Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shopar-plugin

Package Overview
Dependencies
Maintainers
1
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shopar-plugin - npm Package Compare versions

Comparing version 0.0.7-alpha.1 to 0.0.7-alpha.2

2

dist/shopar-plugin.esm.js

@@ -1,1 +0,1 @@

function e(e,n,t,o){return new(t||(t=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,s)}l((o=o.apply(e,n||[])).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}"};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 t=[Uint8Array,Uint32Array],o=t.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],r=[2,12,7,1],a=window[i[r[r[o]]]][i[r[r[r.length-1]]]],s=a.charCodeAt(o),l=s^s,c=new t[1]([l]);function d(){const e=(new TextEncoder).encode(a),n=i.map((e=>e.length));for(let t=0;t<e.length;t++)e[t]^=n[t%n.length];return window[i[n[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(n,t=0){return e(this,void 0,void 0,(function*(){try{return yield n()}catch(e){if(t>=h)throw e;return yield new Promise((e=>setTimeout(e,u[t]))),p(n,t+1)}}))}const f=["Glasses","Shoes","Watches"],m=["Shoes"];let v;const g=new Uint8Array(16);function w(){if(!v&&(v="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!v))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return v(g)}const y=[];for(let e=0;e<256;++e)y.push((e+256).toString(16).slice(1));var b={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function C(e,n,t){if(b.randomUUID&&!n&&!e)return b.randomUUID();const o=(e=e||{}).random||(e.rng||w)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=o[e];return n}return function(e,n=0){return y[e[n+0]]+y[e[n+1]]+y[e[n+2]]+y[e[n+3]]+"-"+y[e[n+4]]+y[e[n+5]]+"-"+y[e[n+6]]+y[e[n+7]]+"-"+y[e[n+8]]+y[e[n+9]]+"-"+y[e[n+10]]+y[e[n+11]]+y[e[n+12]]+y[e[n+13]]+y[e[n+14]]+y[e[n+15]]}(o)}const E="0.0.7-alpha.1";let S=`https://cdn.jsdelivr.net/npm/shopar-plugin@${E}/dist`;const R={update:e=>{null!=e&&(S=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>S};function A(n){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",n),e.setAttribute("crossorigin","anonymous"),new Promise((n=>{e.addEventListener("load",(()=>n()),!1),e.addEventListener("error",(()=>n()),!1),document.body.appendChild(e)}))}importScripts(n.toString())}))}const k="qrLaunch",x="arLaunch",L="previewLaunch",$="heartbeat";let M,P,U=!1;const D=[];function T(e,n){const t=performance.now(),o=C();let i=0,r=0,a=0,s=0,l=0,c=!1;const d=(i,r={})=>{var a;r=Object.assign(Object.assign({},r),{pluginVersion:E,sessionId:P,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},U?a():D.push(a)};return window.setInterval((()=>{c&&(i=r+a,c=!1,d($,{engagementTotal:i,engagementAR:r,engagement3D:a}))}),1e3),[d,()=>{const e=performance.now(),n=e-s;s=e,n<200&&(r+=n,c=!0)},()=>{const e=performance.now(),n=e-l;l=e,n<200&&(a+=n,c=!0)}]}function I(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function N(n){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield n,e}))}const j=200,_=10;let O,G,W,F,q=!1;function B(t){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(t).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!e.ok)throw new n(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let H,K,V,z,X,Q,Z,Y=!0;function J(e){e!==F&&(F=e,W=B(e),Q=null,null==H||H.clearEffect(),q=!0)}function ee(t,o,i){return e(this,void 0,void 0,(function*(){return V=i,z=t,null==X&&(X=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new n("No camera available!");var r;const a=ie(i),s=I(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(i);H=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),K=yield N(s),yield re(H,K,"user"===a),"Glasses"===i&&(yield G,function(n,t){e(this,void 0,void 0,(function*(){q=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${R}/wasm/mediapipe`,n);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){if(q)return void clearInterval(r);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(q)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<_)return void i.push(n);clearInterval(r);const a=137/(function(e){let n=0;const t=e.length;for(let o=0;o<t;o++)n+=e[o];return n/t}(i)+5);t.changeParameterVector("GLASSES","","scale",a,a,a,0),t.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),j)}))}(K,H))})))()),X}))}function ne(e){H.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},H.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},H.callbacks.onWristTracked=n=>{n.detected&&e()}}function te(n){return e(this,void 0,void 0,(function*(){return null==Q&&(Q=H.switchEffect(n)),Q}))}function oe(){null!=H&&(Y=!0,H.setPaused(Y),null!=K&&null!=K.srcObject&&K.srcObject instanceof MediaStream&&(K.srcObject.getTracks().forEach((e=>e.stop())),K=null),H.stopCamera(),z.style.display="none")}function ie(e){var n;return null==e?"user":null!==(n={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==n?n:"user"}function re(n,t,o){return e(this,void 0,void 0,(function*(){yield new Promise((i=>{t.onloadedmetadata=()=>{t.play().then((()=>e(this,void 0,void 0,(function*(){n.setVideoElement(t,o),i()}))))}}))}))}function ae(e,n){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width",e),t.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n),o.setAttribute("width",e),o.setAttribute("height",e),t.appendChild(o)}return t}const se="shopar-error";function le(e,n,t,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ae("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=n,i.appendChild(e)}i.ariaLabel=t;return i.style.display="none",i}const ce="shopar-control";const de="shopar-deepar-output";function ue(e){const n=document.createElement("div");n.className=e,n.classList.add("shopar-loading-container",e);const t=n.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",n}function he(e,n){const t=document.createElement("div");return t.classList.add("shopar-loading-text",e),t.textContent=n,t.style.textAlign="center",t}function pe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-bg",e);const t=n.style;return t.position="relative",t.overflow="hidden",n}function fe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-fg",e);const t=n.style;return t.width="100%",t.height="100%",n}const me="shopar-main";const ve="shopar-qr-output";const ge="shopar-three-output";var we;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(we||(we={}));let ye,be,Ce,Ee,Se,Re,Ae,ke,xe,Le,$e,Me,Pe,Ue,De=we.None;function Te(e){De=e}let Ie,Ne=!1,je=null;function _e(e){var n,t;if(Ne)return;!function(){try{const e=document.createElement("style"),n=process.env.css;null!=n&&(e.innerHTML=n);const t=document.head;t.insertBefore(e,t.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),ye=function(){const e=document.createElement("div");e.id=me;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),Ce=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),be=function(e){const n=document.createElement("div");n.id=ve;const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none";const o=document.createElement("div");o.className="shopar-qr";const i=o.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(o);const r=document.createElement("div");r.innerText="Scan on mobile or tablet to try on",r.style.textAlign="center",o.appendChild(r);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),n}(Ce),ye.appendChild(be),Ee=function(){const e=document.createElement("div");e.id=de;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),ye.appendChild(Ee),Se=function(){const e=document.createElement("canvas");e.id=ge;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),ye.appendChild(Se),Le=ue("shopar-ar-loading-container");const o=he("shopar-ar-loading-text",null!==(n=null==e?void 0:e["loading.ar"])&&void 0!==n?n:"Loading Try On...");Le.appendChild(o);const i=pe("shopar-ar-loading-bar-bg");$e=fe("shopar-ar-loading-bar-fg"),i.appendChild($e),Le.appendChild(i),ye.appendChild(Le),Me=ue("shopar-3d-loading-container");const r=he("shopar-3d-loading-text",null!==(t=null==e?void 0:e["loading.3d"])&&void 0!==t?t:"Loading 3D...");Me.appendChild(r);const a=pe("shopar-3d-loading-bar-bg");Pe=fe("shopar-3d-loading-bar-fg"),a.appendChild(Pe),Me.appendChild(a),ye.appendChild(Me),Ue=function(){const e=document.createElement("div");e.id=se;const n=e.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const t=document.createElement("div"),o=t.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(t);const i=ae("4rem",`${R}/img/icons/close.svg`);t.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",t.appendChild(r);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",t.appendChild(a),e}(),ye.appendChild(Ue),Re=function(){const e=document.createElement("div");return e.id=ce,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ye.appendChild(Re),Ae=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"),Re.appendChild(Ae),ke=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${R}/img/icons/cube.svg`),Re.appendChild(ke),xe=le("shopar-btn-close","Close","Close ShopAR view",`${R}/img/icons/close.svg`),Re.append(xe),Ne=!0}function Oe(e,n,t,o){var i;Ge(Re,e),Ge(Ae,e&&(t||n)&&De===we.None),Ge(ke,e&&o&&De===we.None),Ge(xe,e&&De!==we.None),We(),qe(),e||""===(i=Ue).style.display&&Ge(i,!1)}function Ge(e,n){e.style.display=n?"":"none"}function We(){$e.classList.remove("active"),Le.style.visibility="hidden"}function Fe(){Pe.classList.add("active"),Me.style.visibility="visible"}function qe(){Pe.classList.remove("active"),Me.style.visibility="hidden"}let Be,He,Ke,Ve,ze,Xe=!0;function Qe(n,t){return e(this,void 0,void 0,(function*(){yield Ie;const e=`https://apps.deepar.ai/${E.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:n,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),i=Ce,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Xe=!1,be.style.display=""}))}function Ze(){Xe=!0,be.style.display="none"}let Ye,Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn=!1,vn=!1;const gn=45,wn=45,yn=3,bn=0,Cn=1.5,En=1,Sn=.5;let Rn,An;function kn(o){if(o!==Ke){const i=255;Ke=o,He=function(o,i,r){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}`],v=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${o}`).catch((()=>{throw new n("Unknown error.")}));if(!e.ok)throw new n("Unknown error.");return e})))),g=new t[0](yield(yield v.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));r+=s;const w=g.byteLength;if(c[l]=Math.min(76,i)*((a>>5)-1),152===c[l]&&(c[l]=w),r==l)return g;r=l,r^=l;for(let e=0,n=g.length;e<n;e++)c[l]^=c[r]<<13,c[l]^=c[r]>>17,c[l]^=c[r]<<5,g[e]=g[e]^c[l];return r^=c[0],r^=c[1],r^=c[2],g}))}(o,(new Date).getTime()+i,Math.random()*i),Rn=null,null==un||un.clear()}}function xn(e){fn.removeEventListener("change",An),An=e,fn.addEventListener("change",e)}function Ln(n,t){return e(this,void 0,void 0,(function*(){return null==Rn&&(Rn=(()=>e(this,void 0,void 0,(function*(){const e=new Je.RGBELoader,o=function(e,n){const t=e.THREE,o=new t.DataTexture(n.data,n.width,n.height,void 0,n.type,void 0,t.ClampToEdgeWrapping,t.ClampToEdgeWrapping,t.LinearFilter,t.LinearFilter,1,t.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(Je,e.parse(t));o.mapping=en.EquirectangularReflectionMapping,o.encoding=en.LinearEncoding,un.environment=o;const i=(new Je.GLTFLoader).setDRACOLoader((new Je.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${en.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Je.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${en.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(nn)).setMeshoptDecoder("function"==typeof Je.MeshoptDecoder?Je.MeshoptDecoder():Je.MeshoptDecoder);return yield i.parseAsync(n.buffer,"")})))()),Rn}))}function $n(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-55,30,30],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);hn.position.set(n[0],n[1],n[2]),fn.minDistance="Shoes"===e?25:0,fn.maxDistance="Shoes"===e?150:1/0}function Mn(e){un.add(e.scene);const n=(new en.Box3).setFromObject(e.scene);tn.position.y=n.min.y-bn,un.add(tn),un.traverse((e=>{if(e instanceof en.Mesh){const n=e.material;n.depthWrite=!0,n instanceof en.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function Pn(){mn=!0,null!=Ye&&(Ye.style.display="none")}function Un(){if(mn)return;requestAnimationFrame(Un),Dn(),fn.update();const e=un.background;un.background=null,un.overrideMaterial=ln;const n=nn.getClearAlpha();nn.setClearAlpha(0),nn.setRenderTarget(on),nn.render(un,pn),un.overrideMaterial=null,Tn(Cn),Tn(.4*Cn),nn.setRenderTarget(null),nn.setClearAlpha(n),un.background=e,nn.render(un,hn)}function Dn(){const e=Ye.clientWidth,n=Ye.clientHeight;Ye.width===e&&Ye.height===n||(nn.setSize(e,n,!1),hn.aspect=e/n,hn.updateProjectionMatrix())}function Tn(e){sn.visible=!0,cn.uniforms.tDiffuse.value=on.texture,cn.uniforms.h.value=1*e/256,sn.material=cn,nn.setRenderTarget(rn),nn.render(sn,pn),dn.uniforms.tDiffuse.value=rn.texture,dn.uniforms.v.value=1*e/256,sn.material=dn,nn.setRenderTarget(on),nn.render(sn,pn),sn.visible=!1}function In(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Nn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const jn=["AR","3D"];function _n(e){const{apiKey:t,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;In(t,"apiKey"),Nn(t,"apiKey"),In(o,"sku"),Nn(o,"sku"),In(i,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&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 '")}.`)}(r,"initialState",jn),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let On=0,Gn=0;function Wn(t){var o,i,r;return e(this,void 0,void 0,(function*(){_n(t);const{apiKey:a,sku:s,targetElement:l,initialState:c}=t;!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}'.`)}(l),R.update(t.baseUrl);const u=function(t,o){return e(this,void 0,void 0,(function*(){const i=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:t,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!e.ok)throw new n(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(a,s);null==M&&(P=C(),M=A(`${R}/shopar-analytics.js`),M.then((()=>{U=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[h,v,g]=T(s,a);h("setup",{hostname:window.location.hostname}),_e(null===(o=t._internalOptions)||void 0===o?void 0:o.strings);const w=++Gn,y=yield u;h("apiResponse",y);const{category:b,arUrl:E,arKey:S,previewUrl:$,previewEnvUrl:j}=y;Fn(w);const _=null!=E&&function(e){return null!=e&&f.includes(e)}(b),F=null==(null===(i=t._internalOptions)||void 0===i?void 0:i.qrEnabled)||(null===(r=t._internalOptions)||void 0===r?void 0:r.qrEnabled),q=_&&function(e){return null!=e&&m.includes(e)}(b),X=F&&q&&!(yield function(){var n;return e(this,void 0,void 0,(function*(){return null==Z&&(Z=A(`${R}/shopar-platform.js`)),yield Z,["Android","iOS","Windows Phone",void 0].includes(null===(n=window.ShopAR__platform.platform.os)||void 0===n?void 0:n.family)}))}());Fn(w),X&&function(){e(this,void 0,void 0,(function*(){null==Ie&&(Ie=A(`${R}/shopar-qr.js`))}))}();const Q=_&&!X;Q&&(null==O&&(O=A(`${R}/shopar-deepar.js`)),J(E),"Glasses"===b&&null==G&&(G=A(`${R}/shopar-true-scale.js`)));const ae=null!=$;var se;ae&&(null==Be&&(Be=A(`${R}/shopar-three.js`)),kn($),(se=null!=j?j:`${R}/env/default.hdr`)!==ze&&(ze=se,Ve=B(se))),function(e){e.style.position="relative",null==je?e.appendChild(ye):e!==je&&(je.removeChild(ye),e.appendChild(ye)),je=e}(l);const le=null==t.defaultUI||t.defaultUI;if(Oe(le,X,Q,ae),De===we.AR){if(!Y)if(ne(v),Q){h(x);const e=yield W;Fn(w),yield te(e),Fn(w)}else oe(),Te(we.None),le&&(Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0));if(!Xe)if(X){h(k);try{yield Qe(a,s)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ze(),Te(we.None),le&&(Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0))}else if(De===we.Preview&&!mn)if(xn(g),ae){h(L),Fe(),Ge(Se,!1);const e=yield He;Fn(w);const n=yield Ve;Fn(w);const t=yield Ln(e,n);Fn(w),$n(b),Mn(t),Ge(Se,!0),qe()}else Pn(),Te(we.None),le&&(Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0));const ce=()=>e(this,void 0,void 0,(function*(){if(X){if(De===we.AR)throw new n("AR already launched.");try{h(k);++On;return De===we.Preview&&ae&&!mn&&Pn(),Te(we.AR),le&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),le&&Ge(Ue,!1),void(yield Qe(a,s))}catch(e){const t=e instanceof Error;throw h("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!Q)throw new n("Model does not have AR enabled.");if(De===we.AR)throw new n("AR already launched.");try{h(x);const n=++On;De===we.Preview&&ae&&!mn&&Pn(),Te(we.AR),le&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),le&&Ge(Ue,!1),$e.classList.add("active"),Le.style.visibility="visible";const t=yield W;if(On!==n||Gn!==w)return;if(yield O,On!==n||Gn!==w)return;if(yield ee(Ee,S,b),On!==n||Gn!==w)return;if(ne(v),yield te(t),On!==n||Gn!==w)return;if(yield function(){return e(this,void 0,void 0,(function*(){if(null!=H){if(Y=!1,null==K){const e=ie(V),n=I(e);K=yield N(n),yield re(H,K,"user"===e)}H.setPaused(Y),z.style.display=""}}))}(),On!==n||Gn!==w)return}catch(e){const t=e instanceof Error;throw h("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),le&&Ge(Ue,!0),oe(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{We()}})),de=()=>e(this,void 0,void 0,(function*(){if(!ae)throw new n("Model does not have 3D enabled.");if(De===we.Preview)throw new n("3D already launched.");try{h(L);const n=++On;De===we.AR&&(Q&&!Y&&oe(),Ze()),Te(we.Preview),le&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),le&&Ge(Ue,!1),Fe();const t=yield He;if(On!==n||Gn!==w)return;const o=yield Ve;if(On!==n||Gn!==w)return;if(yield Be,On!==n||Gn!==w)return;if(yield function(n){return e(this,void 0,void 0,(function*(){if(Ye=n,!vn){Je=window.ShopAR__THREE,en=Je.THREE,nn=new en.WebGLRenderer({powerPreference:"high-performance",canvas:n,antialias:!0,alpha:!0}),nn.outputEncoding=en.sRGBEncoding,nn.toneMapping=en.ACESFilmicToneMapping,nn.setPixelRatio(window.devicePixelRatio||1),nn.setClearColor(new en.Color(16777215)),un=new en.Scene,tn=new en.Group,tn.position.y=-.7,on=new en.WebGLRenderTarget(512,512),on.texture.generateMipmaps=!1,rn=new en.WebGLRenderTarget(512,512),rn.texture.generateMipmaps=!1;const e=new en.PlaneGeometry(gn,wn).rotateX(Math.PI/2),t=new en.MeshBasicMaterial({map:on.texture,opacity:Sn,transparent:!0,depthWrite:!1});an=new en.Mesh(e,t),an.renderOrder=1,tn.add(an),an.scale.y=-1,sn=new en.Mesh(e),sn.visible=!1,tn.add(sn),pn=new en.OrthographicCamera(-gn/2,gn/2,wn/2,-wn/2,0,yn),pn.rotation.x=Math.PI/2,tn.add(pn),ln=new en.MeshDepthMaterial,ln.userData.darkness={value:En},ln.onBeforeCompile=function(e){e.uniforms.darkness=ln.userData.darkness,e.fragmentShader=`\n uniform float darkness;\n ${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );")}\n `},ln.depthTest=!1,ln.depthWrite=!1,cn=new en.ShaderMaterial(Je.HorizontalBlurShader),cn.depthTest=!1,dn=new en.ShaderMaterial(Je.VerticalBlurShader),dn.depthTest=!1,hn=new en.PerspectiveCamera(25,1,.5),fn=new Je.OrbitControls(hn,nn.domElement),fn.target.set(0,.03,0),fn.dampingFactor=.3,vn=!0}Dn()}))}(Se),On!==n||Gn!==w)return;xn(g);const i=yield Ln(t,o);if(On!==n||Gn!==w)return;$n(b),Mn(i),mn=!1,Un(),null!=Ye&&(Ye.style.display="")}catch(e){const t=e instanceof Error;throw h("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{qe()}})),ue=()=>e(this,void 0,void 0,(function*(){if(De===we.None)throw new n("Neither AR or 3D launched.");++On,De===we.AR?(Q&&!Y&&oe(),Ze()):De===we.Preview&&ae&&!mn&&Pn(),Te(we.None),We(),qe(),le&&(Ge(Ue,!1),Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0))}));return le&&((X||Q)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${R}/img/icons/${null!=e&&n[e]||n.Glasses}`;Ae.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(b),Ae.onclick=ce),ae&&(ke.onclick=de),xe.onclick=ue),"AR"===c?(yield ce(),Fn(w)):"3D"===c&&(yield de(),Fn(w)),{launchAR:ce,launch3D:de,closeAR:()=>e(this,void 0,void 0,(function*(){if(De!==we.AR)throw new n("AR not launched.");++On,Q&&!Y&&oe(),Ze(),Te(we.None),We(),le&&(Ge(Ue,!1),Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(De!==we.Preview)throw new n("3D not launched.");++On,ae&&!mn&&Pn(),Te(we.None),qe(),le&&(Ge(Ue,!1),Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0))})),close:ue}}))}function Fn(e){if(Gn!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const qn={setup:function(t){return e(this,void 0,void 0,(function*(){return function(t,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new n(`${t} failed: ${e.message}`):(console.error(e),new n(`${t} failed.`))}}))}("setup",(()=>Wn(t)))}))},version:E};export{qn as plugin};
function e(e,n,t,o){return new(t||(t=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,s)}l((o=o.apply(e,n||[])).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}"};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 t=[Uint8Array,Uint32Array],o=t.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],r=[2,12,7,1],a=window[i[r[r[o]]]][i[r[r[r.length-1]]]],s=a.charCodeAt(o),l=s^s,c=new t[1]([l]);function d(){const e=(new TextEncoder).encode(a),n=i.map((e=>e.length));for(let t=0;t<e.length;t++)e[t]^=n[t%n.length];return window[i[n[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(n,t=0){return e(this,void 0,void 0,(function*(){try{return yield n()}catch(e){if(t>=h)throw e;return yield new Promise((e=>setTimeout(e,u[t]))),p(n,t+1)}}))}const f=["Glasses","Shoes","Watches"],m=["Shoes"];let v;const g=new Uint8Array(16);function w(){if(!v&&(v="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!v))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return v(g)}const y=[];for(let e=0;e<256;++e)y.push((e+256).toString(16).slice(1));var b={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function C(e,n,t){if(b.randomUUID&&!n&&!e)return b.randomUUID();const o=(e=e||{}).random||(e.rng||w)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=o[e];return n}return function(e,n=0){return y[e[n+0]]+y[e[n+1]]+y[e[n+2]]+y[e[n+3]]+"-"+y[e[n+4]]+y[e[n+5]]+"-"+y[e[n+6]]+y[e[n+7]]+"-"+y[e[n+8]]+y[e[n+9]]+"-"+y[e[n+10]]+y[e[n+11]]+y[e[n+12]]+y[e[n+13]]+y[e[n+14]]+y[e[n+15]]}(o)}const E="0.0.7-alpha.2";let S=`https://cdn.jsdelivr.net/npm/shopar-plugin@${E}/dist`;const R={update:e=>{null!=e&&(S=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>S};function A(n){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",n),e.setAttribute("crossorigin","anonymous"),new Promise((n=>{e.addEventListener("load",(()=>n()),!1),e.addEventListener("error",(()=>n()),!1),document.body.appendChild(e)}))}importScripts(n.toString())}))}const x="qrLaunch",k="arLaunch",L="previewLaunch",$="heartbeat";let M,P,U=!1;const D=[];function T(e,n){const t=performance.now(),o=C();let i=0,r=0,a=0,s=0,l=0,c=!1;const d=(i,r={})=>{var a;r=Object.assign(Object.assign({},r),{pluginVersion:E,sessionId:P,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},U?a():D.push(a)};return window.setInterval((()=>{c&&(i=r+a,c=!1,d($,{engagementTotal:i,engagementAR:r,engagement3D:a}))}),1e3),[d,()=>{const e=performance.now(),n=e-s;s=e,n<200&&(r+=n,c=!0)},()=>{const e=performance.now(),n=e-l;l=e,n<200&&(a+=n,c=!0)}]}function I(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function N(n){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield n,e}))}const j=200,_=10;let O,G,W,F,q=!1;function B(t){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(t).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!e.ok)throw new n(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let H,K,V,z,X,Q,Z,Y=!0;function J(e){e!==F&&(F=e,W=B(e),Q=null,null==H||H.clearEffect(),q=!0)}function ee(t,o,i){return e(this,void 0,void 0,(function*(){return V=i,z=t,null==X&&(X=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new n("No camera available!");var r;const a=ie(i),s=I(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(i);H=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),K=yield N(s),yield re(H,K,"user"===a),"Glasses"===i&&(yield G,function(n,t){e(this,void 0,void 0,(function*(){q=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${R}/wasm/mediapipe`,n);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){if(q)return void clearInterval(r);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(q)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<_)return void i.push(n);clearInterval(r);const a=137/(function(e){let n=0;const t=e.length;for(let o=0;o<t;o++)n+=e[o];return n/t}(i)+5);t.changeParameterVector("GLASSES","","scale",a,a,a,0),t.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),j)}))}(K,H))})))()),X}))}function ne(e){H.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},H.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},H.callbacks.onWristTracked=n=>{n.detected&&e()}}function te(n){return e(this,void 0,void 0,(function*(){return null==Q&&(Q=H.switchEffect(n)),Q}))}function oe(){null!=H&&(Y=!0,H.setPaused(Y),null!=K&&null!=K.srcObject&&K.srcObject instanceof MediaStream&&(K.srcObject.getTracks().forEach((e=>e.stop())),K=null),H.stopCamera(),z.style.display="none")}function ie(e){var n;return null==e?"user":null!==(n={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==n?n:"user"}function re(n,t,o){return e(this,void 0,void 0,(function*(){yield new Promise((i=>{t.onloadedmetadata=()=>{t.play().then((()=>e(this,void 0,void 0,(function*(){n.setVideoElement(t,o),i()}))))}}))}))}function ae(e,n){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width",e),t.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n),o.setAttribute("width",e),o.setAttribute("height",e),t.appendChild(o)}return t}const se="shopar-error";function le(e,n,t,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ae("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=n,i.appendChild(e)}i.ariaLabel=t;return i.style.display="none",i}const ce="shopar-control";const de="shopar-deepar-output";function ue(e){const n=document.createElement("div");n.className=e,n.classList.add("shopar-loading-container",e);const t=n.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",n}function he(e,n){const t=document.createElement("div");return t.classList.add("shopar-loading-text",e),t.textContent=n,t.style.textAlign="center",t}function pe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-bg",e);const t=n.style;return t.position="relative",t.overflow="hidden",n}function fe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-fg",e);const t=n.style;return t.width="100%",t.height="100%",n}const me="shopar-main";const ve="shopar-qr-output";const ge="shopar-three-output";var we;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(we||(we={}));let ye,be,Ce,Ee,Se,Re,Ae,xe,ke,Le,$e,Me,Pe,Ue,De=we.None;function Te(e){De=e}let Ie,Ne=!1,je=null;function _e(e){var n,t;if(Ne)return;!function(){try{const e=document.createElement("style"),n=process.env.css;null!=n&&(e.innerHTML=n);const t=document.head;t.insertBefore(e,t.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),ye=function(){const e=document.createElement("div");e.id=me;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),Ce=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),be=function(e){const n=document.createElement("div");n.id=ve;const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none";const o=document.createElement("div");o.className="shopar-qr";const i=o.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(o);const r=document.createElement("div");r.innerText="Scan on mobile or tablet to try on",r.style.textAlign="center",o.appendChild(r);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),n}(Ce),ye.appendChild(be),Ee=function(){const e=document.createElement("div");e.id=de;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),ye.appendChild(Ee),Se=function(){const e=document.createElement("canvas");e.id=ge;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),ye.appendChild(Se),Le=ue("shopar-ar-loading-container");const o=he("shopar-ar-loading-text",null!==(n=null==e?void 0:e["loading.ar"])&&void 0!==n?n:"Loading Try On...");Le.appendChild(o);const i=pe("shopar-ar-loading-bar-bg");$e=fe("shopar-ar-loading-bar-fg"),i.appendChild($e),Le.appendChild(i),ye.appendChild(Le),Me=ue("shopar-3d-loading-container");const r=he("shopar-3d-loading-text",null!==(t=null==e?void 0:e["loading.3d"])&&void 0!==t?t:"Loading 3D...");Me.appendChild(r);const a=pe("shopar-3d-loading-bar-bg");Pe=fe("shopar-3d-loading-bar-fg"),a.appendChild(Pe),Me.appendChild(a),ye.appendChild(Me),Ue=function(){const e=document.createElement("div");e.id=se;const n=e.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const t=document.createElement("div"),o=t.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(t);const i=ae("4rem",`${R}/img/icons/close.svg`);t.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",t.appendChild(r);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",t.appendChild(a),e}(),ye.appendChild(Ue),Re=function(){const e=document.createElement("div");return e.id=ce,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ye.appendChild(Re),Ae=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"),Re.appendChild(Ae),xe=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${R}/img/icons/cube.svg`),Re.appendChild(xe),ke=le("shopar-btn-close","Close","Close ShopAR view",`${R}/img/icons/close.svg`),Re.append(ke),Ne=!0}function Oe(e,n,t,o){var i;Ge(Re,e),Ge(Ae,e&&(t||n)&&De===we.None),Ge(xe,e&&o&&De===we.None),Ge(ke,e&&De!==we.None),We(),qe(),e||""===(i=Ue).style.display&&Ge(i,!1)}function Ge(e,n){e.style.display=n?"":"none"}function We(){$e.classList.remove("active"),Le.style.visibility="hidden"}function Fe(){Pe.classList.add("active"),Me.style.visibility="visible"}function qe(){Pe.classList.remove("active"),Me.style.visibility="hidden"}let Be,He,Ke,Ve,ze,Xe=!0;function Qe(n,t){return e(this,void 0,void 0,(function*(){yield Ie;const e=`https://apps.deepar.ai/${E.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:n,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),i=Ce,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Xe=!1,be.style.display=""}))}function Ze(){Xe=!0,be.style.display="none"}let Ye,Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn=!1,vn=!1;const gn=45,wn=45,yn=3,bn=0,Cn=1.5,En=1,Sn=.5;let Rn,An;function xn(o){if(o!==Ke){const i=255;Ke=o,He=function(o,i,r){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}`],v=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${o}`).catch((()=>{throw new n("Unknown error.")}));if(!e.ok)throw new n("Unknown error.");return e})))),g=new t[0](yield(yield v.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));r+=s;const w=g.byteLength;if(c[l]=Math.min(76,i)*((a>>5)-1),152===c[l]&&(c[l]=w),r==l)return g;r=l,r^=l;for(let e=0,n=g.length;e<n;e++)c[l]^=c[r]<<13,c[l]^=c[r]>>17,c[l]^=c[r]<<5,g[e]=g[e]^c[l];return r^=c[0],r^=c[1],r^=c[2],g}))}(o,(new Date).getTime()+i,Math.random()*i),Rn=null,null==un||un.clear()}}function kn(e){fn.removeEventListener("change",An),An=e,fn.addEventListener("change",e)}function Ln(n,t){return e(this,void 0,void 0,(function*(){return null==Rn&&(Rn=(()=>e(this,void 0,void 0,(function*(){const e=new Je.RGBELoader,o=function(e,n){const t=e.THREE,o=new t.DataTexture(n.data,n.width,n.height,void 0,n.type,void 0,t.ClampToEdgeWrapping,t.ClampToEdgeWrapping,t.LinearFilter,t.LinearFilter,1,t.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(Je,e.parse(t));o.mapping=en.EquirectangularReflectionMapping,o.encoding=en.LinearEncoding,un.environment=o;const i=(new Je.GLTFLoader).setDRACOLoader((new Je.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${en.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Je.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${en.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(nn)).setMeshoptDecoder("function"==typeof Je.MeshoptDecoder?Je.MeshoptDecoder():Je.MeshoptDecoder);return yield i.parseAsync(n.buffer,"")})))()),Rn}))}function $n(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-55,30,30],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);hn.position.set(n[0],n[1],n[2]),fn.minDistance="Shoes"===e?25:0,fn.maxDistance="Shoes"===e?150:1/0}function Mn(e){un.add(e.scene);const n=(new en.Box3).setFromObject(e.scene);tn.position.y=n.min.y-bn,un.add(tn),un.traverse((e=>{if(e instanceof en.Mesh){const n=e.material;n.depthWrite=!0,n instanceof en.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}})),fn.target.set((n.min.x+n.max.x)/2,(n.min.y+n.max.y)/2,(n.min.z+n.max.z)/2)}function Pn(){mn=!0,null!=Ye&&(Ye.style.display="none")}function Un(){if(mn)return;requestAnimationFrame(Un),Dn(),fn.update();const e=un.background;un.background=null,un.overrideMaterial=ln;const n=nn.getClearAlpha();nn.setClearAlpha(0),nn.setRenderTarget(on),nn.render(un,pn),un.overrideMaterial=null,Tn(Cn),Tn(.4*Cn),nn.setRenderTarget(null),nn.setClearAlpha(n),un.background=e,nn.render(un,hn)}function Dn(){const e=Ye.clientWidth,n=Ye.clientHeight;Ye.width===e&&Ye.height===n||(nn.setSize(e,n,!1),hn.aspect=e/n,hn.updateProjectionMatrix())}function Tn(e){sn.visible=!0,cn.uniforms.tDiffuse.value=on.texture,cn.uniforms.h.value=1*e/256,sn.material=cn,nn.setRenderTarget(rn),nn.render(sn,pn),dn.uniforms.tDiffuse.value=rn.texture,dn.uniforms.v.value=1*e/256,sn.material=dn,nn.setRenderTarget(on),nn.render(sn,pn),sn.visible=!1}function In(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Nn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const jn=["AR","3D"];function _n(e){const{apiKey:t,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;In(t,"apiKey"),Nn(t,"apiKey"),In(o,"sku"),Nn(o,"sku"),In(i,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&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 '")}.`)}(r,"initialState",jn),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let On=0,Gn=0;function Wn(t){var o,i,r;return e(this,void 0,void 0,(function*(){_n(t);const{apiKey:a,sku:s,targetElement:l,initialState:c}=t;!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}'.`)}(l),R.update(t.baseUrl);const u=function(t,o){return e(this,void 0,void 0,(function*(){const i=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:t,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!e.ok)throw new n(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(a,s);null==M&&(P=C(),M=A(`${R}/shopar-analytics.js`),M.then((()=>{U=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[h,v,g]=T(s,a);h("setup",{hostname:window.location.hostname}),_e(null===(o=t._internalOptions)||void 0===o?void 0:o.strings);const w=++Gn,y=yield u;h("apiResponse",y);const{category:b,arUrl:E,arKey:S,previewUrl:$,previewEnvUrl:j}=y;Fn(w);const _=null!=E&&function(e){return null!=e&&f.includes(e)}(b),F=null==(null===(i=t._internalOptions)||void 0===i?void 0:i.qrEnabled)||(null===(r=t._internalOptions)||void 0===r?void 0:r.qrEnabled),q=_&&function(e){return null!=e&&m.includes(e)}(b),X=F&&q&&!(yield function(){var n;return e(this,void 0,void 0,(function*(){return null==Z&&(Z=A(`${R}/shopar-platform.js`)),yield Z,["Android","iOS","Windows Phone",void 0].includes(null===(n=window.ShopAR__platform.platform.os)||void 0===n?void 0:n.family)}))}());Fn(w),X&&function(){e(this,void 0,void 0,(function*(){null==Ie&&(Ie=A(`${R}/shopar-qr.js`))}))}();const Q=_&&!X;Q&&(null==O&&(O=A(`${R}/shopar-deepar.js`)),J(E),"Glasses"===b&&null==G&&(G=A(`${R}/shopar-true-scale.js`)));const ae=null!=$;var se;ae&&(null==Be&&(Be=A(`${R}/shopar-three.js`)),xn($),(se=null!=j?j:`${R}/env/default.hdr`)!==ze&&(ze=se,Ve=B(se))),function(e){e.style.position="relative",null==je?e.appendChild(ye):e!==je&&(je.removeChild(ye),e.appendChild(ye)),je=e}(l);const le=null==t.defaultUI||t.defaultUI;if(Oe(le,X,Q,ae),De===we.AR){if(!Y)if(ne(v),Q){h(k);const e=yield W;Fn(w),yield te(e),Fn(w)}else oe(),Te(we.None),le&&(Ge(ke,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(xe,!0));if(!Xe)if(X){h(x);try{yield Qe(a,s)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ze(),Te(we.None),le&&(Ge(ke,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(xe,!0))}else if(De===we.Preview&&!mn)if(kn(g),ae){h(L),Fe(),Ge(Se,!1);const e=yield He;Fn(w);const n=yield Ve;Fn(w);const t=yield Ln(e,n);Fn(w),$n(b),Mn(t),Ge(Se,!0),qe()}else Pn(),Te(we.None),le&&(Ge(ke,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(xe,!0));const ce=()=>e(this,void 0,void 0,(function*(){if(X){if(De===we.AR)throw new n("AR already launched.");try{h(x);++On;return De===we.Preview&&ae&&!mn&&Pn(),Te(we.AR),le&&(Ge(Ae,!1),Ge(xe,!1),Ge(ke,!0)),le&&Ge(Ue,!1),void(yield Qe(a,s))}catch(e){const t=e instanceof Error;throw h("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!Q)throw new n("Model does not have AR enabled.");if(De===we.AR)throw new n("AR already launched.");try{h(k);const n=++On;De===we.Preview&&ae&&!mn&&Pn(),Te(we.AR),le&&(Ge(Ae,!1),Ge(xe,!1),Ge(ke,!0)),le&&Ge(Ue,!1),$e.classList.add("active"),Le.style.visibility="visible";const t=yield W;if(On!==n||Gn!==w)return;if(yield O,On!==n||Gn!==w)return;if(yield ee(Ee,S,b),On!==n||Gn!==w)return;if(ne(v),yield te(t),On!==n||Gn!==w)return;if(yield function(){return e(this,void 0,void 0,(function*(){if(null!=H){if(Y=!1,null==K){const e=ie(V),n=I(e);K=yield N(n),yield re(H,K,"user"===e)}H.setPaused(Y),z.style.display=""}}))}(),On!==n||Gn!==w)return}catch(e){const t=e instanceof Error;throw h("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),le&&Ge(Ue,!0),oe(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{We()}})),de=()=>e(this,void 0,void 0,(function*(){if(!ae)throw new n("Model does not have 3D enabled.");if(De===we.Preview)throw new n("3D already launched.");try{h(L);const n=++On;De===we.AR&&(Q&&!Y&&oe(),Ze()),Te(we.Preview),le&&(Ge(Ae,!1),Ge(xe,!1),Ge(ke,!0)),le&&Ge(Ue,!1),Fe();const t=yield He;if(On!==n||Gn!==w)return;const o=yield Ve;if(On!==n||Gn!==w)return;if(yield Be,On!==n||Gn!==w)return;if(yield function(n){return e(this,void 0,void 0,(function*(){if(Ye=n,!vn){Je=window.ShopAR__THREE,en=Je.THREE,nn=new en.WebGLRenderer({powerPreference:"high-performance",canvas:n,antialias:!0,alpha:!0}),nn.outputEncoding=en.sRGBEncoding,nn.toneMapping=en.ACESFilmicToneMapping,nn.setPixelRatio(window.devicePixelRatio||1),nn.setClearColor(new en.Color(16777215)),un=new en.Scene,tn=new en.Group,tn.position.y=-.7,on=new en.WebGLRenderTarget(512,512),on.texture.generateMipmaps=!1,rn=new en.WebGLRenderTarget(512,512),rn.texture.generateMipmaps=!1;const e=new en.PlaneGeometry(gn,wn).rotateX(Math.PI/2),t=new en.MeshBasicMaterial({map:on.texture,opacity:Sn,transparent:!0,depthWrite:!1});an=new en.Mesh(e,t),an.renderOrder=1,tn.add(an),an.scale.y=-1,sn=new en.Mesh(e),sn.visible=!1,tn.add(sn),pn=new en.OrthographicCamera(-gn/2,gn/2,wn/2,-wn/2,0,yn),pn.rotation.x=Math.PI/2,tn.add(pn),ln=new en.MeshDepthMaterial,ln.userData.darkness={value:En},ln.onBeforeCompile=function(e){e.uniforms.darkness=ln.userData.darkness,e.fragmentShader=`\n uniform float darkness;\n ${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );")}\n `},ln.depthTest=!1,ln.depthWrite=!1,cn=new en.ShaderMaterial(Je.HorizontalBlurShader),cn.depthTest=!1,dn=new en.ShaderMaterial(Je.VerticalBlurShader),dn.depthTest=!1,hn=new en.PerspectiveCamera(25,1,.5),fn=new Je.OrbitControls(hn,nn.domElement),fn.target.set(0,.03,0),fn.dampingFactor=.3,vn=!0}Dn()}))}(Se),On!==n||Gn!==w)return;kn(g);const i=yield Ln(t,o);if(On!==n||Gn!==w)return;$n(b),Mn(i),mn=!1,Un(),null!=Ye&&(Ye.style.display="")}catch(e){const t=e instanceof Error;throw h("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{qe()}})),ue=()=>e(this,void 0,void 0,(function*(){if(De===we.None)throw new n("Neither AR or 3D launched.");++On,De===we.AR?(Q&&!Y&&oe(),Ze()):De===we.Preview&&ae&&!mn&&Pn(),Te(we.None),We(),qe(),le&&(Ge(Ue,!1),Ge(ke,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(xe,!0))}));return le&&((X||Q)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${R}/img/icons/${null!=e&&n[e]||n.Glasses}`;Ae.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(b),Ae.onclick=ce),ae&&(xe.onclick=de),ke.onclick=ue),"AR"===c?(yield ce(),Fn(w)):"3D"===c&&(yield de(),Fn(w)),{launchAR:ce,launch3D:de,closeAR:()=>e(this,void 0,void 0,(function*(){if(De!==we.AR)throw new n("AR not launched.");++On,Q&&!Y&&oe(),Ze(),Te(we.None),We(),le&&(Ge(Ue,!1),Ge(ke,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(xe,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(De!==we.Preview)throw new n("3D not launched.");++On,ae&&!mn&&Pn(),Te(we.None),qe(),le&&(Ge(Ue,!1),Ge(ke,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(xe,!0))})),close:ue}}))}function Fn(e){if(Gn!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const qn={setup:function(t){return e(this,void 0,void 0,(function*(){return function(t,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new n(`${t} failed: ${e.message}`):(console.error(e),new n(`${t} failed.`))}}))}("setup",(()=>Wn(t)))}))},version:E};export{qn as plugin};

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function n(e,n,t,o){return new(t||(t=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,s)}l((o=o.apply(e,n||[])).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}"};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 o=[Uint8Array,Uint32Array],i=o.length-2,r=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[r[a[a[i]]]][r[a[a[a.length-1]]]],l=s.charCodeAt(i),c=l^l,d=new o[1]([c]);function u(){const e=(new TextEncoder).encode(s),n=r.map((e=>e.length));for(let t=0;t<e.length;t++)e[t]^=n[t%n.length];return window[r[n[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,t=0){return n(this,void 0,void 0,(function*(){try{return yield e()}catch(n){if(t>=p)throw n;return yield new Promise((e=>setTimeout(e,h[t]))),f(e,t+1)}}))}const m=["Glasses","Shoes","Watches"],v=["Shoes"];let g;const w=new Uint8Array(16);function y(){if(!g&&(g="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!g))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return g(w)}const b=[];for(let e=0;e<256;++e)b.push((e+256).toString(16).slice(1));var C={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function E(e,n,t){if(C.randomUUID&&!n&&!e)return C.randomUUID();const o=(e=e||{}).random||(e.rng||y)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=o[e];return n}return function(e,n=0){return b[e[n+0]]+b[e[n+1]]+b[e[n+2]]+b[e[n+3]]+"-"+b[e[n+4]]+b[e[n+5]]+"-"+b[e[n+6]]+b[e[n+7]]+"-"+b[e[n+8]]+b[e[n+9]]+"-"+b[e[n+10]]+b[e[n+11]]+b[e[n+12]]+b[e[n+13]]+b[e[n+14]]+b[e[n+15]]}(o)}const S="0.0.7-alpha.1";let R=`https://cdn.jsdelivr.net/npm/shopar-plugin@${S}/dist`;const A={update:e=>{null!=e&&(R=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>R};function x(e){return n(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const n=document.createElement("script");return n.setAttribute("src",e),n.setAttribute("crossorigin","anonymous"),new Promise((e=>{n.addEventListener("load",(()=>e()),!1),n.addEventListener("error",(()=>e()),!1),document.body.appendChild(n)}))}importScripts(e.toString())}))}const k="qrLaunch",L="arLaunch",$="previewLaunch",M="heartbeat";let P,U,D=!1;const T=[];function I(e,n){const t=performance.now(),o=E();let i=0,r=0,a=0,s=0,l=0,c=!1;const d=(i,r={})=>{var a;r=Object.assign(Object.assign({},r),{pluginVersion:S,sessionId:U,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},D?a():T.push(a)};return window.setInterval((()=>{c&&(i=r+a,c=!1,d(M,{engagementTotal:i,engagementAR:r,engagement3D:a}))}),1e3),[d,()=>{const e=performance.now(),n=e-s;s=e,n<200&&(r+=n,c=!0)},()=>{const e=performance.now(),n=e-l;l=e,n<200&&(a+=n,c=!0)}]}function j(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function N(e){return n(this,void 0,void 0,(function*(){const n=document.createElement("video");return n.setAttribute("playsinline","playsinline"),n.srcObject=yield e,n}))}const _=200,O=10;let G,W,F,q,B=!1;function H(e){return n(this,void 0,void 0,(function*(){const o=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield fetch(e).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!n.ok)throw new t(`Resource download failed with status ${n.status}.`);return n}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let K,V,z,X,Q,Z,Y,J=!0;function ee(e){e!==q&&(q=e,F=H(e),Z=null,null==K||K.clearEffect(),B=!0)}function ne(e,o,i){return n(this,void 0,void 0,(function*(){return z=i,X=e,null==Q&&(Q=(()=>n(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new t("No camera available!");var r;const a=re(i),s=j(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(i);K=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),V=yield N(s),yield ae(K,V,"user"===a),"Glasses"===i&&(yield W,function(e,t){n(this,void 0,void 0,(function*(){B=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${A}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>n(this,void 0,void 0,(function*(){if(B)return void clearInterval(r);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(B)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<O)return void i.push(n);clearInterval(r);const a=137/(function(e){let n=0;const t=e.length;for(let o=0;o<t;o++)n+=e[o];return n/t}(i)+5);t.changeParameterVector("GLASSES","","scale",a,a,a,0),t.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),_)}))}(V,K))})))()),Q}))}function te(e){K.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},K.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},K.callbacks.onWristTracked=n=>{n.detected&&e()}}function oe(e){return n(this,void 0,void 0,(function*(){return null==Z&&(Z=K.switchEffect(e)),Z}))}function ie(){null!=K&&(J=!0,K.setPaused(J),null!=V&&null!=V.srcObject&&V.srcObject instanceof MediaStream&&(V.srcObject.getTracks().forEach((e=>e.stop())),V=null),K.stopCamera(),X.style.display="none")}function re(e){var n;return null==e?"user":null!==(n={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==n?n:"user"}function ae(e,t,o){return n(this,void 0,void 0,(function*(){yield new Promise((i=>{t.onloadedmetadata=()=>{t.play().then((()=>n(this,void 0,void 0,(function*(){e.setVideoElement(t,o),i()}))))}}))}))}function se(e,n){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width",e),t.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n),o.setAttribute("width",e),o.setAttribute("height",e),t.appendChild(o)}return t}const le="shopar-error";function ce(e,n,t,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=se("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=n,i.appendChild(e)}i.ariaLabel=t;return i.style.display="none",i}const de="shopar-control";const ue="shopar-deepar-output";function he(e){const n=document.createElement("div");n.className=e,n.classList.add("shopar-loading-container",e);const t=n.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",n}function pe(e,n){const t=document.createElement("div");return t.classList.add("shopar-loading-text",e),t.textContent=n,t.style.textAlign="center",t}function fe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-bg",e);const t=n.style;return t.position="relative",t.overflow="hidden",n}function me(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-fg",e);const t=n.style;return t.width="100%",t.height="100%",n}const ve="shopar-main";const ge="shopar-qr-output";const we="shopar-three-output";var ye;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(ye||(ye={}));let be,Ce,Ee,Se,Re,Ae,xe,ke,Le,$e,Me,Pe,Ue,De,Te=ye.None;function Ie(e){Te=e}let je,Ne=!1,_e=null;function Oe(e){var n,t;if(Ne)return;!function(){try{const e=document.createElement("style"),n=process.env.css;null!=n&&(e.innerHTML=n);const t=document.head;t.insertBefore(e,t.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),be=function(){const e=document.createElement("div");e.id=ve;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),Ee=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),Ce=function(e){const n=document.createElement("div");n.id=ge;const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none";const o=document.createElement("div");o.className="shopar-qr";const i=o.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(o);const r=document.createElement("div");r.innerText="Scan on mobile or tablet to try on",r.style.textAlign="center",o.appendChild(r);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),n}(Ee),be.appendChild(Ce),Se=function(){const e=document.createElement("div");e.id=ue;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),be.appendChild(Se),Re=function(){const e=document.createElement("canvas");e.id=we;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),be.appendChild(Re),$e=he("shopar-ar-loading-container");const o=pe("shopar-ar-loading-text",null!==(n=null==e?void 0:e["loading.ar"])&&void 0!==n?n:"Loading Try On...");$e.appendChild(o);const i=fe("shopar-ar-loading-bar-bg");Me=me("shopar-ar-loading-bar-fg"),i.appendChild(Me),$e.appendChild(i),be.appendChild($e),Pe=he("shopar-3d-loading-container");const r=pe("shopar-3d-loading-text",null!==(t=null==e?void 0:e["loading.3d"])&&void 0!==t?t:"Loading 3D...");Pe.appendChild(r);const a=fe("shopar-3d-loading-bar-bg");Ue=me("shopar-3d-loading-bar-fg"),a.appendChild(Ue),Pe.appendChild(a),be.appendChild(Pe),De=function(){const e=document.createElement("div");e.id=le;const n=e.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const t=document.createElement("div"),o=t.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(t);const i=se("4rem",`${A}/img/icons/close.svg`);t.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",t.appendChild(r);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",t.appendChild(a),e}(),be.appendChild(De),Ae=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}(),be.appendChild(Ae),xe=ce("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),Ae.appendChild(xe),ke=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${A}/img/icons/cube.svg`),Ae.appendChild(ke),Le=ce("shopar-btn-close","Close","Close ShopAR view",`${A}/img/icons/close.svg`),Ae.append(Le),Ne=!0}function Ge(e,n,t,o){var i;We(Ae,e),We(xe,e&&(t||n)&&Te===ye.None),We(ke,e&&o&&Te===ye.None),We(Le,e&&Te!==ye.None),Fe(),Be(),e||""===(i=De).style.display&&We(i,!1)}function We(e,n){e.style.display=n?"":"none"}function Fe(){Me.classList.remove("active"),$e.style.visibility="hidden"}function qe(){Ue.classList.add("active"),Pe.style.visibility="visible"}function Be(){Ue.classList.remove("active"),Pe.style.visibility="hidden"}let He,Ke,Ve,ze,Xe,Qe=!0;function Ze(e,t){return n(this,void 0,void 0,(function*(){yield je;const n=`https://apps.deepar.ai/${S.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(n),i=Ee,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Qe=!1,Ce.style.display=""}))}function Ye(){Qe=!0,Ce.style.display="none"}let Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn,vn=!1,gn=!1;const wn=45,yn=45,bn=3,Cn=0,En=1.5,Sn=1,Rn=.5;let An,xn;function kn(e){if(e!==Ve){const i=255;Ve=e,Ke=function(e,i,r){return n(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),m=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],v=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield m(`${e}`).catch((()=>{throw new t("Unknown error.")}));if(!n.ok)throw new t("Unknown error.");return n})))),g=new o[0](yield(yield v.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));r+=s;const w=g.byteLength;if(d[c]=Math.min(76,i)*((a>>5)-1),152===d[c]&&(d[c]=w),r==c)return g;r=c,r^=c;for(let e=0,n=g.length;e<n;e++)d[c]^=d[r]<<13,d[c]^=d[r]>>17,d[c]^=d[r]<<5,g[e]=g[e]^d[c];return r^=d[0],r^=d[1],r^=d[2],g}))}(e,(new Date).getTime()+i,Math.random()*i),An=null,null==hn||hn.clear()}}function Ln(e){mn.removeEventListener("change",xn),xn=e,mn.addEventListener("change",e)}function $n(e,t){return n(this,void 0,void 0,(function*(){return null==An&&(An=(()=>n(this,void 0,void 0,(function*(){const n=new en.RGBELoader,o=function(e,n){const t=e.THREE,o=new t.DataTexture(n.data,n.width,n.height,void 0,n.type,void 0,t.ClampToEdgeWrapping,t.ClampToEdgeWrapping,t.LinearFilter,t.LinearFilter,1,t.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(en,n.parse(t));o.mapping=nn.EquirectangularReflectionMapping,o.encoding=nn.LinearEncoding,hn.environment=o;const i=(new en.GLTFLoader).setDRACOLoader((new en.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${nn.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new en.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${nn.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(tn)).setMeshoptDecoder("function"==typeof en.MeshoptDecoder?en.MeshoptDecoder():en.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),An}))}function Mn(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-55,30,30],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);pn.position.set(n[0],n[1],n[2]),mn.minDistance="Shoes"===e?25:0,mn.maxDistance="Shoes"===e?150:1/0}function Pn(e){hn.add(e.scene);const n=(new nn.Box3).setFromObject(e.scene);on.position.y=n.min.y-Cn,hn.add(on),hn.traverse((e=>{if(e instanceof nn.Mesh){const n=e.material;n.depthWrite=!0,n instanceof nn.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function Un(){vn=!0,null!=Je&&(Je.style.display="none")}function Dn(){if(vn)return;requestAnimationFrame(Dn),Tn(),mn.update();const e=hn.background;hn.background=null,hn.overrideMaterial=cn;const n=tn.getClearAlpha();tn.setClearAlpha(0),tn.setRenderTarget(rn),tn.render(hn,fn),hn.overrideMaterial=null,In(En),In(.4*En),tn.setRenderTarget(null),tn.setClearAlpha(n),hn.background=e,tn.render(hn,pn)}function Tn(){const e=Je.clientWidth,n=Je.clientHeight;Je.width===e&&Je.height===n||(tn.setSize(e,n,!1),pn.aspect=e/n,pn.updateProjectionMatrix())}function In(e){ln.visible=!0,dn.uniforms.tDiffuse.value=rn.texture,dn.uniforms.h.value=1*e/256,ln.material=dn,tn.setRenderTarget(an),tn.render(ln,fn),un.uniforms.tDiffuse.value=an.texture,un.uniforms.v.value=1*e/256,ln.material=un,tn.setRenderTarget(rn),tn.render(ln,fn),ln.visible=!1}function jn(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Nn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const _n=["AR","3D"];function On(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;jn(n,"apiKey"),Nn(n,"apiKey"),jn(o,"sku"),Nn(o,"sku"),jn(i,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&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 '")}.`)}(r,"initialState",_n),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let Gn=0,Wn=0;function Fn(e){var o,i,r;return n(this,void 0,void 0,(function*(){On(e);const{apiKey:a,sku:s,targetElement:l,initialState:c}=e;!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}'.`)}(l),A.update(e.baseUrl);const d=function(e,o){return n(this,void 0,void 0,(function*(){const i=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!n.ok)throw new t(`API call failed with status ${n.status}.`);return n}))));try{return yield i.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(a,s);null==P&&(U=E(),P=x(`${A}/shopar-analytics.js`),P.then((()=>{D=!0,window.ShopAR__analytics.initializeImpl(),T.forEach((e=>e()))})));const[h,p,g]=I(s,a);h("setup",{hostname:window.location.hostname}),Oe(null===(o=e._internalOptions)||void 0===o?void 0:o.strings);const w=++Wn,y=yield d;h("apiResponse",y);const{category:b,arUrl:C,arKey:S,previewUrl:R,previewEnvUrl:M}=y;qn(w);const _=null!=C&&function(e){return null!=e&&m.includes(e)}(b),O=null==(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),q=_&&function(e){return null!=e&&v.includes(e)}(b),B=O&&q&&!(yield function(){var e;return n(this,void 0,void 0,(function*(){return null==Y&&(Y=x(`${A}/shopar-platform.js`)),yield Y,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}());qn(w),B&&function(){n(this,void 0,void 0,(function*(){null==je&&(je=x(`${A}/shopar-qr.js`))}))}();const Q=_&&!B;Q&&(null==G&&(G=x(`${A}/shopar-deepar.js`)),ee(C),"Glasses"===b&&null==W&&(W=x(`${A}/shopar-true-scale.js`)));const Z=null!=R;var se;Z&&(null==He&&(He=x(`${A}/shopar-three.js`)),kn(R),(se=null!=M?M:`${A}/env/default.hdr`)!==Xe&&(Xe=se,ze=H(se))),function(e){e.style.position="relative",null==_e?e.appendChild(be):e!==_e&&(_e.removeChild(be),e.appendChild(be)),_e=e}(l);const le=null==e.defaultUI||e.defaultUI;if(Ge(le,B,Q,Z),Te===ye.AR){if(!J)if(te(p),Q){h(L);const e=yield F;qn(w),yield oe(e),qn(w)}else ie(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0));if(!Qe)if(B){h(k);try{yield Ze(a,s)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ye(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))}else if(Te===ye.Preview&&!vn)if(Ln(g),Z){h($),qe(),We(Re,!1);const e=yield Ke;qn(w);const n=yield ze;qn(w);const t=yield $n(e,n);qn(w),Mn(b),Pn(t),We(Re,!0),Be()}else Un(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0));const ce=()=>n(this,void 0,void 0,(function*(){if(B){if(Te===ye.AR)throw new t("AR already launched.");try{h(k);++Gn;return Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.AR),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),void(yield Ze(a,s))}catch(e){const n=e instanceof Error;throw h("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!Q)throw new t("Model does not have AR enabled.");if(Te===ye.AR)throw new t("AR already launched.");try{h(L);const e=++Gn;Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.AR),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),Me.classList.add("active"),$e.style.visibility="visible";const t=yield F;if(Gn!==e||Wn!==w)return;if(yield G,Gn!==e||Wn!==w)return;if(yield ne(Se,S,b),Gn!==e||Wn!==w)return;if(te(p),yield oe(t),Gn!==e||Wn!==w)return;if(yield function(){return n(this,void 0,void 0,(function*(){if(null!=K){if(J=!1,null==V){const e=re(z),n=j(e);V=yield N(n),yield ae(K,V,"user"===e)}K.setPaused(J),X.style.display=""}}))}(),Gn!==e||Wn!==w)return}catch(e){const n=e instanceof Error;throw h("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),le&&We(De,!0),ie(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{Fe()}})),de=()=>n(this,void 0,void 0,(function*(){if(!Z)throw new t("Model does not have 3D enabled.");if(Te===ye.Preview)throw new t("3D already launched.");try{h($);const e=++Gn;Te===ye.AR&&(Q&&!J&&ie(),Ye()),Ie(ye.Preview),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),qe();const t=yield Ke;if(Gn!==e||Wn!==w)return;const o=yield ze;if(Gn!==e||Wn!==w)return;if(yield He,Gn!==e||Wn!==w)return;if(yield function(e){return n(this,void 0,void 0,(function*(){if(Je=e,!gn){en=window.ShopAR__THREE,nn=en.THREE,tn=new nn.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),tn.outputEncoding=nn.sRGBEncoding,tn.toneMapping=nn.ACESFilmicToneMapping,tn.setPixelRatio(window.devicePixelRatio||1),tn.setClearColor(new nn.Color(16777215)),hn=new nn.Scene,on=new nn.Group,on.position.y=-.7,rn=new nn.WebGLRenderTarget(512,512),rn.texture.generateMipmaps=!1,an=new nn.WebGLRenderTarget(512,512),an.texture.generateMipmaps=!1;const n=new nn.PlaneGeometry(wn,yn).rotateX(Math.PI/2),t=new nn.MeshBasicMaterial({map:rn.texture,opacity:Rn,transparent:!0,depthWrite:!1});sn=new nn.Mesh(n,t),sn.renderOrder=1,on.add(sn),sn.scale.y=-1,ln=new nn.Mesh(n),ln.visible=!1,on.add(ln),fn=new nn.OrthographicCamera(-wn/2,wn/2,yn/2,-yn/2,0,bn),fn.rotation.x=Math.PI/2,on.add(fn),cn=new nn.MeshDepthMaterial,cn.userData.darkness={value:Sn},cn.onBeforeCompile=function(e){e.uniforms.darkness=cn.userData.darkness,e.fragmentShader=`\n uniform float darkness;\n ${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );")}\n `},cn.depthTest=!1,cn.depthWrite=!1,dn=new nn.ShaderMaterial(en.HorizontalBlurShader),dn.depthTest=!1,un=new nn.ShaderMaterial(en.VerticalBlurShader),un.depthTest=!1,pn=new nn.PerspectiveCamera(25,1,.5),mn=new en.OrbitControls(pn,tn.domElement),mn.target.set(0,.03,0),mn.dampingFactor=.3,gn=!0}Tn()}))}(Re),Gn!==e||Wn!==w)return;Ln(g);const i=yield $n(t,o);if(Gn!==e||Wn!==w)return;Mn(b),Pn(i),vn=!1,Dn(),null!=Je&&(Je.style.display="")}catch(e){const n=e instanceof Error;throw h("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{Be()}})),ue=()=>n(this,void 0,void 0,(function*(){if(Te===ye.None)throw new t("Neither AR or 3D launched.");++Gn,Te===ye.AR?(Q&&!J&&ie(),Ye()):Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.None),Fe(),Be(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))}));return le&&((B||Q)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${A}/img/icons/${null!=e&&n[e]||n.Glasses}`;xe.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(b),xe.onclick=ce),Z&&(ke.onclick=de),Le.onclick=ue),"AR"===c?(yield ce(),qn(w)):"3D"===c&&(yield de(),qn(w)),{launchAR:ce,launch3D:de,closeAR:()=>n(this,void 0,void 0,(function*(){if(Te!==ye.AR)throw new t("AR not launched.");++Gn,Q&&!J&&ie(),Ye(),Ie(ye.None),Fe(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))})),close3D:()=>n(this,void 0,void 0,(function*(){if(Te!==ye.Preview)throw new t("3D not launched.");++Gn,Z&&!vn&&Un(),Ie(ye.None),Be(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))})),close:ue}}))}function qn(e){if(Wn!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Bn={setup:function(e){return n(this,void 0,void 0,(function*(){return function(e,o){return n(this,void 0,void 0,(function*(){try{return o()}catch(n){throw n instanceof Error?new t(`${e} failed: ${n.message}`):(console.error(n),new t(`${e} failed.`))}}))}("setup",(()=>Fn(e)))}))},version:S};e.plugin=Bn}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function n(e,n,t,o){return new(t||(t=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,s)}l((o=o.apply(e,n||[])).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}"};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 o=[Uint8Array,Uint32Array],i=o.length-2,r=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[r[a[a[i]]]][r[a[a[a.length-1]]]],l=s.charCodeAt(i),c=l^l,d=new o[1]([c]);function u(){const e=(new TextEncoder).encode(s),n=r.map((e=>e.length));for(let t=0;t<e.length;t++)e[t]^=n[t%n.length];return window[r[n[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,t=0){return n(this,void 0,void 0,(function*(){try{return yield e()}catch(n){if(t>=p)throw n;return yield new Promise((e=>setTimeout(e,h[t]))),f(e,t+1)}}))}const m=["Glasses","Shoes","Watches"],v=["Shoes"];let g;const w=new Uint8Array(16);function y(){if(!g&&(g="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!g))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return g(w)}const b=[];for(let e=0;e<256;++e)b.push((e+256).toString(16).slice(1));var C={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function E(e,n,t){if(C.randomUUID&&!n&&!e)return C.randomUUID();const o=(e=e||{}).random||(e.rng||y)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=o[e];return n}return function(e,n=0){return b[e[n+0]]+b[e[n+1]]+b[e[n+2]]+b[e[n+3]]+"-"+b[e[n+4]]+b[e[n+5]]+"-"+b[e[n+6]]+b[e[n+7]]+"-"+b[e[n+8]]+b[e[n+9]]+"-"+b[e[n+10]]+b[e[n+11]]+b[e[n+12]]+b[e[n+13]]+b[e[n+14]]+b[e[n+15]]}(o)}const S="0.0.7-alpha.2";let R=`https://cdn.jsdelivr.net/npm/shopar-plugin@${S}/dist`;const A={update:e=>{null!=e&&(R=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>R};function x(e){return n(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const n=document.createElement("script");return n.setAttribute("src",e),n.setAttribute("crossorigin","anonymous"),new Promise((e=>{n.addEventListener("load",(()=>e()),!1),n.addEventListener("error",(()=>e()),!1),document.body.appendChild(n)}))}importScripts(e.toString())}))}const k="qrLaunch",L="arLaunch",$="previewLaunch",M="heartbeat";let P,U,D=!1;const T=[];function I(e,n){const t=performance.now(),o=E();let i=0,r=0,a=0,s=0,l=0,c=!1;const d=(i,r={})=>{var a;r=Object.assign(Object.assign({},r),{pluginVersion:S,sessionId:U,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},D?a():T.push(a)};return window.setInterval((()=>{c&&(i=r+a,c=!1,d(M,{engagementTotal:i,engagementAR:r,engagement3D:a}))}),1e3),[d,()=>{const e=performance.now(),n=e-s;s=e,n<200&&(r+=n,c=!0)},()=>{const e=performance.now(),n=e-l;l=e,n<200&&(a+=n,c=!0)}]}function j(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function N(e){return n(this,void 0,void 0,(function*(){const n=document.createElement("video");return n.setAttribute("playsinline","playsinline"),n.srcObject=yield e,n}))}const _=200,O=10;let G,W,F,q,B=!1;function H(e){return n(this,void 0,void 0,(function*(){const o=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield fetch(e).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!n.ok)throw new t(`Resource download failed with status ${n.status}.`);return n}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let K,V,z,X,Q,Z,Y,J=!0;function ee(e){e!==q&&(q=e,F=H(e),Z=null,null==K||K.clearEffect(),B=!0)}function ne(e,o,i){return n(this,void 0,void 0,(function*(){return z=i,X=e,null==Q&&(Q=(()=>n(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new t("No camera available!");var r;const a=re(i),s=j(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(i);K=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),V=yield N(s),yield ae(K,V,"user"===a),"Glasses"===i&&(yield W,function(e,t){n(this,void 0,void 0,(function*(){B=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${A}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>n(this,void 0,void 0,(function*(){if(B)return void clearInterval(r);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(B)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<O)return void i.push(n);clearInterval(r);const a=137/(function(e){let n=0;const t=e.length;for(let o=0;o<t;o++)n+=e[o];return n/t}(i)+5);t.changeParameterVector("GLASSES","","scale",a,a,a,0),t.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),_)}))}(V,K))})))()),Q}))}function te(e){K.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},K.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},K.callbacks.onWristTracked=n=>{n.detected&&e()}}function oe(e){return n(this,void 0,void 0,(function*(){return null==Z&&(Z=K.switchEffect(e)),Z}))}function ie(){null!=K&&(J=!0,K.setPaused(J),null!=V&&null!=V.srcObject&&V.srcObject instanceof MediaStream&&(V.srcObject.getTracks().forEach((e=>e.stop())),V=null),K.stopCamera(),X.style.display="none")}function re(e){var n;return null==e?"user":null!==(n={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==n?n:"user"}function ae(e,t,o){return n(this,void 0,void 0,(function*(){yield new Promise((i=>{t.onloadedmetadata=()=>{t.play().then((()=>n(this,void 0,void 0,(function*(){e.setVideoElement(t,o),i()}))))}}))}))}function se(e,n){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width",e),t.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n),o.setAttribute("width",e),o.setAttribute("height",e),t.appendChild(o)}return t}const le="shopar-error";function ce(e,n,t,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=se("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=n,i.appendChild(e)}i.ariaLabel=t;return i.style.display="none",i}const de="shopar-control";const ue="shopar-deepar-output";function he(e){const n=document.createElement("div");n.className=e,n.classList.add("shopar-loading-container",e);const t=n.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",n}function pe(e,n){const t=document.createElement("div");return t.classList.add("shopar-loading-text",e),t.textContent=n,t.style.textAlign="center",t}function fe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-bg",e);const t=n.style;return t.position="relative",t.overflow="hidden",n}function me(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-fg",e);const t=n.style;return t.width="100%",t.height="100%",n}const ve="shopar-main";const ge="shopar-qr-output";const we="shopar-three-output";var ye;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(ye||(ye={}));let be,Ce,Ee,Se,Re,Ae,xe,ke,Le,$e,Me,Pe,Ue,De,Te=ye.None;function Ie(e){Te=e}let je,Ne=!1,_e=null;function Oe(e){var n,t;if(Ne)return;!function(){try{const e=document.createElement("style"),n=process.env.css;null!=n&&(e.innerHTML=n);const t=document.head;t.insertBefore(e,t.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),be=function(){const e=document.createElement("div");e.id=ve;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),Ee=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),Ce=function(e){const n=document.createElement("div");n.id=ge;const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none";const o=document.createElement("div");o.className="shopar-qr";const i=o.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(o);const r=document.createElement("div");r.innerText="Scan on mobile or tablet to try on",r.style.textAlign="center",o.appendChild(r);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),n}(Ee),be.appendChild(Ce),Se=function(){const e=document.createElement("div");e.id=ue;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),be.appendChild(Se),Re=function(){const e=document.createElement("canvas");e.id=we;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),be.appendChild(Re),$e=he("shopar-ar-loading-container");const o=pe("shopar-ar-loading-text",null!==(n=null==e?void 0:e["loading.ar"])&&void 0!==n?n:"Loading Try On...");$e.appendChild(o);const i=fe("shopar-ar-loading-bar-bg");Me=me("shopar-ar-loading-bar-fg"),i.appendChild(Me),$e.appendChild(i),be.appendChild($e),Pe=he("shopar-3d-loading-container");const r=pe("shopar-3d-loading-text",null!==(t=null==e?void 0:e["loading.3d"])&&void 0!==t?t:"Loading 3D...");Pe.appendChild(r);const a=fe("shopar-3d-loading-bar-bg");Ue=me("shopar-3d-loading-bar-fg"),a.appendChild(Ue),Pe.appendChild(a),be.appendChild(Pe),De=function(){const e=document.createElement("div");e.id=le;const n=e.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const t=document.createElement("div"),o=t.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(t);const i=se("4rem",`${A}/img/icons/close.svg`);t.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",t.appendChild(r);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",t.appendChild(a),e}(),be.appendChild(De),Ae=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}(),be.appendChild(Ae),xe=ce("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),Ae.appendChild(xe),ke=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${A}/img/icons/cube.svg`),Ae.appendChild(ke),Le=ce("shopar-btn-close","Close","Close ShopAR view",`${A}/img/icons/close.svg`),Ae.append(Le),Ne=!0}function Ge(e,n,t,o){var i;We(Ae,e),We(xe,e&&(t||n)&&Te===ye.None),We(ke,e&&o&&Te===ye.None),We(Le,e&&Te!==ye.None),Fe(),Be(),e||""===(i=De).style.display&&We(i,!1)}function We(e,n){e.style.display=n?"":"none"}function Fe(){Me.classList.remove("active"),$e.style.visibility="hidden"}function qe(){Ue.classList.add("active"),Pe.style.visibility="visible"}function Be(){Ue.classList.remove("active"),Pe.style.visibility="hidden"}let He,Ke,Ve,ze,Xe,Qe=!0;function Ze(e,t){return n(this,void 0,void 0,(function*(){yield je;const n=`https://apps.deepar.ai/${S.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(n),i=Ee,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Qe=!1,Ce.style.display=""}))}function Ye(){Qe=!0,Ce.style.display="none"}let Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn,vn=!1,gn=!1;const wn=45,yn=45,bn=3,Cn=0,En=1.5,Sn=1,Rn=.5;let An,xn;function kn(e){if(e!==Ve){const i=255;Ve=e,Ke=function(e,i,r){return n(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),m=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],v=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield m(`${e}`).catch((()=>{throw new t("Unknown error.")}));if(!n.ok)throw new t("Unknown error.");return n})))),g=new o[0](yield(yield v.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));r+=s;const w=g.byteLength;if(d[c]=Math.min(76,i)*((a>>5)-1),152===d[c]&&(d[c]=w),r==c)return g;r=c,r^=c;for(let e=0,n=g.length;e<n;e++)d[c]^=d[r]<<13,d[c]^=d[r]>>17,d[c]^=d[r]<<5,g[e]=g[e]^d[c];return r^=d[0],r^=d[1],r^=d[2],g}))}(e,(new Date).getTime()+i,Math.random()*i),An=null,null==hn||hn.clear()}}function Ln(e){mn.removeEventListener("change",xn),xn=e,mn.addEventListener("change",e)}function $n(e,t){return n(this,void 0,void 0,(function*(){return null==An&&(An=(()=>n(this,void 0,void 0,(function*(){const n=new en.RGBELoader,o=function(e,n){const t=e.THREE,o=new t.DataTexture(n.data,n.width,n.height,void 0,n.type,void 0,t.ClampToEdgeWrapping,t.ClampToEdgeWrapping,t.LinearFilter,t.LinearFilter,1,t.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(en,n.parse(t));o.mapping=nn.EquirectangularReflectionMapping,o.encoding=nn.LinearEncoding,hn.environment=o;const i=(new en.GLTFLoader).setDRACOLoader((new en.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${nn.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new en.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${nn.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(tn)).setMeshoptDecoder("function"==typeof en.MeshoptDecoder?en.MeshoptDecoder():en.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),An}))}function Mn(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-55,30,30],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);pn.position.set(n[0],n[1],n[2]),mn.minDistance="Shoes"===e?25:0,mn.maxDistance="Shoes"===e?150:1/0}function Pn(e){hn.add(e.scene);const n=(new nn.Box3).setFromObject(e.scene);on.position.y=n.min.y-Cn,hn.add(on),hn.traverse((e=>{if(e instanceof nn.Mesh){const n=e.material;n.depthWrite=!0,n instanceof nn.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}})),mn.target.set((n.min.x+n.max.x)/2,(n.min.y+n.max.y)/2,(n.min.z+n.max.z)/2)}function Un(){vn=!0,null!=Je&&(Je.style.display="none")}function Dn(){if(vn)return;requestAnimationFrame(Dn),Tn(),mn.update();const e=hn.background;hn.background=null,hn.overrideMaterial=cn;const n=tn.getClearAlpha();tn.setClearAlpha(0),tn.setRenderTarget(rn),tn.render(hn,fn),hn.overrideMaterial=null,In(En),In(.4*En),tn.setRenderTarget(null),tn.setClearAlpha(n),hn.background=e,tn.render(hn,pn)}function Tn(){const e=Je.clientWidth,n=Je.clientHeight;Je.width===e&&Je.height===n||(tn.setSize(e,n,!1),pn.aspect=e/n,pn.updateProjectionMatrix())}function In(e){ln.visible=!0,dn.uniforms.tDiffuse.value=rn.texture,dn.uniforms.h.value=1*e/256,ln.material=dn,tn.setRenderTarget(an),tn.render(ln,fn),un.uniforms.tDiffuse.value=an.texture,un.uniforms.v.value=1*e/256,ln.material=un,tn.setRenderTarget(rn),tn.render(ln,fn),ln.visible=!1}function jn(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Nn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const _n=["AR","3D"];function On(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;jn(n,"apiKey"),Nn(n,"apiKey"),jn(o,"sku"),Nn(o,"sku"),jn(i,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&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 '")}.`)}(r,"initialState",_n),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let Gn=0,Wn=0;function Fn(e){var o,i,r;return n(this,void 0,void 0,(function*(){On(e);const{apiKey:a,sku:s,targetElement:l,initialState:c}=e;!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}'.`)}(l),A.update(e.baseUrl);const d=function(e,o){return n(this,void 0,void 0,(function*(){const i=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!n.ok)throw new t(`API call failed with status ${n.status}.`);return n}))));try{return yield i.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(a,s);null==P&&(U=E(),P=x(`${A}/shopar-analytics.js`),P.then((()=>{D=!0,window.ShopAR__analytics.initializeImpl(),T.forEach((e=>e()))})));const[h,p,g]=I(s,a);h("setup",{hostname:window.location.hostname}),Oe(null===(o=e._internalOptions)||void 0===o?void 0:o.strings);const w=++Wn,y=yield d;h("apiResponse",y);const{category:b,arUrl:C,arKey:S,previewUrl:R,previewEnvUrl:M}=y;qn(w);const _=null!=C&&function(e){return null!=e&&m.includes(e)}(b),O=null==(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),q=_&&function(e){return null!=e&&v.includes(e)}(b),B=O&&q&&!(yield function(){var e;return n(this,void 0,void 0,(function*(){return null==Y&&(Y=x(`${A}/shopar-platform.js`)),yield Y,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}());qn(w),B&&function(){n(this,void 0,void 0,(function*(){null==je&&(je=x(`${A}/shopar-qr.js`))}))}();const Q=_&&!B;Q&&(null==G&&(G=x(`${A}/shopar-deepar.js`)),ee(C),"Glasses"===b&&null==W&&(W=x(`${A}/shopar-true-scale.js`)));const Z=null!=R;var se;Z&&(null==He&&(He=x(`${A}/shopar-three.js`)),kn(R),(se=null!=M?M:`${A}/env/default.hdr`)!==Xe&&(Xe=se,ze=H(se))),function(e){e.style.position="relative",null==_e?e.appendChild(be):e!==_e&&(_e.removeChild(be),e.appendChild(be)),_e=e}(l);const le=null==e.defaultUI||e.defaultUI;if(Ge(le,B,Q,Z),Te===ye.AR){if(!J)if(te(p),Q){h(L);const e=yield F;qn(w),yield oe(e),qn(w)}else ie(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0));if(!Qe)if(B){h(k);try{yield Ze(a,s)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ye(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))}else if(Te===ye.Preview&&!vn)if(Ln(g),Z){h($),qe(),We(Re,!1);const e=yield Ke;qn(w);const n=yield ze;qn(w);const t=yield $n(e,n);qn(w),Mn(b),Pn(t),We(Re,!0),Be()}else Un(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0));const ce=()=>n(this,void 0,void 0,(function*(){if(B){if(Te===ye.AR)throw new t("AR already launched.");try{h(k);++Gn;return Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.AR),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),void(yield Ze(a,s))}catch(e){const n=e instanceof Error;throw h("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!Q)throw new t("Model does not have AR enabled.");if(Te===ye.AR)throw new t("AR already launched.");try{h(L);const e=++Gn;Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.AR),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),Me.classList.add("active"),$e.style.visibility="visible";const t=yield F;if(Gn!==e||Wn!==w)return;if(yield G,Gn!==e||Wn!==w)return;if(yield ne(Se,S,b),Gn!==e||Wn!==w)return;if(te(p),yield oe(t),Gn!==e||Wn!==w)return;if(yield function(){return n(this,void 0,void 0,(function*(){if(null!=K){if(J=!1,null==V){const e=re(z),n=j(e);V=yield N(n),yield ae(K,V,"user"===e)}K.setPaused(J),X.style.display=""}}))}(),Gn!==e||Wn!==w)return}catch(e){const n=e instanceof Error;throw h("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),le&&We(De,!0),ie(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{Fe()}})),de=()=>n(this,void 0,void 0,(function*(){if(!Z)throw new t("Model does not have 3D enabled.");if(Te===ye.Preview)throw new t("3D already launched.");try{h($);const e=++Gn;Te===ye.AR&&(Q&&!J&&ie(),Ye()),Ie(ye.Preview),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),qe();const t=yield Ke;if(Gn!==e||Wn!==w)return;const o=yield ze;if(Gn!==e||Wn!==w)return;if(yield He,Gn!==e||Wn!==w)return;if(yield function(e){return n(this,void 0,void 0,(function*(){if(Je=e,!gn){en=window.ShopAR__THREE,nn=en.THREE,tn=new nn.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),tn.outputEncoding=nn.sRGBEncoding,tn.toneMapping=nn.ACESFilmicToneMapping,tn.setPixelRatio(window.devicePixelRatio||1),tn.setClearColor(new nn.Color(16777215)),hn=new nn.Scene,on=new nn.Group,on.position.y=-.7,rn=new nn.WebGLRenderTarget(512,512),rn.texture.generateMipmaps=!1,an=new nn.WebGLRenderTarget(512,512),an.texture.generateMipmaps=!1;const n=new nn.PlaneGeometry(wn,yn).rotateX(Math.PI/2),t=new nn.MeshBasicMaterial({map:rn.texture,opacity:Rn,transparent:!0,depthWrite:!1});sn=new nn.Mesh(n,t),sn.renderOrder=1,on.add(sn),sn.scale.y=-1,ln=new nn.Mesh(n),ln.visible=!1,on.add(ln),fn=new nn.OrthographicCamera(-wn/2,wn/2,yn/2,-yn/2,0,bn),fn.rotation.x=Math.PI/2,on.add(fn),cn=new nn.MeshDepthMaterial,cn.userData.darkness={value:Sn},cn.onBeforeCompile=function(e){e.uniforms.darkness=cn.userData.darkness,e.fragmentShader=`\n uniform float darkness;\n ${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );")}\n `},cn.depthTest=!1,cn.depthWrite=!1,dn=new nn.ShaderMaterial(en.HorizontalBlurShader),dn.depthTest=!1,un=new nn.ShaderMaterial(en.VerticalBlurShader),un.depthTest=!1,pn=new nn.PerspectiveCamera(25,1,.5),mn=new en.OrbitControls(pn,tn.domElement),mn.target.set(0,.03,0),mn.dampingFactor=.3,gn=!0}Tn()}))}(Re),Gn!==e||Wn!==w)return;Ln(g);const i=yield $n(t,o);if(Gn!==e||Wn!==w)return;Mn(b),Pn(i),vn=!1,Dn(),null!=Je&&(Je.style.display="")}catch(e){const n=e instanceof Error;throw h("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{Be()}})),ue=()=>n(this,void 0,void 0,(function*(){if(Te===ye.None)throw new t("Neither AR or 3D launched.");++Gn,Te===ye.AR?(Q&&!J&&ie(),Ye()):Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.None),Fe(),Be(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))}));return le&&((B||Q)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${A}/img/icons/${null!=e&&n[e]||n.Glasses}`;xe.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(b),xe.onclick=ce),Z&&(ke.onclick=de),Le.onclick=ue),"AR"===c?(yield ce(),qn(w)):"3D"===c&&(yield de(),qn(w)),{launchAR:ce,launch3D:de,closeAR:()=>n(this,void 0,void 0,(function*(){if(Te!==ye.AR)throw new t("AR not launched.");++Gn,Q&&!J&&ie(),Ye(),Ie(ye.None),Fe(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))})),close3D:()=>n(this,void 0,void 0,(function*(){if(Te!==ye.Preview)throw new t("3D not launched.");++Gn,Z&&!vn&&Un(),Ie(ye.None),Be(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))})),close:ue}}))}function qn(e){if(Wn!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Bn={setup:function(e){return n(this,void 0,void 0,(function*(){return function(e,o){return n(this,void 0,void 0,(function*(){try{return o()}catch(n){throw n instanceof Error?new t(`${e} failed: ${n.message}`):(console.error(n),new t(`${e} failed.`))}}))}("setup",(()=>Fn(e)))}))},version:S};e.plugin=Bn}));
{
"name": "shopar-plugin",
"version": "0.0.7-alpha.1",
"version": "0.0.7-alpha.2",
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",

@@ -5,0 +5,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc