gpu.js/dist/gpu-browser.min.js
2019-10-11 07:28:02 -04:00

14 lines
366 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* gpu.js
* http://gpu.rocks/
*
* GPU Accelerated JavaScript
*
* @version 2.0.5
* @date Fri Oct 11 2019 07:23:40 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
*
* Copyright (c) 2019 gpu.js Team
*/!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).GPU=e()}}(function(){return function(){return function e(t,r,n){function i(a,o){if(!r[a]){if(!t[a]){var u="function"==typeof require&&require;if(!o&&u)return u(a,!0);if(s)return s(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var h=r[a]={exports:{}};t[a][0].call(h.exports,function(e){return i(t[a][1][e]||e)},h,h.exports,e,t,r,n)}return r[a].exports}for(var s="function"==typeof require&&require,a=0;a<n.length;a++)i(n[a]);return i}}()({1:[function(e,t,r){var n;n=this,function(e){"use strict";var t={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",5:"class enum extends super const export import",6:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"},r="break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",n={5:r,6:r+" const class extends export import super"},i=/^in(stanceof)?$/,s="ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈא-תׯ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࡠ-ࡪࢠ-ࢴࢶ-ࢽऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱৼਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡸᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-ᲈᲐ-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿯ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞹꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꣾꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭥꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA--zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ",a="‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛࣓-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳷-᳹᷀-᷹᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍--_",o=new RegExp("["+s+"]"),u=new RegExp("["+s+a+"]");s=a=null;var l=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,190,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541],h=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,280,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239];function c(e,t){for(var r=65536,n=0;n<t.length;n+=2){if((r+=t[n])>e)return!1;if((r+=t[n+1])>=e)return!0}}function p(e,t){return e<65?36===e:e<91||(e<97?95===e:e<123||(e<=65535?e>=170&&o.test(String.fromCharCode(e)):!1!==t&&c(e,l)))}function d(e,t){return e<48?36===e:e<58||!(e<65)&&(e<91||(e<97?95===e:e<123||(e<=65535?e>=170&&u.test(String.fromCharCode(e)):!1!==t&&(c(e,l)||c(e,h)))))}var m=function(e,t){void 0===t&&(t={}),this.label=e,this.keyword=t.keyword,this.beforeExpr=!!t.beforeExpr,this.startsExpr=!!t.startsExpr,this.isLoop=!!t.isLoop,this.isAssign=!!t.isAssign,this.prefix=!!t.prefix,this.postfix=!!t.postfix,this.binop=t.binop||null,this.updateContext=null};function g(e,t){return new m(e,{beforeExpr:!0,binop:t})}var f={beforeExpr:!0},x={startsExpr:!0},y={};function T(e,t){return void 0===t&&(t={}),t.keyword=e,y[e]=new m(e,t)}var b={num:new m("num",x),regexp:new m("regexp",x),string:new m("string",x),name:new m("name",x),eof:new m("eof"),bracketL:new m("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new m("]"),braceL:new m("{",{beforeExpr:!0,startsExpr:!0}),braceR:new m("}"),parenL:new m("(",{beforeExpr:!0,startsExpr:!0}),parenR:new m(")"),comma:new m(",",f),semi:new m(";",f),colon:new m(":",f),dot:new m("."),question:new m("?",f),arrow:new m("=>",f),template:new m("template"),invalidTemplate:new m("invalidTemplate"),ellipsis:new m("...",f),backQuote:new m("`",x),dollarBraceL:new m("${",{beforeExpr:!0,startsExpr:!0}),eq:new m("=",{beforeExpr:!0,isAssign:!0}),assign:new m("_=",{beforeExpr:!0,isAssign:!0}),incDec:new m("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new m("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:g("||",1),logicalAND:g("&&",2),bitwiseOR:g("|",3),bitwiseXOR:g("^",4),bitwiseAND:g("&",5),equality:g("==/!=/===/!==",6),relational:g("</>/<=/>=",7),bitShift:g("<</>>/>>>",8),plusMin:new m("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:g("%",10),star:g("*",10),slash:g("/",10),starstar:new m("**",{beforeExpr:!0}),_break:T("break"),_case:T("case",f),_catch:T("catch"),_continue:T("continue"),_debugger:T("debugger"),_default:T("default",f),_do:T("do",{isLoop:!0,beforeExpr:!0}),_else:T("else",f),_finally:T("finally"),_for:T("for",{isLoop:!0}),_function:T("function",x),_if:T("if"),_return:T("return",f),_switch:T("switch"),_throw:T("throw",f),_try:T("try"),_var:T("var"),_const:T("const"),_while:T("while",{isLoop:!0}),_with:T("with"),_new:T("new",{beforeExpr:!0,startsExpr:!0}),_this:T("this",x),_super:T("super",x),_class:T("class",x),_extends:T("extends",f),_export:T("export"),_import:T("import"),_null:T("null",x),_true:T("true",x),_false:T("false",x),_in:T("in",{beforeExpr:!0,binop:7}),_instanceof:T("instanceof",{beforeExpr:!0,binop:7}),_typeof:T("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:T("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:T("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},A=/\r\n?|\n|\u2028|\u2029/,v=new RegExp(A.source,"g");function S(e,t){return 10===e||13===e||!t&&(8232===e||8233===e)}var E=/[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/,_=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,w=Object.prototype,k=w.hasOwnProperty,D=w.toString;function I(e,t){return k.call(e,t)}var R=Array.isArray||function(e){return"[object Array]"===D.call(e)},L=function(e,t){this.line=e,this.column=t};L.prototype.offset=function(e){return new L(this.line,this.column+e)};var $=function(e,t,r){this.start=t,this.end=r,null!==e.sourceFile&&(this.source=e.sourceFile)};function C(e,t){for(var r=1,n=0;;){v.lastIndex=n;var i=v.exec(e);if(!(i&&i.index<t))return new L(r,t-n);++r,n=i.index+i[0].length}}var F={ecmaVersion:7,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:!1,allowHashBang:!1,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1,plugins:{}};function V(e){var t={};for(var r in F)t[r]=e&&I(e,r)?e[r]:F[r];if(t.ecmaVersion>=2015&&(t.ecmaVersion-=2009),null==t.allowReserved&&(t.allowReserved=t.ecmaVersion<5),R(t.onToken)){var n=t.onToken;t.onToken=function(e){return n.push(e)}}return R(t.onComment)&&(t.onComment=function(e,t){return function(r,n,i,s,a,o){var u={type:r?"Block":"Line",value:n,start:i,end:s};e.locations&&(u.loc=new $(this,a,o)),e.ranges&&(u.range=[i,s]),t.push(u)}}(t,t.onComment)),t}var N={};function O(e){return new RegExp("^(?:"+e.replace(/ /g,"|")+")$")}var M=function(e,r,i){this.options=e=V(e),this.sourceFile=e.sourceFile,this.keywords=O(n[e.ecmaVersion>=6?6:5]);var s="";if(!e.allowReserved){for(var a=e.ecmaVersion;!(s=t[a]);a--);"module"===e.sourceType&&(s+=" await")}this.reservedWords=O(s);var o=(s?s+" ":"")+t.strict;this.reservedWordsStrict=O(o),this.reservedWordsStrictBind=O(o+" "+t.strictBind),this.input=String(r),this.containsEsc=!1,this.loadPlugins(e.plugins),i?(this.pos=i,this.lineStart=this.input.lastIndexOf("\n",i-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(A).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=b.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule="module"===e.sourceType,this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.inFunction=this.inGenerator=this.inAsync=!1,this.yieldPos=this.awaitPos=0,this.labels=[],0===this.pos&&e.allowHashBang&&"#!"===this.input.slice(0,2)&&this.skipLineComment(2),this.scopeStack=[],this.enterFunctionScope(),this.regexpState=null};M.prototype.isKeyword=function(e){return this.keywords.test(e)},M.prototype.isReservedWord=function(e){return this.reservedWords.test(e)},M.prototype.extend=function(e,t){this[e]=t(this[e])},M.prototype.loadPlugins=function(e){for(var t in e){var r=N[t];if(!r)throw new Error("Plugin '"+t+"' not found");r(this,e[t])}},M.prototype.parse=function(){var e=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(e)};var z=M.prototype,P=/^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;function U(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1}z.strictDirective=function(e){for(;;){_.lastIndex=e,e+=_.exec(this.input)[0].length;var t=P.exec(this.input.slice(e));if(!t)return!1;if("use strict"===(t[1]||t[2]))return!0;e+=t[0].length}},z.eat=function(e){return this.type===e&&(this.next(),!0)},z.isContextual=function(e){return this.type===b.name&&this.value===e&&!this.containsEsc},z.eatContextual=function(e){return!!this.isContextual(e)&&(this.next(),!0)},z.expectContextual=function(e){this.eatContextual(e)||this.unexpected()},z.canInsertSemicolon=function(){return this.type===b.eof||this.type===b.braceR||A.test(this.input.slice(this.lastTokEnd,this.start))},z.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0},z.semicolon=function(){this.eat(b.semi)||this.insertSemicolon()||this.unexpected()},z.afterTrailingComma=function(e,t){if(this.type===e)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),t||this.next(),!0},z.expect=function(e){this.eat(e)||this.unexpected()},z.unexpected=function(e){this.raise(null!=e?e:this.start,"Unexpected token")},z.checkPatternErrors=function(e,t){if(e){e.trailingComma>-1&&this.raiseRecoverable(e.trailingComma,"Comma is not permitted after the rest element");var r=t?e.parenthesizedAssign:e.parenthesizedBind;r>-1&&this.raiseRecoverable(r,"Parenthesized pattern")}},z.checkExpressionErrors=function(e,t){if(!e)return!1;var r=e.shorthandAssign,n=e.doubleProto;if(!t)return r>=0||n>=0;r>=0&&this.raise(r,"Shorthand property assignments are valid only in destructuring patterns"),n>=0&&this.raiseRecoverable(n,"Redefinition of __proto__ property")},z.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos<this.awaitPos)&&this.raise(this.yieldPos,"Yield expression cannot be a default value"),this.awaitPos&&this.raise(this.awaitPos,"Await expression cannot be a default value")},z.isSimpleAssignTarget=function(e){return"ParenthesizedExpression"===e.type?this.isSimpleAssignTarget(e.expression):"Identifier"===e.type||"MemberExpression"===e.type};var G=M.prototype;G.parseTopLevel=function(e){var t={};for(e.body||(e.body=[]);this.type!==b.eof;){var r=this.parseStatement(!0,!0,t);e.body.push(r)}return this.adaptDirectivePrologue(e.body),this.next(),this.options.ecmaVersion>=6&&(e.sourceType=this.options.sourceType),this.finishNode(e,"Program")};var K={kind:"loop"},B={kind:"switch"};G.isLet=function(){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;_.lastIndex=this.pos;var e=_.exec(this.input),t=this.pos+e[0].length,r=this.input.charCodeAt(t);if(91===r||123===r)return!0;if(p(r,!0)){for(var n=t+1;d(this.input.charCodeAt(n),!0);)++n;var s=this.input.slice(t,n);if(!i.test(s))return!0}return!1},G.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;_.lastIndex=this.pos;var e=_.exec(this.input),t=this.pos+e[0].length;return!(A.test(this.input.slice(this.pos,t))||"function"!==this.input.slice(t,t+8)||t+8!==this.input.length&&d(this.input.charAt(t+8)))},G.parseStatement=function(e,t,r){var n,i=this.type,s=this.startNode();switch(this.isLet()&&(i=b._var,n="let"),i){case b._break:case b._continue:return this.parseBreakContinueStatement(s,i.keyword);case b._debugger:return this.parseDebuggerStatement(s);case b._do:return this.parseDoStatement(s);case b._for:return this.parseForStatement(s);case b._function:return!e&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(s,!1);case b._class:return e||this.unexpected(),this.parseClass(s,!0);case b._if:return this.parseIfStatement(s);case b._return:return this.parseReturnStatement(s);case b._switch:return this.parseSwitchStatement(s);case b._throw:return this.parseThrowStatement(s);case b._try:return this.parseTryStatement(s);case b._const:case b._var:return n=n||this.value,e||"var"===n||this.unexpected(),this.parseVarStatement(s,n);case b._while:return this.parseWhileStatement(s);case b._with:return this.parseWithStatement(s);case b.braceL:return this.parseBlock();case b.semi:return this.parseEmptyStatement(s);case b._export:case b._import:return this.options.allowImportExportEverywhere||(t||this.raise(this.start,"'import' and 'export' may only appear at the top level"),this.inModule||this.raise(this.start,"'import' and 'export' may appear only with 'sourceType: module'")),i===b._import?this.parseImport(s):this.parseExport(s,r);default:if(this.isAsyncFunction())return e||this.unexpected(),this.next(),this.parseFunctionStatement(s,!0);var a=this.value,o=this.parseExpression();return i===b.name&&"Identifier"===o.type&&this.eat(b.colon)?this.parseLabeledStatement(s,a,o):this.parseExpressionStatement(s,o)}},G.parseBreakContinueStatement=function(e,t){var r="break"===t;this.next(),this.eat(b.semi)||this.insertSemicolon()?e.label=null:this.type!==b.name?this.unexpected():(e.label=this.parseIdent(),this.semicolon());for(var n=0;n<this.labels.length;++n){var i=this.labels[n];if(null==e.label||i.name===e.label.name){if(null!=i.kind&&(r||"loop"===i.kind))break;if(e.label&&r)break}}return n===this.labels.length&&this.raise(e.start,"Unsyntactic "+t),this.finishNode(e,r?"BreakStatement":"ContinueStatement")},G.parseDebuggerStatement=function(e){return this.next(),this.semicolon(),this.finishNode(e,"DebuggerStatement")},G.parseDoStatement=function(e){return this.next(),this.labels.push(K),e.body=this.parseStatement(!1),this.labels.pop(),this.expect(b._while),e.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(b.semi):this.semicolon(),this.finishNode(e,"DoWhileStatement")},G.parseForStatement=function(e){this.next();var t=this.options.ecmaVersion>=9&&(this.inAsync||!this.inFunction&&this.options.allowAwaitOutsideFunction)&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(K),this.enterLexicalScope(),this.expect(b.parenL),this.type===b.semi)return t>-1&&this.unexpected(t),this.parseFor(e,null);var r=this.isLet();if(this.type===b._var||this.type===b._const||r){var n=this.startNode(),i=r?"let":this.value;return this.next(),this.parseVar(n,!0,i),this.finishNode(n,"VariableDeclaration"),!(this.type===b._in||this.options.ecmaVersion>=6&&this.isContextual("of"))||1!==n.declarations.length||"var"!==i&&n.declarations[0].init?(t>-1&&this.unexpected(t),this.parseFor(e,n)):(this.options.ecmaVersion>=9&&(this.type===b._in?t>-1&&this.unexpected(t):e.await=t>-1),this.parseForIn(e,n))}var s=new U,a=this.parseExpression(!0,s);return this.type===b._in||this.options.ecmaVersion>=6&&this.isContextual("of")?(this.options.ecmaVersion>=9&&(this.type===b._in?t>-1&&this.unexpected(t):e.await=t>-1),this.toAssignable(a,!1,s),this.checkLVal(a),this.parseForIn(e,a)):(this.checkExpressionErrors(s,!0),t>-1&&this.unexpected(t),this.parseFor(e,a))},G.parseFunctionStatement=function(e,t){return this.next(),this.parseFunction(e,!0,!1,t)},G.parseIfStatement=function(e){return this.next(),e.test=this.parseParenExpression(),e.consequent=this.parseStatement(!this.strict&&this.type===b._function),e.alternate=this.eat(b._else)?this.parseStatement(!this.strict&&this.type===b._function):null,this.finishNode(e,"IfStatement")},G.parseReturnStatement=function(e){return this.inFunction||this.options.allowReturnOutsideFunction||this.raise(this.start,"'return' outside of function"),this.next(),this.eat(b.semi)||this.insertSemicolon()?e.argument=null:(e.argument=this.parseExpression(),this.semicolon()),this.finishNode(e,"ReturnStatement")},G.parseSwitchStatement=function(e){var t;this.next(),e.discriminant=this.parseParenExpression(),e.cases=[],this.expect(b.braceL),this.labels.push(B),this.enterLexicalScope();for(var r=!1;this.type!==b.braceR;)if(this.type===b._case||this.type===b._default){var n=this.type===b._case;t&&this.finishNode(t,"SwitchCase"),e.cases.push(t=this.startNode()),t.consequent=[],this.next(),n?t.test=this.parseExpression():(r&&this.raiseRecoverable(this.lastTokStart,"Multiple default clauses"),r=!0,t.test=null),this.expect(b.colon)}else t||this.unexpected(),t.consequent.push(this.parseStatement(!0));return this.exitLexicalScope(),t&&this.finishNode(t,"SwitchCase"),this.next(),this.labels.pop(),this.finishNode(e,"SwitchStatement")},G.parseThrowStatement=function(e){return this.next(),A.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,"Illegal newline after throw"),e.argument=this.parseExpression(),this.semicolon(),this.finishNode(e,"ThrowStatement")};var W=[];G.parseTryStatement=function(e){if(this.next(),e.block=this.parseBlock(),e.handler=null,this.type===b._catch){var t=this.startNode();this.next(),this.eat(b.parenL)?(t.param=this.parseBindingAtom(),this.enterLexicalScope(),this.checkLVal(t.param,"let"),this.expect(b.parenR)):(this.options.ecmaVersion<10&&this.unexpected(),t.param=null,this.enterLexicalScope()),t.body=this.parseBlock(!1),this.exitLexicalScope(),e.handler=this.finishNode(t,"CatchClause")}return e.finalizer=this.eat(b._finally)?this.parseBlock():null,e.handler||e.finalizer||this.raise(e.start,"Missing catch or finally clause"),this.finishNode(e,"TryStatement")},G.parseVarStatement=function(e,t){return this.next(),this.parseVar(e,!1,t),this.semicolon(),this.finishNode(e,"VariableDeclaration")},G.parseWhileStatement=function(e){return this.next(),e.test=this.parseParenExpression(),this.labels.push(K),e.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(e,"WhileStatement")},G.parseWithStatement=function(e){return this.strict&&this.raise(this.start,"'with' in strict mode"),this.next(),e.object=this.parseParenExpression(),e.body=this.parseStatement(!1),this.finishNode(e,"WithStatement")},G.parseEmptyStatement=function(e){return this.next(),this.finishNode(e,"EmptyStatement")},G.parseLabeledStatement=function(e,t,r){for(var n=0,i=this.labels;n<i.length;n+=1){i[n].name===t&&this.raise(r.start,"Label '"+t+"' is already declared")}for(var s=this.type.isLoop?"loop":this.type===b._switch?"switch":null,a=this.labels.length-1;a>=0;a--){var o=this.labels[a];if(o.statementStart!==e.start)break;o.statementStart=this.start,o.kind=s}return this.labels.push({name:t,kind:s,statementStart:this.start}),e.body=this.parseStatement(!0),("ClassDeclaration"===e.body.type||"VariableDeclaration"===e.body.type&&"var"!==e.body.kind||"FunctionDeclaration"===e.body.type&&(this.strict||e.body.generator||e.body.async))&&this.raiseRecoverable(e.body.start,"Invalid labeled declaration"),this.labels.pop(),e.label=r,this.finishNode(e,"LabeledStatement")},G.parseExpressionStatement=function(e,t){return e.expression=t,this.semicolon(),this.finishNode(e,"ExpressionStatement")},G.parseBlock=function(e){void 0===e&&(e=!0);var t=this.startNode();for(t.body=[],this.expect(b.braceL),e&&this.enterLexicalScope();!this.eat(b.braceR);){var r=this.parseStatement(!0);t.body.push(r)}return e&&this.exitLexicalScope(),this.finishNode(t,"BlockStatement")},G.parseFor=function(e,t){return e.init=t,this.expect(b.semi),e.test=this.type===b.semi?null:this.parseExpression(),this.expect(b.semi),e.update=this.type===b.parenR?null:this.parseExpression(),this.expect(b.parenR),this.exitLexicalScope(),e.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(e,"ForStatement")},G.parseForIn=function(e,t){var r=this.type===b._in?"ForInStatement":"ForOfStatement";return this.next(),"ForInStatement"===r&&("AssignmentPattern"===t.type||"VariableDeclaration"===t.type&&null!=t.declarations[0].init&&(this.strict||"Identifier"!==t.declarations[0].id.type))&&this.raise(t.start,"Invalid assignment in for-in loop head"),e.left=t,e.right="ForInStatement"===r?this.parseExpression():this.parseMaybeAssign(),this.expect(b.parenR),this.exitLexicalScope(),e.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(e,r)},G.parseVar=function(e,t,r){for(e.declarations=[],e.kind=r;;){var n=this.startNode();if(this.parseVarId(n,r),this.eat(b.eq)?n.init=this.parseMaybeAssign(t):"const"!==r||this.type===b._in||this.options.ecmaVersion>=6&&this.isContextual("of")?"Identifier"===n.id.type||t&&(this.type===b._in||this.isContextual("of"))?n.init=null:this.raise(this.lastTokEnd,"Complex binding patterns require an initialization value"):this.unexpected(),e.declarations.push(this.finishNode(n,"VariableDeclarator")),!this.eat(b.comma))break}return e},G.parseVarId=function(e,t){e.id=this.parseBindingAtom(t),this.checkLVal(e.id,t,!1)},G.parseFunction=function(e,t,r,n){this.initFunction(e),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!n)&&(e.generator=this.eat(b.star)),this.options.ecmaVersion>=8&&(e.async=!!n),t&&(e.id="nullableID"===t&&this.type!==b.name?null:this.parseIdent(),e.id&&this.checkLVal(e.id,this.inModule&&!this.inFunction?"let":"var"));var i=this.inGenerator,s=this.inAsync,a=this.yieldPos,o=this.awaitPos,u=this.inFunction;return this.inGenerator=e.generator,this.inAsync=e.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,this.enterFunctionScope(),t||(e.id=this.type===b.name?this.parseIdent():null),this.parseFunctionParams(e),this.parseFunctionBody(e,r),this.inGenerator=i,this.inAsync=s,this.yieldPos=a,this.awaitPos=o,this.inFunction=u,this.finishNode(e,t?"FunctionDeclaration":"FunctionExpression")},G.parseFunctionParams=function(e){this.expect(b.parenL),e.params=this.parseBindingList(b.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()},G.parseClass=function(e,t){this.next(),this.parseClassId(e,t),this.parseClassSuper(e);var r=this.startNode(),n=!1;for(r.body=[],this.expect(b.braceL);!this.eat(b.braceR);){var i=this.parseClassMember(r);i&&"MethodDefinition"===i.type&&"constructor"===i.kind&&(n&&this.raise(i.start,"Duplicate constructor in the same class"),n=!0)}return e.body=this.finishNode(r,"ClassBody"),this.finishNode(e,t?"ClassDeclaration":"ClassExpression")},G.parseClassMember=function(e){var t=this;if(this.eat(b.semi))return null;var r=this.startNode(),n=function(e,n){void 0===n&&(n=!1);var i=t.start,s=t.startLoc;return!!t.eatContextual(e)&&(!(t.type===b.parenL||n&&t.canInsertSemicolon())||(r.key&&t.unexpected(),r.computed=!1,r.key=t.startNodeAt(i,s),r.key.name=e,t.finishNode(r.key,"Identifier"),!1))};r.kind="method",r.static=n("static");var i=this.eat(b.star),s=!1;i||(this.options.ecmaVersion>=8&&n("async",!0)?(s=!0,i=this.options.ecmaVersion>=9&&this.eat(b.star)):n("get")?r.kind="get":n("set")&&(r.kind="set")),r.key||this.parsePropertyName(r);var a=r.key;return r.computed||r.static||!("Identifier"===a.type&&"constructor"===a.name||"Literal"===a.type&&"constructor"===a.value)?r.static&&"Identifier"===a.type&&"prototype"===a.name&&this.raise(a.start,"Classes may not have a static property named prototype"):("method"!==r.kind&&this.raise(a.start,"Constructor can't have get/set modifier"),i&&this.raise(a.start,"Constructor can't be a generator"),s&&this.raise(a.start,"Constructor can't be an async method"),r.kind="constructor"),this.parseClassMethod(e,r,i,s),"get"===r.kind&&0!==r.value.params.length&&this.raiseRecoverable(r.value.start,"getter should have no params"),"set"===r.kind&&1!==r.value.params.length&&this.raiseRecoverable(r.value.start,"setter should have exactly one param"),"set"===r.kind&&"RestElement"===r.value.params[0].type&&this.raiseRecoverable(r.value.params[0].start,"Setter cannot use rest params"),r},G.parseClassMethod=function(e,t,r,n){t.value=this.parseMethod(r,n),e.body.push(this.finishNode(t,"MethodDefinition"))},G.parseClassId=function(e,t){e.id=this.type===b.name?this.parseIdent():!0===t?this.unexpected():null},G.parseClassSuper=function(e){e.superClass=this.eat(b._extends)?this.parseExprSubscripts():null},G.parseExport=function(e,t){if(this.next(),this.eat(b.star))return this.expectContextual("from"),this.type!==b.string&&this.unexpected(),e.source=this.parseExprAtom(),this.semicolon(),this.finishNode(e,"ExportAllDeclaration");if(this.eat(b._default)){var r;if(this.checkExport(t,"default",this.lastTokStart),this.type===b._function||(r=this.isAsyncFunction())){var n=this.startNode();this.next(),r&&this.next(),e.declaration=this.parseFunction(n,"nullableID",!1,r)}else if(this.type===b._class){var i=this.startNode();e.declaration=this.parseClass(i,"nullableID")}else e.declaration=this.parseMaybeAssign(),this.semicolon();return this.finishNode(e,"ExportDefaultDeclaration")}if(this.shouldParseExportStatement())e.declaration=this.parseStatement(!0),"VariableDeclaration"===e.declaration.type?this.checkVariableExport(t,e.declaration.declarations):this.checkExport(t,e.declaration.id.name,e.declaration.id.start),e.specifiers=[],e.source=null;else{if(e.declaration=null,e.specifiers=this.parseExportSpecifiers(t),this.eatContextual("from"))this.type!==b.string&&this.unexpected(),e.source=this.parseExprAtom();else{for(var s=0,a=e.specifiers;s<a.length;s+=1){var o=a[s];this.checkUnreserved(o.local)}e.source=null}this.semicolon()}return this.finishNode(e,"ExportNamedDeclaration")},G.checkExport=function(e,t,r){e&&(I(e,t)&&this.raiseRecoverable(r,"Duplicate export '"+t+"'"),e[t]=!0)},G.checkPatternExport=function(e,t){var r=t.type;if("Identifier"===r)this.checkExport(e,t.name,t.start);else if("ObjectPattern"===r)for(var n=0,i=t.properties;n<i.length;n+=1){var s=i[n];this.checkPatternExport(e,s)}else if("ArrayPattern"===r)for(var a=0,o=t.elements;a<o.length;a+=1){var u=o[a];u&&this.checkPatternExport(e,u)}else"Property"===r?this.checkPatternExport(e,t.value):"AssignmentPattern"===r?this.checkPatternExport(e,t.left):"RestElement"===r?this.checkPatternExport(e,t.argument):"ParenthesizedExpression"===r&&this.checkPatternExport(e,t.expression)},G.checkVariableExport=function(e,t){if(e)for(var r=0,n=t;r<n.length;r+=1){var i=n[r];this.checkPatternExport(e,i.id)}},G.shouldParseExportStatement=function(){return"var"===this.type.keyword||"const"===this.type.keyword||"class"===this.type.keyword||"function"===this.type.keyword||this.isLet()||this.isAsyncFunction()},G.parseExportSpecifiers=function(e){var t=[],r=!0;for(this.expect(b.braceL);!this.eat(b.braceR);){if(r)r=!1;else if(this.expect(b.comma),this.afterTrailingComma(b.braceR))break;var n=this.startNode();n.local=this.parseIdent(!0),n.exported=this.eatContextual("as")?this.parseIdent(!0):n.local,this.checkExport(e,n.exported.name,n.exported.start),t.push(this.finishNode(n,"ExportSpecifier"))}return t},G.parseImport=function(e){return this.next(),this.type===b.string?(e.specifiers=W,e.source=this.parseExprAtom()):(e.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),e.source=this.type===b.string?this.parseExprAtom():this.unexpected()),this.semicolon(),this.finishNode(e,"ImportDeclaration")},G.parseImportSpecifiers=function(){var e=[],t=!0;if(this.type===b.name){var r=this.startNode();if(r.local=this.parseIdent(),this.checkLVal(r.local,"let"),e.push(this.finishNode(r,"ImportDefaultSpecifier")),!this.eat(b.comma))return e}if(this.type===b.star){var n=this.startNode();return this.next(),this.expectContextual("as"),n.local=this.parseIdent(),this.checkLVal(n.local,"let"),e.push(this.finishNode(n,"ImportNamespaceSpecifier")),e}for(this.expect(b.braceL);!this.eat(b.braceR);){if(t)t=!1;else if(this.expect(b.comma),this.afterTrailingComma(b.braceR))break;var i=this.startNode();i.imported=this.parseIdent(!0),this.eatContextual("as")?i.local=this.parseIdent():(this.checkUnreserved(i.imported),i.local=i.imported),this.checkLVal(i.local,"let"),e.push(this.finishNode(i,"ImportSpecifier"))}return e},G.adaptDirectivePrologue=function(e){for(var t=0;t<e.length&&this.isDirectiveCandidate(e[t]);++t)e[t].directive=e[t].expression.raw.slice(1,-1)},G.isDirectiveCandidate=function(e){return"ExpressionStatement"===e.type&&"Literal"===e.expression.type&&"string"==typeof e.expression.value&&('"'===this.input[e.start]||"'"===this.input[e.start])};var j=M.prototype;j.toAssignable=function(e,t,r){if(this.options.ecmaVersion>=6&&e)switch(e.type){case"Identifier":this.inAsync&&"await"===e.name&&this.raise(e.start,"Can not use 'await' as identifier inside an async function");break;case"ObjectPattern":case"ArrayPattern":case"RestElement":break;case"ObjectExpression":e.type="ObjectPattern",r&&this.checkPatternErrors(r,!0);for(var n=0,i=e.properties;n<i.length;n+=1){var s=i[n];this.toAssignable(s,t),"RestElement"!==s.type||"ArrayPattern"!==s.argument.type&&"ObjectPattern"!==s.argument.type||this.raise(s.argument.start,"Unexpected token")}break;case"Property":"init"!==e.kind&&this.raise(e.key.start,"Object pattern can't contain getter or setter"),this.toAssignable(e.value,t);break;case"ArrayExpression":e.type="ArrayPattern",r&&this.checkPatternErrors(r,!0),this.toAssignableList(e.elements,t);break;case"SpreadElement":e.type="RestElement",this.toAssignable(e.argument,t),"AssignmentPattern"===e.argument.type&&this.raise(e.argument.start,"Rest elements cannot have a default value");break;case"AssignmentExpression":"="!==e.operator&&this.raise(e.left.end,"Only '=' operator can be used for specifying default value."),e.type="AssignmentPattern",delete e.operator,this.toAssignable(e.left,t);case"AssignmentPattern":break;case"ParenthesizedExpression":this.toAssignable(e.expression,t);break;case"MemberExpression":if(!t)break;default:this.raise(e.start,"Assigning to rvalue")}else r&&this.checkPatternErrors(r,!0);return e},j.toAssignableList=function(e,t){for(var r=e.length,n=0;n<r;n++){var i=e[n];i&&this.toAssignable(i,t)}if(r){var s=e[r-1];6===this.options.ecmaVersion&&t&&s&&"RestElement"===s.type&&"Identifier"!==s.argument.type&&this.unexpected(s.argument.start)}return e},j.parseSpread=function(e){var t=this.startNode();return this.next(),t.argument=this.parseMaybeAssign(!1,e),this.finishNode(t,"SpreadElement")},j.parseRestBinding=function(){var e=this.startNode();return this.next(),6===this.options.ecmaVersion&&this.type!==b.name&&this.unexpected(),e.argument=this.parseBindingAtom(),this.finishNode(e,"RestElement")},j.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case b.bracketL:var e=this.startNode();return this.next(),e.elements=this.parseBindingList(b.bracketR,!0,!0),this.finishNode(e,"ArrayPattern");case b.braceL:return this.parseObj(!0)}return this.parseIdent()},j.parseBindingList=function(e,t,r){for(var n=[],i=!0;!this.eat(e);)if(i?i=!1:this.expect(b.comma),t&&this.type===b.comma)n.push(null);else{if(r&&this.afterTrailingComma(e))break;if(this.type===b.ellipsis){var s=this.parseRestBinding();this.parseBindingListItem(s),n.push(s),this.type===b.comma&&this.raise(this.start,"Comma is not permitted after the rest element"),this.expect(e);break}var a=this.parseMaybeDefault(this.start,this.startLoc);this.parseBindingListItem(a),n.push(a)}return n},j.parseBindingListItem=function(e){return e},j.parseMaybeDefault=function(e,t,r){if(r=r||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(b.eq))return r;var n=this.startNodeAt(e,t);return n.left=r,n.right=this.parseMaybeAssign(),this.finishNode(n,"AssignmentPattern")},j.checkLVal=function(e,t,r){switch(e.type){case"Identifier":this.strict&&this.reservedWordsStrictBind.test(e.name)&&this.raiseRecoverable(e.start,(t?"Binding ":"Assigning to ")+e.name+" in strict mode"),r&&(I(r,e.name)&&this.raiseRecoverable(e.start,"Argument name clash"),r[e.name]=!0),t&&"none"!==t&&(("var"===t&&!this.canDeclareVarName(e.name)||"var"!==t&&!this.canDeclareLexicalName(e.name))&&this.raiseRecoverable(e.start,"Identifier '"+e.name+"' has already been declared"),"var"===t?this.declareVarName(e.name):this.declareLexicalName(e.name));break;case"MemberExpression":t&&this.raiseRecoverable(e.start,"Binding member expression");break;case"ObjectPattern":for(var n=0,i=e.properties;n<i.length;n+=1){var s=i[n];this.checkLVal(s,t,r)}break;case"Property":this.checkLVal(e.value,t,r);break;case"ArrayPattern":for(var a=0,o=e.elements;a<o.length;a+=1){var u=o[a];u&&this.checkLVal(u,t,r)}break;case"AssignmentPattern":this.checkLVal(e.left,t,r);break;case"RestElement":this.checkLVal(e.argument,t,r);break;case"ParenthesizedExpression":this.checkLVal(e.expression,t,r);break;default:this.raise(e.start,(t?"Binding":"Assigning to")+" rvalue")}};var X=M.prototype;X.checkPropClash=function(e,t,r){if(!(this.options.ecmaVersion>=9&&"SpreadElement"===e.type||this.options.ecmaVersion>=6&&(e.computed||e.method||e.shorthand))){var n,i=e.key;switch(i.type){case"Identifier":n=i.name;break;case"Literal":n=String(i.value);break;default:return}var s=e.kind;if(this.options.ecmaVersion>=6)"__proto__"===n&&"init"===s&&(t.proto&&(r&&r.doubleProto<0?r.doubleProto=i.start:this.raiseRecoverable(i.start,"Redefinition of __proto__ property")),t.proto=!0);else{var a=t[n="$"+n];if(a)("init"===s?this.strict&&a.init||a.get||a.set:a.init||a[s])&&this.raiseRecoverable(i.start,"Redefinition of property");else a=t[n]={init:!1,get:!1,set:!1};a[s]=!0}}},X.parseExpression=function(e,t){var r=this.start,n=this.startLoc,i=this.parseMaybeAssign(e,t);if(this.type===b.comma){var s=this.startNodeAt(r,n);for(s.expressions=[i];this.eat(b.comma);)s.expressions.push(this.parseMaybeAssign(e,t));return this.finishNode(s,"SequenceExpression")}return i},X.parseMaybeAssign=function(e,t,r){if(this.inGenerator&&this.isContextual("yield"))return this.parseYield();var n=!1,i=-1,s=-1;t?(i=t.parenthesizedAssign,s=t.trailingComma,t.parenthesizedAssign=t.trailingComma=-1):(t=new U,n=!0);var a=this.start,o=this.startLoc;this.type!==b.parenL&&this.type!==b.name||(this.potentialArrowAt=this.start);var u=this.parseMaybeConditional(e,t);if(r&&(u=r.call(this,u,a,o)),this.type.isAssign){var l=this.startNodeAt(a,o);return l.operator=this.value,l.left=this.type===b.eq?this.toAssignable(u,!1,t):u,n||U.call(t),t.shorthandAssign=-1,this.checkLVal(u),this.next(),l.right=this.parseMaybeAssign(e),this.finishNode(l,"AssignmentExpression")}return n&&this.checkExpressionErrors(t,!0),i>-1&&(t.parenthesizedAssign=i),s>-1&&(t.trailingComma=s),u},X.parseMaybeConditional=function(e,t){var r=this.start,n=this.startLoc,i=this.parseExprOps(e,t);if(this.checkExpressionErrors(t))return i;if(this.eat(b.question)){var s=this.startNodeAt(r,n);return s.test=i,s.consequent=this.parseMaybeAssign(),this.expect(b.colon),s.alternate=this.parseMaybeAssign(e),this.finishNode(s,"ConditionalExpression")}return i},X.parseExprOps=function(e,t){var r=this.start,n=this.startLoc,i=this.parseMaybeUnary(t,!1);return this.checkExpressionErrors(t)?i:i.start===r&&"ArrowFunctionExpression"===i.type?i:this.parseExprOp(i,r,n,-1,e)},X.parseExprOp=function(e,t,r,n,i){var s=this.type.binop;if(null!=s&&(!i||this.type!==b._in)&&s>n){var a=this.type===b.logicalOR||this.type===b.logicalAND,o=this.value;this.next();var u=this.start,l=this.startLoc,h=this.parseExprOp(this.parseMaybeUnary(null,!1),u,l,s,i),c=this.buildBinary(t,r,e,h,o,a);return this.parseExprOp(c,t,r,n,i)}return e},X.buildBinary=function(e,t,r,n,i,s){var a=this.startNodeAt(e,t);return a.left=r,a.operator=i,a.right=n,this.finishNode(a,s?"LogicalExpression":"BinaryExpression")},X.parseMaybeUnary=function(e,t){var r,n=this.start,i=this.startLoc;if(this.isContextual("await")&&(this.inAsync||!this.inFunction&&this.options.allowAwaitOutsideFunction))r=this.parseAwait(),t=!0;else if(this.type.prefix){var s=this.startNode(),a=this.type===b.incDec;s.operator=this.value,s.prefix=!0,this.next(),s.argument=this.parseMaybeUnary(null,!0),this.checkExpressionErrors(e,!0),a?this.checkLVal(s.argument):this.strict&&"delete"===s.operator&&"Identifier"===s.argument.type?this.raiseRecoverable(s.start,"Deleting local variable in strict mode"):t=!0,r=this.finishNode(s,a?"UpdateExpression":"UnaryExpression")}else{if(r=this.parseExprSubscripts(e),this.checkExpressionErrors(e))return r;for(;this.type.postfix&&!this.canInsertSemicolon();){var o=this.startNodeAt(n,i);o.operator=this.value,o.prefix=!1,o.argument=r,this.checkLVal(r),this.next(),r=this.finishNode(o,"UpdateExpression")}}return!t&&this.eat(b.starstar)?this.buildBinary(n,i,r,this.parseMaybeUnary(null,!1),"**",!1):r},X.parseExprSubscripts=function(e){var t=this.start,r=this.startLoc,n=this.parseExprAtom(e),i="ArrowFunctionExpression"===n.type&&")"!==this.input.slice(this.lastTokStart,this.lastTokEnd);if(this.checkExpressionErrors(e)||i)return n;var s=this.parseSubscripts(n,t,r);return e&&"MemberExpression"===s.type&&(e.parenthesizedAssign>=s.start&&(e.parenthesizedAssign=-1),e.parenthesizedBind>=s.start&&(e.parenthesizedBind=-1)),s},X.parseSubscripts=function(e,t,r,n){for(var i=this.options.ecmaVersion>=8&&"Identifier"===e.type&&"async"===e.name&&this.lastTokEnd===e.end&&!this.canInsertSemicolon()&&"async"===this.input.slice(e.start,e.end),s=void 0;;)if((s=this.eat(b.bracketL))||this.eat(b.dot)){var a=this.startNodeAt(t,r);a.object=e,a.property=s?this.parseExpression():this.parseIdent(!0),a.computed=!!s,s&&this.expect(b.bracketR),e=this.finishNode(a,"MemberExpression")}else if(!n&&this.eat(b.parenL)){var o=new U,u=this.yieldPos,l=this.awaitPos;this.yieldPos=0,this.awaitPos=0;var h=this.parseExprList(b.parenR,this.options.ecmaVersion>=8,!1,o);if(i&&!this.canInsertSemicolon()&&this.eat(b.arrow))return this.checkPatternErrors(o,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=u,this.awaitPos=l,this.parseArrowExpression(this.startNodeAt(t,r),h,!0);this.checkExpressionErrors(o,!0),this.yieldPos=u||this.yieldPos,this.awaitPos=l||this.awaitPos;var c=this.startNodeAt(t,r);c.callee=e,c.arguments=h,e=this.finishNode(c,"CallExpression")}else{if(this.type!==b.backQuote)return e;var p=this.startNodeAt(t,r);p.tag=e,p.quasi=this.parseTemplate({isTagged:!0}),e=this.finishNode(p,"TaggedTemplateExpression")}},X.parseExprAtom=function(e){var t,r=this.potentialArrowAt===this.start;switch(this.type){case b._super:return this.inFunction||this.raise(this.start,"'super' outside of function or class"),t=this.startNode(),this.next(),this.type!==b.dot&&this.type!==b.bracketL&&this.type!==b.parenL&&this.unexpected(),this.finishNode(t,"Super");case b._this:return t=this.startNode(),this.next(),this.finishNode(t,"ThisExpression");case b.name:var n=this.start,i=this.startLoc,s=this.containsEsc,a=this.parseIdent(this.type!==b.name);if(this.options.ecmaVersion>=8&&!s&&"async"===a.name&&!this.canInsertSemicolon()&&this.eat(b._function))return this.parseFunction(this.startNodeAt(n,i),!1,!1,!0);if(r&&!this.canInsertSemicolon()){if(this.eat(b.arrow))return this.parseArrowExpression(this.startNodeAt(n,i),[a],!1);if(this.options.ecmaVersion>=8&&"async"===a.name&&this.type===b.name&&!s)return a=this.parseIdent(),!this.canInsertSemicolon()&&this.eat(b.arrow)||this.unexpected(),this.parseArrowExpression(this.startNodeAt(n,i),[a],!0)}return a;case b.regexp:var o=this.value;return(t=this.parseLiteral(o.value)).regex={pattern:o.pattern,flags:o.flags},t;case b.num:case b.string:return this.parseLiteral(this.value);case b._null:case b._true:case b._false:return(t=this.startNode()).value=this.type===b._null?null:this.type===b._true,t.raw=this.type.keyword,this.next(),this.finishNode(t,"Literal");case b.parenL:var u=this.start,l=this.parseParenAndDistinguishExpression(r);return e&&(e.parenthesizedAssign<0&&!this.isSimpleAssignTarget(l)&&(e.parenthesizedAssign=u),e.parenthesizedBind<0&&(e.parenthesizedBind=u)),l;case b.bracketL:return t=this.startNode(),this.next(),t.elements=this.parseExprList(b.bracketR,!0,!0,e),this.finishNode(t,"ArrayExpression");case b.braceL:return this.parseObj(!1,e);case b._function:return t=this.startNode(),this.next(),this.parseFunction(t,!1);case b._class:return this.parseClass(this.startNode(),!1);case b._new:return this.parseNew();case b.backQuote:return this.parseTemplate();default:this.unexpected()}},X.parseLiteral=function(e){var t=this.startNode();return t.value=e,t.raw=this.input.slice(this.start,this.end),this.next(),this.finishNode(t,"Literal")},X.parseParenExpression=function(){this.expect(b.parenL);var e=this.parseExpression();return this.expect(b.parenR),e},X.parseParenAndDistinguishExpression=function(e){var t,r=this.start,n=this.startLoc,i=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var s,a=this.start,o=this.startLoc,u=[],l=!0,h=!1,c=new U,p=this.yieldPos,d=this.awaitPos;for(this.yieldPos=0,this.awaitPos=0;this.type!==b.parenR;){if(l?l=!1:this.expect(b.comma),i&&this.afterTrailingComma(b.parenR,!0)){h=!0;break}if(this.type===b.ellipsis){s=this.start,u.push(this.parseParenItem(this.parseRestBinding())),this.type===b.comma&&this.raise(this.start,"Comma is not permitted after the rest element");break}u.push(this.parseMaybeAssign(!1,c,this.parseParenItem))}var m=this.start,g=this.startLoc;if(this.expect(b.parenR),e&&!this.canInsertSemicolon()&&this.eat(b.arrow))return this.checkPatternErrors(c,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=p,this.awaitPos=d,this.parseParenArrowList(r,n,u);u.length&&!h||this.unexpected(this.lastTokStart),s&&this.unexpected(s),this.checkExpressionErrors(c,!0),this.yieldPos=p||this.yieldPos,this.awaitPos=d||this.awaitPos,u.length>1?((t=this.startNodeAt(a,o)).expressions=u,this.finishNodeAt(t,"SequenceExpression",m,g)):t=u[0]}else t=this.parseParenExpression();if(this.options.preserveParens){var f=this.startNodeAt(r,n);return f.expression=t,this.finishNode(f,"ParenthesizedExpression")}return t},X.parseParenItem=function(e){return e},X.parseParenArrowList=function(e,t,r){return this.parseArrowExpression(this.startNodeAt(e,t),r)};var H=[];X.parseNew=function(){var e=this.startNode(),t=this.parseIdent(!0);if(this.options.ecmaVersion>=6&&this.eat(b.dot)){e.meta=t;var r=this.containsEsc;return e.property=this.parseIdent(!0),("target"!==e.property.name||r)&&this.raiseRecoverable(e.property.start,"The only valid meta property for new is new.target"),this.inFunction||this.raiseRecoverable(e.start,"new.target can only be used in functions"),this.finishNode(e,"MetaProperty")}var n=this.start,i=this.startLoc;return e.callee=this.parseSubscripts(this.parseExprAtom(),n,i,!0),this.eat(b.parenL)?e.arguments=this.parseExprList(b.parenR,this.options.ecmaVersion>=8,!1):e.arguments=H,this.finishNode(e,"NewExpression")},X.parseTemplateElement=function(e){var t=e.isTagged,r=this.startNode();return this.type===b.invalidTemplate?(t||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),r.value={raw:this.value,cooked:null}):r.value={raw:this.input.slice(this.start,this.end).replace(/\r\n?/g,"\n"),cooked:this.value},this.next(),r.tail=this.type===b.backQuote,this.finishNode(r,"TemplateElement")},X.parseTemplate=function(e){void 0===e&&(e={});var t=e.isTagged;void 0===t&&(t=!1);var r=this.startNode();this.next(),r.expressions=[];var n=this.parseTemplateElement({isTagged:t});for(r.quasis=[n];!n.tail;)this.type===b.eof&&this.raise(this.pos,"Unterminated template literal"),this.expect(b.dollarBraceL),r.expressions.push(this.parseExpression()),this.expect(b.braceR),r.quasis.push(n=this.parseTemplateElement({isTagged:t}));return this.next(),this.finishNode(r,"TemplateLiteral")},X.isAsyncProp=function(e){return!e.computed&&"Identifier"===e.key.type&&"async"===e.key.name&&(this.type===b.name||this.type===b.num||this.type===b.string||this.type===b.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===b.star)&&!A.test(this.input.slice(this.lastTokEnd,this.start))},X.parseObj=function(e,t){var r=this.startNode(),n=!0,i={};for(r.properties=[],this.next();!this.eat(b.braceR);){if(n)n=!1;else if(this.expect(b.comma),this.afterTrailingComma(b.braceR))break;var s=this.parseProperty(e,t);e||this.checkPropClash(s,i,t),r.properties.push(s)}return this.finishNode(r,e?"ObjectPattern":"ObjectExpression")},X.parseProperty=function(e,t){var r,n,i,s,a=this.startNode();if(this.options.ecmaVersion>=9&&this.eat(b.ellipsis))return e?(a.argument=this.parseIdent(!1),this.type===b.comma&&this.raise(this.start,"Comma is not permitted after the rest element"),this.finishNode(a,"RestElement")):(this.type===b.parenL&&t&&(t.parenthesizedAssign<0&&(t.parenthesizedAssign=this.start),t.parenthesizedBind<0&&(t.parenthesizedBind=this.start)),a.argument=this.parseMaybeAssign(!1,t),this.type===b.comma&&t&&t.trailingComma<0&&(t.trailingComma=this.start),this.finishNode(a,"SpreadElement"));this.options.ecmaVersion>=6&&(a.method=!1,a.shorthand=!1,(e||t)&&(i=this.start,s=this.startLoc),e||(r=this.eat(b.star)));var o=this.containsEsc;return this.parsePropertyName(a),!e&&!o&&this.options.ecmaVersion>=8&&!r&&this.isAsyncProp(a)?(n=!0,r=this.options.ecmaVersion>=9&&this.eat(b.star),this.parsePropertyName(a,t)):n=!1,this.parsePropertyValue(a,e,r,n,i,s,t,o),this.finishNode(a,"Property")},X.parsePropertyValue=function(e,t,r,n,i,s,a,o){if((r||n)&&this.type===b.colon&&this.unexpected(),this.eat(b.colon))e.value=t?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,a),e.kind="init";else if(this.options.ecmaVersion>=6&&this.type===b.parenL)t&&this.unexpected(),e.kind="init",e.method=!0,e.value=this.parseMethod(r,n);else if(t||o||!(this.options.ecmaVersion>=5)||e.computed||"Identifier"!==e.key.type||"get"!==e.key.name&&"set"!==e.key.name||this.type===b.comma||this.type===b.braceR)this.options.ecmaVersion>=6&&!e.computed&&"Identifier"===e.key.type?(this.checkUnreserved(e.key),e.kind="init",t?e.value=this.parseMaybeDefault(i,s,e.key):this.type===b.eq&&a?(a.shorthandAssign<0&&(a.shorthandAssign=this.start),e.value=this.parseMaybeDefault(i,s,e.key)):e.value=e.key,e.shorthand=!0):this.unexpected();else{(r||n)&&this.unexpected(),e.kind=e.key.name,this.parsePropertyName(e),e.value=this.parseMethod(!1);var u="get"===e.kind?0:1;if(e.value.params.length!==u){var l=e.value.start;"get"===e.kind?this.raiseRecoverable(l,"getter should have no params"):this.raiseRecoverable(l,"setter should have exactly one param")}else"set"===e.kind&&"RestElement"===e.value.params[0].type&&this.raiseRecoverable(e.value.params[0].start,"Setter cannot use rest params")}},X.parsePropertyName=function(e){if(this.options.ecmaVersion>=6){if(this.eat(b.bracketL))return e.computed=!0,e.key=this.parseMaybeAssign(),this.expect(b.bracketR),e.key;e.computed=!1}return e.key=this.type===b.num||this.type===b.string?this.parseExprAtom():this.parseIdent(!0)},X.initFunction=function(e){e.id=null,this.options.ecmaVersion>=6&&(e.generator=!1,e.expression=!1),this.options.ecmaVersion>=8&&(e.async=!1)},X.parseMethod=function(e,t){var r=this.startNode(),n=this.inGenerator,i=this.inAsync,s=this.yieldPos,a=this.awaitPos,o=this.inFunction;return this.initFunction(r),this.options.ecmaVersion>=6&&(r.generator=e),this.options.ecmaVersion>=8&&(r.async=!!t),this.inGenerator=r.generator,this.inAsync=r.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,this.enterFunctionScope(),this.expect(b.parenL),r.params=this.parseBindingList(b.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(r,!1),this.inGenerator=n,this.inAsync=i,this.yieldPos=s,this.awaitPos=a,this.inFunction=o,this.finishNode(r,"FunctionExpression")},X.parseArrowExpression=function(e,t,r){var n=this.inGenerator,i=this.inAsync,s=this.yieldPos,a=this.awaitPos,o=this.inFunction;return this.enterFunctionScope(),this.initFunction(e),this.options.ecmaVersion>=8&&(e.async=!!r),this.inGenerator=!1,this.inAsync=e.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,e.params=this.toAssignableList(t,!0),this.parseFunctionBody(e,!0),this.inGenerator=n,this.inAsync=i,this.yieldPos=s,this.awaitPos=a,this.inFunction=o,this.finishNode(e,"ArrowFunctionExpression")},X.parseFunctionBody=function(e,t){var r=t&&this.type!==b.braceL,n=this.strict,i=!1;if(r)e.body=this.parseMaybeAssign(),e.expression=!0,this.checkParams(e,!1);else{var s=this.options.ecmaVersion>=7&&!this.isSimpleParamList(e.params);n&&!s||(i=this.strictDirective(this.end))&&s&&this.raiseRecoverable(e.start,"Illegal 'use strict' directive in function with non-simple parameter list");var a=this.labels;this.labels=[],i&&(this.strict=!0),this.checkParams(e,!n&&!i&&!t&&this.isSimpleParamList(e.params)),e.body=this.parseBlock(!1),e.expression=!1,this.adaptDirectivePrologue(e.body.body),this.labels=a}this.exitFunctionScope(),this.strict&&e.id&&this.checkLVal(e.id,"none"),this.strict=n},X.isSimpleParamList=function(e){for(var t=0,r=e;t<r.length;t+=1){if("Identifier"!==r[t].type)return!1}return!0},X.checkParams=function(e,t){for(var r={},n=0,i=e.params;n<i.length;n+=1){var s=i[n];this.checkLVal(s,"var",t?null:r)}},X.parseExprList=function(e,t,r,n){for(var i=[],s=!0;!this.eat(e);){if(s)s=!1;else if(this.expect(b.comma),t&&this.afterTrailingComma(e))break;var a=void 0;r&&this.type===b.comma?a=null:this.type===b.ellipsis?(a=this.parseSpread(n),n&&this.type===b.comma&&n.trailingComma<0&&(n.trailingComma=this.start)):a=this.parseMaybeAssign(!1,n),i.push(a)}return i},X.checkUnreserved=function(e){var t=e.start,r=e.end,n=e.name;(this.inGenerator&&"yield"===n&&this.raiseRecoverable(t,"Can not use 'yield' as identifier inside a generator"),this.inAsync&&"await"===n&&this.raiseRecoverable(t,"Can not use 'await' as identifier inside an async function"),this.isKeyword(n)&&this.raise(t,"Unexpected keyword '"+n+"'"),this.options.ecmaVersion<6&&-1!==this.input.slice(t,r).indexOf("\\"))||(this.strict?this.reservedWordsStrict:this.reservedWords).test(n)&&(this.inAsync||"await"!==n||this.raiseRecoverable(t,"Can not use keyword 'await' outside an async function"),this.raiseRecoverable(t,"The keyword '"+n+"' is reserved"))},X.parseIdent=function(e,t){var r=this.startNode();return e&&"never"===this.options.allowReserved&&(e=!1),this.type===b.name?r.name=this.value:this.type.keyword?(r.name=this.type.keyword,"class"!==r.name&&"function"!==r.name||this.lastTokEnd===this.lastTokStart+1&&46===this.input.charCodeAt(this.lastTokStart)||this.context.pop()):this.unexpected(),this.next(),this.finishNode(r,"Identifier"),e||this.checkUnreserved(r),r},X.parseYield=function(){this.yieldPos||(this.yieldPos=this.start);var e=this.startNode();return this.next(),this.type===b.semi||this.canInsertSemicolon()||this.type!==b.star&&!this.type.startsExpr?(e.delegate=!1,e.argument=null):(e.delegate=this.eat(b.star),e.argument=this.parseMaybeAssign()),this.finishNode(e,"YieldExpression")},X.parseAwait=function(){this.awaitPos||(this.awaitPos=this.start);var e=this.startNode();return this.next(),e.argument=this.parseMaybeUnary(null,!0),this.finishNode(e,"AwaitExpression")};var q=M.prototype;q.raise=function(e,t){var r=C(this.input,e);t+=" ("+r.line+":"+r.column+")";var n=new SyntaxError(t);throw n.pos=e,n.loc=r,n.raisedAt=this.pos,n},q.raiseRecoverable=q.raise,q.curPosition=function(){if(this.options.locations)return new L(this.curLine,this.pos-this.lineStart)};var Y=M.prototype,Z=Object.assign||function(e){for(var t=[],r=arguments.length-1;r-- >0;)t[r]=arguments[r+1];for(var n=0,i=t;n<i.length;n+=1){var s=i[n];for(var a in s)I(s,a)&&(e[a]=s[a])}return e};Y.enterFunctionScope=function(){this.scopeStack.push({var:{},lexical:{},childVar:{},parentLexical:{}})},Y.exitFunctionScope=function(){this.scopeStack.pop()},Y.enterLexicalScope=function(){var e=this.scopeStack[this.scopeStack.length-1],t={var:{},lexical:{},childVar:{},parentLexical:{}};this.scopeStack.push(t),Z(t.parentLexical,e.lexical,e.parentLexical)},Y.exitLexicalScope=function(){var e=this.scopeStack.pop(),t=this.scopeStack[this.scopeStack.length-1];Z(t.childVar,e.var,e.childVar)},Y.canDeclareVarName=function(e){var t=this.scopeStack[this.scopeStack.length-1];return!I(t.lexical,e)&&!I(t.parentLexical,e)},Y.canDeclareLexicalName=function(e){var t=this.scopeStack[this.scopeStack.length-1];return!I(t.lexical,e)&&!I(t.var,e)&&!I(t.childVar,e)},Y.declareVarName=function(e){this.scopeStack[this.scopeStack.length-1].var[e]=!0},Y.declareLexicalName=function(e){this.scopeStack[this.scopeStack.length-1].lexical[e]=!0};var J=function(e,t,r){this.type="",this.start=t,this.end=0,e.options.locations&&(this.loc=new $(e,r)),e.options.directSourceFile&&(this.sourceFile=e.options.directSourceFile),e.options.ranges&&(this.range=[t,0])},Q=M.prototype;function ee(e,t,r,n){return e.type=t,e.end=r,this.options.locations&&(e.loc.end=n),this.options.ranges&&(e.range[1]=r),e}Q.startNode=function(){return new J(this,this.start,this.startLoc)},Q.startNodeAt=function(e,t){return new J(this,e,t)},Q.finishNode=function(e,t){return ee.call(this,e,t,this.lastTokEnd,this.lastTokEndLoc)},Q.finishNodeAt=function(e,t,r,n){return ee.call(this,e,t,r,n)};var te=function(e,t,r,n,i){this.token=e,this.isExpr=!!t,this.preserveSpace=!!r,this.override=n,this.generator=!!i},re={b_stat:new te("{",!1),b_expr:new te("{",!0),b_tmpl:new te("${",!1),p_stat:new te("(",!1),p_expr:new te("(",!0),q_tmpl:new te("`",!0,!0,function(e){return e.tryReadTemplateToken()}),f_stat:new te("function",!1),f_expr:new te("function",!0),f_expr_gen:new te("function",!0,!1,null,!0),f_gen:new te("function",!1,!1,null,!0)},ne=M.prototype;ne.initialContext=function(){return[re.b_stat]},ne.braceIsBlock=function(e){var t=this.curContext();return t===re.f_expr||t===re.f_stat||(e!==b.colon||t!==re.b_stat&&t!==re.b_expr?e===b._return||e===b.name&&this.exprAllowed?A.test(this.input.slice(this.lastTokEnd,this.start)):e===b._else||e===b.semi||e===b.eof||e===b.parenR||e===b.arrow||(e===b.braceL?t===re.b_stat:e!==b._var&&e!==b.name&&!this.exprAllowed):!t.isExpr)},ne.inGeneratorContext=function(){for(var e=this.context.length-1;e>=1;e--){var t=this.context[e];if("function"===t.token)return t.generator}return!1},ne.updateContext=function(e){var t,r=this.type;r.keyword&&e===b.dot?this.exprAllowed=!1:(t=r.updateContext)?t.call(this,e):this.exprAllowed=r.beforeExpr},b.parenR.updateContext=b.braceR.updateContext=function(){if(1!==this.context.length){var e=this.context.pop();e===re.b_stat&&"function"===this.curContext().token&&(e=this.context.pop()),this.exprAllowed=!e.isExpr}else this.exprAllowed=!0},b.braceL.updateContext=function(e){this.context.push(this.braceIsBlock(e)?re.b_stat:re.b_expr),this.exprAllowed=!0},b.dollarBraceL.updateContext=function(){this.context.push(re.b_tmpl),this.exprAllowed=!0},b.parenL.updateContext=function(e){var t=e===b._if||e===b._for||e===b._with||e===b._while;this.context.push(t?re.p_stat:re.p_expr),this.exprAllowed=!0},b.incDec.updateContext=function(){},b._function.updateContext=b._class.updateContext=function(e){e.beforeExpr&&e!==b.semi&&e!==b._else&&(e!==b.colon&&e!==b.braceL||this.curContext()!==re.b_stat)?this.context.push(re.f_expr):this.context.push(re.f_stat),this.exprAllowed=!1},b.backQuote.updateContext=function(){this.curContext()===re.q_tmpl?this.context.pop():this.context.push(re.q_tmpl),this.exprAllowed=!1},b.star.updateContext=function(e){if(e===b._function){var t=this.context.length-1;this.context[t]===re.f_expr?this.context[t]=re.f_expr_gen:this.context[t]=re.f_gen}this.exprAllowed=!0},b.name.updateContext=function(e){var t=!1;this.options.ecmaVersion>=6&&e!==b.dot&&("of"===this.value&&!this.exprAllowed||"yield"===this.value&&this.inGeneratorContext())&&(t=!0),this.exprAllowed=t};var ie={$LONE:["ASCII","ASCII_Hex_Digit","AHex","Alphabetic","Alpha","Any","Assigned","Bidi_Control","Bidi_C","Bidi_Mirrored","Bidi_M","Case_Ignorable","CI","Cased","Changes_When_Casefolded","CWCF","Changes_When_Casemapped","CWCM","Changes_When_Lowercased","CWL","Changes_When_NFKC_Casefolded","CWKCF","Changes_When_Titlecased","CWT","Changes_When_Uppercased","CWU","Dash","Default_Ignorable_Code_Point","DI","Deprecated","Dep","Diacritic","Dia","Emoji","Emoji_Component","Emoji_Modifier","Emoji_Modifier_Base","Emoji_Presentation","Extender","Ext","Grapheme_Base","Gr_Base","Grapheme_Extend","Gr_Ext","Hex_Digit","Hex","IDS_Binary_Operator","IDSB","IDS_Trinary_Operator","IDST","ID_Continue","IDC","ID_Start","IDS","Ideographic","Ideo","Join_Control","Join_C","Logical_Order_Exception","LOE","Lowercase","Lower","Math","Noncharacter_Code_Point","NChar","Pattern_Syntax","Pat_Syn","Pattern_White_Space","Pat_WS","Quotation_Mark","QMark","Radical","Regional_Indicator","RI","Sentence_Terminal","STerm","Soft_Dotted","SD","Terminal_Punctuation","Term","Unified_Ideograph","UIdeo","Uppercase","Upper","Variation_Selector","VS","White_Space","space","XID_Continue","XIDC","XID_Start","XIDS"],General_Category:["Cased_Letter","LC","Close_Punctuation","Pe","Connector_Punctuation","Pc","Control","Cc","cntrl","Currency_Symbol","Sc","Dash_Punctuation","Pd","Decimal_Number","Nd","digit","Enclosing_Mark","Me","Final_Punctuation","Pf","Format","Cf","Initial_Punctuation","Pi","Letter","L","Letter_Number","Nl","Line_Separator","Zl","Lowercase_Letter","Ll","Mark","M","Combining_Mark","Math_Symbol","Sm","Modifier_Letter","Lm","Modifier_Symbol","Sk","Nonspacing_Mark","Mn","Number","N","Open_Punctuation","Ps","Other","C","Other_Letter","Lo","Other_Number","No","Other_Punctuation","Po","Other_Symbol","So","Paragraph_Separator","Zp","Private_Use","Co","Punctuation","P","punct","Separator","Z","Space_Separator","Zs","Spacing_Mark","Mc","Surrogate","Cs","Symbol","S","Titlecase_Letter","Lt","Unassigned","Cn","Uppercase_Letter","Lu"],Script:["Adlam","Adlm","Ahom","Anatolian_Hieroglyphs","Hluw","Arabic","Arab","Armenian","Armn","Avestan","Avst","Balinese","Bali","Bamum","Bamu","Bassa_Vah","Bass","Batak","Batk","Bengali","Beng","Bhaiksuki","Bhks","Bopomofo","Bopo","Brahmi","Brah","Braille","Brai","Buginese","Bugi","Buhid","Buhd","Canadian_Aboriginal","Cans","Carian","Cari","Caucasian_Albanian","Aghb","Chakma","Cakm","Cham","Cherokee","Cher","Common","Zyyy","Coptic","Copt","Qaac","Cuneiform","Xsux","Cypriot","Cprt","Cyrillic","Cyrl","Deseret","Dsrt","Devanagari","Deva","Duployan","Dupl","Egyptian_Hieroglyphs","Egyp","Elbasan","Elba","Ethiopic","Ethi","Georgian","Geor","Glagolitic","Glag","Gothic","Goth","Grantha","Gran","Greek","Grek","Gujarati","Gujr","Gurmukhi","Guru","Han","Hani","Hangul","Hang","Hanunoo","Hano","Hatran","Hatr","Hebrew","Hebr","Hiragana","Hira","Imperial_Aramaic","Armi","Inherited","Zinh","Qaai","Inscriptional_Pahlavi","Phli","Inscriptional_Parthian","Prti","Javanese","Java","Kaithi","Kthi","Kannada","Knda","Katakana","Kana","Kayah_Li","Kali","Kharoshthi","Khar","Khmer","Khmr","Khojki","Khoj","Khudawadi","Sind","Lao","Laoo","Latin","Latn","Lepcha","Lepc","Limbu","Limb","Linear_A","Lina","Linear_B","Linb","Lisu","Lycian","Lyci","Lydian","Lydi","Mahajani","Mahj","Malayalam","Mlym","Mandaic","Mand","Manichaean","Mani","Marchen","Marc","Masaram_Gondi","Gonm","Meetei_Mayek","Mtei","Mende_Kikakui","Mend","Meroitic_Cursive","Merc","Meroitic_Hieroglyphs","Mero","Miao","Plrd","Modi","Mongolian","Mong","Mro","Mroo","Multani","Mult","Myanmar","Mymr","Nabataean","Nbat","New_Tai_Lue","Talu","Newa","Nko","Nkoo","Nushu","Nshu","Ogham","Ogam","Ol_Chiki","Olck","Old_Hungarian","Hung","Old_Italic","Ital","Old_North_Arabian","Narb","Old_Permic","Perm","Old_Persian","Xpeo","Old_South_Arabian","Sarb","Old_Turkic","Orkh","Oriya","Orya","Osage","Osge","Osmanya","Osma","Pahawh_Hmong","Hmng","Palmyrene","Palm","Pau_Cin_Hau","Pauc","Phags_Pa","Phag","Phoenician","Phnx","Psalter_Pahlavi","Phlp","Rejang","Rjng","Runic","Runr","Samaritan","Samr","Saurashtra","Saur","Sharada","Shrd","Shavian","Shaw","Siddham","Sidd","SignWriting","Sgnw","Sinhala","Sinh","Sora_Sompeng","Sora","Soyombo","Soyo","Sundanese","Sund","Syloti_Nagri","Sylo","Syriac","Syrc","Tagalog","Tglg","Tagbanwa","Tagb","Tai_Le","Tale","Tai_Tham","Lana","Tai_Viet","Tavt","Takri","Takr","Tamil","Taml","Tangut","Tang","Telugu","Telu","Thaana","Thaa","Thai","Tibetan","Tibt","Tifinagh","Tfng","Tirhuta","Tirh","Ugaritic","Ugar","Vai","Vaii","Warang_Citi","Wara","Yi","Yiii","Zanabazar_Square","Zanb"]};Array.prototype.push.apply(ie.$LONE,ie.General_Category),ie.gc=ie.General_Category,ie.sc=ie.Script_Extensions=ie.scx=ie.Script;var se=M.prototype,ae=function(e){this.parser=e,this.validFlags="gim"+(e.options.ecmaVersion>=6?"uy":"")+(e.options.ecmaVersion>=9?"s":""),this.source="",this.flags="",this.start=0,this.switchU=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue="",this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=[],this.backReferenceNames=[]};function oe(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10),56320+(1023&e)))}function ue(e){return 36===e||e>=40&&e<=43||46===e||63===e||e>=91&&e<=94||e>=123&&e<=125}function le(e){return e>=65&&e<=90||e>=97&&e<=122}function he(e){return le(e)||95===e}function ce(e){return he(e)||pe(e)}function pe(e){return e>=48&&e<=57}function de(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function me(e){return e>=65&&e<=70?e-65+10:e>=97&&e<=102?e-97+10:e-48}function ge(e){return e>=48&&e<=55}ae.prototype.reset=function(e,t,r){var n=-1!==r.indexOf("u");this.start=0|e,this.source=t+"",this.flags=r,this.switchU=n&&this.parser.options.ecmaVersion>=6,this.switchN=n&&this.parser.options.ecmaVersion>=9},ae.prototype.raise=function(e){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+e)},ae.prototype.at=function(e){var t=this.source,r=t.length;if(e>=r)return-1;var n=t.charCodeAt(e);return!this.switchU||n<=55295||n>=57344||e+1>=r?n:(n<<10)+t.charCodeAt(e+1)-56613888},ae.prototype.nextIndex=function(e){var t=this.source,r=t.length;if(e>=r)return r;var n=t.charCodeAt(e);return!this.switchU||n<=55295||n>=57344||e+1>=r?e+1:e+2},ae.prototype.current=function(){return this.at(this.pos)},ae.prototype.lookahead=function(){return this.at(this.nextIndex(this.pos))},ae.prototype.advance=function(){this.pos=this.nextIndex(this.pos)},ae.prototype.eat=function(e){return this.current()===e&&(this.advance(),!0)},se.validateRegExpFlags=function(e){for(var t=e.validFlags,r=e.flags,n=0;n<r.length;n++){var i=r.charAt(n);-1===t.indexOf(i)&&this.raise(e.start,"Invalid regular expression flag"),r.indexOf(i,n+1)>-1&&this.raise(e.start,"Duplicate regular expression flag")}},se.validateRegExpPattern=function(e){this.regexp_pattern(e),!e.switchN&&this.options.ecmaVersion>=9&&e.groupNames.length>0&&(e.switchN=!0,this.regexp_pattern(e))},se.regexp_pattern=function(e){e.pos=0,e.lastIntValue=0,e.lastStringValue="",e.lastAssertionIsQuantifiable=!1,e.numCapturingParens=0,e.maxBackReference=0,e.groupNames.length=0,e.backReferenceNames.length=0,this.regexp_disjunction(e),e.pos!==e.source.length&&(e.eat(41)&&e.raise("Unmatched ')'"),(e.eat(93)||e.eat(125))&&e.raise("Lone quantifier brackets")),e.maxBackReference>e.numCapturingParens&&e.raise("Invalid escape");for(var t=0,r=e.backReferenceNames;t<r.length;t+=1){var n=r[t];-1===e.groupNames.indexOf(n)&&e.raise("Invalid named capture referenced")}},se.regexp_disjunction=function(e){for(this.regexp_alternative(e);e.eat(124);)this.regexp_alternative(e);this.regexp_eatQuantifier(e,!0)&&e.raise("Nothing to repeat"),e.eat(123)&&e.raise("Lone quantifier brackets")},se.regexp_alternative=function(e){for(;e.pos<e.source.length&&this.regexp_eatTerm(e););},se.regexp_eatTerm=function(e){return this.regexp_eatAssertion(e)?(e.lastAssertionIsQuantifiable&&this.regexp_eatQuantifier(e)&&e.switchU&&e.raise("Invalid quantifier"),!0):!(e.switchU?!this.regexp_eatAtom(e):!this.regexp_eatExtendedAtom(e))&&(this.regexp_eatQuantifier(e),!0)},se.regexp_eatAssertion=function(e){var t=e.pos;if(e.lastAssertionIsQuantifiable=!1,e.eat(94)||e.eat(36))return!0;if(e.eat(92)){if(e.eat(66)||e.eat(98))return!0;e.pos=t}if(e.eat(40)&&e.eat(63)){var r=!1;if(this.options.ecmaVersion>=9&&(r=e.eat(60)),e.eat(61)||e.eat(33))return this.regexp_disjunction(e),e.eat(41)||e.raise("Unterminated group"),e.lastAssertionIsQuantifiable=!r,!0}return e.pos=t,!1},se.regexp_eatQuantifier=function(e,t){return void 0===t&&(t=!1),!!this.regexp_eatQuantifierPrefix(e,t)&&(e.eat(63),!0)},se.regexp_eatQuantifierPrefix=function(e,t){return e.eat(42)||e.eat(43)||e.eat(63)||this.regexp_eatBracedQuantifier(e,t)},se.regexp_eatBracedQuantifier=function(e,t){var r=e.pos;if(e.eat(123)){var n=0,i=-1;if(this.regexp_eatDecimalDigits(e)&&(n=e.lastIntValue,e.eat(44)&&this.regexp_eatDecimalDigits(e)&&(i=e.lastIntValue),e.eat(125)))return-1!==i&&i<n&&!t&&e.raise("numbers out of order in {} quantifier"),!0;e.switchU&&!t&&e.raise("Incomplete quantifier"),e.pos=r}return!1},se.regexp_eatAtom=function(e){return this.regexp_eatPatternCharacters(e)||e.eat(46)||this.regexp_eatReverseSolidusAtomEscape(e)||this.regexp_eatCharacterClass(e)||this.regexp_eatUncapturingGroup(e)||this.regexp_eatCapturingGroup(e)},se.regexp_eatReverseSolidusAtomEscape=function(e){var t=e.pos;if(e.eat(92)){if(this.regexp_eatAtomEscape(e))return!0;e.pos=t}return!1},se.regexp_eatUncapturingGroup=function(e){var t=e.pos;if(e.eat(40)){if(e.eat(63)&&e.eat(58)){if(this.regexp_disjunction(e),e.eat(41))return!0;e.raise("Unterminated group")}e.pos=t}return!1},se.regexp_eatCapturingGroup=function(e){if(e.eat(40)){if(this.options.ecmaVersion>=9?this.regexp_groupSpecifier(e):63===e.current()&&e.raise("Invalid group"),this.regexp_disjunction(e),e.eat(41))return e.numCapturingParens+=1,!0;e.raise("Unterminated group")}return!1},se.regexp_eatExtendedAtom=function(e){return e.eat(46)||this.regexp_eatReverseSolidusAtomEscape(e)||this.regexp_eatCharacterClass(e)||this.regexp_eatUncapturingGroup(e)||this.regexp_eatCapturingGroup(e)||this.regexp_eatInvalidBracedQuantifier(e)||this.regexp_eatExtendedPatternCharacter(e)},se.regexp_eatInvalidBracedQuantifier=function(e){return this.regexp_eatBracedQuantifier(e,!0)&&e.raise("Nothing to repeat"),!1},se.regexp_eatSyntaxCharacter=function(e){var t=e.current();return!!ue(t)&&(e.lastIntValue=t,e.advance(),!0)},se.regexp_eatPatternCharacters=function(e){for(var t=e.pos,r=0;-1!==(r=e.current())&&!ue(r);)e.advance();return e.pos!==t},se.regexp_eatExtendedPatternCharacter=function(e){var t=e.current();return!(-1===t||36===t||t>=40&&t<=43||46===t||63===t||91===t||94===t||124===t)&&(e.advance(),!0)},se.regexp_groupSpecifier=function(e){if(e.eat(63)){if(this.regexp_eatGroupName(e))return-1!==e.groupNames.indexOf(e.lastStringValue)&&e.raise("Duplicate capture group name"),void e.groupNames.push(e.lastStringValue);e.raise("Invalid group")}},se.regexp_eatGroupName=function(e){if(e.lastStringValue="",e.eat(60)){if(this.regexp_eatRegExpIdentifierName(e)&&e.eat(62))return!0;e.raise("Invalid capture group name")}return!1},se.regexp_eatRegExpIdentifierName=function(e){if(e.lastStringValue="",this.regexp_eatRegExpIdentifierStart(e)){for(e.lastStringValue+=oe(e.lastIntValue);this.regexp_eatRegExpIdentifierPart(e);)e.lastStringValue+=oe(e.lastIntValue);return!0}return!1},se.regexp_eatRegExpIdentifierStart=function(e){var t=e.pos,r=e.current();return e.advance(),92===r&&this.regexp_eatRegExpUnicodeEscapeSequence(e)&&(r=e.lastIntValue),function(e){return p(e,!0)||36===e||95===e}(r)?(e.lastIntValue=r,!0):(e.pos=t,!1)},se.regexp_eatRegExpIdentifierPart=function(e){var t=e.pos,r=e.current();return e.advance(),92===r&&this.regexp_eatRegExpUnicodeEscapeSequence(e)&&(r=e.lastIntValue),function(e){return d(e,!0)||36===e||95===e||8204===e||8205===e}(r)?(e.lastIntValue=r,!0):(e.pos=t,!1)},se.regexp_eatAtomEscape=function(e){return!!(this.regexp_eatBackReference(e)||this.regexp_eatCharacterClassEscape(e)||this.regexp_eatCharacterEscape(e)||e.switchN&&this.regexp_eatKGroupName(e))||(e.switchU&&(99===e.current()&&e.raise("Invalid unicode escape"),e.raise("Invalid escape")),!1)},se.regexp_eatBackReference=function(e){var t=e.pos;if(this.regexp_eatDecimalEscape(e)){var r=e.lastIntValue;if(e.switchU)return r>e.maxBackReference&&(e.maxBackReference=r),!0;if(r<=e.numCapturingParens)return!0;e.pos=t}return!1},se.regexp_eatKGroupName=function(e){if(e.eat(107)){if(this.regexp_eatGroupName(e))return e.backReferenceNames.push(e.lastStringValue),!0;e.raise("Invalid named reference")}return!1},se.regexp_eatCharacterEscape=function(e){return this.regexp_eatControlEscape(e)||this.regexp_eatCControlLetter(e)||this.regexp_eatZero(e)||this.regexp_eatHexEscapeSequence(e)||this.regexp_eatRegExpUnicodeEscapeSequence(e)||!e.switchU&&this.regexp_eatLegacyOctalEscapeSequence(e)||this.regexp_eatIdentityEscape(e)},se.regexp_eatCControlLetter=function(e){var t=e.pos;if(e.eat(99)){if(this.regexp_eatControlLetter(e))return!0;e.pos=t}return!1},se.regexp_eatZero=function(e){return 48===e.current()&&!pe(e.lookahead())&&(e.lastIntValue=0,e.advance(),!0)},se.regexp_eatControlEscape=function(e){var t=e.current();return 116===t?(e.lastIntValue=9,e.advance(),!0):110===t?(e.lastIntValue=10,e.advance(),!0):118===t?(e.lastIntValue=11,e.advance(),!0):102===t?(e.lastIntValue=12,e.advance(),!0):114===t&&(e.lastIntValue=13,e.advance(),!0)},se.regexp_eatControlLetter=function(e){var t=e.current();return!!le(t)&&(e.lastIntValue=t%32,e.advance(),!0)},se.regexp_eatRegExpUnicodeEscapeSequence=function(e){var t,r=e.pos;if(e.eat(117)){if(this.regexp_eatFixedHexDigits(e,4)){var n=e.lastIntValue;if(e.switchU&&n>=55296&&n<=56319){var i=e.pos;if(e.eat(92)&&e.eat(117)&&this.regexp_eatFixedHexDigits(e,4)){var s=e.lastIntValue;if(s>=56320&&s<=57343)return e.lastIntValue=1024*(n-55296)+(s-56320)+65536,!0}e.pos=i,e.lastIntValue=n}return!0}if(e.switchU&&e.eat(123)&&this.regexp_eatHexDigits(e)&&e.eat(125)&&((t=e.lastIntValue)>=0&&t<=1114111))return!0;e.switchU&&e.raise("Invalid unicode escape"),e.pos=r}return!1},se.regexp_eatIdentityEscape=function(e){if(e.switchU)return!!this.regexp_eatSyntaxCharacter(e)||!!e.eat(47)&&(e.lastIntValue=47,!0);var t=e.current();return!(99===t||e.switchN&&107===t)&&(e.lastIntValue=t,e.advance(),!0)},se.regexp_eatDecimalEscape=function(e){e.lastIntValue=0;var t=e.current();if(t>=49&&t<=57){do{e.lastIntValue=10*e.lastIntValue+(t-48),e.advance()}while((t=e.current())>=48&&t<=57);return!0}return!1},se.regexp_eatCharacterClassEscape=function(e){var t=e.current();if(function(e){return 100===e||68===e||115===e||83===e||119===e||87===e}(t))return e.lastIntValue=-1,e.advance(),!0;if(e.switchU&&this.options.ecmaVersion>=9&&(80===t||112===t)){if(e.lastIntValue=-1,e.advance(),e.eat(123)&&this.regexp_eatUnicodePropertyValueExpression(e)&&e.eat(125))return!0;e.raise("Invalid property name")}return!1},se.regexp_eatUnicodePropertyValueExpression=function(e){var t=e.pos;if(this.regexp_eatUnicodePropertyName(e)&&e.eat(61)){var r=e.lastStringValue;if(this.regexp_eatUnicodePropertyValue(e)){var n=e.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(e,r,n),!0}}if(e.pos=t,this.regexp_eatLoneUnicodePropertyNameOrValue(e)){var i=e.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(e,i),!0}return!1},se.regexp_validateUnicodePropertyNameAndValue=function(e,t,r){ie.hasOwnProperty(t)&&-1!==ie[t].indexOf(r)||e.raise("Invalid property name")},se.regexp_validateUnicodePropertyNameOrValue=function(e,t){-1===ie.$LONE.indexOf(t)&&e.raise("Invalid property name")},se.regexp_eatUnicodePropertyName=function(e){var t=0;for(e.lastStringValue="";he(t=e.current());)e.lastStringValue+=oe(t),e.advance();return""!==e.lastStringValue},se.regexp_eatUnicodePropertyValue=function(e){var t=0;for(e.lastStringValue="";ce(t=e.current());)e.lastStringValue+=oe(t),e.advance();return""!==e.lastStringValue},se.regexp_eatLoneUnicodePropertyNameOrValue=function(e){return this.regexp_eatUnicodePropertyValue(e)},se.regexp_eatCharacterClass=function(e){if(e.eat(91)){if(e.eat(94),this.regexp_classRanges(e),e.eat(93))return!0;e.raise("Unterminated character class")}return!1},se.regexp_classRanges=function(e){for(;this.regexp_eatClassAtom(e);){var t=e.lastIntValue;if(e.eat(45)&&this.regexp_eatClassAtom(e)){var r=e.lastIntValue;!e.switchU||-1!==t&&-1!==r||e.raise("Invalid character class"),-1!==t&&-1!==r&&t>r&&e.raise("Range out of order in character class")}}},se.regexp_eatClassAtom=function(e){var t=e.pos;if(e.eat(92)){if(this.regexp_eatClassEscape(e))return!0;if(e.switchU){var r=e.current();(99===r||ge(r))&&e.raise("Invalid class escape"),e.raise("Invalid escape")}e.pos=t}var n=e.current();return 93!==n&&(e.lastIntValue=n,e.advance(),!0)},se.regexp_eatClassEscape=function(e){var t=e.pos;if(e.eat(98))return e.lastIntValue=8,!0;if(e.switchU&&e.eat(45))return e.lastIntValue=45,!0;if(!e.switchU&&e.eat(99)){if(this.regexp_eatClassControlLetter(e))return!0;e.pos=t}return this.regexp_eatCharacterClassEscape(e)||this.regexp_eatCharacterEscape(e)},se.regexp_eatClassControlLetter=function(e){var t=e.current();return!(!pe(t)&&95!==t)&&(e.lastIntValue=t%32,e.advance(),!0)},se.regexp_eatHexEscapeSequence=function(e){var t=e.pos;if(e.eat(120)){if(this.regexp_eatFixedHexDigits(e,2))return!0;e.switchU&&e.raise("Invalid escape"),e.pos=t}return!1},se.regexp_eatDecimalDigits=function(e){var t=e.pos,r=0;for(e.lastIntValue=0;pe(r=e.current());)e.lastIntValue=10*e.lastIntValue+(r-48),e.advance();return e.pos!==t},se.regexp_eatHexDigits=function(e){var t=e.pos,r=0;for(e.lastIntValue=0;de(r=e.current());)e.lastIntValue=16*e.lastIntValue+me(r),e.advance();return e.pos!==t},se.regexp_eatLegacyOctalEscapeSequence=function(e){if(this.regexp_eatOctalDigit(e)){var t=e.lastIntValue;if(this.regexp_eatOctalDigit(e)){var r=e.lastIntValue;t<=3&&this.regexp_eatOctalDigit(e)?e.lastIntValue=64*t+8*r+e.lastIntValue:e.lastIntValue=8*t+r}else e.lastIntValue=t;return!0}return!1},se.regexp_eatOctalDigit=function(e){var t=e.current();return ge(t)?(e.lastIntValue=t-48,e.advance(),!0):(e.lastIntValue=0,!1)},se.regexp_eatFixedHexDigits=function(e,t){var r=e.pos;e.lastIntValue=0;for(var n=0;n<t;++n){var i=e.current();if(!de(i))return e.pos=r,!1;e.lastIntValue=16*e.lastIntValue+me(i),e.advance()}return!0};var fe=function(e){this.type=e.type,this.value=e.value,this.start=e.start,this.end=e.end,e.options.locations&&(this.loc=new $(e,e.startLoc,e.endLoc)),e.options.ranges&&(this.range=[e.start,e.end])},xe=M.prototype;function ye(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10),56320+(1023&e)))}xe.next=function(){this.options.onToken&&this.options.onToken(new fe(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()},xe.getToken=function(){return this.next(),new fe(this)},"undefined"!=typeof Symbol&&(xe[Symbol.iterator]=function(){var e=this;return{next:function(){var t=e.getToken();return{done:t.type===b.eof,value:t}}}}),xe.curContext=function(){return this.context[this.context.length-1]},xe.nextToken=function(){var e=this.curContext();return e&&e.preserveSpace||this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length?this.finishToken(b.eof):e.override?e.override(this):void this.readToken(this.fullCharCodeAtPos())},xe.readToken=function(e){return p(e,this.options.ecmaVersion>=6)||92===e?this.readWord():this.getTokenFromCode(e)},xe.fullCharCodeAtPos=function(){var e=this.input.charCodeAt(this.pos);return e<=55295||e>=57344?e:(e<<10)+this.input.charCodeAt(this.pos+1)-56613888},xe.skipBlockComment=function(){var e,t=this.options.onComment&&this.curPosition(),r=this.pos,n=this.input.indexOf("*/",this.pos+=2);if(-1===n&&this.raise(this.pos-2,"Unterminated comment"),this.pos=n+2,this.options.locations)for(v.lastIndex=r;(e=v.exec(this.input))&&e.index<this.pos;)++this.curLine,this.lineStart=e.index+e[0].length;this.options.onComment&&this.options.onComment(!0,this.input.slice(r+2,n),r,this.pos,t,this.curPosition())},xe.skipLineComment=function(e){for(var t=this.pos,r=this.options.onComment&&this.curPosition(),n=this.input.charCodeAt(this.pos+=e);this.pos<this.input.length&&!S(n);)n=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(t+e,this.pos),t,this.pos,r,this.curPosition())},xe.skipSpace=function(){e:for(;this.pos<this.input.length;){var e=this.input.charCodeAt(this.pos);switch(e){case 32:case 160:++this.pos;break;case 13:10===this.input.charCodeAt(this.pos+1)&&++this.pos;case 10:case 8232:case 8233:++this.pos,this.options.locations&&(++this.curLine,this.lineStart=this.pos);break;case 47:switch(this.input.charCodeAt(this.pos+1)){case 42:this.skipBlockComment();break;case 47:this.skipLineComment(2);break;default:break e}break;default:if(!(e>8&&e<14||e>=5760&&E.test(String.fromCharCode(e))))break e;++this.pos}}},xe.finishToken=function(e,t){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var r=this.type;this.type=e,this.value=t,this.updateContext(r)},xe.readToken_dot=function(){var e=this.input.charCodeAt(this.pos+1);if(e>=48&&e<=57)return this.readNumber(!0);var t=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&46===e&&46===t?(this.pos+=3,this.finishToken(b.ellipsis)):(++this.pos,this.finishToken(b.dot))},xe.readToken_slash=function(){var e=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):61===e?this.finishOp(b.assign,2):this.finishOp(b.slash,1)},xe.readToken_mult_modulo_exp=function(e){var t=this.input.charCodeAt(this.pos+1),r=1,n=42===e?b.star:b.modulo;return this.options.ecmaVersion>=7&&42===e&&42===t&&(++r,n=b.starstar,t=this.input.charCodeAt(this.pos+2)),61===t?this.finishOp(b.assign,r+1):this.finishOp(n,r)},xe.readToken_pipe_amp=function(e){var t=this.input.charCodeAt(this.pos+1);return t===e?this.finishOp(124===e?b.logicalOR:b.logicalAND,2):61===t?this.finishOp(b.assign,2):this.finishOp(124===e?b.bitwiseOR:b.bitwiseAND,1)},xe.readToken_caret=function(){return 61===this.input.charCodeAt(this.pos+1)?this.finishOp(b.assign,2):this.finishOp(b.bitwiseXOR,1)},xe.readToken_plus_min=function(e){var t=this.input.charCodeAt(this.pos+1);return t===e?45!==t||this.inModule||62!==this.input.charCodeAt(this.pos+2)||0!==this.lastTokEnd&&!A.test(this.input.slice(this.lastTokEnd,this.pos))?this.finishOp(b.incDec,2):(this.skipLineComment(3),this.skipSpace(),this.nextToken()):61===t?this.finishOp(b.assign,2):this.finishOp(b.plusMin,1)},xe.readToken_lt_gt=function(e){var t=this.input.charCodeAt(this.pos+1),r=1;return t===e?(r=62===e&&62===this.input.charCodeAt(this.pos+2)?3:2,61===this.input.charCodeAt(this.pos+r)?this.finishOp(b.assign,r+1):this.finishOp(b.bitShift,r)):33!==t||60!==e||this.inModule||45!==this.input.charCodeAt(this.pos+2)||45!==this.input.charCodeAt(this.pos+3)?(61===t&&(r=2),this.finishOp(b.relational,r)):(this.skipLineComment(4),this.skipSpace(),this.nextToken())},xe.readToken_eq_excl=function(e){var t=this.input.charCodeAt(this.pos+1);return 61===t?this.finishOp(b.equality,61===this.input.charCodeAt(this.pos+2)?3:2):61===e&&62===t&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(b.arrow)):this.finishOp(61===e?b.eq:b.prefix,1)},xe.getTokenFromCode=function(e){switch(e){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(b.parenL);case 41:return++this.pos,this.finishToken(b.parenR);case 59:return++this.pos,this.finishToken(b.semi);case 44:return++this.pos,this.finishToken(b.comma);case 91:return++this.pos,this.finishToken(b.bracketL);case 93:return++this.pos,this.finishToken(b.bracketR);case 123:return++this.pos,this.finishToken(b.braceL);case 125:return++this.pos,this.finishToken(b.braceR);case 58:return++this.pos,this.finishToken(b.colon);case 63:return++this.pos,this.finishToken(b.question);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(b.backQuote);case 48:var t=this.input.charCodeAt(this.pos+1);if(120===t||88===t)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(111===t||79===t)return this.readRadixNumber(8);if(98===t||66===t)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(e);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(e);case 124:case 38:return this.readToken_pipe_amp(e);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(e);case 60:case 62:return this.readToken_lt_gt(e);case 61:case 33:return this.readToken_eq_excl(e);case 126:return this.finishOp(b.prefix,1)}this.raise(this.pos,"Unexpected character '"+ye(e)+"'")},xe.finishOp=function(e,t){var r=this.input.slice(this.pos,this.pos+t);return this.pos+=t,this.finishToken(e,r)},xe.readRegexp=function(){for(var e,t,r=this.pos;;){this.pos>=this.input.length&&this.raise(r,"Unterminated regular expression");var n=this.input.charAt(this.pos);if(A.test(n)&&this.raise(r,"Unterminated regular expression"),e)e=!1;else{if("["===n)t=!0;else if("]"===n&&t)t=!1;else if("/"===n&&!t)break;e="\\"===n}++this.pos}var i=this.input.slice(r,this.pos);++this.pos;var s=this.pos,a=this.readWord1();this.containsEsc&&this.unexpected(s);var o=this.regexpState||(this.regexpState=new ae(this));o.reset(r,i,a),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var u=null;try{u=new RegExp(i,a)}catch(e){}return this.finishToken(b.regexp,{pattern:i,flags:a,value:u})},xe.readInt=function(e,t){for(var r=this.pos,n=0,i=0,s=null==t?1/0:t;i<s;++i){var a=this.input.charCodeAt(this.pos),o=void 0;if((o=a>=97?a-97+10:a>=65?a-65+10:a>=48&&a<=57?a-48:1/0)>=e)break;++this.pos,n=n*e+o}return this.pos===r||null!=t&&this.pos-r!==t?null:n},xe.readRadixNumber=function(e){this.pos+=2;var t=this.readInt(e);return null==t&&this.raise(this.start+2,"Expected number in radix "+e),p(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(b.num,t)},xe.readNumber=function(e){var t=this.pos;e||null!==this.readInt(10)||this.raise(t,"Invalid number");var r=this.pos-t>=2&&48===this.input.charCodeAt(t);r&&this.strict&&this.raise(t,"Invalid number"),r&&/[89]/.test(this.input.slice(t,this.pos))&&(r=!1);var n=this.input.charCodeAt(this.pos);46!==n||r||(++this.pos,this.readInt(10),n=this.input.charCodeAt(this.pos)),69!==n&&101!==n||r||(43!==(n=this.input.charCodeAt(++this.pos))&&45!==n||++this.pos,null===this.readInt(10)&&this.raise(t,"Invalid number")),p(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var i=this.input.slice(t,this.pos),s=r?parseInt(i,8):parseFloat(i);return this.finishToken(b.num,s)},xe.readCodePoint=function(){var e;if(123===this.input.charCodeAt(this.pos)){this.options.ecmaVersion<6&&this.unexpected();var t=++this.pos;e=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,e>1114111&&this.invalidStringToken(t,"Code point out of bounds")}else e=this.readHexChar(4);return e},xe.readString=function(e){for(var t="",r=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated string constant");var n=this.input.charCodeAt(this.pos);if(n===e)break;92===n?(t+=this.input.slice(r,this.pos),t+=this.readEscapedChar(!1),r=this.pos):(S(n,this.options.ecmaVersion>=10)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return t+=this.input.slice(r,this.pos++),this.finishToken(b.string,t)};var Te={};xe.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(e){if(e!==Te)throw e;this.readInvalidTemplateToken()}this.inTemplateElement=!1},xe.invalidStringToken=function(e,t){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw Te;this.raise(e,t)},xe.readTmplToken=function(){for(var e="",t=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var r=this.input.charCodeAt(this.pos);if(96===r||36===r&&123===this.input.charCodeAt(this.pos+1))return this.pos!==this.start||this.type!==b.template&&this.type!==b.invalidTemplate?(e+=this.input.slice(t,this.pos),this.finishToken(b.template,e)):36===r?(this.pos+=2,this.finishToken(b.dollarBraceL)):(++this.pos,this.finishToken(b.backQuote));if(92===r)e+=this.input.slice(t,this.pos),e+=this.readEscapedChar(!0),t=this.pos;else if(S(r)){switch(e+=this.input.slice(t,this.pos),++this.pos,r){case 13:10===this.input.charCodeAt(this.pos)&&++this.pos;case 10:e+="\n";break;default:e+=String.fromCharCode(r)}this.options.locations&&(++this.curLine,this.lineStart=this.pos),t=this.pos}else++this.pos}},xe.readInvalidTemplateToken=function(){for(;this.pos<this.input.length;this.pos++)switch(this.input[this.pos]){case"\\":++this.pos;break;case"$":if("{"!==this.input[this.pos+1])break;case"`":return this.finishToken(b.invalidTemplate,this.input.slice(this.start,this.pos))}this.raise(this.start,"Unterminated template")},xe.readEscapedChar=function(e){var t=this.input.charCodeAt(++this.pos);switch(++this.pos,t){case 110:return"\n";case 114:return"\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return ye(this.readCodePoint());case 116:return"\t";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 13:10===this.input.charCodeAt(this.pos)&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";default:if(t>=48&&t<=55){var r=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],n=parseInt(r,8);return n>255&&(r=r.slice(0,-1),n=parseInt(r,8)),this.pos+=r.length-1,t=this.input.charCodeAt(this.pos),"0"===r&&56!==t&&57!==t||!this.strict&&!e||this.invalidStringToken(this.pos-1-r.length,e?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(n)}return String.fromCharCode(t)}},xe.readHexChar=function(e){var t=this.pos,r=this.readInt(16,e);return null===r&&this.invalidStringToken(t,"Bad character escape sequence"),r},xe.readWord1=function(){this.containsEsc=!1;for(var e="",t=!0,r=this.pos,n=this.options.ecmaVersion>=6;this.pos<this.input.length;){var i=this.fullCharCodeAtPos();if(d(i,n))this.pos+=i<=65535?1:2;else{if(92!==i)break;this.containsEsc=!0,e+=this.input.slice(r,this.pos);var s=this.pos;117!==this.input.charCodeAt(++this.pos)&&this.invalidStringToken(this.pos,"Expecting Unicode escape sequence \\uXXXX"),++this.pos;var a=this.readCodePoint();(t?p:d)(a,n)||this.invalidStringToken(s,"Invalid Unicode escape"),e+=ye(a),r=this.pos}t=!1}return e+this.input.slice(r,this.pos)},xe.readWord=function(){var e=this.readWord1(),t=b.name;return this.keywords.test(e)&&(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword "+e),t=y[e]),this.finishToken(t,e)},e.version="5.7.3",e.parse=function(e,t){return new M(t,e).parse()},e.parseExpressionAt=function(e,t,r){var n=new M(r,e,t);return n.nextToken(),n.parseExpression()},e.tokenizer=function(e,t){return new M(t,e)},e.addLooseExports=function(t,r,n){e.parse_dammit=t,e.LooseParser=r,e.pluginsLoose=n},e.Parser=M,e.plugins=N,e.defaultOptions=F,e.Position=L,e.SourceLocation=$,e.getLineInfo=C,e.Node=J,e.TokenType=m,e.tokTypes=b,e.keywordTypes=y,e.TokContext=te,e.tokContexts=re,e.isIdentifierChar=d,e.isIdentifierStart=p,e.Token=fe,e.isNewLine=S,e.lineBreak=A,e.lineBreakG=v,e.nonASCIIwhitespace=E,Object.defineProperty(e,"__esModule",{value:!0})}("object"==typeof r&&void 0!==t?r:n.acorn={})},{}],2:[function(e,t,r){},{}],3:[function(e,t,r){function n(e,t={}){const{contextName:r="gl",throwGetError:n,useTrackablePrimitives:o,readPixelsFile:u,recording:l=[],variables:h={},onReadPixels:c,onUnrecognizedArgumentLookup:p}=t,d=new Proxy(e,{get:function(t,d){switch(d){case"addComment":return _;case"checkThrowError":return w;case"getReadPixelsVariableName":return f;case"insertVariable":return A;case"reset":return b;case"setIndent":return S;case"toString":return T;case"getContextVariableName":return D}if("function"==typeof e[d])return function(){switch(d){case"getError":return n?l.push(`${y}if (${r}.getError() !== ${r}.NONE) throw new Error('error');`):l.push(`${y}${r}.getError();`),e.getError();case"getExtension":{const t=`${r}Variables${m.length}`;l.push(`${y}const ${t} = ${r}.getExtension('${arguments[0]}');`);const n=e.getExtension(arguments[0]);if(n&&"object"==typeof n){const e=i(n,{getEntity:v,useTrackablePrimitives:o,recording:l,contextName:t,contextVariables:m,variables:h,indent:y,onUnrecognizedArgumentLookup:p});return m.push(e),e}return m.push(null),n}case"readPixels":const t=m.indexOf(arguments[6]);let a;if(-1===t){const e=function(e){if(h)for(const t in h)if(h[t]===e)return t;return null}(arguments[6]);e?(a=e,l.push(`${y}${e}`)):(a=`${r}Variable${m.length}`,m.push(arguments[6]),l.push(`${y}const ${a} = new ${arguments[6].constructor.name}(${arguments[6].length});`))}else a=`${r}Variable${t}`;f=a;const g=[arguments[0],arguments[1],arguments[2],arguments[3],v(arguments[4]),v(arguments[5]),a];return l.push(`${y}${r}.readPixels(${g.join(", ")});`),u&&function(e,t){const n=`${r}Variable${m.length}`,i=`imageDatum${x}`;l.push(`${y}let ${i} = ["P3\\n# ${u}.ppm\\n", ${e}, ' ', ${t}, "\\n255\\n"].join("");`),l.push(`${y}for (let i = 0; i < ${i}.length; i += 4) {`),l.push(`${y} ${i} += ${n}[i] + ' ' + ${n}[i + 1] + ' ' + ${n}[i + 2] + ' ';`),l.push(`${y}}`),l.push(`${y}if (typeof require !== "undefined") {`),l.push(`${y} require('fs').writeFileSync('./${u}.ppm', ${i});`),l.push(`${y}}`),x++}(arguments[2],arguments[3]),c&&c(a,g),e.readPixels.apply(e,arguments);case"drawBuffers":return l.push(`${y}${r}.drawBuffers([${s(arguments[0],{contextName:r,contextVariables:m,getEntity:v,addVariable:E,variables:h,onUnrecognizedArgumentLookup:p})}]);`),e.drawBuffers(arguments[0])}let t=e[d].apply(e,arguments);switch(typeof t){case"undefined":return void l.push(`${y}${k(d,arguments)};`);case"number":case"boolean":if(o&&-1===m.indexOf(a(t))){l.push(`${y}const ${r}Variable${m.length} = ${k(d,arguments)};`),m.push(t=a(t));break}default:null===t?l.push(`${k(d,arguments)};`):l.push(`${y}const ${r}Variable${m.length} = ${k(d,arguments)};`),m.push(t)}return t};return g[e[d]]=d,e[d]}}),m=[],g={};let f,x=0,y="";return d;function T(){return l.join("\n")}function b(){for(;l.length>0;)l.pop()}function A(e,t){h[e]=t}function v(e){const t=g[e];return t?r+"."+t:e}function S(e){y=" ".repeat(e)}function E(e,t){const n=`${r}Variable${m.length}`;return l.push(`${y}const ${n} = ${t};`),m.push(e),n}function _(e){l.push(`${y}// ${e}`)}function w(){l.push(`${y}(() => {\n${y}const error = ${r}.getError();\n${y}if (error !== ${r}.NONE) {\n${y} const names = Object.getOwnPropertyNames(gl);\n${y} for (let i = 0; i < names.length; i++) {\n${y} const name = names[i];\n${y} if (${r}[name] === error) {\n${y} throw new Error('${r} threw ' + name);\n${y} }\n${y} }\n${y}}\n${y}})();`)}function k(e,t){return`${r}.${e}(${s(t,{contextName:r,contextVariables:m,getEntity:v,addVariable:E,variables:h,onUnrecognizedArgumentLookup:p})})`}function D(e){const t=m.indexOf(e);return-1!==t?`${r}Variable${t}`:null}}function i(e,t){const r=new Proxy(e,{get:function(t,r){if("function"==typeof t[r])return function(){switch(r){case"drawBuffersWEBGL":return h.push(`${p}${i}.drawBuffersWEBGL([${s(arguments[0],{contextName:i,contextVariables:o,getEntity:m,addVariable:f,variables:c,onUnrecognizedArgumentLookup:d})}]);`),e.drawBuffersWEBGL(arguments[0])}let t=e[r].apply(e,arguments);switch(typeof t){case"undefined":return void h.push(`${p}${g(r,arguments)};`);case"number":case"boolean":l&&-1===o.indexOf(a(t))?(h.push(`${p}const ${i}Variable${o.length} = ${g(r,arguments)};`),o.push(t=a(t))):(h.push(`${p}const ${i}Variable${o.length} = ${g(r,arguments)};`),o.push(t));break;default:null===t?h.push(`${g(r,arguments)};`):h.push(`${p}const ${i}Variable${o.length} = ${g(r,arguments)};`),o.push(t)}return t};return n[e[r]]=r,e[r]}}),n={},{contextName:i,contextVariables:o,getEntity:u,useTrackablePrimitives:l,recording:h,variables:c,indent:p,onUnrecognizedArgumentLookup:d}=t;return r;function m(e){return n.hasOwnProperty(e)?`${i}.${n[e]}`:u(e)}function g(e,t){return`${i}.${e}(${s(t,{contextName:i,contextVariables:o,getEntity:m,addVariable:f,variables:c,onUnrecognizedArgumentLookup:d})})`}function f(e,t){const r=`${i}Variable${o.length}`;return o.push(e),h.push(`${p}const ${r} = ${t};`),r}}function s(e,t){const{variables:r,onUnrecognizedArgumentLookup:n}=t;return Array.from(e).map(e=>{const i=function(e){if(r)for(const t in r)if(r.hasOwnProperty(t)&&r[t]===e)return t;if(n)return n(e);return null}(e);return i||function(e,t){const{contextName:r,contextVariables:n,getEntity:i,addVariable:s,onUnrecognizedArgumentLookup:a}=t;if(void 0===e)return"undefined";if(null===e)return"null";const o=n.indexOf(e);if(o>-1)return`${r}Variable${o}`;switch(e.constructor.name){case"String":const t=/\n/.test(e),r=/'/.test(e),n=/"/.test(e);return t?"`"+e+"`":r&&!n?'"'+e+'"':"'"+e+"'";case"Number":case"Boolean":return i(e);case"Array":return s(e,`new ${e.constructor.name}([${Array.from(e).join(",")}])`);case"Float32Array":case"Uint8Array":case"Uint16Array":case"Int32Array":return s(e,`new ${e.constructor.name}(${JSON.stringify(Array.from(e))})`);default:if(a){const t=a(e);if(t)return t}throw new Error(`unrecognized argument type ${e.constructor.name}`)}}(e,t)}).join(", ")}function a(e){return new e.constructor(e)}void 0!==t&&(t.exports={glWiretap:n,glExtensionWiretap:i}),"undefined"!=typeof window&&(n.glExtensionWiretap=i,window.glWiretap=n)},{}],4:[function(e,t,r){function n(e){const t=new Array(e.length);for(let r=0;r<e.length;r++){const n=e[r];n.toArray?t[r]=n.toArray():t[r]=n}return t}function i(e){return e.setOutput=(t=>{e.output=a(t),e.graphical&&s(e)}),e.toJSON=(()=>{throw new Error("Not usable with gpuMock")}),e.setConstants=(t=>(e.constants=t,e)),e.setGraphical=(t=>(e.graphical=t,e)),e.setCanvas=(t=>(e.canvas=t,e)),e.setContext=(t=>(e.context=t,e)),e.exec=function(){return new Promise((t,r)=>{try{t(e.apply(e,arguments))}catch(e){r(e)}})},e.getPixels=(t=>{const{x:r,y:n}=e.output;return t?function(e,t,r){const n=r/2|0,i=4*t,s=new Uint8ClampedArray(4*t),a=e.slice(0);for(let e=0;e<n;++e){const t=e*i,n=(r-e-1)*i;s.set(a.subarray(t,t+i)),a.copyWithin(t,n,n+i),a.set(s,n)}return a}(e._imageData.data,r,n):e._imageData.data.slice(0)}),e.color=function(t,r,n,i){void 0===i&&(i=1),t=Math.floor(255*t),r=Math.floor(255*r),n=Math.floor(255*n),i=Math.floor(255*i);const s=e.output.x,a=e.output.y,o=e.thread.x+(a-e.thread.y-1)*s;e._colorData[4*o+0]=t,e._colorData[4*o+1]=r,e._colorData[4*o+2]=n,e._colorData[4*o+3]=i},e.setWarnVarUsage=(()=>e),e.setOptimizeFloatMemory=(()=>e),e.setArgumentTypes=(()=>e),e.setDebug=(()=>e),e.setLoopMaxIterations=(()=>e),e.setPipeline=(()=>e),e.setPrecision=(()=>e),e.setImmutable=(()=>e),e.setFunctions=(()=>e),e.addSubKernel=(()=>e),e.destroy=(()=>{}),e.validateSettings=(()=>{}),e.graphical&&e.output&&s(e),e}function s(e){const{x:t,y:r}=e.output;if(e.context&&e.context.createImageData){const n=new Uint8ClampedArray(t*r*4);e._imageData=e.context.createImageData(t,r),e._colorData=n}else{const n=new Uint8ClampedArray(t*r*4);e._imageData={data:n},e._colorData=n}}function a(e){let t=null;if(e.length)if(3===e.length){const[r,n,i]=e;t={x:r,y:n,z:i}}else if(2===e.length){const[r,n]=e;t={x:r,y:n}}else{const[r]=e;t={x:r}}else t=e;return t}t.exports={gpuMock:function(e,t={}){const r=t.output?a(t.output):null;function s(){return s.output.z?function(){const e=n(arguments),t=new Array(this.output.z);for(let r=0;r<this.output.z;r++){const n=new Array(this.output.y);for(let t=0;t<this.output.y;t++){const i=new Float32Array(this.output.x);for(let n=0;n<this.output.x;n++)this.thread.x=n,this.thread.y=t,this.thread.z=r,i[n]=this._fn.apply(this,e);n[t]=i}t[r]=n}return t}.apply(s,arguments):s.output.y?s.graphical?function(){const e=n(arguments);for(let t=0;t<this.output.y;t++)for(let r=0;r<this.output.x;r++)this.thread.x=r,this.thread.y=t,this.thread.z=0,this._fn.apply(this,e)}.apply(s,arguments):function(){const e=n(arguments),t=new Array(this.output.y);for(let r=0;r<this.output.y;r++){const n=new Float32Array(this.output.x);for(let t=0;t<this.output.x;t++)this.thread.x=t,this.thread.y=r,this.thread.z=0,n[t]=this._fn.apply(this,e);t[r]=n}return t}.apply(s,arguments):function(){const e=n(arguments),t=new Float32Array(this.output.x);for(let r=0;r<this.output.x;r++)this.thread.x=r,this.thread.y=0,this.thread.z=0,t[r]=this._fn.apply(this,e);return t}.apply(s,arguments)}return s._fn=e,s.constants=t.constants||null,s.context=t.context||null,s.canvas=t.canvas||null,s.graphical=t.graphical||!1,s._imageData=null,s._colorData=null,s.output=r,s.thread={x:0,y:0,z:0},i(s)}}},{}],5:[function(e,t,r){const{utils:n}=e("./utils");t.exports={alias:function(e,t){const r=t.toString();return new Function(`return function ${e} (${n.getArgumentNamesFromString(r).join(", ")}) {\n ${n.getFunctionBodyFromString(r)}\n}`)()}}},{"./utils":112}],6:[function(e,t,r){const{FunctionNode:n}=e("../function-node");t.exports={CPUFunctionNode:class extends n{astFunction(e,t){if(!this.isRootKernel){t.push("function"),t.push(" "),t.push(this.name),t.push("(");for(let e=0;e<this.argumentNames.length;++e){const r=this.argumentNames[e];e>0&&t.push(", "),t.push("user_"),t.push(r)}t.push(") {\n")}for(let r=0;r<e.body.body.length;++r)this.astGeneric(e.body.body[r],t),t.push("\n");return this.isRootKernel||t.push("}\n"),t}astReturnStatement(e,t){const r=this.returnType||this.getType(e.argument);return this.returnType||(this.returnType=r),this.isRootKernel?(t.push(this.leadingReturnStatement),this.astGeneric(e.argument,t),t.push(";\n"),t.push(this.followingReturnStatement),t.push("continue;\n")):this.isSubKernel?(t.push(`subKernelResult_${this.name} = `),this.astGeneric(e.argument,t),t.push(";"),t.push(`return subKernelResult_${this.name};`)):(t.push("return "),this.astGeneric(e.argument,t),t.push(";")),t}astLiteral(e,t){if(isNaN(e.value))throw this.astErrorOutput("Non-numeric literal not supported : "+e.value,e);return t.push(e.value),t}astBinaryExpression(e,t){return t.push("("),this.astGeneric(e.left,t),t.push(e.operator),this.astGeneric(e.right,t),t.push(")"),t}astIdentifierExpression(e,t){if("Identifier"!==e.type)throw this.astErrorOutput("IdentifierExpression - not an Identifier",e);switch(e.name){case"Infinity":t.push("Infinity");break;default:this.constants&&this.constants.hasOwnProperty(e.name)?t.push("constants_"+e.name):t.push("user_"+e.name)}return t}astForStatement(e,t){if("ForStatement"!==e.type)throw this.astErrorOutput("Invalid for statement",e);const r=[],n=[],i=[],s=[];let a=null;if(e.init){this.pushState("in-for-loop-init"),this.astGeneric(e.init,r);for(let e=0;e<r.length;e++)r[e].includes&&r[e].includes(",")&&(a=!1);this.popState("in-for-loop-init")}else a=!1;if(e.test?this.astGeneric(e.test,n):a=!1,e.update?this.astGeneric(e.update,i):a=!1,e.body&&(this.pushState("loop-body"),this.astGeneric(e.body,s),this.popState("loop-body")),null===a&&(a=this.isSafe(e.init)&&this.isSafe(e.test)),a)t.push(`for (${r.join("")};${n.join("")};${i.join("")}){\n`),t.push(s.join("")),t.push("}\n");else{const e=this.getInternalVariableName("safeI");r.length>0&&t.push(r.join(""),";\n"),t.push(`for (let ${e}=0;${e}<LOOP_MAX;${e}++){\n`),n.length>0&&t.push(`if (!${n.join("")}) break;\n`),t.push(s.join("")),t.push(`\n${i.join("")};`),t.push("}\n")}return t}astWhileStatement(e,t){if("WhileStatement"!==e.type)throw this.astErrorOutput("Invalid while statement",e);return t.push("for (let i = 0; i < LOOP_MAX; i++) {"),t.push("if ("),this.astGeneric(e.test,t),t.push(") {\n"),this.astGeneric(e.body,t),t.push("} else {\n"),t.push("break;\n"),t.push("}\n"),t.push("}\n"),t}astDoWhileStatement(e,t){if("DoWhileStatement"!==e.type)throw this.astErrorOutput("Invalid while statement",e);return t.push("for (let i = 0; i < LOOP_MAX; i++) {"),this.astGeneric(e.body,t),t.push("if (!"),this.astGeneric(e.test,t),t.push(") {\n"),t.push("break;\n"),t.push("}\n"),t.push("}\n"),t}astAssignmentExpression(e,t){const r=this.getDeclaration(e.left);if(r&&!r.assignable)throw this.astErrorOutput(`Variable ${e.left.name} is not assignable here`,e);return this.astGeneric(e.left,t),t.push(e.operator),this.astGeneric(e.right,t),t}astBlockStatement(e,t){if(this.isState("loop-body")){this.pushState("block-body");for(let r=0;r<e.body.length;r++)this.astGeneric(e.body[r],t);this.popState("block-body")}else{t.push("{\n");for(let r=0;r<e.body.length;r++)this.astGeneric(e.body[r],t);t.push("}\n")}return t}astVariableDeclaration(e,t){"var"===e.kind&&this.warnVarUsage&&this.varWarn(),t.push(`${e.kind} `);const{declarations:r}=e;for(let e=0;e<r.length;e++)e>0&&t.push(","),this.astGeneric(r[e],t);return this.isState("in-for-loop-init")||t.push(";"),t}astIfStatement(e,t){return t.push("if ("),this.astGeneric(e.test,t),t.push(")"),"BlockStatement"===e.consequent.type?this.astGeneric(e.consequent,t):(t.push(" {\n"),this.astGeneric(e.consequent,t),t.push("\n}\n")),e.alternate&&(t.push("else "),"BlockStatement"===e.alternate.type?this.astGeneric(e.alternate,t):(t.push(" {\n"),this.astGeneric(e.alternate,t),t.push("\n}\n"))),t}astSwitchStatement(e,t){const{discriminant:r,cases:n}=e;t.push("switch ("),this.astGeneric(r,t),t.push(") {\n");for(let e=0;e<n.length;e++)null!==n[e].test?(t.push("case "),this.astGeneric(n[e].test,t),t.push(":\n"),n[e].consequent&&n[e].consequent.length>0&&(this.astGeneric(n[e].consequent,t),t.push("break;\n"))):(t.push("default:\n"),this.astGeneric(n[e].consequent,t),n[e].consequent&&n[e].consequent.length>0&&t.push("break;\n"));t.push("\n}")}astThisExpression(e,t){return t.push("_this"),t}astMemberExpression(e,t){const{signature:r,type:n,property:i,xProperty:s,yProperty:a,zProperty:o,name:u,origin:l}=this.getMemberExpressionDetails(e);switch(r){case"this.thread.value":return t.push(`_this.thread.${u}`),t;case"this.output.value":switch(u){case"x":t.push("outputX");break;case"y":t.push("outputY");break;case"z":t.push("outputZ");break;default:throw this.astErrorOutput("Unexpected expression",e)}return t;case"value":throw this.astErrorOutput("Unexpected expression",e);case"value[]":case"value[][]":case"value[][][]":case"value.value":if("Math"===l)return t.push(Math[u]),t;switch(i){case"r":return t.push(`user_${u}[0]`),t;case"g":return t.push(`user_${u}[1]`),t;case"b":return t.push(`user_${u}[2]`),t;case"a":return t.push(`user_${u}[3]`),t}break;case"this.constants.value":case"this.constants.value[]":case"this.constants.value[][]":case"this.constants.value[][][]":break;case"fn()[]":return this.astGeneric(e.object,t),t.push("["),this.astGeneric(e.property,t),t.push("]"),t;default:throw this.astErrorOutput("Unexpected expression",e)}if(!e.computed)switch(n){case"Number":case"Integer":case"Float":case"Boolean":return t.push(`${l}_${u}`),t}const h=`${l}_${u}`;switch(n){case"Array(2)":case"Array(3)":case"Array(4)":case"HTMLImageArray":case"ArrayTexture(1)":case"ArrayTexture(2)":case"ArrayTexture(3)":case"ArrayTexture(4)":case"HTMLImage":default:let e,r;if("constants"===l){const t=this.constants[u];e=(r="Input"===this.constantTypes[u])?t.size:null}else e=(r=this.isInput(u))?this.argumentSizes[this.argumentNames.indexOf(u)]:null;t.push(`${h}`),o&&a?r?(t.push("[("),this.astGeneric(o,t),t.push(`*${this.dynamicArguments?"(outputY * outputX)":e[1]*e[0]})+(`),this.astGeneric(a,t),t.push(`*${this.dynamicArguments?"outputX":e[0]})+`),this.astGeneric(s,t),t.push("]")):(t.push("["),this.astGeneric(o,t),t.push("]"),t.push("["),this.astGeneric(a,t),t.push("]"),t.push("["),this.astGeneric(s,t),t.push("]")):a?r?(t.push("[("),this.astGeneric(a,t),t.push(`*${this.dynamicArguments?"outputX":e[0]})+`),this.astGeneric(s,t),t.push("]")):(t.push("["),this.astGeneric(a,t),t.push("]"),t.push("["),this.astGeneric(s,t),t.push("]")):void 0!==s&&(t.push("["),this.astGeneric(s,t),t.push("]"))}return t}astCallExpression(e,t){if("CallExpression"!==e.type)throw this.astErrorOutput("Unknown CallExpression",e);let r=this.astMemberExpressionUnroll(e.callee);this.calledFunctions.indexOf(r)<0&&this.calledFunctions.push(r),this.isAstMathFunction(e),this.onFunctionCall&&this.onFunctionCall(this.name,r,e.arguments),t.push(r),t.push("(");const n=this.lookupFunctionArgumentTypes(r)||[];for(let i=0;i<e.arguments.length;++i){const s=e.arguments[i];let a=this.getType(s);n[i]||this.triggerImplyArgumentType(r,i,a,this),i>0&&t.push(", "),this.astGeneric(s,t)}return t.push(")"),t}astArrayExpression(e,t){const r=e.elements.length;t.push("new Float32Array([");for(let n=0;n<r;++n){n>0&&t.push(", ");const r=e.elements[n];this.astGeneric(r,t)}return t.push("])"),t}astDebuggerStatement(e,t){return t.push("debugger;"),t}}}},{"../function-node":10}],7:[function(e,t,r){const{utils:n}=e("../../utils");t.exports={cpuKernelString:function(e,t){const r=[],i=[],s=[],a=!/^function/.test(e.color.toString());if(r.push(" const { context, canvas, constants: incomingConstants } = settings;",` const output = new Int32Array(${JSON.stringify(Array.from(e.output))});`,` const _constantTypes = ${JSON.stringify(e.constantTypes)};`,` const _constants = ${function(e,t){const r=[];for(const n in t){if(!t.hasOwnProperty(n))continue;const i=t[n],s=e[n];switch(i){case"Number":case"Integer":case"Float":case"Boolean":r.push(`${n}:${s}`);break;case"Array(2)":case"Array(3)":case"Array(4)":r.push(`${n}:new ${s.constructor.name}(${JSON.stringify(Array.from(s))})`)}}return`{ ${r.join()} }`}(e.constants,e.constantTypes)};`),i.push(" constants: _constants,"," context,"," output,"," thread: {x: 0, y: 0, z: 0},"),e.graphical){r.push(` const _imageData = context.createImageData(${e.output[0]}, ${e.output[1]});`),r.push(` const _colorData = new Uint8ClampedArray(${e.output[0]} * ${e.output[1]} * 4);`);const t=n.flattenFunctionToString((a?"function ":"")+e.color.toString(),{thisLookup:t=>{switch(t){case"_colorData":return"_colorData";case"_imageData":return"_imageData";case"output":return"output";case"thread":return"this.thread"}return JSON.stringify(e[t])},findDependency:(e,t)=>null}),o=n.flattenFunctionToString((a?"function ":"")+e.getPixels.toString(),{thisLookup:t=>{switch(t){case"_colorData":return"_colorData";case"_imageData":return"_imageData";case"output":return"output";case"thread":return"this.thread"}return JSON.stringify(e[t])},findDependency:()=>null});i.push(" _imageData,"," _colorData,",` color: ${t},`),s.push(` kernel.getPixels = ${o};`)}const o=[],u=Object.keys(e.constantTypes);for(let t=0;t<u.length;t++)o.push(e.constantTypes[u]);if(-1!==e.argumentTypes.indexOf("HTMLImageArray")||-1!==o.indexOf("HTMLImageArray")){const t=n.flattenFunctionToString((a?"function ":"")+e._imageTo3DArray.toString(),{doNotDefine:["canvas"],findDependency:(t,r)=>"this"===t?(a?"function ":"")+e[r].toString():null,thisLookup:e=>{switch(e){case"canvas":return;case"context":return"context"}}});s.push(t),i.push(" _mediaTo2DArray,"),i.push(" _imageTo3DArray,")}else if(-1!==e.argumentTypes.indexOf("HTMLImage")||-1!==o.indexOf("HTMLImage")){const t=n.flattenFunctionToString((a?"function ":"")+e._mediaTo2DArray.toString(),{findDependency:(e,t)=>null,thisLookup:e=>{switch(e){case"canvas":return"settings.canvas";case"context":return"settings.context"}throw new Error("unhandled thisLookup")}});s.push(t),i.push(" _mediaTo2DArray,")}return`function(settings) {\n${r.join("\n")}\n for (const p in _constantTypes) {\n if (!_constantTypes.hasOwnProperty(p)) continue;\n const type = _constantTypes[p];\n switch (type) {\n case 'Number':\n case 'Integer':\n case 'Float':\n case 'Boolean':\n case 'Array(2)':\n case 'Array(3)':\n case 'Array(4)':\n if (incomingConstants.hasOwnProperty(p)) {\n console.warn('constant ' + p + ' of type ' + type + ' cannot be resigned');\n }\n continue;\n }\n if (!incomingConstants.hasOwnProperty(p)) {\n throw new Error('constant ' + p + ' not found');\n }\n _constants[p] = incomingConstants[p];\n }\n const kernel = (function() {\n${e._kernelString}\n })\n .apply({ ${i.join("\n")} });\n ${s.join("\n")}\n return kernel;\n}`}}},{"../../utils":112}],8:[function(e,t,r){const{Kernel:n}=e("../kernel"),{FunctionBuilder:i}=e("../function-builder"),{CPUFunctionNode:s}=e("./function-node"),{utils:a}=e("../../utils"),{cpuKernelString:o}=e("./kernel-string");t.exports={CPUKernel:class extends n{static getFeatures(){return this.features}static get features(){return Object.freeze({kernelMap:!0,isIntegerDivisionAccurate:!0})}static get isSupported(){return!0}static isContextMatch(e){return!1}static get mode(){return"cpu"}static nativeFunctionArguments(){return null}static nativeFunctionReturnType(){return null}static combineKernels(e){return e}constructor(e,t){super(e,t),this.mergeSettings(e.settings||t),this._imageData=null,this._colorData=null,this._kernelString=null,this.thread={x:0,y:0,z:0},this.translatedSources=null}initCanvas(){return"undefined"!=typeof document?document.createElement("canvas"):"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(0,0):void 0}initContext(){return this.canvas?this.canvas.getContext("2d"):null}initPlugins(e){return[]}validateSettings(e){if(!this.output||0===this.output.length){if(1!==e.length)throw new Error("Auto output only supported for kernels with only one input");const t=a.getVariableType(e[0],this.strictIntegers);if("Array"===t)this.output=a.getDimensions(t);else{if("NumberTexture"!==t&&"ArrayTexture(4)"!==t)throw new Error("Auto output not supported for input type: "+t);this.output=e[0].output}}if(this.graphical&&2!==this.output.length)throw new Error("Output must have 2 dimensions on graphical mode");this.checkOutput()}translateSource(){if(this.leadingReturnStatement=this.output.length>1?"resultX[x] = ":"result[x] = ",this.subKernels){const e=[];for(let t=0;t<this.subKernels.length;t++){const{name:r}=this.subKernels[t];e.push(this.output.length>1?`resultX_${r}[x] = subKernelResult_${r};\n`:`result_${r}[x] = subKernelResult_${r};\n`)}this.followingReturnStatement=e.join("")}const e=i.fromKernel(this,s);this.translatedSources=e.getPrototypes("kernel"),this.graphical||this.returnType||(this.returnType=e.getKernelResultType())}build(){if(this.setupConstants(),this.setupArguments(arguments),this.validateSettings(arguments),this.translateSource(),this.graphical){const{canvas:e,output:t}=this;if(!e)throw new Error("no canvas available for using graphical output");const r=t[0],n=t[1]||1;e.width=r,e.height=n,this._imageData=this.context.createImageData(r,n),this._colorData=new Uint8ClampedArray(r*n*4)}const e=this.getKernelString();this.kernelString=e,this.debug&&(console.log("Function output:"),console.log(e));try{this.run=new Function([],e).bind(this)()}catch(e){console.error("An error occurred compiling the javascript: ",e)}}color(e,t,r,n){void 0===n&&(n=1),e=Math.floor(255*e),t=Math.floor(255*t),r=Math.floor(255*r),n=Math.floor(255*n);const i=this.output[0],s=this.output[1],a=this.thread.x+(s-this.thread.y-1)*i;this._colorData[4*a+0]=e,this._colorData[4*a+1]=t,this._colorData[4*a+2]=r,this._colorData[4*a+3]=n}getKernelString(){if(null!==this._kernelString)return this._kernelString;let e=null,{translatedSources:t}=this;return t.length>1?t=t.filter(t=>/^function/.test(t)?t:(e=t,!1)):e=t.shift(),this._kernelString=` const LOOP_MAX = ${this._getLoopMaxString()};\n ${this.injectedNative||""}\n const _this = this;\n ${this._processConstants()}\n return (${this.argumentNames.map(e=>"user_"+e).join(", ")}) => {\n ${this._processArguments()}\n ${this.graphical?this._graphicalKernelBody(e):this._resultKernelBody(e)}\n ${t.length>0?t.join("\n"):""}\n };`}toString(){return o(this)}_getLoopMaxString(){return this.loopMaxIterations?` ${parseInt(this.loopMaxIterations)};`:" 1000;"}_processConstants(){if(!this.constants)return"";const e=[];for(let t in this.constants)switch(this.constantTypes[t]){case"HTMLImage":case"HTMLVideo":e.push(` const constants_${t} = this._mediaTo2DArray(this.constants.${t});\n`);break;case"HTMLImageArray":e.push(` const constants_${t} = this._imageTo3DArray(this.constants.${t});\n`);break;case"Input":e.push(` const constants_${t} = this.constants.${t}.value;\n`);break;default:e.push(` const constants_${t} = this.constants.${t};\n`)}return e.join("")}_processArguments(){const e=[];for(let t=0;t<this.argumentTypes.length;t++){const r=`user_${this.argumentNames[t]}`;switch(this.argumentTypes[t]){case"HTMLImage":case"HTMLVideo":e.push(` ${r} = this._mediaTo2DArray(${r});\n`);break;case"HTMLImageArray":e.push(` ${r} = this._imageTo3DArray(${r});\n`);break;case"Input":e.push(` ${r} = ${r}.value;\n`);break;case"ArrayTexture(1)":case"ArrayTexture(2)":case"ArrayTexture(3)":case"ArrayTexture(4)":case"NumberTexture":case"MemoryOptimizedNumberTexture":e.push(`\n if (${r}.toArray) {\n if (!_this.textureCache) {\n _this.textureCache = [];\n _this.arrayCache = [];\n }\n const textureIndex = _this.textureCache.indexOf(${r});\n if (textureIndex !== -1) {\n ${r} = _this.arrayCache[textureIndex];\n } else {\n _this.textureCache.push(${r});\n ${r} = ${r}.toArray();\n _this.arrayCache.push(${r});\n }\n }`)}}return e.join("")}_mediaTo2DArray(e){const t=this.canvas,r=e.width>0?e.width:e.videoWidth,n=e.height>0?e.height:e.videoHeight;t.width<r&&(t.width=r),t.height<n&&(t.height=n);const i=this.context;i.drawImage(e,0,0,r,n);const s=i.getImageData(0,0,r,n).data,a=new Array(n);let o=0;for(let e=n-1;e>=0;e--){const t=a[e]=new Array(r);for(let e=0;e<r;e++){const r=new Float32Array(4);r[0]=s[o++]/255,r[1]=s[o++]/255,r[2]=s[o++]/255,r[3]=s[o++]/255,t[e]=r}}return a}getPixels(e){const[t,r]=this.output;return e?a.flipPixels(this._imageData.data,t,r):this._imageData.data.slice(0)}_imageTo3DArray(e){const t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=this._mediaTo2DArray(e[r]);return t}_resultKernelBody(e){switch(this.output.length){case 1:return this._resultKernel1DLoop(e)+this._kernelOutput();case 2:return this._resultKernel2DLoop(e)+this._kernelOutput();case 3:return this._resultKernel3DLoop(e)+this._kernelOutput();default:throw new Error("unsupported size kernel")}}_graphicalKernelBody(e){switch(this.output.length){case 2:return this._graphicalKernel2DLoop(e)+this._graphicalOutput();default:throw new Error("unsupported size kernel")}}_graphicalOutput(){return"\n this._imageData.data.set(this._colorData);\n this.context.putImageData(this._imageData, 0, 0);\n return;"}_getKernelResultTypeConstructorString(){switch(this.returnType){case"LiteralInteger":case"Number":case"Integer":case"Float":return"Float32Array";case"Array(2)":case"Array(3)":case"Array(4)":return"Array";default:if(this.graphical)return"Float32Array";throw new Error(`unhandled returnType ${this.returnType}`)}}_resultKernel1DLoop(e){const{output:t}=this,r=this._getKernelResultTypeConstructorString();return` const outputX = _this.output[0];\n const result = new ${r}(outputX);\n ${this._mapSubKernels(e=>`const result_${e.name} = new ${r}(outputX);\n`).join(" ")}\n ${this._mapSubKernels(e=>`let subKernelResult_${e.name};\n`).join(" ")}\n for (let x = 0; x < outputX; x++) {\n this.thread.x = x;\n this.thread.y = 0;\n this.thread.z = 0;\n ${e}\n }`}_resultKernel2DLoop(e){const{output:t}=this,r=this._getKernelResultTypeConstructorString();return` const outputX = _this.output[0];\n const outputY = _this.output[1];\n const result = new Array(outputY);\n ${this._mapSubKernels(e=>`const result_${e.name} = new Array(outputY);\n`).join(" ")}\n ${this._mapSubKernels(e=>`let subKernelResult_${e.name};\n`).join(" ")}\n for (let y = 0; y < outputY; y++) {\n this.thread.z = 0;\n this.thread.y = y;\n const resultX = result[y] = new ${r}(outputX);\n ${this._mapSubKernels(e=>`const resultX_${e.name} = result_${e.name}[y] = new ${r}(outputX);\n`).join("")}\n for (let x = 0; x < outputX; x++) {\n this.thread.x = x;\n ${e}\n }\n }`}_graphicalKernel2DLoop(e){const{output:t}=this,r=this._getKernelResultTypeConstructorString();return` const outputX = _this.output[0];\n const outputY = _this.output[1];\n ${this._mapSubKernels(e=>`const result_${e.name} = new Array(outputY);\n`).join(" ")}\n ${this._mapSubKernels(e=>`let subKernelResult_${e.name};\n`).join(" ")}\n for (let y = 0; y < outputY; y++) {\n this.thread.z = 0;\n this.thread.y = y;\n ${this._mapSubKernels(e=>`const resultX_${e.name} = result_${e.name}[y] = new ${r}(outputX);\n`).join("")}\n for (let x = 0; x < outputX; x++) {\n this.thread.x = x;\n ${e}\n }\n }`}_resultKernel3DLoop(e){const{output:t}=this,r=this._getKernelResultTypeConstructorString();return` const outputX = _this.output[0];\n const outputY = _this.output[1];\n const outputZ = _this.output[2];\n const result = new Array(outputZ);\n ${this._mapSubKernels(e=>`const result_${e.name} = new Array(outputZ);\n`).join(" ")}\n ${this._mapSubKernels(e=>`let subKernelResult_${e.name};\n`).join(" ")}\n for (let z = 0; z < outputZ; z++) {\n this.thread.z = z;\n const resultY = result[z] = new Array(outputY);\n ${this._mapSubKernels(e=>`const resultY_${e.name} = result_${e.name}[z] = new Array(outputY);\n`).join(" ")}\n for (let y = 0; y < outputY; y++) {\n this.thread.y = y;\n const resultX = resultY[y] = new ${r}(outputX);\n ${this._mapSubKernels(e=>`const resultX_${e.name} = resultY_${e.name}[y] = new ${r}(outputX);\n`).join(" ")}\n for (let x = 0; x < outputX; x++) {\n this.thread.x = x;\n ${e}\n }\n }\n }`}_kernelOutput(){return this.subKernels?`\n return {\n result: result,\n ${this.subKernels.map(e=>`${e.property}: result_${e.name}`).join(",\n ")}\n };`:"\n return result;"}_mapSubKernels(e){return null===this.subKernels?[""]:this.subKernels.map(e)}destroy(e){e&&delete this.canvas}static destroyContext(e){}toJSON(){const e=super.toJSON();return e.functionNodes=i.fromKernel(this,s).toJSON(),e}setOutput(e){super.setOutput(e);const[t,r]=this.output;this.graphical&&(this._imageData=this.context.createImageData(t,r),this._colorData=new Uint8ClampedArray(t*r*4))}}}},{"../../utils":112,"../function-builder":9,"../kernel":35,"./function-node":6,"./kernel-string":7}],9:[function(e,t,r){class n{static fromKernel(e,t,r){const{kernelArguments:i,kernelConstants:s,argumentNames:a,argumentSizes:o,argumentBitRatios:u,constants:l,constantBitRatios:h,debug:c,loopMaxIterations:p,nativeFunctions:d,output:m,optimizeFloatMemory:g,precision:f,plugins:x,source:y,subKernels:T,functions:b,leadingReturnStatement:A,followingReturnStatement:v,dynamicArguments:S,dynamicOutput:E,warnVarUsage:_}=e,w=new Array(i.length),k={};for(let e=0;e<i.length;e++)w[e]=i[e].type;for(let e=0;e<s.length;e++){const t=s[e];k[t.name]=t.type}const D=(e,t)=>K.needsArgumentType(e,t),I=(e,t,r)=>{K.assignArgumentType(e,t,r)},R=(e,t,r)=>K.lookupReturnType(e,t,r),L=e=>K.lookupFunctionArgumentTypes(e),$=(e,t)=>K.lookupFunctionArgumentName(e,t),C=(e,t)=>K.lookupFunctionArgumentBitRatio(e,t),F=(e,t,r,n)=>{K.assignArgumentType(e,t,r,n)},V=(e,t,r,n)=>{K.assignArgumentBitRatio(e,t,r,n)},N=(e,t,r)=>{K.trackFunctionCall(e,t,r)},O=(e,r)=>{const n=[];for(let t=0;t<e.params.length;t++)n.push(e.params[t].name);const i=new t(null,Object.assign({},M,{returnType:null,ast:e,name:e.id.name,argumentNames:n,lookupReturnType:R,lookupFunctionArgumentTypes:L,lookupFunctionArgumentName:$,lookupFunctionArgumentBitRatio:C,needsArgumentType:D,assignArgumentType:I,triggerImplyArgumentType:F,triggerImplyArgumentBitRatio:V,onFunctionCall:N,warnVarUsage:_}));i.traceFunctionAST(e),K.addFunctionNode(i)},M=Object.assign({isRootKernel:!1,onNestedFunction:O,lookupReturnType:R,lookupFunctionArgumentTypes:L,lookupFunctionArgumentName:$,lookupFunctionArgumentBitRatio:C,needsArgumentType:D,assignArgumentType:I,triggerImplyArgumentType:F,triggerImplyArgumentBitRatio:V,onFunctionCall:N,optimizeFloatMemory:g,precision:f,constants:l,constantTypes:k,constantBitRatios:h,debug:c,loopMaxIterations:p,output:m,plugins:x,dynamicArguments:S,dynamicOutput:E},r||{}),z=Object.assign({},M,{isRootKernel:!0,name:"kernel",argumentNames:a,argumentTypes:w,argumentSizes:o,argumentBitRatios:u,leadingReturnStatement:A,followingReturnStatement:v});if("object"==typeof y&&y.functionNodes)return(new n).fromJSON(y.functionNodes,t);const P=new t(y,z);let U=null;b&&(U=b.map(e=>new t(e.source,{returnType:e.returnType,argumentTypes:e.argumentTypes,output:m,plugins:x,constants:l,constantTypes:k,constantBitRatios:h,optimizeFloatMemory:g,precision:f,lookupReturnType:R,lookupFunctionArgumentTypes:L,lookupFunctionArgumentName:$,lookupFunctionArgumentBitRatio:C,needsArgumentType:D,assignArgumentType:I,triggerImplyArgumentType:F,triggerImplyArgumentBitRatio:V,onFunctionCall:N,onNestedFunction:O})));let G=null;T&&(G=T.map(e=>{const{name:r,source:n}=e;return new t(n,Object.assign({},M,{name:r,isSubKernel:!0,isRootKernel:!1}))}));const K=new n({kernel:e,rootNode:P,functionNodes:U,nativeFunctions:d,subKernelNodes:G});return K}constructor(e){if(e=e||{},this.kernel=e.kernel,this.rootNode=e.rootNode,this.functionNodes=e.functionNodes||[],this.subKernelNodes=e.subKernelNodes||[],this.nativeFunctions=e.nativeFunctions||[],this.functionMap={},this.nativeFunctionNames=[],this.lookupChain=[],this.argumentChain=[],this.functionNodeDependencies={},this.functionCalls={},this.rootNode&&(this.functionMap.kernel=this.rootNode),this.functionNodes)for(let e=0;e<this.functionNodes.length;e++)this.functionMap[this.functionNodes[e].name]=this.functionNodes[e];if(this.subKernelNodes)for(let e=0;e<this.subKernelNodes.length;e++)this.functionMap[this.subKernelNodes[e].name]=this.subKernelNodes[e];if(this.nativeFunctions)for(let e=0;e<this.nativeFunctions.length;e++){const t=this.nativeFunctions[e];this.nativeFunctionNames.push(t.name)}}addFunctionNode(e){if(!e.name)throw new Error("functionNode.name needs set");this.functionMap[e.name]=e,e.isRootKernel&&(this.rootNode=e)}traceFunctionCalls(e,t){if(e=e||"kernel",t=t||[],this.nativeFunctionNames.indexOf(e)>-1)return-1===t.indexOf(e)&&t.push(e),t;const r=this.functionMap[e];if(r){const n=t.indexOf(e);if(-1===n){t.push(e),r.toString();for(let e=0;e<r.calledFunctions.length;++e)this.traceFunctionCalls(r.calledFunctions[e],t)}else{const e=t.splice(n,1)[0];t.push(e)}}return t}getPrototypeString(e){return this.getPrototypes(e).join("\n")}getPrototypes(e){return this.rootNode&&this.rootNode.toString(),e?this.getPrototypesFromFunctionNames(this.traceFunctionCalls(e,[]).reverse()):this.getPrototypesFromFunctionNames(Object.keys(this.functionMap))}getStringFromFunctionNames(e){const t=[];for(let r=0;r<e.length;++r){this.functionMap[e[r]]&&t.push(this.functionMap[e[r]].toString())}return t.join("\n")}getPrototypesFromFunctionNames(e){const t=[];for(let r=0;r<e.length;++r){const n=e[r],i=this.nativeFunctionNames.indexOf(n);if(i>-1){t.push(this.nativeFunctions[i].source);continue}const s=this.functionMap[n];s&&t.push(s.toString())}return t}toJSON(){return this.traceFunctionCalls(this.rootNode.name).reverse().map(e=>{const t=this.nativeFunctions.indexOf(e);if(t>-1)return{name:e,source:this.nativeFunctions[t].source};if(this.functionMap[e])return this.functionMap[e].toJSON();throw new Error(`function ${e} not found`)})}fromJSON(e,t){this.functionMap={};for(let r=0;r<e.length;r++){const n=e[r];this.functionMap[n.settings.name]=new t(n.ast,n.settings)}return this}getString(e){return e?this.getStringFromFunctionNames(this.traceFunctionCalls(e).reverse()):this.getStringFromFunctionNames(Object.keys(this.functionMap))}lookupReturnType(e,t,r){if("CallExpression"!==t.type)throw new Error(`expected ast type of "CallExpression", but is ${t.type}`);if(this._isNativeFunction(e))return this._lookupNativeFunctionReturnType(e);if(this._isFunction(e)){const n=this._getFunction(e);if(n.returnType)return n.returnType;{for(let e=0;e<this.lookupChain.length;e++)if(this.lookupChain[e].ast===t){if(0===n.argumentTypes.length&&t.arguments.length>0){const i=t.arguments;for(let t=0;t<i.length;t++)this.lookupChain.push({name:r.name,ast:i[e],requestingNode:r}),n.argumentTypes[t]=r.getType(i[t]),this.lookupChain.pop();return n.returnType=n.getType(n.getJsAST())}throw new Error("circlical logic detected!")}this.lookupChain.push({name:r.name,ast:t,requestingNode:r});const e=n.getType(n.getJsAST());return this.lookupChain.pop(),n.returnType=e}}return null}_getFunction(e){return this._isFunction(e)||new Error(`Function ${e} not found`),this.functionMap[e]}_isFunction(e){return Boolean(this.functionMap[e])}_getNativeFunction(e){for(let t=0;t<this.nativeFunctions.length;t++)if(this.nativeFunctions[t].name===e)return this.nativeFunctions[t];return null}_isNativeFunction(e){return Boolean(this._getNativeFunction(e))}_lookupNativeFunctionReturnType(e){let t=this._getNativeFunction(e);if(t)return t.returnType;throw new Error(`Native function ${e} not found`)}lookupFunctionArgumentTypes(e){return this._isNativeFunction(e)?this._getNativeFunction(e).argumentTypes:this._isFunction(e)?this._getFunction(e).argumentTypes:null}lookupFunctionArgumentName(e,t){return this._getFunction(e).argumentNames[t]}lookupFunctionArgumentBitRatio(e,t){if(!this._isFunction(e))throw new Error("function not found");if(this.rootNode.name===e){const e=this.rootNode.argumentNames.indexOf(t);if(-1!==e)return this.rootNode.argumentBitRatios[e]}const r=this._getFunction(e),n=r.argumentNames.indexOf(t);if(-1===n)throw new Error("argument not found");const i=r.argumentBitRatios[n];if("number"!=typeof i)throw new Error("argument bit ratio not found");return i}needsArgumentType(e,t){if(!this._isFunction(e))return!1;return!this._getFunction(e).argumentTypes[t]}assignArgumentType(e,t,r,n){if(!this._isFunction(e))return;const i=this._getFunction(e);i.argumentTypes[t]||(i.argumentTypes[t]=r)}assignArgumentBitRatio(e,t,r,n){const i=this._getFunction(e);if(this._isNativeFunction(r))return null;const s=this._getFunction(r),a=i.argumentNames.indexOf(t);if(-1===a)throw new Error(`Argument ${t} not found in arguments from function ${e}`);const o=i.argumentBitRatios[a];if("number"!=typeof o)throw new Error(`Bit ratio for argument ${t} not found in function ${e}`);s.argumentBitRatios||(s.argumentBitRatios=new Array(s.argumentNames.length));const u=s.argumentBitRatios[a];if("number"==typeof u){if(u!==o)throw new Error(`Incompatible bit ratio found at function ${e} at argument ${t}`);return u}return s.argumentBitRatios[a]=o,o}trackFunctionCall(e,t,r){this.functionNodeDependencies[e]||(this.functionNodeDependencies[e]=new Set,this.functionCalls[e]=[]),this.functionNodeDependencies[e].add(t),this.functionCalls[e].push(r)}getKernelResultType(){return this.rootNode.returnType||this.rootNode.getType(this.rootNode.ast)}getSubKernelResultType(e){const t=this.subKernelNodes[e];let r=!1;for(let e=0;e<this.rootNode.functionCalls.length;e++){this.rootNode.functionCalls[e].ast.callee.name===t.name&&(r=!0)}if(!r)throw new Error(`SubKernel ${t.name} never called by kernel`);return t.returnType||t.getType(t.getJsAST())}getReturnTypes(){const e={[this.rootNode.name]:this.rootNode.getType(this.rootNode.ast)},t=this.traceFunctionCalls(this.rootNode.name);for(let r=0;r<t.length;r++){const n=t[r],i=this.functionMap[n];e[n]=i.getType(i.ast)}return e}}t.exports={FunctionBuilder:n}},{}],10:[function(e,t,r){const n=e("acorn"),{utils:i}=e("../utils"),{FunctionTracer:s}=e("./function-tracer");const a={Number:"Number",Float:"Float",Integer:"Integer",Array:"Number","Array(2)":"Number","Array(3)":"Number","Array(4)":"Number",Array2D:"Number",Array3D:"Number",Input:"Number",HTMLImage:"Array(4)",HTMLVideo:"Array(4)",HTMLImageArray:"Array(4)",NumberTexture:"Number",MemoryOptimizedNumberTexture:"Number","Array1D(2)":"Array(2)","Array1D(3)":"Array(3)","Array1D(4)":"Array(4)","Array2D(2)":"Array(2)","Array2D(3)":"Array(3)","Array2D(4)":"Array(4)","Array3D(2)":"Array(2)","Array3D(3)":"Array(3)","Array3D(4)":"Array(4)","ArrayTexture(1)":"Number","ArrayTexture(2)":"Array(2)","ArrayTexture(3)":"Array(3)","ArrayTexture(4)":"Array(4)"};t.exports={FunctionNode:class{constructor(e,t){if(!e&&!t.ast)throw new Error("source parameter is missing");if(t=t||{},this.source=e,this.ast=null,this.name="string"==typeof e?t.isRootKernel?"kernel":t.name||i.getFunctionNameFromString(e):null,this.calledFunctions=[],this.constants={},this.constantTypes={},this.constantBitRatios={},this.isRootKernel=!1,this.isSubKernel=!1,this.debug=null,this.declarations=null,this.functions=null,this.identifiers=null,this.contexts=null,this.functionCalls=null,this.states=[],this.needsArgumentType=null,this.assignArgumentType=null,this.lookupReturnType=null,this.lookupFunctionArgumentTypes=null,this.lookupFunctionArgumentBitRatio=null,this.triggerImplyArgumentType=null,this.triggerImplyArgumentBitRatio=null,this.onNestedFunction=null,this.onFunctionCall=null,this.optimizeFloatMemory=null,this.precision=null,this.loopMaxIterations=null,this.argumentNames="string"==typeof this.source?i.getArgumentNamesFromString(this.source):null,this.argumentTypes=[],this.argumentSizes=[],this.argumentBitRatios=null,this.returnType=null,this.output=[],this.plugins=null,this.leadingReturnStatement=null,this.followingReturnStatement=null,this.dynamicOutput=null,this.dynamicArguments=null,this.strictTypingChecking=!1,this.fixIntegerDivisionAccuracy=null,this.warnVarUsage=!0,t)for(const e in t)t.hasOwnProperty(e)&&this.hasOwnProperty(e)&&(this[e]=t[e]);this.literalTypes={},this.validate(),this._string=null,this._internalVariableNames={}}validate(){if("string"!=typeof this.source&&!this.ast)throw new Error("this.source not a string");if(!this.ast&&!i.isFunctionString(this.source))throw new Error("this.source not a function string");if(!this.name)throw new Error("this.name could not be set");if(this.argumentTypes.length>0&&this.argumentTypes.length!==this.argumentNames.length)throw new Error(`argumentTypes count of ${this.argumentTypes.length} exceeds ${this.argumentNames.length}`);if(this.output.length<1)throw new Error("this.output is not big enough")}isIdentifierConstant(e){return!!this.constants&&this.constants.hasOwnProperty(e)}isInput(e){return"Input"===this.argumentTypes[this.argumentNames.indexOf(e)]}pushState(e){this.states.push(e)}popState(e){if(this.state!==e)throw new Error(`Cannot popState ${e} when in ${this.state}`);this.states.pop()}isState(e){return this.state===e}get state(){return this.states[this.states.length-1]}astMemberExpressionUnroll(e){if("Identifier"===e.type)return e.name;if("ThisExpression"===e.type)return"this";if("MemberExpression"===e.type&&e.object&&e.property)return e.object.hasOwnProperty("name")&&"_"===e.object.name[0]?this.astMemberExpressionUnroll(e.property):this.astMemberExpressionUnroll(e.object)+"."+this.astMemberExpressionUnroll(e.property);if(e.hasOwnProperty("expressions")){const t=e.expressions[0];if("Literal"===t.type&&0===t.value&&2===e.expressions.length)return this.astMemberExpressionUnroll(e.expressions[1])}throw this.astErrorOutput("Unknown astMemberExpressionUnroll",e)}getJsAST(e){if(this.ast)return this.ast;if("object"==typeof this.source)return this.traceFunctionAST(this.source),this.ast=this.source;if(null===(e=e||n))throw new Error("Missing JS to AST parser");const t=Object.freeze(e.parse(`const parser_${this.name} = ${this.source};`,{locations:!0})),r=t.body[0].declarations[0].init;if(this.traceFunctionAST(r),!t)throw new Error("Failed to parse JS code");return this.ast=r}traceFunctionAST(e){const{contexts:t,declarations:r,functions:n,identifiers:i,functionCalls:a}=new s(e);this.contexts=t,this.identifiers=i,this.functionCalls=a,this.declarations=[],this.functions=n;for(let e=0;e<r.length;e++){const t=r[e],{ast:n,context:i,name:s,origin:a,forceInteger:o,assignable:u}=t,{init:l}=n,h=this.getDependencies(l);let c=null;if(o)c="Integer";else if(l){const e=this.getType(l);switch(e){case"Integer":case"Float":case"Number":c="MemberExpression"===l.type?e:"Number";break;case"LiteralInteger":c="Number";break;default:c=e}}this.declarations.push({valueType:c,dependencies:h,isSafe:this.isSafeDependencies(h),ast:n,name:s,context:i,origin:a,assignable:u})}for(let e=0;e<n.length;e++)this.onNestedFunction(n[e])}getDeclaration(e){for(let t=0;t<this.identifiers.length;t++){const r=this.identifiers[t];if(e===r.ast&&r.context.hasOwnProperty(e.name))for(let t=0;t<this.declarations.length;t++){const n=this.declarations[t];if(n.name===e.name&&n.context[e.name]===r.context[e.name])return n}}return null}getVariableType(e){if("Identifier"!==e.type)throw new Error(`ast of ${e.type} not "Identifier"`);let t=null;const r=this.argumentNames.indexOf(e.name);if(-1===r){const t=this.getDeclaration(e);if(t)return t.valueType}else{const e=this.argumentTypes[r];e&&(t=e)}if(!t&&this.strictTypingChecking)throw new Error(`Declaration of ${name} not found`);return t}getLookupType(e){if(!a.hasOwnProperty(e))throw new Error(`unknown typeLookupMap ${e}`);return a[e]}getConstantType(e){if(this.constantTypes[e]){const t=this.constantTypes[e];return"Float"===t?"Number":t}throw new Error(`Type for constant "${e}" not declared`)}toString(){return this._string?this._string:this._string=this.astGeneric(this.getJsAST(),[]).join("").trim()}toJSON(){const e={source:this.source,name:this.name,constants:this.constants,constantTypes:this.constantTypes,isRootKernel:this.isRootKernel,isSubKernel:this.isSubKernel,debug:this.debug,output:this.output,loopMaxIterations:this.loopMaxIterations,argumentNames:this.argumentNames,argumentTypes:this.argumentTypes,argumentSizes:this.argumentSizes,returnType:this.returnType,leadingReturnStatement:this.leadingReturnStatement,followingReturnStatement:this.followingReturnStatement};return{ast:this.ast,settings:e}}getType(e){if(Array.isArray(e))return this.getType(e[e.length-1]);switch(e.type){case"BlockStatement":return this.getType(e.body);case"ArrayExpression":return`Array(${e.elements.length})`;case"Literal":const t=`${e.start},${e.end}`;return this.literalTypes[t]?this.literalTypes[t]:Number.isInteger(e.value)?"LiteralInteger":!0===e.value||!1===e.value?"Boolean":"Number";case"AssignmentExpression":return this.getType(e.left);case"CallExpression":if(this.isAstMathFunction(e))return"Number";if(!e.callee||!e.callee.name){if("SequenceExpression"===e.callee.type&&e.callee.expressions[e.callee.expressions.length-1].property.name){const t=e.callee.expressions[e.callee.expressions.length-1].property.name;return this.inferArgumentTypesIfNeeded(t,e.arguments),this.lookupReturnType(t,e,this)}throw this.astErrorOutput("Unknown call expression",e)}if(e.callee&&e.callee.name){const t=e.callee.name;return this.inferArgumentTypesIfNeeded(t,e.arguments),this.lookupReturnType(t,e,this)}throw this.astErrorOutput(`Unhandled getType Type "${e.type}"`,e);case"BinaryExpression":switch(e.operator){case"%":case"/":if(this.fixIntegerDivisionAccuracy)return"Number";break;case">":case"<":return"Boolean";case"&":case"|":case"^":case"<<":case">>":case">>>":return"Integer"}const r=this.getType(e.left);if(this.isState("skip-literal-correction"))return r;if("LiteralInteger"===r){const t=this.getType(e.right);return"LiteralInteger"===t?e.left.value%1==0?"Integer":"Float":t}return a[r]||r;case"UpdateExpression":return this.getType(e.argument);case"UnaryExpression":return"~"===e.operator?"Integer":this.getType(e.argument);case"VariableDeclaration":{const t=e.declarations;let r;for(let e=0;e<t.length;e++){const n=t[e];r=this.getType(n)}if(!r)throw this.astErrorOutput("Unable to find type for declaration",e);return r}case"VariableDeclarator":const n=this.getDeclaration(e.id);if(!n)throw this.astErrorOutput("Unable to find declarator",e);if(!n.valueType)throw this.astErrorOutput("Unable to find declarator valueType",e);return n.valueType;case"Identifier":if("Infinity"===e.name)return"Number";if(this.isAstVariable(e)&&"value"===this.getVariableSignature(e)){const t=this.getVariableType(e);if(!t)throw this.astErrorOutput("Unable to find identifier valueType",e);return t}const i=this.findIdentifierOrigin(e);return i&&i.init?this.getType(i.init):null;case"ReturnStatement":return this.getType(e.argument);case"MemberExpression":if(this.isAstMathFunction(e)){switch(e.property.name){case"ceil":case"floor":case"round":return"Integer"}return"Number"}if(this.isAstVariable(e)){switch(this.getVariableSignature(e)){case"value[]":return this.getLookupType(this.getVariableType(e.object));case"value[][]":return this.getLookupType(this.getVariableType(e.object.object));case"value[][][]":return this.getLookupType(this.getVariableType(e.object.object.object));case"value[][][][]":return this.getLookupType(this.getVariableType(e.object.object.object.object));case"value.thread.value":case"this.thread.value":return"Integer";case"this.output.value":return this.dynamicOutput?"Integer":"LiteralInteger";case"this.constants.value":return this.getConstantType(e.property.name);case"this.constants.value[]":return this.getLookupType(this.getConstantType(e.object.property.name));case"this.constants.value[][]":return this.getLookupType(this.getConstantType(e.object.object.property.name));case"this.constants.value[][][]":return this.getLookupType(this.getConstantType(e.object.object.object.property.name));case"this.constants.value[][][][]":return this.getLookupType(this.getConstantType(e.object.object.object.object.property.name));case"fn()[]":case"fn()[][]":case"fn()[][][]":return this.getLookupType(this.getType(e.object));case"value.value":if(this.isAstMathVariable(e))return"Number";switch(e.property.name){case"r":case"g":case"b":case"a":return this.getLookupType(this.getVariableType(e.object))}case"[][]":return"Number"}throw this.astErrorOutput("Unhandled getType MemberExpression",e)}throw this.astErrorOutput("Unhandled getType MemberExpression",e);case"ConditionalExpression":return this.getType(e.consequent);case"FunctionDeclaration":case"FunctionExpression":const s=this.findLastReturn(e.body);return s?this.getType(s):null;case"IfStatement":return this.getType(e.consequent);default:throw this.astErrorOutput(`Unhandled getType Type "${e.type}"`,e)}}inferArgumentTypesIfNeeded(e,t){for(let r=0;r<t.length;r++){if(!this.needsArgumentType(e,r))continue;const n=this.getType(t[r]);if(!n)throw this.astErrorOutput(`Unable to infer argument ${r}`,t[r]);this.assignArgumentType(e,r,n)}}isAstMathVariable(e){return"MemberExpression"===e.type&&e.object&&"Identifier"===e.object.type&&"Math"===e.object.name&&e.property&&"Identifier"===e.property.type&&["E","PI","SQRT2","SQRT1_2","LN2","LN10","LOG2E","LOG10E"].indexOf(e.property.name)>-1}isAstMathFunction(e){return"CallExpression"===e.type&&e.callee&&"MemberExpression"===e.callee.type&&e.callee.object&&"Identifier"===e.callee.object.type&&"Math"===e.callee.object.name&&e.callee.property&&"Identifier"===e.callee.property.type&&["abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","log2","max","min","pow","random","round","sign","sin","sqrt","tan"].indexOf(e.callee.property.name)>-1}isAstVariable(e){return"Identifier"===e.type||"MemberExpression"===e.type}isSafe(e){return this.isSafeDependencies(this.getDependencies(e))}isSafeDependencies(e){return!e||!e.every||e.every(e=>e.isSafe)}getDependencies(e,t,r){if(t||(t=[]),!e)return null;if(Array.isArray(e)){for(let n=0;n<e.length;n++)this.getDependencies(e[n],t,r);return t}switch(e.type){case"AssignmentExpression":return this.getDependencies(e.left,t,r),this.getDependencies(e.right,t,r),t;case"ConditionalExpression":return this.getDependencies(e.test,t,r),this.getDependencies(e.alternate,t,r),this.getDependencies(e.consequent,t,r),t;case"Literal":t.push({origin:"literal",value:e.value,isSafe:!0!==r&&e.value>-1/0&&e.value<1/0&&!isNaN(e.value)});break;case"VariableDeclarator":return this.getDependencies(e.init,t,r);case"Identifier":const n=this.getDeclaration(e);if(n)t.push({name:e.name,origin:"declaration",isSafe:!r&&this.isSafeDependencies(n.dependencies)});else if(this.argumentNames.indexOf(e.name)>-1)t.push({name:e.name,origin:"argument",isSafe:!1});else if(this.strictTypingChecking)throw new Error(`Cannot find identifier origin "${e.name}"`);break;case"FunctionDeclaration":return this.getDependencies(e.body.body[e.body.body.length-1],t,r);case"ReturnStatement":return this.getDependencies(e.argument,t);case"BinaryExpression":return r="/"===e.operator||"*"===e.operator,this.getDependencies(e.left,t,r),this.getDependencies(e.right,t,r),t;case"UnaryExpression":case"UpdateExpression":return this.getDependencies(e.argument,t,r);case"VariableDeclaration":return this.getDependencies(e.declarations,t,r);case"ArrayExpression":return t.push({origin:"declaration",isSafe:!0}),t;case"CallExpression":return t.push({origin:"function",isSafe:!0}),t;case"MemberExpression":const i=this.getMemberExpressionDetails(e);switch(i.signature){case"value[]":this.getDependencies(e.object,t,r);break;case"value[][]":this.getDependencies(e.object.object,t,r);break;case"value[][][]":this.getDependencies(e.object.object.object,t,r);break;case"this.output.value":this.dynamicOutput&&t.push({name:i.name,origin:"output",isSafe:!1})}if(i)return i.property&&this.getDependencies(i.property,t,r),i.xProperty&&this.getDependencies(i.xProperty,t,r),i.yProperty&&this.getDependencies(i.yProperty,t,r),i.zProperty&&this.getDependencies(i.zProperty,t,r),t;default:throw this.astErrorOutput(`Unhandled type ${e.type} in getDependencies`,e)}return t}getVariableSignature(e){if(!this.isAstVariable(e))throw new Error(`ast of type "${e.type}" is not a variable signature`);if("Identifier"===e.type)return"value";const t=[];for(;e;)e.computed?t.push("[]"):"ThisExpression"===e.type?t.unshift("this"):e.property&&e.property.name?"x"===e.property.name||"y"===e.property.name||"z"===e.property.name?t.unshift(".value"):"constants"===e.property.name||"thread"===e.property.name||"output"===e.property.name?t.unshift("."+e.property.name):t.unshift(".value"):e.name?t.unshift("value"):e.callee&&e.callee.name?t.unshift("fn()"):e.elements?t.unshift("[]"):t.unshift("unknown"),e=e.object;const r=t.join("");return["value","value[]","value[][]","value[][][]","value[][][][]","value.value","value.thread.value","this.thread.value","this.output.value","this.constants.value","this.constants.value[]","this.constants.value[][]","this.constants.value[][][]","this.constants.value[][][][]","fn()[]","fn()[][]","fn()[][][]","[][]"].indexOf(r)>-1?r:null}build(){return this.toString().length>0}astGeneric(e,t){if(null===e)throw this.astErrorOutput("NULL ast",e);if(Array.isArray(e)){for(let r=0;r<e.length;r++)this.astGeneric(e[r],t);return t}switch(e.type){case"FunctionDeclaration":return this.astFunctionDeclaration(e,t);case"FunctionExpression":return this.astFunctionExpression(e,t);case"ReturnStatement":return this.astReturnStatement(e,t);case"Literal":return this.astLiteral(e,t);case"BinaryExpression":return this.astBinaryExpression(e,t);case"Identifier":return this.astIdentifierExpression(e,t);case"AssignmentExpression":return this.astAssignmentExpression(e,t);case"ExpressionStatement":return this.astExpressionStatement(e,t);case"EmptyStatement":return this.astEmptyStatement(e,t);case"BlockStatement":return this.astBlockStatement(e,t);case"IfStatement":return this.astIfStatement(e,t);case"SwitchStatement":return this.astSwitchStatement(e,t);case"BreakStatement":return this.astBreakStatement(e,t);case"ContinueStatement":return this.astContinueStatement(e,t);case"ForStatement":return this.astForStatement(e,t);case"WhileStatement":return this.astWhileStatement(e,t);case"DoWhileStatement":return this.astDoWhileStatement(e,t);case"VariableDeclaration":return this.astVariableDeclaration(e,t);case"VariableDeclarator":return this.astVariableDeclarator(e,t);case"ThisExpression":return this.astThisExpression(e,t);case"SequenceExpression":return this.astSequenceExpression(e,t);case"UnaryExpression":return this.astUnaryExpression(e,t);case"UpdateExpression":return this.astUpdateExpression(e,t);case"LogicalExpression":return this.astLogicalExpression(e,t);case"MemberExpression":return this.astMemberExpression(e,t);case"CallExpression":return this.astCallExpression(e,t);case"ArrayExpression":return this.astArrayExpression(e,t);case"DebuggerStatement":return this.astDebuggerStatement(e,t);case"ConditionalExpression":return this.astConditionalExpression(e,t)}throw this.astErrorOutput("Unknown ast type : "+e.type,e)}astErrorOutput(e,t){if("string"!=typeof this.source)return new Error(e);const r=i.getAstString(this.source,t),n=this.source.substr(t.start).split(/\n/),s=n.length>0?n[n.length-1]:0;return new Error(`${e} on line ${n.length}, position ${s.length}:\n ${r}`)}astDebuggerStatement(e,t){return t}astConditionalExpression(e,t){if("ConditionalExpression"!==e.type)throw this.astErrorOutput("Not a conditional expression",e);return t.push("("),this.astGeneric(e.test,t),t.push("?"),this.astGeneric(e.consequent,t),t.push(":"),this.astGeneric(e.alternate,t),t.push(")"),t}astFunction(e,t){throw new Error(`"astFunction" not defined on ${this.constructor.name}`)}astFunctionDeclaration(e,t){return this.isChildFunction(e)?t:this.astFunction(e,t)}astFunctionExpression(e,t){return this.isChildFunction(e)?t:this.astFunction(e,t)}isChildFunction(e){for(let t=0;t<this.functions.length;t++)if(this.functions[t]===e)return!0;return!1}astReturnStatement(e,t){return t}astLiteral(e,t){return this.literalTypes[`${e.start},${e.end}`]="Number",t}astBinaryExpression(e,t){return t}astIdentifierExpression(e,t){return t}astAssignmentExpression(e,t){return t}astExpressionStatement(e,t){return this.astGeneric(e.expression,t),t.push(";"),t}astEmptyStatement(e,t){return t}astBlockStatement(e,t){return t}astIfStatement(e,t){return t}astSwitchStatement(e,t){return t}astBreakStatement(e,t){return t.push("break;"),t}astContinueStatement(e,t){return t.push("continue;\n"),t}astForStatement(e,t){return t}astWhileStatement(e,t){return t}astDoWhileStatement(e,t){return t}astVariableDeclaration(e,t){const r=e.declarations;if(!r||!r[0]||!r[0].init)throw this.astErrorOutput("Unexpected expression",e);const n=r[0],i=n.init;let s=this.isState("in-for-loop-init")?"Integer":this.getType(i);"LiteralInteger"===s&&(s="Number");const a=typeMap[s];if(!a)throw this.astErrorOutput(`Markup type ${a} not handled`,e);throw this.getDependencies(n.init),new Error("remove me")}astVariableDeclarator(e,t){return this.astGeneric(e.id,t),null!==e.init&&(t.push("="),this.astGeneric(e.init,t)),t}astThisExpression(e,t){return t}astSequenceExpression(e,t){for(let r=0;r<e.expressions.length;r++)r>0&&t.push(","),this.astGeneric(e.expressions,t);return t}astUnaryExpression(e,t){return this.checkAndUpconvertBitwiseUnary(e,t)?t:(e.prefix?(t.push(e.operator),this.astGeneric(e.argument,t)):(this.astGeneric(e.argument,t),t.push(e.operator)),t)}checkAndUpconvertBitwiseUnary(e,t){}astUpdateExpression(e,t){return e.prefix?(t.push(e.operator),this.astGeneric(e.argument,t)):(this.astGeneric(e.argument,t),t.push(e.operator)),t}astLogicalExpression(e,t){return t.push("("),this.astGeneric(e.left,t),t.push(e.operator),this.astGeneric(e.right,t),t.push(")"),t}astMemberExpression(e,t){return t}astCallExpression(e,t){return t}astArrayExpression(e,t){return t}getMemberExpressionDetails(e){if("MemberExpression"!==e.type)throw this.astErrorOutput(`Expression ${e.type} not a MemberExpression`,e);let t=null,r=null;const n=this.getVariableSignature(e);switch(n){case"value":return null;case"value.thread.value":case"this.thread.value":case"this.output.value":return{signature:n,type:"Integer",name:e.property.name};case"value[]":if("string"!=typeof e.object.name)throw this.astErrorOutput("Unexpected expression",e);return{name:t=e.object.name,origin:"user",signature:n,type:this.getVariableType(e.object),xProperty:e.property};case"value[][]":if("string"!=typeof e.object.object.name)throw this.astErrorOutput("Unexpected expression",e);return{name:t=e.object.object.name,origin:"user",signature:n,type:this.getVariableType(e.object.object),yProperty:e.object.property,xProperty:e.property};case"value[][][]":if("string"!=typeof e.object.object.object.name)throw this.astErrorOutput("Unexpected expression",e);return{name:t=e.object.object.object.name,origin:"user",signature:n,type:this.getVariableType(e.object.object.object),zProperty:e.object.object.property,yProperty:e.object.property,xProperty:e.property};case"value[][][][]":if("string"!=typeof e.object.object.object.object.name)throw this.astErrorOutput("Unexpected expression",e);return{name:t=e.object.object.object.object.name,origin:"user",signature:n,type:this.getVariableType(e.object.object.object.object),zProperty:e.object.object.property,yProperty:e.object.property,xProperty:e.property};case"value.value":if("string"!=typeof e.property.name)throw this.astErrorOutput("Unexpected expression",e);if(this.isAstMathVariable(e))return{name:t=e.property.name,origin:"Math",type:"Number",signature:n};switch(e.property.name){case"r":case"g":case"b":case"a":return{name:t=e.object.name,property:e.property.name,origin:"user",signature:n,type:"Number"};default:throw this.astErrorOutput("Unexpected expression",e)}case"this.constants.value":if("string"!=typeof e.property.name)throw this.astErrorOutput("Unexpected expression",e);if(t=e.property.name,!(r=this.getConstantType(t)))throw this.astErrorOutput("Constant has no type",e);return{name:t,type:r,origin:"constants",signature:n};case"this.constants.value[]":if("string"!=typeof e.object.property.name)throw this.astErrorOutput("Unexpected expression",e);if(t=e.object.property.name,!(r=this.getConstantType(t)))throw this.astErrorOutput("Constant has no type",e);return{name:t,type:r,origin:"constants",signature:n,xProperty:e.property};case"this.constants.value[][]":if("string"!=typeof e.object.object.property.name)throw this.astErrorOutput("Unexpected expression",e);if(t=e.object.object.property.name,!(r=this.getConstantType(t)))throw this.astErrorOutput("Constant has no type",e);return{name:t,type:r,origin:"constants",signature:n,yProperty:e.object.property,xProperty:e.property};case"this.constants.value[][][]":if("string"!=typeof e.object.object.object.property.name)throw this.astErrorOutput("Unexpected expression",e);if(t=e.object.object.object.property.name,!(r=this.getConstantType(t)))throw this.astErrorOutput("Constant has no type",e);return{name:t,type:r,origin:"constants",signature:n,zProperty:e.object.object.property,yProperty:e.object.property,xProperty:e.property};case"fn()[]":case"[][]":return{signature:n,property:e.property};default:throw this.astErrorOutput("Unexpected expression",e)}}findIdentifierOrigin(e){const t=[this.ast];for(;t.length>0;){const r=t[0];if("VariableDeclarator"===r.type&&r.id&&r.id.name&&r.id.name===e.name)return r;if(t.shift(),r.argument)t.push(r.argument);else if(r.body)t.push(r.body);else if(r.declarations)t.push(r.declarations);else if(Array.isArray(r))for(let e=0;e<r.length;e++)t.push(r[e])}return null}findLastReturn(e){const t=[e||this.ast];for(;t.length>0;){const e=t.pop();if("ReturnStatement"===e.type)return e;if("FunctionDeclaration"!==e.type)if(e.argument)t.push(e.argument);else if(e.body)t.push(e.body);else if(e.declarations)t.push(e.declarations);else if(Array.isArray(e))for(let r=0;r<e.length;r++)t.push(e[r]);else e.consequent?t.push(e.consequent):e.cases&&t.push(e.cases)}return null}getInternalVariableName(e){return this._internalVariableNames.hasOwnProperty(e)||(this._internalVariableNames[e]=0),this._internalVariableNames[e]++,1===this._internalVariableNames[e]?e:e+this._internalVariableNames[e]}varWarn(){console.warn("var declarations are deprecated, weird things happen when falling back to CPU because var scope differs in javascript than in most languages. Use const or let")}}}},{"../utils":112,"./function-tracer":11,acorn:1}],11:[function(e,t,r){t.exports={FunctionTracer:class{constructor(e){this.runningContexts=[],this.contexts=[],this.functionCalls=[],this.declarations=[],this.identifiers=[],this.functions=[],this.returnStatements=[],this.inLoopInit=!1,this.scan(e)}get currentContext(){return this.runningContexts.length>0?this.runningContexts[this.runningContexts.length-1]:null}newContext(e){const t=Object.assign({},this.currentContext);this.contexts.push(t),this.runningContexts.push(t),e(),this.runningContexts.pop()}scan(e){if(e)if(Array.isArray(e))for(let t=0;t<e.length;t++)this.scan(e[t]);else switch(e.type){case"Program":this.scan(e.body);break;case"BlockStatement":this.newContext(()=>{this.scan(e.body)});break;case"AssignmentExpression":case"LogicalExpression":case"BinaryExpression":this.scan(e.left),this.scan(e.right);break;case"UpdateExpression":case"UnaryExpression":this.scan(e.argument);break;case"VariableDeclaration":this.scan(e.declarations);break;case"VariableDeclarator":const{currentContext:t}=this,r={ast:e,context:t,name:e.id.name,origin:"declaration",forceInteger:this.inLoopInit,assignable:!this.inLoopInit&&!t.hasOwnProperty(e.id.name)};t[e.id.name]=r,this.declarations.push(r),this.scan(e.id),this.scan(e.init);break;case"FunctionExpression":case"FunctionDeclaration":0===this.runningContexts.length?this.scan(e.body):this.functions.push(e);break;case"IfStatement":this.scan(e.test),this.scan(e.consequent),e.alternate&&this.scan(e.alternate);break;case"ForStatement":this.newContext(()=>{this.inLoopInit=!0,this.scan(e.init),this.inLoopInit=!1,this.scan(e.test),this.scan(e.update),this.newContext(()=>{this.scan(e.body)})});break;case"DoWhileStatement":case"WhileStatement":this.newContext(()=>{this.scan(e.body),this.scan(e.test)});break;case"Identifier":this.identifiers.push({context:this.currentContext,ast:e});break;case"ReturnStatement":this.returnStatements.push(e),this.scan(e.argument);break;case"MemberExpression":this.scan(e.object),this.scan(e.property);break;case"ExpressionStatement":this.scan(e.expression);break;case"CallExpression":this.functionCalls.push({context:this.currentContext,ast:e}),this.scan(e.arguments);break;case"ArrayExpression":this.scan(e.elements);break;case"ConditionalExpression":this.scan(e.test),this.scan(e.alternate),this.scan(e.consequent);break;case"SwitchStatement":this.scan(e.discriminant),this.scan(e.cases);break;case"SwitchCase":this.scan(e.test),this.scan(e.consequent);break;case"ThisExpression":case"Literal":case"DebuggerStatement":case"EmptyStatement":case"BreakStatement":case"ContinueStatement":break;default:throw new Error(`unhandled type "${e.type}"`)}}}}},{}],12:[function(e,t,r){const{glWiretap:n}=e("gl-wiretap"),{utils:i}=e("../../utils");function s(e){return e.toString().replace("=>","").replace(/^function /,"").replace(/utils[.]/g,"/*utils.*/")}function a(e,t){const r="single"===t.precision?e:`new Float32Array(${e}.buffer)`;return t.output[2]?`renderOutput(${r}, ${t.output[0]}, ${t.output[1]}, ${t.output[2]})`:t.output[1]?`renderOutput(${r}, ${t.output[0]}, ${t.output[1]})`:`renderOutput(${r}, ${t.output[0]})`}function o(e,t){const r=e.toArray.toString(),n=!/^function/.test(r);return`() => {\n ${i.flattenFunctionToString(`${n?"function ":""}${r}`,{findDependency:(t,r)=>{if("utils"===t)return`const ${r} = ${i[r].toString()};`;if("this"===t)return`${n?"function ":""}${e[r].toString()}`;throw new Error("unhandled fromObject")},thisLookup:r=>{if("texture"===r)return t;if(e.hasOwnProperty(r))return JSON.stringify(e[r]);throw new Error(`unhandled thisLookup ${r}`)}})}\n return toArray();\n }`}function u(e,t,r,n,i){if(null===e)return null;switch(typeof e){case"boolean":case"number":return null}if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement){for(let i=0;i<t.length;i++){const s=t[i];if("HTMLImageArray"!==s.type)continue;if(s.uploadValue!==e)continue;const a=r[i].indexOf(e);if(-1===a)continue;const o=`uploadValue_${s.name}[${a}]`;return n.insertVariable(o,e),o}return null}for(let r=0;r<t.length;r++){const i=t[r];if(e!==i.uploadValue)continue;const s=`uploadValue_${i.name}`;return n.insertVariable(s,i),s}return null}t.exports={glKernelString:function(e,t,r,l,h){t=t?Array.from(t).map(e=>{switch(typeof e){case"boolean":return new Boolean(e);case"number":return new Number(e);default:return e}}):null;const c=[],p=n(r.context,{useTrackablePrimitives:!0,onReadPixels:e=>{if(C.subKernels){if(d){const t=C.subKernels[m++].property;c.push(` result${isNaN(t)?"."+t:`[${t}]`} = ${a(e,C)};`)}else c.push(` const result = { result: ${a(e,C)} };`),d=!0;m===C.subKernels.length&&c.push(" return result;")}else e?c.push(` return ${a(e,C)};`):c.push(" return null;")},onUnrecognizedArgumentLookup:e=>{const t=u(e,C.kernelArguments,[],p);if(t)return t;const r=u(e,C.kernelConstants,A?Object.keys(A).map(e=>A[e]):[],p);return r||null}});let d=!1,m=0;const{source:g,canvas:f,output:x,pipeline:y,graphical:T,loopMaxIterations:b,constants:A,optimizeFloatMemory:v,precision:S,fixIntegerDivisionAccuracy:E,functions:_,nativeFunctions:w,subKernels:k,immutable:D,argumentTypes:I,constantTypes:R,kernelArguments:L,kernelConstants:$}=r,C=new e(g,{canvas:f,context:p,checkContext:!1,output:x,pipeline:y,graphical:T,loopMaxIterations:b,constants:A,optimizeFloatMemory:v,precision:S,fixIntegerDivisionAccuracy:E,functions:_,nativeFunctions:w,subKernels:k,immutable:D,argumentTypes:I,constantTypes:R});let F=[];if(p.setIndent(2),C.build.apply(C,t),F.push(p.toString()),p.reset(),C.kernelArguments.forEach((e,r)=>{switch(e.type){case"Integer":case"Boolean":case"Number":case"Float":case"Array":case"Array(2)":case"Array(3)":case"Array(4)":case"HTMLImage":case"HTMLVideo":p.insertVariable(`uploadValue_${e.name}`,e.uploadValue);break;case"HTMLImageArray":for(let n=0;n<t[r].length;n++){const i=t[r];p.insertVariable(`uploadValue_${e.name}[${n}]`,i[n])}break;case"Input":p.insertVariable(`uploadValue_${e.name}`,e.uploadValue);break;case"MemoryOptimizedNumberTexture":case"NumberTexture":case"Array1D(2)":case"Array1D(3)":case"Array1D(4)":case"Array2D(2)":case"Array2D(3)":case"Array2D(4)":case"Array3D(2)":case"Array3D(3)":case"Array3D(4)":case"ArrayTexture(1)":case"ArrayTexture(2)":case"ArrayTexture(3)":case"ArrayTexture(4)":p.insertVariable(`uploadValue_${e.name}`,t[r].texture);break;default:throw new Error(`unhandled kernelArgumentType insertion for glWiretap of type ${e.type}`)}}),F.push("/** start of injected functions **/"),F.push(`function ${s(i.flattenTo)}`),F.push(`function ${s(i.flatten2dArrayTo)}`),F.push(`function ${s(i.flatten3dArrayTo)}`),F.push(`function ${s(i.flatten4dArrayTo)}`),F.push(`function ${s(i.isArray)}`),C.renderOutput!==C.renderTexture&&C.formatValues&&F.push(` const renderOutput = function ${s(C.formatValues)};`),F.push("/** end of injected functions **/"),F.push(` const innerKernel = function (${C.kernelArguments.map(e=>e.varName).join(", ")}) {`),p.setIndent(4),C.run.apply(C,t),C.renderKernels?C.renderKernels():C.renderOutput&&C.renderOutput(),F.push(" /** start setup uploads for kernel values **/"),C.kernelArguments.forEach(e=>{F.push(" "+e.getStringValueHandler().split("\n").join("\n "))}),F.push(" /** end setup uploads for kernel values **/"),F.push(p.toString()),C.renderOutput===C.renderTexture){p.reset();const e=C.renderKernels(),t=p.getContextVariableName(C.outputTexture);F.push(` return {\n result: {\n texture: ${t},\n type: '${e.result.type}',\n toArray: ${o(e.result,t)}\n },`);const{subKernels:r,subKernelOutputTextures:n}=C;for(let t=0;t<r.length;t++){const i=n[t],s=r[t],a=e[s.property],u=p.getContextVariableName(i);F.push(`\n ${s.property}: {\n texture: ${u},\n type: '${a.type}',\n toArray: ${o(a,u)}\n },`)}F.push(" };")}F.push(` ${h?"\n"+h+" ":""}`),F.push(c.join("\n")),F.push(" };"),C.graphical&&(F.push(function(e){const t=e.getPixels.toString(),r=!/^function/.test(t);return i.flattenFunctionToString(`${r?"function ":""}${t}`,{findDependency:(e,t)=>"utils"===e?`const ${t} = ${i[t].toString()};`:null,thisLookup:t=>{if("context"===t)return null;if(e.hasOwnProperty(t))return JSON.stringify(e[t]);throw new Error(`unhandled thisLookup ${t}`)}})}(C)),F.push(" innerKernel.getPixels = getPixels;")),F.push(" return innerKernel;");let V=[];return $.forEach(e=>{V.push(`${e.getStringValueHandler()}`)}),`function kernel(settings) {\n const { context, constants } = settings;\n ${V.join("")}\n ${l||""}\n${F.join("\n")}\n}`}}},{"../../utils":112,"gl-wiretap":3}],13:[function(e,t,r){const{Kernel:n}=e("../kernel"),{Texture:i}=e("../../texture"),{utils:s}=e("../../utils"),{GLTextureArray2Float:a}=e("./texture/array-2-float"),{GLTextureArray2Float2D:o}=e("./texture/array-2-float-2d"),{GLTextureArray2Float3D:u}=e("./texture/array-2-float-3d"),{GLTextureArray3Float:l}=e("./texture/array-3-float"),{GLTextureArray3Float2D:h}=e("./texture/array-3-float-2d"),{GLTextureArray3Float3D:c}=e("./texture/array-3-float-3d"),{GLTextureArray4Float:p}=e("./texture/array-4-float"),{GLTextureArray4Float2D:d}=e("./texture/array-4-float-2d"),{GLTextureArray4Float3D:m}=e("./texture/array-4-float-3d"),{GLTextureFloat:g}=e("./texture/float"),{GLTextureFloat2D:f}=e("./texture/float-2d"),{GLTextureFloat3D:x}=e("./texture/float-3d"),{GLTextureMemoryOptimized:y}=e("./texture/memory-optimized"),{GLTextureMemoryOptimized2D:T}=e("./texture/memory-optimized-2d"),{GLTextureMemoryOptimized3D:b}=e("./texture/memory-optimized-3d"),{GLTextureUnsigned:A}=e("./texture/unsigned"),{GLTextureUnsigned2D:v}=e("./texture/unsigned-2d"),{GLTextureUnsigned3D:S}=e("./texture/unsigned-3d"),{GLTextureGraphical:E}=e("./texture/graphical");const _=Object.freeze({PackedPixelToUint8Array:Symbol("PackedPixelToUint8Array"),PackedPixelToFloat:Symbol("PackedPixelToFloat"),PackedPixelTo2DFloat:Symbol("PackedPixelTo2DFloat"),PackedPixelTo3DFloat:Symbol("PackedPixelTo3DFloat"),PackedTexture:Symbol("PackedTexture"),FloatPixelToFloat32Array:Symbol("FloatPixelToFloat32Array"),FloatPixelToFloat:Symbol("FloatPixelToFloat"),FloatPixelTo2DFloat:Symbol("FloatPixelTo2DFloat"),FloatPixelTo3DFloat:Symbol("FloatPixelTo3DFloat"),FloatPixelToArray2:Symbol("FloatPixelToArray2"),FloatPixelTo2DArray2:Symbol("FloatPixelTo2DArray2"),FloatPixelTo3DArray2:Symbol("FloatPixelTo3DArray2"),FloatPixelToArray3:Symbol("FloatPixelToArray3"),FloatPixelTo2DArray3:Symbol("FloatPixelTo2DArray3"),FloatPixelTo3DArray3:Symbol("FloatPixelTo3DArray3"),FloatPixelToArray4:Symbol("FloatPixelToArray4"),FloatPixelTo2DArray4:Symbol("FloatPixelTo2DArray4"),FloatPixelTo3DArray4:Symbol("FloatPixelTo3DArray4"),FloatTexture:Symbol("FloatTexture"),MemoryOptimizedFloatPixelToMemoryOptimizedFloat:Symbol("MemoryOptimizedFloatPixelToFloat"),MemoryOptimizedFloatPixelToMemoryOptimized2DFloat:Symbol("MemoryOptimizedFloatPixelTo2DFloat"),MemoryOptimizedFloatPixelToMemoryOptimized3DFloat:Symbol("MemoryOptimizedFloatPixelTo3DFloat")}),w={int:"Integer",float:"Number",vec2:"Array(2)",vec3:"Array(3)",vec4:"Array(4)"};t.exports={GLKernel:class extends n{static get mode(){return"gpu"}static getIsFloatRead(){const e=new this("function kernelFunction() {\n return 1;\n }",{context:this.testContext,canvas:this.testCanvas,validate:!1,output:[1],precision:"single",returnType:"Number",tactic:"speed"});e.build(),e.run();const t=e.renderOutput();return e.destroy(!0),1===t[0]}static getIsIntegerDivisionAccurate(){const e=new this(function(e,t){return e[this.thread.x]/t[this.thread.x]}.toString(),{context:this.testContext,canvas:this.testCanvas,validate:!1,output:[2],returnType:"Number",precision:"unsigned",tactic:"speed"}),t=[[6,6030401],[3,3991]];e.build.apply(e,t),e.run.apply(e,t);const r=e.renderOutput();return e.destroy(!0),2===r[0]&&1511===r[1]}static get testCanvas(){throw new Error(`"testCanvas" not defined on ${this.name}`)}static get testContext(){throw new Error(`"testContext" not defined on ${this.name}`)}static get features(){throw new Error(`"features" not defined on ${this.name}`)}static setupFeatureChecks(){throw new Error(`"setupFeatureChecks" not defined on ${this.name}`)}setFixIntegerDivisionAccuracy(e){return this.fixIntegerDivisionAccuracy=e,this}setPrecision(e){return this.precision=e,this}setFloatTextures(e){return s.warnDeprecated("method","setFloatTextures","setOptimizeFloatMemory"),this.floatTextures=e,this}static nativeFunctionArguments(e){const t=[],r=[],n=[],i=/^[a-zA-Z_]/,s=/[a-zA-Z_0-9]/;let a=0,o=null,u=null;for(;a<e.length;){const l=e[a],h=e[a+1],c=n.length>0?n[n.length-1]:null;if("FUNCTION_ARGUMENTS"!==c||"/"!==l||"*"!==h)if("MULTI_LINE_COMMENT"!==c||"*"!==l||"/"!==h)if("FUNCTION_ARGUMENTS"!==c||"/"!==l||"/"!==h)if("COMMENT"!==c||"\n"!==l)if(null!==c||"("!==l){if("FUNCTION_ARGUMENTS"===c){if(")"===l){n.pop();break}if("f"===l&&"l"===h&&"o"===e[a+2]&&"a"===e[a+3]&&"t"===e[a+4]&&" "===e[a+5]){n.push("DECLARE_VARIABLE"),u="float",o="",a+=6;continue}if("i"===l&&"n"===h&&"t"===e[a+2]&&" "===e[a+3]){n.push("DECLARE_VARIABLE"),u="int",o="",a+=4;continue}if("v"===l&&"e"===h&&"c"===e[a+2]&&"2"===e[a+3]&&" "===e[a+4]){n.push("DECLARE_VARIABLE"),u="vec2",o="",a+=5;continue}if("v"===l&&"e"===h&&"c"===e[a+2]&&"3"===e[a+3]&&" "===e[a+4]){n.push("DECLARE_VARIABLE"),u="vec3",o="",a+=5;continue}if("v"===l&&"e"===h&&"c"===e[a+2]&&"4"===e[a+3]&&" "===e[a+4]){n.push("DECLARE_VARIABLE"),u="vec4",o="",a+=5;continue}}else if("DECLARE_VARIABLE"===c){if(""===o){if(" "===l){a++;continue}if(!i.test(l))throw new Error("variable name is not expected string")}o+=l,s.test(h)||(n.pop(),r.push(o),t.push(w[u]))}a++}else n.push("FUNCTION_ARGUMENTS"),a++;else n.pop(),a++;else n.push("COMMENT"),a+=2;else n.pop(),a+=2;else n.push("MULTI_LINE_COMMENT"),a+=2}if(n.length>0)throw new Error("GLSL function was not parsable");return{argumentNames:r,argumentTypes:t}}static nativeFunctionReturnType(e){return w[e.match(/int|float|vec[2-4]/)[0]]}static combineKernels(e,t){e.apply(null,arguments);const{texSize:r,context:n,threadDim:i}=t.texSize;let a;if("single"===t.precision){const e=r[0],t=Math.ceil(r[1]/4);a=new Float32Array(e*t*4*4),n.readPixels(0,0,e,4*t,n.RGBA,n.FLOAT,a)}else{const e=new Uint8Array(r[0]*r[1]*4);n.readPixels(0,0,r[0],r[1],n.RGBA,n.UNSIGNED_BYTE,e),a=new Float32Array(e.buffer)}return a=a.subarray(0,i[0]*i[1]*i[2]),1===t.output.length?a:2===t.output.length?s.splitArray(a,t.output[0]):3===t.output.length?s.splitArray(a,t.output[0]*t.output[1]).map(function(e){return s.splitArray(e,t.output[0])}):void 0}constructor(e,t){super(e,t),this.transferValues=null,this.formatValues=null,this.TextureConstructor=null,this.renderOutput=null,this.renderRawOutput=null,this.texSize=null,this.translatedSource=null,this.renderStrategy=null,this.compiledFragmentShader=null,this.compiledVertexShader=null}checkTextureSize(){const{features:e}=this.constructor;if(this.texSize[0]>e.maxTextureSize||this.texSize[1]>e.maxTextureSize)throw new Error(`Texture size [${this.texSize[0]},${this.texSize[1]}] generated by kernel is larger than supported size [${e.maxTextureSize},${e.maxTextureSize}]`)}translateSource(){throw new Error(`"translateSource" not defined on ${this.constructor.name}`)}pickRenderStrategy(e){if(this.graphical)return this.renderRawOutput=this.readPackedPixelsToUint8Array,this.transferValues=(e=>e),this.TextureConstructor=E,null;if("unsigned"===this.precision)if(this.renderRawOutput=this.readPackedPixelsToUint8Array,this.transferValues=this.readPackedPixelsToFloat32Array,this.pipeline)switch(this.renderOutput=this.renderTexture,null!==this.subKernels&&(this.renderKernels=this.renderKernelsToTextures),this.returnType){case"LiteralInteger":case"Float":case"Number":case"Integer":return this.output[2]>0?(this.TextureConstructor=S,this.renderStrategy=_.PackedPixelTo3DFloat,null):this.output[1]>0?(this.TextureConstructor=v,this.renderStrategy=_.PackedPixelTo2DFloat,null):(this.TextureConstructor=A,this.renderStrategy=_.PackedPixelToFloat,null);case"Array(2)":case"Array(3)":case"Array(4)":return this.requestFallback(e)}else switch(null!==this.subKernels&&(this.renderKernels=this.renderKernelsToArrays),this.returnType){case"LiteralInteger":case"Float":case"Number":case"Integer":return this.renderOutput=this.renderValues,this.output[2]>0?(this.TextureConstructor=S,this.renderStrategy=_.PackedPixelTo3DFloat,this.formatValues=s.erect3DPackedFloat,null):this.output[1]>0?(this.TextureConstructor=v,this.renderStrategy=_.PackedPixelTo2DFloat,this.formatValues=s.erect2DPackedFloat,null):(this.TextureConstructor=A,this.renderStrategy=_.PackedPixelToFloat,this.formatValues=s.erectPackedFloat,null);case"Array(2)":case"Array(3)":case"Array(4)":return this.requestFallback(e)}else{if("single"!==this.precision)throw new Error(`unhandled precision of "${this.precision}"`);if(this.renderRawOutput=this.readFloatPixelsToFloat32Array,this.transferValues=this.readFloatPixelsToFloat32Array,this.pipeline)switch(this.renderStrategy=_.FloatTexture,this.renderOutput=this.renderTexture,null!==this.subKernels&&(this.renderKernels=this.renderKernelsToTextures),this.returnType){case"LiteralInteger":case"Float":case"Number":case"Integer":return this.optimizeFloatMemory?this.output[2]>0?(this.TextureConstructor=b,null):this.output[1]>0?(this.TextureConstructor=T,null):(this.TextureConstructor=y,null):this.output[2]>0?(this.TextureConstructor=x,null):this.output[1]>0?(this.TextureConstructor=f,null):(this.TextureConstructor=g,null);case"Array(2)":return this.output[2]>0?(this.TextureConstructor=u,null):this.output[1]>0?(this.TextureConstructor=o,null):(this.TextureConstructor=a,null);case"Array(3)":return this.output[2]>0?(this.TextureConstructor=c,null):this.output[1]>0?(this.TextureConstructor=h,null):(this.TextureConstructor=l,null);case"Array(4)":return this.output[2]>0?(this.TextureConstructor=m,null):this.output[1]>0?(this.TextureConstructor=d,null):(this.TextureConstructor=p,null)}if(this.renderOutput=this.renderValues,null!==this.subKernels&&(this.renderKernels=this.renderKernelsToArrays),this.optimizeFloatMemory)switch(this.returnType){case"LiteralInteger":case"Float":case"Number":case"Integer":return this.output[2]>0?(this.TextureConstructor=b,this.renderStrategy=_.MemoryOptimizedFloatPixelToMemoryOptimized3DFloat,this.formatValues=s.erectMemoryOptimized3DFloat,null):this.output[1]>0?(this.TextureConstructor=T,this.renderStrategy=_.MemoryOptimizedFloatPixelToMemoryOptimized2DFloat,this.formatValues=s.erectMemoryOptimized2DFloat,null):(this.TextureConstructor=y,this.renderStrategy=_.MemoryOptimizedFloatPixelToMemoryOptimizedFloat,this.formatValues=s.erectMemoryOptimizedFloat,null);case"Array(2)":return this.output[2]>0?(this.TextureConstructor=u,this.renderStrategy=_.FloatPixelTo3DArray2,this.formatValues=s.erect3DArray2,null):this.output[1]>0?(this.TextureConstructor=o,this.renderStrategy=_.FloatPixelTo2DArray2,this.formatValues=s.erect2DArray2,null):(this.TextureConstructor=a,this.renderStrategy=_.FloatPixelToArray2,this.formatValues=s.erectArray2,null);case"Array(3)":return this.output[2]>0?(this.TextureConstructor=c,this.renderStrategy=_.FloatPixelTo3DArray3,this.formatValues=s.erect3DArray3,null):this.output[1]>0?(this.TextureConstructor=h,this.renderStrategy=_.FloatPixelTo2DArray3,this.formatValues=s.erect2DArray3,null):(this.TextureConstructor=l,this.renderStrategy=_.FloatPixelToArray3,this.formatValues=s.erectArray3,null);case"Array(4)":return this.output[2]>0?(this.TextureConstructor=m,this.renderStrategy=_.FloatPixelTo3DArray4,this.formatValues=s.erect3DArray4,null):this.output[1]>0?(this.TextureConstructor=d,this.renderStrategy=_.FloatPixelTo2DArray4,this.formatValues=s.erect2DArray4,null):(this.TextureConstructor=p,this.renderStrategy=_.FloatPixelToArray4,this.formatValues=s.erectArray4,null)}else switch(this.returnType){case"LiteralInteger":case"Float":case"Number":case"Integer":return this.output[2]>0?(this.TextureConstructor=x,this.renderStrategy=_.FloatPixelTo3DFloat,this.formatValues=s.erect3DFloat,null):this.output[1]>0?(this.TextureConstructor=f,this.renderStrategy=_.FloatPixelTo2DFloat,this.formatValues=s.erect2DFloat,null):(this.TextureConstructor=g,this.renderStrategy=_.FloatPixelToFloat,this.formatValues=s.erectFloat,null);case"Array(2)":return this.output[2]>0?(this.TextureConstructor=u,this.renderStrategy=_.FloatPixelTo3DArray2,this.formatValues=s.erect3DArray2,null):this.output[1]>0?(this.TextureConstructor=o,this.renderStrategy=_.FloatPixelTo2DArray2,this.formatValues=s.erect2DArray2,null):(this.TextureConstructor=a,this.renderStrategy=_.FloatPixelToArray2,this.formatValues=s.erectArray2,null);case"Array(3)":return this.output[2]>0?(this.TextureConstructor=c,this.renderStrategy=_.FloatPixelTo3DArray3,this.formatValues=s.erect3DArray3,null):this.output[1]>0?(this.TextureConstructor=h,this.renderStrategy=_.FloatPixelTo2DArray3,this.formatValues=s.erect2DArray3,null):(this.TextureConstructor=l,this.renderStrategy=_.FloatPixelToArray3,this.formatValues=s.erectArray3,null);case"Array(4)":return this.output[2]>0?(this.TextureConstructor=m,this.renderStrategy=_.FloatPixelTo3DArray4,this.formatValues=s.erect3DArray4,null):this.output[1]>0?(this.TextureConstructor=d,this.renderStrategy=_.FloatPixelTo2DArray4,this.formatValues=s.erect2DArray4,null):(this.TextureConstructor=p,this.renderStrategy=_.FloatPixelToArray4,this.formatValues=s.erectArray4,null)}}throw new Error(`unhandled return type "${this.returnType}"`)}getKernelString(){throw new Error("abstract method call")}getMainResultTexture(){switch(this.returnType){case"LiteralInteger":case"Float":case"Integer":case"Number":return this.getMainResultNumberTexture();case"Array(2)":return this.getMainResultArray2Texture();case"Array(3)":return this.getMainResultArray3Texture();case"Array(4)":return this.getMainResultArray4Texture();default:throw new Error(`unhandled returnType type ${this.returnType}`)}}getMainResultKernelNumberTexture(){throw new Error("abstract method call")}getMainResultSubKernelNumberTexture(){throw new Error("abstract method call")}getMainResultKernelArray2Texture(){throw new Error("abstract method call")}getMainResultSubKernelArray2Texture(){throw new Error("abstract method call")}getMainResultKernelArray3Texture(){throw new Error("abstract method call")}getMainResultSubKernelArray3Texture(){throw new Error("abstract method call")}getMainResultKernelArray4Texture(){throw new Error("abstract method call")}getMainResultSubKernelArray4Texture(){throw new Error("abstract method call")}getMainResultGraphical(){throw new Error("abstract method call")}getMainResultMemoryOptimizedFloats(){throw new Error("abstract method call")}getMainResultPackedPixels(){throw new Error("abstract method call")}getMainResultString(){return this.graphical?this.getMainResultGraphical():"single"===this.precision?this.optimizeFloatMemory?this.getMainResultMemoryOptimizedFloats():this.getMainResultTexture():this.getMainResultPackedPixels()}getMainResultNumberTexture(){return s.linesToString(this.getMainResultKernelNumberTexture())+s.linesToString(this.getMainResultSubKernelNumberTexture())}getMainResultArray2Texture(){return s.linesToString(this.getMainResultKernelArray2Texture())+s.linesToString(this.getMainResultSubKernelArray2Texture())}getMainResultArray3Texture(){return s.linesToString(this.getMainResultKernelArray3Texture())+s.linesToString(this.getMainResultSubKernelArray3Texture())}getMainResultArray4Texture(){return s.linesToString(this.getMainResultKernelArray4Texture())+s.linesToString(this.getMainResultSubKernelArray4Texture())}getFloatTacticDeclaration(){switch(this.tactic){case"speed":return"precision lowp float;\n";case"performance":return"precision highp float;\n";case"balanced":default:return"precision mediump float;\n"}}getIntTacticDeclaration(){switch(this.tactic){case"speed":return"precision lowp int;\n";case"performance":return"precision highp int;\n";case"balanced":default:return"precision mediump int;\n"}}getSampler2DTacticDeclaration(){switch(this.tactic){case"speed":return"precision lowp sampler2D;\n";case"performance":return"precision highp sampler2D;\n";case"balanced":default:return"precision mediump sampler2D;\n"}}getSampler2DArrayTacticDeclaration(){switch(this.tactic){case"speed":return"precision lowp sampler2DArray;\n";case"performance":return"precision highp sampler2DArray;\n";case"balanced":default:return"precision mediump sampler2DArray;\n"}}renderTexture(){return new this.TextureConstructor({texture:this.outputTexture,size:this.texSize,dimensions:this.threadDim,output:this.output,context:this.context})}readPackedPixelsToUint8Array(){if("unsigned"!==this.precision)throw new Error('Requires this.precision to be "unsigned"');const{texSize:e,context:t}=this,r=new Uint8Array(e[0]*e[1]*4);return t.readPixels(0,0,e[0],e[1],t.RGBA,t.UNSIGNED_BYTE,r),r}readPackedPixelsToFloat32Array(){return new Float32Array(this.readPackedPixelsToUint8Array().buffer)}readFloatPixelsToFloat32Array(){if("single"!==this.precision)throw new Error('Requires this.precision to be "single"');const{texSize:e,context:t}=this,r=e[0],n=e[1],i=new Float32Array(r*n*4);return t.readPixels(0,0,r,n,t.RGBA,t.FLOAT,i),i}readMemoryOptimizedFloatPixelsToFloat32Array(){if("single"!==this.precision)throw new Error('Requires this.precision to be "single"');const{texSize:e,context:t}=this,r=e[0],n=e[1],i=new Float32Array(r*n*4);return t.readPixels(0,0,r,n,t.RGBA,t.FLOAT,i),i}getPixels(e){const{context:t,output:r}=this,[n,i]=r,a=new Uint8Array(n*i*4);return t.readPixels(0,0,n,i,t.RGBA,t.UNSIGNED_BYTE,a),new Uint8ClampedArray((e?a:s.flipPixels(a,n,i)).buffer)}renderKernelsToArrays(){const e={result:this.renderOutput()};for(let t=0;t<this.subKernels.length;t++)e[this.subKernels[t].property]=new this.TextureConstructor({texture:this.subKernelOutputTextures[t],size:this.texSize,dimensions:this.threadDim,output:this.output,context:this.context}).toArray();return e}renderKernelsToTextures(){const e={result:this.renderOutput()};for(let t=0;t<this.subKernels.length;t++)e[this.subKernels[t].property]=new this.TextureConstructor({texture:this.subKernelOutputTextures[t],size:this.texSize,dimensions:this.threadDim,output:this.output,context:this.context});return e}setOutput(e){if(super.setOutput(e),this.program){this.threadDim=[this.output[0],this.output[1]||1,this.output[2]||1],this.texSize=s.getKernelTextureSize({optimizeFloatMemory:this.optimizeFloatMemory,precision:this.precision},this.output);const{context:e}=this;e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),this.updateMaxTexSize(),this.framebuffer.width=this.texSize[0],this.framebuffer.height=this.texSize[1],this.context.viewport(0,0,this.maxTexSize[0],this.maxTexSize[1]),this.canvas.width=this.maxTexSize[0],this.canvas.height=this.maxTexSize[1],this._setupOutputTexture(),this.subKernels&&this.subKernels.length>0&&this._setupSubOutputTextures()}return this}renderValues(){return this.formatValues(this.transferValues(),this.output[0],this.output[1],this.output[2])}},renderStrategy:_}},{"../../texture":111,"../../utils":112,"../kernel":35,"./texture/array-2-float":16,"./texture/array-2-float-2d":14,"./texture/array-2-float-3d":15,"./texture/array-3-float":19,"./texture/array-3-float-2d":17,"./texture/array-3-float-3d":18,"./texture/array-4-float":22,"./texture/array-4-float-2d":20,"./texture/array-4-float-3d":21,"./texture/float":25,"./texture/float-2d":23,"./texture/float-3d":24,"./texture/graphical":26,"./texture/memory-optimized":29,"./texture/memory-optimized-2d":27,"./texture/memory-optimized-3d":28,"./texture/unsigned":32,"./texture/unsigned-2d":30,"./texture/unsigned-3d":31}],14:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray2Float2D:class extends i{constructor(e){super(e),this.type="ArrayTexture(2)"}toArray(){return n.erect2DArray2(this.renderValues(),this.output[0],this.output[1])}}}},{"../../../utils":112,"./float":25}],15:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray2Float3D:class extends i{constructor(e){super(e),this.type="ArrayTexture(2)"}toArray(){return n.erect3DArray2(this.renderValues(),this.output[0],this.output[1],this.output[2])}}}},{"../../../utils":112,"./float":25}],16:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray2Float:class extends i{constructor(e){super(e),this.type="ArrayTexture(2)"}toArray(){return n.erectArray2(this.renderValues(),this.output[0],this.output[1])}}}},{"../../../utils":112,"./float":25}],17:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray3Float2D:class extends i{constructor(e){super(e),this.type="ArrayTexture(3)"}toArray(){return n.erect2DArray3(this.renderValues(),this.output[0],this.output[1])}}}},{"../../../utils":112,"./float":25}],18:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray3Float3D:class extends i{constructor(e){super(e),this.type="ArrayTexture(3)"}toArray(){return n.erect3DArray3(this.renderValues(),this.output[0],this.output[1],this.output[2])}}}},{"../../../utils":112,"./float":25}],19:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray3Float:class extends i{constructor(e){super(e),this.type="ArrayTexture(3)"}toArray(){return n.erectArray3(this.renderValues(),this.output[0])}}}},{"../../../utils":112,"./float":25}],20:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray4Float2D:class extends i{constructor(e){super(e),this.type="ArrayTexture(4)"}toArray(){return n.erect2DArray4(this.renderValues(),this.output[0],this.output[1])}}}},{"../../../utils":112,"./float":25}],21:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray4Float3D:class extends i{constructor(e){super(e),this.type="ArrayTexture(4)"}toArray(){return n.erect3DArray4(this.renderValues(),this.output[0],this.output[1],this.output[2])}}}},{"../../../utils":112,"./float":25}],22:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureArray4Float:class extends i{constructor(e){super(e),this.type="ArrayTexture(4)"}toArray(){return n.erectArray4(this.renderValues(),this.output[0])}}}},{"../../../utils":112,"./float":25}],23:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureFloat2D:class extends i{constructor(e){super(e),this.type="ArrayTexture(1)"}toArray(){return n.erect2DFloat(this.renderValues(),this.output[0],this.output[1])}}}},{"../../../utils":112,"./float":25}],24:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureFloat3D:class extends i{constructor(e){super(e),this.type="ArrayTexture(1)"}toArray(){return n.erect3DFloat(this.renderValues(),this.output[0],this.output[1],this.output[2])}}}},{"../../../utils":112,"./float":25}],25:[function(e,t,r){const{utils:n}=e("../../../utils"),{Texture:i}=e("../../../texture");t.exports={GLTextureFloat:class extends i{constructor(e){super(e),this.type="ArrayTexture(1)"}renderRawOutput(){const{context:e}=this,t=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,t),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.texture,0);const r=new Float32Array(this.size[0]*this.size[1]*4);return e.readPixels(0,0,this.size[0],this.size[1],e.RGBA,e.FLOAT,r),r}renderValues(){return this.renderRawOutput()}toArray(){return n.erectFloat(this.renderValues(),this.output[0])}}}},{"../../../texture":111,"../../../utils":112}],26:[function(e,t,r){const{GLTextureUnsigned:n}=e("./unsigned");t.exports={GLTextureGraphical:class extends n{constructor(e){super(e),this.type="ArrayTexture(4)"}toArray(){return this.renderValues()}}}},{"./unsigned":32}],27:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureMemoryOptimized2D:class extends i{constructor(e){super(e),this.type="MemoryOptimizedNumberTexture"}toArray(){return n.erectMemoryOptimized2DFloat(this.renderValues(),this.output[0],this.output[1])}}}},{"../../../utils":112,"./float":25}],28:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureMemoryOptimized3D:class extends i{constructor(e){super(e),this.type="MemoryOptimizedNumberTexture"}toArray(){return n.erectMemoryOptimized3DFloat(this.renderValues(),this.output[0],this.output[1],this.output[2])}}}},{"../../../utils":112,"./float":25}],29:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureFloat:i}=e("./float");t.exports={GLTextureMemoryOptimized:class extends i{constructor(e){super(e),this.type="MemoryOptimizedNumberTexture"}toArray(){return n.erectMemoryOptimizedFloat(this.renderValues(),this.output[0])}}}},{"../../../utils":112,"./float":25}],30:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureUnsigned:i}=e("./unsigned");t.exports={GLTextureUnsigned2D:class extends i{constructor(e){super(e),this.type="NumberTexture"}toArray(){return n.erect2DPackedFloat(this.renderValues(),this.output[0],this.output[1])}}}},{"../../../utils":112,"./unsigned":32}],31:[function(e,t,r){const{utils:n}=e("../../../utils"),{GLTextureUnsigned:i}=e("./unsigned");t.exports={GLTextureUnsigned3D:class extends i{constructor(e){super(e),this.type="NumberTexture"}toArray(){return n.erect3DPackedFloat(this.renderValues(),this.output[0],this.output[1],this.output[2])}}}},{"../../../utils":112,"./unsigned":32}],32:[function(e,t,r){const{utils:n}=e("../../../utils"),{Texture:i}=e("../../../texture");t.exports={GLTextureUnsigned:class extends i{constructor(e){super(e),this.type="NumberTexture"}renderRawOutput(){const{context:e}=this,t=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,t),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.texture,0);const r=new Uint8Array(this.size[0]*this.size[1]*4);return e.readPixels(0,0,this.size[0],this.size[1],e.RGBA,e.UNSIGNED_BYTE,r),r}renderValues(){return new Float32Array(this.renderRawOutput().buffer)}toArray(){return n.erectPackedFloat(this.renderValues(),this.output[0])}}}},{"../../../texture":111,"../../../utils":112}],33:[function(e,t,r){const n=e("gl"),{WebGLKernel:i}=e("../web-gl/kernel"),{glKernelString:s}=e("../gl/kernel-string");let a=null,o=null,u=null,l=null,h=null;t.exports={HeadlessGLKernel:class extends i{static get isSupported(){return null!==a?a:(this.setupFeatureChecks(),a=null!==u)}static setupFeatureChecks(){if(o=null,l=null,"function"==typeof n)try{if(!(u=n(2,2,{preserveDrawingBuffer:!0}))||!u.getExtension)return;l={STACKGL_resize_drawingbuffer:u.getExtension("STACKGL_resize_drawingbuffer"),STACKGL_destroy_context:u.getExtension("STACKGL_destroy_context"),OES_texture_float:u.getExtension("OES_texture_float"),OES_texture_float_linear:u.getExtension("OES_texture_float_linear"),OES_element_index_uint:u.getExtension("OES_element_index_uint"),WEBGL_draw_buffers:u.getExtension("WEBGL_draw_buffers")},h=this.getFeatures()}catch(e){console.warn(e)}}static isContextMatch(e){try{return"ANGLE"===e.getParameter(e.RENDERER)}catch(e){return!1}}static getFeatures(){const e=this.getIsDrawBuffers();return Object.freeze({isFloatRead:this.getIsFloatRead(),isIntegerDivisionAccurate:this.getIsIntegerDivisionAccurate(),isTextureFloat:this.getIsTextureFloat(),isDrawBuffers:e,kernelMap:e,channelCount:this.getChannelCount(),maxTextureSize:this.getMaxTextureSize()})}static getIsTextureFloat(){return Boolean(l.OES_texture_float)}static getIsDrawBuffers(){return Boolean(l.WEBGL_draw_buffers)}static getChannelCount(){return l.WEBGL_draw_buffers?u.getParameter(l.WEBGL_draw_buffers.MAX_DRAW_BUFFERS_WEBGL):1}static getMaxTextureSize(){return u.getParameter(u.MAX_TEXTURE_SIZE)}static get testCanvas(){return o}static get testContext(){return u}static get features(){return h}initCanvas(){return{}}initContext(){return n(2,2,{preserveDrawingBuffer:!0})}initExtensions(){this.extensions={STACKGL_resize_drawingbuffer:this.context.getExtension("STACKGL_resize_drawingbuffer"),STACKGL_destroy_context:this.context.getExtension("STACKGL_destroy_context"),OES_texture_float:this.context.getExtension("OES_texture_float"),OES_texture_float_linear:this.context.getExtension("OES_texture_float_linear"),OES_element_index_uint:this.context.getExtension("OES_element_index_uint"),WEBGL_draw_buffers:this.context.getExtension("WEBGL_draw_buffers")}}build(){super.build.apply(this,arguments),this.fallbackRequested||this.extensions.STACKGL_resize_drawingbuffer.resize(this.maxTexSize[0],this.maxTexSize[1])}destroyExtensions(){this.extensions.STACKGL_resize_drawingbuffer=null,this.extensions.STACKGL_destroy_context=null,this.extensions.OES_texture_float=null,this.extensions.OES_texture_float_linear=null,this.extensions.OES_element_index_uint=null,this.extensions.WEBGL_draw_buffers=null}static destroyContext(e){const t=e.getExtension("STACKGL_destroy_context");t&&t.destroy&&t.destroy()}toString(){return s(this.constructor,arguments,this,"const gl = context || require('gl')(1, 1);\n"," if (!context) { gl.getExtension('STACKGL_destroy_context').destroy(); }\n")}setOutput(e){super.setOutput(e),this.graphical&&this.extensions.STACKGL_resize_drawingbuffer&&this.extensions.STACKGL_resize_drawingbuffer.resize(this.maxTexSize[0],this.maxTexSize[1])}}}},{"../gl/kernel-string":12,"../web-gl/kernel":68,gl:2}],34:[function(e,t,r){t.exports={KernelValue:class{constructor(e,t){const{name:r,kernel:n,context:i,checkContext:s,onRequestContextHandle:a,onUpdateValueMismatch:o,origin:u,strictIntegers:l,type:h,tactic:c}=t;if(!r)throw new Error("name not set");if(!h)throw new Error("type not set");if(!u)throw new Error("origin not set");if(!c)throw new Error("tactic not set");if("user"!==u&&"constants"!==u)throw new Error(`origin must be "user" or "constants" value is "${u}"`);if(!a)throw new Error("onRequestContextHandle is not set");this.name=r,this.origin=u,this.tactic=c,this.id=`${this.origin}_${r}`,this.varName="constants"===u?`constants.${r}`:r,this.kernel=n,this.strictIntegers=l,this.type=e.type||h,this.size=e.size||null,this.index=null,this.context=i,this.checkContext=null==s||s,this.contextHandle=null,this.onRequestContextHandle=a,this.onUpdateValueMismatch=o,this.forceUploadEachRun=null}getSource(){throw new Error(`"getSource" not defined on ${this.constructor.name}`)}updateValue(e){throw new Error(`"updateValue" not defined on ${this.constructor.name}`)}}}},{}],35:[function(e,t,r){const{utils:n}=e("../utils"),{Input:i}=e("../input");t.exports={Kernel:class{static get isSupported(){throw new Error(`"isSupported" not implemented on ${this.name}`)}static isContextMatch(e){throw new Error(`"isContextMatch" not implemented on ${this.name}`)}static getFeatures(){throw new Error(`"getFeatures" not implemented on ${this.name}`)}static destroyContext(e){throw new Error(`"destroyContext" called on ${this.name}`)}static nativeFunctionArguments(){throw new Error(`"nativeFunctionArguments" called on ${this.name}`)}static nativeFunctionReturnType(){throw new Error(`"nativeFunctionReturnType" called on ${this.name}`)}static combineKernels(){throw new Error(`"combineKernels" called on ${this.name}`)}constructor(e,t){if("object"!=typeof e){if("string"!=typeof e)throw new Error("source not a string");if(!n.isFunctionString(e))throw new Error("source not a function string")}this.useLegacyEncoder=!1,this.fallbackRequested=!1,this.onRequestFallback=null,this.argumentNames="string"==typeof e?n.getArgumentNamesFromString(e):null,this.argumentTypes=null,this.argumentSizes=null,this.argumentBitRatios=null,this.kernelArguments=null,this.kernelConstants=null,this.forceUploadKernelConstants=null,this.source=e,this.output=null,this.debug=!1,this.graphical=!1,this.loopMaxIterations=0,this.constants=null,this.constantTypes=null,this.constantBitRatios=null,this.dynamicArguments=!1,this.dynamicOutput=!1,this.canvas=null,this.context=null,this.checkContext=null,this.gpu=null,this.functions=null,this.nativeFunctions=null,this.injectedNative=null,this.subKernels=null,this.validate=!0,this.immutable=!1,this.pipeline=!1,this.precision=null,this.tactic="balanced",this.plugins=null,this.returnType=null,this.leadingReturnStatement=null,this.followingReturnStatement=null,this.optimizeFloatMemory=null,this.strictIntegers=!1,this.fixIntegerDivisionAccuracy=null,this.warnVarUsage=!0}mergeSettings(e){for(let t in e)if(e.hasOwnProperty(t)&&this.hasOwnProperty(t)){switch(t){case"output":if(!Array.isArray(e.output)){this.setOutput(e.output);continue}break;case"functions":if("function"==typeof e.functions[0]){this.functions=e.functions.map(e=>n.functionToIFunction(e));continue}break;case"graphical":e[t]&&!e.hasOwnProperty("precision")&&(this.precision="unsigned"),this[t]=e[t];continue}this[t]=e[t]}this.canvas||(this.canvas=this.initCanvas()),this.context||(this.context=this.initContext()),this.plugins||(this.plugins=this.initPlugins(e))}build(){throw new Error(`"build" not defined on ${this.constructor.name}`)}run(){throw new Error(`"run" not defined on ${this.constructor.name}`)}initCanvas(){throw new Error(`"initCanvas" not defined on ${this.constructor.name}`)}initContext(){throw new Error(`"initContext" not defined on ${this.constructor.name}`)}initPlugins(e){throw new Error(`"initPlugins" not defined on ${this.constructor.name}`)}setupArguments(e){if(this.kernelArguments=[],this.argumentTypes)for(let e=0;e<this.argumentTypes.length;e++)this.kernelArguments.push({type:this.argumentTypes[e]});else if(!this.argumentTypes){this.argumentTypes=[];for(let t=0;t<e.length;t++){const r=n.getVariableType(e[t],this.strictIntegers),i="Integer"===r?"Number":r;this.argumentTypes.push(i),this.kernelArguments.push({type:i})}}this.argumentSizes=new Array(e.length),this.argumentBitRatios=new Int32Array(e.length);for(let t=0;t<e.length;t++){const r=e[t];this.argumentSizes[t]=r.constructor===i?r.size:null,this.argumentBitRatios[t]=this.getBitRatio(r)}if(this.argumentNames.length!==e.length)throw new Error("arguments are miss-aligned")}setupConstants(){this.kernelConstants=[];let e=null===this.constantTypes;if(e&&(this.constantTypes={}),this.constantBitRatios={},this.constants)for(let t in this.constants){if(e){const e=n.getVariableType(this.constants[t],this.strictIntegers);this.constantTypes[t]=e,this.kernelConstants.push({name:t,type:e})}else this.kernelConstants.push({name:t,type:this.constantTypes[t]});this.constantBitRatios[t]=this.getBitRatio(this.constants[t])}}setOptimizeFloatMemory(e){return this.optimizeFloatMemory=e,this}setOutput(e){return e.hasOwnProperty("x")?e.hasOwnProperty("y")?e.hasOwnProperty("z")?this.output=[e.x,e.y,e.z]:this.output=[e.x,e.y]:this.output=[e.x]:this.output=e,this}setDebug(e){return this.debug=e,this}setGraphical(e){return this.graphical=e,this.precision="unsigned",this}setLoopMaxIterations(e){return this.loopMaxIterations=e,this}setConstants(e){return this.constants=e,this}setConstantTypes(e){return this.constantTypes=e,this}setFunctions(e){return"function"==typeof e[0]?this.functions=e.map(e=>n.functionToIFunction(e)):this.functions=e,this}setNativeFunctions(e){return this.nativeFunctions=e,this}setInjectedNative(e){return this.injectedNative=e,this}setPipeline(e){return this.pipeline=e,this}setPrecision(e){return this.precision=e,this}setOutputToTexture(e){return n.warnDeprecated("method","setOutputToTexture","setPipeline"),this.pipeline=e,this}setImmutable(e){return this.immutable=e,this}setCanvas(e){return this.canvas=e,this}setStrictIntegers(e){return this.strictIntegers=e,this}setDynamicOutput(e){return this.dynamicOutput=e,this}setHardcodeConstants(e){return n.warnDeprecated("method","setHardcodeConstants"),this.setDynamicOutput(e),this.setDynamicArguments(e),this}setDynamicArguments(e){return this.dynamicArguments=e,this}setUseLegacyEncoder(e){return this.useLegacyEncoder=e,this}setWarnVarUsage(e){return this.warnVarUsage=e,this}getCanvas(){return n.warnDeprecated("method","getCanvas"),this.canvas}getWebGl(){return n.warnDeprecated("method","getWebGl"),this.context}setContext(e){return this.context=e,this}setArgumentTypes(e){if(Array.isArray(e))this.argumentTypes=e;else{this.argumentTypes=[];for(const t in e){const r=this.argumentNames.indexOf(t);if(-1===r)throw new Error(`unable to find argument ${t}`);this.argumentTypes[r]=e[t]}}return this}setTactic(e){return this.tactic=e,this}requestFallback(e){if(!this.onRequestFallback)throw new Error(`"onRequestFallback" not defined on ${this.constructor.name}`);return this.fallbackRequested=!0,this.onRequestFallback(e)}validateSettings(){throw new Error(`"validateSettings" not defined on ${this.constructor.name}`)}addSubKernel(e){if(null===this.subKernels&&(this.subKernels=[]),!e.source)throw new Error('subKernel missing "source" property');if(!e.property&&isNaN(e.property))throw new Error('subKernel missing "property" property');if(!e.name)throw new Error('subKernel missing "name" property');return this.subKernels.push(e),this}destroy(e){throw new Error(`"destroy" called on ${this.constructor.name}`)}getBitRatio(e){if("single"===this.precision)return 4;if(Array.isArray(e[0]))return this.getBitRatio(e[0]);if(e.constructor===i)return this.getBitRatio(e.value);switch(e.constructor){case Uint8ClampedArray:case Uint8Array:case Int8Array:return 1;case Uint16Array:case Int16Array:return 2;case Float32Array:case Int32Array:default:return 4}}getPixels(){throw new Error(`"getPixels" called on ${this.constructor.name}`)}checkOutput(){if(!this.output||!n.isArray(this.output))throw new Error("kernel.output not an array");if(this.output.length<1)throw new Error("kernel.output is empty, needs at least 1 value");for(let e=0;e<this.output.length;e++)if(isNaN(this.output[e])||this.output[e]<1)throw new Error(`${this.constructor.name}.output[${e}] incorrectly defined as \`${this.output[e]}\`, needs to be numeric, and greater than 0`)}toJSON(){return{settings:{output:this.output,threadDim:this.threadDim,pipeline:this.pipeline,argumentNames:this.argumentNames,argumentsTypes:this.argumentTypes,constants:this.constants,pluginNames:this.plugins?this.plugins.map(e=>e.name):null,returnType:this.returnType}}}}}},{"../input":108,"../utils":112}],36:[function(e,t,r){t.exports={fragmentShader:"__HEADER__;\n__FLOAT_TACTIC_DECLARATION__;\n__INT_TACTIC_DECLARATION__;\n__SAMPLER_2D_TACTIC_DECLARATION__;\n\nconst int LOOP_MAX = __LOOP_MAX__;\n\n__PLUGINS__;\n__CONSTANTS__;\n\nvarying vec2 vTexCoord;\n\nvec4 round(vec4 x) {\n return floor(x + 0.5);\n}\n\nfloat round(float x) {\n return floor(x + 0.5);\n}\n\nconst int BIT_COUNT = 32;\nint modi(int x, int y) {\n return x - y * (x / y);\n}\n\nint bitwiseOr(int a, int b) {\n int result = 0;\n int n = 1;\n \n for (int i = 0; i < BIT_COUNT; i++) {\n if ((modi(a, 2) == 1) || (modi(b, 2) == 1)) {\n result += n;\n }\n a = a / 2;\n b = b / 2;\n n = n * 2;\n if(!(a > 0 || b > 0)) {\n break;\n }\n }\n return result;\n}\nint bitwiseXOR(int a, int b) {\n int result = 0;\n int n = 1;\n \n for (int i = 0; i < BIT_COUNT; i++) {\n if ((modi(a, 2) == 1) != (modi(b, 2) == 1)) {\n result += n;\n }\n a = a / 2;\n b = b / 2;\n n = n * 2;\n if(!(a > 0 || b > 0)) {\n break;\n }\n }\n return result;\n}\nint bitwiseAnd(int a, int b) {\n int result = 0;\n int n = 1;\n for (int i = 0; i < BIT_COUNT; i++) {\n if ((modi(a, 2) == 1) && (modi(b, 2) == 1)) {\n result += n;\n }\n a = a / 2;\n b = b / 2;\n n = n * 2;\n if(!(a > 0 && b > 0)) {\n break;\n }\n }\n return result;\n}\nint bitwiseNot(int a) {\n int result = 0;\n int n = 1;\n \n for (int i = 0; i < BIT_COUNT; i++) {\n if (modi(a, 2) == 0) {\n result += n; \n }\n a = a / 2;\n n = n * 2;\n }\n return result;\n}\nint bitwiseZeroFillLeftShift(int n, int shift) {\n int maxBytes = BIT_COUNT;\n for (int i = 0; i < BIT_COUNT; i++) {\n if (maxBytes >= n) {\n break;\n }\n maxBytes *= 2;\n }\n for (int i = 0; i < BIT_COUNT; i++) {\n if (i >= shift) {\n break;\n }\n n *= 2;\n }\n\n int result = 0;\n int byteVal = 1;\n for (int i = 0; i < BIT_COUNT; i++) {\n if (i >= maxBytes) break;\n if (modi(n, 2) > 0) { result += byteVal; }\n n = int(n / 2);\n byteVal *= 2;\n }\n return result;\n}\n\nint bitwiseSignedRightShift(int num, int shifts) {\n return int(floor(float(num) / pow(2.0, float(shifts))));\n}\n\nint bitwiseZeroFillRightShift(int n, int shift) {\n int maxBytes = BIT_COUNT;\n for (int i = 0; i < BIT_COUNT; i++) {\n if (maxBytes >= n) {\n break;\n }\n maxBytes *= 2;\n }\n for (int i = 0; i < BIT_COUNT; i++) {\n if (i >= shift) {\n break;\n }\n n /= 2;\n }\n int result = 0;\n int byteVal = 1;\n for (int i = 0; i < BIT_COUNT; i++) {\n if (i >= maxBytes) break;\n if (modi(n, 2) > 0) { result += byteVal; }\n n = int(n / 2);\n byteVal *= 2;\n }\n return result;\n}\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nfloat integerMod(float x, float y) {\n float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nint integerMod(int x, int y) {\n return x - (y * int(x / y));\n}\n\n__DIVIDE_WITH_INTEGER_CHECK__;\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nfloat decode32(vec4 texel) {\n __DECODE32_ENDIANNESS__;\n texel *= 255.0;\n vec2 gte128;\n gte128.x = texel.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = texel.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * texel.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n texel.b = texel.b - 128.0 * gte128.x;\n res = dot(texel, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nfloat decode16(vec4 texel, int index) {\n int channel = integerMod(index, 2);\n if (channel == 0) return texel.r * 255.0 + texel.g * 65280.0;\n if (channel == 1) return texel.b * 255.0 + texel.a * 65280.0;\n return 0.0;\n}\n\nfloat decode8(vec4 texel, int index) {\n int channel = integerMod(index, 4);\n if (channel == 0) return texel.r * 255.0;\n if (channel == 1) return texel.g * 255.0;\n if (channel == 2) return texel.b * 255.0;\n if (channel == 3) return texel.a * 255.0;\n return 0.0;\n}\n\nvec4 legacyEncode32(float f) {\n float F = abs(f);\n float sign = f < 0.0 ? 1.0 : 0.0;\n float exponent = floor(log2(F));\n float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 texel = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n texel.rg = integerMod(texel.rg, 256.0);\n texel.b = integerMod(texel.b, 128.0);\n texel.a = exponent*0.5 + 63.5;\n texel.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n texel = floor(texel);\n texel *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return texel;\n}\n\n// https://github.com/gpujs/gpu.js/wiki/Encoder-details\nvec4 encode32(float value) {\n if (value == 0.0) return vec4(0, 0, 0, 0);\n\n float exponent;\n float mantissa;\n vec4 result;\n float sgn;\n\n sgn = step(0.0, -value);\n value = abs(value);\n\n exponent = floor(log2(value));\n\n mantissa = value*pow(2.0, -exponent)-1.0;\n exponent = exponent+127.0;\n result = vec4(0,0,0,0);\n\n result.a = floor(exponent/2.0);\n exponent = exponent - result.a*2.0;\n result.a = result.a + 128.0*sgn;\n\n result.b = floor(mantissa * 128.0);\n mantissa = mantissa - result.b / 128.0;\n result.b = result.b + exponent*128.0;\n\n result.g = floor(mantissa*32768.0);\n mantissa = mantissa - result.g/32768.0;\n\n result.r = floor(mantissa*8388608.0);\n return result/255.0;\n}\n// Dragons end here\n\nint index;\nivec3 threadId;\n\nivec3 indexTo3D(int idx, ivec3 texDim) {\n int z = int(idx / (texDim.x * texDim.y));\n idx -= z * int(texDim.x * texDim.y);\n int y = int(idx / texDim.x);\n int x = int(integerMod(idx, texDim.x));\n return ivec3(x, y, z);\n}\n\nfloat get32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture2D(tex, st / vec2(texSize));\n return decode32(texel);\n}\n\nfloat get16(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int w = texSize.x * 2;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture2D(tex, st / vec2(texSize.x * 2, texSize.y));\n return decode16(texel, index);\n}\n\nfloat get8(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int w = texSize.x * 4;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture2D(tex, st / vec2(texSize.x * 4, texSize.y));\n return decode8(texel, index);\n}\n\nfloat getMemoryOptimized32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int channel = integerMod(index, 4);\n index = index / 4;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture2D(tex, st / vec2(texSize));\n if (channel == 0) return texel.r;\n if (channel == 1) return texel.g;\n if (channel == 2) return texel.b;\n if (channel == 3) return texel.a;\n return 0.0;\n}\n\nvec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n return texture2D(tex, st / vec2(texSize));\n}\n\nfloat getFloatFromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n vec4 result = getImage2D(tex, texSize, texDim, z, y, x);\n return result[0];\n}\n\nvec2 getVec2FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n vec4 result = getImage2D(tex, texSize, texDim, z, y, x);\n return vec2(result[0], result[1]);\n}\n\nvec2 getMemoryOptimizedVec2(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + (texDim.x * (y + (texDim.y * z)));\n int channel = integerMod(index, 2);\n index = index / 2;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture2D(tex, st / vec2(texSize));\n if (channel == 0) return vec2(texel.r, texel.g);\n if (channel == 1) return vec2(texel.b, texel.a);\n return vec2(0.0, 0.0);\n}\n\nvec3 getVec3FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n vec4 result = getImage2D(tex, texSize, texDim, z, y, x);\n return vec3(result[0], result[1], result[2]);\n}\n\nvec3 getMemoryOptimizedVec3(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int fieldIndex = 3 * (x + texDim.x * (y + texDim.y * z));\n int vectorIndex = fieldIndex / 4;\n int vectorOffset = fieldIndex - vectorIndex * 4;\n int readY = vectorIndex / texSize.x;\n int readX = vectorIndex - readY * texSize.x;\n vec4 tex1 = texture2D(tex, (vec2(readX, readY) + 0.5) / vec2(texSize));\n \n if (vectorOffset == 0) {\n return tex1.xyz;\n } else if (vectorOffset == 1) {\n return tex1.yzw;\n } else {\n readX++;\n if (readX >= texSize.x) {\n readX = 0;\n readY++;\n }\n vec4 tex2 = texture2D(tex, vec2(readX, readY) / vec2(texSize));\n if (vectorOffset == 2) {\n return vec3(tex1.z, tex1.w, tex2.x);\n } else {\n return vec3(tex1.w, tex2.x, tex2.y);\n }\n }\n}\n\nvec4 getVec4FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n return getImage2D(tex, texSize, texDim, z, y, x);\n}\n\nvec4 getMemoryOptimizedVec4(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int channel = integerMod(index, 2);\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture2D(tex, st / vec2(texSize));\n return vec4(texel.r, texel.g, texel.b, texel.a);\n}\n\nvec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\nvoid color(sampler2D image) {\n actualColor = texture2D(image, vTexCoord);\n}\n\n__INJECTED_NATIVE__;\n__MAIN_CONSTANTS__;\n__MAIN_ARGUMENTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = int(vTexCoord.s * float(uTexSize.x)) + int(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}"}},{}],37:[function(e,t,r){const{utils:n}=e("../../utils"),{FunctionNode:i}=e("../function-node");const s={Array:"sampler2D","Array(2)":"vec2","Array(3)":"vec3","Array(4)":"vec4",Array2D:"sampler2D",Array3D:"sampler2D",Boolean:"bool",Float:"float",Input:"sampler2D",Integer:"int",Number:"float",LiteralInteger:"float",NumberTexture:"sampler2D",MemoryOptimizedNumberTexture:"sampler2D","ArrayTexture(1)":"sampler2D","ArrayTexture(2)":"sampler2D","ArrayTexture(3)":"sampler2D","ArrayTexture(4)":"sampler2D",HTMLVideo:"sampler2D",HTMLImage:"sampler2D",HTMLImageArray:"sampler2DArray"},a={"===":"==","!==":"!="};t.exports={WebGLFunctionNode:class extends i{constructor(e,t){super(e,t),t&&t.hasOwnProperty("fixIntegerDivisionAccuracy")&&(this.fixIntegerDivisionAccuracy=t.fixIntegerDivisionAccuracy)}astFunction(e,t){if(this.isRootKernel)t.push("void");else{this.returnType||this.findLastReturn()&&(this.returnType=this.getType(e.body),"LiteralInteger"===this.returnType&&(this.returnType="Number"));const{returnType:r}=this;if(r){const e=s[r];if(!e)throw new Error(`unknown type ${r}`);t.push(e)}else t.push("void")}if(t.push(" "),t.push(this.name),t.push("("),!this.isRootKernel)for(let r=0;r<this.argumentNames.length;++r){const n=this.argumentNames[r];r>0&&t.push(", ");let i=this.argumentTypes[this.argumentNames.indexOf(n)];if(!i)throw this.astErrorOutput(`Unknown argument ${n} type`,e);"LiteralInteger"===i&&(this.argumentTypes[r]=i="Number");const a=s[i];if(!a)throw this.astErrorOutput("Unexpected expression",e);"sampler2D"===a||"sampler2DArray"===a?t.push(`${a} user_${n},ivec2 user_${n}Size,ivec3 user_${n}Dim`):t.push(`${a} user_${n}`)}t.push(") {\n");for(let r=0;r<e.body.body.length;++r)this.astGeneric(e.body.body[r],t),t.push("\n");return t.push("}\n"),t}astReturnStatement(e,t){if(!e.argument)throw this.astErrorOutput("Unexpected return statement",e);this.pushState("skip-literal-correction");const r=this.getType(e.argument);this.popState("skip-literal-correction");const n=[];switch(this.returnType||(this.returnType="LiteralInteger"===r||"Integer"===r?"Number":r),this.returnType){case"LiteralInteger":case"Number":case"Float":switch(r){case"Integer":n.push("float("),this.astGeneric(e.argument,n),n.push(")");break;case"LiteralInteger":this.castLiteralToFloat(e.argument,n),"Integer"===this.getType(e)&&(n.unshift("float("),n.push(")"));break;default:this.astGeneric(e.argument,n)}break;case"Integer":switch(r){case"Float":case"Number":this.castValueToInteger(e.argument,n);break;case"LiteralInteger":this.castLiteralToInteger(e.argument,n);break;default:this.astGeneric(e.argument,n)}break;case"Array(4)":case"Array(3)":case"Array(2)":case"Input":this.astGeneric(e.argument,n);break;default:throw this.astErrorOutput(`unhandled return type ${this.returnType}`,e)}return this.isRootKernel?(t.push(`kernelResult = ${n.join("")};`),t.push("return;")):this.isSubKernel?(t.push(`subKernelResult_${this.name} = ${n.join("")};`),t.push(`return subKernelResult_${this.name};`)):t.push(`return ${n.join("")};`),t}astLiteral(e,t){if(isNaN(e.value))throw this.astErrorOutput("Non-numeric literal not supported : "+e.value,e);const r=`${e.start},${e.end}`;return Number.isInteger(e.value)?this.isState("in-for-loop-init")||this.isState("casting-to-integer")||this.isState("building-integer")?(this.literalTypes[r]="Integer",t.push(`${e.value}`)):(this.isState("casting-to-float")||this.isState("building-float"),this.literalTypes[r]="Number",t.push(`${e.value}.0`)):this.isState("casting-to-integer")||this.isState("building-integer")?(this.literalTypes[r]="Integer",t.push(Math.round(e.value))):(this.literalTypes[r]="Number",t.push(`${e.value}`)),t}astBinaryExpression(e,t){if(this.checkAndUpconvertOperator(e,t))return t;if(this.fixIntegerDivisionAccuracy&&"/"===e.operator){switch(t.push("div_with_int_check("),this.pushState("building-float"),this.getType(e.left)){case"Integer":this.castValueToFloat(e.left,t);break;case"LiteralInteger":this.castLiteralToFloat(e.left,t);break;default:this.astGeneric(e.left,t)}switch(t.push(", "),this.getType(e.right)){case"Integer":this.castValueToFloat(e.right,t);break;case"LiteralInteger":this.castLiteralToFloat(e.right,t);break;default:this.astGeneric(e.right,t)}return this.popState("building-float"),t.push(")"),t}t.push("(");const r=this.getType(e.left)||"Number",n=this.getType(e.right)||"Number";if(!r||!n)throw this.astErrorOutput("Unhandled binary expression",e);const i=r+" & "+n;switch(i){case"Integer & Integer":this.pushState("building-integer"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.astGeneric(e.right,t),this.popState("building-integer");break;case"Number & Float":case"Float & Number":case"Float & Float":case"Number & Number":this.pushState("building-float"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.astGeneric(e.right,t),this.popState("building-float");break;case"LiteralInteger & LiteralInteger":this.isState("casting-to-integer")||this.isState("building-integer")?(this.pushState("building-integer"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.astGeneric(e.right,t),this.popState("building-integer")):(this.pushState("building-float"),this.castLiteralToFloat(e.left,t),t.push(a[e.operator]||e.operator),this.castLiteralToFloat(e.right,t),this.popState("building-float"));break;case"Integer & Float":case"Integer & Number":if((">"===e.operator||"<"===e.operator&&"Literal"===e.right.type)&&!Number.isInteger(e.right.value)){this.pushState("building-float"),this.castValueToFloat(e.left,t),t.push(a[e.operator]||e.operator),this.astGeneric(e.right,t),this.popState("building-float");break}if(this.pushState("building-integer"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.pushState("casting-to-integer"),"Literal"===e.right.type){const r=[];if(this.astGeneric(e.right,r),"Integer"!==this.getType(e.right))throw this.astErrorOutput("Unhandled binary expression with literal",e);t.push(r.join(""))}else t.push("int("),this.astGeneric(e.right,t),t.push(")");this.popState("casting-to-integer"),this.popState("building-integer");break;case"Integer & LiteralInteger":this.pushState("building-integer"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.castLiteralToInteger(e.right,t),this.popState("building-integer");break;case"Number & Integer":this.pushState("building-float"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.castValueToFloat(e.right,t),this.popState("building-float");break;case"Float & LiteralInteger":case"Number & LiteralInteger":this.isState("in-for-loop-test")?(this.pushState("building-integer"),t.push("int("),this.astGeneric(e.left,t),t.push(")"),t.push(a[e.operator]||e.operator),this.castLiteralToInteger(e.right,t),this.popState("building-integer")):(this.pushState("building-float"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.castLiteralToFloat(e.right,t),this.popState("building-float"));break;case"LiteralInteger & Float":case"LiteralInteger & Number":this.isState("in-for-loop-test")||this.isState("in-for-loop-init")||this.isState("casting-to-integer")?(this.pushState("building-integer"),this.castLiteralToInteger(e.left,t),t.push(a[e.operator]||e.operator),this.castValueToInteger(e.right,t),this.popState("building-integer")):(this.pushState("building-float"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.pushState("casting-to-float"),this.astGeneric(e.right,t),this.popState("casting-to-float"),this.popState("building-float"));break;case"LiteralInteger & Integer":this.pushState("building-integer"),this.castLiteralToInteger(e.left,t),t.push(a[e.operator]||e.operator),this.astGeneric(e.right,t),this.popState("building-integer");break;case"Boolean & Boolean":this.pushState("building-boolean"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.astGeneric(e.right,t),this.popState("building-boolean");break;case"Float & Integer":this.pushState("building-float"),this.astGeneric(e.left,t),t.push(a[e.operator]||e.operator),this.castValueToFloat(e.right,t),this.popState("building-float");break;default:throw this.astErrorOutput(`Unhandled binary expression between ${i}`,e)}return t.push(")"),t}checkAndUpconvertOperator(e,t){const r=this.checkAndUpconvertBitwiseOperators(e,t);if(r)return r;const n={"%":"mod","**":"pow"}[e.operator];if(!n)return null;switch(t.push(n),t.push("("),this.getType(e.left)){case"Integer":this.castValueToFloat(e.left,t);break;case"LiteralInteger":this.castLiteralToFloat(e.left,t);break;default:this.astGeneric(e.left,t)}switch(t.push(","),this.getType(e.right)){case"Integer":this.castValueToFloat(e.right,t);break;case"LiteralInteger":this.castLiteralToFloat(e.right,t);break;default:this.astGeneric(e.right,t)}return t.push(")"),t}checkAndUpconvertBitwiseOperators(e,t){const r={"&":"bitwiseAnd","|":"bitwiseOr","^":"bitwiseXOR","<<":"bitwiseZeroFillLeftShift",">>":"bitwiseSignedRightShift",">>>":"bitwiseZeroFillRightShift"}[e.operator];if(!r)return null;switch(t.push(r),t.push("("),this.getType(e.left)){case"Number":case"Float":this.castValueToInteger(e.left,t);break;case"LiteralInteger":this.castLiteralToInteger(e.left,t);break;default:this.astGeneric(e.left,t)}switch(t.push(","),this.getType(e.right)){case"Number":case"Float":this.castValueToInteger(e.right,t);break;case"LiteralInteger":this.castLiteralToInteger(e.right,t);break;default:this.astGeneric(e.right,t)}return t.push(")"),t}checkAndUpconvertBitwiseUnary(e,t){const r={"~":"bitwiseNot"}[e.operator];if(!r)return null;switch(t.push(r),t.push("("),this.getType(e.argument)){case"Number":case"Float":this.castValueToInteger(e.argument,t);break;case"LiteralInteger":this.castLiteralToInteger(e.argument,t);break;default:this.astGeneric(e.argument,t)}return t.push(")"),t}castLiteralToInteger(e,t){return this.pushState("casting-to-integer"),this.astGeneric(e,t),this.popState("casting-to-integer"),t}castLiteralToFloat(e,t){return this.pushState("casting-to-float"),this.astGeneric(e,t),this.popState("casting-to-float"),t}castValueToInteger(e,t){return this.pushState("casting-to-integer"),t.push("int("),this.astGeneric(e,t),t.push(")"),this.popState("casting-to-integer"),t}castValueToFloat(e,t){return this.pushState("casting-to-float"),t.push("float("),this.astGeneric(e,t),t.push(")"),this.popState("casting-to-float"),t}astIdentifierExpression(e,t){if("Identifier"!==e.type)throw this.astErrorOutput("IdentifierExpression - not an Identifier",e);const r=this.getType(e);return"Infinity"===e.name?t.push("3.402823466e+38"):"Boolean"===r&&this.argumentNames.indexOf(e.name)>-1?t.push(`bool(user_${e.name})`):t.push(`user_${e.name}`),t}astForStatement(e,t){if("ForStatement"!==e.type)throw this.astErrorOutput("Invalid for statement",e);const r=[],n=[],i=[],s=[];let a=null;if(e.init){this.pushState("in-for-loop-init"),this.astGeneric(e.init,r);const{declarations:t}=e.init;for(let e=0;e<t.length;e++)t[e].init&&"Literal"!==t[e].init.type&&(a=!1);if(a)for(let e=0;e<r.length;e++)r[e].includes&&r[e].includes(",")&&(a=!1);this.popState("in-for-loop-init")}else a=!1;if(e.test?(this.pushState("in-for-loop-test"),this.astGeneric(e.test,n),this.popState("in-for-loop-test")):a=!1,e.update?this.astGeneric(e.update,i):a=!1,e.body&&(this.pushState("loop-body"),this.astGeneric(e.body,s),this.popState("loop-body")),null===a&&(a=this.isSafe(e.init)&&this.isSafe(e.test)),a)t.push(`for (${r.join("")};${n.join("")};${i.join("")}){\n`),t.push(s.join("")),t.push("}\n");else{const e=this.getInternalVariableName("safeI");r.length>0&&t.push(r.join(""),";\n"),t.push(`for (int ${e}=0;${e}<LOOP_MAX;${e}++){\n`),n.length>0&&t.push(`if (!${n.join("")}) break;\n`),t.push(s.join("")),t.push(`\n${i.join("")};`),t.push("}\n")}return t}astWhileStatement(e,t){if("WhileStatement"!==e.type)throw this.astErrorOutput("Invalid while statement",e);const r=this.getInternalVariableName("safeI");return t.push(`for (int ${r}=0;${r}<LOOP_MAX;${r}++){\n`),t.push("if (!"),this.astGeneric(e.test,t),t.push(") break;\n"),this.astGeneric(e.body,t),t.push("}\n"),t}astDoWhileStatement(e,t){if("DoWhileStatement"!==e.type)throw this.astErrorOutput("Invalid while statement",e);const r=this.getInternalVariableName("safeI");return t.push(`for (int ${r}=0;${r}<LOOP_MAX;${r}++){\n`),this.astGeneric(e.body,t),t.push("if (!"),this.astGeneric(e.test,t),t.push(") break;\n"),t.push("}\n"),t}astAssignmentExpression(e,t){if("%="===e.operator)this.astGeneric(e.left,t),t.push("="),t.push("mod("),this.astGeneric(e.left,t),t.push(","),this.astGeneric(e.right,t),t.push(")");else{if("**="!==e.operator){const r=this.getType(e.left),n=this.getType(e.right);return this.astGeneric(e.left,t),t.push(e.operator),"Integer"!==r&&"Integer"===n?(t.push("float("),this.astGeneric(e.right,t),t.push(")")):this.astGeneric(e.right,t),t}this.astGeneric(e.left,t),t.push("="),t.push("pow("),this.astGeneric(e.left,t),t.push(","),this.astGeneric(e.right,t),t.push(")")}}astBlockStatement(e,t){if(this.isState("loop-body")){this.pushState("block-body");for(let r=0;r<e.body.length;r++)this.astGeneric(e.body[r],t);this.popState("block-body")}else{t.push("{\n");for(let r=0;r<e.body.length;r++)this.astGeneric(e.body[r],t);t.push("}\n")}return t}astVariableDeclaration(e,t){"var"===e.kind&&this.warnVarUsage&&this.varWarn();const r=e.declarations;if(!r||!r[0]||!r[0].init)throw this.astErrorOutput("Unexpected expression",e);const n=[];let i=null;const a=this.isState("in-for-loop-init");for(let t=0;t<r.length;t++){const o=r[t],u=o.init,l=this.getDeclaration(o.id),h=(l.valueType,this.getType(o.init));l.dependencies;let c=a?"Integer":h;"LiteralInteger"===c&&(c="Number");const p=s[c];if(!p)throw this.astErrorOutput(`Markup type ${p} not handled`,e);const d=[];if("Integer"!==h||"Integer"!==c||a)l.valueType=c,0===t||null===i?d.push(`${p} `):c!==i?(n.push(";"),d.push(`${p} `)):d.push(","),i=c,d.push(`user_${o.id.name}=`),"Number"===h&&"Integer"===c?u.left&&"Literal"===u.left.type?this.astGeneric(u,d):(d.push("int("),this.astGeneric(u,d),d.push(")")):this.astGeneric(u,d);else{if(l.valueType="Number",0===t||null===i)d.push("float ");else{if(c!==i)throw new Error("Unhandled declaration");d.push(",")}i=c,d.push(`user_${o.id.name}=`),d.push("float("),this.astGeneric(u,d),d.push(")")}n.push(d.join(""))}return t.push(n.join("")),a||t.push(";"),t}astIfStatement(e,t){return t.push("if ("),this.astGeneric(e.test,t),t.push(")"),"BlockStatement"===e.consequent.type?this.astGeneric(e.consequent,t):(t.push(" {\n"),this.astGeneric(e.consequent,t),t.push("\n}\n")),e.alternate&&(t.push("else "),"BlockStatement"===e.alternate.type?this.astGeneric(e.alternate,t):(t.push(" {\n"),this.astGeneric(e.alternate,t),t.push("\n}\n"))),t}astSwitchStatement(e,t){if("SwitchStatement"!==e.type)throw this.astErrorOutput("Invalid switch statement",e);const{discriminant:r,cases:n}=e,i=this.getType(r),s=`switchDiscriminant${e.start}_${e.end}`;switch(i){case"Float":case"Number":t.push(`float ${s} = `),this.astGeneric(r,t),t.push(";\n");break;case"Integer":t.push(`int ${s} = `),this.astGeneric(r,t),t.push(";\n")}if(1===n.length&&!n[0].test)return this.astGeneric(n[0].consequent,t),t;let a=!1,o=[],u=!1,l=!1;for(let e=0;e<n.length;e++){if(n[e].test){if(0!==e&&l?a?(t.push(`${s} == `),a=!1):t.push(` else if (${s} == `):(l=!0,t.push(`if (${s} == `)),"Integer"===i)switch(this.getType(n[e].test)){case"Number":case"Float":this.castValueToInteger(n[e].test,t);break;case"LiteralInteger":this.castLiteralToInteger(n[e].test,t)}else{if("Float"!==i)throw new Error("unhanlded");switch(this.getType(n[e].test)){case"LiteralInteger":this.castLiteralToFloat(n[e].test,t);break;case"Integer":this.castValueToFloat(n[e].test,t)}}if(!n[e].consequent||0===n[e].consequent.length){a=!0,t.push(" || ");continue}t.push(") {\n")}else{if(n.length>e+1){u=!0,this.astGeneric(n[e].consequent,o);continue}t.push(" else {\n")}this.astGeneric(n[e].consequent,t),t.push("\n}")}return u&&(t.push(" else {"),t.push(o.join("")),t.push("}")),t}astThisExpression(e,t){return t.push("this"),t}astMemberExpression(e,t){const{property:r,name:n,signature:i,origin:s,type:a,xProperty:o,yProperty:u,zProperty:l}=this.getMemberExpressionDetails(e);switch(i){case"value.thread.value":case"this.thread.value":if("x"!==n&&"y"!==n&&"z"!==n)throw this.astErrorOutput("Unexpected expression, expected `this.thread.x`, `this.thread.y`, or `this.thread.z`",e);return t.push(`threadId.${n}`),t;case"this.output.value":if(this.dynamicOutput)switch(n){case"x":this.isState("casting-to-float")?t.push("float(uOutputDim.x)"):t.push("uOutputDim.x");break;case"y":this.isState("casting-to-float")?t.push("float(uOutputDim.y)"):t.push("uOutputDim.y");break;case"z":this.isState("casting-to-float")?t.push("float(uOutputDim.z)"):t.push("uOutputDim.z");break;default:throw this.astErrorOutput("Unexpected expression",e)}else switch(n){case"x":this.isState("casting-to-integer")?t.push(this.output[0]):t.push(this.output[0],".0");break;case"y":this.isState("casting-to-integer")?t.push(this.output[1]):t.push(this.output[1],".0");break;case"z":this.isState("casting-to-integer")?t.push(this.output[2]):t.push(this.output[2],".0");break;default:throw this.astErrorOutput("Unexpected expression",e)}return t;case"value":throw this.astErrorOutput("Unexpected expression",e);case"value[]":case"value[][]":case"value[][][]":case"value[][][][]":case"value.value":if("Math"===s)return t.push(Math[n]),t;switch(r){case"r":return t.push(`user_${n}.r`),t;case"g":return t.push(`user_${n}.g`),t;case"b":return t.push(`user_${n}.b`),t;case"a":return t.push(`user_${n}.a`),t}break;case"this.constants.value":if(void 0===o)switch(a){case"Array(2)":case"Array(3)":case"Array(4)":return t.push(`constants_${n}`),t}case"this.constants.value[]":case"this.constants.value[][]":case"this.constants.value[][][]":case"this.constants.value[][][][]":break;case"fn()[]":return this.astCallExpression(e.object,t),t.push("["),t.push(this.memberExpressionPropertyMarkup(r)),t.push("]"),t;case"[][]":return this.astArrayExpression(e.object,t),t.push("["),t.push(this.memberExpressionPropertyMarkup(r)),t.push("]"),t;default:throw this.astErrorOutput("Unexpected expression",e)}if(!1===e.computed)switch(a){case"Number":case"Integer":case"Float":case"Boolean":return t.push(`${s}_${n}`),t}const h=`${s}_${n}`;switch(a){case"Array(2)":case"Array(3)":case"Array(4)":this.astGeneric(e.object,t),t.push("["),t.push(this.memberExpressionPropertyMarkup(o)),t.push("]");break;case"HTMLImageArray":t.push(`getImage3D(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;case"ArrayTexture(1)":t.push(`getFloatFromSampler2D(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;case"Array1D(2)":case"Array2D(2)":case"Array3D(2)":t.push(`getMemoryOptimizedVec2(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;case"ArrayTexture(2)":t.push(`getVec2FromSampler2D(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;case"Array1D(3)":case"Array2D(3)":case"Array3D(3)":t.push(`getMemoryOptimizedVec3(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;case"ArrayTexture(3)":t.push(`getVec3FromSampler2D(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;case"Array1D(4)":case"Array2D(4)":case"Array3D(4)":t.push(`getMemoryOptimizedVec4(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;case"ArrayTexture(4)":case"HTMLImage":case"HTMLVideo":t.push(`getVec4FromSampler2D(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;case"NumberTexture":case"Array":case"Array2D":case"Array3D":case"Array4D":case"Input":case"Number":case"Float":case"Integer":if("single"===this.precision)t.push(`getMemoryOptimized32(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");else{const e="user"===s?this.lookupFunctionArgumentBitRatio(this.name,n):this.constantBitRatios[n];switch(e){case 1:t.push(`get8(${h}, ${h}Size, ${h}Dim, `);break;case 2:t.push(`get16(${h}, ${h}Size, ${h}Dim, `);break;case 4:case 0:t.push(`get32(${h}, ${h}Size, ${h}Dim, `);break;default:throw new Error(`unhandled bit ratio of ${e}`)}this.memberExpressionXYZ(o,u,l,t),t.push(")")}break;case"MemoryOptimizedNumberTexture":t.push(`getMemoryOptimized32(${h}, ${h}Size, ${h}Dim, `),this.memberExpressionXYZ(o,u,l,t),t.push(")");break;default:throw new Error(`unhandled member expression "${a}"`)}return t}astCallExpression(e,t){if(!e.callee)throw this.astErrorOutput("Unknown CallExpression",e);let r=null;const n=this.isAstMathFunction(e);if(!(r=n||e.callee.object&&"ThisExpression"===e.callee.object.type?e.callee.property.name:"SequenceExpression"!==e.callee.type||"Literal"!==e.callee.expressions[0].type||isNaN(e.callee.expressions[0].raw)?e.callee.name:e.callee.expressions[1].property.name))throw this.astErrorOutput("Unhandled function, couldn't find name",e);if("atan2"===r&&(r="atan"),this.calledFunctions.indexOf(r)<0&&this.calledFunctions.push(r),"random"===r&&this.plugins&&this.plugins.length>0)for(let e=0;e<this.plugins.length;e++){const r=this.plugins[e];if("Math.random()"===r.functionMatch&&r.functionReplace)return t.push(r.functionReplace),t}if(this.onFunctionCall&&this.onFunctionCall(this.name,r,e.arguments),t.push(r),t.push("("),n)for(let r=0;r<e.arguments.length;++r){const n=e.arguments[r],i=this.getType(n);switch(r>0&&t.push(", "),i){case"Integer":this.castValueToFloat(n,t);break;default:this.astGeneric(n,t)}}else{const n=this.lookupFunctionArgumentTypes(r)||[];for(let i=0;i<e.arguments.length;++i){const s=e.arguments[i];let a=n[i];i>0&&t.push(", ");const o=this.getType(s);switch(a||(this.triggerImplyArgumentType(r,i,o,this),a=o),o){case"Number":case"Float":if("Integer"===a){t.push("int("),this.astGeneric(s,t),t.push(")");continue}if("Number"===a||"Float"===a){this.astGeneric(s,t);continue}if("LiteralInteger"===a){this.castLiteralToFloat(s,t);continue}break;case"Integer":if("Number"===a||"Float"===a){t.push("float("),this.astGeneric(s,t),t.push(")");continue}if("Integer"===a){this.astGeneric(s,t);continue}break;case"LiteralInteger":if("Integer"===a){this.castLiteralToInteger(s,t);continue}if("Number"===a||"Float"===a){this.castLiteralToFloat(s,t);continue}if("LiteralInteger"===a){this.astGeneric(s,t);continue}break;case"Array(2)":case"Array(3)":case"Array(4)":if(a===o){if("Identifier"!==s.type)throw this.astErrorOutput(`Unhandled argument type ${s.type}`,e);this.triggerImplyArgumentBitRatio(this.name,s.name,r,i),t.push(`user_${s.name}`);continue}break;case"HTMLImage":case"HTMLImageArray":case"HTMLVideo":case"ArrayTexture(1)":case"ArrayTexture(2)":case"ArrayTexture(3)":case"ArrayTexture(4)":case"Array":case"Input":if(a===o){if("Identifier"!==s.type)throw this.astErrorOutput(`Unhandled argument type ${s.type}`,e);this.triggerImplyArgumentBitRatio(this.name,s.name,r,i),t.push(`user_${s.name},user_${s.name}Size,user_${s.name}Dim`);continue}}throw this.astErrorOutput(`Unhandled argument combination of ${o} and ${a} for argument named "${s.name}"`,e)}}return t.push(")"),t}astArrayExpression(e,t){const r=e.elements.length;t.push("vec"+r+"(");for(let n=0;n<r;++n){n>0&&t.push(", ");const r=e.elements[n];this.astGeneric(r,t)}return t.push(")"),t}memberExpressionXYZ(e,t,r,n){return r?n.push(this.memberExpressionPropertyMarkup(r),", "):n.push("0, "),t?n.push(this.memberExpressionPropertyMarkup(t),", "):n.push("0, "),n.push(this.memberExpressionPropertyMarkup(e)),n}memberExpressionPropertyMarkup(e){if(!e)throw new Error("Property not set");const t=[];switch(this.getType(e)){case"Number":case"Float":this.castValueToInteger(e,t);break;case"LiteralInteger":this.castLiteralToInteger(e,t);break;default:this.astGeneric(e,t)}return t.join("")}}}},{"../../utils":112,"../function-node":10}],38:[function(e,t,r){const{WebGLKernelValueBoolean:n}=e("./kernel-value/boolean"),{WebGLKernelValueFloat:i}=e("./kernel-value/float"),{WebGLKernelValueInteger:s}=e("./kernel-value/integer"),{WebGLKernelValueHTMLImage:a}=e("./kernel-value/html-image"),{WebGLKernelValueDynamicHTMLImage:o}=e("./kernel-value/dynamic-html-image"),{WebGLKernelValueHTMLVideo:u}=e("./kernel-value/html-video"),{WebGLKernelValueDynamicHTMLVideo:l}=e("./kernel-value/dynamic-html-video"),{WebGLKernelValueSingleInput:h}=e("./kernel-value/single-input"),{WebGLKernelValueDynamicSingleInput:c}=e("./kernel-value/dynamic-single-input"),{WebGLKernelValueUnsignedInput:p}=e("./kernel-value/unsigned-input"),{WebGLKernelValueDynamicUnsignedInput:d}=e("./kernel-value/dynamic-unsigned-input"),{WebGLKernelValueMemoryOptimizedNumberTexture:m}=e("./kernel-value/memory-optimized-number-texture"),{WebGLKernelValueDynamicMemoryOptimizedNumberTexture:g}=e("./kernel-value/dynamic-memory-optimized-number-texture"),{WebGLKernelValueNumberTexture:f}=e("./kernel-value/number-texture"),{WebGLKernelValueDynamicNumberTexture:x}=e("./kernel-value/dynamic-number-texture"),{WebGLKernelValueSingleArray:y}=e("./kernel-value/single-array"),{WebGLKernelValueDynamicSingleArray:T}=e("./kernel-value/dynamic-single-array"),{WebGLKernelValueSingleArray1DI:b}=e("./kernel-value/single-array1d-i"),{WebGLKernelValueDynamicSingleArray1DI:A}=e("./kernel-value/dynamic-single-array1d-i"),{WebGLKernelValueSingleArray2DI:v}=e("./kernel-value/single-array2d-i"),{WebGLKernelValueDynamicSingleArray2DI:S}=e("./kernel-value/dynamic-single-array2d-i"),{WebGLKernelValueSingleArray3DI:E}=e("./kernel-value/single-array3d-i"),{WebGLKernelValueDynamicSingleArray3DI:_}=e("./kernel-value/dynamic-single-array3d-i"),{WebGLKernelValueSingleArray2:w}=e("./kernel-value/single-array2"),{WebGLKernelValueSingleArray3:k}=e("./kernel-value/single-array3"),{WebGLKernelValueSingleArray4:D}=e("./kernel-value/single-array4"),{WebGLKernelValueUnsignedArray:I}=e("./kernel-value/unsigned-array"),{WebGLKernelValueDynamicUnsignedArray:R}=e("./kernel-value/dynamic-unsigned-array"),L={unsigned:{dynamic:{Boolean:n,Integer:s,Float:i,Array:R,"Array(2)":!1,"Array(3)":!1,"Array(4)":!1,"Array1D(2)":!1,"Array1D(3)":!1,"Array1D(4)":!1,"Array2D(2)":!1,"Array2D(3)":!1,"Array2D(4)":!1,"Array3D(2)":!1,"Array3D(3)":!1,"Array3D(4)":!1,Input:d,NumberTexture:x,"ArrayTexture(1)":x,"ArrayTexture(2)":x,"ArrayTexture(3)":x,"ArrayTexture(4)":x,MemoryOptimizedNumberTexture:g,HTMLImage:o,HTMLImageArray:!1,HTMLVideo:l},static:{Boolean:n,Float:i,Integer:s,Array:I,"Array(2)":!1,"Array(3)":!1,"Array(4)":!1,"Array1D(2)":!1,"Array1D(3)":!1,"Array1D(4)":!1,"Array2D(2)":!1,"Array2D(3)":!1,"Array2D(4)":!1,"Array3D(2)":!1,"Array3D(3)":!1,"Array3D(4)":!1,Input:p,NumberTexture:f,"ArrayTexture(1)":f,"ArrayTexture(2)":f,"ArrayTexture(3)":f,"ArrayTexture(4)":f,MemoryOptimizedNumberTexture:m,HTMLImage:a,HTMLImageArray:!1,HTMLVideo:u}},single:{dynamic:{Boolean:n,Integer:s,Float:i,Array:T,"Array(2)":w,"Array(3)":k,"Array(4)":D,"Array1D(2)":A,"Array1D(3)":A,"Array1D(4)":A,"Array2D(2)":S,"Array2D(3)":S,"Array2D(4)":S,"Array3D(2)":_,"Array3D(3)":_,"Array3D(4)":_,Input:c,NumberTexture:x,"ArrayTexture(1)":x,"ArrayTexture(2)":x,"ArrayTexture(3)":x,"ArrayTexture(4)":x,MemoryOptimizedNumberTexture:g,HTMLImage:o,HTMLImageArray:!1,HTMLVideo:l},static:{Boolean:n,Float:i,Integer:s,Array:y,"Array(2)":w,"Array(3)":k,"Array(4)":D,"Array1D(2)":b,"Array1D(3)":b,"Array1D(4)":b,"Array2D(2)":v,"Array2D(3)":v,"Array2D(4)":v,"Array3D(2)":E,"Array3D(3)":E,"Array3D(4)":E,Input:h,NumberTexture:f,"ArrayTexture(1)":f,"ArrayTexture(2)":f,"ArrayTexture(3)":f,"ArrayTexture(4)":f,MemoryOptimizedNumberTexture:m,HTMLImage:a,HTMLImageArray:!1,HTMLVideo:u}}};t.exports={lookupKernelValueType:function(e,t,r,n){if(!e)throw new Error("type missing");if(!t)throw new Error("dynamic missing");if(!r)throw new Error("precision missing");n.type&&(e=n.type);const i=L[r][t];if(!1===i[e])return null;if(void 0===i[e])throw new Error(`Could not find a KernelValue for ${e}`);return i[e]},kernelValueMaps:L}},{"./kernel-value/boolean":39,"./kernel-value/dynamic-html-image":40,"./kernel-value/dynamic-html-video":41,"./kernel-value/dynamic-memory-optimized-number-texture":42,"./kernel-value/dynamic-number-texture":43,"./kernel-value/dynamic-single-array":44,"./kernel-value/dynamic-single-array1d-i":45,"./kernel-value/dynamic-single-array2d-i":46,"./kernel-value/dynamic-single-array3d-i":47,"./kernel-value/dynamic-single-input":48,"./kernel-value/dynamic-unsigned-array":49,"./kernel-value/dynamic-unsigned-input":50,"./kernel-value/float":51,"./kernel-value/html-image":52,"./kernel-value/html-video":53,"./kernel-value/integer":55,"./kernel-value/memory-optimized-number-texture":56,"./kernel-value/number-texture":57,"./kernel-value/single-array":58,"./kernel-value/single-array1d-i":59,"./kernel-value/single-array2":60,"./kernel-value/single-array2d-i":61,"./kernel-value/single-array3":62,"./kernel-value/single-array3d-i":63,"./kernel-value/single-array4":64,"./kernel-value/single-input":65,"./kernel-value/unsigned-array":66,"./kernel-value/unsigned-input":67}],39:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueBoolean:class extends i{constructor(e,t){super(e,t),this.uploadValue=e}getSource(e){return"constants"===this.origin?`const bool ${this.id} = ${e};\n`:`uniform bool ${this.id};\n`}getStringValueHandler(){return`const uploadValue_${this.name} = ${this.varName};\n`}updateValue(e){"constants"!==this.origin&&this.kernel.setUniform1i(this.id,this.uploadValue=e)}}}},{"../../../utils":112,"./index":54}],40:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueHTMLImage:i}=e("./html-image");t.exports={WebGLKernelValueDynamicHTMLImage:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){const{width:t,height:r}=e;this.checkSize(t,r),this.dimensions=[t,r,1],this.textureSize=[t,r],this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./html-image":52}],41:[function(e,t,r){const{WebGLKernelValueDynamicHTMLImage:n}=e("./dynamic-html-image");t.exports={WebGLKernelValueDynamicHTMLVideo:class extends n{}}},{"./dynamic-html-image":40}],42:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueMemoryOptimizedNumberTexture:i}=e("./memory-optimized-number-texture");t.exports={WebGLKernelValueDynamicMemoryOptimizedNumberTexture:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){this.checkSize(e.size[0],e.size[1]),this.dimensions=e.dimensions,this.textureSize=e.size,this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./memory-optimized-number-texture":56}],43:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueNumberTexture:i}=e("./number-texture");t.exports={WebGLKernelValueDynamicNumberTexture:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){this.dimensions=e.dimensions,this.checkSize(e.size[0],e.size[1]),this.textureSize=e.size,this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./number-texture":57}],44:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleArray:i}=e("./single-array");t.exports={WebGLKernelValueDynamicSingleArray:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){this.dimensions=n.getDimensions(e,!0),this.textureSize=n.getMemoryOptimizedFloatTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./single-array":58}],45:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleArray1DI:i}=e("./single-array1d-i");t.exports={WebGLKernelValueDynamicSingleArray1DI:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){this.setShape(e),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./single-array1d-i":59}],46:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleArray2DI:i}=e("./single-array2d-i");t.exports={WebGLKernelValueDynamicSingleArray2DI:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){this.setShape(e),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./single-array2d-i":61}],47:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleArray3DI:i}=e("./single-array3d-i");t.exports={WebGLKernelValueDynamicSingleArray3DI:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){this.setShape(e),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./single-array3d-i":63}],48:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleInput:i}=e("./single-input");t.exports={WebGLKernelValueDynamicSingleInput:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){let[t,r,i]=e.size;this.dimensions=new Int32Array([t||1,r||1,i||1]),this.textureSize=n.getMemoryOptimizedFloatTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./single-input":65}],49:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueUnsignedArray:i}=e("./unsigned-array");t.exports={WebGLKernelValueDynamicUnsignedArray:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){this.dimensions=n.getDimensions(e,!0),this.textureSize=n.getMemoryOptimizedPackedTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*(4/this.bitRatio),this.checkSize(this.textureSize[0]*(4/this.bitRatio),this.textureSize[1]*(4/this.bitRatio));const t=this.getTransferArrayType(e);this.preUploadValue=new t(this.uploadArrayLength),this.uploadValue=new Uint8Array(this.preUploadValue.buffer),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./unsigned-array":66}],50:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueUnsignedInput:i}=e("./unsigned-input");t.exports={WebGLKernelValueDynamicUnsignedInput:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}updateValue(e){let[t,r,i]=e.size;this.dimensions=new Int32Array([t||1,r||1,i||1]),this.textureSize=n.getMemoryOptimizedPackedTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*(4/this.bitRatio),this.checkSize(this.textureSize[0]*(4/this.bitRatio),this.textureSize[1]*(4/this.bitRatio));const s=this.getTransferArrayType(e.value);this.preUploadValue=new s(this.uploadArrayLength),this.uploadValue=new Uint8Array(this.preUploadValue.buffer),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"./unsigned-input":67}],51:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueFloat:class extends i{constructor(e,t){super(e,t),this.uploadValue=e}getStringValueHandler(){return`const uploadValue_${this.name} = ${this.varName};\n`}getSource(e){return"constants"===this.origin?Number.isInteger(e)?`const float ${this.id} = ${e}.0;\n`:`const float ${this.id} = ${e};\n`:`uniform float ${this.id};\n`}updateValue(e){"constants"!==this.origin&&this.kernel.setUniform1f(this.id,this.uploadValue=e)}}}},{"../../../utils":112,"./index":54}],52:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueHTMLImage:class extends i{constructor(e,t){super(e,t);const{width:r,height:n}=e;this.checkSize(r,n),this.dimensions=[r,n,1],this.requestTexture(),this.textureSize=[r,n],this.uploadValue=e}getStringValueHandler(){return`const uploadValue_${this.name} = ${this.varName};\n`}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!0),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,this.uploadValue=e),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],53:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueHTMLImage:i}=e("./html-image");t.exports={WebGLKernelValueHTMLVideo:class extends i{}}},{"../../../utils":112,"./html-image":52}],54:[function(e,t,r){const{utils:n}=e("../../../utils"),{Input:i}=e("../../../input"),{KernelValue:s}=e("../../kernel-value");t.exports={WebGLKernelValue:class extends s{constructor(e,t){super(e,t),this.dimensionsId=null,this.sizeId=null,this.initialValueConstructor=e.constructor,this.onRequestTexture=t.onRequestTexture,this.onRequestIndex=t.onRequestIndex,this.uploadValue=null,this.textureSize=null,this.bitRatio=null}checkSize(e,t){if(!this.kernel.validate)return;const{maxTextureSize:r}=this.kernel.constructor.features;if(e>r||t>r)throw e>t?new Error(`Argument width of ${e} larger than maximum size of ${r} for your GPU`):new Error(`Argument height of ${t} larger than maximum size of ${r} for your GPU`)}requestTexture(){this.texture=this.onRequestTexture(),this.setupTexture()}setupTexture(){this.contextHandle=this.onRequestContextHandle(),this.index=this.onRequestIndex(),this.dimensionsId=this.id+"Dim",this.sizeId=this.id+"Size"}getTransferArrayType(e){if(Array.isArray(e[0]))return this.getTransferArrayType(e[0]);switch(e.constructor){case Array:case Int32Array:case Int16Array:case Int8Array:return Float32Array;case Uint8ClampedArray:case Uint8Array:case Uint16Array:case Uint32Array:case Float32Array:case Float64Array:return e.constructor}return console.warn("Unfamiliar constructor type. Will go ahead and use, but likley this may result in a transfer of zeros"),e.constructor}formatArrayTransfer(e,t,r){if(n.isArray(e[0])||this.optimizeFloatMemory){const r=new Float32Array(t);return n.flattenTo(e,r),r}switch(e.constructor){case Uint8ClampedArray:case Uint8Array:case Int8Array:case Uint16Array:case Int16Array:case Float32Array:case Int32Array:{const i=new(r||e.constructor)(t);return n.flattenTo(e,i),i}default:{const r=new Float32Array(t);return n.flattenTo(e,r),r}}}getBitRatio(e){if(Array.isArray(e[0]))return this.getBitRatio(e[0]);if(e.constructor===i)return this.getBitRatio(e.value);switch(e.constructor){case Uint8ClampedArray:case Uint8Array:case Int8Array:return 1;case Uint16Array:case Int16Array:return 2;case Float32Array:case Int32Array:default:return 4}}getStringValueHandler(){throw new Error(`"getStringValueHandler" not implemented on ${this.constructor.name}`)}getVariablePrecisionString(){switch(this.tactic){case"speed":return"lowp";case"performance":return"highp";case"balanced":default:return"mediump"}}}}},{"../../../input":108,"../../../utils":112,"../../kernel-value":34}],55:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueInteger:class extends i{constructor(e,t){super(e,t),this.uploadValue=e}getStringValueHandler(){return`const uploadValue_${this.name} = ${this.varName};\n`}getSource(e){return"constants"===this.origin?`const int ${this.id} = ${parseInt(e)};\n`:`uniform int ${this.id};\n`}updateValue(e){"constants"!==this.origin&&this.kernel.setUniform1i(this.id,this.uploadValue=e)}}}},{"../../../utils":112,"./index":54}],56:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueMemoryOptimizedNumberTexture:class extends i{constructor(e,t){super(e,t);const[r,n]=e.size;this.checkSize(r,n),this.setupTexture(),this.dimensions=e.dimensions,this.textureSize=e.size,this.uploadValue=e.texture,this.forceUploadEachRun=!0}getStringValueHandler(){return`const uploadValue_${this.name} = ${this.varName}.texture;\n`}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();if(this.checkContext&&e.context!==this.context)throw new Error(`Value ${this.name} (${this.type}) must be from same context`);const{context:t}=this;t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.uploadValue=e.texture),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],57:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueNumberTexture:class extends i{constructor(e,t){super(e,t);const[r,n]=e.size;this.checkSize(r,n),this.setupTexture();const{size:i,dimensions:s}=e;this.bitRatio=this.getBitRatio(e),this.dimensions=s,this.textureSize=i,this.uploadValue=e.texture,this.forceUploadEachRun=!0}getStringValueHandler(){return`const uploadValue_${this.name} = ${this.varName}.texture;\n`}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();if(this.checkContext&&e.context!==this.context)throw new Error(`Value ${this.name} (${this.type}) must be from same context`);const{context:t}=this;t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.uploadValue=e.texture),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],58:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueSingleArray:class extends i{constructor(e,t){super(e,t),this.requestTexture(),this.bitRatio=4,this.dimensions=n.getDimensions(e,!0),this.textureSize=n.getMemoryOptimizedFloatTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength)}getStringValueHandler(){return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`,`flattenTo(${this.varName}, uploadValue_${this.name})`])}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flattenTo(e,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],59:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueSingleArray1DI:class extends i{constructor(e,t){super(e,t),this.requestTexture(),this.bitRatio=4,this.setShape(e)}setShape(e){const t=n.getDimensions(e,!0);this.textureSize=n.getMemoryOptimizedFloatTextureSize(t,this.bitRatio),this.dimensions=new Int32Array([t[1],1,1]),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength)}getStringValueHandler(){return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`,`flattenTo(${this.varName}, uploadValue_${this.name})`])}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flatten2dArrayTo(e,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],60:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueSingleArray2:class extends i{constructor(e,t){super(e,t),this.uploadValue=e}getSource(e){return"constants"===this.origin?`const vec2 ${this.id} = vec2(${e[0]},${e[1]});\n`:`uniform vec2 ${this.id};\n`}getStringValueHandler(){return"constants"===this.origin?"":`const uploadValue_${this.name} = ${this.varName};\n`}updateValue(e){"constants"!==this.origin&&this.kernel.setUniform2fv(this.id,this.uploadValue=e)}}}},{"../../../utils":112,"./index":54}],61:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueSingleArray2DI:class extends i{constructor(e,t){super(e,t),this.requestTexture(),this.bitRatio=4,this.setShape(e)}setShape(e){const t=n.getDimensions(e,!0);this.textureSize=n.getMemoryOptimizedFloatTextureSize(t,this.bitRatio),this.dimensions=new Int32Array([t[1],t[2],1]),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength)}getStringValueHandler(){return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`,`flattenTo(${this.varName}, uploadValue_${this.name})`])}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flatten3dArrayTo(e,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],62:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueSingleArray3:class extends i{constructor(e,t){super(e,t),this.uploadValue=e}getSource(e){return"constants"===this.origin?`const vec3 ${this.id} = vec3(${e[0]},${e[1]},${e[2]});\n`:`uniform vec3 ${this.id};\n`}getStringValueHandler(){return"constants"===this.origin?"":`const uploadValue_${this.name} = ${this.varName};\n`}updateValue(e){"constants"!==this.origin&&this.kernel.setUniform3fv(this.id,this.uploadValue=e)}}}},{"../../../utils":112,"./index":54}],63:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueSingleArray3DI:class extends i{constructor(e,t){super(e,t),this.requestTexture(),this.bitRatio=4,this.setShape(e)}setShape(e){const t=n.getDimensions(e,!0);this.textureSize=n.getMemoryOptimizedFloatTextureSize(t,this.bitRatio),this.dimensions=new Int32Array([t[1],t[2],t[3]]),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength)}getStringValueHandler(){return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`,`flattenTo(${this.varName}, uploadValue_${this.name})`])}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flatten4dArrayTo(e,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],64:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueSingleArray4:class extends i{constructor(e,t){super(e,t),this.uploadValue=e}getSource(e){return"constants"===this.origin?`const vec4 ${this.id} = vec4(${e[0]},${e[1]},${e[2]},${e[3]});\n`:`uniform vec4 ${this.id};\n`}getStringValueHandler(){return"constants"===this.origin?"":`const uploadValue_${this.name} = ${this.varName};\n`}updateValue(e){"constants"!==this.origin&&this.kernel.setUniform4fv(this.id,this.uploadValue=e)}}}},{"../../../utils":112,"./index":54}],65:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueSingleInput:class extends i{constructor(e,t){super(e,t),this.requestTexture(),this.bitRatio=4;let[r,i,s]=e.size;this.dimensions=new Int32Array([r||1,i||1,s||1]),this.textureSize=n.getMemoryOptimizedFloatTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength)}getStringValueHandler(){return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`,`flattenTo(${this.varName}.value, uploadValue_${this.name})`])}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flattenTo(e.value,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],66:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueUnsignedArray:class extends i{constructor(e,t){super(e,t),this.requestTexture(),this.bitRatio=this.getBitRatio(e),this.dimensions=n.getDimensions(e,!0),this.textureSize=n.getMemoryOptimizedPackedTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*(4/this.bitRatio),this.checkSize(this.textureSize[0]*(4/this.bitRatio),this.textureSize[1]*(4/this.bitRatio)),this.TranserArrayType=this.getTransferArrayType(e),this.preUploadValue=new this.TranserArrayType(this.uploadArrayLength),this.uploadValue=new Uint8Array(this.preUploadValue.buffer)}getStringValueHandler(){return n.linesToString([`const preUploadValue_${this.name} = new ${this.TranserArrayType.name}(${this.uploadArrayLength})`,`const uploadValue_${this.name} = new Uint8Array(preUploadValue_${this.name}.buffer)`,`flattenTo(${this.varName}, preUploadValue_${this.name})`])}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flattenTo(e,this.preUploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.UNSIGNED_BYTE,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],67:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("./index");t.exports={WebGLKernelValueUnsignedInput:class extends i{constructor(e,t){super(e,t),this.requestTexture(),this.bitRatio=this.getBitRatio(e);const[r,i,s]=e.size;this.dimensions=new Int32Array([r||1,i||1,s||1]),this.textureSize=n.getMemoryOptimizedPackedTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*(4/this.bitRatio),this.checkSize(this.textureSize[0]*(4/this.bitRatio),this.textureSize[1]*(4/this.bitRatio)),this.TranserArrayType=this.getTransferArrayType(e.value),this.preUploadValue=new this.TranserArrayType(this.uploadArrayLength),this.uploadValue=new Uint8Array(this.preUploadValue.buffer)}getStringValueHandler(){return n.linesToString([`const preUploadValue_${this.name} = new ${this.TranserArrayType.name}(${this.uploadArrayLength})`,`const uploadValue_${this.name} = new Uint8Array(preUploadValue_${this.name}.buffer)`,`flattenTo(${this.varName}.value, preUploadValue_${this.name})`])}getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flattenTo(e.value,this.preUploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.UNSIGNED_BYTE,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"./index":54}],68:[function(e,t,r){const{GLKernel:n}=e("../gl/kernel"),{FunctionBuilder:i}=e("../function-builder"),{WebGLFunctionNode:s}=e("./function-node"),{utils:a}=e("../../utils"),o=e("../../plugins/triangle-noise"),{fragmentShader:u}=e("./fragment-shader"),{vertexShader:l}=e("./vertex-shader"),{glKernelString:h}=e("../gl/kernel-string"),{lookupKernelValueType:c}=e("./kernel-value-maps");let p=null,d=null,m=null,g=null,f=null;const x=[o],y=[],T={};t.exports={WebGLKernel:class extends n{static get isSupported(){return null!==p?p:(this.setupFeatureChecks(),p=this.isContextMatch(m))}static setupFeatureChecks(){"undefined"!=typeof document?d=document.createElement("canvas"):"undefined"!=typeof OffscreenCanvas&&(d=new OffscreenCanvas(0,0)),d&&(m=d.getContext("webgl")||d.getContext("experimental-webgl"))&&m.getExtension&&(g={OES_texture_float:m.getExtension("OES_texture_float"),OES_texture_float_linear:m.getExtension("OES_texture_float_linear"),OES_element_index_uint:m.getExtension("OES_element_index_uint"),WEBGL_draw_buffers:m.getExtension("WEBGL_draw_buffers")},f=this.getFeatures())}static isContextMatch(e){return"undefined"!=typeof WebGLRenderingContext&&e instanceof WebGLRenderingContext}static getFeatures(){const e=this.getIsDrawBuffers();return Object.freeze({isFloatRead:this.getIsFloatRead(),isIntegerDivisionAccurate:this.getIsIntegerDivisionAccurate(),isTextureFloat:this.getIsTextureFloat(),isDrawBuffers:e,kernelMap:e,channelCount:this.getChannelCount(),maxTextureSize:this.getMaxTextureSize()})}static getIsTextureFloat(){return Boolean(g.OES_texture_float)}static getIsDrawBuffers(){return Boolean(g.WEBGL_draw_buffers)}static getChannelCount(){return g.WEBGL_draw_buffers?m.getParameter(g.WEBGL_draw_buffers.MAX_DRAW_BUFFERS_WEBGL):1}static getMaxTextureSize(){return m.getParameter(m.MAX_TEXTURE_SIZE)}static lookupKernelValueType(e,t,r,n){return c(e,t,r,n)}static get testCanvas(){return d}static get testContext(){return m}static get features(){return f}static get fragmentShader(){return u}static get vertexShader(){return l}constructor(e,t){super(e,t),this.program=null,this.pipeline=t.pipeline,this.endianness=a.systemEndianness(),this.extensions={},this.subKernelOutputTextures=null,this.kernelArguments=null,this.argumentTextureCount=0,this.constantTextureCount=0,this.compiledFragmentShader=null,this.compiledVertexShader=null,this.fragShader=null,this.vertShader=null,this.drawBuffersMap=null,this.outputTexture=null,this.maxTexSize=null,this.switchingKernels=!1,this.onRequestSwitchKernel=null,this.mergeSettings(e.settings||t),this.threadDim=null,this.framebuffer=null,this.buffer=null,this.textureCache={},this.programUniformLocationCache={},this.uniform1fCache={},this.uniform1iCache={},this.uniform2fCache={},this.uniform2fvCache={},this.uniform2ivCache={},this.uniform3fvCache={},this.uniform3ivCache={},this.uniform4fvCache={},this.uniform4ivCache={}}initCanvas(){if("undefined"!=typeof document){const e=document.createElement("canvas");return e.width=2,e.height=2,e}if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(0,0)}initContext(){const e={alpha:!1,depth:!1,antialias:!1};return this.canvas.getContext("webgl",e)||this.canvas.getContext("experimental-webgl",e)}initPlugins(e){const t=[],{source:r}=this;if("string"==typeof r)for(let e=0;e<x.length;e++){const n=x[e];r.match(n.functionMatch)&&t.push(n)}else if("object"==typeof r&&e.pluginNames)for(let r=0;r<x.length;r++){const n=x[r];e.pluginNames.some(e=>e===n.name)&&t.push(n)}return t}initExtensions(){this.extensions={OES_texture_float:this.context.getExtension("OES_texture_float"),OES_texture_float_linear:this.context.getExtension("OES_texture_float_linear"),OES_element_index_uint:this.context.getExtension("OES_element_index_uint"),WEBGL_draw_buffers:this.context.getExtension("WEBGL_draw_buffers"),WEBGL_color_buffer_float:this.context.getExtension("WEBGL_color_buffer_float")}}validateSettings(e){if(!this.validate)return void(this.texSize=a.getKernelTextureSize({optimizeFloatMemory:this.optimizeFloatMemory,precision:this.precision},this.output));const{features:t}=this.constructor;if(!0===this.optimizeFloatMemory&&!t.isTextureFloat)throw new Error("Float textures are not supported");if("single"===this.precision&&!t.isFloatRead)throw new Error("Single precision not supported");if(!this.graphical&&null===this.precision&&t.isTextureFloat&&(this.precision=t.isFloatRead?"single":"unsigned"),this.subKernels&&this.subKernels.length>0&&!this.extensions.WEBGL_draw_buffers)throw new Error("could not instantiate draw buffers extension");if(null===this.fixIntegerDivisionAccuracy?this.fixIntegerDivisionAccuracy=!t.isIntegerDivisionAccurate:this.fixIntegerDivisionAccuracy&&t.isIntegerDivisionAccurate&&(this.fixIntegerDivisionAccuracy=!1),this.checkOutput(),!this.output||0===this.output.length){if(1!==e.length)throw new Error("Auto output only supported for kernels with only one input");const t=a.getVariableType(e[0],this.strictIntegers);if("Array"===t)this.output=a.getDimensions(t);else{if("NumberTexture"!==t&&"ArrayTexture(4)"!==t)throw new Error("Auto output not supported for input type: "+t);this.output=e[0].output}}if(this.graphical){if(2!==this.output.length)throw new Error("Output must have 2 dimensions on graphical mode");return"precision"===this.precision&&(this.precision="unsigned",console.warn("Cannot use graphical mode and single precision at the same time")),void(this.texSize=a.clone(this.output))}null===this.precision&&t.isTextureFloat&&(this.precision="single"),this.texSize=a.getKernelTextureSize({optimizeFloatMemory:this.optimizeFloatMemory,precision:this.precision},this.output),this.checkTextureSize()}updateMaxTexSize(){const{texSize:e,canvas:t}=this;if(null===this.maxTexSize){let r=y.indexOf(t);-1===r&&(r=y.length,y.push(t),T[r]=[e[0],e[1]]),this.maxTexSize=T[r]}this.maxTexSize[0]<e[0]&&(this.maxTexSize[0]=e[0]),this.maxTexSize[1]<e[1]&&(this.maxTexSize[1]=e[1])}_oldtranslateSource(){const e=i.fromKernel(this,s,{fixIntegerDivisionAccuracy:this.fixIntegerDivisionAccuracy}),t=e.getPrototypeString("kernel");this.returnType||(this.returnType=e.getKernelResultType());let r=0;const n=e.getReturnTypes();for(let e=0;e<n.length;e++)switch(n[e]){case"Float":case"Number":case"Integer":r++;break;case"Array(2)":r+=2;break;case"Array(3)":r+=3;break;case"Array(4)":r+=4}if(f&&r>f.channelCount)throw new Error("Too many channels!");return this.translatedSource=t}setupArguments(e){this.kernelArguments=[],this.argumentTextureCount=0;const t=null===this.argumentTypes;if(t&&(this.argumentTypes=[]),this.argumentSizes=[],this.argumentBitRatios=[],e.length<this.argumentNames.length)throw new Error("not enough arguments for kernel");if(e.length>this.argumentNames.length)throw new Error("too many arguments for kernel");const{context:r}=this;let n=0;for(let i=0;i<e.length;i++){const s=e[i],o=this.argumentNames[i];let u;t?(u=a.getVariableType(s,this.strictIntegers),this.argumentTypes.push(u)):u=this.argumentTypes[i];const l=this.constructor.lookupKernelValueType(u,this.dynamicArguments?"dynamic":"static",this.precision,e[i]);if(null===l)return this.requestFallback(e);const h=new l(s,{name:o,type:u,tactic:this.tactic,origin:"user",context:r,checkContext:this.checkContext,kernel:this,strictIntegers:this.strictIntegers,onRequestTexture:()=>this.context.createTexture(),onRequestIndex:()=>n++,onUpdateValueMismatch:()=>{this.switchingKernels=!0},onRequestContextHandle:()=>r.TEXTURE0+this.constantTextureCount+this.argumentTextureCount++});this.kernelArguments.push(h),this.argumentSizes.push(h.textureSize),this.argumentBitRatios[i]=h.bitRatio}}setupConstants(e){const{context:t}=this;this.kernelConstants=[],this.forceUploadKernelConstants=[];let r=null===this.constantTypes;r&&(this.constantTypes={}),this.constantBitRatios={};let n=0;for(const i in this.constants){const s=this.constants[i];let o;r?(o=a.getVariableType(s,this.strictIntegers),this.constantTypes[i]=o):o=this.constantTypes[i];const u=this.constructor.lookupKernelValueType(o,"static",this.precision,s);if(null===u)return this.requestFallback(e);const l=new u(s,{name:i,type:o,tactic:this.tactic,origin:"constants",context:this.context,checkContext:this.checkContext,kernel:this,strictIntegers:this.strictIntegers,onRequestTexture:()=>this.context.createTexture(),onRequestIndex:()=>n++,onRequestContextHandle:()=>t.TEXTURE0+this.constantTextureCount++});this.constantBitRatios[i]=l.bitRatio,this.kernelConstants.push(l),l.forceUploadEachRun&&this.forceUploadKernelConstants.push(l)}}build(){if(this.initExtensions(),this.validateSettings(arguments),this.setupConstants(arguments),this.fallbackRequested)return;if(this.setupArguments(arguments),this.fallbackRequested)return;this.updateMaxTexSize(),this.translateSource();const e=this.pickRenderStrategy(arguments);if(e)return e;const{texSize:t,context:r,canvas:n}=this;r.enable(r.SCISSOR_TEST),this.pipeline&&this.precision,r.viewport(0,0,this.maxTexSize[0],this.maxTexSize[1]),n.width=this.maxTexSize[0],n.height=this.maxTexSize[1];const i=this.threadDim=Array.from(this.output);for(;i.length<3;)i.push(1);const s=this.getVertexShader(arguments),a=r.createShader(r.VERTEX_SHADER);r.shaderSource(a,s),r.compileShader(a),this.vertShader=a;const o=this.getFragmentShader(arguments),u=r.createShader(r.FRAGMENT_SHADER);if(r.shaderSource(u,o),r.compileShader(u),this.fragShader=u,this.debug&&(console.log("GLSL Shader Output:"),console.log(o)),!r.getShaderParameter(a,r.COMPILE_STATUS))throw new Error("Error compiling vertex shader: "+r.getShaderInfoLog(a));if(!r.getShaderParameter(u,r.COMPILE_STATUS))throw new Error("Error compiling fragment shader: "+r.getShaderInfoLog(u));const l=this.program=r.createProgram();r.attachShader(l,a),r.attachShader(l,u),r.linkProgram(l),this.framebuffer=r.createFramebuffer(),this.framebuffer.width=t[0],this.framebuffer.height=t[1];const h=new Float32Array([-1,-1,1,-1,-1,1,1,1]),c=new Float32Array([0,0,1,0,0,1,1,1]),p=h.byteLength;let d=this.buffer;d?r.bindBuffer(r.ARRAY_BUFFER,d):(d=this.buffer=r.createBuffer(),r.bindBuffer(r.ARRAY_BUFFER,d),r.bufferData(r.ARRAY_BUFFER,h.byteLength+c.byteLength,r.STATIC_DRAW)),r.bufferSubData(r.ARRAY_BUFFER,0,h),r.bufferSubData(r.ARRAY_BUFFER,p,c);const m=r.getAttribLocation(this.program,"aPos");r.enableVertexAttribArray(m),r.vertexAttribPointer(m,2,r.FLOAT,!1,0,0);const g=r.getAttribLocation(this.program,"aTexCoord");r.enableVertexAttribArray(g),r.vertexAttribPointer(g,2,r.FLOAT,!1,0,p),r.bindFramebuffer(r.FRAMEBUFFER,this.framebuffer);let f=0;r.useProgram(this.program);for(let e in this.constants)this.kernelConstants[f++].updateValue(this.constants[e]);this.immutable||(this._setupOutputTexture(),null!==this.subKernels&&this.subKernels.length>0&&this._setupSubOutputTextures())}translateSource(){const e=i.fromKernel(this,s,{fixIntegerDivisionAccuracy:this.fixIntegerDivisionAccuracy});if(this.translatedSource=e.getPrototypeString("kernel"),this.graphical||this.returnType||(this.returnType=e.getKernelResultType()),this.subKernels&&this.subKernels.length>0)for(let t=0;t<this.subKernels.length;t++){const r=this.subKernels[t];r.returnType||(r.returnType=e.getSubKernelResultType(t))}}run(){const{kernelArguments:e,forceUploadKernelConstants:t}=this,r=this.texSize,n=this.context;n.useProgram(this.program),n.scissor(0,0,r[0],r[1]),this.dynamicOutput&&(this.setUniform3iv("uOutputDim",new Int32Array(this.threadDim)),this.setUniform2iv("uTexSize",r)),this.setUniform2f("ratio",r[0]/this.maxTexSize[0],r[1]/this.maxTexSize[1]),this.switchingKernels=!1;for(let e=0;e<t.length;e++){const r=t[e];if(r.updateValue(this.constants[r.name]),this.switchingKernels)return}for(let t=0;t<e.length;t++)if(e[t].updateValue(arguments[t]),this.switchingKernels)return;if(this.plugins)for(let e=0;e<this.plugins.length;e++){const t=this.plugins[e];t.onBeforeRun&&t.onBeforeRun(this)}if(this.graphical)return this.pipeline?(n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer),this.outputTexture&&!this.immutable||this._setupOutputTexture(),n.drawArrays(n.TRIANGLE_STRIP,0,4),new this.TextureConstructor({texture:this.outputTexture,size:r,dimensions:this.threadDim,output:this.output,context:this.context})):(n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),void n.drawArrays(n.TRIANGLE_STRIP,0,4));n.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer),this.immutable&&this._setupOutputTexture(),null!==this.subKernels&&(this.immutable&&this._setupSubOutputTextures(),this.extensions.WEBGL_draw_buffers.drawBuffersWEBGL(this.drawBuffersMap)),n.drawArrays(n.TRIANGLE_STRIP,0,4)}getOutputTexture(){return this.outputTexture}_setupOutputTexture(){const e=this.context,t=this.texSize,r=this.outputTexture=this.context.createTexture();if(e.activeTexture(e.TEXTURE0+this.constantTextureCount+this.argumentTextureCount),e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),"single"===this.precision)if(this.pipeline)switch(this.returnType){case"Number":case"Float":case"Integer":this.optimizeFloatMemory,e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t[0],t[1],0,e.RGBA,e.FLOAT,null);break;case"Array(2)":case"Array(3)":case"Array(4)":e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t[0],t[1],0,e.RGBA,e.FLOAT,null);break;default:if(!this.graphical)throw new Error("Unhandled return type")}else e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t[0],t[1],0,e.RGBA,e.FLOAT,null);else e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t[0],t[1],0,e.RGBA,e.UNSIGNED_BYTE,null);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0)}_setupSubOutputTextures(){const e=this.context,t=this.texSize;this.drawBuffersMap=[e.COLOR_ATTACHMENT0],this.subKernelOutputTextures=[];for(let r=0;r<this.subKernels.length;r++){const n=this.context.createTexture();this.subKernelOutputTextures.push(n),this.drawBuffersMap.push(e.COLOR_ATTACHMENT0+r+1),e.activeTexture(e.TEXTURE0+this.constantTextureCount+this.argumentTextureCount+r),e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),"single"===this.precision?e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t[0],t[1],0,e.RGBA,e.FLOAT,null):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t[0],t[1],0,e.RGBA,e.UNSIGNED_BYTE,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+r+1,e.TEXTURE_2D,n,0)}}getTextureCache(e){return this.textureCache.hasOwnProperty(e)?this.textureCache[e]:this.textureCache[e]=this.context.createTexture()}detachTextureCache(e){delete this.textureCache[e]}setUniform1f(e,t){if(this.uniform1fCache.hasOwnProperty(e)&&t===this.uniform1fCache[e])return;this.uniform1fCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform1f(r,t)}setUniform1i(e,t){if(this.uniform1iCache.hasOwnProperty(e)&&t===this.uniform1iCache[e])return;this.uniform1iCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform1i(r,t)}setUniform2f(e,t,r){if(this.uniform2fCache.hasOwnProperty(e)){const n=this.uniform2fCache[e];if(t===n[0]&&r===n[1])return}this.uniform2fCache[e]=[t,r];const n=this.getUniformLocation(e);this.context.uniform2f(n,t,r)}setUniform2fv(e,t){if(this.uniform2fvCache.hasOwnProperty(e)){const r=this.uniform2fvCache[e];if(t[0]===r[0]&&t[1]===r[1])return}this.uniform2fvCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform2fv(r,t)}setUniform2iv(e,t){if(this.uniform2ivCache.hasOwnProperty(e)){const r=this.uniform2ivCache[e];if(t[0]===r[0]&&t[1]===r[1])return}this.uniform2ivCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform2iv(r,t)}setUniform3fv(e,t){if(this.uniform3fvCache.hasOwnProperty(e)){const r=this.uniform3fvCache[e];if(t[0]===r[0]&&t[1]===r[1]&&t[2]===r[2])return}this.uniform3fvCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform3fv(r,t)}setUniform3iv(e,t){if(this.uniform3ivCache.hasOwnProperty(e)){const r=this.uniform3ivCache[e];if(t[0]===r[0]&&t[1]===r[1]&&t[2]===r[2])return}this.uniform3ivCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform3iv(r,t)}setUniform3fv(e,t){if(this.uniform3fvCache.hasOwnProperty(e)){const r=this.uniform3fvCache[e];if(t[0]===r[0]&&t[1]===r[1]&&t[2]===r[2])return}this.uniform3fvCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform3fv(r,t)}setUniform4iv(e,t){if(this.uniform4ivCache.hasOwnProperty(e)){const r=this.uniform4ivCache[e];if(t[0]===r[0]&&t[1]===r[1]&&t[2]===r[2]&&t[3]===r[3])return}this.uniform4ivCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform4iv(r,t)}setUniform4fv(e,t){if(this.uniform4fvCache.hasOwnProperty(e)){const r=this.uniform4fvCache[e];if(t[0]===r[0]&&t[1]===r[1]&&t[2]===r[2]&&t[3]===r[3])return}this.uniform4fvCache[e]=t;const r=this.getUniformLocation(e);this.context.uniform4fv(r,t)}getUniformLocation(e){return this.programUniformLocationCache.hasOwnProperty(e)?this.programUniformLocationCache[e]:this.programUniformLocationCache[e]=this.context.getUniformLocation(this.program,e)}_getFragShaderArtifactMap(e){return{HEADER:this._getHeaderString(),LOOP_MAX:this._getLoopMaxString(),PLUGINS:this._getPluginsString(),CONSTANTS:this._getConstantsString(),DECODE32_ENDIANNESS:this._getDecode32EndiannessString(),ENCODE32_ENDIANNESS:this._getEncode32EndiannessString(),DIVIDE_WITH_INTEGER_CHECK:this._getDivideWithIntegerCheckString(),INJECTED_NATIVE:this._getInjectedNative(),MAIN_CONSTANTS:this._getMainConstantsString(),MAIN_ARGUMENTS:this._getMainArgumentsString(e),KERNEL:this.getKernelString(),MAIN_RESULT:this.getMainResultString(),FLOAT_TACTIC_DECLARATION:this.getFloatTacticDeclaration(),INT_TACTIC_DECLARATION:this.getIntTacticDeclaration(),SAMPLER_2D_TACTIC_DECLARATION:this.getSampler2DTacticDeclaration(),SAMPLER_2D_ARRAY_TACTIC_DECLARATION:this.getSampler2DArrayTacticDeclaration()}}_getVertShaderArtifactMap(e){return{FLOAT_TACTIC_DECLARATION:this.getFloatTacticDeclaration(),INT_TACTIC_DECLARATION:this.getIntTacticDeclaration(),SAMPLER_2D_TACTIC_DECLARATION:this.getSampler2DTacticDeclaration(),SAMPLER_2D_ARRAY_TACTIC_DECLARATION:this.getSampler2DArrayTacticDeclaration()}}_getHeaderString(){return null!==this.subKernels?"#extension GL_EXT_draw_buffers : require\n":""}_getLoopMaxString(){return this.loopMaxIterations?` ${parseInt(this.loopMaxIterations)};\n`:" 1000;\n"}_getPluginsString(){return this.plugins?this.plugins.map(e=>e.source&&this.source.match(e.functionMatch)?e.source:"").join("\n"):"\n"}_getConstantsString(){const e=[],{threadDim:t,texSize:r}=this;return this.dynamicOutput?e.push("uniform ivec3 uOutputDim","uniform ivec2 uTexSize"):e.push(`ivec3 uOutputDim = ivec3(${t[0]}, ${t[1]}, ${t[2]})`,`ivec2 uTexSize = ivec2(${r[0]}, ${r[1]})`),a.linesToString(e)}_getTextureCoordinate(){const e=this.subKernels;return null===e||e.length<1?"varying vec2 vTexCoord;\n":"out vec2 vTexCoord;\n"}_getDecode32EndiannessString(){return"LE"===this.endianness?"":" texel.rgba = texel.abgr;\n"}_getEncode32EndiannessString(){return"LE"===this.endianness?"":" texel.rgba = texel.abgr;\n"}_getDivideWithIntegerCheckString(){return this.fixIntegerDivisionAccuracy?"float div_with_int_check(float x, float y) {\n if (floor(x) == x && floor(y) == y && integerMod(x, y) == 0.0) {\n return float(int(x)/int(y));\n }\n return x / y;\n}":""}_getMainArgumentsString(e){const t=[],{argumentNames:r}=this;for(let n=0;n<r.length;n++)t.push(this.kernelArguments[n].getSource(e[n]));return t.join("")}_getInjectedNative(){return this.injectedNative||""}_getMainConstantsString(){const e=[],{constants:t}=this;if(t){let r=0;for(const n in t)e.push(this.kernelConstants[r++].getSource(this.constants[n]))}return e.join("")}getKernelString(){let e;switch(this.returnType){case"Array(2)":e="vec2 kernelResult";break;case"Array(3)":e="vec3 kernelResult";break;case"Array(4)":e="vec4 kernelResult";break;case"LiteralInteger":case"Float":case"Number":case"Integer":e="float kernelResult";break;default:if(!this.graphical)throw new Error(`unrecognized output type "${this.returnType}"`);e="float kernelResult"}const t=[],r=this.subKernels;if(null!==r)switch(t.push(e),this.returnType){case"Number":case"Float":case"Integer":for(let e=0;e<r.length;e++){const n=r[e];t.push("Integer"===n.returnType?`int subKernelResult_${n.name} = 0`:`float subKernelResult_${n.name} = 0.0`)}break;case"Array(2)":for(let e=0;e<r.length;e++)t.push(`vec2 subKernelResult_${r[e].name}`);break;case"Array(3)":for(let e=0;e<r.length;e++)t.push(`vec3 subKernelResult_${r[e].name}`);break;case"Array(4)":for(let e=0;e<r.length;e++)t.push(`vec4 subKernelResult_${r[e].name}`)}else t.push(e);return a.linesToString(t)+this.translatedSource}getMainResultGraphical(){return a.linesToString([" threadId = indexTo3D(index, uOutputDim)"," kernel()"," gl_FragColor = actualColor"])}getMainResultPackedPixels(){switch(this.returnType){case"LiteralInteger":case"Number":case"Integer":case"Float":return this.getMainResultKernelPackedPixels()+this.getMainResultSubKernelPackedPixels();default:throw new Error(`packed output only usable with Numbers, "${this.returnType}" specified`)}}getMainResultKernelPackedPixels(){return a.linesToString([" threadId = indexTo3D(index, uOutputDim)"," kernel()",` gl_FragData[0] = ${this.useLegacyEncoder?"legacyEncode32":"encode32"}(kernelResult)`])}getMainResultSubKernelPackedPixels(){const e=[];if(!this.subKernels)return"";for(let t=0;t<this.subKernels.length;t++)"Integer"===this.subKernels[t].returnType?e.push(` gl_FragData[${t+1}] = ${this.useLegacyEncoder?"legacyEncode32":"encode32"}(float(subKernelResult_${this.subKernels[t].name}))`):e.push(` gl_FragData[${t+1}] = ${this.useLegacyEncoder?"legacyEncode32":"encode32"}(subKernelResult_${this.subKernels[t].name})`);return a.linesToString(e)}getMainResultMemoryOptimizedFloats(){const e=[" index *= 4"];switch(this.returnType){case"Number":case"Integer":case"Float":const t=["r","g","b","a"];for(let r=0;r<t.length;r++){const n=t[r];this.getMainResultKernelMemoryOptimizedFloats(e,n),this.getMainResultSubKernelMemoryOptimizedFloats(e,n),r+1<t.length&&e.push(" index += 1")}break;default:throw new Error(`optimized output only usable with Numbers, ${this.returnType} specified`)}return a.linesToString(e)}getMainResultKernelMemoryOptimizedFloats(e,t){e.push(" threadId = indexTo3D(index, uOutputDim)"," kernel()",` gl_FragData[0].${t} = kernelResult`)}getMainResultSubKernelMemoryOptimizedFloats(e,t){if(!this.subKernels)return e;for(let r=0;r<this.subKernels.length;r++)"Integer"===this.subKernels[r].returnType?e.push(` gl_FragData[${r+1}].${t} = float(subKernelResult_${this.subKernels[r].name})`):e.push(` gl_FragData[${r+1}].${t} = subKernelResult_${this.subKernels[r].name}`)}getMainResultKernelNumberTexture(){return[" threadId = indexTo3D(index, uOutputDim)"," kernel()"," gl_FragData[0][0] = kernelResult"]}getMainResultSubKernelNumberTexture(){const e=[];if(!this.subKernels)return e;for(let t=0;t<this.subKernels.length;++t){const r=this.subKernels[t];"Integer"===r.returnType?e.push(` gl_FragData[${t+1}][0] = float(subKernelResult_${r.name})`):e.push(` gl_FragData[${t+1}][0] = subKernelResult_${r.name}`)}return e}getMainResultKernelArray2Texture(){return[" threadId = indexTo3D(index, uOutputDim)"," kernel()"," gl_FragData[0][0] = kernelResult[0]"," gl_FragData[0][1] = kernelResult[1]"]}getMainResultSubKernelArray2Texture(){const e=[];if(!this.subKernels)return e;for(let t=0;t<this.subKernels.length;++t)e.push(` gl_FragData[${t+1}][0] = subKernelResult_${this.subKernels[t].name}[0]`,` gl_FragData[${t+1}][1] = subKernelResult_${this.subKernels[t].name}[1]`);return e}getMainResultKernelArray3Texture(){return[" threadId = indexTo3D(index, uOutputDim)"," kernel()"," gl_FragData[0][0] = kernelResult[0]"," gl_FragData[0][1] = kernelResult[1]"," gl_FragData[0][2] = kernelResult[2]"]}getMainResultSubKernelArray3Texture(){const e=[];if(!this.subKernels)return e;for(let t=0;t<this.subKernels.length;++t)e.push(` gl_FragData[${t+1}][0] = subKernelResult_${this.subKernels[t].name}[0]`,` gl_FragData[${t+1}][1] = subKernelResult_${this.subKernels[t].name}[1]`,` gl_FragData[${t+1}][2] = subKernelResult_${this.subKernels[t].name}[2]`);return e}getMainResultKernelArray4Texture(){return[" threadId = indexTo3D(index, uOutputDim)"," kernel()"," gl_FragData[0] = kernelResult"]}getMainResultSubKernelArray4Texture(){const e=[];if(!this.subKernels)return e;switch(this.returnType){case"Number":case"Float":case"Integer":for(let t=0;t<this.subKernels.length;++t)"Integer"===this.subKernels[t].returnType?e.push(` gl_FragData[${t+1}] = float(subKernelResult_${this.subKernels[t].name})`):e.push(` gl_FragData[${t+1}] = subKernelResult_${this.subKernels[t].name}`);break;case"Array(2)":for(let t=0;t<this.subKernels.length;++t)e.push(` gl_FragData[${t+1}][0] = subKernelResult_${this.subKernels[t].name}[0]`,` gl_FragData[${t+1}][1] = subKernelResult_${this.subKernels[t].name}[1]`);break;case"Array(3)":for(let t=0;t<this.subKernels.length;++t)e.push(` gl_FragData[${t+1}][0] = subKernelResult_${this.subKernels[t].name}[0]`,` gl_FragData[${t+1}][1] = subKernelResult_${this.subKernels[t].name}[1]`,` gl_FragData[${t+1}][2] = subKernelResult_${this.subKernels[t].name}[2]`);break;case"Array(4)":for(let t=0;t<this.subKernels.length;++t)e.push(` gl_FragData[${t+1}][0] = subKernelResult_${this.subKernels[t].name}[0]`,` gl_FragData[${t+1}][1] = subKernelResult_${this.subKernels[t].name}[1]`,` gl_FragData[${t+1}][2] = subKernelResult_${this.subKernels[t].name}[2]`,` gl_FragData[${t+1}][3] = subKernelResult_${this.subKernels[t].name}[3]`)}return e}replaceArtifacts(e,t){return e.replace(/[ ]*__([A-Z]+[0-9]*([_]?[A-Z]*[0-9]?)*)__;\n/g,(e,r)=>{if(t.hasOwnProperty(r))return t[r];throw`unhandled artifact ${r}`})}getFragmentShader(e){return null!==this.compiledFragmentShader?this.compiledFragmentShader:this.compiledFragmentShader=this.replaceArtifacts(this.constructor.fragmentShader,this._getFragShaderArtifactMap(e))}getVertexShader(e){return null!==this.compiledVertexShader?this.compiledVertexShader:this.compiledVertexShader=this.replaceArtifacts(this.constructor.vertexShader,this._getVertShaderArtifactMap(e))}toString(){const e=a.linesToString(["const gl = context"]);return h(this.constructor,arguments,this,e)}destroy(e){this.outputTexture&&this.context.deleteTexture(this.outputTexture),this.buffer&&this.context.deleteBuffer(this.buffer),this.framebuffer&&this.context.deleteFramebuffer(this.framebuffer),this.vertShader&&this.context.deleteShader(this.vertShader),this.fragShader&&this.context.deleteShader(this.fragShader),this.program&&this.context.deleteProgram(this.program);const t=Object.keys(this.textureCache);for(let e=0;e<t.length;e++){const r=t[e];this.context.deleteTexture(this.textureCache[r])}if(this.subKernelOutputTextures)for(let e=0;e<this.subKernelOutputTextures.length;e++)this.context.deleteTexture(this.subKernelOutputTextures[e]);if(e){const e=y.indexOf(this.canvas);e>=0&&(y[e]=null,T[e]=null)}this.destroyExtensions(),delete this.context,delete this.canvas}destroyExtensions(){this.extensions.OES_texture_float=null,this.extensions.OES_texture_float_linear=null,this.extensions.OES_element_index_uint=null,this.extensions.WEBGL_draw_buffers=null}static destroyContext(e){const t=e.getExtension("WEBGL_lose_context");t&&t.loseContext()}toJSON(){const e=super.toJSON();return e.functionNodes=i.fromKernel(this,s).toJSON(),e}}}},{"../../plugins/triangle-noise":110,"../../utils":112,"../function-builder":9,"../gl/kernel":13,"../gl/kernel-string":12,"./fragment-shader":36,"./function-node":37,"./kernel-value-maps":38,"./vertex-shader":69}],69:[function(e,t,r){t.exports={vertexShader:"__FLOAT_TACTIC_DECLARATION__;\n__INT_TACTIC_DECLARATION__;\n__SAMPLER_2D_TACTIC_DECLARATION__;\n\nattribute vec2 aPos;\nattribute vec2 aTexCoord;\n\nvarying vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}"}},{}],70:[function(e,t,r){t.exports={fragmentShader:"#version 300 es\n__HEADER__;\n__FLOAT_TACTIC_DECLARATION__;\n__INT_TACTIC_DECLARATION__;\n__SAMPLER_2D_TACTIC_DECLARATION__;\n__SAMPLER_2D_ARRAY_TACTIC_DECLARATION__;\n\nconst int LOOP_MAX = __LOOP_MAX__;\n\n__PLUGINS__;\n__CONSTANTS__;\n\nin vec2 vTexCoord;\n\nconst int BIT_COUNT = 32;\nint modi(int x, int y) {\n return x - y * (x / y);\n}\n\nint bitwiseOr(int a, int b) {\n int result = 0;\n int n = 1;\n \n for (int i = 0; i < BIT_COUNT; i++) {\n if ((modi(a, 2) == 1) || (modi(b, 2) == 1)) {\n result += n;\n }\n a = a / 2;\n b = b / 2;\n n = n * 2;\n if(!(a > 0 || b > 0)) {\n break;\n }\n }\n return result;\n}\nint bitwiseXOR(int a, int b) {\n int result = 0;\n int n = 1;\n \n for (int i = 0; i < BIT_COUNT; i++) {\n if ((modi(a, 2) == 1) != (modi(b, 2) == 1)) {\n result += n;\n }\n a = a / 2;\n b = b / 2;\n n = n * 2;\n if(!(a > 0 || b > 0)) {\n break;\n }\n }\n return result;\n}\nint bitwiseAnd(int a, int b) {\n int result = 0;\n int n = 1;\n for (int i = 0; i < BIT_COUNT; i++) {\n if ((modi(a, 2) == 1) && (modi(b, 2) == 1)) {\n result += n;\n }\n a = a / 2;\n b = b / 2;\n n = n * 2;\n if(!(a > 0 && b > 0)) {\n break;\n }\n }\n return result;\n}\nint bitwiseNot(int a) {\n int result = 0;\n int n = 1;\n \n for (int i = 0; i < BIT_COUNT; i++) {\n if (modi(a, 2) == 0) {\n result += n; \n }\n a = a / 2;\n n = n * 2;\n }\n return result;\n}\nint bitwiseZeroFillLeftShift(int n, int shift) {\n int maxBytes = BIT_COUNT;\n for (int i = 0; i < BIT_COUNT; i++) {\n if (maxBytes >= n) {\n break;\n }\n maxBytes *= 2;\n }\n for (int i = 0; i < BIT_COUNT; i++) {\n if (i >= shift) {\n break;\n }\n n *= 2;\n }\n\n int result = 0;\n int byteVal = 1;\n for (int i = 0; i < BIT_COUNT; i++) {\n if (i >= maxBytes) break;\n if (modi(n, 2) > 0) { result += byteVal; }\n n = int(n / 2);\n byteVal *= 2;\n }\n return result;\n}\n\nint bitwiseSignedRightShift(int num, int shifts) {\n return int(floor(float(num) / pow(2.0, float(shifts))));\n}\n\nint bitwiseZeroFillRightShift(int n, int shift) {\n int maxBytes = BIT_COUNT;\n for (int i = 0; i < BIT_COUNT; i++) {\n if (maxBytes >= n) {\n break;\n }\n maxBytes *= 2;\n }\n for (int i = 0; i < BIT_COUNT; i++) {\n if (i >= shift) {\n break;\n }\n n /= 2;\n }\n int result = 0;\n int byteVal = 1;\n for (int i = 0; i < BIT_COUNT; i++) {\n if (i >= maxBytes) break;\n if (modi(n, 2) > 0) { result += byteVal; }\n n = int(n / 2);\n byteVal *= 2;\n }\n return result;\n}\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nfloat integerMod(float x, float y) {\n float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nint integerMod(int x, int y) {\n return x - (y * int(x/y));\n}\n\n__DIVIDE_WITH_INTEGER_CHECK__;\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nfloat decode32(vec4 texel) {\n __DECODE32_ENDIANNESS__;\n texel *= 255.0;\n vec2 gte128;\n gte128.x = texel.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = texel.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * texel.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n texel.b = texel.b - 128.0 * gte128.x;\n res = dot(texel, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nfloat decode16(vec4 texel, int index) {\n int channel = integerMod(index, 2);\n return texel[channel*2] * 255.0 + texel[channel*2 + 1] * 65280.0;\n}\n\nfloat decode8(vec4 texel, int index) {\n int channel = integerMod(index, 4);\n return texel[channel] * 255.0;\n}\n\nvec4 legacyEncode32(float f) {\n float F = abs(f);\n float sign = f < 0.0 ? 1.0 : 0.0;\n float exponent = floor(log2(F));\n float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 texel = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n texel.rg = integerMod(texel.rg, 256.0);\n texel.b = integerMod(texel.b, 128.0);\n texel.a = exponent*0.5 + 63.5;\n texel.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n texel = floor(texel);\n texel *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return texel;\n}\n\n// https://github.com/gpujs/gpu.js/wiki/Encoder-details\nvec4 encode32(float value) {\n if (value == 0.0) return vec4(0, 0, 0, 0);\n\n float exponent;\n float mantissa;\n vec4 result;\n float sgn;\n\n sgn = step(0.0, -value);\n value = abs(value);\n\n exponent = floor(log2(value));\n\n mantissa = value*pow(2.0, -exponent)-1.0;\n exponent = exponent+127.0;\n result = vec4(0,0,0,0);\n\n result.a = floor(exponent/2.0);\n exponent = exponent - result.a*2.0;\n result.a = result.a + 128.0*sgn;\n\n result.b = floor(mantissa * 128.0);\n mantissa = mantissa - result.b / 128.0;\n result.b = result.b + exponent*128.0;\n\n result.g = floor(mantissa*32768.0);\n mantissa = mantissa - result.g/32768.0;\n\n result.r = floor(mantissa*8388608.0);\n return result/255.0;\n}\n// Dragons end here\n\nint index;\nivec3 threadId;\n\nivec3 indexTo3D(int idx, ivec3 texDim) {\n int z = int(idx / (texDim.x * texDim.y));\n idx -= z * int(texDim.x * texDim.y);\n int y = int(idx / texDim.x);\n int x = int(integerMod(idx, texDim.x));\n return ivec3(x, y, z);\n}\n\nfloat get32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture(tex, st / vec2(texSize));\n return decode32(texel);\n}\n\nfloat get16(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + (texDim.x * (y + (texDim.y * z)));\n int w = texSize.x * 2;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture(tex, st / vec2(texSize.x * 2, texSize.y));\n return decode16(texel, index);\n}\n\nfloat get8(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + (texDim.x * (y + (texDim.y * z)));\n int w = texSize.x * 4;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture(tex, st / vec2(texSize.x * 4, texSize.y));\n return decode8(texel, index);\n}\n\nfloat getMemoryOptimized32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + (texDim.x * (y + (texDim.y * z)));\n int channel = integerMod(index, 4);\n index = index / 4;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n index = index / 4;\n vec4 texel = texture(tex, st / vec2(texSize));\n return texel[channel];\n}\n\nvec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n return texture(tex, st / vec2(texSize));\n}\n\nvec4 getImage3D(sampler2DArray tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n return texture(tex, vec3(st / vec2(texSize), z));\n}\n\nfloat getFloatFromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n vec4 result = getImage2D(tex, texSize, texDim, z, y, x);\n return result[0];\n}\n\nvec2 getVec2FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n vec4 result = getImage2D(tex, texSize, texDim, z, y, x);\n return vec2(result[0], result[1]);\n}\n\nvec2 getMemoryOptimizedVec2(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int channel = integerMod(index, 2);\n index = index / 2;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture(tex, st / vec2(texSize));\n if (channel == 0) return vec2(texel.r, texel.g);\n if (channel == 1) return vec2(texel.b, texel.a);\n return vec2(0.0, 0.0);\n}\n\nvec3 getVec3FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n vec4 result = getImage2D(tex, texSize, texDim, z, y, x);\n return vec3(result[0], result[1], result[2]);\n}\n\nvec3 getMemoryOptimizedVec3(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int fieldIndex = 3 * (x + texDim.x * (y + texDim.y * z));\n int vectorIndex = fieldIndex / 4;\n int vectorOffset = fieldIndex - vectorIndex * 4;\n int readY = vectorIndex / texSize.x;\n int readX = vectorIndex - readY * texSize.x;\n vec4 tex1 = texture(tex, (vec2(readX, readY) + 0.5) / vec2(texSize));\n\n if (vectorOffset == 0) {\n return tex1.xyz;\n } else if (vectorOffset == 1) {\n return tex1.yzw;\n } else {\n readX++;\n if (readX >= texSize.x) {\n readX = 0;\n readY++;\n }\n vec4 tex2 = texture(tex, vec2(readX, readY) / vec2(texSize));\n if (vectorOffset == 2) {\n return vec3(tex1.z, tex1.w, tex2.x);\n } else {\n return vec3(tex1.w, tex2.x, tex2.y);\n }\n }\n}\n\nvec4 getVec4FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n return getImage2D(tex, texSize, texDim, z, y, x);\n}\n\nvec4 getMemoryOptimizedVec4(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n int index = x + texDim.x * (y + texDim.y * z);\n int channel = integerMod(index, 2);\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n vec4 texel = texture(tex, st / vec2(texSize));\n return vec4(texel.r, texel.g, texel.b, texel.a);\n}\n\nvec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\n__INJECTED_NATIVE__;\n__MAIN_CONSTANTS__;\n__MAIN_ARGUMENTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = int(vTexCoord.s * float(uTexSize.x)) + int(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}"}},{}],71:[function(e,t,r){const{WebGLFunctionNode:n}=e("../web-gl/function-node");t.exports={WebGL2FunctionNode:class extends n{astIdentifierExpression(e,t){if("Identifier"!==e.type)throw this.astErrorOutput("IdentifierExpression - not an Identifier",e);const r=this.getType(e);return"Infinity"===e.name?t.push("intBitsToFloat(2139095039)"):"Boolean"===r&&this.argumentNames.indexOf(e.name)>-1?t.push(`bool(user_${e.name})`):t.push(`user_${e.name}`),t}}}},{"../web-gl/function-node":37}],72:[function(e,t,r){const{WebGL2KernelValueBoolean:n}=e("./kernel-value/boolean"),{WebGL2KernelValueFloat:i}=e("./kernel-value/float"),{WebGL2KernelValueInteger:s}=e("./kernel-value/integer"),{WebGL2KernelValueHTMLImage:a}=e("./kernel-value/html-image"),{WebGL2KernelValueDynamicHTMLImage:o}=e("./kernel-value/dynamic-html-image"),{WebGL2KernelValueHTMLImageArray:u}=e("./kernel-value/html-image-array"),{WebGL2KernelValueDynamicHTMLImageArray:l}=e("./kernel-value/dynamic-html-image-array"),{WebGL2KernelValueHTMLVideo:h}=e("./kernel-value/html-video"),{WebGL2KernelValueDynamicHTMLVideo:c}=e("./kernel-value/dynamic-html-video"),{WebGL2KernelValueSingleInput:p}=e("./kernel-value/single-input"),{WebGL2KernelValueDynamicSingleInput:d}=e("./kernel-value/dynamic-single-input"),{WebGL2KernelValueUnsignedInput:m}=e("./kernel-value/unsigned-input"),{WebGL2KernelValueDynamicUnsignedInput:g}=e("./kernel-value/dynamic-unsigned-input"),{WebGL2KernelValueMemoryOptimizedNumberTexture:f}=e("./kernel-value/memory-optimized-number-texture"),{WebGL2KernelValueDynamicMemoryOptimizedNumberTexture:x}=e("./kernel-value/dynamic-memory-optimized-number-texture"),{WebGL2KernelValueNumberTexture:y}=e("./kernel-value/number-texture"),{WebGL2KernelValueDynamicNumberTexture:T}=e("./kernel-value/dynamic-number-texture"),{WebGL2KernelValueSingleArray:b}=e("./kernel-value/single-array"),{WebGL2KernelValueDynamicSingleArray:A}=e("./kernel-value/dynamic-single-array"),{WebGL2KernelValueSingleArray1DI:v}=e("./kernel-value/single-array1d-i"),{WebGL2KernelValueDynamicSingleArray1DI:S}=e("./kernel-value/dynamic-single-array1d-i"),{WebGL2KernelValueSingleArray2DI:E}=e("./kernel-value/single-array2d-i"),{WebGL2KernelValueDynamicSingleArray2DI:_}=e("./kernel-value/dynamic-single-array2d-i"),{WebGL2KernelValueSingleArray3DI:w}=e("./kernel-value/single-array3d-i"),{WebGL2KernelValueDynamicSingleArray3DI:k}=e("./kernel-value/dynamic-single-array3d-i"),{WebGL2KernelValueSingleArray2:D}=e("./kernel-value/single-array2"),{WebGL2KernelValueSingleArray3:I}=e("./kernel-value/single-array3"),{WebGL2KernelValueSingleArray4:R}=e("./kernel-value/single-array4"),{WebGL2KernelValueUnsignedArray:L}=e("./kernel-value/unsigned-array"),{WebGL2KernelValueDynamicUnsignedArray:$}=e("./kernel-value/dynamic-unsigned-array"),C={unsigned:{dynamic:{Boolean:n,Integer:s,Float:i,Array:$,"Array(2)":!1,"Array(3)":!1,"Array(4)":!1,"Array1D(2)":!1,"Array1D(3)":!1,"Array1D(4)":!1,"Array2D(2)":!1,"Array2D(3)":!1,"Array2D(4)":!1,"Array3D(2)":!1,"Array3D(3)":!1,"Array3D(4)":!1,Input:g,NumberTexture:T,"ArrayTexture(1)":T,"ArrayTexture(2)":T,"ArrayTexture(3)":T,"ArrayTexture(4)":T,MemoryOptimizedNumberTexture:x,HTMLImage:o,HTMLImageArray:l,HTMLVideo:c},static:{Boolean:n,Float:i,Integer:s,Array:L,"Array(2)":!1,"Array(3)":!1,"Array(4)":!1,"Array1D(2)":!1,"Array1D(3)":!1,"Array1D(4)":!1,"Array2D(2)":!1,"Array2D(3)":!1,"Array2D(4)":!1,"Array3D(2)":!1,"Array3D(3)":!1,"Array3D(4)":!1,Input:m,NumberTexture:y,"ArrayTexture(1)":y,"ArrayTexture(2)":y,"ArrayTexture(3)":y,"ArrayTexture(4)":y,MemoryOptimizedNumberTexture:x,HTMLImage:a,HTMLImageArray:u,HTMLVideo:h}},single:{dynamic:{Boolean:n,Integer:s,Float:i,Array:A,"Array(2)":D,"Array(3)":I,"Array(4)":R,"Array1D(2)":S,"Array1D(3)":S,"Array1D(4)":S,"Array2D(2)":_,"Array2D(3)":_,"Array2D(4)":_,"Array3D(2)":k,"Array3D(3)":k,"Array3D(4)":k,Input:d,NumberTexture:T,"ArrayTexture(1)":T,"ArrayTexture(2)":T,"ArrayTexture(3)":T,"ArrayTexture(4)":T,MemoryOptimizedNumberTexture:x,HTMLImage:o,HTMLImageArray:l,HTMLVideo:c},static:{Boolean:n,Float:i,Integer:s,Array:b,"Array(2)":D,"Array(3)":I,"Array(4)":R,"Array1D(2)":v,"Array1D(3)":v,"Array1D(4)":v,"Array2D(2)":E,"Array2D(3)":E,"Array2D(4)":E,"Array3D(2)":w,"Array3D(3)":w,"Array3D(4)":w,Input:p,NumberTexture:y,"ArrayTexture(1)":y,"ArrayTexture(2)":y,"ArrayTexture(3)":y,"ArrayTexture(4)":y,MemoryOptimizedNumberTexture:f,HTMLImage:a,HTMLImageArray:u,HTMLVideo:h}}};t.exports={kernelValueMaps:C,lookupKernelValueType:function(e,t,r,n){if(!e)throw new Error("type missing");if(!t)throw new Error("dynamic missing");if(!r)throw new Error("precision missing");n.type&&(e=n.type);const i=C[r][t];if(!1===i[e])return null;if(void 0===i[e])throw new Error(`Could not find a KernelValue for ${e}`);return i[e]}}},{"./kernel-value/boolean":73,"./kernel-value/dynamic-html-image":75,"./kernel-value/dynamic-html-image-array":74,"./kernel-value/dynamic-html-video":76,"./kernel-value/dynamic-memory-optimized-number-texture":77,"./kernel-value/dynamic-number-texture":78,"./kernel-value/dynamic-single-array":79,"./kernel-value/dynamic-single-array1d-i":80,"./kernel-value/dynamic-single-array2d-i":81,"./kernel-value/dynamic-single-array3d-i":82,"./kernel-value/dynamic-single-input":83,"./kernel-value/dynamic-unsigned-array":84,"./kernel-value/dynamic-unsigned-input":85,"./kernel-value/float":86,"./kernel-value/html-image":88,"./kernel-value/html-image-array":87,"./kernel-value/html-video":89,"./kernel-value/integer":90,"./kernel-value/memory-optimized-number-texture":91,"./kernel-value/number-texture":92,"./kernel-value/single-array":93,"./kernel-value/single-array1d-i":94,"./kernel-value/single-array2":95,"./kernel-value/single-array2d-i":96,"./kernel-value/single-array3":97,"./kernel-value/single-array3d-i":98,"./kernel-value/single-array4":99,"./kernel-value/single-input":100,"./kernel-value/unsigned-array":101,"./kernel-value/unsigned-input":102}],73:[function(e,t,r){const{WebGLKernelValueBoolean:n}=e("../../web-gl/kernel-value/boolean");t.exports={WebGL2KernelValueBoolean:class extends n{}}},{"../../web-gl/kernel-value/boolean":39}],74:[function(e,t,r){const{WebGL2KernelValueHTMLImageArray:n}=e("./html-image-array");t.exports={WebGL2KernelValueDynamicHTMLImageArray:class extends n{getSource(){const e=this.getVariablePrecisionString();return utils.linesToString([`uniform ${e} sampler2DArray ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}updateValue(e){const{width:t,height:r}=e[0];this.checkSize(t,r),this.dimensions=[t,r,e.length],this.textureSize=[t,r],this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"./html-image-array":87}],75:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueDynamicHTMLImage:i}=e("../../web-gl/kernel-value/dynamic-html-image");t.exports={WebGL2KernelValueDynamicHTMLImage:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/dynamic-html-image":40}],76:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGL2KernelValueDynamicHTMLImage:i}=e("./dynamic-html-image");t.exports={WebGL2KernelValueDynamicHTMLVideo:class extends i{}}},{"../../../utils":112,"./dynamic-html-image":75}],77:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueDynamicMemoryOptimizedNumberTexture:i}=e("../../web-gl/kernel-value/dynamic-memory-optimized-number-texture");t.exports={WebGL2KernelValueDynamicMemoryOptimizedNumberTexture:class extends i{getSource(){return n.linesToString([`uniform sampler2D ${this.id}`,`uniform ivec2 ${this.sizeId}`,`uniform ivec3 ${this.dimensionsId}`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/dynamic-memory-optimized-number-texture":42}],78:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueDynamicNumberTexture:i}=e("../../web-gl/kernel-value/dynamic-number-texture");t.exports={WebGL2KernelValueDynamicNumberTexture:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/dynamic-number-texture":43}],79:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGL2KernelValueSingleArray:i}=e("../../web-gl2/kernel-value/single-array");t.exports={WebGL2KernelValueDynamicSingleArray:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}updateValue(e){this.dimensions=n.getDimensions(e,!0),this.textureSize=n.getMemoryOptimizedFloatTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"../../web-gl2/kernel-value/single-array":93}],80:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGL2KernelValueSingleArray1DI:i}=e("../../web-gl2/kernel-value/single-array1d-i");t.exports={WebGL2KernelValueDynamicSingleArray1DI:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}updateValue(e){this.setShape(e),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"../../web-gl2/kernel-value/single-array1d-i":94}],81:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGL2KernelValueSingleArray2DI:i}=e("../../web-gl2/kernel-value/single-array2d-i");t.exports={WebGL2KernelValueDynamicSingleArray2DI:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}updateValue(e){this.setShape(e),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"../../web-gl2/kernel-value/single-array2d-i":96}],82:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGL2KernelValueSingleArray3DI:i}=e("../../web-gl2/kernel-value/single-array3d-i");t.exports={WebGL2KernelValueDynamicSingleArray3DI:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}updateValue(e){this.setShape(e),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"../../web-gl2/kernel-value/single-array3d-i":98}],83:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGL2KernelValueSingleInput:i}=e("../../web-gl2/kernel-value/single-input");t.exports={WebGL2KernelValueDynamicSingleInput:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}updateValue(e){let[t,r,i]=e.size;this.dimensions=new Int32Array([t||1,r||1,i||1]),this.textureSize=n.getMemoryOptimizedFloatTextureSize(this.dimensions,this.bitRatio),this.uploadArrayLength=this.textureSize[0]*this.textureSize[1]*this.bitRatio,this.checkSize(this.textureSize[0]*this.bitRatio,this.textureSize[1]*this.bitRatio),this.uploadValue=new Float32Array(this.uploadArrayLength),this.kernel.setUniform3iv(this.dimensionsId,this.dimensions),this.kernel.setUniform2iv(this.sizeId,this.textureSize),super.updateValue(e)}}}},{"../../../utils":112,"../../web-gl2/kernel-value/single-input":100}],84:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueDynamicUnsignedArray:i}=e("../../web-gl/kernel-value/dynamic-unsigned-array");t.exports={WebGL2KernelValueDynamicUnsignedArray:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/dynamic-unsigned-array":49}],85:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueDynamicUnsignedInput:i}=e("../../web-gl/kernel-value/dynamic-unsigned-input");t.exports={WebGL2KernelValueDynamicUnsignedInput:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`uniform ${e} ivec2 ${this.sizeId}`,`uniform ${e} ivec3 ${this.dimensionsId}`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/dynamic-unsigned-input":50}],86:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueFloat:i}=e("../../web-gl/kernel-value/float");t.exports={WebGL2KernelValueFloat:class extends i{}}},{"../../../utils":112,"../../web-gl/kernel-value/float":51}],87:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValue:i}=e("../../web-gl/kernel-value/index");t.exports={WebGL2KernelValueHTMLImageArray:class extends i{constructor(e,t){super(e,t),this.checkSize(e[0].width,e[0].height),this.requestTexture(),this.dimensions=[e[0].width,e[0].height,e.length],this.textureSize=[e[0].width,e[0].height]}getStringValueHandler(){return`const uploadValue_${this.name} = ${this.varName};\n`}getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2DArray ${this.id}`,`${e} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`${e} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){const{context:t}=this;t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D_ARRAY,this.texture),t.texParameteri(t.TEXTURE_2D_ARRAY,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D_ARRAY,t.TEXTURE_MIN_FILTER,t.NEAREST),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!0),t.texImage3D(t.TEXTURE_2D_ARRAY,0,t.RGBA,e[0].width,e[0].height,e.length,0,t.RGBA,t.UNSIGNED_BYTE,null);for(let r=0;r<e.length;r++){const n=0,i=0,s=1;t.texSubImage3D(t.TEXTURE_2D_ARRAY,0,n,i,r,e[r].width,e[r].height,s,t.RGBA,t.UNSIGNED_BYTE,this.uploadValue=e[r])}this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"../../web-gl/kernel-value/index":54}],88:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueHTMLImage:i}=e("../../web-gl/kernel-value/html-image");t.exports={WebGL2KernelValueHTMLImage:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`${e} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`${e} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/html-image":52}],89:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGL2KernelValueHTMLImage:i}=e("./html-image");t.exports={WebGL2KernelValueHTMLVideo:class extends i{}}},{"../../../utils":112,"./html-image":88}],90:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueInteger:i}=e("../../web-gl/kernel-value/integer");t.exports={WebGL2KernelValueInteger:class extends i{getSource(e){const t=this.getVariablePrecisionString();return"constants"===this.origin?`const ${t} int ${this.id} = ${parseInt(e)};\n`:`uniform ${t} int ${this.id};\n`}updateValue(e){"constants"!==this.origin&&this.kernel.setUniform1i(this.id,this.uploadValue=e)}}}},{"../../../utils":112,"../../web-gl/kernel-value/integer":55}],91:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueMemoryOptimizedNumberTexture:i}=e("../../web-gl/kernel-value/memory-optimized-number-texture");t.exports={WebGL2KernelValueMemoryOptimizedNumberTexture:class extends i{getSource(){const{id:e,sizeId:t,textureSize:r,dimensionsId:i,dimensions:s}=this,a=this.getVariablePrecisionString();return n.linesToString([`uniform sampler2D ${e}`,`${a} ivec2 ${t} = ivec2(${r[0]}, ${r[1]})`,`${a} ivec3 ${i} = ivec3(${s[0]}, ${s[1]}, ${s[2]})`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/memory-optimized-number-texture":56}],92:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueNumberTexture:i}=e("../../web-gl/kernel-value/number-texture");t.exports={WebGL2KernelValueNumberTexture:class extends i{getSource(){const{id:e,sizeId:t,textureSize:r,dimensionsId:i,dimensions:s}=this,a=this.getVariablePrecisionString();return n.linesToString([`uniform ${a} sampler2D ${e}`,`${a} ivec2 ${t} = ivec2(${r[0]}, ${r[1]})`,`${a} ivec3 ${i} = ivec3(${s[0]}, ${s[1]}, ${s[2]})`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/number-texture":57}],93:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleArray:i}=e("../../web-gl/kernel-value/single-array");t.exports={WebGL2KernelValueSingleArray:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`${e} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`${e} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flattenTo(e,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"../../web-gl/kernel-value/single-array":58}],94:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleArray1DI:i}=e("../../web-gl/kernel-value/single-array1d-i");t.exports={WebGL2KernelValueSingleArray1DI:class extends i{updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flattenTo(e,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"../../web-gl/kernel-value/single-array1d-i":59}],95:[function(e,t,r){const{WebGLKernelValueSingleArray2:n}=e("../../web-gl/kernel-value/single-array2");t.exports={WebGL2KernelValueSingleArray2:class extends n{}}},{"../../web-gl/kernel-value/single-array2":60}],96:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleArray2DI:i}=e("../../web-gl/kernel-value/single-array2d-i");t.exports={WebGL2KernelValueSingleArray2DI:class extends i{updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flattenTo(e,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"../../web-gl/kernel-value/single-array2d-i":61}],97:[function(e,t,r){const{WebGLKernelValueSingleArray3:n}=e("../../web-gl/kernel-value/single-array3");t.exports={WebGL2KernelValueSingleArray3:class extends n{}}},{"../../web-gl/kernel-value/single-array3":62}],98:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleArray3DI:i}=e("../../web-gl/kernel-value/single-array3d-i");t.exports={WebGL2KernelValueSingleArray3DI:class extends i{updateValue(e){if(e.constructor!==this.initialValueConstructor)return void this.onUpdateValueMismatch();const{context:t}=this;n.flattenTo(e,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"../../web-gl/kernel-value/single-array3d-i":63}],99:[function(e,t,r){const{WebGLKernelValueSingleArray4:n}=e("../../web-gl/kernel-value/single-array4");t.exports={WebGL2KernelValueSingleArray4:class extends n{}}},{"../../web-gl/kernel-value/single-array4":64}],100:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueSingleInput:i}=e("../../web-gl/kernel-value/single-input");t.exports={WebGL2KernelValueSingleInput:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`${e} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`${e} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}updateValue(e){const{context:t}=this;n.flattenTo(e.value,this.uploadValue),t.activeTexture(this.contextHandle),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,this.textureSize[0],this.textureSize[1],0,t.RGBA,t.FLOAT,this.uploadValue),this.kernel.setUniform1i(this.id,this.index)}}}},{"../../../utils":112,"../../web-gl/kernel-value/single-input":65}],101:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueUnsignedArray:i}=e("../../web-gl/kernel-value/unsigned-array");t.exports={WebGL2KernelValueUnsignedArray:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`${e} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`${e} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/unsigned-array":66}],102:[function(e,t,r){const{utils:n}=e("../../../utils"),{WebGLKernelValueUnsignedInput:i}=e("../../web-gl/kernel-value/unsigned-input");t.exports={WebGL2KernelValueUnsignedInput:class extends i{getSource(){const e=this.getVariablePrecisionString();return n.linesToString([`uniform ${e} sampler2D ${this.id}`,`${e} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`,`${e} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`])}}}},{"../../../utils":112,"../../web-gl/kernel-value/unsigned-input":67}],103:[function(e,t,r){const{WebGLKernel:n}=e("../web-gl/kernel"),{WebGL2FunctionNode:i}=e("./function-node"),{FunctionBuilder:s}=e("../function-builder"),{utils:a}=e("../../utils"),{fragmentShader:o}=e("./fragment-shader"),{vertexShader:u}=e("./vertex-shader"),{lookupKernelValueType:l}=e("./kernel-value-maps");let h=null,c=null,p=null,d=null,m=null;t.exports={WebGL2Kernel:class extends n{static get isSupported(){return null!==h?h:(this.setupFeatureChecks(),h=this.isContextMatch(p))}static setupFeatureChecks(){"undefined"!=typeof document?c=document.createElement("canvas"):"undefined"!=typeof OffscreenCanvas&&(c=new OffscreenCanvas(0,0)),c&&(p=c.getContext("webgl2"))&&p.getExtension&&(d={EXT_color_buffer_float:p.getExtension("EXT_color_buffer_float"),OES_texture_float_linear:p.getExtension("OES_texture_float_linear")},m=this.getFeatures())}static isContextMatch(e){return"undefined"!=typeof WebGL2RenderingContext&&e instanceof WebGL2RenderingContext}static getFeatures(){return Object.freeze({isFloatRead:this.getIsFloatRead(),isIntegerDivisionAccurate:this.getIsIntegerDivisionAccurate(),kernelMap:!0,isTextureFloat:!0,channelCount:this.getChannelCount(),maxTextureSize:this.getMaxTextureSize()})}static getIsTextureFloat(){return!0}static getIsIntegerDivisionAccurate(){return super.getIsIntegerDivisionAccurate()}static getChannelCount(){return p.getParameter(p.MAX_DRAW_BUFFERS)}static getMaxTextureSize(){return p.getParameter(p.MAX_TEXTURE_SIZE)}static lookupKernelValueType(e,t,r,n){return l(e,t,r,n)}static get testCanvas(){return c}static get testContext(){return p}static get features(){return m}static get fragmentShader(){return o}static get vertexShader(){return u}initContext(){return this.canvas.getContext("webgl2",{alpha:!1,depth:!1,antialias:!1})}initExtensions(){this.extensions={EXT_color_buffer_float:this.context.getExtension("EXT_color_buffer_float"),OES_texture_float_linear:this.context.getExtension("OES_texture_float_linear")}}validateSettings(e){if(!this.validate)return void(this.texSize=a.getKernelTextureSize({optimizeFloatMemory:this.optimizeFloatMemory,precision:this.precision},this.output));const t=this.constructor.features;if("single"===this.precision&&!t.isFloatRead)throw new Error("Float texture outputs are not supported");if(this.graphical||null!==this.precision||(this.precision=t.isFloatRead?"single":"unsigned"),null===this.fixIntegerDivisionAccuracy?this.fixIntegerDivisionAccuracy=!t.isIntegerDivisionAccurate:this.fixIntegerDivisionAccuracy&&t.isIntegerDivisionAccurate&&(this.fixIntegerDivisionAccuracy=!1),this.checkOutput(),!this.output||0===this.output.length){if(1!==e.length)throw new Error("Auto output only supported for kernels with only one input");const t=a.getVariableType(e[0],this.strictIntegers);switch(t){case"Array":this.output=a.getDimensions(t);break;case"NumberTexture":case"MemoryOptimizedNumberTexture":case"ArrayTexture(1)":case"ArrayTexture(2)":case"ArrayTexture(3)":case"ArrayTexture(4)":this.output=e[0].output;break;default:throw new Error("Auto output not supported for input type: "+t)}}if(this.graphical){if(2!==this.output.length)throw new Error("Output must have 2 dimensions on graphical mode");return"single"===this.precision&&(console.warn("Cannot use graphical mode and single precision at the same time"),this.precision="unsigned"),void(this.texSize=a.clone(this.output))}!this.graphical&&null===this.precision&&t.isTextureFloat&&(this.precision="single"),this.texSize=a.getKernelTextureSize({optimizeFloatMemory:this.optimizeFloatMemory,precision:this.precision},this.output),this.checkTextureSize()}translateSource(){const e=s.fromKernel(this,i,{fixIntegerDivisionAccuracy:this.fixIntegerDivisionAccuracy});if(this.translatedSource=e.getPrototypeString("kernel"),this.graphical||this.returnType||(this.returnType=e.getKernelResultType()),this.subKernels&&this.subKernels.length>0)for(let t=0;t<this.subKernels.length;t++){const r=this.subKernels[t];r.returnType||(r.returnType=e.getSubKernelResultType(t))}}run(){const{kernelArguments:e,texSize:t,forceUploadKernelConstants:r}=this,n=this.context;n.useProgram(this.program),n.scissor(0,0,t[0],t[1]),this.dynamicOutput&&(this.setUniform3iv("uOutputDim",new Int32Array(this.threadDim)),this.setUniform2iv("uTexSize",t)),this.setUniform2f("ratio",t[0]/this.maxTexSize[0],t[1]/this.maxTexSize[1]),this.switchingKernels=!1;for(let e=0;e<r.length;e++){const t=r[e];if(t.updateValue(this.constants[t.name]),this.switchingKernels)return}for(let t=0;t<e.length;t++)if(e[t].updateValue(arguments[t]),this.switchingKernels)return;if(this.plugins)for(let e=0;e<this.plugins.length;e++){const t=this.plugins[e];t.onBeforeRun&&t.onBeforeRun(this)}if(this.graphical)return this.pipeline?(n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer),this.outputTexture&&!this.immutable||this._setupOutputTexture(),n.drawArrays(n.TRIANGLE_STRIP,0,4),new this.TextureConstructor({texture:this.outputTexture,size:t,dimensions:this.threadDim,output:this.output,context:this.context})):(n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),void n.drawArrays(n.TRIANGLE_STRIP,0,4));n.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer),this.immutable&&this._setupOutputTexture(),null!==this.subKernels&&(this.immutable&&this._setupSubOutputTextures(),n.drawBuffers(this.drawBuffersMap)),n.drawArrays(n.TRIANGLE_STRIP,0,4)}drawBuffers(){this.context.drawBuffers(this.drawBuffersMap)}getOutputTexture(){return this.outputTexture}_setupOutputTexture(){const{texSize:e}=this,t=this.context,r=this.outputTexture=t.createTexture();if(t.activeTexture(t.TEXTURE0+this.constantTextureCount+this.argumentTextureCount),t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),"single"===this.precision)if(this.pipeline)switch(this.returnType){case"Number":case"Float":case"Integer":this.optimizeFloatMemory?t.texStorage2D(t.TEXTURE_2D,1,t.RGBA32F,e[0],e[1]):t.texStorage2D(t.TEXTURE_2D,1,t.R32F,e[0],e[1]);break;case"Array(2)":t.texStorage2D(t.TEXTURE_2D,1,t.RG32F,e[0],e[1]);break;case"Array(3)":case"Array(4)":t.texStorage2D(t.TEXTURE_2D,1,t.RGBA32F,e[0],e[1]);break;default:throw new Error("Unhandled return type")}else t.texStorage2D(t.TEXTURE_2D,1,t.RGBA32F,e[0],e[1]);else t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e[0],e[1],0,t.RGBA,t.UNSIGNED_BYTE,null);t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0)}_setupSubOutputTextures(){const{texSize:e}=this,t=this.context;this.drawBuffersMap=[t.COLOR_ATTACHMENT0],this.subKernelOutputTextures=[];for(let r=0;r<this.subKernels.length;r++){const n=this.context.createTexture();this.subKernelOutputTextures.push(n),this.drawBuffersMap.push(t.COLOR_ATTACHMENT0+r+1),t.activeTexture(t.TEXTURE0+this.constantTextureCount+this.argumentTextureCount+r),t.bindTexture(t.TEXTURE_2D,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),"single"===this.precision?t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,e[0],e[1],0,t.RGBA,t.FLOAT,null):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e[0],e[1],0,t.RGBA,t.UNSIGNED_BYTE,null),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+r+1,t.TEXTURE_2D,n,0)}}_getHeaderString(){return""}_getTextureCoordinate(){const e=this.subKernels;if(null===e||e.length<1)switch(this.tactic){case"speed":return"in lowp vec2 vTexCoord;\n";case"performance":return"in highp vec2 vTexCoord;\n";case"balanced":default:return"in mediump vec2 vTexCoord;\n"}else switch(this.tactic){case"speed":return"out lowp vec2 vTexCoord;\n";case"performance":return"out highp vec2 vTexCoord;\n";case"balanced":default:return"out mediump vec2 vTexCoord;\n"}}_getMainArgumentsString(e){const t=[],r=this.argumentNames;for(let n=0;n<r.length;n++)t.push(this.kernelArguments[n].getSource(e[n]));return t.join("")}getKernelString(){let e;switch(this.returnType){case"Array(2)":e="vec2 kernelResult";break;case"Array(3)":e="vec3 kernelResult";break;case"Array(4)":e="vec4 kernelResult";break;case"LiteralInteger":case"Float":case"Number":case"Integer":e="float kernelResult";break;default:if(!this.graphical)throw new Error(`unrecognized output type "${this.returnType}"`);e="float kernelResult"}const t=[],r=this.subKernels;if(null!==r){t.push(e,"layout(location = 0) out vec4 data0");for(let e=0;e<r.length;e++){const n=r[e];t.push("Integer"===n.returnType?`int subKernelResult_${n.name} = 0`:`float subKernelResult_${n.name} = 0.0`,`layout(location = ${e+1}) out vec4 data${e+1}`)}}else t.push("out vec4 data0",e);return a.linesToString(t)+this.translatedSource}getMainResultGraphical(){return a.linesToString([" threadId = indexTo3D(index, uOutputDim)"," kernel()"," data0 = actualColor"])}getMainResultPackedPixels(){switch(this.returnType){case"LiteralInteger":case"Number":case"Integer":case"Float":return this.getMainResultKernelPackedPixels()+this.getMainResultSubKernelPackedPixels();default:throw new Error(`packed output only usable with Numbers, "${this.returnType}" specified`)}}getMainResultKernelPackedPixels(){return a.linesToString([" threadId = indexTo3D(index, uOutputDim)"," kernel()",` data0 = ${this.useLegacyEncoder?"legacyEncode32":"encode32"}(kernelResult)`])}getMainResultSubKernelPackedPixels(){const e=[];if(!this.subKernels)return"";for(let t=0;t<this.subKernels.length;t++)"Integer"===this.subKernels[t].returnType?e.push(` data${t+1} = ${this.useLegacyEncoder?"legacyEncode32":"encode32"}(float(subKernelResult_${this.subKernels[t].name}))`):e.push(` data${t+1} = ${this.useLegacyEncoder?"legacyEncode32":"encode32"}(subKernelResult_${this.subKernels[t].name})`);return a.linesToString(e)}getMainResultMemoryOptimizedFloats(){const e=[" index *= 4"];switch(this.returnType){case"Number":case"Integer":case"Float":const t=["r","g","b","a"];for(let r=0;r<t.length;r++){const n=t[r];this.getMainResultKernelMemoryOptimizedFloats(e,n),this.getMainResultSubKernelMemoryOptimizedFloats(e,n),r+1<t.length&&e.push(" index += 1")}break;default:throw new Error(`optimized output only usable with Numbers, ${this.returnType} specified`)}return a.linesToString(e)}getMainResultKernelMemoryOptimizedFloats(e,t){e.push(" threadId = indexTo3D(index, uOutputDim)"," kernel()",` data0.${t} = kernelResult`)}getMainResultSubKernelMemoryOptimizedFloats(e,t){if(!this.subKernels)return e;for(let r=0;r<this.subKernels.length;r++){const n=this.subKernels[r];"Integer"===n.returnType?e.push(` data${r+1}.${t} = float(subKernelResult_${n.name})`):e.push(` data${r+1}.${t} = subKernelResult_${n.name}`)}}getMainResultKernelNumberTexture(){return[" threadId = indexTo3D(index, uOutputDim)"," kernel()"," data0[0] = kernelResult"]}getMainResultSubKernelNumberTexture(){const e=[];if(!this.subKernels)return e;for(let t=0;t<this.subKernels.length;++t){const r=this.subKernels[t];"Integer"===r.returnType?e.push(` data${t+1}[0] = float(subKernelResult_${r.name})`):e.push(` data${t+1}[0] = subKernelResult_${r.name}`)}return e}getMainResultKernelArray2Texture(){return[" threadId = indexTo3D(index, uOutputDim)"," kernel()"," data0[0] = kernelResult[0]"," data0[1] = kernelResult[1]"]}getMainResultSubKernelArray2Texture(){const e=[];if(!this.subKernels)return e;for(let t=0;t<this.subKernels.length;++t){const r=this.subKernels[t];e.push(` data${t+1}[0] = subKernelResult_${r.name}[0]`,` data${t+1}[1] = subKernelResult_${r.name}[1]`)}return e}getMainResultKernelArray3Texture(){return[" threadId = indexTo3D(index, uOutputDim)"," kernel()"," data0[0] = kernelResult[0]"," data0[1] = kernelResult[1]"," data0[2] = kernelResult[2]"]}getMainResultSubKernelArray3Texture(){const e=[];if(!this.subKernels)return e;for(let t=0;t<this.subKernels.length;++t){const r=this.subKernels[t];e.push(` data${t+1}[0] = subKernelResult_${r.name}[0]`,` data${t+1}[1] = subKernelResult_${r.name}[1]`,` data${t+1}[2] = subKernelResult_${r.name}[2]`)}return e}getMainResultKernelArray4Texture(){return[" threadId = indexTo3D(index, uOutputDim)"," kernel()"," data0 = kernelResult"]}getMainResultSubKernelArray4Texture(){const e=[];if(!this.subKernels)return e;for(let t=0;t<this.subKernels.length;++t)e.push(` data${t+1} = subKernelResult_${this.subKernels[t].name}`);return e}destroyExtensions(){this.extensions.EXT_color_buffer_float=null,this.extensions.OES_texture_float_linear=null}toJSON(){const e=super.toJSON();return e.functionNodes=s.fromKernel(this,i).toJSON(),e}}}},{"../../utils":112,"../function-builder":9,"../web-gl/kernel":68,"./fragment-shader":70,"./function-node":71,"./kernel-value-maps":72,"./vertex-shader":104}],104:[function(e,t,r){t.exports={vertexShader:"#version 300 es\n__FLOAT_TACTIC_DECLARATION__;\n__INT_TACTIC_DECLARATION__;\n__SAMPLER_2D_TACTIC_DECLARATION__;\n\nin vec2 aPos;\nin vec2 aTexCoord;\n\nout vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}"}},{}],105:[function(e,t,r){const n=e("./index"),i=n.GPU;for(const e in n)n.hasOwnProperty(e)&&"GPU"!==e&&(i[e]=n[e]);t.exports=i},{"./index":107}],106:[function(e,t,r){const{gpuMock:n}=e("gpu-mock.js"),{utils:i}=e("./utils"),{CPUKernel:s}=e("./backend/cpu/kernel"),{HeadlessGLKernel:a}=e("./backend/headless-gl/kernel"),{WebGL2Kernel:o}=e("./backend/web-gl2/kernel"),{WebGLKernel:u}=e("./backend/web-gl/kernel"),{kernelRunShortcut:l}=e("./kernel-run-shortcut"),h=[a,o,u],c=["gpu","cpu"],p={headlessgl:a,webgl2:o,webgl:u};let d=!0;function m(e){if(!e)return{};const t=Object.assign({},e);return e.hasOwnProperty("floatOutput")&&(i.warnDeprecated("setting","floatOutput","precision"),t.precision=e.floatOutput?"single":"unsigned"),e.hasOwnProperty("outputToTexture")&&(i.warnDeprecated("setting","outputToTexture","pipeline"),t.pipeline=Boolean(e.outputToTexture)),e.hasOwnProperty("outputImmutable")&&(i.warnDeprecated("setting","outputImmutable","immutable"),t.immutable=Boolean(e.outputImmutable)),e.hasOwnProperty("floatTextures")&&(i.warnDeprecated("setting","floatTextures","optimizeFloatMemory"),t.optimizeFloatMemory=Boolean(e.floatTextures)),t}t.exports={GPU:class{static disableValidation(){d=!1}static enableValidation(){d=!0}static get isGPUSupported(){return h.some(e=>e.isSupported)}static get isKernelMapSupported(){return h.some(e=>e.isSupported&&e.features.kernelMap)}static get isOffscreenCanvasSupported(){return"undefined"!=typeof Worker&&"undefined"!=typeof OffscreenCanvas||"undefined"!=typeof importScripts}static get isWebGLSupported(){return u.isSupported}static get isWebGL2Supported(){return o.isSupported}static get isHeadlessGLSupported(){return a.isSupported}static get isCanvasSupported(){return"undefined"!=typeof HTMLCanvasElement}static get isGPUHTMLImageArraySupported(){return o.isSupported}static get isSinglePrecisionSupported(){return h.some(e=>e.isSupported&&e.features.isFloatRead&&e.features.isTextureFloat)}constructor(e){if(e=e||{},this.canvas=e.canvas||null,this.context=e.context||null,this.mode=e.mode,this.Kernel=null,this.kernels=[],this.functions=[],this.nativeFunctions=[],this.injectedNative=null,"dev"!==this.mode){if(this.chooseKernel(),e.functions)for(let t=0;t<e.functions.length;t++)this.addFunction(e.functions[t]);if(e.nativeFunctions)for(const t in e.nativeFunctions)this.addNativeFunction(t,e.nativeFunctions[t])}}chooseKernel(){if(this.Kernel)return;let e=null;if(this.context){for(let t=0;t<h.length;t++){const r=h[t];if(r.isContextMatch(this.context)){if(!r.isSupported)throw new Error(`Kernel type ${r.name} not supported`);e=r;break}}if(null===e)throw new Error("unknown Context")}else if(this.mode){if(this.mode in p)d&&!p[this.mode].isSupported||(e=p[this.mode]);else if("gpu"===this.mode){for(let t=0;t<h.length;t++)if(h[t].isSupported){e=h[t];break}}else"cpu"===this.mode&&(e=s);if(!e)throw new Error(`A requested mode of "${this.mode}" and is not supported`)}else{for(let t=0;t<h.length;t++)if(h[t].isSupported){e=h[t];break}e||(e=s)}this.mode||(this.mode=e.mode),this.Kernel=e}createKernel(e,t){if(void 0===e)throw new Error("Missing source parameter");if("object"!=typeof e&&!i.isFunction(e)&&"string"!=typeof e)throw new Error("source parameter not a function");if("dev"===this.mode){const r=n(e,m(t));return this.kernels.push(r),r}e="function"==typeof e?e.toString():e;const r={},a=m(t)||{};function o(t){const r=new s(e,{argumentTypes:h.argumentTypes,constantTypes:h.constantTypes,graphical:h.graphical,loopMaxIterations:h.loopMaxIterations,constants:h.constants,dynamicOutput:h.dynamicOutput,dynamicArgument:h.dynamicArguments,output:h.output,precision:h.precision,pipeline:h.pipeline,immutable:h.immutable,optimizeFloatMemory:h.optimizeFloatMemory,fixIntegerDivisionAccuracy:h.fixIntegerDivisionAccuracy,functions:h.functions,nativeFunctions:h.nativeFunctions,injectedNative:h.injectedNative,subKernels:h.subKernels,strictIntegers:h.strictIntegers,debug:h.debug,warnVarUsage:h.warnVarUsage});r.build.apply(r,t);const n=r.run.apply(r,t);return h.replaceKernel(r),n}t&&"object"==typeof t.argumentTypes&&(a.argumentTypes=Object.keys(t.argumentTypes).map(e=>t.argumentTypes[e]));const u=Object.assign({context:this.context,canvas:this.canvas,functions:this.functions,nativeFunctions:this.nativeFunctions,injectedNative:this.injectedNative,gpu:this,validate:d,onRequestFallback:o,onRequestSwitchKernel:function t(n,s){const a=new Array(n.length);for(let e=0;e<n.length;e++){const t=n[e],r=s.argumentTypes[e];if(t.type)a[e]=t.type;else switch(r){case"Number":case"Integer":case"Float":case"ArrayTexture(1)":a[e]=i.getVariableType(t);break;default:a[e]=r}}const u=a.join(","),l=r[u];if(l)return l.run.apply(l,n),l.renderKernels?l.renderKernels():l.renderOutput();const c=r[u]=new s.constructor(e,{argumentTypes:a,constantTypes:s.constantTypes,graphical:s.graphical,loopMaxIterations:s.loopMaxIterations,constants:s.constants,dynamicOutput:s.dynamicOutput,dynamicArgument:s.dynamicArguments,context:s.context,canvas:s.canvas,output:s.output,precision:s.precision,pipeline:s.pipeline,immutable:s.immutable,optimizeFloatMemory:s.optimizeFloatMemory,fixIntegerDivisionAccuracy:s.fixIntegerDivisionAccuracy,functions:s.functions,nativeFunctions:s.nativeFunctions,injectedNative:s.injectedNative,subKernels:s.subKernels,strictIntegers:s.strictIntegers,debug:s.debug,gpu:s.gpu,validate:d,warnVarUsage:s.warnVarUsage,returnType:s.returnType,onRequestFallback:o,onRequestSwitchKernel:t});return c.build.apply(c,n),c.run.apply(c,n),h.replaceKernel(c),c.renderKernels?c.renderKernels():c.renderOutput()}},a),h=l(new this.Kernel(e,u));return this.canvas||(this.canvas=h.canvas),this.context||(this.context=h.context),this.kernels.push(h),h}createKernelMap(){let e,t;if("function"==typeof arguments[arguments.length-2]?(e=arguments[arguments.length-2],t=arguments[arguments.length-1]):e=arguments[arguments.length-1],"dev"!==this.mode&&(!this.Kernel.isSupported||!this.Kernel.features.kernelMap)&&this.mode&&c.indexOf(this.mode)<0)throw new Error(`kernelMap not supported on ${this.Kernel.name}`);const r=m(t);if(t&&"object"==typeof t.argumentTypes&&(r.argumentTypes=Object.keys(t.argumentTypes).map(e=>t.argumentTypes[e])),Array.isArray(arguments[0])){r.subKernels=[];const e=arguments[0];for(let t=0;t<e.length;t++){const n=e[t].toString(),s=i.getFunctionNameFromString(n);r.subKernels.push({name:s,source:n,property:t})}}else{r.subKernels=[];const e=arguments[0];for(let t in e){if(!e.hasOwnProperty(t))continue;const n=e[t].toString(),s=i.getFunctionNameFromString(n);r.subKernels.push({name:s||t,source:n,property:t})}}return this.createKernel(e,r)}combineKernels(){const e=arguments[0],t=arguments[arguments.length-1];if("cpu"===e.kernel.constructor.mode)return t;const r=arguments[0].canvas,n=arguments[0].context,i=arguments.length-1;for(let e=0;e<i;e++)arguments[e].setCanvas(r).setContext(n).setPipeline(!0);return function(){const e=t.apply(this,arguments);return e.toArray?e.toArray():e}}addFunction(e,t){return this.functions.push(i.functionToIFunction(e,t)),this}addNativeFunction(e,t,r){if(this.kernels.length>0)throw new Error('Cannot call "addNativeFunction" after "createKernels" has been called.');r=r||{};const{argumentTypes:n,argumentNames:i}=this.Kernel.nativeFunctionArguments(t)||{};return this.nativeFunctions.push({name:e,source:t,settings:r,argumentTypes:n,argumentNames:i,returnType:r.returnType||this.Kernel.nativeFunctionReturnType(t)}),this}injectNative(e){return this.injectedNative=e,this}destroy(){this.kernels&&setTimeout(()=>{for(let e=0;e<this.kernels.length;e++)this.kernels[e].destroy(!0);let e=this.kernels[0];e&&(e.kernel&&(e=e.kernel),e.constructor.destroyContext&&e.constructor.destroyContext(this.context))},0)}},kernelOrder:h,kernelTypes:c}},{"./backend/cpu/kernel":8,"./backend/headless-gl/kernel":33,"./backend/web-gl/kernel":68,"./backend/web-gl2/kernel":103,"./kernel-run-shortcut":109,"./utils":112,"gpu-mock.js":4}],107:[function(e,t,r){const{GPU:n}=e("./gpu"),{alias:i}=e("./alias"),{utils:s}=e("./utils"),{Input:a,input:o}=e("./input"),{Texture:u}=e("./texture"),{FunctionBuilder:l}=e("./backend/function-builder"),{FunctionNode:h}=e("./backend/function-node"),{CPUFunctionNode:c}=e("./backend/cpu/function-node"),{CPUKernel:p}=e("./backend/cpu/kernel"),{HeadlessGLKernel:d}=e("./backend/headless-gl/kernel"),{WebGLFunctionNode:m}=e("./backend/web-gl/function-node"),{WebGLKernel:g}=e("./backend/web-gl/kernel"),{kernelValueMaps:f}=e("./backend/web-gl/kernel-value-maps"),{WebGL2FunctionNode:x}=e("./backend/web-gl2/function-node"),{WebGL2Kernel:y}=e("./backend/web-gl2/kernel"),{kernelValueMaps:T}=e("./backend/web-gl2/kernel-value-maps"),{GLKernel:b}=e("./backend/gl/kernel"),{Kernel:A}=e("./backend/kernel"),{FunctionTracer:v}=e("./backend/function-tracer");t.exports={alias:i,CPUFunctionNode:c,CPUKernel:p,GPU:n,FunctionBuilder:l,FunctionNode:h,HeadlessGLKernel:d,Input:a,input:o,Texture:u,utils:s,WebGL2FunctionNode:x,WebGL2Kernel:y,webGL2KernelValueMaps:T,WebGLFunctionNode:m,WebGLKernel:g,webGLKernelValueMaps:f,GLKernel:b,Kernel:A,FunctionTracer:v}},{"./alias":5,"./backend/cpu/function-node":6,"./backend/cpu/kernel":8,"./backend/function-builder":9,"./backend/function-node":10,"./backend/function-tracer":11,"./backend/gl/kernel":13,"./backend/headless-gl/kernel":33,"./backend/kernel":35,"./backend/web-gl/function-node":37,"./backend/web-gl/kernel":68,"./backend/web-gl/kernel-value-maps":38,"./backend/web-gl2/function-node":71,"./backend/web-gl2/kernel":103,"./backend/web-gl2/kernel-value-maps":72,"./gpu":106,"./input":108,"./texture":111,"./utils":112}],108:[function(e,t,r){class n{constructor(e,t){this.value=e,Array.isArray(t)?this.size=t:(this.size=new Int32Array(3),t.z?this.size=new Int32Array([t.x,t.y,t.z]):t.y?this.size=new Int32Array([t.x,t.y]):this.size=new Int32Array([t.x]));const[r,n,i]=this.size;if(i){if(this.value.length!==r*n*i)throw new Error(`Input size ${this.value.length} does not match ${r} * ${n} * ${i} = ${n*r*i}`)}else if(n){if(this.value.length!==r*n)throw new Error(`Input size ${this.value.length} does not match ${r} * ${n} = ${n*r}`)}else if(this.value.length!==r)throw new Error(`Input size ${this.value.length} does not match ${r}`)}toArray(){const{utils:t}=e("./utils"),[r,n,i]=this.size;return i?t.erectMemoryOptimized3DFloat(this.value.subarray?this.value:new Float32Array(this.value),r,n,i):n?t.erectMemoryOptimized2DFloat(this.value.subarray?this.value:new Float32Array(this.value),r,n):this.value}}t.exports={Input:n,input:function(e,t){return new n(e,t)}}},{"./utils":112}],109:[function(e,t,r){const{utils:n}=e("./utils");function i(e,t){const r=n.allPropertiesOf(e);for(let n=0;n<r.length;n++){const i=r[n];"_"===i[0]&&"_"===i[1]||("function"==typeof e[i]?"add"===i.substring(0,3)||"set"===i.substring(0,3)?t[i]=function(){return e[i].apply(e,arguments),t}:"toString"===i?t.toString=function(){return e.toString.apply(e,arguments)}:t[i]=e[i].bind(e):(t.__defineGetter__(i,()=>e[i]),t.__defineSetter__(i,t=>{e[i]=t})))}}t.exports={kernelRunShortcut:function(e){let t=function(){return e.build.apply(e,arguments),(t=e.renderKernels?function(){return e.run.apply(e,arguments),e.switchingKernels?(e.switchingKernels=!1,e.onRequestSwitchKernel(arguments,e)):e.renderKernels()}:e.renderOutput?function(){return e.run.apply(e,arguments),e.switchingKernels?(e.switchingKernels=!1,e.onRequestSwitchKernel(arguments,e)):e.renderOutput()}:function(){return e.run.apply(e,arguments)}).apply(e,arguments)};const r=function(){return t.apply(e,arguments)};return r.exec=function(){return new Promise((e,r)=>{try{e(t.apply(this,arguments))}catch(e){r(e)}})},r.replaceKernel=function(t){i(e=t,r),r.kernel=e},i(e,r),r.kernel=e,r}}},{"./utils":112}],110:[function(e,t,r){t.exports={name:"triangle-noise-noise",onBeforeRun:e=>{e.setUniform1f("triangle_noise_seed",Math.random())},functionMatch:"Math.random()",functionReplace:"n4rand(vTexCoord)",functionReturnType:"Number",source:"\n\nuniform highp float triangle_noise_seed;\nhighp float triangle_noise_shift = 0.000001;\n\n//https://www.shadertoy.com/view/4t2SDh\n//note: uniformly distributed, normalized rand, [0;1[\nfloat nrand( vec2 n )\n{\n return fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);\n}\n//note: remaps v to [0;1] in interval [a;b]\nfloat remap( float a, float b, float v )\n{\n return clamp( (v-a) / (b-a), 0.0, 1.0 );\n}\n\nfloat n4rand( vec2 n )\n{\n float t = fract( triangle_noise_seed + triangle_noise_shift );\n float nrnd0 = nrand( n + 0.07*t );\n float nrnd1 = nrand( n + 0.11*t ); \n float nrnd2 = nrand( n + 0.13*t );\n float nrnd3 = nrand( n + 0.17*t );\n float result = (nrnd0+nrnd1+nrnd2+nrnd3) / 4.0;\n triangle_noise_shift = result + 0.000001;\n return result;\n}"}},{}],111:[function(e,t,r){t.exports={Texture:class{constructor(e){const{texture:t,size:r,dimensions:n,output:i,context:s,type:a="NumberTexture"}=e;if(!i)throw new Error('settings property "output" required.');if(!s)throw new Error('settings property "context" required.');this.texture=t,this.size=r,this.dimensions=n,this.output=i,this.context=s,this.kernel=null,this.type=a}toArray(){throw new Error(`Not implemented on ${this.constructor.name}`)}delete(){return this.context.deleteTexture(this.texture)}}}},{}],112:[function(e,t,r){const n=e("acorn"),{Input:i}=e("./input"),{Texture:s}=e("./texture"),a=/function ([^(]*)/,o=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,u=/([^\s,]+)/g,l={systemEndianness:()=>h,getSystemEndianness(){const e=new ArrayBuffer(4),t=new Uint32Array(e),r=new Uint8Array(e);if(t[0]=3735928559,239===r[0])return"LE";if(222===r[0])return"BE";throw new Error("unknown endianness")},isFunction:e=>"function"==typeof e,isFunctionString:e=>"string"==typeof e&&"function"===e.slice(0,"function".length).toLowerCase(),getFunctionNameFromString:e=>a.exec(e)[1].trim(),getFunctionBodyFromString:e=>e.substring(e.indexOf("{")+1,e.lastIndexOf("}")),getArgumentNamesFromString(e){const t=e.replace(o,"");let r=t.slice(t.indexOf("(")+1,t.indexOf(")")).match(u);return null===r&&(r=[]),r},clone(e){if(null===e||"object"!=typeof e||e.hasOwnProperty("isActiveClone"))return e;const t=e.constructor();for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(e.isActiveClone=null,t[r]=l.clone(e[r]),delete e.isActiveClone);return t},isArray:e=>!isNaN(e.length),getVariableType(e,t){if(l.isArray(e))return"IMG"===e[0].nodeName?"HTMLImageArray":"Array";switch(e.constructor){case Boolean:return"Boolean";case Number:return t&&Number.isInteger(e)?"Integer":"Float";case s:return e.type;case i:return"Input"}switch(e.nodeName){case"IMG":return"HTMLImage";case"VIDEO":return"HTMLVideo"}return e.hasOwnProperty("type")?e.type:"Unknown"},getKernelTextureSize(e,t){let[r,n,i]=t,s=(r||1)*(n||1)*(i||1);return e.optimizeFloatMemory&&"single"===e.precision&&(r=s=Math.ceil(s/4)),n>1&&r*n===s?new Int32Array([r,n]):l.closestSquareDimensions(s)},closestSquareDimensions(e){const t=Math.sqrt(e);let r=Math.ceil(t),n=Math.floor(t);for(;r*n<e;)r--,n=Math.ceil(e/r);return new Int32Array([n,Math.ceil(e/n)])},getMemoryOptimizedFloatTextureSize(e,t){const r=l.roundTo((e[0]||1)*(e[1]||1)*(e[2]||1)*(e[3]||1),4)/t;return l.closestSquareDimensions(r)},getMemoryOptimizedPackedTextureSize(e,t){const[r,n,i]=e,s=l.roundTo((r||1)*(n||1)*(i||1),4)/(4/t);return l.closestSquareDimensions(s)},roundTo:(e,t)=>Math.floor((e+t-1)/t)*t,getDimensions(e,t){let r;if(l.isArray(e)){const t=[];let n=e;for(;l.isArray(n);)t.push(n.length),n=n[0];r=t.reverse()}else if(e instanceof s)r=e.output;else{if(!(e instanceof i))throw new Error(`Unknown dimensions of ${e}`);r=e.size}if(t)for(r=Array.from(r);r.length<3;)r.push(1);return new Int32Array(r)},flatten2dArrayTo(e,t){let r=0;for(let n=0;n<e.length;n++)t.set(e[n],r),r+=e[n].length},flatten3dArrayTo(e,t){let r=0;for(let n=0;n<e.length;n++)for(let i=0;i<e[n].length;i++)t.set(e[n][i],r),r+=e[n][i].length},flatten4dArrayTo(e,t){let r=0;for(let n=0;n<e.length;n++)for(let i=0;i<e[n].length;i++)for(let s=0;s<e[n][i].length;s++)t.set(e[n][i][s],r),r+=e[n][i][s].length},flattenTo(e,t){l.isArray(e[0])?l.isArray(e[0][0])?l.isArray(e[0][0][0])?l.flatten4dArrayTo(e,t):l.flatten3dArrayTo(e,t):l.flatten2dArrayTo(e,t):t.set(e)},splitArray(e,t){const r=[];for(let n=0;n<e.length;n+=t)r.push(new e.constructor(e.buffer,4*n+e.byteOffset,t));return r},getAstString(e,t){const r=Array.isArray(e)?e:e.split(/\r?\n/g),n=t.loc.start,i=t.loc.end,s=[];if(n.line===i.line)s.push(r[n.line-1].substring(n.column,i.column));else{s.push(r[n.line-1].slice(n.column));for(let e=n.line;e<i.line;e++)s.push(r[e]);s.push(r[i.line-1].slice(0,i.column))}return s.join("\n")},allPropertiesOf(e){const t=[];do{t.push.apply(t,Object.getOwnPropertyNames(e))}while(e=Object.getPrototypeOf(e));return t},linesToString:e=>e.length>0?e.join(";\n")+";\n":"\n",warnDeprecated(e,t,r){r?console.warn(`You are using a deprecated ${e} "${t}". It has been replaced with "${r}". Fixing, but please upgrade as it will soon be removed.`):console.warn(`You are using a deprecated ${e} "${t}". It has been removed. Fixing, but please upgrade as it will soon be removed.`)},functionToIFunction(e,t){if(t=t||{},"string"!=typeof e&&"function"!=typeof e)throw new Error("source not a string or function");const r="string"==typeof e?e:e.toString();let n=[];return{source:r,argumentTypes:n=Array.isArray(t.argumentTypes)?t.argumentTypes:"object"==typeof t.argumentTypes?l.getArgumentNamesFromString(r).map(e=>t.argumentTypes[e])||[]:t.argumentTypes||[],returnType:t.returnType||null}},flipPixels:(e,t,r)=>{const n=r/2|0,i=4*t,s=new Uint8ClampedArray(4*t),a=e.slice(0);for(let e=0;e<n;++e){const t=e*i,n=(r-e-1)*i;s.set(a.subarray(t,t+i)),a.copyWithin(t,n,n+i),a.set(s,n)}return a},erectPackedFloat:(e,t)=>e.subarray(0,t),erect2DPackedFloat:(e,t,r)=>{const n=new Array(r);for(let i=0;i<r;i++){const r=i*t,s=r+t;n[i]=e.subarray(r,s)}return n},erect3DPackedFloat:(e,t,r,n)=>{const i=new Array(n);for(let s=0;s<n;s++){const n=new Array(r);for(let i=0;i<r;i++){const a=s*r*t+i*t,o=a+t;n[i]=e.subarray(a,o)}i[s]=n}return i},erectMemoryOptimizedFloat:(e,t)=>e.subarray(0,t),erectMemoryOptimized2DFloat:(e,t,r)=>{const n=new Array(r);for(let i=0;i<r;i++){const r=i*t;n[i]=e.subarray(r,r+t)}return n},erectMemoryOptimized3DFloat:(e,t,r,n)=>{const i=new Array(n);for(let s=0;s<n;s++){const n=new Array(r);for(let i=0;i<r;i++){const a=s*r*t+i*t;n[i]=e.subarray(a,a+t)}i[s]=n}return i},erectFloat:(e,t)=>{const r=new Float32Array(t);let n=0;for(let i=0;i<t;i++)r[i]=e[n],n+=4;return r},erect2DFloat:(e,t,r)=>{const n=new Array(r);let i=0;for(let s=0;s<r;s++){const r=new Float32Array(t);for(let n=0;n<t;n++)r[n]=e[i],i+=4;n[s]=r}return n},erect3DFloat:(e,t,r,n)=>{const i=new Array(n);let s=0;for(let a=0;a<n;a++){const n=new Array(r);for(let i=0;i<r;i++){const r=new Float32Array(t);for(let n=0;n<t;n++)r[n]=e[s],s+=4;n[i]=r}i[a]=n}return i},erectArray2:(e,t)=>{const r=new Array(t),n=4*t;let i=0;for(let t=0;t<n;t+=4)r[i++]=e.subarray(t,t+2);return r},erect2DArray2:(e,t,r)=>{const n=new Array(r),i=4*t;for(let s=0;s<r;s++){const r=new Array(t),a=s*i;let o=0;for(let t=0;t<i;t+=4)r[o++]=e.subarray(t+a,t+a+2);n[s]=r}return n},erect3DArray2:(e,t,r,n)=>{const i=4*t,s=new Array(n);for(let a=0;a<n;a++){const n=new Array(r);for(let s=0;s<r;s++){const o=new Array(t),u=a*i*r+s*i;let l=0;for(let t=0;t<i;t+=4)o[l++]=e.subarray(t+u,t+u+2);n[s]=o}s[a]=n}return s},erectArray3:(e,t)=>{const r=new Array(t),n=4*t;let i=0;for(let t=0;t<n;t+=4)r[i++]=e.subarray(t,t+3);return r},erect2DArray3:(e,t,r)=>{const n=4*t,i=new Array(r);for(let s=0;s<r;s++){const r=new Array(t),a=s*n;let o=0;for(let t=0;t<n;t+=4)r[o++]=e.subarray(t+a,t+a+3);i[s]=r}return i},erect3DArray3:(e,t,r,n)=>{const i=4*t,s=new Array(n);for(let a=0;a<n;a++){const n=new Array(r);for(let s=0;s<r;s++){const o=new Array(t),u=a*i*r+s*i;let l=0;for(let t=0;t<i;t+=4)o[l++]=e.subarray(t+u,t+u+3);n[s]=o}s[a]=n}return s},erectArray4:(e,t)=>{const r=new Array(e),n=4*t;let i=0;for(let t=0;t<n;t+=4)r[i++]=e.subarray(t,t+4);return r},erect2DArray4:(e,t,r)=>{const n=4*t,i=new Array(r);for(let s=0;s<r;s++){const r=new Array(t),a=s*n;let o=0;for(let t=0;t<n;t+=4)r[o++]=e.subarray(t+a,t+a+4);i[s]=r}return i},erect3DArray4:(e,t,r,n)=>{const i=4*t,s=new Array(n);for(let a=0;a<n;a++){const n=new Array(r);for(let s=0;s<r;s++){const o=new Array(t),u=a*i*r+s*i;let l=0;for(let t=0;t<i;t+=4)o[l++]=e.subarray(t+u,t+u+4);n[s]=o}s[a]=n}return s},flattenFunctionToString:(e,t)=>{const{findDependency:r,thisLookup:i,doNotDefine:s}=t;let a=t.flattened;a||(a=t.flattened={});const o=n.parse(e),u=[];const h=function e(t){if(Array.isArray(t)){const r=[];for(let n=0;n<t.length;n++)r.push(e(t[n]));return r.join("")}switch(t.type){case"Program":return e(t.body);case"FunctionDeclaration":return`function ${t.id.name}(${t.params.map(e).join(", ")}) ${e(t.body)}`;case"BlockStatement":{const r=[];for(let n=0;n<t.body.length;n++)r.push(e(t.body[n]),";\n");return`{\n${r.join("")}}`}case"VariableDeclaration":switch(t.declarations[0].id.type){case"ObjectPattern":{const r=e(t.declarations[0].init),n=t.declarations.map(t=>t.id.properties.map(e))[0];if(/this/.test(r)){const e=[],r=n.map(i);for(let i=0;i<r.length;i++){const s=r[i];if(null===s)continue;const a=n[i];e.push(`${t.kind} ${a} = ${s};\n`)}return e.join("")}return`${t.kind} { ${n} } = ${r}`}case"ArrayPattern":return`${t.kind} [ ${t.declarations.map(t=>e(t.id)).join(", ")} ] = ${e(t.declarations[0].init)}`}return s&&-1!==s.indexOf(t.declarations[0].id.name)?"":`${t.kind} ${t.declarations[0].id.name} = ${e(t.declarations[0].init)}`;case"CallExpression":if("subarray"===t.callee.property.name)return`${e(t.callee.object)}.${e(t.callee.property)}(${t.arguments.map(t=>e(t)).join(", ")})`;if("gl"===t.callee.object.name||"context"===t.callee.object.name)return`${e(t.callee.object)}.${e(t.callee.property)}(${t.arguments.map(t=>e(t)).join(", ")})`;if("ThisExpression"===t.callee.object.type)return u.push(r("this",t.callee.property.name)),`${t.callee.property.name}(${t.arguments.map(t=>e(t)).join(", ")})`;if(t.callee.object.name){const n=r(t.callee.object.name,t.callee.property.name);return null===n?`${t.callee.object.name}.${t.callee.property.name}(${t.arguments.map(t=>e(t)).join(", ")})`:(u.push(n),`${t.callee.property.name}(${t.arguments.map(t=>e(t)).join(", ")})`)}if("MemberExpression"===t.callee.object.type)return`${e(t.callee.object)}.${t.callee.property.name}(${t.arguments.map(t=>e(t)).join(", ")})`;throw new Error("unknown ast.callee");case"ReturnStatement":return`return ${e(t.argument)}`;case"BinaryExpression":return`(${e(t.left)}${t.operator}${e(t.right)})`;case"UnaryExpression":return t.prefix?`${t.operator} ${e(t.argument)}`:`${e(t.argument)} ${t.operator}`;case"ExpressionStatement":return`(${e(t.expression)})`;case"ArrowFunctionExpression":return`(${t.params.map(e).join(", ")}) => ${e(t.body)}`;case"Literal":return t.raw;case"Identifier":return t.name;case"MemberExpression":return"ThisExpression"===t.object.type?i(t.property.name):t.computed?`${e(t.object)}[${e(t.property)}]`:e(t.object)+"."+e(t.property);case"ThisExpression":return"this";case"NewExpression":return`new ${e(t.callee)}(${t.arguments.map(t=>e(t)).join(", ")})`;case"ForStatement":return`for (${e(t.init)};${e(t.test)};${e(t.update)}) ${e(t.body)}`;case"AssignmentExpression":return`${e(t.left)}${t.operator}${e(t.right)}`;case"UpdateExpression":return`${e(t.argument)}${t.operator}`;case"IfStatement":return`if (${e(t.test)}) ${e(t.consequent)}`;case"ThrowStatement":return`throw ${e(t.argument)}`;case"ObjectPattern":return t.properties.map(e).join(", ");case"ArrayPattern":return t.elements.map(e).join(", ");case"DebuggerStatement":return"debugger;";case"ConditionalExpression":return`${e(t.test)}?${e(t.consequent)}:${e(t.alternate)}`;case"Property":if("init"===t.kind)return e(t.key)}throw new Error(`unhandled ast.type of ${t.type}`)}(o);if(u.length>0){const e=[];for(let r=0;r<u.length;r++){const n=u[r];a[n]||(a[n]=!0),e.push(l.flattenFunctionToString(n,t)+";\n")}return e.join("")+h}return h},splitHTMLImageToRGB:(e,t)=>{const r=new GPU({mode:t}),n=r.createKernel(function(e){return 255*e[this.thread.y][this.thread.x].r},{output:[e.width,e.height],precision:"unsigned",argumentTypes:["HTMLImage"]}),i=r.createKernel(function(e){return 255*e[this.thread.y][this.thread.x].g},{output:[e.width,e.height],precision:"unsigned",argumentTypes:["HTMLImage"]}),s=r.createKernel(function(e){return 255*e[this.thread.y][this.thread.x].b},{output:[e.width,e.height],precision:"unsigned",argumentTypes:["HTMLImage"]}),a=r.createKernel(function(e){return 255*e[this.thread.y][this.thread.x].a},{output:[e.width,e.height],precision:"unsigned",argumentTypes:["HTMLImage"]}),o=[n(e),i(e),s(e),a(e)];return o.rKernel=n,o.gKernel=i,o.bKernel=s,o.aKernel=a,o.gpu=r,o},splitRGBAToCanvases:(t,r,n,i)=>{const{GPU:s}=e("./gpu.js"),a=new s({mode:i}),o=a.createKernel(function(e){const t=e[this.thread.y][this.thread.x];this.color(t.r/255,0,0,255)},{output:[r,n],graphical:!0,argumentTypes:{v:"Array2D(4)"}});o(t);const u=new s({mode:i}),l=u.createKernel(function(e){const t=e[this.thread.y][this.thread.x];this.color(0,t.g/255,0,255)},{output:[r,n],graphical:!0,argumentTypes:{v:"Array2D(4)"}});l(t);const h=new s({mode:i}),c=h.createKernel(function(e){const t=e[this.thread.y][this.thread.x];this.color(0,0,t.b/255,255)},{output:[r,n],graphical:!0,argumentTypes:{v:"Array2D(4)"}});c(t);const p=new s({mode:i}),d=p.createKernel(function(e){const t=e[this.thread.y][this.thread.x];this.color(255,255,255,t.a/255)},{output:[r,n],graphical:!0,argumentTypes:{v:"Array2D(4)"}});return d(t),a.destroy(),u.destroy(),h.destroy(),p.destroy(),[o.canvas,l.canvas,c.canvas,d.canvas]}},h=l.getSystemEndianness();t.exports={utils:l}},{"./gpu.js":106,"./input":108,"./texture":111,acorn:1}]},{},[105])(105)});