shopar-plugin 0.7.3-alpha.2 → 0.7.3-alpha.3

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