shopar-plugin
Advanced tools
Comparing version 0.0.5 to 0.0.6-alpha.0
@@ -44,2 +44,3 @@ /** Preview state values. */ | ||
defaultUI?: boolean; | ||
_internalOptions?: any; | ||
}; | ||
@@ -46,0 +47,0 @@ |
@@ -1,1 +0,1 @@ | ||
function e(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{l(o.next(e))}catch(e){r(e)}}function a(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const n=[Uint8Array,Uint32Array],o=n.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],r=[2,12,7,1],s=window[i[r[r[o]]]][i[r[r[r.length-1]]]],a=s.charCodeAt(o),l=a^a,c=new n[1]([l]);function d(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,u[n]))),p(t,n+1)}}))}const f=["Glasses","Shoes","Watches"];const v="0.0.5";let w=`https://cdn.jsdelivr.net/npm/shopar-plugin@${v}/dist`;const m={update:e=>{null!=e&&(w=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>w};function y(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let g,b,E=!1;const C=[],A={organizationId:"Unknown",sku:"Unknown"};let S;function R(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),A),{vtoTime:(performance.now()-S)/1e3,vtoSessionId:b}),P((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function P(e){E?e():C.push(e)}function $(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function k(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const I=200,x=10;let _,L,D,M,T=!1;function N(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let U,j,G,O,z,W,F,K,H,V,B,q=!0;function X(e){e!==M&&(M=e,D=N(e),W=null,null==U||U.clearEffect(),T=!0)}function Y(n,o,i){return e(this,void 0,void 0,(function*(){return G=i,O=n,null==z&&(z=(()=>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 t("No camera available!");var r;const s=Z(i),a=$(s);R("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);U=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:n,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),j=yield k(a),R("vto_camera_granted"),yield ee(U,j,"user"===s),"Glasses"===i&&(yield L,function(t,n){e(this,void 0,void 0,(function*(){T=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${m}/wasm/mediapipe`,t);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){if(T)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(T)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<x)return void i.push(t);clearInterval(r);const s=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",s,s,s,0),n.changeParameterVector("shopar_glasses","","scale",s,s,s,0)}))),I)}))}(j,U)),R("vto_init_success")})))()),z}))}function J(t){return e(this,void 0,void 0,(function*(){return null==W&&(W=U.switchEffect(t)),W}))}function Q(){null!=U&&(q=!0,U.setPaused(q),null!=j&&null!=j.srcObject&&j.srcObject instanceof MediaStream&&(j.srcObject.getTracks().forEach((e=>e.stop())),j=null),U.stopCamera(),O.style.display="none")}function Z(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function ee(t,n,o){return e(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,o),i()}))))}}))}))}let te,ne,oe,ie,re,se,ae,le,ce=!1,de=!1;function ue(o){if(o!==H){const i=255;H=o,K=function(o,i,r){return e(this,void 0,void 0,(function*(){let s="glb".charCodeAt(0),a="3d".charCodeAt(0);s>>=1,s+=a;const d=String.fromCharCode(s+14);a>>=2,s^=a+2;const u=String.fromCharCode(s-3);s^=5;const h=String.fromCharCode(s-7);s^=2;const f=String.fromCharCode(s-7),v=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],w=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield v(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),m=new n[0](yield(yield w.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));r+=a;const y=m.byteLength;if(c[l]=Math.min(76,i)*((s>>5)-1),152===c[l]&&(c[l]=y),r==l)return m;r=l,r^=l;for(let e=0,t=m.length;e<t;e++)c[l]^=c[r]<<13,c[l]^=c[r]>>17,c[l]^=c[r]<<5,m[e]=m[e]^c[l];return r^=c[0],r^=c[1],r^=c[2],m}))}(o,(new Date).getTime()+i,Math.random()*i),le=null,null==re||re.clear()}}function he(t,n){return e(this,void 0,void 0,(function*(){if(te=t,!de){ne=window.ShopAR__THREE,oe=ne.THREE,ie=new oe.WebGLRenderer({powerPreference:"high-performance",canvas:t,antialias:!0,alpha:!0}),ie.outputEncoding=oe.sRGBEncoding,ie.toneMapping=oe.ACESFilmicToneMapping,ie.setPixelRatio(window.devicePixelRatio||1),ie.setClearColor(new oe.Color(16777215)),re=new oe.Scene,se=new oe.PerspectiveCamera(25,1,.5);const e=function(e){var t;const n={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);se.position.set(e[0],e[1],e[2]),ae=new ne.OrbitControls(se,ie.domElement),ae.target.set(0,.03,0),ae.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{R("preview_interacted")}),200);ae.addEventListener("end",e)}de=!0}me()}))}function pe(t,n){return e(this,void 0,void 0,(function*(){return null==le&&(le=(()=>e(this,void 0,void 0,(function*(){const e=new ne.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(ne,e.parse(n));o.mapping=oe.EquirectangularReflectionMapping,o.encoding=oe.LinearEncoding,re.environment=o;const i=(new ne.GLTFLoader).setDRACOLoader((new ne.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${oe.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new ne.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${oe.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(ie)).setMeshoptDecoder("function"==typeof ne.MeshoptDecoder?ne.MeshoptDecoder():ne.MeshoptDecoder);return yield i.parseAsync(t.buffer,"")})))()),le}))}function fe(t){return e(this,void 0,void 0,(function*(){re.add(t.scene),re.traverse((e=>{if(e instanceof oe.Mesh){const t=e.material;t.depthWrite=!0,t instanceof oe.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ve(){ce=!0,te.style.display="none"}function we(){ce||(requestAnimationFrame(we),me(),ae.update(),ie.render(re,se))}function me(){const e=te.clientWidth,t=te.clientHeight;te.width===e&&te.height===t||(ie.setSize(e,t,!1),se.aspect=e/t,se.updateProjectionMatrix())}function ye(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const ge="shopar-error";function be(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ye("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const Ee="shopar-control";const Ce="shopar-deepar-output";const Ae="shopar-loading";const Se="shopar-main";const Re="shopar-three-output";var Pe;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(Pe||(Pe={}));let $e,ke,Ie,xe,_e,Le,De,Me,Te,Ne=Pe.None;function Ue(e){Ne=e}let je=!1,Ge=null;function Oe(){je||($e=function(){const e=document.createElement("div");e.id=Se;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),ke=function(){const e=document.createElement("div");e.id=Ce;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),$e.appendChild(ke),Ie=function(){const e=document.createElement("canvas");e.id=Re;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),$e.appendChild(Ie),xe=function(){const e=document.createElement("div");return e.id=Ee,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),$e.appendChild(xe),_e=be("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),xe.appendChild(_e),Le=be("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${m}/img/icons/cube.svg`),xe.appendChild(Le),De=be("shopar-btn-close","Close","Close ShopAR view",`${m}/img/icons/close.svg`),xe.append(De),Me=function(){const e=document.createElement("div");e.id=Ae;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),$e.appendChild(Me),Te=function(){const e=document.createElement("div");e.id=ge;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=ye("4rem",`${m}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.appendChild(r);const s=document.createElement("div");return s.className="shopar-error-body",s.textContent="Please refresh the page and allow the use of camera.",n.appendChild(s),e}(),$e.appendChild(Te),je=!0)}function ze(e,t){e.style.display=t?"":"none"}function We(e){""===e.style.display&&ze(e,!1)}function Fe(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Ke(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const He=["AR","3D"];function Ve(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:s,defaultUI:a}=e;Fe(n,"apiKey"),Ke(n,"apiKey"),Fe(o,"sku"),Ke(o,"sku"),Fe(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",He),null!=s&&Ke(s,"baseUrl"),null!=a&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(a,"defaultUI")}let Be=0,qe=0;function Xe(n){return e(this,void 0,void 0,(function*(){Ve(n);const{apiKey:o,sku:i,targetElement:r,initialState:s}=n;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(r),m.update(n.baseUrl);const a=function(n,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:n,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(o,i);null==g&&(g=y(`${m}/shopar-analytics.js`),g.then((()=>{E=!0,b=window.ShopAR__analytics.uuidv4(),C.forEach((e=>e()))}))),function(e,t){A.organizationId=e,A.sku=t,S=performance.now(),P((()=>{window.ShopAR__analytics.initializeImpl()}))}(o,i),Oe();const l=++qe,{category:c,arUrl:u,arKey:h,previewUrl:v,previewEnvUrl:w}=yield a;Ye(l),R("initialized");const I=null!=u&&function(e){return null!=e&&f.includes(e)}(c);I&&(null==_&&(_=y(`${m}/shopar-deepar.js`)),X(u),"Glasses"===c&&null==L&&(L=y(`${m}/shopar-true-scale.js`)));const x=null!=v;var M;x&&(null==F&&(F=y(`${m}/shopar-three.js`)),ue(v),(M=null!=w?w:`${m}/env/default.hdr`)!==B&&(B=M,V=N(M))),function(e){e.style.position="relative",null==Ge?e.appendChild($e):e!==Ge&&(Ge.removeChild($e),e.appendChild($e)),Ge=e}(r);const T=null==n.defaultUI||n.defaultUI;if(function(e,t,n){ze(xe,e),ze(_e,e&&t&&Ne===Pe.None),ze(Le,e&&n&&Ne===Pe.None),ze(De,e&&Ne!==Pe.None),e||We(Me),e||We(Te)}(T,I,x),Ne===Pe.AR){if(I&&!q){const e=yield D;Ye(l),yield J(e),Ye(l)}}else if(Ne===Pe.Preview&&x&&!ce){const e=yield K;Ye(l);const t=yield V;Ye(l);const n=yield pe(e,t);Ye(l),fe(n)}const z=()=>e(this,void 0,void 0,(function*(){if(!I)throw new t("Model does not have AR enabled.");if(Ne===Pe.AR)throw new t("AR already launched.");const n=++Be;Ne===Pe.Preview&&x&&!ce&&ve(),Ue(Pe.AR),T&&(ze(_e,!1),ze(Le,!1),ze(De,!0)),R("vto_launched"),T&&(ze(Te,!1),ze(Me,!0));const o=yield D;if(Be===n&&qe===l&&(yield _,Be===n&&qe===l)){try{yield Y(ke,h,c)}catch(e){throw function(e){R("vto_camera_denied",{error:e})}(e),T&&(ze(Me,!1),ze(Te,!0)),e}Be===n&&qe===l&&(yield J(o),Be===n&&qe===l&&(yield function(){return e(this,void 0,void 0,(function*(){if(null!=U){if(q=!1,null==j){const e=Z(G),t=$(e);j=yield k(t),yield ee(U,j,"user"===e)}U.setPaused(q),O.style.display=""}}))}(),Be===n&&qe===l&&T&&ze(Me,!1)))}})),W=()=>e(this,void 0,void 0,(function*(){if(!x)throw new t("Model does not have 3D enabled.");if(Ne===Pe.Preview)throw new t("3D already launched.");const e=++Be;Ne===Pe.AR&&I&&!q&&Q(),Ue(Pe.Preview),T&&(ze(_e,!1),ze(Le,!1),ze(De,!0)),R("preview_launched"),T&&(ze(Te,!1),ze(Me,!0));const n=yield K;if(Be!==e||qe!==l)return;const o=yield V;if(Be!==e||qe!==l)return;if(yield F,Be!==e||qe!==l)return;if(yield he(Ie,c),Be!==e||qe!==l)return;const i=yield pe(n,o);Be===e&&qe===l&&(fe(i),ce=!1,we(),te.style.display="",T&&ze(Me,!1))})),H=()=>e(this,void 0,void 0,(function*(){if(Ne===Pe.None)throw new t("Neither AR or 3D launched.");++Be,Ne===Pe.AR?I&&!q&&Q():Ne===Pe.Preview&&x&&!ce&&ve(),Ue(Pe.None),T&&(ze(Me,!1),ze(Te,!1),ze(De,!1),I&&ze(_e,!0),x&&ze(Le,!0))}));return T&&(I&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${m}/img/icons/${null!=e&&t[e]||t.Glasses}`;_e.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(c),_e.onclick=z),x&&(Le.onclick=W),De.onclick=H),"AR"===s?(yield z(),Ye(l)):"3D"===s&&(yield W(),Ye(l)),{launchAR:z,launch3D:W,closeAR:()=>e(this,void 0,void 0,(function*(){if(Ne!==Pe.AR)throw new t("AR not launched.");++Be,I&&!q&&Q(),Ue(Pe.None),T&&(ze(Me,!1),ze(Te,!1),ze(De,!1),I&&ze(_e,!0),x&&ze(Le,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(Ne!==Pe.Preview)throw new t("3D not launched.");++Be,x&&!ce&&ve(),Ue(Pe.None),T&&(ze(Me,!1),ze(Te,!1),ze(De,!1),I&&ze(_e,!0),x&&ze(Le,!0))})),close:H}}))}function Ye(e){if(qe!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Je={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>Xe(n)))}))},version:v};export{Je as plugin}; | ||
function e(e,t,n,o){return new(n||(n=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 t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const n=[Uint8Array,Uint32Array],o=n.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 n[1]([l]);function d(){const e=(new TextEncoder).encode(a),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,u[n]))),p(t,n+1)}}))}const f=["Glasses","Shoes","Watches"],v=["Shoes"];const w="0.0.6-alpha.0";let m=`https://cdn.jsdelivr.net/npm/shopar-plugin@${w}/dist`;const y={update:e=>{null!=e&&(m=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>m};function g(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let b,C,E=!1;const R=[],A={organizationId:"Unknown",sku:"Unknown"};let S;function P(){k("vto_launched")}function k(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),A),{vtoTime:(performance.now()-S)/1e3,vtoSessionId:C}),x((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function x(e){E?e():R.push(e)}function $(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function M(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const _=200,I=10;let T,D,L,U,N=!1;function j(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let O,G,W,z,F,B,H,K=!0;function q(e){e!==U&&(U=e,L=j(e),B=null,null==O||O.clearEffect(),N=!0)}function V(n,o,i){return e(this,void 0,void 0,(function*(){return W=i,z=n,null==F&&(F=(()=>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 t("No camera available!");var r;const a=Z(i),s=$(a);k("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);O=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:n,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),G=yield M(s),k("vto_camera_granted"),yield Y(O,G,"user"===a),"Glasses"===i&&(yield D,function(t,n){e(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,t);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<I)return void i.push(t);clearInterval(r);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),_)}))}(G,O)),k("vto_init_success")})))()),F}))}function Q(t){return e(this,void 0,void 0,(function*(){return null==B&&(B=O.switchEffect(t)),B}))}function X(){null!=O&&(K=!0,O.setPaused(K),null!=G&&null!=G.srcObject&&G.srcObject instanceof MediaStream&&(G.srcObject.getTracks().forEach((e=>e.stop())),G=null),O.stopCamera(),z.style.display="none")}function Z(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Y(t,n,o){return e(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,o),i()}))))}}))}))}function J(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const ee="shopar-error";function te(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=J("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const ne="shopar-control";const oe="shopar-deepar-output";const ie="shopar-loading";const re="shopar-main";const ae="shopar-qr-output";const se="shopar-three-output";var le;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(le||(le={}));let ce,de,ue,he,pe,fe,ve,we,me,ye,ge=le.None;function be(e){ge=e}let Ce,Ee=!1,Re=null;function Ae(){Ee||(ce=function(){const e=document.createElement("div");e.id=re;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),de=function(){const e=document.createElement("div");e.id=ae;const t=e.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="relative",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="flex",o.alignItems="center",o.justifyContent="center",e.appendChild(n);const i=new Image,r=i.style;return r.maxWidth="100%",r.maxHeight="100%",n.appendChild(i),e}(),ce.appendChild(de),ue=function(){const e=document.createElement("div");e.id=oe;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(ue),he=function(){const e=document.createElement("canvas");e.id=se;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(he),pe=function(){const e=document.createElement("div");return e.id=ne,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ce.appendChild(pe),fe=te("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),pe.appendChild(fe),ve=te("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`),pe.appendChild(ve),we=te("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`),pe.append(we),me=function(){const e=document.createElement("div");e.id=ie;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),ce.appendChild(me),ye=function(){const e=document.createElement("div");e.id=ee;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=J("4rem",`${y}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.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.",n.appendChild(a),e}(),ce.appendChild(ye),Ee=!0)}function Se(e,t){e.style.display=t?"":"none"}function Pe(e){""===e.style.display&&Se(e,!1)}let ke,xe,$e,Me,_e,Ie=!0;function Te(t,n){return e(this,void 0,void 0,(function*(){yield Ce;const e=`https://apps.deepar.ai/shopar-qr?${new URLSearchParams({a:t,s:n,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),i=de.firstChild.firstChild,r=new Promise(((e,t)=>{i.onload=e,i.onerror=t}));i.src=o,yield r,Ie=!1,de.style.display=""}))}function De(){Ie=!0,de.style.display="none"}let Le,Ue,Ne,je,Oe,Ge,We,ze,Fe,Be,He,Ke,qe,Ve,Qe,Xe,Ze=!1,Ye=!1;const Je=45,et=45,tt=3,nt=.1,ot=3.5,it=2,rt=1;let at;function st(o){if(o!==$e){const i=255;$e=o,xe=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),v=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],w=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield v(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),m=new n[0](yield(yield w.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));r+=s;const y=m.byteLength;if(c[l]=Math.min(76,i)*((a>>5)-1),152===c[l]&&(c[l]=y),r==l)return m;r=l,r^=l;for(let e=0,t=m.length;e<t;e++)c[l]^=c[r]<<13,c[l]^=c[r]>>17,c[l]^=c[r]<<5,m[e]=m[e]^c[l];return r^=c[0],r^=c[1],r^=c[2],m}))}(o,(new Date).getTime()+i,Math.random()*i),at=null,null==qe||qe.clear()}}function lt(t,n){return e(this,void 0,void 0,(function*(){if(Le=t,!Ye){Ue=window.ShopAR__THREE,Ne=Ue.THREE,je=new Ne.WebGLRenderer({powerPreference:"high-performance",canvas:t,antialias:!0,alpha:!0}),je.outputEncoding=Ne.sRGBEncoding,je.toneMapping=Ne.ACESFilmicToneMapping,je.setPixelRatio(window.devicePixelRatio||1),je.setClearColor(new Ne.Color(16777215)),qe=new Ne.Scene,Oe=new Ne.Group,Oe.position.y=-.7,Ge=new Ne.WebGLRenderTarget(512,512),Ge.texture.generateMipmaps=!1,We=new Ne.WebGLRenderTarget(512,512),We.texture.generateMipmaps=!1;const e=new Ne.PlaneGeometry(Je,et).rotateX(Math.PI/2),o=new Ne.MeshBasicMaterial({map:Ge.texture,opacity:rt,transparent:!0,depthWrite:!1});ze=new Ne.Mesh(e,o),ze.renderOrder=1,Oe.add(ze),ze.scale.y=-1,Fe=new Ne.Mesh(e),Fe.visible=!1,Oe.add(Fe),Qe=new Ne.OrthographicCamera(-Je/2,Je/2,et/2,-et/2,0,tt),Qe.rotation.x=Math.PI/2,Oe.add(Qe),Be=new Ne.MeshDepthMaterial,Be.userData.darkness={value:it},Be.onBeforeCompile=function(e){e.uniforms.darkness=Be.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 `},Be.depthTest=!1,Be.depthWrite=!1,He=new Ne.ShaderMaterial(Ue.HorizontalBlurShader),He.depthTest=!1,Ke=new Ne.ShaderMaterial(Ue.VerticalBlurShader),Ke.depthTest=!1,Ve=new Ne.PerspectiveCamera(25,1,.5);const i=function(e){var t;const n={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);Ve.position.set(i[0],i[1],i[2]),Xe=new Ue.OrbitControls(Ve,je.domElement),Xe.target.set(0,.03,0),Xe.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{k("preview_interacted")}),200);Xe.addEventListener("end",e)}Ye=!0}pt()}))}function ct(t,n){return e(this,void 0,void 0,(function*(){return null==at&&(at=(()=>e(this,void 0,void 0,(function*(){const e=new Ue.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(Ue,e.parse(n));o.mapping=Ne.EquirectangularReflectionMapping,o.encoding=Ne.LinearEncoding,qe.environment=o;const i=(new Ue.GLTFLoader).setDRACOLoader((new Ue.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Ue.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(je)).setMeshoptDecoder("function"==typeof Ue.MeshoptDecoder?Ue.MeshoptDecoder():Ue.MeshoptDecoder);return yield i.parseAsync(t.buffer,"")})))()),at}))}function dt(t){return e(this,void 0,void 0,(function*(){qe.add(t.scene);const e=(new Ne.Box3).setFromObject(t.scene);Oe.position.y=e.min.y-nt,qe.add(Oe),qe.traverse((e=>{if(e instanceof Ne.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ne.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ut(){Ze=!0,Le.style.display="none"}function ht(){if(Ze)return;requestAnimationFrame(ht),pt(),Xe.update();const e=qe.background;qe.background=null,qe.overrideMaterial=Be;const t=je.getClearAlpha();je.setClearAlpha(0),je.setRenderTarget(Ge),je.render(qe,Qe),qe.overrideMaterial=null,ft(ot),ft(.4*ot),je.setRenderTarget(null),je.setClearAlpha(t),qe.background=e,je.render(qe,Ve)}function pt(){const e=Le.clientWidth,t=Le.clientHeight;Le.width===e&&Le.height===t||(je.setSize(e,t,!1),Ve.aspect=e/t,Ve.updateProjectionMatrix())}function ft(e){Fe.visible=!0,He.uniforms.tDiffuse.value=Ge.texture,He.uniforms.h.value=1*e/256,Fe.material=He,je.setRenderTarget(We),je.render(Fe,Qe),Ke.uniforms.tDiffuse.value=We.texture,Ke.uniforms.v.value=1*e/256,Fe.material=Ke,je.setRenderTarget(Ge),je.render(Fe,Qe),Fe.visible=!1}function vt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function wt(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const mt=["AR","3D"];function yt(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;vt(n,"apiKey"),wt(n,"apiKey"),vt(o,"sku"),wt(o,"sku"),vt(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",mt),null!=a&&wt(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let gt=0,bt=0;function Ct(n){var o,i;return e(this,void 0,void 0,(function*(){yt(n);const{apiKey:r,sku:a,targetElement:s,initialState:l}=n;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(s),y.update(n.baseUrl);const c=function(n,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:n,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(r,a);null==b&&(b=g(`${y}/shopar-analytics.js`),b.then((()=>{E=!0,C=window.ShopAR__analytics.uuidv4(),R.forEach((e=>e()))}))),function(e,t){A.organizationId=e,A.sku=t,S=performance.now(),x((()=>{window.ShopAR__analytics.initializeImpl()}))}(r,a),Ae();const u=++bt,{category:h,arUrl:w,arKey:m,previewUrl:_,previewEnvUrl:I}=yield c;Et(u),k("initialized");const U=null!=w&&function(e){return null!=e&&f.includes(e)}(h),N=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=n._internalOptions)||void 0===i?void 0:i.qrEnabled),F=U&&function(e){return null!=e&&v.includes(e)}(h),B=N&&F&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==H&&(H=g(`${y}/shopar-platform.js`)),yield H,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}());Et(u),B&&function(){e(this,void 0,void 0,(function*(){null==Ce&&(Ce=g(`${y}/shopar-qr.js`))}))}();const J=U&&!B;J&&(null==T&&(T=g(`${y}/shopar-deepar.js`)),q(w),"Glasses"===h&&null==D&&(D=g(`${y}/shopar-true-scale.js`)));const ee=null!=_;var te;ee&&(null==ke&&(ke=g(`${y}/shopar-three.js`)),st(_),(te=null!=I?I:`${y}/env/default.hdr`)!==_e&&(_e=te,Me=j(te))),function(e){e.style.position="relative",null==Re?e.appendChild(ce):e!==Re&&(Re.removeChild(ce),e.appendChild(ce)),Re=e}(s);const ne=null==n.defaultUI||n.defaultUI;if(function(e,t,n,o){Se(pe,e),Se(fe,e&&(n||t)&&ge===le.None),Se(ve,e&&o&&ge===le.None),Se(we,e&&ge!==le.None),e||Pe(me),e||Pe(ye)}(ne,B,J,ee),ge===le.AR){if(!K)if(J){const e=yield L;Et(u),yield Q(e),Et(u)}else X(),be(le.None),ne&&(Se(we,!1),(B||J)&&Se(fe,!0),ee&&Se(ve,!0));if(!Ie)if(B)try{yield Te(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}else De(),be(le.None),ne&&(Se(we,!1),(B||J)&&Se(fe,!0),ee&&Se(ve,!0))}else if(ge===le.Preview&&!Ze)if(ee){const e=yield xe;Et(u);const t=yield Me;Et(u);const n=yield ct(e,t);Et(u),dt(n)}else ut(),be(le.None),ne&&(Se(we,!1),(B||J)&&Se(fe,!0),ee&&Se(ve,!0));const oe=()=>e(this,void 0,void 0,(function*(){if(B){if(ge===le.AR)throw new t("AR already launched.");const e=++gt;ge===le.Preview&&ee&&!Ze&&ut(),be(le.AR),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),P(),ne&&(Se(ye,!1),Se(me,!0));try{yield Te(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}if(gt!==e||bt!==u)return;return void(ne&&Se(me,!1))}if(!J)throw new t("Model does not have AR enabled.");if(ge===le.AR)throw new t("AR already launched.");const n=++gt;ge===le.Preview&&ee&&!Ze&&ut(),be(le.AR),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),P(),ne&&(Se(ye,!1),Se(me,!0));const o=yield L;if(gt===n&&bt===u&&(yield T,gt===n&&bt===u)){try{yield V(ue,m,h)}catch(e){throw function(e){k("vto_camera_denied",{error:e})}(e),ne&&(Se(me,!1),Se(ye,!0)),e}gt===n&&bt===u&&(yield Q(o),gt===n&&bt===u&&(yield function(){return e(this,void 0,void 0,(function*(){if(null!=O){if(K=!1,null==G){const e=Z(W),t=$(e);G=yield M(t),yield Y(O,G,"user"===e)}O.setPaused(K),z.style.display=""}}))}(),gt===n&&bt===u&&ne&&Se(me,!1)))}})),ie=()=>e(this,void 0,void 0,(function*(){if(!ee)throw new t("Model does not have 3D enabled.");if(ge===le.Preview)throw new t("3D already launched.");const e=++gt;ge===le.AR&&(J&&!K&&X(),De()),be(le.Preview),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),k("preview_launched"),ne&&(Se(ye,!1),Se(me,!0));const n=yield xe;if(gt!==e||bt!==u)return;const o=yield Me;if(gt!==e||bt!==u)return;if(yield ke,gt!==e||bt!==u)return;if(yield lt(he,h),gt!==e||bt!==u)return;const i=yield ct(n,o);gt===e&&bt===u&&(dt(i),Ze=!1,ht(),Le.style.display="",ne&&Se(me,!1))})),re=()=>e(this,void 0,void 0,(function*(){if(ge===le.None)throw new t("Neither AR or 3D launched.");++gt,ge===le.AR?(J&&!K&&X(),De()):ge===le.Preview&&ee&&!Ze&&ut(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(B||J)&&Se(fe,!0),ee&&Se(ve,!0))}));return ne&&((B||J)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${y}/img/icons/${null!=e&&t[e]||t.Glasses}`;fe.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(h),fe.onclick=oe),ee&&(ve.onclick=ie),we.onclick=re),"AR"===l?(yield oe(),Et(u)):"3D"===l&&(yield ie(),Et(u)),{launchAR:oe,launch3D:ie,closeAR:()=>e(this,void 0,void 0,(function*(){if(ge!==le.AR)throw new t("AR not launched.");++gt,J&&!K&&X(),De(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(B||J)&&Se(fe,!0),ee&&Se(ve,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(ge!==le.Preview)throw new t("3D not launched.");++gt,ee&&!Ze&&ut(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(B||J)&&Se(fe,!0),ee&&Se(ve,!0))})),close:re}}))}function Et(e){if(bt!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Rt={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>Ct(n)))}))},version:w};export{Rt as plugin}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{l(o.next(e))}catch(e){r(e)}}function a(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class n 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"],s=[2,12,7,1],a=window[r[s[s[i]]]][r[s[s[s.length-1]]]],l=a.charCodeAt(i),c=l^l,d=new o[1]([c]);function u(){const e=(new TextEncoder).encode(a),t=r.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[r[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],f=h.length;function p(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=f)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),p(e,n+1)}}))}const v=["Glasses","Shoes","Watches"];const w="0.0.5";let m=`https://cdn.jsdelivr.net/npm/shopar-plugin@${w}/dist`;const y={update:e=>{null!=e&&(m=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>m};function g(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let b,E,C=!1;const A=[],S={organizationId:"Unknown",sku:"Unknown"};let R;function P(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),S),{vtoTime:(performance.now()-R)/1e3,vtoSessionId:E}),$((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function $(e){C?e():A.push(e)}function x(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function k(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const I=200,_=10;let T,L,D,M,N=!1;function U(e){return t(this,void 0,void 0,(function*(){const o=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let j,G,O,z,W,F,K,H,V,B,q,X=!0;function Y(e){e!==M&&(M=e,D=U(e),F=null,null==j||j.clearEffect(),N=!0)}function J(e,o,i){return t(this,void 0,void 0,(function*(){return O=i,z=e,null==W&&(W=(()=>t(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 s=ee(i),a=x(s);P("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);j=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),G=yield k(a),P("vto_camera_granted"),yield te(j,G,"user"===s),"Glasses"===i&&(yield L,function(e,n){t(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>t(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<_)return void i.push(t);clearInterval(r);const s=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",s,s,s,0),n.changeParameterVector("shopar_glasses","","scale",s,s,s,0)}))),I)}))}(G,j)),P("vto_init_success")})))()),W}))}function Q(e){return t(this,void 0,void 0,(function*(){return null==F&&(F=j.switchEffect(e)),F}))}function Z(){null!=j&&(X=!0,j.setPaused(X),null!=G&&null!=G.srcObject&&G.srcObject instanceof MediaStream&&(G.srcObject.getTracks().forEach((e=>e.stop())),G=null),j.stopCamera(),z.style.display="none")}function ee(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function te(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),i()}))))}}))}))}let ne,oe,ie,re,se,ae,le,ce,de=!1,ue=!1;function he(e){if(e!==V){const i=255;V=e,H=function(e,i,r){return t(this,void 0,void 0,(function*(){let s="glb".charCodeAt(0),a="3d".charCodeAt(0);s>>=1,s+=a;const l=String.fromCharCode(s+14);a>>=2,s^=a+2;const u=String.fromCharCode(s-3);s^=5;const h=String.fromCharCode(s-7);s^=2;const f=String.fromCharCode(s-7),v=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],w=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield v(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),m=new o[0](yield(yield w.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));r+=a;const y=m.byteLength;if(d[c]=Math.min(76,i)*((s>>5)-1),152===d[c]&&(d[c]=y),r==c)return m;r=c,r^=c;for(let e=0,t=m.length;e<t;e++)d[c]^=d[r]<<13,d[c]^=d[r]>>17,d[c]^=d[r]<<5,m[e]=m[e]^d[c];return r^=d[0],r^=d[1],r^=d[2],m}))}(e,(new Date).getTime()+i,Math.random()*i),ce=null,null==se||se.clear()}}function fe(e,n){return t(this,void 0,void 0,(function*(){if(ne=e,!ue){oe=window.ShopAR__THREE,ie=oe.THREE,re=new ie.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),re.outputEncoding=ie.sRGBEncoding,re.toneMapping=ie.ACESFilmicToneMapping,re.setPixelRatio(window.devicePixelRatio||1),re.setClearColor(new ie.Color(16777215)),se=new ie.Scene,ae=new ie.PerspectiveCamera(25,1,.5);const t=function(e){var t;const n={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);ae.position.set(t[0],t[1],t[2]),le=new oe.OrbitControls(ae,re.domElement),le.target.set(0,.03,0),le.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{P("preview_interacted")}),200);le.addEventListener("end",e)}ue=!0}ye()}))}function pe(e,n){return t(this,void 0,void 0,(function*(){return null==ce&&(ce=(()=>t(this,void 0,void 0,(function*(){const t=new oe.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(oe,t.parse(n));o.mapping=ie.EquirectangularReflectionMapping,o.encoding=ie.LinearEncoding,se.environment=o;const i=(new oe.GLTFLoader).setDRACOLoader((new oe.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${ie.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new oe.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${ie.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(re)).setMeshoptDecoder("function"==typeof oe.MeshoptDecoder?oe.MeshoptDecoder():oe.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),ce}))}function ve(e){return t(this,void 0,void 0,(function*(){se.add(e.scene),se.traverse((e=>{if(e instanceof ie.Mesh){const t=e.material;t.depthWrite=!0,t instanceof ie.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function we(){de=!0,ne.style.display="none"}function me(){de||(requestAnimationFrame(me),ye(),le.update(),re.render(se,ae))}function ye(){const e=ne.clientWidth,t=ne.clientHeight;ne.width===e&&ne.height===t||(re.setSize(e,t,!1),ae.aspect=e/t,ae.updateProjectionMatrix())}function ge(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const be="shopar-error";function Ee(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ge("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const Ce="shopar-control";const Ae="shopar-deepar-output";const Se="shopar-loading";const Re="shopar-main";const Pe="shopar-three-output";var $e;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}($e||($e={}));let xe,ke,Ie,_e,Te,Le,De,Me,Ne,Ue=$e.None;function je(e){Ue=e}let Ge=!1,Oe=null;function ze(){Ge||(xe=function(){const e=document.createElement("div");e.id=Re;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),ke=function(){const e=document.createElement("div");e.id=Ae;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),xe.appendChild(ke),Ie=function(){const e=document.createElement("canvas");e.id=Pe;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),xe.appendChild(Ie),_e=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}(),xe.appendChild(_e),Te=Ee("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),_e.appendChild(Te),Le=Ee("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`),_e.appendChild(Le),De=Ee("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`),_e.append(De),Me=function(){const e=document.createElement("div");e.id=Se;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),xe.appendChild(Me),Ne=function(){const e=document.createElement("div");e.id=be;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=ge("4rem",`${y}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.appendChild(r);const s=document.createElement("div");return s.className="shopar-error-body",s.textContent="Please refresh the page and allow the use of camera.",n.appendChild(s),e}(),xe.appendChild(Ne),Ge=!0)}function We(e,t){e.style.display=t?"":"none"}function Fe(e){""===e.style.display&&We(e,!1)}function Ke(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function He(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const Ve=["AR","3D"];function Be(e){const{apiKey:t,sku:o,targetElement:i,initialState:r,baseUrl:s,defaultUI:a}=e;Ke(t,"apiKey"),He(t,"apiKey"),Ke(o,"sku"),He(o,"sku"),Ke(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",Ve),null!=s&&He(s,"baseUrl"),null!=a&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(a,"defaultUI")}let qe=0,Xe=0;function Ye(e){return t(this,void 0,void 0,(function*(){Be(e);const{apiKey:o,sku:i,targetElement:r,initialState:s}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(r),y.update(e.baseUrl);const a=function(e,o){return t(this,void 0,void 0,(function*(){const i=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield i.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(o,i);null==b&&(b=g(`${y}/shopar-analytics.js`),b.then((()=>{C=!0,E=window.ShopAR__analytics.uuidv4(),A.forEach((e=>e()))}))),function(e,t){S.organizationId=e,S.sku=t,R=performance.now(),$((()=>{window.ShopAR__analytics.initializeImpl()}))}(o,i),ze();const l=++Xe,{category:c,arUrl:d,arKey:h,previewUrl:f,previewEnvUrl:w}=yield a;Je(l),P("initialized");const m=null!=d&&function(e){return null!=e&&v.includes(e)}(c);m&&(null==T&&(T=g(`${y}/shopar-deepar.js`)),Y(d),"Glasses"===c&&null==L&&(L=g(`${y}/shopar-true-scale.js`)));const I=null!=f;var _;I&&(null==K&&(K=g(`${y}/shopar-three.js`)),he(f),(_=null!=w?w:`${y}/env/default.hdr`)!==q&&(q=_,B=U(_))),function(e){e.style.position="relative",null==Oe?e.appendChild(xe):e!==Oe&&(Oe.removeChild(xe),e.appendChild(xe)),Oe=e}(r);const M=null==e.defaultUI||e.defaultUI;if(function(e,t,n){We(_e,e),We(Te,e&&t&&Ue===$e.None),We(Le,e&&n&&Ue===$e.None),We(De,e&&Ue!==$e.None),e||Fe(Me),e||Fe(Ne)}(M,m,I),Ue===$e.AR){if(m&&!X){const e=yield D;Je(l),yield Q(e),Je(l)}}else if(Ue===$e.Preview&&I&&!de){const e=yield H;Je(l);const t=yield B;Je(l);const n=yield pe(e,t);Je(l),ve(n)}const N=()=>t(this,void 0,void 0,(function*(){if(!m)throw new n("Model does not have AR enabled.");if(Ue===$e.AR)throw new n("AR already launched.");const e=++qe;Ue===$e.Preview&&I&&!de&&we(),je($e.AR),M&&(We(Te,!1),We(Le,!1),We(De,!0)),P("vto_launched"),M&&(We(Ne,!1),We(Me,!0));const o=yield D;if(qe===e&&Xe===l&&(yield T,qe===e&&Xe===l)){try{yield J(ke,h,c)}catch(e){throw function(e){P("vto_camera_denied",{error:e})}(e),M&&(We(Me,!1),We(Ne,!0)),e}qe===e&&Xe===l&&(yield Q(o),qe===e&&Xe===l&&(yield function(){return t(this,void 0,void 0,(function*(){if(null!=j){if(X=!1,null==G){const e=ee(O),t=x(e);G=yield k(t),yield te(j,G,"user"===e)}j.setPaused(X),z.style.display=""}}))}(),qe===e&&Xe===l&&M&&We(Me,!1)))}})),W=()=>t(this,void 0,void 0,(function*(){if(!I)throw new n("Model does not have 3D enabled.");if(Ue===$e.Preview)throw new n("3D already launched.");const e=++qe;Ue===$e.AR&&m&&!X&&Z(),je($e.Preview),M&&(We(Te,!1),We(Le,!1),We(De,!0)),P("preview_launched"),M&&(We(Ne,!1),We(Me,!0));const t=yield H;if(qe!==e||Xe!==l)return;const o=yield B;if(qe!==e||Xe!==l)return;if(yield K,qe!==e||Xe!==l)return;if(yield fe(Ie,c),qe!==e||Xe!==l)return;const i=yield pe(t,o);qe===e&&Xe===l&&(ve(i),de=!1,me(),ne.style.display="",M&&We(Me,!1))})),F=()=>t(this,void 0,void 0,(function*(){if(Ue===$e.None)throw new n("Neither AR or 3D launched.");++qe,Ue===$e.AR?m&&!X&&Z():Ue===$e.Preview&&I&&!de&&we(),je($e.None),M&&(We(Me,!1),We(Ne,!1),We(De,!1),m&&We(Te,!0),I&&We(Le,!0))}));return M&&(m&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${y}/img/icons/${null!=e&&t[e]||t.Glasses}`;Te.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(c),Te.onclick=N),I&&(Le.onclick=W),De.onclick=F),"AR"===s?(yield N(),Je(l)):"3D"===s&&(yield W(),Je(l)),{launchAR:N,launch3D:W,closeAR:()=>t(this,void 0,void 0,(function*(){if(Ue!==$e.AR)throw new n("AR not launched.");++qe,m&&!X&&Z(),je($e.None),M&&(We(Me,!1),We(Ne,!1),We(De,!1),m&&We(Te,!0),I&&We(Le,!0))})),close3D:()=>t(this,void 0,void 0,(function*(){if(Ue!==$e.Preview)throw new n("3D not launched.");++qe,I&&!de&&we(),je($e.None),M&&(We(Me,!1),We(Ne,!1),We(De,!1),m&&We(Te,!0),I&&We(Le,!0))})),close:F}}))}function Je(e){if(Xe!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const Qe={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Ye(e)))}))},version:w};e.plugin=Qe})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{l(o.next(e))}catch(e){r(e)}}function a(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class n 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"],s=[2,12,7,1],a=window[r[s[s[i]]]][r[s[s[s.length-1]]]],l=a.charCodeAt(i),d=l^l,c=new o[1]([d]);function u(){const e=(new TextEncoder).encode(a),t=r.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[r[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=p)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),f(e,n+1)}}))}const v=["Glasses","Shoes","Watches"],w=["Shoes"];const m="0.0.6-alpha.0";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${m}/dist`;const g={update:e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>y};function b(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let C,E,R=!1;const A=[],S={organizationId:"Unknown",sku:"Unknown"};let x;function P(){k("vto_launched")}function k(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),S),{vtoTime:(performance.now()-x)/1e3,vtoSessionId:E}),$((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function $(e){R?e():A.push(e)}function M(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function _(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const I=200,T=10;let D,L,U,j,N=!1;function O(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let G,W,z,F,B,H,K,q=!0;function V(e){e!==j&&(j=e,U=O(e),H=null,null==G||G.clearEffect(),N=!0)}function Q(e,o,i){return t(this,void 0,void 0,(function*(){return z=i,F=e,null==B&&(B=(()=>t(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 s=Y(i),a=M(s);k("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);G=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),W=yield _(a),k("vto_camera_granted"),yield J(G,W,"user"===s),"Glasses"===i&&(yield L,function(e,n){t(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${g}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>t(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<T)return void i.push(t);clearInterval(r);const s=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",s,s,s,0),n.changeParameterVector("shopar_glasses","","scale",s,s,s,0)}))),I)}))}(W,G)),k("vto_init_success")})))()),B}))}function X(e){return t(this,void 0,void 0,(function*(){return null==H&&(H=G.switchEffect(e)),H}))}function Z(){null!=G&&(q=!0,G.setPaused(q),null!=W&&null!=W.srcObject&&W.srcObject instanceof MediaStream&&(W.srcObject.getTracks().forEach((e=>e.stop())),W=null),G.stopCamera(),F.style.display="none")}function Y(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function J(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),i()}))))}}))}))}function ee(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const te="shopar-error";function ne(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ee("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const oe="shopar-control";const ie="shopar-deepar-output";const re="shopar-loading";const se="shopar-main";const ae="shopar-qr-output";const le="shopar-three-output";var de;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(de||(de={}));let ce,ue,he,pe,fe,ve,we,me,ye,ge,be=de.None;function Ce(e){be=e}let Ee,Re=!1,Ae=null;function Se(){Re||(ce=function(){const e=document.createElement("div");e.id=se;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),ue=function(){const e=document.createElement("div");e.id=ae;const t=e.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="relative",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="flex",o.alignItems="center",o.justifyContent="center",e.appendChild(n);const i=new Image,r=i.style;return r.maxWidth="100%",r.maxHeight="100%",n.appendChild(i),e}(),ce.appendChild(ue),he=function(){const e=document.createElement("div");e.id=ie;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(he),pe=function(){const e=document.createElement("canvas");e.id=le;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(pe),fe=function(){const e=document.createElement("div");return e.id=oe,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ce.appendChild(fe),ve=ne("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),fe.appendChild(ve),we=ne("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${g}/img/icons/cube.svg`),fe.appendChild(we),me=ne("shopar-btn-close","Close","Close ShopAR view",`${g}/img/icons/close.svg`),fe.append(me),ye=function(){const e=document.createElement("div");e.id=re;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),ce.appendChild(ye),ge=function(){const e=document.createElement("div");e.id=te;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=ee("4rem",`${g}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.appendChild(r);const s=document.createElement("div");return s.className="shopar-error-body",s.textContent="Please refresh the page and allow the use of camera.",n.appendChild(s),e}(),ce.appendChild(ge),Re=!0)}function xe(e,t){e.style.display=t?"":"none"}function Pe(e){""===e.style.display&&xe(e,!1)}let ke,$e,Me,_e,Ie,Te=!0;function De(e,n){return t(this,void 0,void 0,(function*(){yield Ee;const t=`https://apps.deepar.ai/shopar-qr?${new URLSearchParams({a:e,s:n,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(t),i=ue.firstChild.firstChild,r=new Promise(((e,t)=>{i.onload=e,i.onerror=t}));i.src=o,yield r,Te=!1,ue.style.display=""}))}function Le(){Te=!0,ue.style.display="none"}let Ue,je,Ne,Oe,Ge,We,ze,Fe,Be,He,Ke,qe,Ve,Qe,Xe,Ze,Ye=!1,Je=!1;const et=45,tt=45,nt=3,ot=.1,it=3.5,rt=2,st=1;let at;function lt(e){if(e!==Me){const i=255;Me=e,$e=function(e,i,r){return t(this,void 0,void 0,(function*(){let s="glb".charCodeAt(0),a="3d".charCodeAt(0);s>>=1,s+=a;const l=String.fromCharCode(s+14);a>>=2,s^=a+2;const u=String.fromCharCode(s-3);s^=5;const h=String.fromCharCode(s-7);s^=2;const p=String.fromCharCode(s-7),v=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],w=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield v(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),m=new o[0](yield(yield w.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));r+=a;const y=m.byteLength;if(c[d]=Math.min(76,i)*((s>>5)-1),152===c[d]&&(c[d]=y),r==d)return m;r=d,r^=d;for(let e=0,t=m.length;e<t;e++)c[d]^=c[r]<<13,c[d]^=c[r]>>17,c[d]^=c[r]<<5,m[e]=m[e]^c[d];return r^=c[0],r^=c[1],r^=c[2],m}))}(e,(new Date).getTime()+i,Math.random()*i),at=null,null==Ve||Ve.clear()}}function dt(e,n){return t(this,void 0,void 0,(function*(){if(Ue=e,!Je){je=window.ShopAR__THREE,Ne=je.THREE,Oe=new Ne.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),Oe.outputEncoding=Ne.sRGBEncoding,Oe.toneMapping=Ne.ACESFilmicToneMapping,Oe.setPixelRatio(window.devicePixelRatio||1),Oe.setClearColor(new Ne.Color(16777215)),Ve=new Ne.Scene,Ge=new Ne.Group,Ge.position.y=-.7,We=new Ne.WebGLRenderTarget(512,512),We.texture.generateMipmaps=!1,ze=new Ne.WebGLRenderTarget(512,512),ze.texture.generateMipmaps=!1;const t=new Ne.PlaneGeometry(et,tt).rotateX(Math.PI/2),o=new Ne.MeshBasicMaterial({map:We.texture,opacity:st,transparent:!0,depthWrite:!1});Fe=new Ne.Mesh(t,o),Fe.renderOrder=1,Ge.add(Fe),Fe.scale.y=-1,Be=new Ne.Mesh(t),Be.visible=!1,Ge.add(Be),Xe=new Ne.OrthographicCamera(-et/2,et/2,tt/2,-tt/2,0,nt),Xe.rotation.x=Math.PI/2,Ge.add(Xe),He=new Ne.MeshDepthMaterial,He.userData.darkness={value:rt},He.onBeforeCompile=function(e){e.uniforms.darkness=He.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 `},He.depthTest=!1,He.depthWrite=!1,Ke=new Ne.ShaderMaterial(je.HorizontalBlurShader),Ke.depthTest=!1,qe=new Ne.ShaderMaterial(je.VerticalBlurShader),qe.depthTest=!1,Qe=new Ne.PerspectiveCamera(25,1,.5);const i=function(e){var t;const n={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);Qe.position.set(i[0],i[1],i[2]),Ze=new je.OrbitControls(Qe,Oe.domElement),Ze.target.set(0,.03,0),Ze.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{k("preview_interacted")}),200);Ze.addEventListener("end",e)}Je=!0}ft()}))}function ct(e,n){return t(this,void 0,void 0,(function*(){return null==at&&(at=(()=>t(this,void 0,void 0,(function*(){const t=new je.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(je,t.parse(n));o.mapping=Ne.EquirectangularReflectionMapping,o.encoding=Ne.LinearEncoding,Ve.environment=o;const i=(new je.GLTFLoader).setDRACOLoader((new je.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new je.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(Oe)).setMeshoptDecoder("function"==typeof je.MeshoptDecoder?je.MeshoptDecoder():je.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),at}))}function ut(e){return t(this,void 0,void 0,(function*(){Ve.add(e.scene);const t=(new Ne.Box3).setFromObject(e.scene);Ge.position.y=t.min.y-ot,Ve.add(Ge),Ve.traverse((e=>{if(e instanceof Ne.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ne.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ht(){Ye=!0,Ue.style.display="none"}function pt(){if(Ye)return;requestAnimationFrame(pt),ft(),Ze.update();const e=Ve.background;Ve.background=null,Ve.overrideMaterial=He;const t=Oe.getClearAlpha();Oe.setClearAlpha(0),Oe.setRenderTarget(We),Oe.render(Ve,Xe),Ve.overrideMaterial=null,vt(it),vt(.4*it),Oe.setRenderTarget(null),Oe.setClearAlpha(t),Ve.background=e,Oe.render(Ve,Qe)}function ft(){const e=Ue.clientWidth,t=Ue.clientHeight;Ue.width===e&&Ue.height===t||(Oe.setSize(e,t,!1),Qe.aspect=e/t,Qe.updateProjectionMatrix())}function vt(e){Be.visible=!0,Ke.uniforms.tDiffuse.value=We.texture,Ke.uniforms.h.value=1*e/256,Be.material=Ke,Oe.setRenderTarget(ze),Oe.render(Be,Xe),qe.uniforms.tDiffuse.value=ze.texture,qe.uniforms.v.value=1*e/256,Be.material=qe,Oe.setRenderTarget(We),Oe.render(Be,Xe),Be.visible=!1}function wt(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function mt(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const yt=["AR","3D"];function gt(e){const{apiKey:t,sku:o,targetElement:i,initialState:r,baseUrl:s,defaultUI:a}=e;wt(t,"apiKey"),mt(t,"apiKey"),wt(o,"sku"),mt(o,"sku"),wt(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",yt),null!=s&&mt(s,"baseUrl"),null!=a&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(a,"defaultUI")}let bt=0,Ct=0;function Et(e){var o,i;return t(this,void 0,void 0,(function*(){gt(e);const{apiKey:r,sku:s,targetElement:a,initialState:l}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(a),g.update(e.baseUrl);const d=function(e,o){return t(this,void 0,void 0,(function*(){const i=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield i.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(r,s);null==C&&(C=b(`${g}/shopar-analytics.js`),C.then((()=>{R=!0,E=window.ShopAR__analytics.uuidv4(),A.forEach((e=>e()))}))),function(e,t){S.organizationId=e,S.sku=t,x=performance.now(),$((()=>{window.ShopAR__analytics.initializeImpl()}))}(r,s),Se();const c=++Ct,{category:h,arUrl:p,arKey:m,previewUrl:y,previewEnvUrl:I}=yield d;Rt(c),k("initialized");const T=null!=p&&function(e){return null!=e&&v.includes(e)}(h),j=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled),N=T&&function(e){return null!=e&&w.includes(e)}(h),B=j&&N&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==K&&(K=b(`${g}/shopar-platform.js`)),yield K,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}());Rt(c),B&&function(){t(this,void 0,void 0,(function*(){null==Ee&&(Ee=b(`${g}/shopar-qr.js`))}))}();const H=T&&!B;H&&(null==D&&(D=b(`${g}/shopar-deepar.js`)),V(p),"Glasses"===h&&null==L&&(L=b(`${g}/shopar-true-scale.js`)));const ee=null!=y;var te;ee&&(null==ke&&(ke=b(`${g}/shopar-three.js`)),lt(y),(te=null!=I?I:`${g}/env/default.hdr`)!==Ie&&(Ie=te,_e=O(te))),function(e){e.style.position="relative",null==Ae?e.appendChild(ce):e!==Ae&&(Ae.removeChild(ce),e.appendChild(ce)),Ae=e}(a);const ne=null==e.defaultUI||e.defaultUI;if(function(e,t,n,o){xe(fe,e),xe(ve,e&&(n||t)&&be===de.None),xe(we,e&&o&&be===de.None),xe(me,e&&be!==de.None),e||Pe(ye),e||Pe(ge)}(ne,B,H,ee),be===de.AR){if(!q)if(H){const e=yield U;Rt(c),yield X(e),Rt(c)}else Z(),Ce(de.None),ne&&(xe(me,!1),(B||H)&&xe(ve,!0),ee&&xe(we,!0));if(!Te)if(B)try{yield De(r,s)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}else Le(),Ce(de.None),ne&&(xe(me,!1),(B||H)&&xe(ve,!0),ee&&xe(we,!0))}else if(be===de.Preview&&!Ye)if(ee){const e=yield $e;Rt(c);const t=yield _e;Rt(c);const n=yield ct(e,t);Rt(c),ut(n)}else ht(),Ce(de.None),ne&&(xe(me,!1),(B||H)&&xe(ve,!0),ee&&xe(we,!0));const oe=()=>t(this,void 0,void 0,(function*(){if(B){if(be===de.AR)throw new n("AR already launched.");const e=++bt;be===de.Preview&&ee&&!Ye&&ht(),Ce(de.AR),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),P(),ne&&(xe(ge,!1),xe(ye,!0));try{yield De(r,s)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}if(bt!==e||Ct!==c)return;return void(ne&&xe(ye,!1))}if(!H)throw new n("Model does not have AR enabled.");if(be===de.AR)throw new n("AR already launched.");const e=++bt;be===de.Preview&&ee&&!Ye&&ht(),Ce(de.AR),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),P(),ne&&(xe(ge,!1),xe(ye,!0));const o=yield U;if(bt===e&&Ct===c&&(yield D,bt===e&&Ct===c)){try{yield Q(he,m,h)}catch(e){throw function(e){k("vto_camera_denied",{error:e})}(e),ne&&(xe(ye,!1),xe(ge,!0)),e}bt===e&&Ct===c&&(yield X(o),bt===e&&Ct===c&&(yield function(){return t(this,void 0,void 0,(function*(){if(null!=G){if(q=!1,null==W){const e=Y(z),t=M(e);W=yield _(t),yield J(G,W,"user"===e)}G.setPaused(q),F.style.display=""}}))}(),bt===e&&Ct===c&&ne&&xe(ye,!1)))}})),ie=()=>t(this,void 0,void 0,(function*(){if(!ee)throw new n("Model does not have 3D enabled.");if(be===de.Preview)throw new n("3D already launched.");const e=++bt;be===de.AR&&(H&&!q&&Z(),Le()),Ce(de.Preview),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),k("preview_launched"),ne&&(xe(ge,!1),xe(ye,!0));const t=yield $e;if(bt!==e||Ct!==c)return;const o=yield _e;if(bt!==e||Ct!==c)return;if(yield ke,bt!==e||Ct!==c)return;if(yield dt(pe,h),bt!==e||Ct!==c)return;const i=yield ct(t,o);bt===e&&Ct===c&&(ut(i),Ye=!1,pt(),Ue.style.display="",ne&&xe(ye,!1))})),re=()=>t(this,void 0,void 0,(function*(){if(be===de.None)throw new n("Neither AR or 3D launched.");++bt,be===de.AR?(H&&!q&&Z(),Le()):be===de.Preview&&ee&&!Ye&&ht(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(B||H)&&xe(ve,!0),ee&&xe(we,!0))}));return ne&&((B||H)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${g}/img/icons/${null!=e&&t[e]||t.Glasses}`;ve.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(h),ve.onclick=oe),ee&&(we.onclick=ie),me.onclick=re),"AR"===l?(yield oe(),Rt(c)):"3D"===l&&(yield ie(),Rt(c)),{launchAR:oe,launch3D:ie,closeAR:()=>t(this,void 0,void 0,(function*(){if(be!==de.AR)throw new n("AR not launched.");++bt,H&&!q&&Z(),Le(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(B||H)&&xe(ve,!0),ee&&xe(we,!0))})),close3D:()=>t(this,void 0,void 0,(function*(){if(be!==de.Preview)throw new n("3D not launched.");++bt,ee&&!Ye&&ht(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(B||H)&&xe(ve,!0),ee&&xe(we,!0))})),close:re}}))}function Rt(e){if(Ct!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const At={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Et(e)))}))},version:m};e.plugin=At})); |
{ | ||
"name": "shopar-plugin", | ||
"version": "0.0.5", | ||
"version": "0.0.6-alpha.0", | ||
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.", | ||
@@ -39,2 +39,4 @@ "scripts": { | ||
"deepar": "5.5.1", | ||
"platform": "^1.3.6", | ||
"qrcode": "1.5.1", | ||
"three": "0.151.3", | ||
@@ -49,2 +51,4 @@ "uuid": "^9.0.1" | ||
"@trivago/prettier-plugin-sort-imports": "^4.2.0", | ||
"@types/platform": "^1.3.6", | ||
"@types/qrcode": "^1.5.5", | ||
"@types/three": "0.151.0", | ||
@@ -61,2 +65,3 @@ "@types/uuid": "^9.0.6", | ||
"rollup-plugin-dts": "^6.0.0", | ||
"rollup-plugin-polyfill-node": "^0.13.0", | ||
"tslib": "^2.6.2", | ||
@@ -63,0 +68,0 @@ "typescript": "^5.0.4" |
@@ -35,3 +35,3 @@ # ShopAR Plugin | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.5/dist/shopar-plugin.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@{{VERSION}}/dist/shopar-plugin.js"></script> | ||
``` | ||
@@ -126,3 +126,3 @@ | ||
- If provided, defines where the additional ShopAR plugin files are fetched from. | ||
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.5/dist` | ||
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@{{VERSION}}/dist` | ||
@@ -129,0 +129,0 @@ ## License |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20969487
23
8048
7
21
+ Addedplatform@^1.3.6
+ Addedqrcode@1.5.1
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcliui@6.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddijkstrajs@1.0.3(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedencode-utf8@1.0.3(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedplatform@1.3.6(transitive)
+ Addedpngjs@5.0.0(transitive)
+ Addedqrcode@1.5.1(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@15.4.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)