shopar-plugin
Advanced tools
Comparing version 0.0.6-alpha.3 to 0.0.6-alpha.4
@@ -1,1 +0,1 @@ | ||
function e(e,t,n,o){return new(n||(n=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 t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const n=[Uint8Array,Uint32Array],o=n.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],r=[2,12,7,1],a=window[i[r[r[o]]]][i[r[r[r.length-1]]]],s=a.charCodeAt(o),l=s^s,c=new n[1]([l]);function d(){const e=(new TextEncoder).encode(a),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,u[n]))),p(t,n+1)}}))}const f=["Glasses","Shoes","Watches"],v=["Shoes"];const w="0.0.6-alpha.3";let m=`https://cdn.jsdelivr.net/npm/shopar-plugin@${w}/dist`;const y={update:e=>{null!=e&&(m=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>m};function g(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let b,C,E=!1;const R=[],A={organizationId:"Unknown",sku:"Unknown"};let S;function k(){P("vto_launched")}function P(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),A),{vtoTime:(performance.now()-S)/1e3,vtoSessionId:C}),$((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function $(e){E?e():R.push(e)}function x(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function M(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const _=200,I=10;let T,D,L,U,N=!1;function j(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let O,G,W,z,F,q,B,H=!0;function K(e){e!==U&&(U=e,L=j(e),q=null,null==O||O.clearEffect(),N=!0)}function V(n,o,i){return e(this,void 0,void 0,(function*(){return W=i,z=n,null==F&&(F=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new t("No camera available!");var r;const a=Z(i),s=x(a);P("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);O=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:n,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),G=yield M(s),P("vto_camera_granted"),yield Y(O,G,"user"===a),"Glasses"===i&&(yield D,function(t,n){e(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,t);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<I)return void i.push(t);clearInterval(r);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),_)}))}(G,O)),P("vto_init_success")})))()),F}))}function Q(t){return e(this,void 0,void 0,(function*(){return null==q&&(q=O.switchEffect(t)),q}))}function X(){null!=O&&(H=!0,O.setPaused(H),null!=G&&null!=G.srcObject&&G.srcObject instanceof MediaStream&&(G.srcObject.getTracks().forEach((e=>e.stop())),G=null),O.stopCamera(),z.style.display="none")}function Z(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Y(t,n,o){return e(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,o),i()}))))}}))}))}function J(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const ee="shopar-error";function te(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=J("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const ne="shopar-control";const oe="shopar-deepar-output";const ie="shopar-loading";const re="shopar-main";const ae="shopar-qr-output";const se="shopar-three-output";var le;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(le||(le={}));let ce,de,ue,he,pe,fe,ve,we,me,ye,ge=le.None;function be(e){ge=e}let Ce,Ee=!1,Re=null;function Ae(){Ee||(ce=function(){const e=document.createElement("div");e.id=re;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),de=function(){const e=document.createElement("div");e.id=ae;const t=e.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="relative",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="flex",o.alignItems="center",o.justifyContent="center",o.backgroundColor="white",e.appendChild(n);const i=new Image,r=i.style;return r.maxWidth="100%",r.maxHeight="100%",n.appendChild(i),e}(),ce.appendChild(de),ue=function(){const e=document.createElement("div");e.id=oe;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(ue),he=function(){const e=document.createElement("canvas");e.id=se;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(he),pe=function(){const e=document.createElement("div");return e.id=ne,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ce.appendChild(pe),fe=te("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),pe.appendChild(fe),ve=te("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`),pe.appendChild(ve),we=te("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`),pe.append(we),me=function(){const e=document.createElement("div");e.id=ie;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),ce.appendChild(me),ye=function(){const e=document.createElement("div");e.id=ee;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.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(n);const i=J("4rem",`${y}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.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.",n.appendChild(a),e}(),ce.appendChild(ye),Ee=!0)}function Se(e,t){e.style.display=t?"":"none"}function ke(e){""===e.style.display&&Se(e,!1)}let Pe,$e,xe,Me,_e,Ie=!0;function Te(t,n){return e(this,void 0,void 0,(function*(){yield Ce;const e=`https://apps.deepar.ai/${w.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:t,s:n,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),i=de.firstChild.firstChild,r=new Promise(((e,t)=>{i.onload=e,i.onerror=t}));i.src=o,yield r,Ie=!1,de.style.display=""}))}function De(){Ie=!0,de.style.display="none"}let Le,Ue,Ne,je,Oe,Ge,We,ze,Fe,qe,Be,He,Ke,Ve,Qe,Xe,Ze=!1,Ye=!1;const Je=45,et=45,tt=3,nt=.1,ot=3.5,it=2,rt=1;let at;function st(o){if(o!==xe){const i=255;xe=o,$e=function(o,i,r){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const d=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),v=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],w=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield v(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),m=new n[0](yield(yield w.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));r+=s;const y=m.byteLength;if(c[l]=Math.min(76,i)*((a>>5)-1),152===c[l]&&(c[l]=y),r==l)return m;r=l,r^=l;for(let e=0,t=m.length;e<t;e++)c[l]^=c[r]<<13,c[l]^=c[r]>>17,c[l]^=c[r]<<5,m[e]=m[e]^c[l];return r^=c[0],r^=c[1],r^=c[2],m}))}(o,(new Date).getTime()+i,Math.random()*i),at=null,null==Ke||Ke.clear()}}function lt(t,n){return e(this,void 0,void 0,(function*(){if(Le=t,!Ye){Ue=window.ShopAR__THREE,Ne=Ue.THREE,je=new Ne.WebGLRenderer({powerPreference:"high-performance",canvas:t,antialias:!0,alpha:!0}),je.outputEncoding=Ne.sRGBEncoding,je.toneMapping=Ne.ACESFilmicToneMapping,je.setPixelRatio(window.devicePixelRatio||1),je.setClearColor(new Ne.Color(16777215)),Ke=new Ne.Scene,Oe=new Ne.Group,Oe.position.y=-.7,Ge=new Ne.WebGLRenderTarget(512,512),Ge.texture.generateMipmaps=!1,We=new Ne.WebGLRenderTarget(512,512),We.texture.generateMipmaps=!1;const e=new Ne.PlaneGeometry(Je,et).rotateX(Math.PI/2),o=new Ne.MeshBasicMaterial({map:Ge.texture,opacity:rt,transparent:!0,depthWrite:!1});ze=new Ne.Mesh(e,o),ze.renderOrder=1,Oe.add(ze),ze.scale.y=-1,Fe=new Ne.Mesh(e),Fe.visible=!1,Oe.add(Fe),Qe=new Ne.OrthographicCamera(-Je/2,Je/2,et/2,-et/2,0,tt),Qe.rotation.x=Math.PI/2,Oe.add(Qe),qe=new Ne.MeshDepthMaterial,qe.userData.darkness={value:it},qe.onBeforeCompile=function(e){e.uniforms.darkness=qe.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 `},qe.depthTest=!1,qe.depthWrite=!1,Be=new Ne.ShaderMaterial(Ue.HorizontalBlurShader),Be.depthTest=!1,He=new Ne.ShaderMaterial(Ue.VerticalBlurShader),He.depthTest=!1,Ve=new Ne.PerspectiveCamera(25,1,.5);const i=function(e){var t;const n={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?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);Ve.position.set(i[0],i[1],i[2]),Xe=new Ue.OrbitControls(Ve,je.domElement),Xe.target.set(0,.03,0),Xe.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{P("preview_interacted")}),200);Xe.addEventListener("end",e)}Ye=!0}pt()}))}function ct(t,n){return e(this,void 0,void 0,(function*(){return null==at&&(at=(()=>e(this,void 0,void 0,(function*(){const e=new Ue.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(Ue,e.parse(n));o.mapping=Ne.EquirectangularReflectionMapping,o.encoding=Ne.LinearEncoding,Ke.environment=o;const i=(new Ue.GLTFLoader).setDRACOLoader((new Ue.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Ue.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(je)).setMeshoptDecoder("function"==typeof Ue.MeshoptDecoder?Ue.MeshoptDecoder():Ue.MeshoptDecoder);return yield i.parseAsync(t.buffer,"")})))()),at}))}function dt(t){return e(this,void 0,void 0,(function*(){Ke.add(t.scene);const e=(new Ne.Box3).setFromObject(t.scene);Oe.position.y=e.min.y-nt,Ke.add(Oe),Ke.traverse((e=>{if(e instanceof Ne.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ne.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ut(){Ze=!0,Le.style.display="none"}function ht(){if(Ze)return;requestAnimationFrame(ht),pt(),Xe.update();const e=Ke.background;Ke.background=null,Ke.overrideMaterial=qe;const t=je.getClearAlpha();je.setClearAlpha(0),je.setRenderTarget(Ge),je.render(Ke,Qe),Ke.overrideMaterial=null,ft(ot),ft(.4*ot),je.setRenderTarget(null),je.setClearAlpha(t),Ke.background=e,je.render(Ke,Ve)}function pt(){const e=Le.clientWidth,t=Le.clientHeight;Le.width===e&&Le.height===t||(je.setSize(e,t,!1),Ve.aspect=e/t,Ve.updateProjectionMatrix())}function ft(e){Fe.visible=!0,Be.uniforms.tDiffuse.value=Ge.texture,Be.uniforms.h.value=1*e/256,Fe.material=Be,je.setRenderTarget(We),je.render(Fe,Qe),He.uniforms.tDiffuse.value=We.texture,He.uniforms.v.value=1*e/256,Fe.material=He,je.setRenderTarget(Ge),je.render(Fe,Qe),Fe.visible=!1}function vt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function wt(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const mt=["AR","3D"];function yt(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;vt(n,"apiKey"),wt(n,"apiKey"),vt(o,"sku"),wt(o,"sku"),vt(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",mt),null!=a&&wt(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let gt=0,bt=0;function Ct(n){var o,i;return e(this,void 0,void 0,(function*(){yt(n);const{apiKey:r,sku:a,targetElement:s,initialState:l}=n;!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),y.update(n.baseUrl);const c=function(n,o){return e(this,void 0,void 0,(function*(){const i=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:n,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(r,a);null==b&&(b=g(`${y}/shopar-analytics.js`),b.then((()=>{E=!0,C=window.ShopAR__analytics.uuidv4(),R.forEach((e=>e()))}))),function(e,t){A.organizationId=e,A.sku=t,S=performance.now(),$((()=>{window.ShopAR__analytics.initializeImpl()}))}(r,a),Ae();const u=++bt,{category:h,arUrl:w,arKey:m,previewUrl:_,previewEnvUrl:I}=yield c;Et(u),P("initialized");const U=null!=w&&function(e){return null!=e&&f.includes(e)}(h),N=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=n._internalOptions)||void 0===i?void 0:i.qrEnabled),F=U&&function(e){return null!=e&&v.includes(e)}(h),q=N&&F&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==B&&(B=g(`${y}/shopar-platform.js`)),yield B,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}());Et(u),q&&function(){e(this,void 0,void 0,(function*(){null==Ce&&(Ce=g(`${y}/shopar-qr.js`))}))}();const J=U&&!q;J&&(null==T&&(T=g(`${y}/shopar-deepar.js`)),K(w),"Glasses"===h&&null==D&&(D=g(`${y}/shopar-true-scale.js`)));const ee=null!=_;var te;ee&&(null==Pe&&(Pe=g(`${y}/shopar-three.js`)),st(_),(te=null!=I?I:`${y}/env/default.hdr`)!==_e&&(_e=te,Me=j(te))),function(e){e.style.position="relative",null==Re?e.appendChild(ce):e!==Re&&(Re.removeChild(ce),e.appendChild(ce)),Re=e}(s);const ne=null==n.defaultUI||n.defaultUI;if(function(e,t,n,o){Se(pe,e),Se(fe,e&&(n||t)&&ge===le.None),Se(ve,e&&o&&ge===le.None),Se(we,e&&ge!==le.None),e||ke(me),e||ke(ye)}(ne,q,J,ee),ge===le.AR){if(!H)if(J){const e=yield L;Et(u),yield Q(e),Et(u)}else X(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0));if(!Ie)if(q)try{yield Te(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}else De(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))}else if(ge===le.Preview&&!Ze)if(ee){const e=yield $e;Et(u);const t=yield Me;Et(u);const n=yield ct(e,t);Et(u),dt(n)}else ut(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0));const oe=()=>e(this,void 0,void 0,(function*(){if(q){if(ge===le.AR)throw new t("AR already launched.");const e=++gt;ge===le.Preview&&ee&&!Ze&&ut(),be(le.AR),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),k(),ne&&(Se(ye,!1),Se(me,!0));try{yield Te(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}if(gt!==e||bt!==u)return;return void(ne&&Se(me,!1))}if(!J)throw new t("Model does not have AR enabled.");if(ge===le.AR)throw new t("AR already launched.");const n=++gt;ge===le.Preview&&ee&&!Ze&&ut(),be(le.AR),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),k(),ne&&(Se(ye,!1),Se(me,!0));const o=yield L;if(gt===n&&bt===u&&(yield T,gt===n&&bt===u)){try{yield V(ue,m,h)}catch(e){throw function(e){P("vto_camera_denied",{error:e})}(e),ne&&(Se(me,!1),Se(ye,!0)),e}gt===n&&bt===u&&(yield Q(o),gt===n&&bt===u&&(yield function(){return e(this,void 0,void 0,(function*(){if(null!=O){if(H=!1,null==G){const e=Z(W),t=x(e);G=yield M(t),yield Y(O,G,"user"===e)}O.setPaused(H),z.style.display=""}}))}(),gt===n&&bt===u&&ne&&Se(me,!1)))}})),ie=()=>e(this,void 0,void 0,(function*(){if(!ee)throw new t("Model does not have 3D enabled.");if(ge===le.Preview)throw new t("3D already launched.");const e=++gt;ge===le.AR&&(J&&!H&&X(),De()),be(le.Preview),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),P("preview_launched"),ne&&(Se(ye,!1),Se(me,!0));const n=yield $e;if(gt!==e||bt!==u)return;const o=yield Me;if(gt!==e||bt!==u)return;if(yield Pe,gt!==e||bt!==u)return;if(yield lt(he,h),gt!==e||bt!==u)return;const i=yield ct(n,o);gt===e&&bt===u&&(dt(i),Ze=!1,ht(),Le.style.display="",ne&&Se(me,!1))})),re=()=>e(this,void 0,void 0,(function*(){if(ge===le.None)throw new t("Neither AR or 3D launched.");++gt,ge===le.AR?(J&&!H&&X(),De()):ge===le.Preview&&ee&&!Ze&&ut(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))}));return ne&&((q||J)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${y}/img/icons/${null!=e&&t[e]||t.Glasses}`;fe.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(h),fe.onclick=oe),ee&&(ve.onclick=ie),we.onclick=re),"AR"===l?(yield oe(),Et(u)):"3D"===l&&(yield ie(),Et(u)),{launchAR:oe,launch3D:ie,closeAR:()=>e(this,void 0,void 0,(function*(){if(ge!==le.AR)throw new t("AR not launched.");++gt,J&&!H&&X(),De(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(ge!==le.Preview)throw new t("3D not launched.");++gt,ee&&!Ze&&ut(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))})),close:re}}))}function Et(e){if(bt!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Rt={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>Ct(n)))}))},version:w};export{Rt as plugin}; | ||
function e(e,t,n,o){return new(n||(n=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 t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const n=[Uint8Array,Uint32Array],o=n.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],r=[2,12,7,1],a=window[i[r[r[o]]]][i[r[r[r.length-1]]]],s=a.charCodeAt(o),l=s^s,c=new n[1]([l]);function d(){const e=(new TextEncoder).encode(a),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,u[n]))),p(t,n+1)}}))}const f=["Glasses","Shoes","Watches"],v=["Shoes"];const w="0.0.6-alpha.4";let m=`https://cdn.jsdelivr.net/npm/shopar-plugin@${w}/dist`;const y={update:e=>{null!=e&&(m=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>m};function g(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let b,C,E=!1;const R=[],A={organizationId:"Unknown",sku:"Unknown"};let S;function k(){P("vto_launched")}function P(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),A),{vtoTime:(performance.now()-S)/1e3,vtoSessionId:C}),$((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function $(e){E?e():R.push(e)}function x(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function M(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const _=200,I=10;let T,D,L,U,N=!1;function j(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let O,G,W,z,F,q,B,H=!0;function K(e){e!==U&&(U=e,L=j(e),q=null,null==O||O.clearEffect(),N=!0)}function V(n,o,i){return e(this,void 0,void 0,(function*(){return W=i,z=n,null==F&&(F=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new t("No camera available!");var r;const a=Z(i),s=x(a);P("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);O=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:n,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),G=yield M(s),P("vto_camera_granted"),yield Y(O,G,"user"===a),"Glasses"===i&&(yield D,function(t,n){e(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,t);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<I)return void i.push(t);clearInterval(r);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),_)}))}(G,O)),P("vto_init_success")})))()),F}))}function Q(t){return e(this,void 0,void 0,(function*(){return null==q&&(q=O.switchEffect(t)),q}))}function X(){null!=O&&(H=!0,O.setPaused(H),null!=G&&null!=G.srcObject&&G.srcObject instanceof MediaStream&&(G.srcObject.getTracks().forEach((e=>e.stop())),G=null),O.stopCamera(),z.style.display="none")}function Z(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Y(t,n,o){return e(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,o),i()}))))}}))}))}function J(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const ee="shopar-error";function te(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=J("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const ne="shopar-control";const oe="shopar-deepar-output";const ie="shopar-loading";const re="shopar-main";const ae="shopar-qr-output";const se="shopar-three-output";var le;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(le||(le={}));let ce,de,ue,he,pe,fe,ve,we,me,ye,ge=le.None;function be(e){ge=e}let Ce,Ee=!1,Re=null;function Ae(){Ee||(ce=function(){const e=document.createElement("div");e.id=re;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),de=function(){const e=document.createElement("div");e.id=ae;const t=e.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="relative",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="flex",o.alignItems="center",o.justifyContent="center",o.backgroundColor="white",e.appendChild(n);const i=new Image,r=i.style;return r.maxWidth="100%",r.maxHeight="100%",n.appendChild(i),e}(),ce.appendChild(de),ue=function(){const e=document.createElement("div");e.id=oe;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(ue),he=function(){const e=document.createElement("canvas");e.id=se;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(he),pe=function(){const e=document.createElement("div");return e.id=ne,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ce.appendChild(pe),fe=te("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),pe.appendChild(fe),ve=te("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`),pe.appendChild(ve),we=te("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`),pe.append(we),me=function(){const e=document.createElement("div");e.id=ie;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),ce.appendChild(me),ye=function(){const e=document.createElement("div");e.id=ee;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.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(n);const i=J("4rem",`${y}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.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.",n.appendChild(a),e}(),ce.appendChild(ye),Ee=!0)}function Se(e,t){e.style.display=t?"":"none"}function ke(e){""===e.style.display&&Se(e,!1)}let Pe,$e,xe,Me,_e,Ie=!0;function Te(t,n){return e(this,void 0,void 0,(function*(){yield Ce;const e=`https://apps.deepar.ai/${w.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:t,s:n,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),i=de.firstChild.firstChild,r=new Promise(((e,t)=>{i.onload=e,i.onerror=t}));i.src=o,yield r,Ie=!1,de.style.display=""}))}function De(){Ie=!0,de.style.display="none"}let Le,Ue,Ne,je,Oe,Ge,We,ze,Fe,qe,Be,He,Ke,Ve,Qe,Xe,Ze=!1,Ye=!1;const Je=45,et=45,tt=3,nt=.1,ot=3.5,it=2,rt=1;let at;function st(o){if(o!==xe){const i=255;xe=o,$e=function(o,i,r){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const d=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),v=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],w=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield v(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),m=new n[0](yield(yield w.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));r+=s;const y=m.byteLength;if(c[l]=Math.min(76,i)*((a>>5)-1),152===c[l]&&(c[l]=y),r==l)return m;r=l,r^=l;for(let e=0,t=m.length;e<t;e++)c[l]^=c[r]<<13,c[l]^=c[r]>>17,c[l]^=c[r]<<5,m[e]=m[e]^c[l];return r^=c[0],r^=c[1],r^=c[2],m}))}(o,(new Date).getTime()+i,Math.random()*i),at=null,null==Ke||Ke.clear()}}function lt(t,n){return e(this,void 0,void 0,(function*(){if(Le=t,!Ye){Ue=window.ShopAR__THREE,Ne=Ue.THREE,je=new Ne.WebGLRenderer({powerPreference:"high-performance",canvas:t,antialias:!0,alpha:!0}),je.outputEncoding=Ne.sRGBEncoding,je.toneMapping=Ne.ACESFilmicToneMapping,je.setPixelRatio(window.devicePixelRatio||1),je.setClearColor(new Ne.Color(16777215)),Ke=new Ne.Scene,Oe=new Ne.Group,Oe.position.y=-.7,Ge=new Ne.WebGLRenderTarget(512,512),Ge.texture.generateMipmaps=!1,We=new Ne.WebGLRenderTarget(512,512),We.texture.generateMipmaps=!1;const e=new Ne.PlaneGeometry(Je,et).rotateX(Math.PI/2),o=new Ne.MeshBasicMaterial({map:Ge.texture,opacity:rt,transparent:!0,depthWrite:!1});ze=new Ne.Mesh(e,o),ze.renderOrder=1,Oe.add(ze),ze.scale.y=-1,Fe=new Ne.Mesh(e),Fe.visible=!1,Oe.add(Fe),Qe=new Ne.OrthographicCamera(-Je/2,Je/2,et/2,-et/2,0,tt),Qe.rotation.x=Math.PI/2,Oe.add(Qe),qe=new Ne.MeshDepthMaterial,qe.userData.darkness={value:it},qe.onBeforeCompile=function(e){e.uniforms.darkness=qe.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 `},qe.depthTest=!1,qe.depthWrite=!1,Be=new Ne.ShaderMaterial(Ue.HorizontalBlurShader),Be.depthTest=!1,He=new Ne.ShaderMaterial(Ue.VerticalBlurShader),He.depthTest=!1,Ve=new Ne.PerspectiveCamera(25,1,.5);const i=function(e){var t;const n={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?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);Ve.position.set(i[0],i[1],i[2]),Xe=new Ue.OrbitControls(Ve,je.domElement),Xe.target.set(0,.03,0),Xe.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{P("preview_interacted")}),200);Xe.addEventListener("end",e)}Ye=!0}pt()}))}function ct(t,n){return e(this,void 0,void 0,(function*(){return null==at&&(at=(()=>e(this,void 0,void 0,(function*(){const e=new Ue.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(Ue,e.parse(n));o.mapping=Ne.EquirectangularReflectionMapping,o.encoding=Ne.LinearEncoding,Ke.environment=o;const i=(new Ue.GLTFLoader).setDRACOLoader((new Ue.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Ue.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(je)).setMeshoptDecoder("function"==typeof Ue.MeshoptDecoder?Ue.MeshoptDecoder():Ue.MeshoptDecoder);return yield i.parseAsync(t.buffer,"")})))()),at}))}function dt(t){return e(this,void 0,void 0,(function*(){Ke.add(t.scene);const e=(new Ne.Box3).setFromObject(t.scene);Oe.position.y=e.min.y-nt,Ke.add(Oe),Ke.traverse((e=>{if(e instanceof Ne.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ne.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ut(){Ze=!0,Le.style.display="none"}function ht(){if(Ze)return;requestAnimationFrame(ht),pt(),Xe.update();const e=Ke.background;Ke.background=null,Ke.overrideMaterial=qe;const t=je.getClearAlpha();je.setClearAlpha(0),je.setRenderTarget(Ge),je.render(Ke,Qe),Ke.overrideMaterial=null,ft(ot),ft(.4*ot),je.setRenderTarget(null),je.setClearAlpha(t),Ke.background=e,je.render(Ke,Ve)}function pt(){const e=Le.clientWidth,t=Le.clientHeight;Le.width===e&&Le.height===t||(je.setSize(e,t,!1),Ve.aspect=e/t,Ve.updateProjectionMatrix())}function ft(e){Fe.visible=!0,Be.uniforms.tDiffuse.value=Ge.texture,Be.uniforms.h.value=1*e/256,Fe.material=Be,je.setRenderTarget(We),je.render(Fe,Qe),He.uniforms.tDiffuse.value=We.texture,He.uniforms.v.value=1*e/256,Fe.material=He,je.setRenderTarget(Ge),je.render(Fe,Qe),Fe.visible=!1}function vt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function wt(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const mt=["AR","3D"];function yt(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;vt(n,"apiKey"),wt(n,"apiKey"),vt(o,"sku"),wt(o,"sku"),vt(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",mt),null!=a&&wt(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let gt=0,bt=0;function Ct(n){var o,i;return e(this,void 0,void 0,(function*(){yt(n);const{apiKey:r,sku:a,targetElement:s,initialState:l}=n;!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),y.update(n.baseUrl);const c=function(n,o){return e(this,void 0,void 0,(function*(){const i=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:n,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(r,a);null==b&&(b=g(`${y}/shopar-analytics.js`),b.then((()=>{E=!0,C=window.ShopAR__analytics.uuidv4(),R.forEach((e=>e()))}))),function(e,t){A.organizationId=e,A.sku=t,S=performance.now(),$((()=>{window.ShopAR__analytics.initializeImpl()}))}(r,a),Ae();const u=++bt,{category:h,arUrl:w,arKey:m,previewUrl:_,previewEnvUrl:I}=yield c;Et(u),P("initialized");const U=null!=w&&function(e){return null!=e&&f.includes(e)}(h),N=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=n._internalOptions)||void 0===i?void 0:i.qrEnabled),F=U&&function(e){return null!=e&&v.includes(e)}(h),q=N&&F&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==B&&(B=g(`${y}/shopar-platform.js`)),yield B,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}());Et(u),q&&function(){e(this,void 0,void 0,(function*(){null==Ce&&(Ce=g(`${y}/shopar-qr.js`))}))}();const J=U&&!q;J&&(null==T&&(T=g(`${y}/shopar-deepar.js`)),K(w),"Glasses"===h&&null==D&&(D=g(`${y}/shopar-true-scale.js`)));const ee=null!=_;var te;ee&&(null==Pe&&(Pe=g(`${y}/shopar-three.js`)),st(_),(te=null!=I?I:`${y}/env/default.hdr`)!==_e&&(_e=te,Me=j(te))),function(e){e.style.position="relative",null==Re?e.appendChild(ce):e!==Re&&(Re.removeChild(ce),e.appendChild(ce)),Re=e}(s);const ne=null==n.defaultUI||n.defaultUI;if(function(e,t,n,o){Se(pe,e),Se(fe,e&&(n||t)&&ge===le.None),Se(ve,e&&o&&ge===le.None),Se(we,e&&ge!==le.None),e||ke(me),e||ke(ye)}(ne,q,J,ee),ge===le.AR){if(!H)if(J){const e=yield L;Et(u),yield Q(e),Et(u)}else X(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0));if(!Ie)if(q)try{yield Te(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}else De(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))}else if(ge===le.Preview&&!Ze)if(ee){const e=yield $e;Et(u);const t=yield Me;Et(u);const n=yield ct(e,t);Et(u),dt(n)}else ut(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0));const oe=()=>e(this,void 0,void 0,(function*(){if(q){if(ge===le.AR)throw new t("AR already launched.");const e=++gt;ge===le.Preview&&ee&&!Ze&&ut(),be(le.AR),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),k(),ne&&(Se(ye,!1),Se(me,!0));try{yield Te(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}if(gt!==e||bt!==u)return;return void(ne&&Se(me,!1))}if(!J)throw new t("Model does not have AR enabled.");if(ge===le.AR)throw new t("AR already launched.");const n=++gt;ge===le.Preview&&ee&&!Ze&&ut(),be(le.AR),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),k(),ne&&(Se(ye,!1),Se(me,!0));const o=yield L;if(gt===n&&bt===u&&(yield T,gt===n&&bt===u)){try{yield V(ue,m,h)}catch(e){throw function(e){P("vto_camera_denied",{error:e})}(e),ne&&(Se(me,!1),Se(ye,!0)),e}gt===n&&bt===u&&(yield Q(o),gt===n&&bt===u&&(yield function(){return e(this,void 0,void 0,(function*(){if(null!=O){if(H=!1,null==G){const e=Z(W),t=x(e);G=yield M(t),yield Y(O,G,"user"===e)}O.setPaused(H),z.style.display=""}}))}(),gt===n&&bt===u&&ne&&Se(me,!1)))}})),ie=()=>e(this,void 0,void 0,(function*(){if(!ee)throw new t("Model does not have 3D enabled.");if(ge===le.Preview)throw new t("3D already launched.");const e=++gt;ge===le.AR&&(J&&!H&&X(),De()),be(le.Preview),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),P("preview_launched"),ne&&(Se(ye,!1),Se(me,!0));const n=yield $e;if(gt!==e||bt!==u)return;const o=yield Me;if(gt!==e||bt!==u)return;if(yield Pe,gt!==e||bt!==u)return;if(yield lt(he,h),gt!==e||bt!==u)return;const i=yield ct(n,o);gt===e&&bt===u&&(dt(i),Ze=!1,ht(),Le.style.display="",ne&&Se(me,!1))})),re=()=>e(this,void 0,void 0,(function*(){if(ge===le.None)throw new t("Neither AR or 3D launched.");++gt,ge===le.AR?(J&&!H&&X(),De()):ge===le.Preview&&ee&&!Ze&&ut(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))}));return ne&&((q||J)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${y}/img/icons/${null!=e&&t[e]||t.Glasses}`;fe.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(h),fe.onclick=oe),ee&&(ve.onclick=ie),we.onclick=re),"AR"===l?(yield oe(),Et(u)):"3D"===l&&(yield ie(),Et(u)),{launchAR:oe,launch3D:ie,closeAR:()=>e(this,void 0,void 0,(function*(){if(ge!==le.AR)throw new t("AR not launched.");++gt,J&&!H&&X(),De(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(ge!==le.Preview)throw new t("3D not launched.");++gt,ee&&!Ze&&ut(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))})),close:re}}))}function Et(e){if(bt!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Rt={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>Ct(n)))}))},version:w};export{Rt as plugin}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(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 t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class n 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),d=l^l,c=new o[1]([d]);function u(){const e=(new TextEncoder).encode(s),t=r.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[r[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=p)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),f(e,n+1)}}))}const v=["Glasses","Shoes","Watches"],w=["Shoes"];const m="0.0.6-alpha.3";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${m}/dist`;const g={update:e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>y};function b(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let C,E,R=!1;const A=[],S={organizationId:"Unknown",sku:"Unknown"};let x;function k(){P("vto_launched")}function P(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),S),{vtoTime:(performance.now()-x)/1e3,vtoSessionId:E}),$((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function $(e){R?e():A.push(e)}function M(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function _(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const I=200,T=10;let D,L,U,j,N=!1;function O(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let G,W,z,F,q,B,H,K=!0;function V(e){e!==j&&(j=e,U=O(e),B=null,null==G||G.clearEffect(),N=!0)}function Q(e,o,i){return t(this,void 0,void 0,(function*(){return z=i,F=e,null==q&&(q=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new n("No camera available!");var r;const a=Y(i),s=M(a);P("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);G=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),W=yield _(s),P("vto_camera_granted"),yield J(G,W,"user"===a),"Glasses"===i&&(yield L,function(e,n){t(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${g}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>t(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<T)return void i.push(t);clearInterval(r);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),I)}))}(W,G)),P("vto_init_success")})))()),q}))}function X(e){return t(this,void 0,void 0,(function*(){return null==B&&(B=G.switchEffect(e)),B}))}function Z(){null!=G&&(K=!0,G.setPaused(K),null!=W&&null!=W.srcObject&&W.srcObject instanceof MediaStream&&(W.srcObject.getTracks().forEach((e=>e.stop())),W=null),G.stopCamera(),F.style.display="none")}function Y(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function J(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),i()}))))}}))}))}function ee(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const te="shopar-error";function ne(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ee("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const oe="shopar-control";const ie="shopar-deepar-output";const re="shopar-loading";const ae="shopar-main";const se="shopar-qr-output";const le="shopar-three-output";var de;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(de||(de={}));let ce,ue,he,pe,fe,ve,we,me,ye,ge,be=de.None;function Ce(e){be=e}let Ee,Re=!1,Ae=null;function Se(){Re||(ce=function(){const e=document.createElement("div");e.id=ae;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),ue=function(){const e=document.createElement("div");e.id=se;const t=e.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="relative",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="flex",o.alignItems="center",o.justifyContent="center",o.backgroundColor="white",e.appendChild(n);const i=new Image,r=i.style;return r.maxWidth="100%",r.maxHeight="100%",n.appendChild(i),e}(),ce.appendChild(ue),he=function(){const e=document.createElement("div");e.id=ie;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(he),pe=function(){const e=document.createElement("canvas");e.id=le;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(pe),fe=function(){const e=document.createElement("div");return e.id=oe,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ce.appendChild(fe),ve=ne("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),fe.appendChild(ve),we=ne("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${g}/img/icons/cube.svg`),fe.appendChild(we),me=ne("shopar-btn-close","Close","Close ShopAR view",`${g}/img/icons/close.svg`),fe.append(me),ye=function(){const e=document.createElement("div");e.id=re;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),ce.appendChild(ye),ge=function(){const e=document.createElement("div");e.id=te;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.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(n);const i=ee("4rem",`${g}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.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.",n.appendChild(a),e}(),ce.appendChild(ge),Re=!0)}function xe(e,t){e.style.display=t?"":"none"}function ke(e){""===e.style.display&&xe(e,!1)}let Pe,$e,Me,_e,Ie,Te=!0;function De(e,n){return t(this,void 0,void 0,(function*(){yield Ee;const t=`https://apps.deepar.ai/${m.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:n,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(t),i=ue.firstChild.firstChild,r=new Promise(((e,t)=>{i.onload=e,i.onerror=t}));i.src=o,yield r,Te=!1,ue.style.display=""}))}function Le(){Te=!0,ue.style.display="none"}let Ue,je,Ne,Oe,Ge,We,ze,Fe,qe,Be,He,Ke,Ve,Qe,Xe,Ze,Ye=!1,Je=!1;const et=45,tt=45,nt=3,ot=.1,it=3.5,rt=2,at=1;let st;function lt(e){if(e!==Me){const i=255;Me=e,$e=function(e,i,r){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),v=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],w=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield v(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),m=new o[0](yield(yield w.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));r+=s;const y=m.byteLength;if(c[d]=Math.min(76,i)*((a>>5)-1),152===c[d]&&(c[d]=y),r==d)return m;r=d,r^=d;for(let e=0,t=m.length;e<t;e++)c[d]^=c[r]<<13,c[d]^=c[r]>>17,c[d]^=c[r]<<5,m[e]=m[e]^c[d];return r^=c[0],r^=c[1],r^=c[2],m}))}(e,(new Date).getTime()+i,Math.random()*i),st=null,null==Ve||Ve.clear()}}function dt(e,n){return t(this,void 0,void 0,(function*(){if(Ue=e,!Je){je=window.ShopAR__THREE,Ne=je.THREE,Oe=new Ne.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),Oe.outputEncoding=Ne.sRGBEncoding,Oe.toneMapping=Ne.ACESFilmicToneMapping,Oe.setPixelRatio(window.devicePixelRatio||1),Oe.setClearColor(new Ne.Color(16777215)),Ve=new Ne.Scene,Ge=new Ne.Group,Ge.position.y=-.7,We=new Ne.WebGLRenderTarget(512,512),We.texture.generateMipmaps=!1,ze=new Ne.WebGLRenderTarget(512,512),ze.texture.generateMipmaps=!1;const t=new Ne.PlaneGeometry(et,tt).rotateX(Math.PI/2),o=new Ne.MeshBasicMaterial({map:We.texture,opacity:at,transparent:!0,depthWrite:!1});Fe=new Ne.Mesh(t,o),Fe.renderOrder=1,Ge.add(Fe),Fe.scale.y=-1,qe=new Ne.Mesh(t),qe.visible=!1,Ge.add(qe),Xe=new Ne.OrthographicCamera(-et/2,et/2,tt/2,-tt/2,0,nt),Xe.rotation.x=Math.PI/2,Ge.add(Xe),Be=new Ne.MeshDepthMaterial,Be.userData.darkness={value:rt},Be.onBeforeCompile=function(e){e.uniforms.darkness=Be.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 `},Be.depthTest=!1,Be.depthWrite=!1,He=new Ne.ShaderMaterial(je.HorizontalBlurShader),He.depthTest=!1,Ke=new Ne.ShaderMaterial(je.VerticalBlurShader),Ke.depthTest=!1,Qe=new Ne.PerspectiveCamera(25,1,.5);const i=function(e){var t;const n={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?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);Qe.position.set(i[0],i[1],i[2]),Ze=new je.OrbitControls(Qe,Oe.domElement),Ze.target.set(0,.03,0),Ze.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{P("preview_interacted")}),200);Ze.addEventListener("end",e)}Je=!0}ft()}))}function ct(e,n){return t(this,void 0,void 0,(function*(){return null==st&&(st=(()=>t(this,void 0,void 0,(function*(){const t=new je.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(je,t.parse(n));o.mapping=Ne.EquirectangularReflectionMapping,o.encoding=Ne.LinearEncoding,Ve.environment=o;const i=(new je.GLTFLoader).setDRACOLoader((new je.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new je.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(Oe)).setMeshoptDecoder("function"==typeof je.MeshoptDecoder?je.MeshoptDecoder():je.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),st}))}function ut(e){return t(this,void 0,void 0,(function*(){Ve.add(e.scene);const t=(new Ne.Box3).setFromObject(e.scene);Ge.position.y=t.min.y-ot,Ve.add(Ge),Ve.traverse((e=>{if(e instanceof Ne.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ne.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ht(){Ye=!0,Ue.style.display="none"}function pt(){if(Ye)return;requestAnimationFrame(pt),ft(),Ze.update();const e=Ve.background;Ve.background=null,Ve.overrideMaterial=Be;const t=Oe.getClearAlpha();Oe.setClearAlpha(0),Oe.setRenderTarget(We),Oe.render(Ve,Xe),Ve.overrideMaterial=null,vt(it),vt(.4*it),Oe.setRenderTarget(null),Oe.setClearAlpha(t),Ve.background=e,Oe.render(Ve,Qe)}function ft(){const e=Ue.clientWidth,t=Ue.clientHeight;Ue.width===e&&Ue.height===t||(Oe.setSize(e,t,!1),Qe.aspect=e/t,Qe.updateProjectionMatrix())}function vt(e){qe.visible=!0,He.uniforms.tDiffuse.value=We.texture,He.uniforms.h.value=1*e/256,qe.material=He,Oe.setRenderTarget(ze),Oe.render(qe,Xe),Ke.uniforms.tDiffuse.value=ze.texture,Ke.uniforms.v.value=1*e/256,qe.material=Ke,Oe.setRenderTarget(We),Oe.render(qe,Xe),qe.visible=!1}function wt(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function mt(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const yt=["AR","3D"];function gt(e){const{apiKey:t,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;wt(t,"apiKey"),mt(t,"apiKey"),wt(o,"sku"),mt(o,"sku"),wt(i,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(r,"initialState",yt),null!=a&&mt(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let bt=0,Ct=0;function Et(e){var o,i;return t(this,void 0,void 0,(function*(){gt(e);const{apiKey:r,sku:a,targetElement:s,initialState:l}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),g.update(e.baseUrl);const d=function(e,o){return t(this,void 0,void 0,(function*(){const i=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield i.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(r,a);null==C&&(C=b(`${g}/shopar-analytics.js`),C.then((()=>{R=!0,E=window.ShopAR__analytics.uuidv4(),A.forEach((e=>e()))}))),function(e,t){S.organizationId=e,S.sku=t,x=performance.now(),$((()=>{window.ShopAR__analytics.initializeImpl()}))}(r,a),Se();const c=++Ct,{category:h,arUrl:p,arKey:m,previewUrl:y,previewEnvUrl:I}=yield d;Rt(c),P("initialized");const T=null!=p&&function(e){return null!=e&&v.includes(e)}(h),j=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled),N=T&&function(e){return null!=e&&w.includes(e)}(h),q=j&&N&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==H&&(H=b(`${g}/shopar-platform.js`)),yield H,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}());Rt(c),q&&function(){t(this,void 0,void 0,(function*(){null==Ee&&(Ee=b(`${g}/shopar-qr.js`))}))}();const B=T&&!q;B&&(null==D&&(D=b(`${g}/shopar-deepar.js`)),V(p),"Glasses"===h&&null==L&&(L=b(`${g}/shopar-true-scale.js`)));const ee=null!=y;var te;ee&&(null==Pe&&(Pe=b(`${g}/shopar-three.js`)),lt(y),(te=null!=I?I:`${g}/env/default.hdr`)!==Ie&&(Ie=te,_e=O(te))),function(e){e.style.position="relative",null==Ae?e.appendChild(ce):e!==Ae&&(Ae.removeChild(ce),e.appendChild(ce)),Ae=e}(s);const ne=null==e.defaultUI||e.defaultUI;if(function(e,t,n,o){xe(fe,e),xe(ve,e&&(n||t)&&be===de.None),xe(we,e&&o&&be===de.None),xe(me,e&&be!==de.None),e||ke(ye),e||ke(ge)}(ne,q,B,ee),be===de.AR){if(!K)if(B){const e=yield U;Rt(c),yield X(e),Rt(c)}else Z(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0));if(!Te)if(q)try{yield De(r,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}else Le(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))}else if(be===de.Preview&&!Ye)if(ee){const e=yield $e;Rt(c);const t=yield _e;Rt(c);const n=yield ct(e,t);Rt(c),ut(n)}else ht(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0));const oe=()=>t(this,void 0,void 0,(function*(){if(q){if(be===de.AR)throw new n("AR already launched.");const e=++bt;be===de.Preview&&ee&&!Ye&&ht(),Ce(de.AR),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),k(),ne&&(xe(ge,!1),xe(ye,!0));try{yield De(r,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}if(bt!==e||Ct!==c)return;return void(ne&&xe(ye,!1))}if(!B)throw new n("Model does not have AR enabled.");if(be===de.AR)throw new n("AR already launched.");const e=++bt;be===de.Preview&&ee&&!Ye&&ht(),Ce(de.AR),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),k(),ne&&(xe(ge,!1),xe(ye,!0));const o=yield U;if(bt===e&&Ct===c&&(yield D,bt===e&&Ct===c)){try{yield Q(he,m,h)}catch(e){throw function(e){P("vto_camera_denied",{error:e})}(e),ne&&(xe(ye,!1),xe(ge,!0)),e}bt===e&&Ct===c&&(yield X(o),bt===e&&Ct===c&&(yield function(){return t(this,void 0,void 0,(function*(){if(null!=G){if(K=!1,null==W){const e=Y(z),t=M(e);W=yield _(t),yield J(G,W,"user"===e)}G.setPaused(K),F.style.display=""}}))}(),bt===e&&Ct===c&&ne&&xe(ye,!1)))}})),ie=()=>t(this,void 0,void 0,(function*(){if(!ee)throw new n("Model does not have 3D enabled.");if(be===de.Preview)throw new n("3D already launched.");const e=++bt;be===de.AR&&(B&&!K&&Z(),Le()),Ce(de.Preview),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),P("preview_launched"),ne&&(xe(ge,!1),xe(ye,!0));const t=yield $e;if(bt!==e||Ct!==c)return;const o=yield _e;if(bt!==e||Ct!==c)return;if(yield Pe,bt!==e||Ct!==c)return;if(yield dt(pe,h),bt!==e||Ct!==c)return;const i=yield ct(t,o);bt===e&&Ct===c&&(ut(i),Ye=!1,pt(),Ue.style.display="",ne&&xe(ye,!1))})),re=()=>t(this,void 0,void 0,(function*(){if(be===de.None)throw new n("Neither AR or 3D launched.");++bt,be===de.AR?(B&&!K&&Z(),Le()):be===de.Preview&&ee&&!Ye&&ht(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))}));return ne&&((q||B)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${g}/img/icons/${null!=e&&t[e]||t.Glasses}`;ve.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(h),ve.onclick=oe),ee&&(we.onclick=ie),me.onclick=re),"AR"===l?(yield oe(),Rt(c)):"3D"===l&&(yield ie(),Rt(c)),{launchAR:oe,launch3D:ie,closeAR:()=>t(this,void 0,void 0,(function*(){if(be!==de.AR)throw new n("AR not launched.");++bt,B&&!K&&Z(),Le(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))})),close3D:()=>t(this,void 0,void 0,(function*(){if(be!==de.Preview)throw new n("3D not launched.");++bt,ee&&!Ye&&ht(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))})),close:re}}))}function Rt(e){if(Ct!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const At={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Et(e)))}))},version:m};e.plugin=At})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(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 t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class n 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),d=l^l,c=new o[1]([d]);function u(){const e=(new TextEncoder).encode(s),t=r.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[r[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=p)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),f(e,n+1)}}))}const v=["Glasses","Shoes","Watches"],w=["Shoes"];const m="0.0.6-alpha.4";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${m}/dist`;const g={update:e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>y};function b(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let C,E,R=!1;const A=[],S={organizationId:"Unknown",sku:"Unknown"};let x;function k(){P("vto_launched")}function P(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),S),{vtoTime:(performance.now()-x)/1e3,vtoSessionId:E}),$((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function $(e){R?e():A.push(e)}function M(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function _(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const I=200,T=10;let D,L,U,j,N=!1;function O(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let G,W,z,F,q,B,H,K=!0;function V(e){e!==j&&(j=e,U=O(e),B=null,null==G||G.clearEffect(),N=!0)}function Q(e,o,i){return t(this,void 0,void 0,(function*(){return z=i,F=e,null==q&&(q=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new n("No camera available!");var r;const a=Y(i),s=M(a);P("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);G=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),W=yield _(s),P("vto_camera_granted"),yield J(G,W,"user"===a),"Glasses"===i&&(yield L,function(e,n){t(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${g}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>t(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<T)return void i.push(t);clearInterval(r);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),I)}))}(W,G)),P("vto_init_success")})))()),q}))}function X(e){return t(this,void 0,void 0,(function*(){return null==B&&(B=G.switchEffect(e)),B}))}function Z(){null!=G&&(K=!0,G.setPaused(K),null!=W&&null!=W.srcObject&&W.srcObject instanceof MediaStream&&(W.srcObject.getTracks().forEach((e=>e.stop())),W=null),G.stopCamera(),F.style.display="none")}function Y(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function J(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),i()}))))}}))}))}function ee(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const te="shopar-error";function ne(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ee("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const oe="shopar-control";const ie="shopar-deepar-output";const re="shopar-loading";const ae="shopar-main";const se="shopar-qr-output";const le="shopar-three-output";var de;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(de||(de={}));let ce,ue,he,pe,fe,ve,we,me,ye,ge,be=de.None;function Ce(e){be=e}let Ee,Re=!1,Ae=null;function Se(){Re||(ce=function(){const e=document.createElement("div");e.id=ae;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),ue=function(){const e=document.createElement("div");e.id=se;const t=e.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="relative",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="flex",o.alignItems="center",o.justifyContent="center",o.backgroundColor="white",e.appendChild(n);const i=new Image,r=i.style;return r.maxWidth="100%",r.maxHeight="100%",n.appendChild(i),e}(),ce.appendChild(ue),he=function(){const e=document.createElement("div");e.id=ie;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(he),pe=function(){const e=document.createElement("canvas");e.id=le;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(pe),fe=function(){const e=document.createElement("div");return e.id=oe,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ce.appendChild(fe),ve=ne("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),fe.appendChild(ve),we=ne("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${g}/img/icons/cube.svg`),fe.appendChild(we),me=ne("shopar-btn-close","Close","Close ShopAR view",`${g}/img/icons/close.svg`),fe.append(me),ye=function(){const e=document.createElement("div");e.id=re;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),ce.appendChild(ye),ge=function(){const e=document.createElement("div");e.id=te;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.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(n);const i=ee("4rem",`${g}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.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.",n.appendChild(a),e}(),ce.appendChild(ge),Re=!0)}function xe(e,t){e.style.display=t?"":"none"}function ke(e){""===e.style.display&&xe(e,!1)}let Pe,$e,Me,_e,Ie,Te=!0;function De(e,n){return t(this,void 0,void 0,(function*(){yield Ee;const t=`https://apps.deepar.ai/${m.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:n,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(t),i=ue.firstChild.firstChild,r=new Promise(((e,t)=>{i.onload=e,i.onerror=t}));i.src=o,yield r,Te=!1,ue.style.display=""}))}function Le(){Te=!0,ue.style.display="none"}let Ue,je,Ne,Oe,Ge,We,ze,Fe,qe,Be,He,Ke,Ve,Qe,Xe,Ze,Ye=!1,Je=!1;const et=45,tt=45,nt=3,ot=.1,it=3.5,rt=2,at=1;let st;function lt(e){if(e!==Me){const i=255;Me=e,$e=function(e,i,r){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),v=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],w=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield v(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),m=new o[0](yield(yield w.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));r+=s;const y=m.byteLength;if(c[d]=Math.min(76,i)*((a>>5)-1),152===c[d]&&(c[d]=y),r==d)return m;r=d,r^=d;for(let e=0,t=m.length;e<t;e++)c[d]^=c[r]<<13,c[d]^=c[r]>>17,c[d]^=c[r]<<5,m[e]=m[e]^c[d];return r^=c[0],r^=c[1],r^=c[2],m}))}(e,(new Date).getTime()+i,Math.random()*i),st=null,null==Ve||Ve.clear()}}function dt(e,n){return t(this,void 0,void 0,(function*(){if(Ue=e,!Je){je=window.ShopAR__THREE,Ne=je.THREE,Oe=new Ne.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),Oe.outputEncoding=Ne.sRGBEncoding,Oe.toneMapping=Ne.ACESFilmicToneMapping,Oe.setPixelRatio(window.devicePixelRatio||1),Oe.setClearColor(new Ne.Color(16777215)),Ve=new Ne.Scene,Ge=new Ne.Group,Ge.position.y=-.7,We=new Ne.WebGLRenderTarget(512,512),We.texture.generateMipmaps=!1,ze=new Ne.WebGLRenderTarget(512,512),ze.texture.generateMipmaps=!1;const t=new Ne.PlaneGeometry(et,tt).rotateX(Math.PI/2),o=new Ne.MeshBasicMaterial({map:We.texture,opacity:at,transparent:!0,depthWrite:!1});Fe=new Ne.Mesh(t,o),Fe.renderOrder=1,Ge.add(Fe),Fe.scale.y=-1,qe=new Ne.Mesh(t),qe.visible=!1,Ge.add(qe),Xe=new Ne.OrthographicCamera(-et/2,et/2,tt/2,-tt/2,0,nt),Xe.rotation.x=Math.PI/2,Ge.add(Xe),Be=new Ne.MeshDepthMaterial,Be.userData.darkness={value:rt},Be.onBeforeCompile=function(e){e.uniforms.darkness=Be.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 `},Be.depthTest=!1,Be.depthWrite=!1,He=new Ne.ShaderMaterial(je.HorizontalBlurShader),He.depthTest=!1,Ke=new Ne.ShaderMaterial(je.VerticalBlurShader),Ke.depthTest=!1,Qe=new Ne.PerspectiveCamera(25,1,.5);const i=function(e){var t;const n={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?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);Qe.position.set(i[0],i[1],i[2]),Ze=new je.OrbitControls(Qe,Oe.domElement),Ze.target.set(0,.03,0),Ze.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{P("preview_interacted")}),200);Ze.addEventListener("end",e)}Je=!0}ft()}))}function ct(e,n){return t(this,void 0,void 0,(function*(){return null==st&&(st=(()=>t(this,void 0,void 0,(function*(){const t=new je.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(je,t.parse(n));o.mapping=Ne.EquirectangularReflectionMapping,o.encoding=Ne.LinearEncoding,Ve.environment=o;const i=(new je.GLTFLoader).setDRACOLoader((new je.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new je.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(Oe)).setMeshoptDecoder("function"==typeof je.MeshoptDecoder?je.MeshoptDecoder():je.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),st}))}function ut(e){return t(this,void 0,void 0,(function*(){Ve.add(e.scene);const t=(new Ne.Box3).setFromObject(e.scene);Ge.position.y=t.min.y-ot,Ve.add(Ge),Ve.traverse((e=>{if(e instanceof Ne.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ne.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ht(){Ye=!0,Ue.style.display="none"}function pt(){if(Ye)return;requestAnimationFrame(pt),ft(),Ze.update();const e=Ve.background;Ve.background=null,Ve.overrideMaterial=Be;const t=Oe.getClearAlpha();Oe.setClearAlpha(0),Oe.setRenderTarget(We),Oe.render(Ve,Xe),Ve.overrideMaterial=null,vt(it),vt(.4*it),Oe.setRenderTarget(null),Oe.setClearAlpha(t),Ve.background=e,Oe.render(Ve,Qe)}function ft(){const e=Ue.clientWidth,t=Ue.clientHeight;Ue.width===e&&Ue.height===t||(Oe.setSize(e,t,!1),Qe.aspect=e/t,Qe.updateProjectionMatrix())}function vt(e){qe.visible=!0,He.uniforms.tDiffuse.value=We.texture,He.uniforms.h.value=1*e/256,qe.material=He,Oe.setRenderTarget(ze),Oe.render(qe,Xe),Ke.uniforms.tDiffuse.value=ze.texture,Ke.uniforms.v.value=1*e/256,qe.material=Ke,Oe.setRenderTarget(We),Oe.render(qe,Xe),qe.visible=!1}function wt(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function mt(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const yt=["AR","3D"];function gt(e){const{apiKey:t,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;wt(t,"apiKey"),mt(t,"apiKey"),wt(o,"sku"),mt(o,"sku"),wt(i,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(r,"initialState",yt),null!=a&&mt(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let bt=0,Ct=0;function Et(e){var o,i;return t(this,void 0,void 0,(function*(){gt(e);const{apiKey:r,sku:a,targetElement:s,initialState:l}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),g.update(e.baseUrl);const d=function(e,o){return t(this,void 0,void 0,(function*(){const i=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield i.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(r,a);null==C&&(C=b(`${g}/shopar-analytics.js`),C.then((()=>{R=!0,E=window.ShopAR__analytics.uuidv4(),A.forEach((e=>e()))}))),function(e,t){S.organizationId=e,S.sku=t,x=performance.now(),$((()=>{window.ShopAR__analytics.initializeImpl()}))}(r,a),Se();const c=++Ct,{category:h,arUrl:p,arKey:m,previewUrl:y,previewEnvUrl:I}=yield d;Rt(c),P("initialized");const T=null!=p&&function(e){return null!=e&&v.includes(e)}(h),j=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled),N=T&&function(e){return null!=e&&w.includes(e)}(h),q=j&&N&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==H&&(H=b(`${g}/shopar-platform.js`)),yield H,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}());Rt(c),q&&function(){t(this,void 0,void 0,(function*(){null==Ee&&(Ee=b(`${g}/shopar-qr.js`))}))}();const B=T&&!q;B&&(null==D&&(D=b(`${g}/shopar-deepar.js`)),V(p),"Glasses"===h&&null==L&&(L=b(`${g}/shopar-true-scale.js`)));const ee=null!=y;var te;ee&&(null==Pe&&(Pe=b(`${g}/shopar-three.js`)),lt(y),(te=null!=I?I:`${g}/env/default.hdr`)!==Ie&&(Ie=te,_e=O(te))),function(e){e.style.position="relative",null==Ae?e.appendChild(ce):e!==Ae&&(Ae.removeChild(ce),e.appendChild(ce)),Ae=e}(s);const ne=null==e.defaultUI||e.defaultUI;if(function(e,t,n,o){xe(fe,e),xe(ve,e&&(n||t)&&be===de.None),xe(we,e&&o&&be===de.None),xe(me,e&&be!==de.None),e||ke(ye),e||ke(ge)}(ne,q,B,ee),be===de.AR){if(!K)if(B){const e=yield U;Rt(c),yield X(e),Rt(c)}else Z(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0));if(!Te)if(q)try{yield De(r,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}else Le(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))}else if(be===de.Preview&&!Ye)if(ee){const e=yield $e;Rt(c);const t=yield _e;Rt(c);const n=yield ct(e,t);Rt(c),ut(n)}else ht(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0));const oe=()=>t(this,void 0,void 0,(function*(){if(q){if(be===de.AR)throw new n("AR already launched.");const e=++bt;be===de.Preview&&ee&&!Ye&&ht(),Ce(de.AR),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),k(),ne&&(xe(ge,!1),xe(ye,!0));try{yield De(r,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}if(bt!==e||Ct!==c)return;return void(ne&&xe(ye,!1))}if(!B)throw new n("Model does not have AR enabled.");if(be===de.AR)throw new n("AR already launched.");const e=++bt;be===de.Preview&&ee&&!Ye&&ht(),Ce(de.AR),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),k(),ne&&(xe(ge,!1),xe(ye,!0));const o=yield U;if(bt===e&&Ct===c&&(yield D,bt===e&&Ct===c)){try{yield Q(he,m,h)}catch(e){throw function(e){P("vto_camera_denied",{error:e})}(e),ne&&(xe(ye,!1),xe(ge,!0)),e}bt===e&&Ct===c&&(yield X(o),bt===e&&Ct===c&&(yield function(){return t(this,void 0,void 0,(function*(){if(null!=G){if(K=!1,null==W){const e=Y(z),t=M(e);W=yield _(t),yield J(G,W,"user"===e)}G.setPaused(K),F.style.display=""}}))}(),bt===e&&Ct===c&&ne&&xe(ye,!1)))}})),ie=()=>t(this,void 0,void 0,(function*(){if(!ee)throw new n("Model does not have 3D enabled.");if(be===de.Preview)throw new n("3D already launched.");const e=++bt;be===de.AR&&(B&&!K&&Z(),Le()),Ce(de.Preview),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),P("preview_launched"),ne&&(xe(ge,!1),xe(ye,!0));const t=yield $e;if(bt!==e||Ct!==c)return;const o=yield _e;if(bt!==e||Ct!==c)return;if(yield Pe,bt!==e||Ct!==c)return;if(yield dt(pe,h),bt!==e||Ct!==c)return;const i=yield ct(t,o);bt===e&&Ct===c&&(ut(i),Ye=!1,pt(),Ue.style.display="",ne&&xe(ye,!1))})),re=()=>t(this,void 0,void 0,(function*(){if(be===de.None)throw new n("Neither AR or 3D launched.");++bt,be===de.AR?(B&&!K&&Z(),Le()):be===de.Preview&&ee&&!Ye&&ht(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))}));return ne&&((q||B)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${g}/img/icons/${null!=e&&t[e]||t.Glasses}`;ve.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(h),ve.onclick=oe),ee&&(we.onclick=ie),me.onclick=re),"AR"===l?(yield oe(),Rt(c)):"3D"===l&&(yield ie(),Rt(c)),{launchAR:oe,launch3D:ie,closeAR:()=>t(this,void 0,void 0,(function*(){if(be!==de.AR)throw new n("AR not launched.");++bt,B&&!K&&Z(),Le(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))})),close3D:()=>t(this,void 0,void 0,(function*(){if(be!==de.Preview)throw new n("3D not launched.");++bt,ee&&!Ye&&ht(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))})),close:re}}))}function Rt(e){if(Ct!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const At={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Et(e)))}))},version:m};e.plugin=At})); |
{ | ||
"name": "shopar-plugin", | ||
"version": "0.0.6-alpha.3", | ||
"version": "0.0.6-alpha.4", | ||
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.", | ||
@@ -36,5 +36,5 @@ "scripts": { | ||
"dependencies": { | ||
"@amplitude/analytics-browser": "^2.3.3", | ||
"@axiomhq/js": "^1.0.0-rc.1", | ||
"@mediapipe/tasks-vision": "^0.10.7", | ||
"deepar": "5.5.1", | ||
"deepar": "5.5.2", | ||
"platform": "^1.3.6", | ||
@@ -41,0 +41,0 @@ "qrcode": "1.5.1", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31
20915097
7841
+ Added@axiomhq/js@^1.0.0-rc.1
+ Added@axiomhq/js@1.3.0(transitive)
+ Addeddeepar@5.5.2(transitive)
+ Addedfetch-retry@6.0.0(transitive)
+ Addeduuid@11.0.3(transitive)
- Removed@amplitude/analytics-browser@^2.3.3
- Removed@amplitude/analytics-browser@2.11.9(transitive)
- Removed@amplitude/analytics-client-common@2.3.5(transitive)
- Removed@amplitude/analytics-connector@1.6.1(transitive)
- Removed@amplitude/analytics-core@2.5.4(transitive)
- Removed@amplitude/analytics-remote-config@0.4.1(transitive)
- Removed@amplitude/analytics-types@2.8.4(transitive)
- Removed@amplitude/experiment-core@0.10.0(transitive)
- Removed@amplitude/plugin-autocapture-browser@1.0.3(transitive)
- Removed@amplitude/plugin-page-view-tracking-browser@2.3.5(transitive)
- Removeddeepar@5.5.1(transitive)
- Removedjs-base64@3.7.7(transitive)
- Removedrxjs@7.8.1(transitive)
- Removedtslib@2.8.1(transitive)
Updateddeepar@5.5.2