shopar-plugin 0.4.0-alpha.3 → 0.4.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 +2 -2
- package/dist/shopar-analytics.js +1 -1
- package/dist/shopar-plugin.esm.js +1 -1
- package/dist/shopar-plugin.js +1 -1
- package/package.json +1 -1
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@0.4.0/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).
|
|
@@ -157,7 +157,7 @@ Options used for the plugin setup:
|
|
|
157
157
|
- `baseUrl` (optional)
|
|
158
158
|
- Type: `string`
|
|
159
159
|
- If provided, defines where the additional ShopAR plugin files are fetched from.
|
|
160
|
-
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@
|
|
160
|
+
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@0.4.0/dist`
|
|
161
161
|
- `strings` (optional)
|
|
162
162
|
- Type: `object`
|
|
163
163
|
- If provided, overrides strings in the UI.
|
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 x 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 b;!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(){b=new x({token:"xaat-f69a9dd7-3988-4fc2-849b-4a0978468c25"})},t.trackEventImpl=function(t,e){b.ingest("shopar-plugin",Object.assign({name:t},e))}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).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}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}.shopar-3d{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 n=[Uint8Array,Uint32Array],r=n.length-2,o=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],i=[2,12,7,1],a=window[o[i[i[r]]]][o[i[i[i.length-1]]]],s=a.charCodeAt(r),l=s^s,c=new n[1]([l]);function u(){const e=(new TextEncoder).encode(a),t=o.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[o[t[2]]](String.fromCodePoint(...e))}const d=[1e3,2e3,4e3],h=d.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,d[n]))),p(t,n+1)}}))}function f(e){return Math.round(100*e)/100}const m=["Glasses","Shoes","Watches"],g=["Shoes"];const v="0.4.0-alpha.3";let w=`https://cdn.jsdelivr.net/npm/shopar-plugin@${v}/dist`;const y={update:e=>{null!=e&&(w=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>w};function b(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let E;const A=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let S,R,C;function I(e){const t=function(e){const t=new R.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,R.ClampToEdgeWrapping,R.ClampToEdgeWrapping,R.LinearFilter,R.LinearFilter,1,R.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=R.EquirectangularReflectionMapping,t.colorSpace=R.LinearSRGBColorSpace,t}const x=45,P=45,M=3,T=1.5,k=1,L=.5;let U,$,D,_,O,N=!1;const j=4,F=.001,W=1e-7,q=10,G=11,z=1/(G-1),Q="function"==typeof Float32Array;function V(e,t,n,r){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===r)return Y;const o=Q?new Float32Array(G):new Array(G);for(let t=0;t<G;++t)o[t]=X(t*z,e,n);function i(t){let r=0,i=1;const a=G-1;for(;i!==a&&o[i]<=t;++i)r+=z;--i;const s=r+(t-o[i])/(o[i+1]-o[i])*z,l=Z(s,e,n);return l>=F?function(e,t,n,r){for(let o=0;o<j;++o){const o=Z(t,n,r);if(0===o)return t;t-=(X(t,n,r)-e)/o}return t}(t,s,e,n):0===l?s:function(e,t,n,r,o){let i,a,s=0;do{a=t+(n-t)/2,i=X(a,r,o)-e,i>0?n=a:t=a}while(Math.abs(i)>W&&++s<q);return a}(t,r,r+z,e,n)}return function(e){return 0===e||1===e?e:X(i(e),t,r)}}function K(e,t){return 1-3*t+3*e}function B(e,t){return 3*t-6*e}function H(e){return 3*e}function X(e,t,n){return((K(t,n)*e+B(t,n))*e+H(t))*e}function Z(e,t,n){return 3*K(t,n)*e*e+2*B(t,n)*e+H(t)}function Y(e){return e}function J(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=V(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function ee(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort(((e,t)=>e.time-t.time)).map((({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:J(n)})));let r=0,o=n[0].value;return{reset:()=>{r=0},update:e=>{for(r+=e;r>=t;)r-=t;for(let e=0;e<n.length-1;e++){const t=n[e],i=n[e+1];if(r>=t.time&&r<i.time){const e=t.interpolate((r-t.time)/(i.time-t.time));o=t.value+e*(i.value-t.value)}}},get:()=>o}}const te="#",ne="time",re="interpolation",oe="yaw",ie="pitch",ae="fov",se=[ne,oe,ie,ae,re],le="s",ce="ms",ue=1e3,de="deg",he="rad",pe=Math.PI/180,fe="ease-in-out",me="cubic-bezier(",ge=")";function ve(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map((e=>function(e){const t=e.indexOf(te);return(-1!==t?e.substring(0,t):e).trim()}(e))).filter((e=>""!==e))}(e);if(null==t)throw new Error("Header missing.");const r=function(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(!se.includes(r))throw new Error(`Invalid token in header: '${r}'.`);if(t.includes(r))throw new Error(`Duplicate token in header: '${r}'.`);t.push(r)}if(!t.includes(ne))throw new Error(`Missing required token: '${ne}'.`);return t}(t.split(/\s+/)),o={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:i}=we(r,e);null!=t&&(null==o.theta&&(o.theta=[]),o.theta.push(t)),null!=n&&(null==o.phi&&(o.phi=[]),o.phi.push(n)),null!=i&&(null==o.fov&&(o.fov=[]),o.fov.push(i))}if(0===Object.values(o).length)throw new Error("At least one parameter should be animated.");return o}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const r of e){const{time:e,pitch:o,yaw:i,fov:a}=r;if(null==e)throw new Error("Time missing.");const s=be(null!==(t=r.interpolation)&&void 0!==t?t:fe);null!=i&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:i*pe,interpolation:s})),null!=o&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:o*pe,interpolation:s})),null!=a&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:a*pe,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every((t=>t.length!==e.length)))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function we(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter((e=>!(null==n?void 0:n.includes(e)))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter((t=>!e.includes(t))).join(", ")}'.`);const r=e.indexOf(ne),o=function(e){if(e.endsWith(ce))return Ae(e.substring(0,e.length-ce.length));if(e.endsWith(le))return Ae(e.substring(0,e.length-le.length))*ue;return Ae(e)}(n[r]),i=e.indexOf(re),a=be(-1===i?fe:n[i]),s={};for(let t=0;t<n.length;t++){if(t===r||t===i)continue;const l=e[t],c=n[t];switch(l){case oe:s.theta={time:o,value:ye(c),interpolation:a};break;case ie:s.phi={time:o,value:ye(c),interpolation:a};break;case ae:s.fov={time:o,value:ye(c),interpolation:a};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function ye(e){return e.endsWith(de)?Ae(e.substring(0,e.length-de.length))*pe:e.endsWith(he)?Ae(e.substring(0,e.length-he.length)):Ae(e)*pe}function be(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ee(0,0,1,1);if("sine"===e)return Ee(.37,0,.63,1);if("sine-in"===e)return Ee(.12,0,.39,0);if("sine-out"===e)return Ee(.61,1,.88,1);if("ease"===e)return Ee(.25,.1,.25,1);if("ease-in"===e)return Ee(.42,0,1,1);if("ease-out"===e)return Ee(0,0,.58,1);if("ease-in-out"===e)return Ee(.42,0,.58,1);if(e.startsWith(me)&&e.endsWith(ge)){const t=e.substring(me.length,e.length-ge.length).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Ae(t[0]),y1:Ae(t[1]),x2:Ae(t[2]),y2:Ae(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ee(e,t,n,r){return{type:"bezier",x1:e,y1:t,x2:n,y2:r}}function Ae(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}const Se=300,Re=2e3,Ce=.05,Ie=2*Math.PI/32,xe=be("hold"),Pe=be("sine"),Me=be("sine-in"),Te=be("sine-out");let ke;const Le=0,Ue=3;let $e,De,_e,Oe=!1,Ne=1,je=1,Fe=1;const We=1;let qe;const Ge=new Map;function ze(t,n,r){const o=t.getContext("2d");null==o&&console.warn("2D context missing.");let i,a,s,l,c,u,d,h,p,f,m,g,v,w,y=!1,b=!0,E=!1,A=1,k=!0,N=!1,j=0,F=0,W=1,q=1,G=1;const z={threeInit:()=>{y||(Qe(),i=new De.Scene,a=new De.PerspectiveCamera(25,1,.5),s=new $e.OrbitControls(a,t),s.setInteractionEnabled(k),h=De.ACESFilmicToneMapping,({renderShadow:c,shadowGroup:l}=function(e){const t=new U.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new U.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const r=new U.Group;r.position.y=-.7;const o=new U.PlaneGeometry(x,P).rotateX(Math.PI/2),i=new U.MeshBasicMaterial({map:t.texture,opacity:L,transparent:!0,depthWrite:!1}),a=new U.Mesh(o,i);a.renderOrder=1,a.scale.y=-1,r.add(a);const s=new U.Mesh(o);s.visible=!1,r.add(s);const l=new U.OrthographicCamera(-x/2,x/2,P/2,-P/2,0,M);function c(e){s.visible=!0,_.uniforms.tDiffuse.value=t.texture,_.uniforms.h.value=1*e/256,s.material=_,$.setRenderTarget(n),$.render(s,l),O.uniforms.tDiffuse.value=n.texture,O.uniforms.v.value=1*e/256,s.material=O,$.setRenderTarget(t),$.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,r.add(l),{shadowGroup:r,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=D;const r=$.getClearAlpha();$.setClearAlpha(0),$.setRenderTarget(t),$.render(e,l),e.overrideMaterial=null,c(T),c(.4*T),$.setRenderTarget(null),$.setClearAlpha(r),e.background=n}}}(i)),y=!0)},threeParse:(t,n,r)=>e(this,void 0,void 0,(function*(){return null!=u&&d===r||(yield u,u=(()=>e(this,void 0,void 0,(function*(){var e,r;return R=(e=$e).THREE,C=new e.RGBELoader,i.environment=I(n),function(e,t){const{THREE:n}=t;S=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder(t.MeshoptDecoder)}(qe,$e),r=t,S.parseAsync(r.buffer,"")})))(),d=r),u})),threeLoad:(e,t)=>{i.traverse((e=>{var t,n;e instanceof De.Mesh&&(null===(t=e.geometry)||void 0===t||t.dispose(),Array.isArray(e.material)?e.material.forEach((e=>e.dispose())):null===(n=e.material)||void 0===n||n.dispose())})),i.clear(),i.add(e.scene);const n=(new De.Box3).setFromObject(e.scene);l.position.y=n.min.y-Le,i.add(l),c(),i.traverse((e=>{e instanceof De.Mesh&&(e.material.depthWrite=!0)}));const r=n.min.clone().add(n.max).divideScalar(2),o=Math.sqrt($e.reduceVertices(e.scene,((e,t)=>Math.max(e,r.distanceToSquared(t))),0));s.reset(r,o,function(e,t){var n;const r={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?r.Glasses:null!==(n=r[e])&&void 0!==n?n:r.Glasses).normalize()}(t,De.Vector3)),j=0},threePaused:()=>b,threeResume:()=>{b=!1,qe.setAnimationLoop(Ve),t.style.visibility="visible",F=0,null==f||f.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset(),null==w||w.reset()},threePause:()=>{b=!0,function(){for(const{threePaused:e}of Ge.values())if(!e())return!1;return!0}()&&qe.setAnimationLoop(null),t.style.visibility="hidden",r.style.opacity="0",n.style.visibility="hidden"},threeSetToneMapping:(e,t)=>{const n={ACES:De.ACESFilmicToneMapping,Linear:De.LinearToneMapping,Neutral:De.NeutralToneMapping};null!=n[e]&&(h=n[e]),A=t},threeIsInteractive:()=>k,threeSetInteractive:e=>{k=e,null==s||s.setInteractionEnabled(k)},threeSetOnInteracted:e=>{s.removeEventListener("change",p),p=e,s.addEventListener("change",e)},threeInitPromptAnimation:()=>{var e;e=s.getTheta(),f=ee([{time:0,value:e,interpolation:xe},{time:Se,value:e,interpolation:Te},{time:Se+Re/4,value:e+Ie,interpolation:Pe},{time:Se+3*Re/4,value:e-Ie,interpolation:Me},{time:Se+Re,value:e,interpolation:xe},{time:Se+2*Re,value:e,interpolation:xe}]),m=null,g=null,v=ee([{time:0,value:0,interpolation:xe},{time:Se,value:1,interpolation:xe},{time:Se+Re,value:0,interpolation:xe},{time:Se+2*Re,value:0,interpolation:xe}]),w=ee([{time:0,value:0,interpolation:xe},{time:Se,value:0,interpolation:Te},{time:Se+Re/4,value:-Ce,interpolation:Pe},{time:Se+3*Re/4,value:Ce,interpolation:Me},{time:Se+Re,value:0,interpolation:xe},{time:Se+2*Re,value:0,interpolation:xe}])},threeInitThetaAnimation:e=>{f=e},threeInitPhiAnimation:e=>{m=e},threeInitFovAnimation:e=>{g=e},preRender_:e=>{if(!y||b)return;let t=0!==F?e-F:0;F=e,0===j?E=!0:j<Ue&&(t=0),j++,N||(s.hasUserInteracted()?(N=!0,f=null,m=null,g=null,v=null,w=null):(null==f||f.update(t),null==m||m.update(t),null==g||g.update(t),null==v||v.update(t),null==w||w.update(t),null!=f&&(s.setTheta(f.get()),E=!0),null!=m&&(s.setPhi(m.get()),E=!0),null!=g&&(s.setFovRadians(g.get()),E=!0))),s.update()&&(E=!0)},shouldRender_:()=>!(!y||b)&&E,render_:()=>{const e=qe.toneMapping,s=qe.toneMappingExposure;qe.toneMapping=h,qe.toneMappingExposure=A,qe.setViewport(0,0,t.width,t.height),qe.render(i,a),qe.toneMapping=e,qe.toneMappingExposure=s,E=!1,null!=o&&(o.clearRect(0,0,t.width,t.height),_e.width>0&&_e.height>0&&o.drawImage(_e,0,je-t.height,t.width,t.height,0,0,t.width,t.height),n.style.visibility=k&&!N?"visible":"hidden",null!=v&&(r.style.opacity=`${v.get()}`),null!=w&&(r.style.transform=`translateX(${w.get()*Math.min(W,q)}px)`))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===W&&n===q&&Fe===G||(t.width=Math.ceil(e*Fe*We),t.height=Math.ceil(n*Fe*We),W=e,q=n,G=Fe,E=!0)},target_:t};return Ge.set(t,z),z}function Qe(){if(Oe)return;$e=window.ShopAR__THREE,De=$e.THREE,_e=document.createElement("canvas");var e,t;_e.style.position="block",qe=new De.WebGLRenderer({powerPreference:"high-performance",canvas:_e,antialias:!0,alpha:!0}),qe.outputColorSpace=De.SRGBColorSpace,qe.toneMapping=De.ACESFilmicToneMapping,qe.setClearColor(new De.Color(16777215),0),e=qe,t=$e,N||(U=t.THREE,$=e,D=new U.MeshDepthMaterial,D.userData.darkness={value:k},D.onBeforeCompile=e=>{e.uniforms.darkness=D.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},D.depthTest=!1,D.depthWrite=!1,_=new U.ShaderMaterial(t.HorizontalBlurShader),_.depthTest=!1,O=new U.ShaderMaterial(t.VerticalBlurShader),O.depthTest=!1,N=!0),Ke(),Oe=!0}function Ve(e){Ke(),qe.clear();for(const{preRender_:t,shouldRender_:n,render_:r}of Ge.values())t(e),n()&&r()}function Ke(){let e=0,t=0;for(const{target_:n}of Ge.values()){const{clientWidth:r,clientHeight:o}=n;e=Math.max(e,r),t=Math.max(t,o)}const n=A();e=Math.ceil(e*n*We),t=Math.ceil(t*n*We),e===Ne&&t===je&&n===Fe||(Ne=e,je=t,Fe=n,qe.setSize(Ne,je,!1));for(const{updateSize_:e}of Ge.values())e()}const Be={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},He=Object.keys(Be);function Xe(e){return Be[e]}const Ze="shopar-error";function Ye(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const r=document.createElementNS("http://www.w3.org/2000/svg","image");r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),r.setAttribute("width",e),r.setAttribute("height",e),n.appendChild(r)}return n}function Je(e,t,n,r){const o=document.createElement("button");o.id=e,o.type="button",o.className="shopar-btn";{const e=Ye("1.75rem",r);o.appendChild(e)}{const e=document.createElement("span");e.textContent=t,o.appendChild(e)}o.ariaLabel=n;return o.style.display="none",o}const et="shopar-control";const tt="shopar-deepar-output";function nt(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",t}function rt(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function ot(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function it(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const at="shopar-main";const st="shopar-qr-output";const lt="shopar-three-output";var ct;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(ct||(ct={}));let ut=!1;function dt(){ut||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),ut=!0)}function ht(){dt();const e=function(){const e=document.createElement("div");e.id=at;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),t=function(){const e=document.createElement("div");return e.style.textAlign="center",e}(),n=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),r=function(e,t){const n=document.createElement("div");n.id=st;const r=n.style;r.position="absolute",r.top="0",r.left="0",r.width="100%",r.height="100%",r.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),o.appendChild(e);const a=document.createElement("div");return a.appendChild(t),o.appendChild(a),n}(t,n);e.appendChild(r);const o=function(){const e=document.createElement("div");e.id=tt;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",e}();e.appendChild(o);const i=function(){const e=document.createElement("canvas");e.id=lt,e.className="shopar-3d";const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",e}();e.appendChild(i);const a=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),s=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),l=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:r}=n;return r.position="absolute",r.width="100%",r.height="100%",r.pointerEvents="none",r.opacity="0",n.appendChild(e),n.appendChild(t),n}(a,s);e.appendChild(l);const c=function(){const e=Ye("2rem",`${y}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),u=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",n.pointerEvents="none",t.appendChild(e),t}(c);e.appendChild(u);const d=nt("shopar-ar-loading-container"),h=rt("shopar-ar-loading-text",Xe("loading.ar"));d.appendChild(h);const p=ot("shopar-ar-loading-bar-bg"),f=it("shopar-ar-loading-bar-fg");p.appendChild(f),d.appendChild(p),e.appendChild(d);const m=nt("shopar-3d-loading-container"),g=rt("shopar-3d-loading-text",Xe("loading.3d"));m.appendChild(g);const v=ot("shopar-3d-loading-bar-bg"),w=it("shopar-3d-loading-bar-fg");v.appendChild(w),m.appendChild(v),e.appendChild(m);const b=function(){const e=document.createElement("div"),{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",e}(),E=function(){const e=new Image,{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.objectFit="contain",t.pointerEvents="none",e}();b.appendChild(E),e.appendChild(b);const A=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),S=function(e){const t=document.createElement("div");t.id=Ze;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const r=document.createElement("div"),o=r.style;return o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",t.appendChild(r),r.appendChild(e),t}(A);e.appendChild(S);const R=function(){const e=document.createElement("div");return e.id=et,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(R);const C=Je("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");R.appendChild(C);const I=Je("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);R.appendChild(I);const x=Je("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);R.append(x);let P,M=ct.None,T=!1,k=!1,L=!1,U=!1;function $(){f.classList.remove("active"),d.style.visibility="hidden"}function D(){b.style.visibility="hidden",w.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return r},getQRImage:function(){return n},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return l},getThreeTarget:function(){return i},getThreePrompt:function(){return u},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){A.textContent=null!=e?e:"Please reload page and allow camera access to continue"},customizeQRPrompt:function(e){t.textContent=null!=e?e:"Scan on mobile or tablet to try on"},setVisibilityParameters:function(e,t,n,r,o){var i;T=e,k=t,L=n,U=r,P=o,pt(R,T),pt(C,T&&(L||k)&&M===ct.None),pt(I,T&&U&&M===ct.None),pt(x,T&&M!==ct.None),$(),D(),T||""===(i=S).style.display&&pt(i,!1)},getUIState:function(){return M},setUIState:function(e){M=e,M===ct.None?($(),D(),T&&(pt(S,!1),pt(x,!1),(k||L)&&pt(C,!0),U&&pt(I,!0))):M!==ct.QR&&M!==ct.AR&&M!==ct.Preview||T&&(pt(S,!1),pt(C,!1),pt(I,!1),pt(x,!0))},setDefaultUIActions:function(e,t,n){T&&((k||L)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,r=`${y}/img/icons/${n}`;C.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r)}(P),C.onclick=e),U&&(I.onclick=t),x.onclick=n)},startDeepARLoading:function(){f.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:$,startThreeLoading:function(){null!=E.dataset.srcSet?b.style.visibility="visible":(w.classList.add("active"),m.style.visibility="visible")},stopThreeLoading:D,setThreePosterUrl:function(e){null!=e?(E.src=e,E.dataset.srcSet="true"):delete E.dataset.srcSet},showCameraError:function(){T&&pt(S,!0)}}}function pt(e,t){e.style.display=t?"":"none"}const ft=new Map;function mt(t){let n=ft.get(t);return null==n?(n=function(){let t=0,n=null,r=null,o=null;const i=()=>(null==n&&(n=ht()),n);return{getSetupId:()=>t,incrementSetupId_:()=>t++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==r){const{getQRTarget:t,getQRImage:n}=i();r=function(t,n){let r=!0;return{qrPaused:()=>r,qrDraw:(o,i)=>e(this,void 0,void 0,(function*(){yield E;const e=`https://ar.shopar.ai/${v.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:o,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(e),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,r=!1,t.style.display=""})),qrPause:()=>e(this,void 0,void 0,(function*(){r=!0,t.style.display="none"}))}}(t(),n())}return r},findThree:()=>{if(null==o){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();o=ze(e(),t(),n())}return o}}}(),ft.set(t,n)):n.incrementSetupId_(),n}function gt(e){for(const t of ft.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:r,setUIState:o}=n;r()===ct.AR&&o(ct.None)}}let vt;const wt=new Uint8Array(16);function yt(){if(!vt&&(vt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!vt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return vt(wt)}const bt=[];for(let e=0;e<256;++e)bt.push((e+256).toString(16).slice(1));var Et={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function At(e,t,n){if(Et.randomUUID&&!t&&!e)return Et.randomUUID();const r=(e=e||{}).random||(e.rng||yt)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return bt[e[t+0]]+bt[e[t+1]]+bt[e[t+2]]+bt[e[t+3]]+"-"+bt[e[t+4]]+bt[e[t+5]]+"-"+bt[e[t+6]]+bt[e[t+7]]+"-"+bt[e[t+8]]+bt[e[t+9]]+"-"+bt[e[t+10]]+bt[e[t+11]]+bt[e[t+12]]+bt[e[t+13]]+bt[e[t+14]]+bt[e[t+15]]}(r)}const St="qrLaunch",Rt="arLaunch",Ct="previewLaunch",It="heartbeat";let xt,Pt,Mt=!1,Tt=window.navigator.userAgent||"no user agent";const kt=[];function Lt(){null==xt&&(Pt=At(),xt=b(`${y}/shopar-analytics.js`),xt.then((()=>{Mt=!0,window.ShopAR__analytics.initializeImpl(),kt.forEach((e=>e()))})))}function Ut(e){Mt?e():kt.push(e)}function $t(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Dt(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const _t=200,Ot=10;let Nt=!1,jt=null,Ft=[],Wt=[];function qt(t){return e(this,void 0,void 0,(function*(){Nt=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${y}/wasm/mediapipe`,t),jt&&clearInterval(jt);const r=[],o=[];jt=setInterval((()=>e(this,void 0,void 0,(function*(){if(Nt)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());Nt||(null!=a&&null!=s&&function(e){for(let t of Ft)t(e)}({translation:a,rotation:s}),null==e&&(r.push(t),o.push(i),r.length<Ot||(r.shift(),o.shift(),function(e,t){for(let n of Wt)n({faceWidth:e,IPD:t})}(zt(r),zt(o)))))}))),_t)}))}function Gt(){Wt=[],Ft=[],Nt=!0}function zt(e){let t=0;const n=e.length;for(let r=0;r<n;r++)t+=e[r];return t/n}function Qt(n){return e(this,void 0,void 0,(function*(){const r=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield r.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}var Vt="undefined"!=typeof Float32Array?Float32Array:Array;function Kt(){var e=new Vt(16);return Vt!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Bt(e,t,n){var r=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],u=t[7],d=t[8],h=t[9],p=t[10],f=t[11],m=t[12],g=t[13],v=t[14],w=t[15],y=n[0],b=n[1],E=n[2],A=n[3];return e[0]=y*r+b*s+E*d+A*m,e[1]=y*o+b*l+E*h+A*g,e[2]=y*i+b*c+E*p+A*v,e[3]=y*a+b*u+E*f+A*w,y=n[4],b=n[5],E=n[6],A=n[7],e[4]=y*r+b*s+E*d+A*m,e[5]=y*o+b*l+E*h+A*g,e[6]=y*i+b*c+E*p+A*v,e[7]=y*a+b*u+E*f+A*w,y=n[8],b=n[9],E=n[10],A=n[11],e[8]=y*r+b*s+E*d+A*m,e[9]=y*o+b*l+E*h+A*g,e[10]=y*i+b*c+E*p+A*v,e[11]=y*a+b*u+E*f+A*w,y=n[12],b=n[13],E=n[14],A=n[15],e[12]=y*r+b*s+E*d+A*m,e[13]=y*o+b*l+E*h+A*g,e[14]=y*i+b*c+E*p+A*v,e[15]=y*a+b*u+E*f+A*w,e}function Ht(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Xt(e,t){var n=t[0],r=t[1],o=t[2],i=t[4],a=t[5],s=t[6],l=t[8],c=t[9],u=t[10];return e[0]=Math.hypot(n,r,o),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(l,c,u),e}function Zt(e,t,n,r){var o=t[0],i=t[1],a=t[2],s=t[3],l=o+o,c=i+i,u=a+a,d=o*l,h=o*c,p=o*u,f=i*c,m=i*u,g=a*u,v=s*l,w=s*c,y=s*u,b=r[0],E=r[1],A=r[2];return e[0]=(1-(f+g))*b,e[1]=(h+y)*b,e[2]=(p-w)*b,e[3]=0,e[4]=(h-y)*E,e[5]=(1-(d+g))*E,e[6]=(m+v)*E,e[7]=0,e[8]=(p+w)*A,e[9]=(m-v)*A,e[10]=(1-(d+f))*A,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Yt(){var e=new Vt(3);return Vt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Jt(e,t,n){var r=new Vt(3);return r[0]=e,r[1]=t,r[2]=n,r}function en(e,t){var n=t[0]-e[0],r=t[1]-e[1],o=t[2]-e[2];return Math.hypot(n,r,o)}function tn(e,t,n){var r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*r+n[4]*o+n[8]*i+n[12])/a,e[1]=(n[1]*r+n[5]*o+n[9]*i+n[13])/a,e[2]=(n[2]*r+n[6]*o+n[10]*i+n[14])/a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function nn(){var e=new Vt(4);return Vt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Yt(),function(){var e,t=(e=new Vt(4),Vt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var rn;let on,an,sn;Yt(),Jt(1,0,0),Jt(0,1,0),nn(),nn(),rn=new Vt(9),Vt!=Float32Array&&(rn[1]=0,rn[2]=0,rn[3]=0,rn[5]=0,rn[6]=0,rn[7]=0),rn[0]=1,rn[4]=1,rn[8]=1;let ln,cn,un,dn,hn=!0,pn=null;const fn=new Set;let mn,gn,vn,wn,yn,bn;function En(){null==on&&(on=b(`${y}/shopar-deepar.js`))}function An(){null==an&&(an=b(`${y}/shopar-true-scale.js`))}function Sn(n){return e(this,void 0,void 0,(function*(){const{licenseKey:r,truescaleUsecase:o}=n;return yn=o,null==mn&&(mn=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(e=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))throw new t("No camera available!");var e;const n=kn(un),o=$t(n);ln=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:r||"your_license_key_goes_here",previewElement:dn,additionalOptions:{hint:bn,cameraConfig:{disableDefaultCamera:!0}}}),cn=yield Dt(o),yield Ln(ln,cn,"user"===n),"Glasses"===un&&(yield an,qt(cn),"DetectionLoop"!==yn&&_n((e=>{wn=e.faceWidth})))})))()),mn}))}function Rn(e,t){var n,r;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===un&&(n=t,r=bn,n===r||null!=n&&null!=r&&n.length===r.length&&n.every((e=>r.find((t=>e===t))))&&r.every((e=>n.find((t=>t===e))))))||(null!=ln&&(ln.shutdown(),ln=null,mn=null),un=e,bn=t)}function Cn(e){e!==dn&&(dn=e,null!=ln&&ln.changePreviewElement(dn))}function In(e){pn=e}function xn(e){ln.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(wn){const e=137/(wn+5);ln.changeParameterVector("GLASSES","","scale",e,e,e,0),ln.changeParameterVector("shopar_glasses","","scale",e,e,e,0),function(e){const t=[-8.362421,4.549,-9.275],n=[8.362421,4.549,-9.275];try{const r=$n("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),o=$n("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);ln.changeParameterVector("temple_left","","rotation",0,56.6*-r,0,0),ln.changeParameterVector("temple_right","","rotation",0,56.6*-o,0,0)}catch(e){return}}(e),Gt(),wn=null}e(),Un("Glasses")}},ln.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Un("Shoes"))},ln.callbacks.onWristTracked=t=>{t.detected&&(e(),Un("Watches"))}}function Pn(t,n){return e(this,void 0,void 0,(function*(){return null!=gn&&vn===n||(yield gn,gn=ln.switchEffect(t),vn=n),gn}))}function Mn(){return e(this,void 0,void 0,(function*(){if(null!=ln){if(hn=!1,null==cn){const e=kn(un),t=$t(e);cn=yield Dt(t),yield Ln(ln,cn,"user"===e),"Glasses"===un&&(qt(cn),"DetectionLoop"!==yn&&_n((e=>{wn=e.faceWidth})))}!function(){if(null==pn)return;if(null==un||fn.has(un))return;pn.style.visibility="visible",pn.style.opacity="1"}(),ln.setPaused(hn),dn.style.display=""}}))}function Tn(){null!=ln&&(hn=!0,ln.setPaused(hn),Gt(),null!=cn&&null!=cn.srcObject&&cn.srcObject instanceof MediaStream&&(cn.srcObject.getTracks().forEach((e=>e.stop())),cn=null),function(){if(null==pn)return;pn.style.visibility="hidden",pn.style.opacity="0"}(),ln.stopCamera(),dn.style.display="none")}function kn(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Ln(t,n,r){return e(this,void 0,void 0,(function*(){yield new Promise((o=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,r),o()}))))}}))}))}function Un(e){null!=pn&&(fn.has(e)||(fn.add(e),pn.style.opacity="0"))}function $n(e,t,n,r,o,i,a){const s=ln.getTransformationBetween(e,t),l=Ht(Yt(),s),c=function(e,t){var n=new Vt(3);Xt(n,t);var r=1/n[0],o=1/n[1],i=1/n[2],a=t[0]*r,s=t[1]*o,l=t[2]*i,c=t[4]*r,u=t[5]*o,d=t[6]*i,h=t[8]*r,p=t[9]*o,f=t[10]*i,m=a+u+f,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(d-p)/g,e[1]=(h-l)/g,e[2]=(s-c)/g):a>u&&a>f?(g=2*Math.sqrt(1+a-u-f),e[3]=(d-p)/g,e[0]=.25*g,e[1]=(s+c)/g,e[2]=(h+l)/g):u>f?(g=2*Math.sqrt(1+u-a-f),e[3]=(h-l)/g,e[0]=(s+c)/g,e[1]=.25*g,e[2]=(d+p)/g):(g=2*Math.sqrt(1+f-a-u),e[3]=(s-c)/g,e[0]=(h+l)/g,e[1]=(d+p)/g,e[2]=.25*g),e}(nn(),s);Zt(s,c,l,Jt(a,a,a));const u=ln.getTransformationBetween(t,n),d=Ht(Yt(),u);Zt(u,nn(),d,Xt(Yt(),u));const h=Bt(Kt(),s,u),p=Ht(Yt(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=ln.getTransformationBetween(n,r)}catch(e){return f}const g=Bt(Kt(),u,m),v=Bt(Kt(),s,g),w=Jt(p[0],i[1],i[2]),y=tn(Yt(),w,function(e,t){var n=t[0],r=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],u=t[8],d=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15],w=n*s-r*a,y=n*l-o*a,b=n*c-i*a,E=r*l-o*s,A=r*c-i*s,S=o*c-i*l,R=u*m-d*f,C=u*g-h*f,I=u*v-p*f,x=d*g-h*m,P=d*v-p*m,M=h*v-p*g,T=w*M-y*P+b*x+E*I-A*C+S*R;return T?(T=1/T,e[0]=(s*M-l*P+c*x)*T,e[1]=(o*P-r*M-i*x)*T,e[2]=(m*S-g*A+v*E)*T,e[3]=(h*A-d*S-p*E)*T,e[4]=(l*I-a*M-c*C)*T,e[5]=(n*M-o*I+i*C)*T,e[6]=(g*b-f*S-v*y)*T,e[7]=(u*S-h*b+p*y)*T,e[8]=(a*P-s*I+c*R)*T,e[9]=(r*I-n*P-i*R)*T,e[10]=(f*A-m*b+v*w)*T,e[11]=(d*b-u*A-p*w)*T,e[12]=(s*C-a*x-l*R)*T,e[13]=(n*x-r*C+o*R)*T,e[14]=(m*y-f*E-g*w)*T,e[15]=(u*E-d*y+h*w)*T,e):null}(Kt(),v));let b=ln.getClosestPointOnMesh(r,y);try{const e=ln.getClosestPointOnMesh(o,y);en(y,e)<en(y,b)&&(b=e)}catch(e){}const E=tn(Yt(),b,g);return f-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function Dn(e){!function(e){Ft.push(e)}(e)}function _n(e){!function(e){Wt.push(e)}(e)}var On;function Nn(){return[On.Android,On.iOS,On.Tablet].includes(function(){if("undefined"!=typeof window&&window.navigator){const e=window.navigator.userAgent,t=window.navigator.platform||"",n=["Macintosh","MacIntel","MacPPC","Mac68K"],r=["Win32","Win64","Windows","WinCE"],o=["iPhone","iPod","iPad"];return"ontouchstart"in window||navigator.maxTouchPoints>0?On.Tablet:-1!==o.indexOf(t)?On.iOS:-1!==n.indexOf(t)?On.MacOS:-1!==r.indexOf(t)?On.Windows:/Android/.test(e)?On.Android:/Linux/.test(t)?On.Linux:On.Unknown}return On.Unknown}())}function jn(r,o,i){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const u=String.fromCharCode(a+14);s>>=2,a^=s+2;const d=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${d+u+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],g=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${r}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),v=new n[0](yield(yield g.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));i+=s;const w=v.byteLength;if(c[l]=Math.min(76,o)*((a>>5)-1),152===c[l]&&(c[l]=w),i==l)return v;i=l,i^=l;for(let e=0,t=v.length;e<t;e++)c[l]^=c[i]<<13,c[l]^=c[i]>>17,c[l]^=c[i]<<5,v[e]=v[e]^c[l];return i^=c[0],i^=c[1],i^=c[2],v}))}function Fn(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Wn(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}function qn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}!function(e){e[e.Unknown=0]="Unknown",e[e.Android=1]="Android",e[e.iOS=2]="iOS",e[e.Tablet=3]="Tablet",e[e.MacOS=4]="MacOS",e[e.Windows=5]="Windows",e[e.Linux=6]="Linux"}(On||(On={}));const Gn=["AR","3D"];function zn(e){const{apiKey:n,sku:r,targetElement:o,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;Fn(n,"apiKey"),qn(n,"apiKey"),Fn(r,"sku"),qn(r,"sku"),Fn(o,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,n,r){if("string"!=typeof e)throw new t(`'${n}' must be a string.`);if(!r.includes(e))throw new t(`'${n}' must be ${r.join("' or '")}.`)}(i,"initialState",Gn),null!=a&&function(e,n){if("string"!=typeof e&&!Array.isArray(e))throw new t(`'${n}' must be a string or array.`)}(a,"initialAnimation"),null!=s&&qn(s,"baseUrl"),null!=l&&Wn(l,"defaultUI"),null!=c&&Wn(c,"interactive"),null!=u&&function(e,n,r){for(const o of r){const r=e[o];if(null!=r&&"string"!=typeof r)throw new t(`Value for key '${o}' in '${n}' must be a string.`)}}(u,"strings",He)}let Qn=!1;function Vn(n){return e(this,void 0,void 0,(function*(){const{targetElement:r}=n;y.update(n.baseUrl),Lt();const{trackEvent:o}=function(e){const t=performance.now(),n=At();return{trackEvent:(r,o={})=>{o=Object.assign(Object.assign({},o),{pluginVersion:v,userAgent:Tt,sessionId:Pt,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Ut((()=>{window.ShopAR__analytics.trackEventImpl(r,o)}))}}}(n.apiKey);o("visionSetup");const i=yield function(n){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/vision?${new URLSearchParams({apiKey:n,sid:u()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield r.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(n.apiKey);o("visionApiResponse",i);const{arKey:a}=i,s=mt(r),{getSetupId:l,findUI:c}=s,d=l();En(),An();const{setTargetElement:h,getDeepARTarget:f,setVisibilityParameters:m,getUIState:g,setUIState:w,startDeepARLoading:b,stopDeepARLoading:E,showCameraError:A}=c();if(g()!=ct.None)throw Error("UI state is not None, this is weird..");w(ct.AR),h(r),m(!1,!1,!0,!1,void 0),b(),yield on,Kn(l(),d);try{o("visionArLaunch"),Tn(),Rn("Glasses",["faceInit"]),Cn(f()),yield Sn({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Kn(l(),d),yield Mn(),Kn(l(),d)}catch(e){const n=e instanceof Error;throw o("visionArLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),A(),Tn(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{E()}return Qn=!0,{registerFacePoseListener:e=>{Qn&&(o("registerFacePoseListener"),Dn(e))},registerFaceMeasurementListener:e=>{Qn&&(o("registerFaceMeasurementListener"),_n(e))},switchEffect:t=>e(this,void 0,void 0,(function*(){Qn&&(o("switchEffect",{arUrl:t}),function(e){ln.switchEffect(e)}(t))})),clearEffect:()=>{Qn&&(o("clearEffect"),ln.clearEffect())},close:()=>{if(Qn){if(Qn=!1,o("visionClose"),g()!==ct.AR)throw new t("AR not launched.");Tn(),w(ct.None)}}}}))}function Kn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}function Bn(n){var r,o;return e(this,void 0,void 0,(function*(){zn(n);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=n;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(s),y.update(n.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(Be,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(Be[t]=n)}}(n.strings);const d=null!=c?ve(c):null,h=null!=(null==d?void 0:d.theta)?ee(d.theta):null,w=null!=(null==d?void 0:d.phi)?ee(d.phi):null,A=null!=(null==d?void 0:d.fov)?ee(d.fov):null,S=function(n,r,o,i,a){return e(this,void 0,void 0,(function*(){const s=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams(Object.assign(Object.assign(Object.assign({apiKey:n,sku:r,sid:u()},null!=o&&{theta:`${f(o)}`}),null!=i&&{phi:`${f(i)}`}),null!=a&&{fov:`${f(a)}`}))}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield s.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(i,a,null==h?void 0:h.get(),null==w?void 0:w.get(),null==A?void 0:A.get()),R=mt(s),{getSetupId:C,findUI:I,findQR:x,findThree:P}=R,M=C();Lt();const{trackEvent:T,arInteracted:k,previewInteracted:L}=function(e,t){const n=performance.now(),r=At();let o=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(o=i+a,c=!1,u(It,{engagementTotal:o,engagementAR:i,engagement3D:a}))}),1e3);const u=(o,i={})=>{i=Object.assign(Object.assign({},i),{userAgent:Tt,pluginVersion:v,sessionId:Pt,setupId:r,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Ut((()=>{window.ShopAR__analytics.trackEventImpl(o,i)}))};return{trackEvent:u,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}(a,i);T("setup",{hostname:window.location.hostname});const U=yield S;T("apiResponse",U);const{category:$,arUrl:D,arKey:_,arPromptEnabled:O,arPromptText:N,arPromptImage:j,previewUrl:F,previewEnvUrl:W,previewToneMapping:q,previewToneMappingExposure:G,previewPosterUrl:z,cameraErrorText:Q,qrPromptText:V}=U;Hn(C(),M);const K=null!=D&&function(e){return null!=e&&m.includes(e)}($),B=null==(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled)||(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled),H=K&&function(e){return null!=e&&g.includes(e)}($),X=B&&H&&!Nn(),Z=K&&!X,Y=null!=F;if(Hn(C(),M),X&&function(){e(this,void 0,void 0,(function*(){null==E&&(E=b(`${y}/shopar-qr.js`))}))}(),Z&&(En(),function(e){e!==sn&&(sn=e,Qt(e),gn=null,Gt())}(D),"Glasses"===$&&An()),Y){null==ke&&(ke=b(`${y}/shopar-three.js`));const e=255;jn(F,(new Date).getTime()+e,Math.random()*e),Qt(null!=W?W:`${y}/env/default.hdr`)}const{setTargetElement:J,getDeepARTarget:te,getDeepARPrompt:ne,customizeDeepARPrompt:re,customizeCameraError:oe,customizeQRPrompt:ie,setVisibilityParameters:ae,getUIState:se,setUIState:le,setDefaultUIActions:ce,startDeepARLoading:ue,stopDeepARLoading:de,startThreeLoading:he,stopThreeLoading:pe,setThreePosterUrl:fe,showCameraError:me}=I();J(s);ae(null==n.defaultUI||n.defaultUI,X,Z,Y,$),re(null!=N?N:"",null!=j?j:""),oe(Q),ie(V),fe(z),function(e,n){const r=e.parentNode;if(null==r)throw new t("Parent node missing.");new MutationObserver((t=>{for(const r of t)for(const t of r.removedNodes)if(t===e)return void n()})).observe(r,{childList:!0})}(s,(()=>{se()!==ct.QR||ge()||ye(),se()!==ct.AR||hn||Tn(),se()!==ct.Preview||Se()||Ce(),le(ct.None)}));const{qrPaused:ge,qrDraw:we,qrPause:ye}=x(),{threeInit:be,threeParse:Ee,threeLoad:Ae,threePaused:Se,threeResume:Re,threePause:Ce,threeSetToneMapping:Ie,threeIsInteractive:xe,threeSetInteractive:Pe,threeSetOnInteracted:Me,threeInitPromptAnimation:Te,threeInitThetaAnimation:Le,threeInitPhiAnimation:Ue,threeInitFovAnimation:$e}=P(),De=null==n.interactive||n.interactive;Pe(De);let _e=0;if(se()===ct.QR){if(!ge())if(X){T(St);try{yield we(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ye(),le(ct.None)}else if(se()===ct.AR){if(!hn)if(Z&&!Qn){T(Rt);const e=yield Qt(D);Hn(C(),M),gt(R),Rn($),Cn(te()),In(O?ne():null),yield Pn(e,D),xn(k),Hn(C(),M)}else Tn(),le(ct.None)}else if(se()===ct.Preview&&!Se())if(Y){T(Ct),he();const e=255,t=yield jn(F,(new Date).getTime()+e,Math.random()*e);Hn(C(),M);const n=yield Qt(null!=W?W:`${y}/env/default.hdr`);Hn(C(),M);const r=yield Ee(t,n,`${F}${W}`);Hn(C(),M),Ae(r,$),Ie(null!=q?q:"ACES",null!=G?G:1),Me(L),Te(),null!=d&&(Le(h),Ue(w),$e(A)),pe()}else Ce(),le(ct.None);const Oe=()=>e(this,void 0,void 0,(function*(){if(X){if(se()===ct.QR||se()===ct.AR)throw new t("AR already launched.");try{T(St);const e=++_e;if(se()===ct.Preview&&Y&&!Se()&&Ce(),le(ct.QR),yield we(i,a),_e!==e)return;return void Hn(C(),M)}catch(e){const n=e instanceof Error;throw T("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!Z)throw new t("Model does not have AR enabled.");if(se()===ct.AR)throw new t("AR already launched.");try{T(Rt);const e=++_e;se()===ct.Preview&&Y&&!Se()&&Ce(),gt(R),le(ct.AR),ue();const t=yield Qt(D);if(_e!==e)return;if(Hn(C(),M),yield on,_e!==e)return;if(Hn(C(),M),Tn(),Rn($),Cn(te()),In(O?ne():null),yield Sn({licenseKey:_}),_e!==e)return;if(Hn(C(),M),yield Pn(t,D),xn(k),_e!==e)return;if(Hn(C(),M),yield Mn(),_e!==e)return;Hn(C(),M)}catch(e){const n=e instanceof Error;throw T("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),me(),Tn(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{de()}})),Ne=()=>e(this,void 0,void 0,(function*(){if(!Y)throw new t("Model does not have 3D enabled.");if(se()===ct.Preview)throw new t("3D already launched.");try{T(Ct);const e=++_e;se()===ct.AR&&(Z&&!hn&&Tn(),ye()),le(ct.Preview),he();const t=255,n=yield jn(F,(new Date).getTime()+t,Math.random()*t);if(_e!==e)return;Hn(C(),M);const r=yield Qt(null!=W?W:`${y}/env/default.hdr`);if(_e!==e)return;if(Hn(C(),M),yield ke,_e!==e)return;if(Hn(C(),M),be(),_e!==e)return;Hn(C(),M);const o=yield Ee(n,r,`${F}${W}`);if(_e!==e)return;Hn(C(),M),Ae(o,$),Ie(null!=q?q:"ACES",null!=G?G:1),Me(L),Te(),null!=d&&(Le(h),Ue(w),$e(A)),Re()}catch(e){const n=e instanceof Error;throw T("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{pe()}})),je=()=>e(this,void 0,void 0,(function*(){if(se()===ct.None)throw new t("Neither AR or 3D launched.");++_e,se()===ct.QR||se()===ct.AR?(Z&&!hn&&Tn(),ye()):se()===ct.Preview&&Y&&!Se()&&Ce(),le(ct.None)}));return ce(Oe,Ne,je),"AR"===l?(yield Oe(),Hn(C(),M)):"3D"===l&&(yield Ne(),Hn(C(),M)),Qn=!1,{launchAR:K?Oe:void 0,launch3D:Y?Ne:void 0,closeAR:K?()=>e(this,void 0,void 0,(function*(){if(se()!==ct.AR&&se()!==ct.QR)throw new t("AR not launched.");++_e,Z&&!hn&&Tn(),ye(),le(ct.None)})):void 0,close3D:Y?()=>e(this,void 0,void 0,(function*(){if(se()!==ct.Preview)throw new t("3D not launched.");++_e,Y&&!Se()&&Ce(),le(ct.None)})):void 0,close:K||Y?je:void 0,isInteractive:()=>xe(),setInteractive:e=>Pe(e)}}))}function Hn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Xn={setup:function(t){return e(this,void 0,void 0,(function*(){return Vn(t)}))}},Zn={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,r){return e(this,void 0,void 0,(function*(){try{return r()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>Bn(n)))}))},version:v};export{Zn as plugin,Xn as vision};
|
|
1
|
+
function e(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).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}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}.shopar-3d{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 n=[Uint8Array,Uint32Array],r=n.length-2,o=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],i=[2,12,7,1],a=window[o[i[i[r]]]][o[i[i[i.length-1]]]],s=a.charCodeAt(r),l=s^s,c=new n[1]([l]);function u(){const e=(new TextEncoder).encode(a),t=o.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[o[t[2]]](String.fromCodePoint(...e))}const d=[1e3,2e3,4e3],h=d.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,d[n]))),p(t,n+1)}}))}function f(e){return Math.round(100*e)/100}const m=["Glasses","Shoes","Watches"],g=["Shoes"];const v="0.4.0";let w=`https://cdn.jsdelivr.net/npm/shopar-plugin@${v}/dist`;const y={update:e=>{null!=e&&(w=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>w};function b(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let E;const A=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let S,R,C;function I(e){const t=function(e){const t=new R.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,R.ClampToEdgeWrapping,R.ClampToEdgeWrapping,R.LinearFilter,R.LinearFilter,1,R.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=R.EquirectangularReflectionMapping,t.colorSpace=R.LinearSRGBColorSpace,t}const x=45,P=45,M=3,T=1.5,k=1,L=.5;let U,$,D,_,O,N=!1;const j=4,F=.001,W=1e-7,q=10,G=11,z=1/(G-1),Q="function"==typeof Float32Array;function V(e,t,n,r){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===r)return Y;const o=Q?new Float32Array(G):new Array(G);for(let t=0;t<G;++t)o[t]=X(t*z,e,n);function i(t){let r=0,i=1;const a=G-1;for(;i!==a&&o[i]<=t;++i)r+=z;--i;const s=r+(t-o[i])/(o[i+1]-o[i])*z,l=Z(s,e,n);return l>=F?function(e,t,n,r){for(let o=0;o<j;++o){const o=Z(t,n,r);if(0===o)return t;t-=(X(t,n,r)-e)/o}return t}(t,s,e,n):0===l?s:function(e,t,n,r,o){let i,a,s=0;do{a=t+(n-t)/2,i=X(a,r,o)-e,i>0?n=a:t=a}while(Math.abs(i)>W&&++s<q);return a}(t,r,r+z,e,n)}return function(e){return 0===e||1===e?e:X(i(e),t,r)}}function K(e,t){return 1-3*t+3*e}function B(e,t){return 3*t-6*e}function H(e){return 3*e}function X(e,t,n){return((K(t,n)*e+B(t,n))*e+H(t))*e}function Z(e,t,n){return 3*K(t,n)*e*e+2*B(t,n)*e+H(t)}function Y(e){return e}function J(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=V(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function ee(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort(((e,t)=>e.time-t.time)).map((({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:J(n)})));let r=0,o=n[0].value;return{reset:()=>{r=0},update:e=>{for(r+=e;r>=t;)r-=t;for(let e=0;e<n.length-1;e++){const t=n[e],i=n[e+1];if(r>=t.time&&r<i.time){const e=t.interpolate((r-t.time)/(i.time-t.time));o=t.value+e*(i.value-t.value)}}},get:()=>o}}const te="#",ne="time",re="interpolation",oe="yaw",ie="pitch",ae="fov",se=[ne,oe,ie,ae,re],le="s",ce="ms",ue=1e3,de="deg",he="rad",pe=Math.PI/180,fe="ease-in-out",me="cubic-bezier(",ge=")";function ve(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map((e=>function(e){const t=e.indexOf(te);return(-1!==t?e.substring(0,t):e).trim()}(e))).filter((e=>""!==e))}(e);if(null==t)throw new Error("Header missing.");const r=function(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(!se.includes(r))throw new Error(`Invalid token in header: '${r}'.`);if(t.includes(r))throw new Error(`Duplicate token in header: '${r}'.`);t.push(r)}if(!t.includes(ne))throw new Error(`Missing required token: '${ne}'.`);return t}(t.split(/\s+/)),o={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:i}=we(r,e);null!=t&&(null==o.theta&&(o.theta=[]),o.theta.push(t)),null!=n&&(null==o.phi&&(o.phi=[]),o.phi.push(n)),null!=i&&(null==o.fov&&(o.fov=[]),o.fov.push(i))}if(0===Object.values(o).length)throw new Error("At least one parameter should be animated.");return o}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const r of e){const{time:e,pitch:o,yaw:i,fov:a}=r;if(null==e)throw new Error("Time missing.");const s=be(null!==(t=r.interpolation)&&void 0!==t?t:fe);null!=i&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:i*pe,interpolation:s})),null!=o&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:o*pe,interpolation:s})),null!=a&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:a*pe,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every((t=>t.length!==e.length)))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function we(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter((e=>!(null==n?void 0:n.includes(e)))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter((t=>!e.includes(t))).join(", ")}'.`);const r=e.indexOf(ne),o=function(e){if(e.endsWith(ce))return Ae(e.substring(0,e.length-ce.length));if(e.endsWith(le))return Ae(e.substring(0,e.length-le.length))*ue;return Ae(e)}(n[r]),i=e.indexOf(re),a=be(-1===i?fe:n[i]),s={};for(let t=0;t<n.length;t++){if(t===r||t===i)continue;const l=e[t],c=n[t];switch(l){case oe:s.theta={time:o,value:ye(c),interpolation:a};break;case ie:s.phi={time:o,value:ye(c),interpolation:a};break;case ae:s.fov={time:o,value:ye(c),interpolation:a};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function ye(e){return e.endsWith(de)?Ae(e.substring(0,e.length-de.length))*pe:e.endsWith(he)?Ae(e.substring(0,e.length-he.length)):Ae(e)*pe}function be(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ee(0,0,1,1);if("sine"===e)return Ee(.37,0,.63,1);if("sine-in"===e)return Ee(.12,0,.39,0);if("sine-out"===e)return Ee(.61,1,.88,1);if("ease"===e)return Ee(.25,.1,.25,1);if("ease-in"===e)return Ee(.42,0,1,1);if("ease-out"===e)return Ee(0,0,.58,1);if("ease-in-out"===e)return Ee(.42,0,.58,1);if(e.startsWith(me)&&e.endsWith(ge)){const t=e.substring(me.length,e.length-ge.length).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Ae(t[0]),y1:Ae(t[1]),x2:Ae(t[2]),y2:Ae(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ee(e,t,n,r){return{type:"bezier",x1:e,y1:t,x2:n,y2:r}}function Ae(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}const Se=300,Re=2e3,Ce=.05,Ie=2*Math.PI/32,xe=be("hold"),Pe=be("sine"),Me=be("sine-in"),Te=be("sine-out");let ke;const Le=0,Ue=3;let $e,De,_e,Oe=!1,Ne=1,je=1,Fe=1;const We=1;let qe;const Ge=new Map;function ze(t,n,r){const o=t.getContext("2d");null==o&&console.warn("2D context missing.");let i,a,s,l,c,u,d,h,p,f,m,g,v,w,y=!1,b=!0,E=!1,A=1,k=!0,N=!1,j=0,F=0,W=1,q=1,G=1;const z={threeInit:()=>{y||(Qe(),i=new De.Scene,a=new De.PerspectiveCamera(25,1,.5),s=new $e.OrbitControls(a,t),s.setInteractionEnabled(k),h=De.ACESFilmicToneMapping,({renderShadow:c,shadowGroup:l}=function(e){const t=new U.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new U.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const r=new U.Group;r.position.y=-.7;const o=new U.PlaneGeometry(x,P).rotateX(Math.PI/2),i=new U.MeshBasicMaterial({map:t.texture,opacity:L,transparent:!0,depthWrite:!1}),a=new U.Mesh(o,i);a.renderOrder=1,a.scale.y=-1,r.add(a);const s=new U.Mesh(o);s.visible=!1,r.add(s);const l=new U.OrthographicCamera(-x/2,x/2,P/2,-P/2,0,M);function c(e){s.visible=!0,_.uniforms.tDiffuse.value=t.texture,_.uniforms.h.value=1*e/256,s.material=_,$.setRenderTarget(n),$.render(s,l),O.uniforms.tDiffuse.value=n.texture,O.uniforms.v.value=1*e/256,s.material=O,$.setRenderTarget(t),$.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,r.add(l),{shadowGroup:r,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=D;const r=$.getClearAlpha();$.setClearAlpha(0),$.setRenderTarget(t),$.render(e,l),e.overrideMaterial=null,c(T),c(.4*T),$.setRenderTarget(null),$.setClearAlpha(r),e.background=n}}}(i)),y=!0)},threeParse:(t,n,r)=>e(this,void 0,void 0,(function*(){return null!=u&&d===r||(yield u,u=(()=>e(this,void 0,void 0,(function*(){var e,r;return R=(e=$e).THREE,C=new e.RGBELoader,i.environment=I(n),function(e,t){const{THREE:n}=t;S=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder(t.MeshoptDecoder)}(qe,$e),r=t,S.parseAsync(r.buffer,"")})))(),d=r),u})),threeLoad:(e,t)=>{i.traverse((e=>{var t,n;e instanceof De.Mesh&&(null===(t=e.geometry)||void 0===t||t.dispose(),Array.isArray(e.material)?e.material.forEach((e=>e.dispose())):null===(n=e.material)||void 0===n||n.dispose())})),i.clear(),i.add(e.scene);const n=(new De.Box3).setFromObject(e.scene);l.position.y=n.min.y-Le,i.add(l),c(),i.traverse((e=>{e instanceof De.Mesh&&(e.material.depthWrite=!0)}));const r=n.min.clone().add(n.max).divideScalar(2),o=Math.sqrt($e.reduceVertices(e.scene,((e,t)=>Math.max(e,r.distanceToSquared(t))),0));s.reset(r,o,function(e,t){var n;const r={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?r.Glasses:null!==(n=r[e])&&void 0!==n?n:r.Glasses).normalize()}(t,De.Vector3)),j=0},threePaused:()=>b,threeResume:()=>{b=!1,qe.setAnimationLoop(Ve),t.style.visibility="visible",F=0,null==f||f.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset(),null==w||w.reset()},threePause:()=>{b=!0,function(){for(const{threePaused:e}of Ge.values())if(!e())return!1;return!0}()&&qe.setAnimationLoop(null),t.style.visibility="hidden",r.style.opacity="0",n.style.visibility="hidden"},threeSetToneMapping:(e,t)=>{const n={ACES:De.ACESFilmicToneMapping,Linear:De.LinearToneMapping,Neutral:De.NeutralToneMapping};null!=n[e]&&(h=n[e]),A=t},threeIsInteractive:()=>k,threeSetInteractive:e=>{k=e,null==s||s.setInteractionEnabled(k)},threeSetOnInteracted:e=>{s.removeEventListener("change",p),p=e,s.addEventListener("change",e)},threeInitPromptAnimation:()=>{var e;e=s.getTheta(),f=ee([{time:0,value:e,interpolation:xe},{time:Se,value:e,interpolation:Te},{time:Se+Re/4,value:e+Ie,interpolation:Pe},{time:Se+3*Re/4,value:e-Ie,interpolation:Me},{time:Se+Re,value:e,interpolation:xe},{time:Se+2*Re,value:e,interpolation:xe}]),m=null,g=null,v=ee([{time:0,value:0,interpolation:xe},{time:Se,value:1,interpolation:xe},{time:Se+Re,value:0,interpolation:xe},{time:Se+2*Re,value:0,interpolation:xe}]),w=ee([{time:0,value:0,interpolation:xe},{time:Se,value:0,interpolation:Te},{time:Se+Re/4,value:-Ce,interpolation:Pe},{time:Se+3*Re/4,value:Ce,interpolation:Me},{time:Se+Re,value:0,interpolation:xe},{time:Se+2*Re,value:0,interpolation:xe}])},threeInitThetaAnimation:e=>{f=e},threeInitPhiAnimation:e=>{m=e},threeInitFovAnimation:e=>{g=e},preRender_:e=>{if(!y||b)return;let t=0!==F?e-F:0;F=e,0===j?E=!0:j<Ue&&(t=0),j++,N||(s.hasUserInteracted()?(N=!0,f=null,m=null,g=null,v=null,w=null):(null==f||f.update(t),null==m||m.update(t),null==g||g.update(t),null==v||v.update(t),null==w||w.update(t),null!=f&&(s.setTheta(f.get()),E=!0),null!=m&&(s.setPhi(m.get()),E=!0),null!=g&&(s.setFovRadians(g.get()),E=!0))),s.update()&&(E=!0)},shouldRender_:()=>!(!y||b)&&E,render_:()=>{const e=qe.toneMapping,s=qe.toneMappingExposure;qe.toneMapping=h,qe.toneMappingExposure=A,qe.setViewport(0,0,t.width,t.height),qe.render(i,a),qe.toneMapping=e,qe.toneMappingExposure=s,E=!1,null!=o&&(o.clearRect(0,0,t.width,t.height),_e.width>0&&_e.height>0&&o.drawImage(_e,0,je-t.height,t.width,t.height,0,0,t.width,t.height),n.style.visibility=k&&!N?"visible":"hidden",null!=v&&(r.style.opacity=`${v.get()}`),null!=w&&(r.style.transform=`translateX(${w.get()*Math.min(W,q)}px)`))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===W&&n===q&&Fe===G||(t.width=Math.ceil(e*Fe*We),t.height=Math.ceil(n*Fe*We),W=e,q=n,G=Fe,E=!0)},target_:t};return Ge.set(t,z),z}function Qe(){if(Oe)return;$e=window.ShopAR__THREE,De=$e.THREE,_e=document.createElement("canvas");var e,t;_e.style.position="block",qe=new De.WebGLRenderer({powerPreference:"high-performance",canvas:_e,antialias:!0,alpha:!0}),qe.outputColorSpace=De.SRGBColorSpace,qe.toneMapping=De.ACESFilmicToneMapping,qe.setClearColor(new De.Color(16777215),0),e=qe,t=$e,N||(U=t.THREE,$=e,D=new U.MeshDepthMaterial,D.userData.darkness={value:k},D.onBeforeCompile=e=>{e.uniforms.darkness=D.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},D.depthTest=!1,D.depthWrite=!1,_=new U.ShaderMaterial(t.HorizontalBlurShader),_.depthTest=!1,O=new U.ShaderMaterial(t.VerticalBlurShader),O.depthTest=!1,N=!0),Ke(),Oe=!0}function Ve(e){Ke(),qe.clear();for(const{preRender_:t,shouldRender_:n,render_:r}of Ge.values())t(e),n()&&r()}function Ke(){let e=0,t=0;for(const{target_:n}of Ge.values()){const{clientWidth:r,clientHeight:o}=n;e=Math.max(e,r),t=Math.max(t,o)}const n=A();e=Math.ceil(e*n*We),t=Math.ceil(t*n*We),e===Ne&&t===je&&n===Fe||(Ne=e,je=t,Fe=n,qe.setSize(Ne,je,!1));for(const{updateSize_:e}of Ge.values())e()}const Be={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},He=Object.keys(Be);function Xe(e){return Be[e]}const Ze="shopar-error";function Ye(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const r=document.createElementNS("http://www.w3.org/2000/svg","image");r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),r.setAttribute("width",e),r.setAttribute("height",e),n.appendChild(r)}return n}function Je(e,t,n,r){const o=document.createElement("button");o.id=e,o.type="button",o.className="shopar-btn";{const e=Ye("1.75rem",r);o.appendChild(e)}{const e=document.createElement("span");e.textContent=t,o.appendChild(e)}o.ariaLabel=n;return o.style.display="none",o}const et="shopar-control";const tt="shopar-deepar-output";function nt(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",t}function rt(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function ot(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function it(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const at="shopar-main";const st="shopar-qr-output";const lt="shopar-three-output";var ct;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(ct||(ct={}));let ut=!1;function dt(){ut||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),ut=!0)}function ht(){dt();const e=function(){const e=document.createElement("div");e.id=at;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),t=function(){const e=document.createElement("div");return e.style.textAlign="center",e}(),n=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),r=function(e,t){const n=document.createElement("div");n.id=st;const r=n.style;r.position="absolute",r.top="0",r.left="0",r.width="100%",r.height="100%",r.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),o.appendChild(e);const a=document.createElement("div");return a.appendChild(t),o.appendChild(a),n}(t,n);e.appendChild(r);const o=function(){const e=document.createElement("div");e.id=tt;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",e}();e.appendChild(o);const i=function(){const e=document.createElement("canvas");e.id=lt,e.className="shopar-3d";const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",e}();e.appendChild(i);const a=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),s=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),l=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:r}=n;return r.position="absolute",r.width="100%",r.height="100%",r.pointerEvents="none",r.opacity="0",n.appendChild(e),n.appendChild(t),n}(a,s);e.appendChild(l);const c=function(){const e=Ye("2rem",`${y}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),u=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",n.pointerEvents="none",t.appendChild(e),t}(c);e.appendChild(u);const d=nt("shopar-ar-loading-container"),h=rt("shopar-ar-loading-text",Xe("loading.ar"));d.appendChild(h);const p=ot("shopar-ar-loading-bar-bg"),f=it("shopar-ar-loading-bar-fg");p.appendChild(f),d.appendChild(p),e.appendChild(d);const m=nt("shopar-3d-loading-container"),g=rt("shopar-3d-loading-text",Xe("loading.3d"));m.appendChild(g);const v=ot("shopar-3d-loading-bar-bg"),w=it("shopar-3d-loading-bar-fg");v.appendChild(w),m.appendChild(v),e.appendChild(m);const b=function(){const e=document.createElement("div"),{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",e}(),E=function(){const e=new Image,{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.objectFit="contain",t.pointerEvents="none",e}();b.appendChild(E),e.appendChild(b);const A=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),S=function(e){const t=document.createElement("div");t.id=Ze;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const r=document.createElement("div"),o=r.style;return o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",t.appendChild(r),r.appendChild(e),t}(A);e.appendChild(S);const R=function(){const e=document.createElement("div");return e.id=et,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(R);const C=Je("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");R.appendChild(C);const I=Je("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);R.appendChild(I);const x=Je("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);R.append(x);let P,M=ct.None,T=!1,k=!1,L=!1,U=!1;function $(){f.classList.remove("active"),d.style.visibility="hidden"}function D(){b.style.visibility="hidden",w.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return r},getQRImage:function(){return n},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return l},getThreeTarget:function(){return i},getThreePrompt:function(){return u},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){A.textContent=null!=e?e:"Please reload page and allow camera access to continue"},customizeQRPrompt:function(e){t.textContent=null!=e?e:"Scan on mobile or tablet to try on"},setVisibilityParameters:function(e,t,n,r,o){var i;T=e,k=t,L=n,U=r,P=o,pt(R,T),pt(C,T&&(L||k)&&M===ct.None),pt(I,T&&U&&M===ct.None),pt(x,T&&M!==ct.None),$(),D(),T||""===(i=S).style.display&&pt(i,!1)},getUIState:function(){return M},setUIState:function(e){M=e,M===ct.None?($(),D(),T&&(pt(S,!1),pt(x,!1),(k||L)&&pt(C,!0),U&&pt(I,!0))):M!==ct.QR&&M!==ct.AR&&M!==ct.Preview||T&&(pt(S,!1),pt(C,!1),pt(I,!1),pt(x,!0))},setDefaultUIActions:function(e,t,n){T&&((k||L)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,r=`${y}/img/icons/${n}`;C.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r)}(P),C.onclick=e),U&&(I.onclick=t),x.onclick=n)},startDeepARLoading:function(){f.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:$,startThreeLoading:function(){null!=E.dataset.srcSet?b.style.visibility="visible":(w.classList.add("active"),m.style.visibility="visible")},stopThreeLoading:D,setThreePosterUrl:function(e){null!=e?(E.src=e,E.dataset.srcSet="true"):delete E.dataset.srcSet},showCameraError:function(){T&&pt(S,!0)}}}function pt(e,t){e.style.display=t?"":"none"}const ft=new Map;function mt(t){let n=ft.get(t);return null==n?(n=function(){let t=0,n=null,r=null,o=null;const i=()=>(null==n&&(n=ht()),n);return{getSetupId:()=>t,incrementSetupId_:()=>t++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==r){const{getQRTarget:t,getQRImage:n}=i();r=function(t,n){let r=!0;return{qrPaused:()=>r,qrDraw:(o,i)=>e(this,void 0,void 0,(function*(){yield E;const e=`https://ar.shopar.ai/${v.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:o,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(e),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,r=!1,t.style.display=""})),qrPause:()=>e(this,void 0,void 0,(function*(){r=!0,t.style.display="none"}))}}(t(),n())}return r},findThree:()=>{if(null==o){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();o=ze(e(),t(),n())}return o}}}(),ft.set(t,n)):n.incrementSetupId_(),n}function gt(e){for(const t of ft.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:r,setUIState:o}=n;r()===ct.AR&&o(ct.None)}}let vt;const wt=new Uint8Array(16);function yt(){if(!vt&&(vt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!vt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return vt(wt)}const bt=[];for(let e=0;e<256;++e)bt.push((e+256).toString(16).slice(1));var Et={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function At(e,t,n){if(Et.randomUUID&&!t&&!e)return Et.randomUUID();const r=(e=e||{}).random||(e.rng||yt)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return bt[e[t+0]]+bt[e[t+1]]+bt[e[t+2]]+bt[e[t+3]]+"-"+bt[e[t+4]]+bt[e[t+5]]+"-"+bt[e[t+6]]+bt[e[t+7]]+"-"+bt[e[t+8]]+bt[e[t+9]]+"-"+bt[e[t+10]]+bt[e[t+11]]+bt[e[t+12]]+bt[e[t+13]]+bt[e[t+14]]+bt[e[t+15]]}(r)}const St="qrLaunch",Rt="arLaunch",Ct="previewLaunch",It="heartbeat";let xt,Pt,Mt=!1,Tt=window.navigator.userAgent||"no user agent";const kt=[];function Lt(){null==xt&&(Pt=At(),xt=b(`${y}/shopar-analytics.js`),xt.then((()=>{Mt=!0,window.ShopAR__analytics.initializeImpl(),kt.forEach((e=>e()))})))}function Ut(e){Mt?e():kt.push(e)}function $t(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Dt(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("video");return e.setAttribute("playsinline","playsinline"),e.srcObject=yield t,e}))}const _t=200,Ot=10;let Nt=!1,jt=null,Ft=[],Wt=[];function qt(t){return e(this,void 0,void 0,(function*(){Nt=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${y}/wasm/mediapipe`,t),jt&&clearInterval(jt);const r=[],o=[];jt=setInterval((()=>e(this,void 0,void 0,(function*(){if(Nt)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());Nt||(null!=a&&null!=s&&function(e){for(let t of Ft)t(e)}({translation:a,rotation:s}),null==e&&(r.push(t),o.push(i),r.length<Ot||(r.shift(),o.shift(),function(e,t){for(let n of Wt)n({faceWidth:e,IPD:t})}(zt(r),zt(o)))))}))),_t)}))}function Gt(){Wt=[],Ft=[],Nt=!0}function zt(e){let t=0;const n=e.length;for(let r=0;r<n;r++)t+=e[r];return t/n}function Qt(n){return e(this,void 0,void 0,(function*(){const r=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield r.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}var Vt="undefined"!=typeof Float32Array?Float32Array:Array;function Kt(){var e=new Vt(16);return Vt!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Bt(e,t,n){var r=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],u=t[7],d=t[8],h=t[9],p=t[10],f=t[11],m=t[12],g=t[13],v=t[14],w=t[15],y=n[0],b=n[1],E=n[2],A=n[3];return e[0]=y*r+b*s+E*d+A*m,e[1]=y*o+b*l+E*h+A*g,e[2]=y*i+b*c+E*p+A*v,e[3]=y*a+b*u+E*f+A*w,y=n[4],b=n[5],E=n[6],A=n[7],e[4]=y*r+b*s+E*d+A*m,e[5]=y*o+b*l+E*h+A*g,e[6]=y*i+b*c+E*p+A*v,e[7]=y*a+b*u+E*f+A*w,y=n[8],b=n[9],E=n[10],A=n[11],e[8]=y*r+b*s+E*d+A*m,e[9]=y*o+b*l+E*h+A*g,e[10]=y*i+b*c+E*p+A*v,e[11]=y*a+b*u+E*f+A*w,y=n[12],b=n[13],E=n[14],A=n[15],e[12]=y*r+b*s+E*d+A*m,e[13]=y*o+b*l+E*h+A*g,e[14]=y*i+b*c+E*p+A*v,e[15]=y*a+b*u+E*f+A*w,e}function Ht(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Xt(e,t){var n=t[0],r=t[1],o=t[2],i=t[4],a=t[5],s=t[6],l=t[8],c=t[9],u=t[10];return e[0]=Math.hypot(n,r,o),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(l,c,u),e}function Zt(e,t,n,r){var o=t[0],i=t[1],a=t[2],s=t[3],l=o+o,c=i+i,u=a+a,d=o*l,h=o*c,p=o*u,f=i*c,m=i*u,g=a*u,v=s*l,w=s*c,y=s*u,b=r[0],E=r[1],A=r[2];return e[0]=(1-(f+g))*b,e[1]=(h+y)*b,e[2]=(p-w)*b,e[3]=0,e[4]=(h-y)*E,e[5]=(1-(d+g))*E,e[6]=(m+v)*E,e[7]=0,e[8]=(p+w)*A,e[9]=(m-v)*A,e[10]=(1-(d+f))*A,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Yt(){var e=new Vt(3);return Vt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Jt(e,t,n){var r=new Vt(3);return r[0]=e,r[1]=t,r[2]=n,r}function en(e,t){var n=t[0]-e[0],r=t[1]-e[1],o=t[2]-e[2];return Math.hypot(n,r,o)}function tn(e,t,n){var r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*r+n[4]*o+n[8]*i+n[12])/a,e[1]=(n[1]*r+n[5]*o+n[9]*i+n[13])/a,e[2]=(n[2]*r+n[6]*o+n[10]*i+n[14])/a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function nn(){var e=new Vt(4);return Vt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Yt(),function(){var e,t=(e=new Vt(4),Vt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var rn;let on,an,sn;Yt(),Jt(1,0,0),Jt(0,1,0),nn(),nn(),rn=new Vt(9),Vt!=Float32Array&&(rn[1]=0,rn[2]=0,rn[3]=0,rn[5]=0,rn[6]=0,rn[7]=0),rn[0]=1,rn[4]=1,rn[8]=1;let ln,cn,un,dn,hn=!0,pn=null;const fn=new Set;let mn,gn,vn,wn,yn,bn;function En(){null==on&&(on=b(`${y}/shopar-deepar.js`))}function An(){null==an&&(an=b(`${y}/shopar-true-scale.js`))}function Sn(n){return e(this,void 0,void 0,(function*(){const{licenseKey:r,truescaleUsecase:o}=n;return yn=o,null==mn&&(mn=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(e=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))throw new t("No camera available!");var e;const n=kn(un),o=$t(n);ln=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:r||"your_license_key_goes_here",previewElement:dn,additionalOptions:{hint:bn,cameraConfig:{disableDefaultCamera:!0}}}),cn=yield Dt(o),yield Ln(ln,cn,"user"===n),"Glasses"===un&&(yield an,qt(cn),"DetectionLoop"!==yn&&_n((e=>{wn=e.faceWidth})))})))()),mn}))}function Rn(e,t){var n,r;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===un&&(n=t,r=bn,n===r||null!=n&&null!=r&&n.length===r.length&&n.every((e=>r.find((t=>e===t))))&&r.every((e=>n.find((t=>t===e))))))||(null!=ln&&(ln.shutdown(),ln=null,mn=null),un=e,bn=t)}function Cn(e){e!==dn&&(dn=e,null!=ln&&ln.changePreviewElement(dn))}function In(e){pn=e}function xn(e){ln.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(wn){const e=137/(wn+5);ln.changeParameterVector("GLASSES","","scale",e,e,e,0),ln.changeParameterVector("shopar_glasses","","scale",e,e,e,0),function(e){const t=[-8.362421,4.549,-9.275],n=[8.362421,4.549,-9.275];try{const r=$n("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),o=$n("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);ln.changeParameterVector("temple_left","","rotation",0,56.6*-r,0,0),ln.changeParameterVector("temple_right","","rotation",0,56.6*-o,0,0)}catch(e){return}}(e),Gt(),wn=null}e(),Un("Glasses")}},ln.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Un("Shoes"))},ln.callbacks.onWristTracked=t=>{t.detected&&(e(),Un("Watches"))}}function Pn(t,n){return e(this,void 0,void 0,(function*(){return null!=gn&&vn===n||(yield gn,gn=ln.switchEffect(t),vn=n),gn}))}function Mn(){return e(this,void 0,void 0,(function*(){if(null!=ln){if(hn=!1,null==cn){const e=kn(un),t=$t(e);cn=yield Dt(t),yield Ln(ln,cn,"user"===e),"Glasses"===un&&(qt(cn),"DetectionLoop"!==yn&&_n((e=>{wn=e.faceWidth})))}!function(){if(null==pn)return;if(null==un||fn.has(un))return;pn.style.visibility="visible",pn.style.opacity="1"}(),ln.setPaused(hn),dn.style.display=""}}))}function Tn(){null!=ln&&(hn=!0,ln.setPaused(hn),Gt(),null!=cn&&null!=cn.srcObject&&cn.srcObject instanceof MediaStream&&(cn.srcObject.getTracks().forEach((e=>e.stop())),cn=null),function(){if(null==pn)return;pn.style.visibility="hidden",pn.style.opacity="0"}(),ln.stopCamera(),dn.style.display="none")}function kn(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Ln(t,n,r){return e(this,void 0,void 0,(function*(){yield new Promise((o=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,r),o()}))))}}))}))}function Un(e){null!=pn&&(fn.has(e)||(fn.add(e),pn.style.opacity="0"))}function $n(e,t,n,r,o,i,a){const s=ln.getTransformationBetween(e,t),l=Ht(Yt(),s),c=function(e,t){var n=new Vt(3);Xt(n,t);var r=1/n[0],o=1/n[1],i=1/n[2],a=t[0]*r,s=t[1]*o,l=t[2]*i,c=t[4]*r,u=t[5]*o,d=t[6]*i,h=t[8]*r,p=t[9]*o,f=t[10]*i,m=a+u+f,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(d-p)/g,e[1]=(h-l)/g,e[2]=(s-c)/g):a>u&&a>f?(g=2*Math.sqrt(1+a-u-f),e[3]=(d-p)/g,e[0]=.25*g,e[1]=(s+c)/g,e[2]=(h+l)/g):u>f?(g=2*Math.sqrt(1+u-a-f),e[3]=(h-l)/g,e[0]=(s+c)/g,e[1]=.25*g,e[2]=(d+p)/g):(g=2*Math.sqrt(1+f-a-u),e[3]=(s-c)/g,e[0]=(h+l)/g,e[1]=(d+p)/g,e[2]=.25*g),e}(nn(),s);Zt(s,c,l,Jt(a,a,a));const u=ln.getTransformationBetween(t,n),d=Ht(Yt(),u);Zt(u,nn(),d,Xt(Yt(),u));const h=Bt(Kt(),s,u),p=Ht(Yt(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=ln.getTransformationBetween(n,r)}catch(e){return f}const g=Bt(Kt(),u,m),v=Bt(Kt(),s,g),w=Jt(p[0],i[1],i[2]),y=tn(Yt(),w,function(e,t){var n=t[0],r=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],u=t[8],d=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15],w=n*s-r*a,y=n*l-o*a,b=n*c-i*a,E=r*l-o*s,A=r*c-i*s,S=o*c-i*l,R=u*m-d*f,C=u*g-h*f,I=u*v-p*f,x=d*g-h*m,P=d*v-p*m,M=h*v-p*g,T=w*M-y*P+b*x+E*I-A*C+S*R;return T?(T=1/T,e[0]=(s*M-l*P+c*x)*T,e[1]=(o*P-r*M-i*x)*T,e[2]=(m*S-g*A+v*E)*T,e[3]=(h*A-d*S-p*E)*T,e[4]=(l*I-a*M-c*C)*T,e[5]=(n*M-o*I+i*C)*T,e[6]=(g*b-f*S-v*y)*T,e[7]=(u*S-h*b+p*y)*T,e[8]=(a*P-s*I+c*R)*T,e[9]=(r*I-n*P-i*R)*T,e[10]=(f*A-m*b+v*w)*T,e[11]=(d*b-u*A-p*w)*T,e[12]=(s*C-a*x-l*R)*T,e[13]=(n*x-r*C+o*R)*T,e[14]=(m*y-f*E-g*w)*T,e[15]=(u*E-d*y+h*w)*T,e):null}(Kt(),v));let b=ln.getClosestPointOnMesh(r,y);try{const e=ln.getClosestPointOnMesh(o,y);en(y,e)<en(y,b)&&(b=e)}catch(e){}const E=tn(Yt(),b,g);return f-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function Dn(e){!function(e){Ft.push(e)}(e)}function _n(e){!function(e){Wt.push(e)}(e)}var On;function Nn(){return[On.Android,On.iOS,On.Tablet].includes(function(){if("undefined"!=typeof window&&window.navigator){const e=window.navigator.userAgent,t=window.navigator.platform||"",n=["Macintosh","MacIntel","MacPPC","Mac68K"],r=["Win32","Win64","Windows","WinCE"],o=["iPhone","iPod","iPad"];return"ontouchstart"in window||navigator.maxTouchPoints>0?On.Tablet:-1!==o.indexOf(t)?On.iOS:-1!==n.indexOf(t)?On.MacOS:-1!==r.indexOf(t)?On.Windows:/Android/.test(e)?On.Android:/Linux/.test(t)?On.Linux:On.Unknown}return On.Unknown}())}function jn(r,o,i){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const u=String.fromCharCode(a+14);s>>=2,a^=s+2;const d=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${d+u+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],g=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${r}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),v=new n[0](yield(yield g.blob().catch((()=>{throw new t("Unknown error.")}))).arrayBuffer().catch((()=>{throw new t("Unknown error.")})));i+=s;const w=v.byteLength;if(c[l]=Math.min(76,o)*((a>>5)-1),152===c[l]&&(c[l]=w),i==l)return v;i=l,i^=l;for(let e=0,t=v.length;e<t;e++)c[l]^=c[i]<<13,c[l]^=c[i]>>17,c[l]^=c[i]<<5,v[e]=v[e]^c[l];return i^=c[0],i^=c[1],i^=c[2],v}))}function Fn(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Wn(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}function qn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}!function(e){e[e.Unknown=0]="Unknown",e[e.Android=1]="Android",e[e.iOS=2]="iOS",e[e.Tablet=3]="Tablet",e[e.MacOS=4]="MacOS",e[e.Windows=5]="Windows",e[e.Linux=6]="Linux"}(On||(On={}));const Gn=["AR","3D"];function zn(e){const{apiKey:n,sku:r,targetElement:o,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;Fn(n,"apiKey"),qn(n,"apiKey"),Fn(r,"sku"),qn(r,"sku"),Fn(o,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,n,r){if("string"!=typeof e)throw new t(`'${n}' must be a string.`);if(!r.includes(e))throw new t(`'${n}' must be ${r.join("' or '")}.`)}(i,"initialState",Gn),null!=a&&function(e,n){if("string"!=typeof e&&!Array.isArray(e))throw new t(`'${n}' must be a string or array.`)}(a,"initialAnimation"),null!=s&&qn(s,"baseUrl"),null!=l&&Wn(l,"defaultUI"),null!=c&&Wn(c,"interactive"),null!=u&&function(e,n,r){for(const o of r){const r=e[o];if(null!=r&&"string"!=typeof r)throw new t(`Value for key '${o}' in '${n}' must be a string.`)}}(u,"strings",He)}let Qn=!1;function Vn(n){return e(this,void 0,void 0,(function*(){const{targetElement:r}=n;y.update(n.baseUrl),Lt();const{trackEvent:o}=function(e){const t=performance.now(),n=At();return{trackEvent:(r,o={})=>{o=Object.assign(Object.assign({},o),{pluginVersion:v,userAgent:Tt,sessionId:Pt,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Ut((()=>{window.ShopAR__analytics.trackEventImpl(r,o)}))}}}(n.apiKey);o("visionSetup");const i=yield function(n){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/vision?${new URLSearchParams({apiKey:n,sid:u()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield r.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(n.apiKey);o("visionApiResponse",i);const{arKey:a}=i,s=mt(r),{getSetupId:l,findUI:c}=s,d=l();En(),An();const{setTargetElement:h,getDeepARTarget:f,setVisibilityParameters:m,getUIState:g,setUIState:w,startDeepARLoading:b,stopDeepARLoading:E,showCameraError:A}=c();if(g()!=ct.None)throw Error("UI state is not None, this is weird..");w(ct.AR),h(r),m(!1,!1,!0,!1,void 0),b(),yield on,Kn(l(),d);try{o("visionArLaunch"),Tn(),Rn("Glasses",["faceInit"]),Cn(f()),yield Sn({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Kn(l(),d),yield Mn(),Kn(l(),d)}catch(e){const n=e instanceof Error;throw o("visionArLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),A(),Tn(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{E()}return Qn=!0,{registerFacePoseListener:e=>{Qn&&(o("registerFacePoseListener"),Dn(e))},registerFaceMeasurementListener:e=>{Qn&&(o("registerFaceMeasurementListener"),_n(e))},switchEffect:t=>e(this,void 0,void 0,(function*(){Qn&&(o("switchEffect",{arUrl:t}),function(e){ln.switchEffect(e)}(t))})),clearEffect:()=>{Qn&&(o("clearEffect"),ln.clearEffect())},close:()=>{if(Qn){if(Qn=!1,o("visionClose"),g()!==ct.AR)throw new t("AR not launched.");Tn(),w(ct.None)}}}}))}function Kn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}function Bn(n){var r,o;return e(this,void 0,void 0,(function*(){zn(n);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=n;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(s),y.update(n.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(Be,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(Be[t]=n)}}(n.strings);const d=null!=c?ve(c):null,h=null!=(null==d?void 0:d.theta)?ee(d.theta):null,w=null!=(null==d?void 0:d.phi)?ee(d.phi):null,A=null!=(null==d?void 0:d.fov)?ee(d.fov):null,S=function(n,r,o,i,a){return e(this,void 0,void 0,(function*(){const s=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams(Object.assign(Object.assign(Object.assign({apiKey:n,sku:r,sid:u()},null!=o&&{theta:`${f(o)}`}),null!=i&&{phi:`${f(i)}`}),null!=a&&{fov:`${f(a)}`}))}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield s.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(i,a,null==h?void 0:h.get(),null==w?void 0:w.get(),null==A?void 0:A.get()),R=mt(s),{getSetupId:C,findUI:I,findQR:x,findThree:P}=R,M=C();Lt();const{trackEvent:T,arInteracted:k,previewInteracted:L}=function(e,t){const n=performance.now(),r=At();let o=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(o=i+a,c=!1,u(It,{engagementTotal:o,engagementAR:i,engagement3D:a}))}),1e3);const u=(o,i={})=>{i=Object.assign(Object.assign({},i),{userAgent:Tt,pluginVersion:v,sessionId:Pt,setupId:r,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Ut((()=>{window.ShopAR__analytics.trackEventImpl(o,i)}))};return{trackEvent:u,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}(a,i);T("setup",{hostname:window.location.hostname});const U=yield S;T("apiResponse",U);const{category:$,arUrl:D,arKey:_,arPromptEnabled:O,arPromptText:N,arPromptImage:j,previewUrl:F,previewEnvUrl:W,previewToneMapping:q,previewToneMappingExposure:G,previewPosterUrl:z,cameraErrorText:Q,qrPromptText:V}=U;Hn(C(),M);const K=null!=D&&function(e){return null!=e&&m.includes(e)}($),B=null==(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled)||(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled),H=K&&function(e){return null!=e&&g.includes(e)}($),X=B&&H&&!Nn(),Z=K&&!X,Y=null!=F;if(Hn(C(),M),X&&function(){e(this,void 0,void 0,(function*(){null==E&&(E=b(`${y}/shopar-qr.js`))}))}(),Z&&(En(),function(e){e!==sn&&(sn=e,Qt(e),gn=null,Gt())}(D),"Glasses"===$&&An()),Y){null==ke&&(ke=b(`${y}/shopar-three.js`));const e=255;jn(F,(new Date).getTime()+e,Math.random()*e),Qt(null!=W?W:`${y}/env/default.hdr`)}const{setTargetElement:J,getDeepARTarget:te,getDeepARPrompt:ne,customizeDeepARPrompt:re,customizeCameraError:oe,customizeQRPrompt:ie,setVisibilityParameters:ae,getUIState:se,setUIState:le,setDefaultUIActions:ce,startDeepARLoading:ue,stopDeepARLoading:de,startThreeLoading:he,stopThreeLoading:pe,setThreePosterUrl:fe,showCameraError:me}=I();J(s);ae(null==n.defaultUI||n.defaultUI,X,Z,Y,$),re(null!=N?N:"",null!=j?j:""),oe(Q),ie(V),fe(z),function(e,n){const r=e.parentNode;if(null==r)throw new t("Parent node missing.");new MutationObserver((t=>{for(const r of t)for(const t of r.removedNodes)if(t===e)return void n()})).observe(r,{childList:!0})}(s,(()=>{se()!==ct.QR||ge()||ye(),se()!==ct.AR||hn||Tn(),se()!==ct.Preview||Se()||Ce(),le(ct.None)}));const{qrPaused:ge,qrDraw:we,qrPause:ye}=x(),{threeInit:be,threeParse:Ee,threeLoad:Ae,threePaused:Se,threeResume:Re,threePause:Ce,threeSetToneMapping:Ie,threeIsInteractive:xe,threeSetInteractive:Pe,threeSetOnInteracted:Me,threeInitPromptAnimation:Te,threeInitThetaAnimation:Le,threeInitPhiAnimation:Ue,threeInitFovAnimation:$e}=P(),De=null==n.interactive||n.interactive;Pe(De);let _e=0;if(se()===ct.QR){if(!ge())if(X){T(St);try{yield we(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ye(),le(ct.None)}else if(se()===ct.AR){if(!hn)if(Z&&!Qn){T(Rt);const e=yield Qt(D);Hn(C(),M),gt(R),Rn($),Cn(te()),In(O?ne():null),yield Pn(e,D),xn(k),Hn(C(),M)}else Tn(),le(ct.None)}else if(se()===ct.Preview&&!Se())if(Y){T(Ct),he();const e=255,t=yield jn(F,(new Date).getTime()+e,Math.random()*e);Hn(C(),M);const n=yield Qt(null!=W?W:`${y}/env/default.hdr`);Hn(C(),M);const r=yield Ee(t,n,`${F}${W}`);Hn(C(),M),Ae(r,$),Ie(null!=q?q:"ACES",null!=G?G:1),Me(L),Te(),null!=d&&(Le(h),Ue(w),$e(A)),pe()}else Ce(),le(ct.None);const Oe=()=>e(this,void 0,void 0,(function*(){if(X){if(se()===ct.QR||se()===ct.AR)throw new t("AR already launched.");try{T(St);const e=++_e;if(se()===ct.Preview&&Y&&!Se()&&Ce(),le(ct.QR),yield we(i,a),_e!==e)return;return void Hn(C(),M)}catch(e){const n=e instanceof Error;throw T("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!Z)throw new t("Model does not have AR enabled.");if(se()===ct.AR)throw new t("AR already launched.");try{T(Rt);const e=++_e;se()===ct.Preview&&Y&&!Se()&&Ce(),gt(R),le(ct.AR),ue();const t=yield Qt(D);if(_e!==e)return;if(Hn(C(),M),yield on,_e!==e)return;if(Hn(C(),M),Tn(),Rn($),Cn(te()),In(O?ne():null),yield Sn({licenseKey:_}),_e!==e)return;if(Hn(C(),M),yield Pn(t,D),xn(k),_e!==e)return;if(Hn(C(),M),yield Mn(),_e!==e)return;Hn(C(),M)}catch(e){const n=e instanceof Error;throw T("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),me(),Tn(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{de()}})),Ne=()=>e(this,void 0,void 0,(function*(){if(!Y)throw new t("Model does not have 3D enabled.");if(se()===ct.Preview)throw new t("3D already launched.");try{T(Ct);const e=++_e;se()===ct.AR&&(Z&&!hn&&Tn(),ye()),le(ct.Preview),he();const t=255,n=yield jn(F,(new Date).getTime()+t,Math.random()*t);if(_e!==e)return;Hn(C(),M);const r=yield Qt(null!=W?W:`${y}/env/default.hdr`);if(_e!==e)return;if(Hn(C(),M),yield ke,_e!==e)return;if(Hn(C(),M),be(),_e!==e)return;Hn(C(),M);const o=yield Ee(n,r,`${F}${W}`);if(_e!==e)return;Hn(C(),M),Ae(o,$),Ie(null!=q?q:"ACES",null!=G?G:1),Me(L),Te(),null!=d&&(Le(h),Ue(w),$e(A)),Re()}catch(e){const n=e instanceof Error;throw T("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{pe()}})),je=()=>e(this,void 0,void 0,(function*(){if(se()===ct.None)throw new t("Neither AR or 3D launched.");++_e,se()===ct.QR||se()===ct.AR?(Z&&!hn&&Tn(),ye()):se()===ct.Preview&&Y&&!Se()&&Ce(),le(ct.None)}));return ce(Oe,Ne,je),"AR"===l?(yield Oe(),Hn(C(),M)):"3D"===l&&(yield Ne(),Hn(C(),M)),Qn=!1,{launchAR:K?Oe:void 0,launch3D:Y?Ne:void 0,closeAR:K?()=>e(this,void 0,void 0,(function*(){if(se()!==ct.AR&&se()!==ct.QR)throw new t("AR not launched.");++_e,Z&&!hn&&Tn(),ye(),le(ct.None)})):void 0,close3D:Y?()=>e(this,void 0,void 0,(function*(){if(se()!==ct.Preview)throw new t("3D not launched.");++_e,Y&&!Se()&&Ce(),le(ct.None)})):void 0,close:K||Y?je:void 0,isInteractive:()=>xe(),setInteractive:e=>Pe(e)}}))}function Hn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Xn={setup:function(t){return e(this,void 0,void 0,(function*(){return Vn(t)}))}},Zn={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,r){return e(this,void 0,void 0,(function*(){try{return r()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>Bn(n)))}))},version:v};export{Zn as plugin,Xn as vision};
|
package/dist/shopar-plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).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}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}.shopar-3d{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 r=[Uint8Array,Uint32Array],o=r.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[i[a[a[o]]]][i[a[a[a.length-1]]]],l=s.charCodeAt(o),c=l^l,u=new r[1]([c]);function d(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],f=h.length;function p(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=f)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),p(e,n+1)}}))}function m(e){return Math.round(100*e)/100}const g=["Glasses","Shoes","Watches"],v=["Shoes"];const w="0.4.0-alpha.3";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${w}/dist`;const b={update:e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>y};function E(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let A;const S=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let R,x,C;function I(e){const t=function(e){const t=new x.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,x.ClampToEdgeWrapping,x.ClampToEdgeWrapping,x.LinearFilter,x.LinearFilter,1,x.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=x.EquirectangularReflectionMapping,t.colorSpace=x.LinearSRGBColorSpace,t}const P=45,M=45,T=3,k=1.5,L=1,U=.5;let $,D,_,O,N,j=!1;const F=4,W=.001,q=1e-7,G=10,z=11,Q=1/(z-1),V="function"==typeof Float32Array;function K(e,t,n,r){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===r)return J;const o=V?new Float32Array(z):new Array(z);for(let t=0;t<z;++t)o[t]=Z(t*Q,e,n);function i(t){let r=0,i=1;const a=z-1;for(;i!==a&&o[i]<=t;++i)r+=Q;--i;const s=r+(t-o[i])/(o[i+1]-o[i])*Q,l=Y(s,e,n);return l>=W?function(e,t,n,r){for(let o=0;o<F;++o){const o=Y(t,n,r);if(0===o)return t;t-=(Z(t,n,r)-e)/o}return t}(t,s,e,n):0===l?s:function(e,t,n,r,o){let i,a,s=0;do{a=t+(n-t)/2,i=Z(a,r,o)-e,i>0?n=a:t=a}while(Math.abs(i)>q&&++s<G);return a}(t,r,r+Q,e,n)}return function(e){return 0===e||1===e?e:Z(i(e),t,r)}}function B(e,t){return 1-3*t+3*e}function H(e,t){return 3*t-6*e}function X(e){return 3*e}function Z(e,t,n){return((B(t,n)*e+H(t,n))*e+X(t))*e}function Y(e,t,n){return 3*B(t,n)*e*e+2*H(t,n)*e+X(t)}function J(e){return e}function ee(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=K(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function te(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort(((e,t)=>e.time-t.time)).map((({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:ee(n)})));let r=0,o=n[0].value;return{reset:()=>{r=0},update:e=>{for(r+=e;r>=t;)r-=t;for(let e=0;e<n.length-1;e++){const t=n[e],i=n[e+1];if(r>=t.time&&r<i.time){const e=t.interpolate((r-t.time)/(i.time-t.time));o=t.value+e*(i.value-t.value)}}},get:()=>o}}const ne="#",re="time",oe="interpolation",ie="yaw",ae="pitch",se="fov",le=[re,ie,ae,se,oe],ce="s",ue="ms",de=1e3,he="deg",fe="rad",pe=Math.PI/180,me="ease-in-out",ge="cubic-bezier(",ve=")";function we(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map((e=>function(e){const t=e.indexOf(ne);return(-1!==t?e.substring(0,t):e).trim()}(e))).filter((e=>""!==e))}(e);if(null==t)throw new Error("Header missing.");const r=function(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(!le.includes(r))throw new Error(`Invalid token in header: '${r}'.`);if(t.includes(r))throw new Error(`Duplicate token in header: '${r}'.`);t.push(r)}if(!t.includes(re))throw new Error(`Missing required token: '${re}'.`);return t}(t.split(/\s+/)),o={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:i}=ye(r,e);null!=t&&(null==o.theta&&(o.theta=[]),o.theta.push(t)),null!=n&&(null==o.phi&&(o.phi=[]),o.phi.push(n)),null!=i&&(null==o.fov&&(o.fov=[]),o.fov.push(i))}if(0===Object.values(o).length)throw new Error("At least one parameter should be animated.");return o}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const r of e){const{time:e,pitch:o,yaw:i,fov:a}=r;if(null==e)throw new Error("Time missing.");const s=Ee(null!==(t=r.interpolation)&&void 0!==t?t:me);null!=i&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:i*pe,interpolation:s})),null!=o&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:o*pe,interpolation:s})),null!=a&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:a*pe,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every((t=>t.length!==e.length)))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function ye(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter((e=>!(null==n?void 0:n.includes(e)))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter((t=>!e.includes(t))).join(", ")}'.`);const r=e.indexOf(re),o=function(e){if(e.endsWith(ue))return Se(e.substring(0,e.length-ue.length));if(e.endsWith(ce))return Se(e.substring(0,e.length-ce.length))*de;return Se(e)}(n[r]),i=e.indexOf(oe),a=Ee(-1===i?me:n[i]),s={};for(let t=0;t<n.length;t++){if(t===r||t===i)continue;const l=e[t],c=n[t];switch(l){case ie:s.theta={time:o,value:be(c),interpolation:a};break;case ae:s.phi={time:o,value:be(c),interpolation:a};break;case se:s.fov={time:o,value:be(c),interpolation:a};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function be(e){return e.endsWith(he)?Se(e.substring(0,e.length-he.length))*pe:e.endsWith(fe)?Se(e.substring(0,e.length-fe.length)):Se(e)*pe}function Ee(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ae(0,0,1,1);if("sine"===e)return Ae(.37,0,.63,1);if("sine-in"===e)return Ae(.12,0,.39,0);if("sine-out"===e)return Ae(.61,1,.88,1);if("ease"===e)return Ae(.25,.1,.25,1);if("ease-in"===e)return Ae(.42,0,1,1);if("ease-out"===e)return Ae(0,0,.58,1);if("ease-in-out"===e)return Ae(.42,0,.58,1);if(e.startsWith(ge)&&e.endsWith(ve)){const t=e.substring(ge.length,e.length-ve.length).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Se(t[0]),y1:Se(t[1]),x2:Se(t[2]),y2:Se(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ae(e,t,n,r){return{type:"bezier",x1:e,y1:t,x2:n,y2:r}}function Se(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}const Re=300,xe=2e3,Ce=.05,Ie=2*Math.PI/32,Pe=Ee("hold"),Me=Ee("sine"),Te=Ee("sine-in"),ke=Ee("sine-out");let Le;const Ue=0,$e=3;let De,_e,Oe,Ne=!1,je=1,Fe=1,We=1;const qe=1;let Ge;const ze=new Map;function Qe(e,n,r){const o=e.getContext("2d");null==o&&console.warn("2D context missing.");let i,a,s,l,c,u,d,h,f,p,m,g,v,w,y=!1,b=!0,E=!1,A=1,S=!0,L=!1,j=0,F=0,W=1,q=1,G=1;const z={threeInit:()=>{y||(Ve(),i=new _e.Scene,a=new _e.PerspectiveCamera(25,1,.5),s=new De.OrbitControls(a,e),s.setInteractionEnabled(S),h=_e.ACESFilmicToneMapping,({renderShadow:c,shadowGroup:l}=function(e){const t=new $.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new $.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const r=new $.Group;r.position.y=-.7;const o=new $.PlaneGeometry(P,M).rotateX(Math.PI/2),i=new $.MeshBasicMaterial({map:t.texture,opacity:U,transparent:!0,depthWrite:!1}),a=new $.Mesh(o,i);a.renderOrder=1,a.scale.y=-1,r.add(a);const s=new $.Mesh(o);s.visible=!1,r.add(s);const l=new $.OrthographicCamera(-P/2,P/2,M/2,-M/2,0,T);function c(e){s.visible=!0,O.uniforms.tDiffuse.value=t.texture,O.uniforms.h.value=1*e/256,s.material=O,D.setRenderTarget(n),D.render(s,l),N.uniforms.tDiffuse.value=n.texture,N.uniforms.v.value=1*e/256,s.material=N,D.setRenderTarget(t),D.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,r.add(l),{shadowGroup:r,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=_;const r=D.getClearAlpha();D.setClearAlpha(0),D.setRenderTarget(t),D.render(e,l),e.overrideMaterial=null,c(k),c(.4*k),D.setRenderTarget(null),D.setClearAlpha(r),e.background=n}}}(i)),y=!0)},threeParse:(e,n,r)=>t(this,void 0,void 0,(function*(){return null!=u&&d===r||(yield u,u=(()=>t(this,void 0,void 0,(function*(){var t,r;return x=(t=De).THREE,C=new t.RGBELoader,i.environment=I(n),function(e,t){const{THREE:n}=t;R=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder(t.MeshoptDecoder)}(Ge,De),r=e,R.parseAsync(r.buffer,"")})))(),d=r),u})),threeLoad:(e,t)=>{i.traverse((e=>{var t,n;e instanceof _e.Mesh&&(null===(t=e.geometry)||void 0===t||t.dispose(),Array.isArray(e.material)?e.material.forEach((e=>e.dispose())):null===(n=e.material)||void 0===n||n.dispose())})),i.clear(),i.add(e.scene);const n=(new _e.Box3).setFromObject(e.scene);l.position.y=n.min.y-Ue,i.add(l),c(),i.traverse((e=>{e instanceof _e.Mesh&&(e.material.depthWrite=!0)}));const r=n.min.clone().add(n.max).divideScalar(2),o=Math.sqrt(De.reduceVertices(e.scene,((e,t)=>Math.max(e,r.distanceToSquared(t))),0));s.reset(r,o,function(e,t){var n;const r={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?r.Glasses:null!==(n=r[e])&&void 0!==n?n:r.Glasses).normalize()}(t,_e.Vector3)),j=0},threePaused:()=>b,threeResume:()=>{b=!1,Ge.setAnimationLoop(Ke),e.style.visibility="visible",F=0,null==p||p.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset(),null==w||w.reset()},threePause:()=>{b=!0,function(){for(const{threePaused:e}of ze.values())if(!e())return!1;return!0}()&&Ge.setAnimationLoop(null),e.style.visibility="hidden",r.style.opacity="0",n.style.visibility="hidden"},threeSetToneMapping:(e,t)=>{const n={ACES:_e.ACESFilmicToneMapping,Linear:_e.LinearToneMapping,Neutral:_e.NeutralToneMapping};null!=n[e]&&(h=n[e]),A=t},threeIsInteractive:()=>S,threeSetInteractive:e=>{S=e,null==s||s.setInteractionEnabled(S)},threeSetOnInteracted:e=>{s.removeEventListener("change",f),f=e,s.addEventListener("change",e)},threeInitPromptAnimation:()=>{var e;e=s.getTheta(),p=te([{time:0,value:e,interpolation:Pe},{time:Re,value:e,interpolation:ke},{time:Re+xe/4,value:e+Ie,interpolation:Me},{time:Re+3*xe/4,value:e-Ie,interpolation:Te},{time:Re+xe,value:e,interpolation:Pe},{time:Re+2*xe,value:e,interpolation:Pe}]),m=null,g=null,v=te([{time:0,value:0,interpolation:Pe},{time:Re,value:1,interpolation:Pe},{time:Re+xe,value:0,interpolation:Pe},{time:Re+2*xe,value:0,interpolation:Pe}]),w=te([{time:0,value:0,interpolation:Pe},{time:Re,value:0,interpolation:ke},{time:Re+xe/4,value:-Ce,interpolation:Me},{time:Re+3*xe/4,value:Ce,interpolation:Te},{time:Re+xe,value:0,interpolation:Pe},{time:Re+2*xe,value:0,interpolation:Pe}])},threeInitThetaAnimation:e=>{p=e},threeInitPhiAnimation:e=>{m=e},threeInitFovAnimation:e=>{g=e},preRender_:e=>{if(!y||b)return;let t=0!==F?e-F:0;F=e,0===j?E=!0:j<$e&&(t=0),j++,L||(s.hasUserInteracted()?(L=!0,p=null,m=null,g=null,v=null,w=null):(null==p||p.update(t),null==m||m.update(t),null==g||g.update(t),null==v||v.update(t),null==w||w.update(t),null!=p&&(s.setTheta(p.get()),E=!0),null!=m&&(s.setPhi(m.get()),E=!0),null!=g&&(s.setFovRadians(g.get()),E=!0))),s.update()&&(E=!0)},shouldRender_:()=>!(!y||b)&&E,render_:()=>{const t=Ge.toneMapping,s=Ge.toneMappingExposure;Ge.toneMapping=h,Ge.toneMappingExposure=A,Ge.setViewport(0,0,e.width,e.height),Ge.render(i,a),Ge.toneMapping=t,Ge.toneMappingExposure=s,E=!1,null!=o&&(o.clearRect(0,0,e.width,e.height),Oe.width>0&&Oe.height>0&&o.drawImage(Oe,0,Fe-e.height,e.width,e.height,0,0,e.width,e.height),n.style.visibility=S&&!L?"visible":"hidden",null!=v&&(r.style.opacity=`${v.get()}`),null!=w&&(r.style.transform=`translateX(${w.get()*Math.min(W,q)}px)`))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===W&&n===q&&We===G||(e.width=Math.ceil(t*We*qe),e.height=Math.ceil(n*We*qe),W=t,q=n,G=We,E=!0)},target_:e};return ze.set(e,z),z}function Ve(){if(Ne)return;De=window.ShopAR__THREE,_e=De.THREE,Oe=document.createElement("canvas");var e,t;Oe.style.position="block",Ge=new _e.WebGLRenderer({powerPreference:"high-performance",canvas:Oe,antialias:!0,alpha:!0}),Ge.outputColorSpace=_e.SRGBColorSpace,Ge.toneMapping=_e.ACESFilmicToneMapping,Ge.setClearColor(new _e.Color(16777215),0),e=Ge,t=De,j||($=t.THREE,D=e,_=new $.MeshDepthMaterial,_.userData.darkness={value:L},_.onBeforeCompile=e=>{e.uniforms.darkness=_.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},_.depthTest=!1,_.depthWrite=!1,O=new $.ShaderMaterial(t.HorizontalBlurShader),O.depthTest=!1,N=new $.ShaderMaterial(t.VerticalBlurShader),N.depthTest=!1,j=!0),Be(),Ne=!0}function Ke(e){Be(),Ge.clear();for(const{preRender_:t,shouldRender_:n,render_:r}of ze.values())t(e),n()&&r()}function Be(){let e=0,t=0;for(const{target_:n}of ze.values()){const{clientWidth:r,clientHeight:o}=n;e=Math.max(e,r),t=Math.max(t,o)}const n=S();e=Math.ceil(e*n*qe),t=Math.ceil(t*n*qe),e===je&&t===Fe&&n===We||(je=e,Fe=t,We=n,Ge.setSize(je,Fe,!1));for(const{updateSize_:e}of ze.values())e()}const He={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},Xe=Object.keys(He);function Ze(e){return He[e]}const Ye="shopar-error";function Je(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const r=document.createElementNS("http://www.w3.org/2000/svg","image");r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),r.setAttribute("width",e),r.setAttribute("height",e),n.appendChild(r)}return n}function et(e,t,n,r){const o=document.createElement("button");o.id=e,o.type="button",o.className="shopar-btn";{const e=Je("1.75rem",r);o.appendChild(e)}{const e=document.createElement("span");e.textContent=t,o.appendChild(e)}o.ariaLabel=n;return o.style.display="none",o}const tt="shopar-control";const nt="shopar-deepar-output";function rt(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",t}function ot(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function it(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function at(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const st="shopar-main";const lt="shopar-qr-output";const ct="shopar-three-output";var ut;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(ut||(ut={}));let dt=!1;function ht(){dt||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),dt=!0)}function ft(){ht();const e=function(){const e=document.createElement("div");e.id=st;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),t=function(){const e=document.createElement("div");return e.style.textAlign="center",e}(),n=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),r=function(e,t){const n=document.createElement("div");n.id=lt;const r=n.style;r.position="absolute",r.top="0",r.left="0",r.width="100%",r.height="100%",r.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),o.appendChild(e);const a=document.createElement("div");return a.appendChild(t),o.appendChild(a),n}(t,n);e.appendChild(r);const o=function(){const e=document.createElement("div");e.id=nt;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",e}();e.appendChild(o);const i=function(){const e=document.createElement("canvas");e.id=ct,e.className="shopar-3d";const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",e}();e.appendChild(i);const a=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),s=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),l=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:r}=n;return r.position="absolute",r.width="100%",r.height="100%",r.pointerEvents="none",r.opacity="0",n.appendChild(e),n.appendChild(t),n}(a,s);e.appendChild(l);const c=function(){const e=Je("2rem",`${b}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),u=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",n.pointerEvents="none",t.appendChild(e),t}(c);e.appendChild(u);const d=rt("shopar-ar-loading-container"),h=ot("shopar-ar-loading-text",Ze("loading.ar"));d.appendChild(h);const f=it("shopar-ar-loading-bar-bg"),p=at("shopar-ar-loading-bar-fg");f.appendChild(p),d.appendChild(f),e.appendChild(d);const m=rt("shopar-3d-loading-container"),g=ot("shopar-3d-loading-text",Ze("loading.3d"));m.appendChild(g);const v=it("shopar-3d-loading-bar-bg"),w=at("shopar-3d-loading-bar-fg");v.appendChild(w),m.appendChild(v),e.appendChild(m);const y=function(){const e=document.createElement("div"),{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",e}(),E=function(){const e=new Image,{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.objectFit="contain",t.pointerEvents="none",e}();y.appendChild(E),e.appendChild(y);const A=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),S=function(e){const t=document.createElement("div");t.id=Ye;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const r=document.createElement("div"),o=r.style;return o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",t.appendChild(r),r.appendChild(e),t}(A);e.appendChild(S);const R=function(){const e=document.createElement("div");return e.id=tt,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(R);const x=et("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");R.appendChild(x);const C=et("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${b}/img/icons/cube.svg`);R.appendChild(C);const I=et("shopar-btn-close","Close","Close ShopAR view",`${b}/img/icons/close.svg`);R.append(I);let P,M=ut.None,T=!1,k=!1,L=!1,U=!1;function $(){p.classList.remove("active"),d.style.visibility="hidden"}function D(){y.style.visibility="hidden",w.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return r},getQRImage:function(){return n},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return l},getThreeTarget:function(){return i},getThreePrompt:function(){return u},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){A.textContent=null!=e?e:"Please reload page and allow camera access to continue"},customizeQRPrompt:function(e){t.textContent=null!=e?e:"Scan on mobile or tablet to try on"},setVisibilityParameters:function(e,t,n,r,o){var i;T=e,k=t,L=n,U=r,P=o,pt(R,T),pt(x,T&&(L||k)&&M===ut.None),pt(C,T&&U&&M===ut.None),pt(I,T&&M!==ut.None),$(),D(),T||""===(i=S).style.display&&pt(i,!1)},getUIState:function(){return M},setUIState:function(e){M=e,M===ut.None?($(),D(),T&&(pt(S,!1),pt(I,!1),(k||L)&&pt(x,!0),U&&pt(C,!0))):M!==ut.QR&&M!==ut.AR&&M!==ut.Preview||T&&(pt(S,!1),pt(x,!1),pt(C,!1),pt(I,!0))},setDefaultUIActions:function(e,t,n){T&&((k||L)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,r=`${b}/img/icons/${n}`;x.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r)}(P),x.onclick=e),U&&(C.onclick=t),I.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:$,startThreeLoading:function(){null!=E.dataset.srcSet?y.style.visibility="visible":(w.classList.add("active"),m.style.visibility="visible")},stopThreeLoading:D,setThreePosterUrl:function(e){null!=e?(E.src=e,E.dataset.srcSet="true"):delete E.dataset.srcSet},showCameraError:function(){T&&pt(S,!0)}}}function pt(e,t){e.style.display=t?"":"none"}const mt=new Map;function gt(e){let n=mt.get(e);return null==n?(n=function(){let e=0,n=null,r=null,o=null;const i=()=>(null==n&&(n=ft()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==r){const{getQRTarget:e,getQRImage:n}=i();r=function(e,n){let r=!0;return{qrPaused:()=>r,qrDraw:(o,i)=>t(this,void 0,void 0,(function*(){yield A;const t=`https://ar.shopar.ai/${w.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:o,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(t),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,r=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){r=!0,e.style.display="none"}))}}(e(),n())}return r},findThree:()=>{if(null==o){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();o=Qe(e(),t(),n())}return o}}}(),mt.set(e,n)):n.incrementSetupId_(),n}function vt(e){for(const t of mt.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:r,setUIState:o}=n;r()===ut.AR&&o(ut.None)}}let wt;const yt=new Uint8Array(16);function bt(){if(!wt&&(wt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!wt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return wt(yt)}const Et=[];for(let e=0;e<256;++e)Et.push((e+256).toString(16).slice(1));var At={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function St(e,t,n){if(At.randomUUID&&!t&&!e)return At.randomUUID();const r=(e=e||{}).random||(e.rng||bt)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return Et[e[t+0]]+Et[e[t+1]]+Et[e[t+2]]+Et[e[t+3]]+"-"+Et[e[t+4]]+Et[e[t+5]]+"-"+Et[e[t+6]]+Et[e[t+7]]+"-"+Et[e[t+8]]+Et[e[t+9]]+"-"+Et[e[t+10]]+Et[e[t+11]]+Et[e[t+12]]+Et[e[t+13]]+Et[e[t+14]]+Et[e[t+15]]}(r)}const Rt="qrLaunch",xt="arLaunch",Ct="previewLaunch",It="heartbeat";let Pt,Mt,Tt=!1,kt=window.navigator.userAgent||"no user agent";const Lt=[];function Ut(){null==Pt&&(Mt=St(),Pt=E(`${b}/shopar-analytics.js`),Pt.then((()=>{Tt=!0,window.ShopAR__analytics.initializeImpl(),Lt.forEach((e=>e()))})))}function $t(e){Tt?e():Lt.push(e)}function Dt(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function _t(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const Ot=200,Nt=10;let jt=!1,Ft=null,Wt=[],qt=[];function Gt(e){return t(this,void 0,void 0,(function*(){jt=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${b}/wasm/mediapipe`,e),Ft&&clearInterval(Ft);const r=[],o=[];Ft=setInterval((()=>t(this,void 0,void 0,(function*(){if(jt)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());jt||(null!=a&&null!=s&&function(e){for(let t of Wt)t(e)}({translation:a,rotation:s}),null==e&&(r.push(t),o.push(i),r.length<Nt||(r.shift(),o.shift(),function(e,t){for(let n of qt)n({faceWidth:e,IPD:t})}(Qt(r),Qt(o)))))}))),Ot)}))}function zt(){qt=[],Wt=[],jt=!0}function Qt(e){let t=0;const n=e.length;for(let r=0;r<n;r++)t+=e[r];return t/n}function Vt(e){return t(this,void 0,void 0,(function*(){const r=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield r.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}var Kt="undefined"!=typeof Float32Array?Float32Array:Array;function Bt(){var e=new Kt(16);return Kt!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Ht(e,t,n){var r=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],u=t[7],d=t[8],h=t[9],f=t[10],p=t[11],m=t[12],g=t[13],v=t[14],w=t[15],y=n[0],b=n[1],E=n[2],A=n[3];return e[0]=y*r+b*s+E*d+A*m,e[1]=y*o+b*l+E*h+A*g,e[2]=y*i+b*c+E*f+A*v,e[3]=y*a+b*u+E*p+A*w,y=n[4],b=n[5],E=n[6],A=n[7],e[4]=y*r+b*s+E*d+A*m,e[5]=y*o+b*l+E*h+A*g,e[6]=y*i+b*c+E*f+A*v,e[7]=y*a+b*u+E*p+A*w,y=n[8],b=n[9],E=n[10],A=n[11],e[8]=y*r+b*s+E*d+A*m,e[9]=y*o+b*l+E*h+A*g,e[10]=y*i+b*c+E*f+A*v,e[11]=y*a+b*u+E*p+A*w,y=n[12],b=n[13],E=n[14],A=n[15],e[12]=y*r+b*s+E*d+A*m,e[13]=y*o+b*l+E*h+A*g,e[14]=y*i+b*c+E*f+A*v,e[15]=y*a+b*u+E*p+A*w,e}function Xt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Zt(e,t){var n=t[0],r=t[1],o=t[2],i=t[4],a=t[5],s=t[6],l=t[8],c=t[9],u=t[10];return e[0]=Math.hypot(n,r,o),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(l,c,u),e}function Yt(e,t,n,r){var o=t[0],i=t[1],a=t[2],s=t[3],l=o+o,c=i+i,u=a+a,d=o*l,h=o*c,f=o*u,p=i*c,m=i*u,g=a*u,v=s*l,w=s*c,y=s*u,b=r[0],E=r[1],A=r[2];return e[0]=(1-(p+g))*b,e[1]=(h+y)*b,e[2]=(f-w)*b,e[3]=0,e[4]=(h-y)*E,e[5]=(1-(d+g))*E,e[6]=(m+v)*E,e[7]=0,e[8]=(f+w)*A,e[9]=(m-v)*A,e[10]=(1-(d+p))*A,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Jt(){var e=new Kt(3);return Kt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function en(e,t,n){var r=new Kt(3);return r[0]=e,r[1]=t,r[2]=n,r}function tn(e,t){var n=t[0]-e[0],r=t[1]-e[1],o=t[2]-e[2];return Math.hypot(n,r,o)}function nn(e,t,n){var r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*r+n[4]*o+n[8]*i+n[12])/a,e[1]=(n[1]*r+n[5]*o+n[9]*i+n[13])/a,e[2]=(n[2]*r+n[6]*o+n[10]*i+n[14])/a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function rn(){var e=new Kt(4);return Kt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Jt(),function(){var e,t=(e=new Kt(4),Kt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var on;let an,sn,ln;Jt(),en(1,0,0),en(0,1,0),rn(),rn(),on=new Kt(9),Kt!=Float32Array&&(on[1]=0,on[2]=0,on[3]=0,on[5]=0,on[6]=0,on[7]=0),on[0]=1,on[4]=1,on[8]=1;let cn,un,dn,hn,fn=!0,pn=null;const mn=new Set;let gn,vn,wn,yn,bn,En;function An(){null==an&&(an=E(`${b}/shopar-deepar.js`))}function Sn(){null==sn&&(sn=E(`${b}/shopar-true-scale.js`))}function Rn(e){return t(this,void 0,void 0,(function*(){const{licenseKey:r,truescaleUsecase:o}=e;return bn=o,null==gn&&(gn=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(e=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))throw new n("No camera available!");var e;const t=Ln(dn),o=Dt(t);cn=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:r||"your_license_key_goes_here",previewElement:hn,additionalOptions:{hint:En,cameraConfig:{disableDefaultCamera:!0}}}),un=yield _t(o),yield Un(cn,un,"user"===t),"Glasses"===dn&&(yield sn,Gt(un),"DetectionLoop"!==bn&&On((e=>{yn=e.faceWidth})))})))()),gn}))}function xn(e,t){var n,r;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===dn&&(n=t,r=En,n===r||null!=n&&null!=r&&n.length===r.length&&n.every((e=>r.find((t=>e===t))))&&r.every((e=>n.find((t=>t===e))))))||(null!=cn&&(cn.shutdown(),cn=null,gn=null),dn=e,En=t)}function Cn(e){e!==hn&&(hn=e,null!=cn&&cn.changePreviewElement(hn))}function In(e){pn=e}function Pn(e){cn.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(yn){const e=137/(yn+5);cn.changeParameterVector("GLASSES","","scale",e,e,e,0),cn.changeParameterVector("shopar_glasses","","scale",e,e,e,0),function(e){const t=[-8.362421,4.549,-9.275],n=[8.362421,4.549,-9.275];try{const r=Dn("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),o=Dn("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);cn.changeParameterVector("temple_left","","rotation",0,56.6*-r,0,0),cn.changeParameterVector("temple_right","","rotation",0,56.6*-o,0,0)}catch(e){return}}(e),zt(),yn=null}e(),$n("Glasses")}},cn.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),$n("Shoes"))},cn.callbacks.onWristTracked=t=>{t.detected&&(e(),$n("Watches"))}}function Mn(e,n){return t(this,void 0,void 0,(function*(){return null!=vn&&wn===n||(yield vn,vn=cn.switchEffect(e),wn=n),vn}))}function Tn(){return t(this,void 0,void 0,(function*(){if(null!=cn){if(fn=!1,null==un){const e=Ln(dn),t=Dt(e);un=yield _t(t),yield Un(cn,un,"user"===e),"Glasses"===dn&&(Gt(un),"DetectionLoop"!==bn&&On((e=>{yn=e.faceWidth})))}!function(){if(null==pn)return;if(null==dn||mn.has(dn))return;pn.style.visibility="visible",pn.style.opacity="1"}(),cn.setPaused(fn),hn.style.display=""}}))}function kn(){null!=cn&&(fn=!0,cn.setPaused(fn),zt(),null!=un&&null!=un.srcObject&&un.srcObject instanceof MediaStream&&(un.srcObject.getTracks().forEach((e=>e.stop())),un=null),function(){if(null==pn)return;pn.style.visibility="hidden",pn.style.opacity="0"}(),cn.stopCamera(),hn.style.display="none")}function Ln(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Un(e,n,r){return t(this,void 0,void 0,(function*(){yield new Promise((o=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,r),o()}))))}}))}))}function $n(e){null!=pn&&(mn.has(e)||(mn.add(e),pn.style.opacity="0"))}function Dn(e,t,n,r,o,i,a){const s=cn.getTransformationBetween(e,t),l=Xt(Jt(),s),c=function(e,t){var n=new Kt(3);Zt(n,t);var r=1/n[0],o=1/n[1],i=1/n[2],a=t[0]*r,s=t[1]*o,l=t[2]*i,c=t[4]*r,u=t[5]*o,d=t[6]*i,h=t[8]*r,f=t[9]*o,p=t[10]*i,m=a+u+p,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(d-f)/g,e[1]=(h-l)/g,e[2]=(s-c)/g):a>u&&a>p?(g=2*Math.sqrt(1+a-u-p),e[3]=(d-f)/g,e[0]=.25*g,e[1]=(s+c)/g,e[2]=(h+l)/g):u>p?(g=2*Math.sqrt(1+u-a-p),e[3]=(h-l)/g,e[0]=(s+c)/g,e[1]=.25*g,e[2]=(d+f)/g):(g=2*Math.sqrt(1+p-a-u),e[3]=(s-c)/g,e[0]=(h+l)/g,e[1]=(d+f)/g,e[2]=.25*g),e}(rn(),s);Yt(s,c,l,en(a,a,a));const u=cn.getTransformationBetween(t,n),d=Xt(Jt(),u);Yt(u,rn(),d,Zt(Jt(),u));const h=Ht(Bt(),s,u),f=Xt(Jt(),h),p=Math.atan2(i[0]-f[0],Math.abs(i[2]-f[2]));let m;try{m=cn.getTransformationBetween(n,r)}catch(e){return p}const g=Ht(Bt(),u,m),v=Ht(Bt(),s,g),w=en(f[0],i[1],i[2]),y=nn(Jt(),w,function(e,t){var n=t[0],r=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],u=t[8],d=t[9],h=t[10],f=t[11],p=t[12],m=t[13],g=t[14],v=t[15],w=n*s-r*a,y=n*l-o*a,b=n*c-i*a,E=r*l-o*s,A=r*c-i*s,S=o*c-i*l,R=u*m-d*p,x=u*g-h*p,C=u*v-f*p,I=d*g-h*m,P=d*v-f*m,M=h*v-f*g,T=w*M-y*P+b*I+E*C-A*x+S*R;return T?(T=1/T,e[0]=(s*M-l*P+c*I)*T,e[1]=(o*P-r*M-i*I)*T,e[2]=(m*S-g*A+v*E)*T,e[3]=(h*A-d*S-f*E)*T,e[4]=(l*C-a*M-c*x)*T,e[5]=(n*M-o*C+i*x)*T,e[6]=(g*b-p*S-v*y)*T,e[7]=(u*S-h*b+f*y)*T,e[8]=(a*P-s*C+c*R)*T,e[9]=(r*C-n*P-i*R)*T,e[10]=(p*A-m*b+v*w)*T,e[11]=(d*b-u*A-f*w)*T,e[12]=(s*x-a*I-l*R)*T,e[13]=(n*I-r*x+o*R)*T,e[14]=(m*y-p*E-g*w)*T,e[15]=(u*E-d*y+h*w)*T,e):null}(Bt(),v));let b=cn.getClosestPointOnMesh(r,y);try{const e=cn.getClosestPointOnMesh(o,y);tn(y,e)<tn(y,b)&&(b=e)}catch(e){}const E=nn(Jt(),b,g);return p-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function _n(e){!function(e){Wt.push(e)}(e)}function On(e){!function(e){qt.push(e)}(e)}var Nn;function jn(){return[Nn.Android,Nn.iOS,Nn.Tablet].includes(function(){if("undefined"!=typeof window&&window.navigator){const e=window.navigator.userAgent,t=window.navigator.platform||"",n=["Macintosh","MacIntel","MacPPC","Mac68K"],r=["Win32","Win64","Windows","WinCE"],o=["iPhone","iPod","iPad"];return"ontouchstart"in window||navigator.maxTouchPoints>0?Nn.Tablet:-1!==o.indexOf(t)?Nn.iOS:-1!==n.indexOf(t)?Nn.MacOS:-1!==r.indexOf(t)?Nn.Windows:/Android/.test(e)?Nn.Android:/Linux/.test(t)?Nn.Linux:Nn.Unknown}return Nn.Unknown}())}function Fn(e,o,i){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const d=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${d+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],g=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield m(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),v=new r[0](yield(yield g.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=v.byteLength;if(u[c]=Math.min(76,o)*((a>>5)-1),152===u[c]&&(u[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)u[c]^=u[i]<<13,u[c]^=u[i]>>17,u[c]^=u[i]<<5,v[e]=v[e]^u[c];return i^=u[0],i^=u[1],i^=u[2],v}))}function Wn(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function qn(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}function Gn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}!function(e){e[e.Unknown=0]="Unknown",e[e.Android=1]="Android",e[e.iOS=2]="iOS",e[e.Tablet=3]="Tablet",e[e.MacOS=4]="MacOS",e[e.Windows=5]="Windows",e[e.Linux=6]="Linux"}(Nn||(Nn={}));const zn=["AR","3D"];function Qn(e){const{apiKey:t,sku:r,targetElement:o,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;Wn(t,"apiKey"),Gn(t,"apiKey"),Wn(r,"sku"),Gn(r,"sku"),Wn(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,t,r){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!r.includes(e))throw new n(`'${t}' must be ${r.join("' or '")}.`)}(i,"initialState",zn),null!=a&&function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new n(`'${t}' must be a string or array.`)}(a,"initialAnimation"),null!=s&&Gn(s,"baseUrl"),null!=l&&qn(l,"defaultUI"),null!=c&&qn(c,"interactive"),null!=u&&function(e,t,r){for(const o of r){const r=e[o];if(null!=r&&"string"!=typeof r)throw new n(`Value for key '${o}' in '${t}' must be a string.`)}}(u,"strings",Xe)}let Vn=!1;function Kn(e){return t(this,void 0,void 0,(function*(){const{targetElement:r}=e;b.update(e.baseUrl),Ut();const{trackEvent:o}=function(e){const t=performance.now(),n=St();return{trackEvent:(r,o={})=>{o=Object.assign(Object.assign({},o),{pluginVersion:w,userAgent:kt,sessionId:Mt,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),$t((()=>{window.ShopAR__analytics.trackEventImpl(r,o)}))}}}(e.apiKey);o("visionSetup");const i=yield function(e){return t(this,void 0,void 0,(function*(){const r=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:e,sid:d()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield r.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(e.apiKey);o("visionApiResponse",i);const{arKey:a}=i,s=gt(r),{getSetupId:l,findUI:c}=s,u=l();An(),Sn();const{setTargetElement:h,getDeepARTarget:f,setVisibilityParameters:m,getUIState:g,setUIState:v,startDeepARLoading:y,stopDeepARLoading:E,showCameraError:A}=c();if(g()!=ut.None)throw Error("UI state is not None, this is weird..");v(ut.AR),h(r),m(!1,!1,!0,!1,void 0),y(),yield an,Bn(l(),u);try{o("visionArLaunch"),kn(),xn("Glasses",["faceInit"]),Cn(f()),yield Rn({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Bn(l(),u),yield Tn(),Bn(l(),u)}catch(e){const t=e instanceof Error;throw o("visionArLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),A(),kn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{E()}return Vn=!0,{registerFacePoseListener:e=>{Vn&&(o("registerFacePoseListener"),_n(e))},registerFaceMeasurementListener:e=>{Vn&&(o("registerFaceMeasurementListener"),On(e))},switchEffect:e=>t(this,void 0,void 0,(function*(){Vn&&(o("switchEffect",{arUrl:e}),function(e){cn.switchEffect(e)}(e))})),clearEffect:()=>{Vn&&(o("clearEffect"),cn.clearEffect())},close:()=>{if(Vn){if(Vn=!1,o("visionClose"),g()!==ut.AR)throw new n("AR not launched.");kn(),v(ut.None)}}}}))}function Bn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}function Hn(e){var r,o;return t(this,void 0,void 0,(function*(){Qn(e);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),b.update(e.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(He,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(He[t]=n)}}(e.strings);const u=null!=c?we(c):null,h=null!=(null==u?void 0:u.theta)?te(u.theta):null,f=null!=(null==u?void 0:u.phi)?te(u.phi):null,y=null!=(null==u?void 0:u.fov)?te(u.fov):null,S=function(e,r,o,i,a){return t(this,void 0,void 0,(function*(){const s=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams(Object.assign(Object.assign(Object.assign({apiKey:e,sku:r,sid:d()},null!=o&&{theta:`${m(o)}`}),null!=i&&{phi:`${m(i)}`}),null!=a&&{fov:`${m(a)}`}))}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield s.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a,null==h?void 0:h.get(),null==f?void 0:f.get(),null==y?void 0:y.get()),R=gt(s),{getSetupId:x,findUI:C,findQR:I,findThree:P}=R,M=x();Ut();const{trackEvent:T,arInteracted:k,previewInteracted:L}=function(e,t){const n=performance.now(),r=St();let o=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(o=i+a,c=!1,u(It,{engagementTotal:o,engagementAR:i,engagement3D:a}))}),1e3);const u=(o,i={})=>{i=Object.assign(Object.assign({},i),{userAgent:kt,pluginVersion:w,sessionId:Mt,setupId:r,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),$t((()=>{window.ShopAR__analytics.trackEventImpl(o,i)}))};return{trackEvent:u,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}(a,i);T("setup",{hostname:window.location.hostname});const U=yield S;T("apiResponse",U);const{category:$,arUrl:D,arKey:_,arPromptEnabled:O,arPromptText:N,arPromptImage:j,previewUrl:F,previewEnvUrl:W,previewToneMapping:q,previewToneMappingExposure:G,previewPosterUrl:z,cameraErrorText:Q,qrPromptText:V}=U;Xn(x(),M);const K=null!=D&&function(e){return null!=e&&g.includes(e)}($),B=null==(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled)||(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled),H=K&&function(e){return null!=e&&v.includes(e)}($),X=B&&H&&!jn(),Z=K&&!X,Y=null!=F;if(Xn(x(),M),X&&function(){t(this,void 0,void 0,(function*(){null==A&&(A=E(`${b}/shopar-qr.js`))}))}(),Z&&(An(),function(e){e!==ln&&(ln=e,Vt(e),vn=null,zt())}(D),"Glasses"===$&&Sn()),Y){null==Le&&(Le=E(`${b}/shopar-three.js`));const e=255;Fn(F,(new Date).getTime()+e,Math.random()*e),Vt(null!=W?W:`${b}/env/default.hdr`)}const{setTargetElement:J,getDeepARTarget:ee,getDeepARPrompt:ne,customizeDeepARPrompt:re,customizeCameraError:oe,customizeQRPrompt:ie,setVisibilityParameters:ae,getUIState:se,setUIState:le,setDefaultUIActions:ce,startDeepARLoading:ue,stopDeepARLoading:de,startThreeLoading:he,stopThreeLoading:fe,setThreePosterUrl:pe,showCameraError:me}=C();J(s);ae(null==e.defaultUI||e.defaultUI,X,Z,Y,$),re(null!=N?N:"",null!=j?j:""),oe(Q),ie(V),pe(z),function(e,t){const r=e.parentNode;if(null==r)throw new n("Parent node missing.");new MutationObserver((n=>{for(const r of n)for(const n of r.removedNodes)if(n===e)return void t()})).observe(r,{childList:!0})}(s,(()=>{se()!==ut.QR||ge()||ye(),se()!==ut.AR||fn||kn(),se()!==ut.Preview||Se()||xe(),le(ut.None)}));const{qrPaused:ge,qrDraw:ve,qrPause:ye}=I(),{threeInit:be,threeParse:Ee,threeLoad:Ae,threePaused:Se,threeResume:Re,threePause:xe,threeSetToneMapping:Ce,threeIsInteractive:Ie,threeSetInteractive:Pe,threeSetOnInteracted:Me,threeInitPromptAnimation:Te,threeInitThetaAnimation:ke,threeInitPhiAnimation:Ue,threeInitFovAnimation:$e}=P(),De=null==e.interactive||e.interactive;Pe(De);let _e=0;if(se()===ut.QR){if(!ge())if(X){T(Rt);try{yield ve(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ye(),le(ut.None)}else if(se()===ut.AR){if(!fn)if(Z&&!Vn){T(xt);const e=yield Vt(D);Xn(x(),M),vt(R),xn($),Cn(ee()),In(O?ne():null),yield Mn(e,D),Pn(k),Xn(x(),M)}else kn(),le(ut.None)}else if(se()===ut.Preview&&!Se())if(Y){T(Ct),he();const e=255,t=yield Fn(F,(new Date).getTime()+e,Math.random()*e);Xn(x(),M);const n=yield Vt(null!=W?W:`${b}/env/default.hdr`);Xn(x(),M);const r=yield Ee(t,n,`${F}${W}`);Xn(x(),M),Ae(r,$),Ce(null!=q?q:"ACES",null!=G?G:1),Me(L),Te(),null!=u&&(ke(h),Ue(f),$e(y)),fe()}else xe(),le(ut.None);const Oe=()=>t(this,void 0,void 0,(function*(){if(X){if(se()===ut.QR||se()===ut.AR)throw new n("AR already launched.");try{T(Rt);const e=++_e;if(se()===ut.Preview&&Y&&!Se()&&xe(),le(ut.QR),yield ve(i,a),_e!==e)return;return void Xn(x(),M)}catch(e){const t=e instanceof Error;throw T("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!Z)throw new n("Model does not have AR enabled.");if(se()===ut.AR)throw new n("AR already launched.");try{T(xt);const e=++_e;se()===ut.Preview&&Y&&!Se()&&xe(),vt(R),le(ut.AR),ue();const t=yield Vt(D);if(_e!==e)return;if(Xn(x(),M),yield an,_e!==e)return;if(Xn(x(),M),kn(),xn($),Cn(ee()),In(O?ne():null),yield Rn({licenseKey:_}),_e!==e)return;if(Xn(x(),M),yield Mn(t,D),Pn(k),_e!==e)return;if(Xn(x(),M),yield Tn(),_e!==e)return;Xn(x(),M)}catch(e){const t=e instanceof Error;throw T("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),me(),kn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{de()}})),Ne=()=>t(this,void 0,void 0,(function*(){if(!Y)throw new n("Model does not have 3D enabled.");if(se()===ut.Preview)throw new n("3D already launched.");try{T(Ct);const e=++_e;se()===ut.AR&&(Z&&!fn&&kn(),ye()),le(ut.Preview),he();const t=255,n=yield Fn(F,(new Date).getTime()+t,Math.random()*t);if(_e!==e)return;Xn(x(),M);const r=yield Vt(null!=W?W:`${b}/env/default.hdr`);if(_e!==e)return;if(Xn(x(),M),yield Le,_e!==e)return;if(Xn(x(),M),be(),_e!==e)return;Xn(x(),M);const o=yield Ee(n,r,`${F}${W}`);if(_e!==e)return;Xn(x(),M),Ae(o,$),Ce(null!=q?q:"ACES",null!=G?G:1),Me(L),Te(),null!=u&&(ke(h),Ue(f),$e(y)),Re()}catch(e){const t=e instanceof Error;throw T("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{fe()}})),je=()=>t(this,void 0,void 0,(function*(){if(se()===ut.None)throw new n("Neither AR or 3D launched.");++_e,se()===ut.QR||se()===ut.AR?(Z&&!fn&&kn(),ye()):se()===ut.Preview&&Y&&!Se()&&xe(),le(ut.None)}));return ce(Oe,Ne,je),"AR"===l?(yield Oe(),Xn(x(),M)):"3D"===l&&(yield Ne(),Xn(x(),M)),Vn=!1,{launchAR:K?Oe:void 0,launch3D:Y?Ne:void 0,closeAR:K?()=>t(this,void 0,void 0,(function*(){if(se()!==ut.AR&&se()!==ut.QR)throw new n("AR not launched.");++_e,Z&&!fn&&kn(),ye(),le(ut.None)})):void 0,close3D:Y?()=>t(this,void 0,void 0,(function*(){if(se()!==ut.Preview)throw new n("3D not launched.");++_e,Y&&!Se()&&xe(),le(ut.None)})):void 0,close:K||Y?je:void 0,isInteractive:()=>Ie(),setInteractive:e=>Pe(e)}}))}function Xn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const Zn={setup:function(e){return t(this,void 0,void 0,(function*(){return Kn(e)}))}},Yn={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,r){return t(this,void 0,void 0,(function*(){try{return r()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Hn(e)))}))},version:w};e.plugin=Yn,e.vision=Zn}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).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}.shopar-ar-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#1e293bb2;transition:.3s ease-in-out opacity}.shopar-ar-prompt-text{text-align:center;color:#fff}.shopar-ar-prompt-img{max-width:80%;max-height:50%;object-fit:contain}.shopar-3d{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 r=[Uint8Array,Uint32Array],o=r.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[i[a[a[o]]]][i[a[a[a.length-1]]]],l=s.charCodeAt(o),c=l^l,u=new r[1]([c]);function d(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],f=h.length;function p(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=f)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),p(e,n+1)}}))}function m(e){return Math.round(100*e)/100}const g=["Glasses","Shoes","Watches"],v=["Shoes"];const w="0.4.0";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${w}/dist`;const b={update:e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>y};function E(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let A;const S=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let R,x,C;function I(e){const t=function(e){const t=new x.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,x.ClampToEdgeWrapping,x.ClampToEdgeWrapping,x.LinearFilter,x.LinearFilter,1,x.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=x.EquirectangularReflectionMapping,t.colorSpace=x.LinearSRGBColorSpace,t}const P=45,M=45,T=3,k=1.5,L=1,U=.5;let $,D,_,O,N,j=!1;const F=4,W=.001,q=1e-7,G=10,z=11,Q=1/(z-1),V="function"==typeof Float32Array;function K(e,t,n,r){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===r)return J;const o=V?new Float32Array(z):new Array(z);for(let t=0;t<z;++t)o[t]=Z(t*Q,e,n);function i(t){let r=0,i=1;const a=z-1;for(;i!==a&&o[i]<=t;++i)r+=Q;--i;const s=r+(t-o[i])/(o[i+1]-o[i])*Q,l=Y(s,e,n);return l>=W?function(e,t,n,r){for(let o=0;o<F;++o){const o=Y(t,n,r);if(0===o)return t;t-=(Z(t,n,r)-e)/o}return t}(t,s,e,n):0===l?s:function(e,t,n,r,o){let i,a,s=0;do{a=t+(n-t)/2,i=Z(a,r,o)-e,i>0?n=a:t=a}while(Math.abs(i)>q&&++s<G);return a}(t,r,r+Q,e,n)}return function(e){return 0===e||1===e?e:Z(i(e),t,r)}}function B(e,t){return 1-3*t+3*e}function H(e,t){return 3*t-6*e}function X(e){return 3*e}function Z(e,t,n){return((B(t,n)*e+H(t,n))*e+X(t))*e}function Y(e,t,n){return 3*B(t,n)*e*e+2*H(t,n)*e+X(t)}function J(e){return e}function ee(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=K(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function te(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort(((e,t)=>e.time-t.time)).map((({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:ee(n)})));let r=0,o=n[0].value;return{reset:()=>{r=0},update:e=>{for(r+=e;r>=t;)r-=t;for(let e=0;e<n.length-1;e++){const t=n[e],i=n[e+1];if(r>=t.time&&r<i.time){const e=t.interpolate((r-t.time)/(i.time-t.time));o=t.value+e*(i.value-t.value)}}},get:()=>o}}const ne="#",re="time",oe="interpolation",ie="yaw",ae="pitch",se="fov",le=[re,ie,ae,se,oe],ce="s",ue="ms",de=1e3,he="deg",fe="rad",pe=Math.PI/180,me="ease-in-out",ge="cubic-bezier(",ve=")";function we(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map((e=>function(e){const t=e.indexOf(ne);return(-1!==t?e.substring(0,t):e).trim()}(e))).filter((e=>""!==e))}(e);if(null==t)throw new Error("Header missing.");const r=function(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(!le.includes(r))throw new Error(`Invalid token in header: '${r}'.`);if(t.includes(r))throw new Error(`Duplicate token in header: '${r}'.`);t.push(r)}if(!t.includes(re))throw new Error(`Missing required token: '${re}'.`);return t}(t.split(/\s+/)),o={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:i}=ye(r,e);null!=t&&(null==o.theta&&(o.theta=[]),o.theta.push(t)),null!=n&&(null==o.phi&&(o.phi=[]),o.phi.push(n)),null!=i&&(null==o.fov&&(o.fov=[]),o.fov.push(i))}if(0===Object.values(o).length)throw new Error("At least one parameter should be animated.");return o}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const r of e){const{time:e,pitch:o,yaw:i,fov:a}=r;if(null==e)throw new Error("Time missing.");const s=Ee(null!==(t=r.interpolation)&&void 0!==t?t:me);null!=i&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:i*pe,interpolation:s})),null!=o&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:o*pe,interpolation:s})),null!=a&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:a*pe,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every((t=>t.length!==e.length)))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function ye(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter((e=>!(null==n?void 0:n.includes(e)))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter((t=>!e.includes(t))).join(", ")}'.`);const r=e.indexOf(re),o=function(e){if(e.endsWith(ue))return Se(e.substring(0,e.length-ue.length));if(e.endsWith(ce))return Se(e.substring(0,e.length-ce.length))*de;return Se(e)}(n[r]),i=e.indexOf(oe),a=Ee(-1===i?me:n[i]),s={};for(let t=0;t<n.length;t++){if(t===r||t===i)continue;const l=e[t],c=n[t];switch(l){case ie:s.theta={time:o,value:be(c),interpolation:a};break;case ae:s.phi={time:o,value:be(c),interpolation:a};break;case se:s.fov={time:o,value:be(c),interpolation:a};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function be(e){return e.endsWith(he)?Se(e.substring(0,e.length-he.length))*pe:e.endsWith(fe)?Se(e.substring(0,e.length-fe.length)):Se(e)*pe}function Ee(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ae(0,0,1,1);if("sine"===e)return Ae(.37,0,.63,1);if("sine-in"===e)return Ae(.12,0,.39,0);if("sine-out"===e)return Ae(.61,1,.88,1);if("ease"===e)return Ae(.25,.1,.25,1);if("ease-in"===e)return Ae(.42,0,1,1);if("ease-out"===e)return Ae(0,0,.58,1);if("ease-in-out"===e)return Ae(.42,0,.58,1);if(e.startsWith(ge)&&e.endsWith(ve)){const t=e.substring(ge.length,e.length-ve.length).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Se(t[0]),y1:Se(t[1]),x2:Se(t[2]),y2:Se(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ae(e,t,n,r){return{type:"bezier",x1:e,y1:t,x2:n,y2:r}}function Se(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}const Re=300,xe=2e3,Ce=.05,Ie=2*Math.PI/32,Pe=Ee("hold"),Me=Ee("sine"),Te=Ee("sine-in"),ke=Ee("sine-out");let Le;const Ue=0,$e=3;let De,_e,Oe,Ne=!1,je=1,Fe=1,We=1;const qe=1;let Ge;const ze=new Map;function Qe(e,n,r){const o=e.getContext("2d");null==o&&console.warn("2D context missing.");let i,a,s,l,c,u,d,h,f,p,m,g,v,w,y=!1,b=!0,E=!1,A=1,S=!0,L=!1,j=0,F=0,W=1,q=1,G=1;const z={threeInit:()=>{y||(Ve(),i=new _e.Scene,a=new _e.PerspectiveCamera(25,1,.5),s=new De.OrbitControls(a,e),s.setInteractionEnabled(S),h=_e.ACESFilmicToneMapping,({renderShadow:c,shadowGroup:l}=function(e){const t=new $.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new $.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const r=new $.Group;r.position.y=-.7;const o=new $.PlaneGeometry(P,M).rotateX(Math.PI/2),i=new $.MeshBasicMaterial({map:t.texture,opacity:U,transparent:!0,depthWrite:!1}),a=new $.Mesh(o,i);a.renderOrder=1,a.scale.y=-1,r.add(a);const s=new $.Mesh(o);s.visible=!1,r.add(s);const l=new $.OrthographicCamera(-P/2,P/2,M/2,-M/2,0,T);function c(e){s.visible=!0,O.uniforms.tDiffuse.value=t.texture,O.uniforms.h.value=1*e/256,s.material=O,D.setRenderTarget(n),D.render(s,l),N.uniforms.tDiffuse.value=n.texture,N.uniforms.v.value=1*e/256,s.material=N,D.setRenderTarget(t),D.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,r.add(l),{shadowGroup:r,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=_;const r=D.getClearAlpha();D.setClearAlpha(0),D.setRenderTarget(t),D.render(e,l),e.overrideMaterial=null,c(k),c(.4*k),D.setRenderTarget(null),D.setClearAlpha(r),e.background=n}}}(i)),y=!0)},threeParse:(e,n,r)=>t(this,void 0,void 0,(function*(){return null!=u&&d===r||(yield u,u=(()=>t(this,void 0,void 0,(function*(){var t,r;return x=(t=De).THREE,C=new t.RGBELoader,i.environment=I(n),function(e,t){const{THREE:n}=t;R=(new t.GLTFLoader).setDRACOLoader((new t.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new t.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${n.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e)).setMeshoptDecoder(t.MeshoptDecoder)}(Ge,De),r=e,R.parseAsync(r.buffer,"")})))(),d=r),u})),threeLoad:(e,t)=>{i.traverse((e=>{var t,n;e instanceof _e.Mesh&&(null===(t=e.geometry)||void 0===t||t.dispose(),Array.isArray(e.material)?e.material.forEach((e=>e.dispose())):null===(n=e.material)||void 0===n||n.dispose())})),i.clear(),i.add(e.scene);const n=(new _e.Box3).setFromObject(e.scene);l.position.y=n.min.y-Ue,i.add(l),c(),i.traverse((e=>{e instanceof _e.Mesh&&(e.material.depthWrite=!0)}));const r=n.min.clone().add(n.max).divideScalar(2),o=Math.sqrt(De.reduceVertices(e.scene,((e,t)=>Math.max(e,r.distanceToSquared(t))),0));s.reset(r,o,function(e,t){var n;const r={Glasses:new t(67.5,15,90),Shoes:new t(-55,30,30),Watches:new t(0,-10,40),Handbags:new t(40,0,0),Rings:new t(0,0,10)};return(null==e?r.Glasses:null!==(n=r[e])&&void 0!==n?n:r.Glasses).normalize()}(t,_e.Vector3)),j=0},threePaused:()=>b,threeResume:()=>{b=!1,Ge.setAnimationLoop(Ke),e.style.visibility="visible",F=0,null==p||p.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset(),null==w||w.reset()},threePause:()=>{b=!0,function(){for(const{threePaused:e}of ze.values())if(!e())return!1;return!0}()&&Ge.setAnimationLoop(null),e.style.visibility="hidden",r.style.opacity="0",n.style.visibility="hidden"},threeSetToneMapping:(e,t)=>{const n={ACES:_e.ACESFilmicToneMapping,Linear:_e.LinearToneMapping,Neutral:_e.NeutralToneMapping};null!=n[e]&&(h=n[e]),A=t},threeIsInteractive:()=>S,threeSetInteractive:e=>{S=e,null==s||s.setInteractionEnabled(S)},threeSetOnInteracted:e=>{s.removeEventListener("change",f),f=e,s.addEventListener("change",e)},threeInitPromptAnimation:()=>{var e;e=s.getTheta(),p=te([{time:0,value:e,interpolation:Pe},{time:Re,value:e,interpolation:ke},{time:Re+xe/4,value:e+Ie,interpolation:Me},{time:Re+3*xe/4,value:e-Ie,interpolation:Te},{time:Re+xe,value:e,interpolation:Pe},{time:Re+2*xe,value:e,interpolation:Pe}]),m=null,g=null,v=te([{time:0,value:0,interpolation:Pe},{time:Re,value:1,interpolation:Pe},{time:Re+xe,value:0,interpolation:Pe},{time:Re+2*xe,value:0,interpolation:Pe}]),w=te([{time:0,value:0,interpolation:Pe},{time:Re,value:0,interpolation:ke},{time:Re+xe/4,value:-Ce,interpolation:Me},{time:Re+3*xe/4,value:Ce,interpolation:Te},{time:Re+xe,value:0,interpolation:Pe},{time:Re+2*xe,value:0,interpolation:Pe}])},threeInitThetaAnimation:e=>{p=e},threeInitPhiAnimation:e=>{m=e},threeInitFovAnimation:e=>{g=e},preRender_:e=>{if(!y||b)return;let t=0!==F?e-F:0;F=e,0===j?E=!0:j<$e&&(t=0),j++,L||(s.hasUserInteracted()?(L=!0,p=null,m=null,g=null,v=null,w=null):(null==p||p.update(t),null==m||m.update(t),null==g||g.update(t),null==v||v.update(t),null==w||w.update(t),null!=p&&(s.setTheta(p.get()),E=!0),null!=m&&(s.setPhi(m.get()),E=!0),null!=g&&(s.setFovRadians(g.get()),E=!0))),s.update()&&(E=!0)},shouldRender_:()=>!(!y||b)&&E,render_:()=>{const t=Ge.toneMapping,s=Ge.toneMappingExposure;Ge.toneMapping=h,Ge.toneMappingExposure=A,Ge.setViewport(0,0,e.width,e.height),Ge.render(i,a),Ge.toneMapping=t,Ge.toneMappingExposure=s,E=!1,null!=o&&(o.clearRect(0,0,e.width,e.height),Oe.width>0&&Oe.height>0&&o.drawImage(Oe,0,Fe-e.height,e.width,e.height,0,0,e.width,e.height),n.style.visibility=S&&!L?"visible":"hidden",null!=v&&(r.style.opacity=`${v.get()}`),null!=w&&(r.style.transform=`translateX(${w.get()*Math.min(W,q)}px)`))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===W&&n===q&&We===G||(e.width=Math.ceil(t*We*qe),e.height=Math.ceil(n*We*qe),W=t,q=n,G=We,E=!0)},target_:e};return ze.set(e,z),z}function Ve(){if(Ne)return;De=window.ShopAR__THREE,_e=De.THREE,Oe=document.createElement("canvas");var e,t;Oe.style.position="block",Ge=new _e.WebGLRenderer({powerPreference:"high-performance",canvas:Oe,antialias:!0,alpha:!0}),Ge.outputColorSpace=_e.SRGBColorSpace,Ge.toneMapping=_e.ACESFilmicToneMapping,Ge.setClearColor(new _e.Color(16777215),0),e=Ge,t=De,j||($=t.THREE,D=e,_=new $.MeshDepthMaterial,_.userData.darkness={value:L},_.onBeforeCompile=e=>{e.uniforms.darkness=_.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},_.depthTest=!1,_.depthWrite=!1,O=new $.ShaderMaterial(t.HorizontalBlurShader),O.depthTest=!1,N=new $.ShaderMaterial(t.VerticalBlurShader),N.depthTest=!1,j=!0),Be(),Ne=!0}function Ke(e){Be(),Ge.clear();for(const{preRender_:t,shouldRender_:n,render_:r}of ze.values())t(e),n()&&r()}function Be(){let e=0,t=0;for(const{target_:n}of ze.values()){const{clientWidth:r,clientHeight:o}=n;e=Math.max(e,r),t=Math.max(t,o)}const n=S();e=Math.ceil(e*n*qe),t=Math.ceil(t*n*qe),e===je&&t===Fe&&n===We||(je=e,Fe=t,We=n,Ge.setSize(je,Fe,!1));for(const{updateSize_:e}of ze.values())e()}const He={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},Xe=Object.keys(He);function Ze(e){return He[e]}const Ye="shopar-error";function Je(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const r=document.createElementNS("http://www.w3.org/2000/svg","image");r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),r.setAttribute("width",e),r.setAttribute("height",e),n.appendChild(r)}return n}function et(e,t,n,r){const o=document.createElement("button");o.id=e,o.type="button",o.className="shopar-btn";{const e=Je("1.75rem",r);o.appendChild(e)}{const e=document.createElement("span");e.textContent=t,o.appendChild(e)}o.ariaLabel=n;return o.style.display="none",o}const tt="shopar-control";const nt="shopar-deepar-output";function rt(e){const t=document.createElement("div");t.classList.add("shopar-loading-container",e);const n=t.style;return n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",t}function ot(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function it(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-bg",e);const n=t.style;return n.position="relative",n.overflow="hidden",t}function at(e){const t=document.createElement("div");t.classList.add("shopar-loading-bar-fg",e);const n=t.style;return n.width="100%",n.height="100%",t}const st="shopar-main";const lt="shopar-qr-output";const ct="shopar-three-output";var ut;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(ut||(ut={}));let dt=!1;function ht(){dt||(!function(){try{const e=document.createElement("style"),t=process.env.css;null!=t&&(e.innerHTML=t);const n=document.head;n.insertBefore(e,n.children[0])}catch(e){console.warn("Failed to write default ShopAR Plugin CSS.")}}(),dt=!0)}function ft(){ht();const e=function(){const e=document.createElement("div");e.id=st;const t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}(),t=function(){const e=document.createElement("div");return e.style.textAlign="center",e}(),n=function(){const e=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),r=function(e,t){const n=document.createElement("div");n.id=lt;const r=n.style;r.position="absolute",r.top="0",r.left="0",r.width="100%",r.height="100%",r.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),o.appendChild(e);const a=document.createElement("div");return a.appendChild(t),o.appendChild(a),n}(t,n);e.appendChild(r);const o=function(){const e=document.createElement("div");e.id=nt;const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.display="none",e}();e.appendChild(o);const i=function(){const e=document.createElement("canvas");e.id=ct,e.className="shopar-3d";const t=e.style;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.visibility="hidden",e}();e.appendChild(i);const a=function(){const e=document.createElement("div");return e.className="shopar-ar-prompt-text",e}(),s=function(){const e=new Image;return e.className="shopar-ar-prompt-img",e}(),l=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:r}=n;return r.position="absolute",r.width="100%",r.height="100%",r.pointerEvents="none",r.opacity="0",n.appendChild(e),n.appendChild(t),n}(a,s);e.appendChild(l);const c=function(){const e=Je("2rem",`${b}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),u=function(e){const t=document.createElement("div"),{style:n}=t;return n.visibility="hidden",n.position="absolute",n.width="100%",n.height="100%",n.display="flex",n.justifyContent="center",n.alignItems="center",n.pointerEvents="none",t.appendChild(e),t}(c);e.appendChild(u);const d=rt("shopar-ar-loading-container"),h=ot("shopar-ar-loading-text",Ze("loading.ar"));d.appendChild(h);const f=it("shopar-ar-loading-bar-bg"),p=at("shopar-ar-loading-bar-fg");f.appendChild(p),d.appendChild(f),e.appendChild(d);const m=rt("shopar-3d-loading-container"),g=ot("shopar-3d-loading-text",Ze("loading.3d"));m.appendChild(g);const v=it("shopar-3d-loading-bar-bg"),w=at("shopar-3d-loading-bar-fg");v.appendChild(w),m.appendChild(v),e.appendChild(m);const y=function(){const e=document.createElement("div"),{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",e}(),E=function(){const e=new Image,{style:t}=e;return t.position="absolute",t.top="0",t.left="0",t.width="100%",t.height="100%",t.objectFit="contain",t.pointerEvents="none",e}();y.appendChild(E),e.appendChild(y);const A=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),S=function(e){const t=document.createElement("div");t.id=Ye;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const r=document.createElement("div"),o=r.style;return o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",t.appendChild(r),r.appendChild(e),t}(A);e.appendChild(S);const R=function(){const e=document.createElement("div");return e.id=tt,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(R);const x=et("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");R.appendChild(x);const C=et("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${b}/img/icons/cube.svg`);R.appendChild(C);const I=et("shopar-btn-close","Close","Close ShopAR view",`${b}/img/icons/close.svg`);R.append(I);let P,M=ut.None,T=!1,k=!1,L=!1,U=!1;function $(){p.classList.remove("active"),d.style.visibility="hidden"}function D(){y.style.visibility="hidden",w.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return r},getQRImage:function(){return n},getDeepARTarget:function(){return o},getDeepARPrompt:function(){return l},getThreeTarget:function(){return i},getThreePrompt:function(){return u},getThreePromptImage:function(){return c},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){A.textContent=null!=e?e:"Please reload page and allow camera access to continue"},customizeQRPrompt:function(e){t.textContent=null!=e?e:"Scan on mobile or tablet to try on"},setVisibilityParameters:function(e,t,n,r,o){var i;T=e,k=t,L=n,U=r,P=o,pt(R,T),pt(x,T&&(L||k)&&M===ut.None),pt(C,T&&U&&M===ut.None),pt(I,T&&M!==ut.None),$(),D(),T||""===(i=S).style.display&&pt(i,!1)},getUIState:function(){return M},setUIState:function(e){M=e,M===ut.None?($(),D(),T&&(pt(S,!1),pt(I,!1),(k||L)&&pt(x,!0),U&&pt(C,!0))):M!==ut.QR&&M!==ut.AR&&M!==ut.Preview||T&&(pt(S,!1),pt(x,!1),pt(C,!1),pt(I,!0))},setDefaultUIActions:function(e,t,n){T&&((k||L)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,r=`${b}/img/icons/${n}`;x.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r)}(P),x.onclick=e),U&&(C.onclick=t),I.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:$,startThreeLoading:function(){null!=E.dataset.srcSet?y.style.visibility="visible":(w.classList.add("active"),m.style.visibility="visible")},stopThreeLoading:D,setThreePosterUrl:function(e){null!=e?(E.src=e,E.dataset.srcSet="true"):delete E.dataset.srcSet},showCameraError:function(){T&&pt(S,!0)}}}function pt(e,t){e.style.display=t?"":"none"}const mt=new Map;function gt(e){let n=mt.get(e);return null==n?(n=function(){let e=0,n=null,r=null,o=null;const i=()=>(null==n&&(n=ft()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==r){const{getQRTarget:e,getQRImage:n}=i();r=function(e,n){let r=!0;return{qrPaused:()=>r,qrDraw:(o,i)=>t(this,void 0,void 0,(function*(){yield A;const t=`https://ar.shopar.ai/${w.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:o,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(t),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,r=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){r=!0,e.style.display="none"}))}}(e(),n())}return r},findThree:()=>{if(null==o){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();o=Qe(e(),t(),n())}return o}}}(),mt.set(e,n)):n.incrementSetupId_(),n}function vt(e){for(const t of mt.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:r,setUIState:o}=n;r()===ut.AR&&o(ut.None)}}let wt;const yt=new Uint8Array(16);function bt(){if(!wt&&(wt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!wt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return wt(yt)}const Et=[];for(let e=0;e<256;++e)Et.push((e+256).toString(16).slice(1));var At={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function St(e,t,n){if(At.randomUUID&&!t&&!e)return At.randomUUID();const r=(e=e||{}).random||(e.rng||bt)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return Et[e[t+0]]+Et[e[t+1]]+Et[e[t+2]]+Et[e[t+3]]+"-"+Et[e[t+4]]+Et[e[t+5]]+"-"+Et[e[t+6]]+Et[e[t+7]]+"-"+Et[e[t+8]]+Et[e[t+9]]+"-"+Et[e[t+10]]+Et[e[t+11]]+Et[e[t+12]]+Et[e[t+13]]+Et[e[t+14]]+Et[e[t+15]]}(r)}const Rt="qrLaunch",xt="arLaunch",Ct="previewLaunch",It="heartbeat";let Pt,Mt,Tt=!1,kt=window.navigator.userAgent||"no user agent";const Lt=[];function Ut(){null==Pt&&(Mt=St(),Pt=E(`${b}/shopar-analytics.js`),Pt.then((()=>{Tt=!0,window.ShopAR__analytics.initializeImpl(),Lt.forEach((e=>e()))})))}function $t(e){Tt?e():Lt.push(e)}function Dt(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function _t(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const Ot=200,Nt=10;let jt=!1,Ft=null,Wt=[],qt=[];function Gt(e){return t(this,void 0,void 0,(function*(){jt=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${b}/wasm/mediapipe`,e),Ft&&clearInterval(Ft);const r=[],o=[];Ft=setInterval((()=>t(this,void 0,void 0,(function*(){if(jt)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());jt||(null!=a&&null!=s&&function(e){for(let t of Wt)t(e)}({translation:a,rotation:s}),null==e&&(r.push(t),o.push(i),r.length<Nt||(r.shift(),o.shift(),function(e,t){for(let n of qt)n({faceWidth:e,IPD:t})}(Qt(r),Qt(o)))))}))),Ot)}))}function zt(){qt=[],Wt=[],jt=!0}function Qt(e){let t=0;const n=e.length;for(let r=0;r<n;r++)t+=e[r];return t/n}function Vt(e){return t(this,void 0,void 0,(function*(){const r=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield r.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}var Kt="undefined"!=typeof Float32Array?Float32Array:Array;function Bt(){var e=new Kt(16);return Kt!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Ht(e,t,n){var r=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],u=t[7],d=t[8],h=t[9],f=t[10],p=t[11],m=t[12],g=t[13],v=t[14],w=t[15],y=n[0],b=n[1],E=n[2],A=n[3];return e[0]=y*r+b*s+E*d+A*m,e[1]=y*o+b*l+E*h+A*g,e[2]=y*i+b*c+E*f+A*v,e[3]=y*a+b*u+E*p+A*w,y=n[4],b=n[5],E=n[6],A=n[7],e[4]=y*r+b*s+E*d+A*m,e[5]=y*o+b*l+E*h+A*g,e[6]=y*i+b*c+E*f+A*v,e[7]=y*a+b*u+E*p+A*w,y=n[8],b=n[9],E=n[10],A=n[11],e[8]=y*r+b*s+E*d+A*m,e[9]=y*o+b*l+E*h+A*g,e[10]=y*i+b*c+E*f+A*v,e[11]=y*a+b*u+E*p+A*w,y=n[12],b=n[13],E=n[14],A=n[15],e[12]=y*r+b*s+E*d+A*m,e[13]=y*o+b*l+E*h+A*g,e[14]=y*i+b*c+E*f+A*v,e[15]=y*a+b*u+E*p+A*w,e}function Xt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Zt(e,t){var n=t[0],r=t[1],o=t[2],i=t[4],a=t[5],s=t[6],l=t[8],c=t[9],u=t[10];return e[0]=Math.hypot(n,r,o),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(l,c,u),e}function Yt(e,t,n,r){var o=t[0],i=t[1],a=t[2],s=t[3],l=o+o,c=i+i,u=a+a,d=o*l,h=o*c,f=o*u,p=i*c,m=i*u,g=a*u,v=s*l,w=s*c,y=s*u,b=r[0],E=r[1],A=r[2];return e[0]=(1-(p+g))*b,e[1]=(h+y)*b,e[2]=(f-w)*b,e[3]=0,e[4]=(h-y)*E,e[5]=(1-(d+g))*E,e[6]=(m+v)*E,e[7]=0,e[8]=(f+w)*A,e[9]=(m-v)*A,e[10]=(1-(d+p))*A,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Jt(){var e=new Kt(3);return Kt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function en(e,t,n){var r=new Kt(3);return r[0]=e,r[1]=t,r[2]=n,r}function tn(e,t){var n=t[0]-e[0],r=t[1]-e[1],o=t[2]-e[2];return Math.hypot(n,r,o)}function nn(e,t,n){var r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*r+n[4]*o+n[8]*i+n[12])/a,e[1]=(n[1]*r+n[5]*o+n[9]*i+n[13])/a,e[2]=(n[2]*r+n[6]*o+n[10]*i+n[14])/a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function rn(){var e=new Kt(4);return Kt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Jt(),function(){var e,t=(e=new Kt(4),Kt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var on;let an,sn,ln;Jt(),en(1,0,0),en(0,1,0),rn(),rn(),on=new Kt(9),Kt!=Float32Array&&(on[1]=0,on[2]=0,on[3]=0,on[5]=0,on[6]=0,on[7]=0),on[0]=1,on[4]=1,on[8]=1;let cn,un,dn,hn,fn=!0,pn=null;const mn=new Set;let gn,vn,wn,yn,bn,En;function An(){null==an&&(an=E(`${b}/shopar-deepar.js`))}function Sn(){null==sn&&(sn=E(`${b}/shopar-true-scale.js`))}function Rn(e){return t(this,void 0,void 0,(function*(){const{licenseKey:r,truescaleUsecase:o}=e;return bn=o,null==gn&&(gn=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(e=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))throw new n("No camera available!");var e;const t=Ln(dn),o=Dt(t);cn=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:r||"your_license_key_goes_here",previewElement:hn,additionalOptions:{hint:En,cameraConfig:{disableDefaultCamera:!0}}}),un=yield _t(o),yield Un(cn,un,"user"===t),"Glasses"===dn&&(yield sn,Gt(un),"DetectionLoop"!==bn&&On((e=>{yn=e.faceWidth})))})))()),gn}))}function xn(e,t){var n,r;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===dn&&(n=t,r=En,n===r||null!=n&&null!=r&&n.length===r.length&&n.every((e=>r.find((t=>e===t))))&&r.every((e=>n.find((t=>t===e))))))||(null!=cn&&(cn.shutdown(),cn=null,gn=null),dn=e,En=t)}function Cn(e){e!==hn&&(hn=e,null!=cn&&cn.changePreviewElement(hn))}function In(e){pn=e}function Pn(e){cn.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(yn){const e=137/(yn+5);cn.changeParameterVector("GLASSES","","scale",e,e,e,0),cn.changeParameterVector("shopar_glasses","","scale",e,e,e,0),function(e){const t=[-8.362421,4.549,-9.275],n=[8.362421,4.549,-9.275];try{const r=Dn("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),o=Dn("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);cn.changeParameterVector("temple_left","","rotation",0,56.6*-r,0,0),cn.changeParameterVector("temple_right","","rotation",0,56.6*-o,0,0)}catch(e){return}}(e),zt(),yn=null}e(),$n("Glasses")}},cn.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),$n("Shoes"))},cn.callbacks.onWristTracked=t=>{t.detected&&(e(),$n("Watches"))}}function Mn(e,n){return t(this,void 0,void 0,(function*(){return null!=vn&&wn===n||(yield vn,vn=cn.switchEffect(e),wn=n),vn}))}function Tn(){return t(this,void 0,void 0,(function*(){if(null!=cn){if(fn=!1,null==un){const e=Ln(dn),t=Dt(e);un=yield _t(t),yield Un(cn,un,"user"===e),"Glasses"===dn&&(Gt(un),"DetectionLoop"!==bn&&On((e=>{yn=e.faceWidth})))}!function(){if(null==pn)return;if(null==dn||mn.has(dn))return;pn.style.visibility="visible",pn.style.opacity="1"}(),cn.setPaused(fn),hn.style.display=""}}))}function kn(){null!=cn&&(fn=!0,cn.setPaused(fn),zt(),null!=un&&null!=un.srcObject&&un.srcObject instanceof MediaStream&&(un.srcObject.getTracks().forEach((e=>e.stop())),un=null),function(){if(null==pn)return;pn.style.visibility="hidden",pn.style.opacity="0"}(),cn.stopCamera(),hn.style.display="none")}function Ln(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function Un(e,n,r){return t(this,void 0,void 0,(function*(){yield new Promise((o=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,r),o()}))))}}))}))}function $n(e){null!=pn&&(mn.has(e)||(mn.add(e),pn.style.opacity="0"))}function Dn(e,t,n,r,o,i,a){const s=cn.getTransformationBetween(e,t),l=Xt(Jt(),s),c=function(e,t){var n=new Kt(3);Zt(n,t);var r=1/n[0],o=1/n[1],i=1/n[2],a=t[0]*r,s=t[1]*o,l=t[2]*i,c=t[4]*r,u=t[5]*o,d=t[6]*i,h=t[8]*r,f=t[9]*o,p=t[10]*i,m=a+u+p,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(d-f)/g,e[1]=(h-l)/g,e[2]=(s-c)/g):a>u&&a>p?(g=2*Math.sqrt(1+a-u-p),e[3]=(d-f)/g,e[0]=.25*g,e[1]=(s+c)/g,e[2]=(h+l)/g):u>p?(g=2*Math.sqrt(1+u-a-p),e[3]=(h-l)/g,e[0]=(s+c)/g,e[1]=.25*g,e[2]=(d+f)/g):(g=2*Math.sqrt(1+p-a-u),e[3]=(s-c)/g,e[0]=(h+l)/g,e[1]=(d+f)/g,e[2]=.25*g),e}(rn(),s);Yt(s,c,l,en(a,a,a));const u=cn.getTransformationBetween(t,n),d=Xt(Jt(),u);Yt(u,rn(),d,Zt(Jt(),u));const h=Ht(Bt(),s,u),f=Xt(Jt(),h),p=Math.atan2(i[0]-f[0],Math.abs(i[2]-f[2]));let m;try{m=cn.getTransformationBetween(n,r)}catch(e){return p}const g=Ht(Bt(),u,m),v=Ht(Bt(),s,g),w=en(f[0],i[1],i[2]),y=nn(Jt(),w,function(e,t){var n=t[0],r=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],u=t[8],d=t[9],h=t[10],f=t[11],p=t[12],m=t[13],g=t[14],v=t[15],w=n*s-r*a,y=n*l-o*a,b=n*c-i*a,E=r*l-o*s,A=r*c-i*s,S=o*c-i*l,R=u*m-d*p,x=u*g-h*p,C=u*v-f*p,I=d*g-h*m,P=d*v-f*m,M=h*v-f*g,T=w*M-y*P+b*I+E*C-A*x+S*R;return T?(T=1/T,e[0]=(s*M-l*P+c*I)*T,e[1]=(o*P-r*M-i*I)*T,e[2]=(m*S-g*A+v*E)*T,e[3]=(h*A-d*S-f*E)*T,e[4]=(l*C-a*M-c*x)*T,e[5]=(n*M-o*C+i*x)*T,e[6]=(g*b-p*S-v*y)*T,e[7]=(u*S-h*b+f*y)*T,e[8]=(a*P-s*C+c*R)*T,e[9]=(r*C-n*P-i*R)*T,e[10]=(p*A-m*b+v*w)*T,e[11]=(d*b-u*A-f*w)*T,e[12]=(s*x-a*I-l*R)*T,e[13]=(n*I-r*x+o*R)*T,e[14]=(m*y-p*E-g*w)*T,e[15]=(u*E-d*y+h*w)*T,e):null}(Bt(),v));let b=cn.getClosestPointOnMesh(r,y);try{const e=cn.getClosestPointOnMesh(o,y);tn(y,e)<tn(y,b)&&(b=e)}catch(e){}const E=nn(Jt(),b,g);return p-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function _n(e){!function(e){Wt.push(e)}(e)}function On(e){!function(e){qt.push(e)}(e)}var Nn;function jn(){return[Nn.Android,Nn.iOS,Nn.Tablet].includes(function(){if("undefined"!=typeof window&&window.navigator){const e=window.navigator.userAgent,t=window.navigator.platform||"",n=["Macintosh","MacIntel","MacPPC","Mac68K"],r=["Win32","Win64","Windows","WinCE"],o=["iPhone","iPod","iPad"];return"ontouchstart"in window||navigator.maxTouchPoints>0?Nn.Tablet:-1!==o.indexOf(t)?Nn.iOS:-1!==n.indexOf(t)?Nn.MacOS:-1!==r.indexOf(t)?Nn.Windows:/Android/.test(e)?Nn.Android:/Linux/.test(t)?Nn.Linux:Nn.Unknown}return Nn.Unknown}())}function Fn(e,o,i){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const d=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${d+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],g=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield m(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),v=new r[0](yield(yield g.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=v.byteLength;if(u[c]=Math.min(76,o)*((a>>5)-1),152===u[c]&&(u[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)u[c]^=u[i]<<13,u[c]^=u[i]>>17,u[c]^=u[i]<<5,v[e]=v[e]^u[c];return i^=u[0],i^=u[1],i^=u[2],v}))}function Wn(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function qn(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}function Gn(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}!function(e){e[e.Unknown=0]="Unknown",e[e.Android=1]="Android",e[e.iOS=2]="iOS",e[e.Tablet=3]="Tablet",e[e.MacOS=4]="MacOS",e[e.Windows=5]="Windows",e[e.Linux=6]="Linux"}(Nn||(Nn={}));const zn=["AR","3D"];function Qn(e){const{apiKey:t,sku:r,targetElement:o,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;Wn(t,"apiKey"),Gn(t,"apiKey"),Wn(r,"sku"),Gn(r,"sku"),Wn(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&function(e,t,r){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!r.includes(e))throw new n(`'${t}' must be ${r.join("' or '")}.`)}(i,"initialState",zn),null!=a&&function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new n(`'${t}' must be a string or array.`)}(a,"initialAnimation"),null!=s&&Gn(s,"baseUrl"),null!=l&&qn(l,"defaultUI"),null!=c&&qn(c,"interactive"),null!=u&&function(e,t,r){for(const o of r){const r=e[o];if(null!=r&&"string"!=typeof r)throw new n(`Value for key '${o}' in '${t}' must be a string.`)}}(u,"strings",Xe)}let Vn=!1;function Kn(e){return t(this,void 0,void 0,(function*(){const{targetElement:r}=e;b.update(e.baseUrl),Ut();const{trackEvent:o}=function(e){const t=performance.now(),n=St();return{trackEvent:(r,o={})=>{o=Object.assign(Object.assign({},o),{pluginVersion:w,userAgent:kt,sessionId:Mt,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),$t((()=>{window.ShopAR__analytics.trackEventImpl(r,o)}))}}}(e.apiKey);o("visionSetup");const i=yield function(e){return t(this,void 0,void 0,(function*(){const r=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:e,sid:d()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield r.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(e.apiKey);o("visionApiResponse",i);const{arKey:a}=i,s=gt(r),{getSetupId:l,findUI:c}=s,u=l();An(),Sn();const{setTargetElement:h,getDeepARTarget:f,setVisibilityParameters:m,getUIState:g,setUIState:v,startDeepARLoading:y,stopDeepARLoading:E,showCameraError:A}=c();if(g()!=ut.None)throw Error("UI state is not None, this is weird..");v(ut.AR),h(r),m(!1,!1,!0,!1,void 0),y(),yield an,Bn(l(),u);try{o("visionArLaunch"),kn(),xn("Glasses",["faceInit"]),Cn(f()),yield Rn({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Bn(l(),u),yield Tn(),Bn(l(),u)}catch(e){const t=e instanceof Error;throw o("visionArLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),A(),kn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{E()}return Vn=!0,{registerFacePoseListener:e=>{Vn&&(o("registerFacePoseListener"),_n(e))},registerFaceMeasurementListener:e=>{Vn&&(o("registerFaceMeasurementListener"),On(e))},switchEffect:e=>t(this,void 0,void 0,(function*(){Vn&&(o("switchEffect",{arUrl:e}),function(e){cn.switchEffect(e)}(e))})),clearEffect:()=>{Vn&&(o("clearEffect"),cn.clearEffect())},close:()=>{if(Vn){if(Vn=!1,o("visionClose"),g()!==ut.AR)throw new n("AR not launched.");kn(),v(ut.None)}}}}))}function Bn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}function Hn(e){var r,o;return t(this,void 0,void 0,(function*(){Qn(e);const{apiKey:i,sku:a,targetElement:s,initialState:l,initialAnimation:c}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),b.update(e.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(He,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(He[t]=n)}}(e.strings);const u=null!=c?we(c):null,h=null!=(null==u?void 0:u.theta)?te(u.theta):null,f=null!=(null==u?void 0:u.phi)?te(u.phi):null,y=null!=(null==u?void 0:u.fov)?te(u.fov):null,S=function(e,r,o,i,a){return t(this,void 0,void 0,(function*(){const s=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams(Object.assign(Object.assign(Object.assign({apiKey:e,sku:r,sid:d()},null!=o&&{theta:`${m(o)}`}),null!=i&&{phi:`${m(i)}`}),null!=a&&{fov:`${m(a)}`}))}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield s.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a,null==h?void 0:h.get(),null==f?void 0:f.get(),null==y?void 0:y.get()),R=gt(s),{getSetupId:x,findUI:C,findQR:I,findThree:P}=R,M=x();Ut();const{trackEvent:T,arInteracted:k,previewInteracted:L}=function(e,t){const n=performance.now(),r=St();let o=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(o=i+a,c=!1,u(It,{engagementTotal:o,engagementAR:i,engagement3D:a}))}),1e3);const u=(o,i={})=>{i=Object.assign(Object.assign({},i),{userAgent:kt,pluginVersion:w,sessionId:Mt,setupId:r,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),$t((()=>{window.ShopAR__analytics.trackEventImpl(o,i)}))};return{trackEvent:u,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,c=!0)},previewInteracted:()=>{const e=performance.now(),t=e-l;l=e,t<200&&(a+=t,c=!0)}}}(a,i);T("setup",{hostname:window.location.hostname});const U=yield S;T("apiResponse",U);const{category:$,arUrl:D,arKey:_,arPromptEnabled:O,arPromptText:N,arPromptImage:j,previewUrl:F,previewEnvUrl:W,previewToneMapping:q,previewToneMappingExposure:G,previewPosterUrl:z,cameraErrorText:Q,qrPromptText:V}=U;Xn(x(),M);const K=null!=D&&function(e){return null!=e&&g.includes(e)}($),B=null==(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled)||(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled),H=K&&function(e){return null!=e&&v.includes(e)}($),X=B&&H&&!jn(),Z=K&&!X,Y=null!=F;if(Xn(x(),M),X&&function(){t(this,void 0,void 0,(function*(){null==A&&(A=E(`${b}/shopar-qr.js`))}))}(),Z&&(An(),function(e){e!==ln&&(ln=e,Vt(e),vn=null,zt())}(D),"Glasses"===$&&Sn()),Y){null==Le&&(Le=E(`${b}/shopar-three.js`));const e=255;Fn(F,(new Date).getTime()+e,Math.random()*e),Vt(null!=W?W:`${b}/env/default.hdr`)}const{setTargetElement:J,getDeepARTarget:ee,getDeepARPrompt:ne,customizeDeepARPrompt:re,customizeCameraError:oe,customizeQRPrompt:ie,setVisibilityParameters:ae,getUIState:se,setUIState:le,setDefaultUIActions:ce,startDeepARLoading:ue,stopDeepARLoading:de,startThreeLoading:he,stopThreeLoading:fe,setThreePosterUrl:pe,showCameraError:me}=C();J(s);ae(null==e.defaultUI||e.defaultUI,X,Z,Y,$),re(null!=N?N:"",null!=j?j:""),oe(Q),ie(V),pe(z),function(e,t){const r=e.parentNode;if(null==r)throw new n("Parent node missing.");new MutationObserver((n=>{for(const r of n)for(const n of r.removedNodes)if(n===e)return void t()})).observe(r,{childList:!0})}(s,(()=>{se()!==ut.QR||ge()||ye(),se()!==ut.AR||fn||kn(),se()!==ut.Preview||Se()||xe(),le(ut.None)}));const{qrPaused:ge,qrDraw:ve,qrPause:ye}=I(),{threeInit:be,threeParse:Ee,threeLoad:Ae,threePaused:Se,threeResume:Re,threePause:xe,threeSetToneMapping:Ce,threeIsInteractive:Ie,threeSetInteractive:Pe,threeSetOnInteracted:Me,threeInitPromptAnimation:Te,threeInitThetaAnimation:ke,threeInitPhiAnimation:Ue,threeInitFovAnimation:$e}=P(),De=null==e.interactive||e.interactive;Pe(De);let _e=0;if(se()===ut.QR){if(!ge())if(X){T(Rt);try{yield ve(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ye(),le(ut.None)}else if(se()===ut.AR){if(!fn)if(Z&&!Vn){T(xt);const e=yield Vt(D);Xn(x(),M),vt(R),xn($),Cn(ee()),In(O?ne():null),yield Mn(e,D),Pn(k),Xn(x(),M)}else kn(),le(ut.None)}else if(se()===ut.Preview&&!Se())if(Y){T(Ct),he();const e=255,t=yield Fn(F,(new Date).getTime()+e,Math.random()*e);Xn(x(),M);const n=yield Vt(null!=W?W:`${b}/env/default.hdr`);Xn(x(),M);const r=yield Ee(t,n,`${F}${W}`);Xn(x(),M),Ae(r,$),Ce(null!=q?q:"ACES",null!=G?G:1),Me(L),Te(),null!=u&&(ke(h),Ue(f),$e(y)),fe()}else xe(),le(ut.None);const Oe=()=>t(this,void 0,void 0,(function*(){if(X){if(se()===ut.QR||se()===ut.AR)throw new n("AR already launched.");try{T(Rt);const e=++_e;if(se()===ut.Preview&&Y&&!Se()&&xe(),le(ut.QR),yield ve(i,a),_e!==e)return;return void Xn(x(),M)}catch(e){const t=e instanceof Error;throw T("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!Z)throw new n("Model does not have AR enabled.");if(se()===ut.AR)throw new n("AR already launched.");try{T(xt);const e=++_e;se()===ut.Preview&&Y&&!Se()&&xe(),vt(R),le(ut.AR),ue();const t=yield Vt(D);if(_e!==e)return;if(Xn(x(),M),yield an,_e!==e)return;if(Xn(x(),M),kn(),xn($),Cn(ee()),In(O?ne():null),yield Rn({licenseKey:_}),_e!==e)return;if(Xn(x(),M),yield Mn(t,D),Pn(k),_e!==e)return;if(Xn(x(),M),yield Tn(),_e!==e)return;Xn(x(),M)}catch(e){const t=e instanceof Error;throw T("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),me(),kn(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{de()}})),Ne=()=>t(this,void 0,void 0,(function*(){if(!Y)throw new n("Model does not have 3D enabled.");if(se()===ut.Preview)throw new n("3D already launched.");try{T(Ct);const e=++_e;se()===ut.AR&&(Z&&!fn&&kn(),ye()),le(ut.Preview),he();const t=255,n=yield Fn(F,(new Date).getTime()+t,Math.random()*t);if(_e!==e)return;Xn(x(),M);const r=yield Vt(null!=W?W:`${b}/env/default.hdr`);if(_e!==e)return;if(Xn(x(),M),yield Le,_e!==e)return;if(Xn(x(),M),be(),_e!==e)return;Xn(x(),M);const o=yield Ee(n,r,`${F}${W}`);if(_e!==e)return;Xn(x(),M),Ae(o,$),Ce(null!=q?q:"ACES",null!=G?G:1),Me(L),Te(),null!=u&&(ke(h),Ue(f),$e(y)),Re()}catch(e){const t=e instanceof Error;throw T("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{fe()}})),je=()=>t(this,void 0,void 0,(function*(){if(se()===ut.None)throw new n("Neither AR or 3D launched.");++_e,se()===ut.QR||se()===ut.AR?(Z&&!fn&&kn(),ye()):se()===ut.Preview&&Y&&!Se()&&xe(),le(ut.None)}));return ce(Oe,Ne,je),"AR"===l?(yield Oe(),Xn(x(),M)):"3D"===l&&(yield Ne(),Xn(x(),M)),Vn=!1,{launchAR:K?Oe:void 0,launch3D:Y?Ne:void 0,closeAR:K?()=>t(this,void 0,void 0,(function*(){if(se()!==ut.AR&&se()!==ut.QR)throw new n("AR not launched.");++_e,Z&&!fn&&kn(),ye(),le(ut.None)})):void 0,close3D:Y?()=>t(this,void 0,void 0,(function*(){if(se()!==ut.Preview)throw new n("3D not launched.");++_e,Y&&!Se()&&xe(),le(ut.None)})):void 0,close:K||Y?je:void 0,isInteractive:()=>Ie(),setInteractive:e=>Pe(e)}}))}function Xn(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const Zn={setup:function(e){return t(this,void 0,void 0,(function*(){return Kn(e)}))}},Yn={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,r){return t(this,void 0,void 0,(function*(){try{return r()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>Hn(e)))}))},version:w};e.plugin=Yn,e.vision=Zn}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shopar-plugin",
|
|
3
|
-
"version": "0.4.0
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",
|
|
5
5
|
"main": "dist/shopar-plugin.esm.js",
|
|
6
6
|
"module": "dist/shopar-plugin.esm.js",
|