piling.js
Version:
A WebGL-based Library for Visual Piling/Stacking
21 lines • 440 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("pixi.js")):"function"==typeof define&&define.amd?define(["exports","pixi.js"],t):t((e=e||self).pilingJs={},e.PIXI)}(this,(function(e,t){"use strict";function n(e,t,n,r,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(r,i)}var r=function(e){return function(){var t=this,r=arguments;return new Promise((function(i,o){var a=e.apply(t,r);function s(e){n(a,i,o,s,u,"next",e)}function u(e){n(a,i,o,s,u,"throw",e)}s(void 0)}))}},i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function a(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports}var s=a((function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function s(e,t,n,r){var i=t&&t.prototype instanceof l?t:l,o=Object.create(i.prototype),a=new S(r||[]);return o._invoke=function(e,t,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return k()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=b(a,n);if(s){if(s===c)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var l=u(e,t,n);if("normal"===l.type){if(r=n.done?"completed":"suspendedYield",l.arg===c)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(r="completed",n.method="throw",n.arg=l.arg)}}}(e,n,a),o}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var c={};function l(){}function f(){}function h(){}var p={};p[i]=function(){return this};var d=Object.getPrototypeOf,g=d&&d(d(E([])));g&&g!==t&&n.call(g,i)&&(p=g);var m=h.prototype=l.prototype=Object.create(p);function v(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function y(e,t){var r;this._invoke=function(i,o){function a(){return new t((function(r,a){!function r(i,o,a,s){var c=u(e[i],e,o);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(f).then((function(e){l.value=e,a(l)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}}function b(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return c;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return c}var r=u(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,c;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,c):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,c)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function E(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:k}}function k(){return{value:void 0,done:!0}}return f.prototype=m.constructor=h,h.constructor=f,h[a]=f.displayName="GeneratorFunction",e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,a in e||(e[a]="GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},v(y.prototype),y.prototype[o]=function(){return this},e.AsyncIterator=y,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new y(s(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},v(m),m[a]="Generator",m[i]=function(){return this},m.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=E,S.prototype={constructor:S,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var s=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,c):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),c},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),x(n),c}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;x(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),c}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}));var u=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r};var c=function(e){if(Array.isArray(e))return u(e)};var l=function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)};var f=function(e,t){if(e){if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(e,t):void 0}};var h=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")};var p=function(e){return c(e)||l(e)||f(e)||h()};var d=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e};var g=function(e){if(Array.isArray(e))return e};var m=function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}};var v=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")};var y=function(e,t){return g(e)||m(e,t)||f(e,t)||v()},b="undefined"!=typeof Float32Array?Float32Array:Array;function w(){var e=new b(16);return b!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function x(e){var t=new b(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function S(e,t){var n=t[0],r=t[1],i=t[2],o=t[3],a=t[4],s=t[5],u=t[6],c=t[7],l=t[8],f=t[9],h=t[10],p=t[11],d=t[12],g=t[13],m=t[14],v=t[15],y=n*s-r*a,b=n*u-i*a,w=n*c-o*a,x=r*u-i*s,S=r*c-o*s,E=i*c-o*u,k=l*g-f*d,M=l*m-h*d,O=l*v-p*d,A=f*m-h*g,j=f*v-p*g,P=h*v-p*m,C=y*P-b*j+w*A+x*O-S*M+E*k;return C?(C=1/C,e[0]=(s*P-u*j+c*A)*C,e[1]=(i*j-r*P-o*A)*C,e[2]=(g*E-m*S+v*x)*C,e[3]=(h*S-f*E-p*x)*C,e[4]=(u*O-a*P-c*M)*C,e[5]=(n*P-i*O+o*M)*C,e[6]=(m*w-d*E-v*b)*C,e[7]=(l*E-h*w+p*b)*C,e[8]=(a*j-s*O+c*k)*C,e[9]=(r*O-n*j-o*k)*C,e[10]=(d*S-g*w+v*y)*C,e[11]=(f*w-l*S-p*y)*C,e[12]=(s*M-a*A-u*k)*C,e[13]=(n*A-r*M+i*k)*C,e[14]=(g*b-d*x-m*y)*C,e[15]=(l*x-f*b+h*y)*C,e):null}function E(e,t,n){var r=t[0],i=t[1],o=t[2],a=t[3],s=t[4],u=t[5],c=t[6],l=t[7],f=t[8],h=t[9],p=t[10],d=t[11],g=t[12],m=t[13],v=t[14],y=t[15],b=n[0],w=n[1],x=n[2],S=n[3];return e[0]=b*r+w*s+x*f+S*g,e[1]=b*i+w*u+x*h+S*m,e[2]=b*o+w*c+x*p+S*v,e[3]=b*a+w*l+x*d+S*y,b=n[4],w=n[5],x=n[6],S=n[7],e[4]=b*r+w*s+x*f+S*g,e[5]=b*i+w*u+x*h+S*m,e[6]=b*o+w*c+x*p+S*v,e[7]=b*a+w*l+x*d+S*y,b=n[8],w=n[9],x=n[10],S=n[11],e[8]=b*r+w*s+x*f+S*g,e[9]=b*i+w*u+x*h+S*m,e[10]=b*o+w*c+x*p+S*v,e[11]=b*a+w*l+x*d+S*y,b=n[12],w=n[13],x=n[14],S=n[15],e[12]=b*r+w*s+x*f+S*g,e[13]=b*i+w*u+x*h+S*m,e[14]=b*o+w*c+x*p+S*v,e[15]=b*a+w*l+x*d+S*y,e}function k(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function M(e,t,n){var r=t[0],i=t[1],o=t[2],a=t[3];return e[0]=n[0]*r+n[4]*i+n[8]*o+n[12]*a,e[1]=n[1]*r+n[5]*i+n[9]*o+n[13]*a,e[2]=n[2]*r+n[6]*i+n[10]*o+n[14]*a,e[3]=n[3]*r+n[7]*i+n[11]*o+n[15]*a,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});var O,A;O=new b(4),b!=Float32Array&&(O[0]=0,O[1]=0,O[2]=0,O[3]=0),A=O;!function(){var e=function(){var e=new b(2);return b!=Float32Array&&(e[0]=0,e[1]=0),e}()}();const j=(e=[0,0],t=1,n=0,r=[0,0],i=[0,1/0])=>{const o=new Float32Array(16),a=new Float32Array(16),s=new Float32Array(16);let u=w(),c=[...r.slice(0,2),0,1];const l=[...i],f=()=>function(e,t){var n=t[0],r=t[1],i=t[2],o=t[4],a=t[5],s=t[6],u=t[8],c=t[9],l=t[10];return e[0]=Math.hypot(n,r,i),e[1]=Math.hypot(o,a,s),e[2]=Math.hypot(u,c,l),e}(o,u)[0],h=([e=0,t=0]=[],n=1,r=0)=>{u=w(),p([-e,-t]),g(r),d(1/n)},p=([e=0,t=0]=[])=>{o[0]=e,o[1]=t,o[2]=0;const n=k(a,o);E(u,n,u)},d=(e,t)=>{if(e<=0)return;const n=f(),r=n*e;if(1===(e=Math.max(l[0],Math.min(r,l[1]))/n))return;o[0]=e,o[1]=e,o[2]=1;const i=function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(a,o),h=t?[...t,0]:c,p=k(o,h);E(u,p,E(u,i,E(u,S(s,p),u)))},g=e=>{const t=w();!function(e,t,n){var r,i,o,a=n[0],s=n[1],u=n[2],c=Math.hypot(a,s,u);c<1e-6||(a*=c=1/c,s*=c,u*=c,r=Math.sin(t),o=1-(i=Math.cos(t)),e[0]=a*a*o+i,e[1]=s*a*o+u*r,e[2]=u*a*o-s*r,e[3]=0,e[4]=a*s*o-u*r,e[5]=s*s*o+i,e[6]=u*s*o+a*r,e[7]=0,e[8]=a*u*o+s*r,e[9]=s*u*o-a*r,e[10]=u*u*o+i,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1)}(t,e,[0,0,1]),E(u,t,u)},m=e=>{!e||e.length<16||(u=e)};return h(e,t,n),{get translation(){return function(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}(o,u).slice(0,2)},get target(){return M(o,c,S(s,u)).slice(0,2)},get scaling(){return f()},get scaleBounds(){return[...l]},get distance(){return 1/f()},get rotation(){return Math.acos(u[0])},get view(){return u},get viewCenter(){return c.slice(0,2)},lookAt:h,translate:p,pan:p,rotate:g,scale:d,zoom:d,reset:()=>{h(e,t,n)},set:(...e)=>(console.warn("Deprecated. Please use `setView()` instead."),m(...e)),setScaleBounds:e=>{l[0]=e[0],l[1]=e[1]},setView:m,setViewCenter:e=>{c=[...e.slice(0,2),0,1]}}},P=(e,{distance:t=1,target:n=[0,0],rotation:r=0,isNdc:i=!0,isFixed:o=!1,isPan:a=!0,panSpeed:s=1,isRotate:u=!0,rotateSpeed:c=1,isZoom:l=!0,zoomSpeed:f=1,viewCenter:h=null,scaleBounds:p=null,onKeyDown:d=(()=>{}),onKeyUp:g=(()=>{}),onMouseDown:m=(()=>{}),onMouseUp:v=(()=>{}),onMouseMove:y=(()=>{}),onWheel:b=(()=>{})}={})=>{let w=j(n,t,r,h,p),x=!1,S=0,E=0,k=0,M=0,O=!1,A=0,P=0,C=0,_=1,I=1,R=1,T=!1;const L=i?e=>e/_*2*R:e=>e,B=i?e=>e/I*2:e=>-e,N=i?e=>(e/_*2-1)*R:e=>e,D=i?e=>1-e/I*2:e=>e,z=()=>{const t=e.getBoundingClientRect();P=t.top,C=t.left,_=t.width,I=t.height,R=_/I},F=e=>{T=!1,g(e)},V=e=>{T=e.altKey,d(e)},U=e=>{O=!1,v(e)},Y=e=>{O=1===e.buttons,m(e)},X=e=>{k=S,M=E,S=e.clientX-C,E=e.clientY-P,y(e)},q=e=>{e.preventDefault();const t=1===e.deltaMode?12:1;A+=t*(e.deltaY||0),b(e)};return window.addEventListener("keydown",V,{passive:!0}),window.addEventListener("keyup",F,{passive:!0}),e.addEventListener("mousedown",Y,{passive:!0}),window.addEventListener("mouseup",U,{passive:!0}),window.addEventListener("mousemove",X,{passive:!0}),e.addEventListener("wheel",q,{passive:!1}),z(),w.config=({isFixed:e=null,isPan:t=null,isRotate:n=null,isZoom:r=null,panSpeed:i=null,rotateSpeed:h=null,zoomSpeed:p=null}={})=>{o=null!==e?e:o,a=null!==t?t:a,u=null!==n?n:u,l=null!==r?r:l,s=+i>0?i:s,c=+h>0?h:c,f=+p>0?p:f},w.dispose=()=>{w=void 0,window.removeEventListener("keydown",V),window.removeEventListener("keyup",F),e.removeEventListener("mousedown",Y),window.removeEventListener("mouseup",U),window.removeEventListener("mousemove",X),e.removeEventListener("wheel",q)},w.refresh=z,w.tick=()=>{if(o)return!1;if(x=!1,a&&O&&!T&&(w.pan([L(s*(S-k)),B(s*(M-E))]),x=!0),l&&A){const e=f*Math.exp(A/I),t=N(S),n=D(E);w.scale(1/e,[t,n]),x=!0}if(u&&O&&T){const e=_/2,t=I/2,n=k-e,r=t-M,i=S-e,o=t-E,a=function(e,t){var n=e[0],r=e[1],i=t[0],o=t[1],a=n*n+r*r;a>0&&(a=1/Math.sqrt(a));var s=i*i+o*o;s>0&&(s=1/Math.sqrt(s));var u=(n*i+r*o)*a*s;return u>1?0:u<-1?Math.PI:Math.acos(u)}([n,r],[i,o]),s=n*o-i*r;w.rotate(c*a*Math.sign(s)),x=!0}return A=0,k=S,M=E,x},w},C=(()=>{try{return new window.BroadcastChannel("pub-sub-es")}catch(e){return{postMessage:()=>{}}}})(),_=e=>(t,n,r=1/0)=>(e[t]||(e[t]=[],e.__times__[t]=[]),e[t].push(n),e.__times__[t].push(+r||1/0),{event:t,handler:n}),I=e=>(t,n)=>{if("object"==typeof t&&(n=t.handler,t=t.event),!e[t])return;const r=e[t].indexOf(n);-1===r||r>=e[t].length||(e[t].splice(r,1),e.__times__[t].splice(r,1))},R=(e,t)=>(n,r,i)=>{if(!e[n])return;const o=I(e);if(e[n].forEach((t,i)=>{t(r),e.__times__[n][i]--,e.__times__[n][i]<1&&o(n,t)}),t&&!i)try{C.postMessage({event:n,news:r})}catch(e){if(!(e instanceof DOMException))throw e;console.warn(`Could not broadcast '${n}' globally. Payload is not clonable.`)}},T=e=>()=>{Object.keys(e).filter(e=>"_"!==e[0]).forEach(t=>{e[t]=void 0,e.__times__[t]=void 0,delete e[t],delete e.__times__[t]})},L=(e={__times__:{}})=>(e.__times__||(e.__times__={}),{publish:R(e),subscribe:_(e),unsubscribe:I(e),clear:T(e),stack:e}),B={__times__:{}},N={publish:R(B,!0),subscribe:_(B),unsubscribe:I(B),stack:B};C.onmessage=({data:{event:e,news:t}})=>N.publish(e,t,!0);const D=(e,t,n=window.requestAnimationFrame)=>{let r,i=!1;return(...o)=>{if(r=o,!i)return i=!0,n(()=>{const n=e(...r);i=!1,t&&t(n)})}};var z,F,V,U,Y,X,q,H,G,W,$,K,Z,Q,J,ee=a((function(e,t){e.exports=function(){function e(e,r,i,o,a){!function e(n,r,i,o,a){for(;o>i;){if(o-i>600){var s=o-i+1,u=r-i+1,c=Math.log(s),l=.5*Math.exp(2*c/3),f=.5*Math.sqrt(c*l*(s-l)/s)*(u-s/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-u*l/s+f)),Math.min(o,Math.floor(r+(s-u)*l/s+f)),a)}var h=n[r],p=i,d=o;for(t(n,i,r),a(n[o],h)>0&&t(n,i,o);p<d;){for(t(n,p,d),p++,d--;a(n[p],h)<0;)p++;for(;a(n[d],h)>0;)d--}0===a(n[i],h)?t(n,i,d):t(n,++d,o),d<=r&&(i=d+1),r<=d&&(o=d-1)}}(e,r,i||0,o||e.length-1,a||n)}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return e<t?-1:e>t?1:0}var r=function(e){void 0===e&&(e=9),this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function i(e,t,n){if(!n)return t.indexOf(e);for(var r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function o(e,t){a(e,0,e.children.length,t,e)}function a(e,t,n,r,i){i||(i=d(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(var o=t;o<n;o++){var a=e.children[o];s(i,e.leaf?r(a):a)}return i}function s(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function u(e,t){return e.minX-t.minX}function c(e,t){return e.minY-t.minY}function l(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function f(e){return e.maxX-e.minX+(e.maxY-e.minY)}function h(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function p(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function d(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function g(t,n,r,i,o){for(var a=[n,r];a.length;)if(!((r=a.pop())-(n=a.pop())<=i)){var s=n+Math.ceil((r-n)/i/2)*i;e(t,s,n,r,o),a.push(n,s,s,r)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(e){var t=this.data,n=[];if(!p(e,t))return n;for(var r=this.toBBox,i=[];t;){for(var o=0;o<t.children.length;o++){var a=t.children[o],s=t.leaf?r(a):a;p(e,s)&&(t.leaf?n.push(a):h(e,s)?this._all(a,n):i.push(a))}t=i.pop()}return n},r.prototype.collides=function(e){var t=this.data;if(!p(e,t))return!1;for(var n=[];t;){for(var r=0;r<t.children.length;r++){var i=t.children[r],o=t.leaf?this.toBBox(i):i;if(p(e,o)){if(t.leaf||h(e,o))return!0;n.push(i)}}t=n.pop()}return!1},r.prototype.load=function(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(var t=0;t<e.length;t++)this.insert(e[t]);return this}var n=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},r.prototype.insert=function(e){return e&&this._insert(e,this.data.height-1),this},r.prototype.clear=function(){return this.data=d([]),this},r.prototype.remove=function(e,t){if(!e)return this;for(var n,r,o,a=this.data,s=this.toBBox(e),u=[],c=[];a||u.length;){if(a||(a=u.pop(),r=u[u.length-1],n=c.pop(),o=!0),a.leaf){var l=i(e,a.children,t);if(-1!==l)return a.children.splice(l,1),u.push(a),this._condense(u),this}o||a.leaf||!h(a,s)?r?(n++,a=r.children[n],o=!1):a=null:(u.push(a),c.push(n),n=0,r=a,a=a.children[0])}return this},r.prototype.toBBox=function(e){return e},r.prototype.compareMinX=function(e,t){return e.minX-t.minX},r.prototype.compareMinY=function(e,t){return e.minY-t.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(e){return this.data=e,this},r.prototype._all=function(e,t){for(var n=[];e;)e.leaf?t.push.apply(t,e.children):n.push.apply(n,e.children),e=n.pop();return t},r.prototype._build=function(e,t,n,r){var i,a=n-t+1,s=this._maxEntries;if(a<=s)return o(i=d(e.slice(t,n+1)),this.toBBox),i;r||(r=Math.ceil(Math.log(a)/Math.log(s)),s=Math.ceil(a/Math.pow(s,r-1))),(i=d([])).leaf=!1,i.height=r;var u=Math.ceil(a/s),c=u*Math.ceil(Math.sqrt(s));g(e,t,n,c,this.compareMinX);for(var l=t;l<=n;l+=c){var f=Math.min(l+c-1,n);g(e,l,f,u,this.compareMinY);for(var h=l;h<=f;h+=u){var p=Math.min(h+u-1,f);i.children.push(this._build(e,h,p,r-1))}}return o(i,this.toBBox),i},r.prototype._chooseSubtree=function(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){for(var i=1/0,o=1/0,a=void 0,s=0;s<t.children.length;s++){var u=t.children[s],c=l(u),f=(h=e,p=u,(Math.max(p.maxX,h.maxX)-Math.min(p.minX,h.minX))*(Math.max(p.maxY,h.maxY)-Math.min(p.minY,h.minY))-c);f<o?(o=f,i=c<i?c:i,a=u):f===o&&c<i&&(i=c,a=u)}t=a||t.children[0]}var h,p;return t},r.prototype._insert=function(e,t,n){var r=n?e:this.toBBox(e),i=[],o=this._chooseSubtree(r,this.data,t,i);for(o.children.push(e),s(o,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)},r.prototype._split=function(e,t){var n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);var a=this._chooseSplitIndex(n,i,r),s=d(n.children.splice(a,n.children.length-a));s.height=n.height,s.leaf=n.leaf,o(n,this.toBBox),o(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)},r.prototype._splitRoot=function(e,t){this.data=d([e,t]),this.data.height=e.height+1,this.data.leaf=!1,o(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(e,t,n){for(var r,i,o,s,u,c,f,h=1/0,p=1/0,d=t;d<=n-t;d++){var g=a(e,0,d,this.toBBox),m=a(e,d,n,this.toBBox),v=(i=g,o=m,s=Math.max(i.minX,o.minX),u=Math.max(i.minY,o.minY),c=Math.min(i.maxX,o.maxX),f=Math.min(i.maxY,o.maxY),Math.max(0,c-s)*Math.max(0,f-u)),y=l(g)+l(m);v<h?(h=v,r=d,p=y<p?y:p):v===h&&y<p&&(p=y,r=d)}return r||n-t},r.prototype._chooseSplitAxis=function(e,t,n){var r=e.leaf?this.compareMinX:u,i=e.leaf?this.compareMinY:c;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)},r.prototype._allDistMargin=function(e,t,n,r){e.children.sort(r);for(var i=this.toBBox,o=a(e,0,t,i),u=a(e,n-t,n,i),c=f(o)+f(u),l=t;l<n-t;l++){var h=e.children[l];s(o,e.leaf?i(h):h),c+=f(o)}for(var p=n-t-1;p>=t;p--){var d=e.children[p];s(u,e.leaf?i(d):d),c+=f(u)}return c},r.prototype._adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)s(t[r],e)},r.prototype._condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)0===e[t].children.length?t>0?(n=e[t-1].children).splice(n.indexOf(e[t]),1):this.clear():o(e[t],this.toBBox)},r}()})),te=!1;function ne(){if(!te){te=!0;var e=navigator.userAgent,t=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(e),n=/(Mac OS X)|(Windows)|(Linux)/.exec(e);if(K=/\b(iPhone|iP[ao]d)/.exec(e),Z=/\b(iP[ao]d)/.exec(e),W=/Android/i.exec(e),Q=/FBAN\/\w+;/i.exec(e),J=/Mobile/i.exec(e),$=!!/Win64/.exec(e),t){(z=t[1]?parseFloat(t[1]):t[5]?parseFloat(t[5]):NaN)&&document&&document.documentMode&&(z=document.documentMode);var r=/(?:Trident\/(\d+.\d+))/.exec(e);X=r?parseFloat(r[1])+4:z,F=t[2]?parseFloat(t[2]):NaN,V=t[3]?parseFloat(t[3]):NaN,(U=t[4]?parseFloat(t[4]):NaN)?(t=/(?:Chrome\/(\d+\.\d+))/.exec(e),Y=t&&t[1]?parseFloat(t[1]):NaN):Y=NaN}else z=F=V=Y=U=NaN;if(n){if(n[1]){var i=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(e);q=!i||parseFloat(i[1].replace("_","."))}else q=!1;H=!!n[2],G=!!n[3]}else q=H=G=!1}}var re,ie={ie:function(){return ne()||z},ieCompatibilityMode:function(){return ne()||X>z},ie64:function(){return ie.ie()&&$},firefox:function(){return ne()||F},opera:function(){return ne()||V},webkit:function(){return ne()||U},safari:function(){return ie.webkit()},chrome:function(){return ne()||Y},windows:function(){return ne()||H},osx:function(){return ne()||q},linux:function(){return ne()||G},iphone:function(){return ne()||K},mobile:function(){return ne()||K||Z||W||J},nativeApp:function(){return ne()||Q},android:function(){return ne()||W},ipad:function(){return ne()||Z}},oe=ie,ae=!("undefined"==typeof window||!window.document||!window.document.createElement),se={canUseDOM:ae,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:ae&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:ae&&!!window.screen,isInWorker:!ae};se.canUseDOM&&(re=document.implementation&&document.implementation.hasFeature&&!0!==document.implementation.hasFeature("",""))
/**
* Checks if an event is supported in the current execution environment.
*
* NOTE: This will not work correctly for non-generic events such as `change`,
* `reset`, `load`, `error`, and `select`.
*
* Borrows from Modernizr.
*
* @param {string} eventNameSuffix Event name, e.g. "click".
* @param {?boolean} capture Check if the capture phase is supported.
* @return {boolean} True if the event is supported.
* @internal
* @license Modernizr 3.0.0pre (Custom Build) | MIT
*/;var ue=function(e,t){if(!se.canUseDOM||t&&!("addEventListener"in document))return!1;var n="on"+e,r=n in document;if(!r){var i=document.createElement("div");i.setAttribute(n,"return;"),r="function"==typeof i[n]}return!r&&re&&"wheel"===e&&(r=document.implementation.hasFeature("Events.wheel","3.0")),r};function ce(e){var t=0,n=0,r=0,i=0;return"detail"in e&&(n=e.detail),"wheelDelta"in e&&(n=-e.wheelDelta/120),"wheelDeltaY"in e&&(n=-e.wheelDeltaY/120),"wheelDeltaX"in e&&(t=-e.wheelDeltaX/120),"axis"in e&&e.axis===e.HORIZONTAL_AXIS&&(t=n,n=0),r=10*t,i=10*n,"deltaY"in e&&(i=e.deltaY),"deltaX"in e&&(r=e.deltaX),(r||i)&&e.deltaMode&&(1==e.deltaMode?(r*=40,i*=40):(r*=800,i*=800)),r&&!t&&(t=r<1?-1:1),i&&!n&&(n=i<1?-1:1),{spinX:t,spinY:n,pixelX:r,pixelY:i}}ce.getEventType=function(){return oe.firefox()?"DOMMouseScroll":ue("wheel")?"wheel":"mousewheel"};var le=ce,fe="BATCHING_REDUCER.BATCH";function he(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:fe;return{type:t,meta:{batch:!0},payload:e}}const pe=e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1,de=e=>--e*e*e+1,ge=(e,t,n)=>e*(1-(n=Math.min(1,Math.max(0,n))))+t*n,me=(e,t,n)=>e.map((e,r)=>ge(e,t[r],n)),ve=e=>e,ye=(e,t,n=6)=>Math.abs(e-t)<10**-n,be=(e,t=ve)=>{const n=new Set,r=[];for(let i=0;i<e.length;i++){const o=t(e[i]);n.has(o)||(n.add(o),r.push(o))}return r},we=Array.isArray,xe=e=>!!(e&&e.constructor&&e.call&&e.apply),Se=e=>!!e&&e.constructor===Object,Ee=e=>Math.sqrt(e.reduce((e,t)=>e+t**2,0)),ke=e=>e.reduce((e,t)=>t>e?t:e,-1/0),Me=e=>{switch(e.length){case 0:return[];case 1:return e[0];default:return e.reduce((e,t)=>t.map((t,n)=>e[n]>t?e[n]:t),new Array(e[0].length).fill(-1/0))}},Oe=e=>Re(e)/e.length,Ae=e=>{switch(e.length){case 0:return[];case 1:return e[0];default:return e.reduce((t,n)=>n.map((n,r)=>t[r]+n/e.length),new Array(e[0].length).fill(0))}},je=e=>e[Math.floor(e.length/2)],Pe=je,Ce=e=>e.reduce((e,t)=>t<e?t:e,1/0),_e=e=>{switch(e.length){case 0:return[];case 1:return e[0];default:return e.reduce((e,t)=>t.map((t,n)=>e[n]<t?e[n]:t),new Array(e[0].length).fill(1/0))}},Ie=e=>{const t=Ee(e);return e.map(e=>e/t)},Re=e=>e.reduce((e,t)=>t?e+t:e,0),Te=e=>{switch(e.length){case 0:return[];case 1:return e[0];default:return e.reduce((e,t)=>t.map((t,n)=>e[n]+t),new Array(e[0].length).fill(0))}},Le="http://www.w3.org/2000/svg",Be=(e,t)=>{if(e.namespaceURI===Le){if(!De(e,t)){const n=e.getAttribute("class")||"";e.setAttribute("class",`${n} ${t}`)}}else e.classList?e.classList.add(t):De(e,t)||(e.className+=" "+t)},Ne=e=>{const t=document.createElement("div");return t.insertAdjacentHTML("beforeend",e),t.firstChild},De=(e,t)=>{if(e.namespaceURI===Le){const n=e.getAttribute("class");return n&&!!n.match(new RegExp(`(\\s|^)${t}(\\s|$)`))}return e.classList?e.classList.contains(t):!!e.className.match(new RegExp(`(\\s|^)${t}(\\s|$)`))},ze=e=>{for(;e.firstChild;)e.removeChild(e.firstChild)},Fe=e=>{e.removeChild(e.lastChild)},Ve=(e,t)=>{const n=new RegExp(`(\\s|^)${t}(\\s|$)`);if(e.namespaceURI===Le){const t=e.getAttribute("class")||"";e.setAttribute("class",t.replace(n," "))}else e.classList?e.classList.remove(t):De(e,t)&&(e.className=e.className.replace(n," "))},Ue=(e,...t)=>(t.forEach(t=>{const n=Object.keys(t).reduce((e,n)=>(e[n]=Object.getOwnPropertyDescriptor(t,n),e),{});Object.getOwnPropertySymbols(t).forEach(e=>{const r=Object.getOwnPropertyDescriptor(t,e);r.enumerable&&(n[e]=r)}),Object.defineProperties(e,n)}),e),Ye=e=>Xe(void 0,e),Xe=(e,t)=>{if(null===t||"object"!=typeof t)return t;if(t.constructor!==Object&&t.constructor!==Array)return t;if(t.constructor===Date||t.constructor===RegExp||t.constructor===Function||t.constructor===String||t.constructor===Number||t.constructor===Boolean)return new t.constructor(t);const n=e||new t.constructor;return Object.keys(t).forEach(e=>{const r=Object.getOwnPropertyDescriptor(t,e);void 0===n[e]&&(void 0===r.value?Object.defineProperty(n,e,r):n[e]=Xe(void 0,t[e]))}),n},qe=(e,t)=>{if(null===t||"object"!=typeof t)return t;if(t.constructor!==Object&&t.constructor!==Array)return new t.constructor(t);const n=new e.constructor;let r=!1;return Object.keys(t).forEach(i=>{const o=Object.getOwnPropertyDescriptor(t,i);void 0===e[i]?void 0===o.value?Object.defineProperty(n,i,o):n[i]=Xe(void 0,t[i]):n[i]=qe(e[i],t[i]),r=r||n[i]!==e[i]}),r=r||Object.keys(e).filter(e=>void 0===t[e]).length,r?n:e},He=e=>e.split(/(?=[A-Z])/).join("_").toUpperCase(),Ge=e=>`${e[0].toUpperCase()}${e.substr(1)}`,We=e=>t=>Array.prototype.forEach.call(t,e),$e=(...e)=>t=>e.reduce((e,t)=>t(e),t),Ke=e=>t=>Ue({__proto__:{constructor:e}},t),Ze=(e,t)=>n=>Ue(n,{[e](...e){return t.apply(this,e)}}),Qe=(e,{initialValue:t,getter:n,setter:r,cloner:i=ve,transformer:o=ve,validator:a=(()=>!0)}={})=>s=>{let u=t;const c=n?()=>n():()=>i(u),l=r?e=>r(e):e=>{const t=o(e);u=a(t)?t:u};return Ue(s,{get[e](){return c()},["set"+Ge(e)](e){l(e)}})},Je=(e,t)=>n=>Ue(n,{get[e](){return t()}}),et=(e,t)=>n=>Ue(n,{get[e](){return t}}),tt=(e,t,n,r)=>Math.abs(e-n)+Math.abs(t-r),nt=(e,t,n,r)=>Math.sqrt((e-n)**2+(t-r)**2),rt=([e,t]=[],n=[])=>{let r,i,o,a,s=!1;for(let u=0,c=n.length-2;u<n.length;u+=2)r=n[u],i=n[u+1],o=n[c],a=n[c+1],i>t!=a>t&&e<(o-r)*(t-i)/(a-i)+r&&(s=!s),c=u;return s},it=(e,t)=>new Map(function*(){yield*e,yield*t}()),ot=e=>new Worker(window.URL.createObjectURL(new Blob([`(${e.toString()})()`],{type:"text/javascript"}))),at=()=>{},st=(e,t)=>e-t,ut=(e,t)=>t-e,ct=(e,{getter:t=ve,comparator:n=st,ignoreNull:r=!1}={})=>Object.entries(e).map(r?([e,n])=>null===t(n)?void 0:[e,t(n)]:([e,n])=>[e,t(n)]).sort((e,t)=>n(e[1],t[1])).reduce((e,t,n)=>t?(e[t[0]]=n,e):e,new e.constructor),lt=(e,t)=>{let n;const r=(...r)=>{clearTimeout(n),n=setTimeout(()=>{n=null,e(...r)},t)};return r.cancel=()=>{clearTimeout(n)},r.now=(...t)=>e(...t),r},ft=(e=1)=>new Promise(t=>{let n=0;const r=()=>requestAnimationFrame(()=>{n++,n<e?r():t()});r()}),ht=(e,t,n=null)=>{let r,i=0;n=null===n?t:n;const o=(...t)=>{clearTimeout(r),r=setTimeout(()=>{i>0&&(e(...t),i=0)},n)};let a=!1;const s=(...n)=>{a?(i++,o(...n)):(e(...n),o(...n),a=!0,i=0,setTimeout(()=>{a=!1},t))};return s.reset=()=>{a=!1},s.cancel=()=>{clearTimeout(r)},s.now=(...t)=>e(...t),s},pt=e=>new Promise(t=>setTimeout(t,e));var dt=new Array(256);!function(e){for(var t=0;t<256;++t){var n=t,r=t,i=7;for(n>>>=1;n;n>>>=1)r<<=1,r|=1&n,--i;e[t]=r<<i&255}}(dt);var gt=function(e){return!(e&e-1||!e)},mt=function(e){var t,n;return t=(e>65535)<<4,t|=n=((e>>>=t)>255)<<3,t|=n=((e>>>=n)>15)<<2,(t|=n=((e>>>=n)>3)<<1)|(e>>>=n)>>1},vt=function(e){return e+=0===e,--e,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,(e|=e>>>16)+1};var yt=function(e){for(var t=new Array(e),n=0;n<e;++n)t[n]=n;return t},bt=function(e){return null!=e&&(wt(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&wt(e.slice(0,0))}(e)||!!e._isBuffer)};
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/function wt(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}var xt="undefined"!=typeof Float64Array;function St(e,t){return e[0]-t[0]}function Et(){var e,t=this.stride,n=new Array(t.length);for(e=0;e<n.length;++e)n[e]=[Math.abs(t[e]),e];n.sort(St);var r=new Array(n.length);for(e=0;e<r.length;++e)r[e]=n[e][1];return r}function kt(e,t){var n=["View",t,"d",e].join("");t<0&&(n="View_Nil"+e);var r="generic"===e;if(-1===t){var i="function "+n+"(a){this.data=a;};var proto="+n+".prototype;proto.dtype='"+e+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+n+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+n+"(a){return new "+n+"(a);}";return new Function(i)()}if(0===t){i="function "+n+"(a,d) {this.data = a;this.offset = d};var proto="+n+".prototype;proto.dtype='"+e+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+n+"_copy() {return new "+n+"(this.data,this.offset)};proto.pick=function "+n+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+n+"_get(){return "+(r?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+n+"_set(v){return "+(r?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+n+"(a,b,c,d){return new "+n+"(a,d)}";return new Function("TrivialArray",i)(Mt[e][0])}i=["'use strict'"];var o=yt(t),a=o.map((function(e){return"i"+e})),s="this.offset+"+o.map((function(e){return"this.stride["+e+"]*i"+e})).join("+"),u=o.map((function(e){return"b"+e})).join(","),c=o.map((function(e){return"c"+e})).join(",");i.push("function "+n+"(a,"+u+","+c+",d){this.data=a","this.shape=["+u+"]","this.stride=["+c+"]","this.offset=d|0}","var proto="+n+".prototype","proto.dtype='"+e+"'","proto.dimension="+t),i.push("Object.defineProperty(proto,'size',{get:function "+n+"_size(){return "+o.map((function(e){return"this.shape["+e+"]"})).join("*"),"}})"),1===t?i.push("proto.order=[0]"):(i.push("Object.defineProperty(proto,'order',{get:"),t<4?(i.push("function "+n+"_order(){"),2===t?i.push("return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}})"):3===t&&i.push("var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):i.push("ORDER})")),i.push("proto.set=function "+n+"_set("+a.join(",")+",v){"),r?i.push("return this.data.set("+s+",v)}"):i.push("return this.data["+s+"]=v}"),i.push("proto.get=function "+n+"_get("+a.join(",")+"){"),r?i.push("return this.data.get("+s+")}"):i.push("return this.data["+s+"]}"),i.push("proto.index=function "+n+"_index(",a.join(),"){return "+s+"}"),i.push("proto.hi=function "+n+"_hi("+a.join(",")+"){return new "+n+"(this.data,"+o.map((function(e){return["(typeof i",e,"!=='number'||i",e,"<0)?this.shape[",e,"]:i",e,"|0"].join("")})).join(",")+","+o.map((function(e){return"this.stride["+e+"]"})).join(",")+",this.offset)}");var l=o.map((function(e){return"a"+e+"=this.shape["+e+"]"})),f=o.map((function(e){return"c"+e+"=this.stride["+e+"]"}));i.push("proto.lo=function "+n+"_lo("+a.join(",")+"){var b=this.offset,d=0,"+l.join(",")+","+f.join(","));for(var h=0;h<t;++h)i.push("if(typeof i"+h+"==='number'&&i"+h+">=0){d=i"+h+"|0;b+=c"+h+"*d;a"+h+"-=d}");i.push("return new "+n+"(this.data,"+o.map((function(e){return"a"+e})).join(",")+","+o.map((function(e){return"c"+e})).join(",")+",b)}"),i.push("proto.step=function "+n+"_step("+a.join(",")+"){var "+o.map((function(e){return"a"+e+"=this.shape["+e+"]"})).join(",")+","+o.map((function(e){return"b"+e+"=this.stride["+e+"]"})).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(h=0;h<t;++h)i.push("if(typeof i"+h+"==='number'){d=i"+h+"|0;if(d<0){c+=b"+h+"*(a"+h+"-1);a"+h+"=ceil(-a"+h+"/d)}else{a"+h+"=ceil(a"+h+"/d)}b"+h+"*=d}");i.push("return new "+n+"(this.data,"+o.map((function(e){return"a"+e})).join(",")+","+o.map((function(e){return"b"+e})).join(",")+",c)}");var p=new Array(t),d=new Array(t);for(h=0;h<t;++h)p[h]="a[i"+h+"]",d[h]="b[i"+h+"]";i.push("proto.transpose=function "+n+"_transpose("+a+"){"+a.map((function(e,t){return e+"=("+e+"===undefined?"+t+":"+e+"|0)"})).join(";"),"var a=this.shape,b=this.stride;return new "+n+"(this.data,"+p.join(",")+","+d.join(",")+",this.offset)}"),i.push("proto.pick=function "+n+"_pick("+a+"){var a=[],b=[],c=this.offset");for(h=0;h<t;++h)i.push("if(typeof i"+h+"==='number'&&i"+h+">=0){c=(c+this.stride["+h+"]*i"+h+")|0}else{a.push(this.shape["+h+"]);b.push(this.stride["+h+"])}");return i.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),i.push("return function construct_"+n+"(data,shape,stride,offset){return new "+n+"(data,"+o.map((function(e){return"shape["+e+"]"})).join(",")+","+o.map((function(e){return"stride["+e+"]"})).join(",")+",offset)}"),new Function("CTOR_LIST","ORDER",i.join("\n"))(Mt[e],Et)}var Mt={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],bigint64:[],biguint64:[],buffer:[],generic:[]};var Ot=function(e,t,n,r){if(void 0===e)return(0,Mt.array[0])([]);"number"==typeof e&&(e=[e]),void 0===t&&(t=[e.length]);var i=t.length;if(void 0===n){n=new Array(i);for(var o=i-1,a=1;o>=0;--o)n[o]=a,a*=t[o]}if(void 0===r){r=0;for(o=0;o<i;++o)n[o]<0&&(r-=(t[o]-1)*n[o])}for(var s=function(e){if(bt(e))return"buffer";if(xt)switch(Object.prototype.toString.call(e)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped";case"[object BigInt64Array]":return"bigint64";case"[object BigUint64Array]":return"biguint64"}return Array.isArray(e)?"array":"generic"}(e),u=Mt[s];u.length<=i+1;)u.push(kt(s,u.length-1));return(0,u[i+1])(e,t,n,r)};var At=function(e,t,n){return 0===e.length?e:t?(n||e.sort(t),function(e,t){for(var n=1,r=e.length,i=e[0],o=e[0],a=1;a<r;++a)if(o=i,t(i=e[a],o)){if(a===n){n++;continue}e[n++]=i}return e.length=n,e}(e,t)):(n||e.sort(),function(e){for(var t=1,n=e.length,r=e[0],i=e[0],o=1;o<n;++o,i=r)if(i=r,(r=e[o])!==i){if(o===t){t++;continue}e[t++]=r}return e.length=t,e}(e))};function jt(e,t,n){var r,i,o=e.length,a=t.arrayArgs.length,s=t.indexArgs.length>0,u=[],c=[],l=0,f=0;for(r=0;r<o;++r)c.push(["i",r,"=0"].join(""));for(i=0;i<a;++i)for(r=0;r<o;++r)f=l,l=e[r],0===r?c.push(["d",i,"s",r,"=t",i,"p",l].join("")):c.push(["d",i,"s",r,"=(t",i,"p",l,"-s",f,"*t",i,"p",f,")"].join(""));for(c.length>0&&u.push("var "+c.join(",")),r=o-1;r>=0;--r)l=e[r],u.push(["for(i",r,"=0;i",r,"<s",l,";++i",r,"){"].join(""));for(u.push(n),r=0;r<o;++r){for(f=l,l=e[r],i=0;i<a;++i)u.push(["p",i,"+=d",i,"s",r].join(""));s&&(r>0&&u.push(["index[",f,"]-=s",f].join("")),u.push(["++index[",l,"]"].join(""))),u.push("}")}return u.join("\n")}function Pt(e,t,n){for(var r=e.body,i=[],o=[],a=0;a<e.args.length;++a){var s=e.args[a];if(!(s.count<=0)){var u=new RegExp(s.name,"g"),c="",l=t.arrayArgs.indexOf(a);switch(t.argTypes[a]){case"offset":var f=t.offsetArgIndex.indexOf(a);l=t.offsetArgs[f].array,c="+q"+f;case"array":c="p"+l+c;var h="l"+a,p="a"+l;if(0===t.arrayBlockIndices[l])1===s.count?"generic"===n[l]?s.lvalue?(i.push(["var ",h,"=",p,".get(",c,")"].join("")),r=r.replace(u,h),o.push([p,".set(",c,",",h,")"].join(""))):r=r.replace(u,[p,".get(",c,")"].join("")):r=r.replace(u,[p,"[",c,"]"].join("")):"generic"===n[l]?(i.push(["var ",h,"=",p,".get(",c,")"].join("")),r=r.replace(u,h),s.lvalue&&o.push([p,".set(",c,",",h,")"].join(""))):(i.push(["var ",h,"=",p,"[",c,"]"].join("")),r=r.replace(u,h),s.lvalue&&o.push([p,"[",c,"]=",h].join("")));else{for(var d=[s.name],g=[c],m=0;m<Math.abs(t.arrayBlockIndices[l]);m++)d.push("\\s*\\[([^\\]]+)\\]"),g.push("$"+(m+1)+"*t"+l+"b"+m);if(u=new RegExp(d.join(""),"g"),c=g.join("+"),"generic"===n[l])throw new Error("cwise: Generic arrays not supported in combination with blocks!");r=r.replace(u,[p,"[",c,"]"].join(""))}break;case"scalar":r=r.replace(u,"Y"+t.scalarArgs.indexOf(a));break;case"index":r=r.replace(u,"index");break;case"shape":r=r.replace(u,"shape")}}}return[i.join("\n"),r,o.join("\n")].join("\n").trim()}function Ct(e){for(var t=new Array(e.length),n=!0,r=0;r<e.length;++r){var i=e[r],o=i.match(/\d+/);o=o?o[0]:"",0===i.charAt(0)?t[r]="u"+i.charAt(1)+o:t[r]=i.charAt(0)+o,r>0&&(n=n&&t[r]===t[r-1])}return n?t[0]:t.join("")}var _t=function(e,t){for(var n=t[1].length-Math.abs(e.arrayBlockIndices[0])|0,r=new Array(e.arrayArgs.length),i=new Array(e.arrayArgs.length),o=0;o<e.arrayArgs.length;++o)i[o]=t[2*o],r[o]=t[2*o+1];var a=[],s=[],u=[],c=[],l=[];for(o=0;o<e.arrayArgs.length;++o){e.arrayBlockIndices[o]<0?(u.push(0),c.push(n),a.push(n),s.push(n+e.arrayBlockIndices[o])):(u.push(e.arrayBlockIndices[o]),c.push(e.arrayBlockIndices[o]+n),a.push(0),s.push(e.arrayBlockIndices[o]));for(var f=[],h=0;h<r[o].length;h++)u[o]<=r[o][h]&&r[o][h]<c[o]&&f.push(r[o][h]-u[o]);l.push(f)}var p=["SS"],d=["'use strict'"],g=[];for(h=0;h<n;++h)g.push(["s",h,"=SS[",h,"]"].join(""));for(o=0;o<e.arrayArgs.length;++o){p.push("a"+o),p.push("t"+o),p.push("p"+o);for(h=0;h<n;++h)g.push(["t",o,"p",h,"=t",o,"[",u[o]+h,"]"].join(""));for(h=0;h<Math.abs(e.arrayBlockIndices[o]);++h)g.push(["t",o,"b",h,"=t",o,"[",a[o]+h,"]"].join(""))}for(o=0;o<e.scalarArgs.length;++o)p.push("Y"+o);if(e.shapeArgs.length>0&&g.push("shape=SS.slice(0)"),e.indexArgs.length>0){var m=new Array(n);for(o=0;o<n;++o)m[o]="0";g.push(["index=[",m.join(","),"]"].join(""))}for(o=0;o<e.offsetArgs.length;++o){var v=e.offsetArgs[o],y=[];for(h=0;h<v.offset.length;++h)0!==v.offset[h]&&(1===v.offset[h]?y.push(["t",v.array,"p",h].join("")):y.push([v.offset[h],"*t",v.array,"p",h].join("")));0===y.length?g.push("q"+o+"=0"):g.push(["q",o,"=",y.join("+")].join(""))}var b=At([].concat(e.pre.thisVars).concat(e.body.thisVars).concat(e.post.thisVars));for((g=g.concat(b)).length>0&&d.push("var "+g.join(",")),o=0;o<e.arrayArgs.length;++o)d.push("p"+o+"|=0");e.pre.body.length>3&&d.push(Pt(e.pre,e,i));var w=Pt(e.body,e,i),x=function(e){for(var t=0,n=e[0].length;t<n;){for(var r=1;r<e.length;++r)if(e[r][t]!==e[0][t])return t;++t}return t}(l);x<n?d.push(function(e,t,n,r){for(var i=t.length,o=n.arrayArgs.length,a=n.blockSize,s=n.indexArgs.length>0,u=[],c=0;c<o;++c)u.push(["var offset",c,"=p",c].join(""));for(c=e;c<i;++c)u.push(["for(var j"+c+"=SS[",t[c],"]|0;j",c,">0;){"].join("")),u.push(["if(j",c,"<",a,"){"].join("")),u.push(["s",t[c],"=j",c].join("")),u.push(["j",c,"=0"].join("")),u.push(["}else{s",t[c],"=",a].join("")),u.push(["j",c,"-=",a,"}"].join("")),s&&u.push(["index[",t[c],"]=j",c].join(""));for(c=0;c<o;++c){for(var l=["offset"+c],f=e;f<i;++f)l.push(["j",f,"*t",c,"p",t[f]].join(""));u.push(["p",c,"=(",l.join("+"),")"].join(""))}for(u.push(jt(t,n,r)),c=e;c<i;++c)u.push("}");return u.join("\n")}(x,l[0],e,w)):d.push(jt(l[0],e,w)),e.post.body.length>3&&d.push(Pt(e.post,e,i)),e.debug&&console.log("-----Generated cwise routine for ",t,":\n"+d.join("\n")+"\n----------");var S=[e.funcName||"unnamed","_cwise_loop_",r[0].join("s"),"m",x,Ct(i)].join("");return new Function(["function ",S,"(",p.join(","),"){",d.join("\n"),"} return ",S].join(""))()};var It=function(e){var t=["'use strict'","var CACHED={}"],n=[],r=e.funcName+"_cwise_thunk";t.push(["return function ",r,"(",e.shimArgs.join(","),"){"].join(""));for(var i=[],o=[],a=[["array",e.arrayArgs[0],".shape.slice(",Math.max(0,e.arrayBlockIndices[0]),e.arrayBlockIndices[0]<0?","+e.arrayBlockIndices[0]+")":")"].join("")],s=[],u=[],c=0;c<e.arrayArgs.length;++c){var l=e.arrayArgs[c];n.push(["t",l,"=array",l,".dtype,","r",l,"=array",l,".order"].join("")),i.push("t"+l),i.push("r"+l),o.push("t"+l),o.push("r"+l+".join()"),a.push("array"+l+".data"),a.push("array"+l+".stride"),a.push("array"+l+".offset|0"),c>0&&(s.push("array"+e.arrayArgs[0]+".shape.length===array"+l+".shape.length+"+(Math.abs(e.arrayBlockIndices[0])-Math.abs(e.arrayBlockIndices[c]))),u.push("array"+e.arrayArgs[0]+".shape[shapeIndex+"+Math.max(0,e.arrayBlockIndices[0])+"]===array"+l+".shape[shapeIndex+"+Math.max(0,e.arrayBlockIndices[c])+"]"))}for(e.arrayArgs.length>1&&(t.push("if (!("+s.join(" && ")+")) throw new Error('cwise: Arrays do not all have the same dimensionality!')"),t.push("for(var shapeIndex=array"+e.arrayArgs[0]+".shape.length-"+Math.abs(e.arrayBlockIndices[0])+"; shapeIndex--\x3e0;) {"),t.push("if (!("+u.join(" && ")+")) throw new Error('cwise: Arrays do not all have the same shape!')"),t.push("}")),c=0;c<e.scalarArgs.length;++c)a.push("scalar"+e.scalarArgs[c]);return n.push(["type=[",o.join(","),"].join()"].join("")),n.push("proc=CACHED[type]"),t.push("var "+n.join(",")),t.push(["if(!proc){","CACHED[type]=proc=compile([",i.join(","),"])}","return proc(",a.join(","),")}"].join("")),e.debug&&console.log("-----Generated thunk:\n"+t.join("\n")+"\n----------"),new Function("compile",t.join("\n"))(_t.bind(void 0,e))};function Rt(){this.argTypes=[],this.shimArgs=[],this.arrayArgs=[],this.arrayBlockIndices=[],this.scalarArgs=[],this.offsetArgs=[],this.offsetArgIndex=[],this.indexArgs=[],this.shapeArgs=[],this.funcName="",this.pre=null,this.body=null,this.post=null,this.debug=!1}var Tt=function(e){var t=new Rt;t.pre=e.pre,t.body=e.body,t.post=e.post;var n=e.args.slice(0);t.argTypes=n;for(var r=0;r<n.length;++r){var i=n[r];if("array"===i||"object"==typeof i&&i.blockIndices){if(t.argTypes[r]="array",t.arrayArgs.push(r),t.arrayBlockIndices.push(i.blockIndices?i.blockIndices:0),t.shimArgs.push("array"+r),r<t.pre.args.length&&t.pre.args[r].count>0)throw new Error("cwise: pre() block may not reference array args");if(r<t.post.args.length&&t.post.args[r].count>0)throw new Error("cwise: post() block may not reference array args")}else if("scalar"===i)t.scalarArgs.push(r),t.shimArgs.push("scalar"+r);else if("index"===i){if(t.indexArgs.push(r),r<t.pre.args.length&&t.pre.args[r].count>0)throw new Error("cwise: pre() block may not reference array index");if(r<t.body.args.length&&t.body.args[r].lvalue)throw new Error("cwise: body() block may not write to array index");if(r<t.post.args.length&&t.post.args[r].count>0)throw new Error("cwise: post() block may not reference array index")}else if("shape"===i){if(t.shapeArgs.push(r),r<t.pre.args.length&&t.pre.args[r].lvalue)throw new Error("cwise: pre() block may not write to array shape");if(r<t.body.args.length&&t.body.args[r].lvalue)throw new Error("cwise: body() block may not write to array shape");if(r<t.post.args.length&&t.post.args[r].lvalue)throw new Error("cwise: post() block may not write to array shape")}else{if("object"!=typeof i||!i.offset)throw new Error("cwise: Unknown argument type "+n[r]);t.argTypes[r]="offset",t.offsetArgs.push({array:i.array,offset:i.offset}),t.offsetArgIndex.push(r)}}if(t.arrayArgs.length<=0)throw new Error("cwise: No array arguments specified");if(t.pre.args.length>n.length)throw new Error("cwise: Too many arguments in pre() block");if(t.body.args.length>n.length)throw new Error("cwise: Too many arguments in body() block");if(t.post.args.length>n.length)throw new Error("cwise: Too many arguments in post() block");return t.debug=!!e.printCode||!!e.debug,t.funcName=e.funcName||"cwise",t.blockSize=e.blockSize||64,It(t)},Lt=a((function(e,t){var n={body:"",args:[],thisVars:[],localVars:[]};function r(e){if(!e)return n;for(var t=0;t<e.args.length;++t){var r=e.args[t];e.args[t]=0===t?{name:r,lvalue:!0,rvalue:!!e.rvalue,count:e.count||1}:{name:r,lvalue:!1,rvalue:!0,count:1}}return e.thisVars||(e.thisVars=[]),e.localVars||(e.localVars=[]),e}function i(e){for(var t=[],n=0;n<e.args.length;++n)t.push("a"+n);return new Function("P",["return function ",e.funcName,"_ndarrayops(",t.join(","),") {P(",t.join(","),");return a0}"].join(""))(function(e){return Tt({args:e.args,pre:r(e.pre),body:r(e.body),post:r(e.proc),funcName:e.funcName})}(e))}var o={add:"+",sub:"-",mul:"*",div:"/",mod:"%",band:"&",bor:"|",bxor:"^",lshift:"<<",rshift:">>",rrshift:">>>"};!function(){for(var e in o){var n=o[e];t[e]=i({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+n+"c"},funcName:e}),t[e+"eq"]=i({args:["array","array"],body:{args:["a","b"],body:"a"+n+"=b"},rvalue:!0,funcName:e+"eq"}),t[e+"s"]=i({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+n+"s"},funcName:e+"s"}),t[e+"seq"]=i({args:["array","scalar"],body:{args:["a","s"],body:"a"+n+"=s"},rvalue:!0,funcName:e+"seq"})}}();var a={not:"!",bnot:"~",neg:"-",recip:"1.0/"};!function(){for(var e in a){var n=a[e];t[e]=i({args:["array","array"],body:{args:["a","b"],body:"a="+n+"b"},funcName:e}),t[e+"eq"]=i({args:["array"],body:{args:["a"],body:"a="+n+"a"},rvalue:!0,count:2,funcName:e+"eq"})}}();var s={and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">="};!function(){for(var e in s){var n=s[e];t[e]=i({args:["array","array","array"],body:{args:["a","b","c"],body:"a=b"+n+"c"},funcName:e}),t[e+"s"]=i({args:["array","array","scalar"],body:{args:["a","b","s"],body:"a=b"+n+"s"},funcName:e+"s"}),t[e+"eq"]=i({args:["array","array"],body:{args:["a","b"],body:"a=a"+n+"b"},rvalue:!0,count:2,funcName:e+"eq"}),t[e+"seq"]=i({args:["array","scalar"],body:{args:["a","s"],body:"a=a"+n+"s"},rvalue:!0,count:2,funcName:e+"seq"})}}();var u=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan"];!function(){for(var e=0;e<u.length;++e){var n=u[e];t[n]=i({args:["array","array"],pre:{args:[],body:"this_f=Math."+n,thisVars:["this_f"]},body:{args:["a","b"],body:"a=this_f(b)",thisVars:["this_f"]},funcName:n}),t[n+"eq"]=i({args:["array"],pre:{args:[],body:"this_f=Math."+n,thisVars:["this_f"]},body:{args:["a"],body:"a=this_f(a)",thisVars:[