<!doctype html> <html> <head> <meta charset="UTF-8"> <title>__GAMETITLE__</title> <style> body{ background-color:black; font-family:"Courier New", Courier, monospace }#gameCanvas{ position:absolute;top:0px;left:0px;width:100%;height:100%;bottom:0px;right:0px;border:0px;background-color:black; -webkit-tap-highlight-color:rgba(0,0,0,0);image-rendering:-moz-crisp-edges;image-rendering:-webkit-crisp-edges;image-rendering:pixelated;image-rendering:crisp-edges;}h1{ color:lightblue;font-weight:normal;}a{ color:lightblue;}.title{ background-color:none;text-align:center;font-size:100%;float:center;color:gray;position:absolute;left:10%;right:10%;top:0%;height:10%;}.footer{ background-color:none;text-align:center;float:center;color:white;position:absolute;margin-top:10px;left:10%;right:10%;top:90%;bottom:10%;}.gameContainer{ background-color:none;position:absolute;left:10%;right:10%;top:70px;bottom:70px;}</style> </head> <body> <div class="title"><h1>__GAMETITLE__</h1></div> <div class="gameContainer"> <canvas id="gameCanvas3d"></canvas> <canvas id="gameCanvas" onmousemove="mouseMove(event)" onmouseout="mouseOut()" onkeydown="keyDown()"></canvas> </div> <div class="footer"> <span id="errormessage" style="color:red;"></span> <a href="http://__HOMEPAGE__">__HOMEPAGE__</a> </div> <script>function doSetupTitleScreenLevelContinue(){try{if(window.localStorage&&void 0!==localStorage[document.URL]){if(void 0!==localStorage[document.URL+"_checkpoint"]){var e=localStorage[document.URL+"_checkpoint"];curlevelTarget=JSON.parse(e);var t=[];for(var i in Object.keys(curlevelTarget.dat))t[i]=curlevelTarget.dat[i];curlevelTarget.dat=new Int32Array(t)}curlevel=localStorage[document.URL]}}catch(e){}}var unitTesting=!1,curlevel=0,curlevelTarget=null,hasUsedCheckpoint=!1,levelEditorOpened=!1;doSetupTitleScreenLevelContinue();var verbose_logging=!1,throttle_movement=!1,cache_console_messages=!1,quittingTitleScreen=!1,quittingMessageScreen=!1,deltatime=17,timer=0,repeatinterval=250,autotick=0,autotickinterval=0,winning=!1,againing=!1,againinterval=250,norepeat_action=!1,oldflickscreendat=[],keybuffer=[],interpolating=0,displayIndex=0,interpolationInterval=250,viewPitch=0,scaleHeight=1,viewDistance=10,viewHeight=.5,fieldOfView=60,fogPower=2,gradientBottom="#dfdfdf",gradientMiddle="#ffffff",gradientTop="#cfcfcf",restarting=!1,messageselected=!1,textImages={},initLevel={width:5,height:5,layerCount:2,dat:[1,3,3,1,1,2,2,3,3,1,2,1,2,2,3,3,1,1,2,2,3,2,1,3,2,1,3,2,1,3,1,3,3,1,1,2,2,3,3,1,2,1,2,2,3,3,1,1,2,2],movementMask:[1,3,3,1,1,2,2,3,3,1,2,1,2,2,3,3,1,1,2,2,3,2,1,3,2,1,3,2,1,3,1,3,3,1,1,2,2,3,3,1,2,1,2,2,3,3,1,1,2,2],rigidGroupIndexMask:[],rigidMovementAppliedMask:[],bannedGroup:[],colCellContents:[],rowCellContents:[]},level=initLevel;</script> <script>!function(t,a){if("object"==typeof exports&&"object"==typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var n=a();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,function(){return function(t){function a(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,a),o.loaded=!0,o.exports}var n={};return a.m=t,a.c=n,a.p="",a(0)}([function(t,a,n){a.glMatrix=n(1),a.mat2=n(2),a.mat2d=n(3),a.mat3=n(4),a.mat4=n(5),a.quat=n(6),a.vec2=n(9),a.vec3=n(7),a.vec4=n(8)},function(t,a){var n={};n.EPSILON=1e-6,n.ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array,n.RANDOM=Math.random,n.ENABLE_SIMD=!1,n.SIMD_AVAILABLE=n.ARRAY_TYPE===this.Float32Array&&"SIMD"in this,n.USE_SIMD=n.ENABLE_SIMD&&n.SIMD_AVAILABLE,n.setMatrixArrayType=function(t){n.ARRAY_TYPE=t};var r=Math.PI/180;n.toRadian=function(t){return t*r},n.equals=function(t,a){return Math.abs(t-a)<=n.EPSILON*Math.max(1,Math.abs(t),Math.abs(a))},t.exports=n},function(t,a,n){var r=n(1),o={};o.create=function(){var t=new r.ARRAY_TYPE(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},o.clone=function(t){var a=new r.ARRAY_TYPE(4);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t},o.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},o.fromValues=function(t,a,n,o){var u=new r.ARRAY_TYPE(4);return u[0]=t,u[1]=a,u[2]=n,u[3]=o,u},o.set=function(t,a,n,r,o){return t[0]=a,t[1]=n,t[2]=r,t[3]=o,t},o.transpose=function(t,a){if(t===a){var n=a[1];t[1]=a[2],t[2]=n}else t[0]=a[0],t[1]=a[2],t[2]=a[1],t[3]=a[3];return t},o.invert=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=n*u-o*r;return l?(l=1/l,t[0]=u*l,t[1]=-r*l,t[2]=-o*l,t[3]=n*l,t):null},o.adjoint=function(t,a){var n=a[0];return t[0]=a[3],t[1]=-a[1],t[2]=-a[2],t[3]=n,t},o.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},o.multiply=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=n[0],M=n[1],s=n[2],i=n[3];return t[0]=r*e+u*M,t[1]=o*e+l*M,t[2]=r*s+u*i,t[3]=o*s+l*i,t},o.mul=o.multiply,o.rotate=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=Math.sin(n),M=Math.cos(n);return t[0]=r*M+u*e,t[1]=o*M+l*e,t[2]=r*-e+u*M,t[3]=o*-e+l*M,t},o.scale=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=n[0],M=n[1];return t[0]=r*e,t[1]=o*e,t[2]=u*M,t[3]=l*M,t},o.fromRotation=function(t,a){var n=Math.sin(a),r=Math.cos(a);return t[0]=r,t[1]=n,t[2]=-n,t[3]=r,t},o.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=a[1],t},o.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},o.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2))},o.LDU=function(t,a,n,r){return t[2]=r[2]/r[0],n[0]=r[0],n[1]=r[1],n[3]=r[3]-t[2]*n[1],[t,a,n]},o.add=function(t,a,n){return t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t[3]=a[3]+n[3],t},o.subtract=function(t,a,n){return t[0]=a[0]-n[0],t[1]=a[1]-n[1],t[2]=a[2]-n[2],t[3]=a[3]-n[3],t},o.sub=o.subtract,o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]},o.equals=function(t,a){var n=t[0],o=t[1],u=t[2],l=t[3],e=a[0],M=a[1],s=a[2],i=a[3];return Math.abs(n-e)<=r.EPSILON*Math.max(1,Math.abs(n),Math.abs(e))&&Math.abs(o-M)<=r.EPSILON*Math.max(1,Math.abs(o),Math.abs(M))&&Math.abs(u-s)<=r.EPSILON*Math.max(1,Math.abs(u),Math.abs(s))&&Math.abs(l-i)<=r.EPSILON*Math.max(1,Math.abs(l),Math.abs(i))},o.multiplyScalar=function(t,a,n){return t[0]=a[0]*n,t[1]=a[1]*n,t[2]=a[2]*n,t[3]=a[3]*n,t},o.multiplyScalarAndAdd=function(t,a,n,r){return t[0]=a[0]+n[0]*r,t[1]=a[1]+n[1]*r,t[2]=a[2]+n[2]*r,t[3]=a[3]+n[3]*r,t},t.exports=o},function(t,a,n){var r=n(1),o={};o.create=function(){var t=new r.ARRAY_TYPE(6);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},o.clone=function(t){var a=new r.ARRAY_TYPE(6);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[4]=a[4],t[5]=a[5],t},o.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},o.fromValues=function(t,a,n,o,u,l){var e=new r.ARRAY_TYPE(6);return e[0]=t,e[1]=a,e[2]=n,e[3]=o,e[4]=u,e[5]=l,e},o.set=function(t,a,n,r,o,u,l){return t[0]=a,t[1]=n,t[2]=r,t[3]=o,t[4]=u,t[5]=l,t},o.invert=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=a[4],e=a[5],M=n*u-r*o;return M?(M=1/M,t[0]=u*M,t[1]=-r*M,t[2]=-o*M,t[3]=n*M,t[4]=(o*e-u*l)*M,t[5]=(r*l-n*e)*M,t):null},o.determinant=function(t){return t[0]*t[3]-t[1]*t[2]},o.multiply=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=n[0],i=n[1],c=n[2],h=n[3],S=n[4],I=n[5];return t[0]=r*s+u*i,t[1]=o*s+l*i,t[2]=r*c+u*h,t[3]=o*c+l*h,t[4]=r*S+u*I+e,t[5]=o*S+l*I+M,t},o.mul=o.multiply,o.rotate=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=Math.sin(n),i=Math.cos(n);return t[0]=r*i+u*s,t[1]=o*i+l*s,t[2]=r*-s+u*i,t[3]=o*-s+l*i,t[4]=e,t[5]=M,t},o.scale=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=n[0],i=n[1];return t[0]=r*s,t[1]=o*s,t[2]=u*i,t[3]=l*i,t[4]=e,t[5]=M,t},o.translate=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=n[0],i=n[1];return t[0]=r,t[1]=o,t[2]=u,t[3]=l,t[4]=r*s+u*i+e,t[5]=o*s+l*i+M,t},o.fromRotation=function(t,a){var n=Math.sin(a),r=Math.cos(a);return t[0]=r,t[1]=n,t[2]=-n,t[3]=r,t[4]=0,t[5]=0,t},o.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=a[1],t[4]=0,t[5]=0,t},o.fromTranslation=function(t,a){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=a[0],t[5]=a[1],t},o.str=function(t){return"mat2d("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+")"},o.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+1)},o.add=function(t,a,n){return t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t[3]=a[3]+n[3],t[4]=a[4]+n[4],t[5]=a[5]+n[5],t},o.subtract=function(t,a,n){return t[0]=a[0]-n[0],t[1]=a[1]-n[1],t[2]=a[2]-n[2],t[3]=a[3]-n[3],t[4]=a[4]-n[4],t[5]=a[5]-n[5],t},o.sub=o.subtract,o.multiplyScalar=function(t,a,n){return t[0]=a[0]*n,t[1]=a[1]*n,t[2]=a[2]*n,t[3]=a[3]*n,t[4]=a[4]*n,t[5]=a[5]*n,t},o.multiplyScalarAndAdd=function(t,a,n,r){return t[0]=a[0]+n[0]*r,t[1]=a[1]+n[1]*r,t[2]=a[2]+n[2]*r,t[3]=a[3]+n[3]*r,t[4]=a[4]+n[4]*r,t[5]=a[5]+n[5]*r,t},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]&&t[4]===a[4]&&t[5]===a[5]},o.equals=function(t,a){var n=t[0],o=t[1],u=t[2],l=t[3],e=t[4],M=t[5],s=a[0],i=a[1],c=a[2],h=a[3],S=a[4],I=a[5];return Math.abs(n-s)<=r.EPSILON*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(o-i)<=r.EPSILON*Math.max(1,Math.abs(o),Math.abs(i))&&Math.abs(u-c)<=r.EPSILON*Math.max(1,Math.abs(u),Math.abs(c))&&Math.abs(l-h)<=r.EPSILON*Math.max(1,Math.abs(l),Math.abs(h))&&Math.abs(e-S)<=r.EPSILON*Math.max(1,Math.abs(e),Math.abs(S))&&Math.abs(M-I)<=r.EPSILON*Math.max(1,Math.abs(M),Math.abs(I))},t.exports=o},function(t,a,n){var r=n(1),o={};o.create=function(){var t=new r.ARRAY_TYPE(9);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},o.fromMat4=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[4],t[4]=a[5],t[5]=a[6],t[6]=a[8],t[7]=a[9],t[8]=a[10],t},o.clone=function(t){var a=new r.ARRAY_TYPE(9);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t},o.fromValues=function(t,a,n,o,u,l,e,M,s){var i=new r.ARRAY_TYPE(9);return i[0]=t,i[1]=a,i[2]=n,i[3]=o,i[4]=u,i[5]=l,i[6]=e,i[7]=M,i[8]=s,i},o.set=function(t,a,n,r,o,u,l,e,M,s){return t[0]=a,t[1]=n,t[2]=r,t[3]=o,t[4]=u,t[5]=l,t[6]=e,t[7]=M,t[8]=s,t},o.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},o.transpose=function(t,a){if(t===a){var n=a[1],r=a[2],o=a[5];t[1]=a[3],t[2]=a[6],t[3]=n,t[5]=a[7],t[6]=r,t[7]=o}else t[0]=a[0],t[1]=a[3],t[2]=a[6],t[3]=a[1],t[4]=a[4],t[5]=a[7],t[6]=a[2],t[7]=a[5],t[8]=a[8];return t},o.invert=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=a[4],e=a[5],M=a[6],s=a[7],i=a[8],c=i*l-e*s,h=-i*u+e*M,S=s*u-l*M,I=n*c+r*h+o*S;return I?(I=1/I,t[0]=c*I,t[1]=(-i*r+o*s)*I,t[2]=(e*r-o*l)*I,t[3]=h*I,t[4]=(i*n-o*M)*I,t[5]=(-e*n+o*u)*I,t[6]=S*I,t[7]=(-s*n+r*M)*I,t[8]=(l*n-r*u)*I,t):null},o.adjoint=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=a[4],e=a[5],M=a[6],s=a[7],i=a[8];return t[0]=l*i-e*s,t[1]=o*s-r*i,t[2]=r*e-o*l,t[3]=e*M-u*i,t[4]=n*i-o*M,t[5]=o*u-n*e,t[6]=u*s-l*M,t[7]=r*M-n*s,t[8]=n*l-r*u,t},o.determinant=function(t){var a=t[0],n=t[1],r=t[2],o=t[3],u=t[4],l=t[5],e=t[6],M=t[7],s=t[8];return a*(s*u-l*M)+n*(-s*o+l*e)+r*(M*o-u*e)},o.multiply=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=a[6],i=a[7],c=a[8],h=n[0],S=n[1],I=n[2],f=n[3],x=n[4],D=n[5],F=n[6],m=n[7],d=n[8];return t[0]=h*r+S*l+I*s,t[1]=h*o+S*e+I*i,t[2]=h*u+S*M+I*c,t[3]=f*r+x*l+D*s,t[4]=f*o+x*e+D*i,t[5]=f*u+x*M+D*c,t[6]=F*r+m*l+d*s,t[7]=F*o+m*e+d*i,t[8]=F*u+m*M+d*c,t},o.mul=o.multiply,o.translate=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=a[6],i=a[7],c=a[8],h=n[0],S=n[1];return t[0]=r,t[1]=o,t[2]=u,t[3]=l,t[4]=e,t[5]=M,t[6]=h*r+S*l+s,t[7]=h*o+S*e+i,t[8]=h*u+S*M+c,t},o.rotate=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=a[6],i=a[7],c=a[8],h=Math.sin(n),S=Math.cos(n);return t[0]=S*r+h*l,t[1]=S*o+h*e,t[2]=S*u+h*M,t[3]=S*l-h*r,t[4]=S*e-h*o,t[5]=S*M-h*u,t[6]=s,t[7]=i,t[8]=c,t},o.scale=function(t,a,n){var r=n[0],o=n[1];return t[0]=r*a[0],t[1]=r*a[1],t[2]=r*a[2],t[3]=o*a[3],t[4]=o*a[4],t[5]=o*a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t},o.fromTranslation=function(t,a){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=a[0],t[7]=a[1],t[8]=1,t},o.fromRotation=function(t,a){var n=Math.sin(a),r=Math.cos(a);return t[0]=r,t[1]=n,t[2]=0,t[3]=-n,t[4]=r,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},o.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=0,t[4]=a[1],t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},o.fromMat2d=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=0,t[3]=a[2],t[4]=a[3],t[5]=0,t[6]=a[4],t[7]=a[5],t[8]=1,t},o.fromQuat=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=n+n,e=r+r,M=o+o,s=n*l,i=r*l,c=r*e,h=o*l,S=o*e,I=o*M,f=u*l,x=u*e,D=u*M;return t[0]=1-c-I,t[3]=i-D,t[6]=h+x,t[1]=i+D,t[4]=1-s-I,t[7]=S-f,t[2]=h-x,t[5]=S+f,t[8]=1-s-c,t},o.normalFromMat4=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=a[4],e=a[5],M=a[6],s=a[7],i=a[8],c=a[9],h=a[10],S=a[11],I=a[12],f=a[13],x=a[14],D=a[15],F=n*e-r*l,m=n*M-o*l,d=n*s-u*l,b=r*M-o*e,v=r*s-u*e,z=o*s-u*M,p=i*f-c*I,w=i*x-h*I,E=i*D-S*I,A=c*x-h*f,P=c*D-S*f,L=h*D-S*x,q=F*L-m*P+d*A+b*E-v*w+z*p;return q?(q=1/q,t[0]=(e*L-M*P+s*A)*q,t[1]=(M*E-l*L-s*w)*q,t[2]=(l*P-e*E+s*p)*q,t[3]=(o*P-r*L-u*A)*q,t[4]=(n*L-o*E+u*w)*q,t[5]=(r*E-n*P-u*p)*q,t[6]=(f*z-x*v+D*b)*q,t[7]=(x*d-I*z-D*m)*q,t[8]=(I*v-f*d+D*F)*q,t):null},o.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},o.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+Math.pow(t[6],2)+Math.pow(t[7],2)+Math.pow(t[8],2))},o.add=function(t,a,n){return t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t[3]=a[3]+n[3],t[4]=a[4]+n[4],t[5]=a[5]+n[5],t[6]=a[6]+n[6],t[7]=a[7]+n[7],t[8]=a[8]+n[8],t},o.subtract=function(t,a,n){return t[0]=a[0]-n[0],t[1]=a[1]-n[1],t[2]=a[2]-n[2],t[3]=a[3]-n[3],t[4]=a[4]-n[4],t[5]=a[5]-n[5],t[6]=a[6]-n[6],t[7]=a[7]-n[7],t[8]=a[8]-n[8],t},o.sub=o.subtract,o.multiplyScalar=function(t,a,n){return t[0]=a[0]*n,t[1]=a[1]*n,t[2]=a[2]*n,t[3]=a[3]*n,t[4]=a[4]*n,t[5]=a[5]*n,t[6]=a[6]*n,t[7]=a[7]*n,t[8]=a[8]*n,t},o.multiplyScalarAndAdd=function(t,a,n,r){return t[0]=a[0]+n[0]*r,t[1]=a[1]+n[1]*r,t[2]=a[2]+n[2]*r,t[3]=a[3]+n[3]*r,t[4]=a[4]+n[4]*r,t[5]=a[5]+n[5]*r,t[6]=a[6]+n[6]*r,t[7]=a[7]+n[7]*r,t[8]=a[8]+n[8]*r,t},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]&&t[4]===a[4]&&t[5]===a[5]&&t[6]===a[6]&&t[7]===a[7]&&t[8]===a[8]},o.equals=function(t,a){var n=t[0],o=t[1],u=t[2],l=t[3],e=t[4],M=t[5],s=t[6],i=t[7],c=t[8],h=a[0],S=a[1],I=a[2],f=a[3],x=a[4],D=a[5],F=t[6],m=a[7],d=a[8];return Math.abs(n-h)<=r.EPSILON*Math.max(1,Math.abs(n),Math.abs(h))&&Math.abs(o-S)<=r.EPSILON*Math.max(1,Math.abs(o),Math.abs(S))&&Math.abs(u-I)<=r.EPSILON*Math.max(1,Math.abs(u),Math.abs(I))&&Math.abs(l-f)<=r.EPSILON*Math.max(1,Math.abs(l),Math.abs(f))&&Math.abs(e-x)<=r.EPSILON*Math.max(1,Math.abs(e),Math.abs(x))&&Math.abs(M-D)<=r.EPSILON*Math.max(1,Math.abs(M),Math.abs(D))&&Math.abs(s-F)<=r.EPSILON*Math.max(1,Math.abs(s),Math.abs(F))&&Math.abs(i-m)<=r.EPSILON*Math.max(1,Math.abs(i),Math.abs(m))&&Math.abs(c-d)<=r.EPSILON*Math.max(1,Math.abs(c),Math.abs(d))},t.exports=o},function(t,a,n){var r=n(1),o={scalar:{},SIMD:{}};o.create=function(){var t=new r.ARRAY_TYPE(16);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.clone=function(t){var a=new r.ARRAY_TYPE(16);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a[9]=t[9],a[10]=t[10],a[11]=t[11],a[12]=t[12],a[13]=t[13],a[14]=t[14],a[15]=t[15],a},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t[9]=a[9],t[10]=a[10],t[11]=a[11],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15],t},o.fromValues=function(t,a,n,o,u,l,e,M,s,i,c,h,S,I,f,x){var D=new r.ARRAY_TYPE(16);return D[0]=t,D[1]=a,D[2]=n,D[3]=o,D[4]=u,D[5]=l,D[6]=e,D[7]=M,D[8]=s,D[9]=i,D[10]=c,D[11]=h,D[12]=S,D[13]=I,D[14]=f,D[15]=x,D},o.set=function(t,a,n,r,o,u,l,e,M,s,i,c,h,S,I,f,x){return t[0]=a,t[1]=n,t[2]=r,t[3]=o,t[4]=u,t[5]=l,t[6]=e,t[7]=M,t[8]=s,t[9]=i,t[10]=c,t[11]=h,t[12]=S,t[13]=I,t[14]=f,t[15]=x,t},o.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.scalar.transpose=function(t,a){if(t===a){var n=a[1],r=a[2],o=a[3],u=a[6],l=a[7],e=a[11];t[1]=a[4],t[2]=a[8],t[3]=a[12],t[4]=n,t[6]=a[9],t[7]=a[13],t[8]=r,t[9]=u,t[11]=a[14],t[12]=o,t[13]=l,t[14]=e}else t[0]=a[0],t[1]=a[4],t[2]=a[8],t[3]=a[12],t[4]=a[1],t[5]=a[5],t[6]=a[9],t[7]=a[13],t[8]=a[2],t[9]=a[6],t[10]=a[10],t[11]=a[14],t[12]=a[3],t[13]=a[7],t[14]=a[11],t[15]=a[15];return t},o.SIMD.transpose=function(t,a){var n,r,o,u,l,e,M,s,i,c;return n=SIMD.Float32x4.load(a,0),r=SIMD.Float32x4.load(a,4),o=SIMD.Float32x4.load(a,8),u=SIMD.Float32x4.load(a,12),l=SIMD.Float32x4.shuffle(n,r,0,1,4,5),e=SIMD.Float32x4.shuffle(o,u,0,1,4,5),M=SIMD.Float32x4.shuffle(l,e,0,2,4,6),s=SIMD.Float32x4.shuffle(l,e,1,3,5,7),SIMD.Float32x4.store(t,0,M),SIMD.Float32x4.store(t,4,s),l=SIMD.Float32x4.shuffle(n,r,2,3,6,7),e=SIMD.Float32x4.shuffle(o,u,2,3,6,7),i=SIMD.Float32x4.shuffle(l,e,0,2,4,6),c=SIMD.Float32x4.shuffle(l,e,1,3,5,7),SIMD.Float32x4.store(t,8,i),SIMD.Float32x4.store(t,12,c),t},o.transpose=r.USE_SIMD?o.SIMD.transpose:o.scalar.transpose,o.scalar.invert=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=a[4],e=a[5],M=a[6],s=a[7],i=a[8],c=a[9],h=a[10],S=a[11],I=a[12],f=a[13],x=a[14],D=a[15],F=n*e-r*l,m=n*M-o*l,d=n*s-u*l,b=r*M-o*e,v=r*s-u*e,z=o*s-u*M,p=i*f-c*I,w=i*x-h*I,E=i*D-S*I,A=c*x-h*f,P=c*D-S*f,L=h*D-S*x,q=F*L-m*P+d*A+b*E-v*w+z*p;return q?(q=1/q,t[0]=(e*L-M*P+s*A)*q,t[1]=(o*P-r*L-u*A)*q,t[2]=(f*z-x*v+D*b)*q,t[3]=(h*v-c*z-S*b)*q,t[4]=(M*E-l*L-s*w)*q,t[5]=(n*L-o*E+u*w)*q,t[6]=(x*d-I*z-D*m)*q,t[7]=(i*z-h*d+S*m)*q,t[8]=(l*P-e*E+s*p)*q,t[9]=(r*E-n*P-u*p)*q,t[10]=(I*v-f*d+D*F)*q,t[11]=(c*d-i*v-S*F)*q,t[12]=(e*w-l*A-M*p)*q,t[13]=(n*A-r*w+o*p)*q,t[14]=(f*m-I*b-x*F)*q,t[15]=(i*b-c*m+h*F)*q,t):null},o.SIMD.invert=function(t,a){var n,r,o,u,l,e,M,s,i,c,h=SIMD.Float32x4.load(a,0),S=SIMD.Float32x4.load(a,4),I=SIMD.Float32x4.load(a,8),f=SIMD.Float32x4.load(a,12);return l=SIMD.Float32x4.shuffle(h,S,0,1,4,5),r=SIMD.Float32x4.shuffle(I,f,0,1,4,5),n=SIMD.Float32x4.shuffle(l,r,0,2,4,6),r=SIMD.Float32x4.shuffle(r,l,1,3,5,7),l=SIMD.Float32x4.shuffle(h,S,2,3,6,7),u=SIMD.Float32x4.shuffle(I,f,2,3,6,7),o=SIMD.Float32x4.shuffle(l,u,0,2,4,6),u=SIMD.Float32x4.shuffle(u,l,1,3,5,7),l=SIMD.Float32x4.mul(o,u),l=SIMD.Float32x4.swizzle(l,1,0,3,2),e=SIMD.Float32x4.mul(r,l),M=SIMD.Float32x4.mul(n,l),l=SIMD.Float32x4.swizzle(l,2,3,0,1),e=SIMD.Float32x4.sub(SIMD.Float32x4.mul(r,l),e),M=SIMD.Float32x4.sub(SIMD.Float32x4.mul(n,l),M),M=SIMD.Float32x4.swizzle(M,2,3,0,1),l=SIMD.Float32x4.mul(r,o),l=SIMD.Float32x4.swizzle(l,1,0,3,2),e=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,l),e),i=SIMD.Float32x4.mul(n,l),l=SIMD.Float32x4.swizzle(l,2,3,0,1),e=SIMD.Float32x4.sub(e,SIMD.Float32x4.mul(u,l)),i=SIMD.Float32x4.sub(SIMD.Float32x4.mul(n,l),i),i=SIMD.Float32x4.swizzle(i,2,3,0,1),l=SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(r,2,3,0,1),u),l=SIMD.Float32x4.swizzle(l,1,0,3,2),o=SIMD.Float32x4.swizzle(o,2,3,0,1),e=SIMD.Float32x4.add(SIMD.Float32x4.mul(o,l),e),s=SIMD.Float32x4.mul(n,l),l=SIMD.Float32x4.swizzle(l,2,3,0,1),e=SIMD.Float32x4.sub(e,SIMD.Float32x4.mul(o,l)),s=SIMD.Float32x4.sub(SIMD.Float32x4.mul(n,l),s),s=SIMD.Float32x4.swizzle(s,2,3,0,1),l=SIMD.Float32x4.mul(n,r),l=SIMD.Float32x4.swizzle(l,1,0,3,2),s=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,l),s),i=SIMD.Float32x4.sub(SIMD.Float32x4.mul(o,l),i),l=SIMD.Float32x4.swizzle(l,2,3,0,1),s=SIMD.Float32x4.sub(SIMD.Float32x4.mul(u,l),s),i=SIMD.Float32x4.sub(i,SIMD.Float32x4.mul(o,l)),l=SIMD.Float32x4.mul(n,u),l=SIMD.Float32x4.swizzle(l,1,0,3,2),M=SIMD.Float32x4.sub(M,SIMD.Float32x4.mul(o,l)),s=SIMD.Float32x4.add(SIMD.Float32x4.mul(r,l),s),l=SIMD.Float32x4.swizzle(l,2,3,0,1),M=SIMD.Float32x4.add(SIMD.Float32x4.mul(o,l),M),s=SIMD.Float32x4.sub(s,SIMD.Float32x4.mul(r,l)),l=SIMD.Float32x4.mul(n,o),l=SIMD.Float32x4.swizzle(l,1,0,3,2),M=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,l),M),i=SIMD.Float32x4.sub(i,SIMD.Float32x4.mul(r,l)),l=SIMD.Float32x4.swizzle(l,2,3,0,1),M=SIMD.Float32x4.sub(M,SIMD.Float32x4.mul(u,l)),i=SIMD.Float32x4.add(SIMD.Float32x4.mul(r,l),i),c=SIMD.Float32x4.mul(n,e),c=SIMD.Float32x4.add(SIMD.Float32x4.swizzle(c,2,3,0,1),c),c=SIMD.Float32x4.add(SIMD.Float32x4.swizzle(c,1,0,3,2),c),l=SIMD.Float32x4.reciprocalApproximation(c),c=SIMD.Float32x4.sub(SIMD.Float32x4.add(l,l),SIMD.Float32x4.mul(c,SIMD.Float32x4.mul(l,l))),(c=SIMD.Float32x4.swizzle(c,0,0,0,0))?(SIMD.Float32x4.store(t,0,SIMD.Float32x4.mul(c,e)),SIMD.Float32x4.store(t,4,SIMD.Float32x4.mul(c,M)),SIMD.Float32x4.store(t,8,SIMD.Float32x4.mul(c,s)),SIMD.Float32x4.store(t,12,SIMD.Float32x4.mul(c,i)),t):null},o.invert=r.USE_SIMD?o.SIMD.invert:o.scalar.invert,o.scalar.adjoint=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=a[4],e=a[5],M=a[6],s=a[7],i=a[8],c=a[9],h=a[10],S=a[11],I=a[12],f=a[13],x=a[14],D=a[15];return t[0]=e*(h*D-S*x)-c*(M*D-s*x)+f*(M*S-s*h),t[1]=-(r*(h*D-S*x)-c*(o*D-u*x)+f*(o*S-u*h)),t[2]=r*(M*D-s*x)-e*(o*D-u*x)+f*(o*s-u*M),t[3]=-(r*(M*S-s*h)-e*(o*S-u*h)+c*(o*s-u*M)),t[4]=-(l*(h*D-S*x)-i*(M*D-s*x)+I*(M*S-s*h)),t[5]=n*(h*D-S*x)-i*(o*D-u*x)+I*(o*S-u*h),t[6]=-(n*(M*D-s*x)-l*(o*D-u*x)+I*(o*s-u*M)),t[7]=n*(M*S-s*h)-l*(o*S-u*h)+i*(o*s-u*M),t[8]=l*(c*D-S*f)-i*(e*D-s*f)+I*(e*S-s*c),t[9]=-(n*(c*D-S*f)-i*(r*D-u*f)+I*(r*S-u*c)),t[10]=n*(e*D-s*f)-l*(r*D-u*f)+I*(r*s-u*e),t[11]=-(n*(e*S-s*c)-l*(r*S-u*c)+i*(r*s-u*e)),t[12]=-(l*(c*x-h*f)-i*(e*x-M*f)+I*(e*h-M*c)),t[13]=n*(c*x-h*f)-i*(r*x-o*f)+I*(r*h-o*c),t[14]=-(n*(e*x-M*f)-l*(r*x-o*f)+I*(r*M-o*e)),t[15]=n*(e*h-M*c)-l*(r*h-o*c)+i*(r*M-o*e),t},o.SIMD.adjoint=function(t,a){var n,r,o,u,l,e,M,s,i,c,h,S,I;return n=SIMD.Float32x4.load(a,0),r=SIMD.Float32x4.load(a,4),o=SIMD.Float32x4.load(a,8),u=SIMD.Float32x4.load(a,12),i=SIMD.Float32x4.shuffle(n,r,0,1,4,5),e=SIMD.Float32x4.shuffle(o,u,0,1,4,5),l=SIMD.Float32x4.shuffle(i,e,0,2,4,6),e=SIMD.Float32x4.shuffle(e,i,1,3,5,7),i=SIMD.Float32x4.shuffle(n,r,2,3,6,7),s=SIMD.Float32x4.shuffle(o,u,2,3,6,7),M=SIMD.Float32x4.shuffle(i,s,0,2,4,6),s=SIMD.Float32x4.shuffle(s,i,1,3,5,7),i=SIMD.Float32x4.mul(M,s),i=SIMD.Float32x4.swizzle(i,1,0,3,2),c=SIMD.Float32x4.mul(e,i),h=SIMD.Float32x4.mul(l,i),i=SIMD.Float32x4.swizzle(i,2,3,0,1),c=SIMD.Float32x4.sub(SIMD.Float32x4.mul(e,i),c),h=SIMD.Float32x4.sub(SIMD.Float32x4.mul(l,i),h),h=SIMD.Float32x4.swizzle(h,2,3,0,1),i=SIMD.Float32x4.mul(e,M),i=SIMD.Float32x4.swizzle(i,1,0,3,2),c=SIMD.Float32x4.add(SIMD.Float32x4.mul(s,i),c),I=SIMD.Float32x4.mul(l,i),i=SIMD.Float32x4.swizzle(i,2,3,0,1),c=SIMD.Float32x4.sub(c,SIMD.Float32x4.mul(s,i)),I=SIMD.Float32x4.sub(SIMD.Float32x4.mul(l,i),I),I=SIMD.Float32x4.swizzle(I,2,3,0,1),i=SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(e,2,3,0,1),s),i=SIMD.Float32x4.swizzle(i,1,0,3,2),M=SIMD.Float32x4.swizzle(M,2,3,0,1),c=SIMD.Float32x4.add(SIMD.Float32x4.mul(M,i),c),S=SIMD.Float32x4.mul(l,i),i=SIMD.Float32x4.swizzle(i,2,3,0,1),c=SIMD.Float32x4.sub(c,SIMD.Float32x4.mul(M,i)),S=SIMD.Float32x4.sub(SIMD.Float32x4.mul(l,i),S),S=SIMD.Float32x4.swizzle(S,2,3,0,1),i=SIMD.Float32x4.mul(l,e),i=SIMD.Float32x4.swizzle(i,1,0,3,2),S=SIMD.Float32x4.add(SIMD.Float32x4.mul(s,i),S),I=SIMD.Float32x4.sub(SIMD.Float32x4.mul(M,i),I),i=SIMD.Float32x4.swizzle(i,2,3,0,1),S=SIMD.Float32x4.sub(SIMD.Float32x4.mul(s,i),S),I=SIMD.Float32x4.sub(I,SIMD.Float32x4.mul(M,i)),i=SIMD.Float32x4.mul(l,s),i=SIMD.Float32x4.swizzle(i,1,0,3,2),h=SIMD.Float32x4.sub(h,SIMD.Float32x4.mul(M,i)),S=SIMD.Float32x4.add(SIMD.Float32x4.mul(e,i),S),i=SIMD.Float32x4.swizzle(i,2,3,0,1),h=SIMD.Float32x4.add(SIMD.Float32x4.mul(M,i),h),S=SIMD.Float32x4.sub(S,SIMD.Float32x4.mul(e,i)),i=SIMD.Float32x4.mul(l,M),i=SIMD.Float32x4.swizzle(i,1,0,3,2),h=SIMD.Float32x4.add(SIMD.Float32x4.mul(s,i),h),I=SIMD.Float32x4.sub(I,SIMD.Float32x4.mul(e,i)),i=SIMD.Float32x4.swizzle(i,2,3,0,1),h=SIMD.Float32x4.sub(h,SIMD.Float32x4.mul(s,i)),I=SIMD.Float32x4.add(SIMD.Float32x4.mul(e,i),I),SIMD.Float32x4.store(t,0,c),SIMD.Float32x4.store(t,4,h),SIMD.Float32x4.store(t,8,S),SIMD.Float32x4.store(t,12,I),t},o.adjoint=r.USE_SIMD?o.SIMD.adjoint:o.scalar.adjoint,o.determinant=function(t){var a=t[0],n=t[1],r=t[2],o=t[3],u=t[4],l=t[5],e=t[6],M=t[7],s=t[8],i=t[9],c=t[10],h=t[11],S=t[12],I=t[13],f=t[14],x=t[15];return(a*l-n*u)*(c*x-h*f)-(a*e-r*u)*(i*x-h*I)+(a*M-o*u)*(i*f-c*I)+(n*e-r*l)*(s*x-h*S)-(n*M-o*l)*(s*f-c*S)+(r*M-o*e)*(s*I-i*S)},o.SIMD.multiply=function(t,a,n){var r=SIMD.Float32x4.load(a,0),o=SIMD.Float32x4.load(a,4),u=SIMD.Float32x4.load(a,8),l=SIMD.Float32x4.load(a,12),e=SIMD.Float32x4.load(n,0),M=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(e,0,0,0,0),r),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(e,1,1,1,1),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(e,2,2,2,2),u),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(e,3,3,3,3),l))));SIMD.Float32x4.store(t,0,M);var s=SIMD.Float32x4.load(n,4),i=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,0,0,0,0),r),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,1,1,1,1),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,2,2,2,2),u),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,3,3,3,3),l))));SIMD.Float32x4.store(t,4,i);var c=SIMD.Float32x4.load(n,8),h=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(c,0,0,0,0),r),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(c,1,1,1,1),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(c,2,2,2,2),u),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(c,3,3,3,3),l))));SIMD.Float32x4.store(t,8,h);var S=SIMD.Float32x4.load(n,12),I=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(S,0,0,0,0),r),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(S,1,1,1,1),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(S,2,2,2,2),u),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(S,3,3,3,3),l))));return SIMD.Float32x4.store(t,12,I),t},o.scalar.multiply=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=a[6],i=a[7],c=a[8],h=a[9],S=a[10],I=a[11],f=a[12],x=a[13],D=a[14],F=a[15],m=n[0],d=n[1],b=n[2],v=n[3];return t[0]=m*r+d*e+b*c+v*f,t[1]=m*o+d*M+b*h+v*x,t[2]=m*u+d*s+b*S+v*D,t[3]=m*l+d*i+b*I+v*F,m=n[4],d=n[5],b=n[6],v=n[7],t[4]=m*r+d*e+b*c+v*f,t[5]=m*o+d*M+b*h+v*x,t[6]=m*u+d*s+b*S+v*D,t[7]=m*l+d*i+b*I+v*F,m=n[8],d=n[9],b=n[10],v=n[11],t[8]=m*r+d*e+b*c+v*f,t[9]=m*o+d*M+b*h+v*x,t[10]=m*u+d*s+b*S+v*D,t[11]=m*l+d*i+b*I+v*F,m=n[12],d=n[13],b=n[14],v=n[15],t[12]=m*r+d*e+b*c+v*f,t[13]=m*o+d*M+b*h+v*x,t[14]=m*u+d*s+b*S+v*D,t[15]=m*l+d*i+b*I+v*F,t},o.multiply=r.USE_SIMD?o.SIMD.multiply:o.scalar.multiply,o.mul=o.multiply,o.scalar.translate=function(t,a,n){var r,o,u,l,e,M,s,i,c,h,S,I,f=n[0],x=n[1],D=n[2];return a===t?(t[12]=a[0]*f+a[4]*x+a[8]*D+a[12],t[13]=a[1]*f+a[5]*x+a[9]*D+a[13],t[14]=a[2]*f+a[6]*x+a[10]*D+a[14],t[15]=a[3]*f+a[7]*x+a[11]*D+a[15]):(r=a[0],o=a[1],u=a[2],l=a[3],e=a[4],M=a[5],s=a[6],i=a[7],c=a[8],h=a[9],S=a[10],I=a[11],t[0]=r,t[1]=o,t[2]=u,t[3]=l,t[4]=e,t[5]=M,t[6]=s,t[7]=i,t[8]=c,t[9]=h,t[10]=S,t[11]=I,t[12]=r*f+e*x+c*D+a[12],t[13]=o*f+M*x+h*D+a[13],t[14]=u*f+s*x+S*D+a[14],t[15]=l*f+i*x+I*D+a[15]),t},o.SIMD.translate=function(t,a,n){var r=SIMD.Float32x4.load(a,0),o=SIMD.Float32x4.load(a,4),u=SIMD.Float32x4.load(a,8),l=SIMD.Float32x4.load(a,12),e=SIMD.Float32x4(n[0],n[1],n[2],0);a!==t&&(t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t[9]=a[9],t[10]=a[10],t[11]=a[11]),r=SIMD.Float32x4.mul(r,SIMD.Float32x4.swizzle(e,0,0,0,0)),o=SIMD.Float32x4.mul(o,SIMD.Float32x4.swizzle(e,1,1,1,1)),u=SIMD.Float32x4.mul(u,SIMD.Float32x4.swizzle(e,2,2,2,2));var M=SIMD.Float32x4.add(r,SIMD.Float32x4.add(o,SIMD.Float32x4.add(u,l)));return SIMD.Float32x4.store(t,12,M),t},o.translate=r.USE_SIMD?o.SIMD.translate:o.scalar.translate,o.scalar.scale=function(t,a,n){var r=n[0],o=n[1],u=n[2];return t[0]=a[0]*r,t[1]=a[1]*r,t[2]=a[2]*r,t[3]=a[3]*r,t[4]=a[4]*o,t[5]=a[5]*o,t[6]=a[6]*o,t[7]=a[7]*o,t[8]=a[8]*u,t[9]=a[9]*u,t[10]=a[10]*u,t[11]=a[11]*u,t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15],t},o.SIMD.scale=function(t,a,n){var r,o,u,l=SIMD.Float32x4(n[0],n[1],n[2],0);return r=SIMD.Float32x4.load(a,0),SIMD.Float32x4.store(t,0,SIMD.Float32x4.mul(r,SIMD.Float32x4.swizzle(l,0,0,0,0))),o=SIMD.Float32x4.load(a,4),SIMD.Float32x4.store(t,4,SIMD.Float32x4.mul(o,SIMD.Float32x4.swizzle(l,1,1,1,1))),u=SIMD.Float32x4.load(a,8),SIMD.Float32x4.store(t,8,SIMD.Float32x4.mul(u,SIMD.Float32x4.swizzle(l,2,2,2,2))),t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15],t},o.scale=r.USE_SIMD?o.SIMD.scale:o.scalar.scale,o.rotate=function(t,a,n,o){var u,l,e,M,s,i,c,h,S,I,f,x,D,F,m,d,b,v,z,p,w,E,A,P,L=o[0],q=o[1],R=o[2],N=Math.sqrt(L*L+q*q+R*R);return Math.abs(N)<r.EPSILON?null:(N=1/N,L*=N,q*=N,R*=N,u=Math.sin(n),l=Math.cos(n),e=1-l,M=a[0],s=a[1],i=a[2],c=a[3],h=a[4],S=a[5],I=a[6],f=a[7],x=a[8],D=a[9],F=a[10],m=a[11],d=L*L*e+l,b=q*L*e+R*u,v=R*L*e-q*u,z=L*q*e-R*u,p=q*q*e+l,w=R*q*e+L*u,E=L*R*e+q*u,A=q*R*e-L*u,P=R*R*e+l,t[0]=M*d+h*b+x*v,t[1]=s*d+S*b+D*v,t[2]=i*d+I*b+F*v,t[3]=c*d+f*b+m*v,t[4]=M*z+h*p+x*w,t[5]=s*z+S*p+D*w,t[6]=i*z+I*p+F*w,t[7]=c*z+f*p+m*w,t[8]=M*E+h*A+x*P,t[9]=s*E+S*A+D*P,t[10]=i*E+I*A+F*P,t[11]=c*E+f*A+m*P,a!==t&&(t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t)},o.scalar.rotateX=function(t,a,n){var r=Math.sin(n),o=Math.cos(n),u=a[4],l=a[5],e=a[6],M=a[7],s=a[8],i=a[9],c=a[10],h=a[11];return a!==t&&(t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t[4]=u*o+s*r,t[5]=l*o+i*r,t[6]=e*o+c*r,t[7]=M*o+h*r,t[8]=s*o-u*r,t[9]=i*o-l*r,t[10]=c*o-e*r,t[11]=h*o-M*r,t},o.SIMD.rotateX=function(t,a,n){var r=SIMD.Float32x4.splat(Math.sin(n)),o=SIMD.Float32x4.splat(Math.cos(n));a!==t&&(t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]);var u=SIMD.Float32x4.load(a,4),l=SIMD.Float32x4.load(a,8);return SIMD.Float32x4.store(t,4,SIMD.Float32x4.add(SIMD.Float32x4.mul(u,o),SIMD.Float32x4.mul(l,r))),SIMD.Float32x4.store(t,8,SIMD.Float32x4.sub(SIMD.Float32x4.mul(l,o),SIMD.Float32x4.mul(u,r))),t},o.rotateX=r.USE_SIMD?o.SIMD.rotateX:o.scalar.rotateX,o.scalar.rotateY=function(t,a,n){var r=Math.sin(n),o=Math.cos(n),u=a[0],l=a[1],e=a[2],M=a[3],s=a[8],i=a[9],c=a[10],h=a[11];return a!==t&&(t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t[0]=u*o-s*r,t[1]=l*o-i*r,t[2]=e*o-c*r,t[3]=M*o-h*r,t[8]=u*r+s*o,t[9]=l*r+i*o,t[10]=e*r+c*o,t[11]=M*r+h*o,t},o.SIMD.rotateY=function(t,a,n){var r=SIMD.Float32x4.splat(Math.sin(n)),o=SIMD.Float32x4.splat(Math.cos(n));a!==t&&(t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]);var u=SIMD.Float32x4.load(a,0),l=SIMD.Float32x4.load(a,8);return SIMD.Float32x4.store(t,0,SIMD.Float32x4.sub(SIMD.Float32x4.mul(u,o),SIMD.Float32x4.mul(l,r))),SIMD.Float32x4.store(t,8,SIMD.Float32x4.add(SIMD.Float32x4.mul(u,r),SIMD.Float32x4.mul(l,o))),t},o.rotateY=r.USE_SIMD?o.SIMD.rotateY:o.scalar.rotateY,o.scalar.rotateZ=function(t,a,n){var r=Math.sin(n),o=Math.cos(n),u=a[0],l=a[1],e=a[2],M=a[3],s=a[4],i=a[5],c=a[6],h=a[7];return a!==t&&(t[8]=a[8],t[9]=a[9],t[10]=a[10],t[11]=a[11],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t[0]=u*o+s*r,t[1]=l*o+i*r,t[2]=e*o+c*r,t[3]=M*o+h*r,t[4]=s*o-u*r,t[5]=i*o-l*r,t[6]=c*o-e*r,t[7]=h*o-M*r,t},o.SIMD.rotateZ=function(t,a,n){var r=SIMD.Float32x4.splat(Math.sin(n)),o=SIMD.Float32x4.splat(Math.cos(n));a!==t&&(t[8]=a[8],t[9]=a[9],t[10]=a[10],t[11]=a[11],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]);var u=SIMD.Float32x4.load(a,0),l=SIMD.Float32x4.load(a,4);return SIMD.Float32x4.store(t,0,SIMD.Float32x4.add(SIMD.Float32x4.mul(u,o),SIMD.Float32x4.mul(l,r))),SIMD.Float32x4.store(t,4,SIMD.Float32x4.sub(SIMD.Float32x4.mul(l,o),SIMD.Float32x4.mul(u,r))),t},o.rotateZ=r.USE_SIMD?o.SIMD.rotateZ:o.scalar.rotateZ,o.fromTranslation=function(t,a){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=a[0],t[13]=a[1],t[14]=a[2],t[15]=1,t},o.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=a[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.fromRotation=function(t,a,n){var o,u,l,e=n[0],M=n[1],s=n[2],i=Math.sqrt(e*e+M*M+s*s);return Math.abs(i)<r.EPSILON?null:(i=1/i,e*=i,M*=i,s*=i,o=Math.sin(a),u=Math.cos(a),l=1-u,t[0]=e*e*l+u,t[1]=M*e*l+s*o,t[2]=s*e*l-M*o,t[3]=0,t[4]=e*M*l-s*o,t[5]=M*M*l+u,t[6]=s*M*l+e*o,t[7]=0,t[8]=e*s*l+M*o,t[9]=M*s*l-e*o,t[10]=s*s*l+u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)},o.fromXRotation=function(t,a){var n=Math.sin(a),r=Math.cos(a);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=r,t[6]=n,t[7]=0,t[8]=0,t[9]=-n,t[10]=r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.fromYRotation=function(t,a){var n=Math.sin(a),r=Math.cos(a);return t[0]=r,t[1]=0,t[2]=-n,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=n,t[9]=0,t[10]=r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.fromZRotation=function(t,a){var n=Math.sin(a),r=Math.cos(a);return t[0]=r,t[1]=n,t[2]=0,t[3]=0,t[4]=-n,t[5]=r,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.fromRotationTranslation=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=r+r,M=o+o,s=u+u,i=r*e,c=r*M,h=r*s,S=o*M,I=o*s,f=u*s,x=l*e,D=l*M,F=l*s;return t[0]=1-(S+f),t[1]=c+F,t[2]=h-D,t[3]=0,t[4]=c-F,t[5]=1-(i+f),t[6]=I+x,t[7]=0,t[8]=h+D,t[9]=I-x,t[10]=1-(i+S),t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t},o.getTranslation=function(t,a){return t[0]=a[12],t[1]=a[13],t[2]=a[14],t},o.getRotation=function(t,a){var n=a[0]+a[5]+a[10],r=0;return n>0?(r=2*Math.sqrt(n+1),t[3]=.25*r,t[0]=(a[6]-a[9])/r,t[1]=(a[8]-a[2])/r,t[2]=(a[1]-a[4])/r):a[0]>a[5]&a[0]>a[10]?(r=2*Math.sqrt(1+a[0]-a[5]-a[10]),t[3]=(a[6]-a[9])/r,t[0]=.25*r,t[1]=(a[1]+a[4])/r,t[2]=(a[8]+a[2])/r):a[5]>a[10]?(r=2*Math.sqrt(1+a[5]-a[0]-a[10]),t[3]=(a[8]-a[2])/r,t[0]=(a[1]+a[4])/r,t[1]=.25*r,t[2]=(a[6]+a[9])/r):(r=2*Math.sqrt(1+a[10]-a[0]-a[5]),t[3]=(a[1]-a[4])/r,t[0]=(a[8]+a[2])/r,t[1]=(a[6]+a[9])/r,t[2]=.25*r),t},o.fromRotationTranslationScale=function(t,a,n,r){var o=a[0],u=a[1],l=a[2],e=a[3],M=o+o,s=u+u,i=l+l,c=o*M,h=o*s,S=o*i,I=u*s,f=u*i,x=l*i,D=e*M,F=e*s,m=e*i,d=r[0],b=r[1],v=r[2];return t[0]=(1-(I+x))*d,t[1]=(h+m)*d,t[2]=(S-F)*d,t[3]=0,t[4]=(h-m)*b,t[5]=(1-(c+x))*b,t[6]=(f+D)*b,t[7]=0,t[8]=(S+F)*v,t[9]=(f-D)*v,t[10]=(1-(c+I))*v,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t},
o.fromRotationTranslationScaleOrigin=function(t,a,n,r,o){var u=a[0],l=a[1],e=a[2],M=a[3],s=u+u,i=l+l,c=e+e,h=u*s,S=u*i,I=u*c,f=l*i,x=l*c,D=e*c,F=M*s,m=M*i,d=M*c,b=r[0],v=r[1],z=r[2],p=o[0],w=o[1],E=o[2];return t[0]=(1-(f+D))*b,t[1]=(S+d)*b,t[2]=(I-m)*b,t[3]=0,t[4]=(S-d)*v,t[5]=(1-(h+D))*v,t[6]=(x+F)*v,t[7]=0,t[8]=(I+m)*z,t[9]=(x-F)*z,t[10]=(1-(h+f))*z,t[11]=0,t[12]=n[0]+p-(t[0]*p+t[4]*w+t[8]*E),t[13]=n[1]+w-(t[1]*p+t[5]*w+t[9]*E),t[14]=n[2]+E-(t[2]*p+t[6]*w+t[10]*E),t[15]=1,t},o.fromQuat=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=n+n,e=r+r,M=o+o,s=n*l,i=r*l,c=r*e,h=o*l,S=o*e,I=o*M,f=u*l,x=u*e,D=u*M;return t[0]=1-c-I,t[1]=i+D,t[2]=h-x,t[3]=0,t[4]=i-D,t[5]=1-s-I,t[6]=S+f,t[7]=0,t[8]=h+x,t[9]=S-f,t[10]=1-s-c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.frustum=function(t,a,n,r,o,u,l){var e=1/(n-a),M=1/(o-r),s=1/(u-l);return t[0]=2*u*e,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*u*M,t[6]=0,t[7]=0,t[8]=(n+a)*e,t[9]=(o+r)*M,t[10]=(l+u)*s,t[11]=-1,t[12]=0,t[13]=0,t[14]=l*u*2*s,t[15]=0,t},o.perspective=function(t,a,n,r,o){var u=1/Math.tan(a/2),l=1/(r-o);return t[0]=u/n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=(o+r)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*o*r*l,t[15]=0,t},o.perspectiveFromFieldOfView=function(t,a,n,r){var o=Math.tan(a.upDegrees*Math.PI/180),u=Math.tan(a.downDegrees*Math.PI/180),l=Math.tan(a.leftDegrees*Math.PI/180),e=Math.tan(a.rightDegrees*Math.PI/180),M=2/(l+e),s=2/(o+u);return t[0]=M,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=-(l-e)*M*.5,t[9]=(o-u)*s*.5,t[10]=r/(n-r),t[11]=-1,t[12]=0,t[13]=0,t[14]=r*n/(n-r),t[15]=0,t},o.ortho=function(t,a,n,r,o,u,l){var e=1/(a-n),M=1/(r-o),s=1/(u-l);return t[0]=-2*e,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*M,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*s,t[11]=0,t[12]=(a+n)*e,t[13]=(o+r)*M,t[14]=(l+u)*s,t[15]=1,t},o.lookAt=function(t,a,n,u){var l,e,M,s,i,c,h,S,I,f,x=a[0],D=a[1],F=a[2],m=u[0],d=u[1],b=u[2],v=n[0],z=n[1],p=n[2];return Math.abs(x-v)<r.EPSILON&&Math.abs(D-z)<r.EPSILON&&Math.abs(F-p)<r.EPSILON?o.identity(t):(h=x-v,S=D-z,I=F-p,f=1/Math.sqrt(h*h+S*S+I*I),h*=f,S*=f,I*=f,l=d*I-b*S,e=b*h-m*I,M=m*S-d*h,f=Math.sqrt(l*l+e*e+M*M),f?(f=1/f,l*=f,e*=f,M*=f):(l=0,e=0,M=0),s=S*M-I*e,i=I*l-h*M,c=h*e-S*l,f=Math.sqrt(s*s+i*i+c*c),f?(f=1/f,s*=f,i*=f,c*=f):(s=0,i=0,c=0),t[0]=l,t[1]=s,t[2]=h,t[3]=0,t[4]=e,t[5]=i,t[6]=S,t[7]=0,t[8]=M,t[9]=c,t[10]=I,t[11]=0,t[12]=-(l*x+e*D+M*F),t[13]=-(s*x+i*D+c*F),t[14]=-(h*x+S*D+I*F),t[15]=1,t)},o.str=function(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"},o.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+Math.pow(t[6],2)+Math.pow(t[7],2)+Math.pow(t[8],2)+Math.pow(t[9],2)+Math.pow(t[10],2)+Math.pow(t[11],2)+Math.pow(t[12],2)+Math.pow(t[13],2)+Math.pow(t[14],2)+Math.pow(t[15],2))},o.add=function(t,a,n){return t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t[3]=a[3]+n[3],t[4]=a[4]+n[4],t[5]=a[5]+n[5],t[6]=a[6]+n[6],t[7]=a[7]+n[7],t[8]=a[8]+n[8],t[9]=a[9]+n[9],t[10]=a[10]+n[10],t[11]=a[11]+n[11],t[12]=a[12]+n[12],t[13]=a[13]+n[13],t[14]=a[14]+n[14],t[15]=a[15]+n[15],t},o.subtract=function(t,a,n){return t[0]=a[0]-n[0],t[1]=a[1]-n[1],t[2]=a[2]-n[2],t[3]=a[3]-n[3],t[4]=a[4]-n[4],t[5]=a[5]-n[5],t[6]=a[6]-n[6],t[7]=a[7]-n[7],t[8]=a[8]-n[8],t[9]=a[9]-n[9],t[10]=a[10]-n[10],t[11]=a[11]-n[11],t[12]=a[12]-n[12],t[13]=a[13]-n[13],t[14]=a[14]-n[14],t[15]=a[15]-n[15],t},o.sub=o.subtract,o.multiplyScalar=function(t,a,n){return t[0]=a[0]*n,t[1]=a[1]*n,t[2]=a[2]*n,t[3]=a[3]*n,t[4]=a[4]*n,t[5]=a[5]*n,t[6]=a[6]*n,t[7]=a[7]*n,t[8]=a[8]*n,t[9]=a[9]*n,t[10]=a[10]*n,t[11]=a[11]*n,t[12]=a[12]*n,t[13]=a[13]*n,t[14]=a[14]*n,t[15]=a[15]*n,t},o.multiplyScalarAndAdd=function(t,a,n,r){return t[0]=a[0]+n[0]*r,t[1]=a[1]+n[1]*r,t[2]=a[2]+n[2]*r,t[3]=a[3]+n[3]*r,t[4]=a[4]+n[4]*r,t[5]=a[5]+n[5]*r,t[6]=a[6]+n[6]*r,t[7]=a[7]+n[7]*r,t[8]=a[8]+n[8]*r,t[9]=a[9]+n[9]*r,t[10]=a[10]+n[10]*r,t[11]=a[11]+n[11]*r,t[12]=a[12]+n[12]*r,t[13]=a[13]+n[13]*r,t[14]=a[14]+n[14]*r,t[15]=a[15]+n[15]*r,t},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]&&t[4]===a[4]&&t[5]===a[5]&&t[6]===a[6]&&t[7]===a[7]&&t[8]===a[8]&&t[9]===a[9]&&t[10]===a[10]&&t[11]===a[11]&&t[12]===a[12]&&t[13]===a[13]&&t[14]===a[14]&&t[15]===a[15]},o.equals=function(t,a){var n=t[0],o=t[1],u=t[2],l=t[3],e=t[4],M=t[5],s=t[6],i=t[7],c=t[8],h=t[9],S=t[10],I=t[11],f=t[12],x=t[13],D=t[14],F=t[15],m=a[0],d=a[1],b=a[2],v=a[3],z=a[4],p=a[5],w=a[6],E=a[7],A=a[8],P=a[9],L=a[10],q=a[11],R=a[12],N=a[13],O=a[14],Y=a[15];return Math.abs(n-m)<=r.EPSILON*Math.max(1,Math.abs(n),Math.abs(m))&&Math.abs(o-d)<=r.EPSILON*Math.max(1,Math.abs(o),Math.abs(d))&&Math.abs(u-b)<=r.EPSILON*Math.max(1,Math.abs(u),Math.abs(b))&&Math.abs(l-v)<=r.EPSILON*Math.max(1,Math.abs(l),Math.abs(v))&&Math.abs(e-z)<=r.EPSILON*Math.max(1,Math.abs(e),Math.abs(z))&&Math.abs(M-p)<=r.EPSILON*Math.max(1,Math.abs(M),Math.abs(p))&&Math.abs(s-w)<=r.EPSILON*Math.max(1,Math.abs(s),Math.abs(w))&&Math.abs(i-E)<=r.EPSILON*Math.max(1,Math.abs(i),Math.abs(E))&&Math.abs(c-A)<=r.EPSILON*Math.max(1,Math.abs(c),Math.abs(A))&&Math.abs(h-P)<=r.EPSILON*Math.max(1,Math.abs(h),Math.abs(P))&&Math.abs(S-L)<=r.EPSILON*Math.max(1,Math.abs(S),Math.abs(L))&&Math.abs(I-q)<=r.EPSILON*Math.max(1,Math.abs(I),Math.abs(q))&&Math.abs(f-R)<=r.EPSILON*Math.max(1,Math.abs(f),Math.abs(R))&&Math.abs(x-N)<=r.EPSILON*Math.max(1,Math.abs(x),Math.abs(N))&&Math.abs(D-O)<=r.EPSILON*Math.max(1,Math.abs(D),Math.abs(O))&&Math.abs(F-Y)<=r.EPSILON*Math.max(1,Math.abs(F),Math.abs(Y))},t.exports=o},function(t,a,n){var r=n(1),o=n(4),u=n(7),l=n(8),e={};e.create=function(){var t=new r.ARRAY_TYPE(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},e.rotationTo=function(){var t=u.create(),a=u.fromValues(1,0,0),n=u.fromValues(0,1,0);return function(r,o,l){var M=u.dot(o,l);return-.999999>M?(u.cross(t,a,o),u.length(t)<1e-6&&u.cross(t,n,o),u.normalize(t,t),e.setAxisAngle(r,t,Math.PI),r):M>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(u.cross(t,o,l),r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=1+M,e.normalize(r,r))}}(),e.setAxes=function(){var t=o.create();return function(a,n,r,o){return t[0]=r[0],t[3]=r[1],t[6]=r[2],t[1]=o[0],t[4]=o[1],t[7]=o[2],t[2]=-n[0],t[5]=-n[1],t[8]=-n[2],e.normalize(a,e.fromMat3(a,t))}}(),e.clone=l.clone,e.fromValues=l.fromValues,e.copy=l.copy,e.set=l.set,e.identity=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},e.setAxisAngle=function(t,a,n){n*=.5;var r=Math.sin(n);return t[0]=r*a[0],t[1]=r*a[1],t[2]=r*a[2],t[3]=Math.cos(n),t},e.getAxisAngle=function(t,a){var n=2*Math.acos(a[3]),r=Math.sin(n/2);return 0!=r?(t[0]=a[0]/r,t[1]=a[1]/r,t[2]=a[2]/r):(t[0]=1,t[1]=0,t[2]=0),n},e.add=l.add,e.multiply=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3],e=n[0],M=n[1],s=n[2],i=n[3];return t[0]=r*i+l*e+o*s-u*M,t[1]=o*i+l*M+u*e-r*s,t[2]=u*i+l*s+r*M-o*e,t[3]=l*i-r*e-o*M-u*s,t},e.mul=e.multiply,e.scale=l.scale,e.rotateX=function(t,a,n){n*=.5;var r=a[0],o=a[1],u=a[2],l=a[3],e=Math.sin(n),M=Math.cos(n);return t[0]=r*M+l*e,t[1]=o*M+u*e,t[2]=u*M-o*e,t[3]=l*M-r*e,t},e.rotateY=function(t,a,n){n*=.5;var r=a[0],o=a[1],u=a[2],l=a[3],e=Math.sin(n),M=Math.cos(n);return t[0]=r*M-u*e,t[1]=o*M+l*e,t[2]=u*M+r*e,t[3]=l*M-o*e,t},e.rotateZ=function(t,a,n){n*=.5;var r=a[0],o=a[1],u=a[2],l=a[3],e=Math.sin(n),M=Math.cos(n);return t[0]=r*M+o*e,t[1]=o*M-r*e,t[2]=u*M+l*e,t[3]=l*M-u*e,t},e.calculateW=function(t,a){var n=a[0],r=a[1],o=a[2];return t[0]=n,t[1]=r,t[2]=o,t[3]=Math.sqrt(Math.abs(1-n*n-r*r-o*o)),t},e.dot=l.dot,e.lerp=l.lerp,e.slerp=function(t,a,n,r){var o,u,l,e,M,s=a[0],i=a[1],c=a[2],h=a[3],S=n[0],I=n[1],f=n[2],x=n[3];return u=s*S+i*I+c*f+h*x,0>u&&(u=-u,S=-S,I=-I,f=-f,x=-x),1-u>1e-6?(o=Math.acos(u),l=Math.sin(o),e=Math.sin((1-r)*o)/l,M=Math.sin(r*o)/l):(e=1-r,M=r),t[0]=e*s+M*S,t[1]=e*i+M*I,t[2]=e*c+M*f,t[3]=e*h+M*x,t},e.sqlerp=function(){var t=e.create(),a=e.create();return function(n,r,o,u,l,M){return e.slerp(t,r,l,M),e.slerp(a,o,u,M),e.slerp(n,t,a,2*M*(1-M)),n}}(),e.invert=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=n*n+r*r+o*o+u*u,e=l?1/l:0;return t[0]=-n*e,t[1]=-r*e,t[2]=-o*e,t[3]=u*e,t},e.conjugate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t[2]=-a[2],t[3]=a[3],t},e.length=l.length,e.len=e.length,e.squaredLength=l.squaredLength,e.sqrLen=e.squaredLength,e.normalize=l.normalize,e.fromMat3=function(t,a){var n,r=a[0]+a[4]+a[8];if(r>0)n=Math.sqrt(r+1),t[3]=.5*n,n=.5/n,t[0]=(a[5]-a[7])*n,t[1]=(a[6]-a[2])*n,t[2]=(a[1]-a[3])*n;else{var o=0;a[4]>a[0]&&(o=1),a[8]>a[3*o+o]&&(o=2);var u=(o+1)%3,l=(o+2)%3;n=Math.sqrt(a[3*o+o]-a[3*u+u]-a[3*l+l]+1),t[o]=.5*n,n=.5/n,t[3]=(a[3*u+l]-a[3*l+u])*n,t[u]=(a[3*u+o]+a[3*o+u])*n,t[l]=(a[3*l+o]+a[3*o+l])*n}return t},e.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},e.exactEquals=l.exactEquals,e.equals=l.equals,t.exports=e},function(t,a,n){var r=n(1),o={};o.create=function(){var t=new r.ARRAY_TYPE(3);return t[0]=0,t[1]=0,t[2]=0,t},o.clone=function(t){var a=new r.ARRAY_TYPE(3);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a},o.fromValues=function(t,a,n){var o=new r.ARRAY_TYPE(3);return o[0]=t,o[1]=a,o[2]=n,o},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t},o.set=function(t,a,n,r){return t[0]=a,t[1]=n,t[2]=r,t},o.add=function(t,a,n){return t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t},o.subtract=function(t,a,n){return t[0]=a[0]-n[0],t[1]=a[1]-n[1],t[2]=a[2]-n[2],t},o.sub=o.subtract,o.multiply=function(t,a,n){return t[0]=a[0]*n[0],t[1]=a[1]*n[1],t[2]=a[2]*n[2],t},o.mul=o.multiply,o.divide=function(t,a,n){return t[0]=a[0]/n[0],t[1]=a[1]/n[1],t[2]=a[2]/n[2],t},o.div=o.divide,o.ceil=function(t,a){return t[0]=Math.ceil(a[0]),t[1]=Math.ceil(a[1]),t[2]=Math.ceil(a[2]),t},o.floor=function(t,a){return t[0]=Math.floor(a[0]),t[1]=Math.floor(a[1]),t[2]=Math.floor(a[2]),t},o.min=function(t,a,n){return t[0]=Math.min(a[0],n[0]),t[1]=Math.min(a[1],n[1]),t[2]=Math.min(a[2],n[2]),t},o.max=function(t,a,n){return t[0]=Math.max(a[0],n[0]),t[1]=Math.max(a[1],n[1]),t[2]=Math.max(a[2],n[2]),t},o.round=function(t,a){return t[0]=Math.round(a[0]),t[1]=Math.round(a[1]),t[2]=Math.round(a[2]),t},o.scale=function(t,a,n){return t[0]=a[0]*n,t[1]=a[1]*n,t[2]=a[2]*n,t},o.scaleAndAdd=function(t,a,n,r){return t[0]=a[0]+n[0]*r,t[1]=a[1]+n[1]*r,t[2]=a[2]+n[2]*r,t},o.distance=function(t,a){var n=a[0]-t[0],r=a[1]-t[1],o=a[2]-t[2];return Math.sqrt(n*n+r*r+o*o)},o.dist=o.distance,o.squaredDistance=function(t,a){var n=a[0]-t[0],r=a[1]-t[1],o=a[2]-t[2];return n*n+r*r+o*o},o.sqrDist=o.squaredDistance,o.length=function(t){var a=t[0],n=t[1],r=t[2];return Math.sqrt(a*a+n*n+r*r)},o.len=o.length,o.squaredLength=function(t){var a=t[0],n=t[1],r=t[2];return a*a+n*n+r*r},o.sqrLen=o.squaredLength,o.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t[2]=-a[2],t},o.inverse=function(t,a){return t[0]=1/a[0],t[1]=1/a[1],t[2]=1/a[2],t},o.normalize=function(t,a){var n=a[0],r=a[1],o=a[2],u=n*n+r*r+o*o;return u>0&&(u=1/Math.sqrt(u),t[0]=a[0]*u,t[1]=a[1]*u,t[2]=a[2]*u),t},o.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]+t[2]*a[2]},o.cross=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=n[0],e=n[1],M=n[2];return t[0]=o*M-u*e,t[1]=u*l-r*M,t[2]=r*e-o*l,t},o.lerp=function(t,a,n,r){var o=a[0],u=a[1],l=a[2];return t[0]=o+r*(n[0]-o),t[1]=u+r*(n[1]-u),t[2]=l+r*(n[2]-l),t},o.hermite=function(t,a,n,r,o,u){var l=u*u,e=l*(2*u-3)+1,M=l*(u-2)+u,s=l*(u-1),i=l*(3-2*u);return t[0]=a[0]*e+n[0]*M+r[0]*s+o[0]*i,t[1]=a[1]*e+n[1]*M+r[1]*s+o[1]*i,t[2]=a[2]*e+n[2]*M+r[2]*s+o[2]*i,t},o.bezier=function(t,a,n,r,o,u){var l=1-u,e=l*l,M=u*u,s=e*l,i=3*u*e,c=3*M*l,h=M*u;return t[0]=a[0]*s+n[0]*i+r[0]*c+o[0]*h,t[1]=a[1]*s+n[1]*i+r[1]*c+o[1]*h,t[2]=a[2]*s+n[2]*i+r[2]*c+o[2]*h,t},o.random=function(t,a){a=a||1;var n=2*r.RANDOM()*Math.PI,o=2*r.RANDOM()-1,u=Math.sqrt(1-o*o)*a;return t[0]=Math.cos(n)*u,t[1]=Math.sin(n)*u,t[2]=o*a,t},o.transformMat4=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=n[3]*r+n[7]*o+n[11]*u+n[15];return l=l||1,t[0]=(n[0]*r+n[4]*o+n[8]*u+n[12])/l,t[1]=(n[1]*r+n[5]*o+n[9]*u+n[13])/l,t[2]=(n[2]*r+n[6]*o+n[10]*u+n[14])/l,t},o.transformMat3=function(t,a,n){var r=a[0],o=a[1],u=a[2];return t[0]=r*n[0]+o*n[3]+u*n[6],t[1]=r*n[1]+o*n[4]+u*n[7],t[2]=r*n[2]+o*n[5]+u*n[8],t},o.transformQuat=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=n[0],e=n[1],M=n[2],s=n[3],i=s*r+e*u-M*o,c=s*o+M*r-l*u,h=s*u+l*o-e*r,S=-l*r-e*o-M*u;return t[0]=i*s+S*-l+c*-M-h*-e,t[1]=c*s+S*-e+h*-l-i*-M,t[2]=h*s+S*-M+i*-e-c*-l,t},o.rotateX=function(t,a,n,r){var o=[],u=[];return o[0]=a[0]-n[0],o[1]=a[1]-n[1],o[2]=a[2]-n[2],u[0]=o[0],u[1]=o[1]*Math.cos(r)-o[2]*Math.sin(r),u[2]=o[1]*Math.sin(r)+o[2]*Math.cos(r),t[0]=u[0]+n[0],t[1]=u[1]+n[1],t[2]=u[2]+n[2],t},o.rotateY=function(t,a,n,r){var o=[],u=[];return o[0]=a[0]-n[0],o[1]=a[1]-n[1],o[2]=a[2]-n[2],u[0]=o[2]*Math.sin(r)+o[0]*Math.cos(r),u[1]=o[1],u[2]=o[2]*Math.cos(r)-o[0]*Math.sin(r),t[0]=u[0]+n[0],t[1]=u[1]+n[1],t[2]=u[2]+n[2],t},o.rotateZ=function(t,a,n,r){var o=[],u=[];return o[0]=a[0]-n[0],o[1]=a[1]-n[1],o[2]=a[2]-n[2],u[0]=o[0]*Math.cos(r)-o[1]*Math.sin(r),u[1]=o[0]*Math.sin(r)+o[1]*Math.cos(r),u[2]=o[2],t[0]=u[0]+n[0],t[1]=u[1]+n[1],t[2]=u[2]+n[2],t},o.forEach=function(){var t=o.create();return function(a,n,r,o,u,l){var e,M;for(n||(n=3),r||(r=0),M=o?Math.min(o*n+r,a.length):a.length,e=r;M>e;e+=n)t[0]=a[e],t[1]=a[e+1],t[2]=a[e+2],u(t,t,l),a[e]=t[0],a[e+1]=t[1],a[e+2]=t[2];return a}}(),o.angle=function(t,a){var n=o.fromValues(t[0],t[1],t[2]),r=o.fromValues(a[0],a[1],a[2]);o.normalize(n,n),o.normalize(r,r);var u=o.dot(n,r);return u>1?0:Math.acos(u)},o.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]},o.equals=function(t,a){var n=t[0],o=t[1],u=t[2],l=a[0],e=a[1],M=a[2];return Math.abs(n-l)<=r.EPSILON*Math.max(1,Math.abs(n),Math.abs(l))&&Math.abs(o-e)<=r.EPSILON*Math.max(1,Math.abs(o),Math.abs(e))&&Math.abs(u-M)<=r.EPSILON*Math.max(1,Math.abs(u),Math.abs(M))},t.exports=o},function(t,a,n){var r=n(1),o={};o.create=function(){var t=new r.ARRAY_TYPE(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},o.clone=function(t){var a=new r.ARRAY_TYPE(4);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a},o.fromValues=function(t,a,n,o){var u=new r.ARRAY_TYPE(4);return u[0]=t,u[1]=a,u[2]=n,u[3]=o,u},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t},o.set=function(t,a,n,r,o){return t[0]=a,t[1]=n,t[2]=r,t[3]=o,t},o.add=function(t,a,n){return t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t[3]=a[3]+n[3],t},o.subtract=function(t,a,n){return t[0]=a[0]-n[0],t[1]=a[1]-n[1],t[2]=a[2]-n[2],t[3]=a[3]-n[3],t},o.sub=o.subtract,o.multiply=function(t,a,n){return t[0]=a[0]*n[0],t[1]=a[1]*n[1],t[2]=a[2]*n[2],t[3]=a[3]*n[3],t},o.mul=o.multiply,o.divide=function(t,a,n){return t[0]=a[0]/n[0],t[1]=a[1]/n[1],t[2]=a[2]/n[2],t[3]=a[3]/n[3],t},o.div=o.divide,o.ceil=function(t,a){return t[0]=Math.ceil(a[0]),t[1]=Math.ceil(a[1]),t[2]=Math.ceil(a[2]),t[3]=Math.ceil(a[3]),t},o.floor=function(t,a){return t[0]=Math.floor(a[0]),t[1]=Math.floor(a[1]),t[2]=Math.floor(a[2]),t[3]=Math.floor(a[3]),t},o.min=function(t,a,n){return t[0]=Math.min(a[0],n[0]),t[1]=Math.min(a[1],n[1]),t[2]=Math.min(a[2],n[2]),t[3]=Math.min(a[3],n[3]),t},o.max=function(t,a,n){return t[0]=Math.max(a[0],n[0]),t[1]=Math.max(a[1],n[1]),t[2]=Math.max(a[2],n[2]),t[3]=Math.max(a[3],n[3]),t},o.round=function(t,a){return t[0]=Math.round(a[0]),t[1]=Math.round(a[1]),t[2]=Math.round(a[2]),t[3]=Math.round(a[3]),t},o.scale=function(t,a,n){return t[0]=a[0]*n,t[1]=a[1]*n,t[2]=a[2]*n,t[3]=a[3]*n,t},o.scaleAndAdd=function(t,a,n,r){return t[0]=a[0]+n[0]*r,t[1]=a[1]+n[1]*r,t[2]=a[2]+n[2]*r,t[3]=a[3]+n[3]*r,t},o.distance=function(t,a){var n=a[0]-t[0],r=a[1]-t[1],o=a[2]-t[2],u=a[3]-t[3];return Math.sqrt(n*n+r*r+o*o+u*u)},o.dist=o.distance,o.squaredDistance=function(t,a){var n=a[0]-t[0],r=a[1]-t[1],o=a[2]-t[2],u=a[3]-t[3];return n*n+r*r+o*o+u*u},o.sqrDist=o.squaredDistance,o.length=function(t){var a=t[0],n=t[1],r=t[2],o=t[3];return Math.sqrt(a*a+n*n+r*r+o*o)},o.len=o.length,o.squaredLength=function(t){var a=t[0],n=t[1],r=t[2],o=t[3];return a*a+n*n+r*r+o*o},o.sqrLen=o.squaredLength,o.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t[2]=-a[2],t[3]=-a[3],t},o.inverse=function(t,a){return t[0]=1/a[0],t[1]=1/a[1],t[2]=1/a[2],t[3]=1/a[3],t},o.normalize=function(t,a){var n=a[0],r=a[1],o=a[2],u=a[3],l=n*n+r*r+o*o+u*u;return l>0&&(l=1/Math.sqrt(l),t[0]=n*l,t[1]=r*l,t[2]=o*l,t[3]=u*l),t},o.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]+t[2]*a[2]+t[3]*a[3]},o.lerp=function(t,a,n,r){var o=a[0],u=a[1],l=a[2],e=a[3];return t[0]=o+r*(n[0]-o),t[1]=u+r*(n[1]-u),t[2]=l+r*(n[2]-l),t[3]=e+r*(n[3]-e),t},o.random=function(t,a){return a=a||1,t[0]=r.RANDOM(),t[1]=r.RANDOM(),t[2]=r.RANDOM(),t[3]=r.RANDOM(),o.normalize(t,t),o.scale(t,t,a),t},o.transformMat4=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=a[3];return t[0]=n[0]*r+n[4]*o+n[8]*u+n[12]*l,t[1]=n[1]*r+n[5]*o+n[9]*u+n[13]*l,t[2]=n[2]*r+n[6]*o+n[10]*u+n[14]*l,t[3]=n[3]*r+n[7]*o+n[11]*u+n[15]*l,t},o.transformQuat=function(t,a,n){var r=a[0],o=a[1],u=a[2],l=n[0],e=n[1],M=n[2],s=n[3],i=s*r+e*u-M*o,c=s*o+M*r-l*u,h=s*u+l*o-e*r,S=-l*r-e*o-M*u;return t[0]=i*s+S*-l+c*-M-h*-e,t[1]=c*s+S*-e+h*-l-i*-M,t[2]=h*s+S*-M+i*-e-c*-l,t[3]=a[3],t},o.forEach=function(){var t=o.create();return function(a,n,r,o,u,l){var e,M;for(n||(n=4),r||(r=0),M=o?Math.min(o*n+r,a.length):a.length,e=r;M>e;e+=n)t[0]=a[e],t[1]=a[e+1],t[2]=a[e+2],t[3]=a[e+3],u(t,t,l),a[e]=t[0],a[e+1]=t[1],a[e+2]=t[2],a[e+3]=t[3];return a}}(),o.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]},o.equals=function(t,a){var n=t[0],o=t[1],u=t[2],l=t[3],e=a[0],M=a[1],s=a[2],i=a[3];return Math.abs(n-e)<=r.EPSILON*Math.max(1,Math.abs(n),Math.abs(e))&&Math.abs(o-M)<=r.EPSILON*Math.max(1,Math.abs(o),Math.abs(M))&&Math.abs(u-s)<=r.EPSILON*Math.max(1,Math.abs(u),Math.abs(s))&&Math.abs(l-i)<=r.EPSILON*Math.max(1,Math.abs(l),Math.abs(i))},t.exports=o},function(t,a,n){var r=n(1),o={};o.create=function(){var t=new r.ARRAY_TYPE(2);return t[0]=0,t[1]=0,t},o.clone=function(t){var a=new r.ARRAY_TYPE(2);return a[0]=t[0],a[1]=t[1],a},o.fromValues=function(t,a){var n=new r.ARRAY_TYPE(2);return n[0]=t,n[1]=a,n},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t},o.set=function(t,a,n){return t[0]=a,t[1]=n,t},o.add=function(t,a,n){return t[0]=a[0]+n[0],t[1]=a[1]+n[1],t},o.subtract=function(t,a,n){return t[0]=a[0]-n[0],t[1]=a[1]-n[1],t},o.sub=o.subtract,o.multiply=function(t,a,n){return t[0]=a[0]*n[0],t[1]=a[1]*n[1],t},o.mul=o.multiply,o.divide=function(t,a,n){return t[0]=a[0]/n[0],t[1]=a[1]/n[1],t},o.div=o.divide,o.ceil=function(t,a){return t[0]=Math.ceil(a[0]),t[1]=Math.ceil(a[1]),t},o.floor=function(t,a){return t[0]=Math.floor(a[0]),t[1]=Math.floor(a[1]),t},o.min=function(t,a,n){return t[0]=Math.min(a[0],n[0]),t[1]=Math.min(a[1],n[1]),t},o.max=function(t,a,n){return t[0]=Math.max(a[0],n[0]),t[1]=Math.max(a[1],n[1]),t},o.round=function(t,a){return t[0]=Math.round(a[0]),t[1]=Math.round(a[1]),t},o.scale=function(t,a,n){return t[0]=a[0]*n,t[1]=a[1]*n,t},o.scaleAndAdd=function(t,a,n,r){return t[0]=a[0]+n[0]*r,t[1]=a[1]+n[1]*r,t},o.distance=function(t,a){var n=a[0]-t[0],r=a[1]-t[1];return Math.sqrt(n*n+r*r)},o.dist=o.distance,o.squaredDistance=function(t,a){var n=a[0]-t[0],r=a[1]-t[1];return n*n+r*r},o.sqrDist=o.squaredDistance,o.length=function(t){var a=t[0],n=t[1];return Math.sqrt(a*a+n*n)},o.len=o.length,o.squaredLength=function(t){var a=t[0],n=t[1];return a*a+n*n},o.sqrLen=o.squaredLength,o.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t},o.inverse=function(t,a){return t[0]=1/a[0],t[1]=1/a[1],t},o.normalize=function(t,a){var n=a[0],r=a[1],o=n*n+r*r;return o>0&&(o=1/Math.sqrt(o),t[0]=a[0]*o,t[1]=a[1]*o),t},o.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]},o.cross=function(t,a,n){var r=a[0]*n[1]-a[1]*n[0];return t[0]=t[1]=0,t[2]=r,t},o.lerp=function(t,a,n,r){var o=a[0],u=a[1];return t[0]=o+r*(n[0]-o),t[1]=u+r*(n[1]-u),t},o.random=function(t,a){a=a||1;var n=2*r.RANDOM()*Math.PI;return t[0]=Math.cos(n)*a,t[1]=Math.sin(n)*a,t},o.transformMat2=function(t,a,n){var r=a[0],o=a[1];return t[0]=n[0]*r+n[2]*o,t[1]=n[1]*r+n[3]*o,t},o.transformMat2d=function(t,a,n){var r=a[0],o=a[1];return t[0]=n[0]*r+n[2]*o+n[4],t[1]=n[1]*r+n[3]*o+n[5],t},o.transformMat3=function(t,a,n){var r=a[0],o=a[1];return t[0]=n[0]*r+n[3]*o+n[6],t[1]=n[1]*r+n[4]*o+n[7],t},o.transformMat4=function(t,a,n){var r=a[0],o=a[1];return t[0]=n[0]*r+n[4]*o+n[12],t[1]=n[1]*r+n[5]*o+n[13],t},o.forEach=function(){var t=o.create();return function(a,n,r,o,u,l){var e,M;for(n||(n=2),r||(r=0),M=o?Math.min(o*n+r,a.length):a.length,e=r;M>e;e+=n)t[0]=a[e],t[1]=a[e+1],u(t,t,l),a[e]=t[0],a[e+1]=t[1];return a}}(),o.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]},o.equals=function(t,a){var n=t[0],o=t[1],u=a[0],l=a[1];return Math.abs(n-u)<=r.EPSILON*Math.max(1,Math.abs(n),Math.abs(u))&&Math.abs(o-l)<=r.EPSILON*Math.max(1,Math.abs(o),Math.abs(l))},t.exports=o}])});</script> <script>function stripTags(n){var e=document.createElement("div");return e.innerHTML=n,e.textContent||e.innerText||""}function consolePrint(n){}function consoleCacheDump(n){}function consoleError(n,e){var r=document.getElementById("errormessage");n=stripTags(n),r.innerHTML+=n+"<br>"}function logErrorNoLine(n){var e=document.getElementById("errormessage");n=stripTags(n),e.innerHTML+=n+"<br>"}function logBetaMessage(n){var e=document.getElementById("errormessage");n=stripTags(n),e.innerHTML+=n+"<br>"}function clearInputHistory(){}function pushInput(n){}var canSetHTMLColors=!0,canDump=!1,canOpenEditor=!1,canYoutube=!0,IDE=!1;</script> <script>var font={a:[[0,0,0,0,0],[0,1,1,1,0],[1,0,0,1,0],[1,0,0,1,0],[0,1,1,1,0]],b:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[1,0,0,1,0],[0,1,1,0,0]],c:[[0,0,0,0,0],[0,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[0,1,1,1,0]],d:[[0,0,0,1,0],[0,0,0,1,0],[0,1,1,1,0],[1,0,0,1,0],[0,1,1,0,0]],e:[[0,1,1,0,0],[1,0,0,1,0],[1,1,1,0,0],[1,0,0,0,0],[0,1,1,0,0]],f:[[0,0,0,0,0],[0,0,1,1,0],[0,1,0,0,0],[1,1,1,0,0],[0,1,0,0,0]],g:[[0,1,1,0,0],[1,0,0,1,0],[0,1,1,1,0],[0,0,0,1,0],[0,1,1,0,0]],h:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[1,0,0,1,0],[1,0,0,1,0]],i:[[0,0,1,0,0],[0,0,0,0,0],[0,1,1,0,0],[0,0,1,0,0],[0,1,1,1,0]],j:[[0,0,1,0,0],[0,0,0,0,0],[0,0,1,0,0],[1,0,1,0,0],[0,1,0,0,0]],k:[[1,0,0,0,0],[1,0,0,1,0],[1,1,1,0,0],[1,0,0,1,0],[1,0,0,1,0]],l:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,1,0],[0,1,1,0,0]],m:[[0,0,0,0,0],[0,1,0,1,0],[1,0,1,0,1],[1,0,1,0,1],[1,0,1,0,1]],n:[[0,0,0,0,0],[0,1,1,0,0],[1,0,0,1,0],[1,0,0,1,0],[1,0,0,1,0]],o:[[0,0,0,0,0],[0,1,1,0,0],[1,0,0,1,0],[1,0,0,1,0],[0,1,1,0,0]],p:[[0,0,0,0,0],[0,1,1,0,0],[1,0,0,1,0],[1,1,1,0,0],[1,0,0,0,0]],q:[[0,0,0,0,0],[0,1,1,0,0],[1,0,0,1,0],[0,1,1,1,0],[0,0,0,1,0]],r:[[0,0,0,0,0],[0,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]],s:[[0,1,1,1,0],[1,0,0,0,0],[0,1,1,0,0],[0,0,0,1,0],[1,1,1,0,0]],t:[[0,1,0,0,0],[1,1,1,0,0],[0,1,0,0,0],[0,1,0,0,1],[0,0,1,1,0]],u:[[0,0,0,0,0],[1,0,0,1,0],[1,0,0,1,0],[1,0,0,1,0],[1,1,1,0,0]],v:[[0,0,0,0,0],[1,0,0,1,0],[1,0,1,0,0],[1,1,0,0,0],[1,0,0,0,0]],w:[[0,0,0,0,0],[1,0,1,0,1],[1,0,1,0,1],[1,0,1,0,1],[0,1,0,1,0]],x:[[0,0,0,0,0],[1,0,0,1,0],[0,1,1,0,0],[0,1,1,0,0],[1,0,0,1,0]],y:[[1,0,0,1,0],[1,0,0,1,0],[0,1,1,1,0],[0,0,0,1,0],[1,1,1,0,0]],z:[[0,0,0,0,0],[1,1,1,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,1,1,1,0]],A:[[1,1,1,1,1],[1,0,0,0,1],[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1]],B:[[1,1,1,1,0],[1,0,0,0,1],[1,1,1,1,0],[1,0,0,0,1],[1,1,1,1,0]],C:[[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],D:[[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,0]],E:[[1,1,1,1,1],[1,0,0,0,0],[1,1,1,1,1],[1,0,0,0,0],[1,1,1,1,1]],F:[[1,1,1,1,1],[1,0,0,0,0],[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0]],G:[[0,1,1,1,1],[1,0,0,0,0],[1,0,0,1,1],[1,0,0,0,1],[0,1,1,1,1]],H:[[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1]],I:[[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1]],J:[[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0]],K:[[1,0,0,0,1],[1,0,1,1,0],[1,1,0,0,0],[1,0,1,1,0],[1,0,0,0,1]],L:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],M:[[1,1,1,1,1],[1,0,1,0,1],[1,0,1,0,1],[1,0,1,0,1],[1,0,1,0,1]],N:[[1,0,0,0,1],[1,1,0,0,1],[1,0,1,0,1],[1,0,0,1,1],[1,0,0,0,1]],O:[[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1]],P:[[1,1,1,1,1],[1,0,0,0,1],[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0]],Q:[[1,1,1,1,1],[1,0,0,0,1],[1,1,1,1,1],[0,0,0,0,1],[0,0,0,0,1]],R:[[1,1,1,1,0],[1,0,0,0,1],[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1]],S:[[0,1,1,1,1],[1,0,0,0,0],[0,1,1,1,0],[0,0,0,0,1],[1,1,1,1,0]],T:[[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0]],U:[[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1]],V:[[1,0,0,0,1],[0,1,0,1,0],[0,1,0,1,0],[0,0,1,0,0],[0,0,1,0,0]],W:[[1,0,1,0,1],[1,0,1,0,1],[1,0,1,0,1],[1,0,1,0,1],[0,1,0,1,0]],X:[[1,0,0,0,1],[0,1,0,1,0],[0,0,1,0,0],[0,1,0,1,0],[1,0,0,0,1]],Y:[[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0]],Z:[[1,1,1,1,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,1,1,1,1]],0:[[1,1,1,1,1],[1,0,0,1,1],[1,0,1,0,1],[1,1,0,0,1],[1,1,1,1,1]],1:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1]],2:[[1,1,1,1,1],[0,0,0,0,1],[1,1,1,1,1],[1,0,0,0,0],[1,1,1,1,1]],3:[[1,1,1,1,0],[0,0,0,0,1],[0,0,1,1,0],[0,0,0,0,1],[1,1,1,1,0]],4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,1,0],[1,1,1,1,1],[0,0,0,1,0]],5:[[1,1,1,1,1],[1,0,0,0,0],[1,1,1,1,0],[0,0,0,0,1],[1,1,1,1,0]],6:[[0,1,1,1,0],[1,0,0,0,0],[1,1,1,1,0],[1,0,0,0,1],[0,1,1,1,0]],7:[[1,1,1,1,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0]],8:[[0,1,1,1,0],[1,0,0,0,1],[0,1,1,1,0],[1,0,0,0,1],[0,1,1,1,0]],9:[[0,1,1,1,0],[1,0,0,0,1],[0,1,1,1,1],[0,0,0,0,1],[0,1,1,1,0]],".":[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0]],",":[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,1,1,0,0]],";":[[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,1,1,0,0]],":":[[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0]],"?":[[0,1,1,1,0],[1,0,0,0,1],[0,0,1,1,0],[0,0,1,0,0],[0,0,1,0,0]],"!":[[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,1,0,0]],"@":[[0,1,1,1,0],[1,0,0,0,1],[1,0,1,1,1],[1,0,0,0,0],[0,1,1,1,0]],"£":[[0,1,1,1,0],[0,1,0,0,1],[1,1,1,0,0],[0,1,0,0,0],[1,1,1,1,1]],$:[[0,1,1,1,1],[1,0,1,0,0],[0,1,1,1,0],[0,0,1,0,1],[1,1,1,1,0]],"%":[[1,1,0,0,1],[1,1,0,1,0],[0,0,1,0,0],[0,1,0,1,1],[1,0,0,1,1]],"^":[[0,0,1,0,0],[0,1,0,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],"&":[[0,1,1,0,0],[1,0,0,0,0],[0,1,0,1,1],[1,0,0,1,0],[0,1,1,0,0]],"*":[[0,1,0,1,0],[0,0,1,0,0],[0,1,0,1,0],[0,0,0,0,0],[0,0,0,0,0]],"(":[[0,0,0,1,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,1,0]],")":[[0,1,0,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,1,0,0,0]],"+":[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0]],"-":[[0,0,0,0,0],[0,0,0,0,0],[0,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0]],_:[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1]],"=":[[0,0,0,0,0],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[0,0,0,0,0]]," ":[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],"{":[[0,0,1,1,0],[0,0,1,0,0],[0,1,1,0,0],[0,0,1,0,0],[0,0,1,1,0]],"}":[[0,1,1,0,0],[0,0,1,0,0],[0,0,1,1,0],[0,0,1,0,0],[0,1,1,0,0]],"[":[[0,0,1,1,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,1,0]],"]":[[0,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,1,1,0,0]],"'":[[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],'"':[[0,1,0,1,0],[0,1,0,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],"/":[[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,0,0,0,0]],"\\":[[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]],"|":[[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0]],"<":[[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0]],">":[[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0]],"~":[[0,0,0,0,0],[0,1,0,0,0],[1,0,1,0,1],[0,0,0,1,0],[0,0,0,0,0]],"`":[[0,1,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],"#":[[0,1,0,1,0],[1,1,1,1,1],[0,1,0,1,0],[1,1,1,1,1],[0,1,0,1,0]]};</script> <script>function RC4(t){this.s=new Array(256),this.i=0,this.j=0;for(var n=0;n<256;n++)this.s[n]=n;t&&this.mix(t)}function print_call_stack(){var t=new Error,n=t.stack;console.log(n)}function RNG(t){this.seed=t,null==t?t=(Math.random()+Date.now()).toString():"function"==typeof t?(this.uniform=t,this.nextByte=function(){return~~(256*this.uniform())},t=null):"[object String]"!==Object.prototype.toString.call(t)&&(t=JSON.stringify(t)),this._normal=null,this._state=t?new RC4(t):null}String.prototype.getBytes=function(){for(var t=[],n=0;n<this.length;n++){var i=this.charCodeAt(n),o=[];do{o.push(255&i),i>>=8}while(i>0);t=t.concat(o.reverse())}return t},RC4.prototype._swap=function(t,n){var i=this.s[t];this.s[t]=this.s[n],this.s[n]=i},RC4.prototype.mix=function(t){for(var n=t.getBytes(),i=0,o=0;o<this.s.length;o++)i+=this.s[o]+n[o%n.length],i%=256,this._swap(o,i)},RC4.prototype.next=function(){return this.i=(this.i+1)%256,this.j=(this.j+this.s[this.i])%256,this._swap(this.i,this.j),this.s[(this.s[this.i]+this.s[this.j])%256]},RNG.prototype.nextByte=function(){return this._state.next()},RNG.prototype.uniform=function(){for(var t=0,n=0;n<7;n++)t*=256,t+=this.nextByte();return t/(Math.pow(2,56)-1)},RNG.prototype.random=function(t,n){return null==t?this.uniform():(null==n&&(n=t,t=0),t+Math.floor(this.uniform()*(n-t)))},RNG.prototype.normal=function(){if(null!==this._normal){var t=this._normal;return this._normal=null,t}var n=this.uniform()||Math.pow(2,-53),i=this.uniform();return this._normal=Math.sqrt(-2*Math.log(n))*Math.sin(2*Math.PI*i),Math.sqrt(-2*Math.log(n))*Math.cos(2*Math.PI*i)},RNG.prototype.exponential=function(){return-Math.log(this.uniform()||Math.pow(2,-53))},RNG.prototype.poisson=function(t){var n=Math.exp(-(t||1)),i=0,o=1;do{i++,o*=this.uniform()}while(o>n);return i-1},RNG.prototype.gamma=function(t){var n=(t<1?1+t:t)-1/3,i=1/Math.sqrt(9*n);do{do{var o=this.normal(),r=Math.pow(i*o+1,3)}while(r<=0);var s=this.uniform(),h=Math.pow(o,2)}while(s>=1-.0331*h*h&&Math.log(s)>=.5*h+n*(1-r+Math.log(r)));return t<1?n*r*Math.exp(this.exponential()/-t):n*r},RNG.roller=function(t,n){var i=t.split(/(\d+)?d(\d+)([+-]\d+)?/).slice(1),o=parseFloat(i[0])||1,r=parseFloat(i[1]),s=parseFloat(i[2])||0;return n=n||new RNG,function(){for(var t=o+s,i=0;i<o;i++)t+=n.random(r);return t}};</script> <script>function FastBase64_Init(){for(var a=0;a<4096;a++)FastBase64_encLookup[a]=FastBase64_chars[a>>6]+FastBase64_chars[63&a]}function FastBase64_Encode(a){for(var e=a.length,s="",u=0;e>2;)n=a[u]<<16|a[u+1]<<8|a[u+2],s+=FastBase64_encLookup[n>>12]+FastBase64_encLookup[4095&n],e-=3,u+=3;if(e>0){var r=(252&a[u])>>2,t=(3&a[u])<<4;if(e>1&&(t|=(240&a[++u])>>4),s+=FastBase64_chars[r],s+=FastBase64_chars[t],2==e){var o=(15&a[u++])<<2;o|=(192&a[u])>>6,s+=FastBase64_chars[o]}1==e&&(s+="="),s+="="}return s}function u32ToArray(a){return[255&a,a>>8&255,a>>16&255,a>>24&255]}function u16ToArray(a){return[255&a,a>>8&255]}function MakeRiff(a,e,n){var s=[],u=[],r=[],t={chunkId:[82,73,70,70],chunkSize:0,format:[87,65,86,69],subChunk1Id:[102,109,116,32],subChunk1Size:16,audioFormat:1,numChannels:1,sampleRate:a,byteRate:0,blockAlign:0,bitsPerSample:e,subChunk2Id:[100,97,116,97],subChunk2Size:0};return t.byteRate=t.sampleRate*t.numChannels*t.bitsPerSample>>3,t.blockAlign=t.numChannels*t.bitsPerSample>>3,t.subChunk2Size=n.length,t.chunkSize=36+t.subChunk2Size,u=t.chunkId.concat(u32ToArray(t.chunkSize),t.format,t.subChunk1Id,u32ToArray(t.subChunk1Size),u16ToArray(t.audioFormat),u16ToArray(t.numChannels),u32ToArray(t.sampleRate),u32ToArray(t.byteRate),u16ToArray(t.blockAlign),u16ToArray(t.bitsPerSample),t.subChunk2Id,u32ToArray(t.subChunk2Size),n),r="data:audio/wav;base64,"+FastBase64_Encode(u),{dat:s,wav:u,header:t,dataURI:r}}var FastBase64_chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",FastBase64_encLookup=[];FastBase64_Init(),"undefined"!=typeof exports&&(exports.RIFFWAVE=RIFFWAVE);</script> <script>function Params(){var e={};return e.wave_type=SQUARE,e.p_env_attack=0,e.p_env_sustain=.3,e.p_env_punch=0,e.p_env_decay=.4,e.p_base_freq=.3,e.p_freq_limit=0,e.p_freq_ramp=0,e.p_freq_dramp=0,e.p_vib_strength=0,e.p_vib_speed=0,e.p_arp_mod=0,e.p_arp_speed=0,e.p_duty=0,e.p_duty_ramp=0,e.p_repeat_speed=0,e.p_pha_offset=0,e.p_pha_ramp=0,e.p_lpf_freq=1,e.p_lpf_ramp=0,e.p_lpf_resonance=0,e.p_hpf_freq=0,e.p_hpf_ramp=0,e.sound_vol=.5,e.sample_rate=44100,e.bit_depth=8,e}function frnd(e){return seeded?rng.uniform()*e:Math.random()*e}function rnd(e){return seeded?Math.floor(rng.uniform()*(e+1)):Math.floor(Math.random()*(e+1))}function SoundEffect(e,r){this._buffer=AUDIO_CONTEXT.createBuffer(1,e,r)}function cacheSeed(e){if(e in sfxCache)return sfxCache[e];var r=generateFromSeed(e);r.sound_vol=SOUND_VOL,r.sample_rate=SAMPLE_RATE,r.bit_depth=BIT_DEPTH;var _=SoundEffect.generate(r);for(sfxCache[e]=_,cachedSeeds.push(e);cachedSeeds.length>CACHE_MAX;){var p=cachedSeeds[0];cachedSeeds=cachedSeeds.slice(1),delete sfxCache[p]}return _}function playSound(e){if(!unitTesting){cacheSeed(e).play()}}var SOUND_VOL=.25,SAMPLE_RATE=5512,BIT_DEPTH=8,SQUARE=0,SAWTOOTH=1,SINE=2,NOISE=3,TRIANGLE=4,BREAKER=5,SHAPES=["square","sawtooth","sine","noise","triangle","breaker"],AUDIO_CONTEXT;"undefined"!=typeof AudioContext?AUDIO_CONTEXT=new AudioContext:"undefined"!=typeof webkitAudioContext&&(AUDIO_CONTEXT=new webkitAudioContext);var masterVolume=1,rng,seeded=!1;pickupCoin=function(){var e=Params();if(e.wave_type=Math.floor(frnd(SHAPES.length)),3===e.wave_type&&(e.wave_type=0),e.p_base_freq=.4+frnd(.5),e.p_env_attack=0,e.p_env_sustain=frnd(.1),e.p_env_decay=.1+frnd(.4),e.p_env_punch=.3+frnd(.3),rnd(1)){e.p_arp_speed=.5+frnd(.2);var r=1+(1|frnd(7)),_=r+(1|frnd(7))+2;e.p_arp_mod=+r/+_}return e},laserShoot=function(){var e=Params();return e.wave_type=rnd(2),e.wave_type===SINE&&rnd(1)&&(e.wave_type=rnd(1)),e.wave_type=Math.floor(frnd(SHAPES.length)),3===e.wave_type&&(e.wave_type=SQUARE),e.p_base_freq=.5+frnd(.5),e.p_freq_limit=e.p_base_freq-.2-frnd(.6),e.p_freq_limit<.2&&(e.p_freq_limit=.2),e.p_freq_ramp=-.15-frnd(.2),0===rnd(2)&&(e.p_base_freq=.3+frnd(.6),e.p_freq_limit=frnd(.1),e.p_freq_ramp=-.35-frnd(.3)),rnd(1)?(e.p_duty=frnd(.5),e.p_duty_ramp=frnd(.2)):(e.p_duty=.4+frnd(.5),e.p_duty_ramp=-frnd(.7)),e.p_env_attack=0,e.p_env_sustain=.1+frnd(.2),e.p_env_decay=frnd(.4),rnd(1)&&(e.p_env_punch=frnd(.3)),0===rnd(2)&&(e.p_pha_offset=frnd(.2),e.p_pha_ramp=-frnd(.2)),rnd(1)&&(e.p_hpf_freq=frnd(.3)),e},explosion=function(){var e=Params();return rnd(1)?(e.p_base_freq=.1+frnd(.4),e.p_freq_ramp=-.1+frnd(.4)):(e.p_base_freq=.2+frnd(.7),e.p_freq_ramp=-.2-frnd(.2)),e.p_base_freq*=e.p_base_freq,0===rnd(4)&&(e.p_freq_ramp=0),0===rnd(2)&&(e.p_repeat_speed=.3+frnd(.5)),e.p_env_attack=0,e.p_env_sustain=.1+frnd(.3),e.p_env_decay=frnd(.5),0===rnd(1)&&(e.p_pha_offset=-.3+frnd(.9),e.p_pha_ramp=-frnd(.3)),e.p_env_punch=.2+frnd(.6),rnd(1)&&(e.p_vib_strength=frnd(.7),e.p_vib_speed=frnd(.6)),0===rnd(2)&&(e.p_arp_speed=.6+frnd(.3),e.p_arp_mod=.8-frnd(1.6)),e},birdSound=function(){var e=Params();return frnd(10)<1?(e.wave_type=Math.floor(frnd(SHAPES.length)),3===e.wave_type&&(e.wave_type=SQUARE),e.p_env_attack=.4304400932967592+frnd(.2)-.1,e.p_env_sustain=.15739346034252394+frnd(.2)-.1,e.p_env_punch=.004488201744871758+frnd(.2)-.1,e.p_env_decay=.07478075528212291+frnd(.2)-.1,e.p_base_freq=.9865265720147687+frnd(.2)-.1,e.p_freq_limit=0+frnd(.2)-.1,e.p_freq_ramp=-.2995018224359539+frnd(.2)-.1,frnd(1)<.5&&(e.p_freq_ramp=.1+frnd(.15)),e.p_freq_dramp=.004598608156964473+frnd(.1)-.05,e.p_vib_strength=-.2202799497929496+frnd(.2)-.1,e.p_vib_speed=.8084998703158364+frnd(.2)-.1,e.p_arp_mod=0,e.p_arp_speed=0,e.p_duty=-.9031808754347107+frnd(.2)-.1,e.p_duty_ramp=-.8128699999808343+frnd(.2)-.1,e.p_repeat_speed=.601486018931999+frnd(.2)-.1,e.p_pha_offset=-.9424902314367765+frnd(.2)-.1,e.p_pha_ramp=-.1055482222272056+frnd(.2)-.1,e.p_lpf_freq=.9989765717851521+frnd(.2)-.1,e.p_lpf_ramp=-.25051720626043017+frnd(.2)-.1,e.p_lpf_resonance=.32777871505494693+frnd(.2)-.1,e.p_hpf_freq=.0023548750981756753+frnd(.2)-.1,e.p_hpf_ramp=-.002375673204842568+frnd(.2)-.1,e):frnd(10)<1?(e.wave_type=Math.floor(frnd(SHAPES.length)),3===e.wave_type&&(e.wave_type=SQUARE),e.p_env_attack=.5277795946672003+frnd(.2)-.1,e.p_env_sustain=.18243733568468432+frnd(.2)-.1,e.p_env_punch=-.020159754546840117+frnd(.2)-.1,e.p_env_decay=.1561353422051903+frnd(.2)-.1,e.p_base_freq=.9028855606533718+frnd(.2)-.1,e.p_freq_limit=-.008842787837148716,e.p_freq_ramp=-.1,e.p_freq_dramp=-.012891241489551925,e.p_vib_strength=-.17923136138403065+frnd(.2)-.1,e.p_vib_speed=.908263385610142+frnd(.2)-.1,e.p_arp_mod=.41690153355414894+frnd(.2)-.1,e.p_arp_speed=.0010766233195860704+frnd(.2)-.1,e.p_duty=-.8735363011184684+frnd(.2)-.1,e.p_duty_ramp=-.7397985366747507+frnd(.2)-.1,e.p_repeat_speed=.0591789344172107+frnd(.2)-.1,e.p_pha_offset=-.9961184222777699+frnd(.2)-.1,e.p_pha_ramp=-.08234769395850523+frnd(.2)-.1,e.p_lpf_freq=.9412475115697335+frnd(.2)-.1,e.p_lpf_ramp=-.18261358925834958+frnd(.2)-.1,e.p_lpf_resonance=.24541438107389477+frnd(.2)-.1,e.p_hpf_freq=-.01831940280978611+frnd(.2)-.1,e.p_hpf_ramp=-.03857383633171346+frnd(.2)-.1,e):frnd(10)<1?(e.wave_type=Math.floor(frnd(SHAPES.length)),3===e.wave_type&&(e.wave_type=SQUARE),e.p_env_attack=.4304400932967592+frnd(.2)-.1,e.p_env_sustain=.15739346034252394+frnd(.2)-.1,e.p_env_punch=.004488201744871758+frnd(.2)-.1,e.p_env_decay=.07478075528212291+frnd(.2)-.1,e.p_base_freq=.9865265720147687+frnd(.2)-.1,e.p_freq_limit=0+frnd(.2)-.1,e.p_freq_ramp=-.2995018224359539+frnd(.2)-.1,e.p_freq_dramp=.004598608156964473+frnd(.2)-.1,e.p_vib_strength=-.2202799497929496+frnd(.2)-.1,e.p_vib_speed=.8084998703158364+frnd(.2)-.1,e.p_arp_mod=-.46410459213693644+frnd(.2)-.1,e.p_arp_speed=-.10955361249587248+frnd(.2)-.1,e.p_duty=-.9031808754347107+frnd(.2)-.1,e.p_duty_ramp=-.8128699999808343+frnd(.2)-.1,e.p_repeat_speed=.7014860189319991+frnd(.2)-.1,e.p_pha_offset=-.9424902314367765+frnd(.2)-.1,e.p_pha_ramp=-.1055482222272056+frnd(.2)-.1,e.p_lpf_freq=.9989765717851521+frnd(.2)-.1,e.p_lpf_ramp=-.25051720626043017+frnd(.2)-.1,e.p_lpf_resonance=.32777871505494693+frnd(.2)-.1,e.p_hpf_freq=.0023548750981756753+frnd(.2)-.1,e.p_hpf_ramp=-.002375673204842568+frnd(.2)-.1,e):frnd(5)>1?(e.wave_type=Math.floor(frnd(SHAPES.length)),3===e.wave_type&&(e.wave_type=SQUARE),rnd(1)?(e.p_arp_mod=.2697849293151393+frnd(.2)-.1,e.p_arp_speed=-.3131172257760948+frnd(.2)-.1,e.p_base_freq=.8090588299313949+frnd(.2)-.1,e.p_duty=-.6210022920964955+frnd(.2)-.1,e.p_duty_ramp=-.00043441813553182567+frnd(.2)-.1,e.p_env_attack=.004321877246874195+frnd(.2)-.1,e.p_env_decay=.1+frnd(.2)-.1,e.p_env_punch=.061737781504416146+frnd(.2)-.1,e.p_env_sustain=.4987252564798832+frnd(.2)-.1,e.p_freq_dramp=.31700340314222614+frnd(.2)-.1,e.p_freq_limit=0+frnd(.2)-.1,e.p_freq_ramp=-.163380391341416+frnd(.2)-.1,e.p_hpf_freq=.4709005021145149+frnd(.2)-.1,e.p_hpf_ramp=.6924667290539194+frnd(.2)-.1,e.p_lpf_freq=.8351398631384511+frnd(.2)-.1,e.p_lpf_ramp=.36616557192873134+frnd(.2)-.1,e.p_lpf_resonance=-.08685777111664439+frnd(.2)-.1,e.p_pha_offset=-.036084571580025544+frnd(.2)-.1,e.p_pha_ramp=-.014806445085568108+frnd(.2)-.1,e.p_repeat_speed=-.8094368475518489+frnd(.2)-.1,e.p_vib_speed=.4496665457171294+frnd(.2)-.1,e.p_vib_strength=.23413762515532424+frnd(.2)-.1):(e.p_arp_mod=-.35697118026766184+frnd(.2)-.1,e.p_arp_speed=.3581140690559588+frnd(.2)-.1,e.p_base_freq=1.3260897696157528+frnd(.2)-.1,e.p_duty=-.30984900436710694+frnd(.2)-.1,e.p_duty_ramp=-.0014374759133411626+frnd(.2)-.1,e.p_env_attack=.3160357835682254+frnd(.2)-.1,e.p_env_decay=.1+frnd(.2)-.1,e.p_env_punch=.24323114016870148+frnd(.2)-.1,e.p_env_sustain=.4+frnd(.2)-.1,e.p_freq_dramp=.2866475886237244+frnd(.2)-.1,e.p_freq_limit=0+frnd(.2)-.1,e.p_freq_ramp=-.10956352368742976+frnd(.2)-.1,e.p_hpf_freq=.20772718017889846+frnd(.2)-.1,e.p_hpf_ramp=.1564090637378835+frnd(.2)-.1,e.p_lpf_freq=.6021372770637031+frnd(.2)-.1,e.p_lpf_ramp=.24016227139979027+frnd(.2)-.1,e.p_lpf_resonance=-.08787383821160144+frnd(.2)-.1,e.p_pha_offset=-.381597686151701+frnd(.2)-.1,e.p_pha_ramp=-.0002481687661373495+frnd(.2)-.1,e.p_repeat_speed=.07812112809425686+frnd(.2)-.1,e.p_vib_speed=-.13648848579133943+frnd(.2)-.1,e.p_vib_strength=.0018874158972302657+frnd(.2)-.1),e):(e.wave_type=Math.floor(frnd(SHAPES.length)),1!==e.wave_type&&3!==e.wave_type||(e.wave_type=2),e.p_base_freq=.85+frnd(.15),e.p_freq_ramp=.3+frnd(.15),e.p_env_attack=0+frnd(.09),e.p_env_sustain=.2+frnd(.3),e.p_env_decay=0+frnd(.1),e.p_duty=frnd(2)-1,e.p_duty_ramp=Math.pow(frnd(2)-1,3),e.p_repeat_speed=.5+frnd(.1),e.p_pha_offset=-.3+frnd(.9),e.p_pha_ramp=-frnd(.3),e.p_arp_speed=.4+frnd(.6),e.p_arp_mod=.8+frnd(.1),e.p_lpf_resonance=frnd(2)-1,e.p_lpf_freq=1-Math.pow(frnd(1),3),e.p_lpf_ramp=Math.pow(frnd(2)-1,3),e.p_lpf_freq<.1&&e.p_lpf_ramp<-.05&&(e.p_lpf_ramp=-e.p_lpf_ramp),e.p_hpf_freq=Math.pow(frnd(1),5),e.p_hpf_ramp=Math.pow(frnd(2)-1,5),e)},pushSound=function(){var e=Params();return e.wave_type=Math.floor(frnd(SHAPES.length)),2===e.wave_type&&e.wave_type++,0===e.wave_type&&(e.wave_type=NOISE),e.p_base_freq=.1+frnd(.4),e.p_freq_ramp=.05+frnd(.2),e.p_env_attack=.01+frnd(.09),e.p_env_sustain=.01+frnd(.09),e.p_env_decay=.01+frnd(.09),e.p_repeat_speed=.3+frnd(.5),e.p_pha_offset=-.3+frnd(.9),e.p_pha_ramp=-frnd(.3),e.p_arp_speed=.6+frnd(.3),e.p_arp_mod=.8-frnd(1.6),e},powerUp=function(){var e=Params();return rnd(1)?e.wave_type=SAWTOOTH:e.p_duty=frnd(.6),e.wave_type=Math.floor(frnd(SHAPES.length)),3===e.wave_type&&(e.wave_type=SQUARE),rnd(1)?(e.p_base_freq=.2+frnd(.3),e.p_freq_ramp=.1+frnd(.4),e.p_repeat_speed=.4+frnd(.4)):(e.p_base_freq=.2+frnd(.3),e.p_freq_ramp=.05+frnd(.2),rnd(1)&&(e.p_vib_strength=frnd(.7),e.p_vib_speed=frnd(.6))),e.p_env_attack=0,e.p_env_sustain=frnd(.4),e.p_env_decay=.1+frnd(.4),e},hitHurt=function(){return result=Params(),result.wave_type=rnd(2),result.wave_type===SINE&&(result.wave_type=NOISE),result.wave_type===SQUARE&&(result.p_duty=frnd(.6)),result.wave_type=Math.floor(frnd(SHAPES.length)),result.p_base_freq=.2+frnd(.6),result.p_freq_ramp=-.3-frnd(.4),result.p_env_attack=0,result.p_env_sustain=frnd(.1),result.p_env_decay=.1+frnd(.2),rnd(1)&&(result.p_hpf_freq=frnd(.3)),result},jump=function(){return result=Params(),result.wave_type=SQUARE,result.wave_type=Math.floor(frnd(SHAPES.length)),3===result.wave_type&&(result.wave_type=SQUARE),result.p_duty=frnd(.6),result.p_base_freq=.3+frnd(.3),result.p_freq_ramp=.1+frnd(.2),result.p_env_attack=0,result.p_env_sustain=.1+frnd(.3),result.p_env_decay=.1+frnd(.2),rnd(1)&&(result.p_hpf_freq=frnd(.3)),rnd(1)&&(result.p_lpf_freq=1-frnd(.6)),result},blipSelect=function(){return result=Params(),result.wave_type=rnd(1),result.wave_type=Math.floor(frnd(SHAPES.length)),3===result.wave_type&&(result.wave_type=rnd(1)),result.wave_type===SQUARE&&(result.p_duty=frnd(.6)),result.p_base_freq=.2+frnd(.4),result.p_env_attack=0,result.p_env_sustain=.1+frnd(.1),result.p_env_decay=frnd(.2),result.p_hpf_freq=.1,result},random=function(){return result=Params(),result.wave_type=Math.floor(frnd(SHAPES.length)),result.p_base_freq=Math.pow(frnd(2)-1,2),rnd(1)&&(result.p_base_freq=Math.pow(frnd(2)-1,3)+.5),result.p_freq_limit=0,result.p_freq_ramp=Math.pow(frnd(2)-1,5),result.p_base_freq>.7&&result.p_freq_ramp>.2&&(result.p_freq_ramp=-result.p_freq_ramp),result.p_base_freq<.2&&result.p_freq_ramp<-.05&&(result.p_freq_ramp=-result.p_freq_ramp),result.p_freq_dramp=Math.pow(frnd(2)-1,3),result.p_duty=frnd(2)-1,result.p_duty_ramp=Math.pow(frnd(2)-1,3),result.p_vib_strength=Math.pow(frnd(2)-1,3),result.p_vib_speed=frnd(2)-1,result.p_env_attack=Math.pow(frnd(2)-1,3),result.p_env_sustain=Math.pow(frnd(2)-1,2),result.p_env_decay=frnd(2)-1,result.p_env_punch=Math.pow(frnd(.8),2),result.p_env_attack+result.p_env_sustain+result.p_env_decay<.2&&(result.p_env_sustain+=.2+frnd(.3),result.p_env_decay+=.2+frnd(.3)),result.p_lpf_resonance=frnd(2)-1,result.p_lpf_freq=1-Math.pow(frnd(1),3),result.p_lpf_ramp=Math.pow(frnd(2)-1,3),result.p_lpf_freq<.1&&result.p_lpf_ramp<-.05&&(result.p_lpf_ramp=-result.p_lpf_ramp),result.p_hpf_freq=Math.pow(frnd(1),5),result.p_hpf_ramp=Math.pow(frnd(2)-1,5),result.p_pha_offset=Math.pow(frnd(2)-1,3),result.p_pha_ramp=Math.pow(frnd(2)-1,3),result.p_repeat_speed=frnd(2)-1,result.p_arp_speed=frnd(2)-1,result.p_arp_mod=frnd(2)-1,result};var generators=[pickupCoin,laserShoot,explosion,powerUp,hitHurt,jump,blipSelect,pushSound,random,birdSound],generatorNames=["pickupCoin","laserShoot","explosion","powerUp","hitHurt","jump","blipSelect","pushSound","random","birdSound"];if(generateFromSeed=function(e){rng=new RNG(e/100|0);var r=e%100,_=generators[r%generators.length];seeded=!0;var p=_();return p.seed=e,seeded=!1,p},SoundEffect.prototype.getBuffer=function(){return this._buffer.getChannelData(0)},SoundEffect.prototype.play=function(){var e=AUDIO_CONTEXT.createBufferSource(),r=AUDIO_CONTEXT.createBiquadFilter(),_=AUDIO_CONTEXT.createBiquadFilter(),p=AUDIO_CONTEXT.createBiquadFilter();e.buffer=this._buffer,e.connect(r),r.frequency.value=1600,_.frequency.value=1600,p.frequency.value=1600,r.connect(_),_.connect(p),p.connect(AUDIO_CONTEXT.destination);var n=AUDIO_CONTEXT.currentTime;void 0!==e.start?e.start(n):e.noteOn(n)},SoundEffect.MIN_SAMPLE_RATE=22050,void 0===AUDIO_CONTEXT&&(SoundEffect=function(e,r){this._sample_rate=r,this._buffer=new Array(e),this._audioElement=null},SoundEffect.prototype.getBuffer=function(){return this._audioElement=null,this._buffer},SoundEffect.prototype.play=function(){if(this._audioElement)this._audioElement.cloneNode(!1).play();else{for(var e=0;e<this._buffer.length;e++)this._buffer[e]=255&Math.floor(128*Math.max(0,Math.min(this._buffer[e]+1,2)));var r=MakeRiff(this._sample_rate,BIT_DEPTH,this._buffer);this._audioElement=new Audio,this._audioElement.src=r.dataURI,this._audioElement.play()}},SoundEffect.MIN_SAMPLE_RATE=1),SoundEffect.generate=function(e){function r(){_=0,p=100/(e.p_base_freq*e.p_base_freq+.001),n=Math.floor(p),f=100/(e.p_freq_limit*e.p_freq_limit+.001),a=1-.01*Math.pow(e.p_freq_ramp,3),t=1e-6*-Math.pow(e.p_freq_dramp,3),d=.5-.5*e.p_duty,s=5e-5*-e.p_duty_ramp,u=e.p_arp_mod>=0?1-.9*Math.pow(e.p_arp_mod,2):1+10*Math.pow(e.p_arp_mod,2),o=0,l=Math.floor(2e4*Math.pow(1-e.p_arp_speed,2)+32),1==e.p_arp_speed&&(l=0)}var _,p,n,f,a,t,d,s,u,o,l;r();var h=0,v=0,i=.1*Math.pow(e.p_lpf_freq,3),m=1+1e-4*e.p_lpf_ramp,c=5/(1+20*Math.pow(e.p_lpf_resonance,2))*(.01+i);c>.8&&(c=.8);var y=0,q=.1*Math.pow(e.p_hpf_freq,2),w=1+3e-4*e.p_hpf_ramp,S=0,E=.01*Math.pow(e.p_vib_speed,2),M=.5*e.p_vib_strength,b=0,A=0,g=0,T=[Math.floor(e.p_env_attack*e.p_env_attack*1e5),Math.floor(e.p_env_sustain*e.p_env_sustain*1e5),Math.floor(e.p_env_decay*e.p_env_decay*1e5)],P=T[0]+T[1]+T[2],O=0,I=1020*Math.pow(e.p_pha_offset,2);e.p_pha_offset<0&&(I=-I);var N=1*Math.pow(e.p_pha_ramp,2);e.p_pha_ramp<0&&(N=-N);for(var R=Math.abs(Math.floor(I)),U=0,C=[],k=0;k<1024;++k)C[k]=0;for(var H=[],k=0;k<32;++k)H[k]=2*Math.random()-1;var x=Math.floor(2e4*Math.pow(1-e.p_repeat_speed,2)+32);0==e.p_repeat_speed&&(x=0);var D,B=2*e.sound_vol,B=Math.exp(e.sound_vol)-1,Q=0,X=0,L=Math.floor(44100/e.sample_rate),F=0,V=Math.ceil(P/L),W=!1;D=e.sample_rate<SoundEffect.MIN_SAMPLE_RATE?new SoundEffect(4*V,SoundEffect.MIN_SAMPLE_RATE):new SoundEffect(V,e.sample_rate);for(var j=D.getBuffer(),G=0;;++G){0!=x&&++_>=x&&r(),0!=l&&G>=l&&(l=0,p*=u),a+=t,p*=a,p>f&&(p=f,e.p_freq_limit>0&&(W=!0));var K=p;M>0&&(S+=E,K=p*(1+Math.sin(S)*M)),n=Math.floor(K),n<8&&(n=8),d+=s,d<0&&(d=0),d>.5&&(d=.5),g++,g>T[A]&&(g=0,3===++A&&(W=!0)),b=0===A?g/T[0]:1===A?1+2*Math.pow(1-g/T[1],1)*e.p_env_punch:1-g/T[2],I+=N,R=Math.abs(Math.floor(I)),R>1023&&(R=1023),0!=w&&(q*=w,q<1e-5&&(q=1e-5),q>.1&&(q=.1));for(var z=0,J=0;J<8;++J){var Y=0;if(++O>=n&&(O%=n,e.wave_type===NOISE))for(var k=0;k<32;++k)H[k]=2*Math.random()-1;var Z=O/n;if(e.wave_type===SQUARE)Y=Z<d?.5:-.5;else if(e.wave_type===SAWTOOTH)Y=1-2*Z;else if(e.wave_type===SINE)Y=Math.sin(2*Z*Math.PI);else if(e.wave_type===NOISE)Y=H[Math.floor(32*O/n)];else if(e.wave_type===TRIANGLE)Y=Math.abs(1-2*Z)-1;else{if(e.wave_type!==BREAKER)throw new Exception("bad wave type! "+e.wave_type);Y=Math.abs(1-Z*Z*2)-1}var $=h;i*=m,i<0&&(i=0),i>.1&&(i=.1),1!=e.p_lpf_freq?(v+=(Y-h)*i,v-=v*c):(h=Y,v=0),h+=v,y+=h-$,y-=y*q,Y=y,C[1023&U]=Y,Y+=C[U-R+1024&1023],U=U+1&1023,z+=Y*b}if(Q+=z,++X>=L&&(X=0,z=Q/L,Q=0,z=z/8*masterVolume,z*=B,j[F++]=z,e.sample_rate<SoundEffect.MIN_SAMPLE_RATE&&(j[F++]=z,j[F++]=z,j[F++]=z),W)){for(;F<V;F++)e.sample_rate<SoundEffect.MIN_SAMPLE_RATE&&(j[F++]=0,j[F++]=0,j[F++]=0),j[F]=0;break}}return D},"undefined"!=typeof exports){var RIFFWAVE=require("./riffwave").RIFFWAVE;exports.Params=Params,exports.generate=generate}var sfxCache={},cachedSeeds=[],CACHE_MAX=50;</script> <script>!function(e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else{if("function"==typeof define&&define.amd)return define([],e);this.CodeMirror=e()}}(function(){"use strict";function e(r,n){if(!(this instanceof e))return new e(r,n);this.options=n=n||{};for(var i in ro)n.hasOwnProperty(i)||(n[i]=ro[i]);d(n);var o=n.value;"string"==typeof o&&(o=new To(o,n.mode)),this.doc=o;var l=this.display=new t(r,o);l.wrapper.CodeMirror=this,c(this),a(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),n.autofocus&&!Ei&&ft(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,draggingText:!1,highlight:new Bn},yi&&setTimeout(jn(ct,this,!0),20),pt(this);var s=this;je(this,function(){s.curOp.forceUpdate=!0,an(s,o),n.autofocus&&!Ei||ti()==l.input?setTimeout(jn(It,s),20):zt(s);for(var e in no)no.hasOwnProperty(e)&&no[e](s,n[e],io);for(var t=0;t<ao.length;++t)ao[t](s)})}function t(e,t){var r=this,n=r.input=Zn("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none");Si?n.style.width="1000px":n.setAttribute("wrap","off"),Di&&(n.style.border="1px solid black"),n.setAttribute("autocorrect","off"),n.setAttribute("autocapitalize","off"),n.setAttribute("spellcheck","false"),r.inputDiv=Zn("div",[n],null,"overflow: hidden; position: relative; width: 3px; height: 0px;"),r.scrollbarH=Zn("div",[Zn("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar"),r.scrollbarV=Zn("div",[Zn("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),r.scrollbarFiller=Zn("div",null,"CodeMirror-scrollbar-filler"),r.gutterFiller=Zn("div",null,"CodeMirror-gutter-filler"),r.lineDiv=Zn("div",null,"CodeMirror-code"),r.selectionDiv=Zn("div",null,null,"position: relative; z-index: 1"),r.cursorDiv=Zn("div",null,"CodeMirror-cursors"),r.measure=Zn("div",null,"CodeMirror-measure"),r.lineMeasure=Zn("div",null,"CodeMirror-measure"),r.lineSpace=Zn("div",[r.measure,r.lineMeasure,r.selectionDiv,r.cursorDiv,r.lineDiv],null,"position: relative; outline: none"),r.mover=Zn("div",[Zn("div",[r.lineSpace],"CodeMirror-lines")],null,"position: relative"),r.sizer=Zn("div",[r.mover],"CodeMirror-sizer"),r.heightForcer=Zn("div",null,null,"position: absolute; height: "+Ro+"px; width: 1px;"),r.gutters=Zn("div",null,"CodeMirror-gutters"),r.lineGutter=null,r.scroller=Zn("div",[r.sizer,r.heightForcer,r.gutters],"CodeMirror-scroll"),r.scroller.setAttribute("tabIndex","-1"),r.wrapper=Zn("div",[r.inputDiv,r.scrollbarH,r.scrollbarV,r.scrollbarFiller,r.gutterFiller,r.scroller],"CodeMirror"),bi&&(r.gutters.style.zIndex=-1,r.scroller.style.paddingRight=0),Di&&(n.style.width="0px"),Si||(r.scroller.draggable=!0),Hi&&(r.inputDiv.style.height="1px",r.inputDiv.style.position="absolute"),bi&&(r.scrollbarH.style.minHeight=r.scrollbarV.style.minWidth="18px"),e.appendChild?e.appendChild(r.wrapper):e(r.wrapper),r.viewFrom=r.viewTo=t.first,r.view=[],r.externalMeasured=null,r.viewOffset=0,r.lastSizeC=0,r.updateLineNumbers=null,r.lineNumWidth=r.lineNumInnerWidth=r.lineNumChars=null,r.prevInput="",r.alignWidgets=!1,r.pollingFast=!1,r.poll=new Bn,r.cachedCharWidth=r.cachedTextHeight=r.cachedPaddingH=null,r.inaccurateSelection=!1,r.maxLine=null,r.maxLineLength=0,r.maxLineChanged=!1,r.wheelDX=r.wheelDY=r.wheelStartX=r.wheelStartY=null,r.shift=!1}function r(t){t.doc.mode=e.getMode(t.options,t.doc.modeOption),n(t)}function n(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,me(e,100),e.state.modeGen++,e.curOp&&et(e)}function i(e){e.options.lineWrapping?(e.display.wrapper.className+=" CodeMirror-wrap",e.display.sizer.style.minWidth=""):(e.display.wrapper.className=e.display.wrapper.className.replace(" CodeMirror-wrap",""),h(e)),l(e),et(e),De(e),setTimeout(function(){g(e)},100)}function o(e){var t=Ke(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/_e(e.display)-3);return function(i){if(Pr(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;l<i.widgets.length;l++)i.widgets[l].height&&(o+=i.widgets[l].height);return r?o+(Math.ceil(i.text.length/n)||1)*t:o+t}}function l(e){var t=e.doc,r=o(e);t.iter(function(e){var t=r(e);t!=e.height&&hn(e,t)})}function s(e){var t=po[e.options.keyMap],r=t.style;e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-keymap-\S+/g,"")+(r?" cm-keymap-"+r:"")}function a(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),De(e)}function u(e){c(e),et(e),setTimeout(function(){v(e)},20)}function c(e){var t=e.display.gutters,r=e.options.gutters;Qn(t);for(var n=0;n<r.length;++n){var i=r[n],o=t.appendChild(Zn("div",null,"CodeMirror-gutter "+i));"CodeMirror-linenumbers"==i&&(e.display.lineGutter=o,o.style.width=(e.display.lineNumWidth||1)+"px")}t.style.display=n?"":"none";var l=t.offsetWidth;e.display.sizer.style.marginLeft=l+"px",n&&(e.display.scrollbarH.style.left=e.options.fixedGutter?l+"px":0)}function f(e){if(0==e.height)return 0;for(var t,r=e.text.length,n=e;t=Ar(n);){var i=t.find(0,!0);n=i.from.line,r+=i.from.ch-i.to.ch}for(n=e;t=Or(n);){var i=t.find(0,!0);r-=n.text.length-i.from.ch,n=i.to.line,r+=n.text.length-i.to.ch}return r}function h(e){var t=e.display,r=e.doc;t.maxLine=un(r,r.first),t.maxLineLength=f(t.maxLine),t.maxLineChanged=!0,r.iter(function(e){var r=f(e);r>t.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function d(e){var t=Kn(e.gutters,"CodeMirror-linenumbers");-1==t&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function p(e){var t=e.display.scroller;return{clientHeight:t.clientHeight,barHeight:e.display.scrollbarV.clientHeight,scrollWidth:t.scrollWidth,clientWidth:t.clientWidth,barWidth:e.display.scrollbarH.clientWidth,docHeight:Math.round(e.doc.height+we(e.display))}}function g(e,t){t||(t=p(e));var r=e.display,n=t.docHeight+Ro,i=t.scrollWidth>t.clientWidth,o=n>t.clientHeight;if(o?(r.scrollbarV.style.display="block",r.scrollbarV.style.bottom=i?ri(r.measure)+"px":"0",r.scrollbarV.firstChild.style.height=Math.max(0,n-t.clientHeight+(t.barHeight||r.scrollbarV.clientHeight))+"px"):(r.scrollbarV.style.display="",r.scrollbarV.firstChild.style.height="0"),i?(r.scrollbarH.style.display="block",r.scrollbarH.style.right=o?ri(r.measure)+"px":"0",r.scrollbarH.firstChild.style.width=t.scrollWidth-t.clientWidth+(t.barWidth||r.scrollbarH.clientWidth)+"px"):(r.scrollbarH.style.display="",r.scrollbarH.firstChild.style.width="0"),i&&o?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=r.scrollbarFiller.style.width=ri(r.measure)+"px"):r.scrollbarFiller.style.display="",i&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=ri(r.measure)+"px",r.gutterFiller.style.width=r.gutters.offsetWidth+"px"):r.gutterFiller.style.display="",Ai&&0===ri(r.measure)){r.scrollbarV.style.minWidth=r.scrollbarH.style.minHeight=Oi?"18px":"12px";var l=function(t){Dn(t)!=r.scrollbarV&&Dn(t)!=r.scrollbarH&&$e(e,vt)(t)};Eo(r.scrollbarV,"mousedown",l),Eo(r.scrollbarH,"mousedown",l)}}function m(e,t,r){var n=r&&null!=r.top?r.top:e.scroller.scrollTop;n=Math.floor(n-xe(e));var i=r&&null!=r.bottom?r.bottom:n+e.wrapper.clientHeight,o=pn(t,n),l=pn(t,i);if(r&&r.ensure){var s=r.ensure.from.line,a=r.ensure.to.line;if(s<o)return{from:s,to:pn(t,gn(un(t,s))+e.wrapper.clientHeight)};if(Math.min(a,t.lastLine())>=l)return{from:pn(t,gn(un(t,a))-e.wrapper.clientHeight),to:a}}return{from:o,to:l}}function v(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=x(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",l=0;l<r.length;l++)if(!r[l].hidden){e.options.fixedGutter&&r[l].gutter&&(r[l].gutter.style.left=o);var s=r[l].alignable;if(s)for(var a=0;a<s.length;a++)s[a].style.left=o}e.options.fixedGutter&&(t.gutters.style.left=n+i+"px")}}function y(e){if(!e.options.lineNumbers)return!1;var t=e.doc,r=b(e.options,t.first+t.size-1),n=e.display;if(r.length!=n.lineNumChars){var i=n.measure.appendChild(Zn("div",[Zn("div",r)],"CodeMirror-linenumber CodeMirror-gutter-elt")),o=i.firstChild.offsetWidth,l=i.offsetWidth-o;n.lineGutter.style.width="",n.lineNumInnerWidth=Math.max(o,n.lineGutter.offsetWidth-l),n.lineNumWidth=n.lineNumInnerWidth+l,n.lineNumChars=n.lineNumInnerWidth?r.length:-1,n.lineGutter.style.width=n.lineNumWidth+"px";var s=n.gutters.offsetWidth;return n.scrollbarH.style.left=e.options.fixedGutter?s+"px":0,n.sizer.style.marginLeft=s+"px",!0}return!1}function b(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function x(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function w(e,t,r){for(var n,i=e.display.viewFrom,o=e.display.viewTo,l=m(e.display,e.doc,t),s=!0;;s=!1){var a=e.display.scroller.clientWidth;if(!C(e,l,r))break;n=!0,e.display.maxLineChanged&&!e.options.lineWrapping&&L(e);var u=p(e);if(he(e),S(e,u),g(e,u),s&&e.options.lineWrapping&&a!=e.display.scroller.clientWidth)r=!0;else if(r=!1,t&&null!=t.top&&(t={top:Math.min(u.docHeight-Ro-u.clientHeight,t.top)}),l=m(e.display,e.doc,t),l.from>=e.display.viewFrom&&l.to<=e.display.viewTo)break}return e.display.updateLineNumbers=null,n&&(In(e,"update",e),e.display.viewFrom==i&&e.display.viewTo==o||In(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo)),n}function C(e,t,r){var n=e.display,i=e.doc;if(!n.wrapper.offsetWidth)return void rt(e);if(!(!r&&t.from>=n.viewFrom&&t.to<=n.viewTo&&0==lt(e))){y(e)&&rt(e);var o=T(e),l=i.first+i.size,s=Math.max(t.from-e.options.viewportMargin,i.first),a=Math.min(l,t.to+e.options.viewportMargin);n.viewFrom<s&&s-n.viewFrom<20&&(s=Math.max(i.first,n.viewFrom)),n.viewTo>a&&n.viewTo-a<20&&(a=Math.min(l,n.viewTo)),Gi&&(s=Ir(e.doc,s),a=zr(e.doc,a));var u=s!=n.viewFrom||a!=n.viewTo||n.lastSizeC!=n.wrapper.clientHeight;ot(e,s,a),n.viewOffset=gn(un(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";var c=lt(e);if(u||0!=c||r){var f=ti();return c>4&&(n.lineDiv.style.display="none"),N(e,n.updateLineNumbers,o),c>4&&(n.lineDiv.style.display=""),f&&ti()!=f&&f.offsetHeight&&f.focus(),Qn(n.cursorDiv),Qn(n.selectionDiv),u&&(n.lastSizeC=n.wrapper.clientHeight,me(e,400)),k(e),!0}}}function L(e){var t=e.display,r=Me(e,t.maxLine,t.maxLine.text.length).left;t.maxLineChanged=!1;var n=Math.max(0,r+3),i=Math.max(0,t.sizer.offsetLeft+n+Ro-t.scroller.clientWidth);t.sizer.style.minWidth=n+"px",i<e.doc.scrollLeft&&Mt(e,Math.min(t.scroller.scrollLeft,i),!0)}function S(e,t){e.display.sizer.style.minHeight=e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=Math.max(t.docHeight,t.clientHeight-Ro)+"px"}function k(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;n<t.view.length;n++){var i,o=t.view[n];if(!o.hidden){if(bi){var l=o.node.offsetTop+o.node.offsetHeight;i=l-r,r=l}else{var s=o.node.getBoundingClientRect();i=s.bottom-s.top}var a=o.line.height-i;if(i<2&&(i=Ke(t)),(a>.001||a<-.001)&&(hn(o.line,i),M(o.line),o.rest))for(var u=0;u<o.rest.length;u++)M(o.rest[u])}}}function M(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t)e.widgets[t].height=e.widgets[t].node.offsetHeight}function T(e){for(var t=e.display,r={},n={},i=t.gutters.firstChild,o=0;i;i=i.nextSibling,++o)r[e.options.gutters[o]]=i.offsetLeft,n[e.options.gutters[o]]=i.offsetWidth;return{fixedPos:x(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:r,gutterWidth:n,wrapperWidth:t.wrapper.clientWidth}}function N(e,t,r){function n(t){var r=t.nextSibling;return Si&&Ii&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),r}for(var i=e.display,o=e.options.lineNumbers,l=i.lineDiv,s=l.firstChild,a=i.view,u=i.viewFrom,c=0;c<a.length;c++){var f=a[c];if(f.hidden);else if(f.node){for(;s!=f.node;)s=n(s);var h=o&&null!=t&&t<=u&&f.lineNumber;f.changes&&(Kn(f.changes,"gutter")>-1&&(h=!1),H(e,f,u,r)),h&&(Qn(f.lineNumber),f.lineNumber.appendChild(document.createTextNode(b(e.options,u)))),s=f.node.nextSibling}else{var d=P(e,f,u,r);l.insertBefore(d,s)}u+=f.size}for(;s;)s=n(s)}function H(e,t,r,n){for(var i=0;i<t.changes.length;i++){var o=t.changes[i];"text"==o?D(e,t):"gutter"==o?I(e,t,r,n):"class"==o?E(t):"widget"==o&&z(t,n)}t.changes=null}function A(e){return e.node==e.text&&(e.node=Zn("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),bi&&(e.node.style.zIndex=2)),e.node}function O(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var r=A(e);e.background=r.insertBefore(Zn("div",null,t),r.firstChild)}}function W(e,t){var r=e.display.externalMeasured;return r&&r.line==t.line?(e.display.externalMeasured=null,t.measure=r.measure,r.built):$r(e,t)}function D(e,t){var r=t.text.className,n=W(e,t);t.text==t.node&&(t.node=n.pre),t.text.parentNode.replaceChild(n.pre,t.text),t.text=n.pre,n.bgClass!=t.bgClass||n.textClass!=t.textClass?(t.bgClass=n.bgClass,t.textClass=n.textClass,E(t)):r&&(t.text.className=r)}function E(e){O(e),e.line.wrapClass?A(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function I(e,t,r,n){t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null);var i=t.line.gutterMarkers;if(e.options.lineNumbers||i){var o=A(t),l=t.gutter=o.insertBefore(Zn("div",null,"CodeMirror-gutter-wrapper","position: absolute; left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px"),t.text);if(!e.options.lineNumbers||i&&i["CodeMirror-linenumbers"]||(t.lineNumber=l.appendChild(Zn("div",b(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+n.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),i)for(var s=0;s<e.options.gutters.length;++s){var a=e.options.gutters[s],u=i.hasOwnProperty(a)&&i[a];u&&l.appendChild(Zn("div",[u],"CodeMirror-gutter-elt","left: "+n.gutterLeft[a]+"px; width: "+n.gutterWidth[a]+"px"))}}}function z(e,t){e.alignable&&(e.alignable=null);for(var r,n=e.node.firstChild;n;n=r){var r=n.nextSibling;"CodeMirror-linewidget"==n.className&&e.node.removeChild(n)}R(e,t)}function P(e,t,r,n){var i=W(e,t);return t.text=t.node=i.pre,i.bgClass&&(t.bgClass=i.bgClass),i.textClass&&(t.textClass=i.textClass),E(t),I(e,t,r,n),R(t,n),t.node}function R(e,t){if(F(e.line,e,t,!0),e.rest)for(var r=0;r<e.rest.length;r++)F(e.rest[r],e,t,!1)}function F(e,t,r,n){if(e.widgets)for(var i=A(t),o=0,l=e.widgets;o<l.length;++o){var s=l[o],a=Zn("div",[s.node],"CodeMirror-linewidget");s.handleMouseEvents||(a.ignoreEvents=!0),B(s,a,t,r),n&&s.above?i.insertBefore(a,t.gutter||t.text):i.appendChild(a),In(s,"redraw")}}function B(e,t,r,n){if(e.noHScroll){(r.alignable||(r.alignable=[])).push(t);var i=n.wrapperWidth;t.style.left=n.fixedPos+"px",e.coverGutter||(i-=n.gutterTotalWidth,t.style.paddingLeft=n.gutterTotalWidth+"px"),t.style.width=i+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-n.gutterTotalWidth+"px"))}function G(e){return Vi(e.line,e.ch)}function V(e,t){return Ui(e,t)<0?t:e}function U(e,t){return Ui(e,t)<0?e:t}function K(e,t){this.ranges=e,this.primIndex=t}function _(e,t){this.anchor=e,this.head=t}function X(e,t){var r=e[t];e.sort(function(e,t){return Ui(e.from(),t.from())}),t=Kn(e,r);for(var n=1;n<e.length;n++){var i=e[n],o=e[n-1];if(Ui(o.to(),i.from())>=0){var l=U(o.from(),i.from()),s=V(o.to(),i.to()),a=o.empty()?i.from()==i.head:o.from()==o.head;n<=t&&--t,e.splice(--n,2,new _(a?s:l,a?l:s))}}return new K(e,t)}function Y(e,t){return new K([new _(e,t||e)],0)}function j(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function $(e,t){if(t.line<e.first)return Vi(e.first,0);var r=e.first+e.size-1;return t.line>r?Vi(r,un(e,r).text.length):q(t,un(e,t.line).text.length)}function q(e,t){var r=e.ch;return null==r||r>t?Vi(e.line,t):r<0?Vi(e.line,0):e}function Z(e,t){return t>=e.first&&t<e.first+e.size}function Q(e,t){for(var r=[],n=0;n<t.length;n++)r[n]=$(e,t[n]);return r}function J(e,t,r,n){if(e.cm&&e.cm.display.shift||e.extend){var i=t.anchor;if(n){var o=Ui(r,i)<0;o!=Ui(n,i)<0?(i=r,r=n):o!=Ui(r,n)<0&&(r=n)}return new _(i,r)}return new _(n||r,r)}function ee(e,t,r,n){le(e,new K([J(e,e.sel.primary(),t,r)],0),n)}function te(e,t,r){for(var n=[],i=0;i<e.sel.ranges.length;i++)n[i]=J(e,e.sel.ranges[i],t[i],null);le(e,X(n,e.sel.primIndex),r)}function re(e,t,r,n){var i=e.sel.ranges.slice(0);i[t]=r,le(e,X(i,e.sel.primIndex),n)}function ne(e,t,r,n){le(e,Y(t,r),n)}function ie(e,t){var r={ranges:t.ranges,update:function(t){this.ranges=[];for(var r=0;r<t.length;r++)this.ranges[r]=new _($(e,t[r].anchor),$(e,t[r].head))}};return zo(e,"beforeSelectionChange",e,r),e.cm&&zo(e.cm,"beforeSelectionChange",e.cm,r),r.ranges!=t.ranges?X(r.ranges,r.ranges.length-1):t}function oe(e,t,r){var n=e.history.done,i=Un(n);i&&i.ranges?(n[n.length-1]=t,se(e,t,r)):le(e,t,r)}function le(e,t,r){se(e,t,r),Ln(e,e.sel,e.cm?e.cm.curOp.id:NaN,r)}function se(e,t,r){(Rn(e,"beforeSelectionChange")||e.cm&&Rn(e.cm,"beforeSelectionChange"))&&(t=ie(e,t)),ae(e,ce(e,t,Ui(t.primary().head,e.sel.primary().head)<0?-1:1,!0)),r&&!1===r.scroll||!e.cm||rr(e.cm)}function ae(e,t){t.equals(e.sel)||(e.sel=t,e.cm&&(e.cm.curOp.updateInput=e.cm.curOp.selectionChanged=e.cm.curOp.cursorActivity=!0),In(e,"cursorActivity",e))}function ue(e){ae(e,ce(e,e.sel,null,!1),Bo)}function ce(e,t,r,n){for(var i,o=0;o<t.ranges.length;o++){var l=t.ranges[o],s=fe(e,l.anchor,r,n),a=fe(e,l.head,r,n);(i||s!=l.anchor||a!=l.head)&&(i||(i=t.ranges.slice(0,o)),i[o]=new _(s,a))}return i?X(i,t.primIndex):t}function fe(e,t,r,n){var i=!1,o=t,l=r||1;e.cantEdit=!1;e:for(;;){var s=un(e,o.line);if(s.markedSpans)for(var a=0;a<s.markedSpans.length;++a){var u=s.markedSpans[a],c=u.marker;if((null==u.from||(c.inclusiveLeft?u.from<=o.ch:u.from<o.ch))&&(null==u.to||(c.inclusiveRight?u.to>=o.ch:u.to>o.ch))){if(n&&(zo(c,"beforeCursorEnter"),c.explicitlyCleared)){if(s.markedSpans){--a;continue}break}if(!c.atomic)continue;var f=c.find(l<0?-1:1);if(0==Ui(f,o)&&(f.ch+=l,f.ch<0?f=f.line>e.first?$(e,Vi(f.line-1)):null:f.ch>s.text.length&&(f=f.line<e.first+e.size-1?Vi(f.line+1,0):null),!f)){if(i)return n?(e.cantEdit=!0,Vi(e.first,0)):fe(e,t,r,!0);i=!0,f=t,l=-l}o=f;continue e}}return o}}function he(e){for(var t=e.display,r=e.doc,n=document.createDocumentFragment(),i=document.createDocumentFragment(),o=0;o<r.sel.ranges.length;o++){var l=r.sel.ranges[o],s=l.empty();(s||e.options.showCursorWhenSelecting)&&de(e,l,n),s||pe(e,l,i)}if(e.options.moveInputWithCursor){var a=Fe(e,r.sel.primary().head,"div"),u=t.wrapper.getBoundingClientRect(),c=t.lineDiv.getBoundingClientRect(),f=Math.max(0,Math.min(t.wrapper.clientHeight-10,a.top+c.top-u.top)),h=Math.max(0,Math.min(t.wrapper.clientWidth-10,a.left+c.left-u.left));t.inputDiv.style.top=f+"px",t.inputDiv.style.left=h+"px"}Jn(t.cursorDiv,n),Jn(t.selectionDiv,i)}function de(e,t,r){var n=Fe(e,t.head,"div"),i=r.appendChild(Zn("div"," ","CodeMirror-cursor"));if(i.style.left=n.left+"px",i.style.top=n.top+"px",i.style.height=Math.max(0,n.bottom-n.top)*e.options.cursorHeight+"px",n.other){var o=r.appendChild(Zn("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));o.style.display="",o.style.left=n.other.left+"px",o.style.top=n.other.top+"px",o.style.height=.85*(n.other.bottom-n.other.top)+"px"}}function pe(e,t,r){function n(e,t,r,n){t<0&&(t=0),s.appendChild(Zn("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(null==r?c-e:r)+"px; height: "+(n-t)+"px"))}function i(t,r,i){function o(r,n){return Re(e,Vi(t,r),"div",f,n)}var s,a,f=un(l,t),h=f.text.length;return oi(mn(f),r||0,null==i?h:i,function(e,t,l){var f,d,p,g=o(e,"left");if(e==t)f=g,d=p=g.left;else{if(f=o(t-1,"right"),"rtl"==l){var m=g;g=f,f=m}d=g.left,p=f.right}null==r&&0==e&&(d=u),f.top-g.top>3&&(n(d,g.top,null,g.bottom),d=u,g.bottom<f.top&&n(d,g.bottom,null,f.top)),null==i&&t==h&&(p=c),(!s||g.top<s.top||g.top==s.top&&g.left<s.left)&&(s=g),(!a||f.bottom>a.bottom||f.bottom==a.bottom&&f.right>a.right)&&(a=f),d<u+1&&(d=u),n(d,f.top,p-d,f.bottom)}),{start:s,end:a}}var o=e.display,l=e.doc,s=document.createDocumentFragment(),a=Ce(e.display),u=a.left,c=o.lineSpace.offsetWidth-a.right,f=t.from(),h=t.to();if(f.line==h.line)i(f.line,f.ch,h.ch);else{var d=un(l,f.line),p=un(l,h.line),g=Dr(d)==Dr(p),m=i(f.line,f.ch,g?d.text.length+1:null).end,v=i(h.line,g?0:null,h.ch).start;g&&(m.top<v.top-2?(n(m.right,m.top,null,m.bottom),n(u,v.top,v.left,v.bottom)):n(m.right,m.top,v.left-m.right,m.bottom)),m.bottom<v.top&&n(u,m.bottom,null,v.top)}r.appendChild(s)}function ge(e){if(e.state.focused){var t=e.display;clearInterval(t.blinker);var r=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0&&(t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(r=!r)?"":"hidden"},e.options.cursorBlinkRate))}}function me(e,t){e.doc.mode.startState&&e.doc.frontier<e.display.viewTo&&e.state.highlight.set(t,jn(ve,e))}function ve(e){var t=e.doc;if(t.frontier<t.first&&(t.frontier=t.first),!(t.frontier>=e.display.viewTo)){var r=+new Date+e.options.workTime,n=co(t.mode,be(e,t.frontier));je(e,function(){t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(i){if(t.frontier>=e.display.viewFrom){var o=i.styles;i.styles=_r(e,i,n,!0);for(var l=!o||o.length!=i.styles.length,s=0;!l&&s<o.length;++s)l=o[s]!=i.styles[s];l&&tt(e,t.frontier,"text"),i.stateAfter=co(t.mode,n)}else Yr(e,i.text,n),i.stateAfter=t.frontier%5==0?co(t.mode,n):null;if(++t.frontier,+new Date>r)return me(e,e.options.workDelay),!0})})}}function ye(e,t,r){for(var n,i,o=e.doc,l=r?-1:t-(e.doc.mode.innerMode?1e3:100),s=t;s>l;--s){if(s<=o.first)return o.first;var a=un(o,s-1);if(a.stateAfter&&(!r||s<=o.frontier))return s;var u=Uo(a.text,null,e.options.tabSize);(null==i||n>u)&&(i=s-1,n=u)}return i}function be(e,t,r){var n=e.doc,i=e.display;if(!n.mode.startState)return!0;var o=ye(e,t,r),l=o>n.first&&un(n,o-1).stateAfter;return l=l?co(n.mode,l):fo(n.mode),n.iter(o,t,function(r){Yr(e,r.text,l);var s=o==t-1||o%5==0||o>=i.viewFrom&&o<i.viewTo;r.stateAfter=s?co(n.mode,l):null,++o}),r&&(n.frontier=o),l}function xe(e){return e.lineSpace.offsetTop}function we(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function Ce(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=Jn(e.measure,Zn("pre","x")),r=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle;return e.cachedPaddingH={left:parseInt(r.paddingLeft),right:parseInt(r.paddingRight)}}function Le(e,t,r){var n=e.options.lineWrapping,i=n&&e.display.scroller.clientWidth;if(!t.measure.heights||n&&t.measure.width!=i){var o=t.measure.heights=[];if(n){t.measure.width=i;for(var l=t.text.firstChild.getClientRects(),s=0;s<l.length-1;s++){var a=l[s],u=l[s+1];Math.abs(a.bottom-u.bottom)>2&&o.push((a.bottom+u.top)/2-r.top)}}o.push(r.bottom-r.top)}}function Se(e,t,r){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var n=0;n<e.rest.length;n++)if(e.rest[n]==t)return{map:e.measure.maps[n],cache:e.measure.caches[n]};for(var n=0;n<e.rest.length;n++)if(dn(e.rest[n])>r)return{map:e.measure.maps[n],cache:e.measure.caches[n],before:!0}}function ke(e,t){t=Dr(t);var r=dn(t),n=e.display.externalMeasured=new Qe(e.doc,t,r);n.lineN=r;var i=n.built=$r(e,n);return n.text=i.pre,Jn(e.display.lineMeasure,i.pre),n}function Me(e,t,r,n){return He(e,Ne(e,t),r,n)}function Te(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[nt(e,t)];var r=e.display.externalMeasured;return r&&t>=r.lineN&&t<r.lineN+r.size?r:void 0}function Ne(e,t){var r=dn(t),n=Te(e,r);n&&!n.text?n=null:n&&n.changes&&H(e,n,r,T(e)),n||(n=ke(e,t));var i=Se(n,t,r);return{line:t,view:n,rect:null,map:i.map,cache:i.cache,before:i.before,hasHeights:!1}}function He(e,t,r,n){t.before&&(r=-1);var i,o=r+(n||"");return t.cache.hasOwnProperty(o)?i=t.cache[o]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(Le(e,t.view,t.rect),t.hasHeights=!0),i=Ae(e,t,r,n),i.bogus||(t.cache[o]=i)),{left:i.left,right:i.right,top:i.top,bottom:i.bottom}}function Ae(e,t,r,n){for(var i,o,l,s,a=t.map,u=0;u<a.length;u+=3){var c=a[u],f=a[u+1];if(r<c?(o=0,l=1,s="left"):r<f?(o=r-c,l=o+1):(u==a.length-3||r==f&&a[u+3]>r)&&(l=f-c,o=l-1,r>=f&&(s="right")),null!=o){if(i=a[u+2],c==f&&n==(i.insertLeft?"left":"right")&&(s=n),"left"==n&&0==o)for(;u&&a[u-2]==a[u-3]&&a[u-1].insertLeft;)i=a[2+(u-=3)],s="left";if("right"==n&&o==f-c)for(;u<a.length-3&&a[u+3]==a[u+4]&&!a[u+5].insertLeft;)i=a[(u+=3)+2],s="right";break}}var h;if(3==i.nodeType){for(;o&&qn(t.line.text.charAt(c+o));)--o;for(;c+l<f&&qn(t.line.text.charAt(c+l));)++l;if(xi&&0==o&&l==f-c)h=i.parentNode.getBoundingClientRect();else if(Li&&e.options.lineWrapping){var d=Xo(i,o,l).getClientRects();h=d.length?d["right"==n?d.length-1:0]:Yi}else h=Xo(i,o,l).getBoundingClientRect()}else{o>0&&(s=n="right");var d;h=e.options.lineWrapping&&(d=i.getClientRects()).length>1?d["right"==n?d.length-1:0]:i.getBoundingClientRect()}if(xi&&!o&&(!h||!h.left&&!h.right)){var p=i.parentNode.getClientRects()[0];h=p?{left:p.left,right:p.left+_e(e.display),top:p.top,bottom:p.bottom}:Yi}for(var g,m=(h.bottom+h.top)/2-t.rect.top,v=t.view.measure.heights,u=0;u<v.length-1&&!(m<v[u]);u++);g=u?v[u-1]:0,m=v[u];var y={left:("right"==s?h.right:h.left)-t.rect.left,right:("left"==s?h.left:h.right)-t.rect.left,top:g,bottom:m};return h.left||h.right||(y.bogus=!0),y}function Oe(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(var t=0;t<e.rest.length;t++)e.measure.caches[t]={}}function We(e){e.display.externalMeasure=null,Qn(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++)Oe(e.display.view[t])}function De(e){We(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function Ee(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function Ie(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function ze(e,t,r,n){if(t.widgets)for(var i=0;i<t.widgets.length;++i)if(t.widgets[i].above){var o=Br(t.widgets[i]);r.top+=o,r.bottom+=o}if("line"==n)return r;n||(n="local");var l=gn(t);if("local"==n?l+=xe(e.display):l-=e.display.viewOffset,"page"==n||"window"==n){var s=e.display.lineSpace.getBoundingClientRect();l+=s.top+("window"==n?0:Ie());var a=s.left+("window"==n?0:Ee());r.left+=a,r.right+=a}return r.top+=l,r.bottom+=l,r}function Pe(e,t,r){if("div"==r)return t;var n=t.left,i=t.top;if("page"==r)n-=Ee(),i-=Ie();else if("local"==r||!r){var o=e.display.sizer.getBoundingClientRect();n+=o.left,i+=o.top}var l=e.display.lineSpace.getBoundingClientRect();return{left:n-l.left,top:i-l.top}}function Re(e,t,r,n,i){return n||(n=un(e.doc,t.line)),ze(e,n,Me(e,n,t.ch,i),r)}function Fe(e,t,r,n,i){function o(t,o){var l=He(e,i,t,o?"right":"left");return o?l.left=l.right:l.right=l.left,ze(e,n,l,r)}function l(e,t){var r=s[t],n=r.level%2;return e==li(r)&&t&&r.level<s[t-1].level?(r=s[--t],e=si(r)-(r.level%2?0:1),n=!0):e==si(r)&&t<s.length-1&&r.level<s[t+1].level&&(r=s[++t],e=li(r)-r.level%2,n=!1),n&&e==r.to&&e>r.from?o(e-1):o(e,n)}n=n||un(e.doc,t.line),i||(i=Ne(e,n));var s=mn(n),a=t.ch;if(!s)return o(a);var u=di(s,a),c=l(a,u);return null!=il&&(c.other=l(a,il)),c}function Be(e,t){var r=0,t=$(e.doc,t);e.options.lineWrapping||(r=_e(e.display)*t.ch);var n=un(e.doc,t.line),i=gn(n)+xe(e.display);return{left:r,right:r,top:i,bottom:i+n.height}}function Ge(e,t,r,n){var i=Vi(e,t);return i.xRel=n,r&&(i.outside=!0),i}function Ve(e,t,r){var n=e.doc;if((r+=e.display.viewOffset)<0)return Ge(n.first,0,!0,-1);var i=pn(n,r),o=n.first+n.size-1;if(i>o)return Ge(n.first+n.size-1,un(n,o).text.length,!0,1);t<0&&(t=0);for(var l=un(n,i);;){var s=Ue(e,l,i,t,r),a=Or(l),u=a&&a.find(0,!0);if(!a||!(s.ch>u.from.ch||s.ch==u.from.ch&&s.xRel>0))return s;i=dn(l=u.to.line)}}function Ue(e,t,r,n,i){function o(n){var i=Fe(e,Vi(r,n),"line",t,u);return s=!0,l>i.bottom?i.left-a:l<i.top?i.left+a:(s=!1,i.left)}var l=i-gn(t),s=!1,a=2*e.display.wrapper.clientWidth,u=Ne(e,t),c=mn(t),f=t.text.length,h=ai(t),d=ui(t),p=o(h),g=s,m=o(d),v=s;if(n>m)return Ge(r,d,v,1);for(;;){if(c?d==h||d==gi(t,h,1):d-h<=1){for(var y=n<p||n-p<=m-n?h:d,b=n-(y==h?p:m);qn(t.text.charAt(y));)++y;return Ge(r,y,y==h?g:v,b<-1?-1:b>1?1:0)}var x=Math.ceil(f/2),w=h+x;if(c){w=h;for(var C=0;C<x;++C)w=gi(t,w,1)}var L=o(w);L>n?(d=w,m=L,(v=s)&&(m+=1e3),f=x):(h=w,p=L,g=s,f-=x)}}function Ke(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Ki){Ki=Zn("pre");for(var t=0;t<49;++t)Ki.appendChild(document.createTextNode("x")),Ki.appendChild(Zn("br"));Ki.appendChild(document.createTextNode("x"))}Jn(e.measure,Ki);var r=Ki.offsetHeight/50;return r>3&&(e.cachedTextHeight=r),Qn(e.measure),r||1}function _e(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=Zn("span","xxxxxxxxxx"),r=Zn("pre",[t]);Jn(e.measure,r);var n=t.getBoundingClientRect(),i=(n.right-n.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function Xe(e){e.curOp={viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivity:!1,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,id:++ji},Po++||(Ao=[])}function Ye(e){var t=e.curOp,r=e.doc,n=e.display;if(e.curOp=null,t.updateMaxLine&&h(e),t.viewChanged||t.forceUpdate||null!=t.scrollTop||t.scrollToPos&&(t.scrollToPos.from.line<n.viewFrom||t.scrollToPos.to.line>=n.viewTo)||n.maxLineChanged&&e.options.lineWrapping){var i=w(e,{top:t.scrollTop,ensure:t.scrollToPos},t.forceUpdate);e.display.scroller.offsetHeight&&(e.doc.scrollTop=e.display.scroller.scrollTop)}if(!i&&t.selectionChanged&&he(e),i||t.startHeight==e.doc.height||g(e),null!=t.scrollTop&&n.scroller.scrollTop!=t.scrollTop){var o=Math.max(0,Math.min(n.scroller.scrollHeight-n.scroller.clientHeight,t.scrollTop));n.scroller.scrollTop=n.scrollbarV.scrollTop=r.scrollTop=o}if(null!=t.scrollLeft&&n.scroller.scrollLeft!=t.scrollLeft){var l=Math.max(0,Math.min(n.scroller.scrollWidth-n.scroller.clientWidth,t.scrollLeft));n.scroller.scrollLeft=n.scrollbarH.scrollLeft=r.scrollLeft=l,v(e)}if(t.scrollToPos){var s=Qt(e,$(e.doc,t.scrollToPos.from),$(e.doc,t.scrollToPos.to),t.scrollToPos.margin);t.scrollToPos.isCursor&&e.state.focused&&Zt(e,s)}t.selectionChanged&&ge(e),e.state.focused&&t.updateInput&&ct(e,t.typing);var a=t.maybeHiddenMarkers,u=t.maybeUnhiddenMarkers;if(a)for(var c=0;c<a.length;++c)a[c].lines.length||zo(a[c],"hide");if(u)for(var c=0;c<u.length;++c)u[c].lines.length&&zo(u[c],"unhide");var f;if(--Po||(f=Ao,Ao=null),t.changeObjs){for(var c=0;c<t.changeObjs.length;c++)zo(e,"change",e,t.changeObjs[c]);zo(e,"changes",e,t.changeObjs)}if(t.cursorActivity&&zo(e,"cursorActivity",e),f)for(var c=0;c<f.length;++c)f[c]()}function je(e,t){if(e.curOp)return t();Xe(e);try{return t()}finally{Ye(e)}}function $e(e,t){return function(){if(e.curOp)return t.apply(e,arguments);Xe(e);try{return t.apply(e,arguments)}finally{Ye(e)}}}function qe(e){return function(){if(this.curOp)return e.apply(this,arguments);Xe(this);try{return e.apply(this,arguments)}finally{Ye(this)}}}function Ze(e){return function(){var t=this.cm;if(!t||t.curOp)return e.apply(this,arguments);Xe(t);try{return e.apply(this,arguments)}finally{Ye(t)}}}function Qe(e,t,r){this.line=t,this.rest=Er(t),this.size=this.rest?dn(Un(this.rest))-r+1:1,this.node=this.text=null,this.hidden=Pr(e,t)}function Je(e,t,r){for(var n,i=[],o=t;o<r;o=n){var l=new Qe(e.doc,un(e.doc,o),o);n=o+l.size,i.push(l)}return i}function et(e,t,r,n){null==t&&(t=e.doc.first),null==r&&(r=e.doc.first+e.doc.size),n||(n=0);var i=e.display
;if(n&&r<i.viewTo&&(null==i.updateLineNumbers||i.updateLineNumbers>t)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Gi&&Ir(e.doc,t)<i.viewTo&&rt(e);else if(r<=i.viewFrom)Gi&&zr(e.doc,r+n)>i.viewFrom?rt(e):(i.viewFrom+=n,i.viewTo+=n);else if(t<=i.viewFrom&&r>=i.viewTo)rt(e);else if(t<=i.viewFrom){var o=it(e,r,r+n,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=n):rt(e)}else if(r>=i.viewTo){var o=it(e,t,t,-1);o?(i.view=i.view.slice(0,o.index),i.viewTo=o.lineN):rt(e)}else{var l=it(e,t,t,-1),s=it(e,r,r+n,1);l&&s?(i.view=i.view.slice(0,l.index).concat(Je(e,l.lineN,s.lineN)).concat(i.view.slice(s.index)),i.viewTo+=n):rt(e)}var a=i.externalMeasured;a&&(r<a.lineN?a.lineN+=n:t<a.lineN+a.size&&(i.externalMeasured=null))}function tt(e,t,r){e.curOp.viewChanged=!0;var n=e.display,i=e.display.externalMeasured;if(i&&t>=i.lineN&&t<i.lineN+i.size&&(n.externalMeasured=null),!(t<n.viewFrom||t>=n.viewTo)){var o=n.view[nt(e,t)];if(null!=o.node){var l=o.changes||(o.changes=[]);-1==Kn(l,r)&&l.push(r)}}}function rt(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function nt(e,t){if(t>=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;for(var r=e.display.view,n=0;n<r.length;n++)if((t-=r[n].size)<0)return n}function it(e,t,r,n){var i,o=nt(e,t),l=e.display.view;if(!Gi)return{index:o,lineN:r};for(var s=0,a=e.display.viewFrom;s<o;s++)a+=l[s].size;if(a!=t){if(n>0){if(o==l.length-1)return null;i=a+l[o].size-t,o++}else i=a-t;t+=i,r+=i}for(;Ir(e.doc,r)!=r;){if(o==(n<0?0:l.length-1))return null;r+=n*l[o-(n<0?1:0)].size,o+=n}return{index:o,lineN:r}}function ot(e,t,r){var n=e.display;0==n.view.length||t>=n.viewTo||r<=n.viewFrom?(n.view=Je(e,t,r),n.viewFrom=t):(n.viewFrom>t?n.view=Je(e,t,n.viewFrom).concat(n.view):n.viewFrom<t&&(n.view=n.view.slice(nt(e,t))),n.viewFrom=t,n.viewTo<r?n.view=n.view.concat(Je(e,n.viewTo,r)):n.viewTo>r&&(n.view=n.view.slice(0,nt(e,r)))),n.viewTo=r}function lt(e){for(var t=e.display.view,r=0,n=0;n<t.length;n++){var i=t[n];i.hidden||i.node&&!i.changes||++r}return r}function st(e){e.display.pollingFast||e.display.poll.set(e.options.pollInterval,function(){ut(e),e.state.focused&&st(e)})}function at(e){function t(){ut(e)||r?(e.display.pollingFast=!1,st(e)):(r=!0,e.display.poll.set(60,t))}var r=!1;e.display.pollingFast=!0,e.display.poll.set(20,t)}function ut(e){var t=e.display.input,r=e.display.prevInput,n=e.doc;if(!e.state.focused||tl(t)||dt(e)||e.options.disableInput)return!1;var i=t.value;if(i==r&&!e.somethingSelected())return!1;if(Li&&!xi&&e.display.inputHasSelection===i)return ct(e),!1;var o=!e.curOp;o&&Xe(e),e.display.shift=!1;for(var l=0,s=Math.min(r.length,i.length);l<s&&r.charCodeAt(l)==i.charCodeAt(l);)++l;for(var a=i.slice(l),u=el(a),c=e.state.pasteIncoming&&u.length>1&&n.sel.ranges.length==u.length,f=n.sel.ranges.length-1;f>=0;f--){var h=n.sel.ranges[f],d=h.from(),p=h.to();l<r.length?d=Vi(d.line,d.ch-(r.length-l)):e.state.overwrite&&h.empty()&&!e.state.pasteIncoming&&(p=Vi(p.line,Math.min(un(n,p.line).text.length,p.ch+Un(u).length)));var g=e.curOp.updateInput,m={from:d,to:p,text:c?[u[f]]:u,origin:e.state.pasteIncoming?"paste":e.state.cutIncoming?"cut":"+input"};if(Kt(e.doc,m),In(e,"inputRead",e,m),a&&!e.state.pasteIncoming&&e.options.electricChars&&e.options.smartIndent&&h.head.ch<100&&(!f||n.sel.ranges[f-1].head.line!=h.head.line)){var v=e.getModeAt(h.head).electricChars;if(v)for(var y=0;y<v.length;y++)if(a.indexOf(v.charAt(y))>-1){ir(e,h.head.line,"smart");break}}}return rr(e),e.curOp.updateInput=g,e.curOp.typing=!0,i.length>1e3||i.indexOf("\n")>-1?t.value=e.display.prevInput="":e.display.prevInput=i,o&&Ye(e),e.state.pasteIncoming=e.state.cutIncoming=!1,!0}function ct(e,t){var r,n,i=e.doc;if(e.somethingSelected()){e.display.prevInput="";var o=i.sel.primary();r=rl&&(o.to().line-o.from().line>100||(n=e.getSelection()).length>1e3);var l=r?"-":n||e.getSelection();e.display.input.value=l,e.state.focused&&_o(e.display.input),Li&&!xi&&(e.display.inputHasSelection=l)}else t||(e.display.prevInput=e.display.input.value="",Li&&!xi&&(e.display.inputHasSelection=null));e.display.inaccurateSelection=r}function ft(e){"nocursor"==e.options.readOnly||Ei&&ti()==e.display.input||e.display.input.focus()}function ht(e){e.state.focused||(ft(e),It(e))}function dt(e){return e.options.readOnly||e.doc.cantEdit}function pt(e){function t(){e.state.focused&&setTimeout(jn(ft,e),0)}function r(){null==s&&(s=setTimeout(function(){s=null,l.cachedCharWidth=l.cachedTextHeight=l.cachedPaddingH=qo=null,e.setSize()},100))}function n(){ei(document.body,l.wrapper)?setTimeout(n,5e3):Io(window,"resize",r)}function i(t){Pn(e,t)||Do(t)}function o(t){l.inaccurateSelection&&(l.prevInput="",l.inaccurateSelection=!1,l.input.value=e.getSelection(),_o(l.input)),"cut"==t.type&&(e.state.cutIncoming=!0)}var l=e.display;Eo(l.scroller,"mousedown",$e(e,vt)),yi?Eo(l.scroller,"dblclick",$e(e,function(t){if(!Pn(e,t)){var r=mt(e,t);if(r&&!Ct(e,t)&&!gt(e.display,t)){Oo(t);var n=ur(e.doc,r);ee(e.doc,n.anchor,n.head)}}})):Eo(l.scroller,"dblclick",function(t){Pn(e,t)||Oo(t)}),Eo(l.lineSpace,"selectstart",function(e){gt(l,e)||Oo(e)}),Fi||Eo(l.scroller,"contextmenu",function(t){Pt(e,t)}),Eo(l.scroller,"scroll",function(){l.scroller.clientHeight&&(kt(e,l.scroller.scrollTop),Mt(e,l.scroller.scrollLeft,!0),zo(e,"scroll",e))}),Eo(l.scrollbarV,"scroll",function(){l.scroller.clientHeight&&kt(e,l.scrollbarV.scrollTop)}),Eo(l.scrollbarH,"scroll",function(){l.scroller.clientHeight&&Mt(e,l.scrollbarH.scrollLeft)}),Eo(l.scroller,"mousewheel",function(t){Tt(e,t)}),Eo(l.scroller,"DOMMouseScroll",function(t){Tt(e,t)}),Eo(l.scrollbarH,"mousedown",t),Eo(l.scrollbarV,"mousedown",t),Eo(l.wrapper,"scroll",function(){l.wrapper.scrollTop=l.wrapper.scrollLeft=0});var s;Eo(window,"resize",r),setTimeout(n,5e3),Eo(l.input,"keyup",$e(e,Dt)),Eo(l.input,"input",function(){Li&&!xi&&e.display.inputHasSelection&&(e.display.inputHasSelection=null),at(e)}),Eo(l.input,"keydown",$e(e,Wt)),Eo(l.input,"keypress",$e(e,Et)),Eo(l.input,"focus",jn(It,e)),Eo(l.input,"blur",jn(zt,e)),e.options.dragDrop&&(Eo(l.scroller,"dragstart",function(t){St(e,t)}),Eo(l.scroller,"dragenter",i),Eo(l.scroller,"dragover",i),Eo(l.scroller,"drop",$e(e,Lt))),Eo(l.scroller,"paste",function(t){gt(l,t)||(e.state.pasteIncoming=!0,ft(e),at(e))}),Eo(l.input,"paste",function(){e.state.pasteIncoming=!0,at(e)}),Eo(l.input,"cut",o),Eo(l.input,"copy",o),Hi&&Eo(l.sizer,"mouseup",function(){ti()==l.input&&l.input.blur(),ft(e)})}function gt(e,t){for(var r=Dn(t);r!=e.wrapper;r=r.parentNode)if(!r||r.ignoreEvents||r.parentNode==e.sizer&&r!=e.mover)return!0}function mt(e,t,r,n){var i=e.display;if(!r){var o=Dn(t);if(o==i.scrollbarH||o==i.scrollbarV||o==i.scrollbarFiller||o==i.gutterFiller)return null}var l,s,a=i.lineSpace.getBoundingClientRect();try{l=t.clientX-a.left,s=t.clientY-a.top}catch(t){return null}var u,c=Ve(e,l,s);if(n&&1==c.xRel&&(u=un(e.doc,c.line).text).length==c.ch){var f=Uo(u,u.length,e.options.tabSize)-u.length;c=Vi(c.line,Math.round((l-Ce(e.display).left)/_e(e.display))-f)}return c}function vt(e){if(!Pn(this,e)){var t=this,r=t.display;if(r.shift=e.shiftKey,gt(r,e))return void(Si||(r.scroller.draggable=!1,setTimeout(function(){r.scroller.draggable=!0},100)));if(!Ct(t,e)){var n=mt(t,e);switch(window.focus(),En(e)){case 1:n?yt(t,e,n):Dn(e)==r.scroller&&Oo(e);break;case 2:Si&&(t.state.lastMiddleDown=+new Date),n&&ee(t.doc,n),setTimeout(jn(ft,t),20),Oo(e);break;case 3:Fi&&Pt(t,e)}}}}function yt(e,t,r){setTimeout(jn(ht,e),0);var n,i=+new Date;Xi&&Xi.time>i-400&&0==Ui(Xi.pos,r)?n="triple":_i&&_i.time>i-400&&0==Ui(_i.pos,r)?(n="double",Xi={time:i,pos:r}):(n="single",_i={time:i,pos:r});var o=e.doc.sel;e.options.dragDrop&&Jo&&!dt(e)&&"single"==n&&o.contains(r)>-1&&o.somethingSelected()?bt(e,t,r):xt(e,t,r,n,!1)}function bt(e,t,r){var n=e.display,i=$e(e,function(o){Si&&(n.scroller.draggable=!1),e.state.draggingText=!1,Io(document,"mouseup",i),Io(n.scroller,"drop",i),Math.abs(t.clientX-o.clientX)+Math.abs(t.clientY-o.clientY)<10&&(Oo(o),ee(e.doc,r),ft(e),yi&&!xi&&setTimeout(function(){document.body.focus(),ft(e)},20))});Si&&(n.scroller.draggable=!0),e.state.draggingText=i,n.scroller.dragDrop&&n.scroller.dragDrop(),Eo(document,"mouseup",i),Eo(n.scroller,"drop",i)}function xt(e,t,r,n,i){function o(t){if(0!=Ui(g,t))if(g=t,"rect"==n){for(var i=[],o=e.options.tabSize,l=Uo(un(u,r.line).text,r.ch,o),s=Uo(un(u,t.line).text,t.ch,o),a=Math.min(l,s),d=Math.max(l,s),p=Math.min(r.line,t.line),m=Math.min(e.lastLine(),Math.max(r.line,t.line));p<=m;p++){var v=un(u,p).text,y=Gn(v,a,o);a==d?i.push(new _(Vi(p,y),Vi(p,y))):v.length>y&&i.push(new _(Vi(p,y),Vi(p,Gn(v,d,o))))}i.length||i.push(new _(r,r)),le(u,X(h.ranges.slice(0,f).concat(i),f),Go)}else{var b=c,x=b.anchor,w=t;if("single"!=n){if("double"==n)var C=ur(u,t);else var C=new _(Vi(t.line,0),$(u,Vi(t.line+1,0)));Ui(C.anchor,x)>0?(w=C.head,x=U(b.from(),C.anchor)):(w=C.anchor,x=V(b.to(),C.head))}var i=h.ranges.slice(0);i[f]=new _($(u,x),w),le(u,X(i,f),Go)}}function l(t){var r=++y,i=mt(e,t,!0,"rect"==n);if(i)if(0!=Ui(i,g)){ht(e),o(i);var s=m(a,u);(i.line>=s.to||i.line<s.from)&&setTimeout($e(e,function(){y==r&&l(t)}),150)}else{var c=t.clientY<v.top?-20:t.clientY>v.bottom?20:0;c&&setTimeout($e(e,function(){y==r&&(a.scroller.scrollTop+=c,l(t))}),50)}}function s(t){y=1/0,Oo(t),ft(e),Io(document,"mousemove",b),Io(document,"mouseup",x),u.history.lastSelOrigin=null}var a=e.display,u=e.doc;Oo(t);var c,f,h=u.sel;if(i?(f=u.sel.contains(r),c=f>-1?u.sel.ranges[f]:new _(r,r)):c=u.sel.primary(),t.altKey)n="rect",i||(c=new _(r,r)),r=mt(e,t,!0,!0),f=-1;else if("double"==n){var d=ur(u,r);c=e.display.shift||u.extend?J(u,c,d.anchor,d.head):d}else if("triple"==n){var p=new _(Vi(r.line,0),$(u,Vi(r.line+1,0)));c=e.display.shift||u.extend?J(u,c,p.anchor,p.head):p}else c=J(u,c,r);i?f>-1?re(u,f,c,Go):(f=u.sel.ranges.length,le(u,X(u.sel.ranges.concat([c]),f),{scroll:!1,origin:"*mouse"})):(f=0,le(u,new K([c],0),Go));var g=r,v=a.wrapper.getBoundingClientRect(),y=0,b=$e(e,function(e){(Li&&!wi?e.buttons:En(e))?l(e):s(e)}),x=$e(e,s);Eo(document,"mousemove",b),Eo(document,"mouseup",x)}function wt(e,t,r,n,i){try{var o=t.clientX,l=t.clientY}catch(t){return!1}if(o>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;n&&Oo(t);var s=e.display,a=s.lineDiv.getBoundingClientRect();if(l>a.bottom||!Rn(e,r))return Wn(t);l-=a.top-s.viewOffset;for(var u=0;u<e.options.gutters.length;++u){var c=s.gutters.childNodes[u];if(c&&c.getBoundingClientRect().right>=o){return i(e,r,e,pn(e.doc,l),e.options.gutters[u],t),Wn(t)}}}function Ct(e,t){return wt(e,t,"gutterClick",!0,In)}function Lt(e){var t=this;if(!Pn(t,e)&&!gt(t.display,e)){Oo(e),yi&&($i=+new Date);var r=mt(t,e,!0),n=e.dataTransfer.files;if(r&&!dt(t))if(n&&n.length&&window.FileReader&&window.File)for(var i=n.length,o=Array(i),l=0,s=0;s<i;++s)!function(e,n){var s=new FileReader;s.onload=function(){if(o[n]=s.result,++l==i){r=$(t.doc,r);var e={from:r,to:r,text:el(o.join("\n")),origin:"paste"};Kt(t.doc,e),oe(t.doc,Y(r,to(e)))}},s.readAsText(e)}(n[s],s);else{if(t.state.draggingText&&t.doc.sel.contains(r)>-1)return t.state.draggingText(e),void setTimeout(jn(ft,t),20);try{var o=e.dataTransfer.getData("Text");if(o){var a=t.state.draggingText&&t.listSelections();if(se(t.doc,Y(r,r)),a)for(var s=0;s<a.length;++s)qt(t.doc,"",a[s].anchor,a[s].head,"drag");t.replaceSelection(o,"around","paste"),ft(t)}}catch(e){}}}}function St(e,t){if(yi&&(!e.state.draggingText||+new Date-$i<100))return void Do(t);if(!Pn(e,t)&&!gt(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.setDragImage&&!Ni)){var r=Zn("img",null,null,"position: fixed; left: 0; top: 0;");r.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",Ti&&(r.width=r.height=1,e.display.wrapper.appendChild(r),r._top=r.offsetTop),t.dataTransfer.setDragImage(r,0,0),Ti&&r.parentNode.removeChild(r)}}function kt(e,t){Math.abs(e.doc.scrollTop-t)<2||(e.doc.scrollTop=t,vi||w(e,{top:t}),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t),e.display.scrollbarV.scrollTop!=t&&(e.display.scrollbarV.scrollTop=t),vi&&w(e),me(e,100))}function Mt(e,t,r){(r?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)||(t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth),e.doc.scrollLeft=t,v(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbarH.scrollLeft!=t&&(e.display.scrollbarH.scrollLeft=t))}function Tt(e,t){var r=t.wheelDeltaX,n=t.wheelDeltaY;null==r&&t.detail&&t.axis==t.HORIZONTAL_AXIS&&(r=t.detail),null==n&&t.detail&&t.axis==t.VERTICAL_AXIS?n=t.detail:null==n&&(n=t.wheelDelta);var i=e.display,o=i.scroller;if(r&&o.scrollWidth>o.clientWidth||n&&o.scrollHeight>o.clientHeight){if(n&&Ii&&Si)e:for(var l=t.target,s=i.view;l!=o;l=l.parentNode)for(var a=0;a<s.length;a++)if(s[a].node==l){e.display.currentWheelTarget=l;break e}if(r&&!vi&&!Ti&&null!=Zi)return n&&kt(e,Math.max(0,Math.min(o.scrollTop+n*Zi,o.scrollHeight-o.clientHeight))),Mt(e,Math.max(0,Math.min(o.scrollLeft+r*Zi,o.scrollWidth-o.clientWidth))),Oo(t),void(i.wheelStartX=null);if(n&&null!=Zi){var u=n*Zi,c=e.doc.scrollTop,f=c+i.wrapper.clientHeight;u<0?c=Math.max(0,c+u-50):f=Math.min(e.doc.height,f+u+50),w(e,{top:c,bottom:f})}qi<20&&(null==i.wheelStartX?(i.wheelStartX=o.scrollLeft,i.wheelStartY=o.scrollTop,i.wheelDX=r,i.wheelDY=n,setTimeout(function(){if(null!=i.wheelStartX){var e=o.scrollLeft-i.wheelStartX,t=o.scrollTop-i.wheelStartY,r=t&&i.wheelDY&&t/i.wheelDY||e&&i.wheelDX&&e/i.wheelDX;i.wheelStartX=i.wheelStartY=null,r&&(Zi=(Zi*qi+r)/(qi+1),++qi)}},200)):(i.wheelDX+=r,i.wheelDY+=n))}}function Nt(e,t,r){if("string"==typeof t&&!(t=ho[t]))return!1;e.display.pollingFast&&ut(e)&&(e.display.pollingFast=!1);var n=e.display.shift,i=!1;try{dt(e)&&(e.state.suppressEdits=!0),r&&(e.display.shift=!1),i=t(e)!=Fo}finally{e.display.shift=n,e.state.suppressEdits=!1}return i}function Ht(e){var t=e.state.keyMaps.slice(0);return e.options.extraKeys&&t.push(e.options.extraKeys),t.push(e.options.keyMap),t}function At(e,t){var r=fr(e.options.keyMap),n=r.auto;clearTimeout(Qi),n&&!mo(t)&&(Qi=setTimeout(function(){fr(e.options.keyMap)==r&&(e.options.keyMap=n.call?n.call(null,e):n,s(e))},50));var i=vo(t,!0),o=!1;if(!i)return!1;var l=Ht(e);return o=t.shiftKey?go("Shift-"+i,l,function(t){return Nt(e,t,!0)})||go(i,l,function(t){if("string"==typeof t?/^go[A-Z]/.test(t):t.motion)return Nt(e,t)}):go(i,l,function(t){return Nt(e,t)}),o&&(Oo(t),ge(e),In(e,"keyHandled",e,i,t)),o}function Ot(e,t,r){var n=go("'"+r+"'",Ht(e),function(t){return Nt(e,t,!0)});return n&&(Oo(t),ge(e),In(e,"keyHandled",e,"'"+r+"'",t)),n}function Wt(e){var t=this;if(ht(t),!Pn(t,e)){yi&&27==e.keyCode&&(e.returnValue=!1);var r=e.keyCode;t.display.shift=16==r||e.shiftKey;var n=At(t,e);Ti&&(eo=n?r:null,!n&&88==r&&!rl&&(Ii?e.metaKey:e.ctrlKey)&&t.replaceSelection("",null,"cut"))}}function Dt(e){Pn(this,e)||16==e.keyCode&&(this.doc.sel.shift=!1)}function Et(e){var t=this;if(!Pn(t,e)){var r=e.keyCode,n=e.charCode;if(Ti&&r==eo)return eo=null,void Oo(e);if(!(Ti&&(!e.which||e.which<10)||Hi)||!At(t,e)){Ot(t,e,String.fromCharCode(null==n?r:n))||(Li&&!xi&&(t.display.inputHasSelection=null),at(t))}}}function It(e){"nocursor"!=e.options.readOnly&&(e.state.focused||(zo(e,"focus",e),e.state.focused=!0,-1==e.display.wrapper.className.search(/\bCodeMirror-focused\b/)&&(e.display.wrapper.className+=" CodeMirror-focused"),e.curOp||(ct(e),Si&&setTimeout(jn(ct,e,!0),0))),st(e),ge(e))}function zt(e){e.state.focused&&(zo(e,"blur",e),e.state.focused=!1,e.display.wrapper.className=e.display.wrapper.className.replace(" CodeMirror-focused","")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150)}function Pt(e,t){function r(){if(null!=i.input.selectionStart){var t=i.input.value="​"+(e.somethingSelected()?i.input.value:"");i.prevInput="​",i.input.selectionStart=1,i.input.selectionEnd=t.length}}function n(){if(i.inputDiv.style.position="relative",i.input.style.cssText=s,xi&&(i.scrollbarV.scrollTop=i.scroller.scrollTop=l),st(e),null!=i.input.selectionStart){Li&&!xi||r(),clearTimeout(Ji);var t=0,n=function(){"​"==i.prevInput&&0==i.input.selectionStart?$e(e,ho.selectAll)(e):t++<10?Ji=setTimeout(n,500):ct(e)};Ji=setTimeout(n,200)}}if(!Pn(e,t,"contextmenu")){var i=e.display;if(!gt(i,t)&&!Rt(e,t)){var o=mt(e,t),l=i.scroller.scrollTop;if(o&&!Ti){e.options.resetSelectionOnContextMenu&&-1==e.doc.sel.contains(o)&&$e(e,le)(e.doc,Y(o),Bo);var s=i.input.style.cssText;if(i.inputDiv.style.position="absolute",i.input.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(t.clientY-5)+"px; left: "+(t.clientX-5)+"px; z-index: 1000; background: "+(Li?"rgba(255, 255, 255, .05)":"transparent")+"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",ft(e),ct(e),e.somethingSelected()||(i.input.value=i.prevInput=" "),Li&&!xi&&r(),Fi){Do(t);var a=function(){Io(window,"mouseup",a),setTimeout(n,20)};Eo(window,"mouseup",a)}else setTimeout(n,50)}}}}function Rt(e,t){return!!Rn(e,"gutterContextMenu")&&wt(e,t,"gutterContextMenu",!1,zo)}function Ft(e,t){if(Ui(e,t.from)<0)return e;if(Ui(e,t.to)<=0)return to(t);var r=e.line+t.text.length-(t.to.line-t.from.line)-1,n=e.ch;return e.line==t.to.line&&(n+=to(t).ch-t.to.ch),Vi(r,n)}function Bt(e,t){for(var r=[],n=0;n<e.sel.ranges.length;n++){var i=e.sel.ranges[n];r.push(new _(Ft(i.anchor,t),Ft(i.head,t)))}return X(r,e.sel.primIndex)}function Gt(e,t,r){return e.line==t.line?Vi(r.line,e.ch-t.ch+r.ch):Vi(r.line+(e.line-t.line),e.ch)}function Vt(e,t,r){for(var n=[],i=Vi(e.first,0),o=i,l=0;l<t.length;l++){var s=t[l],a=Gt(s.from,i,o),u=Gt(to(s),i,o);if(i=s.to,o=u,"around"==r){var c=e.sel.ranges[l],f=Ui(c.head,c.anchor)<0;n[l]=new _(f?u:a,f?a:u)}else n[l]=new _(a,a)}return new K(n,e.sel.primIndex)}function Ut(e,t,r){var n={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){this.canceled=!0}};return r&&(n.update=function(t,r,n,i){t&&(this.from=$(e,t)),r&&(this.to=$(e,r)),n&&(this.text=n),void 0!==i&&(this.origin=i)}),zo(e,"beforeChange",e,n),e.cm&&zo(e.cm,"beforeChange",e.cm,n),n.canceled?null:{from:n.from,to:n.to,text:n.text,origin:n.origin}}function Kt(e,t,r){if(e.cm){if(!e.cm.curOp)return $e(e.cm,Kt)(e,t,r);if(e.cm.state.suppressEdits)return}if(!(Rn(e,"beforeChange")||e.cm&&Rn(e.cm,"beforeChange"))||(t=Ut(e,t,!0))){var n=Bi&&!r&&Lr(e,t.from,t.to);if(n)for(var i=n.length-1;i>=0;--i)_t(e,{from:n[i].from,to:n[i].to,text:i?[""]:t.text});else _t(e,t)}}function _t(e,t){if(1!=t.text.length||""!=t.text[0]||0!=Ui(t.from,t.to)){var r=Bt(e,t);wn(e,t,r,e.cm?e.cm.curOp.id:NaN),jt(e,t,r,xr(e,t));var n=[];sn(e,function(e,r){r||-1!=Kn(n,e.history)||(On(e.history,t),n.push(e.history)),jt(e,t,null,xr(e,t))})}}function Xt(e,t,r){if(!e.cm||!e.cm.state.suppressEdits){for(var n,i=e.history,o=e.sel,l="undo"==t?i.done:i.undone,s="undo"==t?i.undone:i.done,a=0;a<l.length&&(n=l[a],r?!n.ranges||n.equals(e.sel):n.ranges);a++);if(a!=l.length){for(i.lastOrigin=i.lastSelOrigin=null;n=l.pop(),n.ranges;){if(Sn(n,s),r&&!n.equals(e.sel))return void le(e,n,{clearRedo:!1});o=n}var u=[];Sn(o,s),s.push({changes:u,generation:i.generation}),i.generation=n.generation||++i.maxGeneration;for(var c=Rn(e,"beforeChange")||e.cm&&Rn(e.cm,"beforeChange"),a=n.changes.length-1;a>=0;--a){var f=n.changes[a];if(f.origin=t,c&&!Ut(e,f,!1))return void(l.length=0);u.push(yn(e,f));var h=a?Bt(e,f,null):Un(l);jt(e,f,h,Cr(e,f)),e.cm&&rr(e.cm);var d=[];sn(e,function(e,t){t||-1!=Kn(d,e.history)||(On(e.history,f),d.push(e.history)),jt(e,f,null,Cr(e,f))})}}}}function Yt(e,t){e.first+=t,e.sel=new K(_n(e.sel.ranges,function(e){return new _(Vi(e.anchor.line+t,e.anchor.ch),Vi(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm&&et(e.cm,e.first,e.first-t,t)}function jt(e,t,r,n){if(e.cm&&!e.cm.curOp)return $e(e.cm,jt)(e,t,r,n);if(t.to.line<e.first)return void Yt(e,t.text.length-1-(t.to.line-t.from.line));if(!(t.from.line>e.lastLine())){if(t.from.line<e.first){var i=t.text.length-1-(e.first-t.from.line);Yt(e,i),t={from:Vi(e.first,0),to:Vi(t.to.line+i,t.to.ch),text:[Un(t.text)],origin:t.origin}}var o=e.lastLine();t.to.line>o&&(t={from:t.from,to:Vi(o,un(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=cn(e,t.from,t.to),r||(r=Bt(e,t,null)),e.cm?$t(e.cm,t,n):nn(e,t,n),se(e,r,Bo)}}function $t(e,t,r){var n=e.doc,i=e.display,l=t.from,s=t.to,a=!1,u=l.line;e.options.lineWrapping||(u=dn(Dr(un(n,l.line))),n.iter(u,s.line+1,function(e){if(e==i.maxLine)return a=!0,!0})),n.sel.contains(t.from,t.to)>-1&&(e.curOp.cursorActivity=!0),nn(n,t,r,o(e)),e.options.lineWrapping||(n.iter(u,l.line+t.text.length,function(e){var t=f(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,a=!1)}),a&&(e.curOp.updateMaxLine=!0)),n.frontier=Math.min(n.frontier,l.line),me(e,400);var c=t.text.length-(s.line-l.line)-1;l.line!=s.line||1!=t.text.length||rn(e.doc,t)?et(e,l.line,s.line+1,c):tt(e,l.line,"text"),(Rn(e,"change")||Rn(e,"changes"))&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push({from:l,to:s,text:t.text,removed:t.removed,origin:t.origin})}function qt(e,t,r,n,i){if(n||(n=r),Ui(n,r)<0){var o=n;n=r,r=o}"string"==typeof t&&(t=el(t)),Kt(e,{from:r,to:n,text:t,origin:i})}function Zt(e,t){var r=e.display,n=r.sizer.getBoundingClientRect(),i=null;if(t.top+n.top<0?i=!0:t.bottom+n.top>(window.innerHeight||document.documentElement.clientHeight)&&(i=!1),null!=i&&!Wi){var o=Zn("div","​",null,"position: absolute; top: "+(t.top-r.viewOffset-xe(e.display))+"px; height: "+(t.bottom-t.top+Ro)+"px; left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(o),o.scrollIntoView(i),e.display.lineSpace.removeChild(o)}}function Qt(e,t,r,n){for(null==n&&(n=0);;){var i=!1,o=Fe(e,t),l=r&&r!=t?Fe(e,r):o,s=er(e,Math.min(o.left,l.left),Math.min(o.top,l.top)-n,Math.max(o.left,l.left),Math.max(o.bottom,l.bottom)+n),a=e.doc.scrollTop,u=e.doc.scrollLeft;if(null!=s.scrollTop&&(kt(e,s.scrollTop),Math.abs(e.doc.scrollTop-a)>1&&(i=!0)),null!=s.scrollLeft&&(Mt(e,s.scrollLeft),Math.abs(e.doc.scrollLeft-u)>1&&(i=!0)),!i)return o}}function Jt(e,t,r,n,i){var o=er(e,t,r,n,i);null!=o.scrollTop&&kt(e,o.scrollTop),null!=o.scrollLeft&&Mt(e,o.scrollLeft)}function er(e,t,r,n,i){var o=e.display,l=Ke(e.display);r<0&&(r=0);var s=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:o.scroller.scrollTop,a=o.scroller.clientHeight-Ro,u={},c=e.doc.height+we(o),f=r<l,h=i>c-l;if(r<s)u.scrollTop=f?0:r;else if(i>s+a){var d=Math.min(r,(h?c:i)-a);d!=s&&(u.scrollTop=d)}var p=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:o.scroller.scrollLeft,g=o.scroller.clientWidth-Ro;t+=o.gutters.offsetWidth,n+=o.gutters.offsetWidth;var m=o.gutters.offsetWidth,v=t<m+10;return t<p+m||v?(v&&(t=0),u.scrollLeft=Math.max(0,t-10-m)):n>g+p-3&&(u.scrollLeft=n+10-g),u}function tr(e,t,r){null==t&&null==r||nr(e),null!=t&&(e.curOp.scrollLeft=(null==e.curOp.scrollLeft?e.doc.scrollLeft:e.curOp.scrollLeft)+t),null!=r&&(e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+r)}function rr(e){nr(e);var t=e.getCursor(),r=t,n=t;e.options.lineWrapping||(r=t.ch?Vi(t.line,t.ch-1):t,n=Vi(t.line,t.ch+1)),e.curOp.scrollToPos={from:r,to:n,margin:e.options.cursorScrollMargin,isCursor:!0}}function nr(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var r=Be(e,t.from),n=Be(e,t.to),i=er(e,Math.min(r.left,n.left),Math.min(r.top,n.top)-t.margin,Math.max(r.right,n.right),Math.max(r.bottom,n.bottom)+t.margin);e.scrollTo(i.scrollLeft,i.scrollTop)}}function ir(e,t,r,n){var i,o=e.doc;null==r&&(r="add"),"smart"==r&&(e.doc.mode.indent?i=be(e,t):r="prev");var l=e.options.tabSize,s=un(o,t),a=Uo(s.text,null,l);s.stateAfter&&(s.stateAfter=null);var u,c=s.text.match(/^\s*/)[0];if(n||/\S/.test(s.text)){if("smart"==r&&(u=e.doc.mode.indent(i,s.text.slice(c.length),s.text))==Fo){if(!n)return;r="prev"}}else u=0,r="not";"prev"==r?u=t>o.first?Uo(un(o,t-1).text,null,l):0:"add"==r?u=a+e.options.indentUnit:"subtract"==r?u=a-e.options.indentUnit:"number"==typeof r&&(u=a+r),u=Math.max(0,u);var f="",h=0;if(e.options.indentWithTabs)for(var d=Math.floor(u/l);d;--d)h+=l,f+="\t";if(h<u&&(f+=Vn(u-h)),f!=c)qt(e.doc,f,Vi(t,0),Vi(t,c.length),"+input");else for(var d=0;d<o.sel.ranges.length;d++){var p=o.sel.ranges[d];if(p.head.line==t&&p.head.ch<c.length){var h=Vi(t,c.length);re(o,d,new _(h,h));break}}s.stateAfter=null}function or(e,t,r,n){var i=t,o=t,l=e.doc;return"number"==typeof t?o=un(l,j(l,t)):i=dn(t),null==i?null:n(o,i)?(tt(e,i,r),o):null}function lr(e,t){for(var r=e.doc.sel.ranges,n=[],i=0;i<r.length;i++){for(var o=t(r[i]);n.length&&Ui(o.from,Un(n).to)<=0;){var l=n.pop();if(Ui(l.from,o.from)<0){o.from=l.from;break}}n.push(o)}je(e,function(){for(var t=n.length-1;t>=0;t--)qt(e.doc,"",n[t].from,n[t].to,"+delete");rr(e)})}function sr(e,t,r,n,i){function o(){var t=s+r;return t<e.first||t>=e.first+e.size?f=!1:(s=t,c=un(e,t))}function l(e){var t=(i?gi:mi)(c,a,r,!0);if(null==t){if(e||!o())return f=!1;a=i?(r<0?ui:ai)(c):r<0?c.text.length:0}else a=t;return!0}var s=t.line,a=t.ch,u=r,c=un(e,s),f=!0;if("char"==n)l();else if("column"==n)l(!0);else if("word"==n||"group"==n)for(var h=null,d="group"==n,p=!0;!(r<0)||l(!p);p=!1){var g=c.text.charAt(a)||"\n",m=jo(g)?"w":d&&"\n"==g?"n":!d||/\s/.test(g)?null:"p";if(!d||p||m||(m="s"),h&&h!=m){r<0&&(r=1,l());break}if(m&&(h=m),r>0&&!l(!p))break}var v=fe(e,Vi(s,a),u,!0);return f||(v.hitSide=!0),v}function ar(e,t,r,n){var i,o=e.doc,l=t.left;if("page"==n){var s=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight);i=t.top+r*(s-(r<0?1.5:.5)*Ke(e.display))}else"line"==n&&(i=r>0?t.bottom+3:t.top-3);for(;;){var a=Ve(e,l,i);if(!a.outside)break;if(r<0?i<=0:i>=o.height){a.hitSide=!0;break}i+=5*r}return a}function ur(e,t){var r=un(e,t.line).text,n=t.ch,i=t.ch;if(r){(t.xRel<0||i==r.length)&&n?--n:++i;for(var o=r.charAt(n),l=jo(o)?jo:/\s/.test(o)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!jo(e)};n>0&&l(r.charAt(n-1));)--n;for(;i<r.length&&l(r.charAt(i));)++i}return new _(Vi(t.line,n),Vi(t.line,i))}function cr(t,r,n,i){e.defaults[t]=r,n&&(no[t]=i?function(e,t,r){r!=io&&n(e,t,r)}:n)}function fr(e){return"string"==typeof e?po[e]:e}function hr(e,t,r,n,i){if(n&&n.shared)return dr(e,t,r,n,i);if(e.cm&&!e.cm.curOp)return $e(e.cm,hr)(e,t,r,n,i);var o=new bo(e,i),l=Ui(t,r);if(n&&Yn(n,o),l>0||0==l&&!1!==o.clearWhenEmpty)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=Zn("span",[o.replacedWith],"CodeMirror-widget"),n.handleMouseEvents||(o.widgetNode.ignoreEvents=!0),n.insertLeft&&(o.widgetNode.insertLeft=!0)),o.collapsed){if(Wr(e,t.line,t,r,o)||t.line!=r.line&&Wr(e,r.line,t,r,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");Gi=!0}o.addToHistory&&wn(e,{from:t,to:r,origin:"markText"},e.sel,NaN);var s,a=t.line,u=e.cm;if(e.iter(a,r.line+1,function(e){u&&o.collapsed&&!u.options.lineWrapping&&Dr(e)==u.display.maxLine&&(s=!0),o.collapsed&&a!=t.line&&hn(e,0),vr(e,new pr(o,a==t.line?t.ch:null,a==r.line?r.ch:null)),++a}),o.collapsed&&e.iter(t.line,r.line+1,function(t){Pr(e,t)&&hn(t,0)}),o.clearOnEnter&&Eo(o,"beforeCursorEnter",function(){o.clear()}),o.readOnly&&(Bi=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++xo,o.atomic=!0),u){if(s&&(u.curOp.updateMaxLine=!0),o.collapsed)et(u,t.line,r.line+1);else if(o.className||o.title||o.startStyle||o.endStyle)for(var c=t.line;c<=r.line;c++)tt(u,c,"text");o.atomic&&ue(u.doc),In(u,"markerAdded",u,o)}return o}function dr(e,t,r,n,i){n=Yn(n),n.shared=!1;var o=[hr(e,t,r,n,i)],l=o[0],s=n.widgetNode;return sn(e,function(e){s&&(n.widgetNode=s.cloneNode(!0)),o.push(hr(e,$(e,t),$(e,r),n,i));for(var a=0;a<e.linked.length;++a)if(e.linked[a].isParent)return;l=Un(o)}),new wo(o,l)}function pr(e,t,r){this.marker=e,this.from=t,this.to=r}function gr(e,t){if(e)for(var r=0;r<e.length;++r){var n=e[r];if(n.marker==t)return n}}function mr(e,t){for(var r,n=0;n<e.length;++n)e[n]!=t&&(r||(r=[])).push(e[n]);return r}function vr(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}function yr(e,t,r){if(e)for(var n,i=0;i<e.length;++i){var o=e[i],l=o.marker,s=null==o.from||(l.inclusiveLeft?o.from<=t:o.from<t);if(s||o.from==t&&"bookmark"==l.type&&(!r||!o.marker.insertLeft)){var a=null==o.to||(l.inclusiveRight?o.to>=t:o.to>t);(n||(n=[])).push(new pr(l,o.from,a?null:o.to))}}return n}function br(e,t,r){if(e)for(var n,i=0;i<e.length;++i){var o=e[i],l=o.marker,s=null==o.to||(l.inclusiveRight?o.to>=t:o.to>t);if(s||o.from==t&&"bookmark"==l.type&&(!r||o.marker.insertLeft)){var a=null==o.from||(l.inclusiveLeft?o.from<=t:o.from<t);(n||(n=[])).push(new pr(l,a?null:o.from-t,null==o.to?null:o.to-t))}}return n}function xr(e,t){var r=Z(e,t.from.line)&&un(e,t.from.line).markedSpans,n=Z(e,t.to.line)&&un(e,t.to.line).markedSpans;if(!r&&!n)return null;var i=t.from.ch,o=t.to.ch,l=0==Ui(t.from,t.to),s=yr(r,i,l),a=br(n,o,l),u=1==t.text.length,c=Un(t.text).length+(u?i:0);if(s)for(var f=0;f<s.length;++f){var h=s[f];if(null==h.to){var d=gr(a,h.marker);d?u&&(h.to=null==d.to?null:d.to+c):h.to=i}}if(a)for(var f=0;f<a.length;++f){var h=a[f];if(null!=h.to&&(h.to+=c),null==h.from){var d=gr(s,h.marker);d||(h.from=c,u&&(s||(s=[])).push(h))}else h.from+=c,u&&(s||(s=[])).push(h)}s&&(s=wr(s)),a&&a!=s&&(a=wr(a));var p=[s];if(!u){var g,m=t.text.length-2;if(m>0&&s)for(var f=0;f<s.length;++f)null==s[f].to&&(g||(g=[])).push(new pr(s[f].marker,null,null));for(var f=0;f<m;++f)p.push(g);p.push(a)}return p}function wr(e){for(var t=0;t<e.length;++t){var r=e[t];null!=r.from&&r.from==r.to&&!1!==r.marker.clearWhenEmpty&&e.splice(t--,1)}return e.length?e:null}function Cr(e,t){var r=Tn(e,t),n=xr(e,t);if(!r)return n;if(!n)return r;for(var i=0;i<r.length;++i){var o=r[i],l=n[i];if(o&&l)e:for(var s=0;s<l.length;++s){for(var a=l[s],u=0;u<o.length;++u)if(o[u].marker==a.marker)continue e;o.push(a)}else l&&(r[i]=l)}return r}function Lr(e,t,r){var n=null;if(e.iter(t.line,r.line+1,function(e){if(e.markedSpans)for(var t=0;t<e.markedSpans.length;++t){var r=e.markedSpans[t].marker;!r.readOnly||n&&-1!=Kn(n,r)||(n||(n=[])).push(r)}}),!n)return null;for(var i=[{from:t,to:r}],o=0;o<n.length;++o)for(var l=n[o],s=l.find(0),a=0;a<i.length;++a){var u=i[a];if(!(Ui(u.to,s.from)<0||Ui(u.from,s.to)>0)){var c=[a,1],f=Ui(u.from,s.from),h=Ui(u.to,s.to);(f<0||!l.inclusiveLeft&&!f)&&c.push({from:u.from,to:s.from}),(h>0||!l.inclusiveRight&&!h)&&c.push({from:s.to,to:u.to}),i.splice.apply(i,c),a+=c.length-1}}return i}function Sr(e){var t=e.markedSpans;if(t){for(var r=0;r<t.length;++r)t[r].marker.detachLine(e);e.markedSpans=null}}function kr(e,t){if(t){for(var r=0;r<t.length;++r)t[r].marker.attachLine(e);e.markedSpans=t}}function Mr(e){return e.inclusiveLeft?-1:0}function Tr(e){return e.inclusiveRight?1:0}function Nr(e,t){var r=e.lines.length-t.lines.length;if(0!=r)return r;var n=e.find(),i=t.find(),o=Ui(n.from,i.from)||Mr(e)-Mr(t);if(o)return-o;var l=Ui(n.to,i.to)||Tr(e)-Tr(t);return l||t.id-e.id}function Hr(e,t){var r,n=Gi&&e.markedSpans;if(n)for(var i,o=0;o<n.length;++o)i=n[o],i.marker.collapsed&&null==(t?i.from:i.to)&&(!r||Nr(r,i.marker)<0)&&(r=i.marker);return r}function Ar(e){return Hr(e,!0)}function Or(e){return Hr(e,!1)}function Wr(e,t,r,n,i){var o=un(e,t),l=Gi&&o.markedSpans;if(l)for(var s=0;s<l.length;++s){var a=l[s];if(a.marker.collapsed){var u=a.marker.find(0),c=Ui(u.from,r)||Mr(a.marker)-Mr(i),f=Ui(u.to,n)||Tr(a.marker)-Tr(i);if(!(c>=0&&f<=0||c<=0&&f>=0)&&(c<=0&&(Ui(u.to,r)||Tr(a.marker)-Mr(i))>0||c>=0&&(Ui(u.from,n)||Mr(a.marker)-Tr(i))<0))return!0}}}function Dr(e){for(var t;t=Ar(e);)e=t.find(-1,!0).line;return e}function Er(e){for(var t,r;t=Or(e);)e=t.find(1,!0).line,(r||(r=[])).push(e);return r}function Ir(e,t){var r=un(e,t),n=Dr(r);return r==n?t:dn(n)}function zr(e,t){if(t>e.lastLine())return t;var r,n=un(e,t);if(!Pr(e,n))return t;for(;r=Or(n);)n=r.find(1,!0).line;return dn(n)+1}function Pr(e,t){var r=Gi&&t.markedSpans;if(r)for(var n,i=0;i<r.length;++i)if(n=r[i],
n.marker.collapsed){if(null==n.from)return!0;if(!n.marker.widgetNode&&0==n.from&&n.marker.inclusiveLeft&&Rr(e,t,n))return!0}}function Rr(e,t,r){if(null==r.to){var n=r.marker.find(1,!0);return Rr(e,n.line,gr(n.line.markedSpans,r.marker))}if(r.marker.inclusiveRight&&r.to==t.text.length)return!0;for(var i,o=0;o<t.markedSpans.length;++o)if(i=t.markedSpans[o],i.marker.collapsed&&!i.marker.widgetNode&&i.from==r.to&&(null==i.to||i.to!=r.from)&&(i.marker.inclusiveLeft||r.marker.inclusiveRight)&&Rr(e,t,i))return!0}function Fr(e,t,r){gn(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&tr(e,null,r)}function Br(e){return null!=e.height?e.height:(ei(document.body,e.node)||Jn(e.cm.display.measure,Zn("div",[e.node],null,"position: relative")),e.height=e.node.offsetHeight)}function Gr(e,t,r,n){var i=new Co(e,r,n);return i.noHScroll&&(e.display.alignWidgets=!0),or(e,t,"widget",function(t){var r=t.widgets||(t.widgets=[]);if(null==i.insertAt?r.push(i):r.splice(Math.min(r.length-1,Math.max(0,i.insertAt)),0,i),i.line=t,!Pr(e.doc,t)){var n=gn(t)<e.doc.scrollTop;hn(t,t.height+Br(i)),n&&tr(e,null,i.height),e.curOp.forceUpdate=!0}return!0}),i}function Vr(e,t,r,n){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),null!=e.order&&(e.order=null),Sr(e),kr(e,r);var i=n?n(e):1;i!=e.height&&hn(e,i)}function Ur(e){e.parent=null,Sr(e)}function Kr(t,r,n,i,o,l){var s=n.flattenSpans;null==s&&(s=t.options.flattenSpans);var a,u=0,c=null,f=new yo(r,t.options.tabSize);for(""==r&&n.blankLine&&n.blankLine(i);!f.eol();){if(f.pos>t.options.maxHighlightLength?(s=!1,l&&Yr(t,r,i,f.pos),f.pos=r.length,a=null):a=n.token(f,i),t.options.addModeClass){var h=e.innerMode(n,i).mode.name;h&&(a="m-"+(a?h+" "+a:h))}s&&c==a||(u<f.start&&o(f.start,c),u=f.start,c=a),f.start=f.pos}for(;u<f.pos;){var d=Math.min(f.pos,u+5e4);o(d,c),u=d}}function _r(e,t,r,n){var i=[e.state.modeGen];Kr(e,t.text,e.doc.mode,r,function(e,t){i.push(e,t)},n);for(var o=0;o<e.state.overlays.length;++o){var l=e.state.overlays[o],s=1,a=0;Kr(e,t.text,l.mode,!0,function(e,t){for(var r=s;a<e;){var n=i[s];n>e&&i.splice(s,1,e,i[s+1],n),s+=2,a=Math.min(e,n)}if(t)if(l.opaque)i.splice(r,s-r,e,t),s=r+2;else for(;r<s;r+=2){var o=i[r+1];i[r+1]=o?o+" "+t:t}})}return i}function Xr(e,t){return t.styles&&t.styles[0]==e.state.modeGen||(t.styles=_r(e,t,t.stateAfter=be(e,dn(t)))),t.styles}function Yr(e,t,r,n){var i=e.doc.mode,o=new yo(t,e.options.tabSize);for(o.start=o.pos=n||0,""==t&&i.blankLine&&i.blankLine(r);!o.eol()&&o.pos<=e.options.maxHighlightLength;)i.token(o,r),o.start=o.pos}function jr(e,t){if(!e)return null;for(;;){var r=e.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!r)break;e=e.slice(0,r.index)+e.slice(r.index+r[0].length);var n=r[1]?"bgClass":"textClass";null==t[n]?t[n]=r[2]:new RegExp("(?:^|s)"+r[2]+"(?:$|s)").test(t[n])||(t[n]+=" "+r[2])}if(/^\s*$/.test(e))return null;var i=t.cm.options.addModeClass?ko:So;return i[e]||(i[e]=e.replace(/\S+/g,"cm-$&"))}function $r(e,t){var r=Zn("span",null,null,Si?"padding-right: .1px":null),n={pre:Zn("pre",[r]),content:r,col:0,pos:0,cm:e};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var o,l=i?t.rest[i-1]:t.line;n.pos=0,n.addToken=Zr,(Li||Si)&&e.getOption("lineWrapping")&&(n.addToken=Qr(n.addToken)),ii(e.display.measure)&&(o=mn(l))&&(n.addToken=Jr(n.addToken,o)),n.map=[],tn(l,n,Xr(e,l)),0==n.map.length&&n.map.push(0,0,n.content.appendChild(ni(e.display.measure))),0==i?(t.measure.map=n.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(n.map),(t.measure.caches||(t.measure.caches=[])).push({}))}return zo(e,"renderLine",e,t.line,n.pre),n}function qr(e){var t=Zn("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t}function Zr(e,t,r,n,i,o){if(t){var l=e.cm.options.specialChars,s=!1;if(l.test(t))for(var a=document.createDocumentFragment(),u=0;;){l.lastIndex=u;var c=l.exec(t),f=c?c.index-u:t.length-u;if(f){var h=document.createTextNode(t.slice(u,u+f));xi?a.appendChild(Zn("span",[h])):a.appendChild(h),e.map.push(e.pos,e.pos+f,h),e.col+=f,e.pos+=f}if(!c)break;if(u+=f+1,"\t"==c[0]){var d=e.cm.options.tabSize,p=d-e.col%d,h=a.appendChild(Zn("span",Vn(p),"cm-tab"));e.col+=p}else{var h=e.cm.options.specialCharPlaceholder(c[0]);xi?a.appendChild(Zn("span",[h])):a.appendChild(h),e.col+=1}e.map.push(e.pos,e.pos+1,h),e.pos++}else{e.col+=t.length;var a=document.createTextNode(t);e.map.push(e.pos,e.pos+t.length,a),xi&&(s=!0),e.pos+=t.length}if(r||n||i||s){var g=r||"";n&&(g+=n),i&&(g+=i);var m=Zn("span",[a],g);return o&&(m.title=o),e.content.appendChild(m)}e.content.appendChild(a)}}function Qr(e){function t(e){for(var t=" ",r=0;r<e.length-2;++r)t+=r%2?" ":" ";return t+=" "}return function(r,n,i,o,l,s){e(r,n.replace(/ {3,}/g,t),i,o,l,s)}}function Jr(e,t){return function(r,n,i,o,l,s){i=i?i+" cm-force-border":"cm-force-border";for(var a=r.pos,u=a+n.length;;){for(var c=0;c<t.length;c++){var f=t[c];if(f.to>a&&f.from<=a)break}if(f.to>=u)return e(r,n,i,o,l,s);e(r,n.slice(0,f.to-a),i,o,null,s),o=null,n=n.slice(f.to-a),a=f.to}}}function en(e,t,r,n){var i=!n&&r.widgetNode;i&&(e.map.push(e.pos,e.pos+t,i),e.content.appendChild(i)),e.pos+=t}function tn(e,t,r){var n=e.markedSpans,i=e.text,o=0;if(n)for(var l,s,a,u,c,f,h=i.length,d=0,p=1,g="",m=0;;){if(m==d){s=a=u=c="",f=null,m=1/0;for(var v=[],y=0;y<n.length;++y){var b=n[y],x=b.marker;b.from<=d&&(null==b.to||b.to>d)?(null!=b.to&&m>b.to&&(m=b.to,a=""),x.className&&(s+=" "+x.className),x.startStyle&&b.from==d&&(u+=" "+x.startStyle),x.endStyle&&b.to==m&&(a+=" "+x.endStyle),x.title&&!c&&(c=x.title),x.collapsed&&(!f||Nr(f.marker,x)<0)&&(f=b)):b.from>d&&m>b.from&&(m=b.from),"bookmark"==x.type&&b.from==d&&x.widgetNode&&v.push(x)}if(f&&(f.from||0)==d&&(en(t,(null==f.to?h+1:f.to)-d,f.marker,null==f.from),null==f.to))return;if(!f&&v.length)for(var y=0;y<v.length;++y)en(t,0,v[y])}if(d>=h)break;for(var w=Math.min(h,m);;){if(g){var C=d+g.length;if(!f){var L=C>w?g.slice(0,w-d):g;t.addToken(t,L,l?l+s:s,u,d+L.length==m?a:"",c)}if(C>=w){g=g.slice(w-d),d=w;break}d=C,u=""}g=i.slice(o,o=r[p++]),l=jr(r[p++],t)}}else for(var p=1;p<r.length;p+=2)t.addToken(t,i.slice(o,o=r[p]),jr(r[p+1],t))}function rn(e,t){return 0==t.from.ch&&0==t.to.ch&&""==Un(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function nn(e,t,r,n){function i(e){return r?r[e]:null}function o(e,r,i){Vr(e,r,i,n),In(e,"change",e,t)}var l=t.from,s=t.to,a=t.text,u=un(e,l.line),c=un(e,s.line),f=Un(a),h=i(a.length-1),d=s.line-l.line;if(rn(e,t)){for(var p=0,g=[];p<a.length-1;++p)g.push(new Lo(a[p],i(p),n));o(c,c.text,h),d&&e.remove(l.line,d),g.length&&e.insert(l.line,g)}else if(u==c)if(1==a.length)o(u,u.text.slice(0,l.ch)+f+u.text.slice(s.ch),h);else{for(var g=[],p=1;p<a.length-1;++p)g.push(new Lo(a[p],i(p),n));g.push(new Lo(f+u.text.slice(s.ch),h,n)),o(u,u.text.slice(0,l.ch)+a[0],i(0)),e.insert(l.line+1,g)}else if(1==a.length)o(u,u.text.slice(0,l.ch)+a[0]+c.text.slice(s.ch),i(0)),e.remove(l.line+1,d);else{o(u,u.text.slice(0,l.ch)+a[0],i(0)),o(c,f+c.text.slice(s.ch),h);for(var p=1,g=[];p<a.length-1;++p)g.push(new Lo(a[p],i(p),n));d>1&&e.remove(l.line+1,d-1),e.insert(l.line+1,g)}In(e,"change",e,t)}function on(e){this.lines=e,this.parent=null;for(var t=0,r=0;t<e.length;++t)e[t].parent=this,r+=e[t].height;this.height=r}function ln(e){this.children=e;for(var t=0,r=0,n=0;n<e.length;++n){var i=e[n];t+=i.chunkSize(),r+=i.height,i.parent=this}this.size=t,this.height=r,this.parent=null}function sn(e,t,r){function n(e,i,o){if(e.linked)for(var l=0;l<e.linked.length;++l){var s=e.linked[l];if(s.doc!=i){var a=o&&s.sharedHist;r&&!a||(t(s.doc,a),n(s.doc,e,a))}}}n(e,null,!0)}function an(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,l(e),r(e),e.options.lineWrapping||h(e),e.options.mode=t.modeOption,et(e)}function un(e,t){if((t-=e.first)<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var r=e;!r.lines;)for(var n=0;;++n){var i=r.children[n],o=i.chunkSize();if(t<o){r=i;break}t-=o}return r.lines[t]}function cn(e,t,r){var n=[],i=t.line;return e.iter(t.line,r.line+1,function(e){var o=e.text;i==r.line&&(o=o.slice(0,r.ch)),i==t.line&&(o=o.slice(t.ch)),n.push(o),++i}),n}function fn(e,t,r){var n=[];return e.iter(t,r,function(e){n.push(e.text)}),n}function hn(e,t){var r=t-e.height;if(r)for(var n=e;n;n=n.parent)n.height+=r}function dn(e){if(null==e.parent)return null;for(var t=e.parent,r=Kn(t.lines,e),n=t.parent;n;t=n,n=n.parent)for(var i=0;n.children[i]!=t;++i)r+=n.children[i].chunkSize();return r+t.first}function pn(e,t){var r=e.first;e:do{for(var n=0;n<e.children.length;++n){var i=e.children[n],o=i.height;if(t<o){e=i;continue e}t-=o,r+=i.chunkSize()}return r}while(!e.lines);for(var n=0;n<e.lines.length;++n){var l=e.lines[n],s=l.height;if(t<s)break;t-=s}return r+n}function gn(e){e=Dr(e);for(var t=0,r=e.parent,n=0;n<r.lines.length;++n){var i=r.lines[n];if(i==e)break;t+=i.height}for(var o=r.parent;o;r=o,o=r.parent)for(var n=0;n<o.children.length;++n){var l=o.children[n];if(l==r)break;t+=l.height}return t}function mn(e){var t=e.order;return null==t&&(t=e.order=ol(e.text)),t}function vn(e){this.done=[],this.undone=[],this.undoDepth=1/0,this.lastModTime=this.lastSelTime=0,this.lastOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=e||1}function yn(e,t){var r={from:G(t.from),to:to(t),text:cn(e,t.from,t.to)};return kn(e,r,t.from.line,t.to.line+1),sn(e,function(e){kn(e,r,t.from.line,t.to.line+1)},!0),r}function bn(e){for(;e.length;){if(!Un(e).ranges)break;e.pop()}}function xn(e,t){return t?(bn(e.done),Un(e.done)):e.done.length&&!Un(e.done).ranges?Un(e.done):e.done.length>1&&!e.done[e.done.length-2].ranges?(e.done.pop(),Un(e.done)):void 0}function wn(e,t,r,n){var i=e.history;i.undone.length=0;var o,l=+new Date;if((i.lastOp==n||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&e.cm&&i.lastModTime>l-e.cm.options.historyEventDelay||"*"==t.origin.charAt(0)))&&(o=xn(i,i.lastOp==n))){var s=Un(o.changes);0==Ui(t.from,t.to)&&0==Ui(t.from,s.to)?s.to=to(t):o.changes.push(yn(e,t))}else{var a=Un(i.done);for(a&&a.ranges||Sn(e.sel,i.done),o={changes:[yn(e,t)],generation:i.generation},i.done.push(o);i.done.length>i.undoDepth;)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(r),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=l,i.lastOp=n,i.lastOrigin=i.lastSelOrigin=t.origin,s||zo(e,"historyAdded")}function Cn(e,t,r,n){var i=t.charAt(0);return"*"==i||"+"==i&&r.ranges.length==n.ranges.length&&r.somethingSelected()==n.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}function Ln(e,t,r,n){var i=e.history,o=n&&n.origin;r==i.lastOp||o&&i.lastSelOrigin==o&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==o||Cn(e,o,Un(i.done),t))?i.done[i.done.length-1]=t:Sn(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastOp=r,n&&!1!==n.clearRedo&&bn(i.undone)}function Sn(e,t){var r=Un(t);r&&r.ranges&&r.equals(e)||t.push(e)}function kn(e,t,r,n){var i=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,r),Math.min(e.first+e.size,n),function(r){r.markedSpans&&((i||(i=t["spans_"+e.id]={}))[o]=r.markedSpans),++o})}function Mn(e){if(!e)return null;for(var t,r=0;r<e.length;++r)e[r].marker.explicitlyCleared?t||(t=e.slice(0,r)):t&&t.push(e[r]);return t?t.length?t:null:e}function Tn(e,t){var r=t["spans_"+e.id];if(!r)return null;for(var n=0,i=[];n<t.text.length;++n)i.push(Mn(r[n]));return i}function Nn(e,t,r){for(var n=0,i=[];n<e.length;++n){var o=e[n];if(o.ranges)i.push(r?K.prototype.deepCopy.call(o):o);else{var l=o.changes,s=[];i.push({changes:s});for(var a=0;a<l.length;++a){var u,c=l[a];if(s.push({from:c.from,to:c.to,text:c.text}),t)for(var f in c)(u=f.match(/^spans_(\d+)$/))&&Kn(t,Number(u[1]))>-1&&(Un(s)[f]=c[f],delete c[f])}}}return i}function Hn(e,t,r,n){r<e.line?e.line+=n:t<e.line&&(e.line=t,e.ch=0)}function An(e,t,r,n){for(var i=0;i<e.length;++i){var o=e[i],l=!0;if(o.ranges){o.copied||(o=e[i]=o.deepCopy(),o.copied=!0);for(var s=0;s<o.ranges.length;s++)Hn(o.ranges[s].anchor,t,r,n),Hn(o.ranges[s].head,t,r,n)}else{for(var s=0;s<o.changes.length;++s){var a=o.changes[s];if(r<a.from.line)a.from=Vi(a.from.line+n,a.from.ch),a.to=Vi(a.to.line+n,a.to.ch);else if(t<=a.to.line){l=!1;break}}l||(e.splice(0,i+1),i=0)}}}function On(e,t){var r=t.from.line,n=t.to.line,i=t.text.length-(n-r)-1;An(e.done,r,n,i),An(e.undone,r,n,i)}function Wn(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function Dn(e){return e.target||e.srcElement}function En(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),Ii&&e.ctrlKey&&1==t&&(t=3),t}function In(e,t){var r=e._handlers&&e._handlers[t];if(r){var n=Array.prototype.slice.call(arguments,2);Ao||(++Po,Ao=[],setTimeout(zn,0));for(var i=0;i<r.length;++i)Ao.push(function(e){return function(){e.apply(null,n)}}(r[i]))}}function zn(){--Po;var e=Ao;Ao=null;for(var t=0;t<e.length;++t)e[t]()}function Pn(e,t,r){return zo(e,r||t.type,e,t),Wn(t)||t.codemirrorIgnore}function Rn(e,t){var r=e._handlers&&e._handlers[t];return r&&r.length>0}function Fn(e){e.prototype.on=function(e,t){Eo(this,e,t)},e.prototype.off=function(e,t){Io(this,e,t)}}function Bn(){this.id=null}function Gn(e,t,r){for(var n=0,i=0;;){var o=e.indexOf("\t",n);-1==o&&(o=e.length);var l=o-n;if(o==e.length||i+l>=t)return n+Math.min(l,t-i);if(i+=o-n,i+=r-i%r,n=o+1,i>=t)return n}}function Vn(e){for(;Ko.length<=e;)Ko.push(Un(Ko)+" ");return Ko[e]}function Un(e){return e[e.length-1]}function Kn(e,t){for(var r=0;r<e.length;++r)if(e[r]==t)return r;return-1}function _n(e,t){for(var r=[],n=0;n<e.length;n++)r[n]=t(e[n],n);return r}function Xn(e,t){var r;if(Object.create)r=Object.create(e);else{var n=function(){};n.prototype=e,r=new n}return t&&Yn(t,r),r}function Yn(e,t){t||(t={});for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}function jn(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function $n(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function qn(e){return e.charCodeAt(0)>=768&&$o.test(e)}function Zn(e,t,r,n){var i=document.createElement(e);if(r&&(i.className=r),n&&(i.style.cssText=n),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o<t.length;++o)i.appendChild(t[o]);return i}function Qn(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function Jn(e,t){return Qn(e).appendChild(t)}function ei(e,t){if(e.contains)return e.contains(t);for(;t=t.parentNode;)if(t==e)return!0}function ti(){return document.activeElement}function ri(e){if(null!=qo)return qo;var t=Zn("div",null,null,"width: 50px; height: 50px; overflow-x: scroll");return Jn(e,t),t.offsetWidth&&(qo=t.offsetHeight-t.clientHeight),qo||0}function ni(e){if(null==Zo){var t=Zn("span","​");Jn(e,Zn("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(Zo=t.offsetWidth<=1&&t.offsetHeight>2&&!bi)}return Zo?Zn("span","​"):Zn("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px")}function ii(e){if(null!=Qo)return Qo;var t=Jn(e,document.createTextNode("AخA")),r=Xo(t,0,1).getBoundingClientRect();if(r.left==r.right)return!1;var n=Xo(t,1,2).getBoundingClientRect();return Qo=n.right-r.right<3}function oi(e,t,r,n){if(!e)return n(t,r,"ltr");for(var i=!1,o=0;o<e.length;++o){var l=e[o];(l.from<r&&l.to>t||t==r&&l.to==t)&&(n(Math.max(l.from,t),Math.min(l.to,r),1==l.level?"rtl":"ltr"),i=!0)}i||n(t,r,"ltr")}function li(e){return e.level%2?e.to:e.from}function si(e){return e.level%2?e.from:e.to}function ai(e){var t=mn(e);return t?li(t[0]):0}function ui(e){var t=mn(e);return t?si(Un(t)):e.text.length}function ci(e,t){var r=un(e.doc,t),n=Dr(r);n!=r&&(t=dn(n));var i=mn(n),o=i?i[0].level%2?ui(n):ai(n):0;return Vi(t,o)}function fi(e,t){for(var r,n=un(e.doc,t);r=Or(n);)n=r.find(1,!0).line,t=null;var i=mn(n),o=i?i[0].level%2?ai(n):ui(n):n.text.length;return Vi(null==t?dn(n):t,o)}function hi(e,t,r){var n=e[0].level;return t==n||r!=n&&t<r}function di(e,t){il=null;for(var r,n=0;n<e.length;++n){var i=e[n];if(i.from<t&&i.to>t)return n;if(i.from==t||i.to==t){if(null!=r)return hi(e,i.level,e[r].level)?(i.from!=i.to&&(il=r),n):(i.from!=i.to&&(il=n),r);r=n}}return r}function pi(e,t,r,n){if(!n)return t+r;do{t+=r}while(t>0&&qn(e.text.charAt(t)));return t}function gi(e,t,r,n){var i=mn(e);if(!i)return mi(e,t,r,n);for(var o=di(i,t),l=i[o],s=pi(e,t,l.level%2?-r:r,n);;){if(s>l.from&&s<l.to)return s;if(s==l.from||s==l.to)return di(i,s)==o?s:(l=i[o+=r],r>0==l.level%2?l.to:l.from);if(!(l=i[o+=r]))return null;s=r>0==l.level%2?pi(e,l.to,-1,n):pi(e,l.from,1,n)}}function mi(e,t,r,n){var i=t+r;if(n)for(;i>0&&qn(e.text.charAt(i));)i+=r;return i<0||i>e.text.length?null:i}var vi=/gecko\/\d/i.test(navigator.userAgent),yi=/MSIE \d/.test(navigator.userAgent),bi=yi&&(null==document.documentMode||document.documentMode<8),xi=yi&&(null==document.documentMode||document.documentMode<9),wi=yi&&(null==document.documentMode||document.documentMode<10),Ci=/Trident\/([7-9]|\d{2,})\./.test(navigator.userAgent),Li=yi||Ci,Si=/WebKit\//.test(navigator.userAgent),ki=Si&&/Qt\/\d+\.\d+/.test(navigator.userAgent),Mi=/Chrome\//.test(navigator.userAgent),Ti=/Opera\//.test(navigator.userAgent),Ni=/Apple Computer/.test(navigator.vendor),Hi=/KHTML\//.test(navigator.userAgent),Ai=/Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent),Oi=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),Wi=/PhantomJS/.test(navigator.userAgent),Di=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),Ei=Di||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),Ii=Di||/Mac/.test(navigator.platform),zi=/win/i.test(navigator.platform),Pi=Ti&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);Pi&&(Pi=Number(Pi[1])),Pi&&Pi>=15&&(Ti=!1,Si=!0);var Ri=Ii&&(ki||Ti&&(null==Pi||Pi<12.11)),Fi=vi||Li&&!xi,Bi=!1,Gi=!1,Vi=e.Pos=function(e,t){if(!(this instanceof Vi))return new Vi(e,t);this.line=e,this.ch=t},Ui=e.cmpPos=function(e,t){return e.line-t.line||e.ch-t.ch};K.prototype={primary:function(){return this.ranges[this.primIndex]},equals:function(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(var t=0;t<this.ranges.length;t++){var r=this.ranges[t],n=e.ranges[t];if(0!=Ui(r.anchor,n.anchor)||0!=Ui(r.head,n.head))return!1}return!0},deepCopy:function(){for(var e=[],t=0;t<this.ranges.length;t++)e[t]=new _(G(this.ranges[t].anchor),G(this.ranges[t].head));return new K(e,this.primIndex)},somethingSelected:function(){for(var e=0;e<this.ranges.length;e++)if(!this.ranges[e].empty())return!0;return!1},contains:function(e,t){t||(t=e);for(var r=0;r<this.ranges.length;r++){var n=this.ranges[r];if(Ui(t,n.from())>=0&&Ui(e,n.to())<=0)return r}return-1}},_.prototype={from:function(){return U(this.anchor,this.head)},to:function(){return V(this.anchor,this.head)},empty:function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch}};var Ki,_i,Xi,Yi={left:0,right:0,top:0,bottom:0},ji=0,$i=0,qi=0,Zi=null;Li?Zi=-.53:vi?Zi=15:Mi?Zi=-.7:Ni&&(Zi=-1/3);var Qi,Ji,eo=null,to=e.changeEnd=function(e){return e.text?Vi(e.from.line+e.text.length-1,Un(e.text).length+(1==e.text.length?e.from.ch:0)):e.to};e.prototype={constructor:e,posFromMouse:function(e){return mt(this,e,!0)},focus:function(){window.focus(),ft(this),at(this)},setOption:function(e,t){var r=this.options,n=r[e];r[e]==t&&"mode"!=e||(r[e]=t,no.hasOwnProperty(e)&&$e(this,no[e])(this,t,n))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](e)},removeKeyMap:function(e){for(var t=this.state.keyMaps,r=0;r<t.length;++r)if(t[r]==e||"string"!=typeof t[r]&&t[r].name==e)return t.splice(r,1),!0},addOverlay:qe(function(t,r){var n=t.token?t:e.getMode(this.options,t);if(n.startState)throw new Error("Overlays may not be stateful.");this.state.overlays.push({mode:n,modeSpec:t,opaque:r&&r.opaque}),this.state.modeGen++,et(this)}),removeOverlay:qe(function(e){for(var t=this.state.overlays,r=0;r<t.length;++r){var n=t[r].modeSpec;if(n==e||"string"==typeof e&&n.name==e)return t.splice(r,1),this.state.modeGen++,void et(this)}}),indentLine:qe(function(e,t,r){"string"!=typeof t&&"number"!=typeof t&&(t=null==t?this.options.smartIndent?"smart":"prev":t?"add":"subtract"),Z(this.doc,e)&&ir(this,e,t,r)}),indentSelection:qe(function(e){for(var t=this.doc.sel.ranges,r=-1,n=0;n<t.length;n++){var i=t[n];if(i.empty())i.head.line>r&&(ir(this,i.head.line,e,!0),r=i.head.line,n==this.doc.sel.primIndex&&rr(this));else{var o=Math.max(r,i.from().line),l=i.to();r=Math.min(this.lastLine(),l.line-(l.ch?0:1))+1;for(var s=o;s<r;++s)ir(this,s,e)}}}),getTokenAt:function(e,t){var r=this.doc;e=$(r,e);for(var n=be(this,e.line,t),i=this.doc.mode,o=un(r,e.line),l=new yo(o.text,this.options.tabSize);l.pos<e.ch&&!l.eol();){l.start=l.pos;var s=i.token(l,n)}return{start:l.start,end:l.pos,string:l.current(),type:s||null,state:n}},getTokenTypeAt:function(e){e=$(this.doc,e);var t=Xr(this,un(this.doc,e.line)),r=0,n=(t.length-1)/2,i=e.ch;if(0==i)return t[2];for(;;){var o=r+n>>1;if((o?t[2*o-1]:0)>=i)n=o;else{if(!(t[2*o+1]<i))return t[2*o+2];r=o+1}}},getModeAt:function(t){var r=this.doc.mode;return r.innerMode?e.innerMode(r,this.getTokenAt(t).state).mode:r},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var r=[];if(!uo.hasOwnProperty(t))return uo;var n=uo[t],i=this.getModeAt(e);if("string"==typeof i[t])n[i[t]]&&r.push(n[i[t]]);else if(i[t])for(var o=0;o<i[t].length;o++){var l=n[i[t][o]];l&&r.push(l)}else i.helperType&&n[i.helperType]?r.push(n[i.helperType]):n[i.name]&&r.push(n[i.name]);for(var o=0;o<n._global.length;o++){var s=n._global[o];s.pred(i,this)&&-1==Kn(r,s.val)&&r.push(s.val)}return r},getStateAfter:function(e,t){var r=this.doc;return e=j(r,null==e?r.first+r.size-1:e),be(this,e+1,t)},cursorCoords:function(e,t){var r,n=this.doc.sel.primary();return r=null==e?n.head:"object"==typeof e?$(this.doc,e):e?n.from():n.to(),Fe(this,r,t||"page")},charCoords:function(e,t){return Re(this,$(this.doc,e),t||"page")},coordsChar:function(e,t){return e=Pe(this,e,t||"page"),Ve(this,e.left,e.top)},lineAtHeight:function(e,t){return e=Pe(this,{top:e,left:0},t||"page").top,pn(this.doc,e+this.display.viewOffset)},heightAtLine:function(e,t){var r=!1,n=this.doc.first+this.doc.size-1;e<this.doc.first?e=this.doc.first:e>n&&(e=n,r=!0);var i=un(this.doc,e);return ze(this,i,{top:0,left:0},t||"page").top+(r?this.doc.height-gn(i):0)},defaultTextHeight:function(){return Ke(this.display)},defaultCharWidth:function(){return _e(this.display)},setGutterMarker:qe(function(e,t,r){return or(this,e,"gutter",function(e){var n=e.gutterMarkers||(e.gutterMarkers={});return n[t]=r,!r&&$n(n)&&(e.gutterMarkers=null),!0})}),clearGutter:qe(function(e){var t=this,r=t.doc,n=r.first;r.iter(function(r){r.gutterMarkers&&r.gutterMarkers[e]&&(r.gutterMarkers[e]=null,tt(t,n,"gutter"),$n(r.gutterMarkers)&&(r.gutterMarkers=null)),++n})}),addLineClass:qe(function(e,t,r){return or(this,e,"class",function(e){var n="text"==t?"textClass":"background"==t?"bgClass":"wrapClass";if(e[n]){if(new RegExp("(?:^|\\s)"+r+"(?:$|\\s)").test(e[n]))return!1;e[n]+=" "+r}else e[n]=r;return!0})}),removeLineClass:qe(function(e,t,r){return or(this,e,"class",function(e){var n="text"==t?"textClass":"background"==t?"bgClass":"wrapClass",i=e[n];if(!i)return!1;if(null==r)e[n]=null;else{var o=i.match(new RegExp("(?:^|\\s+)"+r+"(?:$|\\s+)"));if(!o)return!1;var l=o.index+o[0].length;e[n]=i.slice(0,o.index)+(o.index&&l!=i.length?" ":"")+i.slice(l)||null}return!0})}),addLineWidget:qe(function(e,t,r){return Gr(this,e,t,r)}),removeLineWidget:function(e){e.clear()},lineInfo:function(e){if("number"==typeof e){if(!Z(this.doc,e))return null;var t=e;if(!(e=un(this.doc,e)))return null}else{var t=dn(e);if(null==t)return null}return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,r,n,i){var o=this.display;e=Fe(this,$(this.doc,e));var l=e.bottom,s=e.left;if(t.style.position="absolute",o.sizer.appendChild(t),"over"==n)l=e.top;else if("above"==n||"near"==n){var a=Math.max(o.wrapper.clientHeight,this.doc.height),u=Math.max(o.sizer.clientWidth,o.lineSpace.clientWidth);("above"==n||e.bottom+t.offsetHeight>a)&&e.top>t.offsetHeight?l=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=a&&(l=e.bottom),s+t.offsetWidth>u&&(s=u-t.offsetWidth)}t.style.top=l+"px",t.style.left=t.style.right="","right"==i?(s=o.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?s=0:"middle"==i&&(s=(o.sizer.clientWidth-t.offsetWidth)/2),t.style.left=s+"px"),r&&Jt(this,s,l,s+t.offsetWidth,l+t.offsetHeight)},triggerOnKeyDown:qe(Wt),triggerOnKeyPress:qe(Et),triggerOnKeyUp:qe(Dt),execCommand:function(e){if(ho.hasOwnProperty(e))return ho[e](this)},findPosH:function(e,t,r,n){var i=1;t<0&&(i=-1,t=-t);for(var o=0,l=$(this.doc,e);o<t&&(l=sr(this.doc,l,i,r,n),!l.hitSide);++o);return l},moveH:qe(function(e,t){var r=this;r.extendSelectionsBy(function(n){return r.display.shift||r.doc.extend||n.empty()?sr(r.doc,n.head,e,t,r.options.rtlMoveVisually):e<0?n.from():n.to()},Vo)}),deleteH:qe(function(e,t){var r=this.doc.sel,n=this.doc;r.somethingSelected()?n.replaceSelection("",null,"+delete"):lr(this,function(r){var i=sr(n,r.head,e,t,!1);return e<0?{from:i,to:r.head}:{from:r.head,to:i}})}),findPosV:function(e,t,r,n){var i=1,o=n;t<0&&(i=-1,t=-t);for(var l=0,s=$(this.doc,e);l<t;++l){var a=Fe(this,s,"div");if(null==o?o=a.left:a.left=o,s=ar(this,a,i,r),s.hitSide)break}return s},moveV:qe(function(e,t){var r=this,n=this.doc,i=[],o=!r.display.shift&&!n.extend&&n.sel.somethingSelected();if(n.extendSelectionsBy(function(l){if(o)return e<0?l.from():l.to();var s=Fe(r,l.head,"div");null!=l.goalColumn&&(s.left=l.goalColumn),i.push(s.left);var a=ar(r,s,e,t);return"page"==t&&l==n.sel.primary()&&tr(r,null,Re(r,a,"div").top-s.top),a},Vo),i.length)for(var l=0;l<n.sel.ranges.length;l++)n.sel.ranges[l].goalColumn=i[l]}),toggleOverwrite:function(e){null!=e&&e==this.state.overwrite||((this.state.overwrite=!this.state.overwrite)?this.display.cursorDiv.className+=" CodeMirror-overwrite":this.display.cursorDiv.className=this.display.cursorDiv.className.replace(" CodeMirror-overwrite",""),zo(this,"overwriteToggle",this,this.state.overwrite))},hasFocus:function(){return ti()==this.display.input},scrollTo:qe(function(e,t){null==e&&null==t||nr(this),null!=e&&(this.curOp.scrollLeft=e),null!=t&&(this.curOp.scrollTop=t)}),getScrollInfo:function(){var e=this.display.scroller,t=Ro;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-t,width:e.scrollWidth-t,clientHeight:e.clientHeight-t,clientWidth:e.clientWidth-t}},scrollIntoView:qe(function(e,t){if(null==e?(e={from:this.doc.sel.primary().head,to:null},null==t&&(t=this.options.cursorScrollMargin)):"number"==typeof e?e={from:Vi(e,0),to:null}:null==e.from&&(e={from:e,to:null}),e.to||(e.to=e.from),e.margin=t||0,null!=e.from.line)nr(this),this.curOp.scrollToPos=e;else{var r=er(this,Math.min(e.from.left,e.to.left),Math.min(e.from.top,e.to.top)-e.margin,Math.max(e.from.right,e.to.right),Math.max(e.from.bottom,e.to.bottom)+e.margin);this.scrollTo(r.scrollLeft,r.scrollTop)}}),setSize:qe(function(e,t){function r(e){return"number"==typeof e||/^\d+$/.test(String(e))?e+"px":e}null!=e&&(this.display.wrapper.style.width=r(e)),null!=t&&(this.display.wrapper.style.height=r(t)),this.options.lineWrapping&&We(this),this.curOp.forceUpdate=!0,zo(this,"refresh",this)}),operation:function(e){return je(this,e)},refresh:qe(function(){var e=this.display.cachedTextHeight;et(this),De(this),this.scrollTo(this.doc.scrollLeft,this.doc.scrollTop),(null==e||Math.abs(e-Ke(this.display))>.5)&&l(this),zo(this,"refresh",this)}),swapDoc:qe(function(e){var t=this.doc;return t.cm=null,an(this,e),De(this),ct(this),this.scrollTo(e.scrollLeft,e.scrollTop),In(this,"swapDoc",this,t),t}),getInputField:function(){return this.display.input},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},Fn(e);var ro=e.defaults={},no=e.optionHandlers={},io=e.Init={toString:function(){return"CodeMirror.Init"}};cr("value","",function(e,t){e.setValue(t)},!0),cr("mode",null,function(e,t){e.doc.modeOption=t,r(e)},!0),cr("indentUnit",2,r,!0),cr("indentWithTabs",!1),cr("smartIndent",!0),cr("tabSize",4,function(e){n(e),De(e),et(e)},!0),cr("specialChars",/[\t\u0000-\u0019\u00ad\u200b\u2028\u2029\ufeff]/g,function(e,t){e.options.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),e.refresh()},!0),cr("specialCharPlaceholder",qr,function(e){e.refresh()},!0),cr("electricChars",!0),cr("rtlMoveVisually",!zi),cr("wholeLineUpdateBefore",!0),cr("theme","default",function(e){a(e),u(e)},!0),cr("keyMap","default",s),cr("extraKeys",null),cr("lineWrapping",!1,i,!0),cr("gutters",[],function(e){d(e.options),u(e)},!0),cr("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?x(e.display)+"px":"0",e.refresh()},!0),cr("coverGutterNextToScrollbar",!1,g,!0),cr("lineNumbers",!1,function(e){d(e.options),u(e)},!0),cr("firstLineNumber",1,u,!0),cr("lineNumberFormatter",function(e){return e},u,!0),cr("showCursorWhenSelecting",!1,he,!0),cr("resetSelectionOnContextMenu",!0),cr("readOnly",!1,function(e,t){"nocursor"==t?(zt(e),e.display.input.blur(),e.display.disabled=!0):(e.display.disabled=!1,t||ct(e))}),cr("disableInput",!1,function(e,t){t||ct(e)},!0),cr("dragDrop",!0),cr("cursorBlinkRate",530),cr("cursorScrollMargin",0),cr("cursorHeight",1),cr("workTime",100),cr("workDelay",100),cr("flattenSpans",!0,n,!0),cr("addModeClass",!1,n,!0),cr("pollInterval",100),cr("undoDepth",200,function(e,t){e.doc.history.undoDepth=t}),cr("historyEventDelay",1250),cr("viewportMargin",10,function(e){e.refresh()},!0),cr("maxHighlightLength",1e4,n,!0),cr("moveInputWithCursor",!0,function(e,t){t||(e.display.inputDiv.style.top=e.display.inputDiv.style.left=0)}),cr("tabindex",null,function(e,t){e.display.input.tabIndex=t||""}),cr("autofocus",null);var oo=e.modes={},lo=e.mimeModes={};e.defineMode=function(t,r){if(e.defaults.mode||"null"==t||(e.defaults.mode=t),arguments.length>2){r.dependencies=[];for(var n=2;n<arguments.length;++n)r.dependencies.push(arguments[n])}oo[t]=r},e.defineMIME=function(e,t){lo[e]=t},e.resolveMode=function(t){if("string"==typeof t&&lo.hasOwnProperty(t))t=lo[t];else if(t&&"string"==typeof t.name&&lo.hasOwnProperty(t.name)){var r=lo[t.name];"string"==typeof r&&(r={name:r}),t=Xn(r,t),t.name=r.name}else if("string"==typeof t&&/^[\w\-]+\/[\w\-]+\+xml$/.test(t))return e.resolveMode("application/xml");return"string"==typeof t?{name:t}:t||{name:"null"}},e.getMode=function(t,r){var r=e.resolveMode(r),n=oo[r.name];if(!n)return e.getMode(t,"text/plain");var i=n(t,r);if(so.hasOwnProperty(r.name)){var o=so[r.name];for(var l in o)o.hasOwnProperty(l)&&(i.hasOwnProperty(l)&&(i["_"+l]=i[l]),i[l]=o[l])}if(i.name=r.name,r.helperType&&(i.helperType=r.helperType),r.modeProps)for(var l in r.modeProps)i[l]=r.modeProps[l];return i},e.defineMode("null",function(){return{token:function(e){e.skipToEnd()}}}),e.defineMIME("text/plain","null");var so=e.modeExtensions={};e.extendMode=function(e,t){Yn(t,so.hasOwnProperty(e)?so[e]:so[e]={})},e.defineExtension=function(t,r){e.prototype[t]=r},e.defineDocExtension=function(e,t){To.prototype[e]=t},e.defineOption=cr;var ao=[];e.defineInitHook=function(e){ao.push(e)};var uo=e.helpers={};e.registerHelper=function(t,r,n){uo.hasOwnProperty(t)||(uo[t]=e[t]={_global:[]}),uo[t][r]=n},e.registerGlobalHelper=function(t,r,n,i){e.registerHelper(t,r,i),uo[t]._global.push({pred:n,val:i})};var co=e.copyState=function(e,t){if(!0===t)return t;if(e.copyState)return e.copyState(t);var r={};for(var n in t){var i=t[n];i instanceof Array&&(i=i.concat([])),r[n]=i}return r},fo=e.startState=function(e,t,r){return!e.startState||e.startState(t,r)}
;e.innerMode=function(e,t){for(;e.innerMode;){var r=e.innerMode(t);if(!r||r.mode==e)break;t=r.state,e=r.mode}return r||{mode:e,state:t}};var ho=e.commands={selectAll:function(e){e.setSelection(Vi(e.firstLine(),0),Vi(e.lastLine()),Bo)},singleSelection:function(e){e.setSelection(e.getCursor("anchor"),e.getCursor("head"),Bo)},killLine:function(e){lr(e,function(t){if(t.empty()){var r=un(e.doc,t.head.line).text.length;return t.head.ch==r&&t.head.line<e.lastLine()?{from:t.head,to:Vi(t.head.line+1,0)}:{from:t.head,to:Vi(t.head.line,r)}}return{from:t.from(),to:t.to()}})},deleteLine:function(e){lr(e,function(t){return{from:Vi(t.from().line,0),to:$(e.doc,Vi(t.to().line+1,0))}})},delLineLeft:function(e){lr(e,function(e){return{from:Vi(e.from().line,0),to:e.from()}})},undo:function(e){e.undo()},redo:function(e){e.redo()},undoSelection:function(e){e.undoSelection()},redoSelection:function(e){e.redoSelection()},goDocStart:function(e){e.extendSelection(Vi(e.firstLine(),0))},goDocEnd:function(e){e.extendSelection(Vi(e.lastLine()))},goLineStart:function(e){e.extendSelectionsBy(function(t){return ci(e,t.head.line)},Vo)},goLineStartSmart:function(e){e.extendSelectionsBy(function(t){var r=ci(e,t.head.line),n=e.getLineHandle(r.line),i=mn(n);if(!i||0==i[0].level){var o=Math.max(0,n.text.search(/\S/)),l=t.head.line==r.line&&t.head.ch<=o&&t.head.ch;return Vi(r.line,l?0:o)}return r},Vo)},goLineEnd:function(e){e.extendSelectionsBy(function(t){return fi(e,t.head.line)},Vo)},goLineRight:function(e){e.extendSelectionsBy(function(t){var r=e.charCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:r},"div")},Vo)},goLineLeft:function(e){e.extendSelectionsBy(function(t){var r=e.charCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:r},"div")},Vo)},goLineUp:function(e){e.moveV(-1,"line")},goLineDown:function(e){e.moveV(1,"line")},goPageUp:function(e){e.moveV(-1,"page")},goPageDown:function(e){e.moveV(1,"page")},goCharLeft:function(e){e.moveH(-1,"char")},goCharRight:function(e){e.moveH(1,"char")},goColumnLeft:function(e){e.moveH(-1,"column")},goColumnRight:function(e){e.moveH(1,"column")},goWordLeft:function(e){e.moveH(-1,"word")},goGroupRight:function(e){e.moveH(1,"group")},goGroupLeft:function(e){e.moveH(-1,"group")},goWordRight:function(e){e.moveH(1,"word")},delCharBefore:function(e){e.deleteH(-1,"char")},delCharAfter:function(e){e.deleteH(1,"char")},delWordBefore:function(e){e.deleteH(-1,"word")},delWordAfter:function(e){e.deleteH(1,"word")},delGroupBefore:function(e){e.deleteH(-1,"group")},delGroupAfter:function(e){e.deleteH(1,"group")},indentAuto:function(e){e.indentSelection("smart")},indentMore:function(e){e.indentSelection("add")},indentLess:function(e){e.indentSelection("subtract")},insertTab:function(e){e.replaceSelection("\t")},defaultTab:function(e){e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:function(e){je(e,function(){for(var t=e.listSelections(),r=0;r<t.length;r++){var n=t[r].head,i=un(e.doc,n.line).text;n.ch>0&&n.ch<i.length-1&&e.replaceRange(i.charAt(n.ch)+i.charAt(n.ch-1),Vi(n.line,n.ch-1),Vi(n.line,n.ch+1))}})},newlineAndIndent:function(e){je(e,function(){for(var t=e.listSelections().length,r=0;r<t;r++){var n=e.listSelections()[r];e.replaceRange("\n",n.anchor,n.head,"+input"),e.indentLine(n.from().line+1,null,!0),rr(e)}})},toggleOverwrite:function(e){e.toggleOverwrite()}},po=e.keyMap={};po.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},po.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-Up":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Down":"goDocEnd","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},po.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineStart","Cmd-Right":"goLineEnd","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delLineLeft","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection",fallthrough:["basic","emacsy"]},po.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars"},po.default=Ii?po.macDefault:po.pcDefault;var go=e.lookupKey=function(e,t,r){function n(t){t=fr(t);var i=t[e];if(!1===i)return"stop";if(null!=i&&r(i))return!0;if(t.nofallthrough)return"stop";var o=t.fallthrough;if(null==o)return!1;if("[object Array]"!=Object.prototype.toString.call(o))return n(o);for(var l=0;l<o.length;++l){var s=n(o[l]);if(s)return s}return!1}for(var i=0;i<t.length;++i){var o=n(t[i]);if(o)return"stop"!=o}},mo=e.isModifierKey=function(e){var t=nl[e.keyCode];return"Ctrl"==t||"Alt"==t||"Shift"==t||"Mod"==t},vo=e.keyName=function(e,t){if(Ti&&34==e.keyCode&&e.char)return!1;var r=nl[e.keyCode];return null!=r&&!e.altGraphKey&&(e.altKey&&(r="Alt-"+r),(Ri?e.metaKey:e.ctrlKey)&&(r="Ctrl-"+r),(Ri?e.ctrlKey:e.metaKey)&&(r="Cmd-"+r),!t&&e.shiftKey&&(r="Shift-"+r),r)};e.fromTextArea=function(t,r){function n(){t.value=a.getValue()}if(r||(r={}),r.value=t.value,!r.tabindex&&t.tabindex&&(r.tabindex=t.tabindex),!r.placeholder&&t.placeholder&&(r.placeholder=t.placeholder),null==r.autofocus){var i=ti();r.autofocus=i==t||null!=t.getAttribute("autofocus")&&i==document.body}if(t.form&&(Eo(t.form,"submit",n),!r.leaveSubmitMethodAlone)){var o=t.form,l=o.submit;try{var s=o.submit=function(){n(),o.submit=l,o.submit(),o.submit=s}}catch(e){}}t.style.display="none";var a=e(function(e){t.parentNode.insertBefore(e,t.nextSibling)},r);return a.save=n,a.getTextArea=function(){return t},a.toTextArea=function(){n(),t.parentNode.removeChild(a.getWrapperElement()),t.style.display="",t.form&&(Io(t.form,"submit",n),"function"==typeof t.form.submit&&(t.form.submit=l))},a};var yo=e.StringStream=function(e,t){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0};yo.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return this.pos==this.lineStart},peek:function(){return this.string.charAt(this.pos)||void 0},next:function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},eat:function(e){var t=this.string.charAt(this.pos);if("string"==typeof e)var r=t==e;else var r=t&&(e.test?e.test(t):e(t));if(r)return++this.pos,t},eatWhile:function(e){for(var t=this.pos;this.eat(e););return this.pos>t},eatSpace:function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},skipToEnd:function(){this.pos=this.string.length},skipTo:function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},backUp:function(e){this.pos-=e},column:function(){return this.lastColumnPos<this.start&&(this.lastColumnValue=Uo(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?Uo(this.string,this.lineStart,this.tabSize):0)},indentation:function(){return Uo(this.string,null,this.tabSize)-(this.lineStart?Uo(this.string,this.lineStart,this.tabSize):0)},match:function(e,t,r){if("string"!=typeof e){var n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&!1!==t&&(this.pos+=n[0].length),n)}var i=function(e){return r?e.toLowerCase():e};if(i(this.string.substr(this.pos,e.length))==i(e))return!1!==t&&(this.pos+=e.length),!0},current:function(){return this.string.slice(this.start,this.pos)},hideFirstChars:function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}}};var bo=e.TextMarker=function(e,t){this.lines=[],this.type=t,this.doc=e};Fn(bo),bo.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&Xe(e),Rn(this,"clear")){var r=this.find();r&&In(this,"clear",r.from,r.to)}for(var n=null,i=null,o=0;o<this.lines.length;++o){var l=this.lines[o],s=gr(l.markedSpans,this);e&&!this.collapsed?tt(e,dn(l),"text"):e&&(null!=s.to&&(i=dn(l)),null!=s.from&&(n=dn(l))),l.markedSpans=mr(l.markedSpans,s),null==s.from&&this.collapsed&&!Pr(this.doc,l)&&e&&hn(l,Ke(e.display))}if(e&&this.collapsed&&!e.options.lineWrapping)for(var o=0;o<this.lines.length;++o){var a=Dr(this.lines[o]),u=f(a);u>e.display.maxLineLength&&(e.display.maxLine=a,e.display.maxLineLength=u,e.display.maxLineChanged=!0)}null!=n&&e&&this.collapsed&&et(e,n,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&ue(e.doc)),e&&In(e,"markerCleared",e,this),t&&Ye(e)}},bo.prototype.find=function(e,t){null==e&&"bookmark"==this.type&&(e=1);for(var r,n,i=0;i<this.lines.length;++i){var o=this.lines[i],l=gr(o.markedSpans,this);if(null!=l.from&&(r=Vi(t?o:dn(o),l.from),-1==e))return r;if(null!=l.to&&(n=Vi(t?o:dn(o),l.to),1==e))return n}return r&&{from:r,to:n}},bo.prototype.changed=function(){var e=this.find(-1,!0),t=this,r=this.doc.cm;e&&r&&je(r,function(){var n=e.line,i=dn(e.line),o=Te(r,i);if(o&&(Oe(o),r.curOp.selectionChanged=r.curOp.forceUpdate=!0),r.curOp.updateMaxLine=!0,!Pr(t.doc,n)&&null!=t.height){var l=t.height;t.height=null;var s=Br(t)-l;s&&hn(n,n.height+s)}})},bo.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;t.maybeHiddenMarkers&&-1!=Kn(t.maybeHiddenMarkers,this)||(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)},bo.prototype.detachLine=function(e){if(this.lines.splice(Kn(this.lines,e),1),!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}};var xo=0,wo=e.SharedTextMarker=function(e,t){this.markers=e,this.primary=t;for(var r=0,n=this;r<e.length;++r)e[r].parent=this,Eo(e[r],"clear",function(){n.clear()})};Fn(wo),wo.prototype.clear=function(){if(!this.explicitlyCleared){this.explicitlyCleared=!0;for(var e=0;e<this.markers.length;++e)this.markers[e].clear();In(this,"clear")}},wo.prototype.find=function(e,t){return this.primary.find(e,t)};var Co=e.LineWidget=function(e,t,r){if(r)for(var n in r)r.hasOwnProperty(n)&&(this[n]=r[n]);this.cm=e,this.node=t};Fn(Co),Co.prototype.clear=function(){var e=this.cm,t=this.line.widgets,r=this.line,n=dn(r);if(null!=n&&t){for(var i=0;i<t.length;++i)t[i]==this&&t.splice(i--,1);t.length||(r.widgets=null);var o=Br(this);je(e,function(){Fr(e,r,-o),tt(e,n,"widget"),hn(r,Math.max(0,r.height-o))})}},Co.prototype.changed=function(){var e=this.height,t=this.cm,r=this.line;this.height=null;var n=Br(this)-e;n&&je(t,function(){t.curOp.forceUpdate=!0,Fr(t,r,n),hn(r,r.height+n)})};var Lo=e.Line=function(e,t,r){this.text=e,kr(this,t),this.height=r?r(this):1};Fn(Lo),Lo.prototype.lineNo=function(){return dn(this)};var So={},ko={};on.prototype={chunkSize:function(){return this.lines.length},removeInner:function(e,t){for(var r=e,n=e+t;r<n;++r){var i=this.lines[r];this.height-=i.height,Ur(i),In(i,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,r){this.height+=r,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var n=0;n<t.length;++n)t[n].parent=this},iterN:function(e,t,r){for(var n=e+t;e<n;++e)if(r(this.lines[e]))return!0}},ln.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var r=0;r<this.children.length;++r){var n=this.children[r],i=n.chunkSize();if(e<i){var o=Math.min(t,i-e),l=n.height;if(n.removeInner(e,o),this.height-=l-n.height,i==o&&(this.children.splice(r--,1),n.parent=null),0==(t-=o))break;e=0}else e-=i}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof on))){var s=[];this.collapse(s),this.children=[new on(s)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t<this.children.length;++t)this.children[t].collapse(e)},insertInner:function(e,t,r){this.size+=t.length,this.height+=r;for(var n=0;n<this.children.length;++n){var i=this.children[n],o=i.chunkSize();if(e<=o){if(i.insertInner(e,t,r),i.lines&&i.lines.length>50){for(;i.lines.length>50;){var l=i.lines.splice(i.lines.length-25,25),s=new on(l);i.height-=s.height,this.children.splice(n+1,0,s),s.parent=this}this.maybeSpill()}break}e-=o}},maybeSpill:function(){if(!(this.children.length<=10)){var e=this;do{var t=e.children.splice(e.children.length-5,5),r=new ln(t);if(e.parent){e.size-=r.size,e.height-=r.height;var n=Kn(e.parent.children,e);e.parent.children.splice(n+1,0,r)}else{var i=new ln(e.children);i.parent=e,e.children=[i,r],e=i}r.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},iterN:function(e,t,r){for(var n=0;n<this.children.length;++n){var i=this.children[n],o=i.chunkSize();if(e<o){var l=Math.min(t,o-e);if(i.iterN(e,l,r))return!0;if(0==(t-=l))break;e=0}else e-=o}}};var Mo=0,To=e.Doc=function(e,t,r){if(!(this instanceof To))return new To(e,t,r);null==r&&(r=0),ln.call(this,[new on([new Lo("",null)])]),this.first=r,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.frontier=r;var n=Vi(r,0);this.sel=Y(n),this.history=new vn(null),this.id=++Mo,this.modeOption=t,"string"==typeof e&&(e=el(e)),nn(this,{from:n,to:n,text:e}),le(this,Y(n),Bo)};To.prototype=Xn(ln.prototype,{constructor:To,iter:function(e,t,r){r?this.iterN(e-this.first,t-e,r):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var r=0,n=0;n<t.length;++n)r+=t[n].height;this.insertInner(e-this.first,t,r)},remove:function(e,t){this.removeInner(e-this.first,t)},getValue:function(e){var t=fn(this,this.first,this.first+this.size);return!1===e?t:t.join(e||"\n")},setValue:Ze(function(e){var t=Vi(this.first,0),r=this.first+this.size-1;Kt(this,{from:t,to:Vi(r,un(this,r).text.length),text:el(e),origin:"setValue"},!0),le(this,Y(t))}),replaceRange:function(e,t,r,n){t=$(this,t),r=r?$(this,r):t,qt(this,e,t,r,n)},getRange:function(e,t,r){var n=cn(this,$(this,e),$(this,t));return!1===r?n:n.join(r||"\n")},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},getLineHandle:function(e){if(Z(this,e))return un(this,e)},getLineNumber:function(e){return dn(e)},getLineHandleVisualStart:function(e){return"number"==typeof e&&(e=un(this,e)),Dr(e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return $(this,e)},getCursor:function(e){var t=this.sel.primary();return null==e||"head"==e?t.head:"anchor"==e?t.anchor:"end"==e||"to"==e||!1===e?t.to():t.from()},listSelections:function(){return this.sel.ranges},somethingSelected:function(){return this.sel.somethingSelected()},setCursor:Ze(function(e,t,r){ne(this,$(this,"number"==typeof e?Vi(e,t||0):e),null,r)}),setSelection:Ze(function(e,t,r){ne(this,$(this,e),$(this,t||e),r)}),extendSelection:Ze(function(e,t,r){ee(this,$(this,e),t&&$(this,t),r)}),extendSelections:Ze(function(e,t){te(this,Q(this,e))}),extendSelectionsBy:Ze(function(e,t){te(this,_n(this.sel.ranges,e),t)}),setSelections:Ze(function(e,t,r){if(e.length){for(var n=0,i=[];n<e.length;n++)i[n]=new _($(this,e[n].anchor),$(this,e[n].head));null==t&&(t=Math.min(e.length-1,this.sel.primIndex)),le(this,X(i,t),r)}}),addSelection:Ze(function(e,t,r){var n=this.sel.ranges.slice(0);n.push(new _($(this,e),$(this,t||e))),le(this,X(n,n.length-1),r)}),getSelection:function(e){for(var t,r=this.sel.ranges,n=0;n<r.length;n++){var i=cn(this,r[n].from(),r[n].to());t=t?t.concat(i):i}return!1===e?t:t.join(e||"\n")},getSelections:function(e){for(var t=[],r=this.sel.ranges,n=0;n<r.length;n++){var i=cn(this,r[n].from(),r[n].to());!1!==e&&(i=i.join(e||"\n")),t[n]=i}return t},replaceSelection:Ze(function(e,t,r){for(var n=[],i=0;i<this.sel.ranges.length;i++)n[i]=e;this.replaceSelections(n,t,r||"+input")}),replaceSelections:function(e,t,r){for(var n=[],i=this.sel,o=0;o<i.ranges.length;o++){var l=i.ranges[o];n[o]={from:l.from(),to:l.to(),text:el(e[o]),origin:r}}for(var s=t&&"end"!=t&&Vt(this,n,t),o=n.length-1;o>=0;o--)Kt(this,n[o]);s?oe(this,s):this.cm&&rr(this.cm)},undo:Ze(function(){Xt(this,"undo")}),redo:Ze(function(){Xt(this,"redo")}),undoSelection:Ze(function(){Xt(this,"undo",!0)}),redoSelection:Ze(function(){Xt(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,r=0,n=0;n<e.done.length;n++)e.done[n].ranges||++t;for(var n=0;n<e.undone.length;n++)e.undone[n].ranges||++r;return{undo:t,redo:r}},clearHistory:function(){this.history=new vn(this.history.maxGeneration)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(e){return e&&(this.history.lastOp=this.history.lastOrigin=null),this.history.generation},isClean:function(e){return this.history.generation==(e||this.cleanGeneration)},getHistory:function(){return{done:Nn(this.history.done),undone:Nn(this.history.undone)}},setHistory:function(e){var t=this.history=new vn(this.history.maxGeneration);t.done=Nn(e.done.slice(0),null,!0),t.undone=Nn(e.undone.slice(0),null,!0)},markText:function(e,t,r){return hr(this,$(this,e),$(this,t),r,"range")},setBookmark:function(e,t){var r={replacedWith:t&&(null==t.nodeType?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1,shared:t&&t.shared};return e=$(this,e),hr(this,e,e,r,"bookmark")},findMarksAt:function(e){e=$(this,e);var t=[],r=un(this,e.line).markedSpans;if(r)for(var n=0;n<r.length;++n){var i=r[n];(null==i.from||i.from<=e.ch)&&(null==i.to||i.to>=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t){e=$(this,e),t=$(this,t);var r=[],n=e.line;return this.iter(e.line,t.line+1,function(i){var o=i.markedSpans;if(o)for(var l=0;l<o.length;l++){var s=o[l];n==e.line&&e.ch>s.to||null==s.from&&n!=e.line||n==t.line&&s.from>t.ch||r.push(s.marker.parent||s.marker)}++n}),r},getAllMarks:function(){var e=[];return this.iter(function(t){var r=t.markedSpans;if(r)for(var n=0;n<r.length;++n)null!=r[n].from&&e.push(r[n].marker)}),e},posFromIndex:function(e){var t,r=this.first;return this.iter(function(n){var i=n.text.length+1;if(i>e)return t=e,!0;e-=i,++r}),$(this,Vi(r,t))},indexFromPos:function(e){e=$(this,e);var t=e.ch;return e.line<this.first||e.ch<0?0:(this.iter(this.first,e.line,function(e){t+=e.text.length+1}),t)},copy:function(e){var t=new To(fn(this,this.first,this.first+this.size),this.modeOption,this.first);return t.scrollTop=this.scrollTop,t.scrollLeft=this.scrollLeft,t.sel=this.sel,t.extend=!1,e&&(t.history.undoDepth=this.history.undoDepth,t.setHistory(this.getHistory())),t},linkedDoc:function(e){e||(e={});var t=this.first,r=this.first+this.size;null!=e.from&&e.from>t&&(t=e.from),null!=e.to&&e.to<r&&(r=e.to);var n=new To(fn(this,t,r),e.mode||this.modeOption,t);return e.sharedHist&&(n.history=this.history),(this.linked||(this.linked=[])).push({doc:n,sharedHist:e.sharedHist}),n.linked=[{doc:this,isParent:!0,sharedHist:e.sharedHist}],n},unlinkDoc:function(t){if(t instanceof e&&(t=t.doc),this.linked)for(var r=0;r<this.linked.length;++r){var n=this.linked[r];if(n.doc==t){this.linked.splice(r,1),t.unlinkDoc(this);break}}if(t.history==this.history){var i=[t.id];sn(t,function(e){i.push(e.id)},!0),t.history=new vn(null),t.history.done=Nn(this.history.done,i),t.history.undone=Nn(this.history.undone,i)}},iterLinkedDocs:function(e){sn(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm}}),To.prototype.eachLine=To.prototype.iter;var No="iter insert remove copy getEditor".split(" ");for(var Ho in To.prototype)To.prototype.hasOwnProperty(Ho)&&Kn(No,Ho)<0&&(e.prototype[Ho]=function(e){return function(){return e.apply(this.doc,arguments)}}(To.prototype[Ho]));Fn(To);var Ao,Oo=e.e_preventDefault=function(e){e.preventDefault?e.preventDefault():e.returnValue=!1},Wo=e.e_stopPropagation=function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},Do=e.e_stop=function(e){Oo(e),Wo(e)},Eo=e.on=function(e,t,r){if(e.addEventListener)e.addEventListener(t,r,!1);else if(e.attachEvent)e.attachEvent("on"+t,r);else{var n=e._handlers||(e._handlers={}),i=n[t]||(n[t]=[]);i.push(r)}},Io=e.off=function(e,t,r){if(e.removeEventListener)e.removeEventListener(t,r,!1);else if(e.detachEvent)e.detachEvent("on"+t,r);else{var n=e._handlers&&e._handlers[t];if(!n)return;for(var i=0;i<n.length;++i)if(n[i]==r){n.splice(i,1);break}}},zo=e.signal=function(e,t){var r=e._handlers&&e._handlers[t];if(r)for(var n=Array.prototype.slice.call(arguments,2),i=0;i<r.length;++i)r[i].apply(null,n)},Po=0,Ro=30,Fo=e.Pass={toString:function(){return"CodeMirror.Pass"}},Bo={scroll:!1},Go={origin:"*mouse"},Vo={origin:"+move"};Bn.prototype.set=function(e,t){clearTimeout(this.id),this.id=setTimeout(t,e)};var Uo=e.countColumn=function(e,t,r,n,i){null==t&&-1==(t=e.search(/[^\s\u00a0]/))&&(t=e.length);for(var o=n||0,l=i||0;;){var s=e.indexOf("\t",o);if(s<0||s>=t)return l+(t-o);l+=s-o,l+=r-l%r,o=s+1}},Ko=[""],_o=function(e){e.select()};Di?_o=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:Li&&(_o=function(e){try{e.select()}catch(e){}}),[].indexOf&&(Kn=function(e,t){return e.indexOf(t)}),[].map&&(_n=function(e,t){return e.map(t)});var Xo,Yo=/[\u00df\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,jo=e.isWordChar=function(e){return/\w/.test(e)||e>""&&(e.toUpperCase()!=e.toLowerCase()||Yo.test(e))},$o=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;Xo=document.createRange?function(e,t,r){var n=document.createRange();return n.setEnd(e,r),n.setStart(e,t),n}:function(e,t,r){var n=document.body.createTextRange();return n.moveToElementText(e.parentNode),n.collapse(!0),n.moveEnd("character",r),n.moveStart("character",t),n},yi&&(ti=function(){try{return document.activeElement}catch(e){return document.body}});var qo,Zo,Qo,Jo=function(){if(xi)return!1;var e=Zn("div");return"draggable"in e||"dragDrop"in e}(),el=e.splitLines=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,r=[],n=e.length;t<=n;){var i=e.indexOf("\n",t);-1==i&&(i=e.length);var o=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),l=o.indexOf("\r");-1!=l?(r.push(o.slice(0,l)),t+=l+1):(r.push(o),t=i+1)}return r}:function(e){return e.split(/\r\n?|\n/)},tl=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(e){return!1}}:function(e){try{var t=e.ownerDocument.selection.createRange()}catch(e){}return!(!t||t.parentElement()!=e)&&0!=t.compareEndPoints("StartToEnd",t)},rl=function(){var e=Zn("div");return"oncopy"in e||(e.setAttribute("oncopy","return;"),"function"==typeof e.oncopy)}(),nl={3:"Enter",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",61:"=",91:"Mod",92:"Mod",93:"Mod",107:"=",109:"-",127:"Delete",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"};e.keyNames=nl,function(){for(var e=0;e<10;e++)nl[e+48]=nl[e+96]=String(e);for(var e=65;e<=90;e++)nl[e]=String.fromCharCode(e);for(var e=1;e<=12;e++)nl[e+111]=nl[e+63235]="F"+e}();var il,ol=function(){function e(e){return e<=247?r.charAt(e):1424<=e&&e<=1524?"R":1536<=e&&e<=1773?n.charAt(e-1536):1774<=e&&e<=2220?"r":8192<=e&&e<=8203?"w":8204==e?"b":"L"}function t(e,t,r){this.level=e,this.from=t,this.to=r}var r="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",n="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm",i=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,o=/[stwN]/,l=/[LRr]/,s=/[Lb1n]/,a=/[1n]/;return function(r){if(!i.test(r))return!1;for(var n,u=r.length,c=[],f=0;f<u;++f)c.push(n=e(r.charCodeAt(f)));for(var f=0,h="L";f<u;++f){var n=c[f];"m"==n?c[f]=h:h=n}for(var f=0,d="L";f<u;++f){var n=c[f];"1"==n&&"r"==d?c[f]="n":l.test(n)&&(d=n,"r"==n&&(c[f]="R"))}for(var f=1,h=c[0];f<u-1;++f){var n=c[f];"+"==n&&"1"==h&&"1"==c[f+1]?c[f]="1":","!=n||h!=c[f+1]||"1"!=h&&"n"!=h||(c[f]=h),h=n}for(var f=0;f<u;++f){var n=c[f];if(","==n)c[f]="N";else if("%"==n){for(var p=f+1;p<u&&"%"==c[p];++p);for(var g=f&&"!"==c[f-1]||p<u&&"1"==c[p]?"1":"N",m=f;m<p;++m)c[m]=g;f=p-1}}for(var f=0,d="L";f<u;++f){var n=c[f];"L"==d&&"1"==n?c[f]="L":l.test(n)&&(d=n)}for(var f=0;f<u;++f)if(o.test(c[f])){for(var p=f+1;p<u&&o.test(c[p]);++p);for(var v="L"==(f?c[f-1]:"L"),y="L"==(p<u?c[p]:"L"),g=v||y?"L":"R",m=f;m<p;++m)c[m]=g;f=p-1}for(var b,x=[],f=0;f<u;)if(s.test(c[f])){var w=f;for(++f;f<u&&s.test(c[f]);++f);x.push(new t(0,w,f))}else{var C=f,L=x.length;for(++f;f<u&&"L"!=c[f];++f);for(var m=C;m<f;)if(a.test(c[m])){C<m&&x.splice(L,0,new t(1,C,m));var S=m;for(++m;m<f&&a.test(c[m]);++m);x.splice(L,0,new t(2,S,m)),C=m}else++m;C<f&&x.splice(L,0,new t(1,C,f))}return 1==x[0].level&&(b=r.match(/^\s+/))&&(x[0].from=b[0].length,x.unshift(new t(0,0,b[0].length))),1==Un(x).level&&(b=r.match(/\s+$/))&&(Un(x).to-=b[0].length,x.push(new t(0,u-b[0].length,u))),x[0].level!=Un(x).level&&x.push(new t(x[0].level,u,u)),x}}();return e.version="4.0.3",e});</script> <script>colorPalettesAliases={1:"mastersystem",2:"gameboycolour",3:"amiga",4:"arnecolors",5:"famicom",6:"atari",7:"pastel",8:"ega",9:"amstrad",10:"proteus_mellow",11:"proteus_rich",12:"proteus_night",13:"c64",14:"whitingjp"},colorPalettes={mastersystem:{black:"#000000",white:"#FFFFFF",grey:"#555555",darkgrey:"#555500",lightgrey:"#AAAAAA",gray:"#555555",darkgray:"#555500",lightgray:"#AAAAAA",red:"#FF0000",darkred:"#AA0000",lightred:"#FF5555",brown:"#AA5500",darkbrown:"#550000",lightbrown:"#FFAA00",orange:"#FF5500",yellow:"#FFFF55",green:"#55AA00",darkgreen:"#005500",lightgreen:"#AAFF00",blue:"#5555AA",lightblue:"#AAFFFF",darkblue:"#000055",purple:"#550055",pink:"#FFAAFF"},gameboycolour:{black:"#000000",white:"#FFFFFF",grey:"#7F7F7C",darkgrey:"#3E3E44",lightgrey:"#BAA7A7",gray:"#7F7F7C",darkgray:"#3E3E44",lightgray:"#BAA7A7",red:"#A7120C",darkred:"#880606",lightred:"#BA381F",brown:"#57381F",darkbrown:"#3E2519",lightbrown:"#8E634B",orange:"#BA4B32",yellow:"#C0BA6F",green:"#517525",darkgreen:"#385D12",lightgreen:"#6F8E44",blue:"#5D6FA7",lightblue:"#8EA7A7",darkblue:"#4B575D",purple:"#3E3E44",pink:"#BA381F"},amiga:{black:"#000000",white:"#FFFFFF",grey:"#BBBBBB",darkgrey:"#333333",lightgrey:"#FFEEDD",gray:"#BBBBBB",darkgray:"#333333",lightgray:"#FFEEDD",red:"#DD1111",darkred:"#990000",lightred:"#FF4422",brown:"#663311",darkbrown:"#331100",lightbrown:"#AA6644",orange:"#FF6644",yellow:"#FFDD66",green:"#448811",darkgreen:"#335500",lightgreen:"#88BB77",blue:"#8899DD",lightblue:"#BBDDEE",darkblue:"#666688",purple:"#665555",pink:"#997788"},arnecolors:{black:"#000000",white:"#FFFFFF",grey:"#9d9d9d",darkgrey:"#697175",lightgrey:"#cccccc",gray:"#9d9d9d",darkgray:"#697175",lightgray:"#cccccc",red:"#be2633",darkred:"#732930",lightred:"#e06f8b",brown:"#a46422",darkbrown:"#493c2b",lightbrown:"#eeb62f",orange:"#eb8931",yellow:"#f7e26b",green:"#44891a",darkgreen:"#2f484e",lightgreen:"#a3ce27",blue:"#1d57f7",lightblue:"#B2DCEF",darkblue:"#1B2632",purple:"#342a97",pink:"#de65e2"},famicom:{black:"#000000",white:"#ffffff",grey:"#7c7c7c",darkgrey:"#080808",lightgrey:"#bcbcbc",gray:"#7c7c7c",darkgray:"#080808",lightgray:"#bcbcbc",red:"#f83800",darkred:"#881400",lightred:"#f87858",brown:"#AC7C00",darkbrown:"#503000",lightbrown:"#FCE0A8",orange:"#FCA044",yellow:"#F8B800",green:"#00B800",darkgreen:"#005800",lightgreen:"#B8F8B8",blue:"#0058F8",lightblue:"#3CBCFC",darkblue:"#0000BC",purple:"#6644FC",pink:"#F878F8"},atari:{black:"#000000",white:"#FFFFFF",grey:"#909090",darkgrey:"#404040",lightgrey:"#b0b0b0",gray:"#909090",darkgray:"#404040",lightgray:"#b0b0b0",red:"#A03C50",darkred:"#700014",lightred:"#DC849C",brown:"#805020",darkbrown:"#703400",lightbrown:"#CB9870",orange:"#CCAC70",yellow:"#ECD09C",green:"#58B06C",darkgreen:"#006414",lightgreen:"#70C484",blue:"#1C3C88",lightblue:"#6888C8",darkblue:"#000088",purple:"#3C0080",pink:"#B484DC"},pastel:{black:"#000000",white:"#FFFFFF",grey:"#3e3e3e",darkgrey:"#313131",lightgrey:"#9cbcbc",gray:"#3e3e3e",darkgray:"#313131",lightgray:"#9cbcbc",red:"#f56ca2",darkred:"#a63577",lightred:"#ffa9cf",brown:"#b58c53",darkbrown:"#787562",lightbrown:"#B58C53",orange:"#EB792D",yellow:"#FFe15F",green:"#00FF4F",darkgreen:"#2b732c",lightgreen:"#97c04f",blue:"#0f88d3",lightblue:"#00fffe",darkblue:"#293a7b",purple:"#ff6554",pink:"#eb792d"},ega:{black:"#000000",white:"#ffffff",grey:"#555555",darkgrey:"#555555",lightgrey:"#aaaaaa",gray:"#555555",darkgray:"#555555",lightgray:"#aaaaaa",red:"#ff5555",darkred:"#aa0000",lightred:"#ff55ff",brown:"#aa5500",darkbrown:"#aa5500",lightbrown:"#ffff55",orange:"#ff5555",yellow:"#ffff55",green:"#00aa00",darkgreen:"#00aaaa",lightgreen:"#55ff55",blue:"#5555ff",lightblue:"#55ffff",darkblue:"#0000aa",purple:"#aa00aa",pink:"#ff55ff"},proteus_mellow:{black:"#3d2d2e",white:"#ddf1fc",grey:"#9fb2d4",darkgrey:"#7b8272",lightgrey:"#a4bfda",gray:"#9fb2d4",darkgray:"#7b8272",lightgray:"#a4bfda",red:"#9d5443",darkred:"#8c5b4a",lightred:"#94614c",brown:"#89a78d",darkbrown:"#829e88",lightbrown:"#aaae97",orange:"#d1ba86",yellow:"#d6cda2",green:"#75ac8d",darkgreen:"#8fa67f",lightgreen:"#8eb682",blue:"#88a3ce",lightblue:"#a5adb0",darkblue:"#5c6b8c",purple:"#d39fac",pink:"#c8ac9e"},proteus_night:{black:"#010912",white:"#fdeeec",grey:"#051d40",darkgrey:"#091842",lightgrey:"#062151",gray:"#051d40",darkgray:"#091842",lightgray:"#062151",red:"#ad4576",darkred:"#934765",lightred:"#ab6290",brown:"#61646b",darkbrown:"#3d2d2d",lightbrown:"#8393a0",orange:"#0a2227",yellow:"#0a2541",green:"#75ac8d",darkgreen:"#0a2434",lightgreen:"#061f2e",blue:"#0b2c79",lightblue:"#809ccb",darkblue:"#08153b",purple:"#666a87",pink:"#754b4d"},proteus_rich:{black:"#6f686f",white:"#d1b1e2",grey:"#b9aac1",darkgrey:"#8e8b84",lightgrey:"#c7b5cd",gray:"#b9aac1",darkgray:"#8e8b84",lightgray:"#c7b5cd",red:"#a11f4f",darkred:"#934765",lightred:"#c998ad",brown:"#89867d",darkbrown:"#797f75",lightbrown:"#ab9997",orange:"#ce8c5c",yellow:"#f0d959",green:"#75bc54",darkgreen:"#599d79",lightgreen:"#90cf5c",blue:"#8fd0ec",lightblue:"#bcdce7",darkblue:"#0b2c70",purple:"#9b377f",pink:"#cd88e5"},amstrad:{black:"#000000",white:"#ffffff",grey:"#7f7f7f",darkgrey:"#636363",lightgrey:"#afafaf",gray:"#7f7f7f",darkgray:"#636363",lightgray:"#afafaf",red:"#ff0000",darkred:"#7f0000",lightred:"#ff7f7f",brown:"#ff7f00",darkbrown:"#7f7f00",lightbrown:"#ffff00",orange:"#ff007f",yellow:"#ffff7f",green:"#01ff00",darkgreen:"#007f00",lightgreen:"#7fff7f",blue:"#0000ff",lightblue:"#7f7fff",darkblue:"#00007f",purple:"#7f007f",pink:"#ff7fff"},c64:{black:"#000000",white:"#ffffff",grey:"#6C6C6C",darkgrey:"#444444",lightgrey:"#959595",gray:"#6C6C6C",darkgray:"#444444",lightgray:"#959595",red:"#68372B",darkred:"#3f1e17",lightred:"#9A6759",brown:"#433900",darkbrown:"#221c02",lightbrown:"#6d5c0d",orange:"#6F4F25",yellow:"#B8C76F",green:"#588D43",darkgreen:"#345129",lightgreen:"#9AD284",blue:"#6C5EB5",lightblue:"#70A4B2",darkblue:"#352879",purple:"#6F3D86",pink:"#b044ac"},whitingjp:{black:"#202527",white:"#eff8fd",grey:"#7b7680",darkgrey:"#3c3b44",lightgrey:"#bed0d7",gray:"#7b7680",darkgray:"#3c3b44",lightgray:"#bed0d7",red:"#bd194b",darkred:"#6b1334",lightred:"#ef2358",brown:"#b52e1c",darkbrown:"#681c12",lightbrown:"#e87b45",orange:"#ff8c10",yellow:"#fbd524",green:"#36bc3c",darkgreen:"#317610",lightgreen:"#8ce062",blue:"#3f62c6",lightblue:"#57bbe0",darkblue:"#2c2fa0",purple:"#7037d9",pink:"#ec2b8f"}};var reg_color_names=/(black|white|darkgray|lightgray|gray|grey|darkgrey|lightgrey|red|darkred|lightred|brown|darkbrown|lightbrown|orange|yellow|green|darkgreen|lightgreen|blue|lightblue|darkblue|purple|pink|transparent)\s*/,reg_color=/(black|white|gray|darkgray|lightgray|grey|darkgrey|lightgrey|red|darkred|lightred|brown|darkbrown|lightbrown|orange|yellow|green|darkgreen|lightgreen|blue|lightblue|darkblue|purple|pink|transparent|#(?:[0-9a-f]{3}){1,2})\s*/;</script> <script>function createSprite(e,t,i,r,a){void 0===i&&(i=[state.bgcolor,state.fgcolor]),void 0==a&&(a=!1);var l=makeSpriteCanvas(e),o=l.getContext("2d");o.clearRect(0,0,cellwidth,cellheight);var s=t[0].length,n=t.length,c=~~(cellwidth/(s+(0|r))),g=~~(cellheight/(n+(0|r))),h=g;"scanline"in state.metadata&&(h=Math.ceil(g/2)),o.fillStyle=state.fgcolor;for(var d=0;d<s;d++)for(var f=0;f<n;f++){var m=a?t[f][d]:t[d][f];if(m>=0){var p=d*c|0,v=f*g|0;o.fillStyle=i[m],o.fillRect(v,p,c,h)}}return l}function createSpriteBuffer(e,t,i,r){void 0===i&&(i=[state.bgcolor,state.fgcolor]),rgbColors=[];for(var a=0;a<i.length;++a)rgbColors.push([parseInt(i[a].substring(1,3),16)/255,parseInt(i[a].substring(3,5),16)/255,parseInt(i[a].substring(5,7),16)/255]);var l=[],o=[];switch(r){case"floor":addHorizontalPlaneVerts(t[0],rgbColors,l,o,0);break;case"ceiling":addHorizontalPlaneVerts(t[0],rgbColors,l,o,1);break;case"sandwich":addHorizontalPlaneVerts(t[0],rgbColors,l,o,1),t.length>1?addHorizontalPlaneVerts(t[1],rgbColors,l,o,0):addHorizontalPlaneVerts(t[0],rgbColors,l,o,0);break;case"sprite":case"billboard":case"hud":addVerticalPlaneVerts(t[0],rgbColors,l,o);break;case"wall":addWallVerts(t[0],rgbColors,l,o);break;case"voxel":case"motionvoxel":case"facingvoxel":addVoxelVerts(t,rgbColors,l,o)}var s=gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER,s),gl.bufferData(gl.ARRAY_BUFFER,new Float32Array(l),gl.STATIC_DRAW);var n=gl.createBuffer();return gl.bindBuffer(gl.ARRAY_BUFFER,n),gl.bufferData(gl.ARRAY_BUFFER,new Float32Array(o),gl.STATIC_DRAW),[s,n,l.length/3]}function addHorizontalPlaneVerts(e,t,i,r,a){for(var l,o,s,n,c,g,h,d=e[0].length,f=e.length,m=i.length,p=r.length,v=0;v<d;v++)for(var u=0;u<f;u++){var w=e[u][v];w>=0&&(l=v/d-.5,o=(v+1)/d-.5,s=u/f-.5,n=(u+1)/f-.5,i.splice(m,0,o,a,n),m+=3,i.splice(m,0,l,a,n),m+=3,i.splice(m,0,o,a,s),m+=3,i.splice(m,0,l,a,n),m+=3,i.splice(m,0,o,a,s),m+=3,i.splice(m,0,l,a,s),m+=3,c=t[w][0],g=t[w][1],h=t[w][2],r.splice(p,0,c,g,h,1),p+=4,r.splice(p,0,c,g,h,1),p+=4,r.splice(p,0,c,g,h,1),p+=4,r.splice(p,0,c,g,h,1),p+=4,r.splice(p,0,c,g,h,1),p+=4,r.splice(p,0,c,g,h,1),p+=4)}}function addVerticalPlaneVerts(e,t,i,r){for(var a,l,o,s,n,c,g,h=e[0].length,d=e.length,f=i.length,m=r.length,p=0;p<h;p++)for(var v=0;v<d;v++){var u=e[v][p];u>=0&&(a=p/h-.5,l=(p+1)/h-.5,o=1-v/d,s=1-(v+1)/d,i.splice(f,0,l,s,0),f+=3,i.splice(f,0,a,s,0),f+=3,i.splice(f,0,l,o,0),f+=3,i.splice(f,0,a,s,0),f+=3,i.splice(f,0,l,o,0),f+=3,i.splice(f,0,a,o,0),f+=3,n=t[u][0],c=t[u][1],g=t[u][2],r.splice(m,0,n,c,g,1),m+=4,r.splice(m,0,n,c,g,1),m+=4,r.splice(m,0,n,c,g,1),m+=4,r.splice(m,0,n,c,g,1),m+=4,r.splice(m,0,n,c,g,1),m+=4,r.splice(m,0,n,c,g,1),m+=4)}}function addWallVerts(e,t,i,r){for(var a,l,o,s,n,c,g,h=e[0].length,d=e.length,f=i.length,m=r.length,p=0;p<h;p++)for(var v=0;v<d;v++){var u=e[v][p];if(u>=0){a=p/h-.5,l=(p+1)/h-.5,o=1-v/d,s=1-(v+1)/d,i.splice(f,0,l,s,.5),f+=3,i.splice(f,0,a,s,.5),f+=3,i.splice(f,0,l,o,.5),f+=3,i.splice(f,0,a,s,.5),f+=3,i.splice(f,0,l,o,.5),f+=3,i.splice(f,0,a,o,.5),f+=3,i.splice(f,0,-.5,s,l),f+=3,i.splice(f,0,-.5,s,a),f+=3,i.splice(f,0,-.5,o,l),f+=3,i.splice(f,0,-.5,s,a),f+=3,i.splice(f,0,-.5,o,l),f+=3,i.splice(f,0,-.5,o,a),f+=3,i.splice(f,0,-l,s,-.5),f+=3,i.splice(f,0,-a,s,-.5),f+=3,i.splice(f,0,-l,o,-.5),f+=3,i.splice(f,0,-a,s,-.5),f+=3,i.splice(f,0,-l,o,-.5),f+=3,i.splice(f,0,-a,o,-.5),f+=3,i.splice(f,0,.5,s,-l),f+=3,i.splice(f,0,.5,s,-a),f+=3,i.splice(f,0,.5,o,-l),f+=3,i.splice(f,0,.5,s,-a),f+=3,i.splice(f,0,.5,o,-l),f+=3,i.splice(f,0,.5,o,-a),f+=3,n=t[u][0],c=t[u][1],g=t[u][2];for(var w=0;w<24;++w)r.splice(m,0,n,c,g,1),m+=4}}}function addVoxelVerts(e,t,i,r){for(var a,l,o,s,n,c,g,h,d,f=e.width,m=e.height,p=e.depth,v=i.length,u=r.length,w=0,x=0;x<f;x++)for(var M=0;M<m;M++)for(var y=0;y<p;++y){var P=e[y][M][x];if(P>=0&&(a=x/f-.5,l=(x+1)/f-.5,o=M/m-.5,s=(M+1)/m-.5,n=1-y/p,c=1-(y+1)/p,w=0,y!=p-1&&-1!=e[y+1][M][x]||(i.splice(v,0,l,c,s),v+=3,i.splice(v,0,a,c,s),v+=3,i.splice(v,0,l,c,o),v+=3,i.splice(v,0,a,c,s),v+=3,i.splice(v,0,l,c,o),v+=3,i.splice(v,0,a,c,o),v+=3,w+=6),0!=y&&-1!=e[y-1][M][x]||(i.splice(v,0,l,n,s),v+=3,i.splice(v,0,a,n,s),v+=3,i.splice(v,0,l,n,o),v+=3,i.splice(v,0,a,n,s),v+=3,i.splice(v,0,l,n,o),v+=3,i.splice(v,0,a,n,o),v+=3,w+=6),0!=x&&-1!=e[y][M][x-1]||(i.splice(v,0,a,c,s),v+=3,i.splice(v,0,a,n,s),v+=3,i.splice(v,0,a,c,o),v+=3,i.splice(v,0,a,n,s),v+=3,i.splice(v,0,a,c,o),v+=3,i.splice(v,0,a,n,o),v+=3,w+=6),x!=f-1&&-1!=e[y][M][x+1]||(i.splice(v,0,l,c,s),v+=3,i.splice(v,0,l,n,s),v+=3,i.splice(v,0,l,c,o),v+=3,i.splice(v,0,l,n,s),v+=3,i.splice(v,0,l,c,o),v+=3,i.splice(v,0,l,n,o),v+=3,w+=6),M!=m-1&&-1!=e[y][M+1][x]||(i.splice(v,0,l,c,s),v+=3,i.splice(v,0,l,n,s),v+=3,i.splice(v,0,a,c,s),v+=3,i.splice(v,0,l,n,s),v+=3,i.splice(v,0,a,c,s),v+=3,i.splice(v,0,a,n,s),v+=3,w+=6),0!=M&&-1!=e[y][M-1][x]||(i.splice(v,0,l,c,o),v+=3,i.splice(v,0,l,n,o),v+=3,i.splice(v,0,a,c,o),v+=3,i.splice(v,0,l,n,o),v+=3,i.splice(v,0,a,c,o),v+=3,i.splice(v,0,a,n,o),v+=3,w+=6),w>0))for(g=t[P][0],h=t[P][1],d=t[P][2];w>0;)r.splice(u,0,g,h,d,1),u+=4,w-=1}}function regenText(e,t){textImages={};for(var i in font)font.hasOwnProperty(i)&&(textImages[i]=createSprite("char"+i,font[i],void 0,1))}function regenSpriteImages(){if(textMode)return void regenText();if(levelEditorOpened&&(textImages.s=createSprite("chars",font.s,void 0)),0!==state.levels.length){spriteimages=[];for(var e=0;e<sprites.length;e++)void 0!=sprites[e]&&(spriteimages[e]=createSprite(e.toString(),sprites[e].dat[0],sprites[e].colors,0,!0));for(var e=0;e<spriteBuffers.length;++e)void 0!=spriteBuffers[e]&&(gl.deleteBuffer(spriteBuffers[e][0]),gl.deleteBuffer(spriteBuffers[e][1]));spriteBuffers=[];for(var e=0;e<sprites.length;++e)void 0!=sprites[e]&&(spriteBuffers[e]=createSpriteBuffer(e.toString(),sprites[e].dat,sprites[e].colors,sprites[e].renderType));canOpenEditor&&generateGlyphImages()}}function makeSpriteCanvas(e){var t;return e in canvasdict?t=canvasdict[e]:(t=document.createElement("canvas"),canvasdict[e]=t),t.width=cellwidth,t.height=cellheight,t}function generateGlyphImages(){if(0!==cellwidth&&0!==cellheight){glyphImagesCorrespondance=[],glyphImages=[];for(var e in state.glyphDict)if(1==e.length&&state.glyphDict.hasOwnProperty(e)){var t=state.glyphDict[e],i=makeSpriteCanvas("C"+e),r=i.getContext("2d");glyphImagesCorrespondance.push(e);for(var a=0;a<t.length;a++){var l=t[a];-1!==l&&r.drawImage(spriteimages[l],0,0)}glyphImages.push(i)}glyphHighlight=makeSpriteCanvas("highlight");var r=glyphHighlight.getContext("2d");r.fillStyle="#FFFFFF",r.fillRect(0,0,cellwidth,1),r.fillRect(0,0,1,cellheight),r.fillRect(0,cellheight-1,cellwidth,1),r.fillRect(cellwidth-1,0,1,cellheight),glyphPrintButton=textImages.s,glyphHighlightResize=makeSpriteCanvas("highlightresize");var r=glyphHighlightResize.getContext("2d");r.fillStyle="#FFFFFF";var o=cellwidth/2-1|0,s=cellwidth-o-1-o,n=cellheight/2-1|0,c=cellheight-n-1-o;r.fillRect(o,0,s,cellheight),r.fillRect(0,n,cellwidth,c),glyphMouseOver=makeSpriteCanvas();var r=glyphMouseOver.getContext("2d");r.fillStyle="yellow",r.fillRect(0,0,cellwidth,2),r.fillRect(0,0,2,cellheight),r.fillRect(0,cellheight-2,cellwidth,2),r.fillRect(cellwidth-2,0,2,cellheight)}}function glyphCount(){var e=0;for(var t in state.glyphDict)1==t.length&&state.glyphDict.hasOwnProperty(t)&&e++;return e}function initWebGL(e){return gl=null,gl=e.getContext("webgl")||e.getContext("experimental-webgl"),gl||alert("Unable to initialize WebGL. Your browser may not support it."),gl}function initMatrices(){vMatrix=mat4.create(),mMatrix=mat4.create(),pMatrix=mat4.create()}function initShaders(){var e=gl.createShader(gl.VERTEX_SHADER);gl.shaderSource(e,"\t\tattribute vec3 aVertexPosition;\t\tattribute vec4 aVertexColor;\t\t\t\tuniform mat4 uMMatrix;\t\tuniform mat4 uVMatrix;\t\tuniform mat4 uPMatrix;\t\tuniform lowp float uScaleHeight;\t\t\t\tvarying lowp vec4 vColor;\t\tvarying highp vec3 vPos;        varying highp vec3 wPos;\t\t\t\tvoid main(void)\t\t{\t\t\tgl_Position = uPMatrix * uVMatrix * uMMatrix * vec4(aVertexPosition * vec3(1.0,uScaleHeight,1.0), 1.0);\t\t\tvColor = aVertexColor;\t\t\tvPos = ( uVMatrix * uMMatrix * vec4( aVertexPosition, 1.0 ) ).xyz;            wPos = ( uMMatrix * vec4( aVertexPosition, 1.0 ) ).xyz;\t\t}\t   "),gl.compileShader(e),gl.getShaderParameter(e,gl.COMPILE_STATUS)||console.log("An error occurred compiling the shaders: "+gl.getShaderInfoLog(e));var t=gl.createShader(gl.FRAGMENT_SHADER);gl.shaderSource(t,"\t\tprecision mediump float;\t\t\t\tvarying lowp vec4 vColor;\t\tvarying highp vec3 vPos;\t\tvarying highp vec3 wPos;\t\t\t\tuniform lowp float uViewDistance;\t\tuniform lowp vec4 uFogColor;\t\tuniform lowp float uFogPower;        \t\tuniform lowp vec4 uGradientBottom;\t\tuniform lowp vec4 uGradientMiddle;\t\tuniform lowp vec4 uGradientTop;\t\t\t\tvoid main(void)\t\t{\t\t\tfloat fog = max( 1.0 - sqrt( dot( vPos, vPos ) ) / uViewDistance, 0.0 );\t\t\tfog = uFogPower > 0.0 ? pow( fog, uFogPower ) : ( fog <= 0.0 ? 0.0 : 1.0 );            float aoPos = wPos.y;            vec4 ao = mix( mix( uGradientBottom, uGradientMiddle, aoPos ), mix( uGradientMiddle, uGradientTop, aoPos ), aoPos );\t\t\tgl_FragColor = vColor * fog * ao + uFogColor * ( 1.0 - fog );\t\t}\t"),gl.compileShader(t),gl.getShaderParameter(t,gl.COMPILE_STATUS)||console.log("An error occurred compiling the shaders: "+gl.getShaderInfoLog(t)),shaderProgram=gl.createProgram(),gl.attachShader(shaderProgram,e),gl.attachShader(shaderProgram,t),gl.linkProgram(shaderProgram),gl.useProgram(shaderProgram),vertexPositionAttribute=gl.getAttribLocation(shaderProgram,"aVertexPosition"),gl.enableVertexAttribArray(vertexPositionAttribute),vertexColorAttribute=gl.getAttribLocation(shaderProgram,"aVertexColor"),gl.enableVertexAttribArray(vertexColorAttribute)}function initUniforms(){mUniform=gl.getUniformLocation(shaderProgram,"uMMatrix"),vUniform=gl.getUniformLocation(shaderProgram,"uVMatrix"),pUniform=gl.getUniformLocation(shaderProgram,"uPMatrix"),scaleHeightUniform=gl.getUniformLocation(shaderProgram,"uScaleHeight"),viewDistanceUniform=gl.getUniformLocation(shaderProgram,"uViewDistance"),fogColorUniform=gl.getUniformLocation(shaderProgram,"uFogColor"),fogPowerUniform=gl.getUniformLocation(shaderProgram,"uFogPower"),gradientBottomUniform=gl.getUniformLocation(shaderProgram,"uGradientBottom"),gradientMiddleUniform=gl.getUniformLocation(shaderProgram,"uGradientMiddle"),gradientTopUniform=gl.getUniformLocation(shaderProgram,"uGradientTop")}function redraw(){if(0!==cellwidth&&0!==cellheight){void 0===spriteimages&&regenSpriteImages();var e=level;if(void 0!=backups&&displayIndex<backups.length&&(e=backups[displayIndex]),textMode){canvas.style.visibility="visible",ctx.fillStyle=state.bgcolor,ctx.fillRect(0,0,canvas.width,canvas.height);for(var t=0;t<titleWidth;t++)for(var i=0;i<titleHeight;i++){var r=titleImage[i].charAt(t);if(r in textImages){var a=textImages[r];ctx.drawImage(a,xoffset+t*cellwidth,yoffset+i*cellheight)}}}else{var l=0,o=screenwidth,s=0,n=screenheight;if(levelEditorOpened){var c=glyphCount();editorRowCount=Math.ceil(c/(screenwidth-1)),o-=2,n-=2+editorRowCount}else if(flickscreen){var g=e.getPlayerPositions();if(g.length>0){var h=g[0],d=h/e.height|0,f=h%e.height|0,m=d/screenwidth|0,p=f/screenheight|0;l=m*screenwidth,s=p*screenheight,o=Math.min(l+screenwidth,e.width),n=Math.min(s+screenheight,e.height),oldflickscreendat=[l,s,o,n]}else oldflickscreendat.length>0&&(l=oldflickscreendat[0],s=oldflickscreendat[1],o=oldflickscreendat[2],n=oldflickscreendat[3])}else if(zoomscreen){var g=getPlayerPositions();if(g.length>0){var h=g[0],d=h/e.height|0,f=h%e.height|0;l=Math.max(Math.min(d-(screenwidth/2|0),e.width-screenwidth),0),s=Math.max(Math.min(f-(screenheight/2|0),e.height-screenheight),0),o=Math.min(l+screenwidth,e.width),n=Math.min(s+screenheight,e.height),oldflickscreendat=[l,s,o,n]}else oldflickscreendat.length>0&&(l=oldflickscreendat[0],s=oldflickscreendat[1],o=oldflickscreendat[2],n=oldflickscreendat[3])}levelEditorOpened&&drawEditorIcons();var v=interpolating,u=1-v,w=e;void 0!=backups&&backups.length>0&&displayIndex>0&&displayIndex<=backups.length&&(w=backups[displayIndex-1]);var t,i,x,M=parseInt(state.bgcolor.substring(1,3),16)/255,y=parseInt(state.bgcolor.substring(3,5),16)/255,P=parseInt(state.bgcolor.substring(5,7),16)/255,b=parseInt(gradientBottom.substring(1,3),16)/255,C=parseInt(gradientBottom.substring(3,5),16)/255,I=parseInt(gradientBottom.substring(5,7),16)/255,R=parseInt(gradientMiddle.substring(1,3),16)/255,S=parseInt(gradientMiddle.substring(3,5),16)/255,A=parseInt(gradientMiddle.substring(5,7),16)/255,U=parseInt(gradientTop.substring(1,3),16)/255,k=parseInt(gradientTop.substring(3,5),16)/255,B=parseInt(gradientTop.substring(5,7),16)/255;R=2*R-.5*U-.5*b,S=2*S-.5*k-.5*C,A=2*A-.5*B-.5*I,canvas.style.visibility="hidden",gl.clearColor(M,y,P,1),gl.enable(gl.DEPTH_TEST),gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT),mat4.perspective(pMatrix,fieldOfView/180*Math.PI,canvas3d.width/canvas3d.height,.01,viewDistance),mat4.fromXRotation(vMatrix,-viewPitch);var F=facingToYaw(w.facing),T=facingToYaw(e.facing);Math.abs(T-F)>Math.PI&&(F>T?T+=2*Math.PI:F+=2*Math.PI);var V=F*v+T*u;mat4.rotateY(vMatrix,vMatrix,V),w.facing[0]==e.facing[0]&&w.facing[1]==e.facing[1]||(v=0,u=1);var d=0,f=0,E=e.getPlayerPositions(),H="linear",L=0;if(E.length>0){E=E[0],pxe=E/e.height|0,pye=E%e.height|0;for(var D=e.getMotions(E),z=getLayersOfMask(state.playerMask),Y=dirMasksDelta[dirMasks.no],t=0;t<z.length;t++){var _=D.getshiftor(31,5*z[t]);if(0!=(_&dirMasks.moving)&&0!=(_&dirMasks.action)){Y=dirMasksDelta[_&dirMasks.moving];break}}if(pxs=pxe-Y[0],pys=pye-Y[1],pxs!=pxe||pys!=pye){e.getCellInto(pye+pxe*e.height,_o11),_o11.iand(state.playerMask);for(var t=0;t<state.objectCount;t++)if(_o11.get(t)){var O=state.idDict[t];H=state.objects[O].tween}d=tweenH(H,pxs,pxe,v,u),f=tweenH(H,pys,pye,v,u),L=tweenV(H,v,u)}else d=pxs,f=pys}else d=0,f=0;mat4.translate(vMatrix,vMatrix,[-d,-viewHeight-.25*L,-f]),gl.uniformMatrix4fv(pUniform,!1,pMatrix),gl.uniformMatrix4fv(vUniform,!1,vMatrix),gl.uniform1f(scaleHeightUniform,scaleHeight),gl.uniform1f(viewDistanceUniform,viewDistance),gl.uniform4f(fogColorUniform,M,y,P,1),gl.uniform1f(fogPowerUniform,fogPower),gl.uniform4f(gradientBottomUniform,b,C,I,1),gl.uniform4f(gradientMiddleUniform,R,S,A,1),gl.uniform4f(gradientTopUniform,U,k,B,1),l=Math.max(l,Math.floor(d-viewDistance-1)),o=Math.min(o,Math.ceil(d+viewDistance+1)),s=Math.max(s,Math.floor(f-viewDistance-1)),n=Math.min(n,Math.ceil(f+viewDistance+1));for(var G=0,X=0;X<3;X++){gl.depthFunc(1!=X?gl.ALWAYS:gl.LEQUAL);for(var W=0;W<state.objectCount;W++){var N=spriteBuffers[W];if(void 0!=N&&0!=N[2]){var j=sprites[W].renderType,q=sprites[W].tween;if((0==X||"floor"!=j&&"ceiling"!=j&&"sandwich"!=j)&&(1==X||"sprite"!=j&&"billboard"!=j&&"wall"!=j&&"voxel"!=j&&"motionvoxel"!=j&&"facingvoxel"!=j)&&(2==X||"hud"!=j)){gl.bindBuffer(gl.ARRAY_BUFFER,N[0]),gl.vertexAttribPointer(vertexPositionAttribute,3,gl.FLOAT,!1,0,0),gl.bindBuffer(gl.ARRAY_BUFFER,N[1]),gl.vertexAttribPointer(vertexColorAttribute,4,gl.FLOAT,!1,0,0);var Q=state.objects[state.idDict[W]].layer;2==X&&(mat4.identity(pMatrix),mat4.identity(vMatrix),gl.uniformMatrix4fv(pUniform,!1,pMatrix),gl.uniformMatrix4fv(vUniform,!1,vMatrix),gl.uniform4f(gradientBottomUniform,1,1,1,1),gl.uniform4f(gradientMiddleUniform,1,1,1,1),gl.uniform4f(gradientTopUniform,1,1,1,1));for(var J=l;J<o;J++)for(var K=s;K<n;K++){var Z=K+J*e.height,$=e.getCellInto(Z,_o12);if(0!=$.get(W)){var ee=e.getMotions(Z),Y=dirMasksDelta[dirMasks.no],_=ee.getshiftor(31,5*Q),te=ee.getshiftor(15,5*Q);if(0!=(te&dirMasks.moving)&&(Y=dirMasksDelta[te]),is=J-Y[0],js=K-Y[1],0==(_&dirMasks.action)||0==Y[0]&&0==Y[1]?(t=J,i=K,x=0):(t=tweenH(q,is,J,v,u),i=tweenH(q,js,K,v,u),x=tweenV(q,v,u)),G+=1,"floor"==j||"ceiling"==j||"sandwich"==j||"wall"==j||"voxel"==j)mat4.identity(mMatrix),mat4.translate(mMatrix,mMatrix,[t,x,i]),setMUniform(),gl.drawArrays(gl.TRIANGLES,0,N[2]);else if("sprite"==j||"facingvoxel"==j)mat4.identity(mMatrix),mat4.translate(mMatrix,mMatrix,[t,x,i]),t==d&&i==f||mat4.rotateY(mMatrix,mMatrix,.5*-Math.PI-Math.atan2(i-f,t-d)),setMUniform(),gl.drawArrays(gl.TRIANGLES,0,N[2]);else if("billboard"==j)mat4.identity(mMatrix),mat4.translate(mMatrix,mMatrix,[t,x,i]),mat4.rotateY(mMatrix,mMatrix,-V),setMUniform(),gl.drawArrays(gl.TRIANGLES,0,N[2]);else if("motionvoxel"==j){mat4.identity(mMatrix),mat4.translate(mMatrix,mMatrix,[t,x,i]),0==Y[0]&&0==Y[1]||mat4.rotateY(mMatrix,mMatrix,Math.atan2(Y[0],Y[1]));var ie=tweenP(q,v,u);0!=tweenP&&(mat4.translate(mMatrix,mMatrix,[0,.5,0]),mat4.rotateX(mMatrix,mMatrix,ie),mat4.translate(mMatrix,mMatrix,[0,-.5,0])),setMUniform(),gl.drawArrays(gl.TRIANGLES,0,N[2])}else"hud"==j&&(mat4.identity(mMatrix),mat4.translate(mMatrix,mMatrix,[0,-1,0]),mat4.scale(mMatrix,mMatrix,[2,2,2]),setMUniform(),gl.drawArrays(gl.TRIANGLES,0,N[2]))}}}}}}}}}function facingToYaw(e){return-1==e[0]?1.5*Math.PI:1==e[0]?.5*Math.PI:1==e[1]?Math.PI:0}function tweenH(e,t,i,r,a){switch(e){case"easein":var l=a*a;return t*(1-l)+i*l;case"easeout":var l=1-(1-a)*(1-a);return t*(1-l)+i*l;case"smoothstep":var l=a*a*(3-2*a);return t*(1-l)+i*l;case"throw":var o=Math.min(a/.66666,1),s=Math.max((a-.66666)/(1-.66666),0),l=.83333*o+s*(1-.83333);return t*(1-l)+i*l;case"linear":default:return r*t+a*i}}function tweenV(e,t,i){switch(e){case"step":case"bound":return.25*(1-Math.pow(2*i-1,2));case"doublestep":return.125*(1-Math.pow(2*i%1*2-1,2));case"throw":var r=Math.min(i/.66666,1),a=Math.max((i-.66666)/(1-.66666),0);return 1==i&&(r=1,a=1),tweenV("bound",r,r)+.125*tweenV("bound",a,a);default:return 0}}function tweenP(e,t,i){switch(e){case"bound":return-.125*Math.sin(i*Math.PI*2);case"roll":return i*Math.PI*2;default:return 0}}function drawEditorIcons(){var e=(glyphImages.length,glyphImages.length),t=e-0;ctx.drawImage(glyphPrintButton,xoffset-cellwidth,yoffset-cellheight*(1+editorRowCount)),mouseCoordY===-1-editorRowCount&&-1===mouseCoordX&&ctx.drawImage(glyphMouseOver,xoffset-cellwidth,yoffset-cellheight*(1+editorRowCount));for(var i=editorRowCount-(-mouseCoordY-2)-1,r=mouseCoordX+(screenwidth-1)*i,a=0;a<t;a++){var l=0+a,o=glyphImages[l],s=a%(screenwidth-1),i=a/(screenwidth-1)|0;ctx.drawImage(o,xoffset+s*cellwidth,yoffset+i*cellheight-cellheight*(1+editorRowCount)),mouseCoordX>=0&&mouseCoordX<screenwidth-1&&r===a&&ctx.drawImage(glyphMouseOver,xoffset+s*cellwidth,yoffset+i*cellheight-cellheight*(1+editorRowCount)),a===glyphSelectedIndex&&ctx.drawImage(glyphHighlight,xoffset+s*cellwidth,yoffset+i*cellheight-cellheight*(1+editorRowCount))}mouseCoordX>=-1&&mouseCoordY>=-1&&mouseCoordX<screenwidth-1&&mouseCoordY<screenheight-1-editorRowCount&&(-1==mouseCoordX||-1==mouseCoordY||mouseCoordX==screenwidth-2||mouseCoordY===screenheight-2-editorRowCount?ctx.drawImage(glyphHighlightResize,xoffset+mouseCoordX*cellwidth,yoffset+mouseCoordY*cellheight):ctx.drawImage(glyphHighlight,xoffset+mouseCoordX*cellwidth,yoffset+mouseCoordY*cellheight))}function canvasResize(){if(canvas3d.width=canvas.width=canvas.parentNode.clientWidth,canvas3d.height=canvas.height=canvas.parentNode.clientHeight,gl.viewport(0,0,canvas3d.width,canvas3d.height),screenwidth=level.width,screenheight=level.height,void 0!==state)if(flickscreen=void 0!==state.metadata.flickscreen,zoomscreen=void 0!==state.metadata.zoomscreen,levelEditorOpened){screenwidth+=2;var e=glyphCount();editorRowCount=Math.ceil(e/(screenwidth-1)),screenheight+=2+editorRowCount}else flickscreen?(screenwidth=state.metadata.flickscreen[0],screenheight=state.metadata.flickscreen[1]):zoomscreen&&(screenwidth=state.metadata.zoomscreen[0],screenheight=state.metadata.zoomscreen[1]);textMode&&(screenwidth=titleWidth,screenheight=titleHeight),cellwidth=canvas.width/screenwidth,cellheight=canvas.height/screenheight;var t=5,i=5;textMode&&(t=6,i=6),cellwidth=t*~~(cellwidth/t),cellheight=i*~~(cellheight/i),xoffset=0,yoffset=0,cellwidth>cellheight?(cellwidth=cellheight,xoffset=(canvas.width-cellwidth*screenwidth)/2,yoffset=(canvas.height-cellheight*screenheight)/2):(cellheight=cellwidth,yoffset=(canvas.height-cellheight*screenheight)/2,xoffset=(canvas.width-cellwidth*screenwidth)/2),magnification=cellwidth/t*5|0,levelEditorOpened&&!textMode&&(xoffset+=cellwidth,yoffset+=cellheight*(1+editorRowCount)),cellwidth|=0,cellheight|=0,xoffset|=0,yoffset|=0,(oldcellwidth!=cellwidth||oldcellheight!=cellheight||oldtextmode!=textMode||oldfgcolor!=state.fgcolor||forceRegenImages)&&(forceRegenImages=!1,regenSpriteImages()),oldcellheight=cellheight,oldcellwidth=cellwidth,oldtextmode=textMode,oldfgcolor=state.fgcolor,redraw()}function setMUniform(){gl.uniformMatrix4fv(mUniform,!1,mMatrix)}var spriteimages,spriteBuffers=[],glyphImagesCorrespondance,glyphImages,glyphHighlight,glyphHighlightResize,glyphPrintButton,glyphMouseOver,glyphSelectedIndex=0,editorRowCount=1,canvasdict={},canvas,ctx,x,y,cellwidth,cellheight,magnification,xoffset,yoffset;window.addEventListener("resize",canvasResize,!1),canvas=document.getElementById("gameCanvas"),ctx=canvas.getContext("2d"),canvas3d=document.getElementById("gameCanvas3d"),gl=initWebGL(canvas3d),initMatrices(),initShaders(),initUniforms(),x=0,y=0;var lastDownTarget,oldcellwidth=0,oldcellheight=0,oldtextmode=-1,oldfgcolor=-1,forceRegenImages=!1;</script> <script>function unloadGame(){state=introstate,level=new Level(0,5,5,2,null),level.objects=new Int32Array(0),generateTitleScreen(),canvasResize(),redraw()}function generateTitleScreen(){if(titleMode=curlevel>0||null!==curlevelTarget?1:0,0===state.levels.length)return void(titleImage=intro_template);var e="DungeonScript Game";void 0!==state.metadata.title&&(e=state.metadata.title),titleImage=deepClone(0===titleMode?titleSelected?titletemplate_firstgo_selected:titletemplate_firstgo:0===titleSelection?titleSelected?titletemplate_select0_selected:titletemplate_select0:titleSelected?titletemplate_select1_selected:titletemplate_select1);var t="noaction"in state.metadata,a="noundo"in state.metadata,n="norestart"in state.metadata;a&&n?titleImage[11]="..................................":a?titleImage[11]=".R to restart.....................":n&&(titleImage[11]=".Z to undo....................."),t&&(titleImage[10]=".X to select......................");for(var l=0;l<titleImage.length;l++)titleImage[l]=titleImage[l].replace(/\./g," ");for(var i=titleImage[0].length,o=wordwrap(e,titleImage[0].length),l=0;l<o.length;l++){var r=o[l],s=r.length,c=(i-s)/2|0,v=titleImage[1+l];titleImage[1+l]=v.slice(0,c)+r+v.slice(c+r.length)}if(void 0!==state.metadata.author)for(var d="by "+state.metadata.author,u=wordwrap(d,titleImage[0].length),l=0;l<u.length;l++){var g=u[l]+" ";g.length>i&&(g=g.slice(0,i));var v=titleImage[3+l];titleImage[3+l]=v.slice(0,i-g.length)+g}}function deepClone(e){if(!e)return e;var t,a=[Number,String,Boolean];if(a.forEach(function(a){e instanceof a&&(t=a(e))}),void 0===t)if("[object Array]"===Object.prototype.toString.call(e))t=[],e.forEach(function(e,a,n){t[a]=deepClone(e)});else if("object"==typeof e)if(e.nodeType&&"function"==typeof e.cloneNode)var t=e.cloneNode(!0);else if(e.prototype)t=e;else if(e instanceof Date)t=new Date(e);else{t={};for(var n in e)t[n]=deepClone(e[n])}else t=e;return t}function wordwrap(e,t){t=t||75;if(!e)return e;var a=".{1,"+t+"}(\\s|$)|.{"+t+"}|.+$";return e.match(RegExp(a,"g"))}function drawMessageScreen(){titleMode=0,textMode=!0,titleImage=deepClone(messagecontainer_template);for(var e=0;e<titleImage.length;e++)titleImage[e]=titleImage[e].replace(/\./g," ");var t=titleImage[9],a=titleImage[10];titleImage[10]=t;var n,l=titleImage[0].length;if(""===messagetext){n=state.levels[curlevel].message.trim()}else n=messagetext;splitMessage=wordwrap(n,titleImage[0].length);var i=5-(splitMessage.length/2|0);i<0&&(i=0);for(var o=Math.min(splitMessage.length,12),e=0;e<o;e++){var r=splitMessage[e],s=i+e,c=r.length,v=(l-c)/2|0,d=titleImage[s];titleImage[s]=d.slice(0,v)+r+d.slice(v+r.length)}quittingMessageScreen?titleImage[10]=t:o<10?titleImage[10]=a:o<12?titleImage[o+1]=a:titleImage[o]=a,canvasResize()}function loadLevelFromLevelDat(e,t,a){if(null==a&&(a=(Math.random()+Date.now()).toString()),loadedLevelSeed=a,RandomGen=new RNG(loadedLevelSeed),forceRegenImages=!0,titleScreen=!1,titleMode=curlevel>0||null!==curlevelTarget?1:0,titleSelection=curlevel>0||null!==curlevelTarget?1:0,titleSelected=!1,againing=!1,void 0===t)return void consolePrint("Trying to access a level that doesn't exist.",!0);void 0===t.message?(titleMode=0,textMode=!1,level=t.clone(),RebuildLevelArrays(),void 0!==e&&(void 0!==e.metadata.flickscreen?oldflickscreendat=[0,0,Math.min(e.metadata.flickscreen[0],level.width),Math.min(e.metadata.flickscreen[1],level.height)]:void 0!==e.metadata.zoomscreen&&(oldflickscreendat=[0,0,Math.min(e.metadata.zoomscreen[0],level.width),Math.min(e.metadata.zoomscreen[1],level.height)])),backups=[],restartTarget=backupLevel(),keybuffer=[],"run_rules_on_level_start"in e.metadata&&processInput(-1,!0)):(tryPlayShowMessageSound(),drawMessageScreen(),canvasResize()),clearInputHistory()}function loadLevelFromStateTarget(e,t,a,n){var l=a;curlevel=t,curlevelTarget=a,void 0===l.message&&tryPlayStartLevelSound(),loadLevelFromLevelDat(e,e.levels[t],n),restoreLevel(a),restartTarget=a}function loadLevelFromState(e,t,a){var n=e.levels[t];curlevel=t,curlevelTarget=null,void 0===n.message&&tryPlayStartLevelSound(),loadLevelFromLevelDat(e,n,a)}function tryPlaySimpleSound(e){if(void 0!==state.sfx_Events[e]){var t=state.sfx_Events[e];playSound(t)}}function tryPlayTitleSound(){tryPlaySimpleSound("titlescreen")}function tryPlayStartGameSound(){tryPlaySimpleSound("startgame")}function tryPlayEndGameSound(){tryPlaySimpleSound("endgame")}function tryPlayCancelSound(){tryPlaySimpleSound("cancel")}function tryPlayStartLevelSound(){tryPlaySimpleSound("startlevel")}function tryPlayEndLevelSound(){tryPlaySimpleSound("endlevel")}function tryPlayUndoSound(){tryPlaySimpleSound("undo")}function tryPlayRestartSound(){tryPlaySimpleSound("restart")}function tryPlayShowMessageSound(){tryPlaySimpleSound("showmessage")}function tryPlayCloseMessageSound(){tryPlaySimpleSound("closemessage")}function backupLevel(e){var t=level.clone();return t.oldflickscreendat=oldflickscreendat.concat([]),t.hadPlayerInput="undefined"!=e&&e,t}function level4Serialization(){var e=level.clone4Serialization();return e.oldflickscreendat=oldflickscreendat.concat([]),e}function setGameState(e,t,a){oldflickscreendat=[],timer=0,autotick=0,winning=!1,againing=!1,messageselected=!1,STRIDE_MOV=e.STRIDE_MOV,STRIDE_OBJ=e.STRIDE_OBJ,sfxCreateMask=new BitVec(STRIDE_OBJ),sfxDestroyMask=new BitVec(STRIDE_OBJ),void 0===t&&(t=["restart"]),0===state.levels.length&&t.length>0&&"rebuild"===t[0]&&(t=["restart"]),void 0===a&&(a=null),RandomGen=new RNG(a),state=e,window.console.log("setting game state :D "),"rebuild"!==t[0]&&(backups=[]),sprites=[];for(var n in state.objects)if(state.objects.hasOwnProperty(n)){var l=state.objects[n],i={colors:l.colors,dat:l.spritematrix,renderType:l.renderType,tween:l.tween};sprites[l.id]=i}switch(void 0!==state.metadata.realtime_interval?(autotick=0,autotickinterval=1e3*state.metadata.realtime_interval):(autotick=0,autotickinterval=0),void 0!==state.metadata.view_pitch?viewPitch=state.metadata.view_pitch*Math.PI/180:viewPitch=0,void 0!==state.metadata.scale_height?scaleHeight=parseFloat(state.metadata.scale_height):scaleHeight=1,void 0!==state.metadata.view_distance?viewDistance=parseFloat(state.metadata.view_distance):viewDistance=10,void 0!==state.metadata.view_height?viewHeight=state.metadata.view_height:viewHeight=.5,void 0!==state.metadata.field_of_view?fieldOfView=state.metadata.field_of_view:fieldOfView=60,void 0!==state.metadata.fog_power?fogPower=state.metadata.fog_power:fogPower=2,void 0!==state.metadata.gradient_bottom?gradientBottom=colorToHex(colorPalette,state.metadata.gradient_bottom):gradientBottom="#dfdfdf",void 0!==state.metadata.gradient_middle?gradientMiddle=colorToHex(colorPalette,state.metadata.gradient_middle):gradientMiddle="#ffffff",void 0!==state.metadata.gradient_top?gradientTop=colorToHex(colorPalette,state.metadata.gradient_top):gradientTop="#cfcfcf",void 0!==state.metadata.key_repeat_interval?repeatinterval=1e3*state.metadata.key_repeat_interval:repeatinterval=250,void 0!==state.metadata.again_interval?againinterval=1e3*state.metadata.again_interval:againinterval=250,void 0!==state.metadata.interpolation_interval?interpolationInterval=1e3*state.metadata.interpolation_interval:(interpolationInterval=Math.min(repeatinterval>0?repeatinterval:250,againinterval>0?againinterval:250),autotickinterval>0&&(interpolationInterval=Math.min(interpolationInterval,autotickinterval))),throttle_movement&&0===autotickinterval&&logWarning("throttle_movement is designed for use in conjunction with realtime_interval. Using it in other situations makes games gross and unresponsive, broadly speaking.  Please don't."),norepeat_action=void 0!==state.metadata.norepeat_action,t[0]){case"restart":if(1==restarting){logWarning('A "restart" command is being triggered in the "run_rules_on_level_start" section of level creation, which would cause an infinite loop if it was actually triggered, but it\'s being ignored, so it\'s not.');break}winning=!1,timer=0,titleScreen=!0,tryPlayTitleSound(),textMode=!0,titleSelection=curlevel>0||null!==curlevelTarget?1:0,titleSelected=!1,quittingMessageScreen=!1,quittingTitleScreen=!1,messageselected=!1,titleMode=0,(curlevel>0||null!==curlevelTarget)&&(titleMode=1),generateTitleScreen();break;case"rebuild":break;case"loadLevel":var o=t[1];curlevel=s,winning=!1,timer=0,titleScreen=!1,textMode=!1,titleSelection=curlevel>0||null!==curlevelTarget?1:0,titleSelected=!1,quittingMessageScreen=!1,quittingTitleScreen=!1,messageselected=!1,titleMode=0,loadLevelFromState(state,o,a);break;case"levelline":for(var r=t[1],s=state.levels.length-1;s>=0;s--){if(state.levels[s].lineNumber<=r+1){curlevel=s,winning=!1,timer=0,titleScreen=!1,textMode=!1,titleSelection=curlevel>0||null!==curlevelTarget?1:0,titleSelected=!1,quittingMessageScreen=!1,quittingTitleScreen=!1,messageselected=!1,titleMode=0,loadLevelFromState(state,s);break}}}if("rebuild"!==t[0]&&clearInputHistory(),canvasResize(),canYoutube&&"youtube"in state.metadata){var c=state.metadata.youtube,v="https://www.youtube.com/embed/"+c+"?autoplay=1&loop=1&playlist="+c;ifrm=document.createElement("IFRAME"),ifrm.setAttribute("src",v),ifrm.style.visibility="hidden",ifrm.style.width="500px",ifrm.style.height="500px",ifrm.style.position="absolute",ifrm.style.top="-1000px",ifrm.style.left="-1000px",document.body.appendChild(ifrm)}}function RebuildLevelArrays(){level.movements=new Int32Array(level.n_tiles*STRIDE_MOV),level.motions=new Int32Array(level.n_tiles*STRIDE_MOV),level.noActionMotions=new Int32Array(level.n_tiles*STRIDE_MOV),level.rigidMovementAppliedMask=[],level.rigidGroupIndexMask=[],level.rowCellContents=[],level.colCellContents=[],level.mapCellContents=new BitVec(STRIDE_OBJ),_movementVecs=[new BitVec(STRIDE_MOV),new BitVec(STRIDE_MOV),new BitVec(STRIDE_MOV)],_o1=new BitVec(STRIDE_OBJ),_o2=new BitVec(STRIDE_OBJ),_o2_5=new BitVec(STRIDE_OBJ),_o3=new BitVec(STRIDE_OBJ),_o4=new BitVec(STRIDE_OBJ),_o5=new BitVec(STRIDE_OBJ),_o6=new BitVec(STRIDE_OBJ),_o7=new BitVec(STRIDE_OBJ),_o8=new BitVec(STRIDE_OBJ),_o9=new BitVec(STRIDE_OBJ),_o10=new BitVec(STRIDE_OBJ),_o11=new BitVec(STRIDE_OBJ),_o12=new BitVec(STRIDE_OBJ),_m1=new BitVec(STRIDE_MOV),_m2=new BitVec(STRIDE_MOV),_m3=new BitVec(STRIDE_MOV),_mo1=new BitVec(STRIDE_MOV),_mo2=new BitVec(STRIDE_MOV);for(var e=0;e<level.height;e++)level.rowCellContents[e]=new BitVec(STRIDE_OBJ);for(var e=0;e<level.width;e++)level.colCellContents[e]=new BitVec(STRIDE_OBJ);for(var e=0;e<level.n_tiles;e++)level.rigidMovementAppliedMask[e]=new BitVec(STRIDE_MOV),level.rigidGroupIndexMask[e]=new BitVec(STRIDE_MOV)}function restoreLevel(e){if(oldflickscreendat=e.oldflickscreendat.concat([]),level.objects=new Int32Array(e.objects),level.motions=new Int32Array(e.motions),level.noActionMotions=new Int32Array(e.noActionMotions),level.facing=e.facing,level.width!==e.width||level.height!==e.height)level.width=e.width,level.height=e.height,level.n_tiles=e.width*e.height,RebuildLevelArrays();else{for(var t=0;t<level.n_tiles;t++)level.movements[t]=0,level.rigidMovementAppliedMask[t]=0,level.rigidGroupIndexMask[t]=0;for(var t=0;t<level.height;t++){level.rowCellContents[t].setZero()}for(var t=0;t<level.width;t++){level.colCellContents[t].setZero()}}againing=!1,level.commandQueue=[]}function DoRestart(e){!0!==restarting&&(restarting=!0,!0!==e&&"norestart"in state.metadata||(!1===e&&backups.push(backupLevel()),verbose_logging&&consolePrint("--- restarting ---",!0),restoreLevel(restartTarget),tryPlayRestartSound(),"run_rules_on_level_start"in state.metadata&&processInput(-1,!0),level.commandQueue=[],restarting=!1))}function backupDiffers(){if(0==backups.length)return!0;for(var e=backups[backups.length-1],t=0;t<level.objects.length;t++)if(level.objects[t]!==e.objects[t])return!0;for(var t=0;t<level.motions.length;t++)if(level.motions[t]!==e.motions[t])return!0;return level.facing[0]!=e.facing[0]||level.facing[1]!=e.facing[1]}function backupIsManualUndoTarget(){return 0==backups.length||backups[backups.length-1].hadPlayerInput}function DoUndo(e,t){if(levelEditorOpened||!("noundo"in state.metadata)||!0===e){if(verbose_logging&&consolePrint("--- undoing ---",!0),t)for(;0==backupIsManualUndoTarget();)backups.pop();if(backups.length>0){restoreLevel(backups[backups.length-1]),backups=backups.splice(0,backups.length-1),e||tryPlayUndoSound()}}}function getPlayerPositions(){var e=[],t=state.playerMask;for(i=0;i<level.n_tiles;i++)level.getCellInto(i,_o11),t.anyBitsInCommon(_o11)&&e.push(i);return e}function getLayersOfMask(e){for(var t=[],a=0;a<state.objectCount;a++)if(e.get(a)){var n=state.idDict[a],l=state.objects[n];t.push(l.layer)}return t}function moveEntitiesAtIndex(e,t,a){var n=level.getCell(e);n.iand(t);for(var l=getLayersOfMask(n),i=level.getMovements(e),o=0;o<l.length;o++)i.ishiftor(a,5*l[o]);level.setMovements(e,i)}function startMovement(e){for(var t=getPlayerPositions(),a=0;a<t.length;a++){moveEntitiesAtIndex(t[a],state.playerMask,e)}return t}function repositionEntitiesOnLayer(e,t,a){var n=dirMasksDelta[a],l=n[0],i=n[1],o=e/level.height|0,r=e%level.height,s=level.width-1,c=level.height-1;if(0===o&&l<0||o===s&&l>0||0===r&&i<0||r===c&&i>0)return!1;var v=e+n[1]+n[0]*level.height,d=state.layerMasks[t],u=level.getCellInto(v,_o7),g=level.getCellInto(e,_o8);if(d.anyBitsInCommon(u)&&16!=a)return!1;for(var m=0;m<state.sfx_MovementMasks.length;m++){var h=state.sfx_MovementMasks[m];if(h.objectMask.anyBitsInCommon(g)){var f=level.getMovements(e),p=h.directionMask;f.anyBitsInCommon(p)&&-1===seedsToPlay_CanMove.indexOf(h.seed)&&seedsToPlay_CanMove.push(h.seed)}}var _=g.clone();g.iclear(d),_.iand(d),u.ior(_),level.setCell(e,g),level.setCell(v,u);var M=level.getNoActionMotions(v);M.ishiftclear(dirMasks.all,5*t),M.ishiftor(a,5*t),M.ishiftclear(dirMasks.action,5*t);var y=level.getMotions(v);y.ishiftclear(dirMasks.all,5*t),y.ishiftor(a,5*t),y.ishiftor(dirMasks.action,5*t),level.setMotions(v,M,y);var S=v/level.height|0,I=v%level.height;return level.colCellContents[S].ior(_),level.rowCellContents[I].ior(_),level.mapCellContents.ior(_),!0}function repositionEntitiesAtCell(e){var t=level.getMovements(e);if(t.iszero())return!1;for(var a=!1,n=0;n<level.layerCount;n++){var l=t.getshiftor(31,5*n);if(0!==l){repositionEntitiesOnLayer(e,n,l)&&(t.ishiftclear(l,5*n),a=!0)}}return level.setMovements(e,t),a}function Level(e,t,a,n,l){this.lineNumber=e,this.width=t,this.height=a,this.n_tiles=t*a,this.objects=l,this.layerCount=n,this.commandQueue=[],this.facing=[0,-1]}function BitVec(e){return this.data=new Int32Array(e),this}function Rule(e){this.direction=e[0],this.patterns=e[1],this.hasReplacements=e[2],this.lineNumber=e[3],this.isEllipsis=e[4],this.groupNumber=e[5],this.isRigid=e[6],this.commands=e[7],this.isRandom=e[8],this.isViewDir=e[9],this.cellRowMasks=e[10],this.cellRowMatches=[];for(var t=0;t<this.patterns.length;t++)this.cellRowMatches.push(this.generateCellRowMatchesFunction(this.patterns[t],this.isEllipsis[t]))}function CellPattern(e){this.objectsPresent=e[0],this.objectsMissing=e[1],this.anyObjectsPresent=e[2],this.movementsPresent=e[3],this.movementsMissing=e[4],this.matches=this.generateMatchFunction(),this.replacement=e[5]}function CellReplacement(e){this.objectsClear=e[0],this.objectsSet=e[1],this.movementsClear=e[2],this.movementsSet=e[3],this.movementsLayerMask=e[4],this.randomEntityMask=e[5],this.randomDirMask=e[6]}function DoesCellRowMatchWildCard(e,t,a,n,l){void 0===l&&(l=0);var i=t[0];if(i.matches(a))for(var o=dirMasksDelta[e],r=o[0]*level.height,s=o[1],c=a,v=1;v<t.length;v+=1){c=c+s+r;var i=t[v];if(i===ellipsisPattern){for(var d=l;d<n;d++){var u=c;u=(u+(s+r)*d+level.n_tiles)%level.n_tiles;for(var g=v+1;g<t.length&&(i=t[g],i.matches(u));g++)u=u+s+r;if(g>=t.length)return!0}break}if(!i.matches(c))break}return!1}function DoesCellRowMatch(e,t,a,n){var l=t[0];if(l.matches(a)){for(var i=dirMasksDelta[e],o=i[0]*level.height,r=i[1],s=t.length,c=a,v=1;v<s&&(c=c+r+o,l=t[v],l===ellipsisPattern&&(c+=(r+o)*n),l.matches(c));v++);if(v>=t.length)return!0}return!1}function matchCellRow(e,t,a,n){var l=[];if(!n.bitsSetInArray(level.mapCellContents.data))return l;var i=0,o=level.width,r=0,s=level.height,c=a.length;switch(e){case 1:r+=c-1;break;case 2:s-=c-1;break;case 4:i+=c-1;break;case 8:o-=c-1;break;default:window.console.log("EEEP "+e)}if(e>2){for(var v=r;v<s;v++)if(n.bitsSetInArray(level.rowCellContents[v].data))for(var d=i;d<o;d++){var u=d*level.height+v;t(a,u)&&l.push(u)}}else for(var d=i;d<o;d++)if(n.bitsSetInArray(level.colCellContents[d].data))for(var v=r;v<s;v++){var u=d*level.height+v;t(a,u)&&l.push(u)}return l}function matchCellRowWildCard(e,t,a,n){var l=[];if(!n.bitsSetInArray(level.mapCellContents.data))return l;var i=0,o=level.width,r=0,s=level.height,c=a.length-1;switch(e){case 1:r+=c-1;break;case 2:s-=c-1;break;case 4:i+=c-1;break;case 8:o-=c-1;break;default:window.console.log("EEEP2 "+e)}if(e>2){for(var v=r;v<s;v++)if(n.bitsSetInArray(level.rowCellContents[v].data))for(var d=i;d<o;d++){var u,g=d*level.height+v;4===e?u=d-c+2:8===e?u=level.width-(d+c)+1:window.console.log("EEEP2 "+e),l.push.apply(l,t(a,g,u,0))}}else for(var d=i;d<o;d++)if(n.bitsSetInArray(level.colCellContents[d].data))for(var v=r;v<s;v++){var u,g=d*level.height+v;2===e?u=level.height-(v+c)+1:1===e?u=v-c+2:window.console.log("EEEP2 "+e),l.push.apply(l,t(a,g,u,0))}return l}function generateTuples(e){for(var t=[[]],a=0;a<e.length;a++){for(var n=e[a],l=[],i=0;i<n.length;i++)for(var o=n[i],r=0;r<t.length;r++){var s=t[r],c=s.concat([o]);l.push(c)}t=l}return t}function commitPreservationState(e){var t={ruleGroupIndex:e,objects:new Int32Array(level.objects),movements:new Int32Array(level.movements),rigidGroupIndexMask:level.rigidGroupIndexMask.concat([]),rigidMovementAppliedMask:level.rigidMovementAppliedMask.concat([]),bannedGroup:level.bannedGroup.concat([]),commandQueue:level.commandQueue.concat([])};return rigidBackups[e]=t,t}function restorePreservationState(e){level.objects=new Int32Array(e.objects),level.movements=new Int32Array(e.movements),level.rigidGroupIndexMask=e.rigidGroupIndexMask.concat([]),level.rigidMovementAppliedMask=e.rigidMovementAppliedMask.concat([]),level.commandQueue=e.commandQueue.concat([]),sfxCreateMask.setZero(),sfxDestroyMask.setZero(),consolePrint("Rigid movement application failed, rolling back")}function showTempMessage(){keybuffer=[],textMode=!0,titleScreen=!1,quittingMessageScreen=!1,messageselected=!1,tryPlayShowMessageSound(),drawMessageScreen(),canvasResize()}function applyRandomRuleGroup(e){for(var t=[],a=0;a<e.length;a++){var n=e[a],l=n.findMatches();if(l.length>0)for(var i=generateTuples(l),o=0;o<i.length;o++){var r=i[o];t.push([a,r])}}if(0===t.length)return!1;var s=t[Math.floor(RandomGen.uniform()*t.length)],a=s[0],n=e[a],c=dirMasksDelta[n.direction],r=s[1],v=n.applyAt(c,r,!1);return n.queueCommands(),v}function applyRuleGroup(e){if(e[0].isRandom)return applyRandomRuleGroup(e);for(var t=!1,a=!0,n=0;a;){if(++n>200){logErrorCacheable("Got caught looping lots in a rule group :O",e[0].lineNumber,!0);break}a=!1;for(var l=0;l<e.length;l++){a=e[l].tryApply()||a}a&&(t=!0)}return t}function applyRules(e,t,a,n){for(var l=a>0,i=0,o=a;o<e.length;){if(n&&n[o]);else{var r=e[o];l=applyRuleGroup(r)||l}if(l&&void 0!==t[o]){if(o=t[o],l=!1,++i>200){var r=e[o];logErrorCacheable("got caught in an endless startloop...endloop vortex, escaping!",r[0].lineNumber,!0);break}}else if(++o===e.length&&l&&void 0!==t[o]&&(o=t[o],l=!1,++i>200)){var r=e[o];logErrorCacheable("got caught in an endless startloop...endloop vortex, escaping!",r[0].lineNumber,!0);break}}}function resolveMovements(e){for(var t=!0;t;){t=!1;for(var a=0;a<level.n_tiles;a++)t=repositionEntitiesAtCell(a)||t}for(var n=!1,a=0;a<level.n_tiles;a++){var l=level.getCellInto(a,_o6),i=level.getMovements(a);if(!i.iszero()){var o=level.rigidMovementAppliedMask[a];if(0!==o&&(i.iand(o),!i.iszero()))for(var r=0;r<level.layerCount;r++){var s=i.getshiftor(31,5*r);if(0!==s){var c=level.rigidGroupIndexMask[a],v=c.getshiftor(31,5*r);v--;var d=state.rigidGroupIndex_to_GroupIndex[v];level.bannedGroup[d]=!0,n=!0;break}}for(var r=0;r<state.sfx_MovementFailureMasks.length;r++){var u=state.sfx_MovementFailureMasks[r];if(u.objectMask.anyBitsInCommon(l)){var g=u.directionMask;i.anyBitsInCommon(g)&&-1===seedsToPlay_CantMove.indexOf(u.seed)&&seedsToPlay_CantMove.push(u.seed)}}}for(var r=0;r<STRIDE_MOV;r++)level.movements[r+a*STRIDE_MOV]=0;level.rigidGroupIndexMask[a]=0,level.rigidMovementAppliedMask[a]=0}return n}function calculateRowColMasks(){for(var e=0;e<level.mapCellContents.length;e++)level.mapCellContents[e]=0;for(var e=0;e<level.width;e++){level.colCellContents[e].setZero()}for(var e=0;e<level.height;e++){level.rowCellContents[e].setZero()}for(var e=0;e<level.width;e++)for(var t=0;t<level.height;t++){var a=t+e*level.height,n=level.getCellInto(a,_o9);level.mapCellContents.ior(n),level.rowCellContents[t].ior(n),level.colCellContents[e].ior(n)}}function processInput(e,t,a){againing=!1,verbose_logging&&(-1===e?consolePrint("Turn starts with no input."):(consolePrint("======================="),consolePrint("Turn starts with input of "+["up","left","down","right","action"][e]+".")));var n=backupLevel(e>=0&&e<=6);level.motions.set(level.noActionMotions,0);var l=[];if(e<=6){if(e>=0){switch(e){case 0:-1==level.facing[1]?e=parseInt("00001",2):-1==level.facing[0]?e=parseInt("00100",2):1==level.facing[1]?e=parseInt("00010",2):1==level.facing[0]&&(e=parseInt("01000",2));break;case 1:return level.facing=[level.facing[1],-level.facing[0]],backups.push(n),!0;case 2:1==level.facing[1]?e=parseInt("00001",2):1==level.facing[0]?e=parseInt("00100",2):-1==level.facing[1]?e=parseInt("00010",2):-1==level.facing[0]&&(e=parseInt("01000",2));break;case 3:return level.facing=[-level.facing[1],level.facing[0]],backups.push(n),!0;case 4:e=parseInt("10000",2);break;case 5:1==level.facing[0]?e=parseInt("00001",2):-1==level.facing[1]?e=parseInt("00100",2):-1==level.facing[0]?e=parseInt("00010",2):1==level.facing[1]&&(e=parseInt("01000",2));break;case 6:-1==level.facing[0]?e=parseInt("00001",2):1==level.facing[1]?e=parseInt("00100",2):1==level.facing[0]?e=parseInt("00010",2):-1==level.facing[1]&&(e=parseInt("01000",2))}l=startMovement(e)}var i=0;level.bannedGroup=[],rigidBackups=[],level.commandQueue=[];var o=0,r=!1,s=commitPreservationState();sfxCreateMask.setZero(),sfxDestroyMask.setZero(),seedsToPlay_CanMove=[],seedsToPlay_CantMove=[],calculateRowColMasks();do{r=!1,i++,verbose_logging&&consolePrint("applying rules"),applyRules(state.rules,state.loopPoint,o,level.bannedGroup);resolveMovements()?(r=!0,restorePreservationState(s),o=0):(verbose_logging&&consolePrint("applying late rules"),applyRules(state.lateRules,state.lateLoopPoint,0),o=0)}while(i<50&&r);if(i>=50&&consolePrint("looped through 50 times, gave up.  too many loops!"),l.length>0&&void 0!==state.metadata.require_player_movement){for(var c=!1,i=0;i<l.length;i++){var v=l[i],d=level.getCell(v);if(state.playerMask.bitsClearInArray(d.data)){c=!0;break}}if(!1===c)return verbose_logging&&(consolePrint("require_player_movement set, but no player movement detected, so cancelling turn."),consoleCacheDump()),backups.push(n),DoUndo(!0,!1),!1}if(level.commandQueue.indexOf("cancel")>=0)return verbose_logging&&(consoleCacheDump(),consolePrint("CANCEL command executed, cancelling turn.",!0)),backups.push(n),DoUndo(!0,!1),tryPlayCancelSound(),!1;if(level.commandQueue.indexOf("restart")>=0)return verbose_logging&&(consolePrint("RESTART command executed, reverting to restart state."),consoleCacheDump()),backups.push(n),DoRestart(!0),!0;if(a&&level.commandQueue.indexOf("win")>=0)return!0;for(var u=!1,i=0;i<level.objects.length;i++)if(level.objects[i]!==n.objects[i]){if(a)return verbose_logging&&consoleCacheDump(),backups.push(n),DoUndo(!0,!1),!0;backups.push(n),u=!0;break}if(a)return verbose_logging&&consoleCacheDump(),level.motions=n.motions,level.noActionMotions=n.noActionMotions,!1;for(var i=0;i<seedsToPlay_CantMove.length;i++)playSound(seedsToPlay_CantMove[i]);for(var i=0;i<seedsToPlay_CanMove.length;i++)playSound(seedsToPlay_CanMove[i]);for(var i=0;i<state.sfx_CreationMasks.length;i++){var g=state.sfx_CreationMasks[i];sfxCreateMask.anyBitsInCommon(g.objectMask)&&playSound(g.seed)}for(var i=0;i<state.sfx_DestructionMasks.length;i++){var g=state.sfx_DestructionMasks[i];sfxDestroyMask.anyBitsInCommon(g.objectMask)&&playSound(g.seed)}for(var i=0;i<level.commandQueue.length;i++){var m=level.commandQueue[i];"f"===m.charAt(1)&&tryPlaySimpleSound(m),!1===unitTesting&&"message"===m&&showTempMessage()}if(!1!==textMode||void 0!==t&&!1!==t||(verbose_logging&&consolePrint("Checking win condition."),checkWin()),!winning){if(level.commandQueue.indexOf("checkpoint")>=0){verbose_logging&&consolePrint("CHECKPOINT command executed, saving current state to the restart state."),restartTarget=level4Serialization(),hasUsedCheckpoint=!0;var h=JSON.stringify(restartTarget);localStorage[document.URL+"_checkpoint"]=h,localStorage[document.URL]=curlevel}if(level.commandQueue.indexOf("again")>=0&&u){var f=verbose_logging,p=messagetext;verbose_logging=!1,processInput(-1,!0,!0)?(verbose_logging=f,verbose_logging&&consolePrint("AGAIN command executed, with changes detected - will execute another turn."),againing=!0,timer=0):(verbose_logging=f,verbose_logging&&consolePrint("AGAIN command not executed, it wouldn't make any changes.")),verbose_logging=f,messagetext=p}}level.commandQueue=[]}return verbose_logging&&consoleCacheDump(),winning&&(againing=!1),0==u&&(level.motions=n.motions,level.noActionMotions=n.noActionMotions),u}function checkWin(){if(!levelEditorOpened){if(level.commandQueue.indexOf("win")>=0)return consolePrint("Win Condition Satisfied"),void DoWin();var e=!1;if(state.winconditions.length>0){for(var t=!0,a=0;a<state.winconditions.length;a++){var n=state.winconditions[a],l=n[1],i=n[2],o=!0;switch(n[0]){case-1:for(var r=0;r<level.n_tiles;r++){var s=level.getCellInto(r,_o10);if(!l.bitsClearInArray(s.data)&&!i.bitsClearInArray(s.data)){o=!1;break}}break;case 0:for(var c=!1,r=0;r<level.n_tiles;r++){var s=level.getCellInto(r,_o10);if(!l.bitsClearInArray(s.data)&&!i.bitsClearInArray(s.data)){c=!0;break}}!1===c&&(o=!1);break;case 1:for(var r=0;r<level.n_tiles;r++){var s=level.getCellInto(r,_o10);if(!l.bitsClearInArray(s.data)&&i.bitsClearInArray(s.data)){o=!1;break}}}!1===o&&(t=!1)}e=t}e&&(consolePrint("Win Condition Satisfied"),DoWin())}}function DoWin(){if(!winning){if(againing=!1,tryPlayEndLevelSound(),unitTesting)return void nextLevel();winning=!0,timer=0}}function nextLevel(){if(againing=!1,messagetext="",state&&state.levels&&curlevel>state.levels.length&&(curlevel=state.levels.length-1),titleScreen)0===titleSelection&&(curlevel=0,curlevelTarget=null),null!==curlevelTarget?loadLevelFromStateTarget(state,curlevel,curlevelTarget):loadLevelFromState(state,curlevel);else if(hasUsedCheckpoint&&(curlevelTarget=null,hasUsedCheckpoint=!1),curlevel<state.levels.length-1)curlevel++,textMode=!1,titleScreen=!1,quittingMessageScreen=!1,messageselected=!1,null!==curlevelTarget?loadLevelFromStateTarget(state,curlevel,curlevelTarget):loadLevelFromState(state,curlevel);else{if(window.localStorage)try{localStorage.removeItem(document.URL),localStorage.removeItem(document.URL+"_checkpoint")}catch(e){}curlevel=0,curlevelTarget=null,goToTitleScreen(),tryPlayEndGameSound()}try{if(window.localStorage)if(localStorage[document.URL]=curlevel,null!==curlevelTarget){restartTarget=level4Serialization();var e=JSON.stringify(restartTarget);localStorage[document.URL+"_checkpoint"]=e}else localStorage.removeItem(document.URL+"_checkpoint")}catch(e){}void 0!==state&&void 0!==state.metadata.flickscreen&&(oldflickscreendat=[0,0,Math.min(state.metadata.flickscreen[0],level.width),Math.min(state.metadata.flickscreen[1],level.height)]),canvasResize(),clearInputHistory()}function goToTitleScreen(){againing=!1,messagetext="",titleScreen=!0,textMode=!0,doSetupTitleScreenLevelContinue(),titleSelection=curlevel>0||null!==curlevelTarget?1:0,generateTitleScreen()}
var RandomGen=new RNG,intro_template=["..................................","..................................","..................................","......Puzzle Script Terminal......","..............v 1.0...............","..................................","..................................","..................................",".........insert cartridge.........","..................................","..................................","..................................",".................................."],messagecontainer_template=["..................................","..................................","..................................","..................................","..................................","..................................","..................................","..................................","..................................","..................................","........SPACE to continue.........","..................................",".................................."],titletemplate_firstgo=["..................................","..................................","..................................","..................................","..................................","..................................","..........#.start game.#..........","..................................","..................................",".WASD to move, arrows to turn.....",".SPACE to action..................",".Z to undo, R to restart..........",".................................."],titletemplate_select0=["..................................","..................................","..................................","..................................","..................................","...........#.new game.#...........","..................................",".............continue.............","..................................",".WASD to move, arrows to turn.....",".SPACE to action..................",".Z to undo, R to restart..........",".................................."],titletemplate_select1=["..................................","..................................","..................................","..................................","..................................",".............new game.............","..................................","...........#.continue.#...........","..................................",".WASD to move, arrows to turn.....",".SPACE to action..................",".Z to undo, R to restart..........",".................................."],titletemplate_firstgo_selected=["..................................","..................................","..................................","..................................","..................................","..................................","###########.start game.###########","..................................","..................................",".WASD to move, arrows to turn.....",".SPACE to action..................",".Z to undo, R to restart..........",".................................."],titletemplate_select0_selected=["..................................","..................................","..................................","..................................","..................................","############.new game.############","..................................",".............continue.............","..................................",".WASD to move, arrows to turn.....",".SPACE to action..................",".Z to undo, R to restart..........",".................................."],titletemplate_select1_selected=["..................................","..................................","..................................","..................................","..................................",".............new game.............","..................................","############.continue.############","..................................",".WASD to move, arrows to turn.....",".SPACE to action..................",".Z to undo, R to restart..........",".................................."],titleImage=[],titleWidth=titletemplate_select1[0].length,titleHeight=titletemplate_select1.length,textMode=!0,titleScreen=!0,titleMode=0,titleSelection=0,titleSelected=!1,introstate={title:"2D Whale World",attribution:"increpare",objectCount:2,metadata:[],levels:[],bgcolor:"#000000",fgcolor:"#FFFFFF"},state=introstate,splitMessage=[],loadedLevelSeed=0,sprites=[{color:"#423563",dat:[[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1]]},{color:"#252342",dat:[[0,0,1,0,0],[1,1,1,1,1],[0,0,1,0,0],[0,1,1,1,0],[0,1,0,1,0]]}];generateTitleScreen(),titleMode>0&&(titleSelection=1),canvasResize();var backups=[],restartTarget,display=[],messagetext="",zoomscreen=!1,flickscreen=!1,screenwidth=0,screenheight=0,dirMasksDelta={1:[0,-1],2:[0,1],4:[-1,0],8:[1,0],15:[0,0],16:[0,0],3:[0,0]},dirMaskName={1:"up",2:"down",4:"left",8:"right",15:"?",16:"action",3:"no"},seedsToPlay_CanMove=[],seedsToPlay_CantMove=[];Level.prototype.clone4Serialization=function(){var e=new Level(this.lineNumber,this.width,this.height,this.layerCount,null);return e.objects=Array.from(this.objects),e.motions=Array.from(this.motions),e.noActionMotions=Array.from(this.noActionMotions),e.facing=this.facing.slice(0),e},Level.prototype.clone=function(){var e=new Level(this.lineNumber,this.width,this.height,this.layerCount,null);return e.objects=new Int32Array(this.objects),e.motions=new Int32Array(this.motions),e.noActionMotions=new Int32Array(this.noActionMotions),e.facing=this.facing.slice(0),e},Level.prototype.getPlayerPositions=function(){var e=[],t=state.playerMask;for(i=0;i<this.n_tiles;i++)this.getCellInto(i,_o11),t.anyBitsInCommon(_o11)&&e.push(i);return e},Level.prototype.getCell=function(e){return new BitVec(this.objects.subarray(e*STRIDE_OBJ,e*STRIDE_OBJ+STRIDE_OBJ))},Level.prototype.getCellInto=function(e,t){for(var a=0;a<STRIDE_OBJ;a++)t.data[a]=this.objects[e*STRIDE_OBJ+a];return t},Level.prototype.setCell=function(e,t){for(var a=0;a<t.data.length;++a)this.objects[e*STRIDE_OBJ+a]=t.data[a]};var _movementVecs,_movementVecIndex=0;Level.prototype.getMovements=function(e){var t=_movementVecs[_movementVecIndex];_movementVecIndex=(_movementVecIndex+1)%_movementVecs.length;for(var a=0;a<STRIDE_MOV;a++)t.data[a]=this.movements[e*STRIDE_MOV+a];return t},Level.prototype.setMovements=function(e,t){for(var a=0;a<t.data.length;++a)this.movements[e*STRIDE_MOV+a]=t.data[a]},Level.prototype.getMotions=function(e){for(var t=0;t<STRIDE_MOV;t++)_mo1.data[t]=this.motions[e*STRIDE_MOV+t];return _mo1},Level.prototype.getNoActionMotions=function(e){for(var t=0;t<STRIDE_MOV;t++)_mo2.data[t]=this.noActionMotions[e*STRIDE_MOV+t];return _mo2},Level.prototype.setMotions=function(e,t,a){for(var n=0;n<t.data.length;++n)this.noActionMotions[e*STRIDE_MOV+n]=t.data[n],this.motions[e*STRIDE_MOV+n]=a.data[n]};var ellipsisPattern=["ellipsis"];BitVec.prototype.cloneInto=function(e){for(var t=0;t<this.data.length;++t)e.data[t]=this.data[t];return e},BitVec.prototype.clone=function(){return new BitVec(this.data)},BitVec.prototype.iand=function(e){for(var t=0;t<this.data.length;++t)this.data[t]&=e.data[t]},BitVec.prototype.ior=function(e){for(var t=0;t<this.data.length;++t)this.data[t]|=e.data[t]},BitVec.prototype.iclear=function(e){for(var t=0;t<this.data.length;++t)this.data[t]&=~e.data[t]},BitVec.prototype.ibitset=function(e){this.data[e>>5]|=1<<(31&e)},BitVec.prototype.ibitclear=function(e){this.data[e>>5]&=~(1<<(31&e))},BitVec.prototype.get=function(e){return 0!=(this.data[e>>5]&1<<(31&e))},BitVec.prototype.getshiftor=function(e,t){var a=31&t,n=this.data[t>>5]>>>a;return a&&(n|=this.data[1+(t>>5)]<<32-a),n&e},BitVec.prototype.ishiftor=function(e,t){var a=31&t,n=e<<a;if(this.data[t>>5]|=n,a){var l=e>>32-a;this.data[1+(t>>5)]|=l}},BitVec.prototype.ishiftclear=function(e,t){var a=31&t,n=e<<a;if(this.data[t>>5]&=~n,a){var l=e>>32-(31&t);this.data[1+(t>>5)]&=~l}},BitVec.prototype.equals=function(e){if(this.data.length!==e.data.length)return!1;for(var t=0;t<this.data.length;++t)if(this.data[t]!==e.data[t])return!1;return!0},BitVec.prototype.setZero=function(){for(var e=0;e<this.data.length;++e)this.data[e]=0},BitVec.prototype.iszero=function(){for(var e=0;e<this.data.length;++e)if(this.data[e])return!1;return!0},BitVec.prototype.bitsSetInArray=function(e){for(var t=0;t<this.data.length;++t)if((this.data[t]&e[t])!==this.data[t])return!1;return!0},BitVec.prototype.bitsClearInArray=function(e){for(var t=0;t<this.data.length;++t)if(this.data[t]&e[t])return!1;return!0},BitVec.prototype.anyBitsInCommon=function(e){return!this.bitsClearInArray(e.data)},Rule.prototype.generateCellRowMatchesFunction=function(e,t){if(0==t){for(var a=dirMasksDelta[this.direction],n=a[0],l=a[1],i=e.length,o="var d = "+l+"+"+n+"*level.height;\n",r=1===STRIDE_OBJ?"":"*"+STRIDE_OBJ,s=0;s<STRIDE_OBJ;++s)o+="var cellObjects"+s+" = level.objects[i"+r+(s?"+"+s:"")+"];\n";r=1===STRIDE_MOV?"":"*"+STRIDE_MOV;for(var s=0;s<STRIDE_MOV;++s)o+="var cellMovements"+s+" = level.movements[i"+r+(s?"+"+s:"")+"];\n";o+="return "+e[0].generateMatchString("0_");for(var c=1;c<i;c++)o+="&&cellRow["+c+"].matches((i+"+c+"*d))";return o+=";",o in matchCache?matchCache[o]:matchCache[o]=new Function("cellRow","i",o)}var a=dirMasksDelta[this.direction],n=a[0],l=a[1],i=e.length,o="var d = "+l+"+"+n+"*level.height;\n";o+="var result = [];\n",o+="if(cellRow[0].matches(i)";for(var c=1;e[c]!==ellipsisPattern;c++)o+="&&cellRow["+c+"].matches((i+"+c+"*d))";for(c++,o+=") {\n",o+="\tfor (var k=kmin;k<kmax;k++) {\n",o+="\t\tif(cellRow["+c+"].matches((i+d*(k+"+(c-1)+")))",c++;c<i;c++)o+="&&cellRow["+c+"].matches((i+d*(k+"+(c-1)+")))";return o+="){\n",o+="\t\t\tresult.push([i,k]);\n",o+="\t\t}\n",o+="\t}\n",o+="}\n",o+="return result;",o in matchCache?matchCache[o]:matchCache[o]=new Function("cellRow","i","kmax","kmin",o)},Rule.prototype.toJSON=function(){return[this.direction,this.patterns,this.hasReplacements,this.lineNumber,this.isEllipsis,this.groupNumber,this.isRigid,this.commands,this.isRandom,this.isViewDir,this.cellRowMasks]};var STRIDE_OBJ=1,STRIDE_MOV=1,matchCache={};CellPattern.prototype.generateMatchString=function(){for(var e="(true",t=0;t<Math.max(STRIDE_OBJ,STRIDE_MOV);++t){var a="cellObjects"+t,n="cellMovements"+t,l=this.objectsPresent.data[t],i=this.objectsMissing.data[t],o=this.movementsPresent.data[t],r=this.movementsMissing.data[t];l&&(e+=l&l-1?"\t\t&& (("+a+"&"+l+")==="+l+")\n":"\t\t&& ("+a+"&"+l+")\n"),i&&(e+="\t\t&& !("+a+"&"+i+")\n"),o&&(e+=o&o-1?"\t\t&& (("+n+"&"+o+")==="+o+")\n":"\t\t&& ("+n+"&"+o+")\n"),r&&(e+="\t\t&& !("+n+"&"+r+")\n")}for(var s=0;s<this.anyObjectsPresent.length;s++){e+="\t\t&& (0";for(var t=0;t<STRIDE_OBJ;++t){var c=this.anyObjectsPresent[s].data[t];c&&(e+="|(cellObjects"+t+"&"+c+")")}e+=")"}return e+="\t)"},CellPattern.prototype.generateMatchFunction=function(){for(var e,t="",a=1===STRIDE_OBJ?"":"*"+STRIDE_OBJ,e=0;e<STRIDE_OBJ;++e)t+="\tvar cellObjects"+e+" = level.objects[i"+a+(e?"+"+e:"")+"];\n";a=1===STRIDE_MOV?"":"*"+STRIDE_MOV;for(var e=0;e<STRIDE_MOV;++e)t+="\tvar cellMovements"+e+" = level.movements[i"+a+(e?"+"+e:"")+"];\n";return t+="return "+this.generateMatchString()+";",t in matchCache?matchCache[t]:matchCache[t]=new Function("i",t)},CellPattern.prototype.toJSON=function(){return[this.movementMask,this.cellMask,this.nonExistenceMask,this.moveNonExistenceMask,this.moveStationaryMask,this.randomDirOrEntityMask,this.movementsToRemove]};var _o1,_o2,_o2_5,_o3,_o4,_o5,_o6,_o7,_o8,_o9,_o10,_o11,_o12,_m1,_m2,_m3;CellPattern.prototype.replace=function(e,t){var a=this.replacement;if(null===a)return!1;var n=a.randomEntityMask,l=a.randomDirMask,i=a.objectsSet.cloneInto(_o1),o=a.objectsClear.cloneInto(_o2),r=a.movementsSet.cloneInto(_m1),s=a.movementsClear.cloneInto(_m2);if(s.ior(a.movementsLayerMask),!n.iszero()){for(var c=[],v=0;v<32*STRIDE_OBJ;v++)n.get(v)&&c.push(v);var d=c[Math.floor(RandomGen.uniform()*c.length)],u=state.idDict[d],g=state.objects[u];i.ibitset(d),o.ior(state.layerMasks[g.layer]),s.ishiftor(31,5*g.layer)}if(!l.iszero())for(var m=0;m<level.layerCount;m++)if(l.get(5*m)){var h=Math.floor(4*RandomGen.uniform());r.ibitset(h+5*m)}var f=level.getCellInto(t,_o2_5),p=level.getMovements(t),_=f.cloneInto(_o3),M=p.cloneInto(_m3);f.iclear(o),f.ior(i),p.iclear(s),p.ior(r);var y=!1,S=0,I=0;if(e.isRigid){var b=state.groupNumber_to_RigidGroupIndex[e.groupNumber];b++;for(var w=new BitVec(STRIDE_MOV),k=0;k<level.layerCount;k++)w.ishiftor(b,5*k);w.iand(a.movementsLayerMask),S=level.rigidGroupIndexMask[t]||new BitVec(STRIDE_MOV),I=level.rigidMovementAppliedMask[t]||new BitVec(STRIDE_MOV),w.bitsSetInArray(S.data)||a.movementsLayerMask.bitsSetInArray(I.data)||(S.ior(w),I.ior(a.movementsLayerMask),y=!0)}var C=!1;if(!_.equals(f)||!M.equals(p)||y){C=!0,y&&(level.rigidGroupIndexMask[t]=S,level.rigidMovementAppliedMask[t]=I);var R=f.cloneInto(_o4);R.iclear(_),sfxCreateMask.ior(R);var T=_.cloneInto(_o5);T.iclear(f),sfxDestroyMask.ior(T),level.setCell(t,f),level.setMovements(t,p);var D=t/level.height|0,E=t%level.height;level.colCellContents[D].ior(f),level.rowCellContents[E].ior(f),level.mapCellContents.ior(f)}return C};var rigidBackups=[];Rule.prototype.findMatches=function(){for(var e=[],t=this.cellRowMasks,a=0;a<this.patterns.length;a++){var n=this.patterns[a],l=this.cellRowMatches[a];if(this.isEllipsis[a])var i=matchCellRowWildCard(this.direction,l,n,t[a]);else var i=matchCellRow(this.direction,l,n,t[a]);if(0===i.length)return[];e.push(i)}return e},Rule.prototype.directional=function(){for(var e=0;e<state.rules.length;e++)for(var t=state.rules[e],a=0,n=0;n<t.length;n++)if(this.lineNumber===t[n].lineNumber&&a++,a>1)return!0;return!1},Rule.prototype.applyAt=function(e,t,a){var n=this;if(this.isViewDir){var e=dirMasksDelta[this.direction];if(e[0]!=level.facing[0]||e[1]!=level.facing[1])return!1}if(a){for(var l=!0,i=0;i<n.patterns.length;i++)if(n.isEllipsis[i]){if(!1===DoesCellRowMatchWildCard(n.direction,n.patterns[i],t[i][0],t[i][1]+1,t[i][1])){l=!1;break}}else if(!1===DoesCellRowMatch(n.direction,n.patterns[i],t[i])){l=!1;break}if(!1===l)return!1}for(var o=!1,r=e[0]*level.height,s=e[1],i=0;i<n.patterns.length;i++)for(var c=n.patterns[i],v=n.isEllipsis[i]?t[i][0]:t[i],d=0;d<c.length;d++){var u=c[d];if(u!==ellipsisPattern)o=u.replace(n,v)||o,v=v+s+r;else{var g=t[i][1];v+=(s+r)*g}}if(verbose_logging&&o){var m=dirMaskName[n.direction];n.directional()||(m="");var h='<font color="green">Rule <a onclick="jumpToLine('+n.lineNumber+');"  href="javascript:void(0);">'+n.lineNumber+"</a> "+m+" applied.</font>";consolePrint(h)}return o},Rule.prototype.tryApply=function(){var e=dirMasksDelta[this.direction],t=this.findMatches();if(0===t.length)return!1;var a=!1;if(this.hasReplacements)for(var n=generateTuples(t),l=0;l<n.length;l++){var i=n[l],o=l>0,r=this.applyAt(e,i,o);a=r||a}return t.length>0&&this.queueCommands(),a},Rule.prototype.queueCommands=function(){for(var e=this.commands,t=0;t<e.length;t++){var a=e[t];if(!(level.commandQueue.indexOf(a[0])>=0)){if(level.commandQueue.push(a[0]),verbose_logging){var n=this.lineNumber,l=(dirMaskName[this.direction],'<font color="green">Rule <a onclick="jumpToLine('+n.toString()+');"  href="javascript:void(0);">'+n.toString()+"</a> triggers command "+a[0]+".</font>");consolePrint(l)}"message"===a[0]&&(messagetext=a[1])}}};var sfxCreateMask=null,sfxDestroyMask=null;</script> <script>function logErrorCacheable(e,n,r){if(compiling||r){if(void 0===n)return logErrorNoLine(e);var t='<a onclick="jumpToLine('+n.toString()+');"  href="javascript:void(0);"><span class="errorTextLineNumber"> line '+n.toString()+'</span></a> : <span class="errorText">'+e+"</span>";errorStrings.indexOf(t)>=0&&!r||(consolePrint(t),errorStrings.push(t),errorCount++)}}function logError(e,n,r){if(compiling||r){if(void 0===n)return logErrorNoLine(e);var t='<a onclick="jumpToLine('+n.toString()+');"  href="javascript:void(0);"><span class="errorTextLineNumber"> line '+n.toString()+'</span></a> : <span class="errorText">'+e+"</span>";errorStrings.indexOf(t)>=0&&!r||(consolePrint(t,!0),errorStrings.push(t),errorCount++)}}function logWarning(e,n,r){if(compiling||r){if(void 0===n)return logErrorNoLine(e);var t='<a onclick="jumpToLine('+n.toString()+');"  href="javascript:void(0);"><span class="errorTextLineNumber"> line '+n.toString()+'</span></a> : <span class="warningText">'+e+"</span>";errorStrings.indexOf(t)>=0&&!r||(consolePrint(t,!0),errorStrings.push(t))}}function logErrorNoLine(e,n){if(compiling||n){var r='<span class="errorText">'+e+"</span>";errorStrings.indexOf(r)>=0&&!n||(consolePrint(r,!0),errorStrings.push(r)),errorCount++}}function logBetaMessage(e,n){if(compiling||n){var r='<span class="betaText">'+e+"</span>";errorStrings.indexOf(r)>=0&&!n||(consoleError(r),errorStrings.push(r))}}function blankLineHandle(e){"levels"===e.section?e.levels[e.levels.length-1].length>0&&e.levels.push([]):"objects"===e.section&&(e.objects_section=0)}var compiling=!1,errorStrings=[],errorCount=0,codeMirrorFn=function(){"use strict";function e(e,n){if(void 0!==e.objects[n])return logError('Object "'+n.toUpperCase()+'" defined multiple times.',e.lineNumber),"ERROR";for(var r=0;r<e.legend_synonyms.length;r++){var t=e.legend_synonyms[r];t[0]==n&&logError('Name "'+n.toUpperCase()+'" already in use.',e.lineNumber)}for(var r=0;r<e.legend_aggregates.length;r++){var t=e.legend_aggregates[r];t[0]==n&&logError('Name "'+n.toUpperCase()+'" already in use.',e.lineNumber)}for(var r=0;r<e.legend_properties.length;r++){var t=e.legend_properties[r];t[0]==n&&logError('Name "'+n.toUpperCase()+'" already in use.',e.lineNumber)}}var n=["objects","legend","sounds","collisionlayers","rules","winconditions","levels"],r=["sfx0","sfx1","sfx2","sfx3","sfx4","sfx5","sfx6","sfx7","sfx8","sfx9","sfx10","cancel","checkpoint","restart","win","message","again"],t=/[\w]+\s*/,o=/\d+\b/,s=/(objects|collisionlayers|legend|sounds|rules|winconditions|levels)\s*/,i=/[\=]+/,a=/[^\(]+/,l=/[ \,]*/,c=/(move|action|create|destroy|cantmove|undo|restart|titlescreen|startgame|cancel|endgame|startlevel|endlevel|showmessage|closemessage|sfx0|sfx1|sfx2|sfx3|sfx4|sfx5|sfx6|sfx7|sfx8|sfx9|sfx10)\s+/,g=/^(action|up|down|left|right|\^|v|\<|\>|forward|moving|stationary|parallel|perpendicular|horizontal|orthogonal|vertical|no|randomdir|random)$/,d=/^(startloop|endloop)$/,u=/^(up|down|left|right|horizontal|vertical|orthogonal|late|rigid)$/,m=/\s*(up|down|left|right|horizontal|vertical|orthogonal)\s*/,p=/^(all|any|no|some)$/,h=["checkpoint","objects","collisionlayers","legend","sounds","rules","...","winconditions","levels","|","[","]","up","down","left","right","late","rigid","^","v",">","<","no","randomdir","random","horizontal","vertical","any","all","no","some","moving","stationary","parallel","perpendicular","action","message","viewdir"],f=/(floor|ceiling|sandwich|wall|voxel|sprite|billboard|motionvoxel|facingvoxel|hud)\s*/,v=/(linear|easein|easeout|smoothstep|step|doublestep|bound|roll|throw)\s*/;return{copyState:function(e){var n={};for(var r in e.objects)if(e.objects.hasOwnProperty(r)){var t=e.objects[r];n[r]={colors:t.colors.concat([]),lineNumber:t.lineNumber,spritematrix:t.spritematrix.concat([])}}for(var o=[],r=0;r<e.collisionLayers.length;r++)o.push(e.collisionLayers[r].concat([]));for(var s=[],i=[],a=[],l=[],c=[],g=[],r=0;r<e.legend_synonyms.length;r++)s.push(e.legend_synonyms[r].concat([]));for(var r=0;r<e.legend_aggregates.length;r++)i.push(e.legend_aggregates[r].concat([]));for(var r=0;r<e.legend_properties.length;r++)a.push(e.legend_properties[r].concat([]));for(var r=0;r<e.sounds.length;r++)l.push(e.sounds[r].concat([]));for(var r=0;r<e.levels.length;r++)c.push(e.levels[r].concat([]));for(var r=0;r<e.winconditions.length;r++)g.push(e.winconditions[r].concat([]));return{lineNumber:e.lineNumber,objects:n,collisionLayers:o,commentLevel:e.commentLevel,section:e.section,visitedSections:e.visitedSections.concat([]),objects_candname:e.objects_candname,objects_section:e.objects_section,objects_spritematrix:e.objects_spritematrix.concat([]),tokenIndex:e.tokenIndex,legend_synonyms:s,legend_aggregates:i,legend_properties:a,sounds:l,rules:e.rules.concat([]),names:e.names.concat([]),winconditions:g,abbrevNames:e.abbrevNames.concat([]),metadata:e.metadata.concat([]),levels:c,STRIDE_OBJ:e.STRIDE_OBJ,STRIDE_MOV:e.STRIDE_MOV}},blankLine:function(e){"levels"===e.section&&e.levels[e.levels.length-1].length>0&&e.levels.push([])},token:function(b,_){var x=b.string,E=b.sol();E&&(b.string=b.string.toLowerCase(),_.tokenIndex=0),b.eatWhile(/[ \t]/);var y=b.peek();if("("===y&&-4!==_.tokenIndex)b.next(),_.commentLevel++;else if(")"===y&&(b.next(),_.commentLevel>0&&0===--_.commentLevel))return"comment";if(_.commentLevel>0){for(;;){if(b.eatWhile(/[^\(\)]+/),b.eol())break;if(y=b.peek(),"("===y?_.commentLevel++:")"===y&&_.commentLevel--,b.next(),0===_.commentLevel)break}return"comment"}if(b.eatWhile(/[ \t]/),E&&b.eol())return blankLineHandle(_);if(E&&b.match(i,!0))return"EQUALSBIT";if(b.match(s,!0)){_.section=b.string.slice(0,b.pos).trim(),_.visitedSections.indexOf(_.section)>=0&&logError('cannot duplicate sections (you tried to duplicate "'+_.section.toUpperCase()+'").',_.lineNumber),_.visitedSections.push(_.section);var N=n.indexOf(_.section);if(0==N?(_.objects_section=0,_.visitedSections.length>1&&logError('section "'+_.section.toUpperCase()+'" must be the first section',_.lineNumber)):-1==_.visitedSections.indexOf(n[N-1])&&(-1===N?logError('no such section as "'+_.section.toUpperCase()+'".',_.lineNumber):logError('section "'+_.section.toUpperCase()+'" is out of order, must follow  "'+n[N-1].toUpperCase()+'".',_.lineNumber)),"sounds"===_.section){for(var R in _.objects)_.objects.hasOwnProperty(R)&&_.names.push(R);for(var O=0;O<_.legend_synonyms.length;O++){var R=_.legend_synonyms[O][0];_.names.push(R)}for(var O=0;O<_.legend_aggregates.length;O++){var R=_.legend_aggregates[O][0];_.names.push(R)}for(var O=0;O<_.legend_properties.length;O++){var R=_.legend_properties[O][0];_.names.push(R)}}else if("levels"===_.section){for(var R in _.objects)_.objects.hasOwnProperty(R)&&1==R.length&&_.abbrevNames.push(R);for(var O=0;O<_.legend_synonyms.length;O++)1==_.legend_synonyms[O][0].length&&_.abbrevNames.push(_.legend_synonyms[O][0]);for(var O=0;O<_.legend_aggregates.length;O++)1==_.legend_aggregates[O][0].length&&_.abbrevNames.push(_.legend_aggregates[O][0])}return"HEADER"}if(void 0===_.section&&logError('must start with section "OBJECTS"',_.lineNumber),b.eol())return null;switch(_.section){case"objects":var j=function(){var e=E?b.match(t,!0):b.match(/[^\s\()]+\s*/,!0);if(null==e)return b.match(a,!0),b.pos>0&&logWarning('Unknown junk in object section (possibly: sprites have to be 5 pixels wide and 5 pixels high exactly. Or maybe: the main names for objects have to be words containing only the letters a-z0.9 - if you want to call them something like ",", do it in the legend section).',_.lineNumber),"ERROR";var n=e[0].trim();if(void 0!==_.objects[n])return logError('Object "'+n.toUpperCase()+'" defined multiple times.',_.lineNumber),"ERROR";for(var r=0;r<_.legend_synonyms.length;r++){_.legend_synonyms[r][0]==n&&logError('Name "'+n.toUpperCase()+'" already in use.',_.lineNumber)}if(h.indexOf(n)>=0&&logWarning('You named an object "'+n.toUpperCase()+"\", but this is a keyword. Don't do that!",_.lineNumber),E)_.objects_candname=n,_.objects[_.objects_candname]={lineNumber:_.lineNumber,renderType:"floor",colors:[],spritematrix:[]};else{var o=[n,_.objects_candname];o.lineNumber=_.lineNumber,_.legend_synonyms.push(o)}return _.objects_section=1,"NAME"};switch(E&&4==_.objects_section&&(_.objects_section=5),E&&3==_.objects_section&&(_.objects_section=4),E&&2==_.objects_section&&(_.objects_section=3),E&&1==_.objects_section&&(_.objects_section=2),_.objects_section){case 0:case 1:return _.objects_spritematrix=[],j();case 2:_.tokenIndex=0;var k=b.match(f,!0);if(null!=k)return _.objects[_.objects_candname].renderType=k[0],"RENDERTYPE";_.objects[_.objects_candname].renderType="floor",_.objects_section=3;case 3:_.tokenIndex=0;var C=b.match(v,!0);if(null!=C)return _.objects[_.objects_candname].tween=C[0],"TWEEN";_.objects[_.objects_candname].tween="linear",_.objects_section=4;case 4:_.tokenIndex=0;var L=b.match(reg_color,!0);if(null==L){var w=b.match(t,!0)||b.match(a,!0);return logError("Was looking for color for object "+_.objects_candname.toUpperCase()+', got "'+w+'" instead.',_.lineNumber),null}void 0===_.objects[_.objects_candname].colors?_.objects[_.objects_candname].colors=[L[0].trim()]:_.objects[_.objects_candname].colors.push(L[0].trim());var I=L[0].trim().toLowerCase();return I in colorPalettes.arnecolors?"COLOR COLOR-"+I.toUpperCase():"transparent"===I?"COLOR FADECOLOR":"COLOR";case 5:var y=b.eat(/[&.\d]/),T=_.objects_spritematrix;if(void 0===y)return j();var S=T[T.length-1];E&&(0!=T.length&&"&"!=y||(T.push([]),(void 0==T.depth||T.depth<T.length)&&(T.depth=T.length)),S=T[T.length-1],"&"!=y&&(S.push(""),(void 0==T.height||T.height<S.length)&&(T.height=S.length)));var D=_.objects[_.objects_candname];if("&"!=y&&(S[S.length-1]+=y,(void 0==T.width||T.width<S[S.length-1].length)&&(T.width=S[S.length-1].length)),D.spritematrix=_.objects_spritematrix,"."!==y&&"&"!=y){var R=parseInt(y);return R>=D.colors.length?(logError("Trying to access color number "+R+" from the color palette of sprite "+_.objects_candname.toUpperCase()+", but there are only "+D.colors.length+" defined in it.",_.lineNumber),"ERROR"):isNaN(R)?(logError('Invalid character "'+y+'" in sprite for '+_.objects_candname.toUpperCase(),_.lineNumber),"ERROR"):"COLOR BOLDCOLOR COLOR-"+D.colors[R].toUpperCase()}return"COLOR FADECOLOR";default:window.console.logError("EEK shouldn't get here.")}break;case"sounds":if(E){var A=!0,U=a.exec(b.string)[0].split(/\s/).filter(function(e){return""!==e});U.push(_.lineNumber),_.sounds.push(U)}if(null!==(G=b.match(c,!0)))return"SOUNDVERB";if(null!==(G=b.match(m,!0)))return"DIRECTION";if(null!==(G=b.match(o,!0)))return _.tokenIndex++,"SOUND";if(null!==(G=b.match(/[^\[\|\]\s]*/,!0))){var M=G[0].trim();if(_.names.indexOf(M)>=0)return"NAME"}return G=b.match(a,!0),logError('unexpected sound token "'+G+'".',_.lineNumber),b.match(a,!0),"ERROR";case"collisionlayers":E&&(_.collisionLayers.push([]),_.tokenIndex=0);var B=b.match(t,!0);if(null===B){var W=b.pos;return b.match(l,!0),b.pos==W&&(logError("error detected - unexpected character "+b.peek(),_.lineNumber),b.next()),null}var G=B[0].trim(),P=function(e){if((e=e.toLowerCase())in _.objects)return[e];for(var n=0;n<_.legend_synonyms.length;n++){var r=_.legend_synonyms[n];if(r[0]===e)return[r[1]]}for(var n=0;n<_.legend_aggregates.length;n++){var r=_.legend_aggregates[n];if(r[0]===e)return logError('"'+e+'" is an aggregate (defined using "and"), and cannot be added to a single layer because its constituent objects must be able to coexist.',_.lineNumber),[]}for(var n=0;n<_.legend_properties.length;n++){var r=_.legend_properties[n];if(r[0]===e){return[].concat.apply([],r.slice(1).map(P))}}return logError('Cannot add "'+G.toUpperCase()+'" to a collision layer; it has not been declared.',_.lineNumber),[]};"background"===G?(_.collisionLayers.length>0&&_.collisionLayers[_.collisionLayers.length-1].length>0&&logError("Background must be in a layer by itself.",_.lineNumber),_.tokenIndex=1):0!==_.tokenIndex&&logError("Background must be in a layer by itself.",_.lineNumber);var z=P(G);if(0===_.collisionLayers.length)return logError("no layers found.",_.lineNumber),"ERROR";for(var V=[],O=0;O<z.length;O++)for(var G=z[O],Y=0;Y<=_.collisionLayers.length-1;Y++){var F=_.collisionLayers[Y];F.indexOf(G)>=0&&V.push(Y)}if(V.length>0){for(var K='Object "'+G.toUpperCase()+'" included in multiple collision layers ( layers ',O=0;O<V.length;O++)K+=V[O]+", ";K+=_.collisionLayers.length-1,logWarning(K+"). You should fix this!",_.lineNumber)}return _.collisionLayers[_.collisionLayers.length-1]=_.collisionLayers[_.collisionLayers.length-1].concat(z),z.length>0?"NAME":"ERROR";case"legend":if(E){var $=b.string.replace("="," = ");$=a.exec($)[0];var U=$.split(/\s/).filter(function(e){return""!==e}),A=!0;if(U.length>0){var G=U[0].toLowerCase();h.indexOf(G)>=0&&logWarning('You named an object "'+G.toUpperCase()+"\", but this is a keyword. Don't do that!",_.lineNumber),U.indexOf(G,2)>=2&&logError("You can't define object "+G.toUpperCase()+" in terms of itself!",_.lineNumber),e(_,G)}if(U.length<3)A=!1;else if("="!==U[1])A=!1;else if(3===U.length){var H=[U[0],U[2].toLowerCase()];H.lineNumber=_.lineNumber,_.legend_synonyms.push(H)}else if(U.length%2==0)A=!1;else{var J=U[3].toLowerCase();if("and"===J){for(var P=(function(e){if((e=e.toLowerCase())in _.objects)return[e];for(var n=0;n<_.legend_synonyms.length;n++){var r=_.legend_synonyms[n];if(r[0]===e)return[1]}for(var n=0;n<_.legend_aggregates.length;n++){var r=_.legend_aggregates[n];if(r[0]===e)return[].concat.apply([],r.slice(1).map(P))}for(var n=0;n<_.legend_properties.length;n++){var r=_.legend_properties[n];if(r[0]===e)return logError("Cannot define an aggregate (using 'and') in terms of properties (something that uses 'or').",_.lineNumber),A=!1,[e]}return[e]}),O=5;O<U.length;O+=2)if("and"!==U[O].toLowerCase()){A=!1;break}if(A){for(var q=[U[0]].concat(P(U[2])).concat(P(U[4])),O=6;O<U.length;O+=2)q=q.concat(P(U[O]));q.lineNumber=_.lineNumber,_.legend_aggregates.push(q)}}else if("or"===J){for(var P=(function(e){if((e=e.toLowerCase())in _.objects)return[e];for(var n=0;n<_.legend_synonyms.length;n++){var r=_.legend_synonyms[n];if(r[0]===e)return[1]}for(var n=0;n<_.legend_aggregates.length;n++){var r=_.legend_aggregates[n];r[0]===e&&(logError("Cannot define a property (using 'or') in terms of aggregates (something that uses 'and').",_.lineNumber),A=!1)}for(var n=0;n<_.legend_properties.length;n++){var r=_.legend_properties[n];if(r[0]===e)return[].concat.apply([],r.slice(1).map(P))}return[e]}),O=5;O<U.length;O+=2)if("or"!==U[O].toLowerCase()){A=!1;break}if(A){for(var q=[U[0],U[2].toLowerCase(),U[4].toLowerCase()],O=6;O<U.length;O+=2)q.push(U[O].toLowerCase());q.lineNumber=_.lineNumber,_.legend_properties.push(q)}}else A=!1}if(!1===A)return logError("incorrect format of legend - should be one of A = B, A = B or C ( or D ...), A = B and C (and D ...)",_.lineNumber),b.match(a,!0),"ERROR";_.tokenIndex=0}if(0===_.tokenIndex)return b.match(/[^=]*/,!0),_.tokenIndex++,"NAME";if(1===_.tokenIndex)return b.next(),b.match(/\s*/,!0),_.tokenIndex++,"ASSSIGNMENT";var B=b.match(t,!0);if(null===B)return logError("Something bad's happening in the LEGEND",_.lineNumber),b.match(a,!0),"ERROR";var G=B[0].trim();if(_.tokenIndex%2==0){return!1===function(e){if((e=e.toLowerCase())in _.objects)return!0;for(var n=0;n<_.legend_aggregates.length;n++){var r=_.legend_aggregates[n];if(r[0]===e)return!0}for(var n=0;n<_.legend_properties.length;n++){var r=_.legend_properties[n];if(r[0]===e)return!0}for(var n=0;n<_.legend_synonyms.length;n++){var r=_.legend_synonyms[n];if(r[0]===e)return!0}return!1}(G)?(logError('Cannot reference "'+G.toUpperCase()+'" in the LEGEND section; it has not been defined yet.',_.lineNumber),_.tokenIndex++,"ERROR"):(_.tokenIndex++,"NAME")}return _.tokenIndex++,"LOGICWORD";case"rules":if(E){var Q=a.exec(b.string)[0];_.rules.push([Q,_.lineNumber,x]),_.tokenIndex=0}if(-4===_.tokenIndex)return b.skipToEnd(),"MESSAGE";if(b.match(/\s*\-\>\s*/,!0))return"ARROW";if("["===y||"|"===y||"]"===y||"+"===y)return"+"!==y&&(_.tokenIndex=1),b.next(),b.match(/\s*/,!0),"BRACKET";var M=b.match(/[^\[\|\]\s]*/,!0)[0].trim();return 0===_.tokenIndex&&d.exec(M)?"BRACKET":0===_.tokenIndex&&u.exec(M)?(b.match(/\s*/,!0),"DIRECTION"):1===_.tokenIndex&&g.exec(M)?(b.match(/\s*/,!0),"DIRECTION"):_.names.indexOf(M)>=0?E?(logError("Identifiers cannot appear outside of square brackes in rules, only directions can.",_.lineNumber),"ERROR"):(b.match(/\s*/,!0),"NAME"):"..."===M?"DIRECTION":"rigid"===M?"DIRECTION":"random"===M?"DIRECTION":"viewdir"===M?"DIRECTION":r.indexOf(M)>=0?("message"===M&&(_.tokenIndex=-4),"COMMAND"):(logError('Name "'+M+'", referred to in a rule, does not exist.',_.lineNumber),"ERROR");case"winconditions":if(E){var X=a.exec(b.string),Z=X[0].split(/\s/),ee=Z.filter(function(e){return""!==e});ee.push(_.lineNumber),_.winconditions.push(ee),_.tokenIndex=-1}_.tokenIndex++;var ne=b.match(/\s*\w+\s*/);if(null===ne)return logError("incorrect format of win condition.",_.lineNumber),b.match(a,!0),"ERROR";var re=ne[0].trim();if(0===_.tokenIndex)return p.exec(re)?"LOGICWORD":"ERROR";if(2===_.tokenIndex)return"on"!=re?"ERROR":"LOGICWORD";if(1===_.tokenIndex||3===_.tokenIndex)return-1===_.names.indexOf(re)?(logError('Error in win condition: "'+re.toUpperCase()+'" is not a valid object name.',_.lineNumber),"ERROR"):"NAME";break;case"levels":if(E){if(b.match(/\s*message\s*/,!0)){_.tokenIndex=1;var te=["\n",x.slice(b.pos).trim(),_.lineNumber];return 0==_.levels[_.levels.length-1].length?_.levels.splice(_.levels.length-1,0,te):_.levels.push(te),"MESSAGE_VERB"}var oe=b.match(a,!1)[0].trim();_.tokenIndex=2;var se=_.levels[_.levels.length-1];"\n"==se[0]?_.levels.push([_.lineNumber,oe]):(0==se.length&&se.push(_.lineNumber),se.push(oe),se.length>1&&oe.length!=se[1].length&&logWarning("Maps must be rectangular, yo (In a level, the length of each row must be the same).",_.lineNumber))}else if(1==_.tokenIndex)return b.skipToEnd(),"MESSAGE";if(2===_.tokenIndex&&!b.eol()){var y=b.peek();return b.next(),_.abbrevNames.indexOf(y)>=0?"LEVEL":(logError('Key "'+y.toUpperCase()+'" not found. Do you need to add it to the legend, or define a new object?',_.lineNumber),"ERROR")}break;default:if(E&&(_.tokenIndex=0),0!=_.tokenIndex)return b.match(a,!0),"METADATATEXT";var ne=b.match(/\s*\w+\s*/);if(null!==ne){var ie=ne[0].trim();if(E){if(["title","author","homepage","background_color","text_color","key_repeat_interval","realtime_interval","again_interval","flickscreen","zoomscreen","color_palette","youtube","view_pitch","view_distance","view_height","field_of_view","fog_power","interpolation_interval","gradient_bottom","gradient_middle","gradient_top","scale_width","scale_height","scale_depth"].indexOf(ie)>=0){"youtube"!==ie&&"author"!==ie&&"title"!==ie||(b.string=x);var ae=b.match(a,!1);return null!=ae?(_.metadata.push(ie),_.metadata.push(ae[0].trim())):logError('MetaData "'+ie+'" needs a value.',_.lineNumber),_.tokenIndex=1,"METADATA"}return["run_rules_on_level_start","norepeat_action","require_player_movement","debug","verbose_logging","throttle_movement","noundo","noaction","norestart","scanline"].indexOf(ie)>=0?(_.metadata.push(ie),_.metadata.push("true"),_.tokenIndex=-1,"METADATA"):(logError("Unrecognised stuff in metadata section.",_.lineNumber),"ERROR")}return-1==_.tokenIndex?(logError('MetaData "'+ie+'" has no parameters.',_.lineNumber),"ERROR"):"METADATA"}}return b.eol()?null:b.eol()?void 0:(b.next(),null)},startState:function(){return{objects:{},lineNumber:0,commentLevel:0,section:"",visitedSections:[],objects_candname:"",objects_section:0,objects_spritematrix:[],collisionLayers:[],tokenIndex:0,legend_synonyms:[],legend_aggregates:[],legend_properties:[],sounds:[],rules:[],names:[],winconditions:[],metadata:[],abbrevNames:[],levels:[[]],subsection:""}}}};window.CodeMirror.defineMode("puzzle",codeMirrorFn);</script> <script>"use strict";function isColor(e){return(e=e.trim())in colorPalettes.arnecolors||(!!/^#([0-9A-F]{3}){1,2}$/i.test(e)||"transparent"===e)}function colorToHex(e,r){return r=r.trim(),r in e?e[r]:r}function generateSpriteMatrix(e){var r=[];r.depth=e.depth,r.height=e.height,r.width=e.width;for(var o=0;o<e.depth;++o){for(var t=[],n=e[o],a=0;a<e.height;++a){for(var i=[],l=n[a],s=0;s<e.width;++s)if(void 0!=l&&s<l.length){var c=l.charAt(s);"."==c?i.push(-1):i.push(c)}else i.push(-1);t.push(i)}r.push(t)}return r}function generateExtraMembers(e){0===e.collisionLayers.length&&logError("No collision layers defined.  All objects need to be in collision layers."),e.idDict={};for(var r=0,o=0;o<e.collisionLayers.length;o++)for(var t=0;t<e.collisionLayers[o].length;t++){var n=e.collisionLayers[o][t];if(n in e.objects){var a=e.objects[n];a.layer=o,a.id=r,e.idDict[r]=n,r++}}e.objectCount=r;for(var i=e.collisionLayers.length,l=[],s=0;s<i;s++)l.push(-1);STRIDE_OBJ=0|Math.ceil(e.objectCount/32),STRIDE_MOV=0|Math.ceil(i/5),e.STRIDE_OBJ=STRIDE_OBJ,e.STRIDE_MOV=STRIDE_MOV,debugMode=!1,verbose_logging=!1,throttle_movement=!1,colorPalette=colorPalettes.arnecolors;for(var s=0;s<e.metadata.length;s+=2){var c=e.metadata[s],g=e.metadata[s+1];"color_palette"===c?(g in colorPalettesAliases&&(g=colorPalettesAliases[g]),void 0===colorPalettes[g]?logError('Palette "'+g+'" not found, defaulting to arnecolors.',0):colorPalette=colorPalettes[g]):"debug"===c?(debugMode=!0,cache_console_messages=!0):"verbose_logging"===c?(verbose_logging=!0,cache_console_messages=!0):"throttle_movement"===c&&(throttle_movement=!0)}for(var n in e.objects)if(e.objects.hasOwnProperty(n)){var a=e.objects[n];a.colors.length>10&&logError("a sprite cannot have more than 10 colors.  Why you would want more than 10 is beyond me.",a.lineNumber+1);for(var s=0;s<a.colors.length;s++){var h=a.colors[s];isColor(h)?(h=colorToHex(colorPalette,h),a.colors[s]=h):(logError('Invalid color specified for object "'+n+'", namely "'+a.colors[s]+'".',a.lineNumber+1),a.colors[s]="#ff00ff")}}for(var n in e.objects)if(e.objects.hasOwnProperty(n)){var a=e.objects[n];0==a.colors.length&&(logError('color not specified for object "'+n+'".',a.lineNumber),a.colors=["#ff00ff"]),0===a.spritematrix.length||1==a.spritematrix.length&&0==a.spritematrix[0].length?a.spritematrix=[[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]]:a.spritematrix=generateSpriteMatrix(a.spritematrix)}var u={};for(var n in e.objects)if(e.objects.hasOwnProperty(n)){var a=e.objects[n],f=l.concat([]);f[a.layer]=a.id,u[n]=f}for(var p=!0;p;){p=!1;for(var s=0;s<e.legend_synonyms.length;s++){var d=e.legend_synonyms[s],c=d[0],g=d[1];c in u&&void 0!==u[c]||void 0===u[g]||(p=!0,u[c]=u[g])}for(var s=0;s<e.legend_aggregates.length;s++){for(var d=e.legend_aggregates[s],c=d[0],v=d.slice(1),m=!0,t=0;t<v.length;t++){if(void 0===u[v[t]]){m=!1;break}}if((!(c in u)||void 0===u[c])&&m){for(var f=l.concat([]),t=1;t<d.length;t++){var n=d[t],a=e.objects[n];void 0==a&&logError("Object not found with name "+n,e.lineNumber),-1==f[a.layer]?f[a.layer]=a.id:void 0===a.layer?logError('Object "'+n.toUpperCase()+'" has been defined, but not assigned to a layer.',d.lineNumber):logError('Trying to create an aggregate object (defined in the legend) with both "'+n.toUpperCase()+'" and "'+e.idDict[f[a.layer]].toUpperCase()+"\", which are on the same layer and therefore can't coexist.",d.lineNumber)}p=!0,u[d[0]]=f}}}e.glyphDict=u;for(var b={},s=0;s<e.legend_aggregates.length;s++){var y=e.legend_aggregates[s];b[y[0]]=y.slice(1)}e.aggregatesDict=b;for(var R={},s=0;s<e.legend_properties.length;s++){var y=e.legend_properties[s];R[y[0]]=y.slice(1)}e.propertiesDict=R;for(var w={},s=0;s<e.legend_synonyms.length;s++){var y=e.legend_synonyms[s],c=y[0],E=y[1];E in b?b[c]=b[E]:E in R?R[c]=R[E]:c!==E&&(w[c]=E)}e.synonymsDict=w;for(var k=!0;k;){k=!1;for(var n in w)if(w.hasOwnProperty(n)){var E=w[n];E in R?(delete w[n],R[n]=R[E],k=!0):E in b?(delete b[n],b[n]=b[E],k=!0):E in w&&(w[n]=w[E])}for(var n in R)if(R.hasOwnProperty(n))for(var D=R[n],s=0;s<D.length;s++){var E=D[s];if(E in w)D[s]=w[E],k=!0;else if(E in R){D.splice(s,1);for(var I=R[E],t=0;t<I.length;t++){var _=I[t];-1===D.indexOf(_)&&D.push(_)}k=!0}E in b&&logError('Trying to define property "'+n.toUpperCase()+'" in terms of aggregate "'+E.toUpperCase()+'".')}for(var n in b)if(b.hasOwnProperty(n))for(var D=b[n],s=0;s<D.length;s++){var E=D[s];if(E in w)D[s]=w[E],k=!0;else if(E in b){D.splice(s,1);for(var I=b[E],t=0;t<I.length;t++){var _=I[t];-1===D.indexOf(_)&&D.push(_)}k=!0}E in R&&logError('Trying to define aggregate "'+n.toUpperCase()+'" in terms of property "'+E.toUpperCase()+'".')}}e.propertiesSingleLayer={};for(var c in R)if(R.hasOwnProperty(c)){for(var D=R[c],M=!0,s=1;s<D.length;s++)if(e.objects[D[s-1]].layer!==e.objects[D[s]].layer){M=!1;break}M&&(e.propertiesSingleLayer[c]=e.objects[D[0]].layer)}void 0===e.idDict[0]&&e.collisionLayers.length>0&&logError("You need to have some objects defined");var j,x;if(void 0===e.objects.background)if("background"in e.synonymsDict){var n=e.synonymsDict.background,a=e.objects[n];j=a.id,x=a.layer}else if("background"in e.propertiesDict){var n=e.propertiesDict.background[0],a=e.objects[n];j=a.id,x=a.layer}else if("background"in e.aggregatesDict){var a=e.objects[e.idDict[0]];j=a.id,x=a.layer,logError("background cannot be an aggregate (declared with 'and'), it has to be a simple type, or property (declared in terms of others using 'or').")}else{var a=e.objects[e.idDict[0]];j=a.id,x=a.layer,logError("you have to define something to be the background")}else j=e.objects.background.id,x=e.objects.background.layer;e.backgroundid=j,e.backgroundlayer=x}function levelFromString(e,r){var o=e.backgroundlayer,t=(e.backgroundid,e.layerMasks[o]),n=new Level(r[0],r[1].length,r.length-1,e.collisionLayers.length,null);n.objects=new Int32Array(n.width*n.height*STRIDE_OBJ),n.motions=new Int32Array(n.width*n.height*STRIDE_MOV),n.noActionMotions=new Int32Array(n.width*n.height*STRIDE_MOV);for(var a=0;a<n.width;a++)for(var i=0;i<n.height;i++){var l=r[i+1].charAt(a);0==l.length&&(l=r[i+1].charAt(r[i+1].length-1));var s=e.glyphDict[l];void 0==s&&(void 0===e.propertiesDict[l]?logError('Error, symbol "'+l+'", used in map, not found.',r[0]+i):logError('Error, symbol "'+l+"\" is defined using 'or', and therefore ambiguous - it cannot be used in a map. Did you mean to define it in terms of 'and'?",r[0]+i));var c=new BitVec(STRIDE_OBJ);s=s.concat([]);for(var g=0;g<n.layerCount;g++)s[g]>=0&&c.ibitset(s[g]);for(var h=0;h<STRIDE_OBJ;++h)n.objects[STRIDE_OBJ*(a*n.height+i)+h]=c.data[h]}for(var u=n.calcBackgroundMask(e),a=0;a<n.n_tiles;a++){var f=n.getCell(a);t.anyBitsInCommon(f)||f.ior(u),n.setCell(a,f)}return n}function levelsToArray(e){for(var r=e.levels,o=[],t=0;t<r.length;t++){var n=r[t];if(0!=n.length)if("\n"==n[0]){var a={message:n[1]};splitMessage=wordwrap(a.message,intro_template[0].length),splitMessage.length>12&&logWarning("Message too long to fit on screen.",n[2]),o.push(a)}else{var a=levelFromString(e,n);o.push(a)}}e.levels=o}function directionalRule(e){for(var r=0;r<e.lhs.length;r++){var o=e.lhs[r];if(o.length>1)return!0;for(var t=0;t<o.length;t++)for(var n=o[t],a=0;a<n.length;a+=2)if(relativeDirections.indexOf(n[a])>=0)return!0}for(var r=0;r<e.rhs.length;r++){var o=e.rhs[r];if(o.length>1)return!0;for(var t=0;t<o.length;t++)for(var n=o[t],a=0;a<n.length;a+=2)if(relativeDirections.indexOf(n[a])>=0)return!0}return!1}function findIndexAfterToken(e,r,o){e=e.toLowerCase();for(var t=0,n=0;n<=o;n++){var a=r[n];t=e.indexOf(a,t)+a.length}return t}function processRuleString(e,r,o){var t=e[0],n=e[1],a=e[2];t=t.replace(/\[/g," [ ").replace(/\]/g," ] ").replace(/\|/g," | ").replace(/\-\>/g," -> "),t=t.trim(),"+"===t[0]&&(t=t.substring(0,1)+" "+t.substring(1,t.length));var i=t.split(/\s/).filter(function(e){return""!==e});0==i.length&&logError("Spooky error!  Empty line passed to rule function.",n);var l=0,s=[],c=null,g=[],h=!1,u=!1,f=[],p=[],d=!1,v=!1,m=n,b=[],y=!1,R=!1;if(1===i.length){if("startloop"===i[0])return I={bracket:1};if("endloop"===i[0])return I={bracket:-1}}-1==i.indexOf("->")&&logError("A rule has to have an arrow in it.  There's no arrow here! Consider reading up about rules - you're clearly doing something weird",n);for(var w=0;w<i.length;w++){var E=i[w];switch(l){case 0:"+"===E?m===n?(0==o.length&&logError('The "+" symbol, for joining a rule with the group of the previous rule, needs a previous rule to be applied to.'),0!==w&&logError('The "+" symbol, for joining a rule with the group of the previous rule, must be the first symbol on the line '),m=o[o.length-1].groupNumber):logError('Two "+"s ("append to previous rule group" symbol) applied to the same rule.',n):E in directionaggregates?s=s.concat(directionaggregates[E]):"late"===E?d=!0:"rigid"===E?v=!0:"random"===E?y=!0:"viewdir"===E?R=!0:simpleAbsoluteDirections.indexOf(E)>=0?s.push(E):simpleRelativeDirections.indexOf(E)>=0?logError('You cannot use relative directions ("^v<>") to indicate in which direction(s) a rule applies.  Use absolute directions indicators (Up, Down, Left, Right, Horizontal, or Vertical, for instance), or, if you want the rule to apply in all four directions, do not specify directions',n):"["==E?(0==s.length&&(s=s.concat(directionaggregates.orthogonal)),l=1,w--):logError("The start of a rule must consist of some number of directions (possibly 0), before the first bracket, specifying in what directions to look (with no direction specified, it applies in all four directions).  It seems you've just entered \""+E.toUpperCase()+'".',n);break;case 1:if("["==E)g.length>0&&logError('Error, malformed cell rule - encountered a "["" before previous bracket was closed',n),h=!0,c=[];else if(reg_directions_only.exec(E))c.length%2==1?logError("Error, an item can only have one direction/action at a time, but you're looking for several at once!",n):h?c.push(E):logWarning("Invalid syntax. Directions should be placed at the start of a rule.",n);else if("|"==E)c.length%2==1?logError("In a rule, if you specify a force, it has to act on an object.",n):(g.push(c),c=[]);else if("]"===E)c.length%2==1?"..."===c[0]?logError("Cannot end a rule with ellipses.",n):logError("In a rule, if you specify a force, it has to act on an object.",n):(g.push(c),c=[]),u?p.push(g):f.push(g),g=[],h=!1;else if("->"===E)u&&logError('Error, you can only use "->" once in a rule; it\'s used to separate before and after states.',n),g.length>0?logError('Encountered an unexpected "->" inside square brackets.  It\'s used to separate states, it has no place inside them >:| .',n):u=!0;else if(r.names.indexOf(E)>=0)h?c.length%2==0?(c.push(""),c.push(E)):c.length%2==1&&c.push(E):logWarning("Invalid token "+E.toUpperCase()+". Object names should only be used within cells (square brackets).",n);else if("..."===E)h?(c.push(E),c.push(E)):logWarning("Invalid syntax, ellipses should only be used within cells (square brackets).",n);else if(commandwords.indexOf(E)>=0)if(!1===u&&logError("Commands cannot appear on the left-hand side of the arrow.",n),"message"===E){var k=findIndexAfterToken(a,i,w),D=a.substring(k).trim();""===D&&(D=" "),b.push([E,D]),w=i.length}else b.push([E]);else logError('Error, malformed cell rule - was looking for cell contents, but found "'+E+'".  What am I supposed to do with this, eh, please tell me that.',n)}}if(f.length!=p.length)b.length>0&&0==p.length||logError("Error, when specifying a rule, the number of matches (square bracketed bits) on the left hand side of the arrow must equal the number on the right",n);else for(var w=0;w<f.length;w++)f[w].length!=p[w].length&&logError("In a rule, each pattern to match on the left must have a corresponding pattern on the right of equal length (number of cells).",n),0==f[w].length&&logError("You have an totally empty pattern on the left-hand side.  This will match *everything*.  You certianly don't want this.");0==f.length&&logError("This rule refers to nothing.  What the heck? :O",n);var I={directions:s,lhs:f,rhs:p,lineNumber:n,late:d,rigid:v,groupNumber:m,commands:b,randomRule:y,viewDirRule:R};!1===directionalRule(I)&&(I.directions=["up"]);for(var w=0;w<b.length;w++){var _=b[w][0];"restart"===_?(b.length>1||p.length>0)&&logError("The RESTART command can only appear by itself on the right hand side of the arrow.",n):"cancel"===_&&(b.length>1||p.length>0)&&logError("The CANCEL command can only appear by itself on the right hand side of the arrow.",n)}return I}function deepCloneHS(e){return e.map(function(e){return e.map(function(e){return e.slice()})})}function deepCloneRule(e){return{direction:e.direction,lhs:deepCloneHS(e.lhs),rhs:deepCloneHS(e.rhs),lineNumber:e.lineNumber,late:e.late,rigid:e.rigid,groupNumber:e.groupNumber,commands:e.commands,randomRule:e.randomRule,viewDirRule:e.viewDirRule}}function rulesToArray(e){for(var r=e.rules,o=[],t=[],n=0;n<r.length;n++){var a=r[n][1],i=processRuleString(r[n],e,o);void 0===i.bracket?o.push(i):t.push([a,i.bracket])}e.loops=t;for(var l=[],n=0;n<o.length;n++)for(var s=o[n],c=s.directions,g=0;g<c.length;g++){var h=c[g];if(h in directionaggregates&&directionalRule(s))for(var u=directionaggregates[h],f=0;f<u.length;f++){var p=deepCloneRule(s);p.direction=u[f],l.push(p)}else{var p=deepCloneRule(s);p.direction=h,l.push(p)}}for(var n=0;n<l.length;n++){var s=l[n];convertRelativeDirsToAbsolute(s),atomizeAggregates(e,s),rephraseSynonyms(e,s)}for(var d=[],n=0;n<l.length;n++){var s=l[n];d=d.concat(concretizeMovingRule(e,s,s.lineNumber))}for(var v=[],n=0;n<d.length;n++){var s=d[n];v=v.concat(concretizePropertyRule(e,s,s.lineNumber))}e.rules=v}function containsEllipsis(e){for(var r=0;r<e.lhs.length;r++)for(var o=0;o<e.lhs[r].length;o++)if("..."===e.lhs[r][o][1])return!0;return!1}function rewriteUpLeftRules(e){if(!containsEllipsis(e)){if("up"==e.direction)e.direction="down";else{if("left"!=e.direction)return;e.direction="right"}for(var r=0;r<e.lhs.length;r++)e.lhs[r].reverse(),e.rhs.length>0&&e.rhs[r].reverse()}}function getPropertiesFromCell(e,r){for(var o=[],t=0;t<r.length;t+=2){var n=r[t],a=r[t+1];"random"!=n&&(a in e.propertiesDict&&o.push(a))}return o}function getMovings(e,r){for(var o=[],t=0;t<r.length;t+=2){var n=r[t],a=r[t+1];n in directionaggregates&&o.push([a,n])}return o}function concretizePropertyInCell(e,r,o){for(var t=0;t<e.length;t+=2)e[t+1]===r&&"random"!==e[t]&&(e[t+1]=o)}function concretizeMovingInCell(e,r,o,t){for(var n=0;n<e.length;n+=2)e[n]===r&&e[n+1]===o&&(e[n]=t)}function concretizeMovingInCellByAmbiguousMovementName(e,r,o){for(var t=0;t<e.length;t+=2)e[t]===r&&(e[t]=o)}function expandNoPrefixedProperties(e,r){for(var o=[],t=0;t<r.length;t+=2){var n=r[t],a=r[t+1];if("no"===n&&a in e.propertiesDict)for(var i=e.propertiesDict[a],l=0;l<i.length;l++){var s=i[l];o.push(n),o.push(s)}else o.push(n),o.push(a)}return o}function concretizePropertyRule(e,r,o){for(var t=0;t<r.lhs.length;t++)for(var n=r.lhs[t],a=0;a<n.length;a++)n[a]=expandNoPrefixedProperties(e,n[a]),r.rhs.length>0&&(r.rhs[t][a]=expandNoPrefixedProperties(e,r.rhs[t][a]));for(var i={},a=0;a<r.rhs.length;a++)for(var l=r.lhs[a],s=r.rhs[a],c=0;c<s.length;c++)for(var g=getPropertiesFromCell(e,l[c]),h=getPropertiesFromCell(e,s[c]),u=0;u<h.length;u++){var f=h[u];-1==g.indexOf(f)&&(i[f]=!0)}for(var p,d=[r],v=!0;v;){v=!1;for(var t=0;t<d.length;t++){var m=d[t];p=!1;for(var a=0;a<m.lhs.length&&!p;a++)for(var b=m.lhs[a],c=0;c<b.length&&!p;c++)for(var y=b[c],R=getPropertiesFromCell(e,y),u=0;u<R.length;++u){var f=R[u];if(!e.propertiesSingleLayer.hasOwnProperty(f)||!0===i[f]){var w=e.propertiesDict[f];p=!0,v=!0;for(var E=0;E<w.length;E++){var k=w[E],D=deepCloneRule(m);D.propertyReplacement={};for(var I in m.propertyReplacement)if(m.propertyReplacement.hasOwnProperty(I)){var _=m.propertyReplacement[I];D.propertyReplacement[I]=[_[0],_[1]]}concretizePropertyInCell(D.lhs[a][c],f,k),D.rhs.length>0&&concretizePropertyInCell(D.rhs[a][c],f,k),void 0===D.propertyReplacement[f]?D.propertyReplacement[f]=[k,1]:D.propertyReplacement[f][1]=D.propertyReplacement[f][1]+1,d.push(D)}break}}p&&(d.splice(t,1),t--)}}for(var t=0;t<d.length;t++){var m=d[t];if(void 0!==m.propertyReplacement)for(var f in m.propertyReplacement)if(m.propertyReplacement.hasOwnProperty(f)){var M=m.propertyReplacement[f],k=M[0],j=M[1];if(1===j)for(var a=0;a<m.rhs.length;a++)for(var x=m.rhs[a],c=0;c<x.length;c++){var O=x[c];concretizePropertyInCell(O,f,k)}}}for(var C="",t=0;t<d.length;t++){var m=d[t];delete d.propertyReplacement;for(var a=0;a<m.rhs.length;a++)for(var b=m.rhs[a],c=0;c<b.length;c++)for(var y=b[c],R=getPropertiesFromCell(e,y),u=0;u<R.length;u++)i.hasOwnProperty(R[u])&&(C=R[u])}return C.length>0&&logError('This rule has a property on the right-hand side, "'+C+"\", that can't be inferred from the left-hand side.  (either for every property on the right there has to be a corresponding one on the left in the same cell, OR, if there's a single occurrence of a particular property name on the left, all properties of the same name on the right are assumed to be the same).",o),d}function concretizeMovingRule(e,r,o){for(var t,n=[r],a=!0;a;){a=!1;for(var i=0;i<n.length;i++){var l=n[i];t=!1;for(var s=0;s<l.lhs.length;s++)for(var c=l.lhs[s],g=0;g<c.length;g++){var h=c[g],u=getMovings(e,h);if(u.length>0){t=!0,a=!0;for(var f=u[0][0],p=u[0][1],d=directionaggregates[p],v=0;v<d.length;v++){var m=d[v],b=deepCloneRule(l);b.movingReplacement={};for(var y in l.movingReplacement)if(l.movingReplacement.hasOwnProperty(y)){var R=l.movingReplacement[y];b.movingReplacement[y]=[R[0],R[1],R[3]]}concretizeMovingInCell(b.lhs[s][g],p,f,m),b.rhs.length>0&&concretizeMovingInCell(b.rhs[s][g],p,f,m),void 0===b.movingReplacement[f]?b.movingReplacement[f]=[m,1,p]:b.movingReplacement[f][1]=b.movingReplacement[f][1]+1,n.push(b)}}}t&&(n.splice(i,1),i--)}}for(var i=0;i<n.length;i++){var l=n[i];if(void 0!==l.movingReplacement){var w={};for(var f in l.movingReplacement)if(l.movingReplacement.hasOwnProperty(f)){var E=l.movingReplacement[f],k=E[0],D=E[1],I=E[2];if(w[I]=I in w||1!==D?"INVALID":k,1===D)for(var s=0;s<l.rhs.length;s++)for(var _=l.rhs[s],g=0;g<_.length;g++){var M=_[g];concretizeMovingInCell(M,I,f,k)}}for(var I in w)if(w.hasOwnProperty(I)&&"INVALID"!==I){k=w[I];for(var s=0;s<l.rhs.length;s++)for(var _=l.rhs[s],g=0;g<_.length;g++){var M=_[g];concretizeMovingInCellByAmbiguousMovementName(M,I,k)}}}}for(var j="",i=0;i<n.length;i++){var l=n[i];delete n.movingReplacement;for(var s=0;s<l.rhs.length;s++)for(var c=l.rhs[s],g=0;g<c.length;g++){var h=c[g],u=getMovings(e,h);u.length>0&&(j=u[0][1])}}return j.length>0&&logError('This rule has an ambiguous movement on the right-hand side, "'+j+"\", that can't be inferred from the left-hand side.  (either for every ambiguous movement associated to an entity on the right there has to be a corresponding one on the left attached to the same entity, OR, if there's a single occurrence of a particular ambiguous movement on the left, all properties of the same movement attached to the same object on the right are assumed to be the same (or something like that)).",o),n}function rephraseSynonyms(e,r){for(var o=0;o<r.lhs.length;o++)for(var t=r.lhs[o],n=r.rhs[o],a=0;a<t.length;a++){for(var i=t[a],l=1;l<i.length;l+=2){var s=i[l];s in e.synonymsDict&&(i[l]=e.synonymsDict[i[l]])}if(r.rhs.length>0)for(var c=n[a],l=1;l<c.length;l+=2){var s=c[l];s in e.synonymsDict&&(c[l]=e.synonymsDict[c[l]])}}}function atomizeAggregates(e,r){for(var o=0;o<r.lhs.length;o++)for(var t=r.lhs[o],n=0;n<t.length;n++){var a=t[n];atomizeCellAggregates(e,a,r.lineNumber)}for(var o=0;o<r.rhs.length;o++)for(var t=r.rhs[o],n=0;n<t.length;n++){var a=t[n];atomizeCellAggregates(e,a,r.lineNumber)}}function atomizeCellAggregates(e,r,o){for(var t=0;t<r.length;t+=2){var n=r[t],a=r[t+1];if(a in e.aggregatesDict){"no"===n&&logError("You cannot use 'no' to exclude the aggregate object "+a.toUpperCase()+" (defined using 'AND'), only regular objects, or properties (objects defined using 'OR').  If you want to do this, you'll have to write it out yourself the long way.",o);var i=e.aggregatesDict[a];r[t+1]=i[0];for(var l=1;l<i.length;l++)r.push(r[t]),r.push(i[l])}}}function convertRelativeDirsToAbsolute(e){for(var r=e.direction,o=0;o<e.lhs.length;o++)for(var t=e.lhs[o],n=0;n<t.length;n++){var a=t[n];absolutifyRuleCell(r,a)}for(var o=0;o<e.rhs.length;o++)for(var t=e.rhs[o],n=0;n<t.length;n++){var a=t[n];absolutifyRuleCell(r,a)}}function absolutifyRuleCell(e,r){for(var o=0;o<r.length;o+=2){var t=r[o],n=relativeDirs.indexOf(t);n>=0&&(r[o]=relativeDict[e][n])}}function rulesToMask(e){for(var r=e.collisionLayers.length,o=[],t=0;t<r;t++)o.push(null);for(var t=0;t<e.rules.length;t++)for(var n=e.rules[t],a=0;a<n.lhs.length;a++)for(var i=n.lhs[a],l=n.rhs[a],s=0;s<i.length;s++){for(var c=i[s],g=o.concat([]),h=new BitVec(STRIDE_OBJ),u=new BitVec(STRIDE_OBJ),f=[],p=new BitVec(STRIDE_MOV),d=new BitVec(STRIDE_MOV),v=new BitVec(STRIDE_MOV),m=0;m<c.length;m+=2){var b=c[m];if("..."===b){if(h=ellipsisPattern,2!==c.length)logError("You can't have anything in with an ellipsis. Sorry.",n.lineNumber);else if(0===s||s===i.length-1)logError("There's no point in putting an ellipsis at the very start or the end of a rule",n.lineNumber);else if(n.rhs.length>0){var y=l[s];2===y.length&&"..."===y[0]||logError("An ellipsis on the left must be matched by one in the corresponding place on the right.",n.lineNumber)}break}if("random"!==b){var R=c[m+1],w=e.objects[R],E=e.objectMasks[R];if(w)var k=0|w.layer;else var k=e.propertiesSingleLayer[R];if(void 0===k&&logError("Oops!  "+R.toUpperCase()+" not assigned to a layer.",n.lineNumber),"no"===b)u.ior(E);else{var D=g[k];null!==D&&logError("Rule matches object types that can't overlap: \""+R.toUpperCase()+'" and "'+D.toUpperCase()+'".',n.lineNumber),g[k]=R,w?(h.ior(E),v.ishiftor(31,5*k)):f.push(E),"stationary"===b?d.ishiftor(31,5*k):p.ishiftor(dirMasks[b],5*k)}}else logError("'random' cannot be matched on the left-hand side, it can only appear on the right",n.lineNumber)}if(n.rhs.length>0){var y=l[s],I=i[s];"..."===y[0]&&"..."!==I[0]&&logError("An ellipsis on the right must be matched by one in the corresponding place on the left.",n.lineNumber);for(var m=0;m<y.length;m+=2){var _=y[m];"..."===_&&2!==y.length&&logError("You can't have anything in with an ellipsis. Sorry.",n.lineNumber)}}if(h!==ellipsisPattern){if(i[s]=new CellPattern([h,u,f,p,d,null]),0!==n.rhs.length){for(var M=l[s],j=o.concat([]),x=new BitVec(STRIDE_OBJ),O=new BitVec(STRIDE_OBJ),C=new BitVec(STRIDE_MOV),N=new BitVec(STRIDE_MOV),S=new BitVec(STRIDE_MOV),T=new BitVec(STRIDE_OBJ),P=new BitVec(STRIDE_MOV),L=new BitVec(STRIDE_MOV),m=0;m<M.length;m+=2){var b=M[m],R=M[m+1];if("..."===b)break;if("random"!==b){var w=e.objects[R],E=e.objectMasks[R];if(w)var k=0|w.layer;else var k=e.propertiesSingleLayer[R];if("no"==b)x.ior(E);else{var D=j[k];null!==D&&logError("Rule matches object types that can't overlap: \""+R.toUpperCase()+'" and "'+D.toUpperCase()+'".',n.lineNumber),j[k]=R,b.length>0&&P.ishiftor(31,5*k);var A=e.layerMasks[k];w&&(O.ibitset(w.id),x.ior(A),S.ishiftor(31,5*k)),"stationary"===b&&C.ishiftor(31,5*k),"randomdir"===b?L.ishiftor(dirMasks[b],5*k):N.ishiftor(dirMasks[b],5*k)}}else if(R in e.objectMasks){var B=e.objectMasks[R];T.ior(B)}else logError('You want to spawn a random "'+R.toUpperCase()+"\", but I don't know how to do that",n.lineNumber)}h.bitsSetInArray(O.data)||x.ior(h),p.bitsSetInArray(N.data)||C.ior(p);for(var m=0;m<r;m++)null!==g[m]&&null===j[m]&&(x.ior(e.layerMasks[m]),P.ishiftor(31,5*m));v.iclear(S),P.ior(v),(x||O||C||N||P)&&(i[s].replacement=new CellReplacement([x,O,C,N,P,T,L]))}}else i[s]=ellipsisPattern}}function cellRowMasks(e){for(var r=[],o=e[1],t=0;t<o.length;t++){for(var n=o[t],a=new BitVec(STRIDE_OBJ),i=0;i<n.length;i++)n[i]!==ellipsisPattern&&a.ior(n[i].objectsPresent);r.push(a)}return r}function collapseRules(e){for(var r=0;r<e.length;r++)for(var o=e[r],t=0;t<o.length;t++){for(var n=o[t],a=[0,[],n.rhs.length>0,n.lineNumber],i=[],l=0;l<n.lhs.length;l++)i.push(!1);a[0]=dirMasks[n.direction];for(var l=0;l<n.lhs.length;l++){for(var s=n.lhs[l],c=0;c<s.length;c++)s[c]===ellipsisPattern&&(i[l]&&logError("You can't use two ellipses in a single cell match pattern.  If you really want to, please implement it yourself and send me a patch :) ",n.lineNumber),i[l]=!0);a[1][l]=s}a.push(i),a.push(n.groupNumber),a.push(n.rigid),a.push(n.commands),a.push(n.randomRule),a.push(n.viewDirRule),a.push(cellRowMasks(a)),o[t]=new Rule(a)}matchCache={}}function ruleGroupRandomnessTest(e){if(0!==e.length)for(var r=e[0].lineNumber,o=1;o<e.length;o++){var t=e[o];t.lineNumber!==r&&(t.randomRule&&logError("A rule-group can only be marked random by the first rule",t.lineNumber))}}function arrangeRulesByGroupNumber(e){for(var r={},o={},t=0;t<e.rules.length;t++){var n=e.rules[t],a=r;n.late&&(a=o),void 0==a[n.groupNumber]&&(a[n.groupNumber]=[]),a[n.groupNumber].push(n)}var i=[];for(var l in r)if(r.hasOwnProperty(l)){var s=r[l];ruleGroupRandomnessTest(s),i.push(s)}var c=[];for(var l in o)if(o.hasOwnProperty(l)){var s=o[l];ruleGroupRandomnessTest(s),c.push(s)}e.rules=i,e.lateRules=c}function checkNoLateRulesHaveMoves(e){for(var r=0;r<e.lateRules.length;r++)for(var o=e.lateRules[r],t=0;t<o.length;t++)for(var n=o[t],a=0;a<n.patterns.length;a++)for(var i=n.patterns[a],l=0;l<i.length;l++){var s=i[l];if(s!==ellipsisPattern){var c=s.movementsMissing,g=s.movementsPresent;if(!c.iszero()||!g.iszero())return void logError("Movements cannot appear in late rules.",n.lineNumber);if(null!=s.replacement){var h=s.replacement.movementsClear,u=s.replacement.movementsSet;if(!h.iszero()||!u.iszero())return void logError("Movements cannot appear in late rules.",n.lineNumber)}}}}function generateRigidGroupList(e){for(var r=[],o=[],t=[],n=[],a=[],i=0;i<e.rules.length;i++){for(var l=e.rules[i],s=!1,c=0;c<l.length;c++){l[c].isRigid&&(s=!0)}if(a[i]=s,s){var g=l[0].groupNumber;t[g]=i;var h=r.length;o[i]=h,n[g]=h,r.push(i)}}r.length>30&&logError("There can't be more than 30 rigid groups (rule groups containing rigid members).",rules[0][0][3]),e.rigidGroups=a,e.rigidGroupIndex_to_GroupIndex=r,e.groupNumber_to_RigidGroupIndex=n,e.groupIndex_to_RigidGroupIndex=o}function getMaskFromName(e,r){var o=new BitVec(STRIDE_OBJ);if(r in e.objects){var t=e.objects[r];o.ibitset(t.id)}if(r in e.aggregatesDict)for(var n=e.aggregatesDict[r],a=0;a<n.length;a++){var i=n[a],t=e.objects[i];o.ibitset(t.id)}if(r in e.propertiesDict)for(var n=e.propertiesDict[r],a=0;a<n.length;a++){var i=n[a],t=e.objects[i];o.ibitset(t.id)}if(r in e.synonymsDict){var i=e.synonymsDict[r],t=e.objects[i];o.ibitset(t.id)}return o.iszero()&&logErrorNoLine("error, didn't find any object called player, either in the objects section, or the legends section. there must be a player!"),o}function generateMasks(e){e.playerMask=getMaskFromName(e,"player");for(var r=[],o=e.collisionLayers.length,t=0;t<o;t++){for(var n=new BitVec(STRIDE_OBJ),a=0;a<e.objectCount;a++){var i=e.idDict[a],l=e.objects[i];l.layer==t&&n.ibitset(l.id)}r.push(n)}e.layerMasks=r;var s={};for(var i in e.objects)if(e.objects.hasOwnProperty(i)){var l=e.objects[i];s[i]=new BitVec(STRIDE_OBJ),s[i].ibitset(l.id)}var c=e.legend_synonyms.concat(e.legend_properties);c.sort(function(e,r){return e.lineNumber-r.lineNumber});for(var g=0;g<c.length;g++){var h=c[g];if(2==h.length)s[h[0]]=s[h[1]];else{for(var u=new BitVec(STRIDE_OBJ),a=1;a<h.length;a++){var i=h[a];u.ior(s[i])}s[h[0]]=u}}e.objectMasks=s}function checkObjectsAreLayered(e){for(var r in e.objects)if(e.objects.hasOwnProperty(r)){for(var o=!1,t=0;t<e.collisionLayers.length;t++){for(var n=e.collisionLayers[t],a=0;a<n.length;a++)if(n[a]===r){o=!0;break}if(o)break}if(!1===o){var i=e.objects[r];logError('Object "'+r.toUpperCase()+'" has been defined, but not assigned to a layer.',i.lineNumber)}}}function twiddleMetaData(e){for(var r={},o=0;o<e.metadata.length;o+=2){var t=e.metadata[o],n=e.metadata[o+1];r[t]=n}if(void 0!==r.flickscreen){var n=r.flickscreen,a=n.split("x"),i=[parseInt(a[0]),parseInt(a[1])];r.flickscreen=i}if(void 0!==r.zoomscreen){var n=r.zoomscreen,a=n.split("x"),i=[parseInt(a[0]),parseInt(a[1])];r.zoomscreen=i}e.metadata=r}function processWinConditions(e){for(var r=[],o=0;o<e.winconditions.length;o++){var t=e.winconditions[o];if(0==t.length)return;var n=0;switch(t[0]){case"no":n=-1;break;case"all":n=1}var a,i=t[t.length-1],l=t[1];a=5==t.length?t[3]:"background";var s=0,c=0;l in e.objectMasks?s=e.objectMasks[l]:logError('unwelcome term "'+l+'" found in win condition. Win conditions objects have to be objects or properties (defined using "or", in terms of other properties)',i),a in e.objectMasks?c=e.objectMasks[a]:logError('unwelcome term "'+a+'" found in win condition. Win conditions objects have to be objects or properties (defined using "or", in terms of other properties)',i);var g=[n,s,c,i];r.push(g)}e.winconditions=r}function printCellRow(e){for(var r="[ ",o=0;o<e.length;o++){o>0&&(r+="| ");for(var t=e[o],n=0;n<t.length;n+=2){var a=t[n],i=t[n+1];r+="..."===a?a+" ":a+" "+i+" "}}return r+="] "}function printRule(e){var r="(<a onclick=\"jumpToLine('"+e.lineNumber.toString()+'\');"  href="javascript:void(0);">'+e.lineNumber+"</a>) "+e.direction.toString().toUpperCase()+" ";e.rigid&&(r="RIGID "+r+" "),e.randomRule&&(r="RANDOM "+r+" "),e.viewDirRule&&(r="VIEWDIR "+r+" "),e.late&&(r="LATE "+r+" ");for(var o=0;o<e.lhs.length;o++){var t=e.lhs[o];r+=printCellRow(t)}r+="-> ";for(var o=0;o<e.rhs.length;o++){var t=e.rhs[o];r+=printCellRow(t)}for(var o=0;o<e.commands.length;o++){var n=e.commands[o];1===n.length?r+=n[0].toString():r=r+"("+n[0].toString()+", "+n[1].toString()+") "}return r}function printRules(e){for(var r="<br>Rule Assembly : ("+e.rules.length+" rules )<br>===========<br>",o=0,t=-1,n=0;n<e.rules.length;n++){var a=e.rules[n];o<e.loops.length&&e.loops[o][0]<a.lineNumber&&(r+="STARTLOOP<br>",++o<e.loops.length&&(t=e.loops[o][0],o++)),-1!==t&&t<a.lineNumber&&(r+="ENDLOOP<br>",t=-1),r+=printRule(a)+"<br>"}-1!==t&&(r+="ENDLOOP<br>"),r+="===========<br>",consolePrint(r)}function removeDuplicateRules(e){console.log("rule count before = "+e.rules.length);for(var r={},o=-1,t=e.rules.length-1;t>=0;t--){var n=e.rules[t],a=n.groupNumber;a!==o&&(r={});var i=printRule(n);r.hasOwnProperty(i)?e.rules.splice(t,1):r[i]=!0,o=a}console.log("rule count after = "+e.rules.length)}function generateLoopPoints(e){var r={},o=!0,t=0,n=0;e.loops.length%2==1&&logErrorNoLine("have to have matching number of  'startLoop' and 'endLoop' loop points.");for(var a=0;a<e.loops.length;a++)for(var i=e.loops[a],l=0;l<e.rules.length;l++){var s=e.rules[l],c=s[0],g=s[s.length-1],h=c.lineNumber;g.lineNumber;if(o){if(h>=i[0]){n=l,o=!1,-1===i[1]&&logErrorNoLine("Need have to have matching number of  'startLoop' and 'endLoop' loop points.");break}}else if(h>=i[0]){t=l-1,r[t]=n,o=!0,1===i[1]&&logErrorNoLine("Need have to have matching number of  'startLoop' and 'endLoop' loop points.");break}}if(!1===o){var t=e.rules.length;r[t]=n}e.loopPoint=r,r={},o=!0;for(var a=0;a<e.loops.length;a++)for(var i=e.loops[a],l=0;l<e.lateRules.length;l++){var s=e.lateRules[l],c=s[0],g=s[s.length-1],h=c.lineNumber;g.lineNumber;if(o){if(h>=i[0]){n=l,o=!1,-1===i[1]&&logErrorNoLine("Need have to have matching number of  'startLoop' and 'endLoop' loop points.");break}}else if(h>=i[0]){t=l-1,r[t]=n,o=!0,1===i[1]&&logErrorNoLine("Need have to have matching number of  'startLoop' and 'endLoop' loop points.");break}}if(!1===o){var t=e.lateRules.length;r[t]=n}e.lateLoopPoint=r}function validSeed(e){return null!==/^\s*\d+\s*$/.exec(e)}function generateSoundData(e){for(var r={},o=[],t=[],n=[],a=[],i=0;i<e.sounds.length;i++){var l=e.sounds[i];if(!(l.length<=1)){var s=l[l.length-1];if(2!==l.length)if(soundEvents.indexOf(l[0])>=0){l.length>4&&logError("too much stuff to define a sound event.",s);var c=l[1];validSeed(c)?(void 0!==r[l[0]]&&logWarning(l[0].toUpperCase()+" already declared.",s),
r[l[0]]=l[1]):logError('Expecting sfx data, instead found "'+l[1]+'".',s)}else{var g=l[0].trim(),h=l[1].trim(),u=l.slice(2,l.length-2);u.length>0&&"move"!==h&&"cantmove"!==h&&logError("incorrect sound declaration.",s),"action"===h&&(h="move",u=["___action____"]),0==u.length&&(u=["orthogonal"]);var c=l[l.length-2];g in e.aggregatesDict?logError('cannot assign sound fevents to aggregate objects (declared with "and"), only to regular objects, or properties, things defined in terms of "or" ("'+g+'").',s):g in e.objectMasks||logError('Object "'+g+'" not found.',s);for(var f=e.objectMasks[g],p=0,d=0;d<u.length;d++){u[d]=u[d].trim();var v=u[d];if(-1===soundDirectionIndicators.indexOf(v))logError('Was expecting a direction, instead found "'+v+'".',s);else{var m=soundDirectionIndicatorMasks[v];p|=m}}for(var b=[g],y=!0;y;){y=!1;for(var R=0;R<b.length;R++){var w=b[R];if(w in e.synonymsDict)b[R]=e.synonymsDict[w],y=!0;else if(w in e.propertiesDict){y=!0;var E=e.propertiesDict[w];b.splice(R,1),R--;for(var k=0;k<E.length;k++)b.push(E[k])}}}if("move"===h||"cantmove"===h)for(var d=0;d<b.length;d++){var D=b[d],I=e.objects[D],_=I.layer,M=new BitVec(STRIDE_MOV);M.ishiftor(p,5*_);var j={objectMask:f,directionMask:M,seed:c};"move"===h?n.push(j):a.push(j)}validSeed(c)||logError('Expecting sfx data, instead found "'+c+'".',s);switch(h){case"create":var j={objectMask:f,seed:c};o.push(j);break;case"destroy":var j={objectMask:f,seed:c};t.push(j)}}else logError("incorrect sound declaration.",s)}}e.sfx_Events=r,e.sfx_CreationMasks=o,e.sfx_DestructionMasks=t,e.sfx_MovementMasks=n,e.sfx_MovementFailureMasks=a}function formatHomePage(e){if("background_color"in e.metadata?e.bgcolor=colorToHex(colorPalette,e.metadata.background_color):e.bgcolor="#000000","text_color"in e.metadata?e.fgcolor=colorToHex(colorPalette,e.metadata.text_color):e.fgcolor="#FFFFFF",!1===isColor(e.fgcolor)&&logError("text_color in incorrect format - found "+e.fgcolor+", but I expect a color name (like 'pink') or hex-formatted color (like '#1412FA')."),!1===isColor(e.bgcolor)&&logError("background_color in incorrect format - found "+e.bgcolor+", but I expect a color name (like 'pink') or hex-formatted color (like '#1412FA')."),canSetHTMLColors&&("background_color"in e.metadata&&(document.body.style.backgroundColor=e.bgcolor),"text_color"in e.metadata)){var r=document.getElementById("separator");null!=r&&(r.style.color=e.fgcolor);for(var o=document.getElementsByTagName("a"),t=0;t<o.length;t++)o[t].style.color=e.fgcolor;for(var o=document.getElementsByTagName("h1"),t=0;t<o.length;t++)o[t].style.color=e.fgcolor}if("homepage"in e.metadata){var n=e.metadata.homepage;n=n.replace("http://",""),n=n.replace("https://",""),e.metadata.homepage=n}}function loadFile(e){window.console.log("loadFile");for(var r=new codeMirrorFn,o=r.startState(),t=e.split("\n"),n=0;n<t.length;n++){var a=t[n];o.lineNumber=n+1;var i=new CodeMirror.StringStream(a,4);do{if(r.token(i,o),errorCount>MAX_ERRORS)return void consolePrint("too many errors, aborting compilation")}while(!1===i.eol())}return delete o.lineNumber,generateExtraMembers(o),generateMasks(o),levelsToArray(o),rulesToArray(o),removeDuplicateRules(o),debugMode&&printRules(o),rulesToMask(o),arrangeRulesByGroupNumber(o),collapseRules(o.rules),collapseRules(o.lateRules),checkNoLateRulesHaveMoves(o),generateRigidGroupList(o),processWinConditions(o),checkObjectsAreLayered(o),twiddleMetaData(o),generateLoopPoints(o),generateSoundData(o),formatHomePage(o),delete o.commentLevel,delete o.names,delete o.abbrevNames,delete o.objects_candname,delete o.objects_section,delete o.objects_spritematrix,delete o.section,delete o.subsection,delete o.tokenIndex,delete o.visitedSections,delete o.loops,o}function compile(e,r,o){if(matchCache={},forceRegenImages=!0,void 0===e&&(e=["restart"]),void 0===o&&(o=null),lastDownTarget=canvas,void 0===r){r=window.form1.code.editorreference.getValue()+"\n"}!0===canDump&&(compiledText=r),errorCount=0,compiling=!0,errorStrings=[],consolePrint("=================================");try{var t=loadFile(r)}finally{compiling=!1}if(!(errorCount>MAX_ERRORS)){if(errorCount>0)consoleError('<span class="systemMessage">Errors detected during compilation, the game may not work correctly.</span>');else{for(var n=0,a=0;a<t.rules.length;a++)n+=t.rules[a].length;for(var a=0;a<t.lateRules.length;a++)n+=t.lateRules[a].length;"restart"==e[0]?consolePrint('<span class="systemMessage">Successful Compilation, generated '+n+" instructions.</span>"):consolePrint('<span class="systemMessage">Successful live recompilation, generated '+n+" instructions.</span>")}setGameState(t,e,o),clearInputHistory(),consoleCacheDump()}}function qualifyURL(e){var r=document.createElement("a");return r.href=e,r.href}var debugMode,colorPalette;Level.prototype.calcBackgroundMask=function(e){void 0===e.backgroundlayer&&logError("you have to have a background layer");for(var r=e.layerMasks[e.backgroundlayer],o=0;o<this.n_tiles;o++){var t=this.getCell(o);if(t.iand(r),!t.iszero())return t}return t=new BitVec(STRIDE_OBJ),t.ibitset(e.backgroundid),t};var directionaggregates={horizontal:["left","right"],vertical:["up","down"],moving:["up","down","left","right","action"],orthogonal:["up","down","left","right"],perpendicular:["^","v"],parallel:["<",">"]},relativeDirections=["^","v","<",">","horizontal","vertical"],simpleAbsoluteDirections=["up","down","left","right"],simpleRelativeDirections=["^","v","<",">"],reg_directions_only=/^(\>|\<|\^|v|up|down|left|right|moving|stationary|no|randomdir|random|horizontal|vertical|orthogonal|perpendicular|parallel|action)$/,commandwords=["sfx0","sfx1","sfx2","sfx3","sfx4","sfx5","sfx6","sfx7","sfx8","sfx9","sfx10","cancel","checkpoint","restart","win","message","again"],relativeDirs=["^","v","<",">","parallel","perpendicular"],relativeDict={right:["up","down","left","right","horizontal","vertical"],up:["left","right","down","up","vertical","horizontal"],down:["right","left","up","down","vertical","horizontal"],left:["down","up","right","left","horizontal","vertical"]},dirMasks={up:parseInt("00001",2),down:parseInt("00010",2),left:parseInt("00100",2),right:parseInt("01000",2),moving:parseInt("01111",2),no:parseInt("00011",2),randomdir:parseInt("00101",2),random:parseInt("10010",2),action:parseInt("10000",2),"":parseInt("00000",2),all:parseInt("11111",2)},soundEvents=["titlescreen","startgame","cancel","endgame","startlevel","undo","restart","endlevel","showmessage","closemessage","sfx0","sfx1","sfx2","sfx3","sfx4","sfx5","sfx6","sfx7","sfx8","sfx9","sfx10"],soundMaskedEvents=["create","destroy","move","cantmove","action"],soundVerbs=soundEvents.concat(soundMaskedEvents),soundDirectionIndicatorMasks={up:parseInt("00001",2),down:parseInt("00010",2),left:parseInt("00100",2),right:parseInt("01000",2),horizontal:parseInt("01100",2),vertical:parseInt("00011",2),orthogonal:parseInt("01111",2),___action____:parseInt("10000",2)},soundDirectionIndicators=["up","down","left","right","horizontal","vertical","orthogonal","___action____"],MAX_ERRORS=5,ifrm;</script> <script>function selectText(e,t){t=t||window.event;var o=document.getElementById(e);if(t&&(t.ctrlKey||t.metaKey)){var r=["console"].concat(o.innerHTML.split("<br>")),n=levelFromString(state,r);loadLevelFromLevelDat(state,n,null),canvasResize()}else if(document.selection){var l=document.body.createTextRange();l.moveToElementText(o),l.select()}else if(window.getSelection){var l=document.createRange();l.selectNode(o),window.getSelection().addRange(l)}}function recalcLevelBounds(){}function arrCopy(e,t,o,r,n){for(;n--;)o[r++]=e[t]++}function adjustLevel(e,t,o){backups.push(backupLevel());var r=e.clone();e.width+=t,e.height+=o,e.n_tiles=e.width*e.height,e.objects=new Int32Array(e.n_tiles*STRIDE_OBJ);var n=new BitVec(STRIDE_OBJ);n.ibitset(state.backgroundid);for(var l=0;l<e.n_tiles;++l)e.setCell(l,n);return e.movements=new Int32Array(e.objects.length),columnAdded=!0,RebuildLevelArrays(),r}function addLeftColumn(){for(var e=adjustLevel(level,1,0),t=1;t<level.width;++t)for(var o=0;o<level.height;++o){var r=t*level.height+o;level.setCell(r,e.getCell(r-level.height))}}function addRightColumn(){for(var e=adjustLevel(level,1,0),t=0;t<level.width-1;++t)for(var o=0;o<level.height;++o){var r=t*level.height+o;level.setCell(r,e.getCell(r))}}function addTopRow(){for(var e=adjustLevel(level,0,1),t=0;t<level.width;++t)for(var o=1;o<level.height;++o){var r=t*level.height+o;level.setCell(r,e.getCell(r-t-1))}}function addBottomRow(){for(var e=adjustLevel(level,0,1),t=0;t<level.width;++t)for(var o=0;o<level.height-1;++o){var r=t*level.height+o;level.setCell(r,e.getCell(r-t))}}function removeLeftColumn(){if(!(level.width<=1))for(var e=adjustLevel(level,-1,0),t=0;t<level.width;++t)for(var o=0;o<level.height;++o){var r=t*level.height+o;level.setCell(r,e.getCell(r+level.height))}}function removeRightColumn(){if(!(level.width<=1))for(var e=adjustLevel(level,-1,0),t=0;t<level.width;++t)for(var o=0;o<level.height;++o){var r=t*level.height+o;level.setCell(r,e.getCell(r))}}function removeTopRow(){if(!(level.height<=1))for(var e=adjustLevel(level,0,-1),t=0;t<level.width;++t)for(var o=0;o<level.height;++o){var r=t*level.height+o;level.setCell(r,e.getCell(r+t+1))}}function removeBottomRow(){if(!(level.height<=1))for(var e=adjustLevel(level,0,-1),t=0;t<level.width;++t)for(var o=0;o<level.height;++o){var r=t*level.height+o;level.setCell(r,e.getCell(r+t))}}function matchGlyph(e,t){for(var o,r=-1,n=0;n<t.length;++n){var l=t[n][0],a=t[n][1],i=t[n][2];if(a.bitsSetInArray(e.data)){for(var s=0,d=0;d<32*STRIDE_OBJ;++d)i.get(d)&&e.get(d)&&s++,a.get(d)&&e.get(d)&&s++;s>r&&(r=s,o=l)}}return r>0?o:(logErrorNoLine("Wasn't able to approximate a glyph value for some tiles, using '.' as a placeholder.",!0),".")}function printLevel(){var e=[];for(var t in state.glyphDict)if(state.glyphDict.hasOwnProperty(t)&&1===t.length){for(var o=state.glyphDict[t],r=new BitVec(STRIDE_OBJ),n=0;n<o.length;n++){var l=o[n];l>=0&&r.ibitset(l)}var a=r.clone(),i=state.layerMasks[state.backgroundlayer];r.iclear(i),e.push([t,r,a])}selectableint++;var s="selectable"+selectableint,d='Printing level contents:<br><br><span id="'+s+'" onclick="selectText(\''+s+"',event)\">";cache_console_messages=!1;for(var c=0;c<level.height;c++){for(var n=0;n<level.width;n++){var u=c+n*level.height,v=level.getCell(u),o=matchGlyph(v,e);o in htmlEntityMap&&(o=htmlEntityMap[o]),d+=o}c<level.height-1&&(d+="<br>")}d+="</span><br><br>",consolePrint(d,!0)}function levelEditorClick(e,t){if(mouseCoordY<=-2){var o=editorRowCount-(-mouseCoordY-2)-1,r=mouseCoordX+(screenwidth-1)*o;-1===mouseCoordX?printLevel():mouseCoordX>=0&&r<glyphImages.length&&(glyphSelectedIndex=r,redraw())}else if(mouseCoordX>-1&&mouseCoordY>-1&&mouseCoordX<screenwidth-2&&mouseCoordY<screenheight-2-editorRowCount){for(var n=glyphImagesCorrespondance[glyphSelectedIndex],l=state.glyphDict[n],a=new BitVec(STRIDE_OBJ),i=0;i<l.length;i++){var s=l[i];s>=0&&a.ibitset(s)}var d=state.layerMasks[state.backgroundlayer];a.bitsClearInArray(d.data)&&a.ibitset(state.backgroundid);var c=mouseCoordY+mouseCoordX*level.height,u=level.getCell(c);if(u.equals(a))return;!1===anyEditsSinceMouseDown&&(anyEditsSinceMouseDown=!0,backups.push(backupLevel())),level.setCell(c,a),redraw()}else t&&(-1===mouseCoordX?(addLeftColumn(),canvasResize()):mouseCoordX===screenwidth-2&&(addRightColumn(),canvasResize()),-1===mouseCoordY?(addTopRow(),canvasResize()):mouseCoordY===screenheight-2-editorRowCount&&(addBottomRow(),canvasResize()))}function levelEditorRightClick(e,t){if(-2===mouseCoordY)mouseCoordX<=glyphImages.length&&(glyphSelectedIndex=mouseCoordX,redraw());else if(mouseCoordX>-1&&mouseCoordY>-1&&mouseCoordX<screenwidth-2&&mouseCoordY<screenheight-2-editorRowCount){var o=mouseCoordY+mouseCoordX*level.height,r=new BitVec(STRIDE_OBJ);r.ibitset(state.backgroundid),level.setCell(o,r),redraw()}else t&&(-1===mouseCoordX?(removeLeftColumn(),canvasResize()):mouseCoordX===screenwidth-2&&(removeRightColumn(),canvasResize()),-1===mouseCoordY?(removeTopRow(),canvasResize()):mouseCoordY===screenheight-2-editorRowCount&&(removeBottomRow(),canvasResize()))}function onMouseDown(e){if(0!==e.button||e.ctrlKey||e.metaKey){if((2===e.button||0===e.button&&(e.ctrlKey||e.metaKey))&&"gameCanvas"===e.target.id&&(dragging=!1,rightdragging=!0,levelEditorOpened))return levelEditorRightClick(e,!0)}else{if(lastDownTarget=e.target,keybuffer=[],e.target===canvas&&(setMouseCoord(e),dragging=!0,rightdragging=!1,levelEditorOpened))return anyEditsSinceMouseDown=!1,levelEditorClick(e,!0);dragging=!1,rightdragging=!1}}function rightClickCanvas(e){return prevent(e)}function onMouseUp(e){dragging=!1,rightdragging=!1}function onKeyDown(e){e=e||window.event,!IDE&&[32,37,38,39,40].indexOf(e.keyCode)>-1&&prevent(e),keybuffer.indexOf(e.keyCode)>=0||((lastDownTarget===canvas||lastDownTarget===canvas3d||window.Mobile&&lastDownTarget===window.Mobile.focusIndicator)&&-1===keybuffer.indexOf(e.keyCode)&&(keybuffer.splice(keyRepeatIndex,0,e.keyCode),keyRepeatTimer=0,checkKey(e,!0)),!0===canDump&&74===e.keyCode&&(e.ctrlKey||e.metaKey)&&(dumpTestCase(),prevent(e)))}function relMouseCoords(e){var t=0,o=0,r=0,n=0,l=this;do{t+=l.offsetLeft-l.scrollLeft,o+=l.offsetTop-l.scrollTop}while(l=l.offsetParent);return r=e.pageX-t,n=e.pageY-o,{x:r,y:n}}function onKeyUp(e){e=e||window.event;var t=keybuffer.indexOf(e.keyCode);t>=0&&(keybuffer.splice(t,1),keyRepeatIndex>=t&&keyRepeatIndex--)}function onMyFocus(e){keybuffer=[],keyRepeatIndex=0,keyRepeatTimer=0}function onMyBlur(e){keybuffer=[],keyRepeatIndex=0,keyRepeatTimer=0}function setMouseCoord(e){var t=canvas.relMouseCoords(e);mouseCoordX=t.x-xoffset,mouseCoordY=t.y-yoffset,mouseCoordX=Math.floor(mouseCoordX/cellwidth),mouseCoordY=Math.floor(mouseCoordY/cellheight)}function mouseMove(e){levelEditorOpened&&(setMouseCoord(e),dragging?levelEditorClick(e,!1):rightdragging&&levelEditorRightClick(e,!1),redraw())}function mouseOut(){}function prevent(e){return e.preventDefault&&e.preventDefault(),e.stopImmediatePropagation&&e.stopImmediatePropagation(),e.stopPropagation&&e.stopPropagation(),e.returnValue=!1,!1}function checkKey(e,t){if(!winning){var o=-1;switch(e.keyCode){case 65:o=5;break;case 37:o=1;break;case 38:case 87:o=0;break;case 68:o=6;break;case 39:o=3;break;case 83:case 40:o=2;break;case 13:case 32:case 67:case 88:if(!1!==norepeat_action&&!t)return;o=4;break;case 85:case 90:if(!1===textMode)return pushInput("undo"),DoUndo(!1,!0),canvasResize(),prevent(e);break;case 82:if(!1===textMode&&t)return pushInput("restart"),DoRestart(),canvasResize(),prevent(e);break;case 27:if(!1===titleScreen)return goToTitleScreen(),tryPlayTitleSound(),canvasResize(),prevent(e);break;case 69:if(canOpenEditor)return t&&(levelEditorOpened=!levelEditorOpened,!1===levelEditorOpened&&printLevel(),restartTarget=backupLevel(),canvasResize()),prevent(e);break;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:if(levelEditorOpened&&t){var r=9;return e.keyCode>=49&&(r=e.keyCode-49),r<glyphImages.length?glyphSelectedIndex=r:consolePrint("Trying to select tile outside of range in level editor.",!0),canvasResize(),prevent(e)}}if(throttle_movement&&(o>=0&&o<=3||5==o||6==o)){if(lastinput==o&&input_throttle_timer<repeatinterval)return;lastinput=o,input_throttle_timer=0}if(textMode){if(0===state.levels.length);else if(titleScreen)0===titleMode?4===o&&t&&!1===titleSelected&&(tryPlayStartGameSound(),titleSelected=!0,messageselected=!1,timer=0,quittingTitleScreen=!0,generateTitleScreen(),canvasResize()):4==o&&t?!1===titleSelected&&(tryPlayStartGameSound(),titleSelected=!0,messageselected=!1,timer=0,quittingTitleScreen=!0,generateTitleScreen(),redraw()):0!==o&&2!==o||(titleSelection=0===o?0:1,generateTitleScreen(),redraw());else if(4==o&&t){if(unitTesting)return void nextLevel();!1===messageselected&&(messageselected=!0,timer=0,quittingMessageScreen=!0,tryPlayCloseMessageSound(),titleScreen=!1,drawMessageScreen())}}else if(!againing&&o>=0)return 4===o&&"noaction"in state.metadata||(pushInput(o),processInput(o)&&redraw()),prevent(e)}}function update(){var e=Date.now();if(deltatime=e-lastTime,lastTime=e,void 0!=backups){var t=backups.length,o=!1;displayIndex>t?(displayIndex=t,interpolating=0,o=!0):(interpolating>0&&(interpolating=Math.max(interpolating-deltatime*(t-displayIndex+1)/interpolationInterval,0),o=!0),0==interpolating&&displayIndex<t&&(displayIndex+=1,interpolating=1,o=!0)),o&&redraw()}if(timer+=deltatime,input_throttle_timer+=deltatime,quittingTitleScreen&&timer/1e3>.3&&(quittingTitleScreen=!1,nextLevel()),againing&&timer>againinterval&&0==messagetext.length&&processInput(-1)&&(redraw(),keyRepeatTimer=0,autotick=0),quittingMessageScreen&&timer/1e3>.15&&(quittingMessageScreen=!1,""===messagetext?nextLevel():(messagetext="",textMode=!1,titleScreen=!1,titleMode=curlevel>0||null!==curlevelTarget?1:0,titleSelected=!1,titleSelection=0,canvasResize(),checkWin())),winning&&timer/1e3>.5&&(winning=!1,nextLevel()),keybuffer.length>0){keyRepeatTimer+=deltatime;var r=throttle_movement?repeatinterval:repeatinterval/Math.sqrt(keybuffer.length);if(keyRepeatTimer>r){keyRepeatTimer=0,keyRepeatIndex=(keyRepeatIndex+1)%keybuffer.length;checkKey({keyCode:keybuffer[keyRepeatIndex]},!1)}}!(autotickinterval>0)||textMode||levelEditorOpened||againing||winning||(autotick+=deltatime,autotick>autotickinterval&&(autotick=0,pushInput("tick"),processInput(-1)&&redraw()))}var keyRepeatTimer=0,keyRepeatIndex=0,input_throttle_timer=0,lastinput=-100,dragging=!1,rightdragging=!1,columnAdded=!1,htmlEntityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"},selectableint=0,anyEditsSinceMouseDown=!1;HTMLCanvasElement.prototype.relMouseCoords=relMouseCoords;var mouseCoordX=0,mouseCoordY=0;document.addEventListener("mousedown",onMouseDown,!1),document.addEventListener("mouseup",onMouseUp,!1),document.addEventListener("keydown",onKeyDown,!1),document.addEventListener("keyup",onKeyUp,!1),window.addEventListener("focus",onMyFocus,!1),window.addEventListener("blur",onMyBlur,!1),lastTime=Date.now(),setInterval(function(){update()},deltatime);</script> <script>function Animatable(t,i,e){function n(){var t;return a+=i,a>=1&&(t=!0,a=1),e(a),t}function s(){var t;return a-=i,a<=0&&(t=!0,a=0),e(a),t}var a,o;return o={animateUp:function(){Animator.getInstance().animate(t,n)},animateDown:function(){Animator.getInstance().animate(t,s)}},a=0,o}window.Mobile={},Mobile.hasTouch=function(){var t;return("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch)&&(t=!0),t},Mobile.enable=function(t){return(t||Mobile.hasTouch()&&!Mobile._instance)&&(Mobile._instance=new Mobile.GestureHandler,Mobile._instance.bindEvents(),Mobile._instance.bootstrap()),Mobile._instance},window.Mobile.GestureHandler=function(){this.initialize.apply(this,arguments)},Mobile.log=function(t){var i;i=document.getElementsByTagName("h1")[0],i.innerHTML=Math.random().toString().substring(4,1)+"-"+t},Mobile.debugDot=function(t){var i,e,n;n="border-radius: 50px;width: 5px;height: 5px;background: red;position: absolute;left: "+t.touches[0].clientX+"px;top: "+t.touches[0].clientY+"px;",i=document.createElement("div"),i.setAttribute("style",n),e=document.getElementsByTagName("body")[0],e.appendChild(i)},function(t){"use strict";var i={action:88,left:37,right:39,up:38,down:40,undo:85,restart:82,quit:27},e=['<div class="tab">','  <div class="tab-affordance"></div>','  <div class="tab-icon">','    <div class="slice"></div>','    <div class="slice"></div>',"  </div>","</div>"].join("\n");t.initialize=function(){this.firstPos={x:0,y:0},this.setTabAnimationRatio=this.setTabAnimationRatio.bind(this),this.setMenuAnimationRatio=this.setMenuAnimationRatio.bind(this),this.repeatTick=this.repeatTick.bind(this),this.isFocused=!0},t.setFocusElement=function(t){this.focusElement=t,this.isFocused=!1,this.buildFocusIndicator()},t.bindEvents=function(){window.addEventListener("touchstart",this.onTouchStart.bind(this)),window.addEventListener("touchend",this.onTouchEnd.bind(this)),window.addEventListener("touchmove",this.onTouchMove.bind(this))},t.bootstrap=function(){this.showTab(),this.isAudioSupported()||this.disableAudio(),this.disableSelection()},t.onTouchStart=function(t){this.isTouching||(this.handleFocusChange(t),this.isFocused&&"A"!==t.target.tagName.toUpperCase()&&(this.isTouching=!0,this.mayBeSwiping=!0,this.gestured=!1,this.swipeDirection=void 0,this.swipeDistance=0,this.startTime=(new Date).getTime(),this.firstPos.x=t.touches[0].clientX,this.firstPos.y=t.touches[0].clientY))},t.onTouchEnd=function(t){this.isFocused&&this.isTouching&&(this.gestured||0===t.touches.length&&this.handleTap(),0===t.touches.length&&(this.isTouching=!1,this.endRepeatWatcher()))},t.onTouchMove=function(t){if(this.isFocused)return this.isSuccessfulSwipe()?(this.handleSwipe(this.swipeDirection,this.touchCount),this.gestured=!0,this.mayBeSwiping=!1,this.beginRepeatWatcher(t)):this.mayBeSwiping?this.swipeStep(t):this.isRepeating&&this.repeatStep(t),prevent(t),!1},t.handleFocusChange=function(t){this.focusElement&&(this.isFocused=this.isTouchInsideFocusElement(t),this.setFocusIndicatorVisibility(this.isFocused))},t.isTouchInsideFocusElement=function(t){var i;return!(!t.touches||!t.touches[0])&&(i=this.absoluteElementPosition(this.focusElement),!(t.touches[0].clientX<i.left||t.touches[0].clientY<i.top)&&!(t.touches[0].clientX>i.left+this.focusElement.clientWidth||t.touches[0].clientY>i.top+this.focusElement.clientHeight))},t.setFocusIndicatorVisibility=function(t){var i;i="visible",t||(i="hidden"),this.focusIndicator.setAttribute("style","visibility: "+i+";")},t.absoluteElementPosition=function(t){var i,e;for(i={top:t.offsetTop||0,left:t.offsetLeft||0},e=document.getElementsByTagName("body")[0],i.top-=e.scrollTop||0;;){if(!(t=t.offsetParent))break;i.top+=t.offsetTop||0,i.left+=t.offsetLeft||0}return i},t.beginRepeatWatcher=function(t){var i;this.repeatInterval||(this.isRepeating=!0,i=1e3*state.metadata.key_repeat_interval,!isNaN(i)&&i||(i=150),this.repeatInterval=setInterval(this.repeatTick,i),this.recenter(t))},t.endRepeatWatcher=function(){this.repeatInterval&&(clearInterval(this.repeatInterval),delete this.repeatInterval,this.isRepeating=!1)},t.repeatTick=function(){this.isTouching&&this.handleSwipe(this.direction,this.touchCount)},t.recenter=function(t){this.firstPos.x=t.touches[0].clientX,this.firstPos.y=t.touches[0].clientY},t.isSuccessfulSwipe=function(){var t;return this.mayBeSwiping&&void 0!==this.swipeDirection&&this.swipeDistance>=50&&(t=!0),t},t.swipeStep=function(t){var i,e,n;this.mayBeSwiping&&(i={x:t.touches[0].clientX,y:t.touches[0].clientY},e=(new Date).getTime(),n=t.touches.length,this.swipeDistance=this.cardinalDistance(this.firstPos,i),this.swipeDirection?e-this.startTime>1e3&&(this.mayBeSwiping=!1):this.swipeDistance>10&&(this.swipeDirection=this.dominantDirection(this.firstPos,i),this.touchCount=n))},t.repeatStep=function(t){var i,e;i={x:t.touches[0].clientX,y:t.touches[0].clientY},(e=this.cardinalDistance(this.firstPos,i))>=50&&(this.swipeDirection=this.dominantDirection(this.firstPos,i),this.recenter(t))},t.cardinalDistance=function(t,i){var e,n;return e=Math.abs(t.x-i.x),n=Math.abs(t.y-i.y),Math.max(e,n)},t.dominantDirection=function(t,i){var e,n,s;return e=i.x-t.x,n=i.y-t.y,s="x",Math.abs(n)>Math.abs(e)&&(s="y"),textMode?"x"===s?e>0?"right":"left":n>0?"down":"up":"x"===s?e>0?"left":"right":n>0?"up":"down"},t.handleSwipe=function(t,i){1===i?this.emitKeydown(this.swipeDirection):i>1&&this.toggleMenu()},t.handleTap=function(){this.emitKeydown("action")},t.emitKeydown=function(t){var e;e={keyCode:i[t]},this.fakeCanvasFocus(),onKeyDown(e),onKeyUp(e)},t.fakeCanvasFocus=function(){var t;t=document.getElementById("gameCanvas"),onMouseDown({button:0,target:t})},t.toggleMenu=function(){this.isMenuVisible?this.hideMenu():this.showMenu()},t.showMenu=function(){this.menuElem||this.buildMenu(),this.getAnimatables().menu.animateUp(),this.isMenuVisible=!0,this.hideTab()},t.hideMenu=function(){this.menuElem&&this.getAnimatables().menu.animateDown(),this.isMenuVisible=!1,this.showTab()},t.getAnimatables=function(){var t=this;return this._animatables||(this._animatables={tab:Animatable("tab",.1,t.setTabAnimationRatio),menu:Animatable("menu",.1,t.setMenuAnimationRatio)}),this._animatables},t.showTab=function(){this.tabElem||this.buildTab(),this.getAnimatables().tab.animateDown()},t.hideTab=function(){this.tabElem&&this.tabElem.setAttribute("style","display: none;"),this.getAnimatables().tab.animateUp()},t.buildTab=function(){var t,i,n,s,a=this;t=document.createElement("div"),t.innerHTML=e,s=t.children[0],n=function(t){t.stopPropagation(),a.showMenu()},this.tabAffordance=s.getElementsByClassName("tab-affordance")[0],this.tabElem=s.getElementsByClassName("tab-icon")[0],this.tabAffordance.addEventListener("touchstart",n),this.tabElem.addEventListener("touchstart",n),i=document.getElementsByTagName("body")[0],i.appendChild(s)},t.buildMenu=function(){var t,i,e,n,s,a,o,c=this;t=document.createElement("div"),t.innerHTML=this.buildMenuString(state),this.menuElem=t.children[0],this.closeElem=this.menuElem.getElementsByClassName("close")[0],o=function(t){t.stopPropagation(),c.hideMenu()},this.closeAffordance=this.menuElem.getElementsByClassName("close-affordance")[0],a=this.menuElem.getElementsByClassName("close")[0],this.closeAffordance.addEventListener("touchstart",o),a.addEventListener("touchstart",o),e=this.menuElem.getElementsByClassName("undo")[0],e&&e.addEventListener("touchstart",function(t){t.stopPropagation(),c.emitKeydown("undo")}),n=this.menuElem.getElementsByClassName("restart")[0],n&&n.addEventListener("touchstart",function(t){t.stopPropagation(),c.emitKeydown("restart")}),s=this.menuElem.getElementsByClassName("quit")[0],s.addEventListener("touchstart",function(t){t.stopPropagation(),c.emitKeydown("quit")}),i=document.getElementsByTagName("body")[0],i.appendChild(this.menuElem)},t.buildMenuString=function(t){var i,e,n,s;return n=t.metadata.noundo,s=t.metadata.norestart,i=3,n&&(i-=1),s&&(i-=1),e=['<div class="mobile-menu item-count-'+i+'">','  <div class="close-affordance"></div>','  <div class="close">','    <div class="slice"></div>','    <div class="slice"></div>',"  </div>"],n||e.push('  <div class="undo button">Undo</div>'),s||e.push('  <div class="restart button">Restart</div>'),e=e.concat(['  <div class="quit button">Quit to Menu</div>','  <div class="clear"></div>',"</div>"]),e.join("\n")},t.buildFocusIndicator=function(){var t;this.focusIndicator=document.createElement("DIV"),this.focusIndicator.setAttribute("class","tapFocusIndicator"),this.focusIndicator.setAttribute("style","visibility: hidden;"),t=this.focusElement.parentNode,t.appendChild(this.focusIndicator)},t.setTabAnimationRatio=function(t){var i,e,n;t=Math.round(1e3*t)/1e3,t>=.999?this.tabAffordance.setAttribute("style","display: none;"):this.tabAffordance.setAttribute("style","display: block;"),i=66*t+18*(1-t),e="opacity: "+(1-t)+";",n=e+" width: "+i+"px;",this.tabElem.setAttribute("style",n)},t.setMenuAnimationRatio=function(t){var i,e,n;t=Math.round(1e3*t)/1e3,t<=.001?this.closeAffordance.setAttribute("style","display: none;"):this.closeAffordance.setAttribute("style","display: block;"),i=-18*t+-66*(1-t),e="opacity: "+t+";",n="left: "+(i-4)+"px; "+e+" width: "+-i+"px;",this.closeElem.setAttribute("style",n),this.menuElem.setAttribute("style",e)},t.disableAudio=function(){window.playSeed=function(){}},t.isAudioSupported=function(){var t=!0;return"undefined"!=typeof webkitAudioContext&&(t=!1),t},t.disableSelection=function(){var t;t=document.getElementsByTagName("body")[0],t.setAttribute("class",t.getAttribute("class")+" disable-select")}}(window.Mobile.GestureHandler.prototype),window.Animator=function(){this.initialize.apply(this,arguments)},function(t){t.initialize=function(){this._animations={},this.tick=this.tick.bind(this)},t.animate=function(t,i){this._animations[t]=i,this.wakeup()},t.wakeup=function(){this._isAnimating||(this._isAnimating=!0,this.tick())},t.tick=function(){var t,i,e,n,s;n=[],e=!0;for(t in this._animations){if(!this._animations.hasOwnProperty(t))return;i=this._animations[t](),i?n.push(t):e=!1}if(e){for(s=0;s<n.length;n++)delete this._isAnimating[n[s]];this._isAnimating=!1}else requestAnimationFrame(this.tick)}}(window.Animator.prototype),window.Animator.getInstance=function(){return window.Animator._instance||(window.Animator._instance=new window.Animator),window.Animator._instance},function(){"use strict";var t,i,e=["ms","moz","webkit","o"];for(t=0;t<e.length&&!window.requestAnimationFrame;t++)window.requestAnimationFrame=window[e[t]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e[t]+"CancelAnimationFrame"],window.cancelAnimationFrame||(window.cancelAnimationFrame=window[e[t]+"CancelRequestAnimationFrame"]);window.requestAnimationFrame||(i=0,window.requestAnimationFrame=function(t,e){var n,s,a;return n=(new Date).getTime(),s=Math.max(0,16-(n-i)),a=window.setTimeout(function(){t(n+s)},s),i=n+s,a}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)})}();</script> <script>var sourceCode=__GAMEDAT__;compile(["restart"],sourceCode);</script> </body> </html> 
