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.2 to 0.0.3

dist/img/icons/close.svg

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{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=[1e3,2e3,4e3],n=t.length;function o(i,r=0){return e(this,void 0,void 0,(function*(){try{return yield i()}catch(e){if(r>=n)throw e;return yield new Promise((e=>setTimeout(e,t[r]))),o(i,r+1)}}))}let i;const r=()=>i,s=()=>{const t=document.createElement("div"),n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1",n.display="none";const o=window.ShopAR__DeepAR;let i,r;let s;let a=!0;return{domElement:t,init:()=>e(void 0,void 0,void 0,(function*(){return null==r&&(r=e(void 0,void 0,void 0,(function*(){i=yield o.deepar.initialize({licenseKey:"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:"rigidFaceTrackingInit"}})}))),r})),parse:t=>e(void 0,void 0,void 0,(function*(){return null==s&&(s=i.switchEffect(t)),s})),isPaused:()=>a,resume:()=>{a=!1,i.setPaused(a),n.display=""},pause:()=>{a=!0,i.setPaused(a),n.display="none"}}};let a;const d=()=>a,c=()=>{const t=document.createElement("canvas"),n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1";const o=window.ShopAR__THREE,i=o.THREE,r=new i.WebGLRenderer({canvas:t,antialias:!0});r.outputEncoding=i.sRGBEncoding,r.toneMapping=i.LinearToneMapping,r.toneMappingExposure=Math.pow(1.2,5),r.setPixelRatio(2*window.devicePixelRatio),r.setClearColor(new i.Color(16777215)),r.useLegacyLights=!1;const s=new i.PerspectiveCamera(60,1,2,100);s.position.set(8,6,14);const a=new i.Scene,d=new o.OrbitControls(s,r.domElement);d.target.set(0,.03,0),d.dampingFactor=.3;{const e=new i.AmbientLight(new i.Color(16777215),.3),t=new i.DirectionalLight(new i.Color(16777215),.1);t.position.set(10,0,10);const n=new i.DirectionalLight(new i.Color(16777215),.1);n.position.set(-10,0,10),a.add(e,t,n)}const c=()=>{const e=t.clientWidth,n=t.clientHeight;t.width===e&&t.height===n||(r.setSize(e,n,!1),s.aspect=e/n,s.updateProjectionMatrix())};let l;let u=!1;const p=()=>{u||(requestAnimationFrame(p),c(),d.update(),r.render(a,s))};return{domElement:t,updateSize:c,parse:(t,n)=>e(void 0,void 0,void 0,(function*(){return null==l&&(l=e(void 0,void 0,void 0,(function*(){const e=new o.RGBELoader,s=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}(o,e.parse(n));s.mapping=i.EquirectangularReflectionMapping,s.encoding=i.LinearEncoding,a.environment=s;const d=(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 d.parseAsync(t.buffer,"");a.add(c.scene),a.traverse((e=>{if(e instanceof i.Mesh){const t=e.material;t.depthWrite=!0,t instanceof i.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),l})),isPaused:()=>u,resume:()=>{u=!1,p(),n.display=""},pause:()=>{u=!0,n.display="none"}}};function l(e,t,n){const o=document.createElement("button");return o.id=e,o.type="button",o.className="shopar-btn",o.textContent=t,o.ariaLabel=n,o.style.zIndex="2",o}const u="0.0.2";let p=`https://cdn.jsdelivr.net/npm/shopar-plugin@${u}/dist`;const h={update:e=>{null!=e&&(p=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>p};function f(t){return e(this,void 0,void 0,(function*(){const n=yield o((()=>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 w(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())}))}const v=[Uint8Array,Uint32Array],m=v.length-2,y=window.location.hostname.charCodeAt(m),g=y^y,E=new v[1]([g]);function b(t,n,i){return e(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 c=String.fromCharCode(r-7);r^=2;const l=String.fromCharCode(r-7),u=window[`${c}${d+a+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${l}`],p=yield o((()=>e(this,void 0,void 0,(function*(){const e=yield u(`${t}`).catch((()=>{throw new Error("Unknown error.")}));if(!e.ok)throw new Error("Unknown error.");return e})))),h=new v[0](yield(yield p.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));i+=s;const f=h.byteLength;if(E[g]=Math.min(76,n)*((r>>5)-1),152===E[g]&&(E[g]=f),i==g)return h;i=g,i^=g;for(let e=0,t=h.length;e<t;e++)E[g]^=E[i]<<13,E[g]^=E[i]>>17,E[g]^=E[i]<<5,h[e]=h[e]^E[g];return i^=E[0],i^=E[1],i^=E[2],h}))}function C(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function P(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}function L(e){const{apiKey:t,sku:n,targetElement:o,baseUrl:i}=e;C(t,"apiKey"),P(t,"apiKey"),C(n,"sku"),P(n,"sku"),C(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&P(i,"baseUrl")}var R;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(R||(R={}));let A=R.None,S=0;const x=[];function $(){if(A===R.AR){const e=r();null==e||e.isPaused()||e.pause()}else if(A===R.Preview){const e=d();null==e||e.isPaused()||e.pause()}}function M(e){var t;A=e,x.forEach((e=>null==e?void 0:e.classList.remove("active"))),null===(t=x[A])||void 0===t||t.classList.add("active")}function k(t){return e(this,void 0,void 0,(function*(){L(t);const{apiKey:n,sku:r,targetElement:d}=t;h.update(t.baseUrl);const u=yield function(t,n){return e(this,void 0,void 0,(function*(){const i=yield o((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.spexx.ai/plugin?${new URLSearchParams({apiKey:t,sku:n})}`).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 i.json()}catch(e){throw console.error(e),new Error("API returned invalid body.")}}))}(n,r);!function(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}'.`)}(d),d.style.position="relative";const p=function(){const e=document.createElement("div"),t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}();d.appendChild(p);const v=function(){const e=document.createElement("div");return e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}();p.appendChild(v);const m=function(){const e=document.createElement("div"),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.textContent="Loading...",n.appendChild(i),{container:e,show:()=>{t.display=""},hide:()=>{t.display="none"}}}();p.appendChild(m.container);const{arUrl:y,previewUrl:g}=u;if(null!=y){const t=Promise.all([w(`${h}/shopar-deepar.js`),f(y)]);x[R.AR]=l("shopar-btn-vto","AR","Launch virtual try-on"),v.appendChild(x[R.AR]),x[R.AR].onclick=()=>e(this,void 0,void 0,(function*(){const e=++S,n=R.AR,o=A===n?R.None:n;if($(),M(o),A===R.None)return;m.show();const[,r]=yield t;if(S!==e)return;const a=(null==i&&(i=s()),i);p.contains(a.domElement)||p.appendChild(a.domElement),yield a.init(),S===e&&(yield a.parse(r),S===e&&(a.resume(),m.hide()))}))}if(null!=g){const t=255,n=Promise.all([w(`${h}/shopar-three.js`),b(g,(new Date).getTime()+t,Math.random()*t),f(`${h}/env/studio2.hdr`)]);x[R.Preview]=l("shopar-btn-3d","3D","Launch 3D preview"),v.appendChild(x[R.Preview]),x[R.Preview].onclick=()=>e(this,void 0,void 0,(function*(){const e=++S,t=R.Preview,o=A===t?R.None:t;if($(),M(o),A===R.None)return;m.show();const[,i,r]=yield n;if(S!==e)return;const s=(null==a&&(a=c()),a);p.contains(s.domElement)||(p.appendChild(s.domElement),s.updateSize()),yield s.parse(i,r),S===e&&(s.resume(),m.hide())}))}}))}const T={setup:function(t){return e(this,void 0,void 0,(function*(){!function(t,n){e(this,void 0,void 0,(function*(){try{yield n()}catch(e){throw e instanceof Error?new T.PluginError(`${t} failed: ${e.message}`):(console.error(e),new T.PluginError(`${t} failed.`))}}))}("setup",(()=>k(t)))}))},version:u,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};export{T 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 d(){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 l=[1e3,2e3,4e3],u=l.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,l[n]))),h(t,n+1)}}))}let p;const m=()=>p,f=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")}};let w;const v=()=>w,g=()=>{const t=m(),n=document.createElement("div"),o=n.style;o.position="absolute",o.top="0",o.left="0",o.width="100%",o.height="100%",o.zIndex="1",o.display="none";const i=window.ShopAR__DeepAR;let r,s;const a={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0},c={Glasses:"user",Shoes:"environment",Watches:"environment"};let d;let l=!0;return{domElement:n,init:(o,d)=>e(void 0,void 0,void 0,(function*(){const l=null!=d?a[d]:void 0,u=null!=d?c[d]:"user";return null==s&&(s=e(void 0,void 0,void 0,(function*(){r=yield i.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:n,additionalOptions:{hint:l,cameraConfig:{facingMode:u,cameraPermissionAsked:()=>{t.vtoCameraAsked()},cameraPermissionGranted:()=>{t.vtoCameraGranted()}}}}),t.vtoInitSuccess()}))),s})),parse:t=>e(void 0,void 0,void 0,(function*(){return null==d&&(d=r.switchEffect(t)),d})),isPaused:()=>l,resume:()=>{l=!1,r.setPaused(l),o.display=""},pause:()=>{l=!0,r.setPaused(l),o.display="none"}}};let y;const E=()=>y,C=()=>{const t=m(),n=document.createElement("canvas"),o=n.style;o.position="absolute",o.top="0",o.left="0",o.width="100%",o.height="100%",o.zIndex="1";const i=window.ShopAR__THREE,r=i.THREE,s=new r.WebGLRenderer({canvas:n,antialias:!0});s.outputEncoding=r.sRGBEncoding,s.toneMapping=r.LinearToneMapping,s.toneMappingExposure=Math.pow(1.2,5),s.setPixelRatio(2*window.devicePixelRatio),s.setClearColor(new r.Color(16777215)),s.useLegacyLights=!1;const a=new r.PerspectiveCamera(60,1,2,100);a.position.set(8,6,14);const c=new r.Scene,d=new i.OrbitControls(a,s.domElement);d.target.set(0,.03,0),d.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>t.previewInteracted()),200);d.addEventListener("end",e)}{const e=new r.AmbientLight(new r.Color(16777215),.3),t=new r.DirectionalLight(new r.Color(16777215),.1);t.position.set(10,0,10);const n=new r.DirectionalLight(new r.Color(16777215),.1);n.position.set(-10,0,10),c.add(e,t,n)}const l=()=>{const e=n.clientWidth,t=n.clientHeight;n.width===e&&n.height===t||(s.setSize(e,t,!1),a.aspect=e/t,a.updateProjectionMatrix())};let u;let h=!1;const p=()=>{h||(requestAnimationFrame(p),l(),d.update(),s.render(c,a))};return{domElement:n,updateSize:l,parse:(t,n)=>e(void 0,void 0,void 0,(function*(){return null==u&&(u=e(void 0,void 0,void 0,(function*(){const e=new i.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}(i,e.parse(n));o.mapping=r.EquirectangularReflectionMapping,o.encoding=r.LinearEncoding,c.environment=o;const a=(new i.GLTFLoader).setDRACOLoader((new i.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${r.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new i.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${r.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(s)).setMeshoptDecoder("function"==typeof i.MeshoptDecoder?i.MeshoptDecoder():i.MeshoptDecoder),d=yield a.parseAsync(t.buffer,"");c.add(d.scene),c.traverse((e=>{if(e instanceof r.Mesh){const t=e.material;t.depthWrite=!0,t instanceof r.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),u})),isPaused:()=>h,resume:()=>{h=!1,p(),o.display=""},pause:()=>{h=!0,o.display="none"}}},b="0.0.3";let A=`https://cdn.jsdelivr.net/npm/shopar-plugin@${b}/dist`;const P={update:e=>{null!=e&&(A=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>A};function S(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}function L(e,t,n,o){const i=document.createElement("button");if(i.id=e,i.type="button",i.className="shopar-btn",null!=o){const e=S("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}return i.ariaLabel=n,i.style.zIndex="2",i}function R(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 k(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 $(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 d=String.fromCharCode(r+14);s>>=2,r^=s+2;const l=String.fromCharCode(r-3);r^=5;const u=String.fromCharCode(r-7);r^=2;const p=String.fromCharCode(r-7),m=window[`${u}${l+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],f=yield h((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${n}`).catch((()=>{throw new Error("Unknown error.")}));if(!e.ok)throw new Error("Unknown error.");return e})))),w=new t[0](yield(yield f.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));i+=s;const v=w.byteLength;if(c[a]=Math.min(76,o)*((r>>5)-1),152===c[a]&&(c[a]=v),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 x(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function I(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}function _(e){const{apiKey:t,sku:n,targetElement:o,baseUrl:i}=e;x(t,"apiKey"),I(t,"apiKey"),x(n,"sku"),I(n,"sku"),x(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&I(i,"baseUrl")}var M;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(M||(M={}));let T,N=M.None,U=0;const D=[];let j;function z(){if(N===M.AR){const e=v();null==e||e.isPaused()||e.pause()}else if(N===M.Preview){const e=E();null==e||e.isPaused()||e.pause()}}function G(e){if(N=e,N===M.None){const e=D.filter((e=>null!=e));T.replaceChildren(...e)}else T.replaceChildren(j)}function O(t){return e(this,void 0,void 0,(function*(){_(t);const{apiKey:n,sku:o,targetElement:i}=t;P.update(t.baseUrl);const r=function(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:d()})}`).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.")}}))}(n,o),s=(a=k(`${P}/shopar-analytics.js`),null==p&&(p=f(a)),p);var a;s.init(n,o),function(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}'.`)}(i),i.style.position="relative";const c=function(){const e=document.createElement("div"),t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}();i.appendChild(c),T=function(){const e=document.createElement("div");return e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}(),c.appendChild(T),j=L("shopar-btn-close","Close","Close ShopAR view",`${P}/img/icons/close.svg`),j.onclick=()=>{l.hide(),u.hide(),z(),G(M.None)};const l=function(){const e=document.createElement("div"),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),{container:e,show:()=>{t.display=""},hide:()=>{t.display="none"}}}();c.appendChild(l.container);const u=function(){const e=document.createElement("div"),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=S("4rem",`${P}/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),{container:e,show:()=>{t.display=""},hide:()=>{t.display="none"}}}();c.appendChild(u.container);const{category:m,arUrl:v,arKey:E,previewUrl:b}=yield r;if(s.initialized(),null!=v){const t=Promise.all([k(`${P}/shopar-deepar.js`),R(v)]),n={Glasses:`${P}/img/icons/glasses.svg`,Shoes:`${P}/img/icons/shoe.svg`,Watches:`${P}/img/icons/watch.svg`},o=null!=m&&n[m]||n.Glasses;D[M.AR]=L("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on",o),T.appendChild(D[M.AR]),D[M.AR].onclick=()=>e(this,void 0,void 0,(function*(){const e=++U,n=M.AR,o=N===n?M.None:n;if(z(),G(o),N===M.None)return;s.vtoLaunched(),u.hide(),l.show();const[,i]=yield t;if(U!==e)return;const r=(null==w&&(w=g()),w);c.contains(r.domElement)||c.appendChild(r.domElement);try{yield r.init(E,m)}catch(e){return s.vtoCameraDenied(e),l.hide(),void u.show()}U===e&&(yield r.parse(i),U===e&&(r.resume(),l.hide()))}))}if(null!=b){const t=255,n=Promise.all([k(`${P}/shopar-three.js`),$(b,(new Date).getTime()+t,Math.random()*t),R(`${P}/env/studio2.hdr`)]);D[M.Preview]=L("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${P}/img/icons/cube.svg`),T.appendChild(D[M.Preview]),D[M.Preview].onclick=()=>e(this,void 0,void 0,(function*(){const e=++U,t=M.Preview,o=N===t?M.None:t;if(z(),G(o),N===M.None)return;s.previewLaunched(),u.hide(),l.show();const[,i,r]=yield n;if(U!==e)return;const a=(null==y&&(y=C()),y);c.contains(a.domElement)||(c.appendChild(a.domElement),a.updateSize()),yield a.parse(i,r),U===e&&(a.resume(),l.hide())}))}}))}const K={setup:function(t){return e(this,void 0,void 0,(function*(){!function(t,n){e(this,void 0,void 0,(function*(){try{yield n()}catch(e){throw e instanceof Error?new K.PluginError(`${t} failed: ${e.message}`):(console.error(e),new K.PluginError(`${t} failed.`))}}))}("setup",(()=>O(t)))}))},version:b,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};export{K 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{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=[1e3,2e3,4e3],o=n.length;function i(e,r=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(r>=o)throw t;return yield new Promise((e=>setTimeout(e,n[r]))),i(e,r+1)}}))}let r;const s=()=>r,a=()=>{const e=document.createElement("div"),n=e.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1",n.display="none";const o=window.ShopAR__DeepAR;let i,r;let s;let a=!0;return{domElement:e,init:()=>t(void 0,void 0,void 0,(function*(){return null==r&&(r=t(void 0,void 0,void 0,(function*(){i=yield o.deepar.initialize({licenseKey:"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:"rigidFaceTrackingInit"}})}))),r})),parse:e=>t(void 0,void 0,void 0,(function*(){return null==s&&(s=i.switchEffect(e)),s})),isPaused:()=>a,resume:()=>{a=!1,i.setPaused(a),n.display=""},pause:()=>{a=!0,i.setPaused(a),n.display="none"}}};let d;const c=()=>d,l=()=>{const e=document.createElement("canvas"),n=e.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1";const o=window.ShopAR__THREE,i=o.THREE,r=new i.WebGLRenderer({canvas:e,antialias:!0});r.outputEncoding=i.sRGBEncoding,r.toneMapping=i.LinearToneMapping,r.toneMappingExposure=Math.pow(1.2,5),r.setPixelRatio(2*window.devicePixelRatio),r.setClearColor(new i.Color(16777215)),r.useLegacyLights=!1;const s=new i.PerspectiveCamera(60,1,2,100);s.position.set(8,6,14);const a=new i.Scene,d=new o.OrbitControls(s,r.domElement);d.target.set(0,.03,0),d.dampingFactor=.3;{const e=new i.AmbientLight(new i.Color(16777215),.3),t=new i.DirectionalLight(new i.Color(16777215),.1);t.position.set(10,0,10);const n=new i.DirectionalLight(new i.Color(16777215),.1);n.position.set(-10,0,10),a.add(e,t,n)}const c=()=>{const t=e.clientWidth,n=e.clientHeight;e.width===t&&e.height===n||(r.setSize(t,n,!1),s.aspect=t/n,s.updateProjectionMatrix())};let l;let u=!1;const p=()=>{u||(requestAnimationFrame(p),c(),d.update(),r.render(a,s))};return{domElement:e,updateSize:c,parse:(e,n)=>t(void 0,void 0,void 0,(function*(){return null==l&&(l=t(void 0,void 0,void 0,(function*(){const t=new o.RGBELoader,s=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}(o,t.parse(n));s.mapping=i.EquirectangularReflectionMapping,s.encoding=i.LinearEncoding,a.environment=s;const d=(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 d.parseAsync(e.buffer,"");a.add(c.scene),a.traverse((e=>{if(e instanceof i.Mesh){const t=e.material;t.depthWrite=!0,t instanceof i.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),l})),isPaused:()=>u,resume:()=>{u=!1,p(),n.display=""},pause:()=>{u=!0,n.display="none"}}};function u(e,t,n){const o=document.createElement("button");return o.id=e,o.type="button",o.className="shopar-btn",o.textContent=t,o.ariaLabel=n,o.style.zIndex="2",o}const p="0.0.2";let h=`https://cdn.jsdelivr.net/npm/shopar-plugin@${p}/dist`;const f={update:e=>{null!=e&&(h=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>h};function w(e){return t(this,void 0,void 0,(function*(){const n=yield i((()=>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 m(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())}))}const v=[Uint8Array,Uint32Array],y=v.length-2,g=window.location.hostname.charCodeAt(y),E=g^g,b=new v[1]([E]);function C(e,n,o){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 c=String.fromCharCode(r-7);r^=2;const l=String.fromCharCode(r-7),u=window[`${c}${d+a+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${l}`],p=yield i((()=>t(this,void 0,void 0,(function*(){const t=yield u(`${e}`).catch((()=>{throw new Error("Unknown error.")}));if(!t.ok)throw new Error("Unknown error.");return t})))),h=new v[0](yield(yield p.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));o+=s;const f=h.byteLength;if(b[E]=Math.min(76,n)*((r>>5)-1),152===b[E]&&(b[E]=f),o==E)return h;o=E,o^=E;for(let e=0,t=h.length;e<t;e++)b[E]^=b[o]<<13,b[E]^=b[o]>>17,b[E]^=b[o]<<5,h[e]=h[e]^b[E];return o^=b[0],o^=b[1],o^=b[2],h}))}function P(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function L(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}function R(e){const{apiKey:t,sku:n,targetElement:o,baseUrl:i}=e;P(t,"apiKey"),L(t,"apiKey"),P(n,"sku"),L(n,"sku"),P(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&L(i,"baseUrl")}var A;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(A||(A={}));let x=A.None,S=0;const $=[];function M(){if(x===A.AR){const e=s();null==e||e.isPaused()||e.pause()}else if(x===A.Preview){const e=c();null==e||e.isPaused()||e.pause()}}function T(e){var t;x=e,$.forEach((e=>null==e?void 0:e.classList.remove("active"))),null===(t=$[x])||void 0===t||t.classList.add("active")}function k(e){return t(this,void 0,void 0,(function*(){R(e);const{apiKey:n,sku:o,targetElement:s}=e;f.update(e.baseUrl);const c=yield function(e,n){return t(this,void 0,void 0,(function*(){const o=yield i((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.spexx.ai/plugin?${new URLSearchParams({apiKey:e,sku:n})}`).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.")}}))}(n,o);!function(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}'.`)}(s),s.style.position="relative";const p=function(){const e=document.createElement("div"),t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}();s.appendChild(p);const h=function(){const e=document.createElement("div");return e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}();p.appendChild(h);const v=function(){const e=document.createElement("div"),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.textContent="Loading...",n.appendChild(i),{container:e,show:()=>{t.display=""},hide:()=>{t.display="none"}}}();p.appendChild(v.container);const{arUrl:y,previewUrl:g}=c;if(null!=y){const e=Promise.all([m(`${f}/shopar-deepar.js`),w(y)]);$[A.AR]=u("shopar-btn-vto","AR","Launch virtual try-on"),h.appendChild($[A.AR]),$[A.AR].onclick=()=>t(this,void 0,void 0,(function*(){const t=++S,n=A.AR,o=x===n?A.None:n;if(M(),T(o),x===A.None)return;v.show();const[,i]=yield e;if(S!==t)return;const s=(null==r&&(r=a()),r);p.contains(s.domElement)||p.appendChild(s.domElement),yield s.init(),S===t&&(yield s.parse(i),S===t&&(s.resume(),v.hide()))}))}if(null!=g){const e=255,n=Promise.all([m(`${f}/shopar-three.js`),C(g,(new Date).getTime()+e,Math.random()*e),w(`${f}/env/studio2.hdr`)]);$[A.Preview]=u("shopar-btn-3d","3D","Launch 3D preview"),h.appendChild($[A.Preview]),$[A.Preview].onclick=()=>t(this,void 0,void 0,(function*(){const e=++S,t=A.Preview,o=x===t?A.None:t;if(M(),T(o),x===A.None)return;v.show();const[,i,r]=yield n;if(S!==e)return;const s=(null==d&&(d=l()),d);p.contains(s.domElement)||(p.appendChild(s.domElement),s.updateSize()),yield s.parse(i,r),S===e&&(s.resume(),v.hide())}))}}))}const D={setup:function(e){return t(this,void 0,void 0,(function*(){!function(e,n){t(this,void 0,void 0,(function*(){try{yield n()}catch(t){throw t instanceof Error?new D.PluginError(`${e} failed: ${t.message}`):(console.error(t),new D.PluginError(`${e} failed.`))}}))}("setup",(()=>k(e)))}))},version:p,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};e.plugin=D}));
!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,d=new n[1]([c]);function l(){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)}}))}let f;const m=()=>f,w=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")}};let v;const g=()=>v,y=()=>{const e=m(),n=document.createElement("div"),o=n.style;o.position="absolute",o.top="0",o.left="0",o.width="100%",o.height="100%",o.zIndex="1",o.display="none";const i=window.ShopAR__DeepAR;let r,s;const a={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0},c={Glasses:"user",Shoes:"environment",Watches:"environment"};let d;let l=!0;return{domElement:n,init:(o,d)=>t(void 0,void 0,void 0,(function*(){const l=null!=d?a[d]:void 0,u=null!=d?c[d]:"user";return null==s&&(s=t(void 0,void 0,void 0,(function*(){r=yield i.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:n,additionalOptions:{hint:l,cameraConfig:{facingMode:u,cameraPermissionAsked:()=>{e.vtoCameraAsked()},cameraPermissionGranted:()=>{e.vtoCameraGranted()}}}}),e.vtoInitSuccess()}))),s})),parse:e=>t(void 0,void 0,void 0,(function*(){return null==d&&(d=r.switchEffect(e)),d})),isPaused:()=>l,resume:()=>{l=!1,r.setPaused(l),o.display=""},pause:()=>{l=!0,r.setPaused(l),o.display="none"}}};let E;const b=()=>E,C=()=>{const e=m(),n=document.createElement("canvas"),o=n.style;o.position="absolute",o.top="0",o.left="0",o.width="100%",o.height="100%",o.zIndex="1";const i=window.ShopAR__THREE,r=i.THREE,s=new r.WebGLRenderer({canvas:n,antialias:!0});s.outputEncoding=r.sRGBEncoding,s.toneMapping=r.LinearToneMapping,s.toneMappingExposure=Math.pow(1.2,5),s.setPixelRatio(2*window.devicePixelRatio),s.setClearColor(new r.Color(16777215)),s.useLegacyLights=!1;const a=new r.PerspectiveCamera(60,1,2,100);a.position.set(8,6,14);const c=new r.Scene,d=new i.OrbitControls(a,s.domElement);d.target.set(0,.03,0),d.dampingFactor=.3;{const t=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>e.previewInteracted()),200);d.addEventListener("end",t)}{const e=new r.AmbientLight(new r.Color(16777215),.3),t=new r.DirectionalLight(new r.Color(16777215),.1);t.position.set(10,0,10);const n=new r.DirectionalLight(new r.Color(16777215),.1);n.position.set(-10,0,10),c.add(e,t,n)}const l=()=>{const e=n.clientWidth,t=n.clientHeight;n.width===e&&n.height===t||(s.setSize(e,t,!1),a.aspect=e/t,a.updateProjectionMatrix())};let u;let h=!1;const p=()=>{h||(requestAnimationFrame(p),l(),d.update(),s.render(c,a))};return{domElement:n,updateSize:l,parse:(e,n)=>t(void 0,void 0,void 0,(function*(){return null==u&&(u=t(void 0,void 0,void 0,(function*(){const t=new i.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}(i,t.parse(n));o.mapping=r.EquirectangularReflectionMapping,o.encoding=r.LinearEncoding,c.environment=o;const a=(new i.GLTFLoader).setDRACOLoader((new i.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${r.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new i.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${r.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(s)).setMeshoptDecoder("function"==typeof i.MeshoptDecoder?i.MeshoptDecoder():i.MeshoptDecoder),d=yield a.parseAsync(e.buffer,"");c.add(d.scene),c.traverse((e=>{if(e instanceof r.Mesh){const t=e.material;t.depthWrite=!0,t instanceof r.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),u})),isPaused:()=>h,resume:()=>{h=!1,p(),o.display=""},pause:()=>{h=!0,o.display="none"}}},A="0.0.3";let P=`https://cdn.jsdelivr.net/npm/shopar-plugin@${A}/dist`;const S={update:e=>{null!=e&&(P=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>P};function L(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}function R(e,t,n,o){const i=document.createElement("button");if(i.id=e,i.type="button",i.className="shopar-btn",null!=o){const e=L("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}return i.ariaLabel=n,i.style.zIndex="2",i}function k(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 x(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 $(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 l=String.fromCharCode(r-3);r^=5;const u=String.fromCharCode(r-7);r^=2;const h=String.fromCharCode(r-7),f=window[`${u}${l+a+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${h}`],m=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 m.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));i+=s;const v=w.byteLength;if(d[c]=Math.min(76,o)*((r>>5)-1),152===d[c]&&(d[c]=v),i==c)return w;i=c,i^=c;for(let e=0,t=w.length;e<t;e++)d[c]^=d[i]<<13,d[c]^=d[i]>>17,d[c]^=d[i]<<5,w[e]=w[e]^d[c];return i^=d[0],i^=d[1],i^=d[2],w}))}function I(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function T(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}function _(e){const{apiKey:t,sku:n,targetElement:o,baseUrl:i}=e;I(t,"apiKey"),T(t,"apiKey"),I(n,"sku"),T(n,"sku"),I(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&T(i,"baseUrl")}var M;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(M||(M={}));let N,U=M.None,D=0;const j=[];let z;function G(){if(U===M.AR){const e=g();null==e||e.isPaused()||e.pause()}else if(U===M.Preview){const e=b();null==e||e.isPaused()||e.pause()}}function O(e){if(U=e,U===M.None){const e=j.filter((e=>null!=e));N.replaceChildren(...e)}else N.replaceChildren(z)}function K(e){return t(this,void 0,void 0,(function*(){_(e);const{apiKey:n,sku:o,targetElement:i}=e;S.update(e.baseUrl);const r=function(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:l()})}`).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.")}}))}(n,o),s=(a=x(`${S}/shopar-analytics.js`),null==f&&(f=w(a)),f);var a;s.init(n,o),function(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}'.`)}(i),i.style.position="relative";const c=function(){const e=document.createElement("div"),t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}();i.appendChild(c),N=function(){const e=document.createElement("div");return e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}(),c.appendChild(N),z=R("shopar-btn-close","Close","Close ShopAR view",`${S}/img/icons/close.svg`),z.onclick=()=>{d.hide(),u.hide(),G(),O(M.None)};const d=function(){const e=document.createElement("div"),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),{container:e,show:()=>{t.display=""},hide:()=>{t.display="none"}}}();c.appendChild(d.container);const u=function(){const e=document.createElement("div"),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=L("4rem",`${S}/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),{container:e,show:()=>{t.display=""},hide:()=>{t.display="none"}}}();c.appendChild(u.container);const{category:h,arUrl:m,arKey:g,previewUrl:b}=yield r;if(s.initialized(),null!=m){const e=Promise.all([x(`${S}/shopar-deepar.js`),k(m)]),n={Glasses:`${S}/img/icons/glasses.svg`,Shoes:`${S}/img/icons/shoe.svg`,Watches:`${S}/img/icons/watch.svg`},o=null!=h&&n[h]||n.Glasses;j[M.AR]=R("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on",o),N.appendChild(j[M.AR]),j[M.AR].onclick=()=>t(this,void 0,void 0,(function*(){const t=++D,n=M.AR,o=U===n?M.None:n;if(G(),O(o),U===M.None)return;s.vtoLaunched(),u.hide(),d.show();const[,i]=yield e;if(D!==t)return;const r=(null==v&&(v=y()),v);c.contains(r.domElement)||c.appendChild(r.domElement);try{yield r.init(g,h)}catch(e){return s.vtoCameraDenied(e),d.hide(),void u.show()}D===t&&(yield r.parse(i),D===t&&(r.resume(),d.hide()))}))}if(null!=b){const e=255,n=Promise.all([x(`${S}/shopar-three.js`),$(b,(new Date).getTime()+e,Math.random()*e),k(`${S}/env/studio2.hdr`)]);j[M.Preview]=R("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${S}/img/icons/cube.svg`),N.appendChild(j[M.Preview]),j[M.Preview].onclick=()=>t(this,void 0,void 0,(function*(){const e=++D,t=M.Preview,o=U===t?M.None:t;if(G(),O(o),U===M.None)return;s.previewLaunched(),u.hide(),d.show();const[,i,r]=yield n;if(D!==e)return;const a=(null==E&&(E=C()),E);c.contains(a.domElement)||(c.appendChild(a.domElement),a.updateSize()),yield a.parse(i,r),D===e&&(a.resume(),d.hide())}))}}))}const W={setup:function(e){return t(this,void 0,void 0,(function*(){!function(e,n){t(this,void 0,void 0,(function*(){try{yield n()}catch(t){throw t instanceof Error?new W.PluginError(`${e} failed: ${t.message}`):(console.error(t),new W.PluginError(`${e} failed.`))}}))}("setup",(()=>K(e)))}))},version:A,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};e.plugin=W}));
{
"name": "shopar-plugin",
"version": "0.0.2",
"version": "0.0.3",
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",
"scripts": {
"clean": "rm -rf dist",
"build": "yarn run clean && rollup -c --environment BUILD_PRODUCTION",
"build-dev": "yarn run clean && rollup -c",
"build-prod": "yarn run clean && rollup -c --environment MINIFY,ANALYTICS:prod.js",
"build-stage": "yarn run clean && rollup -c --environment MINIFY,ANALYTICS:stage.js",
"build-debug": "yarn run clean && rollup -c",
"build": "yarn run clean && rollup -c --environment MINIFY",
"generate-version": "node ci/generate-version.js",

@@ -33,4 +35,6 @@ "prepare-release": "node ci/prepare-release.js",

"dependencies": {
"@amplitude/analytics-browser": "^2.3.3",
"deepar": "5.4.1",
"three": "0.151.3"
"three": "0.151.3",
"uuid": "^9.0.1"
},

@@ -44,2 +48,3 @@ "devDependencies": {

"@types/three": "0.151.0",
"@types/uuid": "^9.0.6",
"@typescript-eslint/eslint-plugin": "^6.4.1",

@@ -46,0 +51,0 @@ "@typescript-eslint/parser": "^6.4.1",

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

```html
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.2/dist/shopar-plugin.js"></script>
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.3/dist/shopar-plugin.js"></script>
```

@@ -78,5 +78,2 @@

}
.shopar-btn.active {
/* Toggled control button. */
}
```

@@ -104,3 +101,3 @@

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

@@ -107,0 +104,0 @@ ## License

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