shopar-plugin 0.0.6-alpha.6 → 0.0.6-alpha.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 +21 -0
- package/dist/shopar-plugin.esm.js +1 -1
- package/dist/shopar-plugin.js +1 -1
- package/dist/styles/default.css +7 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,6 +74,27 @@ To change the look-and-feel of the plugin's UI, modify the following CSS classes
|
|
|
74
74
|
.shopar-btn {
|
|
75
75
|
/* Control button. */
|
|
76
76
|
}
|
|
77
|
+
.shopar-btn:hover {
|
|
78
|
+
/* Hovered control button. */
|
|
79
|
+
}
|
|
80
|
+
.shopar-loading-container {
|
|
81
|
+
/* Container for the loading screen. */
|
|
82
|
+
}
|
|
83
|
+
.shopar-loading-text {
|
|
84
|
+
/* Loading text. */
|
|
85
|
+
}
|
|
86
|
+
.shopar-loading-bar-bg {
|
|
87
|
+
/* Loading bar's background. */
|
|
88
|
+
}
|
|
89
|
+
.shopar-loading-bar-fg {
|
|
90
|
+
/* Loading bar's foreground. */
|
|
91
|
+
}
|
|
92
|
+
.shopar-loading-bar-fg.active {
|
|
93
|
+
/* Loading bar's foreground when active. */
|
|
94
|
+
}
|
|
95
|
+
.shopar-qr {
|
|
96
|
+
/* Container for the QR code. */
|
|
97
|
+
}
|
|
77
98
|
```
|
|
78
99
|
|
|
79
100
|
Alternatively, use your own UI:
|
|
@@ -1 +1 @@
|
|
|
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-ar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-ar-loading-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-ar-loading-bar{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-ar-loading-bar.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-3d-loading-container{display:flex;align-items:end}.shopar-3d-loading-bg{width:100%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-3d-loading-bar{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-3d-loading-bar.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}"};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.6-alpha.6";let R=`https://cdn.jsdelivr.net/npm/shopar-plugin@${C}/dist`;const S={update:e=>{null!=e&&(R=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>R};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",$="previewLaunch",L="heartbeat";let M,P,U=!1;const T=[];function D(e,n){const t=performance.now(),o=E();let r=0,i=0,a=0,s=0,l=0,c=!1;const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:C,sessionId:P,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},U?a():T.push(a)};return window.setInterval((()=>{c&&(r=i+a,c=!1,d(L,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3),[d,()=>{const e=performance.now(),n=e-s;s=e,n<200&&(i+=n,c=!0)},()=>{const e=performance.now(),n=e-l;l=e,n<200&&(a+=n,c=!0)}]}function N(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function I(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,W,F,q=!1;function B(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 H,K,V,z,X,Q,Z,Y=!0;function J(e){e!==F&&(F=e,W=B(e),Q=null,null==H||H.clearEffect(),q=!0)}function ee(t,o,r){return e(this,void 0,void 0,(function*(){return V=r,z=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=N(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(r);H=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),K=yield I(s),yield ie(H,K,"user"===a),"Glasses"===r&&(yield G,function(n,t){e(this,void 0,void 0,(function*(){q=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${S}/wasm/mediapipe`,n);const r=[],i=setInterval((()=>e(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)}))),j)}))}(K,H))})))()),X}))}function ne(e){H.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},H.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},H.callbacks.onWristTracked=n=>{n.detected&&e()}}function te(n){return e(this,void 0,void 0,(function*(){return null==Q&&(Q=H.switchEffect(n)),Q}))}function oe(){null!=H&&(Y=!0,H.setPaused(Y),null!=K&&null!=K.srcObject&&K.srcObject instanceof MediaStream&&(K.srcObject.getTracks().forEach((e=>e.stop())),K=null),H.stopCamera(),z.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()}))))}}))}))}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 r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=ae("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 ce="shopar-control";const de="shopar-deepar-output";const ue="shopar-main";const he="shopar-qr-output";const pe="shopar-three-output";var fe;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(fe||(fe={}));let me,ve,ge,we,ye,be,Ee,Ce,Re,Se,Ae,ke,xe,$e,Le=fe.None;function Me(e){Le=e}let Pe,Ue=!1,Te=null;function De(){Ue||(!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.")}}(),me=function(){const e=document.createElement("div");e.id=ue;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),ge=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),ve=function(e){const n=document.createElement("div");n.id=he;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}(ge),me.appendChild(ve),we=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}(),me.appendChild(we),ye=function(){const e=document.createElement("canvas");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}(),me.appendChild(ye),xe=function(){const e=document.createElement("div");e.className="shopar-3d-loading-bar";const n=e.style;return n.width="100%",n.height="100%",e}(),ke=function(e){const n=document.createElement("div");n.className="shopar-3d-loading-container";const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%";const o=document.createElement("div");o.className="shopar-3d-loading-bg";const r=o.style;return r.position="relative",r.overflow="hidden",o.appendChild(e),n.appendChild(o),n}(xe),me.appendChild(ke),Ae=function(){const e=document.createElement("div");e.className="shopar-ar-loading-bar";const n=e.style;return n.width="100%",n.height="100%",e}(),Se=function(e){const n=document.createElement("div");n.className="shopar-ar-loading-container";const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%";const o=document.createElement("div");o.className="shopar-ar-loading-text",o.textContent="Loading Try On...",o.style.textAlign="center",n.appendChild(o);const r=document.createElement("div");r.className="shopar-ar-loading-bg";const i=r.style;return i.position="relative",i.overflow="hidden",r.appendChild(e),n.appendChild(r),n}(Ae),me.appendChild(Se),$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 r=ae("4rem",`${S}/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}(),me.appendChild($e),be=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}(),me.appendChild(be),Ee=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"),be.appendChild(Ee),Ce=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${S}/img/icons/cube.svg`),be.appendChild(Ce),Re=le("shopar-btn-close","Close","Close ShopAR view",`${S}/img/icons/close.svg`),be.append(Re),Ue=!0)}function Ne(e,n,t,o){var r;Ie(be,e),Ie(Ee,e&&(t||n)&&Le===fe.None),Ie(Ce,e&&o&&Le===fe.None),Ie(Re,e&&Le!==fe.None),je(),Oe(),e||""===(r=$e).style.display&&Ie(r,!1)}function Ie(e,n){e.style.display=n?"":"none"}function je(){Ae.classList.remove("active"),Se.style.visibility="hidden"}function _e(){xe.classList.add("active"),ke.style.visibility="visible"}function Oe(){xe.classList.remove("active"),ke.style.visibility="hidden"}let Ge,We,Fe,qe,Be,He=!0;function Ke(n,t){return e(this,void 0,void 0,(function*(){yield Pe;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=ge,i=new Promise(((e,n)=>{r.onload=e,r.onerror=n}));r.src=o,yield i,He=!1,ve.style.display=""}))}function Ve(){He=!0,ve.style.display="none"}let ze,Xe,Qe,Ze,Ye,Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un=!1,hn=!1;const pn=45,fn=45,mn=3,vn=.1,gn=3.5,wn=2,yn=1;let bn,En;function Cn(o){if(o!==Fe){const r=255;Fe=o,We=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),bn=null,null==sn||sn.clear()}}function Rn(e){dn.removeEventListener("change",En),En=e,dn.addEventListener("change",e)}function Sn(n,t){return e(this,void 0,void 0,(function*(){return null==bn&&(bn=(()=>e(this,void 0,void 0,(function*(){const e=new Xe.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}(Xe,e.parse(t));o.mapping=Qe.EquirectangularReflectionMapping,o.encoding=Qe.LinearEncoding,sn.environment=o;const r=(new Xe.GLTFLoader).setDRACOLoader((new Xe.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Qe.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Xe.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Qe.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(Ze)).setMeshoptDecoder("function"==typeof Xe.MeshoptDecoder?Xe.MeshoptDecoder():Xe.MeshoptDecoder);return yield r.parseAsync(n.buffer,"")})))()),bn}))}function An(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);ln.position.set(n[0],n[1],n[2])}function kn(e){sn.add(e.scene);const n=(new Qe.Box3).setFromObject(e.scene);Ye.position.y=n.min.y-vn,sn.add(Ye),sn.traverse((e=>{if(e instanceof Qe.Mesh){const n=e.material;n.depthWrite=!0,n instanceof Qe.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function xn(){un=!0,null!=ze&&(ze.style.display="none")}function $n(){if(un)return;requestAnimationFrame($n),Ln(),dn.update();const e=sn.background;sn.background=null,sn.overrideMaterial=on;const n=Ze.getClearAlpha();Ze.setClearAlpha(0),Ze.setRenderTarget(Je),Ze.render(sn,cn),sn.overrideMaterial=null,Mn(gn),Mn(.4*gn),Ze.setRenderTarget(null),Ze.setClearAlpha(n),sn.background=e,Ze.render(sn,ln)}function Ln(){const e=ze.clientWidth,n=ze.clientHeight;ze.width===e&&ze.height===n||(Ze.setSize(e,n,!1),ln.aspect=e/n,ln.updateProjectionMatrix())}function Mn(e){tn.visible=!0,rn.uniforms.tDiffuse.value=Je.texture,rn.uniforms.h.value=1*e/256,tn.material=rn,Ze.setRenderTarget(en),Ze.render(tn,cn),an.uniforms.tDiffuse.value=en.texture,an.uniforms.v.value=1*e/256,tn.material=an,Ze.setRenderTarget(Je),Ze.render(tn,cn),tn.visible=!1}function Pn(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Un(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const Tn=["AR","3D"];function Dn(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s}=e;Pn(t,"apiKey"),Un(t,"apiKey"),Pn(o,"sku"),Un(o,"sku"),Pn(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",Tn),null!=a&&Un(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let Nn=0,In=0;function jn(t){var o,r;return e(this,void 0,void 0,(function*(){Dn(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),S.update(t.baseUrl);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==M&&(P=E(),M=A(`${S}/shopar-analytics.js`),M.then((()=>{U=!0,window.ShopAR__analytics.initializeImpl(),T.forEach((e=>e()))})));const[u,h,v]=D(a,i);u("setup",{hostname:window.location.hostname}),De();const g=++In,w=yield c;u("apiResponse",w);const{category:y,arUrl:b,arKey:C,previewUrl:R,previewEnvUrl:L}=w;_n(g);const j=null!=b&&function(e){return null!=e&&f.includes(e)}(y),_=null==(null===(o=t._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=t._internalOptions)||void 0===r?void 0:r.qrEnabled),F=j&&function(e){return null!=e&&m.includes(e)}(y),q=_&&F&&!(yield function(){var n;return e(this,void 0,void 0,(function*(){return null==Z&&(Z=A(`${S}/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)}))}());_n(g),q&&function(){e(this,void 0,void 0,(function*(){null==Pe&&(Pe=A(`${S}/shopar-qr.js`))}))}();const X=j&&!q;X&&(null==O&&(O=A(`${S}/shopar-deepar.js`)),J(b),"Glasses"===y&&null==G&&(G=A(`${S}/shopar-true-scale.js`)));const Q=null!=R;var ae;Q&&(null==Ge&&(Ge=A(`${S}/shopar-three.js`)),Cn(R),(ae=null!=L?L:`${S}/env/default.hdr`)!==Be&&(Be=ae,qe=B(ae))),function(e){e.style.position="relative",null==Te?e.appendChild(me):e!==Te&&(Te.removeChild(me),e.appendChild(me)),Te=e}(s);const se=null==t.defaultUI||t.defaultUI;if(Ne(se,q,X,Q),Le===fe.AR){if(!Y)if(ne(h),X){u(x);const e=yield W;_n(g),yield te(e),_n(g)}else oe(),Me(fe.None),se&&(Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0));if(!He)if(q){u(k);try{yield Ke(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ve(),Me(fe.None),se&&(Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0))}else if(Le===fe.Preview&&!un)if(Rn(v),Q){u($),_e(),Ie(ye,!1);const e=yield We;_n(g);const n=yield qe;_n(g);const t=yield Sn(e,n);_n(g),An(y),kn(t),Ie(ye,!0),Oe()}else xn(),Me(fe.None),se&&(Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0));const le=()=>e(this,void 0,void 0,(function*(){if(q){if(Le===fe.AR)throw new n("AR already launched.");try{u(k);++Nn;return Le===fe.Preview&&Q&&!un&&xn(),Me(fe.AR),se&&(Ie(Ee,!1),Ie(Ce,!1),Ie(Re,!0)),se&&Ie($e,!1),void(yield Ke(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(Le===fe.AR)throw new n("AR already launched.");try{u(x);const n=++Nn;Le===fe.Preview&&Q&&!un&&xn(),Me(fe.AR),se&&(Ie(Ee,!1),Ie(Ce,!1),Ie(Re,!0)),se&&Ie($e,!1),Ae.classList.add("active"),Se.style.visibility="visible";const t=yield W;if(Nn!==n||In!==g)return;if(yield O,Nn!==n||In!==g)return;if(yield ee(we,C,y),Nn!==n||In!==g)return;if(ne(h),yield te(t),Nn!==n||In!==g)return;if(yield function(){return e(this,void 0,void 0,(function*(){if(null!=H){if(Y=!1,null==K){const e=re(V),n=N(e);K=yield I(n),yield ie(H,K,"user"===e)}H.setPaused(Y),z.style.display=""}}))}(),Nn!==n||In!==g)return}catch(e){const t=e instanceof Error;throw u("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),se&&Ie($e,!0),oe(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{je()}})),ce=()=>e(this,void 0,void 0,(function*(){if(!Q)throw new n("Model does not have 3D enabled.");if(Le===fe.Preview)throw new n("3D already launched.");try{u($);const n=++Nn;Le===fe.AR&&(X&&!Y&&oe(),Ve()),Me(fe.Preview),se&&(Ie(Ee,!1),Ie(Ce,!1),Ie(Re,!0)),se&&Ie($e,!1),_e();const t=yield We;if(Nn!==n||In!==g)return;const o=yield qe;if(Nn!==n||In!==g)return;if(yield Ge,Nn!==n||In!==g)return;if(yield function(n){return e(this,void 0,void 0,(function*(){if(ze=n,!hn){Xe=window.ShopAR__THREE,Qe=Xe.THREE,Ze=new Qe.WebGLRenderer({powerPreference:"high-performance",canvas:n,antialias:!0,alpha:!0}),Ze.outputEncoding=Qe.sRGBEncoding,Ze.toneMapping=Qe.ACESFilmicToneMapping,Ze.setPixelRatio(window.devicePixelRatio||1),Ze.setClearColor(new Qe.Color(16777215)),sn=new Qe.Scene,Ye=new Qe.Group,Ye.position.y=-.7,Je=new Qe.WebGLRenderTarget(512,512),Je.texture.generateMipmaps=!1,en=new Qe.WebGLRenderTarget(512,512),en.texture.generateMipmaps=!1;const e=new Qe.PlaneGeometry(pn,fn).rotateX(Math.PI/2),t=new Qe.MeshBasicMaterial({map:Je.texture,opacity:yn,transparent:!0,depthWrite:!1});nn=new Qe.Mesh(e,t),nn.renderOrder=1,Ye.add(nn),nn.scale.y=-1,tn=new Qe.Mesh(e),tn.visible=!1,Ye.add(tn),cn=new Qe.OrthographicCamera(-pn/2,pn/2,fn/2,-fn/2,0,mn),cn.rotation.x=Math.PI/2,Ye.add(cn),on=new Qe.MeshDepthMaterial,on.userData.darkness={value:wn},on.onBeforeCompile=function(e){e.uniforms.darkness=on.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 `},on.depthTest=!1,on.depthWrite=!1,rn=new Qe.ShaderMaterial(Xe.HorizontalBlurShader),rn.depthTest=!1,an=new Qe.ShaderMaterial(Xe.VerticalBlurShader),an.depthTest=!1,ln=new Qe.PerspectiveCamera(25,1,.5),dn=new Xe.OrbitControls(ln,Ze.domElement),dn.target.set(0,.03,0),dn.dampingFactor=.3,hn=!0}Ln()}))}(ye),Nn!==n||In!==g)return;Rn(v);const r=yield Sn(t,o);if(Nn!==n||In!==g)return;An(y),kn(r),un=!1,$n(),null!=ze&&(ze.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{Oe()}})),de=()=>e(this,void 0,void 0,(function*(){if(Le===fe.None)throw new n("Neither AR or 3D launched.");++Nn,Le===fe.AR?(X&&!Y&&oe(),Ve()):Le===fe.Preview&&Q&&!un&&xn(),Me(fe.None),je(),Oe(),se&&(Ie($e,!1),Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0))}));return se&&((q||X)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${S}/img/icons/${null!=e&&n[e]||n.Glasses}`;Ee.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(y),Ee.onclick=le),Q&&(Ce.onclick=ce),Re.onclick=de),"AR"===l?(yield le(),_n(g)):"3D"===l&&(yield ce(),_n(g)),{launchAR:le,launch3D:ce,closeAR:()=>e(this,void 0,void 0,(function*(){if(Le!==fe.AR)throw new n("AR not launched.");++Nn,X&&!Y&&oe(),Ve(),Me(fe.None),je(),se&&(Ie($e,!1),Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(Le!==fe.Preview)throw new n("3D not launched.");++Nn,Q&&!un&&xn(),Me(fe.None),Oe(),se&&(Ie($e,!1),Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0))})),close:de}}))}function _n(e){if(In!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const On={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",(()=>jn(t)))}))},version:C};export{On 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 C(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 E="0.0.6-alpha.7";let R=`https://cdn.jsdelivr.net/npm/shopar-plugin@${E}/dist`;const S={update:e=>{null!=e&&(R=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>R};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",L="previewLaunch",$="heartbeat";let M,P,U=!1;const D=[];function T(e,n){const t=performance.now(),o=C();let r=0,i=0,a=0,s=0,l=0,c=!1;const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:E,sessionId:P,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},U?a():D.push(a)};return window.setInterval((()=>{c&&(r=i+a,c=!1,d($,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3),[d,()=>{const e=performance.now(),n=e-s;s=e,n<200&&(i+=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,W,F,q=!1;function B(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 H,K,V,z,X,Q,Z,Y=!0;function J(e){e!==F&&(F=e,W=B(e),Q=null,null==H||H.clearEffect(),q=!0)}function ee(t,o,r){return e(this,void 0,void 0,(function*(){return V=r,z=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);H=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),K=yield N(s),yield ie(H,K,"user"===a),"Glasses"===r&&(yield G,function(n,t){e(this,void 0,void 0,(function*(){q=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${S}/wasm/mediapipe`,n);const r=[],i=setInterval((()=>e(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)}))),j)}))}(K,H))})))()),X}))}function ne(e){H.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},H.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},H.callbacks.onWristTracked=n=>{n.detected&&e()}}function te(n){return e(this,void 0,void 0,(function*(){return null==Q&&(Q=H.switchEffect(n)),Q}))}function oe(){null!=H&&(Y=!0,H.setPaused(Y),null!=K&&null!=K.srcObject&&K.srcObject instanceof MediaStream&&(K.srcObject.getTracks().forEach((e=>e.stop())),K=null),H.stopCamera(),z.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()}))))}}))}))}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 r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=ae("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 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,Ce,Ee,Re,Se,Ae,ke,xe,Le,$e,Me,Pe,Ue,De=we.None;function Te(e){De=e}let Ie,Ne=!1,je=null;function _e(){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}(),Ce=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 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}(Ce),ye.appendChild(be),Ee=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(Ee),Re=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(Re),Le=ue("shopar-ar-loading-container");const e=he("shopar-ar-loading-text","Loading Try On...");Le.appendChild(e);const n=pe("shopar-ar-loading-bar-bg");$e=fe("shopar-ar-loading-bar-fg"),n.appendChild($e),Le.appendChild(n),ye.appendChild(Le),Me=ue("shopar-3d-loading-container");const t=he("shopar-3d-loading-text","Loading 3D...");Me.appendChild(t);const o=pe("shopar-3d-loading-bar-bg");Pe=fe("shopar-3d-loading-bar-fg"),o.appendChild(Pe),Me.appendChild(o),ye.appendChild(Me),Ue=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 r=ae("4rem",`${S}/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}(),ye.appendChild(Ue),Se=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(Se),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"),Se.appendChild(Ae),ke=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${S}/img/icons/cube.svg`),Se.appendChild(ke),xe=le("shopar-btn-close","Close","Close ShopAR view",`${S}/img/icons/close.svg`),Se.append(xe),Ne=!0}function Oe(e,n,t,o){var r;Ge(Se,e),Ge(Ae,e&&(t||n)&&De===we.None),Ge(ke,e&&o&&De===we.None),Ge(xe,e&&De!==we.None),We(),qe(),e||""===(r=Ue).style.display&&Ge(r,!1)}function Ge(e,n){e.style.display=n?"":"none"}function We(){$e.classList.remove("active"),Le.style.visibility="hidden"}function Fe(){Pe.classList.add("active"),Me.style.visibility="visible"}function qe(){Pe.classList.remove("active"),Me.style.visibility="hidden"}let Be,He,Ke,Ve,ze,Xe=!0;function Qe(n,t){return e(this,void 0,void 0,(function*(){yield Ie;const e=`https://apps.deepar.ai/${E.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:n,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),r=Ce,i=new Promise(((e,n)=>{r.onload=e,r.onerror=n}));r.src=o,yield i,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=!1,vn=!1;const gn=45,wn=45,yn=3,bn=.1,Cn=3.5,En=2,Rn=1;let Sn,An;function kn(o){if(o!==Ke){const r=255;Ke=o,He=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),Sn=null,null==un||un.clear()}}function xn(e){fn.removeEventListener("change",An),An=e,fn.addEventListener("change",e)}function Ln(n,t){return e(this,void 0,void 0,(function*(){return null==Sn&&(Sn=(()=>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 r=(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 r.parseAsync(n.buffer,"")})))()),Sn}))}function $n(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);hn.position.set(n[0],n[1],n[2])}function Mn(e){un.add(e.scene);const n=(new en.Box3).setFromObject(e.scene);tn.position.y=n.min.y-bn,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)}}))}function Pn(){mn=!0,null!=Ye&&(Ye.style.display="none")}function Un(){if(mn)return;requestAnimationFrame(Un),Dn(),fn.update();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,Tn(Cn),Tn(.4*Cn),nn.setRenderTarget(null),nn.setClearAlpha(n),un.background=e,nn.render(un,hn)}function Dn(){const e=Ye.clientWidth,n=Ye.clientHeight;Ye.width===e&&Ye.height===n||(nn.setSize(e,n,!1),hn.aspect=e/n,hn.updateProjectionMatrix())}function Tn(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 In(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Nn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const jn=["AR","3D"];function _n(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s}=e;In(t,"apiKey"),Nn(t,"apiKey"),In(o,"sku"),Nn(o,"sku"),In(r,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(i,"initialState",jn),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let On=0,Gn=0;function Wn(t){var o,r;return e(this,void 0,void 0,(function*(){_n(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),S.update(t.baseUrl);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==M&&(P=C(),M=A(`${S}/shopar-analytics.js`),M.then((()=>{U=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[u,h,v]=T(a,i);u("setup",{hostname:window.location.hostname}),_e();const g=++Gn,w=yield c;u("apiResponse",w);const{category:y,arUrl:b,arKey:E,previewUrl:R,previewEnvUrl:$}=w;Fn(g);const j=null!=b&&function(e){return null!=e&&f.includes(e)}(y),_=null==(null===(o=t._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=t._internalOptions)||void 0===r?void 0:r.qrEnabled),F=j&&function(e){return null!=e&&m.includes(e)}(y),q=_&&F&&!(yield function(){var n;return e(this,void 0,void 0,(function*(){return null==Z&&(Z=A(`${S}/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)}))}());Fn(g),q&&function(){e(this,void 0,void 0,(function*(){null==Ie&&(Ie=A(`${S}/shopar-qr.js`))}))}();const X=j&&!q;X&&(null==O&&(O=A(`${S}/shopar-deepar.js`)),J(b),"Glasses"===y&&null==G&&(G=A(`${S}/shopar-true-scale.js`)));const Q=null!=R;var ae;Q&&(null==Be&&(Be=A(`${S}/shopar-three.js`)),kn(R),(ae=null!=$?$:`${S}/env/default.hdr`)!==ze&&(ze=ae,Ve=B(ae))),function(e){e.style.position="relative",null==je?e.appendChild(ye):e!==je&&(je.removeChild(ye),e.appendChild(ye)),je=e}(s);const se=null==t.defaultUI||t.defaultUI;if(Oe(se,q,X,Q),De===we.AR){if(!Y)if(ne(h),X){u(x);const e=yield W;Fn(g),yield te(e),Fn(g)}else oe(),Te(we.None),se&&(Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0));if(!Xe)if(q){u(k);try{yield Qe(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ze(),Te(we.None),se&&(Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0))}else if(De===we.Preview&&!mn)if(xn(v),Q){u(L),Fe(),Ge(Re,!1);const e=yield He;Fn(g);const n=yield Ve;Fn(g);const t=yield Ln(e,n);Fn(g),$n(y),Mn(t),Ge(Re,!0),qe()}else Pn(),Te(we.None),se&&(Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0));const le=()=>e(this,void 0,void 0,(function*(){if(q){if(De===we.AR)throw new n("AR already launched.");try{u(k);++On;return De===we.Preview&&Q&&!mn&&Pn(),Te(we.AR),se&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),se&&Ge(Ue,!1),void(yield Qe(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(De===we.AR)throw new n("AR already launched.");try{u(x);const n=++On;De===we.Preview&&Q&&!mn&&Pn(),Te(we.AR),se&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),se&&Ge(Ue,!1),$e.classList.add("active"),Le.style.visibility="visible";const t=yield W;if(On!==n||Gn!==g)return;if(yield O,On!==n||Gn!==g)return;if(yield ee(Ee,E,y),On!==n||Gn!==g)return;if(ne(h),yield te(t),On!==n||Gn!==g)return;if(yield function(){return e(this,void 0,void 0,(function*(){if(null!=H){if(Y=!1,null==K){const e=re(V),n=I(e);K=yield N(n),yield ie(H,K,"user"===e)}H.setPaused(Y),z.style.display=""}}))}(),On!==n||Gn!==g)return}catch(e){const t=e instanceof Error;throw u("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),se&&Ge(Ue,!0),oe(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{We()}})),ce=()=>e(this,void 0,void 0,(function*(){if(!Q)throw new n("Model does not have 3D enabled.");if(De===we.Preview)throw new n("3D already launched.");try{u(L);const n=++On;De===we.AR&&(X&&!Y&&oe(),Ze()),Te(we.Preview),se&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),se&&Ge(Ue,!1),Fe();const t=yield He;if(On!==n||Gn!==g)return;const o=yield Ve;if(On!==n||Gn!==g)return;if(yield Be,On!==n||Gn!==g)return;if(yield function(n){return e(this,void 0,void 0,(function*(){if(Ye=n,!vn){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(gn,wn).rotateX(Math.PI/2),t=new en.MeshBasicMaterial({map:on.texture,opacity:Rn,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(-gn/2,gn/2,wn/2,-wn/2,0,yn),pn.rotation.x=Math.PI/2,tn.add(pn),ln=new en.MeshDepthMaterial,ln.userData.darkness={value:En},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.target.set(0,.03,0),fn.dampingFactor=.3,vn=!0}Dn()}))}(Re),On!==n||Gn!==g)return;xn(v);const r=yield Ln(t,o);if(On!==n||Gn!==g)return;$n(y),Mn(r),mn=!1,Un(),null!=Ye&&(Ye.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{qe()}})),de=()=>e(this,void 0,void 0,(function*(){if(De===we.None)throw new n("Neither AR or 3D launched.");++On,De===we.AR?(X&&!Y&&oe(),Ze()):De===we.Preview&&Q&&!mn&&Pn(),Te(we.None),We(),qe(),se&&(Ge(Ue,!1),Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0))}));return se&&((q||X)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${S}/img/icons/${null!=e&&n[e]||n.Glasses}`;Ae.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(y),Ae.onclick=le),Q&&(ke.onclick=ce),xe.onclick=de),"AR"===l?(yield le(),Fn(g)):"3D"===l&&(yield ce(),Fn(g)),{launchAR:le,launch3D:ce,closeAR:()=>e(this,void 0,void 0,(function*(){if(De!==we.AR)throw new n("AR not launched.");++On,X&&!Y&&oe(),Ze(),Te(we.None),We(),se&&(Ge(Ue,!1),Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(De!==we.Preview)throw new n("3D not launched.");++On,Q&&!mn&&Pn(),Te(we.None),qe(),se&&(Ge(Ue,!1),Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0))})),close:de}}))}function Fn(e){if(Gn!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const qn={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",(()=>Wn(t)))}))},version:E};export{qn 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-ar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-ar-loading-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-ar-loading-bar{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-ar-loading-bar.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-3d-loading-container{display:flex;align-items:end}.shopar-3d-loading-bg{width:100%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-3d-loading-bar{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-3d-loading-bar.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}"};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 R="0.0.6-alpha.6";let S=`https://cdn.jsdelivr.net/npm/shopar-plugin@${R}/dist`;const A={update:e=>{null!=e&&(S=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>S};function k(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 x="qrLaunch",$="arLaunch",L="previewLaunch",M="heartbeat";let P,U,T=!1;const D=[];function N(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:R,sessionId:U,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},T?a():D.push(a)};return window.setInterval((()=>{c&&(i=r+a,c=!1,d(M,{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 j(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,W,F,q,B=!1;function H(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 K,V,z,X,Q,Z,Y,J=!0;function ee(e){e!==q&&(q=e,F=H(e),Z=null,null==K||K.clearEffect(),B=!0)}function ne(e,o,i){return n(this,void 0,void 0,(function*(){return z=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=I(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(i);K=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),V=yield j(s),yield ae(K,V,"user"===a),"Glasses"===i&&(yield W,function(e,t){n(this,void 0,void 0,(function*(){B=!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(B)return void clearInterval(r);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(B)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)}))),_)}))}(V,K))})))()),Q}))}function te(e){K.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},K.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},K.callbacks.onWristTracked=n=>{n.detected&&e()}}function oe(e){return n(this,void 0,void 0,(function*(){return null==Z&&(Z=K.switchEffect(e)),Z}))}function ie(){null!=K&&(J=!0,K.setPaused(J),null!=V&&null!=V.srcObject&&V.srcObject instanceof MediaStream&&(V.srcObject.getTracks().forEach((e=>e.stop())),V=null),K.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";const he="shopar-main";const pe="shopar-qr-output";const fe="shopar-three-output";var me;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(me||(me={}));let ve,ge,we,ye,be,Ee,Ce,Re,Se,Ae,ke,xe,$e,Le,Me=me.None;function Pe(e){Me=e}let Ue,Te=!1,De=null;function Ne(){Te||(!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.")}}(),ve=function(){const e=document.createElement("div");e.id=he;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),we=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),ge=function(e){const n=document.createElement("div");n.id=pe;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}(we),ve.appendChild(ge),ye=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}(),ve.appendChild(ye),be=function(){const e=document.createElement("canvas");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}(),ve.appendChild(be),$e=function(){const e=document.createElement("div");e.className="shopar-3d-loading-bar";const n=e.style;return n.width="100%",n.height="100%",e}(),xe=function(e){const n=document.createElement("div");n.className="shopar-3d-loading-container";const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%";const o=document.createElement("div");o.className="shopar-3d-loading-bg";const i=o.style;return i.position="relative",i.overflow="hidden",o.appendChild(e),n.appendChild(o),n}($e),ve.appendChild(xe),ke=function(){const e=document.createElement("div");e.className="shopar-ar-loading-bar";const n=e.style;return n.width="100%",n.height="100%",e}(),Ae=function(e){const n=document.createElement("div");n.className="shopar-ar-loading-container";const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%";const o=document.createElement("div");o.className="shopar-ar-loading-text",o.textContent="Loading Try On...",o.style.textAlign="center",n.appendChild(o);const i=document.createElement("div");i.className="shopar-ar-loading-bg";const r=i.style;return r.position="relative",r.overflow="hidden",i.appendChild(e),n.appendChild(i),n}(ke),ve.appendChild(Ae),Le=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}(),ve.appendChild(Le),Ee=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}(),ve.appendChild(Ee),Ce=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"),Ee.appendChild(Ce),Re=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${A}/img/icons/cube.svg`),Ee.appendChild(Re),Se=ce("shopar-btn-close","Close","Close ShopAR view",`${A}/img/icons/close.svg`),Ee.append(Se),Te=!0)}function Ie(e,n,t,o){var i;je(Ee,e),je(Ce,e&&(t||n)&&Me===me.None),je(Re,e&&o&&Me===me.None),je(Se,e&&Me!==me.None),_e(),Ge(),e||""===(i=Le).style.display&&je(i,!1)}function je(e,n){e.style.display=n?"":"none"}function _e(){ke.classList.remove("active"),Ae.style.visibility="hidden"}function Oe(){$e.classList.add("active"),xe.style.visibility="visible"}function Ge(){$e.classList.remove("active"),xe.style.visibility="hidden"}let We,Fe,qe,Be,He,Ke=!0;function Ve(e,t){return n(this,void 0,void 0,(function*(){yield Ue;const n=`https://apps.deepar.ai/${R.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(n),i=we,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Ke=!1,ge.style.display=""}))}function ze(){Ke=!0,ge.style.display="none"}let Xe,Qe,Ze,Ye,Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn=!1,pn=!1;const fn=45,mn=45,vn=3,gn=.1,wn=3.5,yn=2,bn=1;let En,Cn;function Rn(e){if(e!==qe){const i=255;qe=e,Fe=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),En=null,null==ln||ln.clear()}}function Sn(e){un.removeEventListener("change",Cn),Cn=e,un.addEventListener("change",e)}function An(e,t){return n(this,void 0,void 0,(function*(){return null==En&&(En=(()=>n(this,void 0,void 0,(function*(){const n=new Qe.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}(Qe,n.parse(t));o.mapping=Ze.EquirectangularReflectionMapping,o.encoding=Ze.LinearEncoding,ln.environment=o;const i=(new Qe.GLTFLoader).setDRACOLoader((new Qe.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ze.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Qe.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ze.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(Ye)).setMeshoptDecoder("function"==typeof Qe.MeshoptDecoder?Qe.MeshoptDecoder():Qe.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),En}))}function kn(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);cn.position.set(n[0],n[1],n[2])}function xn(e){ln.add(e.scene);const n=(new Ze.Box3).setFromObject(e.scene);Je.position.y=n.min.y-gn,ln.add(Je),ln.traverse((e=>{if(e instanceof Ze.Mesh){const n=e.material;n.depthWrite=!0,n instanceof Ze.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function $n(){hn=!0,null!=Xe&&(Xe.style.display="none")}function Ln(){if(hn)return;requestAnimationFrame(Ln),Mn(),un.update();const e=ln.background;ln.background=null,ln.overrideMaterial=rn;const n=Ye.getClearAlpha();Ye.setClearAlpha(0),Ye.setRenderTarget(en),Ye.render(ln,dn),ln.overrideMaterial=null,Pn(wn),Pn(.4*wn),Ye.setRenderTarget(null),Ye.setClearAlpha(n),ln.background=e,Ye.render(ln,cn)}function Mn(){const e=Xe.clientWidth,n=Xe.clientHeight;Xe.width===e&&Xe.height===n||(Ye.setSize(e,n,!1),cn.aspect=e/n,cn.updateProjectionMatrix())}function Pn(e){on.visible=!0,an.uniforms.tDiffuse.value=en.texture,an.uniforms.h.value=1*e/256,on.material=an,Ye.setRenderTarget(nn),Ye.render(on,dn),sn.uniforms.tDiffuse.value=nn.texture,sn.uniforms.v.value=1*e/256,on.material=sn,Ye.setRenderTarget(en),Ye.render(on,dn),on.visible=!1}function Un(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Tn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const Dn=["AR","3D"];function Nn(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;Un(n,"apiKey"),Tn(n,"apiKey"),Un(o,"sku"),Tn(o,"sku"),Un(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",Dn),null!=a&&Tn(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let In=0,jn=0;function _n(e){var o,i;return n(this,void 0,void 0,(function*(){Nn(e);const{apiKey:r,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);const c=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.")}}))}(r,a);null==P&&(U=C(),P=k(`${A}/shopar-analytics.js`),P.then((()=>{T=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[d,h,p]=N(a,r);d("setup",{hostname:window.location.hostname}),Ne();const g=++jn,w=yield c;d("apiResponse",w);const{category:y,arUrl:b,arKey:E,previewUrl:R,previewEnvUrl:S}=w;On(g);const M=null!=b&&function(e){return null!=e&&m.includes(e)}(y),_=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled),O=M&&function(e){return null!=e&&v.includes(e)}(y),q=_&&O&&!(yield function(){var e;return n(this,void 0,void 0,(function*(){return null==Y&&(Y=k(`${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)}))}());On(g),q&&function(){n(this,void 0,void 0,(function*(){null==Ue&&(Ue=k(`${A}/shopar-qr.js`))}))}();const B=M&&!q;B&&(null==G&&(G=k(`${A}/shopar-deepar.js`)),ee(b),"Glasses"===y&&null==W&&(W=k(`${A}/shopar-true-scale.js`)));const Q=null!=R;var Z;Q&&(null==We&&(We=k(`${A}/shopar-three.js`)),Rn(R),(Z=null!=S?S:`${A}/env/default.hdr`)!==He&&(He=Z,Be=H(Z))),function(e){e.style.position="relative",null==De?e.appendChild(ve):e!==De&&(De.removeChild(ve),e.appendChild(ve)),De=e}(s);const se=null==e.defaultUI||e.defaultUI;if(Ie(se,q,B,Q),Me===me.AR){if(!J)if(te(h),B){d($);const e=yield F;On(g),yield oe(e),On(g)}else ie(),Pe(me.None),se&&(je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0));if(!Ke)if(q){d(x);try{yield Ve(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ze(),Pe(me.None),se&&(je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0))}else if(Me===me.Preview&&!hn)if(Sn(p),Q){d(L),Oe(),je(be,!1);const e=yield Fe;On(g);const n=yield Be;On(g);const t=yield An(e,n);On(g),kn(y),xn(t),je(be,!0),Ge()}else $n(),Pe(me.None),se&&(je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0));const le=()=>n(this,void 0,void 0,(function*(){if(q){if(Me===me.AR)throw new t("AR already launched.");try{d(x);++In;return Me===me.Preview&&Q&&!hn&&$n(),Pe(me.AR),se&&(je(Ce,!1),je(Re,!1),je(Se,!0)),se&&je(Le,!1),void(yield Ve(r,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(!B)throw new t("Model does not have AR enabled.");if(Me===me.AR)throw new t("AR already launched.");try{d($);const e=++In;Me===me.Preview&&Q&&!hn&&$n(),Pe(me.AR),se&&(je(Ce,!1),je(Re,!1),je(Se,!0)),se&&je(Le,!1),ke.classList.add("active"),Ae.style.visibility="visible";const t=yield F;if(In!==e||jn!==g)return;if(yield G,In!==e||jn!==g)return;if(yield ne(ye,E,y),In!==e||jn!==g)return;if(te(h),yield oe(t),In!==e||jn!==g)return;if(yield function(){return n(this,void 0,void 0,(function*(){if(null!=K){if(J=!1,null==V){const e=re(z),n=I(e);V=yield j(n),yield ae(K,V,"user"===e)}K.setPaused(J),X.style.display=""}}))}(),In!==e||jn!==g)return}catch(e){const n=e instanceof Error;throw d("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),se&&je(Le,!0),ie(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{_e()}})),ce=()=>n(this,void 0,void 0,(function*(){if(!Q)throw new t("Model does not have 3D enabled.");if(Me===me.Preview)throw new t("3D already launched.");try{d(L);const e=++In;Me===me.AR&&(B&&!J&&ie(),ze()),Pe(me.Preview),se&&(je(Ce,!1),je(Re,!1),je(Se,!0)),se&&je(Le,!1),Oe();const t=yield Fe;if(In!==e||jn!==g)return;const o=yield Be;if(In!==e||jn!==g)return;if(yield We,In!==e||jn!==g)return;if(yield function(e){return n(this,void 0,void 0,(function*(){if(Xe=e,!pn){Qe=window.ShopAR__THREE,Ze=Qe.THREE,Ye=new Ze.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),Ye.outputEncoding=Ze.sRGBEncoding,Ye.toneMapping=Ze.ACESFilmicToneMapping,Ye.setPixelRatio(window.devicePixelRatio||1),Ye.setClearColor(new Ze.Color(16777215)),ln=new Ze.Scene,Je=new Ze.Group,Je.position.y=-.7,en=new Ze.WebGLRenderTarget(512,512),en.texture.generateMipmaps=!1,nn=new Ze.WebGLRenderTarget(512,512),nn.texture.generateMipmaps=!1;const n=new Ze.PlaneGeometry(fn,mn).rotateX(Math.PI/2),t=new Ze.MeshBasicMaterial({map:en.texture,opacity:bn,transparent:!0,depthWrite:!1});tn=new Ze.Mesh(n,t),tn.renderOrder=1,Je.add(tn),tn.scale.y=-1,on=new Ze.Mesh(n),on.visible=!1,Je.add(on),dn=new Ze.OrthographicCamera(-fn/2,fn/2,mn/2,-mn/2,0,vn),dn.rotation.x=Math.PI/2,Je.add(dn),rn=new Ze.MeshDepthMaterial,rn.userData.darkness={value:yn},rn.onBeforeCompile=function(e){e.uniforms.darkness=rn.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 `},rn.depthTest=!1,rn.depthWrite=!1,an=new Ze.ShaderMaterial(Qe.HorizontalBlurShader),an.depthTest=!1,sn=new Ze.ShaderMaterial(Qe.VerticalBlurShader),sn.depthTest=!1,cn=new Ze.PerspectiveCamera(25,1,.5),un=new Qe.OrbitControls(cn,Ye.domElement),un.target.set(0,.03,0),un.dampingFactor=.3,pn=!0}Mn()}))}(be),In!==e||jn!==g)return;Sn(p);const i=yield An(t,o);if(In!==e||jn!==g)return;kn(y),xn(i),hn=!1,Ln(),null!=Xe&&(Xe.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{Ge()}})),de=()=>n(this,void 0,void 0,(function*(){if(Me===me.None)throw new t("Neither AR or 3D launched.");++In,Me===me.AR?(B&&!J&&ie(),ze()):Me===me.Preview&&Q&&!hn&&$n(),Pe(me.None),_e(),Ge(),se&&(je(Le,!1),je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0))}));return se&&((q||B)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${A}/img/icons/${null!=e&&n[e]||n.Glasses}`;Ce.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(y),Ce.onclick=le),Q&&(Re.onclick=ce),Se.onclick=de),"AR"===l?(yield le(),On(g)):"3D"===l&&(yield ce(),On(g)),{launchAR:le,launch3D:ce,closeAR:()=>n(this,void 0,void 0,(function*(){if(Me!==me.AR)throw new t("AR not launched.");++In,B&&!J&&ie(),ze(),Pe(me.None),_e(),se&&(je(Le,!1),je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0))})),close3D:()=>n(this,void 0,void 0,(function*(){if(Me!==me.Preview)throw new t("3D not launched.");++In,Q&&!hn&&$n(),Pe(me.None),Ge(),se&&(je(Le,!1),je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0))})),close:de}}))}function On(e){if(jn!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Gn={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",(()=>_n(e)))}))},version:R};e.plugin=Gn}));
|
|
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 C={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function E(e,n,t){if(C.randomUUID&&!n&&!e)return C.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 R="0.0.6-alpha.7";let S=`https://cdn.jsdelivr.net/npm/shopar-plugin@${R}/dist`;const A={update:e=>{null!=e&&(S=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>S};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",L="arLaunch",$="previewLaunch",M="heartbeat";let P,U,T=!1;const D=[];function I(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:R,sessionId:U,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},T?a():D.push(a)};return window.setInterval((()=>{c&&(i=r+a,c=!1,d(M,{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,W,F,q,B=!1;function H(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 K,V,z,X,Q,Z,Y,J=!0;function ee(e){e!==q&&(q=e,F=H(e),Z=null,null==K||K.clearEffect(),B=!0)}function ne(e,o,i){return n(this,void 0,void 0,(function*(){return z=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);K=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),V=yield N(s),yield ae(K,V,"user"===a),"Glasses"===i&&(yield W,function(e,t){n(this,void 0,void 0,(function*(){B=!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(B)return void clearInterval(r);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(B)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)}))),_)}))}(V,K))})))()),Q}))}function te(e){K.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},K.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},K.callbacks.onWristTracked=n=>{n.detected&&e()}}function oe(e){return n(this,void 0,void 0,(function*(){return null==Z&&(Z=K.switchEffect(e)),Z}))}function ie(){null!=K&&(J=!0,K.setPaused(J),null!=V&&null!=V.srcObject&&V.srcObject instanceof MediaStream&&(V.srcObject.getTracks().forEach((e=>e.stop())),V=null),K.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,Ce,Ee,Re,Se,Ae,xe,ke,Le,$e,Me,Pe,Ue,Te,De=ye.None;function Ie(e){De=e}let je,Ne=!1,_e=null;function Oe(){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}(),Ee=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),Ce=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}(Ee),be.appendChild(Ce),Re=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(Re),Se=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(Se),$e=he("shopar-ar-loading-container");const e=pe("shopar-ar-loading-text","Loading Try On...");$e.appendChild(e);const n=fe("shopar-ar-loading-bar-bg");Me=me("shopar-ar-loading-bar-fg"),n.appendChild(Me),$e.appendChild(n),be.appendChild($e),Pe=he("shopar-3d-loading-container");const t=pe("shopar-3d-loading-text","Loading 3D...");Pe.appendChild(t);const o=fe("shopar-3d-loading-bar-bg");Ue=me("shopar-3d-loading-bar-fg"),o.appendChild(Ue),Pe.appendChild(o),be.appendChild(Pe),Te=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(Te),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),Le=ce("shopar-btn-close","Close","Close ShopAR view",`${A}/img/icons/close.svg`),Ae.append(Le),Ne=!0}function Ge(e,n,t,o){var i;We(Ae,e),We(xe,e&&(t||n)&&De===ye.None),We(ke,e&&o&&De===ye.None),We(Le,e&&De!==ye.None),Fe(),Be(),e||""===(i=Te).style.display&&We(i,!1)}function We(e,n){e.style.display=n?"":"none"}function Fe(){Me.classList.remove("active"),$e.style.visibility="hidden"}function qe(){Ue.classList.add("active"),Pe.style.visibility="visible"}function Be(){Ue.classList.remove("active"),Pe.style.visibility="hidden"}let He,Ke,Ve,ze,Xe,Qe=!0;function Ze(e,t){return n(this,void 0,void 0,(function*(){yield je;const n=`https://apps.deepar.ai/${R.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(n),i=Ee,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Qe=!1,Ce.style.display=""}))}function Ye(){Qe=!0,Ce.style.display="none"}let Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn,vn=!1,gn=!1;const wn=45,yn=45,bn=3,Cn=.1,En=3.5,Rn=2,Sn=1;let An,xn;function kn(e){if(e!==Ve){const i=255;Ve=e,Ke=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),An=null,null==hn||hn.clear()}}function Ln(e){mn.removeEventListener("change",xn),xn=e,mn.addEventListener("change",e)}function $n(e,t){return n(this,void 0,void 0,(function*(){return null==An&&(An=(()=>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,"")})))()),An}))}function Mn(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);pn.position.set(n[0],n[1],n[2])}function Pn(e){hn.add(e.scene);const n=(new nn.Box3).setFromObject(e.scene);on.position.y=n.min.y-Cn,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)}}))}function Un(){vn=!0,null!=Je&&(Je.style.display="none")}function Tn(){if(vn)return;requestAnimationFrame(Tn),Dn(),mn.update();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,In(En),In(.4*En),tn.setRenderTarget(null),tn.setClearAlpha(n),hn.background=e,tn.render(hn,pn)}function Dn(){const e=Je.clientWidth,n=Je.clientHeight;Je.width===e&&Je.height===n||(tn.setSize(e,n,!1),pn.aspect=e/n,pn.updateProjectionMatrix())}function In(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 jn(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Nn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const _n=["AR","3D"];function On(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;jn(n,"apiKey"),Nn(n,"apiKey"),jn(o,"sku"),Nn(o,"sku"),jn(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",_n),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let Gn=0,Wn=0;function Fn(e){var o,i;return n(this,void 0,void 0,(function*(){On(e);const{apiKey:r,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);const c=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.")}}))}(r,a);null==P&&(U=E(),P=x(`${A}/shopar-analytics.js`),P.then((()=>{T=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[d,h,p]=I(a,r);d("setup",{hostname:window.location.hostname}),Oe();const g=++Wn,w=yield c;d("apiResponse",w);const{category:y,arUrl:b,arKey:C,previewUrl:R,previewEnvUrl:S}=w;qn(g);const M=null!=b&&function(e){return null!=e&&m.includes(e)}(y),_=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled),O=M&&function(e){return null!=e&&v.includes(e)}(y),q=_&&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)}))}());qn(g),q&&function(){n(this,void 0,void 0,(function*(){null==je&&(je=x(`${A}/shopar-qr.js`))}))}();const B=M&&!q;B&&(null==G&&(G=x(`${A}/shopar-deepar.js`)),ee(b),"Glasses"===y&&null==W&&(W=x(`${A}/shopar-true-scale.js`)));const Q=null!=R;var Z;Q&&(null==He&&(He=x(`${A}/shopar-three.js`)),kn(R),(Z=null!=S?S:`${A}/env/default.hdr`)!==Xe&&(Xe=Z,ze=H(Z))),function(e){e.style.position="relative",null==_e?e.appendChild(be):e!==_e&&(_e.removeChild(be),e.appendChild(be)),_e=e}(s);const se=null==e.defaultUI||e.defaultUI;if(Ge(se,q,B,Q),De===ye.AR){if(!J)if(te(h),B){d(L);const e=yield F;qn(g),yield oe(e),qn(g)}else ie(),Ie(ye.None),se&&(We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0));if(!Qe)if(q){d(k);try{yield Ze(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ye(),Ie(ye.None),se&&(We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0))}else if(De===ye.Preview&&!vn)if(Ln(p),Q){d($),qe(),We(Se,!1);const e=yield Ke;qn(g);const n=yield ze;qn(g);const t=yield $n(e,n);qn(g),Mn(y),Pn(t),We(Se,!0),Be()}else Un(),Ie(ye.None),se&&(We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0));const le=()=>n(this,void 0,void 0,(function*(){if(q){if(De===ye.AR)throw new t("AR already launched.");try{d(k);++Gn;return De===ye.Preview&&Q&&!vn&&Un(),Ie(ye.AR),se&&(We(xe,!1),We(ke,!1),We(Le,!0)),se&&We(Te,!1),void(yield Ze(r,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(!B)throw new t("Model does not have AR enabled.");if(De===ye.AR)throw new t("AR already launched.");try{d(L);const e=++Gn;De===ye.Preview&&Q&&!vn&&Un(),Ie(ye.AR),se&&(We(xe,!1),We(ke,!1),We(Le,!0)),se&&We(Te,!1),Me.classList.add("active"),$e.style.visibility="visible";const t=yield F;if(Gn!==e||Wn!==g)return;if(yield G,Gn!==e||Wn!==g)return;if(yield ne(Re,C,y),Gn!==e||Wn!==g)return;if(te(h),yield oe(t),Gn!==e||Wn!==g)return;if(yield function(){return n(this,void 0,void 0,(function*(){if(null!=K){if(J=!1,null==V){const e=re(z),n=j(e);V=yield N(n),yield ae(K,V,"user"===e)}K.setPaused(J),X.style.display=""}}))}(),Gn!==e||Wn!==g)return}catch(e){const n=e instanceof Error;throw d("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),se&&We(Te,!0),ie(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{Fe()}})),ce=()=>n(this,void 0,void 0,(function*(){if(!Q)throw new t("Model does not have 3D enabled.");if(De===ye.Preview)throw new t("3D already launched.");try{d($);const e=++Gn;De===ye.AR&&(B&&!J&&ie(),Ye()),Ie(ye.Preview),se&&(We(xe,!1),We(ke,!1),We(Le,!0)),se&&We(Te,!1),qe();const t=yield Ke;if(Gn!==e||Wn!==g)return;const o=yield ze;if(Gn!==e||Wn!==g)return;if(yield He,Gn!==e||Wn!==g)return;if(yield function(e){return n(this,void 0,void 0,(function*(){if(Je=e,!gn){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(wn,yn).rotateX(Math.PI/2),t=new nn.MeshBasicMaterial({map:rn.texture,opacity:Sn,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(-wn/2,wn/2,yn/2,-yn/2,0,bn),fn.rotation.x=Math.PI/2,on.add(fn),cn=new nn.MeshDepthMaterial,cn.userData.darkness={value:Rn},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.target.set(0,.03,0),mn.dampingFactor=.3,gn=!0}Dn()}))}(Se),Gn!==e||Wn!==g)return;Ln(p);const i=yield $n(t,o);if(Gn!==e||Wn!==g)return;Mn(y),Pn(i),vn=!1,Tn(),null!=Je&&(Je.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{Be()}})),de=()=>n(this,void 0,void 0,(function*(){if(De===ye.None)throw new t("Neither AR or 3D launched.");++Gn,De===ye.AR?(B&&!J&&ie(),Ye()):De===ye.Preview&&Q&&!vn&&Un(),Ie(ye.None),Fe(),Be(),se&&(We(Te,!1),We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0))}));return se&&((q||B)&&(!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)}(y),xe.onclick=le),Q&&(ke.onclick=ce),Le.onclick=de),"AR"===l?(yield le(),qn(g)):"3D"===l&&(yield ce(),qn(g)),{launchAR:le,launch3D:ce,closeAR:()=>n(this,void 0,void 0,(function*(){if(De!==ye.AR)throw new t("AR not launched.");++Gn,B&&!J&&ie(),Ye(),Ie(ye.None),Fe(),se&&(We(Te,!1),We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0))})),close3D:()=>n(this,void 0,void 0,(function*(){if(De!==ye.Preview)throw new t("3D not launched.");++Gn,Q&&!vn&&Un(),Ie(ye.None),Be(),se&&(We(Te,!1),We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0))})),close:de}}))}function qn(e){if(Wn!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Bn={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",(()=>Fn(e)))}))},version:R};e.plugin=Bn}));
|
package/dist/styles/default.css
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
.shopar-btn:hover {
|
|
24
24
|
background-color: #f5f5f5;
|
|
25
25
|
}
|
|
26
|
-
.shopar-
|
|
26
|
+
.shopar-loading-container {
|
|
27
27
|
display: flex;
|
|
28
28
|
flex-direction: column;
|
|
29
29
|
justify-content: center;
|
|
@@ -31,20 +31,23 @@
|
|
|
31
31
|
gap: 1rem;
|
|
32
32
|
background-color: #ffffff;
|
|
33
33
|
}
|
|
34
|
-
.shopar-
|
|
34
|
+
.shopar-loading-text {
|
|
35
|
+
text-align: center;
|
|
36
|
+
}
|
|
37
|
+
.shopar-loading-bar-bg {
|
|
35
38
|
width: 80%;
|
|
36
39
|
height: 0.5rem;
|
|
37
40
|
background-color: #e5e7eb;
|
|
38
41
|
border-radius: 9999px;
|
|
39
42
|
}
|
|
40
|
-
.shopar-
|
|
43
|
+
.shopar-loading-bar-fg {
|
|
41
44
|
background-color: #1434f7;
|
|
42
45
|
border-radius: 9999px;
|
|
43
46
|
transition: none;
|
|
44
47
|
transform: translateX(-100%);
|
|
45
48
|
will-change: transform;
|
|
46
49
|
}
|
|
47
|
-
.shopar-
|
|
50
|
+
.shopar-loading-bar-fg.active {
|
|
48
51
|
transition: transform 5000ms cubic-bezier(0,0,.2,1);
|
|
49
52
|
transform: none;
|
|
50
53
|
}
|
|
@@ -54,25 +57,4 @@
|
|
|
54
57
|
justify-content: center;
|
|
55
58
|
align-items: center;
|
|
56
59
|
background-color: #ffffff;
|
|
57
|
-
}
|
|
58
|
-
.shopar-3d-loading-container {
|
|
59
|
-
display: flex;
|
|
60
|
-
align-items: end;
|
|
61
|
-
}
|
|
62
|
-
.shopar-3d-loading-bg {
|
|
63
|
-
width: 100%;
|
|
64
|
-
height: 0.5rem;
|
|
65
|
-
background-color: #e5e7eb;
|
|
66
|
-
border-radius: 9999px;
|
|
67
|
-
}
|
|
68
|
-
.shopar-3d-loading-bar {
|
|
69
|
-
background-color: #1434f7;
|
|
70
|
-
border-radius: 9999px;
|
|
71
|
-
transition: none;
|
|
72
|
-
transform: translateX(-100%);
|
|
73
|
-
will-change: transform;
|
|
74
|
-
}
|
|
75
|
-
.shopar-3d-loading-bar.active {
|
|
76
|
-
transition: transform 5000ms cubic-bezier(0,0,.2,1);
|
|
77
|
-
transform: none;
|
|
78
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shopar-plugin",
|
|
3
|
-
"version": "0.0.6-alpha.
|
|
3
|
+
"version": "0.0.6-alpha.7",
|
|
4
4
|
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rm -rf dist",
|