-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathasim.min.js
More file actions
1 lines (1 loc) · 432 KB
/
asim.min.js
File metadata and controls
1 lines (1 loc) · 432 KB
1
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).CodeMirror=t()}(this,(function(){"use strict";var e=navigator.userAgent,t=navigator.platform,n=/gecko\/\d/i.test(e),i=/MSIE \d/.test(e),r=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(e),s=/Edge\/(\d+)/.exec(e),o=i||r||s,a=o&&(i?document.documentMode||6:+(s||r)[1]),l=!s&&/WebKit\//.test(e),c=l&&/Qt\/\d+\.\d+/.test(e),d=!s&&/Chrome\//.test(e),h=/Opera\//.test(e),u=/Apple Computer/.test(navigator.vendor),f=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(e),m=/PhantomJS/.test(e),p=u&&(/Mobile\/\w+/.test(e)||navigator.maxTouchPoints>2),g=/Android/.test(e),v=p||g||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(e),_=p||/Mac/.test(t),y=/\bCrOS\b/.test(e),b=/win/i.test(t),x=h&&e.match(/Version\/(\d*\.\d*)/);x&&(x=Number(x[1])),x&&x>=15&&(h=!1,l=!0);var w=_&&(c||h&&(null==x||x<12.11)),k=n||o&&a>=9;function C(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}var S,L=function(e,t){var n=e.className,i=C(t).exec(n);if(i){var r=n.slice(i.index+i[0].length);e.className=n.slice(0,i.index)+(r?i[1]+r:"")}};function M(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function T(e,t){return M(e).appendChild(t)}function I(e,t,n,i){var r=document.createElement(e);if(n&&(r.className=n),i&&(r.style.cssText=i),"string"==typeof t)r.appendChild(document.createTextNode(t));else if(t)for(var s=0;s<t.length;++s)r.appendChild(t[s]);return r}function A(e,t,n,i){var r=I(e,t,n,i);return r.setAttribute("role","presentation"),r}function E(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do{if(11==t.nodeType&&(t=t.host),t==e)return!0}while(t=t.parentNode)}function z(){var e;try{e=document.activeElement}catch(t){e=document.body||null}for(;e&&e.shadowRoot&&e.shadowRoot.activeElement;)e=e.shadowRoot.activeElement;return e}function N(e,t){var n=e.className;C(t).test(n)||(e.className+=(n?" ":"")+t)}function F(e,t){for(var n=e.split(" "),i=0;i<n.length;i++)n[i]&&!C(n[i]).test(t)&&(t+=" "+n[i]);return t}S=document.createRange?function(e,t,n,i){var r=document.createRange();return r.setEnd(i||e,n),r.setStart(e,t),r}:function(e,t,n){var i=document.body.createTextRange();try{i.moveToElementText(e.parentNode)}catch(e){return i}return i.collapse(!0),i.moveEnd("character",n),i.moveStart("character",t),i};var B=function(e){e.select()};function $(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function O(e,t,n){for(var i in t||(t={}),e)!e.hasOwnProperty(i)||!1===n&&t.hasOwnProperty(i)||(t[i]=e[i]);return t}function R(e,t,n,i,r){null==t&&-1==(t=e.search(/[^\s\u00a0]/))&&(t=e.length);for(var s=i||0,o=r||0;;){var a=e.indexOf("\t",s);if(a<0||a>=t)return o+(t-s);o+=a-s,o+=n-o%n,s=a+1}}p?B=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:o&&(B=function(e){try{e.select()}catch(e){}});var H=function(){this.id=null,this.f=null,this.time=0,this.handler=$(this.onTimeout,this)};function D(e,t){for(var n=0;n<e.length;++n)if(e[n]==t)return n;return-1}H.prototype.onTimeout=function(e){e.id=0,e.time<=+new Date?e.f():setTimeout(e.handler,e.time-+new Date)},H.prototype.set=function(e,t){this.f=t;var n=+new Date+e;(!this.id||n<this.time)&&(clearTimeout(this.id),this.id=setTimeout(this.handler,e),this.time=n)};var P={toString:function(){return"CodeMirror.Pass"}},W={scroll:!1},U={origin:"*mouse"},j={origin:"+move"};function K(e,t,n){for(var i=0,r=0;;){var s=e.indexOf("\t",i);-1==s&&(s=e.length);var o=s-i;if(s==e.length||r+o>=t)return i+Math.min(o,t-r);if(r+=s-i,i=s+1,(r+=n-r%n)>=t)return i}}var V=[""];function q(e){for(;V.length<=e;)V.push(X(V)+" ");return V[e]}function X(e){return e[e.length-1]}function G(e,t){for(var n=[],i=0;i<e.length;i++)n[i]=t(e[i],i);return n}function Y(){}function J(e,t){var n;return Object.create?n=Object.create(e):(Y.prototype=e,n=new Y),t&&O(t,n),n}var Q=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;function Z(e){return/\w/.test(e)||e>""&&(e.toUpperCase()!=e.toLowerCase()||Q.test(e))}function ee(e,t){return t?!!(t.source.indexOf("\\w")>-1&&Z(e))||t.test(e):Z(e)}function te(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}var ne=/[\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]/;function ie(e){return e.charCodeAt(0)>=768&&ne.test(e)}function re(e,t,n){for(;(n<0?t>0:t<e.length)&&ie(e.charAt(t));)t+=n;return t}function se(e,t,n){for(var i=t>n?-1:1;;){if(t==n)return t;var r=(t+n)/2,s=i<0?Math.ceil(r):Math.floor(r);if(s==t)return e(s)?t:n;e(s)?n=s:t=s+i}}var oe=null;function ae(e,t,n){var i;oe=null;for(var r=0;r<e.length;++r){var s=e[r];if(s.from<t&&s.to>t)return r;s.to==t&&(s.from!=s.to&&"before"==n?i=r:oe=r),s.from==t&&(s.from!=s.to&&"before"!=n?i=r:oe=r)}return null!=i?i:oe}var le=function(){var e=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,t=/[stwN]/,n=/[LRr]/,i=/[Lb1n]/,r=/[1n]/;function s(e,t,n){this.level=e,this.from=t,this.to=n}return function(o,a){var l="ltr"==a?"L":"R";if(0==o.length||"ltr"==a&&!e.test(o))return!1;for(var c,d=o.length,h=[],u=0;u<d;++u)h.push((c=o.charCodeAt(u))<=247?"bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN".charAt(c):1424<=c&&c<=1524?"R":1536<=c&&c<=1785?"nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111".charAt(c-1536):1774<=c&&c<=2220?"r":8192<=c&&c<=8203?"w":8204==c?"b":"L");for(var f=0,m=l;f<d;++f){var p=h[f];"m"==p?h[f]=m:m=p}for(var g=0,v=l;g<d;++g){var _=h[g];"1"==_&&"r"==v?h[g]="n":n.test(_)&&(v=_,"r"==_&&(h[g]="R"))}for(var y=1,b=h[0];y<d-1;++y){var x=h[y];"+"==x&&"1"==b&&"1"==h[y+1]?h[y]="1":","!=x||b!=h[y+1]||"1"!=b&&"n"!=b||(h[y]=b),b=x}for(var w=0;w<d;++w){var k=h[w];if(","==k)h[w]="N";else if("%"==k){var C=void 0;for(C=w+1;C<d&&"%"==h[C];++C);for(var S=w&&"!"==h[w-1]||C<d&&"1"==h[C]?"1":"N",L=w;L<C;++L)h[L]=S;w=C-1}}for(var M=0,T=l;M<d;++M){var I=h[M];"L"==T&&"1"==I?h[M]="L":n.test(I)&&(T=I)}for(var A=0;A<d;++A)if(t.test(h[A])){var E=void 0;for(E=A+1;E<d&&t.test(h[E]);++E);for(var z="L"==(A?h[A-1]:l),N=z==("L"==(E<d?h[E]:l))?z?"L":"R":l,F=A;F<E;++F)h[F]=N;A=E-1}for(var B,$=[],O=0;O<d;)if(i.test(h[O])){var R=O;for(++O;O<d&&i.test(h[O]);++O);$.push(new s(0,R,O))}else{var H=O,D=$.length,P="rtl"==a?1:0;for(++O;O<d&&"L"!=h[O];++O);for(var W=H;W<O;)if(r.test(h[W])){H<W&&($.splice(D,0,new s(1,H,W)),D+=P);var U=W;for(++W;W<O&&r.test(h[W]);++W);$.splice(D,0,new s(2,U,W)),D+=P,H=W}else++W;H<O&&$.splice(D,0,new s(1,H,O))}return"ltr"==a&&(1==$[0].level&&(B=o.match(/^\s+/))&&($[0].from=B[0].length,$.unshift(new s(0,0,B[0].length))),1==X($).level&&(B=o.match(/\s+$/))&&(X($).to-=B[0].length,$.push(new s(0,d-B[0].length,d)))),"rtl"==a?$.reverse():$}}();function ce(e,t){var n=e.order;return null==n&&(n=e.order=le(e.text,t)),n}var de=[],he=function(e,t,n){if(e.addEventListener)e.addEventListener(t,n,!1);else if(e.attachEvent)e.attachEvent("on"+t,n);else{var i=e._handlers||(e._handlers={});i[t]=(i[t]||de).concat(n)}};function ue(e,t){return e._handlers&&e._handlers[t]||de}function fe(e,t,n){if(e.removeEventListener)e.removeEventListener(t,n,!1);else if(e.detachEvent)e.detachEvent("on"+t,n);else{var i=e._handlers,r=i&&i[t];if(r){var s=D(r,n);s>-1&&(i[t]=r.slice(0,s).concat(r.slice(s+1)))}}}function me(e,t){var n=ue(e,t);if(n.length)for(var i=Array.prototype.slice.call(arguments,2),r=0;r<n.length;++r)n[r].apply(null,i)}function pe(e,t,n){return"string"==typeof t&&(t={type:t,preventDefault:function(){this.defaultPrevented=!0}}),me(e,n||t.type,e,t),xe(t)||t.codemirrorIgnore}function ge(e){var t=e._handlers&&e._handlers.cursorActivity;if(t)for(var n=e.curOp.cursorActivityHandlers||(e.curOp.cursorActivityHandlers=[]),i=0;i<t.length;++i)-1==D(n,t[i])&&n.push(t[i])}function ve(e,t){return ue(e,t).length>0}function _e(e){e.prototype.on=function(e,t){he(this,e,t)},e.prototype.off=function(e,t){fe(this,e,t)}}function ye(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function be(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function xe(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function we(e){ye(e),be(e)}function ke(e){return e.target||e.srcElement}function Ce(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),_&&e.ctrlKey&&1==t&&(t=3),t}var Se,Le,Me=function(){if(o&&a<9)return!1;var e=I("div");return"draggable"in e||"dragDrop"in e}();function Te(e){if(null==Se){var t=I("span","");T(e,I("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(Se=t.offsetWidth<=1&&t.offsetHeight>2&&!(o&&a<8))}var n=Se?I("span",""):I("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return n.setAttribute("cm-text",""),n}function Ie(e){if(null!=Le)return Le;var t=T(e,document.createTextNode("AخA")),n=S(t,0,1).getBoundingClientRect(),i=S(t,1,2).getBoundingClientRect();return M(e),!(!n||n.left==n.right)&&(Le=i.right-n.right<3)}var Ae,Ee=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,n=[],i=e.length;t<=i;){var r=e.indexOf("\n",t);-1==r&&(r=e.length);var s=e.slice(t,"\r"==e.charAt(r-1)?r-1:r),o=s.indexOf("\r");-1!=o?(n.push(s.slice(0,o)),t+=o+1):(n.push(s),t=r+1)}return n}:function(e){return e.split(/\r\n?|\n/)},ze=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(e){return!1}}:function(e){var t;try{t=e.ownerDocument.selection.createRange()}catch(e){}return!(!t||t.parentElement()!=e)&&0!=t.compareEndPoints("StartToEnd",t)},Ne="oncopy"in(Ae=I("div"))||(Ae.setAttribute("oncopy","return;"),"function"==typeof Ae.oncopy),Fe=null;var Be={},$e={};function Oe(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),Be[e]=t}function Re(e){if("string"==typeof e&&$e.hasOwnProperty(e))e=$e[e];else if(e&&"string"==typeof e.name&&$e.hasOwnProperty(e.name)){var t=$e[e.name];"string"==typeof t&&(t={name:t}),(e=J(t,e)).name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return Re("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return Re("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function He(e,t){t=Re(t);var n=Be[t.name];if(!n)return He(e,"text/plain");var i=n(e,t);if(De.hasOwnProperty(t.name)){var r=De[t.name];for(var s in r)r.hasOwnProperty(s)&&(i.hasOwnProperty(s)&&(i["_"+s]=i[s]),i[s]=r[s])}if(i.name=t.name,t.helperType&&(i.helperType=t.helperType),t.modeProps)for(var o in t.modeProps)i[o]=t.modeProps[o];return i}var De={};function Pe(e,t){O(t,De.hasOwnProperty(e)?De[e]:De[e]={})}function We(e,t){if(!0===t)return t;if(e.copyState)return e.copyState(t);var n={};for(var i in t){var r=t[i];r instanceof Array&&(r=r.concat([])),n[i]=r}return n}function Ue(e,t){for(var n;e.innerMode&&(n=e.innerMode(t))&&n.mode!=e;)t=n.state,e=n.mode;return n||{mode:e,state:t}}function je(e,t,n){return!e.startState||e.startState(t,n)}var Ke=function(e,t,n){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0,this.lineOracle=n};function Ve(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 n=e;!n.lines;)for(var i=0;;++i){var r=n.children[i],s=r.chunkSize();if(t<s){n=r;break}t-=s}return n.lines[t]}function qe(e,t,n){var i=[],r=t.line;return e.iter(t.line,n.line+1,(function(e){var s=e.text;r==n.line&&(s=s.slice(0,n.ch)),r==t.line&&(s=s.slice(t.ch)),i.push(s),++r})),i}function Xe(e,t,n){var i=[];return e.iter(t,n,(function(e){i.push(e.text)})),i}function Ge(e,t){var n=t-e.height;if(n)for(var i=e;i;i=i.parent)i.height+=n}function Ye(e){if(null==e.parent)return null;for(var t=e.parent,n=D(t.lines,e),i=t.parent;i;t=i,i=i.parent)for(var r=0;i.children[r]!=t;++r)n+=i.children[r].chunkSize();return n+t.first}function Je(e,t){var n=e.first;e:do{for(var i=0;i<e.children.length;++i){var r=e.children[i],s=r.height;if(t<s){e=r;continue e}t-=s,n+=r.chunkSize()}return n}while(!e.lines);for(var o=0;o<e.lines.length;++o){var a=e.lines[o].height;if(t<a)break;t-=a}return n+o}function Qe(e,t){return t>=e.first&&t<e.first+e.size}function Ze(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function et(e,t,n){if(void 0===n&&(n=null),!(this instanceof et))return new et(e,t,n);this.line=e,this.ch=t,this.sticky=n}function tt(e,t){return e.line-t.line||e.ch-t.ch}function nt(e,t){return e.sticky==t.sticky&&0==tt(e,t)}function it(e){return et(e.line,e.ch)}function rt(e,t){return tt(e,t)<0?t:e}function st(e,t){return tt(e,t)<0?e:t}function ot(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function at(e,t){if(t.line<e.first)return et(e.first,0);var n=e.first+e.size-1;return t.line>n?et(n,Ve(e,n).text.length):function(e,t){var n=e.ch;return null==n||n>t?et(e.line,t):n<0?et(e.line,0):e}(t,Ve(e,t.line).text.length)}function lt(e,t){for(var n=[],i=0;i<t.length;i++)n[i]=at(e,t[i]);return n}Ke.prototype.eol=function(){return this.pos>=this.string.length},Ke.prototype.sol=function(){return this.pos==this.lineStart},Ke.prototype.peek=function(){return this.string.charAt(this.pos)||void 0},Ke.prototype.next=function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},Ke.prototype.eat=function(e){var t=this.string.charAt(this.pos);if("string"==typeof e?t==e:t&&(e.test?e.test(t):e(t)))return++this.pos,t},Ke.prototype.eatWhile=function(e){for(var t=this.pos;this.eat(e););return this.pos>t},Ke.prototype.eatSpace=function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},Ke.prototype.skipToEnd=function(){this.pos=this.string.length},Ke.prototype.skipTo=function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},Ke.prototype.backUp=function(e){this.pos-=e},Ke.prototype.column=function(){return this.lastColumnPos<this.start&&(this.lastColumnValue=R(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?R(this.string,this.lineStart,this.tabSize):0)},Ke.prototype.indentation=function(){return R(this.string,null,this.tabSize)-(this.lineStart?R(this.string,this.lineStart,this.tabSize):0)},Ke.prototype.match=function(e,t,n){if("string"!=typeof e){var i=this.string.slice(this.pos).match(e);return i&&i.index>0?null:(i&&!1!==t&&(this.pos+=i[0].length),i)}var r=function(e){return n?e.toLowerCase():e};if(r(this.string.substr(this.pos,e.length))==r(e))return!1!==t&&(this.pos+=e.length),!0},Ke.prototype.current=function(){return this.string.slice(this.start,this.pos)},Ke.prototype.hideFirstChars=function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}},Ke.prototype.lookAhead=function(e){var t=this.lineOracle;return t&&t.lookAhead(e)},Ke.prototype.baseToken=function(){var e=this.lineOracle;return e&&e.baseToken(this.pos)};var ct=function(e,t){this.state=e,this.lookAhead=t},dt=function(e,t,n,i){this.state=t,this.doc=e,this.line=n,this.maxLookAhead=i||0,this.baseTokens=null,this.baseTokenPos=1};function ht(e,t,n,i){var r=[e.state.modeGen],s={};bt(e,t.text,e.doc.mode,n,(function(e,t){return r.push(e,t)}),s,i);for(var o=n.state,a=function(i){n.baseTokens=r;var a=e.state.overlays[i],l=1,c=0;n.state=!0,bt(e,t.text,a.mode,n,(function(e,t){for(var n=l;c<e;){var i=r[l];i>e&&r.splice(l,1,e,r[l+1],i),l+=2,c=Math.min(e,i)}if(t)if(a.opaque)r.splice(n,l-n,e,"overlay "+t),l=n+2;else for(;n<l;n+=2){var s=r[n+1];r[n+1]=(s?s+" ":"")+"overlay "+t}}),s),n.state=o,n.baseTokens=null,n.baseTokenPos=1},l=0;l<e.state.overlays.length;++l)a(l);return{styles:r,classes:s.bgClass||s.textClass?s:null}}function ut(e,t,n){if(!t.styles||t.styles[0]!=e.state.modeGen){var i=ft(e,Ye(t)),r=t.text.length>e.options.maxHighlightLength&&We(e.doc.mode,i.state),s=ht(e,t,i);r&&(i.state=r),t.stateAfter=i.save(!r),t.styles=s.styles,s.classes?t.styleClasses=s.classes:t.styleClasses&&(t.styleClasses=null),n===e.doc.highlightFrontier&&(e.doc.modeFrontier=Math.max(e.doc.modeFrontier,++e.doc.highlightFrontier))}return t.styles}function ft(e,t,n){var i=e.doc,r=e.display;if(!i.mode.startState)return new dt(i,!0,t);var s=function(e,t,n){for(var i,r,s=e.doc,o=n?-1:t-(e.doc.mode.innerMode?1e3:100),a=t;a>o;--a){if(a<=s.first)return s.first;var l=Ve(s,a-1),c=l.stateAfter;if(c&&(!n||a+(c instanceof ct?c.lookAhead:0)<=s.modeFrontier))return a;var d=R(l.text,null,e.options.tabSize);(null==r||i>d)&&(r=a-1,i=d)}return r}(e,t,n),o=s>i.first&&Ve(i,s-1).stateAfter,a=o?dt.fromSaved(i,o,s):new dt(i,je(i.mode),s);return i.iter(s,t,(function(n){mt(e,n.text,a);var i=a.line;n.stateAfter=i==t-1||i%5==0||i>=r.viewFrom&&i<r.viewTo?a.save():null,a.nextLine()})),n&&(i.modeFrontier=a.line),a}function mt(e,t,n,i){var r=e.doc.mode,s=new Ke(t,e.options.tabSize,n);for(s.start=s.pos=i||0,""==t&&pt(r,n.state);!s.eol();)gt(r,s,n.state),s.start=s.pos}function pt(e,t){if(e.blankLine)return e.blankLine(t);if(e.innerMode){var n=Ue(e,t);return n.mode.blankLine?n.mode.blankLine(n.state):void 0}}function gt(e,t,n,i){for(var r=0;r<10;r++){i&&(i[0]=Ue(e,n).mode);var s=e.token(t,n);if(t.pos>t.start)return s}throw new Error("Mode "+e.name+" failed to advance stream.")}dt.prototype.lookAhead=function(e){var t=this.doc.getLine(this.line+e);return null!=t&&e>this.maxLookAhead&&(this.maxLookAhead=e),t},dt.prototype.baseToken=function(e){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=e;)this.baseTokenPos+=2;var t=this.baseTokens[this.baseTokenPos+1];return{type:t&&t.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}},dt.prototype.nextLine=function(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--},dt.fromSaved=function(e,t,n){return t instanceof ct?new dt(e,We(e.mode,t.state),n,t.lookAhead):new dt(e,We(e.mode,t),n)},dt.prototype.save=function(e){var t=!1!==e?We(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new ct(t,this.maxLookAhead):t};var vt=function(e,t,n){this.start=e.start,this.end=e.pos,this.string=e.current(),this.type=t||null,this.state=n};function _t(e,t,n,i){var r,s,o=e.doc,a=o.mode,l=Ve(o,(t=at(o,t)).line),c=ft(e,t.line,n),d=new Ke(l.text,e.options.tabSize,c);for(i&&(s=[]);(i||d.pos<t.ch)&&!d.eol();)d.start=d.pos,r=gt(a,d,c.state),i&&s.push(new vt(d,r,We(o.mode,c.state)));return i?s:new vt(d,r,c.state)}function yt(e,t){if(e)for(;;){var n=e.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!n)break;e=e.slice(0,n.index)+e.slice(n.index+n[0].length);var i=n[1]?"bgClass":"textClass";null==t[i]?t[i]=n[2]:new RegExp("(?:^|\\s)"+n[2]+"(?:$|\\s)").test(t[i])||(t[i]+=" "+n[2])}return e}function bt(e,t,n,i,r,s,o){var a=n.flattenSpans;null==a&&(a=e.options.flattenSpans);var l,c=0,d=null,h=new Ke(t,e.options.tabSize,i),u=e.options.addModeClass&&[null];for(""==t&&yt(pt(n,i.state),s);!h.eol();){if(h.pos>e.options.maxHighlightLength?(a=!1,o&&mt(e,t,i,h.pos),h.pos=t.length,l=null):l=yt(gt(n,h,i.state,u),s),u){var f=u[0].name;f&&(l="m-"+(l?f+" "+l:f))}if(!a||d!=l){for(;c<h.start;)r(c=Math.min(h.start,c+5e3),d);d=l}h.start=h.pos}for(;c<h.pos;){var m=Math.min(h.pos,c+5e3);r(m,d),c=m}}var xt=!1,wt=!1;function kt(e,t,n){this.marker=e,this.from=t,this.to=n}function Ct(e,t){if(e)for(var n=0;n<e.length;++n){var i=e[n];if(i.marker==t)return i}}function St(e,t){for(var n,i=0;i<e.length;++i)e[i]!=t&&(n||(n=[])).push(e[i]);return n}function Lt(e,t){if(t.full)return null;var n=Qe(e,t.from.line)&&Ve(e,t.from.line).markedSpans,i=Qe(e,t.to.line)&&Ve(e,t.to.line).markedSpans;if(!n&&!i)return null;var r=t.from.ch,s=t.to.ch,o=0==tt(t.from,t.to),a=function(e,t,n){var i;if(e)for(var r=0;r<e.length;++r){var s=e[r],o=s.marker;if(null==s.from||(o.inclusiveLeft?s.from<=t:s.from<t)||s.from==t&&"bookmark"==o.type&&(!n||!s.marker.insertLeft)){var a=null==s.to||(o.inclusiveRight?s.to>=t:s.to>t);(i||(i=[])).push(new kt(o,s.from,a?null:s.to))}}return i}(n,r,o),l=function(e,t,n){var i;if(e)for(var r=0;r<e.length;++r){var s=e[r],o=s.marker;if(null==s.to||(o.inclusiveRight?s.to>=t:s.to>t)||s.from==t&&"bookmark"==o.type&&(!n||s.marker.insertLeft)){var a=null==s.from||(o.inclusiveLeft?s.from<=t:s.from<t);(i||(i=[])).push(new kt(o,a?null:s.from-t,null==s.to?null:s.to-t))}}return i}(i,s,o),c=1==t.text.length,d=X(t.text).length+(c?r:0);if(a)for(var h=0;h<a.length;++h){var u=a[h];if(null==u.to){var f=Ct(l,u.marker);f?c&&(u.to=null==f.to?null:f.to+d):u.to=r}}if(l)for(var m=0;m<l.length;++m){var p=l[m];if(null!=p.to&&(p.to+=d),null==p.from)Ct(a,p.marker)||(p.from=d,c&&(a||(a=[])).push(p));else p.from+=d,c&&(a||(a=[])).push(p)}a&&(a=Mt(a)),l&&l!=a&&(l=Mt(l));var g=[a];if(!c){var v,_=t.text.length-2;if(_>0&&a)for(var y=0;y<a.length;++y)null==a[y].to&&(v||(v=[])).push(new kt(a[y].marker,null,null));for(var b=0;b<_;++b)g.push(v);g.push(l)}return g}function Mt(e){for(var t=0;t<e.length;++t){var n=e[t];null!=n.from&&n.from==n.to&&!1!==n.marker.clearWhenEmpty&&e.splice(t--,1)}return e.length?e:null}function Tt(e){var t=e.markedSpans;if(t){for(var n=0;n<t.length;++n)t[n].marker.detachLine(e);e.markedSpans=null}}function It(e,t){if(t){for(var n=0;n<t.length;++n)t[n].marker.attachLine(e);e.markedSpans=t}}function At(e){return e.inclusiveLeft?-1:0}function Et(e){return e.inclusiveRight?1:0}function zt(e,t){var n=e.lines.length-t.lines.length;if(0!=n)return n;var i=e.find(),r=t.find(),s=tt(i.from,r.from)||At(e)-At(t);if(s)return-s;var o=tt(i.to,r.to)||Et(e)-Et(t);return o||t.id-e.id}function Nt(e,t){var n,i=wt&&e.markedSpans;if(i)for(var r=void 0,s=0;s<i.length;++s)(r=i[s]).marker.collapsed&&null==(t?r.from:r.to)&&(!n||zt(n,r.marker)<0)&&(n=r.marker);return n}function Ft(e){return Nt(e,!0)}function Bt(e){return Nt(e,!1)}function $t(e,t){var n,i=wt&&e.markedSpans;if(i)for(var r=0;r<i.length;++r){var s=i[r];s.marker.collapsed&&(null==s.from||s.from<t)&&(null==s.to||s.to>t)&&(!n||zt(n,s.marker)<0)&&(n=s.marker)}return n}function Ot(e,t,n,i,r){var s=Ve(e,t),o=wt&&s.markedSpans;if(o)for(var a=0;a<o.length;++a){var l=o[a];if(l.marker.collapsed){var c=l.marker.find(0),d=tt(c.from,n)||At(l.marker)-At(r),h=tt(c.to,i)||Et(l.marker)-Et(r);if(!(d>=0&&h<=0||d<=0&&h>=0)&&(d<=0&&(l.marker.inclusiveRight&&r.inclusiveLeft?tt(c.to,n)>=0:tt(c.to,n)>0)||d>=0&&(l.marker.inclusiveRight&&r.inclusiveLeft?tt(c.from,i)<=0:tt(c.from,i)<0)))return!0}}}function Rt(e){for(var t;t=Ft(e);)e=t.find(-1,!0).line;return e}function Ht(e,t){var n=Ve(e,t),i=Rt(n);return n==i?t:Ye(i)}function Dt(e,t){if(t>e.lastLine())return t;var n,i=Ve(e,t);if(!Pt(e,i))return t;for(;n=Bt(i);)i=n.find(1,!0).line;return Ye(i)+1}function Pt(e,t){var n=wt&&t.markedSpans;if(n)for(var i=void 0,r=0;r<n.length;++r)if((i=n[r]).marker.collapsed){if(null==i.from)return!0;if(!i.marker.widgetNode&&0==i.from&&i.marker.inclusiveLeft&&Wt(e,t,i))return!0}}function Wt(e,t,n){if(null==n.to){var i=n.marker.find(1,!0);return Wt(e,i.line,Ct(i.line.markedSpans,n.marker))}if(n.marker.inclusiveRight&&n.to==t.text.length)return!0;for(var r=void 0,s=0;s<t.markedSpans.length;++s)if((r=t.markedSpans[s]).marker.collapsed&&!r.marker.widgetNode&&r.from==n.to&&(null==r.to||r.to!=n.from)&&(r.marker.inclusiveLeft||n.marker.inclusiveRight)&&Wt(e,t,r))return!0}function Ut(e){for(var t=0,n=(e=Rt(e)).parent,i=0;i<n.lines.length;++i){var r=n.lines[i];if(r==e)break;t+=r.height}for(var s=n.parent;s;s=(n=s).parent)for(var o=0;o<s.children.length;++o){var a=s.children[o];if(a==n)break;t+=a.height}return t}function jt(e){if(0==e.height)return 0;for(var t,n=e.text.length,i=e;t=Ft(i);){var r=t.find(0,!0);i=r.from.line,n+=r.from.ch-r.to.ch}for(i=e;t=Bt(i);){var s=t.find(0,!0);n-=i.text.length-s.from.ch,n+=(i=s.to.line).text.length-s.to.ch}return n}function Kt(e){var t=e.display,n=e.doc;t.maxLine=Ve(n,n.first),t.maxLineLength=jt(t.maxLine),t.maxLineChanged=!0,n.iter((function(e){var n=jt(e);n>t.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)}))}var Vt=function(e,t,n){this.text=e,It(this,t),this.height=n?n(this):1};function qt(e){e.parent=null,Tt(e)}Vt.prototype.lineNo=function(){return Ye(this)},_e(Vt);var Xt={},Gt={};function Yt(e,t){if(!e||/^\s*$/.test(e))return null;var n=t.addModeClass?Gt:Xt;return n[e]||(n[e]=e.replace(/\S+/g,"cm-$&"))}function Jt(e,t){var n=A("span",null,null,l?"padding-right: .1px":null),i={pre:A("pre",[n],"CodeMirror-line"),content:n,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:e.getOption("lineWrapping")};t.measure={};for(var r=0;r<=(t.rest?t.rest.length:0);r++){var s=r?t.rest[r-1]:t.line,o=void 0;i.pos=0,i.addToken=Zt,Ie(e.display.measure)&&(o=ce(s,e.doc.direction))&&(i.addToken=en(i.addToken,o)),i.map=[],nn(s,i,ut(e,s,t!=e.display.externalMeasured&&Ye(s))),s.styleClasses&&(s.styleClasses.bgClass&&(i.bgClass=F(s.styleClasses.bgClass,i.bgClass||"")),s.styleClasses.textClass&&(i.textClass=F(s.styleClasses.textClass,i.textClass||""))),0==i.map.length&&i.map.push(0,0,i.content.appendChild(Te(e.display.measure))),0==r?(t.measure.map=i.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(i.map),(t.measure.caches||(t.measure.caches=[])).push({}))}if(l){var a=i.content.lastChild;(/\bcm-tab\b/.test(a.className)||a.querySelector&&a.querySelector(".cm-tab"))&&(i.content.className="cm-tab-wrap-hack")}return me(e,"renderLine",e,t.line,i.pre),i.pre.className&&(i.textClass=F(i.pre.className,i.textClass||"")),i}function Qt(e){var t=I("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function Zt(e,t,n,i,r,s,l){if(t){var c,d=e.splitSpaces?function(e,t){if(e.length>1&&!/ /.test(e))return e;for(var n=t,i="",r=0;r<e.length;r++){var s=e.charAt(r);" "!=s||!n||r!=e.length-1&&32!=e.charCodeAt(r+1)||(s=" "),i+=s,n=" "==s}return i}(t,e.trailingSpace):t,h=e.cm.state.specialChars,u=!1;if(h.test(t)){c=document.createDocumentFragment();for(var f=0;;){h.lastIndex=f;var m=h.exec(t),p=m?m.index-f:t.length-f;if(p){var g=document.createTextNode(d.slice(f,f+p));o&&a<9?c.appendChild(I("span",[g])):c.appendChild(g),e.map.push(e.pos,e.pos+p,g),e.col+=p,e.pos+=p}if(!m)break;f+=p+1;var v=void 0;if("\t"==m[0]){var _=e.cm.options.tabSize,y=_-e.col%_;(v=c.appendChild(I("span",q(y),"cm-tab"))).setAttribute("role","presentation"),v.setAttribute("cm-text","\t"),e.col+=y}else"\r"==m[0]||"\n"==m[0]?((v=c.appendChild(I("span","\r"==m[0]?"␍":"","cm-invalidchar"))).setAttribute("cm-text",m[0]),e.col+=1):((v=e.cm.options.specialCharPlaceholder(m[0])).setAttribute("cm-text",m[0]),o&&a<9?c.appendChild(I("span",[v])):c.appendChild(v),e.col+=1);e.map.push(e.pos,e.pos+1,v),e.pos++}}else e.col+=t.length,c=document.createTextNode(d),e.map.push(e.pos,e.pos+t.length,c),o&&a<9&&(u=!0),e.pos+=t.length;if(e.trailingSpace=32==d.charCodeAt(t.length-1),n||i||r||u||s||l){var b=n||"";i&&(b+=i),r&&(b+=r);var x=I("span",[c],b,s);if(l)for(var w in l)l.hasOwnProperty(w)&&"style"!=w&&"class"!=w&&x.setAttribute(w,l[w]);return e.content.appendChild(x)}e.content.appendChild(c)}}function en(e,t){return function(n,i,r,s,o,a,l){r=r?r+" cm-force-border":"cm-force-border";for(var c=n.pos,d=c+i.length;;){for(var h=void 0,u=0;u<t.length&&!((h=t[u]).to>c&&h.from<=c);u++);if(h.to>=d)return e(n,i,r,s,o,a,l);e(n,i.slice(0,h.to-c),r,s,null,a,l),s=null,i=i.slice(h.to-c),c=h.to}}}function tn(e,t,n,i){var r=!i&&n.widgetNode;r&&e.map.push(e.pos,e.pos+t,r),!i&&e.cm.display.input.needsContentAttribute&&(r||(r=e.content.appendChild(document.createElement("span"))),r.setAttribute("cm-marker",n.id)),r&&(e.cm.display.input.setUneditable(r),e.content.appendChild(r)),e.pos+=t,e.trailingSpace=!1}function nn(e,t,n){var i=e.markedSpans,r=e.text,s=0;if(i)for(var o,a,l,c,d,h,u,f=r.length,m=0,p=1,g="",v=0;;){if(v==m){l=c=d=a="",u=null,h=null,v=1/0;for(var _=[],y=void 0,b=0;b<i.length;++b){var x=i[b],w=x.marker;if("bookmark"==w.type&&x.from==m&&w.widgetNode)_.push(w);else if(x.from<=m&&(null==x.to||x.to>m||w.collapsed&&x.to==m&&x.from==m)){if(null!=x.to&&x.to!=m&&v>x.to&&(v=x.to,c=""),w.className&&(l+=" "+w.className),w.css&&(a=(a?a+";":"")+w.css),w.startStyle&&x.from==m&&(d+=" "+w.startStyle),w.endStyle&&x.to==v&&(y||(y=[])).push(w.endStyle,x.to),w.title&&((u||(u={})).title=w.title),w.attributes)for(var k in w.attributes)(u||(u={}))[k]=w.attributes[k];w.collapsed&&(!h||zt(h.marker,w)<0)&&(h=x)}else x.from>m&&v>x.from&&(v=x.from)}if(y)for(var C=0;C<y.length;C+=2)y[C+1]==v&&(c+=" "+y[C]);if(!h||h.from==m)for(var S=0;S<_.length;++S)tn(t,0,_[S]);if(h&&(h.from||0)==m){if(tn(t,(null==h.to?f+1:h.to)-m,h.marker,null==h.from),null==h.to)return;h.to==m&&(h=!1)}}if(m>=f)break;for(var L=Math.min(f,v);;){if(g){var M=m+g.length;if(!h){var T=M>L?g.slice(0,L-m):g;t.addToken(t,T,o?o+l:l,d,m+T.length==v?c:"",a,u)}if(M>=L){g=g.slice(L-m),m=L;break}m=M,d=""}g=r.slice(s,s=n[p++]),o=Yt(n[p++],t.cm.options)}}else for(var I=1;I<n.length;I+=2)t.addToken(t,r.slice(s,s=n[I]),Yt(n[I+1],t.cm.options))}function rn(e,t,n){this.line=t,this.rest=function(e){for(var t,n;t=Bt(e);)e=t.find(1,!0).line,(n||(n=[])).push(e);return n}(t),this.size=this.rest?Ye(X(this.rest))-n+1:1,this.node=this.text=null,this.hidden=Pt(e,t)}function sn(e,t,n){for(var i,r=[],s=t;s<n;s=i){var o=new rn(e.doc,Ve(e.doc,s),s);i=s+o.size,r.push(o)}return r}var on=null;var an=null;function ln(e,t){var n=ue(e,t);if(n.length){var i,r=Array.prototype.slice.call(arguments,2);on?i=on.delayedCallbacks:an?i=an:(i=an=[],setTimeout(cn,0));for(var s=function(e){i.push((function(){return n[e].apply(null,r)}))},o=0;o<n.length;++o)s(o)}}function cn(){var e=an;an=null;for(var t=0;t<e.length;++t)e[t]()}function dn(e,t,n,i){for(var r=0;r<t.changes.length;r++){var s=t.changes[r];"text"==s?fn(e,t):"gutter"==s?pn(e,t,n,i):"class"==s?mn(e,t):"widget"==s&&gn(e,t,i)}t.changes=null}function hn(e){return e.node==e.text&&(e.node=I("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),o&&a<8&&(e.node.style.zIndex=2)),e.node}function un(e,t){var n=e.display.externalMeasured;return n&&n.line==t.line?(e.display.externalMeasured=null,t.measure=n.measure,n.built):Jt(e,t)}function fn(e,t){var n=t.text.className,i=un(e,t);t.text==t.node&&(t.node=i.pre),t.text.parentNode.replaceChild(i.pre,t.text),t.text=i.pre,i.bgClass!=t.bgClass||i.textClass!=t.textClass?(t.bgClass=i.bgClass,t.textClass=i.textClass,mn(e,t)):n&&(t.text.className=n)}function mn(e,t){!function(e,t){var n=t.bgClass?t.bgClass+" "+(t.line.bgClass||""):t.line.bgClass;if(n&&(n+=" CodeMirror-linebackground"),t.background)n?t.background.className=n:(t.background.parentNode.removeChild(t.background),t.background=null);else if(n){var i=hn(t);t.background=i.insertBefore(I("div",null,n),i.firstChild),e.display.input.setUneditable(t.background)}}(e,t),t.line.wrapClass?hn(t).className=t.line.wrapClass:t.node!=t.text&&(t.node.className="");var n=t.textClass?t.textClass+" "+(t.line.textClass||""):t.line.textClass;t.text.className=n||""}function pn(e,t,n,i){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var r=hn(t);t.gutterBackground=I("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px; width: "+i.gutterTotalWidth+"px"),e.display.input.setUneditable(t.gutterBackground),r.insertBefore(t.gutterBackground,t.text)}var s=t.line.gutterMarkers;if(e.options.lineNumbers||s){var o=hn(t),a=t.gutter=I("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px");if(a.setAttribute("aria-hidden","true"),e.display.input.setUneditable(a),o.insertBefore(a,t.text),t.line.gutterClass&&(a.className+=" "+t.line.gutterClass),!e.options.lineNumbers||s&&s["CodeMirror-linenumbers"]||(t.lineNumber=a.appendChild(I("div",Ze(e.options,n),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+i.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),s)for(var l=0;l<e.display.gutterSpecs.length;++l){var c=e.display.gutterSpecs[l].className,d=s.hasOwnProperty(c)&&s[c];d&&a.appendChild(I("div",[d],"CodeMirror-gutter-elt","left: "+i.gutterLeft[c]+"px; width: "+i.gutterWidth[c]+"px"))}}}function gn(e,t,n){t.alignable&&(t.alignable=null);for(var i=C("CodeMirror-linewidget"),r=t.node.firstChild,s=void 0;r;r=s)s=r.nextSibling,i.test(r.className)&&t.node.removeChild(r);_n(e,t,n)}function vn(e,t,n,i){var r=un(e,t);return t.text=t.node=r.pre,r.bgClass&&(t.bgClass=r.bgClass),r.textClass&&(t.textClass=r.textClass),mn(e,t),pn(e,t,n,i),_n(e,t,i),t.node}function _n(e,t,n){if(yn(e,t.line,t,n,!0),t.rest)for(var i=0;i<t.rest.length;i++)yn(e,t.rest[i],t,n,!1)}function yn(e,t,n,i,r){if(t.widgets)for(var s=hn(n),o=0,a=t.widgets;o<a.length;++o){var l=a[o],c=I("div",[l.node],"CodeMirror-linewidget"+(l.className?" "+l.className:""));l.handleMouseEvents||c.setAttribute("cm-ignore-events","true"),bn(l,c,n,i),e.display.input.setUneditable(c),r&&l.above?s.insertBefore(c,n.gutter||n.text):s.appendChild(c),ln(l,"redraw")}}function bn(e,t,n,i){if(e.noHScroll){(n.alignable||(n.alignable=[])).push(t);var r=i.wrapperWidth;t.style.left=i.fixedPos+"px",e.coverGutter||(r-=i.gutterTotalWidth,t.style.paddingLeft=i.gutterTotalWidth+"px"),t.style.width=r+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-i.gutterTotalWidth+"px"))}function xn(e){if(null!=e.height)return e.height;var t=e.doc.cm;if(!t)return 0;if(!E(document.body,e.node)){var n="position: relative;";e.coverGutter&&(n+="margin-left: -"+t.display.gutters.offsetWidth+"px;"),e.noHScroll&&(n+="width: "+t.display.wrapper.clientWidth+"px;"),T(t.display.measure,I("div",[e.node],null,n))}return e.height=e.node.parentNode.offsetHeight}function wn(e,t){for(var n=ke(t);n!=e.wrapper;n=n.parentNode)if(!n||1==n.nodeType&&"true"==n.getAttribute("cm-ignore-events")||n.parentNode==e.sizer&&n!=e.mover)return!0}function kn(e){return e.lineSpace.offsetTop}function Cn(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function Sn(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=T(e.measure,I("pre","x","CodeMirror-line-like")),n=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,i={left:parseInt(n.paddingLeft),right:parseInt(n.paddingRight)};return isNaN(i.left)||isNaN(i.right)||(e.cachedPaddingH=i),i}function Ln(e){return 50-e.display.nativeBarWidth}function Mn(e){return e.display.scroller.clientWidth-Ln(e)-e.display.barWidth}function Tn(e){return e.display.scroller.clientHeight-Ln(e)-e.display.barHeight}function In(e,t,n){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};if(e.rest){for(var i=0;i<e.rest.length;i++)if(e.rest[i]==t)return{map:e.measure.maps[i],cache:e.measure.caches[i]};for(var r=0;r<e.rest.length;r++)if(Ye(e.rest[r])>n)return{map:e.measure.maps[r],cache:e.measure.caches[r],before:!0}}}function An(e,t,n,i){return Nn(e,zn(e,t),n,i)}function En(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[di(e,t)];var n=e.display.externalMeasured;return n&&t>=n.lineN&&t<n.lineN+n.size?n:void 0}function zn(e,t){var n=Ye(t),i=En(e,n);i&&!i.text?i=null:i&&i.changes&&(dn(e,i,n,si(e)),e.curOp.forceUpdate=!0),i||(i=function(e,t){var n=Ye(t=Rt(t)),i=e.display.externalMeasured=new rn(e.doc,t,n);i.lineN=n;var r=i.built=Jt(e,i);return i.text=r.pre,T(e.display.lineMeasure,r.pre),i}(e,t));var r=In(i,t,n);return{line:t,view:i,rect:null,map:r.map,cache:r.cache,before:r.before,hasHeights:!1}}function Nn(e,t,n,i,r){t.before&&(n=-1);var s,l=n+(i||"");return t.cache.hasOwnProperty(l)?s=t.cache[l]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(!function(e,t,n){var i=e.options.lineWrapping,r=i&&Mn(e);if(!t.measure.heights||i&&t.measure.width!=r){var s=t.measure.heights=[];if(i){t.measure.width=r;for(var o=t.text.firstChild.getClientRects(),a=0;a<o.length-1;a++){var l=o[a],c=o[a+1];Math.abs(l.bottom-c.bottom)>2&&s.push((l.bottom+c.top)/2-n.top)}}s.push(n.bottom-n.top)}}(e,t.view,t.rect),t.hasHeights=!0),s=function(e,t,n,i){var r,s=$n(t.map,n,i),l=s.node,c=s.start,d=s.end,h=s.collapse;if(3==l.nodeType){for(var u=0;u<4;u++){for(;c&&ie(t.line.text.charAt(s.coverStart+c));)--c;for(;s.coverStart+d<s.coverEnd&&ie(t.line.text.charAt(s.coverStart+d));)++d;if((r=o&&a<9&&0==c&&d==s.coverEnd-s.coverStart?l.parentNode.getBoundingClientRect():On(S(l,c,d).getClientRects(),i)).left||r.right||0==c)break;d=c,c-=1,h="right"}o&&a<11&&(r=function(e,t){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!function(e){if(null!=Fe)return Fe;var t=T(e,I("span","x")),n=t.getBoundingClientRect(),i=S(t,0,1).getBoundingClientRect();return Fe=Math.abs(n.left-i.left)>1}(e))return t;var n=screen.logicalXDPI/screen.deviceXDPI,i=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*n,right:t.right*n,top:t.top*i,bottom:t.bottom*i}}(e.display.measure,r))}else{var f;c>0&&(h=i="right"),r=e.options.lineWrapping&&(f=l.getClientRects()).length>1?f["right"==i?f.length-1:0]:l.getBoundingClientRect()}if(o&&a<9&&!c&&(!r||!r.left&&!r.right)){var m=l.parentNode.getClientRects()[0];r=m?{left:m.left,right:m.left+ri(e.display),top:m.top,bottom:m.bottom}:Bn}for(var p=r.top-t.rect.top,g=r.bottom-t.rect.top,v=(p+g)/2,_=t.view.measure.heights,y=0;y<_.length-1&&!(v<_[y]);y++);var b=y?_[y-1]:0,x=_[y],w={left:("right"==h?r.right:r.left)-t.rect.left,right:("left"==h?r.left:r.right)-t.rect.left,top:b,bottom:x};r.left||r.right||(w.bogus=!0);e.options.singleCursorHeightPerLine||(w.rtop=p,w.rbottom=g);return w}(e,t,n,i),s.bogus||(t.cache[l]=s)),{left:s.left,right:s.right,top:r?s.rtop:s.top,bottom:r?s.rbottom:s.bottom}}var Fn,Bn={left:0,right:0,top:0,bottom:0};function $n(e,t,n){for(var i,r,s,o,a,l,c=0;c<e.length;c+=3)if(a=e[c],l=e[c+1],t<a?(r=0,s=1,o="left"):t<l?s=(r=t-a)+1:(c==e.length-3||t==l&&e[c+3]>t)&&(r=(s=l-a)-1,t>=l&&(o="right")),null!=r){if(i=e[c+2],a==l&&n==(i.insertLeft?"left":"right")&&(o=n),"left"==n&&0==r)for(;c&&e[c-2]==e[c-3]&&e[c-1].insertLeft;)i=e[2+(c-=3)],o="left";if("right"==n&&r==l-a)for(;c<e.length-3&&e[c+3]==e[c+4]&&!e[c+5].insertLeft;)i=e[(c+=3)+2],o="right";break}return{node:i,start:r,end:s,collapse:o,coverStart:a,coverEnd:l}}function On(e,t){var n=Bn;if("left"==t)for(var i=0;i<e.length&&(n=e[i]).left==n.right;i++);else for(var r=e.length-1;r>=0&&(n=e[r]).left==n.right;r--);return n}function Rn(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 Hn(e){e.display.externalMeasure=null,M(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++)Rn(e.display.view[t])}function Dn(e){Hn(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function Pn(){return d&&g?-(document.body.getBoundingClientRect().left-parseInt(getComputedStyle(document.body).marginLeft)):window.pageXOffset||(document.documentElement||document.body).scrollLeft}function Wn(){return d&&g?-(document.body.getBoundingClientRect().top-parseInt(getComputedStyle(document.body).marginTop)):window.pageYOffset||(document.documentElement||document.body).scrollTop}function Un(e){var t=Rt(e).widgets,n=0;if(t)for(var i=0;i<t.length;++i)t[i].above&&(n+=xn(t[i]));return n}function jn(e,t,n,i,r){if(!r){var s=Un(t);n.top+=s,n.bottom+=s}if("line"==i)return n;i||(i="local");var o=Ut(t);if("local"==i?o+=kn(e.display):o-=e.display.viewOffset,"page"==i||"window"==i){var a=e.display.lineSpace.getBoundingClientRect();o+=a.top+("window"==i?0:Wn());var l=a.left+("window"==i?0:Pn());n.left+=l,n.right+=l}return n.top+=o,n.bottom+=o,n}function Kn(e,t,n){if("div"==n)return t;var i=t.left,r=t.top;if("page"==n)i-=Pn(),r-=Wn();else if("local"==n||!n){var s=e.display.sizer.getBoundingClientRect();i+=s.left,r+=s.top}var o=e.display.lineSpace.getBoundingClientRect();return{left:i-o.left,top:r-o.top}}function Vn(e,t,n,i,r){return i||(i=Ve(e.doc,t.line)),jn(e,i,An(e,i,t.ch,r),n)}function qn(e,t,n,i,r,s){function o(t,o){var a=Nn(e,r,t,o?"right":"left",s);return o?a.left=a.right:a.right=a.left,jn(e,i,a,n)}i=i||Ve(e.doc,t.line),r||(r=zn(e,i));var a=ce(i,e.doc.direction),l=t.ch,c=t.sticky;if(l>=i.text.length?(l=i.text.length,c="before"):l<=0&&(l=0,c="after"),!a)return o("before"==c?l-1:l,"before"==c);function d(e,t,n){return o(n?e-1:e,1==a[t].level!=n)}var h=ae(a,l,c),u=oe,f=d(l,h,"before"==c);return null!=u&&(f.other=d(l,u,"before"!=c)),f}function Xn(e,t){var n=0;t=at(e.doc,t),e.options.lineWrapping||(n=ri(e.display)*t.ch);var i=Ve(e.doc,t.line),r=Ut(i)+kn(e.display);return{left:n,right:n,top:r,bottom:r+i.height}}function Gn(e,t,n,i,r){var s=et(e,t,n);return s.xRel=r,i&&(s.outside=i),s}function Yn(e,t,n){var i=e.doc;if((n+=e.display.viewOffset)<0)return Gn(i.first,0,null,-1,-1);var r=Je(i,n),s=i.first+i.size-1;if(r>s)return Gn(i.first+i.size-1,Ve(i,s).text.length,null,1,1);t<0&&(t=0);for(var o=Ve(i,r);;){var a=ei(e,o,r,t,n),l=$t(o,a.ch+(a.xRel>0||a.outside>0?1:0));if(!l)return a;var c=l.find(1);if(c.line==r)return c;o=Ve(i,r=c.line)}}function Jn(e,t,n,i){i-=Un(t);var r=t.text.length,s=se((function(t){return Nn(e,n,t-1).bottom<=i}),r,0);return{begin:s,end:r=se((function(t){return Nn(e,n,t).top>i}),s,r)}}function Qn(e,t,n,i){return n||(n=zn(e,t)),Jn(e,t,n,jn(e,t,Nn(e,n,i),"line").top)}function Zn(e,t,n,i){return!(e.bottom<=n)&&(e.top>n||(i?e.left:e.right)>t)}function ei(e,t,n,i,r){r-=Ut(t);var s=zn(e,t),o=Un(t),a=0,l=t.text.length,c=!0,d=ce(t,e.doc.direction);if(d){var h=(e.options.lineWrapping?ni:ti)(e,t,n,s,d,i,r);a=(c=1!=h.level)?h.from:h.to-1,l=c?h.to:h.from-1}var u,f,m=null,p=null,g=se((function(t){var n=Nn(e,s,t);return n.top+=o,n.bottom+=o,!!Zn(n,i,r,!1)&&(n.top<=r&&n.left<=i&&(m=t,p=n),!0)}),a,l),v=!1;if(p){var _=i-p.left<p.right-i,y=_==c;g=m+(y?0:1),f=y?"after":"before",u=_?p.left:p.right}else{c||g!=l&&g!=a||g++,f=0==g?"after":g==t.text.length?"before":Nn(e,s,g-(c?1:0)).bottom+o<=r==c?"after":"before";var b=qn(e,et(n,g,f),"line",t,s);u=b.left,v=r<b.top?-1:r>=b.bottom?1:0}return Gn(n,g=re(t.text,g,1),f,v,i-u)}function ti(e,t,n,i,r,s,o){var a=se((function(a){var l=r[a],c=1!=l.level;return Zn(qn(e,et(n,c?l.to:l.from,c?"before":"after"),"line",t,i),s,o,!0)}),0,r.length-1),l=r[a];if(a>0){var c=1!=l.level,d=qn(e,et(n,c?l.from:l.to,c?"after":"before"),"line",t,i);Zn(d,s,o,!0)&&d.top>o&&(l=r[a-1])}return l}function ni(e,t,n,i,r,s,o){var a=Jn(e,t,i,o),l=a.begin,c=a.end;/\s/.test(t.text.charAt(c-1))&&c--;for(var d=null,h=null,u=0;u<r.length;u++){var f=r[u];if(!(f.from>=c||f.to<=l)){var m=Nn(e,i,1!=f.level?Math.min(c,f.to)-1:Math.max(l,f.from)).right,p=m<s?s-m+1e9:m-s;(!d||h>p)&&(d=f,h=p)}}return d||(d=r[r.length-1]),d.from<l&&(d={from:l,to:d.to,level:d.level}),d.to>c&&(d={from:d.from,to:c,level:d.level}),d}function ii(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Fn){Fn=I("pre",null,"CodeMirror-line-like");for(var t=0;t<49;++t)Fn.appendChild(document.createTextNode("x")),Fn.appendChild(I("br"));Fn.appendChild(document.createTextNode("x"))}T(e.measure,Fn);var n=Fn.offsetHeight/50;return n>3&&(e.cachedTextHeight=n),M(e.measure),n||1}function ri(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=I("span","xxxxxxxxxx"),n=I("pre",[t],"CodeMirror-line-like");T(e.measure,n);var i=t.getBoundingClientRect(),r=(i.right-i.left)/10;return r>2&&(e.cachedCharWidth=r),r||10}function si(e){for(var t=e.display,n={},i={},r=t.gutters.clientLeft,s=t.gutters.firstChild,o=0;s;s=s.nextSibling,++o){var a=e.display.gutterSpecs[o].className;n[a]=s.offsetLeft+s.clientLeft+r,i[a]=s.clientWidth}return{fixedPos:oi(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:i,wrapperWidth:t.wrapper.clientWidth}}function oi(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function ai(e){var t=ii(e.display),n=e.options.lineWrapping,i=n&&Math.max(5,e.display.scroller.clientWidth/ri(e.display)-3);return function(r){if(Pt(e.doc,r))return 0;var s=0;if(r.widgets)for(var o=0;o<r.widgets.length;o++)r.widgets[o].height&&(s+=r.widgets[o].height);return n?s+(Math.ceil(r.text.length/i)||1)*t:s+t}}function li(e){var t=e.doc,n=ai(e);t.iter((function(e){var t=n(e);t!=e.height&&Ge(e,t)}))}function ci(e,t,n,i){var r=e.display;if(!n&&"true"==ke(t).getAttribute("cm-not-content"))return null;var s,o,a=r.lineSpace.getBoundingClientRect();try{s=t.clientX-a.left,o=t.clientY-a.top}catch(e){return null}var l,c=Yn(e,s,o);if(i&&c.xRel>0&&(l=Ve(e.doc,c.line).text).length==c.ch){var d=R(l,l.length,e.options.tabSize)-l.length;c=et(c.line,Math.max(0,Math.round((s-Sn(e.display).left)/ri(e.display))-d))}return c}function di(e,t){if(t>=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;for(var n=e.display.view,i=0;i<n.length;i++)if((t-=n[i].size)<0)return i}function hi(e,t,n,i){null==t&&(t=e.doc.first),null==n&&(n=e.doc.first+e.doc.size),i||(i=0);var r=e.display;if(i&&n<r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>t)&&(r.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=r.viewTo)wt&&Ht(e.doc,t)<r.viewTo&&fi(e);else if(n<=r.viewFrom)wt&&Dt(e.doc,n+i)>r.viewFrom?fi(e):(r.viewFrom+=i,r.viewTo+=i);else if(t<=r.viewFrom&&n>=r.viewTo)fi(e);else if(t<=r.viewFrom){var s=mi(e,n,n+i,1);s?(r.view=r.view.slice(s.index),r.viewFrom=s.lineN,r.viewTo+=i):fi(e)}else if(n>=r.viewTo){var o=mi(e,t,t,-1);o?(r.view=r.view.slice(0,o.index),r.viewTo=o.lineN):fi(e)}else{var a=mi(e,t,t,-1),l=mi(e,n,n+i,1);a&&l?(r.view=r.view.slice(0,a.index).concat(sn(e,a.lineN,l.lineN)).concat(r.view.slice(l.index)),r.viewTo+=i):fi(e)}var c=r.externalMeasured;c&&(n<c.lineN?c.lineN+=i:t<c.lineN+c.size&&(r.externalMeasured=null))}function ui(e,t,n){e.curOp.viewChanged=!0;var i=e.display,r=e.display.externalMeasured;if(r&&t>=r.lineN&&t<r.lineN+r.size&&(i.externalMeasured=null),!(t<i.viewFrom||t>=i.viewTo)){var s=i.view[di(e,t)];if(null!=s.node){var o=s.changes||(s.changes=[]);-1==D(o,n)&&o.push(n)}}}function fi(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function mi(e,t,n,i){var r,s=di(e,t),o=e.display.view;if(!wt||n==e.doc.first+e.doc.size)return{index:s,lineN:n};for(var a=e.display.viewFrom,l=0;l<s;l++)a+=o[l].size;if(a!=t){if(i>0){if(s==o.length-1)return null;r=a+o[s].size-t,s++}else r=a-t;t+=r,n+=r}for(;Ht(e.doc,n)!=n;){if(s==(i<0?0:o.length-1))return null;n+=i*o[s-(i<0?1:0)].size,s+=i}return{index:s,lineN:n}}function pi(e){for(var t=e.display.view,n=0,i=0;i<t.length;i++){var r=t[i];r.hidden||r.node&&!r.changes||++n}return n}function gi(e){e.display.input.showSelection(e.display.input.prepareSelection())}function vi(e,t){void 0===t&&(t=!0);var n=e.doc,i={},r=i.cursors=document.createDocumentFragment(),s=i.selection=document.createDocumentFragment(),o=e.options.$customCursor;o&&(t=!0);for(var a=0;a<n.sel.ranges.length;a++)if(t||a!=n.sel.primIndex){var l=n.sel.ranges[a];if(!(l.from().line>=e.display.viewTo||l.to().line<e.display.viewFrom)){var c=l.empty();if(o){var d=o(e,l);d&&_i(e,d,r)}else(c||e.options.showCursorWhenSelecting)&&_i(e,l.head,r);c||bi(e,l,s)}}return i}function _i(e,t,n){var i=qn(e,t,"div",null,null,!e.options.singleCursorHeightPerLine),r=n.appendChild(I("div"," ","CodeMirror-cursor"));if(r.style.left=i.left+"px",r.style.top=i.top+"px",r.style.height=Math.max(0,i.bottom-i.top)*e.options.cursorHeight+"px",/\bcm-fat-cursor\b/.test(e.getWrapperElement().className)){var s=Vn(e,t,"div",null,null),o=s.right-s.left;r.style.width=(o>0?o:e.defaultCharWidth())+"px"}if(i.other){var a=n.appendChild(I("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));a.style.display="",a.style.left=i.other.left+"px",a.style.top=i.other.top+"px",a.style.height=.85*(i.other.bottom-i.other.top)+"px"}}function yi(e,t){return e.top-t.top||e.left-t.left}function bi(e,t,n){var i=e.display,r=e.doc,s=document.createDocumentFragment(),o=Sn(e.display),a=o.left,l=Math.max(i.sizerWidth,Mn(e)-i.sizer.offsetLeft)-o.right,c="ltr"==r.direction;function d(e,t,n,i){t<0&&(t=0),t=Math.round(t),i=Math.round(i),s.appendChild(I("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px;\n top: "+t+"px; width: "+(null==n?l-e:n)+"px;\n height: "+(i-t)+"px"))}function h(t,n,i){var s,o,h=Ve(r,t),u=h.text.length;function f(n,i){return Vn(e,et(t,n),"div",h,i)}function m(t,n,i){var r=Qn(e,h,null,t),s="ltr"==n==("after"==i)?"left":"right";return f("after"==i?r.begin:r.end-(/\s/.test(h.text.charAt(r.end-1))?2:1),s)[s]}var p=ce(h,r.direction);return function(e,t,n,i){if(!e)return i(t,n,"ltr",0);for(var r=!1,s=0;s<e.length;++s){var o=e[s];(o.from<n&&o.to>t||t==n&&o.to==t)&&(i(Math.max(o.from,t),Math.min(o.to,n),1==o.level?"rtl":"ltr",s),r=!0)}r||i(t,n,"ltr")}(p,n||0,null==i?u:i,(function(e,t,r,h){var g="ltr"==r,v=f(e,g?"left":"right"),_=f(t-1,g?"right":"left"),y=null==n&&0==e,b=null==i&&t==u,x=0==h,w=!p||h==p.length-1;if(_.top-v.top<=3){var k=(c?b:y)&&w,C=(c?y:b)&&x?a:(g?v:_).left,S=k?l:(g?_:v).right;d(C,v.top,S-C,v.bottom)}else{var L,M,T,I;g?(L=c&&y&&x?a:v.left,M=c?l:m(e,r,"before"),T=c?a:m(t,r,"after"),I=c&&b&&w?l:_.right):(L=c?m(e,r,"before"):a,M=!c&&y&&x?l:v.right,T=!c&&b&&w?a:_.left,I=c?m(t,r,"after"):l),d(L,v.top,M-L,v.bottom),v.bottom<_.top&&d(a,v.bottom,null,_.top),d(T,_.top,I-T,_.bottom)}(!s||yi(v,s)<0)&&(s=v),yi(_,s)<0&&(s=_),(!o||yi(v,o)<0)&&(o=v),yi(_,o)<0&&(o=_)})),{start:s,end:o}}var u=t.from(),f=t.to();if(u.line==f.line)h(u.line,u.ch,f.ch);else{var m=Ve(r,u.line),p=Ve(r,f.line),g=Rt(m)==Rt(p),v=h(u.line,u.ch,g?m.text.length+1:null).end,_=h(f.line,g?0:null,f.ch).start;g&&(v.top<_.top-2?(d(v.right,v.top,null,v.bottom),d(a,_.top,_.left,_.bottom)):d(v.right,v.top,_.left-v.right,v.bottom)),v.bottom<_.top&&d(a,v.bottom,null,_.top)}n.appendChild(s)}function xi(e){if(e.state.focused){var t=e.display;clearInterval(t.blinker);var n=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0?t.blinker=setInterval((function(){e.hasFocus()||Si(e),t.cursorDiv.style.visibility=(n=!n)?"":"hidden"}),e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function wi(e){e.hasFocus()||(e.display.input.focus(),e.state.focused||Ci(e))}function ki(e){e.state.delayingBlurEvent=!0,setTimeout((function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,e.state.focused&&Si(e))}),100)}function Ci(e,t){e.state.delayingBlurEvent&&!e.state.draggingText&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(me(e,"focus",e,t),e.state.focused=!0,N(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),l&&setTimeout((function(){return e.display.input.reset(!0)}),20)),e.display.input.receivedFocus()),xi(e))}function Si(e,t){e.state.delayingBlurEvent||(e.state.focused&&(me(e,"blur",e,t),e.state.focused=!1,L(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout((function(){e.state.focused||(e.display.shift=!1)}),150))}function Li(e){for(var t=e.display,n=t.lineDiv.offsetTop,i=Math.max(0,t.scroller.getBoundingClientRect().top),r=t.lineDiv.getBoundingClientRect().top,s=0,l=0;l<t.view.length;l++){var c=t.view[l],d=e.options.lineWrapping,h=void 0,u=0;if(!c.hidden){if(r+=c.line.height,o&&a<8){var f=c.node.offsetTop+c.node.offsetHeight;h=f-n,n=f}else{var m=c.node.getBoundingClientRect();h=m.bottom-m.top,!d&&c.text.firstChild&&(u=c.text.firstChild.getBoundingClientRect().right-m.left-1)}var p=c.line.height-h;if((p>.005||p<-.005)&&(r<i&&(s-=p),Ge(c.line,h),Mi(c.line),c.rest))for(var g=0;g<c.rest.length;g++)Mi(c.rest[g]);if(u>e.display.sizerWidth){var v=Math.ceil(u/ri(e.display));v>e.display.maxLineLength&&(e.display.maxLineLength=v,e.display.maxLine=c.line,e.display.maxLineChanged=!0)}}}Math.abs(s)>2&&(t.scroller.scrollTop+=s)}function Mi(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t){var n=e.widgets[t],i=n.node.parentNode;i&&(n.height=i.offsetHeight)}}function Ti(e,t,n){var i=n&&null!=n.top?Math.max(0,n.top):e.scroller.scrollTop;i=Math.floor(i-kn(e));var r=n&&null!=n.bottom?n.bottom:i+e.wrapper.clientHeight,s=Je(t,i),o=Je(t,r);if(n&&n.ensure){var a=n.ensure.from.line,l=n.ensure.to.line;a<s?(s=a,o=Je(t,Ut(Ve(t,a))+e.wrapper.clientHeight)):Math.min(l,t.lastLine())>=o&&(s=Je(t,Ut(Ve(t,l))-e.wrapper.clientHeight),o=l)}return{from:s,to:Math.max(o,s+1)}}function Ii(e,t){var n=e.display,i=ii(e.display);t.top<0&&(t.top=0);var r=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:n.scroller.scrollTop,s=Tn(e),o={};t.bottom-t.top>s&&(t.bottom=t.top+s);var a=e.doc.height+Cn(n),l=t.top<i,c=t.bottom>a-i;if(t.top<r)o.scrollTop=l?0:t.top;else if(t.bottom>r+s){var d=Math.min(t.top,(c?a:t.bottom)-s);d!=r&&(o.scrollTop=d)}var h=e.options.fixedGutter?0:n.gutters.offsetWidth,u=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:n.scroller.scrollLeft-h,f=Mn(e)-n.gutters.offsetWidth,m=t.right-t.left>f;return m&&(t.right=t.left+f),t.left<10?o.scrollLeft=0:t.left<u?o.scrollLeft=Math.max(0,t.left+h-(m?0:10)):t.right>f+u-3&&(o.scrollLeft=t.right+(m?0:10)-f),o}function Ai(e,t){null!=t&&(Ni(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+t)}function Ei(e){Ni(e);var t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function zi(e,t,n){null==t&&null==n||Ni(e),null!=t&&(e.curOp.scrollLeft=t),null!=n&&(e.curOp.scrollTop=n)}function Ni(e){var t=e.curOp.scrollToPos;t&&(e.curOp.scrollToPos=null,Fi(e,Xn(e,t.from),Xn(e,t.to),t.margin))}function Fi(e,t,n,i){var r=Ii(e,{left:Math.min(t.left,n.left),top:Math.min(t.top,n.top)-i,right:Math.max(t.right,n.right),bottom:Math.max(t.bottom,n.bottom)+i});zi(e,r.scrollLeft,r.scrollTop)}function Bi(e,t){Math.abs(e.doc.scrollTop-t)<2||(n||lr(e,{top:t}),$i(e,t,!0),n&&lr(e),ir(e,100))}function $i(e,t,n){t=Math.max(0,Math.min(e.display.scroller.scrollHeight-e.display.scroller.clientHeight,t)),(e.display.scroller.scrollTop!=t||n)&&(e.doc.scrollTop=t,e.display.scrollbars.setScrollTop(t),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t))}function Oi(e,t,n,i){t=Math.max(0,Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth)),(n?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)&&!i||(e.doc.scrollLeft=t,hr(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function Ri(e){var t=e.display,n=t.gutters.offsetWidth,i=Math.round(e.doc.height+Cn(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?n:0,docHeight:i,scrollHeight:i+Ln(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}var Hi=function(e,t,n){this.cm=n;var i=this.vert=I("div",[I("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),r=this.horiz=I("div",[I("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");i.tabIndex=r.tabIndex=-1,e(i),e(r),he(i,"scroll",(function(){i.clientHeight&&t(i.scrollTop,"vertical")})),he(r,"scroll",(function(){r.clientWidth&&t(r.scrollLeft,"horizontal")})),this.checkedZeroWidth=!1,o&&a<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};Hi.prototype.update=function(e){var t=e.scrollWidth>e.clientWidth+1,n=e.scrollHeight>e.clientHeight+1,i=e.nativeBarWidth;if(n){this.vert.style.display="block",this.vert.style.bottom=t?i+"px":"0";var r=e.viewHeight-(t?i:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+r)+"px"}else this.vert.scrollTop=0,this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=n?i+"px":"0",this.horiz.style.left=e.barLeft+"px";var s=e.viewWidth-e.barLeft-(n?i:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+s)+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedZeroWidth&&e.clientHeight>0&&(0==i&&this.zeroWidthHack(),this.checkedZeroWidth=!0),{right:n?i:0,bottom:t?i:0}},Hi.prototype.setScrollLeft=function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")},Hi.prototype.setScrollTop=function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")},Hi.prototype.zeroWidthHack=function(){var e=_&&!f?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new H,this.disableVert=new H},Hi.prototype.enableZeroWidthBar=function(e,t,n){e.style.pointerEvents="auto",t.set(1e3,(function i(){var r=e.getBoundingClientRect();("vert"==n?document.elementFromPoint(r.right-1,(r.top+r.bottom)/2):document.elementFromPoint((r.right+r.left)/2,r.bottom-1))!=e?e.style.pointerEvents="none":t.set(1e3,i)}))},Hi.prototype.clear=function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)};var Di=function(){};function Pi(e,t){t||(t=Ri(e));var n=e.display.barWidth,i=e.display.barHeight;Wi(e,t);for(var r=0;r<4&&n!=e.display.barWidth||i!=e.display.barHeight;r++)n!=e.display.barWidth&&e.options.lineWrapping&&Li(e),Wi(e,Ri(e)),n=e.display.barWidth,i=e.display.barHeight}function Wi(e,t){var n=e.display,i=n.scrollbars.update(t);n.sizer.style.paddingRight=(n.barWidth=i.right)+"px",n.sizer.style.paddingBottom=(n.barHeight=i.bottom)+"px",n.heightForcer.style.borderBottom=i.bottom+"px solid transparent",i.right&&i.bottom?(n.scrollbarFiller.style.display="block",n.scrollbarFiller.style.height=i.bottom+"px",n.scrollbarFiller.style.width=i.right+"px"):n.scrollbarFiller.style.display="",i.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(n.gutterFiller.style.display="block",n.gutterFiller.style.height=i.bottom+"px",n.gutterFiller.style.width=t.gutterWidth+"px"):n.gutterFiller.style.display=""}Di.prototype.update=function(){return{bottom:0,right:0}},Di.prototype.setScrollLeft=function(){},Di.prototype.setScrollTop=function(){},Di.prototype.clear=function(){};var Ui={native:Hi,null:Di};function ji(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&L(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new Ui[e.options.scrollbarStyle]((function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),he(t,"mousedown",(function(){e.state.focused&&setTimeout((function(){return e.display.input.focus()}),0)})),t.setAttribute("cm-not-content","true")}),(function(t,n){"horizontal"==n?Oi(e,t):Bi(e,t)}),e),e.display.scrollbars.addClass&&N(e.display.wrapper,e.display.scrollbars.addClass)}var Ki=0;function Vi(e){var t;e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:0,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Ki,markArrays:null},t=e.curOp,on?on.ops.push(t):t.ownsGroup=on={ops:[t],delayedCallbacks:[]}}function qi(e){var t=e.curOp;t&&function(e,t){var n=e.ownsGroup;if(n)try{!function(e){var t=e.delayedCallbacks,n=0;do{for(;n<t.length;n++)t[n].call(null);for(var i=0;i<e.ops.length;i++){var r=e.ops[i];if(r.cursorActivityHandlers)for(;r.cursorActivityCalled<r.cursorActivityHandlers.length;)r.cursorActivityHandlers[r.cursorActivityCalled++].call(null,r.cm)}}while(n<t.length)}(n)}finally{on=null,t(n)}}(t,(function(e){for(var t=0;t<e.ops.length;t++)e.ops[t].cm.curOp=null;!function(e){for(var t=e.ops,n=0;n<t.length;n++)Xi(t[n]);for(var i=0;i<t.length;i++)Gi(t[i]);for(var r=0;r<t.length;r++)Yi(t[r]);for(var s=0;s<t.length;s++)Ji(t[s]);for(var o=0;o<t.length;o++)Qi(t[o])}(e)}))}function Xi(e){var t=e.cm,n=t.display;!function(e){var t=e.display;!t.scrollbarsClipped&&t.scroller.offsetWidth&&(t.nativeBarWidth=t.scroller.offsetWidth-t.scroller.clientWidth,t.heightForcer.style.height=Ln(e)+"px",t.sizer.style.marginBottom=-t.nativeBarWidth+"px",t.sizer.style.borderRightWidth=Ln(e)+"px",t.scrollbarsClipped=!0)}(t),e.updateMaxLine&&Kt(t),e.mustUpdate=e.viewChanged||e.forceUpdate||null!=e.scrollTop||e.scrollToPos&&(e.scrollToPos.from.line<n.viewFrom||e.scrollToPos.to.line>=n.viewTo)||n.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new sr(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function Gi(e){e.updatedDisplay=e.mustUpdate&&or(e.cm,e.update)}function Yi(e){var t=e.cm,n=t.display;e.updatedDisplay&&Li(t),e.barMeasure=Ri(t),n.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=An(t,n.maxLine,n.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(n.scroller.clientWidth,n.sizer.offsetLeft+e.adjustWidthTo+Ln(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-Mn(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function Ji(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft<t.doc.scrollLeft&&Oi(t,Math.min(t.display.scroller.scrollLeft,e.maxScrollLeft),!0),t.display.maxLineChanged=!1);var n=e.focus&&e.focus==z();e.preparedSelection&&t.display.input.showSelection(e.preparedSelection,n),(e.updatedDisplay||e.startHeight!=t.doc.height)&&Pi(t,e.barMeasure),e.updatedDisplay&&dr(t,e.barMeasure),e.selectionChanged&&xi(t),t.state.focused&&e.updateInput&&t.display.input.reset(e.typing),n&&wi(e.cm)}function Qi(e){var t=e.cm,n=t.display,i=t.doc;if(e.updatedDisplay&&ar(t,e.update),null==n.wheelStartX||null==e.scrollTop&&null==e.scrollLeft&&!e.scrollToPos||(n.wheelStartX=n.wheelStartY=null),null!=e.scrollTop&&$i(t,e.scrollTop,e.forceScroll),null!=e.scrollLeft&&Oi(t,e.scrollLeft,!0,!0),e.scrollToPos){var r=function(e,t,n,i){var r;null==i&&(i=0),e.options.lineWrapping||t!=n||(n="before"==t.sticky?et(t.line,t.ch+1,"before"):t,t=t.ch?et(t.line,"before"==t.sticky?t.ch-1:t.ch,"after"):t);for(var s=0;s<5;s++){var o=!1,a=qn(e,t),l=n&&n!=t?qn(e,n):a,c=Ii(e,r={left:Math.min(a.left,l.left),top:Math.min(a.top,l.top)-i,right:Math.max(a.left,l.left),bottom:Math.max(a.bottom,l.bottom)+i}),d=e.doc.scrollTop,h=e.doc.scrollLeft;if(null!=c.scrollTop&&(Bi(e,c.scrollTop),Math.abs(e.doc.scrollTop-d)>1&&(o=!0)),null!=c.scrollLeft&&(Oi(e,c.scrollLeft),Math.abs(e.doc.scrollLeft-h)>1&&(o=!0)),!o)break}return r}(t,at(i,e.scrollToPos.from),at(i,e.scrollToPos.to),e.scrollToPos.margin);!function(e,t){if(!pe(e,"scrollCursorIntoView")){var n=e.display,i=n.sizer.getBoundingClientRect(),r=null;if(t.top+i.top<0?r=!0:t.bottom+i.top>(window.innerHeight||document.documentElement.clientHeight)&&(r=!1),null!=r&&!m){var s=I("div","",null,"position: absolute;\n top: "+(t.top-n.viewOffset-kn(e.display))+"px;\n height: "+(t.bottom-t.top+Ln(e)+n.barHeight)+"px;\n left: "+t.left+"px; width: "+Math.max(2,t.right-t.left)+"px;");e.display.lineSpace.appendChild(s),s.scrollIntoView(r),e.display.lineSpace.removeChild(s)}}}(t,r)}var s=e.maybeHiddenMarkers,o=e.maybeUnhiddenMarkers;if(s)for(var a=0;a<s.length;++a)s[a].lines.length||me(s[a],"hide");if(o)for(var l=0;l<o.length;++l)o[l].lines.length&&me(o[l],"unhide");n.wrapper.offsetHeight&&(i.scrollTop=t.display.scroller.scrollTop),e.changeObjs&&me(t,"changes",t,e.changeObjs),e.update&&e.update.finish()}function Zi(e,t){if(e.curOp)return t();Vi(e);try{return t()}finally{qi(e)}}function er(e,t){return function(){if(e.curOp)return t.apply(e,arguments);Vi(e);try{return t.apply(e,arguments)}finally{qi(e)}}}function tr(e){return function(){if(this.curOp)return e.apply(this,arguments);Vi(this);try{return e.apply(this,arguments)}finally{qi(this)}}}function nr(e){return function(){var t=this.cm;if(!t||t.curOp)return e.apply(this,arguments);Vi(t);try{return e.apply(this,arguments)}finally{qi(t)}}}function ir(e,t){e.doc.highlightFrontier<e.display.viewTo&&e.state.highlight.set(t,$(rr,e))}function rr(e){var t=e.doc;if(!(t.highlightFrontier>=e.display.viewTo)){var n=+new Date+e.options.workTime,i=ft(e,t.highlightFrontier),r=[];t.iter(i.line,Math.min(t.first+t.size,e.display.viewTo+500),(function(s){if(i.line>=e.display.viewFrom){var o=s.styles,a=s.text.length>e.options.maxHighlightLength?We(t.mode,i.state):null,l=ht(e,s,i,!0);a&&(i.state=a),s.styles=l.styles;var c=s.styleClasses,d=l.classes;d?s.styleClasses=d:c&&(s.styleClasses=null);for(var h=!o||o.length!=s.styles.length||c!=d&&(!c||!d||c.bgClass!=d.bgClass||c.textClass!=d.textClass),u=0;!h&&u<o.length;++u)h=o[u]!=s.styles[u];h&&r.push(i.line),s.stateAfter=i.save(),i.nextLine()}else s.text.length<=e.options.maxHighlightLength&&mt(e,s.text,i),s.stateAfter=i.line%5==0?i.save():null,i.nextLine();if(+new Date>n)return ir(e,e.options.workDelay),!0})),t.highlightFrontier=i.line,t.modeFrontier=Math.max(t.modeFrontier,i.line),r.length&&Zi(e,(function(){for(var t=0;t<r.length;t++)ui(e,r[t],"text")}))}}var sr=function(e,t,n){var i=e.display;this.viewport=t,this.visible=Ti(i,e.doc,t),this.editorIsHidden=!i.wrapper.offsetWidth,this.wrapperHeight=i.wrapper.clientHeight,this.wrapperWidth=i.wrapper.clientWidth,this.oldDisplayWidth=Mn(e),this.force=n,this.dims=si(e),this.events=[]};function or(e,t){var n=e.display,i=e.doc;if(t.editorIsHidden)return fi(e),!1;if(!t.force&&t.visible.from>=n.viewFrom&&t.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==pi(e))return!1;ur(e)&&(fi(e),t.dims=si(e));var r=i.first+i.size,s=Math.max(t.visible.from-e.options.viewportMargin,i.first),o=Math.min(r,t.visible.to+e.options.viewportMargin);n.viewFrom<s&&s-n.viewFrom<20&&(s=Math.max(i.first,n.viewFrom)),n.viewTo>o&&n.viewTo-o<20&&(o=Math.min(r,n.viewTo)),wt&&(s=Ht(e.doc,s),o=Dt(e.doc,o));var a=s!=n.viewFrom||o!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth;!function(e,t,n){var i=e.display;0==i.view.length||t>=i.viewTo||n<=i.viewFrom?(i.view=sn(e,t,n),i.viewFrom=t):(i.viewFrom>t?i.view=sn(e,t,i.viewFrom).concat(i.view):i.viewFrom<t&&(i.view=i.view.slice(di(e,t))),i.viewFrom=t,i.viewTo<n?i.view=i.view.concat(sn(e,i.viewTo,n)):i.viewTo>n&&(i.view=i.view.slice(0,di(e,n)))),i.viewTo=n}(e,s,o),n.viewOffset=Ut(Ve(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";var c=pi(e);if(!a&&0==c&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;var d=function(e){if(e.hasFocus())return null;var t=z();if(!t||!E(e.display.lineDiv,t))return null;var n={activeElt:t};if(window.getSelection){var i=window.getSelection();i.anchorNode&&i.extend&&E(e.display.lineDiv,i.anchorNode)&&(n.anchorNode=i.anchorNode,n.anchorOffset=i.anchorOffset,n.focusNode=i.focusNode,n.focusOffset=i.focusOffset)}return n}(e);return c>4&&(n.lineDiv.style.display="none"),function(e,t,n){var i=e.display,r=e.options.lineNumbers,s=i.lineDiv,o=s.firstChild;function a(t){var n=t.nextSibling;return l&&_&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}for(var c=i.view,d=i.viewFrom,h=0;h<c.length;h++){var u=c[h];if(u.hidden);else if(u.node&&u.node.parentNode==s){for(;o!=u.node;)o=a(o);var f=r&&null!=t&&t<=d&&u.lineNumber;u.changes&&(D(u.changes,"gutter")>-1&&(f=!1),dn(e,u,d,n)),f&&(M(u.lineNumber),u.lineNumber.appendChild(document.createTextNode(Ze(e.options,d)))),o=u.node.nextSibling}else{var m=vn(e,u,d,n);s.insertBefore(m,o)}d+=u.size}for(;o;)o=a(o)}(e,n.updateLineNumbers,t.dims),c>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,function(e){if(e&&e.activeElt&&e.activeElt!=z()&&(e.activeElt.focus(),!/^(INPUT|TEXTAREA)$/.test(e.activeElt.nodeName)&&e.anchorNode&&E(document.body,e.anchorNode)&&E(document.body,e.focusNode))){var t=window.getSelection(),n=document.createRange();n.setEnd(e.anchorNode,e.anchorOffset),n.collapse(!1),t.removeAllRanges(),t.addRange(n),t.extend(e.focusNode,e.focusOffset)}}(d),M(n.cursorDiv),M(n.selectionDiv),n.gutters.style.height=n.sizer.style.minHeight=0,a&&(n.lastWrapHeight=t.wrapperHeight,n.lastWrapWidth=t.wrapperWidth,ir(e,400)),n.updateLineNumbers=null,!0}function ar(e,t){for(var n=t.viewport,i=!0;;i=!1){if(i&&e.options.lineWrapping&&t.oldDisplayWidth!=Mn(e))i&&(t.visible=Ti(e.display,e.doc,n));else if(n&&null!=n.top&&(n={top:Math.min(e.doc.height+Cn(e.display)-Tn(e),n.top)}),t.visible=Ti(e.display,e.doc,n),t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)break;if(!or(e,t))break;Li(e);var r=Ri(e);gi(e),Pi(e,r),dr(e,r),t.force=!1}t.signal(e,"update",e),e.display.viewFrom==e.display.reportedViewFrom&&e.display.viewTo==e.display.reportedViewTo||(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function lr(e,t){var n=new sr(e,t);if(or(e,n)){Li(e),ar(e,n);var i=Ri(e);gi(e),Pi(e,i),dr(e,i),n.finish()}}function cr(e){var t=e.gutters.offsetWidth;e.sizer.style.marginLeft=t+"px",ln(e,"gutterChanged",e)}function dr(e,t){e.display.sizer.style.minHeight=t.docHeight+"px",e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=t.docHeight+e.display.barHeight+Ln(e)+"px"}function hr(e){var t=e.display,n=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var i=oi(t)-t.scroller.scrollLeft+e.doc.scrollLeft,r=t.gutters.offsetWidth,s=i+"px",o=0;o<n.length;o++)if(!n[o].hidden){e.options.fixedGutter&&(n[o].gutter&&(n[o].gutter.style.left=s),n[o].gutterBackground&&(n[o].gutterBackground.style.left=s));var a=n[o].alignable;if(a)for(var l=0;l<a.length;l++)a[l].style.left=s}e.options.fixedGutter&&(t.gutters.style.left=i+r+"px")}}function ur(e){if(!e.options.lineNumbers)return!1;var t=e.doc,n=Ze(e.options,t.first+t.size-1),i=e.display;if(n.length!=i.lineNumChars){var r=i.measure.appendChild(I("div",[I("div",n)],"CodeMirror-linenumber CodeMirror-gutter-elt")),s=r.firstChild.offsetWidth,o=r.offsetWidth-s;return i.lineGutter.style.width="",i.lineNumInnerWidth=Math.max(s,i.lineGutter.offsetWidth-o)+1,i.lineNumWidth=i.lineNumInnerWidth+o,i.lineNumChars=i.lineNumInnerWidth?n.length:-1,i.lineGutter.style.width=i.lineNumWidth+"px",cr(e.display),!0}return!1}function fr(e,t){for(var n=[],i=!1,r=0;r<e.length;r++){var s=e[r],o=null;if("string"!=typeof s&&(o=s.style,s=s.className),"CodeMirror-linenumbers"==s){if(!t)continue;i=!0}n.push({className:s,style:o})}return t&&!i&&n.push({className:"CodeMirror-linenumbers",style:null}),n}function mr(e){var t=e.gutters,n=e.gutterSpecs;M(t),e.lineGutter=null;for(var i=0;i<n.length;++i){var r=n[i],s=r.className,o=r.style,a=t.appendChild(I("div",null,"CodeMirror-gutter "+s));o&&(a.style.cssText=o),"CodeMirror-linenumbers"==s&&(e.lineGutter=a,a.style.width=(e.lineNumWidth||1)+"px")}t.style.display=n.length?"":"none",cr(e)}function pr(e){mr(e.display),hi(e),hr(e)}function gr(e,t,i,r){var s=this;this.input=i,s.scrollbarFiller=I("div",null,"CodeMirror-scrollbar-filler"),s.scrollbarFiller.setAttribute("cm-not-content","true"),s.gutterFiller=I("div",null,"CodeMirror-gutter-filler"),s.gutterFiller.setAttribute("cm-not-content","true"),s.lineDiv=A("div",null,"CodeMirror-code"),s.selectionDiv=I("div",null,null,"position: relative; z-index: 1"),s.cursorDiv=I("div",null,"CodeMirror-cursors"),s.measure=I("div",null,"CodeMirror-measure"),s.lineMeasure=I("div",null,"CodeMirror-measure"),s.lineSpace=A("div",[s.measure,s.lineMeasure,s.selectionDiv,s.cursorDiv,s.lineDiv],null,"position: relative; outline: none");var c=A("div",[s.lineSpace],"CodeMirror-lines");s.mover=I("div",[c],null,"position: relative"),s.sizer=I("div",[s.mover],"CodeMirror-sizer"),s.sizerWidth=null,s.heightForcer=I("div",null,null,"position: absolute; height: 50px; width: 1px;"),s.gutters=I("div",null,"CodeMirror-gutters"),s.lineGutter=null,s.scroller=I("div",[s.sizer,s.heightForcer,s.gutters],"CodeMirror-scroll"),s.scroller.setAttribute("tabIndex","-1"),s.wrapper=I("div",[s.scrollbarFiller,s.gutterFiller,s.scroller],"CodeMirror"),s.wrapper.setAttribute("translate","no"),o&&a<8&&(s.gutters.style.zIndex=-1,s.scroller.style.paddingRight=0),l||n&&v||(s.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(s.wrapper):e(s.wrapper)),s.viewFrom=s.viewTo=t.first,s.reportedViewFrom=s.reportedViewTo=t.first,s.view=[],s.renderedView=null,s.externalMeasured=null,s.viewOffset=0,s.lastWrapHeight=s.lastWrapWidth=0,s.updateLineNumbers=null,s.nativeBarWidth=s.barHeight=s.barWidth=0,s.scrollbarsClipped=!1,s.lineNumWidth=s.lineNumInnerWidth=s.lineNumChars=null,s.alignWidgets=!1,s.cachedCharWidth=s.cachedTextHeight=s.cachedPaddingH=null,s.maxLine=null,s.maxLineLength=0,s.maxLineChanged=!1,s.wheelDX=s.wheelDY=s.wheelStartX=s.wheelStartY=null,s.shift=!1,s.selForContextMenu=null,s.activeTouch=null,s.gutterSpecs=fr(r.gutters,r.lineNumbers),mr(s),i.init(s)}sr.prototype.signal=function(e,t){ve(e,t)&&this.events.push(arguments)},sr.prototype.finish=function(){for(var e=0;e<this.events.length;e++)me.apply(null,this.events[e])};var vr=0,_r=null;function yr(e){var t=e.wheelDeltaX,n=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==n&&e.detail&&e.axis==e.VERTICAL_AXIS?n=e.detail:null==n&&(n=e.wheelDelta),{x:t,y:n}}function br(e){var t=yr(e);return t.x*=_r,t.y*=_r,t}function xr(e,t){var i=yr(t),r=i.x,s=i.y,o=_r;0===t.deltaMode&&(r=t.deltaX,s=t.deltaY,o=1);var a=e.display,c=a.scroller,d=c.scrollWidth>c.clientWidth,u=c.scrollHeight>c.clientHeight;if(r&&d||s&&u){if(s&&_&&l)e:for(var f=t.target,m=a.view;f!=c;f=f.parentNode)for(var p=0;p<m.length;p++)if(m[p].node==f){e.display.currentWheelTarget=f;break e}if(r&&!n&&!h&&null!=o)return s&&u&&Bi(e,Math.max(0,c.scrollTop+s*o)),Oi(e,Math.max(0,c.scrollLeft+r*o)),(!s||s&&u)&&ye(t),void(a.wheelStartX=null);if(s&&null!=o){var g=s*o,v=e.doc.scrollTop,y=v+a.wrapper.clientHeight;g<0?v=Math.max(0,v+g-50):y=Math.min(e.doc.height,y+g+50),lr(e,{top:v,bottom:y})}vr<20&&0!==t.deltaMode&&(null==a.wheelStartX?(a.wheelStartX=c.scrollLeft,a.wheelStartY=c.scrollTop,a.wheelDX=r,a.wheelDY=s,setTimeout((function(){if(null!=a.wheelStartX){var e=c.scrollLeft-a.wheelStartX,t=c.scrollTop-a.wheelStartY,n=t&&a.wheelDY&&t/a.wheelDY||e&&a.wheelDX&&e/a.wheelDX;a.wheelStartX=a.wheelStartY=null,n&&(_r=(_r*vr+n)/(vr+1),++vr)}}),200)):(a.wheelDX+=r,a.wheelDY+=s))}}o?_r=-.53:n?_r=15:d?_r=-.7:u&&(_r=-1/3);var wr=function(e,t){this.ranges=e,this.primIndex=t};wr.prototype.primary=function(){return this.ranges[this.primIndex]},wr.prototype.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 n=this.ranges[t],i=e.ranges[t];if(!nt(n.anchor,i.anchor)||!nt(n.head,i.head))return!1}return!0},wr.prototype.deepCopy=function(){for(var e=[],t=0;t<this.ranges.length;t++)e[t]=new kr(it(this.ranges[t].anchor),it(this.ranges[t].head));return new wr(e,this.primIndex)},wr.prototype.somethingSelected=function(){for(var e=0;e<this.ranges.length;e++)if(!this.ranges[e].empty())return!0;return!1},wr.prototype.contains=function(e,t){t||(t=e);for(var n=0;n<this.ranges.length;n++){var i=this.ranges[n];if(tt(t,i.from())>=0&&tt(e,i.to())<=0)return n}return-1};var kr=function(e,t){this.anchor=e,this.head=t};function Cr(e,t,n){var i=e&&e.options.selectionsMayTouch,r=t[n];t.sort((function(e,t){return tt(e.from(),t.from())})),n=D(t,r);for(var s=1;s<t.length;s++){var o=t[s],a=t[s-1],l=tt(a.to(),o.from());if(i&&!o.empty()?l>0:l>=0){var c=st(a.from(),o.from()),d=rt(a.to(),o.to()),h=a.empty()?o.from()==o.head:a.from()==a.head;s<=n&&--n,t.splice(--s,2,new kr(h?d:c,h?c:d))}}return new wr(t,n)}function Sr(e,t){return new wr([new kr(e,t||e)],0)}function Lr(e){return e.text?et(e.from.line+e.text.length-1,X(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function Mr(e,t){if(tt(e,t.from)<0)return e;if(tt(e,t.to)<=0)return Lr(t);var n=e.line+t.text.length-(t.to.line-t.from.line)-1,i=e.ch;return e.line==t.to.line&&(i+=Lr(t).ch-t.to.ch),et(n,i)}function Tr(e,t){for(var n=[],i=0;i<e.sel.ranges.length;i++){var r=e.sel.ranges[i];n.push(new kr(Mr(r.anchor,t),Mr(r.head,t)))}return Cr(e.cm,n,e.sel.primIndex)}function Ir(e,t,n){return e.line==t.line?et(n.line,e.ch-t.ch+n.ch):et(n.line+(e.line-t.line),e.ch)}function Ar(e){e.doc.mode=He(e.options,e.doc.modeOption),Er(e)}function Er(e){e.doc.iter((function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)})),e.doc.modeFrontier=e.doc.highlightFrontier=e.doc.first,ir(e,100),e.state.modeGen++,e.curOp&&hi(e)}function zr(e,t){return 0==t.from.ch&&0==t.to.ch&&""==X(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function Nr(e,t,n,i){function r(e){return n?n[e]:null}function s(e,n,r){!function(e,t,n,i){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),null!=e.order&&(e.order=null),Tt(e),It(e,n);var r=i?i(e):1;r!=e.height&&Ge(e,r)}(e,n,r,i),ln(e,"change",e,t)}function o(e,t){for(var n=[],s=e;s<t;++s)n.push(new Vt(c[s],r(s),i));return n}var a=t.from,l=t.to,c=t.text,d=Ve(e,a.line),h=Ve(e,l.line),u=X(c),f=r(c.length-1),m=l.line-a.line;if(t.full)e.insert(0,o(0,c.length)),e.remove(c.length,e.size-c.length);else if(zr(e,t)){var p=o(0,c.length-1);s(h,h.text,f),m&&e.remove(a.line,m),p.length&&e.insert(a.line,p)}else if(d==h)if(1==c.length)s(d,d.text.slice(0,a.ch)+u+d.text.slice(l.ch),f);else{var g=o(1,c.length-1);g.push(new Vt(u+d.text.slice(l.ch),f,i)),s(d,d.text.slice(0,a.ch)+c[0],r(0)),e.insert(a.line+1,g)}else if(1==c.length)s(d,d.text.slice(0,a.ch)+c[0]+h.text.slice(l.ch),r(0)),e.remove(a.line+1,m);else{s(d,d.text.slice(0,a.ch)+c[0],r(0)),s(h,u+h.text.slice(l.ch),f);var v=o(1,c.length-1);m>1&&e.remove(a.line+1,m-1),e.insert(a.line+1,v)}ln(e,"change",e,t)}function Fr(e,t,n){!function e(i,r,s){if(i.linked)for(var o=0;o<i.linked.length;++o){var a=i.linked[o];if(a.doc!=r){var l=s&&a.sharedHist;n&&!l||(t(a.doc,l),e(a.doc,i,l))}}}(e,null,!0)}function Br(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,li(e),Ar(e),$r(e),e.options.direction=t.direction,e.options.lineWrapping||Kt(e),e.options.mode=t.modeOption,hi(e)}function $r(e){("rtl"==e.doc.direction?N:L)(e.display.lineDiv,"CodeMirror-rtl")}function Or(e){this.done=[],this.undone=[],this.undoDepth=e?e.undoDepth:1/0,this.lastModTime=this.lastSelTime=0,this.lastOp=this.lastSelOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=e?e.maxGeneration:1}function Rr(e,t){var n={from:it(t.from),to:Lr(t),text:qe(e,t.from,t.to)};return Ur(e,n,t.from.line,t.to.line+1),Fr(e,(function(e){return Ur(e,n,t.from.line,t.to.line+1)}),!0),n}function Hr(e){for(;e.length;){if(!X(e).ranges)break;e.pop()}}function Dr(e,t,n,i){var r=e.history;r.undone.length=0;var s,o,a=+new Date;if((r.lastOp==i||r.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&r.lastModTime>a-(e.cm?e.cm.options.historyEventDelay:500)||"*"==t.origin.charAt(0)))&&(s=function(e,t){return t?(Hr(e.done),X(e.done)):e.done.length&&!X(e.done).ranges?X(e.done):e.done.length>1&&!e.done[e.done.length-2].ranges?(e.done.pop(),X(e.done)):void 0}(r,r.lastOp==i)))o=X(s.changes),0==tt(t.from,t.to)&&0==tt(t.from,o.to)?o.to=Lr(t):s.changes.push(Rr(e,t));else{var l=X(r.done);for(l&&l.ranges||Wr(e.sel,r.done),s={changes:[Rr(e,t)],generation:r.generation},r.done.push(s);r.done.length>r.undoDepth;)r.done.shift(),r.done[0].ranges||r.done.shift()}r.done.push(n),r.generation=++r.maxGeneration,r.lastModTime=r.lastSelTime=a,r.lastOp=r.lastSelOp=i,r.lastOrigin=r.lastSelOrigin=t.origin,o||me(e,"historyAdded")}function Pr(e,t,n,i){var r=e.history,s=i&&i.origin;n==r.lastSelOp||s&&r.lastSelOrigin==s&&(r.lastModTime==r.lastSelTime&&r.lastOrigin==s||function(e,t,n,i){var r=t.charAt(0);return"*"==r||"+"==r&&n.ranges.length==i.ranges.length&&n.somethingSelected()==i.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}(e,s,X(r.done),t))?r.done[r.done.length-1]=t:Wr(t,r.done),r.lastSelTime=+new Date,r.lastSelOrigin=s,r.lastSelOp=n,i&&!1!==i.clearRedo&&Hr(r.undone)}function Wr(e,t){var n=X(t);n&&n.ranges&&n.equals(e)||t.push(e)}function Ur(e,t,n,i){var r=t["spans_"+e.id],s=0;e.iter(Math.max(e.first,n),Math.min(e.first+e.size,i),(function(n){n.markedSpans&&((r||(r=t["spans_"+e.id]={}))[s]=n.markedSpans),++s}))}function jr(e){if(!e)return null;for(var t,n=0;n<e.length;++n)e[n].marker.explicitlyCleared?t||(t=e.slice(0,n)):t&&t.push(e[n]);return t?t.length?t:null:e}function Kr(e,t){var n=function(e,t){var n=t["spans_"+e.id];if(!n)return null;for(var i=[],r=0;r<t.text.length;++r)i.push(jr(n[r]));return i}(e,t),i=Lt(e,t);if(!n)return i;if(!i)return n;for(var r=0;r<n.length;++r){var s=n[r],o=i[r];if(s&&o)e:for(var a=0;a<o.length;++a){for(var l=o[a],c=0;c<s.length;++c)if(s[c].marker==l.marker)continue e;s.push(l)}else o&&(n[r]=o)}return n}function Vr(e,t,n){for(var i=[],r=0;r<e.length;++r){var s=e[r];if(s.ranges)i.push(n?wr.prototype.deepCopy.call(s):s);else{var o=s.changes,a=[];i.push({changes:a});for(var l=0;l<o.length;++l){var c=o[l],d=void 0;if(a.push({from:c.from,to:c.to,text:c.text}),t)for(var h in c)(d=h.match(/^spans_(\d+)$/))&&D(t,Number(d[1]))>-1&&(X(a)[h]=c[h],delete c[h])}}}return i}function qr(e,t,n,i){if(i){var r=e.anchor;if(n){var s=tt(t,r)<0;s!=tt(n,r)<0?(r=t,t=n):s!=tt(t,n)<0&&(t=n)}return new kr(r,t)}return new kr(n||t,t)}function Xr(e,t,n,i,r){null==r&&(r=e.cm&&(e.cm.display.shift||e.extend)),Zr(e,new wr([qr(e.sel.primary(),t,n,r)],0),i)}function Gr(e,t,n){for(var i=[],r=e.cm&&(e.cm.display.shift||e.extend),s=0;s<e.sel.ranges.length;s++)i[s]=qr(e.sel.ranges[s],t[s],null,r);Zr(e,Cr(e.cm,i,e.sel.primIndex),n)}function Yr(e,t,n,i){var r=e.sel.ranges.slice(0);r[t]=n,Zr(e,Cr(e.cm,r,e.sel.primIndex),i)}function Jr(e,t,n,i){Zr(e,Sr(t,n),i)}function Qr(e,t,n){var i=e.history.done,r=X(i);r&&r.ranges?(i[i.length-1]=t,es(e,t,n)):Zr(e,t,n)}function Zr(e,t,n){es(e,t,n),Pr(e,e.sel,e.cm?e.cm.curOp.id:NaN,n)}function es(e,t,n){(ve(e,"beforeSelectionChange")||e.cm&&ve(e.cm,"beforeSelectionChange"))&&(t=function(e,t,n){var i={ranges:t.ranges,update:function(t){this.ranges=[];for(var n=0;n<t.length;n++)this.ranges[n]=new kr(at(e,t[n].anchor),at(e,t[n].head))},origin:n&&n.origin};return me(e,"beforeSelectionChange",e,i),e.cm&&me(e.cm,"beforeSelectionChange",e.cm,i),i.ranges!=t.ranges?Cr(e.cm,i.ranges,i.ranges.length-1):t}(e,t,n));var i=n&&n.bias||(tt(t.primary().head,e.sel.primary().head)<0?-1:1);ts(e,is(e,t,i,!0)),n&&!1===n.scroll||!e.cm||"nocursor"==e.cm.getOption("readOnly")||Ei(e.cm)}function ts(e,t){t.equals(e.sel)||(e.sel=t,e.cm&&(e.cm.curOp.updateInput=1,e.cm.curOp.selectionChanged=!0,ge(e.cm)),ln(e,"cursorActivity",e))}function ns(e){ts(e,is(e,e.sel,null,!1))}function is(e,t,n,i){for(var r,s=0;s<t.ranges.length;s++){var o=t.ranges[s],a=t.ranges.length==e.sel.ranges.length&&e.sel.ranges[s],l=ss(e,o.anchor,a&&a.anchor,n,i),c=ss(e,o.head,a&&a.head,n,i);(r||l!=o.anchor||c!=o.head)&&(r||(r=t.ranges.slice(0,s)),r[s]=new kr(l,c))}return r?Cr(e.cm,r,t.primIndex):t}function rs(e,t,n,i,r){var s=Ve(e,t.line);if(s.markedSpans)for(var o=0;o<s.markedSpans.length;++o){var a=s.markedSpans[o],l=a.marker,c="selectLeft"in l?!l.selectLeft:l.inclusiveLeft,d="selectRight"in l?!l.selectRight:l.inclusiveRight;if((null==a.from||(c?a.from<=t.ch:a.from<t.ch))&&(null==a.to||(d?a.to>=t.ch:a.to>t.ch))){if(r&&(me(l,"beforeCursorEnter"),l.explicitlyCleared)){if(s.markedSpans){--o;continue}break}if(!l.atomic)continue;if(n){var h=l.find(i<0?1:-1),u=void 0;if((i<0?d:c)&&(h=os(e,h,-i,h&&h.line==t.line?s:null)),h&&h.line==t.line&&(u=tt(h,n))&&(i<0?u<0:u>0))return rs(e,h,t,i,r)}var f=l.find(i<0?-1:1);return(i<0?c:d)&&(f=os(e,f,i,f.line==t.line?s:null)),f?rs(e,f,t,i,r):null}}return t}function ss(e,t,n,i,r){var s=i||1,o=rs(e,t,n,s,r)||!r&&rs(e,t,n,s,!0)||rs(e,t,n,-s,r)||!r&&rs(e,t,n,-s,!0);return o||(e.cantEdit=!0,et(e.first,0))}function os(e,t,n,i){return n<0&&0==t.ch?t.line>e.first?at(e,et(t.line-1)):null:n>0&&t.ch==(i||Ve(e,t.line)).text.length?t.line<e.first+e.size-1?et(t.line+1,0):null:new et(t.line,t.ch+n)}function as(e){e.setSelection(et(e.firstLine(),0),et(e.lastLine()),W)}function ls(e,t,n){var i={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){return i.canceled=!0}};return n&&(i.update=function(t,n,r,s){t&&(i.from=at(e,t)),n&&(i.to=at(e,n)),r&&(i.text=r),void 0!==s&&(i.origin=s)}),me(e,"beforeChange",e,i),e.cm&&me(e.cm,"beforeChange",e.cm,i),i.canceled?(e.cm&&(e.cm.curOp.updateInput=2),null):{from:i.from,to:i.to,text:i.text,origin:i.origin}}function cs(e,t,n){if(e.cm){if(!e.cm.curOp)return er(e.cm,cs)(e,t,n);if(e.cm.state.suppressEdits)return}if(!(ve(e,"beforeChange")||e.cm&&ve(e.cm,"beforeChange"))||(t=ls(e,t,!0))){var i=xt&&!n&&function(e,t,n){var i=null;if(e.iter(t.line,n.line+1,(function(e){if(e.markedSpans)for(var t=0;t<e.markedSpans.length;++t){var n=e.markedSpans[t].marker;!n.readOnly||i&&-1!=D(i,n)||(i||(i=[])).push(n)}})),!i)return null;for(var r=[{from:t,to:n}],s=0;s<i.length;++s)for(var o=i[s],a=o.find(0),l=0;l<r.length;++l){var c=r[l];if(!(tt(c.to,a.from)<0||tt(c.from,a.to)>0)){var d=[l,1],h=tt(c.from,a.from),u=tt(c.to,a.to);(h<0||!o.inclusiveLeft&&!h)&&d.push({from:c.from,to:a.from}),(u>0||!o.inclusiveRight&&!u)&&d.push({from:a.to,to:c.to}),r.splice.apply(r,d),l+=d.length-3}}return r}(e,t.from,t.to);if(i)for(var r=i.length-1;r>=0;--r)ds(e,{from:i[r].from,to:i[r].to,text:r?[""]:t.text,origin:t.origin});else ds(e,t)}}function ds(e,t){if(1!=t.text.length||""!=t.text[0]||0!=tt(t.from,t.to)){var n=Tr(e,t);Dr(e,t,n,e.cm?e.cm.curOp.id:NaN),fs(e,t,n,Lt(e,t));var i=[];Fr(e,(function(e,n){n||-1!=D(i,e.history)||(vs(e.history,t),i.push(e.history)),fs(e,t,null,Lt(e,t))}))}}function hs(e,t,n){var i=e.cm&&e.cm.state.suppressEdits;if(!i||n){for(var r,s=e.history,o=e.sel,a="undo"==t?s.done:s.undone,l="undo"==t?s.undone:s.done,c=0;c<a.length&&(r=a[c],n?!r.ranges||r.equals(e.sel):r.ranges);c++);if(c!=a.length){for(s.lastOrigin=s.lastSelOrigin=null;;){if(!(r=a.pop()).ranges){if(i)return void a.push(r);break}if(Wr(r,l),n&&!r.equals(e.sel))return void Zr(e,r,{clearRedo:!1});o=r}var d=[];Wr(o,l),l.push({changes:d,generation:s.generation}),s.generation=r.generation||++s.maxGeneration;for(var h=ve(e,"beforeChange")||e.cm&&ve(e.cm,"beforeChange"),u=function(n){var i=r.changes[n];if(i.origin=t,h&&!ls(e,i,!1))return a.length=0,{};d.push(Rr(e,i));var s=n?Tr(e,i):X(a);fs(e,i,s,Kr(e,i)),!n&&e.cm&&e.cm.scrollIntoView({from:i.from,to:Lr(i)});var o=[];Fr(e,(function(e,t){t||-1!=D(o,e.history)||(vs(e.history,i),o.push(e.history)),fs(e,i,null,Kr(e,i))}))},f=r.changes.length-1;f>=0;--f){var m=u(f);if(m)return m.v}}}}function us(e,t){if(0!=t&&(e.first+=t,e.sel=new wr(G(e.sel.ranges,(function(e){return new kr(et(e.anchor.line+t,e.anchor.ch),et(e.head.line+t,e.head.ch))})),e.sel.primIndex),e.cm)){hi(e.cm,e.first,e.first-t,t);for(var n=e.cm.display,i=n.viewFrom;i<n.viewTo;i++)ui(e.cm,i,"gutter")}}function fs(e,t,n,i){if(e.cm&&!e.cm.curOp)return er(e.cm,fs)(e,t,n,i);if(t.to.line<e.first)us(e,t.text.length-1-(t.to.line-t.from.line));else if(!(t.from.line>e.lastLine())){if(t.from.line<e.first){var r=t.text.length-1-(e.first-t.from.line);us(e,r),t={from:et(e.first,0),to:et(t.to.line+r,t.to.ch),text:[X(t.text)],origin:t.origin}}var s=e.lastLine();t.to.line>s&&(t={from:t.from,to:et(s,Ve(e,s).text.length),text:[t.text[0]],origin:t.origin}),t.removed=qe(e,t.from,t.to),n||(n=Tr(e,t)),e.cm?function(e,t,n){var i=e.doc,r=e.display,s=t.from,o=t.to,a=!1,l=s.line;e.options.lineWrapping||(l=Ye(Rt(Ve(i,s.line))),i.iter(l,o.line+1,(function(e){if(e==r.maxLine)return a=!0,!0})));i.sel.contains(t.from,t.to)>-1&&ge(e);Nr(i,t,n,ai(e)),e.options.lineWrapping||(i.iter(l,s.line+t.text.length,(function(e){var t=jt(e);t>r.maxLineLength&&(r.maxLine=e,r.maxLineLength=t,r.maxLineChanged=!0,a=!1)})),a&&(e.curOp.updateMaxLine=!0));(function(e,t){if(e.modeFrontier=Math.min(e.modeFrontier,t),!(e.highlightFrontier<t-10)){for(var n=e.first,i=t-1;i>n;i--){var r=Ve(e,i).stateAfter;if(r&&(!(r instanceof ct)||i+r.lookAhead<t)){n=i+1;break}}e.highlightFrontier=Math.min(e.highlightFrontier,n)}})(i,s.line),ir(e,400);var c=t.text.length-(o.line-s.line)-1;t.full?hi(e):s.line!=o.line||1!=t.text.length||zr(e.doc,t)?hi(e,s.line,o.line+1,c):ui(e,s.line,"text");var d=ve(e,"changes"),h=ve(e,"change");if(h||d){var u={from:s,to:o,text:t.text,removed:t.removed,origin:t.origin};h&&ln(e,"change",e,u),d&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(u)}e.display.selForContextMenu=null}(e.cm,t,i):Nr(e,t,i),es(e,n,W),e.cantEdit&&ss(e,et(e.firstLine(),0))&&(e.cantEdit=!1)}}function ms(e,t,n,i,r){var s;i||(i=n),tt(i,n)<0&&(n=(s=[i,n])[0],i=s[1]),"string"==typeof t&&(t=e.splitLines(t)),cs(e,{from:n,to:i,text:t,origin:r})}function ps(e,t,n,i){n<e.line?e.line+=i:t<e.line&&(e.line=t,e.ch=0)}function gs(e,t,n,i){for(var r=0;r<e.length;++r){var s=e[r],o=!0;if(s.ranges){s.copied||((s=e[r]=s.deepCopy()).copied=!0);for(var a=0;a<s.ranges.length;a++)ps(s.ranges[a].anchor,t,n,i),ps(s.ranges[a].head,t,n,i)}else{for(var l=0;l<s.changes.length;++l){var c=s.changes[l];if(n<c.from.line)c.from=et(c.from.line+i,c.from.ch),c.to=et(c.to.line+i,c.to.ch);else if(t<=c.to.line){o=!1;break}}o||(e.splice(0,r+1),r=0)}}}function vs(e,t){var n=t.from.line,i=t.to.line,r=t.text.length-(i-n)-1;gs(e.done,n,i,r),gs(e.undone,n,i,r)}function _s(e,t,n,i){var r=t,s=t;return"number"==typeof t?s=Ve(e,ot(e,t)):r=Ye(t),null==r?null:(i(s,r)&&e.cm&&ui(e.cm,r,n),s)}function ys(e){this.lines=e,this.parent=null;for(var t=0,n=0;n<e.length;++n)e[n].parent=this,t+=e[n].height;this.height=t}function bs(e){this.children=e;for(var t=0,n=0,i=0;i<e.length;++i){var r=e[i];t+=r.chunkSize(),n+=r.height,r.parent=this}this.size=t,this.height=n,this.parent=null}kr.prototype.from=function(){return st(this.anchor,this.head)},kr.prototype.to=function(){return rt(this.anchor,this.head)},kr.prototype.empty=function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch},ys.prototype={chunkSize:function(){return this.lines.length},removeInner:function(e,t){for(var n=e,i=e+t;n<i;++n){var r=this.lines[n];this.height-=r.height,qt(r),ln(r,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,n){this.height+=n,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var i=0;i<t.length;++i)t[i].parent=this},iterN:function(e,t,n){for(var i=e+t;e<i;++e)if(n(this.lines[e]))return!0}},bs.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var n=0;n<this.children.length;++n){var i=this.children[n],r=i.chunkSize();if(e<r){var s=Math.min(t,r-e),o=i.height;if(i.removeInner(e,s),this.height-=o-i.height,r==s&&(this.children.splice(n--,1),i.parent=null),0==(t-=s))break;e=0}else e-=r}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof ys))){var a=[];this.collapse(a),this.children=[new ys(a)],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,n){this.size+=t.length,this.height+=n;for(var i=0;i<this.children.length;++i){var r=this.children[i],s=r.chunkSize();if(e<=s){if(r.insertInner(e,t,n),r.lines&&r.lines.length>50){for(var o=r.lines.length%25+25,a=o;a<r.lines.length;){var l=new ys(r.lines.slice(a,a+=25));r.height-=l.height,this.children.splice(++i,0,l),l.parent=this}r.lines=r.lines.slice(0,o),this.maybeSpill()}break}e-=s}},maybeSpill:function(){if(!(this.children.length<=10)){var e=this;do{var t=new bs(e.children.splice(e.children.length-5,5));if(e.parent){e.size-=t.size,e.height-=t.height;var n=D(e.parent.children,e);e.parent.children.splice(n+1,0,t)}else{var i=new bs(e.children);i.parent=e,e.children=[i,t],e=i}t.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},iterN:function(e,t,n){for(var i=0;i<this.children.length;++i){var r=this.children[i],s=r.chunkSize();if(e<s){var o=Math.min(t,s-e);if(r.iterN(e,o,n))return!0;if(0==(t-=o))break;e=0}else e-=s}}};var xs=function(e,t,n){if(n)for(var i in n)n.hasOwnProperty(i)&&(this[i]=n[i]);this.doc=e,this.node=t};function ws(e,t,n){Ut(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Ai(e,n)}xs.prototype.clear=function(){var e=this.doc.cm,t=this.line.widgets,n=this.line,i=Ye(n);if(null!=i&&t){for(var r=0;r<t.length;++r)t[r]==this&&t.splice(r--,1);t.length||(n.widgets=null);var s=xn(this);Ge(n,Math.max(0,n.height-s)),e&&(Zi(e,(function(){ws(e,n,-s),ui(e,i,"widget")})),ln(e,"lineWidgetCleared",e,this,i))}},xs.prototype.changed=function(){var e=this,t=this.height,n=this.doc.cm,i=this.line;this.height=null;var r=xn(this)-t;r&&(Pt(this.doc,i)||Ge(i,i.height+r),n&&Zi(n,(function(){n.curOp.forceUpdate=!0,ws(n,i,r),ln(n,"lineWidgetChanged",n,e,Ye(i))})))},_e(xs);var ks=0,Cs=function(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++ks};function Ss(e,t,n,i,r){if(i&&i.shared)return function(e,t,n,i,r){(i=O(i)).shared=!1;var s=[Ss(e,t,n,i,r)],o=s[0],a=i.widgetNode;return Fr(e,(function(e){a&&(i.widgetNode=a.cloneNode(!0)),s.push(Ss(e,at(e,t),at(e,n),i,r));for(var l=0;l<e.linked.length;++l)if(e.linked[l].isParent)return;o=X(s)})),new Ls(s,o)}(e,t,n,i,r);if(e.cm&&!e.cm.curOp)return er(e.cm,Ss)(e,t,n,i,r);var s=new Cs(e,r),o=tt(t,n);if(i&&O(i,s,!1),o>0||0==o&&!1!==s.clearWhenEmpty)return s;if(s.replacedWith&&(s.collapsed=!0,s.widgetNode=A("span",[s.replacedWith],"CodeMirror-widget"),i.handleMouseEvents||s.widgetNode.setAttribute("cm-ignore-events","true"),i.insertLeft&&(s.widgetNode.insertLeft=!0)),s.collapsed){if(Ot(e,t.line,t,n,s)||t.line!=n.line&&Ot(e,n.line,t,n,s))throw new Error("Inserting collapsed marker partially overlapping an existing one");wt=!0}s.addToHistory&&Dr(e,{from:t,to:n,origin:"markText"},e.sel,NaN);var a,l=t.line,c=e.cm;if(e.iter(l,n.line+1,(function(i){c&&s.collapsed&&!c.options.lineWrapping&&Rt(i)==c.display.maxLine&&(a=!0),s.collapsed&&l!=t.line&&Ge(i,0),function(e,t,n){var i=n&&window.WeakSet&&(n.markedSpans||(n.markedSpans=new WeakSet));i&&e.markedSpans&&i.has(e.markedSpans)?e.markedSpans.push(t):(e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],i&&i.add(e.markedSpans)),t.marker.attachLine(e)}(i,new kt(s,l==t.line?t.ch:null,l==n.line?n.ch:null),e.cm&&e.cm.curOp),++l})),s.collapsed&&e.iter(t.line,n.line+1,(function(t){Pt(e,t)&&Ge(t,0)})),s.clearOnEnter&&he(s,"beforeCursorEnter",(function(){return s.clear()})),s.readOnly&&(xt=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),s.collapsed&&(s.id=++ks,s.atomic=!0),c){if(a&&(c.curOp.updateMaxLine=!0),s.collapsed)hi(c,t.line,n.line+1);else if(s.className||s.startStyle||s.endStyle||s.css||s.attributes||s.title)for(var d=t.line;d<=n.line;d++)ui(c,d,"text");s.atomic&&ns(c.doc),ln(c,"markerAdded",c,s)}return s}Cs.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&Vi(e),ve(this,"clear")){var n=this.find();n&&ln(this,"clear",n.from,n.to)}for(var i=null,r=null,s=0;s<this.lines.length;++s){var o=this.lines[s],a=Ct(o.markedSpans,this);e&&!this.collapsed?ui(e,Ye(o),"text"):e&&(null!=a.to&&(r=Ye(o)),null!=a.from&&(i=Ye(o))),o.markedSpans=St(o.markedSpans,a),null==a.from&&this.collapsed&&!Pt(this.doc,o)&&e&&Ge(o,ii(e.display))}if(e&&this.collapsed&&!e.options.lineWrapping)for(var l=0;l<this.lines.length;++l){var c=Rt(this.lines[l]),d=jt(c);d>e.display.maxLineLength&&(e.display.maxLine=c,e.display.maxLineLength=d,e.display.maxLineChanged=!0)}null!=i&&e&&this.collapsed&&hi(e,i,r+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&ns(e.doc)),e&&ln(e,"markerCleared",e,this,i,r),t&&qi(e),this.parent&&this.parent.clear()}},Cs.prototype.find=function(e,t){var n,i;null==e&&"bookmark"==this.type&&(e=1);for(var r=0;r<this.lines.length;++r){var s=this.lines[r],o=Ct(s.markedSpans,this);if(null!=o.from&&(n=et(t?s:Ye(s),o.from),-1==e))return n;if(null!=o.to&&(i=et(t?s:Ye(s),o.to),1==e))return i}return n&&{from:n,to:i}},Cs.prototype.changed=function(){var e=this,t=this.find(-1,!0),n=this,i=this.doc.cm;t&&i&&Zi(i,(function(){var r=t.line,s=Ye(t.line),o=En(i,s);if(o&&(Rn(o),i.curOp.selectionChanged=i.curOp.forceUpdate=!0),i.curOp.updateMaxLine=!0,!Pt(n.doc,r)&&null!=n.height){var a=n.height;n.height=null;var l=xn(n)-a;l&&Ge(r,r.height+l)}ln(i,"markerChanged",i,e)}))},Cs.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;t.maybeHiddenMarkers&&-1!=D(t.maybeHiddenMarkers,this)||(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)},Cs.prototype.detachLine=function(e){if(this.lines.splice(D(this.lines,e),1),!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}},_e(Cs);var Ls=function(e,t){this.markers=e,this.primary=t;for(var n=0;n<e.length;++n)e[n].parent=this};function Ms(e){return e.findMarks(et(e.first,0),e.clipPos(et(e.lastLine())),(function(e){return e.parent}))}function Ts(e){for(var t=function(t){var n=e[t],i=[n.primary.doc];Fr(n.primary.doc,(function(e){return i.push(e)}));for(var r=0;r<n.markers.length;r++){var s=n.markers[r];-1==D(i,s.doc)&&(s.parent=null,n.markers.splice(r--,1))}},n=0;n<e.length;n++)t(n)}Ls.prototype.clear=function(){if(!this.explicitlyCleared){this.explicitlyCleared=!0;for(var e=0;e<this.markers.length;++e)this.markers[e].clear();ln(this,"clear")}},Ls.prototype.find=function(e,t){return this.primary.find(e,t)},_e(Ls);var Is=0,As=function(e,t,n,i,r){if(!(this instanceof As))return new As(e,t,n,i,r);null==n&&(n=0),bs.call(this,[new ys([new Vt("",null)])]),this.first=n,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.modeFrontier=this.highlightFrontier=n;var s=et(n,0);this.sel=Sr(s),this.history=new Or(null),this.id=++Is,this.modeOption=t,this.lineSep=i,this.direction="rtl"==r?"rtl":"ltr",this.extend=!1,"string"==typeof e&&(e=this.splitLines(e)),Nr(this,{from:s,to:s,text:e}),Zr(this,Sr(s),W)};As.prototype=J(bs.prototype,{constructor:As,iter:function(e,t,n){n?this.iterN(e-this.first,t-e,n):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var n=0,i=0;i<t.length;++i)n+=t[i].height;this.insertInner(e-this.first,t,n)},remove:function(e,t){this.removeInner(e-this.first,t)},getValue:function(e){var t=Xe(this,this.first,this.first+this.size);return!1===e?t:t.join(e||this.lineSeparator())},setValue:nr((function(e){var t=et(this.first,0),n=this.first+this.size-1;cs(this,{from:t,to:et(n,Ve(this,n).text.length),text:this.splitLines(e),origin:"setValue",full:!0},!0),this.cm&&zi(this.cm,0,0),Zr(this,Sr(t),W)})),replaceRange:function(e,t,n,i){ms(this,e,t=at(this,t),n=n?at(this,n):t,i)},getRange:function(e,t,n){var i=qe(this,at(this,e),at(this,t));return!1===n?i:""===n?i.join(""):i.join(n||this.lineSeparator())},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},getLineHandle:function(e){if(Qe(this,e))return Ve(this,e)},getLineNumber:function(e){return Ye(e)},getLineHandleVisualStart:function(e){return"number"==typeof e&&(e=Ve(this,e)),Rt(e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return at(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:nr((function(e,t,n){Jr(this,at(this,"number"==typeof e?et(e,t||0):e),null,n)})),setSelection:nr((function(e,t,n){Jr(this,at(this,e),at(this,t||e),n)})),extendSelection:nr((function(e,t,n){Xr(this,at(this,e),t&&at(this,t),n)})),extendSelections:nr((function(e,t){Gr(this,lt(this,e),t)})),extendSelectionsBy:nr((function(e,t){Gr(this,lt(this,G(this.sel.ranges,e)),t)})),setSelections:nr((function(e,t,n){if(e.length){for(var i=[],r=0;r<e.length;r++)i[r]=new kr(at(this,e[r].anchor),at(this,e[r].head||e[r].anchor));null==t&&(t=Math.min(e.length-1,this.sel.primIndex)),Zr(this,Cr(this.cm,i,t),n)}})),addSelection:nr((function(e,t,n){var i=this.sel.ranges.slice(0);i.push(new kr(at(this,e),at(this,t||e))),Zr(this,Cr(this.cm,i,i.length-1),n)})),getSelection:function(e){for(var t,n=this.sel.ranges,i=0;i<n.length;i++){var r=qe(this,n[i].from(),n[i].to());t=t?t.concat(r):r}return!1===e?t:t.join(e||this.lineSeparator())},getSelections:function(e){for(var t=[],n=this.sel.ranges,i=0;i<n.length;i++){var r=qe(this,n[i].from(),n[i].to());!1!==e&&(r=r.join(e||this.lineSeparator())),t[i]=r}return t},replaceSelection:function(e,t,n){for(var i=[],r=0;r<this.sel.ranges.length;r++)i[r]=e;this.replaceSelections(i,t,n||"+input")},replaceSelections:nr((function(e,t,n){for(var i=[],r=this.sel,s=0;s<r.ranges.length;s++){var o=r.ranges[s];i[s]={from:o.from(),to:o.to(),text:this.splitLines(e[s]),origin:n}}for(var a=t&&"end"!=t&&function(e,t,n){for(var i=[],r=et(e.first,0),s=r,o=0;o<t.length;o++){var a=t[o],l=Ir(a.from,r,s),c=Ir(Lr(a),r,s);if(r=a.to,s=c,"around"==n){var d=e.sel.ranges[o],h=tt(d.head,d.anchor)<0;i[o]=new kr(h?c:l,h?l:c)}else i[o]=new kr(l,l)}return new wr(i,e.sel.primIndex)}(this,i,t),l=i.length-1;l>=0;l--)cs(this,i[l]);a?Qr(this,a):this.cm&&Ei(this.cm)})),undo:nr((function(){hs(this,"undo")})),redo:nr((function(){hs(this,"redo")})),undoSelection:nr((function(){hs(this,"undo",!0)})),redoSelection:nr((function(){hs(this,"redo",!0)})),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,n=0,i=0;i<e.done.length;i++)e.done[i].ranges||++t;for(var r=0;r<e.undone.length;r++)e.undone[r].ranges||++n;return{undo:t,redo:n}},clearHistory:function(){var e=this;this.history=new Or(this.history),Fr(this,(function(t){return t.history=e.history}),!0)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(e){return e&&(this.history.lastOp=this.history.lastSelOp=this.history.lastOrigin=null),this.history.generation},isClean:function(e){return this.history.generation==(e||this.cleanGeneration)},getHistory:function(){return{done:Vr(this.history.done),undone:Vr(this.history.undone)}},setHistory:function(e){var t=this.history=new Or(this.history);t.done=Vr(e.done.slice(0),null,!0),t.undone=Vr(e.undone.slice(0),null,!0)},setGutterMarker:nr((function(e,t,n){return _s(this,e,"gutter",(function(e){var i=e.gutterMarkers||(e.gutterMarkers={});return i[t]=n,!n&&te(i)&&(e.gutterMarkers=null),!0}))})),clearGutter:nr((function(e){var t=this;this.iter((function(n){n.gutterMarkers&&n.gutterMarkers[e]&&_s(t,n,"gutter",(function(){return n.gutterMarkers[e]=null,te(n.gutterMarkers)&&(n.gutterMarkers=null),!0}))}))})),lineInfo:function(e){var t;if("number"==typeof e){if(!Qe(this,e))return null;if(t=e,!(e=Ve(this,e)))return null}else if(null==(t=Ye(e)))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}},addLineClass:nr((function(e,t,n){return _s(this,e,"gutter"==t?"gutter":"class",(function(e){var i="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass";if(e[i]){if(C(n).test(e[i]))return!1;e[i]+=" "+n}else e[i]=n;return!0}))})),removeLineClass:nr((function(e,t,n){return _s(this,e,"gutter"==t?"gutter":"class",(function(e){var i="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass",r=e[i];if(!r)return!1;if(null==n)e[i]=null;else{var s=r.match(C(n));if(!s)return!1;var o=s.index+s[0].length;e[i]=r.slice(0,s.index)+(s.index&&o!=r.length?" ":"")+r.slice(o)||null}return!0}))})),addLineWidget:nr((function(e,t,n){return function(e,t,n,i){var r=new xs(e,n,i),s=e.cm;return s&&r.noHScroll&&(s.display.alignWidgets=!0),_s(e,t,"widget",(function(t){var n=t.widgets||(t.widgets=[]);if(null==r.insertAt?n.push(r):n.splice(Math.min(n.length,Math.max(0,r.insertAt)),0,r),r.line=t,s&&!Pt(e,t)){var i=Ut(t)<e.scrollTop;Ge(t,t.height+xn(r)),i&&Ai(s,r.height),s.curOp.forceUpdate=!0}return!0})),s&&ln(s,"lineWidgetAdded",s,r,"number"==typeof t?t:Ye(t)),r}(this,e,t,n)})),removeLineWidget:function(e){e.clear()},markText:function(e,t,n){return Ss(this,at(this,e),at(this,t),n,n&&n.type||"range")},setBookmark:function(e,t){var n={replacedWith:t&&(null==t.nodeType?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1,shared:t&&t.shared,handleMouseEvents:t&&t.handleMouseEvents};return Ss(this,e=at(this,e),e,n,"bookmark")},findMarksAt:function(e){var t=[],n=Ve(this,(e=at(this,e)).line).markedSpans;if(n)for(var i=0;i<n.length;++i){var r=n[i];(null==r.from||r.from<=e.ch)&&(null==r.to||r.to>=e.ch)&&t.push(r.marker.parent||r.marker)}return t},findMarks:function(e,t,n){e=at(this,e),t=at(this,t);var i=[],r=e.line;return this.iter(e.line,t.line+1,(function(s){var o=s.markedSpans;if(o)for(var a=0;a<o.length;a++){var l=o[a];null!=l.to&&r==e.line&&e.ch>=l.to||null==l.from&&r!=e.line||null!=l.from&&r==t.line&&l.from>=t.ch||n&&!n(l.marker)||i.push(l.marker.parent||l.marker)}++r})),i},getAllMarks:function(){var e=[];return this.iter((function(t){var n=t.markedSpans;if(n)for(var i=0;i<n.length;++i)null!=n[i].from&&e.push(n[i].marker)})),e},posFromIndex:function(e){var t,n=this.first,i=this.lineSeparator().length;return this.iter((function(r){var s=r.text.length+i;if(s>e)return t=e,!0;e-=s,++n})),at(this,et(n,t))},indexFromPos:function(e){var t=(e=at(this,e)).ch;if(e.line<this.first||e.ch<0)return 0;var n=this.lineSeparator().length;return this.iter(this.first,e.line,(function(e){t+=e.text.length+n})),t},copy:function(e){var t=new As(Xe(this,this.first,this.first+this.size),this.modeOption,this.first,this.lineSep,this.direction);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,n=this.first+this.size;null!=e.from&&e.from>t&&(t=e.from),null!=e.to&&e.to<n&&(n=e.to);var i=new As(Xe(this,t,n),e.mode||this.modeOption,t,this.lineSep,this.direction);return e.sharedHist&&(i.history=this.history),(this.linked||(this.linked=[])).push({doc:i,sharedHist:e.sharedHist}),i.linked=[{doc:this,isParent:!0,sharedHist:e.sharedHist}],function(e,t){for(var n=0;n<t.length;n++){var i=t[n],r=i.find(),s=e.clipPos(r.from),o=e.clipPos(r.to);if(tt(s,o)){var a=Ss(e,s,o,i.primary,i.primary.type);i.markers.push(a),a.parent=i}}}(i,Ms(this)),i},unlinkDoc:function(e){if(e instanceof Mo&&(e=e.doc),this.linked)for(var t=0;t<this.linked.length;++t){if(this.linked[t].doc==e){this.linked.splice(t,1),e.unlinkDoc(this),Ts(Ms(this));break}}if(e.history==this.history){var n=[e.id];Fr(e,(function(e){return n.push(e.id)}),!0),e.history=new Or(null),e.history.done=Vr(this.history.done,n),e.history.undone=Vr(this.history.undone,n)}},iterLinkedDocs:function(e){Fr(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm},splitLines:function(e){return this.lineSep?e.split(this.lineSep):Ee(e)},lineSeparator:function(){return this.lineSep||"\n"},setDirection:nr((function(e){var t;("rtl"!=e&&(e="ltr"),e!=this.direction)&&(this.direction=e,this.iter((function(e){return e.order=null})),this.cm&&Zi(t=this.cm,(function(){$r(t),hi(t)})))}))}),As.prototype.eachLine=As.prototype.iter;var Es=0;function zs(e){var t=this;if(Ns(t),!pe(t,e)&&!wn(t.display,e)){ye(e),o&&(Es=+new Date);var n=ci(t,e,!0),i=e.dataTransfer.files;if(n&&!t.isReadOnly())if(i&&i.length&&window.FileReader&&window.File)for(var r=i.length,s=Array(r),a=0,l=function(){++a==r&&er(t,(function(){var e={from:n=at(t.doc,n),to:n,text:t.doc.splitLines(s.filter((function(e){return null!=e})).join(t.doc.lineSeparator())),origin:"paste"};cs(t.doc,e),Qr(t.doc,Sr(at(t.doc,n),at(t.doc,Lr(e))))}))()},c=function(e,n){if(t.options.allowDropFileTypes&&-1==D(t.options.allowDropFileTypes,e.type))l();else{var i=new FileReader;i.onerror=function(){return l()},i.onload=function(){var e=i.result;/[\x00-\x08\x0e-\x1f]{2}/.test(e)||(s[n]=e),l()},i.readAsText(e)}},d=0;d<i.length;d++)c(i[d],d);else{if(t.state.draggingText&&t.doc.sel.contains(n)>-1)return t.state.draggingText(e),void setTimeout((function(){return t.display.input.focus()}),20);try{var h=e.dataTransfer.getData("Text");if(h){var u;if(t.state.draggingText&&!t.state.draggingText.copy&&(u=t.listSelections()),es(t.doc,Sr(n,n)),u)for(var f=0;f<u.length;++f)ms(t.doc,"",u[f].anchor,u[f].head,"drag");t.replaceSelection(h,"around","paste"),t.display.input.focus()}}catch(e){}}}}function Ns(e){e.display.dragCursor&&(e.display.lineSpace.removeChild(e.display.dragCursor),e.display.dragCursor=null)}function Fs(e){if(document.getElementsByClassName){for(var t=document.getElementsByClassName("CodeMirror"),n=[],i=0;i<t.length;i++){var r=t[i].CodeMirror;r&&n.push(r)}n.length&&n[0].operation((function(){for(var t=0;t<n.length;t++)e(n[t])}))}}var Bs=!1;function $s(){var e;Bs||(he(window,"resize",(function(){null==e&&(e=setTimeout((function(){e=null,Fs(Os)}),100))})),he(window,"blur",(function(){return Fs(Si)})),Bs=!0)}function Os(e){var t=e.display;t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize()}for(var Rs={3:"Pause",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",106:"*",107:"=",109:"-",110:".",111:"/",145:"ScrollLock",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",224:"Mod",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"},Hs=0;Hs<10;Hs++)Rs[Hs+48]=Rs[Hs+96]=String(Hs);for(var Ds=65;Ds<=90;Ds++)Rs[Ds]=String.fromCharCode(Ds);for(var Ps=1;Ps<=12;Ps++)Rs[Ps+111]=Rs[Ps+63235]="F"+Ps;var Ws={};function Us(e){var t,n,i,r,s=e.split(/-(?!$)/);e=s[s.length-1];for(var o=0;o<s.length-1;o++){var a=s[o];if(/^(cmd|meta|m)$/i.test(a))r=!0;else if(/^a(lt)?$/i.test(a))t=!0;else if(/^(c|ctrl|control)$/i.test(a))n=!0;else{if(!/^s(hift)?$/i.test(a))throw new Error("Unrecognized modifier name: "+a);i=!0}}return t&&(e="Alt-"+e),n&&(e="Ctrl-"+e),r&&(e="Cmd-"+e),i&&(e="Shift-"+e),e}function js(e){var t={};for(var n in e)if(e.hasOwnProperty(n)){var i=e[n];if(/^(name|fallthrough|(de|at)tach)$/.test(n))continue;if("..."==i){delete e[n];continue}for(var r=G(n.split(" "),Us),s=0;s<r.length;s++){var o=void 0,a=void 0;s==r.length-1?(a=r.join(" "),o=i):(a=r.slice(0,s+1).join(" "),o="...");var l=t[a];if(l){if(l!=o)throw new Error("Inconsistent bindings for "+a)}else t[a]=o}delete e[n]}for(var c in t)e[c]=t[c];return e}function Ks(e,t,n,i){var r=(t=Gs(t)).call?t.call(e,i):t[e];if(!1===r)return"nothing";if("..."===r)return"multi";if(null!=r&&n(r))return"handled";if(t.fallthrough){if("[object Array]"!=Object.prototype.toString.call(t.fallthrough))return Ks(e,t.fallthrough,n,i);for(var s=0;s<t.fallthrough.length;s++){var o=Ks(e,t.fallthrough[s],n,i);if(o)return o}}}function Vs(e){var t="string"==typeof e?e:Rs[e.keyCode];return"Ctrl"==t||"Alt"==t||"Shift"==t||"Mod"==t}function qs(e,t,n){var i=e;return t.altKey&&"Alt"!=i&&(e="Alt-"+e),(w?t.metaKey:t.ctrlKey)&&"Ctrl"!=i&&(e="Ctrl-"+e),(w?t.ctrlKey:t.metaKey)&&"Mod"!=i&&(e="Cmd-"+e),!n&&t.shiftKey&&"Shift"!=i&&(e="Shift-"+e),e}function Xs(e,t){if(h&&34==e.keyCode&&e.char)return!1;var n=Rs[e.keyCode];return null!=n&&!e.altGraphKey&&(3==e.keyCode&&e.code&&(n=e.code),qs(n,e,t))}function Gs(e){return"string"==typeof e?Ws[e]:e}function Ys(e,t){for(var n=e.doc.sel.ranges,i=[],r=0;r<n.length;r++){for(var s=t(n[r]);i.length&&tt(s.from,X(i).to)<=0;){var o=i.pop();if(tt(o.from,s.from)<0){s.from=o.from;break}}i.push(s)}Zi(e,(function(){for(var t=i.length-1;t>=0;t--)ms(e.doc,"",i[t].from,i[t].to,"+delete");Ei(e)}))}function Js(e,t,n){var i=re(e.text,t+n,n);return i<0||i>e.text.length?null:i}function Qs(e,t,n){var i=Js(e,t.ch,n);return null==i?null:new et(t.line,i,n<0?"after":"before")}function Zs(e,t,n,i,r){if(e){"rtl"==t.doc.direction&&(r=-r);var s=ce(n,t.doc.direction);if(s){var o,a=r<0?X(s):s[0],l=r<0==(1==a.level)?"after":"before";if(a.level>0||"rtl"==t.doc.direction){var c=zn(t,n);o=r<0?n.text.length-1:0;var d=Nn(t,c,o).top;o=se((function(e){return Nn(t,c,e).top==d}),r<0==(1==a.level)?a.from:a.to-1,o),"before"==l&&(o=Js(n,o,1))}else o=r<0?a.to:a.from;return new et(i,o,l)}}return new et(i,r<0?n.text.length:0,r<0?"before":"after")}Ws.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"},Ws.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","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"},Ws.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Ws.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","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":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},Ws.default=_?Ws.macDefault:Ws.pcDefault;var eo={selectAll:as,singleSelection:function(e){return e.setSelection(e.getCursor("anchor"),e.getCursor("head"),W)},killLine:function(e){return Ys(e,(function(t){if(t.empty()){var n=Ve(e.doc,t.head.line).text.length;return t.head.ch==n&&t.head.line<e.lastLine()?{from:t.head,to:et(t.head.line+1,0)}:{from:t.head,to:et(t.head.line,n)}}return{from:t.from(),to:t.to()}}))},deleteLine:function(e){return Ys(e,(function(t){return{from:et(t.from().line,0),to:at(e.doc,et(t.to().line+1,0))}}))},delLineLeft:function(e){return Ys(e,(function(e){return{from:et(e.from().line,0),to:e.from()}}))},delWrappedLineLeft:function(e){return Ys(e,(function(t){var n=e.charCoords(t.head,"div").top+5;return{from:e.coordsChar({left:0,top:n},"div"),to:t.from()}}))},delWrappedLineRight:function(e){return Ys(e,(function(t){var n=e.charCoords(t.head,"div").top+5,i=e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div");return{from:t.from(),to:i}}))},undo:function(e){return e.undo()},redo:function(e){return e.redo()},undoSelection:function(e){return e.undoSelection()},redoSelection:function(e){return e.redoSelection()},goDocStart:function(e){return e.extendSelection(et(e.firstLine(),0))},goDocEnd:function(e){return e.extendSelection(et(e.lastLine()))},goLineStart:function(e){return e.extendSelectionsBy((function(t){return to(e,t.head.line)}),{origin:"+move",bias:1})},goLineStartSmart:function(e){return e.extendSelectionsBy((function(t){return no(e,t.head)}),{origin:"+move",bias:1})},goLineEnd:function(e){return e.extendSelectionsBy((function(t){return function(e,t){var n=Ve(e.doc,t),i=function(e){for(var t;t=Bt(e);)e=t.find(1,!0).line;return e}(n);i!=n&&(t=Ye(i));return Zs(!0,e,n,t,-1)}(e,t.head.line)}),{origin:"+move",bias:-1})},goLineRight:function(e){return e.extendSelectionsBy((function(t){var n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div")}),j)},goLineLeft:function(e){return e.extendSelectionsBy((function(t){var n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:n},"div")}),j)},goLineLeftSmart:function(e){return e.extendSelectionsBy((function(t){var n=e.cursorCoords(t.head,"div").top+5,i=e.coordsChar({left:0,top:n},"div");return i.ch<e.getLine(i.line).search(/\S/)?no(e,t.head):i}),j)},goLineUp:function(e){return e.moveV(-1,"line")},goLineDown:function(e){return e.moveV(1,"line")},goPageUp:function(e){return e.moveV(-1,"page")},goPageDown:function(e){return e.moveV(1,"page")},goCharLeft:function(e){return e.moveH(-1,"char")},goCharRight:function(e){return e.moveH(1,"char")},goColumnLeft:function(e){return e.moveH(-1,"column")},goColumnRight:function(e){return e.moveH(1,"column")},goWordLeft:function(e){return e.moveH(-1,"word")},goGroupRight:function(e){return e.moveH(1,"group")},goGroupLeft:function(e){return e.moveH(-1,"group")},goWordRight:function(e){return e.moveH(1,"word")},delCharBefore:function(e){return e.deleteH(-1,"codepoint")},delCharAfter:function(e){return e.deleteH(1,"char")},delWordBefore:function(e){return e.deleteH(-1,"word")},delWordAfter:function(e){return e.deleteH(1,"word")},delGroupBefore:function(e){return e.deleteH(-1,"group")},delGroupAfter:function(e){return e.deleteH(1,"group")},indentAuto:function(e){return e.indentSelection("smart")},indentMore:function(e){return e.indentSelection("add")},indentLess:function(e){return e.indentSelection("subtract")},insertTab:function(e){return e.replaceSelection("\t")},insertSoftTab:function(e){for(var t=[],n=e.listSelections(),i=e.options.tabSize,r=0;r<n.length;r++){var s=n[r].from(),o=R(e.getLine(s.line),s.ch,i);t.push(q(i-o%i))}e.replaceSelections(t)},defaultTab:function(e){e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:function(e){return Zi(e,(function(){for(var t=e.listSelections(),n=[],i=0;i<t.length;i++)if(t[i].empty()){var r=t[i].head,s=Ve(e.doc,r.line).text;if(s)if(r.ch==s.length&&(r=new et(r.line,r.ch-1)),r.ch>0)r=new et(r.line,r.ch+1),e.replaceRange(s.charAt(r.ch-1)+s.charAt(r.ch-2),et(r.line,r.ch-2),r,"+transpose");else if(r.line>e.doc.first){var o=Ve(e.doc,r.line-1).text;o&&(r=new et(r.line,1),e.replaceRange(s.charAt(0)+e.doc.lineSeparator()+o.charAt(o.length-1),et(r.line-1,o.length-1),r,"+transpose"))}n.push(new kr(r,r))}e.setSelections(n)}))},newlineAndIndent:function(e){return Zi(e,(function(){for(var t=e.listSelections(),n=t.length-1;n>=0;n--)e.replaceRange(e.doc.lineSeparator(),t[n].anchor,t[n].head,"+input");t=e.listSelections();for(var i=0;i<t.length;i++)e.indentLine(t[i].from().line,null,!0);Ei(e)}))},openLine:function(e){return e.replaceSelection("\n","start")},toggleOverwrite:function(e){return e.toggleOverwrite()}};function to(e,t){var n=Ve(e.doc,t),i=Rt(n);return i!=n&&(t=Ye(i)),Zs(!0,e,i,t,1)}function no(e,t){var n=to(e,t.line),i=Ve(e.doc,n.line),r=ce(i,e.doc.direction);if(!r||0==r[0].level){var s=Math.max(n.ch,i.text.search(/\S/)),o=t.line==n.line&&t.ch<=s&&t.ch;return et(n.line,o?0:s,n.sticky)}return n}function io(e,t,n){if("string"==typeof t&&!(t=eo[t]))return!1;e.display.input.ensurePolled();var i=e.display.shift,r=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),n&&(e.display.shift=!1),r=t(e)!=P}finally{e.display.shift=i,e.state.suppressEdits=!1}return r}var ro=new H;function so(e,t,n,i){var r=e.state.keySeq;if(r){if(Vs(t))return"handled";if(/\'$/.test(t)?e.state.keySeq=null:ro.set(50,(function(){e.state.keySeq==r&&(e.state.keySeq=null,e.display.input.reset())})),oo(e,r+" "+t,n,i))return!0}return oo(e,t,n,i)}function oo(e,t,n,i){var r=function(e,t,n){for(var i=0;i<e.state.keyMaps.length;i++){var r=Ks(t,e.state.keyMaps[i],n,e);if(r)return r}return e.options.extraKeys&&Ks(t,e.options.extraKeys,n,e)||Ks(t,e.options.keyMap,n,e)}(e,t,i);return"multi"==r&&(e.state.keySeq=t),"handled"==r&&ln(e,"keyHandled",e,t,n),"handled"!=r&&"multi"!=r||(ye(n),xi(e)),!!r}function ao(e,t){var n=Xs(t,!0);return!!n&&(t.shiftKey&&!e.state.keySeq?so(e,"Shift-"+n,t,(function(t){return io(e,t,!0)}))||so(e,n,t,(function(t){if("string"==typeof t?/^go[A-Z]/.test(t):t.motion)return io(e,t)})):so(e,n,t,(function(t){return io(e,t)})))}var lo=null;function co(e){var t=this;if(!(e.target&&e.target!=t.display.input.getField()||(t.curOp.focus=z(),pe(t,e)))){o&&a<11&&27==e.keyCode&&(e.returnValue=!1);var i=e.keyCode;t.display.shift=16==i||e.shiftKey;var r=ao(t,e);h&&(lo=r?i:null,r||88!=i||Ne||!(_?e.metaKey:e.ctrlKey)||t.replaceSelection("",null,"cut")),n&&!_&&!r&&46==i&&e.shiftKey&&!e.ctrlKey&&document.execCommand&&document.execCommand("cut"),18!=i||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||function(e){var t=e.display.lineDiv;function n(e){18!=e.keyCode&&e.altKey||(L(t,"CodeMirror-crosshair"),fe(document,"keyup",n),fe(document,"mouseover",n))}N(t,"CodeMirror-crosshair"),he(document,"keyup",n),he(document,"mouseover",n)}(t)}}function ho(e){16==e.keyCode&&(this.doc.sel.shift=!1),pe(this,e)}function uo(e){var t=this;if(!(e.target&&e.target!=t.display.input.getField()||wn(t.display,e)||pe(t,e)||e.ctrlKey&&!e.altKey||_&&e.metaKey)){var n=e.keyCode,i=e.charCode;if(h&&n==lo)return lo=null,void ye(e);if(!h||e.which&&!(e.which<10)||!ao(t,e)){var r=String.fromCharCode(null==i?n:i);"\b"!=r&&(function(e,t,n){return so(e,"'"+n+"'",t,(function(t){return io(e,t,!0)}))}(t,e,r)||t.display.input.onKeyPress(e))}}}var fo,mo,po=function(e,t,n){this.time=e,this.pos=t,this.button=n};function go(e){var t=this,n=t.display;if(!(pe(t,e)||n.activeTouch&&n.input.supportsTouch()))if(n.input.ensurePolled(),n.shift=e.shiftKey,wn(n,e))l||(n.scroller.draggable=!1,setTimeout((function(){return n.scroller.draggable=!0}),100));else if(!yo(t,e)){var i=ci(t,e),r=Ce(e),s=i?function(e,t){var n=+new Date;return mo&&mo.compare(n,e,t)?(fo=mo=null,"triple"):fo&&fo.compare(n,e,t)?(mo=new po(n,e,t),fo=null,"double"):(fo=new po(n,e,t),mo=null,"single")}(i,r):"single";window.focus(),1==r&&t.state.selectingText&&t.state.selectingText(e),i&&function(e,t,n,i,r){var s="Click";"double"==i?s="Double"+s:"triple"==i&&(s="Triple"+s);return so(e,qs(s=(1==t?"Left":2==t?"Middle":"Right")+s,r),r,(function(t){if("string"==typeof t&&(t=eo[t]),!t)return!1;var i=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),i=t(e,n)!=P}finally{e.state.suppressEdits=!1}return i}))}(t,r,i,s,e)||(1==r?i?function(e,t,n,i){o?setTimeout($(wi,e),0):e.curOp.focus=z();var r,s=function(e,t,n){var i=e.getOption("configureMouse"),r=i?i(e,t,n):{};if(null==r.unit){var s=y?n.shiftKey&&n.metaKey:n.altKey;r.unit=s?"rectangle":"single"==t?"char":"double"==t?"word":"line"}(null==r.extend||e.doc.extend)&&(r.extend=e.doc.extend||n.shiftKey);null==r.addNew&&(r.addNew=_?n.metaKey:n.ctrlKey);null==r.moveOnDrag&&(r.moveOnDrag=!(_?n.altKey:n.ctrlKey));return r}(e,n,i),c=e.doc.sel;e.options.dragDrop&&Me&&!e.isReadOnly()&&"single"==n&&(r=c.contains(t))>-1&&(tt((r=c.ranges[r]).from(),t)<0||t.xRel>0)&&(tt(r.to(),t)>0||t.xRel<0)?function(e,t,n,i){var r=e.display,s=!1,c=er(e,(function(t){l&&(r.scroller.draggable=!1),e.state.draggingText=!1,e.state.delayingBlurEvent&&(e.hasFocus()?e.state.delayingBlurEvent=!1:ki(e)),fe(r.wrapper.ownerDocument,"mouseup",c),fe(r.wrapper.ownerDocument,"mousemove",d),fe(r.scroller,"dragstart",h),fe(r.scroller,"drop",c),s||(ye(t),i.addNew||Xr(e.doc,n,null,null,i.extend),l&&!u||o&&9==a?setTimeout((function(){r.wrapper.ownerDocument.body.focus({preventScroll:!0}),r.input.focus()}),20):r.input.focus())})),d=function(e){s=s||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},h=function(){return s=!0};l&&(r.scroller.draggable=!0);e.state.draggingText=c,c.copy=!i.moveOnDrag,he(r.wrapper.ownerDocument,"mouseup",c),he(r.wrapper.ownerDocument,"mousemove",d),he(r.scroller,"dragstart",h),he(r.scroller,"drop",c),e.state.delayingBlurEvent=!0,setTimeout((function(){return r.input.focus()}),20),r.scroller.dragDrop&&r.scroller.dragDrop()}(e,i,t,s):function(e,t,n,i){o&&ki(e);var r=e.display,s=e.doc;ye(t);var a,l,c=s.sel,d=c.ranges;i.addNew&&!i.extend?(l=s.sel.contains(n),a=l>-1?d[l]:new kr(n,n)):(a=s.sel.primary(),l=s.sel.primIndex);if("rectangle"==i.unit)i.addNew||(a=new kr(n,n)),n=ci(e,t,!0,!0),l=-1;else{var h=vo(e,n,i.unit);a=i.extend?qr(a,h.anchor,h.head,i.extend):h}i.addNew?-1==l?(l=d.length,Zr(s,Cr(e,d.concat([a]),l),{scroll:!1,origin:"*mouse"})):d.length>1&&d[l].empty()&&"char"==i.unit&&!i.extend?(Zr(s,Cr(e,d.slice(0,l).concat(d.slice(l+1)),0),{scroll:!1,origin:"*mouse"}),c=s.sel):Yr(s,l,a,U):(l=0,Zr(s,new wr([a],0),U),c=s.sel);var u=n;function f(t){if(0!=tt(u,t))if(u=t,"rectangle"==i.unit){for(var r=[],o=e.options.tabSize,d=R(Ve(s,n.line).text,n.ch,o),h=R(Ve(s,t.line).text,t.ch,o),f=Math.min(d,h),m=Math.max(d,h),p=Math.min(n.line,t.line),g=Math.min(e.lastLine(),Math.max(n.line,t.line));p<=g;p++){var v=Ve(s,p).text,_=K(v,f,o);f==m?r.push(new kr(et(p,_),et(p,_))):v.length>_&&r.push(new kr(et(p,_),et(p,K(v,m,o))))}r.length||r.push(new kr(n,n)),Zr(s,Cr(e,c.ranges.slice(0,l).concat(r),l),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var y,b=a,x=vo(e,t,i.unit),w=b.anchor;tt(x.anchor,w)>0?(y=x.head,w=st(b.from(),x.anchor)):(y=x.anchor,w=rt(b.to(),x.head));var k=c.ranges.slice(0);k[l]=function(e,t){var n=t.anchor,i=t.head,r=Ve(e.doc,n.line);if(0==tt(n,i)&&n.sticky==i.sticky)return t;var s=ce(r);if(!s)return t;var o=ae(s,n.ch,n.sticky),a=s[o];if(a.from!=n.ch&&a.to!=n.ch)return t;var l,c=o+(a.from==n.ch==(1!=a.level)?0:1);if(0==c||c==s.length)return t;if(i.line!=n.line)l=(i.line-n.line)*("ltr"==e.doc.direction?1:-1)>0;else{var d=ae(s,i.ch,i.sticky),h=d-o||(i.ch-n.ch)*(1==a.level?-1:1);l=d==c-1||d==c?h<0:h>0}var u=s[c+(l?-1:0)],f=l==(1==u.level),m=f?u.from:u.to,p=f?"after":"before";return n.ch==m&&n.sticky==p?t:new kr(new et(n.line,m,p),i)}(e,new kr(at(s,w),y)),Zr(s,Cr(e,k,l),U)}}var m=r.wrapper.getBoundingClientRect(),p=0;function g(t){var n=++p,o=ci(e,t,!0,"rectangle"==i.unit);if(o)if(0!=tt(o,u)){e.curOp.focus=z(),f(o);var a=Ti(r,s);(o.line>=a.to||o.line<a.from)&&setTimeout(er(e,(function(){p==n&&g(t)})),150)}else{var l=t.clientY<m.top?-20:t.clientY>m.bottom?20:0;l&&setTimeout(er(e,(function(){p==n&&(r.scroller.scrollTop+=l,g(t))})),50)}}function v(t){e.state.selectingText=!1,p=1/0,t&&(ye(t),r.input.focus()),fe(r.wrapper.ownerDocument,"mousemove",_),fe(r.wrapper.ownerDocument,"mouseup",y),s.history.lastSelOrigin=null}var _=er(e,(function(e){0!==e.buttons&&Ce(e)?g(e):v(e)})),y=er(e,v);e.state.selectingText=y,he(r.wrapper.ownerDocument,"mousemove",_),he(r.wrapper.ownerDocument,"mouseup",y)}(e,i,t,s)}(t,i,s,e):ke(e)==n.scroller&&ye(e):2==r?(i&&Xr(t.doc,i),setTimeout((function(){return n.input.focus()}),20)):3==r&&(k?t.display.input.onContextMenu(e):ki(t)))}}function vo(e,t,n){if("char"==n)return new kr(t,t);if("word"==n)return e.findWordAt(t);if("line"==n)return new kr(et(t.line,0),at(e.doc,et(t.line+1,0)));var i=n(e,t);return new kr(i.from,i.to)}function _o(e,t,n,i){var r,s;if(t.touches)r=t.touches[0].clientX,s=t.touches[0].clientY;else try{r=t.clientX,s=t.clientY}catch(e){return!1}if(r>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;i&&ye(t);var o=e.display,a=o.lineDiv.getBoundingClientRect();if(s>a.bottom||!ve(e,n))return xe(t);s-=a.top-o.viewOffset;for(var l=0;l<e.display.gutterSpecs.length;++l){var c=o.gutters.childNodes[l];if(c&&c.getBoundingClientRect().right>=r)return me(e,n,e,Je(e.doc,s),e.display.gutterSpecs[l].className,t),xe(t)}}function yo(e,t){return _o(e,t,"gutterClick",!0)}function bo(e,t){wn(e.display,t)||function(e,t){if(!ve(e,"gutterContextMenu"))return!1;return _o(e,t,"gutterContextMenu",!1)}(e,t)||pe(e,t,"contextmenu")||k||e.display.input.onContextMenu(t)}function xo(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),Dn(e)}po.prototype.compare=function(e,t,n){return this.time+400>e&&0==tt(t,this.pos)&&n==this.button};var wo={toString:function(){return"CodeMirror.Init"}},ko={},Co={};function So(e,t,n){if(!t!=!(n&&n!=wo)){var i=e.display.dragFunctions,r=t?he:fe;r(e.display.scroller,"dragstart",i.start),r(e.display.scroller,"dragenter",i.enter),r(e.display.scroller,"dragover",i.over),r(e.display.scroller,"dragleave",i.leave),r(e.display.scroller,"drop",i.drop)}}function Lo(e){e.options.lineWrapping?(N(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(L(e.display.wrapper,"CodeMirror-wrap"),Kt(e)),li(e),hi(e),Dn(e),setTimeout((function(){return Pi(e)}),100)}function Mo(e,t){var n=this;if(!(this instanceof Mo))return new Mo(e,t);this.options=t=t?O(t):{},O(ko,t,!1);var i=t.value;"string"==typeof i?i=new As(i,t.mode,null,t.lineSeparator,t.direction):t.mode&&(i.modeOption=t.mode),this.doc=i;var r=new Mo.inputStyles[t.inputStyle](this),s=this.display=new gr(e,i,r,t);for(var c in s.wrapper.CodeMirror=this,xo(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),ji(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:-1,cutIncoming:-1,selectingText:!1,draggingText:!1,highlight:new H,keySeq:null,specialChars:null},t.autofocus&&!v&&s.input.focus(),o&&a<11&&setTimeout((function(){return n.display.input.reset(!0)}),20),function(e){var t=e.display;he(t.scroller,"mousedown",er(e,go)),he(t.scroller,"dblclick",o&&a<11?er(e,(function(t){if(!pe(e,t)){var n=ci(e,t);if(n&&!yo(e,t)&&!wn(e.display,t)){ye(t);var i=e.findWordAt(n);Xr(e.doc,i.anchor,i.head)}}})):function(t){return pe(e,t)||ye(t)});he(t.scroller,"contextmenu",(function(t){return bo(e,t)})),he(t.input.getField(),"contextmenu",(function(n){t.scroller.contains(n.target)||bo(e,n)}));var n,i={end:0};function r(){t.activeTouch&&(n=setTimeout((function(){return t.activeTouch=null}),1e3),(i=t.activeTouch).end=+new Date)}function s(e){if(1!=e.touches.length)return!1;var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}function l(e,t){if(null==t.left)return!0;var n=t.left-e.left,i=t.top-e.top;return n*n+i*i>400}he(t.scroller,"touchstart",(function(r){if(!pe(e,r)&&!s(r)&&!yo(e,r)){t.input.ensurePolled(),clearTimeout(n);var o=+new Date;t.activeTouch={start:o,moved:!1,prev:o-i.end<=300?i:null},1==r.touches.length&&(t.activeTouch.left=r.touches[0].pageX,t.activeTouch.top=r.touches[0].pageY)}})),he(t.scroller,"touchmove",(function(){t.activeTouch&&(t.activeTouch.moved=!0)})),he(t.scroller,"touchend",(function(n){var i=t.activeTouch;if(i&&!wn(t,n)&&null!=i.left&&!i.moved&&new Date-i.start<300){var s,o=e.coordsChar(t.activeTouch,"page");s=!i.prev||l(i,i.prev)?new kr(o,o):!i.prev.prev||l(i,i.prev.prev)?e.findWordAt(o):new kr(et(o.line,0),at(e.doc,et(o.line+1,0))),e.setSelection(s.anchor,s.head),e.focus(),ye(n)}r()})),he(t.scroller,"touchcancel",r),he(t.scroller,"scroll",(function(){t.scroller.clientHeight&&(Bi(e,t.scroller.scrollTop),Oi(e,t.scroller.scrollLeft,!0),me(e,"scroll",e))})),he(t.scroller,"mousewheel",(function(t){return xr(e,t)})),he(t.scroller,"DOMMouseScroll",(function(t){return xr(e,t)})),he(t.wrapper,"scroll",(function(){return t.wrapper.scrollTop=t.wrapper.scrollLeft=0})),t.dragFunctions={enter:function(t){pe(e,t)||we(t)},over:function(t){pe(e,t)||(!function(e,t){var n=ci(e,t);if(n){var i=document.createDocumentFragment();_i(e,n,i),e.display.dragCursor||(e.display.dragCursor=I("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),e.display.lineSpace.insertBefore(e.display.dragCursor,e.display.cursorDiv)),T(e.display.dragCursor,i)}}(e,t),we(t))},start:function(t){return function(e,t){if(o&&(!e.state.draggingText||+new Date-Es<100))we(t);else if(!pe(e,t)&&!wn(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.effectAllowed="copyMove",t.dataTransfer.setDragImage&&!u)){var n=I("img",null,null,"position: fixed; left: 0; top: 0;");n.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",h&&(n.width=n.height=1,e.display.wrapper.appendChild(n),n._top=n.offsetTop),t.dataTransfer.setDragImage(n,0,0),h&&n.parentNode.removeChild(n)}}(e,t)},drop:er(e,zs),leave:function(t){pe(e,t)||Ns(e)}};var c=t.input.getField();he(c,"keyup",(function(t){return ho.call(e,t)})),he(c,"keydown",er(e,co)),he(c,"keypress",er(e,uo)),he(c,"focus",(function(t){return Ci(e,t)})),he(c,"blur",(function(t){return Si(e,t)}))}(this),$s(),Vi(this),this.curOp.forceUpdate=!0,Br(this,i),t.autofocus&&!v||this.hasFocus()?setTimeout((function(){n.hasFocus()&&!n.state.focused&&Ci(n)}),20):Si(this),Co)Co.hasOwnProperty(c)&&Co[c](this,t[c],wo);ur(this),t.finishInit&&t.finishInit(this);for(var d=0;d<To.length;++d)To[d](this);qi(this),l&&t.lineWrapping&&"optimizelegibility"==getComputedStyle(s.lineDiv).textRendering&&(s.lineDiv.style.textRendering="auto")}Mo.defaults=ko,Mo.optionHandlers=Co;var To=[];function Io(e,t,n,i){var r,s=e.doc;null==n&&(n="add"),"smart"==n&&(s.mode.indent?r=ft(e,t).state:n="prev");var o=e.options.tabSize,a=Ve(s,t),l=R(a.text,null,o);a.stateAfter&&(a.stateAfter=null);var c,d=a.text.match(/^\s*/)[0];if(i||/\S/.test(a.text)){if("smart"==n&&((c=s.mode.indent(r,a.text.slice(d.length),a.text))==P||c>150)){if(!i)return;n="prev"}}else c=0,n="not";"prev"==n?c=t>s.first?R(Ve(s,t-1).text,null,o):0:"add"==n?c=l+e.options.indentUnit:"subtract"==n?c=l-e.options.indentUnit:"number"==typeof n&&(c=l+n),c=Math.max(0,c);var h="",u=0;if(e.options.indentWithTabs)for(var f=Math.floor(c/o);f;--f)u+=o,h+="\t";if(u<c&&(h+=q(c-u)),h!=d)return ms(s,h,et(t,0),et(t,d.length),"+input"),a.stateAfter=null,!0;for(var m=0;m<s.sel.ranges.length;m++){var p=s.sel.ranges[m];if(p.head.line==t&&p.head.ch<d.length){var g=et(t,d.length);Yr(s,m,new kr(g,g));break}}}Mo.defineInitHook=function(e){return To.push(e)};var Ao=null;function Eo(e){Ao=e}function zo(e,t,n,i,r){var s=e.doc;e.display.shift=!1,i||(i=s.sel);var o=+new Date-200,a="paste"==r||e.state.pasteIncoming>o,l=Ee(t),c=null;if(a&&i.ranges.length>1)if(Ao&&Ao.text.join("\n")==t){if(i.ranges.length%Ao.text.length==0){c=[];for(var d=0;d<Ao.text.length;d++)c.push(s.splitLines(Ao.text[d]))}}else l.length==i.ranges.length&&e.options.pasteLinesPerSelection&&(c=G(l,(function(e){return[e]})));for(var h=e.curOp.updateInput,u=i.ranges.length-1;u>=0;u--){var f=i.ranges[u],m=f.from(),p=f.to();f.empty()&&(n&&n>0?m=et(m.line,m.ch-n):e.state.overwrite&&!a?p=et(p.line,Math.min(Ve(s,p.line).text.length,p.ch+X(l).length)):a&&Ao&&Ao.lineWise&&Ao.text.join("\n")==l.join("\n")&&(m=p=et(m.line,0)));var g={from:m,to:p,text:c?c[u%c.length]:l,origin:r||(a?"paste":e.state.cutIncoming>o?"cut":"+input")};cs(e.doc,g),ln(e,"inputRead",e,g)}t&&!a&&Fo(e,t),Ei(e),e.curOp.updateInput<2&&(e.curOp.updateInput=h),e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=-1}function No(e,t){var n=e.clipboardData&&e.clipboardData.getData("Text");if(n)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||Zi(t,(function(){return zo(t,n,0,null,"paste")})),!0}function Fo(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var n=e.doc.sel,i=n.ranges.length-1;i>=0;i--){var r=n.ranges[i];if(!(r.head.ch>100||i&&n.ranges[i-1].head.line==r.head.line)){var s=e.getModeAt(r.head),o=!1;if(s.electricChars){for(var a=0;a<s.electricChars.length;a++)if(t.indexOf(s.electricChars.charAt(a))>-1){o=Io(e,r.head.line,"smart");break}}else s.electricInput&&s.electricInput.test(Ve(e.doc,r.head.line).text.slice(0,r.head.ch))&&(o=Io(e,r.head.line,"smart"));o&&ln(e,"electricInput",e,r.head.line)}}}function Bo(e){for(var t=[],n=[],i=0;i<e.doc.sel.ranges.length;i++){var r=e.doc.sel.ranges[i].head.line,s={anchor:et(r,0),head:et(r+1,0)};n.push(s),t.push(e.getRange(s.anchor,s.head))}return{text:t,ranges:n}}function $o(e,t,n,i){e.setAttribute("autocorrect",n?"":"off"),e.setAttribute("autocapitalize",i?"":"off"),e.setAttribute("spellcheck",!!t)}function Oo(){var e=I("textarea",null,null,"position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; min-height: 1em; outline: none"),t=I("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");return l?e.style.width="1000px":e.setAttribute("wrap","off"),p&&(e.style.border="1px solid black"),$o(e),t}function Ro(e,t,n,i,r){var s=t,o=n,a=Ve(e,t.line),l=r&&"rtl"==e.direction?-n:n;function c(s){var o,c;if("codepoint"==i){var d=a.text.charCodeAt(t.ch+(n>0?0:-1));if(isNaN(d))o=null;else{var h=n>0?d>=55296&&d<56320:d>=56320&&d<57343;o=new et(t.line,Math.max(0,Math.min(a.text.length,t.ch+n*(h?2:1))),-n)}}else o=r?function(e,t,n,i){var r=ce(t,e.doc.direction);if(!r)return Qs(t,n,i);n.ch>=t.text.length?(n.ch=t.text.length,n.sticky="before"):n.ch<=0&&(n.ch=0,n.sticky="after");var s=ae(r,n.ch,n.sticky),o=r[s];if("ltr"==e.doc.direction&&o.level%2==0&&(i>0?o.to>n.ch:o.from<n.ch))return Qs(t,n,i);var a,l=function(e,n){return Js(t,e instanceof et?e.ch:e,n)},c=function(n){return e.options.lineWrapping?(a=a||zn(e,t),Qn(e,t,a,n)):{begin:0,end:t.text.length}},d=c("before"==n.sticky?l(n,-1):n.ch);if("rtl"==e.doc.direction||1==o.level){var h=1==o.level==i<0,u=l(n,h?1:-1);if(null!=u&&(h?u<=o.to&&u<=d.end:u>=o.from&&u>=d.begin)){var f=h?"before":"after";return new et(n.line,u,f)}}var m=function(e,t,i){for(var s=function(e,t){return t?new et(n.line,l(e,1),"before"):new et(n.line,e,"after")};e>=0&&e<r.length;e+=t){var o=r[e],a=t>0==(1!=o.level),c=a?i.begin:l(i.end,-1);if(o.from<=c&&c<o.to)return s(c,a);if(c=a?o.from:l(o.to,-1),i.begin<=c&&c<i.end)return s(c,a)}},p=m(s+i,i,d);if(p)return p;var g=i>0?d.end:l(d.begin,-1);return null==g||i>0&&g==t.text.length||!(p=m(i>0?0:r.length-1,i,c(g)))?null:p}(e.cm,a,t,n):Qs(a,t,n);if(null==o){if(s||(c=t.line+l)<e.first||c>=e.first+e.size||(t=new et(c,t.ch,t.sticky),!(a=Ve(e,c))))return!1;t=Zs(r,e.cm,a,t.line,l)}else t=o;return!0}if("char"==i||"codepoint"==i)c();else if("column"==i)c(!0);else if("word"==i||"group"==i)for(var d=null,h="group"==i,u=e.cm&&e.cm.getHelper(t,"wordChars"),f=!0;!(n<0)||c(!f);f=!1){var m=a.text.charAt(t.ch)||"\n",p=ee(m,u)?"w":h&&"\n"==m?"n":!h||/\s/.test(m)?null:"p";if(!h||f||p||(p="s"),d&&d!=p){n<0&&(n=1,c(),t.sticky="after");break}if(p&&(d=p),n>0&&!c(!f))break}var g=ss(e,t,s,o,!0);return nt(s,g)&&(g.hitSide=!0),g}function Ho(e,t,n,i){var r,s,o=e.doc,a=t.left;if("page"==i){var l=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),c=Math.max(l-.5*ii(e.display),3);r=(n>0?t.bottom:t.top)+n*c}else"line"==i&&(r=n>0?t.bottom+3:t.top-3);for(;(s=Yn(e,a,r)).outside;){if(n<0?r<=0:r>=o.height){s.hitSide=!0;break}r+=5*n}return s}var Do=function(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new H,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};function Po(e,t){var n=En(e,t.line);if(!n||n.hidden)return null;var i=Ve(e.doc,t.line),r=In(n,i,t.line),s=ce(i,e.doc.direction),o="left";s&&(o=ae(s,t.ch)%2?"right":"left");var a=$n(r.map,t.ch,o);return a.offset="right"==a.collapse?a.end:a.start,a}function Wo(e,t){return t&&(e.bad=!0),e}function Uo(e,t,n){var i;if(t==e.display.lineDiv){if(!(i=e.display.lineDiv.childNodes[n]))return Wo(e.clipPos(et(e.display.viewTo-1)),!0);t=null,n=0}else for(i=t;;i=i.parentNode){if(!i||i==e.display.lineDiv)return null;if(i.parentNode&&i.parentNode==e.display.lineDiv)break}for(var r=0;r<e.display.view.length;r++){var s=e.display.view[r];if(s.node==i)return jo(s,t,n)}}function jo(e,t,n){var i=e.text.firstChild,r=!1;if(!t||!E(i,t))return Wo(et(Ye(e.line),0),!0);if(t==i&&(r=!0,t=i.childNodes[n],n=0,!t)){var s=e.rest?X(e.rest):e.line;return Wo(et(Ye(s),s.text.length),r)}var o=3==t.nodeType?t:null,a=t;for(o||1!=t.childNodes.length||3!=t.firstChild.nodeType||(o=t.firstChild,n&&(n=o.nodeValue.length));a.parentNode!=i;)a=a.parentNode;var l=e.measure,c=l.maps;function d(t,n,i){for(var r=-1;r<(c?c.length:0);r++)for(var s=r<0?l.map:c[r],o=0;o<s.length;o+=3){var a=s[o+2];if(a==t||a==n){var d=Ye(r<0?e.line:e.rest[r]),h=s[o]+i;return(i<0||a!=t)&&(h=s[o+(i?1:0)]),et(d,h)}}}var h=d(o,a,n);if(h)return Wo(h,r);for(var u=a.nextSibling,f=o?o.nodeValue.length-n:0;u;u=u.nextSibling){if(h=d(u,u.firstChild,0))return Wo(et(h.line,h.ch-f),r);f+=u.textContent.length}for(var m=a.previousSibling,p=n;m;m=m.previousSibling){if(h=d(m,m.firstChild,-1))return Wo(et(h.line,h.ch+p),r);p+=m.textContent.length}}Do.prototype.init=function(e){var t=this,n=this,i=n.cm,r=n.div=e.lineDiv;function s(e){for(var t=e.target;t;t=t.parentNode){if(t==r)return!0;if(/\bCodeMirror-(?:line)?widget\b/.test(t.className))break}return!1}function o(e){if(s(e)&&!pe(i,e)){if(i.somethingSelected())Eo({lineWise:!1,text:i.getSelections()}),"cut"==e.type&&i.replaceSelection("",null,"cut");else{if(!i.options.lineWiseCopyCut)return;var t=Bo(i);Eo({lineWise:!0,text:t.text}),"cut"==e.type&&i.operation((function(){i.setSelections(t.ranges,0,W),i.replaceSelection("",null,"cut")}))}if(e.clipboardData){e.clipboardData.clearData();var o=Ao.text.join("\n");if(e.clipboardData.setData("Text",o),e.clipboardData.getData("Text")==o)return void e.preventDefault()}var a=Oo(),l=a.firstChild;i.display.lineSpace.insertBefore(a,i.display.lineSpace.firstChild),l.value=Ao.text.join("\n");var c=z();B(l),setTimeout((function(){i.display.lineSpace.removeChild(a),c.focus(),c==r&&n.showPrimarySelection()}),50)}}r.contentEditable=!0,$o(r,i.options.spellcheck,i.options.autocorrect,i.options.autocapitalize),he(r,"paste",(function(e){!s(e)||pe(i,e)||No(e,i)||a<=11&&setTimeout(er(i,(function(){return t.updateFromDOM()})),20)})),he(r,"compositionstart",(function(e){t.composing={data:e.data,done:!1}})),he(r,"compositionupdate",(function(e){t.composing||(t.composing={data:e.data,done:!1})})),he(r,"compositionend",(function(e){t.composing&&(e.data!=t.composing.data&&t.readFromDOMSoon(),t.composing.done=!0)})),he(r,"touchstart",(function(){return n.forceCompositionEnd()})),he(r,"input",(function(){t.composing||t.readFromDOMSoon()})),he(r,"copy",o),he(r,"cut",o)},Do.prototype.screenReaderLabelChanged=function(e){e?this.div.setAttribute("aria-label",e):this.div.removeAttribute("aria-label")},Do.prototype.prepareSelection=function(){var e=vi(this.cm,!1);return e.focus=z()==this.div,e},Do.prototype.showSelection=function(e,t){e&&this.cm.display.view.length&&((e.focus||t)&&this.showPrimarySelection(),this.showMultipleSelections(e))},Do.prototype.getSelection=function(){return this.cm.display.wrapper.ownerDocument.getSelection()},Do.prototype.showPrimarySelection=function(){var e=this.getSelection(),t=this.cm,i=t.doc.sel.primary(),r=i.from(),s=i.to();if(t.display.viewTo==t.display.viewFrom||r.line>=t.display.viewTo||s.line<t.display.viewFrom)e.removeAllRanges();else{var o=Uo(t,e.anchorNode,e.anchorOffset),a=Uo(t,e.focusNode,e.focusOffset);if(!o||o.bad||!a||a.bad||0!=tt(st(o,a),r)||0!=tt(rt(o,a),s)){var l=t.display.view,c=r.line>=t.display.viewFrom&&Po(t,r)||{node:l[0].measure.map[2],offset:0},d=s.line<t.display.viewTo&&Po(t,s);if(!d){var h=l[l.length-1].measure,u=h.maps?h.maps[h.maps.length-1]:h.map;d={node:u[u.length-1],offset:u[u.length-2]-u[u.length-3]}}if(c&&d){var f,m=e.rangeCount&&e.getRangeAt(0);try{f=S(c.node,c.offset,d.offset,d.node)}catch(e){}f&&(!n&&t.state.focused?(e.collapse(c.node,c.offset),f.collapsed||(e.removeAllRanges(),e.addRange(f))):(e.removeAllRanges(),e.addRange(f)),m&&null==e.anchorNode?e.addRange(m):n&&this.startGracePeriod()),this.rememberSelection()}else e.removeAllRanges()}}},Do.prototype.startGracePeriod=function(){var e=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout((function(){e.gracePeriod=!1,e.selectionChanged()&&e.cm.operation((function(){return e.cm.curOp.selectionChanged=!0}))}),20)},Do.prototype.showMultipleSelections=function(e){T(this.cm.display.cursorDiv,e.cursors),T(this.cm.display.selectionDiv,e.selection)},Do.prototype.rememberSelection=function(){var e=this.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset},Do.prototype.selectionInEditor=function(){var e=this.getSelection();if(!e.rangeCount)return!1;var t=e.getRangeAt(0).commonAncestorContainer;return E(this.div,t)},Do.prototype.focus=function(){"nocursor"!=this.cm.options.readOnly&&(this.selectionInEditor()&&z()==this.div||this.showSelection(this.prepareSelection(),!0),this.div.focus())},Do.prototype.blur=function(){this.div.blur()},Do.prototype.getField=function(){return this.div},Do.prototype.supportsTouch=function(){return!0},Do.prototype.receivedFocus=function(){var e=this,t=this;this.selectionInEditor()?setTimeout((function(){return e.pollSelection()}),20):Zi(this.cm,(function(){return t.cm.curOp.selectionChanged=!0})),this.polling.set(this.cm.options.pollInterval,(function e(){t.cm.state.focused&&(t.pollSelection(),t.polling.set(t.cm.options.pollInterval,e))}))},Do.prototype.selectionChanged=function(){var e=this.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset},Do.prototype.pollSelection=function(){if(null==this.readDOMTimeout&&!this.gracePeriod&&this.selectionChanged()){var e=this.getSelection(),t=this.cm;if(g&&d&&this.cm.display.gutterSpecs.length&&function(e){for(var t=e;t;t=t.parentNode)if(/CodeMirror-gutter-wrapper/.test(t.className))return!0;return!1}(e.anchorNode))return this.cm.triggerOnKeyDown({type:"keydown",keyCode:8,preventDefault:Math.abs}),this.blur(),void this.focus();if(!this.composing){this.rememberSelection();var n=Uo(t,e.anchorNode,e.anchorOffset),i=Uo(t,e.focusNode,e.focusOffset);n&&i&&Zi(t,(function(){Zr(t.doc,Sr(n,i),W),(n.bad||i.bad)&&(t.curOp.selectionChanged=!0)}))}}},Do.prototype.pollContent=function(){null!=this.readDOMTimeout&&(clearTimeout(this.readDOMTimeout),this.readDOMTimeout=null);var e,t,n,i=this.cm,r=i.display,s=i.doc.sel.primary(),o=s.from(),a=s.to();if(0==o.ch&&o.line>i.firstLine()&&(o=et(o.line-1,Ve(i.doc,o.line-1).length)),a.ch==Ve(i.doc,a.line).text.length&&a.line<i.lastLine()&&(a=et(a.line+1,0)),o.line<r.viewFrom||a.line>r.viewTo-1)return!1;o.line==r.viewFrom||0==(e=di(i,o.line))?(t=Ye(r.view[0].line),n=r.view[0].node):(t=Ye(r.view[e].line),n=r.view[e-1].node.nextSibling);var l,c,d=di(i,a.line);if(d==r.view.length-1?(l=r.viewTo-1,c=r.lineDiv.lastChild):(l=Ye(r.view[d+1].line)-1,c=r.view[d+1].node.previousSibling),!n)return!1;for(var h=i.doc.splitLines(function(e,t,n,i,r){var s="",o=!1,a=e.doc.lineSeparator(),l=!1;function c(e){return function(t){return t.id==e}}function d(){o&&(s+=a,l&&(s+=a),o=l=!1)}function h(e){e&&(d(),s+=e)}function u(t){if(1==t.nodeType){var n=t.getAttribute("cm-text");if(n)return void h(n);var s,f=t.getAttribute("cm-marker");if(f){var m=e.findMarks(et(i,0),et(r+1,0),c(+f));return void(m.length&&(s=m[0].find(0))&&h(qe(e.doc,s.from,s.to).join(a)))}if("false"==t.getAttribute("contenteditable"))return;var p=/^(pre|div|p|li|table|br)$/i.test(t.nodeName);if(!/^br$/i.test(t.nodeName)&&0==t.textContent.length)return;p&&d();for(var g=0;g<t.childNodes.length;g++)u(t.childNodes[g]);/^(pre|p)$/i.test(t.nodeName)&&(l=!0),p&&(o=!0)}else 3==t.nodeType&&h(t.nodeValue.replace(/\u200b/g,"").replace(/\u00a0/g," "))}for(;u(t),t!=n;)t=t.nextSibling,l=!1;return s}(i,n,c,t,l)),u=qe(i.doc,et(t,0),et(l,Ve(i.doc,l).text.length));h.length>1&&u.length>1;)if(X(h)==X(u))h.pop(),u.pop(),l--;else{if(h[0]!=u[0])break;h.shift(),u.shift(),t++}for(var f=0,m=0,p=h[0],g=u[0],v=Math.min(p.length,g.length);f<v&&p.charCodeAt(f)==g.charCodeAt(f);)++f;for(var _=X(h),y=X(u),b=Math.min(_.length-(1==h.length?f:0),y.length-(1==u.length?f:0));m<b&&_.charCodeAt(_.length-m-1)==y.charCodeAt(y.length-m-1);)++m;if(1==h.length&&1==u.length&&t==o.line)for(;f&&f>o.ch&&_.charCodeAt(_.length-m-1)==y.charCodeAt(y.length-m-1);)f--,m++;h[h.length-1]=_.slice(0,_.length-m).replace(/^\u200b+/,""),h[0]=h[0].slice(f).replace(/\u200b+$/,"");var x=et(t,f),w=et(l,u.length?X(u).length-m:0);return h.length>1||h[0]||tt(x,w)?(ms(i.doc,h,x,w,"+input"),!0):void 0},Do.prototype.ensurePolled=function(){this.forceCompositionEnd()},Do.prototype.reset=function(){this.forceCompositionEnd()},Do.prototype.forceCompositionEnd=function(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())},Do.prototype.readFromDOMSoon=function(){var e=this;null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout((function(){if(e.readDOMTimeout=null,e.composing){if(!e.composing.done)return;e.composing=null}e.updateFromDOM()}),80))},Do.prototype.updateFromDOM=function(){var e=this;!this.cm.isReadOnly()&&this.pollContent()||Zi(this.cm,(function(){return hi(e.cm)}))},Do.prototype.setUneditable=function(e){e.contentEditable="false"},Do.prototype.onKeyPress=function(e){0==e.charCode||this.composing||(e.preventDefault(),this.cm.isReadOnly()||er(this.cm,zo)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0))},Do.prototype.readOnlyChanged=function(e){this.div.contentEditable=String("nocursor"!=e)},Do.prototype.onContextMenu=function(){},Do.prototype.resetPosition=function(){},Do.prototype.needsContentAttribute=!0;var Ko=function(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new H,this.hasSelection=!1,this.composing=null};Ko.prototype.init=function(e){var t=this,n=this,i=this.cm;this.createField(e);var r=this.textarea;function s(e){if(!pe(i,e)){if(i.somethingSelected())Eo({lineWise:!1,text:i.getSelections()});else{if(!i.options.lineWiseCopyCut)return;var t=Bo(i);Eo({lineWise:!0,text:t.text}),"cut"==e.type?i.setSelections(t.ranges,null,W):(n.prevInput="",r.value=t.text.join("\n"),B(r))}"cut"==e.type&&(i.state.cutIncoming=+new Date)}}e.wrapper.insertBefore(this.wrapper,e.wrapper.firstChild),p&&(r.style.width="0px"),he(r,"input",(function(){o&&a>=9&&t.hasSelection&&(t.hasSelection=null),n.poll()})),he(r,"paste",(function(e){pe(i,e)||No(e,i)||(i.state.pasteIncoming=+new Date,n.fastPoll())})),he(r,"cut",s),he(r,"copy",s),he(e.scroller,"paste",(function(t){if(!wn(e,t)&&!pe(i,t)){if(!r.dispatchEvent)return i.state.pasteIncoming=+new Date,void n.focus();var s=new Event("paste");s.clipboardData=t.clipboardData,r.dispatchEvent(s)}})),he(e.lineSpace,"selectstart",(function(t){wn(e,t)||ye(t)})),he(r,"compositionstart",(function(){var e=i.getCursor("from");n.composing&&n.composing.range.clear(),n.composing={start:e,range:i.markText(e,i.getCursor("to"),{className:"CodeMirror-composing"})}})),he(r,"compositionend",(function(){n.composing&&(n.poll(),n.composing.range.clear(),n.composing=null)}))},Ko.prototype.createField=function(e){this.wrapper=Oo(),this.textarea=this.wrapper.firstChild},Ko.prototype.screenReaderLabelChanged=function(e){e?this.textarea.setAttribute("aria-label",e):this.textarea.removeAttribute("aria-label")},Ko.prototype.prepareSelection=function(){var e=this.cm,t=e.display,n=e.doc,i=vi(e);if(e.options.moveInputWithCursor){var r=qn(e,n.sel.primary().head,"div"),s=t.wrapper.getBoundingClientRect(),o=t.lineDiv.getBoundingClientRect();i.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,r.top+o.top-s.top)),i.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,r.left+o.left-s.left))}return i},Ko.prototype.showSelection=function(e){var t=this.cm.display;T(t.cursorDiv,e.cursors),T(t.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},Ko.prototype.reset=function(e){if(!this.contextMenuPending&&!this.composing){var t=this.cm;if(t.somethingSelected()){this.prevInput="";var n=t.getSelection();this.textarea.value=n,t.state.focused&&B(this.textarea),o&&a>=9&&(this.hasSelection=n)}else e||(this.prevInput=this.textarea.value="",o&&a>=9&&(this.hasSelection=null))}},Ko.prototype.getField=function(){return this.textarea},Ko.prototype.supportsTouch=function(){return!1},Ko.prototype.focus=function(){if("nocursor"!=this.cm.options.readOnly&&(!v||z()!=this.textarea))try{this.textarea.focus()}catch(e){}},Ko.prototype.blur=function(){this.textarea.blur()},Ko.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0},Ko.prototype.receivedFocus=function(){this.slowPoll()},Ko.prototype.slowPoll=function(){var e=this;this.pollingFast||this.polling.set(this.cm.options.pollInterval,(function(){e.poll(),e.cm.state.focused&&e.slowPoll()}))},Ko.prototype.fastPoll=function(){var e=!1,t=this;t.pollingFast=!0,t.polling.set(20,(function n(){t.poll()||e?(t.pollingFast=!1,t.slowPoll()):(e=!0,t.polling.set(60,n))}))},Ko.prototype.poll=function(){var e=this,t=this.cm,n=this.textarea,i=this.prevInput;if(this.contextMenuPending||!t.state.focused||ze(n)&&!i&&!this.composing||t.isReadOnly()||t.options.disableInput||t.state.keySeq)return!1;var r=n.value;if(r==i&&!t.somethingSelected())return!1;if(o&&a>=9&&this.hasSelection===r||_&&/[\uf700-\uf7ff]/.test(r))return t.display.input.reset(),!1;if(t.doc.sel==t.display.selForContextMenu){var s=r.charCodeAt(0);if(8203!=s||i||(i=""),8666==s)return this.reset(),this.cm.execCommand("undo")}for(var l=0,c=Math.min(i.length,r.length);l<c&&i.charCodeAt(l)==r.charCodeAt(l);)++l;return Zi(t,(function(){zo(t,r.slice(l),i.length-l,null,e.composing?"*compose":null),r.length>1e3||r.indexOf("\n")>-1?n.value=e.prevInput="":e.prevInput=r,e.composing&&(e.composing.range.clear(),e.composing.range=t.markText(e.composing.start,t.getCursor("to"),{className:"CodeMirror-composing"}))})),!0},Ko.prototype.ensurePolled=function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},Ko.prototype.onKeyPress=function(){o&&a>=9&&(this.hasSelection=null),this.fastPoll()},Ko.prototype.onContextMenu=function(e){var t=this,n=t.cm,i=n.display,r=t.textarea;t.contextMenuPending&&t.contextMenuPending();var s=ci(n,e),c=i.scroller.scrollTop;if(s&&!h){n.options.resetSelectionOnContextMenu&&-1==n.doc.sel.contains(s)&&er(n,Zr)(n.doc,Sr(s),W);var d,u=r.style.cssText,f=t.wrapper.style.cssText,m=t.wrapper.offsetParent.getBoundingClientRect();if(t.wrapper.style.cssText="position: static",r.style.cssText="position: absolute; width: 30px; height: 30px;\n top: "+(e.clientY-m.top-5)+"px; left: "+(e.clientX-m.left-5)+"px;\n z-index: 1000; background: "+(o?"rgba(255, 255, 255, .05)":"transparent")+";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",l&&(d=window.scrollY),i.input.focus(),l&&window.scrollTo(null,d),i.input.reset(),n.somethingSelected()||(r.value=t.prevInput=" "),t.contextMenuPending=v,i.selForContextMenu=n.doc.sel,clearTimeout(i.detectingSelectAll),o&&a>=9&&g(),k){we(e);var p=function(){fe(window,"mouseup",p),setTimeout(v,20)};he(window,"mouseup",p)}else setTimeout(v,50)}function g(){if(null!=r.selectionStart){var e=n.somethingSelected(),s=""+(e?r.value:"");r.value="⇚",r.value=s,t.prevInput=e?"":"",r.selectionStart=1,r.selectionEnd=s.length,i.selForContextMenu=n.doc.sel}}function v(){if(t.contextMenuPending==v&&(t.contextMenuPending=!1,t.wrapper.style.cssText=f,r.style.cssText=u,o&&a<9&&i.scrollbars.setScrollTop(i.scroller.scrollTop=c),null!=r.selectionStart)){(!o||o&&a<9)&&g();var e=0,s=function(){i.selForContextMenu==n.doc.sel&&0==r.selectionStart&&r.selectionEnd>0&&""==t.prevInput?er(n,as)(n):e++<10?i.detectingSelectAll=setTimeout(s,500):(i.selForContextMenu=null,i.input.reset())};i.detectingSelectAll=setTimeout(s,200)}}},Ko.prototype.readOnlyChanged=function(e){e||this.reset(),this.textarea.disabled="nocursor"==e,this.textarea.readOnly=!!e},Ko.prototype.setUneditable=function(){},Ko.prototype.needsContentAttribute=!1,function(e){var t=e.optionHandlers;function n(n,i,r,s){e.defaults[n]=i,r&&(t[n]=s?function(e,t,n){n!=wo&&r(e,t,n)}:r)}e.defineOption=n,e.Init=wo,n("value","",(function(e,t){return e.setValue(t)}),!0),n("mode",null,(function(e,t){e.doc.modeOption=t,Ar(e)}),!0),n("indentUnit",2,Ar,!0),n("indentWithTabs",!1),n("smartIndent",!0),n("tabSize",4,(function(e){Er(e),Dn(e),hi(e)}),!0),n("lineSeparator",null,(function(e,t){if(e.doc.lineSep=t,t){var n=[],i=e.doc.first;e.doc.iter((function(e){for(var r=0;;){var s=e.text.indexOf(t,r);if(-1==s)break;r=s+t.length,n.push(et(i,s))}i++}));for(var r=n.length-1;r>=0;r--)ms(e.doc,t,n[r],et(n[r].line,n[r].ch+t.length))}})),n("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g,(function(e,t,n){e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),n!=wo&&e.refresh()})),n("specialCharPlaceholder",Qt,(function(e){return e.refresh()}),!0),n("electricChars",!0),n("inputStyle",v?"contenteditable":"textarea",(function(){throw new Error("inputStyle can not (yet) be changed in a running editor")}),!0),n("spellcheck",!1,(function(e,t){return e.getInputField().spellcheck=t}),!0),n("autocorrect",!1,(function(e,t){return e.getInputField().autocorrect=t}),!0),n("autocapitalize",!1,(function(e,t){return e.getInputField().autocapitalize=t}),!0),n("rtlMoveVisually",!b),n("wholeLineUpdateBefore",!0),n("theme","default",(function(e){xo(e),pr(e)}),!0),n("keyMap","default",(function(e,t,n){var i=Gs(t),r=n!=wo&&Gs(n);r&&r.detach&&r.detach(e,i),i.attach&&i.attach(e,r||null)})),n("extraKeys",null),n("configureMouse",null),n("lineWrapping",!1,Lo,!0),n("gutters",[],(function(e,t){e.display.gutterSpecs=fr(t,e.options.lineNumbers),pr(e)}),!0),n("fixedGutter",!0,(function(e,t){e.display.gutters.style.left=t?oi(e.display)+"px":"0",e.refresh()}),!0),n("coverGutterNextToScrollbar",!1,(function(e){return Pi(e)}),!0),n("scrollbarStyle","native",(function(e){ji(e),Pi(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)}),!0),n("lineNumbers",!1,(function(e,t){e.display.gutterSpecs=fr(e.options.gutters,t),pr(e)}),!0),n("firstLineNumber",1,pr,!0),n("lineNumberFormatter",(function(e){return e}),pr,!0),n("showCursorWhenSelecting",!1,gi,!0),n("resetSelectionOnContextMenu",!0),n("lineWiseCopyCut",!0),n("pasteLinesPerSelection",!0),n("selectionsMayTouch",!1),n("readOnly",!1,(function(e,t){"nocursor"==t&&(Si(e),e.display.input.blur()),e.display.input.readOnlyChanged(t)})),n("screenReaderLabel",null,(function(e,t){t=""===t?null:t,e.display.input.screenReaderLabelChanged(t)})),n("disableInput",!1,(function(e,t){t||e.display.input.reset()}),!0),n("dragDrop",!0,So),n("allowDropFileTypes",null),n("cursorBlinkRate",530),n("cursorScrollMargin",0),n("cursorHeight",1,gi,!0),n("singleCursorHeightPerLine",!0,gi,!0),n("workTime",100),n("workDelay",100),n("flattenSpans",!0,Er,!0),n("addModeClass",!1,Er,!0),n("pollInterval",100),n("undoDepth",200,(function(e,t){return e.doc.history.undoDepth=t})),n("historyEventDelay",1250),n("viewportMargin",10,(function(e){return e.refresh()}),!0),n("maxHighlightLength",1e4,Er,!0),n("moveInputWithCursor",!0,(function(e,t){t||e.display.input.resetPosition()})),n("tabindex",null,(function(e,t){return e.display.input.getField().tabIndex=t||""})),n("autofocus",null),n("direction","ltr",(function(e,t){return e.doc.setDirection(t)}),!0),n("phrases",null)}(Mo),function(e){var t=e.optionHandlers,n=e.helpers={};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,n){var i=this.options,r=i[e];i[e]==n&&"mode"!=e||(i[e]=n,t.hasOwnProperty(e)&&er(this,t[e])(this,n,r),me(this,"optionChange",this,e))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](Gs(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,n=0;n<t.length;++n)if(t[n]==e||t[n].name==e)return t.splice(n,1),!0},addOverlay:tr((function(t,n){var i=t.token?t:e.getMode(this.options,t);if(i.startState)throw new Error("Overlays may not be stateful.");!function(e,t,n){for(var i=0,r=n(t);i<e.length&&n(e[i])<=r;)i++;e.splice(i,0,t)}(this.state.overlays,{mode:i,modeSpec:t,opaque:n&&n.opaque,priority:n&&n.priority||0},(function(e){return e.priority})),this.state.modeGen++,hi(this)})),removeOverlay:tr((function(e){for(var t=this.state.overlays,n=0;n<t.length;++n){var i=t[n].modeSpec;if(i==e||"string"==typeof e&&i.name==e)return t.splice(n,1),this.state.modeGen++,void hi(this)}})),indentLine:tr((function(e,t,n){"string"!=typeof t&&"number"!=typeof t&&(t=null==t?this.options.smartIndent?"smart":"prev":t?"add":"subtract"),Qe(this.doc,e)&&Io(this,e,t,n)})),indentSelection:tr((function(e){for(var t=this.doc.sel.ranges,n=-1,i=0;i<t.length;i++){var r=t[i];if(r.empty())r.head.line>n&&(Io(this,r.head.line,e,!0),n=r.head.line,i==this.doc.sel.primIndex&&Ei(this));else{var s=r.from(),o=r.to(),a=Math.max(n,s.line);n=Math.min(this.lastLine(),o.line-(o.ch?0:1))+1;for(var l=a;l<n;++l)Io(this,l,e);var c=this.doc.sel.ranges;0==s.ch&&t.length==c.length&&c[i].from().ch>0&&Yr(this.doc,i,new kr(s,c[i].to()),W)}}})),getTokenAt:function(e,t){return _t(this,e,t)},getLineTokens:function(e,t){return _t(this,et(e),t,!0)},getTokenTypeAt:function(e){e=at(this.doc,e);var t,n=ut(this,Ve(this.doc,e.line)),i=0,r=(n.length-1)/2,s=e.ch;if(0==s)t=n[2];else for(;;){var o=i+r>>1;if((o?n[2*o-1]:0)>=s)r=o;else{if(!(n[2*o+1]<s)){t=n[2*o+2];break}i=o+1}}var a=t?t.indexOf("overlay "):-1;return a<0?t:0==a?null:t.slice(0,a-1)},getModeAt:function(t){var n=this.doc.mode;return n.innerMode?e.innerMode(n,this.getTokenAt(t).state).mode:n},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var i=[];if(!n.hasOwnProperty(t))return i;var r=n[t],s=this.getModeAt(e);if("string"==typeof s[t])r[s[t]]&&i.push(r[s[t]]);else if(s[t])for(var o=0;o<s[t].length;o++){var a=r[s[t][o]];a&&i.push(a)}else s.helperType&&r[s.helperType]?i.push(r[s.helperType]):r[s.name]&&i.push(r[s.name]);for(var l=0;l<r._global.length;l++){var c=r._global[l];c.pred(s,this)&&-1==D(i,c.val)&&i.push(c.val)}return i},getStateAfter:function(e,t){var n=this.doc;return ft(this,(e=ot(n,null==e?n.first+n.size-1:e))+1,t).state},cursorCoords:function(e,t){var n=this.doc.sel.primary();return qn(this,null==e?n.head:"object"==typeof e?at(this.doc,e):e?n.from():n.to(),t||"page")},charCoords:function(e,t){return Vn(this,at(this.doc,e),t||"page")},coordsChar:function(e,t){return Yn(this,(e=Kn(this,e,t||"page")).left,e.top)},lineAtHeight:function(e,t){return e=Kn(this,{top:e,left:0},t||"page").top,Je(this.doc,e+this.display.viewOffset)},heightAtLine:function(e,t,n){var i,r=!1;if("number"==typeof e){var s=this.doc.first+this.doc.size-1;e<this.doc.first?e=this.doc.first:e>s&&(e=s,r=!0),i=Ve(this.doc,e)}else i=e;return jn(this,i,{top:0,left:0},t||"page",n||r).top+(r?this.doc.height-Ut(i):0)},defaultTextHeight:function(){return ii(this.display)},defaultCharWidth:function(){return ri(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,n,i,r){var s,o,a,l=this.display,c=(e=qn(this,at(this.doc,e))).bottom,d=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),l.sizer.appendChild(t),"over"==i)c=e.top;else if("above"==i||"near"==i){var h=Math.max(l.wrapper.clientHeight,this.doc.height),u=Math.max(l.sizer.clientWidth,l.lineSpace.clientWidth);("above"==i||e.bottom+t.offsetHeight>h)&&e.top>t.offsetHeight?c=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=h&&(c=e.bottom),d+t.offsetWidth>u&&(d=u-t.offsetWidth)}t.style.top=c+"px",t.style.left=t.style.right="","right"==r?(d=l.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==r?d=0:"middle"==r&&(d=(l.sizer.clientWidth-t.offsetWidth)/2),t.style.left=d+"px"),n&&(s=this,o={left:d,top:c,right:d+t.offsetWidth,bottom:c+t.offsetHeight},null!=(a=Ii(s,o)).scrollTop&&Bi(s,a.scrollTop),null!=a.scrollLeft&&Oi(s,a.scrollLeft))},triggerOnKeyDown:tr(co),triggerOnKeyPress:tr(uo),triggerOnKeyUp:ho,triggerOnMouseDown:tr(go),execCommand:function(e){if(eo.hasOwnProperty(e))return eo[e].call(null,this)},triggerElectric:tr((function(e){Fo(this,e)})),findPosH:function(e,t,n,i){var r=1;t<0&&(r=-1,t=-t);for(var s=at(this.doc,e),o=0;o<t&&!(s=Ro(this.doc,s,r,n,i)).hitSide;++o);return s},moveH:tr((function(e,t){var n=this;this.extendSelectionsBy((function(i){return n.display.shift||n.doc.extend||i.empty()?Ro(n.doc,i.head,e,t,n.options.rtlMoveVisually):e<0?i.from():i.to()}),j)})),deleteH:tr((function(e,t){var n=this.doc.sel,i=this.doc;n.somethingSelected()?i.replaceSelection("",null,"+delete"):Ys(this,(function(n){var r=Ro(i,n.head,e,t,!1);return e<0?{from:r,to:n.head}:{from:n.head,to:r}}))})),findPosV:function(e,t,n,i){var r=1,s=i;t<0&&(r=-1,t=-t);for(var o=at(this.doc,e),a=0;a<t;++a){var l=qn(this,o,"div");if(null==s?s=l.left:l.left=s,(o=Ho(this,l,r,n)).hitSide)break}return o},moveV:tr((function(e,t){var n=this,i=this.doc,r=[],s=!this.display.shift&&!i.extend&&i.sel.somethingSelected();if(i.extendSelectionsBy((function(o){if(s)return e<0?o.from():o.to();var a=qn(n,o.head,"div");null!=o.goalColumn&&(a.left=o.goalColumn),r.push(a.left);var l=Ho(n,a,e,t);return"page"==t&&o==i.sel.primary()&&Ai(n,Vn(n,l,"div").top-a.top),l}),j),r.length)for(var o=0;o<i.sel.ranges.length;o++)i.sel.ranges[o].goalColumn=r[o]})),findWordAt:function(e){var t=Ve(this.doc,e.line).text,n=e.ch,i=e.ch;if(t){var r=this.getHelper(e,"wordChars");"before"!=e.sticky&&i!=t.length||!n?++i:--n;for(var s=t.charAt(n),o=ee(s,r)?function(e){return ee(e,r)}:/\s/.test(s)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!ee(e)};n>0&&o(t.charAt(n-1));)--n;for(;i<t.length&&o(t.charAt(i));)++i}return new kr(et(e.line,n),et(e.line,i))},toggleOverwrite:function(e){null!=e&&e==this.state.overwrite||((this.state.overwrite=!this.state.overwrite)?N(this.display.cursorDiv,"CodeMirror-overwrite"):L(this.display.cursorDiv,"CodeMirror-overwrite"),me(this,"overwriteToggle",this,this.state.overwrite))},hasFocus:function(){return this.display.input.getField()==z()},isReadOnly:function(){return!(!this.options.readOnly&&!this.doc.cantEdit)},scrollTo:tr((function(e,t){zi(this,e,t)})),getScrollInfo:function(){var e=this.display.scroller;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-Ln(this)-this.display.barHeight,width:e.scrollWidth-Ln(this)-this.display.barWidth,clientHeight:Tn(this),clientWidth:Mn(this)}},scrollIntoView:tr((function(e,t){null==e?(e={from:this.doc.sel.primary().head,to:null},null==t&&(t=this.options.cursorScrollMargin)):"number"==typeof e?e={from:et(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?function(e,t){Ni(e),e.curOp.scrollToPos=t}(this,e):Fi(this,e.from,e.to,e.margin)})),setSize:tr((function(e,t){var n=this,i=function(e){return"number"==typeof e||/^\d+$/.test(String(e))?e+"px":e};null!=e&&(this.display.wrapper.style.width=i(e)),null!=t&&(this.display.wrapper.style.height=i(t)),this.options.lineWrapping&&Hn(this);var r=this.display.viewFrom;this.doc.iter(r,this.display.viewTo,(function(e){if(e.widgets)for(var t=0;t<e.widgets.length;t++)if(e.widgets[t].noHScroll){ui(n,r,"widget");break}++r})),this.curOp.forceUpdate=!0,me(this,"refresh",this)})),operation:function(e){return Zi(this,e)},startOperation:function(){return Vi(this)},endOperation:function(){return qi(this)},refresh:tr((function(){var e=this.display.cachedTextHeight;hi(this),this.curOp.forceUpdate=!0,Dn(this),zi(this,this.doc.scrollLeft,this.doc.scrollTop),cr(this.display),(null==e||Math.abs(e-ii(this.display))>.5||this.options.lineWrapping)&&li(this),me(this,"refresh",this)})),swapDoc:tr((function(e){var t=this.doc;return t.cm=null,this.state.selectingText&&this.state.selectingText(),Br(this,e),Dn(this),this.display.input.reset(),zi(this,e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,ln(this,"swapDoc",this,t),t})),phrase:function(e){var t=this.options.phrases;return t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:e},getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},_e(e),e.registerHelper=function(t,i,r){n.hasOwnProperty(t)||(n[t]=e[t]={_global:[]}),n[t][i]=r},e.registerGlobalHelper=function(t,i,r,s){e.registerHelper(t,i,s),n[t]._global.push({pred:r,val:s})}}(Mo);var Vo="iter insert remove copy getEditor constructor".split(" ");for(var qo in As.prototype)As.prototype.hasOwnProperty(qo)&&D(Vo,qo)<0&&(Mo.prototype[qo]=function(e){return function(){return e.apply(this.doc,arguments)}}(As.prototype[qo]));return _e(As),Mo.inputStyles={textarea:Ko,contenteditable:Do},Mo.defineMode=function(e){Mo.defaults.mode||"null"==e||(Mo.defaults.mode=e),Oe.apply(this,arguments)},Mo.defineMIME=function(e,t){$e[e]=t},Mo.defineMode("null",(function(){return{token:function(e){return e.skipToEnd()}}})),Mo.defineMIME("text/plain","null"),Mo.defineExtension=function(e,t){Mo.prototype[e]=t},Mo.defineDocExtension=function(e,t){As.prototype[e]=t},Mo.fromTextArea=function(e,t){if((t=t?O(t):{}).value=e.value,!t.tabindex&&e.tabIndex&&(t.tabindex=e.tabIndex),!t.placeholder&&e.placeholder&&(t.placeholder=e.placeholder),null==t.autofocus){var n=z();t.autofocus=n==e||null!=e.getAttribute("autofocus")&&n==document.body}function i(){e.value=a.getValue()}var r;if(e.form&&(he(e.form,"submit",i),!t.leaveSubmitMethodAlone)){var s=e.form;r=s.submit;try{var o=s.submit=function(){i(),s.submit=r,s.submit(),s.submit=o}}catch(e){}}t.finishInit=function(n){n.save=i,n.getTextArea=function(){return e},n.toTextArea=function(){n.toTextArea=isNaN,i(),e.parentNode.removeChild(n.getWrapperElement()),e.style.display="",e.form&&(fe(e.form,"submit",i),t.leaveSubmitMethodAlone||"function"!=typeof e.form.submit||(e.form.submit=r))}},e.style.display="none";var a=Mo((function(t){return e.parentNode.insertBefore(t,e.nextSibling)}),t);return a},function(e){e.off=fe,e.on=he,e.wheelEventPixels=br,e.Doc=As,e.splitLines=Ee,e.countColumn=R,e.findColumn=K,e.isWordChar=Z,e.Pass=P,e.signal=me,e.Line=Vt,e.changeEnd=Lr,e.scrollbarModel=Ui,e.Pos=et,e.cmpPos=tt,e.modes=Be,e.mimeModes=$e,e.resolveMode=Re,e.getMode=He,e.modeExtensions=De,e.extendMode=Pe,e.copyState=We,e.startState=je,e.innerMode=Ue,e.commands=eo,e.keyMap=Ws,e.keyName=Xs,e.isModifierKey=Vs,e.lookupKey=Ks,e.normalizeKeyMap=js,e.StringStream=Ke,e.SharedTextMarker=Ls,e.TextMarker=Cs,e.LineWidget=xs,e.e_preventDefault=ye,e.e_stopPropagation=be,e.e_stop=we,e.addClass=N,e.contains=E,e.rmClass=L,e.keyNames=Rs}(Mo),Mo.version="5.65.3",Mo})),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../lib/codemirror")):"function"==typeof define&&define.amd?define(["../lib/codemirror"],e):e(CodeMirror)}((function(e){"use strict";var t=e.commands,n=e.Pos;function i(e,t){return e.line==t.line&&e.ch==t.ch}var r=[];function s(e){r.push(e),r.length>50&&r.shift()}function o(e){return r[r.length-(e?Math.min(e,1):1)]||""}var a=null;function l(e,t,n,o,l){null==l&&(l=e.getRange(t,n)),"grow"==o&&a&&a.cm==e&&i(t,a.pos)&&e.isClean(a.gen)?function(e){if(!r.length)return s(e);r[r.length-1]+=e}(l):!1!==o&&s(l),e.replaceRange("",t,n,"+delete"),a="grow"==o?{cm:e,pos:t,gen:e.changeGeneration()}:null}function c(e,t,n){return e.findPosH(t,n,"char",!0)}function d(e,t,n){return e.findPosH(t,n,"word",!0)}function h(e,t,n){return e.findPosV(t,n,"line",e.doc.sel.goalColumn)}function u(e,t,n){return e.findPosV(t,n,"page",e.doc.sel.goalColumn)}function f(e,t,i){for(var r=t.line,s=e.getLine(r),o=/\S/.test(i<0?s.slice(0,t.ch):s.slice(t.ch)),a=e.firstLine(),l=e.lastLine();;){if((r+=i)<a||r>l)return e.clipPos(n(r-i,i<0?0:null));if(s=e.getLine(r),/\S/.test(s))o=!0;else if(o)return n(r,0)}}function m(e,t,i){for(var r=t.line,s=t.ch,o=e.getLine(t.line),a=!1;;){var l=o.charAt(s+(i<0?-1:0));if(l){if(a&&/[!?.]/.test(l))return n(r,s+(i>0?1:0));a||(a=/\w/.test(l)),s+=i}else{if(r==(i<0?e.firstLine():e.lastLine()))return n(r,s);if(o=e.getLine(r+i),!/\S/.test(o))return n(r,s);r+=i,s=i<0?o.length:0}}}function p(e,t,r){var s;if(e.findMatchingBracket&&(s=e.findMatchingBracket(t,{strict:!0}))&&s.match&&(s.forward?1:-1)==r)return r>0?n(s.to.line,s.to.ch+1):s.to;for(var o=!0;;o=!1){var a=e.getTokenAt(t),l=n(t.line,r<0?a.start:a.end);if(!(o&&r>0&&a.end==t.ch)&&/\w/.test(a.string))return l;var c=e.findPosH(l,r,"char");if(i(l,c))return t;t=c}}function g(e,t){var n=e.state.emacsPrefix;return n?(S(e),"-"==n?-1:Number(n)):t?null:1}function v(e){var t="string"==typeof e?function(t){t.execCommand(e)}:e;return function(e){var n=g(e);t(e);for(var i=1;i<n;++i)t(e)}}function _(e,t,n,r){var s=g(e);s<0&&(r=-r,s=-s);for(var o=0;o<s;++o){var a=n(e,t,r);if(i(a,t))break;t=a}return t}function y(e,t){var n=function(n){n.extendSelection(_(n,n.getCursor(),e,t))};return n.motion=!0,n}function b(e,t,n,i){for(var r,s=e.listSelections(),o=s.length;o--;)l(e,r=s[o].head,_(e,r,t,n),i)}function x(e,t){if(e.somethingSelected()){for(var n,i=e.listSelections(),r=i.length;r--;)l(e,(n=i[r]).anchor,n.head,t);return!0}}function w(e,t){e.state.emacsPrefix?"-"!=t&&(e.state.emacsPrefix+=t):(e.state.emacsPrefix=t,e.on("keyHandled",C),e.on("inputRead",L))}var k={"Alt-G":!0,"Ctrl-X":!0,"Ctrl-Q":!0,"Ctrl-U":!0};function C(e,t){e.state.emacsPrefixMap||k.hasOwnProperty(t)||S(e)}function S(e){e.state.emacsPrefix=null,e.off("keyHandled",C),e.off("inputRead",L)}function L(e,t){var n=g(e);if(n>1&&"+input"==t.origin){for(var i=t.text.join("\n"),r="",s=1;s<n;++s)r+=i;e.replaceSelection(r)}}function M(e,t){("string"!=typeof t||!/^\d$/.test(t)&&"Ctrl-U"!=t)&&(e.removeKeyMap(z),e.state.emacsPrefixMap=!1,e.off("keyHandled",M),e.off("inputRead",M))}function T(e){e.setExtending(!1),e.setCursor(e.getCursor())}function I(e,t,n){e.openDialog?e.openDialog(function(e){var t=document.createDocumentFragment(),n=document.createElement("input");return n.setAttribute("type","text"),n.style.width="10em",t.appendChild(document.createTextNode(e+": ")),t.appendChild(n),t}(t),n,{bottom:!0}):n(prompt(t,""))}function A(e,t){var n=e.getCursor(),i=e.findPosH(n,1,"word");e.replaceRange(t(e.getRange(n,i)),n,i),e.setCursor(i)}t.setMark=function(e){e.setCursor(e.getCursor()),e.setExtending(!e.getExtending()),e.on("change",(function(){e.setExtending(!1)}))},t.killRegion=function(e){l(e,e.getCursor("start"),e.getCursor("end"),!0)},t.killLineEmacs=v((function(e){var t=e.getCursor(),i=e.clipPos(n(t.line)),r=e.getRange(t,i);/\S/.test(r)||(r+="\n",i=n(t.line+1,0)),l(e,t,i,"grow",r)})),t.killRingSave=function(e){s(e.getSelection()),T(e)},t.yank=function(e){var t=e.getCursor();e.replaceRange(o(g(e)),t,t,"paste"),e.setSelection(t,e.getCursor())},t.yankPop=function(e){e.replaceSelection((r.length>1&&r.pop(),o()),"around","paste")},t.forwardChar=y(c,1),t.backwardChar=y(c,-1),t.deleteChar=function(e){b(e,c,1,!1)},t.deleteForwardChar=function(e){x(e,!1)||b(e,c,1,!1)},t.deleteBackwardChar=function(e){x(e,!1)||b(e,c,-1,!1)},t.forwardWord=y(d,1),t.backwardWord=y(d,-1),t.killWord=function(e){b(e,d,1,"grow")},t.backwardKillWord=function(e){b(e,d,-1,"grow")},t.nextLine=y(h,1),t.previousLine=y(h,-1),t.scrollDownCommand=y(u,-1),t.scrollUpCommand=y(u,1),t.backwardParagraph=y(f,-1),t.forwardParagraph=y(f,1),t.backwardSentence=y(m,-1),t.forwardSentence=y(m,1),t.killSentence=function(e){b(e,m,1,"grow")},t.backwardKillSentence=function(e){l(e,e.getCursor(),m(e,e.getCursor(),1),"grow")},t.killSexp=function(e){b(e,p,1,"grow")},t.backwardKillSexp=function(e){b(e,p,-1,"grow")},t.forwardSexp=y(p,1),t.backwardSexp=y(p,-1),t.markSexp=function(e){var t=e.getCursor();e.setSelection(_(e,t,p,1),t)},t.transposeSexps=function(e){var t=p(e,e.getCursor(),-1),n=p(e,t,1),i=p(e,n,1),r=p(e,i,-1);e.replaceRange(e.getRange(r,i)+e.getRange(n,r)+e.getRange(t,n),t,i)},t.backwardUpList=v((function(e){for(var t=e.getCursor(),i=t.line,r=t.ch,s=[];i>=e.firstLine();){for(var o=e.getLine(i),a=null==r?o.length:r;a>0;){if(")"==(r=o.charAt(--a)))s.push("(");else if("]"==r)s.push("[");else if("}"==r)s.push("{");else if(/[\(\{\[]/.test(r)&&(!s.length||s.pop()!=r))return e.extendSelection(n(i,a))}--i,r=null}})),t.justOneSpace=function(e){for(var t=e.getCursor(),i=t.ch,r=t.ch,s=e.getLine(t.line);i&&/\s/.test(s.charAt(i-1));)--i;for(;r<s.length&&/\s/.test(s.charAt(r));)++r;e.replaceRange(" ",n(t.line,i),n(t.line,r))},t.openLine=v((function(e){e.replaceSelection("\n","start")})),t.transposeCharsRepeatable=v((function(e){e.execCommand("transposeChars")})),t.capitalizeWord=v((function(e){A(e,(function(e){var t=e.search(/\w/);return-1==t?e:e.slice(0,t)+e.charAt(t).toUpperCase()+e.slice(t+1).toLowerCase()}))})),t.upcaseWord=v((function(e){A(e,(function(e){return e.toUpperCase()}))})),t.downcaseWord=v((function(e){A(e,(function(e){return e.toLowerCase()}))})),t.undoRepeatable=v("undo"),t.keyboardQuit=function(e){e.execCommand("clearSearch"),T(e)},t.newline=v((function(e){e.replaceSelection("\n","end")})),t.gotoLine=function(e){var t=g(e,!0);if(null!=t&&t>0)return e.setCursor(t-1);I(e,"Goto line",(function(t){var n;t&&!isNaN(n=Number(t))&&n==(0|n)&&n>0&&e.setCursor(n-1)}))},t.indentRigidly=function(e){e.indentSelection(g(e,!0)||e.getOption("indentUnit"))},t.exchangePointAndMark=function(e){e.setSelection(e.getCursor("head"),e.getCursor("anchor"))},t.quotedInsertTab=v("insertTab"),t.universalArgument=function(e){e.state.emacsPrefixMap=!0,e.addKeyMap(z),e.on("keyHandled",M),e.on("inputRead",M)},e.emacs={kill:l,killRegion:x,repeated:v};var E=e.keyMap.emacs=e.normalizeKeyMap({"Ctrl-W":"killRegion","Ctrl-K":"killLineEmacs","Alt-W":"killRingSave","Ctrl-Y":"yank","Alt-Y":"yankPop","Ctrl-Space":"setMark","Ctrl-Shift-2":"setMark","Ctrl-F":"forwardChar","Ctrl-B":"backwardChar",Right:"forwardChar",Left:"backwardChar","Ctrl-D":"deleteChar",Delete:"deleteForwardChar","Ctrl-H":"deleteBackwardChar",Backspace:"deleteBackwardChar","Alt-F":"forwardWord","Alt-B":"backwardWord","Alt-Right":"forwardWord","Alt-Left":"backwardWord","Alt-D":"killWord","Alt-Backspace":"backwardKillWord","Ctrl-N":"nextLine","Ctrl-P":"previousLine",Down:"nextLine",Up:"previousLine","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd",End:"goLineEnd",Home:"goLineStart","Alt-V":"scrollDownCommand","Ctrl-V":"scrollUpCommand",PageUp:"scrollDownCommand",PageDown:"scrollUpCommand","Ctrl-Up":"backwardParagraph","Ctrl-Down":"forwardParagraph","Alt-{":"backwardParagraph","Alt-}":"forwardParagraph","Alt-A":"backwardSentence","Alt-E":"forwardSentence","Alt-K":"killSentence","Ctrl-X Delete":"backwardKillSentence","Ctrl-Alt-K":"killSexp","Ctrl-Alt-Backspace":"backwardKillSexp","Ctrl-Alt-F":"forwardSexp","Ctrl-Alt-B":"backwardSexp","Shift-Ctrl-Alt-2":"markSexp","Ctrl-Alt-T":"transposeSexps","Ctrl-Alt-U":"backwardUpList","Alt-Space":"justOneSpace","Ctrl-O":"openLine","Ctrl-T":"transposeCharsRepeatable","Alt-C":"capitalizeWord","Alt-U":"upcaseWord","Alt-L":"downcaseWord","Alt-;":"toggleComment","Ctrl-/":"undoRepeatable","Shift-Ctrl--":"undoRepeatable","Ctrl-Z":"undoRepeatable","Cmd-Z":"undoRepeatable","Ctrl-X U":"undoRepeatable","Shift-Ctrl-Z":"redo","Shift-Alt-,":"goDocStart","Shift-Alt-.":"goDocEnd","Ctrl-S":"findPersistentNext","Ctrl-R":"findPersistentPrev","Ctrl-G":"keyboardQuit","Shift-Alt-5":"replace","Alt-/":"autocomplete",Enter:"newlineAndIndent","Ctrl-J":"newline",Tab:"indentAuto","Alt-G G":"gotoLine","Ctrl-X Tab":"indentRigidly","Ctrl-X Ctrl-X":"exchangePointAndMark","Ctrl-X Ctrl-S":"save","Ctrl-X Ctrl-W":"save","Ctrl-X S":"saveAll","Ctrl-X F":"open","Ctrl-X K":"close","Ctrl-X H":"selectAll","Ctrl-Q Tab":"quotedInsertTab","Ctrl-U":"universalArgument",fallthrough:"default"}),z={"Ctrl-G":S};function N(e){z[e]=function(t){w(t,e)},E["Ctrl-"+e]=function(t){w(t,e)},k["Ctrl-"+e]=!0}for(var F=0;F<10;++F)N(String(F));N("-")})),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../lib/codemirror"),require("../addon/search/searchcursor"),require("../addon/edit/matchbrackets")):"function"==typeof define&&define.amd?define(["../lib/codemirror","../addon/search/searchcursor","../addon/edit/matchbrackets"],e):e(CodeMirror)}((function(e){"use strict";var t=e.commands,n=e.Pos;function i(t,i){t.extendSelectionsBy((function(r){return t.display.shift||t.doc.extend||r.empty()?function(t,i,r){if(r<0&&0==i.ch)return t.clipPos(n(i.line-1));var s=t.getLine(i.line);if(r>0&&i.ch>=s.length)return t.clipPos(n(i.line+1,0));for(var o,a="start",l=i.ch,c=l,d=r<0?0:s.length,h=0;c!=d;c+=r,h++){var u=s.charAt(r<0?c-1:c),f="_"!=u&&e.isWordChar(u)?"w":"o";if("w"==f&&u.toUpperCase()==u&&(f="W"),"start"==a)"o"!=f?(a="in",o=f):l=c+r;else if("in"==a&&o!=f){if("w"==o&&"W"==f&&r<0&&c--,"W"==o&&"w"==f&&r>0){if(c==l+1){o="w";continue}c--}break}}return n(i.line,c)}(t.doc,r.head,i):i<0?r.from():r.to()}))}function r(t,i){if(t.isReadOnly())return e.Pass;t.operation((function(){for(var e=t.listSelections().length,r=[],s=-1,o=0;o<e;o++){var a=t.listSelections()[o].head;if(!(a.line<=s)){var l=n(a.line+(i?0:1),0);t.replaceRange("\n",l,null,"+insertLine"),t.indentLine(l.line,null,!0),r.push({head:l,anchor:l}),s=a.line+1}}t.setSelections(r)})),t.execCommand("indentAuto")}function s(t,i){for(var r=i.ch,s=r,o=t.getLine(i.line);r&&e.isWordChar(o.charAt(r-1));)--r;for(;s<o.length&&e.isWordChar(o.charAt(s));)++s;return{from:n(i.line,r),to:n(i.line,s),word:o.slice(r,s)}}function o(e,t){for(var n=e.listSelections(),i=[],r=0;r<n.length;r++){var s=n[r],o=e.findPosV(s.anchor,t,"line",s.anchor.goalColumn),a=e.findPosV(s.head,t,"line",s.head.goalColumn);o.goalColumn=null!=s.anchor.goalColumn?s.anchor.goalColumn:e.cursorCoords(s.anchor,"div").left,a.goalColumn=null!=s.head.goalColumn?s.head.goalColumn:e.cursorCoords(s.head,"div").left;var l={anchor:o,head:a};i.push(s),i.push(l)}e.setSelections(i)}t.goSubwordLeft=function(e){i(e,-1)},t.goSubwordRight=function(e){i(e,1)},t.scrollLineUp=function(e){var t=e.getScrollInfo();if(!e.somethingSelected()){var n=e.lineAtHeight(t.top+t.clientHeight,"local");e.getCursor().line>=n&&e.execCommand("goLineUp")}e.scrollTo(null,t.top-e.defaultTextHeight())},t.scrollLineDown=function(e){var t=e.getScrollInfo();if(!e.somethingSelected()){var n=e.lineAtHeight(t.top,"local")+1;e.getCursor().line<=n&&e.execCommand("goLineDown")}e.scrollTo(null,t.top+e.defaultTextHeight())},t.splitSelectionByLine=function(e){for(var t=e.listSelections(),i=[],r=0;r<t.length;r++)for(var s=t[r].from(),o=t[r].to(),a=s.line;a<=o.line;++a)o.line>s.line&&a==o.line&&0==o.ch||i.push({anchor:a==s.line?s:n(a,0),head:a==o.line?o:n(a)});e.setSelections(i,0)},t.singleSelectionTop=function(e){var t=e.listSelections()[0];e.setSelection(t.anchor,t.head,{scroll:!1})},t.selectLine=function(e){for(var t=e.listSelections(),i=[],r=0;r<t.length;r++){var s=t[r];i.push({anchor:n(s.from().line,0),head:n(s.to().line+1,0)})}e.setSelections(i)},t.insertLineAfter=function(e){return r(e,!1)},t.insertLineBefore=function(e){return r(e,!0)},t.selectNextOccurrence=function(t){var i=t.getCursor("from"),r=t.getCursor("to"),o=t.state.sublimeFindFullWord==t.doc.sel;if(0==e.cmpPos(i,r)){var a=s(t,i);if(!a.word)return;t.setSelection(a.from,a.to),o=!0}else{var l=t.getRange(i,r),c=o?new RegExp("\\b"+l+"\\b"):l,d=t.getSearchCursor(c,r),h=d.findNext();if(h||(h=(d=t.getSearchCursor(c,n(t.firstLine(),0))).findNext()),!h||function(t,n,i){for(var r=0;r<t.length;r++)if(0==e.cmpPos(t[r].from(),n)&&0==e.cmpPos(t[r].to(),i))return!0;return!1}(t.listSelections(),d.from(),d.to()))return;t.addSelection(d.from(),d.to())}o&&(t.state.sublimeFindFullWord=t.doc.sel)},t.skipAndSelectNextOccurrence=function(n){var i=n.getCursor("anchor"),r=n.getCursor("head");t.selectNextOccurrence(n),0!=e.cmpPos(i,r)&&n.doc.setSelections(n.doc.listSelections().filter((function(e){return e.anchor!=i||e.head!=r})))},t.addCursorToPrevLine=function(e){o(e,-1)},t.addCursorToNextLine=function(e){o(e,1)};var a="(){}[]";function l(t){for(var i=t.listSelections(),r=[],s=0;s<i.length;s++){var o=i[s],l=o.head,c=t.scanForBracket(l,-1);if(!c)return!1;for(;;){var d=t.scanForBracket(l,1);if(!d)return!1;if(d.ch==a.charAt(a.indexOf(c.ch)+1)){var h=n(c.pos.line,c.pos.ch+1);if(0!=e.cmpPos(h,o.from())||0!=e.cmpPos(d.pos,o.to())){r.push({anchor:h,head:d.pos});break}if(!(c=t.scanForBracket(c.pos,-1)))return!1}l=n(d.pos.line,d.pos.ch+1)}}return t.setSelections(r),!0}function c(e){return e?/\bpunctuation\b/.test(e)?e:void 0:null}function d(t,i,r){if(t.isReadOnly())return e.Pass;for(var s,o=t.listSelections(),a=[],l=0;l<o.length;l++){var c=o[l];if(!c.empty()){for(var d=c.from().line,h=c.to().line;l<o.length-1&&o[l+1].from().line==h;)h=o[++l].to().line;o[l].to().ch||h--,a.push(d,h)}}a.length?s=!0:a.push(t.firstLine(),t.lastLine()),t.operation((function(){for(var e=[],o=0;o<a.length;o+=2){var l=a[o],c=a[o+1],d=n(l,0),h=n(c),u=t.getRange(d,h,!1);i?u.sort((function(e,t){return e<t?-r:e==t?0:r})):u.sort((function(e,t){var n=e.toUpperCase(),i=t.toUpperCase();return n!=i&&(e=n,t=i),e<t?-r:e==t?0:r})),t.replaceRange(u,d,h),s&&e.push({anchor:d,head:n(c+1,0)})}s&&t.setSelections(e,0)}))}function h(t,n){t.operation((function(){for(var i=t.listSelections(),r=[],o=[],a=0;a<i.length;a++){(c=i[a]).empty()?(r.push(a),o.push("")):o.push(n(t.getRange(c.from(),c.to())))}t.replaceSelections(o,"around","case");var l;for(a=r.length-1;a>=0;a--){var c=i[r[a]];if(!(l&&e.cmpPos(c.head,l)>0)){var d=s(t,c.head);l=d.from,t.replaceRange(n(d.word),d.from,d.to)}}}))}function u(t){var n=t.getCursor("from"),i=t.getCursor("to");if(0==e.cmpPos(n,i)){var r=s(t,n);if(!r.word)return;n=r.from,i=r.to}return{from:n,to:i,query:t.getRange(n,i),word:r}}function f(e,t){var i=u(e);if(i){var r=i.query,s=e.getSearchCursor(r,t?i.to:i.from);(t?s.findNext():s.findPrevious())?e.setSelection(s.from(),s.to()):(s=e.getSearchCursor(r,t?n(e.firstLine(),0):e.clipPos(n(e.lastLine()))),(t?s.findNext():s.findPrevious())?e.setSelection(s.from(),s.to()):i.word&&e.setSelection(i.from,i.to))}}t.selectScope=function(e){l(e)||e.execCommand("selectAll")},t.selectBetweenBrackets=function(t){if(!l(t))return e.Pass},t.goToBracket=function(t){t.extendSelectionsBy((function(i){var r=t.scanForBracket(i.head,1,c(t.getTokenTypeAt(i.head)));if(r&&0!=e.cmpPos(r.pos,i.head))return r.pos;var s=t.scanForBracket(i.head,-1,c(t.getTokenTypeAt(n(i.head.line,i.head.ch+1))));return s&&n(s.pos.line,s.pos.ch+1)||i.head}))},t.swapLineUp=function(t){if(t.isReadOnly())return e.Pass;for(var i=t.listSelections(),r=[],s=t.firstLine()-1,o=[],a=0;a<i.length;a++){var l=i[a],c=l.from().line-1,d=l.to().line;o.push({anchor:n(l.anchor.line-1,l.anchor.ch),head:n(l.head.line-1,l.head.ch)}),0!=l.to().ch||l.empty()||--d,c>s?r.push(c,d):r.length&&(r[r.length-1]=d),s=d}t.operation((function(){for(var e=0;e<r.length;e+=2){var i=r[e],s=r[e+1],a=t.getLine(i);t.replaceRange("",n(i,0),n(i+1,0),"+swapLine"),s>t.lastLine()?t.replaceRange("\n"+a,n(t.lastLine()),null,"+swapLine"):t.replaceRange(a+"\n",n(s,0),null,"+swapLine")}t.setSelections(o),t.scrollIntoView()}))},t.swapLineDown=function(t){if(t.isReadOnly())return e.Pass;for(var i=t.listSelections(),r=[],s=t.lastLine()+1,o=i.length-1;o>=0;o--){var a=i[o],l=a.to().line+1,c=a.from().line;0!=a.to().ch||a.empty()||l--,l<s?r.push(l,c):r.length&&(r[r.length-1]=c),s=c}t.operation((function(){for(var e=r.length-2;e>=0;e-=2){var i=r[e],s=r[e+1],o=t.getLine(i);i==t.lastLine()?t.replaceRange("",n(i-1),n(i),"+swapLine"):t.replaceRange("",n(i,0),n(i+1,0),"+swapLine"),t.replaceRange(o+"\n",n(s,0),null,"+swapLine")}t.scrollIntoView()}))},t.toggleCommentIndented=function(e){e.toggleComment({indent:!0})},t.joinLines=function(e){for(var t=e.listSelections(),i=[],r=0;r<t.length;r++){for(var s=t[r],o=s.from(),a=o.line,l=s.to().line;r<t.length-1&&t[r+1].from().line==l;)l=t[++r].to().line;i.push({start:a,end:l,anchor:!s.empty()&&o})}e.operation((function(){for(var t=0,r=[],s=0;s<i.length;s++){for(var o,a=i[s],l=a.anchor&&n(a.anchor.line-t,a.anchor.ch),c=a.start;c<=a.end;c++){var d=c-t;c==a.end&&(o=n(d,e.getLine(d).length+1)),d<e.lastLine()&&(e.replaceRange(" ",n(d),n(d+1,/^\s*/.exec(e.getLine(d+1))[0].length)),++t)}r.push({anchor:l||o,head:o})}e.setSelections(r,0)}))},t.duplicateLine=function(e){e.operation((function(){for(var t=e.listSelections().length,i=0;i<t;i++){var r=e.listSelections()[i];r.empty()?e.replaceRange(e.getLine(r.head.line)+"\n",n(r.head.line,0)):e.replaceRange(e.getRange(r.from(),r.to()),r.from())}e.scrollIntoView()}))},t.sortLines=function(e){d(e,!0,1)},t.reverseSortLines=function(e){d(e,!0,-1)},t.sortLinesInsensitive=function(e){d(e,!1,1)},t.reverseSortLinesInsensitive=function(e){d(e,!1,-1)},t.nextBookmark=function(e){var t=e.state.sublimeBookmarks;if(t)for(;t.length;){var n=t.shift(),i=n.find();if(i)return t.push(n),e.setSelection(i.from,i.to)}},t.prevBookmark=function(e){var t=e.state.sublimeBookmarks;if(t)for(;t.length;){t.unshift(t.pop());var n=t[t.length-1].find();if(n)return e.setSelection(n.from,n.to);t.pop()}},t.toggleBookmark=function(e){for(var t=e.listSelections(),n=e.state.sublimeBookmarks||(e.state.sublimeBookmarks=[]),i=0;i<t.length;i++){for(var r=t[i].from(),s=t[i].to(),o=t[i].empty()?e.findMarksAt(r):e.findMarks(r,s),a=0;a<o.length;a++)if(o[a].sublimeBookmark){o[a].clear();for(var l=0;l<n.length;l++)n[l]==o[a]&&n.splice(l--,1);break}a==o.length&&n.push(e.markText(r,s,{sublimeBookmark:!0,clearWhenEmpty:!1}))}},t.clearBookmarks=function(e){var t=e.state.sublimeBookmarks;if(t)for(var n=0;n<t.length;n++)t[n].clear();t.length=0},t.selectBookmarks=function(e){var t=e.state.sublimeBookmarks,n=[];if(t)for(var i=0;i<t.length;i++){var r=t[i].find();r?n.push({anchor:r.from,head:r.to}):t.splice(i--,0)}n.length&&e.setSelections(n,0)},t.smartBackspace=function(t){if(t.somethingSelected())return e.Pass;t.operation((function(){for(var i=t.listSelections(),r=t.getOption("indentUnit"),s=i.length-1;s>=0;s--){var o=i[s].head,a=t.getRange({line:o.line,ch:0},o),l=e.countColumn(a,null,t.getOption("tabSize")),c=t.findPosH(o,-1,"char",!1);if(a&&!/\S/.test(a)&&l%r==0){var d=new n(o.line,e.findColumn(a,l-r,r));d.ch!=o.ch&&(c=d)}t.replaceRange("",c,o,"+delete")}}))},t.delLineRight=function(e){e.operation((function(){for(var t=e.listSelections(),i=t.length-1;i>=0;i--)e.replaceRange("",t[i].anchor,n(t[i].to().line),"+delete");e.scrollIntoView()}))},t.upcaseAtCursor=function(e){h(e,(function(e){return e.toUpperCase()}))},t.downcaseAtCursor=function(e){h(e,(function(e){return e.toLowerCase()}))},t.setSublimeMark=function(e){e.state.sublimeMark&&e.state.sublimeMark.clear(),e.state.sublimeMark=e.setBookmark(e.getCursor())},t.selectToSublimeMark=function(e){var t=e.state.sublimeMark&&e.state.sublimeMark.find();t&&e.setSelection(e.getCursor(),t)},t.deleteToSublimeMark=function(t){var n=t.state.sublimeMark&&t.state.sublimeMark.find();if(n){var i=t.getCursor(),r=n;if(e.cmpPos(i,r)>0){var s=r;r=i,i=s}t.state.sublimeKilled=t.getRange(i,r),t.replaceRange("",i,r)}},t.swapWithSublimeMark=function(e){var t=e.state.sublimeMark&&e.state.sublimeMark.find();t&&(e.state.sublimeMark.clear(),e.state.sublimeMark=e.setBookmark(e.getCursor()),e.setCursor(t))},t.sublimeYank=function(e){null!=e.state.sublimeKilled&&e.replaceSelection(e.state.sublimeKilled,null,"paste")},t.showInCenter=function(e){var t=e.cursorCoords(null,"local");e.scrollTo(null,(t.top+t.bottom)/2-e.getScrollInfo().clientHeight/2)},t.findUnder=function(e){f(e,!0)},t.findUnderPrevious=function(e){f(e,!1)},t.findAllUnder=function(e){var t=u(e);if(t){for(var n=e.getSearchCursor(t.query),i=[],r=-1;n.findNext();)i.push({anchor:n.from(),head:n.to()}),n.from().line<=t.from.line&&n.from().ch<=t.from.ch&&r++;e.setSelections(i,r)}};var m=e.keyMap;m.macSublime={"Cmd-Left":"goLineStartSmart","Shift-Tab":"indentLess","Shift-Ctrl-K":"deleteLine","Alt-Q":"wrapLines","Ctrl-Left":"goSubwordLeft","Ctrl-Right":"goSubwordRight","Ctrl-Alt-Up":"scrollLineUp","Ctrl-Alt-Down":"scrollLineDown","Cmd-L":"selectLine","Shift-Cmd-L":"splitSelectionByLine",Esc:"singleSelectionTop","Cmd-Enter":"insertLineAfter","Shift-Cmd-Enter":"insertLineBefore","Cmd-D":"selectNextOccurrence","Shift-Cmd-Space":"selectScope","Shift-Cmd-M":"selectBetweenBrackets","Cmd-M":"goToBracket","Cmd-Ctrl-Up":"swapLineUp","Cmd-Ctrl-Down":"swapLineDown","Cmd-/":"toggleCommentIndented","Cmd-J":"joinLines","Shift-Cmd-D":"duplicateLine",F5:"sortLines","Shift-F5":"reverseSortLines","Cmd-F5":"sortLinesInsensitive","Shift-Cmd-F5":"reverseSortLinesInsensitive",F2:"nextBookmark","Shift-F2":"prevBookmark","Cmd-F2":"toggleBookmark","Shift-Cmd-F2":"clearBookmarks","Alt-F2":"selectBookmarks",Backspace:"smartBackspace","Cmd-K Cmd-D":"skipAndSelectNextOccurrence","Cmd-K Cmd-K":"delLineRight","Cmd-K Cmd-U":"upcaseAtCursor","Cmd-K Cmd-L":"downcaseAtCursor","Cmd-K Cmd-Space":"setSublimeMark","Cmd-K Cmd-A":"selectToSublimeMark","Cmd-K Cmd-W":"deleteToSublimeMark","Cmd-K Cmd-X":"swapWithSublimeMark","Cmd-K Cmd-Y":"sublimeYank","Cmd-K Cmd-C":"showInCenter","Cmd-K Cmd-G":"clearBookmarks","Cmd-K Cmd-Backspace":"delLineLeft","Cmd-K Cmd-1":"foldAll","Cmd-K Cmd-0":"unfoldAll","Cmd-K Cmd-J":"unfoldAll","Ctrl-Shift-Up":"addCursorToPrevLine","Ctrl-Shift-Down":"addCursorToNextLine","Cmd-F3":"findUnder","Shift-Cmd-F3":"findUnderPrevious","Alt-F3":"findAllUnder","Shift-Cmd-[":"fold","Shift-Cmd-]":"unfold","Cmd-I":"findIncremental","Shift-Cmd-I":"findIncrementalReverse","Cmd-H":"replace",F3:"findNext","Shift-F3":"findPrev",fallthrough:"macDefault"},e.normalizeKeyMap(m.macSublime),m.pcSublime={"Shift-Tab":"indentLess","Shift-Ctrl-K":"deleteLine","Alt-Q":"wrapLines","Ctrl-T":"transposeChars","Alt-Left":"goSubwordLeft","Alt-Right":"goSubwordRight","Ctrl-Up":"scrollLineUp","Ctrl-Down":"scrollLineDown","Ctrl-L":"selectLine","Shift-Ctrl-L":"splitSelectionByLine",Esc:"singleSelectionTop","Ctrl-Enter":"insertLineAfter","Shift-Ctrl-Enter":"insertLineBefore","Ctrl-D":"selectNextOccurrence","Shift-Ctrl-Space":"selectScope","Shift-Ctrl-M":"selectBetweenBrackets","Ctrl-M":"goToBracket","Shift-Ctrl-Up":"swapLineUp","Shift-Ctrl-Down":"swapLineDown","Ctrl-/":"toggleCommentIndented","Ctrl-J":"joinLines","Shift-Ctrl-D":"duplicateLine",F9:"sortLines","Shift-F9":"reverseSortLines","Ctrl-F9":"sortLinesInsensitive","Shift-Ctrl-F9":"reverseSortLinesInsensitive",F2:"nextBookmark","Shift-F2":"prevBookmark","Ctrl-F2":"toggleBookmark","Shift-Ctrl-F2":"clearBookmarks","Alt-F2":"selectBookmarks",Backspace:"smartBackspace","Ctrl-K Ctrl-D":"skipAndSelectNextOccurrence","Ctrl-K Ctrl-K":"delLineRight","Ctrl-K Ctrl-U":"upcaseAtCursor","Ctrl-K Ctrl-L":"downcaseAtCursor","Ctrl-K Ctrl-Space":"setSublimeMark","Ctrl-K Ctrl-A":"selectToSublimeMark","Ctrl-K Ctrl-W":"deleteToSublimeMark","Ctrl-K Ctrl-X":"swapWithSublimeMark","Ctrl-K Ctrl-Y":"sublimeYank","Ctrl-K Ctrl-C":"showInCenter","Ctrl-K Ctrl-G":"clearBookmarks","Ctrl-K Ctrl-Backspace":"delLineLeft","Ctrl-K Ctrl-1":"foldAll","Ctrl-K Ctrl-0":"unfoldAll","Ctrl-K Ctrl-J":"unfoldAll","Ctrl-Alt-Up":"addCursorToPrevLine","Ctrl-Alt-Down":"addCursorToNextLine","Ctrl-F3":"findUnder","Shift-Ctrl-F3":"findUnderPrevious","Alt-F3":"findAllUnder","Shift-Ctrl-[":"fold","Shift-Ctrl-]":"unfold","Ctrl-I":"findIncremental","Shift-Ctrl-I":"findIncrementalReverse","Ctrl-H":"replace",F3:"findNext","Shift-F3":"findPrev",fallthrough:"pcDefault"},e.normalizeKeyMap(m.pcSublime);var p=m.default==m.macDefault;m.sublime=p?m.macSublime:m.pcSublime})),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../lib/codemirror"),require("../addon/search/searchcursor"),require("../addon/dialog/dialog"),require("../addon/edit/matchbrackets.js")):"function"==typeof define&&define.amd?define(["../lib/codemirror","../addon/search/searchcursor","../addon/dialog/dialog","../addon/edit/matchbrackets"],e):e(CodeMirror)}((function(e){"use strict";var t=e.Pos;function n(e,n){var i=e.state.vim;if(!i||i.insertMode)return n.head;var r=i.sel.head;return r?i.visualBlock&&n.head.line!=r.line?void 0:n.from()!=n.anchor||n.empty()||n.head.line!=r.line||n.head.ch==r.ch?n.head:new t(n.head.line,n.head.ch-1):n.head}var i=[{keys:"<Left>",type:"keyToKey",toKeys:"h"},{keys:"<Right>",type:"keyToKey",toKeys:"l"},{keys:"<Up>",type:"keyToKey",toKeys:"k"},{keys:"<Down>",type:"keyToKey",toKeys:"j"},{keys:"g<Up>",type:"keyToKey",toKeys:"gk"},{keys:"g<Down>",type:"keyToKey",toKeys:"gj"},{keys:"<Space>",type:"keyToKey",toKeys:"l"},{keys:"<BS>",type:"keyToKey",toKeys:"h",context:"normal"},{keys:"<Del>",type:"keyToKey",toKeys:"x",context:"normal"},{keys:"<C-Space>",type:"keyToKey",toKeys:"W"},{keys:"<C-BS>",type:"keyToKey",toKeys:"B",context:"normal"},{keys:"<S-Space>",type:"keyToKey",toKeys:"w"},{keys:"<S-BS>",type:"keyToKey",toKeys:"b",context:"normal"},{keys:"<C-n>",type:"keyToKey",toKeys:"j"},{keys:"<C-p>",type:"keyToKey",toKeys:"k"},{keys:"<C-[>",type:"keyToKey",toKeys:"<Esc>"},{keys:"<C-c>",type:"keyToKey",toKeys:"<Esc>"},{keys:"<C-[>",type:"keyToKey",toKeys:"<Esc>",context:"insert"},{keys:"<C-c>",type:"keyToKey",toKeys:"<Esc>",context:"insert"},{keys:"s",type:"keyToKey",toKeys:"cl",context:"normal"},{keys:"s",type:"keyToKey",toKeys:"c",context:"visual"},{keys:"S",type:"keyToKey",toKeys:"cc",context:"normal"},{keys:"S",type:"keyToKey",toKeys:"VdO",context:"visual"},{keys:"<Home>",type:"keyToKey",toKeys:"0"},{keys:"<End>",type:"keyToKey",toKeys:"$"},{keys:"<PageUp>",type:"keyToKey",toKeys:"<C-b>"},{keys:"<PageDown>",type:"keyToKey",toKeys:"<C-f>"},{keys:"<CR>",type:"keyToKey",toKeys:"j^",context:"normal"},{keys:"<Ins>",type:"keyToKey",toKeys:"i",context:"normal"},{keys:"<Ins>",type:"action",action:"toggleOverwrite",context:"insert"},{keys:"H",type:"motion",motion:"moveToTopLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"M",type:"motion",motion:"moveToMiddleLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"L",type:"motion",motion:"moveToBottomLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"h",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!1}},{keys:"l",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!0}},{keys:"j",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,linewise:!0}},{keys:"k",type:"motion",motion:"moveByLines",motionArgs:{forward:!1,linewise:!0}},{keys:"gj",type:"motion",motion:"moveByDisplayLines",motionArgs:{forward:!0}},{keys:"gk",type:"motion",motion:"moveByDisplayLines",motionArgs:{forward:!1}},{keys:"w",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1}},{keys:"W",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1,bigWord:!0}},{keys:"e",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,inclusive:!0}},{keys:"E",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:"b",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1}},{keys:"B",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1,bigWord:!0}},{keys:"ge",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,inclusive:!0}},{keys:"gE",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:"{",type:"motion",motion:"moveByParagraph",motionArgs:{forward:!1,toJumplist:!0}},{keys:"}",type:"motion",motion:"moveByParagraph",motionArgs:{forward:!0,toJumplist:!0}},{keys:"(",type:"motion",motion:"moveBySentence",motionArgs:{forward:!1}},{keys:")",type:"motion",motion:"moveBySentence",motionArgs:{forward:!0}},{keys:"<C-f>",type:"motion",motion:"moveByPage",motionArgs:{forward:!0}},{keys:"<C-b>",type:"motion",motion:"moveByPage",motionArgs:{forward:!1}},{keys:"<C-d>",type:"motion",motion:"moveByScroll",motionArgs:{forward:!0,explicitRepeat:!0}},{keys:"<C-u>",type:"motion",motion:"moveByScroll",motionArgs:{forward:!1,explicitRepeat:!0}},{keys:"gg",type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0,toJumplist:!0}},{keys:"G",type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!0,explicitRepeat:!0,linewise:!0,toJumplist:!0}},{keys:"g$",type:"motion",motion:"moveToEndOfDisplayLine"},{keys:"g^",type:"motion",motion:"moveToStartOfDisplayLine"},{keys:"g0",type:"motion",motion:"moveToStartOfDisplayLine"},{keys:"0",type:"motion",motion:"moveToStartOfLine"},{keys:"^",type:"motion",motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"+",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,toFirstChar:!0}},{keys:"-",type:"motion",motion:"moveByLines",motionArgs:{forward:!1,toFirstChar:!0}},{keys:"_",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,toFirstChar:!0,repeatOffset:-1}},{keys:"$",type:"motion",motion:"moveToEol",motionArgs:{inclusive:!0}},{keys:"%",type:"motion",motion:"moveToMatchedSymbol",motionArgs:{inclusive:!0,toJumplist:!0}},{keys:"f<character>",type:"motion",motion:"moveToCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:"F<character>",type:"motion",motion:"moveToCharacter",motionArgs:{forward:!1}},{keys:"t<character>",type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:"T<character>",type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!1}},{keys:";",type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!0}},{keys:",",type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!1}},{keys:"'<character>",type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0,linewise:!0}},{keys:"`<character>",type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0}},{keys:"]`",type:"motion",motion:"jumpToMark",motionArgs:{forward:!0}},{keys:"[`",type:"motion",motion:"jumpToMark",motionArgs:{forward:!1}},{keys:"]'",type:"motion",motion:"jumpToMark",motionArgs:{forward:!0,linewise:!0}},{keys:"['",type:"motion",motion:"jumpToMark",motionArgs:{forward:!1,linewise:!0}},{keys:"]p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!0,isEdit:!0,matchIndent:!0}},{keys:"[p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!1,isEdit:!0,matchIndent:!0}},{keys:"]<character>",type:"motion",motion:"moveToSymbol",motionArgs:{forward:!0,toJumplist:!0}},{keys:"[<character>",type:"motion",motion:"moveToSymbol",motionArgs:{forward:!1,toJumplist:!0}},{keys:"|",type:"motion",motion:"moveToColumn"},{keys:"o",type:"motion",motion:"moveToOtherHighlightedEnd",context:"visual"},{keys:"O",type:"motion",motion:"moveToOtherHighlightedEnd",motionArgs:{sameLine:!0},context:"visual"},{keys:"d",type:"operator",operator:"delete"},{keys:"y",type:"operator",operator:"yank"},{keys:"c",type:"operator",operator:"change"},{keys:"=",type:"operator",operator:"indentAuto"},{keys:">",type:"operator",operator:"indent",operatorArgs:{indentRight:!0}},{keys:"<",type:"operator",operator:"indent",operatorArgs:{indentRight:!1}},{keys:"g~",type:"operator",operator:"changeCase"},{keys:"gu",type:"operator",operator:"changeCase",operatorArgs:{toLower:!0},isEdit:!0},{keys:"gU",type:"operator",operator:"changeCase",operatorArgs:{toLower:!1},isEdit:!0},{keys:"n",type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:!0}},{keys:"N",type:"motion",motion:"findNext",motionArgs:{forward:!1,toJumplist:!0}},{keys:"gn",type:"motion",motion:"findAndSelectNextInclusive",motionArgs:{forward:!0}},{keys:"gN",type:"motion",motion:"findAndSelectNextInclusive",motionArgs:{forward:!1}},{keys:"x",type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!0},operatorMotionArgs:{visualLine:!1}},{keys:"X",type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!1},operatorMotionArgs:{visualLine:!0}},{keys:"D",type:"operatorMotion",operator:"delete",motion:"moveToEol",motionArgs:{inclusive:!0},context:"normal"},{keys:"D",type:"operator",operator:"delete",operatorArgs:{linewise:!0},context:"visual"},{keys:"Y",type:"operatorMotion",operator:"yank",motion:"expandToLine",motionArgs:{linewise:!0},context:"normal"},{keys:"Y",type:"operator",operator:"yank",operatorArgs:{linewise:!0},context:"visual"},{keys:"C",type:"operatorMotion",operator:"change",motion:"moveToEol",motionArgs:{inclusive:!0},context:"normal"},{keys:"C",type:"operator",operator:"change",operatorArgs:{linewise:!0},context:"visual"},{keys:"~",type:"operatorMotion",operator:"changeCase",motion:"moveByCharacters",motionArgs:{forward:!0},operatorArgs:{shouldMoveCursor:!0},context:"normal"},{keys:"~",type:"operator",operator:"changeCase",context:"visual"},{keys:"<C-u>",type:"operatorMotion",operator:"delete",motion:"moveToStartOfLine",context:"insert"},{keys:"<C-w>",type:"operatorMotion",operator:"delete",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1},context:"insert"},{keys:"<C-w>",type:"idle",context:"normal"},{keys:"<C-i>",type:"action",action:"jumpListWalk",actionArgs:{forward:!0}},{keys:"<C-o>",type:"action",action:"jumpListWalk",actionArgs:{forward:!1}},{keys:"<C-e>",type:"action",action:"scroll",actionArgs:{forward:!0,linewise:!0}},{keys:"<C-y>",type:"action",action:"scroll",actionArgs:{forward:!1,linewise:!0}},{keys:"a",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"charAfter"},context:"normal"},{keys:"A",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"eol"},context:"normal"},{keys:"A",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"endOfSelectedArea"},context:"visual"},{keys:"i",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"inplace"},context:"normal"},{keys:"gi",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"lastEdit"},context:"normal"},{keys:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"firstNonBlank"},context:"normal"},{keys:"gI",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"bol"},context:"normal"},{keys:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"startOfSelectedArea"},context:"visual"},{keys:"o",type:"action",action:"newLineAndEnterInsertMode",isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!0},context:"normal"},{keys:"O",type:"action",action:"newLineAndEnterInsertMode",isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!1},context:"normal"},{keys:"v",type:"action",action:"toggleVisualMode"},{keys:"V",type:"action",action:"toggleVisualMode",actionArgs:{linewise:!0}},{keys:"<C-v>",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"<C-q>",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"gv",type:"action",action:"reselectLastSelection"},{keys:"J",type:"action",action:"joinLines",isEdit:!0},{keys:"gJ",type:"action",action:"joinLines",actionArgs:{keepSpaces:!0},isEdit:!0},{keys:"p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!0,isEdit:!0}},{keys:"P",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!1,isEdit:!0}},{keys:"r<character>",type:"action",action:"replace",isEdit:!0},{keys:"@<character>",type:"action",action:"replayMacro"},{keys:"q<character>",type:"action",action:"enterMacroRecordMode"},{keys:"R",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{replace:!0},context:"normal"},{keys:"R",type:"operator",operator:"change",operatorArgs:{linewise:!0,fullLine:!0},context:"visual",exitVisualBlock:!0},{keys:"u",type:"action",action:"undo",context:"normal"},{keys:"u",type:"operator",operator:"changeCase",operatorArgs:{toLower:!0},context:"visual",isEdit:!0},{keys:"U",type:"operator",operator:"changeCase",operatorArgs:{toLower:!1},context:"visual",isEdit:!0},{keys:"<C-r>",type:"action",action:"redo"},{keys:"m<character>",type:"action",action:"setMark"},{keys:'"<character>',type:"action",action:"setRegister"},{keys:"zz",type:"action",action:"scrollToCursor",actionArgs:{position:"center"}},{keys:"z.",type:"action",action:"scrollToCursor",actionArgs:{position:"center"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"zt",type:"action",action:"scrollToCursor",actionArgs:{position:"top"}},{keys:"z<CR>",type:"action",action:"scrollToCursor",actionArgs:{position:"top"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"z-",type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"}},{keys:"zb",type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:".",type:"action",action:"repeatLastEdit"},{keys:"<C-a>",type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!0,backtrack:!1}},{keys:"<C-x>",type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!1,backtrack:!1}},{keys:"<C-t>",type:"action",action:"indent",actionArgs:{indentRight:!0},context:"insert"},{keys:"<C-d>",type:"action",action:"indent",actionArgs:{indentRight:!1},context:"insert"},{keys:"a<character>",type:"motion",motion:"textObjectManipulation"},{keys:"i<character>",type:"motion",motion:"textObjectManipulation",motionArgs:{textObjectInner:!0}},{keys:"/",type:"search",searchArgs:{forward:!0,querySrc:"prompt",toJumplist:!0}},{keys:"?",type:"search",searchArgs:{forward:!1,querySrc:"prompt",toJumplist:!0}},{keys:"*",type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor",wholeWordOnly:!0,toJumplist:!0}},{keys:"#",type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor",wholeWordOnly:!0,toJumplist:!0}},{keys:"g*",type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:"g#",type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:":",type:"ex"}],r=i.length,s=[{name:"colorscheme",shortName:"colo"},{name:"map"},{name:"imap",shortName:"im"},{name:"nmap",shortName:"nm"},{name:"vmap",shortName:"vm"},{name:"unmap"},{name:"write",shortName:"w"},{name:"undo",shortName:"u"},{name:"redo",shortName:"red"},{name:"set",shortName:"se"},{name:"setlocal",shortName:"setl"},{name:"setglobal",shortName:"setg"},{name:"sort",shortName:"sor"},{name:"substitute",shortName:"s",possiblyAsync:!0},{name:"nohlsearch",shortName:"noh"},{name:"yank",shortName:"y"},{name:"delmarks",shortName:"delm"},{name:"registers",shortName:"reg",excludeFromCommandHistory:!0},{name:"vglobal",shortName:"v"},{name:"global",shortName:"g"}];e.Vim=function(){function o(t,n){this==e.keyMap.vim&&(t.options.$customCursor=null,e.rmClass(t.getWrapperElement(),"cm-fat-cursor")),n&&n.attach==a||function(t){t.setOption("disableInput",!1),t.off("cursorActivity",et),e.off(t.getInputField(),"paste",h(t)),t.state.vim=null,He&&clearTimeout(He)}(t)}function a(t,i){this==e.keyMap.vim&&(t.curOp&&(t.curOp.selectionChanged=!0),t.options.$customCursor=n,e.addClass(t.getWrapperElement(),"cm-fat-cursor")),i&&i.attach==a||function(t){t.setOption("disableInput",!0),t.setOption("showCursorWhenSelecting",!1),e.signal(t,"vim-mode-change",{mode:"normal"}),t.on("cursorActivity",et),O(t),e.on(t.getInputField(),"paste",h(t))}(t)}function l(t,n){if(n){if(this[t])return this[t];var i=function(e){if("'"==e.charAt(0))return e.charAt(1);var t=e.split(/-(?!$)/),n=t[t.length-1];if(1==t.length&&1==t[0].length)return!1;if(2==t.length&&"Shift"==t[0]&&1==n.length)return!1;for(var i=!1,r=0;r<t.length;r++){var s=t[r];s in c?t[r]=c[s]:i=!0,s in d&&(t[r]=d[s])}if(!i)return!1;C(n)&&(t[t.length-1]=n.toLowerCase());return"<"+t.join("-")+">"}(t);if(!i)return!1;var r=H.findKey(n,i);return"function"==typeof r&&e.signal(n,"vim-keypress",i),r}}e.defineOption("vimMode",!1,(function(t,n,i){n&&"vim"!=t.getOption("keyMap")?t.setOption("keyMap","vim"):!n&&i!=e.Init&&/^vim/.test(t.getOption("keyMap"))&&t.setOption("keyMap","default")}));var c={Shift:"S",Ctrl:"C",Alt:"A",Cmd:"D",Mod:"A",CapsLock:""},d={Enter:"CR",Backspace:"BS",Delete:"Del",Insert:"Ins"};function h(e){var t=e.state.vim;return t.onPasteFn||(t.onPasteFn=function(){t.insertMode||(e.setCursor(Q(e.getCursor(),0,1)),G.enterInsertMode(e,{},t))}),t.onPasteFn}var u=/[\d]/,f=[e.isWordChar,function(t){return t&&!e.isWordChar(t)&&!/\s/.test(t)}],m=[function(e){return/\S/.test(e)}];function p(e,t){for(var n=[],i=e;i<e+t;i++)n.push(String.fromCharCode(i));return n}var g,v=p(65,26),_=p(97,26),y=p(48,10),b=[].concat(v,_,y,["<",">"]),x=[].concat(v,_,y,["-",'"',".",":","_","/"]);try{g=new RegExp("^[\\p{Lu}]$","u")}catch(e){g=/^[A-Z]$/}function w(e,t){return t>=e.firstLine()&&t<=e.lastLine()}function k(e){return/^[a-z]$/.test(e)}function C(e){return g.test(e)}function S(e){return/^\s*$/.test(e)}function L(e){return-1!=".?!".indexOf(e)}function M(e,t){for(var n=0;n<t.length;n++)if(t[n]==e)return!0;return!1}var T={};function I(e,t,n,i,r){if(void 0===t&&!r)throw Error("defaultValue is required unless callback is provided");if(n||(n="string"),T[e]={type:n,defaultValue:t,callback:r},i)for(var s=0;s<i.length;s++)T[i[s]]=T[e];t&&A(e,t)}function A(e,t,n,i){var r=T[e],s=(i=i||{}).scope;if(!r)return new Error("Unknown option: "+e);if("boolean"==r.type){if(t&&!0!==t)return new Error("Invalid argument: "+e+"="+t);!1!==t&&(t=!0)}r.callback?("local"!==s&&r.callback(t,void 0),"global"!==s&&n&&r.callback(t,n)):("local"!==s&&(r.value="boolean"==r.type?!!t:t),"global"!==s&&n&&(n.state.vim.options[e]={value:t}))}function E(e,t,n){var i=T[e],r=(n=n||{}).scope;if(!i)return new Error("Unknown option: "+e);if(i.callback){var s=t&&i.callback(void 0,t);return"global"!==r&&void 0!==s?s:"local"!==r?i.callback():void 0}return((s="global"!==r&&t&&t.state.vim.options[e])||"local"!==r&&i||{}).value}I("filetype",void 0,"string",["ft"],(function(e,t){if(void 0!==t){if(void 0===e)return"null"==(n=t.getOption("mode"))?"":n;var n=""==e?"null":e;t.setOption("mode",n)}}));var z,N,F=function(){var e=100,t=-1,n=0,i=0,r=new Array(e);function s(s,o){(t+=o)>n?t=n:t<i&&(t=i);var a=r[(e+t)%e];if(a&&!a.find()){var l,c=o>0?1:-1,d=s.getCursor();do{if((a=r[(e+(t+=c))%e])&&(l=a.find())&&!ne(d,l))break}while(t<n&&t>i)}return a}return{cachedCursor:void 0,add:function(s,o,a){var l=r[t%e];function c(n){var i=++t%e,o=r[i];o&&o.clear(),r[i]=s.setBookmark(n)}if(l){var d=l.find();d&&!ne(d,o)&&c(o)}else c(o);c(a),n=t,(i=t-e+1)<0&&(i=0)},find:function(e,n){var i=t,r=s(e,n);return t=i,r&&r.find()},move:s}},B=function(e){return e?{changes:e.changes,expectCursorActivityForChange:e.expectCursorActivityForChange}:{changes:[],expectCursorActivityForChange:!1}};function $(){this.latestRegister=void 0,this.isPlaying=!1,this.isRecording=!1,this.replaySearchQueries=[],this.onRecordingDone=void 0,this.lastInsertModeChanges=B()}function O(e){return e.state.vim||(e.state.vim={inputState:new D,lastEditInputState:void 0,lastEditActionCommand:void 0,lastHPos:-1,lastHSPos:-1,lastMotion:null,marks:{},insertMode:!1,insertModeRepeat:void 0,visualMode:!1,visualLine:!1,visualBlock:!1,lastSelection:null,lastPastedText:null,sel:{},options:{}}),e.state.vim}function R(){for(var e in z={searchQuery:null,searchIsReversed:!1,lastSubstituteReplacePart:void 0,jumpList:F(),macroModeState:new $,lastCharacterSearch:{increment:0,forward:!0,selectedCharacter:""},registerController:new U({}),searchHistoryController:new j,exCommandHistoryController:new j},T){var t=T[e];t.value=t.defaultValue}}$.prototype={exitMacroRecordMode:function(){var e=z.macroModeState;e.onRecordingDone&&e.onRecordingDone(),e.onRecordingDone=void 0,e.isRecording=!1},enterMacroRecordMode:function(e,t){var n=z.registerController.getRegister(t);n&&(n.clear(),this.latestRegister=t,e.openDialog&&(this.onRecordingDone=e.openDialog(document.createTextNode("(recording)["+t+"]"),null,{bottom:!0})),this.isRecording=!0)}};var H={buildKeyMap:function(){},getRegisterController:function(){return z.registerController},resetVimGlobalState_:R,getVimGlobalState_:function(){return z},maybeInitVimState_:O,suppressErrorLogging:!1,InsertModeKey:tt,map:function(e,t,n){Ge.map(e,t,n)},unmap:function(e,t){return Ge.unmap(e,t)},noremap:function(e,t,n){function s(e){return e?[e]:["normal","insert","visual"]}for(var o=s(n),a=i.length,l=a-r;l<a&&o.length;l++){var c=i[l];if(!(c.keys!=t||n&&c.context&&c.context!==n||"ex"===c.type.substr(0,2)||"key"===c.type.substr(0,3))){var d={};for(var h in c)d[h]=c[h];d.keys=e,n&&!d.context&&(d.context=n),this._mapCommand(d);var u=s(c.context);o=o.filter((function(e){return-1===u.indexOf(e)}))}}},mapclear:function(e){var t=i.length,n=r,s=i.slice(0,t-n);if(i=i.slice(t-n),e)for(var o=s.length-1;o>=0;o--){var a=s[o];if(e!==a.context)if(a.context)this._mapCommand(a);else{var l=["normal","insert","visual"];for(var c in l)if(l[c]!==e){var d={};for(var h in a)d[h]=a[h];d.context=l[c],this._mapCommand(d)}}}},setOption:A,getOption:E,defineOption:I,defineEx:function(e,t,n){if(t){if(0!==e.indexOf(t))throw new Error('(Vim.defineEx) "'+t+'" is not a prefix of "'+e+'", command not registered')}else t=e;Xe[e]=n,Ge.commandMap_[t]={name:e,shortName:t,type:"api"}},handleKey:function(e,t,n){var i=this.findKey(e,t,n);if("function"==typeof i)return i()},findKey:function(e,t,n){var r,s=O(e);function o(){var i=z.macroModeState;if(i.isRecording){if("q"==t)return i.exitMacroRecordMode(),P(e),!0;"mapping"!=n&&function(e,t){if(e.isPlaying)return;var n=e.latestRegister,i=z.registerController.getRegister(n);i&&i.pushText(t)}(i,t)}}function a(){if("<Esc>"==t){if(s.visualMode)pe(e);else{if(!s.insertMode)return;Ye(e)}return P(e),!0}}return!1===(r=s.insertMode?function(){if(a())return!0;for(var n=s.inputState.keyBuffer=s.inputState.keyBuffer+t,r=1==t.length,o=K.matchCommand(n,i,s.inputState,"insert");n.length>1&&"full"!=o.type;){n=s.inputState.keyBuffer=n.slice(1);var l=K.matchCommand(n,i,s.inputState,"insert");"none"!=l.type&&(o=l)}if("none"==o.type)return P(e),!1;if("partial"==o.type)return N&&window.clearTimeout(N),N=window.setTimeout((function(){s.insertMode&&s.inputState.keyBuffer&&P(e)}),E("insertModeEscKeysTimeout")),!r;if(N&&window.clearTimeout(N),r){for(var c=e.listSelections(),d=0;d<c.length;d++){var h=c[d].head;e.replaceRange("",Q(h,0,-(n.length-1)),h,"+input")}z.macroModeState.lastInsertModeChanges.changes.pop()}return P(e),o.command}():function(){if(o()||a())return!0;var n=s.inputState.keyBuffer=s.inputState.keyBuffer+t;if(/^[1-9]\d*$/.test(n))return!0;if(!(c=/^(\d*)(.*)$/.exec(n)))return P(e),!1;var r=s.visualMode?"visual":"normal",l=c[2]||c[1];s.inputState.operatorShortcut&&s.inputState.operatorShortcut.slice(-1)==l&&(l=s.inputState.operatorShortcut);var c,d=K.matchCommand(l,i,s.inputState,r);return"none"==d.type?(P(e),!1):"partial"==d.type||(s.inputState.keyBuffer="",(c=/^(\d*)(.*)$/.exec(n))[1]&&"0"!=c[1]&&s.inputState.pushRepeatDigit(c[1]),d.command)}())?s.insertMode||1!==t.length?void 0:function(){return!0}:!0===r?function(){return!0}:function(){return e.operation((function(){e.curOp.isVimOp=!0;try{"keyToKey"==r.type?function(n){for(var i;n;)i=/<\w+-.+?>|<\w+>|./.exec(n),t=i[0],n=n.substring(i.index+t.length),H.handleKey(e,t,"mapping")}(r.toKeys):K.processCommand(e,s,r)}catch(t){throw e.state.vim=void 0,O(e),H.suppressErrorLogging||console.log(t),t}return!0}))}},handleEx:function(e,t){Ge.processCommand(e,t)},defineMotion:function(e,t){V[e]=t},defineAction:function(e,t){G[e]=t},defineOperator:function(e,t){X[e]=t},mapCommand:function(e,t,n,i,r){var s={keys:e,type:t};for(var o in s[t]=n,s[t+"Args"]=i,r)s[o]=r[o];Je(s)},_mapCommand:Je,defineRegister:function(e,t){var n=z.registerController.registers;if(!e||1!=e.length)throw Error("Register name must be 1 character");if(n[e])throw Error("Register already defined "+e);n[e]=t,x.push(e)},exitVisualMode:pe,exitInsertMode:Ye};function D(){this.prefixRepeat=[],this.motionRepeat=[],this.operator=null,this.operatorArgs=null,this.motion=null,this.motionArgs=null,this.keyBuffer=[],this.registerName=null}function P(t,n){t.state.vim.inputState=new D,e.signal(t,"vim-command-done",n)}function W(e,t,n){this.clear(),this.keyBuffer=[e||""],this.insertModeChanges=[],this.searchQueries=[],this.linewise=!!t,this.blockwise=!!n}function U(e){this.registers=e,this.unnamedRegister=e['"']=new W,e["."]=new W,e[":"]=new W,e["/"]=new W}function j(){this.historyBuffer=[],this.iterator=0,this.initialPrefix=null}D.prototype.pushRepeatDigit=function(e){this.operator?this.motionRepeat=this.motionRepeat.concat(e):this.prefixRepeat=this.prefixRepeat.concat(e)},D.prototype.getRepeat=function(){var e=0;return(this.prefixRepeat.length>0||this.motionRepeat.length>0)&&(e=1,this.prefixRepeat.length>0&&(e*=parseInt(this.prefixRepeat.join(""),10)),this.motionRepeat.length>0&&(e*=parseInt(this.motionRepeat.join(""),10))),e},W.prototype={setText:function(e,t,n){this.keyBuffer=[e||""],this.linewise=!!t,this.blockwise=!!n},pushText:function(e,t){t&&(this.linewise||this.keyBuffer.push("\n"),this.linewise=!0),this.keyBuffer.push(e)},pushInsertModeChanges:function(e){this.insertModeChanges.push(B(e))},pushSearchQuery:function(e){this.searchQueries.push(e)},clear:function(){this.keyBuffer=[],this.insertModeChanges=[],this.searchQueries=[],this.linewise=!1},toString:function(){return this.keyBuffer.join("")}},U.prototype={pushText:function(e,t,n,i,r){if("_"!==e){i&&"\n"!==n.charAt(n.length-1)&&(n+="\n");var s=this.isValidRegister(e)?this.getRegister(e):null;if(s){C(e)?s.pushText(n,i):s.setText(n,i,r),this.unnamedRegister.setText(s.toString(),i)}else{switch(t){case"yank":this.registers[0]=new W(n,i,r);break;case"delete":case"change":-1==n.indexOf("\n")?this.registers["-"]=new W(n,i):(this.shiftNumericRegisters_(),this.registers[1]=new W(n,i))}this.unnamedRegister.setText(n,i,r)}}},getRegister:function(e){return this.isValidRegister(e)?(e=e.toLowerCase(),this.registers[e]||(this.registers[e]=new W),this.registers[e]):this.unnamedRegister},isValidRegister:function(e){return e&&M(e,x)},shiftNumericRegisters_:function(){for(var e=9;e>=2;e--)this.registers[e]=this.getRegister(""+(e-1))}},j.prototype={nextMatch:function(e,t){var n=this.historyBuffer,i=t?-1:1;null===this.initialPrefix&&(this.initialPrefix=e);for(var r=this.iterator+i;t?r>=0:r<n.length;r+=i)for(var s=n[r],o=0;o<=s.length;o++)if(this.initialPrefix==s.substring(0,o))return this.iterator=r,s;return r>=n.length?(this.iterator=n.length,this.initialPrefix):r<0?e:void 0},pushInput:function(e){var t=this.historyBuffer.indexOf(e);t>-1&&this.historyBuffer.splice(t,1),e.length&&this.historyBuffer.push(e)},reset:function(){this.initialPrefix=null,this.iterator=this.historyBuffer.length}};var K={matchCommand:function(e,t,n,i){var r,s=function(e,t,n,i){for(var r,s=[],o=[],a=0;a<t.length;a++){var l=t[a];"insert"==n&&"insert"!=l.context||l.context&&l.context!=n||i.operator&&"action"==l.type||!(r=Z(e,l.keys))||("partial"==r&&s.push(l),"full"==r&&o.push(l))}return{partial:s.length&&s,full:o.length&&o}}(e,t,i,n);if(!s.full&&!s.partial)return{type:"none"};if(!s.full&&s.partial)return{type:"partial"};for(var o=0;o<s.full.length;o++){var a=s.full[o];r||(r=a)}if("<character>"==r.keys.slice(-11)){var l=function(e){var t=/^.*(<[^>]+>)$/.exec(e),n=t?t[1]:e.slice(-1);if(n.length>1)switch(n){case"<CR>":n="\n";break;case"<Space>":n=" ";break;default:n=""}return n}(e);if(!l)return{type:"none"};n.selectedCharacter=l}return{type:"full",command:r}},processCommand:function(e,t,n){switch(t.inputState.repeatOverride=n.repeatOverride,n.type){case"motion":this.processMotion(e,t,n);break;case"operator":this.processOperator(e,t,n);break;case"operatorMotion":this.processOperatorMotion(e,t,n);break;case"action":this.processAction(e,t,n);break;case"search":this.processSearch(e,t,n);break;case"ex":case"keyToEx":this.processEx(e,t,n)}},processMotion:function(e,t,n){t.inputState.motion=n.motion,t.inputState.motionArgs=J(n.motionArgs),this.evalInput(e,t)},processOperator:function(e,t,n){var i=t.inputState;if(i.operator){if(i.operator==n.operator)return i.motion="expandToLine",i.motionArgs={linewise:!0},void this.evalInput(e,t);P(e)}i.operator=n.operator,i.operatorArgs=J(n.operatorArgs),n.keys.length>1&&(i.operatorShortcut=n.keys),n.exitVisualBlock&&(t.visualBlock=!1,fe(e)),t.visualMode&&this.evalInput(e,t)},processOperatorMotion:function(e,t,n){var i=t.visualMode,r=J(n.operatorMotionArgs);r&&i&&r.visualLine&&(t.visualLine=!0),this.processOperator(e,t,n),i||this.processMotion(e,t,n)},processAction:function(e,t,n){var i=t.inputState,r=i.getRepeat(),s=!!r,o=J(n.actionArgs)||{};i.selectedCharacter&&(o.selectedCharacter=i.selectedCharacter),n.operator&&this.processOperator(e,t,n),n.motion&&this.processMotion(e,t,n),(n.motion||n.operator)&&this.evalInput(e,t),o.repeat=r||1,o.repeatIsExplicit=s,o.registerName=i.registerName,P(e),t.lastMotion=null,n.isEdit&&this.recordLastEdit(t,i,n),G[n.action](e,o,t)},processSearch:function(t,n,i){if(t.getSearchCursor){var r=i.searchArgs.forward,s=i.searchArgs.wholeWordOnly;Ie(t).setReversed(!r);var o=r?"/":"?",a=Ie(t).getQuery(),l=t.getScrollInfo();switch(i.searchArgs.querySrc){case"prompt":var c=z.macroModeState;if(c.isPlaying)f(u=c.replaySearchQueries.shift(),!0,!1);else Oe(t,{onClose:function(e){t.scrollTo(l.left,l.top),f(e,!0,!0);var n=z.macroModeState;n.isRecording&&function(e,t){if(!e.isPlaying){var n=e.latestRegister,i=z.registerController.getRegister(n);i&&i.pushSearchQuery&&i.pushSearchQuery(t)}}(n,e)},prefix:o,desc:"(JavaScript regexp)",onKeyUp:function(n,i,s){var o,a,c,d=e.keyName(n);"Up"==d||"Down"==d?(o="Up"==d,a=n.target?n.target.selectionEnd:0,s(i=z.searchHistoryController.nextMatch(i,o)||""),a&&n.target&&(n.target.selectionEnd=n.target.selectionStart=Math.min(a,n.target.value.length))):"Left"!=d&&"Right"!=d&&"Ctrl"!=d&&"Alt"!=d&&"Shift"!=d&&z.searchHistoryController.reset();try{c=Re(t,i,!0,!0)}catch(n){}c?t.scrollIntoView(Pe(t,!r,c),30):(We(t),t.scrollTo(l.left,l.top))},onKeyDown:function(n,i,r){var s=e.keyName(n);"Esc"==s||"Ctrl-C"==s||"Ctrl-["==s||"Backspace"==s&&""==i?(z.searchHistoryController.pushInput(i),z.searchHistoryController.reset(),Re(t,a),We(t),t.scrollTo(l.left,l.top),e.e_stop(n),P(t),r(),t.focus()):"Up"==s||"Down"==s?e.e_stop(n):"Ctrl-U"==s&&(e.e_stop(n),r(""))}});break;case"wordUnderCursor":var d=ve(t,!1,!0,!1,!0),h=!0;if(d||(d=ve(t,!1,!0,!1,!1),h=!1),!d)return;var u=t.getLine(d.start.line).substring(d.start.ch,d.end.ch);u=h&&s?"\\b"+u+"\\b":u.replace(/([.?*+$\[\]\/\\(){}|\-])/g,"\\$1"),z.jumpList.cachedCursor=t.getCursor(),t.setCursor(d.start),f(u,!0,!1)}}function f(e,r,s){z.searchHistoryController.pushInput(e),z.searchHistoryController.reset();try{Re(t,e,r,s)}catch(n){return $e(t,"Invalid regex: "+e),void P(t)}K.processMotion(t,n,{type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:i.searchArgs.toJumplist}})}},processEx:function(t,n,i){function r(e){z.exCommandHistoryController.pushInput(e),z.exCommandHistoryController.reset(),Ge.processCommand(t,e)}function s(n,i,r){var s,o,a=e.keyName(n);("Esc"==a||"Ctrl-C"==a||"Ctrl-["==a||"Backspace"==a&&""==i)&&(z.exCommandHistoryController.pushInput(i),z.exCommandHistoryController.reset(),e.e_stop(n),P(t),r(),t.focus()),"Up"==a||"Down"==a?(e.e_stop(n),s="Up"==a,o=n.target?n.target.selectionEnd:0,r(i=z.exCommandHistoryController.nextMatch(i,s)||""),o&&n.target&&(n.target.selectionEnd=n.target.selectionStart=Math.min(o,n.target.value.length))):"Ctrl-U"==a?(e.e_stop(n),r("")):"Left"!=a&&"Right"!=a&&"Ctrl"!=a&&"Alt"!=a&&"Shift"!=a&&z.exCommandHistoryController.reset()}"keyToEx"==i.type?Ge.processCommand(t,i.exArgs.input):n.visualMode?Oe(t,{onClose:r,prefix:":",value:"'<,'>",onKeyDown:s,selectValueOnOpen:!1}):Oe(t,{onClose:r,prefix:":",onKeyDown:s})},evalInput:function(e,n){var i,r,s,o=n.inputState,a=o.motion,l=o.motionArgs||{},c=o.operator,d=o.operatorArgs||{},h=o.registerName,u=n.sel,f=te(n.visualMode?Y(e,u.head):e.getCursor("head")),m=te(n.visualMode?Y(e,u.anchor):e.getCursor("anchor")),p=te(f),g=te(m);if(c&&this.recordLastEdit(n,o),(s=void 0!==o.repeatOverride?o.repeatOverride:o.getRepeat())>0&&l.explicitRepeat?l.repeatIsExplicit=!0:(l.noRepeat||!l.explicitRepeat&&0===s)&&(s=1,l.repeatIsExplicit=!1),o.selectedCharacter&&(l.selectedCharacter=d.selectedCharacter=o.selectedCharacter),l.repeat=s,P(e),a){var v=V[a](e,f,l,n,o);if(n.lastMotion=V[a],!v)return;if(l.toJumplist){var _=z.jumpList,y=_.cachedCursor;y?(_e(e,y,v),delete _.cachedCursor):_e(e,f,v)}v instanceof Array?(r=v[0],i=v[1]):i=v,i||(i=te(f)),n.visualMode?(n.visualBlock&&i.ch===1/0||(i=Y(e,i)),r&&(r=Y(e,r)),r=r||g,u.anchor=r,u.head=i,fe(e),Se(e,n,"<",ie(r,i)?r:i),Se(e,n,">",ie(r,i)?i:r)):c||(i=Y(e,i),e.setCursor(i.line,i.ch))}if(c){if(d.lastSel){r=g;var b=d.lastSel,x=Math.abs(b.head.line-b.anchor.line),w=Math.abs(b.head.ch-b.anchor.ch);i=b.visualLine?new t(g.line+x,g.ch):b.visualBlock?new t(g.line+x,g.ch+w):b.head.line==b.anchor.line?new t(g.line,g.ch+w):new t(g.line+x,g.ch),n.visualMode=!0,n.visualLine=b.visualLine,n.visualBlock=b.visualBlock,u=n.sel={anchor:r,head:i},fe(e)}else n.visualMode&&(d.lastSel={anchor:te(u.anchor),head:te(u.head),visualBlock:n.visualBlock,visualLine:n.visualLine});var k,C,L,M,T;if(n.visualMode){if(k=re(u.head,u.anchor),C=se(u.head,u.anchor),L=n.visualLine||d.linewise,T=me(e,{anchor:k,head:C},M=n.visualBlock?"block":L?"line":"char"),L){var I=T.ranges;if("block"==M)for(var A=0;A<I.length;A++)I[A].head.ch=ae(e,I[A].head.line);else"line"==M&&(I[0].head=new t(I[0].head.line+1,0))}}else{if(k=te(r||g),ie(C=te(i||p),k)){var E=k;k=C,C=E}(L=l.linewise||d.linewise)?function(e,t,n){t.ch=0,n.ch=0,n.line++}(0,k,C):l.forward&&function(e,t,n){var i=e.getRange(t,n);if(/\n\s*$/.test(i)){var r=i.split("\n");r.pop();for(var s=r.pop();r.length>0&&s&&S(s);s=r.pop())n.line--,n.ch=0;s?(n.line--,n.ch=ae(e,n.line)):n.ch=0}}(e,k,C),T=me(e,{anchor:k,head:C},M="char",!l.inclusive||L)}e.setSelections(T.ranges,T.primary),n.lastMotion=null,d.repeat=s,d.registerName=h,d.linewise=L;var N=X[c](e,d,T.ranges,g,i);n.visualMode&&pe(e,null!=N),N&&e.setCursor(N)}},recordLastEdit:function(e,t,n){var i=z.macroModeState;i.isPlaying||(e.lastEditInputState=t,e.lastEditActionCommand=n,i.lastInsertModeChanges.changes=[],i.lastInsertModeChanges.expectCursorActivityForChange=!1,i.lastInsertModeChanges.visualBlock=e.visualBlock?e.sel.head.line-e.sel.anchor.line:0)}},V={moveToTopLine:function(e,n,i){var r=je(e).top+i.repeat-1;return new t(r,ge(e.getLine(r)))},moveToMiddleLine:function(e){var n=je(e),i=Math.floor(.5*(n.top+n.bottom));return new t(i,ge(e.getLine(i)))},moveToBottomLine:function(e,n,i){var r=je(e).bottom-i.repeat+1;return new t(r,ge(e.getLine(r)))},expandToLine:function(e,n,i){return new t(n.line+i.repeat-1,1/0)},findNext:function(e,t,n){var i=Ie(e),r=i.getQuery();if(r){var s=!n.forward;return s=i.isReversed()?!s:s,De(e,r),Pe(e,s,r,n.repeat)}},findAndSelectNextInclusive:function(n,i,r,s,o){var a=Ie(n),l=a.getQuery();if(l){var c=!r.forward,d=function(e,n,i,r,s){void 0===r&&(r=1);return e.operation((function(){var o=e.getCursor(),a=e.getSearchCursor(i,o),l=a.find(!n);!s.visualMode&&l&&ne(a.from(),o)&&a.find(!n);for(var c=0;c<r;c++)if(!(l=a.find(n))&&!(a=e.getSearchCursor(i,n?new t(e.lastLine()):new t(e.firstLine(),0))).find(n))return;return[a.from(),a.to()]}))}(n,c=a.isReversed()?!c:c,l,r.repeat,s);if(d){if(o.operator)return d;var h=d[0],u=new t(d[1].line,d[1].ch-1);if(s.visualMode){(s.visualLine||s.visualBlock)&&(s.visualLine=!1,s.visualBlock=!1,e.signal(n,"vim-mode-change",{mode:"visual",subMode:""}));var f=s.sel.anchor;if(f)return a.isReversed()?r.forward?[f,h]:[f,u]:r.forward?[f,u]:[f,h]}else s.visualMode=!0,s.visualLine=!1,s.visualBlock=!1,e.signal(n,"vim-mode-change",{mode:"visual",subMode:""});return c?[u,h]:[h,u]}}},goToMark:function(e,t,n,i){var r=Ke(e,i,n.selectedCharacter);return r?n.linewise?{line:r.line,ch:ge(e.getLine(r.line))}:r:null},moveToOtherHighlightedEnd:function(e,n,i,r){if(r.visualBlock&&i.sameLine){var s=r.sel;return[Y(e,new t(s.anchor.line,s.head.ch)),Y(e,new t(s.head.line,s.anchor.ch))]}return[r.sel.head,r.sel.anchor]},jumpToMark:function(e,n,i,r){for(var s=n,o=0;o<i.repeat;o++){var a=s;for(var l in r.marks)if(k(l)){var c=r.marks[l].find();if(!((i.forward?ie(c,a):ie(a,c))||i.linewise&&c.line==a.line)){var d=ne(a,s),h=i.forward?oe(a,c,s):oe(s,c,a);(d||h)&&(s=c)}}}return i.linewise&&(s=new t(s.line,ge(e.getLine(s.line)))),s},moveByCharacters:function(e,n,i){var r=n,s=i.repeat,o=i.forward?r.ch+s:r.ch-s;return new t(r.line,o)},moveByLines:function(e,n,i,r){var s=n,o=s.ch;switch(r.lastMotion){case this.moveByLines:case this.moveByDisplayLines:case this.moveByScroll:case this.moveToColumn:case this.moveToEol:o=r.lastHPos;break;default:r.lastHPos=o}var a=i.repeat+(i.repeatOffset||0),l=i.forward?s.line+a:s.line-a,c=e.firstLine(),d=e.lastLine(),h=e.findPosV(s,i.forward?a:-a,"line",r.lastHSPos);return(i.forward?h.line>l:h.line<l)&&(l=h.line,o=h.ch),l<c&&s.line==c?this.moveToStartOfLine(e,n,i,r):l>d&&s.line==d?ke(e,n,i,r,!0):(i.toFirstChar&&(o=ge(e.getLine(l)),r.lastHPos=o),r.lastHSPos=e.charCoords(new t(l,o),"div").left,new t(l,o))},moveByDisplayLines:function(e,n,i,r){var s=n;switch(r.lastMotion){case this.moveByDisplayLines:case this.moveByScroll:case this.moveByLines:case this.moveToColumn:case this.moveToEol:break;default:r.lastHSPos=e.charCoords(s,"div").left}var o=i.repeat;if((l=e.findPosV(s,i.forward?o:-o,"line",r.lastHSPos)).hitSide)if(i.forward)var a={top:e.charCoords(l,"div").top+8,left:r.lastHSPos},l=e.coordsChar(a,"div");else{var c=e.charCoords(new t(e.firstLine(),0),"div");c.left=r.lastHSPos,l=e.coordsChar(c,"div")}return r.lastHPos=l.ch,l},moveByPage:function(e,t,n){var i=t,r=n.repeat;return e.findPosV(i,n.forward?r:-r,"page")},moveByParagraph:function(e,t,n){var i=n.forward?1:-1;return Me(e,t,n.repeat,i)},moveBySentence:function(e,n,i){var r=i.forward?1:-1;return function(e,n,i,r){function s(e,t){if(t.pos+t.dir<0||t.pos+t.dir>=t.line.length){if(t.ln+=t.dir,!w(e,t.ln))return t.line=null,t.ln=null,void(t.pos=null);t.line=e.getLine(t.ln),t.pos=t.dir>0?0:t.line.length-1}else t.pos+=t.dir}function o(e,t,n,i){var r=""===(c=e.getLine(t)),o={line:c,ln:t,pos:n,dir:i},a={ln:o.ln,pos:o.pos},l=""===o.line;for(s(e,o);null!==o.line;){if(a.ln=o.ln,a.pos=o.pos,""===o.line&&!l)return{ln:o.ln,pos:o.pos};if(r&&""!==o.line&&!S(o.line[o.pos]))return{ln:o.ln,pos:o.pos};!L(o.line[o.pos])||r||o.pos!==o.line.length-1&&!S(o.line[o.pos+1])||(r=!0),s(e,o)}var c=e.getLine(a.ln);a.pos=0;for(var d=c.length-1;d>=0;--d)if(!S(c[d])){a.pos=d;break}return a}function a(e,t,n,i){var r={line:l=e.getLine(t),ln:t,pos:n,dir:i},o={ln:r.ln,pos:null},a=""===r.line;for(s(e,r);null!==r.line;){if(""===r.line&&!a)return null!==o.pos?o:{ln:r.ln,pos:r.pos};if(L(r.line[r.pos])&&null!==o.pos&&(r.ln!==o.ln||r.pos+1!==o.pos))return o;""===r.line||S(r.line[r.pos])||(a=!1,o={ln:r.ln,pos:r.pos}),s(e,r)}var l=e.getLine(o.ln);o.pos=0;for(var c=0;c<l.length;++c)if(!S(l[c])){o.pos=c;break}return o}var l={ln:n.line,pos:n.ch};for(;i>0;)l=r<0?a(e,l.ln,l.pos,r):o(e,l.ln,l.pos,r),i--;return new t(l.ln,l.pos)}(e,n,i.repeat,r)},moveByScroll:function(e,t,n,i){var r=e.getScrollInfo(),s=null,o=n.repeat;o||(o=r.clientHeight/(2*e.defaultTextHeight()));var a=e.charCoords(t,"local");if(n.repeat=o,!(s=V.moveByDisplayLines(e,t,n,i)))return null;var l=e.charCoords(s,"local");return e.scrollTo(null,r.top+l.top-a.top),s},moveByWords:function(e,n,i){return function(e,n,i,r,s,o){var a=te(n),l=[];(r&&!s||!r&&s)&&i++;for(var c=!(r&&s),d=0;d<i;d++){var h=we(e,n,r,o,c);if(!h){var u=ae(e,e.lastLine());l.push(r?{line:e.lastLine(),from:u,to:u}:{line:0,from:0,to:0});break}l.push(h),n=new t(h.line,r?h.to-1:h.from)}var f=l.length!=i,m=l[0],p=l.pop();return r&&!s?(f||m.from==a.ch&&m.line==a.line||(p=l.pop()),new t(p.line,p.from)):r&&s?new t(p.line,p.to-1):!r&&s?(f||m.to==a.ch&&m.line==a.line||(p=l.pop()),new t(p.line,p.to)):new t(p.line,p.from)}(e,n,i.repeat,!!i.forward,!!i.wordEnd,!!i.bigWord)},moveTillCharacter:function(e,t,n){var i=Ce(e,n.repeat,n.forward,n.selectedCharacter),r=n.forward?-1:1;return ye(r,n),i?(i.ch+=r,i):null},moveToCharacter:function(e,t,n){var i=n.repeat;return ye(0,n),Ce(e,i,n.forward,n.selectedCharacter)||t},moveToSymbol:function(e,n,i){return function(e,n,i,r){var s=te(e.getCursor()),o=i?1:-1,a=i?e.lineCount():-1,l=s.ch,c=s.line,d=e.getLine(c),h={lineText:d,nextCh:d.charAt(l),lastCh:null,index:l,symb:r,reverseSymb:(i?{")":"(","}":"{"}:{"(":")","{":"}"})[r],forward:i,depth:0,curMoveThrough:!1},u=be[r];if(!u)return s;var f=xe[u].init,m=xe[u].isComplete;f&&f(h);for(;c!==a&&n;){if(h.index+=o,h.nextCh=h.lineText.charAt(h.index),!h.nextCh){if(c+=o,h.lineText=e.getLine(c)||"",o>0)h.index=0;else{var p=h.lineText.length;h.index=p>0?p-1:0}h.nextCh=h.lineText.charAt(h.index)}m(h)&&(s.line=c,s.ch=h.index,n--)}if(h.nextCh||h.curMoveThrough)return new t(c,h.index);return s}(e,i.repeat,i.forward,i.selectedCharacter)||n},moveToColumn:function(e,n,i,r){var s=i.repeat;return r.lastHPos=s-1,r.lastHSPos=e.charCoords(n,"div").left,function(e,n){var i=e.getCursor().line;return Y(e,new t(i,n-1))}(e,s)},moveToEol:function(e,t,n,i){return ke(e,t,n,i,!1)},moveToFirstNonWhiteSpaceCharacter:function(e,n){var i=n;return new t(i.line,ge(e.getLine(i.line)))},moveToMatchedSymbol:function(e,n){for(var i,r=n,s=r.line,o=r.ch,a=e.getLine(s);o<a.length;o++)if((i=a.charAt(o))&&-1!="()[]{}".indexOf(i)){var l=e.getTokenTypeAt(new t(s,o+1));if("string"!==l&&"comment"!==l)break}if(o<a.length){var c="<"===o||">"===o?/[(){}[\]<>]/:/[(){}[\]]/;return e.findMatchingBracket(new t(s,o),{bracketRegex:c}).to}return r},moveToStartOfLine:function(e,n){return new t(n.line,0)},moveToLineOrEdgeOfDocument:function(e,n,i){var r=i.forward?e.lastLine():e.firstLine();return i.repeatIsExplicit&&(r=i.repeat-e.getOption("firstLineNumber")),new t(r,ge(e.getLine(r)))},moveToStartOfDisplayLine:function(e){return e.execCommand("goLineLeft"),e.getCursor()},moveToEndOfDisplayLine:function(e){e.execCommand("goLineRight");var t=e.getCursor();return"before"==t.sticky&&t.ch--,t},textObjectManipulation:function(n,i,r,s){var o=r.selectedCharacter;"b"==o?o="(":"B"==o&&(o="{");var a,l=!r.textObjectInner;if({"(":")",")":"(","{":"}","}":"{","[":"]","]":"[","<":">",">":"<"}[o])a=function(e,n,i,r){var s,o,a=n,l={"(":/[()]/,")":/[()]/,"[":/[[\]]/,"]":/[[\]]/,"{":/[{}]/,"}":/[{}]/,"<":/[<>]/,">":/[<>]/}[i],c={"(":"(",")":"(","[":"[","]":"[","{":"{","}":"{","<":"<",">":"<"}[i],d=e.getLine(a.line).charAt(a.ch)===c?1:0;if(s=e.scanForBracket(new t(a.line,a.ch+d),-1,void 0,{bracketRegex:l}),o=e.scanForBracket(new t(a.line,a.ch+d),1,void 0,{bracketRegex:l}),!s||!o)return{start:a,end:a};if(s=s.pos,o=o.pos,s.line==o.line&&s.ch>o.ch||s.line>o.line){var h=s;s=o,o=h}r?o.ch+=1:s.ch+=1;return{start:s,end:o}}(n,i,o,l);else if({"'":!0,'"':!0,"`":!0}[o])a=function(e,n,i,r){var s,o,a,l,c=te(n),d=e.getLine(c.line).split(""),h=d.indexOf(i);c.ch<h?c.ch=h:h<c.ch&&d[c.ch]==i&&(o=c.ch,--c.ch);if(d[c.ch]!=i||o)for(a=c.ch;a>-1&&!s;a--)d[a]==i&&(s=a+1);else s=c.ch+1;if(s&&!o)for(a=s,l=d.length;a<l&&!o;a++)d[a]==i&&(o=a);if(!s||!o)return{start:c,end:c};r&&(--s,++o);return{start:new t(c.line,s),end:new t(c.line,o)}}(n,i,o,l);else if("W"===o)a=ve(n,l,!0,!0);else if("w"===o)a=ve(n,l,!0,!1);else if("p"===o)if(a=Me(n,i,r.repeat,0,l),r.linewise=!0,s.visualMode)s.visualLine||(s.visualLine=!0);else{var c=s.inputState.operatorArgs;c&&(c.linewise=!0),a.end.line--}else{if("t"!==o)return null;a=function(t,n,i){var r=n;if(!e.findMatchingTag||!e.findEnclosingTag)return{start:r,end:r};var s=e.findMatchingTag(t,n)||e.findEnclosingTag(t,n);if(!s||!s.open||!s.close)return{start:r,end:r};if(i)return{start:s.open.from,end:s.close.to};return{start:s.open.to,end:s.close.from}}(n,i,l)}return n.state.vim.visualMode?function(e,n,i){var r,s=e.state.vim.sel,o=s.head,a=s.anchor;ie(i,n)&&(r=i,i=n,n=r);ie(o,a)?(o=re(n,o),a=se(a,i)):(a=re(n,a),-1==(o=Q(o=se(o,i),0,-1)).ch&&o.line!=e.firstLine()&&(o=new t(o.line-1,ae(e,o.line-1))));return[a,o]}(n,a.start,a.end):[a.start,a.end]},repeatLastCharacterSearch:function(e,t,n){var i=z.lastCharacterSearch,r=n.repeat,s=n.forward===i.forward,o=(i.increment?1:0)*(s?-1:1);e.moveH(-o,"char"),n.inclusive=!!s;var a=Ce(e,r,s,i.selectedCharacter);return a?(a.ch+=o,a):(e.moveH(o,"char"),t)}};function q(e,t){for(var n=[],i=0;i<t;i++)n.push(e);return n}var X={change:function(n,i,r){var s,o,a=n.state.vim,l=r[0].anchor,c=r[0].head;if(a.visualMode)if(i.fullLine)c.ch=Number.MAX_VALUE,c.line--,n.setSelection(l,c),o=n.getSelection(),n.replaceSelection(""),s=l;else{o=n.getSelection();var d=q("",r.length);n.replaceSelections(d),s=re(r[0].head,r[0].anchor)}else{o=n.getRange(l,c);var h=a.lastEditInputState||{};if("moveByWords"==h.motion&&!S(o)){var u=/\s+$/.exec(o);u&&h.motionArgs&&h.motionArgs.forward&&(c=Q(c,0,-u[0].length),o=o.slice(0,-u[0].length))}var f=new t(l.line-1,Number.MAX_VALUE),m=n.firstLine()==n.lastLine();c.line>n.lastLine()&&i.linewise&&!m?n.replaceRange("",f,c):n.replaceRange("",l,c),i.linewise&&(m||(n.setCursor(f),e.commands.newlineAndIndent(n)),l.ch=Number.MAX_VALUE),s=l}z.registerController.pushText(i.registerName,"change",o,i.linewise,r.length>1),G.enterInsertMode(n,{head:s},n.state.vim)},delete:function(e,n,i){var r,s,o=e.state.vim;if(o.visualBlock){s=e.getSelection();var a=q("",i.length);e.replaceSelections(a),r=re(i[0].head,i[0].anchor)}else{var l=i[0].anchor,c=i[0].head;n.linewise&&c.line!=e.firstLine()&&l.line==e.lastLine()&&l.line==c.line-1&&(l.line==e.firstLine()?l.ch=0:l=new t(l.line-1,ae(e,l.line-1))),s=e.getRange(l,c),e.replaceRange("",l,c),r=l,n.linewise&&(r=V.moveToFirstNonWhiteSpaceCharacter(e,l))}return z.registerController.pushText(n.registerName,"delete",s,n.linewise,o.visualBlock),Y(e,r)},indent:function(e,t,n){var i=e.state.vim,r=n[0].anchor.line,s=i.visualBlock?n[n.length-1].anchor.line:n[0].head.line,o=i.visualMode?t.repeat:1;t.linewise&&s--;for(var a=r;a<=s;a++)for(var l=0;l<o;l++)e.indentLine(a,t.indentRight);return V.moveToFirstNonWhiteSpaceCharacter(e,n[0].anchor)},indentAuto:function(e,t,n){return e.execCommand("indentAuto"),V.moveToFirstNonWhiteSpaceCharacter(e,n[0].anchor)},changeCase:function(e,t,n,i,r){for(var s=e.getSelections(),o=[],a=t.toLower,l=0;l<s.length;l++){var c=s[l],d="";if(!0===a)d=c.toLowerCase();else if(!1===a)d=c.toUpperCase();else for(var h=0;h<c.length;h++){var u=c.charAt(h);d+=C(u)?u.toLowerCase():u.toUpperCase()}o.push(d)}return e.replaceSelections(o),t.shouldMoveCursor?r:!e.state.vim.visualMode&&t.linewise&&n[0].anchor.line+1==n[0].head.line?V.moveToFirstNonWhiteSpaceCharacter(e,i):t.linewise?i:re(n[0].anchor,n[0].head)},yank:function(e,t,n,i){var r=e.state.vim,s=e.getSelection(),o=r.visualMode?re(r.sel.anchor,r.sel.head,n[0].head,n[0].anchor):i;return z.registerController.pushText(t.registerName,"yank",s,t.linewise,r.visualBlock),o}};var G={jumpListWalk:function(e,t,n){if(!n.visualMode){var i=t.repeat,r=t.forward,s=z.jumpList.move(e,r?i:-i),o=s?s.find():void 0;o=o||e.getCursor(),e.setCursor(o)}},scroll:function(e,t,n){if(!n.visualMode){var i=t.repeat||1,r=e.defaultTextHeight(),s=e.getScrollInfo().top,o=r*i,a=t.forward?s+o:s-o,l=te(e.getCursor()),c=e.charCoords(l,"local");if(t.forward)a>c.top?(l.line+=(a-c.top)/r,l.line=Math.ceil(l.line),e.setCursor(l),c=e.charCoords(l,"local"),e.scrollTo(null,c.top)):e.scrollTo(null,a);else{var d=a+e.getScrollInfo().clientHeight;d<c.bottom?(l.line-=(c.bottom-d)/r,l.line=Math.floor(l.line),e.setCursor(l),c=e.charCoords(l,"local"),e.scrollTo(null,c.bottom-e.getScrollInfo().clientHeight)):e.scrollTo(null,a)}}},scrollToCursor:function(e,n){var i=e.getCursor().line,r=e.charCoords(new t(i,0),"local"),s=e.getScrollInfo().clientHeight,o=r.top,a=r.bottom-o;switch(n.position){case"center":o=o-s/2+a;break;case"bottom":o=o-s+a}e.scrollTo(null,o)},replayMacro:function(e,t,n){var i=t.selectedCharacter,r=t.repeat,s=z.macroModeState;for("@"==i?i=s.latestRegister:s.latestRegister=i;r--;)Qe(e,n,s,i)},enterMacroRecordMode:function(e,t){var n=z.macroModeState,i=t.selectedCharacter;z.registerController.isValidRegister(i)&&n.enterMacroRecordMode(e,i)},toggleOverwrite:function(t){t.state.overwrite?(t.toggleOverwrite(!1),t.setOption("keyMap","vim-insert"),e.signal(t,"vim-mode-change",{mode:"insert"})):(t.toggleOverwrite(!0),t.setOption("keyMap","vim-replace"),e.signal(t,"vim-mode-change",{mode:"replace"}))},enterInsertMode:function(n,i,r){if(!n.getOption("readOnly")){r.insertMode=!0,r.insertModeRepeat=i&&i.repeat||1;var s=i?i.insertAt:null,o=r.sel,a=i.head||n.getCursor("head"),l=n.listSelections().length;if("eol"==s)a=new t(a.line,ae(n,a.line));else if("bol"==s)a=new t(a.line,0);else if("charAfter"==s)a=Q(a,0,1);else if("firstNonBlank"==s)a=V.moveToFirstNonWhiteSpaceCharacter(n,a);else if("startOfSelectedArea"==s){if(!r.visualMode)return;r.visualBlock?(a=new t(Math.min(o.head.line,o.anchor.line),Math.min(o.head.ch,o.anchor.ch)),l=Math.abs(o.head.line-o.anchor.line)+1):a=o.head.line<o.anchor.line?o.head:new t(o.anchor.line,0)}else if("endOfSelectedArea"==s){if(!r.visualMode)return;r.visualBlock?(a=new t(Math.min(o.head.line,o.anchor.line),Math.max(o.head.ch,o.anchor.ch)+1),l=Math.abs(o.head.line-o.anchor.line)+1):a=o.head.line>=o.anchor.line?Q(o.head,0,1):new t(o.anchor.line,0)}else if("inplace"==s){if(r.visualMode)return}else"lastEdit"==s&&(a=Ve(n)||a);n.setOption("disableInput",!1),i&&i.replace?(n.toggleOverwrite(!0),n.setOption("keyMap","vim-replace"),e.signal(n,"vim-mode-change",{mode:"replace"})):(n.toggleOverwrite(!1),n.setOption("keyMap","vim-insert"),e.signal(n,"vim-mode-change",{mode:"insert"})),z.macroModeState.isPlaying||(n.on("change",Ze),e.on(n.getInputField(),"keydown",nt)),r.visualMode&&pe(n),he(n,a,l)}},toggleVisualMode:function(n,i,r){var s,o=i.repeat,a=n.getCursor();r.visualMode?r.visualLine^i.linewise||r.visualBlock^i.blockwise?(r.visualLine=!!i.linewise,r.visualBlock=!!i.blockwise,e.signal(n,"vim-mode-change",{mode:"visual",subMode:r.visualLine?"linewise":r.visualBlock?"blockwise":""}),fe(n)):pe(n):(r.visualMode=!0,r.visualLine=!!i.linewise,r.visualBlock=!!i.blockwise,s=Y(n,new t(a.line,a.ch+o-1)),r.sel={anchor:a,head:s},e.signal(n,"vim-mode-change",{mode:"visual",subMode:r.visualLine?"linewise":r.visualBlock?"blockwise":""}),fe(n),Se(n,r,"<",re(a,s)),Se(n,r,">",se(a,s)))},reselectLastSelection:function(t,n,i){var r=i.lastSelection;if(i.visualMode&&ue(t,i),r){var s=r.anchorMark.find(),o=r.headMark.find();if(!s||!o)return;i.sel={anchor:s,head:o},i.visualMode=!0,i.visualLine=r.visualLine,i.visualBlock=r.visualBlock,fe(t),Se(t,i,"<",re(s,o)),Se(t,i,">",se(s,o)),e.signal(t,"vim-mode-change",{mode:"visual",subMode:i.visualLine?"linewise":i.visualBlock?"blockwise":""})}},joinLines:function(e,n,i){var r,s;if(i.visualMode){if(r=e.getCursor("anchor"),ie(s=e.getCursor("head"),r)){var o=s;s=r,r=o}s.ch=ae(e,s.line)-1}else{var a=Math.max(n.repeat,2);r=e.getCursor(),s=Y(e,new t(r.line+a-1,1/0))}for(var l=0,c=r.line;c<s.line;c++){l=ae(e,r.line);o=new t(r.line+1,ae(e,r.line+1));var d=e.getRange(r,o);d=n.keepSpaces?d.replace(/\n\r?/g,""):d.replace(/\n\s*/g," "),e.replaceRange(d,r,o)}var h=new t(r.line,l);i.visualMode&&pe(e,!1),e.setCursor(h)},newLineAndEnterInsertMode:function(n,i,r){r.insertMode=!0;var s=te(n.getCursor());s.line!==n.firstLine()||i.after?(s.line=i.after?s.line:s.line-1,s.ch=ae(n,s.line),n.setCursor(s),(e.commands.newlineAndIndentContinueComment||e.commands.newlineAndIndent)(n)):(n.replaceRange("\n",new t(n.firstLine(),0)),n.setCursor(n.firstLine(),0));this.enterInsertMode(n,{repeat:i.repeat},r)},paste:function(e,n,i){var r=te(e.getCursor()),s=z.registerController.getRegister(n.registerName);if(f=s.toString()){if(n.matchIndent){var o=e.getOption("tabSize"),a=function(e){var t=e.split("\t").length-1,n=e.split(" ").length-1;return t*o+1*n},l=e.getLine(e.getCursor().line),c=a(l.match(/^\s*/)[0]),d=f.replace(/\n$/,""),h=f!==d,u=a(f.match(/^\s*/)[0]),f=d.replace(/^\s*/gm,(function(t){var n=c+(a(t)-u);if(n<0)return"";if(e.getOption("indentWithTabs")){var i=Math.floor(n/o);return Array(i+1).join("\t")}return Array(n+1).join(" ")}));f+=h?"\n":""}if(n.repeat>1)f=Array(n.repeat+1).join(f);var m,p,g=s.linewise,v=s.blockwise;if(v){f=f.split("\n"),g&&f.pop();for(var _=0;_<f.length;_++)f[_]=""==f[_]?" ":f[_];r.ch+=n.after?1:0,r.ch=Math.min(ae(e,r.line),r.ch)}else g?i.visualMode?f=i.visualLine?f.slice(0,-1):"\n"+f.slice(0,f.length-1)+"\n":n.after?(f="\n"+f.slice(0,f.length-1),r.ch=ae(e,r.line)):r.ch=0:r.ch+=n.after?1:0;if(i.visualMode){var y;i.lastPastedText=f;var b=function(e,n){var i=n.lastSelection,r=function(){var t=e.listSelections(),n=t[0],i=t[t.length-1];return[ie(n.anchor,n.head)?n.anchor:n.head,ie(i.anchor,i.head)?i.head:i.anchor]},s=function(){var n=e.getCursor(),r=e.getCursor(),s=i.visualBlock;if(s){var o=s.width,a=s.height;r=new t(n.line+a,n.ch+o);for(var l=[],c=n.line;c<r.line;c++){var d={anchor:new t(c,n.ch),head:new t(c,r.ch)};l.push(d)}e.setSelections(l)}else{var h=i.anchorMark.find(),u=i.headMark.find(),f=u.line-h.line,m=u.ch-h.ch;r={line:r.line+f,ch:f?r.ch:m+r.ch},i.visualLine&&(n=new t(n.line,0),r=new t(r.line,ae(e,r.line))),e.setSelection(n,r)}return[n,r]};return n.visualMode?r():s()}(e,i),x=b[0],w=b[1],k=e.getSelection(),C=e.listSelections(),S=new Array(C.length).join("1").split("1");i.lastSelection&&(y=i.lastSelection.headMark.find()),z.registerController.unnamedRegister.setText(k),v?(e.replaceSelections(S),w=new t(x.line+f.length-1,x.ch),e.setCursor(x),de(e,w),e.replaceSelections(f),m=x):i.visualBlock?(e.replaceSelections(S),e.setCursor(x),e.replaceRange(f,x,x),m=x):(e.replaceRange(f,x,w),m=e.posFromIndex(e.indexFromPos(x)+f.length-1)),y&&(i.lastSelection.headMark=e.setBookmark(y)),g&&(m.ch=0)}else if(v){e.setCursor(r);for(_=0;_<f.length;_++){var L=r.line+_;L>e.lastLine()&&e.replaceRange("\n",new t(L,0)),ae(e,L)<r.ch&&ce(e,L,r.ch)}e.setCursor(r),de(e,new t(r.line+f.length-1,r.ch)),e.replaceSelections(f),m=r}else e.replaceRange(f,r),g&&n.after?m=new t(r.line+1,ge(e.getLine(r.line+1))):g&&!n.after?m=new t(r.line,ge(e.getLine(r.line))):!g&&n.after?(p=e.indexFromPos(r),m=e.posFromIndex(p+f.length-1)):(p=e.indexFromPos(r),m=e.posFromIndex(p+f.length));i.visualMode&&pe(e,!1),e.setCursor(m)}},undo:function(t,n){t.operation((function(){ee(t,e.commands.undo,n.repeat)(),t.setCursor(t.getCursor("anchor"))}))},redo:function(t,n){ee(t,e.commands.redo,n.repeat)()},setRegister:function(e,t,n){n.inputState.registerName=t.selectedCharacter},setMark:function(e,t,n){Se(e,n,t.selectedCharacter,e.getCursor())},replace:function(n,i,r){var s,o,a=i.selectedCharacter,l=n.getCursor(),c=n.listSelections();if(r.visualMode)l=n.getCursor("start"),o=n.getCursor("end");else{var d=n.getLine(l.line);(s=l.ch+i.repeat)>d.length&&(s=d.length),o=new t(l.line,s)}if("\n"==a)r.visualMode||n.replaceRange("",l,o),(e.commands.newlineAndIndentContinueComment||e.commands.newlineAndIndent)(n);else{var h=n.getRange(l,o);if(h=h.replace(/[^\n]/g,a),r.visualBlock){var u=new Array(n.getOption("tabSize")+1).join(" ");h=(h=n.getSelection()).replace(/\t/g,u).replace(/[^\n]/g,a).split("\n"),n.replaceSelections(h)}else n.replaceRange(h,l,o);r.visualMode?(l=ie(c[0].anchor,c[0].head)?c[0].anchor:c[0].head,n.setCursor(l),pe(n,!1)):n.setCursor(Q(o,0,-1))}},incrementNumberToken:function(e,n){for(var i,r,s,o,a=e.getCursor(),l=e.getLine(a.line),c=/(-?)(?:(0x)([\da-f]+)|(0b|0|)(\d+))/gi;null!==(i=c.exec(l))&&(s=(r=i.index)+i[0].length,!(a.ch<s)););if((n.backtrack||!(s<=a.ch))&&i){var d=i[2]||i[4],h=i[3]||i[5],u=n.increase?1:-1,f={"0b":2,0:8,"":10,"0x":16}[d.toLowerCase()];o=(parseInt(i[1]+h,f)+u*n.repeat).toString(f);var m=d?new Array(h.length-o.length+1+i[1].length).join("0"):"";o="-"===o.charAt(0)?"-"+d+m+o.substr(1):d+m+o;var p=new t(a.line,r),g=new t(a.line,s);e.replaceRange(o,p,g),e.setCursor(new t(a.line,r+o.length-1))}},repeatLastEdit:function(e,t,n){if(n.lastEditInputState){var i=t.repeat;i&&t.repeatIsExplicit?n.lastEditInputState.repeatOverride=i:i=n.lastEditInputState.repeatOverride||i,it(e,n,i,!1)}},indent:function(e,t){e.indentLine(e.getCursor().line,t.indentRight)},exitInsertMode:Ye};function Y(e,n){var i=e.state.vim,r=i.insertMode||i.visualMode,s=Math.min(Math.max(e.firstLine(),n.line),e.lastLine()),o=ae(e,s)-1+!!r,a=Math.min(Math.max(0,n.ch),o);return new t(s,a)}function J(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function Q(e,n,i){return"object"==typeof n&&(i=n.ch,n=n.line),new t(e.line+n,e.ch+i)}function Z(e,t){if("<character>"==t.slice(-11)){var n=t.length-11,i=e.slice(0,n),r=t.slice(0,n);return i==r&&e.length>n?"full":0==r.indexOf(i)&&"partial"}return e==t?"full":0==t.indexOf(e)&&"partial"}function ee(e,t,n){return function(){for(var i=0;i<n;i++)t(e)}}function te(e){return new t(e.line,e.ch)}function ne(e,t){return e.ch==t.ch&&e.line==t.line}function ie(e,t){return e.line<t.line||e.line==t.line&&e.ch<t.ch}function re(e,t){return arguments.length>2&&(t=re.apply(void 0,Array.prototype.slice.call(arguments,1))),ie(e,t)?e:t}function se(e,t){return arguments.length>2&&(t=se.apply(void 0,Array.prototype.slice.call(arguments,1))),ie(e,t)?t:e}function oe(e,t,n){var i=ie(e,t),r=ie(t,n);return i&&r}function ae(e,t){return e.getLine(t).length}function le(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function ce(e,n,i){var r=ae(e,n),s=new Array(i-r+1).join(" ");e.setCursor(new t(n,r)),e.replaceRange(s,e.getCursor())}function de(e,n){var i=[],r=e.listSelections(),s=te(e.clipPos(n)),o=!ne(n,s),a=function(e,t,n){for(var i=0;i<e.length;i++){var r="head"!=n&&ne(e[i].anchor,t),s="anchor"!=n&&ne(e[i].head,t);if(r||s)return i}return-1}(r,e.getCursor("head")),l=ne(r[a].head,r[a].anchor),c=r.length-1,d=c-a>a?c:0,h=r[d].anchor,u=Math.min(h.line,s.line),f=Math.max(h.line,s.line),m=h.ch,p=s.ch,g=r[d].head.ch-m,v=p-m;g>0&&v<=0?(m++,o||p--):g<0&&v>=0?(m--,l||p++):g<0&&-1==v&&(m--,p++);for(var _=u;_<=f;_++){var y={anchor:new t(_,m),head:new t(_,p)};i.push(y)}return e.setSelections(i),n.ch=p,h.ch=m,h}function he(e,t,n){for(var i=[],r=0;r<n;r++){var s=Q(t,r,0);i.push({anchor:s,head:s})}e.setSelections(i,0)}function ue(e,t){var n=t.sel.anchor,i=t.sel.head;t.lastPastedText&&(i=e.posFromIndex(e.indexFromPos(n)+t.lastPastedText.length),t.lastPastedText=null),t.lastSelection={anchorMark:e.setBookmark(n),headMark:e.setBookmark(i),anchor:te(n),head:te(i),visualMode:t.visualMode,visualLine:t.visualLine,visualBlock:t.visualBlock}}function fe(e,t,n){var i=e.state.vim,r=me(e,t=t||i.sel,n=n||i.visualLine?"line":i.visualBlock?"block":"char");e.setSelections(r.ranges,r.primary)}function me(e,n,i,r){var s=te(n.head),o=te(n.anchor);if("char"==i){var a=r||ie(n.head,n.anchor)?0:1,l=ie(n.head,n.anchor)?1:0;return s=Q(n.head,0,a),{ranges:[{anchor:o=Q(n.anchor,0,l),head:s}],primary:0}}if("line"==i){if(ie(n.head,n.anchor))s.ch=0,o.ch=ae(e,o.line);else{o.ch=0;var c=e.lastLine();s.line>c&&(s.line=c),s.ch=ae(e,s.line)}return{ranges:[{anchor:o,head:s}],primary:0}}if("block"==i){var d=Math.min(o.line,s.line),h=o.ch,u=Math.max(o.line,s.line),f=s.ch;h<f?f+=1:h+=1;for(var m=u-d+1,p=s.line==d?0:m-1,g=[],v=0;v<m;v++)g.push({anchor:new t(d+v,h),head:new t(d+v,f)});return{ranges:g,primary:p}}}function pe(t,n){var i=t.state.vim;!1!==n&&t.setCursor(Y(t,i.sel.head)),ue(t,i),i.visualMode=!1,i.visualLine=!1,i.visualBlock=!1,i.insertMode||e.signal(t,"vim-mode-change",{mode:"normal"})}function ge(e){if(!e)return 0;var t=e.search(/\S/);return-1==t?e.length:t}function ve(e,n,i,r,s){for(var o=function(e){var t=e.getCursor("head");return 1==e.getSelection().length&&(t=re(t,e.getCursor("anchor"))),t}(e),a=e.getLine(o.line),l=o.ch,c=s?f[0]:m[0];!c(a.charAt(l));)if(++l>=a.length)return null;r?c=m[0]:(c=f[0])(a.charAt(l))||(c=f[1]);for(var d=l,h=l;c(a.charAt(d))&&d<a.length;)d++;for(;c(a.charAt(h))&&h>=0;)h--;if(h++,n){for(var u=d;/\s/.test(a.charAt(d))&&d<a.length;)d++;if(u==d){for(var p=h;/\s/.test(a.charAt(h-1))&&h>0;)h--;h||(h=p)}}return{start:new t(o.line,h),end:new t(o.line,d)}}function _e(e,t,n){ne(t,n)||z.jumpList.add(e,t,n)}function ye(e,t){z.lastCharacterSearch.increment=e,z.lastCharacterSearch.forward=t.forward,z.lastCharacterSearch.selectedCharacter=t.selectedCharacter}var be={"(":"bracket",")":"bracket","{":"bracket","}":"bracket","[":"section","]":"section","*":"comment","/":"comment",m:"method",M:"method","#":"preprocess"},xe={bracket:{isComplete:function(e){if(e.nextCh===e.symb){if(e.depth++,e.depth>=1)return!0}else e.nextCh===e.reverseSymb&&e.depth--;return!1}},section:{init:function(e){e.curMoveThrough=!0,e.symb=(e.forward?"]":"[")===e.symb?"{":"}"},isComplete:function(e){return 0===e.index&&e.nextCh===e.symb}},comment:{isComplete:function(e){var t="*"===e.lastCh&&"/"===e.nextCh;return e.lastCh=e.nextCh,t}},method:{init:function(e){e.symb="m"===e.symb?"{":"}",e.reverseSymb="{"===e.symb?"}":"{"},isComplete:function(e){return e.nextCh===e.symb}},preprocess:{init:function(e){e.index=0},isComplete:function(e){if("#"===e.nextCh){var t=e.lineText.match(/^#(\w+)/)[1];if("endif"===t){if(e.forward&&0===e.depth)return!0;e.depth++}else if("if"===t){if(!e.forward&&0===e.depth)return!0;e.depth--}if("else"===t&&0===e.depth)return!0}return!1}}};function we(e,t,n,i,r){var s=t.line,o=t.ch,a=e.getLine(s),l=n?1:-1,c=i?m:f;if(r&&""==a){if(s+=l,a=e.getLine(s),!w(e,s))return null;o=n?0:a.length}for(;;){if(r&&""==a)return{from:0,to:0,line:s};for(var d=l>0?a.length:-1,h=d,u=d;o!=d;){for(var p=!1,g=0;g<c.length&&!p;++g)if(c[g](a.charAt(o))){for(h=o;o!=d&&c[g](a.charAt(o));)o+=l;if(p=h!=(u=o),h==t.ch&&s==t.line&&u==h+l)continue;return{from:Math.min(h,u+1),to:Math.max(h,u),line:s}}p||(o+=l)}if(!w(e,s+=l))return null;a=e.getLine(s),o=l>0?0:a.length}}function ke(e,n,i,r,s){var o=new t(n.line+i.repeat-1,1/0),a=e.clipPos(o);return a.ch--,s||(r.lastHPos=1/0,r.lastHSPos=e.charCoords(a,"div").left),o}function Ce(e,n,i,r){for(var s,o=e.getCursor(),a=o.ch,l=0;l<n;l++){if(-1==(s=Le(a,e.getLine(o.line),r,i,!0)))return null;a=s}return new t(e.getCursor().line,s)}function Se(e,t,n,i){M(n,b)&&(t.marks[n]&&t.marks[n].clear(),t.marks[n]=e.setBookmark(i))}function Le(e,t,n,i,r){var s;return i?-1==(s=t.indexOf(n,e+1))||r||(s-=1):-1==(s=t.lastIndexOf(n,e-1))||r||(s+=1),s}function Me(e,n,i,r,s){var o,a=n.line,l=e.firstLine(),c=e.lastLine(),d=a;function h(t){return!e.getLine(t)}function u(e,t,n){return n?h(e)!=h(e+t):!h(e)&&h(e+t)}if(r){for(;l<=d&&d<=c&&i>0;)u(d,r)&&i--,d+=r;return new t(d,0)}var f=e.state.vim;if(f.visualLine&&u(a,1,!0)){var m=f.sel.anchor;u(m.line,-1,!0)&&(s&&m.line==a||(a+=1))}var p=h(a);for(d=a;d<=c&&i;d++)u(d,1,!0)&&(s&&h(d)==p||i--);for(o=new t(d,0),d>c&&!p?p=!0:s=!1,d=a;d>l&&(s&&h(d)!=p&&d!=a||!u(d,-1,!0));d--);return{start:new t(d,0),end:o}}function Te(){}function Ie(e){var t=e.state.vim;return t.searchState_||(t.searchState_=new Te)}function Ae(e,t){var n=Ee(e,t)||[];if(!n.length)return[];var i=[];if(0===n[0]){for(var r=0;r<n.length;r++)"number"==typeof n[r]&&i.push(e.substring(n[r]+1,n[r+1]));return i}}function Ee(e,t){t||(t="/");for(var n=!1,i=[],r=0;r<e.length;r++){var s=e.charAt(r);n||s!=t||i.push(r),n=!n&&"\\"==s}return i}I("pcre",!0,"boolean"),Te.prototype={getQuery:function(){return z.query},setQuery:function(e){z.query=e},getOverlay:function(){return this.searchOverlay},setOverlay:function(e){this.searchOverlay=e},isReversed:function(){return z.isReversed},setReversed:function(e){z.isReversed=e},getScrollbarAnnotate:function(){return this.annotate},setScrollbarAnnotate:function(e){this.annotate=e}};var ze={"\\n":"\n","\\r":"\r","\\t":"\t"};var Ne={"\\/":"/","\\\\":"\\","\\n":"\n","\\r":"\r","\\t":"\t","\\&":"&"};function Fe(e,t,n){if(z.registerController.getRegister("/").setText(e),e instanceof RegExp)return e;var i,r,s=Ee(e,"/");s.length?(i=e.substring(0,s[0]),r=-1!=e.substring(s[0]).indexOf("i")):i=e;return i?(E("pcre")||(i=function(e){for(var t=!1,n=[],i=-1;i<e.length;i++){var r=e.charAt(i)||"",s=e.charAt(i+1)||"",o=s&&-1!="|(){".indexOf(s);t?("\\"===r&&o||n.push(r),t=!1):"\\"===r?(t=!0,s&&-1!="}".indexOf(s)&&(o=!0),o&&"\\"!==s||n.push(r)):(n.push(r),o&&"\\"!==s&&n.push("\\"))}return n.join("")}(i)),n&&(t=/^[^A-Z]*$/.test(i)),new RegExp(i,t||r?"im":"m")):null}function Be(e){"string"==typeof e&&(e=document.createElement(e));for(var t,n=1;n<arguments.length;n++)if(t=arguments[n])if("object"!=typeof t&&(t=document.createTextNode(t)),t.nodeType)e.appendChild(t);else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&("$"===i[0]?e.style[i.slice(1)]=t[i]:e.setAttribute(i,t[i]));return e}function $e(e,t){var n=Be("pre",{$color:"red",class:"cm-vim-message"},t);e.openNotification?e.openNotification(n,{bottom:!0,duration:5e3}):alert(n.innerText)}function Oe(e,t){var n,i,r=(n=t.prefix,i=t.desc,Be(document.createDocumentFragment(),Be("span",{$fontFamily:"monospace",$whiteSpace:"pre"},n,Be("input",{type:"text",autocorrect:"off",autocapitalize:"off",spellcheck:"false"})),i&&Be("span",{$color:"#888"},i)));if(e.openDialog)e.openDialog(r,t.onClose,{onKeyDown:t.onKeyDown,onKeyUp:t.onKeyUp,bottom:!0,selectValueOnOpen:!1,value:t.value});else{var s="";"string"!=typeof t.prefix&&t.prefix&&(s+=t.prefix.textContent),t.desc&&(s+=" "+t.desc),t.onClose(prompt(s,""))}}function Re(e,t,n,i){if(t){var r=Ie(e),s=Fe(t,!!n,!!i);if(s)return De(e,s),function(e,t){if(e instanceof RegExp&&t instanceof RegExp){for(var n=["global","multiline","ignoreCase","source"],i=0;i<n.length;i++){var r=n[i];if(e[r]!==t[r])return!1}return!0}return!1}(s,r.getQuery())||r.setQuery(s),s}}var He=0;function De(e,t){clearTimeout(He),He=setTimeout((function(){if(e.state.vim){var n=Ie(e),i=n.getOverlay();i&&t==i.query||(i&&e.removeOverlay(i),i=function(e){if("^"==e.source.charAt(0))var t=!0;return{token:function(n){if(!t||n.sol()){var i=n.match(e,!1);if(i)return 0==i[0].length?(n.next(),"searching"):n.sol()||(n.backUp(1),e.exec(n.next()+i[0]))?(n.match(e),"searching"):(n.next(),null);for(;!n.eol()&&(n.next(),!n.match(e,!1)););}else n.skipToEnd()},query:e}}(t),e.addOverlay(i),e.showMatchesOnScrollbar&&(n.getScrollbarAnnotate()&&n.getScrollbarAnnotate().clear(),n.setScrollbarAnnotate(e.showMatchesOnScrollbar(t))),n.setOverlay(i))}}),50)}function Pe(e,n,i,r){return void 0===r&&(r=1),e.operation((function(){for(var s=e.getCursor(),o=e.getSearchCursor(i,s),a=0;a<r;a++){var l=o.find(n);if(0==a&&l&&ne(o.from(),s)){var c=n?o.from():o.to();(l=o.find(n))&&!l[0]&&ne(o.from(),c)&&e.getLine(c.line).length==c.ch&&(l=o.find(n))}if(!l&&!(o=e.getSearchCursor(i,n?new t(e.lastLine()):new t(e.firstLine(),0))).find(n))return}return o.from()}))}function We(e){var t=Ie(e);e.removeOverlay(Ie(e).getOverlay()),t.setOverlay(null),t.getScrollbarAnnotate()&&(t.getScrollbarAnnotate().clear(),t.setScrollbarAnnotate(null))}function Ue(e,t,n){return"number"!=typeof e&&(e=e.line),t instanceof Array?M(e,t):"number"==typeof n?e>=t&&e<=n:e==t}function je(e){var t=e.getScrollInfo(),n=e.coordsChar({left:0,top:6+t.top},"local"),i=t.clientHeight-10+t.top,r=e.coordsChar({left:0,top:i},"local");return{top:n.line,bottom:r.line}}function Ke(e,n,i){if("'"==i||"`"==i)return z.jumpList.find(e,-1)||new t(0,0);if("."==i)return Ve(e);var r=n.marks[i];return r&&r.find()}function Ve(e){for(var t=e.doc.history.done,n=t.length;n--;)if(t[n].changes)return te(t[n].changes[0].to)}var qe=function(){this.buildCommandMap_()};qe.prototype={processCommand:function(e,t,n){var i=this;e.operation((function(){e.curOp.isVimOp=!0,i._processCommand(e,t,n)}))},_processCommand:function(t,n,i){var r=t.state.vim,s=z.registerController.getRegister(":"),o=s.toString();r.visualMode&&pe(t);var a=new e.StringStream(n);s.setText(n);var l,c,d=i||{};d.input=n;try{this.parseInput_(t,a,d)}catch(e){throw $e(t,e.toString()),e}if(d.commandName){if(l=this.matchCommand_(d.commandName)){if(c=l.name,l.excludeFromCommandHistory&&s.setText(o),this.parseCommandArgs_(a,d,l),"exToKey"==l.type){for(var h=0;h<l.toKeys.length;h++)H.handleKey(t,l.toKeys[h],"mapping");return}if("exToEx"==l.type)return void this.processCommand(t,l.toInput)}}else void 0!==d.line&&(c="move");if(c)try{Xe[c](t,d),l&&l.possiblyAsync||!d.callback||d.callback()}catch(e){throw $e(t,e.toString()),e}else $e(t,'Not an editor command ":'+n+'"')},parseInput_:function(e,t,n){t.eatWhile(":"),t.eat("%")?(n.line=e.firstLine(),n.lineEnd=e.lastLine()):(n.line=this.parseLineSpec_(e,t),void 0!==n.line&&t.eat(",")&&(n.lineEnd=this.parseLineSpec_(e,t)));var i=t.match(/^(\w+|!!|@@|[!#&*<=>@~])/);return n.commandName=i?i[1]:t.match(/.*/)[0],n},parseLineSpec_:function(e,t){var n=t.match(/^(\d+)/);if(n)return parseInt(n[1],10)-1;switch(t.next()){case".":return this.parseLineSpecOffset_(t,e.getCursor().line);case"$":return this.parseLineSpecOffset_(t,e.lastLine());case"'":var i=t.next(),r=Ke(e,e.state.vim,i);if(!r)throw new Error("Mark not set");return this.parseLineSpecOffset_(t,r.line);case"-":case"+":return t.backUp(1),this.parseLineSpecOffset_(t,e.getCursor().line);default:return void t.backUp(1)}},parseLineSpecOffset_:function(e,t){var n=e.match(/^([+-])?(\d+)/);if(n){var i=parseInt(n[2],10);"-"==n[1]?t-=i:t+=i}return t},parseCommandArgs_:function(e,t,n){if(!e.eol()){t.argString=e.match(/.*/)[0];var i=n.argDelimiter||/\s+/,r=le(t.argString).split(i);r.length&&r[0]&&(t.args=r)}},matchCommand_:function(e){for(var t=e.length;t>0;t--){var n=e.substring(0,t);if(this.commandMap_[n]){var i=this.commandMap_[n];if(0===i.name.indexOf(e))return i}}return null},buildCommandMap_:function(){this.commandMap_={};for(var e=0;e<s.length;e++){var t=s[e],n=t.shortName||t.name;this.commandMap_[n]=t}},map:function(e,t,n){if(":"!=e&&":"==e.charAt(0)){if(n)throw Error("Mode not supported for ex mappings");var r=e.substring(1);":"!=t&&":"==t.charAt(0)?this.commandMap_[r]={name:r,type:"exToEx",toInput:t.substring(1),user:!0}:this.commandMap_[r]={name:r,type:"exToKey",toKeys:t,user:!0}}else if(":"!=t&&":"==t.charAt(0)){var s={keys:e,type:"keyToEx",exArgs:{input:t.substring(1)}};n&&(s.context=n),i.unshift(s)}else{s={keys:e,type:"keyToKey",toKeys:t};n&&(s.context=n),i.unshift(s)}},unmap:function(e,t){if(":"!=e&&":"==e.charAt(0)){if(t)throw Error("Mode not supported for ex mappings");var n=e.substring(1);if(this.commandMap_[n]&&this.commandMap_[n].user)return delete this.commandMap_[n],!0}else for(var r=e,s=0;s<i.length;s++)if(r==i[s].keys&&i[s].context===t)return i.splice(s,1),!0}};var Xe={colorscheme:function(e,t){!t.args||t.args.length<1?$e(e,e.getOption("theme")):e.setOption("theme",t.args[0])},map:function(e,t,n){var i=t.args;!i||i.length<2?e&&$e(e,"Invalid mapping: "+t.input):Ge.map(i[0],i[1],n)},imap:function(e,t){this.map(e,t,"insert")},nmap:function(e,t){this.map(e,t,"normal")},vmap:function(e,t){this.map(e,t,"visual")},unmap:function(e,t,n){var i=t.args;(!i||i.length<1||!Ge.unmap(i[0],n))&&e&&$e(e,"No such mapping: "+t.input)},move:function(e,t){K.processCommand(e,e.state.vim,{type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0},repeatOverride:t.line+1})},set:function(e,t){var n=t.args,i=t.setCfg||{};if(!n||n.length<1)e&&$e(e,"Invalid mapping: "+t.input);else{var r=n[0].split("="),s=r[0],o=r[1],a=!1;if("?"==s.charAt(s.length-1)){if(o)throw Error("Trailing characters: "+t.argString);s=s.substring(0,s.length-1),a=!0}void 0===o&&"no"==s.substring(0,2)&&(s=s.substring(2),o=!1);var l=T[s]&&"boolean"==T[s].type;if(l&&null==o&&(o=!0),!l&&void 0===o||a){var c=E(s,e,i);c instanceof Error?$e(e,c.message):$e(e,!0===c||!1===c?" "+(c?"":"no")+s:" "+s+"="+c)}else{var d=A(s,o,e,i);d instanceof Error&&$e(e,d.message)}}},setlocal:function(e,t){t.setCfg={scope:"local"},this.set(e,t)},setglobal:function(e,t){t.setCfg={scope:"global"},this.set(e,t)},registers:function(e,t){var n=t.args,i=z.registerController.registers,r="----------Registers----------\n\n";if(n){n=n.join("");for(var s=0;s<n.length;s++){if(o=n.charAt(s),z.registerController.isValidRegister(o))r+='"'+o+" "+(i[o]||new W).toString()+"\n"}}else for(var o in i){var a=i[o].toString();a.length&&(r+='"'+o+" "+a+"\n")}$e(e,r)},sort:function(n,i){var r,s,o,a,l;var c=function(){if(i.argString){var t=new e.StringStream(i.argString);if(t.eat("!")&&(r=!0),t.eol())return;if(!t.eatSpace())return"Invalid arguments";var n=t.match(/([dinuox]+)?\s*(\/.+\/)?\s*/);if(!n&&!t.eol())return"Invalid arguments";if(n[1]){s=-1!=n[1].indexOf("i"),o=-1!=n[1].indexOf("u");var c=-1!=n[1].indexOf("d")||-1!=n[1].indexOf("n")&&1,d=-1!=n[1].indexOf("x")&&1,h=-1!=n[1].indexOf("o")&&1;if(c+d+h>1)return"Invalid arguments";a=(c?"decimal":d&&"hex")||h&&"octal"}n[2]&&(l=new RegExp(n[2].substr(1,n[2].length-2),s?"i":""))}}();if(c)$e(n,c+": "+i.argString);else{var d=i.line||n.firstLine(),h=i.lineEnd||i.line||n.lastLine();if(d!=h){var u=new t(d,0),f=new t(h,ae(n,h)),m=n.getRange(u,f).split("\n"),p=l||("decimal"==a?/(-?)([\d]+)/:"hex"==a?/(-?)(?:0x)?([0-9a-f]+)/i:"octal"==a?/([0-7]+)/:null),g="decimal"==a?10:"hex"==a?16:"octal"==a?8:null,v=[],_=[];if(a||l)for(var y=0;y<m.length;y++){var b=l?m[y].match(l):null;b&&""!=b[0]?v.push(b):!l&&p.exec(m[y])?v.push(m[y]):_.push(m[y])}else _=m;if(v.sort(l?function(e,t){var n;return r&&(n=e,e=t,t=n),s&&(e[0]=e[0].toLowerCase(),t[0]=t[0].toLowerCase()),e[0]<t[0]?-1:1}:k),l)for(y=0;y<v.length;y++)v[y]=v[y].input;else a||_.sort(k);if(m=r?v.concat(_):_.concat(v),o){var x,w=m;m=[];for(y=0;y<w.length;y++)w[y]!=x&&m.push(w[y]),x=w[y]}n.replaceRange(m.join("\n"),u,f)}}function k(e,t){var n;r&&(n=e,e=t,t=n);s&&(e=e.toLowerCase(),t=t.toLowerCase());var i=a&&p.exec(e),o=a&&p.exec(t);return i?(i=parseInt((i[1]+i[2]).toLowerCase(),g))-(o=parseInt((o[1]+o[2]).toLowerCase(),g)):e<t?-1:1}},vglobal:function(e,t){this.global(e,t)},global:function(e,t){var n=t.argString;if(n){var i,r="v"===t.commandName[0],s=void 0!==t.line?t.line:e.firstLine(),o=t.lineEnd||t.line||e.lastLine(),a=function(e){return Ae(e,"/")}(n),l=n;if(a.length&&(l=a[0],i=a.slice(1,a.length).join("/")),l)try{Re(e,l,!0,!0)}catch(t){return void $e(e,"Invalid regex: "+l)}for(var c=Ie(e).getQuery(),d=[],h=s;h<=o;h++){var u=e.getLineHandle(h);c.test(u.text)!==r&&d.push(i?u:u.text)}if(i){var f=0,m=function(){if(f<d.length){var t=d[f++],n=e.getLineNumber(t);if(null==n)return void m();var r=n+1+i;Ge.processCommand(e,r,{callback:m})}};m()}else $e(e,d.join("\n"))}else $e(e,"Regular Expression missing from global")},substitute:function(n,i){if(!n.getSearchCursor)throw new Error("Search feature not available. Requires searchcursor.js or any other getSearchCursor implementation.");var r,s,o,a,l=i.argString,c=l?Ae(l,l[0]):[],d="",h=!1,f=!1;if(c.length)r=c[0],E("pcre")&&""!==r&&(r=new RegExp(r).source),void 0!==(d=c[1])&&(d=E("pcre")?function(t){for(var n=new e.StringStream(t),i=[];!n.eol();){for(;n.peek()&&"\\"!=n.peek();)i.push(n.next());var r=!1;for(var s in Ne)if(n.match(s,!0)){r=!0,i.push(Ne[s]);break}r||i.push(n.next())}return i.join("")}(d.replace(/([^\\])&/g,"$1$$&")):function(e){for(var t,n=!1,i=[],r=-1;r<e.length;r++){var s=e.charAt(r)||"",o=e.charAt(r+1)||"";ze[s+o]?(i.push(ze[s+o]),r++):n?(i.push(s),n=!1):"\\"===s?(n=!0,t=o,u.test(t)||"$"===o?i.push("$"):"/"!==o&&"\\"!==o&&i.push("\\")):("$"===s&&i.push("$"),i.push(s),"/"===o&&i.push("\\"))}return i.join("")}(d),z.lastSubstituteReplacePart=d),s=c[2]?c[2].split(" "):[];else if(l&&l.length)return void $e(n,"Substitutions should be of the form :s/pattern/replace/");if(s&&(o=s[0],a=parseInt(s[1]),o&&(-1!=o.indexOf("c")&&(h=!0),-1!=o.indexOf("g")&&(f=!0),r=E("pcre")?r+"/"+o:r.replace(/\//g,"\\/")+"/"+o)),r)try{Re(n,r,!0,!0)}catch(e){return void $e(n,"Invalid regex: "+r)}if(void 0!==(d=d||z.lastSubstituteReplacePart)){var m=Ie(n).getQuery(),p=void 0!==i.line?i.line:n.getCursor().line,g=i.lineEnd||p;p==n.firstLine()&&g==n.lastLine()&&(g=1/0),a&&(g=(p=g)+a-1);var v=Y(n,new t(p,0)),_=n.getSearchCursor(m,v);!function(t,n,i,r,s,o,a,l,c){t.state.vim.exMode=!0;var d,h,u,f=!1;function m(){t.operation((function(){for(;!f;)p(),v();_()}))}function p(){var e=t.getRange(o.from(),o.to()).replace(a,l),n=o.to().line;o.replace(e),h=o.to().line,s+=h-n,u=h<n}function g(){var e=d&&te(o.to()),t=o.findNext();return t&&!t[0]&&e&&ne(o.from(),e)&&(t=o.findNext()),t}function v(){for(;g()&&Ue(o.from(),r,s);)if(i||o.from().line!=h||u)return t.scrollIntoView(o.from(),30),t.setSelection(o.from(),o.to()),d=o.from(),void(f=!1);f=!0}function _(e){if(e&&e(),t.focus(),d){t.setCursor(d);var n=t.state.vim;n.exMode=!1,n.lastHPos=n.lastHSPos=d.ch}c&&c()}function y(n,i,r){switch(e.e_stop(n),e.keyName(n)){case"Y":p(),v();break;case"N":v();break;case"A":var s=c;c=void 0,t.operation(m),c=s;break;case"L":p();case"Q":case"Esc":case"Ctrl-C":case"Ctrl-[":_(r)}return f&&_(r),!0}if(v(),f)return void $e(t,"No matches for "+a.source);if(!n)return m(),void(c&&c());Oe(t,{prefix:Be("span","replace with ",Be("strong",l)," (y/n/a/q/l)"),onKeyDown:y})}(n,h,f,p,g,_,m,d,i.callback)}else $e(n,"No previous substitute regular expression")},redo:e.commands.redo,undo:e.commands.undo,write:function(t){e.commands.save?e.commands.save(t):t.save&&t.save()},nohlsearch:function(e){We(e)},yank:function(e){var t=te(e.getCursor()).line,n=e.getLine(t);z.registerController.pushText("0","yank",n,!0,!0)},delmarks:function(t,n){if(n.argString&&le(n.argString))for(var i=t.state.vim,r=new e.StringStream(le(n.argString));!r.eol();){r.eatSpace();var s=r.pos;if(!r.match(/[a-zA-Z]/,!1))return void $e(t,"Invalid argument: "+n.argString.substring(s));var o=r.next();if(r.match("-",!0)){if(!r.match(/[a-zA-Z]/,!1))return void $e(t,"Invalid argument: "+n.argString.substring(s));var a=o,l=r.next();if(!(k(a)&&k(l)||C(a)&&C(l)))return void $e(t,"Invalid argument: "+a+"-");var c=a.charCodeAt(0),d=l.charCodeAt(0);if(c>=d)return void $e(t,"Invalid argument: "+n.argString.substring(s));for(var h=0;h<=d-c;h++){var u=String.fromCharCode(c+h);delete i.marks[u]}}else delete i.marks[o]}else $e(t,"Argument required")}},Ge=new qe;function Ye(t){var n=t.state.vim,i=z.macroModeState,r=z.registerController.getRegister("."),s=i.isPlaying,o=i.lastInsertModeChanges;s||(t.off("change",Ze),e.off(t.getInputField(),"keydown",nt)),!s&&n.insertModeRepeat>1&&(it(t,n,n.insertModeRepeat-1,!0),n.lastEditInputState.repeatOverride=n.insertModeRepeat),delete n.insertModeRepeat,n.insertMode=!1,t.setCursor(t.getCursor().line,t.getCursor().ch-1),t.setOption("keyMap","vim"),t.setOption("disableInput",!0),t.toggleOverwrite(!1),r.setText(o.changes.join("")),e.signal(t,"vim-mode-change",{mode:"normal"}),i.isRecording&&function(e){if(e.isPlaying)return;var t=e.latestRegister,n=z.registerController.getRegister(t);n&&n.pushInsertModeChanges&&n.pushInsertModeChanges(e.lastInsertModeChanges)}(i)}function Je(e){i.unshift(e)}function Qe(e,t,n,i){var r=z.registerController.getRegister(i);if(":"==i)return r.keyBuffer[0]&&Ge.processCommand(e,r.keyBuffer[0]),void(n.isPlaying=!1);var s=r.keyBuffer,o=0;n.isPlaying=!0,n.replaySearchQueries=r.searchQueries.slice(0);for(var a=0;a<s.length;a++)for(var l,c,d=s[a];d;)if(c=(l=/<\w+-.+?>|<\w+>|./.exec(d))[0],d=d.substring(l.index+c.length),H.handleKey(e,c,"macro"),t.insertMode){var h=r.insertModeChanges[o++].changes;z.macroModeState.lastInsertModeChanges.changes=h,rt(e,h,1),Ye(e)}n.isPlaying=!1}function Ze(e,t){var n=z.macroModeState,i=n.lastInsertModeChanges;if(!n.isPlaying)for(;t;){if(i.expectCursorActivityForChange=!0,i.ignoreCount>1)i.ignoreCount--;else if("+input"==t.origin||"paste"==t.origin||void 0===t.origin){var r=e.listSelections().length;r>1&&(i.ignoreCount=r);var s=t.text.join("\n");i.maybeReset&&(i.changes=[],i.maybeReset=!1),s&&(e.state.overwrite&&!/\n/.test(s)?i.changes.push([s]):i.changes.push(s))}t=t.next}}function et(t){var n=t.state.vim;if(n.insertMode){var i=z.macroModeState;if(i.isPlaying)return;var r=i.lastInsertModeChanges;r.expectCursorActivityForChange?r.expectCursorActivityForChange=!1:r.maybeReset=!0}else t.curOp.isVimOp||function(t,n){var i=t.getCursor("anchor"),r=t.getCursor("head");n.visualMode&&!t.somethingSelected()?pe(t,!1):n.visualMode||n.insertMode||!t.somethingSelected()||(n.visualMode=!0,n.visualLine=!1,e.signal(t,"vim-mode-change",{mode:"visual"}));if(n.visualMode){var s=ie(r,i)?0:-1,o=ie(r,i)?-1:0;r=Q(r,0,s),i=Q(i,0,o),n.sel={anchor:i,head:r},Se(t,n,"<",re(r,i)),Se(t,n,">",se(r,i))}else n.insertMode||(n.lastHPos=t.getCursor().ch)}(t,n)}function tt(e){this.keyName=e}function nt(t){var n=z.macroModeState.lastInsertModeChanges,i=e.keyName(t);i&&(-1==i.indexOf("Delete")&&-1==i.indexOf("Backspace")||e.lookupKey(i,"vim-insert",(function(){return n.maybeReset&&(n.changes=[],n.maybeReset=!1),n.changes.push(new tt(i)),!0})))}function it(e,t,n,i){var r=z.macroModeState;r.isPlaying=!0;var s=!!t.lastEditActionCommand,o=t.inputState;function a(){s?K.processAction(e,t,t.lastEditActionCommand):K.evalInput(e,t)}function l(n){if(r.lastInsertModeChanges.changes.length>0){n=t.lastEditActionCommand?n:1;var i=r.lastInsertModeChanges;rt(e,i.changes,n)}}if(t.inputState=t.lastEditInputState,s&&t.lastEditActionCommand.interlaceInsertRepeat)for(var c=0;c<n;c++)a(),l(1);else i||a(),l(n);t.inputState=o,t.insertMode&&!i&&Ye(e),r.isPlaying=!1}function rt(t,n,i){function r(n){return"string"==typeof n?e.commands[n](t):n(t),!0}var s=t.getCursor("head"),o=z.macroModeState.lastInsertModeChanges.visualBlock;o&&(he(t,s,o+1),i=t.listSelections().length,t.setCursor(s));for(var a=0;a<i;a++){o&&t.setCursor(Q(s,a,0));for(var l=0;l<n.length;l++){var c=n[l];if(c instanceof tt)e.lookupKey(c.keyName,"vim-insert",r);else if("string"==typeof c)t.replaceSelection(c);else{var d=t.getCursor(),h=Q(d,0,c[0].length);t.replaceRange(c[0],d,h),t.setCursor(h)}}}o&&t.setCursor(Q(s,0,1))}return e.keyMap.vim={attach:a,detach:o,call:l},I("insertModeEscKeysTimeout",200,"number"),e.keyMap["vim-insert"]={fallthrough:["default"],attach:a,detach:o,call:l},e.keyMap["vim-replace"]={Backspace:"goCharLeft",fallthrough:["vim-insert"],attach:a,detach:o,call:l},R(),H}()}));"use strict";var CodeMirror,getstate,setstate,gradefn,tool,xdp;class SimTool{constructor(e,t,n,i){e.sim_tool=this,this.tool_div=e,this.version=t||"sim_tool.1",this.cm_mode=n,this.github_url=i,this.configuration={};try{let e=this.tool_div.innerHTML.trim();e=e.replace("\x3c!--[CDATA[","").replace("]]--\x3e","").trim(),this.configuration=JSON.parse(e||"{}")}catch{window.alert("Error parsing configuration info as JSON")}this.editor_list=[],this.current_editor=void 0,this.setup_gui(),this.left_pane_only(),this.process_configuration()}process_configuration(){if("object"!=typeof this.configuration&&(window.alert("Unexpected configuration info"),this.configuration={}),this.configuration.buffers)for(let e of this.configuration.buffers)this.new_editor_pane(e);else this.new_editor_pane({name:"Untitled"});this.select_buffer(this.editor_list[0].id)}hexify(e,t){if(void 0===t&&(t=8),void 0===e)return"-".padStart(t,"-");let n;return n="bigint"==typeof e?BigInt.asUintN(4*t,e).toString(16):(e>>>0).toString(16),n.padStart(t,"0")}setup_gui(){this.tool_div.classList.add("sim_tool"),this.tool_div.innerHTML=`\n<div class="sim_tool-body">\n \x3c!-- left pane: controls, error listing, editors --\x3e\n <div id="body-left" class="sim_tool-body-left">\n <div class="sim_tool-body-left-header">\n <div id="action-buttons" class="sim_tool-action-buttons"></div>\n File:\n <select id="editor-select" class="sim_tool-editor-select"></select>\n <div id="read-only" class="sim_tool-read-only">\n <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">\n <path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2z"/>\n </svg>\n <div class="sim_tool-tip">File is read-only</div>\n </div>\n <div id="rename-buffer" class="sim_tool-control sim_tool-rename-buffer">\n <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" transform="translate(0 4)" fill="currentColor" viewBox="0 0 16 16">\n <path d="M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5h-2z"></path>\n <path transform="scale(0.5 0.5) translate(8 10)" d="M12.854.146a.5.5 0 0 0-.707 0L10.5 1.793 14.207 5.5l1.647-1.646a.5.5 0 0 0 0-.708l-3-3zm.646 6.061L9.793 2.5 3.293 9H3.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.207l6.5-6.5zm-7.468 7.468A.5.5 0 0 1 6 13.5V13h-.5a.5.5 0 0 1-.5-.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.5-.5V10h-.5a.499.499 0 0 1-.175-.032l-.179.178a.5.5 0 0 0-.11.168l-2 5a.5.5 0 0 0 .65.65l5-2a.5.5 0 0 0 .168-.11l.178-.178z"></path>\n </svg>\n <div class="sim_tool-tip">Rename file</div>\n </div>\n <div id="new-buffer" class="sim_tool-control sim_tool-new-buffer">\n <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" transform="translate(0 4)" fill="currentColor" viewBox="0 0 16 16">\n <path d="M8 6.5a.5.5 0 0 1 .5.5v1.5H10a.5.5 0 0 1 0 1H8.5V11a.5.5 0 0 1-1 0V9.5H6a.5.5 0 0 1 0-1h1.5V7a.5.5 0 0 1 .5-.5z"/>\n <path d="M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5h-2z"/>\n </svg>\n <div class="sim_tool-tip">New file</div>\n </div>\n <div id="upload-buffer" class="sim_tool-control sim_tool-upload-buffer">\n <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" transform="translate(0 4)" fill="currentColor" viewBox="0 0 16 16">\n <path d="M8.5 11.5a.5.5 0 0 1-1 0V7.707L6.354 8.854a.5.5 0 1 1-.708-.708l2-2a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 7.707V11.5z"/>\n <path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2zM9.5 3A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.5v2z"/>\n </svg>\n <div class="sim_tool-tip">Load file</div>\n </div>\n <div id="choose-file" class="sim_tool-choose-file"></div>\n <a id="download-buffer" class="sim_tool-download-buffer" download="buffer_name" href="#">\n <div class="sim_tool-control">\n <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" transform="translate(0 4)" fill="currentColor" viewBox="0 0 16 16">\n <path d="M8.5 6.5a.5.5 0 0 0-1 0v3.793L6.354 9.146a.5.5 0 1 0-.708.708l2 2a.5.5 0 0 0 .708 0l2-2a.5.5 0 0 0-.708-.708L8.5 10.293V6.5z"/>\n <path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2zM9.5 3A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.5v2z"/>\n </svg>\n <div class="sim_tool-tip">Download file</div>\n </div>\n </a>\n <div class="sim_tool-font-buttons">\n <div id="font-smaller" class="sim_tool-font-button sim_tool-font-smaller">A</div>\n <div id="font-larger" class="sim_tool-font-button sim_tool-font-larger">A</div>\n </div>\n <div id="key-map-indicator" class="sim_tool-key-map-indicator" key-map="default">\n <span>DEFAULT</span>\n <div class="sim_tool-key-map-list">\n <div class="sim_tool-key-map-choice" choice="default">DEFAULT</div>\n <div class="sim_tool-key-map-choice" choice="emacs">EMACS</div>\n <div class="sim_tool-key-map-choice" choice="sublime"">SUBLIME</div>\n <div class="sim_tool-key-map-choice" choice="vim"">VIM</div>\n </div>\n </div>\n </div>\n <div id="error-div" class="sim_tool-error-div">\n <div id="error-list" class="sim_tool-error-list"></div>\n </div>\n \x3c!-- editor divs will be added here --\x3e\n </div>\n\n \x3c!-- moveable divider --\x3e\n <div id="body-divider" class="sim_tool-body-divider"></div>\n\n \x3c!-- right pane: simulation results --\x3e\n <div id="body-right" class="sim_tool-body-right"> </div>\n</div>\n\n\x3c!-- bug-report link, version --\x3e\n<div class="sim_tool-notice">\n <div id="message" class="sim_tool-message"></div>\n <div style="float:right;">\n <a style="margin-right:0.5em;" href="${this.github_url}/issues/new?labels=bug&title=Bug+report+for+${this.version}" target="_blank">send bug report</a>\n <a style="margin-right:0.5em;" href="${this.github_url}" target="_blank">github</a>\n ${this.version}\n </div>\n</div>\n`,this.left=this.tool_div.querySelector("#body-left"),this.action_buttons=this.tool_div.querySelector("#action-buttons"),this.error_div=this.tool_div.querySelector("#error-div"),this.error_list=this.tool_div.querySelector("#error-list"),this.divider=this.tool_div.querySelector("#body-divider"),this.right=this.tool_div.querySelector("#body-right"),this.message=this.tool_div.querySelector("#message"),this.selector=this.tool_div.querySelector("#editor-select"),this.rename_buffer=this.tool_div.querySelector("#rename-buffer"),this.new_buffer=this.tool_div.querySelector("#new-buffer"),this.upload_buffer=this.tool_div.querySelector("#upload-buffer"),this.choose_file=this.tool_div.querySelector("#choose-file"),this.download_buffer=this.tool_div.querySelector("#download-buffer"),this.read_only=this.tool_div.querySelector("#read-only"),this.font_larger=this.tool_div.querySelector("#font-larger"),this.font_smaller=this.tool_div.querySelector("#font-smaller"),this.key_map_indicator=this.tool_div.querySelector("#key-map-indicator");const e=this;this.setup_divider(),this.font_larger.addEventListener("click",(function(){e.buffer_font_size("larger")})),this.font_smaller.addEventListener("click",(function(){e.buffer_font_size("smaller")}));for(let t of this.tool_div.getElementsByClassName("sim_tool-key-map-choice"))t.addEventListener("click",(function(t){e.select_key_map(t.target.getAttribute("choice"))}));if(this.selector.addEventListener("change",(function(){e.select_buffer(e.selector.value)})),this.rename_buffer.addEventListener("click",(function(){const t=e.selector.value,n=window.prompt("Enter new file name",t);if(null!==n&&n!==t)if(""===n||e.buffer_name_in_use(n))alert(""==n?"Buffer name cannot be blank.":"Buffer name already in use.");else{for(let i of e.editor_list)if(i.id===t){i.id=n;break}for(let i of e.selector.getElementsByTagName("option"))if(i.getAttribute("value")===t){i.setAttribute("value",n),i.innerHTML=n;break}}})),this.new_buffer.addEventListener("click",(function(){const t=e.unique_buffer_name("Untitled");e.new_editor_pane({name:t}),e.select_buffer(t)})),this.upload_buffer.addEventListener("click",(function(){const t=e.choose_file;""!=t.innerHTML?t.innerHTML="":(t.innerHTML='<input type="file"/>',t.getElementsByTagName("input")[0].addEventListener("change",(function(){const n=this.files[0];if(n){const i=new FileReader;i.onload=function(i){const r=e.unique_buffer_name(n.name);e.new_editor_pane({name:r,contents:i.target.result}),e.select_buffer(r),t.innerHTML=""},i.readAsText(n)}else t.innerHTML=""})))})),this.download_buffer.addEventListener("click",(function(){const t=e.selector.value,n=e.current_editor.CodeMirror.doc.getValue();this.setAttribute("download",t),this.setAttribute("href","data:text/plain;base64,"+btoa(n))})),window.parent!==window)for(let e of window.parent.document.getElementsByTagName("iframe"))if(e.contentWindow===window){e.style.resize="both",e.setAttribute("sandbox",e.getAttribute("sandbox")+" allow-modals");break}let t=this;getstate=function(e){let n={...t.configuration};n.buffers=[];for(let e of t.editor_list){const t={name:e.id};n.buffers.push(t),e.readonly&&(t.readonly=!0,e.url&&(t.url=e.url)),void 0===t.url&&(t.contents=e.CodeMirror.doc.getValue()||"")}return JSON.stringify(n)},setstate=function(e){try{t.configuration=JSON.parse(e||"{}");for(let e of t.editor_list)e.style.display="none",e.remove();t.editor_list=[],t.current_editor=void 0,t.selector.innerHTML="",t.process_configuration()}catch{console.log("Error parsing configuration info as JSON",e)}},gradefn=function(e){return t.configuration.checksum||""}}clear_message(){this.message.innerHTML=""}setup_divider(){const e=this;this.divider.addEventListener("mousedown",(function(t){(t=t||window.event).preventDefault();let n=t.clientX;function i(t){(t=t||window.event).preventDefault();let i=t.clientX-n;n=t.clientX,i=Math.min(i,e.right.offsetWidth),e.left.style.width=Math.max(0,100*(e.left.offsetWidth+i)/e.left.parentElement.offsetWidth)+"%"}e.left.style.userSelect="none",e.left.style.pointerEvents="none",e.right.style.userSelect="none",e.right.style.pointerEvents="none",document.addEventListener("mousemove",i),document.addEventListener("mouseup",(function t(){document.removeEventListener("mouseup",t),document.removeEventListener("mousemove",i),e.left.style.removeProperty("user-select"),e.left.style.removeProperty("pointer-events"),e.right.style.removeProperty("user-select"),e.right.style.removeProperty("pointer-events")}))}))}left_pane_only(){this.left.style.width=100*(this.left.offsetWidth+this.right.offsetWidth)/this.left.parentElement.offsetWidth+"%"}add_action_button(e,t,n){void 0===n&&(n=["btn-primary"]),this.action_buttons.innerHTML+=`<button class="sim_tool-action-button btn btn-sm ${n.join(" ")}">${e}</button>`;this.action_buttons.lastChild.addEventListener("click",t)}buffer_name_in_use(e){for(let t of this.editor_list)if(t.id===e)return!0;return!1}unique_buffer_name(e){let t=e,n=0;for(;this.buffer_name_in_use(t);)n+=1,t=`${e} (${n})`;return t}gutter_list(){return[{className:"CodeMirror-linenumbers"}]}gutter_click(e,t,n,i){}editor_before_change(e,t){}new_editor_pane(e){const t=this;let n=this.unique_buffer_name(e.name);this.selector.innerHTML+=`<option value="${n}" selected>${n}</option>`;const i={lineNumbers:!0,mode:this.cm_mode,value:e.contents||"",keyMap:this.key_map_indicator.getAttribute("key-map")||"default",gutters:this.gutter_list()};e.readonly&&(i.readOnly=!0);const r=CodeMirror((function(i){t.left.appendChild(i),i.id=n,e.url&&(i.url=e.url),e.readonly&&(i.readonly=!0,i.style.backgroundColor="#ccc"),t.editor_list.push(i)}),i);if(this.current_editor=r,r.tool=t,r.buffer_name=n,r.on("gutterClick",this.gutter_click),r.on("beforeChange",this.editor_before_change),e.url)try{const t=new XMLHttpRequest;t.open("GET",e.url,!0),t.onreadystatechange=function(){4===t.readyState&&(200===t.status?r.doc.setValue(t.responseText):r.doc.setValue(`Cannot read url:${e.url}.`),r.refresh())},t.send()}catch(t){r.doc.setValue(`Cannot read url:${e.url}.`)}return r}select_buffer(e){for(let t of this.editor_list)t.id===e?(t.style.display="block",this.read_only.style.display=t.CodeMirror.options.readOnly?"inline-block":"none",setTimeout((function(){t.CodeMirror.refresh(),t.CodeMirror.focus()}),1),this.current_editor=t):t.style.display="none";for(let t of this.selector.getElementsByTagName("option"))if(t.getAttribute("value")===e){t.selected=!0;break}return this.current_editor}upload_buffer(e){const t=e.target.files[0];if(!t)return;const n=this,i=this.unique_buffer_name(t.name),r=new FileReader;r.onload=function(e){const t=n.new_editor_pane(i);n.select_buffer(i),t.doc.setValue(e.target.result)},r.readAsText(t),this.choose_file.innerHTML=""}buffer_font_size(e){for(let t of this.editor_list){const n=getComputedStyle(t).fontSize;let i=parseFloat(n.replace("px",""));i*="larger"===e?1.1:1/1.1,t.style.fontSize=i+"px",t.CodeMirror.refresh()}}select_key_map(e){this.key_map_indicator.setAttribute("key-map",e),this.key_map_indicator.getElementsByTagName("span")[0].innerHTML=e.toUpperCase();for(let t of this.editor_list)t.CodeMirror.setOption("keyMap",e)}show_error(e,t){const n=this.select_buffer(e[0]);if(n){n.CodeMirror.doc.setSelection(CodeMirror.Pos(e[1]-1,e[2]-1),CodeMirror.Pos(t[1]-1,t[2]-1),{scroll:!0})}return!1}handle_errors(e,t){const n=this;if(0!==e.length||0!==t.length){if(this.error_list.innerHTML="",e)for(let t of e)this.error_list.innerHTML+=`Error [<a href="#" class="sim_tool-show-error" estart="${t.start[0]},${t.start[1]},${t.start[2]}" eend="${t.end[0]},${t.end[1]},${t.end[2]}">${t.start[0]}:${t.start[1]}</a>] ${t.message}<br/>`;if(t)for(let e of t)this.error_list.innerHTML+=`Warning [<a href="#" class="sim_tool-show-error" estart="${e.start[0]},${e.start[1]},${e.start[2]}" eend="${e.end[0]},${e.end[1]},${e.end[2]}">${e.start[0]}:${e.start[1]}</a>] ${e.message}<br/>`;for(let e of this.tool_div.getElementsByClassName("sim_tool-show-error"))e.addEventListener("click",(function(e){const t=e.target.getAttribute("estart").split(",");t[1]=parseInt(t[1]),t[2]=parseInt(t[2]);const i=e.target.getAttribute("eend").split(",");return i[1]=parseInt(i[1]),i[2]=parseInt(i[2]),n.show_error(t,i),e.preventDefault(),!1}));n.error_div.style.display="block"}}}window.addEventListener("load",(function(){for(let e of document.getElementsByClassName("sim_tool"))new SimTool(e)})),SimTool.SyntaxError=class{constructor(e,t,n){this.start=t,this.end=n,this.message=e}toString(){return`${JSON.stringify(this.start)}, ${JSON.stringify(this.end)}: ${this.message}`}},SimTool.SyntaxWarning=class{constructor(e,t,n){this.start=t,this.end=n,this.message=e}toString(){return`${JSON.stringify(this.start)}, ${JSON.stringify(this.end)}: ${this.message}`}},SimTool.Token=class{constructor(e,t,n,i){this.type=e,this.token=t,this.start=n,this.end=i}asSyntaxError(e){return new SimTool.SyntaxError(e||this.token,this.start,this.end)}locationString(e){return void 0===e&&(e=this.start),`${e[0]}:locn[1]}:locn[2]}`}lineString(e){return void 0===e&&(e=this.start),`${this.start[0]}:${this.start[1]}`}url(e){return`<a href="#" class="sim_tool-show-error" estart="${`${this.start[0]},${this.start[1]},${this.start[2]}`}" eend="${`${this.end[0]},${this.end[1]},${this.end[2]}`}">${e||this.lineString()}</a>`}toJSON(){return`[${this.type} '${this.token.toString()}' ${this.start[0]}:${this.start[1]}:${this.start[2]} ${this.end[0]}:${this.end[1]}:${this.end[2]}]`}},SimTool.BufferStream=class{constructor(){this.buffer_list=[],this.state=void 0}push_buffer(e,t){const n=t.split("\n");this.state={pos:0,string:n[0],lines:n,line_number:0,buffer_name:e},this.buffer_list.push(this.state)}reset_state(){this.state.pos=0,this.state.line_number=0,this.state.string=this.state.lines[0]}get buffer_name(){if(void 0!==this.state)return this.state.buffer_name}get line_number(){if(void 0!==this.state)return this.state.line_number+1}get column(){if(void 0!==this.state)return this.state.pos+1}set column(e){this.state&&(this.state.pos=e-1)}get location(){if(void 0!==this.state)return[this.state.buffer_name,this.state.line_number+1,this.state.pos+1]}next_line(e){if(void 0===this.state)return!1;if(this.state.line_number+=1,this.state.line_number<this.state.lines.length)this.state.string=this.state.lines[this.state.line_number],this.state.pos=0;else{if(e)return!1;this.buffer_list.pop(),this.state=this.buffer_list[this.buffer_list.length-1]}return!0}eol(){return void 0===this.state||this.state.pos>=this.state.string.length}sol(){return void 0===this.state||0===this.state.pos}peek(){if(void 0!==this.state)return this.state.string.charAt(this.state.pos)}next(){if(!(void 0===this.state||this.state.pos>=this.state.string.length))return this.state.string.charAt(this.state.pos++)}eat(e){if(void 0===this.state)return;const t=this.state.string.charAt(this.state.pos);return("string"==typeof e?t===e:t&&(e.test?e.test(t):e(t)))?(this.state.pos+=1,t):void 0}eatWhile(e){if(void 0===this.state)return;const t=this.state.pos;for(;this.eat(e););return this.state.pos>t}eatSpace(){if(void 0===this.state)return;const e=this.state.pos;for(;/[\s\u00a0]/.test(this.state.string.charAt(this.state.pos))&&!this.eol();)this.state.pos+=1;return this.state.pos>e}skipToEnd(){this.state&&(this.state.pos=this.state.string.length)}skipTo(e){if(void 0===this.state)return;const t=this.state.string.indexOf(e,this.state.pos);return t>-1?(this.state.pos=t,!0):void 0}backUp(e){this.state&&(this.state.pos-=e)}match(e,t,n){if(void 0!==this.state){if("string"!=typeof e){const n=this.state.string.slice(this.state.pos).match(e);return n&&n.index>0?null:(n&&!1!==t&&(this.state.pos+=n[0].length),n)}{const i=function(e){return n?e.toLowerCase():e},r=this.state.string.substr(this.state.pos,e.length);if(i(r)===i(e))return!1!==t&&(this.state.pos+=e.length),r}}}},SimTool.TokenStream=class extends SimTool.BufferStream{constructor(e){super(),this.options=e,void 0!==this.options.block_comment_end&&(this.options.block_comment_end_pattern=new RegExp("^.*?"+this.options.block_comment_end.replace("*","\\*"))),this.token=void 0,this.token_buffers=[],this.token_state=void 0}push_tokens(e){this.token_state={pos:0,tokens:e[0],lines:e,line_number:0},this.token_buffers.push(this.token_state)}match(e,t,n){if(void 0!==this.token_state){const n=this.token_state.tokens[this.token_state.pos+1];return n&&n.token===e?(!1!==t&&(this.token_state.pos+=1),n.token):void 0}return super.match(e,t,n)}eol(){return void 0!==this.token_state?this.token_state.pos>=this.token_state.tokens.length:super.eol()}next_line(){return void 0!==this.token_state?(this.token_state.line_number+=1,this.token_state.line_number<this.token_state.lines.length?(this.token_state.tokens=this.token_state.lines[this.token_state.line_number],this.token_state.pos=0):(this.token_buffers.pop(),this.token_state=this.token_buffers[this.token_buffers.length-1]),!0):super.next_line()}read_string_char(e){const t=this.location;let n,i=this.next();switch(i){case e:return!1;case"\\":if(n=this.match(/^[0-7]{1,3}/),n){const e=parseInt(n[0],8);if(e>255)throw this.syntax_error("Octal escape sequence \\"+n+" is larger than one byte (max is \\377)",t,this.location);return String.fromCharCode(e)}switch(i=this.next(),i){case"b":return"\b";case"f":return"\f";case"n":return"\n";case"r":return"\r";case"t":return"\t";case'"':return'"';case"'":return"'";case"\\":return"\\";default:throw this.syntax_error("Unknown escape sequence \\"+i+". (if you want a literal backslash, try \\\\)",t,this.location)}default:return i}}make_token(e,t,n,i){return new SimTool.Token(e,t,n,i)}syntax_error(e,t,n){throw new SimTool.SyntaxError(e,t,n)}eat_space_and_comments(){for(;!this.eol();){this.eatSpace();const e=this.location;if(void 0!==this.options.line_comment&&this.match(this.options.line_comment))this.skipToEnd();else{if(!this.options.block_comment_start||!this.match(this.options.block_comment_start))break;for(;!this.match(this.options.block_comment_end_pattern);)if(this.skipToEnd(),!this.next_line(!0))throw this.syntax_error("Unterminated block comment",e,this.location)}}}next_token(){if(void 0!==this.token_state)return this.token=this.token_state.tokens[this.token_state.pos++],this.token;let e,t,n;for(;!this.eol()&&(this.eat_space_and_comments(),!this.eol());){if(n=this.location,this.options.next_token&&(this.token=this.options.next_token(this),void 0!==this.token))return this.token;if(this.match("'")){t="number",e=BigInt(this.read_string_char().charCodeAt(0));break}if(this.match('"')){e="",t="string";let i=!0;for(;!this.eol();){const t=this.read_string_char('"');if(!1===t){i=!1;break}e+=t}if(i)throw this.syntax_error("Unterminated string constant",n,this.location);break}if(t="label",e=this.match(/^([._$A-Z][._$A-Z0-9]*):/i),e){e=e[1];break}if(t="local_label",e=this.match(/^(\d):/i),e){e=e[1];break}if(t="symbol",e=this.match(/^[._$A-Z][._$A-Z0-9]*/i),e){e=e[0];break}if(t="local_symbol",e=this.match(/^\d[fb]/i),e){e=e[0];break}if(t="number",e=this.match(/^0x[0-9a-f]*/i),e){e=BigInt(e[0]);break}if(e=this.match(/^0b[01]*/i),e){e=BigInt(e[0]);break}if(e=this.match(/^0[0-7]*/),e){e=BigInt(e[0],8);break}if(e=this.match(/^[1-9][0-9]*/),e){e=BigInt(e[0]);break}if(t="operator",e=this.match(/^\+\+|--|>>>|>>|<<|\*\*|==|!=/),e){e=e[0];break}if(e=this.match(/[-#,;!()[\]{}\\+*/%=~&|^]/),e){e=e[0];break}if(!this.eol())throw e=this.next(),this.syntax_error("Unexpected character",n,this.location);e=void 0,t=void 0}return this.token=void 0===t?void 0:new SimTool.Token(t,e,n,this.location),this.token}},SimTool.CPUTool=class extends SimTool{constructor(e,t,n,i){super(e,t||"cpu_tool.21",n,i),this.emulation_initialize(),void 0===this.directives&&(this.directives=new Map),this.add_built_in_directives(),this.cpu_gui_setup(),this.reset_action(),tool=this}template_simulator_header='\n<div class="cpu_tool-simulator-header">\n <button id="reset" class="cpu_tool-simulator-control btn btn-sm btn-primary" disabled>Reset</button>\n <button id="step" class="cpu_tool-simulator-control btn btn-sm btn-primary" disabled>Step</button>\n <button id="walk" class="cpu_tool-simulator-control btn btn-sm btn-primary" disabled>Walk</button>\n <button id="walk-stop" class="cpu_tool-simulator-control cpu_tool-walk-stop btn btn-sm btn-danger">Stop</button>\n <button id="run" class="cpu_tool-simulator-control btn btn-sm btn-primary" disabled>Run</button>\n <button id="run-stop" class="cpu_tool-simulator-control cpu_tool-run-stop btn btn-sm btn-danger">Stop</button>\n <div id="running" class="cpu_tool-running"></div>\n <div style="float:right;"><button id="show-console" class="cpu_tool-show-console">Show console</button></div>\n</div>\n';template_64bit='\n<div>\n <div class="cpu_tool-banner">Registers</div>\n <div id="registers" class="cpu_tool-pane cpu_tool-regs"></div>\n</div>\n<div class="cpu_tool-memories">\n <div style="flex: 1 0 auto; display: flex; flex-flow: column;">\n <div class="cpu_tool-banner">Disassembly</div>\n <div id="disassembly" style="flex: 1 1 auto;" class="cpu_tool-pane cpu_tool-disassembly"></div>\n </div>\n <div style="flex: 0 0 auto; display: flex; flex-flow: column;">\n <div class="cpu_tool-banner">Memory</div>\n <div id="memory" style="flex: 1 1 auto;" class="cpu_tool-pane cpu_tool-memory"></div>\n </div>\n \x3c!--\n <div style="flex: 0 0 auto; display: flex; flex-flow: column;">\n <div class="cpu_tool-banner">Stack</div>\n <div id="stack" style="flex: 1 1 auto;" class="cpu_tool-pane cpu_tool-stack"></div>\n </div>\n --\x3e\n</div>\n<div id="console-wrapper" class="cpu_tool-console-wrapper">\n <div class="cpu_tool-banner">Console</div>\n <textarea id="console" class="cpu_tool-console"></textara>\n</div>\n';template_32bit='\n<div style="overflow-y: hidden; display: flex; flex-flow: row; gap: 5px;">\n <div style="flex: 0 0 auto; display: flex; flex-flow: column;">\n <div class="cpu_tool-banner">Registers</div>\n <div class="cpu_tool-pane cpu_tool-regs"></div>\n <div class="cpu_tool-banner">Disassembly</div>\n <div style="flex: 1 1 auto;" class="cpu_tool-pane cpu_tool-disassembly"></div>\n </div>\n <div style="flex: 0 0 auto; display: flex; flex-flow: column;">\n <div class="cpu_tool-banner">Memory</div>\n <div style="flex: 1 1 auto;" class="cpu_tool-pane cpu_tool-memory"></div>\n </div>\n \x3c!--\n <div style="flex: 0 0 auto; display: flex; flex-flow: column;">\n <div class="cpu_tool-banner">Stack</div>\n <div style="flex: 1 1 auto;" class="cpu_tool-pane cpu_tool-stack"></div>\n </div>\n --\x3e\n</div>\n<div class="cpu_tool-console-wrapper">\n <div class="cpu_tool-banner">Console</div>\n <textarea class="cpu_tool-console"></textara>\n</div>\n';cpu_gui_simulation_controls(){this.reset_button=this.right.querySelector("#reset"),this.step_button=this.right.querySelector("#step"),this.walk_button=this.right.querySelector("#walk"),this.walk_stop_button=this.right.querySelector("#walk-stop"),this.run_button=this.right.querySelector("#run"),this.run_stop_button=this.right.querySelector("#run-stop"),this.running=this.right.querySelector("#running");const e=this;this.reset_button.addEventListener("click",(function(){e.reset_action()})),this.step_button.addEventListener("click",(function(){e.step_action()})),this.walk_button.addEventListener("click",(function(){e.walk_action()})),this.walk_stop_button.addEventListener("click",(function(){e.stop_action()})),this.run_button.addEventListener("click",(function(){e.run_action()})),this.run_stop_button.addEventListener("click",(function(){e.stop_action()}))}gutter_list(){return[{className:"CodeMirror-linenumbers"},{className:"cpu_tool-breakpoint"}]}gutter_click(e,t,n,i){if("cpu_tool-breakpoint"===n){const i=e.lineInfo(t);i.gutterMarkers&&i.gutterMarkers[n]?e.setGutterMarker(t,n,null):e.tool.set_breakpoint(e,t)}}set_breakpoint(e,t){const n=document.createElement("div");n.innerHTML='<div style="color:red; text-align: center;">●</div>',e.setGutterMarker(t,"cpu_tool-breakpoint",n.firstChild)}editor_before_change(e,t){e.tool.clear_highlights()}get_breakpoints(){const e=[];for(let t of this.editor_list){const n=t.CodeMirror;let i=0;n.eachLine((function(t){i+=1,t.gutterMarkers&&t.gutterMarkers["cpu_tool-breakpoint"]&&(t.buffer_name=n.buffer_name,t.line_number=i,e.push(t))}))}return e}set_breakpoints(e){if(this.source_map){for(let e of this.source_map)e&&(e.breakpoint=!1);if(!e)for(let e of this.get_breakpoints()){const t=e.buffer_name,n=e.line_number;for(let e of this.source_map)if(e&&e.start[0]===t&&e.start[1]>=n){e.breakpoint=!0;break}}}}cpu_gui_setup(){const e=this;this.add_action_button("Assemble",(function(){e.assemble()})),this.right.innerHTML=64==this.register_nbits?this.template_simulator_header+this.template_64bit:this.template_simulator_header+this.template_32bit,this.cpu_gui_simulation_controls(),this.regs_div=this.right.querySelector("#registers"),this.disassembly=this.right.querySelector("#disassembly"),this.memory_div=this.right.querySelector("#memory");const t=this;this.console=this.right.querySelector("#console");const n=this.right.querySelector("#show-console"),i=this.right.querySelector("#console-wrapper");n.addEventListener("click",(function(){"Show console"===n.innerHTML?(i.style.display="flex",n.innerHTML="Hide console"):(i.style.display="none",n.innerHTML="Show console")})),this.console_chars=[],this.mouse_click=-1,this.console.addEventListener("beforeinput",(function(e){let n;return"insertLineBreak"===e.inputType?n="\n":"deleteContentBackward"===e.inputType?n="":"insertText"===e.inputType&&(n=e.data),n&&t.console_chars.length<8&&t.console_chars.push(n),e.preventDefault(),!1})),this.console.addEventListener("mousedown",(function(e){this.console.focus(),this.mouse_click=((65535&e.clientX)<<16)+(65535&e.clientY)}))}reset_controls(){this.reset_button.disabled=!1,this.step_button.disabled=!1,this.walk_button.disabled=!1,this.run_button.disabled=!1,this.walk_button.style.display="inline-block",this.walk_stop_button.style.display="none",this.run_button.style.display="inline-block",this.run_stop_button.style.display="none",this.running.style.display="none"}reset_action(){this.clear_message(),this.emulation_reset(),this.fill_in_simulator_gui(),this.next_pc(),this.reset_controls(),void 0!==this.console&&(this.console.value="",this.console.setSelectionRange(0,0))}stop_action(){this.stop_request=!0}execution_halted(e){this.err=e,this.next_pc();let t="Oops, execution error";if(void 0!==this.emulation_pc()&&(t+=` detected at pc = 0x${this.emulation_pc().toString(16)}`),t+=": ","string"==typeof e){if("Halt Execution"===e)return;t+=e}else e instanceof RangeError?t+="memory address out of bounds":t+=`internal error (${e.message})`;setTimeout((function(){alert(t)}),1)}step_action(){this.err=void 0,this.clear_message(),this.set_breakpoints(!0);try{void 0!==this.console&&this.console.focus(),this.emulation_step(!0)}catch(e){this.execution_halted(e)}}walk_action(){void 0!==this.console&&this.console.focus(),this.clear_message(),this.err=void 0;const e=this;this.stop_request=!1,this.reset_button.disabled=!0,this.step_button.disabled=!0,this.walk_button.style.display="none",this.walk_stop_button.style.display="inline-block",this.run_button.disabled=!0,this.running.style.display="none",this.set_breakpoints(),setTimeout((function t(){if(e.stop_request)e.reset_controls();else try{e.emulation_step(!0),setTimeout(t,1)}catch(t){e.reset_controls(),e.execution_halted(t)}}),0)}grey_out_state(e){for(let t of this.right.getElementsByClassName("cpu_tool-pane"))t.style.opacity=e?"20%":"100%"}run_action(){void 0!==this.console&&this.console.focus(),this.clear_message(),this.err=void 0;const e=this,t=this.ncycles,n=new Date;function i(){if(e.grey_out_state(!1),e.reset_controls(),e.fill_in_simulator_gui(),"Halt Execution"===e.err||void 0===e.err){const i=((new Date).getTime()-n.getTime())/1e3,r=e.ncycles-t;console.log(`Emulation stats: ${r.toLocaleString("en-US")} instructions in ${i} seconds = ${Math.round(r/i).toLocaleString("en-US")} instructions/sec`)}}const r=e.quanta||1e6;this.clear_highlights(),this.stop_request=!1,this.reset_button.disabled=!0,this.step_button.disabled=!0,this.walk_button.disabled=!0,this.run_button.style.display="none",this.run_stop_button.style.display="inline-block",this.running.style.display="inline-block",this.grey_out_state(!0),this.set_breakpoints(),setTimeout((function t(){if(e.stop_request)i();else try{for(let t=r;t>0;t-=1)e.emulation_step(!1);setTimeout(t,0)}catch(t){i(),e.execution_halted(t)}}),0)}emulation_initialize(){this.line_comment="#",this.block_comment_start="/*",this.block_comment_end="*/",this.little_endian=!0,this.data_section_alignment=256,this.bss_section_alignment=8,this.address_space_alignment=256,this.memory=new SimTool.Memory(this.little_endian),this.source_highlight=void 0,this.source_map=[],this.inst_decode=[],this.register_file=new Array(32),this.register_names=new Array(32);for(let e=0;e<this.register_file.length;e+=1)this.register_names[e]="r"+e;this.emulation_reset()}emulation_pc(){return 0}emulation_reset(){this.ncycles=0,this.clear_highlights()}emulation_step(e){}disassemble(e){return"???"}fill_in_simulator_gui(){let e;this.right.focus();const t=Math.ceil(Math.log2(this.memory.byteLength)/4);if(void 0!==this.register_file){e=['<table cellpadding="2px" border="0" style="border-collapse: collapse;">'];const t=Math.ceil(this.register_names.length/4);for(let n=0;n<t;n+=1){const i=["<tr>"];for(let e=n;e<4*t;e+=t)if(e<this.register_names.length){const t=this.register_file[e];i.push(`<td class="cpu_tool-addr">${this.register_names[e]}</td>`),i.push(`<td ${t?"":'class="cpu_tool-unused"'} id="r${e}">${this.hexify(t,this.register_nbits/4)}</td>`)}else i.push("<td></td><td></td>");i.push("</tr>"),e.push(i.join(""))}if(this.extra_registers(e),this.caches)for(let t=0;t<this.caches.length;t+=1){const n=this.caches[t];e.push(`<tr><td class="cpu_tool-cache" colspan="8">Cache(${n.description()}) <span id="cache-${t}"></span></td></td>`)}e.push("</table>"),this.regs_div.innerHTML=e.join("")}e=['<table class="cpu_tool-disassembly" cellpadding="2px" border="0">'];for(let n=0;n<this.memory.byteLength;n+=this.inst_nbits/8){let i=this.hexify(n,t),r="";this.label_table&&this.label_table.has(n)&&(r=this.label_table.get(n),/L\d\*\d+/.test(r)&&(r=r.charAt(1)),r+=":",r.length>10&&(r=r.slice(0,9)+"…:"));const s=this.disassemble(n);e.push(`<tr><td class="cpu_tool-addr">${i}</td>\n <td>${this.location(n,this.inst_nbits)}</td>\n <td class="cpu_tool-label">${r}</td>\n <td id="i${n}"><div class="cpu_tool-inst">${s?s.assy:"???"}</div></td>\n </tr>`)}e.push("</table>"),this.disassembly.innerHTML=e.join(""),e=['<table cellpadding="2px" border="0">'];for(let n=0;n<this.memory.byteLength;n+=this.word_nbits/8)e.push(`<tr>\n <td class="cpu_tool-addr">${this.hexify(n,t)}</td>\n <td id="m${n}">${this.location(n)}</td>\n </tr>`);e.push("</table>"),this.memory_div.innerHTML=e.join("")}extra_registers(){}is_visible(e,t){const n=e.getBoundingClientRect(),i=t.getBoundingClientRect();return n.top>=i.top&&n.bottom<=i.bottom}remove_class(e,t){void 0===t&&(t=this.right);const n=Array.from(t.getElementsByClassName(e));for(let t of n)t.classList.remove(e)}clear_highlights(){this.remove_class("cpu_tool-reg-read",this.regs_div),this.remove_class("cpu_tool-reg-write",this.regs_div),this.remove_class("cpu_tool-mem-read",this.memory_div),this.remove_class("cpu_tool-mem-write",this.memory_div),this.remove_class("cpu_tool-next_inst",this.disassembly),this.source_highlight&&(this.source_highlight.doc.removeLineClass(this.source_highlight.line,"background","cpu_tool-next-inst"),this.source_highlight=void 0)}reg_read(e){const t=this.right.querySelector("#r"+e);t&&(t.classList.remove("cpu_tool-unused"),t.classList.add("cpu_tool-reg-read"))}reg_write(e,t){if(-1===e)return;const n=this.right.querySelector("#r"+e);n&&(n.classList.remove("cpu_tool-unused"),n.classList.add("cpu_tool-reg-write"),n.innerHTML=this.hexify(t,this.register_nbits/4))}mem_read(e,t){let n;e&=~(this.word_nbits/8-1),64===t&&(n=this.right.querySelector("#m"+(e+4)),n.classList.add("cpu_tool-mem-read")),n=this.right.querySelector("#m"+e),n.classList.add("cpu_tool-mem-read"),this.is_visible(n,this.memory_div)||n.scrollIntoView({block:"center"})}mem_write(e,t,n){e&=-4;let i=this.right.querySelector("#m"+e);i.classList.add("cpu_tool-mem-write"),i.innerHTML=this.hexify(0xFFFFFFFFn&t,8),64===n&&(i=this.right.querySelector("#m"+(e+4)),i.classList.add("cpu_tool-mem-write"),i.innerHTML=this.hexify(t>>32n&0xFFFFFFFFn,8)),this.is_visible(i,this.memory_div)||i.scrollIntoView({block:"center"})}next_pc(){for(let e of this.disassembly.getElementsByClassName("cpu_tool-next-inst"))e.classList.remove("cpu_tool-next-inst");this.source_highlight&&(this.source_highlight.doc.removeLineClass(this.source_highlight.line,"background","cpu_tool-next-inst"),this.source_highlight=void 0);const e=this.emulation_pc(),t=this.right.querySelector("#i"+e);if(t&&(t.parentElement.classList.add("cpu_tool-next-inst"),this.is_visible(t,this.disassembly)||t.scrollIntoView({block:"center"})),this.source_map){const t=this.va_to_phys(e),n=this.source_map[t/4];if(n){const e=this.select_buffer(n.start[0]);if(e){const t=e.CodeMirror.doc;t.addLineClass(n.start[1]-1,"background","cpu_tool-next-inst"),this.source_highlight={doc:t,line:n.start[1]-1},e.CodeMirror.scrollIntoView({line:n.start[1]-1,ch:n.start[2]})}}}if(this.caches)for(let e=0;e<this.caches.length;e+=1){const t=this.caches[e];document.getElementById("cache-"+e).innerHTML=t.report_statistics()}}console_output(e){if(void 0===this.console)return;let t=this.console.value;""===e?t=t.slice(0,t.length-1):t+=e,this.console.value=t,this.console.focus(),this.console.setSelectionRange(t.length,t.length),this.console.scrollTop=this.console.scrollHeight}console_input(){if(void 0!==this.console)return this.console_chars.shift()}mouse_click(){const e=this.mouse_click;return this.mouse_click=-1,e}syntax_error(e,t,n){throw new SimTool.SyntaxError(e,t,n)}syntax_warning(e,t,n){throw new SimTool.SyntaxWarning(e,t,n)}add_built_in_directives(){const e=this;this.directives.set(".align",(function(t,n){return e.directive_align(t,n)})),this.directives.set(".ascii",(function(t,n){return e.directive_ascii(t,n)})),this.directives.set(".asciz",(function(t,n){return e.directive_ascii(t,n)})),this.directives.set(".averify",(function(t,n){return e.directive_averify(t,n)})),this.directives.set(".mverify",(function(t,n){return e.directive_mverify(t,n)})),this.directives.set(".bss",(function(t,n){return e.directive_section(t,n)})),this.directives.set(".breakpoint",(function(t,n){return e.directive_breakpoint(t,n)})),this.directives.set(".byte",(function(t,n){return e.directive_storage(t,n)})),this.directives.set(".cache",(function(t,n){return e.directive_cache(t,n)})),this.directives.set(".data",(function(t,n){return e.directive_section(t,n)})),this.directives.set(".long",(function(t,n){return e.directive_storage(t,n)})),this.directives.set(".global",(function(t,n){return e.directive_global(t,n)})),this.directives.set(".hword",(function(t,n){return e.directive_storage(t,n)})),this.directives.set(".include",(function(t,n){return e.directive_include(t,n)})),this.directives.set(".long",(function(t,n){return e.directive_storage(t,n)})),this.directives.set(".macro",(function(t,n){return e.directive_macro(t,n)})),this.directives.set(".section",(function(t,n){return e.directive_section(t,n)})),this.directives.set(".text",(function(t,n){return e.directive_section(t,n)})),this.directives.set(".word",(function(t,n){return e.directive_storage(t,n)}))}assemble(){this.clear_message(),this.error_div.style.display="none";const e=this.selector.value;this.buffer_map=new Map;for(let e of this.editor_list)this.buffer_map.set(e.id,e.CodeMirror.doc.getValue());if(this.stream=new SimTool.TokenStream(this),this.assembly_warnings=[],this.assembly_errors=[],this.address_spaces=new Map,this.current_aspace=this.add_aspace("kernel"),this.current_section=void 0,this.macro_map=new Map,this.assembler_memory=void 0,this.mverify=[],this.caches=[],this.source_map=[],this.pass=0,this.next_pass(),this.stream.push_buffer(e,this.buffer_map.get(e)),this.assembly_prologue&&this.stream.push_buffer("prologue",this.assembly_prologue),this.assemble_buffer(),0===this.assembly_errors.length&&(this.next_pass(),this.stream.push_buffer(e,this.buffer_map.get(e)),this.assembly_prologue&&this.stream.push_buffer("prologue",this.assembly_prologue),this.assemble_buffer(),console.log(this)),this.assembly_errors.length>0)this.left_pane_only(),this.handle_errors(this.assembly_errors);else{this.handle_errors([],this.assembly_warnings),this.configuration.checksum=void 0,this.build_label_table(),this.inst_decode&&this.inst_decode.fill(void 0),this.reset_action();const e=100*(this.right.scrollWidth+this.divider.offsetWidth+27)/this.left.parentElement.offsetWidth;this.left.style.width=Math.max(0,100-e)+"%"}}next_pass(){if(this.pass+=1,!(this.pass>2)){if(this.pass,2===this.pass){let e=0;for(let t of this.address_spaces.values()){const n=t.sections.get(".text");n.base=0,n.dot=this.align(n.dot,this.data_section_alignment||8);const i=t.sections.get(".data");i.base=n.dot,i.dot=this.align(i.dot,this.bss_section_alignment||8);const r=t.sections.get(".bss");r.base=i.base+i.dot,r.dot=this.align(r.dot,this.address_space_alignment||8),t.base=e,t.size=r.base+r.dot,this.add_symbol(`_${t.name}_base_`,t.base,"kernel"),this.add_symbol(`_${t.name}_bounds_`,t.size,"kernel"),e+=t.size}this.assembler_memory=new DataView(new ArrayBuffer(e))}for(let e of this.address_spaces.values())if(e.local_label_index.clear(),this.pass>1)for(let t of e.sections.values())t.dot=0;this.macro_map.clear(),this.change_section(".text","kernel")}}emit8(e){this.assembler_memory&&this.assembler_memory.setUint8(this.dot(!0),Number(e),this.little_endian),this.incr_dot(1)}emit16(e){this.assembler_memory&&this.assembler_memory.setUint16(this.dot(!0),Number(e),this.little_endian),this.incr_dot(2)}emit32(e){this.assembler_memory&&this.assembler_memory.setUint32(this.dot(!0),Number(e),this.little_endian),this.incr_dot(4)}emit64(e){this.assembler_memory&&this.assembler_memory.setBigUint64(this.dot(!0),e,this.little_endian),this.incr_dot(8)}location(e,t){if(this.memory&&this.memory.memory){let n;return void 0===t&&(t=this.word_nbits),n=t<=32?this.memory.memory.getUint32(e,this.little_endian):this.memory.memory.getBigUint64(e,this.little_endian),this.hexify(n,t/4)}}verify_memory(){const e=new Array(256);for(let t=0;t<256;t+=1){let n=t;for(let e=0;e<8;e+=1)n=1&n?3988292384^n>>>1:n>>>1;e[t]=n}this.configuration.checksum="";let t,n=-1;for(let i=0;i<this.mverify.length;i+=2){const r=this.mverify[i],s=this.mverify[i+1],o=this.memory.memory.getUint32(r,this.little_endian);if(o!==s){t=`Memory verification mismatch at location 0x${r.toString(16)}, expected 0x${s.toString(16).padStart(8,"0")}, got 0x${o.toString(16).padStart(8,"0")}`;break}n=n>>>8^e[255&(n^o)],n=n>>>8^e[255&(n^o>>>8)],n=n>>>8^e[255&(n^o>>>16)],n=n>>>8^e[255&(n^o>>>24)]}if(t)setTimeout((function(){alert(t)}),1);else{this.configuration.checksum=((-1^n)>>>0).toString(16).padStart(8,"0").toUpperCase();let e=`Executed HLT instruction at pc = 0x${this.emulation_pc().toString(16)}.`;-1!==n&&(e+=`\n\nMemory verification successful! (checksum ${this.configuration.checksum})`),setTimeout((function(){alert(e)}),1)}}add_aspace(e){let t=this.address_spaces.get(e);return void 0===t&&(t={},t.name=e,t.sections=new Map,t.sections.set(".text",{aspace:t,name:".text",dot:0,base:0}),t.sections.set(".data",{aspace:t,name:".data",dot:0,base:0}),t.sections.set(".bss",{aspace:t,name:".bss",dot:0,base:0}),t.symbol_table=new Map,t.local_label_index=new Map,t.base=0,t.size=0,this.address_spaces.set(e,t)),t}pa2va(e){if(void 0!==e&&void 0!==this.address_spaces)for(let t of this.address_spaces.values()){const n=e-t.base;if(e>=t.base&&n<=t.size)return n}}change_section(e,t){return t&&(this.current_aspace=this.add_aspace(t)),this.current_aspace.sections.has(e)&&(this.current_section=this.current_aspace.sections.get(e)),this.current_section}align(e,t){const n=e%t;return n>0?e+t-n:e}align_dot(e){this.current_section.dot=this.align(this.current_section.dot,e)}incr_dot(e){return this.current_section.dot+=e,this.current_section.dot}dot(e){let t=this.current_section.dot;return e&&(t+=this.current_section.base+this.current_section.aspace.base),t}add_label(e,t,n){const i=n?this.address_spaces.get(n):this.current_aspace;if(void 0===i)return!1;const r=t?i.sections.get(t):this.current_section;if(void 0===r)return!1;let s=e.token;if("local_label"===e.type){const e=(i.local_label_index.get(s)||0)+1;i.local_label_index.set(s,e),s="L"+s+"*"+e.toString()}else if(1===this.pass){const t=i.symbol_table.get(s);if(void 0!==t)throw e.asSyntaxError(`Duplicate label definition for "${s}", originally defined at ${t.definition.url()}`)}return i.symbol_table.set(s,{type:"label",definition:e,name:s,section:r,value:r.dot}),!0}add_symbol(e,t,n){const i=n?this.address_spaces.get(n):this.current_aspace;if(void 0===i)return!1;let r=i.symbol_table.get(e);return void 0===r&&(r={type:"symbol",name:e,section:void 0},i.symbol_table.set(e,r)),r.definition=r,r.value=t,!0}symbol_value(e,t,n){const i=n?this.address_spaces.get(n):this.current_aspace;if(void 0===i)return!1;if("."===e)return this.dot(t);let r=e;if(/\d[fb]/.test(e)){const t=e.charAt(e.length-1);e=e.slice(0,-1);let n=i.local_label_index.get(e)||0;"f"===t&&(n+=1),r="L"+e+"*"+n.toString()}const s=i.symbol_table.get(r);if(void 0===s)return;let o=s.value;return"label"===s.type&&(o+=s.section.base,t&&(o+=s.section.aspace.base)),o}build_label_table(){this.label_table=new Map;for(let e of this.address_spaces.keys()){const t=this.address_spaces.get(e);for(let n of t.symbol_table.keys())void 0!==t.symbol_table.get(n).section&&this.label_table.set(this.symbol_value(n,!0,e),n)}}expect_token(e,t){return 1==e.length&&e[0].type==t||this.syntax_error(`Expected ${t}`,e[0].start,e[e.length-1].end),e[0].token}directive_breakpoint(e,t){if(0!==t.length)throw e.asSyntaxError(".breakpoint does not expect arguments");for(let t of this.editor_list)if(t.id===e.start[0]){this.set_breakpoint(t.CodeMirror,e.start[1]-1);break}return!0}directive_align(e,t){if(1!==t.length)throw e.asSyntaxError("Expected one argument");const n=Number(this.eval_expression(this.read_expression(t[0])));if(n<1||n>12)throw e.asSyntaxError("Expected a single numeric argument between 1 and 12");return this.align_dot(2<<n),!0}directive_ascii(e,t){for(let n of t){const t=this.expect_token(n,"string");for(let e=0;e<t.length;e+=1)this.emit8(t.charCodeAt(e));".asciz"===e.token&&this.emit8(0)}return!0}directive_averify(e,t){if(2===this.pass){let e;for(let n of t){const t=Number(this.eval_expression(this.read_expression(n)));if(void 0===e)e=t;else{const i=e<this.assembler_memory.byteLength?this.assembler_memory.getUint32(e,this.little_endian):void 0;void 0===i?this.syntax_error(`.averify address (0x${this.hexify(e)}) out of range`,n[0].start,n[n.length-1].end):t!==i&&this.syntax_warning(`Assembly mismatch at location 0x${this.hexify(e)}: expected 0x${this.hexify(t,8)}, got 0x${this.hexify(i,8)}`,n[0].start,n[n.length-1].end),e+=4}}}return!0}directive_mverify(e,t){if(2===this.pass){let e;for(let n of t){const t=Number(this.eval_expression(this.read_expression(n)));void 0===e?e=t:(this.mverify.push(e),this.mverify.push(t),e+=4)}}return!0}directive_global(e,t){for(let e of t){const t=this.expect_token(e,"symbol");2===this.pass&&void 0===this.symbol_value(t)&&this.syntax_error("Undefined symbol",e[0].start,e[0].end)}return!0}directive_include(e,t){if(1!=t.length||1!=t[0].length||"string"!=t[0][0].type)throw e.asSyntaxError("Expected a single string argument");const n=t[0][0].token;if(!this.buffer_map.has(n))throw t[0][0].asSyntaxError(`Cannot find buffer "${n}"`);return this.stream.push_buffer(n,this.buffer_map.get(n)),!0}directive_macro(e,t){for(let e=1;e<t.length;e+=1)for(let n of t[e])t[0].push(n);if(0===(t=t[0]).length)throw e.asSyntaxError('".macro" should be followed the macro name');if("symbol"!=t[0].type)throw t[0].asSyntaxError("Expected symbol as name of macro");const n={name:t[0].token,arguments:[],body:[]};for(let e=1;e<t.length;e+=1){if("symbol"!=t[e].type)throw t[e].asSyntaxError("Expected symbol as macro argument name");n.arguments.push(t[e])}let i=1;do{const e=this.stream.next_token();if(void 0===e)continue;if(".endm"===e.token){if(i-=1,0===i)break}else".macro"===e.token&&(i+=1);let t=[e];for(n.body.push(t);!this.stream.eol();){let e=this.stream.next_token();";"===e.token&&(e=this.stream.next_token(),e)?(t=[e],n.body.push(t)):t.push(e)}}while(this.stream.next_line());if(0!=i)throw e.asSyntaxError("no .endm found for this macro");return this.macro_map.set(n.name,n),!0}directive_section(e,t){".section"===e.token&&((1!=(e=t[0]).length||"symbol"!=e[0].type||".text"!==e[0].token&&".data"!==e[0].token&&".bss"!==e[0].token)&&this.syntax_error("Expected .text, .data, or .bss",e[0].start,e[e.length-1].end),t=t.slice(1));let n=this.current_aspace.name;if(1===t.length)n=t[1],1==n.length&&"symbol"==n.token.type||this.syntax_error("Expected name of address space",n[0].start,n[e.length-1].end),n=n[0].token;else if(t.length>1){const e=t[t.length-1];this.syntax_error("Too many arguments!",t[1][0].start,e[e.length-1].end)}return this.change_section(e.token,n),!0}directive_storage(e,t){for(let n of t){let t,i=this.read_expression(n);if(i=2===this.pass?this.eval_expression(i):0n,".byte"===e.token?(t=this.dot(!0),this.emit8(i)):".hword"===e.token?(this.align_dot(2),t=this.dot(!0),this.emit16(i)):".word"===e.token?(this.align_dot(4),t=this.dot(!0),this.emit32(i)):".long"===e.token&&(this.align_dot(8),t=this.dot(!0),this.emit64(i)),2==this.pass&&this.source_map){const e={start:n[0].start,end:n[n.length-1].end,breakpoint:!1},i=this.dot(!0);for(let n=t;n<i;n+=4)this.source_map[n/4]=e}}return!0}directive_cache(e,t){5!=t.length&&this.syntax_error("Expected 5 arguments: blocksize,nlines,nways,replacement,writes",e.start,e.end);const n=Number(this.eval_expression(this.read_expression(t[0])));let i=n;if(i>0)for(;0==(1&i);)i>>=1;1!==i&&this.syntax_error("blocksize must be a power of two",t[0][0].start,t[0][t[0].length-1].end);const r=Number(this.eval_expression(this.read_expression(t[1])));if(i=r,i>0)for(;0==(1&i);)i>>=1;1!==i&&this.syntax_error("nlines must be a power of two",t[1][0].start,t[1][t[1].length-1].end);const s=Number(this.eval_expression(this.read_expression(t[2])));s<1&&this.syntax_error("nways must be >= 1",t[2][0].start,t[2][t[2].length-1].end);const o=this.expect_token(t[3],"symbol").toLowerCase();["lru","fifo","random","cycle"].includes(o)||this.syntax_error("replacement must be one of lru, fifo, random, or cycle",t[3][0].start,t[3][t[3].length-1].end);const a=this.expect_token(t[4],"symbol").toLowerCase();if(["writeback","writethough"].includes(a)||this.syntax_error("writes must be one of writeback or writethrough",t[4][0].start,t[4][t[4].length-1].end),2==this.pass){const e=new SimTool.Cache({blocksize:n,nlines:r,nways:s,replacement_strategy:o,write_back:"writeback"===a});this.caches.push(e)}return!0}read_expression(e,t){function n(){throw new SimTool.SyntaxError("Invalid expression",e[0].start,e[e.length-1].end)}function i(){const i=e[t];void 0===i&&n(),"+"!==i.token&&"-"!==i.token&&"~"!==i.token||(t+=1);let r=function(){let i=e[t];if(void 0===i&&n(),"number"===i.type||"symbol"===i.type||"local_symbol"===i.type)return t+=1,i;if("("===i.token){const n=i;t+=1;const r=h();if(i=e[t],i&&")"===i.token)return t+=1,r;throw n.asSyntaxError("Missing close parenthesis that matches this one")}throw i.asSyntaxError("Invalid expression")}();return"-"!==i.token&&"~"!==i.token||(r=[i,r]),r}function r(){let n=i();for(;;){const r=e[t];if(!r||"*"!==r.token&&"/"!==r.token&&"%"!==r.token)break;t+=1,n=[r,n,i()]}return n}function s(){let n=r();for(;;){const i=e[t];if(!i||"+"!==i.token&&"-"!==i.token)break;t+=1,n=[i,n,r()]}return n}function o(){let n=s();for(;;){const i=e[t];if(!i||"<<"!==i.token&&">>"!==i.token&&">>>"!==i.token)break;t+=1,n=[i,n,s()]}return n}function a(){let n=o();const i=e[t];return!i||"<"!==i.token&&"<="!==i.token&&">="!==i.token&&">"!==i.token||(t+=1,n=[i,n,o()]),n}function l(){let n=a();const i=e[t];return!i||"=="!==i.token&&"!="!==i.token||(t+=1,n=[i,n,a()]),n}function c(){let n=l();for(;;){const i=e[t];if(!i||"&"!==i.token)break;t+=1,n=[i,n,l()]}return n}function d(){let n=c();for(;;){const i=e[t];if(!i||"^"!==i.token)break;t+=1,n=[i,n,c()]}return n}function h(){return function(){let n=d();for(;;){const i=e[t];if(!i||"|"!==i.token)break;t+=1,n=[i,n,d()]}return n}()}void 0===t&&(t=0);const u=h();if(t!=e.length)throw new SimTool.SyntaxError("Extra tokens after expression ends",e[t].start,e[e.length-1].end);return u}eval_expression(e){if("number"===e.type)return e.token;if("symbol"===e.type||"local_symbol"===e.type){const t=this.symbol_value(e.token);if(void 0===t)throw e.asSyntaxError("Undefined symbol");return BigInt(t)}if(2===e.length)switch(e[0].token){case"-":return-this.eval_expression(e[1]);case"+":return this.eval_expression(e[1]);case"~":return~this.eval_expression(e[1]);default:throw e[0].asSyntaxError("Unrecognized unary operator")}else{const t=this.eval_expression(e[1]),n=this.eval_expression(e[2]);switch(e[0].token){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n;case"%":return t%n;case"&":return t&n;case"^":return t^n;case"|":return t|n;case"<<":return t<<n;case">>":return t>>n;case">>>":return BigInt.asUintN(64,t)>>n;case"==":return t==n?1n:0n;case"!=":return t!=n?1n:0n;case"<":return t<n?1n:0n;case"<=":return t<=n?1n:0n;case">=":return t>=n?1n:0n;case">":return t>n?1n:0n;default:throw e[0].asSyntaxError("Unrecognized binary operator")}}}expand_macro(e,t){const n=this.macro_map.get(e.token);if(t.length!=n.arguments.length)throw e.asSyntaxError(`Expected ${n.arguments.length} operands, got ${t.length}`);const i=new Map;for(let e=0;e<t.length;e+=1)i.set(n.arguments[e].token,t[e]);const r=[];for(let e of n.body){const t=[];r.push(t);for(let n=0;n<e.length;n+=1){const r=e[n];if("\\"===r.token){const r=e[n+1];if(r&&"symbol"===r.type&&i.has(r.token)){n+=1;const e=i.get(r.token);for(let n=0;n<e.length;n+=1)t.push(e[n]);continue}}t.push(r)}}this.stream.push_tokens(r)}read_operands(){const e=[],t=[];for(;;){let n;for(;;){const i=this.stream.next_token();if(void 0===i||";"===i.token){if(t.length>0){let e=t.pop();throw e.asSyntaxError(`Missing close ${e.token}`)}return e}if(void 0===n&&(n=[],e.push(n)),"("==i.token||"["==i.token||"{"==i.token)t.push(i);else if(")"==i.token){let e=t.pop();if(void 0===e)throw i.asSyntaxError('Missing matching "("');if("("!=e.token)throw e.asSyntaxError('Missing matching ")"')}else if("]"==i.token){let e=t.pop();if(void 0===e)throw i.asSyntaxError('Missing matching "["');if("["!=e.token)throw e.asSyntaxError('Missing matching "]"')}else if("}"==i.token){let e=t.pop();if(void 0===e)throw i.asSyntaxError('Missing matching "{"');if("{"!=e.token)throw e.asSyntaxError('Missing matching "}"')}else if(0===t.length&&","===i.token)break;n.push(i)}}}assemble_buffer(){do{try{for(;!this.stream.eol();){const e=this.stream.next_token();if(void 0===e)break;if(";"!==e.token){if("label"!==e.type&&"local_label"!==e.type){if("symbol"===e.type){if(this.stream.eat_space_and_comments(),this.stream.match("=")){const t=this.read_operands();1!==t.length&&this.syntax_error('single expression expected following "="',e.start,e.end);const n=this.eval_expression(this.read_expression(t[0]));"."===e.token?this.current_section.dot=Number(n):this.add_symbol(e.token,n);continue}if("."===e.token.charAt(0)){const t=this.read_operands(),n=this.directives.get(e.token);if(n&&n(e,t))continue;throw e.asSyntaxError(`Unrecognized directive: ${e.token}`)}if(this.macro_map.has(e.token)){const t=this.read_operands();this.expand_macro(e,t);continue}const t=this.read_operands();if(this.assemble_opcode(e,t))continue}throw e.asSyntaxError(`"${e.token}" not recognized as an opcode, directive, or macro name`,e.start,e.end)}this.add_label(e)}}}catch(e){if(e instanceof SimTool.SyntaxError)this.assembly_errors.push(e);else{if(!(e instanceof SimTool.SyntaxWarning))throw e;this.assembly_warnings.push(e)}}}while(this.stream.next_line())}assemble_opcode(e,t){return!1}},window.addEventListener("load",(function(){for(let e of document.getElementsByClassName("cpu_tool"))new SimTool.CPUTool(e)})),SimTool.Memory=class{constructor(e){this.little_endian=e,this.memory=void 0,this.caches=[],this.has_caches=!1,this.mask64=0xFFFFFFFFFFFFFFFFn}reset(e){void 0!==e&&e!==this.caches&&(this.caches=e,this.has_caches=e.length>0);for(let e of this.caches)e.reset()}get byteLength(){return void 0===this.memory?0:this.memory.byteLength}load_bytes(e){void 0!==this.memory&&this.memory.byteLength===e.byteLength||(this.memory=new DataView(new ArrayBuffer(e.byteLength))),new Uint8Array(this.memory.buffer).set(new Uint8Array(e.buffer)),this.reset()}read_int8(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return this.memory.getInt8(e)}read_bigint8(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return BigInt(this.memory.getInt8(e))&this.mask64}read_int16(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return this.memory.getInt16(e,this.little_endian)}read_int16_aligned(e){if(0!=(1&e))throw`Misaligned 16-bit read from address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.read(e,!1);return this.memory.getInt16(e,this.little_endian)}read_bigint16(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return BigInt(this.memory.getInt16(e,this.little_endian))&this.mask64}read_bigint16_aligned(e){if(0!=(1&e))throw`Misaligned 16-bit read from address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.read(e,!1);return BigInt(this.memory.getInt16(e,this.little_endian))&this.mask64}read_int32(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return this.memory.getInt32(e,this.little_endian)}read_int32_aligned(e){if(0!=(3&e))throw`Misaligned 32-bit read from address ${e}`;if(this.has_caches)for(let t of this.caches)t.read(e,!1);return this.memory.getInt32(e,this.little_endian)}read_bigint32(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return BigInt(this.memory.getInt32(e,this.little_endian))&this.mask64}read_bigint32_aligned(e){if(0!=(3&e))throw`Misaligned 32-bit read from address ${e}`;if(this.has_caches)for(let t of this.caches)t.read(e,!1);return BigInt(this.memory.getInt32(e,this.little_endian))&this.mask64}read_bigint64(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1),t.line_size<2&&t.read(e+4,!1);return this.memory.getBigUint64(e,this.little_endian)}read_bigint64_aligned(e){if(0!=(7&e))throw`Misaligned 64-bit read from address ${e}`;if(this.has_caches)for(let t of this.caches)t.read(e,!1),t.line_size<2&&t.read(e+4,!1);return this.memory.getBigUint64(e,this.little_endian)}read_uint8(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return this.memory.getUint8(e)}read_biguint8(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return BigInt(this.memory.getUint8(e))}read_uint16(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return this.memory.getUint16(e,this.little_endian)}read_uint16_aligned(e){if(0!=(1&e))throw`Misaligned 16-bit read from address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.read(e,!1);return this.memory.getUint16(e,this.little_endian)}read_biguint16(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1);return BigInt(this.memory.getUint16(e,this.little_endian))}read_biguint16_aligned(e){if(0!=(1&e))throw`Misaligned 16-bit read from address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.read(e,!1);return BigInt(this.memory.getUint16(e,this.little_endian))}read_uint32(e,t){if(this.has_caches)for(let n of this.caches)n.read(e,t);return this.memory.getUint32(e,this.little_endian)}read_uint32_aligned(e,t){if(0!=(3&e))throw`Misaligned 32-bit read from address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.read(e);return this.memory.getUint32(e,this.little_endian)}fetch32(e){if(this.has_caches)for(let t of this.caches)t.read(e,!0);return this.memory.getUint32(e,this.little_endian)}fetch32_aligned(e){if(0!=(3&e))throw`Misaligned 32-bit read from address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.read(e,!0);return this.memory.getUint32(e,this.little_endian)}read_biguint32(e,t){if(this.has_caches)for(let n of this.caches)n.read(e,t);return BigInt(this.memory.getUint32(e,this.little_endian))}read_biguint32_aligned(e,t){if(0!=(3&e))throw`Misaligned 32-bit read from address 0x${e.toString(16)})`;if(this.has_caches)for(let n of this.caches)n.read(e,t);return BigInt(this.memory.getUint32(e,this.little_endian))}read_biguint64(e){if(this.has_caches)for(let t of this.caches)t.read(e,!1),t.line_size<2&&t.read(e+4,!1);return this.memory.getBigUint64(e,this.little_endian)}read_biguint64_aligned(e){if(0!=(7&e))throw`Misaligned 64-bit read from address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.read(e,!1),t.line_size<2&&t.read(e+4,!1);return this.memory.getBigUint64(e,this.little_endian)}write_int8(e,t){if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint8(e,t)}write_bigint8(e,t){if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint8(e,Number(0xFFn&t))}write_int16(e,t){if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint16(e,t,this.little_endian)}write_int16_aligned(e,t){if(0!=(1&e))throw`Misaligned 16-bit write to address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint16(e,t,this.little_endian)}write_bigint16(e,t){if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint16(e,Number(0xFFFFn&t),this.little_endian)}write_bigint16_aligned(e,t){if(0!=(1&e))throw`Misaligned 16-bit write to address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint16(e,Number(0xFFFFn&t),this.little_endian)}write_int32(e,t){if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint32(e,t,this.little_endian)}write_int32_aligned(e,t){if(0!=(3&e))throw`Misaligned 32-bit write to address ${e}.toString(16)`;if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint32(e,t,this.little_endian)}write_bigint32(e,t){if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint32(e,Number(0xFFFFFFFFn&t),this.little_endian)}write_bigint32_aligned(e,t){if(0!=(3&e))throw`Misaligned 32-bit write to address 0x${e}.toString(16)`;if(this.has_caches)for(let t of this.caches)t.write(e);this.memory.setUint32(e,Number(0xFFFFFFFFn&t),this.little_endian)}write_bigint64(e,t){if(this.has_caches)for(let t of this.caches)t.write(e),t.line_size<2&&t.write(e+4);this.memory.setBigUint64(e,t,this.little_endian)}write_bigint64_aligned(e,t){if(0!=(7&e))throw`Misaligned 64-bit write to address 0x${e.toString(16)}`;if(this.has_caches)for(let t of this.caches)t.write(e),t.line_size<2&&t.write(e+4);this.memory.setBigUint64(e,t,this.little_endian)}},SimTool.Cache=class{static LRU=0;static FIFO=1;static RANDOM=2;static CYCLE=3;constructor(e){void 0===e&&(e={}),this.name=e.name||"?",this.nlines=e.nlines||64,this.line_size=e.blocksize||1,this.nways=e.nways||1;let t=this.nlines;if(t>0)for(;0==(1&t);)t>>=1;if(1!==t)throw"Cache: nlines must be a power of two";if(t=this.line_size,t>0)for(;0==(1&t);)t>>=1;if(1!==t)throw"Cache: blocksize must be a power of two";this.total_words=this.nlines*this.line_size*this.nways;const n=e.replacement_strategy||"lru";this.replacement_strategy={lru:SimTool.Cache.LRU,fifo:SimTool.Cache.FIFO,random:SimTool.Cache.RANDOM,cycle:SimTool.Cache.CYCLE}[n.toLowerCase()],void 0===this.replacement_strategy&&(this.replacement_strategy=SimTool.Cache.LRU),this.write_back=e.write_back,void 0===this.write_back&&(this.write_back=!0),this.total_lines=this.nlines*this.nways,this.line_shift=this.log2(this.line_size)+2,this.line_mask=this.mask(this.nlines),this.tag_shift=this.line_shift+this.log2(this.nlines),this.tag_mask=(1<<32-this.tag_shift)-1,this.dirty=new Uint8Array(this.total_lines),this.valid=new Uint8Array(this.total_lines),this.tag=new Uint32Array(this.total_lines),this.age=new Uint32Array(this.total_lines),this.reset()}description(){return`${this.line_size},${this.nlines},${this.nways},${"LFRC"[this.replacement_strategy]},${this.write_back?"B":"T"}`}report_statistics(){const e=this.fetch_hits,t=e+this.fetch_misses,n=t?Math.round(100*e/t):0,i=this.read_hits,r=i+this.read_misses,s=r?Math.round(100*i/r):0,o=this.write_hits,a=o+this.write_misses,l=e+i+o,c=t+r+a;return`I=${e}/${t} (${n}%), R=${i}/${r} (${s}%), W=${o}/${a} (${a?Math.round(100*o/a):0}%), ${l}/${c} (${c?Math.round(100*l/c):0}%) `}log2(e){let t=0;for(let n=1;t<32&&!(n>=e);n<<=1,t+=1);return t}mask(e){return(1<<this.log2(e))-1}reset(){this.accesses=0,this.fetch_hits=0,this.fetch_misses=0,this.read_hits=0,this.read_misses=0,this.write_hits=0,this.write_misses=0,this.dirty_replacements=0,this.valid_replacements=0,this.total_replacements=0,this.r_way=0,this.dirty.fill(0),this.valid.fill(0),this.tag.fill(0),this.age.fill(0)}read(e,t){this.accesses+=1;const n=e>>this.line_shift&this.line_mask,i=e>>this.tag_shift&this.tag_mask;let r=n;for(let e=0;e<this.nways;e+=1){if(this.valid[r]&&this.tag[r]===i)return t?this.fetch_hits+=1:this.read_hits+=1,void(this.replacement_strategy==SimTool.Cache.LRU&&(this.age[r]=this.accesses));r+=this.nlines}this.replace(n,i,!1),t?this.fetch_misses+=1:this.read_misses+=1}write(e){this.accesses+=1;const t=e>>this.line_shift&this.line_mask,n=e>>this.tag_shift&this.tag_mask;let i=t;for(let e=0;e<this.nways;e+=1){if(this.valid[i]&&this.tag[i]===n)return this.write_hits+=1,this.write_back&&(this.dirty[i]=1),void(this.replacement_strategy==SimTool.Cache.LRU&&(this.age[i]=this.accesses));i+=this.nlines}this.replace(t,n,this.write_back),this.write_misses+=1}replace(e,t,n){let i,r,s=this.r_way;if(this.nways>1)switch(this.replacement_strategy){case SimTool.Cache.LRU:case SimTool.Cace.FIFO:i=this.age[e],r=e+this.nlines,s=0;for(let e=1;e<this.nways;e+=1)this.age[r]<i&&(s=e,i=this.age[r]),r+=this.nlines;break;case SimTool.Cache.RANDOM:s=Math.floor(Math.random()*(this.nways+1));break;case SimTool.Cache.CYCLE:s=(s+1)%this.nways}this.r_way=s,e+=s*this.nlines,this.total_replacements+=1,this.valid[e]&&(this.valid_replacements+=1,this.dirty[e]&&(this.dirty[e]=0,this.dirty_replacements+=1)),this.valid[e]=1,this.dirty[e]=n?1:0,this.tag[e]=t,this.age[e]=this.accesses}},SimTool.InstructionCodec=class{constructor(e,t){this.cpu_tool=t,this.pattern_table=new Map;for(let t of e)this.pattern_table.set(t.opcode,this.process_pattern(t))}process_pattern(e){const t=e.pattern,n={info:e,mask:0,match:0,fields:[]};let i,r="";const s=t.length-1;for(let e=0;e<=s;e+=1){let o=1<<e,a=t.charAt(s-e);"0"==a||"1"==a?(n.mask|=o,"1"==a&&(n.match|=o)):a==r?i.mask=i.mask<<1|1:(i={name:a,offset:e,mask:1,sxt:a.toUpperCase()==a},n.fields.push(i),r=a)}return n}encode(e,t,n){const i=this.pattern_table.get(e.toLowerCase());if(void 0===i)throw"unrecognized opcode name: "+e;let r=i.match;for(let n of i.fields){const i=t[n.name];if(void 0===i)throw`no value provided for field ${n.name} ['${e}', ${JSON.stringify(t)}]`;r|=(i&n.mask)<<n.offset}return void 0!==n&&this.cpu_tool.emit32(r),r}decode(e){for(let t of this.pattern_table.values())if((e&t.mask)==t.match){const n={info:t.info,inst:e};for(let i of t.fields){let t=e>>i.offset&i.mask;if(i.sxt){const e=i.mask>>1;t>e&&(t-=e+1<<1)}n[i.name]=t}return n}}},SimTool.ArmA64Assembler=class extends SimTool.CPUTool{constructor(e,t){super(e,t,"ARMV8A","https://github.com/computation-structures/asim")}va_to_phys(e){return Number(e)}emulation_initialize(){this.educore=-1!==this.version.indexOf("Educore"),this.line_comment="//",this.block_comment_start="/*",this.block_comment_end="*/",this.little_endian=!0,this.register_nbits=64,this.inst_nbits=32,this.word_nbits=32,this.mask64=0xFFFFFFFFFFFFFFFFn,this.max64=0x7FFFFFFFFFFFFFFFn,this.off64=0x10000000000000000n,this.mask32=0xFFFFFFFFn,this.max32=0x7FFFFFFFn,this.off32=0x100000000n,this.data_section_alignment=256,this.bss_section_alignment=8,this.address_space_alignment=256,this.exception_level=1,this.pc=0n,this.nzcv=0,this.register_file=new Array(34),this.memory=new SimTool.Memory(this.little_endian),this.source_map=[],this.inst_decode=[],this.register_info(),this.opcode_info(),this.handler_info(),this.emulation_reset()}handle_not_implemented(e,t,n){throw`Unimplemented opcode ${t.opcode.toUpperCase()}`}handler_info(){this.handlers={adr:this.handle_not_implemented,alu:this.handle_not_implemented,b:this.handle_not_implemented,bcc:this.handle_not_implemented,bfm:this.handle_not_implemented,br:this.handle_not_implemented,cbz:this.handle_not_implemented,cc:this.handle_not_implemented,cl:this.handle_not_implemented,cs:this.handle_not_implemented,extr:this.handle_not_implemented,hlt:this.handle_not_implemented,ldr_literal:this.handle_not_implemented,ldst:this.handle_not_implemented,ldstp:this.handle_not_implemented,movx:this.handle_not_implemented,nop:this.handle_not_implemented,not_implemented:this.handle_not_implemented,rbit:this.handle_not_implemented,rev:this.handle_not_implemented,sysreg:this.handle_not_implemented,tb:this.handle_not_implemented}}emulation_reset(){super.emulation_reset(),this.pc=0n,this.nzcv=0,this.register_file.fill(0n),void 0!==this.assembler_memory&&(this.memory.load_bytes(this.assembler_memory),void 0!==this.inst_decode&&this.inst_decode.length==this.assembler_memory.byteLength/4||(this.inst_decode=Array(this.assembler_memory.byteLength/4))),this.memory.reset(this.caches)}emulation_step(e){this.ncycles+=1,e&&this.clear_highlights();const t=this.va_to_phys(this.pc),n=t/4;let i=this.inst_decode[n];if(void 0===i&&(this.disassemble(t,this.pc),i=this.inst_decode[t/4],void 0===i))throw"cannot decode instruction";this.memory.fetch32_aligned(t),i.handler(this,i,e),e&&this.next_pc(this.pc);const r=this.source_map[this.va_to_phys(this.pc)/4];if(r&&r.breakpoint)throw"Halt Execution"}emulation_pc(){return this.pc}register_info(){this.registers=new Map;for(let e=0;e<=30;e+=1)this.registers.set("x"+e,e);this.registers.set("sp",31),this.register_names=[];for(let e of this.registers.keys()){const t=this.registers.get(e);this.register_names[t]=e}this.registers.set("xzr",31),this.registers.set("fp",29),this.registers.set("lr",30)}extra_registers(e){let t=['<tr style="border-top: 1px solid gray;">'];t.push('<td colspan="8">'),t.push('<span class="cpu_tool-addr" style="margin-right: 4px;">pc</span>'),t.push(`<span id="pc">${this.hexify(this.pc,this.register_nbits/4)}</span>`),t.push('<span class="cpu_tool-addr" style="margin-left: 4px; margin-right: 4px;">NZCV</span>'),t.push(`<span id="nzcv">${this.nzcv.toString(2).padStart(4,"0")}</span>`),t.push("</td></tr>"),e.push(t.join(""))}next_pc(){this.right.querySelector("#pc").innerHTML=this.hexify(this.pc,16),super.next_pc()}opcode_info(){const e=this;function t(t,n){return t.type!==n&&e.syntax_error(`Expected ${n} operand`,t.start,t.end),!0}function n(n,i){return t(n,"register"),void 0!==i&&n.z!==i&&e.syntax_error(`Expected ${1===i?"X":"W"} reg`,n.start,n.end),n.reg}function i(n,i){return"sp"!==n.type&&(t(n,"register"),31===n.reg&&e.syntax_error("XZR/WZR not allowed",n.start,n.end)),void 0!==i&&n.z!==i&&e.syntax_error(`Expected ${1===i?"X":"W"} reg`,n.start,n.end),n.reg}function r(n,i,r){return t(n,"immediate"),2===e.pass?(void 0!==i&&(n.imm<i||n.imm>r)&&e.syntax_error(`Immediate value ${n.imm} out of range ${i}:${r}`,n.start,n.end),Number(n.imm)):0}function s(e){return function(e){return 0n===(e+1n&e)}(e-1n|e)}function o(e){for(let t=0;t<64;t+=1,e>>=1n)if(0n===(1n&e))return t;return 64}function a(t,n){if(void 0===t)return!1;if(2!==e.pass)return n.y=0,n.r=0,n.s=0,n.mask=0n,!0;let i=1==n.z?64:32;const r=BigInt.asUintN(i,t);if(n.mask=r,0n===r||r===(1n<<BigInt(i))-1n)return;let a,l,c=r;for(;;){if(i>>=1,(c&(t=(1n<<BigInt(i))-1n))!=(c>>BigInt(i)&t)){i<<=1;break}if(i<=2)break}if(c&=t=0xFFFFFFFFFFFFFFFFn>>BigInt(64-i),s(c))l=function(e){for(let t=0;t<64;t+=1,e>>=1n)if(1n===(1n&e))return t;return 64}(c),a=o(c>>BigInt(l));else{if(c|=~t,!s(~c))return!1;const e=function(e){const t=0x8000000000000000n;for(let n=0;n<64;n+=1,e<<=1n)if(0n===(e&t))return n;return 64}(c);l=64-e,a=e+o(c)-(64-i)}n.r=63&Number(i-l&i-1);let d=Number(~(i-1)<<1|a-1);return n.s=63&d,n.y=d>>6&1^1,!0}function l(t,s,o,l){let c={cmn:2,cmp:2,neg:2,negs:2,mvn:2,tst:2}[t]||3,d={cmn:"adds",cmp:"subs",mvn:"orn",neg:"sub",negs:"subs",tst:"ands"}[t]||t;if(c!==o.length&&e.syntax_error(`${t.toUpperCase()} expects ${c} operands`,s.start,s.end),["cmn","cmp","tst"].includes(t)){const e={type:"register",reg:31,start:s.start,end:s.end,z:o[0].z};o.unshift(e)}else if(["mvn","neg","negs"].includes(t)){const e={type:"register",reg:31,start:s.start,end:s.end,z:o[0].z};o.splice(1,0,e)}const h=o[2];"register"===h.type&&("sp"===o[0].type||"sp"===o[1].type?(h.type="extended-register",h.shiftext="lsl",h.shamt=0):(h.type="shifted-register",h.shiftext="lsl",h.shamt=0));const u={},f=["add","sub"].includes(d)&&"shifted-register"!==h.type||["and","eor","orr"].includes(d)&&"immediate"===h.type;u.d=f?i(o[0],void 0):n(o[0]),u.z=o[0].z;const m=["add","sub","adds","subs"].includes(d)&&"shifted-register"!==h.type;if(u.n=m?i(o[1],u.z):n(o[1],u.z),"immediate"===h.type)"arithmetic"===l?(u.x={add:0,adds:1,sub:2,subs:3}[d],d="addsubi",u.i=r(h,0,4095),u.s=0,void 0!==h.shiftext&&(("lsl"!==h.shiftext||0!==h.shamt&&12!==h.shamt)&&e.syntax_error("Immediate shift must be LSL of 0 or 12",h.start,h.end),u.s=12===h.shamt?1:0)):(u.x={and:0,orr:1,eor:2,ands:3}[d],void 0===u.x&&e.syntax_error(`Immediate operand not permitted for ${t.toUpperCase()}`,h.start,h.end),d="boolm",a(h.imm,u)||e.syntax_error("Cannot encode immediate as a bitmask",h.start,h.end));else if(["register","shifted-register","extended-register"].includes(h.type))if(u.m=h.reg,"register"===h.type&&(h.type="shifted-register",h.shiftext="lsl",h.shamt=0),"arithmetic"===l)u.x={add:0,adds:1,sub:2,subs:3}[d],"shifted-register"===h.type?(d="addsub",u.s={lsl:0,lsr:1,asr:2}[h.shiftext],void 0===u.s&&e.syntax_error(`${h.shiftext} not allowed for ${t.toUpperCase()}`,h.start,h.end),(h.shamt<0||h.shamt>(u.z?63:31))&&e.syntax_error("shift amount not in range 0:"+(u.z?63:31),h.start,h.end),u.j=h.shamt):"extended-register"===h.type&&(d="addsubx",u.o={uxtb:0,uxth:1,uxtw:2,uxtx:3,sxtb:4,sxth:5,sxtw:6,sxtx:7}[h.shiftext],void 0===u.o&&("lsl"===h.shiftext?u.o=u.z?3:2:e.syntax_error(`${h.shiftext} not allowed`,h.start,h.end)),void 0===h.shamt&&(h.shamt=0),(h.shamt<0||h.shamt>4)&&e.syntax_error("shift amount not in range 0:4",h.start,h.end),u.j=h.shamt);else{const t={and:0,bic:1,orr:2,orn:3,eor:4,eon:5,ands:6,bics:7}[d];u.N=1&t,u.x=t>>1,u.j=0,u.s=0,"shifted-register"===h.type?(u.s={lsl:0,lsr:1,asr:2,ror:3}[h.shiftext],void 0===u.s&&e.syntax_error(`${h.shiftext} not allowed`,h.start,h.end),(h.shamt<0||h.shamt>(u.z?63:31))&&e.syntax_error("shift amount not in range 0:"+(u.z?63:31),h.start,h.end),u.j=h.shamt):"extended-register"===h.type&&e.syntax_error(`${h.shiftext} not allowed`,h.start,h.end),d="bool"}else e.syntax_error("Illegal operand",h.start,h.end);e.inst_codec.encode(d,u,!0)}function c(e,t,n){return l(e,t,n,"arithmetic")}function d(e,t,n){return l(e,t,n,"logical")}function h(t,i,s){3!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 3 operands`,i.start,i.end);let o={d:n(s[0]),s:{lsl:0,lsr:1,asr:2,ror:3}[t]};o.z=s[0].z;const a=0==o.z?32:64;if("immediate"===s[2].type){o.n=n(s[1],o.z);const e=r(s[2],0,a-1);switch(o.s){case 0:t="bf",o.x=2,o.y=o.z,o.r=-e&a-1,o.s=a-1-e;break;case 1:t="bf",o.x=2,o.y=o.z,o.r=e,o.s=a-1;break;case 2:t="bf",o.x=0,o.y=o.z,o.r=e,o.s=a-1;break;case 3:t="extr",o.y=o.z,o.m=o.n,o.j=e}}else e.educore?e.syntax_error("Illegal operand",s[2].start,s[2].end):(o.n=n(s[1],o.z),o.m=n(s[2],o.z),t="shift");e.inst_codec.encode(t,o,!0)}function u(t,i,s){2!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 2 operands`,i.start,i.end);let o={x:{movn:0,movz:2,movk:3}[t],d:n(s[0]),i:r(s[1],0,65535),s:s[1].shamt||0};o.z=s[0].z,0===o.z&&([0,16].includes(o.s)?[0,16,32,48].includes(o.s)||e.syntax_error("Shift must be LSL of 0, 16, 32, or 48",s[1].start,s[1].end):e.syntax_error("Shift must be LSL of 0, 16",s[1].start,s[1].end)),o.s>>=4,e.inst_codec.encode("movx",o,!0)}function f(t,i,r){let s={adc:3,adcs:3,ngc:2,ngcs:2,sbc:3,sbcs:3}[t];r.length!==s&&e.syntax_error(`${t.toUpperCase()} expects ${s} operands`,i.start,i.end);const o={d:n(r[0]),z:r[0].z};"ngc"===t||"ngcs"===t?(t="ngc"===t?"sbc":"sbcs",o.n=31,o.m=n(r[1],r[0].z)):(o.n=n(r[1],r[0].z),o.m=n(r[2],r[0].z)),o.x={adc:0,adcs:1,sbc:2,sbcs:3}[t],e.inst_codec.encode("adcsbc",o,!0)}function m(t,i,r){let s={madd:4,mneg:3,msub:4,mul:3,sdiv:3,smulh:3,udiv:3,umulh:3}[t];r.length!==s&&e.syntax_error(`${t.toUpperCase()} expects ${s} operands`,i.start,i.end);let o={d:n(r[0])};o.z=r[0].z,o.n=n(r[1],o.z),o.m=n(r[2],o.z),s>3&&(o.a=n(r[3],o.z)),"mul"!==t&&"mneg"!==t||(t="mul"===t?"madd":"msub",o.a=31),e.inst_codec.encode(t,o,!0)}function p(t,i,r){2!==r.length&&e.syntax_error(`${t.toUpperCase()} expects 2 operands`,i.start,i.end);let s={d:"rev32"==t?n(r[0],1):n(r[0])};s.y=s.z=r[0].z,s.n=n(r[1],s.z),e.inst_codec.encode(t,s,!0)}function g(t,i,r){let s={smaddl:4,smsubl:4,umaddl:4,umsubl:4,smnegl:3,smull:3,umnegl:3,umull:3}[t];r.length!==s&&e.syntax_error(`${t.toUpperCase()} expects ${s} operands`,i.start,i.end);let o={d:n(r[0],1),n:n(r[1],0),m:n(r[2],0),a:4===s?n(r[3],1):31,u:"u"===t.charAt(0)?1:0,x:["smsubl","umsubl","smnegl","umnegl"].includes(t)?1:0};e.inst_codec.encode("muladd",o,!0)}function v(t,i,s){2!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 2 operands`,i.start,i.end);const o={d:n(s[0],1),i:0,I:r(s[1])};if(2===e.pass){let n=e.dot();"adrp"===t&&(o.I>>=12,n>>=12);const i=o.I-n;(i<-1048576||i>1048575)&&e.syntax_error(`Offset ${i} is out of range -1048576:1048575`,s[1].start,s[1].end),o.i=3&i,o.I=i>>2}e.inst_codec.encode(t,o,!0)}function _(t,n,i){1!==i.length&&e.syntax_error(`${t.toUpperCase()} expects 1 operand`,n.start,n.end);const s={x:{b:0,bl:1}[t],I:r(i[0])};if(2===e.pass){s.I-=e.dot(),s.I>>=2;const t=2**25;(s.I<-t||s.I>=t)&&e.syntax_error("Offset too large",i[1].start,i[1].end)}e.inst_codec.encode("brel",s,!0)}function y(t,i,r){const s={x:{br:0,blr:1,ret:2}[t]};"ret"===t&&0===r.length?s.n=30:(1!==r.length&&e.syntax_error(`${t.toUpperCase()} expects 1 operand`,i.start,i.end),s.n=n(r[0],1)),e.inst_codec.encode("blink",s,!0)}function b(t,i,s){2!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 2 operands`,i.start,i.end);const o={n:n(s[0]),x:{cbz:0,cbnz:1}[t],I:r(s[1])};if(o.z=s[0].z,2===e.pass){o.I-=e.dot(),o.I>>=2;const t=2**18;(o.I<-t||o.I>=t)&&e.syntax_error("Offset too large",s[1].start,s[1].end)}e.inst_codec.encode("cb",o,!0)}function x(t,i,s){3!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 2 operands`,i.start,i.end);const o={n:n(s[0]),x:{tbz:0,tbnz:1}[t],I:r(s[2]),z:0};if(o.b=r(s[1],0,s[0].z?63:31),o.b>31&&(o.z=1,o.b-=32),2===e.pass){o.I-=e.dot(),o.I>>=2;const t=8192;(o.I<-t||o.I>=t)&&e.syntax_error("Offset too large",s[1].start,s[1].end)}e.inst_codec.encode("tb",o,!0)}function w(t,n,i){1!==i.length&&e.syntax_error(`${t.toUpperCase()} expects 1 operand`,n.start,n.end);const s={c:{"b.eq":0,beq:0,"b.ne":1,bne:1,"b.cs":2,bcs:2,"b.cc":3,bcc:3,"b.hs":2,bhs:2,"b.lo":3,blo:3,"b.mi":4,bmi:4,"b.pl":5,bpl:5,"b.vs":6,bvs:6,"b.vc":7,bvc:7,"b.hi":8,bhi:8,"b.ls":9,bls:9,"b.ge":10,bge:10,"b.lt":11,blt:11,"b.gt":12,bgt:12,"b.le":13,ble:13,"b.al":14,bal:14,"b.nv":15,bnv:15}[t],I:r(i[0])};if(2===e.pass){s.I-=e.dot(),s.I>>=2;const t=2**18;(s.I<-t||s.I>=t)&&e.syntax_error("Offset too large",i[0].start,i[0].end)}e.inst_codec.encode("bcc",s,!0)}function k(t,s,o){2!==o.length&&e.syntax_error(`${t.toUpperCase()} expects 2 operands`,s.start,s.end);let a={};if("immediate"===o[1].type&&["ldr","ldrsw"].includes(t)){if("ldrsw"===t?(a.d=n(o[0],1),a.x=1,a.z=0):(a.d=n(o[0]),a.x=0,a.z=o[0].z),a.I=r(o[1]),2===e.pass){a.I-=e.dot(),a.I>>=2;const t=2**18;(a.I<-t||a.I>=t)&&e.syntax_error("Offset too large",o[1].start,o[1].end)}return void e.inst_codec.encode("ldr.pc",a,!0)}a.d=n(o[0]);const[l,c,d,h,u]=t.match(/(ld|st)(u?)r(s?)([bhw]?)/);a.z={b:0,h:1,w:2}[u],void 0===a.z&&(a.z=2+o[0].z),a.s="st"===c?0:h?o[0].z?2:3:1,["ldrsw","ldursw"].includes(t)&&1!==o[0].z&&e.syntax_error(`${t.toUpperCase()} requires Xn as a target`,o[0].start,o[0].end),h||0!==a.z&&1!==a.z||0===o[0].z||e.syntax_error(`${t.toUpperCase()} requires Wn as a target`,o[0].start,o[0].end);let f=o[1].addr;void 0===f&&e.syntax_error("Invalid operand",o[1].start,o[1].end),a.n=i(f[0],1);const m=a.z;if(2===f.length&&["register","shifted-register","extended-register"].includes(f[1].type)){if(!o[1].pre_index&&void 0===o[1].post_index)return a.m=f[1].reg,a.x=2,void 0===f[1].shiftext?(a.o=3,a.y=0):(a.o={lsl:3,uxtw:2,sxtw:6,sxtx:7}[f[1].shiftext],void 0===a.o&&e.syntax_error("Invalid operand",o[1].start,o[1].end),3===a.o&&0!==f[1].shamt&&f[1].shamt!==m&&e.syntax_error(`Index shift amount must be 0 or ${m}`,o[1].start,o[1].end),(1&a.o)!==f[1].z&&e.syntax_error("Offset register size and extend operation must match",o[1].start,o[1].end),void 0===f[1].shamt||0!=m&&0===f[1].shamt?a.y=0:f[1].shamt!==m?e.syntax_error(`Shift amount does not match size of ${o[0].rname}`,o[0].start,o[0].end):a.y=1),void e.inst_codec.encode("ldst.reg",a,!0)}else if(void 0!==f&&f.length<=2&&void 0!==f[0]){if(!d)return o[1].pre_index?(void 0!==f[1]?a.I=r(f[1],-256,255):a.I=0,a.x=3,void e.inst_codec.encode("ldst",a,!0)):void 0!==o[1].post_index?(a.I=o[1].post_index,(a.I<-256||a.I>=256)&&e.syntax_error(`Immediate value ${a.I} out of range -256:255`,o[1].start,o[1].end),a.x=1,void e.inst_codec.encode("ldst",a,!0)):(e.educore&&e.syntax_error("scaled offsets not supported on Educore",o[1].start,o[1].end),void 0!==f[1]?a.i=r(f[1],0,(4096<<m)-1):a.i=0,a.i%(1<<m)!=0&&e.syntax_error(`Offset ${a.i} must be a multiple of ${1<<m}`,o[1].start,o[1].end),a.i>>=m,void e.inst_codec.encode("ldst.off",a,!0));if(!o[1].pre_index&&void 0===o[1].post_index)return void 0!==f[1]?a.I=r(f[1],-256,255):a.I=0,a.x=0,void e.inst_codec.encode("ldst",a,!0);e.syntax_error("Invalid operand",o[1].start,o[1].end)}e.syntax_error("Invalid operand",o[1].start,o[1].end)}function C(t,r,s){3!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 3 operands`,r.start,r.end);const o={d:n(s[0])};o.e=n(s[1],s[0].z),o.x="ldpsw"===t?1:2*s[0].z,o.o="stp"===t?0:1;let a=s[2].addr;(void 0===a||void 0===a[0]||a.length>2||2==a.length&&"immediate"!==a[1].type)&&e.syntax_error("Invalid operand",s[2].start,s[2].end),o.n=i(a[0],1);const l="ldpsw"===t||0===s[0].z?2:3;o.I=s[2].post_index||(2==a.length?Number(a[1].imm):0);const c=-64<<l,d=(64<<l)-1;(o.I<c||o.I>d)&&e.syntax_error(`Offset ${o.I} out of range ${c}:${d}`,s[2].start,s[2].end),o.I%(1<<l)!=0&&e.syntax_error(`Offset ${o.I} must be a multiple of ${1<<l}`,s[2].start,s[2].end),o.I>>=l,s[2].pre_index?o.s=3:s[2].post_index?o.s=1:o.s=2,e.inst_codec.encode("ldstp",o,!0)}function S(t,i,r){const s={cinc:3,cinv:3,cneg:3,csel:4,cset:2,csetm:2,csinc:4,csinv:4,csneg:4}[t];r.length!==s&&e.syntax_error(`${t.toUpperCase()} expects ${s} operands`,i.start,i.end);const o=r[s-1];"condition"!==o.type&&e.syntax_error(`${t.toUpperCase()} expects a condition as the final operand`,o.start,o.end);const a={d:n(r[0]),z:r[0].z,c:o.cc},l={csetm:"csinv",cset:"csinc",cinc:"csinc",cinv:"csinv",cneg:"csneg"}[t]||t;["csetm","cset"].includes(t)?(a.n=31,a.m=31,14!==a.c&&15!==a.c||e.syntax_error("AL or NV not permitted",o.start,o.end),a.c^=1):["cinc","cinv","cneg"].includes(t)?(a.n=n(r[1],a.z),"cneg"!==t&&31===a.n&&e.syntax_error("Invalid operand",r[1].start,r[1].end),a.m=a.n,a.c^=1,14!==a.c&&15!==a.c||e.syntax_error("AL or NV not permitted",o.start,o.end)):(a.n=n(r[1],a.z),a.m=n(r[2],a.z)),a.x="csinv"===l||"csneg"===l?1:0,a.y="csinc"===l||"csneg"===l?1:0,e.inst_codec.encode("csxx",a,!0)}function L(t,i,s){4!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 4 operands`,i.start,i.end);const o=s[3];"condition"!==o.type&&e.syntax_error(`${t.toUpperCase()} expects a condition as the final operand`,o.start,o.end);const a={n:n(s[0]),x:"ccmp"===t?1:0,y:"immediate"===s[1].type?1:0,j:r(s[2],0,15),c:o.cc};a.z=s[0].z,1==a.y?a.m=r(s[1],0,31):a.m=n(s[1],a.z),e.inst_codec.encode("ccxx",a,!0)}function M(t,i,s){const o={bfc:3,sxtb:2,sxth:2,sxtw:2,uxtb:2,uxth:2}[t]||4;s.length!=o&&e.syntax_error(`${t.toUpperCase()} expects ${o} operands`,i.start,i.end);const a={x:{sbfm:0,sbfiz:0,sbfx:0,sxtb:0,sxth:0,sxtw:0,bfm:1,bfc:1,bfi:1,bfxil:1,ubfm:2,ubfiz:2,ubfx:2,uxtb:2,uxth:2}[t]};let l,c;"bfc"===t?(a.d=n(s[0]),a.y=a.z=s[0].z,a.n=31,l=r(s[1],0,a.z?63:31),c=r(s[2],1,a.z?64:32)):["sxtb","sxth","sxtw"].includes(t)?(a.d=n(s[0]),a.y=a.z=s[0].z,a.n=n(s[1],0),l=0,c={sxtb:7,sxth:15,sxtw:31}[t]):["uxtb","uxth"].includes(t)?(a.d=n(s[0],0),a.y=a.z=s[0].z,a.n=n(s[1],0),l=0,c={uxtb:7,uxth:15}[t]):(a.d=n(s[0]),a.y=a.z=s[0].z,a.n=n(s[1],a.z),l=r(s[2],0,a.z?63:31),c=r(s[3],0,a.z?64:32)),["bfxil","sbfx","ubfx"].includes(t)?(2==e.pass&&(c<1||c>(a.z?64:32)-l)&&e.syntax_error(`Width out of range 1 to ${a.z?64:32}-lsb`,i.start,i.end),a.r=l,a.s=l+c-1):["bfc","bfi","sbfiz","ubfiz"].includes(t)?(2==e.pass&&(c<1||c>(a.z?64:32)-l)&&e.syntax_error(`${t}: Width out of range 1 to ${a.z?64:32}-lsb}`,i.start,i.end),a.r=-l&(a.z?63:31),a.s=c-1):(a.r=l,a.s=c),e.inst_codec.encode("bf",a,!0)}function T(t,n,i){i.length>1&&e.syntax_error(`${t.toUpperCase()} instruction expects at most 1 operand`,n.start,n.end);const s={j:i.length>0?r(i[0],0,65535):0};e.inst_codec.encode(t,s,!0)}function I(t,n,i){0!==i.length&&e.syntax_error(`${t} instruction expects no operands`,n.start,n.end),e.inst_codec.encode(t,{},!0)}function A(t,i,r){function s(t){return"sysreg"!==t.type&&e.syntax_error("Expected name of system register",t.start,t.end),t.imm}2!==r.length&&e.syntax_error("${opc.toUpperCase()} instruction expects 2 operands",i.start,i.end);const o={};"mrs"===t?(o.x=1,o.d=n(r[0],1),o.j=s(r[1])):"msr"===t?(o.x=0,o.d=n(r[1],1),o.j=s(r[0])):e.syntax_error("Unrecognized opcode",i.start,i.end),e.inst_codec.encode("sysreg",o,!0)}e.opcode_list=[{opcode:"adcsbc",pattern:"zxx11010000mmmmm000000nnnnnddddd",type:"R"},{opcode:"addsub",pattern:"zxx01011ss0mmmmmjjjjjjnnnnnddddd",type:"R"},{opcode:"addsubx",pattern:"zxx01011001mmmmmooojjjnnnnnddddd",type:"R"},{opcode:"addsubi",pattern:"zxx100010siiiiiiiiiiiinnnnnddddd",type:"I"},{opcode:"adr",pattern:"0ii10000IIIIIIIIIIIIIIIIIIIddddd",type:"A"},{opcode:"adrp",pattern:"1ii10000IIIIIIIIIIIIIIIIIIIddddd",type:"A"},{opcode:"madd",pattern:"z0011011000mmmmm0aaaaannnnnddddd",type:"R"},{opcode:"msub",pattern:"z0011011000mmmmm1aaaaannnnnddddd",type:"R"},{opcode:"sdiv",pattern:"z0011010110mmmmm000011nnnnnddddd",type:"R"},{opcode:"smulh",pattern:"z0011011010mmmmm011111nnnnnddddd",type:"R"},{opcode:"udiv",pattern:"z0011010110mmmmm000010nnnnnddddd",type:"R"},{opcode:"umulh",pattern:"z0011011110mmmmm011111nnnnnddddd",type:"R"},{opcode:"muladd",pattern:"10011011u01mmmmmxaaaaannnnnddddd",type:"MA"},{opcode:"bf",pattern:"zxx100110yrrrrrrssssssnnnnnddddd",type:"BF"},{opcode:"cls",pattern:"z101101011000000000101nnnnnddddd",type:"BITS"},{opcode:"clz",pattern:"z101101011000000000100nnnnnddddd",type:"BITS"},{opcode:"rbit",pattern:"z101101011000000000000nnnnnddddd",type:"BITS"},{opcode:"rev",pattern:"z10110101100000000001ynnnnnddddd",type:"BITS"},{opcode:"rev16",pattern:"z101101011000000000001nnnnnddddd",type:"BITS"},{opcode:"rev32",pattern:"1101101011000000000010nnnnnddddd",type:"BITS"},{opcode:"extr",pattern:"z00100111y0mmmmmjjjjjjnnnnnddddd",type:"EXTR"},{opcode:"bool",pattern:"zxx01010ssNmmmmmjjjjjjnnnnnddddd",type:"R"},{opcode:"boolm",pattern:"zxx100100yrrrrrrssssssnnnnnddddd",type:"IM"},{opcode:"shift",pattern:"z0011010110mmmmm0010ssnnnnnddddd",type:"R"},{opcode:"movx",pattern:"zxx100101ssiiiiiiiiiiiiiiiiddddd",type:"M"},{opcode:"brel",pattern:"x00101IIIIIIIIIIIIIIIIIIIIIIIIII",type:"B"},{opcode:"blink",pattern:"110101100xx11111000000nnnnn00000",type:"BL"},{opcode:"cb",pattern:"z011010xIIIIIIIIIIIIIIIIIIInnnnn",type:"CB"},{opcode:"tb",pattern:"z011011xbbbbbIIIIIIIIIIIIIInnnnn",type:"TB"},{opcode:"bcc",pattern:"01010100IIIIIIIIIIIIIIIIIII0cccc",type:"BCC"},{opcode:"csxx",pattern:"zx011010100mmmmmcccc0ynnnnnddddd",type:"CS"},{opcode:"ccxx",pattern:"zx111010010mmmmmccccy0nnnnn0jjjj",type:"CC"},{opcode:"ldst",pattern:"zz111000ss0IIIIIIIIIxxnnnnnddddd",type:"D"},{opcode:"ldst.off",pattern:"zz111001ssiiiiiiiiiiiinnnnnddddd",type:"D"},{opcode:"ldst.reg",pattern:"zz111000ss1mmmmmoooyxxnnnnnddddd",type:"D"},{opcode:"ldr.pc",pattern:"xz011000IIIIIIIIIIIIIIIIIIIddddd",type:"D"},{opcode:"ldstp",pattern:"xx10100ssoIIIIIIIeeeeennnnnddddd",type:"P"},{opcode:"hlt",pattern:"11010100010jjjjjjjjjjjjjjjj00000",type:"H"},{opcode:"brk",pattern:"11010100001jjjjjjjjjjjjjjjj00000",type:"H"},{opcode:"svc",pattern:"11010100000jjjjjjjjjjjjjjjj00001",type:"H"},{opcode:"eret",pattern:"11010110100111110000001111100000",type:"ERET"},{opcode:"nop",pattern:"11010101000000110010000000011111",type:"NOP"},{opcode:"yield",pattern:"11010101000000110010000000111111",type:"NOP"},{opcode:"sysreg",pattern:"1101010100x1jjjjjjjjjjjjjjjddddd",type:"SYS"}],e.inst_codec=new SimTool.InstructionCodec(e.opcode_list,this),e.assembly_prologue="\n",e.register_operands={x0:0,x1:1,x2:2,x3:3,x4:4,x5:5,x6:6,x7:7,x8:8,x9:9,x10:10,x11:11,x12:12,x13:13,x14:14,x15:15,x16:16,x17:17,x18:18,x19:19,x20:20,x21:21,x22:22,x23:23,x24:24,x25:25,x26:26,x27:27,x28:28,x29:29,x30:30,xzr:31,sp:31,lr:30,fp:29,w0:0,w1:1,w2:2,w3:3,w4:4,w5:5,w6:6,w7:7,w8:8,w9:9,w10:10,w11:11,w12:12,w13:13,w14:14,w15:15,w16:16,w17:17,w18:18,w19:19,w20:20,w21:21,w22:22,w23:23,w24:24,w25:25,w26:26,w27:27,w28:28,w29:29,w30:30,wzr:31,wsp:31},e.parse_operands=function(t){let n,i=[],r=0;for(;r<t.length;){let s=t[r++],o=0;const a=s[o],l="number"===a.type?"":a.token.toLowerCase();if(void 0!==e.register_operands[l]){if(n={type:"sp"===l||"wsp"===l?"sp":"register",rname:l,reg:e.register_operands[l],start:s[0].start,end:s[0].end,z:"w"===l.charAt(0)?0:1},i.push(n),o+=1,o<s.length)throw this.syntax_error("Invalid operand",s[0].start,s[s.length-1].end);continue}if(l.match(/^(lsl|lsr|asr|ror)/)){if(o+=1,"#"===s[o].token&&(o+=1),void 0!==n){if(n.end=s[s.length-1].end,n.shiftext=l,n.shamt=e.read_expression(s,o),2===e.pass?n.shamt=Number(e.eval_expression(n.shamt)):n.shamt=0,"register"===n.type){n.type="shifted-register";continue}if("lsl"===l&&"immediate"===n.type)continue}e.syntax_error(`Shift ${l.toUpperCase()} cannot be applied to previous operand`,s[0].start,s[s.length-1].end)}if(l.match(/^[su]xt[bhwx]/)){o+=1;const t=l.charAt(l.length-1);(void 0===n||"register"!==n.type||"x"===t&&1!==n.z||"x"!==t&&0!==n.z)&&e.syntax_error(`Register extension ${l.toUpperCase()} cannot be applied to previous operand`,s[0].start,s[s.length-1].end),n.type="extended-register",n.shiftext=l,n.shamt=void 0,n.end=s[s.length-1],o<s.length&&("#"===s[o].token&&(o+=1),n.shamt=e.read_expression(s,o),2===e.pass?n.shamt=Number(e.eval_expression(n.shamt)):n.shamt=0);continue}if("["===l){let t=o+1,r=s.length-1,a=!1;"!"===s[r].token&&(a=!0,r-=1),"]"!==s[r].token&&e.syntax_error("Invalid operand",s[0].start,s[s.length-1].end);let l=[[]];for(;t<r;)","===s[t].token?l.push([]):l[l.length-1].push(s[t]),t+=1;n={type:"address",addr:e.parse_operands(l),pre_index:a,start:s[0].start,end:s[s.length-1].end},i.push(n);continue}if("#"===l)o+=1;else if(1===s.length){const e={eq:0,ne:1,cs:2,hs:2,cc:3,lo:3,mi:4,pl:5,vs:6,vc:7,hi:8,ls:9,ge:10,lt:11,gt:12,le:13,al:14,nv:15}[l];if(void 0!==e){n={type:"condition",condition:l,cc:e,start:s[0].start,end:s[0].end},i.push(n);continue}const t={nzcv:23056,console:1,mouse:2,cycles:3}[l];if(void 0!==t){n={type:"sysreg",imm:t,sysreg:l,start:s[0].start,end:s[0].end},i.push(n);continue}}let c,d;c=this.read_expression(s,o),d=2===e.pass?e.eval_expression(c):0n,void 0===n||"address"!==n.type||n.pre_index?(n={type:"immediate",imm:d,expression:c,start:s[0].start,end:s[s.length-1].end},i.push(n)):(n.post_index=Number(d),n.end=s[s.length-1].end)}return i},this.assembly_handlers=new Map,this.assembly_handlers.set("adc",f),this.assembly_handlers.set("adcs",f),this.assembly_handlers.set("add",c),this.assembly_handlers.set("adds",c),this.assembly_handlers.set("adr",v),this.assembly_handlers.set("adrp",v),this.assembly_handlers.set("cmn",c),this.assembly_handlers.set("cmp",c),this.educore||this.assembly_handlers.set("madd",m),this.educore||this.assembly_handlers.set("mneg",m),this.educore||this.assembly_handlers.set("msub",m),this.educore||this.assembly_handlers.set("mul",m),this.assembly_handlers.set("neg",c),this.assembly_handlers.set("negs",c),this.assembly_handlers.set("ngc",f),this.assembly_handlers.set("ngcs",f),this.assembly_handlers.set("sbc",f),this.assembly_handlers.set("sbcs",f),this.educore||this.assembly_handlers.set("sdiv",m),this.educore||this.assembly_handlers.set("smaddl",g),this.educore||this.assembly_handlers.set("smnegl",g),this.educore||this.assembly_handlers.set("smsubl",g),this.educore||this.assembly_handlers.set("smulh",m),this.educore||this.assembly_handlers.set("smull",g),this.assembly_handlers.set("sub",c),this.assembly_handlers.set("subs",c),this.educore||this.assembly_handlers.set("udiv",m),this.educore||this.assembly_handlers.set("umaddl",g),this.educore||this.assembly_handlers.set("umnegl",g),this.educore||this.assembly_handlers.set("umsubl",g),this.educore||this.assembly_handlers.set("umulh",m),this.educore||this.assembly_handlers.set("umull",g),this.assembly_handlers.set("bfc",M),this.assembly_handlers.set("bfi",M),this.assembly_handlers.set("bfm",M),this.assembly_handlers.set("bfxil",M),this.educore||this.assembly_handlers.set("cls",p),this.educore||this.assembly_handlers.set("clz",p),this.assembly_handlers.set("extr",(function(t,i,s){4!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 4 operands`,i.start,i.end);const o={d:n(s[0])};o.y=o.z=s[0].z,o.n=n(s[1],o.z),o.m=n(s[2],o.z),o.j=r(s[3],0,o.z?63:31),e.inst_codec.encode(t,o,!0)})),this.educore||this.assembly_handlers.set("rbit",p),this.educore||this.assembly_handlers.set("rev",p),this.educore||this.assembly_handlers.set("rev16",p),this.educore||this.assembly_handlers.set("rev32",p),this.assembly_handlers.set("sbfiz",M),this.assembly_handlers.set("sbfm",M),this.assembly_handlers.set("sbfx",M),this.assembly_handlers.set("sxtb",M),this.assembly_handlers.set("sxth",M),this.assembly_handlers.set("sxtw",M),this.assembly_handlers.set("ubfiz",M),this.assembly_handlers.set("ubfm",M),this.assembly_handlers.set("ubfx",M),this.assembly_handlers.set("uxtb",M),this.assembly_handlers.set("uxth",M),this.assembly_handlers.set("and",d),this.assembly_handlers.set("ands",d),this.assembly_handlers.set("asr",h),this.assembly_handlers.set("bic",d),this.assembly_handlers.set("bics",d),this.assembly_handlers.set("eon",d),this.assembly_handlers.set("eor",d),this.assembly_handlers.set("lsl",h),this.assembly_handlers.set("lsr",h),this.assembly_handlers.set("mov",(function(t,r,s){let o;2!==s.length&&e.syntax_error(`${t.toUpperCase()} expects 2 operands`,r.start,r.end);const l={};if("sp"===s[0].type&&("register"===s[1].type||"sp"===s[1].type)||"sp"===s[1].type&&("register"===s[0].type||"sp"===s[0].type))l.d=i(s[0],void 0),l.z=s[0].z,l.n=i(s[1],l.z),l.x=0,l.i=0,l.s=0,o="addsubi";else if("register"===s[0].type&&"register"===s[1].type)l.d=n(s[0]),l.z=s[0].z,l.n=31,l.m=n(s[1],l.z),l.x=1,l.N=0,l.s=0,l.j=0,o="bool";else{"immediate"!==s[1].type&&e.syntax_error("Invalid operand",s[1].start,s[1].end);const t=s[1].imm&e.mask64;if("sp"!==s[0].type){l.d=n(s[0]),l.z=s[0].z;const i=~s[1].imm&e.mask64;for(let e=0;e<(l.z?4:2);e+=1){const n=BigInt(16*e);if(0n===(t&~(0xFFFFn<<n))){o="movx",l.x=2,l.s=e,l.i=Number(t>>n);break}if(0n===(i&~(0xFFFFn<<n))){o="movx",l.x=0,l.s=e,l.i=Number(i>>n);break}}}void 0===o&&(l.d=i(s[0]),l.z=s[0].z,a(t,l)?(o="boolm",l.n=31,l.x=1):e.syntax_error("Invalid operand",s[1].start,s[1].end))}e.inst_codec.encode(o,l,!0)})),this.assembly_handlers.set("movk",u),this.assembly_handlers.set("movn",u),this.assembly_handlers.set("movz",u),this.assembly_handlers.set("mvn",d),this.assembly_handlers.set("orn",d),this.assembly_handlers.set("orr",d),this.assembly_handlers.set("ror",h),this.assembly_handlers.set("tst",d),this.assembly_handlers.set("b",_),this.assembly_handlers.set("b.eq",w),this.assembly_handlers.set("beq",w),this.assembly_handlers.set("b.ne",w),this.assembly_handlers.set("bne",w),this.assembly_handlers.set("b.cs",w),this.assembly_handlers.set("bcs",w),this.assembly_handlers.set("b.hs",w),this.assembly_handlers.set("bhs",w),this.assembly_handlers.set("b.cc",w),this.assembly_handlers.set("bcc",w),this.assembly_handlers.set("b.lo",w),this.assembly_handlers.set("blo",w),this.assembly_handlers.set("b.mi",w),this.assembly_handlers.set("bmi",w),this.assembly_handlers.set("b.pl",w),this.assembly_handlers.set("bpl",w),this.assembly_handlers.set("b.vs",w),this.assembly_handlers.set("bvs",w),this.assembly_handlers.set("b.vc",w),this.assembly_handlers.set("bvc",w),this.assembly_handlers.set("b.hi",w),this.assembly_handlers.set("bhi",w),this.assembly_handlers.set("b.ls",w),this.assembly_handlers.set("bls",w),this.assembly_handlers.set("b.ge",w),this.assembly_handlers.set("bge",w),this.assembly_handlers.set("b.lt",w),this.assembly_handlers.set("blt",w),this.assembly_handlers.set("b.gt",w),this.assembly_handlers.set("bgt",w),this.assembly_handlers.set("b.le",w),this.assembly_handlers.set("ble",w),this.assembly_handlers.set("b.al",w),this.assembly_handlers.set("bal",w),this.assembly_handlers.set("b.nv",w),this.assembly_handlers.set("bnv",w),this.assembly_handlers.set("bl",_),this.assembly_handlers.set("blr",y),this.assembly_handlers.set("br",y),this.educore||this.assembly_handlers.set("cbnz",b),this.educore||this.assembly_handlers.set("cbz",b),this.assembly_handlers.set("ret",y),this.educore||this.assembly_handlers.set("tbz",x),this.educore||this.assembly_handlers.set("tbnz",x),this.assembly_handlers.set("ccmn",L),this.assembly_handlers.set("ccmp",L),this.assembly_handlers.set("cinc",S),this.assembly_handlers.set("cinv",S),this.assembly_handlers.set("cneg",S),this.assembly_handlers.set("csel",S),this.assembly_handlers.set("cset",S),this.assembly_handlers.set("csetm",S),this.assembly_handlers.set("csinc",S),this.assembly_handlers.set("csinv",S),this.assembly_handlers.set("csneg",S),this.educore||this.assembly_handlers.set("ldp",C),this.educore||this.assembly_handlers.set("ldpsw",C),this.assembly_handlers.set("ldr",k),this.assembly_handlers.set("ldrb",k),this.assembly_handlers.set("ldrh",k),this.assembly_handlers.set("ldrsb",k),this.assembly_handlers.set("ldrsh",k),this.assembly_handlers.set("ldrsw",k),this.assembly_handlers.set("ldur",k),this.assembly_handlers.set("ldurb",k),this.assembly_handlers.set("ldurh",k),this.assembly_handlers.set("ldursb",k),this.assembly_handlers.set("ldursh",k),this.assembly_handlers.set("ldursw",k),this.educore||this.assembly_handlers.set("stp",C),this.assembly_handlers.set("str",k),this.assembly_handlers.set("strb",k),this.assembly_handlers.set("strh",k),this.assembly_handlers.set("stur",k),this.assembly_handlers.set("sturb",k),this.assembly_handlers.set("sturh",k),this.assembly_handlers.set("hlt",T),this.assembly_handlers.set("brk",T),this.assembly_handlers.set("svc",T),this.assembly_handlers.set("eret",T),this.assembly_handlers.set("nop",I),this.assembly_handlers.set("yield",I),this.assembly_handlers.set("mrs",A),this.assembly_handlers.set("msr",A)}assemble_opcode(e,t){if("symbol"!==e.type)return;const n=e.token.toLowerCase(),i=this.assembly_handlers.get(n);if(void 0===i)return;const r=this.dot(!0);if(i(n,e,this.parse_operands(t)),2==this.pass&&this.source_map){const n=t[t.length-1],i={start:e.start,end:n?n[n.length-1].end:e.end,breakpoint:!1},s=this.dot(!0);for(let e=r;e<s;e+=4)this.source_map[e/4]=i}return!0}add_built_in_directives(){super.add_built_in_directives();const e=this;this.directives.set(".balign",(function(t,n){return e.directive_balign(t,n)})),this.directives.set(".p2align",(function(t,n){return e.directive_align(t,n)})),this.directives.set(".quad",(function(t,n){return t.token=".long",e.directive_storage(t,n)}))}directive_balign(e,t){if(1!==t.length)throw e.asSyntaxError("Expected one argument");const n=Number(this.eval_expression(this.read_expression(t[0])));let i=n;if(i>0)for(;0==(1&i););return 1!==i&&this.syntax_error("operand must be a power of two",t[0].start,t[0].end),this.align_dot(n),!0}decode_bitmask_immediate(e){let t,n;0===e.y&&60==(62&e.s)?(t=2,n=1+(1&e.s)):0===e.y&&56==(60&e.s)?(t=4,n=1+(3&e.s)):0===e.y&&48==(56&e.s)?(t=8,n=1+(7&e.s)):0===e.y&&32==(48&e.s)?(t=16,n=1+(15&e.s)):0===e.y&&0==(32&e.s)?(t=32,n=1+(31&e.s)):1===e.y&&(t=64,n=1+(63&e.s));let i=(1n<<BigInt(n))-1n;i=BigInt.asUintN(t,(i<<BigInt(t)|i)>>BigInt(e.r)),e.sz=1==e.z?64:32,e.vmask=32==e.sz?this.mask32:this.mask64,e.i=0n;for(let n=0;n<e.sz/t;n+=1)e.i|=i<<BigInt(n*t)}disassemble(e,t){try{const n=this.memory.memory.getUint32(e,this.little_endian);return this.disassemble_inst(n,e,t)}catch(t){throw t instanceof RangeError&&(t=`Instruction fetch from 0x${e.toString(16)} out of bounds`),t}}disassemble_inst(e,t,n){const i=this.inst_codec.decode(e);if(void 0===i)return;const r=i.info;void 0===n&&void 0!==t&&(n=BigInt(this.pa2va(t))),i.pa=t,i.va=n,i.opcode=r.opcode,i.handler=this.handlers.not_implemented,void 0!==t&&this.inst_decode&&(this.inst_decode[t/4]=i),i.dest=31===i.d?33:i.d,31===i.n&&(i.n=32),31===i.m&&(i.m=32),31===i.a&&(i.a=32),i.sz=0===i.z?32:64,i.vmask=32==i.sz?this.mask32:this.mask64;let s=0===i.z?"w":"x",o=31===i.d?`${s}zr`:`${s}${i.d}`,a=32===i.n?`${s}zr`:`${s}${i.n}`,l=32===i.m?`${s}zr`:`${s}${i.m}`;if("R"===r.type){if(i.iclass="alu",i.handler=this.handlers.alu,i.msel=void 0,i.flags=!1,i.alu=0,"bool"===i.opcode){switch(i.x){case 0:i.opcode=0===i.N?"and":"bic";break;case 1:i.opcode=0===i.N?"orr":"orn";break;case 2:i.opcode=0===i.N?"eor":"eon";break;case 3:i.opcode=0===i.N?"ands":"bics"}-1===i.N&&(i.N=1),i.alu={0:1,1:2,2:3,3:1}[i.x],3===i.x&&(i.flags=!0)}else"shift"===i.opcode?(i.opcode={0:"lsl",1:"lsr",2:"asr",3:"ror"}[i.s],i.alu=i.s+4):"adcsbc"===i.opcode?(i.opcode={0:"adc",1:"adcs",2:"sbc",3:"sbcs"}[i.x],i.N=i.x>=2?1:0,1&i.x&&(i.flags=!0),i.cin=2):"addsub"===i.opcode||"addsubx"===i.opcode?(i.opcode={0:"add",1:"adds",2:"sub",3:"subs"}[i.x],i.x>=2?(i.N=1,i.cin=1):(i.N=0,i.cin=0),1&i.x&&(i.flags=!0),"addsubx"===r.opcode&&(0==(1&i.x)&&31===i.d&&(i.dest=31,o=0===i.z?"wsp":"sp"),32===i.n&&(i.n=31,a=0===i.z?"wsp":"sp"),3!=(3&i.o)&&(l=`w${i.m}`))):(i.alu={madd:8,msub:9,sdiv:10,udiv:11,smulh:12,umulh:13}[i.opcode],void 0===i.alu&&(i.iclass="not_implemented",i.handler=this.handlers.not_implemented));let e=`${i.opcode} ${o},${a},${l}`;if(void 0!==i.a){e+=`,${32===i.a?`${s}zr`:`${s}${i.a}`}`}return void 0===i.o&&void 0!==i.j&&(0!==i.j&&(e+=`,${["lsl","lsr","asr","ror"][i.s]} #${i.j}`),i.j=BigInt(i.j),i.msel=i.s+9),void 0!==i.o&&(3===i.o&&0===i.j||(e+=`,${["uxtb","uxth","uxtw","uxtx","sxtb","sxth","sxtw","sxtx"][i.o]} ${i.j?" #"+i.j:""}`),i.j=BigInt(i.j),i.msel=i.o+1),i.assy=e,i}if("I"===r.type){i.opcode={0:"add",1:"adds",2:"sub",3:"subs"}[i.x],i.iclass="alu",i.handler=this.handlers.alu,i.x>=2?(i.N=1,i.cin=1):(i.N=0,i.cin=0),i.flags=1==(1&i.x),i.alu=0,i.msel=0,i.i=BigInt(i.i)&this.mask64,0==(1&i.x)&&31===i.d&&(i.dest=31,o=0===i.z?"wsp":"sp"),32===i.n&&(i.n=31,a=0===i.z?"wsp":"sp");let e=`${i.opcode} ${o},${a},#${i.i}`;return 1===i.s&&(e+=",lsl #12",i.i<<=12n),i.assy=e,i}if("D"===r.type){s="ldr.pc"===r.opcode?i.z?"x":"w":i.s>=2?1&i.s?"w":"x":3===i.z?"x":"w";let e=31===i.d?`${s}zr`:`${s}${i.d}`;if(i.vmask="x"==s?this.mask64:this.mask32,32===i.n?(i.n=31,a="sp"):a=`x${i.n}`,i.i=BigInt(void 0===i.I?void 0===i.i?0:i.i:i.I)&this.mask64,i.offset=i.i,"ldr.pc"===r.opcode)return 1===i.x?(i.opcode="ldrsw",e=e.replace("w","x"),i.sz=64,i.vmask=this.mask64):i.opcode="ldr",i.i=i.i<<2n,i.offset=i.i+n&this.mask64,i.iclass="ldr_literal",i.handler=this.handlers.ldr_literal,i.assy=`${i.opcode} ${e},0x${i.offset.toString(16)}`,i;if(i.iclass="ldst",i.handler=this.handlers.ldst,i.osel=0,0===i.s?(i.opcode="st",i.a=i.d):i.opcode="ld",0===i.s&&31===i.d&&(i.d=32),0===i.x&&(i.opcode+="u"),i.opcode+="r",i.opcode+=i.s>=2?"s":"",i.opcode+={0:"b",1:"h",2:i.s>=2?"w":"",3:""}[i.z],"ldst.off"===r.opcode){i.i=i.i<<BigInt(i.z)&this.mask64,i.offset=i.i;let t=`${i.opcode} ${e},[${a}`;return 0n!==i.i&&(t+=`,#${i.offset}`),i.assy=t+"]",i}if("ldst.reg"===r.opcode){const t={2:"uxtw",3:"lsl",6:"sxtw",7:"sxtx"}[i.o];i.osel={2:3,3:4,6:5,7:6}[i.o],i.shamt=BigInt(i.y?i.z:0),l=`${1&i.o?"x":"w"}${32===i.m?"zr":i.m}`;const n=i.shamt?`,${t} #${i.shamt}`:"";return i.assy=`${i.opcode} ${e},[${a},${l}${n}]`,i}if("ldst"===r.opcode){let t;switch(i.x){case 0:t=0n!==i.offset?`,#${i.offset}`:"",i.assy=`${i.opcode} ${e},[${a}${t}]`;break;case 1:i.osel=2,i.assy=`${i.opcode} ${e},[${a}],#${i.offset}`;break;case 2:i.assy="???";break;case 3:i.osel=1,i.assy=`${i.opcode} ${e},[${a},#${i.offset}]!`}return i}}if("P"===r.type){s=0===i.x?"w":"x",i.vmask=0===i.x?this.mask32:this.mask64,o=31===i.d?`${s}zr`:`${s}${i.d}`;const e=31===i.e?`${s}zr`:`${s}${i.e}`;i.opcode=1===i.x?"ldpsw":i.o?"ldp":"stp",i.iclass="ldstp",i.handler=this.handlers.ldstp,32===i.n?(i.n=31,a="sp"):a=`x${i.n}`;const t=2===i.x?3:2;switch(i.offset=BigInt(i.I<<t),i.s){case 1:i.assy=`${i.opcode} ${o},${e},[${a}],#${i.offset}`;break;case 2:i.assy=`${i.opcode} ${o},${e},[${a},#${i.offset}]`;break;case 3:i.assy=`${i.opcode} ${o},${e},[${a},#${i.offset}]!`}return i}if("B"===r.type)return i.i=BigInt(i.I<<2)&this.mask64,i.addr=i.i+n&this.mask64,i.opcode={0:"b",1:"bl"}[i.x],i.iclass="b",i.handler=this.handlers.b,i.assy=`${i.opcode} 0x${i.addr.toString(16)}`,i;if("CB"===r.type)return i.i=BigInt(i.I<<2)&this.mask64,i.addr=i.i+n&this.mask64,i.opcode={0:"cbz",1:"cbnz"}[i.x],i.iclass="cbz",i.handler=this.handlers.cbz,i.assy=`${i.opcode} ${a},0x${i.addr.toString(16)}`,i;if("TB"===r.type)return i.i=BigInt(i.I<<2)&this.mask64,i.addr=i.i+n&this.mask64,i.z&&(i.b+=32),i.mask=1n<<BigInt(i.b),i.opcode={0:"tbz",1:"tbnz"}[i.x],i.iclass="tb",i.handler=this.handlers.tb,i.assy=`${i.opcode} ${a},#${i.b},0x${i.addr.toString(16)}`,i;if("BL"===r.type)return i.opcode={0:"br",1:"blr",2:"ret"}[i.x],i.iclass="br",i.handler=this.handlers.br,i.assy=`${i.opcode} ${a}`,i;if("BCC"===r.type)return i.opcode={0:"b.eq",1:"b.ne",2:"b.cs",3:"b.cc",4:"b.mi",5:"b.pl",6:"b.vs",7:"b.vc",8:"b.hi",9:"b.ls",10:"b.ge",11:"b.lt",12:"b.gt",13:"b.le",14:"b.al",15:"b.nv"}[i.c],i.i=BigInt(i.I<<2)&this.mask64,i.addr=i.i+n&this.mask64,i.iclass="bcc",i.handler=this.handlers.bcc,i.assy=`${i.opcode} 0x${i.addr.toString(16)}`,i;if("CS"===r.type){i.x=2*i.x+i.y,i.opcode={0:"csel",1:"csinc",2:"csinv",3:"csneg"}[i.x],i.iclass="cs",i.handler=this.handlers.cs;const e={0:"eq",1:"ne",2:"cs",3:"cc",4:"mi",5:"pl",6:"vs",7:"vc",8:"hi",9:"ls",10:"ge",11:"lt",12:"gt",13:"le",14:"al",15:"nv"}[i.c];return i.assy=`${i.opcode} ${o},${a},${l},${e}`,i}if("CC"===r.type){i.opcode={0:"ccmn",1:"ccmp"}[i.x];const e={0:"eq",1:"ne",2:"cs",3:"cc",4:"mi",5:"pl",6:"vs",7:"vc",8:"hi",9:"ls",10:"ge",11:"lt",12:"gt",13:"le",14:"al",15:"nv"}[i.c];return i.iclass="cc",i.handler=this.handlers.cc,1===i.y?(i.m=BigInt(i.m),i.assy=`${i.opcode} ${a},#${i.m},#${i.j},${e}`):i.assy=`${i.opcode} ${a},${l},#${i.j},${e}`,i}if("BF"===r.type)return i.opcode={0:"sbfm",1:"bfm",2:"ubfm"}[i.x],i.s>=i.r?(i.ror=BigInt(i.r),i.maskn=(2n<<BigInt(i.s-i.r))-1n,i.maskd=1===i.x?~i.maskn&i.vmask:0n,i.sxtsz=0===i.x?i.s-i.r+1:0):(i.ror=BigInt(i.r),i.maskn=(2n<<BigInt(i.s))-1n<<BigInt(i.sz-i.r),i.maskd=1===i.x?~i.maskn&i.vmask:0n,i.sxtsz=0===i.x?i.sz-i.r+i.s+1:void 0),i.iclass="bfm",i.handler=this.handlers.bfm,i.assy=`${i.opcode} ${o},${a},#${i.r},#${i.s}`,i;if("BITS"===r.type)return 1===i.z&&0===i.y&&(i.opcode="rev32"),i.iclass={cls:"cls",clz:"cl",rbit:"rbit",rev:"rev",rev16:"rev",rev32:"rev"}[i.opcode],i.handler={cls:this.handlers.cl,clz:this.handlers.cl,rbit:this.handlers.rbit,rev:this.handlers.rev,rev16:this.handlers.rev,rev32:this.handlers.rev}[i.opcode],i.assy=`${i.opcode} ${o},${a}`,i;if("EXTR"===r.type)return i.j=BigInt(i.j),i.iclass="extr",i.handler=this.handlers.extr,i.assy=`extr ${o},${a},${l},#${i.j}`,i;if("IM"===r.type)return i.opcode={0:"and",1:"orr",2:"eor",3:"ands"}[i.x],i.msel=0,i.alu={0:1,1:2,2:3,3:1}[i.x],i.flags=3==i.x,i.iclass="alu",i.handler=this.handlers.alu,3!==i.x&&31===i.d&&(o=0===i.z?"wsp":"sp",i.dest=31),this.decode_bitmask_immediate(i),i.assy=`${i.opcode} ${o},${a},#0x${this.hexify(i.i,1==i.z?16:8)}`,i;if("A"===r.type){i.i=BigInt((i.I<<2)+i.i)&this.mask64;let e=n;return"adrp"===r.opcode&&(i.i=i.i<<12n&this.mask64,i.pcmask=~0xFFFn&this.mask64,e&=~0xFFFn),i.addr=i.i+e&this.mask64,i.iclass="adr",i.handler=this.handlers.adr,i.assy=`${i.opcode} ${o},#0x${i.addr.toString(16)}`,i}if("M"===r.type){i.opcode={0:"movn",2:"movz",3:"movk"}[i.x];const e=BigInt(16*i.s),t=i.s>0?`,LSL #${e}`:"";let n=i.i;return i.i=BigInt(i.i)<<e,i.maskn=BigInt(65535)<<e,i.iclass="movx",i.handler=this.handlers.movx,i.assy=`${i.opcode} ${o},#0x${n.toString(16)}${t}`,i}if("MA"===r.type){i.opcode=`${i.u?"u":"s"}m${i.x?"sub":"add"}l`,i.sz=64,i.vmask=this.mask64,i.alu={smaddl:14,smsubl:15,umaddl:16,umsubl:17}[i.opcode],i.iclass="alu",i.handler=this.handlers.alu,o=31===i.d?"xzr":`x${i.d}`,a=31===i.n?"wzr":`w${i.n}`,l=31===i.m?"wzr":`w${i.m}`;const e=31===i.a?"xzr":`x${i.a}`;return i.assy=`${i.opcode} ${o},${a},${l},${e}`,i}return"H"===r.type?(["svc","eret"].includes(i.opcode)?(i.iclass="not_implmented",i.handler=this.handlers.not_implemented):(i.iclass="hlt",i.handler=this.handlers.hlt),i.incrpc="brk"===i.opcode,i.assy=`${i.opcode} #${i.j}`,i):"ERET"===r.type?(i.handler=this.handlers.not_implemented,i.assy=`${i.opcode}`,i):"NOP"===r.type?(i.iclass="nop",i.handler=this.handlers.nop,i.assy=i.opcode,i):"SYS"===r.type?(i.opcode={0:"msr",1:"mrs"}[i.x],0===i.x&&31===i.d&&(i.d=32),i.sysreg={23056:"NZCV",1:"console",2:"mouse",3:"cycles",default:"???"}[i.j],i.iclass="sysreg",i.handler=this.handlers.sysreg,0===i.x?i.assy=`msr ${i.sysreg},${o}`:i.assy=`mrs ${o},${i.sysreg}`,i):(i.iclass="not_implemented",i.assy="???",i)}},SimTool.ASim=class extends SimTool.ArmA64Assembler{static asim_version="asim.81";constructor(e,t){super(e,`Arm ${t?"Educore":"A64"} ${SimTool.ASim.asim_version}`)}handle_alu(e,t,n){const i=e.register_file[t.n]&t.vmask;let r,s,o;if(0===t.msel)r=t.i;else if(r=e.register_file[t.m]&t.vmask,void 0!==t.msel)switch(t.msel){case 1:r=BigInt.asUintN(8,r)<<t.j;break;case 2:r=BigInt.asUintN(16,r)<<t.j;break;case 3:r=BigInt.asUintN(32,r)<<t.j;break;case 4:r=BigInt.asUintN(64,r)<<t.j;break;case 5:r=BigInt.asIntN(8,r)<<t.j;break;case 6:r=BigInt.asIntN(16,r)<<t.j;break;case 7:r=BigInt.asIntN(32,r)<<t.j;break;case 8:r=BigInt.asIntN(64,r)<<t.j;break;case 9:r<<=t.j;break;case 10:r>>=t.j;break;case 11:r=BigInt.asIntN(t.sz,r)>>t.j;break;case 12:r=(r<<BigInt(t.sz)|r)>>t.j;break;default:r=0n}switch(1===t.N&&(r=~r),r&=t.vmask,t.alu){case 0:o=t.cin,2===o&&(o=2&e.nzcv?1:0),o=BigInt(o),s=i+r+o;break;case 1:s=i&r;break;case 2:s=i|r;break;case 3:s=i^r;break;case 4:s=i<<r;break;case 5:s=i>>r;break;case 6:s=BigInt.asIntN(t.sz,i)>>r;break;case 7:s=(i<<BigInt(t.sz)|i)>>r;break;case 8:s=e.register_file[t.a]+i*r;break;case 9:s=e.register_file[t.a]-i*r;break;case 10:s=BigInt.asIntN(t.sz,i)/BigInt.asIntN(t.sz,r);break;case 11:s=i/r;break;case 12:s=BigInt.asIntN(t.sz,i)*BigInt.asIntN(t.sz,r)>>64n;break;case 13:s=i*r>>64n;break;case 14:s=e.register_file[t.a]+BigInt.asIntN(32,i)*BigInt.asIntN(32,r);break;case 15:s=e.register_file[t.a]-BigInt.asIntN(32,i)*BigInt.asIntN(32,r);break;case 16:s=e.register_file[t.a]+BigInt.asUintN(32,i)*BigInt.asUintN(32,r);break;case 17:s=e.register_file[t.a]-BigInt.asUintN(32,i)*BigInt.asUintN(32,r);break;default:s=0n}const a=s&t.vmask;if(t.flags){if(e.nzcv=0,BigInt.asIntN(t.sz,a)<0&&(e.nzcv|=8),0n===a&&(e.nzcv|=4),0===t.alu){a!==s&&(e.nzcv|=2);const n=BigInt.asIntN(t.sz,i)+BigInt.asIntN(t.sz,r)+o;BigInt.asIntN(t.sz,n)!==n&&(e.nzcv|=1)}if(n){const t=e.right.querySelector("#nzcv");t.classList.add("cpu_tool-reg-write"),t.innerHTML=e.nzcv.toString(2).padStart(4,"0")}}e.register_file[t.dest]=a,e.pc=e.pc+4n&e.mask64,n&&(e.reg_read(t.n),0!==t.msel&&e.reg_read(t.m),void 0!==t.o&&e.reg_read(t.o),33!==t.dest&&e.reg_write(t.dest,a))}handle_movx(e,t,n){let i=0n;3===t.x&&(i=e.register_file[t.dest]&~t.maskn&t.vmask),i|=t.i,0===t.x&&(i=~i&t.vmask),e.register_file[t.dest]=i,e.pc=e.pc+4n&e.mask64,n&&e.reg_write(t.dest,i)}handle_b(e,t,n){if(1===t.x&&(e.register_file[30]=e.pc+4n&e.mask64,n&&e.reg_write(30,e.register_file[30])),t.addr===e.pc)throw"Halt Execution";e.pc=t.addr}check_cc(e,t){let n;switch(t){case 0:return 0!=(4&e);case 1:return 0==(4&e);case 2:return 0!=(2&e);case 3:return 0==(2&e);case 4:return 0!=(8&e);case 5:return 0==(8&e);case 6:return 0!=(1&e);case 7:return 0==(1&e);case 8:return 2==(6&e);case 9:return 2!=(6&e);case 10:return n=9&e,0===n||9===n;case 11:return n=9&e,0!==n&&9!==n;case 12:return n=9&e,0==(4&e)&&(0===n||9===n);case 13:return n=9&e,4==(4&e)||0!==n&&9!==n;case 14:return!0;default:return!1}}handle_cc(e,t,n){const i=e.register_file[t.n]&t.vmask;let r,s=1===t.y?t.m:e.register_file[t.m]&t.vmask;if(e.check_cc(e.nzcv,t.c)){let n=0n;t.x&&(n=1n,s=~s&t.vmask),r=i+s+n;const o=r&t.vmask;e.nzcv=0,BigInt.asIntN(t.sz,o)<0&&(e.nzcv|=8),0n===o&&(e.nzcv|=4),o!==r&&(e.nzcv|=2);const a=BigInt.asIntN(t.sz,i),l=BigInt.asIntN(t.sz,s),c=0===t.x?a+l:a-l;BigInt.asIntN(t.sz,c)!==c&&(e.nzcv|=1)}else e.nzcv=t.j;if(e.pc=e.pc+4n&e.mask64,n){const t=e.right.querySelector("#nzcv");t.classList.add("cpu_tool-reg-write"),t.innerHTML=e.nzcv.toString(2).padStart(4,"0")}}handle_cs(e,t,n){let i;if(e.check_cc(e.nzcv,t.c))i=e.register_file[t.n],n&&e.reg_read(t.n);else{switch(i=e.register_file[t.m],t.x){case 0:break;case 1:i+=1n;break;case 2:i=~i;break;case 3:i=-i}n&&e.reg_read(t.m)}i&=t.vmask,e.register_file[t.dest]=i,e.pc=e.pc+4n&e.mask64,n&&e.reg_write(t.dest,i)}handle_bcc(e,t,n){if(e.check_cc(e.nzcv,t.c)){if(t.addr===e.pc)throw"Halt Execution";e.pc=t.addr}else e.pc=e.pc+4n&e.mask64}handle_br(e,t,n){1===t.x&&(e.register_file[30]=e.pc+4n&e.mask64,n&&e.reg_write(30,e.register_file[30])),n&&e.reg_read(t.h);const i=e.register_file[t.n];if(i===e.pc)throw"Halt Execution";e.pc=i}handle_cbz(e,t,n){n&&e.reg_read(t.n);const i=(0n===e.register_file[t.n]?0===t.x:1===t.x)?t.addr:e.pc+4n&e.mask64;if(i===e.pc)throw"Halt Execution";e.pc=i,n&&e.reg_read(t.n)}handle_tb(e,t,n){n&&e.reg_read(t.n);const i=0n===(e.register_file[t.n]&t.mask);if(t.x?!i:i){if(e.pc===t.addr)throw"Halt Execution";e.pc=t.addr}else e.pc=e.pc+4n&e.mask64}handle_ldr_literal(e,t,n){const i=e.va_to_phys(t.offset);let r;try{r=e.memory.read_biguint64(i),1===t.x?r=BigInt.asIntN(32,r)&e.mask64:r&=t.vmask}catch(e){throw e instanceof RangeError&&(e=`memory address 0x${i.toString(16)} out of bounds`),e}e.register_file[t.dest]=r,e.pc=e.pc+4n&e.mask64,n&&(e.mem_read(i,1==t.x||0===t.z?32:64),e.reg_write(t.dest,r))}handle_ldst(e,t,n){let i=e.register_file[t.n];switch(t.osel){case 0:case 1:i=i+t.offset&e.mask64,1===t.osel&&(e.register_file[t.n]=i,n&&e.reg_write(t.n,i));break;case 2:e.register_file[t.n]=e.register_file[t.n]+t.offset&e.mask64,n&&e.reg_write(t.n,e.register_file[t.n]);break;case 3:i=i+((e.register_file[t.m]&e.mask32)<<t.shamt)&e.mask64;break;case 4:case 6:i=i+(e.register_file[t.m]<<t.shamt)&e.mask64;break;case 5:i=i+(BigInt.asIntN(32,e.register_file[t.m])<<t.shamt)&e.mask64}const r=e.va_to_phys(i);try{if(0===t.s){let i=e.register_file[t.d];switch(t.z){case 0:e.memory.write_bigint8(r,i);break;case 1:e.memory.write_bigint16(r,i);break;case 2:e.memory.write_bigint32(r,i);break;case 3:e.memory.write_bigint64(r,i)}n&&(e.reg_read(t.d),t.z<2&&(i=e.memory.read_biguint32(-4&r)),e.mem_write(r,i,3===t.z?64:32))}else{let i;if(1===t.s)switch(t.z){case 0:i=e.memory.read_biguint8(r);break;case 1:i=e.memory.read_biguint16(r);break;case 2:i=e.memory.read_biguint32(r);break;case 3:i=e.memory.read_biguint64(r)}else{switch(t.z){case 0:i=e.memory.read_bigint8(r);break;case 1:i=e.memory.read_bigint16(r);break;case 2:i=e.memory.read_bigint32(r);break;case 3:i=e.memory.read_bigint64(r)}i&=t.vmask}e.register_file[t.dest]=i,n&&(e.mem_read(r,3===t.z?64:32),e.reg_write(t.dest,i))}}catch(e){throw e instanceof RangeError&&(e=`memory address 0x${r.toString(16)} out of bounds`),e}e.pc=e.pc+4n&e.mask64}handle_ldstp(e,t,n){let i,r=e.register_file[t.n];switch(n&&e.reg_read(t.n),t.s){case 1:e.register_file[t.n]=e.register_file[t.n]+t.offset&e.mask64,n&&e.reg_write(t.n,e.register_file[t.n]);break;case 2:r=r+t.offset&e.mask64;break;case 3:r=r+t.offset&e.mask64,e.register_file[t.n]=r,n&&e.reg_write(t.n,r)}const s=e.va_to_phys(r),o=e.va_to_phys(r+(2==t.x?8n:4n));try{if(0===t.o)if(0===t.x){const r=e.register_file[t.d]&e.mask32;i=s,e.memory.write_bigint32_aligned(s,r);const a=e.register_file[t.e]&e.mask32;i=o,e.memory.write_bigint32_aligned(o,a),n&&(e.reg_read(t.d),e.reg_read(t.e),e.mem_write(s,r),e.mem_write(o,a))}else i=s,e.memory.write_bigint64_aligned(s,e.register_file[t.d]),i=o,e.memory.write_bigint64_aligned(o,e.register_file[t.e]),n&&(e.reg_read(t.d),e.reg_read(t.e),e.mem_write(s,e.register_file[t.d],64),e.mem_write(o,e.register_file[t.e],64));else 0===t.x?(i=s,e.register_file[t.d]=e.memory.read_biguint32_aligned(s),i=o,e.register_file[t.e]=e.memory.read_biguint32_aligned(o),n&&(e.reg_write(t.d,e.register_file[t.d]),e.reg_write(t.e,e.register_file[t.e]),e.mem_read(s),e.mem_read(o))):2===t.x?(i=s,e.register_file[t.d]=e.memory.read_bigint64_aligned(s),i=o,e.register_file[t.e]=e.memory.read_bigint64_aligned(o),n&&(e.reg_write(t.d,e.register_file[t.d]),e.reg_write(t.e,e.register_file[t.e]),e.mem_read(s,64),e.mem_read(o,64))):(i=s,e.register_file[t.d]=e.memory.read_bigint32_aligned(s),i=o,e.register_file[t.e]=e.memory.read_bigint32_aligned(o),n&&(e.reg_write(t.d,e.register_file[t.d]),e.reg_write(t.e,e.register_file[t.e]),e.mem_read(s),e.mem_read(o)))}catch(e){throw e instanceof RangeError&&(e=`memory address 0x${i.toString(16)} out of bounds`),e}e.pc=e.pc+4n&e.mask64}handle_cl(e,t,n){let i=0,r=e.register_file[t.n]&t.vmask;const s=1===t.z?0x8000000000000000n:0x80000000n;if("cls"===t.opcode){const e=r&s;for(let n=1;n<t.sz&&(r<<=1n,(r&s)===e);n+=1)i+=1}else for(let e=0;e<t.sz&&0n===(r&s);e+=1)r<<=1n,i+=1;e.register_file[t.dest]=BigInt(i),e.pc=e.pc+4n&e.mask64,n&&(e.reg_read(t.n),e.reg_write(t.dest,i))}handle_rbit(e,t,n){let i=0n,r=e.register_file[t.n]&t.vmask;for(let e=0;e<t.sz;e+=1)i<<=1n,1n===(1n&r)&&(i|=1n),r>>=1n;e.register_file[t.dest]=i,e.pc=e.pc+4n&e.mask64,n&&(e.reg_read(t.n),e.reg_write(t.dest,i))}handle_rev(e,t,n){let i,r=0n,s=e.register_file[t.n]&t.vmask;i="rev"===t.opcode?32===t.sz?[24n,16n,8n,0n]:[56n,48n,40n,32n,24n,16n,8n,0n]:"rev16"===t.opcode?32===t.sz?[8n,0n,24n,16n]:[8n,0n,24n,16n,40n,32n,56n,48n]:[24n,16n,8n,0n,56n,48n,40n,32n];for(let e of i)r|=(0xFFn&s)<<e,s>>=8n;e.register_file[t.dest]=r,e.pc=e.pc+4n&e.mask64,n&&(e.reg_read(t.n),e.reg_write(t.dest,r))}handle_extr(e,t,n){let i=(e.register_file[t.n]&t.vmask)<<BigInt(t.sz)|e.register_file[t.m]&t.vmask;i=i>>t.j&t.vmask,e.register_file[t.dest]=i,e.pc=e.pc+4n&e.mask64,n&&(e.reg_read(t.n),e.reg_read(t.m),e.reg_write(t.dest,i))}handle_bfm(e,t,n){let i=(e.register_file[t.n]&t.vmask)<<BigInt(t.sz)|e.register_file[t.n]&t.vmask;i=i>>t.ror&t.maskn,i|=e.register_file[t.d]&t.maskd,t.sxtsz&&(i=BigInt.asIntN(t.sxtsz,i)&t.vmask),e.register_file[t.dest]=i,e.pc=e.pc+4n&e.mask64,n&&(e.reg_read(t.n),e.reg_read(t.m),e.reg_write(t.dest,i))}handle_adr(e,t,n){e.register_file[t.dest]=t.addr,e.pc=e.pc+4n&e.mask64,n&&e.reg_write(t.dest,t.addr)}handle_hlt(e,t,n){throw t.incrpc&&(e.pc=e.pc+4n&e.mask64),n&&e.next_pc(e.pc),"hlt"===t.opcode&&e.verify_memory(),"Halt Execution"}handle_nop(e,t,n){if("yield"===t.opcode)throw"Halt Execution";e.pc=e.pc+4n&e.mask64}handle_sysreg(e,t,n){if(0===t.x){switch(t.j){case 23056:if(e.nzcv=Number(e.register_file[t.d]>>28n&0xFn),n){const t=e.right.querySelector("#nzcv");t.classList.add("cpu_tool-reg-write"),t.innerHTML=e.nzcv.toString(2).padStart(4,"0")}break;case 1:const i=String.fromCharCode(Number(0xFFFFn&e.register_file[t.d]));e.console_output(i)}n&&e.reg_read(t.d)}else{let i;switch(t.j){case 23056:i=BigInt(e.nzcv)<<28n,n&&e.right.querySelector("#nzcv").classList.add("cpu_tool-reg-read");break;case 1:i=e.console_input(),i=void 0===i?0n:BigInt(i.charCodeAt(0));break;case 2:i=BigInt(e.mouse_input());break;case 3:i=BigInt(e.ncycles)}e.register_file[t.dest]=i,n&&e.reg_write(t.d,i)}e.pc=e.pc+4n&e.mask64}handler_info(){this.handlers={adr:this.handle_adr,alu:this.handle_alu,b:this.handle_b,bcc:this.handle_bcc,bfm:this.handle_bfm,br:this.handle_br,cbz:this.handle_cbz,cc:this.handle_cc,cl:this.handle_cl,cs:this.handle_cs,extr:this.handle_extr,hlt:this.handle_hlt,ldr_literal:this.handle_ldr_literal,ldst:this.handle_ldst,ldstp:this.handle_ldstp,movx:this.handle_movx,nop:this.handle_nop,not_implemented:this.handle_not_implemented,rbit:this.handle_rbit,rev:this.handle_rev,sysreg:this.handle_sysreg,tb:this.handle_tb}}},SimTool.ASimPipelined=class extends SimTool.ArmA64Assembler{constructor(e){super(e,`Arm Educore ${SimTool.ASim.asim_version}`),this.quanta=1e5}disassemble_inst(e,t,n){let i=super.disassemble_inst(e,t,n);if(void 0===i)return{pa:t,va:n,inst:e,info:{},opcode:"???",assy:"???"};switch(void 0!==i.dest&&33!==i.dest&&(i.rd_addr=i.dest,i.write_en=1),void 0!==i.n&&(32===i.n?(i.read_n_valid=0,i.read_reg_an=31,i.read_n_sp=0):(i.read_n_valid=1,i.read_reg_an=i.n,i.read_n_sp=31===i.n),i.fex_n_mux=2,i.alu_op_a_mux=2),void 0!==i.m&&(32===i.m?(i.read_m_valid=0,i.read_reg_am=31):(i.read_m_valid=1,i.read_reg_am=i.m),i.fex_m_mux=1,i.fex_m_mux=1,i.barrel_lo_mux=1,i.barrel_hi_mux=1,i.barrel_op=0,i.original_shamt=i.shamt,i.shamt=0n,i.tmask=i.vmask,i.alu_op_b_mux=0),void 0!==i.a&&(32===i.a?(i.read_a_valid=0,i.read_reg_aa=31):(i.read_a_valid=1,i.read_reg_aa=i.a)),i.FnH=i.vmask,i.imm_sz=i.vmask==this.mask64?64:32,i.iclass){case"adr":i.fex_n_mux="adrp"===i.opcode?1:0,i.fex_m_mux=0,i.FnH=this.mask64,i.barrel_op=0,i.shamt=0n,i.barrel_lo_mux=1,i.barrel_hi_mux=1,i.wtmask=0,i.bitext_sign_ext=0,i.alu_op_a_mux=2,i.alu_op_b_mux=0,i.alu_invert_b=0,i.alu_cmd=4,i.ex_out_mux=1;break;case"alu":if(void 0===i.msel)i.barrel_op=0,i.shamt=0n;else if(0===i.msel)0===i.alu?(i.fex_m_mux=0,i.barrel_lo_mux=1,i.barrel_hi_mux=1,i.barrel_op=0,i.shamt=0n,i.alu_op_b_mux=0):i.alu_op_b_mux=1;else if(i.msel<=8)switch(i.shamt=i.j,i.msel>=5&&(i.bitext_sign_ext=1),3&i.msel){case 1:i.imm_sz=8+Number(i.j);break;case 2:i.imm_sz=16+Number(i.j);break;case 3:i.imm_sz=32+Number(i.j);break;case 0:i.imm_sz=64}else i.barrel_op=i.msel-9,i.shamt=i.j;switch(i.alu_invert_b=i.N,i.alu){case 0:i.alu_cmd=4+i.cin;break;case 1:i.alu_cmd=0;break;case 2:i.alu_cmd=1;break;case 3:i.alu_cmd=2;break;default:throw"Unsupported ALU operation"}i.flags&&(i.pstate_en=1,i.pstate_mux=0),i.ex_out_mux=1;break;case"b":i.br_condition_mux=1,i.next_PC_mux=0,i.PC_add_op_mux=1,i.fex_n_mux=0,i.fex_m_mux=0,1===i.x&&(i.ex_out_mux=0,i.rd_addr=30,i.write_en=1);break;case"bcc":i.br_condition_mux=0,i.next_PC_mux=0,i.PC_add_op_mux=1,i.fex_n_mux=0,i.fex_m_mux=0;break;case"bfm":i.alu_op_a_mux=1==i.x?2:0,i.barrel_lo_mux=0,i.barrel_hi_mux=0,i.barrel_op=3,i.shamt=i.ror,i.wtmask=1,i.sxtsz>0&&(i.bitext_sign_ext=1,i.imm_sz=i.sxtsz),i.alu_op_b_mux=0,i.alu_cmd=1,i.ex_out_mux=1;break;case"br":i.next_PC_mux=1,1===i.x&&(i.ex_out_mux=0,i.rd_addr=30,i.write_en=1);break;case"cc":i.y&&(i.read_reg_am=void 0,i.read_m_valid=0,i.i=BigInt(i.m),i.fex_m_mux=0,i.barrel_lo_mux=1,i.barrel_hi_mux=1,i.barrel_op=0,i.original_shamt=i.shamt,i.shamt=0n,i.read_m_valid=0),i.x?(i.alu_invert_b=1,i.alu_cmd=5):i.alu_cmd=4,i.pstate_mux=2,i.pstate_en=1;break;case"cs":i.alu_op_a_mux=0,i.alu_invert_b=2&i.x?1:0,i.alu_cmd=1&i.x?5:1,i.ex_out_mux=2;break;case"extr":i.barrel_lo_mux=1,i.barrel_hi_mux=0,i.barrel_op=3,i.shamt=i.j,i.alu_op_a_mux=0,i.alu_cmd=1,i.ex_out_mux=1;break;case"hlt":case"nop":break;case"ldr_literal":i.fex_n_mux=0,i.fex_m_mux=0,i.FnH=this.mask64,i.barrel_op=0,i.shamt=0n,i.barrel_lo_mux=1,i.barrel_hi_mux=1,i.wtmask=0,i.bitext_sign_ext=0,i.alu_op_a_mux=2,i.alu_op_b_mux=0,i.alu_invert_b=0,i.alu_cmd=4,i.ex_out_mux=1,i.mem_read=1,i.mem_addr_mux=0,i.mem_load_FnH=i.vmask,i.mem_size=1===i.z?64:32,i.mem_sign_ext=1===i.x,32!=i.dest&&(i.wload_en=1,i.rt_addr=i.dest,i.write_en=0,i.rd_addr=void 0);break;case"ldst":i.write_en=0,i.osel<=2?(i.fex_m_mux=0,i.barrel_lo_mux=1,i.barrel_hi_mux=1,i.barrel_op=0,i.shamt=0n,i.imm_sz=64,i.mem_addr_mux=2===i.osel?1:0,0!==i.osel?(i.write_en=1,i.rd_addr=i.n):(i.write_en=0,i.rd_addr=void 0)):(i.shamt=i.original_shamt,i.bitext_sign_ext=5==i.osel?1:0,i.imm_sz=1&i.osel?32+Number(i.shamt):64,i.mem_addr_mux=0),i.alu_op_b_mux=0,i.alu_invert_b=0,i.alu_cmd=4,i.ex_out_mux=1,i.mem_size=8<<i.z,0===i.s?(33===i.dest?(i.read_a_valid=0,i.read_reg_aa=31):(i.read_a_valid=1,i.read_reg_aa=i.dest),i.mem_write=1):(i.mem_read=1,i.mem_sign_ext=i.s>=2?1:0,i.mem_load_FnH=i.vmask,33!==i.dest&&(i.wload_en=1,i.rt_addr=i.dest));break;case"movx":switch(i.fex_m_mux=0,i.FnH=i.vmask,i.barrel_lo_mux=1,i.barrel_hi_mux=1,i.barrel_op=0,i.shamt=BigInt(16*i.s),i.i>>=i.shamt,i.alu_op_b_mux=0,i.alu_cmd=1,i.x){case 0:i.alu_op_a_mux=0,i.alu_invert_b=1;break;case 2:i.alu_op_a_mux=0;break;case 3:32===i.dest?(i.read_a_valid=0,i.read_reg_aa=31):(i.read_a_valid=1,i.read_reg_aa=i.dest),i.alu_op_a_mux=1,i.wtmask=1}i.ex_out_mux=1;break;case"sysreg":if(i.x)i.ex_out_mux=3;else{switch(33===i.dest?(i.read_a_valid=0,i.read_reg_aa=31):(i.read_a_valid=1,i.read_reg_aa=i.dest),i.j){case 23056:i.pstate_mux=1,i.pstate_en=1;break;case 1:i.console_en=1;break;default:throw`MSR: Unrecognized sysreg destination ${info.j}`}i.rd_addr=void 0,i.write_en=0}break;default:throw`Unsupported instruction class in disassemble_inst: ${i.iclass}`}return i}static template_simulator_display='\n<style>\n #pipeline-diagram { flex: 1 1 ; padding: 5px; min-width: 430px; min-height: 532px;}\n #pipeline-diagram .stage-divider { stroke: #DDD; stroke-width: 2; fill: none; }\n #pipeline-diagram .stage-label { font: 12px serif; stroke: none; fill: grey; }\n #pipeline-diagram .wire { stroke: #666; stroke-width: 0.5; fill: none;}\n #pipeline-diagram .wire.highlight { stroke: red; }\n #pipeline-diagram .italic { font-style: italic !important; }\n #pipeline-diagram .outline { stroke: #AAA; stroke-width: 0.5; fill: none;}\n #pipeline-diagram .reg { stroke: #AAA; stroke-width: 0.5; fill: #DDD;}\n #pipeline-diagram .logic { fill: #EFE;}\n #pipeline-diagram .reg-value { stroke: black; stroke-width: 0.5; fill: #EFE;}\n #pipeline-diagram .label { font: 8px sanserif; fill: #666; }\n #pipeline-diagram .link { font: 10px sanserif; fill: blue; text-decoration: underline; }\n #pipeline-diagram .label.highlight { fill: red; }\n #pipeline-diagram .small-label { font: 6px sanserif; fill: #666; }\n #pipeline-diagram .small-label.highlight { fill: red; }\n #pipeline-diagram .reg-name { font: 8px sanserif; fill: #666; }\n #pipeline-diagram .icon { font: 8px sanserif; fill: #666; }\n #pipeline-diagram .value { font: 8px monospace; fill: blue; }\n #pipeline-diagram .value.highlight { fill: red; }\n #pipeline-diagram .mux-value { font: 7px monospace; fill: blue; }\n #pipeline-diagram .mux-value.highlight { fill: red; }\n #simulator-display .banner-link { margin-left: 0.5em; font-size:10px; color: white; text-decoration: underline; }\n </style>\n<div id="simulator-display" style="flex: 1 1 auto; display: flex; overflow: auto;">\n <div style="flex: 0 0 auto; display: flex; flex-direction: column; overflow: auto;">\n <div class="cpu_tool-banner">Registers</div>\n <div class="cpu_tool-pane" id="registers" style="font: 9pt monospace; line-height: 7pt;"></div>\n <div class="cpu_tool-banner" style="margin-top: 3px;">Memory</div>\n <div class="cpu_tool-pane" id="memory" style="flex: 1 1 auto; font: 9pt monospace; line-height: 7pt; overflow-y:scroll; min-height: 50px;"></div>\n </div>\n <div style="flex: 1 1 auto; display: flex; flex-direction: column; margin-left: 3px;">\n <div class="cpu_tool-banner">\n Datapath\n <a class="banner-link" href="https://github.com/computation-structures/asim/blob/main/PIPELINE.md" target="_blank">diagram help</a>\n </div>\n <svg style="flex: 1 1 auto;" class="cpu_tool-pane" id="pipeline-diagram" preserveAspectRatio="xMinYMin">\n <defs>\n <marker id="arrow" markerWidth="4" markerHeight="4" refX="4" refY="2" orient="auto">\n <polygon stroke-linejoin="miter" points="0 0, 4 2, 0 4"/>\n </marker>\n </defs>\n </svg>\n <div id="console-wrapper" class="cpu_tool-console-wrapper" style="display: none;">\n <div class="cpu_tool-banner">Console</div>\n <textarea id="console" class="cpu_tool-console"></textarea>\n </div>\n </div>\n</div>\n';cpu_gui_setup(){const e=this;this.add_action_button("Assemble",(function(){e.assemble()})),this.right.innerHTML=this.template_simulator_header+SimTool.ASimPipelined.template_simulator_display,this.cpu_gui_simulation_controls();const t=this;this.console=this.right.querySelector("#console");const n=this.right.querySelector("#show-console"),i=this.right.querySelector("#console-wrapper");n.addEventListener("click",(function(){"Show console"===n.innerHTML?(i.style.display="flex",n.innerHTML="Hide console"):(i.style.display="none",n.innerHTML="Show console")})),this.console_chars=[],this.mouse_click=-1,this.console.addEventListener("beforeinput",(function(e){let n;return"insertLineBreak"===e.inputType?n="\n":"deleteContentBackward"===e.inputType?n="":"insertText"===e.inputType&&(n=e.data),n&&t.console_chars.length<8&&t.console_chars.push(n),e.preventDefault(),!1})),this.console.addEventListener("mousedown",(function(e){t.console.focus(),t.mouse_click=((65535&e.clientX)<<16)+(65535&e.clientY)}))}fill_in_simulator_gui(){let e,t;this.right.focus(),e=['<table cellspacing="3" border="0">'];for(let n=0;n<=31;n+=1)t=this.dp.register_file[n],e.push(`<tr><td class="cpu_tool-addr">${31==n?"sp":`x${n}`}</td><td ${t?"":'class="cpu_tool-unused"'} id="r${n}">${this.hexify(t,16)}</td></tr>`);e.push("</table>"),this.right.querySelector("#registers").innerHTML=e.join("\n");const n=Math.ceil(Math.log2(this.memory.byteLength)/4);e=['<table cellspacing="3" border="0">'];for(let t=0;t<this.memory.byteLength;t+=8)e.push(`<tr><td class="cpu_tool-addr">${this.hexify(t,n)}</td><td id="m${t}">${this.location(t,64)}</td></tr>`);e.push("</table>"),this.right.querySelector("#memory").innerHTML=e.join("\n")}emulation_pc(){return this.dp&&this.dp.ex_inst?this.dp.ex_inst.va:void 0}emulation_reset(){super.emulation_reset(),void 0===this.dp&&(this.dp={register_file:new Array(32),previous_insts:[]},xdp=this.dp,this.nop_inst=this.disassemble_inst(3573751839),this.nop_inst.assy="↳nop"),void 0!==this.assembler_memory&&(this.memory.load_bytes(this.assembler_memory),void 0!==this.inst_decode&&this.inst_decode.length==this.assembler_memory.byteLength/4||(this.inst_decode=Array(this.assembler_memory.byteLength/4))),this.memory.reset(this.caches);const e=this.dp;e.register_file.fill(0n),e.previous_insts.length=0,e.nzcv=0,e.halt=void 0,e.if_pc=0n,e.id_pc=void 0,e.id_inst=this.nop_inst,e.fex_n=void 0,e.fex_m=void 0,e.fex_a=void 0,e.ex_inst=this.nop_inst,e.mem_n=void 0,e.mem_ex_out=void 0,e.mem_a=void 0,e.mem_inst=this.nop_inst,e.wb_ex_out=void 0,e.wb_mem_out=void 0,e.wb_inst=this.nop_inst,void 0!==this.assembler_memory&&(this.pipeline_propagate(!0),this.update_display(),this.next_pc(0))}clear_highlights(){}emulation_step(e){e&&this.clear_highlights(),this.pipeline_clock(e),this.pipeline_propagate(e);const t=this.dp;for(;t.previous_insts.length>4;)t.previous_insts.shift();t.previous_insts.push(t.ex_inst),e&&(this.update_display(),this.next_pc())}pipeline_propagate(e){const t=this.dp,n=t.id_inst,i=t.ex_inst,r=t.mem_inst,s=t.wb_inst;if("hlt"!==i.opcode&&"yield"!==i.opcode||(t.halt=!0),void 0!==i.c){const e=0!=(8&t.nzcv),n=0!=(4&t.nzcv),r=0!=(2&t.nzcv),s=0!=(1&t.nzcv);switch(i.c){case 0:t.pstate_match=n,t.cc_check="EQ";break;case 1:t.pstate_match=!n,t.cc_check="NE";break;case 2:t.pstate_match=r,t.cc_check="CS";break;case 3:t.pstate_match=!r,t.cc_check="CC";break;case 4:t.pstate_match=e,t.cc_check="MI";break;case 5:t.pstate_match=!e,t.cc_check="PL";break;case 6:t.pstate_match=s,t.cc_check="VS";break;case 7:t.pstate_match=!s,t.cc_check="VC";break;case 8:t.pstate_match=!n&r,t.cc_check="HI";break;case 9:t.pstate_match=n|!r,t.cc_check="LS";break;case 10:t.pstate_match=e===s,t.cc_check="GE";break;case 11:t.pstate_match=e!==s,t.cc_check="LT";break;case 12:t.pstate_match=e===s&!n,t.cc_check="GT";break;case 13:t.pstate_match=e!==s|n,t.cc_check="LE";break;case 14:t.pstate_match=1,t.cc_check="AL";break;case 15:t.pstate_match=0,t.cc_check="NV";break;default:t.pstate_match=0,t.cc_check="-"}}else t.cc_check=void 0,t.pstate_match=0;if(t.branch_taken=i.br_condition_mux||t.pstate_match,t.bubble=i.next_PC_mux||i.PC_add_op_mux&&t.branch_taken,t.stall=!t.bubble&&i.wload_en&&(n.read_n_valid&&n.read_reg_an==i.rt_addr||n.read_m_valid&&n.read_reg_am==i.rt_addr||n.read_a_valid&&n.read_reg_aa==i.rt_addr&&!n.mem_write),s.mem_read){let e=t.wb_mem_out;e=s.mem_sign_ext?BigInt.asIntN(s.mem_size,e):BigInt.asUintN(s.mem_size,e),t.wb_mem_out_sxt=e&s.mem_load_FnH}else t.wb_mem_out_sxt=void 0;if(t.rt_write=s.wload_en,t.rt_addr=s.rt_addr,t.rd_write=s.write_en,t.rd_addr=s.rd_addr,t.mem_read=r.mem_read,t.mem_write=r.mem_write,r.mem_write||r.mem_read)if(t.mem_VA=r.mem_addr_mux?t.mem_n:t.mem_ex_out,t.mem_PA=this.va_to_phys(t.mem_VA),t.mem_addr_mux=r.mem_addr_mux?"[MEM_n]":"[MEM_EX_out]",t.mem_size=r.mem_size,r.mem_write){const e=(1n<<BigInt(r.mem_size))-1n;s.wload_en&&r.read_reg_aa===s.rt_addr?(t.mem_wdata=t.wb_mem_out_sxt&e,t.mem_wdata_mux="[WB_MEM_sxt]"):(t.mem_wdata=t.mem_a&e,t.mem_wdata_mux="[MEM_a]")}else t.mem_wdata=void 0,t.mem_wdata_mux=void 0;else t.mem_VA=void 0,t.mem_PA=void 0,t.mem_addr_mux=void 0,t.mem_size=void 0,t.mem_wdata=void 0,t.mem_wdata_mux=void 0;if(r.mem_read)try{switch(r.mem_size){case 8:t.next_wb_mem_out=this.memory.read_biguint8(t.mem_PA);break;case 16:t.next_wb_mem_out=this.memory.read_biguint16(t.mem_PA);break;case 32:t.next_wb_mem_out=this.memory.read_biguint32(t.mem_PA);break;case 64:t.next_wb_mem_out=this.memory.read_biguint64(t.mem_PA)}}catch(n){throw n instanceof RangeError&&e&&this.update_display(),n=`[In MEM stage] ${t.mem_inst.assy}: memory address 0x${t.mem_PA.toString(16)} out of bounds`}else t.next_wb_mem_out=void 0;if(t.next_wb_ex_out=t.mem_ex_out,t.next_wb_inst=r,"???"===i.opcode)throw`cannot decode instruction at 0x${i.pa}`;i.read_n_valid?r.write_en&&r.rd_addr===i.read_reg_an?(t.ex_n=t.mem_ex_out&i.FnH,t.n_bypass="[MEM_EX_out]"):s.write_en&&s.rd_addr===i.read_reg_an?(t.ex_n=t.wb_ex_out&i.FnH,t.n_bypass="[WB_EX_out]"):s.wload_en&&s.rt_addr===i.read_reg_an?(t.ex_n=t.wb_mem_out_sxt&i.FnH,t.n_bypass="[WB_MEM_sxt]"):(t.ex_n=t.fex_n,t.n_bypass="[FEX_n]"):(t.ex_n=t.fex_n,t.n_bypass="[FEX_n]"),i.read_m_valid?r.write_en&&r.rd_addr===i.read_reg_am?(t.ex_m=t.mem_ex_out&i.FnH,t.m_bypass="[MEM_EX_out]"):s.write_en&&s.rd_addr===i.read_reg_am?(t.ex_m=t.wb_ex_out&i.FnH,t.m_bypass="[WB_EX_out]"):s.wload_en&&s.rt_addr===i.read_reg_am?(t.ex_m=t.wb_mem_out_sxt&i.FnH,t.m_bypass="[WB_MEM_sxt]"):(t.ex_m=t.fex_m,t.m_bypass="[FEX_m]"):(t.ex_m=t.fex_m,t.m_bypass="[FEX_m]"),i.read_a_valid?r.write_en&&r.rd_addr===i.read_reg_aa?(t.ex_a=t.mem_ex_out&i.FnH,t.a_bypass="[MEM_EX_out]"):s.write_en&&s.rd_addr===i.read_reg_aa?(t.ex_a=t.wb_ex_out&i.FnH,t.a_bypass="[WB_EX_out]"):s.wload_en&&s.rt_addr===i.read_reg_aa?(t.ex_a=t.wb_mem_out_sxt&i.FnH,t.a_bypass="[WB_MEM_sxt]"):(t.ex_a=t.fex_a,t.a_bypass="[FEX_a]"):(t.ex_a=t.fex_a,t.a_bypass="[FEX_a]");const o=i.FnH===this.mask64?64:32;if(void 0!==i.barrel_op)switch(t.barrel_in_lo=i.barrel_lo_mux?t.ex_m:t.ex_n,t.barrel_in_hi=i.barrel_hi_mux?t.barrel_in_lo:t.ex_n,t.barrel_mux=i.barrel_lo_mux?i.barrel_hi_mux?"[ex_m:ex_m]":"[ex_n:ex_m]":(i.barrel_hi_mux,"[ex_n:ex_n]"),i.barrel_op){case 0:t.barrel_cmd=`[LSL #${i.shamt||0}]`,t.barrel_out=t.barrel_in_lo<<i.shamt&i.FnH;break;case 1:t.barrel_cmd=`[LSR #${i.shamt||0}]`,t.barrel_out=t.barrel_in_lo>>i.shamt&i.FnH;break;case 2:t.barrel_cmd=`[ASR #${i.shamt||0}]`,t.barrel_out=BigInt.asIntN(o,t.barrel_in_lo)>>i.shamt&i.FnH;break;case 3:t.barrel_cmd=`[ROR #${i.shamt||0}]`;let e=t.barrel_in_hi<<BigInt(o);e|=t.barrel_in_lo,e>>=i.shamt,e&=i.FnH,t.barrel_out=e}else t.barrel_cmd="",t.barrel_in_lo=void 0,t.barrel_in_hi=void 0,t.barrel_out=void 0,t.barrel_mux="";let a,l,c=t.barrel_out;void 0!==c&&(i.wtmask&&(c&=i.maskn&i.FnH),c=i.bitext_sign_ext?BigInt.asIntN(i.imm_sz,c)&i.FnH:BigInt.asUintN(i.imm_sz,c)),2===i.alu_op_a_mux?(t.alu_op_a=t.ex_n,t.alu_a_sel="[EX_n]"):1===i.alu_op_a_mux?(t.alu_op_a=t.ex_a,t.alu_a_sel="[EX_a]"):0===i.alu_op_a_mux?(t.alu_op_a=0n,t.alu_a_sel="[zero]"):(t.alu_op_a=void 0,t.alu_a_sel=void 0),i.wtmask&&(t.alu_op_a&=~i.maskn&i.FnH),0===i.alu_op_b_mux?(t.alu_op_b=c,t.alu_b_sel="[mask/sxt]"):1===i.alu_op_b_mux?(t.alu_op_b=i.i,t.alu_b_sel="[wmask]"):(t.alu_op_b=void 0,t.alu_b_sel=void 0);const d=i.alu_invert_b?~t.alu_op_b&i.FnH:t.alu_op_b;if(void 0===i.alu_cmd)t.alu_out=void 0,t.alu_cmd=void 0;else{switch(i.alu_cmd){case 0:case 3:a=t.alu_op_a&d,t.alu_cmd=i.alu_invert_b?"[bic]":"[and]";break;case 1:a=t.alu_op_a|d,t.alu_cmd=i.alu_invert_b?"[orn]":"[orr]";break;case 2:a=t.alu_op_a^d,t.alu_cmd=i.alu_invert_b?"[eon]":"[eor]";break;case 4:l=0n,a=t.alu_op_a+d,t.alu_cmd="[add]";break;case 5:l=1n,a=t.alu_op_a+d+1n,t.alu_cmd="[sub]";break;case 6:l=2&t.nzcv?1n:0n,a=t.alu_op_a+d+l,t.alu_cmd=i.alu_invert_b?"[sbc]":"[adc]"}t.alu_out=a&i.FnH}if(0===i.pstate_mux||2===i.pstate_mux){if(t.alu_nzcv=0,BigInt.asIntN(o,t.alu_out)<0&&(t.alu_nzcv|=8),0n===t.alu_out&&(t.alu_nzcv|=4),i.alu_cmd>=4){t.alu_out!==a&&(t.alu_nzcv|=2);const e=BigInt.asIntN(o,t.alu_op_a)+BigInt.asIntN(o,d)+l;BigInt.asIntN(o,e)!==e&&(t.alu_nzcv|=1)}}else t.alu_nzcv=void 0;if(i.pstate_en?void 0===i.pstate_mux?(t.next_nzcv=void 0,t.nzcv_mux="[&mdash]"):0===i.pstate_mux?(t.next_nzcv=t.alu_nzcv,t.nzcv_mux="[aluf]"):1===i.pstate_mux?(t.next_nzcv=Number(t.ex_a>>28n&0xFn),t.nzcv_mux="[EX_a]"):2===i.pstate_mux&&(t.next_nzcv=t.pstate_match?t.alu_nzcv:i.j,t.nzcv_mux=`[cond ${t.pstate_match?"aluf":"EX_inst"}]`):(t.next_nzcv=t.nzcv,t.nzcv_mux="[NZCV]"),t.next_mem_n=t.ex_n,t.next_mem_a=t.ex_a,t.next_mem_inst=t.halt?this.nop_inst:t.ex_inst,t.next_mem_inst_mux=t.halt?"[nop]":"[EX_inst]",0===i.ex_out_mux)t.next_mem_ex_out=t.id_pc,t.ex_out_sel="[id_pc]";else if(1===i.ex_out_mux)t.next_mem_ex_out=t.alu_out,t.ex_out_sel="[alu]";else if(2===i.ex_out_mux)t.next_mem_ex_out=t.pstate_match?t.ex_n:t.alu_out,t.ex_out_sel="[cond]";else if(3===i.ex_out_mux){switch(i.j){case 23056:t.next_mem_ex_out=BigInt(t.nzcv)<<28n;break;case 1:const e=this.console_input();t.next_mem_ex_out=void 0===e?0n:BigInt(e.charCodeAt(0));break;case 2:t.next_mem_ex_out=BigInt(this.mouse_input());break;case 3:t.next_mem_ex_out=BigInt(this.ncycles)}t.ex_out_sel="[sysreg]"}else t.next_mem_ex_out=void 0,t.ex_out_sel=void 0;if(t.halt||t.stall)t.next_if_pc=t.if_pc,t.next_if_pc_mux="[IF_pc]⟲",t.next_id_pc=t.id_pc,t.next_id_pc_mux="[ID_pc]⟲",t.next_id_inst=t.id_inst,t.next_id_inst_mux="[ID_inst]⟲",t.next_fex_n=void 0,t.next_fex_m=void 0,t.next_fex_a=void 0,t.next_ex_inst=t.halt?t.ex_inst:this.nop_inst,t.next_ex_inst_mux=t.halt?"[EX_inst]⟲":"[nop]";else{if(i.next_PC_mux?(t.next_if_pc=0xFFFFFFFFFFFFFFFCn&t.ex_n,t.next_if_pc_mux="[EX_n]",t.pc_adder_mux0="",t.pc_adder_mux1=""):i.PC_add_op_mux&&t.branch_taken?(t.next_if_pc=t.ex_n+t.ex_m&0xFFFFFFFFFFFFFFFCn,t.next_if_pc_mux="[pc_adder]",t.pc_adder_mux0="[EX_n]",t.pc_adder_mux1="[EX_m]"):(t.next_if_pc=t.if_pc+4n,t.next_if_pc_mux="[pc_adder]",t.pc_adder_mux0="[PC]",t.pc_adder_mux1="[4]"),t.bubble)t.next_id_inst=this.nop_inst,t.next_id_inst_mux="[nop]",t.next_id_pc=void 0,t.next_id_pc_mux=void 0;else{const e=this.va_to_phys(t.if_pc);let n=this.inst_decode[e/4];void 0===n&&(n=this.disassemble(e,this.if_pc)),this.memory.fetch32_aligned(e),t.next_id_inst=n,t.next_id_inst_mux="[IF_inst]",t.next_id_pc=t.if_pc,t.next_id_pc_mux="[IF_pc]"}t.bubble?(t.next_fex_n=void 0,t.next_fex_m=void 0,t.next_fex_a=void 0,t.next_ex_inst=this.nop_inst,t.next_ex_inst_mux="[nop]"):(n.read_n_valid?(t.an=n.read_reg_an,t.id_n=t.an===s.rd_addr&&s.write_en?t.wb_ex_out:t.an===s.rt_addr&&s.wload_en?t.wb_mem_out_sxt:t.register_file[t.an],t.id_n&=n.FnH):31===n.read_reg_an?(t.an="xzr",t.id_n=0n):(t.an=void 0,t.id_n=void 0),n.read_m_valid?(t.am=n.read_reg_am,t.id_m=t.am===s.rd_addr&&s.write_en?t.wb_ex_out:t.am===s.rt_addr&&s.wload_en?t.wb_mem_out_sxt:t.register_file[t.am],t.id_m&=n.FnH):31===n.read_reg_am?(t.id_m=0n,t.am="xzr"):(t.am=void 0,t.id_m=void 0),n.read_a_valid?(t.aa=n.read_reg_aa,t.ra_name=`R[${t.aa}]`,t.id_a=t.aa===s.rd_addr&&s.write_en?t.wb_ex_out:t.aa===s.rt_addr&&s.wload_en?t.wb_mem_out_sxt:t.register_file[t.aa],t.id_a&=n.FnH):31===n.read_reg_aa?(t.id_a=0n,t.aa="xzr",t.ra_name="R[xzr]"):(t.aa=void 0,t.ra_name="Ra",t.id_a=void 0),2===n.fex_n_mux?(t.next_fex_n=t.id_n,t.fex_n_mux="[Rn]"):0===n.fex_n_mux?(t.next_fex_n=t.id_pc,t.fex_n_mux="[ID_pc]"):1===n.fex_n_mux?(t.next_fex_n=0xFFFFFFFFFFFFF000n&t.id_pc,t.fex_n_mux="[ID_pc_page]"):(t.next_fex_n=void 0,t.fex_n_mux="—"),1===n.fex_m_mux?(t.next_fex_m=t.id_m,t.fex_m_mux="[Rm]"):0===n.fex_m_mux?(t.next_fex_m=n.i,t.fex_m_mux="[Immediate]"):(t.next_fex_m=void 0,t.fex_m_mux="—"),t.next_fex_a=t.id_a,t.next_ex_inst=n,t.next_ex_inst_mux="[ID_inst]")}if(t.halt||"brk"===i.opcode)throw this.update_display(),t.halt&&tool.verify_memory(),"Halt Execution";const h=this.source_map[t.ex_inst.pa/4];if(h&&h.breakpoint)throw this.update_display(),"Halt Execution"}pipeline_clock(e){const t=this.dp;this.ncycles+=1,t.if_pc=t.next_if_pc,t.id_pc=t.next_id_pc,t.id_inst=t.next_id_inst,t.ex_inst.pstate_en&&(t.nzcv=t.next_nzcv,e&&(this.right.querySelector("#nzcv").innerHTML=t.nzcv.toString(2).padStart(4,"0"))),t.ex_inst.console_en&&this.console_output(String.fromCharCode(Number(0xFFFFn&t.ex_a))),t.fex_n=t.next_fex_n,t.fex_m=t.next_fex_m,t.fex_a=t.next_fex_a,t.ex_inst=t.next_ex_inst;const n=t.mem_inst;if(n.mem_write){try{switch(n.mem_size){case 8:this.memory.write_bigint8(t.mem_PA,t.mem_wdata);break;case 16:this.memory.write_bigint16(t.mem_PA,t.mem_wdata);break;case 32:this.memory.write_bigint32(t.mem_PA,t.mem_wdata);break;case 64:this.memory.write_bigint64(t.mem_PA,t.mem_wdata)}}catch(n){throw n instanceof RangeError&&(e&&this.update_display(),n=`[In MEM stage] ${t.mem_inst.assy}: memory address 0x${t.mem_PA.toString(16)} out of bounds`),n}if(e){const e=-8&t.mem_PA,i=this.right.querySelector("#m"+e);i.innerHTML=this.location(e,64),this.is_visible(i,this.right.querySelector("#memory"))||i.scrollIntoView({block:"center"});const r=t.mem_PA+n.mem_size/8-1&-8;r!==e&&(this.right.querySelector("#m"+r).innerHTML=this.location(r,64))}}t.mem_n=t.next_mem_n,t.mem_ex_out=t.next_mem_ex_out,t.mem_a=t.next_mem_a,t.mem_inst=t.next_mem_inst;const i=t.wb_inst;if(i.wload_en&&(t.register_file[i.rt_addr]=t.wb_mem_out_sxt,e)){const e=this.right.querySelector("#r"+i.rt_addr);e&&(e.innerHTML=this.hexify(t.wb_mem_out_sxt,16),e.classList.remove("cpu_tool-unused"))}if(i.write_en&&(t.register_file[i.rd_addr]=t.wb_ex_out,e)){const e=this.right.querySelector("#r"+i.rd_addr);e&&(e.innerHTML=this.hexify(t.wb_ex_out,16),e.classList.remove("cpu_tool-unused"))}t.wb_ex_out=t.next_wb_ex_out,t.wb_mem_out=t.next_wb_mem_out,t.wb_inst=t.next_wb_inst}next_pc(e){if(this.source_highlight&&(this.source_highlight.doc.removeLineClass(this.source_highlight.line,"background","cpu_tool-next-inst"),this.source_highlight=void 0),this.source_map){let t=this.dp.ex_inst.pa;if(void 0===t&&(t=e),void 0!==t){const e=this.source_map[t/4];if(e){const t=this.select_buffer(e.start[0]);if(t){const n=t.CodeMirror.doc;n.addLineClass(e.start[1]-1,"background","cpu_tool-next-inst"),this.source_highlight={doc:n,line:e.start[1]-1},t.CodeMirror.scrollIntoView({line:e.start[1]-1,ch:e.start[2]})}}}}}update_display(){void 0===this.diagram&&(this.diagram=this.right.querySelector("#pipeline-diagram"),this.make_diagram()),this.remove_class("highlight",this.diagram);const e=this.dp;for(let t of this.diagram.getElementsByClassName("value")){let n=e[t.getAttribute("id")];switch(t.getAttribute("dtype")){case"hex":t.innerHTML=void 0===n?"—":"0x"+n.toString(16);break;case"decimal":t.innerHTML=void 0===n?"—":n.toString();break;case"binary4":t.innerHTML=void 0===n?"—":"0b"+n.toString(2).padStart(4,"0");break;case"hex64":t.innerHTML=void 0===n?"—":"0x"+this.hexify(n,16);break;case"hex32":t.innerHTML=void 0===n?"—":"0x"+this.hexify(n,8);break;case"inst":t.innerHTML=void 0===n?"—":n.assy,"↳"===n.assy.charAt(0)&&t.classList.add("highlight");break;case"ibinary":t.innerHTML=void 0===n?"—":`0x${this.hexify(n.inst,8)}`;break;case"ctl":t.innerHTML=n?1:0;break;default:n=void 0===n?"—":n.toString(),t.innerHTML=n,"⟲"===n.charAt(n.length-1)&&t.classList.add("highlight")}}const t=this.right.querySelector("#ID-msg");t.innerHTML="",e.bubble&&(t.innerHTML="bubble (taken branch)"),e.stall&&(t.innerHTML="stall (await memory read)");for(let e of this.diagram.getElementsByClassName("forwarding")){const t=e.textContent.slice(1,-1);if(["MEM_EX_out","WB_EX_out","WB_MEM_sxt"].includes(t)){e.classList.add("highlight");for(let e of this.diagram.getElementsByClassName(t))e.classList.add("highlight")}}if(this.caches)for(let e=0;e<this.caches.length;e+=1){const t=this.caches[e],n=this.right.querySelector("#cache-"+e);n&&(n.innerHTML=`Cache(${t.description()}): ${t.report_statistics()}`)}}make_diagram(){let e=20,t=0;t+=this.make_pre_IF_stage(e,t),t+=this.make_IF_stage(e,t),t+=this.make_ID_stage(e,t),t+=this.make_EX_stage(e,t),t+=this.make_MEM_stage(e,t),t+=this.make_WB_stage(e,t),this.diagram.setAttribute("viewBox",`0 0 430 ${t}`)}make_pre_IF_stage(e,t){const n=t+45-20;this.make_label([e+40,n-2],"label","middle","auto",{text:"EX_n | pc_adder | IF_pc"}),this.make_mux([e+10,n],60,8,"next_if_pc_mux"),this.make_wire([[e+40,n+8],[e+40,t+45]]),this.make_label([e+42,n+14],"value","start","middle",{id:"next_if_pc",dtype:"hex"});const i=e+100,r=t+45-22,s=this.make_alu([i,r],60,10,"outline logic");if(this.make_label(s,"small-label","middle","middle",{text:"+"}),this.make_wire([[i+30,r+10],[i+30,r+15]]),this.make_label([i+30,r+17],"label","middle","hanging",{text:"pc_adder"}),this.make_label([i+28,r-15],"label","end","auto",{text:"EX_n | IF_pc"}),this.make_mux([i,r-13],30,8,"pc_adder_mux0"),this.make_wire([[i+15,r-5],[i+15,r]]),this.make_label([i+32,r-15],"label","start","auto",{text:"EX_m | 4"}),this.make_mux([i+30,r-13],30,8,"pc_adder_mux1"),this.make_wire([[i+45,r-5],[i+45,r]]),this.caches)for(let n=0;n<this.caches.length;n+=1){this.caches[n];this.make_label([e+180,t+5+8*n],"label","start","middle",{id:`cache-${n}`})}return 45}make_IF_stage(e,t){const n=58,i=t+6+29;this.make_svg("path",{class:"stage-divider",d:`M ${e-20} ${t+6} l 430 0`}),this.make_label([e-20,i],"stage-label","start","middle",{text:"IF"}),this.make_reg([e,t],80,12,"IF_pc","if_pc","hex"),this.make_label([e+40,t+n-22],"label","middle","auto",{text:"IF_pc | ID_pc"}),this.make_mux([e+10,t+n-20],60,8,"next_id_pc_mux"),this.make_wire([[e+40,t+n-12],[e+40,t+n]]),this.make_label([e+42,t+n-6],"value","start","middle",{id:"next_id_pc",dtype:"hex"});const r=e+135;return this.make_wire([[r-5,i],[r,i]]),this.make_label([r-7,i-2],"label","end","auto",{text:"IF_pc"}),this.make_label([r-7,i+2],"value","end","hanging",{id:"if_pc",dtype:"hex"}),this.make_rect([r,i-10],80,20,"reg"),this.make_label([r+40,i-2],"label","middle","auto",{text:"Instruction"}),this.make_label([r+40,i+2],"label","middle","hanging",{text:"Memory"}),this.make_label([r+2,i],"small-label","start","middle",{text:"addr"}),this.make_label([r+78,i],"small-label","end","middle",{text:"rdata"}),this.make_wire([[r+80,i],[r+85,i]]),this.make_label([r+87,i-2],"label","start","auto",{text:"IF_inst"}),this.make_label([r+87,i+2],"value","start","hanging",{id:"next_id_inst",dtype:"ibinary"}),this.make_label([e+350,t+n-22],"label","middle","auto",{text:"IF_inst | nop | ID_inst"}),this.make_mux([e+350-30,t+n-20],60,8,"next_id_inst_mux"),this.make_wire([[e+350,t+n-12],[e+350,t+n]]),this.make_label([e+350,t+n-6],"value","middle","middle",{id:"next_id_inst",dtype:"inst"}),n}make_ID_stage(e,t){const n=82;this.make_svg("path",{class:"stage-divider",d:`M ${e-20} ${t+6} l 430 0`}),this.make_label([e-20,t+6+41],"stage-label","start","middle",{text:"ID"}),this.make_reg([e,t],80,12,"ID_pc","id_pc","hex"),this.make_reg([e+300,t],100,12,"ID_inst","id_inst","inst"),this.make_rect([e+300,t+24],100,10,"outline logic","instruction decode"),this.make_label([e+350,t+42],"","middle","middle",{id:"ID-msg",fill:"red","font-family":"sanserif","font-size":"8px"});const i=e+110,r=t+15;return this.make_rect([i,r],80,32,"reg"),this.make_label([i+40,r+14],"label","middle","auto",{text:"Register File"}),this.make_label([i+40,r+18],"label","middle","hanging",{text:"(read ports)"}),this.make_label([i+2,r+8],"small-label","start","middle",{text:"n"}),this.make_wire([[i-5,r+8],[i,r+8]]),this.make_label([i-7,r+8],"value","end","middle",{id:"an",dtype:"decimal"}),this.make_label([i+2,r+16],"small-label","start","middle",{text:"m"}),this.make_wire([[i-5,r+16],[i,r+16]]),this.make_label([i-7,r+16],"value","end","middle",{id:"am",dtype:"decimal"}),this.make_label([i+2,r+24],"small-label","start","middle",{text:"a"}),this.make_wire([[i-5,r+24],[i,r+24]]),this.make_label([i-7,r+24],"value","end","middle",{id:"aa",dtype:"decimal"}),this.make_label([i+78,r+8],"small-label","end","middle",{text:"Rn"}),this.make_wire([[i+80,r+8],[i+85,r+8]]),this.make_label([i+87,r+8],"value","start","middle",{id:"id_n",dtype:"hex64"}),this.make_label([i+78,r+16],"small-label","end","middle",{text:"Rm"}),this.make_wire([[i+80,r+16],[i+85,r+16]]),this.make_label([i+87,r+16],"value","start","middle",{id:"id_m",dtype:"hex64"}),this.make_label([i+78,r+24],"small-label","end","middle",{text:"Ra"}),this.make_wire([[i+80,r+24],[i+85,r+24]]),this.make_label([i+87,r+24],"value","start","middle",{id:"id_a",dtype:"hex64"}),this.make_mux([e+10,t+n-20],80,8,"fex_n_mux"),this.make_label([e+50,t+n-22],"label","middle","auto",{text:"ID_pc | ID_pc_page | Rn"}),this.make_wire([[e+50,t+n-12],[e+50,t+n]]),this.make_label([e+50,t+n-6],"value","middle","middle",{id:"next_fex_n",dtype:"hex64"}),this.make_mux([e+110,t+n-20],80,8,"fex_m_mux"),this.make_label([e+150,t+n-22],"label","middle","auto",{text:"Immediate | Rm"}),this.make_wire([[e+150,t+n-12],[e+150,t+n]]),this.make_label([e+150,t+n-6],"value","middle","middle",{id:"next_fex_m",dtype:"hex64"}),this.make_wire([[e+250,t+n-12],[e+250,t+n]]),this.make_label([e+250,t+n-14],"label","middle","auto",{text:"Ra"}),this.make_label([e+250,t+n-6],"value","middle","middle",{id:"next_fex_a",dtype:"hex64"}),this.make_label([e+350,t+n-22],"label","middle","auto",{text:"ID_inst | nop | EX_inst"}),this.make_mux([e+350-30,t+n-20],60,8,"next_ex_inst_mux"),this.make_wire([[e+350,t+n-12],[e+350,t+n]]),this.make_label([e+350,t+n-6],"value","middle","middle",{id:"next_ex_inst",dtype:"inst"}),n}make_EX_stage(e,t){const n=170;this.make_svg("path",{class:"stage-divider",d:`M ${e-20} ${t+6} l 430 0`}),this.make_label([e-20,t+6+85],"stage-label","start","middle",{text:"EX"}),this.make_reg([e,t],100,12,"FEX_n","fex_n","hex64"),this.make_reg([e+100,t],100,12,"FEX_m","fex_m","hex64"),this.make_reg([e+200,t],100,12,"FEX_a","fex_a","hex64"),this.make_reg([e+300,t],100,12,"EX_inst","ex_inst","inst"),this.make_label([e+18,t+28],"small-label italic","end","middle",{text:"forwarding:"}),this.make_mux([e+20,t+24],60,8,"n_bypass","value mux-value forwarding"),this.make_wire([[e+50,t+33],[e+50,t+45]]),this.make_label([e+50,t+47],"label","middle","hanging",{text:"EX_n"}),this.make_label([e+50,t+39],"value","middle","middle",{id:"ex_n",dtype:"hex64"}),this.make_mux([e+120,t+24],60,8,"m_bypass","value mux-value forwarding"),this.make_wire([[e+150,t+33],[e+150,t+45]]),this.make_label([e+150,t+47],"label","middle","hanging",{text:"EX_m"}),this.make_label([e+150,t+39],"value","middle","middle",{id:"ex_m",dtype:"hex64"}),this.make_mux([e+220,t+24],60,8,"a_bypass","value mux-value forwarding"),this.make_wire([[e+250,t+33],[e+250,t+45]]),this.make_label([e+250,t+47],"label","middle","hanging",{text:"EX_a"}),this.make_label([e+250,t+39],"value","middle","middle",{id:"ex_a",dtype:"hex64"});const i=e+280,r=t+125,s=this.make_alu([i-25,r],50,15,"outline logic");this.make_label(s,"value mux-value","middle","middle",{id:"alu_cmd"}),this.make_wire([[i,r+15],[i,r+27]]),this.make_label([i,r+21],"value","middle","middle",{id:"alu_out",dtype:"hex64"}),this.make_label([i,r+29],"label","middle","hanging",{text:"alu"}),this.make_wire([[i+25-7.5,r+7.5],[i+25,r+7.5]]),this.make_label([i+27,r+7.5],"label","start","middle",{text:"aluf"}),this.make_label([i+42,r+7.5],"value","start","middle",{id:"alu_nzcv",dtype:"binary4"}),this.make_mux([i-50-30,r-40],60,8,"alu_a_sel"),this.make_label([i-50,r-42],"label","middle","auto",{text:"zero | EX_a | Ex_n"}),this.make_wire([[i-50,r-32],[i-50,r-27]]),this.make_rect([i-50-30,r-27],60,10,"outline logic","bit clear logic"),this.make_wire([[i-50,r-17],[i-50,r-5],[i-12.5,r-5],[i-12.5,r]]),this.make_label([i-50,r-11],"value","middle","middle",{id:"alu_op_a",dtype:"hex64"}),this.make_label([i+50-15,r-32],"label","end","auto",{text:"wmask"}),this.make_wire([[i+50-20,r-30],[i+50-20,r-25]]),this.make_label([i+70-20,r-93],"label","middle","auto",{text:"EX_n"}),this.make_wire([[i+70-20,r-91],[i+70-20,r-84]]),this.make_label([i+70+20,r-93],"label","middle","auto",{text:"EX_m"}),this.make_wire([[i+70+20,r-91],[i+70+20,r-84]]),this.make_rect([i+70-30,r-84],60,32,"outline logic","Barrel shifter"),this.make_label([i+70,r-58],"value","middle","middle",{id:"barrel_cmd"}),this.make_label([i+70,r-77],"value","middle","middle",{id:"barrel_mux"}),this.make_wire([[i+70,r-52],[i+70,r-40]]),this.make_label([i+70,r-46],"value","middle","middle",{id:"barrel_out",dtype:"hex64"}),this.make_rect([i+70-30,r-40],60,10,"outline logic","mask/sign extend"),this.make_wire([[i+50+20,r-30],[i+50+20,r-25]]),this.make_mux([i+50-30,r-25],60,8,"alu_b_sel"),this.make_wire([[i+50,r-17],[i+50,r-5],[i+12.5,r-5],[i+12.5,r]]),this.make_label([i+50,r-11],"value","middle","middle",{id:"alu_op_b",dtype:"hex64"});const o=e+110,a=t+65;return this.make_label([o,a],"label","middle","auto",{text:"NZCV | aluf | EX_a | EX_inst"}),this.make_mux([o-30,a+2],60,8,"nzcv_mux"),this.make_wire([[o,a+10],[o,a+22]]),this.make_label([o+2,a+16],"value","start","middle",{id:"next_nzcv",dtype:"binary4"}),this.make_reg([o-30,a+22],60,12,"NZCV","nzcv","binary4"),this.make_rect([o-30,a+46],60,10,"outline logic","CC check"),this.make_label([o+32,a+51],"value","start","middle",{id:"cc_check",dtype:""}),this.make_wire([[o,a+56],[o,a+61]]),this.make_label([o,a+62],"value","middle","hanging",{id:"pstate_match",dtype:"ctl"}),this.make_wire([[o-70,a+41],[o-70,a+46]]),this.make_label([o-70,a+39],"label","middle","auto",{text:"alu"}),this.make_label([o-70,a+47],"small-label","middle","hanging",{text:"0"}),this.make_wire([[o-50,a+41],[o-50,a+46]]),this.make_label([o-50,a+39],"label","middle","auto",{text:"EX_n"}),this.make_label([o-50,a+47],"small-label","middle","hanging",{text:"1"}),this.make_mux([o-80,a+46],40,10),this.make_wire([[o-30,a+51],[o-45,a+51]]),this.make_wire([[o-60,a+56],[o-60,a+61]]),this.make_label([o-60,a+62],"label","middle","hanging",{text:"cond"}),this.make_mux([e+10,t+n-20],80,8,"ex_out_sel"),this.make_label([e+50,t+n-22],"label","middle","auto",{text:"ID_pc | alu | cond | sysreg"}),this.make_wire([[e+50,t+n-12],[e+50,t+n]]),this.make_label([e+50,t+n-6],"value","middle","middle",{id:"next_mem_ex_out",dtype:"hex64"}),this.make_label([e+150,t+n-6],"label","middle","auto",{text:"EX_n"}),this.make_wire([[e+150,t+n-5],[e+150,t+n]]),this.make_label([e+250,t+n-6],"label","middle","auto",{text:"EX_a"}),this.make_wire([[e+250,t+n-5],[e+250,t+n]]),this.make_label([e+350,t+n-22],"label","middle","auto",{text:"EX_inst | nop"}),this.make_mux([e+350-30,t+n-20],60,8,"next_mem_inst_mux"),this.make_wire([[e+350,t+n-12],[e+350,t+n]]),this.make_label([e+350,t+n-6],"value","middle","middle",{id:"next_mem_inst",dtype:"inst"}),n}make_MEM_stage(e,t){const n=85;this.make_svg("path",{class:"stage-divider",d:`M ${e-20} ${t+6} l 430 0`}),this.make_label([e-20,t+6+42.5],"stage-label","start","middle",{text:"MEM"});const i=e+135,r=t+40;return this.make_reg([e,t],100,12,"MEM_EX_out","mem_ex_out","hex64"),this.make_reg([e+100,t],100,12,"MEM_n","mem_n","hex64"),this.make_reg([e+200,t],100,12,"MEM_a","mem_a","hex64"),this.make_reg([e+300,t],100,12,"MEM_inst","mem_inst","inst"),this.make_wire([[e+50,t+24],[e+50,t+n]]),this.make_wire([[e+50,t+n-10],[e+60,t+n-10]]),this.make_label([e+62,t+n-10],"label italic MEM_EX_out","start","middle",{text:"to EX stage"}),this.make_wire([[e+350,t+24],[e+350,t+n]]),this.make_wire([[e+50,t+24],[e+80,t+24],[e+80,t+29]]),this.make_wire([[e+150,t+24],[e+120,t+24],[e+120,t+29]]),this.make_mux([e+70,t+29],60,8,"mem_addr_mux"),this.make_wire([[e+100,t+37],[e+100,r+8],[i,r+8]]),this.make_label([e+102,t+43],"value","start","middle",{id:"mem_PA",dtype:"hex"}),this.make_wire([[e+250,t+24],[e+250,t+29]]),this.make_mux([e+220,t+29],60,8,"mem_wdata_mux","value mux-value forwarding"),this.make_label([e+218,t+33],"small-label italic","end","middle",{text:"forwarding:"}),this.make_wire([[e+250,t+37],[e+250,r+16],[i+80,r+16]]),this.make_label([e+252,t+43],"value","start","middle",{id:"mem_wdata",dtype:"hex"}),this.make_rect([i,r],80,40,"reg"),this.make_label([i+40,r+18],"label","middle","auto",{text:"Data"}),this.make_label([i+40,r+22],"label","middle","hanging",{text:"Memory"}),this.make_label([i+2,r+8],"small-label","start","middle",{text:"addr"}),this.make_label([i+2,r+16],"small-label","start","middle",{text:"size"}),this.make_wire([[i-10,r+16],[i,r+16]]),this.make_label([i-12,r+16],"value","end","middle",{id:"mem_size",dtype:"decimal"}),this.make_label([i+2,r+24],"small-label","start","middle",{text:"read"}),this.make_wire([[i-10,r+24],[i,r+24]]),this.make_label([i-12,r+24],"value","end","middle",{id:"mem_read",dtype:"ctl"}),this.make_label([i+2,r+32],"small-label","start","middle",{text:"write"}),this.make_wire([[i-10,r+32],[i,r+32]]),this.make_label([i-12,r+32],"value","end","middle",{id:"mem_write",dtype:"ctl"}),this.make_label([i+78,r+16],"small-label","end","middle",{text:"wdata"}),this.make_label([i+78,r+24],"small-label","end","middle",{text:"rdata"}),this.make_wire([[i+80,r+24],[e+250,r+24],[e+250,t+n]]),this.make_label([e+252,t+n-6],"value","start","middle",{id:"next_wb_mem_out",dtype:"hex"}),n}make_WB_stage(e,t){this.make_svg("path",{class:"stage-divider",d:`M ${e-20} ${t+6} l 430 0`}),this.make_label([e-20,t+12+32.5],"stage-label","start","middle",{text:"WB"}),this.make_reg([e,t],100,12,"WB_EX_out","wb_ex_out","hex64"),this.make_reg([e+200,t],100,12,"WB_MEM_out","wb_mem_out","hex64"),this.make_reg([e+300,t],100,12,"WB_inst","wb_inst","inst");const n=e+110,i=t+32;this.make_rect([n,i],80,32,"reg"),this.make_label([n+40,i+14],"label","middle","auto",{text:"Register File"}),this.make_label([n+40,i+18],"label","middle","hanging",{text:"(write ports)"}),this.make_label([n+2,i+8],"small-label","start","middle",{text:"wdata"}),this.make_wire([[e+50,t+24],[e+50,i+8],[n,i+8]]),this.make_wire([[e+50,i+8],[e+50,i+18]]),this.make_label([e+50,i+20],"label italic WB_EX_out","middle","hanging",{text:"to EX stage"}),this.make_label([n+2,i+16],"small-label","start","middle",{text:"rd"}),this.make_wire([[n-10,i+16],[n,i+16]]);const r=this.make_label([n-12,i+16],"value","end","middle");r.setAttribute("id","rd_addr"),r.setAttribute("dtype","decimal"),this.make_label([n+2,i+24],"small-label","start","middle",{text:"write"}),this.make_wire([[n-10,i+24],[n,i+24]]);const s=this.make_label([n-12,i+24],"value","end","middle");s.setAttribute("id","rd_write"),s.setAttribute("dtype","ctl"),this.make_rect([e+210,t+24],80,10,"outline logic","sign extension"),this.make_wire([[e+250,t+34],[e+250,i+8],[n+80,i+8]]),this.make_label([n+78,i+8],"small-label","end","middle",{text:"wdata"});const o=this.make_label([e+252,t+45],"value","start","middle");o.setAttribute("id","wb_mem_out_sxt"),o.setAttribute("dtype","hex"),this.make_wire([[e+250,i+8],[e+250,i+20]]),this.make_label([e+250,i+22],"label italic WB_MEM_sxt","middle","hanging",{text:"to EX & WB stages"}),this.make_label([n+78,i+16],"small-label","end","middle",{text:"rt"}),this.make_wire([[n+90,i+16],[n+80,i+16]]);const a=this.make_label([n+92,i+16],"value","start","middle");a.setAttribute("id","rt_addr"),a.setAttribute("dtype","decimal"),this.make_label([n+78,i+24],"small-label","end","middle",{text:"write"}),this.make_wire([[n+90,i+24],[n+80,i+24]]);const l=this.make_label([n+92,i+24],"value","start","middle");return l.setAttribute("id","rt_write"),l.setAttribute("dtype","ctl"),65}make_svg(e,t){var n=document.createElementNS("http://www.w3.org/2000/svg",e);if(t)for(var i in t)n.setAttribute(i,t[i]);return this.diagram.append(n),n}make_label(e,t,n,i,r){const s=this.make_svg("text",{class:t,x:e[0],y:e[1],"dominant-baseline":i,"text-anchor":n});for(let e in r)void 0!==r[e]&&("text"==e?s.innerHTML=r[e]:s.setAttribute(e,r[e]));return s}make_mux(e,t,n,i,r){const s=this.make_svg("path",{class:"outline",d:`M ${e[0]} ${e[1]} l ${t} 0 l ${-n} ${n} l ${2*n-t} 0 z`});return i&&this.make_label([e[0]+t/2,e[1]+n/2],r||"value mux-value","middle","middle",{id:i}),s}make_rect(e,t,n,i,r){this.make_svg("path",{class:i||"reg",d:`M ${e[0]} ${e[1]} l ${t} 0 l 0 ${n} l ${-t} 0 z`});r&&this.make_label([e[0]+t/2,e[1]+n/2+1],"reg-name","middle","middle",{text:r})}make_alu(e,t,n,i,r){this.make_svg("path",{class:i||"reg",d:`M ${e[0]} ${e[1]} l ${t/2-3} 0 l 3 3 l 3 -3 l ${t/2-3} 0 l ${-n} ${n} l ${2*n-t} 0 z`});return[e[0]+t/2,e[1]+n/2+1.5]}make_reg(e,t,n,i,r,s){this.make_rect(e,t,n,"reg",i),this.make_wire([[e[0]+t/2,e[1]+n],[e[0]+t/2,e[1]+n+12]]),["hex","binary4"].includes(s)?this.make_label([e[0]+t/2+2,e[1]+n+6],"value","start","middle",{id:r,dtype:s}):this.make_label([e[0]+t/2,e[1]+n+6],"value","middle","middle",{id:r,dtype:s})}make_wire(e,t){let n="M",i=[];for(let t of e)i.push(`${n} ${t[0]} ${t[1]}`),n="L";return this.make_svg("path",{class:t||"wire",d:i.join(" "),"marker-end":"url(#arrow)"})}make_link(e,t,n,i,r){const s=this.make_svg("a",{href:r.url});r.target&&s.setAttribute("target",r.target),s.appendChild(this.make_label(e,t,n,i,r))}},CodeMirror.defineMode("ARMV8A",(function(){function e(e,t){let n,i=!1;for(;n=e.next();){if("/"===n&&i){t.tokenize=null;break}i="*"===n}return"comment"}let t=[".align",".ascii",".asciz",".balign",".bss",".byte",".cache",".data",".endm",".global",".hword",".include",".long",".macro",".p2align",".quad",".section",".text",".word"],n=["x0","x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12","x13","x14","x15","x16","x17","x18","x19","x20","x21","x22","x23","x24","x25","x26","x27","x28","x29","x30","xzr","sp","fp","lr","w0","w1","w2","w3","w4","w5","w6","w7","w8","w9","w10","w11","w12","w13","w14","w15","w16","w17","w18","w19","w20","w21","w22","w23","w24","w25","w26","w27","w28","w29","w30","wzr","wsp"];return{mode_name:"ARMV8A",lineComment:"//",blockCommentStart:"/*",blockCommentEnd:"*/",startState:function(){return{tokenize:null}},token:function(i,r){if(r.tokenize)return r.tokenize(i,r);if(i.eatSpace())return null;let s=i.next();if("/"===s){if(i.eat("*"))return r.tokenize=e,e(i,r);if(i.eat("/"))return i.skipToEnd(),"comment"}if('"'===s)return function(e,t){let n,i=!1;for(;null!==(n=e.next());){if(n===t&&!i)return!1;i=!i&&"\\"===n}}(i,'"'),"string";if("."===s){i.eatWhile(/\w/);const e=i.current().toLowerCase();return void 0!==t.find((t=>t===e))?"builtin":null}if("="===s)return i.eatWhile(/\w/),"tag";if("{"===s)return"bracket";if("}"===s)return"bracket";if(/\d/.test(s))return"0"===s&&i.eat(/[xXoObB]/)?(i.eatWhile(/[0-9a-fA-F]/),"number"):i.eat(/[bBfF]/)?"tag":(i.eatWhile(/\d/),i.eat(":")?"tag":"number");if(/\w/.test(s)){if(i.eatWhile(/\w/),i.eat(":"))return"tag";const e=i.current().toLowerCase();return void 0!==n.find((t=>t==e))?"keyword":null}}}})),window.addEventListener("load",(function(){for(let e of document.getElementsByClassName("asim"))new SimTool.ASim(e,!1);for(let e of document.getElementsByClassName("educore"))new SimTool.ASim(e,!0);for(let e of document.getElementsByClassName("educore-pipelined"))new SimTool.ASimPipelined(e)}));