shopar-plugin 0.0.8 → 0.0.9-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,7 +32,7 @@ There are two distinct ways of integrating the plugin: via Script tag and via NP
32
32
  Add the following script to your HTML.
33
33
 
34
34
  ```html
35
- <script src="https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.8/dist/shopar-plugin.js"></script>
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).
@@ -148,7 +148,7 @@ Options used for the plugin setup:
148
148
  - `baseUrl` (optional)
149
149
  - Type: `string`
150
150
  - If provided, defines where the additional ShopAR plugin files are fetched from.
151
- - Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.8/dist`
151
+ - Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@{{VERSION}}/dist`
152
152
  - `strings` (optional)
153
153
  - Type: `object`
154
154
  - If provided, overrides strings in the UI.
@@ -0,0 +1 @@
1
+ <svg width="869" height="1251" viewBox="0 0 869 1251" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_894_1533)"><path fill-rule="evenodd" clip-rule="evenodd" d="M303.44 353.132C304.829 314.64 330.051 282.714 363.992 272.987C371.106 271.049 378.436 270.01 385.808 269.895C391.367 269.895 396.717 270.486 401.893 271.424C439.69 278.372 467.899 309.36 467.899 346.462V654.953H511.671C613.911 606.665 685.371 500.36 685.371 376.165C685.571 306.213 662.333 238.211 619.365 183.01L604.427 165.64C577.851 136.528 545.96 112.766 510.212 96.1603C473.492 79.1377 432.881 69.4105 390.012 69.4105C347.143 69.4105 306.636 79.0683 269.812 96.1603C234.029 112.766 202.173 136.528 175.666 165.64L160.728 183.01C117.761 238.211 94.5225 306.213 94.722 376.165C94.714 391.336 95.8054 406.487 97.9875 421.5C99.0297 428.796 101.045 435.744 102.504 442.935L107.228 464.613C110.112 474.548 114.037 484.067 117.824 493.516L122.132 505.085C127.341 516.473 133.246 527.53 139.814 538.192L142.073 542.43C171.755 590.029 214.112 628.416 264.392 653.286L302.954 671.941V353.097L303.44 353.132Z" fill="white" fill-opacity="0.5"/><path fill-rule="evenodd" clip-rule="evenodd" d="M797.001 876.074L701.118 1144.96C695.143 1161.81 677.634 1172.75 657.589 1172.75H425.283C369.49 1172.75 317.867 1149.13 287.018 1109.53C231.711 1038.38 160.321 976.75 74.7561 926.447C71.4558 924.536 69.5451 921.687 69.4757 918.456C69.3367 914.982 71.0737 911.647 76.1805 908.139C95.6349 894.486 119.05 887.295 143.09 887.295C151.152 887.279 159.195 888.083 167.095 889.692L338.085 924.223V346.427C338.085 323.395 359.45 304.635 385.679 304.635C411.908 304.635 433.377 323.395 433.377 346.427V689.728H535.964C545.448 689.728 554.481 692.264 562.263 697.024L779.631 831.606C780.569 832.197 781.194 833.065 782.063 833.691C796.306 843.974 802.42 860.441 796.862 876.074M142.499 542.431C141.665 541.041 141.04 539.547 140.241 538.192C133.666 527.534 127.76 516.477 122.558 505.085C120.891 501.368 119.779 497.338 118.251 493.517L107.655 464.613C105.64 457.595 104.528 450.161 102.93 442.935L98.4141 421.501C96.2308 406.488 95.1394 391.336 95.1485 376.165C95.1485 302.968 119.953 235.815 161.155 183.011L176.093 165.641C202.634 136.459 234.525 112.731 270.238 96.1605C306.993 79.1379 347.569 69.4107 390.439 69.4107C433.308 69.4107 473.884 79.1379 510.639 96.1605C546.421 112.731 578.278 136.459 604.854 165.641L619.723 183.011C662.719 238.184 685.972 306.182 685.763 376.13C685.763 500.395 614.338 606.665 512.063 654.953H468.291V346.393C468.291 309.325 439.735 278.302 402.285 271.354C397.074 270.382 391.724 269.826 386.2 269.826C378.557 269.826 371.366 271.111 364.384 272.952C330.443 282.68 305.221 314.571 303.832 353.063V671.907L265.27 653.251C214.758 628.725 172.376 590.58 142.499 542.431ZM798.043 802.147L580.71 667.564C577.166 665.375 573.136 664.16 569.245 662.562C662.453 600.03 720.503 493.899 720.503 376.2C720.503 359.316 719.218 342.71 716.89 326.521C709.659 275.243 691.021 226.238 662.348 183.115L652.1 168.941L649.807 165.745C639.725 152.491 628.708 139.976 616.839 128.295C604.958 116.692 592.243 105.957 578.834 96.2647C538.709 67.2916 492.261 47.2118 441.958 38.9437L416.528 35.8866L390.543 34.8444C373.298 34.8447 356.082 36.2272 339.058 38.9785C288.789 47.2466 242.272 67.3263 202.182 96.2995C192.322 103.7 182.893 111.657 173.939 120.131C163.518 129.655 153.713 139.831 144.584 150.598L131.209 165.779L118.702 183.149L108.697 199.408L94.1758 226.436L92.7862 229.562C72.1854 274.029 60.478 323.708 60.478 376.234C60.478 509.358 136.281 631.295 253.632 686.741L303.554 710.364V882.188L173.765 855.994C163.608 853.965 153.273 852.964 142.916 853.006C142.325 853.006 141.735 853.11 141.179 853.11C132.425 853.249 123.705 854.257 115.124 855.89C112.364 856.472 109.619 857.121 106.891 857.835C100.186 859.433 93.62 861.552 87.1583 864.088C84.5528 865.13 81.9473 866.068 79.3418 867.562C70.6568 871.523 62.1803 876.039 54.2248 881.632C47.9431 885.96 42.8502 891.798 39.4144 898.609C35.9785 905.42 34.3099 912.986 34.562 920.61C34.9201 928.091 37.1618 935.359 41.079 941.742C44.9961 948.125 50.4619 953.415 56.9693 957.122C139.025 1004.85 207.116 1063.53 259.677 1131.24C264.329 1137.24 269.365 1142.94 274.754 1148.3C312.482 1185.88 367.024 1207.81 425.04 1207.88H657.693C683.679 1207.84 707.372 1196.31 722.24 1177.58C727.173 1171.33 731.134 1164.38 733.913 1156.67L829.691 887.781C832.957 878.749 834.207 869.369 833.582 860.197C832.957 851.026 830.525 842.133 826.53 833.795C820.225 820.757 810.33 809.79 798.008 802.182" fill="black" fill-opacity="0.6"/><path fill-rule="evenodd" clip-rule="evenodd" d="M779.738 831.676L562.37 697.093C554.446 692.276 545.346 689.739 536.072 689.763H433.485V346.532C433.485 323.499 412.085 304.74 385.787 304.74C359.489 304.74 338.193 323.499 338.193 346.532V924.71L167.203 890.178C159.291 888.569 151.236 887.766 143.163 887.781C119.267 887.676 95.9182 894.929 76.2881 908.555C71.1813 912.099 69.4096 915.434 69.5485 918.908C69.6875 922.174 71.5635 925.022 74.8638 926.898C160.394 977.202 231.784 1038.76 287.125 1109.98C317.94 1149.58 369.563 1173.2 425.39 1173.2H657.662C677.707 1173.2 695.181 1161.88 701.191 1145.41L797.074 876.525C802.632 860.962 796.483 844.46 782.274 834.142C781.406 833.448 780.781 832.649 779.843 832.058L779.738 831.676Z" fill="white"/><mask id="mask0_894_1533" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="869" height="1243"><path d="M0.0664062 0.0349731H868.462V1242.62H0.0664062V0.0349731Z" fill="white"/></mask><g mask="url(#mask0_894_1533)"><path fill-rule="evenodd" clip-rule="evenodd" d="M833.58 860.197C834.209 869.559 832.897 878.95 829.724 887.781L733.911 1156.67C731.132 1164.31 727.172 1171.36 722.239 1177.58C707.405 1196.34 683.677 1207.81 657.727 1207.88H425.038C367.022 1207.81 312.481 1185.88 274.753 1148.3C269.403 1142.95 264.331 1137.25 259.676 1131.27C207.114 1063.57 139.024 1004.89 57.2458 956.809C43.8709 948.993 35.4985 935.34 34.8385 920.332C34.5864 912.708 36.255 905.143 39.6909 898.332C43.1267 891.521 48.2196 885.682 54.5013 881.354C62.4292 875.912 70.8363 871.202 79.6183 867.284L87.4348 863.81C93.8598 861.272 100.453 859.183 107.167 857.557L115.401 855.612C124.016 854.014 132.771 853.006 141.456 852.833C142.081 852.833 142.637 852.728 143.193 852.728C153.719 852.694 163.932 853.666 174.111 855.716L303.413 881.84V710.399L253.527 686.775C136.21 631.33 60.3724 509.393 60.3724 376.269C60.3724 323.812 72.045 274.134 92.6806 229.597C93.2017 228.555 93.5491 227.513 94.0702 226.47C98.4821 217.195 103.38 208.232 108.591 199.443C111.822 193.884 115.053 188.465 118.597 183.184C120.785 179.884 123.217 176.723 125.545 173.561L131.138 165.675C135.237 160.291 140.17 155.601 144.513 150.494C153.753 140.072 163.411 129.511 173.868 120.027C182.822 111.552 192.251 103.596 202.112 96.1953C242.202 67.2569 288.753 47.2119 339.022 38.8743C356.034 36.1219 373.239 34.7394 390.472 34.7402C399.145 34.7313 407.815 35.0906 416.457 35.8172C425.038 36.512 433.48 37.5542 441.922 38.8743C492.225 47.1424 538.707 67.2221 578.797 96.1953C592.242 105.923 604.922 116.622 616.803 128.226C628.681 139.898 639.699 152.413 649.771 165.675L652.064 168.871C655.607 173.492 659.116 178.182 662.312 183.045C690.997 226.166 709.647 275.171 716.889 326.452C719.182 342.676 720.467 359.281 720.467 376.13C720.467 493.829 662.451 600.307 569.244 662.492C573.065 664.09 577.13 665.271 580.708 667.495L798.041 802.077C810.895 810.068 820.449 821.184 826.528 833.343C830.523 841.681 832.955 850.644 833.58 859.746M857.794 818.231C848.588 799.124 834.275 783.248 816.315 772.166L631.394 657.628C709.732 586.863 755.207 484.971 755.207 375.748C755.207 299.667 733.078 226.227 691.285 163.348C686.908 156.817 682.253 150.494 677.389 144.171C654.982 114.712 628.684 88.5872 599.155 67.6043C537.561 23.5887 465.337 0.0349731 390.472 0.0349731C315.457 0.0670918 242.383 23.8817 181.754 68.0559C152.294 89.3863 125.961 115.163 103.485 144.658C98.7601 150.911 94.0354 157.268 89.6582 163.765C47.7965 226.679 25.6671 300.119 25.6671 376.2C25.6671 522.733 109.286 656.899 238.728 718.111L268.708 732.354V839.77L180.99 822.053C168.622 819.621 156.081 818.37 143.609 818.37C104.55 818.376 66.4474 830.462 34.5258 852.971C11.8406 868.952 -0.978479 894.729 0.133201 921.861C0.732449 935.148 4.66826 948.071 11.5776 959.437C18.4869 970.803 28.1472 980.245 39.6673 986.894C117.485 1032.68 182.31 1088.44 232.231 1152.67C276.004 1208.95 348.02 1242.65 425.038 1242.72H657.727C707.057 1242.68 750.83 1212.84 766.602 1168.45L862.484 899.558C871.933 873.26 870.266 844.53 857.829 818.787" fill="black" fill-opacity="0.05"/></g></g><defs><clipPath id="clip0_894_1533"><rect width="868.5" height="1250.64" fill="white"/></clipPath></defs></svg>
@@ -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 x extends v{batch={};ingest=(t,e,i)=>{const n=function(t,e){return`${t}:${e?.timestampField||"-"}:${e?.timestampFormat||"-"}:${e?.csvDelimiter||"-"}`}(t,i);return this.batch[n]||(this.batch[n]=new w(((t,e,i)=>{const n=(Array.isArray(e)?e:[e]).map((t=>JSON.stringify(t))).join("\n");return this.ingestRaw(t,n,y.NDJSON,p.Identity,i)}),t,i)),this.batch[n].ingest(e)};flush=async()=>{let t=[];for(const e in this.batch)t.push(this.batch[e].flush());await Promise.all(t)}}let b;!function(t){t.JSON="application/json",t.NDJSON="application/x-ndjson",t.CSV="text/csv"}(y||(y={})),function(t){t.Identity="",t.GZIP="gzip"}(p||(p={})),function(t){t.Count="count",t.Distinct="distinct",t.Sum="sum",t.Avg="avg",t.Min="min",t.Max="max",t.Topk="topk",t.Percentiles="percentiles",t.Histogram="histogram",t.Variance="variance",t.Stdev="stdev",t.ArgMin="argmin",t.ArgMax="argmax",t.MakeSet="makeset",t.MakeSetIf="makesetif",t.CountIf="countif",t.CountDistinctIf="distinctif"}(d||(d={})),function(t){t.And="and",t.Or="or",t.Not="not",t.Equal="==",t.NotEqual="!=",t.Exists="exists",t.NotExists="not-exists",t.GreaterThan=">",t.GreaterThanOrEqualTo=">=",t.LessThan="<",t.LessThanOrEqualTo="<=",t.Gt="gt",t.Gte="gte",t.Lt="lt",t.Lte="lte",t.StartsWith="starts-with",t.NotStartsWith="not-starts-with",t.EndsWith="ends-with",t.NotEndsWith="not-ends-with",t.Contains="contains",t.NotContains="not-contains",t.Regexp="regexp",t.NotRegexp="not-regexp"}(g||(g={})),t.initializeImpl=function(){b=new x({token:"xaat-f69a9dd7-3988-4fc2-849b-4a0978468c25"})},t.trackEventImpl=function(t,e){b.ingest("shopar-plugin",Object.assign({name:t},e))}}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ShopAR__analytics={})}(this,(function(t){"use strict";function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t){return Number.isInteger(t)&&t>=0}function n(t){this.name="ArgumentError",this.message=t}var s=e((function(t,e){if(e=e||{},"function"!=typeof t)throw new n("fetch must be a function");if("object"!=typeof e)throw new n("defaults must be an object");if(void 0!==e.retries&&!i(e.retries))throw new n("retries must be a positive integer");if(void 0!==e.retryDelay&&!i(e.retryDelay)&&"function"!=typeof e.retryDelay)throw new n("retryDelay must be a positive integer or a function returning a positive integer");if(void 0!==e.retryOn&&!Array.isArray(e.retryOn)&&"function"!=typeof e.retryOn)throw new n("retryOn property expects an array or function");return e=Object.assign({retries:3,retryDelay:1e3,retryOn:[]},e),function(s,r){var a=e.retries,o=e.retryDelay,c=e.retryOn;if(r&&void 0!==r.retries){if(!i(r.retries))throw new n("retries must be a positive integer");a=r.retries}if(r&&void 0!==r.retryDelay){if(!i(r.retryDelay)&&"function"!=typeof r.retryDelay)throw new n("retryDelay must be a positive integer or a function returning a positive integer");o=r.retryDelay}if(r&&r.retryOn){if(!Array.isArray(r.retryOn)&&"function"!=typeof r.retryOn)throw new n("retryOn property expects an array or function");c=r.retryOn}return new Promise((function(e,i){var n=function(n){var o="undefined"!=typeof Request&&s instanceof Request?s.clone():s;t(o,r).then((function(t){if(Array.isArray(c)&&-1===c.indexOf(t.status))e(t);else if("function"==typeof c)try{return Promise.resolve(c(n,null,t)).then((function(i){i?u(n,null,t):e(t)})).catch(i)}catch(t){i(t)}else n<a?u(n,null,t):e(t)})).catch((function(t){if("function"==typeof c)try{Promise.resolve(c(n,t,null)).then((function(e){e?u(n,t,null):i(t)})).catch((function(t){i(t)}))}catch(t){i(t)}else n<a?u(n,t,null):i(t)}))};function u(t,e,i){var s="function"==typeof o?o(t,e,i):o;setTimeout((function(){n(++t)}),s)}n(0)}))}}));var r,a;!function(t){t.unknown="unknown",t.user="user",t.organization="organization",t.anonymous="anonymous"}(r||(r={})),function(t){t.api="api",t.query="query",t.ingest="ingest"}(a||(a={}));class o{scope;type;value;remaining;reset;constructor(t=r.unknown,e=a.api,i=0,n=-1,s=new Date){this.scope=t,this.type=e,this.value=i,this.remaining=n,this.reset=s}}function c(t,e,i,n,s){let a=new o;const c=t.headers.get(e.toLowerCase())||r.unknown;a.scope=r[c];const u=t.headers.get(i.toLowerCase())||"",h=parseInt(u,10);isNaN(h)||(a.value=h);const l=t.headers.get(n.toLowerCase())||"",f=parseInt(l,10);isNaN(f)||(a.remaining=f);const m=t.headers.get(s.toLowerCase())||"",y=parseInt(m,10);return isNaN(y)||(a.reset=new Date(1e3*y)),a}class u{config;constructor(t){this.config=t}async doReq(t,e,i={},n={}){let r=`${this.config.baseUrl}${t}`;const o=this._prepareSearchParams(n);o&&(r+=`?${o.toString()}`);const u={...this.config.headers,...i.headers},l=await s(fetch)(r,{retries:3,retryDelay:function(t,e,i){return 1e3*Math.pow(2,t)},retryOn:[503,502,504,500],headers:u,method:e,body:i.body?i.body:void 0});if(204===l.status)return l;if(429==l.status){const t=function(t){let e;return t.url?.endsWith("/ingest")?(e=c(t,"","X-IngestLimit-Limit","X-IngestLimit-Remaining","X-IngestLimit-Reset"),e.type=a.ingest):t.url?.endsWith("/query")||t.url?.endsWith("/_apl")?(e=c(t,"","X-QueryLimit-Limit","X-QueryLimit-Remaining","X-QueryLimit-Reset"),e.type=a.query):(e=c(t,"X-RateLimit-Scope","X-RateLimit-Limit","X-RateLimit-Remaining","X-RateLimit-Reset"),e.type=a.api),e}(l);return Promise.reject(new h(t))}if(401===l.status)return Promise.reject(new Error("Forbidden"));if(l.status>=400){const t=await l.json();return Promise.reject(new Error(t.message))}return await l.json()}post(t,e={},i={}){return this.doReq(t,"POST",e,i)}get(t,e={},i={}){return this.doReq(t,"GET",e,i)}put(t,e={},i={}){return this.doReq(t,"PUT",e,i)}delete(t,e={},i={}){return this.doReq(t,"DELETE",e,i)}_prepareSearchParams=t=>{const e=new URLSearchParams;let i=!1;return Object.keys(t).forEach((n=>{t[n]&&(e.append(n,t[n]),i=!0)})),i?e:null}}class h extends Error{limit;shortcircuit;message="";constructor(t,e=!1){super(),this.limit=t,this.shortcircuit=e,Object.setPrototypeOf(this,h.prototype);const i=h.timeUntilReset(t);this.message=`${t.type} limit exceeded, try again in ${i.minutes}m${i.seconds}s`,t.type==a.api&&(this.message=`${t.scope} `+this.message)}static timeUntilReset(t){const e=t.reset.getTime()-(new Date).getTime(),i=Math.floor(e/1e3%60);return{total:e,minutes:Math.floor(e/1e3/60%60),seconds:i}}}class l{client;constructor({orgId:t="",token:e,url:i}){e||console.warn("Missing Axiom token");const n=i??"https://api.axiom.co",s={Accept:"application/json","Content-Type":"application/json",Authorization:"Bearer "+e};"undefined"==typeof window&&(s["User-Agent"]="axiom-js/1.0.0-rc.1"),t&&(s["X-Axiom-Org-Id"]=t),this.client=new u({baseUrl:n,headers:s,timeout:3e3})}}var f,m,y,p,d,g;!function(t){t.TimestampField="_time";t.Service=class extends l{localPath="/v1/datasets";list=()=>this.client.get(this.localPath);get=t=>this.client.get(this.localPath+"/"+t);create=t=>this.client.post(this.localPath,{body:JSON.stringify(t)});update=(t,e)=>this.client.put(this.localPath+"/"+t,{body:JSON.stringify(e)});delete=t=>this.client.delete(this.localPath+"/"+t);trim=(t,e)=>{const i={maxDuration:e};return this.client.post(this.localPath+"/"+t+"/trim",{body:JSON.stringify(i)})}}}(f||(f={})),function(t){t.Service=class extends l{current=()=>this.client.get("/v1/user")}}(m||(m={}));class w{ingestFn;id;options;events=[];activeFlush=Promise.resolve();nextFlush=setTimeout((()=>{}),0);lastFlush=new Date;constructor(t,e,i){this.ingestFn=t,this.id=e,this.options=i}ingest=t=>{Array.isArray(t)?this.events=this.events.concat(t):this.events.push(t),this.events.length>=1e3||this.lastFlush.getTime()<Date.now()-1e3?(clearTimeout(this.nextFlush),this.activeFlush=this.flush()):(clearTimeout(this.nextFlush),this.nextFlush=setTimeout((()=>{this.activeFlush=this.flush()}),1e3))};flush=async()=>{const t=this.events.splice(0,this.events.length);if(clearTimeout(this.nextFlush),await this.activeFlush,0===t.length)return void(this.lastFlush=new Date);const e=await this.ingestFn(this.id,t,this.options);return this.lastFlush=new Date,e}}class v extends l{datasets;users;localPath="/v1";constructor(t){super(t),this.datasets=new f.Service(t),this.users=new m.Service(t)}ingestRaw=(t,e,i=y.JSON,n=p.Identity,s)=>this.client.post(this.localPath+"/datasets/"+t+"/ingest",{headers:{"Content-Type":i,"Content-Encoding":n},body:e},{"timestamp-field":s?.timestampField,"timestamp-format":s?.timestampFormat,"csv-delimiter":s?.csvDelimiter});queryLegacy=(t,e,i)=>this.client.post(this.localPath+"/datasets/"+t+"/query",{body:JSON.stringify(e)},{"streaming-duration":i?.streamingDuration,nocache:i?.noCache});query=(t,e)=>{const i={apl:t};return e?.startTime&&(i.startTime=e?.startTime),e?.endTime&&(i.endTime=e?.endTime),this.client.post(this.localPath+"/datasets/_apl",{body:JSON.stringify(i)},{"streaming-duration":e?.streamingDuration,nocache:e?.noCache,format:"legacy"})};aplQuery=(t,e)=>this.query(t,e)}class b extends v{batch={};ingest=(t,e,i)=>{const n=function(t,e){return`${t}:${e?.timestampField||"-"}:${e?.timestampFormat||"-"}:${e?.csvDelimiter||"-"}`}(t,i);return this.batch[n]||(this.batch[n]=new w(((t,e,i)=>{const n=(Array.isArray(e)?e:[e]).map((t=>JSON.stringify(t))).join("\n");return this.ingestRaw(t,n,y.NDJSON,p.Identity,i)}),t,i)),this.batch[n].ingest(e)};flush=async()=>{let t=[];for(const e in this.batch)t.push(this.batch[e].flush());await Promise.all(t)}}let x;!function(t){t.JSON="application/json",t.NDJSON="application/x-ndjson",t.CSV="text/csv"}(y||(y={})),function(t){t.Identity="",t.GZIP="gzip"}(p||(p={})),function(t){t.Count="count",t.Distinct="distinct",t.Sum="sum",t.Avg="avg",t.Min="min",t.Max="max",t.Topk="topk",t.Percentiles="percentiles",t.Histogram="histogram",t.Variance="variance",t.Stdev="stdev",t.ArgMin="argmin",t.ArgMax="argmax",t.MakeSet="makeset",t.MakeSetIf="makesetif",t.CountIf="countif",t.CountDistinctIf="distinctif"}(d||(d={})),function(t){t.And="and",t.Or="or",t.Not="not",t.Equal="==",t.NotEqual="!=",t.Exists="exists",t.NotExists="not-exists",t.GreaterThan=">",t.GreaterThanOrEqualTo=">=",t.LessThan="<",t.LessThanOrEqualTo="<=",t.Gt="gt",t.Gte="gte",t.Lt="lt",t.Lte="lte",t.StartsWith="starts-with",t.NotStartsWith="not-starts-with",t.EndsWith="ends-with",t.NotEndsWith="not-ends-with",t.Contains="contains",t.NotContains="not-contains",t.Regexp="regexp",t.NotRegexp="not-regexp"}(g||(g={})),t.initializeImpl=function(){x=new b({token:"xaat-16d05fdd-4ab9-4990-acba-7cee24974bfb"})},t.trackEventImpl=function(t,e){x.ingest("shopar-plugin-alpha",Object.assign({name:t},e))}}));
@@ -1 +1 @@
1
- function e(e,t,n,o){return new(n||(n=Promise))((function(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}"};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"],g=["Shoes"];const m="0.0.8";let v=`https://cdn.jsdelivr.net/npm/shopar-plugin@${m}/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,E,A;function C(e){const t=function(e){const t=new E.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,E.ClampToEdgeWrapping,E.ClampToEdgeWrapping,E.LinearFilter,E.LinearFilter,1,E.LinearEncoding);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(A.parse(e));return t.mapping=E.EquirectangularReflectionMapping,t.encoding=E.LinearEncoding,t}const I=45,L=45,k=3,P=1.5,T=1,x=.5;let M,U,$,D,_,N,j=!1;const O=0;let q,G,W,Q=!1,F=1,V=1,H=1;const B=1;let K;const z=new Map;function X(t){const n=t.getContext("2d");null==n&&console.warn("2D context missing.");let o,r,i,a,s,c,l,d,u=!1,h=!0,p=!1,f=1,g=1,m=1;const v={threeInit:()=>{u||(Z(),o=new G.Scene,r=new G.PerspectiveCamera(25,1,.5),i=new q.OrbitControls(r,t),i.enableInteraction(),({renderShadow:s,shadowGroup:a}=function(e){const t=new M.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new M.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new M.Group;o.position.y=-.7;const r=new M.PlaneGeometry(I,L).rotateX(Math.PI/2),i=new M.MeshBasicMaterial({map:t.texture,opacity:x,transparent:!0,depthWrite:!1}),a=new M.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new M.Mesh(r);s.visible=!1,o.add(s);const c=new M.OrthographicCamera(-I/2,I/2,L/2,-L/2,0,k);function l(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,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=$;const o=U.getClearAlpha();U.setClearAlpha(0),U.setRenderTarget(t),U.render(e,c),e.overrideMaterial=null,l(P),l(.4*P),U.setRenderTarget(null),U.setClearAlpha(o),e.background=n}}}(o)),u=!0)},threeParse:(t,n,r)=>e(this,void 0,void 0,(function*(){return null!=c&&l===r||(yield c,c=(()=>e(this,void 0,void 0,(function*(){var e,r;return E=(e=q).THREE,A=new e.RGBELoader,o.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("function"==typeof t.MeshoptDecoder?t.MeshoptDecoder():t.MeshoptDecoder)}(K,q),r=t,S.parseAsync(r.buffer,"")})))(),l=r),c})),threeLoad:(e,t)=>{o.clear(),o.add(e.scene);const n=(new G.Box3).setFromObject(e.scene);a.position.y=n.min.y-O,o.add(a),s(),o.traverse((e=>{if(e instanceof G.Mesh){const t=e.material;t.depthWrite=!0,t instanceof G.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),c=Math.sqrt(q.reduceVertices(e.scene,((e,t)=>Math.max(e,r.distanceToSquared(t))),0));i.reset(r,c,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,G.Vector3))},threePaused:()=>h,threeResume:()=>{h=!1,K.setAnimationLoop(Y),t.style.visibility="visible"},threePause:()=>{h=!0,function(){for(const{threePaused:e}of z.values())if(!e())return!1;return!0}()&&K.setAnimationLoop(null),t.style.visibility="hidden"},threeSetOnInteracted:e=>{i.removeEventListener("change",d),d=e,i.addEventListener("change",e)},preRender_:()=>{u&&!h&&i.update()&&(p=!0)},shouldRender_:()=>!(!u||h)&&p,render_:()=>{K.setViewport(0,0,t.width,t.height),K.render(o,r),p=!1,null!=n&&(n.clearRect(0,0,t.width,t.height),n.drawImage(W,0,V-t.height,t.width,t.height,0,0,t.width,t.height))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===f&&n===g&&H===m||(t.width=Math.ceil(e*H*B),t.height=Math.ceil(n*H*B),f=e,g=n,m=H,p=!0)},target_:t};return z.set(t,v),v}function Z(){if(Q)return;q=window.ShopAR__THREE,G=q.THREE,W=document.createElement("canvas");var e,t;W.style.position="block",K=new G.WebGLRenderer({powerPreference:"high-performance",canvas:W,antialias:!0,alpha:!0}),K.outputEncoding=G.sRGBEncoding,K.toneMapping=G.ACESFilmicToneMapping,K.setClearColor(new G.Color(16777215)),e=K,t=q,j||(M=t.THREE,U=e,$=new M.MeshDepthMaterial,$.userData.darkness={value:T},$.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 M.ShaderMaterial(t.HorizontalBlurShader),D.depthTest=!1,_=new M.ShaderMaterial(t.VerticalBlurShader),_.depthTest=!1,j=!0),J(),Q=!0}function Y(){J(),K.clear();for(const{preRender_:e,shouldRender_:t,render_:n}of z.values())e(),t()&&n()}function J(){let e=0,t=0;for(const{target_:n}of z.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*B),t=Math.ceil(t*n*B),e===F&&t===V&&n===H||(F=e,V=t,H=n,K.setSize(F,V,!1));for(const{updateSize_:e}of z.values())e()}const ee={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},te=Object.keys(ee);function ne(e){return ee[e]}function oe(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const re="shopar-error";function ie(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=oe("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 ae="shopar-control";const se="shopar-deepar-output";function ce(e){const t=document.createElement("div");t.className=e,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 le(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function de(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 ue(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 he="shopar-main";const pe="shopar-qr-output";const fe="shopar-three-output";var ge;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(ge||(ge={}));let me=!1;function ve(){me||(!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.")}}(),me=!0)}function we(){ve();const e=function(){const e=document.createElement("div");e.id=he;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=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),n=function(e){const t=document.createElement("div");t.id=pe;const n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",t.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),t}(t);e.appendChild(n);const o=function(){const e=document.createElement("div");e.id=se;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 r=function(){const e=document.createElement("canvas");e.id=fe;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(r);const i=ce("shopar-ar-loading-container"),a=le("shopar-ar-loading-text",ne("loading.ar"));i.appendChild(a);const s=de("shopar-ar-loading-bar-bg"),c=ue("shopar-ar-loading-bar-fg");s.appendChild(c),i.appendChild(s),e.appendChild(i);const l=ce("shopar-3d-loading-container"),d=le("shopar-3d-loading-text",ne("loading.3d"));l.appendChild(d);const u=de("shopar-3d-loading-bar-bg"),h=ue("shopar-3d-loading-bar-fg");u.appendChild(h),l.appendChild(u),e.appendChild(l);const p=function(){const e=document.createElement("div");e.id=re;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const r=oe("4rem",`${w}/img/icons/close.svg`);n.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",n.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}();e.appendChild(p);const f=function(){const e=document.createElement("div");return e.id=ae,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(f);const g=ie("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");f.appendChild(g);const m=ie("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${w}/img/icons/cube.svg`);f.appendChild(m);const v=ie("shopar-btn-close","Close","Close ShopAR view",`${w}/img/icons/close.svg`);f.append(v);let y,b=ge.None,R=!1,S=!1,E=!1,A=!1;function C(){c.classList.remove("active"),i.style.visibility="hidden"}function I(){h.classList.remove("active"),l.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return n},getQRImage:function(){return t},getDeepARTarget:function(){return o},getThreeTarget:function(){return r},setVisibilityParameters:function(e,t,n,o,r){var i;R=e,S=t,E=n,A=o,y=r,ye(f,R),ye(g,R&&(E||S)&&b===ge.None),ye(m,R&&A&&b===ge.None),ye(v,R&&b!==ge.None),C(),I(),R||""===(i=p).style.display&&ye(i,!1)},getUIState:function(){return b},setUIState:function(e){b=e,b===ge.None?(C(),I(),R&&(ye(p,!1),ye(v,!1),(S||E)&&ye(g,!0),A&&ye(m,!0))):b!==ge.QR&&b!==ge.AR&&b!==ge.Preview||R&&(ye(p,!1),ye(g,!1),ye(m,!1),ye(v,!0))},setDefaultUIActions:function(e,t,n){R&&((S||E)&&(!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}`;g.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(y),g.onclick=e),A&&(m.onclick=t),v.onclick=n)},startDeepARLoading:function(){c.classList.add("active"),i.style.visibility="visible"},stopDeepARLoading:C,startThreeLoading:function(){h.classList.add("active"),l.style.visibility="visible"},stopThreeLoading:I,showCameraError:function(){R&&ye(p,!0)}}}function ye(e,t){e.style.display=t?"":"none"}const be=new Map;function Re(t){let n=be.get(t);return null==n?(n=function(){let t=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=we()),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/${m.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}=i();r=X(e())}return r}}}(),be.set(t,n)):n.incrementSetupId_(),n}function Se(e){for(const t of be.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===ge.AR&&r(ge.None)}}let Ee;const Ae=new Uint8Array(16);function Ce(){if(!Ee&&(Ee="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ee))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ee(Ae)}const Ie=[];for(let e=0;e<256;++e)Ie.push((e+256).toString(16).slice(1));var Le={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ke(e,t,n){if(Le.randomUUID&&!t&&!e)return Le.randomUUID();const o=(e=e||{}).random||(e.rng||Ce)();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 Ie[e[t+0]]+Ie[e[t+1]]+Ie[e[t+2]]+Ie[e[t+3]]+"-"+Ie[e[t+4]]+Ie[e[t+5]]+"-"+Ie[e[t+6]]+Ie[e[t+7]]+"-"+Ie[e[t+8]]+Ie[e[t+9]]+"-"+Ie[e[t+10]]+Ie[e[t+11]]+Ie[e[t+12]]+Ie[e[t+13]]+Ie[e[t+14]]+Ie[e[t+15]]}(o)}const Pe="qrLaunch",Te="arLaunch",xe="previewLaunch",Me="heartbeat";let Ue,$e,De=!1;const _e=[];function Ne(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(Me,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:m,sessionId:$e,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},De?a():_e.push(a)};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)}}}function je(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Oe(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 qe=200,Ge=10;let We,Qe,Fe,Ve=!1;function He(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let Be,Ke,ze,Xe,Ze,Ye,Je,et,tt=!0;function nt(e){e!==Fe&&(Fe=e,He(e),Ye=null,Ve=!0)}function ot(n,o){return e(this,void 0,void 0,(function*(){return ze=o,null==Ze&&(Ze=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new t("No camera available!");var r;const i=ct(o),a=je(i),s=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(o);Be=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:n||"your_license_key_goes_here",previewElement:Xe,additionalOptions:{hint:s,cameraConfig:{disableDefaultCamera:!0}}}),Ke=yield Oe(a),yield lt(Be,Ke,"user"===i),"Glasses"===o&&(yield Qe,function(t,n){e(this,void 0,void 0,(function*(){Ve=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${w}/wasm/mediapipe`,t);const r=[],i=setInterval((()=>e(this,void 0,void 0,(function*(){if(Ve)return void clearInterval(i);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(Ve)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<Ge)return void r.push(t);clearInterval(i);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(r)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),qe)}))}(Ke,Be))})))()),Ze}))}function rt(t){return e(this,void 0,void 0,(function*(){t!==Xe&&(Xe=t,null!=Be&&Be.changePreviewElement(Xe))}))}function it(e){Be.callbacks.onFaceTracked=t=>{t.some((e=>e.detected))&&e()},Be.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&e()},Be.callbacks.onWristTracked=t=>{t.detected&&e()}}function at(t,n){return e(this,void 0,void 0,(function*(){return null!=Ye&&Je===n||(yield Ye,Ye=Be.switchEffect(t),Je=n),Ye}))}function st(){null!=Be&&(tt=!0,Be.setPaused(tt),null!=Ke&&null!=Ke.srcObject&&Ke.srcObject instanceof MediaStream&&(Ke.srcObject.getTracks().forEach((e=>e.stop())),Ke=null),Be.stopCamera(),Xe.style.display="none")}function ct(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function lt(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 dt(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),g=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],m=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield g(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),v=new n[0](yield(yield m.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 ut(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function ht(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const pt=["AR","3D"];function ft(e){const{apiKey:n,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:c}=e;ut(n,"apiKey"),ht(n,"apiKey"),ut(o,"sku"),ht(o,"sku"),ut(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",pt),null!=a&&ht(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",te)}function gt(n){var o,r;return e(this,void 0,void 0,(function*(){ft(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(ee,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(ee[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=Re(s),{getSetupId:h,findUI:m,findQR:v,findThree:R}=u,S=h();null==Ue&&($e=ke(),Ue=y(`${w}/shopar-analytics.js`),Ue.then((()=>{De=!0,window.ShopAR__analytics.initializeImpl(),_e.forEach((e=>e()))})));const{trackEvent:E,arInteracted:A,previewInteracted:C}=Ne(a,i);E("setup",{hostname:window.location.hostname});const I=yield l;E("apiResponse",I);const{category:L,arUrl:k,arKey:P,previewUrl:T,previewEnvUrl:x}=I;mt(h(),S);const M=null!=k&&function(e){return null!=e&&f.includes(e)}(L),U=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled),$=M&&function(e){return null!=e&&g.includes(e)}(L),D=U&&$&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==et&&(et=y(`${w}/shopar-platform.js`)),yield et,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}()),_=M&&!D,j=null!=T;if(mt(h(),S),D&&function(){e(this,void 0,void 0,(function*(){null==b&&(b=y(`${w}/shopar-qr.js`))}))}(),_&&(null==We&&(We=y(`${w}/shopar-deepar.js`)),nt(k),"Glasses"===L&&null==Qe&&(Qe=y(`${w}/shopar-true-scale.js`))),j){null==N&&(N=y(`${w}/shopar-three.js`));const e=255;dt(T,(new Date).getTime()+e,Math.random()*e),He(null!=x?x:`${w}/env/default.hdr`)}const{setTargetElement:O,getDeepARTarget:q,setVisibilityParameters:G,getUIState:W,setUIState:Q,setDefaultUIActions:F,startDeepARLoading:V,stopDeepARLoading:H,startThreeLoading:B,stopThreeLoading:K,showCameraError:z}=m();O(s);G(null==n.defaultUI||n.defaultUI,D,_,j,L),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,(()=>{W()!==ge.QR||X()||Y(),W()!==ge.AR||tt||st(),W()!==ge.Preview||oe()||ie(),Q(ge.None)}));const{qrPaused:X,qrDraw:Z,qrPause:Y}=v(),{threeInit:J,threeParse:te,threeLoad:ne,threePaused:oe,threeResume:re,threePause:ie,threeSetOnInteracted:ae}=R();let se=0;if(W()===ge.QR){if(!X())if(D){E(Pe);try{yield Z(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Y(),Q(ge.None)}else if(W()===ge.AR){if(!tt)if(_){E(Te);const e=yield He(k);mt(h(),S),Se(u),rt(q()),yield at(e,k),it(A),mt(h(),S)}else st(),Q(ge.None)}else if(W()===ge.Preview&&!oe())if(j){E(xe),B();const e=255,t=yield dt(T,(new Date).getTime()+e,Math.random()*e);mt(h(),S);const n=yield He(null!=x?x:`${w}/env/default.hdr`);mt(h(),S);const o=yield te(t,n,`${T}${x}`);mt(h(),S),ne(o,L),ae(C),K()}else ie(),Q(ge.None);const ce=()=>e(this,void 0,void 0,(function*(){if(D){if(W()===ge.QR||W()===ge.AR)throw new t("AR already launched.");try{E(Pe);const e=++se;if(W()===ge.Preview&&j&&!oe()&&ie(),Q(ge.QR),yield Z(i,a),se!==e)return;return void mt(h(),S)}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(!_)throw new t("Model does not have AR enabled.");if(W()===ge.AR)throw new t("AR already launched.");try{E(Te);const t=++se;W()===ge.Preview&&j&&!oe()&&ie(),Se(u),Q(ge.AR),V();const n=yield He(k);if(se!==t)return;if(mt(h(),S),yield We,se!==t)return;if(mt(h(),S),st(),rt(q()),yield ot(P,L),se!==t)return;if(mt(h(),S),yield at(n,k),it(A),se!==t)return;if(mt(h(),S),yield function(){return e(this,void 0,void 0,(function*(){if(null!=Be){if(tt=!1,null==Ke){const e=ct(ze),t=je(e);Ke=yield Oe(t),yield lt(Be,Ke,"user"===e)}Be.setPaused(tt),Xe.style.display=""}}))}(),se!==t)return;mt(h(),S)}catch(e){const n=e instanceof Error;throw E("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),z(),st(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{H()}})),le=()=>e(this,void 0,void 0,(function*(){if(!j)throw new t("Model does not have 3D enabled.");if(W()===ge.Preview)throw new t("3D already launched.");try{E(xe);const e=++se;W()===ge.AR&&(_&&!tt&&st(),Y()),Q(ge.Preview),B();const t=255,n=yield dt(T,(new Date).getTime()+t,Math.random()*t);if(se!==e)return;mt(h(),S);const o=yield He(null!=x?x:`${w}/env/default.hdr`);if(se!==e)return;if(mt(h(),S),yield N,se!==e)return;if(mt(h(),S),J(),se!==e)return;mt(h(),S);const r=yield te(n,o,`${T}${x}`);if(se!==e)return;mt(h(),S),ne(r,L),ae(C),re()}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{K()}})),de=()=>e(this,void 0,void 0,(function*(){if(W()===ge.None)throw new t("Neither AR or 3D launched.");++se,W()===ge.QR||W()===ge.AR?(_&&!tt&&st(),Y()):W()===ge.Preview&&j&&!oe()&&ie(),Q(ge.None)}));return F(ce,le,de),"AR"===c?(yield ce(),mt(h(),S)):"3D"===c&&(yield le(),mt(h(),S)),{launchAR:M?ce:void 0,launch3D:j?le:void 0,closeAR:M?()=>e(this,void 0,void 0,(function*(){if(W()!==ge.AR&&W()!==ge.QR)throw new t("AR not launched.");++se,_&&!tt&&st(),Y(),Q(ge.None)})):void 0,close3D:j?()=>e(this,void 0,void 0,(function*(){if(W()!==ge.Preview)throw new t("3D not launched.");++se,j&&!oe()&&ie(),Q(ge.None)})):void 0,close:M||j?de:void 0}}))}function mt(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const vt={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",(()=>gt(n)))}))},version:m};export{vt as plugin};
1
+ function e(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem;pointer-events:none}.shopar-btn{padding:.5rem .75rem;display:flex;justify-content:center;align-items:center;gap:.25rem;background-color:#fff;border:1px solid #ddd;border-radius:9999px;cursor:pointer;pointer-events:auto}.shopar-btn:hover{background-color:#f5f5f5}.shopar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const 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),l=s^s,c=new n[1]([l]);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"],g=["Shoes"];const m="0.0.9-alpha.0";let v=`https://cdn.jsdelivr.net/npm/shopar-plugin@${m}/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 E,S,C;function A(e){const t=function(e){const t=new S.DataTexture(e.data,e.width,e.height,void 0,e.type,void 0,S.ClampToEdgeWrapping,S.ClampToEdgeWrapping,S.LinearFilter,S.LinearFilter,1,S.LinearEncoding);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=S.EquirectangularReflectionMapping,t.encoding=S.LinearEncoding,t}const I=45,P=45,T=3,L=1.5,k=1,M=.5;let x,$,U,D,_,N,j=!1;const O=0,q=2e3,G=.05,W=1/(32*Math.PI);let Q,F,V,H=!1,B=1,K=1,z=1;const X=1;let Z;const Y=new Map;function J(t,n,o){const r=t.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,l,c,d,u,h,p,f=!1,g=!0,m=!1,v=!1,w=!1,y=0,b=0,R=1,k=1,N=1;const j={threeInit:()=>{f||(ee(),i=new F.Scene,a=new F.PerspectiveCamera(25,1,.5),s=new Q.OrbitControls(a,t),s.enableInteraction(),({renderShadow:c,shadowGroup:l}=function(e){const t=new x.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new x.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new x.Group;o.position.y=-.7;const r=new x.PlaneGeometry(I,P).rotateX(Math.PI/2),i=new x.MeshBasicMaterial({map:t.texture,opacity:M,transparent:!0,depthWrite:!1}),a=new x.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new x.Mesh(r);s.visible=!1,o.add(s);const l=new x.OrthographicCamera(-I/2,I/2,P/2,-P/2,0,T);function c(e){s.visible=!0,D.uniforms.tDiffuse.value=t.texture,D.uniforms.h.value=1*e/256,s.material=D,$.setRenderTarget(n),$.render(s,l),_.uniforms.tDiffuse.value=n.texture,_.uniforms.v.value=1*e/256,s.material=_,$.setRenderTarget(t),$.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,o.add(l),{shadowGroup:o,renderShadow:()=>{const n=e.background;e.background=null,e.overrideMaterial=U;const o=$.getClearAlpha();$.setClearAlpha(0),$.setRenderTarget(t),$.render(e,l),e.overrideMaterial=null,c(L),c(.4*L),$.setRenderTarget(null),$.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 S=(e=Q).THREE,C=new e.RGBELoader,i.environment=A(n),function(e,t){const{THREE:n}=t;E=(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("function"==typeof t.MeshoptDecoder?t.MeshoptDecoder():t.MeshoptDecoder)}(Z,Q),o=t,E.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new F.Box3).setFromObject(e.scene);l.position.y=n.min.y-O,i.add(l),c(),i.traverse((e=>{if(e instanceof F.Mesh){const t=e.material;t.depthWrite=!0,t instanceof F.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,F.Vector3)),w=!0},threePaused:()=>g,threeResume:()=>{g=!1,Z.setAnimationLoop(te),t.style.visibility="visible",y=0,b=0},threePause:()=>{g=!0,function(){for(const{threePaused:e}of Y.values())if(!e())return!1;return!0}()&&Z.setAnimationLoop(null),t.style.visibility="hidden",n.style.visibility="hidden"},threeSetOnInteracted:e=>{s.removeEventListener("change",h),h=e,s.addEventListener("change",e)},preRender_:e=>{if(!f||g)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>q&&y<2*q))return o.style.opacity="0",void(y>2*q&&(y=0));{n.style.visibility="visible",o.style.opacity="1";const e=2*Math.PI/q*y,t=-Math.sin(e),r=Math.cos(e);o.style.transform=`translateX(${G*t*Math.min(R,k)}px)`,s.updateTheta(W*r)}}m=!0},shouldRender_:()=>!(!f||g)&&m,render_:()=>{Z.setViewport(0,0,t.width,t.height),Z.render(i,a),m=!1,null!=r&&(r.clearRect(0,0,t.width,t.height),r.drawImage(V,0,K-t.height,t.width,t.height,0,0,t.width,t.height))},updateSize_:()=>{const{clientWidth:e,clientHeight:n}=t;e===R&&n===k&&z===N||(t.width=Math.ceil(e*z*X),t.height=Math.ceil(n*z*X),R=e,k=n,N=z,m=!0)},target_:t};return Y.set(t,j),j}function ee(){if(H)return;Q=window.ShopAR__THREE,F=Q.THREE,V=document.createElement("canvas");var e,t;V.style.position="block",Z=new F.WebGLRenderer({powerPreference:"high-performance",canvas:V,antialias:!0,alpha:!0}),Z.outputEncoding=F.sRGBEncoding,Z.toneMapping=F.ACESFilmicToneMapping,Z.setClearColor(new F.Color(16777215)),e=Z,t=Q,j||(x=t.THREE,$=e,U=new x.MeshDepthMaterial,U.userData.darkness={value:k},U.onBeforeCompile=e=>{e.uniforms.darkness=U.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}`},U.depthTest=!1,U.depthWrite=!1,D=new x.ShaderMaterial(t.HorizontalBlurShader),D.depthTest=!1,_=new x.ShaderMaterial(t.VerticalBlurShader),_.depthTest=!1,j=!0),ne(),H=!0}function te(e){ne(),Z.clear();for(const{preRender_:t,shouldRender_:n,render_:o}of Y.values())t(e),n()&&o()}function ne(){let e=0,t=0;for(const{target_:n}of Y.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*X),t=Math.ceil(t*n*X),e===B&&t===K&&n===z||(B=e,K=t,z=n,Z.setSize(B,K,!1));for(const{updateSize_:e}of Y.values())e()}const oe={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},re=Object.keys(oe);function ie(e){return oe[e]}function ae(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const se="shopar-error";function le(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=ae("1.75rem",o);r.appendChild(e)}{const e=document.createElement("span");e.textContent=t,r.appendChild(e)}r.ariaLabel=n;return r.style.display="none",r}const ce="shopar-control";const de="shopar-deepar-output";function ue(e){const t=document.createElement("div");t.className=e,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 he(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function pe(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 fe(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 me="shopar-qr-output";const ve="shopar-three-output";var we;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(we||(we={}));let ye=!1;function be(){ye||(!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.")}}(),ye=!0)}function Re(){be();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=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),n=function(e){const t=document.createElement("div");t.id=me;const n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",t.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),t}(t);e.appendChild(n);const o=function(){const e=document.createElement("div");e.id=de;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 r=function(){const e=document.createElement("canvas");e.id=ve;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(r);const i=function(){const e=ae("2rem",`${w}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),a=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}(i);e.appendChild(a);const s=ue("shopar-ar-loading-container"),l=he("shopar-ar-loading-text",ie("loading.ar"));s.appendChild(l);const c=pe("shopar-ar-loading-bar-bg"),d=fe("shopar-ar-loading-bar-fg");c.appendChild(d),s.appendChild(c),e.appendChild(s);const u=ue("shopar-3d-loading-container"),h=he("shopar-3d-loading-text",ie("loading.3d"));u.appendChild(h);const p=pe("shopar-3d-loading-bar-bg"),f=fe("shopar-3d-loading-bar-fg");p.appendChild(f),u.appendChild(p),e.appendChild(u);const g=function(){const e=document.createElement("div");e.id=se;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const r=ae("4rem",`${w}/img/icons/close.svg`);n.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",n.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}();e.appendChild(g);const m=function(){const e=document.createElement("div");return e.id=ce,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(m);const v=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");m.appendChild(v);const y=le("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${w}/img/icons/cube.svg`);m.appendChild(y);const b=le("shopar-btn-close","Close","Close ShopAR view",`${w}/img/icons/close.svg`);m.append(b);let R,E=we.None,S=!1,C=!1,A=!1,I=!1;function P(){d.classList.remove("active"),s.style.visibility="hidden"}function T(){f.classList.remove("active"),u.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return n},getQRImage:function(){return t},getDeepARTarget:function(){return o},getThreeTarget:function(){return r},getThreePrompt:function(){return a},getThreePromptImage:function(){return i},setVisibilityParameters:function(e,t,n,o,r){var i;S=e,C=t,A=n,I=o,R=r,Ee(m,S),Ee(v,S&&(A||C)&&E===we.None),Ee(y,S&&I&&E===we.None),Ee(b,S&&E!==we.None),P(),T(),S||""===(i=g).style.display&&Ee(i,!1)},getUIState:function(){return E},setUIState:function(e){E=e,E===we.None?(P(),T(),S&&(Ee(g,!1),Ee(b,!1),(C||A)&&Ee(v,!0),I&&Ee(y,!0))):E!==we.QR&&E!==we.AR&&E!==we.Preview||S&&(Ee(g,!1),Ee(v,!1),Ee(y,!1),Ee(b,!0))},setDefaultUIActions:function(e,t,n){S&&((C||A)&&(!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}`;v.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(R),v.onclick=e),I&&(y.onclick=t),b.onclick=n)},startDeepARLoading:function(){d.classList.add("active"),s.style.visibility="visible"},stopDeepARLoading:P,startThreeLoading:function(){f.classList.add("active"),u.style.visibility="visible"},stopThreeLoading:T,showCameraError:function(){S&&Ee(g,!0)}}}function Ee(e,t){e.style.display=t?"":"none"}const Se=new Map;function Ce(t){let n=Se.get(t);return null==n?(n=function(){let t=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Re()),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/${m.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=J(e(),t(),n())}return r}}}(),Se.set(t,n)):n.incrementSetupId_(),n}function Ae(e){for(const t of Se.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===we.AR&&r(we.None)}}let Ie;const Pe=new Uint8Array(16);function Te(){if(!Ie&&(Ie="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ie))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ie(Pe)}const Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));var ke={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Me(e,t,n){if(ke.randomUUID&&!t&&!e)return ke.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 xe="qrLaunch",$e="arLaunch",Ue="previewLaunch",De="heartbeat";let _e,Ne,je=!1;const Oe=[];function qe(e,t){const n=performance.now(),o=Me();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,d(De,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:m,sessionId:Ne,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},je?a():Oe.push(a)};return{trackEvent:d,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)}}}function Ge(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function We(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 Qe=200,Fe=10;let Ve,He,Be,Ke=!1;function ze(n){return e(this,void 0,void 0,(function*(){const o=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(n).catch((e=>{throw console.error(e),new t("Resource unavailable.")}));if(!e.ok)throw new t(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new t("Resource has invalid body.")}}))}let Xe,Ze,Ye,Je,et,tt,nt,ot,rt=!0;function it(e){e!==Be&&(Be=e,ze(e),tt=null,Ke=!0)}function at(n,o){return e(this,void 0,void 0,(function*(){return Ye=o,null==et&&(et=(()=>e(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new t("No camera available!");var r;const i=ut(o),a=Ge(i),s=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(o);Xe=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:n||"your_license_key_goes_here",previewElement:Je,additionalOptions:{hint:s,cameraConfig:{disableDefaultCamera:!0}}}),Ze=yield We(a),yield ht(Xe,Ze,"user"===i),"Glasses"===o&&(yield He,function(t,n){e(this,void 0,void 0,(function*(){Ke=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${w}/wasm/mediapipe`,t);const r=[],i=setInterval((()=>e(this,void 0,void 0,(function*(){if(Ke)return void clearInterval(i);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(Ke)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<Fe)return void r.push(t);clearInterval(i);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(r)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),Qe)}))}(Ze,Xe))})))()),et}))}function st(t){return e(this,void 0,void 0,(function*(){t!==Je&&(Je=t,null!=Xe&&Xe.changePreviewElement(Je))}))}function lt(e){Xe.callbacks.onFaceTracked=t=>{t.some((e=>e.detected))&&e()},Xe.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&e()},Xe.callbacks.onWristTracked=t=>{t.detected&&e()}}function ct(t,n){return e(this,void 0,void 0,(function*(){return null!=tt&&nt===n||(yield tt,tt=Xe.switchEffect(t),nt=n),tt}))}function dt(){null!=Xe&&(rt=!0,Xe.setPaused(rt),null!=Ze&&null!=Ze.srcObject&&Ze.srcObject instanceof MediaStream&&(Ze.srcObject.getTracks().forEach((e=>e.stop())),Ze=null),Xe.stopCamera(),Je.style.display="none")}function ut(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function ht(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 pt(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),g=window[`${h}${u+d+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],m=yield p((()=>e(this,void 0,void 0,(function*(){const e=yield g(`${o}`).catch((()=>{throw new t("Unknown error.")}));if(!e.ok)throw new t("Unknown error.");return e})))),v=new n[0](yield(yield m.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,r)*((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 ft(e,n){if(null==e)throw new t(`'${n}' not specified.`)}function gt(e,n){if("string"!=typeof e)throw new t(`'${n}' must be a string.`)}const mt=["AR","3D"];function vt(e){const{apiKey:n,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:l}=e;ft(n,"apiKey"),gt(n,"apiKey"),ft(o,"sku"),gt(o,"sku"),ft(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",mt),null!=a&&gt(a,"baseUrl"),null!=s&&function(e,n){if("boolean"!=typeof e)throw new t(`'${n}' must be a boolean.`)}(s,"defaultUI"),null!=l&&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.`)}}(l,"strings",re)}function wt(n){var o,r;return e(this,void 0,void 0,(function*(){vt(n);const{apiKey:i,sku:a,targetElement:s,initialState:l}=n;!function(e){const n=getComputedStyle(e);if(!["static","relative"].includes(n.position))throw new t(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${n.position}'.`)}(s),w.update(n.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(oe,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(oe[t]=n)}}(n.strings);const c=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:m,findQR:v,findThree:R}=u,E=h();null==_e&&(Ne=Me(),_e=y(`${w}/shopar-analytics.js`),_e.then((()=>{je=!0,window.ShopAR__analytics.initializeImpl(),Oe.forEach((e=>e()))})));const{trackEvent:S,arInteracted:C,previewInteracted:A}=qe(a,i);S("setup",{hostname:window.location.hostname});const I=yield c;S("apiResponse",I);const{category:P,arUrl:T,arKey:L,previewUrl:k,previewEnvUrl:M}=I;yt(h(),E);const x=null!=T&&function(e){return null!=e&&f.includes(e)}(P),$=null==(null===(o=n._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=n._internalOptions)||void 0===r?void 0:r.qrEnabled),U=x&&function(e){return null!=e&&g.includes(e)}(P),D=$&&U&&!(yield function(){var t;return e(this,void 0,void 0,(function*(){return null==ot&&(ot=y(`${w}/shopar-platform.js`)),yield ot,["Android","iOS","Windows Phone",void 0].includes(null===(t=window.ShopAR__platform.platform.os)||void 0===t?void 0:t.family)}))}()),_=x&&!D,j=null!=k;if(yt(h(),E),D&&function(){e(this,void 0,void 0,(function*(){null==b&&(b=y(`${w}/shopar-qr.js`))}))}(),_&&(null==Ve&&(Ve=y(`${w}/shopar-deepar.js`)),it(T),"Glasses"===P&&null==He&&(He=y(`${w}/shopar-true-scale.js`))),j){null==N&&(N=y(`${w}/shopar-three.js`));const e=255;pt(k,(new Date).getTime()+e,Math.random()*e),ze(null!=M?M:`${w}/env/default.hdr`)}const{setTargetElement:O,getDeepARTarget:q,setVisibilityParameters:G,getUIState:W,setUIState:Q,setDefaultUIActions:F,startDeepARLoading:V,stopDeepARLoading:H,startThreeLoading:B,stopThreeLoading:K,showCameraError:z}=m();O(s);G(null==n.defaultUI||n.defaultUI,D,_,j,P),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,(()=>{W()!==we.QR||X()||Y(),W()!==we.AR||rt||dt(),W()!==we.Preview||ne()||ie(),Q(we.None)}));const{qrPaused:X,qrDraw:Z,qrPause:Y}=v(),{threeInit:J,threeParse:ee,threeLoad:te,threePaused:ne,threeResume:re,threePause:ie,threeSetOnInteracted:ae}=R();let se=0;if(W()===we.QR){if(!X())if(D){S(xe);try{yield Z(i,a)}catch(e){throw new t(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Y(),Q(we.None)}else if(W()===we.AR){if(!rt)if(_){S($e);const e=yield ze(T);yt(h(),E),Ae(u),st(q()),yield ct(e,T),lt(C),yt(h(),E)}else dt(),Q(we.None)}else if(W()===we.Preview&&!ne())if(j){S(Ue),B();const e=255,t=yield pt(k,(new Date).getTime()+e,Math.random()*e);yt(h(),E);const n=yield ze(null!=M?M:`${w}/env/default.hdr`);yt(h(),E);const o=yield ee(t,n,`${k}${M}`);yt(h(),E),te(o,P),ae(A),K()}else ie(),Q(we.None);const le=()=>e(this,void 0,void 0,(function*(){if(D){if(W()===we.QR||W()===we.AR)throw new t("AR already launched.");try{S(xe);const e=++se;if(W()===we.Preview&&j&&!ne()&&ie(),Q(we.QR),yield Z(i,a),se!==e)return;return void yt(h(),E)}catch(e){const n=e instanceof Error;throw S("qrLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`QR failed: ${n?e.message:"Unknown error."}`)}}if(!_)throw new t("Model does not have AR enabled.");if(W()===we.AR)throw new t("AR already launched.");try{S($e);const t=++se;W()===we.Preview&&j&&!ne()&&ie(),Ae(u),Q(we.AR),V();const n=yield ze(T);if(se!==t)return;if(yt(h(),E),yield Ve,se!==t)return;if(yt(h(),E),dt(),st(q()),yield at(L,P),se!==t)return;if(yt(h(),E),yield ct(n,T),lt(C),se!==t)return;if(yt(h(),E),yield function(){return e(this,void 0,void 0,(function*(){if(null!=Xe){if(rt=!1,null==Ze){const e=ut(Ye),t=Ge(e);Ze=yield We(t),yield ht(Xe,Ze,"user"===e)}Xe.setPaused(rt),Je.style.display=""}}))}(),se!==t)return;yt(h(),E)}catch(e){const n=e instanceof Error;throw S("arLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),z(),dt(),new t(`AR failed: ${n?e.message:"Unknown error."}`)}finally{H()}})),ce=()=>e(this,void 0,void 0,(function*(){if(!j)throw new t("Model does not have 3D enabled.");if(W()===we.Preview)throw new t("3D already launched.");try{S(Ue);const e=++se;W()===we.AR&&(_&&!rt&&dt(),Y()),Q(we.Preview),B();const t=255,n=yield pt(k,(new Date).getTime()+t,Math.random()*t);if(se!==e)return;yt(h(),E);const o=yield ze(null!=M?M:`${w}/env/default.hdr`);if(se!==e)return;if(yt(h(),E),yield N,se!==e)return;if(yt(h(),E),J(),se!==e)return;yt(h(),E);const r=yield ee(n,o,`${k}${M}`);if(se!==e)return;yt(h(),E),te(r,P),ae(A),re()}catch(e){const n=e instanceof Error;throw S("previewLaunchFailure",{errorName:n?e.name:"Unknown",errorMessage:n?e.message:""}),new t(`3D failed: ${n?e.message:"Unknown error."}`)}finally{K()}})),de=()=>e(this,void 0,void 0,(function*(){if(W()===we.None)throw new t("Neither AR or 3D launched.");++se,W()===we.QR||W()===we.AR?(_&&!rt&&dt(),Y()):W()===we.Preview&&j&&!ne()&&ie(),Q(we.None)}));return F(le,ce,de),"AR"===l?(yield le(),yt(h(),E)):"3D"===l&&(yield ce(),yt(h(),E)),{launchAR:x?le:void 0,launch3D:j?ce:void 0,closeAR:x?()=>e(this,void 0,void 0,(function*(){if(W()!==we.AR&&W()!==we.QR)throw new t("AR not launched.");++se,_&&!rt&&dt(),Y(),Q(we.None)})):void 0,close3D:j?()=>e(this,void 0,void 0,(function*(){if(W()!==we.Preview)throw new t("3D not launched.");++se,j&&!ne()&&ie(),Q(we.None)})):void 0,close:x||j?de:void 0}}))}function yt(e,n){if(e!==n)throw new t("Setup cancelled. Please ensure that setup is only called once.")}const bt={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",(()=>wt(n)))}))},version:m};export{bt as plugin};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(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}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class n extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const o=[Uint8Array,Uint32Array],r=o.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[i[a[a[r]]]][i[a[a[a.length-1]]]],c=s.charCodeAt(r),l=c^c,d=new o[1]([l]);function u(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],f=h.length;function p(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=f)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),p(e,n+1)}}))}const g=["Glasses","Shoes","Watches"],m=["Shoes"];const v="0.0.8";let w=`https://cdn.jsdelivr.net/npm/shopar-plugin@${v}/dist`;const y={update:e=>{null!=e&&(w=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>w};function b(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let R;const S=(()=>{const e=(()=>{var e;if(null===(e=document.documentElement.getAttribute("itemtype"))||void 0===e?void 0:e.includes("schema.org/SearchResultsPage"))return!0;const t=null!=document.head?Array.from(document.head.querySelectorAll("meta")):[];for(const e of t)if("viewport"===e.name)return!0;return!1})();return e||console.warn('No <meta name="viewport"> detected; ShopAR will cap pixel density at 1.'),()=>e?window.devicePixelRatio:1})();let E,A,C;function T(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.LinearEncoding);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=A.EquirectangularReflectionMapping,t.encoding=A.LinearEncoding,t}const I=45,L=45,k=3,P=1.5,x=1,M=.5;let U,$,D,_,N,j,O=!1;const q=0;let G,W,Q,F=!1,V=1,H=1,B=1;const K=1;let z;const X=new Map;function Z(e){const n=e.getContext("2d");null==n&&console.warn("2D context missing.");let o,r,i,a,s,c,l,d,u=!1,h=!0,f=!1,p=1,g=1,m=1;const v={threeInit:()=>{u||(Y(),o=new W.Scene,r=new W.PerspectiveCamera(25,1,.5),i=new G.OrbitControls(r,e),i.enableInteraction(),({renderShadow:s,shadowGroup:a}=function(e){const t=new U.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new U.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new U.Group;o.position.y=-.7;const r=new U.PlaneGeometry(I,L).rotateX(Math.PI/2),i=new U.MeshBasicMaterial({map:t.texture,opacity:M,transparent:!0,depthWrite:!1}),a=new U.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new U.Mesh(r);s.visible=!1,o.add(s);const c=new U.OrthographicCamera(-I/2,I/2,L/2,-L/2,0,k);function l(e){s.visible=!0,_.uniforms.tDiffuse.value=t.texture,_.uniforms.h.value=1*e/256,s.material=_,$.setRenderTarget(n),$.render(s,c),N.uniforms.tDiffuse.value=n.texture,N.uniforms.v.value=1*e/256,s.material=N,$.setRenderTarget(t),$.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=$.getClearAlpha();$.setClearAlpha(0),$.setRenderTarget(t),$.render(e,c),e.overrideMaterial=null,l(P),l(.4*P),$.setRenderTarget(null),$.setClearAlpha(o),e.background=n}}}(o)),u=!0)},threeParse:(e,n,r)=>t(this,void 0,void 0,(function*(){return null!=c&&l===r||(yield c,c=(()=>t(this,void 0,void 0,(function*(){var t,r;return A=(t=G).THREE,C=new t.RGBELoader,o.environment=T(n),function(e,t){const{THREE:n}=t;E=(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("function"==typeof t.MeshoptDecoder?t.MeshoptDecoder():t.MeshoptDecoder)}(z,G),r=e,E.parseAsync(r.buffer,"")})))(),l=r),c})),threeLoad:(e,t)=>{o.clear(),o.add(e.scene);const n=(new W.Box3).setFromObject(e.scene);a.position.y=n.min.y-q,o.add(a),s(),o.traverse((e=>{if(e instanceof W.Mesh){const t=e.material;t.depthWrite=!0,t instanceof W.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),c=Math.sqrt(G.reduceVertices(e.scene,((e,t)=>Math.max(e,r.distanceToSquared(t))),0));i.reset(r,c,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,W.Vector3))},threePaused:()=>h,threeResume:()=>{h=!1,z.setAnimationLoop(J),e.style.visibility="visible"},threePause:()=>{h=!0,function(){for(const{threePaused:e}of X.values())if(!e())return!1;return!0}()&&z.setAnimationLoop(null),e.style.visibility="hidden"},threeSetOnInteracted:e=>{i.removeEventListener("change",d),d=e,i.addEventListener("change",e)},preRender_:()=>{u&&!h&&i.update()&&(f=!0)},shouldRender_:()=>!(!u||h)&&f,render_:()=>{z.setViewport(0,0,e.width,e.height),z.render(o,r),f=!1,null!=n&&(n.clearRect(0,0,e.width,e.height),n.drawImage(Q,0,H-e.height,e.width,e.height,0,0,e.width,e.height))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===p&&n===g&&B===m||(e.width=Math.ceil(t*B*K),e.height=Math.ceil(n*B*K),p=t,g=n,m=B,f=!0)},target_:e};return X.set(e,v),v}function Y(){if(F)return;G=window.ShopAR__THREE,W=G.THREE,Q=document.createElement("canvas");var e,t;Q.style.position="block",z=new W.WebGLRenderer({powerPreference:"high-performance",canvas:Q,antialias:!0,alpha:!0}),z.outputEncoding=W.sRGBEncoding,z.toneMapping=W.ACESFilmicToneMapping,z.setClearColor(new W.Color(16777215)),e=z,t=G,O||(U=t.THREE,$=e,D=new U.MeshDepthMaterial,D.userData.darkness={value:x},D.onBeforeCompile=e=>{e.uniforms.darkness=D.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},D.depthTest=!1,D.depthWrite=!1,_=new U.ShaderMaterial(t.HorizontalBlurShader),_.depthTest=!1,N=new U.ShaderMaterial(t.VerticalBlurShader),N.depthTest=!1,O=!0),ee(),F=!0}function J(){ee(),z.clear();for(const{preRender_:e,shouldRender_:t,render_:n}of X.values())e(),t()&&n()}function ee(){let e=0,t=0;for(const{target_:n}of X.values()){const{clientWidth:o,clientHeight:r}=n;e=Math.max(e,o),t=Math.max(t,r)}const n=S();e=Math.ceil(e*n*K),t=Math.ceil(t*n*K),e===V&&t===H&&n===B||(V=e,H=t,B=n,z.setSize(V,H,!1));for(const{updateSize_:e}of X.values())e()}const te={"loading.ar":"Loading Try On...","loading.3d":"Loading 3D..."},ne=Object.keys(te);function oe(e){return te[e]}function re(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const ie="shopar-error";function ae(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=re("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 se="shopar-control";const ce="shopar-deepar-output";function le(e){const t=document.createElement("div");t.className=e,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 de(e,t){const n=document.createElement("div");return n.classList.add("shopar-loading-text",e),n.textContent=t,n.style.textAlign="center",n}function ue(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 he(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 fe="shopar-main";const pe="shopar-qr-output";const ge="shopar-three-output";var me;!function(e){e[e.None=0]="None",e[e.QR=1]="QR",e[e.AR=2]="AR",e[e.Preview=3]="Preview"}(me||(me={}));let ve=!1;function we(){ve||(!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.")}}(),ve=!0)}function ye(){we();const e=function(){const e=document.createElement("div");e.id=fe;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=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),n=function(e){const t=document.createElement("div");t.id=pe;const n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",t.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),t}(t);e.appendChild(n);const o=function(){const e=document.createElement("div");e.id=ce;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 r=function(){const e=document.createElement("canvas");e.id=ge;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(r);const i=le("shopar-ar-loading-container"),a=de("shopar-ar-loading-text",oe("loading.ar"));i.appendChild(a);const s=ue("shopar-ar-loading-bar-bg"),c=he("shopar-ar-loading-bar-fg");s.appendChild(c),i.appendChild(s),e.appendChild(i);const l=le("shopar-3d-loading-container"),d=de("shopar-3d-loading-text",oe("loading.3d"));l.appendChild(d);const u=ue("shopar-3d-loading-bar-bg"),h=he("shopar-3d-loading-bar-fg");u.appendChild(h),l.appendChild(u),e.appendChild(l);const f=function(){const e=document.createElement("div");e.id=ie;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const r=re("4rem",`${y}/img/icons/close.svg`);n.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",n.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}();e.appendChild(f);const p=function(){const e=document.createElement("div");return e.id=se,e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e.style.display="none",e}();e.appendChild(p);const g=ae("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");p.appendChild(g);const m=ae("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);p.appendChild(m);const v=ae("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);p.append(v);let w,b=me.None,R=!1,S=!1,E=!1,A=!1;function C(){c.classList.remove("active"),i.style.visibility="hidden"}function T(){h.classList.remove("active"),l.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return n},getQRImage:function(){return t},getDeepARTarget:function(){return o},getThreeTarget:function(){return r},setVisibilityParameters:function(e,t,n,o,r){var i;R=e,S=t,E=n,A=o,w=r,be(p,R),be(g,R&&(E||S)&&b===me.None),be(m,R&&A&&b===me.None),be(v,R&&b!==me.None),C(),T(),R||""===(i=f).style.display&&be(i,!1)},getUIState:function(){return b},setUIState:function(e){b=e,b===me.None?(C(),T(),R&&(be(f,!1),be(v,!1),(S||E)&&be(g,!0),A&&be(m,!0))):b!==me.QR&&b!==me.AR&&b!==me.Preview||R&&(be(f,!1),be(g,!1),be(m,!1),be(v,!0))},setDefaultUIActions:function(e,t,n){R&&((S||E)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${y}/img/icons/${n}`;g.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(w),g.onclick=e),A&&(m.onclick=t),v.onclick=n)},startDeepARLoading:function(){c.classList.add("active"),i.style.visibility="visible"},stopDeepARLoading:C,startThreeLoading:function(){h.classList.add("active"),l.style.visibility="visible"},stopThreeLoading:T,showCameraError:function(){R&&be(f,!0)}}}function be(e,t){e.style.display=t?"":"none"}const Re=new Map;function Se(e){let n=Re.get(e);return null==n?(n=function(){let e=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=ye()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:e,getQRImage:n}=i();o=function(e,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>t(this,void 0,void 0,(function*(){yield R;const t=`https://apps.deepar.ai/${v.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:r,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(t),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,o=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){o=!0,e.style.display="none"}))}}(e(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e}=i();r=Z(e())}return r}}}(),Re.set(e,n)):n.incrementSetupId_(),n}function Ee(e){for(const t of Re.values()){if(t===e)continue;const n=t.getUI_();if(null==n)continue;const{getUIState:o,setUIState:r}=n;o()===me.AR&&r(me.None)}}let Ae;const Ce=new Uint8Array(16);function Te(){if(!Ae&&(Ae="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ae))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ae(Ce)}const Ie=[];for(let e=0;e<256;++e)Ie.push((e+256).toString(16).slice(1));var Le={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ke(e,t,n){if(Le.randomUUID&&!t&&!e)return Le.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 Ie[e[t+0]]+Ie[e[t+1]]+Ie[e[t+2]]+Ie[e[t+3]]+"-"+Ie[e[t+4]]+Ie[e[t+5]]+"-"+Ie[e[t+6]]+Ie[e[t+7]]+"-"+Ie[e[t+8]]+Ie[e[t+9]]+"-"+Ie[e[t+10]]+Ie[e[t+11]]+Ie[e[t+12]]+Ie[e[t+13]]+Ie[e[t+14]]+Ie[e[t+15]]}(o)}const Pe="qrLaunch",xe="arLaunch",Me="previewLaunch",Ue="heartbeat";let $e,De,_e=!1;const Ne=[];function je(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(Ue,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:v,sessionId:De,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},_e?a():Ne.push(a)};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)}}}function Oe(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function qe(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const Ge=200,We=10;let Qe,Fe,Ve,He=!1;function Be(e){return t(this,void 0,void 0,(function*(){const o=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let Ke,ze,Xe,Ze,Ye,Je,et,tt,nt=!0;function ot(e){e!==Ve&&(Ve=e,Be(e),Je=null,He=!0)}function rt(e,o){return t(this,void 0,void 0,(function*(){return Xe=o,null==Ye&&(Ye=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new n("No camera available!");var r;const i=lt(o),a=Oe(i),s=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(o);Ke=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:e||"your_license_key_goes_here",previewElement:Ze,additionalOptions:{hint:s,cameraConfig:{disableDefaultCamera:!0}}}),ze=yield qe(a),yield dt(Ke,ze,"user"===i),"Glasses"===o&&(yield Fe,function(e,n){t(this,void 0,void 0,(function*(){He=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,e);const r=[],i=setInterval((()=>t(this,void 0,void 0,(function*(){if(He)return void clearInterval(i);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(He)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<We)return void r.push(t);clearInterval(i);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(r)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),Ge)}))}(ze,Ke))})))()),Ye}))}function it(e){return t(this,void 0,void 0,(function*(){e!==Ze&&(Ze=e,null!=Ke&&Ke.changePreviewElement(Ze))}))}function at(e){Ke.callbacks.onFaceTracked=t=>{t.some((e=>e.detected))&&e()},Ke.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&e()},Ke.callbacks.onWristTracked=t=>{t.detected&&e()}}function st(e,n){return t(this,void 0,void 0,(function*(){return null!=Je&&et===n||(yield Je,Je=Ke.switchEffect(e),et=n),Je}))}function ct(){null!=Ke&&(nt=!0,Ke.setPaused(nt),null!=ze&&null!=ze.srcObject&&ze.srcObject instanceof MediaStream&&(ze.srcObject.getTracks().forEach((e=>e.stop())),ze=null),Ke.stopCamera(),Ze.style.display="none")}function lt(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function dt(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),r()}))))}}))}))}function ut(e,r,i){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const c=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),g=window[`${h}${u+c+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${f}`],m=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield g(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),v=new o[0](yield(yield m.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=v.byteLength;if(d[l]=Math.min(76,r)*((a>>5)-1),152===d[l]&&(d[l]=w),i==l)return v;i=l,i^=l;for(let e=0,t=v.length;e<t;e++)d[l]^=d[i]<<13,d[l]^=d[i]>>17,d[l]^=d[i]<<5,v[e]=v[e]^d[l];return i^=d[0],i^=d[1],i^=d[2],v}))}function ht(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function ft(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const pt=["AR","3D"];function gt(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:c}=e;ht(t,"apiKey"),ft(t,"apiKey"),ht(o,"sku"),ft(o,"sku"),ht(r,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(i,"initialState",pt),null!=a&&ft(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI"),null!=c&&function(e,t,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new n(`Value for key '${r}' in '${t}' must be a string.`)}}(c,"strings",ne)}function mt(e){var o,r;return t(this,void 0,void 0,(function*(){gt(e);const{apiKey:i,sku:a,targetElement:s,initialState:c}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),y.update(e.baseUrl),function(e){if(null!=e)for(const t of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(te,t)){console.warn(`String for key '${t}' will be ignored.`);continue}const n=e[t];null!=n&&(te[t]=n)}}(e.strings);const l=function(e,o){return t(this,void 0,void 0,(function*(){const r=yield p((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield r.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a),d=Se(s),{getSetupId:h,findUI:f,findQR:v,findThree:w}=d,S=h();null==$e&&(De=ke(),$e=b(`${y}/shopar-analytics.js`),$e.then((()=>{_e=!0,window.ShopAR__analytics.initializeImpl(),Ne.forEach((e=>e()))})));const{trackEvent:E,arInteracted:A,previewInteracted:C}=je(a,i);E("setup",{hostname:window.location.hostname});const T=yield l;E("apiResponse",T);const{category:I,arUrl:L,arKey:k,previewUrl:P,previewEnvUrl:x}=T;vt(h(),S);const M=null!=L&&function(e){return null!=e&&g.includes(e)}(I),U=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),$=M&&function(e){return null!=e&&m.includes(e)}(I),D=U&&$&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==tt&&(tt=b(`${y}/shopar-platform.js`)),yield tt,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}()),_=M&&!D,N=null!=P;if(vt(h(),S),D&&function(){t(this,void 0,void 0,(function*(){null==R&&(R=b(`${y}/shopar-qr.js`))}))}(),_&&(null==Qe&&(Qe=b(`${y}/shopar-deepar.js`)),ot(L),"Glasses"===I&&null==Fe&&(Fe=b(`${y}/shopar-true-scale.js`))),N){null==j&&(j=b(`${y}/shopar-three.js`));const e=255;ut(P,(new Date).getTime()+e,Math.random()*e),Be(null!=x?x:`${y}/env/default.hdr`)}const{setTargetElement:O,getDeepARTarget:q,setVisibilityParameters:G,getUIState:W,setUIState:Q,setDefaultUIActions:F,startDeepARLoading:V,stopDeepARLoading:H,startThreeLoading:B,stopThreeLoading:K,showCameraError:z}=f();O(s);G(null==e.defaultUI||e.defaultUI,D,_,N,I),function(e,t){const o=e.parentNode;if(null==o)throw new n("Parent node missing.");new MutationObserver((n=>{for(const o of n)for(const n of o.removedNodes)if(n===e)return void t()})).observe(o,{childList:!0})}(s,(()=>{W()!==me.QR||X()||Y(),W()!==me.AR||nt||ct(),W()!==me.Preview||oe()||ie(),Q(me.None)}));const{qrPaused:X,qrDraw:Z,qrPause:Y}=v(),{threeInit:J,threeParse:ee,threeLoad:ne,threePaused:oe,threeResume:re,threePause:ie,threeSetOnInteracted:ae}=w();let se=0;if(W()===me.QR){if(!X())if(D){E(Pe);try{yield Z(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Y(),Q(me.None)}else if(W()===me.AR){if(!nt)if(_){E(xe);const e=yield Be(L);vt(h(),S),Ee(d),it(q()),yield st(e,L),at(A),vt(h(),S)}else ct(),Q(me.None)}else if(W()===me.Preview&&!oe())if(N){E(Me),B();const e=255,t=yield ut(P,(new Date).getTime()+e,Math.random()*e);vt(h(),S);const n=yield Be(null!=x?x:`${y}/env/default.hdr`);vt(h(),S);const o=yield ee(t,n,`${P}${x}`);vt(h(),S),ne(o,I),ae(C),K()}else ie(),Q(me.None);const ce=()=>t(this,void 0,void 0,(function*(){if(D){if(W()===me.QR||W()===me.AR)throw new n("AR already launched.");try{E(Pe);const e=++se;if(W()===me.Preview&&N&&!oe()&&ie(),Q(me.QR),yield Z(i,a),se!==e)return;return void vt(h(),S)}catch(e){const t=e instanceof Error;throw E("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!_)throw new n("Model does not have AR enabled.");if(W()===me.AR)throw new n("AR already launched.");try{E(xe);const e=++se;W()===me.Preview&&N&&!oe()&&ie(),Ee(d),Q(me.AR),V();const n=yield Be(L);if(se!==e)return;if(vt(h(),S),yield Qe,se!==e)return;if(vt(h(),S),ct(),it(q()),yield rt(k,I),se!==e)return;if(vt(h(),S),yield st(n,L),at(A),se!==e)return;if(vt(h(),S),yield function(){return t(this,void 0,void 0,(function*(){if(null!=Ke){if(nt=!1,null==ze){const e=lt(Xe),t=Oe(e);ze=yield qe(t),yield dt(Ke,ze,"user"===e)}Ke.setPaused(nt),Ze.style.display=""}}))}(),se!==e)return;vt(h(),S)}catch(e){const t=e instanceof Error;throw E("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),z(),ct(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{H()}})),le=()=>t(this,void 0,void 0,(function*(){if(!N)throw new n("Model does not have 3D enabled.");if(W()===me.Preview)throw new n("3D already launched.");try{E(Me);const e=++se;W()===me.AR&&(_&&!nt&&ct(),Y()),Q(me.Preview),B();const t=255,n=yield ut(P,(new Date).getTime()+t,Math.random()*t);if(se!==e)return;vt(h(),S);const o=yield Be(null!=x?x:`${y}/env/default.hdr`);if(se!==e)return;if(vt(h(),S),yield j,se!==e)return;if(vt(h(),S),J(),se!==e)return;vt(h(),S);const r=yield ee(n,o,`${P}${x}`);if(se!==e)return;vt(h(),S),ne(r,I),ae(C),re()}catch(e){const t=e instanceof Error;throw E("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{K()}})),de=()=>t(this,void 0,void 0,(function*(){if(W()===me.None)throw new n("Neither AR or 3D launched.");++se,W()===me.QR||W()===me.AR?(_&&!nt&&ct(),Y()):W()===me.Preview&&N&&!oe()&&ie(),Q(me.None)}));return F(ce,le,de),"AR"===c?(yield ce(),vt(h(),S)):"3D"===c&&(yield le(),vt(h(),S)),{launchAR:M?ce:void 0,launch3D:N?le:void 0,closeAR:M?()=>t(this,void 0,void 0,(function*(){if(W()!==me.AR&&W()!==me.QR)throw new n("AR not launched.");++se,_&&!nt&&ct(),Y(),Q(me.None)})):void 0,close3D:N?()=>t(this,void 0,void 0,(function*(){if(W()!==me.Preview)throw new n("3D not launched.");++se,N&&!oe()&&ie(),Q(me.None)})):void 0,close:M||N?de:void 0}}))}function vt(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const wt={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>mt(e)))}))},version:v};e.plugin=wt}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}!function(){const e={css:".shopar-btn-container{position:absolute;width:100%;bottom:0;padding-bottom:2rem;display:flex;justify-content:center;gap:.5rem;pointer-events:none}.shopar-btn{padding:.5rem .75rem;display:flex;justify-content:center;align-items:center;gap:.25rem;background-color:#fff;border:1px solid #ddd;border-radius:9999px;cursor:pointer;pointer-events:auto}.shopar-btn:hover{background-color:#f5f5f5}.shopar-loading-container{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:1rem;background-color:#fff}.shopar-loading-text{text-align:center}.shopar-loading-bar-bg{width:80%;height:.5rem;background-color:#e5e7eb;border-radius:9999px}.shopar-loading-bar-fg{background-color:#1434f7;border-radius:9999px;transition:none;transform:translateX(-100%);will-change:transform}.shopar-loading-bar-fg.active{transition:transform 5s cubic-bezier(0,0,.2,1);transform:none}.shopar-qr{display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:#fff}"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}(),"function"==typeof SuppressedError&&SuppressedError;class n extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}const o=[Uint8Array,Uint32Array],r=o.length-2,i=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],a=[2,12,7,1],s=window[i[a[a[r]]]][i[a[a[a.length-1]]]],l=s.charCodeAt(r),c=l^l,d=new o[1]([c]);function u(){const e=(new TextEncoder).encode(s),t=i.map((e=>e.length));for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[i[t[2]]](String.fromCodePoint(...e))}const h=[1e3,2e3,4e3],p=h.length;function f(e,n=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(n>=p)throw t;return yield new Promise((e=>setTimeout(e,h[n]))),f(e,n+1)}}))}const g=["Glasses","Shoes","Watches"],m=["Shoes"];const v="0.0.9-alpha.0";let w=`https://cdn.jsdelivr.net/npm/shopar-plugin@${v}/dist`;const y={update:e=>{null!=e&&(w=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>w};function b(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise((e=>{t.addEventListener("load",(()=>e()),!1),t.addEventListener("error",(()=>e()),!1),document.body.appendChild(t)}))}importScripts(e.toString())}))}let R;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 S,A,C;function T(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.LinearEncoding);return t.flipY=!0,t.generateMipmaps=!1,t.needsUpdate=!0,t}(C.parse(e));return t.mapping=A.EquirectangularReflectionMapping,t.encoding=A.LinearEncoding,t}const I=45,P=45,L=3,x=1.5,k=1,M=.5;let $,U,D,_,N,j,O=!1;const q=0,G=2e3,W=.05,Q=1/(32*Math.PI);let F,V,H,B=!1,K=1,z=1,X=1;const Z=1;let Y;const J=new Map;function ee(e,n,o){const r=e.getContext("2d");null==r&&console.warn("2D context missing.");let i,a,s,l,c,d,u,h,p,f=!1,g=!0,m=!1,v=!1,w=!1,y=0,b=0,R=1,E=1,k=1;const j={threeInit:()=>{f||(te(),i=new V.Scene,a=new V.PerspectiveCamera(25,1,.5),s=new F.OrbitControls(a,e),s.enableInteraction(),({renderShadow:c,shadowGroup:l}=function(e){const t=new $.WebGLRenderTarget(512,512);t.texture.generateMipmaps=!1;const n=new $.WebGLRenderTarget(512,512);n.texture.generateMipmaps=!1;const o=new $.Group;o.position.y=-.7;const r=new $.PlaneGeometry(I,P).rotateX(Math.PI/2),i=new $.MeshBasicMaterial({map:t.texture,opacity:M,transparent:!0,depthWrite:!1}),a=new $.Mesh(r,i);a.renderOrder=1,a.scale.y=-1,o.add(a);const s=new $.Mesh(r);s.visible=!1,o.add(s);const l=new $.OrthographicCamera(-I/2,I/2,P/2,-P/2,0,L);function c(e){s.visible=!0,_.uniforms.tDiffuse.value=t.texture,_.uniforms.h.value=1*e/256,s.material=_,U.setRenderTarget(n),U.render(s,l),N.uniforms.tDiffuse.value=n.texture,N.uniforms.v.value=1*e/256,s.material=N,U.setRenderTarget(t),U.render(s,l),s.visible=!1}return l.rotation.x=Math.PI/2,o.add(l),{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,l),e.overrideMaterial=null,c(x),c(.4*x),U.setRenderTarget(null),U.setClearAlpha(o),e.background=n}}}(i)),f=!0)},threeParse:(e,n,o)=>t(this,void 0,void 0,(function*(){return null!=d&&u===o||(yield d,d=(()=>t(this,void 0,void 0,(function*(){var t,o;return A=(t=F).THREE,C=new t.RGBELoader,i.environment=T(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("function"==typeof t.MeshoptDecoder?t.MeshoptDecoder():t.MeshoptDecoder)}(Y,F),o=e,S.parseAsync(o.buffer,"")})))(),u=o),d})),threeLoad:(e,t)=>{i.clear(),i.add(e.scene);const n=(new V.Box3).setFromObject(e.scene);l.position.y=n.min.y-q,i.add(l),c(),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(F.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:()=>g,threeResume:()=>{g=!1,Y.setAnimationLoop(ne),e.style.visibility="visible",y=0,b=0},threePause:()=>{g=!0,function(){for(const{threePaused:e}of J.values())if(!e())return!1;return!0}()&&Y.setAnimationLoop(null),e.style.visibility="hidden",n.style.visibility="hidden"},threeSetOnInteracted:e=>{s.removeEventListener("change",h),h=e,s.addEventListener("change",e)},preRender_:e=>{if(!f||g)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>G&&y<2*G))return o.style.opacity="0",void(y>2*G&&(y=0));{n.style.visibility="visible",o.style.opacity="1";const e=2*Math.PI/G*y,t=-Math.sin(e),r=Math.cos(e);o.style.transform=`translateX(${W*t*Math.min(R,E)}px)`,s.updateTheta(Q*r)}}m=!0},shouldRender_:()=>!(!f||g)&&m,render_:()=>{Y.setViewport(0,0,e.width,e.height),Y.render(i,a),m=!1,null!=r&&(r.clearRect(0,0,e.width,e.height),r.drawImage(H,0,z-e.height,e.width,e.height,0,0,e.width,e.height))},updateSize_:()=>{const{clientWidth:t,clientHeight:n}=e;t===R&&n===E&&X===k||(e.width=Math.ceil(t*X*Z),e.height=Math.ceil(n*X*Z),R=t,E=n,k=X,m=!0)},target_:e};return J.set(e,j),j}function te(){if(B)return;F=window.ShopAR__THREE,V=F.THREE,H=document.createElement("canvas");var e,t;H.style.position="block",Y=new V.WebGLRenderer({powerPreference:"high-performance",canvas:H,antialias:!0,alpha:!0}),Y.outputEncoding=V.sRGBEncoding,Y.toneMapping=V.ACESFilmicToneMapping,Y.setClearColor(new V.Color(16777215)),e=Y,t=F,O||($=t.THREE,U=e,D=new $.MeshDepthMaterial,D.userData.darkness={value:k},D.onBeforeCompile=e=>{e.uniforms.darkness=D.userData.darkness;const t=e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * darkness );");e.fragmentShader=`uniform float darkness;\n${t}`},D.depthTest=!1,D.depthWrite=!1,_=new $.ShaderMaterial(t.HorizontalBlurShader),_.depthTest=!1,N=new $.ShaderMaterial(t.VerticalBlurShader),N.depthTest=!1,O=!0),oe(),B=!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=E();e=Math.ceil(e*n*Z),t=Math.ceil(t*n*Z),e===K&&t===z&&n===X||(K=e,z=t,X=n,Y.setSize(K,z,!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]}function se(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",e),n.setAttribute("height",e);{const o=document.createElementNS("http://www.w3.org/2000/svg","image");o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),o.setAttribute("width",e),o.setAttribute("height",e),n.appendChild(o)}return n}const le="shopar-error";function ce(e,t,n,o){const r=document.createElement("button");r.id=e,r.type="button",r.className="shopar-btn";{const e=se("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.className=e,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 ge(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 me="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 Ee(){Re();const e=function(){const e=document.createElement("div");e.id=me;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=new Image,t=e.style;return t.maxWidth="100%",t.maxHeight="100%",e}(),n=function(e){const t=document.createElement("div");t.id=ve;const n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.display="none";const o=document.createElement("div");o.className="shopar-qr";const r=o.style;r.position="relative",r.top="0",r.left="0",r.width="100%",r.height="100%",t.appendChild(o);const i=document.createElement("div");i.innerText="Scan on mobile or tablet to try on",i.style.textAlign="center",o.appendChild(i);const a=document.createElement("div");return a.appendChild(e),o.appendChild(a),t}(t);e.appendChild(n);const o=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(o);const r=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(r);const i=function(){const e=se("2rem",`${y}/img/prompt/3d-interaction.svg`),{style:t}=e;return t.transition="opacity 0.3s",t.opacity="0",e}(),a=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}(i);e.appendChild(a);const s=he("shopar-ar-loading-container"),l=pe("shopar-ar-loading-text",ae("loading.ar"));s.appendChild(l);const c=fe("shopar-ar-loading-bar-bg"),d=ge("shopar-ar-loading-bar-fg");c.appendChild(d),s.appendChild(c),e.appendChild(s);const u=he("shopar-3d-loading-container"),h=pe("shopar-3d-loading-text",ae("loading.3d"));u.appendChild(h);const p=fe("shopar-3d-loading-bar-bg"),f=ge("shopar-3d-loading-bar-fg");p.appendChild(f),u.appendChild(p),e.appendChild(u);const g=function(){const e=document.createElement("div");e.id=le;const t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.flexDirection="column",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const r=se("4rem",`${y}/img/icons/close.svg`);n.appendChild(r);const i=document.createElement("div");i.className="shopar-error-title",i.textContent="Camera Error",n.appendChild(i);const a=document.createElement("div");return a.className="shopar-error-body",a.textContent="Please refresh the page and allow the use of camera.",n.appendChild(a),e}();e.appendChild(g);const m=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(m);const v=ce("shopar-btn-vto","Try-on","Launch ShopAR virtual try-on","data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22/%3E");m.appendChild(v);const w=ce("shopar-btn-3d","3D","Launch ShopAR 3D preview",`${y}/img/icons/cube.svg`);m.appendChild(w);const b=ce("shopar-btn-close","Close","Close ShopAR view",`${y}/img/icons/close.svg`);m.append(b);let R,E=ye.None,S=!1,A=!1,C=!1,T=!1;function I(){d.classList.remove("active"),s.style.visibility="hidden"}function P(){f.classList.remove("active"),u.style.visibility="hidden"}return{setTargetElement:function(t){t.style.position="relative",t.appendChild(e)},getQRTarget:function(){return n},getQRImage:function(){return t},getDeepARTarget:function(){return o},getThreeTarget:function(){return r},getThreePrompt:function(){return a},getThreePromptImage:function(){return i},setVisibilityParameters:function(e,t,n,o,r){var i;S=e,A=t,C=n,T=o,R=r,Se(m,S),Se(v,S&&(C||A)&&E===ye.None),Se(w,S&&T&&E===ye.None),Se(b,S&&E!==ye.None),I(),P(),S||""===(i=g).style.display&&Se(i,!1)},getUIState:function(){return E},setUIState:function(e){E=e,E===ye.None?(I(),P(),S&&(Se(g,!1),Se(b,!1),(A||C)&&Se(v,!0),T&&Se(w,!0))):E!==ye.QR&&E!==ye.AR&&E!==ye.Preview||S&&(Se(g,!1),Se(v,!1),Se(w,!1),Se(b,!0))},setDefaultUIActions:function(e,t,n){S&&((A||C)&&(!function(e){const t={Glasses:"glasses.svg",Shoes:"shoe.svg",Watches:"watch.svg"},n=null!=e&&t[e]||t.Glasses,o=`${y}/img/icons/${n}`;v.firstChild.firstChild.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o)}(R),v.onclick=e),T&&(w.onclick=t),b.onclick=n)},startDeepARLoading:function(){d.classList.add("active"),s.style.visibility="visible"},stopDeepARLoading:I,startThreeLoading:function(){f.classList.add("active"),u.style.visibility="visible"},stopThreeLoading:P,showCameraError:function(){S&&Se(g,!0)}}}function Se(e,t){e.style.display=t?"":"none"}const Ae=new Map;function Ce(e){let n=Ae.get(e);return null==n?(n=function(){let e=0,n=null,o=null,r=null;const i=()=>(null==n&&(n=Ee()),n);return{getSetupId:()=>e,incrementSetupId_:()=>e++,getUI_:()=>n,findUI:i,findQR:()=>{if(null==o){const{getQRTarget:e,getQRImage:n}=i();o=function(e,n){let o=!0;return{qrPaused:()=>o,qrDraw:(r,i)=>t(this,void 0,void 0,(function*(){yield R;const t=`https://apps.deepar.ai/${v.includes("alpha")?"shopar-qr-alpha":"shopar-qr"}/?${new URLSearchParams({a:r,s:i,h:location.href})}`,a=yield window.ShopAR__QR.toDataURL(t),s=new Promise(((e,t)=>{n.onload=e,n.onerror=t}));n.src=a,yield s,o=!1,e.style.display=""})),qrPause:()=>t(this,void 0,void 0,(function*(){o=!0,e.style.display="none"}))}}(e(),n())}return o},findThree:()=>{if(null==r){const{getThreeTarget:e,getThreePrompt:t,getThreePromptImage:n}=i();r=ee(e(),t(),n())}return r}}}(),Ae.set(e,n)):n.incrementSetupId_(),n}function Te(e){for(const t of Ae.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 Ie;const Pe=new Uint8Array(16);function Le(){if(!Ie&&(Ie="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ie))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ie(Pe)}const xe=[];for(let e=0;e<256;++e)xe.push((e+256).toString(16).slice(1));var ke={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Me(e,t,n){if(ke.randomUUID&&!t&&!e)return ke.randomUUID();const o=(e=e||{}).random||(e.rng||Le)();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 xe[e[t+0]]+xe[e[t+1]]+xe[e[t+2]]+xe[e[t+3]]+"-"+xe[e[t+4]]+xe[e[t+5]]+"-"+xe[e[t+6]]+xe[e[t+7]]+"-"+xe[e[t+8]]+xe[e[t+9]]+"-"+xe[e[t+10]]+xe[e[t+11]]+xe[e[t+12]]+xe[e[t+13]]+xe[e[t+14]]+xe[e[t+15]]}(o)}const $e="qrLaunch",Ue="arLaunch",De="previewLaunch",_e="heartbeat";let Ne,je,Oe=!1;const qe=[];function Ge(e,t){const n=performance.now(),o=Me();let r=0,i=0,a=0,s=0,l=0,c=!1;window.setInterval((()=>{c&&(r=i+a,c=!1,d(_e,{engagementTotal:r,engagementAR:i,engagement3D:a}))}),1e3);const d=(r,i={})=>{var a;i=Object.assign(Object.assign({},i),{pluginVersion:v,sessionId:je,setupId:o,timeSinceSetup:performance.now()-n,sku:e,apiKey:t}),a=()=>{window.ShopAR__analytics.trackEventImpl(r,i)},Oe?a():qe.push(a)};return{trackEvent:d,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)}}}function We(e){return navigator.mediaDevices.getUserMedia({video:{facingMode:e,frameRate:{ideal:30},width:{ideal:640},height:{ideal:360}}})}function Qe(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("video");return t.setAttribute("playsinline","playsinline"),t.srcObject=yield e,t}))}const Fe=200,Ve=10;let He,Be,Ke,ze=!1;function Xe(e){return t(this,void 0,void 0,(function*(){const o=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new n("Resource unavailable.")}));if(!t.ok)throw new n(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield o.blob()).arrayBuffer()}catch(e){throw console.error(e),new n("Resource has invalid body.")}}))}let Ze,Ye,Je,et,tt,nt,ot,rt,it=!0;function at(e){e!==Ke&&(Ke=e,Xe(e),nt=null,ze=!0)}function st(e,o){return t(this,void 0,void 0,(function*(){return Je=o,null==tt&&(tt=(()=>t(this,void 0,void 0,(function*(){if(null==(null===(r=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===r?void 0:r.getUserMedia))throw new n("No camera available!");var r;const i=ht(o),a=We(i),s=function(e){const t={Glasses:"rigidFaceTrackingInit",Shoes:"footInit",Watches:void 0};return null==e?void 0:t[e]}(o);Ze=yield window.ShopAR__DeepAR.deepar.initialize({licenseKey:e||"your_license_key_goes_here",previewElement:et,additionalOptions:{hint:s,cameraConfig:{disableDefaultCamera:!0}}}),Ye=yield Qe(a),yield pt(Ze,Ye,"user"===i),"Glasses"===o&&(yield Be,function(e,n){t(this,void 0,void 0,(function*(){ze=!1;const{ShopAR__TrueScale:o}=window;yield o.initialize(`${y}/wasm/mediapipe`,e);const r=[],i=setInterval((()=>t(this,void 0,void 0,(function*(){if(ze)return void clearInterval(i);const{error:e,faceWidth:t}=yield o.predict(performance.now());if(ze)return void clearInterval(i);if(null!=e)return void console.error(`TrueScale predict error: ${e}`);if(r.length<Ve)return void r.push(t);clearInterval(i);const a=137/(function(e){let t=0;const n=e.length;for(let o=0;o<n;o++)t+=e[o];return t/n}(r)+5);n.changeParameterVector("GLASSES","","scale",a,a,a,0),n.changeParameterVector("shopar_glasses","","scale",a,a,a,0)}))),Fe)}))}(Ye,Ze))})))()),tt}))}function lt(e){return t(this,void 0,void 0,(function*(){e!==et&&(et=e,null!=Ze&&Ze.changePreviewElement(et))}))}function ct(e){Ze.callbacks.onFaceTracked=t=>{t.some((e=>e.detected))&&e()},Ze.callbacks.onFeetTracked=(t,n)=>{(t.detected||n.detected)&&e()},Ze.callbacks.onWristTracked=t=>{t.detected&&e()}}function dt(e,n){return t(this,void 0,void 0,(function*(){return null!=nt&&ot===n||(yield nt,nt=Ze.switchEffect(e),ot=n),nt}))}function ut(){null!=Ze&&(it=!0,Ze.setPaused(it),null!=Ye&&null!=Ye.srcObject&&Ye.srcObject instanceof MediaStream&&(Ye.srcObject.getTracks().forEach((e=>e.stop())),Ye=null),Ze.stopCamera(),et.style.display="none")}function ht(e){var t;return null==e?"user":null!==(t={Glasses:"user",Shoes:"environment",Watches:"environment"}[e])&&void 0!==t?t:"user"}function pt(e,n,o){return t(this,void 0,void 0,(function*(){yield new Promise((r=>{n.onloadedmetadata=()=>{n.play().then((()=>t(this,void 0,void 0,(function*(){e.setVideoElement(n,o),r()}))))}}))}))}function ft(e,r,i){return t(this,void 0,void 0,(function*(){let a="glb".charCodeAt(0),s="3d".charCodeAt(0);a>>=1,a+=s;const l=String.fromCharCode(a+14);s>>=2,a^=s+2;const u=String.fromCharCode(a-3);a^=5;const h=String.fromCharCode(a-7);a^=2;const p=String.fromCharCode(a-7),g=window[`${h}${u+l+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${p}`],m=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield g(`${e}`).catch((()=>{throw new n("Unknown error.")}));if(!t.ok)throw new n("Unknown error.");return t})))),v=new o[0](yield(yield m.blob().catch((()=>{throw new n("Unknown error.")}))).arrayBuffer().catch((()=>{throw new n("Unknown error.")})));i+=s;const w=v.byteLength;if(d[c]=Math.min(76,r)*((a>>5)-1),152===d[c]&&(d[c]=w),i==c)return v;i=c,i^=c;for(let e=0,t=v.length;e<t;e++)d[c]^=d[i]<<13,d[c]^=d[i]>>17,d[c]^=d[i]<<5,v[e]=v[e]^d[c];return i^=d[0],i^=d[1],i^=d[2],v}))}function gt(e,t){if(null==e)throw new n(`'${t}' not specified.`)}function mt(e,t){if("string"!=typeof e)throw new n(`'${t}' must be a string.`)}const vt=["AR","3D"];function wt(e){const{apiKey:t,sku:o,targetElement:r,initialState:i,baseUrl:a,defaultUI:s,strings:l}=e;gt(t,"apiKey"),mt(t,"apiKey"),gt(o,"sku"),mt(o,"sku"),gt(r,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new n(`'${t}' must be an HTMLElement.`)}(r,"targetElement"),null!=i&&function(e,t,o){if("string"!=typeof e)throw new n(`'${t}' must be a string.`);if(!o.includes(e))throw new n(`'${t}' must be ${o.join("' or '")}.`)}(i,"initialState",vt),null!=a&&mt(a,"baseUrl"),null!=s&&function(e,t){if("boolean"!=typeof e)throw new n(`'${t}' must be a boolean.`)}(s,"defaultUI"),null!=l&&function(e,t,o){for(const r of o){const o=e[r];if(null!=o&&"string"!=typeof o)throw new n(`Value for key '${r}' in '${t}' must be a string.`)}}(l,"strings",ie)}function yt(e){var o,r;return t(this,void 0,void 0,(function*(){wt(e);const{apiKey:i,sku:a,targetElement:s,initialState:l}=e;!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new n(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),y.update(e.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)}}(e.strings);const c=function(e,o){return t(this,void 0,void 0,(function*(){const r=yield f((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.shopar.ai/plugin?${new URLSearchParams({apiKey:e,sku:o,sid:u()})}`).catch((e=>{throw console.error(e),new n("API unavailable.")}));if(!t.ok)throw new n(`API call failed with status ${t.status}.`);return t}))));try{return yield r.json()}catch(e){throw console.error(e),new n("API returned invalid body.")}}))}(i,a),d=Ce(s),{getSetupId:h,findUI:p,findQR:v,findThree:w}=d,E=h();null==Ne&&(je=Me(),Ne=b(`${y}/shopar-analytics.js`),Ne.then((()=>{Oe=!0,window.ShopAR__analytics.initializeImpl(),qe.forEach((e=>e()))})));const{trackEvent:S,arInteracted:A,previewInteracted:C}=Ge(a,i);S("setup",{hostname:window.location.hostname});const T=yield c;S("apiResponse",T);const{category:I,arUrl:P,arKey:L,previewUrl:x,previewEnvUrl:k}=T;bt(h(),E);const M=null!=P&&function(e){return null!=e&&g.includes(e)}(I),$=null==(null===(o=e._internalOptions)||void 0===o?void 0:o.qrEnabled)||(null===(r=e._internalOptions)||void 0===r?void 0:r.qrEnabled),U=M&&function(e){return null!=e&&m.includes(e)}(I),D=$&&U&&!(yield function(){var e;return t(this,void 0,void 0,(function*(){return null==rt&&(rt=b(`${y}/shopar-platform.js`)),yield rt,["Android","iOS","Windows Phone",void 0].includes(null===(e=window.ShopAR__platform.platform.os)||void 0===e?void 0:e.family)}))}()),_=M&&!D,N=null!=x;if(bt(h(),E),D&&function(){t(this,void 0,void 0,(function*(){null==R&&(R=b(`${y}/shopar-qr.js`))}))}(),_&&(null==He&&(He=b(`${y}/shopar-deepar.js`)),at(P),"Glasses"===I&&null==Be&&(Be=b(`${y}/shopar-true-scale.js`))),N){null==j&&(j=b(`${y}/shopar-three.js`));const e=255;ft(x,(new Date).getTime()+e,Math.random()*e),Xe(null!=k?k:`${y}/env/default.hdr`)}const{setTargetElement:O,getDeepARTarget:q,setVisibilityParameters:G,getUIState:W,setUIState:Q,setDefaultUIActions:F,startDeepARLoading:V,stopDeepARLoading:H,startThreeLoading:B,stopThreeLoading:K,showCameraError:z}=p();O(s);G(null==e.defaultUI||e.defaultUI,D,_,N,I),function(e,t){const o=e.parentNode;if(null==o)throw new n("Parent node missing.");new MutationObserver((n=>{for(const o of n)for(const n of o.removedNodes)if(n===e)return void t()})).observe(o,{childList:!0})}(s,(()=>{W()!==ye.QR||X()||Y(),W()!==ye.AR||it||ut(),W()!==ye.Preview||ne()||ie(),Q(ye.None)}));const{qrPaused:X,qrDraw:Z,qrPause:Y}=v(),{threeInit:J,threeParse:ee,threeLoad:te,threePaused:ne,threeResume:oe,threePause:ie,threeSetOnInteracted:ae}=w();let se=0;if(W()===ye.QR){if(!X())if(D){S($e);try{yield Z(i,a)}catch(e){throw new n(`QR failed: ${e instanceof Error?e.message:"Unknown error."}`)}}else Y(),Q(ye.None)}else if(W()===ye.AR){if(!it)if(_){S(Ue);const e=yield Xe(P);bt(h(),E),Te(d),lt(q()),yield dt(e,P),ct(A),bt(h(),E)}else ut(),Q(ye.None)}else if(W()===ye.Preview&&!ne())if(N){S(De),B();const e=255,t=yield ft(x,(new Date).getTime()+e,Math.random()*e);bt(h(),E);const n=yield Xe(null!=k?k:`${y}/env/default.hdr`);bt(h(),E);const o=yield ee(t,n,`${x}${k}`);bt(h(),E),te(o,I),ae(C),K()}else ie(),Q(ye.None);const le=()=>t(this,void 0,void 0,(function*(){if(D){if(W()===ye.QR||W()===ye.AR)throw new n("AR already launched.");try{S($e);const e=++se;if(W()===ye.Preview&&N&&!ne()&&ie(),Q(ye.QR),yield Z(i,a),se!==e)return;return void bt(h(),E)}catch(e){const t=e instanceof Error;throw S("qrLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`QR failed: ${t?e.message:"Unknown error."}`)}}if(!_)throw new n("Model does not have AR enabled.");if(W()===ye.AR)throw new n("AR already launched.");try{S(Ue);const e=++se;W()===ye.Preview&&N&&!ne()&&ie(),Te(d),Q(ye.AR),V();const n=yield Xe(P);if(se!==e)return;if(bt(h(),E),yield He,se!==e)return;if(bt(h(),E),ut(),lt(q()),yield st(L,I),se!==e)return;if(bt(h(),E),yield dt(n,P),ct(A),se!==e)return;if(bt(h(),E),yield function(){return t(this,void 0,void 0,(function*(){if(null!=Ze){if(it=!1,null==Ye){const e=ht(Je),t=We(e);Ye=yield Qe(t),yield pt(Ze,Ye,"user"===e)}Ze.setPaused(it),et.style.display=""}}))}(),se!==e)return;bt(h(),E)}catch(e){const t=e instanceof Error;throw S("arLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),z(),ut(),new n(`AR failed: ${t?e.message:"Unknown error."}`)}finally{H()}})),ce=()=>t(this,void 0,void 0,(function*(){if(!N)throw new n("Model does not have 3D enabled.");if(W()===ye.Preview)throw new n("3D already launched.");try{S(De);const e=++se;W()===ye.AR&&(_&&!it&&ut(),Y()),Q(ye.Preview),B();const t=255,n=yield ft(x,(new Date).getTime()+t,Math.random()*t);if(se!==e)return;bt(h(),E);const o=yield Xe(null!=k?k:`${y}/env/default.hdr`);if(se!==e)return;if(bt(h(),E),yield j,se!==e)return;if(bt(h(),E),J(),se!==e)return;bt(h(),E);const r=yield ee(n,o,`${x}${k}`);if(se!==e)return;bt(h(),E),te(r,I),ae(C),oe()}catch(e){const t=e instanceof Error;throw S("previewLaunchFailure",{errorName:t?e.name:"Unknown",errorMessage:t?e.message:""}),new n(`3D failed: ${t?e.message:"Unknown error."}`)}finally{K()}})),de=()=>t(this,void 0,void 0,(function*(){if(W()===ye.None)throw new n("Neither AR or 3D launched.");++se,W()===ye.QR||W()===ye.AR?(_&&!it&&ut(),Y()):W()===ye.Preview&&N&&!ne()&&ie(),Q(ye.None)}));return F(le,ce,de),"AR"===l?(yield le(),bt(h(),E)):"3D"===l&&(yield ce(),bt(h(),E)),{launchAR:M?le:void 0,launch3D:N?ce:void 0,closeAR:M?()=>t(this,void 0,void 0,(function*(){if(W()!==ye.AR&&W()!==ye.QR)throw new n("AR not launched.");++se,_&&!it&&ut(),Y(),Q(ye.None)})):void 0,close3D:N?()=>t(this,void 0,void 0,(function*(){if(W()!==ye.Preview)throw new n("3D not launched.");++se,N&&!ne()&&ie(),Q(ye.None)})):void 0,close:M||N?de:void 0}}))}function bt(e,t){if(e!==t)throw new n("Setup cancelled. Please ensure that setup is only called once.")}const Rt={setup:function(e){return t(this,void 0,void 0,(function*(){return function(e,o){return t(this,void 0,void 0,(function*(){try{return o()}catch(t){throw t instanceof Error?new n(`${e} failed: ${t.message}`):(console.error(t),new n(`${e} failed.`))}}))}("setup",(()=>yt(e)))}))},version:v};e.plugin=Rt}));