From 355ceb8c6c76833bfed5825827603d8879132b68 Mon Sep 17 00:00:00 2001 From: Jamie Wong Date: Thu, 14 Dec 2017 00:30:25 -0800 Subject: [PATCH] Switch to browserify for better iteration time --- .gitignore | 1 - aphrodite.d.ts | 73 +++++++++++++ dist/speedscope.js | 2 +- flamechart.tsx | 24 ++--- index.html | 45 +------- index.tsx | 6 +- package.json | 23 ++-- profile.ts | 3 + regl.d.ts | 32 +++--- dev.html => reset.css | 21 +--- rollup.config.common.js | 42 -------- rollup.config.dev.js | 2 - rollup.config.release.js | 2 - serveit | 227 --------------------------------------- tsconfig.json | 1 + 15 files changed, 117 insertions(+), 387 deletions(-) create mode 100644 aphrodite.d.ts rename dev.html => reset.css (73%) delete mode 100644 rollup.config.common.js delete mode 100644 rollup.config.dev.js delete mode 100644 rollup.config.release.js delete mode 100755 serveit diff --git a/.gitignore b/.gitignore index 6ad08ca..3c3629e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ node_modules -dist/speedscope-dev.js diff --git a/aphrodite.d.ts b/aphrodite.d.ts new file mode 100644 index 0000000..d7f3a01 --- /dev/null +++ b/aphrodite.d.ts @@ -0,0 +1,73 @@ +// Type definitions for Aphrodite 0.5.0 +// Project: https://github.com/Khan/aphrodite +// Definitions by: Alexey Svetliakov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +declare module 'aphrodite' { +// Modified to remove dependency on 'react' + +/** + * Aphrodite style declaration + */ +export interface StyleDeclaration { + [key: string]: any +} + +interface StyleSheetStatic { + /** + * Create style sheet + */ + create(styles: T): T; + /** + * Rehydrate class names from server renderer + */ + rehydrate(renderedClassNames: string[]): void; +} + +export var StyleSheet: StyleSheetStatic; +/** + * Get class names from passed styles + */ +export function css(...styles: any[]): string; + +interface StaticRendererResult { + html: string; + css: { + content: string; + renderedClassNames: string[]; + } +} + +/** + * Utilities for using Aphrodite server-side. + */ +interface StyleSheetServerStatic { + renderStatic(renderFunc: () => string): StaticRendererResult; +} + +export var StyleSheetServer: StyleSheetServerStatic; + +interface StyleSheetTestUtilsStatic { + /** + * Prevent styles from being injected into the DOM. + * + * This is useful in situations where you'd like to test rendering UI + * components which use Aphrodite without any of the side-effects of + * Aphrodite happening. Particularly useful for testing the output of + * components when you have no DOM, e.g. testing in Node without a fake DOM. + * + * Should be paired with a subsequent call to + * clearBufferAndResumeStyleInjection. + */ + suppressStyleInjection(): void; + /** + * Opposite method of preventStyleInject. + */ + clearBufferAndResumeStyleInjection(): void; +} + +export var StyleSheetTestUtils: StyleSheetTestUtilsStatic; + + +} \ No newline at end of file diff --git a/dist/speedscope.js b/dist/speedscope.js index 4d9d334..3a23c9d 100644 --- a/dist/speedscope.js +++ b/dist/speedscope.js @@ -1 +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)}(); +!function e(t,n,r){function i(o,s){if(!n[o]){if(!t[o]){var f="function"==typeof require&&require;if(!s&&f)return f(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){var n=t[o][1][e];return i(n||e)},c,c.exports,e,t,n,r)}return n[o].exports}for(var a="function"==typeof require&&require,o=0;or&&(t=a)}}(0,t.length,n=>i(e,r(t,n)),n);return r(t,a)}Object.defineProperty(n,"__esModule",{value:!0});const o=e("preact"),s=e("aphrodite"),f=e("regl"),u=e("./math"),c=e("./utils");var l;(l||(l={})).MONOSPACE="Courier, monospace";var d;!function(e){e[e.LABEL=12]="LABEL"}(d||(d={}));class p{constructor(e){this.profile=e,this.layers=[],this.duration=0,this.frameColors=new Map,e.forEachSample(this.appendSample.bind(this)),this.layers=this.layers.map(p.mergeAdjacentFrames),this.selectFrameColors(e)}getDuration(){return this.duration}getLayers(){return this.layers}getFrameColors(){return this.frameColors}appendFrame(e,t,n,r){for(;e>=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&&p.shouldMergeFrames(e,n)?(t.pop(),t.push(p.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);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.renderCanvas=c.atMostOnceAFrame(()=>{!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 u.Vec2(e.offsetX,e.offsetY)}),this.onMouseDrag=(e=>{if(!this.lastDragPos)return;const t=new u.Vec2(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 u.Vec2(e.offsetX,e.offsetY),n=this.logicalToPhysicalViewSpace().transformPosition(t),r=this.configSpaceToPhysicalViewSpace().inverseTransformPosition(n);if(r){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=>{if(e.preventDefault(),e.metaKey||e.ctrlKey){let t=1+e.deltaY/100;e.ctrlKey&&(t=1+e.deltaY/40),this.zoom(new u.Vec2(e.offsetX,e.offsetY),t)}else this.pan(new u.Vec2(e.deltaX,e.deltaY)),this.hoveredLabel=null,this.props.setNodeHover(null,new u.Vec2);this.renderCanvas()}),this.onWindowMouseUp=(e=>{this.lastDragPos=null})}preprocess(e){if(!this.canvas||!this.ctx)return;const t=[],r=[],i=e.getLayers(),a=e.getFrameColors();this.labels=[];for(let e=0;e{this.setState({hoveredNode:e,logicalSpaceMouse:t})}),this.containerRef=(e=>{this.container=e||null}),this.state={hoveredNode:null,logicalSpaceMouse:new u.Vec2}}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:e,logicalSpaceMouse:t}=this.state;if(!e)return null;const{width:n,height:r}=this.container.getBoundingClientRect(),i={};return t.x+7+v.TOOLTIP_WIDTH_MAX{const r=[],i=[],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})})},{"./math":4,"./utils":40,aphrodite:7,preact:35,regl:37}],2:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});const r=e("../profile");n.importFromBGFlameGraph=function(e){const t=function(e){const t=[];return e.replace(/^(.*) (\d+)$/gm,(e,n,r)=>(t.push({stack:n.split(";").map(e=>({key:e,name:e})),duration:parseInt(r,10)}),e)),t}(e),n=t.reduce((e,t)=>e+t.duration,0),i=new r.Profile(n);for(let e of t)i.appendSample(e.stack,e.duration);return i}},{"../profile":39}],3:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});const r=e("preact"),i=e("aphrodite"),a=e("./import/bg-flamegraph"),o=e("./flamechart");const s=i.StyleSheet.create({root:{width:"100vw",height:"100vh",overflow:"hidden"}});r.render(r.h(class extends r.Component{constructor(){super(...arguments),this.onDrop=(e=>{const t=new FileReader;t.addEventListener("loadend",()=>{const e=a.importFromBGFlameGraph(t.result),n=new o.Flamechart(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:e}=this.state;return r.h("div",{onDrop:this.onDrop,onDragOver:this.onDragOver,className:i.css(s.root)},e&&r.h(o.FlamechartView,{flamechart:e}))}},null),document.body)},{"./flamechart":1,"./import/bg-flamegraph":2,aphrodite:7,preact:35}],4:[function(e,t,n){"use strict";function r(e,t,n){return en?n:e}Object.defineProperty(n,"__esModule",{value:!0}),n.clamp=r;class i{constructor(e=0,t=0){this.x=e,this.y=t}withX(e){return new i(e,this.y)}withY(e){return new i(this.x,e)}plus(e){return new i(this.x+e.x,this.y+e.y)}minus(e){return new i(this.x-e.x,this.y-e.y)}times(e){return new i(this.x*e,this.y*e)}timesPointwise(e){return new i(this.x*e.x,this.y*e.y)}dot(e){return this.x*e.x+this.y*e.y}length2(){return this.dot(this)}length(){return Math.sqrt(this.length2())}static min(e,t){return new i(Math.min(e.x,t.x),Math.min(e.y,t.y))}static max(e,t){return new i(Math.max(e.x,t.x),Math.max(e.y,t.y))}flatten(){return[this.x,this.y]}}n.Vec2=i;class a{constructor(e=1,t=0,n=0,r=0,i=1,a=0){this.m00=e,this.m01=t,this.m02=n,this.m10=r,this.m11=i,this.m12=a}withScale(e){let{m00:t,m01:n,m02:r,m10:i,m11:o,m12:s}=this;return t=e.x,o=e.y,new a(t,n,r,i,o,s)}static withScale(e){return(new a).withScale(e)}scaledBy(e){return a.withScale(e).times(this)}getScale(){return new i(this.m00,this.m11)}withTranslation(e){let{m00:t,m01:n,m02:r,m10:i,m11:o,m12:s}=this;return r=e.x,s=e.y,new a(t,n,r,i,o,s)}static withTranslation(e){return(new a).withTranslation(e)}getTranslation(){return new i(this.m02,this.m12)}translatedBy(e){return a.withTranslation(e).times(this)}static betweenRects(e,t){return a.withTranslation(e.origin.times(-1)).scaledBy(new i(t.size.x/e.size.x,t.size.y/e.size.y)).translatedBy(t.origin)}times(e){const t=this.m00*e.m00+this.m01*e.m10,n=this.m00*e.m01+this.m01*e.m11,r=this.m00*e.m02+this.m01*e.m12+this.m02,i=this.m10*e.m00+this.m11*e.m10,o=this.m10*e.m01+this.m11*e.m11,s=this.m10*e.m02+this.m11*e.m12+this.m12;return new a(t,n,r,i,o,s)}timesScalar(e){const{m00:t,m01:n,m02:r,m10:i,m11:o,m12:s}=this;return new a(e*t,e*n,e*r,e*i,e*o,e*s)}det(){const{m00:e,m01:t,m02:n,m10:r,m11:i,m12:a}=this;return e*(1*i-0*a)-t*(1*r-0*a)+n*(0*r-0*i)}adj(){const{m00:e,m01:t,m02:n,m10:r,m11:i,m12:o}=this;return new a(+(1*i-0*o),-(1*t-0*n),+(t*o-n*i),-(1*r-0*o),+(1*e-0*n),-(e*o-n*r))}inverted(){const e=this.det();if(0===e)return null;return this.adj().timesScalar(1/e)}transformVector(e){return new i(e.x*this.m00+e.y*this.m01,e.x*this.m10+e.y*this.m11)}inverseTransformVector(e){const t=this.inverted();return t?t.transformVector(e):null}transformPosition(e){return new i(e.x*this.m00+e.y*this.m01+this.m02,e.x*this.m10+e.y*this.m11+this.m12)}inverseTransformPosition(e){const t=this.inverted();return t?t.transformPosition(e):null}transformRect(e){return new o(this.transformPosition(e.origin),this.transformVector(e.size))}flatten(){return[this.m00,this.m10,0,this.m01,this.m11,0,this.m02,this.m12,1]}}n.AffineTransform=a;class o{constructor(e=new i,t=new i){this.origin=e,this.size=t}isEmpty(){return 0==this.width()||0==this.height()}width(){return this.size.x}height(){return this.size.y}left(){return this.origin.x}right(){return this.left()+this.width()}top(){return this.origin.y}bottom(){return this.top()+this.height()}topLeft(){return this.origin}topRight(){return this.origin.plus(new i(this.width(),0))}bottomRight(){return this.origin.plus(this.size)}bottomLeft(){return this.origin.plus(new i(0,this.height()))}withOrigin(e){return new o(e,this.size)}withSize(e){return new o(this.origin,e)}closestPointTo(e){return new i(r(e.x,this.left(),this.right()),r(e.y,this.top(),this.bottom()))}distanceFrom(e){return e.minus(this.closestPointTo(e)).length()}contains(e){return 0===this.distanceFrom(e)}intersectWith(e){const t=i.max(this.topLeft(),e.topLeft()),n=i.max(t,i.min(this.bottomRight(),e.bottomRight()));return new o(t,n.minus(t))}}n.Rect=o},{}],5:[function(e,t,n){(function(n){"use strict";var r=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(e){i=!0,a=e}finally{try{!r&&s.return&&s.return()}finally{if(i)throw a}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=Object.assign||function(e){for(var t=1;t0&&function(e){if(null==f&&null==(f=document.querySelector("style[data-aphrodite]"))){var t=document.head||document.getElementsByTagName("head")[0];(f=document.createElement("style")).type="text/css",f.setAttribute("data-aphrodite",""),t.appendChild(f)}f.styleSheet?f.styleSheet.cssText+=e:f.appendChild(document.createTextNode(e))}(e)};n.flushToStyleTag=b;n.getRenderedClassNames=function(){return Object.keys(c)};n.addRenderedClassNames=function(e){e.forEach(function(e){c[e]=!0})};n.injectAndGetClassName=function(e,n,r){var i={classNameBits:[],definitionBits:[]};if(function e(t,n){for(var r=0;rf){for(var t=0,n=o.length-s;t0&&(e[f]=c)}else{var m=(0,a.default)(r,f,u,e,n);m&&(e[f]=m),(0,i.default)(n,f,e)}}return e}var n=e.prefixMap,r=e.plugins;return t};var i=r(e("../utils/prefixProperty")),a=r(e("../utils/prefixValue")),o=r(e("../utils/addNewValuesOnly")),s=r(e("../utils/isObject"));t.exports=n.default},{"../utils/addNewValuesOnly":30,"../utils/isObject":32,"../utils/prefixProperty":33,"../utils/prefixValue":34}],18:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(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(")})};var r=function(e){return e&&e.__esModule?e:{default:e}}(e("css-in-js-utils/lib/isPrefixedValue")),i=["-webkit-","-moz-",""];t.exports=n.default},{"css-in-js-utils/lib/isPrefixedValue":15}],19:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(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(")})};var r=function(e){return e&&e.__esModule?e:{default:e}}(e("css-in-js-utils/lib/isPrefixedValue")),i=["-webkit-",""];t.exports=n.default},{"css-in-js-utils/lib/isPrefixedValue":15}],20:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t){if("cursor"===e&&i.hasOwnProperty(t))return r.map(function(e){return e+t})};var r=["-webkit-","-moz-",""],i={"zoom-in":!0,"zoom-out":!0,grab:!0,grabbing:!0};t.exports=n.default},{}],21:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(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(")})};var r=function(e){return e&&e.__esModule?e:{default:e}}(e("css-in-js-utils/lib/isPrefixedValue")),i=["-webkit-",""];t.exports=n.default},{"css-in-js-utils/lib/isPrefixedValue":15}],22:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t){if("display"===e&&r.hasOwnProperty(t))return r[t]};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"]};t.exports=n.default},{}],23:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t,n){i.hasOwnProperty(e)&&(n[i[e]]=r[t]||t)};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"};t.exports=n.default},{}],24:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(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)};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"};t.exports=n.default},{}],25:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t){if("string"==typeof t&&!(0,r.default)(t)&&a.test(t))return i.map(function(e){return e+t})};var r=function(e){return e&&e.__esModule?e:{default:e}}(e("css-in-js-utils/lib/isPrefixedValue")),i=["-webkit-","-moz-",""],a=/linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient/;t.exports=n.default},{"css-in-js-utils/lib/isPrefixedValue":15}],26:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(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(")})};var r=function(e){return e&&e.__esModule?e:{default:e}}(e("css-in-js-utils/lib/isPrefixedValue")),i=["-webkit-",""];t.exports=n.default},{"css-in-js-utils/lib/isPrefixedValue":15}],27:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t){if("position"===e&&"sticky"===t)return["-webkit-sticky","sticky"]},t.exports=n.default},{}],28:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t){if(i.hasOwnProperty(e)&&a.hasOwnProperty(t))return r.map(function(e){return e+t})};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};t.exports=n.default},{}],29:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t,n,r){if("string"==typeof t&&s.hasOwnProperty(e)){var u=function(e,t){if((0,a.default)(e))return e;for(var n=e.split(/,(?![^()]*(?:\([^()]*\))?\))/g),r=0,o=n.length;r-1&&"order"!==l)for(var d=t[c],p=0,m=d.length;p-1)return c;var l=u.split(/,(?![^()]*(?:\([^()]*\))?\))/g).filter(function(e){return!/-webkit-|-ms-/.test(e)}).join(",");return e.indexOf("Moz")>-1?l:(n["Webkit"+(0,o.default)(e)]=c,n["Moz"+(0,o.default)(e)]=l,u)}};var i=r(e("css-in-js-utils/lib/hyphenateProperty")),a=r(e("css-in-js-utils/lib/isPrefixedValue")),o=r(e("../../utils/capitalizeString")),s={transition:!0,transitionProperty:!0,WebkitTransition:!0,WebkitTransitionProperty:!0,MozTransition:!0,MozTransitionProperty:!0},f={Webkit:"-webkit-",Moz:"-moz-",ms:"-ms-"};t.exports=n.default},{"../../utils/capitalizeString":31,"css-in-js-utils/lib/hyphenateProperty":14,"css-in-js-utils/lib/isPrefixedValue":15}],30:[function(e,t,n){"use strict";function r(e,t){-1===e.indexOf(t)&&e.push(t)}Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t){if(Array.isArray(t))for(var n=0,i=t.length;n2;)k.push(arguments[a]);for(t&&null!=t.children&&(k.length||k.push(t.children),delete t.children);k.length;)if((r=k.pop())&&void 0!==r.pop)for(a=r.length;a--;)k.push(r[a]);else"boolean"==typeof r&&(r=null),(i="function"!=typeof e)&&(null==r?r="":"number"==typeof r?r=String(r):"string"!=typeof r&&(i=!1)),i&&n?o[o.length-1]+=r:o===S?o=[r]:o.push(r),n=i;var s=new function(){};return s.nodeName=e,s.children=o,s.attributes=null==t?void 0:t,s.key=null==t?void 0:t.key,void 0!==_.vnode&&_.vnode(s),s}function n(e,t){for(var n in t)e[n]=t[n];return e}function r(e){!e.__d&&(e.__d=!0)&&1==O.push(e)&&(_.debounceRendering||T)(i)}function i(){var e,t=O;for(O=[];e=t.pop();)e.__d&&y(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.__n===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){var t=e.parentNode;t&&t.removeChild(e)}function u(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===A.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,c,o):e.removeEventListener(t,c,o),(e.__l||(e.__l={}))[t]=r}else if("list"!==t&&"type"!==t&&!i&&t in e)!function(e,t,n){try{e[t]=n}catch(e){}}(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 c(e){return this.__l[e.type](_.event&&_.event(e)||e)}function l(){for(var e;e=C.pop();)_.afterMount&&_.afterMount(e),e.componentDidMount&&e.componentDidMount()}function d(e,t,n,r,i,a){E++||(j=null!=i&&void 0!==i.ownerSVGElement,D=null!=e&&!("__preactattr_"in e));var o=p(e,t,n,r,a);return i&&o.parentNode!==i&&i.appendChild(o),--E||(D=!1,a||l()),o}function p(e,t,n,r,i){var c=e,l=j;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):(c=document.createTextNode(t),e&&(e.parentNode&&e.parentNode.replaceChild(c,e),m(e,!0))),c.__preactattr_=!0,c;var d=t.nodeName;if("function"==typeof d)return function(e,t,n,r){var i=e&&e._component,a=i,o=e,f=i&&e._componentConstructor===t.nodeName,u=f,c=s(t);for(;i&&!u&&(i=i.__u);)u=i.constructor===t.nodeName;i&&u&&(!r||i._component)?(v(i,c,3,n,r),e=i.base):(a&&!f&&(x(a),e=o=null),i=b(t.nodeName,c,n),e&&!i.__b&&(i.__b=e,o=null),v(i,c,1,n,r),e=i.base,o&&e!==o&&(o._component=null,m(o,!1)));return e}(e,t,n,r);if(j="svg"===d||"foreignObject"!==d&&j,d=String(d),(!e||!o(e,d))&&(c=function(e,t){var n=t?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e);return n.__n=e,n}(d,j),e)){for(;e.firstChild;)c.appendChild(e.firstChild);e.parentNode&&e.parentNode.replaceChild(c,e),m(e,!0)}var h=c.firstChild,g=c.__preactattr_,y=t.children;if(null==g){g=c.__preactattr_={};for(var w=c.attributes,_=w.length;_--;)g[w[_].name]=w[_].value}return!D&&y&&1===y.length&&"string"==typeof y[0]&&null!=h&&void 0!==h.splitText&&null==h.nextSibling?h.nodeValue!=y[0]&&(h.nodeValue=y[0]):(y&&y.length||null!=h)&&function(e,t,n,r,i){var o,s,u,c,l,d=e.childNodes,h=[],b={},g=0,v=0,y=d.length,x=0,w=t?t.length:0;if(0!==y)for(var _=0;_2?[].slice.call(arguments,2):t.children)},Component:w,render:function(e,t,n){return d(n,e,{},!1,t,!1)},rerender:i,options:_};void 0!==t?t.exports=P:self.preact=P}()},{}],36:[function(e,t,n){function r(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function a(e){if(c===setTimeout)return setTimeout(e,0);if((c===r||!c)&&setTimeout)return c=setTimeout,setTimeout(e,0);try{return c(e,0)}catch(t){try{return c.call(null,e,0)}catch(t){return c.call(this,e,0)}}}function o(){h&&p&&(h=!1,p.length?m=p.concat(m):b=-1,m.length&&s())}function s(){if(!h){var e=a(o);h=!0;for(var t=m.length;t;){for(p=m,m=[];++b1)for(var n=1;n1&&t===n&&('"'===t||"'"===t))return['"'+v(e.substr(1,e.length-2))+'"'];var r=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(e);if(r)return y(e.substr(0,r.index)).concat(y(r[1])).concat(y(e.substr(r.index+r[0].length)));var i=e.split(".");if(1===i.length)return['"'+v(e)+'"'];for(var a=[],o=0;o0,"invalid pixel ratio")):r=(i=a).canvas:t=a:ke.raise("invalid arguments to regl"),t&&("canvas"===t.nodeName.toLowerCase()?r=t:n=t),!i){if(!r){ke("undefined"!=typeof document,"must manually specify webgl context outside of DOM environments");var p=function(e,t,n){function r(){var t=window.innerWidth,r=window.innerHeight;if(e!==document.body){var a=e.getBoundingClientRect();t=a.right-a.left,r=a.bottom-a.top}i.width=n*t,i.height=n*r,ue(i.style,{width:t+"px",height:r+"px"})}var i=document.createElement("canvas");return ue(i.style,{border:0,margin:0,padding:0,top:0,left:0}),e.appendChild(i),e===document.body&&(i.style.position="absolute",ue(e.style,{margin:0,padding:0})),window.addEventListener("resize",r,!1),r(),{canvas:i,onDestroy:function(){window.removeEventListener("resize",r),e.removeChild(i)}}}(n||document.body,0,u);if(!p)return null;r=p.canvas,d=p.onDestroy}i=function(e,t){function n(n){try{return e.getContext(n,t)}catch(e){return null}}return n("webgl")||n("experimental-webgl")||n("webgl-experimental")}(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 S(e){return!!e&&"object"==typeof e&&Array.isArray(e.shape)&&Array.isArray(e.stride)&&"number"==typeof e.offset&&e.shape.length===e.stride.length&&(Array.isArray(e.data)||fe(e.data))}function T(e,t){for(var n=Array(e),r=0;r65535)<<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 O(e){var t=function(e){for(var t=16;t<=1<<28;t*=16)if(e<=t)return t;return 0}(e),n=Be[A(t)>>2];return n.length>0?n.pop():new ArrayBuffer(t)}function C(e){Be[A(e.byteLength)>>2].push(e)}function E(e,t,n,r,i,a){for(var o=a,s=0;s>>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 z(e){return Array.isArray(e)||fe(e)}function F(e){return"[object "+e+"]"}function R(e){return Array.isArray(e)&&(0===e.length||"number"==typeof e[0])}function B(e){if(!Array.isArray(e))return!1;return!(0===e.length||!z(e[0]))}function L(e){return Object.prototype.toString.call(e)}function N(e){return L(e)===kn}function V(e){if(!e)return!1;var t=L(e);return On.indexOf(t)>=0||(R(e)||B(e)||S(e))}function I(e){return 0|se[Object.prototype.toString.call(e)]}function H(e,t){return Le.allocType(e.type===Mt?Xt:e.type,t)}function U(e,t){e.type===Mt?(e.data=W(t),Le.freeType(t)):e.data=t}function G(e,t,n,r,i,a){var o;if(o=void 0!==En[e]?En[e]:_n[e]*Cn[t],a&&(o*=6),i){for(var s=0,f=n;f>=1;)s+=o*f*f,f/=2;return s}return o*n*r}function q(e,t,n,r,i,a,o){function s(){this.internalformat=bt,this.format=bt,this.type=Gt,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&&(ke.type(r.premultiplyAlpha,"boolean","invalid premultiplyAlpha"),e.premultiplyAlpha=r.premultiplyAlpha),"flipY"in r&&(ke.type(r.flipY,"boolean","invalid texture flip"),e.flipY=r.flipY),"alignment"in r&&(ke.oneOf(r.alignment,[1,2,4,8],"invalid texture unpack alignment"),e.unpackAlignment=r.alignment),"colorSpace"in r&&(ke.parameter(r.colorSpace,F,"invalid colorSpace"),e.colorSpace=F[r.colorSpace]),"type"in r){var i=r.type;ke(t.oes_texture_float||!("float"===i||"float32"===i),"you must enable the OES_texture_float extension in order to use floating point textures."),ke(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."),ke(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."),ke.parameter(i,q,"invalid texture type"),e.type=q[i]}var a=e.width,o=e.height,s=e.channels,f=!1;"shape"in r?(ke(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],ke(s>0&&s<=4,"invalid number of channels"),f=!0),ke(a>=0&&a<=n.maxTextureSize,"invalid width"),ke(o>=0&&o<=n.maxTextureSize,"invalid height")):("radius"in r&&(a=o=r.radius,ke(a>=0&&a<=n.maxTextureSize,"invalid radius")),"width"in r&&(a=r.width,ke(a>=0&&a<=n.maxTextureSize,"invalid width")),"height"in r&&(o=r.height,ke(o>=0&&o<=n.maxTextureSize,"invalid height")),"channels"in r&&(s=r.channels,ke(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;ke(t.webgl_depth_texture||!("depth"===c||"depth stencil"===c),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),ke.parameter(c,Q,"invalid texture format");var l=e.internalformat=Q[c];e.format=ne[l],c in q&&("type"in r||(e.type=q[c])),c in X&&(e.compressed=!0),u=!0}!f&&u?e.channels=_n[e.format]:f&&!u?e.channels!==wn[e.format]&&(e.format=e.internalformat=wn[e.channels]):u&&f&&ke(e.channels===_n[e.format],"number of channels inconsistent with specified format")}}function c(t){e.pixelStorei(hn,t.flipY),e.pixelStorei(bn,t.premultiplyAlpha),e.pixelStorei(gn,t.colorSpace),e.pixelStorei(mn,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(V(t)?r=t:t&&(ke.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),V(t.data)&&(r=t.data)),ke(!e.compressed||r instanceof Uint8Array,"compressed texture data must be stored in a uint8array"),t.copy){ke(!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,ke(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(fe(r))e.channels=e.channels||4,e.data=r,"type"in t||e.type!==Gt||(e.type=I(r));else if(R(r))e.channels=e.channels||4,function(e,t){var n=t.length;switch(e.type){case Gt:case qt:case Qt:case Xt:var r=Le.allocType(e.type,n);r.set(t),e.data=r;break;case Mt:e.data=W(t);break;default:ke.raise("unsupported texture type, must specify a typed array")}}(e,r),e.alignment=1,e.needsFree=!0;else if(S(r)){var s=r.data;Array.isArray(s)||e.type!==Gt||(e.type=I(s));var f,c,l,d,p,m,h=r.shape,b=r.stride;3===h.length?(l=h[2],m=b[2]):(ke(2===h.length,"invalid ndarray pixel data, must be 2 or 3D"),l=1,m=1),f=h[0],c=h[1],d=b[0],p=b[1],e.alignment=1,e.width=f,e.height=c,e.channels=l,e.format=e.internalformat=wn[l],e.needsFree=!0,function(e,t,n,r,i,a){for(var o=e.width,s=e.height,f=e.channels,u=H(e,o*s*f),c=0,l=0;l=0,"oes_texture_float extension not enabled"):e.type===Mt&&ke(n.extensions.indexOf("oes_texture_half_float")>=0,"oes_texture_half_float extension not enabled")}function p(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 m(t,n,i,a,o){var s=t.element,f=t.data,u=t.internalformat,l=t.format,d=t.type,p=t.width,m=t.height;c(t),s?e.texSubImage2D(n,o,i,a,l,d,s):t.compressed?e.compressedTexSubImage2D(n,o,i,a,u,p,m,f):t.needsCopy?(r(),e.copyTexSubImage2D(n,o,i,a,t.xOffset,t.yOffset,p,m)):e.texSubImage2D(n,o,i,a,p,m,l,d,f)}function h(){return re.pop()||new l}function b(e){e.needsFree&&Le.freeType(e.data),l.call(e),re.push(e)}function g(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 v(e,t){var n=null;if(V(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;ke.parameter(i,M),e.magFilter=M[i]}var a=e.wrapS,o=e.wrapT;if("wrap"in t){var s=t.wrap;"string"==typeof s?(ke.parameter(s,D),a=o=D[s]):Array.isArray(s)&&(ke.parameter(s[0],D),ke.parameter(s[1],D),a=D[s[0]],o=D[s[1]])}else{if("wrapS"in t){var f=t.wrapS;ke.parameter(f,D),a=D[f]}if("wrapT"in t){var u=t.wrapT;ke.parameter(u,D),o=D[u]}}if(e.wrapS=a,e.wrapT=o,"anisotropic"in t){var c=t.anisotropic;ke("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":ke.parameter(t.mipmap,j,"invalid mipmap hint"),e.mipmapHint=j[t.mipmap],e.genMipmaps=!0,l=!0;break;case"boolean":l=e.genMipmaps=t.mipmap;break;case"object":ke(Array.isArray(t.mipmap),"invalid mipmap type"),e.genMipmaps=!1,l=!0;break;default:ke.raise("invalid mipmap type")}!l||"min"in t||(e.minFilter=an)}}function T(n,r){e.texParameteri(r,tn,n.minFilter),e.texParameteri(r,en,n.magFilter),e.texParameteri(r,Yt,n.wrapS),e.texParameteri(r,$t,n.wrapT),t.ext_texture_filter_anisotropic&&e.texParameteri(r,pn,n.anisotropic),n.genMipmaps&&(e.hint(un,n.mipmapHint),e.generateMipmap(r))}function A(t){s.call(this),this.mipmask=0,this.internalformat=bt,this.id=ae++,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(yn),e.bindTexture(t.target,t.texture)}function C(){var t=ce[0];t?e.bindTexture(t.target,t.texture):e.bindTexture(pt,null)}function E(t){var n=t.texture;ke(n,"must not double destroy texture");var r=t.unit,i=t.target;r>=0&&(e.activeTexture(yn+r),e.bindTexture(i,null),ce[r]=null),e.deleteTexture(n),t.texture=null,t.params=null,t.pixels=null,t.refCount=0,delete oe[t.id],a.textureCount--}var j={"don't care":cn,"dont care":cn,nice:dn,fast:ln},D={repeat:Kt,clamp:Zt,mirror:Jt},M={nearest:nn,linear:rn},P=ue({mipmap:fn,"nearest mipmap nearest":an,"linear mipmap nearest":on,"nearest mipmap linear":sn,"linear mipmap linear":fn},M),F={none:0,browser:vn},q={uint8:Gt,rgba4:St,rgb565:At,"rgb5 a1":Tt},Q={alpha:gt,luminance:yt,"luminance alpha":xt,rgb:vt,rgba:bt,rgba4:wt,"rgb5 a1":_t,rgb565:kt},X={};t.ext_srgb&&(Q.srgb=jt,Q.srgba=Dt),t.oes_texture_float&&(q.float32=q.float=Xt),t.oes_texture_half_float&&(q.float16=q["half float"]=Mt),t.webgl_depth_texture&&(ue(Q,{depth:Ct,"depth stencil":Et}),ue(q,{uint16:qt,uint32:Qt,"depth stencil":Ot})),t.webgl_compressed_texture_s3tc&&ue(X,{"rgb s3tc dxt1":Pt,"rgba s3tc dxt1":Wt,"rgba s3tc dxt3":zt,"rgba s3tc dxt5":Ft}),t.webgl_compressed_texture_atc&&ue(X,{"rgb atc":Rt,"rgba atc explicit alpha":Bt,"rgba atc interpolated alpha":Lt}),t.webgl_compressed_texture_pvrtc&&ue(X,{"rgb pvrtc 4bppv1":Nt,"rgb pvrtc 2bppv1":Vt,"rgba pvrtc 4bppv1":It,"rgba pvrtc 2bppv1":Ht}),t.webgl_compressed_texture_etc1&&(X["rgb etc1"]=Ut);var Y=Array.prototype.slice.call(e.getParameter(dt));Object.keys(X).forEach(function(e){var t=X[e];Y.indexOf(t)>=0&&(Q[e]=t)});var $=Object.keys(Q);n.textureFormats=$;var K=[];Object.keys(Q).forEach(function(e){var t=Q[e];K[t]=e});var Z=[];Object.keys(q).forEach(function(e){var t=q[e];Z[t]=e});var J=[];Object.keys(M).forEach(function(e){var t=M[e];J[t]=e});var ee=[];Object.keys(P).forEach(function(e){var t=P[e];ee[t]=e});var te=[];Object.keys(D).forEach(function(e){var t=D[e];te[t]=e});var ne=$.reduce(function(e,t){var n=Q[t];return n===yt||n===gt||n===yt||n===xt||n===Ct||n===Et?e[n]=n:n===_t||t.indexOf("rgba")>=0?e[n]=bt:e[n]=vt,e},{}),re=[],ie=[],ae=0,oe={},se=n.maxTextureUnits,ce=Array(se).map(function(){return null});return ue(A.prototype,{bind:function(){this.bindCount+=1;var t=this.unit;if(t<0){for(var n=0;n0)continue;r.unit=-1}ce[n]=this,t=n;break}t>=se&&ke.raise("insufficient number of texture units"),o.profile&&a.maxTextureUnits>u)-a,c.height=c.height||(s.height>>u)-o,ke(s.type===c.type&&s.format===c.format&&s.internalformat===c.internalformat,"incompatible format for texture.subimage"),ke(a>=0&&o>=0&&a+c.width<=s.width&&o+c.height<=s.height,"texture.subimage write out of bounds"),ke(s.mipmask&1<>f;++f)e.texImage2D(pt,f,s.format,r>>f,a>>f,0,s.format,s.type,null);return C(),o.profile&&(s.stats.size=G(s.internalformat,s.type,r,a,!1,!1)),i},i._reglType="texture2d",i._texture=s,o.profile&&(i.stats=s.stats),i.destroy=function(){s.decRef()},i},createCube:function(t,r,i,s,c,l){function p(e,t,r,i,a,s){var c,l=S.texInfo;for(_.call(l),c=0;c<6;++c)E[c]=x();if("number"!=typeof e&&e)if("object"==typeof e)if(t)v(E[0],e),v(E[1],t),v(E[2],r),v(E[3],i),v(E[4],a),v(E[5],s);else if(k(l,e),u(S,e),"faces"in e){var d=e.faces;for(ke(Array.isArray(d)&&6===d.length,"cube faces must be a length 6 array"),c=0;c<6;++c)ke("object"==typeof d[c]&&!!d[c],"invalid input for cube map face"),f(E[c],S),v(E[c],d[c])}else for(c=0;c<6;++c)v(E[c],e);else ke.raise("invalid arguments to cube map");else{var m=0|e||1;for(c=0;c<6;++c)g(E[c],m,m)}for(f(S,E[0]),l.genMipmaps?S.mipmask=(E[0].width<<1)-1:S.mipmask=E[0].mipmask,ke.textureCube(S,l,E,n),S.internalformat=E[0].internalformat,p.width=E[0].width,p.height=E[0].height,O(S),c=0;c<6;++c)y(E[c],ht+c);for(T(l,mt),C(),o.profile&&(S.stats.size=G(S.internalformat,S.type,p.width,p.height,l.genMipmaps,!0)),p.format=K[S.internalformat],p.type=Z[S.type],p.mag=J[l.magFilter],p.min=ee[l.minFilter],p.wrapS=te[l.wrapS],p.wrapT=te[l.wrapT],c=0;c<6;++c)w(E[c]);return p}var S=new A(mt);oe[S.id]=S,a.cubeCount++;var E=new Array(6);return p(t,r,i,s,c,l),p.subimage=function(e,t,n,r,i){ke(!!t,"must specify image data"),ke("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,S),u.width=0,u.height=0,d(u,t),u.width=u.width||(S.width>>s)-a,u.height=u.height||(S.height>>s)-o,ke(S.type===u.type&&S.format===u.format&&S.internalformat===u.internalformat,"incompatible format for texture.subimage"),ke(a>=0&&o>=0&&a+u.width<=S.width&&o+u.height<=S.height,"texture.subimage write out of bounds"),ke(S.mipmask&1<>i;++i)e.texImage2D(ht+r,i,S.format,n>>i,n>>i,0,S.format,S.type,null);return C(),o.profile&&(S.stats.size=G(S.internalformat,S.type,p.width,p.height,!1,!0)),p}},p._reglType="textureCube",p._texture=S,o.profile&&(p.stats=S.stats),p.destroy=function(){S.decRef()},p},clear:function(){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(ht+r,n,t.internalformat,t.width>>n,t.height>>n,0,t.internalformat,t.type,null);T(t.texInfo,t.target)})}}}function Q(e,t,n){return Mn[e]*t*n}function X(){this.state=0,this.x=0,this.y=0,this.z=0,this.w=0,this.buffer=null,this.size=0,this.normalized=!1,this.type=Zn,this.offset=0,this.stride=0,this.divisor=0}function Y(e,t,n,r){function i(e,t,n,r){this.name=e,this.id=t,this.location=n,this.info=r}function a(e,t){for(var n=0;n1)for(var h=0;he&&(e=t.stats.uniformsCount)}),e},n.getMaxAttributesCount=function(){var e=0;return l.forEach(function(t){t.stats.attributesCount>e&&(e=t.stats.attributesCount)}),e}),{clear:function(){var t=e.deleteShader.bind(e);je(f).forEach(t),f={},je(u).forEach(t),u={},l.forEach(function(t){e.deleteProgram(t.program)}),l.length=0,c={},n.shaderCount=0},program:function(e,t,i){ke.command(e>=0,"missing vertex shader",i),ke.command(t>=0,"missing fragment shader",i);var a=c[t];a||(a=c[t]={});var o=a[e];return o||(o=new function(e,t){this.id=d++,this.fragId=e,this.vertId=t,this.program=null,this.uniforms=[],this.attributes=[],r.profile&&(this.stats={uniformsCount:0,attributesCount:0})}(t,e),n.shaderCount++,s(o,i),a[e]=o,l.push(o)),o},restore:function(){f={},u={};for(var e=0;e=0&&f=0&&u0&&c+f<=r.framebufferWidth,"invalid width for read pixels"),ke(l>0&&l+u<=r.framebufferHeight,"invalid height for read pixels"),n();var p=c*l*4;return d||(s===ir?d=new Uint8Array(p):s===or&&(d=d||new Float32Array(p))),ke.isTypedArray(d,"data buffer for regl.read() must be a typedarray"),ke(d.byteLength>=p,"data buffer for regl.read() too small"),e.pixelStorei(ar,4),e.readPixels(f,u,c,l,rr,s,d),d}return function(e){return e&&"framebuffer"in e?function(e){var n;return t.setFBO({framebuffer:e.framebuffer},function(){n=o(e)}),n}(e):o(e)}}function K(e){return Array.prototype.slice.call(e)}function Z(e){return K(e).join("")}function J(e){return Array.isArray(e)||fe(e)||S(e)}function ee(e){return e.sort(function(e,t){return e===Ir?-1:t===Ir?1:e=1,r>=2,t)}if(n===hr){var i=e.data;return new te(i.thisDep,i.contextDep,i.propDep,t)}return new te(n===mr,n===pr,n===dr,t)}function ae(e,t,n,r,i,a,o,s,f,u,c,l,d,p,m){function h(e){return e.replace(".","_")}function b(e,t,n){var r=h(e);I.push(e),V[r]=N[r]=!!n,H[r]=t}function g(e,t,n){var r=h(e);I.push(e),Array.isArray(n)?(N[r]=n.slice(),V[r]=n.slice()):N[r]=V[r]=n,U[r]=t}function v(){var e=function(){function e(){var e=[],t=[];return ue(function(){e.push.apply(e,K(arguments))},{def:function(){var r="v"+n++;return t.push(r),arguments.length>0&&(e.push(r,"="),e.push.apply(e,K(arguments)),e.push(";")),r},toString:function(){return Z([t.length>0?"var "+t+";":"",Z(e)])}})}function t(){function t(e,t){r(e,t,"=",n.def(e,t),";")}var n=e(),r=e(),i=n.toString,a=r.toString;return ue(function(){n.apply(n,K(arguments))},{def:n.def,entry:n,exit:r,save:t,set:function(e,r,i){t(e,r),n(e,r,"=",i,";")},toString:function(){return i()+a()}})}var n=0,r=[],i=[],a=e(),o={};return{global:a,link:function(e){for(var t=0;t=0,'unknown parameter "'+e+'"',u.commandStr)})}var t=[Ur,Gr,qr,Qr,Xr,$r,Yr,Kr,Hr].concat(I);e(d),e(p)});var m=function(e,t){var n=e.static,r=e.dynamic;if(Ur in n){var i=n[Ur];return i?(i=s.getFramebuffer(i),ke.command(i,"invalid framebuffer object"),re(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,"."+Zr,n+".width"),t.set(a,"."+Jr,n+".height"),n})):re(function(e,t){var n=e.shared;t.set(n.framebuffer,".next","null");var r=n.context;return t.set(r,"."+Zr,r+"."+ni),t.set(r,"."+Jr,r+"."+ri),"null"})}if(Ur in r){var a=r[Ur];return ie(a,function(e,t){var n=e.invoke(t,a),r=e.shared,i=r.framebuffer,o=t.def(i,".getFramebuffer(",n,")");ke.optional(function(){e.assert(t,"!"+n+"||"+o,"invalid framebuffer object")}),t.set(i,".next",o);var s=r.context;return t.set(s,"."+Zr,o+"?"+o+".width:"+s+"."+ni),t.set(s,"."+Jr,o+"?"+o+".height:"+s+"."+ri),o})}return null}(e),b=function(e,t,n){function r(e){if(e in i){var r=i[e];ke.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,ke.command(o>=0,"invalid "+e,n.commandStr)):f=!1,"height"in r?(s=0|r.height,ke.command(s>=0,"invalid "+e,n.commandStr)):f=!1,new te(!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,".",Zr,"-",u));var a=s;return"height"in r||(a=t.def(n,".",Jr,"-",c)),[u,c,i,a]})}if(e in a){var l=a[e],d=ie(l,function(t,n){var r=t.invoke(n,l);ke.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,".",Zr,"-",a,")"),f=n.def('"height" in ',r,"?",r,".height|0:","(",i,".",Jr,"-",o,")");return ke.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 te(t.thisDep,t.contextDep,t.propDep,function(e,t){var n=e.shared.context;return[0,0,t.def(n,".",Zr),t.def(n,".",Jr)]}):null}var i=e.static,a=e.dynamic,o=r(Ir);if(o){var s=o;o=new te(o.thisDep,o.contextDep,o.propDep,function(e,t){var n=s.append(e,t),r=e.shared.context;return t.set(r,"."+ei,n[2]),t.set(r,"."+ti,n[3]),n})}return{viewport:o,scissor_box:r(Vr)}}(e,m,u),g=function(e,t){function n(e,n){if(e in r){var a=0|r[e];return ke.command(!n||a>=0,"invalid "+e,t.commandStr),re(function(e,t){return n&&(e.OFFSET=a),a})}if(e in i){var s=i[e];return ie(s,function(t,r){var i=t.invoke(r,s);return n&&(t.OFFSET=i,ke.optional(function(){t.assert(r,i+">=0","invalid "+e)})),i})}return n&&o?re(function(e,t){return e.OFFSET="0",0}):null}var r=e.static,i=e.dynamic,o=function(){if(Qr in r){var e=r[Qr];J(e)?e=a.getElements(a.create(e,!0)):e&&(e=a.getElements(e),ke.command(e,"invalid elements",t.commandStr));var n=re(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(Qr in i){var o=i[Qr];return ie(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 ke.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($r,!0);return{elements:o,primitive:function(){if(Xr in r){var e=r[Xr];return ke.commandParameter(e,$e,"invalid primitve",t.commandStr),re(function(t,n){return $e[e]})}if(Xr in i){var n=i[Xr];return ie(n,function(e,t){var r=e.constants.primTypes,i=e.invoke(t,n);return ke.optional(function(){e.assert(t,i+" in "+r,"invalid primitive, must be one of "+Object.keys($e))}),t.def(r,"[",i,"]")})}return o?ne(o)?o.value?re(function(e,t){return t.def(e.ELEMENTS,".primType")}):re(function(){return zi}):new te(o.thisDep,o.contextDep,o.propDep,function(e,t){var n=e.ELEMENTS;return t.def(n,"?",n,".primType:",zi)}):null}(),count:function(){if(Yr in r){var e=0|r[Yr];return ke.command("number"==typeof e&&e>=0,"invalid vertex count",t.commandStr),re(function(){return e})}if(Yr in i){var n=i[Yr];return ie(n,function(e,t){var r=e.invoke(t,n);return ke.optional(function(){e.assert(t,"typeof "+r+'==="number"&&'+r+">=0&&"+r+"===("+r+"|0)","invalid vertex count")}),r})}if(o){if(ne(o)){if(o)return s?new te(s.thisDep,s.contextDep,s.propDep,function(e,t){var n=t.def(e.ELEMENTS,".vertCount-",e.OFFSET);return ke.optional(function(){e.assert(t,n+">=0","invalid vertex offset/element buffer too small")}),n}):re(function(e,t){return t.def(e.ELEMENTS,".vertCount")});var a=re(function(){return-1});return ke.optional(function(){a.MISSING=!0}),a}var f=new te(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 ke.optional(function(){f.DYNAMIC=!0}),f}return null}(),instances:n(Kr,!1),offset:s}}(e,u),v=function(e,t){var n=e.static,i=e.dynamic,a={};return I.forEach(function(e){function o(t,r){if(e in n){var o=t(n[e]);a[s]=re(function(){return o})}else if(e in i){var f=i[e];a[s]=ie(f,function(e,t){return r(e,t,e.invoke(t,f))})}}var s=h(e);switch(e){case Ar:case gr:case br:case zr:case wr:case Nr:case jr:case Mr:case Pr:case Sr:return o(function(n){return ke.commandType(n,"boolean",e,t.commandStr),n},function(t,n,r){return ke.optional(function(){t.assert(n,"typeof "+r+'==="boolean"',"invalid flag "+e,t.commandStr)}),r});case _r:return o(function(n){return ke.commandParameter(n,Zi,"invalid "+e,t.commandStr),Zi[n]},function(t,n,r){var i=t.constants.compareFuncs;return ke.optional(function(){t.assert(n,r+" in "+i,"invalid "+e+", must be one of "+Object.keys(Zi))}),n.def(i,"[",r,"]")});case kr:return o(function(e){return ke.command(z(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 ke.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 xr:return o(function(e){ke.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 ke.commandParameter(n,$i,s+".srcRGB",t.commandStr),ke.commandParameter(r,$i,s+".srcAlpha",t.commandStr),ke.commandParameter(i,$i,s+".dstRGB",t.commandStr),ke.commandParameter(a,$i,s+".dstAlpha",t.commandStr),ke.command(-1===Ki.indexOf(n+", "+i),"unallowed blending combination (srcRGB, dstRGB) = ("+n+", "+i+")",t.commandStr),[$i[n],$i[i],$i[r],$i[a]]},function(t,n,r){function i(i,o){var s=n.def('"',i,o,'" in ',r,"?",r,".",i,o,":",r,".",i);return ke.optional(function(){t.assert(n,s+" in "+a,"invalid "+e+"."+i+o+", must be one of "+Object.keys($i))}),s}var a=t.constants.blendFuncs;ke.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");ke.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 yr:return o(function(n){return"string"==typeof n?(ke.commandParameter(n,R,"invalid "+e,t.commandStr),[R[n],R[n]]):"object"==typeof n?(ke.commandParameter(n.rgb,R,e+".rgb",t.commandStr),ke.commandParameter(n.alpha,R,e+".alpha",t.commandStr),[R[n.rgb],R[n.alpha]]):void ke.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 ke.optional(function(){function n(e,n,r){t.assert(e,r+" in "+i,"invalid "+n+", must be one of "+Object.keys(R))}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 vr:return o(function(e){return ke.command(z(e)&&4===e.length,"blend.color must be a 4d array",t.commandStr),T(4,function(t){return+e[t]})},function(e,t,n){return ke.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","blend.color must be a 4d array")}),T(4,function(e){return t.def("+",n,"[",e,"]")})});case Fr:return o(function(e){return ke.commandType(e,"number",s,t.commandStr),0|e},function(e,t,n){return ke.optional(function(){e.assert(t,"typeof "+n+'==="number"',"invalid stencil.mask")}),t.def(n,"|0")});case Rr:return o(function(n){ke.commandType(n,"object",s,t.commandStr);var r=n.cmp||"keep",i=n.ref||0,a="mask"in n?n.mask:-1;return ke.commandParameter(r,Zi,e+".cmp",t.commandStr),ke.commandType(i,"number",e+".ref",t.commandStr),ke.commandType(a,"number",e+".mask",t.commandStr),[Zi[r],i,a]},function(e,t,n){var r=e.constants.compareFuncs;return ke.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]",":",Hi),t.def(n,".ref|0"),t.def('"mask" in ',n,"?",n,".mask|0:-1")]});case Br:case Lr:return o(function(n){ke.commandType(n,"object",s,t.commandStr);var r=n.fail||"keep",i=n.zfail||"keep",a=n.zpass||"keep";return ke.commandParameter(r,Ji,e+".fail",t.commandStr),ke.commandParameter(i,Ji,e+".zfail",t.commandStr),ke.commandParameter(a,Ji,e+".zpass",t.commandStr),[e===Lr?Ri:Fi,Ji[r],Ji[i],Ji[a]]},function(t,n,r){function i(i){return ke.optional(function(){t.assert(n,'!("'+i+'" in '+r+")||("+r+"."+i+" in "+a+")","invalid "+e+"."+i+", must be one of "+Object.keys(Ji))}),n.def('"',i,'" in ',r,"?",a,"[",r,".",i,"]:",Hi)}var a=t.constants.stencilOps;return ke.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)}),[e===Lr?Ri:Fi,i("fail"),i("zfail"),i("zpass")]});case Dr:return o(function(e){ke.commandType(e,"object",s,t.commandStr);var n=0|e.factor,r=0|e.units;return ke.commandType(n,"number",s+".factor",t.commandStr),ke.commandType(r,"number",s+".units",t.commandStr),[n,r]},function(t,n,r){return ke.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)}),[n.def(r,".factor|0"),n.def(r,".units|0")]});case Or:return o(function(e){var n=0;return"front"===e?n=Fi:"back"===e&&(n=Ri),ke.command(!!n,s,t.commandStr),n},function(e,t,n){return ke.optional(function(){e.assert(t,n+'==="front"||'+n+'==="back"',"invalid cull.face")}),t.def(n,'==="front"?',Fi,":",Ri)});case Er:return o(function(e){return ke.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 ke.optional(function(){e.assert(t,"typeof "+n+'==="number"&&'+n+">="+r.lineWidthDims[0]+"&&"+n+"<="+r.lineWidthDims[1],"invalid line width")}),n});case Cr:return o(function(e){return ke.commandParameter(e,ta,s,t.commandStr),ta[e]},function(e,t,n){return ke.optional(function(){e.assert(t,n+'==="cw"||'+n+'==="ccw"',"invalid frontFace, must be one of cw,ccw")}),t.def(n+'==="cw"?'+Bi+":"+Li)});case Tr:return o(function(e){return ke.command(z(e)&&4===e.length,"color.mask must be length 4 array",t.commandStr),e.map(function(e){return!!e})},function(e,t,n){return ke.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","invalid color.mask")}),T(4,function(e){return"!!"+n+"["+e+"]"})});case Wr:return o(function(e){ke.command("object"==typeof e&&e,s,t.commandStr);var n="value"in e?e.value:1,r=!!e.invert;return ke.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 ke.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}(e,u),y=function(e){function n(e){if(e in i){var n=t.id(i[e]);ke.optional(function(){c.shader(ea[e],n,ke.guessCommand())});var r=re(function(){return n});return r.id=n,r}if(e in a){var o=a[e];return ie(o,function(t,n){var r=t.invoke(n,o),i=n.def(t.shared.strings,".id(",r,")");return ke.optional(function(){n(t.shared.shader,".shader(",ea[e],",",i,",",t.command,");")}),i})}return null}var r,i=e.static,a=e.dynamic,o=n(qr),s=n(Gr),f=null;return ne(o)&&ne(s)?(f=c.program(s.id,o.id),r=re(function(e,t){return e.link(f)})):r=new te(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,".",qr);var i=r+".program("+(s?s.append(e,t):t.def(r,".",Gr))+","+n;return ke.optional(function(){i+=","+e.command}),t.def(i+")")}),{frag:o,vert:s,progVar:r,program:f}}(e);l(Ir),l(h(Vr));var x=Object.keys(v).length>0,w={framebuffer:m,draw:g,shader:y,state:v,dirty:x};return w.profile=function(e){var t,n=e.static,r=e.dynamic;if(Hr in n){var i=!!n[Hr];(t=re(function(e,t){return i})).enable=i}else if(Hr in r){var a=r[Hr];t=ie(a,function(e,t){return e.invoke(t,a)})}return t}(e),w.uniforms=function(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=re(function(){return a});else if("function"==typeof a){var o=a._reglType;"texture2d"===o||"textureCube"===o?r=re(function(e){return e.link(a)}):"framebuffer"===o||"framebufferCube"===o?(ke.command(a.color.length>0,'missing color attachment for framebuffer sent to uniform "'+e+'"',t.commandStr),r=re(function(e){return e.link(a.color[0])})):ke.commandRaise('invalid data for uniform "'+e+'"',t.commandStr)}else z(a)?r=re(function(t){return t.global.def("[",T(a.length,function(n){return ke.command("number"==typeof a[n]||"boolean"==typeof a[n],"invalid uniform "+e,t.commandStr),a[n]}),"]")}):ke.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]=ie(t,function(e,n){return e.invoke(n,t)})}),i}(o,u),w.attributes=function(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 F;if(J(a))f.state=ur,f.buffer=i.getBuffer(i.create(a,ai,!1,!0)),f.type=0;else{var u=i.getBuffer(a);if(u)f.state=ur,f.buffer=u,f.type=0;else if(ke.command("object"==typeof a&&a,"invalid data for attribute "+e,n.commandStr),a.constant){var c=a.constant;f.buffer="null",f.state=cr,"number"==typeof c?f.x=c:(ke.command(z(c)&&c.length>0&&c.length<=4,"invalid constant for attribute "+e,n.commandStr),sr.forEach(function(e,t){t=0,'invalid offset for attribute "'+e+'"',n.commandStr);var d=0|a.stride;ke.command(d>=0&&d<256,'invalid stride for attribute "'+e+'", must be integer betweeen [0, 255]',n.commandStr);var p=0|a.size;ke.command(!("size"in a)||p>0&&p<=4,'invalid size for attribute "'+e+'", must be 1,2,3,4',n.commandStr);var m=!!a.normalized,h=0;"type"in a&&(ke.commandParameter(a.type,Ve,"invalid type for attribute "+e,n.commandStr),h=Ve[a.type]);var b=0|a.divisor;"divisor"in a&&(ke.command(0===b||B,'cannot specify divisor for attribute "'+e+'", instancing not supported',n.commandStr),ke.command(b>=0,'invalid divisor for attribute "'+e+'"',n.commandStr)),ke.optional(function(){var t=n.commandStr,r=["buffer","offset","divisor","normalized","type","size","stride"];Object.keys(a).forEach(function(n){ke.command(r.indexOf(n)>=0,'unknown parameter "'+n+'" for attribute pointer "'+e+'" (valid parameters are '+r+")",t)})}),f.buffer=u,f.state=ur,f.size=p,f.normalized=m,f.type=h||u.dtype,f.offset=l,f.stride=d,f.divisor=b}}o[e]=re(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){var t=a[e];o[e]=ie(t,function(n,r){function i(e){r(u[e],"=",a,".",e,"|0;")}var a=n.invoke(r,t),o=n.shared,s=o.isBufferArgs,f=o.buffer;ke.optional(function(){n.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 F;c.state=ur,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(",ai,",",a,");",d,"=",l,".dtype;","}else{",l,"=",f,".getBuffer(",a,");","if(",l,"){",d,"=",l,".dtype;",'}else if("constant" in ',a,"){",u.state,"=",cr,";","if(typeof "+a+'.constant === "number"){',u[sr[0]],"=",a,".constant;",sr.slice(1).map(function(e){return u[e]}).join("="),"=0;","}else{",sr.map(function(e,t){return u[e]+"="+a+".constant.length>="+t+"?"+a+".constant["+t+"]:0;"}).join(""),"}}else{","if(",s,"(",a,".buffer)){",l,"=",f,".createStream(",ai,",",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})}),o}(n,u),w.context=function(e){var t=e.static,n=e.dynamic,r={};return Object.keys(t).forEach(function(e){var n=t[e];r[e]=re(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]=ie(t,function(e,n){return e.invoke(n,t)})}),r}(f),w}function x(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 w(e,t,n,r){var i,a=e.shared,o=a.gl,s=a.framebuffer;L&&(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(",Xi,",",f,".framebuffer);"),L&&t(i,".drawBuffersWEBGL(",c,"[",f,".colorAttachments.length]);"),t("}else{",o,".bindFramebuffer(",Xi,",null);"),L&&t(i,".drawBuffersWEBGL(",l,");"),t("}",s,".cur=",f,";"),r||t("}")}function _(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");I.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=T(N[r].length,function(e){return u.def(c,"[",e,"]")});u(e.cond(d.map(function(e,t){return e+"!=="+l+"["+t+"]"}).join("||")).then(i,".",U[r],"(",d,");",d.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";"))}else{c=u.def(f,".",r);var p=e.cond(c,"!==",s,".",r);u(p),r in H?p(e.cond(c).then(i,".enable(",H[r],");").else(i,".disable(",H[r],");"),s,".",r,"=",c,";"):p(i,".",U[r],"(",c,");",s,".",r,"=",c,";")}}}),0===Object.keys(n.state).length&&u(s,".dirty=false;"),t(u)}function k(e,t,n,r){var i=e.shared,a=e.current,o=i.current,s=i.gl;ee(Object.keys(n)).forEach(function(i){var f=n[i];if(!r||r(f)){var u=f.append(e,t);if(H[i]){var c=H[i];ne(f)?t(s,u?".enable(":".disable(",c,");"):t(e.cond(u).then(s,".enable(",c,");").else(s,".disable(",c,");")),t(o,".",i,"=",u,";")}else if(z(u)){var l=a[i];t(s,".",U[i],"(",u,");",u.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";")}else t(s,".",U[i],"(",u,");",o,".",i,"=",u,";")}})}function S(e,t){B&&(e.instancing=t.def(e.shared.extensions,".angle_instanced_arrays"))}function A(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(m,".count+=",i,";"):e(m,".count++;"),p&&(r?e(c=t.def(),"=",b,".getNumPendingQueries();"):e(b,".beginQuery(",m,");"))}function s(e){e(m,".cpuTime+=",a(),"-",u,";"),p&&(r?e(b,".pushScopeStats(",c,",",b,".getNumPendingQueries(),",m,");"):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,m=e.stats,h=d.current,b=d.timer,g=n.profile;if(g){if(ne(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 O(e,t,n,r,i){var a=e.shared;r.forEach(function(r){var o,s=r.name,f=n.attributes[s];if(f){if(!i(f))return;o=f.append(e,t)}else{if(!i(na))return;var u=e.scopeAttrib(s);ke.optional(function(){e.assert(t,u+".state","missing attribute "+s)}),o={},Object.keys(new F).forEach(function(e){o[e]=t.def(u,".",e)})}!function(n,r,i){function o(){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,"||",m.map(function(e){return c+"."+e+"!=="+i[e]}).join("||"),"){",f,".bindBuffer(",ai,",",d,".buffer);",f,".vertexAttribPointer(",[u,n,a,i.normalized,i.stride,i.offset],");",c,".type=",a,";",c,".size=",n,";",m.map(function(e){return c+"."+e+"="+i[e]+";"}).join(""),"}"),B){var o=i.divisor;t("if(",c,".divisor!==",o,"){",e.instancing,".vertexAttribDivisorANGLE(",[u,o],");",c,".divisor=",o,";}")}}function s(){t("if(",c,".buffer){",f,".disableVertexAttribArray(",u,");","}if(",sr.map(function(e,t){return c+"."+e+"!=="+p[t]}).join("||"),"){",f,".vertexAttrib4f(",u,",",p,");",sr.map(function(e,t){return c+"."+e+"="+p[t]+";"}).join(""),"}")}var f=a.gl,u=t.def(n,".location"),c=t.def(a.attributes,"[",u,"]"),l=i.state,d=i.buffer,p=[i.x,i.y,i.z,i.w],m=["buffer","normalized","offset","stride"];l===ur?o():l===cr?s():(t("if(",l,"===",ur,"){"),o(),t("}else{"),s(),t("}"))}(e.link(r),function(e){switch(e){case yi:case ki:case Oi:return 2;case xi:case Si:case Ci:return 3;case wi:case Ti:case Ei:return 4;default:return 1}}(r.info.type),o)})}function C(e,n,r,i,a){for(var o,s=e.shared,f=s.gl,u=0;u1?T(x,function(e){return c+"["+e+"]"}):c);n(");")}}function E(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,m,g,p+"<<(("+g+"-"+fr+")>>1)",h],");")}function t(){n(b,".drawArraysInstancedANGLE(",[d,p,m,h],");")}l?v?e():(n("if(",l,"){"),e(),n("}else{"),t(),n("}")):t()}function o(){function e(){n(f+".drawElements("+[d,m,g,p+"<<(("+g+"-"+fr+")>>1)"]+");")}function t(){n(f+".drawArrays("+[d,p,m]+");")}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,".",Qr),i&&o("if("+i+")"+f+".bindBuffer("+oi+","+i+".buffer.buffer);"),i}(),d=i(Xr),p=i($r),m=function(){var i,a=c.count,o=t;return a?((a.contextDep&&r.contextDynamic||a.propDep)&&(o=n),i=a.append(e,o),ke.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,".",Yr),ke.optional(function(){e.assert(o,i+">=0","missing vertex count")})),i}();if("number"==typeof m){if(0===m)return}else n("if(",m,"){"),n.exit("}");var h,b;B&&(h=i(Kr),b=e.instancing);var g=l+".type",v=c.elements&&ne(c.elements);B&&("number"!=typeof h||h>=0)?"string"==typeof h?(n("if(",h,">0){"),a(),n("}else if(",h,"<0){"),o(),n("}")):a():o()}function j(e,t,n,r,i){var a=v(),o=a.proc("body",i);return ke.optional(function(){a.commandStr=t.commandStr,a.command=a.link(t.commandStr)}),B&&(a.instancing=o.def(a.shared.extensions,".angle_instanced_arrays")),e(a,o,n,r),a.compile().body}function D(e,t,n,r){S(e,t),O(e,t,n,r.attributes,function(){return!0}),C(e,t,n,r.uniforms,function(){return!0}),E(e,t,t,n)}function M(e,t,n,r){function i(){return!0}e.batchId="a1",S(e,t),O(e,t,n,r.attributes,i),C(e,t,n,r.uniforms,i),E(e,t,t,n)}function P(e,t,n,r){function i(e){return e.contextDep&&o||e.propDep}function a(e){return!i(e)}S(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&&x(e,c,n.context),n.needsFramebuffer&&w(e,c,n.framebuffer),k(e,c,n.state,i),n.profile&&i(n.profile)&&A(e,c,n,!1,!0),r)O(e,u,n,r.attributes,a),O(e,c,n,r.attributes,i),C(e,u,n,r.uniforms,a),C(e,c,n,r.uniforms,i),E(e,u,c,n);else{var l=e.global.def("{}"),d=n.shader.progVar.append(e,c),p=c.def(d,".id"),m=c.def(l,"[",p,"]");c(e.shared.gl,".useProgram(",d,".program);","if(!",m,"){",m,"=",l,"[",p,"]=",e.link(function(t){return j(M,e,n,t,2)}),"(",d,");}",m,".call(this,a0[",s,"],",s,");")}}function W(e,t,n){var r=t.static[n];if(r&&function(e){if("object"==typeof e&&!z(e)){for(var t=Object.keys(e),n=0;n0&&n(e.shared.current,".dirty=true;")}(o,s),function(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;x(e,i,n.context),n.framebuffer&&n.framebuffer.append(e,i),ee(Object.keys(n.state)).forEach(function(t){var r=n.state[t].append(e,i);z(r)?r.forEach(function(n,r){i.set(e.next[t],"["+r+"]",n)}):i.set(a.next,"."+t,r)}),A(e,i,n,!0,!0),[Qr,$r,Yr,Kr,Xr].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 F).forEach(function(e){i.set(a,"."+e,r[e])})}),r(Gr),r(qr),Object.keys(n.state).length>0&&(i(o,".dirty=true;"),i.exit(o,".dirty=true;")),i("a1(",e.shared.context,",a0,",e.batchId,");")}(o,s),function(e,t){function n(e){return e.contextDep&&i||e.propDep}var r=e.proc("batch",2);e.batchId="0",S(e,r);var i=!1,a=!0;Object.keys(t.context).forEach(function(e){i=i||t.context[e].propDep}),i||(x(e,r,t.context),a=!1);var o=t.framebuffer,s=!1;o?(o.propDep?i=s=!0:o.contextDep&&i&&(s=!0),s||w(e,r,o)):w(e,r,null),t.state.viewport&&t.state.viewport.propDep&&(i=!0),_(e,r,t),k(e,r,t.state,function(e){return!n(e)}),t.profile&&n(t.profile)||A(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)P(e,r,t,null);else{var u=f.append(e,r);if(r(e.shared.gl,".useProgram(",u,".program);"),t.shader.program)P(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 j(P,e,t,n,2)}),"(",u,");",d,".call(this,a0,a1);"))}}Object.keys(t.state).length>0&&r(e.shared.current,".dirty=true;")}(o,s),o.compile()}}}function oe(e,t){for(var n=0;n=0&&(0|e)===e||t("invalid parameter type, ("+e+")"+r(n)+". must be a nonnegative integer")},oneOf:i,shaderError:function(e,t,r,i,o){if(!e.getShaderParameter(t,e.COMPILE_STATUS)){var s=e.getShaderInfoLog(t),u=i===e.FRAGMENT_SHADER?"fragment":"vertex";m(r,"string",u+" shader source must be a string",o);var c=l(r,o),d=function(e){var t=[];return e.split("\n").forEach(function(e){if(!(e.length<5)){var n=/^ERROR\:\s+(\d+)\:(\d+)\:\s*(.*)$/.exec(e);n?t.push(new f(0|n[1],0|n[2],n[3].trim())):e.length>0&&t.push(new f("unknown",0,e))}}),t}(s);!function(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)})}(c,d),Object.keys(c).forEach(function(e){function t(e,t){r.push(e),i.push(t||"")}var n=c[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(a(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,o=/^\s*\'(.*)\'\s*\:\s*(.*)$/.exec(i);if(o){var s=o[1];switch(i=o[2],s){case"assign":s="="}n=Math.max(e.line.indexOf(s,n),0)}else n=0;t(a("| ",6)),t(a("^^^",n+3)+"\n","font-weight:bold"),t(a("| ",6)),t(i+"\n","font-weight:bold")}),t(a("| ",6)+"\n")}else t(a(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 "+u+" shader, "+c[0].name)}},linkError:function(e,t,r,i,a){if(!e.getProgramParameter(t,e.LINK_STATUS)){var o=e.getProgramInfoLog(t),s=l(r,a),f='Error linking program with vertex shader, "'+l(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)}},callSite:c,saveCommandRef:d,saveDrawInfo:function(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})}d(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},framebufferFormat:function(e,t,n){e.texture?i(e.texture._texture.internalformat,t,"unsupported texture format for attachment"):i(e.renderbuffer._renderbuffer.format,n,"unsupported renderbuffer format for attachment")},guessCommand:u,texture2D:function(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===le&&e.wrapT===le||n(b(a)&&b(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!==pe&&e.minFilter!==he&&e.minFilter!==me&&e.minFilter!==be,"min filter requires mipmap"):(n(b(a)&&b(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===ge&&(r.extensions.indexOf("oes_texture_float_linear")<0&&n(e.minFilter===de&&e.magFilter===de,"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===le&&t.wrapT===le,"wrap mode not supported by cube map");for(var f=0;f>l,m=o>>l;n(u.mipmask&1<=2,"invalid renderbuffer shape"),a=0|p[0],o=0|p[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&&(ke.parameter(d.format,s,"invalid renderbuffer format"),c=s[d.format])}else"number"==typeof t?(a=0|t,o="number"==typeof r?0|r:a):t?ke.raise("invalid arguments to renderbuffer constructor"):a=o=1;if(ke(a>0&&o>0&&a<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),a!==l.width||o!==l.height||c!==l.format)return u.width=l.width=a,u.height=l.height=o,l.format=c,e.bindRenderbuffer(jn,l.renderbuffer),e.renderbufferStorage(jn,c,a,o),i.profile&&(l.stats.size=Q(l.format,l.width,l.height)),u.format=f[l.format],u}var l=new a(e.createRenderbuffer());return c[l.id]=l,r.renderbufferCount++,u(t,o),u.resize=function(t,r){var a=0|t,o=0|r||a;return a===l.width&&o===l.height?u:(ke(a>0&&o>0&&a<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),u.width=l.width=a,u.height=l.height=o,e.bindRenderbuffer(jn,l.renderbuffer),e.renderbufferStorage(jn,l.format,a,o),i.profile&&(l.stats.size=Q(l.format,l.width,l.height)),u)},u._reglType="renderbuffer",u._renderbuffer=l,i.profile&&(u.stats=l.stats),u.destroy=function(){l.decRef()},u},clear:function(){je(c).forEach(o)},restore:function(){je(c).forEach(function(t){t.renderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(jn,t.renderbuffer),e.renderbufferStorage(jn,t.format,t.width,t.height)}),e.bindRenderbuffer(jn,null)}}},Wn=36160,zn=36161,Fn=3553,Rn=34069,Bn=36064,Ln=36096,Nn=36128,Vn=33306,In=36053,Hn=6402,Un=[6408],Gn=[];Gn[6408]=4;var qn=[];qn[5121]=1,qn[5126]=4,qn[36193]=2;var Qn=33189,Xn=36168,Yn=34041,$n=[32854,32855,36194,35907,34842,34843,34836],Kn={};Kn[In]="complete",Kn[36054]="incomplete attachment",Kn[36057]="incomplete dimensions",Kn[36055]="incomplete, missing attachment",Kn[36061]="unsupported";var Zn=5126,Jn=35632,er=35633,tr=35718,nr=35721,rr=6408,ir=5121,ar=3333,or=5126,sr="xyzw".split(""),fr=5121,ur=1,cr=2,lr=0,dr=1,pr=2,mr=3,hr=4,br="dither",gr="blend.enable",vr="blend.color",yr="blend.equation",xr="blend.func",wr="depth.enable",_r="depth.func",kr="depth.range",Sr="depth.mask",Tr="colorMask",Ar="cull.enable",Or="cull.face",Cr="frontFace",Er="lineWidth",jr="polygonOffset.enable",Dr="polygonOffset.offset",Mr="sample.alpha",Pr="sample.enable",Wr="sample.coverage",zr="stencil.enable",Fr="stencil.mask",Rr="stencil.func",Br="stencil.opFront",Lr="stencil.opBack",Nr="scissor.enable",Vr="scissor.box",Ir="viewport",Hr="profile",Ur="framebuffer",Gr="vert",qr="frag",Qr="elements",Xr="primitive",Yr="count",$r="offset",Kr="instances",Zr=Ur+"Width",Jr=Ur+"Height",ei=Ir+"Width",ti=Ir+"Height",ni="drawingBufferWidth",ri="drawingBufferHeight",ii=[xr,yr,Rr,Br,Lr,Wr,Ir,Vr,Dr],ai=34962,oi=34963,si=3553,fi=34067,ui=2884,ci=3042,li=3024,di=2960,pi=2929,mi=3089,hi=32823,bi=32926,gi=32928,vi=5126,yi=35664,xi=35665,wi=35666,_i=5124,ki=35667,Si=35668,Ti=35669,Ai=35670,Oi=35671,Ci=35672,Ei=35673,ji=35674,Di=35675,Mi=35676,Pi=35678,Wi=35680,zi=4,Fi=1028,Ri=1029,Bi=2304,Li=2305,Ni=32775,Vi=32776,Ii=519,Hi=7680,Ui=0,Gi=1,qi=32774,Qi=513,Xi=36160,Yi=36064,$i={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},Ki=["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"],Zi={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},Ji={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment wrap":34055,"decrement wrap":34056,invert:5386},ea={frag:35632,vert:35633},ta={cw:Bi,ccw:Li},na=new te(!1,!1,!1,function(){}),ra=34918,ia=34919,aa=35007,oa=function(e,t){function n(e){o.push(e)}function r(e){f.push(e)}function i(e,t,n){var r=f.pop()||new function(){this.startQueryIndex=-1,this.endQueryIndex=-1,this.sum=0,this.stats=null};r.startQueryIndex=e,r.endQueryIndex=t,r.sum=0,r.stats=n,u.push(r)}var a=t.ext_disjoint_timer_query;if(!a)return null;var o=[],s=[],f=[],u=[],c=[],l=[];return{beginQuery:function(e){var t=o.pop()||a.createQueryEXT();a.beginQueryEXT(aa,t),s.push(t),i(s.length-1,s.length,e)},endQuery:function(){a.endQueryEXT(aa)},pushScopeStats:i,update:function(){var e,t,i=s.length;if(0!==i){l.length=Math.max(l.length,i+1),c.length=Math.max(c.length,i+1),c[0]=0,l[0]=0;var o=0;for(e=0,t=0;t=0;--e){var n=H[e];n&&n(O,null,0)}m.flush(),w&&w.update()}function n(){!K&&H.length>0&&(K=Oe.next(t))}function r(){K&&(Oe.cancel(t),K=null)}function i(e){e.preventDefault(),b=!0,r(),U.forEach(function(e){e()})}function a(e){m.getError(),b=!1,g.restore(),z.restore(),E.restore(),F.restore(),R.restore(),B.restore(),w&&w.restore(),L.procs.refresh(),n(),G.forEach(function(e){e()})}function o(e){function t(e){var t={},n={};return Object.keys(e).forEach(function(r){var i=e[r];Ae.isDynamic(i)?n[r]=Ae.unbox(i,r):t[r]=i}),{dynamic:n,static:t}}ke(!!e,"invalid args to regl({...})"),ke.type(e,"object","invalid args to regl({...})");var n=t(e.context||{}),r=t(e.uniforms||{}),i=t(e.attributes||{}),a=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=ue({},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)),o={gpuTime:0,cpuTime:0,count:0},s=L.compile(a,i,r,n,o),f=s.draw,u=s.batch,c=s.scope,l=[];return ue(function(e,t){var n;if(b&&ke.raise("context lost"),"function"==typeof e)return c.call(this,null,e,0);if("function"==typeof t){if("number"==typeof e){for(n=0;n0)return u.call(this,function(e){for(;l.length=0,"cannot cancel a frame twice"),H[n]=t}}}function u(){var e=V.viewport,t=V.scissor_box;e[0]=e[1]=t[0]=t[1]=0,O.viewportWidth=O.framebufferWidth=O.drawingBufferWidth=e[2]=t[2]=m.drawingBufferWidth,O.viewportHeight=O.framebufferHeight=O.drawingBufferHeight=e[3]=t[3]=m.drawingBufferHeight}function c(){O.tick+=1,O.time=d(),u(),L.procs.poll()}function l(){u(),L.procs.refresh(),w&&w.update()}function d(){return(Ce()-_)/1e3}var p=k(e);if(!p)return null;var m=p.gl,h=m.getContextAttributes(),b=m.isContextLost(),g=function(e,t){function n(t){ke.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;i0){var f;if(Array.isArray(t[0])){s=Ue(t);for(var u=1,c=1;c0)if("number"==typeof e[0]){var i=Le.allocType(p.dtype,e.length);M(i,e),d(i,r),Le.freeType(i)}else if(Array.isArray(e[0])||fe(e[0])){n=Ue(e);var a=He(e,n,p.dtype);d(a,r),Le.freeType(a)}else ke.raise("invalid buffer data")}else if(fe(e))d(e,r);else if(S(e)){n=e.shape;var o=e.stride,s=0,f=0,u=0,c=0;1===n.length?(s=n[0],f=1,u=o[0],c=0):2===n.length?(s=n[0],f=n[1],u=o[0],c=o[1]):ke.raise("invalid shape");var m=Array.isArray(e.data)?p.dtype:D(e.data),h=Le.allocType(m,s*f);P(h,e.data,s,f,u,c,e.offset),d(h,r),Le.freeType(h)}else ke.raise("invalid data for buffer subdata");return l},n.profile&&(l.stats=p.stats),l.destroy=function(){o(p)},l},createStream:function(e,t){var n=u.pop();return n||(n=new r(e)),n.bind(),a(n,t,qe,0,1,!1),n},destroyStream:function(e){u.push(e)},clear:function(){je(f).forEach(o),u.forEach(o)},getBuffer:function(e){return e&&e._buffer instanceof r?e._buffer:null},restore:function(){je(f).forEach(function(t){t.buffer=e.createBuffer(),e.bindBuffer(t.type,t.buffer),e.bufferData(t.type,t.persistentData||t.byteLength,t.usage)})},_initBuffer:a}}(m,y,p),j=function(e,t,n,r){function i(e){this.id=f++,s[this.id]=this,this.buffer=e,this.primType=Je,this.vertCount=0,this.type=0}function a(r,i,a,o,s,f,u){if(r.buffer.bind(),i){var c=u;u||fe(i)&&(!S(i)||fe(i.data))||(c=t.oes_element_index_uint?at:rt),n._initBuffer(r.buffer,i,a,c,3)}else e.bufferData(ot,f,a),r.buffer.dtype=l||tt,r.buffer.usage=a,r.buffer.dimension=3,r.buffer.byteLength=f;var l=u;if(!u){switch(r.buffer.dtype){case tt:case et:l=tt;break;case rt:case nt:l=rt;break;case at:case it:l=at;break;default:ke.raise("unsupported type for element array")}r.buffer.dtype=l}r.type=l,ke(l!==at||!!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===rt?d>>=1:l===at&&(d>>=2)),r.vertCount=d;var p=o;if(o<0){p=Je;var m=r.buffer.dimension;1===m&&(p=Ke),2===m&&(p=Ze),3===m&&(p=Je)}r.primType=p}function o(e){r.elementsCount--,ke(null!==e.buffer,"must not double destroy elements"),delete s[e.id],e.buffer.destroy(),e.buffer=null}var s={},f=0,u={uint8:tt,uint16:rt};t.oes_element_index_uint&&(u.uint32=at),i.prototype.bind=function(){this.buffer.bind()};var c=[];return{create:function(e,t){function s(e){if(e)if("number"==typeof e)f(e),c.primType=Je,c.vertCount=0|e,c.type=tt;else{var t=null,n=ft,r=-1,i=-1,o=0,l=0;Array.isArray(e)||fe(e)||S(e)?t=e:(ke.type(e,"object","invalid arguments for elements"),"data"in e&&(t=e.data,ke(Array.isArray(t)||fe(t)||S(t),"invalid data for element buffer")),"usage"in e&&(ke.parameter(e.usage,Ie,"invalid element buffer usage"),n=Ie[e.usage]),"primitive"in e&&(ke.parameter(e.primitive,$e,"invalid element buffer primitive"),r=$e[e.primitive]),"count"in e&&(ke("number"==typeof e.count&&e.count>=0,"invalid vertex count for elements"),i=0|e.count),"type"in e&&(ke.parameter(e.type,u,"invalid buffer type"),l=u[e.type]),"length"in e?o=0|e.length:(o=i,l===rt||l===nt?o*=2:l!==at&&l!==it||(o*=4))),a(c,t,n,r,i,o,l)}else f(),c.primType=Je,c.vertCount=0,c.type=tt;return s}var f=n.create(null,ot,!0),c=new i(f._buffer);return r.elementsCount++,s(e),s._reglType="elements",s._elements=c,s.subdata=function(e,t){return f.subdata(e,t),s},s.destroy=function(){o(c)},s},createStream:function(e){var t=c.pop();return t||(t=new i(n.create(null,ot,!0,!1)._buffer)),a(t,e,st,-1,-1,0,0),t},destroyStream:function(e){c.push(e)},getElements:function(e){return"function"==typeof e&&e._elements instanceof i?e._elements:null},clear:function(){je(s).forEach(o)}}}(m,x,E,y),W=function(e,t,n,r,i){for(var a=n.maxAttributes,o=new Array(a),s=0;s=Rn&&t=2,"invalid shape for framebuffer"),u=M[0],p=M[1]}else"radius"in D&&(u=p=D.radius),"width"in D&&(u=D.width),"height"in D&&(p=D.height);("color"in D||"colors"in D)&&(v=D.color||D.colors,Array.isArray(v)&&ke(1===v.length||s,"multiple render targets not supported")),v||("colorCount"in D&&(A=0|D.colorCount,ke(A>0,"invalid color buffer count")),"colorTexture"in D&&(k=!!D.colorTexture,S="rgba4"),"colorType"in D&&(T=D.colorType,k?(ke(t.oes_texture_float||!("float"===T||"float32"===T),"you must enable OES_texture_float in order to use floating point framebuffer objects"),ke(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?(ke(t.ext_color_buffer_half_float,"you must enable EXT_color_buffer_half_float to use 16-bit render buffers"),S="rgba16f"):"float"!==T&&"float32"!==T||(ke(t.webgl_color_buffer_float,"you must enable WEBGL_color_buffer_float in order to use 32-bit floating point renderbuffers"),S="rgba32f"),ke.oneOf(T,_,"invalid color type")),"colorFormat"in D&&(S=D.colorFormat,x.indexOf(S)>=0?k=!0:w.indexOf(S)>=0?k=!1:k?ke.oneOf(D.colorFormat,x,"invalid color format for texture"):ke.oneOf(D.colorFormat,w,"invalid color format for renderbuffer"))),("depthTexture"in D||"depthStencilTexture"in D)&&(j=!(!D.depthTexture&&!D.depthStencilTexture),ke(!j||t.webgl_depth_texture,"webgl_depth_texture extension not supported")),"depth"in D&&("boolean"==typeof D.depth?m=D.depth:(O=D.depth,b=!1)),"stencil"in D&&("boolean"==typeof D.stencil?b=D.stencil:(C=D.stencil,m=!1)),"depthStencil"in D&&("boolean"==typeof D.depthStencil?m=b=D.depthStencil:(E=D.depthStencil,m=!1,b=!1))}else u=p=1;var P=null,W=null,z=null,F=null;if(Array.isArray(v))P=v.map(c);else if(v)P=[c(v)];else for(P=new Array(A),a=0;a=0||P[a].renderbuffer&&$n.indexOf(P[a].renderbuffer._renderbuffer.format)>=0,"framebuffer color attachment "+a+" is invalid"),P[a]&&P[a].texture){var B=Gn[P[a].texture._texture.format]*qn[P[a].texture._texture.type];null===R?R=B:ke(R===B,"all color attachments much have the same number of bits per pixel.")}return f(W,u,p),ke(!W||W.texture&&W.texture._texture.format===Hn||W.renderbuffer&&W.renderbuffer._renderbuffer.format===Qn,"invalid depth attachment for framebuffer object"),f(z,u,p),ke(!z||z.renderbuffer&&z.renderbuffer._renderbuffer.format===Xn,"invalid stencil attachment for framebuffer object"),f(F,u,p),ke(!F||F.texture&&F.texture._texture.format===Yn||F.renderbuffer&&F.renderbuffer._renderbuffer.format===Yn,"invalid depth-stencil attachment for framebuffer object"),h(o),o.width=u,o.height=p,o.colorAttachments=P,o.depthAttachment=W,o.stencilAttachment=z,o.depthStencilAttachment=F,i.color=P.map(d),i.depth=d(W),i.stencil=d(z),i.depthStencil=d(F),i.width=o.width,i.height=o.height,g(o),i}var o=new m;return a.framebufferCount++,i(e,r),ue(i,{resize:function(e,t){ke(y.next!==o,"can not resize a framebuffer which is currently in use");var n=0|e,r=0|t||n;if(n===o.width&&r===o.height)return i;for(var a=o.colorAttachments,s=0;s=2,"invalid shape for framebuffer"),ke(m[0]===m[1],"cube framebuffer must be square"),f=m[0]}else"radius"in p&&(f=0|p.radius),"width"in p?(f=0|p.width,"height"in p&&ke(p.height===f,"must be square")):"height"in p&&(f=0|p.height);("color"in p||"colors"in p)&&(u=p.color||p.colors,Array.isArray(u)&&ke(1===u.length||o,"multiple render targets not supported")),u||("colorCount"in p&&(d=0|p.colorCount,ke(d>0,"invalid color buffer count")),"colorType"in p&&(ke.oneOf(p.colorType,_,"invalid color type"),l=p.colorType),"colorFormat"in p&&(c=p.colorFormat,ke.oneOf(p.colorFormat,x,"invalid color format for texture"))),"depth"in p&&(s.depth=p.depth),"stencil"in p&&(s.stencil=p.stencil),"depthStencil"in p&&(s.depthStencil=p.depthStencil)}else f=1;var h;if(u)if(Array.isArray(u))for(h=[],n=0;n0&&(s.depth=a[0].depth,s.stencil=a[0].stencil,s.depthStencil=a[0].depthStencil),a[n]?a[n](s):a[n]=v(s)}return ue(i,{width:f,height:f,color:h})}var a=Array(6);return i(e),ue(i,{faces:a,resize:function(e){var t,r=0|e;if(ke(r>0&&r<=n.maxCubeMapSize,"invalid radius for cube fbo"),r===i.width)return i;var o=i.color;for(t=0;t=0},read:N,destroy:function(){H.length=0,r(),I&&(I.removeEventListener(la,i),I.removeEventListener(da,a)),z.clear(),B.clear(),R.clear(),F.clear(),j.clear(),E.clear(),w&&w.clear(),Q.forEach(function(e){e()})},_gl:m,_refresh:l,poll:function(){c(),w&&w.update()},now:d,stats:y});return p.onDone(null,J),J}})},{}],38:[function(e,t,n){"use strict";t.exports=function(e){for(var t=5381,n=e.length;n;)t=33*t^e.charCodeAt(--n);return t>>>0}},{}],39:[function(e,t,n){"use strict";function r(e,t,n){return e.has(t)||e.set(t,n),e.get(t)}function i(e){return e[e.length-1]}Object.defineProperty(n,"__esModule",{value:!0});class a{constructor(){this.selfTime=0,this.totalTime=0}getSelfTime(){return this.selfTime}getTotalTime(){return this.totalTime}addToTotalTime(e){this.totalTime+=e}addToSelfTime(e){this.selfTime+=e}}n.HasTimings=a;class o extends a{constructor(e){super(),this.key=e.key,this.name=e.name,this.file=e.file,this.line=e.line,this.col=e.col}}n.Frame=o;class s extends a{constructor(e,t){super(),this.frame=e,this.parent=t,this.children=[]}}n.CallTreeNode=s;n.Profile=class{constructor(e){this.frames=new Map,this.calltreeRoots=[],this.samples=[],this.timeDeltas=[],this.events=[],this.duration=e}getDuration(){return this.duration}getEvents(){return this.events}forEachSample(e){const t=new Map;for(let n=0;n { + const [lo,] = binarySearch(0, text.length, (n) => { return cachedMeasureTextWidth(ctx, buildTrimmedText(text, n)) }, maxWidth) return buildTrimmedText(text, lo) @@ -246,7 +244,7 @@ interface FlamechartPanZoomViewProps { setNodeHover: (node: CallTreeNode | null, logicalViewSpacemous: Vec2) => void } -export class FlamechartPanZoomView extends Component { +export class FlamechartPanZoomView extends Component { renderer: ReglCommand | null = null ctx: WebGLRenderingContext | null = null @@ -265,9 +263,6 @@ export class FlamechartPanZoomView extends Component { this.container = container } + containerRef = (container?: Element) => { this.container = container as HTMLDivElement || null } render() { - const { flamechart } = this.props - return (
SpeedScope - diff --git a/index.tsx b/index.tsx index ab33f65..084f4e4 100644 --- a/index.tsx +++ b/index.tsx @@ -6,14 +6,12 @@ import {importFromBGFlameGraph} from './import/bg-flamegraph' import {Profile} from './profile' import {Flamechart, FlamechartView} from './flamechart' -import { request } from 'https'; - -interface ApplicaionState { +interface ApplicationState { profile: Profile | null flamechart: Flamechart | null } -class Application extends Component<{}, ApplicaionState> { +class Application extends Component<{}, ApplicationState> { onDrop = (ev: DragEvent) => { const reader = new FileReader reader.addEventListener('loadend', () => { diff --git a/package.json b/package.json index 592f614..cec82ac 100644 --- a/package.json +++ b/package.json @@ -4,26 +4,19 @@ "description": "", "main": "index.js", "scripts": { - "serve": "./serveit -i node_modules 'node_modules/.bin/rollup -c rollup.config.dev.js'", - "release": "rollup -c rollup.config.release.js" + "serve": "budo index.tsx --force-default-index --css reset.css -- -p tsify", + "release": "browserify index.tsx -p tsify | uglifyjs -cm > dist/speedscope.js" }, "author": "", "license": "MIT", "devDependencies": { - "@types/aphrodite": "^0.5.6", - "@types/react-dom": "^16.0.3", "aphrodite": "^1.2.5", - "preact": "^8.2.6", - "react": "^16.1.1", - "react-dom": "^16.1.1", + "browserify": "^14.5.0", + "budo": "^10.0.4", + "preact": "^8.2.7", "regl": "^1.3.0", - "rollup": "^0.51.5", - "rollup-plugin-commonjs": "^8.2.6", - "rollup-plugin-node-globals": "^1.1.0", - "rollup-plugin-node-resolve": "^3.0.0", - "rollup-plugin-replace": "^2.0.0", - "rollup-plugin-typescript": "^0.8.1", - "rollup-plugin-uglify-es": "0.0.1", - "typescript": "^2.6.1" + "tsify": "^3.0.4", + "typescript": "^2.6.1", + "uglify-es": "^3.2.2" } } diff --git a/profile.ts b/profile.ts index ae029b8..b51f3b4 100644 --- a/profile.ts +++ b/profile.ts @@ -115,6 +115,9 @@ export class Profile { this.duration = duration } + getDuration() { return this.duration } + getEvents() { return this.events } + forEachSample(fn: (stack: CallTreeNode[], timeDelta: number) => void) { const nodeToStack = new Map() for (let i = 0; i < this.samples.length; i++) { diff --git a/regl.d.ts b/regl.d.ts index dfea8fb..1553261 100644 --- a/regl.d.ts +++ b/regl.d.ts @@ -10,10 +10,6 @@ declare module "regl" { type ReglValue

= ReglPrimitiveValue | {(context: any, props: P, batchId: number): ReglPrimitiveValue} - export type vec2 = [number, number] - export type vec3 = [number, number, number] - export type mat3 = [number, number, number, number, number, number, number, number, number] - interface ReglCommandParameters

{ /** Source code of vertex shader */ vert: string @@ -35,21 +31,25 @@ declare module "regl" { offset?: number } - export interface ReglCommand

{ - (p: P): void - } - - export interface ReglCommandConstructor { -

(params: ReglCommandParameters

): ReglCommand

- } - - function ReglConstructor(): ReglCommandConstructor - function ReglConstructor(ctx: WebGLRenderingContext): ReglCommandConstructor - function ReglConstructor(canvas: HTMLCanvasElement): ReglCommandConstructor + function ReglConstructor(): ReglConstructor.ReglCommandConstructor + function ReglConstructor(ctx: WebGLRenderingContext): ReglConstructor.ReglCommandConstructor + function ReglConstructor(canvas: HTMLCanvasElement): ReglConstructor.ReglCommandConstructor namespace ReglConstructor { function prop(name: string): ReglProp + + export type vec2 = [number, number] + export type vec3 = [number, number, number] + export type mat3 = [number, number, number, number, number, number, number, number, number] + + interface ReglCommand

{ + (p: P): void + } + + interface ReglCommandConstructor { +

(params: ReglCommandParameters

): ReglCommand

+ } } - export default ReglConstructor + export = ReglConstructor } diff --git a/dev.html b/reset.css similarity index 73% rename from dev.html rename to reset.css index 6fa64f3..14bf909 100644 --- a/dev.html +++ b/reset.css @@ -1,11 +1,7 @@ - - - - - - - SpeedScope - - - -

- - - +} \ No newline at end of file diff --git a/rollup.config.common.js b/rollup.config.common.js deleted file mode 100644 index 3565c37..0000000 --- a/rollup.config.common.js +++ /dev/null @@ -1,42 +0,0 @@ -import commonjs from 'rollup-plugin-commonjs'; -import nodeResolve from 'rollup-plugin-node-resolve'; -import typescript from 'rollup-plugin-typescript'; -import replace from 'rollup-plugin-replace'; -import nodeGlobals from 'rollup-plugin-node-globals'; -import uglify from 'rollup-plugin-uglify-es'; - -export function config(isRelease) { - const plugins = [ - typescript({ - typescript: require('typescript') - }), - nodeResolve({ - jsnext: true, - main: true - }), - commonjs({ - include: 'node_modules/**', - namedExports: { - 'aphrodite': ['StyleSheet', 'css'], - 'react-dom': ['render'], - 'react': ['Component', 'createElement'] - }, - ignore: [ 'domain' ] - }), - replace({ - 'process.env.NODE_ENV': JSON.stringify(isRelease ? 'prod' : 'development') - }), - nodeGlobals() - ] - - if (isRelease) plugins.push(uglify()) - - return [{ - input: 'index.tsx', - output: { - file: isRelease ? 'dist/speedscope.js' : 'dist/speedscope-dev.js', - format: 'iife' - }, - plugins: plugins - }] -} diff --git a/rollup.config.dev.js b/rollup.config.dev.js deleted file mode 100644 index bef9f4d..0000000 --- a/rollup.config.dev.js +++ /dev/null @@ -1,2 +0,0 @@ -import {config} from './rollup.config.common.js' -export default config(false) diff --git a/rollup.config.release.js b/rollup.config.release.js deleted file mode 100644 index 26053fb..0000000 --- a/rollup.config.release.js +++ /dev/null @@ -1,2 +0,0 @@ -import {config} from './rollup.config.common.js' -export default config(true) diff --git a/serveit b/serveit deleted file mode 100755 index f179d20..0000000 --- a/serveit +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/env ruby - -# Copyright (c) 2015 Gary Bernhardt -# -# MIT License -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -require "find" -require "webrick" -require "open3" -require "optparse" - -class ServeIt - VERSION = [0, 0, 2] - - def self.main - serve_dir, ignored_paths, command = parse_opts - serve_dir = File.expand_path(serve_dir) - Server.new(serve_dir, ignored_paths, command).serve - end - - def self.parse_opts - options = {:serve_dir => ".", - :ignored_paths => []} - parser = OptionParser.new do |opts| - opts.banner = "Usage: #{$PROGRAM_NAME} [options] command" - opts.on_tail("-s", "--serve-dir DIR", "Root directory for server") do |dir| - options[:serve_dir] = dir - end - opts.on_tail("-i", "--ignore PATH", "Ignore changes to file or directory") do |path| - options[:ignored_paths] << path - end - opts.on_tail("--version", "Show version") do |dir| - puts ServeIt::VERSION.join('.') - exit - end - end - - begin - parser.parse!(ARGV) - rescue OptionParser::InvalidOption => e - $stderr.puts e - $stderr.puts parser - exit 1 - end - - if ARGV.count == 0 - command = nil - elsif ARGV.count == 1 - command = ARGV.fetch(0) - else - $stderr.write parser.to_s - exit 1 - end - - [options.fetch(:serve_dir), options.fetch(:ignored_paths), command] - end - - class Server - def initialize(serve_dir, ignored_paths, command) - @mutex = Mutex.new - @serve_dir = serve_dir - @command = command - @rebuilder = Rebuilder.new(@command, ignored_paths) if @command - end - - def serve - port = 8000 - puts "Starting server at http://localhost:#{port}" - server = WEBrick::HTTPServer.new(:Port => port) - - server.mount_proc '/' do |req, res| - relative_path = req.path.sub(/^\//, '') - local_abs_path = File.absolute_path(relative_path, @serve_dir) - - if relative_path == "favicon.ico" - respond_to_favicon(res) - else - respond_to_path(res, relative_path, local_abs_path) - end - end - - trap 'INT' do server.shutdown end - server.start - end - - def respond_to_favicon(res) - res.status = 404 - end - - def respond_to_path(res, relative_path, local_abs_path) - begin - rebuild_if_needed - rescue Rebuilder::RebuildFailed => e - return respond_to_error(res, e.to_s) - end - - if File.directory?(local_abs_path) - respond_to_dir(res, relative_path, local_abs_path) - else - # We're building a file - respond_to_file(res, local_abs_path) - end - end - - def respond_to_error(res, message) - res.content_type = "text/html" - res.body = "
" + message + "
" - end - - def respond_to_dir(res, rel_path, local_abs_path) - res.content_type = "text/html" - res.body = ( - "

Listing for /#{rel_path}

\n" + - Dir.entries(local_abs_path).select do |child| - child != "." - end.sort.map do |child| - full_child_path_on_server = File.join("/", rel_path, child) - %{#{child}
} - end.join("\n") - ) - end - - def respond_to_file(res, local_abs_path) - res.body = File.read(local_abs_path) - res.content_type = guess_content_type(local_abs_path) - end - - def guess_content_type(path) - extension = File.extname(path).sub(/^\./, '') - WEBrick::HTTPUtils::DefaultMimeTypes.fetch(extension) do - "application/octet-stream" - end - end - - def rebuild_if_needed - # Webrick is multi-threaded; guard against concurrent builds - @mutex.synchronize do - if @rebuilder - @rebuilder.rebuild_if_needed - end - end - end - end - - class Rebuilder - def initialize(command, ignored_paths) - @command = command - @ignored_paths = ignored_paths - @last_disk_state = nil - end - - def rebuild_if_needed - if disk_state != @last_disk_state - stdout_and_stderr, success = rebuild - if !success - message = "Failed to build! Command output:\n\n" + stdout_and_stderr - raise RebuildFailed.new(message) - end - - # Get a new post-build disk state so we don't pick up changes made during - # the build. - @last_disk_state = disk_state - [stdout_and_stderr, success] - end - end - - def rebuild - puts "Running command: #{@command}" - puts " begin build".rjust(80, "=") - start_time = Time.now - stdout_and_stderr, status = Open3.capture2e(@command) - print stdout_and_stderr - puts (" built in %.03fs" % (Time.now - start_time)).rjust(80, "=") - [stdout_and_stderr, status.success?] - end - - def disk_state - start_time = Time.now - paths = [] - - Find.find(".") do |path| - if ignore_path?(path) - Find.prune - else - paths << path - end - end - - paths.map do |path| - [path, File.stat(path).mtime.to_s] - end.sort.tap do - puts (" scanned in %.03fs" % (Time.now - start_time)).rjust(80, "=") - end - end - - def ignore_path?(path) - @ignored_paths.any? do |ignored_path| - File.absolute_path(path) == File.absolute_path(ignored_path) - end - end - - class RebuildFailed < RuntimeError; end - end -end - -if __FILE__ == $PROGRAM_NAME - ServeIt.main -end diff --git a/tsconfig.json b/tsconfig.json index b5fd812..96cd14b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "module": "commonjs", "strict": true, "jsx": "react", + "noUnusedLocals": true, "jsxFactory": "h", "target": "es2015" }