Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shopar-plugin

Package Overview
Dependencies
Maintainers
1
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shopar-plugin - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5-alpha.0

2

dist/shopar-plugin.esm.js

@@ -1,1 +0,1 @@

function e(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{c(o.next(e))}catch(e){r(e)}}function a(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=[Uint8Array,Uint32Array],n=t.length-2,o=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],i=[2,12,7,1],r=window[o[i[i[n]]]][o[i[i[i.length-1]]]],s=r.charCodeAt(n),a=s^s,c=new t[1]([a]);function l(){const e=(new TextEncoder).encode(r),t=o.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[o[t[2]]](String.fromCodePoint(...e))}const d=[1e3,2e3,4e3],u=d.length;function h(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=u)throw e;return yield new Promise((e=>setTimeout(e,d[n]))),h(t,n+1)}}))}function p(t,n){return e(this,void 0,void 0,(function*(){const o=yield h((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:t,sku:n,sid:l()})}`).catch((e=>{throw console.error(e),new Error("API unavailable.")}));if(!e.ok)throw new Error(`API call failed with status ${e.status}.`);return e}))));try{return yield o.json()}catch(e){throw console.error(e),new Error("API returned invalid body.")}}))}const f=["Glasses","Shoes","Watches"];function v(e){return null!=e&&f.includes(e)}let w;const m=()=>w,g=e=>(null==w&&(w=y(e)),w),y=e=>{let t=!1;const n=[];e.then((()=>{t=!0,n.forEach((e=>e()))}));const o=e=>{t?e():n.push(e)},i={organizationId:"Unknown",sku:"Unknown"};let r,s=0;function a(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),i),{vtoTime:(performance.now()-s)/1e3,vtoSessionId:r}),o((()=>{const{trackEventImpl:n}=window.ShopAR__analytics;n(e,t)}))}return{init:function(e,t){i.organizationId=e||"Unknown",i.sku=t||"Unknown",s=performance.now(),o((()=>{const{initializeImpl:e,uuidv4:t}=window.ShopAR__analytics;e(),r=t()}))},initialized:()=>a("initialized"),vtoLaunched:()=>a("vto_launched"),vtoCameraAsked:()=>a("vto_camera_asked"),vtoCameraGranted:()=>a("vto_camera_granted"),vtoCameraDenied:e=>a("vto_camera_denied",{error:e}),vtoInitSuccess:()=>a("vto_init_success"),previewLaunched:()=>a("preview_launched"),previewInteracted:()=>a("preview_interacted")}};const E="0.0.4";let b=`https://cdn.jsdelivr.net/npm/shopar-plugin@${E}/dist`;const C={update:e=>{null!=e&&(b=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>b},A=10;function S(t,n){return e(this,void 0,void 0,(function*(){const{ShopAR__TrueScale:o}=window;yield o.initialize(`${C}/wasm/mediapipe`,t);const i=[];setInterval((()=>e(this,void 0,void 0,(function*(){const{error:e,ipd:t}=yield o.predict(performance.now());if(null==e){!function(e,t){e.length>A&&e.splice(0,1);e.push(t)}(i,t);const e=62/(i.reduce(((e,t)=>t+e),0)/i.length);n.changeParameterVector("GLASSES","","scale",e,e,e,0),n.changeParameterVector("shopar_glasses","","scale",e,e,e,0)}}))),200)}))}function P(e,t,n){const o=null==e?void 0:e.querySelector(`#${t}`);if(null!=o)return o;const i=n();return null==e||e.appendChild(i),i}function R(e,t,n){const o=P(e,t,n),i=o.style;return{element:o,show:()=>{i.display=""},hide:()=>{i.display="none"}}}const $="shopar-deepar-output";function L(){const e=document.createElement("div");e.id=$;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}let k;const I=()=>k,U=e=>(null==k&&(k=x(e)),k),x=t=>{const n=m(),o=function(e){return P(e,$,L)}(t),i=o.style;let r,s;let a;let c=!0;return{domElement:o,init:(t,i)=>e(void 0,void 0,void 0,(function*(){const a=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i),c=function(e){var t;const n={Glasses:"user",Shoes:"environment",Watches:"environment"};return null==e?"user":null!==(t=n[e])&&void 0!==t?t:"user"}(i);return null==s&&(s=e(void 0,void 0,void 0,(function*(){if(null==(null===(s=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===s?void 0:s.getUserMedia))throw new Error("No camera available!");var s;const l=function(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}(c);n.vtoCameraAsked(),r=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:t||"your_license_key_goes_here",previewElement:o,additionalOptions:{hint:a,cameraConfig:{disableDefaultCamera:!0}}});const d=yield function(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}(l);n.vtoCameraGranted(),yield function(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()}))))}}))}))}(r,d,"user"===c),"Glasses"===i&&S(d,r),n.vtoInitSuccess()}))),s})),parse:t=>e(void 0,void 0,void 0,(function*(){return null==a&&(a=r.switchEffect(t)),a})),isPaused:()=>c,resume:()=>{c=!1,r.setPaused(c),i.display=""},pause:()=>{c=!0,r.setPaused(c),i.display="none"}}};const D="shopar-three-output";function _(){const e=document.createElement("canvas");e.id=D;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",e}let M;const T=()=>M,j=(e,t)=>(null==M&&(M=N(e,t)),M),N=(t,n)=>{const o=m(),i=function(e){return P(e,D,_)}(t),r=i.style,s=window.ShopAR__THREE,a=s.THREE,c=new a.WebGLRenderer({powerPreference:"high-performance",canvas:i,antialias:!0,alpha:!0});c.outputEncoding=a.sRGBEncoding,c.toneMapping=a.ACESFilmicToneMapping,c.setPixelRatio(2*window.devicePixelRatio),c.setClearColor(new a.Color(16777215));const l=new a.PerspectiveCamera(25,1,.5),d=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);l.position.set(d[0],d[1],d[2]);const u=new a.Scene,h=new s.OrbitControls(l,c.domElement);h.target.set(0,.03,0),h.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>o.previewInteracted()),200);h.addEventListener("end",e)}{const e=new a.AmbientLight(new a.Color(16777215),.7),t=new a.RectAreaLight(new a.Color(16772574),10,50,50);t.position.set(-40,60,60);const n=new a.RectAreaLight(new a.Color(16774893),15,50,50);n.position.set(60,60,0),u.add(e,t,n)}const p=()=>{const e=i.clientWidth,t=i.clientHeight;i.width===e&&i.height===t||(c.setSize(e,t,!1),l.aspect=e/t,l.updateProjectionMatrix())};let f;let v=!1;const w=()=>{v||(requestAnimationFrame(w),p(),h.update(),c.render(u,l))};return{domElement:i,updateSize:p,parse:(t,n)=>e(void 0,void 0,void 0,(function*(){return null==f&&(f=e(void 0,void 0,void 0,(function*(){const e=new s.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}(s,e.parse(n));o.mapping=a.EquirectangularReflectionMapping,o.encoding=a.LinearEncoding,u.environment=o;const i=(new s.GLTFLoader).setDRACOLoader((new s.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${a.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new s.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${a.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(c)).setMeshoptDecoder("function"==typeof s.MeshoptDecoder?s.MeshoptDecoder():s.MeshoptDecoder),r=yield i.parseAsync(t.buffer,"");u.add(r.scene),u.traverse((e=>{if(e instanceof a.Mesh){const t=e.material;t.depthWrite=!0,t instanceof a.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),f})),isPaused:()=>v,resume:()=>{v=!1,w(),r.display=""},pause:()=>{v=!0,r.display="none"}}};function z(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 G="shopar-error";function K(){const e=document.createElement("div");e.id=G;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=z("4rem",`${C}/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 s=document.createElement("div");return s.className="shopar-error-body",s.textContent="Please refresh the page and allow the use of camera.",n.appendChild(s),e}function O(e,t){return P(e,t.id,(()=>function(e){const{id:t,iconUrl:n,textContent:o,ariaLabel:i}=e,r=document.createElement("button");if(r.id=t,r.type="button",r.className="shopar-btn",null!=n){const e=z("1.75rem",n);r.appendChild(e)}{const e=document.createElement("span");e.textContent=o,r.appendChild(e)}return r.ariaLabel=i,r.style.zIndex="2",r}(t)))}const W="shopar-control";function F(){const e=document.createElement("div");return e.id=W,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}const H="shopar-loading";function V(){const e=document.createElement("div");e.id=H;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}const q="shopar-main";function B(e){return P(e,q,X)}function X(){const e=document.createElement("div");e.id=q;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}function Y(t){return e(this,void 0,void 0,(function*(){const n=yield h((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(t).catch((e=>{throw console.error(e),new Error("Resource unavailable.")}));if(!e.ok)throw new Error(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield n.blob()).arrayBuffer()}catch(e){throw console.error(e),new Error("Resource has invalid body.")}}))}function J(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())}))}function Q(n,o,i){return e(this,void 0,void 0,(function*(){let r="glb".charCodeAt(0),s="3d".charCodeAt(0);r>>=1,r+=s;const l=String.fromCharCode(r+14);s>>=2,r^=s+2;const d=String.fromCharCode(r-3);r^=5;const u=String.fromCharCode(r-7);r^=2;const p=String.fromCharCode(r-7),f=window[`${u}${d+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],v=yield h((()=>e(this,void 0,void 0,(function*(){const e=yield f(`${n}`).catch((()=>{throw new Error("Unknown error.")}));if(!e.ok)throw new Error("Unknown error.");return e})))),w=new t[0](yield(yield v.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));i+=s;const m=w.byteLength;if(c[a]=Math.min(76,o)*((r>>5)-1),152===c[a]&&(c[a]=m),i==a)return w;i=a,i^=a;for(let e=0,t=w.length;e<t;e++)c[a]^=c[i]<<13,c[a]^=c[i]>>17,c[a]^=c[i]<<5,w[e]=w[e]^c[a];return i^=c[0],i^=c[1],i^=c[2],w}))}function Z(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function ee(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}const te=["AR","3D"];function ne(e){const{apiKey:t,sku:n,targetElement:o,initialState:i,baseUrl:r,defaultUI:s}=e;Z(t,"apiKey"),ee(t,"apiKey"),Z(n,"sku"),ee(n,"sku"),Z(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,t,n){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`);if(!n.includes(e))throw new Error(`'${t}' must be ${n.join("' or '")}.`)}(i,"initialState",te),null!=r&&ee(r,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new Error(`'${t}' must be a boolean.`)}(s,"defaultUI")}function oe(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new Error(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}var ie;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(ie||(ie={}));let re,se=ie.None,ae=0;const ce=[];let le;function de(){if(se===ie.AR){const e=I();null==e||e.isPaused()||e.pause()}else if(se===ie.Preview){const e=T();null==e||e.isPaused()||e.pause()}}function ue(e){if(se=e,se===ie.None){const e=ce.filter((e=>null!=e));re.replaceChildren(...e)}else re.replaceChildren(le)}function he(t){return e(this,void 0,void 0,(function*(){return ne(t),null==t.defaultUI||t.defaultUI?function(t){var n,o;return e(this,void 0,void 0,(function*(){const{apiKey:i,sku:r,targetElement:s,initialState:a}=t;oe(s),C.update(t.baseUrl);const c=p(i,r),l=g(J(`${C}/shopar-analytics.js`));l.init(i,r),s.style.position="relative";const d=B(s);re=P(d,W,F),le=O(null,{id:"shopar-btn-close",textContent:"Close",ariaLabel:"Close ShopAR view",iconUrl:`${C}/img/icons/close.svg`}),le.onclick=()=>{u.hide(),h.hide(),de(),ue(ie.None)};const u=function(e){return R(e,H,V)}(d),h=function(e){return R(e,G,K)}(d),{category:f,arUrl:w,arKey:m,previewUrl:y}=yield c;if(l.initialized(),null!=w&&v(f)){const t=Promise.all([J(`${C}/shopar-deepar.js`),Y(w),..."Glasses"===f?[J(`${C}/shopar-true-scale.js`)]:[]]),n={Glasses:`${C}/img/icons/glasses.svg`,Shoes:`${C}/img/icons/shoe.svg`,Watches:`${C}/img/icons/watch.svg`},o=null!=f&&n[f]||n.Glasses;ce[ie.AR]=O(re,{id:"shopar-btn-vto",textContent:"Try-on",ariaLabel:"Launch ShopAR virtual try-on",iconUrl:o}),ce[ie.AR].onclick=()=>e(this,void 0,void 0,(function*(){const e=++ae,n=ie.AR,o=se===n?ie.None:n;if(de(),ue(o),se===ie.None)return;l.vtoLaunched(),h.hide(),u.show();const[,i]=yield t;if(ae!==e)return;const r=U(d);try{yield r.init(m,f)}catch(e){return l.vtoCameraDenied(e),u.hide(),void h.show()}ae===e&&(yield r.parse(i),ae===e&&(r.resume(),u.hide()))}))}if(null!=y){const t=255,n=Promise.all([J(`${C}/shopar-three.js`),Q(y,(new Date).getTime()+t,Math.random()*t),Y(`${C}/env/studio5.hdr`)]);ce[ie.Preview]=O(re,{id:"shopar-btn-3d",textContent:"3D",ariaLabel:"Launch ShopAR 3D preview",iconUrl:`${C}/img/icons/cube.svg`}),ce[ie.Preview].onclick=()=>e(this,void 0,void 0,(function*(){const e=++ae,t=ie.Preview,o=se===t?ie.None:t;if(de(),ue(o),se===ie.None)return;l.previewLaunched(),h.hide(),u.show();const[,i,r]=yield n;if(ae!==e)return;const s=j(d,f);s.updateSize(),yield s.parse(i,r),ae===e&&(s.resume(),u.hide())}))}"AR"===a?null===(n=ce[ie.AR])||void 0===n||n.click():"3D"===a&&(null===(o=ce[ie.Preview])||void 0===o||o.click())}))}(t):function(t){return e(this,void 0,void 0,(function*(){const{apiKey:n,sku:o,targetElement:i,initialState:r}=t;oe(i),C.update(t.baseUrl);const s=p(n,o),a=g(J(`${C}/shopar-analytics.js`));a.init(n,o),i.style.position="relative";const c=B(i),{category:l,arUrl:d,arKey:u,previewUrl:h}=yield s;a.initialized();let f={enabled:!1};if(null!=d&&v(l)){const e=Promise.all([J(`${C}/shopar-deepar.js`),Y(d),..."Glasses"===l?[J(`${C}/shopar-true-scale.js`)]:[]]);f={enabled:!0,predownload:e,category:l}}const w=()=>e(this,void 0,void 0,(function*(){if(!f.enabled)throw new Error("Model does not have AR enabled.");if(se===ie.AR)throw new Error("AR already launched.");const e=++ae;if(se===ie.Preview){const e=T();null==e||e.isPaused()||e.pause()}se=ie.AR,a.vtoLaunched();const[,t]=yield f.predownload;if(ae!==e)return;const n=U(c);try{yield n.init(u,f.category)}catch(e){throw a.vtoCameraDenied(e),e}ae===e&&(yield n.parse(t),ae===e&&n.resume())}));let m={enabled:!1};if(null!=h){const e=255,t=Promise.all([J(`${C}/shopar-three.js`),Q(h,(new Date).getTime()+e,Math.random()*e),Y(`${C}/env/studio5.hdr`)]);m={enabled:!0,predownload:t}}const y=()=>e(this,void 0,void 0,(function*(){if(!m.enabled)throw new Error("Model does not have AR enabled.");if(se===ie.Preview)throw new Error("3D already launched.");const e=++ae;if(se===ie.AR){const e=I();null==e||e.isPaused()||e.pause()}se=ie.Preview,a.previewLaunched();const[,t,n]=yield m.predownload;if(ae!==e)return;const o=j(c,l);o.updateSize(),yield o.parse(t,n),ae===e&&o.resume()}));return"AR"===r?yield w():"3D"===r&&(yield y()),{launchAR:w,launch3D:y,closeAR:()=>e(this,void 0,void 0,(function*(){if(se!==ie.AR)throw new Error("AR not launched.");const e=I();null==e||e.isPaused()||e.pause(),se=ie.None})),close3D:()=>e(this,void 0,void 0,(function*(){if(se!==ie.Preview)throw new Error("3D not launched.");const e=T();null==e||e.isPaused()||e.pause(),se=ie.None}))}}))}(t)}))}const pe={setup:function(t){return e(this,void 0,void 0,(function*(){return function(t,n){return e(this,void 0,void 0,(function*(){try{return n()}catch(e){throw e instanceof Error?new pe.PluginError(`${t} failed: ${e.message}`):(console.error(e),new pe.PluginError(`${t} failed.`))}}))}("setup",(()=>he(t)))}))},version:E,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};export{pe as plugin};
function e(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{c(o.next(e))}catch(e){r(e)}}function a(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=[Uint8Array,Uint32Array],n=t.length-2,o=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],i=[2,12,7,1],r=window[o[i[i[n]]]][o[i[i[i.length-1]]]],s=r.charCodeAt(n),a=s^s,c=new t[1]([a]);function l(){const e=(new TextEncoder).encode(r),t=o.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[o[t[2]]](String.fromCodePoint(...e))}const d=[1e3,2e3,4e3],u=d.length;function h(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=u)throw e;return yield new Promise((e=>setTimeout(e,d[n]))),h(t,n+1)}}))}function p(t,n){return e(this,void 0,void 0,(function*(){const o=yield h((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:t,sku:n,sid:l()})}`).catch((e=>{throw console.error(e),new Error("API unavailable.")}));if(!e.ok)throw new Error(`API call failed with status ${e.status}.`);return e}))));try{return yield o.json()}catch(e){throw console.error(e),new Error("API returned invalid body.")}}))}const f=["Glasses","Shoes","Watches"];function v(e){return null!=e&&f.includes(e)}let w;const m=()=>w,g=e=>(null==w&&(w=y(e)),w),y=e=>{let t=!1;const n=[];e.then((()=>{t=!0,n.forEach((e=>e()))}));const o=e=>{t?e():n.push(e)},i={organizationId:"Unknown",sku:"Unknown"};let r,s=0;function a(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),i),{vtoTime:(performance.now()-s)/1e3,vtoSessionId:r}),o((()=>{const{trackEventImpl:n}=window.ShopAR__analytics;n(e,t)}))}return{init:function(e,t){i.organizationId=e||"Unknown",i.sku=t||"Unknown",s=performance.now(),o((()=>{const{initializeImpl:e,uuidv4:t}=window.ShopAR__analytics;e(),r=t()}))},initialized:()=>a("initialized"),vtoLaunched:()=>a("vto_launched"),vtoCameraAsked:()=>a("vto_camera_asked"),vtoCameraGranted:()=>a("vto_camera_granted"),vtoCameraDenied:e=>a("vto_camera_denied",{error:e}),vtoInitSuccess:()=>a("vto_init_success"),previewLaunched:()=>a("preview_launched"),previewInteracted:()=>a("preview_interacted")}};const E="0.0.5-alpha.0";let b=`https://cdn.jsdelivr.net/npm/shopar-plugin@${E}/dist`;const C={update:e=>{null!=e&&(b=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>b};function A(e,t,n){const o=null==e?void 0:e.querySelector(`#${t}`);if(null!=o)return o;const i=n();return null==e||e.appendChild(i),i}function S(e,t,n){const o=A(e,t,n),i=o.style;return{element:o,show:()=>{i.display=""},hide:()=>{i.display="none"}}}const P="shopar-deepar-output";function R(){const e=document.createElement("div");e.id=P;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}let $;const L=()=>$,k=e=>(null==$&&($=I(e)),$),I=t=>{const n=m(),o=function(e){return A(e,P,R)}(t),i=o.style;let r,s;let a;let c=!0;return{domElement:o,init:(t,i)=>e(void 0,void 0,void 0,(function*(){const a=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i),c=function(e){var t;const n={Glasses:"user",Shoes:"environment",Watches:"environment"};return null==e?"user":null!==(t=n[e])&&void 0!==t?t:"user"}(i);return null==s&&(s=e(void 0,void 0,void 0,(function*(){if(null==(null===(s=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===s?void 0:s.getUserMedia))throw new Error("No camera available!");var s;const l=function(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}(c);n.vtoCameraAsked(),r=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:t||"your_license_key_goes_here",previewElement:o,additionalOptions:{hint:a,cameraConfig:{disableDefaultCamera:!0}}});const d=yield function(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}(l);n.vtoCameraGranted(),yield function(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()}))))}}))}))}(r,d,"user"===c),"Glasses"===i&&function(t,n){e(this,void 0,void 0,(function*(){const{ShopAR__TrueScale:o}=window;yield o.initialize(`${C}/wasm/mediapipe`,t);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){const{error:e,faceWidth:t}=yield o.predict(performance.now());if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<10)return void i.push(t);clearInterval(r);const s=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",s,s,s,0),n.changeParameterVector("shopar_glasses","","scale",s,s,s,0)}))),200)}))}(d,r),n.vtoInitSuccess()}))),s})),parse:t=>e(void 0,void 0,void 0,(function*(){return null==a&&(a=r.switchEffect(t)),a})),isPaused:()=>c,resume:()=>{c=!1,r.setPaused(c),i.display=""},pause:()=>{c=!0,r.setPaused(c),i.display="none"}}};const U="shopar-three-output";function x(){const e=document.createElement("canvas");e.id=U;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",e}let D;const _=()=>D,M=(e,t)=>(null==D&&(D=T(e,t)),D),T=(t,n)=>{const o=m(),i=function(e){return A(e,U,x)}(t),r=i.style,s=window.ShopAR__THREE,a=s.THREE,c=new a.WebGLRenderer({powerPreference:"high-performance",canvas:i,antialias:!0,alpha:!0});c.outputEncoding=a.sRGBEncoding,c.toneMapping=a.ACESFilmicToneMapping,c.setPixelRatio(2*window.devicePixelRatio),c.setClearColor(new a.Color(16777215));const l=new a.PerspectiveCamera(25,1,.5),d=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);l.position.set(d[0],d[1],d[2]);const u=new a.Scene,h=new s.OrbitControls(l,c.domElement);h.target.set(0,.03,0),h.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>o.previewInteracted()),200);h.addEventListener("end",e)}{const e=new a.AmbientLight(new a.Color(16777215),.7),t=new a.RectAreaLight(new a.Color(16772574),10,50,50);t.position.set(-40,60,60);const n=new a.RectAreaLight(new a.Color(16774893),15,50,50);n.position.set(60,60,0),u.add(e,t,n)}const p=()=>{const e=i.clientWidth,t=i.clientHeight;i.width===e&&i.height===t||(c.setSize(e,t,!1),l.aspect=e/t,l.updateProjectionMatrix())};let f;let v=!1;const w=()=>{v||(requestAnimationFrame(w),p(),h.update(),c.render(u,l))};return{domElement:i,updateSize:p,parse:(t,n)=>e(void 0,void 0,void 0,(function*(){return null==f&&(f=e(void 0,void 0,void 0,(function*(){const e=new s.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}(s,e.parse(n));o.mapping=a.EquirectangularReflectionMapping,o.encoding=a.LinearEncoding,u.environment=o;const i=(new s.GLTFLoader).setDRACOLoader((new s.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${a.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new s.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${a.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(c)).setMeshoptDecoder("function"==typeof s.MeshoptDecoder?s.MeshoptDecoder():s.MeshoptDecoder),r=yield i.parseAsync(t.buffer,"");u.add(r.scene),u.traverse((e=>{if(e instanceof a.Mesh){const t=e.material;t.depthWrite=!0,t instanceof a.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),f})),isPaused:()=>v,resume:()=>{v=!1,w(),r.display=""},pause:()=>{v=!0,r.display="none"}}};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 N="shopar-error";function z(){const e=document.createElement("div");e.id=N;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",`${C}/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 s=document.createElement("div");return s.className="shopar-error-body",s.textContent="Please refresh the page and allow the use of camera.",n.appendChild(s),e}function G(e,t){return A(e,t.id,(()=>function(e){const{id:t,iconUrl:n,textContent:o,ariaLabel:i}=e,r=document.createElement("button");if(r.id=t,r.type="button",r.className="shopar-btn",null!=n){const e=j("1.75rem",n);r.appendChild(e)}{const e=document.createElement("span");e.textContent=o,r.appendChild(e)}return r.ariaLabel=i,r.style.zIndex="2",r}(t)))}const W="shopar-control";function K(){const e=document.createElement("div");return e.id=W,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}const O="shopar-loading";function F(){const e=document.createElement("div");e.id=O;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}const H="shopar-main";function V(e){return A(e,H,q)}function q(){const e=document.createElement("div");e.id=H;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}function B(t){return e(this,void 0,void 0,(function*(){const n=yield h((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(t).catch((e=>{throw console.error(e),new Error("Resource unavailable.")}));if(!e.ok)throw new Error(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield n.blob()).arrayBuffer()}catch(e){throw console.error(e),new Error("Resource has invalid body.")}}))}function X(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())}))}function Y(n,o,i){return e(this,void 0,void 0,(function*(){let r="glb".charCodeAt(0),s="3d".charCodeAt(0);r>>=1,r+=s;const l=String.fromCharCode(r+14);s>>=2,r^=s+2;const d=String.fromCharCode(r-3);r^=5;const u=String.fromCharCode(r-7);r^=2;const p=String.fromCharCode(r-7),f=window[`${u}${d+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],v=yield h((()=>e(this,void 0,void 0,(function*(){const e=yield f(`${n}`).catch((()=>{throw new Error("Unknown error.")}));if(!e.ok)throw new Error("Unknown error.");return e})))),w=new t[0](yield(yield v.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));i+=s;const m=w.byteLength;if(c[a]=Math.min(76,o)*((r>>5)-1),152===c[a]&&(c[a]=m),i==a)return w;i=a,i^=a;for(let e=0,t=w.length;e<t;e++)c[a]^=c[i]<<13,c[a]^=c[i]>>17,c[a]^=c[i]<<5,w[e]=w[e]^c[a];return i^=c[0],i^=c[1],i^=c[2],w}))}function J(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function Q(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}const Z=["AR","3D"];function ee(e){const{apiKey:t,sku:n,targetElement:o,initialState:i,baseUrl:r,defaultUI:s}=e;J(t,"apiKey"),Q(t,"apiKey"),J(n,"sku"),Q(n,"sku"),J(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,t,n){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`);if(!n.includes(e))throw new Error(`'${t}' must be ${n.join("' or '")}.`)}(i,"initialState",Z),null!=r&&Q(r,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new Error(`'${t}' must be a boolean.`)}(s,"defaultUI")}function te(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new Error(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}var ne;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(ne||(ne={}));let oe,ie=ne.None,re=0;const se=[];let ae;function ce(){if(ie===ne.AR){const e=L();null==e||e.isPaused()||e.pause()}else if(ie===ne.Preview){const e=_();null==e||e.isPaused()||e.pause()}}function le(e){if(ie=e,ie===ne.None){const e=se.filter((e=>null!=e));oe.replaceChildren(...e)}else oe.replaceChildren(ae)}function de(t){return e(this,void 0,void 0,(function*(){return ee(t),null==t.defaultUI||t.defaultUI?function(t){var n,o;return e(this,void 0,void 0,(function*(){const{apiKey:i,sku:r,targetElement:s,initialState:a}=t;te(s),C.update(t.baseUrl);const c=p(i,r),l=g(X(`${C}/shopar-analytics.js`));l.init(i,r),s.style.position="relative";const d=V(s);oe=A(d,W,K),ae=G(null,{id:"shopar-btn-close",textContent:"Close",ariaLabel:"Close ShopAR view",iconUrl:`${C}/img/icons/close.svg`}),ae.onclick=()=>{u.hide(),h.hide(),ce(),le(ne.None)};const u=function(e){return S(e,O,F)}(d),h=function(e){return S(e,N,z)}(d),{category:f,arUrl:w,arKey:m,previewUrl:y}=yield c;if(l.initialized(),null!=w&&v(f)){const t=Promise.all([X(`${C}/shopar-deepar.js`),B(w),..."Glasses"===f?[X(`${C}/shopar-true-scale.js`)]:[]]),n={Glasses:`${C}/img/icons/glasses.svg`,Shoes:`${C}/img/icons/shoe.svg`,Watches:`${C}/img/icons/watch.svg`},o=null!=f&&n[f]||n.Glasses;se[ne.AR]=G(oe,{id:"shopar-btn-vto",textContent:"Try-on",ariaLabel:"Launch ShopAR virtual try-on",iconUrl:o}),se[ne.AR].onclick=()=>e(this,void 0,void 0,(function*(){const e=++re,n=ne.AR,o=ie===n?ne.None:n;if(ce(),le(o),ie===ne.None)return;l.vtoLaunched(),h.hide(),u.show();const[,i]=yield t;if(re!==e)return;const r=k(d);try{yield r.init(m,f)}catch(e){return l.vtoCameraDenied(e),u.hide(),void h.show()}re===e&&(yield r.parse(i),re===e&&(r.resume(),u.hide()))}))}if(null!=y){const t=255,n=Promise.all([X(`${C}/shopar-three.js`),Y(y,(new Date).getTime()+t,Math.random()*t),B(`${C}/env/studio5.hdr`)]);se[ne.Preview]=G(oe,{id:"shopar-btn-3d",textContent:"3D",ariaLabel:"Launch ShopAR 3D preview",iconUrl:`${C}/img/icons/cube.svg`}),se[ne.Preview].onclick=()=>e(this,void 0,void 0,(function*(){const e=++re,t=ne.Preview,o=ie===t?ne.None:t;if(ce(),le(o),ie===ne.None)return;l.previewLaunched(),h.hide(),u.show();const[,i,r]=yield n;if(re!==e)return;const s=M(d,f);s.updateSize(),yield s.parse(i,r),re===e&&(s.resume(),u.hide())}))}"AR"===a?null===(n=se[ne.AR])||void 0===n||n.click():"3D"===a&&(null===(o=se[ne.Preview])||void 0===o||o.click())}))}(t):function(t){return e(this,void 0,void 0,(function*(){const{apiKey:n,sku:o,targetElement:i,initialState:r}=t;te(i),C.update(t.baseUrl);const s=p(n,o),a=g(X(`${C}/shopar-analytics.js`));a.init(n,o),i.style.position="relative";const c=V(i),{category:l,arUrl:d,arKey:u,previewUrl:h}=yield s;a.initialized();let f={enabled:!1};if(null!=d&&v(l)){const e=Promise.all([X(`${C}/shopar-deepar.js`),B(d),..."Glasses"===l?[X(`${C}/shopar-true-scale.js`)]:[]]);f={enabled:!0,predownload:e,category:l}}const w=()=>e(this,void 0,void 0,(function*(){if(!f.enabled)throw new Error("Model does not have AR enabled.");if(ie===ne.AR)throw new Error("AR already launched.");const e=++re;if(ie===ne.Preview){const e=_();null==e||e.isPaused()||e.pause()}ie=ne.AR,a.vtoLaunched();const[,t]=yield f.predownload;if(re!==e)return;const n=k(c);try{yield n.init(u,f.category)}catch(e){throw a.vtoCameraDenied(e),e}re===e&&(yield n.parse(t),re===e&&n.resume())}));let m={enabled:!1};if(null!=h){const e=255,t=Promise.all([X(`${C}/shopar-three.js`),Y(h,(new Date).getTime()+e,Math.random()*e),B(`${C}/env/studio5.hdr`)]);m={enabled:!0,predownload:t}}const y=()=>e(this,void 0,void 0,(function*(){if(!m.enabled)throw new Error("Model does not have 3D enabled.");if(ie===ne.Preview)throw new Error("3D already launched.");const e=++re;if(ie===ne.AR){const e=L();null==e||e.isPaused()||e.pause()}ie=ne.Preview,a.previewLaunched();const[,t,n]=yield m.predownload;if(re!==e)return;const o=M(c,l);o.updateSize(),yield o.parse(t,n),re===e&&o.resume()}));return"AR"===r?yield w():"3D"===r&&(yield y()),{launchAR:w,launch3D:y,closeAR:()=>e(this,void 0,void 0,(function*(){if(ie!==ne.AR)throw new Error("AR not launched.");const e=L();null==e||e.isPaused()||e.pause(),ie=ne.None})),close3D:()=>e(this,void 0,void 0,(function*(){if(ie!==ne.Preview)throw new Error("3D not launched.");const e=_();null==e||e.isPaused()||e.pause(),ie=ne.None}))}}))}(t)}))}const ue={setup:function(t){return e(this,void 0,void 0,(function*(){return function(t,n){return e(this,void 0,void 0,(function*(){try{return n()}catch(e){throw e instanceof Error?new ue.PluginError(`${t} failed: ${e.message}`):(console.error(e),new ue.PluginError(`${t} failed.`))}}))}("setup",(()=>de(t)))}))},version:E,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};export{ue 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 s(e){try{c(o.next(e))}catch(e){r(e)}}function a(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;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],s=window[i[r[r[o]]]][i[r[r[r.length-1]]]],a=s.charCodeAt(o),c=a^a,l=new n[1]([c]);function d(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=h)throw t;return yield new Promise((e=>setTimeout(e,u[n]))),p(e,n+1)}}))}function f(e,n){return t(this,void 0,void 0,(function*(){const o=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:n,sid:d()})}`).catch((e=>{throw console.error(e),new Error("API unavailable.")}));if(!t.ok)throw new Error(`API call failed with status ${t.status}.`);return t}))));try{return yield o.json()}catch(e){throw console.error(e),new Error("API returned invalid body.")}}))}const v=["Glasses","Shoes","Watches"];function w(e){return null!=e&&v.includes(e)}let m;const g=()=>m,y=e=>(null==m&&(m=E(e)),m),E=e=>{let t=!1;const n=[];e.then((()=>{t=!0,n.forEach((e=>e()))}));const o=e=>{t?e():n.push(e)},i={organizationId:"Unknown",sku:"Unknown"};let r,s=0;function a(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),i),{vtoTime:(performance.now()-s)/1e3,vtoSessionId:r}),o((()=>{const{trackEventImpl:n}=window.ShopAR__analytics;n(e,t)}))}return{init:function(e,t){i.organizationId=e||"Unknown",i.sku=t||"Unknown",s=performance.now(),o((()=>{const{initializeImpl:e,uuidv4:t}=window.ShopAR__analytics;e(),r=t()}))},initialized:()=>a("initialized"),vtoLaunched:()=>a("vto_launched"),vtoCameraAsked:()=>a("vto_camera_asked"),vtoCameraGranted:()=>a("vto_camera_granted"),vtoCameraDenied:e=>a("vto_camera_denied",{error:e}),vtoInitSuccess:()=>a("vto_init_success"),previewLaunched:()=>a("preview_launched"),previewInteracted:()=>a("preview_interacted")}};const b="0.0.4";let C=`https://cdn.jsdelivr.net/npm/shopar-plugin@${b}/dist`;const A={update:e=>{null!=e&&(C=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>C},S=10;function R(e,n){return t(this,void 0,void 0,(function*(){const{ShopAR__TrueScale:o}=window;yield o.initialize(`${A}/wasm/mediapipe`,e);const i=[];setInterval((()=>t(this,void 0,void 0,(function*(){const{error:e,ipd:t}=yield o.predict(performance.now());if(null==e){!function(e,t){e.length>S&&e.splice(0,1);e.push(t)}(i,t);const e=62/(i.reduce(((e,t)=>t+e),0)/i.length);n.changeParameterVector("GLASSES","","scale",e,e,e,0),n.changeParameterVector("shopar_glasses","","scale",e,e,e,0)}}))),200)}))}function P(e,t,n){const o=null==e?void 0:e.querySelector(`#${t}`);if(null!=o)return o;const i=n();return null==e||e.appendChild(i),i}function $(e,t,n){const o=P(e,t,n),i=o.style;return{element:o,show:()=>{i.display=""},hide:()=>{i.display="none"}}}const L="shopar-deepar-output";function k(){const e=document.createElement("div");e.id=L;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}let x;const I=()=>x,U=e=>(null==x&&(x=D(e)),x),D=e=>{const n=g(),o=function(e){return P(e,L,k)}(e),i=o.style;let r,s;let a;let c=!0;return{domElement:o,init:(e,i)=>t(void 0,void 0,void 0,(function*(){const a=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i),c=function(e){var t;const n={Glasses:"user",Shoes:"environment",Watches:"environment"};return null==e?"user":null!==(t=n[e])&&void 0!==t?t:"user"}(i);return null==s&&(s=t(void 0,void 0,void 0,(function*(){if(null==(null===(s=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===s?void 0:s.getUserMedia))throw new Error("No camera available!");var s;const l=function(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}(c);n.vtoCameraAsked(),r=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:e||"your_license_key_goes_here",previewElement:o,additionalOptions:{hint:a,cameraConfig:{disableDefaultCamera:!0}}});const d=yield 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}))}(l);n.vtoCameraGranted(),yield function(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()}))))}}))}))}(r,d,"user"===c),"Glasses"===i&&R(d,r),n.vtoInitSuccess()}))),s})),parse:e=>t(void 0,void 0,void 0,(function*(){return null==a&&(a=r.switchEffect(e)),a})),isPaused:()=>c,resume:()=>{c=!1,r.setPaused(c),i.display=""},pause:()=>{c=!0,r.setPaused(c),i.display="none"}}};const _="shopar-three-output";function T(){const e=document.createElement("canvas");e.id=_;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",e}let M;const j=()=>M,N=(e,t)=>(null==M&&(M=z(e,t)),M),z=(e,n)=>{const o=g(),i=function(e){return P(e,_,T)}(e),r=i.style,s=window.ShopAR__THREE,a=s.THREE,c=new a.WebGLRenderer({powerPreference:"high-performance",canvas:i,antialias:!0,alpha:!0});c.outputEncoding=a.sRGBEncoding,c.toneMapping=a.ACESFilmicToneMapping,c.setPixelRatio(2*window.devicePixelRatio),c.setClearColor(new a.Color(16777215));const l=new a.PerspectiveCamera(25,1,.5),d=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);l.position.set(d[0],d[1],d[2]);const u=new a.Scene,h=new s.OrbitControls(l,c.domElement);h.target.set(0,.03,0),h.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>o.previewInteracted()),200);h.addEventListener("end",e)}{const e=new a.AmbientLight(new a.Color(16777215),.7),t=new a.RectAreaLight(new a.Color(16772574),10,50,50);t.position.set(-40,60,60);const n=new a.RectAreaLight(new a.Color(16774893),15,50,50);n.position.set(60,60,0),u.add(e,t,n)}const p=()=>{const e=i.clientWidth,t=i.clientHeight;i.width===e&&i.height===t||(c.setSize(e,t,!1),l.aspect=e/t,l.updateProjectionMatrix())};let f;let v=!1;const w=()=>{v||(requestAnimationFrame(w),p(),h.update(),c.render(u,l))};return{domElement:i,updateSize:p,parse:(e,n)=>t(void 0,void 0,void 0,(function*(){return null==f&&(f=t(void 0,void 0,void 0,(function*(){const t=new s.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}(s,t.parse(n));o.mapping=a.EquirectangularReflectionMapping,o.encoding=a.LinearEncoding,u.environment=o;const i=(new s.GLTFLoader).setDRACOLoader((new s.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${a.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new s.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${a.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(c)).setMeshoptDecoder("function"==typeof s.MeshoptDecoder?s.MeshoptDecoder():s.MeshoptDecoder),r=yield i.parseAsync(e.buffer,"");u.add(r.scene),u.traverse((e=>{if(e instanceof a.Mesh){const t=e.material;t.depthWrite=!0,t instanceof a.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),f})),isPaused:()=>v,resume:()=>{v=!1,w(),r.display=""},pause:()=>{v=!0,r.display="none"}}};function G(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 K="shopar-error";function O(){const e=document.createElement("div");e.id=K;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=G("4rem",`${A}/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 s=document.createElement("div");return s.className="shopar-error-body",s.textContent="Please refresh the page and allow the use of camera.",n.appendChild(s),e}function W(e,t){return P(e,t.id,(()=>function(e){const{id:t,iconUrl:n,textContent:o,ariaLabel:i}=e,r=document.createElement("button");if(r.id=t,r.type="button",r.className="shopar-btn",null!=n){const e=G("1.75rem",n);r.appendChild(e)}{const e=document.createElement("span");e.textContent=o,r.appendChild(e)}return r.ariaLabel=i,r.style.zIndex="2",r}(t)))}const F="shopar-control";function H(){const e=document.createElement("div");return e.id=F,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}const V="shopar-loading";function q(){const e=document.createElement("div");e.id=V;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}const B="shopar-main";function X(e){return P(e,B,Y)}function Y(){const e=document.createElement("div");e.id=B;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}function J(e){return t(this,void 0,void 0,(function*(){const n=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new Error("Resource unavailable.")}));if(!t.ok)throw new Error(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield n.blob()).arrayBuffer()}catch(e){throw console.error(e),new Error("Resource has invalid body.")}}))}function Q(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())}))}function Z(e,o,i){return t(this,void 0,void 0,(function*(){let r="glb".charCodeAt(0),s="3d".charCodeAt(0);r>>=1,r+=s;const a=String.fromCharCode(r+14);s>>=2,r^=s+2;const d=String.fromCharCode(r-3);r^=5;const u=String.fromCharCode(r-7);r^=2;const h=String.fromCharCode(r-7),f=window[`${u}${d+a+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${h}`],v=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield f(`${e}`).catch((()=>{throw new Error("Unknown error.")}));if(!t.ok)throw new Error("Unknown error.");return t})))),w=new n[0](yield(yield v.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));i+=s;const m=w.byteLength;if(l[c]=Math.min(76,o)*((r>>5)-1),152===l[c]&&(l[c]=m),i==c)return w;i=c,i^=c;for(let e=0,t=w.length;e<t;e++)l[c]^=l[i]<<13,l[c]^=l[i]>>17,l[c]^=l[i]<<5,w[e]=w[e]^l[c];return i^=l[0],i^=l[1],i^=l[2],w}))}function ee(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function te(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}const ne=["AR","3D"];function oe(e){const{apiKey:t,sku:n,targetElement:o,initialState:i,baseUrl:r,defaultUI:s}=e;ee(t,"apiKey"),te(t,"apiKey"),ee(n,"sku"),te(n,"sku"),ee(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,t,n){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`);if(!n.includes(e))throw new Error(`'${t}' must be ${n.join("' or '")}.`)}(i,"initialState",ne),null!=r&&te(r,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new Error(`'${t}' must be a boolean.`)}(s,"defaultUI")}function ie(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new Error(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}var re;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(re||(re={}));let se,ae=re.None,ce=0;const le=[];let de;function ue(){if(ae===re.AR){const e=I();null==e||e.isPaused()||e.pause()}else if(ae===re.Preview){const e=j();null==e||e.isPaused()||e.pause()}}function he(e){if(ae=e,ae===re.None){const e=le.filter((e=>null!=e));se.replaceChildren(...e)}else se.replaceChildren(de)}function pe(e){return t(this,void 0,void 0,(function*(){return oe(e),null==e.defaultUI||e.defaultUI?function(e){var n,o;return t(this,void 0,void 0,(function*(){const{apiKey:i,sku:r,targetElement:s,initialState:a}=e;ie(s),A.update(e.baseUrl);const c=f(i,r),l=y(Q(`${A}/shopar-analytics.js`));l.init(i,r),s.style.position="relative";const d=X(s);se=P(d,F,H),de=W(null,{id:"shopar-btn-close",textContent:"Close",ariaLabel:"Close ShopAR view",iconUrl:`${A}/img/icons/close.svg`}),de.onclick=()=>{u.hide(),h.hide(),ue(),he(re.None)};const u=function(e){return $(e,V,q)}(d),h=function(e){return $(e,K,O)}(d),{category:p,arUrl:v,arKey:m,previewUrl:g}=yield c;if(l.initialized(),null!=v&&w(p)){const e=Promise.all([Q(`${A}/shopar-deepar.js`),J(v),..."Glasses"===p?[Q(`${A}/shopar-true-scale.js`)]:[]]),n={Glasses:`${A}/img/icons/glasses.svg`,Shoes:`${A}/img/icons/shoe.svg`,Watches:`${A}/img/icons/watch.svg`},o=null!=p&&n[p]||n.Glasses;le[re.AR]=W(se,{id:"shopar-btn-vto",textContent:"Try-on",ariaLabel:"Launch ShopAR virtual try-on",iconUrl:o}),le[re.AR].onclick=()=>t(this,void 0,void 0,(function*(){const t=++ce,n=re.AR,o=ae===n?re.None:n;if(ue(),he(o),ae===re.None)return;l.vtoLaunched(),h.hide(),u.show();const[,i]=yield e;if(ce!==t)return;const r=U(d);try{yield r.init(m,p)}catch(e){return l.vtoCameraDenied(e),u.hide(),void h.show()}ce===t&&(yield r.parse(i),ce===t&&(r.resume(),u.hide()))}))}if(null!=g){const e=255,n=Promise.all([Q(`${A}/shopar-three.js`),Z(g,(new Date).getTime()+e,Math.random()*e),J(`${A}/env/studio5.hdr`)]);le[re.Preview]=W(se,{id:"shopar-btn-3d",textContent:"3D",ariaLabel:"Launch ShopAR 3D preview",iconUrl:`${A}/img/icons/cube.svg`}),le[re.Preview].onclick=()=>t(this,void 0,void 0,(function*(){const e=++ce,t=re.Preview,o=ae===t?re.None:t;if(ue(),he(o),ae===re.None)return;l.previewLaunched(),h.hide(),u.show();const[,i,r]=yield n;if(ce!==e)return;const s=N(d,p);s.updateSize(),yield s.parse(i,r),ce===e&&(s.resume(),u.hide())}))}"AR"===a?null===(n=le[re.AR])||void 0===n||n.click():"3D"===a&&(null===(o=le[re.Preview])||void 0===o||o.click())}))}(e):function(e){return t(this,void 0,void 0,(function*(){const{apiKey:n,sku:o,targetElement:i,initialState:r}=e;ie(i),A.update(e.baseUrl);const s=f(n,o),a=y(Q(`${A}/shopar-analytics.js`));a.init(n,o),i.style.position="relative";const c=X(i),{category:l,arUrl:d,arKey:u,previewUrl:h}=yield s;a.initialized();let p={enabled:!1};if(null!=d&&w(l)){const e=Promise.all([Q(`${A}/shopar-deepar.js`),J(d),..."Glasses"===l?[Q(`${A}/shopar-true-scale.js`)]:[]]);p={enabled:!0,predownload:e,category:l}}const v=()=>t(this,void 0,void 0,(function*(){if(!p.enabled)throw new Error("Model does not have AR enabled.");if(ae===re.AR)throw new Error("AR already launched.");const e=++ce;if(ae===re.Preview){const e=j();null==e||e.isPaused()||e.pause()}ae=re.AR,a.vtoLaunched();const[,t]=yield p.predownload;if(ce!==e)return;const n=U(c);try{yield n.init(u,p.category)}catch(e){throw a.vtoCameraDenied(e),e}ce===e&&(yield n.parse(t),ce===e&&n.resume())}));let m={enabled:!1};if(null!=h){const e=255,t=Promise.all([Q(`${A}/shopar-three.js`),Z(h,(new Date).getTime()+e,Math.random()*e),J(`${A}/env/studio5.hdr`)]);m={enabled:!0,predownload:t}}const g=()=>t(this,void 0,void 0,(function*(){if(!m.enabled)throw new Error("Model does not have AR enabled.");if(ae===re.Preview)throw new Error("3D already launched.");const e=++ce;if(ae===re.AR){const e=I();null==e||e.isPaused()||e.pause()}ae=re.Preview,a.previewLaunched();const[,t,n]=yield m.predownload;if(ce!==e)return;const o=N(c,l);o.updateSize(),yield o.parse(t,n),ce===e&&o.resume()}));return"AR"===r?yield v():"3D"===r&&(yield g()),{launchAR:v,launch3D:g,closeAR:()=>t(this,void 0,void 0,(function*(){if(ae!==re.AR)throw new Error("AR not launched.");const e=I();null==e||e.isPaused()||e.pause(),ae=re.None})),close3D:()=>t(this,void 0,void 0,(function*(){if(ae!==re.Preview)throw new Error("3D not launched.");const e=j();null==e||e.isPaused()||e.pause(),ae=re.None}))}}))}(e)}))}const fe={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,n){return t(this,void 0,void 0,(function*(){try{return n()}catch(t){throw t instanceof Error?new fe.PluginError(`${e} failed: ${t.message}`):(console.error(t),new fe.PluginError(`${e} failed.`))}}))}("setup",(()=>pe(e)))}))},version:b,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};e.plugin=fe}));
!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 s(e){try{c(o.next(e))}catch(e){r(e)}}function a(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;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],s=window[i[r[r[o]]]][i[r[r[r.length-1]]]],a=s.charCodeAt(o),c=a^a,l=new n[1]([c]);function d(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=h)throw t;return yield new Promise((e=>setTimeout(e,u[n]))),p(e,n+1)}}))}function f(e,n){return t(this,void 0,void 0,(function*(){const o=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:n,sid:d()})}`).catch((e=>{throw console.error(e),new Error("API unavailable.")}));if(!t.ok)throw new Error(`API call failed with status ${t.status}.`);return t}))));try{return yield o.json()}catch(e){throw console.error(e),new Error("API returned invalid body.")}}))}const v=["Glasses","Shoes","Watches"];function w(e){return null!=e&&v.includes(e)}let m;const g=()=>m,y=e=>(null==m&&(m=E(e)),m),E=e=>{let t=!1;const n=[];e.then((()=>{t=!0,n.forEach((e=>e()))}));const o=e=>{t?e():n.push(e)},i={organizationId:"Unknown",sku:"Unknown"};let r,s=0;function a(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),i),{vtoTime:(performance.now()-s)/1e3,vtoSessionId:r}),o((()=>{const{trackEventImpl:n}=window.ShopAR__analytics;n(e,t)}))}return{init:function(e,t){i.organizationId=e||"Unknown",i.sku=t||"Unknown",s=performance.now(),o((()=>{const{initializeImpl:e,uuidv4:t}=window.ShopAR__analytics;e(),r=t()}))},initialized:()=>a("initialized"),vtoLaunched:()=>a("vto_launched"),vtoCameraAsked:()=>a("vto_camera_asked"),vtoCameraGranted:()=>a("vto_camera_granted"),vtoCameraDenied:e=>a("vto_camera_denied",{error:e}),vtoInitSuccess:()=>a("vto_init_success"),previewLaunched:()=>a("preview_launched"),previewInteracted:()=>a("preview_interacted")}};const b="0.0.5-alpha.0";let C=`https://cdn.jsdelivr.net/npm/shopar-plugin@${b}/dist`;const A={update:e=>{null!=e&&(C=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>C};function S(e,t,n){const o=null==e?void 0:e.querySelector(`#${t}`);if(null!=o)return o;const i=n();return null==e||e.appendChild(i),i}function P(e,t,n){const o=S(e,t,n),i=o.style;return{element:o,show:()=>{i.display=""},hide:()=>{i.display="none"}}}const R="shopar-deepar-output";function $(){const e=document.createElement("div");e.id=R;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}let L;const k=()=>L,I=e=>(null==L&&(L=x(e)),L),x=e=>{const n=g(),o=function(e){return S(e,R,$)}(e),i=o.style;let r,s;let a;let c=!0;return{domElement:o,init:(e,i)=>t(void 0,void 0,void 0,(function*(){const a=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i),c=function(e){var t;const n={Glasses:"user",Shoes:"environment",Watches:"environment"};return null==e?"user":null!==(t=n[e])&&void 0!==t?t:"user"}(i);return null==s&&(s=t(void 0,void 0,void 0,(function*(){if(null==(null===(s=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===s?void 0:s.getUserMedia))throw new Error("No camera available!");var s;const l=function(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}(c);n.vtoCameraAsked(),r=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:e||"your_license_key_goes_here",previewElement:o,additionalOptions:{hint:a,cameraConfig:{disableDefaultCamera:!0}}});const d=yield 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}))}(l);n.vtoCameraGranted(),yield function(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()}))))}}))}))}(r,d,"user"===c),"Glasses"===i&&function(e,n){t(this,void 0,void 0,(function*(){const{ShopAR__TrueScale:o}=window;yield o.initialize(`${A}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>t(this,void 0,void 0,(function*(){const{error:e,faceWidth:t}=yield o.predict(performance.now());if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<10)return void i.push(t);clearInterval(r);const s=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",s,s,s,0),n.changeParameterVector("shopar_glasses","","scale",s,s,s,0)}))),200)}))}(d,r),n.vtoInitSuccess()}))),s})),parse:e=>t(void 0,void 0,void 0,(function*(){return null==a&&(a=r.switchEffect(e)),a})),isPaused:()=>c,resume:()=>{c=!1,r.setPaused(c),i.display=""},pause:()=>{c=!0,r.setPaused(c),i.display="none"}}};const U="shopar-three-output";function D(){const e=document.createElement("canvas");e.id=U;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",e}let T;const _=()=>T,M=(e,t)=>(null==T&&(T=j(e,t)),T),j=(e,n)=>{const o=g(),i=function(e){return S(e,U,D)}(e),r=i.style,s=window.ShopAR__THREE,a=s.THREE,c=new a.WebGLRenderer({powerPreference:"high-performance",canvas:i,antialias:!0,alpha:!0});c.outputEncoding=a.sRGBEncoding,c.toneMapping=a.ACESFilmicToneMapping,c.setPixelRatio(2*window.devicePixelRatio),c.setClearColor(new a.Color(16777215));const l=new a.PerspectiveCamera(25,1,.5),d=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);l.position.set(d[0],d[1],d[2]);const u=new a.Scene,h=new s.OrbitControls(l,c.domElement);h.target.set(0,.03,0),h.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>o.previewInteracted()),200);h.addEventListener("end",e)}{const e=new a.AmbientLight(new a.Color(16777215),.7),t=new a.RectAreaLight(new a.Color(16772574),10,50,50);t.position.set(-40,60,60);const n=new a.RectAreaLight(new a.Color(16774893),15,50,50);n.position.set(60,60,0),u.add(e,t,n)}const p=()=>{const e=i.clientWidth,t=i.clientHeight;i.width===e&&i.height===t||(c.setSize(e,t,!1),l.aspect=e/t,l.updateProjectionMatrix())};let f;let v=!1;const w=()=>{v||(requestAnimationFrame(w),p(),h.update(),c.render(u,l))};return{domElement:i,updateSize:p,parse:(e,n)=>t(void 0,void 0,void 0,(function*(){return null==f&&(f=t(void 0,void 0,void 0,(function*(){const t=new s.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}(s,t.parse(n));o.mapping=a.EquirectangularReflectionMapping,o.encoding=a.LinearEncoding,u.environment=o;const i=(new s.GLTFLoader).setDRACOLoader((new s.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${a.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new s.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${a.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(c)).setMeshoptDecoder("function"==typeof s.MeshoptDecoder?s.MeshoptDecoder():s.MeshoptDecoder),r=yield i.parseAsync(e.buffer,"");u.add(r.scene),u.traverse((e=>{if(e instanceof a.Mesh){const t=e.material;t.depthWrite=!0,t instanceof a.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),f})),isPaused:()=>v,resume:()=>{v=!1,w(),r.display=""},pause:()=>{v=!0,r.display="none"}}};function N(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 z="shopar-error";function G(){const e=document.createElement("div");e.id=z;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=N("4rem",`${A}/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 s=document.createElement("div");return s.className="shopar-error-body",s.textContent="Please refresh the page and allow the use of camera.",n.appendChild(s),e}function W(e,t){return S(e,t.id,(()=>function(e){const{id:t,iconUrl:n,textContent:o,ariaLabel:i}=e,r=document.createElement("button");if(r.id=t,r.type="button",r.className="shopar-btn",null!=n){const e=N("1.75rem",n);r.appendChild(e)}{const e=document.createElement("span");e.textContent=o,r.appendChild(e)}return r.ariaLabel=i,r.style.zIndex="2",r}(t)))}const K="shopar-control";function O(){const e=document.createElement("div");return e.id=K,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}const F="shopar-loading";function H(){const e=document.createElement("div");e.id=F;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}const V="shopar-main";function q(e){return S(e,V,B)}function B(){const e=document.createElement("div");e.id=V;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}function X(e){return t(this,void 0,void 0,(function*(){const n=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new Error("Resource unavailable.")}));if(!t.ok)throw new Error(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield n.blob()).arrayBuffer()}catch(e){throw console.error(e),new Error("Resource has invalid body.")}}))}function Y(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())}))}function J(e,o,i){return t(this,void 0,void 0,(function*(){let r="glb".charCodeAt(0),s="3d".charCodeAt(0);r>>=1,r+=s;const a=String.fromCharCode(r+14);s>>=2,r^=s+2;const d=String.fromCharCode(r-3);r^=5;const u=String.fromCharCode(r-7);r^=2;const h=String.fromCharCode(r-7),f=window[`${u}${d+a+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${h}`],v=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield f(`${e}`).catch((()=>{throw new Error("Unknown error.")}));if(!t.ok)throw new Error("Unknown error.");return t})))),w=new n[0](yield(yield v.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));i+=s;const m=w.byteLength;if(l[c]=Math.min(76,o)*((r>>5)-1),152===l[c]&&(l[c]=m),i==c)return w;i=c,i^=c;for(let e=0,t=w.length;e<t;e++)l[c]^=l[i]<<13,l[c]^=l[i]>>17,l[c]^=l[i]<<5,w[e]=w[e]^l[c];return i^=l[0],i^=l[1],i^=l[2],w}))}function Q(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function Z(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}const ee=["AR","3D"];function te(e){const{apiKey:t,sku:n,targetElement:o,initialState:i,baseUrl:r,defaultUI:s}=e;Q(t,"apiKey"),Z(t,"apiKey"),Q(n,"sku"),Z(n,"sku"),Q(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,t,n){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`);if(!n.includes(e))throw new Error(`'${t}' must be ${n.join("' or '")}.`)}(i,"initialState",ee),null!=r&&Z(r,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new Error(`'${t}' must be a boolean.`)}(s,"defaultUI")}function ne(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new Error(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}var oe;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(oe||(oe={}));let ie,re=oe.None,se=0;const ae=[];let ce;function le(){if(re===oe.AR){const e=k();null==e||e.isPaused()||e.pause()}else if(re===oe.Preview){const e=_();null==e||e.isPaused()||e.pause()}}function de(e){if(re=e,re===oe.None){const e=ae.filter((e=>null!=e));ie.replaceChildren(...e)}else ie.replaceChildren(ce)}function ue(e){return t(this,void 0,void 0,(function*(){return te(e),null==e.defaultUI||e.defaultUI?function(e){var n,o;return t(this,void 0,void 0,(function*(){const{apiKey:i,sku:r,targetElement:s,initialState:a}=e;ne(s),A.update(e.baseUrl);const c=f(i,r),l=y(Y(`${A}/shopar-analytics.js`));l.init(i,r),s.style.position="relative";const d=q(s);ie=S(d,K,O),ce=W(null,{id:"shopar-btn-close",textContent:"Close",ariaLabel:"Close ShopAR view",iconUrl:`${A}/img/icons/close.svg`}),ce.onclick=()=>{u.hide(),h.hide(),le(),de(oe.None)};const u=function(e){return P(e,F,H)}(d),h=function(e){return P(e,z,G)}(d),{category:p,arUrl:v,arKey:m,previewUrl:g}=yield c;if(l.initialized(),null!=v&&w(p)){const e=Promise.all([Y(`${A}/shopar-deepar.js`),X(v),..."Glasses"===p?[Y(`${A}/shopar-true-scale.js`)]:[]]),n={Glasses:`${A}/img/icons/glasses.svg`,Shoes:`${A}/img/icons/shoe.svg`,Watches:`${A}/img/icons/watch.svg`},o=null!=p&&n[p]||n.Glasses;ae[oe.AR]=W(ie,{id:"shopar-btn-vto",textContent:"Try-on",ariaLabel:"Launch ShopAR virtual try-on",iconUrl:o}),ae[oe.AR].onclick=()=>t(this,void 0,void 0,(function*(){const t=++se,n=oe.AR,o=re===n?oe.None:n;if(le(),de(o),re===oe.None)return;l.vtoLaunched(),h.hide(),u.show();const[,i]=yield e;if(se!==t)return;const r=I(d);try{yield r.init(m,p)}catch(e){return l.vtoCameraDenied(e),u.hide(),void h.show()}se===t&&(yield r.parse(i),se===t&&(r.resume(),u.hide()))}))}if(null!=g){const e=255,n=Promise.all([Y(`${A}/shopar-three.js`),J(g,(new Date).getTime()+e,Math.random()*e),X(`${A}/env/studio5.hdr`)]);ae[oe.Preview]=W(ie,{id:"shopar-btn-3d",textContent:"3D",ariaLabel:"Launch ShopAR 3D preview",iconUrl:`${A}/img/icons/cube.svg`}),ae[oe.Preview].onclick=()=>t(this,void 0,void 0,(function*(){const e=++se,t=oe.Preview,o=re===t?oe.None:t;if(le(),de(o),re===oe.None)return;l.previewLaunched(),h.hide(),u.show();const[,i,r]=yield n;if(se!==e)return;const s=M(d,p);s.updateSize(),yield s.parse(i,r),se===e&&(s.resume(),u.hide())}))}"AR"===a?null===(n=ae[oe.AR])||void 0===n||n.click():"3D"===a&&(null===(o=ae[oe.Preview])||void 0===o||o.click())}))}(e):function(e){return t(this,void 0,void 0,(function*(){const{apiKey:n,sku:o,targetElement:i,initialState:r}=e;ne(i),A.update(e.baseUrl);const s=f(n,o),a=y(Y(`${A}/shopar-analytics.js`));a.init(n,o),i.style.position="relative";const c=q(i),{category:l,arUrl:d,arKey:u,previewUrl:h}=yield s;a.initialized();let p={enabled:!1};if(null!=d&&w(l)){const e=Promise.all([Y(`${A}/shopar-deepar.js`),X(d),..."Glasses"===l?[Y(`${A}/shopar-true-scale.js`)]:[]]);p={enabled:!0,predownload:e,category:l}}const v=()=>t(this,void 0,void 0,(function*(){if(!p.enabled)throw new Error("Model does not have AR enabled.");if(re===oe.AR)throw new Error("AR already launched.");const e=++se;if(re===oe.Preview){const e=_();null==e||e.isPaused()||e.pause()}re=oe.AR,a.vtoLaunched();const[,t]=yield p.predownload;if(se!==e)return;const n=I(c);try{yield n.init(u,p.category)}catch(e){throw a.vtoCameraDenied(e),e}se===e&&(yield n.parse(t),se===e&&n.resume())}));let m={enabled:!1};if(null!=h){const e=255,t=Promise.all([Y(`${A}/shopar-three.js`),J(h,(new Date).getTime()+e,Math.random()*e),X(`${A}/env/studio5.hdr`)]);m={enabled:!0,predownload:t}}const g=()=>t(this,void 0,void 0,(function*(){if(!m.enabled)throw new Error("Model does not have 3D enabled.");if(re===oe.Preview)throw new Error("3D already launched.");const e=++se;if(re===oe.AR){const e=k();null==e||e.isPaused()||e.pause()}re=oe.Preview,a.previewLaunched();const[,t,n]=yield m.predownload;if(se!==e)return;const o=M(c,l);o.updateSize(),yield o.parse(t,n),se===e&&o.resume()}));return"AR"===r?yield v():"3D"===r&&(yield g()),{launchAR:v,launch3D:g,closeAR:()=>t(this,void 0,void 0,(function*(){if(re!==oe.AR)throw new Error("AR not launched.");const e=k();null==e||e.isPaused()||e.pause(),re=oe.None})),close3D:()=>t(this,void 0,void 0,(function*(){if(re!==oe.Preview)throw new Error("3D not launched.");const e=_();null==e||e.isPaused()||e.pause(),re=oe.None}))}}))}(e)}))}const he={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,n){return t(this,void 0,void 0,(function*(){try{return n()}catch(t){throw t instanceof Error?new he.PluginError(`${e} failed: ${t.message}`):(console.error(t),new he.PluginError(`${e} failed.`))}}))}("setup",(()=>ue(e)))}))},version:b,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};e.plugin=he}));
{
"name": "shopar-plugin",
"version": "0.0.4",
"version": "0.0.5-alpha.0",
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",

@@ -38,3 +38,3 @@ "scripts": {

"@mediapipe/tasks-vision": "^0.10.7",
"deepar": "5.4.1",
"deepar": "5.4.5-obj-fix-alpha-84",
"three": "0.151.3",

@@ -41,0 +41,0 @@ "uuid": "^9.0.1"

@@ -35,3 +35,3 @@ # ShopAR Plugin

```html
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.4/dist/shopar-plugin.js"></script>
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@{{VERSION}}/dist/shopar-plugin.js"></script>
```

@@ -121,3 +121,3 @@

- If provided, defines where the additional ShopAR plugin files are fetched from.
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.4/dist`
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@{{VERSION}}/dist`

@@ -124,0 +124,0 @@ ## License

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc