diff --git a/dist/speedscope.js b/dist/speedscope.js new file mode 100644 index 0000000..4d9d334 --- /dev/null +++ b/dist/speedscope.js @@ -0,0 +1 @@ +!function(){"use strict";function e(){}function t(t,n){var r,i,a,o,s=ce;for(o=arguments.length;o-- >2;)ue.push(arguments[o]);for(n&&null!=n.children&&(ue.length||ue.push(n.children),delete n.children);ue.length;)if((i=ue.pop())&&void 0!==i.pop)for(o=i.length;o--;)ue.push(i[o]);else"boolean"==typeof i&&(i=null),(a="function"!=typeof t)&&(null==i?i="":"number"==typeof i?i=String(i):"string"!=typeof i&&(a=!1)),a&&r?s[s.length-1]+=i:s===ce?s=[i]:s.push(i),r=a;var f=new e;return f.nodeName=t,f.children=s,f.attributes=null==n?void 0:n,f.key=null==n?void 0:n.key,void 0!==fe.vnode&&fe.vnode(f),f}function n(e,t){for(var n in t)e[n]=t[n];return e}function r(e){!e._dirty&&(e._dirty=!0)&&1==me.push(e)&&(fe.debounceRendering||le)(i)}function i(){var e,t=me;for(me=[];e=t.pop();)e._dirty&&S(e)}function a(e,t,n){return"string"==typeof t||"number"==typeof t?void 0!==e.splitText:"string"==typeof t.nodeName?!e._componentConstructor&&o(e,t.nodeName):n||e._componentConstructor===t.nodeName}function o(e,t){return e.normalizedNodeName===t||e.nodeName.toLowerCase()===t.toLowerCase()}function s(e){var t=n({},e.attributes);t.children=e.children;var r=e.nodeName.defaultProps;if(void 0!==r)for(var i in r)void 0===t[i]&&(t[i]=r[i]);return t}function f(e,t){var n=t?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e);return n.normalizedNodeName=e,n}function u(e){var t=e.parentNode;t&&t.removeChild(e)}function c(e,t,n,r,i){if("className"===t&&(t="class"),"key"===t);else if("ref"===t)n&&n(null),r&&r(e);else if("class"!==t||i)if("style"===t){if(r&&"string"!=typeof r&&"string"!=typeof n||(e.style.cssText=r||""),r&&"object"==typeof r){if("string"!=typeof n)for(var a in n)a in r||(e.style[a]="");for(var a in r)e.style[a]="number"==typeof r[a]&&!1===de.test(a)?r[a]+"px":r[a]}}else if("dangerouslySetInnerHTML"===t)r&&(e.innerHTML=r.__html||"");else if("o"==t[0]&&"n"==t[1]){var o=t!==(t=t.replace(/Capture$/,""));t=t.toLowerCase().substring(2),r?n||e.addEventListener(t,d,o):e.removeEventListener(t,d,o),(e._listeners||(e._listeners={}))[t]=r}else if("list"!==t&&"type"!==t&&!i&&t in e)l(e,t,null==r?"":r),null!=r&&!1!==r||e.removeAttribute(t);else{var s=i&&t!==(t=t.replace(/^xlink\:?/,""));null==r||!1===r?s?e.removeAttributeNS("http://www.w3.org/1999/xlink",t.toLowerCase()):e.removeAttribute(t):"function"!=typeof r&&(s?e.setAttributeNS("http://www.w3.org/1999/xlink",t.toLowerCase(),r):e.setAttribute(t,r))}else e.className=r||""}function l(e,t,n){try{e[t]=n}catch(e){}}function d(e){return this._listeners[e.type](fe.event&&fe.event(e)||e)}function m(){for(var e;e=pe.pop();)fe.afterMount&&fe.afterMount(e),e.componentDidMount&&e.componentDidMount()}function p(e,t,n,r,i,a){he++||(be=null!=i&&void 0!==i.ownerSVGElement,ge=null!=e&&!("__preactattr_"in e));var o=h(e,t,n,r,a);return i&&o.parentNode!==i&&i.appendChild(o),--he||(ge=!1,a||m()),o}function h(e,t,n,r,i){var a=e,s=be;if(null!=t&&"boolean"!=typeof t||(t=""),"string"==typeof t||"number"==typeof t)return e&&void 0!==e.splitText&&e.parentNode&&(!e._component||i)?e.nodeValue!=t&&(e.nodeValue=t):(a=document.createTextNode(t),e&&(e.parentNode&&e.parentNode.replaceChild(a,e),g(e,!0))),a.__preactattr_=!0,a;var u=t.nodeName;if("function"==typeof u)return T(e,t,n,r);if(be="svg"===u||"foreignObject"!==u&&be,u=String(u),(!e||!o(e,u))&&(a=f(u,be),e)){for(;e.firstChild;)a.appendChild(e.firstChild);e.parentNode&&e.parentNode.replaceChild(a,e),g(e,!0)}var c=a.firstChild,l=a.__preactattr_,d=t.children;if(null==l){l=a.__preactattr_={};for(var m=a.attributes,p=m.length;p--;)l[m[p].name]=m[p].value}return!ge&&d&&1===d.length&&"string"==typeof d[0]&&null!=c&&void 0!==c.splitText&&null==c.nextSibling?c.nodeValue!=d[0]&&(c.nodeValue=d[0]):(d&&d.length||null!=c)&&b(a,d,n,r,ge||null!=l.dangerouslySetInnerHTML),y(a,t.attributes,l),be=s,a}function b(e,t,n,r,i){var o,s,f,c,l,d=e.childNodes,m=[],p={},b=0,v=0,y=d.length,x=0,w=t?t.length:0;if(0!==y)for(T=0;T>>0}function M(){throw new Error("setTimeout has not been defined")}function W(){throw new Error("clearTimeout has not been defined")}function P(e){if(Ye===setTimeout)return setTimeout(e,0);if((Ye===M||!Ye)&&setTimeout)return Ye=setTimeout,setTimeout(e,0);try{return Ye(e,0)}catch(t){try{return Ye.call(null,e,0)}catch(t){return Ye.call(this,e,0)}}}function z(e){if($e===clearTimeout)return clearTimeout(e);if(($e===W||!$e)&&clearTimeout)return $e=clearTimeout,clearTimeout(e);try{return $e(e)}catch(t){try{return $e.call(null,e)}catch(t){return $e.call(this,e)}}}function B(){Je&&Ke&&(Je=!1,Ke.length?Ze=Ke.concat(Ze):et=-1,Ze.length&&R())}function R(){if(!Je){var e=P(B);Je=!0;for(var t=Ze.length;t;){for(Ke=Ze,Ze=[];++et1)for(var n=1;n_t){for(var t=0,n=xt.length-kt;t{t.push({stack:n.split(";").map(e=>({key:e,name:e})),duration:parseInt(r,10)});return e}),t}function te(e){const t=ee(e),n=t.reduce((e,t)=>e+t.duration,0),r=new Lt(n);for(let e of t)r.appendSample(e.stack,e.duration);return r}function ne(e,t,n){return en?n:e}function re(e){function t(...t){null==n&&(n=requestAnimationFrame(function(){e(...t),n=null}))}let n=null;return t}function ie(e,t,n,r,i=1){for(;;){if(t-e<=i)return[e,t];const a=(t+e)/2,o=n(a);or&&(t=a)}}function ae(e,t){const n=Math.floor(t/2),r=e.substr(0,n),i=e.substr(e.length-n,n);return r+Qt+i}function oe(e,t){return Xt.has(t)||Xt.set(t,e.measureText(t).width),Xt.get(t)}function se(e,t,n){if(oe(e,t)<=n)return t;const[r,i]=ie(0,t.length,n=>oe(e,ae(t,n)),n);return ae(t,r)}var fe={},ue=[],ce=[],le="function"==typeof Promise?Promise.resolve().then.bind(Promise.resolve()):setTimeout,de=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,me=[],pe=[],he=0,be=!1,ge=!1,ve={};n(O.prototype,{setState:function(e,t){var i=this.state;this.prevState||(this.prevState=n({},i)),n(i,"function"==typeof e?e(i,this.props):e),t&&(this._renderCallbacks=this._renderCallbacks||[]).push(t),r(this)},forceUpdate:function(e){e&&(this._renderCallbacks=this._renderCallbacks||[]).push(e),S(this,2)},render:function(){}});"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var ye=E(function(e,t){function n(e){return e.charAt(0).toUpperCase()+e.slice(1)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n,e.exports=t.default});C(ye);var xe=E(function(e,t){function n(e,t,n){if(e.hasOwnProperty(t))for(var i=e[t],a=0,o=i.length;a0&&(e[f]=c)}else{var p=(0,a.default)(r,f,u,e,n);p&&(e[f]=p),(0,i.default)(n,f,e)}}return e}var n=e.prefixMap,r=e.plugins;return t}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r;var i=n(xe),a=n(we),o=n(ke),s=n(_e);e.exports=t.default});C(Se);var Te=E(function(e,t){function n(e){return"string"==typeof e&&r.test(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=/-webkit-|-moz-|-ms-/;e.exports=t.default});C(Te);var Ae=E(function(e,t){function n(e,t){if("string"==typeof t&&!(0,r.default)(t)&&t.indexOf("calc(")>-1)return i.map(function(e){return t.replace(/calc\(/g,e+"calc(")})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=function(e){return e&&e.__esModule?e:{default:e}}(Te),i=["-webkit-","-moz-",""];e.exports=t.default});C(Ae);var Oe=E(function(e,t){function n(e,t){if("string"==typeof t&&!(0,r.default)(t)&&t.indexOf("cross-fade(")>-1)return i.map(function(e){return t.replace(/cross-fade\(/g,e+"cross-fade(")})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=function(e){return e&&e.__esModule?e:{default:e}}(Te),i=["-webkit-",""];e.exports=t.default});C(Oe);var Ce=E(function(e,t){function n(e,t){if("cursor"===e&&i.hasOwnProperty(t))return r.map(function(e){return e+t})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=["-webkit-","-moz-",""],i={"zoom-in":!0,"zoom-out":!0,grab:!0,grabbing:!0};e.exports=t.default});C(Ce);var Ee=E(function(e,t){function n(e,t){if("string"==typeof t&&!(0,r.default)(t)&&t.indexOf("filter(")>-1)return i.map(function(e){return t.replace(/filter\(/g,e+"filter(")})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=function(e){return e&&e.__esModule?e:{default:e}}(Te),i=["-webkit-",""];e.exports=t.default});C(Ee);var je=E(function(e,t){function n(e,t){if("display"===e&&r.hasOwnProperty(t))return r[t]}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r={flex:["-webkit-box","-moz-box","-ms-flexbox","-webkit-flex","flex"],"inline-flex":["-webkit-inline-box","-moz-inline-box","-ms-inline-flexbox","-webkit-inline-flex","inline-flex"]};e.exports=t.default});C(je);var De=E(function(e,t){function n(e,t,n){i.hasOwnProperty(e)&&(n[i[e]]=r[t]||t)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r={"space-around":"distribute","space-between":"justify","flex-start":"start","flex-end":"end"},i={alignContent:"msFlexLinePack",alignSelf:"msFlexItemAlign",alignItems:"msFlexAlign",justifyContent:"msFlexPack",order:"msFlexOrder",flexGrow:"msFlexPositive",flexShrink:"msFlexNegative",flexBasis:"msFlexPreferredSize"};e.exports=t.default});C(De);var Me=E(function(e,t){function n(e,t,n){"flexDirection"===e&&"string"==typeof t&&(t.indexOf("column")>-1?n.WebkitBoxOrient="vertical":n.WebkitBoxOrient="horizontal",t.indexOf("reverse")>-1?n.WebkitBoxDirection="reverse":n.WebkitBoxDirection="normal"),i.hasOwnProperty(e)&&(n[i[e]]=r[t]||t)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r={"space-around":"justify","space-between":"justify","flex-start":"start","flex-end":"end","wrap-reverse":"multiple",wrap:"multiple"},i={alignItems:"WebkitBoxAlign",justifyContent:"WebkitBoxPack",flexWrap:"WebkitBoxLines"};e.exports=t.default});C(Me);var We=E(function(e,t){function n(e,t){if("string"==typeof t&&!(0,r.default)(t)&&a.test(t))return i.map(function(e){return e+t})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=function(e){return e&&e.__esModule?e:{default:e}}(Te),i=["-webkit-","-moz-",""],a=/linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient/;e.exports=t.default});C(We);var Pe=E(function(e,t){function n(e,t){if("string"==typeof t&&!(0,r.default)(t)&&t.indexOf("image-set(")>-1)return i.map(function(e){return t.replace(/image-set\(/g,e+"image-set(")})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=function(e){return e&&e.__esModule?e:{default:e}}(Te),i=["-webkit-",""];e.exports=t.default});C(Pe);var ze=E(function(e,t){function n(e,t){if("position"===e&&"sticky"===t)return["-webkit-sticky","sticky"]}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n,e.exports=t.default});C(ze);var Be=E(function(e,t){function n(e,t){if(i.hasOwnProperty(e)&&a.hasOwnProperty(t))return r.map(function(e){return e+t})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=["-webkit-","-moz-",""],i={maxHeight:!0,maxWidth:!0,width:!0,height:!0,columnWidth:!0,minWidth:!0,minHeight:!0},a={"min-content":!0,"max-content":!0,"fill-available":!0,"fit-content":!0,"contain-floats":!0};e.exports=t.default});C(Be);var Re=/[A-Z]/g,Fe=/^ms-/,Le={},Ie=j,Ne=E(function(e,t){function n(e){return(0,r.default)(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=function(e){return e&&e.__esModule?e:{default:e}}(Ie);e.exports=t.default});C(Ne);var He=E(function(e,t){function n(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if((0,o.default)(e))return e;for(var n=e.split(/,(?![^()]*(?:\([^()]*\))?\))/g),r=0,i=n.length;r-1&&"order"!==l)for(var d=t[c],m=0,p=d.length;m-1)return o;var u=a.split(/,(?![^()]*(?:\([^()]*\))?\))/g).filter(function(e){return!/-webkit-|-ms-/.test(e)}).join(",");return e.indexOf("Moz")>-1?u:(n["Webkit"+(0,s.default)(e)]=o,n["Moz"+(0,s.default)(e)]=u,a)}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=i;var a=n(Ne),o=n(Te),s=n(ye),f={transition:!0,transitionProperty:!0,WebkitTransition:!0,WebkitTransitionProperty:!0,MozTransition:!0,MozTransitionProperty:!0},u={Webkit:"-webkit-",Moz:"-moz-",ms:"-ms-"};e.exports=t.default});C(He);var Ve={plugins:[Ae,Oe,Ce,Ee,je,De,Me,We,Pe,ze,Be,He],prefixMap:{transform:["Webkit","ms"],transformOrigin:["Webkit","ms"],transformOriginX:["Webkit","ms"],transformOriginY:["Webkit","ms"],backfaceVisibility:["Webkit"],perspective:["Webkit"],perspectiveOrigin:["Webkit"],transformStyle:["Webkit"],transformOriginZ:["Webkit"],animation:["Webkit"],animationDelay:["Webkit"],animationDirection:["Webkit"],animationFillMode:["Webkit"],animationDuration:["Webkit"],animationIterationCount:["Webkit"],animationName:["Webkit"],animationPlayState:["Webkit"],animationTimingFunction:["Webkit"],appearance:["Webkit","Moz"],userSelect:["Webkit","Moz","ms"],fontKerning:["Webkit"],textEmphasisPosition:["Webkit"],textEmphasis:["Webkit"],textEmphasisStyle:["Webkit"],textEmphasisColor:["Webkit"],boxDecorationBreak:["Webkit"],clipPath:["Webkit"],maskImage:["Webkit"],maskMode:["Webkit"],maskRepeat:["Webkit"],maskPosition:["Webkit"],maskClip:["Webkit"],maskOrigin:["Webkit"],maskSize:["Webkit"],maskComposite:["Webkit"],mask:["Webkit"],maskBorderSource:["Webkit"],maskBorderMode:["Webkit"],maskBorderSlice:["Webkit"],maskBorderWidth:["Webkit"],maskBorderOutset:["Webkit"],maskBorderRepeat:["Webkit"],maskBorder:["Webkit"],maskType:["Webkit"],textDecorationStyle:["Webkit","Moz"],textDecorationSkip:["Webkit","Moz"],textDecorationLine:["Webkit","Moz"],textDecorationColor:["Webkit","Moz"],filter:["Webkit"],fontFeatureSettings:["Webkit","Moz"],breakAfter:["Webkit","Moz","ms"],breakBefore:["Webkit","Moz","ms"],breakInside:["Webkit","Moz","ms"],columnCount:["Webkit","Moz"],columnFill:["Webkit","Moz"],columnGap:["Webkit","Moz"],columnRule:["Webkit","Moz"],columnRuleColor:["Webkit","Moz"],columnRuleStyle:["Webkit","Moz"],columnRuleWidth:["Webkit","Moz"],columns:["Webkit","Moz"],columnSpan:["Webkit","Moz"],columnWidth:["Webkit","Moz"],flex:["Webkit","ms"],flexBasis:["Webkit"],flexDirection:["Webkit","ms"],flexGrow:["Webkit"],flexFlow:["Webkit","ms"],flexShrink:["Webkit"],flexWrap:["Webkit","ms"],alignContent:["Webkit"],alignItems:["Webkit"],alignSelf:["Webkit"],justifyContent:["Webkit"],order:["Webkit"],transitionDelay:["Webkit"],transitionDuration:["Webkit"],transitionProperty:["Webkit"],transitionTimingFunction:["Webkit"],backdropFilter:["Webkit"],scrollSnapType:["Webkit","ms"],scrollSnapPointsX:["Webkit","ms"],scrollSnapPointsY:["Webkit","ms"],scrollSnapDestination:["Webkit","ms"],scrollSnapCoordinate:["Webkit","ms"],shapeImageThreshold:["Webkit"],shapeImageMargin:["Webkit"],shapeImageOutside:["Webkit"],hyphens:["Webkit","Moz","ms"],flowInto:["Webkit","ms"],flowFrom:["Webkit","ms"],regionFragment:["Webkit","ms"],boxSizing:["Moz"],textAlignLast:["Moz"],tabSize:["Moz"],wrapFlow:["ms"],wrapThrough:["ms"],wrapMargin:["ms"],touchAction:["ms"],gridTemplateColumns:["ms"],gridTemplateRows:["ms"],gridTemplateAreas:["ms"],gridTemplate:["ms"],gridAutoColumns:["ms"],gridAutoRows:["ms"],gridAutoFlow:["ms"],grid:["ms"],gridRowStart:["ms"],gridColumnStart:["ms"],gridRowEnd:["ms"],gridRow:["ms"],gridColumn:["ms"],gridColumnEnd:["ms"],gridColumnGap:["ms"],gridRowGap:["ms"],gridArea:["ms"],gridGap:["ms"],textSizeAdjust:["Webkit","ms"],borderImage:["Webkit"],borderImageOutset:["Webkit"],borderImageRepeat:["Webkit"],borderImageSlice:["Webkit"],borderImageSource:["Webkit"],borderImageWidth:["Webkit"]}},Ge=E(function(e,t){function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n0&&o(e)};t.flushToStyleTag=b;var g=function(){return Object.keys(f)};t.getRenderedClassNames=g;var v=function(e){e.forEach(function(e){f[e]=!0})};t.addRenderedClassNames=v;var y=function e(t,n){for(var r=0;r=0&&(0|e)===e||t("invalid parameter type, ("+e+")"+r(n)+". must be a nonnegative integer")}function f(e,n,i){n.indexOf(e)<0&&t("invalid value"+r(i)+". must be one of: "+n)}function u(e){Object.keys(e).forEach(function(e){et.indexOf(e)<0&&t('invalid regl constructor argument "'+e+'". must be one of '+et)})}function c(e,t){for(e+="";e.length0&&t.push(new m("unknown",0,e))}}),t}function v(e,t){t.forEach(function(t){var n=e[t.file];if(n){var r=n.index[t.line];if(r)return r.errors.push(t),void(n.hasErrors=!0)}e.unknown.hasErrors=!0,e.unknown.lines[0].errors.push(t)})}function y(e,t,r,i,a){if(!e.getShaderParameter(t,e.COMPILE_STATUS)){var o=e.getShaderInfoLog(t),s=i===e.FRAGMENT_SHADER?"fragment":"vertex";A(r,"string",s+" shader source must be a string",a);var f=b(r,a),u=g(o);v(f,u),Object.keys(f).forEach(function(e){function t(e,t){r.push(e),i.push(t||"")}var n=f[e];if(n.hasErrors){var r=[""],i=[""];t("file number "+e+": "+n.name+"\n","color:red;text-decoration:underline;font-weight:bold"),n.lines.forEach(function(e){if(e.errors.length>0){t(c(e.number,4)+"| ","background-color:yellow; font-weight:bold"),t(e.line+"\n","color:red; background-color:yellow; font-weight:bold");var n=0;e.errors.forEach(function(r){var i=r.message,a=/^\s*\'(.*)\'\s*\:\s*(.*)$/.exec(i);if(a){var o=a[1];switch(i=a[2],o){case"assign":o="="}n=Math.max(e.line.indexOf(o,n),0)}else n=0;t(c("| ",6)),t(c("^^^",n+3)+"\n","font-weight:bold"),t(c("| ",6)),t(i+"\n","font-weight:bold")}),t(c("| ",6)+"\n")}else t(c(e.number,4)+"| "),t(e.line+"\n","color:red")}),"undefined"!=typeof document?(i[0]=r.join("%c"),console.log.apply(console,i)):console.log(r.join(""))}}),n.raise("Error compiling "+s+" shader, "+f[0].name)}}function x(e,t,r,i,a){if(!e.getProgramParameter(t,e.LINK_STATUS)){var o=e.getProgramInfoLog(t),s=b(r,a),f='Error linking program with vertex shader, "'+b(i,a)[0].name+'", and fragment shader "'+s[0].name+'"';"undefined"!=typeof document?console.log("%c"+f+"\n%c"+o,"color:red;text-decoration:underline;font-weight:bold","color:red"):console.log(f+"\n"+o),n.raise(f)}}function w(e){e._commandRef=p()}function k(e,t,n,r){function i(e){return e?r.id(e):0}function a(e,t){Object.keys(t).forEach(function(t){e[r.id(t)]=!0})}w(e),e._fragId=i(e.static.frag),e._vertId=i(e.static.vert);var o=e._uniformSet={};a(o,t.static),a(o,t.dynamic);var s=e._attributeSet={};a(s,n.static),a(s,n.dynamic),e._hasCount="count"in e.static||"count"in e.dynamic||"elements"in e.static||"elements"in e.dynamic}function _(e,n){var r=h();t(e+" in command "+(n||p())+("unknown"===r?"":" called from "+r))}function S(e,t,n){e||_(t,n||p())}function T(e,t,n,i){e in t||_("unknown parameter ("+e+")"+r(n)+". possible values: "+Object.keys(t).join(),i||p())}function A(e,t,n,i){typeof e!==t&&_("invalid parameter type"+r(n)+". expected "+t+", got "+typeof e,i||p())}function O(e){e()}function C(e,t,n){e.texture?f(e.texture._texture.internalformat,t,"unsupported texture format for attachment"):f(e.renderbuffer._renderbuffer.format,n,"unsupported renderbuffer format for attachment")}function E(e,t){return e===ut||e===ft||e===ct?2:e===lt?4:dt[e]*t}function j(e){return!(e&e-1||!e)}function D(e,t,r){var i,a=t.width,o=t.height,s=t.channels;n(a>0&&a<=r.maxTextureSize&&o>0&&o<=r.maxTextureSize,"invalid texture shape"),e.wrapS===tt&&e.wrapT===tt||n(j(a)&&j(o),"incompatible wrap mode for texture, both width and height must be power of 2"),1===t.mipmask?1!==a&&1!==o&&n(e.minFilter!==rt&&e.minFilter!==at&&e.minFilter!==it&&e.minFilter!==ot,"min filter requires mipmap"):(n(j(a)&&j(o),"texture must be a square power of 2 to support mipmapping"),n(t.mipmask===(a<<1)-1,"missing or incomplete mipmap data")),t.type===st&&(r.extensions.indexOf("oes_texture_float_linear")<0&&n(e.minFilter===nt&&e.magFilter===nt,"filter not supported, must enable oes_texture_float_linear"),n(!e.genMipmaps,"mipmap generation not supported with float textures"));var f=t.images;for(i=0;i<16;++i)if(f[i]){var u=a>>i,c=o>>i;n(t.mipmask&1<0&&a<=i.maxTextureSize&&o>0&&o<=i.maxTextureSize,"invalid texture shape"),n(a===o,"cube map must be square"),n(t.wrapS===tt&&t.wrapT===tt,"wrap mode not supported by cube map");for(var f=0;f>l,p=o>>l;n(u.mipmask&1<1&&t===n&&('"'===t||"'"===t))return['"'+P(e.substr(1,e.length-2))+'"'];var r=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(e);if(r)return z(e.substr(0,r.index)).concat(z(r[1])).concat(z(e.substr(r.index+r[0].length)));var i=e.split(".");if(1===i.length)return['"'+P(e)+'"'];for(var a=[],o=0;o0,"invalid pixel ratio")):mt.raise("invalid arguments to regl"),t&&("canvas"===t.nodeName.toLowerCase()?r=t:n=t),!i){if(!r){mt("undefined"!=typeof document,"must manually specify webgl context outside of DOM environments");var m=N(n||document.body,l,u);if(!m)return null;r=m.canvas,d=m.onDestroy}i=H(r,o)}return i?{gl:i,canvas:r,container:n,extensions:s,optionalExtensions:f,pixelRatio:u,profile:c,onDone:l,onDestroy:d}:(d(),l("webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org"),null)}function X(e,t){function n(t){mt.type(t,"string","extension name must be string");var n,i=t.toLowerCase();try{n=r[i]=e.getExtension(i)}catch(e){}return!!n}for(var r={},i=0;i65535)<<4,e>>>=t,n=(e>255)<<3,e>>>=n,t|=n,n=(e>15)<<2,e>>>=n,t|=n,n=(e>3)<<1,e>>>=n,(t|=n)|e>>1}function J(e){var t=K(e),n=Ct[Z(t)>>2];return n.length>0?n.pop():new ArrayBuffer(t)}function ee(e){Ct[Z(e.byteLength)>>2].push(e)}function te(e,t){var n=null;switch(e){case wt:n=new Int8Array(J(t),0,t);break;case kt:n=new Uint8Array(J(t),0,t);break;case _t:n=new Int16Array(J(2*t),0,t);break;case St:n=new Uint16Array(J(2*t),0,t);break;case Tt:n=new Int32Array(J(4*t),0,t);break;case At:n=new Uint32Array(J(4*t),0,t);break;case Ot:n=new Float32Array(J(4*t),0,t);break;default:return null}return n.length!==t?n.subarray(0,t):n}function ne(e){ee(e.buffer)}function re(e,t,n){for(var r=0;r0){var f;if(Array.isArray(t[0])){s=Pt(t);for(var u=1,c=1;c0)if("number"==typeof e[0]){var i=Et.allocType(p.dtype,e.length);ce(i,e),l(i,r),Et.freeType(i)}else if(Array.isArray(e[0])||Ze(e[0])){n=Pt(e);var a=Wt(e,n,p.dtype);l(a,r),Et.freeType(a)}else mt.raise("invalid buffer data")}else if(Ze(e))l(e,r);else if(Y(e)){n=e.shape;var o=e.stride,s=0,f=0,u=0,d=0;1===n.length?(s=n[0],f=1,u=o[0],d=0):2===n.length?(s=n[0],f=n[1],u=o[0],d=o[1]):mt.raise("invalid shape");var m=Array.isArray(e.data)?p.dtype:ue(e.data),h=Et.allocType(m,s*f);le(h,e.data,s,f,u,d,e.offset),l(h,r),Et.freeType(h)}else mt.raise("invalid data for buffer subdata");return c}t.bufferCount++;var p=new r(a);return d[p.id]=p,o||c(i),c._reglType="buffer",c._buffer=p,c.subdata=m,n.profile&&(c.stats=p.stats),c.destroy=function(){f(p)},c}function c(){xt(d).forEach(function(t){t.buffer=e.createBuffer(),e.bindBuffer(t.type,t.buffer),e.bufferData(t.type,t.persistentData||t.byteLength,t.usage)})}var l=0,d={};r.prototype.bind=function(){e.bindBuffer(this.type,this.buffer)},r.prototype.destroy=function(){f(this)};var m=[];return n.profile&&(t.getTotalBufferSize=function(){var e=0;return Object.keys(d).forEach(function(t){e+=d[t].stats.size}),e}),{create:u,createStream:i,destroyStream:a,clear:function(){xt(d).forEach(f),m.forEach(f)},getBuffer:function(e){return e&&e._buffer instanceof r?e._buffer:null},restore:c,_initBuffer:s}}function me(e,t,n,r){function i(e){this.id=l++,c[this.id]=this,this.buffer=e,this.primType=Vt,this.vertCount=0,this.type=0}function a(e){var t=m.pop();return t||(t=new i(n.create(null,$t,!0,!1)._buffer)),s(t,e,Kt,-1,-1,0,0),t}function o(e){m.push(e)}function s(r,i,a,o,s,f,u){if(r.buffer.bind(),i){var c=u;u||Ze(i)&&(!Y(i)||Ze(i.data))||(c=t.oes_element_index_uint?Yt:Qt),n._initBuffer(r.buffer,i,a,c,3)}else e.bufferData($t,f,a),r.buffer.dtype=l||Ut,r.buffer.usage=a,r.buffer.dimension=3,r.buffer.byteLength=f;var l=u;if(!u){switch(r.buffer.dtype){case Ut:case Gt:l=Ut;break;case Qt:case qt:l=Qt;break;case Yt:case Xt:l=Yt;break;default:mt.raise("unsupported type for element array")}r.buffer.dtype=l}r.type=l,mt(l!==Yt||!!t.oes_element_index_uint,"32 bit element buffers not supported, enable oes_element_index_uint first");var d=s;d<0&&(d=r.buffer.byteLength,l===Qt?d>>=1:l===Yt&&(d>>=2)),r.vertCount=d;var m=o;if(o<0){m=Vt;var p=r.buffer.dimension;1===p&&(m=Nt),2===p&&(m=Ht),3===p&&(m=Vt)}r.primType=m}function f(e){r.elementsCount--,mt(null!==e.buffer,"must not double destroy elements"),delete c[e.id],e.buffer.destroy(),e.buffer=null}function u(e,t){function a(e){if(e)if("number"==typeof e)o(e),u.primType=Vt,u.vertCount=0|e,u.type=Ut;else{var t=null,n=Zt,r=-1,i=-1,f=0,c=0;Array.isArray(e)||Ze(e)||Y(e)?t=e:(mt.type(e,"object","invalid arguments for elements"),"data"in e&&(t=e.data,mt(Array.isArray(t)||Ze(t)||Y(t),"invalid data for element buffer")),"usage"in e&&(mt.parameter(e.usage,Mt,"invalid element buffer usage"),n=Mt[e.usage]),"primitive"in e&&(mt.parameter(e.primitive,It,"invalid element buffer primitive"),r=It[e.primitive]),"count"in e&&(mt("number"==typeof e.count&&e.count>=0,"invalid vertex count for elements"),i=0|e.count),"type"in e&&(mt.parameter(e.type,d,"invalid buffer type"),c=d[e.type]),"length"in e?f=0|e.length:(f=i,c===Qt||c===qt?f*=2:c!==Yt&&c!==Xt||(f*=4))),s(u,t,n,r,i,f,c)}else o(),u.primType=Vt,u.vertCount=0,u.type=Ut;return a}var o=n.create(null,$t,!0),u=new i(o._buffer);return r.elementsCount++,a(e),a._reglType="elements",a._elements=u,a.subdata=function(e,t){return o.subdata(e,t),a},a.destroy=function(){f(u)},a}var c={},l=0,d={uint8:Ut,uint16:Qt};t.oes_element_index_uint&&(d.uint32=Yt),i.prototype.bind=function(){this.buffer.bind()};var m=[];return{create:u,createStream:a,destroyStream:o,getElements:function(e){return"function"==typeof e&&e._elements instanceof i?e._elements:null},clear:function(){xt(c).forEach(f)}}}function pe(e){for(var t=Et.allocType(tn,e.length),n=0;n>>31<<15,a=(r<<1>>>24)-127,o=r>>13&1023;if(a<-24)t[n]=i;else if(a<-14){var s=-14-a;t[n]=i+(o+1024>>s)}else t[n]=a>15?i+31744:i+(a+15<<10)+o}return t}function he(e){return Array.isArray(e)||Ze(e)}function be(e){return"[object "+e+"]"}function ge(e){return Array.isArray(e)&&(0===e.length||"number"==typeof e[0])}function ve(e){return!!Array.isArray(e)&&!(0===e.length||!he(e[0]))}function ye(e){return Object.prototype.toString.call(e)}function xe(e){return ye(e)===mr}function we(e){return ye(e)===pr}function ke(e){return ye(e)===hr}function _e(e){return ye(e)===br}function Se(e){if(!e)return!1;var t=ye(e);return gr.indexOf(t)>=0||(ge(e)||ve(e)||Y(e))}function Te(e){return 0|Ke[Object.prototype.toString.call(e)]}function Ae(e,t){var n=t.length;switch(e.type){case Bn:case Rn:case Fn:case Ln:var r=Et.allocType(e.type,n);r.set(t),e.data=r;break;case _n:e.data=pe(t);break;default:mt.raise("unsupported texture type, must specify a typed array")}}function Oe(e,t){return Et.allocType(e.type===_n?Ln:e.type,t)}function Ce(e,t){e.type===_n?(e.data=pe(t),Et.freeType(t)):e.data=t}function Ee(e,t,n,r,i,a){for(var o=e.width,s=e.height,f=e.channels,u=Oe(e,o*s*f),c=0,l=0;l=1;)s+=o*f*f,f/=2;return s}return o*n*r}function De(e,t,n,r,i,a,o){function s(){this.internalformat=sn,this.format=sn,this.type=Bn,this.compressed=!1,this.premultiplyAlpha=!1,this.flipY=!1,this.unpackAlignment=1,this.colorSpace=0,this.width=0,this.height=0,this.channels=0}function f(e,t){e.internalformat=t.internalformat,e.format=t.format,e.type=t.type,e.compressed=t.compressed,e.premultiplyAlpha=t.premultiplyAlpha,e.flipY=t.flipY,e.unpackAlignment=t.unpackAlignment,e.colorSpace=t.colorSpace,e.width=t.width,e.height=t.height,e.channels=t.channels}function u(e,r){if("object"==typeof r&&r){if("premultiplyAlpha"in r&&(mt.type(r.premultiplyAlpha,"boolean","invalid premultiplyAlpha"),e.premultiplyAlpha=r.premultiplyAlpha),"flipY"in r&&(mt.type(r.flipY,"boolean","invalid texture flip"),e.flipY=r.flipY),"alignment"in r&&(mt.oneOf(r.alignment,[1,2,4,8],"invalid texture unpack alignment"),e.unpackAlignment=r.alignment),"colorSpace"in r&&(mt.parameter(r.colorSpace,F,"invalid colorSpace"),e.colorSpace=F[r.colorSpace]),"type"in r){var i=r.type;mt(t.oes_texture_float||!("float"===i||"float32"===i),"you must enable the OES_texture_float extension in order to use floating point textures."),mt(t.oes_texture_half_float||!("half float"===i||"float16"===i),"you must enable the OES_texture_half_float extension in order to use 16-bit floating point textures."),mt(t.webgl_depth_texture||!("uint16"===i||"uint32"===i||"depth stencil"===i),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),mt.parameter(i,L,"invalid texture type"),e.type=L[i]}var a=e.width,o=e.height,s=e.channels,f=!1;"shape"in r?(mt(Array.isArray(r.shape)&&r.shape.length>=2,"shape must be an array"),a=r.shape[0],o=r.shape[1],3===r.shape.length&&(s=r.shape[2],mt(s>0&&s<=4,"invalid number of channels"),f=!0),mt(a>=0&&a<=n.maxTextureSize,"invalid width"),mt(o>=0&&o<=n.maxTextureSize,"invalid height")):("radius"in r&&(a=o=r.radius,mt(a>=0&&a<=n.maxTextureSize,"invalid radius")),"width"in r&&(a=r.width,mt(a>=0&&a<=n.maxTextureSize,"invalid width")),"height"in r&&(o=r.height,mt(o>=0&&o<=n.maxTextureSize,"invalid height")),"channels"in r&&(s=r.channels,mt(s>0&&s<=4,"invalid number of channels"),f=!0)),e.width=0|a,e.height=0|o,e.channels=0|s;var u=!1;if("format"in r){var c=r.format;mt(t.webgl_depth_texture||!("depth"===c||"depth stencil"===c),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),mt.parameter(c,I,"invalid texture format");var l=e.internalformat=I[c];e.format=$[l],c in L&&("type"in r||(e.type=L[c])),c in N&&(e.compressed=!0),u=!0}!f&&u?e.channels=dr[e.format]:f&&!u?e.channels!==lr[e.format]&&(e.format=e.internalformat=lr[e.channels]):u&&f&&mt(e.channels===dr[e.format],"number of channels inconsistent with specified format")}}function c(t){e.pixelStorei(ar,t.flipY),e.pixelStorei(or,t.premultiplyAlpha),e.pixelStorei(sr,t.colorSpace),e.pixelStorei(ir,t.unpackAlignment)}function l(){s.call(this),this.xOffset=0,this.yOffset=0,this.data=null,this.needsFree=!1,this.element=null,this.needsCopy=!1}function d(e,t){var r=null;if(Se(t)?r=t:t&&(mt.type(t,"object","invalid pixel data type"),u(e,t),"x"in t&&(e.xOffset=0|t.x),"y"in t&&(e.yOffset=0|t.y),Se(t.data)&&(r=t.data)),mt(!e.compressed||r instanceof Uint8Array,"compressed texture data must be stored in a uint8array"),t.copy){mt(!r,"can not specify copy and data field for the same texture");var a=i.viewportWidth,o=i.viewportHeight;e.width=e.width||a-e.xOffset,e.height=e.height||o-e.yOffset,e.needsCopy=!0,mt(e.xOffset>=0&&e.xOffset=0&&e.yOffset0&&e.width<=a&&e.height>0&&e.height<=o,"copy texture read out of bounds")}else if(r){if(Ze(r))e.channels=e.channels||4,e.data=r,"type"in t||e.type!==Bn||(e.type=Te(r));else if(ge(r))e.channels=e.channels||4,Ae(e,r),e.alignment=1,e.needsFree=!0;else if(Y(r)){var s=r.data;Array.isArray(s)||e.type!==Bn||(e.type=Te(s));var f,c,l,d,m,p,h=r.shape,b=r.stride;3===h.length?(l=h[2],p=b[2]):(mt(2===h.length,"invalid ndarray pixel data, must be 2 or 3D"),l=1,p=1),f=h[0],c=h[1],d=b[0],m=b[1],e.alignment=1,e.width=f,e.height=c,e.channels=l,e.format=e.internalformat=lr[l],e.needsFree=!0,Ee(e,s,d,m,p,r.offset)}else if(xe(r)||we(r))xe(r)?e.element=r:e.element=r.canvas,e.width=e.element.width,e.height=e.element.height,e.channels=4;else if(ke(r))e.element=r,e.width=r.naturalWidth,e.height=r.naturalHeight,e.channels=4;else if(_e(r))e.element=r,e.width=r.videoWidth,e.height=r.videoHeight,e.channels=4;else if(ve(r)){var g=e.width||r[0].length,v=e.height||r.length,y=e.channels;y=he(r[0][0])?y||r[0][0].length:y||1;for(var x=jt.shape(r),w=1,k=0;k=0,"oes_texture_float extension not enabled"):e.type===_n&&mt(n.extensions.indexOf("oes_texture_half_float")>=0,"oes_texture_half_float extension not enabled")}function m(t,n,i){var a=t.element,o=t.data,s=t.internalformat,f=t.format,u=t.type,l=t.width,d=t.height;c(t),a?e.texImage2D(n,i,f,f,u,a):t.compressed?e.compressedTexImage2D(n,i,s,l,d,0,o):t.needsCopy?(r(),e.copyTexImage2D(n,i,f,t.xOffset,t.yOffset,l,d,0)):e.texImage2D(n,i,f,l,d,0,f,u,o)}function p(t,n,i,a,o){var s=t.element,f=t.data,u=t.internalformat,l=t.format,d=t.type,m=t.width,p=t.height;c(t),s?e.texSubImage2D(n,o,i,a,l,d,s):t.compressed?e.compressedTexSubImage2D(n,o,i,a,u,m,p,f):t.needsCopy?(r(),e.copyTexSubImage2D(n,o,i,a,t.xOffset,t.yOffset,m,p)):e.texSubImage2D(n,o,i,a,m,p,l,d,f)}function h(){return K.pop()||new l}function b(e){e.needsFree&&Et.freeType(e.data),l.call(e),K.push(e)}function g(){s.call(this),this.genMipmaps=!1,this.mipmapHint=er,this.mipmask=0,this.images=Array(16)}function v(e,t,n){var r=e.images[0]=h();e.mipmask=1,r.width=e.width=t,r.height=e.height=n,r.channels=e.channels=4}function y(e,t){var n=null;if(Se(t))f(n=e.images[0]=h(),e),d(n,t),e.mipmask=1;else if(u(e,t),Array.isArray(t.mipmap))for(var r=t.mipmap,i=0;i>=i,n.height>>=i,d(n,r[i]),e.mipmask|=1<=0&&(e.genMipmaps=!0)}if("mag"in t){var i=t.mag;mt.parameter(i,B),e.magFilter=B[i]}var a=e.wrapS,o=e.wrapT;if("wrap"in t){var s=t.wrap;"string"==typeof s?(mt.parameter(s,z),a=o=z[s]):Array.isArray(s)&&(mt.parameter(s[0],z),mt.parameter(s[1],z),a=z[s[0]],o=z[s[1]])}else{if("wrapS"in t){var f=t.wrapS;mt.parameter(f,z),a=z[f]}if("wrapT"in t){var u=t.wrapT;mt.parameter(u,z),o=z[u]}}if(e.wrapS=a,e.wrapT=o,"anisotropic"in t){var c=t.anisotropic;mt("number"==typeof c&&c>=1&&c<=n.maxAnisotropic,"aniso samples must be between 1 and "),e.anisotropic=t.anisotropic}if("mipmap"in t){var l=!1;switch(typeof t.mipmap){case"string":mt.parameter(t.mipmap,P,"invalid mipmap hint"),e.mipmapHint=P[t.mipmap],e.genMipmaps=!0,l=!0;break;case"boolean":l=e.genMipmaps=t.mipmap;break;case"object":mt(Array.isArray(t.mipmap),"invalid mipmap type"),e.genMipmaps=!1,l=!0;break;default:mt.raise("invalid mipmap type")}!l||"min"in t||(e.minFilter=Yn)}}function T(n,r){e.texParameteri(r,qn,n.minFilter),e.texParameteri(r,Un,n.magFilter),e.texParameteri(r,In,n.wrapS),e.texParameteri(r,Nn,n.wrapT),t.ext_texture_filter_anisotropic&&e.texParameteri(r,rr,n.anisotropic),n.genMipmaps&&(e.hint(Jn,n.mipmapHint),e.generateMipmap(r))}function A(t){s.call(this),this.mipmask=0,this.internalformat=sn,this.id=J++,this.refCount=1,this.target=t,this.texture=e.createTexture(),this.unit=-1,this.bindCount=0,this.texInfo=new _,o.profile&&(this.stats={size:0})}function O(t){e.activeTexture(ur),e.bindTexture(t.target,t.texture)}function C(){var t=ne[0];t?e.bindTexture(t.target,t.texture):e.bindTexture(rn,null)}function E(t){var n=t.texture;mt(n,"must not double destroy texture");var r=t.unit,i=t.target;r>=0&&(e.activeTexture(ur+r),e.bindTexture(i,null),ne[r]=null),e.deleteTexture(n),t.texture=null,t.params=null,t.pixels=null,t.refCount=0,delete ee[t.id],a.textureCount--}function j(t,r){function i(e,t){var r=c.texInfo;_.call(r);var a=w();return"number"==typeof e?"number"==typeof t?v(a,0|e,0|t):v(a,0|e,0|e):e?(mt.type(e,"object","invalid arguments to regl.texture"),S(r,e),y(a,e)):v(a,1,1),r.genMipmaps&&(a.mipmask=(a.width<<1)-1),c.mipmask=a.mipmask,f(c,a),mt.texture2D(r,a,n),c.internalformat=a.internalformat,i.width=a.width,i.height=a.height,O(c),x(a,rn),T(r,rn),C(),k(a),o.profile&&(c.stats.size=je(c.internalformat,c.type,a.width,a.height,r.genMipmaps,!1)),i.format=G[c.internalformat],i.type=U[c.type],i.mag=q[r.magFilter],i.min=Q[r.minFilter],i.wrapS=X[r.wrapS],i.wrapT=X[r.wrapT],i}function s(e,t,n,r){mt(!!e,"must specify image data");var a=0|t,o=0|n,s=0|r,u=h();return f(u,c),u.width=0,u.height=0,d(u,e),u.width=u.width||(c.width>>s)-a,u.height=u.height||(c.height>>s)-o,mt(c.type===u.type&&c.format===u.format&&c.internalformat===u.internalformat,"incompatible format for texture.subimage"),mt(a>=0&&o>=0&&a+u.width<=c.width&&o+u.height<=c.height,"texture.subimage write out of bounds"),mt(c.mipmask&1<>s;++s)e.texImage2D(rn,s,c.format,r>>s,a>>s,0,c.format,c.type,null);return C(),o.profile&&(c.stats.size=je(c.internalformat,c.type,r,a,!1,!1)),i}var c=new A(rn);return ee[c.id]=c,a.textureCount++,i(t,r),i.subimage=s,i.resize=u,i._reglType="texture2d",i._texture=c,o.profile&&(i.stats=c.stats),i.destroy=function(){c.decRef()},i}function D(t,r,i,s,c,l){function m(e,t,r,i,a,s){var c,l=j.texInfo;for(_.call(l),c=0;c<6;++c)D[c]=w();if("number"!=typeof e&&e)if("object"==typeof e)if(t)y(D[0],e),y(D[1],t),y(D[2],r),y(D[3],i),y(D[4],a),y(D[5],s);else if(S(l,e),u(j,e),"faces"in e){var d=e.faces;for(mt(Array.isArray(d)&&6===d.length,"cube faces must be a length 6 array"),c=0;c<6;++c)mt("object"==typeof d[c]&&!!d[c],"invalid input for cube map face"),f(D[c],j),y(D[c],d[c])}else for(c=0;c<6;++c)y(D[c],e);else mt.raise("invalid arguments to cube map");else{var p=0|e||1;for(c=0;c<6;++c)v(D[c],p,p)}for(f(j,D[0]),l.genMipmaps?j.mipmask=(D[0].width<<1)-1:j.mipmask=D[0].mipmask,mt.textureCube(j,l,D,n),j.internalformat=D[0].internalformat,m.width=D[0].width,m.height=D[0].height,O(j),c=0;c<6;++c)x(D[c],on+c);for(T(l,an),C(),o.profile&&(j.stats.size=je(j.internalformat,j.type,m.width,m.height,l.genMipmaps,!0)),m.format=G[j.internalformat],m.type=U[j.type],m.mag=q[l.magFilter],m.min=Q[l.minFilter],m.wrapS=X[l.wrapS],m.wrapT=X[l.wrapT],c=0;c<6;++c)k(D[c]);return m}function g(e,t,n,r,i){mt(!!t,"must specify image data"),mt("number"==typeof e&&e===(0|e)&&e>=0&&e<6,"invalid face");var a=0|n,o=0|r,s=0|i,u=h();return f(u,j),u.width=0,u.height=0,d(u,t),u.width=u.width||(j.width>>s)-a,u.height=u.height||(j.height>>s)-o,mt(j.type===u.type&&j.format===u.format&&j.internalformat===u.internalformat,"incompatible format for texture.subimage"),mt(a>=0&&o>=0&&a+u.width<=j.width&&o+u.height<=j.height,"texture.subimage write out of bounds"),mt(j.mipmask&1<>i;++i)e.texImage2D(on+r,i,j.format,n>>i,n>>i,0,j.format,j.type,null);return C(),o.profile&&(j.stats.size=je(j.internalformat,j.type,m.width,m.height,!1,!0)),m}}var j=new A(an);ee[j.id]=j,a.cubeCount++;var D=new Array(6);return m(t,r,i,s,c,l),m.subimage=g,m.resize=E,m._reglType="textureCube",m._texture=j,o.profile&&(m.stats=j.stats),m.destroy=function(){j.decRef()},m}function M(){for(var t=0;t>n,t.height>>n,0,t.internalformat,t.type,null);else for(var r=0;r<6;++r)e.texImage2D(on+r,n,t.internalformat,t.width>>n,t.height>>n,0,t.internalformat,t.type,null);T(t.texInfo,t.target)})}var P={"don't care":er,"dont care":er,nice:nr,fast:tr},z={repeat:Hn,clamp:Vn,mirror:Gn},B={nearest:Qn,linear:Xn},R=Je({mipmap:Zn,"nearest mipmap nearest":Yn,"linear mipmap nearest":$n,"nearest mipmap linear":Kn,"linear mipmap linear":Zn},B),F={none:0,browser:fr},L={uint8:Bn,rgba4:hn,rgb565:gn,"rgb5 a1":bn},I={alpha:fn,luminance:cn,"luminance alpha":ln,rgb:un,rgba:sn,rgba4:dn,"rgb5 a1":mn,rgb565:pn},N={};t.ext_srgb&&(I.srgb=wn,I.srgba=kn),t.oes_texture_float&&(L.float32=L.float=Ln),t.oes_texture_half_float&&(L.float16=L["half float"]=_n),t.webgl_depth_texture&&(Je(I,{depth:yn,"depth stencil":xn}),Je(L,{uint16:Rn,uint32:Fn,"depth stencil":vn})),t.webgl_compressed_texture_s3tc&&Je(N,{"rgb s3tc dxt1":Sn,"rgba s3tc dxt1":Tn,"rgba s3tc dxt3":An,"rgba s3tc dxt5":On}),t.webgl_compressed_texture_atc&&Je(N,{"rgb atc":Cn,"rgba atc explicit alpha":En,"rgba atc interpolated alpha":jn}),t.webgl_compressed_texture_pvrtc&&Je(N,{"rgb pvrtc 4bppv1":Dn,"rgb pvrtc 2bppv1":Mn,"rgba pvrtc 4bppv1":Wn,"rgba pvrtc 2bppv1":Pn}),t.webgl_compressed_texture_etc1&&(N["rgb etc1"]=zn);var H=Array.prototype.slice.call(e.getParameter(nn));Object.keys(N).forEach(function(e){var t=N[e];H.indexOf(t)>=0&&(I[e]=t)});var V=Object.keys(I);n.textureFormats=V;var G=[];Object.keys(I).forEach(function(e){var t=I[e];G[t]=e});var U=[];Object.keys(L).forEach(function(e){var t=L[e];U[t]=e});var q=[];Object.keys(B).forEach(function(e){var t=B[e];q[t]=e});var Q=[];Object.keys(R).forEach(function(e){var t=R[e];Q[t]=e});var X=[];Object.keys(z).forEach(function(e){var t=z[e];X[t]=e});var $=V.reduce(function(e,t){var n=I[t];return n===cn||n===fn||n===cn||n===ln||n===yn||n===xn?e[n]=n:n===mn||t.indexOf("rgba")>=0?e[n]=sn:e[n]=un,e},{}),K=[],Z=[],J=0,ee={},te=n.maxTextureUnits,ne=Array(te).map(function(){return null});return Je(A.prototype,{bind:function(){var t=this;t.bindCount+=1;var n=t.unit;if(n<0){for(var r=0;r0)continue;i.unit=-1}ne[r]=t,n=r;break}n>=te&&mt.raise("insufficient number of texture units"),o.profile&&a.maxTextureUnits=Or&&t=2,"invalid shape for framebuffer"),u=M[0],m=M[1]}else"radius"in D&&(u=m=D.radius),"width"in D&&(u=D.width),"height"in D&&(m=D.height);("color"in D||"colors"in D)&&(v=D.color||D.colors,Array.isArray(v)&&mt(1===v.length||o,"multiple render targets not supported")),v||("colorCount"in D&&(A=0|D.colorCount,mt(A>0,"invalid color buffer count")),"colorTexture"in D&&(y=!!D.colorTexture,x="rgba4"),"colorType"in D&&(T=D.colorType,y?(mt(t.oes_texture_float||!("float"===T||"float32"===T),"you must enable OES_texture_float in order to use floating point framebuffer objects"),mt(t.oes_texture_half_float||!("half float"===T||"float16"===T),"you must enable OES_texture_half_float in order to use 16-bit floating point framebuffer objects")):"half float"===T||"float16"===T?(mt(t.ext_color_buffer_half_float,"you must enable EXT_color_buffer_half_float to use 16-bit render buffers"),x="rgba16f"):"float"!==T&&"float32"!==T||(mt(t.webgl_color_buffer_float,"you must enable WEBGL_color_buffer_float in order to use 32-bit floating point renderbuffers"),x="rgba32f"),mt.oneOf(T,S,"invalid color type")),"colorFormat"in D&&(x=D.colorFormat,k.indexOf(x)>=0?y=!0:_.indexOf(x)>=0?y=!1:y?mt.oneOf(D.colorFormat,k,"invalid color format for texture"):mt.oneOf(D.colorFormat,_,"invalid color format for renderbuffer"))),("depthTexture"in D||"depthStencilTexture"in D)&&(j=!(!D.depthTexture&&!D.depthStencilTexture),mt(!j||t.webgl_depth_texture,"webgl_depth_texture extension not supported")),"depth"in D&&("boolean"==typeof D.depth?p=D.depth:(O=D.depth,b=!1)),"stencil"in D&&("boolean"==typeof D.stencil?b=D.stencil:(C=D.stencil,p=!1)),"depthStencil"in D&&("boolean"==typeof D.depthStencil?p=b=D.depthStencil:(E=D.depthStencil,p=!1,b=!1))}else u=m=1;var W=null,P=null,z=null,B=null;if(Array.isArray(v))W=v.map(c);else if(v)W=[c(v)];else for(W=new Array(A),a=0;a=0||W[a].renderbuffer&&Ir.indexOf(W[a].renderbuffer._renderbuffer.format)>=0,"framebuffer color attachment "+a+" is invalid"),W[a]&&W[a].texture){var F=zr[W[a].texture._texture.format]*Br[W[a].texture._texture.type];null===R?R=F:mt(R===F,"all color attachments much have the same number of bits per pixel.")}return f(P,u,m),mt(!P||P.texture&&P.texture._texture.format===Wr||P.renderbuffer&&P.renderbuffer._renderbuffer.format===Rr,"invalid depth attachment for framebuffer object"),f(z,u,m),mt(!z||z.renderbuffer&&z.renderbuffer._renderbuffer.format===Fr,"invalid stencil attachment for framebuffer object"),f(B,u,m),mt(!B||B.texture&&B.texture._texture.format===Lr||B.renderbuffer&&B.renderbuffer._renderbuffer.format===Lr,"invalid depth-stencil attachment for framebuffer object"),h(s),s.width=u,s.height=m,s.colorAttachments=W,s.depthAttachment=P,s.stencilAttachment=z,s.depthStencilAttachment=B,i.color=W.map(d),i.depth=d(P),i.stencil=d(z),i.depthStencil=d(B),i.width=s.width,i.height=s.height,g(s),i}function o(e,t){mt(w.next!==s,"can not resize a framebuffer which is currently in use");var n=0|e,r=0|t||n;if(n===s.width&&r===s.height)return i;for(var a=s.colorAttachments,o=0;o=2,"invalid shape for framebuffer"),mt(p[0]===p[1],"cube framebuffer must be square"),f=p[0]}else"radius"in m&&(f=0|m.radius),"width"in m?(f=0|m.width,"height"in m&&mt(m.height===f,"must be square")):"height"in m&&(f=0|m.height);("color"in m||"colors"in m)&&(u=m.color||m.colors,Array.isArray(u)&&mt(1===u.length||a,"multiple render targets not supported")),u||("colorCount"in m&&(d=0|m.colorCount,mt(d>0,"invalid color buffer count")),"colorType"in m&&(mt.oneOf(m.colorType,S,"invalid color type"),l=m.colorType),"colorFormat"in m&&(c=m.colorFormat,mt.oneOf(m.colorFormat,k,"invalid color format for texture"))),"depth"in m&&(s.depth=m.depth),"stencil"in m&&(s.stencil=m.stencil),"depthStencil"in m&&(s.depthStencil=m.depthStencil)}else f=1;var h;if(u)if(Array.isArray(u))for(h=[],n=0;n0&&(s.depth=o[0].depth,s.stencil=o[0].stencil,s.depthStencil=o[0].depthStencil),o[n]?o[n](s):o[n]=v(s)}return Je(i,{width:f,height:f,color:h})}function a(e){var t,r=0|e;if(mt(r>0&&r<=n.maxCubeMapSize,"invalid radius for cube fbo"),r===i.width)return i;var a=i.color;for(t=0;t1)for(var h=0;he&&(e=t.stats.uniformsCount)}),e},n.getMaxAttributesCount=function(){var e=0;return m.forEach(function(t){t.stats.attributesCount>e&&(e=t.stats.attributesCount)}),e}),{clear:function(){var t=e.deleteShader.bind(e);xt(c).forEach(t),c={},xt(l).forEach(t),l={},m.forEach(function(t){e.deleteProgram(t.program)}),m.length=0,d={},n.shaderCount=0},program:function(e,t,r){mt.command(e>=0,"missing vertex shader",r),mt.command(t>=0,"missing fragment shader",r);var i=d[t];i||(i=d[t]={});var a=i[e];return a||(a=new s(t,e),n.shaderCount++,f(a,r),i[e]=a,m.push(a)),a},restore:u,shader:o,frag:-1,vert:-1}}function Re(e,t,n,r,i,a){function o(o){var s;null===t.next?(mt(i.preserveDrawingBuffer,'you must create a webgl context with "preserveDrawingBuffer":true in order to read pixels from the drawing buffer'),s=Xr):(mt(null!==t.next.colorAttachments[0].texture,"You cannot read from a renderbuffer"),s=t.next.colorAttachments[0].texture._texture.type,a.oes_texture_float?mt(s===Xr||s===$r,"Reading from a framebuffer is only allowed for the types 'uint8' and 'float'"):mt(s===Xr,"Reading from a framebuffer is only allowed for the type 'uint8'"));var f=0,u=0,c=r.framebufferWidth,l=r.framebufferHeight,d=null;Ze(o)?d=o:o&&(mt.type(o,"object","invalid arguments to regl.read()"),f=0|o.x,u=0|o.y,mt(f>=0&&f=0&&u0&&c+f<=r.framebufferWidth,"invalid width for read pixels"),mt(l>0&&l+u<=r.framebufferHeight,"invalid height for read pixels"),n();var m=c*l*4;return d||(s===Xr?d=new Uint8Array(m):s===$r&&(d=d||new Float32Array(m))),mt.isTypedArray(d,"data buffer for regl.read() must be a typedarray"),mt(d.byteLength>=m,"data buffer for regl.read() too small"),e.pixelStorei(Yr,4),e.readPixels(f,u,c,l,Qr,s,d),d}function s(e){var n;return t.setFBO({framebuffer:e.framebuffer},function(){n=o(e)}),n}function f(e){return e&&"framebuffer"in e?s(e):o(e)}return f}function Fe(e){return Array.prototype.slice.call(e)}function Le(e){return Fe(e).join("")}function Ie(){function e(e){for(var t=0;t0&&(n.push(e,"="),n.push.apply(n,Fe(arguments)),n.push(";")),e}var n=[],r=[];return Je(e,{def:t,toString:function(){return Le([r.length>0?"var "+r+";":"",Le(n)])}})}function n(){function e(e,t){r(e,t,"=",n.def(e,t),";")}var n=t(),r=t(),i=n.toString,a=r.toString;return Je(function(){n.apply(n,Fe(arguments))},{def:n.def,entry:n,exit:r,save:e,set:function(t,r,i){e(t,r),n(t,r,"=",i,";")},toString:function(){return i()+a()}})}function r(){var e=Le(arguments),t=n(),r=n(),i=t.toString,a=r.toString;return Je(t,{then:function(){return t.apply(t,Fe(arguments)),this},else:function(){return r.apply(r,Fe(arguments)),this},toString:function(){var t=a();return t&&(t="else{"+t+"}"),Le(["if(",e,"){",i(),"}",t])}})}function i(e,t){function r(){var e="a"+i.length;return i.push(e),e}var i=[];t=t||0;for(var a=0;a=1,r>=2,t)}if(n===ai){var i=e.data;return new Ve(i.thisDep,i.contextDep,i.propDep,t)}return new Ve(n===ii,n===ri,n===ni,t)}function Qe(e,t,n,r,i,a,o,s,f,u,c,l,d,m,p){function h(e){return e.replace(".","_")}function b(e,t,n){var r=h(e);te.push(e),ee[r]=J[r]=!!n,ne[r]=t}function g(e,t,n){var r=h(e);te.push(e),Array.isArray(n)?(J[r]=n.slice(),ee[r]=n.slice()):J[r]=ee[r]=n,re[r]=t}function v(){var e=Ie(),n=e.link,r=e.global;e.id=oe++,e.batchId="0";var i=n(ie),a=e.shared={props:"a0"};Object.keys(ie).forEach(function(e){a[e]=r.def(i,".",e)}),mt.optional(function(){e.CHECK=n(mt),e.commandStr=mt.guessCommand(),e.command=n(e.commandStr),e.assert=function(e,t,r){e("if(!(",t,"))",this.CHECK,".commandRaise(",n(r),",",this.command,");")},ae.invalidBlendCombinations=Na});var o=e.next={},s=e.current={};Object.keys(re).forEach(function(e){Array.isArray(J[e])&&(o[e]=r.def(a.next,".",e),s[e]=r.def(a.current,".",e))});var f=e.constants={};Object.keys(ae).forEach(function(e){f[e]=r.def(JSON.stringify(ae[e]))}),e.invoke=function(t,r){switch(r.type){case ti:var i=["this",a.context,a.props,e.batchId];return t.def(n(r.data),".call(",i.slice(0,Math.max(r.data.length+1,4)),")");case ni:return t.def(a.props,r.data);case ri:return t.def(a.context,r.data);case ii:return t.def("this",r.data);case ai:return r.data.append(e,t),r.data.ref}},e.attribCache={};var c={};return e.scopeAttrib=function(e){var r=t.id(e);if(r in c)return c[r];var i=u.scope[r];return i||(i=u.scope[r]=new X),c[r]=n(i)},e}function y(e){var t,n=e.static,r=e.dynamic;if(Wi in n){var i=!!n[Wi];(t=Ue(function(e,t){return i})).enable=i}else if(Wi in r){var a=r[Wi];t=qe(a,function(e,t){return e.invoke(t,a)})}return t}function x(e,t){var n=e.static,r=e.dynamic;if(Pi in n){var i=n[Pi];return i?(i=s.getFramebuffer(i),mt.command(i,"invalid framebuffer object"),Ue(function(e,t){var n=e.link(i),r=e.shared;t.set(r.framebuffer,".next",n);var a=r.context;return t.set(a,"."+Hi,n+".width"),t.set(a,"."+Vi,n+".height"),n})):Ue(function(e,t){var n=e.shared;t.set(n.framebuffer,".next","null");var r=n.context;return t.set(r,"."+Hi,r+"."+qi),t.set(r,"."+Vi,r+"."+Qi),"null"})}if(Pi in r){var a=r[Pi];return qe(a,function(e,t){var n=e.invoke(t,a),r=e.shared,i=r.framebuffer,o=t.def(i,".getFramebuffer(",n,")");mt.optional(function(){e.assert(t,"!"+n+"||"+o,"invalid framebuffer object")}),t.set(i,".next",o);var s=r.context;return t.set(s,"."+Hi,o+"?"+o+".width:"+s+"."+qi),t.set(s,"."+Vi,o+"?"+o+".height:"+s+"."+Qi),o})}return null}function w(e,t,n){function r(e){if(e in i){var r=i[e];mt.commandType(r,"object","invalid "+e,n.commandStr);var o,s,f=!0,u=0|r.x,c=0|r.y;return"width"in r?(o=0|r.width,mt.command(o>=0,"invalid "+e,n.commandStr)):f=!1,"height"in r?(s=0|r.height,mt.command(s>=0,"invalid "+e,n.commandStr)):f=!1,new Ve(!f&&t&&t.thisDep,!f&&t&&t.contextDep,!f&&t&&t.propDep,function(e,t){var n=e.shared.context,i=o;"width"in r||(i=t.def(n,".",Hi,"-",u));var a=s;return"height"in r||(a=t.def(n,".",Vi,"-",c)),[u,c,i,a]})}if(e in a){var l=a[e],d=qe(l,function(t,n){var r=t.invoke(n,l);mt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)});var i=t.shared.context,a=n.def(r,".x|0"),o=n.def(r,".y|0"),s=n.def('"width" in ',r,"?",r,".width|0:","(",i,".",Hi,"-",a,")"),f=n.def('"height" in ',r,"?",r,".height|0:","(",i,".",Vi,"-",o,")");return mt.optional(function(){t.assert(n,s+">=0&&"+f+">=0","invalid "+e)}),[a,o,s,f]});return t&&(d.thisDep=d.thisDep||t.thisDep,d.contextDep=d.contextDep||t.contextDep,d.propDep=d.propDep||t.propDep),d}return t?new Ve(t.thisDep,t.contextDep,t.propDep,function(e,t){var n=e.shared.context;return[0,0,t.def(n,".",Hi),t.def(n,".",Vi)]}):null}var i=e.static,a=e.dynamic,o=r(Mi);if(o){var s=o;o=new Ve(o.thisDep,o.contextDep,o.propDep,function(e,t){var n=s.append(e,t),r=e.shared.context;return t.set(r,"."+Gi,n[2]),t.set(r,"."+Ui,n[3]),n})}return{viewport:o,scissor_box:r(Di)}}function k(e){function n(e){if(e in i){var n=t.id(i[e]);mt.optional(function(){c.shader(Ga[e],n,mt.guessCommand())});var r=Ue(function(){return n});return r.id=n,r}if(e in a){var o=a[e];return qe(o,function(t,n){var r=t.invoke(n,o),i=n.def(t.shared.strings,".id(",r,")");return mt.optional(function(){n(t.shared.shader,".shader(",Ga[e],",",i,",",t.command,");")}),i})}return null}var r,i=e.static,a=e.dynamic,o=n(Bi),s=n(zi),f=null;return Ge(o)&&Ge(s)?(f=c.program(s.id,o.id),r=Ue(function(e,t){return e.link(f)})):r=new Ve(o&&o.thisDep||s&&s.thisDep,o&&o.contextDep||s&&s.contextDep,o&&o.propDep||s&&s.propDep,function(e,t){var n,r=e.shared.shader;n=o?o.append(e,t):t.def(r,".",Bi);var i,a=r+".program("+(i=s?s.append(e,t):t.def(r,".",zi))+","+n;return mt.optional(function(){a+=","+e.command}),t.def(a+")")}),{frag:o,vert:s,progVar:r,program:f}}function _(e,t){function n(e,n){if(e in r){var a=0|r[e];return mt.command(!n||a>=0,"invalid "+e,t.commandStr),Ue(function(e,t){return n&&(e.OFFSET=a),a})}if(e in i){var s=i[e];return qe(s,function(t,r){var i=t.invoke(r,s);return n&&(t.OFFSET=i,mt.optional(function(){t.assert(r,i+">=0","invalid "+e)})),i})}return n&&o?Ue(function(e,t){return e.OFFSET="0",0}):null}var r=e.static,i=e.dynamic,o=function(){if(Ri in r){var e=r[Ri];Ne(e)?e=a.getElements(a.create(e,!0)):e&&(e=a.getElements(e),mt.command(e,"invalid elements",t.commandStr));var n=Ue(function(t,n){if(e){var r=t.link(e);return t.ELEMENTS=r,r}return t.ELEMENTS=null,null});return n.value=e,n}if(Ri in i){var o=i[Ri];return qe(o,function(e,t){var n=e.shared,r=n.isBufferArgs,i=n.elements,a=e.invoke(t,o),s=t.def("null"),f=t.def(r,"(",a,")"),u=e.cond(f).then(s,"=",i,".createStream(",a,");").else(s,"=",i,".getElements(",a,");");return mt.optional(function(){e.assert(u.else,"!"+a+"||"+s,"invalid elements")}),t.entry(u),t.exit(e.cond(f).then(i,".destroyStream(",s,");")),e.ELEMENTS=s,s})}return null}(),s=n(Ii,!0);return{elements:o,primitive:function(){if(Fi in r){var e=r[Fi];return mt.commandParameter(e,It,"invalid primitve",t.commandStr),Ue(function(t,n){return It[e]})}if(Fi in i){var n=i[Fi];return qe(n,function(e,t){var r=e.constants.primTypes,i=e.invoke(t,n);return mt.optional(function(){e.assert(t,i+" in "+r,"invalid primitive, must be one of "+Object.keys(It))}),t.def(r,"[",i,"]")})}return o?Ge(o)?Ue(o.value?function(e,t){return t.def(e.ELEMENTS,".primType")}:function(){return Ta}):new Ve(o.thisDep,o.contextDep,o.propDep,function(e,t){var n=e.ELEMENTS;return t.def(n,"?",n,".primType:",Ta)}):null}(),count:function(){if(Li in r){var e=0|r[Li];return mt.command("number"==typeof e&&e>=0,"invalid vertex count",t.commandStr),Ue(function(){return e})}if(Li in i){var n=i[Li];return qe(n,function(e,t){var r=e.invoke(t,n);return mt.optional(function(){e.assert(t,"typeof "+r+'==="number"&&'+r+">=0&&"+r+"===("+r+"|0)","invalid vertex count")}),r})}if(o){if(Ge(o)){if(o)return s?new Ve(s.thisDep,s.contextDep,s.propDep,function(e,t){var n=t.def(e.ELEMENTS,".vertCount-",e.OFFSET);return mt.optional(function(){e.assert(t,n+">=0","invalid vertex offset/element buffer too small")}),n}):Ue(function(e,t){return t.def(e.ELEMENTS,".vertCount")});var a=Ue(function(){return-1});return mt.optional(function(){a.MISSING=!0}),a}var f=new Ve(o.thisDep||s.thisDep,o.contextDep||s.contextDep,o.propDep||s.propDep,function(e,t){var n=e.ELEMENTS;return e.OFFSET?t.def(n,"?",n,".vertCount-",e.OFFSET,":-1"):t.def(n,"?",n,".vertCount:-1")});return mt.optional(function(){f.DYNAMIC=!0}),f}return null}(),instances:n(Ni,!1),offset:s}}function S(e,t){var n=e.static,i=e.dynamic,a={};return te.forEach(function(e){function o(t,r){if(e in n){var o=t(n[e]);a[s]=Ue(function(){return o})}else if(e in i){var f=i[e];a[s]=qe(f,function(e,t){return r(e,t,e.invoke(t,f))})}}var s=h(e);switch(e){case bi:case si:case oi:case Ti:case li:case ji:case xi:case ki:case _i:case pi:return o(function(n){return mt.commandType(n,"boolean",e,t.commandStr),n},function(t,n,r){return mt.optional(function(){t.assert(n,"typeof "+r+'==="boolean"',"invalid flag "+e,t.commandStr)}),r});case di:return o(function(n){return mt.commandParameter(n,Ha,"invalid "+e,t.commandStr),Ha[n]},function(t,n,r){var i=t.constants.compareFuncs;return mt.optional(function(){t.assert(n,r+" in "+i,"invalid "+e+", must be one of "+Object.keys(Ha))}),n.def(i,"[",r,"]")});case mi:return o(function(e){return mt.command(he(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1]&&e[0]<=e[1],"depth range is 2d array",t.commandStr),e},function(e,t,n){return mt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===2&&typeof "+n+'[0]==="number"&&typeof '+n+'[1]==="number"&&'+n+"[0]<="+n+"[1]","depth range must be a 2d array")}),[t.def("+",n,"[0]"),t.def("+",n,"[1]")]});case ci:return o(function(e){mt.commandType(e,"object","blend.func",t.commandStr);var n="srcRGB"in e?e.srcRGB:e.src,r="srcAlpha"in e?e.srcAlpha:e.src,i="dstRGB"in e?e.dstRGB:e.dst,a="dstAlpha"in e?e.dstAlpha:e.dst;return mt.commandParameter(n,Ia,s+".srcRGB",t.commandStr),mt.commandParameter(r,Ia,s+".srcAlpha",t.commandStr),mt.commandParameter(i,Ia,s+".dstRGB",t.commandStr),mt.commandParameter(a,Ia,s+".dstAlpha",t.commandStr),mt.command(-1===Na.indexOf(n+", "+i),"unallowed blending combination (srcRGB, dstRGB) = ("+n+", "+i+")",t.commandStr),[Ia[n],Ia[i],Ia[r],Ia[a]]},function(t,n,r){function i(i,o){var s=n.def('"',i,o,'" in ',r,"?",r,".",i,o,":",r,".",i);return mt.optional(function(){t.assert(n,s+" in "+a,"invalid "+e+"."+i+o+", must be one of "+Object.keys(Ia))}),s}var a=t.constants.blendFuncs;mt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid blend func, must be an object")});var o=i("src","RGB"),s=i("dst","RGB");mt.optional(function(){var e=t.constants.invalidBlendCombinations;t.assert(n,e+".indexOf("+o+'+", "+'+s+") === -1 ","unallowed blending combination for (srcRGB, dstRGB)")});var f=n.def(a,"[",o,"]"),u=n.def(a,"[",i("src","Alpha"),"]");return[f,n.def(a,"[",s,"]"),u,n.def(a,"[",i("dst","Alpha"),"]")]});case ui:return o(function(n){return"string"==typeof n?(mt.commandParameter(n,Y,"invalid "+e,t.commandStr),[Y[n],Y[n]]):"object"==typeof n?(mt.commandParameter(n.rgb,Y,e+".rgb",t.commandStr),mt.commandParameter(n.alpha,Y,e+".alpha",t.commandStr),[Y[n.rgb],Y[n.alpha]]):void mt.commandRaise("invalid blend.equation",t.commandStr)},function(t,n,r){var i=t.constants.blendEquations,a=n.def(),o=n.def(),s=t.cond("typeof ",r,'==="string"');return mt.optional(function(){function n(e,n,r){t.assert(e,r+" in "+i,"invalid "+n+", must be one of "+Object.keys(Y))}n(s.then,e,r),t.assert(s.else,r+"&&typeof "+r+'==="object"',"invalid "+e),n(s.else,e+".rgb",r+".rgb"),n(s.else,e+".alpha",r+".alpha")}),s.then(a,"=",o,"=",i,"[",r,"];"),s.else(a,"=",i,"[",r,".rgb];",o,"=",i,"[",r,".alpha];"),n(s),[a,o]});case fi:return o(function(e){return mt.command(he(e)&&4===e.length,"blend.color must be a 4d array",t.commandStr),$(4,function(t){return+e[t]})},function(e,t,n){return mt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","blend.color must be a 4d array")}),$(4,function(e){return t.def("+",n,"[",e,"]")})});case Ai:return o(function(e){return mt.commandType(e,"number",s,t.commandStr),0|e},function(e,t,n){return mt.optional(function(){e.assert(t,"typeof "+n+'==="number"',"invalid stencil.mask")}),t.def(n,"|0")});case Oi:return o(function(n){mt.commandType(n,"object",s,t.commandStr);var r=n.cmp||"keep",i=n.ref||0,a="mask"in n?n.mask:-1;return mt.commandParameter(r,Ha,e+".cmp",t.commandStr),mt.commandType(i,"number",e+".ref",t.commandStr),mt.commandType(a,"number",e+".mask",t.commandStr),[Ha[r],i,a]},function(e,t,n){var r=e.constants.compareFuncs;return mt.optional(function(){function i(){e.assert(t,Array.prototype.join.call(arguments,""),"invalid stencil.func")}i(n+"&&typeof ",n,'==="object"'),i('!("cmp" in ',n,")||(",n,".cmp in ",r,")")}),[t.def('"cmp" in ',n,"?",r,"[",n,".cmp]",":",Wa),t.def(n,".ref|0"),t.def('"mask" in ',n,"?",n,".mask|0:-1")]});case Ci:case Ei:return o(function(n){mt.commandType(n,"object",s,t.commandStr);var r=n.fail||"keep",i=n.zfail||"keep",a=n.zpass||"keep";return mt.commandParameter(r,Va,e+".fail",t.commandStr),mt.commandParameter(i,Va,e+".zfail",t.commandStr),mt.commandParameter(a,Va,e+".zpass",t.commandStr),[e===Ei?Oa:Aa,Va[r],Va[i],Va[a]]},function(t,n,r){function i(i){return mt.optional(function(){t.assert(n,'!("'+i+'" in '+r+")||("+r+"."+i+" in "+a+")","invalid "+e+"."+i+", must be one of "+Object.keys(Va))}),n.def('"',i,'" in ',r,"?",a,"[",r,".",i,"]:",Wa)}var a=t.constants.stencilOps;return mt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)}),[e===Ei?Oa:Aa,i("fail"),i("zfail"),i("zpass")]});case wi:return o(function(e){mt.commandType(e,"object",s,t.commandStr);var n=0|e.factor,r=0|e.units;return mt.commandType(n,"number",s+".factor",t.commandStr),mt.commandType(r,"number",s+".units",t.commandStr),[n,r]},function(t,n,r){return mt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)}),[n.def(r,".factor|0"),n.def(r,".units|0")]});case gi:return o(function(e){var n=0;return"front"===e?n=Aa:"back"===e&&(n=Oa),mt.command(!!n,s,t.commandStr),n},function(e,t,n){return mt.optional(function(){e.assert(t,n+'==="front"||'+n+'==="back"',"invalid cull.face")}),t.def(n,'==="front"?',Aa,":",Oa)});case yi:return o(function(e){return mt.command("number"==typeof e&&e>=r.lineWidthDims[0]&&e<=r.lineWidthDims[1],"invalid line width, must positive number between "+r.lineWidthDims[0]+" and "+r.lineWidthDims[1],t.commandStr),e},function(e,t,n){return mt.optional(function(){e.assert(t,"typeof "+n+'==="number"&&'+n+">="+r.lineWidthDims[0]+"&&"+n+"<="+r.lineWidthDims[1],"invalid line width")}),n});case vi:return o(function(e){return mt.commandParameter(e,Ua,s,t.commandStr),Ua[e]},function(e,t,n){return mt.optional(function(){e.assert(t,n+'==="cw"||'+n+'==="ccw"',"invalid frontFace, must be one of cw,ccw")}),t.def(n+'==="cw"?'+Ca+":"+Ea)});case hi:return o(function(e){return mt.command(he(e)&&4===e.length,"color.mask must be length 4 array",t.commandStr),e.map(function(e){return!!e})},function(e,t,n){return mt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","invalid color.mask")}),$(4,function(e){return"!!"+n+"["+e+"]"})});case Si:return o(function(e){mt.command("object"==typeof e&&e,s,t.commandStr);var n="value"in e?e.value:1,r=!!e.invert;return mt.command("number"==typeof n&&n>=0&&n<=1,"sample.coverage.value must be a number between 0 and 1",t.commandStr),[n,r]},function(e,t,n){return mt.optional(function(){e.assert(t,n+"&&typeof "+n+'==="object"',"invalid sample.coverage")}),[t.def('"value" in ',n,"?+",n,".value:1"),t.def("!!",n,".invert")]})}}),a}function T(e,t){var n=e.static,r=e.dynamic,i={};return Object.keys(n).forEach(function(e){var r,a=n[e];if("number"==typeof a||"boolean"==typeof a)r=Ue(function(){return a});else if("function"==typeof a){var o=a._reglType;"texture2d"===o||"textureCube"===o?r=Ue(function(e){return e.link(a)}):"framebuffer"===o||"framebufferCube"===o?(mt.command(a.color.length>0,'missing color attachment for framebuffer sent to uniform "'+e+'"',t.commandStr),r=Ue(function(e){return e.link(a.color[0])})):mt.commandRaise('invalid data for uniform "'+e+'"',t.commandStr)}else he(a)?r=Ue(function(t){return t.global.def("[",$(a.length,function(n){return mt.command("number"==typeof a[n]||"boolean"==typeof a[n],"invalid uniform "+e,t.commandStr),a[n]}),"]")}):mt.commandRaise('invalid or missing data for uniform "'+e+'"',t.commandStr);r.value=a,i[e]=r}),Object.keys(r).forEach(function(e){var t=r[e];i[e]=qe(t,function(e,n){return e.invoke(n,t)})}),i}function A(e,n){var r=e.static,a=e.dynamic,o={};return Object.keys(r).forEach(function(e){var a=r[e],s=t.id(e),f=new X;if(Ne(a))f.state=Jr,f.buffer=i.getBuffer(i.create(a,Yi,!1,!0)),f.type=0;else{var u=i.getBuffer(a);if(u)f.state=Jr,f.buffer=u,f.type=0;else if(mt.command("object"==typeof a&&a,"invalid data for attribute "+e,n.commandStr),a.constant){var c=a.constant;f.buffer="null",f.state=ei,"number"==typeof c?f.x=c:(mt.command(he(c)&&c.length>0&&c.length<=4,"invalid constant for attribute "+e,n.commandStr),Kr.forEach(function(e,t){t=0,'invalid offset for attribute "'+e+'"',n.commandStr);var d=0|a.stride;mt.command(d>=0&&d<256,'invalid stride for attribute "'+e+'", must be integer betweeen [0, 255]',n.commandStr);var m=0|a.size;mt.command(!("size"in a)||m>0&&m<=4,'invalid size for attribute "'+e+'", must be 1,2,3,4',n.commandStr);var p=!!a.normalized,h=0;"type"in a&&(mt.commandParameter(a.type,Dt,"invalid type for attribute "+e,n.commandStr),h=Dt[a.type]);var b=0|a.divisor;"divisor"in a&&(mt.command(0===b||K,'cannot specify divisor for attribute "'+e+'", instancing not supported',n.commandStr),mt.command(b>=0,'invalid divisor for attribute "'+e+'"',n.commandStr)),mt.optional(function(){var t=n.commandStr,r=["buffer","offset","divisor","normalized","type","size","stride"];Object.keys(a).forEach(function(n){mt.command(r.indexOf(n)>=0,'unknown parameter "'+n+'" for attribute pointer "'+e+'" (valid parameters are '+r+")",t)})}),f.buffer=u,f.state=Jr,f.size=m,f.normalized=p,f.type=h||u.dtype,f.offset=l,f.stride=d,f.divisor=b}}o[e]=Ue(function(e,t){var n=e.attribCache;if(s in n)return n[s];var r={isStream:!1};return Object.keys(f).forEach(function(e){r[e]=f[e]}),f.buffer&&(r.buffer=e.link(f.buffer),r.type=r.type||r.buffer+".dtype"),n[s]=r,r})}),Object.keys(a).forEach(function(e){function t(t,r){function i(e){r(u[e],"=",a,".",e,"|0;")}var a=t.invoke(r,n),o=t.shared,s=o.isBufferArgs,f=o.buffer;mt.optional(function(){t.assert(r,a+"&&(typeof "+a+'==="object"||typeof '+a+'==="function")&&('+s+"("+a+")||"+f+".getBuffer("+a+")||"+f+".getBuffer("+a+".buffer)||"+s+"("+a+'.buffer)||("constant" in '+a+"&&(typeof "+a+'.constant==="number"||'+o.isArrayLike+"("+a+".constant))))",'invalid dynamic attribute "'+e+'"')});var u={isStream:r.def(!1)},c=new X;c.state=Jr,Object.keys(c).forEach(function(e){u[e]=r.def(""+c[e])});var l=u.buffer,d=u.type;return r("if(",s,"(",a,")){",u.isStream,"=true;",l,"=",f,".createStream(",Yi,",",a,");",d,"=",l,".dtype;","}else{",l,"=",f,".getBuffer(",a,");","if(",l,"){",d,"=",l,".dtype;",'}else if("constant" in ',a,"){",u.state,"=",ei,";","if(typeof "+a+'.constant === "number"){',u[Kr[0]],"=",a,".constant;",Kr.slice(1).map(function(e){return u[e]}).join("="),"=0;","}else{",Kr.map(function(e,t){return u[e]+"="+a+".constant.length>="+t+"?"+a+".constant["+t+"]:0;"}).join(""),"}}else{","if(",s,"(",a,".buffer)){",l,"=",f,".createStream(",Yi,",",a,".buffer);","}else{",l,"=",f,".getBuffer(",a,".buffer);","}",d,'="type" in ',a,"?",o.glTypes,"[",a,".type]:",l,".dtype;",u.normalized,"=!!",a,".normalized;"),i("size"),i("offset"),i("stride"),i("divisor"),r("}}"),r.exit("if(",u.isStream,"){",f,".destroyStream(",l,");","}"),u}var n=a[e];o[e]=qe(n,t)}),o}function O(e){var t=e.static,n=e.dynamic,r={};return Object.keys(t).forEach(function(e){var n=t[e];r[e]=Ue(function(e,t){return"number"==typeof n||"boolean"==typeof n?""+n:e.link(n)})}),Object.keys(n).forEach(function(e){var t=n[e];r[e]=qe(t,function(e,n){return e.invoke(n,t)})}),r}function C(e,t,n,r,i){function a(e){var t=u[e];t&&(l[e]=t)}var o=e.static,s=e.dynamic;mt.optional(function(){function e(e){Object.keys(e).forEach(function(e){mt.command(t.indexOf(e)>=0,'unknown parameter "'+e+'"',i.commandStr)})}var t=[Pi,zi,Bi,Ri,Fi,Ii,Li,Ni,Wi].concat(te);e(o),e(s)});var f=x(e,i),u=w(e,f,i),c=_(e,i),l=S(e,i),d=k(e,i);a(Mi),a(h(Di));var m=Object.keys(l).length>0,p={framebuffer:f,draw:c,shader:d,state:l,dirty:m};return p.profile=y(e,i),p.uniforms=T(n,i),p.attributes=A(t,i),p.context=O(r,i),p}function E(e,t,n){var r=e.shared.context,i=e.scope();Object.keys(n).forEach(function(a){t.save(r,"."+a);var o=n[a];i(r,".",a,"=",o.append(e,t),";")}),t(i)}function j(e,t,n,r){var i,a=e.shared,o=a.gl,s=a.framebuffer;Z&&(i=t.def(a.extensions,".webgl_draw_buffers"));var f,u=e.constants,c=u.drawBuffer,l=u.backBuffer;f=n?n.append(e,t):t.def(s,".next"),r||t("if(",f,"!==",s,".cur){"),t("if(",f,"){",o,".bindFramebuffer(",Fa,",",f,".framebuffer);"),Z&&t(i,".drawBuffersWEBGL(",c,"[",f,".colorAttachments.length]);"),t("}else{",o,".bindFramebuffer(",Fa,",null);"),Z&&t(i,".drawBuffersWEBGL(",l,");"),t("}",s,".cur=",f,";"),r||t("}")}function D(e,t,n){var r=e.shared,i=r.gl,a=e.current,o=e.next,s=r.current,f=r.next,u=e.cond(s,".dirty");te.forEach(function(t){var r=h(t);if(!(r in n.state)){var c,l;if(r in o){c=o[r],l=a[r];var d=$(J[r].length,function(e){return u.def(c,"[",e,"]")});u(e.cond(d.map(function(e,t){return e+"!=="+l+"["+t+"]"}).join("||")).then(i,".",re[r],"(",d,");",d.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";"))}else{c=u.def(f,".",r);var m=e.cond(c,"!==",s,".",r);u(m),r in ne?m(e.cond(c).then(i,".enable(",ne[r],");").else(i,".disable(",ne[r],");"),s,".",r,"=",c,";"):m(i,".",re[r],"(",c,");",s,".",r,"=",c,";")}}}),0===Object.keys(n.state).length&&u(s,".dirty=false;"),t(u)}function M(e,t,n,r){var i=e.shared,a=e.current,o=i.current,s=i.gl;He(Object.keys(n)).forEach(function(i){var f=n[i];if(!r||r(f)){var u=f.append(e,t);if(ne[i]){var c=ne[i];Ge(f)?u?t(s,".enable(",c,");"):t(s,".disable(",c,");"):t(e.cond(u).then(s,".enable(",c,");").else(s,".disable(",c,");")),t(o,".",i,"=",u,";")}else if(he(u)){var l=a[i];t(s,".",re[i],"(",u,");",u.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";")}else t(s,".",re[i],"(",u,");",o,".",i,"=",u,";")}})}function W(e,t){K&&(e.instancing=t.def(e.shared.extensions,".angle_instanced_arrays"))}function P(e,t,n,r,i){function a(){return"undefined"==typeof performance?"Date.now()":"performance.now()"}function o(e){e(u=t.def(),"=",a(),";"),"string"==typeof i?e(p,".count+=",i,";"):e(p,".count++;"),m&&(r?e(c=t.def(),"=",b,".getNumPendingQueries();"):e(b,".beginQuery(",p,");"))}function s(e){e(p,".cpuTime+=",a(),"-",u,";"),m&&(r?e(b,".pushScopeStats(",c,",",b,".getNumPendingQueries(),",p,");"):e(b,".endQuery();"))}function f(e){var n=t.def(h,".profile");t(h,".profile=",e,";"),t.exit(h,".profile=",n,";")}var u,c,l,d=e.shared,p=e.stats,h=d.current,b=d.timer,g=n.profile;if(g){if(Ge(g))return void(g.enable?(o(t),s(t.exit),f("true")):f("false"));f(l=g.append(e,t))}else l=t.def(h,".profile");var v=e.block();o(v),t("if(",l,"){",v,"}");var y=e.block();s(y),t.exit("if(",l,"){",y,"}")}function z(e,t,n,r,i){function a(e){switch(e){case ua:case ma:case ga:return 2;case ca:case pa:case va:return 3;case la:case ha:case ya:return 4;default:return 1}}function o(n,r,i){function a(){t("if(!",c,".buffer){",f,".enableVertexAttribArray(",u,");}");var n,a=i.type;if(n=i.size?t.def(i.size,"||",r):r,t("if(",c,".type!==",a,"||",c,".size!==",n,"||",p.map(function(e){return c+"."+e+"!=="+i[e]}).join("||"),"){",f,".bindBuffer(",Yi,",",d,".buffer);",f,".vertexAttribPointer(",[u,n,a,i.normalized,i.stride,i.offset],");",c,".type=",a,";",c,".size=",n,";",p.map(function(e){return c+"."+e+"="+i[e]+";"}).join(""),"}"),K){var o=i.divisor;t("if(",c,".divisor!==",o,"){",e.instancing,".vertexAttribDivisorANGLE(",[u,o],");",c,".divisor=",o,";}")}}function o(){t("if(",c,".buffer){",f,".disableVertexAttribArray(",u,");","}if(",Kr.map(function(e,t){return c+"."+e+"!=="+m[t]}).join("||"),"){",f,".vertexAttrib4f(",u,",",m,");",Kr.map(function(e,t){return c+"."+e+"="+m[t]+";"}).join(""),"}")}var f=s.gl,u=t.def(n,".location"),c=t.def(s.attributes,"[",u,"]"),l=i.state,d=i.buffer,m=[i.x,i.y,i.z,i.w],p=["buffer","normalized","offset","stride"];l===Jr?a():l===ei?o():(t("if(",l,"===",Jr,"){"),a(),t("}else{"),o(),t("}"))}var s=e.shared;r.forEach(function(r){var s,f=r.name,u=n.attributes[f];if(u){if(!i(u))return;s=u.append(e,t)}else{if(!i(qa))return;var c=e.scopeAttrib(f);mt.optional(function(){e.assert(t,c+".state","missing attribute "+f)}),s={},Object.keys(new X).forEach(function(e){s[e]=t.def(c,".",e)})}o(e.link(r),a(r.info.type),s)})}function B(e,n,r,i,a){for(var o,s=e.shared,f=s.gl,u=0;u1?$(x,function(e){return c+"["+e+"]"}):c);n(");")}}function R(e,t,n,r){function i(i){var a=c[i];return a?a.contextDep&&r.contextDynamic||a.propDep?a.append(e,n):a.append(e,t):t.def(u,".",i)}function a(){function e(){n(b,".drawElementsInstancedANGLE(",[d,p,g,m+"<<(("+g+"-"+Zr+")>>1)",h],");")}function t(){n(b,".drawArraysInstancedANGLE(",[d,m,p,h],");")}l?v?e():(n("if(",l,"){"),e(),n("}else{"),t(),n("}")):t()}function o(){function e(){n(f+".drawElements("+[d,p,g,m+"<<(("+g+"-"+Zr+")>>1)"]+");")}function t(){n(f+".drawArrays("+[d,m,p]+");")}l?v?e():(n("if(",l,"){"),e(),n("}else{"),t(),n("}")):t()}var s=e.shared,f=s.gl,u=s.draw,c=r.draw,l=function(){var i,a=c.elements,o=t;return a?((a.contextDep&&r.contextDynamic||a.propDep)&&(o=n),i=a.append(e,o)):i=o.def(u,".",Ri),i&&o("if("+i+")"+f+".bindBuffer("+$i+","+i+".buffer.buffer);"),i}(),d=i(Fi),m=i(Ii),p=function(){var i,a=c.count,o=t;return a?((a.contextDep&&r.contextDynamic||a.propDep)&&(o=n),i=a.append(e,o),mt.optional(function(){a.MISSING&&e.assert(t,"false","missing vertex count"),a.DYNAMIC&&e.assert(o,i+">=0","missing vertex count")})):(i=o.def(u,".",Li),mt.optional(function(){e.assert(o,i+">=0","missing vertex count")})),i}();if("number"==typeof p){if(0===p)return}else n("if(",p,"){"),n.exit("}");var h,b;K&&(h=i(Ni),b=e.instancing);var g=l+".type",v=c.elements&&Ge(c.elements);K&&("number"!=typeof h||h>=0)?"string"==typeof h?(n("if(",h,">0){"),a(),n("}else if(",h,"<0){"),o(),n("}")):a():o()}function F(e,t,n,r,i){var a=v(),o=a.proc("body",i);return mt.optional(function(){a.commandStr=t.commandStr,a.command=a.link(t.commandStr)}),K&&(a.instancing=o.def(a.shared.extensions,".angle_instanced_arrays")),e(a,o,n,r),a.compile().body}function L(e,t,n,r){W(e,t),z(e,t,n,r.attributes,function(){return!0}),B(e,t,n,r.uniforms,function(){return!0}),R(e,t,t,n)}function I(e,t){var n=e.proc("draw",1);W(e,n),E(e,n,t.context),j(e,n,t.framebuffer),D(e,n,t),M(e,n,t.state),P(e,n,t,!1,!0);var r=t.shader.progVar.append(e,n);if(n(e.shared.gl,".useProgram(",r,".program);"),t.shader.program)L(e,n,t,t.shader.program);else{var i=e.global.def("{}"),a=n.def(r,".id"),o=n.def(i,"[",a,"]");n(e.cond(o).then(o,".call(this,a0);").else(o,"=",i,"[",a,"]=",e.link(function(n){return F(L,e,t,n,1)}),"(",r,");",o,".call(this,a0);"))}Object.keys(t.state).length>0&&n(e.shared.current,".dirty=true;")}function N(e,t,n,r){function i(){return!0}e.batchId="a1",W(e,t),z(e,t,n,r.attributes,i),B(e,t,n,r.uniforms,i),R(e,t,t,n)}function H(e,t,n,r){function i(e){return e.contextDep&&o||e.propDep}function a(e){return!i(e)}W(e,t);var o=n.contextDep,s=t.def(),f=t.def();e.shared.props=f,e.batchId=s;var u=e.scope(),c=e.scope();if(t(u.entry,"for(",s,"=0;",s,"<","a1",";++",s,"){",f,"=","a0","[",s,"];",c,"}",u.exit),n.needsContext&&E(e,c,n.context),n.needsFramebuffer&&j(e,c,n.framebuffer),M(e,c,n.state,i),n.profile&&i(n.profile)&&P(e,c,n,!1,!0),r)z(e,u,n,r.attributes,a),z(e,c,n,r.attributes,i),B(e,u,n,r.uniforms,a),B(e,c,n,r.uniforms,i),R(e,u,c,n);else{var l=e.global.def("{}"),d=n.shader.progVar.append(e,c),m=c.def(d,".id"),p=c.def(l,"[",m,"]");c(e.shared.gl,".useProgram(",d,".program);","if(!",p,"){",p,"=",l,"[",m,"]=",e.link(function(t){return F(N,e,n,t,2)}),"(",d,");}",p,".call(this,a0[",s,"],",s,");")}}function V(e,t){function n(e){return e.contextDep&&i||e.propDep}var r=e.proc("batch",2);e.batchId="0",W(e,r);var i=!1,a=!0;Object.keys(t.context).forEach(function(e){i=i||t.context[e].propDep}),i||(E(e,r,t.context),a=!1);var o=t.framebuffer,s=!1;o?(o.propDep?i=s=!0:o.contextDep&&i&&(s=!0),s||j(e,r,o)):j(e,r,null),t.state.viewport&&t.state.viewport.propDep&&(i=!0),D(e,r,t),M(e,r,t.state,function(e){return!n(e)}),t.profile&&n(t.profile)||P(e,r,t,!1,"a1"),t.contextDep=i,t.needsContext=a,t.needsFramebuffer=s;var f=t.shader.progVar;if(f.contextDep&&i||f.propDep)H(e,r,t,null);else{var u=f.append(e,r);if(r(e.shared.gl,".useProgram(",u,".program);"),t.shader.program)H(e,r,t,t.shader.program);else{var c=e.global.def("{}"),l=r.def(u,".id"),d=r.def(c,"[",l,"]");r(e.cond(d).then(d,".call(this,a0,a1);").else(d,"=",c,"[",l,"]=",e.link(function(n){return F(H,e,t,n,2)}),"(",u,");",d,".call(this,a0,a1);"))}}Object.keys(t.state).length>0&&r(e.shared.current,".dirty=true;")}function G(e,n){function r(t){var r=n.shader[t];r&&i.set(a.shader,"."+t,r.append(e,i))}var i=e.proc("scope",3);e.batchId="a2";var a=e.shared,o=a.current;E(e,i,n.context),n.framebuffer&&n.framebuffer.append(e,i),He(Object.keys(n.state)).forEach(function(t){var r=n.state[t].append(e,i);he(r)?r.forEach(function(n,r){i.set(e.next[t],"["+r+"]",n)}):i.set(a.next,"."+t,r)}),P(e,i,n,!0,!0),[Ri,Ii,Li,Ni,Fi].forEach(function(t){var r=n.draw[t];r&&i.set(a.draw,"."+t,""+r.append(e,i))}),Object.keys(n.uniforms).forEach(function(r){i.set(a.uniforms,"["+t.id(r)+"]",n.uniforms[r].append(e,i))}),Object.keys(n.attributes).forEach(function(t){var r=n.attributes[t].append(e,i),a=e.scopeAttrib(t);Object.keys(new X).forEach(function(e){i.set(a,"."+e,r[e])})}),r(zi),r(Bi),Object.keys(n.state).length>0&&(i(o,".dirty=true;"),i.exit(o,".dirty=true;")),i("a1(",e.shared.context,",a0,",e.batchId,");")}function U(e){if("object"==typeof e&&!he(e)){for(var t=Object.keys(e),n=0;n=0;--e){var n=G[e];n&&n(C,null,0)}g.flush(),S&&S.update()}function n(){!$&&G.length>0&&($=gt.next(t))}function r(){$&&(gt.cancel(t),$=null)}function i(e){e.preventDefault(),y=!0,r(),U.forEach(function(e){e()})}function a(e){g.getError(),y=!1,x.restore(),z.restore(),M.restore(),B.restore(),R.restore(),F.restore(),S&&S.restore(),L.procs.refresh(),n(),q.forEach(function(e){e()})}function o(){G.length=0,r(),V&&(V.removeEventListener(to,i),V.removeEventListener(no,a)),z.clear(),F.clear(),R.clear(),B.clear(),W.clear(),M.clear(),S&&S.clear(),Y.forEach(function(e){e()})}function s(e){function t(e){var t={},n={};return Object.keys(e).forEach(function(r){var i=e[r];bt.isDynamic(i)?n[r]=bt.unbox(i,r):t[r]=i}),{dynamic:n,static:t}}function n(e){for(;m.length0)return l.call(this,n(0|e),0|e)}else{if(!Array.isArray(e))return c.call(this,e);if(e.length)return l.call(this,e,e.length)}}mt(!!e,"invalid args to regl({...})"),mt.type(e,"object","invalid args to regl({...})");var i=t(e.context||{}),a=t(e.uniforms||{}),o=t(e.attributes||{}),s=t(function(e){function t(e){if(e in n){var t=n[e];delete n[e],Object.keys(t).forEach(function(r){n[e+"."+r]=t[r]})}}var n=Je({},e);return delete n.uniforms,delete n.attributes,delete n.context,"stencil"in n&&n.stencil.op&&(n.stencil.opBack=n.stencil.opFront=n.stencil.op,delete n.stencil.op),t("blend"),t("depth"),t("cull"),t("stencil"),t("polygonOffset"),t("scissor"),t("sample"),n}(e)),f={gpuTime:0,cpuTime:0,count:0},u=L.compile(s,o,a,i,f),c=u.draw,l=u.batch,d=u.scope,m=[];return Je(r,{stats:f})}function f(e,t){var n=0;L.procs.poll();var r=t.color;r&&(g.clearColor(+r[0]||0,+r[1]||0,+r[2]||0,+r[3]||0),n|=Ka),"depth"in t&&(g.clearDepth(+t.depth),n|=Za),"stencil"in t&&(g.clearStencil(0|t.stencil),n|=Ja),mt(!!n,"called regl.clear with no buffer specified"),g.clear(n)}function u(e){if(mt("object"==typeof e&&e,"regl.clear() takes an object as input"),"framebuffer"in e)if(e.framebuffer&&"framebufferCube"===e.framebuffer_reglType)for(var t=0;t<6;++t)K(Je({framebuffer:e.framebuffer.faces[t]},e),f);else K(e,f);else f(null,e)}function c(e){function t(){function t(){var e=Ye(G,t);G[e]=G[G.length-1],G.length-=1,G.length<=0&&r()}var n=Ye(G,e);mt(n>=0,"cannot cancel a frame twice"),G[n]=t}return mt.type(e,"function","regl.frame() callback must be a function"),G.push(e),n(),{cancel:t}}function l(){var e=H.viewport,t=H.scissor_box;e[0]=e[1]=t[0]=t[1]=0,C.viewportWidth=C.framebufferWidth=C.drawingBufferWidth=e[2]=t[2]=g.drawingBufferWidth,C.viewportHeight=C.framebufferHeight=C.drawingBufferHeight=e[3]=t[3]=g.drawingBufferHeight}function d(){C.tick+=1,C.time=p(),l(),L.procs.poll()}function m(){l(),L.procs.refresh(),S&&S.update()}function p(){return(vt()-T)/1e3}function h(e,t){mt.type(t,"function","listener callback must be a function");var n;switch(e){case"frame":return c(t);case"lost":n=U;break;case"restore":n=q;break;case"destroy":n=Y;break;default:mt.raise("invalid event, must be one of frame,lost,restore,destroy")}return n.push(t),{cancel:function(){for(var e=0;e=0},read:N,destroy:o,_gl:g,_refresh:m,poll:function(){d(),S&&S.update()},now:p,stats:k});return b.onDone(null,Z),Z}var Ke={"[object Int8Array]":5120,"[object Int16Array]":5122,"[object Int32Array]":5124,"[object Uint8Array]":5121,"[object Uint8ClampedArray]":5121,"[object Uint16Array]":5123,"[object Uint32Array]":5125,"[object Float32Array]":5126,"[object Float64Array]":5121,"[object ArrayBuffer]":5121},Ze=function(e){return Object.prototype.toString.call(e)in Ke},Je=function(e,t){for(var n=Object.keys(t),r=0;r=2,"invalid renderbuffer shape"),a=0|m[0],o=0|m[1]}else"radius"in d&&(a=o=0|d.radius),"width"in d&&(a=0|d.width),"height"in d&&(o=0|d.height);"format"in d&&(mt.parameter(d.format,u,"invalid renderbuffer format"),f=u[d.format])}else"number"==typeof t?(a=0|t,o="number"==typeof r?0|r:a):t?mt.raise("invalid arguments to renderbuffer constructor"):a=o=1;if(mt(a>0&&o>0&&a<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),a!==l.width||o!==l.height||f!==l.format)return s.width=l.width=a,s.height=l.height=o,l.format=f,e.bindRenderbuffer(xr,l.renderbuffer),e.renderbufferStorage(xr,f,a,o),i.profile&&(l.stats.size=Me(l.format,l.width,l.height)),s.format=c[l.format],s}function f(t,r){var a=0|t,o=0|r||a;return a===l.width&&o===l.height?s:(mt(a>0&&o>0&&a<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),s.width=l.width=a,s.height=l.height=o,e.bindRenderbuffer(xr,l.renderbuffer),e.renderbufferStorage(xr,l.format,a,o),i.profile&&(l.stats.size=Me(l.format,l.width,l.height)),s)}var l=new a(e.createRenderbuffer());return d[l.id]=l,r.renderbufferCount++,s(t,o),s.resize=f,s._reglType="renderbuffer",s._renderbuffer=l,i.profile&&(s.stats=l.stats),s.destroy=function(){l.decRef()},s}function f(){xt(d).forEach(function(t){t.renderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(xr,t.renderbuffer),e.renderbufferStorage(xr,t.format,t.width,t.height)}),e.bindRenderbuffer(xr,null)}var u={rgba4:wr,rgb565:36194,"rgb5 a1":32855,depth:33189,stencil:36168,"depth stencil":34041};t.ext_srgb&&(u.srgba=35907),t.ext_color_buffer_half_float&&(u.rgba16f=34842,u.rgb16f=34843),t.webgl_color_buffer_float&&(u.rgba32f=34836);var c=[];Object.keys(u).forEach(function(e){var t=u[e];c[t]=e});var l=0,d={};return a.prototype.decRef=function(){--this.refCount<=0&&o(this)},i.profile&&(r.getTotalRenderbufferSize=function(){var e=0;return Object.keys(d).forEach(function(t){e+=d[t].stats.size}),e}),{create:s,clear:function(){xt(d).forEach(o)},restore:f}},Sr=36160,Tr=36161,Ar=3553,Or=34069,Cr=36064,Er=36096,jr=36128,Dr=33306,Mr=36053,Wr=6402,Pr=[6408],zr=[];zr[6408]=4;var Br=[];Br[5121]=1,Br[5126]=4,Br[36193]=2;var Rr=33189,Fr=36168,Lr=34041,Ir=[32854,32855,36194,35907,34842,34843,34836],Nr={};Nr[Mr]="complete",Nr[36054]="incomplete attachment",Nr[36057]="incomplete dimensions",Nr[36055]="incomplete, missing attachment",Nr[36061]="unsupported";var Hr=5126,Vr=35632,Gr=35633,Ur=35718,qr=35721,Qr=6408,Xr=5121,Yr=3333,$r=5126,Kr="xyzw".split(""),Zr=5121,Jr=1,ei=2,ti=0,ni=1,ri=2,ii=3,ai=4,oi="dither",si="blend.enable",fi="blend.color",ui="blend.equation",ci="blend.func",li="depth.enable",di="depth.func",mi="depth.range",pi="depth.mask",hi="colorMask",bi="cull.enable",gi="cull.face",vi="frontFace",yi="lineWidth",xi="polygonOffset.enable",wi="polygonOffset.offset",ki="sample.alpha",_i="sample.enable",Si="sample.coverage",Ti="stencil.enable",Ai="stencil.mask",Oi="stencil.func",Ci="stencil.opFront",Ei="stencil.opBack",ji="scissor.enable",Di="scissor.box",Mi="viewport",Wi="profile",Pi="framebuffer",zi="vert",Bi="frag",Ri="elements",Fi="primitive",Li="count",Ii="offset",Ni="instances",Hi=Pi+"Width",Vi=Pi+"Height",Gi=Mi+"Width",Ui=Mi+"Height",qi="drawingBufferWidth",Qi="drawingBufferHeight",Xi=[ci,ui,Oi,Ci,Ei,Si,Mi,Di,wi],Yi=34962,$i=34963,Ki=3553,Zi=34067,Ji=2884,ea=3042,ta=3024,na=2960,ra=2929,ia=3089,aa=32823,oa=32926,sa=32928,fa=5126,ua=35664,ca=35665,la=35666,da=5124,ma=35667,pa=35668,ha=35669,ba=35670,ga=35671,va=35672,ya=35673,xa=35674,wa=35675,ka=35676,_a=35678,Sa=35680,Ta=4,Aa=1028,Oa=1029,Ca=2304,Ea=2305,ja=32775,Da=32776,Ma=519,Wa=7680,Pa=0,za=1,Ba=32774,Ra=513,Fa=36160,La=36064,Ia={0:0,1:1,zero:0,one:1,"src color":768,"one minus src color":769,"src alpha":770,"one minus src alpha":771,"dst color":774,"one minus dst color":775,"dst alpha":772,"one minus dst alpha":773,"constant color":32769,"one minus constant color":32770,"constant alpha":32771,"one minus constant alpha":32772,"src alpha saturate":776},Na=["constant color, constant alpha","one minus constant color, constant alpha","constant color, one minus constant alpha","one minus constant color, one minus constant alpha","constant alpha, constant color","constant alpha, one minus constant color","one minus constant alpha, constant color","one minus constant alpha, one minus constant color"],Ha={never:512,less:513,"<":513,equal:514,"=":514,"==":514,"===":514,lequal:515,"<=":515,greater:516,">":516,notequal:517,"!=":517,"!==":517,gequal:518,">=":518,always:519},Va={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment wrap":34055,"decrement wrap":34056,invert:5386},Ga={frag:35632,vert:35633},Ua={cw:Ca,ccw:Ea},qa=new Ve(!1,!1,!1,function(){}),Qa=34918,Xa=34919,Ya=35007,$a=function(e,t){function n(){return d.pop()||l.createQueryEXT()}function r(e){d.push(e)}function i(e){var t=n();l.beginQueryEXT(Ya,t),m.push(t),u(m.length-1,m.length,e)}function a(){l.endQueryEXT(Ya)}function o(){this.startQueryIndex=-1,this.endQueryIndex=-1,this.sum=0,this.stats=null}function s(){return p.pop()||new o}function f(e){p.push(e)}function u(e,t,n){var r=s();r.startQueryIndex=e,r.endQueryIndex=t,r.sum=0,r.stats=n,h.push(r)}function c(){var e,t,n=m.length;if(0!==n){g.length=Math.max(g.length,n+1),b.length=Math.max(b.length,n+1),b[0]=0,g[0]=0;var i=0;for(e=0,t=0;t=this.layers.length;)this.layers.push([]);const i={node:t,start:this.duration,end:this.duration+n,parent:r,children:[]};return this.layers[e].push(i),r&&r.children.push(i),i}appendSample(e,t){let n=null;for(let r=0;r0?t[t.length-1]:null;e&&qt.shouldMergeFrames(e,n)?(t.pop(),t.push(qt.mergeFrames(e,n))):t.push(n)}return t}selectFrameColors(e){function t(e){return(e.file||"").split("/").concat(e.name.split(/\W/))}function n(e,n){const r=t(e),i=t(n),a=Math.min(r.length,i.length);Math.max(r.length,i.length);let o=0;for(let e=0;ei.join()?s:-s}const r=[];this.profile.forEachFrame(e=>r.push(e)),r.sort(n);const i=[];let a=0;for(let e=0;e{e?(this.canvas=e,this.ctx=this.canvas.getContext("webgl"),this.renderCanvas()):this.canvas=null}),this.overlayCanvasRef=(e=>{e?(this.overlayCanvas=e,this.overlayCtx=this.overlayCanvas.getContext("2d"),this.renderCanvas()):(this.overlayCanvas=null,this.overlayCtx=null)}),this.LOGICAL_VIEW_SPACE_FRAME_HEIGHT=16,this.LOGICAL_VIEW_SPACE_LABEL_FONT_SIZE=12,this.renderCanvas=re(()=>{!this.canvas||this.canvas.getBoundingClientRect().width<2?requestAnimationFrame(()=>this.renderCanvas()):(this.renderer||this.preprocess(this.props.flamechart),this.renderRects(),this.renderLabels())}),this.lastDragPos=null,this.onMouseDown=(e=>{this.lastDragPos=new Nt(e.offsetX,e.offsetY)}),this.onMouseDrag=(e=>{if(!this.lastDragPos)return;const t=new Nt(e.offsetX,e.offsetY);this.pan(this.lastDragPos.minus(t));this.lastDragPos=t}),this.onMouseMove=(e=>{if(this.lastDragPos)return e.preventDefault(),void this.onMouseDrag(e);this.hoveredLabel=null;const t=new Nt(e.offsetX,e.offsetY);const n=this.logicalToPhysicalViewSpace().transformPosition(t);const r=this.configSpaceToPhysicalViewSpace().inverseTransformPosition(n);if(!r)return;for(let e of this.labels)if(e.configSpaceBounds.contains(r)){this.hoveredLabel=e;break}this.props.setNodeHover(this.hoveredLabel?this.hoveredLabel.node:null,t);this.renderCanvas()}),this.onWheel=(e=>{e.preventDefault();if(e.metaKey||e.ctrlKey){let t=1+e.deltaY/100;e.ctrlKey&&(t=1+e.deltaY/40),this.zoom(new Nt(e.offsetX,e.offsetY),t)}else this.pan(new Nt(e.deltaX,e.deltaY)),this.hoveredLabel=null,this.props.setNodeHover(null,new Nt);this.renderCanvas()}),this.onWindowMouseUp=(e=>{this.lastDragPos=null})}preprocess(e){if(this.canvas&&this.ctx){const t=[],n=[],r=e.getLayers(),i=(e.getDuration(),r.length,e.getFrameColors());this.labels=[];for(let e=0;e{this.setState({hoveredNode:e,logicalSpaceMouse:t})}),this.containerRef=(e=>{this.container=e}),this.state={hoveredNode:null,logicalSpaceMouse:new Nt}}formatTime(e){const t=this.props.flamechart.getDuration();return`${(e/1e3).toFixed(2)}ms (${(100*e/t).toFixed()}%)`}renderTooltip(){if(!this.container)return null;const{hoveredNode:hoveredNode,logicalSpaceMouse:logicalSpaceMouse}=this.state;if(!hoveredNode)return null;const{width:width,height:height}=this.container.getBoundingClientRect(),e={};return logicalSpaceMouse.x+7+Kt.TOOLTIP_WIDTH_MAX{const r=[];const i=[];const a=(e,t)=>{function n(e){r.push(e.flatten()),i.push(t)}n(e.topLeft());n(e.bottomLeft());n(e.topRight());n(e.bottomLeft());n(e.topRight());n(e.bottomRight())};for(let e=0;et.configSpaceToNDC.flatten(),physicalSize:(e,t)=>t.physicalSize.flatten()},primitive:"triangles",count:i.length})};class en extends O{constructor(){super(...arguments),this.onDrop=(e=>{const t=new FileReader;t.addEventListener("loadend",()=>{const e=te(t.result);const n=new qt(e);this.setState({profile:e,flamechart:n})});t.readAsText(e.dataTransfer.files.item(0));e.preventDefault()}),this.onDragOver=(e=>{e.preventDefault()})}componentDidMount(){window.addEventListener("resize",()=>{this.forceUpdate()})}render(){const{flamechart:flamechart}=this.state;return t("div",{onDrop:this.onDrop,onDragOver:this.onDragOver,className:zt(tn.root)},flamechart&&t(Kt,{flamechart:flamechart}))}}const tn=Pt.create({root:{width:"100vw",height:"100vh",overflow:"hidden"}});!function(e,t,n){p(n,e,{},!1,t,!1)}(t(en,null),document.body)}();