openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 82b0275bb1dc2693cbdbe33634d266d4f21b1246
parent cbc288f8892478ae1bd44472057cb140dc6c5b98
Author: Jan Dankert <devnull@localhost>
Date:   Tue,  4 Sep 2018 00:05:46 +0200

JQuery-UI hatte die falsche minifizierte Version, Codemirror is erstmal un-minifiziert, da JSqueeze leider ungültiges Javascript erzeugt :-O

Diffstat:
modules/cms-ui/themes/default/production/combined.min.js | 10058++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
modules/cms-ui/themes/default/script/jquery-ui.min.js | 92++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
modules/cms-ui/themes/default/script/svg-injector.min.js | 13+++++++++++++
modules/editor/codemirror/lib/codemirror.min.js | 9654++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/editor/codemirror/mode/apl/apl.min.js | 178++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/asciiarmor/asciiarmor.min.js | 83+++++++++----------------------------------------------------------------------
modules/editor/codemirror/mode/asn.1/asn.1.min.js | 208++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/asterisk/asterisk.min.js | 203+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/brainfuck/brainfuck.min.js | 92++++++-------------------------------------------------------------------------
modules/editor/codemirror/mode/clike/clike.min.js | 796+------------------------------------------------------------------------------
modules/editor/codemirror/mode/clojure/clojure.min.js | 322++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/cmake/cmake.min.js | 100+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/cobol/cobol.min.js | 268++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/coffeescript/coffeescript.min.js | 370+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/commonlisp/commonlisp.min.js | 136+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/crystal/crystal.min.js | 451++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/css/css.min.js | 875++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/cypher/cypher.min.js | 161++++++-------------------------------------------------------------------------
modules/editor/codemirror/mode/d/d.min.js | 221++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/dart/dart.min.js | 162+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/diff/diff.min.js | 50+++-----------------------------------------------
modules/editor/codemirror/mode/django/django.min.js | 374++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/dtd/dtd.min.js | 155+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/dylan/dylan.min.js | 376+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/ebnf/ebnf.min.js | 212+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/ecl/ecl.min.js | 214+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/eiffel/eiffel.min.js | 168++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/elm/elm.min.js | 208++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/erlang/erlang.min.js | 653+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/fcl/fcl.min.js | 177++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/forth/forth.min.js | 183++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/fortran/fortran.min.js | 190+------------------------------------------------------------------------------
modules/editor/codemirror/mode/gas/gas.min.js | 348+------------------------------------------------------------------------------
modules/editor/codemirror/mode/gfm/gfm.min.js | 134+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/gherkin/gherkin.min.js | 193+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/go/go.min.js | 191++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/groovy/groovy.min.js | 235++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/haml/haml.min.js | 171+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/haskell-literate/haskell-literate.min.js | 46+++-------------------------------------------
modules/editor/codemirror/mode/haskell/haskell.min.js | 272++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/haxe/haxe.min.js | 534+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/htmlembedded/htmlembedded.min.js | 30++----------------------------
modules/editor/codemirror/mode/htmlmixed/htmlmixed.min.js | 157+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/http/http.min.js | 125++++++++-----------------------------------------------------------------------
modules/editor/codemirror/mode/idl/idl.min.js | 292+------------------------------------------------------------------------------
modules/editor/codemirror/mode/javascript/javascript.min.js | 916++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/jinja2/jinja2.min.js | 155+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/jsx/jsx.min.js | 156+++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/julia/julia.min.js | 428++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/livescript/livescript.min.js | 284++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/lua/lua.min.js | 163++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/markdown/markdown.min.js | 895+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/mathematica/mathematica.min.js | 178+------------------------------------------------------------------------------
modules/editor/codemirror/mode/mbox/mbox.min.js | 132++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/meta.min.js | 218+------------------------------------------------------------------------------
modules/editor/codemirror/mode/mirc/mirc.min.js | 206+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/mllike/mllike.min.js | 210+------------------------------------------------------------------------------
modules/editor/codemirror/mode/modelica/modelica.min.js | 255++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/mscgen/mscgen.min.js | 177+------------------------------------------------------------------------------
modules/editor/codemirror/mode/mumps/mumps.min.js | 152+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/nginx/nginx.min.js | 192++++++-------------------------------------------------------------------------
modules/editor/codemirror/mode/ntriples/ntriples.min.js | 197+------------------------------------------------------------------------------
modules/editor/codemirror/mode/octave/octave.min.js | 141++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/oz/oz.min.js | 257++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/pascal/pascal.min.js | 111++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/pegjs/pegjs.min.js | 128+++++++++----------------------------------------------------------------------
modules/editor/codemirror/mode/perl/perl.min.js | 850++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/php/php.min.js | 240++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/pig/pig.min.js | 186++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/powershell/powershell.min.js | 409+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/properties/properties.min.js | 84++++++-------------------------------------------------------------------------
modules/editor/codemirror/mode/protobuf/protobuf.min.js | 71++---------------------------------------------------------------------
modules/editor/codemirror/mode/pug/pug.min.js | 603++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/puppet/puppet.min.js | 223++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/python/python.min.js | 340++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/q/q.min.js | 142++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/r/r.min.js | 200+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/rpm/rpm.min.js | 111++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/rst/rst.min.js | 579+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/ruby/ruby.min.js | 323+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/sas/sas.min.js | 317++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/sass/sass.min.js | 473++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/scheme/scheme.min.js | 271+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/shell/shell.min.js | 144++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/sieve/sieve.min.js | 195+------------------------------------------------------------------------------
modules/editor/codemirror/mode/slim/slim.min.js | 578+------------------------------------------------------------------------------
modules/editor/codemirror/mode/smalltalk/smalltalk.min.js | 182+++++++-------------------------------------------------------------------------
modules/editor/codemirror/mode/smarty/smarty.min.js | 241++++++-------------------------------------------------------------------------
modules/editor/codemirror/mode/solr/solr.min.js | 106++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/soy/soy.min.js | 370++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/sparql/sparql.min.js | 191+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/spreadsheet/spreadsheet.min.js | 119+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/sql/sql.min.js | 506+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/stex/stex.min.js | 259+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/stylus/stylus.min.js | 784++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/swift/swift.min.js | 215++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/tcl/tcl.min.js | 148+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/textile/textile.min.js | 481++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/tiddlywiki/tiddlywiki.min.js | 311+------------------------------------------------------------------------------
modules/editor/codemirror/mode/tiki/tiki.min.js | 327++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/toml/toml.min.js | 103++++++++++++-------------------------------------------------------------------
modules/editor/codemirror/mode/tornado/tornado.min.js | 70++--------------------------------------------------------------------
modules/editor/codemirror/mode/troff/troff.min.js | 86++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/ttcn-cfg/ttcn-cfg.min.js | 219++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/ttcn/ttcn.min.js | 287++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/turtle/turtle.min.js | 173+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/twig/twig.min.js | 154+++++++------------------------------------------------------------------------
modules/editor/codemirror/mode/vb/vb.min.js | 285+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/vbscript/vbscript.min.js | 360+++----------------------------------------------------------------------------
modules/editor/codemirror/mode/velocity/velocity.min.js | 214+++++--------------------------------------------------------------------------
modules/editor/codemirror/mode/verilog/verilog.min.js | 705++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/vhdl/vhdl.min.js | 192++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/vue/vue.min.js | 81++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/webidl/webidl.min.js | 199++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/xml/xml.min.js | 422++++++-------------------------------------------------------------------------
modules/editor/codemirror/mode/xquery/xquery.min.js | 468++++---------------------------------------------------------------------------
modules/editor/codemirror/mode/yacas/yacas.min.js | 206+------------------------------------------------------------------------------
modules/editor/codemirror/mode/yaml-frontmatter/yaml-frontmatter.min.js | 73+++++--------------------------------------------------------------------
modules/editor/codemirror/mode/yaml/yaml.min.js | 121++-----------------------------------------------------------------------------
modules/editor/codemirror/mode/z80/z80.min.js | 130+++++++++----------------------------------------------------------------------
120 files changed, 20589 insertions(+), 30220 deletions(-)

diff --git a/modules/cms-ui/themes/default/production/combined.min.js b/modules/cms-ui/themes/default/production/combined.min.js @@ -163,10 +163,10 @@ else{t[r]=o}},t,r,arguments.length)}});e.each(["top","left"],function(t,n){e.css else{e.ready(!0)}};e.isArray=Array.isArray;e.parseJSON=JSON.parse;e.nodeName=c;if(typeof define==="function"&&define.amd){define("jquery",[],function(){return e})};var et=t.jQuery,tt=t.$;e.noConflict=function(n){if(t.$===e){t.$=tt};if(n&&t.jQuery===e){t.jQuery=et};return e};if(!n){t.jQuery=t.$=e};return e}); /* ./modules/cms-ui/themes/default/script/jquery-ui.min.js *//*! jQuery UI - v1.12.1 - 2018-09-03 * http://jqueryui.com -* Includes: widget.js, data.js, scroll-parent.js, widgets/sortable.js, widgets/mouse.js +* Includes: widget.js, data.js, scroll-parent.js, widgets/draggable.js, widgets/droppable.js, widgets/sortable.js, widgets/mouse.js * Copyright jQuery Foundation and other contributors; Licensed MIT */ (function(t){if(typeof define==="function"&&define.amd){define(["jquery"],t)} -else{t(jQuery)}}(function(t){t.ui=t.ui||{};var c=t.ui.version="1.12.1"; +else{t(jQuery)}}(function(t){t.ui=t.ui||{};var g=t.ui.version="1.12.1"; /*! * jQuery UI Widget 1.12.1 * http://jqueryui.com @@ -175,18 +175,18 @@ else{t(jQuery)}}(function(t){t.ui=t.ui||{};var c=t.ui.version="1.12.1"; * Released under the MIT license. * http://jquery.org/license */ -;var s=0,i=Array.prototype.slice;t.cleanData=(function(e){return function(i){var s,n,o;for(o=0;(n=i[o])!=null;o++){try{s=t._data(n,"events");if(s&&s.remove){t(n).triggerHandler("remove")}}catch(r){}};e(i)}})(t.cleanData);t.widget=function(e,i,s){var r,n,h,l={};var o=e.split(".")[0];e=e.split(".")[1];var a=o+"-"+e;if(!s){s=i;i=t.Widget};if(t.isArray(s)){s=t.extend.apply(null,[{}].concat(s))};t.expr[":"][a.toLowerCase()]=function(e){return!!t.data(e,a)};t[o]=t[o]||{};r=t[o][e];n=t[o][e]=function(t,e){if(!this._createWidget){return new n(t,e)};if(arguments.length){this._createWidget(t,e)}};t.extend(n,r,{version:s.version,_proto:t.extend({},s),_childConstructors:[]});h=new i();h.options=t.widget.extend({},h.options);t.each(s,function(e,s){if(!t.isFunction(s)){l[e]=s;return};l[e]=(function(){function t(){return i.prototype[e].apply(this,arguments)};function n(t){return i.prototype[e].apply(this,t)};return function(){var i=this._super,o=this._superApply,e;this._super=t;this._superApply=n;e=s.apply(this,arguments);this._super=i;this._superApply=o;return e}})()});n.prototype=t.widget.extend(h,{widgetEventPrefix:r?(h.widgetEventPrefix||e):e},l,{constructor:n,namespace:o,widgetName:e,widgetFullName:a});if(r){t.each(r._childConstructors,function(e,i){var s=i.prototype;t.widget(s.namespace+"."+s.widgetName,n,i._proto)});delete r._childConstructors} -else{i._childConstructors.push(n)};t.widget.bridge(e,n);return n};t.widget.extend=function(e){var r=i.call(arguments,1),o=0,h=r.length,s,n;for(;o<h;o++){for(s in r[o]){n=r[o][s];if(r[o].hasOwnProperty(s)&&n!==undefined){if(t.isPlainObject(n)){e[s]=t.isPlainObject(e[s])?t.widget.extend({},e[s],n):t.widget.extend({},n)} -else{e[s]=n}}}};return e};t.widget.bridge=function(e,s){var n=s.prototype.widgetFullName||e;t.fn[e]=function(o){var a=typeof o==="string",h=i.call(arguments,1),r=this;if(a){if(!this.length&&o==="instance"){r=undefined} -else{this.each(function(){var i,s=t.data(this,n);if(o==="instance"){r=s;return!1};if(!s){return t.error("cannot call methods on "+e+" prior to initialization; attempted to call method '"+o+"'")};if(!t.isFunction(s[o])||o.charAt(0)==="_"){return t.error("no such method '"+o+"' for "+e+" widget instance")};i=s[o].apply(s,h);if(i!==s&&i!==undefined){r=i&&i.jquery?r.pushStack(i.get()):i;return!1}})}} -else{if(h.length){o=t.widget.extend.apply(null,[o].concat(h))};this.each(function(){var e=t.data(this,n);if(e){e.option(o||{});if(e._init){e._init()}} -else{t.data(this,n,new s(o,this))}})};return r}};t.Widget=function(){};t.Widget._childConstructors=[];t.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",defaultElement:"<div>",options:{classes:{},disabled:!1,create:null},_createWidget:function(e,i){i=t(i||this.defaultElement||this)[0];this.element=t(i);this.uuid=s++;this.eventNamespace="."+this.widgetName+this.uuid;this.bindings=t();this.hoverable=t();this.focusable=t();this.classesElementLookup={};if(i!==this){t.data(i,this.widgetFullName,this);this._on(!0,this.element,{remove:function(t){if(t.target===i){this.destroy()}}});this.document=t(i.style?i.ownerDocument:i.document||i);this.window=t(this.document[0].defaultView||this.document[0].parentWindow)};this.options=t.widget.extend({},this.options,this._getCreateOptions(),e);this._create();if(this.options.disabled){this._setOptionDisabled(this.options.disabled)};this._trigger("create",null,this._getCreateEventData());this._init()},_getCreateOptions:function(){return{}},_getCreateEventData:t.noop,_create:t.noop,_init:t.noop,destroy:function(){var e=this;this._destroy();t.each(this.classesElementLookup,function(t,i){e._removeClass(i,t)});this.element.off(this.eventNamespace).removeData(this.widgetFullName);this.widget().off(this.eventNamespace).removeAttr("aria-disabled");this.bindings.off(this.eventNamespace)},_destroy:t.noop,widget:function(){return this.element},option:function(e,i){var r=e,s,n,o;if(arguments.length===0){return t.widget.extend({},this.options)};if(typeof e==="string"){r={};s=e.split(".");e=s.shift();if(s.length){n=r[e]=t.widget.extend({},this.options[e]);for(o=0;o<s.length-1;o++){n[s[o]]=n[s[o]]||{};n=n[s[o]]};e=s.pop();if(arguments.length===1){return n[e]===undefined?null:n[e]};n[e]=i} -else{if(arguments.length===1){return this.options[e]===undefined?null:this.options[e]};r[e]=i}};this._setOptions(r);return this},_setOptions:function(t){var e;for(e in t){this._setOption(e,t[e])};return this},_setOption:function(t,e){if(t==="classes"){this._setOptionClasses(e)};this.options[t]=e;if(t==="disabled"){this._setOptionDisabled(e)};return this},_setOptionClasses:function(e){var i,n,s;for(i in e){s=this.classesElementLookup[i];if(e[i]===this.options.classes[i]||!s||!s.length){continue};n=t(s.get());this._removeClass(s,i);n.addClass(this._classes({element:n,keys:i,classes:e,add:!0}))}},_setOptionDisabled:function(t){this._toggleClass(this.widget(),this.widgetFullName+"-disabled",null,!!t);if(t){this._removeClass(this.hoverable,null,"ui-state-hover");this._removeClass(this.focusable,null,"ui-state-focus")}},enable:function(){return this._setOptions({disabled:!1})},disable:function(){return this._setOptions({disabled:!0})},_classes:function(e){var i=[],s=this;e=t.extend({element:this.element,classes:this.options.classes||{}},e);function n(n,o){var h,r;for(r=0;r<n.length;r++){h=s.classesElementLookup[n[r]]||t();if(e.add){h=t(t.unique(h.get().concat(e.element.get())))} -else{h=t(h.not(e.element).get())};s.classesElementLookup[n[r]]=h;i.push(n[r]);if(o&&e.classes[n[r]]){i.push(e.classes[n[r]])}}};this._on(e.element,{"remove":"_untrackClassesElement"});if(e.keys){n(e.keys.match(/\S+/g)||[],!0)};if(e.extra){n(e.extra.match(/\S+/g)||[])};return i.join(" ")},_untrackClassesElement:function(e){var i=this;t.each(i.classesElementLookup,function(s,n){if(t.inArray(e.target,n)!==-1){i.classesElementLookup[s]=t(n.not(e.target).get())}})},_removeClass:function(t,e,i){return this._toggleClass(t,e,i,!1)},_addClass:function(t,e,i){return this._toggleClass(t,e,i,!0)},_toggleClass:function(t,e,i,s){s=(typeof s==="boolean")?s:i;var n=(typeof t==="string"||t===null),o={extra:n?e:i,keys:n?t:e,element:n?this.element:t,add:s};o.element.toggleClass(this._classes(o),s);return this},_on:function(e,i,s){var o,n=this;if(typeof e!=="boolean"){s=i;i=e;e=!1};if(!s){s=i;i=this.element;o=this.widget()} -else{i=o=t(i);this.bindings=this.bindings.add(i)};t.each(s,function(s,r){function h(){if(!e&&(n.options.disabled===!0||t(this).hasClass("ui-state-disabled"))){return};return(typeof r==="string"?n[r]:r).apply(n,arguments)};if(typeof r!=="string"){h.guid=r.guid=r.guid||h.guid||t.guid++};var a=s.match(/^([\w:-]*)\s*(.*)$/),l=a[1]+n.eventNamespace,c=a[2];if(c){o.on(l,c,h)} -else{i.on(l,h)}})},_off:function(e,i){i=(i||"").split(" ").join(this.eventNamespace+" ")+this.eventNamespace;e.off(i).off(i);this.bindings=t(this.bindings.not(e).get());this.focusable=t(this.focusable.not(e).get());this.hoverable=t(this.hoverable.not(e).get())},_delay:function(t,e){function s(){return(typeof t==="string"?i[t]:t).apply(i,arguments)};var i=this;return setTimeout(s,e||0)},_hoverable:function(e){this.hoverable=this.hoverable.add(e);this._on(e,{mouseenter:function(e){this._addClass(t(e.currentTarget),null,"ui-state-hover")},mouseleave:function(e){this._removeClass(t(e.currentTarget),null,"ui-state-hover")}})},_focusable:function(e){this.focusable=this.focusable.add(e);this._on(e,{focusin:function(e){this._addClass(t(e.currentTarget),null,"ui-state-focus")},focusout:function(e){this._removeClass(t(e.currentTarget),null,"ui-state-focus")}})},_trigger:function(e,i,s){var n,o,r=this.options[e];s=s||{};i=t.Event(i);i.type=(e===this.widgetEventPrefix?e:this.widgetEventPrefix+e).toLowerCase();i.target=this.element[0];o=i.originalEvent;if(o){for(n in o){if(!(n in i)){i[n]=o[n]}}};this.element.trigger(i,s);return!(t.isFunction(r)&&r.apply(this.element[0],[i].concat(s))===!1||i.isDefaultPrevented())}};t.each({show:"fadeIn",hide:"fadeOut"},function(e,i){t.Widget.prototype["_"+e]=function(s,n,o){if(typeof n==="string"){n={effect:n}};var h,r=!n?e:n===!0||typeof n==="number"?i:n.effect||i;n=n||{};if(typeof n==="number"){n={duration:n}};h=!t.isEmptyObject(n);n.complete=o;if(n.delay){s.delay(n.delay)};if(h&&t.effects&&t.effects.effect[r]){s[e](n)} -else if(r!==e&&s[r]){s[r](n.duration,n.easing,o)} -else{s.queue(function(i){t(this)[e]();if(o){o.call(s[0])};i()})}}});var l=t.widget; +;var o=0,s=Array.prototype.slice;t.cleanData=(function(e){return function(i){var s,o,n;for(n=0;(o=i[n])!=null;n++){try{s=t._data(o,"events");if(s&&s.remove){t(o).triggerHandler("remove")}}catch(r){}};e(i)}})(t.cleanData);t.widget=function(e,i,s){var r,o,a,l={};var n=e.split(".")[0];e=e.split(".")[1];var h=n+"-"+e;if(!s){s=i;i=t.Widget};if(t.isArray(s)){s=t.extend.apply(null,[{}].concat(s))};t.expr[":"][h.toLowerCase()]=function(e){return!!t.data(e,h)};t[n]=t[n]||{};r=t[n][e];o=t[n][e]=function(t,e){if(!this._createWidget){return new o(t,e)};if(arguments.length){this._createWidget(t,e)}};t.extend(o,r,{version:s.version,_proto:t.extend({},s),_childConstructors:[]});a=new i();a.options=t.widget.extend({},a.options);t.each(s,function(e,s){if(!t.isFunction(s)){l[e]=s;return};l[e]=(function(){function t(){return i.prototype[e].apply(this,arguments)};function o(t){return i.prototype[e].apply(this,t)};return function(){var i=this._super,n=this._superApply,e;this._super=t;this._superApply=o;e=s.apply(this,arguments);this._super=i;this._superApply=n;return e}})()});o.prototype=t.widget.extend(a,{widgetEventPrefix:r?(a.widgetEventPrefix||e):e},l,{constructor:o,namespace:n,widgetName:e,widgetFullName:h});if(r){t.each(r._childConstructors,function(e,i){var s=i.prototype;t.widget(s.namespace+"."+s.widgetName,o,i._proto)});delete r._childConstructors} +else{i._childConstructors.push(o)};t.widget.bridge(e,o);return o};t.widget.extend=function(e){var r=s.call(arguments,1),n=0,a=r.length,i,o;for(;n<a;n++){for(i in r[n]){o=r[n][i];if(r[n].hasOwnProperty(i)&&o!==undefined){if(t.isPlainObject(o)){e[i]=t.isPlainObject(e[i])?t.widget.extend({},e[i],o):t.widget.extend({},o)} +else{e[i]=o}}}};return e};t.widget.bridge=function(e,i){var o=i.prototype.widgetFullName||e;t.fn[e]=function(n){var h=typeof n==="string",a=s.call(arguments,1),r=this;if(h){if(!this.length&&n==="instance"){r=undefined} +else{this.each(function(){var i,s=t.data(this,o);if(n==="instance"){r=s;return!1};if(!s){return t.error("cannot call methods on "+e+" prior to initialization; attempted to call method '"+n+"'")};if(!t.isFunction(s[n])||n.charAt(0)==="_"){return t.error("no such method '"+n+"' for "+e+" widget instance")};i=s[n].apply(s,a);if(i!==s&&i!==undefined){r=i&&i.jquery?r.pushStack(i.get()):i;return!1}})}} +else{if(a.length){n=t.widget.extend.apply(null,[n].concat(a))};this.each(function(){var e=t.data(this,o);if(e){e.option(n||{});if(e._init){e._init()}} +else{t.data(this,o,new i(n,this))}})};return r}};t.Widget=function(){};t.Widget._childConstructors=[];t.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",defaultElement:"<div>",options:{classes:{},disabled:!1,create:null},_createWidget:function(e,i){i=t(i||this.defaultElement||this)[0];this.element=t(i);this.uuid=o++;this.eventNamespace="."+this.widgetName+this.uuid;this.bindings=t();this.hoverable=t();this.focusable=t();this.classesElementLookup={};if(i!==this){t.data(i,this.widgetFullName,this);this._on(!0,this.element,{remove:function(t){if(t.target===i){this.destroy()}}});this.document=t(i.style?i.ownerDocument:i.document||i);this.window=t(this.document[0].defaultView||this.document[0].parentWindow)};this.options=t.widget.extend({},this.options,this._getCreateOptions(),e);this._create();if(this.options.disabled){this._setOptionDisabled(this.options.disabled)};this._trigger("create",null,this._getCreateEventData());this._init()},_getCreateOptions:function(){return{}},_getCreateEventData:t.noop,_create:t.noop,_init:t.noop,destroy:function(){var e=this;this._destroy();t.each(this.classesElementLookup,function(t,i){e._removeClass(i,t)});this.element.off(this.eventNamespace).removeData(this.widgetFullName);this.widget().off(this.eventNamespace).removeAttr("aria-disabled");this.bindings.off(this.eventNamespace)},_destroy:t.noop,widget:function(){return this.element},option:function(e,i){var r=e,s,o,n;if(arguments.length===0){return t.widget.extend({},this.options)};if(typeof e==="string"){r={};s=e.split(".");e=s.shift();if(s.length){o=r[e]=t.widget.extend({},this.options[e]);for(n=0;n<s.length-1;n++){o[s[n]]=o[s[n]]||{};o=o[s[n]]};e=s.pop();if(arguments.length===1){return o[e]===undefined?null:o[e]};o[e]=i} +else{if(arguments.length===1){return this.options[e]===undefined?null:this.options[e]};r[e]=i}};this._setOptions(r);return this},_setOptions:function(t){var e;for(e in t){this._setOption(e,t[e])};return this},_setOption:function(t,e){if(t==="classes"){this._setOptionClasses(e)};this.options[t]=e;if(t==="disabled"){this._setOptionDisabled(e)};return this},_setOptionClasses:function(e){var i,o,s;for(i in e){s=this.classesElementLookup[i];if(e[i]===this.options.classes[i]||!s||!s.length){continue};o=t(s.get());this._removeClass(s,i);o.addClass(this._classes({element:o,keys:i,classes:e,add:!0}))}},_setOptionDisabled:function(t){this._toggleClass(this.widget(),this.widgetFullName+"-disabled",null,!!t);if(t){this._removeClass(this.hoverable,null,"ui-state-hover");this._removeClass(this.focusable,null,"ui-state-focus")}},enable:function(){return this._setOptions({disabled:!1})},disable:function(){return this._setOptions({disabled:!0})},_classes:function(e){var i=[],s=this;e=t.extend({element:this.element,classes:this.options.classes||{}},e);function o(o,n){var a,r;for(r=0;r<o.length;r++){a=s.classesElementLookup[o[r]]||t();if(e.add){a=t(t.unique(a.get().concat(e.element.get())))} +else{a=t(a.not(e.element).get())};s.classesElementLookup[o[r]]=a;i.push(o[r]);if(n&&e.classes[o[r]]){i.push(e.classes[o[r]])}}};this._on(e.element,{"remove":"_untrackClassesElement"});if(e.keys){o(e.keys.match(/\S+/g)||[],!0)};if(e.extra){o(e.extra.match(/\S+/g)||[])};return i.join(" ")},_untrackClassesElement:function(e){var i=this;t.each(i.classesElementLookup,function(s,o){if(t.inArray(e.target,o)!==-1){i.classesElementLookup[s]=t(o.not(e.target).get())}})},_removeClass:function(t,e,i){return this._toggleClass(t,e,i,!1)},_addClass:function(t,e,i){return this._toggleClass(t,e,i,!0)},_toggleClass:function(t,e,i,s){s=(typeof s==="boolean")?s:i;var o=(typeof t==="string"||t===null),n={extra:o?e:i,keys:o?t:e,element:o?this.element:t,add:s};n.element.toggleClass(this._classes(n),s);return this},_on:function(e,i,s){var n,o=this;if(typeof e!=="boolean"){s=i;i=e;e=!1};if(!s){s=i;i=this.element;n=this.widget()} +else{i=n=t(i);this.bindings=this.bindings.add(i)};t.each(s,function(s,r){function a(){if(!e&&(o.options.disabled===!0||t(this).hasClass("ui-state-disabled"))){return};return(typeof r==="string"?o[r]:r).apply(o,arguments)};if(typeof r!=="string"){a.guid=r.guid=r.guid||a.guid||t.guid++};var h=s.match(/^([\w:-]*)\s*(.*)$/),l=h[1]+o.eventNamespace,c=h[2];if(c){n.on(l,c,a)} +else{i.on(l,a)}})},_off:function(e,i){i=(i||"").split(" ").join(this.eventNamespace+" ")+this.eventNamespace;e.off(i).off(i);this.bindings=t(this.bindings.not(e).get());this.focusable=t(this.focusable.not(e).get());this.hoverable=t(this.hoverable.not(e).get())},_delay:function(t,e){function s(){return(typeof t==="string"?i[t]:t).apply(i,arguments)};var i=this;return setTimeout(s,e||0)},_hoverable:function(e){this.hoverable=this.hoverable.add(e);this._on(e,{mouseenter:function(e){this._addClass(t(e.currentTarget),null,"ui-state-hover")},mouseleave:function(e){this._removeClass(t(e.currentTarget),null,"ui-state-hover")}})},_focusable:function(e){this.focusable=this.focusable.add(e);this._on(e,{focusin:function(e){this._addClass(t(e.currentTarget),null,"ui-state-focus")},focusout:function(e){this._removeClass(t(e.currentTarget),null,"ui-state-focus")}})},_trigger:function(e,i,s){var o,n,r=this.options[e];s=s||{};i=t.Event(i);i.type=(e===this.widgetEventPrefix?e:this.widgetEventPrefix+e).toLowerCase();i.target=this.element[0];n=i.originalEvent;if(n){for(o in n){if(!(o in i)){i[o]=n[o]}}};this.element.trigger(i,s);return!(t.isFunction(r)&&r.apply(this.element[0],[i].concat(s))===!1||i.isDefaultPrevented())}};t.each({show:"fadeIn",hide:"fadeOut"},function(e,i){t.Widget.prototype["_"+e]=function(s,o,n){if(typeof o==="string"){o={effect:o}};var a,r=!o?e:o===!0||typeof o==="number"?i:o.effect||i;o=o||{};if(typeof o==="number"){o={duration:o}};a=!t.isEmptyObject(o);o.complete=n;if(o.delay){s.delay(o.delay)};if(a&&t.effects&&t.effects.effect[r]){s[e](o)} +else if(r!==e&&s[r]){s[r](o.duration,o.easing,n)} +else{s.queue(function(i){t(this)[e]();if(n){n.call(s[0])};i()})}}});var m=t.widget; /*! * jQuery UI :data 1.12.1 * http://jqueryui.com @@ -195,7 +195,7 @@ else{s.queue(function(i){t(this)[e]();if(o){o.call(s[0])};i()})}}});var l=t.widg * Released under the MIT license. * http://jquery.org/license */ -;var a=t.extend(t.expr[":"],{data:t.expr.createPseudo?t.expr.createPseudo(function(e){return function(i){return!!t.data(i,e)}}):function(e,i,s){return!!t.data(e,s[3])}}); +;var d=t.extend(t.expr[":"],{data:t.expr.createPseudo?t.expr.createPseudo(function(e){return function(i){return!!t.data(i,e)}}):function(e,i,s){return!!t.data(e,s[3])}}); /*! * jQuery UI Scroll Parent 1.12.1 * http://jqueryui.com @@ -204,7 +204,7 @@ else{s.queue(function(i){t(this)[e]();if(o){o.call(s[0])};i()})}}});var l=t.widg * Released under the MIT license. * http://jquery.org/license */ -;var r=t.fn.scrollParent=function(e){var i=this.css("position"),n=i==="absolute",o=e?/(auto|scroll|hidden)/:/(auto|scroll)/,s=this.parents().filter(function(){var e=t(this);if(n&&e.css("position")==="static"){return!1};return o.test(e.css("overflow")+e.css("overflow-y")+e.css("overflow-x"))}).eq(0);return i==="fixed"||!s.length?t(this[0].ownerDocument||document):s},h=t.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase()); +;var p=t.fn.scrollParent=function(e){var i=this.css("position"),o=i==="absolute",n=e?/(auto|scroll|hidden)/:/(auto|scroll)/,s=this.parents().filter(function(){var e=t(this);if(o&&e.css("position")==="static"){return!1};return n.test(e.css("overflow")+e.css("overflow-y")+e.css("overflow-x"))}).eq(0);return i==="fixed"||!s.length?t(this[0].ownerDocument||document):s},u=t.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase()); /*! * jQuery UI Mouse 1.12.1 * http://jqueryui.com @@ -213,9 +213,39 @@ else{s.queue(function(i){t(this)[e]();if(o){o.call(s[0])};i()})}}});var l=t.widg * Released under the MIT license. * http://jquery.org/license */ -;var e=!1;t(document).on("mouseup",function(){e=!1});var o=t.widget("ui.mouse",{version:"1.12.1",options:{cancel:"input, textarea, button, select, option",distance:1,delay:0},_mouseInit:function(){var e=this;this.element.on("mousedown."+this.widgetName,function(t){return e._mouseDown(t)}).on("click."+this.widgetName,function(i){if(!0===t.data(i.target,e.widgetName+".preventClickEvent")){t.removeData(i.target,e.widgetName+".preventClickEvent");i.stopImmediatePropagation();return!1}});this.started=!1},_mouseDestroy:function(){this.element.off("."+this.widgetName);if(this._mouseMoveDelegate){this.document.off("mousemove."+this.widgetName,this._mouseMoveDelegate).off("mouseup."+this.widgetName,this._mouseUpDelegate)}},_mouseDown:function(i){if(e){return};this._mouseMoved=!1;(this._mouseStarted&&this._mouseUp(i));this._mouseDownEvent=i;var s=this,n=(i.which===1),o=(typeof this.options.cancel==="string"&&i.target.nodeName?t(i.target).closest(this.options.cancel).length:!1);if(!n||o||!this._mouseCapture(i)){return!0};this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){s.mouseDelayMet=!0},this.options.delay)};if(this._mouseDistanceMet(i)&&this._mouseDelayMet(i)){this._mouseStarted=(this._mouseStart(i)!==!1);if(!this._mouseStarted){i.preventDefault();return!0}};if(!0===t.data(i.target,this.widgetName+".preventClickEvent")){t.removeData(i.target,this.widgetName+".preventClickEvent")};this._mouseMoveDelegate=function(t){return s._mouseMove(t)};this._mouseUpDelegate=function(t){return s._mouseUp(t)};this.document.on("mousemove."+this.widgetName,this._mouseMoveDelegate).on("mouseup."+this.widgetName,this._mouseUpDelegate);i.preventDefault();e=!0;return!0},_mouseMove:function(e){if(this._mouseMoved){if(t.ui.ie&&(!document.documentMode||document.documentMode<9)&&!e.button){return this._mouseUp(e)} +;var e=!1;t(document).on("mouseup",function(){e=!1});var f=t.widget("ui.mouse",{version:"1.12.1",options:{cancel:"input, textarea, button, select, option",distance:1,delay:0},_mouseInit:function(){var e=this;this.element.on("mousedown."+this.widgetName,function(t){return e._mouseDown(t)}).on("click."+this.widgetName,function(i){if(!0===t.data(i.target,e.widgetName+".preventClickEvent")){t.removeData(i.target,e.widgetName+".preventClickEvent");i.stopImmediatePropagation();return!1}});this.started=!1},_mouseDestroy:function(){this.element.off("."+this.widgetName);if(this._mouseMoveDelegate){this.document.off("mousemove."+this.widgetName,this._mouseMoveDelegate).off("mouseup."+this.widgetName,this._mouseUpDelegate)}},_mouseDown:function(i){if(e){return};this._mouseMoved=!1;(this._mouseStarted&&this._mouseUp(i));this._mouseDownEvent=i;var s=this,o=(i.which===1),n=(typeof this.options.cancel==="string"&&i.target.nodeName?t(i.target).closest(this.options.cancel).length:!1);if(!o||n||!this._mouseCapture(i)){return!0};this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){s.mouseDelayMet=!0},this.options.delay)};if(this._mouseDistanceMet(i)&&this._mouseDelayMet(i)){this._mouseStarted=(this._mouseStart(i)!==!1);if(!this._mouseStarted){i.preventDefault();return!0}};if(!0===t.data(i.target,this.widgetName+".preventClickEvent")){t.removeData(i.target,this.widgetName+".preventClickEvent")};this._mouseMoveDelegate=function(t){return s._mouseMove(t)};this._mouseUpDelegate=function(t){return s._mouseUp(t)};this.document.on("mousemove."+this.widgetName,this._mouseMoveDelegate).on("mouseup."+this.widgetName,this._mouseUpDelegate);i.preventDefault();e=!0;return!0},_mouseMove:function(e){if(this._mouseMoved){if(t.ui.ie&&(!document.documentMode||document.documentMode<9)&&!e.button){return this._mouseUp(e)} else if(!e.which){if(e.originalEvent.altKey||e.originalEvent.ctrlKey||e.originalEvent.metaKey||e.originalEvent.shiftKey){this.ignoreMissingWhich=!0} -else if(!this.ignoreMissingWhich){return this._mouseUp(e)}}};if(e.which||e.button){this._mouseMoved=!0};if(this._mouseStarted){this._mouseDrag(e);return e.preventDefault()};if(this._mouseDistanceMet(e)&&this._mouseDelayMet(e)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,e)!==!1);(this._mouseStarted?this._mouseDrag(e):this._mouseUp(e))};return!this._mouseStarted},_mouseUp:function(i){this.document.off("mousemove."+this.widgetName,this._mouseMoveDelegate).off("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=!1;if(i.target===this._mouseDownEvent.target){t.data(i.target,this.widgetName+".preventClickEvent",!0)};this._mouseStop(i)};if(this._mouseDelayTimer){clearTimeout(this._mouseDelayTimer);delete this._mouseDelayTimer};this.ignoreMissingWhich=!1;e=!1;i.preventDefault()},_mouseDistanceMet:function(t){return(Math.max(Math.abs(this._mouseDownEvent.pageX-t.pageX),Math.abs(this._mouseDownEvent.pageY-t.pageY))>=this.options.distance)},_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return!0}}); +else if(!this.ignoreMissingWhich){return this._mouseUp(e)}}};if(e.which||e.button){this._mouseMoved=!0};if(this._mouseStarted){this._mouseDrag(e);return e.preventDefault()};if(this._mouseDistanceMet(e)&&this._mouseDelayMet(e)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,e)!==!1);(this._mouseStarted?this._mouseDrag(e):this._mouseUp(e))};return!this._mouseStarted},_mouseUp:function(i){this.document.off("mousemove."+this.widgetName,this._mouseMoveDelegate).off("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=!1;if(i.target===this._mouseDownEvent.target){t.data(i.target,this.widgetName+".preventClickEvent",!0)};this._mouseStop(i)};if(this._mouseDelayTimer){clearTimeout(this._mouseDelayTimer);delete this._mouseDelayTimer};this.ignoreMissingWhich=!1;e=!1;i.preventDefault()},_mouseDistanceMet:function(t){return(Math.max(Math.abs(this._mouseDownEvent.pageX-t.pageX),Math.abs(this._mouseDownEvent.pageY-t.pageY))>=this.options.distance)},_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return!0}});var c=t.ui.plugin={add:function(e,i,s){var o,n=t.ui[e].prototype;for(o in s){n.plugins[o]=n.plugins[o]||[];n.plugins[o].push([i,s[o]])}},call:function(t,e,i,o){var s,n=t.plugins[e];if(!n){return};if(!o&&(!t.element[0].parentNode||t.element[0].parentNode.nodeType===11)){return};for(s=0;s<n.length;s++){if(t.options[n[s][0]]){n[s][1].apply(t.element,i)}}}};var h=t.ui.safeActiveElement=function(t){var e;try{e=t.activeElement}catch(i){e=t.body};if(!e){e=t.body};if(!e.nodeName){e=t.body};return e},l=t.ui.safeBlur=function(e){if(e&&e.nodeName.toLowerCase()!=="body"){t(e).trigger("blur")}}; +/*! + * jQuery UI Draggable 1.12.1 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + */ +;t.widget("ui.draggable",t.ui.mouse,{version:"1.12.1",widgetEventPrefix:"drag",options:{addClasses:!0,appendTo:"parent",axis:!1,connectToSortable:!1,containment:!1,cursor:"auto",cursorAt:!1,grid:!1,handle:!1,helper:"original",iframeFix:!1,opacity:!1,refreshPositions:!1,revert:!1,revertDuration:500,scope:"default",scroll:!0,scrollSensitivity:20,scrollSpeed:20,snap:!1,snapMode:"both",snapTolerance:20,stack:!1,zIndex:!1,drag:null,start:null,stop:null},_create:function(){if(this.options.helper==="original"){this._setPositionRelative()};if(this.options.addClasses){this._addClass("ui-draggable")};this._setHandleClassName();this._mouseInit()},_setOption:function(t,e){this._super(t,e);if(t==="handle"){this._removeHandleClassName();this._setHandleClassName()}},_destroy:function(){if((this.helper||this.element).is(".ui-draggable-dragging")){this.destroyOnClear=!0;return};this._removeHandleClassName();this._mouseDestroy()},_mouseCapture:function(e){var i=this.options;if(this.helper||i.disabled||t(e.target).closest(".ui-resizable-handle").length>0){return!1};this.handle=this._getHandle(e);if(!this.handle){return!1};this._blurActiveElement(e);this._blockFrames(i.iframeFix===!0?"iframe":i.iframeFix);return!0},_blockFrames:function(e){this.iframeBlocks=this.document.find(e).map(function(){var e=t(this);return t("<div>").css("position","absolute").appendTo(e.parent()).outerWidth(e.outerWidth()).outerHeight(e.outerHeight()).offset(e.offset())[0]})},_unblockFrames:function(){if(this.iframeBlocks){this.iframeBlocks.remove();delete this.iframeBlocks}},_blurActiveElement:function(e){var i=t.ui.safeActiveElement(this.document[0]),s=t(e.target);if(s.closest(i).length){return};t.ui.safeBlur(i)},_mouseStart:function(e){var i=this.options;this.helper=this._createHelper(e);this._addClass(this.helper,"ui-draggable-dragging");this._cacheHelperProportions();if(t.ui.ddmanager){t.ui.ddmanager.current=this};this._cacheMargins();this.cssPosition=this.helper.css("position");this.scrollParent=this.helper.scrollParent(!0);this.offsetParent=this.helper.offsetParent();this.hasFixedAncestor=this.helper.parents().filter(function(){return t(this).css("position")==="fixed"}).length>0;this.positionAbs=this.element.offset();this._refreshOffsets(e);this.originalPosition=this.position=this._generatePosition(e,!1);this.originalPageX=e.pageX;this.originalPageY=e.pageY;(i.cursorAt&&this._adjustOffsetFromHelper(i.cursorAt));this._setContainment();if(this._trigger("start",e)===!1){this._clear();return!1};this._cacheHelperProportions();if(t.ui.ddmanager&&!i.dropBehaviour){t.ui.ddmanager.prepareOffsets(this,e)};this._mouseDrag(e,!0);if(t.ui.ddmanager){t.ui.ddmanager.dragStart(this,e)};return!0},_refreshOffsets:function(t){this.offset={top:this.positionAbs.top-this.margins.top,left:this.positionAbs.left-this.margins.left,scroll:!1,parent:this._getParentOffset(),relative:this._getRelativeOffset()};this.offset.click={left:t.pageX-this.offset.left,top:t.pageY-this.offset.top}},_mouseDrag:function(e,i){if(this.hasFixedAncestor){this.offset.parent=this._getParentOffset()};this.position=this._generatePosition(e,!0);this.positionAbs=this._convertPositionTo("absolute");if(!i){var s=this._uiHash();if(this._trigger("drag",e,s)===!1){this._mouseUp(new t.Event("mouseup",e));return!1};this.position=s.position};this.helper[0].style.left=this.position.left+"px";this.helper[0].style.top=this.position.top+"px";if(t.ui.ddmanager){t.ui.ddmanager.drag(this,e)};return!1},_mouseStop:function(e){var s=this,i=!1;if(t.ui.ddmanager&&!this.options.dropBehaviour){i=t.ui.ddmanager.drop(this,e)};if(this.dropped){i=this.dropped;this.dropped=!1};if((this.options.revert==="invalid"&&!i)||(this.options.revert==="valid"&&i)||this.options.revert===!0||(t.isFunction(this.options.revert)&&this.options.revert.call(this.element,i))){t(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){if(s._trigger("stop",e)!==!1){s._clear()}})} +else{if(this._trigger("stop",e)!==!1){this._clear()}};return!1},_mouseUp:function(e){this._unblockFrames();if(t.ui.ddmanager){t.ui.ddmanager.dragStop(this,e)};if(this.handleElement.is(e.target)){this.element.trigger("focus")};return t.ui.mouse.prototype._mouseUp.call(this,e)},cancel:function(){if(this.helper.is(".ui-draggable-dragging")){this._mouseUp(new t.Event("mouseup",{target:this.element[0]}))} +else{this._clear()};return this},_getHandle:function(e){return this.options.handle?!!t(e.target).closest(this.element.find(this.options.handle)).length:!0},_setHandleClassName:function(){this.handleElement=this.options.handle?this.element.find(this.options.handle):this.element;this._addClass(this.handleElement,"ui-draggable-handle")},_removeHandleClassName:function(){this._removeClass(this.handleElement,"ui-draggable-handle")},_createHelper:function(e){var s=this.options,o=t.isFunction(s.helper),i=o?t(s.helper.apply(this.element[0],[e])):(s.helper==="clone"?this.element.clone().removeAttr("id"):this.element);if(!i.parents("body").length){i.appendTo((s.appendTo==="parent"?this.element[0].parentNode:s.appendTo))};if(o&&i[0]===this.element[0]){this._setPositionRelative()};if(i[0]!==this.element[0]&&!(/(fixed|absolute)/).test(i.css("position"))){i.css("position","absolute")};return i},_setPositionRelative:function(){if(!(/^(?:r|a|f)/).test(this.element.css("position"))){this.element[0].style.position="relative"}},_adjustOffsetFromHelper:function(e){if(typeof e==="string"){e=e.split(" ")};if(t.isArray(e)){e={left:+e[0],top:+e[1]||0}};if("left" in e){this.offset.click.left=e.left+this.margins.left};if("right" in e){this.offset.click.left=this.helperProportions.width-e.right+this.margins.left};if("top" in e){this.offset.click.top=e.top+this.margins.top};if("bottom" in e){this.offset.click.top=this.helperProportions.height-e.bottom+this.margins.top}},_isRootNode:function(t){return(/(html|body)/i).test(t.tagName)||t===this.document[0]},_getParentOffset:function(){var e=this.offsetParent.offset(),i=this.document[0];if(this.cssPosition==="absolute"&&this.scrollParent[0]!==i&&t.contains(this.scrollParent[0],this.offsetParent[0])){e.left+=this.scrollParent.scrollLeft();e.top+=this.scrollParent.scrollTop()};if(this._isRootNode(this.offsetParent[0])){e={top:0,left:0}};return{top:e.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:e.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition!=="relative"){return{top:0,left:0}};var t=this.element.position(),e=this._isRootNode(this.scrollParent[0]);return{top:t.top-(parseInt(this.helper.css("top"),10)||0)+(!e?this.scrollParent.scrollTop():0),left:t.left-(parseInt(this.helper.css("left"),10)||0)+(!e?this.scrollParent.scrollLeft():0)}},_cacheMargins:function(){this.margins={left:(parseInt(this.element.css("marginLeft"),10)||0),top:(parseInt(this.element.css("marginTop"),10)||0),right:(parseInt(this.element.css("marginRight"),10)||0),bottom:(parseInt(this.element.css("marginBottom"),10)||0)}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var n,e,i,s=this.options,o=this.document[0];this.relativeContainer=null;if(!s.containment){this.containment=null;return};if(s.containment==="window"){this.containment=[t(window).scrollLeft()-this.offset.relative.left-this.offset.parent.left,t(window).scrollTop()-this.offset.relative.top-this.offset.parent.top,t(window).scrollLeft()+t(window).width()-this.helperProportions.width-this.margins.left,t(window).scrollTop()+(t(window).height()||o.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top];return};if(s.containment==="document"){this.containment=[0,0,t(o).width()-this.helperProportions.width-this.margins.left,(t(o).height()||o.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top];return};if(s.containment.constructor===Array){this.containment=s.containment;return};if(s.containment==="parent"){s.containment=this.helper[0].parentNode};e=t(s.containment);i=e[0];if(!i){return};n=/(scroll|auto)/.test(e.css("overflow"));this.containment=[(parseInt(e.css("borderLeftWidth"),10)||0)+(parseInt(e.css("paddingLeft"),10)||0),(parseInt(e.css("borderTopWidth"),10)||0)+(parseInt(e.css("paddingTop"),10)||0),(n?Math.max(i.scrollWidth,i.offsetWidth):i.offsetWidth)-(parseInt(e.css("borderRightWidth"),10)||0)-(parseInt(e.css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left-this.margins.right,(n?Math.max(i.scrollHeight,i.offsetHeight):i.offsetHeight)-(parseInt(e.css("borderBottomWidth"),10)||0)-(parseInt(e.css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top-this.margins.bottom];this.relativeContainer=e},_convertPositionTo:function(t,e){if(!e){e=this.position};var i=t==="absolute"?1:-1,s=this._isRootNode(this.scrollParent[0]);return{top:(e.top+this.offset.relative.top*i+this.offset.parent.top*i-((this.cssPosition==="fixed"?-this.offset.scroll.top:(s?0:this.offset.scroll.top))*i)),left:(e.left+this.offset.relative.left*i+this.offset.parent.left*i-((this.cssPosition==="fixed"?-this.offset.scroll.left:(s?0:this.offset.scroll.left))*i))}},_generatePosition:function(t,e){var i,h,o,n,s=this.options,l=this._isRootNode(this.scrollParent[0]),r=t.pageX,a=t.pageY;if(!l||!this.offset.scroll){this.offset.scroll={top:this.scrollParent.scrollTop(),left:this.scrollParent.scrollLeft()}};if(e){if(this.containment){if(this.relativeContainer){h=this.relativeContainer.offset();i=[this.containment[0]+h.left,this.containment[1]+h.top,this.containment[2]+h.left,this.containment[3]+h.top]} +else{i=this.containment};if(t.pageX-this.offset.click.left<i[0]){r=i[0]+this.offset.click.left};if(t.pageY-this.offset.click.top<i[1]){a=i[1]+this.offset.click.top};if(t.pageX-this.offset.click.left>i[2]){r=i[2]+this.offset.click.left};if(t.pageY-this.offset.click.top>i[3]){a=i[3]+this.offset.click.top}};if(s.grid){o=s.grid[1]?this.originalPageY+Math.round((a-this.originalPageY)/s.grid[1])*s.grid[1]:this.originalPageY;a=i?((o-this.offset.click.top>=i[1]||o-this.offset.click.top>i[3])?o:((o-this.offset.click.top>=i[1])?o-s.grid[1]:o+s.grid[1])):o;n=s.grid[0]?this.originalPageX+Math.round((r-this.originalPageX)/s.grid[0])*s.grid[0]:this.originalPageX;r=i?((n-this.offset.click.left>=i[0]||n-this.offset.click.left>i[2])?n:((n-this.offset.click.left>=i[0])?n-s.grid[0]:n+s.grid[0])):n};if(s.axis==="y"){r=this.originalPageX};if(s.axis==="x"){a=this.originalPageY}};return{top:(a-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+(this.cssPosition==="fixed"?-this.offset.scroll.top:(l?0:this.offset.scroll.top))),left:(r-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+(this.cssPosition==="fixed"?-this.offset.scroll.left:(l?0:this.offset.scroll.left)))}},_clear:function(){this._removeClass(this.helper,"ui-draggable-dragging");if(this.helper[0]!==this.element[0]&&!this.cancelHelperRemoval){this.helper.remove()};this.helper=null;this.cancelHelperRemoval=!1;if(this.destroyOnClear){this.destroy()}},_trigger:function(e,i,s){s=s||this._uiHash();t.ui.plugin.call(this,e,[i,s,this],!0);if(/^(drag|start|stop)/.test(e)){this.positionAbs=this._convertPositionTo("absolute");s.offset=this.positionAbs};return t.Widget.prototype._trigger.call(this,e,i,s)},plugins:{},_uiHash:function(){return{helper:this.helper,position:this.position,originalPosition:this.originalPosition,offset:this.positionAbs}}});t.ui.plugin.add("draggable","connectToSortable",{start:function(e,i,s){var o=t.extend({},i,{item:s.element});s.sortables=[];t(s.options.connectToSortable).each(function(){var i=t(this).sortable("instance");if(i&&!i.options.disabled){s.sortables.push(i);i.refreshPositions();i._trigger("activate",e,o)}})},stop:function(e,i,s){var o=t.extend({},i,{item:s.element});s.cancelHelperRemoval=!1;t.each(s.sortables,function(){var t=this;if(t.isOver){t.isOver=0;s.cancelHelperRemoval=!0;t.cancelHelperRemoval=!1;t._storedCSS={position:t.placeholder.css("position"),top:t.placeholder.css("top"),left:t.placeholder.css("left")};t._mouseStop(e);t.options.helper=t.options._helper} +else{t.cancelHelperRemoval=!0;t._trigger("deactivate",e,o)}})},drag:function(e,i,s){t.each(s.sortables,function(){var n=!1,o=this;o.positionAbs=s.positionAbs;o.helperProportions=s.helperProportions;o.offset.click=s.offset.click;if(o._intersectsWith(o.containerCache)){n=!0;t.each(s.sortables,function(){this.positionAbs=s.positionAbs;this.helperProportions=s.helperProportions;this.offset.click=s.offset.click;if(this!==o&&this._intersectsWith(this.containerCache)&&t.contains(o.element[0],this.element[0])){n=!1};return n})};if(n){if(!o.isOver){o.isOver=1;s._parent=i.helper.parent();o.currentItem=i.helper.appendTo(o.element).data("ui-sortable-item",!0);o.options._helper=o.options.helper;o.options.helper=function(){return i.helper[0]};e.target=o.currentItem[0];o._mouseCapture(e,!0);o._mouseStart(e,!0,!0);o.offset.click.top=s.offset.click.top;o.offset.click.left=s.offset.click.left;o.offset.parent.left-=s.offset.parent.left-o.offset.parent.left;o.offset.parent.top-=s.offset.parent.top-o.offset.parent.top;s._trigger("toSortable",e);s.dropped=o.element;t.each(s.sortables,function(){this.refreshPositions()});s.currentItem=s.element;o.fromOutside=s};if(o.currentItem){o._mouseDrag(e);i.position=o.position}} +else{if(o.isOver){o.isOver=0;o.cancelHelperRemoval=!0;o.options._revert=o.options.revert;o.options.revert=!1;o._trigger("out",e,o._uiHash(o));o._mouseStop(e,!0);o.options.revert=o.options._revert;o.options.helper=o.options._helper;if(o.placeholder){o.placeholder.remove()};i.helper.appendTo(s._parent);s._refreshOffsets(e);i.position=s._generatePosition(e,!0);s._trigger("fromSortable",e);s.dropped=!1;t.each(s.sortables,function(){this.refreshPositions()})}}})}});t.ui.plugin.add("draggable","cursor",{start:function(e,i,s){var o=t("body"),n=s.options;if(o.css("cursor")){n._cursor=o.css("cursor")};o.css("cursor",n.cursor)},stop:function(e,i,s){var o=s.options;if(o._cursor){t("body").css("cursor",o._cursor)}}});t.ui.plugin.add("draggable","opacity",{start:function(e,i,s){var o=t(i.helper),n=s.options;if(o.css("opacity")){n._opacity=o.css("opacity")};o.css("opacity",n.opacity)},stop:function(e,i,s){var o=s.options;if(o._opacity){t(i.helper).css("opacity",o._opacity)}}});t.ui.plugin.add("draggable","scroll",{start:function(t,e,i){if(!i.scrollParentNotHidden){i.scrollParentNotHidden=i.helper.scrollParent(!1)};if(i.scrollParentNotHidden[0]!==i.document[0]&&i.scrollParentNotHidden[0].tagName!=="HTML"){i.overflowOffset=i.scrollParentNotHidden.offset()}},drag:function(e,i,s){var o=s.options,a=!1,r=s.scrollParentNotHidden[0],n=s.document[0];if(r!==n&&r.tagName!=="HTML"){if(!o.axis||o.axis!=="x"){if((s.overflowOffset.top+r.offsetHeight)-e.pageY<o.scrollSensitivity){r.scrollTop=a=r.scrollTop+o.scrollSpeed} +else if(e.pageY-s.overflowOffset.top<o.scrollSensitivity){r.scrollTop=a=r.scrollTop-o.scrollSpeed}};if(!o.axis||o.axis!=="y"){if((s.overflowOffset.left+r.offsetWidth)-e.pageX<o.scrollSensitivity){r.scrollLeft=a=r.scrollLeft+o.scrollSpeed} +else if(e.pageX-s.overflowOffset.left<o.scrollSensitivity){r.scrollLeft=a=r.scrollLeft-o.scrollSpeed}}} +else{if(!o.axis||o.axis!=="x"){if(e.pageY-t(n).scrollTop()<o.scrollSensitivity){a=t(n).scrollTop(t(n).scrollTop()-o.scrollSpeed)} +else if(t(window).height()-(e.pageY-t(n).scrollTop())<o.scrollSensitivity){a=t(n).scrollTop(t(n).scrollTop()+o.scrollSpeed)}};if(!o.axis||o.axis!=="y"){if(e.pageX-t(n).scrollLeft()<o.scrollSensitivity){a=t(n).scrollLeft(t(n).scrollLeft()-o.scrollSpeed)} +else if(t(window).width()-(e.pageX-t(n).scrollLeft())<o.scrollSensitivity){a=t(n).scrollLeft(t(n).scrollLeft()+o.scrollSpeed)}}};if(a!==!1&&t.ui.ddmanager&&!o.dropBehaviour){t.ui.ddmanager.prepareOffsets(s,e)}}});t.ui.plugin.add("draggable","snap",{start:function(e,i,s){var o=s.options;s.snapElements=[];t(o.snap.constructor!==String?(o.snap.items||":data(ui-draggable)"):o.snap).each(function(){var e=t(this),i=e.offset();if(this!==s.element[0]){s.snapElements.push({item:this,width:e.outerWidth(),height:e.outerHeight(),top:i.top,left:i.left})}})},drag:function(e,i,s){var r,a,h,l,c,p,f,u,o,g,v=s.options,n=v.snapTolerance,d=i.offset.left,b=d+s.helperProportions.width,m=i.offset.top,P=m+s.helperProportions.height;for(o=s.snapElements.length-1;o>=0;o--){c=s.snapElements[o].left-s.margins.left;p=c+s.snapElements[o].width;f=s.snapElements[o].top-s.margins.top;u=f+s.snapElements[o].height;if(b<c-n||d>p+n||P<f-n||m>u+n||!t.contains(s.snapElements[o].item.ownerDocument,s.snapElements[o].item)){if(s.snapElements[o].snapping){(s.options.snap.release&&s.options.snap.release.call(s.element,e,t.extend(s._uiHash(),{snapItem:s.snapElements[o].item})))};s.snapElements[o].snapping=!1;continue};if(v.snapMode!=="inner"){r=Math.abs(f-P)<=n;a=Math.abs(u-m)<=n;h=Math.abs(c-b)<=n;l=Math.abs(p-d)<=n;if(r){i.position.top=s._convertPositionTo("relative",{top:f-s.helperProportions.height,left:0}).top};if(a){i.position.top=s._convertPositionTo("relative",{top:u,left:0}).top};if(h){i.position.left=s._convertPositionTo("relative",{top:0,left:c-s.helperProportions.width}).left};if(l){i.position.left=s._convertPositionTo("relative",{top:0,left:p}).left}};g=(r||a||h||l);if(v.snapMode!=="outer"){r=Math.abs(f-m)<=n;a=Math.abs(u-P)<=n;h=Math.abs(c-d)<=n;l=Math.abs(p-b)<=n;if(r){i.position.top=s._convertPositionTo("relative",{top:f,left:0}).top};if(a){i.position.top=s._convertPositionTo("relative",{top:u-s.helperProportions.height,left:0}).top};if(h){i.position.left=s._convertPositionTo("relative",{top:0,left:c}).left};if(l){i.position.left=s._convertPositionTo("relative",{top:0,left:p-s.helperProportions.width}).left}};if(!s.snapElements[o].snapping&&(r||a||h||l||g)){(s.options.snap.snap&&s.options.snap.snap.call(s.element,e,t.extend(s._uiHash(),{snapItem:s.snapElements[o].item})))};s.snapElements[o].snapping=(r||a||h||l||g)}}});t.ui.plugin.add("draggable","stack",{start:function(e,i,s){var n,r=s.options,o=t.makeArray(t(r.stack)).sort(function(e,i){return(parseInt(t(e).css("zIndex"),10)||0)-(parseInt(t(i).css("zIndex"),10)||0)});if(!o.length){return};n=parseInt(t(o[0]).css("zIndex"),10)||0;t(o).each(function(e){t(this).css("zIndex",n+e)});this.css("zIndex",(n+o.length))}});t.ui.plugin.add("draggable","zIndex",{start:function(e,i,s){var o=t(i.helper),n=s.options;if(o.css("zIndex")){n._zIndex=o.css("zIndex")};o.css("zIndex",n.zIndex)},stop:function(e,i,s){var o=s.options;if(o._zIndex){t(i.helper).css("zIndex",o._zIndex)}}});var a=t.ui.draggable; +/*! + * jQuery UI Droppable 1.12.1 + * http://jqueryui.com + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + */ +;t.widget("ui.droppable",{version:"1.12.1",widgetEventPrefix:"drop",options:{accept:"*",addClasses:!0,greedy:!1,scope:"default",tolerance:"intersect",activate:null,deactivate:null,drop:null,out:null,over:null},_create:function(){var e,i=this.options,s=i.accept;this.isover=!1;this.isout=!0;this.accept=t.isFunction(s)?s:function(t){return t.is(s)};this.proportions=function(){if(arguments.length){e=arguments[0]} +else{return e?e:e={width:this.element[0].offsetWidth,height:this.element[0].offsetHeight}}};this._addToManager(i.scope);i.addClasses&&this._addClass("ui-droppable")},_addToManager:function(e){t.ui.ddmanager.droppables[e]=t.ui.ddmanager.droppables[e]||[];t.ui.ddmanager.droppables[e].push(this)},_splice:function(t){var e=0;for(;e<t.length;e++){if(t[e]===this){t.splice(e,1)}}},_destroy:function(){var e=t.ui.ddmanager.droppables[this.options.scope];this._splice(e)},_setOption:function(e,i){if(e==="accept"){this.accept=t.isFunction(i)?i:function(t){return t.is(i)}} +else if(e==="scope"){var s=t.ui.ddmanager.droppables[this.options.scope];this._splice(s);this._addToManager(i)};this._super(e,i)},_activate:function(e){var i=t.ui.ddmanager.current;this._addActiveClass();if(i){this._trigger("activate",e,this.ui(i))}},_deactivate:function(e){var i=t.ui.ddmanager.current;this._removeActiveClass();if(i){this._trigger("deactivate",e,this.ui(i))}},_over:function(e){var i=t.ui.ddmanager.current;if(!i||(i.currentItem||i.element)[0]===this.element[0]){return};if(this.accept.call(this.element[0],(i.currentItem||i.element))){this._addHoverClass();this._trigger("over",e,this.ui(i))}},_out:function(e){var i=t.ui.ddmanager.current;if(!i||(i.currentItem||i.element)[0]===this.element[0]){return};if(this.accept.call(this.element[0],(i.currentItem||i.element))){this._removeHoverClass();this._trigger("out",e,this.ui(i))}},_drop:function(e,s){var o=s||t.ui.ddmanager.current,n=!1;if(!o||(o.currentItem||o.element)[0]===this.element[0]){return!1};this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function(){var s=t(this).droppable("instance");if(s.options.greedy&&!s.options.disabled&&s.options.scope===o.options.scope&&s.accept.call(s.element[0],(o.currentItem||o.element))&&i(o,t.extend(s,{offset:s.element.offset()}),s.options.tolerance,e)){n=!0;return!1}});if(n){return!1};if(this.accept.call(this.element[0],(o.currentItem||o.element))){this._removeActiveClass();this._removeHoverClass();this._trigger("drop",e,this.ui(o));return this.element};return!1},ui:function(t){return{draggable:(t.currentItem||t.element),helper:t.helper,position:t.position,offset:t.positionAbs}},_addHoverClass:function(){this._addClass("ui-droppable-hover")},_removeHoverClass:function(){this._removeClass("ui-droppable-hover")},_addActiveClass:function(){this._addClass("ui-droppable-active")},_removeActiveClass:function(){this._removeClass("ui-droppable-active")}});var i=t.ui.intersect=(function(){function t(t,e,i){return(t>=e)&&(t<(e+i))};return function(e,i,s,h){if(!i.offset){return!1};var r=(e.positionAbs||e.position.absolute).left+e.margins.left,a=(e.positionAbs||e.position.absolute).top+e.margins.top,l=r+e.helperProportions.width,c=a+e.helperProportions.height,o=i.offset.left,n=i.offset.top,f=o+i.proportions().width,p=n+i.proportions().height;switch(s){case"fit":return(o<=r&&l<=f&&n<=a&&c<=p);case"intersect":return(o<r+(e.helperProportions.width/2)&&l-(e.helperProportions.width/2)<f&&n<a+(e.helperProportions.height/2)&&c-(e.helperProportions.height/2)<p);case"pointer":return t(h.pageY,n,i.proportions().height)&&t(h.pageX,o,i.proportions().width);case"touch":return((a>=n&&a<=p)||(c>=n&&c<=p)||(a<n&&c>p))&&((r>=o&&r<=f)||(l>=o&&l<=f)||(r<o&&l>f));default:return!1}}})();t.ui.ddmanager={current:null,droppables:{"default":[]},prepareOffsets:function(e,i){var s,n,o=t.ui.ddmanager.droppables[e.options.scope]||[],a=i?i.type:null,r=(e.currentItem||e.element).find(":data(ui-droppable)").addBack();droppablesLoop:for(s=0;s<o.length;s++){if(o[s].options.disabled||(e&&!o[s].accept.call(o[s].element[0],(e.currentItem||e.element)))){continue};for(n=0;n<r.length;n++){if(r[n]===o[s].element[0]){o[s].proportions().height=0;continue;droppablesLoop}};o[s].visible=o[s].element.css("display")!=="none";if(!o[s].visible){continue};if(a==="mousedown"){o[s]._activate.call(o[s],i)};o[s].offset=o[s].element.offset();o[s].proportions({width:o[s].element[0].offsetWidth,height:o[s].element[0].offsetHeight})}},drop:function(e,s){var o=!1;t.each((t.ui.ddmanager.droppables[e.options.scope]||[]).slice(),function(){if(!this.options){return};if(!this.options.disabled&&this.visible&&i(e,this,this.options.tolerance,s)){o=this._drop.call(this,s)||o};if(!this.options.disabled&&this.visible&&this.accept.call(this.element[0],(e.currentItem||e.element))){this.isout=!0;this.isover=!1;this._deactivate.call(this,s)}});return o},dragStart:function(e,i){e.element.parentsUntil("body").on("scroll.droppable",function(){if(!e.options.refreshPositions){t.ui.ddmanager.prepareOffsets(e,i)}})},drag:function(e,s){if(e.options.refreshPositions){t.ui.ddmanager.prepareOffsets(e,s)};t.each(t.ui.ddmanager.droppables[e.options.scope]||[],function(){if(this.options.disabled||this.greedyChild||!this.visible){return};var o,a,r,h=i(e,this,this.options.tolerance,s),n=!h&&this.isover?"isout":(h&&!this.isover?"isover":null);if(!n){return};if(this.options.greedy){a=this.options.scope;r=this.element.parents(":data(ui-droppable)").filter(function(){return t(this).droppable("instance").options.scope===a});if(r.length){o=t(r[0]).droppable("instance");o.greedyChild=(n==="isover")}};if(o&&n==="isover"){o.isover=!1;o.isout=!0;o._out.call(o,s)};this[n]=!0;this[n==="isout"?"isover":"isout"]=!1;this[n==="isover"?"_over":"_out"].call(this,s);if(o&&n==="isout"){o.isout=!1;o.isover=!0;o._over.call(o,s)}})},dragStop:function(e,i){e.element.parentsUntil("body").off("scroll.droppable");if(!e.options.refreshPositions){t.ui.ddmanager.prepareOffsets(e,i)}}};if(t.uiBackCompat!==!1){t.widget("ui.droppable",t.ui.droppable,{options:{hoverClass:!1,activeClass:!1},_addActiveClass:function(){this._super();if(this.options.activeClass){this.element.addClass(this.options.activeClass)}},_removeActiveClass:function(){this._super();if(this.options.activeClass){this.element.removeClass(this.options.activeClass)}},_addHoverClass:function(){this._super();if(this.options.hoverClass){this.element.addClass(this.options.hoverClass)}},_removeHoverClass:function(){this._super();if(this.options.hoverClass){this.element.removeClass(this.options.hoverClass)}}})};var r=t.ui.droppable; /*! * jQuery UI Sortable 1.12.1 * http://jqueryui.com @@ -224,25 +254,25 @@ else if(!this.ignoreMissingWhich){return this._mouseUp(e)}}};if(e.which||e.butto * Released under the MIT license. * http://jquery.org/license */ -;var n=t.widget("ui.sortable",t.ui.mouse,{version:"1.12.1",widgetEventPrefix:"sort",ready:!1,options:{appendTo:"parent",axis:!1,connectWith:!1,containment:!1,cursor:"auto",cursorAt:!1,dropOnEmpty:!0,forcePlaceholderSize:!1,forceHelperSize:!1,grid:!1,handle:!1,helper:"original",items:"> *",opacity:!1,placeholder:!1,revert:!1,scroll:!0,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1000,activate:null,beforeStop:null,change:null,deactivate:null,out:null,over:null,receive:null,remove:null,sort:null,start:null,stop:null,update:null},_isOverAxis:function(t,e,i){return(t>=e)&&(t<(e+i))},_isFloating:function(t){return(/left|right/).test(t.css("float"))||(/inline|table-cell/).test(t.css("display"))},_create:function(){this.containerCache={};this._addClass("ui-sortable");this.refresh();this.offset=this.element.offset();this._mouseInit();this._setHandleClassName();this.ready=!0},_setOption:function(t,e){this._super(t,e);if(t==="handle"){this._setHandleClassName()}},_setHandleClassName:function(){var e=this;this._removeClass(this.element.find(".ui-sortable-handle"),"ui-sortable-handle");t.each(this.items,function(){e._addClass(this.instance.options.handle?this.item.find(this.instance.options.handle):this.item,"ui-sortable-handle")})},_destroy:function(){this._mouseDestroy();for(var t=this.items.length-1;t>=0;t--){this.items[t].item.removeData(this.widgetName+"-item")};return this},_mouseCapture:function(e,i){var s=null,o=!1,n=this;if(this.reverting){return!1};if(this.options.disabled||this.options.type==="static"){return!1};this._refreshItems(e);t(e.target).parents().each(function(){if(t.data(this,n.widgetName+"-item")===n){s=t(this);return!1}});if(t.data(e.target,n.widgetName+"-item")===n){s=t(e.target)};if(!s){return!1};if(this.options.handle&&!i){t(this.options.handle,s).find("*").addBack().each(function(){if(this===e.target){o=!0}});if(!o){return!1}};this.currentItem=s;this._removeCurrentsFromItems();return!0},_mouseStart:function(e,i,s){var o,r,n=this.options;this.currentContainer=this;this.refreshPositions();this.helper=this._createHelper(e);this._cacheHelperProportions();this._cacheMargins();this.scrollParent=this.helper.scrollParent();this.offset=this.currentItem.offset();this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};t.extend(this.offset,{click:{left:e.pageX-this.offset.left,top:e.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()});this.helper.css("position","absolute");this.cssPosition=this.helper.css("position");this.originalPosition=this._generatePosition(e);this.originalPageX=e.pageX;this.originalPageY=e.pageY;(n.cursorAt&&this._adjustOffsetFromHelper(n.cursorAt));this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]};if(this.helper[0]!==this.currentItem[0]){this.currentItem.hide()};this._createPlaceholder();if(n.containment){this._setContainment()};if(n.cursor&&n.cursor!=="auto"){r=this.document.find("body");this.storedCursor=r.css("cursor");r.css("cursor",n.cursor);this.storedStylesheet=t("<style>*{ cursor: "+n.cursor+" !important; }</style>").appendTo(r)};if(n.opacity){if(this.helper.css("opacity")){this._storedOpacity=this.helper.css("opacity")};this.helper.css("opacity",n.opacity)};if(n.zIndex){if(this.helper.css("zIndex")){this._storedZIndex=this.helper.css("zIndex")};this.helper.css("zIndex",n.zIndex)};if(this.scrollParent[0]!==this.document[0]&&this.scrollParent[0].tagName!=="HTML"){this.overflowOffset=this.scrollParent.offset()};this._trigger("start",e,this._uiHash());if(!this._preserveHelperProportions){this._cacheHelperProportions()};if(!s){for(o=this.containers.length-1;o>=0;o--){this.containers[o]._trigger("activate",e,this._uiHash(this))}};if(t.ui.ddmanager){t.ui.ddmanager.current=this};if(t.ui.ddmanager&&!n.dropBehaviour){t.ui.ddmanager.prepareOffsets(this,e)};this.dragging=!0;this._addClass(this.helper,"ui-sortable-helper");this._mouseDrag(e);return!0},_mouseDrag:function(e){var r,n,o,h,i=this.options,s=!1;this.position=this._generatePosition(e);this.positionAbs=this._convertPositionTo("absolute");if(!this.lastPositionAbs){this.lastPositionAbs=this.positionAbs};if(this.options.scroll){if(this.scrollParent[0]!==this.document[0]&&this.scrollParent[0].tagName!=="HTML"){if((this.overflowOffset.top+this.scrollParent[0].offsetHeight)-e.pageY<i.scrollSensitivity){this.scrollParent[0].scrollTop=s=this.scrollParent[0].scrollTop+i.scrollSpeed} +;var n=t.widget("ui.sortable",t.ui.mouse,{version:"1.12.1",widgetEventPrefix:"sort",ready:!1,options:{appendTo:"parent",axis:!1,connectWith:!1,containment:!1,cursor:"auto",cursorAt:!1,dropOnEmpty:!0,forcePlaceholderSize:!1,forceHelperSize:!1,grid:!1,handle:!1,helper:"original",items:"> *",opacity:!1,placeholder:!1,revert:!1,scroll:!0,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1000,activate:null,beforeStop:null,change:null,deactivate:null,out:null,over:null,receive:null,remove:null,sort:null,start:null,stop:null,update:null},_isOverAxis:function(t,e,i){return(t>=e)&&(t<(e+i))},_isFloating:function(t){return(/left|right/).test(t.css("float"))||(/inline|table-cell/).test(t.css("display"))},_create:function(){this.containerCache={};this._addClass("ui-sortable");this.refresh();this.offset=this.element.offset();this._mouseInit();this._setHandleClassName();this.ready=!0},_setOption:function(t,e){this._super(t,e);if(t==="handle"){this._setHandleClassName()}},_setHandleClassName:function(){var e=this;this._removeClass(this.element.find(".ui-sortable-handle"),"ui-sortable-handle");t.each(this.items,function(){e._addClass(this.instance.options.handle?this.item.find(this.instance.options.handle):this.item,"ui-sortable-handle")})},_destroy:function(){this._mouseDestroy();for(var t=this.items.length-1;t>=0;t--){this.items[t].item.removeData(this.widgetName+"-item")};return this},_mouseCapture:function(e,i){var s=null,n=!1,o=this;if(this.reverting){return!1};if(this.options.disabled||this.options.type==="static"){return!1};this._refreshItems(e);t(e.target).parents().each(function(){if(t.data(this,o.widgetName+"-item")===o){s=t(this);return!1}});if(t.data(e.target,o.widgetName+"-item")===o){s=t(e.target)};if(!s){return!1};if(this.options.handle&&!i){t(this.options.handle,s).find("*").addBack().each(function(){if(this===e.target){n=!0}});if(!n){return!1}};this.currentItem=s;this._removeCurrentsFromItems();return!0},_mouseStart:function(e,i,s){var n,r,o=this.options;this.currentContainer=this;this.refreshPositions();this.helper=this._createHelper(e);this._cacheHelperProportions();this._cacheMargins();this.scrollParent=this.helper.scrollParent();this.offset=this.currentItem.offset();this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};t.extend(this.offset,{click:{left:e.pageX-this.offset.left,top:e.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()});this.helper.css("position","absolute");this.cssPosition=this.helper.css("position");this.originalPosition=this._generatePosition(e);this.originalPageX=e.pageX;this.originalPageY=e.pageY;(o.cursorAt&&this._adjustOffsetFromHelper(o.cursorAt));this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]};if(this.helper[0]!==this.currentItem[0]){this.currentItem.hide()};this._createPlaceholder();if(o.containment){this._setContainment()};if(o.cursor&&o.cursor!=="auto"){r=this.document.find("body");this.storedCursor=r.css("cursor");r.css("cursor",o.cursor);this.storedStylesheet=t("<style>*{ cursor: "+o.cursor+" !important; }</style>").appendTo(r)};if(o.opacity){if(this.helper.css("opacity")){this._storedOpacity=this.helper.css("opacity")};this.helper.css("opacity",o.opacity)};if(o.zIndex){if(this.helper.css("zIndex")){this._storedZIndex=this.helper.css("zIndex")};this.helper.css("zIndex",o.zIndex)};if(this.scrollParent[0]!==this.document[0]&&this.scrollParent[0].tagName!=="HTML"){this.overflowOffset=this.scrollParent.offset()};this._trigger("start",e,this._uiHash());if(!this._preserveHelperProportions){this._cacheHelperProportions()};if(!s){for(n=this.containers.length-1;n>=0;n--){this.containers[n]._trigger("activate",e,this._uiHash(this))}};if(t.ui.ddmanager){t.ui.ddmanager.current=this};if(t.ui.ddmanager&&!o.dropBehaviour){t.ui.ddmanager.prepareOffsets(this,e)};this.dragging=!0;this._addClass(this.helper,"ui-sortable-helper");this._mouseDrag(e);return!0},_mouseDrag:function(e){var r,o,n,a,i=this.options,s=!1;this.position=this._generatePosition(e);this.positionAbs=this._convertPositionTo("absolute");if(!this.lastPositionAbs){this.lastPositionAbs=this.positionAbs};if(this.options.scroll){if(this.scrollParent[0]!==this.document[0]&&this.scrollParent[0].tagName!=="HTML"){if((this.overflowOffset.top+this.scrollParent[0].offsetHeight)-e.pageY<i.scrollSensitivity){this.scrollParent[0].scrollTop=s=this.scrollParent[0].scrollTop+i.scrollSpeed} else if(e.pageY-this.overflowOffset.top<i.scrollSensitivity){this.scrollParent[0].scrollTop=s=this.scrollParent[0].scrollTop-i.scrollSpeed};if((this.overflowOffset.left+this.scrollParent[0].offsetWidth)-e.pageX<i.scrollSensitivity){this.scrollParent[0].scrollLeft=s=this.scrollParent[0].scrollLeft+i.scrollSpeed} else if(e.pageX-this.overflowOffset.left<i.scrollSensitivity){this.scrollParent[0].scrollLeft=s=this.scrollParent[0].scrollLeft-i.scrollSpeed}} else{if(e.pageY-this.document.scrollTop()<i.scrollSensitivity){s=this.document.scrollTop(this.document.scrollTop()-i.scrollSpeed)} else if(this.window.height()-(e.pageY-this.document.scrollTop())<i.scrollSensitivity){s=this.document.scrollTop(this.document.scrollTop()+i.scrollSpeed)};if(e.pageX-this.document.scrollLeft()<i.scrollSensitivity){s=this.document.scrollLeft(this.document.scrollLeft()-i.scrollSpeed)} -else if(this.window.width()-(e.pageX-this.document.scrollLeft())<i.scrollSensitivity){s=this.document.scrollLeft(this.document.scrollLeft()+i.scrollSpeed)}};if(s!==!1&&t.ui.ddmanager&&!i.dropBehaviour){t.ui.ddmanager.prepareOffsets(this,e)}};this.positionAbs=this._convertPositionTo("absolute");if(!this.options.axis||this.options.axis!=="y"){this.helper[0].style.left=this.position.left+"px"};if(!this.options.axis||this.options.axis!=="x"){this.helper[0].style.top=this.position.top+"px"};for(r=this.items.length-1;r>=0;r--){n=this.items[r];o=n.item[0];h=this._intersectsWithPointer(n);if(!h){continue};if(n.instance!==this.currentContainer){continue};if(o!==this.currentItem[0]&&this.placeholder[h===1?"next":"prev"]()[0]!==o&&!t.contains(this.placeholder[0],o)&&(this.options.type==="semi-dynamic"?!t.contains(this.element[0],o):!0)){this.direction=h===1?"down":"up";if(this.options.tolerance==="pointer"||this._intersectsWithSides(n)){this._rearrange(e,n)} -else{break};this._trigger("change",e,this._uiHash());break}};this._contactContainers(e);if(t.ui.ddmanager){t.ui.ddmanager.drag(this,e)};this._trigger("sort",e,this._uiHash());this.lastPositionAbs=this.positionAbs;return!1},_mouseStop:function(e,i){if(!e){return};if(t.ui.ddmanager&&!this.options.dropBehaviour){t.ui.ddmanager.drop(this,e)};if(this.options.revert){var r=this,o=this.placeholder.offset(),s=this.options.axis,n={};if(!s||s==="x"){n.left=o.left-this.offset.parent.left-this.margins.left+(this.offsetParent[0]===this.document[0].body?0:this.offsetParent[0].scrollLeft)};if(!s||s==="y"){n.top=o.top-this.offset.parent.top-this.margins.top+(this.offsetParent[0]===this.document[0].body?0:this.offsetParent[0].scrollTop)};this.reverting=!0;t(this.helper).animate(n,parseInt(this.options.revert,10)||500,function(){r._clear(e)})} +else if(this.window.width()-(e.pageX-this.document.scrollLeft())<i.scrollSensitivity){s=this.document.scrollLeft(this.document.scrollLeft()+i.scrollSpeed)}};if(s!==!1&&t.ui.ddmanager&&!i.dropBehaviour){t.ui.ddmanager.prepareOffsets(this,e)}};this.positionAbs=this._convertPositionTo("absolute");if(!this.options.axis||this.options.axis!=="y"){this.helper[0].style.left=this.position.left+"px"};if(!this.options.axis||this.options.axis!=="x"){this.helper[0].style.top=this.position.top+"px"};for(r=this.items.length-1;r>=0;r--){o=this.items[r];n=o.item[0];a=this._intersectsWithPointer(o);if(!a){continue};if(o.instance!==this.currentContainer){continue};if(n!==this.currentItem[0]&&this.placeholder[a===1?"next":"prev"]()[0]!==n&&!t.contains(this.placeholder[0],n)&&(this.options.type==="semi-dynamic"?!t.contains(this.element[0],n):!0)){this.direction=a===1?"down":"up";if(this.options.tolerance==="pointer"||this._intersectsWithSides(o)){this._rearrange(e,o)} +else{break};this._trigger("change",e,this._uiHash());break}};this._contactContainers(e);if(t.ui.ddmanager){t.ui.ddmanager.drag(this,e)};this._trigger("sort",e,this._uiHash());this.lastPositionAbs=this.positionAbs;return!1},_mouseStop:function(e,i){if(!e){return};if(t.ui.ddmanager&&!this.options.dropBehaviour){t.ui.ddmanager.drop(this,e)};if(this.options.revert){var r=this,n=this.placeholder.offset(),s=this.options.axis,o={};if(!s||s==="x"){o.left=n.left-this.offset.parent.left-this.margins.left+(this.offsetParent[0]===this.document[0].body?0:this.offsetParent[0].scrollLeft)};if(!s||s==="y"){o.top=n.top-this.offset.parent.top-this.margins.top+(this.offsetParent[0]===this.document[0].body?0:this.offsetParent[0].scrollTop)};this.reverting=!0;t(this.helper).animate(o,parseInt(this.options.revert,10)||500,function(){r._clear(e)})} else{this._clear(e,i)};return!1},cancel:function(){if(this.dragging){this._mouseUp(new t.Event("mouseup",{target:null}));if(this.options.helper==="original"){this.currentItem.css(this._storedCSS);this._removeClass(this.currentItem,"ui-sortable-helper")} else{this.currentItem.show()};for(var e=this.containers.length-1;e>=0;e--){this.containers[e]._trigger("deactivate",null,this._uiHash(this));if(this.containers[e].containerCache.over){this.containers[e]._trigger("out",null,this._uiHash(this));this.containers[e].containerCache.over=0}}};if(this.placeholder){if(this.placeholder[0].parentNode){this.placeholder[0].parentNode.removeChild(this.placeholder[0])};if(this.options.helper!=="original"&&this.helper&&this.helper[0].parentNode){this.helper.remove()};t.extend(this,{helper:null,dragging:!1,reverting:!1,_noFinalSort:null});if(this.domPosition.prev){t(this.domPosition.prev).after(this.currentItem)} -else{t(this.domPosition.parent).prepend(this.currentItem)}};return this},serialize:function(e){var s=this._getItemsAsjQuery(e&&e.connected),i=[];e=e||{};t(s).each(function(){var s=(t(e.item||this).attr(e.attribute||"id")||"").match(e.expression||(/(.+)[\-=_](.+)/));if(s){i.push((e.key||s[1]+"[]")+"="+(e.key&&e.expression?s[1]:s[2]))}});if(!i.length&&e.key){i.push(e.key+"=")};return i.join("&")},toArray:function(e){var s=this._getItemsAsjQuery(e&&e.connected),i=[];e=e||{};s.each(function(){i.push(t(e.item||this).attr(e.attribute||"id")||"")});return i},_intersectsWith:function(t){var e=this.positionAbs.left,l=e+this.helperProportions.width,i=this.positionAbs.top,c=i+this.helperProportions.height,s=t.left,o=s+t.width,n=t.top,r=n+t.height,h=this.offset.click.top,a=this.offset.click.left,f=(this.options.axis==="x")||((i+h)>n&&(i+h)<r),u=(this.options.axis==="y")||((e+a)>s&&(e+a)<o),p=f&&u;if(this.options.tolerance==="pointer"||this.options.forcePointerForContainers||(this.options.tolerance!=="pointer"&&this.helperProportions[this.floating?"width":"height"]>t[this.floating?"width":"height"])){return p} -else{return(s<e+(this.helperProportions.width/2)&&l-(this.helperProportions.width/2)<o&&n<i+(this.helperProportions.height/2)&&c-(this.helperProportions.height/2)<r)}},_intersectsWithPointer:function(t){var e,i,s=(this.options.axis==="x")||this._isOverAxis(this.positionAbs.top+this.offset.click.top,t.top,t.height),n=(this.options.axis==="y")||this._isOverAxis(this.positionAbs.left+this.offset.click.left,t.left,t.width),o=s&&n;if(!o){return!1};e=this._getDragVerticalDirection();i=this._getDragHorizontalDirection();return this.floating?((i==="right"||e==="down")?2:1):(e&&(e==="down"?2:1))},_intersectsWithSides:function(t){var s=this._isOverAxis(this.positionAbs.top+this.offset.click.top,t.top+(t.height/2),t.height),n=this._isOverAxis(this.positionAbs.left+this.offset.click.left,t.left+(t.width/2),t.width),e=this._getDragVerticalDirection(),i=this._getDragHorizontalDirection();if(this.floating&&i){return((i==="right"&&n)||(i==="left"&&!n))} -else{return e&&((e==="down"&&s)||(e==="up"&&!s))}},_getDragVerticalDirection:function(){var t=this.positionAbs.top-this.lastPositionAbs.top;return t!==0&&(t>0?"down":"up")},_getDragHorizontalDirection:function(){var t=this.positionAbs.left-this.lastPositionAbs.left;return t!==0&&(t>0?"right":"left")},refresh:function(t){this._refreshItems(t);this._setHandleClassName();this.refreshPositions();return this},_connectWith:function(){var t=this.options;return t.connectWith.constructor===String?[t.connectWith]:t.connectWith},_getItemsAsjQuery:function(e){var s,n,r,i,a=[],o=[],h=this._connectWith();if(h&&e){for(s=h.length-1;s>=0;s--){r=t(h[s],this.document[0]);for(n=r.length-1;n>=0;n--){i=t.data(r[n],this.widgetFullName);if(i&&i!==this&&!i.options.disabled){o.push([t.isFunction(i.options.items)?i.options.items.call(i.element):t(i.options.items,i.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),i])}}}};o.push([t.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):t(this.options.items,this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),this]);function l(){a.push(this)};for(s=o.length-1;s>=0;s--){o[s][0].each(l)};return t(a)},_removeCurrentsFromItems:function(){var e=this.currentItem.find(":data("+this.widgetName+"-item)");this.items=t.grep(this.items,function(t){for(var i=0;i<e.length;i++){if(e[i]===t.item[0]){return!1}};return!0})},_refreshItems:function(e){this.items=[];this.containers=[this];var s,n,r,i,h,a,l,f,u=this.items,o=[[t.isFunction(this.options.items)?this.options.items.call(this.element[0],e,{item:this.currentItem}):t(this.options.items,this.element),this]],c=this._connectWith();if(c&&this.ready){for(s=c.length-1;s>=0;s--){r=t(c[s],this.document[0]);for(n=r.length-1;n>=0;n--){i=t.data(r[n],this.widgetFullName);if(i&&i!==this&&!i.options.disabled){o.push([t.isFunction(i.options.items)?i.options.items.call(i.element[0],e,{item:this.currentItem}):t(i.options.items,i.element),i]);this.containers.push(i)}}}};for(s=o.length-1;s>=0;s--){h=o[s][1];a=o[s][0];for(n=0,f=a.length;n<f;n++){l=t(a[n]);l.data(this.widgetName+"-item",h);u.push({item:l,instance:h,width:0,height:0,left:0,top:0})}}},refreshPositions:function(e){this.floating=this.items.length?this.options.axis==="x"||this._isFloating(this.items[0].item):!1;if(this.offsetParent&&this.helper){this.offset.parent=this._getParentOffset()};var i,s,o,n;for(i=this.items.length-1;i>=0;i--){s=this.items[i];if(s.instance!==this.currentContainer&&this.currentContainer&&s.item[0]!==this.currentItem[0]){continue};o=this.options.toleranceElement?t(this.options.toleranceElement,s.item):s.item;if(!e){s.width=o.outerWidth();s.height=o.outerHeight()};n=o.offset();s.left=n.left;s.top=n.top};if(this.options.custom&&this.options.custom.refreshContainers){this.options.custom.refreshContainers.call(this)} -else{for(i=this.containers.length-1;i>=0;i--){n=this.containers[i].element.offset();this.containers[i].containerCache.left=n.left;this.containers[i].containerCache.top=n.top;this.containers[i].containerCache.width=this.containers[i].element.outerWidth();this.containers[i].containerCache.height=this.containers[i].element.outerHeight()}};return this},_createPlaceholder:function(e){e=e||this;var s,i=e.options;if(!i.placeholder||i.placeholder.constructor===String){s=i.placeholder;i.placeholder={element:function(){var n=e.currentItem[0].nodeName.toLowerCase(),i=t("<"+n+">",e.document[0]);e._addClass(i,"ui-sortable-placeholder",s||e.currentItem[0].className)._removeClass(i,"ui-sortable-helper");if(n==="tbody"){e._createTrPlaceholder(e.currentItem.find("tr").eq(0),t("<tr>",e.document[0]).appendTo(i))} -else if(n==="tr"){e._createTrPlaceholder(e.currentItem,i)} -else if(n==="img"){i.attr("src",e.currentItem.attr("src"))};if(!s){i.css("visibility","hidden")};return i},update:function(t,n){if(s&&!i.forcePlaceholderSize){return};if(!n.height()){n.height(e.currentItem.innerHeight()-parseInt(e.currentItem.css("paddingTop")||0,10)-parseInt(e.currentItem.css("paddingBottom")||0,10))};if(!n.width()){n.width(e.currentItem.innerWidth()-parseInt(e.currentItem.css("paddingLeft")||0,10)-parseInt(e.currentItem.css("paddingRight")||0,10))}}}};e.placeholder=t(i.placeholder.element.call(e.element,e.currentItem));e.currentItem.after(e.placeholder);i.placeholder.update(e,e.placeholder)},_createTrPlaceholder:function(e,i){var s=this;e.children().each(function(){t("<td>&#160;</td>",s.document[0]).attr("colspan",t(this).attr("colspan")||1).appendTo(i)})},_contactContainers:function(e){var s,n,c,o,u,p,h,f,a,l,r=null,i=null;for(s=this.containers.length-1;s>=0;s--){if(t.contains(this.currentItem[0],this.containers[s].element[0])){continue};if(this._intersectsWith(this.containers[s].containerCache)){if(r&&t.contains(this.containers[s].element[0],r.element[0])){continue};r=this.containers[s];i=s} +else{t(this.domPosition.parent).prepend(this.currentItem)}};return this},serialize:function(e){var s=this._getItemsAsjQuery(e&&e.connected),i=[];e=e||{};t(s).each(function(){var s=(t(e.item||this).attr(e.attribute||"id")||"").match(e.expression||(/(.+)[\-=_](.+)/));if(s){i.push((e.key||s[1]+"[]")+"="+(e.key&&e.expression?s[1]:s[2]))}});if(!i.length&&e.key){i.push(e.key+"=")};return i.join("&")},toArray:function(e){var s=this._getItemsAsjQuery(e&&e.connected),i=[];e=e||{};s.each(function(){i.push(t(e.item||this).attr(e.attribute||"id")||"")});return i},_intersectsWith:function(t){var e=this.positionAbs.left,l=e+this.helperProportions.width,i=this.positionAbs.top,c=i+this.helperProportions.height,s=t.left,n=s+t.width,o=t.top,r=o+t.height,a=this.offset.click.top,h=this.offset.click.left,f=(this.options.axis==="x")||((i+a)>o&&(i+a)<r),p=(this.options.axis==="y")||((e+h)>s&&(e+h)<n),u=f&&p;if(this.options.tolerance==="pointer"||this.options.forcePointerForContainers||(this.options.tolerance!=="pointer"&&this.helperProportions[this.floating?"width":"height"]>t[this.floating?"width":"height"])){return u} +else{return(s<e+(this.helperProportions.width/2)&&l-(this.helperProportions.width/2)<n&&o<i+(this.helperProportions.height/2)&&c-(this.helperProportions.height/2)<r)}},_intersectsWithPointer:function(t){var e,i,s=(this.options.axis==="x")||this._isOverAxis(this.positionAbs.top+this.offset.click.top,t.top,t.height),o=(this.options.axis==="y")||this._isOverAxis(this.positionAbs.left+this.offset.click.left,t.left,t.width),n=s&&o;if(!n){return!1};e=this._getDragVerticalDirection();i=this._getDragHorizontalDirection();return this.floating?((i==="right"||e==="down")?2:1):(e&&(e==="down"?2:1))},_intersectsWithSides:function(t){var s=this._isOverAxis(this.positionAbs.top+this.offset.click.top,t.top+(t.height/2),t.height),o=this._isOverAxis(this.positionAbs.left+this.offset.click.left,t.left+(t.width/2),t.width),e=this._getDragVerticalDirection(),i=this._getDragHorizontalDirection();if(this.floating&&i){return((i==="right"&&o)||(i==="left"&&!o))} +else{return e&&((e==="down"&&s)||(e==="up"&&!s))}},_getDragVerticalDirection:function(){var t=this.positionAbs.top-this.lastPositionAbs.top;return t!==0&&(t>0?"down":"up")},_getDragHorizontalDirection:function(){var t=this.positionAbs.left-this.lastPositionAbs.left;return t!==0&&(t>0?"right":"left")},refresh:function(t){this._refreshItems(t);this._setHandleClassName();this.refreshPositions();return this},_connectWith:function(){var t=this.options;return t.connectWith.constructor===String?[t.connectWith]:t.connectWith},_getItemsAsjQuery:function(e){var s,o,r,i,h=[],n=[],a=this._connectWith();if(a&&e){for(s=a.length-1;s>=0;s--){r=t(a[s],this.document[0]);for(o=r.length-1;o>=0;o--){i=t.data(r[o],this.widgetFullName);if(i&&i!==this&&!i.options.disabled){n.push([t.isFunction(i.options.items)?i.options.items.call(i.element):t(i.options.items,i.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),i])}}}};n.push([t.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):t(this.options.items,this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),this]);function l(){h.push(this)};for(s=n.length-1;s>=0;s--){n[s][0].each(l)};return t(h)},_removeCurrentsFromItems:function(){var e=this.currentItem.find(":data("+this.widgetName+"-item)");this.items=t.grep(this.items,function(t){for(var i=0;i<e.length;i++){if(e[i]===t.item[0]){return!1}};return!0})},_refreshItems:function(e){this.items=[];this.containers=[this];var s,o,r,i,a,h,l,f,p=this.items,n=[[t.isFunction(this.options.items)?this.options.items.call(this.element[0],e,{item:this.currentItem}):t(this.options.items,this.element),this]],c=this._connectWith();if(c&&this.ready){for(s=c.length-1;s>=0;s--){r=t(c[s],this.document[0]);for(o=r.length-1;o>=0;o--){i=t.data(r[o],this.widgetFullName);if(i&&i!==this&&!i.options.disabled){n.push([t.isFunction(i.options.items)?i.options.items.call(i.element[0],e,{item:this.currentItem}):t(i.options.items,i.element),i]);this.containers.push(i)}}}};for(s=n.length-1;s>=0;s--){a=n[s][1];h=n[s][0];for(o=0,f=h.length;o<f;o++){l=t(h[o]);l.data(this.widgetName+"-item",a);p.push({item:l,instance:a,width:0,height:0,left:0,top:0})}}},refreshPositions:function(e){this.floating=this.items.length?this.options.axis==="x"||this._isFloating(this.items[0].item):!1;if(this.offsetParent&&this.helper){this.offset.parent=this._getParentOffset()};var i,s,n,o;for(i=this.items.length-1;i>=0;i--){s=this.items[i];if(s.instance!==this.currentContainer&&this.currentContainer&&s.item[0]!==this.currentItem[0]){continue};n=this.options.toleranceElement?t(this.options.toleranceElement,s.item):s.item;if(!e){s.width=n.outerWidth();s.height=n.outerHeight()};o=n.offset();s.left=o.left;s.top=o.top};if(this.options.custom&&this.options.custom.refreshContainers){this.options.custom.refreshContainers.call(this)} +else{for(i=this.containers.length-1;i>=0;i--){o=this.containers[i].element.offset();this.containers[i].containerCache.left=o.left;this.containers[i].containerCache.top=o.top;this.containers[i].containerCache.width=this.containers[i].element.outerWidth();this.containers[i].containerCache.height=this.containers[i].element.outerHeight()}};return this},_createPlaceholder:function(e){e=e||this;var s,i=e.options;if(!i.placeholder||i.placeholder.constructor===String){s=i.placeholder;i.placeholder={element:function(){var o=e.currentItem[0].nodeName.toLowerCase(),i=t("<"+o+">",e.document[0]);e._addClass(i,"ui-sortable-placeholder",s||e.currentItem[0].className)._removeClass(i,"ui-sortable-helper");if(o==="tbody"){e._createTrPlaceholder(e.currentItem.find("tr").eq(0),t("<tr>",e.document[0]).appendTo(i))} +else if(o==="tr"){e._createTrPlaceholder(e.currentItem,i)} +else if(o==="img"){i.attr("src",e.currentItem.attr("src"))};if(!s){i.css("visibility","hidden")};return i},update:function(t,o){if(s&&!i.forcePlaceholderSize){return};if(!o.height()){o.height(e.currentItem.innerHeight()-parseInt(e.currentItem.css("paddingTop")||0,10)-parseInt(e.currentItem.css("paddingBottom")||0,10))};if(!o.width()){o.width(e.currentItem.innerWidth()-parseInt(e.currentItem.css("paddingLeft")||0,10)-parseInt(e.currentItem.css("paddingRight")||0,10))}}}};e.placeholder=t(i.placeholder.element.call(e.element,e.currentItem));e.currentItem.after(e.placeholder);i.placeholder.update(e,e.placeholder)},_createTrPlaceholder:function(e,i){var s=this;e.children().each(function(){t("<td>&#160;</td>",s.document[0]).attr("colspan",t(this).attr("colspan")||1).appendTo(i)})},_contactContainers:function(e){var s,o,c,n,p,u,a,f,h,l,r=null,i=null;for(s=this.containers.length-1;s>=0;s--){if(t.contains(this.currentItem[0],this.containers[s].element[0])){continue};if(this._intersectsWith(this.containers[s].containerCache)){if(r&&t.contains(this.containers[s].element[0],r.element[0])){continue};r=this.containers[s];i=s} else{if(this.containers[s].containerCache.over){this.containers[s]._trigger("out",e,this._uiHash(this));this.containers[s].containerCache.over=0}}};if(!r){return};if(this.containers.length===1){if(!this.containers[i].containerCache.over){this.containers[i]._trigger("over",e,this._uiHash(this));this.containers[i].containerCache.over=1}} -else{c=10000;o=null;a=r.floating||this._isFloating(this.currentItem);u=a?"left":"top";p=a?"width":"height";l=a?"pageX":"pageY";for(n=this.items.length-1;n>=0;n--){if(!t.contains(this.containers[i].element[0],this.items[n].item[0])){continue};if(this.items[n].item[0]===this.currentItem[0]){continue};h=this.items[n].item.offset()[u];f=!1;if(e[l]-h>this.items[n][p]/2){f=!0};if(Math.abs(e[l]-h)<c){c=Math.abs(e[l]-h);o=this.items[n];this.direction=f?"up":"down"}};if(!o&&!this.options.dropOnEmpty){return};if(this.currentContainer===this.containers[i]){if(!this.currentContainer.containerCache.over){this.containers[i]._trigger("over",e,this._uiHash());this.currentContainer.containerCache.over=1};return};o?this._rearrange(e,o,null,!0):this._rearrange(e,null,this.containers[i].element,!0);this._trigger("change",e,this._uiHash());this.containers[i]._trigger("change",e,this._uiHash(this));this.currentContainer=this.containers[i];this.options.placeholder.update(this.currentContainer,this.placeholder);this.containers[i]._trigger("over",e,this._uiHash(this));this.containers[i].containerCache.over=1}},_createHelper:function(e){var s=this.options,i=t.isFunction(s.helper)?t(s.helper.apply(this.element[0],[e,this.currentItem])):(s.helper==="clone"?this.currentItem.clone():this.currentItem);if(!i.parents("body").length){t(s.appendTo!=="parent"?s.appendTo:this.currentItem[0].parentNode)[0].appendChild(i[0])};if(i[0]===this.currentItem[0]){this._storedCSS={width:this.currentItem[0].style.width,height:this.currentItem[0].style.height,position:this.currentItem.css("position"),top:this.currentItem.css("top"),left:this.currentItem.css("left")}};if(!i[0].style.width||s.forceHelperSize){i.width(this.currentItem.width())};if(!i[0].style.height||s.forceHelperSize){i.height(this.currentItem.height())};return i},_adjustOffsetFromHelper:function(e){if(typeof e==="string"){e=e.split(" ")};if(t.isArray(e)){e={left:+e[0],top:+e[1]||0}};if("left" in e){this.offset.click.left=e.left+this.margins.left};if("right" in e){this.offset.click.left=this.helperProportions.width-e.right+this.margins.left};if("top" in e){this.offset.click.top=e.top+this.margins.top};if("bottom" in e){this.offset.click.top=this.helperProportions.height-e.bottom+this.margins.top}},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var e=this.offsetParent.offset();if(this.cssPosition==="absolute"&&this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0])){e.left+=this.scrollParent.scrollLeft();e.top+=this.scrollParent.scrollTop()};if(this.offsetParent[0]===this.document[0].body||(this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()==="html"&&t.ui.ie)){e={top:0,left:0}};return{top:e.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:e.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition==="relative"){var t=this.currentItem.position();return{top:t.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:t.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}} -else{return{top:0,left:0}}},_cacheMargins:function(){this.margins={left:(parseInt(this.currentItem.css("marginLeft"),10)||0),top:(parseInt(this.currentItem.css("marginTop"),10)||0)}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var e,s,n,i=this.options;if(i.containment==="parent"){i.containment=this.helper[0].parentNode};if(i.containment==="document"||i.containment==="window"){this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,i.containment==="document"?this.document.width():this.window.width()-this.helperProportions.width-this.margins.left,(i.containment==="document"?(this.document.height()||document.body.parentNode.scrollHeight):this.window.height()||this.document[0].body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top]};if(!(/^(document|window|parent)$/).test(i.containment)){e=t(i.containment)[0];s=t(i.containment).offset();n=(t(e).css("overflow")!=="hidden");this.containment=[s.left+(parseInt(t(e).css("borderLeftWidth"),10)||0)+(parseInt(t(e).css("paddingLeft"),10)||0)-this.margins.left,s.top+(parseInt(t(e).css("borderTopWidth"),10)||0)+(parseInt(t(e).css("paddingTop"),10)||0)-this.margins.top,s.left+(n?Math.max(e.scrollWidth,e.offsetWidth):e.offsetWidth)-(parseInt(t(e).css("borderLeftWidth"),10)||0)-(parseInt(t(e).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,s.top+(n?Math.max(e.scrollHeight,e.offsetHeight):e.offsetHeight)-(parseInt(t(e).css("borderTopWidth"),10)||0)-(parseInt(t(e).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top]}},_convertPositionTo:function(e,i){if(!i){i=this.position};var s=e==="absolute"?1:-1,n=this.cssPosition==="absolute"&&!(this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,o=(/(html|body)/i).test(n[0].tagName);return{top:(i.top+this.offset.relative.top*s+this.offset.parent.top*s-((this.cssPosition==="fixed"?-this.scrollParent.scrollTop():(o?0:n.scrollTop()))*s)),left:(i.left+this.offset.relative.left*s+this.offset.parent.left*s-((this.cssPosition==="fixed"?-this.scrollParent.scrollLeft():o?0:n.scrollLeft())*s))}},_generatePosition:function(e){var s,n,i=this.options,o=e.pageX,r=e.pageY,h=this.cssPosition==="absolute"&&!(this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,a=(/(html|body)/i).test(h[0].tagName);if(this.cssPosition==="relative"&&!(this.scrollParent[0]!==this.document[0]&&this.scrollParent[0]!==this.offsetParent[0])){this.offset.relative=this._getRelativeOffset()};if(this.originalPosition){if(this.containment){if(e.pageX-this.offset.click.left<this.containment[0]){o=this.containment[0]+this.offset.click.left};if(e.pageY-this.offset.click.top<this.containment[1]){r=this.containment[1]+this.offset.click.top};if(e.pageX-this.offset.click.left>this.containment[2]){o=this.containment[2]+this.offset.click.left};if(e.pageY-this.offset.click.top>this.containment[3]){r=this.containment[3]+this.offset.click.top}};if(i.grid){s=this.originalPageY+Math.round((r-this.originalPageY)/i.grid[1])*i.grid[1];r=this.containment?((s-this.offset.click.top>=this.containment[1]&&s-this.offset.click.top<=this.containment[3])?s:((s-this.offset.click.top>=this.containment[1])?s-i.grid[1]:s+i.grid[1])):s;n=this.originalPageX+Math.round((o-this.originalPageX)/i.grid[0])*i.grid[0];o=this.containment?((n-this.offset.click.left>=this.containment[0]&&n-this.offset.click.left<=this.containment[2])?n:((n-this.offset.click.left>=this.containment[0])?n-i.grid[0]:n+i.grid[0])):n}};return{top:(r-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+((this.cssPosition==="fixed"?-this.scrollParent.scrollTop():(a?0:h.scrollTop())))),left:(o-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+((this.cssPosition==="fixed"?-this.scrollParent.scrollLeft():a?0:h.scrollLeft())))}},_rearrange:function(t,e,i,s){i?i[0].appendChild(this.placeholder[0]):e.item[0].parentNode.insertBefore(this.placeholder[0],(this.direction==="down"?e.item[0]:e.item[0].nextSibling));this.counter=this.counter?++this.counter:1;var n=this.counter;this._delay(function(){if(n===this.counter){this.refreshPositions(!s)}})},_clear:function(t,e){this.reverting=!1;var i,s=[];if(!this._noFinalSort&&this.currentItem.parent().length){this.placeholder.before(this.currentItem)};this._noFinalSort=null;if(this.helper[0]===this.currentItem[0]){for(i in this._storedCSS){if(this._storedCSS[i]==="auto"||this._storedCSS[i]==="static"){this._storedCSS[i]=""}};this.currentItem.css(this._storedCSS);this._removeClass(this.currentItem,"ui-sortable-helper")} -else{this.currentItem.show()};if(this.fromOutside&&!e){s.push(function(t){this._trigger("receive",t,this._uiHash(this.fromOutside))})};if((this.fromOutside||this.domPosition.prev!==this.currentItem.prev().not(".ui-sortable-helper")[0]||this.domPosition.parent!==this.currentItem.parent()[0])&&!e){s.push(function(t){this._trigger("update",t,this._uiHash())})};if(this!==this.currentContainer){if(!e){s.push(function(t){this._trigger("remove",t,this._uiHash())});s.push((function(t){return function(e){t._trigger("receive",e,this._uiHash(this))}}).call(this,this.currentContainer));s.push((function(t){return function(e){t._trigger("update",e,this._uiHash(this))}}).call(this,this.currentContainer))}};function n(t,e,i){return function(s){i._trigger(t,s,e._uiHash(e))}};for(i=this.containers.length-1;i>=0;i--){if(!e){s.push(n("deactivate",this,this.containers[i]))};if(this.containers[i].containerCache.over){s.push(n("out",this,this.containers[i]));this.containers[i].containerCache.over=0}};if(this.storedCursor){this.document.find("body").css("cursor",this.storedCursor);this.storedStylesheet.remove()};if(this._storedOpacity){this.helper.css("opacity",this._storedOpacity)};if(this._storedZIndex){this.helper.css("zIndex",this._storedZIndex==="auto"?"":this._storedZIndex)};this.dragging=!1;if(!e){this._trigger("beforeStop",t,this._uiHash())};this.placeholder[0].parentNode.removeChild(this.placeholder[0]);if(!this.cancelHelperRemoval){if(this.helper[0]!==this.currentItem[0]){this.helper.remove()};this.helper=null};if(!e){for(i=0;i<s.length;i++){s[i].call(this,t)};this._trigger("stop",t,this._uiHash())};this.fromOutside=!1;return!this.cancelHelperRemoval},_trigger:function(){if(t.Widget.prototype._trigger.apply(this,arguments)===!1){this.cancel()}},_uiHash:function(e){var i=e||this;return{helper:i.helper,placeholder:i.placeholder||t([]),position:i.position,originalPosition:i.originalPosition,offset:i.positionAbs,item:i.currentItem,sender:e?e.element:null}}})})); +else{c=10000;n=null;h=r.floating||this._isFloating(this.currentItem);p=h?"left":"top";u=h?"width":"height";l=h?"pageX":"pageY";for(o=this.items.length-1;o>=0;o--){if(!t.contains(this.containers[i].element[0],this.items[o].item[0])){continue};if(this.items[o].item[0]===this.currentItem[0]){continue};a=this.items[o].item.offset()[p];f=!1;if(e[l]-a>this.items[o][u]/2){f=!0};if(Math.abs(e[l]-a)<c){c=Math.abs(e[l]-a);n=this.items[o];this.direction=f?"up":"down"}};if(!n&&!this.options.dropOnEmpty){return};if(this.currentContainer===this.containers[i]){if(!this.currentContainer.containerCache.over){this.containers[i]._trigger("over",e,this._uiHash());this.currentContainer.containerCache.over=1};return};n?this._rearrange(e,n,null,!0):this._rearrange(e,null,this.containers[i].element,!0);this._trigger("change",e,this._uiHash());this.containers[i]._trigger("change",e,this._uiHash(this));this.currentContainer=this.containers[i];this.options.placeholder.update(this.currentContainer,this.placeholder);this.containers[i]._trigger("over",e,this._uiHash(this));this.containers[i].containerCache.over=1}},_createHelper:function(e){var s=this.options,i=t.isFunction(s.helper)?t(s.helper.apply(this.element[0],[e,this.currentItem])):(s.helper==="clone"?this.currentItem.clone():this.currentItem);if(!i.parents("body").length){t(s.appendTo!=="parent"?s.appendTo:this.currentItem[0].parentNode)[0].appendChild(i[0])};if(i[0]===this.currentItem[0]){this._storedCSS={width:this.currentItem[0].style.width,height:this.currentItem[0].style.height,position:this.currentItem.css("position"),top:this.currentItem.css("top"),left:this.currentItem.css("left")}};if(!i[0].style.width||s.forceHelperSize){i.width(this.currentItem.width())};if(!i[0].style.height||s.forceHelperSize){i.height(this.currentItem.height())};return i},_adjustOffsetFromHelper:function(e){if(typeof e==="string"){e=e.split(" ")};if(t.isArray(e)){e={left:+e[0],top:+e[1]||0}};if("left" in e){this.offset.click.left=e.left+this.margins.left};if("right" in e){this.offset.click.left=this.helperProportions.width-e.right+this.margins.left};if("top" in e){this.offset.click.top=e.top+this.margins.top};if("bottom" in e){this.offset.click.top=this.helperProportions.height-e.bottom+this.margins.top}},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var e=this.offsetParent.offset();if(this.cssPosition==="absolute"&&this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0])){e.left+=this.scrollParent.scrollLeft();e.top+=this.scrollParent.scrollTop()};if(this.offsetParent[0]===this.document[0].body||(this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()==="html"&&t.ui.ie)){e={top:0,left:0}};return{top:e.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:e.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition==="relative"){var t=this.currentItem.position();return{top:t.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:t.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}} +else{return{top:0,left:0}}},_cacheMargins:function(){this.margins={left:(parseInt(this.currentItem.css("marginLeft"),10)||0),top:(parseInt(this.currentItem.css("marginTop"),10)||0)}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var e,s,o,i=this.options;if(i.containment==="parent"){i.containment=this.helper[0].parentNode};if(i.containment==="document"||i.containment==="window"){this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,i.containment==="document"?this.document.width():this.window.width()-this.helperProportions.width-this.margins.left,(i.containment==="document"?(this.document.height()||document.body.parentNode.scrollHeight):this.window.height()||this.document[0].body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top]};if(!(/^(document|window|parent)$/).test(i.containment)){e=t(i.containment)[0];s=t(i.containment).offset();o=(t(e).css("overflow")!=="hidden");this.containment=[s.left+(parseInt(t(e).css("borderLeftWidth"),10)||0)+(parseInt(t(e).css("paddingLeft"),10)||0)-this.margins.left,s.top+(parseInt(t(e).css("borderTopWidth"),10)||0)+(parseInt(t(e).css("paddingTop"),10)||0)-this.margins.top,s.left+(o?Math.max(e.scrollWidth,e.offsetWidth):e.offsetWidth)-(parseInt(t(e).css("borderLeftWidth"),10)||0)-(parseInt(t(e).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,s.top+(o?Math.max(e.scrollHeight,e.offsetHeight):e.offsetHeight)-(parseInt(t(e).css("borderTopWidth"),10)||0)-(parseInt(t(e).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top]}},_convertPositionTo:function(e,i){if(!i){i=this.position};var s=e==="absolute"?1:-1,o=this.cssPosition==="absolute"&&!(this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,n=(/(html|body)/i).test(o[0].tagName);return{top:(i.top+this.offset.relative.top*s+this.offset.parent.top*s-((this.cssPosition==="fixed"?-this.scrollParent.scrollTop():(n?0:o.scrollTop()))*s)),left:(i.left+this.offset.relative.left*s+this.offset.parent.left*s-((this.cssPosition==="fixed"?-this.scrollParent.scrollLeft():n?0:o.scrollLeft())*s))}},_generatePosition:function(e){var s,o,i=this.options,n=e.pageX,r=e.pageY,a=this.cssPosition==="absolute"&&!(this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,h=(/(html|body)/i).test(a[0].tagName);if(this.cssPosition==="relative"&&!(this.scrollParent[0]!==this.document[0]&&this.scrollParent[0]!==this.offsetParent[0])){this.offset.relative=this._getRelativeOffset()};if(this.originalPosition){if(this.containment){if(e.pageX-this.offset.click.left<this.containment[0]){n=this.containment[0]+this.offset.click.left};if(e.pageY-this.offset.click.top<this.containment[1]){r=this.containment[1]+this.offset.click.top};if(e.pageX-this.offset.click.left>this.containment[2]){n=this.containment[2]+this.offset.click.left};if(e.pageY-this.offset.click.top>this.containment[3]){r=this.containment[3]+this.offset.click.top}};if(i.grid){s=this.originalPageY+Math.round((r-this.originalPageY)/i.grid[1])*i.grid[1];r=this.containment?((s-this.offset.click.top>=this.containment[1]&&s-this.offset.click.top<=this.containment[3])?s:((s-this.offset.click.top>=this.containment[1])?s-i.grid[1]:s+i.grid[1])):s;o=this.originalPageX+Math.round((n-this.originalPageX)/i.grid[0])*i.grid[0];n=this.containment?((o-this.offset.click.left>=this.containment[0]&&o-this.offset.click.left<=this.containment[2])?o:((o-this.offset.click.left>=this.containment[0])?o-i.grid[0]:o+i.grid[0])):o}};return{top:(r-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+((this.cssPosition==="fixed"?-this.scrollParent.scrollTop():(h?0:a.scrollTop())))),left:(n-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+((this.cssPosition==="fixed"?-this.scrollParent.scrollLeft():h?0:a.scrollLeft())))}},_rearrange:function(t,e,i,s){i?i[0].appendChild(this.placeholder[0]):e.item[0].parentNode.insertBefore(this.placeholder[0],(this.direction==="down"?e.item[0]:e.item[0].nextSibling));this.counter=this.counter?++this.counter:1;var o=this.counter;this._delay(function(){if(o===this.counter){this.refreshPositions(!s)}})},_clear:function(t,e){this.reverting=!1;var i,s=[];if(!this._noFinalSort&&this.currentItem.parent().length){this.placeholder.before(this.currentItem)};this._noFinalSort=null;if(this.helper[0]===this.currentItem[0]){for(i in this._storedCSS){if(this._storedCSS[i]==="auto"||this._storedCSS[i]==="static"){this._storedCSS[i]=""}};this.currentItem.css(this._storedCSS);this._removeClass(this.currentItem,"ui-sortable-helper")} +else{this.currentItem.show()};if(this.fromOutside&&!e){s.push(function(t){this._trigger("receive",t,this._uiHash(this.fromOutside))})};if((this.fromOutside||this.domPosition.prev!==this.currentItem.prev().not(".ui-sortable-helper")[0]||this.domPosition.parent!==this.currentItem.parent()[0])&&!e){s.push(function(t){this._trigger("update",t,this._uiHash())})};if(this!==this.currentContainer){if(!e){s.push(function(t){this._trigger("remove",t,this._uiHash())});s.push((function(t){return function(e){t._trigger("receive",e,this._uiHash(this))}}).call(this,this.currentContainer));s.push((function(t){return function(e){t._trigger("update",e,this._uiHash(this))}}).call(this,this.currentContainer))}};function o(t,e,i){return function(s){i._trigger(t,s,e._uiHash(e))}};for(i=this.containers.length-1;i>=0;i--){if(!e){s.push(o("deactivate",this,this.containers[i]))};if(this.containers[i].containerCache.over){s.push(o("out",this,this.containers[i]));this.containers[i].containerCache.over=0}};if(this.storedCursor){this.document.find("body").css("cursor",this.storedCursor);this.storedStylesheet.remove()};if(this._storedOpacity){this.helper.css("opacity",this._storedOpacity)};if(this._storedZIndex){this.helper.css("zIndex",this._storedZIndex==="auto"?"":this._storedZIndex)};this.dragging=!1;if(!e){this._trigger("beforeStop",t,this._uiHash())};this.placeholder[0].parentNode.removeChild(this.placeholder[0]);if(!this.cancelHelperRemoval){if(this.helper[0]!==this.currentItem[0]){this.helper.remove()};this.helper=null};if(!e){for(i=0;i<s.length;i++){s[i].call(this,t)};this._trigger("stop",t,this._uiHash())};this.fromOutside=!1;return!this.cancelHelperRemoval},_trigger:function(){if(t.Widget.prototype._trigger.apply(this,arguments)===!1){this.cancel()}},_uiHash:function(e){var i=e||this;return{helper:i.helper,placeholder:i.placeholder||t([]),position:i.position,originalPosition:i.originalPosition,offset:i.positionAbs,item:i.currentItem,sender:e?e.element:null}}})})); /* ./modules/cms-ui/themes/default/script/plugin/jquery-plugin-orSearch.min.js */;jQuery.fn.orSearch=function(n){var a=$.extend({'dropdown':'unknown'},n);return $(this).keyup(function(){var n=$(this).val();if(n.length>3){$(a.dropdown).html('');$.ajax({'type':'GET',url:'./api/?action=search&subaction=quicksearch&output=json&search='+n,data:null,success:function(t,e,d){for(id in t.output.result){var n=t.output.result[id];$(a.dropdown).append('<div class="entry clickable" title="'+n.desc+'"><a href="javascript:void(0);" data-type="open" data-name="'+n.name+'" data-action="'+n.type+'" data-id="'+n.id+'"><img src="'+OR_THEMES_EXT_DIR+'default/images/icon_'+n.type+'.png" />'+n.name+'</a></div>')};$(a.dropdown).orLinkify()}});$(a.dropdown).fadeIn()} else{$(a.dropdown).fadeOut()}})}; /* ./modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.min.js */;jQuery.fn.orLinkify=function(){return $(this).click(function(){$(this).find('a').first().each(function(){var t=$(this).attr('data-type');if($(this).parent().hasClass('inactive'))return;if(t=='post'){submitLink(this,$(this).attr('data-data'))} @@ -263,309 +293,9671 @@ else{};$.getJSON(i,function(a){$(t).append('<ul class="tree"/>');var r=$(t).chil /* ./modules/cms-ui/themes/default/script/plugin/jquery-plugin-orAutoheight.min.js */;jQuery.fn.orAutoheight=function(){var t=function(t){var n=$(t).val().split('\n').length;$(t).attr('rows',n+3)};$(this).each(function(n){t(this)});return $(this).keypress(function(){t(this)})}; /* ./modules/cms-ui/themes/default/script/jquery-qrcode.min.js *//*! jquery-qrcode v0.14.0 - https://larsjung.de/jquery-qrcode/ */ !function(r){"use strict";function t(t,e,n,o){function a(r,t){return r-=o,t-=o,0>r||r>=c||0>t||t>=c?!1:f.isDark(r,t)}function i(r,t,e,n){var o=u.isDark,a=1/l;u.isDark=function(i,u){var f=u*a,c=i*a,l=f+a,g=c+a;return o(i,u)&&(r>l||f>e||t>g||c>n)}}var u={},f=r(n,e);f.addData(t),f.make(),o=o||0;var c=f.getModuleCount(),l=f.getModuleCount()+2*o;return u.text=t,u.level=e,u.version=n,u.moduleCount=l,u.isDark=a,u.addBlank=i,u}function e(r,e,n,o,a){n=Math.max(1,n||1),o=Math.min(40,o||40);for(var i=n;o>=i;i+=1)try{return t(r,e,i,a)}catch(u){}}function n(r,t,e){var n=e.size,o="bold "+e.mSize*n+"px "+e.fontname,a=w("<canvas/>")[0].getContext("2d");a.font=o;var i=a.measureText(e.label).width,u=e.mSize,f=i/n,c=(1-f)*e.mPosX,l=(1-u)*e.mPosY,g=c+f,s=l+u,v=.01;1===e.mode?r.addBlank(0,l-v,n,s+v):r.addBlank(c-v,l-v,g+v,s+v),t.fillStyle=e.fontcolor,t.font=o,t.fillText(e.label,c*n,l*n+.75*e.mSize*n)}function o(r,t,e){var n=e.size,o=e.image.naturalWidth||1,a=e.image.naturalHeight||1,i=e.mSize,u=i*o/a,f=(1-u)*e.mPosX,c=(1-i)*e.mPosY,l=f+u,g=c+i,s=.01;3===e.mode?r.addBlank(0,c-s,n,g+s):r.addBlank(f-s,c-s,l+s,g+s),t.drawImage(e.image,f*n,c*n,u*n,i*n)}function a(r,t,e){w(e.background).is("img")?t.drawImage(e.background,0,0,e.size,e.size):e.background&&(t.fillStyle=e.background,t.fillRect(e.left,e.top,e.size,e.size));var a=e.mode;1===a||2===a?n(r,t,e):(3===a||4===a)&&o(r,t,e)}function i(r,t,e,n,o,a,i,u){r.isDark(i,u)&&t.rect(n,o,a,a)}function u(r,t,e,n,o,a,i,u,f,c){i?r.moveTo(t+a,e):r.moveTo(t,e),u?(r.lineTo(n-a,e),r.arcTo(n,e,n,o,a)):r.lineTo(n,e),f?(r.lineTo(n,o-a),r.arcTo(n,o,t,o,a)):r.lineTo(n,o),c?(r.lineTo(t+a,o),r.arcTo(t,o,t,e,a)):r.lineTo(t,o),i?(r.lineTo(t,e+a),r.arcTo(t,e,n,e,a)):r.lineTo(t,e)}function f(r,t,e,n,o,a,i,u,f,c){i&&(r.moveTo(t+a,e),r.lineTo(t,e),r.lineTo(t,e+a),r.arcTo(t,e,t+a,e,a)),u&&(r.moveTo(n-a,e),r.lineTo(n,e),r.lineTo(n,e+a),r.arcTo(n,e,n-a,e,a)),f&&(r.moveTo(n-a,o),r.lineTo(n,o),r.lineTo(n,o-a),r.arcTo(n,o,n-a,o,a)),c&&(r.moveTo(t+a,o),r.lineTo(t,o),r.lineTo(t,o-a),r.arcTo(t,o,t+a,o,a))}function c(r,t,e,n,o,a,i,c){var l=r.isDark,g=n+a,s=o+a,v=e.radius*a,h=i-1,d=i+1,w=c-1,m=c+1,y=l(i,c),T=l(h,w),p=l(h,c),B=l(h,m),A=l(i,m),E=l(d,m),k=l(d,c),M=l(d,w),C=l(i,w);y?u(t,n,o,g,s,v,!p&&!C,!p&&!A,!k&&!A,!k&&!C):f(t,n,o,g,s,v,p&&C&&T,p&&A&&B,k&&A&&E,k&&C&&M)}function l(r,t,e){var n,o,a=r.moduleCount,u=e.size/a,f=i;for(e.radius>0&&e.radius<=.5&&(f=c),t.beginPath(),n=0;a>n;n+=1)for(o=0;a>o;o+=1){var l=e.left+o*u,g=e.top+n*u,s=u;f(r,t,e,l,g,s,n,o)}if(w(e.fill).is("img")){t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=2,t.stroke();var v=t.globalCompositeOperation;t.globalCompositeOperation="destination-out",t.fill(),t.globalCompositeOperation=v,t.clip(),t.drawImage(e.fill,0,0,e.size,e.size),t.restore()}else t.fillStyle=e.fill,t.fill()}function g(r,t){var n=e(t.text,t.ecLevel,t.minVersion,t.maxVersion,t.quiet);if(!n)return null;var o=w(r).data("qrcode",n),i=o[0].getContext("2d");return a(n,i,t),l(n,i,t),o}function s(r){var t=w("<canvas/>").attr("width",r.size).attr("height",r.size);return g(t,r)}function v(r){return w("<img/>").attr("src",s(r)[0].toDataURL("image/png"))}function h(r){var t=e(r.text,r.ecLevel,r.minVersion,r.maxVersion,r.quiet);if(!t)return null;var n,o,a=r.size,i=r.background,u=Math.floor,f=t.moduleCount,c=u(a/f),l=u(.5*(a-c*f)),g={position:"relative",left:0,top:0,padding:0,margin:0,width:a,height:a},s={position:"absolute",padding:0,margin:0,width:c,height:c,"background-color":r.fill},v=w("<div/>").data("qrcode",t).css(g);for(i&&v.css("background-color",i),n=0;f>n;n+=1)for(o=0;f>o;o+=1)t.isDark(n,o)&&w("<div/>").css(s).css({left:l+o*c,top:l+n*c}).appendTo(v);return v}function d(r){return m&&"canvas"===r.render?s(r):m&&"image"===r.render?v(r):h(r)}var w=window.jQuery,m=function(){var r=document.createElement("canvas");return!(!r.getContext||!r.getContext("2d"))}(),y={render:"canvas",minVersion:1,maxVersion:40,ecLevel:"L",left:0,top:0,size:200,fill:"#000",background:null,text:"no text",radius:0,quiet:0,mode:0,mSize:.1,mPosX:.5,mPosY:.5,label:"no label",fontname:"sans",fontcolor:"#000",image:null};w.fn.qrcode=function(r){var t=w.extend({},y,r);return this.each(function(r,e){"canvas"===e.nodeName.toLowerCase()?g(e,t):w(e).append(d(t))})}}(function(){var r=function(){function r(t,e){if("undefined"==typeof t.length)throw new Error(t.length+"/"+e);var n=function(){for(var r=0;r<t.length&&0==t[r];)r+=1;for(var n=new Array(t.length-r+e),o=0;o<t.length-r;o+=1)n[o]=t[o+r];return n}(),o={};return o.getAt=function(r){return n[r]},o.getLength=function(){return n.length},o.multiply=function(t){for(var e=new Array(o.getLength()+t.getLength()-1),n=0;n<o.getLength();n+=1)for(var a=0;a<t.getLength();a+=1)e[n+a]^=i.gexp(i.glog(o.getAt(n))+i.glog(t.getAt(a)));return r(e,0)},o.mod=function(t){if(o.getLength()-t.getLength()<0)return o;for(var e=i.glog(o.getAt(0))-i.glog(t.getAt(0)),n=new Array(o.getLength()),a=0;a<o.getLength();a+=1)n[a]=o.getAt(a);for(var a=0;a<t.getLength();a+=1)n[a]^=i.gexp(i.glog(t.getAt(a))+e);return r(n,0).mod(t)},o}var t=function(t,e){var o=236,i=17,l=t,g=n[e],s=null,v=0,d=null,w=new Array,m={},y=function(r,t){v=4*l+17,s=function(r){for(var t=new Array(r),e=0;r>e;e+=1){t[e]=new Array(r);for(var n=0;r>n;n+=1)t[e][n]=null}return t}(v),T(0,0),T(v-7,0),T(0,v-7),A(),B(),k(r,t),l>=7&&E(r),null==d&&(d=D(l,g,w)),M(d,t)},T=function(r,t){for(var e=-1;7>=e;e+=1)if(!(-1>=r+e||r+e>=v))for(var n=-1;7>=n;n+=1)-1>=t+n||t+n>=v||(e>=0&&6>=e&&(0==n||6==n)||n>=0&&6>=n&&(0==e||6==e)||e>=2&&4>=e&&n>=2&&4>=n?s[r+e][t+n]=!0:s[r+e][t+n]=!1)},p=function(){for(var r=0,t=0,e=0;8>e;e+=1){y(!0,e);var n=a.getLostPoint(m);(0==e||r>n)&&(r=n,t=e)}return t},B=function(){for(var r=8;v-8>r;r+=1)null==s[r][6]&&(s[r][6]=r%2==0);for(var t=8;v-8>t;t+=1)null==s[6][t]&&(s[6][t]=t%2==0)},A=function(){for(var r=a.getPatternPosition(l),t=0;t<r.length;t+=1)for(var e=0;e<r.length;e+=1){var n=r[t],o=r[e];if(null==s[n][o])for(var i=-2;2>=i;i+=1)for(var u=-2;2>=u;u+=1)-2==i||2==i||-2==u||2==u||0==i&&0==u?s[n+i][o+u]=!0:s[n+i][o+u]=!1}},E=function(r){for(var t=a.getBCHTypeNumber(l),e=0;18>e;e+=1){var n=!r&&1==(t>>e&1);s[Math.floor(e/3)][e%3+v-8-3]=n}for(var e=0;18>e;e+=1){var n=!r&&1==(t>>e&1);s[e%3+v-8-3][Math.floor(e/3)]=n}},k=function(r,t){for(var e=g<<3|t,n=a.getBCHTypeInfo(e),o=0;15>o;o+=1){var i=!r&&1==(n>>o&1);6>o?s[o][8]=i:8>o?s[o+1][8]=i:s[v-15+o][8]=i}for(var o=0;15>o;o+=1){var i=!r&&1==(n>>o&1);8>o?s[8][v-o-1]=i:9>o?s[8][15-o-1+1]=i:s[8][15-o-1]=i}s[v-8][8]=!r},M=function(r,t){for(var e=-1,n=v-1,o=7,i=0,u=a.getMaskFunction(t),f=v-1;f>0;f-=2)for(6==f&&(f-=1);;){for(var c=0;2>c;c+=1)if(null==s[n][f-c]){var l=!1;i<r.length&&(l=1==(r[i]>>>o&1));var g=u(n,f-c);g&&(l=!l),s[n][f-c]=l,o-=1,-1==o&&(i+=1,o=7)}if(n+=e,0>n||n>=v){n-=e,e=-e;break}}},C=function(t,e){for(var n=0,o=0,i=0,u=new Array(e.length),f=new Array(e.length),c=0;c<e.length;c+=1){var l=e[c].dataCount,g=e[c].totalCount-l;o=Math.max(o,l),i=Math.max(i,g),u[c]=new Array(l);for(var s=0;s<u[c].length;s+=1)u[c][s]=255&t.getBuffer()[s+n];n+=l;var v=a.getErrorCorrectPolynomial(g),h=r(u[c],v.getLength()-1),d=h.mod(v);f[c]=new Array(v.getLength()-1);for(var s=0;s<f[c].length;s+=1){var w=s+d.getLength()-f[c].length;f[c][s]=w>=0?d.getAt(w):0}}for(var m=0,s=0;s<e.length;s+=1)m+=e[s].totalCount;for(var y=new Array(m),T=0,s=0;o>s;s+=1)for(var c=0;c<e.length;c+=1)s<u[c].length&&(y[T]=u[c][s],T+=1);for(var s=0;i>s;s+=1)for(var c=0;c<e.length;c+=1)s<f[c].length&&(y[T]=f[c][s],T+=1);return y},D=function(r,t,e){for(var n=u.getRSBlocks(r,t),c=f(),l=0;l<e.length;l+=1){var g=e[l];c.put(g.getMode(),4),c.put(g.getLength(),a.getLengthInBits(g.getMode(),r)),g.write(c)}for(var s=0,l=0;l<n.length;l+=1)s+=n[l].dataCount;if(c.getLengthInBits()>8*s)throw new Error("code length overflow. ("+c.getLengthInBits()+">"+8*s+")");for(c.getLengthInBits()+4<=8*s&&c.put(0,4);c.getLengthInBits()%8!=0;)c.putBit(!1);for(;;){if(c.getLengthInBits()>=8*s)break;if(c.put(o,8),c.getLengthInBits()>=8*s)break;c.put(i,8)}return C(c,n)};return m.addData=function(r){var t=c(r);w.push(t),d=null},m.isDark=function(r,t){if(0>r||r>=v||0>t||t>=v)throw new Error(r+","+t);return s[r][t]},m.getModuleCount=function(){return v},m.make=function(){y(!1,p())},m.createTableTag=function(r,t){r=r||2,t="undefined"==typeof t?4*r:t;var e="";e+='<table style="',e+=" border-width: 0px; border-style: none;",e+=" border-collapse: collapse;",e+=" padding: 0px; margin: "+t+"px;",e+='">',e+="<tbody>";for(var n=0;n<m.getModuleCount();n+=1){e+="<tr>";for(var o=0;o<m.getModuleCount();o+=1)e+='<td style="',e+=" border-width: 0px; border-style: none;",e+=" border-collapse: collapse;",e+=" padding: 0px; margin: 0px;",e+=" width: "+r+"px;",e+=" height: "+r+"px;",e+=" background-color: ",e+=m.isDark(n,o)?"#000000":"#ffffff",e+=";",e+='"/>';e+="</tr>"}return e+="</tbody>",e+="</table>"},m.createImgTag=function(r,t){r=r||2,t="undefined"==typeof t?4*r:t;var e=m.getModuleCount()*r+2*t,n=t,o=e-t;return h(e,e,function(t,e){if(t>=n&&o>t&&e>=n&&o>e){var a=Math.floor((t-n)/r),i=Math.floor((e-n)/r);return m.isDark(i,a)?0:1}return 1})},m};t.stringToBytes=function(r){for(var t=new Array,e=0;e<r.length;e+=1){var n=r.charCodeAt(e);t.push(255&n)}return t},t.createStringToBytes=function(r,t){var e=function(){for(var e=s(r),n=function(){var r=e.read();if(-1==r)throw new Error;return r},o=0,a={};;){var i=e.read();if(-1==i)break;var u=n(),f=n(),c=n(),l=String.fromCharCode(i<<8|u),g=f<<8|c;a[l]=g,o+=1}if(o!=t)throw new Error(o+" != "+t);return a}(),n="?".charCodeAt(0);return function(r){for(var t=new Array,o=0;o<r.length;o+=1){var a=r.charCodeAt(o);if(128>a)t.push(a);else{var i=e[r.charAt(o)];"number"==typeof i?(255&i)==i?t.push(i):(t.push(i>>>8),t.push(255&i)):t.push(n)}}return t}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},n={L:1,M:0,Q:3,H:2},o={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},a=function(){var t=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],n=1335,a=7973,u=21522,f={},c=function(r){for(var t=0;0!=r;)t+=1,r>>>=1;return t};return f.getBCHTypeInfo=function(r){for(var t=r<<10;c(t)-c(n)>=0;)t^=n<<c(t)-c(n);return(r<<10|t)^u},f.getBCHTypeNumber=function(r){for(var t=r<<12;c(t)-c(a)>=0;)t^=a<<c(t)-c(a);return r<<12|t},f.getPatternPosition=function(r){return t[r-1]},f.getMaskFunction=function(r){switch(r){case o.PATTERN000:return function(r,t){return(r+t)%2==0};case o.PATTERN001:return function(r,t){return r%2==0};case o.PATTERN010:return function(r,t){return t%3==0};case o.PATTERN011:return function(r,t){return(r+t)%3==0};case o.PATTERN100:return function(r,t){return(Math.floor(r/2)+Math.floor(t/3))%2==0};case o.PATTERN101:return function(r,t){return r*t%2+r*t%3==0};case o.PATTERN110:return function(r,t){return(r*t%2+r*t%3)%2==0};case o.PATTERN111:return function(r,t){return(r*t%3+(r+t)%2)%2==0};default:throw new Error("bad maskPattern:"+r)}},f.getErrorCorrectPolynomial=function(t){for(var e=r([1],0),n=0;t>n;n+=1)e=e.multiply(r([1,i.gexp(n)],0));return e},f.getLengthInBits=function(r,t){if(t>=1&&10>t)switch(r){case e.MODE_NUMBER:return 10;case e.MODE_ALPHA_NUM:return 9;case e.MODE_8BIT_BYTE:return 8;case e.MODE_KANJI:return 8;default:throw new Error("mode:"+r)}else if(27>t)switch(r){case e.MODE_NUMBER:return 12;case e.MODE_ALPHA_NUM:return 11;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 10;default:throw new Error("mode:"+r)}else{if(!(41>t))throw new Error("type:"+t);switch(r){case e.MODE_NUMBER:return 14;case e.MODE_ALPHA_NUM:return 13;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 12;default:throw new Error("mode:"+r)}}},f.getLostPoint=function(r){for(var t=r.getModuleCount(),e=0,n=0;t>n;n+=1)for(var o=0;t>o;o+=1){for(var a=0,i=r.isDark(n,o),u=-1;1>=u;u+=1)if(!(0>n+u||n+u>=t))for(var f=-1;1>=f;f+=1)0>o+f||o+f>=t||(0!=u||0!=f)&&i==r.isDark(n+u,o+f)&&(a+=1);a>5&&(e+=3+a-5)}for(var n=0;t-1>n;n+=1)for(var o=0;t-1>o;o+=1){var c=0;r.isDark(n,o)&&(c+=1),r.isDark(n+1,o)&&(c+=1),r.isDark(n,o+1)&&(c+=1),r.isDark(n+1,o+1)&&(c+=1),(0==c||4==c)&&(e+=3)}for(var n=0;t>n;n+=1)for(var o=0;t-6>o;o+=1)r.isDark(n,o)&&!r.isDark(n,o+1)&&r.isDark(n,o+2)&&r.isDark(n,o+3)&&r.isDark(n,o+4)&&!r.isDark(n,o+5)&&r.isDark(n,o+6)&&(e+=40);for(var o=0;t>o;o+=1)for(var n=0;t-6>n;n+=1)r.isDark(n,o)&&!r.isDark(n+1,o)&&r.isDark(n+2,o)&&r.isDark(n+3,o)&&r.isDark(n+4,o)&&!r.isDark(n+5,o)&&r.isDark(n+6,o)&&(e+=40);for(var l=0,o=0;t>o;o+=1)for(var n=0;t>n;n+=1)r.isDark(n,o)&&(l+=1);var g=Math.abs(100*l/t/t-50)/5;return e+=10*g},f}(),i=function(){for(var r=new Array(256),t=new Array(256),e=0;8>e;e+=1)r[e]=1<<e;for(var e=8;256>e;e+=1)r[e]=r[e-4]^r[e-5]^r[e-6]^r[e-8];for(var e=0;255>e;e+=1)t[r[e]]=e;var n={};return n.glog=function(r){if(1>r)throw new Error("glog("+r+")");return t[r]},n.gexp=function(t){for(;0>t;)t+=255;for(;t>=256;)t-=255;return r[t]},n}(),u=function(){var r=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],t=function(r,t){var e={};return e.totalCount=r,e.dataCount=t,e},e={},o=function(t,e){switch(e){case n.L:return r[4*(t-1)+0];case n.M:return r[4*(t-1)+1];case n.Q:return r[4*(t-1)+2];case n.H:return r[4*(t-1)+3];default:return}};return e.getRSBlocks=function(r,e){var n=o(r,e);if("undefined"==typeof n)throw new Error("bad rs block @ typeNumber:"+r+"/errorCorrectLevel:"+e);for(var a=n.length/3,i=new Array,u=0;a>u;u+=1)for(var f=n[3*u+0],c=n[3*u+1],l=n[3*u+2],g=0;f>g;g+=1)i.push(t(c,l));return i},e}(),f=function(){var r=new Array,t=0,e={};return e.getBuffer=function(){return r},e.getAt=function(t){var e=Math.floor(t/8);return 1==(r[e]>>>7-t%8&1)},e.put=function(r,t){for(var n=0;t>n;n+=1)e.putBit(1==(r>>>t-n-1&1))},e.getLengthInBits=function(){return t},e.putBit=function(e){var n=Math.floor(t/8);r.length<=n&&r.push(0),e&&(r[n]|=128>>>t%8),t+=1},e},c=function(r){var n=e.MODE_8BIT_BYTE,o=t.stringToBytes(r),a={};return a.getMode=function(){return n},a.getLength=function(r){return o.length},a.write=function(r){for(var t=0;t<o.length;t+=1)r.put(o[t],8)},a},l=function(){var r=new Array,t={};return t.writeByte=function(t){r.push(255&t)},t.writeShort=function(r){t.writeByte(r),t.writeByte(r>>>8)},t.writeBytes=function(r,e,n){e=e||0,n=n||r.length;for(var o=0;n>o;o+=1)t.writeByte(r[o+e])},t.writeString=function(r){for(var e=0;e<r.length;e+=1)t.writeByte(r.charCodeAt(e))},t.toByteArray=function(){return r},t.toString=function(){var t="";t+="[";for(var e=0;e<r.length;e+=1)e>0&&(t+=","),t+=r[e];return t+="]"},t},g=function(){var r=0,t=0,e=0,n="",o={},a=function(r){n+=String.fromCharCode(i(63&r))},i=function(r){if(0>r);else{if(26>r)return 65+r;if(52>r)return 97+(r-26);if(62>r)return 48+(r-52);if(62==r)return 43;if(63==r)return 47}throw new Error("n:"+r)};return o.writeByte=function(n){for(r=r<<8|255&n,t+=8,e+=1;t>=6;)a(r>>>t-6),t-=6},o.flush=function(){if(t>0&&(a(r<<6-t),r=0,t=0),e%3!=0)for(var o=3-e%3,i=0;o>i;i+=1)n+="="},o.toString=function(){return n},o},s=function(r){var t=r,e=0,n=0,o=0,a={};a.read=function(){for(;8>o;){if(e>=t.length){if(0==o)return-1;throw new Error("unexpected end of file./"+o)}var r=t.charAt(e);if(e+=1,"="==r)return o=0,-1;r.match(/^\s$/)||(n=n<<6|i(r.charCodeAt(0)),o+=6)}var a=n>>>o-8&255;return o-=8,a};var i=function(r){if(r>=65&&90>=r)return r-65;if(r>=97&&122>=r)return r-97+26;if(r>=48&&57>=r)return r-48+52;if(43==r)return 62;if(47==r)return 63;throw new Error("c:"+r)};return a},v=function(r,t){var e=r,n=t,o=new Array(r*t),a={};a.setPixel=function(r,t,n){o[t*e+r]=n},a.write=function(r){r.writeString("GIF87a"),r.writeShort(e),r.writeShort(n),r.writeByte(128),r.writeByte(0),r.writeByte(0),r.writeByte(0),r.writeByte(0),r.writeByte(0),r.writeByte(255),r.writeByte(255),r.writeByte(255),r.writeString(","),r.writeShort(0),r.writeShort(0),r.writeShort(e),r.writeShort(n),r.writeByte(0);var t=2,o=u(t);r.writeByte(t);for(var a=0;o.length-a>255;)r.writeByte(255),r.writeBytes(o,a,255),a+=255;r.writeByte(o.length-a),r.writeBytes(o,a,o.length-a),r.writeByte(0),r.writeString(";")};var i=function(r){var t=r,e=0,n=0,o={};return o.write=function(r,o){if(r>>>o!=0)throw new Error("length over");for(;e+o>=8;)t.writeByte(255&(r<<e|n)),o-=8-e,r>>>=8-e,n=0,e=0;n=r<<e|n,e+=o},o.flush=function(){e>0&&t.writeByte(n)},o},u=function(r){for(var t=1<<r,e=(1<<r)+1,n=r+1,a=f(),u=0;t>u;u+=1)a.add(String.fromCharCode(u));a.add(String.fromCharCode(t)),a.add(String.fromCharCode(e));var c=l(),g=i(c);g.write(t,n);var s=0,v=String.fromCharCode(o[s]);for(s+=1;s<o.length;){var h=String.fromCharCode(o[s]);s+=1,a.contains(v+h)?v+=h:(g.write(a.indexOf(v),n),a.size()<4095&&(a.size()==1<<n&&(n+=1),a.add(v+h)),v=h)}return g.write(a.indexOf(v),n),g.write(e,n),g.flush(),c.toByteArray()},f=function(){var r={},t=0,e={};return e.add=function(n){if(e.contains(n))throw new Error("dup key:"+n);r[n]=t,t+=1},e.size=function(){return t},e.indexOf=function(t){return r[t]},e.contains=function(t){return"undefined"!=typeof r[t]},e};return a},h=function(r,t,e,n){for(var o=v(r,t),a=0;t>a;a+=1)for(var i=0;r>i;i+=1)o.setPixel(i,a,e(i,a));var u=l();o.write(u);for(var f=g(),c=u.toByteArray(),s=0;s<c.length;s+=1)f.writeByte(c[s]);f.flush();var h="";return h+="<img",h+=' src="',h+="data:image/gif;base64,",h+=f,h+='"',h+=' width="',h+=r,h+='"',h+=' height="',h+=t,h+='"',n&&(h+=' alt="',h+=n,h+='"'),h+="/>"};return t}();return function(r){"function"==typeof define&&define.amd?define([],r):"object"==typeof exports&&(module.exports=r())}(function(){return r}),!function(r){r.stringToBytes=function(r){function t(r){for(var t=[],e=0;e<r.length;e++){var n=r.charCodeAt(e);128>n?t.push(n):2048>n?t.push(192|n>>6,128|63&n):55296>n||n>=57344?t.push(224|n>>12,128|n>>6&63,128|63&n):(e++,n=65536+((1023&n)<<10|1023&r.charCodeAt(e)),t.push(240|n>>18,128|n>>12&63,128|n>>6&63,128|63&n))}return t}return t(r)}}(r),r}()); -/* ./modules/cms-ui/themes/default/script/svg-injector.min.js */ -/* ./modules/editor/codemirror/lib/codemirror.min.js */(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?module.exports=t():typeof define==="function"&&define.amd?define(t):(e.CodeMirror=t())}(this,(function(){"use strict";var S=navigator.userAgent,Kr=navigator.platform,ie=/gecko\/\d/i.test(S),Xr=/MSIE \d/.test(S),jr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(S),st=/Edge\/(\d+)/.exec(S),l=Xr||jr||st,c=l&&(Xr?document.documentMode||6:+(st||jr)[1]),x=!st&&/WebKit\//.test(S),yl=x&&/Qt\/\d+\.\d+/.test(S),Kt=!st&&/Chrome\//.test(S),E=/Opera\//.test(S),Yr=/Apple Computer/.test(navigator.vendor),bl=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(S),wl=/PhantomJS/.test(S),at=!st&&/AppleWebKit/.test(S)&&/Mobile\/\w+/.test(S),Xt=/Android/.test(S),ut=at||Xt||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(S),I=at||/Mac/.test(Kr),xl=/\bCrOS\b/.test(S),Cl=/win/i.test(Kr),pe=E&&S.match(/Version\/(\d*\.\d*)/);if(pe){pe=Number(pe[1])};if(pe&&pe>=15){E=!1;x=!0};var Vr=I&&(yl||E&&(pe==null||pe<12.11)),Ni=ie||(l&&c>=9);function ft(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")};var de=function(e,t){var r=e.className,i=ft(t).exec(r);if(i){var n=r.slice(i.index+i[0].length);e.className=r.slice(0,i.index)+(n?i[1]+n:"")}};function re(e){for(var t=e.childNodes.length;t>0;--t){e.removeChild(e.firstChild)};return e};function W(e,t){return re(e).appendChild(t)};function i(e,t,i,r){var n=document.createElement(e);if(i){n.className=i};if(r){n.style.cssText=r};if(typeof t=="string"){n.appendChild(document.createTextNode(t))} -else if(t){for(var o=0;o<t.length;++o){n.appendChild(t[o])}};return n};function Fe(e,t,r,n){var o=i(e,t,r,n);o.setAttribute("role","presentation");return o};var he;if(document.createRange){he=function(e,t,i,r){var n=document.createRange();n.setEnd(r||e,i);n.setStart(e,t);return n}} -else{he=function(e,t,i){var n=document.body.createTextRange();try{n.moveToElementText(e.parentNode)}catch(r){return n};n.collapse(!0);n.moveEnd("character",i);n.moveStart("character",t);return n}};function ne(e,t){if(t.nodeType==3){t=t.parentNode};if(e.contains){return e.contains(t)};do{if(t.nodeType==11){t=t.host};if(t==e){return!0}} -while(t=t.parentNode)};function Y(){var t;try{t=document.activeElement}catch(e){t=document.body||null} -while(t&&t.shadowRoot&&t.shadowRoot.activeElement){t=t.shadowRoot.activeElement};return t};function ge(e,t){var i=e.className;if(!ft(t).test(i)){e.className+=(i?" ":"")+t}};function Oi(e,t){var r=e.split(" ");for(var i=0;i<r.length;i++){if(r[i]&&!ft(r[i]).test(t)){t+=" "+r[i]}};return t};var lt=function(e){e.select()};if(at){lt=function(e){e.selectionStart=0;e.selectionEnd=e.value.length}} -else if(l){lt=function(e){try{e.select()}catch(t){}}};function Ai(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}};function ve(e,t,i){if(!t){t={}};for(var r in e){if(e.hasOwnProperty(r)&&(i!==!1||!t.hasOwnProperty(r))){t[r]=e[r]}};return t};function H(e,t,i,r,n){if(t==null){t=e.search(/[^\s\u00a0]/);if(t==-1){t=e.length}};for(var l=r||0,s=n||0;;){var o=e.indexOf("\t",l);if(o<0||o>=t){return s+(t-l)};s+=o-l;s+=i-(s%i);l=o+1}};var ce=function(){this.id=null};ce.prototype.set=function(e,t){clearTimeout(this.id);this.id=setTimeout(t,e)};function b(e,t){for(var i=0;i<e.length;++i){if(e[i]==t){return i}};return-1};var Ur=30,Vt={toString:function(){return"CodeMirror.Pass"}};var G={scroll:!1};var Mi={origin:"*mouse"};var ot={origin:"+move"};function Wi(e,t,i){for(var n=0,o=0;;){var r=e.indexOf("\t",n);if(r==-1){r=e.length};var l=r-n;if(r==e.length||o+l>=t){return n+Math.min(l,t-o)};o+=r-n;o+=i-(o%i);n=r+1;if(o>=t){return n}}};var Ut=[""];function Di(e){while(Ut.length<=e){Ut.push(a(Ut)+" ")};return Ut[e]};function a(e){return e[e.length-1]};function jt(e,t){var r=[];for(var i=0;i<e.length;i++){r[i]=t(e[i],i)};return r};function Sl(e,t,i){var r=0,n=i(t);while(r<e.length&&i(e[r])<=n){r++};e.splice(r,0,t)};function qr(){};function Zr(e,t){var i;if(Object.create){i=Object.create(e)} -else{qr.prototype=e;i=new qr()};if(t){ve(t,i)};return i};var ml=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;function Hi(e){return/\w/.test(e)||e>"\x80"&&(e.toUpperCase()!=e.toLowerCase()||ml.test(e))};function Yt(e,t){if(!t){return Hi(e)};if(t.source.indexOf("\\w")>-1&&Hi(e)){return!0};return t.test(e)};function Qr(e){for(var t in e){if(e.hasOwnProperty(t)&&e[t]){return!1}};return!0};var vl=/[\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 Fi(e){return e.charCodeAt(0)>=768&&vl.test(e)};function Jr(e,t,i){while((i<0?t>0:t<e.length)&&Fi(e.charAt(t))){t+=i};return t};function ct(e,t,i){var o=t>i?-1:1;for(;;){if(t==i){return t};var n=(t+i)/2,r=o<0?Math.ceil(n):Math.floor(n);if(r==t){return e(r)?t:i};if(e(r)){i=r} -else{t=r+o}}};function Ll(e,t,r){var n=this;this.input=r;n.scrollbarFiller=i("div",null,"CodeMirror-scrollbar-filler");n.scrollbarFiller.setAttribute("cm-not-content","true");n.gutterFiller=i("div",null,"CodeMirror-gutter-filler");n.gutterFiller.setAttribute("cm-not-content","true");n.lineDiv=Fe("div",null,"CodeMirror-code");n.selectionDiv=i("div",null,null,"position: relative; z-index: 1");n.cursorDiv=i("div",null,"CodeMirror-cursors");n.measure=i("div",null,"CodeMirror-measure");n.lineMeasure=i("div",null,"CodeMirror-measure");n.lineSpace=Fe("div",[n.measure,n.lineMeasure,n.selectionDiv,n.cursorDiv,n.lineDiv],null,"position: relative; outline: none");var o=Fe("div",[n.lineSpace],"CodeMirror-lines");n.mover=i("div",[o],null,"position: relative");n.sizer=i("div",[n.mover],"CodeMirror-sizer");n.sizerWidth=null;n.heightForcer=i("div",null,null,"position: absolute; height: "+Ur+"px; width: 1px;");n.gutters=i("div",null,"CodeMirror-gutters");n.lineGutter=null;n.scroller=i("div",[n.sizer,n.heightForcer,n.gutters],"CodeMirror-scroll");n.scroller.setAttribute("tabIndex","-1");n.wrapper=i("div",[n.scrollbarFiller,n.gutterFiller,n.scroller],"CodeMirror");if(l&&c<8){n.gutters.style.zIndex=-1;n.scroller.style.paddingRight=0};if(!x&&!(ie&&ut)){n.scroller.draggable=!0};if(e){if(e.appendChild){e.appendChild(n.wrapper)} -else{e(n.wrapper)}};n.viewFrom=n.viewTo=t.first;n.reportedViewFrom=n.reportedViewTo=t.first;n.view=[];n.renderedView=null;n.externalMeasured=null;n.viewOffset=0;n.lastWrapHeight=n.lastWrapWidth=0;n.updateLineNumbers=null;n.nativeBarWidth=n.barHeight=n.barWidth=0;n.scrollbarsClipped=!1;n.lineNumWidth=n.lineNumInnerWidth=n.lineNumChars=null;n.alignWidgets=!1;n.cachedCharWidth=n.cachedTextHeight=n.cachedPaddingH=null;n.maxLine=null;n.maxLineLength=0;n.maxLineChanged=!1;n.wheelDX=n.wheelDY=n.wheelStartX=n.wheelStartY=null;n.shift=!1;n.selForContextMenu=null;n.activeTouch=null;r.init(n)};function t(e,t){t-=e.first;if(t<0||t>=e.size){throw new Error("There is no line "+(t+e.first)+" in the document.")};var i=e;while(!i.lines){for(var o=0;;++o){var r=i.children[o],n=r.chunkSize();if(t<n){i=r;break};t-=n}};return i.lines[t]};function me(e,t,i){var n=[],r=t.line;e.iter(t.line,i.line+1,function(e){var o=e.text;if(r==i.line){o=o.slice(0,i.ch)};if(r==t.line){o=o.slice(t.ch)};n.push(o);++r});return n};function Pi(e,t,i){var r=[];e.iter(t,i,function(e){r.push(e.text)});return r};function U(e,t){var r=t-e.height;if(r){for(var i=e;i;i=i.parent){i.height+=r}}};function u(e){if(e.parent==null){return null};var i=e.parent,n=b(i.lines,e);for(var t=i.parent;t;i=t,t=t.parent){for(var r=0;;++r){if(t.children[r]==i){break};n+=t.children[r].chunkSize()}};return n+i.first};function ye(e,t){var o=e.first;outer:do{for(var n=0;n<e.children.length;++n){var r=e.children[n],s=r.height;if(t<s){e=r;continue;outer};t-=s;o+=r.chunkSize()};return o} -while(!e.lines)var i=0;for(;i<e.lines.length;++i){var a=e.lines[i],l=a.height;if(t<l){break};t-=l};return o+i};function ht(e,t){return t>=e.first&&t<e.first+e.size};function Ei(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))};function e(t,i,r){if(r===void 0)r=null;if(!(this instanceof e)){return new e(t,i,r)};this.line=t;this.ch=i;this.sticky=r};function n(e,t){return e.line-t.line||e.ch-t.ch};function Ii(e,t){return e.sticky==t.sticky&&n(e,t)==0};function zi(t){return e(t.line,t.ch)};function qt(e,t){return n(e,t)<0?t:e};function Zt(e,t){return n(e,t)<0?e:t};function en(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))};function o(i,r){if(r.line<i.first){return e(i.first,0)};var n=i.first+i.size-1;if(r.line>n){return e(n,t(i,n).text.length)};return kl(r,t(i,r.line).text.length)};function kl(t,i){var r=t.ch;if(r==null||r>i){return e(t.line,i)} -else if(r<0){return e(t.line,0)} -else{return t}};function tn(e,t){var r=[];for(var i=0;i<t.length;i++){r[i]=o(e,t[i])};return r};var Gr=!1,te=!1;function Tl(){Gr=!0};function Ml(){te=!0};function Qt(e,t,i){this.marker=e;this.from=t;this.to=i};function dt(e,t){if(e){for(var i=0;i<e.length;++i){var r=e[i];if(r.marker==t){return r}}}};function Nl(e,t){var r;for(var i=0;i<e.length;++i){if(e[i]!=t){(r||(r=[])).push(e[i])}};return r};function Ol(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t];t.marker.attachLine(e)};function Al(e,t,i){var l;if(e){for(var o=0;o<e.length;++o){var r=e[o],n=r.marker,a=r.from==null||(n.inclusiveLeft?r.from<=t:r.from<t);if(a||r.from==t&&n.type=="bookmark"&&(!i||!r.marker.insertLeft)){var s=r.to==null||(n.inclusiveRight?r.to>=t:r.to>t);(l||(l=[])).push(new Qt(n,r.from,s?null:r.to))}}};return l};function Wl(e,t,i){var l;if(e){for(var o=0;o<e.length;++o){var r=e[o],n=r.marker,a=r.to==null||(n.inclusiveRight?r.to>=t:r.to>t);if(a||r.from==t&&n.type=="bookmark"&&(!i||r.marker.insertLeft)){var s=r.from==null||(n.inclusiveLeft?r.from<=t:r.from<t);(l||(l=[])).push(new Qt(n,s?null:r.from-t,r.to==null?null:r.to-t))}}};return l};function Ri(e,i){if(i.full){return null};var x=ht(e,i.from.line)&&t(e,i.from.line).markedSpans,C=ht(e,i.to.line)&&t(e,i.to.line).markedSpans;if(!x&&!C){return null};var m=i.from.ch,L=i.to.ch,w=n(i.from,i.to)==0,r=Al(x,m,w),o=Wl(C,L,w),s=i.text.length==1,c=a(i.text).length+(s?m:0);if(r){for(var v=0;v<r.length;++v){var f=r[v];if(f.to==null){var g=dt(o,f.marker);if(!g){f.to=m} -else if(s){f.to=g.to==null?null:g.to+c}}}};if(o){for(var p=0;p<o.length;++p){var l=o[p];if(l.to!=null){l.to+=c};if(l.from==null){var S=dt(r,l.marker);if(!S){l.from=c;if(s){(r||(r=[])).push(l)}}} -else{l.from+=c;if(s){(r||(r=[])).push(l)}}}};if(r){r=rn(r)};if(o&&o!=r){o=rn(o)};var d=[r];if(!s){var b=i.text.length-2,h;if(b>0&&r){for(var u=0;u<r.length;++u){if(r[u].to==null){(h||(h=[])).push(new Qt(r[u].marker,null,null))}}};for(var y=0;y<b;++y){d.push(h)};d.push(o)};return d};function rn(e){for(var i=0;i<e.length;++i){var t=e[i];if(t.from!=null&&t.from==t.to&&t.marker.clearWhenEmpty!==!1){e.splice(i--,1)}};if(!e.length){return null};return e};function Dl(e,t,i){var r=null;e.iter(t.line,i.line+1,function(e){if(e.markedSpans){for(var i=0;i<e.markedSpans.length;++i){var t=e.markedSpans[i].marker;if(t.readOnly&&(!r||b(r,t)==-1)){(r||(r=[])).push(t)}}}});if(!r){return null};var a=[{from:t,to:i}];for(var c=0;c<r.length;++c){var f=r[c],l=f.find(0);for(var s=0;s<a.length;++s){var o=a[s];if(n(o.to,l.from)<0||n(o.from,l.to)>0){continue};var u=[s,1],h=n(o.from,l.from),d=n(o.to,l.to);if(h<0||!f.inclusiveLeft&&!h){u.push({from:o.from,to:l.from})};if(d>0||!f.inclusiveRight&&!d){u.push({from:l.to,to:o.to})};a.splice.apply(a,u);s+=u.length-3}};return a};function nn(e){var i=e.markedSpans;if(!i){return};for(var t=0;t<i.length;++t){i[t].marker.detachLine(e)};e.markedSpans=null};function on(e,t){if(!t){return};for(var i=0;i<t.length;++i){t[i].marker.attachLine(e)};e.markedSpans=t};function Jt(e){return e.inclusiveLeft?-1:0};function ei(e){return e.inclusiveRight?1:0};function ln(e,t){var s=e.lines.length-t.lines.length;if(s!=0){return s};var r=e.find(),o=t.find(),l=n(r.from,o.from)||Jt(e)-Jt(t);if(l){return-l};var i=n(r.to,o.to)||ei(e)-ei(t);if(i){return i};return t.id-e.id};function sn(e,t){var o=te&&e.markedSpans,r;if(o){for(var i=(void 0),n=0;n<o.length;++n){i=o[n];if(i.marker.collapsed&&(t?i.from:i.to)==null&&(!r||ln(r,i.marker)<0)){r=i.marker}}};return r};function an(e){return sn(e,!0)};function pt(e){return sn(e,!1)};function un(e,i,r,o,l){var d=t(e,i),c=te&&d.markedSpans;if(c){for(var f=0;f<c.length;++f){var a=c[f];if(!a.marker.collapsed){continue};var s=a.marker.find(0),u=n(s.from,r)||Jt(a.marker)-Jt(l),h=n(s.to,o)||ei(a.marker)-ei(l);if(u>=0&&h<=0||u<=0&&h>=0){continue};if(u<=0&&(a.marker.inclusiveRight&&l.inclusiveLeft?n(s.to,r)>=0:n(s.to,r)>0)||u>=0&&(a.marker.inclusiveRight&&l.inclusiveLeft?n(s.from,o)<=0:n(s.from,o)<0)){return!0}}}};function V(e){var t;while(t=an(e)){e=t.find(-1,!0).line};return e};function Hl(e){var t;while(t=pt(e)){e=t.find(1,!0).line};return e};function Fl(e){var i,t;while(i=pt(e)){e=i.find(1,!0).line;(t||(t=[])).push(e)};return t};function Bi(e,i){var r=t(e,i),n=V(r);if(r==n){return i};return u(n)};function fn(e,i){if(i>e.lastLine()){return i};var r=t(e,i),n;if(!be(e,r)){return i} -while(n=pt(r)){r=n.find(1,!0).line};return u(r)+1};function be(e,t){var n=te&&t.markedSpans;if(n){for(var i=(void 0),r=0;r<n.length;++r){i=n[r];if(!i.marker.collapsed){continue};if(i.from==null){return!0};if(i.marker.widgetNode){continue};if(i.from==0&&i.marker.inclusiveLeft&&Gi(e,t,i)){return!0}}}};function Gi(e,t,i){if(i.to==null){var o=i.marker.find(1,!0);return Gi(e,o.line,dt(o.line.markedSpans,i.marker))};if(i.marker.inclusiveRight&&i.to==t.text.length){return!0};for(var r=(void 0),n=0;n<t.markedSpans.length;++n){r=t.markedSpans[n];if(r.marker.collapsed&&!r.marker.widgetNode&&r.from==i.to&&(r.to==null||r.to!=i.from)&&(r.marker.inclusiveLeft||i.marker.inclusiveRight)&&Gi(e,t,r)){return!0}}};function q(e){e=V(e);var o=0,t=e.parent;for(var n=0;n<t.lines.length;++n){var s=t.lines[n];if(s==e){break} -else{o+=s.height}};for(var i=t.parent;i;t=i,i=t.parent){for(var r=0;r<i.children.length;++r){var l=i.children[r];if(l==t){break} -else{o+=l.height}}};return o};function ti(e){if(e.height==0){return 0};var i=e.text.length,r,t=e;while(r=an(t)){var o=r.find(0,!0);t=o.from.line;i+=o.from.ch-o.to.ch};t=e;while(r=pt(t)){var n=r.find(0,!0);i-=t.text.length-n.from.ch;t=n.to.line;i+=t.text.length-n.to.ch};return i};function Ui(e){var i=e.display,r=e.doc;i.maxLine=t(r,r.first);i.maxLineLength=ti(i.maxLine);i.maxLineChanged=!0;r.iter(function(e){var t=ti(e);if(t>i.maxLineLength){i.maxLineLength=t;i.maxLine=e}})};function Pl(e,t,i,r){if(!e){return r(t,i,"ltr",0)};var l=!1;for(var o=0;o<e.length;++o){var n=e[o];if(n.from<i&&n.to>t||t==i&&n.to==t){r(Math.max(n.from,t),Math.min(n.to,i),n.level==1?"rtl":"ltr",o);l=!0}};if(!l){r(t,i,"ltr")}};var nt=null;function gt(e,t,i){var o;nt=null;for(var n=0;n<e.length;++n){var r=e[n];if(r.from<t&&r.to>t){return n};if(r.to==t){if(r.from!=r.to&&i=="before"){o=n} -else{nt=n}};if(r.from==t){if(r.from!=r.to&&i!="before"){o=n} -else{nt=n}}};return o!=null?o:nt};var gl=(function(){var l="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",s="nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";function u(e){if(e<=0xf7){return l.charAt(e)} -else if(0x590<=e&&e<=0x5f4){return"R"} -else if(0x600<=e&&e<=0x6f9){return s.charAt(e-0x600)} -else if(0x6ee<=e&&e<=0x8ac){return"r"} -else if(0x2000<=e&&e<=0x200b){return"w"} -else if(e==0x200c){return"b"} -else{return"L"}};var o=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,t=/[stwN]/,i=/[LRr]/,r=/[Lb1n]/,n=/[1n]/;function e(e,t,i){this.level=e;this.from=t;this.to=i};return function(l,s){var S=s=="ltr"?"L":"R";if(l.length==0||s=="ltr"&&!o.test(l)){return!1};var h=l.length,f=[];for(var H=0;H<h;++H){f.push(u(l.charCodeAt(H)))};for(var M=0,R=S;M<h;++M){var z=f[M];if(z=="m"){f[M]=R} -else{R=z}};for(var L=0,I=S;L<h;++L){var T=f[L];if(T=="1"&&I=="r"){f[L]="n"} -else if(i.test(T)){I=T;if(T=="r"){f[L]="R"}}};for(var b=1,C=f[0];b<h-1;++b){var D=f[b];if(D=="+"&&C=="1"&&f[b+1]=="1"){f[b]="1"} -else if(D==","&&C==f[b+1]&&(C=="1"||C=="n")){f[b]=C};C=D};for(var g=0;g<h;++g){var E=f[g];if(E==","){f[g]="N"} -else if(E=="%"){var y=(void 0);for(y=g+1;y<h&&f[y]=="%";++y){};var K=(g&&f[g-1]=="!")||(y<h&&f[y]=="1")?"1":"N";for(var W=g;W<y;++W){f[W]=K};g=y-1}};for(var k=0,P=S;k<h;++k){var A=f[k];if(P=="L"&&A=="1"){f[k]="L"} -else if(i.test(A)){P=A}};for(var m=0;m<h;++m){if(t.test(f[m])){var v=(void 0);for(v=m+1;v<h&&t.test(f[v]);++v){};var F=(m?f[m-1]:S)=="L",U=(v<h?f[v]:S)=="L",V=F==U?(F?"L":"R"):S;for(var O=m;O<v;++O){f[O]=V};m=v-1}};var d=[],x;for(var c=0;c<h;){if(r.test(f[c])){var G=c;for(++c;c<h&&r.test(f[c]);++c){};d.push(new e(0,G,c))} -else{var w=c,N=d.length;for(++c;c<h&&f[c]!="L";++c){};for(var p=w;p<c;){if(n.test(f[p])){if(w<p){d.splice(N,0,new e(1,w,p))};var B=p;for(++p;p<c&&n.test(f[p]);++p){};d.splice(N,0,new e(2,B,p));w=p} -else{++p}};if(w<c){d.splice(N,0,new e(1,w,c))}}};if(s=="ltr"){if(d[0].level==1&&(x=l.match(/^\s+/))){d[0].from=x[0].length;d.unshift(new e(0,0,x[0].length))};if(a(d).level==1&&(x=l.match(/\s+$/))){a(d).to-=x[0].length;d.push(new e(0,h-x[0].length,h))}};return s=="rtl"?d.reverse():d}})();function Z(e,t){var i=e.order;if(i==null){i=e.order=gl(e.text,t)};return i};var Br=[],r=function(e,t,i){if(e.addEventListener){e.addEventListener(t,i,!1)} -else if(e.attachEvent){e.attachEvent("on"+t,i)} -else{var r=e._handlers||(e._handlers={});r[t]=(r[t]||Br).concat(i)}};function Vi(e,t){return e._handlers&&e._handlers[t]||Br};function D(e,t,i){if(e.removeEventListener){e.removeEventListener(t,i,!1)} -else if(e.detachEvent){e.detachEvent("on"+t,i)} -else{var o=e._handlers,r=o&&o[t];if(r){var n=b(r,i);if(n>-1){o[t]=r.slice(0,n).concat(r.slice(n+1))}}}};function p(e,t){var r=Vi(e,t);if(!r.length){return};var n=Array.prototype.slice.call(arguments,2);for(var i=0;i<r.length;++i){r[i].apply(null,n)}};function v(e,t,i){if(typeof t=="string"){t={type:t,preventDefault:function(){this.defaultPrevented=!0}}};p(e,i||t.type,e,t);return Ki(t)||t.codemirrorIgnore};function cn(e){var i=e._handlers&&e._handlers.cursorActivity;if(!i){return};var r=e.curOp.cursorActivityHandlers||(e.curOp.cursorActivityHandlers=[]);for(var t=0;t<i.length;++t){if(b(r,i[t])==-1){r.push(i[t])}}};function F(e,t){return Vi(e,t).length>0};function Pe(e){e.prototype.on=function(e,t){r(this,e,t)};e.prototype.off=function(e,t){D(this,e,t)}};function T(e){if(e.preventDefault){e.preventDefault()} -else{e.returnValue=!1}};function hn(e){if(e.stopPropagation){e.stopPropagation()} -else{e.cancelBubble=!0}};function Ki(e){return e.defaultPrevented!=null?e.defaultPrevented:e.returnValue==!1};function vt(e){T(e);hn(e)};function Xi(e){return e.target||e.srcElement};function dn(e){var t=e.which;if(t==null){if(e.button&1){t=1} -else if(e.button&2){t=3} -else if(e.button&4){t=2}};if(I&&e.ctrlKey&&t==1){t=3};return t};var pl=function(){if(l&&c<9){return!1};var e=i("div");return"draggable" in e||"dragDrop" in e}(),Ti;function El(e){if(Ti==null){var t=i("span","\u200b");W(e,i("span",[t,document.createTextNode("x")]));if(e.firstChild.offsetHeight!=0){Ti=t.offsetWidth<=1&&t.offsetHeight>2&&!(l&&c<8)}};var r=Ti?i("span","\u200b"):i("span","\u00a0",null,"display: inline-block; width: 1px; margin-right: -1px");r.setAttribute("cm-text","");return r};var ki;function Il(e){if(ki!=null){return ki};var i=W(e,document.createTextNode("A\u062eA")),t=he(i,0,1).getBoundingClientRect(),r=he(i,1,2).getBoundingClientRect();re(e);if(!t||t.left==t.right){return!1};return ki=(r.right-t.right<3)};var Si="\n\nb".split(/\n/).length!=3?function(e){var i=0,o=[],l=e.length;while(i<=l){var t=e.indexOf("\n",i);if(t==-1){t=e.length};var r=e.slice(i,e.charAt(t-1)=="\r"?t-1:t),n=r.indexOf("\r");if(n!=-1){o.push(r.slice(0,n));i+=n+1} -else{o.push(r);i=t+1}};return o}:function(e){return e.split(/\r\n?|\n/)},hl=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(t){return!1}}:function(e){var i;try{i=e.ownerDocument.selection.createRange()}catch(t){};if(!i||i.parentElement()!=e){return!1};return i.compareEndPoints("StartToEnd",i)!=0},dl=(function(){var e=i("div");if("oncopy" in e){return!0};e.setAttribute("oncopy","return;");return typeof e.oncopy=="function"})(),Li=null;function zl(e){if(Li!=null){return Li};var t=W(e,i("span","x")),r=t.getBoundingClientRect(),n=he(t,0,1).getBoundingClientRect();return Li=Math.abs(r.left-n.left)>1};var Ci={};var He={};function Rl(e,t){if(arguments.length>2){t.dependencies=Array.prototype.slice.call(arguments,2)};Ci[e]=t};function Bl(e,t){He[e]=t};function ii(e){if(typeof e=="string"&&He.hasOwnProperty(e)){e=He[e]} -else if(e&&typeof e.name=="string"&&He.hasOwnProperty(e.name)){var t=He[e.name];if(typeof t=="string"){t={name:t}};e=Zr(t,e);e.name=t.name} -else if(typeof e=="string"&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e)){return ii("application/xml")} -else if(typeof e=="string"&&/^[\w\-]+\/[\w\-]+\+json$/.test(e)){return ii("application/json")};if(typeof e=="string"){return{name:e}} -else{return e||{name:"null"}}};function ji(e,t){t=ii(t);var l=Ci[t.name];if(!l){return ji(e,"text/plain")};var i=l(e,t);if(De.hasOwnProperty(t.name)){var n=De[t.name];for(var r in n){if(!n.hasOwnProperty(r)){continue};if(i.hasOwnProperty(r)){i["_"+r]=i[r]};i[r]=n[r]}};i.name=t.name;if(t.helperType){i.helperType=t.helperType};if(t.modeProps){for(var o in t.modeProps){i[o]=t.modeProps[o]}};return i};var De={};function Gl(e,t){var i=De.hasOwnProperty(e)?De[e]:(De[e]={});ve(t,i)};function we(e,t){if(t===!0){return t};if(e.copyState){return e.copyState(t)};var n={};for(var r in t){var i=t[r];if(i instanceof Array){i=i.concat([])};n[r]=i};return n};function Yi(e,t){var i;while(e.innerMode){i=e.innerMode(t);if(!i||i.mode==e){break};t=i.state;e=i.mode};return i||{mode:e,state:t}};function pn(e,t,i){return e.startState?e.startState(t,i):!0};var d=function(e,t,i){this.pos=this.start=0;this.string=e;this.tabSize=t||8;this.lastColumnPos=this.lastColumnValue=0;this.lineStart=0;this.lineOracle=i};d.prototype.eol=function(){return this.pos>=this.string.length};d.prototype.sol=function(){return this.pos==this.lineStart};d.prototype.peek=function(){return this.string.charAt(this.pos)||undefined};d.prototype.next=function(){if(this.pos<this.string.length){return this.string.charAt(this.pos++)}};d.prototype.eat=function(e){var t=this.string.charAt(this.pos),i;if(typeof e=="string"){i=t==e} -else{i=t&&(e.test?e.test(t):e(t))};if(i){++this.pos;return t}};d.prototype.eatWhile=function(e){var t=this.pos;while(this.eat(e)){};return this.pos>t};d.prototype.eatSpace=function(){var e=this,t=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos))){++e.pos};return this.pos>t};d.prototype.skipToEnd=function(){this.pos=this.string.length};d.prototype.skipTo=function(e){var t=this.string.indexOf(e,this.pos);if(t>-1){this.pos=t;return!0}};d.prototype.backUp=function(e){this.pos-=e};d.prototype.column=function(){if(this.lastColumnPos<this.start){this.lastColumnValue=H(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue);this.lastColumnPos=this.start};return this.lastColumnValue-(this.lineStart?H(this.string,this.lineStart,this.tabSize):0)};d.prototype.indentation=function(){return H(this.string,null,this.tabSize)-(this.lineStart?H(this.string,this.lineStart,this.tabSize):0)};d.prototype.match=function(e,t,i){if(typeof e=="string"){var n=function(e){return i?e.toLowerCase():e},o=this.string.substr(this.pos,e.length);if(n(o)==n(e)){if(t!==!1){this.pos+=e.length};return!0}} -else{var r=this.string.slice(this.pos).match(e);if(r&&r.index>0){return null};if(r&&t!==!1){this.pos+=r[0].length};return r}};d.prototype.current=function(){return this.string.slice(this.start,this.pos)};d.prototype.hideFirstChars=function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}};d.prototype.lookAhead=function(e){var t=this.lineOracle;return t&&t.lookAhead(e)};d.prototype.baseToken=function(){var e=this.lineOracle;return e&&e.baseToken(this.pos)};var Gt=function(e,t){this.state=e;this.lookAhead=t},B=function(e,t,i,r){this.state=t;this.doc=e;this.line=i;this.maxLookAhead=r||0;this.baseTokens=null;this.baseTokenPos=1};B.prototype.lookAhead=function(e){var t=this.doc.getLine(this.line+e);if(t!=null&&e>this.maxLookAhead){this.maxLookAhead=e};return t};B.prototype.baseToken=function(e){var i=this;if(!this.baseTokens){return null} -while(this.baseTokens[this.baseTokenPos]<=e){i.baseTokenPos+=2};var t=this.baseTokens[this.baseTokenPos+1];return{type:t&&t.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}};B.prototype.nextLine=function(){this.line++;if(this.maxLookAhead>0){this.maxLookAhead--}};B.fromSaved=function(e,t,i){if(t instanceof Gt){return new B(e,we(e.mode,t.state),i,t.lookAhead)} -else{return new B(e,we(e.mode,t),i)}};B.prototype.save=function(e){var t=e!==!1?we(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new Gt(t,this.maxLookAhead):t};function gn(e,t,i,r){var n=[e.state.modeGen],o={};wn(e,t.text,e.doc.mode,i,function(e,t){return n.push(e,t)},o,r);var s=i.state,a=function(r){i.baseTokens=n;var a=e.state.overlays[r],l=1,u=0;i.state=!0;wn(e,t.text,a.mode,i,function(e,t){var i=l;while(u<e){var r=n[l];if(r>e){n.splice(l,1,e,n[l+1],r)};l+=2;u=Math.min(e,r)};if(!t){return};if(a.opaque){n.splice(i,l-i,e,"overlay "+t);l=i+2} -else{for(;i<l;i+=2){var o=n[i+1];n[i+1]=(o?o+" ":"")+"overlay "+t}}},o);i.state=s;i.baseTokens=null;i.baseTokenPos=1};for(var l=0;l<e.state.overlays.length;++l)a(l);return{styles:n,classes:o.bgClass||o.textClass?o:null}};function vn(e,t,i){if(!t.styles||t.styles[0]!=e.state.modeGen){var r=mt(e,u(t)),n=t.text.length>e.options.maxHighlightLength&&we(e.doc.mode,r.state),o=gn(e,t,r);if(n){r.state=n};t.stateAfter=r.save(!n);t.styles=o.styles;if(o.classes){t.styleClasses=o.classes} -else if(t.styleClasses){t.styleClasses=null};if(i===e.doc.highlightFrontier){e.doc.modeFrontier=Math.max(e.doc.modeFrontier,++e.doc.highlightFrontier)}};return t.styles};function mt(e,i,r){var n=e.doc,a=e.display;if(!n.mode.startState){return new B(n,!0,i)};var l=Ul(e,i,r),s=l>n.first&&t(n,l-1).stateAfter,o=s?B.fromSaved(n,s,l):new B(n,pn(n.mode),l);n.iter(l,i,function(t){qi(e,t.text,o);var r=o.line;t.stateAfter=r==i-1||r%5==0||r>=a.viewFrom&&r<a.viewTo?o.save():null;o.nextLine()});if(r){n.modeFrontier=o.line};return o};function qi(e,t,i,r){var o=e.doc.mode,n=new d(t,e.options.tabSize,i);n.start=n.pos=r||0;if(t==""){mn(o,i.state)} -while(!n.eol()){Zi(o,n,i.state);n.start=n.pos}};function mn(e,t){if(e.blankLine){return e.blankLine(t)};if(!e.innerMode){return};var i=Yi(e,t);if(i.mode.blankLine){return i.mode.blankLine(i.state)}};function Zi(e,t,i,r){for(var n=0;n<10;n++){if(r){r[0]=Yi(e,i).mode};var o=e.token(t,i);if(t.pos>t.start){return o}};throw new Error("Mode "+e.name+" failed to advance stream.")};var Rr=function(e,t,i){this.start=e.start;this.end=e.pos;this.string=e.current();this.type=t||null;this.state=i};function yn(e,i,r,n){var a=e.doc,h=a.mode,f;i=o(a,i);var c=t(a,i.line),s=mt(e,i.line,r),l=new d(c.text,e.options.tabSize,s),u;if(n){u=[]} -while((n||l.pos<i.ch)&&!l.eol()){l.start=l.pos;f=Zi(h,l,s.state);if(n){u.push(new Rr(l,f,we(a.mode,s.state)))}};return n?u:new Rr(l,f,s.state)};function bn(e,t){if(e){for(;;){var i=e.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!i){break};e=e.slice(0,i.index)+e.slice(i.index+i[0].length);var r=i[1]?"bgClass":"textClass";if(t[r]==null){t[r]=i[2]} -else if(!(new RegExp("(?:^|\s)"+i[2]+"(?:$|\s)")).test(t[r])){t[r]+=" "+i[2]}}};return e};function wn(e,t,i,r,n,l,u){var c=i.flattenSpans;if(c==null){c=e.options.flattenSpans};var s=0,f=null,o=new d(t,e.options.tabSize,r),a,p=e.options.addModeClass&&[null];if(t==""){bn(mn(i,r.state),l)} -while(!o.eol()){if(o.pos>e.options.maxHighlightLength){c=!1;if(u){qi(e,t,r,o.pos)};o.pos=t.length;a=null} -else{a=bn(Zi(i,o,r.state,p),l)};if(p){var h=p[0].name;if(h){a="m-"+(a?h+" "+a:h)}};if(!c||f!=a){while(s<o.start){s=Math.min(o.start,s+5000);n(s,f)};f=a};o.start=o.pos} -while(s<o.pos){var g=Math.min(o.pos,s+5000);n(g,f);s=g}};function Ul(e,i,r){var f,s,o=e.doc,c=r?-1:i-(e.doc.mode.innerMode?1000:100);for(var n=i;n>c;--n){if(n<=o.first){return o.first};var u=t(o,n-1),l=u.stateAfter;if(l&&(!r||n+(l instanceof Gt?l.lookAhead:0)<=o.modeFrontier)){return n};var a=H(u.text,null,e.options.tabSize);if(s==null||f>a){s=n-1;f=a}};return s};function Vl(e,i){e.modeFrontier=Math.min(e.modeFrontier,i);if(e.highlightFrontier<i-10){return};var o=e.first;for(var r=i-1;r>o;r--){var n=t(e,r).stateAfter;if(n&&(!(n instanceof Gt)||r+n.lookAhead<i)){o=r+1;break}};e.highlightFrontier=Math.min(e.highlightFrontier,o)};var We=function(e,t,i){this.text=e;on(this,t);this.height=i?i(this):1};We.prototype.lineNo=function(){return u(this)};Pe(We);function Kl(e,t,i,r){e.text=t;if(e.stateAfter){e.stateAfter=null};if(e.styles){e.styles=null};if(e.order!=null){e.order=null};nn(e);on(e,i);var n=r?r(e):1;if(n!=e.height){U(e,n)}};function Xl(e){e.parent=null;nn(e)};var cl={};var fl={};function xn(e,t){if(!e||/^\s*$/.test(e)){return null};var i=t.addModeClass?fl:cl;return i[e]||(i[e]=e.replace(/\S+/g,"cm-$&"))};function Cn(e,t){var a=Fe("span",null,null,x?"padding-right: .1px":null),i={pre:Fe("pre",[a],"CodeMirror-line"),content:a,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:(l||x)&&e.getOption("lineWrapping")};t.measure={};for(var n=0;n<=(t.rest?t.rest.length:0);n++){var r=n?t.rest[n-1]:t.line,s=(void 0);i.pos=0;i.addToken=Yl;if(Il(e.display.measure)&&(s=Z(r,e.doc.direction))){i.addToken=Zl(i.addToken,s)};i.map=[];var f=t!=e.display.externalMeasured&&u(r);Ql(r,i,vn(e,r,f));if(r.styleClasses){if(r.styleClasses.bgClass){i.bgClass=Oi(r.styleClasses.bgClass,i.bgClass||"")};if(r.styleClasses.textClass){i.textClass=Oi(r.styleClasses.textClass,i.textClass||"")}};if(i.map.length==0){i.map.push(0,0,i.content.appendChild(El(e.display.measure)))};if(n==0){t.measure.map=i.map;t.measure.cache={}} -else{;(t.measure.maps||(t.measure.maps=[])).push(i.map);(t.measure.caches||(t.measure.caches=[])).push({})}};if(x){var o=i.content.lastChild;if(/\bcm-tab\b/.test(o.className)||(o.querySelector&&o.querySelector(".cm-tab"))){i.content.className="cm-tab-wrap-hack"}};p(e,"renderLine",e,t.line,i.pre);if(i.pre.className){i.textClass=Oi(i.pre.className,i.textClass||"")};return i};function jl(e){var t=i("span","\u2022","cm-invalidchar");t.title="\\u"+e.charCodeAt(0).toString(16);t.setAttribute("aria-label",t.title);return t};function Yl(e,t,r,n,o,f,h){if(!t){return};var m=e.splitSpaces?ql(t,e.trailingSpace):t,y=e.cm.state.specialChars,C=!1,s;if(!y.test(t)){e.col+=t.length;s=document.createTextNode(m);e.map.push(e.pos,e.pos+t.length,s);if(l&&c<9){C=!0};e.pos+=t.length} -else{s=document.createDocumentFragment();var p=0;while(!0){y.lastIndex=p;var u=y.exec(t),d=u?u.index-p:t.length-p;if(d){var v=document.createTextNode(m.slice(p,p+d));if(l&&c<9){s.appendChild(i("span",[v]))} -else{s.appendChild(v)};e.map.push(e.pos,e.pos+d,v);e.col+=d;e.pos+=d};if(!u){break};p+=d+1;var a=(void 0);if(u[0]=="\t"){var w=e.cm.options.tabSize,x=w-e.col%w;a=s.appendChild(i("span",Di(x),"cm-tab"));a.setAttribute("role","presentation");a.setAttribute("cm-text","\t");e.col+=x} -else if(u[0]=="\r"||u[0]=="\n"){a=s.appendChild(i("span",u[0]=="\r"?"\u240d":"\u2424","cm-invalidchar"));a.setAttribute("cm-text",u[0]);e.col+=1} -else{a=e.cm.options.specialCharPlaceholder(u[0]);a.setAttribute("cm-text",u[0]);if(l&&c<9){s.appendChild(i("span",[a]))} -else{s.appendChild(a)};e.col+=1};e.map.push(e.pos,e.pos+1,a);e.pos++}};e.trailingSpace=m.charCodeAt(t.length-1)==32;if(r||n||o||C||h){var g=r||"";if(n){g+=n};if(o){g+=o};var b=i("span",[s],g,h);if(f){b.title=f};return e.content.appendChild(b)};e.content.appendChild(s)};function ql(e,t){if(e.length>1&&!/ /.test(e)){return e};var n=t,o="";for(var i=0;i<e.length;i++){var r=e.charAt(i);if(r==" "&&n&&(i==e.length-1||e.charCodeAt(i+1)==32)){r="\u00a0"};o+=r;n=r==" "};return o};function Zl(e,t){return function(i,r,n,o,l,s,u){n=n?n+" cm-force-border":"cm-force-border";var f=i.pos,h=f+r.length;for(;;){var a=(void 0);for(var c=0;c<t.length;c++){a=t[c];if(a.to>f&&a.from<=f){break}};if(a.to>=h){return e(i,r,n,o,l,s,u)};e(i,r.slice(0,a.to-f),n,o,null,s,u);o=null;r=r.slice(a.to-f);f=a.to}}};function Sn(e,t,i,r){var n=!r&&i.widgetNode;if(n){e.map.push(e.pos,e.pos+t,n)};if(!r&&e.cm.display.input.needsContentAttribute){if(!n){n=e.content.appendChild(document.createElement("span"))};n.setAttribute("cm-marker",i.id)};if(n){e.cm.display.input.setUneditable(n);e.content.appendChild(n)};e.pos+=t;e.trailingSpace=!1};function Ql(e,t,i){var k=e.markedSpans,T=e.text,y=0;if(!k){for(var m=1;m<i.length;m+=2){t.addToken(t,T.slice(y,y=i[m]),xn(i[m+1],t.cm.options))};return};var S=T.length,r=0,N=1,a="",L,c,s=0,d,p,g,v,l;for(;;){if(s==r){d=p=g=v=c="";l=null;s=Infinity;var C=[],u=(void 0);for(var x=0;x<k.length;++x){var n=k[x],o=n.marker;if(o.type=="bookmark"&&n.from==r&&o.widgetNode){C.push(o)} -else if(n.from<=r&&(n.to==null||n.to>r||o.collapsed&&n.to==r&&n.from==r)){if(n.to!=null&&n.to!=r&&s>n.to){s=n.to;p=""};if(o.className){d+=" "+o.className};if(o.css){c=(c?c+";":"")+o.css};if(o.startStyle&&n.from==r){g+=" "+o.startStyle};if(o.endStyle&&n.to==s){(u||(u=[])).push(o.endStyle,n.to)};if(o.title&&!v){v=o.title};if(o.collapsed&&(!l||ln(l.marker,o)<0)){l=n}} -else if(n.from>r&&s>n.from){s=n.from}};if(u){for(var h=0;h<u.length;h+=2){if(u[h+1]==s){p+=" "+u[h]}}};if(!l||l.from==r){for(var w=0;w<C.length;++w){Sn(t,0,C[w])}};if(l&&(l.from||0)==r){Sn(t,(l.to==null?S+1:l.to)-r,l.marker,l.from==null);if(l.to==null){return};if(l.to==r){l=!1}}};if(r>=S){break};var f=Math.min(S,s);while(!0){if(a){var b=r+a.length;if(!l){var M=b>f?a.slice(0,f-r):a;t.addToken(t,M,L?L+d:d,g,r+M.length==s?p:"",v,c)};if(b>=f){a=a.slice(f-r);r=f;break};r=b;g=""};a=T.slice(y,y=i[N++]);L=xn(i[N++],t.cm.options)}}};function Ln(e,t,i){this.line=t;this.rest=Fl(t);this.size=this.rest?u(a(this.rest))-i+1:1;this.node=this.text=null;this.hidden=be(e,t)};function ri(e,i,r){var l=[],s;for(var n=i;n<r;n=s){var o=new Ln(e.doc,t(e.doc,n),n);s=n+o.size;l.push(o)};return l};var Ae=null;function Jl(e){if(Ae){Ae.ops.push(e)} -else{e.ownsGroup=Ae={ops:[e],delayedCallbacks:[]}}};function es(e){var n=e.delayedCallbacks,i=0;do{for(;i<n.length;i++){n[i].call(null)};for(var r=0;r<e.ops.length;r++){var t=e.ops[r];if(t.cursorActivityHandlers){while(t.cursorActivityCalled<t.cursorActivityHandlers.length){t.cursorActivityHandlers[t.cursorActivityCalled++].call(null,t.cm)}}}} -while(i<n.length)};function ts(e,t){var i=e.ownsGroup;if(!i){return};try{es(i)}finally{Ae=null;t(i)}};var rt=null;function w(e,t){var n=Vi(e,t);if(!n.length){return};var l=Array.prototype.slice.call(arguments,2),i;if(Ae){i=Ae.delayedCallbacks} -else if(rt){i=rt} -else{i=rt=[];setTimeout(is,0)};var o=function(e){i.push(function(){return n[e].apply(null,l)})};for(var r=0;r<n.length;++r)o(r)};function is(){var t=rt;rt=null;for(var e=0;e<t.length;++e){t[e]()}};function kn(e,t,i,r){for(var o=0;o<t.changes.length;o++){var n=t.changes[o];if(n=="text"){ns(e,t)} -else if(n=="gutter"){Mn(e,t,i,r)} -else if(n=="class"){Qi(e,t)} -else if(n=="widget"){os(e,t,r)}};t.changes=null};function yt(e){if(e.node==e.text){e.node=i("div",null,null,"position: relative");if(e.text.parentNode){e.text.parentNode.replaceChild(e.node,e.text)};e.node.appendChild(e.text);if(l&&c<8){e.node.style.zIndex=2}};return e.node};function rs(e,t){var r=t.bgClass?t.bgClass+" "+(t.line.bgClass||""):t.line.bgClass;if(r){r+=" CodeMirror-linebackground"};if(t.background){if(r){t.background.className=r} -else{t.background.parentNode.removeChild(t.background);t.background=null}} -else if(r){var n=yt(t);t.background=n.insertBefore(i("div",null,r),n.firstChild);e.display.input.setUneditable(t.background)}};function Tn(e,t){var i=e.display.externalMeasured;if(i&&i.line==t.line){e.display.externalMeasured=null;t.measure=i.measure;return i.built};return Cn(e,t)};function ns(e,t){var r=t.text.className,i=Tn(e,t);if(t.text==t.node){t.node=i.pre};t.text.parentNode.replaceChild(i.pre,t.text);t.text=i.pre;if(i.bgClass!=t.bgClass||i.textClass!=t.textClass){t.bgClass=i.bgClass;t.textClass=i.textClass;Qi(e,t)} -else if(r){t.text.className=r}};function Qi(e,t){rs(e,t);if(t.line.wrapClass){yt(t).className=t.line.wrapClass} -else if(t.node!=t.text){t.node.className=""};var i=t.textClass?t.textClass+" "+(t.line.textClass||""):t.line.textClass;t.text.className=i||""};function Mn(e,t,r,n){if(t.gutter){t.node.removeChild(t.gutter);t.gutter=null};if(t.gutterBackground){t.node.removeChild(t.gutterBackground);t.gutterBackground=null};if(t.line.gutterClass){var c=yt(t);t.gutterBackground=i("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,("left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px; width: "+(n.gutterTotalWidth)+"px"));e.display.input.setUneditable(t.gutterBackground);c.insertBefore(t.gutterBackground,t.text)};var o=t.line.gutterMarkers;if(e.options.lineNumbers||o){var f=yt(t),l=t.gutter=i("div",null,"CodeMirror-gutter-wrapper",("left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px"));e.display.input.setUneditable(l);f.insertBefore(l,t.text);if(t.line.gutterClass){l.className+=" "+t.line.gutterClass};if(e.options.lineNumbers&&(!o||!o["CodeMirror-linenumbers"])){t.lineNumber=l.appendChild(i("div",Ei(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt",("left: "+(n.gutterLeft["CodeMirror-linenumbers"])+"px; width: "+(e.display.lineNumInnerWidth)+"px")))};if(o){for(var a=0;a<e.options.gutters.length;++a){var s=e.options.gutters[a],u=o.hasOwnProperty(s)&&o[s];if(u){l.appendChild(i("div",[u],"CodeMirror-gutter-elt",("left: "+(n.gutterLeft[s])+"px; width: "+(n.gutterWidth[s])+"px")))}}}}};function os(e,t,i){if(t.alignable){t.alignable=null};for(var r=t.node.firstChild,n=(void 0);r;r=n){n=r.nextSibling;if(r.className=="CodeMirror-linewidget"){t.node.removeChild(r)}};Nn(e,t,i)};function ls(e,t,i,r){var n=Tn(e,t);t.text=t.node=n.pre;if(n.bgClass){t.bgClass=n.bgClass};if(n.textClass){t.textClass=n.textClass};Qi(e,t);Mn(e,t,i,r);Nn(e,t,r);return t.node};function Nn(e,t,i){On(e,t.line,t,i,!0);if(t.rest){for(var r=0;r<t.rest.length;r++){On(e,t.rest[r],t,i,!1)}}};function On(e,t,r,n,o){if(!t.widgets){return};var f=yt(r);for(var a=0,u=t.widgets;a<u.length;++a){var l=u[a],s=i("div",[l.node],"CodeMirror-linewidget");if(!l.handleMouseEvents){s.setAttribute("cm-ignore-events","true")};ss(l,s,r,n);e.display.input.setUneditable(s);if(o&&l.above){f.insertBefore(s,r.gutter||r.text)} -else{f.appendChild(s)};w(l,"redraw")}};function ss(e,t,i,r){if(e.noHScroll){;(i.alignable||(i.alignable=[])).push(t);var n=r.wrapperWidth;t.style.left=r.fixedPos+"px";if(!e.coverGutter){n-=r.gutterTotalWidth;t.style.paddingLeft=r.gutterTotalWidth+"px"};t.style.width=n+"px"};if(e.coverGutter){t.style.zIndex=5;t.style.position="relative";if(!e.noHScroll){t.style.marginLeft=-r.gutterTotalWidth+"px"}}};function bt(e){if(e.height!=null){return e.height};var t=e.doc.cm;if(!t){return 0};if(!ne(document.body,e.node)){var r="position: relative;";if(e.coverGutter){r+="margin-left: -"+t.display.gutters.offsetWidth+"px;"};if(e.noHScroll){r+="width: "+t.display.wrapper.clientWidth+"px;"};W(t.display.measure,i("div",[e.node],null,r))};return e.height=e.node.parentNode.offsetHeight};function Q(e,t){for(var i=Xi(t);i!=e.wrapper;i=i.parentNode){if(!i||(i.nodeType==1&&i.getAttribute("cm-ignore-events")=="true")||(i.parentNode==e.sizer&&i!=e.mover)){return!0}}};function ni(e){return e.lineSpace.offsetTop};function Ji(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight};function An(e){if(e.cachedPaddingH){return e.cachedPaddingH};var r=W(e.measure,i("pre","x")),n=window.getComputedStyle?window.getComputedStyle(r):r.currentStyle,t={left:parseInt(n.paddingLeft),right:parseInt(n.paddingRight)};if(!isNaN(t.left)&&!isNaN(t.right)){e.cachedPaddingH=t};return t};function K(e){return Ur-e.display.nativeBarWidth};function xe(e){return e.display.scroller.clientWidth-K(e)-e.display.barWidth};function er(e){return e.display.scroller.clientHeight-K(e)-e.display.barHeight};function as(e,t,i){var o=e.options.lineWrapping,u=o&&xe(e);if(!t.measure.heights||o&&t.measure.width!=u){var a=t.measure.heights=[];if(o){t.measure.width=u;var n=t.text.firstChild.getClientRects();for(var r=0;r<n.length-1;r++){var l=n[r],s=n[r+1];if(Math.abs(l.bottom-s.bottom)>2){a.push((l.bottom+s.top)/2-i.top)}}};a.push(i.bottom-i.top)}};function Wn(e,t,i){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 r=0;r<e.rest.length;r++){if(u(e.rest[r])>i){return{map:e.measure.maps[r],cache:e.measure.caches[r],before:!0}}}};function us(e,t){t=V(t);var n=u(t),i=e.display.externalMeasured=new Ln(e.doc,t,n);i.lineN=n;var r=i.built=Cn(e,i);i.text=r.pre;W(e.display.lineMeasure,r.pre);return i};function Dn(e,t,i,r){return X(e,Ee(e,t),i,r)};function tr(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo){return e.display.view[Le(e,t)]};var i=e.display.externalMeasured;if(i&&t>=i.lineN&&t<i.lineN+i.size){return i}};function Ee(e,t){var n=u(t),i=tr(e,n);if(i&&!i.text){i=null} -else if(i&&i.changes){kn(e,i,n,sr(e));e.curOp.forceUpdate=!0};if(!i){i=us(e,t)};var r=Wn(i,t,n);return{line:t,view:i,rect:null,map:r.map,cache:r.cache,before:r.before,hasHeights:!1}};function X(e,t,i,r,n){if(t.before){i=-1};var l=i+(r||""),o;if(t.cache.hasOwnProperty(l)){o=t.cache[l]} -else{if(!t.rect){t.rect=t.view.text.getBoundingClientRect()};if(!t.hasHeights){as(e,t.view,t.rect);t.hasHeights=!0};o=cs(e,t,i,r);if(!o.bogus){t.cache[l]=o}};return{left:o.left,right:o.right,top:n?o.rtop:o.top,bottom:n?o.rbottom:o.bottom}};var zr={left:0,right:0,top:0,bottom:0};function Hn(e,t,i){var a,n,u,s,l,o;for(var r=0;r<e.length;r+=3){l=e[r];o=e[r+1];if(t<l){n=0;u=1;s="left"} -else if(t<o){n=t-l;u=n+1} -else if(r==e.length-3||t==o&&e[r+3]>t){u=o-l;n=u-1;if(t>=o){s="right"}};if(n!=null){a=e[r+2];if(l==o&&i==(a.insertLeft?"left":"right")){s=i};if(i=="left"&&n==0){while(r&&e[r-2]==e[r-3]&&e[r-1].insertLeft){a=e[(r-=3)+2];s="left"}};if(i=="right"&&n==o-l){while(r<e.length-3&&e[r+3]==e[r+4]&&!e[r+5].insertLeft){a=e[(r+=3)+2];s="right"}};break}};return{node:a,start:n,end:u,collapse:s,coverStart:l,coverEnd:o}};function fs(e,t){var i=zr;if(t=="left"){for(var n=0;n<e.length;n++){if((i=e[n]).left!=i.right){break}}} -else{for(var r=e.length-1;r>=0;r--){if((i=e[r]).left!=i.right){break}}};return i};function cs(e,t,i,r){var s=Hn(t.map,i,r),u=s.node,o=s.start,f=s.end,g=s.collapse,n;if(u.nodeType==3){for(var b=0;b<4;b++){while(o&&Fi(t.line.text.charAt(s.coverStart+o))){--o} -while(s.coverStart+f<s.coverEnd&&Fi(t.line.text.charAt(s.coverStart+f))){++f};if(l&&c<9&&o==0&&f==s.coverEnd-s.coverStart){n=u.parentNode.getBoundingClientRect()} -else{n=fs(he(u,o,f).getClientRects(),r)};if(n.left||n.right||o==0){break};f=o;o=o-1;g="right"};if(l&&c<11){n=hs(e.display.measure,n)}} -else{if(o>0){g=r="right"};var v;if(e.options.lineWrapping&&(v=u.getClientRects()).length>1){n=v[r=="right"?v.length-1:0]} -else{n=u.getBoundingClientRect()}};if(l&&c<9&&!o&&(!n||!n.left&&!n.right)){var h=u.parentNode.getClientRects()[0];if(h){n={left:h.left,right:h.left+xt(e.display),top:h.top,bottom:h.bottom}} -else{n=zr}};var m=n.top-t.rect.top,y=n.bottom-t.rect.top,C=(m+y)/2,p=t.view.measure.heights,a=0;for(;a<p.length-1;a++){if(C<p[a]){break}};var w=a?p[a-1]:0,x=p[a],d={left:(g=="right"?n.right:n.left)-t.rect.left,right:(g=="left"?n.left:n.right)-t.rect.left,top:w,bottom:x};if(!n.left&&!n.right){d.bogus=!0};if(!e.options.singleCursorHeightPerLine){d.rtop=m;d.rbottom=y};return d};function hs(e,t){if(!window.screen||screen.logicalXDPI==null||screen.logicalXDPI==screen.deviceXDPI||!zl(e)){return t};var i=screen.logicalXDPI/screen.deviceXDPI,r=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*i,right:t.right*i,top:t.top*r,bottom:t.bottom*r}};function Fn(e){if(e.measure){e.measure.cache={};e.measure.heights=null;if(e.rest){for(var t=0;t<e.rest.length;t++){e.measure.caches[t]={}}}}};function Pn(e){e.display.externalMeasure=null;re(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++){Fn(e.display.view[t])}};function wt(e){Pn(e);e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null;if(!e.options.lineWrapping){e.display.maxLineChanged=!0};e.display.lineNumChars=null};function En(){if(Kt&&Xt){return-(document.body.getBoundingClientRect().left-parseInt(getComputedStyle(document.body).marginLeft))};return window.pageXOffset||(document.documentElement||document.body).scrollLeft};function In(){if(Kt&&Xt){return-(document.body.getBoundingClientRect().top-parseInt(getComputedStyle(document.body).marginTop))};return window.pageYOffset||(document.documentElement||document.body).scrollTop};function ir(e){var i=0;if(e.widgets){for(var t=0;t<e.widgets.length;++t){if(e.widgets[t].above){i+=bt(e.widgets[t])}}};return i};function oi(e,t,i,r,n){if(!n){var a=ir(t);i.top+=a;i.bottom+=a};if(r=="line"){return i};if(!r){r="local"};var o=q(t);if(r=="local"){o+=ni(e.display)} -else{o-=e.display.viewOffset};if(r=="page"||r=="window"){var s=e.display.lineSpace.getBoundingClientRect();o+=s.top+(r=="window"?0:In());var l=s.left+(r=="window"?0:En());i.left+=l;i.right+=l};i.top+=o;i.bottom+=o;return i};function zn(e,t,i){if(i=="div"){return t};var r=t.left,n=t.top;if(i=="page"){r-=En();n-=In()} -else if(i=="local"||!i){var l=e.display.sizer.getBoundingClientRect();r+=l.left;n+=l.top};var o=e.display.lineSpace.getBoundingClientRect();return{left:r-o.left,top:n-o.top}};function rr(e,i,r,n,o){if(!n){n=t(e.doc,i.line)};return oi(e,n,Dn(e,n,i.ch,o),r)};function z(e,i,r,n,o,a){n=n||t(e.doc,i.line);if(!o){o=Ee(e,n)};function h(t,i){var l=X(e,o,t,i?"right":"left",a);if(i){l.left=l.right} -else{l.right=l.left};return oi(e,n,l,r)};var u=Z(n,e.doc.direction),l=i.ch,s=i.sticky;if(l>=n.text.length){l=n.text.length;s="before"} -else if(l<=0){l=0;s="after"};if(!u){return h(s=="before"?l-1:l,s=="before")};function d(e,t,i){var r=u[t],n=r.level==1;return h(i?e-1:e,n!=i)};var p=gt(u,l,s),f=nt,c=d(l,p,s=="before");if(f!=null){c.other=d(l,f,s!="before")};return c};function Rn(e,i){var r=0;i=o(e.doc,i);if(!e.options.lineWrapping){r=xt(e.display)*i.ch};var n=t(e.doc,i.line),l=q(n)+ni(e.display);return{left:r,right:r,top:l,bottom:l+n.height}};function nr(t,i,r,n,o){var l=e(t,i,r);l.xRel=o;if(n){l.outside=!0};return l};function or(e,i,r){var n=e.doc;r+=e.display.viewOffset;if(r<0){return nr(n.first,0,null,!0,-1)};var l=ye(n,r),c=n.first+n.size-1;if(l>c){return nr(n.first+n.size-1,t(n,c).text.length,null,!0,1)};if(i<0){i=0};var f=t(n,l);for(;;){var o=ds(e,f,l,i,r),s=pt(f),a=s&&s.find(0,!0);if(s&&(o.ch>a.from.ch||o.ch==a.from.ch&&o.xRel>0)){l=u(f=a.to.line)} -else{return o}}};function Bn(e,t,i,r){r-=ir(t);var n=t.text.length,o=ct(function(t){return X(e,i,t-1).bottom<=r},n,0);n=ct(function(t){return X(e,i,t).top>r},o,n);return{begin:o,end:n}};function Gn(e,t,i,r){if(!i){i=Ee(e,t)};var n=oi(e,t,X(e,i,r),"line").top;return Bn(e,t,i,n)};function lr(e,t,i,r){return e.bottom<=i?!1:e.top>i?!0:(r?e.left:e.right)>t};function ds(t,i,r,n,o){o-=q(i);var c=Ee(t,i),p=ir(i),g=0,v=i.text.length,s=!0,x=Z(i,t.doc.direction);if(x){var u=(t.options.lineWrapping?gs:ps)(t,i,r,c,x,n,o);s=u.level!=1;g=s?u.from:u.to-1;v=s?u.to:u.from-1};var b=null,a=null,l=ct(function(e){var i=X(t,c,e);i.top+=p;i.bottom+=p;if(!lr(i,n,o,!1)){return!1};if(i.top<=o&&i.left<=n){b=e;a=i};return!0},g,v),d,f,w=!1;if(a){var m=n-a.left<a.right-n,y=m==s;l=b+(y?0:1);f=y?"after":"before";d=m?a.left:a.right} -else{if(!s&&(l==v||l==g)){l++};f=l==0?"after":l==i.text.length?"before":(X(t,c,l-(s?1:0)).bottom+p<=o)==s?"after":"before";var h=z(t,e(r,l,f),"line",i,c);d=h.left;w=o<h.top||o>=h.bottom};l=Jr(i.text,l,1);return nr(r,l,f,w,n-d)};function ps(t,i,r,n,o,l,s){var u=ct(function(a){var u=o[a],f=u.level!=1;return lr(z(t,e(r,f?u.to:u.from,f?"before":"after"),"line",i,n),l,s,!0)},0,o.length-1),a=o[u];if(u>0){var f=a.level!=1,c=z(t,e(r,f?a.from:a.to,f?"after":"before"),"line",i,n);if(lr(c,l,s,!0)&&c.top>s){a=o[u-1]}};return a};function gs(e,t,i,r,n,l,u){var g=Bn(e,t,r,u),f=g.begin,a=g.end;if(/\s/.test(t.text.charAt(a-1))){a--};var o=null,p=null;for(var h=0;h<n.length;h++){var s=n[h];if(s.from>=a||s.to<=f){continue};var v=s.level!=1,c=X(e,r,v?Math.min(a,s.to)-1:Math.max(f,s.from)).right,d=c<l?l-c+1e9:c-l;if(!o||p>d){o=s;p=d}};if(!o){o=n[n.length-1]};if(o.from<f){o={from:f,to:o.to,level:o.level}};if(o.to>a){o={from:o.from,to:a,level:o.level}};return o};var fe;function Ce(e){if(e.cachedTextHeight!=null){return e.cachedTextHeight};if(fe==null){fe=i("pre");for(var r=0;r<49;++r){fe.appendChild(document.createTextNode("x"));fe.appendChild(i("br"))};fe.appendChild(document.createTextNode("x"))};W(e.measure,fe);var t=fe.offsetHeight/50;if(t>3){e.cachedTextHeight=t};re(e.measure);return t||1};function xt(e){if(e.cachedCharWidth!=null){return e.cachedCharWidth};var n=i("span","xxxxxxxxxx"),o=i("pre",[n]);W(e.measure,o);var r=n.getBoundingClientRect(),t=(r.right-r.left)/10;if(t>2){e.cachedCharWidth=t};return t||10};function sr(e){var i=e.display,n={},o={};var l=i.gutters.clientLeft;for(var t=i.gutters.firstChild,r=0;t;t=t.nextSibling,++r){n[e.options.gutters[r]]=t.offsetLeft+t.clientLeft+l;o[e.options.gutters[r]]=t.clientWidth};return{fixedPos:ar(i),gutterTotalWidth:i.gutters.offsetWidth,gutterLeft:n,gutterWidth:o,wrapperWidth:i.wrapper.clientWidth}};function ar(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left};function Un(e){var t=Ce(e.display),i=e.options.lineWrapping,r=i&&Math.max(5,e.display.scroller.clientWidth/xt(e.display)-3);return function(n){if(be(e.doc,n)){return 0};var l=0;if(n.widgets){for(var o=0;o<n.widgets.length;o++){if(n.widgets[o].height){l+=n.widgets[o].height}}};if(i){return l+(Math.ceil(n.text.length/r)||1)*t} -else{return l+t}}};function ur(e){var t=e.doc,i=Un(e);t.iter(function(e){var t=i(e);if(t!=e.height){U(e,t)}})};function Se(i,r,n,o){var d=i.display;if(!n&&Xi(r).getAttribute("cm-not-content")=="true"){return null};var u,f,c=d.lineSpace.getBoundingClientRect();try{u=r.clientX-c.left;f=r.clientY-c.top}catch(l){return null};var s=or(i,u,f),a;if(o&&s.xRel==1&&(a=t(i.doc,s.line).text).length==s.ch){var h=H(a,a.length,i.options.tabSize)-a.length;s=e(s.line,Math.max(0,Math.round((u-An(i.display).left)/xt(i.display))-h))};return s};function Le(e,t){if(t>=e.display.viewTo){return null};t-=e.display.viewFrom;if(t<0){return null};var r=e.display.view;for(var i=0;i<r.length;i++){t-=r[i].size;if(t<0){return i}}};function Ct(e){e.display.input.showSelection(e.display.input.prepareSelection())};function Vn(e,t){if(t===void 0)t=!0;var n=e.doc,o={};var s=o.cursors=document.createDocumentFragment(),a=o.selection=document.createDocumentFragment();for(var r=0;r<n.sel.ranges.length;r++){if(!t&&r==n.sel.primIndex){continue};var i=n.sel.ranges[r];if(i.from().line>=e.display.viewTo||i.to().line<e.display.viewFrom){continue};var l=i.empty();if(l||e.options.showCursorWhenSelecting){Kn(e,i.head,s)};if(!l){vs(e,i,a)}};return o};function Kn(e,t,r){var n=z(e,t,"div",null,null,!e.options.singleCursorHeightPerLine),l=r.appendChild(i("div","\u00a0","CodeMirror-cursor"));l.style.left=n.left+"px";l.style.top=n.top+"px";l.style.height=Math.max(0,n.bottom-n.top)*e.options.cursorHeight+"px";if(n.other){var o=r.appendChild(i("div","\u00a0","CodeMirror-cursor CodeMirror-secondarycursor"));o.style.display="";o.style.left=n.other.left+"px";o.style.top=n.other.top+"px";o.style.height=(n.other.bottom-n.other.top)*.85+"px"}};function li(e,t){return e.top-t.top||e.left-t.left};function vs(r,n,o){var y=r.display,p=r.doc,b=document.createDocumentFragment(),w=An(r.display),a=w.left,h=Math.max(y.sizerWidth,xe(r)-y.sizer.offsetLeft)-w.right,s=p.direction=="ltr";function u(e,t,r,n){if(t<0){t=0};t=Math.round(t);n=Math.round(n);b.appendChild(i("div",null,"CodeMirror-selected",("position: absolute; left: "+e+"px;\n top: "+t+"px; width: "+(r==null?h-e:r)+"px;\n height: "+(n-t)+"px")))};function v(i,n,o){var c=t(p,i),m=c.text.length,l,f;function v(t,n){return rr(r,e(i,t),"div",c,n)};function d(e,t,i){var n=Gn(r,c,null,e),o=(t=="ltr")==(i=="after")?"left":"right",l=i=="after"?n.begin:n.end-(/\s/.test(c.text.charAt(n.end-1))?2:1);return v(l,o)[o]};var g=Z(c,p.direction);Pl(g,n||0,o==null?m:o,function(e,t,i,r){var y=i=="ltr",c=v(e,y?"left":"right"),p=v(t-1,y?"right":"left"),x=n==null&&e==0,C=o==null&&t==m,k=r==0,T=!g||r==g.length-1;if(p.top-c.top<=3){var N=(s?x:C)&&k,O=(s?C:x)&&T,M=N?a:(y?c:p).left,A=O?h:(y?p:c).right;u(M,c.top,A-M,c.bottom)} -else{var b,S,w,L;if(y){b=s&&x&&k?a:c.left;S=s?h:d(e,i,"before");w=s?a:d(t,i,"after");L=s&&C&&T?h:p.right} -else{b=!s?a:d(e,i,"before");S=!s&&x&&k?h:c.right;w=!s&&C&&T?a:p.left;L=!s?h:d(t,i,"after")};u(b,c.top,S-b,c.bottom);if(c.bottom<p.top){u(a,c.bottom,null,p.top)};u(w,p.top,L-w,p.bottom)};if(!l||li(c,l)<0){l=c};if(li(p,l)<0){l=p};if(!f||li(c,f)<0){f=c};if(li(p,f)<0){f=p}});return{start:l,end:f}};var c=n.from(),d=n.to();if(c.line==d.line){v(c.line,c.ch,d.ch)} -else{var m=t(p,c.line),x=t(p,d.line),g=V(m)==V(x),l=v(c.line,c.ch,g?m.text.length+1:null).end,f=v(d.line,g?0:null,d.ch).start;if(g){if(l.top<f.top-2){u(l.right,l.top,null,l.bottom);u(a,f.top,f.left,f.bottom)} -else{u(l.right,l.top,f.left-l.right,l.bottom)}};if(l.bottom<f.top){u(a,l.bottom,null,f.top)}};o.appendChild(b)};function fr(e){if(!e.state.focused){return};var t=e.display;clearInterval(t.blinker);var i=!0;t.cursorDiv.style.visibility="";if(e.options.cursorBlinkRate>0){t.blinker=setInterval(function(){return t.cursorDiv.style.visibility=(i=!i)?"":"hidden"},e.options.cursorBlinkRate)} -else if(e.options.cursorBlinkRate<0){t.cursorDiv.style.visibility="hidden"}};function Xn(e){if(!e.state.focused){e.display.input.focus();cr(e)}};function jn(e){e.state.delayingBlurEvent=!0;setTimeout(function(){if(e.state.delayingBlurEvent){e.state.delayingBlurEvent=!1;St(e)}},100)};function cr(e,t){if(e.state.delayingBlurEvent){e.state.delayingBlurEvent=!1};if(e.options.readOnly=="nocursor"){return};if(!e.state.focused){p(e,"focus",e,t);e.state.focused=!0;ge(e.display.wrapper,"CodeMirror-focused");if(!e.curOp&&e.display.selForContextMenu!=e.doc.sel){e.display.input.reset();if(x){setTimeout(function(){return e.display.input.reset(!0)},20)}};e.display.input.receivedFocus()};fr(e)};function St(e,t){if(e.state.delayingBlurEvent){return};if(e.state.focused){p(e,"blur",e,t);e.state.focused=!1;de(e.display.wrapper,"CodeMirror-focused")};clearInterval(e.display.blinker);setTimeout(function(){if(!e.state.focused){e.display.shift=!1}},150)};function si(e){var r=e.display,f=r.lineDiv.offsetTop;for(var o=0;o<r.view.length;o++){var t=r.view[o],i=(void 0);if(t.hidden){continue};if(l&&c<8){var u=t.node.offsetTop+t.node.offsetHeight;i=u-f;f=u} -else{var a=t.node.getBoundingClientRect();i=a.bottom-a.top};var s=t.line.height-i;if(i<2){i=Ce(r)};if(s>.005||s<-.005){U(t.line,i);Yn(t.line);if(t.rest){for(var n=0;n<t.rest.length;n++){Yn(t.rest[n])}}}}};function Yn(e){if(e.widgets){for(var t=0;t<e.widgets.length;++t){var i=e.widgets[t],r=i.node.parentNode;if(r){i.height=r.offsetHeight}}}};function hr(e,i,r){var l=r&&r.top!=null?Math.max(0,r.top):e.scroller.scrollTop;l=Math.floor(l-ni(e));var u=r&&r.bottom!=null?r.bottom:l+e.wrapper.clientHeight,n=ye(i,l),o=ye(i,u);if(r&&r.ensure){var s=r.ensure.from.line,a=r.ensure.to.line;if(s<n){n=s;o=ye(i,q(t(i,s))+e.wrapper.clientHeight)} -else if(Math.min(a,i.lastLine())>=o){n=ye(i,q(t(i,a))-e.wrapper.clientHeight);o=a}};return{from:n,to:Math.max(o,n+1)}};function qn(e){var i=e.display,r=i.view;if(!i.alignWidgets&&(!i.gutters.firstChild||!e.options.fixedGutter)){return};var s=ar(i)-i.scroller.scrollLeft+e.doc.scrollLeft,a=i.gutters.offsetWidth,l=s+"px";for(var t=0;t<r.length;t++){if(!r[t].hidden){if(e.options.fixedGutter){if(r[t].gutter){r[t].gutter.style.left=l};if(r[t].gutterBackground){r[t].gutterBackground.style.left=l}};var o=r[t].alignable;if(o){for(var n=0;n<o.length;n++){o[n].style.left=l}}}};if(e.options.fixedGutter){i.gutters.style.left=(s+a)+"px"}};function Zn(e){if(!e.options.lineNumbers){return!1};var s=e.doc,r=Ei(e.options,s.first+s.size-1),t=e.display;if(r.length!=t.lineNumChars){var n=t.measure.appendChild(i("div",[i("div",r)],"CodeMirror-linenumber CodeMirror-gutter-elt")),o=n.firstChild.offsetWidth,l=n.offsetWidth-o;t.lineGutter.style.width="";t.lineNumInnerWidth=Math.max(o,t.lineGutter.offsetWidth-l)+1;t.lineNumWidth=t.lineNumInnerWidth+l;t.lineNumChars=t.lineNumInnerWidth?r.length:-1;t.lineGutter.style.width=t.lineNumWidth+"px";mr(e);return!0};return!1};function ms(e,t){if(v(e,"scrollCursorIntoView")){return};var o=e.display,l=o.sizer.getBoundingClientRect(),r=null;if(t.top+l.top<0){r=!0} -else if(t.bottom+l.top>(window.innerHeight||document.documentElement.clientHeight)){r=!1};if(r!=null&&!wl){var n=i("div","\u200b",null,("position: absolute;\n top: "+(t.top-o.viewOffset-ni(e.display))+"px;\n height: "+(t.bottom-t.top+K(e)+o.barHeight)+"px;\n left: "+(t.left)+"px; width: "+(Math.max(2,t.right-t.left))+"px;"));e.display.lineSpace.appendChild(n);n.scrollIntoView(r);e.display.lineSpace.removeChild(n)}};function ys(t,i,r,n){if(n==null){n=0};var u;if(!t.options.lineWrapping&&i==r){i=i.ch?e(i.line,i.sticky=="before"?i.ch-1:i.ch,"after"):i;r=i.sticky=="before"?e(i.line,i.ch+1,"before"):i};for(var f=0;f<5;f++){var a=!1,o=z(t,i),s=!r||r==i?o:z(t,r);u={left:Math.min(o.left,s.left),top:Math.min(o.top,s.top)-n,right:Math.max(o.left,s.left),bottom:Math.max(o.bottom,s.bottom)+n};var l=dr(t,u),c=t.doc.scrollTop,h=t.doc.scrollLeft;if(l.scrollTop!=null){kt(t,l.scrollTop);if(Math.abs(t.doc.scrollTop-c)>1){a=!0}};if(l.scrollLeft!=null){ke(t,l.scrollLeft);if(Math.abs(t.doc.scrollLeft-h)>1){a=!0}};if(!a){break}};return u};function bs(e,t){var i=dr(e,t);if(i.scrollTop!=null){kt(e,i.scrollTop)};if(i.scrollLeft!=null){ke(e,i.scrollLeft)}};function dr(e,t){var o=e.display,c=Ce(e.display);if(t.top<0){t.top=0};var s=e.curOp&&e.curOp.scrollTop!=null?e.curOp.scrollTop:o.scroller.scrollTop,n=er(e),i={};if(t.bottom-t.top>n){t.bottom=t.top+n};var f=e.doc.height+Ji(o),h=t.top<c,d=t.bottom>f-c;if(t.top<s){i.scrollTop=h?0:t.top} -else if(t.bottom>s+n){var u=Math.min(t.top,(d?f:t.bottom)-n);if(u!=s){i.scrollTop=u}};var a=e.curOp&&e.curOp.scrollLeft!=null?e.curOp.scrollLeft:o.scroller.scrollLeft,r=xe(e)-(e.options.fixedGutter?o.gutters.offsetWidth:0),l=t.right-t.left>r;if(l){t.right=t.left+r};if(t.left<10){i.scrollLeft=0} -else if(t.left<a){i.scrollLeft=Math.max(0,t.left-(l?0:10))} -else if(t.right>r+a-3){i.scrollLeft=t.right+(l?0:10)-r};return i};function pr(e,t){if(t==null){return};ai(e);e.curOp.scrollTop=(e.curOp.scrollTop==null?e.doc.scrollTop:e.curOp.scrollTop)+t};function Ie(e){ai(e);var t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}};function Lt(e,t,i){if(t!=null||i!=null){ai(e)};if(t!=null){e.curOp.scrollLeft=t};if(i!=null){e.curOp.scrollTop=i}};function ws(e,t){ai(e);e.curOp.scrollToPos=t};function ai(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var i=Rn(e,t.from),r=Rn(e,t.to);Qn(e,i,r,t.margin)}};function Qn(e,t,i,r){var n=dr(e,{left:Math.min(t.left,i.left),top:Math.min(t.top,i.top)-r,right:Math.max(t.right,i.right),bottom:Math.max(t.bottom,i.bottom)+r});Lt(e,n.scrollLeft,n.scrollTop)};function kt(e,t){if(Math.abs(e.doc.scrollTop-t)<2){return};if(!ie){vr(e,{top:t})};Jn(e,t,!0);if(ie){vr(e)};Mt(e,100)};function Jn(e,t,i){t=Math.min(e.display.scroller.scrollHeight-e.display.scroller.clientHeight,t);if(e.display.scroller.scrollTop==t&&!i){return};e.doc.scrollTop=t;e.display.scrollbars.setScrollTop(t);if(e.display.scroller.scrollTop!=t){e.display.scroller.scrollTop=t}};function ke(e,t,i,r){t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth);if((i?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)&&!r){return};e.doc.scrollLeft=t;qn(e);if(e.display.scroller.scrollLeft!=t){e.display.scroller.scrollLeft=t};e.display.scrollbars.setScrollLeft(t)};function Tt(e){var t=e.display,i=t.gutters.offsetWidth,r=Math.round(e.doc.height+Ji(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?i:0,docHeight:r,scrollHeight:r+K(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:i}};var ue=function(e,t,n){this.cm=n;var o=this.vert=i("div",[i("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),s=this.horiz=i("div",[i("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(o);e(s);r(o,"scroll",function(){if(o.clientHeight){t(o.scrollTop,"vertical")}});r(s,"scroll",function(){if(s.clientWidth){t(s.scrollLeft,"horizontal")}});this.checkedZeroWidth=!1;if(l&&c<8){this.horiz.style.minHeight=this.vert.style.minWidth="18px"}};ue.prototype.update=function(e){var i=e.scrollWidth>e.clientWidth+1,r=e.scrollHeight>e.clientHeight+1,t=e.nativeBarWidth;if(r){this.vert.style.display="block";this.vert.style.bottom=i?t+"px":"0";var o=e.viewHeight-(i?t:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+o)+"px"} -else{this.vert.style.display="";this.vert.firstChild.style.height="0"};if(i){this.horiz.style.display="block";this.horiz.style.right=r?t+"px":"0";this.horiz.style.left=e.barLeft+"px";var n=e.viewWidth-e.barLeft-(r?t:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+n)+"px"} -else{this.horiz.style.display="";this.horiz.firstChild.style.width="0"};if(!this.checkedZeroWidth&&e.clientHeight>0){if(t==0){this.zeroWidthHack()};this.checkedZeroWidth=!0};return{right:r?t:0,bottom:i?t:0}};ue.prototype.setScrollLeft=function(e){if(this.horiz.scrollLeft!=e){this.horiz.scrollLeft=e};if(this.disableHoriz){this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")}};ue.prototype.setScrollTop=function(e){if(this.vert.scrollTop!=e){this.vert.scrollTop=e};if(this.disableVert){this.enableZeroWidthBar(this.vert,this.disableVert,"vert")}};ue.prototype.zeroWidthHack=function(){var e=I&&!bl?"12px":"18px";this.horiz.style.height=this.vert.style.width=e;this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none";this.disableHoriz=new ce;this.disableVert=new ce};ue.prototype.enableZeroWidthBar=function(e,t,i){e.style.pointerEvents="auto";function r(){var n=e.getBoundingClientRect(),o=i=="vert"?document.elementFromPoint(n.right-1,(n.top+n.bottom)/2):document.elementFromPoint((n.right+n.left)/2,n.bottom-1);if(o!=e){e.style.pointerEvents="none"} -else{t.set(1000,r)}};t.set(1000,r)};ue.prototype.clear=function(){var e=this.horiz.parentNode;e.removeChild(this.horiz);e.removeChild(this.vert)};var it=function(){};it.prototype.update=function(){return{bottom:0,right:0}};it.prototype.setScrollLeft=function(){};it.prototype.setScrollTop=function(){};it.prototype.clear=function(){};function ze(e,t){if(!t){t=Tt(e)};var i=e.display.barWidth,n=e.display.barHeight;eo(e,t);for(var r=0;r<4&&i!=e.display.barWidth||n!=e.display.barHeight;r++){if(i!=e.display.barWidth&&e.options.lineWrapping){si(e)};eo(e,Tt(e));i=e.display.barWidth;n=e.display.barHeight}};function eo(e,t){var i=e.display,r=i.scrollbars.update(t);i.sizer.style.paddingRight=(i.barWidth=r.right)+"px";i.sizer.style.paddingBottom=(i.barHeight=r.bottom)+"px";i.heightForcer.style.borderBottom=r.bottom+"px solid transparent";if(r.right&&r.bottom){i.scrollbarFiller.style.display="block";i.scrollbarFiller.style.height=r.bottom+"px";i.scrollbarFiller.style.width=r.right+"px"} -else{i.scrollbarFiller.style.display=""};if(r.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter){i.gutterFiller.style.display="block";i.gutterFiller.style.height=r.bottom+"px";i.gutterFiller.style.width=t.gutterWidth+"px"} -else{i.gutterFiller.style.display=""}};var Ir={"native":ue,"null":it};function to(e){if(e.display.scrollbars){e.display.scrollbars.clear();if(e.display.scrollbars.addClass){de(e.display.wrapper,e.display.scrollbars.addClass)}};e.display.scrollbars=new Ir[e.options.scrollbarStyle](function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller);r(t,"mousedown",function(){if(e.state.focused){setTimeout(function(){return e.display.input.focus()},0)}});t.setAttribute("cm-not-content","true")},function(t,i){if(i=="horizontal"){ke(e,t)} -else{kt(e,t)}},e);if(e.display.scrollbars.addClass){ge(e.display.wrapper,e.display.scrollbars.addClass)}};var ul=0;function Te(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++ul};Jl(e.curOp)};function Me(e){var t=e.curOp;ts(t,function(e){for(var t=0;t<e.ops.length;t++){e.ops[t].cm.curOp=null};xs(e)})};function xs(e){var t=e.ops;for(var l=0;l<t.length;l++){Cs(t[l])};for(var o=0;o<t.length;o++){Ss(t[o])};for(var n=0;n<t.length;n++){Ls(t[n])};for(var r=0;r<t.length;r++){ks(t[r])};for(var i=0;i<t.length;i++){Ts(t[i])}};function Cs(e){var t=e.cm,i=t.display;Os(t);if(e.updateMaxLine){Ui(t)};e.mustUpdate=e.viewChanged||e.forceUpdate||e.scrollTop!=null||e.scrollToPos&&(e.scrollToPos.from.line<i.viewFrom||e.scrollToPos.to.line>=i.viewTo)||i.maxLineChanged&&t.options.lineWrapping;e.update=e.mustUpdate&&new Bt(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)};function Ss(e){e.updatedDisplay=e.mustUpdate&&gr(e.cm,e.update)};function Ls(e){var t=e.cm,i=t.display;if(e.updatedDisplay){si(t)};e.barMeasure=Tt(t);if(i.maxLineChanged&&!t.options.lineWrapping){e.adjustWidthTo=Dn(t,i.maxLine,i.maxLine.text.length).left+3;t.display.sizerWidth=e.adjustWidthTo;e.barMeasure.scrollWidth=Math.max(i.scroller.clientWidth,i.sizer.offsetLeft+e.adjustWidthTo+K(t)+t.display.barWidth);e.maxScrollLeft=Math.max(0,i.sizer.offsetLeft+e.adjustWidthTo-xe(t))};if(e.updatedDisplay||e.selectionChanged){e.preparedSelection=i.input.prepareSelection()}};function ks(e){var t=e.cm;if(e.adjustWidthTo!=null){t.display.sizer.style.minWidth=e.adjustWidthTo+"px";if(e.maxScrollLeft<t.doc.scrollLeft){ke(t,Math.min(t.display.scroller.scrollLeft,e.maxScrollLeft),!0)};t.display.maxLineChanged=!1};var i=e.focus&&e.focus==Y();if(e.preparedSelection){t.display.input.showSelection(e.preparedSelection,i)};if(e.updatedDisplay||e.startHeight!=t.doc.height){ze(t,e.barMeasure)};if(e.updatedDisplay){yr(t,e.barMeasure)};if(e.selectionChanged){fr(t)};if(t.state.focused&&e.updateInput){t.display.input.reset(e.typing)};if(i){Xn(e.cm)}};function Ts(e){var t=e.cm,s=t.display,a=t.doc;if(e.updatedDisplay){ro(t,e.update)};if(s.wheelStartX!=null&&(e.scrollTop!=null||e.scrollLeft!=null||e.scrollToPos)){s.wheelStartX=s.wheelStartY=null};if(e.scrollTop!=null){Jn(t,e.scrollTop,e.forceScroll)};if(e.scrollLeft!=null){ke(t,e.scrollLeft,!0,!0)};if(e.scrollToPos){var u=ys(t,o(a,e.scrollToPos.from),o(a,e.scrollToPos.to),e.scrollToPos.margin);ms(t,u)};var n=e.maybeHiddenMarkers,l=e.maybeUnhiddenMarkers;if(n){for(var r=0;r<n.length;++r){if(!n[r].lines.length){p(n[r],"hide")}}};if(l){for(var i=0;i<l.length;++i){if(l[i].lines.length){p(l[i],"unhide")}}};if(s.wrapper.offsetHeight){a.scrollTop=t.display.scroller.scrollTop};if(e.changeObjs){p(t,"changes",t,e.changeObjs)};if(e.update){e.update.finish()}};function N(e,t){if(e.curOp){return t()};Te(e);try{return t()}finally{Me(e)}};function m(e,t){return function(){if(e.curOp){return t.apply(e,arguments)};Te(e);try{return t.apply(e,arguments)}finally{Me(e)}}};function L(e){return function(){if(this.curOp){return e.apply(this,arguments)};Te(this);try{return e.apply(this,arguments)}finally{Me(this)}}};function y(e){return function(){var t=this.cm;if(!t||t.curOp){return e.apply(this,arguments)};Te(t);try{return e.apply(this,arguments)}finally{Me(t)}}};function M(e,t,i,r){if(t==null){t=e.doc.first};if(i==null){i=e.doc.first+e.doc.size};if(!r){r=0};var n=e.display;if(r&&i<n.viewTo&&(n.updateLineNumbers==null||n.updateLineNumbers>t)){n.updateLineNumbers=t};e.curOp.viewChanged=!0;if(t>=n.viewTo){if(te&&Bi(e.doc,t)<n.viewTo){le(e)}} -else if(i<=n.viewFrom){if(te&&fn(e.doc,i+r)>n.viewFrom){le(e)} -else{n.viewFrom+=r;n.viewTo+=r}} -else if(t<=n.viewFrom&&i>=n.viewTo){le(e)} -else if(t<=n.viewFrom){var u=ui(e,i,i+r,1);if(u){n.view=n.view.slice(u.index);n.viewFrom=u.lineN;n.viewTo+=r} -else{le(e)}} -else if(i>=n.viewTo){var a=ui(e,t,t,-1);if(a){n.view=n.view.slice(0,a.index);n.viewTo=a.lineN} -else{le(e)}} -else{var l=ui(e,t,t,-1),s=ui(e,i,i+r,1);if(l&&s){n.view=n.view.slice(0,l.index).concat(ri(e,l.lineN,s.lineN)).concat(n.view.slice(s.index));n.viewTo+=r} -else{le(e)}};var o=n.externalMeasured;if(o){if(i<o.lineN){o.lineN+=r} -else if(t<o.lineN+o.size){n.externalMeasured=null}}};function oe(e,t,i){e.curOp.viewChanged=!0;var r=e.display,n=e.display.externalMeasured;if(n&&t>=n.lineN&&t<n.lineN+n.size){r.externalMeasured=null};if(t<r.viewFrom||t>=r.viewTo){return};var o=r.view[Le(e,t)];if(o.node==null){return};var l=o.changes||(o.changes=[]);if(b(l,i)==-1){l.push(i)}};function le(e){e.display.viewFrom=e.display.viewTo=e.doc.first;e.display.view=[];e.display.viewOffset=0};function ui(e,t,i,r){var n=Le(e,t),s,o=e.display.view;if(!te||i==e.doc.first+e.doc.size){return{index:n,lineN:i}};var l=e.display.viewFrom;for(var a=0;a<n;a++){l+=o[a].size};if(l!=t){if(r>0){if(n==o.length-1){return null};s=(l+o[n].size)-t;n++} -else{s=l-t};t+=s;i+=s} -while(Bi(e.doc,i)!=i){if(n==(r<0?0:o.length-1)){return null};i+=r*o[n-(r<0?1:0)].size;n+=r};return{index:n,lineN:i}};function Ms(e,t,i){var r=e.display,n=r.view;if(n.length==0||t>=r.viewTo||i<=r.viewFrom){r.view=ri(e,t,i);r.viewFrom=t} -else{if(r.viewFrom>t){r.view=ri(e,t,r.viewFrom).concat(r.view)} -else if(r.viewFrom<t){r.view=r.view.slice(Le(e,t))};r.viewFrom=t;if(r.viewTo<i){r.view=r.view.concat(ri(e,r.viewTo,i))} -else if(r.viewTo>i){r.view=r.view.slice(0,Le(e,i))}};r.viewTo=i};function io(e){var r=e.display.view,n=0;for(var i=0;i<r.length;i++){var t=r[i];if(!t.hidden&&(!t.node||t.changes)){++n}};return n};function Mt(e,t){if(e.doc.highlightFrontier<e.display.viewTo){e.state.highlight.set(t,Ai(Ns,e))}};function Ns(e){var i=e.doc;if(i.highlightFrontier>=e.display.viewTo){return};var n=+new Date+e.options.workTime,t=mt(e,i.highlightFrontier),r=[];i.iter(t.line,Math.min(i.first+i.size,e.display.viewTo+500),function(o){if(t.line>=e.display.viewFrom){var u=o.styles,c=o.text.length>e.options.maxHighlightLength?we(i.mode,t.state):null,h=gn(e,o,t,!0);if(c){t.state=c};o.styles=h.styles;var s=o.styleClasses,l=h.classes;if(l){o.styleClasses=l} -else if(s){o.styleClasses=null};var f=!u||u.length!=o.styles.length||s!=l&&(!s||!l||s.bgClass!=l.bgClass||s.textClass!=l.textClass);for(var a=0;!f&&a<u.length;++a){f=u[a]!=o.styles[a]};if(f){r.push(t.line)};o.stateAfter=t.save();t.nextLine()} -else{if(o.text.length<=e.options.maxHighlightLength){qi(e,o.text,t)};o.stateAfter=t.line%5==0?t.save():null;t.nextLine()};if(+new Date>n){Mt(e,e.options.workDelay);return!0}});i.highlightFrontier=t.line;i.modeFrontier=Math.max(i.modeFrontier,t.line);if(r.length){N(e,function(){for(var t=0;t<r.length;t++){oe(e,r[t],"text")}})}};var Bt=function(e,t,i){var r=e.display;this.viewport=t;this.visible=hr(r,e.doc,t);this.editorIsHidden=!r.wrapper.offsetWidth;this.wrapperHeight=r.wrapper.clientHeight;this.wrapperWidth=r.wrapper.clientWidth;this.oldDisplayWidth=xe(e);this.force=i;this.dims=sr(e);this.events=[]};Bt.prototype.signal=function(e,t){if(F(e,t)){this.events.push(arguments)}};Bt.prototype.finish=function(){var t=this;for(var e=0;e<this.events.length;e++){p.apply(null,t.events[e])}};function Os(e){var t=e.display;if(!t.scrollbarsClipped&&t.scroller.offsetWidth){t.nativeBarWidth=t.scroller.offsetWidth-t.scroller.clientWidth;t.heightForcer.style.height=K(e)+"px";t.sizer.style.marginBottom=-t.nativeBarWidth+"px";t.sizer.style.borderRightWidth=K(e)+"px";t.scrollbarsClipped=!0}};function As(e){if(e.hasFocus()){return null};var r=Y();if(!r||!ne(e.display.lineDiv,r)){return null};var i={activeElt:r};if(window.getSelection){var t=window.getSelection();if(t.anchorNode&&t.extend&&ne(e.display.lineDiv,t.anchorNode)){i.anchorNode=t.anchorNode;i.anchorOffset=t.anchorOffset;i.focusNode=t.focusNode;i.focusOffset=t.focusOffset}};return i};function Ws(e){if(!e||!e.activeElt||e.activeElt==Y()){return};e.activeElt.focus();if(e.anchorNode&&ne(document.body,e.anchorNode)&&ne(document.body,e.focusNode)){var t=window.getSelection(),i=document.createRange();i.setEnd(e.anchorNode,e.anchorOffset);i.collapse(!1);t.removeAllRanges();t.addRange(i);t.extend(e.focusNode,e.focusOffset)}};function gr(e,i){var r=e.display,l=e.doc;if(i.editorIsHidden){le(e);return!1};if(!i.force&&i.visible.from>=r.viewFrom&&i.visible.to<=r.viewTo&&(r.updateLineNumbers==null||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&io(e)==0){return!1};if(Zn(e)){le(e);i.dims=sr(e)};var u=l.first+l.size,n=Math.max(i.visible.from-e.options.viewportMargin,l.first),o=Math.min(u,i.visible.to+e.options.viewportMargin);if(r.viewFrom<n&&n-r.viewFrom<20){n=Math.max(l.first,r.viewFrom)};if(r.viewTo>o&&r.viewTo-o<20){o=Math.min(u,r.viewTo)};if(te){n=Bi(e.doc,n);o=fn(e.doc,o)};var a=n!=r.viewFrom||o!=r.viewTo||r.lastWrapHeight!=i.wrapperHeight||r.lastWrapWidth!=i.wrapperWidth;Ms(e,n,o);r.viewOffset=q(t(e.doc,r.viewFrom));e.display.mover.style.top=r.viewOffset+"px";var s=io(e);if(!a&&s==0&&!i.force&&r.renderedView==r.view&&(r.updateLineNumbers==null||r.updateLineNumbers>=r.viewTo)){return!1};var f=As(e);if(s>4){r.lineDiv.style.display="none"};Ds(e,r.updateLineNumbers,i.dims);if(s>4){r.lineDiv.style.display=""};r.renderedView=r.view;Ws(f);re(r.cursorDiv);re(r.selectionDiv);r.gutters.style.height=r.sizer.style.minHeight=0;if(a){r.lastWrapHeight=i.wrapperHeight;r.lastWrapWidth=i.wrapperWidth;Mt(e,400)};r.updateLineNumbers=null;return!0};function ro(e,t){var i=t.viewport;for(var n=!0;;n=!1){if(!n||!e.options.lineWrapping||t.oldDisplayWidth==xe(e)){if(i&&i.top!=null){i={top:Math.min(e.doc.height+Ji(e.display)-er(e),i.top)}};t.visible=hr(e.display,e.doc,i);if(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo){break}};if(!gr(e,t)){break};si(e);var r=Tt(e);Ct(e);ze(e,r);yr(e,r);t.force=!1};t.signal(e,"update",e);if(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 vr(e,t){var i=new Bt(e,t);if(gr(e,i)){si(e);ro(e,i);var r=Tt(e);Ct(e);ze(e,r);yr(e,r);i.finish()}};function Ds(e,t,i){var s=e.display,d=e.options.lineNumbers,a=s.lineDiv,n=a.firstChild;function c(t){var i=t.nextSibling;if(x&&I&&e.display.currentWheelTarget==t){t.style.display="none"} -else{t.parentNode.removeChild(t)};return i};var f=s.view,o=s.viewFrom;for(var l=0;l<f.length;l++){var r=f[l];if(r.hidden){} -else if(!r.node||r.node.parentNode!=a){var h=ls(e,r,o,i);a.insertBefore(h,n)} -else{while(n!=r.node){n=c(n)};var u=d&&t!=null&&t<=o&&r.lineNumber;if(r.changes){if(b(r.changes,"gutter")>-1){u=!1};kn(e,r,o,i)};if(u){re(r.lineNumber);r.lineNumber.appendChild(document.createTextNode(Ei(e.options,o)))};n=r.node.nextSibling};o+=r.size} -while(n){n=c(n)}};function mr(e){var t=e.display.gutters.offsetWidth;e.display.sizer.style.marginLeft=t+"px"};function yr(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+K(e))+"px"};function no(e){var r=e.display.gutters,l=e.options.gutters;re(r);var t=0;for(;t<l.length;++t){var n=l[t],o=r.appendChild(i("div",null,"CodeMirror-gutter "+n));if(n=="CodeMirror-linenumbers"){e.display.lineGutter=o;o.style.width=(e.display.lineNumWidth||1)+"px"}};r.style.display=t?"":"none";mr(e)};function br(e){var t=b(e.gutters,"CodeMirror-linenumbers");if(t==-1&&e.lineNumbers){e.gutters=e.gutters.concat(["CodeMirror-linenumbers"])} -else if(t>-1&&!e.lineNumbers){e.gutters=e.gutters.slice(0);e.gutters.splice(t,1)}};var Rt=0,A=null;if(l){A=-.53} -else if(ie){A=15} -else if(Kt){A=-.7} -else if(Yr){A=-1/3};function oo(e){var i=e.wheelDeltaX,t=e.wheelDeltaY;if(i==null&&e.detail&&e.axis==e.HORIZONTAL_AXIS){i=e.detail};if(t==null&&e.detail&&e.axis==e.VERTICAL_AXIS){t=e.detail} -else if(t==null){t=e.wheelDelta};return{x:i,y:t}};function Hs(e){var t=oo(e);t.x*=A;t.y*=A;return t};function lo(e,t){var d=oo(t),l=d.x,n=d.y,i=e.display,r=i.scroller,p=r.scrollWidth>r.clientWidth,c=r.scrollHeight>r.clientHeight;if(!(l&&p||n&&c)){return};if(n&&I&&x){outer:for(var o=t.target,h=i.view;o!=r;o=o.parentNode){for(var f=0;f<h.length;f++){if(h[f].node==o){e.display.currentWheelTarget=o;break outer}}}};if(l&&!ie&&!E&&A!=null){if(n&&c){kt(e,Math.max(0,r.scrollTop+n*A))};ke(e,Math.max(0,r.scrollLeft+l*A));if(!n||(n&&c)){T(t)};i.wheelStartX=null;return};if(n&&A!=null){var a=n*A,s=e.doc.scrollTop,u=s+i.wrapper.clientHeight;if(a<0){s=Math.max(0,s+a-50)} -else{u=Math.min(e.doc.height,u+a+50)};vr(e,{top:s,bottom:u})};if(Rt<20){if(i.wheelStartX==null){i.wheelStartX=r.scrollLeft;i.wheelStartY=r.scrollTop;i.wheelDX=l;i.wheelDY=n;setTimeout(function(){if(i.wheelStartX==null){return};var e=r.scrollLeft-i.wheelStartX,t=r.scrollTop-i.wheelStartY,n=(t&&i.wheelDY&&t/i.wheelDY)||(e&&i.wheelDX&&e/i.wheelDX);i.wheelStartX=i.wheelStartY=null;if(!n){return};A=(A*Rt+n)/(Rt+1);++Rt},200)} -else{i.wheelDX+=l;i.wheelDY+=n}}};var O=function(e,t){this.ranges=e;this.primIndex=t};O.prototype.primary=function(){return this.ranges[this.primIndex]};O.prototype.equals=function(e){var n=this;if(e==this){return!0};if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length){return!1};for(var t=0;t<this.ranges.length;t++){var i=n.ranges[t],r=e.ranges[t];if(!Ii(i.anchor,r.anchor)||!Ii(i.head,r.head)){return!1}};return!0};O.prototype.deepCopy=function(){var t=this,i=[];for(var e=0;e<this.ranges.length;e++){i[e]=new s(zi(t.ranges[e].anchor),zi(t.ranges[e].head))};return new O(i,this.primIndex)};O.prototype.somethingSelected=function(){var t=this;for(var e=0;e<this.ranges.length;e++){if(!t.ranges[e].empty()){return!0}};return!1};O.prototype.contains=function(e,t){var o=this;if(!t){t=e};for(var i=0;i<this.ranges.length;i++){var r=o.ranges[i];if(n(t,r.from())>=0&&n(e,r.to())<=0){return i}};return-1};var s=function(e,t){this.anchor=e;this.head=t};s.prototype.from=function(){return Zt(this.anchor,this.head)};s.prototype.to=function(){return qt(this.anchor,this.head)};s.prototype.empty=function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch};function R(e,t){var f=e[t];e.sort(function(e,t){return n(e.from(),t.from())});t=b(e,f);for(var r=1;r<e.length;r++){var o=e[r],i=e[r-1];if(n(i.to(),o.from())>=0){var l=Zt(i.from(),o.from()),a=qt(i.to(),o.to()),u=i.empty()?o.from()==o.head:i.from()==i.head;if(r<=t){--t};e.splice(--r,2,new s(u?a:l,u?l:a))}};return new O(e,t)};function se(e,t){return new O([new s(e,t||e)],0)};function ae(t){if(!t.text){return t.to};return e(t.from.line+t.text.length-1,a(t.text).length+(t.text.length==1?t.from.ch:0))};function so(t,i){if(n(t,i.from)<0){return t};if(n(t,i.to)<=0){return ae(i)};var o=t.line+i.text.length-(i.to.line-i.from.line)-1,r=t.ch;if(t.line==i.to.line){r+=ae(i).ch-i.to.ch};return e(o,r)};function wr(e,t){var n=[];for(var i=0;i<e.sel.ranges.length;i++){var r=e.sel.ranges[i];n.push(new s(so(r.anchor,t),so(r.head,t)))};return R(n,e.sel.primIndex)};function ao(t,i,r){if(t.line==i.line){return e(r.line,t.ch-i.ch+r.ch)} -else{return e(r.line+(t.line-i.line),t.ch)}};function Fs(t,i,r){var c=[],a=e(t.first,0),h=a;for(var o=0;o<i.length;o++){var u=i[o],l=ao(u.from,a,h),f=ao(ae(u),a,h);a=u.to;h=f;if(r=="around"){var d=t.sel.ranges[o],p=n(d.head,d.anchor)<0;c[o]=new s(p?f:l,p?l:f)} -else{c[o]=new s(l,l)}};return new O(c,t.sel.primIndex)};function xr(e){e.doc.mode=ji(e.options,e.doc.modeOption);Nt(e)};function Nt(e){e.doc.iter(function(e){if(e.stateAfter){e.stateAfter=null};if(e.styles){e.styles=null}});e.doc.modeFrontier=e.doc.highlightFrontier=e.doc.first;Mt(e,100);e.state.modeGen++;if(e.curOp){M(e)}};function uo(e,t){return t.from.ch==0&&t.to.ch==0&&a(t.text)==""&&(!e.cm||e.cm.options.wholeLineUpdateBefore)};function Cr(e,i,r,n){function d(e){return r?r[e]:null};function c(e,t,r){Kl(e,t,r,n);w(e,"change",e,i)};function g(e,t){var r=[];for(var i=e;i<t;++i){r.push(new We(o[i],d(i),n))};return r};var l=i.from,u=i.to,o=i.text,s=t(e,l.line),f=t(e,u.line),v=a(o),p=d(o.length-1),h=u.line-l.line;if(i.full){e.insert(0,g(0,o.length));e.remove(o.length,e.size-o.length)} -else if(uo(e,i)){var y=g(0,o.length-1);c(f,f.text,p);if(h){e.remove(l.line,h)};if(y.length){e.insert(l.line,y)}} -else if(s==f){if(o.length==1){c(s,s.text.slice(0,l.ch)+v+s.text.slice(u.ch),p)} -else{var m=g(1,o.length-1);m.push(new We(v+s.text.slice(u.ch),p,n));c(s,s.text.slice(0,l.ch)+o[0],d(0));e.insert(l.line+1,m)}} -else if(o.length==1){c(s,s.text.slice(0,l.ch)+o[0]+f.text.slice(u.ch),d(0));e.remove(l.line+1,h)} -else{c(s,s.text.slice(0,l.ch)+o[0],d(0));c(f,v+f.text.slice(u.ch),p);var b=g(1,o.length-1);if(h>1){e.remove(l.line+1,h-1)};e.insert(l.line+1,b)};w(e,"change",e,i)};function Ne(e,t,i){function r(e,n,o){if(e.linked){for(var a=0;a<e.linked.length;++a){var l=e.linked[a];if(l.doc==n){continue};var s=o&&l.sharedHist;if(i&&!s){continue};t(l.doc,s);r(l.doc,e,s)}}};r(e,null,!0)};function fo(e,t){if(t.cm){throw new Error("This document is already in use.")};e.doc=t;t.cm=e;ur(e);xr(e);co(e);if(!e.options.lineWrapping){Ui(e)};e.options.mode=t.modeOption;M(e)};function co(e){;(e.doc.direction=="rtl"?ge:de)(e.display.lineDiv,"CodeMirror-rtl")};function Ps(e){N(e,function(){co(e);M(e)})};function fi(e){this.done=[];this.undone=[];this.undoDepth=Infinity;this.lastModTime=this.lastSelTime=0;this.lastOp=this.lastSelOp=null;this.lastOrigin=this.lastSelOrigin=null;this.generation=this.maxGeneration=e||1};function Sr(e,t){var i={from:zi(t.from),to:ae(t),text:me(e,t.from,t.to)};go(e,i,t.from.line,t.to.line+1);Ne(e,function(e){return go(e,i,t.from.line,t.to.line+1)},!0);return i};function ho(e){while(e.length){var t=a(e);if(t.ranges){e.pop()} -else{break}}};function Es(e,t){if(t){ho(e.done);return a(e.done)} -else if(e.done.length&&!a(e.done).ranges){return a(e.done)} -else if(e.done.length>1&&!e.done[e.done.length-2].ranges){e.done.pop();return a(e.done)}};function po(e,t,i,r){var o=e.history;o.undone.length=0;var f=+new Date,l,s;if((o.lastOp==r||o.lastOrigin==t.origin&&t.origin&&((t.origin.charAt(0)=="+"&&e.cm&&o.lastModTime>f-e.cm.options.historyEventDelay)||t.origin.charAt(0)=="*"))&&(l=Es(o,o.lastOp==r))){s=a(l.changes);if(n(t.from,t.to)==0&&n(t.from,s.to)==0){s.to=ae(t)} -else{l.changes.push(Sr(e,t))}} -else{var u=a(o.done);if(!u||!u.ranges){ci(e.sel,o.done)};l={changes:[Sr(e,t)],generation:o.generation};o.done.push(l);while(o.done.length>o.undoDepth){o.done.shift();if(!o.done[0].ranges){o.done.shift()}}};o.done.push(i);o.generation=++o.maxGeneration;o.lastModTime=o.lastSelTime=f;o.lastOp=o.lastSelOp=r;o.lastOrigin=o.lastSelOrigin=t.origin;if(!s){p(e,"historyAdded")}};function Is(e,t,i,r){var n=t.charAt(0);return n=="*"||n=="+"&&i.ranges.length==r.ranges.length&&i.somethingSelected()==r.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)};function zs(e,t,i,r){var n=e.history,o=r&&r.origin;if(i==n.lastSelOp||(o&&n.lastSelOrigin==o&&(n.lastModTime==n.lastSelTime&&n.lastOrigin==o||Is(e,o,a(n.done),t)))){n.done[n.done.length-1]=t} -else{ci(t,n.done)};n.lastSelTime=+new Date;n.lastSelOrigin=o;n.lastSelOp=i;if(r&&r.clearRedo!==!1){ho(n.undone)}};function ci(e,t){var i=a(t);if(!(i&&i.ranges&&i.equals(e))){t.push(e)}};function go(e,t,i,r){var n=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,i),Math.min(e.first+e.size,r),function(i){if(i.markedSpans){(n||(n=t["spans_"+e.id]={}))[o]=i.markedSpans};++o})};function Rs(e){if(!e){return null};var t;for(var i=0;i<e.length;++i){if(e[i].marker.explicitlyCleared){if(!t){t=e.slice(0,i)}} -else if(t){t.push(e[i])}};return!t?e:t.length?t:null};function Bs(e,t){var n=t["spans_"+e.id];if(!n){return null};var r=[];for(var i=0;i<t.text.length;++i){r.push(Rs(n[i]))};return r};function vo(e,t){var i=Bs(e,t),a=Ri(e,t);if(!i){return a};if(!a){return i};for(var n=0;n<i.length;++n){var o=i[n],r=a[n];if(o&&r){spans:for(var s=0;s<r.length;++s){var u=r[s];for(var l=0;l<o.length;++l){if(o[l].marker==u.marker){continue;spans}};o.push(u)}} -else if(r){i[n]=r}};return i};function Re(e,t,i){var f=[];for(var u=0;u<e.length;++u){var o=e[u];if(o.ranges){f.push(i?O.prototype.deepCopy.call(o):o);continue};var h=o.changes,s=[];f.push({changes:s});for(var l=0;l<h.length;++l){var r=h[l],c=(void 0);s.push({from:r.from,to:r.to,text:r.text});if(t){for(var n in r){if(c=n.match(/^spans_(\d+)$/)){if(b(t,Number(c[1]))>-1){a(s)[n]=r[n];delete r[n]}}}}}};return f};function Lr(e,t,i,r){if(r){var o=e.anchor;if(i){var l=n(t,o)<0;if(l!=(n(i,o)<0)){o=t;t=i} -else if(l!=(n(t,i)<0)){t=i}};return new s(o,t)} -else{return new s(i||t,t)}};function hi(e,t,i,r,n){if(n==null){n=e.cm&&(e.cm.display.shift||e.extend)};C(e,new O([Lr(e.sel.primary(),t,i,n)],0),r)};function mo(e,t,i){var n=[],l=e.cm&&(e.cm.display.shift||e.extend);for(var r=0;r<e.sel.ranges.length;r++){n[r]=Lr(e.sel.ranges[r],t[r],null,l)};var o=R(n,e.sel.primIndex);C(e,o,i)};function kr(e,t,i,r){var n=e.sel.ranges.slice(0);n[t]=i;C(e,R(n,e.sel.primIndex),r)};function yo(e,t,i,r){C(e,se(t,i),r)};function Gs(e,t,i){var r={ranges:t.ranges,update:function(t){var r=this;this.ranges=[];for(var i=0;i<t.length;i++){r.ranges[i]=new s(o(e,t[i].anchor),o(e,t[i].head))}},origin:i&&i.origin};p(e,"beforeSelectionChange",e,r);if(e.cm){p(e.cm,"beforeSelectionChange",e.cm,r)};if(r.ranges!=t.ranges){return R(r.ranges,r.ranges.length-1)} -else{return t}};function bo(e,t,i){var r=e.history.done,n=a(r);if(n&&n.ranges){r[r.length-1]=t;di(e,t,i)} -else{C(e,t,i)}};function C(e,t,i){di(e,t,i);zs(e,e.sel,e.cm?e.cm.curOp.id:NaN,i)};function di(e,t,i){if(F(e,"beforeSelectionChange")||e.cm&&F(e.cm,"beforeSelectionChange")){t=Gs(e,t,i)};var r=i&&i.bias||(n(t.primary().head,e.sel.primary().head)<0?-1:1);wo(e,Co(e,t,r,!0));if(!(i&&i.scroll===!1)&&e.cm){Ie(e.cm)}};function wo(e,t){if(t.equals(e.sel)){return};e.sel=t;if(e.cm){e.cm.curOp.updateInput=e.cm.curOp.selectionChanged=!0;cn(e.cm)};w(e,"cursorActivity",e)};function xo(e){wo(e,Co(e,e.sel,null,!1))};function Co(e,t,i,r){var o;for(var n=0;n<t.ranges.length;n++){var l=t.ranges[n],a=t.ranges.length==e.sel.ranges.length&&e.sel.ranges[n],u=Tr(e,l.anchor,a&&a.anchor,i,r),f=Tr(e,l.head,a&&a.head,i,r);if(o||u!=l.anchor||f!=l.head){if(!o){o=t.ranges.slice(0,n)};o[n]=new s(u,f)}};return o?R(o,t.primIndex):t};function Be(e,i,r,o,l){var f=t(e,i.line);if(f.markedSpans){for(var h=0;h<f.markedSpans.length;++h){var u=f.markedSpans[h],s=u.marker;if((u.from==null||(s.inclusiveLeft?u.from<=i.ch:u.from<i.ch))&&(u.to==null||(s.inclusiveRight?u.to>=i.ch:u.to>i.ch))){if(l){p(s,"beforeCursorEnter");if(s.explicitlyCleared){if(!f.markedSpans){break} -else{--h;continue}}};if(!s.atomic){continue};if(r){var a=s.find(o<0?1:-1),d=(void 0);if(o<0?s.inclusiveRight:s.inclusiveLeft){a=So(e,a,-o,a&&a.line==i.line?f:null)};if(a&&a.line==i.line&&(d=n(a,r))&&(o<0?d<0:d>0)){return Be(e,a,i,o,l)}};var c=s.find(o<0?-1:1);if(o<0?s.inclusiveLeft:s.inclusiveRight){c=So(e,c,o,c.line==i.line?f:null)};return c?Be(e,c,i,o,l):null}}};return i};function Tr(t,i,r,n,o){var l=n||1,s=Be(t,i,r,l,o)||(!o&&Be(t,i,r,l,!0))||Be(t,i,r,-l,o)||(!o&&Be(t,i,r,-l,!0));if(!s){t.cantEdit=!0;return e(t.first,0)};return s};function So(i,r,n,l){if(n<0&&r.ch==0){if(r.line>i.first){return o(i,e(r.line-1))} -else{return null}} -else if(n>0&&r.ch==(l||t(i,r.line)).text.length){if(r.line<i.first+i.size-1){return e(r.line+1,0)} -else{return null}} -else{return new e(r.line,r.ch+n)}};function Lo(t){t.setSelection(e(t.firstLine(),0),e(t.lastLine()),G)};function ko(e,t,i){var r={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){return r.canceled=!0}};if(i){r.update=function(t,i,n,l){if(t){r.from=o(e,t)};if(i){r.to=o(e,i)};if(n){r.text=n};if(l!==undefined){r.origin=l}}};p(e,"beforeChange",e,r);if(e.cm){p(e.cm,"beforeChange",e.cm,r)};if(r.canceled){return null};return{from:r.from,to:r.to,text:r.text,origin:r.origin}};function Ge(e,t,i){if(e.cm){if(!e.cm.curOp){return m(e.cm,Ge)(e,t,i)};if(e.cm.state.suppressEdits){return}};if(F(e,"beforeChange")||e.cm&&F(e.cm,"beforeChange")){t=ko(e,t,!0);if(!t){return}};var n=Gr&&!i&&Dl(e,t.from,t.to);if(n){for(var r=n.length-1;r>=0;--r){To(e,{from:n[r].from,to:n[r].to,text:r?[""]:t.text,origin:t.origin})}} -else{To(e,t)}};function To(e,t){if(t.text.length==1&&t.text[0]==""&&n(t.from,t.to)==0){return};var r=wr(e,t);po(e,t,r,e.cm?e.cm.curOp.id:NaN);Ot(e,t,r,Ri(e,t));var i=[];Ne(e,function(e,r){if(!r&&b(i,e.history)==-1){Ao(e.history,t);i.push(e.history)};Ot(e,t,null,Ri(e,t))})};function pi(e,t,i){if(e.cm&&e.cm.state.suppressEdits&&!i){return};var n=e.history,r,h=e.sel,o=t=="undo"?n.done:n.undone,u=t=="undo"?n.undone:n.done,l=0;for(;l<o.length;l++){r=o[l];if(i?r.ranges&&!r.equals(e.sel):!r.ranges){break}};if(l==o.length){return};n.lastOrigin=n.lastSelOrigin=null;for(;;){r=o.pop();if(r.ranges){ci(r,u);if(i&&!r.equals(e.sel)){C(e,r,{clearRedo:!1});return};h=r} -else{break}};var c=[];ci(h,u);u.push({changes:c,generation:n.generation});n.generation=r.generation||++n.maxGeneration;var d=F(e,"beforeChange")||e.cm&&F(e.cm,"beforeChange"),p=function(i){var n=r.changes[i];n.origin=t;if(d&&!ko(e,n,!1)){o.length=0;return{}};c.push(Sr(e,n));var s=i?wr(e,n):a(o);Ot(e,n,s,vo(e,n));if(!i&&e.cm){e.cm.scrollIntoView({from:n.from,to:ae(n)})};var l=[];Ne(e,function(e,t){if(!t&&b(l,e.history)==-1){Ao(e.history,n);l.push(e.history)};Ot(e,n,null,vo(e,n))})};for(var s=r.changes.length-1;s>=0;--s){var f=p(s);if(f)return f.v}};function Mo(t,i){if(i==0){return};t.first+=i;t.sel=new O(jt(t.sel.ranges,function(t){return new s(e(t.anchor.line+i,t.anchor.ch),e(t.head.line+i,t.head.ch))}),t.sel.primIndex);if(t.cm){M(t.cm,t.first,t.first-i,i);for(var n=t.cm.display,r=n.viewFrom;r<n.viewTo;r++){oe(t.cm,r,"gutter")}}};function Ot(i,r,n,o){if(i.cm&&!i.cm.curOp){return m(i.cm,Ot)(i,r,n,o)};if(r.to.line<i.first){Mo(i,r.text.length-1-(r.to.line-r.from.line));return};if(r.from.line>i.lastLine()){return};if(r.from.line<i.first){var s=r.text.length-1-(i.first-r.from.line);Mo(i,s);r={from:e(i.first,0),to:e(r.to.line+s,r.to.ch),text:[a(r.text)],origin:r.origin}};var l=i.lastLine();if(r.to.line>l){r={from:r.from,to:e(l,t(i,l).text.length),text:[r.text[0]],origin:r.origin}};r.removed=me(i,r.from,r.to);if(!n){n=wr(i,r)};if(i.cm){Us(i.cm,r,o)} -else{Cr(i,r,o)};di(i,n,G)};function Us(e,i,r){var o=e.doc,l=e.display,n=i.from,s=i.to,a=!1,f=n.line;if(!e.options.lineWrapping){f=u(V(t(o,n.line)));o.iter(f,s.line+1,function(e){if(e==l.maxLine){a=!0;return!0}})};if(o.sel.contains(i.from,i.to)>-1){cn(e)};Cr(o,i,r,Un(e));if(!e.options.lineWrapping){o.iter(f,n.line+i.text.length,function(e){var t=ti(e);if(t>l.maxLineLength){l.maxLine=e;l.maxLineLength=t;l.maxLineChanged=!0;a=!1}});if(a){e.curOp.updateMaxLine=!0}};Vl(o,n.line);Mt(e,400);var p=i.text.length-(s.line-n.line)-1;if(i.full){M(e)} -else if(n.line==s.line&&i.text.length==1&&!uo(e.doc,i)){oe(e,n.line,"text")} -else{M(e,n.line,s.line+1,p)};var h=F(e,"changes"),d=F(e,"change");if(d||h){var c={from:n,to:s,text:i.text,removed:i.removed,origin:i.origin};if(d){w(e,"change",e,c)};if(h){(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(c)}};e.display.selForContextMenu=null};function Ue(e,t,i,r,o){if(!r){r=i};if(n(r,i)<0){var l;(l=[r,i],i=l[0],r=l[1],l)};if(typeof t=="string"){t=e.splitLines(t)};Ge(e,{from:i,to:r,text:t,origin:o})};function No(e,t,i,r){if(i<e.line){e.line+=r} -else if(t<e.line){e.line=t;e.ch=0}};function Oo(t,i,r,n){for(var s=0;s<t.length;++s){var o=t[s],f=!0;if(o.ranges){if(!o.copied){o=t[s]=o.deepCopy();o.copied=!0};for(var a=0;a<o.ranges.length;a++){No(o.ranges[a].anchor,i,r,n);No(o.ranges[a].head,i,r,n)};continue};for(var u=0;u<o.changes.length;++u){var l=o.changes[u];if(r<l.from.line){l.from=e(l.from.line+n,l.from.ch);l.to=e(l.to.line+n,l.to.ch)} -else if(i<=l.to.line){f=!1;break}};if(!f){t.splice(0,s+1);s=0}}};function Ao(e,t){var i=t.from.line,r=t.to.line,n=t.text.length-(r-i)-1;Oo(e.done,i,r,n);Oo(e.undone,i,r,n)};function At(e,i,r,n){var o=i,l=i;if(typeof i=="number"){l=t(e,en(e,i))} -else{o=u(i)};if(o==null){return null};if(n(l,o)&&e.cm){oe(e.cm,o,r)};return l};function Wt(e){var r=this;this.lines=e;this.parent=null;var i=0;for(var t=0;t<e.length;++t){e[t].parent=r;i+=e[t].height};this.height=i};Wt.prototype={chunkSize:function(){return this.lines.length},removeInner:function(e,t){var n=this;for(var r=e,o=e+t;r<o;++r){var i=n.lines[r];n.height-=i.height;Xl(i);w(i,"delete")};this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,i){var n=this;this.height+=i;this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var r=0;r<t.length;++r){t[r].parent=n}},iterN:function(e,t,i){var n=this;for(var r=e+t;e<r;++e){if(i(n.lines[e])){return!0}}}};function Dt(e){var o=this;this.children=e;var r=0,n=0;for(var i=0;i<e.length;++i){var t=e[i];r+=t.chunkSize();n+=t.height;t.parent=o};this.size=r;this.height=n;this.parent=null};Dt.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){var l=this;this.size-=t;for(var n=0;n<this.children.length;++n){var i=l.children[n],r=i.chunkSize();if(e<r){var o=Math.min(t,r-e),a=i.height;i.removeInner(e,o);l.height-=a-i.height;if(r==o){l.children.splice(n--,1);i.parent=null};if((t-=o)==0){break};e=0} -else{e-=r}};if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof Wt))){var s=[];this.collapse(s);this.children=[new Wt(s)];this.children[0].parent=this}},collapse:function(e){var i=this;for(var t=0;t<this.children.length;++t){i.children[t].collapse(e)}},insertInner:function(e,t,i){var o=this;this.size+=t.length;this.height+=i;for(var n=0;n<this.children.length;++n){var r=o.children[n],u=r.chunkSize();if(e<=u){r.insertInner(e,t,i);if(r.lines&&r.lines.length>50){var a=r.lines.length%25+25;for(var s=a;s<r.lines.length;){var l=new Wt(r.lines.slice(s,s+=25));r.height-=l.height;o.children.splice(++n,0,l);l.parent=o};r.lines=r.lines.slice(0,a);o.maybeSpill()};break};e-=u}},maybeSpill:function(){if(this.children.length<=10){return};var e=this;do{var n=e.children.splice(e.children.length-5,5),t=new Dt(n);if(!e.parent){var i=new Dt(e.children);i.parent=e;e.children=[i,t];e=i} -else{e.size-=t.size;e.height-=t.height;var r=b(e.parent.children,e);e.parent.children.splice(r+1,0,t)};t.parent=e.parent} -while(e.children.length>10)e.parent.maybeSpill()},iterN:function(e,t,i){var s=this;for(var n=0;n<this.children.length;++n){var l=s.children[n],r=l.chunkSize();if(e<r){var o=Math.min(t,r-e);if(l.iterN(e,o,i)){return!0};if((t-=o)==0){break};e=0} -else{e-=r}}}};var tt=function(e,t,i){var n=this;if(i){for(var r in i){if(i.hasOwnProperty(r)){n[r]=i[r]}}};this.doc=e;this.node=t};tt.prototype.clear=function(){var l=this,e=this.doc.cm,t=this.line.widgets,i=this.line,n=u(i);if(n==null||!t){return};for(var r=0;r<t.length;++r){if(t[r]==l){t.splice(r--,1)}};if(!t.length){i.widgets=null};var o=bt(this);U(i,Math.max(0,i.height-o));if(e){N(e,function(){Wo(e,i,-o);oe(e,n,"widget")});w(e,"lineWidgetCleared",e,this,n)}};tt.prototype.changed=function(){var r=this,n=this.height,e=this.doc.cm,t=this.line;this.height=null;var i=bt(this)-n;if(!i){return};U(t,t.height+i);if(e){N(e,function(){e.curOp.forceUpdate=!0;Wo(e,t,i);w(e,"lineWidgetChanged",e,r,u(t))})}};Pe(tt);function Wo(e,t,i){if(q(t)<((e.curOp&&e.curOp.scrollTop)||e.doc.scrollTop)){pr(e,i)}};function Vs(e,t,i,r){var n=new tt(e,i,r),o=e.cm;if(o&&n.noHScroll){o.display.alignWidgets=!0};At(e,t,"widget",function(t){var i=t.widgets||(t.widgets=[]);if(n.insertAt==null){i.push(n)} -else{i.splice(Math.min(i.length-1,Math.max(0,n.insertAt)),0,n)};n.line=t;if(o&&!be(e,t)){var r=q(t)<e.scrollTop;U(t,t.height+bt(n));if(r){pr(o,n.height)};o.curOp.forceUpdate=!0};return!0});w(o,"lineWidgetAdded",o,n,typeof t=="number"?t:u(t));return n};var Er=0,ee=function(e,t){this.lines=[];this.type=t;this.doc=e;this.id=++Er};ee.prototype.clear=function(){var i=this;if(this.explicitlyCleared){return};var e=this.doc.cm,h=e&&!e.curOp;if(h){Te(e)};if(F(this,"clear")){var a=this.find();if(a){w(this,"clear",a.from,a.to)}};var n=null,s=null;for(var l=0;l<this.lines.length;++l){var t=i.lines[l],r=dt(t.markedSpans,i);if(e&&!i.collapsed){oe(e,u(t),"text")} -else if(e){if(r.to!=null){s=u(t)};if(r.from!=null){n=u(t)}};t.markedSpans=Nl(t.markedSpans,r);if(r.from==null&&i.collapsed&&!be(i.doc,t)&&e){U(t,Ce(e.display))}};if(e&&this.collapsed&&!e.options.lineWrapping){for(var o=0;o<this.lines.length;++o){var f=V(i.lines[o]),c=ti(f);if(c>e.display.maxLineLength){e.display.maxLine=f;e.display.maxLineLength=c;e.display.maxLineChanged=!0}}};if(n!=null&&e&&this.collapsed){M(e,n,s+1)};this.lines.length=0;this.explicitlyCleared=!0;if(this.atomic&&this.doc.cantEdit){this.doc.cantEdit=!1;if(e){xo(e.doc)}};if(e){w(e,"markerCleared",e,this,n,s)};if(h){Me(e)};if(this.parent){this.parent.clear()}};ee.prototype.find=function(t,i){var a=this;if(t==null&&this.type=="bookmark"){t=1};var o,s;for(var l=0;l<this.lines.length;++l){var r=a.lines[l],n=dt(r.markedSpans,a);if(n.from!=null){o=e(i?r:u(r),n.from);if(t==-1){return o}};if(n.to!=null){s=e(i?r:u(r),n.to);if(t==1){return s}}};return o&&{from:o,to:s}};ee.prototype.changed=function(){var r=this,i=this.find(-1,!0),t=this,e=this.doc.cm;if(!i||!e){return};N(e,function(){var n=i.line,a=u(i.line),l=tr(e,a);if(l){Fn(l);e.curOp.selectionChanged=e.curOp.forceUpdate=!0};e.curOp.updateMaxLine=!0;if(!be(t.doc,n)&&t.height!=null){var s=t.height;t.height=null;var o=bt(t)-s;if(o){U(n,n.height+o)}};w(e,"markerChanged",e,r)})};ee.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;if(!t.maybeHiddenMarkers||b(t.maybeHiddenMarkers,this)==-1){(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}};this.lines.push(e)};ee.prototype.detachLine=function(e){this.lines.splice(b(this.lines,e),1);if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}};Pe(ee);function Ve(e,t,i,o,s){if(o&&o.shared){return Ks(e,t,i,o,s)};if(e.cm&&!e.cm.curOp){return m(e.cm,Ve)(e,t,i,o,s)};var l=new ee(e,s),h=n(t,i);if(o){ve(o,l,!1)};if(h>0||h==0&&l.clearWhenEmpty!==!1){return l};if(l.replacedWith){l.collapsed=!0;l.widgetNode=Fe("span",[l.replacedWith],"CodeMirror-widget");if(!o.handleMouseEvents){l.widgetNode.setAttribute("cm-ignore-events","true")};if(o.insertLeft){l.widgetNode.insertLeft=!0}};if(l.collapsed){if(un(e,t.line,t,i,l)||t.line!=i.line&&un(e,i.line,t,i,l)){throw new Error("Inserting collapsed marker partially overlapping an existing one")};Ml()};if(l.addToHistory){po(e,{from:t,to:i,origin:"markText"},e.sel,NaN)};var u=t.line,a=e.cm,c;e.iter(u,i.line+1,function(e){if(a&&l.collapsed&&!a.options.lineWrapping&&V(e)==a.display.maxLine){c=!0};if(l.collapsed&&u!=t.line){U(e,0)};Ol(e,new Qt(l,u==t.line?t.ch:null,u==i.line?i.ch:null))++u});if(l.collapsed){e.iter(t.line,i.line+1,function(t){if(be(e,t)){U(t,0)}})};if(l.clearOnEnter){r(l,"beforeCursorEnter",function(){return l.clear()})};if(l.readOnly){Tl();if(e.history.done.length||e.history.undone.length){e.clearHistory()}};if(l.collapsed){l.id=++Er;l.atomic=!0};if(a){if(c){a.curOp.updateMaxLine=!0};if(l.collapsed){M(a,t.line,i.line+1)} -else if(l.className||l.title||l.startStyle||l.endStyle||l.css){for(var f=t.line;f<=i.line;f++){oe(a,f,"text")}};if(l.atomic){xo(a.doc)};w(a,"markerAdded",a,l)};return l};var et=function(e,t){var r=this;this.markers=e;this.primary=t;for(var i=0;i<e.length;++i){e[i].parent=r}};et.prototype.clear=function(){var t=this;if(this.explicitlyCleared){return};this.explicitlyCleared=!0;for(var e=0;e<this.markers.length;++e){t.markers[e].clear()};w(this,"clear")};et.prototype.find=function(e,t){return this.primary.find(e,t)};Pe(et);function Ks(e,t,i,r,n){r=ve(r);r.shared=!1;var l=[Ve(e,t,i,r,n)],s=l[0],u=r.widgetNode;Ne(e,function(e){if(u){r.widgetNode=u.cloneNode(!0)};l.push(Ve(e,o(e,t),o(e,i),r,n));for(var f=0;f<e.linked.length;++f){if(e.linked[f].isParent){return}};s=a(l)});return new et(l,s)};function Do(t){return t.findMarks(e(t.first,0),t.clipPos(e(t.lastLine())),function(e){return e.parent})};function Xs(e,t){for(var r=0;r<t.length;r++){var i=t[r],l=i.find(),s=e.clipPos(l.from),a=e.clipPos(l.to);if(n(s,a)){var o=Ve(e,s,a,i.primary,i.primary.type);i.markers.push(o);o.parent=i}}};function js(e){var i=function(t){var i=e[t],o=[i.primary.doc];Ne(i.primary.doc,function(e){return o.push(e)});for(var r=0;r<i.markers.length;r++){var n=i.markers[r];if(b(o,n.doc)==-1){n.parent=null;i.markers.splice(r--,1)}}};for(var t=0;t<e.length;t++)i(t)};var al=0,k=function(t,i,r,n,o){if(!(this instanceof k)){return new k(t,i,r,n,o)};if(r==null){r=0};Dt.call(this,[new Wt([new We("",null)])]);this.first=r;this.scrollTop=this.scrollLeft=0;this.cantEdit=!1;this.cleanGeneration=1;this.modeFrontier=this.highlightFrontier=r;var l=e(r,0);this.sel=se(l);this.history=new fi(null);this.id=++al;this.modeOption=i;this.lineSep=n;this.direction=(o=="rtl")?"rtl":"ltr";this.extend=!1;if(typeof t=="string"){t=this.splitLines(t)};Cr(this,{from:l,to:l,text:t});C(this,se(l),G)};k.prototype=Zr(Dt.prototype,{constructor:k,iter:function(e,t,i){if(i){this.iterN(e-this.first,t-e,i)} -else{this.iterN(this.first,this.first+this.size,e)}},insert:function(e,t){var r=0;for(var i=0;i<t.length;++i){r+=t[i].height};this.insertInner(e-this.first,t,r)},remove:function(e,t){this.removeInner(e-this.first,t)},getValue:function(e){var t=Pi(this,this.first,this.first+this.size);if(e===!1){return t};return t.join(e||this.lineSeparator())},setValue:y(function(i){var r=e(this.first,0),n=this.first+this.size-1;Ge(this,{from:r,to:e(n,t(this,n).text.length),text:this.splitLines(i),origin:"setValue",full:!0},!0);if(this.cm){Lt(this.cm,0,0)};C(this,se(r),G)}),replaceRange:function(e,t,i,r){t=o(this,t);i=i?o(this,i):t;Ue(this,e,t,i,r)},getRange:function(e,t,i){var r=me(this,o(this,e),o(this,t));if(i===!1){return r};return r.join(i||this.lineSeparator())},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},getLineHandle:function(e){if(ht(this,e)){return t(this,e)}},getLineNumber:function(e){return u(e)},getLineHandleVisualStart:function(e){if(typeof e=="number"){e=t(this,e)};return V(e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return o(this,e)},getCursor:function(e){var i=this.sel.primary(),t;if(e==null||e=="head"){t=i.head} -else if(e=="anchor"){t=i.anchor} -else if(e=="end"||e=="to"||e===!1){t=i.to()} -else{t=i.from()};return t},listSelections:function(){return this.sel.ranges},somethingSelected:function(){return this.sel.somethingSelected()},setCursor:y(function(t,i,r){yo(this,o(this,typeof t=="number"?e(t,i||0):t),null,r)}),setSelection:y(function(e,t,i){yo(this,o(this,e),o(this,t||e),i)}),extendSelection:y(function(e,t,i){hi(this,o(this,e),t&&o(this,t),i)}),extendSelections:y(function(e,t){mo(this,tn(this,e),t)}),extendSelectionsBy:y(function(e,t){var i=jt(this.sel.ranges,e);mo(this,tn(this,i),t)}),setSelections:y(function(e,t,i){var l=this;if(!e.length){return};var n=[];for(var r=0;r<e.length;r++){n[r]=new s(o(l,e[r].anchor),o(l,e[r].head))};if(t==null){t=Math.min(e.length-1,this.sel.primIndex)};C(this,R(n,t),i)}),addSelection:y(function(e,t,i){var r=this.sel.ranges.slice(0);r.push(new s(o(this,e),o(this,t||e)));C(this,R(r,r.length-1),i)}),getSelection:function(e){var o=this,r=this.sel.ranges,t;for(var i=0;i<r.length;i++){var n=me(o,r[i].from(),r[i].to());t=t?t.concat(n):n};if(e===!1){return t} -else{return t.join(e||this.lineSeparator())}},getSelections:function(e){var n=this,o=[],r=this.sel.ranges;for(var t=0;t<r.length;t++){var i=me(n,r[t].from(),r[t].to());if(e!==!1){i=i.join(e||n.lineSeparator())};o[t]=i};return o},replaceSelection:function(e,t,i){var n=[];for(var r=0;r<this.sel.ranges.length;r++){n[r]=e};this.replaceSelections(n,t,i||"+input")},replaceSelections:y(function(e,t,i){var a=this,n=[],u=this.sel;for(var r=0;r<u.ranges.length;r++){var s=u.ranges[r];n[r]={from:s.from(),to:s.to(),text:a.splitLines(e[r]),origin:i}};var l=t&&t!="end"&&Fs(this,n,t);for(var o=n.length-1;o>=0;o--){Ge(a,n[o])};if(l){bo(this,l)} -else if(this.cm){Ie(this.cm)}}),undo:y(function(){pi(this,"undo")}),redo:y(function(){pi(this,"redo")}),undoSelection:y(function(){pi(this,"undo",!0)}),redoSelection:y(function(){pi(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){var e=this.history,r=0,n=0;for(var i=0;i<e.done.length;i++){if(!e.done[i].ranges){++r}};for(var t=0;t<e.undone.length;t++){if(!e.undone[t].ranges){++n}};return{undo:r,redo:n}},clearHistory:function(){this.history=new fi(this.history.maxGeneration)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(e){if(e){this.history.lastOp=this.history.lastSelOp=this.history.lastOrigin=null};return this.history.generation},isClean:function(e){return this.history.generation==(e||this.cleanGeneration)},getHistory:function(){return{done:Re(this.history.done),undone:Re(this.history.undone)}},setHistory:function(e){var t=this.history=new fi(this.history.maxGeneration);t.done=Re(e.done.slice(0),null,!0);t.undone=Re(e.undone.slice(0),null,!0)},setGutterMarker:y(function(e,t,i){return At(this,e,"gutter",function(e){var r=e.gutterMarkers||(e.gutterMarkers={});r[t]=i;if(!i&&Qr(r)){e.gutterMarkers=null};return!0})}),clearGutter:y(function(e){var t=this;this.iter(function(i){if(i.gutterMarkers&&i.gutterMarkers[e]){At(t,i,"gutter",function(){i.gutterMarkers[e]=null;if(Qr(i.gutterMarkers)){i.gutterMarkers=null};return!0})}})}),lineInfo:function(e){var i;if(typeof e=="number"){if(!ht(this,e)){return null};i=e;e=t(this,e);if(!e){return null}} -else{i=u(e);if(i==null){return null}};return{line:i,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},addLineClass:y(function(e,t,i){return At(this,e,t=="gutter"?"gutter":"class",function(e){var r=t=="text"?"textClass":t=="background"?"bgClass":t=="gutter"?"gutterClass":"wrapClass";if(!e[r]){e[r]=i} -else if(ft(i).test(e[r])){return!1} -else{e[r]+=" "+i};return!0})}),removeLineClass:y(function(e,t,i){return At(this,e,t=="gutter"?"gutter":"class",function(e){var o=t=="text"?"textClass":t=="background"?"bgClass":t=="gutter"?"gutterClass":"wrapClass",n=e[o];if(!n){return!1} -else if(i==null){e[o]=null} -else{var r=n.match(ft(i));if(!r){return!1};var l=r.index+r[0].length;e[o]=n.slice(0,r.index)+(!r.index||l==n.length?"":" ")+n.slice(l)||null};return!0})}),addLineWidget:y(function(e,t,i){return Vs(this,e,t,i)}),removeLineWidget:function(e){e.clear()},markText:function(e,t,i){return Ve(this,o(this,e),o(this,t),i,i&&i.type||"range")},setBookmark:function(e,t){var i={replacedWith:t&&(t.nodeType==null?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1,shared:t&&t.shared,handleMouseEvents:t&&t.handleMouseEvents};e=o(this,e);return Ve(this,e,e,i,"bookmark")},findMarksAt:function(e){e=o(this,e);var l=[],n=t(this,e.line).markedSpans;if(n){for(var r=0;r<n.length;++r){var i=n[r];if((i.from==null||i.from<=e.ch)&&(i.to==null||i.to>=e.ch)){l.push(i.marker.parent||i.marker)}}};return l},findMarks:function(e,t,i){e=o(this,e);t=o(this,t);var n=[],r=e.line;this.iter(e.line,t.line+1,function(o){var a=o.markedSpans;if(a){for(var s=0;s<a.length;s++){var l=a[s];if(!(l.to!=null&&r==e.line&&e.ch>=l.to||l.from==null&&r!=e.line||l.from!=null&&r==t.line&&l.from>=t.ch)&&(!i||i(l.marker))){n.push(l.marker.parent||l.marker)}}};++r});return n},getAllMarks:function(){var e=[];this.iter(function(t){var r=t.markedSpans;if(r){for(var i=0;i<r.length;++i){if(r[i].from!=null){e.push(r[i].marker)}}}});return e},posFromIndex:function(t){var i,r=this.first,n=this.lineSeparator().length;this.iter(function(e){var o=e.text.length+n;if(o>t){i=t;return!0};t-=o++r});return o(this,e(r,i))},indexFromPos:function(e){e=o(this,e);var t=e.ch;if(e.line<this.first||e.ch<0){return 0};var i=this.lineSeparator().length;this.iter(this.first,e.line,function(e){t+=e.text.length+i});return t},copy:function(e){var t=new k(Pi(this,this.first,this.first+this.size),this.modeOption,this.first,this.lineSep,this.direction);t.scrollTop=this.scrollTop;t.scrollLeft=this.scrollLeft;t.sel=this.sel;t.extend=!1;if(e){t.history.undoDepth=this.history.undoDepth;t.setHistory(this.getHistory())};return t},linkedDoc:function(e){if(!e){e={}};var i=this.first,r=this.first+this.size;if(e.from!=null&&e.from>i){i=e.from};if(e.to!=null&&e.to<r){r=e.to};var t=new k(Pi(this,i,r),e.mode||this.modeOption,i,this.lineSep,this.direction);if(e.sharedHist){t.history=this.history}(this.linked||(this.linked=[])).push({doc:t,sharedHist:e.sharedHist});t.linked=[{doc:this,isParent:!0,sharedHist:e.sharedHist}];Xs(t,Do(this));return t},unlinkDoc:function(e){var i=this;if(e instanceof h){e=e.doc};if(this.linked){for(var t=0;t<this.linked.length;++t){var n=i.linked[t];if(n.doc!=e){continue};i.linked.splice(t,1);e.unlinkDoc(i);js(Do(i));break}};if(e.history==this.history){var r=[e.id];Ne(e,function(e){return r.push(e.id)},!0);e.history=new fi(null);e.history.done=Re(this.history.done,r);e.history.undone=Re(this.history.undone,r)}},iterLinkedDocs:function(e){Ne(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm},splitLines:function(e){if(this.lineSep){return e.split(this.lineSep)};return Si(e)},lineSeparator:function(){return this.lineSep||"\n"},setDirection:y(function(e){if(e!="rtl"){e="ltr"};if(e==this.direction){return};this.direction=e;this.iter(function(e){return e.order=null});if(this.cm){Ps(this.cm)}})});k.prototype.eachLine=k.prototype.iter;var Pr=0;function Ys(e){var t=this;Ho(t);if(v(t,e)||Q(t.display,e)){return};T(e);if(l){Pr=+new Date};var r=Se(t,e,!0),u=e.dataTransfer.files;if(!r||t.isReadOnly()){return};if(u&&u.length&&window.FileReader&&window.File){var f=u.length,h=Array(f),d=0,p=function(e,i){if(t.options.allowDropFileTypes&&b(t.options.allowDropFileTypes,e.type)==-1){return};var n=new FileReader;n.onload=m(t,function(){var e=n.result;if(/[\x00-\x08\x0e-\x1f]{2}/.test(e)){e=""};h[i]=e;if(++d==f){r=o(t.doc,r);var l={from:r,to:r,text:t.doc.splitLines(h.join(t.doc.lineSeparator())),origin:"paste"};Ge(t.doc,l);bo(t.doc,se(r,ae(l)))}});n.readAsText(e)};for(var a=0;a<f;++a){p(u[a],a)}} -else{if(t.state.draggingText&&t.doc.sel.contains(r)>-1){t.state.draggingText(e);setTimeout(function(){return t.display.input.focus()},20);return};try{var c=e.dataTransfer.getData("Text");if(c){var n;if(t.state.draggingText&&!t.state.draggingText.copy){n=t.listSelections()};di(t.doc,se(r,r));if(n){for(var s=0;s<n.length;++s){Ue(t.doc,"",n[s].anchor,n[s].head,"drag")}};t.replaceSelection(c,"around","paste");t.display.input.focus()}}catch(i){}}};function qs(e,t){if(l&&(!e.state.draggingText||+new Date-Pr<100)){vt(t);return};if(v(e,t)||Q(e.display,t)){return};t.dataTransfer.setData("Text",e.getSelection());t.dataTransfer.effectAllowed="copyMove";if(t.dataTransfer.setDragImage&&!Yr){var r=i("img",null,null,"position: fixed; left: 0; top: 0;");r.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";if(E){r.width=r.height=1;e.display.wrapper.appendChild(r);r._top=r.offsetTop};t.dataTransfer.setDragImage(r,0,0);if(E){r.parentNode.removeChild(r)}}};function Zs(e,t){var n=Se(e,t);if(!n){return};var r=document.createDocumentFragment();Kn(e,n,r);if(!e.display.dragCursor){e.display.dragCursor=i("div",null,"CodeMirror-cursors CodeMirror-dragcursors");e.display.lineSpace.insertBefore(e.display.dragCursor,e.display.cursorDiv)};W(e.display.dragCursor,r)};function Ho(e){if(e.display.dragCursor){e.display.lineSpace.removeChild(e.display.dragCursor);e.display.dragCursor=null}};function Fo(e){if(!document.getElementsByClassName){return};var r=document.getElementsByClassName("CodeMirror");for(var t=0;t<r.length;t++){var i=r[t].CodeMirror;if(i){e(i)}}};var Fr=!1;function Qs(){if(Fr){return};Js();Fr=!0};function Js(){var e;r(window,"resize",function(){if(e==null){e=setTimeout(function(){e=null;Fo(ea)},100)}});r(window,"blur",function(){return Fo(St)})};function ea(e){var t=e.display;if(t.lastWrapHeight==t.wrapper.clientHeight&&t.lastWrapWidth==t.wrapper.clientWidth){return};t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null;t.scrollbarsClipped=!1;e.setSize()};var J={3:"Enter",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",61:"=",91:"Mod",92:"Mod",93:"Mod",106:"*",107:"=",109:"-",110:".",111:"/",127:"Delete",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"};for(var Je=0;Je<10;Je++){J[Je+48]=J[Je+96]=String(Je)};for(var zt=65;zt<=90;zt++){J[zt]=String.fromCharCode(zt)};for(var Qe=1;Qe<=12;Qe++){J[Qe+111]=J[Qe+63235]="F"+Qe};var j={};j.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"};j.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"};j.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"};j.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"]};j["default"]=I?j.macDefault:j.pcDefault;function ta(e){var i=e.split(/-(?!$)/);e=i[i.length-1];var n,o,l,s;for(var r=0;r<i.length-1;r++){var t=i[r];if(/^(cmd|meta|m)$/i.test(t)){s=!0} -else if(/^a(lt)?$/i.test(t)){n=!0} -else if(/^(c|ctrl|control)$/i.test(t)){o=!0} -else if(/^s(hift)?$/i.test(t)){l=!0} -else{throw new Error("Unrecognized modifier name: "+t)}};if(n){e="Alt-"+e};if(o){e="Ctrl-"+e};if(s){e="Cmd-"+e};if(l){e="Shift-"+e};return e};function ia(e){var l={};for(var t in e){if(e.hasOwnProperty(t)){var u=e[t];if(/^(name|fallthrough|(de|at)tach)$/.test(t)){continue};if(u=="..."){delete e[t];continue};var o=jt(t.split(" "),ta);for(var n=0;n<o.length;n++){var r=(void 0),i=(void 0);if(n==o.length-1){i=o.join(" ");r=u} -else{i=o.slice(0,n+1).join(" ");r="..."};var a=l[i];if(!a){l[i]=r} -else if(a!=r){throw new Error("Inconsistent bindings for "+i)}};delete e[t]}};for(var s in l){e[s]=l[s]};return e};function Ke(e,t,i,r){t=gi(t);var n=t.call?t.call(e,r):t[e];if(n===!1){return"nothing"};if(n==="..."){return"multi"};if(n!=null&&i(n)){return"handled"};if(t.fallthrough){if(Object.prototype.toString.call(t.fallthrough)!="[object Array]"){return Ke(e,t.fallthrough,i,r)};for(var o=0;o<t.fallthrough.length;o++){var l=Ke(e,t.fallthrough[o],i,r);if(l){return l}}}};function Po(e){var t=typeof e=="string"?e:J[e.keyCode];return t=="Ctrl"||t=="Alt"||t=="Shift"||t=="Mod"};function Eo(e,t,i){var r=e;if(t.altKey&&r!="Alt"){e="Alt-"+e};if((Vr?t.metaKey:t.ctrlKey)&&r!="Ctrl"){e="Ctrl-"+e};if((Vr?t.ctrlKey:t.metaKey)&&r!="Cmd"){e="Cmd-"+e};if(!i&&t.shiftKey&&r!="Shift"){e="Shift-"+e};return e};function Io(e,t){if(E&&e.keyCode==34&&e["char"]){return!1};var i=J[e.keyCode];if(i==null||e.altGraphKey){return!1};return Eo(i,e,t)};function gi(e){return typeof e=="string"?j[e]:e};function Xe(e,t){var s=e.doc.sel.ranges,i=[];for(var o=0;o<s.length;o++){var r=t(s[o]);while(i.length&&n(r.from,a(i).to)<=0){var l=i.pop();if(n(l.from,r.from)<0){r.from=l.from;break}};i.push(r)};N(e,function(){for(var t=i.length-1;t>=0;t--){Ue(e.doc,"",i[t].from,i[t].to,"+delete")};Ie(e)})};function Mr(e,t,i){var r=Jr(e.text,t+i,i);return r<0||r>e.text.length?null:r};function Nr(t,i,r){var n=Mr(t,i.ch,r);return n==null?null:new e(i.line,n,r<0?"after":"before")};function Or(t,i,r,n,o){if(t){var u=Z(r,i.doc.direction);if(u){var s=o<0?a(u):u[0],d=(o<0)==(s.level==1),c=d?"after":"before",l;if(s.level>0||i.doc.direction=="rtl"){var f=Ee(i,r);l=o<0?r.text.length-1:0;var h=X(i,f,l).top;l=ct(function(e){return X(i,f,e).top==h},(o<0)==(s.level==1)?s.from:s.to-1,l);if(c=="before"){l=Mr(r,l,1)}} -else{l=o<0?s.to:s.from};return new e(n,l,c)}};return new e(n,o<0?r.text.length:0,o<0?"before":"after")};function ra(t,i,r,n){var a=Z(i,t.doc.direction);if(!a){return Nr(i,r,n)};if(r.ch>=i.text.length){r.ch=i.text.length;r.sticky="before"} -else if(r.ch<=0){r.ch=0;r.sticky="after"};var v=gt(a,r.ch,r.sticky),o=a[v];if(t.doc.direction=="ltr"&&o.level%2==0&&(n>0?o.to>r.ch:o.from<r.ch)){return Nr(i,r,n)};var s=function(t,r){return Mr(i,t instanceof e?t.ch:t,r)},d,g=function(e){if(!t.options.lineWrapping){return{begin:0,end:i.text.length}};d=d||Ee(t,i);return Gn(t,i,d,e)},f=g(r.sticky=="before"?s(r,-1):r.ch);if(t.doc.direction=="rtl"||o.level==1){var h=(o.level==1)==(n<0),l=s(r,h?1:-1);if(l!=null&&(!h?l>=o.from&&l>=f.begin:l<=o.to&&l<=f.end)){var m=h?"before":"after";return new e(r.line,l,m)}};var p=function(t,i,n){var f=function(t,i){return i?new e(r.line,s(t,1),"before"):new e(r.line,t,"after")};for(;t>=0&&t<a.length;t+=i){var l=a[t],u=(i>0)==(l.level!=1),o=u?n.begin:s(n.end,-1);if(l.from<=o&&o<l.to){return f(o,u)};o=u?l.from:s(l.to,-1);if(n.begin<=o&&o<n.end){return f(o,u)}}},u=p(v+n,n,f);if(u){return u};var c=n>0?f.end:s(f.begin,-1);if(c!=null&&!(n>0&&c==i.text.length)){u=p(n>0?0:a.length-1,n,g(c));if(u){return u}};return null};var Ze={selectAll:Lo,singleSelection:function(e){return e.setSelection(e.getCursor("anchor"),e.getCursor("head"),G)},killLine:function(i){return Xe(i,function(r){if(r.empty()){var n=t(i.doc,r.head.line).text.length;if(r.head.ch==n&&r.head.line<i.lastLine()){return{from:r.head,to:e(r.head.line+1,0)}} -else{return{from:r.head,to:e(r.head.line,n)}}} -else{return{from:r.from(),to:r.to()}}})},deleteLine:function(t){return Xe(t,function(i){return({from:e(i.from().line,0),to:o(t.doc,e(i.to().line+1,0))})})},delLineLeft:function(t){return Xe(t,function(t){return({from:e(t.from().line,0),to:t.from()})})},delWrappedLineLeft:function(e){return Xe(e,function(t){var i=e.charCoords(t.head,"div").top+5,r=e.coordsChar({left:0,top:i},"div");return{from:r,to:t.from()}})},delWrappedLineRight:function(e){return Xe(e,function(t){var i=e.charCoords(t.head,"div").top+5,r=e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:i},"div");return{from:t.from(),to:r}})},undo:function(e){return e.undo()},redo:function(e){return e.redo()},undoSelection:function(e){return e.undoSelection()},redoSelection:function(e){return e.redoSelection()},goDocStart:function(t){return t.extendSelection(e(t.firstLine(),0))},goDocEnd:function(t){return t.extendSelection(e(t.lastLine()))},goLineStart:function(e){return e.extendSelectionsBy(function(t){return zo(e,t.head.line)},{origin:"+move",bias:1})},goLineStartSmart:function(e){return e.extendSelectionsBy(function(t){return Ro(e,t.head)},{origin:"+move",bias:1})},goLineEnd:function(e){return e.extendSelectionsBy(function(t){return na(e,t.head.line)},{origin:"+move",bias:-1})},goLineRight:function(e){return e.extendSelectionsBy(function(t){var i=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:i},"div")},ot)},goLineLeft:function(e){return e.extendSelectionsBy(function(t){var i=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:i},"div")},ot)},goLineLeftSmart:function(e){return e.extendSelectionsBy(function(t){var r=e.cursorCoords(t.head,"div").top+5,i=e.coordsChar({left:0,top:r},"div");if(i.ch<e.getLine(i.line).search(/\S/)){return Ro(e,t.head)};return i},ot)},goLineUp:function(e){return e.moveV(-1,"line")},goLineDown:function(e){return e.moveV(1,"line")},goPageUp:function(e){return e.moveV(-1,"page")},goPageDown:function(e){return e.moveV(1,"page")},goCharLeft:function(e){return e.moveH(-1,"char")},goCharRight:function(e){return e.moveH(1,"char")},goColumnLeft:function(e){return e.moveH(-1,"column")},goColumnRight:function(e){return e.moveH(1,"column")},goWordLeft:function(e){return e.moveH(-1,"word")},goGroupRight:function(e){return e.moveH(1,"group")},goGroupLeft:function(e){return e.moveH(-1,"group")},goWordRight:function(e){return e.moveH(1,"word")},delCharBefore:function(e){return e.deleteH(-1,"char")},delCharAfter:function(e){return e.deleteH(1,"char")},delWordBefore:function(e){return e.deleteH(-1,"word")},delWordAfter:function(e){return e.deleteH(1,"word")},delGroupBefore:function(e){return e.deleteH(-1,"group")},delGroupAfter:function(e){return e.deleteH(1,"group")},indentAuto:function(e){return e.indentSelection("smart")},indentMore:function(e){return e.indentSelection("add")},indentLess:function(e){return e.indentSelection("subtract")},insertTab:function(e){return e.replaceSelection("\t")},insertSoftTab:function(e){var n=[],o=e.listSelections(),i=e.options.tabSize;for(var t=0;t<o.length;t++){var r=o[t].from(),l=H(e.getLine(r.line),r.ch,i);n.push(Di(i-l%i))};e.replaceSelections(n)},defaultTab:function(e){if(e.somethingSelected()){e.indentSelection("add")} -else{e.execCommand("insertTab")}},transposeChars:function(i){return N(i,function(){var a=i.listSelections(),u=[];for(var l=0;l<a.length;l++){if(!a[l].empty()){continue};var r=a[l].head,n=t(i.doc,r.line).text;if(n){if(r.ch==n.length){r=new e(r.line,r.ch-1)};if(r.ch>0){r=new e(r.line,r.ch+1);i.replaceRange(n.charAt(r.ch-1)+n.charAt(r.ch-2),e(r.line,r.ch-2),r,"+transpose")} -else if(r.line>i.doc.first){var o=t(i.doc,r.line-1).text;if(o){r=new e(r.line,1);i.replaceRange(n.charAt(0)+i.doc.lineSeparator()+o.charAt(o.length-1),e(r.line-1,o.length-1),r,"+transpose")}}};u.push(new s(r,r))};i.setSelections(u)})},newlineAndIndent:function(e){return N(e,function(){var t=e.listSelections();for(var i=t.length-1;i>=0;i--){e.replaceRange(e.doc.lineSeparator(),t[i].anchor,t[i].head,"+input")};t=e.listSelections();for(var r=0;r<t.length;r++){e.indentLine(t[r].from().line,null,!0)};Ie(e)})},openLine:function(e){return e.replaceSelection("\n","start")},toggleOverwrite:function(e){return e.toggleOverwrite()}};function zo(e,i){var n=t(e.doc,i),r=V(n);if(r!=n){i=u(r)};return Or(!0,e,r,i,1)};function na(e,i){var r=t(e.doc,i),n=Hl(r);if(n!=r){i=u(n)};return Or(!0,e,r,i,-1)};function Ro(i,r){var n=zo(i,r.line),l=t(i.doc,n.line),s=Z(l,i.doc.direction);if(!s||s[0].level==0){var o=Math.max(0,l.text.search(/\S/)),a=r.line==n.line&&r.ch<=o&&r.ch;return e(n.line,a?0:o,n.sticky)};return n};function vi(e,t,i){if(typeof t=="string"){t=Ze[t];if(!t){return!1}};e.display.input.ensurePolled();var n=e.display.shift,r=!1;try{if(e.isReadOnly()){e.state.suppressEdits=!0};if(i){e.display.shift=!1};r=t(e)!=Vt}finally{e.display.shift=n;e.state.suppressEdits=!1};return r};function oa(e,t,i){for(var r=0;r<e.state.keyMaps.length;r++){var n=Ke(t,e.state.keyMaps[r],i,e);if(n){return n}};return(e.options.extraKeys&&Ke(t,e.options.extraKeys,i,e))||Ke(t,e.options.keyMap,i,e)};var sl=new ce;function Ht(e,t,i,r){var n=e.state.keySeq;if(n){if(Po(t)){return"handled"};if(/'$/.test(t)){e.state.keySeq=null} -else{sl.set(50,function(){if(e.state.keySeq==n){e.state.keySeq=null;e.display.input.reset()}})};if(Bo(e,n+" "+t,i,r)){return!0}};return Bo(e,t,i,r)};function Bo(e,t,i,r){var n=oa(e,t,r);if(n=="multi"){e.state.keySeq=t};if(n=="handled"){w(e,"keyHandled",e,t,i)};if(n=="handled"||n=="multi"){T(i);fr(e)};return!!n};function Go(e,t){var i=Io(t,!0);if(!i){return!1};if(t.shiftKey&&!e.state.keySeq){return Ht(e,"Shift-"+i,t,function(t){return vi(e,t,!0)})||Ht(e,i,t,function(t){if(typeof t=="string"?/^go[A-Z]/.test(t):t.motion){return vi(e,t)}})} -else{return Ht(e,i,t,function(t){return vi(e,t)})}};function la(e,t,i){return Ht(e,"'"+i+"'",t,function(t){return vi(e,t,!0)})};var xi=null;function Uo(e){var t=this;t.curOp.focus=Y();if(v(t,e)){return};if(l&&c<11&&e.keyCode==27){e.returnValue=!1};var i=e.keyCode;t.display.shift=i==16||e.shiftKey;var r=Go(t,e);if(E){xi=r?i:null;if(!r&&i==88&&!dl&&(I?e.metaKey:e.ctrlKey)){t.replaceSelection("",null,"cut")}};if(i==18&&!/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)){sa(t)}};function sa(e){var i=e.display.lineDiv;ge(i,"CodeMirror-crosshair");function t(e){if(e.keyCode==18||!e.altKey){de(i,"CodeMirror-crosshair");D(document,"keyup",t);D(document,"mouseover",t)}};r(document,"keyup",t);r(document,"mouseover",t)};function Vo(e){if(e.keyCode==16){this.doc.sel.shift=!1};v(this,e)};function Ko(e){var t=this;if(Q(t.display,e)||v(t,e)||e.ctrlKey&&!e.altKey||I&&e.metaKey){return};var r=e.keyCode,n=e.charCode;if(E&&r==xi){xi=null;T(e);return};if((E&&(!e.which||e.which<10))&&Go(t,e)){return};var i=String.fromCharCode(n==null?r:n);if(i=="\x08"){return};if(la(t,e,i)){return};t.display.input.onKeyPress(e)};var ll=400,wi=function(e,t,i){this.time=e;this.pos=t;this.button=i};wi.prototype.compare=function(e,t,i){return this.time+ll>e&&n(t,this.pos)==0&&i==this.button};var Ye,qe;function aa(e,t){var i=+new Date;if(qe&&qe.compare(i,e,t)){Ye=qe=null;return"triple"} -else if(Ye&&Ye.compare(i,e,t)){qe=new wi(i,e,t);Ye=null;return"double"} -else{Ye=new wi(i,e,t);qe=null;return"single"}};function Xo(e){var t=this,i=t.display;if(v(t,e)||i.activeTouch&&i.input.supportsTouch()){return};i.input.ensurePolled();i.shift=e.shiftKey;if(Q(i,e)){if(!x){i.scroller.draggable=!1;setTimeout(function(){return i.scroller.draggable=!0},100)};return};if(Ar(t,e)){return};var r=Se(t,e),n=dn(e),o=r?aa(r,n):"single";window.focus();if(n==1&&t.state.selectingText){t.state.selectingText(e)};if(r&&ua(t,n,r,o,e)){return};if(n==1){if(r){ca(t,r,o,e)} -else if(Xi(e)==i.scroller){T(e)}} -else if(n==2){if(r){hi(t.doc,r)};setTimeout(function(){return i.input.focus()},20)} -else if(n==3){if(Ni){qo(t,e)} -else{jn(t)}}};function ua(e,t,i,r,n){var o="Click";if(r=="double"){o="Double"+o} -else if(r=="triple"){o="Triple"+o};o=(t==1?"Left":t==2?"Middle":"Right")+o;return Ht(e,Eo(o,n),n,function(t){if(typeof t=="string"){t=Ze[t]};if(!t){return!1};var r=!1;try{if(e.isReadOnly()){e.state.suppressEdits=!0};r=t(e,i)!=Vt}finally{e.state.suppressEdits=!1};return r})};function fa(e,t,i){var n=e.getOption("configureMouse"),r=n?n(e,t,i):{};if(r.unit==null){var o=xl?i.shiftKey&&i.metaKey:i.altKey;r.unit=o?"rectangle":t=="single"?"char":t=="double"?"word":"line"};if(r.extend==null||e.doc.extend){r.extend=e.doc.extend||i.shiftKey};if(r.addNew==null){r.addNew=I?i.metaKey:i.ctrlKey};if(r.moveOnDrag==null){r.moveOnDrag=!(I?i.altKey:i.ctrlKey)};return r};function ca(e,t,i,r){if(l){setTimeout(Ai(Xn,e),0)} -else{e.curOp.focus=Y()};var s=fa(e,i,r),a=e.doc.sel,o;if(e.options.dragDrop&&pl&&!e.isReadOnly()&&i=="single"&&(o=a.contains(t))>-1&&(n((o=a.ranges[o]).from(),t)<0||t.xRel>0)&&(n(o.to(),t)>0||t.xRel<0)){ha(e,r,t,s)} -else{da(e,r,t,s)}};function ha(e,t,i,n){var o=e.display,a=!1,s=m(e,function(t){if(x){o.scroller.draggable=!1};e.state.draggingText=!1;D(document,"mouseup",s);D(document,"mousemove",u);D(o.scroller,"dragstart",f);D(o.scroller,"drop",s);if(!a){T(t);if(!n.addNew){hi(e.doc,i,null,null,n.extend)};if(x||l&&c==9){setTimeout(function(){document.body.focus();o.input.focus()},20)} -else{o.input.focus()}}}),u=function(e){a=a||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},f=function(){return a=!0};if(x){o.scroller.draggable=!0};e.state.draggingText=s;s.copy=!n.moveOnDrag;if(o.scroller.dragDrop){o.scroller.dragDrop()};r(document,"mouseup",s);r(document,"mousemove",u);r(o.scroller,"dragstart",f);r(o.scroller,"drop",s);jn(e);setTimeout(function(){return o.input.focus()},20)};function jo(t,i,r){if(r=="char"){return new s(i,i)};if(r=="word"){return t.findWordAt(i)};if(r=="line"){return new s(e(i.line,0),o(t.doc,e(i.line+1,0)))};var n=r(t,i);return new s(n.from,n.to)};function da(i,l,a,u){var v=i.display,f=i.doc;T(l);var h,c,p=f.sel,d=p.ranges;if(u.addNew&&!u.extend){c=f.sel.contains(a);if(c>-1){h=d[c]} -else{h=new s(a,a)}} -else{h=f.sel.primary();c=f.sel.primIndex};if(u.unit=="rectangle"){if(!u.addNew){h=new s(a,a)};a=Se(i,l,!0,!0);c=-1} -else{var w=jo(i,a,u.unit);if(u.extend){h=Lr(h,w.anchor,w.head,u.extend)} -else{h=w}};if(!u.addNew){c=0;C(f,new O([h],0),Mi);p=f.sel} -else if(c==-1){c=d.length;C(f,R(d.concat([h]),c),{scroll:!1,origin:"*mouse"})} -else if(d.length>1&&d[c].empty()&&u.unit=="char"&&!u.extend){C(f,R(d.slice(0,c).concat(d.slice(c+1)),0),{scroll:!1,origin:"*mouse"});p=f.sel} -else{kr(f,c,h,Mi)};var b=a;function M(r){if(n(b,r)==0){return};b=r;if(u.unit=="rectangle"){var g=[],y=i.options.tabSize,k=H(t(f,a.line).text,a.ch,y),T=H(t(f,r.line).text,r.ch,y),M=Math.min(k,T),N=Math.max(k,T);for(var l=Math.min(a.line,r.line),O=Math.min(i.lastLine(),Math.max(a.line,r.line));l<=O;l++){var S=t(f,l).text,m=Wi(S,M,y);if(M==N){g.push(new s(e(l,m),e(l,m)))} -else if(S.length>m){g.push(new s(e(l,m),e(l,Wi(S,N,y))))}};if(!g.length){g.push(new s(a,a))};C(f,R(p.ranges.slice(0,c).concat(g),c),{origin:"*mouse",scroll:!1});i.scrollIntoView(r)} -else{var w=h,d=jo(i,r,u.unit),v=w.anchor,x;if(n(d.anchor,v)>0){x=d.head;v=Zt(w.from(),d.anchor)} -else{x=d.anchor;v=qt(w.to(),d.head)};var L=p.ranges.slice(0);L[c]=pa(i,new s(o(f,v),x));C(f,R(L,c),Mi)}};var L=v.wrapper.getBoundingClientRect(),g=0;function x(e){var l=++g,t=Se(i,e,!0,u.unit=="rectangle");if(!t){return};if(n(t,b)!=0){i.curOp.focus=Y();M(t);var o=hr(v,f);if(t.line>=o.to||t.line<o.from){setTimeout(m(i,function(){if(g==l){x(e)}}),150)}} -else{var r=e.clientY<L.top?-20:e.clientY>L.bottom?20:0;if(r){setTimeout(m(i,function(){if(g!=l){return};v.scroller.scrollTop+=r;x(e)}),50)}}};function k(e){i.state.selectingText=!1;g=Infinity;T(e);v.input.focus();D(document,"mousemove",S);D(document,"mouseup",y);f.history.lastSelOrigin=null};var S=m(i,function(e){if(!dn(e)){k(e)} -else{x(e)}}),y=m(i,k);i.state.selectingText=y;r(document,"mousemove",S);r(document,"mouseup",y)};function pa(i,r){var o=r.anchor,l=r.head,b=t(i.doc,o.line);if(n(o,l)==0&&o.sticky==l.sticky){return r};var a=Z(b);if(!a){return r};var p=gt(a,o.ch,o.sticky),c=a[p];if(c.from!=o.ch&&c.to!=o.ch){return r};var f=p+((c.from==o.ch)==(c.level!=1)?0:1);if(f==0||f==a.length){return r};var u;if(l.line!=o.line){u=(l.line-o.line)*(i.doc.direction=="ltr"?1:-1)>0} -else{var d=gt(a,l.ch,l.sticky),y=d-p||(l.ch-o.ch)*(c.level==1?-1:1);if(d==f-1||d==f){u=y<0} -else{u=y>0}};var h=a[f+(u?-1:0)],g=u==(h.level==1),v=g?h.from:h.to,m=g?"after":"before";return o.ch==v&&o.sticky==m?r:new s(new e(o.line,v,m),l)};function Yo(e,t,i,r){var s,o;if(t.touches){s=t.touches[0].clientX;o=t.touches[0].clientY} -else{try{s=t.clientX;o=t.clientY}catch(n){return!1}};if(s>=Math.floor(e.display.gutters.getBoundingClientRect().right)){return!1};if(r){T(t)};var a=e.display,f=a.lineDiv.getBoundingClientRect();if(o>f.bottom||!F(e,i)){return Ki(t)};o-=f.top-a.viewOffset;for(var l=0;l<e.options.gutters.length;++l){var u=a.gutters.childNodes[l];if(u&&u.getBoundingClientRect().right>=s){var c=ye(e.doc,o),h=e.options.gutters[l];p(e,i,e,c,h,t);return Ki(t)}}};function Ar(e,t){return Yo(e,t,"gutterClick",!0)};function qo(e,t){if(Q(e.display,t)||ga(e,t)){return};if(v(e,t,"contextmenu")){return};e.display.input.onContextMenu(t)};function ga(e,t){if(!F(e,"gutterContextMenu")){return!1};return Yo(e,t,"gutterContextMenu",!1)};function Zo(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-");wt(e)};var Oe={toString:function(){return"CodeMirror.Init"}};var Hr={};var It={};function va(t){var r=t.optionHandlers;function i(e,i,n,o){t.defaults[e]=i;if(n){r[e]=o?function(e,t,i){if(i!=Oe){n(e,t,i)}}:n}};t.defineOption=i;t.Init=Oe;i("value","",function(e,t){return e.setValue(t)},!0);i("mode",null,function(e,t){e.doc.modeOption=t;xr(e)},!0);i("indentUnit",2,xr,!0);i("indentWithTabs",!1);i("smartIndent",!0);i("tabSize",4,function(e){Nt(e);wt(e);M(e)},!0);i("lineSeparator",null,function(t,i){t.doc.lineSep=i;if(!i){return};var n=[],o=t.doc.first;t.doc.iter(function(t){for(var l=0;;){var r=t.text.indexOf(i,l);if(r==-1){break};l=r+i.length;n.push(e(o,r))};o++});for(var r=n.length-1;r>=0;r--){Ue(t.doc,i,n[r],e(n[r].line,n[r].ch+i.length))}});i("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g,function(e,t,i){e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g");if(i!=Oe){e.refresh()}});i("specialCharPlaceholder",jl,function(e){return e.refresh()},!0);i("electricChars",!0);i("inputStyle",ut?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0);i("spellcheck",!1,function(e,t){return e.getInputField().spellcheck=t},!0);i("rtlMoveVisually",!Cl);i("wholeLineUpdateBefore",!0);i("theme","default",function(e){Zo(e);Ft(e)},!0);i("keyMap","default",function(e,t,i){var n=gi(t),r=i!=Oe&&gi(i);if(r&&r.detach){r.detach(e,n)};if(n.attach){n.attach(e,r||null)}});i("extraKeys",null);i("configureMouse",null);i("lineWrapping",!1,ya,!0);i("gutters",[],function(e){br(e.options);Ft(e)},!0);i("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?ar(e.display)+"px":"0";e.refresh()},!0);i("coverGutterNextToScrollbar",!1,function(e){return ze(e)},!0);i("scrollbarStyle","native",function(e){to(e);ze(e);e.display.scrollbars.setScrollTop(e.doc.scrollTop);e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0);i("lineNumbers",!1,function(e){br(e.options);Ft(e)},!0);i("firstLineNumber",1,Ft,!0);i("lineNumberFormatter",function(e){return e},Ft,!0);i("showCursorWhenSelecting",!1,Ct,!0);i("resetSelectionOnContextMenu",!0);i("lineWiseCopyCut",!0);i("pasteLinesPerSelection",!0);i("readOnly",!1,function(e,t){if(t=="nocursor"){St(e);e.display.input.blur()};e.display.input.readOnlyChanged(t)});i("disableInput",!1,function(e,t){if(!t){e.display.input.reset()}},!0);i("dragDrop",!0,ma);i("allowDropFileTypes",null);i("cursorBlinkRate",530);i("cursorScrollMargin",0);i("cursorHeight",1,Ct,!0);i("singleCursorHeightPerLine",!0,Ct,!0);i("workTime",100);i("workDelay",100);i("flattenSpans",!0,Nt,!0);i("addModeClass",!1,Nt,!0);i("pollInterval",100);i("undoDepth",200,function(e,t){return e.doc.history.undoDepth=t});i("historyEventDelay",1250);i("viewportMargin",10,function(e){return e.refresh()},!0);i("maxHighlightLength",10000,Nt,!0);i("moveInputWithCursor",!0,function(e,t){if(!t){e.display.input.resetPosition()}});i("tabindex",null,function(e,t){return e.display.input.getField().tabIndex=t||""});i("autofocus",null);i("direction","ltr",function(e,t){return e.doc.setDirection(t)},!0)};function Ft(e){no(e);M(e);qn(e)};function ma(e,t,i){var l=i&&i!=Oe;if(!t!=!l){var n=e.display.dragFunctions,o=t?r:D;o(e.display.scroller,"dragstart",n.start);o(e.display.scroller,"dragenter",n.enter);o(e.display.scroller,"dragover",n.over);o(e.display.scroller,"dragleave",n.leave);o(e.display.scroller,"drop",n.drop)}};function ya(e){if(e.options.lineWrapping){ge(e.display.wrapper,"CodeMirror-wrap");e.display.sizer.style.minWidth="";e.display.sizerWidth=null} -else{de(e.display.wrapper,"CodeMirror-wrap");Ui(e)};ur(e);M(e);wt(e);setTimeout(function(){return ze(e)},100)};function h(e,t){var s=this;if(!(this instanceof h)){return new h(e,t)};this.options=t=t?ve(t):{};ve(Hr,t,!1);br(t);var i=t.value;if(typeof i=="string"){i=new k(i,t.mode,null,t.lineSeparator,t.direction)};this.doc=i;var a=new h.inputStyles[t.inputStyle](this),r=this.display=new Ll(e,i,a);r.wrapper.CodeMirror=this;no(this);Zo(this);if(t.lineWrapping){this.display.wrapper.className+=" CodeMirror-wrap"};to(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 ce(),keySeq:null,specialChars:null};if(t.autofocus&&!ut){r.input.focus()};if(l&&c<11){setTimeout(function(){return s.display.input.reset(!0)},20)};ba(this);Qs();Te(this);this.curOp.forceUpdate=!0;fo(this,i);if((t.autofocus&&!ut)||this.hasFocus()){setTimeout(Ai(cr,this),20)} -else{St(this)};for(var o in It){if(It.hasOwnProperty(o)){It[o](s,t[o],Oe)}};Zn(this);if(t.finishInit){t.finishInit(this)};for(var n=0;n<bi.length;++n){bi[n](s)};Me(this);if(x&&t.lineWrapping&&getComputedStyle(r.lineDiv).textRendering=="optimizelegibility"){r.lineDiv.style.textRendering="auto"}};h.defaults=Hr;h.optionHandlers=It;function ba(t){var i=t.display;r(i.scroller,"mousedown",m(t,Xo));if(l&&c<11){r(i.scroller,"dblclick",m(t,function(e){if(v(t,e)){return};var r=Se(t,e);if(!r||Ar(t,e)||Q(t.display,e)){return};T(e);var i=t.findWordAt(r);hi(t.doc,i.anchor,i.head)}))} -else{r(i.scroller,"dblclick",function(e){return v(t,e)||T(e)})};if(!Ni){r(i.scroller,"contextmenu",function(e){return qo(t,e)})};var u,a={end:0};function f(){if(i.activeTouch){u=setTimeout(function(){return i.activeTouch=null},1000);a=i.activeTouch;a.end=+new Date}};function d(e){if(e.touches.length!=1){return!1};var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1};function h(e,t){if(t.left==null){return!0};var i=t.left-e.left,r=t.top-e.top;return i*i+r*r>20*20};r(i.scroller,"touchstart",function(e){if(!v(t,e)&&!d(e)&&!Ar(t,e)){i.input.ensurePolled();clearTimeout(u);var r=+new Date;i.activeTouch={start:r,moved:!1,prev:r-a.end<=300?a:null};if(e.touches.length==1){i.activeTouch.left=e.touches[0].pageX;i.activeTouch.top=e.touches[0].pageY}}});r(i.scroller,"touchmove",function(){if(i.activeTouch){i.activeTouch.moved=!0}});r(i.scroller,"touchend",function(r){var n=i.activeTouch;if(n&&!Q(i,r)&&n.left!=null&&!n.moved&&new Date-n.start<300){var l=t.coordsChar(i.activeTouch,"page"),a;if(!n.prev||h(n,n.prev)){a=new s(l,l)} -else if(!n.prev.prev||h(n,n.prev.prev)){a=t.findWordAt(l)} -else{a=new s(e(l.line,0),o(t.doc,e(l.line+1,0)))};t.setSelection(a.anchor,a.head);t.focus();T(r)};f()});r(i.scroller,"touchcancel",f);r(i.scroller,"scroll",function(){if(i.scroller.clientHeight){kt(t,i.scroller.scrollTop);ke(t,i.scroller.scrollLeft,!0);p(t,"scroll",t)}});r(i.scroller,"mousewheel",function(e){return lo(t,e)});r(i.scroller,"DOMMouseScroll",function(e){return lo(t,e)});r(i.wrapper,"scroll",function(){return i.wrapper.scrollTop=i.wrapper.scrollLeft=0});i.dragFunctions={enter:function(e){if(!v(t,e)){vt(e)}},over:function(e){if(!v(t,e)){Zs(t,e);vt(e)}},start:function(e){return qs(t,e)},drop:m(t,Ys),leave:function(e){if(!v(t,e)){Ho(t)}}};var n=i.input.getField();r(n,"keyup",function(e){return Vo.call(t,e)});r(n,"keydown",m(t,Uo));r(n,"keypress",m(t,Ko));r(n,"focus",function(e){return cr(t,e)});r(n,"blur",function(e){return St(t,e)})};var bi=[];h.defineInitHook=function(e){return bi.push(e)};function Pt(i,r,n,o){var a=i.doc,b;if(n==null){n="add"};if(n=="smart"){if(!a.mode.indent){n="prev"} -else{b=mt(i,r).state}};var d=i.options.tabSize,u=t(a,r),g=H(u.text,null,d);if(u.stateAfter){u.stateAfter=null};var f=u.text.match(/^\s*/)[0],l;if(!o&&!/\S/.test(u.text)){l=0;n="not"} -else if(n=="smart"){l=a.mode.indent(b,u.text.slice(f.length),u.text);if(l==Vt||l>150){if(!o){return};n="prev"}};if(n=="prev"){if(r>a.first){l=H(t(a,r-1).text,null,d)} -else{l=0}} -else if(n=="add"){l=g+i.options.indentUnit} -else if(n=="subtract"){l=g-i.options.indentUnit} -else if(typeof n=="number"){l=g+n};l=Math.max(0,l);var h="",p=0;if(i.options.indentWithTabs){for(var y=Math.floor(l/d);y;--y){p+=d;h+="\t"}};if(p<l){h+=Di(l-p)};if(h!=f){Ue(a,h,e(r,0),e(r,f.length),"+input");u.stateAfter=null;return!0} -else{for(var c=0;c<a.sel.ranges.length;c++){var m=a.sel.ranges[c];if(m.head.line==r&&m.head.ch<f.length){var v=e(r,f.length);kr(a,c,new s(v,v));break}}}};var P=null;function mi(e){P=e};function Wr(i,r,n,o,l){var v=i.doc;i.display.shift=!1;if(!o){o=v.sel};var h=i.state.pasteIncoming||l=="paste",d=Si(r),f=null;if(h&&o.ranges.length>1){if(P&&P.text.join("\n")==r){if(o.ranges.length%P.text.length==0){f=[];for(var g=0;g<P.text.length;g++){f.push(v.splitLines(P.text[g]))}}} -else if(d.length==o.ranges.length&&i.options.pasteLinesPerSelection){f=jt(d,function(e){return[e]})}};var y;for(var c=o.ranges.length-1;c>=0;c--){var p=o.ranges[c],s=p.from(),u=p.to();if(p.empty()){if(n&&n>0){s=e(s.line,s.ch-n)} -else if(i.state.overwrite&&!h){u=e(u.line,Math.min(t(v,u.line).text.length,u.ch+a(d).length))} -else if(P&&P.lineWise&&P.text.join("\n")==r){s=u=e(s.line,0)}};y=i.curOp.updateInput;var m={from:s,to:u,text:f?f[c%f.length]:d,origin:l||(h?"paste":i.state.cutIncoming?"cut":"+input")};Ge(i.doc,m);w(i,"inputRead",i,m)};if(r&&!h){Jo(i,r)};Ie(i);i.curOp.updateInput=y;i.curOp.typing=!0;i.state.pasteIncoming=i.state.cutIncoming=!1};function Qo(e,t){var i=e.clipboardData&&e.clipboardData.getData("Text");if(i){e.preventDefault();if(!t.isReadOnly()&&!t.options.disableInput){N(t,function(){return Wr(t,i,0,null,"paste")})};return!0}};function Jo(e,i){if(!e.options.electricChars||!e.options.smartIndent){return};var a=e.doc.sel;for(var o=a.ranges.length-1;o>=0;o--){var r=a.ranges[o];if(r.head.ch>100||(o&&a.ranges[o-1].head.line==r.head.line)){continue};var n=e.getModeAt(r.head),s=!1;if(n.electricChars){for(var l=0;l<n.electricChars.length;l++){if(i.indexOf(n.electricChars.charAt(l))>-1){s=Pt(e,r.head.line,"smart");break}}} -else if(n.electricInput){if(n.electricInput.test(t(e.doc,r.head.line).text.slice(0,r.head.ch))){s=Pt(e,r.head.line,"smart")}};if(s){w(e,"electricInput",e,r.head.line)}}};function el(t){var o=[],l=[];for(var r=0;r<t.doc.sel.ranges.length;r++){var n=t.doc.sel.ranges[r].head.line,i={anchor:e(n,0),head:e(n+1,0)};l.push(i);o.push(t.getRange(i.anchor,i.head))};return{text:o,ranges:l}};function tl(e,t){e.setAttribute("autocorrect","off");e.setAttribute("autocapitalize","off");e.setAttribute("spellcheck",!!t)};function il(){var e=i("textarea",null,null,"position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none"),t=i("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");if(x){e.style.width="1000px"} -else{e.setAttribute("wrap","off")};if(at){e.style.border="1px solid black"};tl(e);return t};function wa(i){var n=i.optionHandlers,r=i.helpers={};i.prototype={constructor:i,focus:function(){window.focus();this.display.input.focus()},setOption:function(e,t){var i=this.options,r=i[e];if(i[e]==t&&e!="mode"){return};i[e]=t;if(n.hasOwnProperty(e)){m(this,n[e])(this,t,r)};p(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"](gi(e))},removeKeyMap:function(e){var i=this.state.keyMaps;for(var t=0;t<i.length;++t){if(i[t]==e||i[t].name==e){i.splice(t,1);return!0}}},addOverlay:L(function(e,t){var r=e.token?e:i.getMode(this.options,e);if(r.startState){throw new Error("Overlays may not be stateful.")};Sl(this.state.overlays,{mode:r,modeSpec:e,opaque:t&&t.opaque,priority:(t&&t.priority)||0},function(e){return e.priority});this.state.modeGen++;M(this)}),removeOverlay:L(function(e){var n=this,i=this.state.overlays;for(var t=0;t<i.length;++t){var r=i[t].modeSpec;if(r==e||typeof e=="string"&&r.name==e){i.splice(t,1);n.state.modeGen++;M(n);return}}}),indentLine:L(function(e,t,i){if(typeof t!="string"&&typeof t!="number"){if(t==null){t=this.options.smartIndent?"smart":"prev"} -else{t=t?"add":"subtract"}};if(ht(this.doc,e)){Pt(this,e,t,i)}}),indentSelection:L(function(e){var i=this,u=this.doc.sel.ranges,n=-1;for(var t=0;t<u.length;t++){var r=u[t];if(!r.empty()){var a=r.from(),f=r.to(),c=Math.max(n,a.line);n=Math.min(i.lastLine(),f.line-(f.ch?0:1))+1;for(var l=c;l<n;++l){Pt(i,l,e)};var o=i.doc.sel.ranges;if(a.ch==0&&u.length==o.length&&o[t].from().ch>0){kr(i.doc,t,new s(a,o[t].to()),G)}} -else if(r.head.line>n){Pt(i,r.head.line,e,!0);n=r.head.line;if(t==i.doc.sel.primIndex){Ie(i)}}}}),getTokenAt:function(e,t){return yn(this,e,t)},getLineTokens:function(t,i){return yn(this,e(t),i,!0)},getTokenTypeAt:function(e){e=o(this.doc,e);var n=vn(this,t(this.doc,e.line)),a=0,u=(n.length-1)/2,s=e.ch,r;if(s==0){r=n[2]} -else{for(;;){var i=(a+u)>>1;if((i?n[i*2-1]:0)>=s){u=i} -else if(n[i*2+1]<s){a=i+1} -else{r=n[i*2+2];break}}};var l=r?r.indexOf("overlay "):-1;return l<0?r:l==0?null:r.slice(0,l-1)},getModeAt:function(e){var t=this.doc.mode;if(!t.innerMode){return t};return i.innerMode(t,this.getTokenAt(e).state).mode},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var f=this,o=[];if(!r.hasOwnProperty(t)){return o};var n=r[t],i=this.getModeAt(e);if(typeof i[t]=="string"){if(n[i[t]]){o.push(n[i[t]])}} -else if(i[t]){for(var a=0;a<i[t].length;a++){var u=n[i[t][a]];if(u){o.push(u)}}} -else if(i.helperType&&n[i.helperType]){o.push(n[i.helperType])} -else if(n[i.name]){o.push(n[i.name])};for(var s=0;s<n._global.length;s++){var l=n._global[s];if(l.pred(i,f)&&b(o,l.val)==-1){o.push(l.val)}};return o},getStateAfter:function(e,t){var i=this.doc;e=en(i,e==null?i.first+i.size-1:e);return mt(this,e+1,t).state},cursorCoords:function(e,t){var i,r=this.doc.sel.primary();if(e==null){i=r.head} -else if(typeof e=="object"){i=o(this.doc,e)} -else{i=e?r.from():r.to()};return z(this,i,t||"page")},charCoords:function(e,t){return rr(this,o(this.doc,e),t||"page")},coordsChar:function(e,t){e=zn(this,e,t||"page");return or(this,e.left,e.top)},lineAtHeight:function(e,t){e=zn(this,{top:e,left:0},t||"page").top;return ye(this.doc,e+this.display.viewOffset)},heightAtLine:function(e,i,r){var o=!1,n;if(typeof e=="number"){var l=this.doc.first+this.doc.size-1;if(e<this.doc.first){e=this.doc.first} -else if(e>l){e=l;o=!0};n=t(this.doc,e)} -else{n=e};return oi(this,n,{top:0,left:0},i||"page",r||o).top+(o?this.doc.height-q(n):0)},defaultTextHeight:function(){return Ce(this.display)},defaultCharWidth:function(){return xt(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,i,r,n){var a=this.display;e=z(this,o(this.doc,e));var s=e.bottom,l=e.left;t.style.position="absolute";t.setAttribute("cm-ignore-events","true");this.display.input.setUneditable(t);a.sizer.appendChild(t);if(r=="over"){s=e.top} -else if(r=="above"||r=="near"){var u=Math.max(a.wrapper.clientHeight,this.doc.height),f=Math.max(a.sizer.clientWidth,a.lineSpace.clientWidth);if((r=="above"||e.bottom+t.offsetHeight>u)&&e.top>t.offsetHeight){s=e.top-t.offsetHeight} -else if(e.bottom+t.offsetHeight<=u){s=e.bottom};if(l+t.offsetWidth>f){l=f-t.offsetWidth}};t.style.top=s+"px";t.style.left=t.style.right="";if(n=="right"){l=a.sizer.clientWidth-t.offsetWidth;t.style.right="0px"} -else{if(n=="left"){l=0} -else if(n=="middle"){l=(a.sizer.clientWidth-t.offsetWidth)/2};t.style.left=l+"px"};if(i){bs(this,{left:l,top:s,right:l+t.offsetWidth,bottom:s+t.offsetHeight})}},triggerOnKeyDown:L(Uo),triggerOnKeyPress:L(Ko),triggerOnKeyUp:Vo,triggerOnMouseDown:L(Xo),execCommand:function(e){if(Ze.hasOwnProperty(e)){return Ze[e].call(null,this)}},triggerElectric:L(function(e){Jo(this,e)}),findPosH:function(e,t,i,r){var a=this,s=1;if(t<0){s=-1;t=-t};var n=o(this.doc,e);for(var l=0;l<t;++l){n=Dr(a.doc,n,s,i,r);if(n.hitSide){break}};return n},moveH:L(function(e,t){var i=this;this.extendSelectionsBy(function(r){if(i.display.shift||i.doc.extend||r.empty()){return Dr(i.doc,r.head,e,t,i.options.rtlMoveVisually)} -else{return e<0?r.from():r.to()}},ot)}),deleteH:L(function(e,t){var r=this.doc.sel,i=this.doc;if(r.somethingSelected()){i.replaceSelection("",null,"+delete")} -else{Xe(this,function(r){var n=Dr(i,r.head,e,t,!1);return e<0?{from:n,to:r.head}:{from:r.head,to:n}})}}),findPosV:function(e,t,i,r){var u=this,f=1,s=r;if(t<0){f=-1;t=-t};var n=o(this.doc,e);for(var a=0;a<t;++a){var l=z(u,n,"div");if(s==null){s=l.left} -else{l.left=s};n=rl(u,l,f,i);if(n.hitSide){break}};return n},moveV:L(function(e,t){var n=this,i=this.doc,o=[],l=!this.display.shift&&!i.extend&&i.sel.somethingSelected();i.extendSelectionsBy(function(r){if(l){return e<0?r.from():r.to()};var s=z(n,r.head,"div");if(r.goalColumn!=null){s.left=r.goalColumn};o.push(s.left);var a=rl(n,s,e,t);if(t=="page"&&r==i.sel.primary()){pr(n,rr(n,a,"div").top-s.top)};return a},ot);if(o.length){for(var r=0;r<i.sel.ranges.length;r++){i.sel.ranges[r].goalColumn=o[r]}}}),findWordAt:function(i){var f=this.doc,n=t(f,i.line).text,r=i.ch,o=i.ch;if(n){var u=this.getHelper(i,"wordChars");if((i.sticky=="before"||o==n.length)&&r){--r} -else{++o};var l=n.charAt(r),a=Yt(l,u)?function(e){return Yt(e,u)}:/\s/.test(l)?function(e){return/\s/.test(e)}:function(e){return(!/\s/.test(e)&&!Yt(e))} -while(r>0&&a(n.charAt(r-1))){--r} -while(o<n.length&&a(n.charAt(o))){++o}};return new s(e(i.line,r),e(i.line,o))},toggleOverwrite:function(e){if(e!=null&&e==this.state.overwrite){return};if(this.state.overwrite=!this.state.overwrite){ge(this.display.cursorDiv,"CodeMirror-overwrite")} -else{de(this.display.cursorDiv,"CodeMirror-overwrite")};p(this,"overwriteToggle",this,this.state.overwrite)},hasFocus:function(){return this.display.input.getField()==Y()},isReadOnly:function(){return!!(this.options.readOnly||this.doc.cantEdit)},scrollTo:L(function(e,t){Lt(this,e,t)}),getScrollInfo:function(){var e=this.display.scroller;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-K(this)-this.display.barHeight,width:e.scrollWidth-K(this)-this.display.barWidth,clientHeight:er(this),clientWidth:xe(this)}},scrollIntoView:L(function(t,i){if(t==null){t={from:this.doc.sel.primary().head,to:null};if(i==null){i=this.options.cursorScrollMargin}} -else if(typeof t=="number"){t={from:e(t,0),to:null}} -else if(t.from==null){t={from:t,to:null}};if(!t.to){t.to=t.from};t.margin=i||0;if(t.from.line!=null){ws(this,t)} -else{Qn(this,t.from,t.to,t.margin)}}),setSize:L(function(e,t){var n=this,r=function(e){return typeof e=="number"||/^\d+$/.test(String(e))?e+"px":e};if(e!=null){this.display.wrapper.style.width=r(e)};if(t!=null){this.display.wrapper.style.height=r(t)};if(this.options.lineWrapping){Pn(this)};var i=this.display.viewFrom;this.doc.iter(i,this.display.viewTo,function(e){if(e.widgets){for(var t=0;t<e.widgets.length;t++){if(e.widgets[t].noHScroll){oe(n,i,"widget");break}}};++i});this.curOp.forceUpdate=!0;p(this,"refresh",this)}),operation:function(e){return N(this,e)},startOperation:function(){return Te(this)},endOperation:function(){return Me(this)},refresh:L(function(){var e=this.display.cachedTextHeight;M(this);this.curOp.forceUpdate=!0;wt(this);Lt(this,this.doc.scrollLeft,this.doc.scrollTop);mr(this);if(e==null||Math.abs(e-Ce(this.display))>.5){ur(this)};p(this,"refresh",this)}),swapDoc:L(function(e){var t=this.doc;t.cm=null;fo(this,e);wt(this);this.display.input.reset();Lt(this,e.scrollLeft,e.scrollTop);this.curOp.forceScroll=!0;w(this,"swapDoc",this,t);return t}),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}};Pe(i);i.registerHelper=function(e,t,n){if(!r.hasOwnProperty(e)){r[e]=i[e]={_global:[]}};r[e][t]=n};i.registerGlobalHelper=function(e,t,n,o){i.registerHelper(e,t,o);r[e]._global.push({pred:n,val:o})}};function Dr(i,r,n,o,l){var g=r,m=n,a=t(i,r.line);function y(){var o=r.line+n;if(o<i.first||o>=i.first+i.size){return!1};r=new e(o,r.ch,r.sticky);return a=t(i,o)};function u(e){var t;if(l){t=ra(i.cm,a,r,n)} -else{t=Nr(a,r,n)};if(t==null){if(!e&&y()){r=Or(l,i.cm,a,r.line,n)} -else{return!1}} -else{r=t};return!0};if(o=="char"){u()} -else if(o=="column"){u(!0)} -else if(o=="word"||o=="group"){var d=null,p=o=="group",v=i.cm&&i.cm.getHelper(r,"wordChars");for(var f=!0;;f=!1){if(n<0&&!u(!f)){break};var h=a.text.charAt(r.ch)||"\n",s=Yt(h,v)?"w":p&&h=="\n"?"n":!p||/\s/.test(h)?null:"p";if(p&&!f&&!s){s="s"};if(d&&d!=s){if(n<0){n=1;u();r.sticky="after"};break};if(s){d=s};if(n>0&&!u(!f)){break}}};var c=Tr(i,r,g,m,!0);if(Ii(g,c)){c.hitSide=!0};return c};function rl(e,t,i,r){var a=e.doc,u=t.left,n;if(r=="page"){var l=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),s=Math.max(l-.5*Ce(e.display),3);n=(i>0?t.bottom:t.top)+i*s} -else if(r=="line"){n=i>0?t.bottom+3:t.top-3};var o;for(;;){o=or(e,u,n);if(!o.outside){break};if(i<0?n<=0:n>=a.height){o.hitSide=!0;break};n+=i*5};return o};var f=function(e){this.cm=e;this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null;this.polling=new ce();this.composing=null;this.gracePeriod=!1;this.readDOMTimeout=null};f.prototype.init=function(e){var i=this,o=this,t=o.cm,n=o.div=e.lineDiv;tl(n,t.options.spellcheck);r(n,"paste",function(e){if(v(t,e)||Qo(e,t)){return};if(c<=11){setTimeout(m(t,function(){return i.updateFromDOM()}),20)}});r(n,"compositionstart",function(e){i.composing={data:e.data,done:!1}});r(n,"compositionupdate",function(e){if(!i.composing){i.composing={data:e.data,done:!1}}});r(n,"compositionend",function(e){if(i.composing){if(e.data!=i.composing.data){i.readFromDOMSoon()};i.composing.done=!0}});r(n,"touchstart",function(){return o.forceCompositionEnd()});r(n,"input",function(){if(!i.composing){i.readFromDOMSoon()}});function l(e){if(v(t,e)){return};if(t.somethingSelected()){mi({lineWise:!1,text:t.getSelections()});if(e.type=="cut"){t.replaceSelection("",null,"cut")}} -else if(!t.options.lineWiseCopyCut){return} -else{var a=el(t);mi({lineWise:!0,text:a.text});if(e.type=="cut"){t.operation(function(){t.setSelections(a.ranges,0,G);t.replaceSelection("",null,"cut")})}};if(e.clipboardData){e.clipboardData.clearData();var s=P.text.join("\n");e.clipboardData.setData("Text",s);if(e.clipboardData.getData("Text")==s){e.preventDefault();return}};var i=il(),l=i.firstChild;t.display.lineSpace.insertBefore(i,t.display.lineSpace.firstChild);l.value=P.text.join("\n");var r=document.activeElement;lt(l);setTimeout(function(){t.display.lineSpace.removeChild(i);r.focus();if(r==n){o.showPrimarySelection()}},50)};r(n,"copy",l);r(n,"cut",l)};f.prototype.prepareSelection=function(){var e=Vn(this.cm,!1);e.focus=this.cm.state.focused;return e};f.prototype.showSelection=function(e,t){if(!e||!this.cm.display.view.length){return};if(e.focus||t){this.showPrimarySelection()};this.showMultipleSelections(e)};f.prototype.showPrimarySelection=function(){var e=window.getSelection(),t=this.cm,g=t.doc.sel.primary(),c=g.from(),h=g.to();if(t.display.viewTo==t.display.viewFrom||c.line>=t.display.viewTo||h.line<t.display.viewFrom){e.removeAllRanges();return};var u=yi(t,e.anchorNode,e.anchorOffset),f=yi(t,e.focusNode,e.focusOffset);if(u&&!u.bad&&f&&!f.bad&&n(Zt(u,f),c)==0&&n(qt(u,f),h)==0){return};var d=t.display.view,s=(c.line>=t.display.viewFrom&&nl(t,c))||{node:d[0].measure.map[2],offset:0};var l=h.line<t.display.viewTo&&nl(t,h);if(!l){var a=d[d.length-1].measure,r=a.maps?a.maps[a.maps.length-1]:a.map;l={node:r[r.length-1],offset:r[r.length-2]-r[r.length-3]}};if(!s||!l){e.removeAllRanges();return};var p=e.rangeCount&&e.getRangeAt(0),o;try{o=he(s.node,s.offset,l.offset,l.node)}catch(i){};if(o){if(!ie&&t.state.focused){e.collapse(s.node,s.offset);if(!o.collapsed){e.removeAllRanges();e.addRange(o)}} -else{e.removeAllRanges();e.addRange(o)};if(p&&e.anchorNode==null){e.addRange(p)} -else if(ie){this.startGracePeriod()}};this.rememberSelection()};f.prototype.startGracePeriod=function(){var e=this;clearTimeout(this.gracePeriod);this.gracePeriod=setTimeout(function(){e.gracePeriod=!1;if(e.selectionChanged()){e.cm.operation(function(){return e.cm.curOp.selectionChanged=!0})}},20)};f.prototype.showMultipleSelections=function(e){W(this.cm.display.cursorDiv,e.cursors);W(this.cm.display.selectionDiv,e.selection)};f.prototype.rememberSelection=function(){var e=window.getSelection();this.lastAnchorNode=e.anchorNode;this.lastAnchorOffset=e.anchorOffset;this.lastFocusNode=e.focusNode;this.lastFocusOffset=e.focusOffset};f.prototype.selectionInEditor=function(){var e=window.getSelection();if(!e.rangeCount){return!1};var t=e.getRangeAt(0).commonAncestorContainer;return ne(this.div,t)};f.prototype.focus=function(){if(this.cm.options.readOnly!="nocursor"){if(!this.selectionInEditor()){this.showSelection(this.prepareSelection(),!0)};this.div.focus()}};f.prototype.blur=function(){this.div.blur()};f.prototype.getField=function(){return this.div};f.prototype.supportsTouch=function(){return!0};f.prototype.receivedFocus=function(){var e=this;if(this.selectionInEditor()){this.pollSelection()} -else{N(this.cm,function(){return e.cm.curOp.selectionChanged=!0})};function t(){if(e.cm.state.focused){e.pollSelection();e.polling.set(e.cm.options.pollInterval,t)}};this.polling.set(this.cm.options.pollInterval,t)};f.prototype.selectionChanged=function(){var e=window.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset};f.prototype.pollSelection=function(){if(this.readDOMTimeout!=null||this.gracePeriod||!this.selectionChanged()){return};var e=window.getSelection(),t=this.cm;if(Xt&&Kt&&this.cm.options.gutters.length&&xa(e.anchorNode)){this.cm.triggerOnKeyDown({type:"keydown",keyCode:8,preventDefault:Math.abs});this.blur();this.focus();return};if(this.composing){return};this.rememberSelection();var i=yi(t,e.anchorNode,e.anchorOffset),r=yi(t,e.focusNode,e.focusOffset);if(i&&r){N(t,function(){C(t.doc,se(i,r),G);if(i.bad||r.bad){t.curOp.selectionChanged=!0}})}};f.prototype.pollContent=function(){if(this.readDOMTimeout!=null){clearTimeout(this.readDOMTimeout);this.readDOMTimeout=null};var r=this.cm,o=r.display,k=r.doc.sel.primary(),f=k.from(),g=k.to();if(f.ch==0&&f.line>r.firstLine()){f=e(f.line-1,t(r.doc,f.line-1).length)};if(g.ch==t(r.doc,g.line).text.length&&g.line<r.lastLine()){g=e(g.line+1,0)};if(f.line<o.viewFrom||g.line>o.viewTo-1){return!1};var w,p,m;if(f.line==o.viewFrom||(w=Le(r,f.line))==0){p=u(o.view[0].line);m=o.view[0].node} -else{p=u(o.view[w].line);m=o.view[w-1].node.nextSibling};var y=Le(r,g.line),d,b;if(y==o.view.length-1){d=o.viewTo-1;b=o.lineDiv.lastChild} -else{d=u(o.view[y+1].line)-1;b=o.view[y+1].node.previousSibling};if(!m){return!1};var i=r.doc.splitLines(Ca(r,m,b,p,d)),s=me(r.doc,e(p,0),e(d,t(r.doc,d).text.length));while(i.length>1&&s.length>1){if(a(i)==a(s)){i.pop();s.pop();d--} -else if(i[0]==s[0]){i.shift();s.shift();p++} -else{break}};var l=0,c=0,S=i[0],L=s[0],M=Math.min(S.length,L.length);while(l<M&&S.charCodeAt(l)==L.charCodeAt(l)){++l};var h=a(i),v=a(s),T=Math.min(h.length-(i.length==1?l:0),v.length-(s.length==1?l:0));while(c<T&&h.charCodeAt(h.length-c-1)==v.charCodeAt(v.length-c-1)){++c};if(i.length==1&&s.length==1&&p==f.line){while(l&&l>f.ch&&h.charCodeAt(h.length-c-1)==v.charCodeAt(v.length-c-1)){l--;c++}};i[i.length-1]=h.slice(0,h.length-c).replace(/^\u200b+/,"");i[0]=i[0].slice(l).replace(/\u200b+$/,"");var x=e(p,l),C=e(d,s.length?a(s).length-c:0);if(i.length>1||i[0]||n(x,C)){Ue(r.doc,i,x,C,"+input");return!0}};f.prototype.ensurePolled=function(){this.forceCompositionEnd()};f.prototype.reset=function(){this.forceCompositionEnd()};f.prototype.forceCompositionEnd=function(){if(!this.composing){return};clearTimeout(this.readDOMTimeout);this.composing=null;this.updateFromDOM();this.div.blur();this.div.focus()};f.prototype.readFromDOMSoon=function(){var e=this;if(this.readDOMTimeout!=null){return};this.readDOMTimeout=setTimeout(function(){e.readDOMTimeout=null;if(e.composing){if(e.composing.done){e.composing=null} -else{return}};e.updateFromDOM()},80)};f.prototype.updateFromDOM=function(){var e=this;if(this.cm.isReadOnly()||!this.pollContent()){N(this.cm,function(){return M(e.cm)})}};f.prototype.setUneditable=function(e){e.contentEditable="false"};f.prototype.onKeyPress=function(e){if(e.charCode==0){return};e.preventDefault();if(!this.cm.isReadOnly()){m(this.cm,Wr)(this.cm,String.fromCharCode(e.charCode==null?e.keyCode:e.charCode),0)}};f.prototype.readOnlyChanged=function(e){this.div.contentEditable=String(e!="nocursor")};f.prototype.onContextMenu=function(){};f.prototype.resetPosition=function(){};f.prototype.needsContentAttribute=!0;function nl(e,i){var n=tr(e,i.line);if(!n||n.hidden){return null};var o=t(e.doc,i.line),u=Wn(n,o,i.line),l=Z(o,e.doc.direction),s="left";if(l){var a=gt(l,i.ch);s=a%2?"right":"left"};var r=Hn(u.map,i.ch,s);r.offset=r.collapse=="right"?r.end:r.start;return r};function xa(e){for(var t=e;t;t=t.parentNode){if(/CodeMirror-gutter-wrapper/.test(t.className)){return!0}};return!1};function je(e,t){if(t){e.bad=!0};return e};function Ca(t,i,r,n,o){var l="",s=!1,u=t.doc.lineSeparator();function h(e){return function(t){return t.id==e}};function f(){if(s){l+=u;s=!1}};function a(e){if(e){f();l+=e}};function c(i){if(i.nodeType==1){var v=i.getAttribute("cm-text");if(v!=null){a(v||i.textContent.replace(/\u200b/g,""));return};var g=i.getAttribute("cm-marker"),l;if(g){var p=t.findMarks(e(n,0),e(o+1,0),h(+g));if(p.length&&(l=p[0].find(0))){a(me(t.doc,l.from,l.to).join(u))};return};if(i.getAttribute("contenteditable")=="false"){return};var d=/^(pre|div|p)$/i.test(i.nodeName);if(d){f()};for(var r=0;r<i.childNodes.length;r++){c(i.childNodes[r])};if(d){s=!0}} -else if(i.nodeType==3){a(i.nodeValue)}};for(;;){c(i);if(i==r){break};i=i.nextSibling};return l};function yi(t,i,r){var n;if(i==t.display.lineDiv){n=t.display.lineDiv.childNodes[r];if(!n){return je(t.clipPos(e(t.display.viewTo-1)),!0)};i=null;r=0} -else{for(n=i;;n=n.parentNode){if(!n||n==t.display.lineDiv){return null};if(n.parentNode&&n.parentNode==t.display.lineDiv){break}}};for(var o=0;o<t.display.view.length;o++){var l=t.display.view[o];if(l.node==n){return Sa(l,i,r)}}};function Sa(t,i,r){var h=t.text.firstChild,c=!1;if(!i||!ne(h,i)){return je(e(u(t.line),0),!0)};if(i==h){c=!0;i=h.childNodes[r];r=0;if(!i){var y=t.rest?a(t.rest):t.line;return je(e(u(y),y.text.length),c)}};var s=i.nodeType==3?i:null,f=i;if(!s&&i.childNodes.length==1&&i.firstChild.nodeType==3){s=i.firstChild;if(r){r=s.nodeValue.length}} -while(f.parentNode!=h){f=f.parentNode};var m=t.measure,d=m.maps;function p(i,r,n){for(var o=-1;o<(d?d.length:0);o++){var s=o<0?m.map:d[o];for(var l=0;l<s.length;l+=3){var a=s[l+2];if(a==i||a==r){var c=u(o<0?t.line:t.rest[o]),f=s[l]+n;if(n<0||a!=i){f=s[l+(n?1:0)]};return e(c,f)}}}};var n=p(s,f,r);if(n){return je(n,c)};for(var l=f.nextSibling,v=s?s.nodeValue.length-r:0;l;l=l.nextSibling){n=p(l,l.firstChild,0);if(n){return je(e(n.line,n.ch-v),c)} -else{v+=l.textContent.length}};for(var o=f.previousSibling,g=r;o;o=o.previousSibling){n=p(o,o.firstChild,-1);if(n){return je(e(n.line,n.ch+g),c)} -else{g+=o.textContent.length}}};var g=function(e){this.cm=e;this.prevInput="";this.pollingFast=!1;this.polling=new ce();this.hasSelection=!1;this.composing=null};g.prototype.init=function(e){var o=this,i=this,t=this.cm,s=this.wrapper=il(),n=this.textarea=s.firstChild;e.wrapper.insertBefore(s,e.wrapper.firstChild);if(at){n.style.width="0px"};r(n,"input",function(){if(l&&c>=9&&o.hasSelection){o.hasSelection=null};i.poll()});r(n,"paste",function(e){if(v(t,e)||Qo(e,t)){return};t.state.pasteIncoming=!0;i.fastPoll()});function a(e){if(v(t,e)){return};if(t.somethingSelected()){mi({lineWise:!1,text:t.getSelections()})} -else if(!t.options.lineWiseCopyCut){return} -else{var r=el(t);mi({lineWise:!0,text:r.text});if(e.type=="cut"){t.setSelections(r.ranges,null,G)} -else{i.prevInput="";n.value=r.text.join("\n");lt(n)}};if(e.type=="cut"){t.state.cutIncoming=!0}};r(n,"cut",a);r(n,"copy",a);r(e.scroller,"paste",function(r){if(Q(e,r)||v(t,r)){return};t.state.pasteIncoming=!0;i.focus()});r(e.lineSpace,"selectstart",function(t){if(!Q(e,t)){T(t)}});r(n,"compositionstart",function(){var e=t.getCursor("from");if(i.composing){i.composing.range.clear()};i.composing={start:e,range:t.markText(e,t.getCursor("to"),{className:"CodeMirror-composing"})}});r(n,"compositionend",function(){if(i.composing){i.poll();i.composing.range.clear();i.composing=null}})};g.prototype.prepareSelection=function(){var e=this.cm,t=e.display,l=e.doc,i=Vn(e);if(e.options.moveInputWithCursor){var r=z(e,l.sel.primary().head,"div"),n=t.wrapper.getBoundingClientRect(),o=t.lineDiv.getBoundingClientRect();i.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,r.top+o.top-n.top));i.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,r.left+o.left-n.left))};return i};g.prototype.showSelection=function(e){var i=this.cm,t=i.display;W(t.cursorDiv,e.cursors);W(t.selectionDiv,e.selection);if(e.teTop!=null){this.wrapper.style.top=e.teTop+"px";this.wrapper.style.left=e.teLeft+"px"}};g.prototype.reset=function(e){if(this.contextMenuPending||this.composing){return};var t=this.cm;if(t.somethingSelected()){this.prevInput="";var i=t.getSelection();this.textarea.value=i;if(t.state.focused){lt(this.textarea)};if(l&&c>=9){this.hasSelection=i}} -else if(!e){this.prevInput=this.textarea.value="";if(l&&c>=9){this.hasSelection=null}}};g.prototype.getField=function(){return this.textarea};g.prototype.supportsTouch=function(){return!1};g.prototype.focus=function(){if(this.cm.options.readOnly!="nocursor"&&(!ut||Y()!=this.textarea)){try{this.textarea.focus()}catch(e){}}};g.prototype.blur=function(){this.textarea.blur()};g.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0};g.prototype.receivedFocus=function(){this.slowPoll()};g.prototype.slowPoll=function(){var e=this;if(this.pollingFast){return};this.polling.set(this.cm.options.pollInterval,function(){e.poll();if(e.cm.state.focused){e.slowPoll()}})};g.prototype.fastPoll=function(){var t=!1,e=this;e.pollingFast=!0;function i(){var r=e.poll();if(!r&&!t){t=!0;e.polling.set(60,i)} -else{e.pollingFast=!1;e.slowPoll()}};e.polling.set(20,i)};g.prototype.poll=function(){var i=this,e=this.cm,o=this.textarea,r=this.prevInput;if(this.contextMenuPending||!e.state.focused||(hl(o)&&!r&&!this.composing)||e.isReadOnly()||e.options.disableInput||e.state.keySeq){return!1};var t=o.value;if(t==r&&!e.somethingSelected()){return!1};if(l&&c>=9&&this.hasSelection===t||I&&/[\uf700-\uf7ff]/.test(t)){e.display.input.reset();return!1};if(e.doc.sel==e.display.selForContextMenu){var s=t.charCodeAt(0);if(s==0x200b&&!r){r="\u200b"};if(s==0x21da){this.reset();return this.cm.execCommand("undo")}};var n=0,a=Math.min(r.length,t.length);while(n<a&&r.charCodeAt(n)==t.charCodeAt(n)){++n};N(e,function(){Wr(e,t.slice(n),r.length-n,null,i.composing?"*compose":null);if(t.length>1000||t.indexOf("\n")>-1){o.value=i.prevInput=""} -else{i.prevInput=t};if(i.composing){i.composing.range.clear();i.composing.range=e.markText(i.composing.start,e.getCursor("to"),{className:"CodeMirror-composing"})}});return!0};g.prototype.ensurePolled=function(){if(this.pollingFast&&this.poll()){this.pollingFast=!1}};g.prototype.onKeyPress=function(){if(l&&c>=9){this.hasSelection=null};this.fastPoll()};g.prototype.onContextMenu=function(e){var o=this,t=o.cm,i=t.display,n=o.textarea,s=Se(t,e),y=i.scroller.scrollTop;if(!s||E){return};var v=t.options.resetSelectionOnContextMenu;if(v&&t.doc.sel.contains(s)==-1){m(t,C)(t.doc,se(s),G)};var p=n.style.cssText,g=o.wrapper.style.cssText;o.wrapper.style.cssText="position: absolute";var f=o.wrapper.getBoundingClientRect();n.style.cssText="position: absolute; width: 30px; height: 30px;\n top: "+(e.clientY-f.top-5)+"px; left: "+(e.clientX-f.left-5)+"px;\n z-index: 1000; background: "+(l?"rgba(255, 255, 255, .05)":"transparent")+";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";var u;if(x){u=window.scrollY};i.input.focus();if(x){window.scrollTo(null,u)};i.input.reset();if(!t.somethingSelected()){n.value=o.prevInput=" "};o.contextMenuPending=!0;i.selForContextMenu=t.doc.sel;clearTimeout(i.detectingSelectAll);function h(){if(n.selectionStart!=null){var e=t.somethingSelected(),r="\u200b"+(e?n.value:"");n.value="\u21da";n.value=r;o.prevInput=e?"":"\u200b";n.selectionStart=1;n.selectionEnd=r.length;i.selForContextMenu=t.doc.sel}};function d(){o.contextMenuPending=!1;o.wrapper.style.cssText=g;n.style.cssText=p;if(l&&c<9){i.scrollbars.setScrollTop(i.scroller.scrollTop=y)};if(n.selectionStart!=null){if(!l||(l&&c<9)){h()};var r=0,e=function(){if(i.selForContextMenu==t.doc.sel&&n.selectionStart==0&&n.selectionEnd>0&&o.prevInput=="\u200b"){m(t,Lo)(t)} -else if(r++<10){i.detectingSelectAll=setTimeout(e,500)} -else{i.selForContextMenu=null;i.input.reset()}};i.detectingSelectAll=setTimeout(e,200)}};if(l&&c>=9){h()};if(Ni){vt(e);var a=function(){D(window,"mouseup",a);setTimeout(d,20)};r(window,"mouseup",a)} -else{setTimeout(d,50)}};g.prototype.readOnlyChanged=function(e){if(!e){this.reset()};this.textarea.disabled=e=="nocursor"};g.prototype.setUneditable=function(){};g.prototype.needsContentAttribute=!1;function La(e,t){t=t?ve(t):{};t.value=e.value;if(!t.tabindex&&e.tabIndex){t.tabindex=e.tabIndex};if(!t.placeholder&&e.placeholder){t.placeholder=e.placeholder};if(t.autofocus==null){var a=Y();t.autofocus=a==e||e.getAttribute("autofocus")!=null&&a==document.body};function o(){e.value=s.getValue()};var l;if(e.form){r(e.form,"submit",o);if(!t.leaveSubmitMethodAlone){var n=e.form;l=n.submit;try{var u=n.submit=function(){o();n.submit=l;n.submit();n.submit=u}}catch(i){}}};t.finishInit=function(t){t.save=o;t.getTextArea=function(){return e};t.toTextArea=function(){t.toTextArea=isNaN;o();e.parentNode.removeChild(t.getWrapperElement());e.style.display="";if(e.form){D(e.form,"submit",o);if(typeof e.form.submit=="function"){e.form.submit=l}}}};e.style.display="none";var s=h(function(t){return e.parentNode.insertBefore(t,e.nextSibling)},t);return s};function ka(t){t.off=D;t.on=r;t.wheelEventPixels=Hs;t.Doc=k;t.splitLines=Si;t.countColumn=H;t.findColumn=Wi;t.isWordChar=Hi;t.Pass=Vt;t.signal=p;t.Line=We;t.changeEnd=ae;t.scrollbarModel=Ir;t.Pos=e;t.cmpPos=n;t.modes=Ci;t.mimeModes=He;t.resolveMode=ii;t.getMode=ji;t.modeExtensions=De;t.extendMode=Gl;t.copyState=we;t.startState=pn;t.innerMode=Yi;t.commands=Ze;t.keyMap=j;t.keyName=Io;t.isModifierKey=Po;t.lookupKey=Ke;t.normalizeKeyMap=ia;t.StringStream=d;t.SharedTextMarker=et;t.TextMarker=ee;t.LineWidget=tt;t.e_preventDefault=T;t.e_stopPropagation=hn;t.e_stop=vt;t.addClass=ge;t.contains=ne;t.rmClass=de;t.keyNames=J};va(h);wa(h);var ol="iter insert remove copy getEditor constructor".split(" ");for(var Et in k.prototype){if(k.prototype.hasOwnProperty(Et)&&b(ol,Et)<0){h.prototype[Et]=(function(e){return function(){return e.apply(this.doc,arguments)}})(k.prototype[Et])}};Pe(k);h.inputStyles={"textarea":g,"contenteditable":f};h.defineMode=function(e){if(!h.defaults.mode&&e!="null"){h.defaults.mode=e};Rl.apply(this,arguments)};h.defineMIME=Bl;h.defineMode("null",function(){return({token:function(e){return e.skipToEnd()}})});h.defineMIME("text/plain","null");h.defineExtension=function(e,t){h.prototype[e]=t};h.defineDocExtension=function(e,t){k.prototype[e]=t};h.fromTextArea=La;ka(h);h.version="5.32.0";return h}))); +/* ./modules/cms-ui/themes/default/script/svg-injector.min.js */(function(e,r){'use strict';var p=e.location.protocol==='file:',h=r.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#BasicStructure','1.1');function g(e){e=e.split(' ');var n={};var t=e.length,r=[];while(t--){if(!n.hasOwnProperty(e[t])){n[e[t]]=1;r.unshift(e[t])}};return r.join(' ')};var o=Array.prototype.forEach||function(e,t){if(this===void 0||this===null||typeof e!=='function'){throw new TypeError()};var r,n=this.length>>>0;for(r=0;r<n;++r){if(r in this){e.call(t,this[r],r,this)}}},t={};var f=0,i=[],n=[],c={};var l=function(e){return e.cloneNode(!0)},s=function(e,t){n[e]=n[e]||[];n[e].push(t)},d=function(e){for(var r=0,i=n[e].length;r<i;r++){(function(r){setTimeout(function(){n[e][r](l(t[e]))},0)})(r)}},v=function(r,i){if(t[r]!==undefined){if(t[r]instanceof SVGSVGElement){i(l(t[r]))} +else{s(r,i)}} +else{if(!e.XMLHttpRequest){i('Browser does not support XMLHttpRequest');return!1};t[r]={};s(r,i);var n=new XMLHttpRequest();n.onreadystatechange=function(){if(n.readyState===4){if(n.status===404||n.responseXML===null){i('Unable to load SVG file: '+r);if(p)i('Note: SVG injection ajax calls do not work locally without adjusting security setting in your browser. Or consider using a local webserver.');i();return!1};if(n.status===200||(p&&n.status===0)){if(n.responseXML instanceof Document){t[r]=n.responseXML.documentElement} +else if(DOMParser&&(DOMParser instanceof Function)){var e;try{var o=new DOMParser();e=o.parseFromString(n.responseText,'text/xml')}catch(a){e=undefined};if(!e||e.getElementsByTagName('parsererror').length){i('Unable to parse SVG file: '+r);return!1} +else{t[r]=e.documentElement}};d(r)} +else{i('There was a problem injecting the SVG: '+n.status+' '+n.statusText);return!1}}};n.open('GET',r);if(n.overrideMimeType)n.overrideMimeType('text/xml');n.send()}},u=function(t,r,l,n){var a=t.getAttribute('data-src')||t.getAttribute('src');if(!(/\.svg/i).test(a)){n('Attempted to inject a file with a non-svg extension: '+a);return};if(!h){var s=t.getAttribute('data-fallback')||t.getAttribute('data-png');if(s){t.setAttribute('src',s);n(null)} +else if(l){t.setAttribute('src',l+'/'+a.split('/').pop().replace('.svg','.png'));n(null)} +else{n('This browser does not support SVG and no PNG fallback was defined.')};return};if(i.indexOf(t)!==-1){return};i.push(t);t.setAttribute('src','');v(a,function(l){if(typeof l==='undefined'||typeof l==='string'){n(l);return!1};var j=t.getAttribute('id');if(j){l.setAttribute('id',j)};var k=t.getAttribute('title');if(k){l.setAttribute('title',k)};var E=[].concat(l.getAttribute('class')||[],'injected-svg',t.getAttribute('class')||[]).join(' ');l.setAttribute('class',g(E));var x=t.getAttribute('style');if(x){l.setAttribute('style',x)};var V=[].filter.call(t.attributes,function(e){return(/^data-\w[\w\-]*$/).test(e.name)});o.call(V,function(e){if(e.name&&e.value){l.setAttribute(e.name,e.value)}});var S={'clipPath':['clip-path'],'color-profile':['color-profile'],'cursor':['cursor'],'filter':['filter'],'linearGradient':['fill','stroke'],'marker':['marker','marker-start','marker-mid','marker-end'],'mask':['mask'],'pattern':['fill','stroke'],'radialGradient':['fill','stroke']};var A,v,w,m,b;Object.keys(S).forEach(function(e){A=e;w=S[e];v=l.querySelectorAll('defs '+A+'[id]');for(var t=0,n=v.length;t<n;t++){m=v[t].id;b=m+'-'+f;var r;o.call(w,function(e){r=l.querySelectorAll('['+e+'*="'+m+'"]');for(var t=0,n=r.length;t<n;t++){r[t].setAttribute(e,'url(#'+b+')')}});v[t].id=b}});l.removeAttribute('xmlns:a');var u=l.querySelectorAll('script'),p=[],y,d;for(var s=0,M=u.length;s<M;s++){d=u[s].getAttribute('type');if(!d||d==='application/ecmascript'||d==='application/javascript'){y=u[s].innerText||u[s].textContent;p.push(y);l.removeChild(u[s])}};if(p.length>0&&(r==='always'||(r==='once'&&!c[a]))){for(var h=0,T=p.length;h<T;h++){new Function(p[h])(e)};c[a]=!0};var G=l.querySelectorAll('style');o.call(G,function(e){e.textContent+=''});t.parentNode.replaceChild(l,t);delete i[i.indexOf(t)];t=null;f++;n(l)})},a=function(e,t,r){t=t||{};var a=t.evalScripts||'always',l=t.pngFallback||!1,n=t.each;if(e.length!==undefined){var i=0;o.call(e,function(t){u(t,a,l,function(t){if(n&&typeof n==='function')n(t);if(r&&e.length===++i)r(i)})})} +else{if(e){u(e,a,l,function(t){if(n&&typeof n==='function')n(t);if(r)r(1);e=null})} +else{if(r)r(0)}}};if(typeof module==='object'&&typeof module.exports==='object'){module.exports=exports=a} +else if(typeof define==='function'&&define.amd){define(function(){return a})} +else if(typeof e==='object'){e.SVGInjector=a}}(window,document)); +/* ./modules/editor/codemirror/lib/codemirror.min.js */// CodeMirror, copyright (c) by Marijn Haverbeke and others +// Distributed under an MIT license: http://codemirror.net/LICENSE + +// This is CodeMirror (http://codemirror.net), a code editor +// implemented in JavaScript on top of the browser's DOM. +// +// You can find some technical background for some of the code below +// at http://marijnhaverbeke.nl/blog/#cm-internals . + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.CodeMirror = factory()); +}(this, (function () { 'use strict'; + +// Kludges for bugs and behavior differences that can't be feature +// detected are enabled based on userAgent etc sniffing. + var userAgent = navigator.userAgent + var platform = navigator.platform + + var gecko = /gecko\/\d/i.test(userAgent) + var ie_upto10 = /MSIE \d/.test(userAgent) + var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent) + var edge = /Edge\/(\d+)/.exec(userAgent) + var ie = ie_upto10 || ie_11up || edge + var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]) + var webkit = !edge && /WebKit\//.test(userAgent) + var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent) + var chrome = !edge && /Chrome\//.test(userAgent) + var presto = /Opera\//.test(userAgent) + var safari = /Apple Computer/.test(navigator.vendor) + var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent) + var phantom = /PhantomJS/.test(userAgent) + + var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent) + var android = /Android/.test(userAgent) +// This is woefully incomplete. Suggestions for alternative methods welcome. + var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent) + var mac = ios || /Mac/.test(platform) + var chromeOS = /\bCrOS\b/.test(userAgent) + var windows = /win/i.test(platform) + + var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/) + if (presto_version) { presto_version = Number(presto_version[1]) } + if (presto_version && presto_version >= 15) { presto = false; webkit = true } +// Some browsers use the wrong event properties to signal cmd/ctrl on OS X + var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11)) + var captureRightClick = gecko || (ie && ie_version >= 9) + + function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") } + + var rmClass = function(node, cls) { + var current = node.className + var match = classTest(cls).exec(current) + if (match) { + var after = current.slice(match.index + match[0].length) + node.className = current.slice(0, match.index) + (after ? match[1] + after : "") + } + } + + function removeChildren(e) { + for (var count = e.childNodes.length; count > 0; --count) + { e.removeChild(e.firstChild) } + return e + } + + function removeChildrenAndAdd(parent, e) { + return removeChildren(parent).appendChild(e) + } + + function elt(tag, content, className, style) { + var e = document.createElement(tag) + if (className) { e.className = className } + if (style) { e.style.cssText = style } + if (typeof content == "string") { e.appendChild(document.createTextNode(content)) } + else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]) } } + return e + } +// wrapper for elt, which removes the elt from the accessibility tree + function eltP(tag, content, className, style) { + var e = elt(tag, content, className, style) + e.setAttribute("role", "presentation") + return e + } + + var range + if (document.createRange) { range = function(node, start, end, endNode) { + var r = document.createRange() + r.setEnd(endNode || node, end) + r.setStart(node, start) + return r + } } + else { range = function(node, start, end) { + var r = document.body.createTextRange() + try { r.moveToElementText(node.parentNode) } + catch(e) { return r } + r.collapse(true) + r.moveEnd("character", end) + r.moveStart("character", start) + return r + } } + + function contains(parent, child) { + if (child.nodeType == 3) // Android browser always returns false when child is a textnode + { child = child.parentNode } + if (parent.contains) + { return parent.contains(child) } + do { + if (child.nodeType == 11) { child = child.host } + if (child == parent) { return true } + } while (child = child.parentNode) + } + + function activeElt() { + // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement. + // IE < 10 will throw when accessed while the page is loading or in an iframe. + // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable. + var activeElement + try { + activeElement = document.activeElement + } catch(e) { + activeElement = document.body || null + } + while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) + { activeElement = activeElement.shadowRoot.activeElement } + return activeElement + } + + function addClass(node, cls) { + var current = node.className + if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls } + } + function joinClasses(a, b) { + var as = a.split(" ") + for (var i = 0; i < as.length; i++) + { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i] } } + return b + } + + var selectInput = function(node) { node.select() } + if (ios) // Mobile Safari apparently has a bug where select() is broken. + { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length } } + else if (ie) // Suppress mysterious IE10 errors + { selectInput = function(node) { try { node.select() } catch(_e) {} } } + + function bind(f) { + var args = Array.prototype.slice.call(arguments, 1) + return function(){return f.apply(null, args)} + } + + function copyObj(obj, target, overwrite) { + if (!target) { target = {} } + for (var prop in obj) + { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop))) + { target[prop] = obj[prop] } } + return target + } + +// Counts the column offset in a string, taking tabs into account. +// Used mostly to find indentation. + function countColumn(string, end, tabSize, startIndex, startValue) { + if (end == null) { + end = string.search(/[^\s\u00a0]/) + if (end == -1) { end = string.length } + } + for (var i = startIndex || 0, n = startValue || 0;;) { + var nextTab = string.indexOf("\t", i) + if (nextTab < 0 || nextTab >= end) + { return n + (end - i) } + n += nextTab - i + n += tabSize - (n % tabSize) + i = nextTab + 1 + } + } + + var Delayed = function() {this.id = null}; + Delayed.prototype.set = function (ms, f) { + clearTimeout(this.id) + this.id = setTimeout(f, ms) + }; + + function indexOf(array, elt) { + for (var i = 0; i < array.length; ++i) + { if (array[i] == elt) { return i } } + return -1 + } + +// Number of pixels added to scroller and sizer to hide scrollbar + var scrollerGap = 30 + +// Returned or thrown by various protocols to signal 'I'm not +// handling this'. + var Pass = {toString: function(){return "CodeMirror.Pass"}} + +// Reused option objects for setSelection & friends + var sel_dontScroll = {scroll: false}; + var sel_mouse = {origin: "*mouse"}; + var sel_move = {origin: "+move"}; +// The inverse of countColumn -- find the offset that corresponds to +// a particular column. + function findColumn(string, goal, tabSize) { + for (var pos = 0, col = 0;;) { + var nextTab = string.indexOf("\t", pos) + if (nextTab == -1) { nextTab = string.length } + var skipped = nextTab - pos + if (nextTab == string.length || col + skipped >= goal) + { return pos + Math.min(skipped, goal - col) } + col += nextTab - pos + col += tabSize - (col % tabSize) + pos = nextTab + 1 + if (col >= goal) { return pos } + } + } + + var spaceStrs = [""] + function spaceStr(n) { + while (spaceStrs.length <= n) + { spaceStrs.push(lst(spaceStrs) + " ") } + return spaceStrs[n] + } + + function lst(arr) { return arr[arr.length-1] } + + function map(array, f) { + var out = [] + for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i) } + return out + } + + function insertSorted(array, value, score) { + var pos = 0, priority = score(value) + while (pos < array.length && score(array[pos]) <= priority) { pos++ } + array.splice(pos, 0, value) + } + + function nothing() {} + + function createObj(base, props) { + var inst + if (Object.create) { + inst = Object.create(base) + } else { + nothing.prototype = base + inst = new nothing() + } + if (props) { copyObj(props, inst) } + return inst + } + + var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/ + function isWordCharBasic(ch) { + return /\w/.test(ch) || ch > "\x80" && + (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)) + } + function isWordChar(ch, helper) { + if (!helper) { return isWordCharBasic(ch) } + if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true } + return helper.test(ch) + } + + function isEmpty(obj) { + for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } } + return true + } + +// Extending unicode characters. A series of a non-extending char + +// any number of extending chars is treated as a single unit as far +// as editing and measuring is concerned. This is not fully correct, +// since some scripts/fonts/browsers also treat other configurations +// of code points as a group. + var extendingChars = /[\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 isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) } + +// Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range. + function skipExtendingChars(str, pos, dir) { + while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir } + return pos + } + +// Returns the value from the range [`from`; `to`] that satisfies +// `pred` and is closest to `from`. Assumes that at least `to` +// satisfies `pred`. Supports `from` being greater than `to`. + function findFirst(pred, from, to) { + // At any point we are certain `to` satisfies `pred`, don't know + // whether `from` does. + var dir = from > to ? -1 : 1 + for (;;) { + if (from == to) { return from } + var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF) + if (mid == from) { return pred(mid) ? from : to } + if (pred(mid)) { to = mid } + else { from = mid + dir } + } + } + +// The display handles the DOM integration, both for input reading +// and content drawing. It holds references to DOM nodes and +// display-related state. + + function Display(place, doc, input) { + var d = this + this.input = input + + // Covers bottom-right square when both scrollbars are present. + d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler") + d.scrollbarFiller.setAttribute("cm-not-content", "true") + // Covers bottom of gutter when coverGutterNextToScrollbar is on + // and h scrollbar is present. + d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler") + d.gutterFiller.setAttribute("cm-not-content", "true") + // Will contain the actual code, positioned to cover the viewport. + d.lineDiv = eltP("div", null, "CodeMirror-code") + // Elements are added to these to represent selection and cursors. + d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1") + d.cursorDiv = elt("div", null, "CodeMirror-cursors") + // A visibility: hidden element used to find the size of things. + d.measure = elt("div", null, "CodeMirror-measure") + // When lines outside of the viewport are measured, they are drawn in this. + d.lineMeasure = elt("div", null, "CodeMirror-measure") + // Wraps everything that needs to exist inside the vertically-padded coordinate system + d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv], + null, "position: relative; outline: none") + var lines = eltP("div", [d.lineSpace], "CodeMirror-lines") + // Moved around its parent to cover visible view. + d.mover = elt("div", [lines], null, "position: relative") + // Set to the height of the document, allowing scrolling. + d.sizer = elt("div", [d.mover], "CodeMirror-sizer") + d.sizerWidth = null + // Behavior of elts with overflow: auto and padding is + // inconsistent across browsers. This is used to ensure the + // scrollable area is big enough. + d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;") + // Will contain the gutters, if any. + d.gutters = elt("div", null, "CodeMirror-gutters") + d.lineGutter = null + // Actual scrollable element. + d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll") + d.scroller.setAttribute("tabIndex", "-1") + // The element in which the editor lives. + d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror") + + // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported) + if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0 } + if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true } + + if (place) { + if (place.appendChild) { place.appendChild(d.wrapper) } + else { place(d.wrapper) } + } + + // Current rendered range (may be bigger than the view window). + d.viewFrom = d.viewTo = doc.first + d.reportedViewFrom = d.reportedViewTo = doc.first + // Information about the rendered lines. + d.view = [] + d.renderedView = null + // Holds info about a single rendered line when it was rendered + // for measurement, while not in view. + d.externalMeasured = null + // Empty space (in pixels) above the view + d.viewOffset = 0 + d.lastWrapHeight = d.lastWrapWidth = 0 + d.updateLineNumbers = null + + d.nativeBarWidth = d.barHeight = d.barWidth = 0 + d.scrollbarsClipped = false + + // Used to only resize the line number gutter when necessary (when + // the amount of lines crosses a boundary that makes its width change) + d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null + // Set to true when a non-horizontal-scrolling line widget is + // added. As an optimization, line widget aligning is skipped when + // this is false. + d.alignWidgets = false + + d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null + + // Tracks the maximum line length so that the horizontal scrollbar + // can be kept static when scrolling. + d.maxLine = null + d.maxLineLength = 0 + d.maxLineChanged = false + + // Used for measuring wheel scrolling granularity + d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null + + // True when shift is held down. + d.shift = false + + // Used to track whether anything happened since the context menu + // was opened. + d.selForContextMenu = null + + d.activeTouch = null + + input.init(d) + } + +// Find the line object corresponding to the given line number. + function getLine(doc, n) { + n -= doc.first + if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") } + var chunk = doc + while (!chunk.lines) { + for (var i = 0;; ++i) { + var child = chunk.children[i], sz = child.chunkSize() + if (n < sz) { chunk = child; break } + n -= sz + } + } + return chunk.lines[n] + } + +// Get the part of a document between two positions, as an array of +// strings. + function getBetween(doc, start, end) { + var out = [], n = start.line + doc.iter(start.line, end.line + 1, function (line) { + var text = line.text + if (n == end.line) { text = text.slice(0, end.ch) } + if (n == start.line) { text = text.slice(start.ch) } + out.push(text) + ++n + }) + return out + } +// Get the lines between from and to, as array of strings. + function getLines(doc, from, to) { + var out = [] + doc.iter(from, to, function (line) { out.push(line.text) }) // iter aborts when callback returns truthy value + return out + } + +// Update the height of a line, propagating the height change +// upwards to parent nodes. + function updateLineHeight(line, height) { + var diff = height - line.height + if (diff) { for (var n = line; n; n = n.parent) { n.height += diff } } + } + +// Given a line object, find its line number by walking up through +// its parent links. + function lineNo(line) { + if (line.parent == null) { return null } + var cur = line.parent, no = indexOf(cur.lines, line) + for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) { + for (var i = 0;; ++i) { + if (chunk.children[i] == cur) { break } + no += chunk.children[i].chunkSize() + } + } + return no + cur.first + } + +// Find the line at the given vertical position, using the height +// information in the document tree. + function lineAtHeight(chunk, h) { + var n = chunk.first + outer: do { + for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) { + var child = chunk.children[i$1], ch = child.height + if (h < ch) { chunk = child; continue outer } + h -= ch + n += child.chunkSize() + } + return n + } while (!chunk.lines) + var i = 0 + for (; i < chunk.lines.length; ++i) { + var line = chunk.lines[i], lh = line.height + if (h < lh) { break } + h -= lh + } + return n + i + } + + function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size} + + function lineNumberFor(options, i) { + return String(options.lineNumberFormatter(i + options.firstLineNumber)) + } + +// A Pos instance represents a position within the text. + function Pos(line, ch, sticky) { + if ( sticky === void 0 ) sticky = null; + + if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) } + this.line = line + this.ch = ch + this.sticky = sticky + } + +// Compare two positions, return 0 if they are the same, a negative +// number when a is less, and a positive number otherwise. + function cmp(a, b) { return a.line - b.line || a.ch - b.ch } + + function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 } + + function copyPos(x) {return Pos(x.line, x.ch)} + function maxPos(a, b) { return cmp(a, b) < 0 ? b : a } + function minPos(a, b) { return cmp(a, b) < 0 ? a : b } + +// Most of the external API clips given positions to make sure they +// actually exist within the document. + function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))} + function clipPos(doc, pos) { + if (pos.line < doc.first) { return Pos(doc.first, 0) } + var last = doc.first + doc.size - 1 + if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) } + return clipToLen(pos, getLine(doc, pos.line).text.length) + } + function clipToLen(pos, linelen) { + var ch = pos.ch + if (ch == null || ch > linelen) { return Pos(pos.line, linelen) } + else if (ch < 0) { return Pos(pos.line, 0) } + else { return pos } + } + function clipPosArray(doc, array) { + var out = [] + for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]) } + return out + } + +// Optimize some code when these features are not used. + var sawReadOnlySpans = false; + var sawCollapsedSpans = false; + function seeReadOnlySpans() { + sawReadOnlySpans = true + } + + function seeCollapsedSpans() { + sawCollapsedSpans = true + } + +// TEXTMARKER SPANS + + function MarkedSpan(marker, from, to) { + this.marker = marker + this.from = from; this.to = to + } + +// Search an array of spans for a span matching the given marker. + function getMarkedSpanFor(spans, marker) { + if (spans) { for (var i = 0; i < spans.length; ++i) { + var span = spans[i] + if (span.marker == marker) { return span } + } } + } +// Remove a span from an array, returning undefined if no spans are +// left (we don't store arrays for lines without spans). + function removeMarkedSpan(spans, span) { + var r + for (var i = 0; i < spans.length; ++i) + { if (spans[i] != span) { (r || (r = [])).push(spans[i]) } } + return r + } +// Add a span to a line. + function addMarkedSpan(line, span) { + line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span] + span.marker.attachLine(line) + } + +// Used for the algorithm that adjusts markers for a change in the +// document. These functions cut an array of spans at a given +// character position, returning an array of remaining chunks (or +// undefined if nothing remains). + function markedSpansBefore(old, startCh, isInsert) { + var nw + if (old) { for (var i = 0; i < old.length; ++i) { + var span = old[i], marker = span.marker + var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh) + if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) { + var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh) + ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to)) + } + } } + return nw + } + function markedSpansAfter(old, endCh, isInsert) { + var nw + if (old) { for (var i = 0; i < old.length; ++i) { + var span = old[i], marker = span.marker + var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh) + if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) { + var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh) + ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh, + span.to == null ? null : span.to - endCh)) + } + } } + return nw + } + +// Given a change object, compute the new set of marker spans that +// cover the line in which the change took place. Removes spans +// entirely within the change, reconnects spans belonging to the +// same marker that appear on both sides of the change, and cuts off +// spans partially within the change. Returns an array of span +// arrays with one element for each line in (after) the change. + function stretchSpansOverChange(doc, change) { + if (change.full) { return null } + var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans + var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans + if (!oldFirst && !oldLast) { return null } + + var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0 + // Get the spans that 'stick out' on both sides + var first = markedSpansBefore(oldFirst, startCh, isInsert) + var last = markedSpansAfter(oldLast, endCh, isInsert) + + // Next, merge those two ends + var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0) + if (first) { + // Fix up .to properties of first + for (var i = 0; i < first.length; ++i) { + var span = first[i] + if (span.to == null) { + var found = getMarkedSpanFor(last, span.marker) + if (!found) { span.to = startCh } + else if (sameLine) { span.to = found.to == null ? null : found.to + offset } + } + } + } + if (last) { + // Fix up .from in last (or move them into first in case of sameLine) + for (var i$1 = 0; i$1 < last.length; ++i$1) { + var span$1 = last[i$1] + if (span$1.to != null) { span$1.to += offset } + if (span$1.from == null) { + var found$1 = getMarkedSpanFor(first, span$1.marker) + if (!found$1) { + span$1.from = offset + if (sameLine) { (first || (first = [])).push(span$1) } + } + } else { + span$1.from += offset + if (sameLine) { (first || (first = [])).push(span$1) } + } + } + } + // Make sure we didn't create any zero-length spans + if (first) { first = clearEmptySpans(first) } + if (last && last != first) { last = clearEmptySpans(last) } + + var newMarkers = [first] + if (!sameLine) { + // Fill gap with whole-line-spans + var gap = change.text.length - 2, gapMarkers + if (gap > 0 && first) + { for (var i$2 = 0; i$2 < first.length; ++i$2) + { if (first[i$2].to == null) + { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)) } } } + for (var i$3 = 0; i$3 < gap; ++i$3) + { newMarkers.push(gapMarkers) } + newMarkers.push(last) + } + return newMarkers + } + +// Remove spans that are empty and don't have a clearWhenEmpty +// option of false. + function clearEmptySpans(spans) { + for (var i = 0; i < spans.length; ++i) { + var span = spans[i] + if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false) + { spans.splice(i--, 1) } + } + if (!spans.length) { return null } + return spans + } + +// Used to 'clip' out readOnly ranges when making a change. + function removeReadOnlyRanges(doc, from, to) { + var markers = null + doc.iter(from.line, to.line + 1, function (line) { + if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) { + var mark = line.markedSpans[i].marker + if (mark.readOnly && (!markers || indexOf(markers, mark) == -1)) + { (markers || (markers = [])).push(mark) } + } } + }) + if (!markers) { return null } + var parts = [{from: from, to: to}] + for (var i = 0; i < markers.length; ++i) { + var mk = markers[i], m = mk.find(0) + for (var j = 0; j < parts.length; ++j) { + var p = parts[j] + if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue } + var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to) + if (dfrom < 0 || !mk.inclusiveLeft && !dfrom) + { newParts.push({from: p.from, to: m.from}) } + if (dto > 0 || !mk.inclusiveRight && !dto) + { newParts.push({from: m.to, to: p.to}) } + parts.splice.apply(parts, newParts) + j += newParts.length - 3 + } + } + return parts + } + +// Connect or disconnect spans from a line. + function detachMarkedSpans(line) { + var spans = line.markedSpans + if (!spans) { return } + for (var i = 0; i < spans.length; ++i) + { spans[i].marker.detachLine(line) } + line.markedSpans = null + } + function attachMarkedSpans(line, spans) { + if (!spans) { return } + for (var i = 0; i < spans.length; ++i) + { spans[i].marker.attachLine(line) } + line.markedSpans = spans + } + +// Helpers used when computing which overlapping collapsed span +// counts as the larger one. + function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 } + function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 } + +// Returns a number indicating which of two overlapping collapsed +// spans is larger (and thus includes the other). Falls back to +// comparing ids when the spans cover exactly the same range. + function compareCollapsedMarkers(a, b) { + var lenDiff = a.lines.length - b.lines.length + if (lenDiff != 0) { return lenDiff } + var aPos = a.find(), bPos = b.find() + var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b) + if (fromCmp) { return -fromCmp } + var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b) + if (toCmp) { return toCmp } + return b.id - a.id + } + +// Find out whether a line ends or starts in a collapsed span. If +// so, return the marker for that span. + function collapsedSpanAtSide(line, start) { + var sps = sawCollapsedSpans && line.markedSpans, found + if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) { + sp = sps[i] + if (sp.marker.collapsed && (start ? sp.from : sp.to) == null && + (!found || compareCollapsedMarkers(found, sp.marker) < 0)) + { found = sp.marker } + } } + return found + } + function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) } + function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) } + +// Test whether there exists a collapsed span that partially +// overlaps (covers the start or end, but not both) of a new span. +// Such overlap is not allowed. + function conflictingCollapsedRange(doc, lineNo, from, to, marker) { + var line = getLine(doc, lineNo) + var sps = sawCollapsedSpans && line.markedSpans + if (sps) { for (var i = 0; i < sps.length; ++i) { + var sp = sps[i] + if (!sp.marker.collapsed) { continue } + var found = sp.marker.find(0) + var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker) + var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker) + if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue } + if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) || + fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0)) + { return true } + } } + } + +// A visual line is a line as drawn on the screen. Folding, for +// example, can cause multiple logical lines to appear on the same +// visual line. This finds the start of the visual line that the +// given line is part of (usually that is the line itself). + function visualLine(line) { + var merged + while (merged = collapsedSpanAtStart(line)) + { line = merged.find(-1, true).line } + return line + } + + function visualLineEnd(line) { + var merged + while (merged = collapsedSpanAtEnd(line)) + { line = merged.find(1, true).line } + return line + } + +// Returns an array of logical lines that continue the visual line +// started by the argument, or undefined if there are no such lines. + function visualLineContinued(line) { + var merged, lines + while (merged = collapsedSpanAtEnd(line)) { + line = merged.find(1, true).line + ;(lines || (lines = [])).push(line) + } + return lines + } + +// Get the line number of the start of the visual line that the +// given line number is part of. + function visualLineNo(doc, lineN) { + var line = getLine(doc, lineN), vis = visualLine(line) + if (line == vis) { return lineN } + return lineNo(vis) + } + +// Get the line number of the start of the next visual line after +// the given line. + function visualLineEndNo(doc, lineN) { + if (lineN > doc.lastLine()) { return lineN } + var line = getLine(doc, lineN), merged + if (!lineIsHidden(doc, line)) { return lineN } + while (merged = collapsedSpanAtEnd(line)) + { line = merged.find(1, true).line } + return lineNo(line) + 1 + } + +// Compute whether a line is hidden. Lines count as hidden when they +// are part of a visual line that starts with another line, or when +// they are entirely covered by collapsed, non-widget span. + function lineIsHidden(doc, line) { + var sps = sawCollapsedSpans && line.markedSpans + if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) { + sp = sps[i] + if (!sp.marker.collapsed) { continue } + if (sp.from == null) { return true } + if (sp.marker.widgetNode) { continue } + if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp)) + { return true } + } } + } + function lineIsHiddenInner(doc, line, span) { + if (span.to == null) { + var end = span.marker.find(1, true) + return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker)) + } + if (span.marker.inclusiveRight && span.to == line.text.length) + { return true } + for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) { + sp = line.markedSpans[i] + if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to && + (sp.to == null || sp.to != span.from) && + (sp.marker.inclusiveLeft || span.marker.inclusiveRight) && + lineIsHiddenInner(doc, line, sp)) { return true } + } + } + +// Find the height above the given line. + function heightAtLine(lineObj) { + lineObj = visualLine(lineObj) + + var h = 0, chunk = lineObj.parent + for (var i = 0; i < chunk.lines.length; ++i) { + var line = chunk.lines[i] + if (line == lineObj) { break } + else { h += line.height } + } + for (var p = chunk.parent; p; chunk = p, p = chunk.parent) { + for (var i$1 = 0; i$1 < p.children.length; ++i$1) { + var cur = p.children[i$1] + if (cur == chunk) { break } + else { h += cur.height } + } + } + return h + } + +// Compute the character length of a line, taking into account +// collapsed ranges (see markText) that might hide parts, and join +// other lines onto it. + function lineLength(line) { + if (line.height == 0) { return 0 } + var len = line.text.length, merged, cur = line + while (merged = collapsedSpanAtStart(cur)) { + var found = merged.find(0, true) + cur = found.from.line + len += found.from.ch - found.to.ch + } + cur = line + while (merged = collapsedSpanAtEnd(cur)) { + var found$1 = merged.find(0, true) + len -= cur.text.length - found$1.from.ch + cur = found$1.to.line + len += cur.text.length - found$1.to.ch + } + return len + } + +// Find the longest line in the document. + function findMaxLine(cm) { + var d = cm.display, doc = cm.doc + d.maxLine = getLine(doc, doc.first) + d.maxLineLength = lineLength(d.maxLine) + d.maxLineChanged = true + doc.iter(function (line) { + var len = lineLength(line) + if (len > d.maxLineLength) { + d.maxLineLength = len + d.maxLine = line + } + }) + } + +// BIDI HELPERS + + function iterateBidiSections(order, from, to, f) { + if (!order) { return f(from, to, "ltr", 0) } + var found = false + for (var i = 0; i < order.length; ++i) { + var part = order[i] + if (part.from < to && part.to > from || from == to && part.to == from) { + f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i) + found = true + } + } + if (!found) { f(from, to, "ltr") } + } + + var bidiOther = null + function getBidiPartAt(order, ch, sticky) { + var found + bidiOther = null + for (var i = 0; i < order.length; ++i) { + var cur = order[i] + if (cur.from < ch && cur.to > ch) { return i } + if (cur.to == ch) { + if (cur.from != cur.to && sticky == "before") { found = i } + else { bidiOther = i } + } + if (cur.from == ch) { + if (cur.from != cur.to && sticky != "before") { found = i } + else { bidiOther = i } + } + } + return found != null ? found : bidiOther + } + +// Bidirectional ordering algorithm +// See http://unicode.org/reports/tr9/tr9-13.html for the algorithm +// that this (partially) implements. + +// One-char codes used for character types: +// L (L): Left-to-Right +// R (R): Right-to-Left +// r (AL): Right-to-Left Arabic +// 1 (EN): European Number +// + (ES): European Number Separator +// % (ET): European Number Terminator +// n (AN): Arabic Number +// , (CS): Common Number Separator +// m (NSM): Non-Spacing Mark +// b (BN): Boundary Neutral +// s (B): Paragraph Separator +// t (S): Segment Separator +// w (WS): Whitespace +// N (ON): Other Neutrals + +// Returns null if characters are ordered as they appear +// (left-to-right), or an array of sections ({from, to, level} +// objects) in the order in which they occur visually. + var bidiOrdering = (function() { + // Character types for codepoints 0 to 0xff + var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN" + // Character types for codepoints 0x600 to 0x6f9 + var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111" + function charType(code) { + if (code <= 0xf7) { return lowTypes.charAt(code) } + else if (0x590 <= code && code <= 0x5f4) { return "R" } + else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) } + else if (0x6ee <= code && code <= 0x8ac) { return "r" } + else if (0x2000 <= code && code <= 0x200b) { return "w" } + else if (code == 0x200c) { return "b" } + else { return "L" } + } + + var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/ + var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/ + + function BidiSpan(level, from, to) { + this.level = level + this.from = from; this.to = to + } + + return function(str, direction) { + var outerType = direction == "ltr" ? "L" : "R" + + if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false } + var len = str.length, types = [] + for (var i = 0; i < len; ++i) + { types.push(charType(str.charCodeAt(i))) } + + // W1. Examine each non-spacing mark (NSM) in the level run, and + // change the type of the NSM to the type of the previous + // character. If the NSM is at the start of the level run, it will + // get the type of sor. + for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) { + var type = types[i$1] + if (type == "m") { types[i$1] = prev } + else { prev = type } + } + + // W2. Search backwards from each instance of a European number + // until the first strong type (R, L, AL, or sor) is found. If an + // AL is found, change the type of the European number to Arabic + // number. + // W3. Change all ALs to R. + for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) { + var type$1 = types[i$2] + if (type$1 == "1" && cur == "r") { types[i$2] = "n" } + else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R" } } + } + + // W4. A single European separator between two European numbers + // changes to a European number. A single common separator between + // two numbers of the same type changes to that type. + for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) { + var type$2 = types[i$3] + if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1" } + else if (type$2 == "," && prev$1 == types[i$3+1] && + (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1 } + prev$1 = type$2 + } + + // W5. A sequence of European terminators adjacent to European + // numbers changes to all European numbers. + // W6. Otherwise, separators and terminators change to Other + // Neutral. + for (var i$4 = 0; i$4 < len; ++i$4) { + var type$3 = types[i$4] + if (type$3 == ",") { types[i$4] = "N" } + else if (type$3 == "%") { + var end = (void 0) + for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {} + var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N" + for (var j = i$4; j < end; ++j) { types[j] = replace } + i$4 = end - 1 + } + } + + // W7. Search backwards from each instance of a European number + // until the first strong type (R, L, or sor) is found. If an L is + // found, then change the type of the European number to L. + for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) { + var type$4 = types[i$5] + if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L" } + else if (isStrong.test(type$4)) { cur$1 = type$4 } + } + + // N1. A sequence of neutrals takes the direction of the + // surrounding strong text if the text on both sides has the same + // direction. European and Arabic numbers act as if they were R in + // terms of their influence on neutrals. Start-of-level-run (sor) + // and end-of-level-run (eor) are used at level run boundaries. + // N2. Any remaining neutrals take the embedding direction. + for (var i$6 = 0; i$6 < len; ++i$6) { + if (isNeutral.test(types[i$6])) { + var end$1 = (void 0) + for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {} + var before = (i$6 ? types[i$6-1] : outerType) == "L" + var after = (end$1 < len ? types[end$1] : outerType) == "L" + var replace$1 = before == after ? (before ? "L" : "R") : outerType + for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1 } + i$6 = end$1 - 1 + } + } + + // Here we depart from the documented algorithm, in order to avoid + // building up an actual levels array. Since there are only three + // levels (0, 1, 2) in an implementation that doesn't take + // explicit embedding into account, we can build up the order on + // the fly, without following the level-based algorithm. + var order = [], m + for (var i$7 = 0; i$7 < len;) { + if (countsAsLeft.test(types[i$7])) { + var start = i$7 + for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {} + order.push(new BidiSpan(0, start, i$7)) + } else { + var pos = i$7, at = order.length + for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {} + for (var j$2 = pos; j$2 < i$7;) { + if (countsAsNum.test(types[j$2])) { + if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)) } + var nstart = j$2 + for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {} + order.splice(at, 0, new BidiSpan(2, nstart, j$2)) + pos = j$2 + } else { ++j$2 } + } + if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)) } + } + } + if (direction == "ltr") { + if (order[0].level == 1 && (m = str.match(/^\s+/))) { + order[0].from = m[0].length + order.unshift(new BidiSpan(0, 0, m[0].length)) + } + if (lst(order).level == 1 && (m = str.match(/\s+$/))) { + lst(order).to -= m[0].length + order.push(new BidiSpan(0, len - m[0].length, len)) + } + } + + return direction == "rtl" ? order.reverse() : order + } + })() + +// Get the bidi ordering for the given line (and cache it). Returns +// false for lines that are fully left-to-right, and an array of +// BidiSpan objects otherwise. + function getOrder(line, direction) { + var order = line.order + if (order == null) { order = line.order = bidiOrdering(line.text, direction) } + return order + } + +// EVENT HANDLING + +// Lightweight event framework. on/off also work on DOM nodes, +// registering native DOM handlers. + + var noHandlers = [] + + var on = function(emitter, type, f) { + if (emitter.addEventListener) { + emitter.addEventListener(type, f, false) + } else if (emitter.attachEvent) { + emitter.attachEvent("on" + type, f) + } else { + var map = emitter._handlers || (emitter._handlers = {}) + map[type] = (map[type] || noHandlers).concat(f) + } + } + + function getHandlers(emitter, type) { + return emitter._handlers && emitter._handlers[type] || noHandlers + } + + function off(emitter, type, f) { + if (emitter.removeEventListener) { + emitter.removeEventListener(type, f, false) + } else if (emitter.detachEvent) { + emitter.detachEvent("on" + type, f) + } else { + var map = emitter._handlers, arr = map && map[type] + if (arr) { + var index = indexOf(arr, f) + if (index > -1) + { map[type] = arr.slice(0, index).concat(arr.slice(index + 1)) } + } + } + } + + function signal(emitter, type /*, values...*/) { + var handlers = getHandlers(emitter, type) + if (!handlers.length) { return } + var args = Array.prototype.slice.call(arguments, 2) + for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args) } + } + +// The DOM events that CodeMirror handles can be overridden by +// registering a (non-DOM) handler on the editor for the event name, +// and preventDefault-ing the event in that handler. + function signalDOMEvent(cm, e, override) { + if (typeof e == "string") + { e = {type: e, preventDefault: function() { this.defaultPrevented = true }} } + signal(cm, override || e.type, cm, e) + return e_defaultPrevented(e) || e.codemirrorIgnore + } + + function signalCursorActivity(cm) { + var arr = cm._handlers && cm._handlers.cursorActivity + if (!arr) { return } + var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []) + for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1) + { set.push(arr[i]) } } + } + + function hasHandler(emitter, type) { + return getHandlers(emitter, type).length > 0 + } + +// Add on and off methods to a constructor's prototype, to make +// registering events on such objects more convenient. + function eventMixin(ctor) { + ctor.prototype.on = function(type, f) {on(this, type, f)} + ctor.prototype.off = function(type, f) {off(this, type, f)} + } + +// Due to the fact that we still support jurassic IE versions, some +// compatibility wrappers are needed. + + function e_preventDefault(e) { + if (e.preventDefault) { e.preventDefault() } + else { e.returnValue = false } + } + function e_stopPropagation(e) { + if (e.stopPropagation) { e.stopPropagation() } + else { e.cancelBubble = true } + } + function e_defaultPrevented(e) { + return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false + } + function e_stop(e) {e_preventDefault(e); e_stopPropagation(e)} + + function e_target(e) {return e.target || e.srcElement} + function e_button(e) { + var b = e.which + if (b == null) { + if (e.button & 1) { b = 1 } + else if (e.button & 2) { b = 3 } + else if (e.button & 4) { b = 2 } + } + if (mac && e.ctrlKey && b == 1) { b = 3 } + return b + } + +// Detect drag-and-drop + var dragAndDrop = function() { + // There is *some* kind of drag-and-drop support in IE6-8, but I + // couldn't get it to work yet. + if (ie && ie_version < 9) { return false } + var div = elt('div') + return "draggable" in div || "dragDrop" in div + }() + + var zwspSupported + function zeroWidthElement(measure) { + if (zwspSupported == null) { + var test = elt("span", "\u200b") + removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")])) + if (measure.firstChild.offsetHeight != 0) + { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8) } + } + var node = zwspSupported ? elt("span", "\u200b") : + elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px") + node.setAttribute("cm-text", "") + return node + } + +// Feature-detect IE's crummy client rect reporting for bidi text + var badBidiRects + function hasBadBidiRects(measure) { + if (badBidiRects != null) { return badBidiRects } + var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA")) + var r0 = range(txt, 0, 1).getBoundingClientRect() + var r1 = range(txt, 1, 2).getBoundingClientRect() + removeChildren(measure) + if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780) + return badBidiRects = (r1.right - r0.right < 3) + } + +// See if "".split is the broken IE version, if so, provide an +// alternative way to split lines. + var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) { + var pos = 0, result = [], l = string.length + while (pos <= l) { + var nl = string.indexOf("\n", pos) + if (nl == -1) { nl = string.length } + var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl) + var rt = line.indexOf("\r") + if (rt != -1) { + result.push(line.slice(0, rt)) + pos += rt + 1 + } else { + result.push(line) + pos = nl + 1 + } + } + return result + } : function (string) { return string.split(/\r\n?|\n/); } + + var hasSelection = window.getSelection ? function (te) { + try { return te.selectionStart != te.selectionEnd } + catch(e) { return false } + } : function (te) { + var range + try {range = te.ownerDocument.selection.createRange()} + catch(e) {} + if (!range || range.parentElement() != te) { return false } + return range.compareEndPoints("StartToEnd", range) != 0 + } + + var hasCopyEvent = (function () { + var e = elt("div") + if ("oncopy" in e) { return true } + e.setAttribute("oncopy", "return;") + return typeof e.oncopy == "function" + })() + + var badZoomedRects = null + function hasBadZoomedRects(measure) { + if (badZoomedRects != null) { return badZoomedRects } + var node = removeChildrenAndAdd(measure, elt("span", "x")) + var normal = node.getBoundingClientRect() + var fromRange = range(node, 0, 1).getBoundingClientRect() + return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1 + } + + var modes = {}; + var mimeModes = {}; +// Extra arguments are stored as the mode's dependencies, which is +// used by (legacy) mechanisms like loadmode.js to automatically +// load a mode. (Preferred mechanism is the require/define calls.) + function defineMode(name, mode) { + if (arguments.length > 2) + { mode.dependencies = Array.prototype.slice.call(arguments, 2) } + modes[name] = mode + } + + function defineMIME(mime, spec) { + mimeModes[mime] = spec + } + +// Given a MIME type, a {name, ...options} config object, or a name +// string, return a mode config object. + function resolveMode(spec) { + if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) { + spec = mimeModes[spec] + } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) { + var found = mimeModes[spec.name] + if (typeof found == "string") { found = {name: found} } + spec = createObj(found, spec) + spec.name = found.name + } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) { + return resolveMode("application/xml") + } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) { + return resolveMode("application/json") + } + if (typeof spec == "string") { return {name: spec} } + else { return spec || {name: "null"} } + } + +// Given a mode spec (anything that resolveMode accepts), find and +// initialize an actual mode object. + function getMode(options, spec) { + spec = resolveMode(spec) + var mfactory = modes[spec.name] + if (!mfactory) { return getMode(options, "text/plain") } + var modeObj = mfactory(options, spec) + if (modeExtensions.hasOwnProperty(spec.name)) { + var exts = modeExtensions[spec.name] + for (var prop in exts) { + if (!exts.hasOwnProperty(prop)) { continue } + if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop] } + modeObj[prop] = exts[prop] + } + } + modeObj.name = spec.name + if (spec.helperType) { modeObj.helperType = spec.helperType } + if (spec.modeProps) { for (var prop$1 in spec.modeProps) + { modeObj[prop$1] = spec.modeProps[prop$1] } } + + return modeObj + } + +// This can be used to attach properties to mode objects from +// outside the actual mode definition. + var modeExtensions = {} + function extendMode(mode, properties) { + var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {}) + copyObj(properties, exts) + } + + function copyState(mode, state) { + if (state === true) { return state } + if (mode.copyState) { return mode.copyState(state) } + var nstate = {} + for (var n in state) { + var val = state[n] + if (val instanceof Array) { val = val.concat([]) } + nstate[n] = val + } + return nstate + } + +// Given a mode and a state (for that mode), find the inner mode and +// state at the position that the state refers to. + function innerMode(mode, state) { + var info + while (mode.innerMode) { + info = mode.innerMode(state) + if (!info || info.mode == mode) { break } + state = info.state + mode = info.mode + } + return info || {mode: mode, state: state} + } + + function startState(mode, a1, a2) { + return mode.startState ? mode.startState(a1, a2) : true + } + +// STRING STREAM + +// Fed to the mode parsers, provides helper functions to make +// parsers more succinct. + + var StringStream = function(string, tabSize, lineOracle) { + this.pos = this.start = 0 + this.string = string + this.tabSize = tabSize || 8 + this.lastColumnPos = this.lastColumnValue = 0 + this.lineStart = 0 + this.lineOracle = lineOracle + }; + + StringStream.prototype.eol = function () {return this.pos >= this.string.length}; + StringStream.prototype.sol = function () {return this.pos == this.lineStart}; + StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined}; + StringStream.prototype.next = function () { + if (this.pos < this.string.length) + { return this.string.charAt(this.pos++) } + }; + StringStream.prototype.eat = function (match) { + var ch = this.string.charAt(this.pos) + var ok + if (typeof match == "string") { ok = ch == match } + else { ok = ch && (match.test ? match.test(ch) : match(ch)) } + if (ok) {++this.pos; return ch} + }; + StringStream.prototype.eatWhile = function (match) { + var start = this.pos + while (this.eat(match)){} + return this.pos > start + }; + StringStream.prototype.eatSpace = function () { + var this$1 = this; + + var start = this.pos + while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this$1.pos } + return this.pos > start + }; + StringStream.prototype.skipToEnd = function () {this.pos = this.string.length}; + StringStream.prototype.skipTo = function (ch) { + var found = this.string.indexOf(ch, this.pos) + if (found > -1) {this.pos = found; return true} + }; + StringStream.prototype.backUp = function (n) {this.pos -= n}; + StringStream.prototype.column = function () { + if (this.lastColumnPos < this.start) { + this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue) + this.lastColumnPos = this.start + } + return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0) + }; + StringStream.prototype.indentation = function () { + return countColumn(this.string, null, this.tabSize) - + (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0) + }; + StringStream.prototype.match = function (pattern, consume, caseInsensitive) { + if (typeof pattern == "string") { + var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; } + var substr = this.string.substr(this.pos, pattern.length) + if (cased(substr) == cased(pattern)) { + if (consume !== false) { this.pos += pattern.length } + return true + } + } else { + var match = this.string.slice(this.pos).match(pattern) + if (match && match.index > 0) { return null } + if (match && consume !== false) { this.pos += match[0].length } + return match + } + }; + StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)}; + StringStream.prototype.hideFirstChars = function (n, inner) { + this.lineStart += n + try { return inner() } + finally { this.lineStart -= n } + }; + StringStream.prototype.lookAhead = function (n) { + var oracle = this.lineOracle + return oracle && oracle.lookAhead(n) + }; + StringStream.prototype.baseToken = function () { + var oracle = this.lineOracle + return oracle && oracle.baseToken(this.pos) + }; + + var SavedContext = function(state, lookAhead) { + this.state = state + this.lookAhead = lookAhead + }; + + var Context = function(doc, state, line, lookAhead) { + this.state = state + this.doc = doc + this.line = line + this.maxLookAhead = lookAhead || 0 + this.baseTokens = null + this.baseTokenPos = 1 + }; + + Context.prototype.lookAhead = function (n) { + var line = this.doc.getLine(this.line + n) + if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n } + return line + }; + + Context.prototype.baseToken = function (n) { + var this$1 = this; + + if (!this.baseTokens) { return null } + while (this.baseTokens[this.baseTokenPos] <= n) + { this$1.baseTokenPos += 2 } + var type = this.baseTokens[this.baseTokenPos + 1] + return {type: type && type.replace(/( |^)overlay .*/, ""), + size: this.baseTokens[this.baseTokenPos] - n} + }; + + Context.prototype.nextLine = function () { + this.line++ + if (this.maxLookAhead > 0) { this.maxLookAhead-- } + }; + + Context.fromSaved = function (doc, saved, line) { + if (saved instanceof SavedContext) + { return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) } + else + { return new Context(doc, copyState(doc.mode, saved), line) } + }; + + Context.prototype.save = function (copy) { + var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state + return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state + }; + + +// Compute a style array (an array starting with a mode generation +// -- for invalidation -- followed by pairs of end positions and +// style strings), which is used to highlight the tokens on the +// line. + function highlightLine(cm, line, context, forceToEnd) { + // A styles array always starts with a number identifying the + // mode/overlays that it is based on (for easy invalidation). + var st = [cm.state.modeGen], lineClasses = {} + // Compute the base array of styles + runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); }, + lineClasses, forceToEnd) + var state = context.state + + // Run overlays, adjust style array. + var loop = function ( o ) { + context.baseTokens = st + var overlay = cm.state.overlays[o], i = 1, at = 0 + context.state = true + runMode(cm, line.text, overlay.mode, context, function (end, style) { + var start = i + // Ensure there's a token end at the current position, and that i points at it + while (at < end) { + var i_end = st[i] + if (i_end > end) + { st.splice(i, 1, end, st[i+1], i_end) } + i += 2 + at = Math.min(end, i_end) + } + if (!style) { return } + if (overlay.opaque) { + st.splice(start, i - start, end, "overlay " + style) + i = start + 2 + } else { + for (; start < i; start += 2) { + var cur = st[start+1] + st[start+1] = (cur ? cur + " " : "") + "overlay " + style + } + } + }, lineClasses) + context.state = state + context.baseTokens = null + context.baseTokenPos = 1 + }; + + for (var o = 0; o < cm.state.overlays.length; ++o) loop( o ); + + return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null} + } + + function getLineStyles(cm, line, updateFrontier) { + if (!line.styles || line.styles[0] != cm.state.modeGen) { + var context = getContextBefore(cm, lineNo(line)) + var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state) + var result = highlightLine(cm, line, context) + if (resetState) { context.state = resetState } + line.stateAfter = context.save(!resetState) + line.styles = result.styles + if (result.classes) { line.styleClasses = result.classes } + else if (line.styleClasses) { line.styleClasses = null } + if (updateFrontier === cm.doc.highlightFrontier) + { cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier) } + } + return line.styles + } + + function getContextBefore(cm, n, precise) { + var doc = cm.doc, display = cm.display + if (!doc.mode.startState) { return new Context(doc, true, n) } + var start = findStartLine(cm, n, precise) + var saved = start > doc.first && getLine(doc, start - 1).stateAfter + var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start) + + doc.iter(start, n, function (line) { + processLine(cm, line.text, context) + var pos = context.line + line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null + context.nextLine() + }) + if (precise) { doc.modeFrontier = context.line } + return context + } + +// Lightweight form of highlight -- proceed over this line and +// update state, but don't save a style array. Used for lines that +// aren't currently visible. + function processLine(cm, text, context, startAt) { + var mode = cm.doc.mode + var stream = new StringStream(text, cm.options.tabSize, context) + stream.start = stream.pos = startAt || 0 + if (text == "") { callBlankLine(mode, context.state) } + while (!stream.eol()) { + readToken(mode, stream, context.state) + stream.start = stream.pos + } + } + + function callBlankLine(mode, state) { + if (mode.blankLine) { return mode.blankLine(state) } + if (!mode.innerMode) { return } + var inner = innerMode(mode, state) + if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) } + } + + function readToken(mode, stream, state, inner) { + for (var i = 0; i < 10; i++) { + if (inner) { inner[0] = innerMode(mode, state).mode } + var style = mode.token(stream, state) + if (stream.pos > stream.start) { return style } + } + throw new Error("Mode " + mode.name + " failed to advance stream.") + } + + var Token = function(stream, type, state) { + this.start = stream.start; this.end = stream.pos + this.string = stream.current() + this.type = type || null + this.state = state + }; + +// Utility for getTokenAt and getLineTokens + function takeToken(cm, pos, precise, asArray) { + var doc = cm.doc, mode = doc.mode, style + pos = clipPos(doc, pos) + var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise) + var stream = new StringStream(line.text, cm.options.tabSize, context), tokens + if (asArray) { tokens = [] } + while ((asArray || stream.pos < pos.ch) && !stream.eol()) { + stream.start = stream.pos + style = readToken(mode, stream, context.state) + if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))) } + } + return asArray ? tokens : new Token(stream, style, context.state) + } + + function extractLineClasses(type, output) { + if (type) { for (;;) { + var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/) + if (!lineClass) { break } + type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length) + var prop = lineClass[1] ? "bgClass" : "textClass" + if (output[prop] == null) + { output[prop] = lineClass[2] } + else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop])) + { output[prop] += " " + lineClass[2] } + } } + return type + } + +// Run the given mode's parser over a line, calling f for each token. + function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) { + var flattenSpans = mode.flattenSpans + if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans } + var curStart = 0, curStyle = null + var stream = new StringStream(text, cm.options.tabSize, context), style + var inner = cm.options.addModeClass && [null] + if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses) } + while (!stream.eol()) { + if (stream.pos > cm.options.maxHighlightLength) { + flattenSpans = false + if (forceToEnd) { processLine(cm, text, context, stream.pos) } + stream.pos = text.length + style = null + } else { + style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses) + } + if (inner) { + var mName = inner[0].name + if (mName) { style = "m-" + (style ? mName + " " + style : mName) } + } + if (!flattenSpans || curStyle != style) { + while (curStart < stream.start) { + curStart = Math.min(stream.start, curStart + 5000) + f(curStart, curStyle) + } + curStyle = style + } + stream.start = stream.pos + } + while (curStart < stream.pos) { + // Webkit seems to refuse to render text nodes longer than 57444 + // characters, and returns inaccurate measurements in nodes + // starting around 5000 chars. + var pos = Math.min(stream.pos, curStart + 5000) + f(pos, curStyle) + curStart = pos + } + } + +// Finds the line to start with when starting a parse. Tries to +// find a line with a stateAfter, so that it can start with a +// valid state. If that fails, it returns the line with the +// smallest indentation, which tends to need the least context to +// parse correctly. + function findStartLine(cm, n, precise) { + var minindent, minline, doc = cm.doc + var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100) + for (var search = n; search > lim; --search) { + if (search <= doc.first) { return doc.first } + var line = getLine(doc, search - 1), after = line.stateAfter + if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier)) + { return search } + var indented = countColumn(line.text, null, cm.options.tabSize) + if (minline == null || minindent > indented) { + minline = search - 1 + minindent = indented + } + } + return minline + } + + function retreatFrontier(doc, n) { + doc.modeFrontier = Math.min(doc.modeFrontier, n) + if (doc.highlightFrontier < n - 10) { return } + var start = doc.first + for (var line = n - 1; line > start; line--) { + var saved = getLine(doc, line).stateAfter + // change is on 3 + // state on line 1 looked ahead 2 -- so saw 3 + // test 1 + 2 < 3 should cover this + if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) { + start = line + 1 + break + } + } + doc.highlightFrontier = Math.min(doc.highlightFrontier, start) + } + +// LINE DATA STRUCTURE + +// Line objects. These hold state related to a line, including +// highlighting info (the styles array). + var Line = function(text, markedSpans, estimateHeight) { + this.text = text + attachMarkedSpans(this, markedSpans) + this.height = estimateHeight ? estimateHeight(this) : 1 + }; + + Line.prototype.lineNo = function () { return lineNo(this) }; + eventMixin(Line) + +// Change the content (text, markers) of a line. Automatically +// invalidates cached information and tries to re-estimate the +// line's height. + function updateLine(line, text, markedSpans, estimateHeight) { + line.text = text + if (line.stateAfter) { line.stateAfter = null } + if (line.styles) { line.styles = null } + if (line.order != null) { line.order = null } + detachMarkedSpans(line) + attachMarkedSpans(line, markedSpans) + var estHeight = estimateHeight ? estimateHeight(line) : 1 + if (estHeight != line.height) { updateLineHeight(line, estHeight) } + } + +// Detach a line from the document tree and its markers. + function cleanUpLine(line) { + line.parent = null + detachMarkedSpans(line) + } + +// Convert a style as returned by a mode (either null, or a string +// containing one or more styles) to a CSS style. This is cached, +// and also looks for line-wide styles. + var styleToClassCache = {}; + var styleToClassCacheWithMode = {}; + function interpretTokenStyle(style, options) { + if (!style || /^\s*$/.test(style)) { return null } + var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache + return cache[style] || + (cache[style] = style.replace(/\S+/g, "cm-$&")) + } + +// Render the DOM representation of the text of a line. Also builds +// up a 'line map', which points at the DOM nodes that represent +// specific stretches of text, and is used by the measuring code. +// The returned object contains the DOM node, this map, and +// information about line-wide styles that were set by the mode. + function buildLineContent(cm, lineView) { + // The padding-right forces the element to have a 'border', which + // is needed on Webkit to be able to get line-level bounding + // rectangles for it (in measureChar). + var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null) + var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content, + col: 0, pos: 0, cm: cm, + trailingSpace: false, + splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")} + lineView.measure = {} + + // Iterate over the logical lines that make up this visual line. + for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) { + var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0) + builder.pos = 0 + builder.addToken = buildToken + // Optionally wire in some hacks into the token-rendering + // algorithm, to deal with browser quirks. + if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) + { builder.addToken = buildTokenBadBidi(builder.addToken, order) } + builder.map = [] + var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line) + insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate)) + if (line.styleClasses) { + if (line.styleClasses.bgClass) + { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "") } + if (line.styleClasses.textClass) + { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "") } + } + + // Ensure at least a single node is present, for measuring. + if (builder.map.length == 0) + { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))) } + + // Store the map and a cache object for the current logical line + if (i == 0) { + lineView.measure.map = builder.map + lineView.measure.cache = {} + } else { + ;(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map) + ;(lineView.measure.caches || (lineView.measure.caches = [])).push({}) + } + } + + // See issue #2901 + if (webkit) { + var last = builder.content.lastChild + if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab"))) + { builder.content.className = "cm-tab-wrap-hack" } + } + + signal(cm, "renderLine", cm, lineView.line, builder.pre) + if (builder.pre.className) + { builder.textClass = joinClasses(builder.pre.className, builder.textClass || "") } + + return builder + } + + function defaultSpecialCharPlaceholder(ch) { + var token = elt("span", "\u2022", "cm-invalidchar") + token.title = "\\u" + ch.charCodeAt(0).toString(16) + token.setAttribute("aria-label", token.title) + return token + } + +// Build up the DOM representation for a single token, and add it to +// the line map. Takes care to render special characters separately. + function buildToken(builder, text, style, startStyle, endStyle, title, css) { + if (!text) { return } + var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text + var special = builder.cm.state.specialChars, mustWrap = false + var content + if (!special.test(text)) { + builder.col += text.length + content = document.createTextNode(displayText) + builder.map.push(builder.pos, builder.pos + text.length, content) + if (ie && ie_version < 9) { mustWrap = true } + builder.pos += text.length + } else { + content = document.createDocumentFragment() + var pos = 0 + while (true) { + special.lastIndex = pos + var m = special.exec(text) + var skipped = m ? m.index - pos : text.length - pos + if (skipped) { + var txt = document.createTextNode(displayText.slice(pos, pos + skipped)) + if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])) } + else { content.appendChild(txt) } + builder.map.push(builder.pos, builder.pos + skipped, txt) + builder.col += skipped + builder.pos += skipped + } + if (!m) { break } + pos += skipped + 1 + var txt$1 = (void 0) + if (m[0] == "\t") { + var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize + txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab")) + txt$1.setAttribute("role", "presentation") + txt$1.setAttribute("cm-text", "\t") + builder.col += tabWidth + } else if (m[0] == "\r" || m[0] == "\n") { + txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar")) + txt$1.setAttribute("cm-text", m[0]) + builder.col += 1 + } else { + txt$1 = builder.cm.options.specialCharPlaceholder(m[0]) + txt$1.setAttribute("cm-text", m[0]) + if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])) } + else { content.appendChild(txt$1) } + builder.col += 1 + } + builder.map.push(builder.pos, builder.pos + 1, txt$1) + builder.pos++ + } + } + builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32 + if (style || startStyle || endStyle || mustWrap || css) { + var fullStyle = style || "" + if (startStyle) { fullStyle += startStyle } + if (endStyle) { fullStyle += endStyle } + var token = elt("span", [content], fullStyle, css) + if (title) { token.title = title } + return builder.content.appendChild(token) + } + builder.content.appendChild(content) + } + + function splitSpaces(text, trailingBefore) { + if (text.length > 1 && !/ /.test(text)) { return text } + var spaceBefore = trailingBefore, result = "" + for (var i = 0; i < text.length; i++) { + var ch = text.charAt(i) + if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) + { ch = "\u00a0" } + result += ch + spaceBefore = ch == " " + } + return result + } + +// Work around nonsense dimensions being reported for stretches of +// right-to-left text. + function buildTokenBadBidi(inner, order) { + return function (builder, text, style, startStyle, endStyle, title, css) { + style = style ? style + " cm-force-border" : "cm-force-border" + var start = builder.pos, end = start + text.length + for (;;) { + // Find the part that overlaps with the start of this text + var part = (void 0) + for (var i = 0; i < order.length; i++) { + part = order[i] + if (part.to > start && part.from <= start) { break } + } + if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, title, css) } + inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css) + startStyle = null + text = text.slice(part.to - start) + start = part.to + } + } + } + + function buildCollapsedSpan(builder, size, marker, ignoreWidget) { + var widget = !ignoreWidget && marker.widgetNode + if (widget) { builder.map.push(builder.pos, builder.pos + size, widget) } + if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) { + if (!widget) + { widget = builder.content.appendChild(document.createElement("span")) } + widget.setAttribute("cm-marker", marker.id) + } + if (widget) { + builder.cm.display.input.setUneditable(widget) + builder.content.appendChild(widget) + } + builder.pos += size + builder.trailingSpace = false + } + +// Outputs a number of spans to make up a line, taking highlighting +// and marked text into account. + function insertLineContent(line, builder, styles) { + var spans = line.markedSpans, allText = line.text, at = 0 + if (!spans) { + for (var i$1 = 1; i$1 < styles.length; i$1+=2) + { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)) } + return + } + + var len = allText.length, pos = 0, i = 1, text = "", style, css + var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed + for (;;) { + if (nextChange == pos) { // Update current marker set + spanStyle = spanEndStyle = spanStartStyle = title = css = "" + collapsed = null; nextChange = Infinity + var foundBookmarks = [], endStyles = (void 0) + for (var j = 0; j < spans.length; ++j) { + var sp = spans[j], m = sp.marker + if (m.type == "bookmark" && sp.from == pos && m.widgetNode) { + foundBookmarks.push(m) + } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) { + if (sp.to != null && sp.to != pos && nextChange > sp.to) { + nextChange = sp.to + spanEndStyle = "" + } + if (m.className) { spanStyle += " " + m.className } + if (m.css) { css = (css ? css + ";" : "") + m.css } + if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle } + if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to) } + if (m.title && !title) { title = m.title } + if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0)) + { collapsed = sp } + } else if (sp.from > pos && nextChange > sp.from) { + nextChange = sp.from + } + } + if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2) + { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1] } } } + + if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2) + { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]) } } + if (collapsed && (collapsed.from || 0) == pos) { + buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos, + collapsed.marker, collapsed.from == null) + if (collapsed.to == null) { return } + if (collapsed.to == pos) { collapsed = false } + } + } + if (pos >= len) { break } + + var upto = Math.min(len, nextChange) + while (true) { + if (text) { + var end = pos + text.length + if (!collapsed) { + var tokenText = end > upto ? text.slice(0, upto - pos) : text + builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle, + spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css) + } + if (end >= upto) {text = text.slice(upto - pos); pos = upto; break} + pos = end + spanStartStyle = "" + } + text = allText.slice(at, at = styles[i++]) + style = interpretTokenStyle(styles[i++], builder.cm.options) + } + } + } + + +// These objects are used to represent the visible (currently drawn) +// part of the document. A LineView may correspond to multiple +// logical lines, if those are connected by collapsed ranges. + function LineView(doc, line, lineN) { + // The starting line + this.line = line + // Continuing lines, if any + this.rest = visualLineContinued(line) + // Number of logical lines in this visual line + this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1 + this.node = this.text = null + this.hidden = lineIsHidden(doc, line) + } + +// Create a range of LineView objects for the given lines. + function buildViewArray(cm, from, to) { + var array = [], nextPos + for (var pos = from; pos < to; pos = nextPos) { + var view = new LineView(cm.doc, getLine(cm.doc, pos), pos) + nextPos = pos + view.size + array.push(view) + } + return array + } + + var operationGroup = null + + function pushOperation(op) { + if (operationGroup) { + operationGroup.ops.push(op) + } else { + op.ownsGroup = operationGroup = { + ops: [op], + delayedCallbacks: [] + } + } + } + + function fireCallbacksForOps(group) { + // Calls delayed callbacks and cursorActivity handlers until no + // new ones appear + var callbacks = group.delayedCallbacks, i = 0 + do { + for (; i < callbacks.length; i++) + { callbacks[i].call(null) } + for (var j = 0; j < group.ops.length; j++) { + var op = group.ops[j] + if (op.cursorActivityHandlers) + { while (op.cursorActivityCalled < op.cursorActivityHandlers.length) + { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm) } } + } + } while (i < callbacks.length) + } + + function finishOperation(op, endCb) { + var group = op.ownsGroup + if (!group) { return } + + try { fireCallbacksForOps(group) } + finally { + operationGroup = null + endCb(group) + } + } + + var orphanDelayedCallbacks = null + +// Often, we want to signal events at a point where we are in the +// middle of some work, but don't want the handler to start calling +// other methods on the editor, which might be in an inconsistent +// state or simply not expect any other events to happen. +// signalLater looks whether there are any handlers, and schedules +// them to be executed when the last operation ends, or, if no +// operation is active, when a timeout fires. + function signalLater(emitter, type /*, values...*/) { + var arr = getHandlers(emitter, type) + if (!arr.length) { return } + var args = Array.prototype.slice.call(arguments, 2), list + if (operationGroup) { + list = operationGroup.delayedCallbacks + } else if (orphanDelayedCallbacks) { + list = orphanDelayedCallbacks + } else { + list = orphanDelayedCallbacks = [] + setTimeout(fireOrphanDelayed, 0) + } + var loop = function ( i ) { + list.push(function () { return arr[i].apply(null, args); }) + }; + + for (var i = 0; i < arr.length; ++i) + loop( i ); + } + + function fireOrphanDelayed() { + var delayed = orphanDelayedCallbacks + orphanDelayedCallbacks = null + for (var i = 0; i < delayed.length; ++i) { delayed[i]() } + } + +// When an aspect of a line changes, a string is added to +// lineView.changes. This updates the relevant part of the line's +// DOM structure. + function updateLineForChanges(cm, lineView, lineN, dims) { + for (var j = 0; j < lineView.changes.length; j++) { + var type = lineView.changes[j] + if (type == "text") { updateLineText(cm, lineView) } + else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims) } + else if (type == "class") { updateLineClasses(cm, lineView) } + else if (type == "widget") { updateLineWidgets(cm, lineView, dims) } + } + lineView.changes = null + } + +// Lines with gutter elements, widgets or a background class need to +// be wrapped, and have the extra elements added to the wrapper div + function ensureLineWrapped(lineView) { + if (lineView.node == lineView.text) { + lineView.node = elt("div", null, null, "position: relative") + if (lineView.text.parentNode) + { lineView.text.parentNode.replaceChild(lineView.node, lineView.text) } + lineView.node.appendChild(lineView.text) + if (ie && ie_version < 8) { lineView.node.style.zIndex = 2 } + } + return lineView.node + } + + function updateLineBackground(cm, lineView) { + var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass + if (cls) { cls += " CodeMirror-linebackground" } + if (lineView.background) { + if (cls) { lineView.background.className = cls } + else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null } + } else if (cls) { + var wrap = ensureLineWrapped(lineView) + lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild) + cm.display.input.setUneditable(lineView.background) + } + } + +// Wrapper around buildLineContent which will reuse the structure +// in display.externalMeasured when possible. + function getLineContent(cm, lineView) { + var ext = cm.display.externalMeasured + if (ext && ext.line == lineView.line) { + cm.display.externalMeasured = null + lineView.measure = ext.measure + return ext.built + } + return buildLineContent(cm, lineView) + } + +// Redraw the line's text. Interacts with the background and text +// classes because the mode may output tokens that influence these +// classes. + function updateLineText(cm, lineView) { + var cls = lineView.text.className + var built = getLineContent(cm, lineView) + if (lineView.text == lineView.node) { lineView.node = built.pre } + lineView.text.parentNode.replaceChild(built.pre, lineView.text) + lineView.text = built.pre + if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) { + lineView.bgClass = built.bgClass + lineView.textClass = built.textClass + updateLineClasses(cm, lineView) + } else if (cls) { + lineView.text.className = cls + } + } + + function updateLineClasses(cm, lineView) { + updateLineBackground(cm, lineView) + if (lineView.line.wrapClass) + { ensureLineWrapped(lineView).className = lineView.line.wrapClass } + else if (lineView.node != lineView.text) + { lineView.node.className = "" } + var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass + lineView.text.className = textClass || "" + } + + function updateLineGutter(cm, lineView, lineN, dims) { + if (lineView.gutter) { + lineView.node.removeChild(lineView.gutter) + lineView.gutter = null + } + if (lineView.gutterBackground) { + lineView.node.removeChild(lineView.gutterBackground) + lineView.gutterBackground = null + } + if (lineView.line.gutterClass) { + var wrap = ensureLineWrapped(lineView) + lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass, + ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px")) + cm.display.input.setUneditable(lineView.gutterBackground) + wrap.insertBefore(lineView.gutterBackground, lineView.text) + } + var markers = lineView.line.gutterMarkers + if (cm.options.lineNumbers || markers) { + var wrap$1 = ensureLineWrapped(lineView) + var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px")) + cm.display.input.setUneditable(gutterWrap) + wrap$1.insertBefore(gutterWrap, lineView.text) + if (lineView.line.gutterClass) + { gutterWrap.className += " " + lineView.line.gutterClass } + if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"])) + { lineView.lineNumber = gutterWrap.appendChild( + elt("div", lineNumberFor(cm.options, lineN), + "CodeMirror-linenumber CodeMirror-gutter-elt", + ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))) } + if (markers) { for (var k = 0; k < cm.options.gutters.length; ++k) { + var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id] + if (found) + { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", + ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))) } + } } + } + } + + function updateLineWidgets(cm, lineView, dims) { + if (lineView.alignable) { lineView.alignable = null } + for (var node = lineView.node.firstChild, next = (void 0); node; node = next) { + next = node.nextSibling + if (node.className == "CodeMirror-linewidget") + { lineView.node.removeChild(node) } + } + insertLineWidgets(cm, lineView, dims) + } + +// Build a line's DOM representation from scratch + function buildLineElement(cm, lineView, lineN, dims) { + var built = getLineContent(cm, lineView) + lineView.text = lineView.node = built.pre + if (built.bgClass) { lineView.bgClass = built.bgClass } + if (built.textClass) { lineView.textClass = built.textClass } + + updateLineClasses(cm, lineView) + updateLineGutter(cm, lineView, lineN, dims) + insertLineWidgets(cm, lineView, dims) + return lineView.node + } + +// A lineView may contain multiple logical lines (when merged by +// collapsed spans). The widgets for all of them need to be drawn. + function insertLineWidgets(cm, lineView, dims) { + insertLineWidgetsFor(cm, lineView.line, lineView, dims, true) + if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++) + { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false) } } + } + + function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) { + if (!line.widgets) { return } + var wrap = ensureLineWrapped(lineView) + for (var i = 0, ws = line.widgets; i < ws.length; ++i) { + var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget") + if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true") } + positionLineWidget(widget, node, lineView, dims) + cm.display.input.setUneditable(node) + if (allowAbove && widget.above) + { wrap.insertBefore(node, lineView.gutter || lineView.text) } + else + { wrap.appendChild(node) } + signalLater(widget, "redraw") + } + } + + function positionLineWidget(widget, node, lineView, dims) { + if (widget.noHScroll) { + ;(lineView.alignable || (lineView.alignable = [])).push(node) + var width = dims.wrapperWidth + node.style.left = dims.fixedPos + "px" + if (!widget.coverGutter) { + width -= dims.gutterTotalWidth + node.style.paddingLeft = dims.gutterTotalWidth + "px" + } + node.style.width = width + "px" + } + if (widget.coverGutter) { + node.style.zIndex = 5 + node.style.position = "relative" + if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px" } + } + } + + function widgetHeight(widget) { + if (widget.height != null) { return widget.height } + var cm = widget.doc.cm + if (!cm) { return 0 } + if (!contains(document.body, widget.node)) { + var parentStyle = "position: relative;" + if (widget.coverGutter) + { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;" } + if (widget.noHScroll) + { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;" } + removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle)) + } + return widget.height = widget.node.parentNode.offsetHeight + } + +// Return true when the given mouse event happened in a widget + function eventInWidget(display, e) { + for (var n = e_target(e); n != display.wrapper; n = n.parentNode) { + if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") || + (n.parentNode == display.sizer && n != display.mover)) + { return true } + } + } + +// POSITION MEASUREMENT + + function paddingTop(display) {return display.lineSpace.offsetTop} + function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight} + function paddingH(display) { + if (display.cachedPaddingH) { return display.cachedPaddingH } + var e = removeChildrenAndAdd(display.measure, elt("pre", "x")) + var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle + var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)} + if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data } + return data + } + + function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth } + function displayWidth(cm) { + return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth + } + function displayHeight(cm) { + return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight + } + +// Ensure the lineView.wrapping.heights array is populated. This is +// an array of bottom offsets for the lines that make up a drawn +// line. When lineWrapping is on, there might be more than one +// height. + function ensureLineHeights(cm, lineView, rect) { + var wrapping = cm.options.lineWrapping + var curWidth = wrapping && displayWidth(cm) + if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) { + var heights = lineView.measure.heights = [] + if (wrapping) { + lineView.measure.width = curWidth + var rects = lineView.text.firstChild.getClientRects() + for (var i = 0; i < rects.length - 1; i++) { + var cur = rects[i], next = rects[i + 1] + if (Math.abs(cur.bottom - next.bottom) > 2) + { heights.push((cur.bottom + next.top) / 2 - rect.top) } + } + } + heights.push(rect.bottom - rect.top) + } + } + +// Find a line map (mapping character offsets to text nodes) and a +// measurement cache for the given line number. (A line view might +// contain multiple lines when collapsed ranges are present.) + function mapFromLineView(lineView, line, lineN) { + if (lineView.line == line) + { return {map: lineView.measure.map, cache: lineView.measure.cache} } + for (var i = 0; i < lineView.rest.length; i++) + { if (lineView.rest[i] == line) + { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } } + for (var i$1 = 0; i$1 < lineView.rest.length; i$1++) + { if (lineNo(lineView.rest[i$1]) > lineN) + { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } } + } + +// Render a line into the hidden node display.externalMeasured. Used +// when measurement is needed for a line that's not in the viewport. + function updateExternalMeasurement(cm, line) { + line = visualLine(line) + var lineN = lineNo(line) + var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN) + view.lineN = lineN + var built = view.built = buildLineContent(cm, view) + view.text = built.pre + removeChildrenAndAdd(cm.display.lineMeasure, built.pre) + return view + } + +// Get a {top, bottom, left, right} box (in line-local coordinates) +// for a given character. + function measureChar(cm, line, ch, bias) { + return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias) + } + +// Find a line view that corresponds to the given line number. + function findViewForLine(cm, lineN) { + if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo) + { return cm.display.view[findViewIndex(cm, lineN)] } + var ext = cm.display.externalMeasured + if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size) + { return ext } + } + +// Measurement can be split in two steps, the set-up work that +// applies to the whole line, and the measurement of the actual +// character. Functions like coordsChar, that need to do a lot of +// measurements in a row, can thus ensure that the set-up work is +// only done once. + function prepareMeasureForLine(cm, line) { + var lineN = lineNo(line) + var view = findViewForLine(cm, lineN) + if (view && !view.text) { + view = null + } else if (view && view.changes) { + updateLineForChanges(cm, view, lineN, getDimensions(cm)) + cm.curOp.forceUpdate = true + } + if (!view) + { view = updateExternalMeasurement(cm, line) } + + var info = mapFromLineView(view, line, lineN) + return { + line: line, view: view, rect: null, + map: info.map, cache: info.cache, before: info.before, + hasHeights: false + } + } + +// Given a prepared measurement object, measures the position of an +// actual character (or fetches it from the cache). + function measureCharPrepared(cm, prepared, ch, bias, varHeight) { + if (prepared.before) { ch = -1 } + var key = ch + (bias || ""), found + if (prepared.cache.hasOwnProperty(key)) { + found = prepared.cache[key] + } else { + if (!prepared.rect) + { prepared.rect = prepared.view.text.getBoundingClientRect() } + if (!prepared.hasHeights) { + ensureLineHeights(cm, prepared.view, prepared.rect) + prepared.hasHeights = true + } + found = measureCharInner(cm, prepared, ch, bias) + if (!found.bogus) { prepared.cache[key] = found } + } + return {left: found.left, right: found.right, + top: varHeight ? found.rtop : found.top, + bottom: varHeight ? found.rbottom : found.bottom} + } + + var nullRect = {left: 0, right: 0, top: 0, bottom: 0} + + function nodeAndOffsetInLineMap(map, ch, bias) { + var node, start, end, collapse, mStart, mEnd + // First, search the line map for the text node corresponding to, + // or closest to, the target character. + for (var i = 0; i < map.length; i += 3) { + mStart = map[i] + mEnd = map[i + 1] + if (ch < mStart) { + start = 0; end = 1 + collapse = "left" + } else if (ch < mEnd) { + start = ch - mStart + end = start + 1 + } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) { + end = mEnd - mStart + start = end - 1 + if (ch >= mEnd) { collapse = "right" } + } + if (start != null) { + node = map[i + 2] + if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right")) + { collapse = bias } + if (bias == "left" && start == 0) + { while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) { + node = map[(i -= 3) + 2] + collapse = "left" + } } + if (bias == "right" && start == mEnd - mStart) + { while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) { + node = map[(i += 3) + 2] + collapse = "right" + } } + break + } + } + return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd} + } + + function getUsefulRect(rects, bias) { + var rect = nullRect + if (bias == "left") { for (var i = 0; i < rects.length; i++) { + if ((rect = rects[i]).left != rect.right) { break } + } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) { + if ((rect = rects[i$1]).left != rect.right) { break } + } } + return rect + } + + function measureCharInner(cm, prepared, ch, bias) { + var place = nodeAndOffsetInLineMap(prepared.map, ch, bias) + var node = place.node, start = place.start, end = place.end, collapse = place.collapse + + var rect + if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates. + for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned + while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start } + while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end } + if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) + { rect = node.parentNode.getBoundingClientRect() } + else + { rect = getUsefulRect(range(node, start, end).getClientRects(), bias) } + if (rect.left || rect.right || start == 0) { break } + end = start + start = start - 1 + collapse = "right" + } + if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect) } + } else { // If it is a widget, simply get the box for the whole widget. + if (start > 0) { collapse = bias = "right" } + var rects + if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1) + { rect = rects[bias == "right" ? rects.length - 1 : 0] } + else + { rect = node.getBoundingClientRect() } + } + if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) { + var rSpan = node.parentNode.getClientRects()[0] + if (rSpan) + { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom} } + else + { rect = nullRect } + } + + var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top + var mid = (rtop + rbot) / 2 + var heights = prepared.view.measure.heights + var i = 0 + for (; i < heights.length - 1; i++) + { if (mid < heights[i]) { break } } + var top = i ? heights[i - 1] : 0, bot = heights[i] + var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left, + right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left, + top: top, bottom: bot} + if (!rect.left && !rect.right) { result.bogus = true } + if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot } + + return result + } + +// Work around problem with bounding client rects on ranges being +// returned incorrectly when zoomed on IE10 and below. + function maybeUpdateRectForZooming(measure, rect) { + if (!window.screen || screen.logicalXDPI == null || + screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure)) + { return rect } + var scaleX = screen.logicalXDPI / screen.deviceXDPI + var scaleY = screen.logicalYDPI / screen.deviceYDPI + return {left: rect.left * scaleX, right: rect.right * scaleX, + top: rect.top * scaleY, bottom: rect.bottom * scaleY} + } + + function clearLineMeasurementCacheFor(lineView) { + if (lineView.measure) { + lineView.measure.cache = {} + lineView.measure.heights = null + if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++) + { lineView.measure.caches[i] = {} } } + } + } + + function clearLineMeasurementCache(cm) { + cm.display.externalMeasure = null + removeChildren(cm.display.lineMeasure) + for (var i = 0; i < cm.display.view.length; i++) + { clearLineMeasurementCacheFor(cm.display.view[i]) } + } + + function clearCaches(cm) { + clearLineMeasurementCache(cm) + cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null + if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true } + cm.display.lineNumChars = null + } + + function pageScrollX() { + // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206 + // which causes page_Offset and bounding client rects to use + // different reference viewports and invalidate our calculations. + if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) } + return window.pageXOffset || (document.documentElement || document.body).scrollLeft + } + function pageScrollY() { + if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) } + return window.pageYOffset || (document.documentElement || document.body).scrollTop + } + + function widgetTopHeight(lineObj) { + var height = 0 + if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above) + { height += widgetHeight(lineObj.widgets[i]) } } } + return height + } + +// Converts a {top, bottom, left, right} box from line-local +// coordinates into another coordinate system. Context may be one of +// "line", "div" (display.lineDiv), "local"./null (editor), "window", +// or "page". + function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) { + if (!includeWidgets) { + var height = widgetTopHeight(lineObj) + rect.top += height; rect.bottom += height + } + if (context == "line") { return rect } + if (!context) { context = "local" } + var yOff = heightAtLine(lineObj) + if (context == "local") { yOff += paddingTop(cm.display) } + else { yOff -= cm.display.viewOffset } + if (context == "page" || context == "window") { + var lOff = cm.display.lineSpace.getBoundingClientRect() + yOff += lOff.top + (context == "window" ? 0 : pageScrollY()) + var xOff = lOff.left + (context == "window" ? 0 : pageScrollX()) + rect.left += xOff; rect.right += xOff + } + rect.top += yOff; rect.bottom += yOff + return rect + } + +// Coverts a box from "div" coords to another coordinate system. +// Context may be "window", "page", "div", or "local"./null. + function fromCoordSystem(cm, coords, context) { + if (context == "div") { return coords } + var left = coords.left, top = coords.top + // First move into "page" coordinate system + if (context == "page") { + left -= pageScrollX() + top -= pageScrollY() + } else if (context == "local" || !context) { + var localBox = cm.display.sizer.getBoundingClientRect() + left += localBox.left + top += localBox.top + } + + var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect() + return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top} + } + + function charCoords(cm, pos, context, lineObj, bias) { + if (!lineObj) { lineObj = getLine(cm.doc, pos.line) } + return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context) + } + +// Returns a box for a given cursor position, which may have an +// 'other' property containing the position of the secondary cursor +// on a bidi boundary. +// A cursor Pos(line, char, "before") is on the same visual line as `char - 1` +// and after `char - 1` in writing order of `char - 1` +// A cursor Pos(line, char, "after") is on the same visual line as `char` +// and before `char` in writing order of `char` +// Examples (upper-case letters are RTL, lower-case are LTR): +// Pos(0, 1, ...) +// before after +// ab a|b a|b +// aB a|B aB| +// Ab |Ab A|b +// AB B|A B|A +// Every position after the last character on a line is considered to stick +// to the last character on the line. + function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) { + lineObj = lineObj || getLine(cm.doc, pos.line) + if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj) } + function get(ch, right) { + var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight) + if (right) { m.left = m.right; } else { m.right = m.left } + return intoCoordSystem(cm, lineObj, m, context) + } + var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky + if (ch >= lineObj.text.length) { + ch = lineObj.text.length + sticky = "before" + } else if (ch <= 0) { + ch = 0 + sticky = "after" + } + if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") } + + function getBidi(ch, partPos, invert) { + var part = order[partPos], right = part.level == 1 + return get(invert ? ch - 1 : ch, right != invert) + } + var partPos = getBidiPartAt(order, ch, sticky) + var other = bidiOther + var val = getBidi(ch, partPos, sticky == "before") + if (other != null) { val.other = getBidi(ch, other, sticky != "before") } + return val + } + +// Used to cheaply estimate the coordinates for a position. Used for +// intermediate scroll updates. + function estimateCoords(cm, pos) { + var left = 0 + pos = clipPos(cm.doc, pos) + if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch } + var lineObj = getLine(cm.doc, pos.line) + var top = heightAtLine(lineObj) + paddingTop(cm.display) + return {left: left, right: left, top: top, bottom: top + lineObj.height} + } + +// Positions returned by coordsChar contain some extra information. +// xRel is the relative x position of the input coordinates compared +// to the found position (so xRel > 0 means the coordinates are to +// the right of the character position, for example). When outside +// is true, that means the coordinates lie outside the line's +// vertical range. + function PosWithInfo(line, ch, sticky, outside, xRel) { + var pos = Pos(line, ch, sticky) + pos.xRel = xRel + if (outside) { pos.outside = true } + return pos + } + +// Compute the character position closest to the given coordinates. +// Input must be lineSpace-local ("div" coordinate system). + function coordsChar(cm, x, y) { + var doc = cm.doc + y += cm.display.viewOffset + if (y < 0) { return PosWithInfo(doc.first, 0, null, true, -1) } + var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1 + if (lineN > last) + { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, true, 1) } + if (x < 0) { x = 0 } + + var lineObj = getLine(doc, lineN) + for (;;) { + var found = coordsCharInner(cm, lineObj, lineN, x, y) + var merged = collapsedSpanAtEnd(lineObj) + var mergedPos = merged && merged.find(0, true) + if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0)) + { lineN = lineNo(lineObj = mergedPos.to.line) } + else + { return found } + } + } + + function wrappedLineExtent(cm, lineObj, preparedMeasure, y) { + y -= widgetTopHeight(lineObj) + var end = lineObj.text.length + var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0) + end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end) + return {begin: begin, end: end} + } + + function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) { + if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj) } + var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top + return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop) + } + +// Returns true if the given side of a box is after the given +// coordinates, in top-to-bottom, left-to-right order. + function boxIsAfter(box, x, y, left) { + return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x + } + + function coordsCharInner(cm, lineObj, lineNo, x, y) { + // Move y into line-local coordinate space + y -= heightAtLine(lineObj) + var preparedMeasure = prepareMeasureForLine(cm, lineObj) + // When directly calling `measureCharPrepared`, we have to adjust + // for the widgets at this line. + var widgetHeight = widgetTopHeight(lineObj) + var begin = 0, end = lineObj.text.length, ltr = true + + var order = getOrder(lineObj, cm.doc.direction) + // If the line isn't plain left-to-right text, first figure out + // which bidi section the coordinates fall into. + if (order) { + var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart) + (cm, lineObj, lineNo, preparedMeasure, order, x, y) + ltr = part.level != 1 + // The awkward -1 offsets are needed because findFirst (called + // on these below) will treat its first bound as inclusive, + // second as exclusive, but we want to actually address the + // characters in the part's range + begin = ltr ? part.from : part.to - 1 + end = ltr ? part.to : part.from - 1 + } + + // A binary search to find the first character whose bounding box + // starts after the coordinates. If we run across any whose box wrap + // the coordinates, store that. + var chAround = null, boxAround = null + var ch = findFirst(function (ch) { + var box = measureCharPrepared(cm, preparedMeasure, ch) + box.top += widgetHeight; box.bottom += widgetHeight + if (!boxIsAfter(box, x, y, false)) { return false } + if (box.top <= y && box.left <= x) { + chAround = ch + boxAround = box + } + return true + }, begin, end) + + var baseX, sticky, outside = false + // If a box around the coordinates was found, use that + if (boxAround) { + // Distinguish coordinates nearer to the left or right side of the box + var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr + ch = chAround + (atStart ? 0 : 1) + sticky = atStart ? "after" : "before" + baseX = atLeft ? boxAround.left : boxAround.right + } else { + // (Adjust for extended bound, if necessary.) + if (!ltr && (ch == end || ch == begin)) { ch++ } + // To determine which side to associate with, get the box to the + // left of the character and compare it's vertical position to the + // coordinates + sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" : + (measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight <= y) == ltr ? + "after" : "before" + // Now get accurate coordinates for this place, in order to get a + // base X position + var coords = cursorCoords(cm, Pos(lineNo, ch, sticky), "line", lineObj, preparedMeasure) + baseX = coords.left + outside = y < coords.top || y >= coords.bottom + } + + ch = skipExtendingChars(lineObj.text, ch, 1) + return PosWithInfo(lineNo, ch, sticky, outside, x - baseX) + } + + function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) { + // Bidi parts are sorted left-to-right, and in a non-line-wrapping + // situation, we can take this ordering to correspond to the visual + // ordering. This finds the first part whose end is after the given + // coordinates. + var index = findFirst(function (i) { + var part = order[i], ltr = part.level != 1 + return boxIsAfter(cursorCoords(cm, Pos(lineNo, ltr ? part.to : part.from, ltr ? "before" : "after"), + "line", lineObj, preparedMeasure), x, y, true) + }, 0, order.length - 1) + var part = order[index] + // If this isn't the first part, the part's start is also after + // the coordinates, and the coordinates aren't on the same line as + // that start, move one part back. + if (index > 0) { + var ltr = part.level != 1 + var start = cursorCoords(cm, Pos(lineNo, ltr ? part.from : part.to, ltr ? "after" : "before"), + "line", lineObj, preparedMeasure) + if (boxIsAfter(start, x, y, true) && start.top > y) + { part = order[index - 1] } + } + return part + } + + function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) { + // In a wrapped line, rtl text on wrapping boundaries can do things + // that don't correspond to the ordering in our `order` array at + // all, so a binary search doesn't work, and we want to return a + // part that only spans one line so that the binary search in + // coordsCharInner is safe. As such, we first find the extent of the + // wrapped line, and then do a flat search in which we discard any + // spans that aren't on the line. + var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y); + var begin = ref.begin; + var end = ref.end; + if (/\s/.test(lineObj.text.charAt(end - 1))) { end-- } + var part = null, closestDist = null + for (var i = 0; i < order.length; i++) { + var p = order[i] + if (p.from >= end || p.to <= begin) { continue } + var ltr = p.level != 1 + var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right + // Weigh against spans ending before this, so that they are only + // picked if nothing ends after + var dist = endX < x ? x - endX + 1e9 : endX - x + if (!part || closestDist > dist) { + part = p + closestDist = dist + } + } + if (!part) { part = order[order.length - 1] } + // Clip the part to the wrapped line. + if (part.from < begin) { part = {from: begin, to: part.to, level: part.level} } + if (part.to > end) { part = {from: part.from, to: end, level: part.level} } + return part + } + + var measureText +// Compute the default text height. + function textHeight(display) { + if (display.cachedTextHeight != null) { return display.cachedTextHeight } + if (measureText == null) { + measureText = elt("pre") + // Measure a bunch of lines, for browsers that compute + // fractional heights. + for (var i = 0; i < 49; ++i) { + measureText.appendChild(document.createTextNode("x")) + measureText.appendChild(elt("br")) + } + measureText.appendChild(document.createTextNode("x")) + } + removeChildrenAndAdd(display.measure, measureText) + var height = measureText.offsetHeight / 50 + if (height > 3) { display.cachedTextHeight = height } + removeChildren(display.measure) + return height || 1 + } + +// Compute the default character width. + function charWidth(display) { + if (display.cachedCharWidth != null) { return display.cachedCharWidth } + var anchor = elt("span", "xxxxxxxxxx") + var pre = elt("pre", [anchor]) + removeChildrenAndAdd(display.measure, pre) + var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10 + if (width > 2) { display.cachedCharWidth = width } + return width || 10 + } + +// Do a bulk-read of the DOM positions and sizes needed to draw the +// view, so that we don't interleave reading and writing to the DOM. + function getDimensions(cm) { + var d = cm.display, left = {}, width = {} + var gutterLeft = d.gutters.clientLeft + for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) { + left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft + width[cm.options.gutters[i]] = n.clientWidth + } + return {fixedPos: compensateForHScroll(d), + gutterTotalWidth: d.gutters.offsetWidth, + gutterLeft: left, + gutterWidth: width, + wrapperWidth: d.wrapper.clientWidth} + } + +// Computes display.scroller.scrollLeft + display.gutters.offsetWidth, +// but using getBoundingClientRect to get a sub-pixel-accurate +// result. + function compensateForHScroll(display) { + return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left + } + +// Returns a function that estimates the height of a line, to use as +// first approximation until the line becomes visible (and is thus +// properly measurable). + function estimateHeight(cm) { + var th = textHeight(cm.display), wrapping = cm.options.lineWrapping + var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3) + return function (line) { + if (lineIsHidden(cm.doc, line)) { return 0 } + + var widgetsHeight = 0 + if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) { + if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height } + } } + + if (wrapping) + { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th } + else + { return widgetsHeight + th } + } + } + + function estimateLineHeights(cm) { + var doc = cm.doc, est = estimateHeight(cm) + doc.iter(function (line) { + var estHeight = est(line) + if (estHeight != line.height) { updateLineHeight(line, estHeight) } + }) + } + +// Given a mouse event, find the corresponding position. If liberal +// is false, it checks whether a gutter or scrollbar was clicked, +// and returns null if it was. forRect is used by rectangular +// selections, and tries to estimate a character position even for +// coordinates beyond the right of the text. + function posFromMouse(cm, e, liberal, forRect) { + var display = cm.display + if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null } + + var x, y, space = display.lineSpace.getBoundingClientRect() + // Fails unpredictably on IE[67] when mouse is dragged around quickly. + try { x = e.clientX - space.left; y = e.clientY - space.top } + catch (e) { return null } + var coords = coordsChar(cm, x, y), line + if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) { + var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length + coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff)) + } + return coords + } + +// Find the view element corresponding to a given line. Return null +// when the line isn't visible. + function findViewIndex(cm, n) { + if (n >= cm.display.viewTo) { return null } + n -= cm.display.viewFrom + if (n < 0) { return null } + var view = cm.display.view + for (var i = 0; i < view.length; i++) { + n -= view[i].size + if (n < 0) { return i } + } + } + + function updateSelection(cm) { + cm.display.input.showSelection(cm.display.input.prepareSelection()) + } + + function prepareSelection(cm, primary) { + if ( primary === void 0 ) primary = true; + + var doc = cm.doc, result = {} + var curFragment = result.cursors = document.createDocumentFragment() + var selFragment = result.selection = document.createDocumentFragment() + + for (var i = 0; i < doc.sel.ranges.length; i++) { + if (!primary && i == doc.sel.primIndex) { continue } + var range = doc.sel.ranges[i] + if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) { continue } + var collapsed = range.empty() + if (collapsed || cm.options.showCursorWhenSelecting) + { drawSelectionCursor(cm, range.head, curFragment) } + if (!collapsed) + { drawSelectionRange(cm, range, selFragment) } + } + return result + } + +// Draws a cursor for the given range + function drawSelectionCursor(cm, head, output) { + var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine) + + var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor")) + cursor.style.left = pos.left + "px" + cursor.style.top = pos.top + "px" + cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px" + + if (pos.other) { + // Secondary cursor, shown when on a 'jump' in bi-directional text + var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor")) + otherCursor.style.display = "" + otherCursor.style.left = pos.other.left + "px" + otherCursor.style.top = pos.other.top + "px" + otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px" + } + } + + function cmpCoords(a, b) { return a.top - b.top || a.left - b.left } + +// Draws the given range as a highlighted selection + function drawSelectionRange(cm, range, output) { + var display = cm.display, doc = cm.doc + var fragment = document.createDocumentFragment() + var padding = paddingH(cm.display), leftSide = padding.left + var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right + var docLTR = doc.direction == "ltr" + + function add(left, top, width, bottom) { + if (top < 0) { top = 0 } + top = Math.round(top) + bottom = Math.round(bottom) + fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px"))) + } + + function drawForLine(line, fromArg, toArg) { + var lineObj = getLine(doc, line) + var lineLen = lineObj.text.length + var start, end + function coords(ch, bias) { + return charCoords(cm, Pos(line, ch), "div", lineObj, bias) + } + + function wrapX(pos, dir, side) { + var extent = wrappedLineExtentChar(cm, lineObj, null, pos) + var prop = (dir == "ltr") == (side == "after") ? "left" : "right" + var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1) + return coords(ch, prop)[prop] + } + + var order = getOrder(lineObj, doc.direction) + iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) { + var ltr = dir == "ltr" + var fromPos = coords(from, ltr ? "left" : "right") + var toPos = coords(to - 1, ltr ? "right" : "left") + + var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen + var first = i == 0, last = !order || i == order.length - 1 + if (toPos.top - fromPos.top <= 3) { // Single line + var openLeft = (docLTR ? openStart : openEnd) && first + var openRight = (docLTR ? openEnd : openStart) && last + var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left + var right = openRight ? rightSide : (ltr ? toPos : fromPos).right + add(left, fromPos.top, right - left, fromPos.bottom) + } else { // Multiple lines + var topLeft, topRight, botLeft, botRight + if (ltr) { + topLeft = docLTR && openStart && first ? leftSide : fromPos.left + topRight = docLTR ? rightSide : wrapX(from, dir, "before") + botLeft = docLTR ? leftSide : wrapX(to, dir, "after") + botRight = docLTR && openEnd && last ? rightSide : toPos.right + } else { + topLeft = !docLTR ? leftSide : wrapX(from, dir, "before") + topRight = !docLTR && openStart && first ? rightSide : fromPos.right + botLeft = !docLTR && openEnd && last ? leftSide : toPos.left + botRight = !docLTR ? rightSide : wrapX(to, dir, "after") + } + add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom) + if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top) } + add(botLeft, toPos.top, botRight - botLeft, toPos.bottom) + } + + if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos } + if (cmpCoords(toPos, start) < 0) { start = toPos } + if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos } + if (cmpCoords(toPos, end) < 0) { end = toPos } + }) + return {start: start, end: end} + } + + var sFrom = range.from(), sTo = range.to() + if (sFrom.line == sTo.line) { + drawForLine(sFrom.line, sFrom.ch, sTo.ch) + } else { + var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line) + var singleVLine = visualLine(fromLine) == visualLine(toLine) + var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end + var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start + if (singleVLine) { + if (leftEnd.top < rightStart.top - 2) { + add(leftEnd.right, leftEnd.top, null, leftEnd.bottom) + add(leftSide, rightStart.top, rightStart.left, rightStart.bottom) + } else { + add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom) + } + } + if (leftEnd.bottom < rightStart.top) + { add(leftSide, leftEnd.bottom, null, rightStart.top) } + } + + output.appendChild(fragment) + } + +// Cursor-blinking + function restartBlink(cm) { + if (!cm.state.focused) { return } + var display = cm.display + clearInterval(display.blinker) + var on = true + display.cursorDiv.style.visibility = "" + if (cm.options.cursorBlinkRate > 0) + { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; }, + cm.options.cursorBlinkRate) } + else if (cm.options.cursorBlinkRate < 0) + { display.cursorDiv.style.visibility = "hidden" } + } + + function ensureFocus(cm) { + if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm) } + } + + function delayBlurEvent(cm) { + cm.state.delayingBlurEvent = true + setTimeout(function () { if (cm.state.delayingBlurEvent) { + cm.state.delayingBlurEvent = false + onBlur(cm) + } }, 100) + } + + function onFocus(cm, e) { + if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false } + + if (cm.options.readOnly == "nocursor") { return } + if (!cm.state.focused) { + signal(cm, "focus", cm, e) + cm.state.focused = true + addClass(cm.display.wrapper, "CodeMirror-focused") + // This test prevents this from firing when a context + // menu is closed (since the input reset would kill the + // select-all detection hack) + if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) { + cm.display.input.reset() + if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20) } // Issue #1730 + } + cm.display.input.receivedFocus() + } + restartBlink(cm) + } + function onBlur(cm, e) { + if (cm.state.delayingBlurEvent) { return } + + if (cm.state.focused) { + signal(cm, "blur", cm, e) + cm.state.focused = false + rmClass(cm.display.wrapper, "CodeMirror-focused") + } + clearInterval(cm.display.blinker) + setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false } }, 150) + } + +// Read the actual heights of the rendered lines, and update their +// stored heights to match. + function updateHeightsInViewport(cm) { + var display = cm.display + var prevBottom = display.lineDiv.offsetTop + for (var i = 0; i < display.view.length; i++) { + var cur = display.view[i], height = (void 0) + if (cur.hidden) { continue } + if (ie && ie_version < 8) { + var bot = cur.node.offsetTop + cur.node.offsetHeight + height = bot - prevBottom + prevBottom = bot + } else { + var box = cur.node.getBoundingClientRect() + height = box.bottom - box.top + } + var diff = cur.line.height - height + if (height < 2) { height = textHeight(display) } + if (diff > .005 || diff < -.005) { + updateLineHeight(cur.line, height) + updateWidgetHeight(cur.line) + if (cur.rest) { for (var j = 0; j < cur.rest.length; j++) + { updateWidgetHeight(cur.rest[j]) } } + } + } + } + +// Read and store the height of line widgets associated with the +// given line. + function updateWidgetHeight(line) { + if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) { + var w = line.widgets[i], parent = w.node.parentNode + if (parent) { w.height = parent.offsetHeight } + } } + } + +// Compute the lines that are visible in a given viewport (defaults +// the the current scroll position). viewport may contain top, +// height, and ensure (see op.scrollToPos) properties. + function visibleLines(display, doc, viewport) { + var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop + top = Math.floor(top - paddingTop(display)) + var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight + + var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom) + // Ensure is a {from: {line, ch}, to: {line, ch}} object, and + // forces those lines into the viewport (if possible). + if (viewport && viewport.ensure) { + var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line + if (ensureFrom < from) { + from = ensureFrom + to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight) + } else if (Math.min(ensureTo, doc.lastLine()) >= to) { + from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight) + to = ensureTo + } + } + return {from: from, to: Math.max(to, from + 1)} + } + +// Re-align line numbers and gutter marks to compensate for +// horizontal scrolling. + function alignHorizontally(cm) { + var display = cm.display, view = display.view + if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return } + var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft + var gutterW = display.gutters.offsetWidth, left = comp + "px" + for (var i = 0; i < view.length; i++) { if (!view[i].hidden) { + if (cm.options.fixedGutter) { + if (view[i].gutter) + { view[i].gutter.style.left = left } + if (view[i].gutterBackground) + { view[i].gutterBackground.style.left = left } + } + var align = view[i].alignable + if (align) { for (var j = 0; j < align.length; j++) + { align[j].style.left = left } } + } } + if (cm.options.fixedGutter) + { display.gutters.style.left = (comp + gutterW) + "px" } + } + +// Used to ensure that the line number gutter is still the right +// size for the current document size. Returns true when an update +// is needed. + function maybeUpdateLineNumberWidth(cm) { + if (!cm.options.lineNumbers) { return false } + var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display + if (last.length != display.lineNumChars) { + var test = display.measure.appendChild(elt("div", [elt("div", last)], + "CodeMirror-linenumber CodeMirror-gutter-elt")) + var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW + display.lineGutter.style.width = "" + display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1 + display.lineNumWidth = display.lineNumInnerWidth + padding + display.lineNumChars = display.lineNumInnerWidth ? last.length : -1 + display.lineGutter.style.width = display.lineNumWidth + "px" + updateGutterSpace(cm) + return true + } + return false + } + +// SCROLLING THINGS INTO VIEW + +// If an editor sits on the top or bottom of the window, partially +// scrolled out of view, this ensures that the cursor is visible. + function maybeScrollWindow(cm, rect) { + if (signalDOMEvent(cm, "scrollCursorIntoView")) { return } + + var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null + if (rect.top + box.top < 0) { doScroll = true } + else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false } + if (doScroll != null && !phantom) { + var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;")) + cm.display.lineSpace.appendChild(scrollNode) + scrollNode.scrollIntoView(doScroll) + cm.display.lineSpace.removeChild(scrollNode) + } + } + +// Scroll a given position into view (immediately), verifying that +// it actually became visible (as line heights are accurately +// measured, the position of something may 'drift' during drawing). + function scrollPosIntoView(cm, pos, end, margin) { + if (margin == null) { margin = 0 } + var rect + if (!cm.options.lineWrapping && pos == end) { + // Set pos and end to the cursor positions around the character pos sticks to + // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch + // If pos == Pos(_, 0, "before"), pos and end are unchanged + pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos + end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos + } + for (var limit = 0; limit < 5; limit++) { + var changed = false + var coords = cursorCoords(cm, pos) + var endCoords = !end || end == pos ? coords : cursorCoords(cm, end) + rect = {left: Math.min(coords.left, endCoords.left), + top: Math.min(coords.top, endCoords.top) - margin, + right: Math.max(coords.left, endCoords.left), + bottom: Math.max(coords.bottom, endCoords.bottom) + margin} + var scrollPos = calculateScrollPos(cm, rect) + var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft + if (scrollPos.scrollTop != null) { + updateScrollTop(cm, scrollPos.scrollTop) + if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true } + } + if (scrollPos.scrollLeft != null) { + setScrollLeft(cm, scrollPos.scrollLeft) + if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true } + } + if (!changed) { break } + } + return rect + } + +// Scroll a given set of coordinates into view (immediately). + function scrollIntoView(cm, rect) { + var scrollPos = calculateScrollPos(cm, rect) + if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop) } + if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft) } + } + +// Calculate a new scroll position needed to scroll the given +// rectangle into view. Returns an object with scrollTop and +// scrollLeft properties. When these are undefined, the +// vertical/horizontal position does not need to be adjusted. + function calculateScrollPos(cm, rect) { + var display = cm.display, snapMargin = textHeight(cm.display) + if (rect.top < 0) { rect.top = 0 } + var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop + var screen = displayHeight(cm), result = {} + if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen } + var docBottom = cm.doc.height + paddingVert(display) + var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin + if (rect.top < screentop) { + result.scrollTop = atTop ? 0 : rect.top + } else if (rect.bottom > screentop + screen) { + var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen) + if (newTop != screentop) { result.scrollTop = newTop } + } + + var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft + var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0) + var tooWide = rect.right - rect.left > screenw + if (tooWide) { rect.right = rect.left + screenw } + if (rect.left < 10) + { result.scrollLeft = 0 } + else if (rect.left < screenleft) + { result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)) } + else if (rect.right > screenw + screenleft - 3) + { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw } + return result + } + +// Store a relative adjustment to the scroll position in the current +// operation (to be applied when the operation finishes). + function addToScrollTop(cm, top) { + if (top == null) { return } + resolveScrollToPos(cm) + cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top + } + +// Make sure that at the end of the operation the current cursor is +// shown. + function ensureCursorVisible(cm) { + resolveScrollToPos(cm) + var cur = cm.getCursor() + cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin} + } + + function scrollToCoords(cm, x, y) { + if (x != null || y != null) { resolveScrollToPos(cm) } + if (x != null) { cm.curOp.scrollLeft = x } + if (y != null) { cm.curOp.scrollTop = y } + } + + function scrollToRange(cm, range) { + resolveScrollToPos(cm) + cm.curOp.scrollToPos = range + } + +// When an operation has its scrollToPos property set, and another +// scroll action is applied before the end of the operation, this +// 'simulates' scrolling that position into view in a cheap way, so +// that the effect of intermediate scroll commands is not ignored. + function resolveScrollToPos(cm) { + var range = cm.curOp.scrollToPos + if (range) { + cm.curOp.scrollToPos = null + var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to) + scrollToCoordsRange(cm, from, to, range.margin) + } + } + + function scrollToCoordsRange(cm, from, to, margin) { + var sPos = calculateScrollPos(cm, { + left: Math.min(from.left, to.left), + top: Math.min(from.top, to.top) - margin, + right: Math.max(from.right, to.right), + bottom: Math.max(from.bottom, to.bottom) + margin + }) + scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop) + } + +// Sync the scrollable area and scrollbars, ensure the viewport +// covers the visible area. + function updateScrollTop(cm, val) { + if (Math.abs(cm.doc.scrollTop - val) < 2) { return } + if (!gecko) { updateDisplaySimple(cm, {top: val}) } + setScrollTop(cm, val, true) + if (gecko) { updateDisplaySimple(cm) } + startWorker(cm, 100) + } + + function setScrollTop(cm, val, forceScroll) { + val = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val) + if (cm.display.scroller.scrollTop == val && !forceScroll) { return } + cm.doc.scrollTop = val + cm.display.scrollbars.setScrollTop(val) + if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val } + } + +// Sync scroller and scrollbar, ensure the gutter elements are +// aligned. + function setScrollLeft(cm, val, isScroller, forceScroll) { + val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth) + if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return } + cm.doc.scrollLeft = val + alignHorizontally(cm) + if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val } + cm.display.scrollbars.setScrollLeft(val) + } + +// SCROLLBARS + +// Prepare DOM reads needed to update the scrollbars. Done in one +// shot to minimize update/measure roundtrips. + function measureForScrollbars(cm) { + var d = cm.display, gutterW = d.gutters.offsetWidth + var docH = Math.round(cm.doc.height + paddingVert(cm.display)) + return { + clientHeight: d.scroller.clientHeight, + viewHeight: d.wrapper.clientHeight, + scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth, + viewWidth: d.wrapper.clientWidth, + barLeft: cm.options.fixedGutter ? gutterW : 0, + docHeight: docH, + scrollHeight: docH + scrollGap(cm) + d.barHeight, + nativeBarWidth: d.nativeBarWidth, + gutterWidth: gutterW + } + } + + var NativeScrollbars = function(place, scroll, cm) { + this.cm = cm + var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar") + var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar") + place(vert); place(horiz) + + on(vert, "scroll", function () { + if (vert.clientHeight) { scroll(vert.scrollTop, "vertical") } + }) + on(horiz, "scroll", function () { + if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal") } + }) + + this.checkedZeroWidth = false + // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8). + if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px" } + }; + + NativeScrollbars.prototype.update = function (measure) { + var needsH = measure.scrollWidth > measure.clientWidth + 1 + var needsV = measure.scrollHeight > measure.clientHeight + 1 + var sWidth = measure.nativeBarWidth + + if (needsV) { + this.vert.style.display = "block" + this.vert.style.bottom = needsH ? sWidth + "px" : "0" + var totalHeight = measure.viewHeight - (needsH ? sWidth : 0) + // A bug in IE8 can cause this value to be negative, so guard it. + this.vert.firstChild.style.height = + Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px" + } else { + this.vert.style.display = "" + this.vert.firstChild.style.height = "0" + } + + if (needsH) { + this.horiz.style.display = "block" + this.horiz.style.right = needsV ? sWidth + "px" : "0" + this.horiz.style.left = measure.barLeft + "px" + var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0) + this.horiz.firstChild.style.width = + Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px" + } else { + this.horiz.style.display = "" + this.horiz.firstChild.style.width = "0" + } + + if (!this.checkedZeroWidth && measure.clientHeight > 0) { + if (sWidth == 0) { this.zeroWidthHack() } + this.checkedZeroWidth = true + } + + return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0} + }; + + NativeScrollbars.prototype.setScrollLeft = function (pos) { + if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos } + if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz") } + }; + + NativeScrollbars.prototype.setScrollTop = function (pos) { + if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos } + if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert") } + }; + + NativeScrollbars.prototype.zeroWidthHack = function () { + var w = mac && !mac_geMountainLion ? "12px" : "18px" + this.horiz.style.height = this.vert.style.width = w + this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none" + this.disableHoriz = new Delayed + this.disableVert = new Delayed + }; + + NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) { + bar.style.pointerEvents = "auto" + function maybeDisable() { + // To find out whether the scrollbar is still visible, we + // check whether the element under the pixel in the bottom + // right corner of the scrollbar box is the scrollbar box + // itself (when the bar is still visible) or its filler child + // (when the bar is hidden). If it is still visible, we keep + // it enabled, if it's hidden, we disable pointer events. + var box = bar.getBoundingClientRect() + var elt = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2) + : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1) + if (elt != bar) { bar.style.pointerEvents = "none" } + else { delay.set(1000, maybeDisable) } + } + delay.set(1000, maybeDisable) + }; + + NativeScrollbars.prototype.clear = function () { + var parent = this.horiz.parentNode + parent.removeChild(this.horiz) + parent.removeChild(this.vert) + }; + + var NullScrollbars = function () {}; + + NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} }; + NullScrollbars.prototype.setScrollLeft = function () {}; + NullScrollbars.prototype.setScrollTop = function () {}; + NullScrollbars.prototype.clear = function () {}; + + function updateScrollbars(cm, measure) { + if (!measure) { measure = measureForScrollbars(cm) } + var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight + updateScrollbarsInner(cm, measure) + for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) { + if (startWidth != cm.display.barWidth && cm.options.lineWrapping) + { updateHeightsInViewport(cm) } + updateScrollbarsInner(cm, measureForScrollbars(cm)) + startWidth = cm.display.barWidth; startHeight = cm.display.barHeight + } + } + +// Re-synchronize the fake scrollbars with the actual size of the +// content. + function updateScrollbarsInner(cm, measure) { + var d = cm.display + var sizes = d.scrollbars.update(measure) + + d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px" + d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px" + d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent" + + if (sizes.right && sizes.bottom) { + d.scrollbarFiller.style.display = "block" + d.scrollbarFiller.style.height = sizes.bottom + "px" + d.scrollbarFiller.style.width = sizes.right + "px" + } else { d.scrollbarFiller.style.display = "" } + if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) { + d.gutterFiller.style.display = "block" + d.gutterFiller.style.height = sizes.bottom + "px" + d.gutterFiller.style.width = measure.gutterWidth + "px" + } else { d.gutterFiller.style.display = "" } + } + + var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars} + + function initScrollbars(cm) { + if (cm.display.scrollbars) { + cm.display.scrollbars.clear() + if (cm.display.scrollbars.addClass) + { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass) } + } + + cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) { + cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller) + // Prevent clicks in the scrollbars from killing focus + on(node, "mousedown", function () { + if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0) } + }) + node.setAttribute("cm-not-content", "true") + }, function (pos, axis) { + if (axis == "horizontal") { setScrollLeft(cm, pos) } + else { updateScrollTop(cm, pos) } + }, cm) + if (cm.display.scrollbars.addClass) + { addClass(cm.display.wrapper, cm.display.scrollbars.addClass) } + } + +// Operations are used to wrap a series of changes to the editor +// state in such a way that each change won't have to update the +// cursor and display (which would be awkward, slow, and +// error-prone). Instead, display updates are batched and then all +// combined and executed at once. + + var nextOpId = 0 +// Start a new operation. + function startOperation(cm) { + cm.curOp = { + cm: cm, + viewChanged: false, // Flag that indicates that lines might need to be redrawn + startHeight: cm.doc.height, // Used to detect need to update scrollbar + forceUpdate: false, // Used to force a redraw + updateInput: null, // Whether to reset the input textarea + typing: false, // Whether this reset should be careful to leave existing text (for compositing) + changeObjs: null, // Accumulated changes, for firing change events + cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on + cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already + selectionChanged: false, // Whether the selection needs to be redrawn + updateMaxLine: false, // Set when the widest line needs to be determined anew + scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet + scrollToPos: null, // Used to scroll to a specific position + focus: false, + id: ++nextOpId // Unique ID + } + pushOperation(cm.curOp) + } + +// Finish an operation, updating the display and signalling delayed events + function endOperation(cm) { + var op = cm.curOp + finishOperation(op, function (group) { + for (var i = 0; i < group.ops.length; i++) + { group.ops[i].cm.curOp = null } + endOperations(group) + }) + } + +// The DOM updates done when an operation finishes are batched so +// that the minimum number of relayouts are required. + function endOperations(group) { + var ops = group.ops + for (var i = 0; i < ops.length; i++) // Read DOM + { endOperation_R1(ops[i]) } + for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe) + { endOperation_W1(ops[i$1]) } + for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM + { endOperation_R2(ops[i$2]) } + for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe) + { endOperation_W2(ops[i$3]) } + for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM + { endOperation_finish(ops[i$4]) } + } + + function endOperation_R1(op) { + var cm = op.cm, display = cm.display + maybeClipScrollbars(cm) + if (op.updateMaxLine) { findMaxLine(cm) } + + op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null || + op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom || + op.scrollToPos.to.line >= display.viewTo) || + display.maxLineChanged && cm.options.lineWrapping + op.update = op.mustUpdate && + new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate) + } + + function endOperation_W1(op) { + op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update) + } + + function endOperation_R2(op) { + var cm = op.cm, display = cm.display + if (op.updatedDisplay) { updateHeightsInViewport(cm) } + + op.barMeasure = measureForScrollbars(cm) + + // If the max line changed since it was last measured, measure it, + // and ensure the document's width matches it. + // updateDisplay_W2 will use these properties to do the actual resizing + if (display.maxLineChanged && !cm.options.lineWrapping) { + op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3 + cm.display.sizerWidth = op.adjustWidthTo + op.barMeasure.scrollWidth = + Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth) + op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm)) + } + + if (op.updatedDisplay || op.selectionChanged) + { op.preparedSelection = display.input.prepareSelection() } + } + + function endOperation_W2(op) { + var cm = op.cm + + if (op.adjustWidthTo != null) { + cm.display.sizer.style.minWidth = op.adjustWidthTo + "px" + if (op.maxScrollLeft < cm.doc.scrollLeft) + { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true) } + cm.display.maxLineChanged = false + } + + var takeFocus = op.focus && op.focus == activeElt() + if (op.preparedSelection) + { cm.display.input.showSelection(op.preparedSelection, takeFocus) } + if (op.updatedDisplay || op.startHeight != cm.doc.height) + { updateScrollbars(cm, op.barMeasure) } + if (op.updatedDisplay) + { setDocumentHeight(cm, op.barMeasure) } + + if (op.selectionChanged) { restartBlink(cm) } + + if (cm.state.focused && op.updateInput) + { cm.display.input.reset(op.typing) } + if (takeFocus) { ensureFocus(op.cm) } + } + + function endOperation_finish(op) { + var cm = op.cm, display = cm.display, doc = cm.doc + + if (op.updatedDisplay) { postUpdateDisplay(cm, op.update) } + + // Abort mouse wheel delta measurement, when scrolling explicitly + if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos)) + { display.wheelStartX = display.wheelStartY = null } + + // Propagate the scroll position to the actual DOM scroller + if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll) } + + if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true) } + // If we need to scroll a specific position into view, do so. + if (op.scrollToPos) { + var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from), + clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin) + maybeScrollWindow(cm, rect) + } + + // Fire events for markers that are hidden/unidden by editing or + // undoing + var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers + if (hidden) { for (var i = 0; i < hidden.length; ++i) + { if (!hidden[i].lines.length) { signal(hidden[i], "hide") } } } + if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1) + { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide") } } } + + if (display.wrapper.offsetHeight) + { doc.scrollTop = cm.display.scroller.scrollTop } + + // Fire change events, and delayed event handlers + if (op.changeObjs) + { signal(cm, "changes", cm, op.changeObjs) } + if (op.update) + { op.update.finish() } + } + +// Run the given function in an operation + function runInOp(cm, f) { + if (cm.curOp) { return f() } + startOperation(cm) + try { return f() } + finally { endOperation(cm) } + } +// Wraps a function in an operation. Returns the wrapped function. + function operation(cm, f) { + return function() { + if (cm.curOp) { return f.apply(cm, arguments) } + startOperation(cm) + try { return f.apply(cm, arguments) } + finally { endOperation(cm) } + } + } +// Used to add methods to editor and doc instances, wrapping them in +// operations. + function methodOp(f) { + return function() { + if (this.curOp) { return f.apply(this, arguments) } + startOperation(this) + try { return f.apply(this, arguments) } + finally { endOperation(this) } + } + } + function docMethodOp(f) { + return function() { + var cm = this.cm + if (!cm || cm.curOp) { return f.apply(this, arguments) } + startOperation(cm) + try { return f.apply(this, arguments) } + finally { endOperation(cm) } + } + } + +// Updates the display.view data structure for a given change to the +// document. From and to are in pre-change coordinates. Lendiff is +// the amount of lines added or subtracted by the change. This is +// used for changes that span multiple lines, or change the way +// lines are divided into visual lines. regLineChange (below) +// registers single-line changes. + function regChange(cm, from, to, lendiff) { + if (from == null) { from = cm.doc.first } + if (to == null) { to = cm.doc.first + cm.doc.size } + if (!lendiff) { lendiff = 0 } + + var display = cm.display + if (lendiff && to < display.viewTo && + (display.updateLineNumbers == null || display.updateLineNumbers > from)) + { display.updateLineNumbers = from } + + cm.curOp.viewChanged = true + + if (from >= display.viewTo) { // Change after + if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo) + { resetView(cm) } + } else if (to <= display.viewFrom) { // Change before + if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) { + resetView(cm) + } else { + display.viewFrom += lendiff + display.viewTo += lendiff + } + } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap + resetView(cm) + } else if (from <= display.viewFrom) { // Top overlap + var cut = viewCuttingPoint(cm, to, to + lendiff, 1) + if (cut) { + display.view = display.view.slice(cut.index) + display.viewFrom = cut.lineN + display.viewTo += lendiff + } else { + resetView(cm) + } + } else if (to >= display.viewTo) { // Bottom overlap + var cut$1 = viewCuttingPoint(cm, from, from, -1) + if (cut$1) { + display.view = display.view.slice(0, cut$1.index) + display.viewTo = cut$1.lineN + } else { + resetView(cm) + } + } else { // Gap in the middle + var cutTop = viewCuttingPoint(cm, from, from, -1) + var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1) + if (cutTop && cutBot) { + display.view = display.view.slice(0, cutTop.index) + .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN)) + .concat(display.view.slice(cutBot.index)) + display.viewTo += lendiff + } else { + resetView(cm) + } + } + + var ext = display.externalMeasured + if (ext) { + if (to < ext.lineN) + { ext.lineN += lendiff } + else if (from < ext.lineN + ext.size) + { display.externalMeasured = null } + } + } + +// Register a change to a single line. Type must be one of "text", +// "gutter", "class", "widget" + function regLineChange(cm, line, type) { + cm.curOp.viewChanged = true + var display = cm.display, ext = cm.display.externalMeasured + if (ext && line >= ext.lineN && line < ext.lineN + ext.size) + { display.externalMeasured = null } + + if (line < display.viewFrom || line >= display.viewTo) { return } + var lineView = display.view[findViewIndex(cm, line)] + if (lineView.node == null) { return } + var arr = lineView.changes || (lineView.changes = []) + if (indexOf(arr, type) == -1) { arr.push(type) } + } + +// Clear the view. + function resetView(cm) { + cm.display.viewFrom = cm.display.viewTo = cm.doc.first + cm.display.view = [] + cm.display.viewOffset = 0 + } + + function viewCuttingPoint(cm, oldN, newN, dir) { + var index = findViewIndex(cm, oldN), diff, view = cm.display.view + if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size) + { return {index: index, lineN: newN} } + var n = cm.display.viewFrom + for (var i = 0; i < index; i++) + { n += view[i].size } + if (n != oldN) { + if (dir > 0) { + if (index == view.length - 1) { return null } + diff = (n + view[index].size) - oldN + index++ + } else { + diff = n - oldN + } + oldN += diff; newN += diff + } + while (visualLineNo(cm.doc, newN) != newN) { + if (index == (dir < 0 ? 0 : view.length - 1)) { return null } + newN += dir * view[index - (dir < 0 ? 1 : 0)].size + index += dir + } + return {index: index, lineN: newN} + } + +// Force the view to cover a given range, adding empty view element +// or clipping off existing ones as needed. + function adjustView(cm, from, to) { + var display = cm.display, view = display.view + if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) { + display.view = buildViewArray(cm, from, to) + display.viewFrom = from + } else { + if (display.viewFrom > from) + { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view) } + else if (display.viewFrom < from) + { display.view = display.view.slice(findViewIndex(cm, from)) } + display.viewFrom = from + if (display.viewTo < to) + { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)) } + else if (display.viewTo > to) + { display.view = display.view.slice(0, findViewIndex(cm, to)) } + } + display.viewTo = to + } + +// Count the number of lines in the view whose DOM representation is +// out of date (or nonexistent). + function countDirtyView(cm) { + var view = cm.display.view, dirty = 0 + for (var i = 0; i < view.length; i++) { + var lineView = view[i] + if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty } + } + return dirty + } + +// HIGHLIGHT WORKER + + function startWorker(cm, time) { + if (cm.doc.highlightFrontier < cm.display.viewTo) + { cm.state.highlight.set(time, bind(highlightWorker, cm)) } + } + + function highlightWorker(cm) { + var doc = cm.doc + if (doc.highlightFrontier >= cm.display.viewTo) { return } + var end = +new Date + cm.options.workTime + var context = getContextBefore(cm, doc.highlightFrontier) + var changedLines = [] + + doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) { + if (context.line >= cm.display.viewFrom) { // Visible + var oldStyles = line.styles + var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null + var highlighted = highlightLine(cm, line, context, true) + if (resetState) { context.state = resetState } + line.styles = highlighted.styles + var oldCls = line.styleClasses, newCls = highlighted.classes + if (newCls) { line.styleClasses = newCls } + else if (oldCls) { line.styleClasses = null } + var ischange = !oldStyles || oldStyles.length != line.styles.length || + oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass) + for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i] } + if (ischange) { changedLines.push(context.line) } + line.stateAfter = context.save() + context.nextLine() + } else { + if (line.text.length <= cm.options.maxHighlightLength) + { processLine(cm, line.text, context) } + line.stateAfter = context.line % 5 == 0 ? context.save() : null + context.nextLine() + } + if (+new Date > end) { + startWorker(cm, cm.options.workDelay) + return true + } + }) + doc.highlightFrontier = context.line + doc.modeFrontier = Math.max(doc.modeFrontier, context.line) + if (changedLines.length) { runInOp(cm, function () { + for (var i = 0; i < changedLines.length; i++) + { regLineChange(cm, changedLines[i], "text") } + }) } + } + +// DISPLAY DRAWING + + var DisplayUpdate = function(cm, viewport, force) { + var display = cm.display + + this.viewport = viewport + // Store some values that we'll need later (but don't want to force a relayout for) + this.visible = visibleLines(display, cm.doc, viewport) + this.editorIsHidden = !display.wrapper.offsetWidth + this.wrapperHeight = display.wrapper.clientHeight + this.wrapperWidth = display.wrapper.clientWidth + this.oldDisplayWidth = displayWidth(cm) + this.force = force + this.dims = getDimensions(cm) + this.events = [] + }; + + DisplayUpdate.prototype.signal = function (emitter, type) { + if (hasHandler(emitter, type)) + { this.events.push(arguments) } + }; + DisplayUpdate.prototype.finish = function () { + var this$1 = this; + + for (var i = 0; i < this.events.length; i++) + { signal.apply(null, this$1.events[i]) } + }; + + function maybeClipScrollbars(cm) { + var display = cm.display + if (!display.scrollbarsClipped && display.scroller.offsetWidth) { + display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth + display.heightForcer.style.height = scrollGap(cm) + "px" + display.sizer.style.marginBottom = -display.nativeBarWidth + "px" + display.sizer.style.borderRightWidth = scrollGap(cm) + "px" + display.scrollbarsClipped = true + } + } + + function selectionSnapshot(cm) { + if (cm.hasFocus()) { return null } + var active = activeElt() + if (!active || !contains(cm.display.lineDiv, active)) { return null } + var result = {activeElt: active} + if (window.getSelection) { + var sel = window.getSelection() + if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) { + result.anchorNode = sel.anchorNode + result.anchorOffset = sel.anchorOffset + result.focusNode = sel.focusNode + result.focusOffset = sel.focusOffset + } + } + return result + } + + function restoreSelection(snapshot) { + if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return } + snapshot.activeElt.focus() + if (snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) { + var sel = window.getSelection(), range = document.createRange() + range.setEnd(snapshot.anchorNode, snapshot.anchorOffset) + range.collapse(false) + sel.removeAllRanges() + sel.addRange(range) + sel.extend(snapshot.focusNode, snapshot.focusOffset) + } + } + +// Does the actual updating of the line display. Bails out +// (returning false) when there is nothing to be done and forced is +// false. + function updateDisplayIfNeeded(cm, update) { + var display = cm.display, doc = cm.doc + + if (update.editorIsHidden) { + resetView(cm) + return false + } + + // Bail out if the visible area is already rendered and nothing changed. + if (!update.force && + update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && + (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && + display.renderedView == display.view && countDirtyView(cm) == 0) + { return false } + + if (maybeUpdateLineNumberWidth(cm)) { + resetView(cm) + update.dims = getDimensions(cm) + } + + // Compute a suitable new viewport (from & to) + var end = doc.first + doc.size + var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first) + var to = Math.min(end, update.visible.to + cm.options.viewportMargin) + if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom) } + if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo) } + if (sawCollapsedSpans) { + from = visualLineNo(cm.doc, from) + to = visualLineEndNo(cm.doc, to) + } + + var different = from != display.viewFrom || to != display.viewTo || + display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth + adjustView(cm, from, to) + + display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom)) + // Position the mover div to align with the current scroll position + cm.display.mover.style.top = display.viewOffset + "px" + + var toUpdate = countDirtyView(cm) + if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && + (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) + { return false } + + // For big changes, we hide the enclosing element during the + // update, since that speeds up the operations on most browsers. + var selSnapshot = selectionSnapshot(cm) + if (toUpdate > 4) { display.lineDiv.style.display = "none" } + patchDisplay(cm, display.updateLineNumbers, update.dims) + if (toUpdate > 4) { display.lineDiv.style.display = "" } + display.renderedView = display.view + // There might have been a widget with a focused element that got + // hidden or updated, if so re-focus it. + restoreSelection(selSnapshot) + + // Prevent selection and cursors from interfering with the scroll + // width and height. + removeChildren(display.cursorDiv) + removeChildren(display.selectionDiv) + display.gutters.style.height = display.sizer.style.minHeight = 0 + + if (different) { + display.lastWrapHeight = update.wrapperHeight + display.lastWrapWidth = update.wrapperWidth + startWorker(cm, 400) + } + + display.updateLineNumbers = null + + return true + } + + function postUpdateDisplay(cm, update) { + var viewport = update.viewport + + for (var first = true;; first = false) { + if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) { + // Clip forced viewport to actual scrollable area. + if (viewport && viewport.top != null) + { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)} } + // Updated line heights might result in the drawn area not + // actually covering the viewport. Keep looping until it does. + update.visible = visibleLines(cm.display, cm.doc, viewport) + if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo) + { break } + } + if (!updateDisplayIfNeeded(cm, update)) { break } + updateHeightsInViewport(cm) + var barMeasure = measureForScrollbars(cm) + updateSelection(cm) + updateScrollbars(cm, barMeasure) + setDocumentHeight(cm, barMeasure) + update.force = false + } + + update.signal(cm, "update", cm) + if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) { + update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo) + cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo + } + } + + function updateDisplaySimple(cm, viewport) { + var update = new DisplayUpdate(cm, viewport) + if (updateDisplayIfNeeded(cm, update)) { + updateHeightsInViewport(cm) + postUpdateDisplay(cm, update) + var barMeasure = measureForScrollbars(cm) + updateSelection(cm) + updateScrollbars(cm, barMeasure) + setDocumentHeight(cm, barMeasure) + update.finish() + } + } + +// Sync the actual display DOM structure with display.view, removing +// nodes for lines that are no longer in view, and creating the ones +// that are not there yet, and updating the ones that are out of +// date. + function patchDisplay(cm, updateNumbersFrom, dims) { + var display = cm.display, lineNumbers = cm.options.lineNumbers + var container = display.lineDiv, cur = container.firstChild + + function rm(node) { + var next = node.nextSibling + // Works around a throw-scroll bug in OS X Webkit + if (webkit && mac && cm.display.currentWheelTarget == node) + { node.style.display = "none" } + else + { node.parentNode.removeChild(node) } + return next + } + + var view = display.view, lineN = display.viewFrom + // Loop over the elements in the view, syncing cur (the DOM nodes + // in display.lineDiv) with the view as we go. + for (var i = 0; i < view.length; i++) { + var lineView = view[i] + if (lineView.hidden) { + } else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet + var node = buildLineElement(cm, lineView, lineN, dims) + container.insertBefore(node, cur) + } else { // Already drawn + while (cur != lineView.node) { cur = rm(cur) } + var updateNumber = lineNumbers && updateNumbersFrom != null && + updateNumbersFrom <= lineN && lineView.lineNumber + if (lineView.changes) { + if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false } + updateLineForChanges(cm, lineView, lineN, dims) + } + if (updateNumber) { + removeChildren(lineView.lineNumber) + lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN))) + } + cur = lineView.node.nextSibling + } + lineN += lineView.size + } + while (cur) { cur = rm(cur) } + } + + function updateGutterSpace(cm) { + var width = cm.display.gutters.offsetWidth + cm.display.sizer.style.marginLeft = width + "px" + } + + function setDocumentHeight(cm, measure) { + cm.display.sizer.style.minHeight = measure.docHeight + "px" + cm.display.heightForcer.style.top = measure.docHeight + "px" + cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px" + } + +// Rebuild the gutter elements, ensure the margin to the left of the +// code matches their width. + function updateGutters(cm) { + var gutters = cm.display.gutters, specs = cm.options.gutters + removeChildren(gutters) + var i = 0 + for (; i < specs.length; ++i) { + var gutterClass = specs[i] + var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass)) + if (gutterClass == "CodeMirror-linenumbers") { + cm.display.lineGutter = gElt + gElt.style.width = (cm.display.lineNumWidth || 1) + "px" + } + } + gutters.style.display = i ? "" : "none" + updateGutterSpace(cm) + } + +// Make sure the gutters options contains the element +// "CodeMirror-linenumbers" when the lineNumbers option is true. + function setGuttersForLineNumbers(options) { + var found = indexOf(options.gutters, "CodeMirror-linenumbers") + if (found == -1 && options.lineNumbers) { + options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]) + } else if (found > -1 && !options.lineNumbers) { + options.gutters = options.gutters.slice(0) + options.gutters.splice(found, 1) + } + } + + var wheelSamples = 0; + var wheelPixelsPerUnit = null; +// Fill in a browser-detected starting value on browsers where we +// know one. These don't have to be accurate -- the result of them +// being wrong would just be a slight flicker on the first wheel +// scroll (if it is large enough). + if (ie) { wheelPixelsPerUnit = -.53 } + else if (gecko) { wheelPixelsPerUnit = 15 } + else if (chrome) { wheelPixelsPerUnit = -.7 } + else if (safari) { wheelPixelsPerUnit = -1/3 } + + function wheelEventDelta(e) { + var dx = e.wheelDeltaX, dy = e.wheelDeltaY + if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail } + if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail } + else if (dy == null) { dy = e.wheelDelta } + return {x: dx, y: dy} + } + function wheelEventPixels(e) { + var delta = wheelEventDelta(e) + delta.x *= wheelPixelsPerUnit + delta.y *= wheelPixelsPerUnit + return delta + } + + function onScrollWheel(cm, e) { + var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y + + var display = cm.display, scroll = display.scroller + // Quit if there's nothing to scroll here + var canScrollX = scroll.scrollWidth > scroll.clientWidth + var canScrollY = scroll.scrollHeight > scroll.clientHeight + if (!(dx && canScrollX || dy && canScrollY)) { return } + + // Webkit browsers on OS X abort momentum scrolls when the target + // of the scroll event is removed from the scrollable element. + // This hack (see related code in patchDisplay) makes sure the + // element is kept around. + if (dy && mac && webkit) { + outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) { + for (var i = 0; i < view.length; i++) { + if (view[i].node == cur) { + cm.display.currentWheelTarget = cur + break outer + } + } + } + } + + // On some browsers, horizontal scrolling will cause redraws to + // happen before the gutter has been realigned, causing it to + // wriggle around in a most unseemly way. When we have an + // estimated pixels/delta value, we just handle horizontal + // scrolling entirely here. It'll be slightly off from native, but + // better than glitching out. + if (dx && !gecko && !presto && wheelPixelsPerUnit != null) { + if (dy && canScrollY) + { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)) } + setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit)) + // Only prevent default scrolling if vertical scrolling is + // actually possible. Otherwise, it causes vertical scroll + // jitter on OSX trackpads when deltaX is small and deltaY + // is large (issue #3579) + if (!dy || (dy && canScrollY)) + { e_preventDefault(e) } + display.wheelStartX = null // Abort measurement, if in progress + return + } + + // 'Project' the visible viewport to cover the area that is being + // scrolled into view (if we know enough to estimate it). + if (dy && wheelPixelsPerUnit != null) { + var pixels = dy * wheelPixelsPerUnit + var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight + if (pixels < 0) { top = Math.max(0, top + pixels - 50) } + else { bot = Math.min(cm.doc.height, bot + pixels + 50) } + updateDisplaySimple(cm, {top: top, bottom: bot}) + } + + if (wheelSamples < 20) { + if (display.wheelStartX == null) { + display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop + display.wheelDX = dx; display.wheelDY = dy + setTimeout(function () { + if (display.wheelStartX == null) { return } + var movedX = scroll.scrollLeft - display.wheelStartX + var movedY = scroll.scrollTop - display.wheelStartY + var sample = (movedY && display.wheelDY && movedY / display.wheelDY) || + (movedX && display.wheelDX && movedX / display.wheelDX) + display.wheelStartX = display.wheelStartY = null + if (!sample) { return } + wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1) + ++wheelSamples + }, 200) + } else { + display.wheelDX += dx; display.wheelDY += dy + } + } + } + +// Selection objects are immutable. A new one is created every time +// the selection changes. A selection is one or more non-overlapping +// (and non-touching) ranges, sorted, and an integer that indicates +// which one is the primary selection (the one that's scrolled into +// view, that getCursor returns, etc). + var Selection = function(ranges, primIndex) { + this.ranges = ranges + this.primIndex = primIndex + }; + + Selection.prototype.primary = function () { return this.ranges[this.primIndex] }; + + Selection.prototype.equals = function (other) { + var this$1 = this; + + if (other == this) { return true } + if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false } + for (var i = 0; i < this.ranges.length; i++) { + var here = this$1.ranges[i], there = other.ranges[i] + if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false } + } + return true + }; + + Selection.prototype.deepCopy = function () { + var this$1 = this; + + var out = [] + for (var i = 0; i < this.ranges.length; i++) + { out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head)) } + return new Selection(out, this.primIndex) + }; + + Selection.prototype.somethingSelected = function () { + var this$1 = this; + + for (var i = 0; i < this.ranges.length; i++) + { if (!this$1.ranges[i].empty()) { return true } } + return false + }; + + Selection.prototype.contains = function (pos, end) { + var this$1 = this; + + if (!end) { end = pos } + for (var i = 0; i < this.ranges.length; i++) { + var range = this$1.ranges[i] + if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0) + { return i } + } + return -1 + }; + + var Range = function(anchor, head) { + this.anchor = anchor; this.head = head + }; + + Range.prototype.from = function () { return minPos(this.anchor, this.head) }; + Range.prototype.to = function () { return maxPos(this.anchor, this.head) }; + Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch }; + +// Take an unsorted, potentially overlapping set of ranges, and +// build a selection out of it. 'Consumes' ranges array (modifying +// it). + function normalizeSelection(ranges, primIndex) { + var prim = ranges[primIndex] + ranges.sort(function (a, b) { return cmp(a.from(), b.from()); }) + primIndex = indexOf(ranges, prim) + for (var i = 1; i < ranges.length; i++) { + var cur = ranges[i], prev = ranges[i - 1] + if (cmp(prev.to(), cur.from()) >= 0) { + var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to()) + var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head + if (i <= primIndex) { --primIndex } + ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to)) + } + } + return new Selection(ranges, primIndex) + } + + function simpleSelection(anchor, head) { + return new Selection([new Range(anchor, head || anchor)], 0) + } + +// Compute the position of the end of a change (its 'to' property +// refers to the pre-change end). + function changeEnd(change) { + if (!change.text) { return change.to } + return Pos(change.from.line + change.text.length - 1, + lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0)) + } + +// Adjust a position to refer to the post-change position of the +// same text, or the end of the change if the change covers it. + function adjustForChange(pos, change) { + if (cmp(pos, change.from) < 0) { return pos } + if (cmp(pos, change.to) <= 0) { return changeEnd(change) } + + var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch + if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch } + return Pos(line, ch) + } + + function computeSelAfterChange(doc, change) { + var out = [] + for (var i = 0; i < doc.sel.ranges.length; i++) { + var range = doc.sel.ranges[i] + out.push(new Range(adjustForChange(range.anchor, change), + adjustForChange(range.head, change))) + } + return normalizeSelection(out, doc.sel.primIndex) + } + + function offsetPos(pos, old, nw) { + if (pos.line == old.line) + { return Pos(nw.line, pos.ch - old.ch + nw.ch) } + else + { return Pos(nw.line + (pos.line - old.line), pos.ch) } + } + +// Used by replaceSelections to allow moving the selection to the +// start or around the replaced test. Hint may be "start" or "around". + function computeReplacedSel(doc, changes, hint) { + var out = [] + var oldPrev = Pos(doc.first, 0), newPrev = oldPrev + for (var i = 0; i < changes.length; i++) { + var change = changes[i] + var from = offsetPos(change.from, oldPrev, newPrev) + var to = offsetPos(changeEnd(change), oldPrev, newPrev) + oldPrev = change.to + newPrev = to + if (hint == "around") { + var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0 + out[i] = new Range(inv ? to : from, inv ? from : to) + } else { + out[i] = new Range(from, from) + } + } + return new Selection(out, doc.sel.primIndex) + } + +// Used to get the editor into a consistent state again when options change. + + function loadMode(cm) { + cm.doc.mode = getMode(cm.options, cm.doc.modeOption) + resetModeState(cm) + } + + function resetModeState(cm) { + cm.doc.iter(function (line) { + if (line.stateAfter) { line.stateAfter = null } + if (line.styles) { line.styles = null } + }) + cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first + startWorker(cm, 100) + cm.state.modeGen++ + if (cm.curOp) { regChange(cm) } + } + +// DOCUMENT DATA STRUCTURE + +// By default, updates that start and end at the beginning of a line +// are treated specially, in order to make the association of line +// widgets and marker elements with the text behave more intuitive. + function isWholeLineUpdate(doc, change) { + return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" && + (!doc.cm || doc.cm.options.wholeLineUpdateBefore) + } + +// Perform a change on the document data structure. + function updateDoc(doc, change, markedSpans, estimateHeight) { + function spansFor(n) {return markedSpans ? markedSpans[n] : null} + function update(line, text, spans) { + updateLine(line, text, spans, estimateHeight) + signalLater(line, "change", line, change) + } + function linesFor(start, end) { + var result = [] + for (var i = start; i < end; ++i) + { result.push(new Line(text[i], spansFor(i), estimateHeight)) } + return result + } + + var from = change.from, to = change.to, text = change.text + var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line) + var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line + + // Adjust the line structure + if (change.full) { + doc.insert(0, linesFor(0, text.length)) + doc.remove(text.length, doc.size - text.length) + } else if (isWholeLineUpdate(doc, change)) { + // This is a whole-line replace. Treated specially to make + // sure line objects move the way they are supposed to. + var added = linesFor(0, text.length - 1) + update(lastLine, lastLine.text, lastSpans) + if (nlines) { doc.remove(from.line, nlines) } + if (added.length) { doc.insert(from.line, added) } + } else if (firstLine == lastLine) { + if (text.length == 1) { + update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans) + } else { + var added$1 = linesFor(1, text.length - 1) + added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight)) + update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)) + doc.insert(from.line + 1, added$1) + } + } else if (text.length == 1) { + update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0)) + doc.remove(from.line + 1, nlines) + } else { + update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)) + update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans) + var added$2 = linesFor(1, text.length - 1) + if (nlines > 1) { doc.remove(from.line + 1, nlines - 1) } + doc.insert(from.line + 1, added$2) + } + + signalLater(doc, "change", doc, change) + } + +// Call f for all linked documents. + function linkedDocs(doc, f, sharedHistOnly) { + function propagate(doc, skip, sharedHist) { + if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) { + var rel = doc.linked[i] + if (rel.doc == skip) { continue } + var shared = sharedHist && rel.sharedHist + if (sharedHistOnly && !shared) { continue } + f(rel.doc, shared) + propagate(rel.doc, doc, shared) + } } + } + propagate(doc, null, true) + } + +// Attach a document to an editor. + function attachDoc(cm, doc) { + if (doc.cm) { throw new Error("This document is already in use.") } + cm.doc = doc + doc.cm = cm + estimateLineHeights(cm) + loadMode(cm) + setDirectionClass(cm) + if (!cm.options.lineWrapping) { findMaxLine(cm) } + cm.options.mode = doc.modeOption + regChange(cm) + } + + function setDirectionClass(cm) { + ;(cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl") + } + + function directionChanged(cm) { + runInOp(cm, function () { + setDirectionClass(cm) + regChange(cm) + }) + } + + function History(startGen) { + // Arrays of change events and selections. Doing something adds an + // event to done and clears undo. Undoing moves events from done + // to undone, redoing moves them in the other direction. + this.done = []; this.undone = [] + this.undoDepth = Infinity + // Used to track when changes can be merged into a single undo + // event + this.lastModTime = this.lastSelTime = 0 + this.lastOp = this.lastSelOp = null + this.lastOrigin = this.lastSelOrigin = null + // Used by the isClean() method + this.generation = this.maxGeneration = startGen || 1 + } + +// Create a history change event from an updateDoc-style change +// object. + function historyChangeFromChange(doc, change) { + var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)} + attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1) + linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true) + return histChange + } + +// Pop all selection events off the end of a history array. Stop at +// a change event. + function clearSelectionEvents(array) { + while (array.length) { + var last = lst(array) + if (last.ranges) { array.pop() } + else { break } + } + } + +// Find the top change event in the history. Pop off selection +// events that are in the way. + function lastChangeEvent(hist, force) { + if (force) { + clearSelectionEvents(hist.done) + return lst(hist.done) + } else if (hist.done.length && !lst(hist.done).ranges) { + return lst(hist.done) + } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) { + hist.done.pop() + return lst(hist.done) + } + } + +// Register a change in the history. Merges changes that are within +// a single operation, or are close together with an origin that +// allows merging (starting with "+") into a single event. + function addChangeToHistory(doc, change, selAfter, opId) { + var hist = doc.history + hist.undone.length = 0 + var time = +new Date, cur + var last + + if ((hist.lastOp == opId || + hist.lastOrigin == change.origin && change.origin && + ((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) || + change.origin.charAt(0) == "*")) && + (cur = lastChangeEvent(hist, hist.lastOp == opId))) { + // Merge this change into the last event + last = lst(cur.changes) + if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) { + // Optimized case for simple insertion -- don't want to add + // new changesets for every character typed + last.to = changeEnd(change) + } else { + // Add new sub-event + cur.changes.push(historyChangeFromChange(doc, change)) + } + } else { + // Can not be merged, start a new event. + var before = lst(hist.done) + if (!before || !before.ranges) + { pushSelectionToHistory(doc.sel, hist.done) } + cur = {changes: [historyChangeFromChange(doc, change)], + generation: hist.generation} + hist.done.push(cur) + while (hist.done.length > hist.undoDepth) { + hist.done.shift() + if (!hist.done[0].ranges) { hist.done.shift() } + } + } + hist.done.push(selAfter) + hist.generation = ++hist.maxGeneration + hist.lastModTime = hist.lastSelTime = time + hist.lastOp = hist.lastSelOp = opId + hist.lastOrigin = hist.lastSelOrigin = change.origin + + if (!last) { signal(doc, "historyAdded") } + } + + function selectionEventCanBeMerged(doc, origin, prev, sel) { + var ch = origin.charAt(0) + return ch == "*" || + ch == "+" && + prev.ranges.length == sel.ranges.length && + prev.somethingSelected() == sel.somethingSelected() && + new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500) + } + +// Called whenever the selection changes, sets the new selection as +// the pending selection in the history, and pushes the old pending +// selection into the 'done' array when it was significantly +// different (in number of selected ranges, emptiness, or time). + function addSelectionToHistory(doc, sel, opId, options) { + var hist = doc.history, origin = options && options.origin + + // A new event is started when the previous origin does not match + // the current, or the origins don't allow matching. Origins + // starting with * are always merged, those starting with + are + // merged when similar and close together in time. + if (opId == hist.lastSelOp || + (origin && hist.lastSelOrigin == origin && + (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin || + selectionEventCanBeMerged(doc, origin, lst(hist.done), sel)))) + { hist.done[hist.done.length - 1] = sel } + else + { pushSelectionToHistory(sel, hist.done) } + + hist.lastSelTime = +new Date + hist.lastSelOrigin = origin + hist.lastSelOp = opId + if (options && options.clearRedo !== false) + { clearSelectionEvents(hist.undone) } + } + + function pushSelectionToHistory(sel, dest) { + var top = lst(dest) + if (!(top && top.ranges && top.equals(sel))) + { dest.push(sel) } + } + +// Used to store marked span information in the history. + function attachLocalSpans(doc, change, from, to) { + var existing = change["spans_" + doc.id], n = 0 + doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) { + if (line.markedSpans) + { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans } + ++n + }) + } + +// When un/re-doing restores text containing marked spans, those +// that have been explicitly cleared should not be restored. + function removeClearedSpans(spans) { + if (!spans) { return null } + var out + for (var i = 0; i < spans.length; ++i) { + if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i) } } + else if (out) { out.push(spans[i]) } + } + return !out ? spans : out.length ? out : null + } + +// Retrieve and filter the old marked spans stored in a change event. + function getOldSpans(doc, change) { + var found = change["spans_" + doc.id] + if (!found) { return null } + var nw = [] + for (var i = 0; i < change.text.length; ++i) + { nw.push(removeClearedSpans(found[i])) } + return nw + } + +// Used for un/re-doing changes from the history. Combines the +// result of computing the existing spans with the set of spans that +// existed in the history (so that deleting around a span and then +// undoing brings back the span). + function mergeOldSpans(doc, change) { + var old = getOldSpans(doc, change) + var stretched = stretchSpansOverChange(doc, change) + if (!old) { return stretched } + if (!stretched) { return old } + + for (var i = 0; i < old.length; ++i) { + var oldCur = old[i], stretchCur = stretched[i] + if (oldCur && stretchCur) { + spans: for (var j = 0; j < stretchCur.length; ++j) { + var span = stretchCur[j] + for (var k = 0; k < oldCur.length; ++k) + { if (oldCur[k].marker == span.marker) { continue spans } } + oldCur.push(span) + } + } else if (stretchCur) { + old[i] = stretchCur + } + } + return old + } + +// Used both to provide a JSON-safe object in .getHistory, and, when +// detaching a document, to split the history in two + function copyHistoryArray(events, newGroup, instantiateSel) { + var copy = [] + for (var i = 0; i < events.length; ++i) { + var event = events[i] + if (event.ranges) { + copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event) + continue + } + var changes = event.changes, newChanges = [] + copy.push({changes: newChanges}) + for (var j = 0; j < changes.length; ++j) { + var change = changes[j], m = (void 0) + newChanges.push({from: change.from, to: change.to, text: change.text}) + if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) { + if (indexOf(newGroup, Number(m[1])) > -1) { + lst(newChanges)[prop] = change[prop] + delete change[prop] + } + } } } + } + } + return copy + } + +// The 'scroll' parameter given to many of these indicated whether +// the new cursor position should be scrolled into view after +// modifying the selection. + +// If shift is held or the extend flag is set, extends a range to +// include a given position (and optionally a second position). +// Otherwise, simply returns the range between the given positions. +// Used for cursor motion and such. + function extendRange(range, head, other, extend) { + if (extend) { + var anchor = range.anchor + if (other) { + var posBefore = cmp(head, anchor) < 0 + if (posBefore != (cmp(other, anchor) < 0)) { + anchor = head + head = other + } else if (posBefore != (cmp(head, other) < 0)) { + head = other + } + } + return new Range(anchor, head) + } else { + return new Range(other || head, head) + } + } + +// Extend the primary selection range, discard the rest. + function extendSelection(doc, head, other, options, extend) { + if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend) } + setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options) + } + +// Extend all selections (pos is an array of selections with length +// equal the number of selections) + function extendSelections(doc, heads, options) { + var out = [] + var extend = doc.cm && (doc.cm.display.shift || doc.extend) + for (var i = 0; i < doc.sel.ranges.length; i++) + { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend) } + var newSel = normalizeSelection(out, doc.sel.primIndex) + setSelection(doc, newSel, options) + } + +// Updates a single range in the selection. + function replaceOneSelection(doc, i, range, options) { + var ranges = doc.sel.ranges.slice(0) + ranges[i] = range + setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options) + } + +// Reset the selection to a single range. + function setSimpleSelection(doc, anchor, head, options) { + setSelection(doc, simpleSelection(anchor, head), options) + } + +// Give beforeSelectionChange handlers a change to influence a +// selection update. + function filterSelectionChange(doc, sel, options) { + var obj = { + ranges: sel.ranges, + update: function(ranges) { + var this$1 = this; + + this.ranges = [] + for (var i = 0; i < ranges.length; i++) + { this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor), + clipPos(doc, ranges[i].head)) } + }, + origin: options && options.origin + } + signal(doc, "beforeSelectionChange", doc, obj) + if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj) } + if (obj.ranges != sel.ranges) { return normalizeSelection(obj.ranges, obj.ranges.length - 1) } + else { return sel } + } + + function setSelectionReplaceHistory(doc, sel, options) { + var done = doc.history.done, last = lst(done) + if (last && last.ranges) { + done[done.length - 1] = sel + setSelectionNoUndo(doc, sel, options) + } else { + setSelection(doc, sel, options) + } + } + +// Set a new selection. + function setSelection(doc, sel, options) { + setSelectionNoUndo(doc, sel, options) + addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options) + } + + function setSelectionNoUndo(doc, sel, options) { + if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange")) + { sel = filterSelectionChange(doc, sel, options) } + + var bias = options && options.bias || + (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1) + setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true)) + + if (!(options && options.scroll === false) && doc.cm) + { ensureCursorVisible(doc.cm) } + } + + function setSelectionInner(doc, sel) { + if (sel.equals(doc.sel)) { return } + + doc.sel = sel + + if (doc.cm) { + doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true + signalCursorActivity(doc.cm) + } + signalLater(doc, "cursorActivity", doc) + } + +// Verify that the selection does not partially select any atomic +// marked ranges. + function reCheckSelection(doc) { + setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false)) + } + +// Return a selection that does not partially select any atomic +// ranges. + function skipAtomicInSelection(doc, sel, bias, mayClear) { + var out + for (var i = 0; i < sel.ranges.length; i++) { + var range = sel.ranges[i] + var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i] + var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear) + var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear) + if (out || newAnchor != range.anchor || newHead != range.head) { + if (!out) { out = sel.ranges.slice(0, i) } + out[i] = new Range(newAnchor, newHead) + } + } + return out ? normalizeSelection(out, sel.primIndex) : sel + } + + function skipAtomicInner(doc, pos, oldPos, dir, mayClear) { + var line = getLine(doc, pos.line) + if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) { + var sp = line.markedSpans[i], m = sp.marker + if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) && + (sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) { + if (mayClear) { + signal(m, "beforeCursorEnter") + if (m.explicitlyCleared) { + if (!line.markedSpans) { break } + else {--i; continue} + } + } + if (!m.atomic) { continue } + + if (oldPos) { + var near = m.find(dir < 0 ? 1 : -1), diff = (void 0) + if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft) + { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null) } + if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0)) + { return skipAtomicInner(doc, near, pos, dir, mayClear) } + } + + var far = m.find(dir < 0 ? -1 : 1) + if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight) + { far = movePos(doc, far, dir, far.line == pos.line ? line : null) } + return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null + } + } } + return pos + } + +// Ensure a given position is not inside an atomic range. + function skipAtomic(doc, pos, oldPos, bias, mayClear) { + var dir = bias || 1 + var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) || + (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) || + skipAtomicInner(doc, pos, oldPos, -dir, mayClear) || + (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true)) + if (!found) { + doc.cantEdit = true + return Pos(doc.first, 0) + } + return found + } + + function movePos(doc, pos, dir, line) { + if (dir < 0 && pos.ch == 0) { + if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) } + else { return null } + } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) { + if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) } + else { return null } + } else { + return new Pos(pos.line, pos.ch + dir) + } + } + + function selectAll(cm) { + cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll) + } + +// UPDATING + +// Allow "beforeChange" event handlers to influence a change + function filterChange(doc, change, update) { + var obj = { + canceled: false, + from: change.from, + to: change.to, + text: change.text, + origin: change.origin, + cancel: function () { return obj.canceled = true; } + } + if (update) { obj.update = function (from, to, text, origin) { + if (from) { obj.from = clipPos(doc, from) } + if (to) { obj.to = clipPos(doc, to) } + if (text) { obj.text = text } + if (origin !== undefined) { obj.origin = origin } + } } + signal(doc, "beforeChange", doc, obj) + if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj) } + + if (obj.canceled) { return null } + return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin} + } + +// Apply a change to a document, and add it to the document's +// history, and propagating it to all linked documents. + function makeChange(doc, change, ignoreReadOnly) { + if (doc.cm) { + if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) } + if (doc.cm.state.suppressEdits) { return } + } + + if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) { + change = filterChange(doc, change, true) + if (!change) { return } + } + + // Possibly split or suppress the update based on the presence + // of read-only spans in its range. + var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to) + if (split) { + for (var i = split.length - 1; i >= 0; --i) + { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}) } + } else { + makeChangeInner(doc, change) + } + } + + function makeChangeInner(doc, change) { + if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return } + var selAfter = computeSelAfterChange(doc, change) + addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN) + + makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change)) + var rebased = [] + + linkedDocs(doc, function (doc, sharedHist) { + if (!sharedHist && indexOf(rebased, doc.history) == -1) { + rebaseHist(doc.history, change) + rebased.push(doc.history) + } + makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change)) + }) + } + +// Revert a change stored in a document's history. + function makeChangeFromHistory(doc, type, allowSelectionOnly) { + if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) { return } + + var hist = doc.history, event, selAfter = doc.sel + var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done + + // Verify that there is a useable event (so that ctrl-z won't + // needlessly clear selection events) + var i = 0 + for (; i < source.length; i++) { + event = source[i] + if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges) + { break } + } + if (i == source.length) { return } + hist.lastOrigin = hist.lastSelOrigin = null + + for (;;) { + event = source.pop() + if (event.ranges) { + pushSelectionToHistory(event, dest) + if (allowSelectionOnly && !event.equals(doc.sel)) { + setSelection(doc, event, {clearRedo: false}) + return + } + selAfter = event + } + else { break } + } + + // Build up a reverse change object to add to the opposite history + // stack (redo when undoing, and vice versa). + var antiChanges = [] + pushSelectionToHistory(selAfter, dest) + dest.push({changes: antiChanges, generation: hist.generation}) + hist.generation = event.generation || ++hist.maxGeneration + + var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange") + + var loop = function ( i ) { + var change = event.changes[i] + change.origin = type + if (filter && !filterChange(doc, change, false)) { + source.length = 0 + return {} + } + + antiChanges.push(historyChangeFromChange(doc, change)) + + var after = i ? computeSelAfterChange(doc, change) : lst(source) + makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change)) + if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}) } + var rebased = [] + + // Propagate to the linked documents + linkedDocs(doc, function (doc, sharedHist) { + if (!sharedHist && indexOf(rebased, doc.history) == -1) { + rebaseHist(doc.history, change) + rebased.push(doc.history) + } + makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change)) + }) + }; + + for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) { + var returned = loop( i$1 ); + + if ( returned ) return returned.v; + } + } + +// Sub-views need their line numbers shifted when text is added +// above or below them in the parent document. + function shiftDoc(doc, distance) { + if (distance == 0) { return } + doc.first += distance + doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range( + Pos(range.anchor.line + distance, range.anchor.ch), + Pos(range.head.line + distance, range.head.ch) + ); }), doc.sel.primIndex) + if (doc.cm) { + regChange(doc.cm, doc.first, doc.first - distance, distance) + for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++) + { regLineChange(doc.cm, l, "gutter") } + } + } + +// More lower-level change function, handling only a single document +// (not linked ones). + function makeChangeSingleDoc(doc, change, selAfter, spans) { + if (doc.cm && !doc.cm.curOp) + { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) } + + if (change.to.line < doc.first) { + shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line)) + return + } + if (change.from.line > doc.lastLine()) { return } + + // Clip the change to the size of this doc + if (change.from.line < doc.first) { + var shift = change.text.length - 1 - (doc.first - change.from.line) + shiftDoc(doc, shift) + change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch), + text: [lst(change.text)], origin: change.origin} + } + var last = doc.lastLine() + if (change.to.line > last) { + change = {from: change.from, to: Pos(last, getLine(doc, last).text.length), + text: [change.text[0]], origin: change.origin} + } + + change.removed = getBetween(doc, change.from, change.to) + + if (!selAfter) { selAfter = computeSelAfterChange(doc, change) } + if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans) } + else { updateDoc(doc, change, spans) } + setSelectionNoUndo(doc, selAfter, sel_dontScroll) + } + +// Handle the interaction of a change to a document with the editor +// that this document is part of. + function makeChangeSingleDocInEditor(cm, change, spans) { + var doc = cm.doc, display = cm.display, from = change.from, to = change.to + + var recomputeMaxLength = false, checkWidthStart = from.line + if (!cm.options.lineWrapping) { + checkWidthStart = lineNo(visualLine(getLine(doc, from.line))) + doc.iter(checkWidthStart, to.line + 1, function (line) { + if (line == display.maxLine) { + recomputeMaxLength = true + return true + } + }) + } + + if (doc.sel.contains(change.from, change.to) > -1) + { signalCursorActivity(cm) } + + updateDoc(doc, change, spans, estimateHeight(cm)) + + if (!cm.options.lineWrapping) { + doc.iter(checkWidthStart, from.line + change.text.length, function (line) { + var len = lineLength(line) + if (len > display.maxLineLength) { + display.maxLine = line + display.maxLineLength = len + display.maxLineChanged = true + recomputeMaxLength = false + } + }) + if (recomputeMaxLength) { cm.curOp.updateMaxLine = true } + } + + retreatFrontier(doc, from.line) + startWorker(cm, 400) + + var lendiff = change.text.length - (to.line - from.line) - 1 + // Remember that these lines changed, for updating the display + if (change.full) + { regChange(cm) } + else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change)) + { regLineChange(cm, from.line, "text") } + else + { regChange(cm, from.line, to.line + 1, lendiff) } + + var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change") + if (changeHandler || changesHandler) { + var obj = { + from: from, to: to, + text: change.text, + removed: change.removed, + origin: change.origin + } + if (changeHandler) { signalLater(cm, "change", cm, obj) } + if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj) } + } + cm.display.selForContextMenu = null + } + + function replaceRange(doc, code, from, to, origin) { + if (!to) { to = from } + if (cmp(to, from) < 0) { var assign; + (assign = [to, from], from = assign[0], to = assign[1], assign) } + if (typeof code == "string") { code = doc.splitLines(code) } + makeChange(doc, {from: from, to: to, text: code, origin: origin}) + } + +// Rebasing/resetting history to deal with externally-sourced changes + + function rebaseHistSelSingle(pos, from, to, diff) { + if (to < pos.line) { + pos.line += diff + } else if (from < pos.line) { + pos.line = from + pos.ch = 0 + } + } + +// Tries to rebase an array of history events given a change in the +// document. If the change touches the same lines as the event, the +// event, and everything 'behind' it, is discarded. If the change is +// before the event, the event's positions are updated. Uses a +// copy-on-write scheme for the positions, to avoid having to +// reallocate them all on every rebase, but also avoid problems with +// shared position objects being unsafely updated. + function rebaseHistArray(array, from, to, diff) { + for (var i = 0; i < array.length; ++i) { + var sub = array[i], ok = true + if (sub.ranges) { + if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true } + for (var j = 0; j < sub.ranges.length; j++) { + rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff) + rebaseHistSelSingle(sub.ranges[j].head, from, to, diff) + } + continue + } + for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) { + var cur = sub.changes[j$1] + if (to < cur.from.line) { + cur.from = Pos(cur.from.line + diff, cur.from.ch) + cur.to = Pos(cur.to.line + diff, cur.to.ch) + } else if (from <= cur.to.line) { + ok = false + break + } + } + if (!ok) { + array.splice(0, i + 1) + i = 0 + } + } + } + + function rebaseHist(hist, change) { + var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1 + rebaseHistArray(hist.done, from, to, diff) + rebaseHistArray(hist.undone, from, to, diff) + } + +// Utility for applying a change to a line by handle or number, +// returning the number and optionally registering the line as +// changed. + function changeLine(doc, handle, changeType, op) { + var no = handle, line = handle + if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)) } + else { no = lineNo(handle) } + if (no == null) { return null } + if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType) } + return line + } + +// The document is represented as a BTree consisting of leaves, with +// chunk of lines in them, and branches, with up to ten leaves or +// other branch nodes below them. The top node is always a branch +// node, and is the document object itself (meaning it has +// additional methods and properties). +// +// All nodes have parent links. The tree is used both to go from +// line numbers to line objects, and to go from objects to numbers. +// It also indexes by height, and is used to convert between height +// and line object, and to find the total height of the document. +// +// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html + + function LeafChunk(lines) { + var this$1 = this; + + this.lines = lines + this.parent = null + var height = 0 + for (var i = 0; i < lines.length; ++i) { + lines[i].parent = this$1 + height += lines[i].height + } + this.height = height + } + + LeafChunk.prototype = { + chunkSize: function chunkSize() { return this.lines.length }, + + // Remove the n lines at offset 'at'. + removeInner: function removeInner(at, n) { + var this$1 = this; + + for (var i = at, e = at + n; i < e; ++i) { + var line = this$1.lines[i] + this$1.height -= line.height + cleanUpLine(line) + signalLater(line, "delete") + } + this.lines.splice(at, n) + }, + + // Helper used to collapse a small branch into a single leaf. + collapse: function collapse(lines) { + lines.push.apply(lines, this.lines) + }, + + // Insert the given array of lines at offset 'at', count them as + // having the given height. + insertInner: function insertInner(at, lines, height) { + var this$1 = this; + + this.height += height + this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at)) + for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1 } + }, + + // Used to iterate over a part of the tree. + iterN: function iterN(at, n, op) { + var this$1 = this; + + for (var e = at + n; at < e; ++at) + { if (op(this$1.lines[at])) { return true } } + } + } + + function BranchChunk(children) { + var this$1 = this; + + this.children = children + var size = 0, height = 0 + for (var i = 0; i < children.length; ++i) { + var ch = children[i] + size += ch.chunkSize(); height += ch.height + ch.parent = this$1 + } + this.size = size + this.height = height + this.parent = null + } + + BranchChunk.prototype = { + chunkSize: function chunkSize() { return this.size }, + + removeInner: function removeInner(at, n) { + var this$1 = this; + + this.size -= n + for (var i = 0; i < this.children.length; ++i) { + var child = this$1.children[i], sz = child.chunkSize() + if (at < sz) { + var rm = Math.min(n, sz - at), oldHeight = child.height + child.removeInner(at, rm) + this$1.height -= oldHeight - child.height + if (sz == rm) { this$1.children.splice(i--, 1); child.parent = null } + if ((n -= rm) == 0) { break } + at = 0 + } else { at -= sz } + } + // If the result is smaller than 25 lines, ensure that it is a + // single leaf node. + if (this.size - n < 25 && + (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) { + var lines = [] + this.collapse(lines) + this.children = [new LeafChunk(lines)] + this.children[0].parent = this + } + }, + + collapse: function collapse(lines) { + var this$1 = this; + + for (var i = 0; i < this.children.length; ++i) { this$1.children[i].collapse(lines) } + }, + + insertInner: function insertInner(at, lines, height) { + var this$1 = this; + + this.size += lines.length + this.height += height + for (var i = 0; i < this.children.length; ++i) { + var child = this$1.children[i], sz = child.chunkSize() + if (at <= sz) { + child.insertInner(at, lines, height) + if (child.lines && child.lines.length > 50) { + // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced. + // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest. + var remaining = child.lines.length % 25 + 25 + for (var pos = remaining; pos < child.lines.length;) { + var leaf = new LeafChunk(child.lines.slice(pos, pos += 25)) + child.height -= leaf.height + this$1.children.splice(++i, 0, leaf) + leaf.parent = this$1 + } + child.lines = child.lines.slice(0, remaining) + this$1.maybeSpill() + } + break + } + at -= sz + } + }, + + // When a node has grown, check whether it should be split. + maybeSpill: function maybeSpill() { + if (this.children.length <= 10) { return } + var me = this + do { + var spilled = me.children.splice(me.children.length - 5, 5) + var sibling = new BranchChunk(spilled) + if (!me.parent) { // Become the parent node + var copy = new BranchChunk(me.children) + copy.parent = me + me.children = [copy, sibling] + me = copy + } else { + me.size -= sibling.size + me.height -= sibling.height + var myIndex = indexOf(me.parent.children, me) + me.parent.children.splice(myIndex + 1, 0, sibling) + } + sibling.parent = me.parent + } while (me.children.length > 10) + me.parent.maybeSpill() + }, + + iterN: function iterN(at, n, op) { + var this$1 = this; + + for (var i = 0; i < this.children.length; ++i) { + var child = this$1.children[i], sz = child.chunkSize() + if (at < sz) { + var used = Math.min(n, sz - at) + if (child.iterN(at, used, op)) { return true } + if ((n -= used) == 0) { break } + at = 0 + } else { at -= sz } + } + } + } + +// Line widgets are block elements displayed above or below a line. + + var LineWidget = function(doc, node, options) { + var this$1 = this; + + if (options) { for (var opt in options) { if (options.hasOwnProperty(opt)) + { this$1[opt] = options[opt] } } } + this.doc = doc + this.node = node + }; + + LineWidget.prototype.clear = function () { + var this$1 = this; + + var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line) + if (no == null || !ws) { return } + for (var i = 0; i < ws.length; ++i) { if (ws[i] == this$1) { ws.splice(i--, 1) } } + if (!ws.length) { line.widgets = null } + var height = widgetHeight(this) + updateLineHeight(line, Math.max(0, line.height - height)) + if (cm) { + runInOp(cm, function () { + adjustScrollWhenAboveVisible(cm, line, -height) + regLineChange(cm, no, "widget") + }) + signalLater(cm, "lineWidgetCleared", cm, this, no) + } + }; + + LineWidget.prototype.changed = function () { + var this$1 = this; + + var oldH = this.height, cm = this.doc.cm, line = this.line + this.height = null + var diff = widgetHeight(this) - oldH + if (!diff) { return } + updateLineHeight(line, line.height + diff) + if (cm) { + runInOp(cm, function () { + cm.curOp.forceUpdate = true + adjustScrollWhenAboveVisible(cm, line, diff) + signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line)) + }) + } + }; + eventMixin(LineWidget) + + function adjustScrollWhenAboveVisible(cm, line, diff) { + if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop)) + { addToScrollTop(cm, diff) } + } + + function addLineWidget(doc, handle, node, options) { + var widget = new LineWidget(doc, node, options) + var cm = doc.cm + if (cm && widget.noHScroll) { cm.display.alignWidgets = true } + changeLine(doc, handle, "widget", function (line) { + var widgets = line.widgets || (line.widgets = []) + if (widget.insertAt == null) { widgets.push(widget) } + else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget) } + widget.line = line + if (cm && !lineIsHidden(doc, line)) { + var aboveVisible = heightAtLine(line) < doc.scrollTop + updateLineHeight(line, line.height + widgetHeight(widget)) + if (aboveVisible) { addToScrollTop(cm, widget.height) } + cm.curOp.forceUpdate = true + } + return true + }) + signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)) + return widget + } + +// TEXTMARKERS + +// Created with markText and setBookmark methods. A TextMarker is a +// handle that can be used to clear or find a marked position in the +// document. Line objects hold arrays (markedSpans) containing +// {from, to, marker} object pointing to such marker objects, and +// indicating that such a marker is present on that line. Multiple +// lines may point to the same marker when it spans across lines. +// The spans will have null for their from/to properties when the +// marker continues beyond the start/end of the line. Markers have +// links back to the lines they currently touch. + +// Collapsed markers have unique ids, in order to be able to order +// them, which is needed for uniquely determining an outer marker +// when they overlap (they may nest, but not partially overlap). + var nextMarkerId = 0 + + var TextMarker = function(doc, type) { + this.lines = [] + this.type = type + this.doc = doc + this.id = ++nextMarkerId + }; + +// Clear the marker. + TextMarker.prototype.clear = function () { + var this$1 = this; + + if (this.explicitlyCleared) { return } + var cm = this.doc.cm, withOp = cm && !cm.curOp + if (withOp) { startOperation(cm) } + if (hasHandler(this, "clear")) { + var found = this.find() + if (found) { signalLater(this, "clear", found.from, found.to) } + } + var min = null, max = null + for (var i = 0; i < this.lines.length; ++i) { + var line = this$1.lines[i] + var span = getMarkedSpanFor(line.markedSpans, this$1) + if (cm && !this$1.collapsed) { regLineChange(cm, lineNo(line), "text") } + else if (cm) { + if (span.to != null) { max = lineNo(line) } + if (span.from != null) { min = lineNo(line) } + } + line.markedSpans = removeMarkedSpan(line.markedSpans, span) + if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm) + { updateLineHeight(line, textHeight(cm.display)) } + } + if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) { + var visual = visualLine(this$1.lines[i$1]), len = lineLength(visual) + if (len > cm.display.maxLineLength) { + cm.display.maxLine = visual + cm.display.maxLineLength = len + cm.display.maxLineChanged = true + } + } } + + if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1) } + this.lines.length = 0 + this.explicitlyCleared = true + if (this.atomic && this.doc.cantEdit) { + this.doc.cantEdit = false + if (cm) { reCheckSelection(cm.doc) } + } + if (cm) { signalLater(cm, "markerCleared", cm, this, min, max) } + if (withOp) { endOperation(cm) } + if (this.parent) { this.parent.clear() } + }; + +// Find the position of the marker in the document. Returns a {from, +// to} object by default. Side can be passed to get a specific side +// -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the +// Pos objects returned contain a line object, rather than a line +// number (used to prevent looking up the same line twice). + TextMarker.prototype.find = function (side, lineObj) { + var this$1 = this; + + if (side == null && this.type == "bookmark") { side = 1 } + var from, to + for (var i = 0; i < this.lines.length; ++i) { + var line = this$1.lines[i] + var span = getMarkedSpanFor(line.markedSpans, this$1) + if (span.from != null) { + from = Pos(lineObj ? line : lineNo(line), span.from) + if (side == -1) { return from } + } + if (span.to != null) { + to = Pos(lineObj ? line : lineNo(line), span.to) + if (side == 1) { return to } + } + } + return from && {from: from, to: to} + }; + +// Signals that the marker's widget changed, and surrounding layout +// should be recomputed. + TextMarker.prototype.changed = function () { + var this$1 = this; + + var pos = this.find(-1, true), widget = this, cm = this.doc.cm + if (!pos || !cm) { return } + runInOp(cm, function () { + var line = pos.line, lineN = lineNo(pos.line) + var view = findViewForLine(cm, lineN) + if (view) { + clearLineMeasurementCacheFor(view) + cm.curOp.selectionChanged = cm.curOp.forceUpdate = true + } + cm.curOp.updateMaxLine = true + if (!lineIsHidden(widget.doc, line) && widget.height != null) { + var oldHeight = widget.height + widget.height = null + var dHeight = widgetHeight(widget) - oldHeight + if (dHeight) + { updateLineHeight(line, line.height + dHeight) } + } + signalLater(cm, "markerChanged", cm, this$1) + }) + }; + + TextMarker.prototype.attachLine = function (line) { + if (!this.lines.length && this.doc.cm) { + var op = this.doc.cm.curOp + if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1) + { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this) } + } + this.lines.push(line) + }; + + TextMarker.prototype.detachLine = function (line) { + this.lines.splice(indexOf(this.lines, line), 1) + if (!this.lines.length && this.doc.cm) { + var op = this.doc.cm.curOp + ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this) + } + }; + eventMixin(TextMarker) + +// Create a marker, wire it up to the right lines, and + function markText(doc, from, to, options, type) { + // Shared markers (across linked documents) are handled separately + // (markTextShared will call out to this again, once per + // document). + if (options && options.shared) { return markTextShared(doc, from, to, options, type) } + // Ensure we are in an operation. + if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) } + + var marker = new TextMarker(doc, type), diff = cmp(from, to) + if (options) { copyObj(options, marker, false) } + // Don't connect empty markers unless clearWhenEmpty is false + if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false) + { return marker } + if (marker.replacedWith) { + // Showing up as a widget implies collapsed (widget replaces text) + marker.collapsed = true + marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget") + if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true") } + if (options.insertLeft) { marker.widgetNode.insertLeft = true } + } + if (marker.collapsed) { + if (conflictingCollapsedRange(doc, from.line, from, to, marker) || + from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker)) + { throw new Error("Inserting collapsed marker partially overlapping an existing one") } + seeCollapsedSpans() + } + + if (marker.addToHistory) + { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN) } + + var curLine = from.line, cm = doc.cm, updateMaxLine + doc.iter(curLine, to.line + 1, function (line) { + if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine) + { updateMaxLine = true } + if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0) } + addMarkedSpan(line, new MarkedSpan(marker, + curLine == from.line ? from.ch : null, + curLine == to.line ? to.ch : null)) + ++curLine + }) + // lineIsHidden depends on the presence of the spans, so needs a second pass + if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) { + if (lineIsHidden(doc, line)) { updateLineHeight(line, 0) } + }) } + + if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }) } + + if (marker.readOnly) { + seeReadOnlySpans() + if (doc.history.done.length || doc.history.undone.length) + { doc.clearHistory() } + } + if (marker.collapsed) { + marker.id = ++nextMarkerId + marker.atomic = true + } + if (cm) { + // Sync editor state + if (updateMaxLine) { cm.curOp.updateMaxLine = true } + if (marker.collapsed) + { regChange(cm, from.line, to.line + 1) } + else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css) + { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text") } } + if (marker.atomic) { reCheckSelection(cm.doc) } + signalLater(cm, "markerAdded", cm, marker) + } + return marker + } + +// SHARED TEXTMARKERS + +// A shared marker spans multiple linked documents. It is +// implemented as a meta-marker-object controlling multiple normal +// markers. + var SharedTextMarker = function(markers, primary) { + var this$1 = this; + + this.markers = markers + this.primary = primary + for (var i = 0; i < markers.length; ++i) + { markers[i].parent = this$1 } + }; + + SharedTextMarker.prototype.clear = function () { + var this$1 = this; + + if (this.explicitlyCleared) { return } + this.explicitlyCleared = true + for (var i = 0; i < this.markers.length; ++i) + { this$1.markers[i].clear() } + signalLater(this, "clear") + }; + + SharedTextMarker.prototype.find = function (side, lineObj) { + return this.primary.find(side, lineObj) + }; + eventMixin(SharedTextMarker) + + function markTextShared(doc, from, to, options, type) { + options = copyObj(options) + options.shared = false + var markers = [markText(doc, from, to, options, type)], primary = markers[0] + var widget = options.widgetNode + linkedDocs(doc, function (doc) { + if (widget) { options.widgetNode = widget.cloneNode(true) } + markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type)) + for (var i = 0; i < doc.linked.length; ++i) + { if (doc.linked[i].isParent) { return } } + primary = lst(markers) + }) + return new SharedTextMarker(markers, primary) + } + + function findSharedMarkers(doc) { + return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; }) + } + + function copySharedMarkers(doc, markers) { + for (var i = 0; i < markers.length; i++) { + var marker = markers[i], pos = marker.find() + var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to) + if (cmp(mFrom, mTo)) { + var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type) + marker.markers.push(subMark) + subMark.parent = marker + } + } + } + + function detachSharedMarkers(markers) { + var loop = function ( i ) { + var marker = markers[i], linked = [marker.primary.doc] + linkedDocs(marker.primary.doc, function (d) { return linked.push(d); }) + for (var j = 0; j < marker.markers.length; j++) { + var subMarker = marker.markers[j] + if (indexOf(linked, subMarker.doc) == -1) { + subMarker.parent = null + marker.markers.splice(j--, 1) + } + } + }; + + for (var i = 0; i < markers.length; i++) loop( i ); + } + + var nextDocId = 0 + var Doc = function(text, mode, firstLine, lineSep, direction) { + if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) } + if (firstLine == null) { firstLine = 0 } + + BranchChunk.call(this, [new LeafChunk([new Line("", null)])]) + this.first = firstLine + this.scrollTop = this.scrollLeft = 0 + this.cantEdit = false + this.cleanGeneration = 1 + this.modeFrontier = this.highlightFrontier = firstLine + var start = Pos(firstLine, 0) + this.sel = simpleSelection(start) + this.history = new History(null) + this.id = ++nextDocId + this.modeOption = mode + this.lineSep = lineSep + this.direction = (direction == "rtl") ? "rtl" : "ltr" + this.extend = false + + if (typeof text == "string") { text = this.splitLines(text) } + updateDoc(this, {from: start, to: start, text: text}) + setSelection(this, simpleSelection(start), sel_dontScroll) + } + + Doc.prototype = createObj(BranchChunk.prototype, { + constructor: Doc, + // Iterate over the document. Supports two forms -- with only one + // argument, it calls that for each line in the document. With + // three, it iterates over the range given by the first two (with + // the second being non-inclusive). + iter: function(from, to, op) { + if (op) { this.iterN(from - this.first, to - from, op) } + else { this.iterN(this.first, this.first + this.size, from) } + }, + + // Non-public interface for adding and removing lines. + insert: function(at, lines) { + var height = 0 + for (var i = 0; i < lines.length; ++i) { height += lines[i].height } + this.insertInner(at - this.first, lines, height) + }, + remove: function(at, n) { this.removeInner(at - this.first, n) }, + + // From here, the methods are part of the public interface. Most + // are also available from CodeMirror (editor) instances. + + getValue: function(lineSep) { + var lines = getLines(this, this.first, this.first + this.size) + if (lineSep === false) { return lines } + return lines.join(lineSep || this.lineSeparator()) + }, + setValue: docMethodOp(function(code) { + var top = Pos(this.first, 0), last = this.first + this.size - 1 + makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length), + text: this.splitLines(code), origin: "setValue", full: true}, true) + if (this.cm) { scrollToCoords(this.cm, 0, 0) } + setSelection(this, simpleSelection(top), sel_dontScroll) + }), + replaceRange: function(code, from, to, origin) { + from = clipPos(this, from) + to = to ? clipPos(this, to) : from + replaceRange(this, code, from, to, origin) + }, + getRange: function(from, to, lineSep) { + var lines = getBetween(this, clipPos(this, from), clipPos(this, to)) + if (lineSep === false) { return lines } + return lines.join(lineSep || this.lineSeparator()) + }, + + getLine: function(line) {var l = this.getLineHandle(line); return l && l.text}, + + getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }}, + getLineNumber: function(line) {return lineNo(line)}, + + getLineHandleVisualStart: function(line) { + if (typeof line == "number") { line = getLine(this, line) } + return visualLine(line) + }, + + lineCount: function() {return this.size}, + firstLine: function() {return this.first}, + lastLine: function() {return this.first + this.size - 1}, + + clipPos: function(pos) {return clipPos(this, pos)}, + + getCursor: function(start) { + var range = this.sel.primary(), pos + if (start == null || start == "head") { pos = range.head } + else if (start == "anchor") { pos = range.anchor } + else if (start == "end" || start == "to" || start === false) { pos = range.to() } + else { pos = range.from() } + return pos + }, + listSelections: function() { return this.sel.ranges }, + somethingSelected: function() {return this.sel.somethingSelected()}, + + setCursor: docMethodOp(function(line, ch, options) { + setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options) + }), + setSelection: docMethodOp(function(anchor, head, options) { + setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options) + }), + extendSelection: docMethodOp(function(head, other, options) { + extendSelection(this, clipPos(this, head), other && clipPos(this, other), options) + }), + extendSelections: docMethodOp(function(heads, options) { + extendSelections(this, clipPosArray(this, heads), options) + }), + extendSelectionsBy: docMethodOp(function(f, options) { + var heads = map(this.sel.ranges, f) + extendSelections(this, clipPosArray(this, heads), options) + }), + setSelections: docMethodOp(function(ranges, primary, options) { + var this$1 = this; + + if (!ranges.length) { return } + var out = [] + for (var i = 0; i < ranges.length; i++) + { out[i] = new Range(clipPos(this$1, ranges[i].anchor), + clipPos(this$1, ranges[i].head)) } + if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex) } + setSelection(this, normalizeSelection(out, primary), options) + }), + addSelection: docMethodOp(function(anchor, head, options) { + var ranges = this.sel.ranges.slice(0) + ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor))) + setSelection(this, normalizeSelection(ranges, ranges.length - 1), options) + }), + + getSelection: function(lineSep) { + var this$1 = this; + + var ranges = this.sel.ranges, lines + for (var i = 0; i < ranges.length; i++) { + var sel = getBetween(this$1, ranges[i].from(), ranges[i].to()) + lines = lines ? lines.concat(sel) : sel + } + if (lineSep === false) { return lines } + else { return lines.join(lineSep || this.lineSeparator()) } + }, + getSelections: function(lineSep) { + var this$1 = this; + + var parts = [], ranges = this.sel.ranges + for (var i = 0; i < ranges.length; i++) { + var sel = getBetween(this$1, ranges[i].from(), ranges[i].to()) + if (lineSep !== false) { sel = sel.join(lineSep || this$1.lineSeparator()) } + parts[i] = sel + } + return parts + }, + replaceSelection: function(code, collapse, origin) { + var dup = [] + for (var i = 0; i < this.sel.ranges.length; i++) + { dup[i] = code } + this.replaceSelections(dup, collapse, origin || "+input") + }, + replaceSelections: docMethodOp(function(code, collapse, origin) { + var this$1 = this; + + var changes = [], sel = this.sel + for (var i = 0; i < sel.ranges.length; i++) { + var range = sel.ranges[i] + changes[i] = {from: range.from(), to: range.to(), text: this$1.splitLines(code[i]), origin: origin} + } + var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse) + for (var i$1 = changes.length - 1; i$1 >= 0; i$1--) + { makeChange(this$1, changes[i$1]) } + if (newSel) { setSelectionReplaceHistory(this, newSel) } + else if (this.cm) { ensureCursorVisible(this.cm) } + }), + undo: docMethodOp(function() {makeChangeFromHistory(this, "undo")}), + redo: docMethodOp(function() {makeChangeFromHistory(this, "redo")}), + undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true)}), + redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true)}), + + setExtending: function(val) {this.extend = val}, + getExtending: function() {return this.extend}, + + historySize: function() { + var hist = this.history, done = 0, undone = 0 + for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done } } + for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone } } + return {undo: done, redo: undone} + }, + clearHistory: function() {this.history = new History(this.history.maxGeneration)}, + + markClean: function() { + this.cleanGeneration = this.changeGeneration(true) + }, + changeGeneration: function(forceSplit) { + if (forceSplit) + { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null } + return this.history.generation + }, + isClean: function (gen) { + return this.history.generation == (gen || this.cleanGeneration) + }, + + getHistory: function() { + return {done: copyHistoryArray(this.history.done), + undone: copyHistoryArray(this.history.undone)} + }, + setHistory: function(histData) { + var hist = this.history = new History(this.history.maxGeneration) + hist.done = copyHistoryArray(histData.done.slice(0), null, true) + hist.undone = copyHistoryArray(histData.undone.slice(0), null, true) + }, + + setGutterMarker: docMethodOp(function(line, gutterID, value) { + return changeLine(this, line, "gutter", function (line) { + var markers = line.gutterMarkers || (line.gutterMarkers = {}) + markers[gutterID] = value + if (!value && isEmpty(markers)) { line.gutterMarkers = null } + return true + }) + }), + + clearGutter: docMethodOp(function(gutterID) { + var this$1 = this; + + this.iter(function (line) { + if (line.gutterMarkers && line.gutterMarkers[gutterID]) { + changeLine(this$1, line, "gutter", function () { + line.gutterMarkers[gutterID] = null + if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null } + return true + }) + } + }) + }), + + lineInfo: function(line) { + var n + if (typeof line == "number") { + if (!isLine(this, line)) { return null } + n = line + line = getLine(this, line) + if (!line) { return null } + } else { + n = lineNo(line) + if (n == null) { return null } + } + return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers, + textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass, + widgets: line.widgets} + }, + + addLineClass: docMethodOp(function(handle, where, cls) { + return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) { + var prop = where == "text" ? "textClass" + : where == "background" ? "bgClass" + : where == "gutter" ? "gutterClass" : "wrapClass" + if (!line[prop]) { line[prop] = cls } + else if (classTest(cls).test(line[prop])) { return false } + else { line[prop] += " " + cls } + return true + }) + }), + removeLineClass: docMethodOp(function(handle, where, cls) { + return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) { + var prop = where == "text" ? "textClass" + : where == "background" ? "bgClass" + : where == "gutter" ? "gutterClass" : "wrapClass" + var cur = line[prop] + if (!cur) { return false } + else if (cls == null) { line[prop] = null } + else { + var found = cur.match(classTest(cls)) + if (!found) { return false } + var end = found.index + found[0].length + line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null + } + return true + }) + }), + + addLineWidget: docMethodOp(function(handle, node, options) { + return addLineWidget(this, handle, node, options) + }), + removeLineWidget: function(widget) { widget.clear() }, + + markText: function(from, to, options) { + return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range") + }, + setBookmark: function(pos, options) { + var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options), + insertLeft: options && options.insertLeft, + clearWhenEmpty: false, shared: options && options.shared, + handleMouseEvents: options && options.handleMouseEvents} + pos = clipPos(this, pos) + return markText(this, pos, pos, realOpts, "bookmark") + }, + findMarksAt: function(pos) { + pos = clipPos(this, pos) + var markers = [], spans = getLine(this, pos.line).markedSpans + if (spans) { for (var i = 0; i < spans.length; ++i) { + var span = spans[i] + if ((span.from == null || span.from <= pos.ch) && + (span.to == null || span.to >= pos.ch)) + { markers.push(span.marker.parent || span.marker) } + } } + return markers + }, + findMarks: function(from, to, filter) { + from = clipPos(this, from); to = clipPos(this, to) + var found = [], lineNo = from.line + this.iter(from.line, to.line + 1, function (line) { + var spans = line.markedSpans + if (spans) { for (var i = 0; i < spans.length; i++) { + var span = spans[i] + if (!(span.to != null && lineNo == from.line && from.ch >= span.to || + span.from == null && lineNo != from.line || + span.from != null && lineNo == to.line && span.from >= to.ch) && + (!filter || filter(span.marker))) + { found.push(span.marker.parent || span.marker) } + } } + ++lineNo + }) + return found + }, + getAllMarks: function() { + var markers = [] + this.iter(function (line) { + var sps = line.markedSpans + if (sps) { for (var i = 0; i < sps.length; ++i) + { if (sps[i].from != null) { markers.push(sps[i].marker) } } } + }) + return markers + }, + + posFromIndex: function(off) { + var ch, lineNo = this.first, sepSize = this.lineSeparator().length + this.iter(function (line) { + var sz = line.text.length + sepSize + if (sz > off) { ch = off; return true } + off -= sz + ++lineNo + }) + return clipPos(this, Pos(lineNo, ch)) + }, + indexFromPos: function (coords) { + coords = clipPos(this, coords) + var index = coords.ch + if (coords.line < this.first || coords.ch < 0) { return 0 } + var sepSize = this.lineSeparator().length + this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value + index += line.text.length + sepSize + }) + return index + }, + + copy: function(copyHistory) { + var doc = new Doc(getLines(this, this.first, this.first + this.size), + this.modeOption, this.first, this.lineSep, this.direction) + doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft + doc.sel = this.sel + doc.extend = false + if (copyHistory) { + doc.history.undoDepth = this.history.undoDepth + doc.setHistory(this.getHistory()) + } + return doc + }, + + linkedDoc: function(options) { + if (!options) { options = {} } + var from = this.first, to = this.first + this.size + if (options.from != null && options.from > from) { from = options.from } + if (options.to != null && options.to < to) { to = options.to } + var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction) + if (options.sharedHist) { copy.history = this.history + ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist}) + copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}] + copySharedMarkers(copy, findSharedMarkers(this)) + return copy + }, + unlinkDoc: function(other) { + var this$1 = this; + + if (other instanceof CodeMirror) { other = other.doc } + if (this.linked) { for (var i = 0; i < this.linked.length; ++i) { + var link = this$1.linked[i] + if (link.doc != other) { continue } + this$1.linked.splice(i, 1) + other.unlinkDoc(this$1) + detachSharedMarkers(findSharedMarkers(this$1)) + break + } } + // If the histories were shared, split them again + if (other.history == this.history) { + var splitIds = [other.id] + linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true) + other.history = new History(null) + other.history.done = copyHistoryArray(this.history.done, splitIds) + other.history.undone = copyHistoryArray(this.history.undone, splitIds) + } + }, + iterLinkedDocs: function(f) {linkedDocs(this, f)}, + + getMode: function() {return this.mode}, + getEditor: function() {return this.cm}, + + splitLines: function(str) { + if (this.lineSep) { return str.split(this.lineSep) } + return splitLinesAuto(str) + }, + lineSeparator: function() { return this.lineSep || "\n" }, + + setDirection: docMethodOp(function (dir) { + if (dir != "rtl") { dir = "ltr" } + if (dir == this.direction) { return } + this.direction = dir + this.iter(function (line) { return line.order = null; }) + if (this.cm) { directionChanged(this.cm) } + }) + }) + +// Public alias. + Doc.prototype.eachLine = Doc.prototype.iter + +// Kludge to work around strange IE behavior where it'll sometimes +// re-fire a series of drag-related events right after the drop (#1551) + var lastDrop = 0 + + function onDrop(e) { + var cm = this + clearDragCursor(cm) + if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) + { return } + e_preventDefault(e) + if (ie) { lastDrop = +new Date } + var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files + if (!pos || cm.isReadOnly()) { return } + // Might be a file drop, in which case we simply extract the text + // and insert it. + if (files && files.length && window.FileReader && window.File) { + var n = files.length, text = Array(n), read = 0 + var loadFile = function (file, i) { + if (cm.options.allowDropFileTypes && + indexOf(cm.options.allowDropFileTypes, file.type) == -1) + { return } + + var reader = new FileReader + reader.onload = operation(cm, function () { + var content = reader.result + if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { content = "" } + text[i] = content + if (++read == n) { + pos = clipPos(cm.doc, pos) + var change = {from: pos, to: pos, + text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())), + origin: "paste"} + makeChange(cm.doc, change) + setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change))) + } + }) + reader.readAsText(file) + } + for (var i = 0; i < n; ++i) { loadFile(files[i], i) } + } else { // Normal drop + // Don't do a replace if the drop happened inside of the selected text. + if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) { + cm.state.draggingText(e) + // Ensure the editor is re-focused + setTimeout(function () { return cm.display.input.focus(); }, 20) + return + } + try { + var text$1 = e.dataTransfer.getData("Text") + if (text$1) { + var selected + if (cm.state.draggingText && !cm.state.draggingText.copy) + { selected = cm.listSelections() } + setSelectionNoUndo(cm.doc, simpleSelection(pos, pos)) + if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1) + { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag") } } + cm.replaceSelection(text$1, "around", "paste") + cm.display.input.focus() + } + } + catch(e){} + } + } + + function onDragStart(cm, e) { + if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return } + if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return } + + e.dataTransfer.setData("Text", cm.getSelection()) + e.dataTransfer.effectAllowed = "copyMove" + + // Use dummy image instead of default browsers image. + // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there. + if (e.dataTransfer.setDragImage && !safari) { + var img = elt("img", null, null, "position: fixed; left: 0; top: 0;") + img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" + if (presto) { + img.width = img.height = 1 + cm.display.wrapper.appendChild(img) + // Force a relayout, or Opera won't use our image for some obscure reason + img._top = img.offsetTop + } + e.dataTransfer.setDragImage(img, 0, 0) + if (presto) { img.parentNode.removeChild(img) } + } + } + + function onDragOver(cm, e) { + var pos = posFromMouse(cm, e) + if (!pos) { return } + var frag = document.createDocumentFragment() + drawSelectionCursor(cm, pos, frag) + if (!cm.display.dragCursor) { + cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors") + cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv) + } + removeChildrenAndAdd(cm.display.dragCursor, frag) + } + + function clearDragCursor(cm) { + if (cm.display.dragCursor) { + cm.display.lineSpace.removeChild(cm.display.dragCursor) + cm.display.dragCursor = null + } + } + +// These must be handled carefully, because naively registering a +// handler for each editor will cause the editors to never be +// garbage collected. + + function forEachCodeMirror(f) { + if (!document.getElementsByClassName) { return } + var byClass = document.getElementsByClassName("CodeMirror") + for (var i = 0; i < byClass.length; i++) { + var cm = byClass[i].CodeMirror + if (cm) { f(cm) } + } + } + + var globalsRegistered = false + function ensureGlobalHandlers() { + if (globalsRegistered) { return } + registerGlobalHandlers() + globalsRegistered = true + } + function registerGlobalHandlers() { + // When the window resizes, we need to refresh active editors. + var resizeTimer + on(window, "resize", function () { + if (resizeTimer == null) { resizeTimer = setTimeout(function () { + resizeTimer = null + forEachCodeMirror(onResize) + }, 100) } + }) + // When the window loses focus, we want to show the editor as blurred + on(window, "blur", function () { return forEachCodeMirror(onBlur); }) + } +// Called when the window resizes + function onResize(cm) { + var d = cm.display + if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth) + { return } + // Might be a text scaling operation, clear size caches. + d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null + d.scrollbarsClipped = false + cm.setSize() + } + + var keyNames = { + 3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt", + 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", + 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert", + 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod", + 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete", + 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", + 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete", + 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert" + } + +// Number keys + for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i) } +// Alphabetic keys + for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1) } +// Function keys + for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2 } + + var keyMap = {} + + keyMap.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" + } +// Note that the save and find-related commands aren't defined by +// default. User code or addons can define them. Unknown commands +// are simply ignored. + keyMap.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" + } +// Very basic readline/emacs-style bindings, which are standard on Mac. + keyMap.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" + } + keyMap.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"] + } + keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault + +// KEYMAP DISPATCH + + function normalizeKeyName(name) { + var parts = name.split(/-(?!$)/) + name = parts[parts.length - 1] + var alt, ctrl, shift, cmd + for (var i = 0; i < parts.length - 1; i++) { + var mod = parts[i] + if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true } + else if (/^a(lt)?$/i.test(mod)) { alt = true } + else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true } + else if (/^s(hift)?$/i.test(mod)) { shift = true } + else { throw new Error("Unrecognized modifier name: " + mod) } + } + if (alt) { name = "Alt-" + name } + if (ctrl) { name = "Ctrl-" + name } + if (cmd) { name = "Cmd-" + name } + if (shift) { name = "Shift-" + name } + return name + } + +// This is a kludge to keep keymaps mostly working as raw objects +// (backwards compatibility) while at the same time support features +// like normalization and multi-stroke key bindings. It compiles a +// new normalized keymap, and then updates the old object to reflect +// this. + function normalizeKeyMap(keymap) { + var copy = {} + for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) { + var value = keymap[keyname] + if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue } + if (value == "...") { delete keymap[keyname]; continue } + + var keys = map(keyname.split(" "), normalizeKeyName) + for (var i = 0; i < keys.length; i++) { + var val = (void 0), name = (void 0) + if (i == keys.length - 1) { + name = keys.join(" ") + val = value + } else { + name = keys.slice(0, i + 1).join(" ") + val = "..." + } + var prev = copy[name] + if (!prev) { copy[name] = val } + else if (prev != val) { throw new Error("Inconsistent bindings for " + name) } + } + delete keymap[keyname] + } } + for (var prop in copy) { keymap[prop] = copy[prop] } + return keymap + } + + function lookupKey(key, map, handle, context) { + map = getKeyMap(map) + var found = map.call ? map.call(key, context) : map[key] + if (found === false) { return "nothing" } + if (found === "...") { return "multi" } + if (found != null && handle(found)) { return "handled" } + + if (map.fallthrough) { + if (Object.prototype.toString.call(map.fallthrough) != "[object Array]") + { return lookupKey(key, map.fallthrough, handle, context) } + for (var i = 0; i < map.fallthrough.length; i++) { + var result = lookupKey(key, map.fallthrough[i], handle, context) + if (result) { return result } + } + } + } + +// Modifier key presses don't count as 'real' key presses for the +// purpose of keymap fallthrough. + function isModifierKey(value) { + var name = typeof value == "string" ? value : keyNames[value.keyCode] + return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod" + } + + function addModifierNames(name, event, noShift) { + var base = name + if (event.altKey && base != "Alt") { name = "Alt-" + name } + if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name } + if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name } + if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name } + return name + } + +// Look up the name of a key as indicated by an event object. + function keyName(event, noShift) { + if (presto && event.keyCode == 34 && event["char"]) { return false } + var name = keyNames[event.keyCode] + if (name == null || event.altGraphKey) { return false } + return addModifierNames(name, event, noShift) + } + + function getKeyMap(val) { + return typeof val == "string" ? keyMap[val] : val + } + +// Helper for deleting text near the selection(s), used to implement +// backspace, delete, and similar functionality. + function deleteNearSelection(cm, compute) { + var ranges = cm.doc.sel.ranges, kill = [] + // Build up a set of ranges to kill first, merging overlapping + // ranges. + for (var i = 0; i < ranges.length; i++) { + var toKill = compute(ranges[i]) + while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) { + var replaced = kill.pop() + if (cmp(replaced.from, toKill.from) < 0) { + toKill.from = replaced.from + break + } + } + kill.push(toKill) + } + // Next, remove those actual ranges. + runInOp(cm, function () { + for (var i = kill.length - 1; i >= 0; i--) + { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete") } + ensureCursorVisible(cm) + }) + } + + function moveCharLogically(line, ch, dir) { + var target = skipExtendingChars(line.text, ch + dir, dir) + return target < 0 || target > line.text.length ? null : target + } + + function moveLogically(line, start, dir) { + var ch = moveCharLogically(line, start.ch, dir) + return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before") + } + + function endOfLine(visually, cm, lineObj, lineNo, dir) { + if (visually) { + var order = getOrder(lineObj, cm.doc.direction) + if (order) { + var part = dir < 0 ? lst(order) : order[0] + var moveInStorageOrder = (dir < 0) == (part.level == 1) + var sticky = moveInStorageOrder ? "after" : "before" + var ch + // With a wrapped rtl chunk (possibly spanning multiple bidi parts), + // it could be that the last bidi part is not on the last visual line, + // since visual lines contain content order-consecutive chunks. + // Thus, in rtl, we are looking for the first (content-order) character + // in the rtl chunk that is on the last line (that is, the same line + // as the last (content-order) character). + if (part.level > 0 || cm.doc.direction == "rtl") { + var prep = prepareMeasureForLine(cm, lineObj) + ch = dir < 0 ? lineObj.text.length - 1 : 0 + var targetTop = measureCharPrepared(cm, prep, ch).top + ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch) + if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1) } + } else { ch = dir < 0 ? part.to : part.from } + return new Pos(lineNo, ch, sticky) + } + } + return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after") + } + + function moveVisually(cm, line, start, dir) { + var bidi = getOrder(line, cm.doc.direction) + if (!bidi) { return moveLogically(line, start, dir) } + if (start.ch >= line.text.length) { + start.ch = line.text.length + start.sticky = "before" + } else if (start.ch <= 0) { + start.ch = 0 + start.sticky = "after" + } + var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos] + if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) { + // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines, + // nothing interesting happens. +