shopar-plugin 0.0.6-alpha.4 → 0.0.6-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/shopar-analytics.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ShopAR__analytics={})}(this,(function(t){"use strict";function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ShopAR__analytics={})}(this,(function(t){"use strict";function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t){return Number.isInteger(t)&&t>=0}function n(t){this.name="ArgumentError",this.message=t}var s=e((function(t,e){if(e=e||{},"function"!=typeof t)throw new n("fetch must be a function");if("object"!=typeof e)throw new n("defaults must be an object");if(void 0!==e.retries&&!i(e.retries))throw new n("retries must be a positive integer");if(void 0!==e.retryDelay&&!i(e.retryDelay)&&"function"!=typeof e.retryDelay)throw new n("retryDelay must be a positive integer or a function returning a positive integer");if(void 0!==e.retryOn&&!Array.isArray(e.retryOn)&&"function"!=typeof e.retryOn)throw new n("retryOn property expects an array or function");return e=Object.assign({retries:3,retryDelay:1e3,retryOn:[]},e),function(s,r){var a=e.retries,o=e.retryDelay,c=e.retryOn;if(r&&void 0!==r.retries){if(!i(r.retries))throw new n("retries must be a positive integer");a=r.retries}if(r&&void 0!==r.retryDelay){if(!i(r.retryDelay)&&"function"!=typeof r.retryDelay)throw new n("retryDelay must be a positive integer or a function returning a positive integer");o=r.retryDelay}if(r&&r.retryOn){if(!Array.isArray(r.retryOn)&&"function"!=typeof r.retryOn)throw new n("retryOn property expects an array or function");c=r.retryOn}return new Promise((function(e,i){var n=function(n){var o="undefined"!=typeof Request&&s instanceof Request?s.clone():s;t(o,r).then((function(t){if(Array.isArray(c)&&-1===c.indexOf(t.status))e(t);else if("function"==typeof c)try{return Promise.resolve(c(n,null,t)).then((function(i){i?u(n,null,t):e(t)})).catch(i)}catch(t){i(t)}else n<a?u(n,null,t):e(t)})).catch((function(t){if("function"==typeof c)try{Promise.resolve(c(n,t,null)).then((function(e){e?u(n,t,null):i(t)})).catch((function(t){i(t)}))}catch(t){i(t)}else n<a?u(n,t,null):i(t)}))};function u(t,e,i){var s="function"==typeof o?o(t,e,i):o;setTimeout((function(){n(++t)}),s)}n(0)}))}}));var r,a;!function(t){t.unknown="unknown",t.user="user",t.organization="organization",t.anonymous="anonymous"}(r||(r={})),function(t){t.api="api",t.query="query",t.ingest="ingest"}(a||(a={}));class o{scope;type;value;remaining;reset;constructor(t=r.unknown,e=a.api,i=0,n=-1,s=new Date){this.scope=t,this.type=e,this.value=i,this.remaining=n,this.reset=s}}function c(t,e,i,n,s){let a=new o;const c=t.headers.get(e.toLowerCase())||r.unknown;a.scope=r[c];const u=t.headers.get(i.toLowerCase())||"",h=parseInt(u,10);isNaN(h)||(a.value=h);const l=t.headers.get(n.toLowerCase())||"",f=parseInt(l,10);isNaN(f)||(a.remaining=f);const m=t.headers.get(s.toLowerCase())||"",y=parseInt(m,10);return isNaN(y)||(a.reset=new Date(1e3*y)),a}class u{config;constructor(t){this.config=t}async doReq(t,e,i={},n={}){let r=`${this.config.baseUrl}${t}`;const o=this._prepareSearchParams(n);o&&(r+=`?${o.toString()}`);const u={...this.config.headers,...i.headers},l=await s(fetch)(r,{retries:3,retryDelay:function(t,e,i){return 1e3*Math.pow(2,t)},retryOn:[503,502,504,500],headers:u,method:e,body:i.body?i.body:void 0});if(204===l.status)return l;if(429==l.status){const t=function(t){let e;return t.url?.endsWith("/ingest")?(e=c(t,"","X-IngestLimit-Limit","X-IngestLimit-Remaining","X-IngestLimit-Reset"),e.type=a.ingest):t.url?.endsWith("/query")||t.url?.endsWith("/_apl")?(e=c(t,"","X-QueryLimit-Limit","X-QueryLimit-Remaining","X-QueryLimit-Reset"),e.type=a.query):(e=c(t,"X-RateLimit-Scope","X-RateLimit-Limit","X-RateLimit-Remaining","X-RateLimit-Reset"),e.type=a.api),e}(l);return Promise.reject(new h(t))}if(401===l.status)return Promise.reject(new Error("Forbidden"));if(l.status>=400){const t=await l.json();return Promise.reject(new Error(t.message))}return await l.json()}post(t,e={},i={}){return this.doReq(t,"POST",e,i)}get(t,e={},i={}){return this.doReq(t,"GET",e,i)}put(t,e={},i={}){return this.doReq(t,"PUT",e,i)}delete(t,e={},i={}){return this.doReq(t,"DELETE",e,i)}_prepareSearchParams=t=>{const e=new URLSearchParams;let i=!1;return Object.keys(t).forEach((n=>{t[n]&&(e.append(n,t[n]),i=!0)})),i?e:null}}class h extends Error{limit;shortcircuit;message="";constructor(t,e=!1){super(),this.limit=t,this.shortcircuit=e,Object.setPrototypeOf(this,h.prototype);const i=h.timeUntilReset(t);this.message=`${t.type} limit exceeded, try again in ${i.minutes}m${i.seconds}s`,t.type==a.api&&(this.message=`${t.scope} `+this.message)}static timeUntilReset(t){const e=t.reset.getTime()-(new Date).getTime(),i=Math.floor(e/1e3%60);return{total:e,minutes:Math.floor(e/1e3/60%60),seconds:i}}}class l{client;constructor({orgId:t="",token:e,url:i}){e||console.warn("Missing Axiom token");const n=i??"https://api.axiom.co",s={Accept:"application/json","Content-Type":"application/json",Authorization:"Bearer "+e};"undefined"==typeof window&&(s["User-Agent"]="axiom-js/1.0.0-rc.1"),t&&(s["X-Axiom-Org-Id"]=t),this.client=new u({baseUrl:n,headers:s,timeout:3e3})}}var f,m,y,p,d,g;!function(t){t.TimestampField="_time";t.Service=class extends l{localPath="/v1/datasets";list=()=>this.client.get(this.localPath);get=t=>this.client.get(this.localPath+"/"+t);create=t=>this.client.post(this.localPath,{body:JSON.stringify(t)});update=(t,e)=>this.client.put(this.localPath+"/"+t,{body:JSON.stringify(e)});delete=t=>this.client.delete(this.localPath+"/"+t);trim=(t,e)=>{const i={maxDuration:e};return this.client.post(this.localPath+"/"+t+"/trim",{body:JSON.stringify(i)})}}}(f||(f={})),function(t){t.Service=class extends l{current=()=>this.client.get("/v1/user")}}(m||(m={}));class w{ingestFn;id;options;events=[];activeFlush=Promise.resolve();nextFlush=setTimeout((()=>{}),0);lastFlush=new Date;constructor(t,e,i){this.ingestFn=t,this.id=e,this.options=i}ingest=t=>{Array.isArray(t)?this.events=this.events.concat(t):this.events.push(t),this.events.length>=1e3||this.lastFlush.getTime()<Date.now()-1e3?(clearTimeout(this.nextFlush),this.activeFlush=this.flush()):(clearTimeout(this.nextFlush),this.nextFlush=setTimeout((()=>{this.activeFlush=this.flush()}),1e3))};flush=async()=>{const t=this.events.splice(0,this.events.length);if(clearTimeout(this.nextFlush),await this.activeFlush,0===t.length)return void(this.lastFlush=new Date);const e=await this.ingestFn(this.id,t,this.options);return this.lastFlush=new Date,e}}class v extends l{datasets;users;localPath="/v1";constructor(t){super(t),this.datasets=new f.Service(t),this.users=new m.Service(t)}ingestRaw=(t,e,i=y.JSON,n=p.Identity,s)=>this.client.post(this.localPath+"/datasets/"+t+"/ingest",{headers:{"Content-Type":i,"Content-Encoding":n},body:e},{"timestamp-field":s?.timestampField,"timestamp-format":s?.timestampFormat,"csv-delimiter":s?.csvDelimiter});queryLegacy=(t,e,i)=>this.client.post(this.localPath+"/datasets/"+t+"/query",{body:JSON.stringify(e)},{"streaming-duration":i?.streamingDuration,nocache:i?.noCache});query=(t,e)=>{const i={apl:t};return e?.startTime&&(i.startTime=e?.startTime),e?.endTime&&(i.endTime=e?.endTime),this.client.post(this.localPath+"/datasets/_apl",{body:JSON.stringify(i)},{"streaming-duration":e?.streamingDuration,nocache:e?.noCache,format:"legacy"})};aplQuery=(t,e)=>this.query(t,e)}class b extends v{batch={};ingest=(t,e,i)=>{const n=function(t,e){return`${t}:${e?.timestampField||"-"}:${e?.timestampFormat||"-"}:${e?.csvDelimiter||"-"}`}(t,i);return this.batch[n]||(this.batch[n]=new w(((t,e,i)=>{const n=(Array.isArray(e)?e:[e]).map((t=>JSON.stringify(t))).join("\n");return this.ingestRaw(t,n,y.NDJSON,p.Identity,i)}),t,i)),this.batch[n].ingest(e)};flush=async()=>{let t=[];for(const e in this.batch)t.push(this.batch[e].flush());await Promise.all(t)}}let x;!function(t){t.JSON="application/json",t.NDJSON="application/x-ndjson",t.CSV="text/csv"}(y||(y={})),function(t){t.Identity="",t.GZIP="gzip"}(p||(p={})),function(t){t.Count="count",t.Distinct="distinct",t.Sum="sum",t.Avg="avg",t.Min="min",t.Max="max",t.Topk="topk",t.Percentiles="percentiles",t.Histogram="histogram",t.Variance="variance",t.Stdev="stdev",t.ArgMin="argmin",t.ArgMax="argmax",t.MakeSet="makeset",t.MakeSetIf="makesetif",t.CountIf="countif",t.CountDistinctIf="distinctif"}(d||(d={})),function(t){t.And="and",t.Or="or",t.Not="not",t.Equal="==",t.NotEqual="!=",t.Exists="exists",t.NotExists="not-exists",t.GreaterThan=">",t.GreaterThanOrEqualTo=">=",t.LessThan="<",t.LessThanOrEqualTo="<=",t.Gt="gt",t.Gte="gte",t.Lt="lt",t.Lte="lte",t.StartsWith="starts-with",t.NotStartsWith="not-starts-with",t.EndsWith="ends-with",t.NotEndsWith="not-ends-with",t.Contains="contains",t.NotContains="not-contains",t.Regexp="regexp",t.NotRegexp="not-regexp"}(g||(g={})),t.initializeImpl=function(){x=new b({token:"xaat-16d05fdd-4ab9-4990-acba-7cee24974bfb"})},t.trackEventImpl=function(t,e){x.ingest("shopar-plugin-alpha",Object.assign({name:t},e))}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const n=[Uint8Array,Uint32Array],o=n.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],r=[2,12,7,1],a=window[i[r[r[o]]]][i[r[r[r.length-1]]]],s=a.charCodeAt(o),l=s^s,c=new n[1]([l]);function d(){const e=(new TextEncoder).encode(a),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,u[n]))),p(t,n+1)}}))}const f=["Glasses","Shoes","Watches"],v=["Shoes"];const w="0.0.6-alpha.4";let m=`https://cdn.jsdelivr.net/npm/shopar-plugin@${w}/dist`;const y={update:e=>{null!=e&&(m=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>m};function g(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let b,C,E=!1;const R=[],A={organizationId:"Unknown",sku:"Unknown"};let S;function k(){P("vto_launched")}function P(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),A),{vtoTime:(performance.now()-S)/1e3,vtoSessionId:C}),$((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function $(e){E?e():R.push(e)}function x(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function M(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const _=200,I=10;let T,D,L,U,N=!1;function j(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let O,G,W,z,F,q,B,H=!0;function K(e){e!==U&&(U=e,L=j(e),q=null,null==O||O.clearEffect(),N=!0)}function V(n,o,i){return e(this,void 0,void 0,(function*(){return W=i,z=n,null==F&&(F=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new t("No camera available!");var r;const a=Z(i),s=x(a);P("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);O=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:n,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),G=yield M(s),P("vto_camera_granted"),yield Y(O,G,"user"===a),"Glasses"===i&&(yield D,function(t,n){e(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,t);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<I)return void i.push(t);clearInterval(r);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),_)}))}(G,O)),P("vto_init_success")})))()),F}))}function Q(t){return e(this,void 0,void 0,(function*(){return null==q&&(q=O.switchEffect(t)),q}))}function X(){null!=O&&(H=!0,O.setPaused(H),null!=G&&null!=G.srcObject&&G.srcObject instanceof MediaStream&&(G.srcObject.getTracks().forEach((e=>e.stop())),G=null),O.stopCamera(),z.style.display="none")}function Z(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Y(t,n,o){return e(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,o),i()}))))}}))}))}function J(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const ee="shopar-error";function te(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=J("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const ne="shopar-control";const oe="shopar-deepar-output";const ie="shopar-loading";const re="shopar-main";const ae="shopar-qr-output";const se="shopar-three-output";var le;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(le||(le={}));let ce,de,ue,he,pe,fe,ve,we,me,ye,ge=le.None;function be(e){ge=e}let Ce,Ee=!1,Re=null;function Ae(){Ee||(ce=function(){const e=document.createElement("div");e.id=re;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),de=function(){const e=document.createElement("div");e.id=ae;const t=e.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="relative",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="flex",o.alignItems="center",o.justifyContent="center",o.backgroundColor="white",e.appendChild(n);const i=new Image,r=i.style;return r.maxWidth="100%",r.maxHeight="100%",n.appendChild(i),e}(),ce.appendChild(de),ue=function(){const e=document.createElement("div");e.id=oe;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(ue),he=function(){const e=document.createElement("canvas");e.id=se;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(he),pe=function(){const e=document.createElement("div");return e.id=ne,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ce.appendChild(pe),fe=te("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),pe.appendChild(fe),ve=te("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`),pe.appendChild(ve),we=te("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`),pe.append(we),me=function(){const e=document.createElement("div");e.id=ie;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),ce.appendChild(me),ye=function(){const e=document.createElement("div");e.id=ee;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=J("4rem",`${y}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.appendChild(r);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}(),ce.appendChild(ye),Ee=!0)}function Se(e,t){e.style.display=t?"":"none"}function ke(e){""===e.style.display&&Se(e,!1)}let Pe,$e,xe,Me,_e,Ie=!0;function Te(t,n){return e(this,void 0,void 0,(function*(){yield Ce;const e=`https://apps.deepar.ai/${w.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:t,s:n,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),i=de.firstChild.firstChild,r=new Promise(((e,t)=>{i.onload=e,i.onerror=t}));i.src=o,yield r,Ie=!1,de.style.display=""}))}function De(){Ie=!0,de.style.display="none"}let Le,Ue,Ne,je,Oe,Ge,We,ze,Fe,qe,Be,He,Ke,Ve,Qe,Xe,Ze=!1,Ye=!1;const Je=45,et=45,tt=3,nt=.1,ot=3.5,it=2,rt=1;let at;function st(o){if(o!==xe){const i=255;xe=o,$e=function(o,i,r){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const d=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),v=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],w=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield v(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),m=new n[0](yield(yield w.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));r+=s;const y=m.byteLength;if(c[l]=Math.min(76,i)*((a>>5)-1),152===c[l]&&(c[l]=y),r==l)return m;r=l,r^=l;for(let e=0,t=m.length;e<t;e++)c[l]^=c[r]<<13,c[l]^=c[r]>>17,c[l]^=c[r]<<5,m[e]=m[e]^c[l];return r^=c[0],r^=c[1],r^=c[2],m}))}(o,(new Date).getTime()+i,Math.random()*i),at=null,null==Ke||Ke.clear()}}function lt(t,n){return e(this,void 0,void 0,(function*(){if(Le=t,!Ye){Ue=window.ShopAR__THREE,Ne=Ue.THREE,je=new Ne.WebGLRenderer({powerPreference:"high-performance",canvas:t,antialias:!0,alpha:!0}),je.outputEncoding=Ne.sRGBEncoding,je.toneMapping=Ne.ACESFilmicToneMapping,je.setPixelRatio(window.devicePixelRatio||1),je.setClearColor(new Ne.Color(16777215)),Ke=new Ne.Scene,Oe=new Ne.Group,Oe.position.y=-.7,Ge=new Ne.WebGLRenderTarget(512,512),Ge.texture.generateMipmaps=!1,We=new Ne.WebGLRenderTarget(512,512),We.texture.generateMipmaps=!1;const e=new Ne.PlaneGeometry(Je,et).rotateX(Math.PI/2),o=new Ne.MeshBasicMaterial({map:Ge.texture,opacity:rt,transparent:!0,depthWrite:!1});ze=new Ne.Mesh(e,o),ze.renderOrder=1,Oe.add(ze),ze.scale.y=-1,Fe=new Ne.Mesh(e),Fe.visible=!1,Oe.add(Fe),Qe=new Ne.OrthographicCamera(-Je/2,Je/2,et/2,-et/2,0,tt),Qe.rotation.x=Math.PI/2,Oe.add(Qe),qe=new Ne.MeshDepthMaterial,qe.userData.darkness={value:it},qe.onBeforeCompile=function(e){e.uniforms.darkness=qe.userData.darkness,e.fragmentShader=`\n uniform float darkness;\n ${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );")}\n `},qe.depthTest=!1,qe.depthWrite=!1,Be=new Ne.ShaderMaterial(Ue.HorizontalBlurShader),Be.depthTest=!1,He=new Ne.ShaderMaterial(Ue.VerticalBlurShader),He.depthTest=!1,Ve=new Ne.PerspectiveCamera(25,1,.5);const i=function(e){var t;const n={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);Ve.position.set(i[0],i[1],i[2]),Xe=new Ue.OrbitControls(Ve,je.domElement),Xe.target.set(0,.03,0),Xe.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{P("preview_interacted")}),200);Xe.addEventListener("end",e)}Ye=!0}pt()}))}function ct(t,n){return e(this,void 0,void 0,(function*(){return null==at&&(at=(()=>e(this,void 0,void 0,(function*(){const e=new Ue.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(Ue,e.parse(n));o.mapping=Ne.EquirectangularReflectionMapping,o.encoding=Ne.LinearEncoding,Ke.environment=o;const i=(new Ue.GLTFLoader).setDRACOLoader((new Ue.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Ue.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(je)).setMeshoptDecoder("function"==typeof Ue.MeshoptDecoder?Ue.MeshoptDecoder():Ue.MeshoptDecoder);return yield i.parseAsync(t.buffer,"")})))()),at}))}function dt(t){return e(this,void 0,void 0,(function*(){Ke.add(t.scene);const e=(new Ne.Box3).setFromObject(t.scene);Oe.position.y=e.min.y-nt,Ke.add(Oe),Ke.traverse((e=>{if(e instanceof Ne.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ne.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ut(){Ze=!0,Le.style.display="none"}function ht(){if(Ze)return;requestAnimationFrame(ht),pt(),Xe.update();const e=Ke.background;Ke.background=null,Ke.overrideMaterial=qe;const t=je.getClearAlpha();je.setClearAlpha(0),je.setRenderTarget(Ge),je.render(Ke,Qe),Ke.overrideMaterial=null,ft(ot),ft(.4*ot),je.setRenderTarget(null),je.setClearAlpha(t),Ke.background=e,je.render(Ke,Ve)}function pt(){const e=Le.clientWidth,t=Le.clientHeight;Le.width===e&&Le.height===t||(je.setSize(e,t,!1),Ve.aspect=e/t,Ve.updateProjectionMatrix())}function ft(e){Fe.visible=!0,Be.uniforms.tDiffuse.value=Ge.texture,Be.uniforms.h.value=1*e/256,Fe.material=Be,je.setRenderTarget(We),je.render(Fe,Qe),He.uniforms.tDiffuse.value=We.texture,He.uniforms.v.value=1*e/256,Fe.material=He,je.setRenderTarget(Ge),je.render(Fe,Qe),Fe.visible=!1}function vt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function wt(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const mt=["AR","3D"];function yt(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;vt(n,"apiKey"),wt(n,"apiKey"),vt(o,"sku"),wt(o,"sku"),vt(i,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&function(e,n,o){if("string"!=typeof e)throw new t(`'${n}' must be a string.`);if(!o.includes(e))throw new t(`'${n}' must be ${o.join("' or '")}.`)}(r,"initialState",mt),null!=a&&wt(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let gt=0,bt=0;function Ct(n){var o,i;return e(this,void 0,void 0,(function*(){yt(n);const{apiKey:r,sku:a,targetElement:s,initialState:l}=n;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(s),y.update(n.baseUrl);const c=function(n,o){return e(this,void 0,void 0,(function*(){const i=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:n,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(r,a);null==b&&(b=g(`${y}/shopar-analytics.js`),b.then((()=>{E=!0,C=window.ShopAR__analytics.uuidv4(),R.forEach((e=>e()))}))),function(e,t){A.organizationId=e,A.sku=t,S=performance.now(),$((()=>{window.ShopAR__analytics.initializeImpl()}))}(r,a),Ae();const u=++bt,{category:h,arUrl:w,arKey:m,previewUrl:_,previewEnvUrl:I}=yield c;Et(u),P("initialized");const U=null!=w&&function(e){return null!=e&&f.includes(e)}(h),N=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=n._internalOptions)||void 0===i?void 0:i.qrEnabled),F=U&&function(e){return null!=e&&v.includes(e)}(h),q=N&&F&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==B&&(B=g(`${y}/shopar-platform.js`)),yield B,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}());Et(u),q&&function(){e(this,void 0,void 0,(function*(){null==Ce&&(Ce=g(`${y}/shopar-qr.js`))}))}();const J=U&&!q;J&&(null==T&&(T=g(`${y}/shopar-deepar.js`)),K(w),"Glasses"===h&&null==D&&(D=g(`${y}/shopar-true-scale.js`)));const ee=null!=_;var te;ee&&(null==Pe&&(Pe=g(`${y}/shopar-three.js`)),st(_),(te=null!=I?I:`${y}/env/default.hdr`)!==_e&&(_e=te,Me=j(te))),function(e){e.style.position="relative",null==Re?e.appendChild(ce):e!==Re&&(Re.removeChild(ce),e.appendChild(ce)),Re=e}(s);const ne=null==n.defaultUI||n.defaultUI;if(function(e,t,n,o){Se(pe,e),Se(fe,e&&(n||t)&&ge===le.None),Se(ve,e&&o&&ge===le.None),Se(we,e&&ge!==le.None),e||ke(me),e||ke(ye)}(ne,q,J,ee),ge===le.AR){if(!H)if(J){const e=yield L;Et(u),yield Q(e),Et(u)}else X(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0));if(!Ie)if(q)try{yield Te(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}else De(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))}else if(ge===le.Preview&&!Ze)if(ee){const e=yield $e;Et(u);const t=yield Me;Et(u);const n=yield ct(e,t);Et(u),dt(n)}else ut(),be(le.None),ne&&(Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0));const oe=()=>e(this,void 0,void 0,(function*(){if(q){if(ge===le.AR)throw new t("AR already launched.");const e=++gt;ge===le.Preview&&ee&&!Ze&&ut(),be(le.AR),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),k(),ne&&(Se(ye,!1),Se(me,!0));try{yield Te(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}if(gt!==e||bt!==u)return;return void(ne&&Se(me,!1))}if(!J)throw new t("Model does not have AR enabled.");if(ge===le.AR)throw new t("AR already launched.");const n=++gt;ge===le.Preview&&ee&&!Ze&&ut(),be(le.AR),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),k(),ne&&(Se(ye,!1),Se(me,!0));const o=yield L;if(gt===n&&bt===u&&(yield T,gt===n&&bt===u)){try{yield V(ue,m,h)}catch(e){throw function(e){P("vto_camera_denied",{error:e})}(e),ne&&(Se(me,!1),Se(ye,!0)),e}gt===n&&bt===u&&(yield Q(o),gt===n&&bt===u&&(yield function(){return e(this,void 0,void 0,(function*(){if(null!=O){if(H=!1,null==G){const e=Z(W),t=x(e);G=yield M(t),yield Y(O,G,"user"===e)}O.setPaused(H),z.style.display=""}}))}(),gt===n&&bt===u&&ne&&Se(me,!1)))}})),ie=()=>e(this,void 0,void 0,(function*(){if(!ee)throw new t("Model does not have 3D enabled.");if(ge===le.Preview)throw new t("3D already launched.");const e=++gt;ge===le.AR&&(J&&!H&&X(),De()),be(le.Preview),ne&&(Se(fe,!1),Se(ve,!1),Se(we,!0)),P("preview_launched"),ne&&(Se(ye,!1),Se(me,!0));const n=yield $e;if(gt!==e||bt!==u)return;const o=yield Me;if(gt!==e||bt!==u)return;if(yield Pe,gt!==e||bt!==u)return;if(yield lt(he,h),gt!==e||bt!==u)return;const i=yield ct(n,o);gt===e&&bt===u&&(dt(i),Ze=!1,ht(),Le.style.display="",ne&&Se(me,!1))})),re=()=>e(this,void 0,void 0,(function*(){if(ge===le.None)throw new t("Neither AR or 3D launched.");++gt,ge===le.AR?(J&&!H&&X(),De()):ge===le.Preview&&ee&&!Ze&&ut(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))}));return ne&&((q||J)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${y}/img/icons/${null!=e&&t[e]||t.Glasses}`;fe.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(h),fe.onclick=oe),ee&&(ve.onclick=ie),we.onclick=re),"AR"===l?(yield oe(),Et(u)):"3D"===l&&(yield ie(),Et(u)),{launchAR:oe,launch3D:ie,closeAR:()=>e(this,void 0,void 0,(function*(){if(ge!==le.AR)throw new t("AR not launched.");++gt,J&&!H&&X(),De(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(ge!==le.Preview)throw new t("3D not launched.");++gt,ee&&!Ze&&ut(),be(le.None),ne&&(Se(me,!1),Se(ye,!1),Se(we,!1),(q||J)&&Se(fe,!0),ee&&Se(ve,!0))})),close:re}}))}function Et(e){if(bt!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Rt={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>Ct(n)))}))},version:w};export{Rt as plugin};
|
|
1
|
+
function e(e,n,t,o){return new(t||(t=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,s)}l((o=o.apply(e,n||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem;pointer-events:none}.shopar-btn{padding:.5rem .75rem;display:flex;justify-content:center;align-items:center;gap:.25rem;background-color:#fff;border:1px solid #ddd;border-radius:9999px;cursor:pointer;pointer-events:auto}.shopar-btn:hover{background-color:#f5f5f5}.shopar-ar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-ar-loading-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-ar-loading-bar{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-ar-loading-bar.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-3d-loading-container{display:flex;align-items:end}.shopar-3d-loading-bg{width:100%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-3d-loading-bar{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-3d-loading-bar.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class n extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const t=[Uint8Array,Uint32Array],o=t.length-2,r=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],i=[2,12,7,1],a=window[r[i[i[o]]]][r[i[i[i.length-1]]]],s=a.charCodeAt(o),l=s^s,c=new t[1]([l]);function d(){const e=(new TextEncoder).encode(a),n=r.map((e=>e.length));for(let t=0;t<e.length;t++)e[t]^=n[t%n.length];return window[r[n[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(n,t=0){return e(this,void 0,void 0,(function*(){try{return yield n()}catch(e){if(t>=h)throw e;return yield new Promise((e=>setTimeout(e,u[t]))),p(n,t+1)}}))}const f=["Glasses","Shoes","Watches"],m=["Shoes"];let v;const g=new Uint8Array(16);function w(){if(!v&&(v="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!v))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return v(g)}const y=[];for(let e=0;e<256;++e)y.push((e+256).toString(16).slice(1));var b={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function E(e,n,t){if(b.randomUUID&&!n&&!e)return b.randomUUID();const o=(e=e||{}).random||(e.rng||w)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=o[e];return n}return function(e,n=0){return y[e[n+0]]+y[e[n+1]]+y[e[n+2]]+y[e[n+3]]+"-"+y[e[n+4]]+y[e[n+5]]+"-"+y[e[n+6]]+y[e[n+7]]+"-"+y[e[n+8]]+y[e[n+9]]+"-"+y[e[n+10]]+y[e[n+11]]+y[e[n+12]]+y[e[n+13]]+y[e[n+14]]+y[e[n+15]]}(o)}const C="0.0.6-alpha.6";let R=`https://cdn.jsdelivr.net/npm/shopar-plugin@${C}/dist`;const S={update:e=>{null!=e&&(R=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>R};function A(n){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",n),e.setAttribute("crossorigin","anonymous"),new Promise((n=>{e.addEventListener("load",(()=>n()),!1),e.addEventListener("error",(()=>n()),!1),document.body.appendChild(e)}))}importScripts(n.toString())}))}const k="qrLaunch",x="arLaunch",$="previewLaunch",L="heartbeat";let M,P,U=!1;const T=[];function D(e,n){const t=performance.now(),o=E();let r=0,i=0,a=0,s=0,l=0,c=!1;const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:C,sessionId:P,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},U?a():T.push(a)};return window.setInterval((()=>{c&&(r=i+a,c=!1,d(L,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3),[d,()=>{const e=performance.now(),n=e-s;s=e,n<200&&(i+=n,c=!0)},()=>{const e=performance.now(),n=e-l;l=e,n<200&&(a+=n,c=!0)}]}function N(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function I(n){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield n,e}))}const j=200,_=10;let O,G,W,F,q=!1;function B(t){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(t).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!e.ok)throw new n(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let H,K,V,z,X,Q,Z,Y=!0;function J(e){e!==F&&(F=e,W=B(e),Q=null,null==H||H.clearEffect(),q=!0)}function ee(t,o,r){return e(this,void 0,void 0,(function*(){return V=r,z=t,null==X&&(X=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(i=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===i?void 0:i.getUserMedia))throw new n("No camera available!");var i;const a=re(r),s=N(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(r);H=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),K=yield I(s),yield ie(H,K,"user"===a),"Glasses"===r&&(yield G,function(n,t){e(this,void 0,void 0,(function*(){q=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${S}/wasm/mediapipe`,n);const r=[],i=setInterval((()=>e(this,void 0,void 0,(function*(){if(q)return void clearInterval(i);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(q)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<_)return void r.push(n);clearInterval(i);const a=137/(function(e){let n=0;const t=e.length;for(let o=0;o<t;o++)n+=e[o];return n/t}(r)+5);t.changeParameterVector("GLASSES","","scale",a,a,a,0),t.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),j)}))}(K,H))})))()),X}))}function ne(e){H.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},H.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},H.callbacks.onWristTracked=n=>{n.detected&&e()}}function te(n){return e(this,void 0,void 0,(function*(){return null==Q&&(Q=H.switchEffect(n)),Q}))}function oe(){null!=H&&(Y=!0,H.setPaused(Y),null!=K&&null!=K.srcObject&&K.srcObject instanceof MediaStream&&(K.srcObject.getTracks().forEach((e=>e.stop())),K=null),H.stopCamera(),z.style.display="none")}function re(e){var n;return null==e?"user":null!==(n={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==n?n:"user"}function ie(n,t,o){return e(this,void 0,void 0,(function*(){yield new Promise((r=>{t.onloadedmetadata=()=>{t.play().then((()=>e(this,void 0,void 0,(function*(){n.setVideoElement(t,o),r()}))))}}))}))}function ae(e,n){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width",e),t.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n),o.setAttribute("width",e),o.setAttribute("height",e),t.appendChild(o)}return t}const se="shopar-error";function le(e,n,t,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=ae("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=n,r.appendChild(e)}r.ariaLabel=t;return r.style.display="none",r}const ce="shopar-control";const de="shopar-deepar-output";const ue="shopar-main";const he="shopar-qr-output";const pe="shopar-three-output";var fe;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(fe||(fe={}));let me,ve,ge,we,ye,be,Ee,Ce,Re,Se,Ae,ke,xe,$e,Le=fe.None;function Me(e){Le=e}let Pe,Ue=!1,Te=null;function De(){Ue||(!function(){try{const e=document.createElement("style"),n=process.env.css;null!=n&&(e.innerHTML=n);const t=document.head;t.insertBefore(e,t.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),me=function(){const e=document.createElement("div");e.id=ue;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),ge=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),ve=function(e){const n=document.createElement("div");n.id=he;const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",n.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),n}(ge),me.appendChild(ve),we=function(){const e=document.createElement("div");e.id=de;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),me.appendChild(we),ye=function(){const e=document.createElement("canvas");e.id=pe;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),me.appendChild(ye),xe=function(){const e=document.createElement("div");e.className="shopar-3d-loading-bar";const n=e.style;return n.width="100%",n.height="100%",e}(),ke=function(e){const n=document.createElement("div");n.className="shopar-3d-loading-container";const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%";const o=document.createElement("div");o.className="shopar-3d-loading-bg";const r=o.style;return r.position="relative",r.overflow="hidden",o.appendChild(e),n.appendChild(o),n}(xe),me.appendChild(ke),Ae=function(){const e=document.createElement("div");e.className="shopar-ar-loading-bar";const n=e.style;return n.width="100%",n.height="100%",e}(),Se=function(e){const n=document.createElement("div");n.className="shopar-ar-loading-container";const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%";const o=document.createElement("div");o.className="shopar-ar-loading-text",o.textContent="Loading Try On...",o.style.textAlign="center",n.appendChild(o);const r=document.createElement("div");r.className="shopar-ar-loading-bg";const i=r.style;return i.position="relative",i.overflow="hidden",r.appendChild(e),n.appendChild(r),n}(Ae),me.appendChild(Se),$e=function(){const e=document.createElement("div");e.id=se;const n=e.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const t=document.createElement("div"),o=t.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(t);const r=ae("4rem",`${S}/img/icons/close.svg`);t.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",t.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",t.appendChild(a),e}(),me.appendChild($e),be=function(){const e=document.createElement("div");return e.id=ce,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),me.appendChild(be),Ee=le("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),be.appendChild(Ee),Ce=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${S}/img/icons/cube.svg`),be.appendChild(Ce),Re=le("shopar-btn-close","Close","Close ShopAR view",`${S}/img/icons/close.svg`),be.append(Re),Ue=!0)}function Ne(e,n,t,o){var r;Ie(be,e),Ie(Ee,e&&(t||n)&&Le===fe.None),Ie(Ce,e&&o&&Le===fe.None),Ie(Re,e&&Le!==fe.None),je(),Oe(),e||""===(r=$e).style.display&&Ie(r,!1)}function Ie(e,n){e.style.display=n?"":"none"}function je(){Ae.classList.remove("active"),Se.style.visibility="hidden"}function _e(){xe.classList.add("active"),ke.style.visibility="visible"}function Oe(){xe.classList.remove("active"),ke.style.visibility="hidden"}let Ge,We,Fe,qe,Be,He=!0;function Ke(n,t){return e(this,void 0,void 0,(function*(){yield Pe;const e=`https://apps.deepar.ai/${C.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:n,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),r=ge,i=new Promise(((e,n)=>{r.onload=e,r.onerror=n}));r.src=o,yield i,He=!1,ve.style.display=""}))}function Ve(){He=!0,ve.style.display="none"}let ze,Xe,Qe,Ze,Ye,Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un=!1,hn=!1;const pn=45,fn=45,mn=3,vn=.1,gn=3.5,wn=2,yn=1;let bn,En;function Cn(o){if(o!==Fe){const r=255;Fe=o,We=function(o,r,i){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const d=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],v=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${o}`).catch((()=>{throw new n("Unknown error.")}));if(!e.ok)throw new n("Unknown error.");return e})))),g=new t[0](yield(yield v.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=g.byteLength;if(c[l]=Math.min(76,r)*((a>>5)-1),152===c[l]&&(c[l]=w),i==l)return g;i=l,i^=l;for(let e=0,n=g.length;e<n;e++)c[l]^=c[i]<<13,c[l]^=c[i]>>17,c[l]^=c[i]<<5,g[e]=g[e]^c[l];return i^=c[0],i^=c[1],i^=c[2],g}))}(o,(new Date).getTime()+r,Math.random()*r),bn=null,null==sn||sn.clear()}}function Rn(e){dn.removeEventListener("change",En),En=e,dn.addEventListener("change",e)}function Sn(n,t){return e(this,void 0,void 0,(function*(){return null==bn&&(bn=(()=>e(this,void 0,void 0,(function*(){const e=new Xe.RGBELoader,o=function(e,n){const t=e.THREE,o=new t.DataTexture(n.data,n.width,n.height,void 0,n.type,void 0,t.ClampToEdgeWrapping,t.ClampToEdgeWrapping,t.LinearFilter,t.LinearFilter,1,t.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(Xe,e.parse(t));o.mapping=Qe.EquirectangularReflectionMapping,o.encoding=Qe.LinearEncoding,sn.environment=o;const r=(new Xe.GLTFLoader).setDRACOLoader((new Xe.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Qe.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Xe.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Qe.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(Ze)).setMeshoptDecoder("function"==typeof Xe.MeshoptDecoder?Xe.MeshoptDecoder():Xe.MeshoptDecoder);return yield r.parseAsync(n.buffer,"")})))()),bn}))}function An(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);ln.position.set(n[0],n[1],n[2])}function kn(e){sn.add(e.scene);const n=(new Qe.Box3).setFromObject(e.scene);Ye.position.y=n.min.y-vn,sn.add(Ye),sn.traverse((e=>{if(e instanceof Qe.Mesh){const n=e.material;n.depthWrite=!0,n instanceof Qe.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function xn(){un=!0,null!=ze&&(ze.style.display="none")}function $n(){if(un)return;requestAnimationFrame($n),Ln(),dn.update();const e=sn.background;sn.background=null,sn.overrideMaterial=on;const n=Ze.getClearAlpha();Ze.setClearAlpha(0),Ze.setRenderTarget(Je),Ze.render(sn,cn),sn.overrideMaterial=null,Mn(gn),Mn(.4*gn),Ze.setRenderTarget(null),Ze.setClearAlpha(n),sn.background=e,Ze.render(sn,ln)}function Ln(){const e=ze.clientWidth,n=ze.clientHeight;ze.width===e&&ze.height===n||(Ze.setSize(e,n,!1),ln.aspect=e/n,ln.updateProjectionMatrix())}function Mn(e){tn.visible=!0,rn.uniforms.tDiffuse.value=Je.texture,rn.uniforms.h.value=1*e/256,tn.material=rn,Ze.setRenderTarget(en),Ze.render(tn,cn),an.uniforms.tDiffuse.value=en.texture,an.uniforms.v.value=1*e/256,tn.material=an,Ze.setRenderTarget(Je),Ze.render(tn,cn),tn.visible=!1}function Pn(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Un(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const Tn=["AR","3D"];function Dn(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s}=e;Pn(t,"apiKey"),Un(t,"apiKey"),Pn(o,"sku"),Un(o,"sku"),Pn(r,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(i,"initialState",Tn),null!=a&&Un(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let Nn=0,In=0;function jn(t){var o,r;return e(this,void 0,void 0,(function*(){Dn(t);const{apiKey:i,sku:a,targetElement:s,initialState:l}=t;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),S.update(t.baseUrl);const c=function(t,o){return e(this,void 0,void 0,(function*(){const r=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:t,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!e.ok)throw new n(`API call failed with status ${e.status}.`);return e}))));try{return yield r.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a);null==M&&(P=E(),M=A(`${S}/shopar-analytics.js`),M.then((()=>{U=!0,window.ShopAR__analytics.initializeImpl(),T.forEach((e=>e()))})));const[u,h,v]=D(a,i);u("setup",{hostname:window.location.hostname}),De();const g=++In,w=yield c;u("apiResponse",w);const{category:y,arUrl:b,arKey:C,previewUrl:R,previewEnvUrl:L}=w;_n(g);const j=null!=b&&function(e){return null!=e&&f.includes(e)}(y),_=null==(null===(o=t._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=t._internalOptions)||void 0===r?void 0:r.qrEnabled),F=j&&function(e){return null!=e&&m.includes(e)}(y),q=_&&F&&!(yield function(){var n;return e(this,void 0,void 0,(function*(){return null==Z&&(Z=A(`${S}/shopar-platform.js`)),yield Z,["Android","iOS","Windows Phone",void 0].includes(null===(n=window.ShopAR__platform.platform.os)||void 0===n?void 0:n.family)}))}());_n(g),q&&function(){e(this,void 0,void 0,(function*(){null==Pe&&(Pe=A(`${S}/shopar-qr.js`))}))}();const X=j&&!q;X&&(null==O&&(O=A(`${S}/shopar-deepar.js`)),J(b),"Glasses"===y&&null==G&&(G=A(`${S}/shopar-true-scale.js`)));const Q=null!=R;var ae;Q&&(null==Ge&&(Ge=A(`${S}/shopar-three.js`)),Cn(R),(ae=null!=L?L:`${S}/env/default.hdr`)!==Be&&(Be=ae,qe=B(ae))),function(e){e.style.position="relative",null==Te?e.appendChild(me):e!==Te&&(Te.removeChild(me),e.appendChild(me)),Te=e}(s);const se=null==t.defaultUI||t.defaultUI;if(Ne(se,q,X,Q),Le===fe.AR){if(!Y)if(ne(h),X){u(x);const e=yield W;_n(g),yield te(e),_n(g)}else oe(),Me(fe.None),se&&(Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0));if(!He)if(q){u(k);try{yield Ke(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ve(),Me(fe.None),se&&(Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0))}else if(Le===fe.Preview&&!un)if(Rn(v),Q){u($),_e(),Ie(ye,!1);const e=yield We;_n(g);const n=yield qe;_n(g);const t=yield Sn(e,n);_n(g),An(y),kn(t),Ie(ye,!0),Oe()}else xn(),Me(fe.None),se&&(Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0));const le=()=>e(this,void 0,void 0,(function*(){if(q){if(Le===fe.AR)throw new n("AR already launched.");try{u(k);++Nn;return Le===fe.Preview&&Q&&!un&&xn(),Me(fe.AR),se&&(Ie(Ee,!1),Ie(Ce,!1),Ie(Re,!0)),se&&Ie($e,!1),void(yield Ke(i,a))}catch(e){const t=e instanceof Error;throw u("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!X)throw new n("Model does not have AR enabled.");if(Le===fe.AR)throw new n("AR already launched.");try{u(x);const n=++Nn;Le===fe.Preview&&Q&&!un&&xn(),Me(fe.AR),se&&(Ie(Ee,!1),Ie(Ce,!1),Ie(Re,!0)),se&&Ie($e,!1),Ae.classList.add("active"),Se.style.visibility="visible";const t=yield W;if(Nn!==n||In!==g)return;if(yield O,Nn!==n||In!==g)return;if(yield ee(we,C,y),Nn!==n||In!==g)return;if(ne(h),yield te(t),Nn!==n||In!==g)return;if(yield function(){return e(this,void 0,void 0,(function*(){if(null!=H){if(Y=!1,null==K){const e=re(V),n=N(e);K=yield I(n),yield ie(H,K,"user"===e)}H.setPaused(Y),z.style.display=""}}))}(),Nn!==n||In!==g)return}catch(e){const t=e instanceof Error;throw u("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),se&&Ie($e,!0),oe(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{je()}})),ce=()=>e(this,void 0,void 0,(function*(){if(!Q)throw new n("Model does not have 3D enabled.");if(Le===fe.Preview)throw new n("3D already launched.");try{u($);const n=++Nn;Le===fe.AR&&(X&&!Y&&oe(),Ve()),Me(fe.Preview),se&&(Ie(Ee,!1),Ie(Ce,!1),Ie(Re,!0)),se&&Ie($e,!1),_e();const t=yield We;if(Nn!==n||In!==g)return;const o=yield qe;if(Nn!==n||In!==g)return;if(yield Ge,Nn!==n||In!==g)return;if(yield function(n){return e(this,void 0,void 0,(function*(){if(ze=n,!hn){Xe=window.ShopAR__THREE,Qe=Xe.THREE,Ze=new Qe.WebGLRenderer({powerPreference:"high-performance",canvas:n,antialias:!0,alpha:!0}),Ze.outputEncoding=Qe.sRGBEncoding,Ze.toneMapping=Qe.ACESFilmicToneMapping,Ze.setPixelRatio(window.devicePixelRatio||1),Ze.setClearColor(new Qe.Color(16777215)),sn=new Qe.Scene,Ye=new Qe.Group,Ye.position.y=-.7,Je=new Qe.WebGLRenderTarget(512,512),Je.texture.generateMipmaps=!1,en=new Qe.WebGLRenderTarget(512,512),en.texture.generateMipmaps=!1;const e=new Qe.PlaneGeometry(pn,fn).rotateX(Math.PI/2),t=new Qe.MeshBasicMaterial({map:Je.texture,opacity:yn,transparent:!0,depthWrite:!1});nn=new Qe.Mesh(e,t),nn.renderOrder=1,Ye.add(nn),nn.scale.y=-1,tn=new Qe.Mesh(e),tn.visible=!1,Ye.add(tn),cn=new Qe.OrthographicCamera(-pn/2,pn/2,fn/2,-fn/2,0,mn),cn.rotation.x=Math.PI/2,Ye.add(cn),on=new Qe.MeshDepthMaterial,on.userData.darkness={value:wn},on.onBeforeCompile=function(e){e.uniforms.darkness=on.userData.darkness,e.fragmentShader=`\n uniform float darkness;\n ${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );")}\n `},on.depthTest=!1,on.depthWrite=!1,rn=new Qe.ShaderMaterial(Xe.HorizontalBlurShader),rn.depthTest=!1,an=new Qe.ShaderMaterial(Xe.VerticalBlurShader),an.depthTest=!1,ln=new Qe.PerspectiveCamera(25,1,.5),dn=new Xe.OrbitControls(ln,Ze.domElement),dn.target.set(0,.03,0),dn.dampingFactor=.3,hn=!0}Ln()}))}(ye),Nn!==n||In!==g)return;Rn(v);const r=yield Sn(t,o);if(Nn!==n||In!==g)return;An(y),kn(r),un=!1,$n(),null!=ze&&(ze.style.display="")}catch(e){const t=e instanceof Error;throw u("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{Oe()}})),de=()=>e(this,void 0,void 0,(function*(){if(Le===fe.None)throw new n("Neither AR or 3D launched.");++Nn,Le===fe.AR?(X&&!Y&&oe(),Ve()):Le===fe.Preview&&Q&&!un&&xn(),Me(fe.None),je(),Oe(),se&&(Ie($e,!1),Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0))}));return se&&((q||X)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${S}/img/icons/${null!=e&&n[e]||n.Glasses}`;Ee.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(y),Ee.onclick=le),Q&&(Ce.onclick=ce),Re.onclick=de),"AR"===l?(yield le(),_n(g)):"3D"===l&&(yield ce(),_n(g)),{launchAR:le,launch3D:ce,closeAR:()=>e(this,void 0,void 0,(function*(){if(Le!==fe.AR)throw new n("AR not launched.");++Nn,X&&!Y&&oe(),Ve(),Me(fe.None),je(),se&&(Ie($e,!1),Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(Le!==fe.Preview)throw new n("3D not launched.");++Nn,Q&&!un&&xn(),Me(fe.None),Oe(),se&&(Ie($e,!1),Ie(Re,!1),(q||X)&&Ie(Ee,!0),Q&&Ie(Ce,!0))})),close:de}}))}function _n(e){if(In!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const On={setup:function(t){return e(this,void 0,void 0,(function*(){return function(t,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new n(`${t} failed: ${e.message}`):(console.error(e),new n(`${t} failed.`))}}))}("setup",(()=>jn(t)))}))},version:C};export{On as plugin};
|
package/dist/shopar-plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class n extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const o=[Uint8Array,Uint32Array],i=o.length-2,r=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[r[a[a[i]]]][r[a[a[a.length-1]]]],l=s.charCodeAt(i),d=l^l,c=new o[1]([d]);function u(){const e=(new TextEncoder).encode(s),t=r.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[r[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=p)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),f(e,n+1)}}))}const v=["Glasses","Shoes","Watches"],w=["Shoes"];const m="0.0.6-alpha.4";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${m}/dist`;const g={update:e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>y};function b(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let C,E,R=!1;const A=[],S={organizationId:"Unknown",sku:"Unknown"};let x;function k(){P("vto_launched")}function P(e,t={}){t=Object.assign(Object.assign(Object.assign({},t),S),{vtoTime:(performance.now()-x)/1e3,vtoSessionId:E}),$((()=>{window.ShopAR__analytics.trackEventImpl(e,t)}))}function $(e){R?e():A.push(e)}function M(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function _(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const I=200,T=10;let D,L,U,j,N=!1;function O(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let G,W,z,F,q,B,H,K=!0;function V(e){e!==j&&(j=e,U=O(e),B=null,null==G||G.clearEffect(),N=!0)}function Q(e,o,i){return t(this,void 0,void 0,(function*(){return z=i,F=e,null==q&&(q=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new n("No camera available!");var r;const a=Y(i),s=M(a);P("vto_camera_asked");const l=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(i);G=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),W=yield _(s),P("vto_camera_granted"),yield J(G,W,"user"===a),"Glasses"===i&&(yield L,function(e,n){t(this,void 0,void 0,(function*(){N=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${g}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>t(this,void 0,void 0,(function*(){if(N)return void clearInterval(r);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(N)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<T)return void i.push(t);clearInterval(r);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(i)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),I)}))}(W,G)),P("vto_init_success")})))()),q}))}function X(e){return t(this,void 0,void 0,(function*(){return null==B&&(B=G.switchEffect(e)),B}))}function Z(){null!=G&&(K=!0,G.setPaused(K),null!=W&&null!=W.srcObject&&W.srcObject instanceof MediaStream&&(W.srcObject.getTracks().forEach((e=>e.stop())),W=null),G.stopCamera(),F.style.display="none")}function Y(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function J(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((i=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),i()}))))}}))}))}function ee(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const te="shopar-error";function ne(e,t,n,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ee("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=t,i.appendChild(e)}i.ariaLabel=n;const r=i.style;return r.zIndex="2",r.display="none",i}const oe="shopar-control";const ie="shopar-deepar-output";const re="shopar-loading";const ae="shopar-main";const se="shopar-qr-output";const le="shopar-three-output";var de;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(de||(de={}));let ce,ue,he,pe,fe,ve,we,me,ye,ge,be=de.None;function Ce(e){be=e}let Ee,Re=!1,Ae=null;function Se(){Re||(ce=function(){const e=document.createElement("div");e.id=ae;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),ue=function(){const e=document.createElement("div");e.id=se;const t=e.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="relative",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="flex",o.alignItems="center",o.justifyContent="center",o.backgroundColor="white",e.appendChild(n);const i=new Image,r=i.style;return r.maxWidth="100%",r.maxHeight="100%",n.appendChild(i),e}(),ce.appendChild(ue),he=function(){const e=document.createElement("div");e.id=ie;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(he),pe=function(){const e=document.createElement("canvas");e.id=le;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.zIndex="1",t.display="none",e}(),ce.appendChild(pe),fe=function(){const e=document.createElement("div");return e.id=oe,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ce.appendChild(fe),ve=ne("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),fe.appendChild(ve),we=ne("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${g}/img/icons/cube.svg`),fe.appendChild(we),me=ne("shopar-btn-close","Close","Close ShopAR view",`${g}/img/icons/close.svg`),fe.append(me),ye=function(){const e=document.createElement("div");e.id=re;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.className="shopar-spinner",n.appendChild(i),e}(),ce.appendChild(ye),ge=function(){const e=document.createElement("div");e.id=te;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=ee("4rem",`${g}/img/icons/close.svg`);n.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",n.appendChild(r);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}(),ce.appendChild(ge),Re=!0)}function xe(e,t){e.style.display=t?"":"none"}function ke(e){""===e.style.display&&xe(e,!1)}let Pe,$e,Me,_e,Ie,Te=!0;function De(e,n){return t(this,void 0,void 0,(function*(){yield Ee;const t=`https://apps.deepar.ai/${m.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:n,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(t),i=ue.firstChild.firstChild,r=new Promise(((e,t)=>{i.onload=e,i.onerror=t}));i.src=o,yield r,Te=!1,ue.style.display=""}))}function Le(){Te=!0,ue.style.display="none"}let Ue,je,Ne,Oe,Ge,We,ze,Fe,qe,Be,He,Ke,Ve,Qe,Xe,Ze,Ye=!1,Je=!1;const et=45,tt=45,nt=3,ot=.1,it=3.5,rt=2,at=1;let st;function lt(e){if(e!==Me){const i=255;Me=e,$e=function(e,i,r){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),v=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],w=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield v(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),m=new o[0](yield(yield w.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));r+=s;const y=m.byteLength;if(c[d]=Math.min(76,i)*((a>>5)-1),152===c[d]&&(c[d]=y),r==d)return m;r=d,r^=d;for(let e=0,t=m.length;e<t;e++)c[d]^=c[r]<<13,c[d]^=c[r]>>17,c[d]^=c[r]<<5,m[e]=m[e]^c[d];return r^=c[0],r^=c[1],r^=c[2],m}))}(e,(new Date).getTime()+i,Math.random()*i),st=null,null==Ve||Ve.clear()}}function dt(e,n){return t(this,void 0,void 0,(function*(){if(Ue=e,!Je){je=window.ShopAR__THREE,Ne=je.THREE,Oe=new Ne.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),Oe.outputEncoding=Ne.sRGBEncoding,Oe.toneMapping=Ne.ACESFilmicToneMapping,Oe.setPixelRatio(window.devicePixelRatio||1),Oe.setClearColor(new Ne.Color(16777215)),Ve=new Ne.Scene,Ge=new Ne.Group,Ge.position.y=-.7,We=new Ne.WebGLRenderTarget(512,512),We.texture.generateMipmaps=!1,ze=new Ne.WebGLRenderTarget(512,512),ze.texture.generateMipmaps=!1;const t=new Ne.PlaneGeometry(et,tt).rotateX(Math.PI/2),o=new Ne.MeshBasicMaterial({map:We.texture,opacity:at,transparent:!0,depthWrite:!1});Fe=new Ne.Mesh(t,o),Fe.renderOrder=1,Ge.add(Fe),Fe.scale.y=-1,qe=new Ne.Mesh(t),qe.visible=!1,Ge.add(qe),Xe=new Ne.OrthographicCamera(-et/2,et/2,tt/2,-tt/2,0,nt),Xe.rotation.x=Math.PI/2,Ge.add(Xe),Be=new Ne.MeshDepthMaterial,Be.userData.darkness={value:rt},Be.onBeforeCompile=function(e){e.uniforms.darkness=Be.userData.darkness,e.fragmentShader=`\n uniform float darkness;\n ${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );")}\n `},Be.depthTest=!1,Be.depthWrite=!1,He=new Ne.ShaderMaterial(je.HorizontalBlurShader),He.depthTest=!1,Ke=new Ne.ShaderMaterial(je.VerticalBlurShader),Ke.depthTest=!1,Qe=new Ne.PerspectiveCamera(25,1,.5);const i=function(e){var t;const n={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?n.Glasses:null!==(t=n[e])&&void 0!==t?t:n.Glasses}(n);Qe.position.set(i[0],i[1],i[2]),Ze=new je.OrbitControls(Qe,Oe.domElement),Ze.target.set(0,.03,0),Ze.dampingFactor=.3;{const e=function(e,t){let n;return()=>{n||e(),clearTimeout(n),n=setTimeout((()=>{n=void 0}),t)}}((()=>{P("preview_interacted")}),200);Ze.addEventListener("end",e)}Je=!0}ft()}))}function ct(e,n){return t(this,void 0,void 0,(function*(){return null==st&&(st=(()=>t(this,void 0,void 0,(function*(){const t=new je.RGBELoader,o=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(je,t.parse(n));o.mapping=Ne.EquirectangularReflectionMapping,o.encoding=Ne.LinearEncoding,Ve.environment=o;const i=(new je.GLTFLoader).setDRACOLoader((new je.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new je.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ne.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(Oe)).setMeshoptDecoder("function"==typeof je.MeshoptDecoder?je.MeshoptDecoder():je.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),st}))}function ut(e){return t(this,void 0,void 0,(function*(){Ve.add(e.scene);const t=(new Ne.Box3).setFromObject(e.scene);Ge.position.y=t.min.y-ot,Ve.add(Ge),Ve.traverse((e=>{if(e instanceof Ne.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ne.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))}function ht(){Ye=!0,Ue.style.display="none"}function pt(){if(Ye)return;requestAnimationFrame(pt),ft(),Ze.update();const e=Ve.background;Ve.background=null,Ve.overrideMaterial=Be;const t=Oe.getClearAlpha();Oe.setClearAlpha(0),Oe.setRenderTarget(We),Oe.render(Ve,Xe),Ve.overrideMaterial=null,vt(it),vt(.4*it),Oe.setRenderTarget(null),Oe.setClearAlpha(t),Ve.background=e,Oe.render(Ve,Qe)}function ft(){const e=Ue.clientWidth,t=Ue.clientHeight;Ue.width===e&&Ue.height===t||(Oe.setSize(e,t,!1),Qe.aspect=e/t,Qe.updateProjectionMatrix())}function vt(e){qe.visible=!0,He.uniforms.tDiffuse.value=We.texture,He.uniforms.h.value=1*e/256,qe.material=He,Oe.setRenderTarget(ze),Oe.render(qe,Xe),Ke.uniforms.tDiffuse.value=ze.texture,Ke.uniforms.v.value=1*e/256,qe.material=Ke,Oe.setRenderTarget(We),Oe.render(qe,Xe),qe.visible=!1}function wt(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function mt(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const yt=["AR","3D"];function gt(e){const{apiKey:t,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;wt(t,"apiKey"),mt(t,"apiKey"),wt(o,"sku"),mt(o,"sku"),wt(i,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(r,"initialState",yt),null!=a&&mt(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let bt=0,Ct=0;function Et(e){var o,i;return t(this,void 0,void 0,(function*(){gt(e);const{apiKey:r,sku:a,targetElement:s,initialState:l}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),g.update(e.baseUrl);const d=function(e,o){return t(this,void 0,void 0,(function*(){const i=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield i.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(r,a);null==C&&(C=b(`${g}/shopar-analytics.js`),C.then((()=>{R=!0,E=window.ShopAR__analytics.uuidv4(),A.forEach((e=>e()))}))),function(e,t){S.organizationId=e,S.sku=t,x=performance.now(),$((()=>{window.ShopAR__analytics.initializeImpl()}))}(r,a),Se();const c=++Ct,{category:h,arUrl:p,arKey:m,previewUrl:y,previewEnvUrl:I}=yield d;Rt(c),P("initialized");const T=null!=p&&function(e){return null!=e&&v.includes(e)}(h),j=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled),N=T&&function(e){return null!=e&&w.includes(e)}(h),q=j&&N&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==H&&(H=b(`${g}/shopar-platform.js`)),yield H,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}());Rt(c),q&&function(){t(this,void 0,void 0,(function*(){null==Ee&&(Ee=b(`${g}/shopar-qr.js`))}))}();const B=T&&!q;B&&(null==D&&(D=b(`${g}/shopar-deepar.js`)),V(p),"Glasses"===h&&null==L&&(L=b(`${g}/shopar-true-scale.js`)));const ee=null!=y;var te;ee&&(null==Pe&&(Pe=b(`${g}/shopar-three.js`)),lt(y),(te=null!=I?I:`${g}/env/default.hdr`)!==Ie&&(Ie=te,_e=O(te))),function(e){e.style.position="relative",null==Ae?e.appendChild(ce):e!==Ae&&(Ae.removeChild(ce),e.appendChild(ce)),Ae=e}(s);const ne=null==e.defaultUI||e.defaultUI;if(function(e,t,n,o){xe(fe,e),xe(ve,e&&(n||t)&&be===de.None),xe(we,e&&o&&be===de.None),xe(me,e&&be!==de.None),e||ke(ye),e||ke(ge)}(ne,q,B,ee),be===de.AR){if(!K)if(B){const e=yield U;Rt(c),yield X(e),Rt(c)}else Z(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0));if(!Te)if(q)try{yield De(r,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}else Le(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))}else if(be===de.Preview&&!Ye)if(ee){const e=yield $e;Rt(c);const t=yield _e;Rt(c);const n=yield ct(e,t);Rt(c),ut(n)}else ht(),Ce(de.None),ne&&(xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0));const oe=()=>t(this,void 0,void 0,(function*(){if(q){if(be===de.AR)throw new n("AR already launched.");const e=++bt;be===de.Preview&&ee&&!Ye&&ht(),Ce(de.AR),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),k(),ne&&(xe(ge,!1),xe(ye,!0));try{yield De(r,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}if(bt!==e||Ct!==c)return;return void(ne&&xe(ye,!1))}if(!B)throw new n("Model does not have AR enabled.");if(be===de.AR)throw new n("AR already launched.");const e=++bt;be===de.Preview&&ee&&!Ye&&ht(),Ce(de.AR),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),k(),ne&&(xe(ge,!1),xe(ye,!0));const o=yield U;if(bt===e&&Ct===c&&(yield D,bt===e&&Ct===c)){try{yield Q(he,m,h)}catch(e){throw function(e){P("vto_camera_denied",{error:e})}(e),ne&&(xe(ye,!1),xe(ge,!0)),e}bt===e&&Ct===c&&(yield X(o),bt===e&&Ct===c&&(yield function(){return t(this,void 0,void 0,(function*(){if(null!=G){if(K=!1,null==W){const e=Y(z),t=M(e);W=yield _(t),yield J(G,W,"user"===e)}G.setPaused(K),F.style.display=""}}))}(),bt===e&&Ct===c&&ne&&xe(ye,!1)))}})),ie=()=>t(this,void 0,void 0,(function*(){if(!ee)throw new n("Model does not have 3D enabled.");if(be===de.Preview)throw new n("3D already launched.");const e=++bt;be===de.AR&&(B&&!K&&Z(),Le()),Ce(de.Preview),ne&&(xe(ve,!1),xe(we,!1),xe(me,!0)),P("preview_launched"),ne&&(xe(ge,!1),xe(ye,!0));const t=yield $e;if(bt!==e||Ct!==c)return;const o=yield _e;if(bt!==e||Ct!==c)return;if(yield Pe,bt!==e||Ct!==c)return;if(yield dt(pe,h),bt!==e||Ct!==c)return;const i=yield ct(t,o);bt===e&&Ct===c&&(ut(i),Ye=!1,pt(),Ue.style.display="",ne&&xe(ye,!1))})),re=()=>t(this,void 0,void 0,(function*(){if(be===de.None)throw new n("Neither AR or 3D launched.");++bt,be===de.AR?(B&&!K&&Z(),Le()):be===de.Preview&&ee&&!Ye&&ht(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))}));return ne&&((q||B)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=`${g}/img/icons/${null!=e&&t[e]||t.Glasses}`;ve.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n)}(h),ve.onclick=oe),ee&&(we.onclick=ie),me.onclick=re),"AR"===l?(yield oe(),Rt(c)):"3D"===l&&(yield ie(),Rt(c)),{launchAR:oe,launch3D:ie,closeAR:()=>t(this,void 0,void 0,(function*(){if(be!==de.AR)throw new n("AR not launched.");++bt,B&&!K&&Z(),Le(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))})),close3D:()=>t(this,void 0,void 0,(function*(){if(be!==de.Preview)throw new n("3D not launched.");++bt,ee&&!Ye&&ht(),Ce(de.None),ne&&(xe(ye,!1),xe(ge,!1),xe(me,!1),(q||B)&&xe(ve,!0),ee&&xe(we,!0))})),close:re}}))}function Rt(e){if(Ct!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const At={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Et(e)))}))},version:m};e.plugin=At}));
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function n(e,n,t,o){return new(t||(t=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,s)}l((o=o.apply(e,n||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem;pointer-events:none}.shopar-btn{padding:.5rem .75rem;display:flex;justify-content:center;align-items:center;gap:.25rem;background-color:#fff;border:1px solid #ddd;border-radius:9999px;cursor:pointer;pointer-events:auto}.shopar-btn:hover{background-color:#f5f5f5}.shopar-ar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-ar-loading-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-ar-loading-bar{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-ar-loading-bar.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}.shopar-3d-loading-container{display:flex;align-items:end}.shopar-3d-loading-bg{width:100%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-3d-loading-bar{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-3d-loading-bar.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const o=[Uint8Array,Uint32Array],i=o.length-2,r=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[r[a[a[i]]]][r[a[a[a.length-1]]]],l=s.charCodeAt(i),c=l^l,d=new o[1]([c]);function u(){const e=(new TextEncoder).encode(s),n=r.map((e=>e.length));for(let t=0;t<e.length;t++)e[t]^=n[t%n.length];return window[r[n[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,t=0){return n(this,void 0,void 0,(function*(){try{return yield e()}catch(n){if(t>=p)throw n;return yield new Promise((e=>setTimeout(e,h[t]))),f(e,t+1)}}))}const m=["Glasses","Shoes","Watches"],v=["Shoes"];let g;const w=new Uint8Array(16);function y(){if(!g&&(g="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!g))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return g(w)}const b=[];for(let e=0;e<256;++e)b.push((e+256).toString(16).slice(1));var E={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function C(e,n,t){if(E.randomUUID&&!n&&!e)return E.randomUUID();const o=(e=e||{}).random||(e.rng||y)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=o[e];return n}return function(e,n=0){return b[e[n+0]]+b[e[n+1]]+b[e[n+2]]+b[e[n+3]]+"-"+b[e[n+4]]+b[e[n+5]]+"-"+b[e[n+6]]+b[e[n+7]]+"-"+b[e[n+8]]+b[e[n+9]]+"-"+b[e[n+10]]+b[e[n+11]]+b[e[n+12]]+b[e[n+13]]+b[e[n+14]]+b[e[n+15]]}(o)}const R="0.0.6-alpha.6";let S=`https://cdn.jsdelivr.net/npm/shopar-plugin@${R}/dist`;const A={update:e=>{null!=e&&(S=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>S};function k(e){return n(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const n=document.createElement("script");return n.setAttribute("src",e),n.setAttribute("crossorigin","anonymous"),new Promise((e=>{n.addEventListener("load",(()=>e()),!1),n.addEventListener("error",(()=>e()),!1),document.body.appendChild(n)}))}importScripts(e.toString())}))}const x="qrLaunch",$="arLaunch",L="previewLaunch",M="heartbeat";let P,U,T=!1;const D=[];function N(e,n){const t=performance.now(),o=C();let i=0,r=0,a=0,s=0,l=0,c=!1;const d=(i,r={})=>{var a;r=Object.assign(Object.assign({},r),{pluginVersion:R,sessionId:U,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},T?a():D.push(a)};return window.setInterval((()=>{c&&(i=r+a,c=!1,d(M,{engagementTotal:i,engagementAR:r,engagement3D:a}))}),1e3),[d,()=>{const e=performance.now(),n=e-s;s=e,n<200&&(r+=n,c=!0)},()=>{const e=performance.now(),n=e-l;l=e,n<200&&(a+=n,c=!0)}]}function I(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function j(e){return n(this,void 0,void 0,(function*(){const n=document.createElement("video");return n.setAttribute("playsinline","playsinline"),n.srcObject=yield e,n}))}const _=200,O=10;let G,W,F,q,B=!1;function H(e){return n(this,void 0,void 0,(function*(){const o=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield fetch(e).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!n.ok)throw new t(`Resource download failed with status ${n.status}.`);return n}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let K,V,z,X,Q,Z,Y,J=!0;function ee(e){e!==q&&(q=e,F=H(e),Z=null,null==K||K.clearEffect(),B=!0)}function ne(e,o,i){return n(this,void 0,void 0,(function*(){return z=i,X=e,null==Q&&(Q=(()=>n(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new t("No camera available!");var r;const a=re(i),s=I(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(i);K=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),V=yield j(s),yield ae(K,V,"user"===a),"Glasses"===i&&(yield W,function(e,t){n(this,void 0,void 0,(function*(){B=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${A}/wasm/mediapipe`,e);const i=[],r=setInterval((()=>n(this,void 0,void 0,(function*(){if(B)return void clearInterval(r);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(B)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<O)return void i.push(n);clearInterval(r);const a=137/(function(e){let n=0;const t=e.length;for(let o=0;o<t;o++)n+=e[o];return n/t}(i)+5);t.changeParameterVector("GLASSES","","scale",a,a,a,0),t.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),_)}))}(V,K))})))()),Q}))}function te(e){K.callbacks.onFaceTracked=n=>{n.some((e=>e.detected))&&e()},K.callbacks.onFeetTracked=(n,t)=>{(n.detected||t.detected)&&e()},K.callbacks.onWristTracked=n=>{n.detected&&e()}}function oe(e){return n(this,void 0,void 0,(function*(){return null==Z&&(Z=K.switchEffect(e)),Z}))}function ie(){null!=K&&(J=!0,K.setPaused(J),null!=V&&null!=V.srcObject&&V.srcObject instanceof MediaStream&&(V.srcObject.getTracks().forEach((e=>e.stop())),V=null),K.stopCamera(),X.style.display="none")}function re(e){var n;return null==e?"user":null!==(n={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==n?n:"user"}function ae(e,t,o){return n(this,void 0,void 0,(function*(){yield new Promise((i=>{t.onloadedmetadata=()=>{t.play().then((()=>n(this,void 0,void 0,(function*(){e.setVideoElement(t,o),i()}))))}}))}))}function se(e,n){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width",e),t.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",n),o.setAttribute("width",e),o.setAttribute("height",e),t.appendChild(o)}return t}const le="shopar-error";function ce(e,n,t,o){const i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=se("1.75rem",o);i.appendChild(e)}{const e=document.createElement("span");e.textContent=n,i.appendChild(e)}i.ariaLabel=t;return i.style.display="none",i}const de="shopar-control";const ue="shopar-deepar-output";const he="shopar-main";const pe="shopar-qr-output";const fe="shopar-three-output";var me;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(me||(me={}));let ve,ge,we,ye,be,Ee,Ce,Re,Se,Ae,ke,xe,$e,Le,Me=me.None;function Pe(e){Me=e}let Ue,Te=!1,De=null;function Ne(){Te||(!function(){try{const e=document.createElement("style"),n=process.env.css;null!=n&&(e.innerHTML=n);const t=document.head;t.insertBefore(e,t.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),ve=function(){const e=document.createElement("div");e.id=he;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),we=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),ge=function(e){const n=document.createElement("div");n.id=pe;const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none";const o=document.createElement("div");o.className="shopar-qr";const i=o.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(o);const r=document.createElement("div");r.innerText="Scan on mobile or tablet to try on",r.style.textAlign="center",o.appendChild(r);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),n}(we),ve.appendChild(ge),ye=function(){const e=document.createElement("div");e.id=ue;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),ve.appendChild(ye),be=function(){const e=document.createElement("canvas");e.id=fe;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),ve.appendChild(be),$e=function(){const e=document.createElement("div");e.className="shopar-3d-loading-bar";const n=e.style;return n.width="100%",n.height="100%",e}(),xe=function(e){const n=document.createElement("div");n.className="shopar-3d-loading-container";const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%";const o=document.createElement("div");o.className="shopar-3d-loading-bg";const i=o.style;return i.position="relative",i.overflow="hidden",o.appendChild(e),n.appendChild(o),n}($e),ve.appendChild(xe),ke=function(){const e=document.createElement("div");e.className="shopar-ar-loading-bar";const n=e.style;return n.width="100%",n.height="100%",e}(),Ae=function(e){const n=document.createElement("div");n.className="shopar-ar-loading-container";const t=n.style;t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%";const o=document.createElement("div");o.className="shopar-ar-loading-text",o.textContent="Loading Try On...",o.style.textAlign="center",n.appendChild(o);const i=document.createElement("div");i.className="shopar-ar-loading-bg";const r=i.style;return r.position="relative",r.overflow="hidden",i.appendChild(e),n.appendChild(i),n}(ke),ve.appendChild(Ae),Le=function(){const e=document.createElement("div");e.id=le;const n=e.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const t=document.createElement("div"),o=t.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(t);const i=se("4rem",`${A}/img/icons/close.svg`);t.appendChild(i);const r=document.createElement("div");r.className="shopar-error-title",r.textContent="Camera Error",t.appendChild(r);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",t.appendChild(a),e}(),ve.appendChild(Le),Ee=function(){const e=document.createElement("div");return e.id=de,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}(),ve.appendChild(Ee),Ce=ce("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E"),Ee.appendChild(Ce),Re=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${A}/img/icons/cube.svg`),Ee.appendChild(Re),Se=ce("shopar-btn-close","Close","Close ShopAR view",`${A}/img/icons/close.svg`),Ee.append(Se),Te=!0)}function Ie(e,n,t,o){var i;je(Ee,e),je(Ce,e&&(t||n)&&Me===me.None),je(Re,e&&o&&Me===me.None),je(Se,e&&Me!==me.None),_e(),Ge(),e||""===(i=Le).style.display&&je(i,!1)}function je(e,n){e.style.display=n?"":"none"}function _e(){ke.classList.remove("active"),Ae.style.visibility="hidden"}function Oe(){$e.classList.add("active"),xe.style.visibility="visible"}function Ge(){$e.classList.remove("active"),xe.style.visibility="hidden"}let We,Fe,qe,Be,He,Ke=!0;function Ve(e,t){return n(this,void 0,void 0,(function*(){yield Ue;const n=`https://apps.deepar.ai/${R.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(n),i=we,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Ke=!1,ge.style.display=""}))}function ze(){Ke=!0,ge.style.display="none"}let Xe,Qe,Ze,Ye,Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn=!1,pn=!1;const fn=45,mn=45,vn=3,gn=.1,wn=3.5,yn=2,bn=1;let En,Cn;function Rn(e){if(e!==qe){const i=255;qe=e,Fe=function(e,i,r){return n(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),m=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],v=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield m(`${e}`).catch((()=>{throw new t("Unknown error.")}));if(!n.ok)throw new t("Unknown error.");return n})))),g=new o[0](yield(yield v.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));r+=s;const w=g.byteLength;if(d[c]=Math.min(76,i)*((a>>5)-1),152===d[c]&&(d[c]=w),r==c)return g;r=c,r^=c;for(let e=0,n=g.length;e<n;e++)d[c]^=d[r]<<13,d[c]^=d[r]>>17,d[c]^=d[r]<<5,g[e]=g[e]^d[c];return r^=d[0],r^=d[1],r^=d[2],g}))}(e,(new Date).getTime()+i,Math.random()*i),En=null,null==ln||ln.clear()}}function Sn(e){un.removeEventListener("change",Cn),Cn=e,un.addEventListener("change",e)}function An(e,t){return n(this,void 0,void 0,(function*(){return null==En&&(En=(()=>n(this,void 0,void 0,(function*(){const n=new Qe.RGBELoader,o=function(e,n){const t=e.THREE,o=new t.DataTexture(n.data,n.width,n.height,void 0,n.type,void 0,t.ClampToEdgeWrapping,t.ClampToEdgeWrapping,t.LinearFilter,t.LinearFilter,1,t.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(Qe,n.parse(t));o.mapping=Ze.EquirectangularReflectionMapping,o.encoding=Ze.LinearEncoding,ln.environment=o;const i=(new Qe.GLTFLoader).setDRACOLoader((new Qe.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ze.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Qe.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${Ze.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(Ye)).setMeshoptDecoder("function"==typeof Qe.MeshoptDecoder?Qe.MeshoptDecoder():Qe.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),En}))}function kn(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-72.8,72.8,54.6],Watches:[0,-10,40],Handbags:[40,0,0],Rings:[0,0,10]};return null==e?t.Glasses:null!==(n=t[e])&&void 0!==n?n:t.Glasses}(e);cn.position.set(n[0],n[1],n[2])}function xn(e){ln.add(e.scene);const n=(new Ze.Box3).setFromObject(e.scene);Je.position.y=n.min.y-gn,ln.add(Je),ln.traverse((e=>{if(e instanceof Ze.Mesh){const n=e.material;n.depthWrite=!0,n instanceof Ze.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function $n(){hn=!0,null!=Xe&&(Xe.style.display="none")}function Ln(){if(hn)return;requestAnimationFrame(Ln),Mn(),un.update();const e=ln.background;ln.background=null,ln.overrideMaterial=rn;const n=Ye.getClearAlpha();Ye.setClearAlpha(0),Ye.setRenderTarget(en),Ye.render(ln,dn),ln.overrideMaterial=null,Pn(wn),Pn(.4*wn),Ye.setRenderTarget(null),Ye.setClearAlpha(n),ln.background=e,Ye.render(ln,cn)}function Mn(){const e=Xe.clientWidth,n=Xe.clientHeight;Xe.width===e&&Xe.height===n||(Ye.setSize(e,n,!1),cn.aspect=e/n,cn.updateProjectionMatrix())}function Pn(e){on.visible=!0,an.uniforms.tDiffuse.value=en.texture,an.uniforms.h.value=1*e/256,on.material=an,Ye.setRenderTarget(nn),Ye.render(on,dn),sn.uniforms.tDiffuse.value=nn.texture,sn.uniforms.v.value=1*e/256,on.material=sn,Ye.setRenderTarget(en),Ye.render(on,dn),on.visible=!1}function Un(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Tn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const Dn=["AR","3D"];function Nn(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;Un(n,"apiKey"),Tn(n,"apiKey"),Un(o,"sku"),Tn(o,"sku"),Un(i,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(i,"targetElement"),null!=r&&function(e,n,o){if("string"!=typeof e)throw new t(`'${n}' must be a string.`);if(!o.includes(e))throw new t(`'${n}' must be ${o.join("' or '")}.`)}(r,"initialState",Dn),null!=a&&Tn(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let In=0,jn=0;function _n(e){var o,i;return n(this,void 0,void 0,(function*(){Nn(e);const{apiKey:r,sku:a,targetElement:s,initialState:l}=e;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(s),A.update(e.baseUrl);const c=function(e,o){return n(this,void 0,void 0,(function*(){const i=yield f((()=>n(this,void 0,void 0,(function*(){const n=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!n.ok)throw new t(`API call failed with status ${n.status}.`);return n}))));try{return yield i.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(r,a);null==P&&(U=C(),P=k(`${A}/shopar-analytics.js`),P.then((()=>{T=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[d,h,p]=N(a,r);d("setup",{hostname:window.location.hostname}),Ne();const g=++jn,w=yield c;d("apiResponse",w);const{category:y,arUrl:b,arKey:E,previewUrl:R,previewEnvUrl:S}=w;On(g);const M=null!=b&&function(e){return null!=e&&m.includes(e)}(y),_=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled),O=M&&function(e){return null!=e&&v.includes(e)}(y),q=_&&O&&!(yield function(){var e;return n(this,void 0,void 0,(function*(){return null==Y&&(Y=k(`${A}/shopar-platform.js`)),yield Y,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}());On(g),q&&function(){n(this,void 0,void 0,(function*(){null==Ue&&(Ue=k(`${A}/shopar-qr.js`))}))}();const B=M&&!q;B&&(null==G&&(G=k(`${A}/shopar-deepar.js`)),ee(b),"Glasses"===y&&null==W&&(W=k(`${A}/shopar-true-scale.js`)));const Q=null!=R;var Z;Q&&(null==We&&(We=k(`${A}/shopar-three.js`)),Rn(R),(Z=null!=S?S:`${A}/env/default.hdr`)!==He&&(He=Z,Be=H(Z))),function(e){e.style.position="relative",null==De?e.appendChild(ve):e!==De&&(De.removeChild(ve),e.appendChild(ve)),De=e}(s);const se=null==e.defaultUI||e.defaultUI;if(Ie(se,q,B,Q),Me===me.AR){if(!J)if(te(h),B){d($);const e=yield F;On(g),yield oe(e),On(g)}else ie(),Pe(me.None),se&&(je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0));if(!Ke)if(q){d(x);try{yield Ve(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ze(),Pe(me.None),se&&(je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0))}else if(Me===me.Preview&&!hn)if(Sn(p),Q){d(L),Oe(),je(be,!1);const e=yield Fe;On(g);const n=yield Be;On(g);const t=yield An(e,n);On(g),kn(y),xn(t),je(be,!0),Ge()}else $n(),Pe(me.None),se&&(je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0));const le=()=>n(this,void 0,void 0,(function*(){if(q){if(Me===me.AR)throw new t("AR already launched.");try{d(x);++In;return Me===me.Preview&&Q&&!hn&&$n(),Pe(me.AR),se&&(je(Ce,!1),je(Re,!1),je(Se,!0)),se&&je(Le,!1),void(yield Ve(r,a))}catch(e){const n=e instanceof Error;throw d("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!B)throw new t("Model does not have AR enabled.");if(Me===me.AR)throw new t("AR already launched.");try{d($);const e=++In;Me===me.Preview&&Q&&!hn&&$n(),Pe(me.AR),se&&(je(Ce,!1),je(Re,!1),je(Se,!0)),se&&je(Le,!1),ke.classList.add("active"),Ae.style.visibility="visible";const t=yield F;if(In!==e||jn!==g)return;if(yield G,In!==e||jn!==g)return;if(yield ne(ye,E,y),In!==e||jn!==g)return;if(te(h),yield oe(t),In!==e||jn!==g)return;if(yield function(){return n(this,void 0,void 0,(function*(){if(null!=K){if(J=!1,null==V){const e=re(z),n=I(e);V=yield j(n),yield ae(K,V,"user"===e)}K.setPaused(J),X.style.display=""}}))}(),In!==e||jn!==g)return}catch(e){const n=e instanceof Error;throw d("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),se&&je(Le,!0),ie(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{_e()}})),ce=()=>n(this,void 0,void 0,(function*(){if(!Q)throw new t("Model does not have 3D enabled.");if(Me===me.Preview)throw new t("3D already launched.");try{d(L);const e=++In;Me===me.AR&&(B&&!J&&ie(),ze()),Pe(me.Preview),se&&(je(Ce,!1),je(Re,!1),je(Se,!0)),se&&je(Le,!1),Oe();const t=yield Fe;if(In!==e||jn!==g)return;const o=yield Be;if(In!==e||jn!==g)return;if(yield We,In!==e||jn!==g)return;if(yield function(e){return n(this,void 0,void 0,(function*(){if(Xe=e,!pn){Qe=window.ShopAR__THREE,Ze=Qe.THREE,Ye=new Ze.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),Ye.outputEncoding=Ze.sRGBEncoding,Ye.toneMapping=Ze.ACESFilmicToneMapping,Ye.setPixelRatio(window.devicePixelRatio||1),Ye.setClearColor(new Ze.Color(16777215)),ln=new Ze.Scene,Je=new Ze.Group,Je.position.y=-.7,en=new Ze.WebGLRenderTarget(512,512),en.texture.generateMipmaps=!1,nn=new Ze.WebGLRenderTarget(512,512),nn.texture.generateMipmaps=!1;const n=new Ze.PlaneGeometry(fn,mn).rotateX(Math.PI/2),t=new Ze.MeshBasicMaterial({map:en.texture,opacity:bn,transparent:!0,depthWrite:!1});tn=new Ze.Mesh(n,t),tn.renderOrder=1,Je.add(tn),tn.scale.y=-1,on=new Ze.Mesh(n),on.visible=!1,Je.add(on),dn=new Ze.OrthographicCamera(-fn/2,fn/2,mn/2,-mn/2,0,vn),dn.rotation.x=Math.PI/2,Je.add(dn),rn=new Ze.MeshDepthMaterial,rn.userData.darkness={value:yn},rn.onBeforeCompile=function(e){e.uniforms.darkness=rn.userData.darkness,e.fragmentShader=`\n uniform float darkness;\n ${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );")}\n `},rn.depthTest=!1,rn.depthWrite=!1,an=new Ze.ShaderMaterial(Qe.HorizontalBlurShader),an.depthTest=!1,sn=new Ze.ShaderMaterial(Qe.VerticalBlurShader),sn.depthTest=!1,cn=new Ze.PerspectiveCamera(25,1,.5),un=new Qe.OrbitControls(cn,Ye.domElement),un.target.set(0,.03,0),un.dampingFactor=.3,pn=!0}Mn()}))}(be),In!==e||jn!==g)return;Sn(p);const i=yield An(t,o);if(In!==e||jn!==g)return;kn(y),xn(i),hn=!1,Ln(),null!=Xe&&(Xe.style.display="")}catch(e){const n=e instanceof Error;throw d("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{Ge()}})),de=()=>n(this,void 0,void 0,(function*(){if(Me===me.None)throw new t("Neither AR or 3D launched.");++In,Me===me.AR?(B&&!J&&ie(),ze()):Me===me.Preview&&Q&&!hn&&$n(),Pe(me.None),_e(),Ge(),se&&(je(Le,!1),je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0))}));return se&&((q||B)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${A}/img/icons/${null!=e&&n[e]||n.Glasses}`;Ce.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(y),Ce.onclick=le),Q&&(Re.onclick=ce),Se.onclick=de),"AR"===l?(yield le(),On(g)):"3D"===l&&(yield ce(),On(g)),{launchAR:le,launch3D:ce,closeAR:()=>n(this,void 0,void 0,(function*(){if(Me!==me.AR)throw new t("AR not launched.");++In,B&&!J&&ie(),ze(),Pe(me.None),_e(),se&&(je(Le,!1),je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0))})),close3D:()=>n(this,void 0,void 0,(function*(){if(Me!==me.Preview)throw new t("3D not launched.");++In,Q&&!hn&&$n(),Pe(me.None),Ge(),se&&(je(Le,!1),je(Se,!1),(q||B)&&je(Ce,!0),Q&&je(Re,!0))})),close:de}}))}function On(e){if(jn!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Gn={setup:function(e){return n(this,void 0,void 0,(function*(){return function(e,o){return n(this,void 0,void 0,(function*(){try{return o()}catch(n){throw n instanceof Error?new t(`${e} failed: ${n.message}`):(console.error(n),new t(`${e} failed.`))}}))}("setup",(()=>_n(e)))}))},version:R};e.plugin=Gn}));
|
package/dist/styles/default.css
CHANGED
|
@@ -23,16 +23,56 @@
|
|
|
23
23
|
.shopar-btn:hover {
|
|
24
24
|
background-color: #f5f5f5;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
.shopar-ar-loading-container {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: 1rem;
|
|
32
|
+
background-color: #ffffff;
|
|
33
|
+
}
|
|
34
|
+
.shopar-ar-loading-bg {
|
|
35
|
+
width: 80%;
|
|
36
|
+
height: 0.5rem;
|
|
37
|
+
background-color: #e5e7eb;
|
|
34
38
|
border-radius: 9999px;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
}
|
|
40
|
+
.shopar-ar-loading-bar {
|
|
41
|
+
background-color: #1434f7;
|
|
42
|
+
border-radius: 9999px;
|
|
43
|
+
transition: none;
|
|
44
|
+
transform: translateX(-100%);
|
|
45
|
+
will-change: transform;
|
|
46
|
+
}
|
|
47
|
+
.shopar-ar-loading-bar.active {
|
|
48
|
+
transition: transform 5000ms cubic-bezier(0,0,.2,1);
|
|
49
|
+
transform: none;
|
|
50
|
+
}
|
|
51
|
+
.shopar-qr {
|
|
52
|
+
display: flex;
|
|
53
|
+
flex-direction: column;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
align-items: center;
|
|
56
|
+
background-color: #ffffff;
|
|
57
|
+
}
|
|
58
|
+
.shopar-3d-loading-container {
|
|
59
|
+
display: flex;
|
|
60
|
+
align-items: end;
|
|
61
|
+
}
|
|
62
|
+
.shopar-3d-loading-bg {
|
|
63
|
+
width: 100%;
|
|
64
|
+
height: 0.5rem;
|
|
65
|
+
background-color: #e5e7eb;
|
|
66
|
+
border-radius: 9999px;
|
|
67
|
+
}
|
|
68
|
+
.shopar-3d-loading-bar {
|
|
69
|
+
background-color: #1434f7;
|
|
70
|
+
border-radius: 9999px;
|
|
71
|
+
transition: none;
|
|
72
|
+
transform: translateX(-100%);
|
|
73
|
+
will-change: transform;
|
|
74
|
+
}
|
|
75
|
+
.shopar-3d-loading-bar.active {
|
|
76
|
+
transition: transform 5000ms cubic-bezier(0,0,.2,1);
|
|
77
|
+
transform: none;
|
|
38
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shopar-plugin",
|
|
3
|
-
"version": "0.0.6-alpha.
|
|
3
|
+
"version": "0.0.6-alpha.6",
|
|
4
4
|
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rm -rf dist",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"@types/uuid": "^9.0.6",
|
|
54
54
|
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
|
55
55
|
"@typescript-eslint/parser": "^6.4.1",
|
|
56
|
+
"clean-css": "^5.3.3",
|
|
56
57
|
"eslint": "^8.47.0",
|
|
57
58
|
"eslint-config-prettier": "^9.0.0",
|
|
58
59
|
"prettier": "^3.0.2",
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
"rollup-plugin-copy": "^3.4.0",
|
|
61
62
|
"rollup-plugin-delete": "^2.0.0",
|
|
62
63
|
"rollup-plugin-dts": "^6.0.0",
|
|
64
|
+
"rollup-plugin-inject-process-env": "^1.3.1",
|
|
63
65
|
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
64
66
|
"tslib": "^2.6.2",
|
|
65
67
|
"typescript": "^5.0.4"
|