diff --git a/README.md b/README.md index 9548edd..acdb1ff 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Syntax highlighting requires importing a `mode` module for the language Then specify the language with the `mode` attribute ```html - + ``` ### Theming @@ -85,5 +85,5 @@ Theming requires importing an editor theme stylesheet Then specify the theme with the `theme` attribute ```html - + ``` diff --git a/dev/index.html b/dev/index.html index acddf42..15549fa 100644 --- a/dev/index.html +++ b/dev/index.html @@ -12,19 +12,22 @@ - + - + - + + + + diff --git a/index.js b/index.js index a825280..b810ba1 100644 --- a/index.js +++ b/index.js @@ -9712,7 +9712,7 @@ self.CodeMirror = CodeMirror; class WCCodeMirror extends HTMLElement { static get observedAttributes () { - return ['src', 'value']; + return ['src']; } attributeChangedCallback (name, oldValue, newValue) { @@ -9726,12 +9726,11 @@ class WCCodeMirror extends HTMLElement { set src (value) { this.setAttribute('src', value); this.setSrc(); - this.__editor.refresh(); } get value () { return this.__editor.getValue(); } set value (value) { - this.__editor.swapDoc(CodeMirror.Doc(value), this.getAttribute('mode')); + this.setValue(value); } constructor () { @@ -9747,17 +9746,9 @@ class WCCodeMirror extends HTMLElement { async connectedCallback () { this.__element = this.querySelector('#code'); this.__element.style = this.hasAttribute('style') ? this.style.cssText : 'width:100%;height:100%'; - this.appendChild(this.__element); - if (this.hasAttribute('src')) { - const src = this.getAttribute('src'); - this.__element.value = await this.fetchSrc(src); - } else { - this.__element.value = ''; - } - - const mode = this.getAttribute('mode') || 'null'; - const theme = this.getAttribute('theme') || 'default'; + const mode = this.hasAttribute('mode') ? this.getAttribute('mode') : 'null'; + const theme = this.hasAttribute('theme') ? this.getAttribute('theme') : 'default'; this.__editor = CodeMirror.fromTextArea(this.__element, { lineNumbers: true, @@ -9766,6 +9757,14 @@ class WCCodeMirror extends HTMLElement { theme }); + if (this.hasAttribute('src')) { + this.setSrc(this.getAttribute('src')); + } else { + // delay until editor initializes + await new Promise(resolve => setTimeout(resolve, 50)); + this.setValue(''); + } + this.__initialized = true; } @@ -9773,6 +9772,12 @@ class WCCodeMirror extends HTMLElement { const src = this.getAttribute('src'); const contents = await this.fetchSrc(src); this.__editor.swapDoc(CodeMirror.Doc(contents, this.getAttribute('mode'))); + this.__editor.refresh(); + } + + async setValue (value) { + this.__editor.swapDoc(CodeMirror.Doc(value, this.getAttribute('mode'))); + this.__editor.refresh(); } async fetchSrc (src) { diff --git a/index.min.js b/index.min.js index 0040006..083732a 100644 --- a/index.min.js +++ b/index.min.js @@ -1 +1 @@ -let 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),l=/Edge\/(\d+)/.exec(e),o=i||r||l,s=o&&(i?document.documentMode||6:+(l||r)[1]),a=!l&&/WebKit\//.test(e),c=a&&/Qt\/\d+\.\d+/.test(e),u=!l&&/Chrome\//.test(e),h=/Opera\//.test(e),d=/Apple Computer/.test(navigator.vendor),f=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(e),p=/PhantomJS/.test(e),g=!l&&/AppleWebKit/.test(e)&&/Mobile\/\w+/.test(e),m=/Android/.test(e),y=g||m||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(e),b=g||/Mac/.test(t),w=/\bCrOS\b/.test(e),v=/win/i.test(t),x=h&&e.match(/Version\/(\d*\.\d*)/);x&&(x=Number(x[1])),x&&x>=15&&(h=!1,a=!0);let C=b&&(c||h&&(null==x||x<12.11)),S=n||o&&s>=9;function k(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}let M,L=function(e,t){let n=e.className,i=k(t).exec(n);if(i){let t=n.slice(i.index+i[0].length);e.className=n.slice(0,i.index)+(t?i[1]+t:"")}};function T(e){for(let t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function N(e,t){return T(e).appendChild(t)}function A(e,t,n,i){let 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(let e=0;e=t)return o+(t-l);o+=i-l,o+=n-o%n,l=i+1}}g?F=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:o&&(F=function(e){try{e.select()}catch(e){}});class R{constructor(){this.id=null,this.f=null,this.time=0,this.handler=P(this.onTimeout,this)}onTimeout(e){e.id=0,e.time<=+new Date?e.f():setTimeout(e.handler,e.time-+new Date)}set(e,t){this.f=t;const n=+new Date+e;(!this.id||n=t)return i+Math.min(o,t-r);if(r+=l-i,r+=n-r%n,i=l+1,r>=t)return i}}let $=[""];function j(e){for(;$.length<=e;)$.push(X($)+" ");return $[e]}function X(e){return e[e.length-1]}function Y(e,t){let n=[];for(let i=0;i"€"&&(e.toUpperCase()!=e.toLowerCase()||Q.test(e))}function ee(e,t){return t?!!(t.source.indexOf("\\w")>-1&&J(e))||t.test(e):J(e)}function te(e){for(let t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}let 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:tn?-1:1;for(;;){if(t==n)return t;let r=(t+n)/2,l=i<0?Math.ceil(r):Math.floor(r);if(l==t)return e(l)?t:n;e(l)?n=l:t=l+i}}let oe=null;function se(e,t,n){let i;oe=null;for(let r=0;rt)return r;l.to==t&&(l.from!=l.to&&"before"==n?i=r:oe=r),l.from==t&&(l.from!=l.to&&"before"!=n?i=r:oe=r)}return null!=i?i:oe}let ae=function(){let e=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,t=/[stwN]/,n=/[LRr]/,i=/[Lb1n]/,r=/[1n]/;function l(e,t,n){this.level=e,this.from=t,this.to=n}return function(o,s){let a="ltr"==s?"L":"R";if(0==o.length||"ltr"==s&&!e.test(o))return!1;let c=o.length,u=[];for(let e=0;e-1&&(i[t]=r.slice(0,e).concat(r.slice(e+1)))}}}function pe(e,t){let n=de(e,t);if(!n.length)return;let i=Array.prototype.slice.call(arguments,2);for(let e=0;e0}function be(e){e.prototype.on=function(e,t){he(this,e,t)},e.prototype.off=function(e,t){fe(this,e,t)}}function we(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function ve(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function xe(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function Ce(e){we(e),ve(e)}function Se(e){return e.target||e.srcElement}function ke(e){let t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),b&&e.ctrlKey&&1==t&&(t=3),t}let Me,Le,Te=function(){if(o&&s<9)return!1;let e=A("div");return"draggable"in e||"dragDrop"in e}();function Ne(e){if(null==Me){let t=A("span","​");N(e,A("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(Me=t.offsetWidth<=1&&t.offsetHeight>2&&!(o&&s<8))}let t=Me?A("span","​"):A("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return t.setAttribute("cm-text",""),t}function Ae(e){if(null!=Le)return Le;let t=N(e,document.createTextNode("AخA")),n=M(t,0,1).getBoundingClientRect(),i=M(t,1,2).getBoundingClientRect();return T(e),!(!n||n.left==n.right)&&(Le=i.right-n.right<3)}let Oe=3!="\n\nb".split(/\n/).length?e=>{let t=0,n=[],i=e.length;for(;t<=i;){let i=e.indexOf("\n",t);-1==i&&(i=e.length);let r=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),l=r.indexOf("\r");-1!=l?(n.push(r.slice(0,l)),t+=l+1):(n.push(r),t=i+1)}return n}:e=>e.split(/\r\n?|\n/),De=window.getSelection?e=>{try{return e.selectionStart!=e.selectionEnd}catch(e){return!1}}:e=>{let t;try{t=e.ownerDocument.selection.createRange()}catch(e){}return!(!t||t.parentElement()!=e)&&0!=t.compareEndPoints("StartToEnd",t)},We=(()=>{let e=A("div");return"oncopy"in e||(e.setAttribute("oncopy","return;"),"function"==typeof e.oncopy)})(),He=null;let ze={},Fe={};function Pe(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),ze[e]=t}function Ee(e){if("string"==typeof e&&Fe.hasOwnProperty(e))e=Fe[e];else if(e&&"string"==typeof e.name&&Fe.hasOwnProperty(e.name)){let t=Fe[e.name];"string"==typeof t&&(t={name:t}),(e=Z(t,e)).name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return Ee("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return Ee("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function Ie(e,t){t=Ee(t);let n=ze[t.name];if(!n)return Ie(e,"text/plain");let i=n(e,t);if(Re.hasOwnProperty(t.name)){let e=Re[t.name];for(let t in e)e.hasOwnProperty(t)&&(i.hasOwnProperty(t)&&(i["_"+t]=i[t]),i[t]=e[t])}if(i.name=t.name,t.helperType&&(i.helperType=t.helperType),t.modeProps)for(let e in t.modeProps)i[e]=t.modeProps[e];return i}let Re={};function Be(e,t){E(t,Re.hasOwnProperty(e)?Re[e]:Re[e]={})}function Ge(e,t){if(!0===t)return t;if(e.copyState)return e.copyState(t);let n={};for(let e in t){let i=t[e];i instanceof Array&&(i=i.concat([])),n[e]=i}return n}function Ue(e,t){let n;for(;e.innerMode&&(n=e.innerMode(t),n&&n.mode!=e);)t=n.state,e=n.mode;return n||{mode:e,state:t}}function _e(e,t,n){return!e.startState||e.startState(t,n)}class Ve{constructor(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}eol(){return this.pos>=this.string.length}sol(){return this.pos==this.lineStart}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.post}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos0?null:(n&&!1!==t&&(this.pos+=n[0].length),n)}{let i=e=>n?e.toLowerCase():e;if(i(this.string.substr(this.pos,e.length))==i(e))return!1!==t&&(this.pos+=e.length),!0}}current(){return this.string.slice(this.start,this.pos)}hideFirstChars(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}}lookAhead(e){let t=this.lineOracle;return t&&t.lookAhead(e)}baseToken(){let e=this.lineOracle;return e&&e.baseToken(this.pos)}}function Ke(e,t){if((t-=e.first)<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");let n=e;for(;!n.lines;)for(let e=0;;++e){let i=n.children[e],r=i.chunkSize();if(t{let l=e.text;r==n.line&&(l=l.slice(0,n.ch)),r==t.line&&(l=l.slice(t.ch)),i.push(l),++r}),i}function je(e,t,n){let i=[];return e.iter(t,n,e=>{i.push(e.text)}),i}function Xe(e,t){let n=t-e.height;if(n)for(let t=e;t;t=t.parent)t.height+=n}function Ye(e){if(null==e.parent)return null;let t=e.parent,n=B(t.lines,e);for(let e=t.parent;e;t=e,e=e.parent)for(let i=0;e.children[i]!=t;++i)n+=e.children[i].chunkSize();return n+t.first}function qe(e,t){let n=e.first;e:do{for(let i=0;i=e.first&&tn?Je(n,Ke(e,n).text.length):function(e,t){let n=e.ch;return null==n||n>t?Je(e.line,t):n<0?Je(e.line,0):e}(t,Ke(e,t.line).text.length)}function st(e,t){let n=[];for(let i=0;ithis.maxLookAhead&&(this.maxLookAhead=e),t}baseToken(e){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=e;)this.baseTokenPos+=2;let t=this.baseTokens[this.baseTokenPos+1];return{type:t&&t.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}}nextLine(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--}static fromSaved(e,t,n){return t instanceof at?new ct(e,Ge(e.mode,t.state),n,t.lookAhead):new ct(e,Ge(e.mode,t),n)}save(e){let t=!1!==e?Ge(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new at(t,this.maxLookAhead):t}}function ut(e,t,n,i){let r=[e.state.modeGen],l={};wt(e,t.text,e.doc.mode,n,(e,t)=>r.push(e,t),l,i);let o=n.state;for(let i=0;i{let n=a;for(;ce&&r.splice(a,1,e,r[a+1],t),a+=2,c=Math.min(e,t)}if(t)if(s.opaque)r.splice(n,a-n,e,"overlay "+t),a=n+2;else for(;ne.options.maxHighlightLength&&Ge(e.doc.mode,i.state),l=ut(e,t,i);r&&(i.state=r),t.stateAfter=i.save(!r),t.styles=l.styles,l.classes?t.styleClasses=l.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 dt(e,t,n){let i=e.doc,r=e.display;if(!i.mode.startState)return new ct(i,!0,t);let l=function(e,t,n){let i,r,l=e.doc,o=n?-1:t-(e.doc.mode.innerMode?1e3:100);for(let s=t;s>o;--s){if(s<=l.first)return l.first;let t=Ke(l,s-1),o=t.stateAfter;if(o&&(!n||s+(o instanceof at?o.lookAhead:0)<=l.modeFrontier))return s;let a=I(t.text,null,e.options.tabSize);(null==r||i>a)&&(r=s-1,i=a)}return r}(e,t,n),o=l>i.first&&Ke(i,l-1).stateAfter,s=o?ct.fromSaved(i,o,l):new ct(i,_e(i.mode),l);return i.iter(l,t,n=>{ft(e,n.text,s);let i=s.line;n.stateAfter=i==t-1||i%5==0||i>=r.viewFrom&&it.start)return r}throw new Error("Mode "+e.name+" failed to advance stream.")}class mt{constructor(e,t,n){this.start=e.start,this.end=e.pos,this.string=e.current(),this.type=t||null,this.state=n}}function yt(e,t,n,i){let r,l,o=e.doc,s=o.mode,a=Ke(o,(t=ot(o,t)).line),c=dt(e,t.line,n),u=new Ve(a.text,e.options.tabSize,c);for(i&&(l=[]);(i||u.pose.options.maxHighlightLength?(s=!1,o&&ft(e,t,i,h.pos),h.pos=t.length,a=null):a=bt(gt(n,h,i.state,d),l),d){let e=d[0].name;e&&(a="m-"+(a?e+" "+a:e))}if(!s||u!=a){for(;c=t:l.to>t);(i||(i=[])).push(new Ct(o,l.from,e?null:l.to))}}return i}(n,r,o),a=function(e,t,n){let i;if(e)for(let r=0;r=t:l.to>t)||l.from==t&&"bookmark"==o.type&&(!n||l.marker.insertLeft)){let e=null==l.from||(o.inclusiveLeft?l.from<=t:l.from0&&s)for(let t=0;tt)&&(!n||Dt(n,r.marker)<0)&&(n=r.marker)}return n}function Pt(e,t,n,i,r){let l=Ke(e,t),o=xt&&l.markedSpans;if(o)for(let e=0;e=0&&a<=0||s<=0&&a>=0)&&(s<=0&&(t.marker.inclusiveRight&&r.inclusiveLeft?et(l.to,n)>=0:et(l.to,n)>0)||s>=0&&(t.marker.inclusiveRight&&r.inclusiveLeft?et(l.from,i)<=0:et(l.from,i)<0)))return!0}}function Et(e){let t;for(;t=Ht(e);)e=t.find(-1,!0).line;return e}function It(e,t){let n=Ke(e,t),i=Et(n);return n==i?t:Ye(i)}function Rt(e,t){if(t>e.lastLine())return t;let n,i=Ke(e,t);if(!Bt(e,i))return t;for(;n=zt(i);)i=n.find(1,!0).line;return Ye(i)+1}function Bt(e,t){let n=xt&&t.markedSpans;if(n)for(let i,r=0;r{let n=_t(e);n>t.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)})}class Kt{constructor(e,t,n){this.text=e,Nt(this,t),this.height=n?n(this):1}lineNo(){return Ye(this)}}function $t(e){e.parent=null,Tt(e)}be(Kt);let jt={},Xt={};function Yt(e,t){if(!e||/^\s*$/.test(e))return null;let n=t.addModeClass?Xt:jt;return n[e]||(n[e]=e.replace(/\S+/g,"cm-$&"))}function qt(e,t){let n=O("span",null,null,a?"padding-right: .1px":null),i={pre:O("pre",[n],"CodeMirror-line"),content:n,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:e.getOption("lineWrapping")};t.measure={};for(let n=0;n<=(t.rest?t.rest.length:0);n++){let r,l=n?t.rest[n-1]:t.line;i.pos=0,i.addToken=Qt,Ae(e.display.measure)&&(r=ce(l,e.doc.direction))&&(i.addToken=Jt(i.addToken,r)),i.map=[],tn(l,i,ht(e,l,t!=e.display.externalMeasured&&Ye(l))),l.styleClasses&&(l.styleClasses.bgClass&&(i.bgClass=z(l.styleClasses.bgClass,i.bgClass||"")),l.styleClasses.textClass&&(i.textClass=z(l.styleClasses.textClass,i.textClass||""))),0==i.map.length&&i.map.push(0,0,i.content.appendChild(Ne(e.display.measure))),0==n?(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(a){let e=i.content.lastChild;(/\bcm-tab\b/.test(e.className)||e.querySelector&&e.querySelector(".cm-tab"))&&(i.content.className="cm-tab-wrap-hack")}return pe(e,"renderLine",e,t.line,i.pre),i.pre.className&&(i.textClass=z(i.pre.className,i.textClass||"")),i}function Zt(e){let t=A("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function Qt(e,t,n,i,r,l,a){if(!t)return;let c,u=e.splitSpaces?function(e,t){if(e.length>1&&!/ /.test(e))return e;let n=t,i="";for(let t=0;t{r=r?r+" cm-force-border":"cm-force-border";let c=n.pos,u=c+i.length;for(;;){let h;for(let e=0;ec&&h.from<=c));e++);if(h.to>=u)return e(n,i,r,l,o,s,a);e(n,i.slice(0,h.to-c),r,l,null,s,a),l=null,i=i.slice(h.to-c),c=h.to}}}function en(e,t,n,i){let 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 tn(e,t,n){let i=e.markedSpans,r=e.text,l=0;if(!i){for(let e=1;ep||l.collapsed&&r.to==p&&r.from==p)){if(null!=r.to&&r.to!=p&&y>r.to&&(y=r.to,c=""),l.className&&(a+=" "+l.className),l.css&&(s=(s?s+";":"")+l.css),l.startStyle&&r.from==p&&(u+=" "+l.startStyle),l.endStyle&&r.to==y&&(e||(e=[])).push(l.endStyle,r.to),l.title&&((d||(d={})).title=l.title),l.attributes)for(let e in l.attributes)(d||(d={}))[e]=l.attributes[e];l.collapsed&&(!h||Dt(h.marker,l)<0)&&(h=r)}else r.from>p&&y>r.from&&(y=r.from)}if(e)for(let t=0;t=f)break;let e=Math.min(f,y);for(;;){if(m){let n=p+m.length;if(!h){let i=n>e?m.slice(0,e-p):m;t.addToken(t,i,o?o+a:a,u,p+i.length==y?c:"",s,d)}if(n>=e){m=m.slice(e-p),p=e;break}p=n,u=""}m=r.slice(l,l=n[g++]),o=Yt(n[g++],t.cm.options)}}}function nn(e,t,n){this.line=t,this.rest=function(e){let t,n;for(;t=zt(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=Bt(e,t)}function rn(e,t,n){let i,r=[];for(let l=t;ln[e].apply(null,r))}function an(){let e=on;on=null;for(let t=0;tn)return{map:e.measure.maps[t],cache:e.measure.caches[t],before:!0}}function An(e,t,n,i){return Wn(e,Dn(e,t),n,i)}function On(e,t){if(t>=e.display.viewFrom&&t=n.lineN&&t2&&e.push((r.bottom+l.top)/2-n.top)}}e.push(n.bottom-n.top)}}(e,t.view,t.rect),t.hasHeights=!0),l=function(e,t,n,i){let r,l=Fn(t.map,n,i),a=l.node,c=l.start,u=l.end,h=l.collapse;if(3==a.nodeType){for(let e=0;e<4;e++){for(;c&&ie(t.line.text.charAt(l.coverStart+c));)--c;for(;l.coverStart+u1}(e))return t;let 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{let t;c>0&&(h=i="right"),r=e.options.lineWrapping&&(t=a.getClientRects()).length>1?t["right"==i?t.length-1:0]:a.getBoundingClientRect()}if(o&&s<9&&!c&&(!r||!r.left&&!r.right)){let t=a.parentNode.getClientRects()[0];r=t?{left:t.left,right:t.left+ii(e.display),top:t.top,bottom:t.bottom}:zn}let d=r.top-t.rect.top,f=r.bottom-t.rect.top,p=(d+f)/2,g=t.view.measure.heights,m=0;for(;mt)&&(l=a-s,r=l-1,t>=a&&(o="right")),null!=r){if(i=e[c+2],s==a&&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==a-s)for(;c=0&&(n=e[t]).left==n.right;t--);return n}function En(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(let t=0;t=i.text.length?(a=i.text.length,c="before"):a<=0&&(a=0,c="after"),!s)return o("before"==c?a-1:a,"before"==c);function u(e,t,n){return o(n?e-1:e,1==s[t].level!=n)}let h=se(s,a,c),d=oe,f=u(a,h,"before"==c);return null!=d&&(f.other=u(a,d,"before"!=c)),f}function jn(e,t){let n=0;t=ot(e.doc,t),e.options.lineWrapping||(n=ii(e.display)*t.ch);let i=Ke(e.doc,t.line),r=Ut(i)+Cn(e.display);return{left:n,right:n,top:r,bottom:r+i.height}}function Xn(e,t,n,i,r){let l=Je(e,t,n);return l.xRel=r,i&&(l.outside=i),l}function Yn(e,t,n){let i=e.doc;if((n+=e.display.viewOffset)<0)return Xn(i.first,0,null,-1,-1);let r=qe(i,n),l=i.first+i.size-1;if(r>l)return Xn(i.first+i.size-1,Ke(i,l).text.length,null,1,1);t<0&&(t=0);let o=Ke(i,r);for(;;){let l=Jn(e,o,r,t,n),s=Ft(o,l.ch+(l.xRel>0||l.outside>0?1:0));if(!s)return l;let a=s.find(1);if(a.line==r)return a;o=Ke(i,r=a.line)}}function qn(e,t,n,i){i-=Un(t);let r=t.text.length,l=le(t=>Wn(e,n,t-1).bottom<=i,r,0);return r=le(t=>Wn(e,n,t).top>i,l,r),{begin:l,end:r}}function Zn(e,t,n,i){return n||(n=Dn(e,t)),qn(e,t,n,_n(e,t,Wn(e,n,i),"line").top)}function Qn(e,t,n,i){return!(e.bottom<=n)&&(e.top>n||(i?e.left:e.right)>t)}function Jn(e,t,n,i,r){r-=Ut(t);let l=Dn(e,t),o=Un(t),s=0,a=t.text.length,c=!0,u=ce(t,e.doc.direction);if(u){let o=(e.options.lineWrapping?ti:ei)(e,t,n,l,u,i,r);c=1!=o.level,s=c?o.from:o.to-1,a=c?o.to:o.from-1}let h,d,f=null,p=null,g=le(t=>{let n=Wn(e,l,t);return n.top+=o,n.bottom+=o,!!Qn(n,i,r,!1)&&(n.top<=r&&n.left<=i&&(f=t,p=n),!0)},s,a),m=!1;if(p){let e=i-p.left=i.bottom?1:0}return g=re(t.text,g,1),Xn(n,g,d,m,i-h)}function ei(e,t,n,i,r,l,o){let s=le(s=>{let a=r[s],c=1!=a.level;return Qn($n(e,Je(n,c?a.to:a.from,c?"before":"after"),"line",t,i),l,o,!0)},0,r.length-1),a=r[s];if(s>0){let c=1!=a.level,u=$n(e,Je(n,c?a.from:a.to,c?"after":"before"),"line",t,i);Qn(u,l,o,!0)&&u.top>o&&(a=r[s-1])}return a}function ti(e,t,n,i,r,l,o){let{begin:s,end:a}=qn(e,t,i,o);/\s/.test(t.text.charAt(a-1))&&a--;let c=null,u=null;for(let t=0;t=a||n.to<=s)continue;let o=Wn(e,i,1!=n.level?Math.min(a,n.to)-1:Math.max(s,n.from)).right,h=oh)&&(c=n,u=h)}return c||(c=r[r.length-1]),c.froma&&(c={from:c.from,to:a,level:c.level}),c}function ni(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Hn){Hn=A("pre",null,"CodeMirror-line-like");for(let e=0;e<49;++e)Hn.appendChild(document.createTextNode("x")),Hn.appendChild(A("br"));Hn.appendChild(document.createTextNode("x"))}N(e.measure,Hn);let t=Hn.offsetHeight/50;return t>3&&(e.cachedTextHeight=t),T(e.measure),t||1}function ii(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;let t=A("span","xxxxxxxxxx"),n=A("pre",[t],"CodeMirror-line-like");N(e.measure,n);let i=t.getBoundingClientRect(),r=(i.right-i.left)/10;return r>2&&(e.cachedCharWidth=r),r||10}function ri(e){let t=e.display,n={},i={},r=t.gutters.clientLeft;for(let l=t.gutters.firstChild,o=0;l;l=l.nextSibling,++o){let t=e.display.gutterSpecs[o].className;n[t]=l.offsetLeft+l.clientLeft+r,i[t]=l.clientWidth}return{fixedPos:li(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:i,wrapperWidth:t.wrapper.clientWidth}}function li(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function oi(e){let t=ni(e.display),n=e.options.lineWrapping,i=n&&Math.max(5,e.display.scroller.clientWidth/ii(e.display)-3);return r=>{if(Bt(e.doc,r))return 0;let l=0;if(r.widgets)for(let e=0;e{let t=n(e);t!=e.height&&Xe(e,t)})}function ai(e,t,n,i){let r=e.display;if(!n&&"true"==Se(t).getAttribute("cm-not-content"))return null;let l,o,s=r.lineSpace.getBoundingClientRect();try{l=t.clientX-s.left,o=t.clientY-s.top}catch(t){return null}let a,c=Yn(e,l,o);if(i&&c.xRel>0&&(a=Ke(e.doc,c.line).text).length==c.ch){let t=I(a,a.length,e.options.tabSize)-a.length;c=Je(c.line,Math.max(0,Math.round((l-kn(e.display).left)/ii(e.display))-t))}return c}function ci(e,t){if(t>=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;let n=e.display.view;for(let e=0;et)&&(r.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=r.viewTo)xt&&It(e.doc,t)r.viewFrom?di(e):(r.viewFrom+=i,r.viewTo+=i);else if(t<=r.viewFrom&&n>=r.viewTo)di(e);else if(t<=r.viewFrom){let t=fi(e,n,n+i,1);t?(r.view=r.view.slice(t.index),r.viewFrom=t.lineN,r.viewTo+=i):di(e)}else if(n>=r.viewTo){let n=fi(e,t,t,-1);n?(r.view=r.view.slice(0,n.index),r.viewTo=n.lineN):di(e)}else{let l=fi(e,t,t,-1),o=fi(e,n,n+i,1);l&&o?(r.view=r.view.slice(0,l.index).concat(rn(e,l.lineN,o.lineN)).concat(r.view.slice(o.index)),r.viewTo+=i):di(e)}let l=r.externalMeasured;l&&(n=r.lineN&&t=i.viewTo)return;let l=i.view[ci(e,t)];if(null==l.node)return;let o=l.changes||(l.changes=[]);-1==B(o,n)&&o.push(n)}function di(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function fi(e,t,n,i){let r,l=ci(e,t),o=e.display.view;if(!xt||n==e.doc.first+e.doc.size)return{index:l,lineN:n};let s=e.display.viewFrom;for(let e=0;e0){if(l==o.length-1)return null;r=s+o[l].size-t,l++}else r=s-t;t+=r,n+=r}for(;It(e.doc,n)!=n;){if(l==(i<0?0:o.length-1))return null;n+=i*o[l-(i<0?1:0)].size,l+=i}return{index:l,lineN:n}}function pi(e){let t=e.display.view,n=0;for(let e=0;e=e.display.viewTo||o.to().linet||t==n&&o.to==t)&&(i(Math.max(o.from,t),Math.min(o.to,n),1==o.level?"rtl":"ltr",l),r=!0)}r||i(t,n,"ltr")}(g,n||0,null==i?d:i,(e,t,r,h)=>{let m="ltr"==r,y=f(e,m?"left":"right"),b=f(t-1,m?"right":"left"),w=null==n&&0==e,v=null==i&&t==d,x=0==h,C=!g||h==g.length-1;if(b.top-y.top<=3){let e=(c?v:w)&&C,t=(c?w:v)&&x?s:(m?y:b).left,n=e?a:(m?b:y).right;u(t,y.top,n-t,y.bottom)}else{let n,i,l,o;m?(n=c&&w&&x?s:y.left,i=c?a:p(e,r,"before"),l=c?s:p(t,r,"after"),o=c&&v&&C?a:b.right):(n=c?p(e,r,"before"):s,i=!c&&w&&x?a:y.right,l=!c&&v&&C?s:b.left,o=c?p(t,r,"after"):a),u(n,y.top,i-n,y.bottom),y.bottom0?t.blinker=setInterval(()=>t.cursorDiv.style.visibility=(n=!n)?"":"hidden",e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}function xi(e){e.state.focused||(e.display.input.focus(),Si(e))}function Ci(e){e.state.delayingBlurEvent=!0,setTimeout(()=>{e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,ki(e))},100)}function Si(e,t){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(pe(e,"focus",e,t),e.state.focused=!0,H(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),a&&setTimeout(()=>e.display.input.reset(!0),20)),e.display.input.receivedFocus()),vi(e))}function ki(e,t){e.state.delayingBlurEvent||(e.state.focused&&(pe(e,"blur",e,t),e.state.focused=!1,L(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(()=>{e.state.focused||(e.display.shift=!1)},150))}function Mi(e){let t=e.display,n=t.lineDiv.offsetTop;for(let i=0;i.005||u<-.005)&&(Xe(l.line,r),Li(l.line),l.rest))for(let e=0;ee.display.sizerWidth){let t=Math.ceil(c/ii(e.display));t>e.display.maxLineLength&&(e.display.maxLineLength=t,e.display.maxLine=l.line,e.display.maxLineChanged=!0)}}}function Li(e){if(e.widgets)for(let t=0;t=o&&(l=qe(t,Ut(Ke(t,r))-e.wrapper.clientHeight),o=r)}return{from:l,to:Math.max(o,l+1)}}function Ni(e,t){let n=e.display,i=ni(e.display);t.top<0&&(t.top=0);let r=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:n.scroller.scrollTop,l=Tn(e),o={};t.bottom-t.top>l&&(t.bottom=t.top+l);let s=e.doc.height+Sn(n),a=t.tops-i;if(t.topr+l){let e=Math.min(t.top,(c?s:t.bottom)-l);e!=r&&(o.scrollTop=e)}let u=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:n.scroller.scrollLeft,h=Ln(e)-(e.options.fixedGutter?n.gutters.offsetWidth:0),d=t.right-t.left>h;return d&&(t.right=t.left+h),t.left<10?o.scrollLeft=0:t.lefth+u-3&&(o.scrollLeft=t.right+(d?0:10)-h),o}function Ai(e,t){null!=t&&(Wi(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+t)}function Oi(e){Wi(e);let t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function Di(e,t,n){null==t&&null==n||Wi(e),null!=t&&(e.curOp.scrollLeft=t),null!=n&&(e.curOp.scrollTop=n)}function Wi(e){let t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null,Hi(e,jn(e,t.from),jn(e,t.to),t.margin)}}function Hi(e,t,n,i){let r=Ni(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});Di(e,r.scrollLeft,r.scrollTop)}function zi(e,t){Math.abs(e.doc.scrollTop-t)<2||(n||lr(e,{top:t}),Fi(e,t,!0),n&&lr(e),er(e,100))}function Fi(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 Pi(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,ar(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function Ei(e){let t=e.display,n=t.gutters.offsetWidth,i=Math.round(e.doc.height+Sn(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+Mn(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}function Ii(e,t){t||(t=Ei(e));let n=e.display.barWidth,i=e.display.barHeight;Ri(e,t);for(let t=0;t<4&&n!=e.display.barWidth||i!=e.display.barHeight;t++)n!=e.display.barWidth&&e.options.lineWrapping&&Mi(e),Ri(e,Ei(e)),n=e.display.barWidth,i=e.display.barHeight}function Ri(e,t){let 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=""}let Bi={native:class{constructor(e,t,n){this.cm=n;let i=this.vert=A("div",[A("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),r=this.horiz=A("div",[A("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");i.tabIndex=r.tabIndex=-1,e(i),e(r),he(i,"scroll",()=>{i.clientHeight&&t(i.scrollTop,"vertical")}),he(r,"scroll",()=>{r.clientWidth&&t(r.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,o&&s<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}update(e){let 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";let n=e.viewHeight-(t?i:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+n)+"px"}else 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";let t=e.viewWidth-e.barLeft-(n?i:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+t)+"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}}setScrollLeft(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")}setScrollTop(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")}zeroWidthHack(){let e=b&&!f?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new R,this.disableVert=new R}enableZeroWidthBar(e,t,n){e.style.pointerEvents="auto",t.set(1e3,(function i(){let 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)}))}clear(){let e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)}},null:class{update(){return{bottom:0,right:0}}setScrollLeft(){}setScrollTop(){}clear(){}}};function Gi(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&L(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new Bi[e.options.scrollbarStyle](t=>{e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),he(t,"mousedown",()=>{e.state.focused&&setTimeout(()=>e.display.input.focus(),0)}),t.setAttribute("cm-not-content","true")},(t,n)=>{"horizontal"==n?Pi(e,t):zi(e,t)},e),e.display.scrollbars.addClass&&H(e.display.wrapper,e.display.scrollbars.addClass)}let Ui=0;function _i(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:++Ui},t=e.curOp,ln?ln.ops.push(t):t.ownsGroup=ln={ops:[t],delayedCallbacks:[]}}function Vi(e){let t=e.curOp;t&&function(e,t){let n=e.ownsGroup;if(n)try{!function(e){let t=e.delayedCallbacks,n=0;do{for(;n{for(let t=0;t=n.viewTo)||n.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new nr(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function $i(e){e.updatedDisplay=e.mustUpdate&&ir(e.cm,e.update)}function ji(e){let t=e.cm,n=t.display;e.updatedDisplay&&Mi(t),e.barMeasure=Ei(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+Mn(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-Ln(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function Xi(e){let t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft(window.innerHeight||document.documentElement.clientHeight)&&(r=!1),null!=r&&!p){let i=A("div","​",null,`position: absolute;\n top: ${t.top-n.viewOffset-Cn(e.display)}px;\n height: ${t.bottom-t.top+Mn(e)+n.barHeight}px;\n left: ${t.left}px; width: ${Math.max(2,t.right-t.left)}px;`);e.display.lineSpace.appendChild(i),i.scrollIntoView(r),e.display.lineSpace.removeChild(i)}}(t,function(e,t,n,i){let r;null==i&&(i=0),e.options.lineWrapping||t!=n||(n="before"==(t=t.ch?Je(t.line,"before"==t.sticky?t.ch-1:t.ch,"after"):t).sticky?Je(t.line,t.ch+1,"before"):t);for(let l=0;l<5;l++){let l=!1,o=$n(e,t),s=n&&n!=t?$n(e,n):o;r={left:Math.min(o.left,s.left),top:Math.min(o.top,s.top)-i,right:Math.max(o.left,s.left),bottom:Math.max(o.bottom,s.bottom)+i};let a=Ni(e,r),c=e.doc.scrollTop,u=e.doc.scrollLeft;if(null!=a.scrollTop&&(zi(e,a.scrollTop),Math.abs(e.doc.scrollTop-c)>1&&(l=!0)),null!=a.scrollLeft&&(Pi(e,a.scrollLeft),Math.abs(e.doc.scrollLeft-u)>1&&(l=!0)),!l)break}return r}(t,ot(i,e.scrollToPos.from),ot(i,e.scrollToPos.to),e.scrollToPos.margin))}let r=e.maybeHiddenMarkers,l=e.maybeUnhiddenMarkers;if(r)for(let e=0;e=e.display.viewTo)return;let n=+new Date+e.options.workTime,i=dt(e,t.highlightFrontier),r=[];t.iter(i.line,Math.min(t.first+t.size,e.display.viewTo+500),l=>{if(i.line>=e.display.viewFrom){let n=l.styles,o=l.text.length>e.options.maxHighlightLength?Ge(t.mode,i.state):null,s=ut(e,l,i,!0);o&&(i.state=o),l.styles=s.styles;let a=l.styleClasses,c=s.classes;c?l.styleClasses=c:a&&(l.styleClasses=null);let u=!n||n.length!=l.styles.length||a!=c&&(!a||!c||a.bgClass!=c.bgClass||a.textClass!=c.textClass);for(let e=0;!u&&en)return er(e,e.options.workDelay),!0}),t.highlightFrontier=i.line,t.modeFrontier=Math.max(t.modeFrontier,i.line),r.length&&qi(e,()=>{for(let t=0;t=n.viewFrom&&t.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==pi(e))return!1;cr(e)&&(di(e),t.dims=ri(e));let r=i.first+i.size,l=Math.max(t.visible.from-e.options.viewportMargin,i.first),o=Math.min(r,t.visible.to+e.options.viewportMargin);n.viewFromo&&n.viewTo-o<20&&(o=Math.min(r,n.viewTo)),xt&&(l=It(e.doc,l),o=Rt(e.doc,o));let s=l!=n.viewFrom||o!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth;!function(e,t,n){let i=e.display;0==i.view.length||t>=i.viewTo||n<=i.viewFrom?(i.view=rn(e,t,n),i.viewFrom=t):(i.viewFrom>t?i.view=rn(e,t,i.viewFrom).concat(i.view):i.viewFromn&&(i.view=i.view.slice(0,ci(e,n)))),i.viewTo=n}(e,l,o),n.viewOffset=Ut(Ke(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";let c=pi(e);if(!s&&0==c&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;let u=function(e){if(e.hasFocus())return null;let t=W();if(!t||!D(e.display.lineDiv,t))return null;let n={activeElt:t};if(window.getSelection){let t=window.getSelection();t.anchorNode&&t.extend&&D(e.display.lineDiv,t.anchorNode)&&(n.anchorNode=t.anchorNode,n.anchorOffset=t.anchorOffset,n.focusNode=t.focusNode,n.focusOffset=t.focusOffset)}return n}(e);return c>4&&(n.lineDiv.style.display="none"),function(e,t,n){let i=e.display,r=e.options.lineNumbers,l=i.lineDiv,o=l.firstChild;function s(t){let n=t.nextSibling;return a&&b&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}let c=i.view,u=i.viewFrom;for(let i=0;i-1&&(i=!1),cn(e,a,u,n)),i&&(T(a.lineNumber),a.lineNumber.appendChild(document.createTextNode(Qe(e.options,u)))),o=a.node.nextSibling}else{let t=mn(e,a,u,n);l.insertBefore(t,o)}u+=a.size}for(;o;)o=s(o)}(e,n.updateLineNumbers,t.dims),c>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,function(e){if(e&&e.activeElt&&e.activeElt!=W()&&(e.activeElt.focus(),e.anchorNode&&D(document.body,e.anchorNode)&&D(document.body,e.focusNode))){let 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)}}(u),T(n.cursorDiv),T(n.selectionDiv),n.gutters.style.height=n.sizer.style.minHeight=0,s&&(n.lastWrapHeight=t.wrapperHeight,n.lastWrapWidth=t.wrapperWidth,er(e,400)),n.updateLineNumbers=null,!0}function rr(e,t){let n=t.viewport;for(let i=!0;;i=!1){if(i&&e.options.lineWrapping&&t.oldDisplayWidth!=Ln(e))i&&(t.visible=Ti(e.display,e.doc,n));else if(n&&null!=n.top&&(n={top:Math.min(e.doc.height+Sn(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(!ir(e,t))break;Mi(e);let r=Ei(e);gi(e),Ii(e,r),sr(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){let n=new nr(e,t);if(ir(e,n)){Mi(e),rr(e,n);let t=Ei(e);gi(e),Ii(e,t),sr(e,t),n.finish()}}function or(e){let t=e.gutters.offsetWidth;e.sizer.style.marginLeft=t+"px"}function sr(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+Mn(e)+"px"}function ar(e){let t=e.display,n=t.view;if(!(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter))return;let i=li(t)-t.scroller.scrollLeft+e.doc.scrollLeft,r=t.gutters.offsetWidth,l=i+"px";for(let t=0;ts.clientWidth,u=s.scrollHeight>s.clientHeight;if(r&&c||l&&u){if(l&&b&&a)e:for(let n=t.target,i=o.view;n!=s;n=n.parentNode)for(let t=0;t{if(null==o.wheelStartX)return;let e=s.scrollLeft-o.wheelStartX,t=s.scrollTop-o.wheelStartY,n=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,n&&(gr=(gr*pr+n)/(pr+1),++pr)},200)):(o.wheelDX+=r,o.wheelDY+=l))}}o?gr=-.53:n?gr=15:u?gr=-.7:d&&(gr=-1/3);class wr{constructor(e,t){this.ranges=e,this.primIndex=t}primary(){return this.ranges[this.primIndex]}equals(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(let t=0;t=0&&et(e,i.to())<=0)return n}return-1}}class vr{constructor(e,t){this.anchor=e,this.head=t}from(){return rt(this.anchor,this.head)}to(){return it(this.anchor,this.head)}empty(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch}}function xr(e,t,n){let i=e&&e.options.selectionsMayTouch,r=t[n];t.sort((e,t)=>et(e.from(),t.from())),n=B(t,r);for(let e=1;e0:o>=0){let i=rt(l.from(),r.from()),o=it(l.to(),r.to()),s=l.empty()?r.from()==r.head:l.from()==l.head;e<=n&&--n,t.splice(--e,2,new vr(s?o:i,s?i:o))}}return new wr(t,n)}function Cr(e,t){return new wr([new vr(e,t||e)],0)}function Sr(e){return e.text?Je(e.from.line+e.text.length-1,X(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function kr(e,t){if(et(e,t.from)<0)return e;if(et(e,t.to)<=0)return Sr(t);let n=e.line+t.text.length-(t.to.line-t.from.line)-1,i=e.ch;return e.line==t.to.line&&(i+=Sr(t).ch-t.to.ch),Je(n,i)}function Mr(e,t){let n=[];for(let i=0;i{e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.modeFrontier=e.doc.highlightFrontier=e.doc.first,er(e,100),e.state.modeGen++,e.curOp&&ui(e)}function Ar(e,t){return 0==t.from.ch&&0==t.to.ch&&""==X(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function Or(e,t,n,i){function r(e){return n?n[e]:null}function l(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),Nt(e,n);let r=i?i(e):1;r!=e.height&&Xe(e,r)}(e,n,r,i),sn(e,"change",e,t)}function o(e,t){let n=[];for(let l=e;l1&&e.remove(s.line+1,p-1),e.insert(s.line+1,t)}sn(e,"change",e,t)}function Dr(e,t,n){!function e(i,r,l){if(i.linked)for(let o=0;oBr(e,n,t.from.line,t.to.line+1),!0),n}function Pr(e){for(;e.length;){if(!X(e).ranges)break;e.pop()}}function Er(e,t,n,i){let r=e.history;r.undone.length=0;let l,o,s=+new Date;if((r.lastOp==i||r.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&r.lastModTime>s-(e.cm?e.cm.options.historyEventDelay:500)||"*"==t.origin.charAt(0)))&&(l=function(e,t){return t?(Pr(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(l.changes),0==et(t.from,t.to)&&0==et(t.from,o.to)?o.to=Sr(t):l.changes.push(Fr(e,t));else{let n=X(r.done);for(n&&n.ranges||Rr(e.sel,r.done),l={changes:[Fr(e,t)],generation:r.generation},r.done.push(l);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=s,r.lastOp=r.lastSelOp=i,r.lastOrigin=r.lastSelOrigin=t.origin,o||pe(e,"historyAdded")}function Ir(e,t,n,i){let r=e.history,l=i&&i.origin;n==r.lastSelOp||l&&r.lastSelOrigin==l&&(r.lastModTime==r.lastSelTime&&r.lastOrigin==l||function(e,t,n,i){let 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,l,X(r.done),t))?r.done[r.done.length-1]=t:Rr(t,r.done),r.lastSelTime=+new Date,r.lastSelOrigin=l,r.lastSelOp=n,i&&!1!==i.clearRedo&&Pr(r.undone)}function Rr(e,t){let n=X(t);n&&n.ranges&&n.equals(e)||t.push(e)}function Br(e,t,n,i){let r=t["spans_"+e.id],l=0;e.iter(Math.max(e.first,n),Math.min(e.first+e.size,i),n=>{n.markedSpans&&((r||(r=t["spans_"+e.id]={}))[l]=n.markedSpans),++l})}function Gr(e){if(!e)return null;let t;for(let n=0;n-1&&(X(a)[r]=i[r],delete i[r])}}return i}function Vr(e,t,n,i){if(i){let i=e.anchor;if(n){let e=et(t,i)<0;e!=et(n,i)<0?(i=t,t=n):e!=et(t,n)<0&&(t=n)}return new vr(i,t)}return new vr(n||t,t)}function Kr(e,t,n,i,r){null==r&&(r=e.cm&&(e.cm.display.shift||e.extend)),qr(e,new wr([Vr(e.sel.primary(),t,n,r)],0),i)}function $r(e,t,n){let i=[],r=e.cm&&(e.cm.display.shift||e.extend);for(let n=0;n=t.ch:s.to>t.ch))){if(r&&(pe(a,"beforeCursorEnter"),a.explicitlyCleared)){if(l.markedSpans){--o;continue}break}if(!a.atomic)continue;if(n){let o,s=a.find(i<0?1:-1);if((i<0?u:c)&&(s=il(e,s,-i,s&&s.line==t.line?l:null)),s&&s.line==t.line&&(o=et(s,n))&&(i<0?o<0:o>0))return tl(e,s,t,i,r)}let s=a.find(i<0?-1:1);return(i<0?c:u)&&(s=il(e,s,i,s.line==t.line?l:null)),s?tl(e,s,t,i,r):null}}return t}function nl(e,t,n,i,r){let l=i||1,o=tl(e,t,n,l,r)||!r&&tl(e,t,n,l,!0)||tl(e,t,n,-l,r)||!r&&tl(e,t,n,-l,!0);return o||(e.cantEdit=!0,Je(e.first,0))}function il(e,t,n,i){return n<0&&0==t.ch?t.line>e.first?ot(e,Je(t.line-1)):null:n>0&&t.ch==(i||Ke(e,t.line)).text.length?t.linei.canceled=!0};return n&&(i.update=(t,n,r,l)=>{t&&(i.from=ot(e,t)),n&&(i.to=ot(e,n)),r&&(i.text=r),void 0!==l&&(i.origin=l)}),pe(e,"beforeChange",e,i),e.cm&&pe(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 ol(e,t,n){if(e.cm){if(!e.cm.curOp)return Zi(e.cm,ol)(e,t,n);if(e.cm.state.suppressEdits)return}if((ye(e,"beforeChange")||e.cm&&ye(e.cm,"beforeChange"))&&!(t=ll(e,t,!0)))return;let i=vt&&!n&&function(e,t,n){let i=null;if(e.iter(t.line,n.line+1,e=>{if(e.markedSpans)for(let t=0;t0)continue;let l=[e,1],o=et(i.from,n.from),s=et(i.to,n.to);(o<0||!t.inclusiveLeft&&!o)&&l.push({from:i.from,to:n.from}),(s>0||!t.inclusiveRight&&!s)&&l.push({from:n.to,to:i.to}),r.splice.apply(r,l),e+=l.length-3}}return r}(e,t.from,t.to);if(i)for(let n=i.length-1;n>=0;--n)sl(e,{from:i[n].from,to:i[n].to,text:n?[""]:t.text,origin:t.origin});else sl(e,t)}function sl(e,t){if(1==t.text.length&&""==t.text[0]&&0==et(t.from,t.to))return;let n=Mr(e,t);Er(e,t,n,e.cm?e.cm.curOp.id:NaN),ul(e,t,n,Mt(e,t));let i=[];Dr(e,(e,n)=>{n||-1!=B(i,e.history)||(pl(e.history,t),i.push(e.history)),ul(e,t,null,Mt(e,t))})}function al(e,t,n){let i=e.cm&&e.cm.state.suppressEdits;if(i&&!n)return;let r,l=e.history,o=e.sel,s="undo"==t?l.done:l.undone,a="undo"==t?l.undone:l.done,c=0;for(;c=0;--n){let i=r.changes[n];if(i.origin=t,h&&!ll(e,i,!1))return void(s.length=0);u.push(Fr(e,i));let l=n?Mr(e,i):X(s);ul(e,i,l,Ur(e,i)),!n&&e.cm&&e.cm.scrollIntoView({from:i.from,to:Sr(i)});let o=[];Dr(e,(e,t)=>{t||-1!=B(o,e.history)||(pl(e.history,i),o.push(e.history)),ul(e,i,null,Ur(e,i))})}}function cl(e,t){if(0!=t&&(e.first+=t,e.sel=new wr(Y(e.sel.ranges,e=>new vr(Je(e.anchor.line+t,e.anchor.ch),Je(e.head.line+t,e.head.ch))),e.sel.primIndex),e.cm)){ui(e.cm,e.first,e.first-t,t);for(let t=e.cm.display,n=t.viewFrom;ne.lastLine())return;if(t.from.liner&&(t={from:t.from,to:Je(r,Ke(e,r).text.length),text:[t.text[0]],origin:t.origin}),t.removed=$e(e,t.from,t.to),n||(n=Mr(e,t)),e.cm?function(e,t,n){let i=e.doc,r=e.display,l=t.from,o=t.to,s=!1,a=l.line;e.options.lineWrapping||(a=Ye(Et(Ke(i,l.line))),i.iter(a,o.line+1,e=>{if(e==r.maxLine)return s=!0,!0}));i.sel.contains(t.from,t.to)>-1&&me(e);Or(i,t,n,oi(e)),e.options.lineWrapping||(i.iter(a,l.line+t.text.length,e=>{let t=_t(e);t>r.maxLineLength&&(r.maxLine=e,r.maxLineLength=t,r.maxLineChanged=!0,s=!1)}),s&&(e.curOp.updateMaxLine=!0));(function(e,t){if(e.modeFrontier=Math.min(e.modeFrontier,t),e.highlightFrontiern;i--){let r=Ke(e,i).stateAfter;if(r&&(!(r instanceof at)||i+r.lookAhead1||!(this.children[0]instanceof ml))){let e=[];this.collapse(e),this.children=[new ml(e)],this.children[0].parent=this}},collapse(e){for(let t=0;t50){let e=r.lines.length%25+25;for(let t=e;t10);e.parent.maybeSpill()},iterN(e,t,n){for(let i=0;i{wl(e,n,-r),hi(e,i,"widget")}),sn(e,"lineWidgetCleared",e,this,i))}changed(){let e=this.height,t=this.doc.cm,n=this.line;this.height=null;let i=vn(this)-e;i&&(Bt(this.doc,n)||Xe(n,n.height+i),t&&qi(t,()=>{t.curOp.forceUpdate=!0,wl(t,n,i),sn(t,"lineWidgetChanged",t,this,Ye(n))}))}}function wl(e,t,n){Ut(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Ai(e,n)}be(bl);let vl=0;class xl{constructor(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++vl}clear(){if(this.explicitlyCleared)return;let e=this.doc.cm,t=e&&!e.curOp;if(t&&_i(e),ye(this,"clear")){let e=this.find();e&&sn(this,"clear",e.from,e.to)}let n=null,i=null;for(let t=0;te.display.maxLineLength&&(e.display.maxLine=n,e.display.maxLineLength=i,e.display.maxLineChanged=!0)}null!=n&&e&&this.collapsed&&ui(e,n,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&Jr(e.doc)),e&&sn(e,"markerCleared",e,this,n,i),t&&Vi(e),this.parent&&this.parent.clear()}find(e,t){let n,i;null==e&&"bookmark"==this.type&&(e=1);for(let r=0;r{let i=e.line,r=Ye(e.line),l=On(n,r);if(l&&(En(l),n.curOp.selectionChanged=n.curOp.forceUpdate=!0),n.curOp.updateMaxLine=!0,!Bt(t.doc,i)&&null!=t.height){let e=t.height;t.height=null;let n=vn(t)-e;n&&Xe(i,i.height+n)}sn(n,"markerChanged",n,this)})}attachLine(e){if(!this.lines.length&&this.doc.cm){let e=this.doc.cm.curOp;e.maybeHiddenMarkers&&-1!=B(e.maybeHiddenMarkers,this)||(e.maybeUnhiddenMarkers||(e.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)}detachLine(e){if(this.lines.splice(B(this.lines,e),1),!this.lines.length&&this.doc.cm){let e=this.doc.cm.curOp;(e.maybeHiddenMarkers||(e.maybeHiddenMarkers=[])).push(this)}}}function Cl(e,t,n,i,r){if(i&&i.shared)return function(e,t,n,i,r){(i=E(i)).shared=!1;let l=[Cl(e,t,n,i,r)],o=l[0],s=i.widgetNode;return Dr(e,e=>{s&&(i.widgetNode=s.cloneNode(!0)),l.push(Cl(e,ot(e,t),ot(e,n),i,r));for(let t=0;t0||0==o&&!1!==l.clearWhenEmpty)return l;if(l.replacedWith&&(l.collapsed=!0,l.widgetNode=O("span",[l.replacedWith],"CodeMirror-widget"),i.handleMouseEvents||l.widgetNode.setAttribute("cm-ignore-events","true"),i.insertLeft&&(l.widgetNode.insertLeft=!0)),l.collapsed){if(Pt(e,t.line,t,n,l)||t.line!=n.line&&Pt(e,n.line,t,n,l))throw new Error("Inserting collapsed marker partially overlapping an existing one");xt=!0}l.addToHistory&&Er(e,{from:t,to:n,origin:"markText"},e.sel,NaN);let s,a=t.line,c=e.cm;if(e.iter(a,n.line+1,e=>{c&&l.collapsed&&!c.options.lineWrapping&&Et(e)==c.display.maxLine&&(s=!0),l.collapsed&&a!=t.line&&Xe(e,0),function(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}(e,new Ct(l,a==t.line?t.ch:null,a==n.line?n.ch:null)),++a}),l.collapsed&&e.iter(t.line,n.line+1,t=>{Bt(e,t)&&Xe(t,0)}),l.clearOnEnter&&he(l,"beforeCursorEnter",()=>l.clear()),l.readOnly&&(vt=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),l.collapsed&&(l.id=++vl,l.atomic=!0),c){if(s&&(c.curOp.updateMaxLine=!0),l.collapsed)ui(c,t.line,n.line+1);else if(l.className||l.startStyle||l.endStyle||l.css||l.attributes||l.title)for(let e=t.line;e<=n.line;e++)hi(c,e,"text");l.atomic&&Jr(c.doc),sn(c,"markerAdded",c,l)}return l}be(xl);class Sl{constructor(e,t){this.markers=e,this.primary=t;for(let t=0;te.parent)}function Ml(e){for(let t=0;ti.push(e));for(let e=0;e=0;e--)ol(this,i[e]);l?Yr(this,l):this.cm&&Oi(this.cm)})),undo:Ji((function(){al(this,"undo")})),redo:Ji((function(){al(this,"redo")})),undoSelection:Ji((function(){al(this,"undo",!0)})),redoSelection:Ji((function(){al(this,"redo",!0)})),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){let e=this.history,t=0,n=0;for(let n=0;ne.history=this.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:_r(this.history.done),undone:_r(this.history.undone)}},setHistory:function(e){let t=this.history=new zr(this.history.maxGeneration);t.done=_r(e.done.slice(0),null,!0),t.undone=_r(e.undone.slice(0),null,!0)},setGutterMarker:Ji((function(e,t,n){return gl(this,e,"gutter",e=>{let i=e.gutterMarkers||(e.gutterMarkers={});return i[t]=n,!n&&te(i)&&(e.gutterMarkers=null),!0})})),clearGutter:Ji((function(e){this.iter(t=>{t.gutterMarkers&&t.gutterMarkers[e]&&gl(this,t,"gutter",()=>(t.gutterMarkers[e]=null,te(t.gutterMarkers)&&(t.gutterMarkers=null),!0))})})),lineInfo:function(e){let t;if("number"==typeof e){if(!Ze(this,e))return null;if(t=e,!(e=Ke(this,e)))return null}else if(t=Ye(e),null==t)return null;return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},addLineClass:Ji((function(e,t,n){return gl(this,e,"gutter"==t?"gutter":"class",e=>{let i="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass";if(e[i]){if(k(n).test(e[i]))return!1;e[i]+=" "+n}else e[i]=n;return!0})})),removeLineClass:Ji((function(e,t,n){return gl(this,e,"gutter"==t?"gutter":"class",e=>{let 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{let t=r.match(k(n));if(!t)return!1;let l=t.index+t[0].length;e[i]=r.slice(0,t.index)+(t.index&&l!=r.length?" ":"")+r.slice(l)||null}return!0})})),addLineWidget:Ji((function(e,t,n){return function(e,t,n,i){let r=new bl(e,n,i),l=e.cm;return l&&r.noHScroll&&(l.display.alignWidgets=!0),gl(e,t,"widget",t=>{let n=t.widgets||(t.widgets=[]);if(null==r.insertAt?n.push(r):n.splice(Math.min(n.length-1,Math.max(0,r.insertAt)),0,r),r.line=t,l&&!Bt(e,t)){let n=Ut(t)=e.ch)&&t.push(r.marker.parent||r.marker)}return t},findMarks:function(e,t,n){e=ot(this,e),t=ot(this,t);let i=[],r=e.line;return this.iter(e.line,t.line+1,l=>{let o=l.markedSpans;if(o)for(let l=0;l=s.to||null==s.from&&r!=e.line||null!=s.from&&r==t.line&&s.from>=t.ch||n&&!n(s.marker)||i.push(s.marker.parent||s.marker)}++r}),i},getAllMarks:function(){let e=[];return this.iter(t=>{let n=t.markedSpans;if(n)for(let t=0;t{let l=r.text.length+i;if(l>e)return t=e,!0;e-=l,++n}),ot(this,Je(n,t))},indexFromPos:function(e){let t=(e=ot(this,e)).ch;if(e.line{t+=e.text.length+n}),t},copy:function(e){let t=new Tl(je(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={});let t=this.first,n=this.first+this.size;null!=e.from&&e.from>t&&(t=e.from),null!=e.to&&e.tot.push(e.id),!0),e.history=new zr(null),e.history.done=_r(this.history.done,t),e.history.undone=_r(this.history.undone,t)}},iterLinkedDocs:function(e){Dr(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm},splitLines:function(e){return this.lineSep?e.split(this.lineSep):Oe(e)},lineSeparator:function(){return this.lineSep||"\n"},setDirection:Ji((function(e){var t;("rtl"!=e&&(e="ltr"),e!=this.direction)&&(this.direction=e,this.iter(e=>e.order=null),this.cm&&qi(t=this.cm,()=>{Hr(t),ui(t)}))}))}),Tl.prototype.eachLine=Tl.prototype.iter;let Nl=0;function Al(e){let t=this;if(Ol(t),ge(t,e)||xn(t.display,e))return;we(e),o&&(Nl=+new Date);let n=ai(t,e,!0),i=e.dataTransfer.files;if(n&&!t.isReadOnly())if(i&&i.length&&window.FileReader&&window.File){let e=i.length,r=Array(e),l=0;const o=()=>{++l==e&&Zi(t,()=>{n=ot(t.doc,n);let e={from:n,to:n,text:t.doc.splitLines(r.filter(e=>null!=e).join(t.doc.lineSeparator())),origin:"paste"};ol(t.doc,e),Yr(t.doc,Cr(ot(t.doc,n),ot(t.doc,Sr(e))))})()},s=(e,n)=>{if(t.options.allowDropFileTypes&&-1==B(t.options.allowDropFileTypes,e.type))return void o();let i=new FileReader;i.onerror=()=>o(),i.onload=()=>{let e=i.result;/[\x00-\x08\x0e-\x1f]{2}/.test(e)||(r[n]=e),o()},i.readAsText(e)};for(let e=0;e-1)return t.state.draggingText(e),void setTimeout(()=>t.display.input.focus(),20);try{let i=e.dataTransfer.getData("Text");if(i){let e;if(t.state.draggingText&&!t.state.draggingText.copy&&(e=t.listSelections()),Zr(t.doc,Cr(n,n)),e)for(let n=0;n{for(let t=0;t{null==e&&(e=setTimeout(()=>{e=null,Dl(zl)},100))}),he(window,"blur",()=>Dl(ki))}(),Wl=!0)}function zl(e){let t=e.display;t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize()}let Fl={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:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"};for(let e=0;e<10;e++)Fl[e+48]=Fl[e+96]=String(e);for(let e=65;e<=90;e++)Fl[e]=String.fromCharCode(e);for(let e=1;e<=12;e++)Fl[e+111]=Fl[e+63235]="F"+e;let Pl={};function El(e){let t,n,i,r,l=e.split(/-(?!$)/);e=l[l.length-1];for(let e=0;e{for(let t=i.length-1;t>=0;t--)hl(e.doc,"",i[t].from,i[t].to,"+delete");Oi(e)})}function Kl(e,t,n){let i=re(e.text,t+n,n);return i<0||i>e.text.length?null:i}function $l(e,t,n){let i=Kl(e,t.ch,n);return null==i?null:new Je(t.line,i,n<0?"after":"before")}function jl(e,t,n,i,r){if(e){"rtl"==t.doc.direction&&(r=-r);let e=ce(n,t.doc.direction);if(e){let l,o=r<0?X(e):e[0],s=r<0==(1==o.level)?"after":"before";if(o.level>0||"rtl"==t.doc.direction){let e=Dn(t,n);l=r<0?n.text.length-1:0;let i=Wn(t,e,l).top;l=le(n=>Wn(t,e,n).top==i,r<0==(1==o.level)?o.from:o.to-1,l),"before"==s&&(l=Kl(n,l,1))}else l=r<0?o.to:o.from;return new Je(i,l,s)}}return new Je(i,r<0?n.text.length:0,r<0?"before":"after")}Pl.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"},Pl.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"},Pl.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Pl.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"]},Pl.default=b?Pl.macDefault:Pl.pcDefault;let Xl={selectAll:rl,singleSelection:e=>e.setSelection(e.getCursor("anchor"),e.getCursor("head"),U),killLine:e=>Vl(e,t=>{if(t.empty()){let n=Ke(e.doc,t.head.line).text.length;return t.head.ch==n&&t.head.lineVl(e,t=>({from:Je(t.from().line,0),to:ot(e.doc,Je(t.to().line+1,0))})),delLineLeft:e=>Vl(e,e=>({from:Je(e.from().line,0),to:e.from()})),delWrappedLineLeft:e=>Vl(e,t=>{let n=e.charCoords(t.head,"div").top+5;return{from:e.coordsChar({left:0,top:n},"div"),to:t.from()}}),delWrappedLineRight:e=>Vl(e,t=>{let 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:e=>e.undo(),redo:e=>e.redo(),undoSelection:e=>e.undoSelection(),redoSelection:e=>e.redoSelection(),goDocStart:e=>e.extendSelection(Je(e.firstLine(),0)),goDocEnd:e=>e.extendSelection(Je(e.lastLine())),goLineStart:e=>e.extendSelectionsBy(t=>Yl(e,t.head.line),{origin:"+move",bias:1}),goLineStartSmart:e=>e.extendSelectionsBy(t=>ql(e,t.head),{origin:"+move",bias:1}),goLineEnd:e=>e.extendSelectionsBy(t=>function(e,t){let n=Ke(e.doc,t),i=function(e){let t;for(;t=zt(e);)e=t.find(1,!0).line;return e}(n);i!=n&&(t=Ye(i));return jl(!0,e,n,t,-1)}(e,t.head.line),{origin:"+move",bias:-1}),goLineRight:e=>e.extendSelectionsBy(t=>{let n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div")},V),goLineLeft:e=>e.extendSelectionsBy(t=>{let n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:n},"div")},V),goLineLeftSmart:e=>e.extendSelectionsBy(t=>{let n=e.cursorCoords(t.head,"div").top+5,i=e.coordsChar({left:0,top:n},"div");return i.che.moveV(-1,"line"),goLineDown:e=>e.moveV(1,"line"),goPageUp:e=>e.moveV(-1,"page"),goPageDown:e=>e.moveV(1,"page"),goCharLeft:e=>e.moveH(-1,"char"),goCharRight:e=>e.moveH(1,"char"),goColumnLeft:e=>e.moveH(-1,"column"),goColumnRight:e=>e.moveH(1,"column"),goWordLeft:e=>e.moveH(-1,"word"),goGroupRight:e=>e.moveH(1,"group"),goGroupLeft:e=>e.moveH(-1,"group"),goWordRight:e=>e.moveH(1,"word"),delCharBefore:e=>e.deleteH(-1,"char"),delCharAfter:e=>e.deleteH(1,"char"),delWordBefore:e=>e.deleteH(-1,"word"),delWordAfter:e=>e.deleteH(1,"word"),delGroupBefore:e=>e.deleteH(-1,"group"),delGroupAfter:e=>e.deleteH(1,"group"),indentAuto:e=>e.indentSelection("smart"),indentMore:e=>e.indentSelection("add"),indentLess:e=>e.indentSelection("subtract"),insertTab:e=>e.replaceSelection("\t"),insertSoftTab:e=>{let t=[],n=e.listSelections(),i=e.options.tabSize;for(let r=0;r{e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:e=>qi(e,()=>{let t=e.listSelections(),n=[];for(let i=0;i0)r=new Je(r.line,r.ch+1),e.replaceRange(l.charAt(r.ch-1)+l.charAt(r.ch-2),Je(r.line,r.ch-2),r,"+transpose");else if(r.line>e.doc.first){let t=Ke(e.doc,r.line-1).text;t&&(r=new Je(r.line,1),e.replaceRange(l.charAt(0)+e.doc.lineSeparator()+t.charAt(t.length-1),Je(r.line-1,t.length-1),r,"+transpose"))}n.push(new vr(r,r))}e.setSelections(n)}),newlineAndIndent:e=>qi(e,()=>{let t=e.listSelections();for(let n=t.length-1;n>=0;n--)e.replaceRange(e.doc.lineSeparator(),t[n].anchor,t[n].head,"+input");t=e.listSelections();for(let n=0;ne.replaceSelection("\n","start"),toggleOverwrite:e=>e.toggleOverwrite()};function Yl(e,t){let n=Ke(e.doc,t),i=Et(n);return i!=n&&(t=Ye(i)),jl(!0,e,i,t,1)}function ql(e,t){let n=Yl(e,t.line),i=Ke(e.doc,n.line),r=ce(i,e.doc.direction);if(!r||0==r[0].level){let e=Math.max(n.ch,i.text.search(/\S/)),r=t.line==n.line&&t.ch<=e&&t.ch;return Je(n.line,r?0:e,n.sticky)}return n}function Zl(e,t,n){if("string"==typeof t&&!(t=Xl[t]))return!1;e.display.input.ensurePolled();let i=e.display.shift,r=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),n&&(e.display.shift=!1),r=t(e)!=G}finally{e.display.shift=i,e.state.suppressEdits=!1}return r}let Ql=new R;function Jl(e,t,n,i){let r=e.state.keySeq;if(r){if(Bl(t))return"handled";if(/\'$/.test(t)?e.state.keySeq=null:Ql.set(50,()=>{e.state.keySeq==r&&(e.state.keySeq=null,e.display.input.reset())}),eo(e,r+" "+t,n,i))return!0}return eo(e,t,n,i)}function eo(e,t,n,i){let r=function(e,t,n){for(let i=0;iZl(e,t,!0))||Jl(e,n,t,t=>{if("string"==typeof t?/^go[A-Z]/.test(t):t.motion)return Zl(e,t)}):Jl(e,n,t,t=>Zl(e,t)))}let no=null;function io(e){let t=this;if(t.curOp.focus=W(),ge(t,e))return;o&&s<11&&27==e.keyCode&&(e.returnValue=!1);let i=e.keyCode;t.display.shift=16==i||e.shiftKey;let r=to(t,e);h&&(no=r?i:null,r||88!=i||We||!(b?e.metaKey:e.ctrlKey)||t.replaceSelection("",null,"cut")),n&&!b&&!r&&46==i&&e.shiftKey&&!e.ctrlKey&&document.execCommand&&document.execCommand("cut"),18!=i||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||function(e){let t=e.display.lineDiv;function n(e){18!=e.keyCode&&e.altKey||(L(t,"CodeMirror-crosshair"),fe(document,"keyup",n),fe(document,"mouseover",n))}H(t,"CodeMirror-crosshair"),he(document,"keyup",n),he(document,"mouseover",n)}(t)}function ro(e){16==e.keyCode&&(this.doc.sel.shift=!1),ge(this,e)}function lo(e){let t=this;if(xn(t.display,e)||ge(t,e)||e.ctrlKey&&!e.altKey||b&&e.metaKey)return;let n=e.keyCode,i=e.charCode;if(h&&n==no)return no=null,void we(e);if(h&&(!e.which||e.which<10)&&to(t,e))return;let r=String.fromCharCode(null==i?n:i);"\b"!=r&&(function(e,t,n){return Jl(e,"'"+n+"'",t,t=>Zl(e,t,!0))}(t,e,r)||t.display.input.onKeyPress(e))}class oo{constructor(e,t,n){this.time=e,this.pos=t,this.button=n}compare(e,t,n){return this.time+400>e&&0==et(t,this.pos)&&n==this.button}}let so,ao;function co(e){let t=this,n=t.display;if(ge(t,e)||n.activeTouch&&n.input.supportsTouch())return;if(n.input.ensurePolled(),n.shift=e.shiftKey,xn(n,e))return void(a||(n.scroller.draggable=!1,setTimeout(()=>n.scroller.draggable=!0,100)));if(fo(t,e))return;let i=ai(t,e),r=ke(e),l=i?function(e,t){let n=+new Date;return ao&&ao.compare(n,e,t)?(so=ao=null,"triple"):so&&so.compare(n,e,t)?(ao=new oo(n,e,t),so=null,"double"):(so=new oo(n,e,t),ao=null,"single")}(i,r):"single";window.focus(),1==r&&t.state.selectingText&&t.state.selectingText(e),i&&function(e,t,n,i,r){let l="Click";"double"==i?l="Double"+l:"triple"==i&&(l="Triple"+l);return l=(1==t?"Left":2==t?"Middle":"Right")+l,Jl(e,Gl(l,r),r,t=>{if("string"==typeof t&&(t=Xl[t]),!t)return!1;let i=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),i=t(e,n)!=G}finally{e.state.suppressEdits=!1}return i})}(t,r,i,l,e)||(1==r?i?function(e,t,n,i){o?setTimeout(P(xi,e),0):e.curOp.focus=W();let r,l=function(e,t,n){let i=e.getOption("configureMouse"),r=i?i(e,t,n):{};if(null==r.unit){let e=w?n.shiftKey&&n.metaKey:n.altKey;r.unit=e?"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=b?n.metaKey:n.ctrlKey);null==r.moveOnDrag&&(r.moveOnDrag=!(b?n.altKey:n.ctrlKey));return r}(e,n,i),c=e.doc.sel;e.options.dragDrop&&Te&&!e.isReadOnly()&&"single"==n&&(r=c.contains(t))>-1&&(et((r=c.ranges[r]).from(),t)<0||t.xRel>0)&&(et(r.to(),t)>0||t.xRel<0)?function(e,t,n,i){let r=e.display,l=!1,c=Zi(e,t=>{a&&(r.scroller.draggable=!1),e.state.draggingText=!1,fe(r.wrapper.ownerDocument,"mouseup",c),fe(r.wrapper.ownerDocument,"mousemove",u),fe(r.scroller,"dragstart",h),fe(r.scroller,"drop",c),l||(we(t),i.addNew||Kr(e.doc,n,null,null,i.extend),a||o&&9==s?setTimeout(()=>{r.wrapper.ownerDocument.body.focus(),r.input.focus()},20):r.input.focus())}),u=function(e){l=l||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},h=()=>l=!0;a&&(r.scroller.draggable=!0);e.state.draggingText=c,c.copy=!i.moveOnDrag,r.scroller.dragDrop&&r.scroller.dragDrop();he(r.wrapper.ownerDocument,"mouseup",c),he(r.wrapper.ownerDocument,"mousemove",u),he(r.scroller,"dragstart",h),he(r.scroller,"drop",c),Ci(e),setTimeout(()=>r.input.focus(),20)}(e,i,t,l):function(e,t,n,i){let r=e.display,l=e.doc;we(t);let o,s,a=l.sel,c=a.ranges;i.addNew&&!i.extend?(s=l.sel.contains(n),o=s>-1?c[s]:new vr(n,n)):(o=l.sel.primary(),s=l.sel.primIndex);if("rectangle"==i.unit)i.addNew||(o=new vr(n,n)),n=ai(e,t,!0,!0),s=-1;else{let t=uo(e,n,i.unit);o=i.extend?Vr(o,t.anchor,t.head,i.extend):t}i.addNew?-1==s?(s=c.length,qr(l,xr(e,c.concat([o]),s),{scroll:!1,origin:"*mouse"})):c.length>1&&c[s].empty()&&"char"==i.unit&&!i.extend?(qr(l,xr(e,c.slice(0,s).concat(c.slice(s+1)),0),{scroll:!1,origin:"*mouse"}),a=l.sel):jr(l,s,o,_):(s=0,qr(l,new wr([o],0),_),a=l.sel);let u=n;function h(t){if(0!=et(u,t))if(u=t,"rectangle"==i.unit){let i=[],r=e.options.tabSize,o=I(Ke(l,n.line).text,n.ch,r),c=I(Ke(l,t.line).text,t.ch,r),u=Math.min(o,c),h=Math.max(o,c);for(let o=Math.min(n.line,t.line),s=Math.min(e.lastLine(),Math.max(n.line,t.line));o<=s;o++){let e=Ke(l,o).text,t=K(e,u,r);u==h?i.push(new vr(Je(o,t),Je(o,t))):e.length>t&&i.push(new vr(Je(o,t),Je(o,K(e,h,r))))}i.length||i.push(new vr(n,n)),qr(l,xr(e,a.ranges.slice(0,s).concat(i),s),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{let n,r=o,c=uo(e,t,i.unit),u=r.anchor;et(c.anchor,u)>0?(n=c.head,u=rt(r.from(),c.anchor)):(n=c.anchor,u=it(r.to(),c.head));let h=a.ranges.slice(0);h[s]=function(e,t){let{anchor:n,head:i}=t,r=Ke(e.doc,n.line);if(0==et(n,i)&&n.sticky==i.sticky)return t;let l=ce(r);if(!l)return t;let o=se(l,n.ch,n.sticky),s=l[o];if(s.from!=n.ch&&s.to!=n.ch)return t;let a,c=o+(s.from==n.ch==(1!=s.level)?0:1);if(0==c||c==l.length)return t;if(i.line!=n.line)a=(i.line-n.line)*("ltr"==e.doc.direction?1:-1)>0;else{let e=se(l,i.ch,i.sticky),t=e-o||(i.ch-n.ch)*(1==s.level?-1:1);a=e==c-1||e==c?t<0:t>0}let u=l[c+(a?-1:0)],h=a==(1==u.level),d=h?u.from:u.to,f=h?"after":"before";return n.ch==d&&n.sticky==f?t:new vr(new Je(n.line,d,f),i)}(e,new vr(ot(l,u),n)),qr(l,xr(e,h,s),_)}}let d=r.wrapper.getBoundingClientRect(),f=0;function p(t){e.state.selectingText=!1,f=1/0,t&&(we(t),r.input.focus()),fe(r.wrapper.ownerDocument,"mousemove",g),fe(r.wrapper.ownerDocument,"mouseup",m),l.history.lastSelOrigin=null}let g=Zi(e,t=>{0!==t.buttons&&ke(t)?function t(n){let o=++f,s=ai(e,n,!0,"rectangle"==i.unit);if(s)if(0!=et(s,u)){e.curOp.focus=W(),h(s);let i=Ti(r,l);(s.line>=i.to||s.line{f==o&&t(n)}),150)}else{let i=n.clientYd.bottom?20:0;i&&setTimeout(Zi(e,()=>{f==o&&(r.scroller.scrollTop+=i,t(n))}),50)}}(t):p(t)}),m=Zi(e,p);e.state.selectingText=m,he(r.wrapper.ownerDocument,"mousemove",g),he(r.wrapper.ownerDocument,"mouseup",m)}(e,i,t,l)}(t,i,l,e):Se(e)==n.scroller&&we(e):2==r?(i&&Kr(t.doc,i),setTimeout(()=>n.input.focus(),20)):3==r&&(S?t.display.input.onContextMenu(e):Ci(t)))}function uo(e,t,n){if("char"==n)return new vr(t,t);if("word"==n)return e.findWordAt(t);if("line"==n)return new vr(Je(t.line,0),ot(e.doc,Je(t.line+1,0)));let i=n(e,t);return new vr(i.from,i.to)}function ho(e,t,n,i){let r,l;if(t.touches)r=t.touches[0].clientX,l=t.touches[0].clientY;else try{r=t.clientX,l=t.clientY}catch(t){return!1}if(r>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;i&&we(t);let o=e.display,s=o.lineDiv.getBoundingClientRect();if(l>s.bottom||!ye(e,n))return xe(t);l-=s.top-o.viewOffset;for(let i=0;i=r){return pe(e,n,e,qe(e.doc,l),e.display.gutterSpecs[i].className,t),xe(t)}}}function fo(e,t){return ho(e,t,"gutterClick",!0)}function po(e,t){xn(e.display,t)||function(e,t){return!!ye(e,"gutterContextMenu")&&ho(e,t,"gutterContextMenu",!1)}(e,t)||ge(e,t,"contextmenu")||S||e.display.input.onContextMenu(t)}function go(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),Rn(e)}let mo={toString:function(){return"CodeMirror.Init"}},yo={},bo={};function wo(e,t,n){if(!t!=!(n&&n!=mo)){let n=e.display.dragFunctions,i=t?he:fe;i(e.display.scroller,"dragstart",n.start),i(e.display.scroller,"dragenter",n.enter),i(e.display.scroller,"dragover",n.over),i(e.display.scroller,"dragleave",n.leave),i(e.display.scroller,"drop",n.drop)}}function vo(e){e.options.lineWrapping?(H(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(L(e.display.wrapper,"CodeMirror-wrap"),Vt(e)),si(e),ui(e),Rn(e),setTimeout(()=>Ii(e),100)}function xo(e,t){if(!(this instanceof xo))return new xo(e,t);this.options=t=t?E(t):{},E(yo,t,!1);let n=t.value;"string"==typeof n?n=new Tl(n,t.mode,null,t.lineSeparator,t.direction):t.mode&&(n.modeOption=t.mode),this.doc=n;let i=new xo.inputStyles[t.inputStyle](this),r=this.display=new fr(e,n,i,t);r.wrapper.CodeMirror=this,go(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),Gi(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 R,keySeq:null,specialChars:null},t.autofocus&&!y&&r.input.focus(),o&&s<11&&setTimeout(()=>this.display.input.reset(!0),20),function(e){let t=e.display;he(t.scroller,"mousedown",Zi(e,co)),he(t.scroller,"dblclick",o&&s<11?Zi(e,t=>{if(ge(e,t))return;let n=ai(e,t);if(!n||fo(e,t)||xn(e.display,t))return;we(t);let i=e.findWordAt(n);Kr(e.doc,i.anchor,i.head)}):t=>ge(e,t)||we(t));he(t.scroller,"contextmenu",t=>po(e,t)),he(t.input.getField(),"contextmenu",n=>{t.scroller.contains(n.target)||po(e,n)});let n,i={end:0};function r(){t.activeTouch&&(n=setTimeout(()=>t.activeTouch=null,1e3),i=t.activeTouch,i.end=+new Date)}function l(e,t){if(null==t.left)return!0;let n=t.left-e.left,i=t.top-e.top;return n*n+i*i>400}he(t.scroller,"touchstart",r=>{if(!ge(e,r)&&!function(e){if(1!=e.touches.length)return!1;let t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}(r)&&!fo(e,r)){t.input.ensurePolled(),clearTimeout(n);let e=+new Date;t.activeTouch={start:e,moved:!1,prev:e-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",()=>{t.activeTouch&&(t.activeTouch.moved=!0)}),he(t.scroller,"touchend",n=>{let i=t.activeTouch;if(i&&!xn(t,n)&&null!=i.left&&!i.moved&&new Date-i.start<300){let r,o=e.coordsChar(t.activeTouch,"page");r=!i.prev||l(i,i.prev)?new vr(o,o):!i.prev.prev||l(i,i.prev.prev)?e.findWordAt(o):new vr(Je(o.line,0),ot(e.doc,Je(o.line+1,0))),e.setSelection(r.anchor,r.head),e.focus(),we(n)}r()}),he(t.scroller,"touchcancel",r),he(t.scroller,"scroll",()=>{t.scroller.clientHeight&&(zi(e,t.scroller.scrollTop),Pi(e,t.scroller.scrollLeft,!0),pe(e,"scroll",e))}),he(t.scroller,"mousewheel",t=>br(e,t)),he(t.scroller,"DOMMouseScroll",t=>br(e,t)),he(t.wrapper,"scroll",()=>t.wrapper.scrollTop=t.wrapper.scrollLeft=0),t.dragFunctions={enter:t=>{ge(e,t)||Ce(t)},over:t=>{ge(e,t)||(!function(e,t){let n=ai(e,t);if(!n)return;let i=document.createDocumentFragment();yi(e,n,i),e.display.dragCursor||(e.display.dragCursor=A("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),e.display.lineSpace.insertBefore(e.display.dragCursor,e.display.cursorDiv)),N(e.display.dragCursor,i)}(e,t),Ce(t))},start:t=>function(e,t){if(o&&(!e.state.draggingText||+new Date-Nl<100))Ce(t);else if(!ge(e,t)&&!xn(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.effectAllowed="copyMove",t.dataTransfer.setDragImage&&!d)){let n=A("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:Zi(e,Al),leave:t=>{ge(e,t)||Ol(e)}};let a=t.input.getField();he(a,"keyup",t=>ro.call(e,t)),he(a,"keydown",Zi(e,io)),he(a,"keypress",Zi(e,lo)),he(a,"focus",t=>Si(e,t)),he(a,"blur",t=>ki(e,t))}(this),Hl(),_i(this),this.curOp.forceUpdate=!0,Wr(this,n),t.autofocus&&!y||this.hasFocus()?setTimeout(P(Si,this),20):ki(this);for(let e in bo)bo.hasOwnProperty(e)&&bo[e](this,t[e],mo);cr(this),t.finishInit&&t.finishInit(this);for(let e=0;e150)){if(!i)return;n="prev"}}else c=0,n="not";"prev"==n?c=t>l.first?I(Ke(l,t-1).text,null,o):0:"add"==n?c=a+e.options.indentUnit:"subtract"==n?c=a-e.options.indentUnit:"number"==typeof n&&(c=a+n),c=Math.max(0,c);let h="",d=0;if(e.options.indentWithTabs)for(let e=Math.floor(c/o);e;--e)d+=o,h+="\t";if(dCo.push(e);let ko=null;function Mo(e){ko=e}function Lo(e,t,n,i,r){let l=e.doc;e.display.shift=!1,i||(i=l.sel);let o=+new Date-200,s="paste"==r||e.state.pasteIncoming>o,a=Oe(t),c=null;if(s&&i.ranges.length>1)if(ko&&ko.text.join("\n")==t){if(i.ranges.length%ko.text.length==0){c=[];for(let e=0;e[e]));let u=e.curOp.updateInput;for(let u=i.ranges.length-1;u>=0;u--){let h=i.ranges[u],d=h.from(),f=h.to();h.empty()&&(n&&n>0?d=Je(d.line,d.ch-n):e.state.overwrite&&!s?f=Je(f.line,Math.min(Ke(l,f.line).text.length,f.ch+X(a).length)):s&&ko&&ko.lineWise&&ko.text.join("\n")==t&&(d=f=Je(d.line,0)));let p={from:d,to:f,text:c?c[u%c.length]:a,origin:r||(s?"paste":e.state.cutIncoming>o?"cut":"+input")};ol(e.doc,p),sn(e,"inputRead",e,p)}t&&!s&&No(e,t),Oi(e),e.curOp.updateInput<2&&(e.curOp.updateInput=u),e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=-1}function To(e,t){let n=e.clipboardData&&e.clipboardData.getData("Text");if(n)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||qi(t,()=>Lo(t,n,0,null,"paste")),!0}function No(e,t){if(!e.options.electricChars||!e.options.smartIndent)return;let n=e.doc.sel;for(let i=n.ranges.length-1;i>=0;i--){let r=n.ranges[i];if(r.head.ch>100||i&&n.ranges[i-1].head.line==r.head.line)continue;let l=e.getModeAt(r.head),o=!1;if(l.electricChars){for(let n=0;n-1){o=So(e,r.head.line,"smart");break}}else l.electricInput&&l.electricInput.test(Ke(e.doc,r.head.line).text.slice(0,r.head.ch))&&(o=So(e,r.head.line,"smart"));o&&sn(e,"electricInput",e,r.head.line)}}function Ao(e){let t=[],n=[];for(let i=0;i=t.text.length?(n.ch=t.text.length,n.sticky="before"):n.ch<=0&&(n.ch=0,n.sticky="after");let l=se(r,n.ch,n.sticky),o=r[l];if("ltr"==e.doc.direction&&o.level%2==0&&(i>0?o.to>n.ch:o.fromKl(t,e instanceof Je?e.ch:e,n),c=n=>e.options.lineWrapping?(s=s||Dn(e,t),Zn(e,t,s,n)):{begin:0,end:t.text.length},u=c("before"==n.sticky?a(n,-1):n.ch);if("rtl"==e.doc.direction||1==o.level){let e=1==o.level==i<0,t=a(n,e?1:-1);if(null!=t&&(e?t<=o.to&&t<=u.end:t>=o.from&&t>=u.begin)){let i=e?"before":"after";return new Je(n.line,t,i)}}let h=(e,t,i)=>{let l=(e,t)=>t?new Je(n.line,a(e,1),"before"):new Je(n.line,e,"after");for(;e>=0&&e0==(1!=n.level),s=o?i.begin:a(i.end,-1);if(n.from<=s&&s0?u.end:a(u.begin,-1);return null==f||i>0&&f==t.text.length||(d=h(i>0?0:r.length-1,i,c(f)),!d)?null:d}(e.cm,s,t,n):$l(s,t,n),null==l){if(i||!function(){let n=t.line+a;return!(n=e.first+e.size)&&(t=new Je(n,t.ch,t.sticky),s=Ke(e,n))}())return!1;t=jl(r,e.cm,s,t.line,a)}else t=l;return!0}if("char"==i)c();else if("column"==i)c(!0);else if("word"==i||"group"==i){let r=null,l="group"==i,o=e.cm&&e.cm.getHelper(t,"wordChars");for(let e=!0;!(n<0)||c(!e);e=!1){let i=s.text.charAt(t.ch)||"\n",a=ee(i,o)?"w":l&&"\n"==i?"n":!l||/\s/.test(i)?null:"p";if(!l||e||a||(a="s"),r&&r!=a){n<0&&(n=1,c(),t.sticky="after");break}if(a&&(r=a),n>0&&!c(!e))break}}let u=nl(e,t,l,o,!0);return tt(l,u)&&(u.hitSide=!0),u}function Ho(e,t,n,i){let r,l,o=e.doc,s=t.left;if("page"==i){let i=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),l=Math.max(i-.5*ni(e.display),3);r=(n>0?t.bottom:t.top)+n*l}else"line"==i&&(r=n>0?t.bottom+3:t.top-3);for(;l=Yn(e,s,r),l.outside;){if(n<0?r<=0:r>=o.height){l.hitSide=!0;break}r+=5*n}return l}class zo{constructor(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new R,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null}init(e){let t=this,n=t.cm,i=t.div=e.lineDiv;function r(e){if(ge(n,e))return;if(n.somethingSelected())Mo({lineWise:!1,text:n.getSelections()}),"cut"==e.type&&n.replaceSelection("",null,"cut");else{if(!n.options.lineWiseCopyCut)return;{let t=Ao(n);Mo({lineWise:!0,text:t.text}),"cut"==e.type&&n.operation(()=>{n.setSelections(t.ranges,0,U),n.replaceSelection("",null,"cut")})}}if(e.clipboardData){e.clipboardData.clearData();let t=ko.text.join("\n");if(e.clipboardData.setData("Text",t),e.clipboardData.getData("Text")==t)return void e.preventDefault()}let r=Do(),l=r.firstChild;n.display.lineSpace.insertBefore(r,n.display.lineSpace.firstChild),l.value=ko.text.join("\n");let o=document.activeElement;F(l),setTimeout(()=>{n.display.lineSpace.removeChild(r),o.focus(),o==i&&t.showPrimarySelection()},50)}Oo(i,n.options.spellcheck,n.options.autocorrect,n.options.autocapitalize),he(i,"paste",e=>{ge(n,e)||To(e,n)||s<=11&&setTimeout(Zi(n,()=>this.updateFromDOM()),20)}),he(i,"compositionstart",e=>{this.composing={data:e.data,done:!1}}),he(i,"compositionupdate",e=>{this.composing||(this.composing={data:e.data,done:!1})}),he(i,"compositionend",e=>{this.composing&&(e.data!=this.composing.data&&this.readFromDOMSoon(),this.composing.done=!0)}),he(i,"touchstart",()=>t.forceCompositionEnd()),he(i,"input",()=>{this.composing||this.readFromDOMSoon()}),he(i,"copy",r),he(i,"cut",r)}prepareSelection(){let e=mi(this.cm,!1);return e.focus=document.activeElement==this.div,e}showSelection(e,t){e&&this.cm.display.view.length&&((e.focus||t)&&this.showPrimarySelection(),this.showMultipleSelections(e))}getSelection(){return this.cm.display.wrapper.ownerDocument.getSelection()}showPrimarySelection(){let e=this.getSelection(),t=this.cm,i=t.doc.sel.primary(),r=i.from(),l=i.to();if(t.display.viewTo==t.display.viewFrom||r.line>=t.display.viewTo||l.line=t.display.viewFrom&&Fo(t,r)||{node:a[0].measure.map[2],offset:0},u=l.line{this.gracePeriod=!1,this.selectionChanged()&&this.cm.operation(()=>this.cm.curOp.selectionChanged=!0)},20)}showMultipleSelections(e){N(this.cm.display.cursorDiv,e.cursors),N(this.cm.display.selectionDiv,e.selection)}rememberSelection(){let e=this.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset}selectionInEditor(){let e=this.getSelection();if(!e.rangeCount)return!1;let t=e.getRangeAt(0).commonAncestorContainer;return D(this.div,t)}focus(){"nocursor"!=this.cm.options.readOnly&&(this.selectionInEditor()&&document.activeElement==this.div||this.showSelection(this.prepareSelection(),!0),this.div.focus())}blur(){this.div.blur()}getField(){return this.div}supportsTouch(){return!0}receivedFocus(){let e=this;this.selectionInEditor()?this.pollSelection():qi(this.cm,()=>e.cm.curOp.selectionChanged=!0),this.polling.set(this.cm.options.pollInterval,(function t(){e.cm.state.focused&&(e.pollSelection(),e.polling.set(e.cm.options.pollInterval,t))}))}selectionChanged(){let e=this.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset}pollSelection(){if(null!=this.readDOMTimeout||this.gracePeriod||!this.selectionChanged())return;let e=this.getSelection(),t=this.cm;if(m&&u&&this.cm.display.gutterSpecs.length&&function(e){for(let 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)return;this.rememberSelection();let n=Eo(t,e.anchorNode,e.anchorOffset),i=Eo(t,e.focusNode,e.focusOffset);n&&i&&qi(t,()=>{qr(t.doc,Cr(n,i),U),(n.bad||i.bad)&&(t.curOp.selectionChanged=!0)})}pollContent(){null!=this.readDOMTimeout&&(clearTimeout(this.readDOMTimeout),this.readDOMTimeout=null);let e,t,n,i=this.cm,r=i.display,l=i.doc.sel.primary(),o=l.from(),s=l.to();if(0==o.ch&&o.line>i.firstLine()&&(o=Je(o.line-1,Ke(i.doc,o.line-1).length)),s.ch==Ke(i.doc,s.line).text.length&&s.liner.viewTo-1)return!1;o.line==r.viewFrom||0==(e=ci(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);let a,c,u=ci(i,s.line);if(u==r.view.length-1?(a=r.viewTo-1,c=r.lineDiv.lastChild):(a=Ye(r.view[u+1].line)-1,c=r.view[u+1].node.previousSibling),!n)return!1;let h=i.doc.splitLines(function(e,t,n,i,r){let l="",o=!1,s=e.doc.lineSeparator(),a=!1;function c(){o&&(l+=s,a&&(l+=s),o=a=!1)}function u(e){e&&(c(),l+=e)}function h(t){if(1==t.nodeType){let l=t.getAttribute("cm-text");if(l)return void u(l);let d,f=t.getAttribute("cm-marker");if(f){let t=e.findMarks(Je(i,0),Je(r+1,0),(n=+f,e=>e.id==n));return void(t.length&&(d=t[0].find(0))&&u($e(e.doc,d.from,d.to).join(s)))}if("false"==t.getAttribute("contenteditable"))return;let p=/^(pre|div|p|li|table|br)$/i.test(t.nodeName);if(!/^br$/i.test(t.nodeName)&&0==t.textContent.length)return;p&&c();for(let e=0;e1&&d.length>1;)if(X(h)==X(d))h.pop(),d.pop(),a--;else{if(h[0]!=d[0])break;h.shift(),d.shift(),t++}let f=0,p=0,g=h[0],m=d[0],y=Math.min(g.length,m.length);for(;fo.ch&&b.charCodeAt(b.length-p-1)==w.charCodeAt(w.length-p-1);)f--,p++;h[h.length-1]=b.slice(0,b.length-p).replace(/^\u200b+/,""),h[0]=h[0].slice(f).replace(/\u200b+$/,"");let x=Je(t,f),C=Je(a,d.length?X(d).length-p:0);return h.length>1||h[0]||et(x,C)?(hl(i.doc,h,x,C,"+input"),!0):void 0}ensurePolled(){this.forceCompositionEnd()}reset(){this.forceCompositionEnd()}forceCompositionEnd(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())}readFromDOMSoon(){null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout(()=>{if(this.readDOMTimeout=null,this.composing){if(!this.composing.done)return;this.composing=null}this.updateFromDOM()},80))}updateFromDOM(){!this.cm.isReadOnly()&&this.pollContent()||qi(this.cm,()=>ui(this.cm))}setUneditable(e){e.contentEditable="false"}onKeyPress(e){0==e.charCode||this.composing||(e.preventDefault(),this.cm.isReadOnly()||Zi(this.cm,Lo)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0))}readOnlyChanged(e){this.div.contentEditable=String("nocursor"!=e)}onContextMenu(){}resetPosition(){}}function Fo(e,t){let n=On(e,t.line);if(!n||n.hidden)return null;let i=Ke(e.doc,t.line),r=Nn(n,i,t.line),l=ce(i,e.doc.direction),o="left";if(l){o=se(l,t.ch)%2?"right":"left"}let s=Fn(r.map,t.ch,o);return s.offset="right"==s.collapse?s.end:s.start,s}function Po(e,t){return t&&(e.bad=!0),e}function Eo(e,t,n){let i;if(t==e.display.lineDiv){if(i=e.display.lineDiv.childNodes[n],!i)return Po(e.clipPos(Je(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(let r=0;r{o&&s>=9&&this.hasSelection&&(this.hasSelection=null),t.poll()}),he(i,"paste",e=>{ge(n,e)||To(e,n)||(n.state.pasteIncoming=+new Date,t.fastPoll())}),he(i,"cut",r),he(i,"copy",r),he(e.scroller,"paste",r=>{if(xn(e,r)||ge(n,r))return;if(!i.dispatchEvent)return n.state.pasteIncoming=+new Date,void t.focus();const l=new Event("paste");l.clipboardData=r.clipboardData,i.dispatchEvent(l)}),he(e.lineSpace,"selectstart",t=>{xn(e,t)||we(t)}),he(i,"compositionstart",()=>{let e=n.getCursor("from");t.composing&&t.composing.range.clear(),t.composing={start:e,range:n.markText(e,n.getCursor("to"),{className:"CodeMirror-composing"})}}),he(i,"compositionend",()=>{t.composing&&(t.poll(),t.composing.range.clear(),t.composing=null)})}createField(e){this.wrapper=Do(),this.textarea=this.wrapper.firstChild}prepareSelection(){let e=this.cm,t=e.display,n=e.doc,i=mi(e);if(e.options.moveInputWithCursor){let r=$n(e,n.sel.primary().head,"div"),l=t.wrapper.getBoundingClientRect(),o=t.lineDiv.getBoundingClientRect();i.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,r.top+o.top-l.top)),i.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,r.left+o.left-l.left))}return i}showSelection(e){let t=this.cm.display;N(t.cursorDiv,e.cursors),N(t.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")}reset(e){if(this.contextMenuPending||this.composing)return;let t=this.cm;if(t.somethingSelected()){this.prevInput="";let e=t.getSelection();this.textarea.value=e,t.state.focused&&F(this.textarea),o&&s>=9&&(this.hasSelection=e)}else e||(this.prevInput=this.textarea.value="",o&&s>=9&&(this.hasSelection=null))}getField(){return this.textarea}supportsTouch(){return!1}focus(){if("nocursor"!=this.cm.options.readOnly&&(!y||W()!=this.textarea))try{this.textarea.focus()}catch(e){}}blur(){this.textarea.blur()}resetPosition(){this.wrapper.style.top=this.wrapper.style.left=0}receivedFocus(){this.slowPoll()}slowPoll(){this.pollingFast||this.polling.set(this.cm.options.pollInterval,()=>{this.poll(),this.cm.state.focused&&this.slowPoll()})}fastPoll(){let 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))}))}poll(){let e=this.cm,t=this.textarea,n=this.prevInput;if(this.contextMenuPending||!e.state.focused||De(t)&&!n&&!this.composing||e.isReadOnly()||e.options.disableInput||e.state.keySeq)return!1;let i=t.value;if(i==n&&!e.somethingSelected())return!1;if(o&&s>=9&&this.hasSelection===i||b&&/[\uf700-\uf7ff]/.test(i))return e.display.input.reset(),!1;if(e.doc.sel==e.display.selForContextMenu){let e=i.charCodeAt(0);if(8203!=e||n||(n="​"),8666==e)return this.reset(),this.cm.execCommand("undo")}let r=0,l=Math.min(n.length,i.length);for(;r{Lo(e,i.slice(r),n.length-r,null,this.composing?"*compose":null),i.length>1e3||i.indexOf("\n")>-1?t.value=this.prevInput="":this.prevInput=i,this.composing&&(this.composing.range.clear(),this.composing.range=e.markText(this.composing.start,e.getCursor("to"),{className:"CodeMirror-composing"}))}),!0}ensurePolled(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)}onKeyPress(){o&&s>=9&&(this.hasSelection=null),this.fastPoll()}onContextMenu(e){let t=this,n=t.cm,i=n.display,r=t.textarea;t.contextMenuPending&&t.contextMenuPending();let l=ai(n,e),c=i.scroller.scrollTop;if(!l||h)return;n.options.resetSelectionOnContextMenu&&-1==n.doc.sel.contains(l)&&Zi(n,qr)(n.doc,Cr(l),U);let u,d=r.style.cssText,f=t.wrapper.style.cssText,p=t.wrapper.offsetParent.getBoundingClientRect();function g(){if(null!=r.selectionStart){let e=n.somethingSelected(),l="​"+(e?r.value:"");r.value="⇚",r.value=l,t.prevInput=e?"":"​",r.selectionStart=1,r.selectionEnd=l.length,i.selForContextMenu=n.doc.sel}}function m(){if(t.contextMenuPending==m&&(t.contextMenuPending=!1,t.wrapper.style.cssText=f,r.style.cssText=d,o&&s<9&&i.scrollbars.setScrollTop(i.scroller.scrollTop=c),null!=r.selectionStart)){(!o||o&&s<9)&&g();let e=0,l=()=>{i.selForContextMenu==n.doc.sel&&0==r.selectionStart&&r.selectionEnd>0&&"​"==t.prevInput?Zi(n,rl)(n):e++<10?i.detectingSelectAll=setTimeout(l,500):(i.selForContextMenu=null,i.input.reset())};i.detectingSelectAll=setTimeout(l,200)}}if(t.wrapper.style.cssText="position: static",r.style.cssText=`position: absolute; width: 30px; height: 30px;\n top: ${e.clientY-p.top-5}px; left: ${e.clientX-p.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);`,a&&(u=window.scrollY),i.input.focus(),a&&window.scrollTo(null,u),i.input.reset(),n.somethingSelected()||(r.value=t.prevInput=" "),t.contextMenuPending=m,i.selForContextMenu=n.doc.sel,clearTimeout(i.detectingSelectAll),o&&s>=9&&g(),S){Ce(e);let t=()=>{fe(window,"mouseup",t),setTimeout(m,20)};he(window,"mouseup",t)}else setTimeout(m,50)}readOnlyChanged(e){e||this.reset(),this.textarea.disabled="nocursor"==e}setUneditable(){}}Ro.prototype.needsContentAttribute=!1,function(e){let t=e.optionHandlers;function n(n,i,r,l){e.defaults[n]=i,r&&(t[n]=l?(e,t,n)=>{n!=mo&&r(e,t,n)}:r)}e.defineOption=n,e.Init=mo,n("value","",(e,t)=>e.setValue(t),!0),n("mode",null,(e,t)=>{e.doc.modeOption=t,Tr(e)},!0),n("indentUnit",2,Tr,!0),n("indentWithTabs",!1),n("smartIndent",!0),n("tabSize",4,e=>{Nr(e),Rn(e),ui(e)},!0),n("lineSeparator",null,(e,t)=>{if(e.doc.lineSep=t,!t)return;let n=[],i=e.doc.first;e.doc.iter(e=>{for(let r=0;;){let l=e.text.indexOf(t,r);if(-1==l)break;r=l+t.length,n.push(Je(i,l))}i++});for(let i=n.length-1;i>=0;i--)hl(e.doc,t,n[i],Je(n[i].line,n[i].ch+t.length))}),n("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g,(e,t,n)=>{e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),n!=mo&&e.refresh()}),n("specialCharPlaceholder",Zt,e=>e.refresh(),!0),n("electricChars",!0),n("inputStyle",y?"contenteditable":"textarea",()=>{throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),n("spellcheck",!1,(e,t)=>e.getInputField().spellcheck=t,!0),n("autocorrect",!1,(e,t)=>e.getInputField().autocorrect=t,!0),n("autocapitalize",!1,(e,t)=>e.getInputField().autocapitalize=t,!0),n("rtlMoveVisually",!v),n("wholeLineUpdateBefore",!0),n("theme","default",e=>{go(e),dr(e)},!0),n("keyMap","default",(e,t,n)=>{let i=_l(t),r=n!=mo&&_l(n);r&&r.detach&&r.detach(e,i),i.attach&&i.attach(e,r||null)}),n("extraKeys",null),n("configureMouse",null),n("lineWrapping",!1,vo,!0),n("gutters",[],(e,t)=>{e.display.gutterSpecs=ur(t,e.options.lineNumbers),dr(e)},!0),n("fixedGutter",!0,(e,t)=>{e.display.gutters.style.left=t?li(e.display)+"px":"0",e.refresh()},!0),n("coverGutterNextToScrollbar",!1,e=>Ii(e),!0),n("scrollbarStyle","native",e=>{Gi(e),Ii(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),n("lineNumbers",!1,(e,t)=>{e.display.gutterSpecs=ur(e.options.gutters,t),dr(e)},!0),n("firstLineNumber",1,dr,!0),n("lineNumberFormatter",e=>e,dr,!0),n("showCursorWhenSelecting",!1,gi,!0),n("resetSelectionOnContextMenu",!0),n("lineWiseCopyCut",!0),n("pasteLinesPerSelection",!0),n("selectionsMayTouch",!1),n("readOnly",!1,(e,t)=>{"nocursor"==t&&(ki(e),e.display.input.blur()),e.display.input.readOnlyChanged(t)}),n("disableInput",!1,(e,t)=>{t||e.display.input.reset()},!0),n("dragDrop",!0,wo),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,Nr,!0),n("addModeClass",!1,Nr,!0),n("pollInterval",100),n("undoDepth",200,(e,t)=>e.doc.history.undoDepth=t),n("historyEventDelay",1250),n("viewportMargin",10,e=>e.refresh(),!0),n("maxHighlightLength",1e4,Nr,!0),n("moveInputWithCursor",!0,(e,t)=>{t||e.display.input.resetPosition()}),n("tabindex",null,(e,t)=>e.display.input.getField().tabIndex=t||""),n("autofocus",null),n("direction","ltr",(e,t)=>e.doc.setDirection(t),!0),n("phrases",null)}(xo),function(e){let t=e.optionHandlers,n=e.helpers={};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,n){let i=this.options,r=i[e];i[e]==n&&"mode"!=e||(i[e]=n,t.hasOwnProperty(e)&&Zi(this,t[e])(this,n,r),pe(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"](_l(e))},removeKeyMap:function(e){let t=this.state.keyMaps;for(let n=0;ne.priority),this.state.modeGen++,ui(this)})),removeOverlay:Qi((function(e){let t=this.state.overlays;for(let n=0;nn&&(So(this,r.head.line,e,!0),n=r.head.line,i==this.doc.sel.primIndex&&Oi(this));else{let l=r.from(),o=r.to(),s=Math.max(n,l.line);n=Math.min(this.lastLine(),o.line-(o.ch?0:1))+1;for(let t=s;t0&&jr(this.doc,i,new vr(l,a[i].to()),U)}}})),getTokenAt:function(e,t){return yt(this,e,t)},getLineTokens:function(e,t){return yt(this,Je(e),t,!0)},getTokenTypeAt:function(e){e=ot(this.doc,e);let t,n=ht(this,Ke(this.doc,e.line)),i=0,r=(n.length-1)/2,l=e.ch;if(0==l)t=n[2];else for(;;){let e=i+r>>1;if((e?n[2*e-1]:0)>=l)r=e;else{if(!(n[2*e+1]t&&(e=t,r=!0),i=Ke(this.doc,e)}else i=e;return _n(this,i,{top:0,left:0},t||"page",n||r).top+(r?this.doc.height-Ut(i):0)},defaultTextHeight:function(){return ni(this.display)},defaultCharWidth:function(){return ii(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,n,i,r){let l=this.display,o=(e=$n(this,ot(this.doc,e))).bottom,s=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),l.sizer.appendChild(t),"over"==i)o=e.top;else if("above"==i||"near"==i){let n=Math.max(l.wrapper.clientHeight,this.doc.height),r=Math.max(l.sizer.clientWidth,l.lineSpace.clientWidth);("above"==i||e.bottom+t.offsetHeight>n)&&e.top>t.offsetHeight?o=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=n&&(o=e.bottom),s+t.offsetWidth>r&&(s=r-t.offsetWidth)}t.style.top=o+"px",t.style.left=t.style.right="","right"==r?(s=l.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==r?s=0:"middle"==r&&(s=(l.sizer.clientWidth-t.offsetWidth)/2),t.style.left=s+"px"),n&&function(e,t){let n=Ni(e,t);null!=n.scrollTop&&zi(e,n.scrollTop),null!=n.scrollLeft&&Pi(e,n.scrollLeft)}(this,{left:s,top:o,right:s+t.offsetWidth,bottom:o+t.offsetHeight})},triggerOnKeyDown:Qi(io),triggerOnKeyPress:Qi(lo),triggerOnKeyUp:ro,triggerOnMouseDown:Qi(co),execCommand:function(e){if(Xl.hasOwnProperty(e))return Xl[e].call(null,this)},triggerElectric:Qi((function(e){No(this,e)})),findPosH:function(e,t,n,i){let r=1;t<0&&(r=-1,t=-t);let l=ot(this.doc,e);for(let e=0;ethis.display.shift||this.doc.extend||n.empty()?Wo(this.doc,n.head,e,t,this.options.rtlMoveVisually):e<0?n.from():n.to(),V)})),deleteH:Qi((function(e,t){let n=this.doc.sel,i=this.doc;n.somethingSelected()?i.replaceSelection("",null,"+delete"):Vl(this,n=>{let r=Wo(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){let r=1,l=i;t<0&&(r=-1,t=-t);let o=ot(this.doc,e);for(let e=0;e{if(r)return e<0?l.from():l.to();let o=$n(this,l.head,"div");null!=l.goalColumn&&(o.left=l.goalColumn),i.push(o.left);let s=Ho(this,o,e,t);return"page"==t&&l==n.sel.primary()&&Ai(this,Kn(this,s,"div").top-o.top),s},V),i.length)for(let e=0;eee(e,r):/\s/.test(l)?e=>/\s/.test(e):e=>!/\s/.test(e)&&!ee(e);for(;n>0&&o(t.charAt(n-1));)--n;for(;i"number"==typeof e||/^\d+$/.test(String(e))?e+"px":e;null!=e&&(this.display.wrapper.style.width=n(e)),null!=t&&(this.display.wrapper.style.height=n(t)),this.options.lineWrapping&&In(this);let i=this.display.viewFrom;this.doc.iter(i,this.display.viewTo,e=>{if(e.widgets)for(let t=0;t.5)&&si(this),pe(this,"refresh",this)})),swapDoc:Qi((function(e){let t=this.doc;return t.cm=null,this.state.selectingText&&this.state.selectingText(),Wr(this,e),Rn(this),this.display.input.reset(),Di(this,e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,sn(this,"swapDoc",this,t),t})),phrase:function(e){let 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}},be(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,l){e.registerHelper(t,i,l),n[t]._global.push({pred:r,val:l})}}(xo);let Bo="iter insert remove copy getEditor constructor".split(" ");for(let e in Tl.prototype)Tl.prototype.hasOwnProperty(e)&&B(Bo,e)<0&&(xo.prototype[e]=function(e){return function(){return e.apply(this.doc,arguments)}}(Tl.prototype[e]));be(Tl),xo.inputStyles={textarea:Ro,contenteditable:zo},xo.defineMode=function(e){xo.defaults.mode||"null"==e||(xo.defaults.mode=e),Pe.apply(this,arguments)},xo.defineMIME=function(e,t){Fe[e]=t},xo.defineMode("null",()=>({token:e=>e.skipToEnd()})),xo.defineMIME("text/plain","null"),xo.defineExtension=(e,t)=>{xo.prototype[e]=t},xo.defineDocExtension=(e,t)=>{Tl.prototype[e]=t},xo.fromTextArea=function(e,t){if((t=t?E(t):{}).value=e.value,!t.tabindex&&e.tabIndex&&(t.tabindex=e.tabIndex),!t.placeholder&&e.placeholder&&(t.placeholder=e.placeholder),null==t.autofocus){let n=W();t.autofocus=n==e||null!=e.getAttribute("autofocus")&&n==document.body}function n(){e.value=r.getValue()}let i;if(e.form&&(he(e.form,"submit",n),!t.leaveSubmitMethodAlone)){let t=e.form;i=t.submit;try{let e=t.submit=()=>{n(),t.submit=i,t.submit(),t.submit=e}}catch(e){}}t.finishInit=r=>{r.save=n,r.getTextArea=()=>e,r.toTextArea=()=>{r.toTextArea=isNaN,n(),e.parentNode.removeChild(r.getWrapperElement()),e.style.display="",e.form&&(fe(e.form,"submit",n),t.leaveSubmitMethodAlone||"function"!=typeof e.form.submit||(e.form.submit=i))}},e.style.display="none";let r=xo(t=>e.parentNode.insertBefore(t,e.nextSibling),t);return r},function(e){e.off=fe,e.on=he,e.wheelEventPixels=yr,e.Doc=Tl,e.splitLines=Oe,e.countColumn=I,e.findColumn=K,e.isWordChar=J,e.Pass=G,e.signal=pe,e.Line=Kt,e.changeEnd=Sr,e.scrollbarModel=Bi,e.Pos=Je,e.cmpPos=et,e.modes=ze,e.mimeModes=Fe,e.resolveMode=Ee,e.getMode=Ie,e.modeExtensions=Re,e.extendMode=Be,e.copyState=Ge,e.startState=_e,e.innerMode=Ue,e.commands=Xl,e.keyMap=Pl,e.keyName=Ul,e.isModifierKey=Bl,e.lookupKey=Rl,e.normalizeKeyMap=Il,e.StringStream=Ve,e.SharedTextMarker=Sl,e.TextMarker=xl,e.LineWidget=bl,e.e_preventDefault=we,e.e_stopPropagation=ve,e.e_stop=Ce,e.addClass=H,e.contains=D,e.rmClass=L,e.keyNames=Fl}(xo),xo.version="5.52.2",self.CodeMirror=xo;class Go extends HTMLElement{static get observedAttributes(){return["src","value"]}attributeChangedCallback(e,t,n){this.__initialized&&t!==n&&(this[e]=n)}get src(){return this.getAttribute("src")}set src(e){this.setAttribute("src",e),this.setSrc(),this.__editor.refresh()}get value(){return this.__editor.getValue()}set value(e){this.__editor.swapDoc(xo.Doc(e),this.getAttribute("mode"))}constructor(){super();const e=document.createElement("template");e.innerHTML=Go.template(),this.appendChild(e.content.cloneNode(!0)),this.__initialized=!1,this.__element=null,this.__editor=null}async connectedCallback(){if(this.__element=this.querySelector("#code"),this.__element.style=this.hasAttribute("style")?this.style.cssText:"width:100%;height:100%",this.appendChild(this.__element),this.hasAttribute("src")){const e=this.getAttribute("src");this.__element.value=await this.fetchSrc(e)}else this.__element.value="";const e=this.getAttribute("mode")||"null",t=this.getAttribute("theme")||"default";this.__editor=xo.fromTextArea(this.__element,{lineNumbers:!0,readOnly:!1,mode:e,theme:t}),this.__initialized=!0}async setSrc(){const e=this.getAttribute("src"),t=await this.fetchSrc(e);this.__editor.swapDoc(xo.Doc(t,this.getAttribute("mode")))}async fetchSrc(e){return(await fetch(e)).text()}static template(){return"\n \n \n \n "}}customElements.define("wc-codemirror",Go);export{Go as WCCodeMirror}; +let 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),l=/Edge\/(\d+)/.exec(e),o=i||r||l,s=o&&(i?document.documentMode||6:+(l||r)[1]),a=!l&&/WebKit\//.test(e),c=a&&/Qt\/\d+\.\d+/.test(e),u=!l&&/Chrome\//.test(e),h=/Opera\//.test(e),d=/Apple Computer/.test(navigator.vendor),f=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(e),p=/PhantomJS/.test(e),g=!l&&/AppleWebKit/.test(e)&&/Mobile\/\w+/.test(e),m=/Android/.test(e),y=g||m||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(e),b=g||/Mac/.test(t),w=/\bCrOS\b/.test(e),v=/win/i.test(t),x=h&&e.match(/Version\/(\d*\.\d*)/);x&&(x=Number(x[1])),x&&x>=15&&(h=!1,a=!0);let C=b&&(c||h&&(null==x||x<12.11)),S=n||o&&s>=9;function k(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}let M,L=function(e,t){let n=e.className,i=k(t).exec(n);if(i){let t=n.slice(i.index+i[0].length);e.className=n.slice(0,i.index)+(t?i[1]+t:"")}};function T(e){for(let t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function N(e,t){return T(e).appendChild(t)}function A(e,t,n,i){let 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(let e=0;e=t)return o+(t-l);o+=i-l,o+=n-o%n,l=i+1}}g?F=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:o&&(F=function(e){try{e.select()}catch(e){}});class R{constructor(){this.id=null,this.f=null,this.time=0,this.handler=P(this.onTimeout,this)}onTimeout(e){e.id=0,e.time<=+new Date?e.f():setTimeout(e.handler,e.time-+new Date)}set(e,t){this.f=t;const n=+new Date+e;(!this.id||n=t)return i+Math.min(o,t-r);if(r+=l-i,r+=n-r%n,i=l+1,r>=t)return i}}let $=[""];function j(e){for(;$.length<=e;)$.push(X($)+" ");return $[e]}function X(e){return e[e.length-1]}function Y(e,t){let n=[];for(let i=0;i"€"&&(e.toUpperCase()!=e.toLowerCase()||Q.test(e))}function ee(e,t){return t?!!(t.source.indexOf("\\w")>-1&&J(e))||t.test(e):J(e)}function te(e){for(let t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}let 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:tn?-1:1;for(;;){if(t==n)return t;let r=(t+n)/2,l=i<0?Math.ceil(r):Math.floor(r);if(l==t)return e(l)?t:n;e(l)?n=l:t=l+i}}let oe=null;function se(e,t,n){let i;oe=null;for(let r=0;rt)return r;l.to==t&&(l.from!=l.to&&"before"==n?i=r:oe=r),l.from==t&&(l.from!=l.to&&"before"!=n?i=r:oe=r)}return null!=i?i:oe}let ae=function(){let e=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,t=/[stwN]/,n=/[LRr]/,i=/[Lb1n]/,r=/[1n]/;function l(e,t,n){this.level=e,this.from=t,this.to=n}return function(o,s){let a="ltr"==s?"L":"R";if(0==o.length||"ltr"==s&&!e.test(o))return!1;let c=o.length,u=[];for(let e=0;e-1&&(i[t]=r.slice(0,e).concat(r.slice(e+1)))}}}function pe(e,t){let n=de(e,t);if(!n.length)return;let i=Array.prototype.slice.call(arguments,2);for(let e=0;e0}function be(e){e.prototype.on=function(e,t){he(this,e,t)},e.prototype.off=function(e,t){fe(this,e,t)}}function we(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function ve(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function xe(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function Ce(e){we(e),ve(e)}function Se(e){return e.target||e.srcElement}function ke(e){let t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),b&&e.ctrlKey&&1==t&&(t=3),t}let Me,Le,Te=function(){if(o&&s<9)return!1;let e=A("div");return"draggable"in e||"dragDrop"in e}();function Ne(e){if(null==Me){let t=A("span","​");N(e,A("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(Me=t.offsetWidth<=1&&t.offsetHeight>2&&!(o&&s<8))}let t=Me?A("span","​"):A("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return t.setAttribute("cm-text",""),t}function Ae(e){if(null!=Le)return Le;let t=N(e,document.createTextNode("AخA")),n=M(t,0,1).getBoundingClientRect(),i=M(t,1,2).getBoundingClientRect();return T(e),!(!n||n.left==n.right)&&(Le=i.right-n.right<3)}let Oe=3!="\n\nb".split(/\n/).length?e=>{let t=0,n=[],i=e.length;for(;t<=i;){let i=e.indexOf("\n",t);-1==i&&(i=e.length);let r=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),l=r.indexOf("\r");-1!=l?(n.push(r.slice(0,l)),t+=l+1):(n.push(r),t=i+1)}return n}:e=>e.split(/\r\n?|\n/),De=window.getSelection?e=>{try{return e.selectionStart!=e.selectionEnd}catch(e){return!1}}:e=>{let t;try{t=e.ownerDocument.selection.createRange()}catch(e){}return!(!t||t.parentElement()!=e)&&0!=t.compareEndPoints("StartToEnd",t)},We=(()=>{let e=A("div");return"oncopy"in e||(e.setAttribute("oncopy","return;"),"function"==typeof e.oncopy)})(),He=null;let ze={},Fe={};function Pe(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),ze[e]=t}function Ee(e){if("string"==typeof e&&Fe.hasOwnProperty(e))e=Fe[e];else if(e&&"string"==typeof e.name&&Fe.hasOwnProperty(e.name)){let t=Fe[e.name];"string"==typeof t&&(t={name:t}),(e=Z(t,e)).name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return Ee("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return Ee("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function Ie(e,t){t=Ee(t);let n=ze[t.name];if(!n)return Ie(e,"text/plain");let i=n(e,t);if(Re.hasOwnProperty(t.name)){let e=Re[t.name];for(let t in e)e.hasOwnProperty(t)&&(i.hasOwnProperty(t)&&(i["_"+t]=i[t]),i[t]=e[t])}if(i.name=t.name,t.helperType&&(i.helperType=t.helperType),t.modeProps)for(let e in t.modeProps)i[e]=t.modeProps[e];return i}let Re={};function Be(e,t){E(t,Re.hasOwnProperty(e)?Re[e]:Re[e]={})}function Ge(e,t){if(!0===t)return t;if(e.copyState)return e.copyState(t);let n={};for(let e in t){let i=t[e];i instanceof Array&&(i=i.concat([])),n[e]=i}return n}function Ue(e,t){let n;for(;e.innerMode&&(n=e.innerMode(t),n&&n.mode!=e);)t=n.state,e=n.mode;return n||{mode:e,state:t}}function Ve(e,t,n){return!e.startState||e.startState(t,n)}class _e{constructor(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}eol(){return this.pos>=this.string.length}sol(){return this.pos==this.lineStart}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.post}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos0?null:(n&&!1!==t&&(this.pos+=n[0].length),n)}{let i=e=>n?e.toLowerCase():e;if(i(this.string.substr(this.pos,e.length))==i(e))return!1!==t&&(this.pos+=e.length),!0}}current(){return this.string.slice(this.start,this.pos)}hideFirstChars(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}}lookAhead(e){let t=this.lineOracle;return t&&t.lookAhead(e)}baseToken(){let e=this.lineOracle;return e&&e.baseToken(this.pos)}}function Ke(e,t){if((t-=e.first)<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");let n=e;for(;!n.lines;)for(let e=0;;++e){let i=n.children[e],r=i.chunkSize();if(t{let l=e.text;r==n.line&&(l=l.slice(0,n.ch)),r==t.line&&(l=l.slice(t.ch)),i.push(l),++r}),i}function je(e,t,n){let i=[];return e.iter(t,n,e=>{i.push(e.text)}),i}function Xe(e,t){let n=t-e.height;if(n)for(let t=e;t;t=t.parent)t.height+=n}function Ye(e){if(null==e.parent)return null;let t=e.parent,n=B(t.lines,e);for(let e=t.parent;e;t=e,e=e.parent)for(let i=0;e.children[i]!=t;++i)n+=e.children[i].chunkSize();return n+t.first}function qe(e,t){let n=e.first;e:do{for(let i=0;i=e.first&&tn?Je(n,Ke(e,n).text.length):function(e,t){let n=e.ch;return null==n||n>t?Je(e.line,t):n<0?Je(e.line,0):e}(t,Ke(e,t.line).text.length)}function st(e,t){let n=[];for(let i=0;ithis.maxLookAhead&&(this.maxLookAhead=e),t}baseToken(e){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=e;)this.baseTokenPos+=2;let t=this.baseTokens[this.baseTokenPos+1];return{type:t&&t.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}}nextLine(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--}static fromSaved(e,t,n){return t instanceof at?new ct(e,Ge(e.mode,t.state),n,t.lookAhead):new ct(e,Ge(e.mode,t),n)}save(e){let t=!1!==e?Ge(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new at(t,this.maxLookAhead):t}}function ut(e,t,n,i){let r=[e.state.modeGen],l={};wt(e,t.text,e.doc.mode,n,(e,t)=>r.push(e,t),l,i);let o=n.state;for(let i=0;i{let n=a;for(;ce&&r.splice(a,1,e,r[a+1],t),a+=2,c=Math.min(e,t)}if(t)if(s.opaque)r.splice(n,a-n,e,"overlay "+t),a=n+2;else for(;ne.options.maxHighlightLength&&Ge(e.doc.mode,i.state),l=ut(e,t,i);r&&(i.state=r),t.stateAfter=i.save(!r),t.styles=l.styles,l.classes?t.styleClasses=l.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 dt(e,t,n){let i=e.doc,r=e.display;if(!i.mode.startState)return new ct(i,!0,t);let l=function(e,t,n){let i,r,l=e.doc,o=n?-1:t-(e.doc.mode.innerMode?1e3:100);for(let s=t;s>o;--s){if(s<=l.first)return l.first;let t=Ke(l,s-1),o=t.stateAfter;if(o&&(!n||s+(o instanceof at?o.lookAhead:0)<=l.modeFrontier))return s;let a=I(t.text,null,e.options.tabSize);(null==r||i>a)&&(r=s-1,i=a)}return r}(e,t,n),o=l>i.first&&Ke(i,l-1).stateAfter,s=o?ct.fromSaved(i,o,l):new ct(i,Ve(i.mode),l);return i.iter(l,t,n=>{ft(e,n.text,s);let i=s.line;n.stateAfter=i==t-1||i%5==0||i>=r.viewFrom&&it.start)return r}throw new Error("Mode "+e.name+" failed to advance stream.")}class mt{constructor(e,t,n){this.start=e.start,this.end=e.pos,this.string=e.current(),this.type=t||null,this.state=n}}function yt(e,t,n,i){let r,l,o=e.doc,s=o.mode,a=Ke(o,(t=ot(o,t)).line),c=dt(e,t.line,n),u=new _e(a.text,e.options.tabSize,c);for(i&&(l=[]);(i||u.pose.options.maxHighlightLength?(s=!1,o&&ft(e,t,i,h.pos),h.pos=t.length,a=null):a=bt(gt(n,h,i.state,d),l),d){let e=d[0].name;e&&(a="m-"+(a?e+" "+a:e))}if(!s||u!=a){for(;c=t:l.to>t);(i||(i=[])).push(new Ct(o,l.from,e?null:l.to))}}return i}(n,r,o),a=function(e,t,n){let i;if(e)for(let r=0;r=t:l.to>t)||l.from==t&&"bookmark"==o.type&&(!n||l.marker.insertLeft)){let e=null==l.from||(o.inclusiveLeft?l.from<=t:l.from0&&s)for(let t=0;tt)&&(!n||Dt(n,r.marker)<0)&&(n=r.marker)}return n}function Pt(e,t,n,i,r){let l=Ke(e,t),o=xt&&l.markedSpans;if(o)for(let e=0;e=0&&a<=0||s<=0&&a>=0)&&(s<=0&&(t.marker.inclusiveRight&&r.inclusiveLeft?et(l.to,n)>=0:et(l.to,n)>0)||s>=0&&(t.marker.inclusiveRight&&r.inclusiveLeft?et(l.from,i)<=0:et(l.from,i)<0)))return!0}}function Et(e){let t;for(;t=Ht(e);)e=t.find(-1,!0).line;return e}function It(e,t){let n=Ke(e,t),i=Et(n);return n==i?t:Ye(i)}function Rt(e,t){if(t>e.lastLine())return t;let n,i=Ke(e,t);if(!Bt(e,i))return t;for(;n=zt(i);)i=n.find(1,!0).line;return Ye(i)+1}function Bt(e,t){let n=xt&&t.markedSpans;if(n)for(let i,r=0;r{let n=Vt(e);n>t.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)})}class Kt{constructor(e,t,n){this.text=e,Nt(this,t),this.height=n?n(this):1}lineNo(){return Ye(this)}}function $t(e){e.parent=null,Tt(e)}be(Kt);let jt={},Xt={};function Yt(e,t){if(!e||/^\s*$/.test(e))return null;let n=t.addModeClass?Xt:jt;return n[e]||(n[e]=e.replace(/\S+/g,"cm-$&"))}function qt(e,t){let n=O("span",null,null,a?"padding-right: .1px":null),i={pre:O("pre",[n],"CodeMirror-line"),content:n,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:e.getOption("lineWrapping")};t.measure={};for(let n=0;n<=(t.rest?t.rest.length:0);n++){let r,l=n?t.rest[n-1]:t.line;i.pos=0,i.addToken=Qt,Ae(e.display.measure)&&(r=ce(l,e.doc.direction))&&(i.addToken=Jt(i.addToken,r)),i.map=[],tn(l,i,ht(e,l,t!=e.display.externalMeasured&&Ye(l))),l.styleClasses&&(l.styleClasses.bgClass&&(i.bgClass=z(l.styleClasses.bgClass,i.bgClass||"")),l.styleClasses.textClass&&(i.textClass=z(l.styleClasses.textClass,i.textClass||""))),0==i.map.length&&i.map.push(0,0,i.content.appendChild(Ne(e.display.measure))),0==n?(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(a){let e=i.content.lastChild;(/\bcm-tab\b/.test(e.className)||e.querySelector&&e.querySelector(".cm-tab"))&&(i.content.className="cm-tab-wrap-hack")}return pe(e,"renderLine",e,t.line,i.pre),i.pre.className&&(i.textClass=z(i.pre.className,i.textClass||"")),i}function Zt(e){let t=A("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function Qt(e,t,n,i,r,l,a){if(!t)return;let c,u=e.splitSpaces?function(e,t){if(e.length>1&&!/ /.test(e))return e;let n=t,i="";for(let t=0;t{r=r?r+" cm-force-border":"cm-force-border";let c=n.pos,u=c+i.length;for(;;){let h;for(let e=0;ec&&h.from<=c));e++);if(h.to>=u)return e(n,i,r,l,o,s,a);e(n,i.slice(0,h.to-c),r,l,null,s,a),l=null,i=i.slice(h.to-c),c=h.to}}}function en(e,t,n,i){let 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 tn(e,t,n){let i=e.markedSpans,r=e.text,l=0;if(!i){for(let e=1;ep||l.collapsed&&r.to==p&&r.from==p)){if(null!=r.to&&r.to!=p&&y>r.to&&(y=r.to,c=""),l.className&&(a+=" "+l.className),l.css&&(s=(s?s+";":"")+l.css),l.startStyle&&r.from==p&&(u+=" "+l.startStyle),l.endStyle&&r.to==y&&(e||(e=[])).push(l.endStyle,r.to),l.title&&((d||(d={})).title=l.title),l.attributes)for(let e in l.attributes)(d||(d={}))[e]=l.attributes[e];l.collapsed&&(!h||Dt(h.marker,l)<0)&&(h=r)}else r.from>p&&y>r.from&&(y=r.from)}if(e)for(let t=0;t=f)break;let e=Math.min(f,y);for(;;){if(m){let n=p+m.length;if(!h){let i=n>e?m.slice(0,e-p):m;t.addToken(t,i,o?o+a:a,u,p+i.length==y?c:"",s,d)}if(n>=e){m=m.slice(e-p),p=e;break}p=n,u=""}m=r.slice(l,l=n[g++]),o=Yt(n[g++],t.cm.options)}}}function nn(e,t,n){this.line=t,this.rest=function(e){let t,n;for(;t=zt(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=Bt(e,t)}function rn(e,t,n){let i,r=[];for(let l=t;ln[e].apply(null,r))}function an(){let e=on;on=null;for(let t=0;tn)return{map:e.measure.maps[t],cache:e.measure.caches[t],before:!0}}function An(e,t,n,i){return Wn(e,Dn(e,t),n,i)}function On(e,t){if(t>=e.display.viewFrom&&t=n.lineN&&t2&&e.push((r.bottom+l.top)/2-n.top)}}e.push(n.bottom-n.top)}}(e,t.view,t.rect),t.hasHeights=!0),l=function(e,t,n,i){let r,l=Fn(t.map,n,i),a=l.node,c=l.start,u=l.end,h=l.collapse;if(3==a.nodeType){for(let e=0;e<4;e++){for(;c&&ie(t.line.text.charAt(l.coverStart+c));)--c;for(;l.coverStart+u1}(e))return t;let 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{let t;c>0&&(h=i="right"),r=e.options.lineWrapping&&(t=a.getClientRects()).length>1?t["right"==i?t.length-1:0]:a.getBoundingClientRect()}if(o&&s<9&&!c&&(!r||!r.left&&!r.right)){let t=a.parentNode.getClientRects()[0];r=t?{left:t.left,right:t.left+ii(e.display),top:t.top,bottom:t.bottom}:zn}let d=r.top-t.rect.top,f=r.bottom-t.rect.top,p=(d+f)/2,g=t.view.measure.heights,m=0;for(;mt)&&(l=a-s,r=l-1,t>=a&&(o="right")),null!=r){if(i=e[c+2],s==a&&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==a-s)for(;c=0&&(n=e[t]).left==n.right;t--);return n}function En(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(let t=0;t=i.text.length?(a=i.text.length,c="before"):a<=0&&(a=0,c="after"),!s)return o("before"==c?a-1:a,"before"==c);function u(e,t,n){return o(n?e-1:e,1==s[t].level!=n)}let h=se(s,a,c),d=oe,f=u(a,h,"before"==c);return null!=d&&(f.other=u(a,d,"before"!=c)),f}function jn(e,t){let n=0;t=ot(e.doc,t),e.options.lineWrapping||(n=ii(e.display)*t.ch);let i=Ke(e.doc,t.line),r=Ut(i)+Cn(e.display);return{left:n,right:n,top:r,bottom:r+i.height}}function Xn(e,t,n,i,r){let l=Je(e,t,n);return l.xRel=r,i&&(l.outside=i),l}function Yn(e,t,n){let i=e.doc;if((n+=e.display.viewOffset)<0)return Xn(i.first,0,null,-1,-1);let r=qe(i,n),l=i.first+i.size-1;if(r>l)return Xn(i.first+i.size-1,Ke(i,l).text.length,null,1,1);t<0&&(t=0);let o=Ke(i,r);for(;;){let l=Jn(e,o,r,t,n),s=Ft(o,l.ch+(l.xRel>0||l.outside>0?1:0));if(!s)return l;let a=s.find(1);if(a.line==r)return a;o=Ke(i,r=a.line)}}function qn(e,t,n,i){i-=Un(t);let r=t.text.length,l=le(t=>Wn(e,n,t-1).bottom<=i,r,0);return r=le(t=>Wn(e,n,t).top>i,l,r),{begin:l,end:r}}function Zn(e,t,n,i){return n||(n=Dn(e,t)),qn(e,t,n,Vn(e,t,Wn(e,n,i),"line").top)}function Qn(e,t,n,i){return!(e.bottom<=n)&&(e.top>n||(i?e.left:e.right)>t)}function Jn(e,t,n,i,r){r-=Ut(t);let l=Dn(e,t),o=Un(t),s=0,a=t.text.length,c=!0,u=ce(t,e.doc.direction);if(u){let o=(e.options.lineWrapping?ti:ei)(e,t,n,l,u,i,r);c=1!=o.level,s=c?o.from:o.to-1,a=c?o.to:o.from-1}let h,d,f=null,p=null,g=le(t=>{let n=Wn(e,l,t);return n.top+=o,n.bottom+=o,!!Qn(n,i,r,!1)&&(n.top<=r&&n.left<=i&&(f=t,p=n),!0)},s,a),m=!1;if(p){let e=i-p.left=i.bottom?1:0}return g=re(t.text,g,1),Xn(n,g,d,m,i-h)}function ei(e,t,n,i,r,l,o){let s=le(s=>{let a=r[s],c=1!=a.level;return Qn($n(e,Je(n,c?a.to:a.from,c?"before":"after"),"line",t,i),l,o,!0)},0,r.length-1),a=r[s];if(s>0){let c=1!=a.level,u=$n(e,Je(n,c?a.from:a.to,c?"after":"before"),"line",t,i);Qn(u,l,o,!0)&&u.top>o&&(a=r[s-1])}return a}function ti(e,t,n,i,r,l,o){let{begin:s,end:a}=qn(e,t,i,o);/\s/.test(t.text.charAt(a-1))&&a--;let c=null,u=null;for(let t=0;t=a||n.to<=s)continue;let o=Wn(e,i,1!=n.level?Math.min(a,n.to)-1:Math.max(s,n.from)).right,h=oh)&&(c=n,u=h)}return c||(c=r[r.length-1]),c.froma&&(c={from:c.from,to:a,level:c.level}),c}function ni(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Hn){Hn=A("pre",null,"CodeMirror-line-like");for(let e=0;e<49;++e)Hn.appendChild(document.createTextNode("x")),Hn.appendChild(A("br"));Hn.appendChild(document.createTextNode("x"))}N(e.measure,Hn);let t=Hn.offsetHeight/50;return t>3&&(e.cachedTextHeight=t),T(e.measure),t||1}function ii(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;let t=A("span","xxxxxxxxxx"),n=A("pre",[t],"CodeMirror-line-like");N(e.measure,n);let i=t.getBoundingClientRect(),r=(i.right-i.left)/10;return r>2&&(e.cachedCharWidth=r),r||10}function ri(e){let t=e.display,n={},i={},r=t.gutters.clientLeft;for(let l=t.gutters.firstChild,o=0;l;l=l.nextSibling,++o){let t=e.display.gutterSpecs[o].className;n[t]=l.offsetLeft+l.clientLeft+r,i[t]=l.clientWidth}return{fixedPos:li(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:i,wrapperWidth:t.wrapper.clientWidth}}function li(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function oi(e){let t=ni(e.display),n=e.options.lineWrapping,i=n&&Math.max(5,e.display.scroller.clientWidth/ii(e.display)-3);return r=>{if(Bt(e.doc,r))return 0;let l=0;if(r.widgets)for(let e=0;e{let t=n(e);t!=e.height&&Xe(e,t)})}function ai(e,t,n,i){let r=e.display;if(!n&&"true"==Se(t).getAttribute("cm-not-content"))return null;let l,o,s=r.lineSpace.getBoundingClientRect();try{l=t.clientX-s.left,o=t.clientY-s.top}catch(t){return null}let a,c=Yn(e,l,o);if(i&&c.xRel>0&&(a=Ke(e.doc,c.line).text).length==c.ch){let t=I(a,a.length,e.options.tabSize)-a.length;c=Je(c.line,Math.max(0,Math.round((l-kn(e.display).left)/ii(e.display))-t))}return c}function ci(e,t){if(t>=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;let n=e.display.view;for(let e=0;et)&&(r.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=r.viewTo)xt&&It(e.doc,t)r.viewFrom?di(e):(r.viewFrom+=i,r.viewTo+=i);else if(t<=r.viewFrom&&n>=r.viewTo)di(e);else if(t<=r.viewFrom){let t=fi(e,n,n+i,1);t?(r.view=r.view.slice(t.index),r.viewFrom=t.lineN,r.viewTo+=i):di(e)}else if(n>=r.viewTo){let n=fi(e,t,t,-1);n?(r.view=r.view.slice(0,n.index),r.viewTo=n.lineN):di(e)}else{let l=fi(e,t,t,-1),o=fi(e,n,n+i,1);l&&o?(r.view=r.view.slice(0,l.index).concat(rn(e,l.lineN,o.lineN)).concat(r.view.slice(o.index)),r.viewTo+=i):di(e)}let l=r.externalMeasured;l&&(n=r.lineN&&t=i.viewTo)return;let l=i.view[ci(e,t)];if(null==l.node)return;let o=l.changes||(l.changes=[]);-1==B(o,n)&&o.push(n)}function di(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function fi(e,t,n,i){let r,l=ci(e,t),o=e.display.view;if(!xt||n==e.doc.first+e.doc.size)return{index:l,lineN:n};let s=e.display.viewFrom;for(let e=0;e0){if(l==o.length-1)return null;r=s+o[l].size-t,l++}else r=s-t;t+=r,n+=r}for(;It(e.doc,n)!=n;){if(l==(i<0?0:o.length-1))return null;n+=i*o[l-(i<0?1:0)].size,l+=i}return{index:l,lineN:n}}function pi(e){let t=e.display.view,n=0;for(let e=0;e=e.display.viewTo||o.to().linet||t==n&&o.to==t)&&(i(Math.max(o.from,t),Math.min(o.to,n),1==o.level?"rtl":"ltr",l),r=!0)}r||i(t,n,"ltr")}(g,n||0,null==i?d:i,(e,t,r,h)=>{let m="ltr"==r,y=f(e,m?"left":"right"),b=f(t-1,m?"right":"left"),w=null==n&&0==e,v=null==i&&t==d,x=0==h,C=!g||h==g.length-1;if(b.top-y.top<=3){let e=(c?v:w)&&C,t=(c?w:v)&&x?s:(m?y:b).left,n=e?a:(m?b:y).right;u(t,y.top,n-t,y.bottom)}else{let n,i,l,o;m?(n=c&&w&&x?s:y.left,i=c?a:p(e,r,"before"),l=c?s:p(t,r,"after"),o=c&&v&&C?a:b.right):(n=c?p(e,r,"before"):s,i=!c&&w&&x?a:y.right,l=!c&&v&&C?s:b.left,o=c?p(t,r,"after"):a),u(n,y.top,i-n,y.bottom),y.bottom0?t.blinker=setInterval(()=>t.cursorDiv.style.visibility=(n=!n)?"":"hidden",e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}function xi(e){e.state.focused||(e.display.input.focus(),Si(e))}function Ci(e){e.state.delayingBlurEvent=!0,setTimeout(()=>{e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,ki(e))},100)}function Si(e,t){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(pe(e,"focus",e,t),e.state.focused=!0,H(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),a&&setTimeout(()=>e.display.input.reset(!0),20)),e.display.input.receivedFocus()),vi(e))}function ki(e,t){e.state.delayingBlurEvent||(e.state.focused&&(pe(e,"blur",e,t),e.state.focused=!1,L(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(()=>{e.state.focused||(e.display.shift=!1)},150))}function Mi(e){let t=e.display,n=t.lineDiv.offsetTop;for(let i=0;i.005||u<-.005)&&(Xe(l.line,r),Li(l.line),l.rest))for(let e=0;ee.display.sizerWidth){let t=Math.ceil(c/ii(e.display));t>e.display.maxLineLength&&(e.display.maxLineLength=t,e.display.maxLine=l.line,e.display.maxLineChanged=!0)}}}function Li(e){if(e.widgets)for(let t=0;t=o&&(l=qe(t,Ut(Ke(t,r))-e.wrapper.clientHeight),o=r)}return{from:l,to:Math.max(o,l+1)}}function Ni(e,t){let n=e.display,i=ni(e.display);t.top<0&&(t.top=0);let r=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:n.scroller.scrollTop,l=Tn(e),o={};t.bottom-t.top>l&&(t.bottom=t.top+l);let s=e.doc.height+Sn(n),a=t.tops-i;if(t.topr+l){let e=Math.min(t.top,(c?s:t.bottom)-l);e!=r&&(o.scrollTop=e)}let u=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:n.scroller.scrollLeft,h=Ln(e)-(e.options.fixedGutter?n.gutters.offsetWidth:0),d=t.right-t.left>h;return d&&(t.right=t.left+h),t.left<10?o.scrollLeft=0:t.lefth+u-3&&(o.scrollLeft=t.right+(d?0:10)-h),o}function Ai(e,t){null!=t&&(Wi(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+t)}function Oi(e){Wi(e);let t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function Di(e,t,n){null==t&&null==n||Wi(e),null!=t&&(e.curOp.scrollLeft=t),null!=n&&(e.curOp.scrollTop=n)}function Wi(e){let t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null,Hi(e,jn(e,t.from),jn(e,t.to),t.margin)}}function Hi(e,t,n,i){let r=Ni(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});Di(e,r.scrollLeft,r.scrollTop)}function zi(e,t){Math.abs(e.doc.scrollTop-t)<2||(n||lr(e,{top:t}),Fi(e,t,!0),n&&lr(e),er(e,100))}function Fi(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 Pi(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,ar(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function Ei(e){let t=e.display,n=t.gutters.offsetWidth,i=Math.round(e.doc.height+Sn(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+Mn(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}function Ii(e,t){t||(t=Ei(e));let n=e.display.barWidth,i=e.display.barHeight;Ri(e,t);for(let t=0;t<4&&n!=e.display.barWidth||i!=e.display.barHeight;t++)n!=e.display.barWidth&&e.options.lineWrapping&&Mi(e),Ri(e,Ei(e)),n=e.display.barWidth,i=e.display.barHeight}function Ri(e,t){let 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=""}let Bi={native:class{constructor(e,t,n){this.cm=n;let i=this.vert=A("div",[A("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),r=this.horiz=A("div",[A("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");i.tabIndex=r.tabIndex=-1,e(i),e(r),he(i,"scroll",()=>{i.clientHeight&&t(i.scrollTop,"vertical")}),he(r,"scroll",()=>{r.clientWidth&&t(r.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,o&&s<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}update(e){let 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";let n=e.viewHeight-(t?i:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+n)+"px"}else 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";let t=e.viewWidth-e.barLeft-(n?i:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+t)+"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}}setScrollLeft(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")}setScrollTop(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")}zeroWidthHack(){let e=b&&!f?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new R,this.disableVert=new R}enableZeroWidthBar(e,t,n){e.style.pointerEvents="auto",t.set(1e3,(function i(){let 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)}))}clear(){let e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)}},null:class{update(){return{bottom:0,right:0}}setScrollLeft(){}setScrollTop(){}clear(){}}};function Gi(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&L(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new Bi[e.options.scrollbarStyle](t=>{e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),he(t,"mousedown",()=>{e.state.focused&&setTimeout(()=>e.display.input.focus(),0)}),t.setAttribute("cm-not-content","true")},(t,n)=>{"horizontal"==n?Pi(e,t):zi(e,t)},e),e.display.scrollbars.addClass&&H(e.display.wrapper,e.display.scrollbars.addClass)}let Ui=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:++Ui},t=e.curOp,ln?ln.ops.push(t):t.ownsGroup=ln={ops:[t],delayedCallbacks:[]}}function _i(e){let t=e.curOp;t&&function(e,t){let n=e.ownsGroup;if(n)try{!function(e){let t=e.delayedCallbacks,n=0;do{for(;n{for(let t=0;t=n.viewTo)||n.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new nr(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function $i(e){e.updatedDisplay=e.mustUpdate&&ir(e.cm,e.update)}function ji(e){let t=e.cm,n=t.display;e.updatedDisplay&&Mi(t),e.barMeasure=Ei(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+Mn(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-Ln(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function Xi(e){let t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft(window.innerHeight||document.documentElement.clientHeight)&&(r=!1),null!=r&&!p){let i=A("div","​",null,`position: absolute;\n top: ${t.top-n.viewOffset-Cn(e.display)}px;\n height: ${t.bottom-t.top+Mn(e)+n.barHeight}px;\n left: ${t.left}px; width: ${Math.max(2,t.right-t.left)}px;`);e.display.lineSpace.appendChild(i),i.scrollIntoView(r),e.display.lineSpace.removeChild(i)}}(t,function(e,t,n,i){let r;null==i&&(i=0),e.options.lineWrapping||t!=n||(n="before"==(t=t.ch?Je(t.line,"before"==t.sticky?t.ch-1:t.ch,"after"):t).sticky?Je(t.line,t.ch+1,"before"):t);for(let l=0;l<5;l++){let l=!1,o=$n(e,t),s=n&&n!=t?$n(e,n):o;r={left:Math.min(o.left,s.left),top:Math.min(o.top,s.top)-i,right:Math.max(o.left,s.left),bottom:Math.max(o.bottom,s.bottom)+i};let a=Ni(e,r),c=e.doc.scrollTop,u=e.doc.scrollLeft;if(null!=a.scrollTop&&(zi(e,a.scrollTop),Math.abs(e.doc.scrollTop-c)>1&&(l=!0)),null!=a.scrollLeft&&(Pi(e,a.scrollLeft),Math.abs(e.doc.scrollLeft-u)>1&&(l=!0)),!l)break}return r}(t,ot(i,e.scrollToPos.from),ot(i,e.scrollToPos.to),e.scrollToPos.margin))}let r=e.maybeHiddenMarkers,l=e.maybeUnhiddenMarkers;if(r)for(let e=0;e=e.display.viewTo)return;let n=+new Date+e.options.workTime,i=dt(e,t.highlightFrontier),r=[];t.iter(i.line,Math.min(t.first+t.size,e.display.viewTo+500),l=>{if(i.line>=e.display.viewFrom){let n=l.styles,o=l.text.length>e.options.maxHighlightLength?Ge(t.mode,i.state):null,s=ut(e,l,i,!0);o&&(i.state=o),l.styles=s.styles;let a=l.styleClasses,c=s.classes;c?l.styleClasses=c:a&&(l.styleClasses=null);let u=!n||n.length!=l.styles.length||a!=c&&(!a||!c||a.bgClass!=c.bgClass||a.textClass!=c.textClass);for(let e=0;!u&&en)return er(e,e.options.workDelay),!0}),t.highlightFrontier=i.line,t.modeFrontier=Math.max(t.modeFrontier,i.line),r.length&&qi(e,()=>{for(let t=0;t=n.viewFrom&&t.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==pi(e))return!1;cr(e)&&(di(e),t.dims=ri(e));let r=i.first+i.size,l=Math.max(t.visible.from-e.options.viewportMargin,i.first),o=Math.min(r,t.visible.to+e.options.viewportMargin);n.viewFromo&&n.viewTo-o<20&&(o=Math.min(r,n.viewTo)),xt&&(l=It(e.doc,l),o=Rt(e.doc,o));let s=l!=n.viewFrom||o!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth;!function(e,t,n){let i=e.display;0==i.view.length||t>=i.viewTo||n<=i.viewFrom?(i.view=rn(e,t,n),i.viewFrom=t):(i.viewFrom>t?i.view=rn(e,t,i.viewFrom).concat(i.view):i.viewFromn&&(i.view=i.view.slice(0,ci(e,n)))),i.viewTo=n}(e,l,o),n.viewOffset=Ut(Ke(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";let c=pi(e);if(!s&&0==c&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;let u=function(e){if(e.hasFocus())return null;let t=W();if(!t||!D(e.display.lineDiv,t))return null;let n={activeElt:t};if(window.getSelection){let t=window.getSelection();t.anchorNode&&t.extend&&D(e.display.lineDiv,t.anchorNode)&&(n.anchorNode=t.anchorNode,n.anchorOffset=t.anchorOffset,n.focusNode=t.focusNode,n.focusOffset=t.focusOffset)}return n}(e);return c>4&&(n.lineDiv.style.display="none"),function(e,t,n){let i=e.display,r=e.options.lineNumbers,l=i.lineDiv,o=l.firstChild;function s(t){let n=t.nextSibling;return a&&b&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}let c=i.view,u=i.viewFrom;for(let i=0;i-1&&(i=!1),cn(e,a,u,n)),i&&(T(a.lineNumber),a.lineNumber.appendChild(document.createTextNode(Qe(e.options,u)))),o=a.node.nextSibling}else{let t=mn(e,a,u,n);l.insertBefore(t,o)}u+=a.size}for(;o;)o=s(o)}(e,n.updateLineNumbers,t.dims),c>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,function(e){if(e&&e.activeElt&&e.activeElt!=W()&&(e.activeElt.focus(),e.anchorNode&&D(document.body,e.anchorNode)&&D(document.body,e.focusNode))){let 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)}}(u),T(n.cursorDiv),T(n.selectionDiv),n.gutters.style.height=n.sizer.style.minHeight=0,s&&(n.lastWrapHeight=t.wrapperHeight,n.lastWrapWidth=t.wrapperWidth,er(e,400)),n.updateLineNumbers=null,!0}function rr(e,t){let n=t.viewport;for(let i=!0;;i=!1){if(i&&e.options.lineWrapping&&t.oldDisplayWidth!=Ln(e))i&&(t.visible=Ti(e.display,e.doc,n));else if(n&&null!=n.top&&(n={top:Math.min(e.doc.height+Sn(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(!ir(e,t))break;Mi(e);let r=Ei(e);gi(e),Ii(e,r),sr(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){let n=new nr(e,t);if(ir(e,n)){Mi(e),rr(e,n);let t=Ei(e);gi(e),Ii(e,t),sr(e,t),n.finish()}}function or(e){let t=e.gutters.offsetWidth;e.sizer.style.marginLeft=t+"px"}function sr(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+Mn(e)+"px"}function ar(e){let t=e.display,n=t.view;if(!(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter))return;let i=li(t)-t.scroller.scrollLeft+e.doc.scrollLeft,r=t.gutters.offsetWidth,l=i+"px";for(let t=0;ts.clientWidth,u=s.scrollHeight>s.clientHeight;if(r&&c||l&&u){if(l&&b&&a)e:for(let n=t.target,i=o.view;n!=s;n=n.parentNode)for(let t=0;t{if(null==o.wheelStartX)return;let e=s.scrollLeft-o.wheelStartX,t=s.scrollTop-o.wheelStartY,n=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,n&&(gr=(gr*pr+n)/(pr+1),++pr)},200)):(o.wheelDX+=r,o.wheelDY+=l))}}o?gr=-.53:n?gr=15:u?gr=-.7:d&&(gr=-1/3);class wr{constructor(e,t){this.ranges=e,this.primIndex=t}primary(){return this.ranges[this.primIndex]}equals(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(let t=0;t=0&&et(e,i.to())<=0)return n}return-1}}class vr{constructor(e,t){this.anchor=e,this.head=t}from(){return rt(this.anchor,this.head)}to(){return it(this.anchor,this.head)}empty(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch}}function xr(e,t,n){let i=e&&e.options.selectionsMayTouch,r=t[n];t.sort((e,t)=>et(e.from(),t.from())),n=B(t,r);for(let e=1;e0:o>=0){let i=rt(l.from(),r.from()),o=it(l.to(),r.to()),s=l.empty()?r.from()==r.head:l.from()==l.head;e<=n&&--n,t.splice(--e,2,new vr(s?o:i,s?i:o))}}return new wr(t,n)}function Cr(e,t){return new wr([new vr(e,t||e)],0)}function Sr(e){return e.text?Je(e.from.line+e.text.length-1,X(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function kr(e,t){if(et(e,t.from)<0)return e;if(et(e,t.to)<=0)return Sr(t);let n=e.line+t.text.length-(t.to.line-t.from.line)-1,i=e.ch;return e.line==t.to.line&&(i+=Sr(t).ch-t.to.ch),Je(n,i)}function Mr(e,t){let n=[];for(let i=0;i{e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.modeFrontier=e.doc.highlightFrontier=e.doc.first,er(e,100),e.state.modeGen++,e.curOp&&ui(e)}function Ar(e,t){return 0==t.from.ch&&0==t.to.ch&&""==X(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function Or(e,t,n,i){function r(e){return n?n[e]:null}function l(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),Nt(e,n);let r=i?i(e):1;r!=e.height&&Xe(e,r)}(e,n,r,i),sn(e,"change",e,t)}function o(e,t){let n=[];for(let l=e;l1&&e.remove(s.line+1,p-1),e.insert(s.line+1,t)}sn(e,"change",e,t)}function Dr(e,t,n){!function e(i,r,l){if(i.linked)for(let o=0;oBr(e,n,t.from.line,t.to.line+1),!0),n}function Pr(e){for(;e.length;){if(!X(e).ranges)break;e.pop()}}function Er(e,t,n,i){let r=e.history;r.undone.length=0;let l,o,s=+new Date;if((r.lastOp==i||r.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&r.lastModTime>s-(e.cm?e.cm.options.historyEventDelay:500)||"*"==t.origin.charAt(0)))&&(l=function(e,t){return t?(Pr(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(l.changes),0==et(t.from,t.to)&&0==et(t.from,o.to)?o.to=Sr(t):l.changes.push(Fr(e,t));else{let n=X(r.done);for(n&&n.ranges||Rr(e.sel,r.done),l={changes:[Fr(e,t)],generation:r.generation},r.done.push(l);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=s,r.lastOp=r.lastSelOp=i,r.lastOrigin=r.lastSelOrigin=t.origin,o||pe(e,"historyAdded")}function Ir(e,t,n,i){let r=e.history,l=i&&i.origin;n==r.lastSelOp||l&&r.lastSelOrigin==l&&(r.lastModTime==r.lastSelTime&&r.lastOrigin==l||function(e,t,n,i){let 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,l,X(r.done),t))?r.done[r.done.length-1]=t:Rr(t,r.done),r.lastSelTime=+new Date,r.lastSelOrigin=l,r.lastSelOp=n,i&&!1!==i.clearRedo&&Pr(r.undone)}function Rr(e,t){let n=X(t);n&&n.ranges&&n.equals(e)||t.push(e)}function Br(e,t,n,i){let r=t["spans_"+e.id],l=0;e.iter(Math.max(e.first,n),Math.min(e.first+e.size,i),n=>{n.markedSpans&&((r||(r=t["spans_"+e.id]={}))[l]=n.markedSpans),++l})}function Gr(e){if(!e)return null;let t;for(let n=0;n-1&&(X(a)[r]=i[r],delete i[r])}}return i}function _r(e,t,n,i){if(i){let i=e.anchor;if(n){let e=et(t,i)<0;e!=et(n,i)<0?(i=t,t=n):e!=et(t,n)<0&&(t=n)}return new vr(i,t)}return new vr(n||t,t)}function Kr(e,t,n,i,r){null==r&&(r=e.cm&&(e.cm.display.shift||e.extend)),qr(e,new wr([_r(e.sel.primary(),t,n,r)],0),i)}function $r(e,t,n){let i=[],r=e.cm&&(e.cm.display.shift||e.extend);for(let n=0;n=t.ch:s.to>t.ch))){if(r&&(pe(a,"beforeCursorEnter"),a.explicitlyCleared)){if(l.markedSpans){--o;continue}break}if(!a.atomic)continue;if(n){let o,s=a.find(i<0?1:-1);if((i<0?u:c)&&(s=il(e,s,-i,s&&s.line==t.line?l:null)),s&&s.line==t.line&&(o=et(s,n))&&(i<0?o<0:o>0))return tl(e,s,t,i,r)}let s=a.find(i<0?-1:1);return(i<0?c:u)&&(s=il(e,s,i,s.line==t.line?l:null)),s?tl(e,s,t,i,r):null}}return t}function nl(e,t,n,i,r){let l=i||1,o=tl(e,t,n,l,r)||!r&&tl(e,t,n,l,!0)||tl(e,t,n,-l,r)||!r&&tl(e,t,n,-l,!0);return o||(e.cantEdit=!0,Je(e.first,0))}function il(e,t,n,i){return n<0&&0==t.ch?t.line>e.first?ot(e,Je(t.line-1)):null:n>0&&t.ch==(i||Ke(e,t.line)).text.length?t.linei.canceled=!0};return n&&(i.update=(t,n,r,l)=>{t&&(i.from=ot(e,t)),n&&(i.to=ot(e,n)),r&&(i.text=r),void 0!==l&&(i.origin=l)}),pe(e,"beforeChange",e,i),e.cm&&pe(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 ol(e,t,n){if(e.cm){if(!e.cm.curOp)return Zi(e.cm,ol)(e,t,n);if(e.cm.state.suppressEdits)return}if((ye(e,"beforeChange")||e.cm&&ye(e.cm,"beforeChange"))&&!(t=ll(e,t,!0)))return;let i=vt&&!n&&function(e,t,n){let i=null;if(e.iter(t.line,n.line+1,e=>{if(e.markedSpans)for(let t=0;t0)continue;let l=[e,1],o=et(i.from,n.from),s=et(i.to,n.to);(o<0||!t.inclusiveLeft&&!o)&&l.push({from:i.from,to:n.from}),(s>0||!t.inclusiveRight&&!s)&&l.push({from:n.to,to:i.to}),r.splice.apply(r,l),e+=l.length-3}}return r}(e,t.from,t.to);if(i)for(let n=i.length-1;n>=0;--n)sl(e,{from:i[n].from,to:i[n].to,text:n?[""]:t.text,origin:t.origin});else sl(e,t)}function sl(e,t){if(1==t.text.length&&""==t.text[0]&&0==et(t.from,t.to))return;let n=Mr(e,t);Er(e,t,n,e.cm?e.cm.curOp.id:NaN),ul(e,t,n,Mt(e,t));let i=[];Dr(e,(e,n)=>{n||-1!=B(i,e.history)||(pl(e.history,t),i.push(e.history)),ul(e,t,null,Mt(e,t))})}function al(e,t,n){let i=e.cm&&e.cm.state.suppressEdits;if(i&&!n)return;let r,l=e.history,o=e.sel,s="undo"==t?l.done:l.undone,a="undo"==t?l.undone:l.done,c=0;for(;c=0;--n){let i=r.changes[n];if(i.origin=t,h&&!ll(e,i,!1))return void(s.length=0);u.push(Fr(e,i));let l=n?Mr(e,i):X(s);ul(e,i,l,Ur(e,i)),!n&&e.cm&&e.cm.scrollIntoView({from:i.from,to:Sr(i)});let o=[];Dr(e,(e,t)=>{t||-1!=B(o,e.history)||(pl(e.history,i),o.push(e.history)),ul(e,i,null,Ur(e,i))})}}function cl(e,t){if(0!=t&&(e.first+=t,e.sel=new wr(Y(e.sel.ranges,e=>new vr(Je(e.anchor.line+t,e.anchor.ch),Je(e.head.line+t,e.head.ch))),e.sel.primIndex),e.cm)){ui(e.cm,e.first,e.first-t,t);for(let t=e.cm.display,n=t.viewFrom;ne.lastLine())return;if(t.from.liner&&(t={from:t.from,to:Je(r,Ke(e,r).text.length),text:[t.text[0]],origin:t.origin}),t.removed=$e(e,t.from,t.to),n||(n=Mr(e,t)),e.cm?function(e,t,n){let i=e.doc,r=e.display,l=t.from,o=t.to,s=!1,a=l.line;e.options.lineWrapping||(a=Ye(Et(Ke(i,l.line))),i.iter(a,o.line+1,e=>{if(e==r.maxLine)return s=!0,!0}));i.sel.contains(t.from,t.to)>-1&&me(e);Or(i,t,n,oi(e)),e.options.lineWrapping||(i.iter(a,l.line+t.text.length,e=>{let t=Vt(e);t>r.maxLineLength&&(r.maxLine=e,r.maxLineLength=t,r.maxLineChanged=!0,s=!1)}),s&&(e.curOp.updateMaxLine=!0));(function(e,t){if(e.modeFrontier=Math.min(e.modeFrontier,t),e.highlightFrontiern;i--){let r=Ke(e,i).stateAfter;if(r&&(!(r instanceof at)||i+r.lookAhead1||!(this.children[0]instanceof ml))){let e=[];this.collapse(e),this.children=[new ml(e)],this.children[0].parent=this}},collapse(e){for(let t=0;t50){let e=r.lines.length%25+25;for(let t=e;t10);e.parent.maybeSpill()},iterN(e,t,n){for(let i=0;i{wl(e,n,-r),hi(e,i,"widget")}),sn(e,"lineWidgetCleared",e,this,i))}changed(){let e=this.height,t=this.doc.cm,n=this.line;this.height=null;let i=vn(this)-e;i&&(Bt(this.doc,n)||Xe(n,n.height+i),t&&qi(t,()=>{t.curOp.forceUpdate=!0,wl(t,n,i),sn(t,"lineWidgetChanged",t,this,Ye(n))}))}}function wl(e,t,n){Ut(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Ai(e,n)}be(bl);let vl=0;class xl{constructor(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++vl}clear(){if(this.explicitlyCleared)return;let e=this.doc.cm,t=e&&!e.curOp;if(t&&Vi(e),ye(this,"clear")){let e=this.find();e&&sn(this,"clear",e.from,e.to)}let n=null,i=null;for(let t=0;te.display.maxLineLength&&(e.display.maxLine=n,e.display.maxLineLength=i,e.display.maxLineChanged=!0)}null!=n&&e&&this.collapsed&&ui(e,n,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&Jr(e.doc)),e&&sn(e,"markerCleared",e,this,n,i),t&&_i(e),this.parent&&this.parent.clear()}find(e,t){let n,i;null==e&&"bookmark"==this.type&&(e=1);for(let r=0;r{let i=e.line,r=Ye(e.line),l=On(n,r);if(l&&(En(l),n.curOp.selectionChanged=n.curOp.forceUpdate=!0),n.curOp.updateMaxLine=!0,!Bt(t.doc,i)&&null!=t.height){let e=t.height;t.height=null;let n=vn(t)-e;n&&Xe(i,i.height+n)}sn(n,"markerChanged",n,this)})}attachLine(e){if(!this.lines.length&&this.doc.cm){let e=this.doc.cm.curOp;e.maybeHiddenMarkers&&-1!=B(e.maybeHiddenMarkers,this)||(e.maybeUnhiddenMarkers||(e.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)}detachLine(e){if(this.lines.splice(B(this.lines,e),1),!this.lines.length&&this.doc.cm){let e=this.doc.cm.curOp;(e.maybeHiddenMarkers||(e.maybeHiddenMarkers=[])).push(this)}}}function Cl(e,t,n,i,r){if(i&&i.shared)return function(e,t,n,i,r){(i=E(i)).shared=!1;let l=[Cl(e,t,n,i,r)],o=l[0],s=i.widgetNode;return Dr(e,e=>{s&&(i.widgetNode=s.cloneNode(!0)),l.push(Cl(e,ot(e,t),ot(e,n),i,r));for(let t=0;t0||0==o&&!1!==l.clearWhenEmpty)return l;if(l.replacedWith&&(l.collapsed=!0,l.widgetNode=O("span",[l.replacedWith],"CodeMirror-widget"),i.handleMouseEvents||l.widgetNode.setAttribute("cm-ignore-events","true"),i.insertLeft&&(l.widgetNode.insertLeft=!0)),l.collapsed){if(Pt(e,t.line,t,n,l)||t.line!=n.line&&Pt(e,n.line,t,n,l))throw new Error("Inserting collapsed marker partially overlapping an existing one");xt=!0}l.addToHistory&&Er(e,{from:t,to:n,origin:"markText"},e.sel,NaN);let s,a=t.line,c=e.cm;if(e.iter(a,n.line+1,e=>{c&&l.collapsed&&!c.options.lineWrapping&&Et(e)==c.display.maxLine&&(s=!0),l.collapsed&&a!=t.line&&Xe(e,0),function(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}(e,new Ct(l,a==t.line?t.ch:null,a==n.line?n.ch:null)),++a}),l.collapsed&&e.iter(t.line,n.line+1,t=>{Bt(e,t)&&Xe(t,0)}),l.clearOnEnter&&he(l,"beforeCursorEnter",()=>l.clear()),l.readOnly&&(vt=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),l.collapsed&&(l.id=++vl,l.atomic=!0),c){if(s&&(c.curOp.updateMaxLine=!0),l.collapsed)ui(c,t.line,n.line+1);else if(l.className||l.startStyle||l.endStyle||l.css||l.attributes||l.title)for(let e=t.line;e<=n.line;e++)hi(c,e,"text");l.atomic&&Jr(c.doc),sn(c,"markerAdded",c,l)}return l}be(xl);class Sl{constructor(e,t){this.markers=e,this.primary=t;for(let t=0;te.parent)}function Ml(e){for(let t=0;ti.push(e));for(let e=0;e=0;e--)ol(this,i[e]);l?Yr(this,l):this.cm&&Oi(this.cm)})),undo:Ji((function(){al(this,"undo")})),redo:Ji((function(){al(this,"redo")})),undoSelection:Ji((function(){al(this,"undo",!0)})),redoSelection:Ji((function(){al(this,"redo",!0)})),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){let e=this.history,t=0,n=0;for(let n=0;ne.history=this.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){let t=this.history=new zr(this.history.maxGeneration);t.done=Vr(e.done.slice(0),null,!0),t.undone=Vr(e.undone.slice(0),null,!0)},setGutterMarker:Ji((function(e,t,n){return gl(this,e,"gutter",e=>{let i=e.gutterMarkers||(e.gutterMarkers={});return i[t]=n,!n&&te(i)&&(e.gutterMarkers=null),!0})})),clearGutter:Ji((function(e){this.iter(t=>{t.gutterMarkers&&t.gutterMarkers[e]&&gl(this,t,"gutter",()=>(t.gutterMarkers[e]=null,te(t.gutterMarkers)&&(t.gutterMarkers=null),!0))})})),lineInfo:function(e){let t;if("number"==typeof e){if(!Ze(this,e))return null;if(t=e,!(e=Ke(this,e)))return null}else if(t=Ye(e),null==t)return null;return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},addLineClass:Ji((function(e,t,n){return gl(this,e,"gutter"==t?"gutter":"class",e=>{let i="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass";if(e[i]){if(k(n).test(e[i]))return!1;e[i]+=" "+n}else e[i]=n;return!0})})),removeLineClass:Ji((function(e,t,n){return gl(this,e,"gutter"==t?"gutter":"class",e=>{let 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{let t=r.match(k(n));if(!t)return!1;let l=t.index+t[0].length;e[i]=r.slice(0,t.index)+(t.index&&l!=r.length?" ":"")+r.slice(l)||null}return!0})})),addLineWidget:Ji((function(e,t,n){return function(e,t,n,i){let r=new bl(e,n,i),l=e.cm;return l&&r.noHScroll&&(l.display.alignWidgets=!0),gl(e,t,"widget",t=>{let n=t.widgets||(t.widgets=[]);if(null==r.insertAt?n.push(r):n.splice(Math.min(n.length-1,Math.max(0,r.insertAt)),0,r),r.line=t,l&&!Bt(e,t)){let n=Ut(t)=e.ch)&&t.push(r.marker.parent||r.marker)}return t},findMarks:function(e,t,n){e=ot(this,e),t=ot(this,t);let i=[],r=e.line;return this.iter(e.line,t.line+1,l=>{let o=l.markedSpans;if(o)for(let l=0;l=s.to||null==s.from&&r!=e.line||null!=s.from&&r==t.line&&s.from>=t.ch||n&&!n(s.marker)||i.push(s.marker.parent||s.marker)}++r}),i},getAllMarks:function(){let e=[];return this.iter(t=>{let n=t.markedSpans;if(n)for(let t=0;t{let l=r.text.length+i;if(l>e)return t=e,!0;e-=l,++n}),ot(this,Je(n,t))},indexFromPos:function(e){let t=(e=ot(this,e)).ch;if(e.line{t+=e.text.length+n}),t},copy:function(e){let t=new Tl(je(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={});let t=this.first,n=this.first+this.size;null!=e.from&&e.from>t&&(t=e.from),null!=e.to&&e.tot.push(e.id),!0),e.history=new zr(null),e.history.done=Vr(this.history.done,t),e.history.undone=Vr(this.history.undone,t)}},iterLinkedDocs:function(e){Dr(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm},splitLines:function(e){return this.lineSep?e.split(this.lineSep):Oe(e)},lineSeparator:function(){return this.lineSep||"\n"},setDirection:Ji((function(e){var t;("rtl"!=e&&(e="ltr"),e!=this.direction)&&(this.direction=e,this.iter(e=>e.order=null),this.cm&&qi(t=this.cm,()=>{Hr(t),ui(t)}))}))}),Tl.prototype.eachLine=Tl.prototype.iter;let Nl=0;function Al(e){let t=this;if(Ol(t),ge(t,e)||xn(t.display,e))return;we(e),o&&(Nl=+new Date);let n=ai(t,e,!0),i=e.dataTransfer.files;if(n&&!t.isReadOnly())if(i&&i.length&&window.FileReader&&window.File){let e=i.length,r=Array(e),l=0;const o=()=>{++l==e&&Zi(t,()=>{n=ot(t.doc,n);let e={from:n,to:n,text:t.doc.splitLines(r.filter(e=>null!=e).join(t.doc.lineSeparator())),origin:"paste"};ol(t.doc,e),Yr(t.doc,Cr(ot(t.doc,n),ot(t.doc,Sr(e))))})()},s=(e,n)=>{if(t.options.allowDropFileTypes&&-1==B(t.options.allowDropFileTypes,e.type))return void o();let i=new FileReader;i.onerror=()=>o(),i.onload=()=>{let e=i.result;/[\x00-\x08\x0e-\x1f]{2}/.test(e)||(r[n]=e),o()},i.readAsText(e)};for(let e=0;e-1)return t.state.draggingText(e),void setTimeout(()=>t.display.input.focus(),20);try{let i=e.dataTransfer.getData("Text");if(i){let e;if(t.state.draggingText&&!t.state.draggingText.copy&&(e=t.listSelections()),Zr(t.doc,Cr(n,n)),e)for(let n=0;n{for(let t=0;t{null==e&&(e=setTimeout(()=>{e=null,Dl(zl)},100))}),he(window,"blur",()=>Dl(ki))}(),Wl=!0)}function zl(e){let t=e.display;t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize()}let Fl={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:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"};for(let e=0;e<10;e++)Fl[e+48]=Fl[e+96]=String(e);for(let e=65;e<=90;e++)Fl[e]=String.fromCharCode(e);for(let e=1;e<=12;e++)Fl[e+111]=Fl[e+63235]="F"+e;let Pl={};function El(e){let t,n,i,r,l=e.split(/-(?!$)/);e=l[l.length-1];for(let e=0;e{for(let t=i.length-1;t>=0;t--)hl(e.doc,"",i[t].from,i[t].to,"+delete");Oi(e)})}function Kl(e,t,n){let i=re(e.text,t+n,n);return i<0||i>e.text.length?null:i}function $l(e,t,n){let i=Kl(e,t.ch,n);return null==i?null:new Je(t.line,i,n<0?"after":"before")}function jl(e,t,n,i,r){if(e){"rtl"==t.doc.direction&&(r=-r);let e=ce(n,t.doc.direction);if(e){let l,o=r<0?X(e):e[0],s=r<0==(1==o.level)?"after":"before";if(o.level>0||"rtl"==t.doc.direction){let e=Dn(t,n);l=r<0?n.text.length-1:0;let i=Wn(t,e,l).top;l=le(n=>Wn(t,e,n).top==i,r<0==(1==o.level)?o.from:o.to-1,l),"before"==s&&(l=Kl(n,l,1))}else l=r<0?o.to:o.from;return new Je(i,l,s)}}return new Je(i,r<0?n.text.length:0,r<0?"before":"after")}Pl.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"},Pl.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"},Pl.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Pl.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"]},Pl.default=b?Pl.macDefault:Pl.pcDefault;let Xl={selectAll:rl,singleSelection:e=>e.setSelection(e.getCursor("anchor"),e.getCursor("head"),U),killLine:e=>_l(e,t=>{if(t.empty()){let n=Ke(e.doc,t.head.line).text.length;return t.head.ch==n&&t.head.line_l(e,t=>({from:Je(t.from().line,0),to:ot(e.doc,Je(t.to().line+1,0))})),delLineLeft:e=>_l(e,e=>({from:Je(e.from().line,0),to:e.from()})),delWrappedLineLeft:e=>_l(e,t=>{let n=e.charCoords(t.head,"div").top+5;return{from:e.coordsChar({left:0,top:n},"div"),to:t.from()}}),delWrappedLineRight:e=>_l(e,t=>{let 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:e=>e.undo(),redo:e=>e.redo(),undoSelection:e=>e.undoSelection(),redoSelection:e=>e.redoSelection(),goDocStart:e=>e.extendSelection(Je(e.firstLine(),0)),goDocEnd:e=>e.extendSelection(Je(e.lastLine())),goLineStart:e=>e.extendSelectionsBy(t=>Yl(e,t.head.line),{origin:"+move",bias:1}),goLineStartSmart:e=>e.extendSelectionsBy(t=>ql(e,t.head),{origin:"+move",bias:1}),goLineEnd:e=>e.extendSelectionsBy(t=>function(e,t){let n=Ke(e.doc,t),i=function(e){let t;for(;t=zt(e);)e=t.find(1,!0).line;return e}(n);i!=n&&(t=Ye(i));return jl(!0,e,n,t,-1)}(e,t.head.line),{origin:"+move",bias:-1}),goLineRight:e=>e.extendSelectionsBy(t=>{let n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div")},_),goLineLeft:e=>e.extendSelectionsBy(t=>{let n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:n},"div")},_),goLineLeftSmart:e=>e.extendSelectionsBy(t=>{let n=e.cursorCoords(t.head,"div").top+5,i=e.coordsChar({left:0,top:n},"div");return i.che.moveV(-1,"line"),goLineDown:e=>e.moveV(1,"line"),goPageUp:e=>e.moveV(-1,"page"),goPageDown:e=>e.moveV(1,"page"),goCharLeft:e=>e.moveH(-1,"char"),goCharRight:e=>e.moveH(1,"char"),goColumnLeft:e=>e.moveH(-1,"column"),goColumnRight:e=>e.moveH(1,"column"),goWordLeft:e=>e.moveH(-1,"word"),goGroupRight:e=>e.moveH(1,"group"),goGroupLeft:e=>e.moveH(-1,"group"),goWordRight:e=>e.moveH(1,"word"),delCharBefore:e=>e.deleteH(-1,"char"),delCharAfter:e=>e.deleteH(1,"char"),delWordBefore:e=>e.deleteH(-1,"word"),delWordAfter:e=>e.deleteH(1,"word"),delGroupBefore:e=>e.deleteH(-1,"group"),delGroupAfter:e=>e.deleteH(1,"group"),indentAuto:e=>e.indentSelection("smart"),indentMore:e=>e.indentSelection("add"),indentLess:e=>e.indentSelection("subtract"),insertTab:e=>e.replaceSelection("\t"),insertSoftTab:e=>{let t=[],n=e.listSelections(),i=e.options.tabSize;for(let r=0;r{e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:e=>qi(e,()=>{let t=e.listSelections(),n=[];for(let i=0;i0)r=new Je(r.line,r.ch+1),e.replaceRange(l.charAt(r.ch-1)+l.charAt(r.ch-2),Je(r.line,r.ch-2),r,"+transpose");else if(r.line>e.doc.first){let t=Ke(e.doc,r.line-1).text;t&&(r=new Je(r.line,1),e.replaceRange(l.charAt(0)+e.doc.lineSeparator()+t.charAt(t.length-1),Je(r.line-1,t.length-1),r,"+transpose"))}n.push(new vr(r,r))}e.setSelections(n)}),newlineAndIndent:e=>qi(e,()=>{let t=e.listSelections();for(let n=t.length-1;n>=0;n--)e.replaceRange(e.doc.lineSeparator(),t[n].anchor,t[n].head,"+input");t=e.listSelections();for(let n=0;ne.replaceSelection("\n","start"),toggleOverwrite:e=>e.toggleOverwrite()};function Yl(e,t){let n=Ke(e.doc,t),i=Et(n);return i!=n&&(t=Ye(i)),jl(!0,e,i,t,1)}function ql(e,t){let n=Yl(e,t.line),i=Ke(e.doc,n.line),r=ce(i,e.doc.direction);if(!r||0==r[0].level){let e=Math.max(n.ch,i.text.search(/\S/)),r=t.line==n.line&&t.ch<=e&&t.ch;return Je(n.line,r?0:e,n.sticky)}return n}function Zl(e,t,n){if("string"==typeof t&&!(t=Xl[t]))return!1;e.display.input.ensurePolled();let i=e.display.shift,r=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),n&&(e.display.shift=!1),r=t(e)!=G}finally{e.display.shift=i,e.state.suppressEdits=!1}return r}let Ql=new R;function Jl(e,t,n,i){let r=e.state.keySeq;if(r){if(Bl(t))return"handled";if(/\'$/.test(t)?e.state.keySeq=null:Ql.set(50,()=>{e.state.keySeq==r&&(e.state.keySeq=null,e.display.input.reset())}),eo(e,r+" "+t,n,i))return!0}return eo(e,t,n,i)}function eo(e,t,n,i){let r=function(e,t,n){for(let i=0;iZl(e,t,!0))||Jl(e,n,t,t=>{if("string"==typeof t?/^go[A-Z]/.test(t):t.motion)return Zl(e,t)}):Jl(e,n,t,t=>Zl(e,t)))}let no=null;function io(e){let t=this;if(t.curOp.focus=W(),ge(t,e))return;o&&s<11&&27==e.keyCode&&(e.returnValue=!1);let i=e.keyCode;t.display.shift=16==i||e.shiftKey;let r=to(t,e);h&&(no=r?i:null,r||88!=i||We||!(b?e.metaKey:e.ctrlKey)||t.replaceSelection("",null,"cut")),n&&!b&&!r&&46==i&&e.shiftKey&&!e.ctrlKey&&document.execCommand&&document.execCommand("cut"),18!=i||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||function(e){let t=e.display.lineDiv;function n(e){18!=e.keyCode&&e.altKey||(L(t,"CodeMirror-crosshair"),fe(document,"keyup",n),fe(document,"mouseover",n))}H(t,"CodeMirror-crosshair"),he(document,"keyup",n),he(document,"mouseover",n)}(t)}function ro(e){16==e.keyCode&&(this.doc.sel.shift=!1),ge(this,e)}function lo(e){let t=this;if(xn(t.display,e)||ge(t,e)||e.ctrlKey&&!e.altKey||b&&e.metaKey)return;let n=e.keyCode,i=e.charCode;if(h&&n==no)return no=null,void we(e);if(h&&(!e.which||e.which<10)&&to(t,e))return;let r=String.fromCharCode(null==i?n:i);"\b"!=r&&(function(e,t,n){return Jl(e,"'"+n+"'",t,t=>Zl(e,t,!0))}(t,e,r)||t.display.input.onKeyPress(e))}class oo{constructor(e,t,n){this.time=e,this.pos=t,this.button=n}compare(e,t,n){return this.time+400>e&&0==et(t,this.pos)&&n==this.button}}let so,ao;function co(e){let t=this,n=t.display;if(ge(t,e)||n.activeTouch&&n.input.supportsTouch())return;if(n.input.ensurePolled(),n.shift=e.shiftKey,xn(n,e))return void(a||(n.scroller.draggable=!1,setTimeout(()=>n.scroller.draggable=!0,100)));if(fo(t,e))return;let i=ai(t,e),r=ke(e),l=i?function(e,t){let n=+new Date;return ao&&ao.compare(n,e,t)?(so=ao=null,"triple"):so&&so.compare(n,e,t)?(ao=new oo(n,e,t),so=null,"double"):(so=new oo(n,e,t),ao=null,"single")}(i,r):"single";window.focus(),1==r&&t.state.selectingText&&t.state.selectingText(e),i&&function(e,t,n,i,r){let l="Click";"double"==i?l="Double"+l:"triple"==i&&(l="Triple"+l);return l=(1==t?"Left":2==t?"Middle":"Right")+l,Jl(e,Gl(l,r),r,t=>{if("string"==typeof t&&(t=Xl[t]),!t)return!1;let i=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),i=t(e,n)!=G}finally{e.state.suppressEdits=!1}return i})}(t,r,i,l,e)||(1==r?i?function(e,t,n,i){o?setTimeout(P(xi,e),0):e.curOp.focus=W();let r,l=function(e,t,n){let i=e.getOption("configureMouse"),r=i?i(e,t,n):{};if(null==r.unit){let e=w?n.shiftKey&&n.metaKey:n.altKey;r.unit=e?"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=b?n.metaKey:n.ctrlKey);null==r.moveOnDrag&&(r.moveOnDrag=!(b?n.altKey:n.ctrlKey));return r}(e,n,i),c=e.doc.sel;e.options.dragDrop&&Te&&!e.isReadOnly()&&"single"==n&&(r=c.contains(t))>-1&&(et((r=c.ranges[r]).from(),t)<0||t.xRel>0)&&(et(r.to(),t)>0||t.xRel<0)?function(e,t,n,i){let r=e.display,l=!1,c=Zi(e,t=>{a&&(r.scroller.draggable=!1),e.state.draggingText=!1,fe(r.wrapper.ownerDocument,"mouseup",c),fe(r.wrapper.ownerDocument,"mousemove",u),fe(r.scroller,"dragstart",h),fe(r.scroller,"drop",c),l||(we(t),i.addNew||Kr(e.doc,n,null,null,i.extend),a||o&&9==s?setTimeout(()=>{r.wrapper.ownerDocument.body.focus(),r.input.focus()},20):r.input.focus())}),u=function(e){l=l||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},h=()=>l=!0;a&&(r.scroller.draggable=!0);e.state.draggingText=c,c.copy=!i.moveOnDrag,r.scroller.dragDrop&&r.scroller.dragDrop();he(r.wrapper.ownerDocument,"mouseup",c),he(r.wrapper.ownerDocument,"mousemove",u),he(r.scroller,"dragstart",h),he(r.scroller,"drop",c),Ci(e),setTimeout(()=>r.input.focus(),20)}(e,i,t,l):function(e,t,n,i){let r=e.display,l=e.doc;we(t);let o,s,a=l.sel,c=a.ranges;i.addNew&&!i.extend?(s=l.sel.contains(n),o=s>-1?c[s]:new vr(n,n)):(o=l.sel.primary(),s=l.sel.primIndex);if("rectangle"==i.unit)i.addNew||(o=new vr(n,n)),n=ai(e,t,!0,!0),s=-1;else{let t=uo(e,n,i.unit);o=i.extend?_r(o,t.anchor,t.head,i.extend):t}i.addNew?-1==s?(s=c.length,qr(l,xr(e,c.concat([o]),s),{scroll:!1,origin:"*mouse"})):c.length>1&&c[s].empty()&&"char"==i.unit&&!i.extend?(qr(l,xr(e,c.slice(0,s).concat(c.slice(s+1)),0),{scroll:!1,origin:"*mouse"}),a=l.sel):jr(l,s,o,V):(s=0,qr(l,new wr([o],0),V),a=l.sel);let u=n;function h(t){if(0!=et(u,t))if(u=t,"rectangle"==i.unit){let i=[],r=e.options.tabSize,o=I(Ke(l,n.line).text,n.ch,r),c=I(Ke(l,t.line).text,t.ch,r),u=Math.min(o,c),h=Math.max(o,c);for(let o=Math.min(n.line,t.line),s=Math.min(e.lastLine(),Math.max(n.line,t.line));o<=s;o++){let e=Ke(l,o).text,t=K(e,u,r);u==h?i.push(new vr(Je(o,t),Je(o,t))):e.length>t&&i.push(new vr(Je(o,t),Je(o,K(e,h,r))))}i.length||i.push(new vr(n,n)),qr(l,xr(e,a.ranges.slice(0,s).concat(i),s),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{let n,r=o,c=uo(e,t,i.unit),u=r.anchor;et(c.anchor,u)>0?(n=c.head,u=rt(r.from(),c.anchor)):(n=c.anchor,u=it(r.to(),c.head));let h=a.ranges.slice(0);h[s]=function(e,t){let{anchor:n,head:i}=t,r=Ke(e.doc,n.line);if(0==et(n,i)&&n.sticky==i.sticky)return t;let l=ce(r);if(!l)return t;let o=se(l,n.ch,n.sticky),s=l[o];if(s.from!=n.ch&&s.to!=n.ch)return t;let a,c=o+(s.from==n.ch==(1!=s.level)?0:1);if(0==c||c==l.length)return t;if(i.line!=n.line)a=(i.line-n.line)*("ltr"==e.doc.direction?1:-1)>0;else{let e=se(l,i.ch,i.sticky),t=e-o||(i.ch-n.ch)*(1==s.level?-1:1);a=e==c-1||e==c?t<0:t>0}let u=l[c+(a?-1:0)],h=a==(1==u.level),d=h?u.from:u.to,f=h?"after":"before";return n.ch==d&&n.sticky==f?t:new vr(new Je(n.line,d,f),i)}(e,new vr(ot(l,u),n)),qr(l,xr(e,h,s),V)}}let d=r.wrapper.getBoundingClientRect(),f=0;function p(t){e.state.selectingText=!1,f=1/0,t&&(we(t),r.input.focus()),fe(r.wrapper.ownerDocument,"mousemove",g),fe(r.wrapper.ownerDocument,"mouseup",m),l.history.lastSelOrigin=null}let g=Zi(e,t=>{0!==t.buttons&&ke(t)?function t(n){let o=++f,s=ai(e,n,!0,"rectangle"==i.unit);if(s)if(0!=et(s,u)){e.curOp.focus=W(),h(s);let i=Ti(r,l);(s.line>=i.to||s.line{f==o&&t(n)}),150)}else{let i=n.clientYd.bottom?20:0;i&&setTimeout(Zi(e,()=>{f==o&&(r.scroller.scrollTop+=i,t(n))}),50)}}(t):p(t)}),m=Zi(e,p);e.state.selectingText=m,he(r.wrapper.ownerDocument,"mousemove",g),he(r.wrapper.ownerDocument,"mouseup",m)}(e,i,t,l)}(t,i,l,e):Se(e)==n.scroller&&we(e):2==r?(i&&Kr(t.doc,i),setTimeout(()=>n.input.focus(),20)):3==r&&(S?t.display.input.onContextMenu(e):Ci(t)))}function uo(e,t,n){if("char"==n)return new vr(t,t);if("word"==n)return e.findWordAt(t);if("line"==n)return new vr(Je(t.line,0),ot(e.doc,Je(t.line+1,0)));let i=n(e,t);return new vr(i.from,i.to)}function ho(e,t,n,i){let r,l;if(t.touches)r=t.touches[0].clientX,l=t.touches[0].clientY;else try{r=t.clientX,l=t.clientY}catch(t){return!1}if(r>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;i&&we(t);let o=e.display,s=o.lineDiv.getBoundingClientRect();if(l>s.bottom||!ye(e,n))return xe(t);l-=s.top-o.viewOffset;for(let i=0;i=r){return pe(e,n,e,qe(e.doc,l),e.display.gutterSpecs[i].className,t),xe(t)}}}function fo(e,t){return ho(e,t,"gutterClick",!0)}function po(e,t){xn(e.display,t)||function(e,t){return!!ye(e,"gutterContextMenu")&&ho(e,t,"gutterContextMenu",!1)}(e,t)||ge(e,t,"contextmenu")||S||e.display.input.onContextMenu(t)}function go(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),Rn(e)}let mo={toString:function(){return"CodeMirror.Init"}},yo={},bo={};function wo(e,t,n){if(!t!=!(n&&n!=mo)){let n=e.display.dragFunctions,i=t?he:fe;i(e.display.scroller,"dragstart",n.start),i(e.display.scroller,"dragenter",n.enter),i(e.display.scroller,"dragover",n.over),i(e.display.scroller,"dragleave",n.leave),i(e.display.scroller,"drop",n.drop)}}function vo(e){e.options.lineWrapping?(H(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(L(e.display.wrapper,"CodeMirror-wrap"),_t(e)),si(e),ui(e),Rn(e),setTimeout(()=>Ii(e),100)}function xo(e,t){if(!(this instanceof xo))return new xo(e,t);this.options=t=t?E(t):{},E(yo,t,!1);let n=t.value;"string"==typeof n?n=new Tl(n,t.mode,null,t.lineSeparator,t.direction):t.mode&&(n.modeOption=t.mode),this.doc=n;let i=new xo.inputStyles[t.inputStyle](this),r=this.display=new fr(e,n,i,t);r.wrapper.CodeMirror=this,go(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),Gi(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 R,keySeq:null,specialChars:null},t.autofocus&&!y&&r.input.focus(),o&&s<11&&setTimeout(()=>this.display.input.reset(!0),20),function(e){let t=e.display;he(t.scroller,"mousedown",Zi(e,co)),he(t.scroller,"dblclick",o&&s<11?Zi(e,t=>{if(ge(e,t))return;let n=ai(e,t);if(!n||fo(e,t)||xn(e.display,t))return;we(t);let i=e.findWordAt(n);Kr(e.doc,i.anchor,i.head)}):t=>ge(e,t)||we(t));he(t.scroller,"contextmenu",t=>po(e,t)),he(t.input.getField(),"contextmenu",n=>{t.scroller.contains(n.target)||po(e,n)});let n,i={end:0};function r(){t.activeTouch&&(n=setTimeout(()=>t.activeTouch=null,1e3),i=t.activeTouch,i.end=+new Date)}function l(e,t){if(null==t.left)return!0;let n=t.left-e.left,i=t.top-e.top;return n*n+i*i>400}he(t.scroller,"touchstart",r=>{if(!ge(e,r)&&!function(e){if(1!=e.touches.length)return!1;let t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}(r)&&!fo(e,r)){t.input.ensurePolled(),clearTimeout(n);let e=+new Date;t.activeTouch={start:e,moved:!1,prev:e-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",()=>{t.activeTouch&&(t.activeTouch.moved=!0)}),he(t.scroller,"touchend",n=>{let i=t.activeTouch;if(i&&!xn(t,n)&&null!=i.left&&!i.moved&&new Date-i.start<300){let r,o=e.coordsChar(t.activeTouch,"page");r=!i.prev||l(i,i.prev)?new vr(o,o):!i.prev.prev||l(i,i.prev.prev)?e.findWordAt(o):new vr(Je(o.line,0),ot(e.doc,Je(o.line+1,0))),e.setSelection(r.anchor,r.head),e.focus(),we(n)}r()}),he(t.scroller,"touchcancel",r),he(t.scroller,"scroll",()=>{t.scroller.clientHeight&&(zi(e,t.scroller.scrollTop),Pi(e,t.scroller.scrollLeft,!0),pe(e,"scroll",e))}),he(t.scroller,"mousewheel",t=>br(e,t)),he(t.scroller,"DOMMouseScroll",t=>br(e,t)),he(t.wrapper,"scroll",()=>t.wrapper.scrollTop=t.wrapper.scrollLeft=0),t.dragFunctions={enter:t=>{ge(e,t)||Ce(t)},over:t=>{ge(e,t)||(!function(e,t){let n=ai(e,t);if(!n)return;let i=document.createDocumentFragment();yi(e,n,i),e.display.dragCursor||(e.display.dragCursor=A("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),e.display.lineSpace.insertBefore(e.display.dragCursor,e.display.cursorDiv)),N(e.display.dragCursor,i)}(e,t),Ce(t))},start:t=>function(e,t){if(o&&(!e.state.draggingText||+new Date-Nl<100))Ce(t);else if(!ge(e,t)&&!xn(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.effectAllowed="copyMove",t.dataTransfer.setDragImage&&!d)){let n=A("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:Zi(e,Al),leave:t=>{ge(e,t)||Ol(e)}};let a=t.input.getField();he(a,"keyup",t=>ro.call(e,t)),he(a,"keydown",Zi(e,io)),he(a,"keypress",Zi(e,lo)),he(a,"focus",t=>Si(e,t)),he(a,"blur",t=>ki(e,t))}(this),Hl(),Vi(this),this.curOp.forceUpdate=!0,Wr(this,n),t.autofocus&&!y||this.hasFocus()?setTimeout(P(Si,this),20):ki(this);for(let e in bo)bo.hasOwnProperty(e)&&bo[e](this,t[e],mo);cr(this),t.finishInit&&t.finishInit(this);for(let e=0;e150)){if(!i)return;n="prev"}}else c=0,n="not";"prev"==n?c=t>l.first?I(Ke(l,t-1).text,null,o):0:"add"==n?c=a+e.options.indentUnit:"subtract"==n?c=a-e.options.indentUnit:"number"==typeof n&&(c=a+n),c=Math.max(0,c);let h="",d=0;if(e.options.indentWithTabs)for(let e=Math.floor(c/o);e;--e)d+=o,h+="\t";if(dCo.push(e);let ko=null;function Mo(e){ko=e}function Lo(e,t,n,i,r){let l=e.doc;e.display.shift=!1,i||(i=l.sel);let o=+new Date-200,s="paste"==r||e.state.pasteIncoming>o,a=Oe(t),c=null;if(s&&i.ranges.length>1)if(ko&&ko.text.join("\n")==t){if(i.ranges.length%ko.text.length==0){c=[];for(let e=0;e[e]));let u=e.curOp.updateInput;for(let u=i.ranges.length-1;u>=0;u--){let h=i.ranges[u],d=h.from(),f=h.to();h.empty()&&(n&&n>0?d=Je(d.line,d.ch-n):e.state.overwrite&&!s?f=Je(f.line,Math.min(Ke(l,f.line).text.length,f.ch+X(a).length)):s&&ko&&ko.lineWise&&ko.text.join("\n")==t&&(d=f=Je(d.line,0)));let p={from:d,to:f,text:c?c[u%c.length]:a,origin:r||(s?"paste":e.state.cutIncoming>o?"cut":"+input")};ol(e.doc,p),sn(e,"inputRead",e,p)}t&&!s&&No(e,t),Oi(e),e.curOp.updateInput<2&&(e.curOp.updateInput=u),e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=-1}function To(e,t){let n=e.clipboardData&&e.clipboardData.getData("Text");if(n)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||qi(t,()=>Lo(t,n,0,null,"paste")),!0}function No(e,t){if(!e.options.electricChars||!e.options.smartIndent)return;let n=e.doc.sel;for(let i=n.ranges.length-1;i>=0;i--){let r=n.ranges[i];if(r.head.ch>100||i&&n.ranges[i-1].head.line==r.head.line)continue;let l=e.getModeAt(r.head),o=!1;if(l.electricChars){for(let n=0;n-1){o=So(e,r.head.line,"smart");break}}else l.electricInput&&l.electricInput.test(Ke(e.doc,r.head.line).text.slice(0,r.head.ch))&&(o=So(e,r.head.line,"smart"));o&&sn(e,"electricInput",e,r.head.line)}}function Ao(e){let t=[],n=[];for(let i=0;i=t.text.length?(n.ch=t.text.length,n.sticky="before"):n.ch<=0&&(n.ch=0,n.sticky="after");let l=se(r,n.ch,n.sticky),o=r[l];if("ltr"==e.doc.direction&&o.level%2==0&&(i>0?o.to>n.ch:o.fromKl(t,e instanceof Je?e.ch:e,n),c=n=>e.options.lineWrapping?(s=s||Dn(e,t),Zn(e,t,s,n)):{begin:0,end:t.text.length},u=c("before"==n.sticky?a(n,-1):n.ch);if("rtl"==e.doc.direction||1==o.level){let e=1==o.level==i<0,t=a(n,e?1:-1);if(null!=t&&(e?t<=o.to&&t<=u.end:t>=o.from&&t>=u.begin)){let i=e?"before":"after";return new Je(n.line,t,i)}}let h=(e,t,i)=>{let l=(e,t)=>t?new Je(n.line,a(e,1),"before"):new Je(n.line,e,"after");for(;e>=0&&e0==(1!=n.level),s=o?i.begin:a(i.end,-1);if(n.from<=s&&s0?u.end:a(u.begin,-1);return null==f||i>0&&f==t.text.length||(d=h(i>0?0:r.length-1,i,c(f)),!d)?null:d}(e.cm,s,t,n):$l(s,t,n),null==l){if(i||!function(){let n=t.line+a;return!(n=e.first+e.size)&&(t=new Je(n,t.ch,t.sticky),s=Ke(e,n))}())return!1;t=jl(r,e.cm,s,t.line,a)}else t=l;return!0}if("char"==i)c();else if("column"==i)c(!0);else if("word"==i||"group"==i){let r=null,l="group"==i,o=e.cm&&e.cm.getHelper(t,"wordChars");for(let e=!0;!(n<0)||c(!e);e=!1){let i=s.text.charAt(t.ch)||"\n",a=ee(i,o)?"w":l&&"\n"==i?"n":!l||/\s/.test(i)?null:"p";if(!l||e||a||(a="s"),r&&r!=a){n<0&&(n=1,c(),t.sticky="after");break}if(a&&(r=a),n>0&&!c(!e))break}}let u=nl(e,t,l,o,!0);return tt(l,u)&&(u.hitSide=!0),u}function Ho(e,t,n,i){let r,l,o=e.doc,s=t.left;if("page"==i){let i=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),l=Math.max(i-.5*ni(e.display),3);r=(n>0?t.bottom:t.top)+n*l}else"line"==i&&(r=n>0?t.bottom+3:t.top-3);for(;l=Yn(e,s,r),l.outside;){if(n<0?r<=0:r>=o.height){l.hitSide=!0;break}r+=5*n}return l}class zo{constructor(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new R,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null}init(e){let t=this,n=t.cm,i=t.div=e.lineDiv;function r(e){if(ge(n,e))return;if(n.somethingSelected())Mo({lineWise:!1,text:n.getSelections()}),"cut"==e.type&&n.replaceSelection("",null,"cut");else{if(!n.options.lineWiseCopyCut)return;{let t=Ao(n);Mo({lineWise:!0,text:t.text}),"cut"==e.type&&n.operation(()=>{n.setSelections(t.ranges,0,U),n.replaceSelection("",null,"cut")})}}if(e.clipboardData){e.clipboardData.clearData();let t=ko.text.join("\n");if(e.clipboardData.setData("Text",t),e.clipboardData.getData("Text")==t)return void e.preventDefault()}let r=Do(),l=r.firstChild;n.display.lineSpace.insertBefore(r,n.display.lineSpace.firstChild),l.value=ko.text.join("\n");let o=document.activeElement;F(l),setTimeout(()=>{n.display.lineSpace.removeChild(r),o.focus(),o==i&&t.showPrimarySelection()},50)}Oo(i,n.options.spellcheck,n.options.autocorrect,n.options.autocapitalize),he(i,"paste",e=>{ge(n,e)||To(e,n)||s<=11&&setTimeout(Zi(n,()=>this.updateFromDOM()),20)}),he(i,"compositionstart",e=>{this.composing={data:e.data,done:!1}}),he(i,"compositionupdate",e=>{this.composing||(this.composing={data:e.data,done:!1})}),he(i,"compositionend",e=>{this.composing&&(e.data!=this.composing.data&&this.readFromDOMSoon(),this.composing.done=!0)}),he(i,"touchstart",()=>t.forceCompositionEnd()),he(i,"input",()=>{this.composing||this.readFromDOMSoon()}),he(i,"copy",r),he(i,"cut",r)}prepareSelection(){let e=mi(this.cm,!1);return e.focus=document.activeElement==this.div,e}showSelection(e,t){e&&this.cm.display.view.length&&((e.focus||t)&&this.showPrimarySelection(),this.showMultipleSelections(e))}getSelection(){return this.cm.display.wrapper.ownerDocument.getSelection()}showPrimarySelection(){let e=this.getSelection(),t=this.cm,i=t.doc.sel.primary(),r=i.from(),l=i.to();if(t.display.viewTo==t.display.viewFrom||r.line>=t.display.viewTo||l.line=t.display.viewFrom&&Fo(t,r)||{node:a[0].measure.map[2],offset:0},u=l.line{this.gracePeriod=!1,this.selectionChanged()&&this.cm.operation(()=>this.cm.curOp.selectionChanged=!0)},20)}showMultipleSelections(e){N(this.cm.display.cursorDiv,e.cursors),N(this.cm.display.selectionDiv,e.selection)}rememberSelection(){let e=this.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset}selectionInEditor(){let e=this.getSelection();if(!e.rangeCount)return!1;let t=e.getRangeAt(0).commonAncestorContainer;return D(this.div,t)}focus(){"nocursor"!=this.cm.options.readOnly&&(this.selectionInEditor()&&document.activeElement==this.div||this.showSelection(this.prepareSelection(),!0),this.div.focus())}blur(){this.div.blur()}getField(){return this.div}supportsTouch(){return!0}receivedFocus(){let e=this;this.selectionInEditor()?this.pollSelection():qi(this.cm,()=>e.cm.curOp.selectionChanged=!0),this.polling.set(this.cm.options.pollInterval,(function t(){e.cm.state.focused&&(e.pollSelection(),e.polling.set(e.cm.options.pollInterval,t))}))}selectionChanged(){let e=this.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset}pollSelection(){if(null!=this.readDOMTimeout||this.gracePeriod||!this.selectionChanged())return;let e=this.getSelection(),t=this.cm;if(m&&u&&this.cm.display.gutterSpecs.length&&function(e){for(let 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)return;this.rememberSelection();let n=Eo(t,e.anchorNode,e.anchorOffset),i=Eo(t,e.focusNode,e.focusOffset);n&&i&&qi(t,()=>{qr(t.doc,Cr(n,i),U),(n.bad||i.bad)&&(t.curOp.selectionChanged=!0)})}pollContent(){null!=this.readDOMTimeout&&(clearTimeout(this.readDOMTimeout),this.readDOMTimeout=null);let e,t,n,i=this.cm,r=i.display,l=i.doc.sel.primary(),o=l.from(),s=l.to();if(0==o.ch&&o.line>i.firstLine()&&(o=Je(o.line-1,Ke(i.doc,o.line-1).length)),s.ch==Ke(i.doc,s.line).text.length&&s.liner.viewTo-1)return!1;o.line==r.viewFrom||0==(e=ci(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);let a,c,u=ci(i,s.line);if(u==r.view.length-1?(a=r.viewTo-1,c=r.lineDiv.lastChild):(a=Ye(r.view[u+1].line)-1,c=r.view[u+1].node.previousSibling),!n)return!1;let h=i.doc.splitLines(function(e,t,n,i,r){let l="",o=!1,s=e.doc.lineSeparator(),a=!1;function c(){o&&(l+=s,a&&(l+=s),o=a=!1)}function u(e){e&&(c(),l+=e)}function h(t){if(1==t.nodeType){let l=t.getAttribute("cm-text");if(l)return void u(l);let d,f=t.getAttribute("cm-marker");if(f){let t=e.findMarks(Je(i,0),Je(r+1,0),(n=+f,e=>e.id==n));return void(t.length&&(d=t[0].find(0))&&u($e(e.doc,d.from,d.to).join(s)))}if("false"==t.getAttribute("contenteditable"))return;let p=/^(pre|div|p|li|table|br)$/i.test(t.nodeName);if(!/^br$/i.test(t.nodeName)&&0==t.textContent.length)return;p&&c();for(let e=0;e1&&d.length>1;)if(X(h)==X(d))h.pop(),d.pop(),a--;else{if(h[0]!=d[0])break;h.shift(),d.shift(),t++}let f=0,p=0,g=h[0],m=d[0],y=Math.min(g.length,m.length);for(;fo.ch&&b.charCodeAt(b.length-p-1)==w.charCodeAt(w.length-p-1);)f--,p++;h[h.length-1]=b.slice(0,b.length-p).replace(/^\u200b+/,""),h[0]=h[0].slice(f).replace(/\u200b+$/,"");let x=Je(t,f),C=Je(a,d.length?X(d).length-p:0);return h.length>1||h[0]||et(x,C)?(hl(i.doc,h,x,C,"+input"),!0):void 0}ensurePolled(){this.forceCompositionEnd()}reset(){this.forceCompositionEnd()}forceCompositionEnd(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())}readFromDOMSoon(){null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout(()=>{if(this.readDOMTimeout=null,this.composing){if(!this.composing.done)return;this.composing=null}this.updateFromDOM()},80))}updateFromDOM(){!this.cm.isReadOnly()&&this.pollContent()||qi(this.cm,()=>ui(this.cm))}setUneditable(e){e.contentEditable="false"}onKeyPress(e){0==e.charCode||this.composing||(e.preventDefault(),this.cm.isReadOnly()||Zi(this.cm,Lo)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0))}readOnlyChanged(e){this.div.contentEditable=String("nocursor"!=e)}onContextMenu(){}resetPosition(){}}function Fo(e,t){let n=On(e,t.line);if(!n||n.hidden)return null;let i=Ke(e.doc,t.line),r=Nn(n,i,t.line),l=ce(i,e.doc.direction),o="left";if(l){o=se(l,t.ch)%2?"right":"left"}let s=Fn(r.map,t.ch,o);return s.offset="right"==s.collapse?s.end:s.start,s}function Po(e,t){return t&&(e.bad=!0),e}function Eo(e,t,n){let i;if(t==e.display.lineDiv){if(i=e.display.lineDiv.childNodes[n],!i)return Po(e.clipPos(Je(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(let r=0;r{o&&s>=9&&this.hasSelection&&(this.hasSelection=null),t.poll()}),he(i,"paste",e=>{ge(n,e)||To(e,n)||(n.state.pasteIncoming=+new Date,t.fastPoll())}),he(i,"cut",r),he(i,"copy",r),he(e.scroller,"paste",r=>{if(xn(e,r)||ge(n,r))return;if(!i.dispatchEvent)return n.state.pasteIncoming=+new Date,void t.focus();const l=new Event("paste");l.clipboardData=r.clipboardData,i.dispatchEvent(l)}),he(e.lineSpace,"selectstart",t=>{xn(e,t)||we(t)}),he(i,"compositionstart",()=>{let e=n.getCursor("from");t.composing&&t.composing.range.clear(),t.composing={start:e,range:n.markText(e,n.getCursor("to"),{className:"CodeMirror-composing"})}}),he(i,"compositionend",()=>{t.composing&&(t.poll(),t.composing.range.clear(),t.composing=null)})}createField(e){this.wrapper=Do(),this.textarea=this.wrapper.firstChild}prepareSelection(){let e=this.cm,t=e.display,n=e.doc,i=mi(e);if(e.options.moveInputWithCursor){let r=$n(e,n.sel.primary().head,"div"),l=t.wrapper.getBoundingClientRect(),o=t.lineDiv.getBoundingClientRect();i.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,r.top+o.top-l.top)),i.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,r.left+o.left-l.left))}return i}showSelection(e){let t=this.cm.display;N(t.cursorDiv,e.cursors),N(t.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")}reset(e){if(this.contextMenuPending||this.composing)return;let t=this.cm;if(t.somethingSelected()){this.prevInput="";let e=t.getSelection();this.textarea.value=e,t.state.focused&&F(this.textarea),o&&s>=9&&(this.hasSelection=e)}else e||(this.prevInput=this.textarea.value="",o&&s>=9&&(this.hasSelection=null))}getField(){return this.textarea}supportsTouch(){return!1}focus(){if("nocursor"!=this.cm.options.readOnly&&(!y||W()!=this.textarea))try{this.textarea.focus()}catch(e){}}blur(){this.textarea.blur()}resetPosition(){this.wrapper.style.top=this.wrapper.style.left=0}receivedFocus(){this.slowPoll()}slowPoll(){this.pollingFast||this.polling.set(this.cm.options.pollInterval,()=>{this.poll(),this.cm.state.focused&&this.slowPoll()})}fastPoll(){let 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))}))}poll(){let e=this.cm,t=this.textarea,n=this.prevInput;if(this.contextMenuPending||!e.state.focused||De(t)&&!n&&!this.composing||e.isReadOnly()||e.options.disableInput||e.state.keySeq)return!1;let i=t.value;if(i==n&&!e.somethingSelected())return!1;if(o&&s>=9&&this.hasSelection===i||b&&/[\uf700-\uf7ff]/.test(i))return e.display.input.reset(),!1;if(e.doc.sel==e.display.selForContextMenu){let e=i.charCodeAt(0);if(8203!=e||n||(n="​"),8666==e)return this.reset(),this.cm.execCommand("undo")}let r=0,l=Math.min(n.length,i.length);for(;r{Lo(e,i.slice(r),n.length-r,null,this.composing?"*compose":null),i.length>1e3||i.indexOf("\n")>-1?t.value=this.prevInput="":this.prevInput=i,this.composing&&(this.composing.range.clear(),this.composing.range=e.markText(this.composing.start,e.getCursor("to"),{className:"CodeMirror-composing"}))}),!0}ensurePolled(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)}onKeyPress(){o&&s>=9&&(this.hasSelection=null),this.fastPoll()}onContextMenu(e){let t=this,n=t.cm,i=n.display,r=t.textarea;t.contextMenuPending&&t.contextMenuPending();let l=ai(n,e),c=i.scroller.scrollTop;if(!l||h)return;n.options.resetSelectionOnContextMenu&&-1==n.doc.sel.contains(l)&&Zi(n,qr)(n.doc,Cr(l),U);let u,d=r.style.cssText,f=t.wrapper.style.cssText,p=t.wrapper.offsetParent.getBoundingClientRect();function g(){if(null!=r.selectionStart){let e=n.somethingSelected(),l="​"+(e?r.value:"");r.value="⇚",r.value=l,t.prevInput=e?"":"​",r.selectionStart=1,r.selectionEnd=l.length,i.selForContextMenu=n.doc.sel}}function m(){if(t.contextMenuPending==m&&(t.contextMenuPending=!1,t.wrapper.style.cssText=f,r.style.cssText=d,o&&s<9&&i.scrollbars.setScrollTop(i.scroller.scrollTop=c),null!=r.selectionStart)){(!o||o&&s<9)&&g();let e=0,l=()=>{i.selForContextMenu==n.doc.sel&&0==r.selectionStart&&r.selectionEnd>0&&"​"==t.prevInput?Zi(n,rl)(n):e++<10?i.detectingSelectAll=setTimeout(l,500):(i.selForContextMenu=null,i.input.reset())};i.detectingSelectAll=setTimeout(l,200)}}if(t.wrapper.style.cssText="position: static",r.style.cssText=`position: absolute; width: 30px; height: 30px;\n top: ${e.clientY-p.top-5}px; left: ${e.clientX-p.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);`,a&&(u=window.scrollY),i.input.focus(),a&&window.scrollTo(null,u),i.input.reset(),n.somethingSelected()||(r.value=t.prevInput=" "),t.contextMenuPending=m,i.selForContextMenu=n.doc.sel,clearTimeout(i.detectingSelectAll),o&&s>=9&&g(),S){Ce(e);let t=()=>{fe(window,"mouseup",t),setTimeout(m,20)};he(window,"mouseup",t)}else setTimeout(m,50)}readOnlyChanged(e){e||this.reset(),this.textarea.disabled="nocursor"==e}setUneditable(){}}Ro.prototype.needsContentAttribute=!1,function(e){let t=e.optionHandlers;function n(n,i,r,l){e.defaults[n]=i,r&&(t[n]=l?(e,t,n)=>{n!=mo&&r(e,t,n)}:r)}e.defineOption=n,e.Init=mo,n("value","",(e,t)=>e.setValue(t),!0),n("mode",null,(e,t)=>{e.doc.modeOption=t,Tr(e)},!0),n("indentUnit",2,Tr,!0),n("indentWithTabs",!1),n("smartIndent",!0),n("tabSize",4,e=>{Nr(e),Rn(e),ui(e)},!0),n("lineSeparator",null,(e,t)=>{if(e.doc.lineSep=t,!t)return;let n=[],i=e.doc.first;e.doc.iter(e=>{for(let r=0;;){let l=e.text.indexOf(t,r);if(-1==l)break;r=l+t.length,n.push(Je(i,l))}i++});for(let i=n.length-1;i>=0;i--)hl(e.doc,t,n[i],Je(n[i].line,n[i].ch+t.length))}),n("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g,(e,t,n)=>{e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),n!=mo&&e.refresh()}),n("specialCharPlaceholder",Zt,e=>e.refresh(),!0),n("electricChars",!0),n("inputStyle",y?"contenteditable":"textarea",()=>{throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),n("spellcheck",!1,(e,t)=>e.getInputField().spellcheck=t,!0),n("autocorrect",!1,(e,t)=>e.getInputField().autocorrect=t,!0),n("autocapitalize",!1,(e,t)=>e.getInputField().autocapitalize=t,!0),n("rtlMoveVisually",!v),n("wholeLineUpdateBefore",!0),n("theme","default",e=>{go(e),dr(e)},!0),n("keyMap","default",(e,t,n)=>{let i=Vl(t),r=n!=mo&&Vl(n);r&&r.detach&&r.detach(e,i),i.attach&&i.attach(e,r||null)}),n("extraKeys",null),n("configureMouse",null),n("lineWrapping",!1,vo,!0),n("gutters",[],(e,t)=>{e.display.gutterSpecs=ur(t,e.options.lineNumbers),dr(e)},!0),n("fixedGutter",!0,(e,t)=>{e.display.gutters.style.left=t?li(e.display)+"px":"0",e.refresh()},!0),n("coverGutterNextToScrollbar",!1,e=>Ii(e),!0),n("scrollbarStyle","native",e=>{Gi(e),Ii(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),n("lineNumbers",!1,(e,t)=>{e.display.gutterSpecs=ur(e.options.gutters,t),dr(e)},!0),n("firstLineNumber",1,dr,!0),n("lineNumberFormatter",e=>e,dr,!0),n("showCursorWhenSelecting",!1,gi,!0),n("resetSelectionOnContextMenu",!0),n("lineWiseCopyCut",!0),n("pasteLinesPerSelection",!0),n("selectionsMayTouch",!1),n("readOnly",!1,(e,t)=>{"nocursor"==t&&(ki(e),e.display.input.blur()),e.display.input.readOnlyChanged(t)}),n("disableInput",!1,(e,t)=>{t||e.display.input.reset()},!0),n("dragDrop",!0,wo),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,Nr,!0),n("addModeClass",!1,Nr,!0),n("pollInterval",100),n("undoDepth",200,(e,t)=>e.doc.history.undoDepth=t),n("historyEventDelay",1250),n("viewportMargin",10,e=>e.refresh(),!0),n("maxHighlightLength",1e4,Nr,!0),n("moveInputWithCursor",!0,(e,t)=>{t||e.display.input.resetPosition()}),n("tabindex",null,(e,t)=>e.display.input.getField().tabIndex=t||""),n("autofocus",null),n("direction","ltr",(e,t)=>e.doc.setDirection(t),!0),n("phrases",null)}(xo),function(e){let t=e.optionHandlers,n=e.helpers={};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,n){let i=this.options,r=i[e];i[e]==n&&"mode"!=e||(i[e]=n,t.hasOwnProperty(e)&&Zi(this,t[e])(this,n,r),pe(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"](Vl(e))},removeKeyMap:function(e){let t=this.state.keyMaps;for(let n=0;ne.priority),this.state.modeGen++,ui(this)})),removeOverlay:Qi((function(e){let t=this.state.overlays;for(let n=0;nn&&(So(this,r.head.line,e,!0),n=r.head.line,i==this.doc.sel.primIndex&&Oi(this));else{let l=r.from(),o=r.to(),s=Math.max(n,l.line);n=Math.min(this.lastLine(),o.line-(o.ch?0:1))+1;for(let t=s;t0&&jr(this.doc,i,new vr(l,a[i].to()),U)}}})),getTokenAt:function(e,t){return yt(this,e,t)},getLineTokens:function(e,t){return yt(this,Je(e),t,!0)},getTokenTypeAt:function(e){e=ot(this.doc,e);let t,n=ht(this,Ke(this.doc,e.line)),i=0,r=(n.length-1)/2,l=e.ch;if(0==l)t=n[2];else for(;;){let e=i+r>>1;if((e?n[2*e-1]:0)>=l)r=e;else{if(!(n[2*e+1]t&&(e=t,r=!0),i=Ke(this.doc,e)}else i=e;return Vn(this,i,{top:0,left:0},t||"page",n||r).top+(r?this.doc.height-Ut(i):0)},defaultTextHeight:function(){return ni(this.display)},defaultCharWidth:function(){return ii(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,n,i,r){let l=this.display,o=(e=$n(this,ot(this.doc,e))).bottom,s=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),l.sizer.appendChild(t),"over"==i)o=e.top;else if("above"==i||"near"==i){let n=Math.max(l.wrapper.clientHeight,this.doc.height),r=Math.max(l.sizer.clientWidth,l.lineSpace.clientWidth);("above"==i||e.bottom+t.offsetHeight>n)&&e.top>t.offsetHeight?o=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=n&&(o=e.bottom),s+t.offsetWidth>r&&(s=r-t.offsetWidth)}t.style.top=o+"px",t.style.left=t.style.right="","right"==r?(s=l.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==r?s=0:"middle"==r&&(s=(l.sizer.clientWidth-t.offsetWidth)/2),t.style.left=s+"px"),n&&function(e,t){let n=Ni(e,t);null!=n.scrollTop&&zi(e,n.scrollTop),null!=n.scrollLeft&&Pi(e,n.scrollLeft)}(this,{left:s,top:o,right:s+t.offsetWidth,bottom:o+t.offsetHeight})},triggerOnKeyDown:Qi(io),triggerOnKeyPress:Qi(lo),triggerOnKeyUp:ro,triggerOnMouseDown:Qi(co),execCommand:function(e){if(Xl.hasOwnProperty(e))return Xl[e].call(null,this)},triggerElectric:Qi((function(e){No(this,e)})),findPosH:function(e,t,n,i){let r=1;t<0&&(r=-1,t=-t);let l=ot(this.doc,e);for(let e=0;ethis.display.shift||this.doc.extend||n.empty()?Wo(this.doc,n.head,e,t,this.options.rtlMoveVisually):e<0?n.from():n.to(),_)})),deleteH:Qi((function(e,t){let n=this.doc.sel,i=this.doc;n.somethingSelected()?i.replaceSelection("",null,"+delete"):_l(this,n=>{let r=Wo(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){let r=1,l=i;t<0&&(r=-1,t=-t);let o=ot(this.doc,e);for(let e=0;e{if(r)return e<0?l.from():l.to();let o=$n(this,l.head,"div");null!=l.goalColumn&&(o.left=l.goalColumn),i.push(o.left);let s=Ho(this,o,e,t);return"page"==t&&l==n.sel.primary()&&Ai(this,Kn(this,s,"div").top-o.top),s},_),i.length)for(let e=0;eee(e,r):/\s/.test(l)?e=>/\s/.test(e):e=>!/\s/.test(e)&&!ee(e);for(;n>0&&o(t.charAt(n-1));)--n;for(;i"number"==typeof e||/^\d+$/.test(String(e))?e+"px":e;null!=e&&(this.display.wrapper.style.width=n(e)),null!=t&&(this.display.wrapper.style.height=n(t)),this.options.lineWrapping&&In(this);let i=this.display.viewFrom;this.doc.iter(i,this.display.viewTo,e=>{if(e.widgets)for(let t=0;t.5)&&si(this),pe(this,"refresh",this)})),swapDoc:Qi((function(e){let t=this.doc;return t.cm=null,this.state.selectingText&&this.state.selectingText(),Wr(this,e),Rn(this),this.display.input.reset(),Di(this,e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,sn(this,"swapDoc",this,t),t})),phrase:function(e){let 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}},be(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,l){e.registerHelper(t,i,l),n[t]._global.push({pred:r,val:l})}}(xo);let Bo="iter insert remove copy getEditor constructor".split(" ");for(let e in Tl.prototype)Tl.prototype.hasOwnProperty(e)&&B(Bo,e)<0&&(xo.prototype[e]=function(e){return function(){return e.apply(this.doc,arguments)}}(Tl.prototype[e]));be(Tl),xo.inputStyles={textarea:Ro,contenteditable:zo},xo.defineMode=function(e){xo.defaults.mode||"null"==e||(xo.defaults.mode=e),Pe.apply(this,arguments)},xo.defineMIME=function(e,t){Fe[e]=t},xo.defineMode("null",()=>({token:e=>e.skipToEnd()})),xo.defineMIME("text/plain","null"),xo.defineExtension=(e,t)=>{xo.prototype[e]=t},xo.defineDocExtension=(e,t)=>{Tl.prototype[e]=t},xo.fromTextArea=function(e,t){if((t=t?E(t):{}).value=e.value,!t.tabindex&&e.tabIndex&&(t.tabindex=e.tabIndex),!t.placeholder&&e.placeholder&&(t.placeholder=e.placeholder),null==t.autofocus){let n=W();t.autofocus=n==e||null!=e.getAttribute("autofocus")&&n==document.body}function n(){e.value=r.getValue()}let i;if(e.form&&(he(e.form,"submit",n),!t.leaveSubmitMethodAlone)){let t=e.form;i=t.submit;try{let e=t.submit=()=>{n(),t.submit=i,t.submit(),t.submit=e}}catch(e){}}t.finishInit=r=>{r.save=n,r.getTextArea=()=>e,r.toTextArea=()=>{r.toTextArea=isNaN,n(),e.parentNode.removeChild(r.getWrapperElement()),e.style.display="",e.form&&(fe(e.form,"submit",n),t.leaveSubmitMethodAlone||"function"!=typeof e.form.submit||(e.form.submit=i))}},e.style.display="none";let r=xo(t=>e.parentNode.insertBefore(t,e.nextSibling),t);return r},function(e){e.off=fe,e.on=he,e.wheelEventPixels=yr,e.Doc=Tl,e.splitLines=Oe,e.countColumn=I,e.findColumn=K,e.isWordChar=J,e.Pass=G,e.signal=pe,e.Line=Kt,e.changeEnd=Sr,e.scrollbarModel=Bi,e.Pos=Je,e.cmpPos=et,e.modes=ze,e.mimeModes=Fe,e.resolveMode=Ee,e.getMode=Ie,e.modeExtensions=Re,e.extendMode=Be,e.copyState=Ge,e.startState=Ve,e.innerMode=Ue,e.commands=Xl,e.keyMap=Pl,e.keyName=Ul,e.isModifierKey=Bl,e.lookupKey=Rl,e.normalizeKeyMap=Il,e.StringStream=_e,e.SharedTextMarker=Sl,e.TextMarker=xl,e.LineWidget=bl,e.e_preventDefault=we,e.e_stopPropagation=ve,e.e_stop=Ce,e.addClass=H,e.contains=D,e.rmClass=L,e.keyNames=Fl}(xo),xo.version="5.52.2",self.CodeMirror=xo;class Go extends HTMLElement{static get observedAttributes(){return["src"]}attributeChangedCallback(e,t,n){this.__initialized&&t!==n&&(this[e]=n)}get src(){return this.getAttribute("src")}set src(e){this.setAttribute("src",e),this.setSrc()}get value(){return this.__editor.getValue()}set value(e){this.setValue(e)}constructor(){super();const e=document.createElement("template");e.innerHTML=Go.template(),this.appendChild(e.content.cloneNode(!0)),this.__initialized=!1,this.__element=null,this.__editor=null}async connectedCallback(){this.__element=this.querySelector("#code"),this.__element.style=this.hasAttribute("style")?this.style.cssText:"width:100%;height:100%";const e=this.hasAttribute("mode")?this.getAttribute("mode"):"null",t=this.hasAttribute("theme")?this.getAttribute("theme"):"default";this.__editor=xo.fromTextArea(this.__element,{lineNumbers:!0,readOnly:!1,mode:e,theme:t}),this.hasAttribute("src")?this.setSrc(this.getAttribute("src")):(await new Promise(e=>setTimeout(e,50)),this.setValue("")),this.__initialized=!0}async setSrc(){const e=this.getAttribute("src"),t=await this.fetchSrc(e);this.__editor.swapDoc(xo.Doc(t,this.getAttribute("mode"))),this.__editor.refresh()}async setValue(e){this.__editor.swapDoc(xo.Doc(e,this.getAttribute("mode"))),this.__editor.refresh()}async fetchSrc(e){return(await fetch(e)).text()}static template(){return"\n \n \n \n "}}customElements.define("wc-codemirror",Go);export{Go as WCCodeMirror}; diff --git a/src/wc-codemirror.js b/src/wc-codemirror.js index 58b530d..8cfad76 100644 --- a/src/wc-codemirror.js +++ b/src/wc-codemirror.js @@ -4,7 +4,7 @@ self.CodeMirror = CodeMirror; export class WCCodeMirror extends HTMLElement { static get observedAttributes () { - return ['src', 'value']; + return ['src']; } attributeChangedCallback (name, oldValue, newValue) { @@ -18,12 +18,11 @@ export class WCCodeMirror extends HTMLElement { set src (value) { this.setAttribute('src', value); this.setSrc(); - this.__editor.refresh(); } get value () { return this.__editor.getValue(); } set value (value) { - this.__editor.swapDoc(CodeMirror.Doc(value), this.getAttribute('mode')); + this.setValue(value); } constructor () { @@ -39,17 +38,9 @@ export class WCCodeMirror extends HTMLElement { async connectedCallback () { this.__element = this.querySelector('#code'); this.__element.style = this.hasAttribute('style') ? this.style.cssText : 'width:100%;height:100%'; - this.appendChild(this.__element); - if (this.hasAttribute('src')) { - const src = this.getAttribute('src'); - this.__element.value = await this.fetchSrc(src); - } else { - this.__element.value = ''; - } - - const mode = this.getAttribute('mode') || 'null'; - const theme = this.getAttribute('theme') || 'default'; + const mode = this.hasAttribute('mode') ? this.getAttribute('mode') : 'null'; + const theme = this.hasAttribute('theme') ? this.getAttribute('theme') : 'default'; this.__editor = CodeMirror.fromTextArea(this.__element, { lineNumbers: true, @@ -58,6 +49,14 @@ export class WCCodeMirror extends HTMLElement { theme }); + if (this.hasAttribute('src')) { + this.setSrc(this.getAttribute('src')); + } else { + // delay until editor initializes + await new Promise(resolve => setTimeout(resolve, 50)); + this.setValue(''); + } + this.__initialized = true; } @@ -65,6 +64,12 @@ export class WCCodeMirror extends HTMLElement { const src = this.getAttribute('src'); const contents = await this.fetchSrc(src); this.__editor.swapDoc(CodeMirror.Doc(contents, this.getAttribute('mode'))); + this.__editor.refresh(); + } + + async setValue (value) { + this.__editor.swapDoc(CodeMirror.Doc(value, this.getAttribute('mode'))); + this.__editor.refresh(); } async fetchSrc (src) {