mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 22:01:58 -05:00
1 line
No EOL
39 KiB
JavaScript
1 line
No EOL
39 KiB
JavaScript
var CodeMirror=function(){function D(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;c<d;++c)if(a[c]==b)return c;return-1}function C(a,b){if(!b)return a?a.length:0;if(!a)return b.length;for(var c=a.length,d=b.length;c>=0&&d>=0;--c,--d)if(a.charAt(c)!=b.charAt(d))break;return d+1}function B(a){return a.replace(/[<>&]/g,function(a){return a=="&"?"&":a=="<"?"<":">"})}function A(a){return{line:a.line,ch:a.ch}}function z(a,b){return a.line<b.line||a.line==b.line&&a.ch<b.ch}function y(a,b){return a.line==b.line&&a.ch==b.ch}function x(a){return a.textContent||a.innerText||a.nodeValue||""}function w(a){var b=0,c=0;for(var d=a;d;d=d.offsetParent)b+=d.offsetLeft,c+=d.offsetTop;for(var d=a.parentNode;d!=document.body;d=d.parentNode)b-=d.scrollLeft,c-=d.scrollTop;return{left:b,top:c}}function v(a,b){b==null&&(b=a.search(/[^\s\u00a0]/),b==-1&&(b=a.length));for(var c=0,d=0;c<b;++c)a.charAt(c)=="\t"?d+=r-d%r:++d;return d}function n(){this.id=null}function m(a,b,c,d){function e(a){c(new l(a||window.event))}if(typeof a.addEventListener=="function"){a.addEventListener(b,e,!1);if(d)return function(){a.removeEventListener(b,e,!1)}}else{a.attachEvent("on"+b,e);if(d)return function(){a.detachEvent("on"+b,e)}}}function l(a){this.e=a}function k(a){a.stop||(a.stop=j);return a}function j(){this.preventDefault?(this.preventDefault(),this.stopPropagation()):(this.returnValue=!1,this.cancelBubble=!0)}function i(){this.time=0,this.done=[],this.undone=[]}function h(a,b,c,d){for(var e=0,f=0,g=0;f<b;e+=2){var h=c[e],i=f+h.length;g==0?(i>a&&d.push(h.slice(a-f,Math.min(h.length,b-f)),c[e+1]),i>=a&&(g=1)):g==1&&(i>b?d.push(h.slice(0,b-f),c[e+1]):d.push(h,c[e+1])),f=i}}function g(a,b){this.styles=b||[a,null],this.stateAfter=null,this.text=a,this.marked=this.gutterMarker=this.className=null}function f(a){this.pos=this.start=0,this.string=a}function e(a,b,c){return a.startState?a.startState(b,c):!0}function d(a,b){if(b===!0)return b;if(a.copyState)return a.copyState(b);var c={};for(var d in b){var e=b[d];e instanceof Array&&(e=e.concat([])),c[d]=e}return c}function a(b,c){function cG(a,b,c){this.atOccurrence=!1,c==null&&(c=typeof a=="string"&&a==a.toLowerCase()),b&&typeof b=="object"?b=bX(b):b={line:0,ch:0},this.pos={from:b,to:b};if(typeof a!="string")this.matches=function(b,c){if(b){var d=S[c.line].text.slice(0,c.ch),e=d.match(a),f=0;while(e){var g=d.indexOf(e[0]);f+=g,d=d.slice(g+1);var h=d.match(a);if(h)e=h;else break}}else var d=S[c.line].text.slice(c.ch),e=d.match(a),f=e&&c.ch+d.indexOf(e[0]);if(e)return{from:{line:c.line,ch:f},to:{line:c.line,ch:f+e[0].length},match:e}};else{c&&(a=a.toLowerCase());var d=c?function(a){return a.toLowerCase()}:function(a){return a},e=a.split("\n");e.length==1?this.matches=function(b,c){var e=d(S[c.line].text),f=a.length,g;if(b?c.ch>=f&&(g=e.lastIndexOf(a,c.ch-f))!=-1:(g=e.indexOf(a,c.ch))!=-1)return{from:{line:c.line,ch:g},to:{line:c.line,ch:g+f}}}:this.matches=function(a,b){var c=b.line,f=a?e.length-1:0,g=e[f],h=d(S[c].text),i=a?h.indexOf(g)+g.length:h.lastIndexOf(g);if(!(a?i>=b.ch||i!=g.length:i<=b.ch||i!=h.length-g.length))for(;;){if(a?!c:c==S.length-1)return;h=d(S[c+=a?-1:1].text),g=e[a?--f:++f];if(f>0&&f<e.length-1){if(h!=g)return;continue}var j=a?h.lastIndexOf(g):h.indexOf(g)+g.length;if(a?j!=h.length-g.length:j!=g.length)return;var k={line:b.line,ch:i},l={line:c,ch:j};return{from:a?l:k,to:a?k:l}}}}}function cF(a){return function(){cE++||cC();try{var b=a.apply(this,arguments)}finally{--cE||cD()}return b}}function cD(){var a=!1;bb&&(a=!bL()),_.length?bO(_):bb&&bS(),a&&bL(),bb&&cv(),!bc&&($===!0||$!==!1&&bb)&&bK(),bb&&f.matchBrackets&&setTimeout(cF(function(){bi&&(bi(),bi=null),cx(!1)}),20);var b=ba;bb&&f.onCursorActivity&&f.onCursorActivity(bl),b&&f.onChange&&bl&&f.onChange(bl,b)}function cC(){$=null,_=[],ba=bb=!1}function cB(a){!T.length||P.set(a,cF(cA))}function cA(){var a=+(new Date)+f.workTime;while(T.length){if(!S[bd].stateAfter)var b=bd;else var b=T.pop();if(b>=S.length)continue;var c=cy(b),g=c&&S[c-1].stateAfter;g?g=d(R,g):g=e(R);for(var h=c,i=S.length;h<i;++h){var j=S[h],k=j.stateAfter;if(+(new Date)>a){T.push(h),cB(f.workDelay),_.push({from:b,to:h});return}var l=j.highlight(R,g);j.stateAfter=d(R,g);if(k&&!l&&j.text)break}_.push({from:b,to:h})}}function cz(a){var b=cy(a),c=b&&S[b-1].stateAfter;c?c=d(R,c):c=e(R);for(var f=b;f<a;++f){var g=S[f];g.highlight(R,c),g.stateAfter=d(R,c)}S[a].stateAfter||T.push(a);return c}function cy(a){var b,c;for(var d=a,e=a-40;d>e;--d){if(d==0)return 0;var f=S[d-1];if(f.stateAfter)return d;var g=f.indentation();if(c==null||b>g)c=d,b=g}return c}function cx(a){function p(a,b,c){if(!!a.text){var d=a.styles,e=g?0:a.text.length-1,f;for(var i=g?0:d.length-2,j=g?d.length:-2;i!=j;i+=2*h){var k=d[i];if(d[i+1]!=null&&d[i+1]!=m){e+=h*k.length;continue}for(var l=g?0:k.length-1,p=g?k.length:-1;l!=p;l+=h,e+=h)if(e>=b&&e<c&&o.test(f=k.charAt(l))){var q=cw[f];if(q.charAt(1)==">"==g)n.push(f);else{if(n.pop()!=q.charAt(0))return{pos:e,match:!1};if(!n.length)return{pos:e,match:!0}}}}}}var b=W.inverted?W.from:W.to,c=S[b.line],d=b.ch-1,e=d>=0&&cw[c.text.charAt(d)]||cw[c.text.charAt(++d)];if(!!e){var f=e.charAt(0),g=e.charAt(1)==">",h=g?1:-1,i=c.styles;for(var j=d+1,k=0,l=i.length;k<l;k+=2)if((j-=i[k].length)<=0){var m=i[k+1];break}var n=[c.text.charAt(d)],o=/[(){}[\]]/;for(var k=b.line,l=g?Math.min(k+50,S.length):Math.max(-1,k-50);k!=l;k+=h){var c=S[k],q=k==b.line,r=p(c,q&&g?d+1:0,q&&!g?d:c.text.length);if(r){var m=r.match?"CodeMirror-matchingbracket":"CodeMirror-nonmatchingbracket",s=cg({line:b.line,ch:d},{line:b.line,ch:d+1},m),t=cg({line:k,ch:r.pos},{line:k,ch:r.pos+1},m),u=cF(function(){s(),t()});a?setTimeout(u,800):bi=u;break}}}}function cv(){clearInterval(Q);var a=!0;M.style.visibility="",Q=setInterval(function(){M.style.visibility=(a=!a)?"":"hidden"},650)}function cu(a){var b=ct(a);if(!!b&&!window.opera){(y(W.from,W.to)||z(b,W.from)||!z(b,W.to))&&bV(b.line,b.ch);var c=K.style.cssText;K.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(a.pageY()-1)+"px; left: "+(a.pageX()-1)+"px; z-index: 1000; background: white; "+"border-width: 0; outline: none; overflow: hidden;";var d=K.value=bF();K.focus(),G(K,0,d.length),p&&a.stop(),bc=!0,setTimeout(function(){K.value!=d&&cF(bC)(K.value,"end"),K.style.cssText=c,bc=!1,bK(),bH()},50)}}function ct(a,b){var c=w(l),d=a.pageX(),e=a.pageY();if(!b&&(d-c.left>l.clientWidth||e-c.top>l.clientHeight))return null;var f=w(L),g=bd+Math.floor((e-f.top)/cq());return bX({line:g,ch:cn(bW(g),d-f.left)})}function cs(){return L.offsetLeft}function cr(){return L.offsetTop}function cq(){var a=N.childNodes.length;if(a)return N.offsetHeight/a;v.innerHTML="<pre>x</pre>";return v.firstChild.offsetHeight||1}function cp(a){var b=co(a,!0),c=w(L);return{x:c.left+b.x,y:c.top+b.y,yBot:c.top+b.yBot}}function co(a,b){var c=cq(),d=a.line-(b?bd:0);return{x:cm(a.line,a.ch),y:d*c,yBot:(d+1)*c}}function cn(a,b){function e(a){v.innerHTML="<pre><span>"+c.getHTML(null,null,!1,a)+"</span></pre>";return v.firstChild.firstChild.offsetWidth}if(b<=0)return 0;var c=S[a],d=c.text,f=0,g=0,h=d.length,i,j=Math.min(h,Math.ceil(b/cl("x")));for(;;){var k=e(j);if(k<=b&&j<h)j=Math.min(h,Math.ceil(j*1.2));else{i=k,h=j;break}}if(b>i)return h;j=Math.floor(h*.8),k=e(j),k<b&&(f=j,g=k);for(;;){if(h-f<=1)return i-b>b-g?f:h;var l=Math.ceil((f+h)/2),m=e(l);m>b?(h=l,i=m):(f=l,g=m)}}function cm(a,b){if(b==0)return 0;v.innerHTML="<pre><span>"+S[a].getHTML(null,null,!1,b)+"</span></pre>";return v.firstChild.firstChild.offsetWidth}function cl(a){v.innerHTML="<pre><span>x</span></pre>",v.firstChild.firstChild.firstChild.nodeValue=a;return v.firstChild.firstChild.offsetWidth||10}function ck(a){if(typeof a=="number"){var b=a;a=S[a];if(!a)return null}else{var b=D(S,a);if(b==-1)return null}var c=a.gutterMarker;return{line:b,text:a.text,markerText:c&&c.text,markerClass:c&&c.style}}function cj(a,b){if(typeof a=="number"){var c=a;a=S[bW(a)]}else{var c=D(S,a);if(c==-1)return null}a.className=b,_.push({from:c,to:c+1});return a}function ci(a){typeof a=="number"&&(a=S[bW(a)]),a.gutterMarker=null,bR()}function ch(a,b,c){typeof a=="number"&&(a=S[bW(a)]),a.gutterMarker={text:b,style:c},bR();return a}function cg(a,b,c){function e(a,b,c,e){var a=S[a],f=a.addMark(b,c,e);f.line=a,d.push(f)}a=bX(a),b=bX(b);var d=[];if(a.line==b.line)e(a.line,a.ch,b.ch,c);else{e(a.line,a.ch,null,c);for(var f=a.line+1,g=b.line;f<g;++f)e(f,0,null,c);e(b.line,0,b.ch,c)}_.push({from:a.line,to:b.line+1});return function(){var a,b;for(var c=0;c<d.length;++c){var e=d[c],f=D(S,e.line);e.line.removeMark(e),f>-1&&(a==null&&(a=f),b=f)}a!=null&&_.push({from:a,to:b+1})}}function cf(){var a=f.gutter||f.lineNumbers;H.style.display=a?"":"none",a?bR():N.parentNode.style.marginLeft=0}function ce(){R=a.getMode(f,f.mode);for(var b=0,c=S.length;b<c;++b)S[b].stateAfter=null;T=[0],cB()}function cd(a,b){if(b=="smart")if(!R.indent)b="prev";else var c=cz(a);var d=S[a],e=d.indentation(),g=d.text.match(/^\s*/)[0],h;b=="prev"?a?h=S[a-1].indentation():h=0:b=="smart"?h=R.indent(c,d.text.slice(g.length)):b=="add"?h=e+f.indentUnit:b=="subtract"&&(h=e-f.indentUnit),h=Math.max(0,h);var i=h-e;if(!i){if(W.from.line!=a&&W.to.line!=a)return;var j=g}else{var j="",k=0;if(f.indentWithTabs)for(var l=Math.floor(h/r);l;--l)k+=r,j+="\t";while(k<h)++k,j+=" "}bB(j,{line:a,ch:0},{line:a,ch:g.length})}function cc(a){X=null;switch(f.tabMode){case"default":return!1;case"indent":for(var b=W.from.line,c=W.to.line;b<=c;++b)cd(b,"smart");break;case"classic":if(y(W.from,W.to)){a?cd(W.from.line,"smart"):bC("\t","end");break};case"shift":for(var b=W.from.line,c=W.to.line;b<=c;++b)cd(b,a?"subtract":"add")}return!0}function cb(){bC("\n","end"),f.enterMode!="flat"&&cd(W.from.line,f.enterMode=="keep"?"prev":"smart")}function ca(a){bT({line:a,ch:0},{line:a,ch:S[a].text.length})}function b_(a){var b=S[a.line].text,c=a.ch,d=a.ch;while(c>0&&/\w/.test(b.charAt(c-1)))--c;while(d<b.length&&/\w/.test(b.charAt(d)))++d;bT({line:a.line,ch:c},{line:a.line,ch:d})}function b$(){var a=S.length-1;bU({line:0,ch:0},{line:a,ch:S[a].text.length})}function bZ(a){bV(a?0:S.length-1,!0)}function bY(a){var b=Math.floor(l.clientHeight/cq()),c=W.inverted?W.from:W.to;bV(c.line+Math.max(b-1,1)*(a?1:-1),c.ch,!0)}function bX(a){if(a.line<0)return{line:0,ch:0};if(a.line>=S.length)return{line:S.length-1,ch:S[S.length-1].text.length};var b=a.ch,c=S[a.line].text.length;return b==null||b>c?{line:a.line,ch:c}:b<0?{line:a.line,ch:0}:a}function bW(a){return Math.max(0,Math.min(a,S.length-1))}function bV(a,b,c){var d=bX({line:a,ch:b||0});(c?bT:bU)(d,d)}function bU(a,b,c,d){if(!y(W.from,a)||!y(W.to,b)){if(z(b,a)){var e=b;b=a,a=e}var f=y(W.to,b),g=y(W.from,a);y(a,b)?W.inverted=!1:f&&!g?W.inverted=!0:g&&!f&&(W.inverted=!1),c==null&&(c=W.from.line,d=W.to.line),y(a,b)?y(W.from,W.to)||_.push({from:c,to:d+1}):y(W.from,W.to)?_.push({from:a.line,to:b.line+1}):(y(a,W.from)||(a.line<c?_.push({from:a.line,to:Math.min(b.line,c)+1}):_.push({from:c,to:Math.min(d,a.line)+1})),y(b,W.to)||(b.line<d?_.push({from:Math.max(c,a.line),to:d+1}):_.push({from:Math.max(a.line,d),to:b.line+1}))),W.from=a,W.to=b,bb=!0}}function bT(a,b){var c=X&&bX(X);c&&(z(c,a)?a=c:z(b,c)&&(b=c)),bU(a,b)}function bS(){var a=W.inverted?W.from:W.to,b=cm(a.line,a.ch)+"px",c=(a.line-bd)*cq()+"px";J.style.top=c,J.style.left=b,y(W.from,W.to)?(M.style.top=c,M.style.left=b,M.style.display=""):M.style.display="none"}function bR(){if(!!f.gutter||!!f.lineNumbers){var a=B.offsetHeight,b=l.clientHeight;H.style.height=(a-b<2?b:a)+"px";var c=[];for(var d=bd;d<be;++d){var e=S[d].gutterMarker,g=f.lineNumbers?d+f.firstLineNumber:null;e&&e.text?g=e.text.replace("%N%",g!=null?g:""):g==null&&(g="\u00a0"),c.push(e&&e.style?'<pre class="'+e.style+'">':"<pre>",g,"</pre>")}H.style.display="none",I.innerHTML=c.join("");var h=String(S.length).length,i=I.firstChild,j=x(i),k="";while(j.length+k.length<h)k+="\u00a0";k&&i.insertBefore(document.createTextNode(k),i.firstChild),H.style.display="",L.style.marginLeft=H.offsetWidth+"px"}}function bQ(a){var b=W.from.line,c=W.to.line,d=0,e=o&&document.createElement("div");for(var f=0,g=a.length;f<g;++f){var h=a[f],i=h.to-h.from-h.domSize,j=N.childNodes[h.domStart+h.domSize+d]||null;if(o)for(var k=Math.max(-i,h.domSize);k>0;--k)N.removeChild(j?j.previousSibling:N.lastChild);else if(i){for(var k=Math.max(0,i);k>0;--k)N.insertBefore(document.createElement("pre"),j);for(var k=Math.max(0,-i);k>0;--k)N.removeChild(j?j.previousSibling:N.lastChild)}var l=N.childNodes[h.domStart+d],m=b<h.from&&c>=h.from;for(var k=h.from;k<h.to;++k){var n=null,p=null;m?(n=0,c==k&&(m=!1,p=W.to.ch)):b==k&&(c==k?(n=W.from.ch,p=W.to.ch):(m=!0,n=W.from.ch)),o?(e.innerHTML=S[k].getHTML(n,p,!0),N.insertBefore(e.firstChild,j)):(l.innerHTML=S[k].getHTML(n,p,!1),l.className=S[k].className||"",l=l.nextSibling)}d+=i}}function bP(a,b){var c=[],d={line:a,ch:0},e=z(W.from,d)&&!z(W.to,d);for(var f=a;f<b;++f){var g=null,h=null;e?(g=0,W.to.line==f&&(e=!1,h=W.to.ch)):W.from.line==f&&(W.to.line==f?(g=W.from.ch,h=W.to.ch):(e=!0,g=W.from.ch)),c.push(S[f].getHTML(g,h,!0))}N.innerHTML=c.join("")}function bO(a){if(!l.clientWidth)bd=be=0;else{var b=a===!0?[]:[{from:bd,to:be,domStart:0}];for(var c=0,d=a.length||0;c<d;++c){var e=a[c],f=[],g=e.diff||0;for(var h=0,i=b.length;h<i;++h){var j=b[h];e.to<=j.from?f.push({from:j.from+g,to:j.to+g,domStart:j.domStart}):j.to<=e.from?f.push(j):(e.from>j.from&&f.push({from:j.from,to:e.from,domStart:j.domStart}),e.to<j.to&&f.push({from:e.to+g,to:j.to+g,domStart:j.domStart+(e.to-j.from)}))}b=f}var k=bN(),m=Math.min(bd,Math.max(k.from-3,0)),n=Math.min(S.length,Math.max(be,k.to+3)),o=[],p=0,q=be-bd,r=m,s=0;for(var c=0,d=b.length;c<d;++c){var j=b[c];if(j.to<=m)continue;if(j.from>=n)break;if(j.domStart>p||j.from>r)o.push({from:r,to:j.from,domSize:j.domStart-p,domStart:p}),s+=j.from-r;r=j.to,p=j.domStart+(j.to-j.from)}if(p!=q||r!=n)s+=Math.abs(n-r),o.push({from:r,to:n,domSize:q-p,domStart:p});if(!o.length)return;N.style.display="none",s>(k.to-k.from)*.3?bP(m=Math.max(k.from-10,0),n=Math.min(k.to+7,S.length)):bQ(o),N.style.display="";var t=m!=bd||n!=be||bf!=l.clientHeight;bd=m,be=n,B.style.top=m*cq()+"px",t&&(bf=l.clientHeight,u.style.height=S.length*cq()+2*cr()+"px",bR());var v=cl(bj);L.style.width=v>l.clientWidth?v+"px":"";if(N.childNodes.length!=be-bd)throw new Error("BAD PATCH! "+JSON.stringify(o)+" size="+(be-bd)+" nodes="+N.childNodes.length);bS()}}function bN(){var a=cq(),b=l.scrollTop-cr();return{from:Math.min(S.length,Math.max(0,Math.floor(b/a))),to:Math.min(S.length,Math.ceil((b+l.clientHeight)/a))}}function bM(a,b,c,d){var e=cs(),g=cr();b+=g,d+=g,a+=e,c+=e;var h=l.clientHeight,i=l.scrollTop,j=!1,k=!0;b<i?(l.scrollTop=Math.max(0,b-10),j=!0):d>i+h&&(l.scrollTop=d+10-h,j=!0);var m=l.clientWidth,n=l.scrollLeft;a<n?(l.scrollLeft=Math.max(0,a-10),j=!0):c>m+n&&(l.scrollLeft=c+10-m,j=!0,c>u.clientWidth&&(k=!1)),j&&f.onScroll&&f.onScroll(bl);return k}function bL(){var a=co(W.inverted?W.from:W.to);return bM(a.x,a.y,a.x,a.yBot)}function bK(){var a=[],b=Math.max(0,W.from.line-1),c=Math.min(S.length,W.to.line+2);for(var d=b;d<c;++d)a.push(S[d].text);a=K.value=a.join(q);var e=W.from.ch,f=W.to.ch;for(var d=b;d<W.from.line;++d)e+=q.length+S[d].text.length;for(var d=b;d<W.to.line;++d)f+=q.length+S[d].text.length;bh={text:a,from:b,to:c,start:e,end:f},G(K,e,Y?e:f)}function bJ(){function g(a,c){var d=0;for(;;){var e=b.indexOf("\n",d);if(e==-1||(b.charAt(e-1)=="\r"?e-1:e)>=a)return{line:c,ch:a-d};++c,d=e+1}}var a=!1,b=K.value,c=F(K);if(!c)return!1;var a=bh.text!=b,d=Y,e=a||c.start!=bh.start||c.end!=(d?bh.start:bh.end);if(!e&&!d)return!1;if(a){X=Y=null;if(f.readOnly){$=!0;return"changed"}}var h=g(c.start,bh.from),i=g(c.end,bh.from);if(d){h=c.start==d.anchor?i:h,i=X?W.to:c.start==d.anchor?h:i;if(!z(h,i)){Y=null,W.inverted=!1;var j=h;h=i,i=j}}h.line==i.line&&h.line==W.from.line&&h.line==W.to.line&&!X&&($=!1);if(a){var k=0,l=b.length,m=Math.min(l,bh.text.length),n,o=bh.from,p=-1;while(k<m&&(n=b.charAt(k))==bh.text.charAt(k))++k,n=="\n"&&(o++,p=k);var q=p>-1?k-p:k,r=bh.to-1,s=bh.text.length;for(;;){n=bh.text.charAt(s),n=="\n"&&r--;if(b.charAt(l)!=n){++l,++s;break}if(s<=k||l<=k)break;--l,--s}var p=bh.text.lastIndexOf("\n",s-1),t=p==-1?s:s-p-1;bw({line:o,ch:q},{line:r,ch:t},E(b.slice(k,l)),h,i);if(o!=r||h.line!=o)$=!0}else bU(h,i);bh.text=b,bh.start=c.start,bh.end=c.end;return a?"changed":e?"moved":!1}function bI(a){function c(){cC();var d=bJ();d=="moved"&&a&&(t[a]=!0),!d&&!b?(b=!0,O.set(80,c)):(bG=!1,bH()),cD()}var b=!1;bG=!0,O.set(20,c)}function bH(){bG||O.set(2e3,function(){cC(),bJ(),V&&bH(),cD()})}function bF(){return bE(W.from,W.to)}function bE(a,b){var c=a.line,d=b.line;if(c==d)return S[c].text.slice(a.ch,b.ch);var e=[S[c].text.slice(a.ch)];for(var f=c+1;f<d;++f)e.push(S[f].text);e.push(S[d].text.slice(0,b.ch));return e.join("\n")}function bD(a,b,c,d){var e=a.length==1?a[0].length+b.ch:a[a.length-1].length,f=d({line:b.line+a.length-1,ch:e});bw(b,c,a,f.from,f.to)}function bC(a,b){bD(E(a),W.from,W.to,function(a){return b=="end"?{from:a,to:a}:b=="start"?{from:W.from,to:W.from}:{from:W.from,to:a}})}function bB(a,b,c){function d(d){if(z(d,b))return d;if(!z(c,d))return e;var f=d.line+a.length-(c.line-b.line)-1,g=d.ch;d.line==c.line&&(g+=a[a.length-1].length-(c.ch-(c.line==b.line?b.ch:0)));return{line:f,ch:g}}b=bX(b),c?c=bX(c):c=b,a=E(a);var e;bD(a,b,c,function(a){e=a;return{from:d(W.from),to:d(W.to)}});return e}function bA(a,b,c,d,e){function s(a){return a<=Math.min(b.line,b.line+q)?a:a+q}var f=!1,h=bj.length;for(var i=a.line;i<b.line;++i)if(S[i].text.length==h){f=!0;break}var j=b.line-a.line,k=S[a.line],l=S[b.line];if(k==l)if(c.length==1)k.replace(a.ch,b.ch,c[0]);else{l=k.split(b.ch,c[c.length-1]);var m=[a.line+1,j];k.replace(a.ch,k.text.length,c[0]);for(var i=1,n=c.length-1;i<n;++i)m.push(new g(c[i]));m.push(l),S.splice.apply(S,m)}else if(c.length==1)k.replace(a.ch,k.text.length,c[0]+l.text.slice(b.ch)),S.splice(a.line+1,j);else{var m=[a.line+1,j-1];k.replace(a.ch,k.text.length,c[0]),l.replace(0,b.ch,c[c.length-1]);for(var i=1,n=c.length-1;i<n;++i)m.push(new g(c[i]));S.splice.apply(S,m)}for(var i=a.line,n=i+c.length;i<n;++i){var o=S[i].text;o.length>h&&(bj=o,h=o.length,f=!1)}if(f){h=0;for(var i=0,n=S.length;i<n;++i){var o=S[i].text;o.length>h&&(h=o.length,bj=o)}}var p=[],q=c.length-j-1;for(var i=0,o=T.length;i<o;++i){var r=T[i];r<a.line?p.push(r):r>b.line&&p.push(r+q)}c.length&&p.push(a.line),T=p,cB(100),_.push({from:a.line,to:b.line+1,diff:q}),ba={from:a,to:b,text:c},bU(d,e,s(W.from.line),s(W.to.line)),u.style.height=S.length*cq()+2*cr()+"px"}function bz(){bx(U.undone,U.done)}function by(){bx(U.done,U.undone)}function bx(a,b){var c=a.pop();if(c){var d=[],e=c.start+c.added;for(var f=c.start;f<e;++f)d.push(S[f].text);b.push({start:c.start,added:c.old.length,old:d});var g=bX({line:c.start+c.old.length-1,ch:C(d[d.length-1],c.old[c.old.length-1])});bA({line:c.start,ch:0},{line:e-1,ch:S[e-1].text.length},c.old,g,g)}}function bw(a,b,c,d,e){if(U){var g=[];for(var h=a.line,i=b.line+1;h<i;++h)g.push(S[h].text);U.addChange(a.line,c.length,g);while(U.done.length>f.undoDepth)U.done.shift()}bA(a,b,c,d,e)}function bv(){V&&f.onBlur&&f.onBlur(bl),clearInterval(Q),X=null,V=!1,l.className=l.className.replace(" CodeMirror-focused","")}function bu(){!V&&f.onFocus&&f.onFocus(bl),V=!0,bH(),l.className.search(/\bCodeMirror-focused\b/)==-1&&(l.className+=" CodeMirror-focused"),cv()}function bt(a){if(!f.onKeyEvent||!f.onKeyEvent(bl,k(a.e))){if(f.electricChars&&R.electricChars){var b=String.fromCharCode(a.e.charCode==null?a.e.keyCode:a.e.charCode);R.electricChars.indexOf(b)>-1&&setTimeout(cF(function(){cd(W.to.line,"smart")}),50)}var c=a.e.keyCode;c==13?(f.readOnly||cb(),a.stop()):!a.e.ctrlKey&&!a.e.altKey&&!a.e.metaKey&&c==9&&f.tabMode!="default"?a.stop():bI(bg)}}function bs(a){Y&&(Y=null,$=!0),a.e.keyCode==16&&(X=null)}function br(a){V||bu();var b=a.e.keyCode,c=(s?a.e.metaKey:a.e.ctrlKey)&&!a.e.altKey,d=a.e.ctrlKey||a.e.altKey||a.e.metaKey;b==16||a.e.shiftKey?X=X||(W.inverted?W.to:W.from):X=null;if(!f.onKeyEvent||!f.onKeyEvent(bl,k(a.e))){if(b==33||b==34){bY(b==34);return a.stop()}if(c&&(b==36||b==35||s&&(b==38||b==40))){bZ(b==36||b==38);return a.stop()}if(c&&b==65){b$();return a.stop()}if(!f.readOnly){if(!d&&b==13)return;if(!d&&b==9&&cc(a.e.shiftKey))return a.stop();if(c&&b==90){by();return a.stop()}if(c&&(a.e.shiftKey&&b==90||b==89)){bz();return a.stop()}}bg=(c?"c":"")+b;if(W.inverted&&t.hasOwnProperty(bg)){var e=F(K);e&&(Y={anchor:e.start},G(K,e.start,e.start))}bI(bg)}}function bq(a){var b=ct(a,!0),c=a.e.dataTransfer.files;if(!!b&&!f.readOnly)if(c&&c.length&&window.FileReader&&window.File){var d=c.length,e=Array(d),g=0;for(var h=0;h<d;++h)i(c[h],h);function i(a,c){var f=new FileReader;f.onload=function(){e[c]=f.result,++g==d&&bB(e.join(""),bX(b),bX(b))},f.readAsText(a)}}else try{var e=a.e.dataTransfer.getData("Text");e&&bB(e,b,b)}catch(a){}}function bp(a){var b=ct(a);!b||(b_(b),a.stop(),Z=+(new Date))}function bo(a){function i(a){var b=ct(a,!0);if(b&&!y(b,e)){V||bu(),e=b,bT(d,b),$=!1;var c=bN();if(b.line>=c.to||b.line<c.from)g=setTimeout(cF(function(){i(a)}),150)}}function h(){K.focus(),$=!0,j(),k()}var b=Z;Z=null;for(var c=a.target();c!=l;c=c.parentNode)if(c.parentNode==I){f.onGutterClick&&f.onGutterClick(bl,D(I.childNodes,c)+bd);return a.stop()}p&&a.button()==3&&cu(a);if(a.button()==1){var d=ct(a),e=d,g;if(!d){a.target()==l&&a.stop();return}V||bu(),a.stop();if(b&&+(new Date)-b<400)return ca(d.line);bV(d.line,d.ch,!0);var j=m(document,"mousemove",cF(function(a){clearTimeout(g),a.stop(),i(a)}),!0),k=m(document,"mouseup",cF(function(a){clearTimeout(g);var b=ct(a);b&&bT(d,b),a.stop(),h()}),!0)}}function bn(a){var b=[];for(var c=0,d=S.length;c<d;++c)b.push(S[c].text);return b.join("\n")}function bm(a){U=null;var b={line:0,ch:0};bw(b,{line:S.length-1,ch:S[S.length-1].text.length},E(a),b,b),U=new i}function bk(a){return a>=0&&a<S.length}var f={},h=a.defaults;for(var j in h)h.hasOwnProperty(j)&&(f[j]=(c&&c.hasOwnProperty(j)?c:h)[j]);var l=document.createElement("div");l.className="CodeMirror",window.ActiveXObject&&/MSIE [1-7][\b\.]/.test(navigator.userAgent)&&(l.style.position="relative"),l.innerHTML='<div style="position: relative"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"></div><div style="position: relative"><div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div style="overflow: hidden; position: absolute; width: 1px; height: 0; left: 0"><textarea style="position: absolute; width: 100000px;" wrap="off"></textarea></div><div class="CodeMirror-lines"><div style="position: relative"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div>',b.appendChild?b.appendChild(l):b(l);var u=l.firstChild,v=u.firstChild,B=v.nextSibling,H=B.firstChild,I=H.firstChild,J=H.nextSibling,K=J.firstChild,L=J.nextSibling.firstChild,M=L.firstChild,N=M.nextSibling;f.tabindex!=null&&(K.tabindex=f.tabindex),!f.gutter&&!f.lineNumbers&&(H.style.display="none");var O=new n,P=new n,Q,R,S=[new g("")],T,U=new i,V;ce();var W={from:{line:0,ch:0},to:{line:0,ch:0},inverted:!1},X,Y,Z,$,_,ba,bb,bc,bd=0,be=0,bf=0,bg=null,bh,bi,bj="";cF(function(){bm(f.value||""),$=!1})(),setTimeout(bK,20),m(l,"mousedown",cF(bo)),p||m(l,"contextmenu",cF(cu)),m(u,"dblclick",cF(bp)),m(l,"scroll",function(){bO([]),f.onScroll&&f.onScroll(bl)}),m(window,"resize",function(){bO(!0)}),m(K,"keyup",cF(bs)),m(K,"keydown",cF(br)),m(K,"keypress",cF(bt)),m(K,"focus",bu),m(K,"blur",bv),m(l,"dragenter",function(a){a.stop()}),m(l,"dragover",function(a){a.stop()}),m(l,"drop",cF(bq)),m(l,"paste",function(){K.focus(),bI()}),m(K,"paste",function(){bI()}),m(K,"cut",function(){bI()}),document.activeElement==K?bu():bv();var bl={getValue:bn,setValue:cF(bm),getSelection:bF,replaceSelection:cF(bC),focus:function(){K.focus(),bu(),bI()},setOption:function(a,b){f[a]=b,a=="lineNumbers"||a=="gutter"?cf():(a=="mode"||a=="indentUnit")&&ce()},getOption:function(a){return f[a]},undo:cF(by),redo:cF(bz),indentLine:cF(function(a){bk(a)&&cd(a,"smart")}),historySize:function(){return{undo:U.done.length,redo:U.undone.length}},matchBrackets:cF(function(){cx(!0)}),getTokenAt:function(a){a=bX(a);return S[a.line].getTokenAt(R,cz(a.line),a.ch)},cursorCoords:function(a){a==null&&(a=W.inverted);return cp(a?W.from:W.to)},charCoords:function(a){return cp(bX(a))},coordsChar:function(a){var b=w(L),c=bW(Math.min(S.length-1,bd+Math.floor((a.y-b.top)/cq())));return bX({line:c,ch:cn(bW(c),a.x-b.left)})},getSearchCursor:function(a,b,c){return new cG(a,b,c)},markText:cF(function(a,b,c){return cF(cg(a,b,c))}),setMarker:ch,clearMarker:ci,setLineClass:cF(cj),lineInfo:ck,addWidget:function(a,b,c){var a=co(bX(a),!0);b.style.top=bd*cq()+a.yBot+cr()+"px",b.style.left=a.x+cs()+"px",u.appendChild(b),c&&bM(a.x,a.yBot,a.x+b.offsetWidth,a.yBot+b.offsetHeight)},lineCount:function(){return S.length},getCursor:function(a){a==null&&(a=W.inverted);return A(a?W.from:W.to)},somethingSelected:function(){return!y(W.from,W.to)},setCursor:cF(function(a,b){b==null&&typeof a.line=="number"?bV(a.line,a.ch):bV(a,b)}),setSelection:cF(function(a,b){bU(bX(a),bX(b||a))}),getLine:function(a){if(bk(a))return S[a].text},setLine:cF(function(a,b){bk(a)&&bB(b,{line:a,ch:0},{line:a,ch:S[a].text.length})}),removeLine:cF(function(a){bk(a)&&bB("",{line:a,ch:0},bX({line:a+1,ch:0}))}),replaceRange:cF(bB),getRange:function(a,b){return bE(bX(a),bX(b))},operation:function(a){return cF(a)()},refresh:function(){bO(!0)},getInputField:function(){return K},getWrapperElement:function(){return l}},bG=!1,cw={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},cE=0;cG.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(a){function d(a){var c={line:a,ch:0};b.pos={from:c,to:c},b.atOccurrence=!1;return!1}var b=this,c=bX(a?this.pos.from:this.pos.to);for(;;){if(this.pos=this.matches(a,c)){this.atOccurrence=!0;return this.pos.match||!0}if(a){if(!c.line)return d(0);c={line:c.line-1,ch:S[c.line-1].text.length}}else{if(c.line==S.length-1)return d(S.length);c={line:c.line+1,ch:0}}}},from:function(){if(this.atOccurrence)return A(this.pos.from)},to:function(){if(this.atOccurrence)return A(this.pos.to)}};return bl}a.defaults={value:"",mode:null,indentUnit:2,indentWithTabs:!1,tabMode:"classic",enterMode:"indent",electricChars:!0,onKeyEvent:null,lineNumbers:!1,gutter:!1,firstLineNumber:1,readOnly:!1,onChange:null,onCursorActivity:null,onGutterClick:null,onFocus:null,onBlur:null,onScroll:null,matchBrackets:!1,workTime:100,workDelay:200,undoDepth:40,tabindex:null};var b={},c={};a.defineMode=function(c,d){!a.defaults.mode&&c!="null"&&(a.defaults.mode=c),b[c]=d},a.defineMIME=function(a,b){c[a]=b},a.getMode=function(d,e){typeof e=="string"&&c.hasOwnProperty(e)&&(e=c[e]);if(typeof e=="string")var f=e,g={};else var f=e.name,g=e;var h=b[f];if(!h){window.console&&console.warn("No mode "+f+" found, falling back to plain text.");return a.getMode(d,"text/plain")}return h(d,g)},a.listModes=function(){var a=[];for(var c in b)b.propertyIsEnumerable(c)&&a.push(c);return a},a.listMIMEs=function(){var a=[];for(var b in c)c.propertyIsEnumerable(b)&&a.push(b);return a},a.fromTextArea=function(b,c){function d(){b.value=h.getValue()}c||(c={}),c.value=b.value,!c.tabindex&&b.tabindex&&(c.tabindex=b.tabindex);if(b.form){var e=m(b.form,"submit",d,!0);if(typeof b.form.submit=="function"){var f=b.form.submit;function g(){d(),b.form.submit=f,b.form.submit(),b.form.submit=g}b.form.submit=g}}b.style.display="none";var h=a(function(a){b.parentNode.insertBefore(a,b.nextSibling)},c);h.save=d,h.toTextArea=function(){d(),b.parentNode.removeChild(h.getWrapperElement()),b.style.display="",b.form&&(e(),typeof b.form.submit=="function"&&(b.form.submit=f))};return h},a.startState=e,a.copyState=d,f.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return this.pos==0},peek:function(){return this.string.charAt(this.pos)},next:function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},eat:function(a){var b=this.string.charAt(this.pos);if(typeof a=="string")var c=b==a;else var c=b&&(a.test?a.test(b):a(b));if(c){++this.pos;return b}},eatWhile:function(a){var b=this.start;while(this.eat(a));return this.pos>b},eatSpace:function(){var a=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos)))++this.pos;return this.pos>a},skipToEnd:function(){this.pos=this.string.length},skipTo:function(a){var b=this.string.indexOf(a,this.pos);if(b>-1){this.pos=b;return!0}},backUp:function(a){this.pos-=a},column:function(){return v(this.string,this.start)},indentation:function(){return v(this.string)},match:function(a,b,c){if(typeof a!="string"){var e=this.string.slice(this.pos).match(a);e&&b!==!1&&(this.pos+=e[0].length);return e}function d(a){return c?a.toLowerCase():a}if(d(this.string).indexOf(d(a),this.pos)==this.pos){b!==!1&&(this.pos+=a.length);return!0}},current:function(){return this.string.slice(this.start,this.pos)}},g.prototype={replace:function(a,b,c){var d=[],e=this.marked;h(0,a,this.styles,d),c&&d.push(c,null),h(b,this.text.length,this.styles,d),this.styles=d,this.text=this.text.slice(0,a)+c+this.text.slice(b),this.stateAfter=null;if(e){var f=c.length-(b-a),g=this.text.length;function i(a){return a<=Math.min(b,b+f)?a:a+f}for(var j=0;j<e.length;++j){var k=e[j],l=!1;k.from>=g?l=!0:(k.from=i(k.from),k.to!=null&&(k.to=i(k.to)));if(l||k.from>=k.to)e.splice(j,1),j--}}},split:function(a,b){var c=[b,null];h(a,this.text.length,this.styles,c);return new g(b+this.text.slice(a),c)},addMark:function(a,b,c){var d=this.marked,e={from:a,to:b,style:c};this.marked==null&&(this.marked=[]),this.marked.push(e),this.marked.sort(function(a,b){return a.from-b.from});return e},removeMark:function(a){var b=this.marked;if(!!b)for(var c=0;c<b.length;++c)if(b[c]==a){b.splice(c,1);break}},highlight:function(a,b){var c=new f(this.text),d=this.styles,e=0,g=!1,h=d[0],i;while(!c.eol()){var j=a.token(c,b),k=this.text.slice(c.start,c.pos);c.start=c.pos,e&&d[e-1]==j?d[e-2]+=k:k&&(!g&&(d[e+1]!=j||e&&d[e-2]!=i)&&(g=!0),d[e++]=k,d[e++]=j,i=h,h=d[e]);if(c.pos>5e3){d[e++]=this.text.slice(c.pos),d[e++]=null;break}}d.length!=e&&(d.length=e,g=!0),e&&d[e-2]!=i&&(g=!0);return g},getTokenAt:function(a,b,c){var d=this.text,e=new f(d);while(e.pos<c&&!e.eol()){e.start=e.pos;var g=a.token(e,b)}return{start:e.start,end:e.pos,string:e.current(),className:g||null,state:b}},indentation:function(){return v(this.text)},getHTML:function(a,b,c,d){function f(a,b){!a||(b?e.push('<span class="',b,'">',B(a),"</span>"):e.push(B(a)))}var e=[];c&&e.push(this.className?'<pre class="'+this.className+'">':"<pre>");var g=this.styles,h=this.text,i=this.marked;a==b&&(a=null);var j=h.length;d!=null&&(j=Math.min(d,j));if(!h&&d==null)f(" ",a!=null&&b==null?"CodeMirror-selected":null);else if(!i&&a==null)for(var k=0,l=0;l<j;k+=2){var m=g[k],n=m.length;l+n>j&&(m=m.slice(0,j-l)),l+=n,f(m,g[k+1])}else{var o=0,k=0,p="",q,r=0,s=-1,t=null;function u(){i&&(s+=1,t=s<i.length?i[s]:null)}u();while(o<j){var v=j,w="";if(a!=null)if(a>o)v=a;else if(b==null||b>o)w=" CodeMirror-selected",b!=null&&(v=Math.min(v,b));while(t&&t.to!=null&&t.to<=o)u();t&&(t.from>o?v=Math.min(v,t.from):(w+=" "+t.style,t.to!=null&&(v=Math.min(v,t.to))));for(;;){var x=o+p.length,y=q;w&&(y=q?q+w:w),f(x>v?p.slice(0,v-o):p,y);if(x>=v){p=p.slice(v-o),o=v;break}o=x,p=g[k++],q=g[k++]}}a!=null&&b==null&&f(" ","CodeMirror-selected")}c&&e.push("</pre>");return e.join("")}},i.prototype={addChange:function(a,b,c){this.undone.length=0;var d=+(new Date),e=this.done[this.done.length-1];if(d-this.time>400||!e||e.start>a+b||e.start+e.added<a-e.added+e.old.length)this.done.push({start:a,added:b,old:c});else{var f=0;if(a<e.start){for(var g=e.start-a-1;g>=0;--g)e.old.unshift(c[g]);e.added+=e.start-a,e.start=a}else e.start<a&&(f=a-e.start,b+=f);for(var g=e.added-f,h=c.length;g<h;++g)e.old.push(c[g]);e.added<b&&(e.added=b)}this.time=d}},l.prototype={stop:function(){j.call(this.e)},target:function(){return this.e.target||this.e.srcElement},button:function(){if(this.e.which)return this.e.which;if(this.e.button&1)return 1;if(this.e.button&2)return 3;if(this.e.button&4)return 2},pageX:function(){return this.e.pageX!=null?this.e.pageX:this.e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft},pageY:function(){return this.e.pageY!=null?this.e.pageY:this.e.clientY+document.body.scrollTop+document.documentElement.scrollTop}},n.prototype={set:function(a,b){clearTimeout(this.id),this.id=setTimeout(b,a)}};var o=function(){var a=document.createElement("pre");a.innerHTML=" ";return!a.innerHTML}(),p=/gecko\/\d{7}/i.test(navigator.userAgent),q="\n";(function(){var a=document.createElement("textarea");a.value="foo\nbar",a.value.indexOf("\r")>-1&&(q="\r\n")})();var r=8,s=/Mac/.test(navigator.platform),t={};for(var u=35;u<=40;++u)t[u]=t["c"+u]=!0;if("\n\nb".split(/\n/).length!=3)var E=function(a){var b=0,c,d=[];while((c=a.indexOf("\n",b))>-1)d.push(a.slice(b,a.charAt(c-1)=="\r"?c-1:c)),b=c+1;d.push(a.slice(b));return d};else var E=function(a){return a.split(/\r?\n/)};if(window.getSelection)var F=function(a){try{return{start:a.selectionStart,end:a.selectionEnd}}catch(b){return null}},G=function(a,b,c){try{a.setSelectionRange(b,c)}catch(d){}};else var F=function(a){try{var b=document.selection.createRange()}catch(c){return null}if(!b||b.parentElement()!=a)return null;var d=a.value,e=d.length,f=a.createTextRange();f.moveToBookmark(b.getBookmark());var g=a.createTextRange();g.collapse(!1);if(f.compareEndPoints("StartToEnd",g)>-1)return{start:e,end:e};var h=-f.moveStart("character",-e);for(var i=d.indexOf("\r");i>-1&&i<h;i=d.indexOf("\r",i+1),h++);if(f.compareEndPoints("EndToEnd",g)>-1)return{start:h,end:e};var j=-f.moveEnd("character",-e);for(var i=d.indexOf("\r");i>-1&&i<j;i=d.indexOf("\r",i+1),j++);return{start:h,end:j}},G=function(a,b,c){var d=a.createTextRange();d.collapse(!0);var e=d.duplicate(),f=0,g=a.value;for(var h=g.indexOf("\n");h>-1&&h<b;h=g.indexOf("\n",h+1))++f;d.move("character",b-f);for(;h>-1&&h<c;h=g.indexOf("\n",h+1))++f;e.move("character",c-f),d.setEndPoint("EndToEnd",e),d.select()};a.defineMode("null",function(){return{token:function(a){a.skipToEnd()}}}),a.defineMIME("text/plain","null");return a}();CodeMirror.defineMode("javascript",function(a,b){function R(a,b){if(a=="variable"){v(b);return u()}}function Q(a,b){if(a=="variable"){v(b);return u(Q)}if(a=="(")return u(z(")"),x,I(R,")"),A,C,y)}function P(a){a!=")"&&u(D)}function O(a,b){if(a==";")return u(P);if(b=="in")return u(D);return u(D,B(";"),P)}function N(a,b){if(b=="in")return u(D);return u(E,O)}function M(a){if(a=="var")return u(K,O);if(a==";")return t(O);if(a=="variable")return u(N);return t(O)}function L(a,b){if(b=="=")return u(D,L);if(a==",")return u(K)}function K(a,b){if(a=="variable"){v(b);return u(L)}return u()}function J(a){if(a=="}")return u();return t(C,J)}function I(a,b){function c(d){if(d==",")return u(a,c);if(d==b)return u();return u(B(b))}return function(d){return d==b?u():t(a,c)}}function H(a){a=="variable"&&(s.marked="js-property");if(o.hasOwnProperty(a))return u(B(":"),D)}function G(a){if(a=="variable"){s.marked="js-property";return u()}}function F(a){if(a==":")return u(A,C);return t(E,B(";"),A)}function E(a,b){if(a=="operator"&&/\+\+|--/.test(b))return u(E);if(a=="operator")return u(D);if(a!=";"){if(a=="(")return u(z(")"),I(D,")"),A,E);if(a==".")return u(G,E);if(a=="[")return u(z("]"),D,B("]"),A,E)}}function D(a){if(o.hasOwnProperty(a))return u(E);if(a=="function")return u(Q);if(a=="keyword c")return u(D);if(a=="(")return u(z(")"),D,B(")"),A,E);if(a=="operator")return u(D);if(a=="[")return u(z("]"),I(D,"]"),A,E);if(a=="{")return u(z("}"),I(H,"}"),A,E);return u()}function C(a){if(a=="var")return u(z("vardef"),K,B(";"),A);if(a=="keyword a")return u(z("form"),D,C,A);if(a=="keyword b")return u(z("form"),C,A);if(a=="{")return u(z("}"),J,A);if(a==";")return u();if(a=="function")return u(Q);if(a=="for")return u(z("form"),B("("),z(")"),M,B(")"),A,C,A);if(a=="variable")return u(z("stat"),F);if(a=="switch")return u(z("form"),D,z("}","switch"),B("{"),J,A,A);if(a=="case")return u(D,B(":"));if(a=="default")return u(B(":"));if(a=="catch")return u(z("form"),x,B("("),R,B(")"),C,A,y);return t(z("stat"),D,B(";"),A)}function B(a){return function(b){return b==a?u():a==";"?t():u(arguments.callee)}}function A(){var a=s.state;a.lexical.prev&&(a.lexical.type==")"&&(a.indented=a.lexical.indented),a.lexical=a.lexical.prev)}function z(a,b){var c=function(){var c=s.state;c.lexical=new p(c.indented,s.stream.column(),a,null,c.lexical,b)};c.lex=!0;return c}function y(){s.state.localVars=s.state.context.vars,s.state.context=s.state.context.prev}function x(){s.state.context||(s.state.localVars=w),s.state.context={prev:s.state.context,vars:s.state.localVars}}function v(a){var b=s.state;if(b.context){s.marked="js-variabledef";for(var c=b.localVars;c;c=c.next)if(c.name==a)return;b.localVars={name:a,next:b.localVars}}}function u(){t.apply(null,arguments);return!0}function t(){for(var a=arguments.length-1;a>=0;a--)s.cc.push(arguments[a])}function r(a,b,c,e,f){var g=a.cc;s.state=a,s.stream=f,s.marked=null,s.cc=g,a.lexical.hasOwnProperty("align")||(a.lexical.align=!0);for(;;){var h=g.length?g.pop():d?D:C;if(h(c,e)){while(g.length&&g[g.length-1].lex)g.pop()();if(s.marked)return s.marked;if(c=="variable"&&q(a,e))return"js-localvariable";return b}}}function q(a,b){for(var c=a.localVars;c;c=c.next)if(c.name==b)return!0}function p(a,b,c,d,e,f){this.indented=a,this.column=b,this.type=c,this.prev=e,this.info=f,d!=null&&(this.align=d)}function n(a,b){var c=!1,d;while(d=a.next()){if(d=="/"&&c){b.tokenize=l;break}c=d=="*"}return k("comment","js-comment")}function m(a){return function(b,c){h(b,a)||(c.tokenize=l);return k("string","js-string")}}function l(a,b){var c=a.next();if(c=='"'||c=="'")return g(a,b,m(c));if(/[\[\]{}\(\),;\:\.]/.test(c))return k(c);if(c=="0"&&a.eat(/x/i)){a.eatWhile(/[\da-f]/i);return k("number","js-atom")}if(/\d/.test(c)){a.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);return k("number","js-atom")}if(c=="/"){if(a.eat("*"))return g(a,b,n);if(a.eat("/")){a.skipToEnd();return k("comment","js-comment")}if(b.reAllowed){h(a,"/"),a.eatWhile(/[gimy]/);return k("regexp","js-string")}a.eatWhile(f);return k("operator",null,a.current())}if(f.test(c)){a.eatWhile(f);return k("operator",null,a.current())}a.eatWhile(/[\w\$_]/);var d=a.current(),i=e.propertyIsEnumerable(d)&&e[d];return i?k(i.type,i.style,d):k("variable","js-variable",d)}function k(a,b,c){i=a,j=c;return b}function h(a,b){var c=!1,d;while((d=a.next())!=null){if(d==b&&!c)return!1;c=!c&&d=="\\"}return c}function g(a,b,c){b.tokenize=c;return c(a,b)}var c=a.indentUnit,d=b.json,e=function(){function a(a){return{type:a,style:"js-keyword"}}var b=a("keyword a"),c=a("keyword b"),d=a("keyword c"),e=a("operator"),f={type:"atom",style:"js-atom"};return{"if":b,"while":b,"with":b,"else":c,"do":c,"try":c,"finally":c,"return":d,"break":d,"continue":d,"new":d,"delete":d,"throw":d,"var":a("var"),"function":a("function"),"catch":a("catch"),"for":a("for"),"switch":a("switch"),"case":a("case"),"default":a("default"),"in":e,"typeof":e,"instanceof":e,"true":f,"false":f,"null":f,"undefined":f,NaN:f,Infinity:f}}(),f=/[+\-*&%=<>!?|]/,i,j,o={atom:!0,number:!0,variable:!0,string:!0,regexp:!0},s={state:null,column:null,marked:null,cc:null},w={name:"this",next:{name:"arguments"}};A.lex=!0;return{startState:function(a){return{tokenize:l,reAllowed:!0,cc:[],lexical:new p((a||0)-c,0,"block",!1),localVars:null,context:null,indented:0}},token:function(a,b){a.sol()&&(b.lexical.hasOwnProperty("align")||(b.lexical.align=!1),b.indented=a.indentation());if(a.eatSpace())return null;var c=b.tokenize(a,b);if(i=="comment")return c;b.reAllowed=i=="operator"||i=="keyword c"||i.match(/^[\[{}\(,;:]$/);return r(b,c,i,j,a)},indent:function(a,b){if(a.tokenize!=l)return 0;var d=b&&b.charAt(0),e=a.lexical,f=e.type,g=d==f;return f=="vardef"?e.indented+4:f=="form"&&d=="{"?e.indented:f=="stat"||f=="form"?e.indented+c:e.info=="switch"&&!g?e.indented+(/^(?:case|default)\b/.test(b)?c:2*c):e.align?e.column+(g?0:1):e.indented+(g?0:c)},electricChars:":{}"}}),CodeMirror.defineMIME("text/javascript","javascript"),CodeMirror.defineMIME("application/json",{name:"javascript",json:!0}) |