UNPKG

@uiw/react-codemirror

Version:
2 lines 142 kB
/*! For license information please see mdeditor.min.js.LICENSE.txt */ !function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t(require("react"),require("@codemirror/state"),require("@codemirror/theme-one-dark"),require("@codemirror/view")):"function"===typeof define&&define.amd?define(["react",,,],t):"object"===typeof exports?exports["@uiw/codemirror"]=t(require("react"),require("@codemirror/state"),require("@codemirror/theme-one-dark"),require("@codemirror/view")):e["@uiw/codemirror"]=t(e.React,e.CM["@codemirror/state"],e.CM["@codemirror/theme-one-dark"],e.CM["@codemirror/view"])}(self,((e,t,n,i)=>(()=>{"use strict";var r={298:(e,t,n)=>{var i=n(787),r=Symbol.for("react.element"),o=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,l=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var i,o={},c=null,h=null;for(i in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(h=t.ref),t)s.call(t,i)&&!a.hasOwnProperty(i)&&(o[i]=t[i]);if(e&&e.defaultProps)for(i in t=e.defaultProps)void 0===o[i]&&(o[i]=t[i]);return{$$typeof:r,type:e,key:c,ref:h,props:o,_owner:l.current}}t.jsx=c},605:(e,t,n)=>{e.exports=n(298)},787:t=>{t.exports=e},242:e=>{e.exports=t},362:e=>{e.exports=n},105:e=>{e.exports=i}},o={};function s(e){var t=o[e];if(void 0!==t)return t.exports;var n=o[e]={exports:{}};return r[e](n,n.exports,s),n.exports}s.d=(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};return(()=>{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t){var n=function(t,n){if("object"!==e(t)||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,n||"default");if("object"!==e(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"===e(n)?n:String(n)}function n(e,n,i){return(n=t(n))in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function r(e,t){if(null==e)return{};var n,i,r=function(e,t){if(null==e)return{};var n,i,r={},o=Object.keys(e);for(i=0;i<o.length;i++)n=o[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i<o.length;i++)n=o[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}s.r(l),s.d(l,{basicSetup:()=>_o,default:()=>$o,getStatistics:()=>Vo,minimalSetup:()=>Fo,useCodeMirror:()=>jo});var o=s(787);function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function c(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var i,r,o,s,l=[],a=!0,c=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;a=!1}else for(;!(a=(i=o.call(n)).done)&&(l.push(i.value),l.length!==t);a=!0);}catch(h){c=!0,r=h}finally{try{if(!a&&null!=n.return&&(s=n.return(),Object(s)!==s))return}finally{if(c)throw r}}return l}}(e,t)||function(e,t){if(e){if("string"===typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var h=s(242),u=s(105);const f=1024;let d=0;class p{constructor(e,t){this.from=e,this.to=t}}class m{constructor(e={}){this.id=d++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof e&&(e=y.match(e)),t=>{let n=e(t);return void 0===n?null:[this,n]}}}m.closedBy=new m({deserialize:e=>e.split(" ")}),m.openedBy=new m({deserialize:e=>e.split(" ")}),m.group=new m({deserialize:e=>e.split(" ")}),m.contextHash=new m({perNode:!0}),m.lookAhead=new m({perNode:!0}),m.mounted=new m({perNode:!0});const g=Object.create(null);class y{constructor(e,t,n,i=0){this.name=e,this.props=t,this.id=n,this.flags=i}static define(e){let t=e.props&&e.props.length?Object.create(null):g,n=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(null==e.name?8:0),i=new y(e.name||"",t,e.id,n);if(e.props)for(let r of e.props)if(Array.isArray(r)||(r=r(i)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}return i}prop(e){return this.props[e.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(e){if("string"==typeof e){if(this.name==e)return!0;let t=this.prop(m.group);return!!t&&t.indexOf(e)>-1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let i of n.split(" "))t[i]=e[n];return e=>{for(let n=e.prop(m.group),i=-1;i<(n?n.length:0);i++){let r=t[i<0?e.name:n[i]];if(r)return r}}}}y.none=new y("",Object.create(null),0,8);const v=new WeakMap,b=new WeakMap;var w;!function(e){e[e.ExcludeBuffers=1]="ExcludeBuffers",e[e.IncludeAnonymous=2]="IncludeAnonymous",e[e.IgnoreMounts=4]="IgnoreMounts",e[e.IgnoreOverlays=8]="IgnoreOverlays"}(w||(w={}));class x{constructor(e,t,n,i,r){if(this.type=e,this.children=t,this.positions=n,this.length=i,this.props=null,r&&r.length){this.props=Object.create(null);for(let[e,t]of r)this.props["number"==typeof e?e:e.id]=t}}toString(){let e=this.prop(m.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let n of this.children){let e=n.toString();e&&(t&&(t+=","),t+=e)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new B(this.topNode,e)}cursorAt(e,t=0,n=0){let i=v.get(this)||this.topNode,r=new B(i);return r.moveTo(e,t),v.set(this,r._tree),r}get topNode(){return new O(this,0,0,null)}resolve(e,t=0){let n=E(v.get(this)||this.topNode,e,t,!1);return v.set(this,n),n}resolveInner(e,t=0){let n=E(b.get(this)||this.topNode,e,t,!0);return b.set(this,n),n}iterate(e){let{enter:t,leave:n,from:i=0,to:r=this.length}=e;for(let o=this.cursor((e.mode||0)|w.IncludeAnonymous);;){let e=!1;if(o.from<=r&&o.to>=i&&(o.type.isAnonymous||!1!==t(o))){if(o.firstChild())continue;e=!0}for(;e&&n&&!o.type.isAnonymous&&n(o),!o.nextSibling();){if(!o.parent())return;e=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:L(y.none,this.children,this.positions,0,this.children.length,0,this.length,((e,t,n)=>new x(this.type,e,t,n,this.propValues)),e.makeTree||((e,t,n)=>new x(y.none,e,t,n)))}static build(e){return function(e){var t;let{buffer:n,nodeSet:i,maxBufferLength:r=f,reused:o=[],minRepeatType:s=i.types.length}=e,l=Array.isArray(n)?new k(n,n.length):n,a=i.types,c=0,h=0;function u(e,t,n,f,m){let{id:b,start:w,end:x,size:k}=l,C=h;for(;k<0;){if(l.next(),-1==k){let t=o[b];return n.push(t),void f.push(w-e)}if(-3==k)return void(c=b);if(-4==k)return void(h=b);throw new RangeError(`Unrecognized record size: ${k}`)}let A,E,O=a[b],M=w-e;if(x-w<=r&&(E=y(l.pos-t,m))){let t=new Uint16Array(E.size-E.skip),n=l.pos-E.size,r=t.length;for(;l.pos>n;)r=v(E.start,t,r);A=new S(t,x-E.start,i),M=E.start-e}else{let e=l.pos-k;l.next();let t=[],n=[],i=b>=s?b:-1,o=0,a=x;for(;l.pos>e;)i>=0&&l.id==i&&l.size>=0?(l.end<=a-r&&(p(t,n,w,o,l.end,a,i,C),o=t.length,a=l.end),l.next()):u(w,e,t,n,i);if(i>=0&&o>0&&o<t.length&&p(t,n,w,o,w,a,i,C),t.reverse(),n.reverse(),i>-1&&o>0){let e=d(O);A=L(O,t,n,0,t.length,0,x-w,e,e)}else A=g(O,t,n,x-w,C-x)}n.push(A),f.push(M)}function d(e){return(t,n,i)=>{let r,o,s=0,l=t.length-1;if(l>=0&&(r=t[l])instanceof x){if(!l&&r.type==e&&r.length==i)return r;(o=r.prop(m.lookAhead))&&(s=n[l]+r.length+o)}return g(e,t,n,i,s)}}function p(e,t,n,r,o,s,l,a){let c=[],h=[];for(;e.length>r;)c.push(e.pop()),h.push(t.pop()+n-o);e.push(g(i.types[l],c,h,s-o,a-s)),t.push(o-n)}function g(e,t,n,i,r=0,o){if(c){let e=[m.contextHash,c];o=o?[e].concat(o):[e]}if(r>25){let e=[m.lookAhead,r];o=o?[e].concat(o):[e]}return new x(e,t,n,i,o)}function y(e,t){let n=l.fork(),i=0,o=0,a=0,c=n.end-r,h={size:0,start:0,skip:0};e:for(let r=n.pos-e;n.pos>r;){let e=n.size;if(n.id==t&&e>=0){h.size=i,h.start=o,h.skip=a,a+=4,i+=4,n.next();continue}let l=n.pos-e;if(e<0||l<r||n.start<c)break;let u=n.id>=s?4:0,f=n.start;for(n.next();n.pos>l;){if(n.size<0){if(-3!=n.size)break e;u+=4}else n.id>=s&&(u+=4);n.next()}o=f,i+=e,a+=u}return(t<0||i==e)&&(h.size=i,h.start=o,h.skip=a),h.size>4?h:void 0}function v(e,t,n){let{id:i,start:r,end:o,size:a}=l;if(l.next(),a>=0&&i<s){let s=n;if(a>4){let i=l.pos-(a-4);for(;l.pos>i;)n=v(e,t,n)}t[--n]=s,t[--n]=o-e,t[--n]=r-e,t[--n]=i}else-3==a?c=i:-4==a&&(h=i);return n}let b=[],w=[];for(;l.pos>0;)u(e.start||0,e.bufferStart||0,b,w,-1);let C=null!==(t=e.length)&&void 0!==t?t:b.length?w[0]+b[0].length:0;return new x(a[e.topID],b.reverse(),w.reverse(),C)}(e)}}x.empty=new x(y.none,[],[],0);class k{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new k(this.buffer,this.index)}}class S{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return y.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],n=this.buffer[e+3],i=this.set.types[t],r=i.name;if(/\W/.test(r)&&!i.isError&&(r=JSON.stringify(r)),n==(e+=4))return r;let o=[];for(;e<n;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,n,i,r){let{buffer:o}=this,s=-1;for(let l=e;l!=t&&!(C(r,i,o[l+1],o[l+2])&&(s=l,n>0));l=o[l+3]);return s}slice(e,t,n){let i=this.buffer,r=new Uint16Array(t-e),o=0;for(let s=e,l=0;s<t;){r[l++]=i[s++],r[l++]=i[s++]-n;let t=r[l++]=i[s++]-n;r[l++]=i[s++]-e,o=Math.max(o,t)}return new S(r,o,this.set)}}function C(e,t,n,i){switch(e){case-2:return n<t;case-1:return i>=t&&n<t;case 0:return n<t&&i>t;case 1:return n<=t&&i>t;case 2:return i>t;case 4:return!0}}function A(e,t){let n=e.childBefore(t);for(;n;){let t=n.lastChild;if(!t||t.to!=n.to)break;t.type.isError&&t.from==t.to?(e=n,n=t.prevSibling):n=t}return e}function E(e,t,n,i){for(var r;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let t=!i&&e instanceof O&&e.index<0?null:e.parent;if(!t)return e;e=t}let o=i?0:w.IgnoreOverlays;if(i)for(let s=e,l=s.parent;l;s=l,l=s.parent)s instanceof O&&s.index<0&&(null===(r=l.enter(t,n,o))||void 0===r?void 0:r.from)!=s.from&&(e=l);for(;;){let i=e.enter(t,n,o);if(!i)return e;e=i}}class O{constructor(e,t,n,i){this._tree=e,this.from=t,this.index=n,this._parent=i}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,n,i,r=0){for(let o=this;;){for(let{children:s,positions:l}=o._tree,a=t>0?s.length:-1;e!=a;e+=t){let a=s[e],c=l[e]+o.from;if(C(i,n,c,c+a.length))if(a instanceof S){if(r&w.ExcludeBuffers)continue;let s=a.findChild(0,a.buffer.length,t,n-c,i);if(s>-1)return new I(new P(o,a,e,c),null,s)}else if(r&w.IncludeAnonymous||!a.type.isAnonymous||T(a)){let s;if(!(r&w.IgnoreMounts)&&a.props&&(s=a.prop(m.mounted))&&!s.overlay)return new O(s.tree,c,e,o);let l=new O(a,c,e,o);return r&w.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(t<0?a.children.length-1:0,t,n,i)}}if(r&w.IncludeAnonymous||!o.type.isAnonymous)return null;if(e=o.index>=0?o.index+t:t<0?-1:o._parent._tree.children.length,o=o._parent,!o)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,n=0){let i;if(!(n&w.IgnoreOverlays)&&(i=this._tree.prop(m.mounted))&&i.overlay){let n=e-this.from;for(let{from:e,to:r}of i.overlay)if((t>0?e<=n:e<n)&&(t<0?r>=n:r>n))return new O(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,n)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(e=0){return new B(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return E(this,e,t,!1)}resolveInner(e,t=0){return E(this,e,t,!0)}enterUnfinishedNodesBefore(e){return A(this,e)}getChild(e,t=null,n=null){let i=M(this,e,t,n);return i.length?i[0]:null}getChildren(e,t=null,n=null){return M(this,e,t,n)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return D(this,e)}}function M(e,t,n,i){let r=e.cursor(),o=[];if(!r.firstChild())return o;if(null!=n)for(;!r.type.is(n);)if(!r.nextSibling())return o;for(;;){if(null!=i&&r.type.is(i))return o;if(r.type.is(t)&&o.push(r.node),!r.nextSibling())return null==i?o:[]}}function D(e,t,n=t.length-1){for(let i=e.parent;n>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(t[n]&&t[n]!=i.name)return!1;n--}}return!0}class P{constructor(e,t,n,i){this.parent=e,this.buffer=t,this.index=n,this.start=i}}class I{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(e,t,n){let{buffer:i}=this.context,r=i.findChild(this.index+4,i.buffer[this.index+3],e,t-this.context.start,n);return r<0?null:new I(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,n=0){if(n&w.ExcludeBuffers)return null;let{buffer:i}=this.context,r=i.findChild(this.index+4,i.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new I(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new I(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new I(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new B(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,i=this.index+4,r=n.buffer[this.index+3];if(r>i){let o=n.buffer[this.index+1];e.push(n.slice(i,r,o)),t.push(0)}return new x(this.type,e,t,this.to-this.from)}resolve(e,t=0){return E(this,e,t,!1)}resolveInner(e,t=0){return E(this,e,t,!0)}enterUnfinishedNodesBefore(e){return A(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,n=null){let i=M(this,e,t,n);return i.length?i[0]:null}getChildren(e,t=null,n=null){return M(this,e,t,n)}get node(){return this}matchContext(e){return D(this,e)}}class B{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof O)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return!!e&&(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0)}yieldBuf(e,t){this.index=e;let{start:n,buffer:i}=this.buffer;return this.type=t||i.set.types[i.buffer[e]],this.from=n+i.buffer[e+1],this.to=n+i.buffer[e+2],!0}yield(e){return!!e&&(e instanceof O?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:i}=this.buffer,r=i.findChild(this.index+4,i.buffer[this.index+3],e,t-this.buffer.start,n);return!(r<0)&&(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?!(n&w.ExcludeBuffers)&&this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&w.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&w.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode));let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let e=n<0?0:this.stack[n]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(e)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:i}=this;if(i){if(e>0){if(this.index<i.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(i.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:n}=i)}else({index:t,_parent:n}=this._tree);for(;n;({index:t,_parent:n}=n))if(t>-1)for(let i=t+e,r=e<0?-1:n._tree.children.length;i!=r;i+=e){let e=n._tree.children[i];if(this.mode&w.IncludeAnonymous||e instanceof S||!e.type.isAnonymous||T(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer)e:for(let i=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==i){if(i==this.index)return o;t=o,n=r+1;break e}i=this.stack[--r]}for(let i=n;i<this.stack.length;i++)t=new I(this.buffer,t,this.stack[i]);return this.bufferNode=new I(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let i=!1;if(this.type.isAnonymous||!1!==e(this)){if(this.firstChild()){n++;continue}this.type.isAnonymous||(i=!0)}for(;i&&t&&t(this),i=this.type.isAnonymous,!this.nextSibling();){if(!n)return;this.parent(),n--,i=!0}}}matchContext(e){if(!this.buffer)return D(this.node,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let i=e.length-1,r=this.stack.length-1;i>=0;r--){if(r<0)return D(this.node,e,i);let o=n[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[i]&&e[i]!=o.name)return!1;i--}}return!0}}function T(e){return e.children.some((e=>e instanceof S||!e.type.isAnonymous||T(e)))}const N=new WeakMap;function R(e,t){if(!e.isAnonymous||t instanceof S||t.type!=e)return 1;let n=N.get(t);if(null==n){n=1;for(let i of t.children){if(i.type!=e||!(i instanceof x)){n=1;break}n+=R(e,i)}N.set(t,n)}return n}function L(e,t,n,i,r,o,s,l,a){let c=0;for(let d=i;d<r;d++)c+=R(e,t[d]);let h=Math.ceil(1.5*c/8),u=[],f=[];return function t(n,i,r,s,l){for(let c=r;c<s;){let r=c,d=i[c],p=R(e,n[c]);for(c++;c<s;c++){let t=R(e,n[c]);if(p+t>=h)break;p+=t}if(c==r+1){if(p>h){let e=n[r];t(e.children,e.positions,0,e.children.length,i[r]+l);continue}u.push(n[r])}else{let t=i[c-1]+n[c-1].length-d;u.push(L(e,n,i,r,c,d,t,null,a))}f.push(d+l-o)}}(t,n,i,r,0),(l||a)(u,f,s)}class _{constructor(e,t,n,i,r=!1,o=!1){this.from=e,this.to=t,this.tree=n,this.offset=i,this.open=(r?1:0)|(o?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(e,t=[],n=!1){let i=[new _(0,e.length,e,0,!1,n)];for(let r of t)r.to>e.length&&i.push(r);return i}static applyChanges(e,t,n=128){if(!t.length)return e;let i=[],r=1,o=e.length?e[0]:null;for(let s=0,l=0,a=0;;s++){let c=s<t.length?t[s]:null,h=c?c.fromA:1e9;if(h-l>=n)for(;o&&o.from<h;){let t=o;if(l>=t.from||h<=t.to||a){let e=Math.max(t.from,l)-a,n=Math.min(t.to,h)-a;t=e>=n?null:new _(e,n,t.tree,t.offset+a,s>0,!!c)}if(t&&i.push(t),o.to>h)break;o=r<e.length?e[r++]:null}if(!c)break;l=c.toA,a=c.toA-c.toB}return i}}class F{startParse(e,t,n){return"string"==typeof e&&(e=new W(e)),n=n?n.length?n.map((e=>new p(e.from,e.to))):[new p(0,0)]:[new p(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let i=this.startParse(e,t,n);for(;;){let e=i.advance();if(e)return e}}}class W{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new m({perNode:!0});let V=0;class j{constructor(e,t,n){this.set=e,this.base=t,this.modified=n,this.id=V++}static define(e){if(null===e||void 0===e?void 0:e.base)throw new Error("Can not derive from a modified tag");let t=new j([],null,[]);if(t.set.push(t),e)for(let n of e.set)t.set.push(n);return t}static defineModifier(){let e=new z;return t=>t.modified.indexOf(e)>-1?t:z.get(t.base||t,t.modified.concat(e).sort(((e,t)=>e.id-t.id)))}}let q=0;class z{constructor(){this.instances=[],this.id=q++}static get(e,t){if(!t.length)return e;let n=t[0].instances.find((n=>{return n.base==e&&(i=t,r=n.modified,i.length==r.length&&i.every(((e,t)=>e==r[t])));var i,r}));if(n)return n;let i=[],r=new j(i,e,t);for(let s of t)s.instances.push(r);let o=function(e){let t=[[]];for(let n=0;n<e.length;n++)for(let i=0,r=t.length;i<r;i++)t.push(t[i].concat(e[n]));return t.sort(((e,t)=>t.length-e.length))}(t);for(let s of e.set)if(!s.modified.length)for(let e of o)i.push(z.get(s,e));return r}}function U(e){let t=Object.create(null);for(let n in e){let i=e[n];Array.isArray(i)||(i=[i]);for(let e of n.split(" "))if(e){let n=[],r=2,o=e;for(let t=0;;){if("..."==o&&t>0&&t+3==e.length){r=1;break}let i=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(o);if(!i)throw new RangeError("Invalid path: "+e);if(n.push("*"==i[0]?"":'"'==i[0][0]?JSON.parse(i[0]):i[0]),t+=i[0].length,t==e.length)break;let s=e[t++];if(t==e.length&&"!"==s){r=0;break}if("/"!=s)throw new RangeError("Invalid path: "+e);o=e.slice(t)}let s=n.length-1,l=n[s];if(!l)throw new RangeError("Invalid path: "+e);let a=new H(i,r,s>0?n.slice(0,s):null);t[l]=a.sort(t[l])}}return $.add(t)}const $=new m;class H{constructor(e,t,n,i){this.tags=e,this.mode=t,this.context=n,this.next=i}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}function J(e,t){let n=Object.create(null);for(let o of e)if(Array.isArray(o.tag))for(let e of o.tag)n[e.id]=o.class;else n[o.tag.id]=o.class;let{scope:i,all:r=null}=t||{};return{style:e=>{let t=r;for(let i of e)for(let e of i.set){let i=n[e.id];if(i){t=t?t+" "+i:i;break}}return t},scope:i}}function G(e,t,n,i=0,r=e.length){let o=new K(i,Array.isArray(t)?t:[t],n);o.highlightRange(e.cursor(),i,r,"",o.highlighters),o.flush(r)}H.empty=new H([],2,null);class K{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,i,r){let{type:o,from:s,to:l}=e;if(s>=n||l<=t)return;o.isTop&&(r=this.highlighters.filter((e=>!e.scope||e.scope(o))));let a=i,c=function(e){let t=e.type.prop($);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}(e)||H.empty,h=function(e,t){let n=null;for(let i of e){let e=i.style(t);e&&(n=n?n+" "+e:e)}return n}(r,c.tags);if(h&&(a&&(a+=" "),a+=h,1==c.mode&&(i+=(i?" ":"")+h)),this.startSpan(e.from,a),c.opaque)return;let u=e.tree&&e.tree.prop(m.mounted);if(u&&u.overlay){let o=e.node.enter(u.overlay[0].from+s,1),c=this.highlighters.filter((e=>!e.scope||e.scope(u.tree.type))),h=e.firstChild();for(let f=0,d=s;;f++){let p=f<u.overlay.length?u.overlay[f]:null,m=p?p.from+s:l,g=Math.max(t,d),y=Math.min(n,m);if(g<y&&h)for(;e.from<y&&(this.highlightRange(e,g,y,i,r),this.startSpan(Math.min(y,e.to),a),!(e.to>=m)&&e.nextSibling()););if(!p||m>n)break;d=p.to+s,d>t&&(this.highlightRange(o.cursor(),Math.max(t,p.from+s),Math.min(n,d),i,c),this.startSpan(d,a))}h&&e.parent()}else if(e.firstChild()){do{if(!(e.to<=t)){if(e.from>=n)break;this.highlightRange(e,t,n,i,r),this.startSpan(Math.min(n,e.to),a)}}while(e.nextSibling());e.parent()}}}const Q=j.define,Y=Q(),X=Q(),Z=Q(X),ee=Q(X),te=Q(),ne=Q(te),ie=Q(te),re=Q(),oe=Q(re),se=Q(),le=Q(),ae=Q(),ce=Q(ae),he=Q(),ue={comment:Y,lineComment:Q(Y),blockComment:Q(Y),docComment:Q(Y),name:X,variableName:Q(X),typeName:Z,tagName:Q(Z),propertyName:ee,attributeName:Q(ee),className:Q(X),labelName:Q(X),namespace:Q(X),macroName:Q(X),literal:te,string:ne,docString:Q(ne),character:Q(ne),attributeValue:Q(ne),number:ie,integer:Q(ie),float:Q(ie),bool:Q(te),regexp:Q(te),escape:Q(te),color:Q(te),url:Q(te),keyword:se,self:Q(se),null:Q(se),atom:Q(se),unit:Q(se),modifier:Q(se),operatorKeyword:Q(se),controlKeyword:Q(se),definitionKeyword:Q(se),moduleKeyword:Q(se),operator:le,derefOperator:Q(le),arithmeticOperator:Q(le),logicOperator:Q(le),bitwiseOperator:Q(le),compareOperator:Q(le),updateOperator:Q(le),definitionOperator:Q(le),typeOperator:Q(le),controlOperator:Q(le),punctuation:ae,separator:Q(ae),bracket:ce,angleBracket:Q(ce),squareBracket:Q(ce),paren:Q(ce),brace:Q(ce),content:re,heading:oe,heading1:Q(oe),heading2:Q(oe),heading3:Q(oe),heading4:Q(oe),heading5:Q(oe),heading6:Q(oe),contentSeparator:Q(re),list:Q(re),quote:Q(re),emphasis:Q(re),strong:Q(re),link:Q(re),monospace:Q(re),strikethrough:Q(re),inserted:Q(),deleted:Q(),changed:Q(),invalid:Q(),meta:he,documentMeta:Q(he),annotation:Q(he),processingInstruction:Q(he),definition:j.defineModifier(),constant:j.defineModifier(),function:j.defineModifier(),standard:j.defineModifier(),local:j.defineModifier(),special:j.defineModifier()},fe=(J([{tag:ue.link,class:"tok-link"},{tag:ue.heading,class:"tok-heading"},{tag:ue.emphasis,class:"tok-emphasis"},{tag:ue.strong,class:"tok-strong"},{tag:ue.keyword,class:"tok-keyword"},{tag:ue.atom,class:"tok-atom"},{tag:ue.bool,class:"tok-bool"},{tag:ue.url,class:"tok-url"},{tag:ue.labelName,class:"tok-labelName"},{tag:ue.inserted,class:"tok-inserted"},{tag:ue.deleted,class:"tok-deleted"},{tag:ue.literal,class:"tok-literal"},{tag:ue.string,class:"tok-string"},{tag:ue.number,class:"tok-number"},{tag:[ue.regexp,ue.escape,ue.special(ue.string)],class:"tok-string2"},{tag:ue.variableName,class:"tok-variableName"},{tag:ue.local(ue.variableName),class:"tok-variableName tok-local"},{tag:ue.definition(ue.variableName),class:"tok-variableName tok-definition"},{tag:ue.special(ue.variableName),class:"tok-variableName2"},{tag:ue.definition(ue.propertyName),class:"tok-propertyName tok-definition"},{tag:ue.typeName,class:"tok-typeName"},{tag:ue.namespace,class:"tok-namespace"},{tag:ue.className,class:"tok-className"},{tag:ue.macroName,class:"tok-macroName"},{tag:ue.propertyName,class:"tok-propertyName"},{tag:ue.operator,class:"tok-operator"},{tag:ue.comment,class:"tok-comment"},{tag:ue.meta,class:"tok-meta"},{tag:ue.invalid,class:"tok-invalid"},{tag:ue.punctuation,class:"tok-punctuation"}]),"undefined"==typeof Symbol?"__\u037c":Symbol.for("\u037c")),de="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),pe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class me{constructor(e,t){this.rules=[];let{finish:n}=t||{};function i(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function r(e,t,o,s){let l=[],a=/^@(\w+)\b/.exec(e[0]),c=a&&"keyframes"==a[1];if(a&&null==t)return o.push(e[0]+";");for(let n in t){let s=t[n];if(/&/.test(n))r(n.split(/,\s*/).map((t=>e.map((e=>t.replace(/&/,e))))).reduce(((e,t)=>e.concat(t))),s,o);else if(s&&"object"==typeof s){if(!a)throw new RangeError("The value of a property ("+n+") should be a primitive value.");r(i(n),s,l,c)}else null!=s&&l.push(n.replace(/_.*/,"").replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))+": "+s+";")}(l.length||c)&&o.push((!n||a||s?e:e.map(n)).join(", ")+" {"+l.join(" ")+"}")}for(let o in e)r(i(o),e[o],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let e=pe[fe]||1;return pe[fe]=e+1,"\u037c"+e.toString(36)}static mount(e,t){(e[de]||new ye(e)).mount(Array.isArray(t)?t:[t])}}let ge=null;class ye{constructor(e){if(!e.head&&e.adoptedStyleSheets&&"undefined"!=typeof CSSStyleSheet){if(ge)return e.adoptedStyleSheets=[ge.sheet].concat(e.adoptedStyleSheets),e[de]=ge;this.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[this.sheet].concat(e.adoptedStyleSheets),ge=this}else{this.styleTag=(e.ownerDocument||e).createElement("style");let t=e.head||e;t.insertBefore(this.styleTag,t.firstChild)}this.modules=[],e[de]=this}mount(e){let t=this.sheet,n=0,i=0;for(let r=0;r<e.length;r++){let o=e[r],s=this.modules.indexOf(o);if(s<i&&s>-1&&(this.modules.splice(s,1),i--,s=-1),-1==s){if(this.modules.splice(i++,0,o),t)for(let e=0;e<o.rules.length;e++)t.insertRule(o.rules[e],n++)}else{for(;i<s;)n+=this.modules[i++].rules.length;n+=o.rules.length,i++}}if(!t){let e="";for(let t=0;t<this.modules.length;t++)e+=this.modules[t].getRules()+"\n";this.styleTag.textContent=e}}}var ve;const be=new m;class we{constructor(e,t,n=[],i=""){this.data=e,this.name=i,h.EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(h.EditorState.prototype,"tree",{get(){return ke(this)}}),this.parser=t,this.extension=[Ie.of(this),h.EditorState.languageData.of(((e,t,n)=>e.facet(xe(e,t,n))))].concat(n)}isActiveAt(e,t,n=-1){return xe(e,t,n)==this.data}findRegions(e){let t=e.facet(Ie);if((null===t||void 0===t?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],i=(e,t)=>{if(e.prop(be)==this.data)return void n.push({from:t,to:t+e.length});let r=e.prop(m.mounted);if(r){if(r.tree.prop(be)==this.data){if(r.overlay)for(let e of r.overlay)n.push({from:e.from+t,to:e.to+t});else n.push({from:t,to:t+e.length});return}if(r.overlay){let e=n.length;if(i(r.tree,r.overlay[0].from+t),n.length>e)return}}for(let n=0;n<e.children.length;n++){let r=e.children[n];r instanceof x&&i(r,e.positions[n]+t)}};return i(ke(e),0),n}get allowsNesting(){return!0}}function xe(e,t,n){let i=e.facet(Ie);if(!i)return null;let r=i.data;if(i.allowsNesting)for(let o=ke(e).topNode;o;o=o.enter(t,n,w.ExcludeBuffers))r=o.type.prop(be)||r;return r}we.setState=h.StateEffect.define();function ke(e){let t=e.field(we.state,!1);return t?t.tree:x.empty}class Se{constructor(e,t=e.length){this.doc=e,this.length=t,this.cursorPos=0,this.string="",this.cursor=e.iter()}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e<n||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}}let Ce=null;class Ae{constructor(e,t,n=[],i,r,o,s,l){this.parser=e,this.state=t,this.fragments=n,this.tree=i,this.treeLen=r,this.viewport=o,this.skipped=s,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new Ae(e,t,[],x.empty,0,n,[],null)}startParse(){return this.parser.startParse(new Se(this.state.doc),this.fragments)}work(e,t){return null!=t&&t>=this.state.doc.length&&(t=void 0),this.tree!=x.empty&&this.isDone(null!==t&&void 0!==t?t:this.state.doc.length)?(this.takeTree(),!0):this.withContext((()=>{var n;if("number"==typeof e){let t=Date.now()+e;e=()=>Date.now()>t}for(this.parse||(this.parse=this.startParse()),null!=t&&(null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let i=this.parse.advance();if(i){if(this.fragments=this.withoutTempSkipped(_.addTree(i,this.fragments,null!=this.parse.stoppedAt)),this.treeLen=null!==(n=this.parse.stoppedAt)&&void 0!==n?n:this.state.doc.length,this.tree=i,this.parse=null,!(this.treeLen<(null!==t&&void 0!==t?t:this.state.doc.length)))return!0;this.parse=this.startParse()}if(e())return!1}}))}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext((()=>{for(;!(t=this.parse.advance()););})),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(_.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Ce;Ce=this;try{return e()}finally{Ce=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Ee(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:i,treeLen:r,viewport:o,skipped:s}=this;if(this.takeTree(),!e.empty){let t=[];if(e.iterChangedRanges(((e,n,i,r)=>t.push({fromA:e,toA:n,fromB:i,toB:r}))),n=_.applyChanges(n,t),i=x.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){s=[];for(let t of this.skipped){let n=e.mapPos(t.from,1),i=e.mapPos(t.to,-1);n<i&&s.push({from:n,to:i})}}}return new Ae(this.parser,t,n,i,r,o,s,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let n=0;n<this.skipped.length;n++){let{from:t,to:i}=this.skipped[n];t<e.to&&i>e.from&&(this.fragments=Ee(this.fragments,t,i),this.skipped.splice(n--,1))}return!(this.skipped.length>=t)&&(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends F{createParse(t,n,i){let r=i[0].from,o=i[i.length-1].to;return{parsedPos:r,advance(){let t=Ce;if(t){for(let e of i)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=o,new x(y.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&0==t[0].from&&t[0].to>=e}static get(){return Ce}}function Ee(e,t,n){return _.applyChanges(e,[{fromA:t,toA:n,fromB:t,toB:n}])}class Oe{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),n=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,n)||t.takeTree(),new Oe(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=Ae.create(e.facet(Ie).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new Oe(n)}}we.state=h.StateField.define({create:Oe.init,update(e,t){for(let n of t.effects)if(n.is(we.setState))return n.value;return t.startState.facet(Ie)!=t.state.facet(Ie)?Oe.init(t.state):e.apply(t)}});let Me=e=>{let t=setTimeout((()=>e()),500);return()=>clearTimeout(t)};"undefined"!=typeof requestIdleCallback&&(Me=e=>{let t=-1,n=setTimeout((()=>{t=requestIdleCallback(e,{timeout:400})}),100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)});const De="undefined"!=typeof navigator&&(null===(ve=navigator.scheduling)||void 0===ve?void 0:ve.isInputPending)?()=>navigator.scheduling.isInputPending():null,Pe=u.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(we.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(we.state);t.tree==t.context.tree&&t.context.isDone(e.doc.length)||(this.working=Me(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:n,viewport:{to:i}}=this.view,r=n.field(we.state);if(r.tree==r.context.tree&&r.context.isDone(i+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!De?Math.max(25,e.timeRemaining()-5):1e9),s=r.context.treeLen<i&&n.doc.length>i+1e3,l=r.context.work((()=>De&&De()||Date.now()>o),i+(s?0:1e5));this.chunkBudget-=Date.now()-t,(l||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:we.setState.of(new Oe(r.context))})),this.chunkBudget>0&&(!l||s)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then((()=>this.scheduleWork())).catch((e=>(0,u.logException)(this.view.state,e))).then((()=>this.workScheduled--)),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ie=h.Facet.define({combine:e=>e.length?e[0]:null,enables:e=>[we.state,Pe,u.EditorView.contentAttributes.compute([e],(t=>{let n=t.facet(e);return n&&n.name?{"data-language":n.name}:{}}))]});const Be=h.Facet.define(),Te=h.Facet.define({combine:e=>{if(!e.length)return" ";if(!/^(?: +|\t+)$/.test(e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(e[0]));return e[0]}});function Ne(e){let t=e.facet(Te);return 9==t.charCodeAt(0)?e.tabSize*t.length:t.length}function Re(e,t){let n="",i=e.tabSize;if(9==e.facet(Te).charCodeAt(0))for(;t>=i;)n+="\t",t-=i;for(let r=0;r<t;r++)n+=" ";return n}function Le(e,t){e instanceof h.EditorState&&(e=new _e(e));for(let i of e.state.facet(Be)){let n=i(e,t);if(void 0!==n)return n}let n=ke(e.state);return n?function(e,t,n){return Ve(t.resolveInner(n).enterUnfinishedNodesBefore(n),n,e)}(e,n,t):null}class _e{constructor(e,t={}){this.state=e,this.options=t,this.unit=Ne(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:i,simulateDoubleBreak:r}=this.options;return null!=i&&i>=n.from&&i<=n.to?r&&i==e?{text:"",from:e}:(t<0?i<e:i<=e)?{text:n.text.slice(i-n.from),from:i}:{text:n.text.slice(0,i-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:n,from:i}=this.lineAt(e,t);return n.slice(e-i,Math.min(n.length,e+100-i))}column(e,t=1){let{text:n,from:i}=this.lineAt(e,t),r=this.countColumn(n,e-i),o=this.options.overrideIndentation?this.options.overrideIndentation(i):-1;return o>-1&&(r+=o-this.countColumn(n,n.search(/\S|$/))),r}countColumn(e,t=e.length){return(0,h.countColumn)(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:i}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let e=r(i);if(e>-1)return e}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Fe=new m;function We(e){let t=e.type.prop(Fe);if(t)return t;let n,i=e.firstChild;if(i&&(n=i.type.prop(m.closedBy))){let t=e.lastChild,i=t&&n.indexOf(t.name)>-1;return e=>Ue(e,!0,1,void 0,i&&!function(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}(e)?t.from:void 0)}return null==e.parent?je:null}function Ve(e,t,n){for(;e;e=e.parent){let i=We(e);if(i)return i(qe.create(n,t,e))}return null}function je(){return 0}class qe extends _e{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.node=n}static create(e,t,n){return new qe(e,t,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let e=this.state.doc.lineAt(this.node.from);for(;;){let t=this.node.resolve(e.from);for(;t.parent&&t.parent.from==t.from;)t=t.parent;if(ze(t,this.node))break;e=this.state.doc.lineAt(t.from)}return this.lineIndent(e.from)}continue(){let e=this.node.parent;return e?Ve(e,this.pos,this.base):0}}function ze(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function Ue(e,t,n,i,r){let o=e.textAfter,s=o.match(/^\s*/)[0].length,l=i&&o.slice(s,s+i.length)==i||r==e.pos+s,a=t?function(e){let t=e.node,n=t.childAfter(t.from),i=t.lastChild;if(!n)return null;let r=e.options.simulateBreak,o=e.state.doc.lineAt(n.from),s=null==r||r<=o.from?o.to:Math.min(o.to,r);for(let l=n.to;;){let e=t.childAfter(l);if(!e||e==i)return null;if(!e.type.isSkipped)return e.from<s?n:null;l=e.to}}(e):null;return a?l?e.column(a.from):e.column(a.to):e.baseIndent+(l?0:e.unit*n)}const $e=h.Facet.define(),He=new m;function Je(e){let t=e.lastChild;return t&&t.to==e.to&&t.type.isError}function Ge(e,t,n){for(let i of e.facet($e)){let r=i(e,t,n);if(r)return r}return function(e,t,n){let i=ke(e);if(i.length<n)return null;let r=null;for(let o=i.resolveInner(n,1);o;o=o.parent){if(o.to<=n||o.from>n)continue;if(r&&o.from<t)break;let s=o.type.prop(He);if(s&&(o.to<i.length-50||i.length==e.doc.length||!Je(o))){let i=s(o,e);i&&i.from<=n&&i.from>=t&&i.to>n&&(r=i)}}return r}(e,t,n)}function Ke(e,t){let n=t.mapPos(e.from,1),i=t.mapPos(e.to,-1);return n>=i?void 0:{from:n,to:i}}const Qe=h.StateEffect.define({map:Ke}),Ye=h.StateEffect.define({map:Ke});function Xe(e){let t=[];for(let{head:n}of e.state.selection.ranges)t.some((e=>e.from<=n&&e.to>=n))||t.push(e.lineBlockAt(n));return t}const Ze=h.StateField.define({create:()=>u.Decoration.none,update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(Qe)&&!tt(e,n.value.from,n.value.to)?e=e.update({add:[at.range(n.value.from,n.value.to)]}):n.is(Ye)&&(e=e.update({filter:(e,t)=>n.value.from!=e||n.value.to!=t,filterFrom:n.value.from,filterTo:n.value.to}));if(t.selection){let n=!1,{head:i}=t.selection.main;e.between(i,i,((e,t)=>{e<i&&t>i&&(n=!0)})),n&&(e=e.update({filterFrom:i,filterTo:i,filter:(e,t)=>t<=i||e>=i}))}return e},provide:e=>u.EditorView.decorations.from(e),toJSON(e,t){let n=[];return e.between(0,t.doc.length,((e,t)=>{n.push(e,t)})),n},fromJSON(e){if(!Array.isArray(e)||e.length%2)throw new RangeError("Invalid JSON for fold state");let t=[];for(let n=0;n<e.length;){let i=e[n++],r=e[n++];if("number"!=typeof i||"number"!=typeof r)throw new RangeError("Invalid JSON for fold state");t.push(at.range(i,r))}return u.Decoration.set(t,!0)}});function et(e,t,n){var i;let r=null;return null===(i=e.field(Ze,!1))||void 0===i||i.between(t,n,((e,t)=>{(!r||r.from>e)&&(r={from:e,to:t})})),r}function tt(e,t,n){let i=!1;return e.between(t,t,((e,r)=>{e==t&&r==n&&(i=!0)})),i}function nt(e,t){return e.field(Ze,!1)?t:t.concat(h.StateEffect.appendConfig.of(lt()))}function it(e,t,n=!0){let i=e.state.doc.lineAt(t.from).number,r=e.state.doc.lineAt(t.to).number;return u.EditorView.announce.of(`${e.state.phrase(n?"Folded lines":"Unfolded lines")} ${i} ${e.state.phrase("to")} ${r}.`)}const rt=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:e=>{for(let t of Xe(e)){let n=Ge(e.state,t.from,t.to);if(n)return e.dispatch({effects:nt(e.state,[Qe.of(n),it(e,n)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:e=>{if(!e.state.field(Ze,!1))return!1;let t=[];for(let n of Xe(e)){let i=et(e.state,n.from,n.to);i&&t.push(Ye.of(i),it(e,i,!1))}return t.length&&e.dispatch({effects:t}),t.length>0}},{key:"Ctrl-Alt-[",run:e=>{let{state:t}=e,n=[];for(let i=0;i<t.doc.length;){let r=e.lineBlockAt(i),o=Ge(t,r.from,r.to);o&&n.push(Qe.of(o)),i=(o?e.lineBlockAt(o.to):r).to+1}return n.length&&e.dispatch({effects:nt(e.state,n)}),!!n.length}},{key:"Ctrl-Alt-]",run:e=>{let t=e.state.field(Ze,!1);if(!t||!t.size)return!1;let n=[];return t.between(0,e.state.doc.length,((e,t)=>{n.push(Ye.of({from:e,to:t}))})),e.dispatch({effects:n}),!0}}],ot={placeholderDOM:null,placeholderText:"\u2026"},st=h.Facet.define({combine:e=>(0,h.combineConfig)(e,ot)});function lt(e){let t=[Ze,ut];return e&&t.push(st.of(e)),t}const at=u.Decoration.replace({widget:new class extends u.WidgetType{toDOM(e){let{state:t}=e,n=t.facet(st),i=t=>{let n=e.lineBlockAt(e.posAtDOM(t.target)),i=et(e.state,n.from,n.to);i&&e.dispatch({effects:Ye.of(i)}),t.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(e,i);let r=document.createElement("span");return r.textContent=n.placeholderText,r.setAttribute("aria-label",t.phrase("folded code")),r.title=t.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=i,r}}}),ct={openText:"\u2304",closedText:"\u203a",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class ht extends u.GutterMarker{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}const ut=u.EditorView.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class ft{constructor(e,t){let n;function i(e){let t=me.newName();return(n||(n=Object.create(null)))["."+t]=e,t}this.specs=e;const r="string"==typeof t.all?t.all:t.all?i(t.all):void 0,o=t.scope;this.scope=o instanceof we?e=>e.prop(be)==o.data:o?e=>e==o:void 0,this.style=J(e.map((e=>({tag:e.tag,class:e.class||i(Object.assign({},e,{tag:null}))}))),{all:r}).style,this.module=n?new me(n):null,this.themeType=t.themeType}static define(e,t){return new ft(e,t||{})}}const dt=h.Facet.define(),pt=h.Facet.define({combine:e=>e.length?[e[0]]:null});function mt(e){let t=e.facet(dt);return t.length?t:e.facet(pt)}function gt(e,t){let n,i=[vt];return e instanceof ft&&(e.module&&i.push(u.EditorView.styleModule.of(e.module)),n=e.themeType),(null===t||void 0===t?void 0:t.fallback)?i.push(pt.of(e)):n?i.push(dt.computeN([u.EditorView.darkTheme],(t=>t.facet(u.EditorView.darkTheme)==("dark"==n)?[e]:[]))):i.push(dt.of(e)),i}class yt{constructor(e){this.markCache=Object.create(null),this.tree=ke(e.state),this.decorations=this.buildDeco(e,mt(e.state))}update(e){let t=ke(e.state),n=mt(e.state),i=n!=mt(e.startState);t.length<e.view.viewport.to&&!i&&t.type==this.tree.type?this.decorations=this.decorations.map(e.changes):(t!=this.tree||e.viewportChanged||i)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n))}buildDeco(e,t){if(!t||!this.tree.length)return u.Decoration.none;let n=new h.RangeSetBuilder;for(let{from:i,to:r}of e.visibleRanges)G(this.tree,t,((e,t,i)=>{n.add(e,t,this.markCache[i]||(this.markCache[i]=u.Decoration.mark({class:i})))}),i,r);return n.finish()}}const vt=h.Prec.high(u.ViewPlugin.fromClass(yt,{decorations:e=>e.decorations})),bt=ft.define([{tag:ue.meta,color:"#7a757a"},{tag:ue.link,textDecoration:"underline"},{tag:ue.heading,textDecoration:"underline",fontWeight:"bold"},{tag:ue.emphasis,fontStyle:"italic"},{tag:ue.strong,fontWeight:"bold"},{tag:ue.strikethrough,textDecoration:"line-through"},{tag:ue.keyword,color:"#708"},{tag:[ue.atom,ue.bool,ue.url,ue.contentSeparator,ue.labelName],color:"#219"},{tag:[ue.literal,ue.inserted],color:"#164"},{tag:[ue.string,ue.deleted],color:"#a11"},{tag:[ue.regexp,ue.escape,ue.special(ue.string)],color:"#e40"},{tag:ue.definition(ue.variableName),color:"#00f"},{tag:ue.local(ue.variableName),color:"#30a"},{tag:[ue.typeName,ue.namespace],color:"#085"},{tag:ue.className,color:"#167"},{tag:[ue.special(ue.variableName),ue.macroName],color:"#256"},{tag:ue.definition(ue.propertyName),color:"#00c"},{tag:ue.comment,color:"#940"},{tag:ue.invalid,color:"#f00"}]),wt=u.EditorView.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),xt="()[]{}",kt=h.Facet.define({combine:e=>(0,h.combineConfig)(e,{afterCursor:!0,brackets:xt,maxScanDistance:1e4,renderMatch:At})}),St=u.Decoration.mark({class:"cm-matchingBracket"}),Ct=u.Decoration.mark({class:"cm-nonmatchingBracket"});function At(e){let t=[],n=e.matched?St:Ct;return t.push(n.range(e.start.from,e.start.to)),e.end&&t.push(n.range(e.end.from,e.end.to)),t}const Et=h.StateField.define({create:()=>u.Decoration.none,update(e,t){if(!t.docChanged&&!t.selection)return e;let n=[],i=t.state.facet(kt);for(let r of t.state.selection.ranges){if(!r.empty)continue;let e=Dt(t.state,r.head,-1,i)||r.head>0&&Dt(t.state,r.head-1,1,i)||i.afterCursor&&(Dt(t.state,r.head,1,i)||r.head<t.state.doc.length&&Dt(t.state,r.head+1,-1,i));e&&(n=n.concat(i.renderMatch(e,t.state)))}return u.Decoration.set(n,!0)},provide:e=>u.EditorView.decorations.from(e)}),Ot=[Et,wt];function Mt(e,t,n){