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.5-alpha.4 to 0.0.5-alpha.5

58

dist/shopar-plugin.d.ts

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

/// <reference types="node" />
/** Preview state values. */

@@ -48,2 +47,38 @@ declare const PREVIEW_STATE: readonly ["AR", "3D"];

/**
* Plugin controller.
*/
type Plugin = {
/**
* Launches the AR view.
*
* @returns A promise that resolves when AR is launched.
*/
launchAR: () => Promise<void>;
/**
* Launches the 3D view.
*
* @returns A promise that resolves when 3D is launched.
*/
launch3D: () => Promise<void>;
/**
* Closes the AR view.
*
* @returns A promise that resolves when AR is closed.
*/
closeAR: () => Promise<void>;
/**
* Closes the 3D view.
*
* @returns A promise that resolves when 3D is closed.
*/
close3D: () => Promise<void>;
/**
* Closes the AR or 3D view.
*
* @returns A promise that resolves when AR or 3D is closed.
*/
close: () => Promise<void>;
};
/**
* The ShopAR plugin.

@@ -74,26 +109,7 @@ *

*/
setup: (options: SetupOptions) => Promise<{
launchAR: () => Promise<void>;
launch3D: () => Promise<void>;
closeAR: () => Promise<void>;
close3D: () => Promise<void>;
close: () => Promise<void>;
}>;
setup: (options: SetupOptions) => Promise<Plugin>;
/** Plugin version. */
version: string;
/**
* Thrown when an unrecoverable plugin error happens.
*/
PluginError: {
new (message: string): {
name: string;
message: string;
stack?: string | undefined;
};
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
stackTraceLimit: number;
};
};
export { plugin };

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

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

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

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

@@ -5,0 +5,0 @@ "scripts": {

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