@uiw/react-codemirror
Version:
CodeMirror component for React.
2 lines • 134 kB
JavaScript
/*! 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,r)=>(()=>{"use strict";var i={298:(e,t,n)=>{var r=n(787),i=Symbol.for("react.element"),o=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,l=r.__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 r,o={},c=null,h=null;for(r in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(h=t.ref),t)s.call(t,r)&&!a.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===o[r]&&(o[r]=t[r]);return{$$typeof:i,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=r}},o={};function s(e){var t=o[e];if(void 0!==t)return t.exports;var n=o[e]={exports:{}};return i[e](n,n.exports,s),n.exports}s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},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(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function n(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}s.r(l),s.d(l,{basicSetup:()=>$o,default:()=>Qo,useCodeMirror:()=>Ho});var r=s(787),i=s.n(r);function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t){if(e){if("string"===typeof e)return o(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)?o(e,t):void 0}}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 r,i,o=[],s=!0,l=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);s=!0);}catch(a){l=!0,i=a}finally{try{s||null==n.return||n.return()}finally{if(l)throw i}}return o}}(e,t)||a(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,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}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),r=new y(e.name||"",t,e.id,n);if(e.props)for(let i of e.props)if(Array.isArray(i)||(i=i(r)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[i[0].id]=i[1]}return r}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 r of n.split(" "))t[r]=e[n];return e=>{for(let n=e.prop(m.group),r=-1;r<(n?n.length:0);r++){let i=t[r<0?e.name:n[r]];if(i)return i}}}}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,r,i){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[e,t]of i)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 r=v.get(this)||this.topNode,i=new B(r);return i.moveTo(e,t),v.set(this,i._tree),i}get topNode(){return new M(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:r=0,to:i=this.length}=e;for(let o=this.cursor((e.mode||0)|w.IncludeAnonymous);;){let e=!1;if(o.from<=i&&o.to>=r&&(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:r,maxBufferLength:i=f,reused:o=[],minRepeatType:s=r.types.length}=e,l=Array.isArray(n)?new k(n,n.length):n,a=r.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,M=a[b],O=w-e;if(x-w<=i&&(E=y(l.pos-t,m))){let t=new Uint16Array(E.size-E.skip),n=l.pos-E.size,i=t.length;for(;l.pos>n;)i=v(E.start,t,i);A=new S(t,x-E.start,r),O=E.start-e}else{let e=l.pos-k;l.next();let t=[],n=[],r=b>=s?b:-1,o=0,a=x;for(;l.pos>e;)r>=0&&l.id==r&&l.size>=0?(l.end<=a-i&&(p(t,n,w,o,l.end,a,r,C),o=t.length,a=l.end),l.next()):u(w,e,t,n,r);if(r>=0&&o>0&&o<t.length&&p(t,n,w,o,w,a,r,C),t.reverse(),n.reverse(),r>-1&&o>0){let e=d(M);A=L(M,t,n,0,t.length,0,x-w,e,e)}else A=g(M,t,n,x-w,C-x)}n.push(A),f.push(O)}function d(e){return(t,n,r)=>{let i,o,s=0,l=t.length-1;if(l>=0&&(i=t[l])instanceof x){if(!l&&i.type==e&&i.length==r)return i;(o=i.prop(m.lookAhead))&&(s=n[l]+i.length+o)}return g(e,t,n,r,s)}}function p(e,t,n,i,o,s,l,a){let c=[],h=[];for(;e.length>i;)c.push(e.pop()),h.push(t.pop()+n-o);e.push(g(r.types[l],c,h,s-o,a-s)),t.push(o-n)}function g(e,t,n,r,i=0,o){if(c){let e=[m.contextHash,c];o=o?[e].concat(o):[e]}if(i>25){let e=[m.lookAhead,i];o=o?[e].concat(o):[e]}return new x(e,t,n,r,o)}function y(e,t){let n=l.fork(),r=0,o=0,a=0,c=n.end-i,h={size:0,start:0,skip:0};e:for(let i=n.pos-e;n.pos>i;){let e=n.size;if(n.id==t&&e>=0){h.size=r,h.start=o,h.skip=a,a+=4,r+=4,n.next();continue}let l=n.pos-e;if(e<0||l<i||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,r+=e,a+=u}return(t<0||r==e)&&(h.size=r,h.start=o,h.skip=a),h.size>4?h:void 0}function v(e,t,n){let{id:r,start:i,end:o,size:a}=l;if(l.next(),a>=0&&r<s){let s=n;if(a>4){let r=l.pos-(a-4);for(;l.pos>r;)n=v(e,t,n)}t[--n]=s,t[--n]=o-e,t[--n]=i-e,t[--n]=r}else-3==a?c=r:-4==a&&(h=r);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],r=this.set.types[t],i=r.name;if(/\W/.test(i)&&!r.isError&&(i=JSON.stringify(i)),n==(e+=4))return i;let o=[];for(;e<n;)o.push(this.childString(e)),e=this.buffer[e+3];return i+"("+o.join(",")+")"}findChild(e,t,n,r,i){let{buffer:o}=this,s=-1;for(let l=e;l!=t&&!(C(i,r,o[l+1],o[l+2])&&(s=l,n>0));l=o[l+3]);return s}slice(e,t,n,r){let i=this.buffer,o=new Uint16Array(t-e);for(let s=e,l=0;s<t;)o[l++]=i[s++],o[l++]=i[s++]-n,o[l++]=i[s++]-n,o[l++]=i[s++]-e;return new S(o,r-n,this.set)}}function C(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>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,r){for(var i;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let t=!r&&e instanceof M&&e.index<0?null:e.parent;if(!t)return e;e=t}let o=r?0:w.IgnoreOverlays;if(r)for(let s=e,l=s.parent;l;s=l,l=s.parent)s instanceof M&&s.index<0&&(null===(i=l.enter(t,n,o))||void 0===i?void 0:i.from)!=s.from&&(e=l);for(;;){let r=e.enter(t,n,o);if(!r)return e;e=r}}class M{constructor(e,t,n,r){this._tree=e,this.from=t,this.index=n,this._parent=r}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,r,i=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(r,n,c,c+a.length))if(a instanceof S){if(i&w.ExcludeBuffers)continue;let s=a.findChild(0,a.buffer.length,t,n-c,r);if(s>-1)return new I(new P(o,a,e,c),null,s)}else if(i&w.IncludeAnonymous||!a.type.isAnonymous||T(a)){let s;if(!(i&w.IgnoreMounts)&&a.props&&(s=a.prop(m.mounted))&&!s.overlay)return new M(s.tree,c,e,o);let l=new M(a,c,e,o);return i&w.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(t<0?a.children.length-1:0,t,n,r)}}if(i&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 r;if(!(n&w.IgnoreOverlays)&&(r=this._tree.prop(m.mounted))&&r.overlay){let n=e-this.from;for(let{from:e,to:i}of r.overlay)if((t>0?e<=n:e<n)&&(t<0?i>=n:i>n))return new M(r.tree,r.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 r=O(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return O(this,e,t,n)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return D(this,e)}}function O(e,t,n,r){let i=e.cursor(),o=[];if(!i.firstChild())return o;if(null!=n)for(;!i.type.is(n);)if(!i.nextSibling())return o;for(;;){if(null!=r&&i.type.is(r))return o;if(i.type.is(t)&&o.push(i.node),!i.nextSibling())return null==r?o:[]}}function D(e,t,n=t.length-1){for(let r=e.parent;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}class P{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}}class I{constructor(e,t,n){this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}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]}child(e,t,n){let{buffer:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.context.start,n);return i<0?null:new I(this.context,this,i)}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:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return i<0?null:new I(this.context,this,i)}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,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let o=n.buffer[this.index+1],s=n.buffer[this.index+2];e.push(n.slice(r,i,o,s)),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 r=O(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return O(this,e,t,n)}get node(){return this}matchContext(e){return D(this,e)}}class B{constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof M)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)}}get name(){return this.type.name}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:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return!!e&&(e instanceof M?(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:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return!(i<0)&&(this.stack.push(this.index),this.yieldBuf(i))}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:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(r.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;({index:t,_parent:n}=n))if(t>-1)for(let r=t+e,i=e<0?-1:n._tree.children.length;r!=i;r+=e){let e=n._tree.children[r];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 r=this.index,i=this.stack.length;i>=0;){for(let o=e;o;o=o._parent)if(o.index==r){if(r==this.index)return o;t=o,n=i+1;break e}r=this.stack[--i]}for(let r=n;r<this.stack.length;r++)t=new I(this.buffer,t,this.stack[r]);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 r=!1;if(this.type.isAnonymous||!1!==e(this)){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;r&&t&&t(this),r=this.type.isAnonymous,!this.nextSibling();){if(!n)return;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return D(this.node,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,i=this.stack.length-1;r>=0;i--){if(i<0)return D(this.node,e,r);let o=n[t.buffer[this.stack[i]]];if(!o.isAnonymous){if(e[r]&&e[r]!=o.name)return!1;r--}}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 r of t.children){if(r.type!=e||!(r instanceof x)){n=1;break}n+=R(e,r)}N.set(t,n)}return n}function L(e,t,n,r,i,o,s,l,a){let c=0;for(let d=r;d<i;d++)c+=R(e,t[d]);let h=Math.ceil(1.5*c/8),u=[],f=[];return function t(n,r,i,s,l){for(let c=i;c<s;){let i=c,d=r[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==i+1){if(p>h){let e=n[i];t(e.children,e.positions,0,e.children.length,r[i]+l);continue}u.push(n[i])}else{let t=r[c-1]+n[c-1].length-d;u.push(L(e,n,r,i,c,d,t,null,a))}f.push(d+l-o)}}(t,n,r,i,0),(l||a)(u,f,s)}class _{constructor(e,t,n,r,i=!1,o=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=(i?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 r=[new _(0,e.length,e,0,!1,n)];for(let i of t)i.to>e.length&&r.push(i);return r}static applyChanges(e,t,n=128){if(!t.length)return e;let r=[],i=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&&r.push(t),o.to>h)break;o=i<e.length?e[i++]:null}if(!c)break;l=c.toA,a=c.toA-c.toB}return r}}class F{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&&(r=t,i=n.modified,r.length==i.length&&r.every(((e,t)=>e==i[t])));var r,i}));if(n)return n;let r=[],i=new j(r,e,t);for(let s of t)s.instances.push(i);let o=W(t);for(let s of e.set)for(let e of o)r.push(z.get(s,e));return i}}function W(e){let t=[e];for(let n=0;n<e.length;n++)for(let r of W(e.slice(0,n).concat(e.slice(n+1))))t.push(r);return t}function U(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let e of n.split(" "))if(e){let n=[],i=2,o=e;for(let t=0;;){if("..."==o&&t>0&&t+3==e.length){i=1;break}let r=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(o);if(!r)throw new RangeError("Invalid path: "+e);if(n.push("*"==r[0]?"":'"'==r[0][0]?JSON.parse(r[0]):r[0]),t+=r[0].length,t==e.length)break;let s=e[t++];if(t==e.length&&"!"==s){i=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(r,i,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,r){this.tags=e,this.mode=t,this.context=n,this.next=r}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:r,all:i=null}=t||{};return{style:e=>{let t=i;for(let r of e)for(let e of r.set){let r=n[e.id];if(r){t=t?t+" "+r:r;break}}return t},scope:r}}function K(e,t){let n=null;for(let r of e){let e=r.style(t);e&&(n=n?n+" "+e:e)}return n}function G(e,t,n,r=0,i=e.length){let o=new Q(r,Array.isArray(t)?t:[t],n);o.highlightRange(e.cursor(),r,i,"",o.highlighters),o.flush(i)}class Q{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,r,i){let{type:o,from:s,to:l}=e;if(s>=n||l<=t)return;o.isTop&&(i=this.highlighters.filter((e=>!e.scope||e.scope(o))));let a=r,c=o.prop($),h=!1;for(;c;){if(!c.context||e.matchContext(c.context)){let e=K(i,c.tags);e&&(a&&(a+=" "),a+=e,1==c.mode?r+=(r?" ":"")+e:0==c.mode&&(h=!0));break}c=c.next}if(this.startSpan(e.from,a),h)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,r,i),this.startSpan(Math.min(n,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),r,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,r,i),this.startSpan(Math.min(n,e.to),a)}}while(e.nextSibling());e.parent()}}}const Y=j.define,Z=Y(),X=Y(),ee=Y(X),te=Y(X),ne=Y(),re=Y(ne),ie=Y(ne),oe=Y(),se=Y(oe),le=Y(),ae=Y(),ce=Y(),he=Y(ce),ue=Y(),fe={comment:Z,lineComment:Y(Z),blockComment:Y(Z),docComment:Y(Z),name:X,variableName:Y(X),typeName:ee,tagName:Y(ee),propertyName:te,attributeName:Y(te),className:Y(X),labelName:Y(X),namespace:Y(X),macroName:Y(X),literal:ne,string:re,docString:Y(re),character:Y(re),attributeValue:Y(re),number:ie,integer:Y(ie),float:Y(ie),bool:Y(ne),regexp:Y(ne),escape:Y(ne),color:Y(ne),url:Y(ne),keyword:le,self:Y(le),null:Y(le),atom:Y(le),unit:Y(le),modifier:Y(le),operatorKeyword:Y(le),controlKeyword:Y(le),definitionKeyword:Y(le),moduleKeyword:Y(le),operator:ae,derefOperator:Y(ae),arithmeticOperator:Y(ae),logicOperator:Y(ae),bitwiseOperator:Y(ae),compareOperator:Y(ae),updateOperator:Y(ae),definitionOperator:Y(ae),typeOperator:Y(ae),controlOperator:Y(ae),punctuation:ce,separator:Y(ce),bracket:he,angleBracket:Y(he),squareBracket:Y(he),paren:Y(he),brace:Y(he),content:oe,heading:se,heading1:Y(se),heading2:Y(se),heading3:Y(se),heading4:Y(se),heading5:Y(se),heading6:Y(se),contentSeparator:Y(oe),list:Y(oe),quote:Y(oe),emphasis:Y(oe),strong:Y(oe),link:Y(oe),monospace:Y(oe),strikethrough:Y(oe),inserted:Y(),deleted:Y(),changed:Y(),invalid:Y(),meta:ue,documentMeta:Y(ue),annotation:Y(ue),processingInstruction:Y(ue),definition:j.defineModifier(),constant:j.defineModifier(),function:j.defineModifier(),standard:j.defineModifier(),local:j.defineModifier(),special:j.defineModifier()},de=(J([{tag:fe.link,class:"tok-link"},{tag:fe.heading,class:"tok-heading"},{tag:fe.emphasis,class:"tok-emphasis"},{tag:fe.strong,class:"tok-strong"},{tag:fe.keyword,class:"tok-keyword"},{tag:fe.atom,class:"tok-atom"},{tag:fe.bool,class:"tok-bool"},{tag:fe.url,class:"tok-url"},{tag:fe.labelName,class:"tok-labelName"},{tag:fe.inserted,class:"tok-inserted"},{tag:fe.deleted,class:"tok-deleted"},{tag:fe.literal,class:"tok-literal"},{tag:fe.string,class:"tok-string"},{tag:fe.number,class:"tok-number"},{tag:[fe.regexp,fe.escape,fe.special(fe.string)],class:"tok-string2"},{tag:fe.variableName,class:"tok-variableName"},{tag:fe.local(fe.variableName),class:"tok-variableName tok-local"},{tag:fe.definition(fe.variableName),class:"tok-variableName tok-definition"},{tag:fe.special(fe.variableName),class:"tok-variableName2"},{tag:fe.definition(fe.propertyName),class:"tok-propertyName tok-definition"},{tag:fe.typeName,class:"tok-typeName"},{tag:fe.namespace,class:"tok-namespace"},{tag:fe.className,class:"tok-className"},{tag:fe.macroName,class:"tok-macroName"},{tag:fe.propertyName,class:"tok-propertyName"},{tag:fe.operator,class:"tok-operator"},{tag:fe.comment,class:"tok-comment"},{tag:fe.meta,class:"tok-meta"},{tag:fe.invalid,class:"tok-invalid"},{tag:fe.punctuation,class:"tok-punctuation"}]),"undefined"==typeof Symbol?"__\u037c":Symbol.for("\u037c")),pe="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),me="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class ge{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function i(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))i(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.");i(r(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)i(r(o),e[o],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let e=me[de]||1;return me[de]=e+1,"\u037c"+e.toString(36)}static mount(e,t){(e[pe]||new ve(e)).mount(Array.isArray(t)?t:[t])}}let ye=null;class ve{constructor(e){if(!e.head&&e.adoptedStyleSheets&&"undefined"!=typeof CSSStyleSheet){if(ye)return e.adoptedStyleSheets=[ye.sheet].concat(e.adoptedStyleSheets),e[pe]=ye;this.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[this.sheet].concat(e.adoptedStyleSheets),ye=this}else{this.styleTag=(e.ownerDocument||e).createElement("style");let t=e.head||e;t.insertBefore(this.styleTag,t.firstChild)}this.modules=[],e[pe]=this}mount(e){let t=this.sheet,n=0,r=0;for(let i=0;i<e.length;i++){let o=e[i],s=this.modules.indexOf(o);if(s<r&&s>-1&&(this.modules.splice(s,1),r--,s=-1),-1==s){if(this.modules.splice(r++,0,o),t)for(let e=0;e<o.rules.length;e++)t.insertRule(o.rules[e],n++)}else{for(;r<s;)n+=this.modules[r++].rules.length;n+=o.rules.length,r++}}if(!t){let e="";for(let t=0;t<this.modules.length;t++)e+=this.modules[t].getRules()+"\n";this.styleTag.textContent=e}}}var be;const we=new m;class xe{constructor(e,t,n=[]){this.data=e,h.EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(h.EditorState.prototype,"tree",{get(){return Se(this)}}),this.parser=t,this.extension=[Be.of(this),h.EditorState.languageData.of(((e,t,n)=>e.facet(ke(e,t,n))))].concat(n)}isActiveAt(e,t,n=-1){return ke(e,t,n)==this.data}findRegions(e){let t=e.facet(Be);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=[],r=(e,t)=>{if(e.prop(we)==this.data)return void n.push({from:t,to:t+e.length});let i=e.prop(m.mounted);if(i){if(i.tree.prop(we)==this.data){if(i.overlay)for(let e of i.overlay)n.push({from:e.from+t,to:e.to+t});else n.push({from:t,to:t+e.length});return}if(i.overlay){let e=n.length;if(r(i.tree,i.overlay[0].from+t),n.length>e)return}}for(let n=0;n<e.children.length;n++){let i=e.children[n];i instanceof x&&r(i,e.positions[n]+t)}};return r(Se(e),0),n}get allowsNesting(){return!0}}function ke(e,t,n){let r=e.facet(Be);if(!r)return null;let i=r.data;if(r.allowsNesting)for(let o=Se(e).topNode;o;o=o.enter(t,n,w.ExcludeBuffers))i=o.type.prop(we)||i;return i}xe.setState=h.StateEffect.define();function Se(e){let t=e.field(xe.state,!1);return t?t.tree:x.empty}class Ce{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 Ae=null;class Ee{constructor(e,t,n=[],r,i,o,s,l){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=i,this.viewport=o,this.skipped=s,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new Ee(e,t,[],x.empty,0,n,[],null)}startParse(){return this.parser.startParse(new Ce(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 r=this.parse.advance();if(r){if(this.fragments=this.withoutTempSkipped(_.addTree(r,this.fragments,null!=this.parse.stoppedAt)),this.treeLen=null!==(n=this.parse.stoppedAt)&&void 0!==n?n:this.state.doc.length,this.tree=r,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=Ae;Ae=this;try{return e()}finally{Ae=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Me(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:r,treeLen:i,viewport:o,skipped:s}=this;if(this.takeTree(),!e.empty){let t=[];if(e.iterChangedRanges(((e,n,r,i)=>t.push({fromA:e,toA:n,fromB:r,toB:i}))),n=_.applyChanges(n,t),r=x.empty,i=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),r=e.mapPos(t.to,-1);n<r&&s.push({from:n,to:r})}}}return new Ee(this.parser,t,n,r,i,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:r}=this.skipped[n];t<e.to&&r>e.from&&(this.fragments=Me(this.fragments,t,r),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 class{startParse(e,t,n){return"string"==typeof e&&(e=new F(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 r=this.startParse(e,t,n);for(;;){let e=r.advance();if(e)return e}}}{createParse(t,n,r){let i=r[0].from,o=r[r.length-1].to;return{parsedPos:i,advance(){let t=Ae;if(t){for(let e of r)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=o,new x(y.none,[],[],o-i)},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 Ae}}function Me(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=Ee.create(e.facet(Be).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new Oe(n)}}xe.state=h.StateField.define({create:Oe.init,update(e,t){for(let n of t.effects)if(n.is(xe.setState))return n.value;return t.startState.facet(Be)!=t.state.facet(Be)?Oe.init(t.state):e.apply(t)}});let De=e=>{let t=setTimeout((()=>e()),500);return()=>clearTimeout(t)};"undefined"!=typeof requestIdleCallback&&(De=e=>{let t=-1,n=setTimeout((()=>{t=requestIdleCallback(e,{timeout:400})}),100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)});const Pe="undefined"!=typeof navigator&&(null===(be=navigator.scheduling)||void 0===be?void 0:be.isInputPending)?()=>navigator.scheduling.isInputPending():null,Ie=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(xe.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(xe.state);t.tree==t.context.tree&&t.context.isDone(e.doc.length)||(this.working=De(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:r}}=this.view,i=n.field(xe.state);if(i.tree==i.context.tree&&i.context.isDone(r+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Pe?Math.max(25,e.timeRemaining()-5):1e9),s=i.context.treeLen<r&&n.doc.length>r+1e3,l=i.context.work((()=>Pe&&Pe()||Date.now()>o),r+(s?0:1e5));this.chunkBudget-=Date.now()-t,(l||this.chunkBudget<=0)&&(i.context.takeTree(),this.view.dispatch({effects:xe.setState.of(new Oe(i.context))})),this.chunkBudget>0&&(!l||s)&&this.scheduleWork(),this.checkAsyncSchedule(i.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()}}}),Be=h.Facet.define({combine:e=>e.length?e[0]:null,enables:[xe.state,Ie]});const Te=h.Facet.define(),Ne=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 Re(e){let t=e.facet(Ne);return 9==t.charCodeAt(0)?e.tabSize*t.length:t.length}function Le(e,t){let n="",r=e.tabSize;if(9==e.facet(Ne).charCodeAt(0))for(;t>=r;)n+="\t",t-=r;for(let i=0;i<t;i++)n+=" ";return n}function _e(e,t){e instanceof h.EditorState&&(e=new Fe(e));for(let r of e.state.facet(Te)){let n=r(e,t);if(null!=n)return n}let n=Se(e.state);return n?function(e,t,n){return qe(t.resolveInner(n).enterUnfinishedNodesBefore(n),n,e)}(e,n,t):null}class Fe{constructor(e,t={}){this.state=e,this.options=t,this.unit=Re(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:i}=this.options;return null!=r&&r>=n.from&&r<=n.to?i&&r==e?{text:"",from:e}:(t<0?r<e:r<=e)?{text:n.text.slice(r-n.from),from:r}:{text:n.text.slice(0,r-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:n,from:r}=this.lineAt(e,t);return n.slice(e-r,Math.min(n.length,e+100-r))}column(e,t=1){let{text:n,from:r}=this.lineAt(e,t),i=this.countColumn(n,e-r),o=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return o>-1&&(i+=o-this.countColumn(n,n.search(/\S|$/))),i}countColumn(e,t=e.length){return(0,h.countColumn)(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:r}=this.lineAt(e,t),i=this.options.overrideIndentation;if(i){let e=i(r);if(e>-1)return e}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Ve=new m;function je(e){let t=e.type.prop(Ve);if(t)return t;let n,r=e.firstChild;if(r&&(n=r.type.prop(m.closedBy))){let t=e.lastChild,r=t&&n.indexOf(t.name)>-1;return e=>$e(e,!0,1,void 0,r&&!function(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}(e)?t.from:void 0)}return null==e.parent?ze:null}function qe(e,t,n){for(;e;e=e.parent){let r=je(e);if(r)return r(We.create(n,t,e))}return null}function ze(){return 0}class We extends Fe{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 We(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(Ue(t,this.node))break;e=this.state.doc.lineAt(t.from)}return this.lineIndent(e.from)}continue(){let e=this.node.parent;return e?qe(e,this.pos,this.base):0}}function Ue(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function $e(e,t,n,r,i){let o=e.textAfter,s=o.match(/^\s*/)[0].length,l=r&&o.slice(s,s+r.length)==r||i==e.pos+s,a=t?function(e){let t=e.node,n=t.childAfter(t.from),r=t.lastChild;if(!n)return null;let i=e.options.simulateBreak,o=e.state.doc.lineAt(n.from),s=null==i||i<=o.from?o.to:Math.min(o.to,i);for(let l=n.to;;){let e=t.childAfter(l);if(!e||e==r)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)}function He(){return h.EditorState.transactionFilter.of((e=>{if(!e.docChanged||!e.isUserEvent("input.type")&&!e.isUserEvent("input.complete"))return e;let t=e.startState.languageDataAt("indentOnInput",e.startState.selection.main.head);if(!t.length)return e;let n=e.newDoc,{head:r}=e.newSelection.main,i=n.lineAt(r);if(r>i.from+200)return e;let o=n.sliceString(i.from,r);if(!t.some((e=>e.test(o))))return e;let{state:s}=e,l=-1,a=[];for(let{head:c}of s.selection.ranges){let e=s.doc.lineAt(c);if(e.from==l)continue;l=e.from;let t=_e(s,e.from);if(null==t)continue;let n=/^\s*/.exec(e.text)[0],r=Le(s,t);n!=r&&a.push({from:e.from,to:e.from+n.length,insert:r})}return a.length?[e,{changes:a,sequential:!0}]:e}))}const Je=h.Facet.define(),Ke=new m;function Ge(e){let t=e.lastChild;return t&&t.to==e.to&&t.type.isError}function Qe(e,t,n){for(let r of e.facet(Je)){let i=r(e,t,n);if(i)return i}return function(e,t,n){let r=Se(e);if(r.length<n)return null;let i=null;for(let o=r.resolveInner(n);o;o=o.parent){if(o.to<=n||o.from>n)continue;if(i&&o.from<t)break;let s=o.type.prop(Ke);if(s&&(o.to<r.length-50||r.length==e.doc.length||!Ge(o))){let r=s(o,e);r&&r.from<=n&&r.from>=t&&r.to>n&&(i=r)}}return i}(e,t,n)}function Ye(e,t){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);return n>=r?void 0:{from:n,to:r}}const Ze=h.StateEffect.define({map:Ye}),Xe=h.StateEffect.define({map:Ye});function et(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 tt=h.StateField.define({create:()=>u.Decoration.none,update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(Ze)&&!rt(e,n.value.from,n.value.to)?e=e.update({add:[ht.range(n.value.from,n.value.to)]}):n.is(Xe)&&(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:r}=t.selection.main;e.between(r,r,((e,t)=>{e<r&&t>r&&(n=!0)})),n&&(e=e.update({filterFrom:r,filterTo:r,filter:(e,t)=>t<=r||e>=r}))}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 r=e[n++],i=e[n++];if("number"!=typeof r||"number"!=typeof i)throw new RangeError("Invalid JSON for fold state");t.push(ht.range(r,i))}return u.Decoration.set(t,!0)}});function nt(e,t,n){var r;let i=null;return null===(r=e.field(tt,!1))||void 0===r||r.between(t,n,((e,t)=>{(!i||i.from>e)&&(i={from:e,to:t})})),i}function rt(e,t,n){let r=!1;return e.between(t,t,((e,i)=>{e==t&&i==n&&(r=!0)})),r}function it(e,t){return e.field(tt,!1)?t:t.concat(h.StateEffect.appendConfig.of(ct()))}function ot(e,t,n=!0){let r=e.state.doc.lineAt(t.from).number,i=e.state.doc.lineAt(t.to).number;return u.EditorView.announce.of(`${e.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${e.state.phrase("to")} ${i}.`)}const st=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:e=>{for(let t of et(e)){let n=Qe(e.state,t.from,t.to);if(n)return e.dispatch({effects:it(e.state,[Ze.of(n),ot(e,n)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:e=>{if(!e.state.field(tt,!1))return!1;let t=[];for(let n of et(e)){let r=nt(e.state,n.from,n.to);r&&t.push(Xe.of(r),ot(e,r,!1))}return t.length&&e.dispatch({effects:t}),t.length>0}},{key:"Ctrl-Alt-[",run:e=>{let{state:t}=e,n=[];for(let r=0;r<t.doc.length;){let i=e.lineBlockAt(r),o=Qe(t,i.from,i.to);o&&n.push(Ze.of(o)),r=(o?e.lineBlockAt(o.to):i).to+1}return n.length&&e.dispatch({effects:it(e.state,n)}),!!n.length}},{key:"Ctrl-Alt-]",run:e=>{let t=e.state.field(tt,!1);if(!t||!t.size)return!1;let n=[];return t.between(0,e.state.doc.length,((e,t)=>{n.push(Xe.of({from:e,to:t}))})),e.dispatch({effects:n}),!0}}],lt={placeholderDOM:null,placeholderText:"\u2026"},at=h.Facet.define({combine:e=>(0,h.combineConfig)(e,lt)});function ct(e){let t=[tt,pt];return e&&t.push(at.of(e)),t}const ht=u.Decoration.replace({widget:new class extends u.WidgetType{toDOM(e){let{state:t}=e,n=t.facet(at),r=t=>{let n=e.lineBlockAt(e.posAtDOM(t.target)),r=nt(e.state,n.from,n.to);r&&e.dispatch({effects:Xe.of(r)}),t.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(e,r);let i=document.createElement("span");return i.textContent=n.placeholderText,i.setAttribute("aria-label",t.phrase("folded code")),i.title=t.phrase("unfold"),i.className="cm-foldPlaceholder",i.onclick=r,i}}}),ut={openText:"\u2304",closedText:"\u203a",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class ft 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}}function dt(e={}){let t=Object.assign(Object.assign({},ut),e),n=new ft(t,!0),r=new ft(t,!1),i=u.ViewPlugin.fromClass(class{constructor(e){this.from=e.viewport.from,this.markers=this.buildMarkers(e)}update(e){(e.docChanged||e.viewportChanged||e.startState.facet(Be)!=e.state.facet(Be)||e.startState.field(tt,!1)!=e.state.field(tt,!1)||Se(e.startState)!=Se(e.state)||t.foldingChanged(e))&&(this.markers=this.buildMarkers(e.view))}buildMarkers(e){let t=new h.RangeSetBuilder;for(let i of e.viewportLineBlocks){let o=nt(e.state,i.from,i.to)?r:Qe(e.state,i.from,i.to)?n:null;o&&t.add(i.from,i.from,o)}return t.finish()}}),{domEventHandlers:o}=t;return[i,(0,u.gutter)({class:"cm-foldGutter",markers(e){var t;return(null===(t=e.plugin(i))||void 0===t?void 0:t.markers)||h.RangeSet.empty},initialSpacer:()=>new ft(t,!1),domEventHandlers:Object.assign(Object.assign({},o),{click:(e,t,n)=>{if(o.click&&o.click(e,t,n))return!0;let r=nt(e.state,t.from,t.to);if(r)return e.dispatch({effects:Xe.of(r)}),!0;let i=Qe(e.state,t.from,t.to);return!!i&&(e.dispatch({effects:Ze.of(i)}),!0)}})}),ct()]}const pt=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 mt{constructor(e,t){let n;function r(e){let t=ge.newName();return(n||(n=Object.create(null)))["."+t]=e,t}const i="string"==typeof t.all?t.all:t.all?r(t.all):void 0,o=t.scope;this.scope=o instanceof xe?e=>e.prop(we)==o.data:o?e=>e==o:void 0,this.style=J(e.map((e=>({tag:e.tag,class:e.class||r(Object.assign({},e,{tag:null}))}))),{all:i}).style,this.module=n?new ge(n):null,this.themeType=t.themeType}static define(e,t){return new mt(e,t||{})}}const gt=h.Facet.define(),yt=h.Facet.define({combine:e=>e.length?[e[0]]:null});function vt(e){let t=e.facet(gt);return t.length?t:e.facet(yt)}function bt(e,t){let n,r=[xt];return e instanceof mt&&(e.module&&r.push(u.EditorView.styleModule.of(e.module)),n=e.themeType),(null===t||void 0===t?void 0:t.fallback)?r.push(yt.of(e)):n?r.push(gt.computeN([u.EditorView.darkTheme],(t=>t.facet(u.EditorView.darkTheme)==("dark"==n)?[e]:[]))):r.push(gt.of(e)),r}class wt{constructor(e){this.markCache=Object.create(null),this.tree=Se(e.state),this.decorations=this.buildDeco(e,vt(e.state))}update(e){let t=Se(e.state),n=vt(e.state),r=n!=vt(e.startState);t.length<e.view.viewport.to&&!r&&t.type==this.tree.type?this.decorations=this.decorations.map(e.changes):(t!=this.tree||e.viewportChanged||r)&&(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:r,to:i}of e.visibleRanges)G(this.tree,t,((e,t,r)=>{n.add(e,t,this.markCache[r]||(this.markCache[r]=u.Decoration.mark({class:r})))}),r,i);return n.finish()}}const xt=h.Prec.high(u.ViewPlugin.fromClass(wt,{decorations:e=>e.decorations})),kt=mt.define([{tag:fe.meta,color:"#7a757a"},{tag:fe.link,textDecoration:"underline"},{tag:fe.heading,textDecoration:"underline",fontWeight:"bold"},{tag:fe.emphasis,fontStyle:"italic"},{tag:fe.strong,fontWeight:"bold"},{tag:fe.strikethrough,textDecoration:"line-through"},{tag:fe.keyword,color:"#708"},{tag:[fe.atom,fe.bool,fe.url,fe.contentSeparator,fe.labelName],color:"#219"},{tag:[fe.literal,fe.inserted],color:"#164"},{tag:[fe.string,fe.deleted],color:"#a11"},{tag:[fe.regexp,fe.escape,fe.special(fe.string)],color:"#e40"},{tag:fe.definition(fe.variableName),color:"#00f"},{tag:fe.local(fe.variableName),color:"#30a"},{tag:[fe.typeName,fe.namespace],color:"#085"},{tag:fe.className,color:"#167"},{tag:[fe.special(fe.variableName),fe.macroName],color:"#256"},{tag:fe.definition(fe.propertyName),color:"#00c"},{tag:fe.comment,color:"#940"},{tag:fe.invalid,color:"#f00"}]),St=u.EditorView.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Ct="