shopar-plugin 0.0.6 → 0.0.7-alpha.0
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/README.md
CHANGED
|
@@ -32,7 +32,7 @@ There are two distinct ways of integrating the plugin: via Script tag and via NP
|
|
|
32
32
|
Add the following script to your HTML.
|
|
33
33
|
|
|
34
34
|
```html
|
|
35
|
-
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@
|
|
35
|
+
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@{{VERSION}}/dist/shopar-plugin.js"></script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
It is possible to use a different CDN instead of [jsDelivr](https://www.jsdelivr.com/) (e.g. [cdnjs](https://cdnjs.com/), [unpkg](https://www.unpkg.com/)), or even a relative path if the plugin is distributed as a static asset to your app. Just make sure to set the `baseUrl` parameter accordingly (see [setup options](#shoparpluginsetupoptions) for more details).
|
|
@@ -143,7 +143,7 @@ Options used for the plugin setup:
|
|
|
143
143
|
- `baseUrl` (optional)
|
|
144
144
|
- Type: `string`
|
|
145
145
|
- If provided, defines where the additional ShopAR plugin files are fetched from.
|
|
146
|
-
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@
|
|
146
|
+
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@{{VERSION}}/dist`
|
|
147
147
|
|
|
148
148
|
## License
|
|
149
149
|
|
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 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
|
|
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,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-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.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}"};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 C(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 E="0.0.6";let R=`https://cdn.jsdelivr.net/npm/shopar-plugin@${E}/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",L="previewLaunch",$="heartbeat";let M,P,U=!1;const D=[];function T(e,n){const t=performance.now(),o=C();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:E,sessionId:P,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},U?a():D.push(a)};return window.setInterval((()=>{c&&(r=i+a,c=!1,d($,{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 I(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function N(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=I(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 N(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";function ue(e){const n=document.createElement("div");n.className=e,n.classList.add("shopar-loading-container",e);const t=n.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",n}function he(e,n){const t=document.createElement("div");return t.classList.add("shopar-loading-text",e),t.textContent=n,t.style.textAlign="center",t}function pe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-bg",e);const t=n.style;return t.position="relative",t.overflow="hidden",n}function fe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-fg",e);const t=n.style;return t.width="100%",t.height="100%",n}const me="shopar-main";const ve="shopar-qr-output";const ge="shopar-three-output";var we;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(we||(we={}));let ye,be,Ce,Ee,Re,Se,Ae,ke,xe,Le,$e,Me,Pe,Ue,De=we.None;function Te(e){De=e}let Ie,Ne=!1,je=null;function _e(){if(Ne)return;!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.")}}(),ye=function(){const e=document.createElement("div");e.id=me;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),Ce=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),be=function(e){const n=document.createElement("div");n.id=ve;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}(Ce),ye.appendChild(be),Ee=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}(),ye.appendChild(Ee),Re=function(){const e=document.createElement("canvas");e.id=ge;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),ye.appendChild(Re),Le=ue("shopar-ar-loading-container");const e=he("shopar-ar-loading-text","Loading Try On...");Le.appendChild(e);const n=pe("shopar-ar-loading-bar-bg");$e=fe("shopar-ar-loading-bar-fg"),n.appendChild($e),Le.appendChild(n),ye.appendChild(Le),Me=ue("shopar-3d-loading-container");const t=he("shopar-3d-loading-text","Loading 3D...");Me.appendChild(t);const o=pe("shopar-3d-loading-bar-bg");Pe=fe("shopar-3d-loading-bar-fg"),o.appendChild(Pe),Me.appendChild(o),ye.appendChild(Me),Ue=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}(),ye.appendChild(Ue),Se=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}(),ye.appendChild(Se),Ae=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"),Se.appendChild(Ae),ke=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${S}/img/icons/cube.svg`),Se.appendChild(ke),xe=le("shopar-btn-close","Close","Close ShopAR view",`${S}/img/icons/close.svg`),Se.append(xe),Ne=!0}function Oe(e,n,t,o){var r;Ge(Se,e),Ge(Ae,e&&(t||n)&&De===we.None),Ge(ke,e&&o&&De===we.None),Ge(xe,e&&De!==we.None),We(),qe(),e||""===(r=Ue).style.display&&Ge(r,!1)}function Ge(e,n){e.style.display=n?"":"none"}function We(){$e.classList.remove("active"),Le.style.visibility="hidden"}function Fe(){Pe.classList.add("active"),Me.style.visibility="visible"}function qe(){Pe.classList.remove("active"),Me.style.visibility="hidden"}let Be,He,Ke,Ve,ze,Xe=!0;function Qe(n,t){return e(this,void 0,void 0,(function*(){yield Ie;const e=`https://apps.deepar.ai/${E.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:n,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),r=Ce,i=new Promise(((e,n)=>{r.onload=e,r.onerror=n}));r.src=o,yield i,Xe=!1,be.style.display=""}))}function Ze(){Xe=!0,be.style.display="none"}let Ye,Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn=!1,vn=!1;const gn=45,wn=45,yn=3,bn=.1,Cn=3.5,En=2,Rn=1;let Sn,An;function kn(o){if(o!==Ke){const r=255;Ke=o,He=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),Sn=null,null==un||un.clear()}}function xn(e){fn.removeEventListener("change",An),An=e,fn.addEventListener("change",e)}function Ln(n,t){return e(this,void 0,void 0,(function*(){return null==Sn&&(Sn=(()=>e(this,void 0,void 0,(function*(){const e=new Je.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}(Je,e.parse(t));o.mapping=en.EquirectangularReflectionMapping,o.encoding=en.LinearEncoding,un.environment=o;const r=(new Je.GLTFLoader).setDRACOLoader((new Je.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${en.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Je.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${en.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(nn)).setMeshoptDecoder("function"==typeof Je.MeshoptDecoder?Je.MeshoptDecoder():Je.MeshoptDecoder);return yield r.parseAsync(n.buffer,"")})))()),Sn}))}function $n(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);hn.position.set(n[0],n[1],n[2])}function Mn(e){un.add(e.scene);const n=(new en.Box3).setFromObject(e.scene);tn.position.y=n.min.y-bn,un.add(tn),un.traverse((e=>{if(e instanceof en.Mesh){const n=e.material;n.depthWrite=!0,n instanceof en.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function Pn(){mn=!0,null!=Ye&&(Ye.style.display="none")}function Un(){if(mn)return;requestAnimationFrame(Un),Dn(),fn.update();const e=un.background;un.background=null,un.overrideMaterial=ln;const n=nn.getClearAlpha();nn.setClearAlpha(0),nn.setRenderTarget(on),nn.render(un,pn),un.overrideMaterial=null,Tn(Cn),Tn(.4*Cn),nn.setRenderTarget(null),nn.setClearAlpha(n),un.background=e,nn.render(un,hn)}function Dn(){const e=Ye.clientWidth,n=Ye.clientHeight;Ye.width===e&&Ye.height===n||(nn.setSize(e,n,!1),hn.aspect=e/n,hn.updateProjectionMatrix())}function Tn(e){sn.visible=!0,cn.uniforms.tDiffuse.value=on.texture,cn.uniforms.h.value=1*e/256,sn.material=cn,nn.setRenderTarget(rn),nn.render(sn,pn),dn.uniforms.tDiffuse.value=rn.texture,dn.uniforms.v.value=1*e/256,sn.material=dn,nn.setRenderTarget(on),nn.render(sn,pn),sn.visible=!1}function In(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Nn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const jn=["AR","3D"];function _n(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s}=e;In(t,"apiKey"),Nn(t,"apiKey"),In(o,"sku"),Nn(o,"sku"),In(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",jn),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let On=0,Gn=0;function Wn(t){var o,r;return e(this,void 0,void 0,(function*(){_n(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=C(),M=A(`${S}/shopar-analytics.js`),M.then((()=>{U=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[u,h,v]=T(a,i);u("setup",{hostname:window.location.hostname}),_e();const g=++Gn,w=yield c;u("apiResponse",w);const{category:y,arUrl:b,arKey:E,previewUrl:R,previewEnvUrl:$}=w;Fn(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)}))}());Fn(g),q&&function(){e(this,void 0,void 0,(function*(){null==Ie&&(Ie=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==Be&&(Be=A(`${S}/shopar-three.js`)),kn(R),(ae=null!=$?$:`${S}/env/default.hdr`)!==ze&&(ze=ae,Ve=B(ae))),function(e){e.style.position="relative",null==je?e.appendChild(ye):e!==je&&(je.removeChild(ye),e.appendChild(ye)),je=e}(s);const se=null==t.defaultUI||t.defaultUI;if(Oe(se,q,X,Q),De===we.AR){if(!Y)if(ne(h),X){u(x);const e=yield W;Fn(g),yield te(e),Fn(g)}else oe(),Te(we.None),se&&(Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0));if(!Xe)if(q){u(k);try{yield Qe(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ze(),Te(we.None),se&&(Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0))}else if(De===we.Preview&&!mn)if(xn(v),Q){u(L),Fe(),Ge(Re,!1);const e=yield He;Fn(g);const n=yield Ve;Fn(g);const t=yield Ln(e,n);Fn(g),$n(y),Mn(t),Ge(Re,!0),qe()}else Pn(),Te(we.None),se&&(Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0));const le=()=>e(this,void 0,void 0,(function*(){if(q){if(De===we.AR)throw new n("AR already launched.");try{u(k);++On;return De===we.Preview&&Q&&!mn&&Pn(),Te(we.AR),se&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),se&&Ge(Ue,!1),void(yield Qe(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(De===we.AR)throw new n("AR already launched.");try{u(x);const n=++On;De===we.Preview&&Q&&!mn&&Pn(),Te(we.AR),se&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),se&&Ge(Ue,!1),$e.classList.add("active"),Le.style.visibility="visible";const t=yield W;if(On!==n||Gn!==g)return;if(yield O,On!==n||Gn!==g)return;if(yield ee(Ee,E,y),On!==n||Gn!==g)return;if(ne(h),yield te(t),On!==n||Gn!==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=I(e);K=yield N(n),yield ie(H,K,"user"===e)}H.setPaused(Y),z.style.display=""}}))}(),On!==n||Gn!==g)return}catch(e){const t=e instanceof Error;throw u("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),se&&Ge(Ue,!0),oe(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{We()}})),ce=()=>e(this,void 0,void 0,(function*(){if(!Q)throw new n("Model does not have 3D enabled.");if(De===we.Preview)throw new n("3D already launched.");try{u(L);const n=++On;De===we.AR&&(X&&!Y&&oe(),Ze()),Te(we.Preview),se&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),se&&Ge(Ue,!1),Fe();const t=yield He;if(On!==n||Gn!==g)return;const o=yield Ve;if(On!==n||Gn!==g)return;if(yield Be,On!==n||Gn!==g)return;if(yield function(n){return e(this,void 0,void 0,(function*(){if(Ye=n,!vn){Je=window.ShopAR__THREE,en=Je.THREE,nn=new en.WebGLRenderer({powerPreference:"high-performance",canvas:n,antialias:!0,alpha:!0}),nn.outputEncoding=en.sRGBEncoding,nn.toneMapping=en.ACESFilmicToneMapping,nn.setPixelRatio(window.devicePixelRatio||1),nn.setClearColor(new en.Color(16777215)),un=new en.Scene,tn=new en.Group,tn.position.y=-.7,on=new en.WebGLRenderTarget(512,512),on.texture.generateMipmaps=!1,rn=new en.WebGLRenderTarget(512,512),rn.texture.generateMipmaps=!1;const e=new en.PlaneGeometry(gn,wn).rotateX(Math.PI/2),t=new en.MeshBasicMaterial({map:on.texture,opacity:Rn,transparent:!0,depthWrite:!1});an=new en.Mesh(e,t),an.renderOrder=1,tn.add(an),an.scale.y=-1,sn=new en.Mesh(e),sn.visible=!1,tn.add(sn),pn=new en.OrthographicCamera(-gn/2,gn/2,wn/2,-wn/2,0,yn),pn.rotation.x=Math.PI/2,tn.add(pn),ln=new en.MeshDepthMaterial,ln.userData.darkness={value:En},ln.onBeforeCompile=function(e){e.uniforms.darkness=ln.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 `},ln.depthTest=!1,ln.depthWrite=!1,cn=new en.ShaderMaterial(Je.HorizontalBlurShader),cn.depthTest=!1,dn=new en.ShaderMaterial(Je.VerticalBlurShader),dn.depthTest=!1,hn=new en.PerspectiveCamera(25,1,.5),fn=new Je.OrbitControls(hn,nn.domElement),fn.target.set(0,.03,0),fn.dampingFactor=.3,vn=!0}Dn()}))}(Re),On!==n||Gn!==g)return;xn(v);const r=yield Ln(t,o);if(On!==n||Gn!==g)return;$n(y),Mn(r),mn=!1,Un(),null!=Ye&&(Ye.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{qe()}})),de=()=>e(this,void 0,void 0,(function*(){if(De===we.None)throw new n("Neither AR or 3D launched.");++On,De===we.AR?(X&&!Y&&oe(),Ze()):De===we.Preview&&Q&&!mn&&Pn(),Te(we.None),We(),qe(),se&&(Ge(Ue,!1),Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!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}`;Ae.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(y),Ae.onclick=le),Q&&(ke.onclick=ce),xe.onclick=de),"AR"===l?(yield le(),Fn(g)):"3D"===l&&(yield ce(),Fn(g)),{launchAR:le,launch3D:ce,closeAR:()=>e(this,void 0,void 0,(function*(){if(De!==we.AR)throw new n("AR not launched.");++On,X&&!Y&&oe(),Ze(),Te(we.None),We(),se&&(Ge(Ue,!1),Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(De!==we.Preview)throw new n("3D not launched.");++On,Q&&!mn&&Pn(),Te(we.None),qe(),se&&(Ge(Ue,!1),Ge(xe,!1),(q||X)&&Ge(Ae,!0),Q&&Ge(ke,!0))})),close:de}}))}function Fn(e){if(Gn!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const qn={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",(()=>Wn(t)))}))},version:E};export{qn as plugin};
|
|
1
|
+
function e(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-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.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}"};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,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 t[1]([l]);function d(){const e=(new TextEncoder).encode(a),n=i.map((e=>e.length));for(let t=0;t<e.length;t++)e[t]^=n[t%n.length];return window[i[n[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(n,t=0){return e(this,void 0,void 0,(function*(){try{return yield n()}catch(e){if(t>=h)throw e;return yield new Promise((e=>setTimeout(e,u[t]))),p(n,t+1)}}))}const f=["Glasses","Shoes","Watches"],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 C(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 E="0.0.7-alpha.0";let S=`https://cdn.jsdelivr.net/npm/shopar-plugin@${E}/dist`;const R={update:e=>{null!=e&&(S=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>S};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",L="previewLaunch",$="heartbeat";let M,P,U=!1;const D=[];function T(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:E,sessionId:P,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},U?a():D.push(a)};return window.setInterval((()=>{c&&(i=r+a,c=!1,d($,{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 N(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,i){return e(this,void 0,void 0,(function*(){return V=i,z=t,null==X&&(X=(()=>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 n("No camera available!");var r;const a=ie(i),s=I(a),l=function(e){const n={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:n[e]}(i);H=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:l,cameraConfig:{disableDefaultCamera:!0}}}),K=yield N(s),yield re(H,K,"user"===a),"Glasses"===i&&(yield G,function(n,t){e(this,void 0,void 0,(function*(){q=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${R}/wasm/mediapipe`,n);const i=[],r=setInterval((()=>e(this,void 0,void 0,(function*(){if(q)return void clearInterval(r);const{error:e,faceWidth:n}=yield o.predict(performance.now());if(q)return void clearInterval(r);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(i.length<_)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)}))),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 ie(e){var n;return null==e?"user":null!==(n={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==n?n:"user"}function re(n,t,o){return e(this,void 0,void 0,(function*(){yield new Promise((i=>{t.onloadedmetadata=()=>{t.play().then((()=>e(this,void 0,void 0,(function*(){n.setVideoElement(t,o),i()}))))}}))}))}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 i=document.createElement("button");i.id=e,i.type="button",i.className="shopar-btn";{const e=ae("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 ce="shopar-control";const de="shopar-deepar-output";function ue(e){const n=document.createElement("div");n.className=e,n.classList.add("shopar-loading-container",e);const t=n.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",n}function he(e,n){const t=document.createElement("div");return t.classList.add("shopar-loading-text",e),t.textContent=n,t.style.textAlign="center",t}function pe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-bg",e);const t=n.style;return t.position="relative",t.overflow="hidden",n}function fe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-fg",e);const t=n.style;return t.width="100%",t.height="100%",n}const me="shopar-main";const ve="shopar-qr-output";const ge="shopar-three-output";var we;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(we||(we={}));let ye,be,Ce,Ee,Se,Re,Ae,ke,xe,Le,$e,Me,Pe,Ue,De=we.None;function Te(e){De=e}let Ie,Ne=!1,je=null;function _e(e){var n,t;if(Ne)return;!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.")}}(),ye=function(){const e=document.createElement("div");e.id=me;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),Ce=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),be=function(e){const n=document.createElement("div");n.id=ve;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}(Ce),ye.appendChild(be),Ee=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}(),ye.appendChild(Ee),Se=function(){const e=document.createElement("canvas");e.id=ge;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),ye.appendChild(Se),Le=ue("shopar-ar-loading-container");const o=he("shopar-ar-loading-text",null!==(n=null==e?void 0:e["loading.ar"])&&void 0!==n?n:"Loading Try On...");Le.appendChild(o);const i=pe("shopar-ar-loading-bar-bg");$e=fe("shopar-ar-loading-bar-fg"),i.appendChild($e),Le.appendChild(i),ye.appendChild(Le),Me=ue("shopar-3d-loading-container");const r=he("shopar-3d-loading-text",null!==(t=null==e?void 0:e["loading.3d"])&&void 0!==t?t:"Loading 3D...");Me.appendChild(r);const a=pe("shopar-3d-loading-bar-bg");Pe=fe("shopar-3d-loading-bar-fg"),a.appendChild(Pe),Me.appendChild(a),ye.appendChild(Me),Ue=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 i=ae("4rem",`${R}/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}(),ye.appendChild(Ue),Re=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}(),ye.appendChild(Re),Ae=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"),Re.appendChild(Ae),ke=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${R}/img/icons/cube.svg`),Re.appendChild(ke),xe=le("shopar-btn-close","Close","Close ShopAR view",`${R}/img/icons/close.svg`),Re.append(xe),Ne=!0}function Oe(e,n,t,o){var i;Ge(Re,e),Ge(Ae,e&&(t||n)&&De===we.None),Ge(ke,e&&o&&De===we.None),Ge(xe,e&&De!==we.None),We(),qe(),e||""===(i=Ue).style.display&&Ge(i,!1)}function Ge(e,n){e.style.display=n?"":"none"}function We(){$e.classList.remove("active"),Le.style.visibility="hidden"}function Fe(){Pe.classList.add("active"),Me.style.visibility="visible"}function qe(){Pe.classList.remove("active"),Me.style.visibility="hidden"}let Be,He,Ke,Ve,ze,Xe=!0;function Qe(n,t){return e(this,void 0,void 0,(function*(){yield Ie;const e=`https://apps.deepar.ai/${E.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:n,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(e),i=Ce,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Xe=!1,be.style.display=""}))}function Ze(){Xe=!0,be.style.display="none"}let Ye,Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn=!1,vn=!1;const gn=45,wn=45,yn=3,bn=0,Cn=1.5,En=1,Sn=.5;let Rn,An;function kn(o){if(o!==Ke){const i=255;Ke=o,He=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),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.")})));r+=s;const w=g.byteLength;if(c[l]=Math.min(76,i)*((a>>5)-1),152===c[l]&&(c[l]=w),r==l)return g;r=l,r^=l;for(let e=0,n=g.length;e<n;e++)c[l]^=c[r]<<13,c[l]^=c[r]>>17,c[l]^=c[r]<<5,g[e]=g[e]^c[l];return r^=c[0],r^=c[1],r^=c[2],g}))}(o,(new Date).getTime()+i,Math.random()*i),Rn=null,null==un||un.clear()}}function xn(e){fn.removeEventListener("change",An),An=e,fn.addEventListener("change",e)}function Ln(n,t){return e(this,void 0,void 0,(function*(){return null==Rn&&(Rn=(()=>e(this,void 0,void 0,(function*(){const e=new Je.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}(Je,e.parse(t));o.mapping=en.EquirectangularReflectionMapping,o.encoding=en.LinearEncoding,un.environment=o;const i=(new Je.GLTFLoader).setDRACOLoader((new Je.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${en.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new Je.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${en.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(nn)).setMeshoptDecoder("function"==typeof Je.MeshoptDecoder?Je.MeshoptDecoder():Je.MeshoptDecoder);return yield i.parseAsync(n.buffer,"")})))()),Rn}))}function $n(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-55,30,30],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);hn.position.set(n[0],n[1],n[2]),fn.minDistance="Shoes"===e?25:0,fn.maxDistance="Shoes"===e?150:1/0}function Mn(e){un.add(e.scene);const n=(new en.Box3).setFromObject(e.scene);tn.position.y=n.min.y-bn,un.add(tn),un.traverse((e=>{if(e instanceof en.Mesh){const n=e.material;n.depthWrite=!0,n instanceof en.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function Pn(){mn=!0,null!=Ye&&(Ye.style.display="none")}function Un(){if(mn)return;requestAnimationFrame(Un),Dn(),fn.update();const e=un.background;un.background=null,un.overrideMaterial=ln;const n=nn.getClearAlpha();nn.setClearAlpha(0),nn.setRenderTarget(on),nn.render(un,pn),un.overrideMaterial=null,Tn(Cn),Tn(.4*Cn),nn.setRenderTarget(null),nn.setClearAlpha(n),un.background=e,nn.render(un,hn)}function Dn(){const e=Ye.clientWidth,n=Ye.clientHeight;Ye.width===e&&Ye.height===n||(nn.setSize(e,n,!1),hn.aspect=e/n,hn.updateProjectionMatrix())}function Tn(e){sn.visible=!0,cn.uniforms.tDiffuse.value=on.texture,cn.uniforms.h.value=1*e/256,sn.material=cn,nn.setRenderTarget(rn),nn.render(sn,pn),dn.uniforms.tDiffuse.value=rn.texture,dn.uniforms.v.value=1*e/256,sn.material=dn,nn.setRenderTarget(on),nn.render(sn,pn),sn.visible=!1}function In(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function Nn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const jn=["AR","3D"];function _n(e){const{apiKey:t,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;In(t,"apiKey"),Nn(t,"apiKey"),In(o,"sku"),Nn(o,"sku"),In(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",jn),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI")}let On=0,Gn=0;function Wn(t){var o,i,r;return e(this,void 0,void 0,(function*(){_n(t);const{apiKey:a,sku:s,targetElement:l,initialState:c}=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}'.`)}(l),R.update(t.baseUrl);const u=function(t,o){return e(this,void 0,void 0,(function*(){const i=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:t,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!e.ok)throw new n(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(a,s);null==M&&(P=C(),M=A(`${R}/shopar-analytics.js`),M.then((()=>{U=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[h,v,g]=T(s,a);h("setup",{hostname:window.location.hostname}),_e(null===(o=t._internalOptions)||void 0===o?void 0:o.strings);const w=++Gn,y=yield u;h("apiResponse",y);const{category:b,arUrl:E,arKey:S,previewUrl:$,previewEnvUrl:j}=y;Fn(w);const _=null!=E&&function(e){return null!=e&&f.includes(e)}(b),F=null==(null===(i=t._internalOptions)||void 0===i?void 0:i.qrEnabled)||(null===(r=t._internalOptions)||void 0===r?void 0:r.qrEnabled),q=_&&function(e){return null!=e&&m.includes(e)}(b),X=F&&q&&!(yield function(){var n;return e(this,void 0,void 0,(function*(){return null==Z&&(Z=A(`${R}/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)}))}());Fn(w),X&&function(){e(this,void 0,void 0,(function*(){null==Ie&&(Ie=A(`${R}/shopar-qr.js`))}))}();const Q=_&&!X;Q&&(null==O&&(O=A(`${R}/shopar-deepar.js`)),J(E),"Glasses"===b&&null==G&&(G=A(`${R}/shopar-true-scale.js`)));const ae=null!=$;var se;ae&&(null==Be&&(Be=A(`${R}/shopar-three.js`)),kn($),(se=null!=j?j:`${R}/env/default.hdr`)!==ze&&(ze=se,Ve=B(se))),function(e){e.style.position="relative",null==je?e.appendChild(ye):e!==je&&(je.removeChild(ye),e.appendChild(ye)),je=e}(l);const le=null==t.defaultUI||t.defaultUI;if(Oe(le,X,Q,ae),De===we.AR){if(!Y)if(ne(v),Q){h(x);const e=yield W;Fn(w),yield te(e),Fn(w)}else oe(),Te(we.None),le&&(Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0));if(!Xe)if(X){h(k);try{yield Qe(a,s)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ze(),Te(we.None),le&&(Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0))}else if(De===we.Preview&&!mn)if(xn(g),ae){h(L),Fe(),Ge(Se,!1);const e=yield He;Fn(w);const n=yield Ve;Fn(w);const t=yield Ln(e,n);Fn(w),$n(b),Mn(t),Ge(Se,!0),qe()}else Pn(),Te(we.None),le&&(Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0));const ce=()=>e(this,void 0,void 0,(function*(){if(X){if(De===we.AR)throw new n("AR already launched.");try{h(k);++On;return De===we.Preview&&ae&&!mn&&Pn(),Te(we.AR),le&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),le&&Ge(Ue,!1),void(yield Qe(a,s))}catch(e){const t=e instanceof Error;throw h("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!Q)throw new n("Model does not have AR enabled.");if(De===we.AR)throw new n("AR already launched.");try{h(x);const n=++On;De===we.Preview&&ae&&!mn&&Pn(),Te(we.AR),le&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),le&&Ge(Ue,!1),$e.classList.add("active"),Le.style.visibility="visible";const t=yield W;if(On!==n||Gn!==w)return;if(yield O,On!==n||Gn!==w)return;if(yield ee(Ee,S,b),On!==n||Gn!==w)return;if(ne(v),yield te(t),On!==n||Gn!==w)return;if(yield function(){return e(this,void 0,void 0,(function*(){if(null!=H){if(Y=!1,null==K){const e=ie(V),n=I(e);K=yield N(n),yield re(H,K,"user"===e)}H.setPaused(Y),z.style.display=""}}))}(),On!==n||Gn!==w)return}catch(e){const t=e instanceof Error;throw h("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),le&&Ge(Ue,!0),oe(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{We()}})),de=()=>e(this,void 0,void 0,(function*(){if(!ae)throw new n("Model does not have 3D enabled.");if(De===we.Preview)throw new n("3D already launched.");try{h(L);const n=++On;De===we.AR&&(Q&&!Y&&oe(),Ze()),Te(we.Preview),le&&(Ge(Ae,!1),Ge(ke,!1),Ge(xe,!0)),le&&Ge(Ue,!1),Fe();const t=yield He;if(On!==n||Gn!==w)return;const o=yield Ve;if(On!==n||Gn!==w)return;if(yield Be,On!==n||Gn!==w)return;if(yield function(n){return e(this,void 0,void 0,(function*(){if(Ye=n,!vn){Je=window.ShopAR__THREE,en=Je.THREE,nn=new en.WebGLRenderer({powerPreference:"high-performance",canvas:n,antialias:!0,alpha:!0}),nn.outputEncoding=en.sRGBEncoding,nn.toneMapping=en.ACESFilmicToneMapping,nn.setPixelRatio(window.devicePixelRatio||1),nn.setClearColor(new en.Color(16777215)),un=new en.Scene,tn=new en.Group,tn.position.y=-.7,on=new en.WebGLRenderTarget(512,512),on.texture.generateMipmaps=!1,rn=new en.WebGLRenderTarget(512,512),rn.texture.generateMipmaps=!1;const e=new en.PlaneGeometry(gn,wn).rotateX(Math.PI/2),t=new en.MeshBasicMaterial({map:on.texture,opacity:Sn,transparent:!0,depthWrite:!1});an=new en.Mesh(e,t),an.renderOrder=1,tn.add(an),an.scale.y=-1,sn=new en.Mesh(e),sn.visible=!1,tn.add(sn),pn=new en.OrthographicCamera(-gn/2,gn/2,wn/2,-wn/2,0,yn),pn.rotation.x=Math.PI/2,tn.add(pn),ln=new en.MeshDepthMaterial,ln.userData.darkness={value:En},ln.onBeforeCompile=function(e){e.uniforms.darkness=ln.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 `},ln.depthTest=!1,ln.depthWrite=!1,cn=new en.ShaderMaterial(Je.HorizontalBlurShader),cn.depthTest=!1,dn=new en.ShaderMaterial(Je.VerticalBlurShader),dn.depthTest=!1,hn=new en.PerspectiveCamera(25,1,.5),fn=new Je.OrbitControls(hn,nn.domElement),fn.target.set(0,.03,0),fn.dampingFactor=.3,vn=!0}Dn()}))}(Se),On!==n||Gn!==w)return;xn(g);const i=yield Ln(t,o);if(On!==n||Gn!==w)return;$n(b),Mn(i),mn=!1,Un(),null!=Ye&&(Ye.style.display="")}catch(e){const t=e instanceof Error;throw h("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{qe()}})),ue=()=>e(this,void 0,void 0,(function*(){if(De===we.None)throw new n("Neither AR or 3D launched.");++On,De===we.AR?(Q&&!Y&&oe(),Ze()):De===we.Preview&&ae&&!mn&&Pn(),Te(we.None),We(),qe(),le&&(Ge(Ue,!1),Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0))}));return le&&((X||Q)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${R}/img/icons/${null!=e&&n[e]||n.Glasses}`;Ae.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(b),Ae.onclick=ce),ae&&(ke.onclick=de),xe.onclick=ue),"AR"===c?(yield ce(),Fn(w)):"3D"===c&&(yield de(),Fn(w)),{launchAR:ce,launch3D:de,closeAR:()=>e(this,void 0,void 0,(function*(){if(De!==we.AR)throw new n("AR not launched.");++On,Q&&!Y&&oe(),Ze(),Te(we.None),We(),le&&(Ge(Ue,!1),Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0))})),close3D:()=>e(this,void 0,void 0,(function*(){if(De!==we.Preview)throw new n("3D not launched.");++On,ae&&!mn&&Pn(),Te(we.None),qe(),le&&(Ge(Ue,!1),Ge(xe,!1),(X||Q)&&Ge(Ae,!0),ae&&Ge(ke,!0))})),close:ue}}))}function Fn(e){if(Gn!==e)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const qn={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",(()=>Wn(t)))}))},version:E};export{qn as plugin};
|
package/dist/shopar-plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.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}"};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 C={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function E(e,n,t){if(C.randomUUID&&!n&&!e)return C.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";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 x(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 k="qrLaunch",L="arLaunch",$="previewLaunch",M="heartbeat";let P,U,T=!1;const D=[];function I(e,n){const t=performance.now(),o=E();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 j(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function N(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=j(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 N(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";function he(e){const n=document.createElement("div");n.className=e,n.classList.add("shopar-loading-container",e);const t=n.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",n}function pe(e,n){const t=document.createElement("div");return t.classList.add("shopar-loading-text",e),t.textContent=n,t.style.textAlign="center",t}function fe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-bg",e);const t=n.style;return t.position="relative",t.overflow="hidden",n}function me(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-fg",e);const t=n.style;return t.width="100%",t.height="100%",n}const ve="shopar-main";const ge="shopar-qr-output";const we="shopar-three-output";var ye;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(ye||(ye={}));let be,Ce,Ee,Re,Se,Ae,xe,ke,Le,$e,Me,Pe,Ue,Te,De=ye.None;function Ie(e){De=e}let je,Ne=!1,_e=null;function Oe(){if(Ne)return;!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.")}}(),be=function(){const e=document.createElement("div");e.id=ve;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),Ee=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),Ce=function(e){const n=document.createElement("div");n.id=ge;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}(Ee),be.appendChild(Ce),Re=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}(),be.appendChild(Re),Se=function(){const e=document.createElement("canvas");e.id=we;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),be.appendChild(Se),$e=he("shopar-ar-loading-container");const e=pe("shopar-ar-loading-text","Loading Try On...");$e.appendChild(e);const n=fe("shopar-ar-loading-bar-bg");Me=me("shopar-ar-loading-bar-fg"),n.appendChild(Me),$e.appendChild(n),be.appendChild($e),Pe=he("shopar-3d-loading-container");const t=pe("shopar-3d-loading-text","Loading 3D...");Pe.appendChild(t);const o=fe("shopar-3d-loading-bar-bg");Ue=me("shopar-3d-loading-bar-fg"),o.appendChild(Ue),Pe.appendChild(o),be.appendChild(Pe),Te=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}(),be.appendChild(Te),Ae=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}(),be.appendChild(Ae),xe=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"),Ae.appendChild(xe),ke=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${A}/img/icons/cube.svg`),Ae.appendChild(ke),Le=ce("shopar-btn-close","Close","Close ShopAR view",`${A}/img/icons/close.svg`),Ae.append(Le),Ne=!0}function Ge(e,n,t,o){var i;We(Ae,e),We(xe,e&&(t||n)&&De===ye.None),We(ke,e&&o&&De===ye.None),We(Le,e&&De!==ye.None),Fe(),Be(),e||""===(i=Te).style.display&&We(i,!1)}function We(e,n){e.style.display=n?"":"none"}function Fe(){Me.classList.remove("active"),$e.style.visibility="hidden"}function qe(){Ue.classList.add("active"),Pe.style.visibility="visible"}function Be(){Ue.classList.remove("active"),Pe.style.visibility="hidden"}let He,Ke,Ve,ze,Xe,Qe=!0;function Ze(e,t){return n(this,void 0,void 0,(function*(){yield je;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=Ee,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Qe=!1,Ce.style.display=""}))}function Ye(){Qe=!0,Ce.style.display="none"}let Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn,vn=!1,gn=!1;const wn=45,yn=45,bn=3,Cn=.1,En=3.5,Rn=2,Sn=1;let An,xn;function kn(e){if(e!==Ve){const i=255;Ve=e,Ke=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),An=null,null==hn||hn.clear()}}function Ln(e){mn.removeEventListener("change",xn),xn=e,mn.addEventListener("change",e)}function $n(e,t){return n(this,void 0,void 0,(function*(){return null==An&&(An=(()=>n(this,void 0,void 0,(function*(){const n=new en.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}(en,n.parse(t));o.mapping=nn.EquirectangularReflectionMapping,o.encoding=nn.LinearEncoding,hn.environment=o;const i=(new en.GLTFLoader).setDRACOLoader((new en.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${nn.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new en.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${nn.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(tn)).setMeshoptDecoder("function"==typeof en.MeshoptDecoder?en.MeshoptDecoder():en.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),An}))}function Mn(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);pn.position.set(n[0],n[1],n[2])}function Pn(e){hn.add(e.scene);const n=(new nn.Box3).setFromObject(e.scene);on.position.y=n.min.y-Cn,hn.add(on),hn.traverse((e=>{if(e instanceof nn.Mesh){const n=e.material;n.depthWrite=!0,n instanceof nn.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function Un(){vn=!0,null!=Je&&(Je.style.display="none")}function Tn(){if(vn)return;requestAnimationFrame(Tn),Dn(),mn.update();const e=hn.background;hn.background=null,hn.overrideMaterial=cn;const n=tn.getClearAlpha();tn.setClearAlpha(0),tn.setRenderTarget(rn),tn.render(hn,fn),hn.overrideMaterial=null,In(En),In(.4*En),tn.setRenderTarget(null),tn.setClearAlpha(n),hn.background=e,tn.render(hn,pn)}function Dn(){const e=Je.clientWidth,n=Je.clientHeight;Je.width===e&&Je.height===n||(tn.setSize(e,n,!1),pn.aspect=e/n,pn.updateProjectionMatrix())}function In(e){ln.visible=!0,dn.uniforms.tDiffuse.value=rn.texture,dn.uniforms.h.value=1*e/256,ln.material=dn,tn.setRenderTarget(an),tn.render(ln,fn),un.uniforms.tDiffuse.value=an.texture,un.uniforms.v.value=1*e/256,ln.material=un,tn.setRenderTarget(rn),tn.render(ln,fn),ln.visible=!1}function jn(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Nn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const _n=["AR","3D"];function On(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;jn(n,"apiKey"),Nn(n,"apiKey"),jn(o,"sku"),Nn(o,"sku"),jn(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",_n),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let Gn=0,Wn=0;function Fn(e){var o,i;return n(this,void 0,void 0,(function*(){On(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=E(),P=x(`${A}/shopar-analytics.js`),P.then((()=>{T=!0,window.ShopAR__analytics.initializeImpl(),D.forEach((e=>e()))})));const[d,h,p]=I(a,r);d("setup",{hostname:window.location.hostname}),Oe();const g=++Wn,w=yield c;d("apiResponse",w);const{category:y,arUrl:b,arKey:C,previewUrl:R,previewEnvUrl:S}=w;qn(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=x(`${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)}))}());qn(g),q&&function(){n(this,void 0,void 0,(function*(){null==je&&(je=x(`${A}/shopar-qr.js`))}))}();const B=M&&!q;B&&(null==G&&(G=x(`${A}/shopar-deepar.js`)),ee(b),"Glasses"===y&&null==W&&(W=x(`${A}/shopar-true-scale.js`)));const Q=null!=R;var Z;Q&&(null==He&&(He=x(`${A}/shopar-three.js`)),kn(R),(Z=null!=S?S:`${A}/env/default.hdr`)!==Xe&&(Xe=Z,ze=H(Z))),function(e){e.style.position="relative",null==_e?e.appendChild(be):e!==_e&&(_e.removeChild(be),e.appendChild(be)),_e=e}(s);const se=null==e.defaultUI||e.defaultUI;if(Ge(se,q,B,Q),De===ye.AR){if(!J)if(te(h),B){d(L);const e=yield F;qn(g),yield oe(e),qn(g)}else ie(),Ie(ye.None),se&&(We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0));if(!Qe)if(q){d(k);try{yield Ze(r,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ye(),Ie(ye.None),se&&(We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0))}else if(De===ye.Preview&&!vn)if(Ln(p),Q){d($),qe(),We(Se,!1);const e=yield Ke;qn(g);const n=yield ze;qn(g);const t=yield $n(e,n);qn(g),Mn(y),Pn(t),We(Se,!0),Be()}else Un(),Ie(ye.None),se&&(We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0));const le=()=>n(this,void 0,void 0,(function*(){if(q){if(De===ye.AR)throw new t("AR already launched.");try{d(k);++Gn;return De===ye.Preview&&Q&&!vn&&Un(),Ie(ye.AR),se&&(We(xe,!1),We(ke,!1),We(Le,!0)),se&&We(Te,!1),void(yield Ze(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(De===ye.AR)throw new t("AR already launched.");try{d(L);const e=++Gn;De===ye.Preview&&Q&&!vn&&Un(),Ie(ye.AR),se&&(We(xe,!1),We(ke,!1),We(Le,!0)),se&&We(Te,!1),Me.classList.add("active"),$e.style.visibility="visible";const t=yield F;if(Gn!==e||Wn!==g)return;if(yield G,Gn!==e||Wn!==g)return;if(yield ne(Re,C,y),Gn!==e||Wn!==g)return;if(te(h),yield oe(t),Gn!==e||Wn!==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=j(e);V=yield N(n),yield ae(K,V,"user"===e)}K.setPaused(J),X.style.display=""}}))}(),Gn!==e||Wn!==g)return}catch(e){const n=e instanceof Error;throw d("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),se&&We(Te,!0),ie(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{Fe()}})),ce=()=>n(this,void 0,void 0,(function*(){if(!Q)throw new t("Model does not have 3D enabled.");if(De===ye.Preview)throw new t("3D already launched.");try{d($);const e=++Gn;De===ye.AR&&(B&&!J&&ie(),Ye()),Ie(ye.Preview),se&&(We(xe,!1),We(ke,!1),We(Le,!0)),se&&We(Te,!1),qe();const t=yield Ke;if(Gn!==e||Wn!==g)return;const o=yield ze;if(Gn!==e||Wn!==g)return;if(yield He,Gn!==e||Wn!==g)return;if(yield function(e){return n(this,void 0,void 0,(function*(){if(Je=e,!gn){en=window.ShopAR__THREE,nn=en.THREE,tn=new nn.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),tn.outputEncoding=nn.sRGBEncoding,tn.toneMapping=nn.ACESFilmicToneMapping,tn.setPixelRatio(window.devicePixelRatio||1),tn.setClearColor(new nn.Color(16777215)),hn=new nn.Scene,on=new nn.Group,on.position.y=-.7,rn=new nn.WebGLRenderTarget(512,512),rn.texture.generateMipmaps=!1,an=new nn.WebGLRenderTarget(512,512),an.texture.generateMipmaps=!1;const n=new nn.PlaneGeometry(wn,yn).rotateX(Math.PI/2),t=new nn.MeshBasicMaterial({map:rn.texture,opacity:Sn,transparent:!0,depthWrite:!1});sn=new nn.Mesh(n,t),sn.renderOrder=1,on.add(sn),sn.scale.y=-1,ln=new nn.Mesh(n),ln.visible=!1,on.add(ln),fn=new nn.OrthographicCamera(-wn/2,wn/2,yn/2,-yn/2,0,bn),fn.rotation.x=Math.PI/2,on.add(fn),cn=new nn.MeshDepthMaterial,cn.userData.darkness={value:Rn},cn.onBeforeCompile=function(e){e.uniforms.darkness=cn.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 `},cn.depthTest=!1,cn.depthWrite=!1,dn=new nn.ShaderMaterial(en.HorizontalBlurShader),dn.depthTest=!1,un=new nn.ShaderMaterial(en.VerticalBlurShader),un.depthTest=!1,pn=new nn.PerspectiveCamera(25,1,.5),mn=new en.OrbitControls(pn,tn.domElement),mn.target.set(0,.03,0),mn.dampingFactor=.3,gn=!0}Dn()}))}(Se),Gn!==e||Wn!==g)return;Ln(p);const i=yield $n(t,o);if(Gn!==e||Wn!==g)return;Mn(y),Pn(i),vn=!1,Tn(),null!=Je&&(Je.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{Be()}})),de=()=>n(this,void 0,void 0,(function*(){if(De===ye.None)throw new t("Neither AR or 3D launched.");++Gn,De===ye.AR?(B&&!J&&ie(),Ye()):De===ye.Preview&&Q&&!vn&&Un(),Ie(ye.None),Fe(),Be(),se&&(We(Te,!1),We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!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}`;xe.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(y),xe.onclick=le),Q&&(ke.onclick=ce),Le.onclick=de),"AR"===l?(yield le(),qn(g)):"3D"===l&&(yield ce(),qn(g)),{launchAR:le,launch3D:ce,closeAR:()=>n(this,void 0,void 0,(function*(){if(De!==ye.AR)throw new t("AR not launched.");++Gn,B&&!J&&ie(),Ye(),Ie(ye.None),Fe(),se&&(We(Te,!1),We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0))})),close3D:()=>n(this,void 0,void 0,(function*(){if(De!==ye.Preview)throw new t("3D not launched.");++Gn,Q&&!vn&&Un(),Ie(ye.None),Be(),se&&(We(Te,!1),We(Le,!1),(q||B)&&We(xe,!0),Q&&We(ke,!0))})),close:de}}))}function qn(e){if(Wn!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Bn={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",(()=>Fn(e)))}))},version:R};e.plugin=Bn}));
|
|
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-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.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}"};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 C={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function E(e,n,t){if(C.randomUUID&&!n&&!e)return C.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 S="0.0.7-alpha.0";let R=`https://cdn.jsdelivr.net/npm/shopar-plugin@${S}/dist`;const A={update:e=>{null!=e&&(R=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>R};function x(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 k="qrLaunch",L="arLaunch",$="previewLaunch",M="heartbeat";let P,U,D=!1;const T=[];function I(e,n){const t=performance.now(),o=E();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:S,sessionId:U,setupId:o,timeSinceSetup:performance.now()-t,sku:e,apiKey:n}),a=()=>{window.ShopAR__analytics.trackEventImpl(i,r)},D?a():T.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 j(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function N(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=j(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 N(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";function he(e){const n=document.createElement("div");n.className=e,n.classList.add("shopar-loading-container",e);const t=n.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",n}function pe(e,n){const t=document.createElement("div");return t.classList.add("shopar-loading-text",e),t.textContent=n,t.style.textAlign="center",t}function fe(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-bg",e);const t=n.style;return t.position="relative",t.overflow="hidden",n}function me(e){const n=document.createElement("div");n.classList.add("shopar-loading-bar-fg",e);const t=n.style;return t.width="100%",t.height="100%",n}const ve="shopar-main";const ge="shopar-qr-output";const we="shopar-three-output";var ye;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(ye||(ye={}));let be,Ce,Ee,Se,Re,Ae,xe,ke,Le,$e,Me,Pe,Ue,De,Te=ye.None;function Ie(e){Te=e}let je,Ne=!1,_e=null;function Oe(e){var n,t;if(Ne)return;!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.")}}(),be=function(){const e=document.createElement("div");e.id=ve;const n=e.style;return n.position="absolute",n.top="0",n.bottom="0",n.left="0",n.right="0",e}(),Ee=function(){const e=new Image,n=e.style;return n.maxWidth="100%",n.maxHeight="100%",e}(),Ce=function(e){const n=document.createElement("div");n.id=ge;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}(Ee),be.appendChild(Ce),Se=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}(),be.appendChild(Se),Re=function(){const e=document.createElement("canvas");e.id=we;const n=e.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none",e}(),be.appendChild(Re),$e=he("shopar-ar-loading-container");const o=pe("shopar-ar-loading-text",null!==(n=null==e?void 0:e["loading.ar"])&&void 0!==n?n:"Loading Try On...");$e.appendChild(o);const i=fe("shopar-ar-loading-bar-bg");Me=me("shopar-ar-loading-bar-fg"),i.appendChild(Me),$e.appendChild(i),be.appendChild($e),Pe=he("shopar-3d-loading-container");const r=pe("shopar-3d-loading-text",null!==(t=null==e?void 0:e["loading.3d"])&&void 0!==t?t:"Loading 3D...");Pe.appendChild(r);const a=fe("shopar-3d-loading-bar-bg");Ue=me("shopar-3d-loading-bar-fg"),a.appendChild(Ue),Pe.appendChild(a),be.appendChild(Pe),De=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}(),be.appendChild(De),Ae=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}(),be.appendChild(Ae),xe=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"),Ae.appendChild(xe),ke=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${A}/img/icons/cube.svg`),Ae.appendChild(ke),Le=ce("shopar-btn-close","Close","Close ShopAR view",`${A}/img/icons/close.svg`),Ae.append(Le),Ne=!0}function Ge(e,n,t,o){var i;We(Ae,e),We(xe,e&&(t||n)&&Te===ye.None),We(ke,e&&o&&Te===ye.None),We(Le,e&&Te!==ye.None),Fe(),Be(),e||""===(i=De).style.display&&We(i,!1)}function We(e,n){e.style.display=n?"":"none"}function Fe(){Me.classList.remove("active"),$e.style.visibility="hidden"}function qe(){Ue.classList.add("active"),Pe.style.visibility="visible"}function Be(){Ue.classList.remove("active"),Pe.style.visibility="hidden"}let He,Ke,Ve,ze,Xe,Qe=!0;function Ze(e,t){return n(this,void 0,void 0,(function*(){yield je;const n=`https://apps.deepar.ai/${S.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:e,s:t,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(n),i=Ee,r=new Promise(((e,n)=>{i.onload=e,i.onerror=n}));i.src=o,yield r,Qe=!1,Ce.style.display=""}))}function Ye(){Qe=!0,Ce.style.display="none"}let Je,en,nn,tn,on,rn,an,sn,ln,cn,dn,un,hn,pn,fn,mn,vn=!1,gn=!1;const wn=45,yn=45,bn=3,Cn=0,En=1.5,Sn=1,Rn=.5;let An,xn;function kn(e){if(e!==Ve){const i=255;Ve=e,Ke=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),An=null,null==hn||hn.clear()}}function Ln(e){mn.removeEventListener("change",xn),xn=e,mn.addEventListener("change",e)}function $n(e,t){return n(this,void 0,void 0,(function*(){return null==An&&(An=(()=>n(this,void 0,void 0,(function*(){const n=new en.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}(en,n.parse(t));o.mapping=nn.EquirectangularReflectionMapping,o.encoding=nn.LinearEncoding,hn.environment=o;const i=(new en.GLTFLoader).setDRACOLoader((new en.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${nn.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new en.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${nn.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(tn)).setMeshoptDecoder("function"==typeof en.MeshoptDecoder?en.MeshoptDecoder():en.MeshoptDecoder);return yield i.parseAsync(e.buffer,"")})))()),An}))}function Mn(e){const n=function(e){var n;const t={Glasses:[67.5,15,90],Shoes:[-55,30,30],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);pn.position.set(n[0],n[1],n[2]),mn.minDistance="Shoes"===e?25:0,mn.maxDistance="Shoes"===e?150:1/0}function Pn(e){hn.add(e.scene);const n=(new nn.Box3).setFromObject(e.scene);on.position.y=n.min.y-Cn,hn.add(on),hn.traverse((e=>{if(e instanceof nn.Mesh){const n=e.material;n.depthWrite=!0,n instanceof nn.MeshPhysicalMaterial&&n.transmissionMap&&(n.transmission=1,n.toneMapped=!1,n.fog=!1,n.needsUpdate=!0)}}))}function Un(){vn=!0,null!=Je&&(Je.style.display="none")}function Dn(){if(vn)return;requestAnimationFrame(Dn),Tn(),mn.update();const e=hn.background;hn.background=null,hn.overrideMaterial=cn;const n=tn.getClearAlpha();tn.setClearAlpha(0),tn.setRenderTarget(rn),tn.render(hn,fn),hn.overrideMaterial=null,In(En),In(.4*En),tn.setRenderTarget(null),tn.setClearAlpha(n),hn.background=e,tn.render(hn,pn)}function Tn(){const e=Je.clientWidth,n=Je.clientHeight;Je.width===e&&Je.height===n||(tn.setSize(e,n,!1),pn.aspect=e/n,pn.updateProjectionMatrix())}function In(e){ln.visible=!0,dn.uniforms.tDiffuse.value=rn.texture,dn.uniforms.h.value=1*e/256,ln.material=dn,tn.setRenderTarget(an),tn.render(ln,fn),un.uniforms.tDiffuse.value=an.texture,un.uniforms.v.value=1*e/256,ln.material=un,tn.setRenderTarget(rn),tn.render(ln,fn),ln.visible=!1}function jn(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Nn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const _n=["AR","3D"];function On(e){const{apiKey:n,sku:o,targetElement:i,initialState:r,baseUrl:a,defaultUI:s}=e;jn(n,"apiKey"),Nn(n,"apiKey"),jn(o,"sku"),Nn(o,"sku"),jn(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",_n),null!=a&&Nn(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI")}let Gn=0,Wn=0;function Fn(e){var o,i,r;return n(this,void 0,void 0,(function*(){On(e);const{apiKey:a,sku:s,targetElement:l,initialState:c}=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}'.`)}(l),A.update(e.baseUrl);const d=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.")}}))}(a,s);null==P&&(U=E(),P=x(`${A}/shopar-analytics.js`),P.then((()=>{D=!0,window.ShopAR__analytics.initializeImpl(),T.forEach((e=>e()))})));const[h,p,g]=I(s,a);h("setup",{hostname:window.location.hostname}),Oe(null===(o=e._internalOptions)||void 0===o?void 0:o.strings);const w=++Wn,y=yield d;h("apiResponse",y);const{category:b,arUrl:C,arKey:S,previewUrl:R,previewEnvUrl:M}=y;qn(w);const _=null!=C&&function(e){return null!=e&&m.includes(e)}(b),O=null==(null===(i=e._internalOptions)||void 0===i?void 0:i.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),q=_&&function(e){return null!=e&&v.includes(e)}(b),B=O&&q&&!(yield function(){var e;return n(this,void 0,void 0,(function*(){return null==Y&&(Y=x(`${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)}))}());qn(w),B&&function(){n(this,void 0,void 0,(function*(){null==je&&(je=x(`${A}/shopar-qr.js`))}))}();const Q=_&&!B;Q&&(null==G&&(G=x(`${A}/shopar-deepar.js`)),ee(C),"Glasses"===b&&null==W&&(W=x(`${A}/shopar-true-scale.js`)));const Z=null!=R;var se;Z&&(null==He&&(He=x(`${A}/shopar-three.js`)),kn(R),(se=null!=M?M:`${A}/env/default.hdr`)!==Xe&&(Xe=se,ze=H(se))),function(e){e.style.position="relative",null==_e?e.appendChild(be):e!==_e&&(_e.removeChild(be),e.appendChild(be)),_e=e}(l);const le=null==e.defaultUI||e.defaultUI;if(Ge(le,B,Q,Z),Te===ye.AR){if(!J)if(te(p),Q){h(L);const e=yield F;qn(w),yield oe(e),qn(w)}else ie(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0));if(!Qe)if(B){h(k);try{yield Ze(a,s)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Ye(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))}else if(Te===ye.Preview&&!vn)if(Ln(g),Z){h($),qe(),We(Re,!1);const e=yield Ke;qn(w);const n=yield ze;qn(w);const t=yield $n(e,n);qn(w),Mn(b),Pn(t),We(Re,!0),Be()}else Un(),Ie(ye.None),le&&(We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0));const ce=()=>n(this,void 0,void 0,(function*(){if(B){if(Te===ye.AR)throw new t("AR already launched.");try{h(k);++Gn;return Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.AR),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),void(yield Ze(a,s))}catch(e){const n=e instanceof Error;throw h("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!Q)throw new t("Model does not have AR enabled.");if(Te===ye.AR)throw new t("AR already launched.");try{h(L);const e=++Gn;Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.AR),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),Me.classList.add("active"),$e.style.visibility="visible";const t=yield F;if(Gn!==e||Wn!==w)return;if(yield G,Gn!==e||Wn!==w)return;if(yield ne(Se,S,b),Gn!==e||Wn!==w)return;if(te(p),yield oe(t),Gn!==e||Wn!==w)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=j(e);V=yield N(n),yield ae(K,V,"user"===e)}K.setPaused(J),X.style.display=""}}))}(),Gn!==e||Wn!==w)return}catch(e){const n=e instanceof Error;throw h("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),le&&We(De,!0),ie(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{Fe()}})),de=()=>n(this,void 0,void 0,(function*(){if(!Z)throw new t("Model does not have 3D enabled.");if(Te===ye.Preview)throw new t("3D already launched.");try{h($);const e=++Gn;Te===ye.AR&&(Q&&!J&&ie(),Ye()),Ie(ye.Preview),le&&(We(xe,!1),We(ke,!1),We(Le,!0)),le&&We(De,!1),qe();const t=yield Ke;if(Gn!==e||Wn!==w)return;const o=yield ze;if(Gn!==e||Wn!==w)return;if(yield He,Gn!==e||Wn!==w)return;if(yield function(e){return n(this,void 0,void 0,(function*(){if(Je=e,!gn){en=window.ShopAR__THREE,nn=en.THREE,tn=new nn.WebGLRenderer({powerPreference:"high-performance",canvas:e,antialias:!0,alpha:!0}),tn.outputEncoding=nn.sRGBEncoding,tn.toneMapping=nn.ACESFilmicToneMapping,tn.setPixelRatio(window.devicePixelRatio||1),tn.setClearColor(new nn.Color(16777215)),hn=new nn.Scene,on=new nn.Group,on.position.y=-.7,rn=new nn.WebGLRenderTarget(512,512),rn.texture.generateMipmaps=!1,an=new nn.WebGLRenderTarget(512,512),an.texture.generateMipmaps=!1;const n=new nn.PlaneGeometry(wn,yn).rotateX(Math.PI/2),t=new nn.MeshBasicMaterial({map:rn.texture,opacity:Rn,transparent:!0,depthWrite:!1});sn=new nn.Mesh(n,t),sn.renderOrder=1,on.add(sn),sn.scale.y=-1,ln=new nn.Mesh(n),ln.visible=!1,on.add(ln),fn=new nn.OrthographicCamera(-wn/2,wn/2,yn/2,-yn/2,0,bn),fn.rotation.x=Math.PI/2,on.add(fn),cn=new nn.MeshDepthMaterial,cn.userData.darkness={value:Sn},cn.onBeforeCompile=function(e){e.uniforms.darkness=cn.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 `},cn.depthTest=!1,cn.depthWrite=!1,dn=new nn.ShaderMaterial(en.HorizontalBlurShader),dn.depthTest=!1,un=new nn.ShaderMaterial(en.VerticalBlurShader),un.depthTest=!1,pn=new nn.PerspectiveCamera(25,1,.5),mn=new en.OrbitControls(pn,tn.domElement),mn.target.set(0,.03,0),mn.dampingFactor=.3,gn=!0}Tn()}))}(Re),Gn!==e||Wn!==w)return;Ln(g);const i=yield $n(t,o);if(Gn!==e||Wn!==w)return;Mn(b),Pn(i),vn=!1,Dn(),null!=Je&&(Je.style.display="")}catch(e){const n=e instanceof Error;throw h("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{Be()}})),ue=()=>n(this,void 0,void 0,(function*(){if(Te===ye.None)throw new t("Neither AR or 3D launched.");++Gn,Te===ye.AR?(Q&&!J&&ie(),Ye()):Te===ye.Preview&&Z&&!vn&&Un(),Ie(ye.None),Fe(),Be(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))}));return le&&((B||Q)&&(!function(e){const n={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},t=`${A}/img/icons/${null!=e&&n[e]||n.Glasses}`;xe.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t)}(b),xe.onclick=ce),Z&&(ke.onclick=de),Le.onclick=ue),"AR"===c?(yield ce(),qn(w)):"3D"===c&&(yield de(),qn(w)),{launchAR:ce,launch3D:de,closeAR:()=>n(this,void 0,void 0,(function*(){if(Te!==ye.AR)throw new t("AR not launched.");++Gn,Q&&!J&&ie(),Ye(),Ie(ye.None),Fe(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))})),close3D:()=>n(this,void 0,void 0,(function*(){if(Te!==ye.Preview)throw new t("3D not launched.");++Gn,Z&&!vn&&Un(),Ie(ye.None),Be(),le&&(We(De,!1),We(Le,!1),(B||Q)&&We(xe,!0),Z&&We(ke,!0))})),close:ue}}))}function qn(e){if(Wn!==e)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Bn={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",(()=>Fn(e)))}))},version:S};e.plugin=Bn}));
|