shopar-plugin 0.1.2 → 0.1.3-alpha.2
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.d.ts +97 -1
- package/dist/shopar-plugin.esm.js +1 -1
- package/dist/shopar-plugin.js +1 -1
- package/dist/shopar-qr.js +1 -1
- package/dist/shopar-three.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@{{VERSION}}/dist/shopar-plugin.js"></script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
It is possible to use a different CDN instead of [jsDelivr](https://www.jsdelivr.com/) (e.g. [cdnjs](https://cdnjs.com/), [unpkg](https://www.unpkg.com/)), or even a relative path if the plugin is distributed as a static asset to your app. Just make sure to set the `baseUrl` parameter accordingly (see [setup options](#shoparpluginsetupoptions) for more details).
|
|
@@ -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@{{VERSION}}/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 b extends v{batch={};ingest=(t,e,i)=>{const n=function(t,e){return`${t}:${e?.timestampField||"-"}:${e?.timestampFormat||"-"}:${e?.csvDelimiter||"-"}`}(t,i);return this.batch[n]||(this.batch[n]=new w(((t,e,i)=>{const n=(Array.isArray(e)?e:[e]).map((t=>JSON.stringify(t))).join("\n");return this.ingestRaw(t,n,y.NDJSON,p.Identity,i)}),t,i)),this.batch[n].ingest(e)};flush=async()=>{let t=[];for(const e in this.batch)t.push(this.batch[e].flush());await Promise.all(t)}}let x;!function(t){t.JSON="application/json",t.NDJSON="application/x-ndjson",t.CSV="text/csv"}(y||(y={})),function(t){t.Identity="",t.GZIP="gzip"}(p||(p={})),function(t){t.Count="count",t.Distinct="distinct",t.Sum="sum",t.Avg="avg",t.Min="min",t.Max="max",t.Topk="topk",t.Percentiles="percentiles",t.Histogram="histogram",t.Variance="variance",t.Stdev="stdev",t.ArgMin="argmin",t.ArgMax="argmax",t.MakeSet="makeset",t.MakeSetIf="makesetif",t.CountIf="countif",t.CountDistinctIf="distinctif"}(d||(d={})),function(t){t.And="and",t.Or="or",t.Not="not",t.Equal="==",t.NotEqual="!=",t.Exists="exists",t.NotExists="not-exists",t.GreaterThan=">",t.GreaterThanOrEqualTo=">=",t.LessThan="<",t.LessThanOrEqualTo="<=",t.Gt="gt",t.Gte="gte",t.Lt="lt",t.Lte="lte",t.StartsWith="starts-with",t.NotStartsWith="not-starts-with",t.EndsWith="ends-with",t.NotEndsWith="not-ends-with",t.Contains="contains",t.NotContains="not-contains",t.Regexp="regexp",t.NotRegexp="not-regexp"}(g||(g={})),t.initializeImpl=function(){x=new b({token:"xaat-16d05fdd-4ab9-4990-acba-7cee24974bfb"})},t.trackEventImpl=function(t,e){x.ingest("shopar-plugin-alpha",Object.assign({name:t},e))}}));
|
package/dist/shopar-plugin.d.ts
CHANGED
|
@@ -8,6 +8,37 @@ type Strings = typeof strings_;
|
|
|
8
8
|
declare const PREVIEW_STATE: readonly ["AR", "3D"];
|
|
9
9
|
/** Preview state type. */
|
|
10
10
|
type PreviewState = typeof PREVIEW_STATE[number];
|
|
11
|
+
/**
|
|
12
|
+
* Configuration of an animation key frame at the specified time point.
|
|
13
|
+
*/
|
|
14
|
+
type KeyFrameConfig = {
|
|
15
|
+
/** Timestamp (in ms). */
|
|
16
|
+
time: number;
|
|
17
|
+
/** Vertical angle of rotation (in degrees). */
|
|
18
|
+
pitch?: number;
|
|
19
|
+
/** Horizontal angle of rotation (in degrees). */
|
|
20
|
+
yaw?: number;
|
|
21
|
+
/** Camera's field of view (in degrees). */
|
|
22
|
+
fov?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Easing function used for interpolating the values between this and the next key frame.
|
|
25
|
+
*
|
|
26
|
+
* Supported options are:
|
|
27
|
+
* - `'hold'`: maintain the current value without interpolation.
|
|
28
|
+
* - `'linear'`: linear interpolation.
|
|
29
|
+
* - `'sine'`: sine wave interpolation.
|
|
30
|
+
* - `'ease'`: starts slowly, accelerates sharply and slows gradually towards the end.
|
|
31
|
+
* - `'ease-in'`: starts slowly, progressively speeds up until the end, at which point it stops abruptly.
|
|
32
|
+
* - `'ease-out'`: starts abruptly and progressively slows down towards the end.
|
|
33
|
+
* - `'ease-in-out'`: smooth start and end with gradual acceleration and decceleration.
|
|
34
|
+
*
|
|
35
|
+
* Additionally, it's possible to specify a custom Bézier function:
|
|
36
|
+
* - `'cubic-bezier(x1, y1, x2, y2)'`: define two 2D points for a custom interpolation curve.
|
|
37
|
+
*
|
|
38
|
+
* @default 'ease-in-out'
|
|
39
|
+
*/
|
|
40
|
+
interpolation?: string;
|
|
41
|
+
};
|
|
11
42
|
/**
|
|
12
43
|
* Options used for the plugin setup.
|
|
13
44
|
*/
|
|
@@ -44,10 +75,63 @@ type SetupOptions = {
|
|
|
44
75
|
* shopAR.launchAR();
|
|
45
76
|
* ```
|
|
46
77
|
*
|
|
47
|
-
* @default
|
|
78
|
+
* @default true
|
|
48
79
|
*/
|
|
49
80
|
defaultUI?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* If provided and set to `false`, disables user interactivity by ignoring input events.
|
|
83
|
+
*
|
|
84
|
+
* @default true
|
|
85
|
+
*/
|
|
86
|
+
interactive?: boolean;
|
|
50
87
|
strings?: Strings;
|
|
88
|
+
/**
|
|
89
|
+
* If provided, replaces the default interactivity animation in 3D with a custom one.
|
|
90
|
+
*
|
|
91
|
+
* Two formats are supported: `KeyFrameConfig[]` and `string`.
|
|
92
|
+
* For more information on the `KeyFrameConfig[]` format, see {@link KeyFrameConfig}.
|
|
93
|
+
*
|
|
94
|
+
* The `string` format is interpreted as a plain-text table. Empty lines and comments are ignored.
|
|
95
|
+
* First line defines the columns and all subsequent lines define data per key frame.
|
|
96
|
+
*
|
|
97
|
+
* Supported columns are:
|
|
98
|
+
* - `time`: timestamp of the key frame.
|
|
99
|
+
* - `pitch`: vertical angle of rotation.
|
|
100
|
+
* - `yaw`: horizontal angle of rotation.
|
|
101
|
+
* - `fov`: camera's field of view.
|
|
102
|
+
* - `interpolation`: easing function used for interpolating the values between this and the next key frame.
|
|
103
|
+
* See {@link KeyFrameConfig.interpolation} for supported options.
|
|
104
|
+
*
|
|
105
|
+
* Timestamps are specified with or without a unit (`ms` or `s`). When not specified, milliseconds are used.
|
|
106
|
+
*
|
|
107
|
+
* Angles are specified with or without a unit (`deg` or `rad`). When not specified, degrees are used.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* `
|
|
111
|
+
* # Empty lines and comments are ignored.
|
|
112
|
+
*
|
|
113
|
+
* time pitch yaw fov interpolation
|
|
114
|
+
* 0s 45deg 60deg 25deg hold
|
|
115
|
+
* 1s 45deg 60deg 25deg ease-in-out
|
|
116
|
+
* 2s 60deg -60deg 20deg hold
|
|
117
|
+
* 3s 60deg -60deg 20deg ease-in-out
|
|
118
|
+
* 4s 90deg 90deg 40deg hold
|
|
119
|
+
* 5s 90deg 90deg 40deg ease-in-out
|
|
120
|
+
* 6s 45deg 420deg 25deg hold
|
|
121
|
+
* `
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* [
|
|
125
|
+
* { time: 0, pitch: 45, yaw: 60, fov: 25, interpolation: 'hold' },
|
|
126
|
+
* { time: 1000, pitch: 45, yaw: 60, fov: 25, interpolation: 'ease-in-out' },
|
|
127
|
+
* { time: 2000, pitch: 60, yaw: -60, fov: 20, interpolation: 'hold' },
|
|
128
|
+
* { time: 3000, pitch: 60, yaw: -60, fov: 20, interpolation: 'ease-in-out' },
|
|
129
|
+
* { time: 4000, pitch: 90, yaw: 90, fov: 40, interpolation: 'hold' },
|
|
130
|
+
* { time: 5000, pitch: 90, yaw: 90, fov: 40, interpolation: 'ease-in-out' },
|
|
131
|
+
* { time: 6000, pitch: 45, yaw: 420, fov: 25, interpolation: 'hold' },
|
|
132
|
+
* ]
|
|
133
|
+
*/
|
|
134
|
+
initialAnimation?: KeyFrameConfig[] | string;
|
|
51
135
|
_internalOptions?: any;
|
|
52
136
|
};
|
|
53
137
|
/**
|
|
@@ -135,6 +219,18 @@ type Plugin = {
|
|
|
135
219
|
* @returns A promise that resolves when AR or 3D is closed.
|
|
136
220
|
*/
|
|
137
221
|
close?: () => Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* Returns the current user interactivity value.
|
|
224
|
+
*
|
|
225
|
+
* @returns `true` is user interactivity is enabled and `false` otherwise.
|
|
226
|
+
*/
|
|
227
|
+
isInteractive: () => boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Sets user interactivity to the provided value. Set to `false` to ignore input events.
|
|
230
|
+
*
|
|
231
|
+
* @param value The provided value.
|
|
232
|
+
*/
|
|
233
|
+
setInteractive: (interactive: boolean) => void;
|
|
138
234
|
};
|
|
139
235
|
/**
|
|
140
236
|
* Vision plugin controller
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((o=o.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}"};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],o=n.length-2,r=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],i=[2,12,7,1],a=window[r[i[i[o]]]][r[i[i[i.length-1]]]],s=a.charCodeAt(o),c=s^s,l=new n[1]([c]);function d(){const e=(new TextEncoder).encode(a),t=r.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[r[t[2]]](String.fromCodePoint(...e))}const u=[1e3,2e3,4e3],h=u.length;function p(t,n=0){return e(this,void 0,void 0,(function*(){try{return yield t()}catch(e){if(n>=h)throw e;return yield new Promise((e=>setTimeout(e,u[n]))),p(t,n+1)}}))}const f=["Glasses","Shoes","Watches"],m=["Shoes"];const g="0.1.2";let v=`https://cdn.jsdelivr.net/npm/shopar-plugin@${g}/dist`;const w={update:e=>{null!=e&&(v=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>v};function y(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let b;const R=(()=>{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,A,E;function C(e){const t=function(e){const t=new A.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,A.ClampToEdgeWrapping,A.ClampToEdgeWrapping,A.LinearFilter,A.LinearFilter,1,A.LinearSRGBColorSpace);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(E.parse(e));return t.mapping=A.EquirectangularReflectionMapping,t.colorSpace=A.LinearSRGBColorSpace,t}const P=45,M=45,I=3,T=1.5,L=1,x=.5;let k,U,D,$,_,N,j=!1;const O=0,F=300,q=2e3,G=.05,W=1/(32*Math.PI);let Q,V,K,z=!1,B=1,H=1,X=1;const Z=1;let Y;const J=new Map;function ee(t,n,o){const r=t.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,c,l,d,u,h,p,f=!1,m=!0,g=!1,v=!1,w=!1,y=0,b=0,R=1,L=1,N=1;const j={threeInit:()=>{f||(te(),i=new V.Scene,a=new V.PerspectiveCamera(25,1,.5),s=new Q.OrbitControls(a,t),s.enableInteraction(),({renderShadow:l,shadowGroup:c}=function(e){const t=new k.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new k.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new k.Group;o.position.y=-.7;const r=new k.PlaneGeometry(P,M).rotateX(Math.PI/2),i=new k.MeshBasicMaterial({map:t.texture,opacity:x,transparent:!0,depthWrite:!1}),a=new k.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new k.Mesh(r);s.visible=!1,o.add(s);const c=new k.OrthographicCamera(-P/2,P/2,M/2,-M/2,0,I);function l(e){s.visible=!0,$.uniforms.tDiffuse.value=t.texture,$.uniforms.h.value=1*e/256,s.material=$,U.setRenderTarget(n),U.render(s,c),_.uniforms.tDiffuse.value=n.texture,_.uniforms.v.value=1*e/256,s.material=_,U.setRenderTarget(t),U.render(s,c),s.visible=!1}return c.rotation.x=Math.PI/2,o.add(c),{shadowGroup:o,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=D;const o=U.getClearAlpha();U.setClearAlpha(0),U.setRenderTarget(t),U.render(e,c),e.overrideMaterial=null,l(T),l(.4*T),U.setRenderTarget(null),U.setClearAlpha(o),e.background=n}}}(i)),f=!0)},threeParse:(t,n,o)=>e(this,void 0,void 0,(function*(){return null!=d&&u===o||(yield d,d=(()=>e(this,void 0,void 0,(function*(){var e,o;return A=(e=Q).THREE,E=new e.RGBELoader,i.environment=C(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)}(Y,Q),o=t,S.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new V.Box3).setFromObject(e.scene);c.position.y=n.min.y-O,i.add(c),l(),i.traverse((e=>{if(e instanceof V.Mesh){const t=e.material;t.depthWrite=!0,t instanceof V.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}));const o=n.min.clone().add(n.max).divideScalar(2),r=Math.sqrt(Q.reduceVertices(e.scene,((e,t)=>Math.max(e,o.distanceToSquared(t))),0));s.reset(o,r,function(e,t){var n;const o={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?o.Glasses:null!==(n=o[e])&&void 0!==n?n:o.Glasses).normalize()}(t,V.Vector3)),w=!0},threePaused:()=>m,threeResume:()=>{m=!1,Y.setAnimationLoop(ne),t.style.visibility="visible",y=0,b=0},threePause:()=>{m=!0,function(){for(const{threePaused:e}of J.values())if(!e())return!1;return!0}()&&Y.setAnimationLoop(null),t.style.visibility="hidden",n.style.visibility="hidden"},threeSetToneMapping:e=>({ACES:V.ACESFilmicToneMapping,Linear:V.LinearToneMapping,Neutral:V.NeutralToneMapping}[e||"ACES"]||V.ACESFilmicToneMapping),threeSetOnInteracted:e=>{s.removeEventListener("change",h),h=e,s.addEventListener("change",e)},preRender_:e=>{if(!f||m)return;e=performance.now();const t=0!==b?e-b:0;if(b=e,!s.update()){if(v)return;if(w)return void(w=!1);if(null==p&&(p=()=>{w||(v=!0,n.style.visibility="hidden",null!=p&&(s.removeEventListener("change",p),p=null))},s.addEventListener("change",p)),y+=t,!(y>F&&y<=F+q))return o.style.opacity="0",void(y>F+2*q&&(y=0));{n.style.visibility="visible",o.style.opacity="1";const e=y-F,t=2*Math.PI/q*e,r=-Math.sin(t),i=Math.cos(t);o.style.transform=`translateX(${G*r*Math.min(R,L)}px)`,s.updateTheta(W*i)}}g=!0},shouldRender_:()=>!(!f||m)&&g,render_:()=>{const e=Y.toneMapping;Y.setViewport(0,0,t.width,t.height),Y.render(i,a),Y.toneMapping=e,g=!1,null!=r&&(r.clearRect(0,0,t.width,t.height),K.width>0&&K.height>0&&r.drawImage(K,0,H-t.height,t.width,t.height,0,0,t.width,t.height))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===R&&n===L&&X===N||(t.width=Math.ceil(e*X*Z),t.height=Math.ceil(n*X*Z),R=e,L=n,N=X,g=!0)},target_:t};return J.set(t,j),j}function te(){if(z)return;Q=window.ShopAR__THREE,V=Q.THREE,K=document.createElement("canvas");var e,t;K.style.position="block",Y=new V.WebGLRenderer({powerPreference:"high-performance",canvas:K,antialias:!0,alpha:!0}),Y.outputColorSpace=V.SRGBColorSpace,Y.toneMapping=V.ACESFilmicToneMapping,Y.setClearColor(new V.Color(16777215)),e=Y,t=Q,j||(k=t.THREE,U=e,D=new k.MeshDepthMaterial,D.userData.darkness={value:L},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 k.ShaderMaterial(t.HorizontalBlurShader),$.depthTest=!1,_=new k.ShaderMaterial(t.VerticalBlurShader),_.depthTest=!1,j=!0),oe(),z=!0}function ne(e){oe(),Y.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of J.values())t(e),n()&&o()}function oe(){let e=0,t=0;for(const{target_:n}of J.values()){const{clientWidth:o,clientHeight:r}=n;e=Math.max(e,o),t=Math.max(t,r)}const n=R();e=Math.ceil(e*n*Z),t=Math.ceil(t*n*Z),e===B&&t===H&&n===X||(B=e,H=t,X=n,Y.setSize(B,H,!1));for(const{updateSize_:e}of J.values())e()}const re={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},ie=Object.keys(re);function ae(e){return re[e]}const se="shopar-error";function ce(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}function le(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=ce("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=t,r.appendChild(e)}r.ariaLabel=n;return r.style.display="none",r}const de="shopar-control";const ue="shopar-deepar-output";function he(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 pe(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function fe(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 me(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 ge="shopar-main";const ve="shopar-qr-output";const we="shopar-three-output";var ye;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(ye||(ye={}));let be=!1;function Re(){be||(!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.")}}(),be=!0)}function Se(){Re();const e=function(){const e=document.createElement("div");e.id=ge;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}(),o=function(e,t){const n=document.createElement("div");n.id=ve;const o=n.style;o.position="absolute",o.top="0",o.left="0",o.width="100%",o.height="100%",o.display="none";const r=document.createElement("div");r.className="shopar-qr";const i=r.style;i.position="relative",i.top="0",i.left="0",i.width="100%",i.height="100%",n.appendChild(r),r.appendChild(e);const a=document.createElement("div");return a.appendChild(t),r.appendChild(a),n}(t,n);e.appendChild(o);const r=function(){const e=document.createElement("div");e.id=ue;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(r);const i=function(){const e=document.createElement("canvas");e.id=we;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}(),c=function(e,t){const n=document.createElement("div");n.className="shopar-ar-prompt";const{style:o}=n;return o.position="absolute",o.width="100%",o.height="100%",o.pointerEvents="none",o.opacity="0",n.appendChild(e),n.appendChild(t),n}(a,s);e.appendChild(c);const l=function(){const e=ce("2rem",`${w}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),d=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}(l);e.appendChild(d);const u=he("shopar-ar-loading-container"),h=pe("shopar-ar-loading-text",ae("loading.ar"));u.appendChild(h);const p=fe("shopar-ar-loading-bar-bg"),f=me("shopar-ar-loading-bar-fg");p.appendChild(f),u.appendChild(p),e.appendChild(u);const m=he("shopar-3d-loading-container"),g=pe("shopar-3d-loading-text",ae("loading.3d"));m.appendChild(g);const v=fe("shopar-3d-loading-bar-bg"),y=me("shopar-3d-loading-bar-fg");v.appendChild(y),m.appendChild(v),e.appendChild(m);const b=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),R=function(e){const t=document.createElement("div");t.id=se;const n=t.style;n.position="absolute",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div"),r=o.style;return r.position="absolute",r.width="100%",r.height="100%",r.backgroundColor="#ffffff",r.display="flex",r.flexDirection="column",r.justifyContent="center",r.alignItems="center",t.appendChild(o),o.appendChild(e),t}(b);e.appendChild(R);const S=function(){const e=document.createElement("div");return e.id=de,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(S);const A=le("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");S.appendChild(A);const E=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${w}/img/icons/cube.svg`);S.appendChild(E);const C=le("shopar-btn-close","Close","Close ShopAR view",`${w}/img/icons/close.svg`);S.append(C);let P,M=ye.None,I=!1,T=!1,L=!1,x=!1;function k(){f.classList.remove("active"),u.style.visibility="hidden"}function U(){y.classList.remove("active"),m.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return o},getQRImage:function(){return n},getDeepARTarget:function(){return r},getDeepARPrompt:function(){return c},getThreeTarget:function(){return i},getThreePrompt:function(){return d},getThreePromptImage:function(){return l},customizeDeepARPrompt:function(e,t){a.textContent=e,s.src=t},customizeCameraError:function(e){b.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,o,r){var i;I=e,T=t,L=n,x=o,P=r,Ae(S,I),Ae(A,I&&(L||T)&&M===ye.None),Ae(E,I&&x&&M===ye.None),Ae(C,I&&M!==ye.None),k(),U(),I||""===(i=R).style.display&&Ae(i,!1)},getUIState:function(){return M},setUIState:function(e){M=e,M===ye.None?(k(),U(),I&&(Ae(R,!1),Ae(C,!1),(T||L)&&Ae(A,!0),x&&Ae(E,!0))):M!==ye.QR&&M!==ye.AR&&M!==ye.Preview||I&&(Ae(R,!1),Ae(A,!1),Ae(E,!1),Ae(C,!0))},setDefaultUIActions:function(e,t,n){I&&((T||L)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${w}/img/icons/${n}`;A.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(P),A.onclick=e),x&&(E.onclick=t),C.onclick=n)},startDeepARLoading:function(){f.classList.add("active"),u.style.visibility="visible"},stopDeepARLoading:k,startThreeLoading:function(){y.classList.add("active"),m.style.visibility="visible"},stopThreeLoading:U,showCameraError:function(){I&&Ae(R,!0)}}}function Ae(e,t){e.style.display=t?"":"none"}const Ee=new Map;function Ce(t){let n=Ee.get(t);return null==n?(n=function(){let t=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Se()),n);return{getSetupId:()=>t,incrementSetupId_:()=>t++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:t,getQRImage:n}=i();o=function(t,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>e(this,void 0,void 0,(function*(){yield b;const e=`https://apps.deepar.ai/${g.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:r,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,o=!1,t.style.display=""})),qrPause:()=>e(this,void 0,void 0,(function*(){o=!0,t.style.display="none"}))}}(t(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();r=ee(e(),t(),n())}return r}}}(),Ee.set(t,n)):n.incrementSetupId_(),n}function Pe(e){for(const t of Ee.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===ye.AR&&r(ye.None)}}let Me;const Ie=new Uint8Array(16);function Te(){if(!Me&&(Me="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Me))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Me(Ie)}const Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));var xe={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ke(e,t,n){if(xe.randomUUID&&!t&&!e)return xe.randomUUID();const o=(e=e||{}).random||(e.rng||Te)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return Le[e[t+0]]+Le[e[t+1]]+Le[e[t+2]]+Le[e[t+3]]+"-"+Le[e[t+4]]+Le[e[t+5]]+"-"+Le[e[t+6]]+Le[e[t+7]]+"-"+Le[e[t+8]]+Le[e[t+9]]+"-"+Le[e[t+10]]+Le[e[t+11]]+Le[e[t+12]]+Le[e[t+13]]+Le[e[t+14]]+Le[e[t+15]]}(o)}const Ue="qrLaunch",De="arLaunch",$e="previewLaunch",_e="heartbeat";let Ne,je,Oe=!1;const Fe=[];function qe(){null==Ne&&(je=ke(),Ne=y(`${w}/shopar-analytics.js`),Ne.then((()=>{Oe=!0,window.ShopAR__analytics.initializeImpl(),Fe.forEach((e=>e()))})))}function Ge(e){Oe?e():Fe.push(e)}function We(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Qe(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 Ve=200,Ke=10;let ze=!1,Be=null,He=[],Xe=[];function Ze(t){return e(this,void 0,void 0,(function*(){ze=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${w}/wasm/mediapipe`,t),Be&&clearInterval(Be);const o=[],r=[];Be=setInterval((()=>e(this,void 0,void 0,(function*(){if(ze)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());ze||(null!=a&&null!=s&&function(e){for(let t of He)t(e)}({translation:a,rotation:s}),null==e&&(o.push(t),r.push(i),o.length<Ke||(o.shift(),r.shift(),function(e,t){for(let n of Xe)n({faceWidth:e,IPD:t})}(Je(o),Je(r)))))}))),Ve)}))}function Ye(){Xe=[],He=[],ze=!0}function Je(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}function et(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}var tt="undefined"!=typeof Float32Array?Float32Array:Array;function nt(){var e=new tt(16);return tt!=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 ot(e,t,n){var o=t[0],r=t[1],i=t[2],a=t[3],s=t[4],c=t[5],l=t[6],d=t[7],u=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],R=n[2],S=n[3];return e[0]=y*o+b*s+R*u+S*m,e[1]=y*r+b*c+R*h+S*g,e[2]=y*i+b*l+R*p+S*v,e[3]=y*a+b*d+R*f+S*w,y=n[4],b=n[5],R=n[6],S=n[7],e[4]=y*o+b*s+R*u+S*m,e[5]=y*r+b*c+R*h+S*g,e[6]=y*i+b*l+R*p+S*v,e[7]=y*a+b*d+R*f+S*w,y=n[8],b=n[9],R=n[10],S=n[11],e[8]=y*o+b*s+R*u+S*m,e[9]=y*r+b*c+R*h+S*g,e[10]=y*i+b*l+R*p+S*v,e[11]=y*a+b*d+R*f+S*w,y=n[12],b=n[13],R=n[14],S=n[15],e[12]=y*o+b*s+R*u+S*m,e[13]=y*r+b*c+R*h+S*g,e[14]=y*i+b*l+R*p+S*v,e[15]=y*a+b*d+R*f+S*w,e}function rt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function it(e,t){var n=t[0],o=t[1],r=t[2],i=t[4],a=t[5],s=t[6],c=t[8],l=t[9],d=t[10];return e[0]=Math.hypot(n,o,r),e[1]=Math.hypot(i,a,s),e[2]=Math.hypot(c,l,d),e}function at(e,t,n,o){var r=t[0],i=t[1],a=t[2],s=t[3],c=r+r,l=i+i,d=a+a,u=r*c,h=r*l,p=r*d,f=i*l,m=i*d,g=a*d,v=s*c,w=s*l,y=s*d,b=o[0],R=o[1],S=o[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)*R,e[5]=(1-(u+g))*R,e[6]=(m+v)*R,e[7]=0,e[8]=(p+w)*S,e[9]=(m-v)*S,e[10]=(1-(u+f))*S,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function st(){var e=new tt(3);return tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function ct(e,t,n){var o=new tt(3);return o[0]=e,o[1]=t,o[2]=n,o}function lt(e,t){var n=t[0]-e[0],o=t[1]-e[1],r=t[2]-e[2];return Math.hypot(n,o,r)}function dt(e,t,n){var o=t[0],r=t[1],i=t[2],a=n[3]*o+n[7]*r+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*o+n[4]*r+n[8]*i+n[12])/a,e[1]=(n[1]*o+n[5]*r+n[9]*i+n[13])/a,e[2]=(n[2]*o+n[6]*r+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 ut(){var e=new tt(4);return tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}st(),function(){var e,t=(e=new tt(4),tt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var ht;let pt,ft,mt;st(),ct(1,0,0),ct(0,1,0),ut(),ut(),ht=new tt(9),tt!=Float32Array&&(ht[1]=0,ht[2]=0,ht[3]=0,ht[5]=0,ht[6]=0,ht[7]=0),ht[0]=1,ht[4]=1,ht[8]=1;let gt,vt,wt,yt,bt=!0,Rt=null;const St=new Set;let At,Et,Ct,Pt,Mt,It,Tt;function Lt(){null==pt&&(pt=y(`${w}/shopar-deepar.js`))}function xt(){null==ft&&(ft=y(`${w}/shopar-true-scale.js`))}function kt(n){return e(this,void 0,void 0,(function*(){const{licenseKey:o,truescaleUsecase:r}=n;return Mt=r,null==At&&(At=(()=>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=Ft(wt),r=We(n);gt=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:o||"your_license_key_goes_here",previewElement:yt,additionalOptions:{hint:It,cameraConfig:{disableDefaultCamera:!0}}}),vt=yield Qe(r),yield qt(gt,vt,"user"===n),"Glasses"===wt&&(yield ft,Ze(vt),"DetectionLoop"!==Mt&&Vt((e=>{Pt=e.faceWidth})))})))()),At}))}function Ut(e,t){var n,o;(t=null!=t?t:function(e){const t={Glasses:["rigidFaceTrackingInit","faceInit"],Shoes:["footInit"],Watches:["wristInit"]};return null==e?void 0:t[e]}(e),e===wt&&(n=t,o=It,n===o||null!=n&&null!=o&&n.length===o.length&&n.every((e=>o.find((t=>e===t))))&&o.every((e=>n.find((t=>t===e))))))||(null!=gt&&(gt.shutdown(),gt=null,At=null),wt=e,It=t)}function Dt(e){e!==yt&&(yt=e,null!=gt&>.changePreviewElement(yt))}function $t(e){Rt=e}function _t(e){gt.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(Pt){const e=137/(Pt+5);gt.changeParameterVector("GLASSES","","scale",e,e,e,0),gt.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 o=Wt("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),r=Wt("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);gt.changeParameterVector("temple_left","","rotation",0,56.6*-o,0,0),gt.changeParameterVector("temple_right","","rotation",0,56.6*-r,0,0)}catch(e){return}}(e),Ye(),Pt=null}e(),Gt("Glasses")}},gt.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Gt("Shoes"))},gt.callbacks.onWristTracked=t=>{t.detected&&(e(),Gt("Watches"))}}function Nt(t,n){return e(this,void 0,void 0,(function*(){return null!=Et&&Ct===n||(yield Et,Et=gt.switchEffect(t),Ct=n),Et}))}function jt(){return e(this,void 0,void 0,(function*(){if(null!=gt){if(bt=!1,null==vt){const e=Ft(wt),t=We(e);vt=yield Qe(t),yield qt(gt,vt,"user"===e),Ze(vt),"DetectionLoop"!==Mt&&Vt((e=>{Pt=e.faceWidth}))}!function(){if(null==Rt)return;if(null==wt||St.has(wt))return;Rt.style.visibility="visible",Rt.style.opacity="1"}(),gt.setPaused(bt),yt.style.display=""}}))}function Ot(){null!=gt&&(bt=!0,gt.setPaused(bt),Ye(),null!=vt&&null!=vt.srcObject&&vt.srcObject instanceof MediaStream&&(vt.srcObject.getTracks().forEach((e=>e.stop())),vt=null),function(){if(null==Rt)return;Rt.style.visibility="hidden",Rt.style.opacity="0"}(),gt.stopCamera(),yt.style.display="none")}function Ft(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function qt(t,n,o){return e(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>e(this,void 0,void 0,(function*(){t.setVideoElement(n,o),r()}))))}}))}))}function Gt(e){null!=Rt&&(St.has(e)||(St.add(e),Rt.style.opacity="0"))}function Wt(e,t,n,o,r,i,a){const s=gt.getTransformationBetween(e,t),c=rt(st(),s),l=function(e,t){var n=new tt(3);it(n,t);var o=1/n[0],r=1/n[1],i=1/n[2],a=t[0]*o,s=t[1]*r,c=t[2]*i,l=t[4]*o,d=t[5]*r,u=t[6]*i,h=t[8]*o,p=t[9]*r,f=t[10]*i,m=a+d+f,g=0;return m>0?(g=2*Math.sqrt(m+1),e[3]=.25*g,e[0]=(u-p)/g,e[1]=(h-c)/g,e[2]=(s-l)/g):a>d&&a>f?(g=2*Math.sqrt(1+a-d-f),e[3]=(u-p)/g,e[0]=.25*g,e[1]=(s+l)/g,e[2]=(h+c)/g):d>f?(g=2*Math.sqrt(1+d-a-f),e[3]=(h-c)/g,e[0]=(s+l)/g,e[1]=.25*g,e[2]=(u+p)/g):(g=2*Math.sqrt(1+f-a-d),e[3]=(s-l)/g,e[0]=(h+c)/g,e[1]=(u+p)/g,e[2]=.25*g),e}(ut(),s);at(s,l,c,ct(a,a,a));const d=gt.getTransformationBetween(t,n),u=rt(st(),d);at(d,ut(),u,it(st(),d));const h=ot(nt(),s,d),p=rt(st(),h),f=Math.atan2(i[0]-p[0],Math.abs(i[2]-p[2]));let m;try{m=gt.getTransformationBetween(n,o)}catch(e){return f}const g=ot(nt(),d,m),v=ot(nt(),s,g),w=ct(p[0],i[1],i[2]),y=dt(st(),w,function(e,t){var n=t[0],o=t[1],r=t[2],i=t[3],a=t[4],s=t[5],c=t[6],l=t[7],d=t[8],u=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15],w=n*s-o*a,y=n*c-r*a,b=n*l-i*a,R=o*c-r*s,S=o*l-i*s,A=r*l-i*c,E=d*m-u*f,C=d*g-h*f,P=d*v-p*f,M=u*g-h*m,I=u*v-p*m,T=h*v-p*g,L=w*T-y*I+b*M+R*P-S*C+A*E;return L?(L=1/L,e[0]=(s*T-c*I+l*M)*L,e[1]=(r*I-o*T-i*M)*L,e[2]=(m*A-g*S+v*R)*L,e[3]=(h*S-u*A-p*R)*L,e[4]=(c*P-a*T-l*C)*L,e[5]=(n*T-r*P+i*C)*L,e[6]=(g*b-f*A-v*y)*L,e[7]=(d*A-h*b+p*y)*L,e[8]=(a*I-s*P+l*E)*L,e[9]=(o*P-n*I-i*E)*L,e[10]=(f*S-m*b+v*w)*L,e[11]=(u*b-d*S-p*w)*L,e[12]=(s*C-a*M-c*E)*L,e[13]=(n*M-o*C+r*E)*L,e[14]=(m*y-f*R-g*w)*L,e[15]=(d*R-u*y+h*w)*L,e):null}(nt(),v));let b=gt.getClosestPointOnMesh(o,y);try{const e=gt.getClosestPointOnMesh(r,y);lt(y,e)<lt(y,b)&&(b=e)}catch(e){}const R=dt(st(),b,g);return f-Math.atan2(R[0]-u[0],Math.abs(R[2]-u[2]))}function Qt(e){!function(e){He.push(e)}(e)}function Vt(e){!function(e){Xe.push(e)}(e)}function Kt(o,r,i){return e(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const d=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const f=String.fromCharCode(a-7),m=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],g=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield m(`${o}`).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(l[c]=Math.min(76,r)*((a>>5)-1),152===l[c]&&(l[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)l[c]^=l[i]<<13,l[c]^=l[i]>>17,l[c]^=l[i]<<5,v[e]=v[e]^l[c];return i^=l[0],i^=l[1],i^=l[2],v}))}function zt(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Bt(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const Ht=["AR","3D"];function Xt(e){const{apiKey:n,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:c}=e;zt(n,"apiKey"),Bt(n,"apiKey"),zt(o,"sku"),Bt(o,"sku"),zt(r,"targetElement"),function(e,n){if(!(e instanceof HTMLElement))throw new t(`'${n}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,n,o){if("string"!=typeof e)throw new t(`'${n}' must be a string.`);if(!o.includes(e))throw new t(`'${n}' must be ${o.join("' or '")}.`)}(i,"initialState",Ht),null!=a&&Bt(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI"),null!=c&&function(e,n,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new t(`Value for key '${r}' in '${n}' must be a string.`)}}(c,"strings",ie)}let Zt=!1;function Yt(n){return e(this,void 0,void 0,(function*(){const{targetElement:o}=n;w.update(n.baseUrl),qe();const{trackEvent:r}=function(e){const t=performance.now(),n=ke();return{trackEvent:(o,r={})=>{r=Object.assign(Object.assign({},r),{pluginVersion:g,sessionId:je,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),Ge((()=>{window.ShopAR__analytics.trackEventImpl(o,r)}))}}}(n.apiKey);r("visionSetup");const i=yield function(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin/vision?${new URLSearchParams({apiKey:n,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield o.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(n.apiKey);r("visionApiResponse",i);const{arKey:a}=i,s=Ce(o),{getSetupId:c,findUI:l}=s,u=c();Lt(),xt();const{setTargetElement:h,getDeepARTarget:f,setVisibilityParameters:m,getUIState:v,setUIState:y,startDeepARLoading:b,stopDeepARLoading:R,showCameraError:S}=l();if(v()!=ye.None)throw Error("UI state is not None, this is weird..");y(ye.AR),h(o),m(!1,!1,!0,!1,void 0),b(),yield pt,Jt(c(),u);try{r("visionArLaunch"),Ot(),Ut("Glasses",["faceInit"]),Dt(f()),yield kt({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Jt(c(),u),yield jt(),Jt(c(),u)}catch(e){const n=e instanceof Error;throw r("visionArLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),S(),Ot(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{R()}return Zt=!0,{registerFacePoseListener:e=>{Zt&&(r("registerFacePoseListener"),Qt(e))},registerFaceMeasurementListener:e=>{Zt&&(r("registerFaceMeasurementListener"),Vt(e))},switchEffect:t=>e(this,void 0,void 0,(function*(){Zt&&(r("switchEffect",{arUrl:t}),function(e){gt.switchEffect(e)}(t))})),clearEffect:()=>{Zt&&(r("clearEffect"),gt.clearEffect())},close:()=>{if(Zt){if(Zt=!1,r("visionClose"),v()!==ye.AR)throw new t("AR not launched.");Ot(),y(ye.None)}}}}))}function Jt(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}function en(n){var o,r;return e(this,void 0,void 0,(function*(){Xt(n);const{apiKey:i,sku:a,targetElement:s,initialState: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),w.update(n.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(re,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(re[t]=n)}}(n.strings);const l=function(n,o){return e(this,void 0,void 0,(function*(){const r=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:n,sku:o,sid:d()})}`).catch((e=>{throw console.error(e),new t("API unavailable.")}));if(!e.ok)throw new t(`API call failed with status ${e.status}.`);return e}))));try{return yield r.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(i,a),u=Ce(s),{getSetupId:h,findUI:v,findQR:R,findThree:S}=u,A=h();qe();const{trackEvent:E,arInteracted:C,previewInteracted:P}=function(e,t){const n=performance.now(),o=ke();let r=0,i=0,a=0,s=0,c=0,l=!1;window.setInterval((()=>{l&&(r=i+a,l=!1,d(_e,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{i=Object.assign(Object.assign({},i),{pluginVersion:g,sessionId:je,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),Ge((()=>{window.ShopAR__analytics.trackEventImpl(r,i)}))};return{trackEvent:d,arInteracted:()=>{const e=performance.now(),t=e-s;s=e,t<200&&(i+=t,l=!0)},previewInteracted:()=>{const e=performance.now(),t=e-c;c=e,t<200&&(a+=t,l=!0)}}}(a,i);E("setup",{hostname:window.location.hostname});const M=yield l;E("apiResponse",M);const{category:I,arUrl:T,arKey:L,arPromptEnabled:x,arPromptText:k,arPromptImage:U,previewUrl:D,previewEnvUrl:$,previewToneMapping:_,cameraErrorText:j,qrPromptText:O}=M;tn(h(),A);const F=null!=T&&function(e){return null!=e&&f.includes(e)}(I),q=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled),G=F&&function(e){return null!=e&&m.includes(e)}(I),W=q&&G&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==Tt&&(Tt=y(`${w}/shopar-platform.js`)),yield Tt,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}()),Q=F&&!W,V=null!=D;if(tn(h(),A),W&&function(){e(this,void 0,void 0,(function*(){null==b&&(b=y(`${w}/shopar-qr.js`))}))}(),Q&&(Lt(),function(e){e!==mt&&(mt=e,et(e),Et=null,Ye())}(T),"Glasses"===I&&xt()),V){null==N&&(N=y(`${w}/shopar-three.js`));const e=255;Kt(D,(new Date).getTime()+e,Math.random()*e),et(null!=$?$:`${w}/env/default.hdr`)}const{setTargetElement:K,getDeepARTarget:z,getDeepARPrompt:B,customizeDeepARPrompt:H,customizeCameraError:X,customizeQRPrompt:Z,setVisibilityParameters:Y,getUIState:J,setUIState:ee,setDefaultUIActions:te,startDeepARLoading:ne,stopDeepARLoading:oe,startThreeLoading:ie,stopThreeLoading:ae,showCameraError:se}=v();K(s);Y(null==n.defaultUI||n.defaultUI,W,Q,V,I),H(null!=k?k:"",null!=U?U:""),X(j),Z(O),function(e,n){const o=e.parentNode;if(null==o)throw new t("Parent node missing.");new MutationObserver((t=>{for(const o of t)for(const t of o.removedNodes)if(t===e)return void n()})).observe(o,{childList:!0})}(s,(()=>{J()!==ye.QR||ce()||de(),J()!==ye.AR||bt||Ot(),J()!==ye.Preview||fe()||ge(),ee(ye.None)}));const{qrPaused:ce,qrDraw:le,qrPause:de}=R(),{threeInit:ue,threeParse:he,threeLoad:pe,threePaused:fe,threeResume:me,threePause:ge,threeSetToneMapping:ve,threeSetOnInteracted:we}=S();let be=0;if(J()===ye.QR){if(!ce())if(W){E(Ue);try{yield le(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else de(),ee(ye.None)}else if(J()===ye.AR){if(!bt)if(Q&&!Zt){E(De);const e=yield et(T);tn(h(),A),Pe(u),Ut(I),Dt(z()),$t(x?B():null),yield Nt(e,T),_t(C),tn(h(),A)}else Ot(),ee(ye.None)}else if(J()===ye.Preview&&!fe())if(V){E($e),ie();const e=255,t=yield Kt(D,(new Date).getTime()+e,Math.random()*e);tn(h(),A);const n=yield et(null!=$?$:`${w}/env/default.hdr`);tn(h(),A);const o=yield he(t,n,`${D}${$}`);tn(h(),A),pe(o,I),ve(null!=_?_:"ACES"),we(P),ae()}else ge(),ee(ye.None);const Re=()=>e(this,void 0,void 0,(function*(){if(W){if(J()===ye.QR||J()===ye.AR)throw new t("AR already launched.");try{E(Ue);const e=++be;if(J()===ye.Preview&&V&&!fe()&&ge(),ee(ye.QR),yield le(i,a),be!==e)return;return void tn(h(),A)}catch(e){const n=e instanceof Error;throw E("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!Q)throw new t("Model does not have AR enabled.");if(J()===ye.AR)throw new t("AR already launched.");try{E(De);const e=++be;J()===ye.Preview&&V&&!fe()&&ge(),Pe(u),ee(ye.AR),ne();const t=yield et(T);if(be!==e)return;if(tn(h(),A),yield pt,be!==e)return;if(tn(h(),A),Ot(),Ut(I),Dt(z()),$t(x?B():null),yield kt({licenseKey:L}),be!==e)return;if(tn(h(),A),yield Nt(t,T),_t(C),be!==e)return;if(tn(h(),A),yield jt(),be!==e)return;tn(h(),A)}catch(e){const n=e instanceof Error;throw E("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),se(),Ot(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{oe()}})),Se=()=>e(this,void 0,void 0,(function*(){if(!V)throw new t("Model does not have 3D enabled.");if(J()===ye.Preview)throw new t("3D already launched.");try{E($e);const e=++be;J()===ye.AR&&(Q&&!bt&&Ot(),de()),ee(ye.Preview),ie();const t=255,n=yield Kt(D,(new Date).getTime()+t,Math.random()*t);if(be!==e)return;tn(h(),A);const o=yield et(null!=$?$:`${w}/env/default.hdr`);if(be!==e)return;if(tn(h(),A),yield N,be!==e)return;if(tn(h(),A),ue(),be!==e)return;tn(h(),A);const r=yield he(n,o,`${D}${$}`);if(be!==e)return;tn(h(),A),pe(r,I),ve(null!=_?_:"ACES"),we(P),me()}catch(e){const n=e instanceof Error;throw E("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{ae()}})),Ae=()=>e(this,void 0,void 0,(function*(){if(J()===ye.None)throw new t("Neither AR or 3D launched.");++be,J()===ye.QR||J()===ye.AR?(Q&&!bt&&Ot(),de()):J()===ye.Preview&&V&&!fe()&&ge(),ee(ye.None)}));return te(Re,Se,Ae),"AR"===c?(yield Re(),tn(h(),A)):"3D"===c&&(yield Se(),tn(h(),A)),Zt=!1,{launchAR:F?Re:void 0,launch3D:V?Se:void 0,closeAR:F?()=>e(this,void 0,void 0,(function*(){if(J()!==ye.AR&&J()!==ye.QR)throw new t("AR not launched.");++be,Q&&!bt&&Ot(),de(),ee(ye.None)})):void 0,close3D:V?()=>e(this,void 0,void 0,(function*(){if(J()!==ye.Preview)throw new t("3D not launched.");++be,V&&!fe()&&ge(),ee(ye.None)})):void 0,close:F||V?Ae:void 0}}))}function tn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const nn={setup:function(t){return e(this,void 0,void 0,(function*(){return Yt(t)}))}},on={setup:function(n){return e(this,void 0,void 0,(function*(){return function(n,o){return e(this,void 0,void 0,(function*(){try{return o()}catch(e){throw e instanceof Error?new t(`${n} failed: ${e.message}`):(console.error(e),new t(`${n} failed.`))}}))}("setup",(()=>en(n)))}))},version:g};export{on as plugin,nn 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}"};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 f(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]))),f(t,n+1)}}))}const p=["Glasses","Shoes","Watches"],m=["Shoes"];const g="0.1.3-alpha.2";let v=`https://cdn.jsdelivr.net/npm/shopar-plugin@${g}/dist`;const w={update:e=>{null!=e&&(v=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>v};function y(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}let b;const E=(()=>{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 A,R,S;function C(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}(S.parse(e));return t.mapping=R.EquirectangularReflectionMapping,t.colorSpace=R.LinearSRGBColorSpace,t}const I=45,P=45,x=3,M=1.5,k=1,T=.5;let L,U,$,D,_,N=!1;const j=4,O=.001,F=1e-7,W=10,q=11,G=1/(q-1),z="function"==typeof Float32Array;function Q(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 Z;const o=z?new Float32Array(q):new Array(q);for(let t=0;t<q;++t)o[t]=H(t*G,e,n);function i(t){let r=0,i=1;const a=q-1;for(;i!==a&&o[i]<=t;++i)r+=G;--i;const s=r+(t-o[i])/(o[i+1]-o[i])*G,l=X(s,e,n);return l>=O?function(e,t,n,r){for(let o=0;o<j;++o){const o=X(t,n,r);if(0===o)return t;t-=(H(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=H(a,r,o)-e,i>0?n=a:t=a}while(Math.abs(i)>F&&++s<W);return a}(t,r,r+G,e,n)}return function(e){return 0===e||1===e?e:H(i(e),t,r)}}function V(e,t){return 1-3*t+3*e}function K(e,t){return 3*t-6*e}function B(e){return 3*e}function H(e,t,n){return((V(t,n)*e+K(t,n))*e+B(t))*e}function X(e,t,n){return 3*V(t,n)*e*e+2*K(t,n)*e+B(t)}function Z(e){return e}function Y(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=Q(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function J(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:Y(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 ee="#",te="time",ne="interpolation",re="yaw",oe="pitch",ie="fov",ae=[te,re,oe,ie,ne],se="s",le="ms",ce=1e3,ue="deg",de="rad",he=Math.PI/180,fe="ease-in-out",pe="cubic-bezier(",me=")";function ge(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(ee);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(!ae.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(te))throw new Error(`Missing required token: '${te}'.`);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}=ve(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=ye(null!==(t=r.interpolation)&&void 0!==t?t:fe);null!=i&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:i*he,interpolation:s})),null!=o&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:o*he,interpolation:s})),null!=a&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:a*he,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 ve(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(te),o=function(e){if(e.endsWith(le))return Ee(e.substring(0,e.length-le.length));if(e.endsWith(se))return Ee(e.substring(0,e.length-se.length))*ce;return Ee(e)}(n[r]),i=e.indexOf(ne),a=ye(-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 re:s.theta={time:o,value:we(c),interpolation:a};break;case oe:s.phi={time:o,value:we(c),interpolation:a};break;case ie:s.fov={time:o,value:we(c),interpolation:a};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function we(e){return e.endsWith(ue)?Ee(e.substring(0,e.length-ue.length))*he:e.endsWith(de)?Ee(e.substring(0,e.length-de.length)):Ee(e)*he}function ye(e){if("hold"===e)return{type:"hold"};if("linear"===e)return be(0,0,1,1);if("sine"===e)return be(.37,0,.63,1);if("sine-in"===e)return be(.12,0,.39,0);if("sine-out"===e)return be(.61,1,.88,1);if("ease"===e)return be(.25,.1,.25,1);if("ease-in"===e)return be(.42,0,1,1);if("ease-out"===e)return be(0,0,.58,1);if("ease-in-out"===e)return be(.42,0,.58,1);if(e.startsWith(pe)&&e.endsWith(me)){const t=e.substring(pe.length,e.length-me.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:Ee(t[0]),y1:Ee(t[1]),x2:Ee(t[2]),y2:Ee(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function be(e,t,n,r){return{type:"bezier",x1:e,y1:t,x2:n,y2:r}}function Ee(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}const Ae=300,Re=2e3,Se=.05,Ce=2*Math.PI/32,Ie=ye("hold"),Pe=ye("sine"),xe=ye("sine-in"),Me=ye("sine-out");let ke;const Te=0;let Le,Ue,$e,De=!1,_e=1,Ne=1,je=1;const Oe=1;let Fe;const We=new Map;function qe(t,n,r){const o=t.getContext("2d");null==o&&console.warn("2D context missing.");let i,a,s,l,c,u,d,h,f,p,m,g,v,w=!1,y=!0,b=!1,E=!0,k=!1,N=!1,j=0,O=1,F=1,W=1;const q={threeInit:()=>{w||(Ge(),i=new Ue.Scene,a=new Ue.PerspectiveCamera(25,1,.5),s=new Le.OrbitControls(a,t),s.setInteractionEnabled(E),({renderShadow:c,shadowGroup:l}=function(e){const t=new L.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new L.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const r=new L.Group;r.position.y=-.7;const o=new L.PlaneGeometry(I,P).rotateX(Math.PI/2),i=new L.MeshBasicMaterial({map:t.texture,opacity:T,transparent:!0,depthWrite:!1}),a=new L.Mesh(o,i);a.renderOrder=1,a.scale.y=-1,r.add(a);const s=new L.Mesh(o);s.visible=!1,r.add(s);const l=new L.OrthographicCamera(-I/2,I/2,P/2,-P/2,0,x);function c(e){s.visible=!0,D.uniforms.tDiffuse.value=t.texture,D.uniforms.h.value=1*e/256,s.material=D,U.setRenderTarget(n),U.render(s,l),_.uniforms.tDiffuse.value=n.texture,_.uniforms.v.value=1*e/256,s.material=_,U.setRenderTarget(t),U.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=U.getClearAlpha();U.setClearAlpha(0),U.setRenderTarget(t),U.render(e,l),e.overrideMaterial=null,c(M),c(.4*M),U.setRenderTarget(null),U.setClearAlpha(r),e.background=n}}}(i)),w=!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=Le).THREE,S=new e.RGBELoader,i.environment=C(n),function(e,t){const{THREE:n}=t;A=(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)}(Fe,Le),r=t,A.parseAsync(r.buffer,"")})))(),d=r),u})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new Ue.Box3).setFromObject(e.scene);l.position.y=n.min.y-Te,i.add(l),c(),i.traverse((e=>{if(e instanceof Ue.Mesh){const t=e.material;t.depthWrite=!0,t instanceof Ue.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}));const r=n.min.clone().add(n.max).divideScalar(2),o=Math.sqrt(Le.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,Ue.Vector3)),N=!0},threePaused:()=>y,threeResume:()=>{y=!1,Fe.setAnimationLoop(ze),t.style.visibility="visible",j=0,null==f||f.reset(),null==p||p.reset(),null==m||m.reset(),null==g||g.reset(),null==v||v.reset()},threePause:()=>{y=!0,function(){for(const{threePaused:e}of We.values())if(!e())return!1;return!0}()&&Fe.setAnimationLoop(null),t.style.visibility="hidden",n.style.visibility="hidden"},threeSetToneMapping:e=>({ACES:Ue.ACESFilmicToneMapping,Linear:Ue.LinearToneMapping,Neutral:Ue.NeutralToneMapping}[e||"ACES"]||Ue.ACESFilmicToneMapping),threeIsInteractive:()=>E,threeSetInteractive:e=>{E=e,null==s||s.setInteractionEnabled(E)},threeSetOnInteracted:e=>{s.removeEventListener("change",h),h=e,s.addEventListener("change",e)},threeInitPromptAnimation:()=>{var e;e=s.getTheta(),f=J([{time:0,value:e,interpolation:Ie},{time:Ae,value:e,interpolation:Me},{time:Ae+Re/4,value:e+Ce,interpolation:Pe},{time:Ae+3*Re/4,value:e-Ce,interpolation:xe},{time:Ae+Re,value:e,interpolation:Ie},{time:Ae+2*Re,value:e,interpolation:Ie}]),p=null,m=null,g=J([{time:0,value:0,interpolation:Ie},{time:Ae,value:1,interpolation:Ie},{time:Ae+Re,value:0,interpolation:Ie},{time:Ae+2*Re,value:0,interpolation:Ie}]),v=J([{time:0,value:0,interpolation:Ie},{time:Ae,value:0,interpolation:Me},{time:Ae+Re/4,value:-Se,interpolation:Pe},{time:Ae+3*Re/4,value:Se,interpolation:xe},{time:Ae+Re,value:0,interpolation:Ie},{time:Ae+2*Re,value:0,interpolation:Ie}])},threeInitCameraAnimation:e=>{const{theta:t,phi:n,fov:r}=e;f=null!=t?J(t):null,p=null!=n?J(n):null,m=null!=r?J(r):null},preRender_:e=>{if(!w||y)return;e=performance.now();const t=0!==j?e-j:0;j=e,N&&(b=!0,N=!1),k||(s.hasUserInteracted()?(k=!0,f=null,p=null,m=null,g=null,v=null):(null==f||f.update(t),null==p||p.update(t),null==m||m.update(t),null==g||g.update(t),null==v||v.update(t),null!=f&&(s.setTheta(f.get()),b=!0),null!=p&&(s.setPhi(p.get()),b=!0),null!=m&&(s.setFovRadians(m.get()),b=!0))),s.update()&&(b=!0)},shouldRender_:()=>!(!w||y)&&b,render_:()=>{const e=Fe.toneMapping;Fe.setViewport(0,0,t.width,t.height),Fe.render(i,a),Fe.toneMapping=e,b=!1,null!=o&&(o.clearRect(0,0,t.width,t.height),$e.width>0&&$e.height>0&&o.drawImage($e,0,Ne-t.height,t.width,t.height,0,0,t.width,t.height),n.style.visibility=E&&!k?"visible":"hidden",null!=g&&(r.style.opacity=`${g.get()}`),null!=v&&(r.style.transform=`translateX(${v.get()*Math.min(O,F)}px)`))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===O&&n===F&&je===W||(t.width=Math.ceil(e*je*Oe),t.height=Math.ceil(n*je*Oe),O=e,F=n,W=je,b=!0)},target_:t};return We.set(t,q),q}function Ge(){if(De)return;Le=window.ShopAR__THREE,Ue=Le.THREE,$e=document.createElement("canvas");var e,t;$e.style.position="block",Fe=new Ue.WebGLRenderer({powerPreference:"high-performance",canvas:$e,antialias:!0,alpha:!0}),Fe.outputColorSpace=Ue.SRGBColorSpace,Fe.toneMapping=Ue.ACESFilmicToneMapping,Fe.setClearColor(new Ue.Color(16777215)),e=Fe,t=Le,N||(L=t.THREE,U=e,$=new L.MeshDepthMaterial,$.userData.darkness={value:k},$.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,D=new L.ShaderMaterial(t.HorizontalBlurShader),D.depthTest=!1,_=new L.ShaderMaterial(t.VerticalBlurShader),_.depthTest=!1,N=!0),Qe(),De=!0}function ze(e){Qe(),Fe.clear();for(const{preRender_:t,shouldRender_:n,render_:r}of We.values())t(e),n()&&r()}function Qe(){let e=0,t=0;for(const{target_:n}of We.values()){const{clientWidth:r,clientHeight:o}=n;e=Math.max(e,r),t=Math.max(t,o)}const n=E();e=Math.ceil(e*n*Oe),t=Math.ceil(t*n*Oe),e===_e&&t===Ne&&n===je||(_e=e,Ne=t,je=n,Fe.setSize(_e,Ne,!1));for(const{updateSize_:e}of We.values())e()}const Ve={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},Ke=Object.keys(Ve);function Be(e){return Ve[e]}const He="shopar-error";function Xe(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 Ze(e,t,n,r){const o=document.createElement("button");o.id=e,o.type="button",o.className="shopar-btn";{const e=Xe("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 Ye="shopar-control";const Je="shopar-deepar-output";function et(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 tt(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function nt(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 rt(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 ot="shopar-main";const it="shopar-qr-output";const at="shopar-three-output";var st;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(st||(st={}));let lt=!1;function ct(){lt||(!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.")}}(),lt=!0)}function ut(){ct();const e=function(){const e=document.createElement("div");e.id=ot;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=it;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=Je;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=at;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=Xe("2rem",`${w}/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=et("shopar-ar-loading-container"),h=tt("shopar-ar-loading-text",Be("loading.ar"));d.appendChild(h);const f=nt("shopar-ar-loading-bar-bg"),p=rt("shopar-ar-loading-bar-fg");f.appendChild(p),d.appendChild(f),e.appendChild(d);const m=et("shopar-3d-loading-container"),g=tt("shopar-3d-loading-text",Be("loading.3d"));m.appendChild(g);const v=nt("shopar-3d-loading-bar-bg"),y=rt("shopar-3d-loading-bar-fg");v.appendChild(y),m.appendChild(v),e.appendChild(m);const b=function(){const e=document.createElement("div");return e.className="shopar-error-text",e.style.textAlign="center",e}(),E=function(e){const t=document.createElement("div");t.id=He;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}(b);e.appendChild(E);const A=function(){const e=document.createElement("div");return e.id=Ye,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(A);const R=Ze("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");A.appendChild(R);const S=Ze("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${w}/img/icons/cube.svg`);A.appendChild(S);const C=Ze("shopar-btn-close","Close","Close ShopAR view",`${w}/img/icons/close.svg`);A.append(C);let I,P=st.None,x=!1,M=!1,k=!1,T=!1;function L(){p.classList.remove("active"),d.style.visibility="hidden"}function U(){y.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){b.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;x=e,M=t,k=n,T=r,I=o,dt(A,x),dt(R,x&&(k||M)&&P===st.None),dt(S,x&&T&&P===st.None),dt(C,x&&P!==st.None),L(),U(),x||""===(i=E).style.display&&dt(i,!1)},getUIState:function(){return P},setUIState:function(e){P=e,P===st.None?(L(),U(),x&&(dt(E,!1),dt(C,!1),(M||k)&&dt(R,!0),T&&dt(S,!0))):P!==st.QR&&P!==st.AR&&P!==st.Preview||x&&(dt(E,!1),dt(R,!1),dt(S,!1),dt(C,!0))},setDefaultUIActions:function(e,t,n){x&&((M||k)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,r=`${w}/img/icons/${n}`;R.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",r)}(I),R.onclick=e),T&&(S.onclick=t),C.onclick=n)},startDeepARLoading:function(){p.classList.add("active"),d.style.visibility="visible"},stopDeepARLoading:L,startThreeLoading:function(){y.classList.add("active"),m.style.visibility="visible"},stopThreeLoading:U,showCameraError:function(){x&&dt(E,!0)}}}function dt(e,t){e.style.display=t?"":"none"}const ht=new Map;function ft(t){let n=ht.get(t);return null==n?(n=function(){let t=0,n=null,r=null,o=null;const i=()=>(null==n&&(n=ut()),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 b;const e=`https://apps.deepar.ai/${g.includes("alpha")?"shopar-qr-alpha":"shopar-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=qe(e(),t(),n())}return o}}}(),ht.set(t,n)):n.incrementSetupId_(),n}function pt(e){for(const t of ht.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:r,setUIState:o}=n;r()===st.AR&&o(st.None)}}let mt;const gt=new Uint8Array(16);function vt(){if(!mt&&(mt="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!mt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return mt(gt)}const wt=[];for(let e=0;e<256;++e)wt.push((e+256).toString(16).slice(1));var yt={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function bt(e,t,n){if(yt.randomUUID&&!t&&!e)return yt.randomUUID();const r=(e=e||{}).random||(e.rng||vt)();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 wt[e[t+0]]+wt[e[t+1]]+wt[e[t+2]]+wt[e[t+3]]+"-"+wt[e[t+4]]+wt[e[t+5]]+"-"+wt[e[t+6]]+wt[e[t+7]]+"-"+wt[e[t+8]]+wt[e[t+9]]+"-"+wt[e[t+10]]+wt[e[t+11]]+wt[e[t+12]]+wt[e[t+13]]+wt[e[t+14]]+wt[e[t+15]]}(r)}const Et="qrLaunch",At="arLaunch",Rt="previewLaunch",St="heartbeat";let Ct,It,Pt=!1;const xt=[];function Mt(){null==Ct&&(It=bt(),Ct=y(`${w}/shopar-analytics.js`),Ct.then((()=>{Pt=!0,window.ShopAR__analytics.initializeImpl(),xt.forEach((e=>e()))})))}function kt(e){Pt?e():xt.push(e)}function Tt(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Lt(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 Ut=200,$t=10;let Dt=!1,_t=null,Nt=[],jt=[];function Ot(t){return e(this,void 0,void 0,(function*(){Dt=!1;const{ShopAR__TrueScale:n}=window;yield n.initialize(`${w}/wasm/mediapipe`,t),_t&&clearInterval(_t);const r=[],o=[];_t=setInterval((()=>e(this,void 0,void 0,(function*(){if(Dt)return;const{error:e,faceWidth:t,ipd:i,translation:a,rotation:s}=yield n.predict(performance.now());Dt||(null!=a&&null!=s&&function(e){for(let t of Nt)t(e)}({translation:a,rotation:s}),null==e&&(r.push(t),o.push(i),r.length<$t||(r.shift(),o.shift(),function(e,t){for(let n of jt)n({faceWidth:e,IPD:t})}(Wt(r),Wt(o)))))}))),Ut)}))}function Ft(){jt=[],Nt=[],Dt=!0}function Wt(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 f((()=>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 Gt="undefined"!=typeof Float32Array?Float32Array:Array;function zt(){var e=new Gt(16);return Gt!=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 Qt(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 Vt(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Kt(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 Bt(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 Ht(){var e=new Gt(3);return Gt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Xt(e,t,n){var r=new Gt(3);return r[0]=e,r[1]=t,r[2]=n,r}function Zt(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 Yt(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 Jt(){var e=new Gt(4);return Gt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Ht(),function(){var e,t=(e=new Gt(4),Gt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e)}();var en;let tn,nn,rn;Ht(),Xt(1,0,0),Xt(0,1,0),Jt(),Jt(),en=new Gt(9),Gt!=Float32Array&&(en[1]=0,en[2]=0,en[3]=0,en[5]=0,en[6]=0,en[7]=0),en[0]=1,en[4]=1,en[8]=1;let on,an,sn,ln,cn=!0,un=null;const dn=new Set;let hn,fn,pn,mn,gn,vn,wn;function yn(){null==tn&&(tn=y(`${w}/shopar-deepar.js`))}function bn(){null==nn&&(nn=y(`${w}/shopar-true-scale.js`))}function En(n){return e(this,void 0,void 0,(function*(){const{licenseKey:r,truescaleUsecase:o}=n;return gn=o,null==hn&&(hn=(()=>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=Mn(sn),o=Tt(n);on=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:r||"your_license_key_goes_here",previewElement:ln,additionalOptions:{hint:vn,cameraConfig:{disableDefaultCamera:!0}}}),an=yield Lt(o),yield kn(on,an,"user"===n),"Glasses"===sn&&(yield nn,Ot(an),"DetectionLoop"!==gn&&$n((e=>{mn=e.faceWidth})))})))()),hn}))}function An(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===sn&&(n=t,r=vn,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!=on&&(on.shutdown(),on=null,hn=null),sn=e,vn=t)}function Rn(e){e!==ln&&(ln=e,null!=on&&on.changePreviewElement(ln))}function Sn(e){un=e}function Cn(e){on.callbacks.onFaceTracked=t=>{if(t.some((e=>e.detected))){if(mn){const e=137/(mn+5);on.changeParameterVector("GLASSES","","scale",e,e,e,0),on.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=Ln("face_position","model","temple_left","temple_left_outer","temple_tip_outer_left",n,e),o=Ln("face_position","model","temple_right","temple_right_outer","temple_tip_outer_right",t,e);on.changeParameterVector("temple_left","","rotation",0,56.6*-r,0,0),on.changeParameterVector("temple_right","","rotation",0,56.6*-o,0,0)}catch(e){return}}(e),Ft(),mn=null}e(),Tn("Glasses")}},on.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&(e(),Tn("Shoes"))},on.callbacks.onWristTracked=t=>{t.detected&&(e(),Tn("Watches"))}}function In(t,n){return e(this,void 0,void 0,(function*(){return null!=fn&&pn===n||(yield fn,fn=on.switchEffect(t),pn=n),fn}))}function Pn(){return e(this,void 0,void 0,(function*(){if(null!=on){if(cn=!1,null==an){const e=Mn(sn),t=Tt(e);an=yield Lt(t),yield kn(on,an,"user"===e),Ot(an),"DetectionLoop"!==gn&&$n((e=>{mn=e.faceWidth}))}!function(){if(null==un)return;if(null==sn||dn.has(sn))return;un.style.visibility="visible",un.style.opacity="1"}(),on.setPaused(cn),ln.style.display=""}}))}function xn(){null!=on&&(cn=!0,on.setPaused(cn),Ft(),null!=an&&null!=an.srcObject&&an.srcObject instanceof MediaStream&&(an.srcObject.getTracks().forEach((e=>e.stop())),an=null),function(){if(null==un)return;un.style.visibility="hidden",un.style.opacity="0"}(),on.stopCamera(),ln.style.display="none")}function Mn(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function kn(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 Tn(e){null!=un&&(dn.has(e)||(dn.add(e),un.style.opacity="0"))}function Ln(e,t,n,r,o,i,a){const s=on.getTransformationBetween(e,t),l=Vt(Ht(),s),c=function(e,t){var n=new Gt(3);Kt(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}(Jt(),s);Bt(s,c,l,Xt(a,a,a));const u=on.getTransformationBetween(t,n),d=Vt(Ht(),u);Bt(u,Jt(),d,Kt(Ht(),u));const h=Qt(zt(),s,u),f=Vt(Ht(),h),p=Math.atan2(i[0]-f[0],Math.abs(i[2]-f[2]));let m;try{m=on.getTransformationBetween(n,r)}catch(e){return p}const g=Qt(zt(),u,m),v=Qt(zt(),s,g),w=Xt(f[0],i[1],i[2]),y=Yt(Ht(),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,R=o*c-i*l,S=u*m-d*p,C=u*g-h*p,I=u*v-f*p,P=d*g-h*m,x=d*v-f*m,M=h*v-f*g,k=w*M-y*x+b*P+E*I-A*C+R*S;return k?(k=1/k,e[0]=(s*M-l*x+c*P)*k,e[1]=(o*x-r*M-i*P)*k,e[2]=(m*R-g*A+v*E)*k,e[3]=(h*A-d*R-f*E)*k,e[4]=(l*I-a*M-c*C)*k,e[5]=(n*M-o*I+i*C)*k,e[6]=(g*b-p*R-v*y)*k,e[7]=(u*R-h*b+f*y)*k,e[8]=(a*x-s*I+c*S)*k,e[9]=(r*I-n*x-i*S)*k,e[10]=(p*A-m*b+v*w)*k,e[11]=(d*b-u*A-f*w)*k,e[12]=(s*C-a*P-l*S)*k,e[13]=(n*P-r*C+o*S)*k,e[14]=(m*y-p*E-g*w)*k,e[15]=(u*E-d*y+h*w)*k,e):null}(zt(),v));let b=on.getClosestPointOnMesh(r,y);try{const e=on.getClosestPointOnMesh(o,y);Zt(y,e)<Zt(y,b)&&(b=e)}catch(e){}const E=Yt(Ht(),b,g);return p-Math.atan2(E[0]-d[0],Math.abs(E[2]-d[2]))}function Un(e){!function(e){Nt.push(e)}(e)}function $n(e){!function(e){jt.push(e)}(e)}function Dn(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 p=String.fromCharCode(a-7),m=window[`${h}${d+u+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],g=yield f((()=>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 _n(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function Nn(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}function jn(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const On=["AR","3D"];function Fn(e){const{apiKey:n,sku:r,targetElement:o,initialState:i,initialAnimation:a,baseUrl:s,defaultUI:l,interactive:c,strings:u}=e;_n(n,"apiKey"),jn(n,"apiKey"),_n(r,"sku"),jn(r,"sku"),_n(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",On),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&&jn(s,"baseUrl"),null!=l&&Nn(l,"defaultUI"),null!=c&&Nn(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",Ke)}let Wn=!1;function qn(n){return e(this,void 0,void 0,(function*(){const{targetElement:r}=n;w.update(n.baseUrl),Mt();const{trackEvent:o}=function(e){const t=performance.now(),n=bt();return{trackEvent:(r,o={})=>{o=Object.assign(Object.assign({},o),{pluginVersion:g,sessionId:It,setupId:n,timeSinceSetup:performance.now()-t,apiKey:e}),kt((()=>{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 f((()=>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=ft(r),{getSetupId:l,findUI:c}=s,d=l();yn(),bn();const{setTargetElement:h,getDeepARTarget:p,setVisibilityParameters:m,getUIState:v,setUIState:y,startDeepARLoading:b,stopDeepARLoading:E,showCameraError:A}=c();if(v()!=st.None)throw Error("UI state is not None, this is weird..");y(st.AR),h(r),m(!1,!1,!0,!1,void 0),b(),yield tn,Gn(l(),d);try{o("visionArLaunch"),xn(),An("Glasses",["faceInit"]),Rn(p()),yield En({licenseKey:a,truescaleUsecase:"DetectionLoop"}),Gn(l(),d),yield Pn(),Gn(l(),d)}catch(e){const n=e instanceof Error;throw o("visionArLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),A(),xn(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{E()}return Wn=!0,{registerFacePoseListener:e=>{Wn&&(o("registerFacePoseListener"),Un(e))},registerFaceMeasurementListener:e=>{Wn&&(o("registerFaceMeasurementListener"),$n(e))},switchEffect:t=>e(this,void 0,void 0,(function*(){Wn&&(o("switchEffect",{arUrl:t}),function(e){on.switchEffect(e)}(t))})),clearEffect:()=>{Wn&&(o("clearEffect"),on.clearEffect())},close:()=>{if(Wn){if(Wn=!1,o("visionClose"),v()!==st.AR)throw new t("AR not launched.");xn(),y(st.None)}}}}))}function Gn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}function zn(n){var r,o;return e(this,void 0,void 0,(function*(){Fn(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),w.update(n.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(Ve,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(Ve[t]=n)}}(n.strings);const d=null!=c?ge(c):null,h=function(n,r){return e(this,void 0,void 0,(function*(){const o=yield f((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:n,sku:r,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 o.json()}catch(e){throw console.error(e),new t("API returned invalid body.")}}))}(i,a),v=ft(s),{getSetupId:E,findUI:A,findQR:R,findThree:S}=v,C=E();Mt();const{trackEvent:I,arInteracted:P,previewInteracted:x}=function(e,t){const n=performance.now(),r=bt();let o=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(o=i+a,c=!1,u(St,{engagementTotal:o,engagementAR:i,engagement3D:a}))}),1e3);const u=(o,i={})=>{i=Object.assign(Object.assign({},i),{pluginVersion:g,sessionId:It,setupId:r,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),kt((()=>{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);I("setup",{hostname:window.location.hostname});const M=yield h;I("apiResponse",M);const{category:k,arUrl:T,arKey:L,arPromptEnabled:U,arPromptText:$,arPromptImage:D,previewUrl:_,previewEnvUrl:N,previewToneMapping:j,cameraErrorText:O,qrPromptText:F}=M;Qn(E(),C);const W=null!=T&&function(e){return null!=e&&p.includes(e)}(k),q=null==(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled)||(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled),G=W&&function(e){return null!=e&&m.includes(e)}(k),z=q&&G&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==wn&&(wn=y(`${w}/shopar-platform.js`)),yield wn,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}()),Q=W&&!z,V=null!=_;if(Qn(E(),C),z&&function(){e(this,void 0,void 0,(function*(){null==b&&(b=y(`${w}/shopar-qr.js`))}))}(),Q&&(yn(),function(e){e!==rn&&(rn=e,qt(e),fn=null,Ft())}(T),"Glasses"===k&&bn()),V){null==ke&&(ke=y(`${w}/shopar-three.js`));const e=255;Dn(_,(new Date).getTime()+e,Math.random()*e),qt(null!=N?N:`${w}/env/default.hdr`)}const{setTargetElement:K,getDeepARTarget:B,getDeepARPrompt:H,customizeDeepARPrompt:X,customizeCameraError:Z,customizeQRPrompt:Y,setVisibilityParameters:J,getUIState:ee,setUIState:te,setDefaultUIActions:ne,startDeepARLoading:re,stopDeepARLoading:oe,startThreeLoading:ie,stopThreeLoading:ae,showCameraError:se}=A();K(s);J(null==n.defaultUI||n.defaultUI,z,Q,V,k),X(null!=$?$:"",null!=D?D:""),Z(O),Y(F),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,(()=>{ee()!==st.QR||le()||ue(),ee()!==st.AR||cn||xn(),ee()!==st.Preview||pe()||ve(),te(st.None)}));const{qrPaused:le,qrDraw:ce,qrPause:ue}=R(),{threeInit:de,threeParse:he,threeLoad:fe,threePaused:pe,threeResume:me,threePause:ve,threeSetToneMapping:we,threeIsInteractive:ye,threeSetInteractive:be,threeSetOnInteracted:Ee,threeInitPromptAnimation:Ae,threeInitCameraAnimation:Re}=S(),Se=null==n.interactive||n.interactive;be(Se);let Ce=0;if(ee()===st.QR){if(!le())if(z){I(Et);try{yield ce(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else ue(),te(st.None)}else if(ee()===st.AR){if(!cn)if(Q&&!Wn){I(At);const e=yield qt(T);Qn(E(),C),pt(v),An(k),Rn(B()),Sn(U?H():null),yield In(e,T),Cn(P),Qn(E(),C)}else xn(),te(st.None)}else if(ee()===st.Preview&&!pe())if(V){I(Rt),ie();const e=255,t=yield Dn(_,(new Date).getTime()+e,Math.random()*e);Qn(E(),C);const n=yield qt(null!=N?N:`${w}/env/default.hdr`);Qn(E(),C);const r=yield he(t,n,`${_}${N}`);Qn(E(),C),fe(r,k),we(null!=j?j:"ACES"),Ee(x),ae()}else ve(),te(st.None);const Ie=()=>e(this,void 0,void 0,(function*(){if(z){if(ee()===st.QR||ee()===st.AR)throw new t("AR already launched.");try{I(Et);const e=++Ce;if(ee()===st.Preview&&V&&!pe()&&ve(),te(st.QR),yield ce(i,a),Ce!==e)return;return void Qn(E(),C)}catch(e){const n=e instanceof Error;throw I("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!Q)throw new t("Model does not have AR enabled.");if(ee()===st.AR)throw new t("AR already launched.");try{I(At);const e=++Ce;ee()===st.Preview&&V&&!pe()&&ve(),pt(v),te(st.AR),re();const t=yield qt(T);if(Ce!==e)return;if(Qn(E(),C),yield tn,Ce!==e)return;if(Qn(E(),C),xn(),An(k),Rn(B()),Sn(U?H():null),yield En({licenseKey:L}),Ce!==e)return;if(Qn(E(),C),yield In(t,T),Cn(P),Ce!==e)return;if(Qn(E(),C),yield Pn(),Ce!==e)return;Qn(E(),C)}catch(e){const n=e instanceof Error;throw I("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),se(),xn(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{oe()}})),Pe=()=>e(this,void 0,void 0,(function*(){if(!V)throw new t("Model does not have 3D enabled.");if(ee()===st.Preview)throw new t("3D already launched.");try{I(Rt);const e=++Ce;ee()===st.AR&&(Q&&!cn&&xn(),ue()),te(st.Preview),ie();const t=255,n=yield Dn(_,(new Date).getTime()+t,Math.random()*t);if(Ce!==e)return;Qn(E(),C);const r=yield qt(null!=N?N:`${w}/env/default.hdr`);if(Ce!==e)return;if(Qn(E(),C),yield ke,Ce!==e)return;if(Qn(E(),C),de(),Ce!==e)return;Qn(E(),C);const o=yield he(n,r,`${_}${N}`);if(Ce!==e)return;Qn(E(),C),fe(o,k),we(null!=j?j:"ACES"),Ee(x),Ae(),null!=d&&Re(d),me()}catch(e){const n=e instanceof Error;throw I("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{ae()}})),xe=()=>e(this,void 0,void 0,(function*(){if(ee()===st.None)throw new t("Neither AR or 3D launched.");++Ce,ee()===st.QR||ee()===st.AR?(Q&&!cn&&xn(),ue()):ee()===st.Preview&&V&&!pe()&&ve(),te(st.None)}));return ne(Ie,Pe,xe),"AR"===l?(yield Ie(),Qn(E(),C)):"3D"===l&&(yield Pe(),Qn(E(),C)),Wn=!1,{launchAR:W?Ie:void 0,launch3D:V?Pe:void 0,closeAR:W?()=>e(this,void 0,void 0,(function*(){if(ee()!==st.AR&&ee()!==st.QR)throw new t("AR not launched.");++Ce,Q&&!cn&&xn(),ue(),te(st.None)})):void 0,close3D:V?()=>e(this,void 0,void 0,(function*(){if(ee()!==st.Preview)throw new t("3D not launched.");++Ce,V&&!pe()&&ve(),te(st.None)})):void 0,close:W||V?xe:void 0,isInteractive:()=>ye(),setInteractive:e=>be(e)}}))}function Qn(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const Vn={setup:function(t){return e(this,void 0,void 0,(function*(){return qn(t)}))}},Kn={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",(()=>zn(n)))}))},version:g};export{Kn as plugin,Vn as vision};
|