shopar-plugin 1.1.0-alpha.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/shopar-analytics.js +1 -1
- package/dist/shopar-plugin.esm.js +1 -1
- package/dist/shopar-plugin.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ There are two distinct ways of integrating the plugin: via Script tag and via NP
|
|
|
32
32
|
Add the following script to your HTML.
|
|
33
33
|
|
|
34
34
|
```html
|
|
35
|
-
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@
|
|
35
|
+
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@1.1.0/dist/shopar-plugin.js"></script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
It is possible to use a different CDN instead of [jsDelivr](https://www.jsdelivr.com/) (e.g. [cdnjs](https://cdnjs.com/), [unpkg](https://www.unpkg.com/)), or even a relative path if the plugin is distributed as a static asset to your app. Just make sure to set the `baseUrl` parameter accordingly (see [setup options](#shoparpluginsetupoptions) for more details).
|
|
@@ -200,7 +200,7 @@ Options used for the plugin setup:
|
|
|
200
200
|
- `baseUrl` (optional)
|
|
201
201
|
- Type: `string`
|
|
202
202
|
- If provided, defines where the additional ShopAR plugin files are fetched from.
|
|
203
|
-
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@
|
|
203
|
+
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@1.1.0/dist`
|
|
204
204
|
- `defaultUI` (optional)
|
|
205
205
|
- Type: `boolean`
|
|
206
206
|
- If provided and set to `false`, disables the default UI (buttons and error 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}var i,n;var s=e(function(){if(n)return i;function t(t){return Number.isInteger(t)&&t>=0}function e(t){this.name="ArgumentError",this.message=t}return n=1,i=function(i,n){if(n=n||{},"function"!=typeof i)throw new e("fetch must be a function");if("object"!=typeof n)throw new e("defaults must be an object");if(void 0!==n.retries&&!t(n.retries))throw new e("retries must be a positive integer");if(void 0!==n.retryDelay&&!t(n.retryDelay)&&"function"!=typeof n.retryDelay)throw new e("retryDelay must be a positive integer or a function returning a positive integer");if(void 0!==n.retryOn&&!Array.isArray(n.retryOn)&&"function"!=typeof n.retryOn)throw new e("retryOn property expects an array or function");return n=Object.assign({retries:3,retryDelay:1e3,retryOn:[]},n),function(s,r){var o=n.retries,a=n.retryDelay,c=n.retryOn;if(r&&void 0!==r.retries){if(!t(r.retries))throw new e("retries must be a positive integer");o=r.retries}if(r&&void 0!==r.retryDelay){if(!t(r.retryDelay)&&"function"!=typeof r.retryDelay)throw new e("retryDelay must be a positive integer or a function returning a positive integer");a=r.retryDelay}if(r&&r.retryOn){if(!Array.isArray(r.retryOn)&&"function"!=typeof r.retryOn)throw new e("retryOn property expects an array or function");c=r.retryOn}return new Promise(function(t,e){var n=function(n){var a="undefined"!=typeof Request&&s instanceof Request?s.clone():s;i(a,r).then(function(i){if(Array.isArray(c)&&-1===c.indexOf(i.status))t(i);else if("function"==typeof c)try{return Promise.resolve(c(n,null,i)).then(function(e){e?l(n,null,i):t(i)}).catch(e)}catch(t){e(t)}else n<o?l(n,null,i):t(i)}).catch(function(t){if("function"==typeof c)try{Promise.resolve(c(n,t,null)).then(function(i){i?l(n,t,null):e(t)}).catch(function(t){e(t)})}catch(t){e(t)}else n<o?l(n,t,null):e(t)})};function l(t,e,i){var s="function"==typeof a?a(t,e,i):a;setTimeout(function(){n(++t)},s)}n(0)})}}}());var r,o;!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"}(o||(o={}));class a{scope;type;value;remaining;reset;constructor(t=r.unknown,e=o.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){const o=new a,c=t.headers.get(e.toLowerCase())||r.unknown;o.scope=r[c];const l=t.headers.get(i.toLowerCase())||"",h=parseInt(l,10);isNaN(h)||(o.value=h);const u=t.headers.get(n.toLowerCase())||"",f=parseInt(u,10);isNaN(f)||(o.remaining=f);const p=t.headers.get(s.toLowerCase())||"",m=parseInt(p,10);return isNaN(m)||(o.reset=new Date(1e3*m)),o}class l{config;constructor(t){this.config=t}async doReq(t,e,i={},n={},r=this.config.timeout,a=!1){let l=a?t:`${this.config.baseUrl}${t}`;const u=this._prepareSearchParams(n);u&&(l+=`?${u.toString()}`);const f={...this.config.headers,...i.headers},p=await s(fetch)(l,{retries:1,retryDelay:function(t,e,i){return 1e3*Math.pow(2,t)},retryOn:[503,502,504,500],headers:f,method:e,body:i.body?i.body:void 0,signal:AbortSignal.timeout(r),cache:"no-store"});if(204===p.status)return p;if(429==p.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=o.ingest):t.url?.endsWith("/query")||t.url?.endsWith("/_apl")?(e=c(t,"","X-QueryLimit-Limit","X-QueryLimit-Remaining","X-QueryLimit-Reset"),e.type=o.query):(e=c(t,"X-RateLimit-Scope","X-RateLimit-Limit","X-RateLimit-Remaining","X-RateLimit-Reset"),e.type=o.api),e}(p);return Promise.reject(new h(t))}if(401===p.status)return Promise.reject(new Error("forbidden"));if(p.status>=400){const t=await p.json();return Promise.reject(new Error(t.message))}return await p.json()}post(t,e={},i={},n=this.config.timeout,s=!1){return this.doReq(t,"POST",e,i,n,s)}get(t,e={},i={},n=this.config.timeout){return this.doReq(t,"GET",e,i,n)}put(t,e={},i={},n=this.config.timeout){return this.doReq(t,"PUT",e,i,n)}delete(t,e={},i={},n=this.config.timeout){return this.doReq(t,"DELETE",e,i,n)}_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==o.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}}}const u="https://api.axiom.co";function f(t,e){return t.edgeUrl?function(t,e){try{const i=new URL(t),n=i.pathname;return""===n||"/"===n?(i.pathname=`/v1/ingest/${e}`,i.toString()):(i.pathname=n.replace(/\/+$/,""),i.toString())}catch{return`${t.replace(/\/+$/,"")}/v1/ingest/${e}`}}(t.edgeUrl,e):t.edge?`https://${t.edge}/v1/ingest/${e}`:t.url?function(t,e){try{const i=new URL(t),n=i.pathname;return""===n||"/"===n?(i.pathname=`/v1/datasets/${e}/ingest`,i.toString()):(i.pathname=n.replace(/\/+$/,""),i.toString())}catch{return`${t.replace(/\/+$/,"")}/v1/datasets/${e}/ingest`}}(t.url,e):`${u}/v1/datasets/${e}/ingest`}class p{client;clientOptions;constructor({orgId:t="",token:e,url:i,edge:n,edgeUrl:s,onError:r}){e||console.warn("Missing Axiom token"),this.clientOptions={orgId:t,token:e,url:i,edge:n,edgeUrl:s,onError:r};const o=i?i.replace(/\/+$/,""):u,a={Accept:"application/json","Content-Type":"application/json",Authorization:"Bearer "+e};"undefined"==typeof window&&(a["User-Agent"]="axiom-js/1.4.0"),t&&(a["X-Axiom-Org-Id"]=t),this.client=new l({baseUrl:o,headers:a,timeout:2e4})}}var m,d,g,y,v,w,b,O;!function(t){t.TimestampField="_time";t.Service=class extends p{localPath="/v1/datasets";list=()=>this.client.get(this.localPath);get=t=>this.client.get(this.localPath+"/"+t);create=(t,e)=>{const i=new URLSearchParams;i.set("referrer",e?.referrer??"");const n=`/v2/datasets?${i.toString()}`;return this.client.post(n,{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)})}}}(m||(m={})),function(t){t.Service=class extends p{current=()=>this.client.get("/v1/user")}}(d||(d={}));class S{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);let e=null;try{e=await this.ingestFn(this.id,t,this.options)}catch(t){throw t}finally{this.lastFlush=new Date}return e}}class x extends p{datasets;users;localPath="/v1";onError=console.error;constructor(t){t.token&&t.token.startsWith("xapt")&&console.warn("Using a personal token (`xapt-...`) is deprecated for security reasons. Please use an API token (`xaat-...`) instead. Support for personal tokens will be removed in a future release."),super(t),this.datasets=new m.Service(t),this.users=new d.Service(t),t.onError&&(this.onError=t.onError)}ingestRaw=async(t,e,i=g.JSON,n=y.Identity,s)=>{try{const r=f(this.clientOptions,t);return await this.client.post(r,{headers:{"Content-Type":i,"Content-Encoding":n},body:e},{"timestamp-field":s?.timestampField,"timestamp-format":s?.timestampFormat,"csv-delimiter":s?.csvDelimiter},void 0,!0)}catch(t){return this.onError(t),await Promise.resolve({ingested:0,failed:0,processedBytes:0,blocksCreated:0,walLength:0})}};queryLegacy=(t,e,i)=>this.client.post(this.localPath+"/datasets/"+t+"/query",{body:JSON.stringify(e)},{"streaming-duration":i?.streamingDuration,nocache:i?.noCache},12e4);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:e?.format??"legacy",cursor:e?.cursor},12e4).then(t=>{if("tabular"!==e?.format)return t;const i=t;return{...t,tables:i.tables.map(t=>({...t,events:function*(){let t=0;if(this.columns)for(;t<=this.columns[0].length;){const e=Object.fromEntries(this.fields.map((e,i)=>[e.name,this.columns[i][t]]));if(t>=this.columns[0].length)return e;yield e,t++}}}))}})};aplQuery=(t,e)=>this.query(t,e)}class P extends x{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 S((t,e,i)=>{const n=(Array.isArray(e)?e:[e]).map(t=>JSON.stringify(t)).join("\n");return this.ingestRaw(t,n,g.NDJSON,y.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().catch(this.onError));await Promise.all(t).catch(this.onError)}}let N;BigInt.prototype.toJSON=function(){return this.toString()},function(t){t.JSON="application/json",t.NDJSON="application/x-ndjson",t.CSV="text/csv"}(g||(g={})),function(t){t.Identity="",t.GZIP="gzip"}(y||(y={})),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"}(v||(v={})),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"}(w||(w={})),function(t){t.Service=class extends p{localPath="/v2/annotations";list=t=>this.client.get(this.localPath,{},t);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)}}(b||(b={})),function(t){t.Service=class extends p{localPath="/v2/monitors";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)}}(O||(O={})),t.initializeImpl=function(){N=new P({token:"xaat-16d05fdd-4ab9-4990-acba-7cee24974bfb"})},t.trackEventImpl=function(t,e){N.ingest("shopar-plugin-alpha",Object.assign({name:t},e))}});
|
|
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}var i,n;var s=e(function(){if(n)return i;function t(t){return Number.isInteger(t)&&t>=0}function e(t){this.name="ArgumentError",this.message=t}return n=1,i=function(i,n){if(n=n||{},"function"!=typeof i)throw new e("fetch must be a function");if("object"!=typeof n)throw new e("defaults must be an object");if(void 0!==n.retries&&!t(n.retries))throw new e("retries must be a positive integer");if(void 0!==n.retryDelay&&!t(n.retryDelay)&&"function"!=typeof n.retryDelay)throw new e("retryDelay must be a positive integer or a function returning a positive integer");if(void 0!==n.retryOn&&!Array.isArray(n.retryOn)&&"function"!=typeof n.retryOn)throw new e("retryOn property expects an array or function");return n=Object.assign({retries:3,retryDelay:1e3,retryOn:[]},n),function(s,r){var o=n.retries,a=n.retryDelay,c=n.retryOn;if(r&&void 0!==r.retries){if(!t(r.retries))throw new e("retries must be a positive integer");o=r.retries}if(r&&void 0!==r.retryDelay){if(!t(r.retryDelay)&&"function"!=typeof r.retryDelay)throw new e("retryDelay must be a positive integer or a function returning a positive integer");a=r.retryDelay}if(r&&r.retryOn){if(!Array.isArray(r.retryOn)&&"function"!=typeof r.retryOn)throw new e("retryOn property expects an array or function");c=r.retryOn}return new Promise(function(t,e){var n=function(n){var a="undefined"!=typeof Request&&s instanceof Request?s.clone():s;i(a,r).then(function(i){if(Array.isArray(c)&&-1===c.indexOf(i.status))t(i);else if("function"==typeof c)try{return Promise.resolve(c(n,null,i)).then(function(e){e?l(n,null,i):t(i)}).catch(e)}catch(t){e(t)}else n<o?l(n,null,i):t(i)}).catch(function(t){if("function"==typeof c)try{Promise.resolve(c(n,t,null)).then(function(i){i?l(n,t,null):e(t)}).catch(function(t){e(t)})}catch(t){e(t)}else n<o?l(n,t,null):e(t)})};function l(t,e,i){var s="function"==typeof a?a(t,e,i):a;setTimeout(function(){n(++t)},s)}n(0)})}}}());var r,o;!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"}(o||(o={}));class a{scope;type;value;remaining;reset;constructor(t=r.unknown,e=o.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){const o=new a,c=t.headers.get(e.toLowerCase())||r.unknown;o.scope=r[c];const l=t.headers.get(i.toLowerCase())||"",h=parseInt(l,10);isNaN(h)||(o.value=h);const u=t.headers.get(n.toLowerCase())||"",f=parseInt(u,10);isNaN(f)||(o.remaining=f);const p=t.headers.get(s.toLowerCase())||"",m=parseInt(p,10);return isNaN(m)||(o.reset=new Date(1e3*m)),o}class l{config;constructor(t){this.config=t}async doReq(t,e,i={},n={},r=this.config.timeout,a=!1){let l=a?t:`${this.config.baseUrl}${t}`;const u=this._prepareSearchParams(n);u&&(l+=`?${u.toString()}`);const f={...this.config.headers,...i.headers},p=await s(fetch)(l,{retries:1,retryDelay:function(t,e,i){return 1e3*Math.pow(2,t)},retryOn:[503,502,504,500],headers:f,method:e,body:i.body?i.body:void 0,signal:AbortSignal.timeout(r),cache:"no-store"});if(204===p.status)return p;if(429==p.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=o.ingest):t.url?.endsWith("/query")||t.url?.endsWith("/_apl")?(e=c(t,"","X-QueryLimit-Limit","X-QueryLimit-Remaining","X-QueryLimit-Reset"),e.type=o.query):(e=c(t,"X-RateLimit-Scope","X-RateLimit-Limit","X-RateLimit-Remaining","X-RateLimit-Reset"),e.type=o.api),e}(p);return Promise.reject(new h(t))}if(401===p.status)return Promise.reject(new Error("forbidden"));if(p.status>=400){const t=await p.json();return Promise.reject(new Error(t.message))}return await p.json()}post(t,e={},i={},n=this.config.timeout,s=!1){return this.doReq(t,"POST",e,i,n,s)}get(t,e={},i={},n=this.config.timeout){return this.doReq(t,"GET",e,i,n)}put(t,e={},i={},n=this.config.timeout){return this.doReq(t,"PUT",e,i,n)}delete(t,e={},i={},n=this.config.timeout){return this.doReq(t,"DELETE",e,i,n)}_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==o.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}}}const u="https://api.axiom.co";function f(t,e){return t.edgeUrl?function(t,e){try{const i=new URL(t),n=i.pathname;return""===n||"/"===n?(i.pathname=`/v1/ingest/${e}`,i.toString()):(i.pathname=n.replace(/\/+$/,""),i.toString())}catch{return`${t.replace(/\/+$/,"")}/v1/ingest/${e}`}}(t.edgeUrl,e):t.edge?`https://${t.edge}/v1/ingest/${e}`:t.url?function(t,e){try{const i=new URL(t),n=i.pathname;return""===n||"/"===n?(i.pathname=`/v1/datasets/${e}/ingest`,i.toString()):(i.pathname=n.replace(/\/+$/,""),i.toString())}catch{return`${t.replace(/\/+$/,"")}/v1/datasets/${e}/ingest`}}(t.url,e):`${u}/v1/datasets/${e}/ingest`}class p{client;clientOptions;constructor({orgId:t="",token:e,url:i,edge:n,edgeUrl:s,onError:r}){e||console.warn("Missing Axiom token"),this.clientOptions={orgId:t,token:e,url:i,edge:n,edgeUrl:s,onError:r};const o=i?i.replace(/\/+$/,""):u,a={Accept:"application/json","Content-Type":"application/json",Authorization:"Bearer "+e};"undefined"==typeof window&&(a["User-Agent"]="axiom-js/1.4.0"),t&&(a["X-Axiom-Org-Id"]=t),this.client=new l({baseUrl:o,headers:a,timeout:2e4})}}var m,d,g,y,v,w,b,O;!function(t){t.TimestampField="_time";t.Service=class extends p{localPath="/v1/datasets";list=()=>this.client.get(this.localPath);get=t=>this.client.get(this.localPath+"/"+t);create=(t,e)=>{const i=new URLSearchParams;i.set("referrer",e?.referrer??"");const n=`/v2/datasets?${i.toString()}`;return this.client.post(n,{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)})}}}(m||(m={})),function(t){t.Service=class extends p{current=()=>this.client.get("/v1/user")}}(d||(d={}));class S{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);let e=null;try{e=await this.ingestFn(this.id,t,this.options)}catch(t){throw t}finally{this.lastFlush=new Date}return e}}class x extends p{datasets;users;localPath="/v1";onError=console.error;constructor(t){t.token&&t.token.startsWith("xapt")&&console.warn("Using a personal token (`xapt-...`) is deprecated for security reasons. Please use an API token (`xaat-...`) instead. Support for personal tokens will be removed in a future release."),super(t),this.datasets=new m.Service(t),this.users=new d.Service(t),t.onError&&(this.onError=t.onError)}ingestRaw=async(t,e,i=g.JSON,n=y.Identity,s)=>{try{const r=f(this.clientOptions,t);return await this.client.post(r,{headers:{"Content-Type":i,"Content-Encoding":n},body:e},{"timestamp-field":s?.timestampField,"timestamp-format":s?.timestampFormat,"csv-delimiter":s?.csvDelimiter},void 0,!0)}catch(t){return this.onError(t),await Promise.resolve({ingested:0,failed:0,processedBytes:0,blocksCreated:0,walLength:0})}};queryLegacy=(t,e,i)=>this.client.post(this.localPath+"/datasets/"+t+"/query",{body:JSON.stringify(e)},{"streaming-duration":i?.streamingDuration,nocache:i?.noCache},12e4);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:e?.format??"legacy",cursor:e?.cursor},12e4).then(t=>{if("tabular"!==e?.format)return t;const i=t;return{...t,tables:i.tables.map(t=>({...t,events:function*(){let t=0;if(this.columns)for(;t<=this.columns[0].length;){const e=Object.fromEntries(this.fields.map((e,i)=>[e.name,this.columns[i][t]]));if(t>=this.columns[0].length)return e;yield e,t++}}}))}})};aplQuery=(t,e)=>this.query(t,e)}class P extends x{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 S((t,e,i)=>{const n=(Array.isArray(e)?e:[e]).map(t=>JSON.stringify(t)).join("\n");return this.ingestRaw(t,n,g.NDJSON,y.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().catch(this.onError));await Promise.all(t).catch(this.onError)}}let N;BigInt.prototype.toJSON=function(){return this.toString()},function(t){t.JSON="application/json",t.NDJSON="application/x-ndjson",t.CSV="text/csv"}(g||(g={})),function(t){t.Identity="",t.GZIP="gzip"}(y||(y={})),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"}(v||(v={})),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"}(w||(w={})),function(t){t.Service=class extends p{localPath="/v2/annotations";list=t=>this.client.get(this.localPath,{},t);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)}}(b||(b={})),function(t){t.Service=class extends p{localPath="/v2/monitors";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)}}(O||(O={})),t.initializeImpl=function(){N=new P({token:"xaat-f69a9dd7-3988-4fc2-849b-4a0978468c25"})},t.trackEventImpl=function(t,e){N.ingest("shopar-plugin",Object.assign({name:t},e))}});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=["AR","3D"];class t extends Error{constructor(e){super(e),this.name="PluginError"}}class n extends t{constructor(e){super(e),this.name="ValidationError"}}class i extends t{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class r extends t{constructor(e){super(e),this.name="SanitizationError"}}class a extends t{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class s extends t{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class o extends s{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class l extends s{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function c(e,t,n,i){return new(n||(n=Promise))(function(r,a){function s(e){try{l(i.next(e))}catch(e){a(e)}}function o(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,o)}l((i=i.apply(e,t||[])).next())})}function h(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function A(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function u(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function d(e,n){return()=>c(this,void 0,void 0,function*(){try{return yield n()}catch(n){if(n instanceof t)throw n;throw new t(`${e} failed: ${A(n)}`)}})}const p=[Uint8Array,Uint32Array].length-2,f=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],g=[2,12,7,1],m=window[f[g[g[p]]]][f[g[g[g.length-1]]]];function v(){const e=(new TextEncoder).encode(m),t=f.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[f[t[2]]](String.fromCodePoint(...e))}m.charCodeAt(p);function E(e){return e*(180/Math.PI)}function b(e){return Math.round(100*e)/100}const C=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],_=["Shoes"];const I="1.1.0-alpha.4";let x=`https://cdn.jsdelivr.net/npm/shopar-plugin@${I}/dist`;const y=e=>{null!=e&&(x=e.endsWith("/")?e.substring(0,e.length-1):e)},w=()=>x;function M(e,t){return c(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let S;function B(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>c(this,void 0,void 0,function*(){!function(){c(this,void 0,void 0,function*(){null==S&&(S=M(`${w()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield S;const a=`https://ar.shopar.ai/${I.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,s=yield window.ShopAR__QR.toDataURL(a),o=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=s,yield o,n=!1,e.style.display=""}),qrPause:()=>c(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const T={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},R=Object.keys(T);const D="--shopar";function Q(e){return`var(${e.var}, ${e.default})`}const U={padding:{var:`${D}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${D}-btn-gap`,default:"0.25rem"},border:{var:`${D}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${D}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${D}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${D}-btn-hover-bg`,default:"#f5f5f5"}};function L(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=Q(U.padding),r.justifyContent="center",r.alignItems="center",r.gap=Q(U.gap),r.backgroundColor=Q(U.bg),r.border=Q(U.border),r.borderRadius=Q(U.borderRadius),r.cursor="pointer";const a=Q(U.bg),s=Q(U.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=s}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const P={paddingBottom:{var:`${D}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${D}-btn-container-gap`,default:"0.5rem"}};const N={bg:{var:`${D}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${D}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${D}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${D}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${D}-ar-prompt-img-max-height`,default:"50%"}};const F={containerDisplay:{var:`${D}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${D}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${D}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${D}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${D}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${D}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${D}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${D}-ar-loading-bar-bg`,default:"#e5e7eb"}};const O={bg:{var:`${D}-qr-bg`,default:"#ffffff"}};function k(e,t,n,i){return new(n||(n=Promise))(function(r,a){function s(e){try{l(i.next(e))}catch(e){a(e)}}function o(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,o)}l((i=i.apply(e,t||[])).next())})}function G(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function H(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const z=.1,V="function"==typeof Float32Array;function W(e,t){return 1-3*t+3*e}function q(e,t){return 3*t-6*e}function j(e){return 3*e}function Y(e,t,n){return((W(t,n)*e+q(t,n))*e+j(t))*e}function X(e,t,n){return 3*W(t,n)*e*e+2*q(t,n)*e+j(t)}function K(e){return e}function J(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){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===i)return K;const r=V?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=Y(t*z,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=z;--a;const s=i+(t-r[a])/(r[a+1]-r[a])*z,o=X(s,e,n);return o>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=X(t,n,i);if(0===r)return t;t-=(Y(t,n,i)-e)/r}return t}(t,s,e,n):0===o?s:function(e,t,n,i,r){let a,s,o=0;do{s=t+(n-t)/2,a=Y(s,i,r)-e,a>0?n=s:t=s}while(Math.abs(a)>1e-7&&++o<10);return s}(t,i,i+z,e,n)}return function(e){return 0===e||1===e?e:Y(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function Z(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort((e,t)=>e.time-t.time).map(({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:J(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const $="time",ee="interpolation",te="pitch",ne=[$,"yaw",te,"fov",ee],ie=Math.PI/180,re="ease-in-out",ae="cubic-bezier(";function se(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("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ne.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes($))throw new Error(`Missing required token: '${$}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=oe(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(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 i of e){const{time:e,pitch:r,yaw:a,fov:s}=i;if(null==e)throw new Error("Time missing.");const o=ce(null!==(t=i.interpolation)&&void 0!==t?t:re);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*ie,interpolation:o})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*ie,interpolation:o})),null!=s&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:s*ie,interpolation:o}))}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 oe(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 i=e.indexOf($),r=function(e){return e.endsWith("ms")?Ae(e.substring(0,e.length-2)):e.endsWith("s")?1e3*Ae(e.substring(0,e.length-1)):Ae(e)}(n[i]),a=e.indexOf(ee),s=ce(-1===a?re:n[a]),o={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":o.theta={time:r,value:le(c),interpolation:s};break;case te:o.phi={time:r,value:le(c),interpolation:s};break;case"fov":o.fov={time:r,value:le(c),interpolation:s};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return o}function le(e){return e.endsWith("deg")?Ae(e.substring(0,e.length-3))*ie:e.endsWith("rad")?Ae(e.substring(0,e.length-3)):Ae(e)*ie}function ce(e){if("hold"===e)return{type:"hold"};if("linear"===e)return he(0,0,1,1);if("sine"===e)return he(.37,0,.63,1);if("sine-in"===e)return he(.12,0,.39,0);if("sine-out"===e)return he(.61,1,.88,1);if("ease"===e)return he(.25,.1,.25,1);if("ease-in"===e)return he(.42,0,1,1);if("ease-out"===e)return he(0,0,.58,1);if("ease-in-out"===e)return he(.42,0,.58,1);if(e.startsWith(ae)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Ae(t[0]),y1:Ae(t[1]),x2:Ae(t[2]),y2:Ae(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function he(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function Ae(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
|
|
1
|
+
const e=["AR","3D"];class t extends Error{constructor(e){super(e),this.name="PluginError"}}class n extends t{constructor(e){super(e),this.name="ValidationError"}}class i extends t{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class r extends t{constructor(e){super(e),this.name="SanitizationError"}}class a extends t{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class s extends t{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class o extends s{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class l extends s{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function c(e,t,n,i){return new(n||(n=Promise))(function(r,a){function s(e){try{l(i.next(e))}catch(e){a(e)}}function o(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,o)}l((i=i.apply(e,t||[])).next())})}function h(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function A(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function u(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function d(e,n){return()=>c(this,void 0,void 0,function*(){try{return yield n()}catch(n){if(n instanceof t)throw n;throw new t(`${e} failed: ${A(n)}`)}})}const p=[Uint8Array,Uint32Array].length-2,f=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],g=[2,12,7,1],m=window[f[g[g[p]]]][f[g[g[g.length-1]]]];function v(){const e=(new TextEncoder).encode(m),t=f.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[f[t[2]]](String.fromCodePoint(...e))}m.charCodeAt(p);function E(e){return e*(180/Math.PI)}function b(e){return Math.round(100*e)/100}const C=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],_=["Shoes"];const I="1.1.0";let x=`https://cdn.jsdelivr.net/npm/shopar-plugin@${I}/dist`;const y=e=>{null!=e&&(x=e.endsWith("/")?e.substring(0,e.length-1):e)},w=()=>x;function M(e,t){return c(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let S;function B(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>c(this,void 0,void 0,function*(){!function(){c(this,void 0,void 0,function*(){null==S&&(S=M(`${w()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield S;const a=`https://ar.shopar.ai/${I.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,s=yield window.ShopAR__QR.toDataURL(a),o=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=s,yield o,n=!1,e.style.display=""}),qrPause:()=>c(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const T={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},R=Object.keys(T);const D="--shopar";function Q(e){return`var(${e.var}, ${e.default})`}const U={padding:{var:`${D}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${D}-btn-gap`,default:"0.25rem"},border:{var:`${D}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${D}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${D}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${D}-btn-hover-bg`,default:"#f5f5f5"}};function L(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=Q(U.padding),r.justifyContent="center",r.alignItems="center",r.gap=Q(U.gap),r.backgroundColor=Q(U.bg),r.border=Q(U.border),r.borderRadius=Q(U.borderRadius),r.cursor="pointer";const a=Q(U.bg),s=Q(U.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=s}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const P={paddingBottom:{var:`${D}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${D}-btn-container-gap`,default:"0.5rem"}};const N={bg:{var:`${D}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${D}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${D}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${D}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${D}-ar-prompt-img-max-height`,default:"50%"}};const F={containerDisplay:{var:`${D}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${D}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${D}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${D}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${D}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${D}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${D}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${D}-ar-loading-bar-bg`,default:"#e5e7eb"}};const O={bg:{var:`${D}-qr-bg`,default:"#ffffff"}};function k(e,t,n,i){return new(n||(n=Promise))(function(r,a){function s(e){try{l(i.next(e))}catch(e){a(e)}}function o(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,o)}l((i=i.apply(e,t||[])).next())})}function G(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function H(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const z=.1,V="function"==typeof Float32Array;function W(e,t){return 1-3*t+3*e}function q(e,t){return 3*t-6*e}function j(e){return 3*e}function Y(e,t,n){return((W(t,n)*e+q(t,n))*e+j(t))*e}function X(e,t,n){return 3*W(t,n)*e*e+2*q(t,n)*e+j(t)}function K(e){return e}function J(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){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===i)return K;const r=V?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=Y(t*z,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=z;--a;const s=i+(t-r[a])/(r[a+1]-r[a])*z,o=X(s,e,n);return o>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=X(t,n,i);if(0===r)return t;t-=(Y(t,n,i)-e)/r}return t}(t,s,e,n):0===o?s:function(e,t,n,i,r){let a,s,o=0;do{s=t+(n-t)/2,a=Y(s,i,r)-e,a>0?n=s:t=s}while(Math.abs(a)>1e-7&&++o<10);return s}(t,i,i+z,e,n)}return function(e){return 0===e||1===e?e:Y(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function Z(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort((e,t)=>e.time-t.time).map(({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:J(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const $="time",ee="interpolation",te="pitch",ne=[$,"yaw",te,"fov",ee],ie=Math.PI/180,re="ease-in-out",ae="cubic-bezier(";function se(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("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ne.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes($))throw new Error(`Missing required token: '${$}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=oe(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(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 i of e){const{time:e,pitch:r,yaw:a,fov:s}=i;if(null==e)throw new Error("Time missing.");const o=ce(null!==(t=i.interpolation)&&void 0!==t?t:re);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*ie,interpolation:o})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*ie,interpolation:o})),null!=s&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:s*ie,interpolation:o}))}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 oe(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 i=e.indexOf($),r=function(e){return e.endsWith("ms")?Ae(e.substring(0,e.length-2)):e.endsWith("s")?1e3*Ae(e.substring(0,e.length-1)):Ae(e)}(n[i]),a=e.indexOf(ee),s=ce(-1===a?re:n[a]),o={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":o.theta={time:r,value:le(c),interpolation:s};break;case te:o.phi={time:r,value:le(c),interpolation:s};break;case"fov":o.fov={time:r,value:le(c),interpolation:s};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return o}function le(e){return e.endsWith("deg")?Ae(e.substring(0,e.length-3))*ie:e.endsWith("rad")?Ae(e.substring(0,e.length-3)):Ae(e)*ie}function ce(e){if("hold"===e)return{type:"hold"};if("linear"===e)return he(0,0,1,1);if("sine"===e)return he(.37,0,.63,1);if("sine-in"===e)return he(.12,0,.39,0);if("sine-out"===e)return he(.61,1,.88,1);if("ease"===e)return he(.25,.1,.25,1);if("ease-in"===e)return he(.42,0,1,1);if("ease-out"===e)return he(0,0,.58,1);if("ease-in-out"===e)return he(.42,0,.58,1);if(e.startsWith(ae)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Ae(t[0]),y1:Ae(t[1]),x2:Ae(t[2]),y2:Ae(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function he(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function Ae(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2010-2024 Three.js Authors
|
package/dist/shopar-plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,function(e){"use strict";const t=["AR","3D"];class n extends Error{constructor(e){super(e),this.name="PluginError"}}class i extends n{constructor(e){super(e),this.name="ValidationError"}}class r extends n{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class a extends n{constructor(e){super(e),this.name="SanitizationError"}}class s extends n{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class o extends n{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class l extends o{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class c extends o{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function h(e,t,n,i){return new(n||(n=Promise))(function(r,a){function s(e){try{l(i.next(e))}catch(e){a(e)}}function o(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,o)}l((i=i.apply(e,t||[])).next())})}function A(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function u(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function d(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function p(e,t){return()=>h(this,void 0,void 0,function*(){try{return yield t()}catch(t){if(t instanceof n)throw t;throw new n(`${e} failed: ${u(t)}`)}})}const f=[Uint8Array,Uint32Array].length-2,g=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],m=[2,12,7,1],v=window[g[m[m[f]]]][g[m[m[m.length-1]]]];function E(){const e=(new TextEncoder).encode(v),t=g.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[g[t[2]]](String.fromCodePoint(...e))}v.charCodeAt(f);function b(e){return e*(180/Math.PI)}function C(e){return Math.round(100*e)/100}const _=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],I=["Shoes"];const x="1.1.0-alpha.4";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${x}/dist`;const w=e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},M=()=>y;function S(e,t){return h(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let B;function T(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>h(this,void 0,void 0,function*(){!function(){h(this,void 0,void 0,function*(){null==B&&(B=S(`${M()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield B;const a=`https://ar.shopar.ai/${x.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,s=yield window.ShopAR__QR.toDataURL(a),o=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=s,yield o,n=!1,e.style.display=""}),qrPause:()=>h(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const R={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},D=Object.keys(R);const Q="--shopar";function U(e){return`var(${e.var}, ${e.default})`}const L={padding:{var:`${Q}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${Q}-btn-gap`,default:"0.25rem"},border:{var:`${Q}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${Q}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${Q}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${Q}-btn-hover-bg`,default:"#f5f5f5"}};function P(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=U(L.padding),r.justifyContent="center",r.alignItems="center",r.gap=U(L.gap),r.backgroundColor=U(L.bg),r.border=U(L.border),r.borderRadius=U(L.borderRadius),r.cursor="pointer";const a=U(L.bg),s=U(L.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=s}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const N={paddingBottom:{var:`${Q}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${Q}-btn-container-gap`,default:"0.5rem"}};const F={bg:{var:`${Q}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${Q}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${Q}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${Q}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${Q}-ar-prompt-img-max-height`,default:"50%"}};const O={containerDisplay:{var:`${Q}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${Q}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${Q}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${Q}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${Q}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${Q}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${Q}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${Q}-ar-loading-bar-bg`,default:"#e5e7eb"}};const k={bg:{var:`${Q}-qr-bg`,default:"#ffffff"}};function G(e,t,n,i){return new(n||(n=Promise))(function(r,a){function s(e){try{l(i.next(e))}catch(e){a(e)}}function o(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,o)}l((i=i.apply(e,t||[])).next())})}function H(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function z(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const V=.1,W="function"==typeof Float32Array;function q(e,t){return 1-3*t+3*e}function j(e,t){return 3*t-6*e}function Y(e){return 3*e}function X(e,t,n){return((q(t,n)*e+j(t,n))*e+Y(t))*e}function K(e,t,n){return 3*q(t,n)*e*e+2*j(t,n)*e+Y(t)}function J(e){return e}function Z(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){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===i)return J;const r=W?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=X(t*V,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=V;--a;const s=i+(t-r[a])/(r[a+1]-r[a])*V,o=K(s,e,n);return o>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=K(t,n,i);if(0===r)return t;t-=(X(t,n,i)-e)/r}return t}(t,s,e,n):0===o?s:function(e,t,n,i,r){let a,s,o=0;do{s=t+(n-t)/2,a=X(s,i,r)-e,a>0?n=s:t=s}while(Math.abs(a)>1e-7&&++o<10);return s}(t,i,i+V,e,n)}return function(e){return 0===e||1===e?e:X(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function $(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:Z(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const ee="time",te="interpolation",ne="pitch",ie=[ee,"yaw",ne,"fov",te],re=Math.PI/180,ae="ease-in-out",se="cubic-bezier(";function oe(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("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ie.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes(ee))throw new Error(`Missing required token: '${ee}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=le(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(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 i of e){const{time:e,pitch:r,yaw:a,fov:s}=i;if(null==e)throw new Error("Time missing.");const o=he(null!==(t=i.interpolation)&&void 0!==t?t:ae);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*re,interpolation:o})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*re,interpolation:o})),null!=s&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:s*re,interpolation:o}))}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 le(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 i=e.indexOf(ee),r=function(e){return e.endsWith("ms")?ue(e.substring(0,e.length-2)):e.endsWith("s")?1e3*ue(e.substring(0,e.length-1)):ue(e)}(n[i]),a=e.indexOf(te),s=he(-1===a?ae:n[a]),o={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":o.theta={time:r,value:ce(c),interpolation:s};break;case ne:o.phi={time:r,value:ce(c),interpolation:s};break;case"fov":o.fov={time:r,value:ce(c),interpolation:s};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return o}function ce(e){return e.endsWith("deg")?ue(e.substring(0,e.length-3))*re:e.endsWith("rad")?ue(e.substring(0,e.length-3)):ue(e)*re}function he(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ae(0,0,1,1);if("sine"===e)return Ae(.37,0,.63,1);if("sine-in"===e)return Ae(.12,0,.39,0);if("sine-out"===e)return Ae(.61,1,.88,1);if("ease"===e)return Ae(.25,.1,.25,1);if("ease-in"===e)return Ae(.42,0,1,1);if("ease-out"===e)return Ae(0,0,.58,1);if("ease-in-out"===e)return Ae(.42,0,.58,1);if(e.startsWith(se)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:ue(t[0]),y1:ue(t[1]),x2:ue(t[2]),y2:ue(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ae(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function ue(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,function(e){"use strict";const t=["AR","3D"];class n extends Error{constructor(e){super(e),this.name="PluginError"}}class i extends n{constructor(e){super(e),this.name="ValidationError"}}class r extends n{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class a extends n{constructor(e){super(e),this.name="SanitizationError"}}class s extends n{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class o extends n{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class l extends o{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class c extends o{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function h(e,t,n,i){return new(n||(n=Promise))(function(r,a){function s(e){try{l(i.next(e))}catch(e){a(e)}}function o(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,o)}l((i=i.apply(e,t||[])).next())})}function A(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function u(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function d(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function p(e,t){return()=>h(this,void 0,void 0,function*(){try{return yield t()}catch(t){if(t instanceof n)throw t;throw new n(`${e} failed: ${u(t)}`)}})}const f=[Uint8Array,Uint32Array].length-2,g=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],m=[2,12,7,1],v=window[g[m[m[f]]]][g[m[m[m.length-1]]]];function E(){const e=(new TextEncoder).encode(v),t=g.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[g[t[2]]](String.fromCodePoint(...e))}v.charCodeAt(f);function b(e){return e*(180/Math.PI)}function C(e){return Math.round(100*e)/100}const _=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],I=["Shoes"];const x="1.1.0";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${x}/dist`;const w=e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},M=()=>y;function S(e,t){return h(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let B;function T(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>h(this,void 0,void 0,function*(){!function(){h(this,void 0,void 0,function*(){null==B&&(B=S(`${M()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield B;const a=`https://ar.shopar.ai/${x.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,s=yield window.ShopAR__QR.toDataURL(a),o=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=s,yield o,n=!1,e.style.display=""}),qrPause:()=>h(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const R={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},D=Object.keys(R);const Q="--shopar";function U(e){return`var(${e.var}, ${e.default})`}const L={padding:{var:`${Q}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${Q}-btn-gap`,default:"0.25rem"},border:{var:`${Q}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${Q}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${Q}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${Q}-btn-hover-bg`,default:"#f5f5f5"}};function P(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=U(L.padding),r.justifyContent="center",r.alignItems="center",r.gap=U(L.gap),r.backgroundColor=U(L.bg),r.border=U(L.border),r.borderRadius=U(L.borderRadius),r.cursor="pointer";const a=U(L.bg),s=U(L.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=s}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const N={paddingBottom:{var:`${Q}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${Q}-btn-container-gap`,default:"0.5rem"}};const F={bg:{var:`${Q}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${Q}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${Q}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${Q}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${Q}-ar-prompt-img-max-height`,default:"50%"}};const O={containerDisplay:{var:`${Q}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${Q}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${Q}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${Q}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${Q}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${Q}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${Q}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${Q}-ar-loading-bar-bg`,default:"#e5e7eb"}};const k={bg:{var:`${Q}-qr-bg`,default:"#ffffff"}};function G(e,t,n,i){return new(n||(n=Promise))(function(r,a){function s(e){try{l(i.next(e))}catch(e){a(e)}}function o(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,o)}l((i=i.apply(e,t||[])).next())})}function H(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function z(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const V=.1,W="function"==typeof Float32Array;function q(e,t){return 1-3*t+3*e}function j(e,t){return 3*t-6*e}function Y(e){return 3*e}function X(e,t,n){return((q(t,n)*e+j(t,n))*e+Y(t))*e}function K(e,t,n){return 3*q(t,n)*e*e+2*j(t,n)*e+Y(t)}function J(e){return e}function Z(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){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===i)return J;const r=W?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=X(t*V,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=V;--a;const s=i+(t-r[a])/(r[a+1]-r[a])*V,o=K(s,e,n);return o>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=K(t,n,i);if(0===r)return t;t-=(X(t,n,i)-e)/r}return t}(t,s,e,n):0===o?s:function(e,t,n,i,r){let a,s,o=0;do{s=t+(n-t)/2,a=X(s,i,r)-e,a>0?n=s:t=s}while(Math.abs(a)>1e-7&&++o<10);return s}(t,i,i+V,e,n)}return function(e){return 0===e||1===e?e:X(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function $(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:Z(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const ee="time",te="interpolation",ne="pitch",ie=[ee,"yaw",ne,"fov",te],re=Math.PI/180,ae="ease-in-out",se="cubic-bezier(";function oe(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("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ie.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes(ee))throw new Error(`Missing required token: '${ee}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=le(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(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 i of e){const{time:e,pitch:r,yaw:a,fov:s}=i;if(null==e)throw new Error("Time missing.");const o=he(null!==(t=i.interpolation)&&void 0!==t?t:ae);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*re,interpolation:o})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*re,interpolation:o})),null!=s&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:s*re,interpolation:o}))}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 le(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 i=e.indexOf(ee),r=function(e){return e.endsWith("ms")?ue(e.substring(0,e.length-2)):e.endsWith("s")?1e3*ue(e.substring(0,e.length-1)):ue(e)}(n[i]),a=e.indexOf(te),s=he(-1===a?ae:n[a]),o={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":o.theta={time:r,value:ce(c),interpolation:s};break;case ne:o.phi={time:r,value:ce(c),interpolation:s};break;case"fov":o.fov={time:r,value:ce(c),interpolation:s};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return o}function ce(e){return e.endsWith("deg")?ue(e.substring(0,e.length-3))*re:e.endsWith("rad")?ue(e.substring(0,e.length-3)):ue(e)*re}function he(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ae(0,0,1,1);if("sine"===e)return Ae(.37,0,.63,1);if("sine-in"===e)return Ae(.12,0,.39,0);if("sine-out"===e)return Ae(.61,1,.88,1);if("ease"===e)return Ae(.25,.1,.25,1);if("ease-in"===e)return Ae(.42,0,1,1);if("ease-out"===e)return Ae(0,0,.58,1);if("ease-in-out"===e)return Ae(.42,0,.58,1);if(e.startsWith(se)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:ue(t[0]),y1:ue(t[1]),x2:ue(t[2]),y2:ue(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ae(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function ue(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2010-2024 Three.js Authors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shopar-plugin",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",
|
|
5
5
|
"main": "dist/shopar-plugin.esm.js",
|
|
6
6
|
"module": "dist/shopar-plugin.esm.js",
|