shopar-plugin 0.7.2 → 0.7.3-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem}.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}.shopar-btn:hover{background-color:#f5f5f5}.shopar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}.shopar-3d{background-color:#fff}.shopar-3d-poster{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 o=[Uint8Array,Uint32Array],r=o.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[i[a[a[r]]]][i[a[a[a.length-1]]]],l=s.charCodeAt(r),c=l^l,u=new o[1]([c]);function d(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],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)}}))}function m(e){return e*(180/Math.PI)}function g(e){return Math.round(100*e)/100}const v=["Glasses","Shoes","Watches"],w=["Shoes"];const y="0.7.2";let b=`https://cdn.jsdelivr.net/npm/shopar-plugin@${y}/dist`;const E={update:e=>{null!=e&&(b=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>b};function A(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let S;const R=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.error('No <meta name="viewport"> detected. This might cause ShopAR to crash on iOS.\nPlease add the following line to your HTML:\n<meta name="viewport" content="width=device-width, initial-scale=1.0">'),()=>e?window.devicePixelRatio:1})();let T,M,P;function C(e){const t=function(e){const t=new M.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,M.ClampToEdgeWrapping,M.ClampToEdgeWrapping,M.LinearFilter,M.LinearFilter,1,M.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(P.parse(e));return t.mapping=M.EquirectangularReflectionMapping,t.colorSpace=M.LinearSRGBColorSpace,t}const I=45,x=45,k=3,L=1.5,U=1,$=.5;let D,O,_,N,j,F=!1;const W=4,q=.001,G=1e-7,z=10,V=11,B=1/(V-1),Q="function"==typeof Float32Array;function K(e,t,n,o){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===o)return ee;const r=Q?new Float32Array(V):new Array(V);for(let t=0;t<V;++t)r[t]=Y(t*B,e,n);function i(t){let o=0,i=1;const a=V-1;for(;i!==a&&r[i]<=t;++i)o+=B;--i;const s=o+(t-r[i])/(r[i+1]-r[i])*B,l=J(s,e,n);return l>=q?function(e,t,n,o){for(let r=0;r<W;++r){const r=J(t,n,o);if(0===r)return t;t-=(Y(t,n,o)-e)/r}return t}(t,s,e,n):0===l?s:function(e,t,n,o,r){let i,a,s=0;do{a=t+(n-t)/2,i=Y(a,o,r)-e,i>0?n=a:t=a}while(Math.abs(i)>G&&++s<z);return a}(t,o,o+B,e,n)}return function(e){return 0===e||1===e?e:Y(i(e),t,o)}}function H(e,t){return 1-3*t+3*e}function X(e,t){return 3*t-6*e}function Z(e){return 3*e}function Y(e,t,n){return((H(t,n)*e+X(t,n))*e+Z(t))*e}function J(e,t,n){return 3*H(t,n)*e*e+2*X(t,n)*e+Z(t)}function ee(e){return e}function te(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=K(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function ne(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort(((e,t)=>e.time-t.time)).map((({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:te(n)})));let o=0,r=n[0].value;return{reset:()=>{o=0},update:e=>{for(o+=e;o>=t;)o-=t;for(let e=0;e<n.length-1;e++){const t=n[e],i=n[e+1];if(o>=t.time&&o<i.time){const e=t.interpolate((o-t.time)/(i.time-t.time));r=t.value+e*(i.value-t.value)}}},get:()=>r}}const oe="#",re="time",ie="interpolation",ae="yaw",se="pitch",le="fov",ce=[re,ae,se,le,ie],ue="s",de="ms",he=1e3,pe="deg",fe="rad",me=Math.PI/180,ge="ease-in-out",ve="cubic-bezier(",we=")";function ye(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map((e=>function(e){const t=e.indexOf(oe);return(-1!==t?e.substring(0,t):e).trim()}(e))).filter((e=>""!==e))}(e);if(null==t)throw new Error("Header missing.");const o=function(e){const t=[];for(let n=0;n<e.length;n++){const o=e[n];if(!ce.includes(o))throw new Error(`Invalid token in header: '${o}'.`);if(t.includes(o))throw new Error(`Duplicate token in header: '${o}'.`);t.push(o)}if(!t.includes(re))throw new Error(`Missing required token: '${re}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:i}=be(o,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=i&&(null==r.fov&&(r.fov=[]),r.fov.push(i))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const o of e){const{time:e,pitch:r,yaw:i,fov:a}=o;if(null==e)throw new Error("Time missing.");const s=Ae(null!==(t=o.interpolation)&&void 0!==t?t:ge);null!=i&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:i*me,interpolation:s})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*me,interpolation:s})),null!=a&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:a*me,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every((t=>t.length!==e.length)))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function be(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter((e=>!(null==n?void 0:n.includes(e)))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter((t=>!e.includes(t))).join(", ")}'.`);const o=e.indexOf(re),r=function(e){if(e.endsWith(de))return Re(e.substring(0,e.length-de.length));if(e.endsWith(ue))return Re(e.substring(0,e.length-ue.length))*he;return Re(e)}(n[o]),i=e.indexOf(ie),a=Ae(-1===i?ge:n[i]),s={};for(let t=0;t<n.length;t++){if(t===o||t===i)continue;const l=e[t],c=n[t];switch(l){case ae:s.theta={time:r,value:Ee(c),interpolation:a};break;case se:s.phi={time:r,value:Ee(c),interpolation:a};break;case le:s.fov={time:r,value:Ee(c),interpolation:a};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function Ee(e){return e.endsWith(pe)?Re(e.substring(0,e.length-pe.length))*me:e.endsWith(fe)?Re(e.substring(0,e.length-fe.length)):Re(e)*me}function Ae(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Se(0,0,1,1);if("sine"===e)return Se(.37,0,.63,1);if("sine-in"===e)return Se(.12,0,.39,0);if("sine-out"===e)return Se(.61,1,.88,1);if("ease"===e)return Se(.25,.1,.25,1);if("ease-in"===e)return Se(.42,0,1,1);if("ease-out"===e)return Se(0,0,.58,1);if("ease-in-out"===e)return Se(.42,0,.58,1);if(e.startsWith(ve)&&e.endsWith(we)){const t=e.substring(ve.length,e.length-we.length).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Re(t[0]),y1:Re(t[1]),x2:Re(t[2]),y2:Re(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Se(e,t,n,o){return{type:"bezier",x1:e,y1:t,x2:n,y2:o}}function Re(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}const Te=300,Me=2e3,Pe=.05,Ce=2*Math.PI/32,Ie=Ae("hold"),xe=Ae("sine"),ke=Ae("sine-in"),Le=Ae("sine-out");const Ue=8,$e=2*Math.PI,De=$e/12,Oe=$e/60,_e=$e/60,Ne=60,je=60,Fe=1e3,We=Ne*je,qe=-1;let Ge;const ze=0,Ve=3;let Be,Qe,Ke,He=!1,Xe=1,Ze=1,Ye=1;const Je=1;let et;const tt=new Map;function nt(e,n,o){const r=e.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,l,c,u,d,h,p,f,m,g,v,w,y,b=!1,E=!1,A=!1,S=!0,R=!1,U=1,F=!0,W=!1,q=0,G=0,z=1,V=1,B=1;const Q={threeInit:()=>{b||(ot(),i=new Qe.Scene,a=new Qe.PerspectiveCamera(25,1,.5),s=new Be.OrbitControls(a,e),s.setInteractionEnabled(F),h=Qe.ACESFilmicToneMapping,({renderShadow:c,shadowGroup:l}=function(e){const t=new D.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new D.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new D.Group;o.position.y=-.7;const r=new D.PlaneGeometry(I,x).rotateX(Math.PI/2),i=new D.MeshBasicMaterial({map:t.texture,opacity:$,transparent:!0,depthWrite:!1}),a=new D.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new D.Mesh(r);s.visible=!1,o.add(s);const l=new D.OrthographicCamera(-I/2,I/2,x/2,-x/2,0,k);function c(e){s.visible=!0,N.uniforms.tDiffuse.value=t.texture,N.uniforms.h.value=1*e/256,s.material=N,O.setRenderTarget(n),O.render(s,l),j.uniforms.tDiffuse.value=n.texture,j.uniforms.v.value=1*e/256,s.material=j,O.setRenderTarget(t),O.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,o.add(l),{shadowGroup:o,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=_;const o=O.getClearAlpha();O.setClearAlpha(0),O.setRenderTarget(t),O.render(e,l),e.overrideMaterial=null,c(L),c(.4*L),O.setRenderTarget(null),O.setClearAlpha(o),e.background=n}}}(i)),b=!0)},threeParse:(e,n,o)=>t(this,void 0,void 0,(function*(){return null!=u&&d===o||(yield u,u=(()=>t(this,void 0,void 0,(function*(){var t,o;return M=(t=Be).THREE,P=new t.RGBELoader,i.environment=C(n),function(e,t){const{THREE:n}=t;T=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder(t.MeshoptDecoder)}(et,Be),o=e,T.parseAsync(o.buffer,"")})))(),d=o),u})),threeLoad:(e,t)=>{i.traverse((e=>{var t,n;e instanceof Qe.Mesh&&(null===(t=e.geometry)||void 0===t||t.dispose(),Array.isArray(e.material)?e.material.forEach((e=>e.dispose())):null===(n=e.material)||void 0===n||n.dispose())})),i.clear(),i.add(e.scene);const n=(new Qe.Box3).setFromObject(e.scene);l.position.y=n.min.y-ze,i.add(l),c(),E=!1,i.traverse((e=>{if(e instanceof Qe.Mesh){e.material.depthWrite=!0;const t=e.material;Array.isArray(t)?t.forEach((e=>{e.transmission>0&&(E=!0)})):t.transmission>0&&(E=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(Be.reduceVertices(e.scene,((e,t)=>Math.max(e,o.distanceToSquared(t))),0));s.reset(o,r,function(e,t){var n;const o={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?o.Glasses:null!==(n=o[e])&&void 0!==n?n:o.Glasses).normalize()}(t,Qe.Vector3)),q=0,y="Watches"===t?function(e){const t=e.getObjectByName("hours"),n=e.getObjectByName("minutes"),o=e.getObjectByName("seconds");if(null==t&&null==n&&null==o)return null;let r=new Date;return{update:()=>{const e=new Date;if(Math.abs(e.getTime()-r.getTime())<Fe/Ue)return!1;r=e;const i=e.getHours(),a=e.getMinutes(),s=e.getSeconds(),l=e.getMilliseconds();return null!=t&&(t.rotation.y=qe*De*(i+a/Ne+s/We)),null!=n&&(n.rotation.y=qe*Oe*(a+s/je)),null!=o&&(o.rotation.y=qe*_e*(s+l/Fe)),!0}}}(e.scene):null},threePaused:()=>S,threeResume:()=>{S=!1,et.setAnimationLoop(rt),e.style.visibility="visible",G=0,null==f||f.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset(),null==w||w.reset()},threePause:()=>{S=!0,function(){for(const{threePaused:e}of tt.values())if(!e())return!1;return!0}()&&et.setAnimationLoop(null),e.style.visibility="hidden",o.style.opacity="0",n.style.visibility="hidden"},threeSetZoomEnabled:e=>{s.enableZoom=e},threeSetForcedTransparency:e=>{A=e},threeSetToneMapping:(e,t)=>{const n={ACES:Qe.ACESFilmicToneMapping,Linear:Qe.LinearToneMapping,Neutral:Qe.NeutralToneMapping};null!=n[e]&&(h=n[e]),U=t},threeIsInteractive:()=>F,threeSetInteractive:e=>{F=e,null==s||s.setInteractionEnabled(F)},threeSetOnInteracted:e=>{s.removeEventListener("change",p),p=e,s.addEventListener("change",e)},threeInitPromptAnimation:()=>{var e;e=s.getTheta(),f=ne([{time:0,value:e,interpolation:Ie},{time:Te,value:e,interpolation:Le},{time:Te+Me/4,value:e+Ce,interpolation:xe},{time:Te+3*Me/4,value:e-Ce,interpolation:ke},{time:Te+Me,value:e,interpolation:Ie},{time:Te+2*Me,value:e,interpolation:Ie}]),s.setTheta(f.get()),m=null,g=null,v=ne([{time:0,value:0,interpolation:Ie},{time:Te,value:1,interpolation:Ie},{time:Te+Me,value:0,interpolation:Ie},{time:Te+2*Me,value:0,interpolation:Ie}]),w=ne([{time:0,value:0,interpolation:Ie},{time:Te,value:0,interpolation:Le},{time:Te+Me/4,value:-Pe,interpolation:xe},{time:Te+3*Me/4,value:Pe,interpolation:ke},{time:Te+Me,value:0,interpolation:Ie},{time:Te+2*Me,value:0,interpolation:Ie}])},threeInitThetaAnimation:e=>{f=e,null!=e&&s.setTheta(e.get())},threeInitPhiAnimation:e=>{m=e,null!=e&&s.setPhi(e.get())},threeInitFovAnimation:e=>{g=e,null!=e&&s.setFovRadians(e.get())},preRender_:e=>{if(!b||S)return;let t=0!==G?e-G:0;G=e,0===q?R=!0:q<Ve&&(t=0),q++,W||(s.hasUserInteracted()?(W=!0,f=null,m=null,g=null,v=null,w=null):(null==f||f.update(t),null==m||m.update(t),null==g||g.update(t),null==v||v.update(t),null==w||w.update(t),null!=f&&(s.setTheta(f.get()),R=!0),null!=m&&(s.setPhi(m.get()),R=!0),null!=g&&(s.setFovRadians(g.get()),R=!0))),s.update()&&(R=!0),(null==y?void 0:y.update())&&(R=!0)},shouldRender_:()=>!(!b||S)&&R,render_:()=>{const t=et.toneMapping,s=et.toneMappingExposure;et.toneMapping=h,et.toneMappingExposure=U,et.setViewport(0,0,e.width,e.height),et.setClearColor(new Qe.Color(16777215),E&&!A?1:0),et.render(i,a),et.toneMapping=t,et.toneMappingExposure=s,R=!1,null!=r&&(r.clearRect(0,0,e.width,e.height),Ke.width>0&&Ke.height>0&&r.drawImage(Ke,0,Ze-e.height,e.width,e.height,0,0,e.width,e.height),n.style.visibility=F&&!W?"visible":"hidden",null!=v&&(o.style.opacity=`${v.get()}`),null!=w&&(o.style.transform=`translateX(${w.get()*Math.min(z,V)}px)`))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===z&&n===V&&Ye===B||(e.width=Math.ceil(t*Ye*Je),e.height=Math.ceil(n*Ye*Je),z=t,V=n,B=Ye,R=!0)},target_:e};return tt.set(e,Q),Q}function ot(){if(He)return;Be=window.ShopAR__THREE,Qe=Be.THREE,Ke=document.createElement("canvas");var e,t;Ke.style.position="block",et=new Qe.WebGLRenderer({powerPreference:"high-performance",canvas:Ke,antialias:!0,alpha:!0}),et.outputColorSpace=Qe.SRGBColorSpace,et.toneMapping=Qe.ACESFilmicToneMapping,et.setClearColor(new Qe.Color(16777215),0),e=et,t=Be,F||(D=t.THREE,O=e,_=new D.MeshDepthMaterial,_.userData.darkness={value:U},_.onBeforeCompile=e=>{e.uniforms.darkness=_.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},_.depthTest=!1,_.depthWrite=!1,N=new D.ShaderMaterial(t.HorizontalBlurShader),N.depthTest=!1,j=new D.ShaderMaterial(t.VerticalBlurShader),j.depthTest=!1,F=!0),it(),He=!0}function rt(e){it(),et.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of tt.values())t(e),n()&&o()}function it(){let e=0,t=0;for(const{target_:n}of tt.values()){const{clientWidth:o,clientHeight:r}=n;e=Math.max(e,o),t=Math.max(t,r)}const n=R();e=Math.ceil(e*n*Je),t=Math.ceil(t*n*Je),e===Xe&&t===Ze&&n===Ye||(Xe=e,Ze=t,Ye=n,et.setSize(Xe,Ze,!1));for(const{updateSize_:e}of tt.values())e()}const at={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},st=Object.keys(at);function lt(e){return at[e]}const ct="shopar-error";function ut(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}function dt(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=ut("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=t,r.appendChild(e)}r.ariaLabel=n;const i=r.style;return i.display="none",i.pointerEvents="auto",r}const ht="shopar-control";const pt="shopar-deepar-output";function ft(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.pointerEvents="auto",n.userSelect="none",t}function mt(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function gt(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function vt(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const wt="shopar-main";const yt="shopar-qr-output";const bt="shopar-three-output";var Et;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(Et||(Et={}));let At=!1;function St(){At||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),At=!0)}function Rt(){St();const e=function(){const e=document.createElement("div");e.id=wt;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",t.pointerEvents="none",e}(),t=function(){const e=document.createElement("div");return e.style.textAlign="center",e}(),n=function(){const e=new Image;e.draggable=!1;const t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),o=function(e,t){const n=document.createElement("div");n.id=yt;const o=n.style;o.position="absolute",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="none",o.pointerEvents="auto",o.userSelect="none";const r=document.createElement("div");r.className="shopar-qr";const i=r.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(r),r.appendChild(e);const a=document.createElement("div");return a.appendChild(t),r.appendChild(a),n}(t,n);e.appendChild(o);const r=function(){const e=document.createElement("div");e.id=pt;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",t.pointerEvents="auto",e}();e.appendChild(r);const i=function(){const e=document.createElement("canvas");e.id=bt,e.className="shopar-3d";const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",t.pointerEvents="auto",e}();e.appendChild(i);const a=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),s=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),l=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:o}=n;return o.position="absolute",o.width="100%",o.height="100%",o.opacity="0",n.appendChild(e),n.appendChild(t),n}(a,s);e.appendChild(l);const c=function(){const e=ut("2rem",`${E}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),u=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",t.appendChild(e),t}(c);e.appendChild(u);const d=ft("shopar-ar-loading-container"),h=mt("shopar-ar-loading-text",lt("loading.ar"));d.appendChild(h);const p=gt("shopar-ar-loading-bar-bg"),f=vt("shopar-ar-loading-bar-fg");p.appendChild(f),d.appendChild(p),e.appendChild(d);const m=ft("shopar-3d-loading-container"),g=mt("shopar-3d-loading-text",lt("loading.3d"));m.appendChild(g);const v=gt("shopar-3d-loading-bar-bg"),w=vt("shopar-3d-loading-bar-fg");v.appendChild(w),m.appendChild(v),e.appendChild(m);const y=function(){const e=document.createElement("div");e.className="shopar-3d-poster";const{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.pointerEvents="auto",t.userSelect="none",e}(),b=function(){const e=new Image;e.draggable=!1;const{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.objectFit="contain",e}();y.appendChild(b),e.appendChild(y);const A=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),S=function(e){const t=document.createElement("div");t.id=ct;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none",n.pointerEvents="auto",n.userSelect="none";const o=document.createElement("div"),r=o.style;return r.position="absolute",r.width="100%",r.height="100%",r.backgroundColor="#ffffff",r.display="flex",r.flexDirection="column",r.justifyContent="center",r.alignItems="center",t.appendChild(o),o.appendChild(e),t}(A);e.appendChild(S);const R=function(){const e=document.createElement("div");return e.id=ht,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(R);const T=dt("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");R.appendChild(T);const M=dt("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${E}/img/icons/cube.svg`);R.appendChild(M);const P=dt("shopar-btn-close","Close","Close ShopAR view",`${E}/img/icons/close.svg`);R.append(P);let C,I,x=Et.None,k=!1,L=!1,U=!1,$=!1;function D(){f.classList.remove("active"),d.style.visibility="hidden"}function O(){y.style.visibility="hidden",w.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return o},getQRImage:function(){return n},getDeepARTarget:function(){return r},getDeepARPrompt:function(){return l},getThreeTarget:function(){return i},getThreePrompt:function(){return u},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){A.textContent=null!=e?e:"Please reload page and allow camera access to continue"},customizeQRPrompt:function(e){t.textContent=null!=e?e:"Scan on mobile or tablet to try on"},setVisibilityParameters:function(e,t,n,o,r,i){var a;k=e,L=t,U=n,$=o,C=r,I=i,Tt(R,k),Tt(T,k&&(U||L)&&x===Et.None),Tt(M,k&&$&&x===Et.None),Tt(P,k&&x!==Et.None),D(),O(),k||""===(a=S).style.display&&Tt(a,!1)},getUIState:function(){return x},setUIState:function(e){x=e,x===Et.None?(D(),O(),k&&(Tt(S,!1),Tt(P,!1),(L||U)&&Tt(T,!0),$&&Tt(M,!0))):x===Et.QR||x===Et.AR?k&&(Tt(S,!1),Tt(T,!1),Tt(M,$&&"AR"===I),Tt(P,"AR"!==I)):x===Et.Preview&&k&&(Tt(S,!1),Tt(T,(L||U)&&"3D"===I),Tt(M,!1),Tt(P,"3D"!==I))},setDefaultUIActions:function(e,t,n){k&&((L||U)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${E}/img/icons/${n}`;T.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(C),T.onclick=e),$&&(M.onclick=t),P.onclick=n)},startDeepARLoading:function(){f.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:D,startThreeLoading:function(){null!=b.dataset.srcSet?y.style.visibility="visible":(w.classList.add("active"),m.style.visibility="visible")},stopThreeLoading:O,setThreePosterUrl:function(e){null!=e?(b.src=e,b.dataset.srcSet="true"):delete b.dataset.srcSet},showCameraError:function(){k&&Tt(S,!0)}}}function Tt(e,t){e.style.display=t?"":"none"}const Mt=new Map;function Pt(e){let n=Mt.get(e);return null==n?(n=function(){let e=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Rt()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:e,getQRImage:n}=i();o=function(e,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>t(this,void 0,void 0,(function*(){yield S;const t=`https://ar.shopar.ai/${y.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:r,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(t),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,o=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){o=!0,e.style.display="none"}))}}(e(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();r=nt(e(),t(),n())}return r}}}(),Mt.set(e,n)):n.incrementSetupId_(),n}function Ct(e){for(const t of Mt.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===Et.AR&&r(Et.None)}}let It;const xt=new Uint8Array(16);function kt(){if(!It&&(It="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!It))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return It(xt)}const Lt=[];for(let e=0;e<256;++e)Lt.push((e+256).toString(16).slice(1));var Ut={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function $t(e,t,n){if(Ut.randomUUID&&!t&&!e)return Ut.randomUUID();const o=(e=e||{}).random||(e.rng||kt)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return Lt[e[t+0]]+Lt[e[t+1]]+Lt[e[t+2]]+Lt[e[t+3]]+"-"+Lt[e[t+4]]+Lt[e[t+5]]+"-"+Lt[e[t+6]]+Lt[e[t+7]]+"-"+Lt[e[t+8]]+Lt[e[t+9]]+"-"+Lt[e[t+10]]+Lt[e[t+11]]+Lt[e[t+12]]+Lt[e[t+13]]+Lt[e[t+14]]+Lt[e[t+15]]}(o)}const Dt="qrLaunch",Ot="arLaunch",_t="previewLaunch",Nt="heartbeat";let jt,Ft,Wt=!1,qt=window.navigator.userAgent||"no user agent";const Gt=[];function zt(){null==jt&&(Ft=$t(),jt=A(`${E}/shopar-analytics.js`),jt.then((()=>{Wt=!0,window.ShopAR__analytics.initializeImpl(),Gt.forEach((e=>e()))})))}function Vt(e){Wt?e():Gt.push(e)}function Bt(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Qt(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 Kt=200,Ht=10;let Xt=!1,Zt=null,Yt=[],Jt=[];function en(e){return t(this,void 0,void 0,(function*(){Xt=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${E}/wasm/mediapipe`,e),Zt&&clearInterval(Zt);const o=[],r=[];Zt=setInterval((()=>t(this,void 0,void 0,(function*(){if(Xt)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());Xt||(null!=a&&null!=s&&function(e){for(let t of Yt)t(e)}({translation:a,rotation:s}),null==e&&(o.push(t),r.push(i),o.length<Ht||(o.shift(),r.shift(),function(e,t){for(let n of Jt)n({faceWidth:e,IPD:t})}(nn(o),nn(r)))))}))),Kt)}))}function tn(){Jt=[],Yt=[],Xt=!0}function nn(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}function on(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}var rn="undefined"!=typeof Float32Array?Float32Array:Array;function an(){var e=new rn(16);return rn!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function sn(e,t,n){var o=t[0],r=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],u=t[7],d=t[8],h=t[9],p=t[10],f=t[11],m=t[12],g=t[13],v=t[14],w=t[15],y=n[0],b=n[1],E=n[2],A=n[3];return e[0]=y*o+b*s+E*d+A*m,e[1]=y*r+b*l+E*h+A*g,e[2]=y*i+b*c+E*p+A*v,e[3]=y*a+b*u+E*f+A*w,y=n[4],b=n[5],E=n[6],A=n[7],e[4]=y*o+b*s+E*d+A*m,e[5]=y*r+b*l+E*h+A*g,e[6]=y*i+b*c+E*p+A*v,e[7]=y*a+b*u+E*f+A*w,y=n[8],b=n[9],E=n[10],A=n[11],e[8]=y*o+b*s+E*d+A*m,e[9]=y*r+b*l+E*h+A*g,e[10]=y*i+b*c+E*p+A*v,e[11]=y*a+b*u+E*f+A*w,y=n[12],b=n[13],E=n[14],A=n[15],e[12]=y*o+b*s+E*d+A*m,e[13]=y*r+b*l+E*h+A*g,e[14]=y*i+b*c+E*p+A*v,e[15]=y*a+b*u+E*f+A*w,e}function ln(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function cn(e,t){var n=t[0],o=t[1],r=t[2],i=t[4],a=t[5],s=t[6],l=t[8],c=t[9],u=t[10];return e[0]=Math.hypot(n,o,r),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(l,c,u),e}function un(e,t,n,o){var r=t[0],i=t[1],a=t[2],s=t[3],l=r+r,c=i+i,u=a+a,d=r*l,h=r*c,p=r*u,f=i*c,m=i*u,g=a*u,v=s*l,w=s*c,y=s*u,b=o[0],E=o[1],A=o[2];return e[0]=(1-(f+g))*b,e[1]=(h+y)*b,e[2]=(p-w)*b,e[3]=0,e[4]=(h-y)*E,e[5]=(1-(d+g))*E,e[6]=(m+v)*E,e[7]=0,e[8]=(p+w)*A,e[9]=(m-v)*A,e[10]=(1-(d+f))*A,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function dn(){var e=new rn(3);return rn!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function hn(e,t,n){var o=new rn(3);return o[0]=e,o[1]=t,o[2]=n,o}function pn(e,t){var n=t[0]-e[0],o=t[1]-e[1],r=t[2]-e[2];return Math.hypot(n,o,r)}function fn(e,t,n){var o=t[0],r=t[1],i=t[2],a=n[3]*o+n[7]*r+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*o+n[4]*r+n[8]*i+n[12])/a,e[1]=(n[1]*o+n[5]*r+n[9]*i+n[13])/a,e[2]=(n[2]*o+n[6]*r+n[10]*i+n[14])/a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function mn(){var e=new rn(4);return rn!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}dn(),function(){var e,t=(e=new rn(4),rn!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var gn;let vn,wn,yn;dn(),hn(1,0,0),hn(0,1,0),mn(),mn(),gn=new rn(9),rn!=Float32Array&&(gn[1]=0,gn[2]=0,gn[3]=0,gn[5]=0,gn[6]=0,gn[7]=0),gn[0]=1,gn[4]=1,gn[8]=1;let bn,En,An,Sn,Rn=!0,Tn=null;const Mn=new Set;let Pn,Cn,In,xn,kn,Ln;function Un(){null==vn&&(vn=A(`${E}/shopar-deepar.js`))}function $n(){null==wn&&(wn=A(`${E}/shopar-true-scale.js`))}function Dn(e){return t(this,void 0,void 0,(function*(){const{licenseKey:o,truescaleUsecase:r}=e;return kn=r,null==Pn&&(Pn=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(e=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))throw new n("No camera available!");var e;const t=zn(An),r=Bt(t);bn=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:Sn,additionalOptions:{hint:Ln,cameraConfig:{disableDefaultCamera:!0}}}),En=yield Qt(r),yield Vn(bn,En,"user"===t),"Glasses"===An&&(yield wn,en(En),"DetectionLoop"!==kn&&Hn((e=>{xn=e.faceWidth})))})))()),Pn}))}function On(e,t){var n,o;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===An&&(n=t,o=Ln,n===o||null!=n&&null!=o&&n.length===o.length&&n.every((e=>o.find((t=>e===t))))&&o.every((e=>n.find((t=>t===e))))))||(null!=bn&&(bn.shutdown(),bn=null,Pn=null),An=e,Ln=t)}function _n(e){e!==Sn&&(Sn=e,null!=bn&&bn.changePreviewElement(Sn))}function Nn(e){Tn=e}function jn(e){bn.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(xn){const e=137/(xn+5);bn.changeParameterVector("GLASSES","","scale",e,e,e,0),bn.changeParameterVector("shopar_glasses","","scale",e,e,e,0),function(e){const t=[-8.362421,4.549,-9.275],n=[8.362421,4.549,-9.275];try{const o=Qn("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=Qn("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);bn.changeParameterVector("temple_left","","rotation",0,56.6*-o,0,0),bn.changeParameterVector("temple_right","","rotation",0,56.6*-r,0,0)}catch(e){return}}(e),tn(),xn=null}e(),Bn("Glasses")}},bn.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Bn("Shoes"))},bn.callbacks.onWristTracked=t=>{t.detected&&(e(),Bn("Watches"))}}function Fn(e,n,o){return t(this,void 0,void 0,(function*(){return null!=Cn&&In===o||(yield Cn,Cn=bn.switchEffect(e,{envmap:n}),In=o),Cn}))}function Wn(e,t){null!=e&&null!=t&&(bn.setToneMapping(e),bn.setExposure(t))}function qn(){return t(this,void 0,void 0,(function*(){if(null!=bn){if(Rn=!1,null==En){const e=zn(An),t=Bt(e);En=yield Qt(t),yield Vn(bn,En,"user"===e),"Glasses"===An&&(en(En),"DetectionLoop"!==kn&&Hn((e=>{xn=e.faceWidth})))}!function(){if(null==Tn)return;if(null==An||Mn.has(An))return;Tn.style.visibility="visible",Tn.style.opacity="1"}(),bn.setPaused(Rn),Sn.style.display=""}}))}function Gn(){null!=bn&&(Rn=!0,bn.setPaused(Rn),tn(),null!=En&&null!=En.srcObject&&En.srcObject instanceof MediaStream&&(En.srcObject.getTracks().forEach((e=>e.stop())),En=null),function(){if(null==Tn)return;Tn.style.visibility="hidden",Tn.style.opacity="0"}(),bn.stopCamera(),Sn.style.display="none")}function zn(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Vn(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),r()}))))}}))}))}function Bn(e){null!=Tn&&(Mn.has(e)||(Mn.add(e),Tn.style.opacity="0"))}function Qn(e,t,n,o,r,i,a){const s=bn.getTransformationBetween(e,t),l=ln(dn(),s),c=function(e,t){var n=new rn(3);cn(n,t);var o=1/n[0],r=1/n[1],i=1/n[2],a=t[0]*o,s=t[1]*r,l=t[2]*i,c=t[4]*o,u=t[5]*r,d=t[6]*i,h=t[8]*o,p=t[9]*r,f=t[10]*i,m=a+u+f,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(d-p)/g,e[1]=(h-l)/g,e[2]=(s-c)/g):a>u&&a>f?(g=2*Math.sqrt(1+a-u-f),e[3]=(d-p)/g,e[0]=.25*g,e[1]=(s+c)/g,e[2]=(h+l)/g):u>f?(g=2*Math.sqrt(1+u-a-f),e[3]=(h-l)/g,e[0]=(s+c)/g,e[1]=.25*g,e[2]=(d+p)/g):(g=2*Math.sqrt(1+f-a-u),e[3]=(s-c)/g,e[0]=(h+l)/g,e[1]=(d+p)/g,e[2]=.25*g),e}(mn(),s);un(s,c,l,hn(a,a,a));const u=bn.getTransformationBetween(t,n),d=ln(dn(),u);un(u,mn(),d,cn(dn(),u));const h=sn(an(),s,u),p=ln(dn(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=bn.getTransformationBetween(n,o)}catch(e){return f}const g=sn(an(),u,m),v=sn(an(),s,g),w=hn(p[0],i[1],i[2]),y=fn(dn(),w,function(e,t){var n=t[0],o=t[1],r=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],u=t[8],d=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15],w=n*s-o*a,y=n*l-r*a,b=n*c-i*a,E=o*l-r*s,A=o*c-i*s,S=r*c-i*l,R=u*m-d*f,T=u*g-h*f,M=u*v-p*f,P=d*g-h*m,C=d*v-p*m,I=h*v-p*g,x=w*I-y*C+b*P+E*M-A*T+S*R;return x?(x=1/x,e[0]=(s*I-l*C+c*P)*x,e[1]=(r*C-o*I-i*P)*x,e[2]=(m*S-g*A+v*E)*x,e[3]=(h*A-d*S-p*E)*x,e[4]=(l*M-a*I-c*T)*x,e[5]=(n*I-r*M+i*T)*x,e[6]=(g*b-f*S-v*y)*x,e[7]=(u*S-h*b+p*y)*x,e[8]=(a*C-s*M+c*R)*x,e[9]=(o*M-n*C-i*R)*x,e[10]=(f*A-m*b+v*w)*x,e[11]=(d*b-u*A-p*w)*x,e[12]=(s*T-a*P-l*R)*x,e[13]=(n*P-o*T+r*R)*x,e[14]=(m*y-f*E-g*w)*x,e[15]=(u*E-d*y+h*w)*x,e):null}(an(),v));let b=bn.getClosestPointOnMesh(o,y);try{const e=bn.getClosestPointOnMesh(r,y);pn(y,e)<pn(y,b)&&(b=e)}catch(e){}const E=fn(dn(),b,g);return f-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function Kn(e){!function(e){Yt.push(e)}(e)}function Hn(e){!function(e){Jt.push(e)}(e)}var Xn;function Zn(){return[Xn.Android,Xn.iOS,Xn.Tablet].includes(function(){if("undefined"!=typeof window&&window.navigator){const e=window.navigator.userAgent,t=window.navigator.platform||"",n=["Macintosh","MacIntel","MacPPC","Mac68K"],o=["Win32","Win64","Windows","WinCE"],r=["iPhone","iPod","iPad"],i="ontouchstart"in window||navigator.maxTouchPoints>0;return-1!==r.indexOf(t)?Xn.iOS:-1!==n.indexOf(t)?i?Xn.Tablet:Xn.MacOS:-1!==o.indexOf(t)?Xn.Windows:/Android/.test(e)?Xn.Android:/Linux/.test(t)?Xn.Linux:i?Xn.Tablet:Xn.Unknown}return Xn.Unknown}())}function Yn(e,r,i){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const d=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),m=window[`${h}${d+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],g=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield m(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),v=new o[0](yield(yield g.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=v.byteLength;if(u[c]=Math.min(76,r)*((a>>5)-1),152===u[c]&&(u[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)u[c]^=u[i]<<13,u[c]^=u[i]>>17,u[c]^=u[i]<<5,v[e]=v[e]^u[c];return i^=u[0],i^=u[1],i^=u[2],v}))}!function(e){e[e.Unknown=0]="Unknown",e[e.Android=1]="Android",e[e.iOS=2]="iOS",e[e.Tablet=3]="Tablet",e[e.MacOS=4]="MacOS",e[e.Windows=5]="Windows",e[e.Linux=6]="Linux"}(Xn||(Xn={}));const Jn=["AR","3D"];function eo(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function to(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}function no(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}function oo(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;eo(t,"apiKey"),no(t,"apiKey"),eo(o,"sku"),no(o,"sku"),eo(r,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(i,"initialState",Jn),null!=a&&function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new n(`'${t}' must be a string or array.`)}(a,"initialAnimation"),null!=s&&no(s,"baseUrl"),null!=l&&to(l,"defaultUI"),null!=c&&to(c,"interactive"),null!=u&&function(e,t,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new n(`Value for key '${r}' in '${t}' must be a string.`)}}(u,"strings",st)}let ro=!1;function io(e){return t(this,void 0,void 0,(function*(){const{targetElement:o}=e;E.update(e.baseUrl),zt();const{trackEvent:r}=function(e){const t=performance.now(),n=$t();return{trackEvent:(o,r={})=>{r=Object.assign(Object.assign({},r),{pluginVersion:y,userAgent:qt,sessionId:Ft,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Vt((()=>{window.ShopAR__analytics.trackEventImpl(o,r)}))}}}(e.apiKey);r("visionSetup");const i=yield function(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:e,sid:d()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield o.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(e.apiKey);r("visionApiResponse",i);const{arKey:a}=i,s=Pt(o),{getSetupId:l,findUI:c}=s,u=l();Un(),$n();const{setTargetElement:h,getDeepARTarget:p,setVisibilityParameters:m,getUIState:g,setUIState:v,startDeepARLoading:w,stopDeepARLoading:b,showCameraError:A}=c();if(g()!=Et.None)throw Error("UI state is not None, this is weird..");v(Et.AR),h(o),m(!1,!1,!0,!1,void 0,void 0),w(),yield vn,ao(l(),u);try{r("visionArLaunch"),Gn(),On("Glasses",["faceInit"]),_n(p()),yield Dn({licenseKey:a,truescaleUsecase:"DetectionLoop"}),ao(l(),u),yield qn(),ao(l(),u)}catch(e){const t=e instanceof Error;throw r("visionArLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),A(),Gn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{b()}return ro=!0,{registerFacePoseListener:e=>{ro&&(r("registerFacePoseListener"),Kn(e))},registerFaceMeasurementListener:e=>{ro&&(r("registerFaceMeasurementListener"),Hn(e))},switchEffect:e=>t(this,void 0,void 0,(function*(){ro&&(r("switchEffect",{arUrl:e}),function(e){bn.switchEffect(e)}(e))})),clearEffect:()=>{ro&&(r("clearEffect"),bn.clearEffect())},close:()=>{if(ro){if(ro=!1,r("visionClose"),g()!==Et.AR)throw new n("AR not launched.");Gn(),v(Et.None)}}}}))}function ao(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}function so(e){var o,r;return t(this,void 0,void 0,(function*(){oo(e);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=e,u=null==e.zoomEnabled||e.zoomEnabled,h=!0===e.alwaysTransparentBackground;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),E.update(e.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(at,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(at[t]=n)}}(e.strings);const p=null!=c?ye(c):null,b=null!=(null==p?void 0:p.theta)?ne(p.theta):null,R=null!=(null==p?void 0:p.phi)?ne(p.phi):null,T=null!=(null==p?void 0:p.fov)?ne(p.fov):null,M=function(e,o,r,i,a,s){return t(this,void 0,void 0,(function*(){const l=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams(Object.assign(Object.assign(Object.assign(Object.assign({apiKey:e,sku:o,sid:d()},null!=r&&{yaw:`${g(m(r))}`}),null!=i&&{pitch:`${g(m(i))}`}),null!=a&&{fov:`${g(m(a))}`}),s&&{forcedTransparency:`${s}`}))}`).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 l.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a,null==b?void 0:b.get(),null==R?void 0:R.get(),null==T?void 0:T.get(),h),P=Pt(s),{getSetupId:C,findUI:I,findQR:x,findThree:k}=P,L=C();zt();const{trackEvent:U,arInteracted:$,previewInteracted:D}=function(e,t){const n=performance.now(),o=$t();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,u(Nt,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const u=(r,i={})=>{i=Object.assign(Object.assign({},i),{userAgent:qt,pluginVersion:y,sessionId:Ft,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Vt((()=>{window.ShopAR__analytics.trackEventImpl(r,i)}))};return{trackEvent:u,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}(a,i);U("setup",{hostname:window.location.hostname});const O=yield M;U("apiResponse",O);const{category:_,arUrl:N,arEnvUrl:j,arToneMapping:F,arToneMappingExposure:W,arKey:q,arPromptEnabled:G,arPromptText:z,arPromptImage:V,previewUrl:B,previewEnvUrl:Q,previewToneMapping:K,previewToneMappingExposure:H,previewPosterUrl:X,cameraErrorText:Z,qrPromptText:Y}=O;lo(C(),L);const J=null!=N&&function(e){return null!=e&&v.includes(e)}(_),ee=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),te=J&&function(e){return null!=e&&w.includes(e)}(_),oe=ee&&te&&!Zn(),re=J&&!oe,ie=null!=B;if(lo(C(),L),oe&&function(){t(this,void 0,void 0,(function*(){null==S&&(S=A(`${E}/shopar-qr.js`))}))}(),re&&(Un(),function(e){e!==yn&&(yn=e,on(e),Cn=null,tn())}(N),"Glasses"===_&&$n(),null!=j&&on(j)),ie){null==Ge&&(Ge=A(`${E}/shopar-three.js`));const e=255;Yn(B,(new Date).getTime()+e,Math.random()*e),on(null!=Q?Q:`${E}/env/default.hdr`)}const{setTargetElement:ae,getDeepARTarget:se,getDeepARPrompt:le,customizeDeepARPrompt:ce,customizeCameraError:ue,customizeQRPrompt:de,setVisibilityParameters:he,getUIState:pe,setUIState:fe,setDefaultUIActions:me,startDeepARLoading:ge,stopDeepARLoading:ve,startThreeLoading:we,stopThreeLoading:be,setThreePosterUrl:Ee,showCameraError:Ae}=I();ae(s);he(null==e.defaultUI||e.defaultUI,oe,re,ie,_,l),ce(null!=z?z:"",null!=V?V:""),ue(Z),de(Y),Ee(X),function(e,t){const o=e.parentNode;if(null==o)throw new n("Parent node missing.");new MutationObserver((n=>{for(const o of n)for(const n of o.removedNodes)if(n===e)return void t()})).observe(o,{childList:!0})}(s,(()=>{pe()!==Et.QR||Se()||Te(),pe()!==Et.AR||Rn||Gn(),pe()!==Et.Preview||Ie()||ke(),fe(Et.None)}));const{qrPaused:Se,qrDraw:Re,qrPause:Te}=x(),{threeInit:Me,threeParse:Pe,threeLoad:Ce,threePaused:Ie,threeResume:xe,threePause:ke,threeSetZoomEnabled:Le,threeSetForcedTransparency:Ue,threeSetToneMapping:$e,threeIsInteractive:De,threeSetInteractive:Oe,threeSetOnInteracted:_e,threeInitPromptAnimation:Ne,threeInitThetaAnimation:je,threeInitPhiAnimation:Fe,threeInitFovAnimation:We}=k(),qe=null==e.interactive||e.interactive;Oe(qe);let ze=0;if(pe()===Et.QR){if(!Se())if(oe){U(Dt);try{yield Re(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Te(),fe(Et.None)}else if(pe()===Et.AR){if(!Rn)if(re&&!ro){U(Ot);const e=null!=j?yield on(j):void 0;lo(C(),L);const t=yield on(N);lo(C(),L),Ct(P),On(_),_n(se()),Nn(G?le():null),yield Fn(t,e,`${N}${j}`),Wn(F,W),jn($),lo(C(),L)}else Gn(),fe(Et.None)}else if(pe()===Et.Preview&&!Ie())if(ie){U(_t),we();const e=255,t=yield Yn(B,(new Date).getTime()+e,Math.random()*e);lo(C(),L);const n=yield on(null!=Q?Q:`${E}/env/default.hdr`);lo(C(),L);const o=yield Pe(t,n,`${B}${Q}`);lo(C(),L),Ce(o,_),Le(u),Ue(h),$e(null!=K?K:"ACES",null!=H?H:1),_e(D),Ne(),null!=p&&(je(b),Fe(R),We(T)),be()}else ke(),fe(Et.None);const Ve=()=>t(this,void 0,void 0,(function*(){if(oe){if(pe()===Et.QR||pe()===Et.AR)return;try{U(Dt);const e=++ze;if(pe()===Et.Preview&&ie&&!Ie()&&ke(),fe(Et.QR),yield Re(i,a),ze!==e)return;return void lo(C(),L)}catch(e){const t=e instanceof Error;throw U("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!re)throw new n("Model does not have AR enabled.");if(pe()!==Et.AR)try{U(Ot);const e=++ze;pe()===Et.Preview&&ie&&!Ie()&&ke(),Ct(P),fe(Et.AR),ge();const t=null!=j?yield on(j):void 0;lo(C(),L);const n=yield on(N);if(ze!==e)return;if(lo(C(),L),yield vn,ze!==e)return;if(lo(C(),L),Gn(),On(_),_n(se()),Nn(G?le():null),yield Dn({licenseKey:q}),ze!==e)return;if(lo(C(),L),yield Fn(n,t,`${N}${j}`),Wn(F,W),jn($),ze!==e)return;if(lo(C(),L),yield qn(),ze!==e)return;lo(C(),L)}catch(e){const t=e instanceof Error;throw U("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),Ae(),Gn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{ve()}})),Be=()=>t(this,void 0,void 0,(function*(){if(!ie)throw new n("Model does not have 3D enabled.");if(pe()!==Et.Preview)try{U(_t);const e=++ze;pe()===Et.AR&&(re&&!Rn&&Gn(),Te()),fe(Et.Preview),we();const t=255,n=yield Yn(B,(new Date).getTime()+t,Math.random()*t);if(ze!==e)return;lo(C(),L);const o=yield on(null!=Q?Q:`${E}/env/default.hdr`);if(ze!==e)return;if(lo(C(),L),yield Ge,ze!==e)return;if(lo(C(),L),Me(),ze!==e)return;lo(C(),L);const r=yield Pe(n,o,`${B}${Q}`);if(ze!==e)return;lo(C(),L),Ce(r,_),Le(u),Ue(h),$e(null!=K?K:"ACES",null!=H?H:1),_e(D),Ne(),null!=p&&(je(b),Fe(R),We(T)),xe()}catch(e){const t=e instanceof Error;throw U("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{be()}})),Qe=()=>t(this,void 0,void 0,(function*(){pe()!==Et.None&&(++ze,pe()===Et.QR||pe()===Et.AR?(re&&!Rn&&Gn(),Te()):pe()===Et.Preview&&ie&&!Ie()&&ke(),fe(Et.None),"AR"!==l?"3D"!==l||(yield Be()):yield Ve())}));return me(Ve,Be,Qe),"AR"===l?(yield Ve(),lo(C(),L)):"3D"===l&&(yield Be(),lo(C(),L)),ro=!1,{launchAR:J?Ve:void 0,launch3D:ie?Be:void 0,closeAR:J?()=>t(this,void 0,void 0,(function*(){pe()!==Et.AR&&pe()!==Et.QR||(++ze,re&&!Rn&&Gn(),Te(),fe(Et.None),"3D"!==l||(yield Be()))})):void 0,close3D:ie?()=>t(this,void 0,void 0,(function*(){pe()===Et.Preview&&(++ze,ie&&!Ie()&&ke(),fe(Et.None),"AR"!==l||(yield Ve()))})):void 0,close:J||ie?Qe:void 0,isInteractive:()=>De(),setInteractive:e=>Oe(e)}}))}function lo(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const co={setup:function(e){return t(this,void 0,void 0,(function*(){return io(e)}))}},uo={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",(()=>so(e)))}))},version:y};e.PREVIEW_STATES=Jn,e.PluginError=n,e.plugin=uo,e.vision=co}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem}.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}.shopar-btn:hover{background-color:#f5f5f5}.shopar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}.shopar-3d{background-color:#fff}.shopar-3d-poster{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 o=[Uint8Array,Uint32Array],r=o.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[i[a[a[r]]]][i[a[a[a.length-1]]]],l=s.charCodeAt(r),c=l^l,u=new o[1]([c]);function d(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],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)}}))}function m(e){return e*(180/Math.PI)}function g(e){return Math.round(100*e)/100}const v=["Glasses","Shoes","Watches"],w=["Shoes"];const y={},b={};function E(e){return null==y[e]&&(y[e]=function(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(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.")}}))}(e)),y[e]}function A(e,r,i){return null==b[e]&&(b[e]=function(e,r,i){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const d=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),m=window[`${h}${d+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],g=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield m(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),v=new o[0](yield(yield g.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=v.byteLength;if(u[c]=Math.min(76,r)*((a>>5)-1),152===u[c]&&(u[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)u[c]^=u[i]<<13,u[c]^=u[i]>>17,u[c]^=u[i]<<5,v[e]=v[e]^u[c];return i^=u[0],i^=u[1],i^=u[2],v}))}(e,r,i)),b[e]}const S="0.7.3-alpha.1";let M=`https://cdn.jsdelivr.net/npm/shopar-plugin@${S}/dist`;const R={update:e=>{null!=e&&(M=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>M};function T(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;const P=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.error('No <meta name="viewport"> detected. This might cause ShopAR to crash on iOS.\nPlease add the following line to your HTML:\n<meta name="viewport" content="width=device-width, initial-scale=1.0">'),()=>e?window.devicePixelRatio:1})();let I,x,k;function L(e){const t=function(e){const t=new x.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,x.ClampToEdgeWrapping,x.ClampToEdgeWrapping,x.LinearFilter,x.LinearFilter,1,x.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(k.parse(e));return t.mapping=x.EquirectangularReflectionMapping,t.colorSpace=x.LinearSRGBColorSpace,t}const U=45,$=45,D=3,O=1.5,_=1,N=.5;let j,F,W,q,G,z=!1;const V=4,B=.001,Q=1e-7,K=10,H=11,X=1/(H-1),Z="function"==typeof Float32Array;function Y(e,t,n,o){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===o)return re;const r=Z?new Float32Array(H):new Array(H);for(let t=0;t<H;++t)r[t]=ne(t*X,e,n);function i(t){let o=0,i=1;const a=H-1;for(;i!==a&&r[i]<=t;++i)o+=X;--i;const s=o+(t-r[i])/(r[i+1]-r[i])*X,l=oe(s,e,n);return l>=B?function(e,t,n,o){for(let r=0;r<V;++r){const r=oe(t,n,o);if(0===r)return t;t-=(ne(t,n,o)-e)/r}return t}(t,s,e,n):0===l?s:function(e,t,n,o,r){let i,a,s=0;do{a=t+(n-t)/2,i=ne(a,o,r)-e,i>0?n=a:t=a}while(Math.abs(i)>Q&&++s<K);return a}(t,o,o+X,e,n)}return function(e){return 0===e||1===e?e:ne(i(e),t,o)}}function J(e,t){return 1-3*t+3*e}function ee(e,t){return 3*t-6*e}function te(e){return 3*e}function ne(e,t,n){return((J(t,n)*e+ee(t,n))*e+te(t))*e}function oe(e,t,n){return 3*J(t,n)*e*e+2*ee(t,n)*e+te(t)}function re(e){return e}function ie(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=Y(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function ae(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort(((e,t)=>e.time-t.time)).map((({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:ie(n)})));let o=0,r=n[0].value;return{reset:()=>{o=0},update:e=>{for(o+=e;o>=t;)o-=t;for(let e=0;e<n.length-1;e++){const t=n[e],i=n[e+1];if(o>=t.time&&o<i.time){const e=t.interpolate((o-t.time)/(i.time-t.time));r=t.value+e*(i.value-t.value)}}},get:()=>r}}const se="#",le="time",ce="interpolation",ue="yaw",de="pitch",he="fov",pe=[le,ue,de,he,ce],fe="s",me="ms",ge=1e3,ve="deg",we="rad",ye=Math.PI/180,be="ease-in-out",Ee="cubic-bezier(",Ae=")";function Se(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map((e=>function(e){const t=e.indexOf(se);return(-1!==t?e.substring(0,t):e).trim()}(e))).filter((e=>""!==e))}(e);if(null==t)throw new Error("Header missing.");const o=function(e){const t=[];for(let n=0;n<e.length;n++){const o=e[n];if(!pe.includes(o))throw new Error(`Invalid token in header: '${o}'.`);if(t.includes(o))throw new Error(`Duplicate token in header: '${o}'.`);t.push(o)}if(!t.includes(le))throw new Error(`Missing required token: '${le}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:i}=Me(o,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=i&&(null==r.fov&&(r.fov=[]),r.fov.push(i))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const o of e){const{time:e,pitch:r,yaw:i,fov:a}=o;if(null==e)throw new Error("Time missing.");const s=Te(null!==(t=o.interpolation)&&void 0!==t?t:be);null!=i&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:i*ye,interpolation:s})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*ye,interpolation:s})),null!=a&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:a*ye,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every((t=>t.length!==e.length)))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function Me(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter((e=>!(null==n?void 0:n.includes(e)))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter((t=>!e.includes(t))).join(", ")}'.`);const o=e.indexOf(le),r=function(e){if(e.endsWith(me))return Pe(e.substring(0,e.length-me.length));if(e.endsWith(fe))return Pe(e.substring(0,e.length-fe.length))*ge;return Pe(e)}(n[o]),i=e.indexOf(ce),a=Te(-1===i?be:n[i]),s={};for(let t=0;t<n.length;t++){if(t===o||t===i)continue;const l=e[t],c=n[t];switch(l){case ue:s.theta={time:r,value:Re(c),interpolation:a};break;case de:s.phi={time:r,value:Re(c),interpolation:a};break;case he:s.fov={time:r,value:Re(c),interpolation:a};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function Re(e){return e.endsWith(ve)?Pe(e.substring(0,e.length-ve.length))*ye:e.endsWith(we)?Pe(e.substring(0,e.length-we.length)):Pe(e)*ye}function Te(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ce(0,0,1,1);if("sine"===e)return Ce(.37,0,.63,1);if("sine-in"===e)return Ce(.12,0,.39,0);if("sine-out"===e)return Ce(.61,1,.88,1);if("ease"===e)return Ce(.25,.1,.25,1);if("ease-in"===e)return Ce(.42,0,1,1);if("ease-out"===e)return Ce(0,0,.58,1);if("ease-in-out"===e)return Ce(.42,0,.58,1);if(e.startsWith(Ee)&&e.endsWith(Ae)){const t=e.substring(Ee.length,e.length-Ae.length).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Pe(t[0]),y1:Pe(t[1]),x2:Pe(t[2]),y2:Pe(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ce(e,t,n,o){return{type:"bezier",x1:e,y1:t,x2:n,y2:o}}function Pe(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}const Ie=300,xe=2e3,ke=.05,Le=2*Math.PI/32,Ue=Te("hold"),$e=Te("sine"),De=Te("sine-in"),Oe=Te("sine-out");const _e=8,Ne=2*Math.PI,je=Ne/12,Fe=Ne/60,We=Ne/60,qe=60,Ge=60,ze=1e3,Ve=qe*Ge,Be=-1;const Qe=["map","alphaMap","anisotropyMap","aoMap","bumpMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap","displacementMap","emissiveMap","envMap","gradientMap","iridescenceMap","iridescenceThicknessMap","lightMap","metalnessMap","normalMap","roughnessMap","sheenColorMap","sheenRoughnessMap","specularMap","specularColorMap","specularIntensityMap","thicknessMap","transmissionMap"];function Ke(e){null!=e&&(e.dispose(),Qe.forEach((t=>{var n;return null===(n=e[t])||void 0===n?void 0:n.dispose()})))}let He;const Xe=0,Ze=3;let Ye,Je,et,tt=!1,nt=1,ot=1,rt=1;const it=1;let at;const st=new Map;function lt(e,n,o){const r=e.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,l,c,u,d,h,p,f,m,g,v,w,y,b=!1,E=!1,A=!1,S=!0,M=!1,R=1,T=!0,C=!1,P=0,_=0,z=1,V=1,B=1;const Q={threeInit:()=>{b||(ct(),i=new Je.Scene,a=new Je.PerspectiveCamera(25,1,.5),s=new Ye.OrbitControls(a,e),s.setInteractionEnabled(T),h=Je.ACESFilmicToneMapping,({renderShadow:c,shadowGroup:l}=function(e){const t=new j.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new j.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new j.Group;o.position.y=-.7;const r=new j.PlaneGeometry(U,$).rotateX(Math.PI/2),i=new j.MeshBasicMaterial({map:t.texture,opacity:N,transparent:!0,depthWrite:!1}),a=new j.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new j.Mesh(r);s.visible=!1,o.add(s);const l=new j.OrthographicCamera(-U/2,U/2,$/2,-$/2,0,D);function c(e){s.visible=!0,q.uniforms.tDiffuse.value=t.texture,q.uniforms.h.value=1*e/256,s.material=q,F.setRenderTarget(n),F.render(s,l),G.uniforms.tDiffuse.value=n.texture,G.uniforms.v.value=1*e/256,s.material=G,F.setRenderTarget(t),F.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,o.add(l),{shadowGroup:o,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=W;const o=F.getClearAlpha();F.setClearAlpha(0),F.setRenderTarget(t),F.render(e,l),e.overrideMaterial=null,c(O),c(.4*O),F.setRenderTarget(null),F.setClearAlpha(o),e.background=n}}}(i)),b=!0)},threeParse:(e,n,o)=>t(this,void 0,void 0,(function*(){return null!=u&&d===o||(yield u,u=(()=>t(this,void 0,void 0,(function*(){var t,o;return x=(t=Ye).THREE,k=new t.RGBELoader,i.environment=L(n),function(e,t){const{THREE:n}=t;I=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder(t.MeshoptDecoder)}(at,Ye),o=e,I.parseAsync(o.buffer,"")})))(),d=o),u})),threeLoad:(e,t)=>{i.traverse((e=>{var t;e instanceof Je.Mesh&&(null===(t=e.geometry)||void 0===t||t.dispose(),Array.isArray(e.material)?e.material.forEach(Ke):Ke(e.material))})),i.clear(),i.add(e.scene);const n=(new Je.Box3).setFromObject(e.scene);l.position.y=n.min.y-Xe,i.add(l),c(),E=!1,i.traverse((e=>{if(e instanceof Je.Mesh){e.material.depthWrite=!0;const t=e.material;Array.isArray(t)?t.forEach((e=>{e.transmission>0&&(E=!0)})):t.transmission>0&&(E=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(Ye.reduceVertices(e.scene,((e,t)=>Math.max(e,o.distanceToSquared(t))),0));s.reset(o,r,function(e,t){var n;const o={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?o.Glasses:null!==(n=o[e])&&void 0!==n?n:o.Glasses).normalize()}(t,Je.Vector3)),P=0,y="Watches"===t?function(e){const t=e.getObjectByName("hours"),n=e.getObjectByName("minutes"),o=e.getObjectByName("seconds");if(null==t&&null==n&&null==o)return null;let r=new Date;return{update:()=>{const e=new Date;if(Math.abs(e.getTime()-r.getTime())<ze/_e)return!1;r=e;const i=e.getHours(),a=e.getMinutes(),s=e.getSeconds(),l=e.getMilliseconds();return null!=t&&(t.rotation.y=Be*je*(i+a/qe+s/Ve)),null!=n&&(n.rotation.y=Be*Fe*(a+s/Ge)),null!=o&&(o.rotation.y=Be*We*(s+l/ze)),!0}}}(e.scene):null},threePaused:()=>S,threeResume:()=>{S=!1,at.setAnimationLoop(ut),e.style.visibility="visible",_=0,null==f||f.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset(),null==w||w.reset()},threePause:()=>{S=!0,function(){for(const{threePaused:e}of st.values())if(!e())return!1;return!0}()&&at.setAnimationLoop(null),e.style.visibility="hidden",o.style.opacity="0",n.style.visibility="hidden"},threeSetZoomEnabled:e=>{s.enableZoom=e},threeSetForcedTransparency:e=>{A=e},threeSetToneMapping:(e,t)=>{const n={ACES:Je.ACESFilmicToneMapping,Linear:Je.LinearToneMapping,Neutral:Je.NeutralToneMapping};null!=n[e]&&(h=n[e]),R=t},threeIsInteractive:()=>T,threeSetInteractive:e=>{T=e,null==s||s.setInteractionEnabled(T)},threeSetOnInteracted:e=>{s.removeEventListener("change",p),p=e,s.addEventListener("change",e)},threeInitPromptAnimation:()=>{var e;e=s.getTheta(),f=ae([{time:0,value:e,interpolation:Ue},{time:Ie,value:e,interpolation:Oe},{time:Ie+xe/4,value:e+Le,interpolation:$e},{time:Ie+3*xe/4,value:e-Le,interpolation:De},{time:Ie+xe,value:e,interpolation:Ue},{time:Ie+2*xe,value:e,interpolation:Ue}]),s.setTheta(f.get()),m=null,g=null,v=ae([{time:0,value:0,interpolation:Ue},{time:Ie,value:1,interpolation:Ue},{time:Ie+xe,value:0,interpolation:Ue},{time:Ie+2*xe,value:0,interpolation:Ue}]),w=ae([{time:0,value:0,interpolation:Ue},{time:Ie,value:0,interpolation:Oe},{time:Ie+xe/4,value:-ke,interpolation:$e},{time:Ie+3*xe/4,value:ke,interpolation:De},{time:Ie+xe,value:0,interpolation:Ue},{time:Ie+2*xe,value:0,interpolation:Ue}])},threeInitThetaAnimation:e=>{f=e,null!=e&&s.setTheta(e.get())},threeInitPhiAnimation:e=>{m=e,null!=e&&s.setPhi(e.get())},threeInitFovAnimation:e=>{g=e,null!=e&&s.setFovRadians(e.get())},preRender_:e=>{if(!b||S)return;let t=0!==_?e-_:0;_=e,0===P?M=!0:P<Ze&&(t=0),P++,C||(s.hasUserInteracted()?(C=!0,f=null,m=null,g=null,v=null,w=null):(null==f||f.update(t),null==m||m.update(t),null==g||g.update(t),null==v||v.update(t),null==w||w.update(t),null!=f&&(s.setTheta(f.get()),M=!0),null!=m&&(s.setPhi(m.get()),M=!0),null!=g&&(s.setFovRadians(g.get()),M=!0))),s.update()&&(M=!0),(null==y?void 0:y.update())&&(M=!0)},shouldRender_:()=>!(!b||S)&&M,render_:()=>{const t=at.toneMapping,s=at.toneMappingExposure;at.toneMapping=h,at.toneMappingExposure=R,at.setViewport(0,0,e.width,e.height),at.setClearColor(new Je.Color(16777215),E&&!A?1:0),at.render(i,a),at.toneMapping=t,at.toneMappingExposure=s,M=!1,null!=r&&(r.clearRect(0,0,e.width,e.height),et.width>0&&et.height>0&&r.drawImage(et,0,ot-e.height,e.width,e.height,0,0,e.width,e.height),n.style.visibility=T&&!C?"visible":"hidden",null!=v&&(o.style.opacity=`${v.get()}`),null!=w&&(o.style.transform=`translateX(${w.get()*Math.min(z,V)}px)`))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===z&&n===V&&rt===B||(e.width=Math.ceil(t*rt*it),e.height=Math.ceil(n*rt*it),z=t,V=n,B=rt,M=!0)},target_:e};return st.set(e,Q),Q}function ct(){if(tt)return;Ye=window.ShopAR__THREE,Je=Ye.THREE,et=document.createElement("canvas");var e,t;et.style.position="block",at=new Je.WebGLRenderer({powerPreference:"high-performance",canvas:et,antialias:!0,alpha:!0}),at.outputColorSpace=Je.SRGBColorSpace,at.toneMapping=Je.ACESFilmicToneMapping,at.setClearColor(new Je.Color(16777215),0),e=at,t=Ye,z||(j=t.THREE,F=e,W=new j.MeshDepthMaterial,W.userData.darkness={value:_},W.onBeforeCompile=e=>{e.uniforms.darkness=W.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},W.depthTest=!1,W.depthWrite=!1,q=new j.ShaderMaterial(t.HorizontalBlurShader),q.depthTest=!1,G=new j.ShaderMaterial(t.VerticalBlurShader),G.depthTest=!1,z=!0),dt(),tt=!0}function ut(e){dt(),at.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of st.values())t(e),n()&&o()}function dt(){let e=0,t=0;for(const{target_:n}of st.values()){const{clientWidth:o,clientHeight:r}=n;e=Math.max(e,o),t=Math.max(t,r)}const n=P();e=Math.ceil(e*n*it),t=Math.ceil(t*n*it),e===nt&&t===ot&&n===rt||(nt=e,ot=t,rt=n,at.setSize(nt,ot,!1));for(const{updateSize_:e}of st.values())e()}const ht={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},pt=Object.keys(ht);function ft(e){return ht[e]}const mt="shopar-error";function gt(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}function vt(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=gt("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=t,r.appendChild(e)}r.ariaLabel=n;const i=r.style;return i.display="none",i.pointerEvents="auto",r}const wt="shopar-control";const yt="shopar-deepar-output";function bt(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.pointerEvents="auto",n.userSelect="none",t}function Et(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function At(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function St(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const Mt="shopar-main";const Rt="shopar-qr-output";const Tt="shopar-three-output";var Ct;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(Ct||(Ct={}));let Pt=!1;function It(){Pt||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),Pt=!0)}function xt(){It();const e=function(){const e=document.createElement("div");e.id=Mt;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",t.pointerEvents="none",e}(),t=function(){const e=document.createElement("div");return e.style.textAlign="center",e}(),n=function(){const e=new Image;e.draggable=!1;const t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),o=function(e,t){const n=document.createElement("div");n.id=Rt;const o=n.style;o.position="absolute",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="none",o.pointerEvents="auto",o.userSelect="none";const r=document.createElement("div");r.className="shopar-qr";const i=r.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(r),r.appendChild(e);const a=document.createElement("div");return a.appendChild(t),r.appendChild(a),n}(t,n);e.appendChild(o);const r=function(){const e=document.createElement("div");e.id=yt;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",t.pointerEvents="auto",e}();e.appendChild(r);const i=function(){const e=document.createElement("canvas");e.id=Tt,e.className="shopar-3d";const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",t.pointerEvents="auto",e}();e.appendChild(i);const a=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),s=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),l=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:o}=n;return o.position="absolute",o.width="100%",o.height="100%",o.opacity="0",n.appendChild(e),n.appendChild(t),n}(a,s);e.appendChild(l);const c=function(){const e=gt("2rem",`${R}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),u=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",t.appendChild(e),t}(c);e.appendChild(u);const d=bt("shopar-ar-loading-container"),h=Et("shopar-ar-loading-text",ft("loading.ar"));d.appendChild(h);const p=At("shopar-ar-loading-bar-bg"),f=St("shopar-ar-loading-bar-fg");p.appendChild(f),d.appendChild(p),e.appendChild(d);const m=bt("shopar-3d-loading-container"),g=Et("shopar-3d-loading-text",ft("loading.3d"));m.appendChild(g);const v=At("shopar-3d-loading-bar-bg"),w=St("shopar-3d-loading-bar-fg");v.appendChild(w),m.appendChild(v),e.appendChild(m);const y=function(){const e=document.createElement("div");e.className="shopar-3d-poster";const{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.pointerEvents="auto",t.userSelect="none",e}(),b=function(){const e=new Image;e.draggable=!1;const{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.objectFit="contain",e}();y.appendChild(b),e.appendChild(y);const E=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),A=function(e){const t=document.createElement("div");t.id=mt;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none",n.pointerEvents="auto",n.userSelect="none";const o=document.createElement("div"),r=o.style;return r.position="absolute",r.width="100%",r.height="100%",r.backgroundColor="#ffffff",r.display="flex",r.flexDirection="column",r.justifyContent="center",r.alignItems="center",t.appendChild(o),o.appendChild(e),t}(E);e.appendChild(A);const S=function(){const e=document.createElement("div");return e.id=wt,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(S);const M=vt("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");S.appendChild(M);const T=vt("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${R}/img/icons/cube.svg`);S.appendChild(T);const C=vt("shopar-btn-close","Close","Close ShopAR view",`${R}/img/icons/close.svg`);S.append(C);let P,I,x=Ct.None,k=!1,L=!1,U=!1,$=!1;function D(){f.classList.remove("active"),d.style.visibility="hidden"}function O(){y.style.visibility="hidden",w.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return o},getQRImage:function(){return n},getDeepARTarget:function(){return r},getDeepARPrompt:function(){return l},getThreeTarget:function(){return i},getThreePrompt:function(){return u},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){E.textContent=null!=e?e:"Please reload page and allow camera access to continue"},customizeQRPrompt:function(e){t.textContent=null!=e?e:"Scan on mobile or tablet to try on"},setVisibilityParameters:function(e,t,n,o,r,i){var a;k=e,L=t,U=n,$=o,P=r,I=i,kt(S,k),kt(M,k&&(U||L)&&x===Ct.None),kt(T,k&&$&&x===Ct.None),kt(C,k&&x!==Ct.None),D(),O(),k||""===(a=A).style.display&&kt(a,!1)},getUIState:function(){return x},setUIState:function(e){x=e,x===Ct.None?(D(),O(),k&&(kt(A,!1),kt(C,!1),(L||U)&&kt(M,!0),$&&kt(T,!0))):x===Ct.QR||x===Ct.AR?k&&(kt(A,!1),kt(M,!1),kt(T,$&&"AR"===I),kt(C,"AR"!==I)):x===Ct.Preview&&k&&(kt(A,!1),kt(M,(L||U)&&"3D"===I),kt(T,!1),kt(C,"3D"!==I))},setDefaultUIActions:function(e,t,n){k&&((L||U)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${R}/img/icons/${n}`;M.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(P),M.onclick=e),$&&(T.onclick=t),C.onclick=n)},startDeepARLoading:function(){f.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:D,startThreeLoading:function(){null!=b.dataset.srcSet?y.style.visibility="visible":(w.classList.add("active"),m.style.visibility="visible")},stopThreeLoading:O,setThreePosterUrl:function(e){null!=e?(b.src=e,b.dataset.srcSet="true"):delete b.dataset.srcSet},showCameraError:function(){k&&kt(A,!0)}}}function kt(e,t){e.style.display=t?"":"none"}const Lt=new Map;function Ut(e){let n=Lt.get(e);return null==n?(n=function(){let e=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=xt()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:e,getQRImage:n}=i();o=function(e,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>t(this,void 0,void 0,(function*(){yield C;const t=`https://ar.shopar.ai/${S.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:r,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(t),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,o=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){o=!0,e.style.display="none"}))}}(e(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();r=lt(e(),t(),n())}return r}}}(),Lt.set(e,n)):n.incrementSetupId_(),n}function $t(e){for(const t of Lt.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===Ct.AR&&r(Ct.None)}}let Dt;const Ot=new Uint8Array(16);function _t(){if(!Dt&&(Dt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Dt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Dt(Ot)}const Nt=[];for(let e=0;e<256;++e)Nt.push((e+256).toString(16).slice(1));var jt={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ft(e,t,n){if(jt.randomUUID&&!t&&!e)return jt.randomUUID();const o=(e=e||{}).random||(e.rng||_t)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return Nt[e[t+0]]+Nt[e[t+1]]+Nt[e[t+2]]+Nt[e[t+3]]+"-"+Nt[e[t+4]]+Nt[e[t+5]]+"-"+Nt[e[t+6]]+Nt[e[t+7]]+"-"+Nt[e[t+8]]+Nt[e[t+9]]+"-"+Nt[e[t+10]]+Nt[e[t+11]]+Nt[e[t+12]]+Nt[e[t+13]]+Nt[e[t+14]]+Nt[e[t+15]]}(o)}const Wt="qrLaunch",qt="arLaunch",Gt="previewLaunch",zt="heartbeat";let Vt,Bt,Qt=!1,Kt=window.navigator.userAgent||"no user agent";const Ht=[];function Xt(){null==Vt&&(Bt=Ft(),Vt=T(`${R}/shopar-analytics.js`),Vt.then((()=>{Qt=!0,window.ShopAR__analytics.initializeImpl(),Ht.forEach((e=>e()))})))}function Zt(e){Qt?e():Ht.push(e)}function Yt(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Jt(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 en=200,tn=10;let nn=!1,on=null,rn=[],an=[];function sn(e){return t(this,void 0,void 0,(function*(){nn=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${R}/wasm/mediapipe`,e),on&&clearInterval(on);const o=[],r=[];on=setInterval((()=>t(this,void 0,void 0,(function*(){if(nn)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());nn||(null!=a&&null!=s&&function(e){for(let t of rn)t(e)}({translation:a,rotation:s}),null==e&&(o.push(t),r.push(i),o.length<tn||(o.shift(),r.shift(),function(e,t){for(let n of an)n({faceWidth:e,IPD:t})}(cn(o),cn(r)))))}))),en)}))}function ln(){an=[],rn=[],nn=!0}function cn(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}var un="undefined"!=typeof Float32Array?Float32Array:Array;function dn(){var e=new un(16);return un!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function hn(e,t,n){var o=t[0],r=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],u=t[7],d=t[8],h=t[9],p=t[10],f=t[11],m=t[12],g=t[13],v=t[14],w=t[15],y=n[0],b=n[1],E=n[2],A=n[3];return e[0]=y*o+b*s+E*d+A*m,e[1]=y*r+b*l+E*h+A*g,e[2]=y*i+b*c+E*p+A*v,e[3]=y*a+b*u+E*f+A*w,y=n[4],b=n[5],E=n[6],A=n[7],e[4]=y*o+b*s+E*d+A*m,e[5]=y*r+b*l+E*h+A*g,e[6]=y*i+b*c+E*p+A*v,e[7]=y*a+b*u+E*f+A*w,y=n[8],b=n[9],E=n[10],A=n[11],e[8]=y*o+b*s+E*d+A*m,e[9]=y*r+b*l+E*h+A*g,e[10]=y*i+b*c+E*p+A*v,e[11]=y*a+b*u+E*f+A*w,y=n[12],b=n[13],E=n[14],A=n[15],e[12]=y*o+b*s+E*d+A*m,e[13]=y*r+b*l+E*h+A*g,e[14]=y*i+b*c+E*p+A*v,e[15]=y*a+b*u+E*f+A*w,e}function pn(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function fn(e,t){var n=t[0],o=t[1],r=t[2],i=t[4],a=t[5],s=t[6],l=t[8],c=t[9],u=t[10];return e[0]=Math.hypot(n,o,r),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(l,c,u),e}function mn(e,t,n,o){var r=t[0],i=t[1],a=t[2],s=t[3],l=r+r,c=i+i,u=a+a,d=r*l,h=r*c,p=r*u,f=i*c,m=i*u,g=a*u,v=s*l,w=s*c,y=s*u,b=o[0],E=o[1],A=o[2];return e[0]=(1-(f+g))*b,e[1]=(h+y)*b,e[2]=(p-w)*b,e[3]=0,e[4]=(h-y)*E,e[5]=(1-(d+g))*E,e[6]=(m+v)*E,e[7]=0,e[8]=(p+w)*A,e[9]=(m-v)*A,e[10]=(1-(d+f))*A,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function gn(){var e=new un(3);return un!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function vn(e,t,n){var o=new un(3);return o[0]=e,o[1]=t,o[2]=n,o}function wn(e,t){var n=t[0]-e[0],o=t[1]-e[1],r=t[2]-e[2];return Math.hypot(n,o,r)}function yn(e,t,n){var o=t[0],r=t[1],i=t[2],a=n[3]*o+n[7]*r+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*o+n[4]*r+n[8]*i+n[12])/a,e[1]=(n[1]*o+n[5]*r+n[9]*i+n[13])/a,e[2]=(n[2]*o+n[6]*r+n[10]*i+n[14])/a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function bn(){var e=new un(4);return un!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}gn(),function(){var e,t=(e=new un(4),un!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var En;let An,Sn,Mn;gn(),vn(1,0,0),vn(0,1,0),bn(),bn(),En=new un(9),un!=Float32Array&&(En[1]=0,En[2]=0,En[3]=0,En[5]=0,En[6]=0,En[7]=0),En[0]=1,En[4]=1,En[8]=1;let Rn,Tn,Cn,Pn,In=!0,xn=null;const kn=new Set;let Ln,Un,$n,Dn,On,_n;function Nn(){null==An&&(An=T(`${R}/shopar-deepar.js`))}function jn(){null==Sn&&(Sn=T(`${R}/shopar-true-scale.js`))}function Fn(e){return t(this,void 0,void 0,(function*(){const{licenseKey:o,truescaleUsecase:r}=e;return On=r,null==Ln&&(Ln=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(e=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))throw new n("No camera available!");var e;const t=Hn(Cn),r=Yt(t);Rn=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:Pn,additionalOptions:{hint:_n,cameraConfig:{disableDefaultCamera:!0}}}),Tn=yield Jt(r),yield Xn(Rn,Tn,"user"===t),"Glasses"===Cn&&(yield Sn,sn(Tn),"DetectionLoop"!==On&&eo((e=>{Dn=e.faceWidth})))})))()),Ln}))}function Wn(e,t){var n,o;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===Cn&&(n=t,o=_n,n===o||null!=n&&null!=o&&n.length===o.length&&n.every((e=>o.find((t=>e===t))))&&o.every((e=>n.find((t=>t===e))))))||(null!=Rn&&(Rn.shutdown(),Rn=null,Ln=null),Cn=e,_n=t)}function qn(e){e!==Pn&&(Pn=e,null!=Rn&&Rn.changePreviewElement(Pn))}function Gn(e){xn=e}function zn(e){Rn.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(Dn){const e=137/(Dn+5);Rn.changeParameterVector("GLASSES","","scale",e,e,e,0),Rn.changeParameterVector("shopar_glasses","","scale",e,e,e,0),function(e){const t=[-8.362421,4.549,-9.275],n=[8.362421,4.549,-9.275];try{const o=Yn("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=Yn("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);Rn.changeParameterVector("temple_left","","rotation",0,56.6*-o,0,0),Rn.changeParameterVector("temple_right","","rotation",0,56.6*-r,0,0)}catch(e){return}}(e),ln(),Dn=null}e(),Zn("Glasses")}},Rn.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Zn("Shoes"))},Rn.callbacks.onWristTracked=t=>{t.detected&&(e(),Zn("Watches"))}}function Vn(e,n,o){return t(this,void 0,void 0,(function*(){return null!=Un&&$n===o||(yield Un,Un=Rn.switchEffect(e,{envmap:n}),$n=o),Un}))}function Bn(e,t){null!=e&&null!=t&&(Rn.setToneMapping(e),Rn.setExposure(t))}function Qn(){return t(this,void 0,void 0,(function*(){if(null!=Rn){if(In=!1,null==Tn){const e=Hn(Cn),t=Yt(e);Tn=yield Jt(t),yield Xn(Rn,Tn,"user"===e),"Glasses"===Cn&&(sn(Tn),"DetectionLoop"!==On&&eo((e=>{Dn=e.faceWidth})))}!function(){if(null==xn)return;if(null==Cn||kn.has(Cn))return;xn.style.visibility="visible",xn.style.opacity="1"}(),Rn.setPaused(In),Pn.style.display=""}}))}function Kn(){null!=Rn&&(In=!0,Rn.setPaused(In),ln(),null!=Tn&&null!=Tn.srcObject&&Tn.srcObject instanceof MediaStream&&(Tn.srcObject.getTracks().forEach((e=>e.stop())),Tn=null),function(){if(null==xn)return;xn.style.visibility="hidden",xn.style.opacity="0"}(),Rn.stopCamera(),Pn.style.display="none")}function Hn(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Xn(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),r()}))))}}))}))}function Zn(e){null!=xn&&(kn.has(e)||(kn.add(e),xn.style.opacity="0"))}function Yn(e,t,n,o,r,i,a){const s=Rn.getTransformationBetween(e,t),l=pn(gn(),s),c=function(e,t){var n=new un(3);fn(n,t);var o=1/n[0],r=1/n[1],i=1/n[2],a=t[0]*o,s=t[1]*r,l=t[2]*i,c=t[4]*o,u=t[5]*r,d=t[6]*i,h=t[8]*o,p=t[9]*r,f=t[10]*i,m=a+u+f,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(d-p)/g,e[1]=(h-l)/g,e[2]=(s-c)/g):a>u&&a>f?(g=2*Math.sqrt(1+a-u-f),e[3]=(d-p)/g,e[0]=.25*g,e[1]=(s+c)/g,e[2]=(h+l)/g):u>f?(g=2*Math.sqrt(1+u-a-f),e[3]=(h-l)/g,e[0]=(s+c)/g,e[1]=.25*g,e[2]=(d+p)/g):(g=2*Math.sqrt(1+f-a-u),e[3]=(s-c)/g,e[0]=(h+l)/g,e[1]=(d+p)/g,e[2]=.25*g),e}(bn(),s);mn(s,c,l,vn(a,a,a));const u=Rn.getTransformationBetween(t,n),d=pn(gn(),u);mn(u,bn(),d,fn(gn(),u));const h=hn(dn(),s,u),p=pn(gn(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=Rn.getTransformationBetween(n,o)}catch(e){return f}const g=hn(dn(),u,m),v=hn(dn(),s,g),w=vn(p[0],i[1],i[2]),y=yn(gn(),w,function(e,t){var n=t[0],o=t[1],r=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],u=t[8],d=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15],w=n*s-o*a,y=n*l-r*a,b=n*c-i*a,E=o*l-r*s,A=o*c-i*s,S=r*c-i*l,M=u*m-d*f,R=u*g-h*f,T=u*v-p*f,C=d*g-h*m,P=d*v-p*m,I=h*v-p*g,x=w*I-y*P+b*C+E*T-A*R+S*M;return x?(x=1/x,e[0]=(s*I-l*P+c*C)*x,e[1]=(r*P-o*I-i*C)*x,e[2]=(m*S-g*A+v*E)*x,e[3]=(h*A-d*S-p*E)*x,e[4]=(l*T-a*I-c*R)*x,e[5]=(n*I-r*T+i*R)*x,e[6]=(g*b-f*S-v*y)*x,e[7]=(u*S-h*b+p*y)*x,e[8]=(a*P-s*T+c*M)*x,e[9]=(o*T-n*P-i*M)*x,e[10]=(f*A-m*b+v*w)*x,e[11]=(d*b-u*A-p*w)*x,e[12]=(s*R-a*C-l*M)*x,e[13]=(n*C-o*R+r*M)*x,e[14]=(m*y-f*E-g*w)*x,e[15]=(u*E-d*y+h*w)*x,e):null}(dn(),v));let b=Rn.getClosestPointOnMesh(o,y);try{const e=Rn.getClosestPointOnMesh(r,y);wn(y,e)<wn(y,b)&&(b=e)}catch(e){}const E=yn(gn(),b,g);return f-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function Jn(e){!function(e){rn.push(e)}(e)}function eo(e){!function(e){an.push(e)}(e)}var to;function no(){return[to.Android,to.iOS,to.Tablet].includes(function(){if("undefined"!=typeof window&&window.navigator){const e=window.navigator.userAgent,t=window.navigator.platform||"",n=["Macintosh","MacIntel","MacPPC","Mac68K"],o=["Win32","Win64","Windows","WinCE"],r=["iPhone","iPod","iPad"],i="ontouchstart"in window||navigator.maxTouchPoints>0;return-1!==r.indexOf(t)?to.iOS:-1!==n.indexOf(t)?i?to.Tablet:to.MacOS:-1!==o.indexOf(t)?to.Windows:/Android/.test(e)?to.Android:/Linux/.test(t)?to.Linux:i?to.Tablet:to.Unknown}return to.Unknown}())}!function(e){e[e.Unknown=0]="Unknown",e[e.Android=1]="Android",e[e.iOS=2]="iOS",e[e.Tablet=3]="Tablet",e[e.MacOS=4]="MacOS",e[e.Windows=5]="Windows",e[e.Linux=6]="Linux"}(to||(to={}));const oo=["AR","3D"];function ro(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function io(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}function ao(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}function so(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;ro(t,"apiKey"),ao(t,"apiKey"),ro(o,"sku"),ao(o,"sku"),ro(r,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(i,"initialState",oo),null!=a&&function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new n(`'${t}' must be a string or array.`)}(a,"initialAnimation"),null!=s&&ao(s,"baseUrl"),null!=l&&io(l,"defaultUI"),null!=c&&io(c,"interactive"),null!=u&&function(e,t,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new n(`Value for key '${r}' in '${t}' must be a string.`)}}(u,"strings",pt)}let lo=!1;function co(e){return t(this,void 0,void 0,(function*(){const{targetElement:o}=e;R.update(e.baseUrl),Xt();const{trackEvent:r}=function(e){const t=performance.now(),n=Ft();return{trackEvent:(o,r={})=>{r=Object.assign(Object.assign({},r),{pluginVersion:S,userAgent:Kt,sessionId:Bt,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Zt((()=>{window.ShopAR__analytics.trackEventImpl(o,r)}))}}}(e.apiKey);r("visionSetup");const i=yield function(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:e,sid:d()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield o.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(e.apiKey);r("visionApiResponse",i);const{arKey:a}=i,s=Ut(o),{getSetupId:l,findUI:c}=s,u=l();Nn(),jn();const{setTargetElement:h,getDeepARTarget:p,setVisibilityParameters:m,getUIState:g,setUIState:v,startDeepARLoading:w,stopDeepARLoading:y,showCameraError:b}=c();if(g()!=Ct.None)throw Error("UI state is not None, this is weird..");v(Ct.AR),h(o),m(!1,!1,!0,!1,void 0,void 0),w(),yield An,uo(l(),u);try{r("visionArLaunch"),Kn(),Wn("Glasses",["faceInit"]),qn(p()),yield Fn({licenseKey:a,truescaleUsecase:"DetectionLoop"}),uo(l(),u),yield Qn(),uo(l(),u)}catch(e){const t=e instanceof Error;throw r("visionArLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),b(),Kn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{y()}return lo=!0,{registerFacePoseListener:e=>{lo&&(r("registerFacePoseListener"),Jn(e))},registerFaceMeasurementListener:e=>{lo&&(r("registerFaceMeasurementListener"),eo(e))},switchEffect:e=>t(this,void 0,void 0,(function*(){lo&&(r("switchEffect",{arUrl:e}),function(e){Rn.switchEffect(e)}(e))})),clearEffect:()=>{lo&&(r("clearEffect"),Rn.clearEffect())},close:()=>{if(lo){if(lo=!1,r("visionClose"),g()!==Ct.AR)throw new n("AR not launched.");Kn(),v(Ct.None)}}}}))}function uo(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}function ho(e){var o,r;return t(this,void 0,void 0,(function*(){so(e);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=e,u=null==e.zoomEnabled||e.zoomEnabled,h=!0===e.alwaysTransparentBackground;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),R.update(e.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(ht,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(ht[t]=n)}}(e.strings);const p=null!=c?Se(c):null,y=null!=(null==p?void 0:p.theta)?ae(p.theta):null,b=null!=(null==p?void 0:p.phi)?ae(p.phi):null,M=null!=(null==p?void 0:p.fov)?ae(p.fov):null,P=function(e,o,r,i,a,s){return t(this,void 0,void 0,(function*(){const l=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams(Object.assign(Object.assign(Object.assign(Object.assign({apiKey:e,sku:o,sid:d()},null!=r&&{yaw:`${g(m(r))}`}),null!=i&&{pitch:`${g(m(i))}`}),null!=a&&{fov:`${g(m(a))}`}),s&&{forcedTransparency:`${s}`}))}`).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 l.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a,null==y?void 0:y.get(),null==b?void 0:b.get(),null==M?void 0:M.get(),h),I=Ut(s),{getSetupId:x,findUI:k,findQR:L,findThree:U}=I,$=x();Xt();const{trackEvent:D,arInteracted:O,previewInteracted:_}=function(e,t){const n=performance.now(),o=Ft();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,u(zt,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const u=(r,i={})=>{i=Object.assign(Object.assign({},i),{userAgent:Kt,pluginVersion:S,sessionId:Bt,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Zt((()=>{window.ShopAR__analytics.trackEventImpl(r,i)}))};return{trackEvent:u,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}(a,i);D("setup",{hostname:window.location.hostname});const N=yield P;D("apiResponse",N);const{category:j,arUrl:F,arEnvUrl:W,arToneMapping:q,arToneMappingExposure:G,arKey:z,arPromptEnabled:V,arPromptText:B,arPromptImage:Q,previewUrl:K,previewEnvUrl:H,previewToneMapping:X,previewToneMappingExposure:Z,previewPosterUrl:Y,cameraErrorText:J,qrPromptText:ee}=N;po(x(),$);const te=null!=F&&function(e){return null!=e&&v.includes(e)}(j),ne=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),oe=te&&function(e){return null!=e&&w.includes(e)}(j),re=ne&&oe&&!no(),ie=te&&!re,se=null!=K;if(po(x(),$),re&&function(){t(this,void 0,void 0,(function*(){null==C&&(C=T(`${R}/shopar-qr.js`))}))}(),ie&&(Nn(),function(e){e!==Mn&&(Mn=e,E(e),Un=null,ln())}(F),"Glasses"===j&&jn(),null!=W&&E(W)),se){null==He&&(He=T(`${R}/shopar-three.js`));const e=255;A(K,(new Date).getTime()+e,Math.random()*e),E(null!=H?H:`${R}/env/default.hdr`)}const{setTargetElement:le,getDeepARTarget:ce,getDeepARPrompt:ue,customizeDeepARPrompt:de,customizeCameraError:he,customizeQRPrompt:pe,setVisibilityParameters:fe,getUIState:me,setUIState:ge,setDefaultUIActions:ve,startDeepARLoading:we,stopDeepARLoading:ye,startThreeLoading:be,stopThreeLoading:Ee,setThreePosterUrl:Ae,showCameraError:Me}=k();le(s);fe(null==e.defaultUI||e.defaultUI,re,ie,se,j,l),de(null!=B?B:"",null!=Q?Q:""),he(J),pe(ee),Ae(Y),function(e,t){const o=e.parentNode;if(null==o)throw new n("Parent node missing.");new MutationObserver((n=>{for(const o of n)for(const n of o.removedNodes)if(n===e)return void t()})).observe(o,{childList:!0})}(s,(()=>{me()!==Ct.QR||Re()||Ce(),me()!==Ct.AR||In||Kn(),me()!==Ct.Preview||ke()||Ue(),ge(Ct.None)}));const{qrPaused:Re,qrDraw:Te,qrPause:Ce}=L(),{threeInit:Pe,threeParse:Ie,threeLoad:xe,threePaused:ke,threeResume:Le,threePause:Ue,threeSetZoomEnabled:$e,threeSetForcedTransparency:De,threeSetToneMapping:Oe,threeIsInteractive:_e,threeSetInteractive:Ne,threeSetOnInteracted:je,threeInitPromptAnimation:Fe,threeInitThetaAnimation:We,threeInitPhiAnimation:qe,threeInitFovAnimation:Ge}=U(),ze=null==e.interactive||e.interactive;Ne(ze);let Ve=0;if(me()===Ct.QR){if(!Re())if(re){D(Wt);try{yield Te(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ce(),ge(Ct.None)}else if(me()===Ct.AR){if(!In)if(ie&&!lo){D(qt);const e=null!=W?yield E(W):void 0;po(x(),$);const t=yield E(F);po(x(),$),$t(I),Wn(j),qn(ce()),Gn(V?ue():null),yield Vn(t,e,`${F}${W}`),Bn(q,G),zn(O),po(x(),$)}else Kn(),ge(Ct.None)}else if(me()===Ct.Preview&&!ke())if(se){D(Gt),be();const e=255,t=yield A(K,(new Date).getTime()+e,Math.random()*e);po(x(),$);const n=yield E(null!=H?H:`${R}/env/default.hdr`);po(x(),$);const o=yield Ie(t,n,`${K}${H}`);po(x(),$),xe(o,j),$e(u),De(h),Oe(null!=X?X:"ACES",null!=Z?Z:1),je(_),Fe(),null!=p&&(We(y),qe(b),Ge(M)),Ee()}else Ue(),ge(Ct.None);const Be=()=>t(this,void 0,void 0,(function*(){if(re){if(me()===Ct.QR||me()===Ct.AR)return;try{D(Wt);const e=++Ve;if(me()===Ct.Preview&&se&&!ke()&&Ue(),ge(Ct.QR),yield Te(i,a),Ve!==e)return;return void po(x(),$)}catch(e){const t=e instanceof Error;throw D("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!ie)throw new n("Model does not have AR enabled.");if(me()!==Ct.AR)try{D(qt);const e=++Ve;me()===Ct.Preview&&se&&!ke()&&Ue(),$t(I),ge(Ct.AR),we();const t=null!=W?yield E(W):void 0;po(x(),$);const n=yield E(F);if(Ve!==e)return;if(po(x(),$),yield An,Ve!==e)return;if(po(x(),$),Kn(),Wn(j),qn(ce()),Gn(V?ue():null),yield Fn({licenseKey:z}),Ve!==e)return;if(po(x(),$),yield Vn(n,t,`${F}${W}`),Bn(q,G),zn(O),Ve!==e)return;if(po(x(),$),yield Qn(),Ve!==e)return;po(x(),$)}catch(e){const t=e instanceof Error;throw D("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),Me(),Kn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{ye()}})),Qe=()=>t(this,void 0,void 0,(function*(){if(!se)throw new n("Model does not have 3D enabled.");if(me()!==Ct.Preview)try{D(Gt);const e=++Ve;me()===Ct.AR&&(ie&&!In&&Kn(),Ce()),ge(Ct.Preview),be();const t=255,n=yield A(K,(new Date).getTime()+t,Math.random()*t);if(Ve!==e)return;po(x(),$);const o=yield E(null!=H?H:`${R}/env/default.hdr`);if(console.log(o),Ve!==e)return;if(po(x(),$),yield He,Ve!==e)return;if(po(x(),$),Pe(),Ve!==e)return;po(x(),$);const r=yield Ie(n,o,`${K}${H}`);if(Ve!==e)return;po(x(),$),xe(r,j),$e(u),De(h),Oe(null!=X?X:"ACES",null!=Z?Z:1),je(_),Fe(),null!=p&&(We(y),qe(b),Ge(M)),Le()}catch(e){const t=e instanceof Error;throw D("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{Ee()}})),Ke=()=>t(this,void 0,void 0,(function*(){me()!==Ct.None&&(++Ve,me()===Ct.QR||me()===Ct.AR?(ie&&!In&&Kn(),Ce()):me()===Ct.Preview&&se&&!ke()&&Ue(),ge(Ct.None),"AR"!==l?"3D"!==l||(yield Qe()):yield Be())}));return ve(Be,Qe,Ke),"AR"===l?(yield Be(),po(x(),$)):"3D"===l&&(yield Qe(),po(x(),$)),lo=!1,{launchAR:te?Be:void 0,launch3D:se?Qe:void 0,closeAR:te?()=>t(this,void 0,void 0,(function*(){me()!==Ct.AR&&me()!==Ct.QR||(++Ve,ie&&!In&&Kn(),Ce(),ge(Ct.None),"3D"!==l||(yield Qe()))})):void 0,close3D:se?()=>t(this,void 0,void 0,(function*(){me()===Ct.Preview&&(++Ve,se&&!ke()&&Ue(),ge(Ct.None),"AR"!==l||(yield Be()))})):void 0,close:te||se?Ke:void 0,isInteractive:()=>_e(),setInteractive:e=>Ne(e)}}))}function po(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const fo={setup:function(e){return t(this,void 0,void 0,(function*(){return co(e)}))}},mo={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",(()=>ho(e)))}))},version:S};e.PREVIEW_STATES=oo,e.PluginError=n,e.plugin=mo,e.vision=fo}));