shopar-plugin
Version:
Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.
1 lines • 5.86 kB
JavaScript
(()=>{"use strict";var e;const r=(e="undefined"!=typeof document?document.currentScript?.src:void 0,function(r={}){var t,n,a,o,i=r,s=new Promise(((e,r)=>{t=e,n=r})),c=Object.assign({},i),f="";f=self.location.href,e&&(f=e),f=f.startsWith("blob:")?"":f.substr(0,f.replace(/[?#].*/,"").lastIndexOf("/")+1),o=e=>{var r=new XMLHttpRequest;return r.open("GET",e,!1),r.responseType="arraybuffer",r.send(null),new Uint8Array(r.response)},a=e=>fetch(e,{credentials:"same-origin"}).then((e=>e.ok?e.arrayBuffer():Promise.reject(Error(e.status+" : "+e.url))));var d,l=console.log.bind(console),u=console.error.bind(console);Object.assign(i,c),c=null,i.wasmBinary&&(d=i.wasmBinary);var h,m,y,v,b=!1;function w(){var e=h.buffer;i.HEAP8=m=new Int8Array(e),i.HEAP16=new Int16Array(e),i.HEAPU8=y=new Uint8Array(e),i.HEAPU16=new Uint16Array(e),i.HEAP32=new Int32Array(e),i.HEAPU32=v=new Uint32Array(e),i.HEAPF32=new Float32Array(e),i.HEAPF64=new Float64Array(e)}var g=[],A=[],p=[],P=!1,E=0,_=null,U=null;function D(e){throw u(e="Aborted("+e+")"),b=!0,e+=". Build with -sASSERTIONS for more info.",P&&O(),e=new WebAssembly.RuntimeError(e),n(e),e}var C,H=e=>e.startsWith("data:application/octet-stream;base64,");function I(e){if(e==C&&d)return new Uint8Array(d);if(o)return o(e);throw"both async and sync fetching of the wasm failed"}function S(e,r,t){return function(e){return d?Promise.resolve().then((()=>I(e))):a(e).then((e=>new Uint8Array(e)),(()=>I(e)))}(e).then((e=>WebAssembly.instantiate(e,r))).then(t,(e=>{u(`failed to asynchronously prepare wasm: ${e}`),D(e)}))}var B,k=[null,[],[]],x="undefined"!=typeof TextDecoder?new TextDecoder:void 0,j=(e,r)=>{for(var t=r+NaN,n=r;e[n]&&!(n>=t);)++n;if(16<n-r&&e.buffer&&x)return x.decode(e.subarray(r,n));for(t="";r<n;){var a=e[r++];if(128&a){var o=63&e[r++];if(192==(224&a))t+=String.fromCharCode((31&a)<<6|o);else{var i=63&e[r++];65536>(a=224==(240&a)?(15&a)<<12|o<<6|i:(7&a)<<18|o<<12|i<<6|63&e[r++])?t+=String.fromCharCode(a):(a-=65536,t+=String.fromCharCode(55296|a>>10,56320|1023&a))}}else t+=String.fromCharCode(a)}return t},M={c:()=>{D("")},d:e=>{var r=y.length;if(2147483648<(e>>>=0))return!1;for(var t=1;4>=t;t*=2){var n=r*(1+.2/t);n=Math.min(n,e+100663296);var a=Math;n=Math.max(e,n);e:{a=(a.min.call(a,2147483648,n+(65536-n%65536)%65536)-h.buffer.byteLength+65535)/65536;try{h.grow(a),w();var o=1;break e}catch(e){}o=void 0}if(o)return!0}return!1},e:()=>52,b:function(){return 70},a:(e,r,t,n)=>{for(var a=0,o=0;o<t;o++){var i=v[r>>2],s=v[r+4>>2];r+=8;for(var c=0;c<s;c++){var f=y[i+c],d=k[e];0===f||10===f?((1===e?l:u)(j(d,0)),d.length=0):d.push(f)}a+=s}return v[n>>2]=a,0}},F=(B={a:M},E++,C||=H("draco-decoder.wasm")?"draco-decoder.wasm":f+"draco-decoder.wasm",function(e,r){var t=C;return d||"function"!=typeof WebAssembly.instantiateStreaming||H(t)||"function"!=typeof fetch?S(t,e,r):fetch(t,{credentials:"same-origin"}).then((n=>WebAssembly.instantiateStreaming(n,e).then(r,(function(n){return u(`wasm streaming compile failed: ${n}`),u("falling back to ArrayBuffer instantiation"),S(t,e,r)}))))}(B,(function(e){F=e.instance.exports,h=F.f,w(),A.unshift(F.g),0==--E&&(null!==_&&(clearInterval(_),_=null),U&&(e=U,U=null,e()))})).catch(n),{});i._malloc=e=>(i._malloc=F.h)(e),i._dracoDecode=(e,r,t)=>(i._dracoDecode=F.i)(e,r,t),i._getDecodedDataPtr=()=>(i._getDecodedDataPtr=F.k)(),i._free=e=>(i._free=F.l)(e);var W,O=()=>(O=F.m)(),T=e=>(T=F.n)(e),L=e=>(L=F.o)(e),R=()=>(R=F.p)();function N(){if(!(0<E)){for(;0<g.length;)g.shift()(i);if(!(0<E||W||(W=!0,i.calledRun=!0,b))){for(P=!0;0<A.length;)A.shift()(i);for(t(i);0<p.length;)p.shift()(i)}}}return i.cwrap=(e,r,t,n)=>{var a=!t||t.every((e=>"number"===e||"boolean"===e));return"string"!==r&&a&&!n?i["_"+e]:(...n)=>((e,r,t,n)=>{var a={string:e=>{var r=0;if(null!=e&&0!==e){for(var t=r=0;t<e.length;++t){var n=e.charCodeAt(t);127>=n?r++:2047>=n?r+=2:55296<=n&&57343>=n?(r+=4,++t):r+=3}var a=r+1;if(t=r=L(a),n=y,0<a){a=t+a-1;for(var o=0;o<e.length;++o){var i=e.charCodeAt(o);if(55296<=i&&57343>=i&&(i=65536+((1023&i)<<10)|1023&e.charCodeAt(++o)),127>=i){if(t>=a)break;n[t++]=i}else{if(2047>=i){if(t+1>=a)break;n[t++]=192|i>>6}else{if(65535>=i){if(t+2>=a)break;n[t++]=224|i>>12}else{if(t+3>=a)break;n[t++]=240|i>>18,n[t++]=128|i>>12&63}n[t++]=128|i>>6&63}n[t++]=128|63&i}}n[t]=0}}return r},array:e=>{var r=L(e.length);return m.set(e,r),r}};e=i["_"+e];var o,s=[],c=0;if(n)for(var f=0;f<n.length;f++){var d=a[t[f]];d?(0===c&&(c=R()),s[f]=d(n[f])):s[f]=n[f]}return o=t=e(...s),0!==c&&T(c),"string"===r?o?j(y,o):"":"boolean"===r?!!o:o})(e,r,t,n)},U=function e(){W||N(),W||(U=e)},N(),s});let t=null;self.onmessage=e=>{const a=e.data;if("init"===a.type)(function(e){return a=this,o=void 0,s=function*(){const a=yield r({wasmBinary:e});t=new n(a),a.wasmBinary=null},new((i=void 0)||(i=Promise))((function(e,r){function t(e){try{c(s.next(e))}catch(e){r(e)}}function n(e){try{c(s.throw(e))}catch(e){r(e)}}function c(r){var a;r.done?e(r.value):(a=r.value,a instanceof i?a:new i((function(e){e(a)}))).then(t,n)}c((s=s.apply(a,o||[])).next())}));var a,o,i,s})(e.data.wasmBuffer).then((()=>{postMessage({type:"ready"})}));else if("decode"===a.type){const r=e.data;if(!t)return void console.error("Draco decoder not initialized!");const n=r.data;try{const e=t.decode(n,r.preserveVertexOrder).buffer;postMessage({type:"decoded",data:e,jobId:r.jobId},void 0,[e])}catch(e){console.error("Failed to decode draco mesh"),postMessage({type:"decoded",data:new ArrayBuffer(0),jobId:r.jobId})}}};class n{constructor(e){this.module=e}decode(e,r){const t=this.module._malloc(e.byteLength);this.module.HEAPU8.set(new Uint8Array(e),t);const n=this.module._dracoDecode(t,e.byteLength,r);if(this.module._free(t),0===n)throw new Error("Failed to decode draco mesh");const a=new Uint8Array(n),o=this.module._getDecodedDataPtr();return a.set(this.module.HEAPU8.subarray(o,o+n)),this.module._free(o),a}}})();