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