shopar-plugin 0.7.0-alpha.0 → 0.7.0
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.
- package/README.md +16 -5
- package/dist/shopar-analytics.js +1 -1
- package/dist/shopar-plugin.d.ts +6 -0
- package/dist/shopar-plugin.esm.js +1 -1
- package/dist/shopar-plugin.js +1 -1
- package/dist/shopar-qr.js +1 -1
- package/dist/shopar-three.js +1 -1
- package/package.json +1 -1
package/dist/shopar-plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{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.0-alpha.0";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.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let C,x,P;function I(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}(P.parse(e));return t.mapping=x.EquirectangularReflectionMapping,t.colorSpace=x.LinearSRGBColorSpace,t}const M=45,T=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,Q=1/(V-1),K="function"==typeof Float32Array;function B(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=K?new Float32Array(V):new Array(V);for(let t=0;t<V;++t)r[t]=Y(t*Q,e,n);function i(t){let o=0,i=1;const a=V-1;for(;i!==a&&r[i]<=t;++i)o+=Q;--i;const s=o+(t-r[i])/(r[i+1]-r[i])*Q,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+Q,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=B(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 Ce=300,xe=2e3,Pe=.05,Ie=2*Math.PI/32,Me=Ae("hold"),Te=Ae("sine"),ke=Ae("sine-in"),Le=Ae("sine-out");let Ue;const $e=0,De=3;let _e,Oe,Ne,je=!1,Fe=1,We=1,qe=1;const Ge=1;let ze;const Ve=new Map;function Qe(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=!1,b=!1,E=!0,A=!1,S=1,R=!0,U=!1,F=0,W=0,q=1,G=1,z=1;const V={threeInit:()=>{y||(Ke(),i=new Oe.Scene,a=new Oe.PerspectiveCamera(25,1,.5),s=new _e.OrbitControls(a,e),s.setInteractionEnabled(R),h=Oe.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(M,T).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(-M/2,M/2,T/2,-T/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,_.setRenderTarget(n),_.render(s,l),j.uniforms.tDiffuse.value=n.texture,j.uniforms.v.value=1*e/256,s.material=j,_.setRenderTarget(t),_.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=O;const o=_.getClearAlpha();_.setClearAlpha(0),_.setRenderTarget(t),_.render(e,l),e.overrideMaterial=null,c(L),c(.4*L),_.setRenderTarget(null),_.setClearAlpha(o),e.background=n}}}(i)),y=!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=_e).THREE,P=new t.RGBELoader,i.environment=I(n),function(e,t){const{THREE:n}=t;C=(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)}(ze,_e),o=e,C.parseAsync(o.buffer,"")})))(),d=o),u})),threeLoad:(e,t)=>{i.traverse((e=>{var t,n;e instanceof Oe.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 Oe.Box3).setFromObject(e.scene);l.position.y=n.min.y-$e,i.add(l),c(),b=!1,i.traverse((e=>{if(e instanceof Oe.Mesh){e.material.depthWrite=!0;const t=e.material;Array.isArray(t)?t.forEach((e=>{e.transmission>0&&(b=!0)})):t.transmission>0&&(b=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(_e.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,Oe.Vector3)),F=0},threePaused:()=>E,threeResume:()=>{E=!1,ze.setAnimationLoop(Be),e.style.visibility="visible",W=0,null==f||f.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset(),null==w||w.reset()},threePause:()=>{E=!0,function(){for(const{threePaused:e}of Ve.values())if(!e())return!1;return!0}()&&ze.setAnimationLoop(null),e.style.visibility="hidden",o.style.opacity="0",n.style.visibility="hidden"},threeSetToneMapping:(e,t)=>{const n={ACES:Oe.ACESFilmicToneMapping,Linear:Oe.LinearToneMapping,Neutral:Oe.NeutralToneMapping};null!=n[e]&&(h=n[e]),S=t},threeIsInteractive:()=>R,threeSetInteractive:e=>{R=e,null==s||s.setInteractionEnabled(R)},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:Me},{time:Ce,value:e,interpolation:Le},{time:Ce+xe/4,value:e+Ie,interpolation:Te},{time:Ce+3*xe/4,value:e-Ie,interpolation:ke},{time:Ce+xe,value:e,interpolation:Me},{time:Ce+2*xe,value:e,interpolation:Me}]),s.setTheta(f.get()),m=null,g=null,v=ne([{time:0,value:0,interpolation:Me},{time:Ce,value:1,interpolation:Me},{time:Ce+xe,value:0,interpolation:Me},{time:Ce+2*xe,value:0,interpolation:Me}]),w=ne([{time:0,value:0,interpolation:Me},{time:Ce,value:0,interpolation:Le},{time:Ce+xe/4,value:-Pe,interpolation:Te},{time:Ce+3*xe/4,value:Pe,interpolation:ke},{time:Ce+xe,value:0,interpolation:Me},{time:Ce+2*xe,value:0,interpolation:Me}])},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(!y||E)return;let t=0!==W?e-W:0;W=e,0===F?A=!0:F<De&&(t=0),F++,U||(s.hasUserInteracted()?(U=!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()),A=!0),null!=m&&(s.setPhi(m.get()),A=!0),null!=g&&(s.setFovRadians(g.get()),A=!0))),s.update()&&(A=!0)},shouldRender_:()=>!(!y||E)&&A,render_:()=>{const t=ze.toneMapping,s=ze.toneMappingExposure;ze.toneMapping=h,ze.toneMappingExposure=S,ze.setViewport(0,0,e.width,e.height),ze.setClearColor(new Oe.Color(16777215),b?1:0),ze.render(i,a),ze.toneMapping=t,ze.toneMappingExposure=s,A=!1,null!=r&&(r.clearRect(0,0,e.width,e.height),Ne.width>0&&Ne.height>0&&r.drawImage(Ne,0,We-e.height,e.width,e.height,0,0,e.width,e.height),n.style.visibility=R&&!U?"visible":"hidden",null!=v&&(o.style.opacity=`${v.get()}`),null!=w&&(o.style.transform=`translateX(${w.get()*Math.min(q,G)}px)`))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===q&&n===G&&qe===z||(e.width=Math.ceil(t*qe*Ge),e.height=Math.ceil(n*qe*Ge),q=t,G=n,z=qe,A=!0)},target_:e};return Ve.set(e,V),V}function Ke(){if(je)return;_e=window.ShopAR__THREE,Oe=_e.THREE,Ne=document.createElement("canvas");var e,t;Ne.style.position="block",ze=new Oe.WebGLRenderer({powerPreference:"high-performance",canvas:Ne,antialias:!0,alpha:!0}),ze.outputColorSpace=Oe.SRGBColorSpace,ze.toneMapping=Oe.ACESFilmicToneMapping,ze.setClearColor(new Oe.Color(16777215),0),e=ze,t=_e,F||(D=t.THREE,_=e,O=new D.MeshDepthMaterial,O.userData.darkness={value:U},O.onBeforeCompile=e=>{e.uniforms.darkness=O.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}`},O.depthTest=!1,O.depthWrite=!1,N=new D.ShaderMaterial(t.HorizontalBlurShader),N.depthTest=!1,j=new D.ShaderMaterial(t.VerticalBlurShader),j.depthTest=!1,F=!0),He(),je=!0}function Be(e){He(),ze.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of Ve.values())t(e),n()&&o()}function He(){let e=0,t=0;for(const{target_:n}of Ve.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*Ge),t=Math.ceil(t*n*Ge),e===Fe&&t===We&&n===qe||(Fe=e,We=t,qe=n,ze.setSize(Fe,We,!1));for(const{updateSize_:e}of Ve.values())e()}const Xe={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},Ze=Object.keys(Xe);function Ye(e){return Xe[e]}const Je="shopar-error";function et(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 tt(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=et("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 nt="shopar-control";const ot="shopar-deepar-output";function rt(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 it(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 lt="shopar-main";const ct="shopar-qr-output";const ut="shopar-three-output";var dt;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(dt||(dt={}));let ht=!1;function pt(){ht||(!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.")}}(),ht=!0)}function ft(){pt();const e=function(){const e=document.createElement("div");e.id=lt;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=ct;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=ot;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=ut,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=et("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=rt("shopar-ar-loading-container"),h=it("shopar-ar-loading-text",Ye("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=rt("shopar-3d-loading-container"),g=it("shopar-3d-loading-text",Ye("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 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=Je;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=nt,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(R);const C=tt("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(C);const x=tt("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${E}/img/icons/cube.svg`);R.appendChild(x);const P=tt("shopar-btn-close","Close","Close ShopAR view",`${E}/img/icons/close.svg`);R.append(P);let I,M,T=dt.None,k=!1,L=!1,U=!1,$=!1;function D(){f.classList.remove("active"),d.style.visibility="hidden"}function _(){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,I=r,M=i,mt(R,k),mt(C,k&&(U||L)&&T===dt.None),mt(x,k&&$&&T===dt.None),mt(P,k&&T!==dt.None),D(),_(),k||""===(a=S).style.display&&mt(a,!1)},getUIState:function(){return T},setUIState:function(e){T=e,T===dt.None?(D(),_(),k&&(mt(S,!1),mt(P,!1),(L||U)&&mt(C,!0),$&&mt(x,!0))):T===dt.QR||T===dt.AR?k&&(mt(S,!1),mt(C,!1),mt(x,$&&"AR"===M),mt(P,"AR"!==M)):T===dt.Preview&&k&&(mt(S,!1),mt(C,(L||U)&&"3D"===M),mt(x,!1),mt(P,"3D"!==M))},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}`;C.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(I),C.onclick=e),$&&(x.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:_,setThreePosterUrl:function(e){null!=e?(b.src=e,b.dataset.srcSet="true"):delete b.dataset.srcSet},showCameraError:function(){k&&mt(S,!0)}}}function mt(e,t){e.style.display=t?"":"none"}const gt=new Map;function vt(e){let n=gt.get(e);return null==n?(n=function(){let e=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=ft()),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=Qe(e(),t(),n())}return r}}}(),gt.set(e,n)):n.incrementSetupId_(),n}function wt(e){for(const t of gt.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===dt.AR&&r(dt.None)}}let yt;const bt=new Uint8Array(16);function Et(){if(!yt&&(yt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!yt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return yt(bt)}const At=[];for(let e=0;e<256;++e)At.push((e+256).toString(16).slice(1));var St={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Rt(e,t,n){if(St.randomUUID&&!t&&!e)return St.randomUUID();const o=(e=e||{}).random||(e.rng||Et)();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 At[e[t+0]]+At[e[t+1]]+At[e[t+2]]+At[e[t+3]]+"-"+At[e[t+4]]+At[e[t+5]]+"-"+At[e[t+6]]+At[e[t+7]]+"-"+At[e[t+8]]+At[e[t+9]]+"-"+At[e[t+10]]+At[e[t+11]]+At[e[t+12]]+At[e[t+13]]+At[e[t+14]]+At[e[t+15]]}(o)}const Ct="qrLaunch",xt="arLaunch",Pt="previewLaunch",It="heartbeat";let Mt,Tt,kt=!1,Lt=window.navigator.userAgent||"no user agent";const Ut=[];function $t(){null==Mt&&(Tt=Rt(),Mt=A(`${E}/shopar-analytics.js`),Mt.then((()=>{kt=!0,window.ShopAR__analytics.initializeImpl(),Ut.forEach((e=>e()))})))}function Dt(e){kt?e():Ut.push(e)}function _t(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Ot(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 Nt=200,jt=10;let Ft=!1,Wt=null,qt=[],Gt=[];function zt(e){return t(this,void 0,void 0,(function*(){Ft=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${E}/wasm/mediapipe`,e),Wt&&clearInterval(Wt);const o=[],r=[];Wt=setInterval((()=>t(this,void 0,void 0,(function*(){if(Ft)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());Ft||(null!=a&&null!=s&&function(e){for(let t of qt)t(e)}({translation:a,rotation:s}),null==e&&(o.push(t),r.push(i),o.length<jt||(o.shift(),r.shift(),function(e,t){for(let n of Gt)n({faceWidth:e,IPD:t})}(Qt(o),Qt(r)))))}))),Nt)}))}function Vt(){Gt=[],qt=[],Ft=!0}function Qt(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}function Kt(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 Bt="undefined"!=typeof Float32Array?Float32Array:Array;function Ht(){var e=new Bt(16);return Bt!=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 Xt(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 Zt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Yt(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 Jt(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 en(){var e=new Bt(3);return Bt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function tn(e,t,n){var o=new Bt(3);return o[0]=e,o[1]=t,o[2]=n,o}function nn(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 on(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 rn(){var e=new Bt(4);return Bt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}en(),function(){var e,t=(e=new Bt(4),Bt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var an;let sn,ln,cn;en(),tn(1,0,0),tn(0,1,0),rn(),rn(),an=new Bt(9),Bt!=Float32Array&&(an[1]=0,an[2]=0,an[3]=0,an[5]=0,an[6]=0,an[7]=0),an[0]=1,an[4]=1,an[8]=1;let un,dn,hn,pn,fn=!0,mn=null;const gn=new Set;let vn,wn,yn,bn,En,An;function Sn(){null==sn&&(sn=A(`${E}/shopar-deepar.js`))}function Rn(){null==ln&&(ln=A(`${E}/shopar-true-scale.js`))}function Cn(e){return t(this,void 0,void 0,(function*(){const{licenseKey:o,truescaleUsecase:r}=e;return En=r,null==vn&&(vn=(()=>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=$n(hn),r=_t(t);un=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:pn,additionalOptions:{hint:An,cameraConfig:{disableDefaultCamera:!0}}}),dn=yield Ot(r),yield Dn(un,dn,"user"===t),"Glasses"===hn&&(yield ln,zt(dn),"DetectionLoop"!==En&&jn((e=>{bn=e.faceWidth})))})))()),vn}))}function xn(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===hn&&(n=t,o=An,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!=un&&(un.shutdown(),un=null,vn=null),hn=e,An=t)}function Pn(e){e!==pn&&(pn=e,null!=un&&un.changePreviewElement(pn))}function In(e){mn=e}function Mn(e){un.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(bn){const e=137/(bn+5);un.changeParameterVector("GLASSES","","scale",e,e,e,0),un.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=On("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=On("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);un.changeParameterVector("temple_left","","rotation",0,56.6*-o,0,0),un.changeParameterVector("temple_right","","rotation",0,56.6*-r,0,0)}catch(e){return}}(e),Vt(),bn=null}e(),_n("Glasses")}},un.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),_n("Shoes"))},un.callbacks.onWristTracked=t=>{t.detected&&(e(),_n("Watches"))}}function Tn(e,n,o){return t(this,void 0,void 0,(function*(){return null!=wn&&yn===o||(yield wn,wn=un.switchEffect(e,{envmap:n}),yn=o),wn}))}function kn(e,t){null!=e&&null!=t&&(un.setToneMapping(e),un.setExposure(t))}function Ln(){return t(this,void 0,void 0,(function*(){if(null!=un){if(fn=!1,null==dn){const e=$n(hn),t=_t(e);dn=yield Ot(t),yield Dn(un,dn,"user"===e),"Glasses"===hn&&(zt(dn),"DetectionLoop"!==En&&jn((e=>{bn=e.faceWidth})))}!function(){if(null==mn)return;if(null==hn||gn.has(hn))return;mn.style.visibility="visible",mn.style.opacity="1"}(),un.setPaused(fn),pn.style.display=""}}))}function Un(){null!=un&&(fn=!0,un.setPaused(fn),Vt(),null!=dn&&null!=dn.srcObject&&dn.srcObject instanceof MediaStream&&(dn.srcObject.getTracks().forEach((e=>e.stop())),dn=null),function(){if(null==mn)return;mn.style.visibility="hidden",mn.style.opacity="0"}(),un.stopCamera(),pn.style.display="none")}function $n(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Dn(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 _n(e){null!=mn&&(gn.has(e)||(gn.add(e),mn.style.opacity="0"))}function On(e,t,n,o,r,i,a){const s=un.getTransformationBetween(e,t),l=Zt(en(),s),c=function(e,t){var n=new Bt(3);Yt(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}(rn(),s);Jt(s,c,l,tn(a,a,a));const u=un.getTransformationBetween(t,n),d=Zt(en(),u);Jt(u,rn(),d,Yt(en(),u));const h=Xt(Ht(),s,u),p=Zt(en(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=un.getTransformationBetween(n,o)}catch(e){return f}const g=Xt(Ht(),u,m),v=Xt(Ht(),s,g),w=tn(p[0],i[1],i[2]),y=on(en(),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,C=u*g-h*f,x=u*v-p*f,P=d*g-h*m,I=d*v-p*m,M=h*v-p*g,T=w*M-y*I+b*P+E*x-A*C+S*R;return T?(T=1/T,e[0]=(s*M-l*I+c*P)*T,e[1]=(r*I-o*M-i*P)*T,e[2]=(m*S-g*A+v*E)*T,e[3]=(h*A-d*S-p*E)*T,e[4]=(l*x-a*M-c*C)*T,e[5]=(n*M-r*x+i*C)*T,e[6]=(g*b-f*S-v*y)*T,e[7]=(u*S-h*b+p*y)*T,e[8]=(a*I-s*x+c*R)*T,e[9]=(o*x-n*I-i*R)*T,e[10]=(f*A-m*b+v*w)*T,e[11]=(d*b-u*A-p*w)*T,e[12]=(s*C-a*P-l*R)*T,e[13]=(n*P-o*C+r*R)*T,e[14]=(m*y-f*E-g*w)*T,e[15]=(u*E-d*y+h*w)*T,e):null}(Ht(),v));let b=un.getClosestPointOnMesh(o,y);try{const e=un.getClosestPointOnMesh(r,y);nn(y,e)<nn(y,b)&&(b=e)}catch(e){}const E=on(en(),b,g);return f-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function Nn(e){!function(e){qt.push(e)}(e)}function jn(e){!function(e){Gt.push(e)}(e)}var Fn;function Wn(){return[Fn.Android,Fn.iOS,Fn.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)?Fn.iOS:-1!==n.indexOf(t)?i?Fn.Tablet:Fn.MacOS:-1!==o.indexOf(t)?Fn.Windows:/Android/.test(e)?Fn.Android:/Linux/.test(t)?Fn.Linux:i?Fn.Tablet:Fn.Unknown}return Fn.Unknown}())}function qn(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"}(Fn||(Fn={}));const Gn=["AR","3D"];function zn(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Vn(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}function Qn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}function Kn(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;zn(t,"apiKey"),Qn(t,"apiKey"),zn(o,"sku"),Qn(o,"sku"),zn(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",Gn),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&&Qn(s,"baseUrl"),null!=l&&Vn(l,"defaultUI"),null!=c&&Vn(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",Ze)}let Bn=!1;function Hn(e){return t(this,void 0,void 0,(function*(){const{targetElement:o}=e;E.update(e.baseUrl),$t();const{trackEvent:r}=function(e){const t=performance.now(),n=Rt();return{trackEvent:(o,r={})=>{r=Object.assign(Object.assign({},r),{pluginVersion:y,userAgent:Lt,sessionId:Tt,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Dt((()=>{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=vt(o),{getSetupId:l,findUI:c}=s,u=l();Sn(),Rn();const{setTargetElement:h,getDeepARTarget:p,setVisibilityParameters:m,getUIState:g,setUIState:v,startDeepARLoading:w,stopDeepARLoading:b,showCameraError:A}=c();if(g()!=dt.None)throw Error("UI state is not None, this is weird..");v(dt.AR),h(o),m(!1,!1,!0,!1,void 0,void 0),w(),yield sn,Xn(l(),u);try{r("visionArLaunch"),Un(),xn("Glasses",["faceInit"]),Pn(p()),yield Cn({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Xn(l(),u),yield Ln(),Xn(l(),u)}catch(e){const t=e instanceof Error;throw r("visionArLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),A(),Un(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{b()}return Bn=!0,{registerFacePoseListener:e=>{Bn&&(r("registerFacePoseListener"),Nn(e))},registerFaceMeasurementListener:e=>{Bn&&(r("registerFaceMeasurementListener"),jn(e))},switchEffect:e=>t(this,void 0,void 0,(function*(){Bn&&(r("switchEffect",{arUrl:e}),function(e){un.switchEffect(e)}(e))})),clearEffect:()=>{Bn&&(r("clearEffect"),un.clearEffect())},close:()=>{if(Bn){if(Bn=!1,r("visionClose"),g()!==dt.AR)throw new n("AR not launched.");Un(),v(dt.None)}}}}))}function Xn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}function Zn(e){var o,r;return t(this,void 0,void 0,(function*(){Kn(e);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),E.update(e.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(Xe,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(Xe[t]=n)}}(e.strings);const u=null!=c?ye(c):null,h=null!=(null==u?void 0:u.theta)?ne(u.theta):null,p=null!=(null==u?void 0:u.phi)?ne(u.phi):null,b=null!=(null==u?void 0:u.fov)?ne(u.fov):null,R=function(e,o,r,i,a){return t(this,void 0,void 0,(function*(){const s=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({apiKey:e,sku:o,sid:d()},null!=r&&{yaw:`${g(m(r))}`}),null!=i&&{pitch:`${g(m(i))}`}),null!=a&&{fov:`${g(m(a))}`}))}`).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 s.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a,null==h?void 0:h.get(),null==p?void 0:p.get(),null==b?void 0:b.get()),C=vt(s),{getSetupId:x,findUI:P,findQR:I,findThree:M}=C,T=x();$t();const{trackEvent:k,arInteracted:L,previewInteracted:U}=function(e,t){const n=performance.now(),o=Rt();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,u(It,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const u=(r,i={})=>{i=Object.assign(Object.assign({},i),{userAgent:Lt,pluginVersion:y,sessionId:Tt,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Dt((()=>{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);k("setup",{hostname:window.location.hostname});const $=yield R;k("apiResponse",$);const{category:D,arUrl:_,arEnvUrl:O,arToneMapping:N,arToneMappingExposure:j,arKey:F,arPromptEnabled:W,arPromptText:q,arPromptImage:G,previewUrl:z,previewEnvUrl:V,previewToneMapping:Q,previewToneMappingExposure:K,previewPosterUrl:B,cameraErrorText:H,qrPromptText:X}=$;Yn(x(),T);const Z=null!=_&&function(e){return null!=e&&v.includes(e)}(D),Y=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),J=Z&&function(e){return null!=e&&w.includes(e)}(D),ee=Y&&J&&!Wn(),te=Z&&!ee,oe=null!=z;if(Yn(x(),T),ee&&function(){t(this,void 0,void 0,(function*(){null==S&&(S=A(`${E}/shopar-qr.js`))}))}(),te&&(Sn(),function(e){e!==cn&&(cn=e,Kt(e),wn=null,Vt())}(_),"Glasses"===D&&Rn(),null!=O&&Kt(O)),oe){null==Ue&&(Ue=A(`${E}/shopar-three.js`));const e=255;qn(z,(new Date).getTime()+e,Math.random()*e),Kt(null!=V?V:`${E}/env/default.hdr`)}const{setTargetElement:re,getDeepARTarget:ie,getDeepARPrompt:ae,customizeDeepARPrompt:se,customizeCameraError:le,customizeQRPrompt:ce,setVisibilityParameters:ue,getUIState:de,setUIState:he,setDefaultUIActions:pe,startDeepARLoading:fe,stopDeepARLoading:me,startThreeLoading:ge,stopThreeLoading:ve,setThreePosterUrl:we,showCameraError:be}=P();re(s);ue(null==e.defaultUI||e.defaultUI,ee,te,oe,D,l),se(null!=q?q:"",null!=G?G:""),le(H),ce(X),we(B),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,(()=>{de()!==dt.QR||Ee()||Se(),de()!==dt.AR||fn||Un(),de()!==dt.Preview||Pe()||Me(),he(dt.None)}));const{qrPaused:Ee,qrDraw:Ae,qrPause:Se}=I(),{threeInit:Re,threeParse:Ce,threeLoad:xe,threePaused:Pe,threeResume:Ie,threePause:Me,threeSetToneMapping:Te,threeIsInteractive:ke,threeSetInteractive:Le,threeSetOnInteracted:$e,threeInitPromptAnimation:De,threeInitThetaAnimation:_e,threeInitPhiAnimation:Oe,threeInitFovAnimation:Ne}=M(),je=null==e.interactive||e.interactive;Le(je);let Fe=0;if(de()===dt.QR){if(!Ee())if(ee){k(Ct);try{yield Ae(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Se(),he(dt.None)}else if(de()===dt.AR){if(!fn)if(te&&!Bn){k(xt);const e=null!=O?yield Kt(O):void 0;Yn(x(),T);const t=yield Kt(_);Yn(x(),T),wt(C),xn(D),Pn(ie()),In(W?ae():null),yield Tn(t,e,`${_}${O}`),kn(N,j),Mn(L),Yn(x(),T)}else Un(),he(dt.None)}else if(de()===dt.Preview&&!Pe())if(oe){k(Pt),ge();const e=255,t=yield qn(z,(new Date).getTime()+e,Math.random()*e);Yn(x(),T);const n=yield Kt(null!=V?V:`${E}/env/default.hdr`);Yn(x(),T);const o=yield Ce(t,n,`${z}${V}`);Yn(x(),T),xe(o,D),Te(null!=Q?Q:"ACES",null!=K?K:1),$e(U),De(),null!=u&&(_e(h),Oe(p),Ne(b)),ve()}else Me(),he(dt.None);const We=()=>t(this,void 0,void 0,(function*(){if(ee){if(de()===dt.QR||de()===dt.AR)return;try{k(Ct);const e=++Fe;if(de()===dt.Preview&&oe&&!Pe()&&Me(),he(dt.QR),yield Ae(i,a),Fe!==e)return;return void Yn(x(),T)}catch(e){const t=e instanceof Error;throw k("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!te)throw new n("Model does not have AR enabled.");if(de()!==dt.AR)try{k(xt);const e=++Fe;de()===dt.Preview&&oe&&!Pe()&&Me(),wt(C),he(dt.AR),fe();const t=null!=O?yield Kt(O):void 0;Yn(x(),T);const n=yield Kt(_);if(Fe!==e)return;if(Yn(x(),T),yield sn,Fe!==e)return;if(Yn(x(),T),Un(),xn(D),Pn(ie()),In(W?ae():null),yield Cn({licenseKey:F}),Fe!==e)return;if(Yn(x(),T),yield Tn(n,t,`${_}${O}`),kn(N,j),Mn(L),Fe!==e)return;if(Yn(x(),T),yield Ln(),Fe!==e)return;Yn(x(),T)}catch(e){const t=e instanceof Error;throw k("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),be(),Un(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{me()}})),qe=()=>t(this,void 0,void 0,(function*(){if(!oe)throw new n("Model does not have 3D enabled.");if(de()!==dt.Preview)try{k(Pt);const e=++Fe;de()===dt.AR&&(te&&!fn&&Un(),Se()),he(dt.Preview),ge();const t=255,n=yield qn(z,(new Date).getTime()+t,Math.random()*t);if(Fe!==e)return;Yn(x(),T);const o=yield Kt(null!=V?V:`${E}/env/default.hdr`);if(Fe!==e)return;if(Yn(x(),T),yield Ue,Fe!==e)return;if(Yn(x(),T),Re(),Fe!==e)return;Yn(x(),T);const r=yield Ce(n,o,`${z}${V}`);if(Fe!==e)return;Yn(x(),T),xe(r,D),Te(null!=Q?Q:"ACES",null!=K?K:1),$e(U),De(),null!=u&&(_e(h),Oe(p),Ne(b)),Ie()}catch(e){const t=e instanceof Error;throw k("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{ve()}})),Ge=()=>t(this,void 0,void 0,(function*(){de()!==dt.None&&(++Fe,de()===dt.QR||de()===dt.AR?(te&&!fn&&Un(),Se()):de()===dt.Preview&&oe&&!Pe()&&Me(),he(dt.None),"AR"!==l?"3D"!==l||(yield qe()):yield We())}));return pe(We,qe,Ge),"AR"===l?(yield We(),Yn(x(),T)):"3D"===l&&(yield qe(),Yn(x(),T)),Bn=!1,{launchAR:Z?We:void 0,launch3D:oe?qe:void 0,closeAR:Z?()=>t(this,void 0,void 0,(function*(){de()!==dt.AR&&de()!==dt.QR||(++Fe,te&&!fn&&Un(),Se(),he(dt.None),"3D"!==l||(yield qe()))})):void 0,close3D:oe?()=>t(this,void 0,void 0,(function*(){de()===dt.Preview&&(++Fe,oe&&!Pe()&&Me(),he(dt.None),"AR"!==l||(yield We()))})):void 0,close:Z||oe?Ge:void 0,isInteractive:()=>ke(),setInteractive:e=>Le(e)}}))}function Yn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const Jn={setup:function(e){return t(this,void 0,void 0,(function*(){return Hn(e)}))}},eo={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",(()=>Zn(e)))}))},version:y};e.PREVIEW_STATES=Gn,e.PluginError=n,e.plugin=eo,e.vision=Jn}));
|
|
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.0";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 C,P,x;function I(e){const t=function(e){const t=new P.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,P.ClampToEdgeWrapping,P.ClampToEdgeWrapping,P.LinearFilter,P.LinearFilter,1,P.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(x.parse(e));return t.mapping=P.EquirectangularReflectionMapping,t.colorSpace=P.LinearSRGBColorSpace,t}const M=45,T=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,Q=1/(V-1),K="function"==typeof Float32Array;function B(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=K?new Float32Array(V):new Array(V);for(let t=0;t<V;++t)r[t]=Y(t*Q,e,n);function i(t){let o=0,i=1;const a=V-1;for(;i!==a&&r[i]<=t;++i)o+=Q;--i;const s=o+(t-r[i])/(r[i+1]-r[i])*Q,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+Q,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=B(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 Ce=300,Pe=2e3,xe=.05,Ie=2*Math.PI/32,Me=Ae("hold"),Te=Ae("sine"),ke=Ae("sine-in"),Le=Ae("sine-out");let Ue;const $e=0,De=3;let _e,Oe,Ne,je=!1,Fe=1,We=1,qe=1;const Ge=1;let ze;const Ve=new Map;function Qe(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=!1,b=!1,E=!0,A=!1,S=1,R=!0,U=!1,F=0,W=0,q=1,G=1,z=1;const V={threeInit:()=>{y||(Ke(),i=new Oe.Scene,a=new Oe.PerspectiveCamera(25,1,.5),s=new _e.OrbitControls(a,e),s.setInteractionEnabled(R),h=Oe.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(M,T).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(-M/2,M/2,T/2,-T/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,_.setRenderTarget(n),_.render(s,l),j.uniforms.tDiffuse.value=n.texture,j.uniforms.v.value=1*e/256,s.material=j,_.setRenderTarget(t),_.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=O;const o=_.getClearAlpha();_.setClearAlpha(0),_.setRenderTarget(t),_.render(e,l),e.overrideMaterial=null,c(L),c(.4*L),_.setRenderTarget(null),_.setClearAlpha(o),e.background=n}}}(i)),y=!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 P=(t=_e).THREE,x=new t.RGBELoader,i.environment=I(n),function(e,t){const{THREE:n}=t;C=(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)}(ze,_e),o=e,C.parseAsync(o.buffer,"")})))(),d=o),u})),threeLoad:(e,t)=>{i.traverse((e=>{var t,n;e instanceof Oe.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 Oe.Box3).setFromObject(e.scene);l.position.y=n.min.y-$e,i.add(l),c(),b=!1,i.traverse((e=>{if(e instanceof Oe.Mesh){e.material.depthWrite=!0;const t=e.material;Array.isArray(t)?t.forEach((e=>{e.transmission>0&&(b=!0)})):t.transmission>0&&(b=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(_e.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,Oe.Vector3)),F=0},threePaused:()=>E,threeResume:()=>{E=!1,ze.setAnimationLoop(Be),e.style.visibility="visible",W=0,null==f||f.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset(),null==w||w.reset()},threePause:()=>{E=!0,function(){for(const{threePaused:e}of Ve.values())if(!e())return!1;return!0}()&&ze.setAnimationLoop(null),e.style.visibility="hidden",o.style.opacity="0",n.style.visibility="hidden"},threeSetZoomEnabled:e=>{s.enableZoom=e},threeSetToneMapping:(e,t)=>{const n={ACES:Oe.ACESFilmicToneMapping,Linear:Oe.LinearToneMapping,Neutral:Oe.NeutralToneMapping};null!=n[e]&&(h=n[e]),S=t},threeIsInteractive:()=>R,threeSetInteractive:e=>{R=e,null==s||s.setInteractionEnabled(R)},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:Me},{time:Ce,value:e,interpolation:Le},{time:Ce+Pe/4,value:e+Ie,interpolation:Te},{time:Ce+3*Pe/4,value:e-Ie,interpolation:ke},{time:Ce+Pe,value:e,interpolation:Me},{time:Ce+2*Pe,value:e,interpolation:Me}]),s.setTheta(f.get()),m=null,g=null,v=ne([{time:0,value:0,interpolation:Me},{time:Ce,value:1,interpolation:Me},{time:Ce+Pe,value:0,interpolation:Me},{time:Ce+2*Pe,value:0,interpolation:Me}]),w=ne([{time:0,value:0,interpolation:Me},{time:Ce,value:0,interpolation:Le},{time:Ce+Pe/4,value:-xe,interpolation:Te},{time:Ce+3*Pe/4,value:xe,interpolation:ke},{time:Ce+Pe,value:0,interpolation:Me},{time:Ce+2*Pe,value:0,interpolation:Me}])},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(!y||E)return;let t=0!==W?e-W:0;W=e,0===F?A=!0:F<De&&(t=0),F++,U||(s.hasUserInteracted()?(U=!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()),A=!0),null!=m&&(s.setPhi(m.get()),A=!0),null!=g&&(s.setFovRadians(g.get()),A=!0))),s.update()&&(A=!0)},shouldRender_:()=>!(!y||E)&&A,render_:()=>{const t=ze.toneMapping,s=ze.toneMappingExposure;ze.toneMapping=h,ze.toneMappingExposure=S,ze.setViewport(0,0,e.width,e.height),ze.setClearColor(new Oe.Color(16777215),b?1:0),ze.render(i,a),ze.toneMapping=t,ze.toneMappingExposure=s,A=!1,null!=r&&(r.clearRect(0,0,e.width,e.height),Ne.width>0&&Ne.height>0&&r.drawImage(Ne,0,We-e.height,e.width,e.height,0,0,e.width,e.height),n.style.visibility=R&&!U?"visible":"hidden",null!=v&&(o.style.opacity=`${v.get()}`),null!=w&&(o.style.transform=`translateX(${w.get()*Math.min(q,G)}px)`))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===q&&n===G&&qe===z||(e.width=Math.ceil(t*qe*Ge),e.height=Math.ceil(n*qe*Ge),q=t,G=n,z=qe,A=!0)},target_:e};return Ve.set(e,V),V}function Ke(){if(je)return;_e=window.ShopAR__THREE,Oe=_e.THREE,Ne=document.createElement("canvas");var e,t;Ne.style.position="block",ze=new Oe.WebGLRenderer({powerPreference:"high-performance",canvas:Ne,antialias:!0,alpha:!0}),ze.outputColorSpace=Oe.SRGBColorSpace,ze.toneMapping=Oe.ACESFilmicToneMapping,ze.setClearColor(new Oe.Color(16777215),0),e=ze,t=_e,F||(D=t.THREE,_=e,O=new D.MeshDepthMaterial,O.userData.darkness={value:U},O.onBeforeCompile=e=>{e.uniforms.darkness=O.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}`},O.depthTest=!1,O.depthWrite=!1,N=new D.ShaderMaterial(t.HorizontalBlurShader),N.depthTest=!1,j=new D.ShaderMaterial(t.VerticalBlurShader),j.depthTest=!1,F=!0),He(),je=!0}function Be(e){He(),ze.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of Ve.values())t(e),n()&&o()}function He(){let e=0,t=0;for(const{target_:n}of Ve.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*Ge),t=Math.ceil(t*n*Ge),e===Fe&&t===We&&n===qe||(Fe=e,We=t,qe=n,ze.setSize(Fe,We,!1));for(const{updateSize_:e}of Ve.values())e()}const Xe={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},Ze=Object.keys(Xe);function Ye(e){return Xe[e]}const Je="shopar-error";function et(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 tt(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=et("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 nt="shopar-control";const ot="shopar-deepar-output";function rt(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 it(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 lt="shopar-main";const ct="shopar-qr-output";const ut="shopar-three-output";var dt;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(dt||(dt={}));let ht=!1;function pt(){ht||(!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.")}}(),ht=!0)}function ft(){pt();const e=function(){const e=document.createElement("div");e.id=lt;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=ct;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=ot;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=ut,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=et("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=rt("shopar-ar-loading-container"),h=it("shopar-ar-loading-text",Ye("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=rt("shopar-3d-loading-container"),g=it("shopar-3d-loading-text",Ye("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 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=Je;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=nt,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(R);const C=tt("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(C);const P=tt("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${E}/img/icons/cube.svg`);R.appendChild(P);const x=tt("shopar-btn-close","Close","Close ShopAR view",`${E}/img/icons/close.svg`);R.append(x);let I,M,T=dt.None,k=!1,L=!1,U=!1,$=!1;function D(){f.classList.remove("active"),d.style.visibility="hidden"}function _(){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,I=r,M=i,mt(R,k),mt(C,k&&(U||L)&&T===dt.None),mt(P,k&&$&&T===dt.None),mt(x,k&&T!==dt.None),D(),_(),k||""===(a=S).style.display&&mt(a,!1)},getUIState:function(){return T},setUIState:function(e){T=e,T===dt.None?(D(),_(),k&&(mt(S,!1),mt(x,!1),(L||U)&&mt(C,!0),$&&mt(P,!0))):T===dt.QR||T===dt.AR?k&&(mt(S,!1),mt(C,!1),mt(P,$&&"AR"===M),mt(x,"AR"!==M)):T===dt.Preview&&k&&(mt(S,!1),mt(C,(L||U)&&"3D"===M),mt(P,!1),mt(x,"3D"!==M))},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}`;C.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(I),C.onclick=e),$&&(P.onclick=t),x.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:_,setThreePosterUrl:function(e){null!=e?(b.src=e,b.dataset.srcSet="true"):delete b.dataset.srcSet},showCameraError:function(){k&&mt(S,!0)}}}function mt(e,t){e.style.display=t?"":"none"}const gt=new Map;function vt(e){let n=gt.get(e);return null==n?(n=function(){let e=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=ft()),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=Qe(e(),t(),n())}return r}}}(),gt.set(e,n)):n.incrementSetupId_(),n}function wt(e){for(const t of gt.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===dt.AR&&r(dt.None)}}let yt;const bt=new Uint8Array(16);function Et(){if(!yt&&(yt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!yt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return yt(bt)}const At=[];for(let e=0;e<256;++e)At.push((e+256).toString(16).slice(1));var St={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Rt(e,t,n){if(St.randomUUID&&!t&&!e)return St.randomUUID();const o=(e=e||{}).random||(e.rng||Et)();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 At[e[t+0]]+At[e[t+1]]+At[e[t+2]]+At[e[t+3]]+"-"+At[e[t+4]]+At[e[t+5]]+"-"+At[e[t+6]]+At[e[t+7]]+"-"+At[e[t+8]]+At[e[t+9]]+"-"+At[e[t+10]]+At[e[t+11]]+At[e[t+12]]+At[e[t+13]]+At[e[t+14]]+At[e[t+15]]}(o)}const Ct="qrLaunch",Pt="arLaunch",xt="previewLaunch",It="heartbeat";let Mt,Tt,kt=!1,Lt=window.navigator.userAgent||"no user agent";const Ut=[];function $t(){null==Mt&&(Tt=Rt(),Mt=A(`${E}/shopar-analytics.js`),Mt.then((()=>{kt=!0,window.ShopAR__analytics.initializeImpl(),Ut.forEach((e=>e()))})))}function Dt(e){kt?e():Ut.push(e)}function _t(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Ot(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 Nt=200,jt=10;let Ft=!1,Wt=null,qt=[],Gt=[];function zt(e){return t(this,void 0,void 0,(function*(){Ft=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${E}/wasm/mediapipe`,e),Wt&&clearInterval(Wt);const o=[],r=[];Wt=setInterval((()=>t(this,void 0,void 0,(function*(){if(Ft)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());Ft||(null!=a&&null!=s&&function(e){for(let t of qt)t(e)}({translation:a,rotation:s}),null==e&&(o.push(t),r.push(i),o.length<jt||(o.shift(),r.shift(),function(e,t){for(let n of Gt)n({faceWidth:e,IPD:t})}(Qt(o),Qt(r)))))}))),Nt)}))}function Vt(){Gt=[],qt=[],Ft=!0}function Qt(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}function Kt(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 Bt="undefined"!=typeof Float32Array?Float32Array:Array;function Ht(){var e=new Bt(16);return Bt!=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 Xt(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 Zt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Yt(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 Jt(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 en(){var e=new Bt(3);return Bt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function tn(e,t,n){var o=new Bt(3);return o[0]=e,o[1]=t,o[2]=n,o}function nn(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 on(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 rn(){var e=new Bt(4);return Bt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}en(),function(){var e,t=(e=new Bt(4),Bt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var an;let sn,ln,cn;en(),tn(1,0,0),tn(0,1,0),rn(),rn(),an=new Bt(9),Bt!=Float32Array&&(an[1]=0,an[2]=0,an[3]=0,an[5]=0,an[6]=0,an[7]=0),an[0]=1,an[4]=1,an[8]=1;let un,dn,hn,pn,fn=!0,mn=null;const gn=new Set;let vn,wn,yn,bn,En,An;function Sn(){null==sn&&(sn=A(`${E}/shopar-deepar.js`))}function Rn(){null==ln&&(ln=A(`${E}/shopar-true-scale.js`))}function Cn(e){return t(this,void 0,void 0,(function*(){const{licenseKey:o,truescaleUsecase:r}=e;return En=r,null==vn&&(vn=(()=>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=$n(hn),r=_t(t);un=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:pn,additionalOptions:{hint:An,cameraConfig:{disableDefaultCamera:!0}}}),dn=yield Ot(r),yield Dn(un,dn,"user"===t),"Glasses"===hn&&(yield ln,zt(dn),"DetectionLoop"!==En&&jn((e=>{bn=e.faceWidth})))})))()),vn}))}function Pn(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===hn&&(n=t,o=An,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!=un&&(un.shutdown(),un=null,vn=null),hn=e,An=t)}function xn(e){e!==pn&&(pn=e,null!=un&&un.changePreviewElement(pn))}function In(e){mn=e}function Mn(e){un.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(bn){const e=137/(bn+5);un.changeParameterVector("GLASSES","","scale",e,e,e,0),un.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=On("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=On("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);un.changeParameterVector("temple_left","","rotation",0,56.6*-o,0,0),un.changeParameterVector("temple_right","","rotation",0,56.6*-r,0,0)}catch(e){return}}(e),Vt(),bn=null}e(),_n("Glasses")}},un.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),_n("Shoes"))},un.callbacks.onWristTracked=t=>{t.detected&&(e(),_n("Watches"))}}function Tn(e,n,o){return t(this,void 0,void 0,(function*(){return null!=wn&&yn===o||(yield wn,wn=un.switchEffect(e,{envmap:n}),yn=o),wn}))}function kn(e,t){null!=e&&null!=t&&(un.setToneMapping(e),un.setExposure(t))}function Ln(){return t(this,void 0,void 0,(function*(){if(null!=un){if(fn=!1,null==dn){const e=$n(hn),t=_t(e);dn=yield Ot(t),yield Dn(un,dn,"user"===e),"Glasses"===hn&&(zt(dn),"DetectionLoop"!==En&&jn((e=>{bn=e.faceWidth})))}!function(){if(null==mn)return;if(null==hn||gn.has(hn))return;mn.style.visibility="visible",mn.style.opacity="1"}(),un.setPaused(fn),pn.style.display=""}}))}function Un(){null!=un&&(fn=!0,un.setPaused(fn),Vt(),null!=dn&&null!=dn.srcObject&&dn.srcObject instanceof MediaStream&&(dn.srcObject.getTracks().forEach((e=>e.stop())),dn=null),function(){if(null==mn)return;mn.style.visibility="hidden",mn.style.opacity="0"}(),un.stopCamera(),pn.style.display="none")}function $n(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Dn(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 _n(e){null!=mn&&(gn.has(e)||(gn.add(e),mn.style.opacity="0"))}function On(e,t,n,o,r,i,a){const s=un.getTransformationBetween(e,t),l=Zt(en(),s),c=function(e,t){var n=new Bt(3);Yt(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}(rn(),s);Jt(s,c,l,tn(a,a,a));const u=un.getTransformationBetween(t,n),d=Zt(en(),u);Jt(u,rn(),d,Yt(en(),u));const h=Xt(Ht(),s,u),p=Zt(en(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=un.getTransformationBetween(n,o)}catch(e){return f}const g=Xt(Ht(),u,m),v=Xt(Ht(),s,g),w=tn(p[0],i[1],i[2]),y=on(en(),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,C=u*g-h*f,P=u*v-p*f,x=d*g-h*m,I=d*v-p*m,M=h*v-p*g,T=w*M-y*I+b*x+E*P-A*C+S*R;return T?(T=1/T,e[0]=(s*M-l*I+c*x)*T,e[1]=(r*I-o*M-i*x)*T,e[2]=(m*S-g*A+v*E)*T,e[3]=(h*A-d*S-p*E)*T,e[4]=(l*P-a*M-c*C)*T,e[5]=(n*M-r*P+i*C)*T,e[6]=(g*b-f*S-v*y)*T,e[7]=(u*S-h*b+p*y)*T,e[8]=(a*I-s*P+c*R)*T,e[9]=(o*P-n*I-i*R)*T,e[10]=(f*A-m*b+v*w)*T,e[11]=(d*b-u*A-p*w)*T,e[12]=(s*C-a*x-l*R)*T,e[13]=(n*x-o*C+r*R)*T,e[14]=(m*y-f*E-g*w)*T,e[15]=(u*E-d*y+h*w)*T,e):null}(Ht(),v));let b=un.getClosestPointOnMesh(o,y);try{const e=un.getClosestPointOnMesh(r,y);nn(y,e)<nn(y,b)&&(b=e)}catch(e){}const E=on(en(),b,g);return f-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function Nn(e){!function(e){qt.push(e)}(e)}function jn(e){!function(e){Gt.push(e)}(e)}var Fn;function Wn(){return[Fn.Android,Fn.iOS,Fn.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)?Fn.iOS:-1!==n.indexOf(t)?i?Fn.Tablet:Fn.MacOS:-1!==o.indexOf(t)?Fn.Windows:/Android/.test(e)?Fn.Android:/Linux/.test(t)?Fn.Linux:i?Fn.Tablet:Fn.Unknown}return Fn.Unknown}())}function qn(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"}(Fn||(Fn={}));const Gn=["AR","3D"];function zn(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Vn(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}function Qn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}function Kn(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;zn(t,"apiKey"),Qn(t,"apiKey"),zn(o,"sku"),Qn(o,"sku"),zn(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",Gn),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&&Qn(s,"baseUrl"),null!=l&&Vn(l,"defaultUI"),null!=c&&Vn(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",Ze)}let Bn=!1;function Hn(e){return t(this,void 0,void 0,(function*(){const{targetElement:o}=e;E.update(e.baseUrl),$t();const{trackEvent:r}=function(e){const t=performance.now(),n=Rt();return{trackEvent:(o,r={})=>{r=Object.assign(Object.assign({},r),{pluginVersion:y,userAgent:Lt,sessionId:Tt,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Dt((()=>{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=vt(o),{getSetupId:l,findUI:c}=s,u=l();Sn(),Rn();const{setTargetElement:h,getDeepARTarget:p,setVisibilityParameters:m,getUIState:g,setUIState:v,startDeepARLoading:w,stopDeepARLoading:b,showCameraError:A}=c();if(g()!=dt.None)throw Error("UI state is not None, this is weird..");v(dt.AR),h(o),m(!1,!1,!0,!1,void 0,void 0),w(),yield sn,Xn(l(),u);try{r("visionArLaunch"),Un(),Pn("Glasses",["faceInit"]),xn(p()),yield Cn({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Xn(l(),u),yield Ln(),Xn(l(),u)}catch(e){const t=e instanceof Error;throw r("visionArLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),A(),Un(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{b()}return Bn=!0,{registerFacePoseListener:e=>{Bn&&(r("registerFacePoseListener"),Nn(e))},registerFaceMeasurementListener:e=>{Bn&&(r("registerFaceMeasurementListener"),jn(e))},switchEffect:e=>t(this,void 0,void 0,(function*(){Bn&&(r("switchEffect",{arUrl:e}),function(e){un.switchEffect(e)}(e))})),clearEffect:()=>{Bn&&(r("clearEffect"),un.clearEffect())},close:()=>{if(Bn){if(Bn=!1,r("visionClose"),g()!==dt.AR)throw new n("AR not launched.");Un(),v(dt.None)}}}}))}function Xn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}function Zn(e){var o,r;return t(this,void 0,void 0,(function*(){Kn(e);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=e,u=null==e.zoomEnabled||e.zoomEnabled;!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(Xe,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(Xe[t]=n)}}(e.strings);const h=null!=c?ye(c):null,p=null!=(null==h?void 0:h.theta)?ne(h.theta):null,b=null!=(null==h?void 0:h.phi)?ne(h.phi):null,R=null!=(null==h?void 0:h.fov)?ne(h.fov):null,C=function(e,o,r,i,a){return t(this,void 0,void 0,(function*(){const s=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({apiKey:e,sku:o,sid:d()},null!=r&&{yaw:`${g(m(r))}`}),null!=i&&{pitch:`${g(m(i))}`}),null!=a&&{fov:`${g(m(a))}`}))}`).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 s.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a,null==p?void 0:p.get(),null==b?void 0:b.get(),null==R?void 0:R.get()),P=vt(s),{getSetupId:x,findUI:I,findQR:M,findThree:T}=P,k=x();$t();const{trackEvent:L,arInteracted:U,previewInteracted:$}=function(e,t){const n=performance.now(),o=Rt();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,u(It,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const u=(r,i={})=>{i=Object.assign(Object.assign({},i),{userAgent:Lt,pluginVersion:y,sessionId:Tt,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Dt((()=>{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);L("setup",{hostname:window.location.hostname});const D=yield C;L("apiResponse",D);const{category:_,arUrl:O,arEnvUrl:N,arToneMapping:j,arToneMappingExposure:F,arKey:W,arPromptEnabled:q,arPromptText:G,arPromptImage:z,previewUrl:V,previewEnvUrl:Q,previewToneMapping:K,previewToneMappingExposure:B,previewPosterUrl:H,cameraErrorText:X,qrPromptText:Z}=D;Yn(x(),k);const Y=null!=O&&function(e){return null!=e&&v.includes(e)}(_),J=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),ee=Y&&function(e){return null!=e&&w.includes(e)}(_),te=J&&ee&&!Wn(),oe=Y&&!te,re=null!=V;if(Yn(x(),k),te&&function(){t(this,void 0,void 0,(function*(){null==S&&(S=A(`${E}/shopar-qr.js`))}))}(),oe&&(Sn(),function(e){e!==cn&&(cn=e,Kt(e),wn=null,Vt())}(O),"Glasses"===_&&Rn(),null!=N&&Kt(N)),re){null==Ue&&(Ue=A(`${E}/shopar-three.js`));const e=255;qn(V,(new Date).getTime()+e,Math.random()*e),Kt(null!=Q?Q:`${E}/env/default.hdr`)}const{setTargetElement:ie,getDeepARTarget:ae,getDeepARPrompt:se,customizeDeepARPrompt:le,customizeCameraError:ce,customizeQRPrompt:ue,setVisibilityParameters:de,getUIState:he,setUIState:pe,setDefaultUIActions:fe,startDeepARLoading:me,stopDeepARLoading:ge,startThreeLoading:ve,stopThreeLoading:we,setThreePosterUrl:be,showCameraError:Ee}=I();ie(s);de(null==e.defaultUI||e.defaultUI,te,oe,re,_,l),le(null!=G?G:"",null!=z?z:""),ce(X),ue(Z),be(H),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,(()=>{he()!==dt.QR||Ae()||Re(),he()!==dt.AR||fn||Un(),he()!==dt.Preview||Ie()||Te(),pe(dt.None)}));const{qrPaused:Ae,qrDraw:Se,qrPause:Re}=M(),{threeInit:Ce,threeParse:Pe,threeLoad:xe,threePaused:Ie,threeResume:Me,threePause:Te,threeSetZoomEnabled:ke,threeSetToneMapping:Le,threeIsInteractive:$e,threeSetInteractive:De,threeSetOnInteracted:_e,threeInitPromptAnimation:Oe,threeInitThetaAnimation:Ne,threeInitPhiAnimation:je,threeInitFovAnimation:Fe}=T(),We=null==e.interactive||e.interactive;De(We);let qe=0;if(he()===dt.QR){if(!Ae())if(te){L(Ct);try{yield Se(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Re(),pe(dt.None)}else if(he()===dt.AR){if(!fn)if(oe&&!Bn){L(Pt);const e=null!=N?yield Kt(N):void 0;Yn(x(),k);const t=yield Kt(O);Yn(x(),k),wt(P),Pn(_),xn(ae()),In(q?se():null),yield Tn(t,e,`${O}${N}`),kn(j,F),Mn(U),Yn(x(),k)}else Un(),pe(dt.None)}else if(he()===dt.Preview&&!Ie())if(re){L(xt),ve();const e=255,t=yield qn(V,(new Date).getTime()+e,Math.random()*e);Yn(x(),k);const n=yield Kt(null!=Q?Q:`${E}/env/default.hdr`);Yn(x(),k);const o=yield Pe(t,n,`${V}${Q}`);Yn(x(),k),xe(o,_),ke(u),Le(null!=K?K:"ACES",null!=B?B:1),_e($),Oe(),null!=h&&(Ne(p),je(b),Fe(R)),we()}else Te(),pe(dt.None);const Ge=()=>t(this,void 0,void 0,(function*(){if(te){if(he()===dt.QR||he()===dt.AR)return;try{L(Ct);const e=++qe;if(he()===dt.Preview&&re&&!Ie()&&Te(),pe(dt.QR),yield Se(i,a),qe!==e)return;return void Yn(x(),k)}catch(e){const t=e instanceof Error;throw L("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!oe)throw new n("Model does not have AR enabled.");if(he()!==dt.AR)try{L(Pt);const e=++qe;he()===dt.Preview&&re&&!Ie()&&Te(),wt(P),pe(dt.AR),me();const t=null!=N?yield Kt(N):void 0;Yn(x(),k);const n=yield Kt(O);if(qe!==e)return;if(Yn(x(),k),yield sn,qe!==e)return;if(Yn(x(),k),Un(),Pn(_),xn(ae()),In(q?se():null),yield Cn({licenseKey:W}),qe!==e)return;if(Yn(x(),k),yield Tn(n,t,`${O}${N}`),kn(j,F),Mn(U),qe!==e)return;if(Yn(x(),k),yield Ln(),qe!==e)return;Yn(x(),k)}catch(e){const t=e instanceof Error;throw L("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),Ee(),Un(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{ge()}})),ze=()=>t(this,void 0,void 0,(function*(){if(!re)throw new n("Model does not have 3D enabled.");if(he()!==dt.Preview)try{L(xt);const e=++qe;he()===dt.AR&&(oe&&!fn&&Un(),Re()),pe(dt.Preview),ve();const t=255,n=yield qn(V,(new Date).getTime()+t,Math.random()*t);if(qe!==e)return;Yn(x(),k);const o=yield Kt(null!=Q?Q:`${E}/env/default.hdr`);if(qe!==e)return;if(Yn(x(),k),yield Ue,qe!==e)return;if(Yn(x(),k),Ce(),qe!==e)return;Yn(x(),k);const r=yield Pe(n,o,`${V}${Q}`);if(qe!==e)return;Yn(x(),k),xe(r,_),ke(u),Le(null!=K?K:"ACES",null!=B?B:1),_e($),Oe(),null!=h&&(Ne(p),je(b),Fe(R)),Me()}catch(e){const t=e instanceof Error;throw L("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{we()}})),Ve=()=>t(this,void 0,void 0,(function*(){he()!==dt.None&&(++qe,he()===dt.QR||he()===dt.AR?(oe&&!fn&&Un(),Re()):he()===dt.Preview&&re&&!Ie()&&Te(),pe(dt.None),"AR"!==l?"3D"!==l||(yield ze()):yield Ge())}));return fe(Ge,ze,Ve),"AR"===l?(yield Ge(),Yn(x(),k)):"3D"===l&&(yield ze(),Yn(x(),k)),Bn=!1,{launchAR:Y?Ge:void 0,launch3D:re?ze:void 0,closeAR:Y?()=>t(this,void 0,void 0,(function*(){he()!==dt.AR&&he()!==dt.QR||(++qe,oe&&!fn&&Un(),Re(),pe(dt.None),"3D"!==l||(yield ze()))})):void 0,close3D:re?()=>t(this,void 0,void 0,(function*(){he()===dt.Preview&&(++qe,re&&!Ie()&&Te(),pe(dt.None),"AR"!==l||(yield Ge()))})):void 0,close:Y||re?Ve:void 0,isInteractive:()=>$e(),setInteractive:e=>De(e)}}))}function Yn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const Jn={setup:function(e){return t(this,void 0,void 0,(function*(){return Hn(e)}))}},eo={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",(()=>Zn(e)))}))},version:y};e.PREVIEW_STATES=Gn,e.PluginError=n,e.plugin=eo,e.vision=Jn}));
|