UNPKG

react-ui-playground

Version:

A pruned live jsx editor from React.

12 lines 1 MB
/** * react-ui-playground v2.0.1 * * Copyright 2016-present, 王健(Jason Wang), contributors. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("React"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["React","ReactDOM"],t):"object"==typeof exports?exports.ReactPlayground=t(require("React"),require("ReactDOM")):e.ReactPlayground=t(e.React,e.ReactDOM)}(this,function(__WEBPACK_EXTERNAL_MODULE_6__,__WEBPACK_EXTERNAL_MODULE_7__){return function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=22)}([function(e,t,r){!function(t,r){e.exports=r()}(this,function(){"use strict";function e(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function t(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function r(e,r){return t(e).appendChild(r)}function n(e,t,r,n){var i=document.createElement(e);if(r&&(i.className=r),n&&(i.style.cssText=n),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o<t.length;++o)i.appendChild(t[o]);return i}function i(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do if(11==t.nodeType&&(t=t.host),t==e)return!0;while(t=t.parentNode)}function o(){var e;try{e=document.activeElement}catch(t){e=document.body||null}for(;e&&e.root&&e.root.activeElement;)e=e.root.activeElement;return e}function s(t,r){var n=t.className;e(r).test(n)||(t.className+=(n?" ":"")+r)}function a(t,r){for(var n=t.split(" "),i=0;i<n.length;i++)n[i]&&!e(n[i]).test(r)&&(r+=" "+n[i]);return r}function u(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function l(e,t,r){t||(t={});for(var n in e)!e.hasOwnProperty(n)||r===!1&&t.hasOwnProperty(n)||(t[n]=e[n]);return t}function c(e,t,r,n,i){null==t&&(t=e.search(/[^\s\u00a0]/),t==-1&&(t=e.length));for(var o=n||0,s=i||0;;){var a=e.indexOf("\t",o);if(a<0||a>=t)return s+(t-o);s+=a-o,s+=r-s%r,o=a+1}}function f(){this.id=null}function p(e,t){for(var r=0;r<e.length;++r)if(e[r]==t)return r;return-1}function d(e,t,r){for(var n=0,i=0;;){var o=e.indexOf("\t",n);o==-1&&(o=e.length);var s=o-n;if(o==e.length||i+s>=t)return n+Math.min(s,t-i);if(i+=o-n,i+=r-i%r,n=o+1,i>=t)return n}}function h(e){for(;Ts.length<=e;)Ts.push(m(Ts)+" ");return Ts[e]}function m(e){return e[e.length-1]}function v(e,t){for(var r=[],n=0;n<e.length;n++)r[n]=t(e[n],n);return r}function g(e,t,r){for(var n=0,i=r(t);n<e.length&&r(e[n])<=i;)n++;e.splice(n,0,t)}function y(){}function b(e,t){var r;return Object.create?r=Object.create(e):(y.prototype=e,r=new y),t&&l(t,r),r}function x(e){return/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||Ps.test(e))}function E(e,t){return t?!!(t.source.indexOf("\\w")>-1&&x(e))||t.test(e):x(e)}function A(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function C(e){return e.charCodeAt(0)>=768&&Os.test(e)}function w(e,t,r){var i=this;this.input=r,i.scrollbarFiller=n("div",null,"CodeMirror-scrollbar-filler"),i.scrollbarFiller.setAttribute("cm-not-content","true"),i.gutterFiller=n("div",null,"CodeMirror-gutter-filler"),i.gutterFiller.setAttribute("cm-not-content","true"),i.lineDiv=n("div",null,"CodeMirror-code"),i.selectionDiv=n("div",null,null,"position: relative; z-index: 1"),i.cursorDiv=n("div",null,"CodeMirror-cursors"),i.measure=n("div",null,"CodeMirror-measure"),i.lineMeasure=n("div",null,"CodeMirror-measure"),i.lineSpace=n("div",[i.measure,i.lineMeasure,i.selectionDiv,i.cursorDiv,i.lineDiv],null,"position: relative; outline: none"),i.mover=n("div",[n("div",[i.lineSpace],"CodeMirror-lines")],null,"position: relative"),i.sizer=n("div",[i.mover],"CodeMirror-sizer"),i.sizerWidth=null,i.heightForcer=n("div",null,null,"position: absolute; height: "+ws+"px; width: 1px;"),i.gutters=n("div",null,"CodeMirror-gutters"),i.lineGutter=null,i.scroller=n("div",[i.sizer,i.heightForcer,i.gutters],"CodeMirror-scroll"),i.scroller.setAttribute("tabIndex","-1"),i.wrapper=n("div",[i.scrollbarFiller,i.gutterFiller,i.scroller],"CodeMirror"),rs&&ns<8&&(i.gutters.style.zIndex=-1,i.scroller.style.paddingRight=0),is||Zo&&ps||(i.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(i.wrapper):e(i.wrapper)),i.viewFrom=i.viewTo=t.first,i.reportedViewFrom=i.reportedViewTo=t.first,i.view=[],i.renderedView=null,i.externalMeasured=null,i.viewOffset=0,i.lastWrapHeight=i.lastWrapWidth=0,i.updateLineNumbers=null,i.nativeBarWidth=i.barHeight=i.barWidth=0,i.scrollbarsClipped=!1,i.lineNumWidth=i.lineNumInnerWidth=i.lineNumChars=null,i.alignWidgets=!1,i.cachedCharWidth=i.cachedTextHeight=i.cachedPaddingH=null,i.maxLine=null,i.maxLineLength=0,i.maxLineChanged=!1,i.wheelDX=i.wheelDY=i.wheelStartX=i.wheelStartY=null,i.shift=!1,i.selForContextMenu=null,i.activeTouch=null,r.init(i)}function S(e,t){if(t-=e.first,t<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var r=e;!r.lines;)for(var n=0;;++n){var i=r.children[n],o=i.chunkSize();if(t<o){r=i;break}t-=o}return r.lines[t]}function _(e,t,r){var n=[],i=t.line;return e.iter(t.line,r.line+1,function(e){var o=e.text;i==r.line&&(o=o.slice(0,r.ch)),i==t.line&&(o=o.slice(t.ch)),n.push(o),++i}),n}function D(e,t,r){var n=[];return e.iter(t,r,function(e){n.push(e.text)}),n}function k(e,t){var r=t-e.height;if(r)for(var n=e;n;n=n.parent)n.height+=r}function T(e){if(null==e.parent)return null;for(var t=e.parent,r=p(t.lines,e),n=t.parent;n;t=n,n=n.parent)for(var i=0;n.children[i]!=t;++i)r+=n.children[i].chunkSize();return r+t.first}function P(e,t){var r=e.first;e:do{for(var n=0;n<e.children.length;++n){var i=e.children[n],o=i.height;if(t<o){e=i;continue e}t-=o,r+=i.chunkSize()}return r}while(!e.lines);for(var s=0;s<e.lines.length;++s){var a=e.lines[s],u=a.height;if(t<u)break;t-=u}return r+s}function O(e,t){return t>=e.first&&t<e.first+e.size}function F(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function M(e,t){return this instanceof M?(this.line=e,void(this.ch=t)):new M(e,t)}function B(e,t){return e.line-t.line||e.ch-t.ch}function R(e){return M(e.line,e.ch)}function L(e,t){return B(e,t)<0?t:e}function I(e,t){return B(e,t)<0?e:t}function N(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function j(e,t){if(t.line<e.first)return M(e.first,0);var r=e.first+e.size-1;return t.line>r?M(r,S(e,r).text.length):U(t,S(e,t.line).text.length)}function U(e,t){var r=e.ch;return null==r||r>t?M(e.line,t):r<0?M(e.line,0):e}function W(e,t){for(var r=[],n=0;n<t.length;n++)r[n]=j(e,t[n]);return r}function V(){Fs=!0}function G(){Ms=!0}function H(e,t,r){this.marker=e,this.from=t,this.to=r}function Y(e,t){if(e)for(var r=0;r<e.length;++r){var n=e[r];if(n.marker==t)return n}}function z(e,t){for(var r,n=0;n<e.length;++n)e[n]!=t&&(r||(r=[])).push(e[n]);return r}function q(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}function K(e,t,r){var n;if(e)for(var i=0;i<e.length;++i){var o=e[i],s=o.marker,a=null==o.from||(s.inclusiveLeft?o.from<=t:o.from<t);if(a||o.from==t&&"bookmark"==s.type&&(!r||!o.marker.insertLeft)){var u=null==o.to||(s.inclusiveRight?o.to>=t:o.to>t);(n||(n=[])).push(new H(s,o.from,u?null:o.to))}}return n}function X(e,t,r){var n;if(e)for(var i=0;i<e.length;++i){var o=e[i],s=o.marker,a=null==o.to||(s.inclusiveRight?o.to>=t:o.to>t);if(a||o.from==t&&"bookmark"==s.type&&(!r||o.marker.insertLeft)){var u=null==o.from||(s.inclusiveLeft?o.from<=t:o.from<t);(n||(n=[])).push(new H(s,u?null:o.from-t,null==o.to?null:o.to-t))}}return n}function J(e,t){if(t.full)return null;var r=O(e,t.from.line)&&S(e,t.from.line).markedSpans,n=O(e,t.to.line)&&S(e,t.to.line).markedSpans;if(!r&&!n)return null;var i=t.from.ch,o=t.to.ch,s=0==B(t.from,t.to),a=K(r,i,s),u=X(n,o,s),l=1==t.text.length,c=m(t.text).length+(l?i:0);if(a)for(var f=0;f<a.length;++f){var p=a[f];if(null==p.to){var d=Y(u,p.marker);d?l&&(p.to=null==d.to?null:d.to+c):p.to=i}}if(u)for(var h=0;h<u.length;++h){var v=u[h];if(null!=v.to&&(v.to+=c),null==v.from){var g=Y(a,v.marker);g||(v.from=c,l&&(a||(a=[])).push(v))}else v.from+=c,l&&(a||(a=[])).push(v)}a&&(a=$(a)),u&&u!=a&&(u=$(u));var y=[a];if(!l){var b,x=t.text.length-2;if(x>0&&a)for(var E=0;E<a.length;++E)null==a[E].to&&(b||(b=[])).push(new H(a[E].marker,null,null));for(var A=0;A<x;++A)y.push(b);y.push(u)}return y}function $(e){for(var t=0;t<e.length;++t){var r=e[t];null!=r.from&&r.from==r.to&&r.marker.clearWhenEmpty!==!1&&e.splice(t--,1)}return e.length?e:null}function Q(e,t,r){var n=null;if(e.iter(t.line,r.line+1,function(e){if(e.markedSpans)for(var t=0;t<e.markedSpans.length;++t){var r=e.markedSpans[t].marker;!r.readOnly||n&&p(n,r)!=-1||(n||(n=[])).push(r)}}),!n)return null;for(var i=[{from:t,to:r}],o=0;o<n.length;++o)for(var s=n[o],a=s.find(0),u=0;u<i.length;++u){var l=i[u];if(!(B(l.to,a.from)<0||B(l.from,a.to)>0)){var c=[u,1],f=B(l.from,a.from),d=B(l.to,a.to);(f<0||!s.inclusiveLeft&&!f)&&c.push({from:l.from,to:a.from}),(d>0||!s.inclusiveRight&&!d)&&c.push({from:a.to,to:l.to}),i.splice.apply(i,c),u+=c.length-1}}return i}function Z(e){var t=e.markedSpans;if(t){for(var r=0;r<t.length;++r)t[r].marker.detachLine(e);e.markedSpans=null}}function ee(e,t){if(t){for(var r=0;r<t.length;++r)t[r].marker.attachLine(e);e.markedSpans=t}}function te(e){return e.inclusiveLeft?-1:0}function re(e){return e.inclusiveRight?1:0}function ne(e,t){var r=e.lines.length-t.lines.length;if(0!=r)return r;var n=e.find(),i=t.find(),o=B(n.from,i.from)||te(e)-te(t);if(o)return-o;var s=B(n.to,i.to)||re(e)-re(t);return s?s:t.id-e.id}function ie(e,t){var r,n=Ms&&e.markedSpans;if(n)for(var i=void 0,o=0;o<n.length;++o)i=n[o],i.marker.collapsed&&null==(t?i.from:i.to)&&(!r||ne(r,i.marker)<0)&&(r=i.marker);return r}function oe(e){return ie(e,!0)}function se(e){return ie(e,!1)}function ae(e,t,r,n,i){var o=S(e,t),s=Ms&&o.markedSpans;if(s)for(var a=0;a<s.length;++a){var u=s[a];if(u.marker.collapsed){var l=u.marker.find(0),c=B(l.from,r)||te(u.marker)-te(i),f=B(l.to,n)||re(u.marker)-re(i);if(!(c>=0&&f<=0||c<=0&&f>=0)&&(c<=0&&(u.marker.inclusiveRight&&i.inclusiveLeft?B(l.to,r)>=0:B(l.to,r)>0)||c>=0&&(u.marker.inclusiveRight&&i.inclusiveLeft?B(l.from,n)<=0:B(l.from,n)<0)))return!0}}}function ue(e){for(var t;t=oe(e);)e=t.find(-1,!0).line;return e}function le(e){for(var t,r;t=se(e);)e=t.find(1,!0).line,(r||(r=[])).push(e);return r}function ce(e,t){var r=S(e,t),n=ue(r);return r==n?t:T(n)}function fe(e,t){if(t>e.lastLine())return t;var r,n=S(e,t);if(!pe(e,n))return t;for(;r=se(n);)n=r.find(1,!0).line;return T(n)+1}function pe(e,t){var r=Ms&&t.markedSpans;if(r)for(var n=void 0,i=0;i<r.length;++i)if(n=r[i],n.marker.collapsed){if(null==n.from)return!0;if(!n.marker.widgetNode&&0==n.from&&n.marker.inclusiveLeft&&de(e,t,n))return!0}}function de(e,t,r){if(null==r.to){var n=r.marker.find(1,!0);return de(e,n.line,Y(n.line.markedSpans,r.marker))}if(r.marker.inclusiveRight&&r.to==t.text.length)return!0;for(var i=void 0,o=0;o<t.markedSpans.length;++o)if(i=t.markedSpans[o],i.marker.collapsed&&!i.marker.widgetNode&&i.from==r.to&&(null==i.to||i.to!=r.from)&&(i.marker.inclusiveLeft||r.marker.inclusiveRight)&&de(e,t,i))return!0}function he(e){e=ue(e);for(var t=0,r=e.parent,n=0;n<r.lines.length;++n){var i=r.lines[n];if(i==e)break;t+=i.height}for(var o=r.parent;o;r=o,o=r.parent)for(var s=0;s<o.children.length;++s){var a=o.children[s];if(a==r)break;t+=a.height}return t}function me(e){if(0==e.height)return 0;for(var t,r=e.text.length,n=e;t=oe(n);){var i=t.find(0,!0);n=i.from.line,r+=i.from.ch-i.to.ch}for(n=e;t=se(n);){var o=t.find(0,!0);r-=n.text.length-o.from.ch,n=o.to.line,r+=n.text.length-o.to.ch}return r}function ve(e){var t=e.display,r=e.doc;t.maxLine=S(r,r.first),t.maxLineLength=me(t.maxLine),t.maxLineChanged=!0,r.iter(function(e){var r=me(e);r>t.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function ge(e,t,r,n){if(!e)return n(t,r,"ltr");for(var i=!1,o=0;o<e.length;++o){var s=e[o];(s.from<r&&s.to>t||t==r&&s.to==t)&&(n(Math.max(s.from,t),Math.min(s.to,r),1==s.level?"rtl":"ltr"),i=!0)}i||n(t,r,"ltr")}function ye(e){return e.level%2?e.to:e.from}function be(e){return e.level%2?e.from:e.to}function xe(e){var t=De(e);return t?ye(t[0]):0}function Ee(e){var t=De(e);return t?be(m(t)):e.text.length}function Ae(e,t,r){var n=e[0].level;return t==n||r!=n&&t<r}function Ce(e,t){var r;Bs=null;for(var n=0;n<e.length;++n){var i=e[n];if(i.from<t&&i.to>t)return n;if(i.from==t||i.to==t){if(null!=r)return Ae(e,i.level,e[r].level)?(i.from!=i.to&&(Bs=r),n):(i.from!=i.to&&(Bs=n),r);r=n}}return r}function we(e,t,r,n){if(!n)return t+r;do t+=r;while(t>0&&C(e.text.charAt(t)));return t}function Se(e,t,r,n){var i=De(e);if(!i)return _e(e,t,r,n);for(var o=Ce(i,t),s=i[o],a=we(e,t,s.level%2?-r:r,n);;){if(a>s.from&&a<s.to)return a;if(a==s.from||a==s.to)return Ce(i,a)==o?a:(s=i[o+=r],r>0==s.level%2?s.to:s.from);if(s=i[o+=r],!s)return null;a=r>0==s.level%2?we(e,s.to,-1,n):we(e,s.from,1,n)}}function _e(e,t,r,n){var i=t+r;if(n)for(;i>0&&C(e.text.charAt(i));)i+=r;return i<0||i>e.text.length?null:i}function De(e){var t=e.order;return null==t&&(t=e.order=Rs(e.text)),t}function ke(e,t){return e._handlers&&e._handlers[t]||Ls}function Te(e,t,r){if(e.removeEventListener)e.removeEventListener(t,r,!1);else if(e.detachEvent)e.detachEvent("on"+t,r);else{var n=e._handlers,i=n&&n[t];if(i){var o=p(i,r);o>-1&&(n[t]=i.slice(0,o).concat(i.slice(o+1)))}}}function Pe(e,t){var r=ke(e,t);if(r.length)for(var n=Array.prototype.slice.call(arguments,2),i=0;i<r.length;++i)r[i].apply(null,n)}function Oe(e,t,r){return"string"==typeof t&&(t={type:t,preventDefault:function(){this.defaultPrevented=!0}}),Pe(e,r||t.type,e,t),Ie(t)||t.codemirrorIgnore}function Fe(e){var t=e._handlers&&e._handlers.cursorActivity;if(t)for(var r=e.curOp.cursorActivityHandlers||(e.curOp.cursorActivityHandlers=[]),n=0;n<t.length;++n)p(r,t[n])==-1&&r.push(t[n])}function Me(e,t){return ke(e,t).length>0}function Be(e){e.prototype.on=function(e,t){Is(this,e,t)},e.prototype.off=function(e,t){Te(this,e,t)}}function Re(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function Le(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function Ie(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function Ne(e){Re(e),Le(e)}function je(e){return e.target||e.srcElement}function Ue(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),ds&&e.ctrlKey&&1==t&&(t=3),t}function We(e){if(null==As){var t=n("span","​");r(e,n("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(As=t.offsetWidth<=1&&t.offsetHeight>2&&!(rs&&ns<8))}var i=As?n("span","​"):n("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return i.setAttribute("cm-text",""),i}function Ve(e){if(null!=Cs)return Cs;var n=r(e,document.createTextNode("AخA")),i=gs(n,0,1).getBoundingClientRect(),o=gs(n,1,2).getBoundingClientRect();return t(e),!(!i||i.left==i.right)&&(Cs=o.right-i.right<3)}function Ge(e){if(null!=Vs)return Vs;var t=r(e,n("span","x")),i=t.getBoundingClientRect(),o=gs(t,0,1).getBoundingClientRect();return Vs=Math.abs(i.left-o.left)>1}function He(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),Gs[e]=t}function Ye(e,t){Hs[e]=t}function ze(e){if("string"==typeof e&&Hs.hasOwnProperty(e))e=Hs[e];else if(e&&"string"==typeof e.name&&Hs.hasOwnProperty(e.name)){var t=Hs[e.name];"string"==typeof t&&(t={name:t}),e=b(t,e),e.name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return ze("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return ze("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function qe(e,t){t=ze(t);var r=Gs[t.name];if(!r)return qe(e,"text/plain");var n=r(e,t);if(Ys.hasOwnProperty(t.name)){var i=Ys[t.name];for(var o in i)i.hasOwnProperty(o)&&(n.hasOwnProperty(o)&&(n["_"+o]=n[o]),n[o]=i[o])}if(n.name=t.name,t.helperType&&(n.helperType=t.helperType),t.modeProps)for(var s in t.modeProps)n[s]=t.modeProps[s];return n}function Ke(e,t){var r=Ys.hasOwnProperty(e)?Ys[e]:Ys[e]={};l(t,r)}function Xe(e,t){if(t===!0)return t;if(e.copyState)return e.copyState(t);var r={};for(var n in t){var i=t[n];i instanceof Array&&(i=i.concat([])),r[n]=i}return r}function Je(e,t){for(var r;e.innerMode&&(r=e.innerMode(t),r&&r.mode!=e);)t=r.state,e=r.mode;return r||{mode:e,state:t}}function $e(e,t,r){return!e.startState||e.startState(t,r)}function Qe(e,t,r,n){var i=[e.state.modeGen],o={};st(e,t.text,e.doc.mode,r,function(e,t){return i.push(e,t)},o,n);for(var s=function(r){var n=e.state.overlays[r],s=1,a=0;st(e,t.text,n.mode,!0,function(e,t){for(var r=s;a<e;){var o=i[s];o>e&&i.splice(s,1,e,i[s+1],o),s+=2,a=Math.min(e,o)}if(t)if(n.opaque)i.splice(r,s-r,e,"overlay "+t),s=r+2;else for(;r<s;r+=2){var u=i[r+1];i[r+1]=(u?u+" ":"")+"overlay "+t}},o)},a=0;a<e.state.overlays.length;++a)s(a);return{styles:i,classes:o.bgClass||o.textClass?o:null}}function Ze(e,t,r){if(!t.styles||t.styles[0]!=e.state.modeGen){var n=et(e,T(t)),i=Qe(e,t,t.text.length>e.options.maxHighlightLength?Xe(e.doc.mode,n):n);t.stateAfter=n,t.styles=i.styles,i.classes?t.styleClasses=i.classes:t.styleClasses&&(t.styleClasses=null),r===e.doc.frontier&&e.doc.frontier++}return t.styles}function et(e,t,r){var n=e.doc,i=e.display;if(!n.mode.startState)return!0;var o=at(e,t,r),s=o>n.first&&S(n,o-1).stateAfter;return s=s?Xe(n.mode,s):$e(n.mode),n.iter(o,t,function(r){tt(e,r.text,s);var a=o==t-1||o%5==0||o>=i.viewFrom&&o<i.viewTo;r.stateAfter=a?Xe(n.mode,s):null,++o}),r&&(n.frontier=o),s}function tt(e,t,r,n){var i=e.doc.mode,o=new zs(t,e.options.tabSize);for(o.start=o.pos=n||0,""==t&&rt(i,r);!o.eol();)nt(i,o,r),o.start=o.pos}function rt(e,t){if(e.blankLine)return e.blankLine(t);if(e.innerMode){var r=Je(e,t);return r.mode.blankLine?r.mode.blankLine(r.state):void 0}}function nt(e,t,r,n){for(var i=0;i<10;i++){n&&(n[0]=Je(e,r).mode);var o=e.token(t,r);if(t.pos>t.start)return o}throw new Error("Mode "+e.name+" failed to advance stream.")}function it(e,t,r,n){var i,o=function(e){return{start:f.start,end:f.pos,string:f.current(),type:i||null,state:e?Xe(s.mode,c):c}},s=e.doc,a=s.mode;t=j(s,t);var u,l=S(s,t.line),c=et(e,t.line,r),f=new zs(l.text,e.options.tabSize);for(n&&(u=[]);(n||f.pos<t.ch)&&!f.eol();)f.start=f.pos,i=nt(a,f,c),n&&u.push(o(!0));return n?u:o()}function ot(e,t){if(e)for(;;){var r=e.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!r)break;e=e.slice(0,r.index)+e.slice(r.index+r[0].length);var n=r[1]?"bgClass":"textClass";null==t[n]?t[n]=r[2]:new RegExp("(?:^|s)"+r[2]+"(?:$|s)").test(t[n])||(t[n]+=" "+r[2])}return e}function st(e,t,r,n,i,o,s){var a=r.flattenSpans;null==a&&(a=e.options.flattenSpans);var u,l=0,c=null,f=new zs(t,e.options.tabSize),p=e.options.addModeClass&&[null];for(""==t&&ot(rt(r,n),o);!f.eol();){if(f.pos>e.options.maxHighlightLength?(a=!1,s&&tt(e,t,n,f.pos),f.pos=t.length,u=null):u=ot(nt(r,f,n,p),o),p){var d=p[0].name;d&&(u="m-"+(u?d+" "+u:d))}if(!a||c!=u){for(;l<f.start;)l=Math.min(f.start,l+5e3),i(l,c);c=u}f.start=f.pos}for(;l<f.pos;){var h=Math.min(f.pos,l+5e3);i(h,c),l=h}}function at(e,t,r){for(var n,i,o=e.doc,s=r?-1:t-(e.doc.mode.innerMode?1e3:100),a=t;a>s;--a){if(a<=o.first)return o.first;var u=S(o,a-1);if(u.stateAfter&&(!r||a<=o.frontier))return a;var l=c(u.text,null,e.options.tabSize);(null==i||n>l)&&(i=a-1,n=l)}return i}function ut(e,t,r){this.text=e,ee(this,t),this.height=r?r(this):1}function lt(e,t,r,n){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),null!=e.order&&(e.order=null),Z(e),ee(e,r);var i=n?n(e):1;i!=e.height&&k(e,i)}function ct(e){e.parent=null,Z(e)}function ft(e,t){if(!e||/^\s*$/.test(e))return null;var r=t.addModeClass?Xs:Ks;return r[e]||(r[e]=e.replace(/\S+/g,"cm-$&"))}function pt(e,t){var r=n("span",null,null,is?"padding-right: .1px":null),i={pre:n("pre",[r],"CodeMirror-line"),content:r,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:(rs||is)&&e.getOption("lineWrapping")};r.setAttribute("role","presentation"),i.pre.setAttribute("role","presentation"),t.measure={};for(var o=0;o<=(t.rest?t.rest.length:0);o++){var s=o?t.rest[o-1]:t.line,u=void 0;i.pos=0,i.addToken=ht,Ve(e.display.measure)&&(u=De(s))&&(i.addToken=vt(i.addToken,u)),i.map=[];var l=t!=e.display.externalMeasured&&T(s);yt(s,i,Ze(e,s,l)),s.styleClasses&&(s.styleClasses.bgClass&&(i.bgClass=a(s.styleClasses.bgClass,i.bgClass||"")),s.styleClasses.textClass&&(i.textClass=a(s.styleClasses.textClass,i.textClass||""))),0==i.map.length&&i.map.push(0,0,i.content.appendChild(We(e.display.measure))),0==o?(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(is){var c=i.content.lastChild;(/\bcm-tab\b/.test(c.className)||c.querySelector&&c.querySelector(".cm-tab"))&&(i.content.className="cm-tab-wrap-hack")}return Pe(e,"renderLine",e,t.line,i.pre),i.pre.className&&(i.textClass=a(i.pre.className,i.textClass||"")),i}function dt(e){var t=n("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function ht(e,t,r,i,o,s,a){if(t){var u,l=e.splitSpaces?mt(t,e.trailingSpace):t,c=e.cm.state.specialChars,f=!1;if(c.test(t)){u=document.createDocumentFragment();for(var p=0;;){c.lastIndex=p;var d=c.exec(t),m=d?d.index-p:t.length-p;if(m){var v=document.createTextNode(l.slice(p,p+m));rs&&ns<9?u.appendChild(n("span",[v])):u.appendChild(v),e.map.push(e.pos,e.pos+m,v),e.col+=m,e.pos+=m}if(!d)break;p+=m+1;var g=void 0;if("\t"==d[0]){var y=e.cm.options.tabSize,b=y-e.col%y;g=u.appendChild(n("span",h(b),"cm-tab")),g.setAttribute("role","presentation"),g.setAttribute("cm-text","\t"),e.col+=b}else"\r"==d[0]||"\n"==d[0]?(g=u.appendChild(n("span","\r"==d[0]?"␍":"␤","cm-invalidchar")),g.setAttribute("cm-text",d[0]),e.col+=1):(g=e.cm.options.specialCharPlaceholder(d[0]),g.setAttribute("cm-text",d[0]),rs&&ns<9?u.appendChild(n("span",[g])):u.appendChild(g),e.col+=1);e.map.push(e.pos,e.pos+1,g),e.pos++}}else e.col+=t.length,u=document.createTextNode(l),e.map.push(e.pos,e.pos+t.length,u),rs&&ns<9&&(f=!0),e.pos+=t.length;if(e.trailingSpace=32==l.charCodeAt(t.length-1),r||i||o||f||a){var x=r||"";i&&(x+=i),o&&(x+=o);var E=n("span",[u],x,a);return s&&(E.title=s),e.content.appendChild(E)}e.content.appendChild(u)}}function mt(e,t){if(e.length>1&&!/ /.test(e))return e;for(var r=t,n="",i=0;i<e.length;i++){var o=e.charAt(i);" "!=o||!r||i!=e.length-1&&32!=e.charCodeAt(i+1)||(o=" "),n+=o,r=" "==o}return n}function vt(e,t){return function(r,n,i,o,s,a,u){i=i?i+" cm-force-border":"cm-force-border";for(var l=r.pos,c=l+n.length;;){for(var f=void 0,p=0;p<t.length&&(f=t[p],!(f.to>l&&f.from<=l));p++);if(f.to>=c)return e(r,n,i,o,s,a,u);e(r,n.slice(0,f.to-l),i,o,null,a,u),o=null,n=n.slice(f.to-l),l=f.to}}}function gt(e,t,r,n){var i=!n&&r.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!n&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",r.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t,e.trailingSpace=!1}function yt(e,t,r){var n=e.markedSpans,i=e.text,o=0;if(n)for(var s,a,u,l,c,f,p,d=i.length,h=0,m=1,v="",g=0;;){if(g==h){u=l=c=f=a="",p=null,g=1/0;for(var y=[],b=void 0,x=0;x<n.length;++x){var E=n[x],A=E.marker;"bookmark"==A.type&&E.from==h&&A.widgetNode?y.push(A):E.from<=h&&(null==E.to||E.to>h||A.collapsed&&E.to==h&&E.from==h)?(null!=E.to&&E.to!=h&&g>E.to&&(g=E.to,l=""),A.className&&(u+=" "+A.className),A.css&&(a=(a?a+";":"")+A.css),A.startStyle&&E.from==h&&(c+=" "+A.startStyle),A.endStyle&&E.to==g&&(b||(b=[])).push(A.endStyle,E.to),A.title&&!f&&(f=A.title),A.collapsed&&(!p||ne(p.marker,A)<0)&&(p=E)):E.from>h&&g>E.from&&(g=E.from)}if(b)for(var C=0;C<b.length;C+=2)b[C+1]==g&&(l+=" "+b[C]);if(!p||p.from==h)for(var w=0;w<y.length;++w)gt(t,0,y[w]);if(p&&(p.from||0)==h){if(gt(t,(null==p.to?d+1:p.to)-h,p.marker,null==p.from),null==p.to)return;p.to==h&&(p=!1)}}if(h>=d)break;for(var S=Math.min(d,g);;){if(v){var _=h+v.length;if(!p){var D=_>S?v.slice(0,S-h):v;t.addToken(t,D,s?s+u:u,c,h+D.length==g?l:"",f,a)}if(_>=S){v=v.slice(S-h),h=S;break}h=_,c=""}v=i.slice(o,o=r[m++]),s=ft(r[m++],t.cm.options)}}else for(var k=1;k<r.length;k+=2)t.addToken(t,i.slice(o,o=r[k]),ft(r[k+1],t.cm.options))}function bt(e,t,r){this.line=t,this.rest=le(t),this.size=this.rest?T(m(this.rest))-r+1:1,this.node=this.text=null,this.hidden=pe(e,t)}function xt(e,t,r){for(var n,i=[],o=t;o<r;o=n){var s=new bt(e.doc,S(e.doc,o),o);n=o+s.size,i.push(s)}return i}function Et(e){Js?Js.ops.push(e):e.ownsGroup=Js={ops:[e],delayedCallbacks:[]}}function At(e){var t=e.delayedCallbacks,r=0;do{for(;r<t.length;r++)t[r].call(null);for(var n=0;n<e.ops.length;n++){var i=e.ops[n];if(i.cursorActivityHandlers)for(;i.cursorActivityCalled<i.cursorActivityHandlers.length;)i.cursorActivityHandlers[i.cursorActivityCalled++].call(null,i.cm)}}while(r<t.length)}function Ct(e,t){var r=e.ownsGroup;if(r)try{At(r)}finally{Js=null,t(r)}}function wt(e,t){var r=ke(e,t);if(r.length){var n,i=Array.prototype.slice.call(arguments,2);Js?n=Js.delayedCallbacks:$s?n=$s:(n=$s=[],setTimeout(St,0));for(var o=function(e){n.push(function(){return r[e].apply(null,i)})},s=0;s<r.length;++s)o(s)}}function St(){var e=$s;$s=null;for(var t=0;t<e.length;++t)e[t]()}function _t(e,t,r,n){for(var i=0;i<t.changes.length;i++){var o=t.changes[i];"text"==o?Pt(e,t):"gutter"==o?Ft(e,t,r,n):"class"==o?Ot(t):"widget"==o&&Mt(e,t,n)}t.changes=null}function Dt(e){return e.node==e.text&&(e.node=n("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),rs&&ns<8&&(e.node.style.zIndex=2)),e.node}function kt(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var r=Dt(e);e.background=r.insertBefore(n("div",null,t),r.firstChild)}}function Tt(e,t){var r=e.display.externalMeasured;return r&&r.line==t.line?(e.display.externalMeasured=null,t.measure=r.measure,r.built):pt(e,t)}function Pt(e,t){var r=t.text.className,n=Tt(e,t);t.text==t.node&&(t.node=n.pre),t.text.parentNode.replaceChild(n.pre,t.text),t.text=n.pre,n.bgClass!=t.bgClass||n.textClass!=t.textClass?(t.bgClass=n.bgClass,t.textClass=n.textClass,Ot(t)):r&&(t.text.className=r)}function Ot(e){kt(e),e.line.wrapClass?Dt(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function Ft(e,t,r,i){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var o=Dt(t);t.gutterBackground=n("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px; width: "+i.gutterTotalWidth+"px"),o.insertBefore(t.gutterBackground,t.text)}var s=t.line.gutterMarkers;if(e.options.lineNumbers||s){var a=Dt(t),u=t.gutter=n("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px");if(e.display.input.setUneditable(u),a.insertBefore(u,t.text),t.line.gutterClass&&(u.className+=" "+t.line.gutterClass),!e.options.lineNumbers||s&&s["CodeMirror-linenumbers"]||(t.lineNumber=u.appendChild(n("div",F(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+i.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),s)for(var l=0;l<e.options.gutters.length;++l){var c=e.options.gutters[l],f=s.hasOwnProperty(c)&&s[c];f&&u.appendChild(n("div",[f],"CodeMirror-gutter-elt","left: "+i.gutterLeft[c]+"px; width: "+i.gutterWidth[c]+"px"))}}}function Mt(e,t,r){t.alignable&&(t.alignable=null);for(var n=t.node.firstChild,i=void 0;n;n=i)i=n.nextSibling,"CodeMirror-linewidget"==n.className&&t.node.removeChild(n);Rt(e,t,r)}function Bt(e,t,r,n){var i=Tt(e,t);return t.text=t.node=i.pre,i.bgClass&&(t.bgClass=i.bgClass),i.textClass&&(t.textClass=i.textClass),Ot(t),Ft(e,t,r,n),Rt(e,t,n),t.node}function Rt(e,t,r){if(Lt(e,t.line,t,r,!0),t.rest)for(var n=0;n<t.rest.length;n++)Lt(e,t.rest[n],t,r,!1)}function Lt(e,t,r,i,o){if(t.widgets)for(var s=Dt(r),a=0,u=t.widgets;a<u.length;++a){var l=u[a],c=n("div",[l.node],"CodeMirror-linewidget");l.handleMouseEvents||c.setAttribute("cm-ignore-events","true"),It(l,c,r,i),e.display.input.setUneditable(c),o&&l.above?s.insertBefore(c,r.gutter||r.text):s.appendChild(c),wt(l,"redraw")}}function It(e,t,r,n){if(e.noHScroll){(r.alignable||(r.alignable=[])).push(t);var i=n.wrapperWidth;t.style.left=n.fixedPos+"px",e.coverGutter||(i-=n.gutterTotalWidth,t.style.paddingLeft=n.gutterTotalWidth+"px"),t.style.width=i+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-n.gutterTotalWidth+"px"))}function Nt(e){if(null!=e.height)return e.height;var t=e.doc.cm;if(!t)return 0;if(!i(document.body,e.node)){var o="position: relative;";e.coverGutter&&(o+="margin-left: -"+t.display.gutters.offsetWidth+"px;"),e.noHScroll&&(o+="width: "+t.display.wrapper.clientWidth+"px;"),r(t.display.measure,n("div",[e.node],null,o))}return e.height=e.node.parentNode.offsetHeight}function jt(e,t){for(var r=je(t);r!=e.wrapper;r=r.parentNode)if(!r||1==r.nodeType&&"true"==r.getAttribute("cm-ignore-events")||r.parentNode==e.sizer&&r!=e.mover)return!0}function Ut(e){return e.lineSpace.offsetTop}function Wt(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function Vt(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=r(e.measure,n("pre","x")),i=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,o={left:parseInt(i.paddingLeft),right:parseInt(i.paddingRight)};return isNaN(o.left)||isNaN(o.right)||(e.cachedPaddingH=o),o}function Gt(e){return ws-e.display.nativeBarWidth}function Ht(e){return e.display.scroller.clientWidth-Gt(e)-e.display.barWidth}function Yt(e){return e.display.scroller.clientHeight-Gt(e)-e.display.barHeight}function zt(e,t,r){var n=e.options.lineWrapping,i=n&&Ht(e);if(!t.measure.heights||n&&t.measure.width!=i){var o=t.measure.heights=[];if(n){t.measure.width=i;for(var s=t.text.firstChild.getClientRects(),a=0;a<s.length-1;a++){var u=s[a],l=s[a+1];Math.abs(u.bottom-l.bottom)>2&&o.push((u.bottom+l.top)/2-r.top)}}o.push(r.bottom-r.top)}}function qt(e,t,r){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var n=0;n<e.rest.length;n++)if(e.rest[n]==t)return{map:e.measure.maps[n],cache:e.measure.caches[n]};for(var i=0;i<e.rest.length;i++)if(T(e.rest[i])>r)return{map:e.measure.maps[i],cache:e.measure.caches[i],before:!0}}function Kt(e,t){t=ue(t);var n=T(t),i=e.display.externalMeasured=new bt(e.doc,t,n);i.lineN=n;var o=i.built=pt(e,i);return i.text=o.pre,r(e.display.lineMeasure,o.pre),i}function Xt(e,t,r,n){return Qt(e,$t(e,t),r,n)}function Jt(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[Cr(e,t)];var r=e.display.externalMeasured;return r&&t>=r.lineN&&t<r.lineN+r.size?r:void 0}function $t(e,t){var r=T(t),n=Jt(e,r);n&&!n.text?n=null:n&&n.changes&&(_t(e,n,r,yr(e)),e.curOp.forceUpdate=!0),n||(n=Kt(e,t));var i=qt(n,t,r);return{line:t,view:n,rect:null,map:i.map,cache:i.cache,before:i.before,hasHeights:!1}}function Qt(e,t,r,n,i){t.before&&(r=-1);var o,s=r+(n||"");return t.cache.hasOwnProperty(s)?o=t.cache[s]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(zt(e,t.view,t.rect),t.hasHeights=!0),o=tr(e,t,r,n),o.bogus||(t.cache[s]=o)),{left:o.left,right:o.right,top:i?o.rtop:o.top,bottom:i?o.rbottom:o.bottom}}function Zt(e,t,r){for(var n,i,o,s,a,u,l=0;l<e.length;l+=3)if(a=e[l],u=e[l+1],t<a?(i=0,o=1,s="left"):t<u?(i=t-a,o=i+1):(l==e.length-3||t==u&&e[l+3]>t)&&(o=u-a, i=o-1,t>=u&&(s="right")),null!=i){if(n=e[l+2],a==u&&r==(n.insertLeft?"left":"right")&&(s=r),"left"==r&&0==i)for(;l&&e[l-2]==e[l-3]&&e[l-1].insertLeft;)n=e[(l-=3)+2],s="left";if("right"==r&&i==u-a)for(;l<e.length-3&&e[l+3]==e[l+4]&&!e[l+5].insertLeft;)n=e[(l+=3)+2],s="right";break}return{node:n,start:i,end:o,collapse:s,coverStart:a,coverEnd:u}}function er(e,t){var r=Qs;if("left"==t)for(var n=0;n<e.length&&(r=e[n]).left==r.right;n++);else for(var i=e.length-1;i>=0&&(r=e[i]).left==r.right;i--);return r}function tr(e,t,r,n){var i,o=Zt(t.map,r,n),s=o.node,a=o.start,u=o.end,l=o.collapse;if(3==s.nodeType){for(var c=0;c<4;c++){for(;a&&C(t.line.text.charAt(o.coverStart+a));)--a;for(;o.coverStart+u<o.coverEnd&&C(t.line.text.charAt(o.coverStart+u));)++u;if(i=rs&&ns<9&&0==a&&u==o.coverEnd-o.coverStart?s.parentNode.getBoundingClientRect():er(gs(s,a,u).getClientRects(),n),i.left||i.right||0==a)break;u=a,a-=1,l="right"}rs&&ns<11&&(i=rr(e.display.measure,i))}else{a>0&&(l=n="right");var f;i=e.options.lineWrapping&&(f=s.getClientRects()).length>1?f["right"==n?f.length-1:0]:s.getBoundingClientRect()}if(rs&&ns<9&&!a&&(!i||!i.left&&!i.right)){var p=s.parentNode.getClientRects()[0];i=p?{left:p.left,right:p.left+gr(e.display),top:p.top,bottom:p.bottom}:Qs}for(var d=i.top-t.rect.top,h=i.bottom-t.rect.top,m=(d+h)/2,v=t.view.measure.heights,g=0;g<v.length-1&&!(m<v[g]);g++);var y=g?v[g-1]:0,b=v[g],x={left:("right"==l?i.right:i.left)-t.rect.left,right:("left"==l?i.left:i.right)-t.rect.left,top:y,bottom:b};return i.left||i.right||(x.bogus=!0),e.options.singleCursorHeightPerLine||(x.rtop=d,x.rbottom=h),x}function rr(e,t){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!Ge(e))return t;var r=screen.logicalXDPI/screen.deviceXDPI,n=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*r,right:t.right*r,top:t.top*n,bottom:t.bottom*n}}function nr(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(var t=0;t<e.rest.length;t++)e.measure.caches[t]={}}function ir(e){e.display.externalMeasure=null,t(e.display.lineMeasure);for(var r=0;r<e.display.view.length;r++)nr(e.display.view[r])}function or(e){ir(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function sr(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function ar(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function ur(e,t,r,n,i){if(!i&&t.widgets)for(var o=0;o<t.widgets.length;++o)if(t.widgets[o].above){var s=Nt(t.widgets[o]);r.top+=s,r.bottom+=s}if("line"==n)return r;n||(n="local");var a=he(t);if("local"==n?a+=Ut(e.display):a-=e.display.viewOffset,"page"==n||"window"==n){var u=e.display.lineSpace.getBoundingClientRect();a+=u.top+("window"==n?0:ar());var l=u.left+("window"==n?0:sr());r.left+=l,r.right+=l}return r.top+=a,r.bottom+=a,r}function lr(e,t,r){if("div"==r)return t;var n=t.left,i=t.top;if("page"==r)n-=sr(),i-=ar();else if("local"==r||!r){var o=e.display.sizer.getBoundingClientRect();n+=o.left,i+=o.top}var s=e.display.lineSpace.getBoundingClientRect();return{left:n-s.left,top:i-s.top}}function cr(e,t,r,n,i){return n||(n=S(e.doc,t.line)),ur(e,n,Xt(e,n,t.ch,i),r)}function fr(e,t,r,n,i,o){function s(t,s){var a=Qt(e,i,t,s?"right":"left",o);return s?a.left=a.right:a.right=a.left,ur(e,n,a,r)}function a(e,t){var r=u[t],n=r.level%2;return e==ye(r)&&t&&r.level<u[t-1].level?(r=u[--t],e=be(r)-(r.level%2?0:1),n=!0):e==be(r)&&t<u.length-1&&r.level<u[t+1].level&&(r=u[++t],e=ye(r)-r.level%2,n=!1),n&&e==r.to&&e>r.from?s(e-1):s(e,n)}n=n||S(e.doc,t.line),i||(i=$t(e,n));var u=De(n),l=t.ch;if(!u)return s(l);var c=Ce(u,l),f=a(l,c);return null!=Bs&&(f.other=a(l,Bs)),f}function pr(e,t){var r=0;t=j(e.doc,t),e.options.lineWrapping||(r=gr(e.display)*t.ch);var n=S(e.doc,t.line),i=he(n)+Ut(e.display);return{left:r,right:r,top:i,bottom:i+n.height}}function dr(e,t,r,n){var i=M(e,t);return i.xRel=n,r&&(i.outside=!0),i}function hr(e,t,r){var n=e.doc;if(r+=e.display.viewOffset,r<0)return dr(n.first,0,!0,-1);var i=P(n,r),o=n.first+n.size-1;if(i>o)return dr(n.first+n.size-1,S(n,o).text.length,!0,1);t<0&&(t=0);for(var s=S(n,i);;){var a=mr(e,s,i,t,r),u=se(s),l=u&&u.find(0,!0);if(!u||!(a.ch>l.from.ch||a.ch==l.from.ch&&a.xRel>0))return a;i=T(s=l.to.line)}}function mr(e,t,r,n,i){function o(n){var i=fr(e,M(r,n),"line",t,l);return a=!0,s>i.bottom?i.left-u:s<i.top?i.left+u:(a=!1,i.left)}var s=i-he(t),a=!1,u=2*e.display.wrapper.clientWidth,l=$t(e,t),c=De(t),f=t.text.length,p=xe(t),d=Ee(t),h=o(p),m=a,v=o(d),g=a;if(n>v)return dr(r,d,g,1);for(;;){if(c?d==p||d==Se(t,p,1):d-p<=1){var y=n<h||n-h<=v-n?p:d,b=y==p?m:g,x=n-(y==p?h:v);if(g&&!c&&!/\s/.test(t.text.charAt(y))&&x>0&&y<t.text.length&&l.view.measure.heights.length>1){var E=Qt(e,l,y,"right");s<=E.bottom&&s>=E.top&&Math.abs(n-E.right)<x&&(b=!1,y++,x=n-E.right)}for(;C(t.text.charAt(y));)++y;var A=dr(r,y,b,x<-1?-1:x>1?1:0);return A}var w=Math.ceil(f/2),S=p+w;if(c){S=p;for(var _=0;_<w;++_)S=Se(t,S,1)}var D=o(S);D>n?(d=S,v=D,(g=a)&&(v+=1e3),f=w):(p=S,h=D,m=a,f-=w)}}function vr(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==qs){qs=n("pre");for(var i=0;i<49;++i)qs.appendChild(document.createTextNode("x")),qs.appendChild(n("br"));qs.appendChild(document.createTextNode("x"))}r(e.measure,qs);var o=qs.offsetHeight/50;return o>3&&(e.cachedTextHeight=o),t(e.measure),o||1}function gr(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=n("span","xxxxxxxxxx"),i=n("pre",[t]);r(e.measure,i);var o=t.getBoundingClientRect(),s=(o.right-o.left)/10;return s>2&&(e.cachedCharWidth=s),s||10}function yr(e){for(var t=e.display,r={},n={},i=t.gutters.clientLeft,o=t.gutters.firstChild,s=0;o;o=o.nextSibling,++s)r[e.options.gutters[s]]=o.offsetLeft+o.clientLeft+i,n[e.options.gutters[s]]=o.clientWidth;return{fixedPos:br(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:r,gutterWidth:n,wrapperWidth:t.wrapper.clientWidth}}function br(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function xr(e){var t=vr(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/gr(e.display)-3);return function(i){if(pe(e.doc,i))return 0;var o=0;if(i.widgets)for(var s=0;s<i.widgets.length;s++)i.widgets[s].height&&(o+=i.widgets[s].height);return r?o+(Math.ceil(i.text.length/n)||1)*t:o+t}}function Er(e){var t=e.doc,r=xr(e);t.iter(function(e){var t=r(e);t!=e.height&&k(e,t)})}function Ar(e,t,r,n){var i=e.display;if(!r&&"true"==je(t).getAttribute("cm-not-content"))return null;var o,s,a=i.lineSpace.getBoundingClientRect();try{o=t.clientX-a.left,s=t.clientY-a.top}catch(e){return null}var u,l=hr(e,o,s);if(n&&1==l.xRel&&(u=S(e.doc,l.line).text).length==l.ch){var f=c(u,u.length,e.options.tabSize)-u.length;l=M(l.line,Math.max(0,Math.round((o-Vt(e.display).left)/gr(e.display))-f))}return l}function Cr(e,t){if(t>=e.display.viewTo)return null;if(t-=e.display.viewFrom,t<0)return null;for(var r=e.display.view,n=0;n<r.length;n++)if(t-=r[n].size,t<0)return n}function wr(e){e.display.input.showSelection(e.display.input.prepareSelection())}function Sr(e,t){for(var r=e.doc,n={},i=n.cursors=document.createDocumentFragment(),o=n.selection=document.createDocumentFragment(),s=0;s<r.sel.ranges.length;s++)if(t!==!1||s!=r.sel.primIndex){var a=r.sel.ranges[s];if(!(a.from().line>=e.display.viewTo||a.to().line<e.display.viewFrom)){var u=a.empty();(u||e.options.showCursorWhenSelecting)&&_r(e,a.head,i),u||Dr(e,a,o)}}return n}function _r(e,t,r){var i=fr(e,t,"div",null,null,!e.options.singleCursorHeightPerLine),o=r.appendChild(n("div"," ","CodeMirror-cursor"));if(o.style.left=i.left+"px",o.style.top=i.top+"px",o.style.height=Math.max(0,i.bottom-i.top)*e.options.cursorHeight+"px",i.other){var s=r.appendChild(n("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));s.style.display="",s.style.left=i.other.left+"px",s.style.top=i.other.top+"px",s.style.height=.85*(i.other.bottom-i.other.top)+"px"}}function Dr(e,t,r){function i(e,t,r,i){t<0&&(t=0),t=Math.round(t),i=Math.round(i),u.appendChild(n("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px;\n top: "+t+"px; width: "+(null==r?f-e:r)+"px;\n height: "+(i-t)+"px"))}function o(t,r,n){function o(r,n){return cr(e,M(t,r),"div",l,n)}var s,u,l=S(a,t),p=l.text.length;return ge(De(l),r||0,null==n?p:n,function(e,t,a){var l,d,h,m=o(e,"left");if(e==t)l=m,d=h=m.left;else{if(l=o(t-1,"right"),"rtl"==a){var v=m;m=l,l=v}d=m.left,h=l.right}null==r&&0==e&&(d=c),l.top-m.top>3&&(i(d,m.top,null,m.bottom),d=c,m.bottom<l.top&&i(d,m.bottom,null,l.top)),null==n&&t==p&&(h=f),(!s||m.top<s.top||m.top==s.top&&m.left<s.left)&&(s=m),(!u||l.bottom>u.bottom||l.bottom==u.bottom&&l.right>u.right)&&(u=l),d<c+1&&(d=c),i(d,l.top,h-d,l.bottom)}),{start:s,end:u}}var s=e.display,a=e.doc,u=document.createDocumentFragment(),l=Vt(e.display),c=l.left,f=Math.max(s.sizerWidth,Ht(e)-s.sizer.offsetLeft)-l.right,p=t.from(),d=t.to();if(p.line==d.line)o(p.line,p.ch,d.ch);else{var h=S(a,p.line),m=S(a,d.line),v=ue(h)==ue(m),g=o(p.line,p.ch,v?h.text.length+1:null).end,y=o(d.line,v?0:null,d.ch).start;v&&(g.top<y.top-2?(i(g.right,g.top,null,g.bottom),i(c,y.top,y.left,y.bottom)):i(g.right,g.top,y.left-g.right,g.bottom)),g.bottom<y.top&&i(c,g.bottom,null,y.top)}r.appendChild(u)}function kr(e){if(e.state.focused){var t=e.display;clearInterval(t.blinker);var r=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0?t.blinker=setInterval(function(){return t.cursorDiv.style.visibility=(r=!r)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function Tr(e){e.state.focused||(e.display.input.focus(),Or(e))}function Pr(e){e.state.delayingBlurEvent=!0,setTimeout(function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,Fr(e))},100)}function Or(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,s(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),is&&setTimeout(function(){return e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),kr(e))}function Fr(e,t){e.state.delayingBlurEvent||(e.state.focused&&(Pe(e,"blur",e,t),e.state.focused=!1,xs(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150))}function Mr(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=br(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",s=0;s<r.length;s++)if(!r[s].hidden){e.options.fixedGutter&&(r[s].gutter&&(r[s].gutter.style.left=o),r[s].gutterBackground&&(r[s].gutterBackground.style.left=o));var a=r[s].alignable;if(a)for(var u=0;u<a.length;u++)a[u].style.left=o}e.options.fixedGutter&&(t.gutters.style.left=n+i+"px")}}function Br(e){if(!e.options.lineNumbers)return!1;var t=e.doc,r=F(e.options,t.first+t.size-1),i=e.display;if(r.length!=i.lineNumChars){var o=i.measure.appendChild(n("div",[n("div",r)],"CodeMirror-linenumber CodeMirror-gutter-elt")),s=o.firstChild.offsetWidth,a=o.offsetWidth-s;return i.lineGutter.style.width="",i.lineNumInnerWidth=Math.max(s,i.lineGutter.offsetWidth-a)+1,i.lineNumWidth=i.lineNumInnerWidth+a,i.lineNumChars=i.lineNumInnerWidth?r.length:-1,i.lineGutter.style.width=i.lineNumWidth+"px",_n(e),!0}return!1}function Rr(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;n<t.view.length;n++){var i=t.view[n],o=void 0;if(!i.hidden){if(rs&&ns<8){var s=i.node.offsetTop+i.node.offsetHeight;o=s-r,r=s}else{var a=i.node.getBoundingClientRect();o=a.bottom-a.top}var u=i.line.height-o;if(o<2&&(o=vr(t)),(u>.001||u<-.001)&&(k(i.line,o),Lr(i.line),i.rest))for(var l=0;l<i.rest.length;l++)Lr(i.rest[l])}}}function Lr(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t)e.widgets[t].height=e.widgets[t].node.parentNode.offsetHeight}function Ir(e,t,r){var n=r&&null!=r.top?Math.max(0,r.top):e.scroller.scrollTop;n=Math.floor(n-Ut(e));var i=r&&null!=r.bottom?r.bottom:n+e.wrapper.clientHeight,o=P(t,n),s=P(t,i);if(r&&r.ensure){var a=r.ensure.from.line,u=r.ensure.to.line;a<o?(o=a,s=P(t,he(S(t,a))+e.wrapper.clientHeight)):Math.min(u,t.lastLine())>=s&&(o=P(t,he(S(t,u))-e.wrapper.clientHeight),s=u)}return{from:o,to:Math.max(s,o+1)}}function Nr(e,t){Math.abs(e.doc.scrollTop-t)<2||(e.doc.scrollTop=t,Zo||wn(e,{top:t}),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t),e.display.scrollbars.setScrollTop(t),Zo&&wn(e),bn(e,100))}function jr(e,t,r){(r?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)||(t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth),e.doc.scrollLeft=t,Mr(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function Ur(e){var t=e.wheelDeltaX,r=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==r&&e.detail&&e.axis==e.VERTICAL_AXIS?r=e.detail:null==r&&(r=e.wheelDelta),{x:t,y:r}}function Wr(e){var t=Ur(e);return t.x*=ea,t.y*=ea,t}function Vr(e,t){var r=Ur(t),n=r.x,i=r.y,o=e.display,s=o.scroller,a=s.scrollWidth>s.clientWidth,u=s.scrollHeight>s.clientHeight;if(n&&a||i&&u){if(i&&ds&&is)e:for(var l=t.target,c=o.view;l!=s;l=l.parentNode)for(var f=0;f<c.length;f++)if(c[f].node==l){e.display.currentWheelTarget=l;break e}if(n&&!Zo&&!as&&null!=ea)return i&&u&&Nr(e,Math.max(0,Math.min(s.scrollTop+i*ea,s.scrollHeight-s.clientHeight))),jr(e,Math.max(0,Math.min(s.scrollLeft+n*ea,s.scrollWidth-s.clientWidth))),(!i||i&&u)&&Re(t),void(o.wheelStartX=null);if(i&&null!=ea){var p=i*ea,d=e.doc.scrollTop,h=d+o.wrapper.clientHeight;p<0?d=Math.max(0,d+p-50):h=Math.min(e.doc.height,h+p+50),wn(e,{top:d,bottom:h})}Zs<20&&(null==o.wheelStartX?(o.wheelStartX=s.scrollLeft,o.wheelStartY=s.scrollTop,o.wheelDX=n,o.wheelDY=i,setTimeout(function(){if(null!=o.wheelStartX){var e=s.scrollLeft-o.wheelStartX,t=s.scrollTop-o.wheelStartY,r=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,r&&(ea=(ea*Zs+r)/(Zs+1),++Zs)}},200)):(o.wheelDX+=n,o.wheelDY+=i))}}function Gr(e){var t=e.display,r=t.gutters.offsetWidth,n=Math.round(e.doc.height+Wt(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?r:0,docHeight:n,scrollHeight:n+Gt(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:r}}function Hr(e,t){t||(t=Gr(e));var r=e.display.barWidth,n=e.display.barHeight;Yr(e,t);for(var i=0;i<4&&r!=e.display.barWidth||n!=e.display.barHeight;i++)r!=e.display.barWidth&&e.options.lineWrapping&&Rr(e),Yr(e,Gr(e)),r=e.display.barWidth,n=e.display.barHeight}function Yr(e,t){var r=e.display,n=r.scrollbars.update(t);r.sizer.style.paddingRight=(r.barWidth=n.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=n.bottom)+"px",r.heightForcer.style.borderBottom=n.bottom+"px solid transparent",n.right&&n.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=n.bottom+"px",r.scrollbarFiller.style.width=n.right+"px"):r.scrollbarFiller.style.display="",n.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=n.bottom+"px",r.gutterFiller.style.width=t.gutterWidth+"px"):r.gutterFiller.style.display=""}function zr(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&xs(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new na[e.options.scrollbarStyle](function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),Is(t,"mousedown",function(){e.state.focused&&setTimeout(function(){return e.display.input.focus()},0)}),t.setAttribute("cm-not-content","true")},function(t,r){"horizontal"==r?jr(e,t):Nr(e,t)},e),e.display.scrollbars.addClass&&s(e.display.wrapper,e.display.scrollbars.addClass)}function qr(e,t){if(!Oe(e,"scrollCursorIntoView")){var r=e.display,i=r.sizer.getBoundingClientRect(),o=null;if(t.top+i.top<0?o=!0:t.bottom+i.top>(window.innerHeight||document.documentElement.clientHeight)&&(o=!1),null!=o&&!cs){var s=n("div","​",null,"position: absolute;\n top: "+(t.top-r.viewOffset-Ut(e.display))+"px;\n height: "+(t.bottom-t.top+Gt(e)+r.barHeight)+"px;\n left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(s),s.scrollIntoView(o),e.display.lineSpace.removeChild(s)}}}function Kr(e,t,r,n){null==n&&(n=0);for(var i,o=0;o<5;o++){var s=!1;i=fr(e,t);var a=r&&r!=t?fr(e,r):i,u=Jr(e,Math.min(i.left,a.left),Math.min(i.top,a.top)-n,Math.max(i.left,a.left),Math.max(i.bottom,a.bottom)+n),l=e.doc.scrollTop,c=e.doc.scrollLeft;if(null!=u.scrollTop&&(Nr(e,u.scrollTop),Math.abs(e.doc.scrollTop-l)>1&&(s=!0)),null!=u.scrollLeft&&(jr(e,u.scrollLeft),Math.abs(e.doc.scrollLeft-c)>1&&(s=!0)),!s)break}return i}function Xr(e,t,r,n,i){var o=Jr(e,t,r,n,i);null!=o.scrollTop&&Nr(e,o.scrollTop),null!=o.scrollLeft&&jr(e,o.scrollLeft)}function Jr(e,t,r,n,i){var o=e.display,s=vr(e.display);r<0&&(r=0);var a=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:o.scroller.scrollTop,u=Yt(e),l={};i-r>u&&(i=r+u);var c=e.doc.height+Wt(o),f=r<s,p=i>c-s;if(r<a)l.scrollTop=f?0:r;else if(i>a+u){var d=Math.min(r,(p?c:i)-u);d!=a&&(l.scrollTop=d)}var h=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:o.scroller.scrollLeft,m=Ht(e)-(e.options.fixedGutter?o.gutters.offsetWidth:0),v=n-t>m;return v&&(n=t+m),t<10?l.scrollLeft=0:t<h?l.scro