satis 2.0.7 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/gem-push.yml +11 -0
  3. data/.gitignore +15 -0
  4. data/.nvmrc +1 -0
  5. data/.rubocop.yml +18 -0
  6. data/Gemfile +27 -0
  7. data/Procfile +2 -0
  8. data/TODO.md +26 -0
  9. data/app/assets/images/satis/.keep +0 -0
  10. data/app/components/satis/tabs/component_controller.js +6 -0
  11. data/bin/importmap +4 -0
  12. data/bin/rails +14 -0
  13. data/lib/satis/version.rb +1 -1
  14. data/package.json +9 -0
  15. data/satis.gemspec +39 -0
  16. data/vendor/javascript/@codemirror--autocomplete.js +2 -0
  17. data/vendor/javascript/@codemirror--commands.js +2 -0
  18. data/vendor/javascript/@codemirror--lang-css.js +2 -0
  19. data/vendor/javascript/@codemirror--lang-html.js +2 -0
  20. data/vendor/javascript/@codemirror--lang-javascript.js +2 -0
  21. data/vendor/javascript/@codemirror--lang-json.js +2 -0
  22. data/vendor/javascript/@codemirror--lang-liquid.js +2 -0
  23. data/vendor/javascript/@codemirror--lang-markdown.js +2 -0
  24. data/vendor/javascript/@codemirror--lang-yaml.js +2 -0
  25. data/vendor/javascript/@codemirror--language.js +2 -0
  26. data/vendor/javascript/@codemirror--lint.js +2 -0
  27. data/vendor/javascript/@codemirror--search.js +2 -0
  28. data/vendor/javascript/@codemirror--state.js +2 -0
  29. data/vendor/javascript/@codemirror--view.js +2 -0
  30. data/vendor/javascript/@lezer--common.js +2 -0
  31. data/vendor/javascript/@lezer--css.js +2 -0
  32. data/vendor/javascript/@lezer--highlight.js +2 -0
  33. data/vendor/javascript/@lezer--html.js +2 -0
  34. data/vendor/javascript/@lezer--javascript.js +2 -0
  35. data/vendor/javascript/@lezer--json.js +2 -0
  36. data/vendor/javascript/@lezer--lr.js +2 -0
  37. data/vendor/javascript/@lezer--markdown.js +2 -0
  38. data/vendor/javascript/@lezer--yaml.js +2 -0
  39. data/vendor/javascript/@rails--actiontext.js +2 -0
  40. data/vendor/javascript/codemirror.js +2 -0
  41. data/vendor/javascript/crelt.js +2 -0
  42. data/vendor/javascript/data.min.js +7 -0
  43. data/vendor/javascript/intl-tel-input-utils.js +520 -0
  44. data/vendor/javascript/intl-tel-input.js +1782 -0
  45. data/vendor/javascript/leaflet.js +6 -0
  46. data/vendor/javascript/popper.js.js +1805 -0
  47. data/vendor/javascript/sortablejs.js +134 -0
  48. data/vendor/javascript/style-mod.js +2 -0
  49. data/vendor/javascript/tippy.js.js +2 -0
  50. data/vendor/javascript/trix.js +2 -0
  51. data/vendor/javascript/w3c-keyname.js +2 -0
  52. data/yarn.lock +821 -0
  53. metadata +51 -2
@@ -0,0 +1,2 @@
1
+ import{countColumn as e,EditorSelection as t,Prec as r,EditorState as n}from"@codemirror/state";import{keymap as o}from"@codemirror/view";import{defineLanguageFacet as l,foldNodeProp as i,indentNodeProp as s,languageDataProp as m,syntaxTree as a,foldService as f,Language as u,LanguageDescription as c,ParseContext as g,indentUnit as d,LanguageSupport as h}from"@codemirror/language";import{CompletionContext as p}from"@codemirror/autocomplete";import{parser as x,GFM as k,Subscript as L,Superscript as b,Emoji as C,MarkdownParser as w,parseCode as A}from"@lezer/markdown";import{html as B,htmlCompletionSource as I}from"@codemirror/lang-html";import{NodeProp as v}from"@lezer/common";const S=l({commentTokens:{block:{open:"\x3c!--",close:"--\x3e"}}});const y=new v;const T=x.configure({props:[i.add((e=>!e.is("Block")||e.is("Document")||isHeading(e)!=null?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to}))),y.add(isHeading),s.add({Document:()=>null}),m.add({Document:S})]});function isHeading(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function findSectionEnd(e,t){let r=e;for(;;){let e,n=r.nextSibling;if(!n||(e=isHeading(n.type))!=null&&e<=t)break;r=n}return r.to}const D=f.of(((e,t,r)=>{for(let n=a(e).resolveInner(r,-1);n;n=n.parent){if(n.from<t)break;let e=n.type.prop(y);if(e==null)continue;let o=findSectionEnd(n,e);if(o>r)return{from:r,to:o}}return null}));function mkLang(e){return new u(S,e,[D],"markdown")}const M=mkLang(T);const O=T.configure([k,L,b,C,{props:[i.add({Table:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})})]}]);const z=mkLang(O);function getCodeParser(e,t){return r=>{if(r&&e){let t=null;r=/\S*/.exec(r)[0];t=typeof e=="function"?e(r):c.matchLanguageName(e,r,true);if(t instanceof c)return t.support?t.support.language.parser:g.getSkippingParser(t.load());if(t)return t.parser}return t?t.parser:null}}class Context{constructor(e,t,r,n,o,l,i){this.node=e;this.from=t;this.to=r;this.spaceBefore=n;this.spaceAfter=o;this.type=l;this.item=i}blank(e,t=true){let r=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(e!=null){while(r.length<e)r+=" ";return r}for(let e=this.to-this.from-r.length-this.spaceAfter.length;e>0;e--)r+=" ";return r+(t?this.spaceAfter:"")}marker(e,t){let r=this.node.name=="OrderedList"?String(+itemNumber(this.item,e)[2]+t):"";return this.spaceBefore+r+this.type+this.spaceAfter}}function getContext(e,t){let r=[];for(let t=e;t&&t.name!="Document";t=t.parent)t.name!="ListItem"&&t.name!="Blockquote"&&t.name!="FencedCode"||r.push(t);let n=[];for(let e=r.length-1;e>=0;e--){let o,l=r[e];let i=t.lineAt(l.from),s=l.from-i.from;if(l.name=="FencedCode")n.push(new Context(l,s,s,"","","",null));else if(l.name=="Blockquote"&&(o=/^ *>( ?)/.exec(i.text.slice(s))))n.push(new Context(l,s,s+o[0].length,"",o[1],">",null));else if(l.name=="ListItem"&&l.parent.name=="OrderedList"&&(o=/^( *)\d+([.)])( *)/.exec(i.text.slice(s)))){let e=o[3],t=o[0].length;if(e.length>=4){e=e.slice(0,e.length-4);t-=4}n.push(new Context(l.parent,s,s+t,o[1],e,o[2],l))}else if(l.name=="ListItem"&&l.parent.name=="BulletList"&&(o=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(i.text.slice(s)))){let e=o[4],t=o[0].length;if(e.length>4){e=e.slice(0,e.length-4);t-=4}let r=o[2];o[3]&&(r+=o[3].replace(/[xX]/," "));n.push(new Context(l.parent,s,s+t,o[1],e,r,l))}}return n}function itemNumber(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function renumberList(e,t,r,n=0){for(let o=-1,l=e;;){if(l.name=="ListItem"){let e=itemNumber(l,t);let i=+e[2];if(o>=0){if(i!=o+1)return;r.push({from:l.from+e[1].length,to:l.from+e[0].length,insert:String(o+2+n)})}o=i}let e=l.nextSibling;if(!e)break;l=e}}function normalizeIndent(t,r){let n=/^[ \t]*/.exec(t)[0].length;if(!n||r.facet(d)!="\t")return t;let o=e(t,4,n);let l="";for(let e=o;e>0;)if(e>=4){l+="\t";e-=4}else{l+=" ";e--}return l+t.slice(n)}const insertNewlineContinueMarkup=({state:r,dispatch:n})=>{let o=a(r),{doc:l}=r;let i=null,s=r.changeByRange((n=>{if(!n.empty||!z.isActiveAt(r,n.from))return i={range:n};let s=n.from,m=l.lineAt(s);let a=getContext(o.resolveInner(s,-1),l);while(a.length&&a[a.length-1].from>s-m.from)a.pop();if(!a.length)return i={range:n};let f=a[a.length-1];if(f.to-f.spaceAfter.length>s-m.from)return i={range:n};let u=s>=f.to-f.spaceAfter.length&&!/\S/.test(m.text.slice(f.to));if(f.item&&u){let e=f.node.firstChild,n=f.node.getChild("ListItem","ListItem");if(e.to>=s||n&&n.to<s||m.from>0&&!/[^\s>]/.test(l.lineAt(m.from-1).text)){let e=a.length>1?a[a.length-2]:null;let r,n="";if(e&&e.item){r=m.from+e.from;n=e.marker(l,1)}else r=m.from+(e?e.to:0);let o=[{from:r,to:s,insert:n}];f.node.name=="OrderedList"&&renumberList(f.item,l,o,-2);e&&e.node.name=="OrderedList"&&renumberList(e.item,l,o);return{range:t.cursor(r+n.length),changes:o}}{let e=blankLine(a,r,m);return{range:t.cursor(s+e.length+1),changes:{from:m.from,insert:e+r.lineBreak}}}}if(f.node.name=="Blockquote"&&u&&m.from){let e=l.lineAt(m.from-1),t=/>\s*$/.exec(e.text);if(t&&t.index==f.from){let o=r.changes([{from:e.from+t.index,to:e.to},{from:m.from+f.from,to:m.to}]);return{range:n.map(o),changes:o}}}let c=[];f.node.name=="OrderedList"&&renumberList(f.item,l,c);let g=f.item&&f.item.from<m.from;let d="";if(!g||/^[\s\d.)\-+*>]*/.exec(m.text)[0].length>=f.to)for(let t=0,r=a.length-1;t<=r;t++)d+=t!=r||g?a[t].blank(t<r?e(m.text,4,a[t+1].from)-d.length:null):a[t].marker(l,1);let h=s;while(h>m.from&&/\s/.test(m.text.charAt(h-m.from-1)))h--;d=normalizeIndent(d,r);nonTightList(f.node,r.doc)&&(d=blankLine(a,r,m)+r.lineBreak+d);c.push({from:h,to:s,insert:r.lineBreak+d});return{range:t.cursor(h+d.length+1),changes:c}}));if(i)return false;n(r.update(s,{scrollIntoView:true,userEvent:"input"}));return true};function isMark(e){return e.name=="QuoteMark"||e.name=="ListMark"}function nonTightList(e,t){if(e.name!="OrderedList"&&e.name!="BulletList")return false;let r=e.firstChild,n=e.getChild("ListItem","ListItem");if(!n)return false;let o=t.lineAt(r.to),l=t.lineAt(n.from);let i=/^[\s>]*$/.test(o.text);return o.number+(i?0:1)<l.number}function blankLine(t,r,n){let o="";for(let r=0,l=t.length-2;r<=l;r++)o+=t[r].blank(r<l?e(n.text,4,t[r+1].from)-o.length:null,r<l);return normalizeIndent(o,r)}function contextNodeForDelete(e,t){let r=e.resolveInner(t,-1),n=t;if(isMark(r)){n=r.from;r=r.parent}for(let e;e=r.childBefore(n);)if(isMark(e))n=e.from;else{if(e.name!="OrderedList"&&e.name!="BulletList")break;r=e.lastChild;n=r.to}return r}const deleteMarkupBackward=({state:r,dispatch:n})=>{let o=a(r);let l=null,i=r.changeByRange((n=>{let i=n.from,{doc:s}=r;if(n.empty&&z.isActiveAt(r,n.from)){let n=s.lineAt(i);let l=getContext(contextNodeForDelete(o,i),s);if(l.length){let o=l[l.length-1];let s=o.to-o.spaceAfter.length+(o.spaceAfter?1:0);if(i-n.from>s&&!/\S/.test(n.text.slice(s,i-n.from)))return{range:t.cursor(n.from+s),changes:{from:n.from+s,to:i}};if(i-n.from==s&&(!o.item||n.from<=o.item.from||!/\S/.test(n.text.slice(0,o.to)))){let l=n.from+o.from;if(o.item&&o.node.from<o.item.from&&/\S/.test(n.text.slice(o.from,o.to))){let i=o.blank(e(n.text,4,o.to)-e(n.text,4,o.from));l==n.from&&(i=normalizeIndent(i,r));return{range:t.cursor(l+i.length),changes:{from:l,to:n.from+o.to,insert:i}}}if(l<i)return{range:t.cursor(l),changes:{from:l,to:i}}}}}return l={range:n}}));if(l)return false;n(r.update(i,{scrollIntoView:true,userEvent:"delete"}));return true};const E=[{key:"Enter",run:insertNewlineContinueMarkup},{key:"Backspace",run:deleteMarkupBackward}];const F=B({matchClosingTags:false});function markdown(e={}){let{codeLanguages:t,defaultCodeLanguage:n,addKeymap:l=true,base:{parser:i}=M,completeHTMLTags:s=true}=e;if(!(i instanceof w))throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");let m=e.extensions?[e.extensions]:[];let a,f=[F.support];if(n instanceof h){f.push(n.support);a=n.language}else n&&(a=n);let u=t||a?getCodeParser(t,a):void 0;m.push(A({codeParser:u,htmlParser:F.language.parser}));l&&f.push(r.high(o.of(E)));let c=mkLang(i.configure(m));s&&f.push(c.data.of({autocomplete:htmlTagCompletion}));return new h(c,f)}function htmlTagCompletion(e){let{state:t,pos:r}=e,n=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(r-25,r));if(!n)return null;let o=a(t).resolveInner(r,-1);while(o&&!o.type.isTop){if(o.name=="CodeBlock"||o.name=="FencedCode"||o.name=="ProcessingInstructionBlock"||o.name=="CommentBlock"||o.name=="Link"||o.name=="Image")return null;o=o.parent}return{from:r-n[0].length,to:r,options:htmlTagCompletions(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}let H=null;function htmlTagCompletions(){if(H)return H;let e=I(new p(n.create({extensions:F}),0,true));return H=e?e.options:[]}export{M as commonmarkLanguage,deleteMarkupBackward,insertNewlineContinueMarkup,markdown,E as markdownKeymap,z as markdownLanguage};
2
+
@@ -0,0 +1,2 @@
1
+ import{parser as e}from"@lezer/yaml";import{delimitedIndent as n,indentNodeProp as o,foldInside as r,foldNodeProp as t,LRLanguage as l,LanguageSupport as a}from"@codemirror/language";const i=l.define({name:"yaml",parser:e.configure({props:[o.add({Stream:e=>{for(let n=e.node.resolve(e.pos,-1);n&&n.to>=e.pos;n=n.parent){if(n.name=="BlockLiteralContent"&&n.from<n.to)return e.baseIndentFor(n);if(n.name=="BlockLiteral")return e.baseIndentFor(n)+e.unit;if(n.name=="BlockSequence"||n.name=="BlockMapping")return e.column(n.from,1);if(n.name=="QuotedLiteral")return null;if(n.name=="Literal"){let o=e.column(n.from,1);if(o==e.lineIndent(n.from,1))return o;if(n.to>e.pos)return null}}return null},FlowMapping:n({closing:"}"}),FlowSequence:n({closing:"]"})}),t.add({"FlowMapping FlowSequence":r,"BlockSequence BlockMapping BlockLiteral":(e,n)=>({from:n.doc.lineAt(e.from).to,to:e.to})})]}),languageData:{commentTokens:{line:"#"},indentOnInput:/^\s*[\]\}]$/}});function yaml(){return new a(i)}export{yaml,i as yamlLanguage};
2
+
@@ -0,0 +1,2 @@
1
+ import{NodeProp as t,Tree as e,IterMode as n,TreeFragment as r,Parser as s,NodeType as i,NodeSet as o}from"@lezer/common";import{Facet as a,EditorState as l,StateEffect as h,StateField as u,countColumn as c,RangeSet as f,combineConfig as d,RangeSetBuilder as p,Prec as g}from"@codemirror/state";import{logException as m,ViewPlugin as k,EditorView as w,Decoration as v,WidgetType as x,GutterMarker as b,gutter as y,Direction as S}from"@codemirror/view";import{tagHighlighter as T,highlightTree as P,tags as L,styleTags as C}from"@lezer/highlight";import{StyleModule as A}from"style-mod";var I;const D=new t;function defineLanguageFacet(t){return a.define({combine:t?e=>e.concat(t):void 0})}const F=new t;class Language{constructor(t,e,n=[],r=""){this.data=t;this.name=r;l.prototype.hasOwnProperty("tree")||Object.defineProperty(l.prototype,"tree",{get(){return syntaxTree(this)}});this.parser=e;this.extension=[M.of(this),l.languageData.of(((t,e,n)=>{let r=topNodeAt(t,e,n),s=r.type.prop(D);if(!s)return[];let i=t.facet(s),o=r.type.prop(F);if(o){let s=r.resolve(e-r.from,n);for(let e of o)if(e.test(s,t)){let n=t.facet(e.facet);return e.type=="replace"?n:n.concat(i)}}return i}))].concat(n)}isActiveAt(t,e,n=-1){return topNodeAt(t,e,n).type.prop(D)==this.data}findRegions(n){let r=n.facet(M);if((r===null||r===void 0?void 0:r.data)==this.data)return[{from:0,to:n.doc.length}];if(!r||!r.allowsNesting)return[];let s=[];let explore=(n,r)=>{if(n.prop(D)==this.data){s.push({from:r,to:r+n.length});return}let i=n.prop(t.mounted);if(i){if(i.tree.prop(D)==this.data){if(i.overlay)for(let t of i.overlay)s.push({from:t.from+r,to:t.to+r});else s.push({from:r,to:r+n.length});return}if(i.overlay){let t=s.length;explore(i.tree,i.overlay[0].from+r);if(s.length>t)return}}for(let t=0;t<n.children.length;t++){let s=n.children[t];s instanceof e&&explore(s,n.positions[t]+r)}};explore(syntaxTree(n),0);return s}get allowsNesting(){return true}}Language.setState=h.define();function topNodeAt(t,e,r){let s=t.facet(M),i=syntaxTree(t).topNode;if(!s||s.allowsNesting)for(let t=i;t;t=t.enter(e,r,n.ExcludeBuffers))t.type.isTop&&(i=t);return i}class LRLanguage extends Language{constructor(t,e,n){super(t,e,[],n);this.parser=e}static define(t){let e=defineLanguageFacet(t.languageData);return new LRLanguage(e,t.parser.configure({props:[D.add((t=>t.isTop?e:void 0))]}),t.name)}configure(t,e){return new LRLanguage(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function syntaxTree(t){let n=t.field(Language.state,false);return n?n.tree:e.empty}function ensureSyntaxTree(t,e,n=50){var r;let s=(r=t.field(Language.state,false))===null||r===void 0?void 0:r.context;if(!s)return null;let i=s.viewport;s.updateViewport({from:0,to:e});let o=s.isDone(e)||s.work(n,e)?s.tree:null;s.updateViewport(i);return o}function syntaxTreeAvailable(t,e=t.doc.length){var n;return((n=t.field(Language.state,false))===null||n===void 0?void 0:n.context.isDone(e))||false}function forceParsing(t,e=t.viewport.to,n=100){let r=ensureSyntaxTree(t.state,e,n);r!=syntaxTree(t.state)&&t.dispatch({});return!!r}function syntaxParserRunning(t){var e;return((e=t.plugin(R))===null||e===void 0?void 0:e.isWorking())||false}class DocInput{constructor(t){this.doc=t;this.cursorPos=0;this.string="";this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){this.string=this.cursor.next(t-this.cursorPos).value;this.cursorPos=t+this.string.length;return this.cursorPos-this.string.length}chunk(t){this.syncTo(t);return this.string}get lineChunks(){return true}read(t,e){let n=this.cursorPos-this.string.length;return t<n||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-n,e-n)}}let O=null;class ParseContext{constructor(t,e,n=[],r,s,i,o,a){this.parser=t;this.state=e;this.fragments=n;this.tree=r;this.treeLen=s;this.viewport=i;this.skipped=o;this.scheduleOn=a;this.parse=null;this.tempSkipped=[]}static create(t,n,r){return new ParseContext(t,n,[],e.empty,0,r,[],null)}startParse(){return this.parser.startParse(new DocInput(this.state.doc),this.fragments)}work(t,n){n!=null&&n>=this.state.doc.length&&(n=void 0);if(this.tree!=e.empty&&this.isDone(n!==null&&n!==void 0?n:this.state.doc.length)){this.takeTree();return true}return this.withContext((()=>{var e;if(typeof t=="number"){let e=Date.now()+t;t=()=>Date.now()>e}this.parse||(this.parse=this.startParse());n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);for(;;){let s=this.parse.advance();if(s){this.fragments=this.withoutTempSkipped(r.addTree(s,this.fragments,this.parse.stoppedAt!=null));this.treeLen=(e=this.parse.stoppedAt)!==null&&e!==void 0?e:this.state.doc.length;this.tree=s;this.parse=null;if(!(this.treeLen<(n!==null&&n!==void 0?n:this.state.doc.length)))return true;this.parse=this.startParse()}if(t())return false}}))}takeTree(){let t,e;if(this.parse&&(t=this.parse.parsedPos)>=this.treeLen){(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t);this.withContext((()=>{while(!(e=this.parse.advance()));}));this.treeLen=t;this.tree=e;this.fragments=this.withoutTempSkipped(r.addTree(this.tree,this.fragments,true));this.parse=null}}withContext(t){let e=O;O=this;try{return t()}finally{O=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=cutFragments(t,e.from,e.to);return t}changes(t,n){let{fragments:s,tree:i,treeLen:o,viewport:a,skipped:l}=this;this.takeTree();if(!t.empty){let n=[];t.iterChangedRanges(((t,e,r,s)=>n.push({fromA:t,toA:e,fromB:r,toB:s})));s=r.applyChanges(s,n);i=e.empty;o=0;a={from:t.mapPos(a.from,-1),to:t.mapPos(a.to,1)};if(this.skipped.length){l=[];for(let e of this.skipped){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);n<r&&l.push({from:n,to:r})}}}return new ParseContext(this.parser,n,s,i,o,a,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return false;this.viewport=t;let e=this.skipped.length;for(let e=0;e<this.skipped.length;e++){let{from:n,to:r}=this.skipped[e];if(n<t.to&&r>t.from){this.fragments=cutFragments(this.fragments,n,r);this.skipped.splice(e--,1)}}if(this.skipped.length>=e)return false;this.reset();return true}reset(){if(this.parse){this.takeTree();this.parse=null}}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends s{createParse(n,r,s){let o=s[0].from,a=s[s.length-1].to;let l={parsedPos:o,advance(){let n=O;if(n){for(let t of s)n.tempSkipped.push(t);t&&(n.scheduleOn=n.scheduleOn?Promise.all([n.scheduleOn,t]):t)}this.parsedPos=a;return new e(i.none,[],[],a-o)},stoppedAt:null,stopAt(){}};return l}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return O}}function cutFragments(t,e,n){return r.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}class LanguageState{constructor(t){this.context=t;this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state);let n=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);e.work(20,n)||e.takeTree();return new LanguageState(e)}static init(t){let e=Math.min(3e3,t.doc.length);let n=ParseContext.create(t.facet(M).parser,t,{from:0,to:e});n.work(20,e)||n.takeTree();return new LanguageState(n)}}Language.state=u.define({create:LanguageState.init,update(t,e){for(let t of e.effects)if(t.is(Language.setState))return t.value;return e.startState.facet(M)!=e.state.facet(M)?LanguageState.init(e.state):t.apply(e)}});let requestIdle=t=>{let e=setTimeout((()=>t()),500);return()=>clearTimeout(e)};typeof requestIdleCallback!="undefined"&&(requestIdle=t=>{let e=-1,n=setTimeout((()=>{e=requestIdleCallback(t,{timeout:400})}),100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});const B=typeof navigator!="undefined"&&((I=navigator.scheduling)===null||I===void 0?void 0:I.isInputPending)?()=>navigator.scheduling.isInputPending():null;const R=k.fromClass(class ParseWorker{constructor(t){this.view=t;this.working=null;this.workScheduled=0;this.chunkEnd=-1;this.chunkBudget=-1;this.work=this.work.bind(this);this.scheduleWork()}update(t){let e=this.view.state.field(Language.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork();if(t.docChanged||t.selectionSet){this.view.hasFocus&&(this.chunkBudget+=50);this.scheduleWork()}this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Language.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=requestIdle(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)){this.chunkEnd=e+3e4;this.chunkBudget=3e3}if(this.chunkBudget<=0)return;let{state:n,viewport:{to:r}}=this.view,s=n.field(Language.state);if(s.tree==s.context.tree&&s.context.isDone(r+1e5))return;let i=Date.now()+Math.min(this.chunkBudget,100,t&&!B?Math.max(25,t.timeRemaining()-5):1e9);let o=s.context.treeLen<r&&n.doc.length>r+1e3;let a=s.context.work((()=>B&&B()||Date.now()>i),r+(o?0:1e5));this.chunkBudget-=Date.now()-e;if(a||this.chunkBudget<=0){s.context.takeTree();this.view.dispatch({effects:Language.setState.of(new LanguageState(s.context))})}this.chunkBudget>0&&!(a&&!o)&&this.scheduleWork();this.checkAsyncSchedule(s.context)}checkAsyncSchedule(t){if(t.scheduleOn){this.workScheduled++;t.scheduleOn.then((()=>this.scheduleWork())).catch((t=>m(this.view.state,t))).then((()=>this.workScheduled--));t.scheduleOn=null}}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}});const M=a.define({combine(t){return t.length?t[0]:null},enables:t=>[Language.state,R,w.contentAttributes.compute([t],(e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}}))]});class LanguageSupport{constructor(t,e=[]){this.language=t;this.support=e;this.extension=[t,e]}}class LanguageDescription{constructor(t,e,n,r,s,i=void 0){this.name=t;this.alias=e;this.extensions=n;this.filename=r;this.loadFunc=s;this.support=i;this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then((t=>this.support=t),(t=>{this.loading=null;throw t})))}static of(t){let{load:e,support:n}=t;if(!e){if(!n)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");e=()=>Promise.resolve(n)}return new LanguageDescription(t.name,(t.alias||[]).concat(t.name).map((t=>t.toLowerCase())),t.extensions||[],t.filename,e,n)}static matchFilename(t,e){for(let n of t)if(n.filename&&n.filename.test(e))return n;let n=/\.([^.]+)$/.exec(e);if(n)for(let e of t)if(e.extensions.indexOf(n[1])>-1)return e;return null}static matchLanguageName(t,e,n=true){e=e.toLowerCase();for(let n of t)if(n.alias.some((t=>t==e)))return n;if(n)for(let n of t)for(let t of n.alias){let r=e.indexOf(t);if(r>-1&&(t.length>2||!/\w/.test(e[r-1])&&!/\w/.test(e[r+t.length])))return n}return null}}const N=a.define();const E=a.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some((t=>t!=e[0])))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function getIndentUnit(t){let e=t.facet(E);return e.charCodeAt(0)==9?t.tabSize*e.length:e.length}function indentString(t,e){let n="",r=t.tabSize,s=t.facet(E)[0];if(s=="\t"){while(e>=r){n+="\t";e-=r}s=" "}for(let t=0;t<e;t++)n+=s;return n}function getIndentation(t,e){t instanceof l&&(t=new IndentContext(t));for(let n of t.state.facet(N)){let r=n(t,e);if(r!==void 0)return r}let n=syntaxTree(t.state);return n.length>=e?syntaxIndentation(t,n,e):null}function indentRange(t,e,n){let r=Object.create(null);let s=new IndentContext(t,{overrideIndentation:t=>{var e;return(e=r[t])!==null&&e!==void 0?e:-1}});let i=[];for(let o=e;o<=n;){let e=t.doc.lineAt(o);o=e.to+1;let n=getIndentation(s,e.from);if(n==null)continue;/\S/.test(e.text)||(n=0);let a=/^\s*/.exec(e.text)[0];let l=indentString(t,n);if(a!=l){r[e.from]=n;i.push({from:e.from,to:e.from+a.length,insert:l})}}return t.changes(i)}class IndentContext{constructor(t,e={}){this.state=t;this.options=e;this.unit=getIndentUnit(t)}lineAt(t,e=1){let n=this.state.doc.lineAt(t);let{simulateBreak:r,simulateDoubleBreak:s}=this.options;return r!=null&&r>=n.from&&r<=n.to?s&&r==t?{text:"",from:t}:(e<0?r<t:r<=t)?{text:n.text.slice(r-n.from),from:r}:{text:n.text.slice(0,r-n.from),from:n.from}:n}textAfterPos(t,e=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:n,from:r}=this.lineAt(t,e);return n.slice(t-r,Math.min(n.length,t+100-r))}column(t,e=1){let{text:n,from:r}=this.lineAt(t,e);let s=this.countColumn(n,t-r);let i=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;i>-1&&(s+=i-this.countColumn(n,n.search(/\S|$/)));return s}countColumn(t,e=t.length){return c(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:n,from:r}=this.lineAt(t,e);let s=this.options.overrideIndentation;if(s){let t=s(r);if(t>-1)return t}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const H=new t;function syntaxIndentation(t,e,n){let r=e.resolveStack(n);let s=r.node.enterUnfinishedNodesBefore(n);if(s!=r.node){let t=[];for(let e=s;e!=r.node;e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)r={node:t[e],next:r}}return indentFor(r,t,n)}function indentFor(t,e,n){for(let r=t;r;r=r.next){let t=indentStrategy(r.node);if(t)return t(TreeIndentContext.create(e,n,r))}return 0}function ignoreClosed(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}function indentStrategy(e){let n=e.type.prop(H);if(n)return n;let r,s=e.firstChild;if(s&&(r=s.type.prop(t.closedBy))){let t=e.lastChild,n=t&&r.indexOf(t.name)>-1;return e=>delimitedStrategy(e,true,1,void 0,n&&!ignoreClosed(e)?t.from:void 0)}return e.parent==null?topIndent:null}function topIndent(){return 0}class TreeIndentContext extends IndentContext{constructor(t,e,n){super(t.state,t.options);this.base=t;this.pos=e;this.context=n}get node(){return this.context.node}static create(t,e,n){return new TreeIndentContext(t,e,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let n=t.resolve(e.from);while(n.parent&&n.parent.from==n.from)n=n.parent;if(isParent(n,t))break;e=this.state.doc.lineAt(n.from)}return this.lineIndent(e.from)}continue(){return indentFor(this.context.next,this.base,this.pos)}}function isParent(t,e){for(let n=e;n;n=n.parent)if(t==n)return true;return false}function bracketedAligned(t){let e=t.node;let n=e.childAfter(e.from),r=e.lastChild;if(!n)return null;let s=t.options.simulateBreak;let i=t.state.doc.lineAt(n.from);let o=s==null||s<=i.from?i.to:Math.min(i.to,s);for(let t=n.to;;){let s=e.childAfter(t);if(!s||s==r)return null;if(!s.type.isSkipped)return s.from<o?n:null;t=s.to}}function delimitedIndent({closing:t,align:e=true,units:n=1}){return r=>delimitedStrategy(r,e,n,t)}function delimitedStrategy(t,e,n,r,s){let i=t.textAfter,o=i.match(/^\s*/)[0].length;let a=r&&i.slice(o,o+r.length)==r||s==t.pos+o;let l=e?bracketedAligned(t):null;return l?a?t.column(l.from):t.column(l.to):t.baseIndent+(a?0:t.unit*n)}const flatIndent=t=>t.baseIndent;function continuedIndent({except:t,units:e=1}={}){return n=>{let r=t&&t.test(n.textAfter);return n.baseIndent+(r?0:e*n.unit)}}const U=200;function indentOnInput(){return l.transactionFilter.of((t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let n=t.newDoc,{head:r}=t.newSelection.main,s=n.lineAt(r);if(r>s.from+U)return t;let i=n.sliceString(s.from,r);if(!e.some((t=>t.test(i))))return t;let{state:o}=t,a=-1,l=[];for(let{head:t}of o.selection.ranges){let e=o.doc.lineAt(t);if(e.from==a)continue;a=e.from;let n=getIndentation(o,e.from);if(n==null)continue;let r=/^\s*/.exec(e.text)[0];let s=indentString(o,n);r!=s&&l.push({from:e.from,to:e.from+r.length,insert:s})}return l.length?[t,{changes:l,sequential:true}]:t}))}const W=a.define();const j=new t;function foldInside(t){let e=t.firstChild,n=t.lastChild;return e&&e.to<n.from?{from:e.to,to:n.type.isError?t.to:n.from}:null}function syntaxFolding(t,e,n){let r=syntaxTree(t);if(r.length<n)return null;let s=r.resolveStack(n,1);let i=null;for(let o=s;o;o=o.next){let s=o.node;if(s.to<=n||s.from>n)continue;if(i&&s.from<e)break;let a=s.type.prop(j);if(a&&(s.to<r.length-50||r.length==t.doc.length||!isUnfinished(s))){let r=a(s,t);r&&r.from<=n&&r.from>=e&&r.to>n&&(i=r)}}return i}function isUnfinished(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function foldable(t,e,n){for(let r of t.facet(W)){let s=r(t,e,n);if(s)return s}return syntaxFolding(t,e,n)}function mapRange(t,e){let n=e.mapPos(t.from,1),r=e.mapPos(t.to,-1);return n>=r?void 0:{from:n,to:r}}const z=h.define({map:mapRange});const V=h.define({map:mapRange});function selectedLines(t){let e=[];for(let{head:n}of t.state.selection.ranges)e.some((t=>t.from<=n&&t.to>=n))||e.push(t.lineBlockAt(n));return e}const $=u.define({create(){return v.none},update(t,e){t=t.map(e.changes);for(let n of e.effects)if(n.is(z)&&!foldExists(t,n.value.from,n.value.to)){let{preparePlaceholder:r}=e.state.facet(J);let s=r?v.replace({widget:new PreparedFoldWidget(r(e.state,n.value))}):_;t=t.update({add:[s.range(n.value.from,n.value.to)]})}else n.is(V)&&(t=t.update({filter:(t,e)=>n.value.from!=t||n.value.to!=e,filterFrom:n.value.from,filterTo:n.value.to}));if(e.selection){let n=false,{head:r}=e.selection.main;t.between(r,r,((t,e)=>{t<r&&e>r&&(n=true)}));n&&(t=t.update({filterFrom:r,filterTo:r,filter:(t,e)=>e<=r||t>=r}))}return t},provide:t=>w.decorations.from(t),toJSON(t,e){let n=[];t.between(0,e.doc.length,((t,e)=>{n.push(t,e)}));return n},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let n=0;n<t.length;){let r=t[n++],s=t[n++];if(typeof r!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");e.push(_.range(r,s))}return v.set(e,true)}});function foldedRanges(t){return t.field($,false)||f.empty}function findFold(t,e,n){var r;let s=null;(r=t.field($,false))===null||r===void 0?void 0:r.between(e,n,((t,e)=>{(!s||s.from>t)&&(s={from:t,to:e})}));return s}function foldExists(t,e,n){let r=false;t.between(e,e,((t,s)=>{t==e&&s==n&&(r=true)}));return r}function maybeEnable(t,e){return t.field($,false)?e:e.concat(h.appendConfig.of(codeFolding()))}const foldCode=t=>{for(let e of selectedLines(t)){let n=foldable(t.state,e.from,e.to);if(n){t.dispatch({effects:maybeEnable(t.state,[z.of(n),announceFold(t,n)])});return true}}return false};const unfoldCode=t=>{if(!t.state.field($,false))return false;let e=[];for(let n of selectedLines(t)){let r=findFold(t.state,n.from,n.to);r&&e.push(V.of(r),announceFold(t,r,false))}e.length&&t.dispatch({effects:e});return e.length>0};function announceFold(t,e,n=true){let r=t.state.doc.lineAt(e.from).number,s=t.state.doc.lineAt(e.to).number;return w.announce.of(`${t.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${t.state.phrase("to")} ${s}.`)}const foldAll=t=>{let{state:e}=t,n=[];for(let r=0;r<e.doc.length;){let s=t.lineBlockAt(r),i=foldable(e,s.from,s.to);i&&n.push(z.of(i));r=(i?t.lineBlockAt(i.to):s).to+1}n.length&&t.dispatch({effects:maybeEnable(t.state,n)});return!!n.length};const unfoldAll=t=>{let e=t.state.field($,false);if(!e||!e.size)return false;let n=[];e.between(0,t.state.doc.length,((t,e)=>{n.push(V.of({from:t,to:e}))}));t.dispatch({effects:n});return true};function foldableContainer(t,e){for(let n=e;;){let r=foldable(t.state,n.from,n.to);if(r&&r.to>e.from)return r;if(!n.from)return null;n=t.lineBlockAt(n.from-1)}}const toggleFold=t=>{let e=[];for(let n of selectedLines(t)){let r=findFold(t.state,n.from,n.to);if(r)e.push(V.of(r),announceFold(t,r,false));else{let r=foldableContainer(t,n);r&&e.push(z.of(r),announceFold(t,r))}}e.length>0&&t.dispatch({effects:maybeEnable(t.state,e)});return!!e.length};const G=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:foldCode},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:unfoldCode},{key:"Ctrl-Alt-[",run:foldAll},{key:"Ctrl-Alt-]",run:unfoldAll}];const q={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"};const J=a.define({combine(t){return d(t,q)}});function codeFolding(t){let e=[$,Q];t&&e.push(J.of(t));return e}function widgetToDOM(t,e){let{state:n}=t,r=n.facet(J);let onclick=e=>{let n=t.lineBlockAt(t.posAtDOM(e.target));let r=findFold(t.state,n.from,n.to);r&&t.dispatch({effects:V.of(r)});e.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(t,onclick,e);let s=document.createElement("span");s.textContent=r.placeholderText;s.setAttribute("aria-label",n.phrase("folded code"));s.title=n.phrase("unfold");s.className="cm-foldPlaceholder";s.onclick=onclick;return s}const _=v.replace({widget:new class extends x{toDOM(t){return widgetToDOM(t,null)}}});class PreparedFoldWidget extends x{constructor(t){super();this.value=t}eq(t){return this.value==t.value}toDOM(t){return widgetToDOM(t,this.value)}}const K={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>false};class FoldMarker extends b{constructor(t,e){super();this.config=t;this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");e.textContent=this.open?this.config.openText:this.config.closedText;e.title=t.state.phrase(this.open?"Fold line":"Unfold line");return e}}function foldGutter(t={}){let e=Object.assign(Object.assign({},K),t);let n=new FoldMarker(e,true),r=new FoldMarker(e,false);let s=k.fromClass(class{constructor(t){this.from=t.viewport.from;this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(M)!=t.state.facet(M)||t.startState.field($,false)!=t.state.field($,false)||syntaxTree(t.startState)!=syntaxTree(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new p;for(let s of t.viewportLineBlocks){let i=findFold(t.state,s.from,s.to)?r:foldable(t.state,s.from,s.to)?n:null;i&&e.add(s.from,s.from,i)}return e.finish()}});let{domEventHandlers:i}=e;return[s,y({class:"cm-foldGutter",markers(t){var e;return((e=t.plugin(s))===null||e===void 0?void 0:e.markers)||f.empty},initialSpacer(){return new FoldMarker(e,false)},domEventHandlers:Object.assign(Object.assign({},i),{click:(t,e,n)=>{if(i.click&&i.click(t,e,n))return true;let r=findFold(t.state,e.from,e.to);if(r){t.dispatch({effects:V.of(r)});return true}let s=foldable(t.state,e.from,e.to);if(s){t.dispatch({effects:z.of(s)});return true}return false}})}),codeFolding()]}const Q=w.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 HighlightStyle{constructor(t,e){this.specs=t;let n;function def(t){let e=A.newName();(n||(n=Object.create(null)))["."+e]=t;return e}const r=typeof e.all=="string"?e.all:e.all?def(e.all):void 0;const s=e.scope;this.scope=s instanceof Language?t=>t.prop(D)==s.data:s?t=>t==s:void 0;this.style=T(t.map((t=>({tag:t.tag,class:t.class||def(Object.assign({},t,{tag:null}))}))),{all:r}).style;this.module=n?new A(n):null;this.themeType=e.themeType}static define(t,e){return new HighlightStyle(t,e||{})}}const X=a.define();const Y=a.define({combine(t){return t.length?[t[0]]:null}});function getHighlighters(t){let e=t.facet(X);return e.length?e:t.facet(Y)}function syntaxHighlighting(t,e){let n,r=[Z];if(t instanceof HighlightStyle){t.module&&r.push(w.styleModule.of(t.module));n=t.themeType}(e===null||e===void 0?void 0:e.fallback)?r.push(Y.of(t)):n?r.push(X.computeN([w.darkTheme],(e=>e.facet(w.darkTheme)==(n=="dark")?[t]:[]))):r.push(X.of(t));return r}function highlightingFor(t,e,n){let r=getHighlighters(t);let s=null;if(r)for(let t of r)if(!t.scope||n&&t.scope(n)){let n=t.style(e);n&&(s=s?s+" "+n:n)}return s}class TreeHighlighter{constructor(t){this.markCache=Object.create(null);this.tree=syntaxTree(t.state);this.decorations=this.buildDeco(t,getHighlighters(t.state));this.decoratedTo=t.viewport.to}update(t){let e=syntaxTree(t.state),n=getHighlighters(t.state);let r=n!=getHighlighters(t.startState);let{viewport:s}=t.view,i=t.changes.mapPos(this.decoratedTo,1);if(e.length<s.to&&!r&&e.type==this.tree.type&&i>=s.to){this.decorations=this.decorations.map(t.changes);this.decoratedTo=i}else if(e!=this.tree||t.viewportChanged||r){this.tree=e;this.decorations=this.buildDeco(t.view,n);this.decoratedTo=s.to}}buildDeco(t,e){if(!e||!this.tree.length)return v.none;let n=new p;for(let{from:r,to:s}of t.visibleRanges)P(this.tree,e,((t,e,r)=>{n.add(t,e,this.markCache[r]||(this.markCache[r]=v.mark({class:r})))}),r,s);return n.finish()}}const Z=g.high(k.fromClass(TreeHighlighter,{decorations:t=>t.decorations}));const tt=HighlightStyle.define([{tag:L.meta,color:"#404740"},{tag:L.link,textDecoration:"underline"},{tag:L.heading,textDecoration:"underline",fontWeight:"bold"},{tag:L.emphasis,fontStyle:"italic"},{tag:L.strong,fontWeight:"bold"},{tag:L.strikethrough,textDecoration:"line-through"},{tag:L.keyword,color:"#708"},{tag:[L.atom,L.bool,L.url,L.contentSeparator,L.labelName],color:"#219"},{tag:[L.literal,L.inserted],color:"#164"},{tag:[L.string,L.deleted],color:"#a11"},{tag:[L.regexp,L.escape,L.special(L.string)],color:"#e40"},{tag:L.definition(L.variableName),color:"#00f"},{tag:L.local(L.variableName),color:"#30a"},{tag:[L.typeName,L.namespace],color:"#085"},{tag:L.className,color:"#167"},{tag:[L.special(L.variableName),L.macroName],color:"#256"},{tag:L.definition(L.propertyName),color:"#00c"},{tag:L.comment,color:"#940"},{tag:L.invalid,color:"#f00"}]);const et=w.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}});const nt=1e4,rt="()[]{}";const st=a.define({combine(t){return d(t,{afterCursor:true,brackets:rt,maxScanDistance:nt,renderMatch:defaultRenderMatch})}});const it=v.mark({class:"cm-matchingBracket"}),ot=v.mark({class:"cm-nonmatchingBracket"});function defaultRenderMatch(t){let e=[];let n=t.matched?it:ot;e.push(n.range(t.start.from,t.start.to));t.end&&e.push(n.range(t.end.from,t.end.to));return e}const at=u.define({create(){return v.none},update(t,e){if(!e.docChanged&&!e.selection)return t;let n=[];let r=e.state.facet(st);for(let t of e.state.selection.ranges){if(!t.empty)continue;let s=matchBrackets(e.state,t.head,-1,r)||t.head>0&&matchBrackets(e.state,t.head-1,1,r)||r.afterCursor&&(matchBrackets(e.state,t.head,1,r)||t.head<e.state.doc.length&&matchBrackets(e.state,t.head+1,-1,r));s&&(n=n.concat(r.renderMatch(s,e.state)))}return v.set(n,true)},provide:t=>w.decorations.from(t)});const lt=[at,et];function bracketMatching(t={}){return[st.of(t),lt]}const ht=new t;function matchingNodes(e,n,r){let s=e.prop(n<0?t.openedBy:t.closedBy);if(s)return s;if(e.name.length==1){let t=r.indexOf(e.name);if(t>-1&&t%2==(n<0?1:0))return[r[t+n]]}return null}function findHandle(t){let e=t.type.prop(ht);return e?e(t.node):t}function matchBrackets(t,e,n,r={}){let s=r.maxScanDistance||nt,i=r.brackets||rt;let o=syntaxTree(t),a=o.resolveInner(e,n);for(let r=a;r;r=r.parent){let s=matchingNodes(r.type,n,i);if(s&&r.from<r.to){let o=findHandle(r);if(o&&(n>0?e>=o.from&&e<o.to:e>o.from&&e<=o.to))return matchMarkedBrackets(t,e,n,r,o,s,i)}}return matchPlainBrackets(t,e,n,o,a.type,s,i)}function matchMarkedBrackets(t,e,n,r,s,i,o){let a=r.parent,l={from:s.from,to:s.to};let h=0,u=a===null||a===void 0?void 0:a.cursor();if(u&&(n<0?u.childBefore(r.from):u.childAfter(r.to)))do{if(n<0?u.to<=r.from:u.from>=r.to){if(h==0&&i.indexOf(u.type.name)>-1&&u.from<u.to){let t=findHandle(u);return{start:l,end:t?{from:t.from,to:t.to}:void 0,matched:true}}if(matchingNodes(u.type,n,o))h++;else if(matchingNodes(u.type,-n,o)){if(h==0){let t=findHandle(u);return{start:l,end:t&&t.from<t.to?{from:t.from,to:t.to}:void 0,matched:false}}h--}}}while(n<0?u.prevSibling():u.nextSibling());return{start:l,matched:false}}function matchPlainBrackets(t,e,n,r,s,i,o){let a=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1);let l=o.indexOf(a);if(l<0||l%2==0!=n>0)return null;let h={from:n<0?e-1:e,to:n>0?e+1:e};let u=t.doc.iterRange(e,n>0?t.doc.length:0),c=0;for(let t=0;!u.next().done&&t<=i;){let i=u.value;n<0&&(t+=i.length);let a=e+t*n;for(let t=n>0?0:i.length-1,e=n>0?i.length:-1;t!=e;t+=n){let e=o.indexOf(i[t]);if(!(e<0||r.resolveInner(a+t,1).type!=s))if(e%2==0==n>0)c++;else{if(c==1)return{start:h,end:{from:a+t,to:a+t+1},matched:e>>1==l>>1};c--}}n>0&&(t+=i.length)}return u.done?{start:h,matched:false}:null}function countCol(t,e,n,r=0,s=0){if(e==null){e=t.search(/[^\s\u00a0]/);e==-1&&(e=t.length)}let i=s;for(let s=r;s<e;s++)t.charCodeAt(s)==9?i+=n-i%n:i++;return i}class StringStream{constructor(t,e,n,r){this.string=t;this.tabSize=e;this.indentUnit=n;this.overrideIndent=r;this.pos=0;this.start=0;this.lastColumnPos=0;this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(t){let e=this.string.charAt(this.pos);let n;n=typeof t=="string"?e==t:e&&(t instanceof RegExp?t.test(e):t(e));if(n){++this.pos;return e}}eatWhile(t){let e=this.pos;while(this.eat(t));return this.pos>e}eatSpace(){let t=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos)))++this.pos;return this.pos>t}skipToEnd(){this.pos=this.string.length}skipTo(t){let e=this.string.indexOf(t,this.pos);if(e>-1){this.pos=e;return true}}backUp(t){this.pos-=t}column(){if(this.lastColumnPos<this.start){this.lastColumnValue=countCol(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue);this.lastColumnPos=this.start}return this.lastColumnValue}indentation(){var t;return(t=this.overrideIndent)!==null&&t!==void 0?t:countCol(this.string,null,this.tabSize)}match(t,e,n){if(typeof t=="string"){let cased=t=>n?t.toLowerCase():t;let r=this.string.substr(this.pos,t.length);if(cased(r)==cased(t)){e!==false&&(this.pos+=t.length);return true}return null}{let n=this.string.slice(this.pos).match(t);if(n&&n.index>0)return null;n&&e!==false&&(this.pos+=n[0].length);return n}}current(){return this.string.slice(this.start,this.pos)}}function fullParser(t){return{name:t.name||"",token:t.token,blankLine:t.blankLine||(()=>{}),startState:t.startState||(()=>true),copyState:t.copyState||defaultCopyState,indent:t.indent||(()=>null),languageData:t.languageData||{},tokenTable:t.tokenTable||ct}}function defaultCopyState(t){if(typeof t!="object")return t;let e={};for(let n in t){let r=t[n];e[n]=r instanceof Array?r.slice():r}return e}const ut=new WeakMap;class StreamLanguage extends Language{constructor(e){let n=defineLanguageFacet(e.languageData);let r,i=fullParser(e);let o=new class extends s{createParse(t,e,n){return new Parse(r,t,e,n)}};super(n,o,[N.of(((t,e)=>this.getIndent(t,e)))],e.name);this.topNode=docID(n);r=this;this.streamParser=i;this.stateAfter=new t({perNode:true});this.tokenTable=e.tokenTable?new TokenTable(i.tokenTable):kt}static define(t){return new StreamLanguage(t)}getIndent(t,e){let n=syntaxTree(t.state),r=n.resolve(e);while(r&&r.type!=this.topNode)r=r.parent;if(!r)return null;let s;let{overrideIndentation:i}=t.options;if(i){s=ut.get(t.state);s!=null&&s<e-1e4&&(s=void 0)}let o,a,l=findState(this,n,0,r.from,s!==null&&s!==void 0?s:e);if(l){a=l.state;o=l.pos+1}else{a=this.streamParser.startState(t.unit);o=0}if(e-o>1e4)return null;while(o<e){let n=t.state.doc.lineAt(o),r=Math.min(e,n.to);if(n.length){let e=i?i(n.from):-1;let s=new StringStream(n.text,t.state.tabSize,t.unit,e<0?void 0:e);while(s.pos<r-n.from)readToken(this.streamParser.token,s,a)}else this.streamParser.blankLine(a,t.unit);if(r==e)break;o=n.to+1}let h=t.lineAt(e);i&&s==null&&ut.set(t.state,h.from);return this.streamParser.indent(a,/^\s*(.*)/.exec(h.text)[1],t)}get allowsNesting(){return false}}function findState(t,n,r,s,i){let o=r>=s&&r+n.length<=i&&n.prop(t.stateAfter);if(o)return{state:t.streamParser.copyState(o),pos:r+n.length};for(let o=n.children.length-1;o>=0;o--){let a=n.children[o],l=r+n.positions[o];let h=a instanceof e&&l<i&&findState(t,a,l,s,i);if(h)return h}return null}function cutTree(t,n,r,s,i){if(i&&r<=0&&s>=n.length)return n;i||n.type!=t.topNode||(i=true);for(let o=n.children.length-1;o>=0;o--){let a,l=n.positions[o],h=n.children[o];if(l<s&&h instanceof e){if(!(a=cutTree(t,h,r-l,s-l,i)))break;return i?new e(n.type,n.children.slice(0,o).concat(a),n.positions.slice(0,o+1),l+a.length):a}}return null}function findStartInFragments(t,n,r,s){for(let e of n){let n=e.from+(e.openStart?25:0),s=e.to-(e.openEnd?25:0);let i,o=n<=r&&s>r&&findState(t,e.tree,0-e.offset,r,s);if(o&&(i=cutTree(t,e.tree,r+e.offset,o.pos+e.offset,false)))return{state:o.state,tree:i}}return{state:t.streamParser.startState(s?getIndentUnit(s):4),tree:e.empty}}class Parse{constructor(t,e,n,r){this.lang=t;this.input=e;this.fragments=n;this.ranges=r;this.stoppedAt=null;this.chunks=[];this.chunkPos=[];this.chunk=[];this.chunkReused=void 0;this.rangeIndex=0;this.to=r[r.length-1].to;let s=ParseContext.get(),i=r[0].from;let{state:o,tree:a}=findStartInFragments(t,n,i,s===null||s===void 0?void 0:s.state);this.state=o;this.parsedPos=this.chunkStart=i+a.length;for(let t=0;t<a.children.length;t++){this.chunks.push(a.children[t]);this.chunkPos.push(a.positions[t])}if(s&&this.parsedPos<s.viewport.from-1e5){this.state=this.lang.streamParser.startState(getIndentUnit(s.state));s.skipUntilInView(this.parsedPos,s.viewport.from);this.parsedPos=s.viewport.from}this.moveRangeIndex()}advance(){let t=ParseContext.get();let e=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt);let n=Math.min(e,this.chunkStart+2048);t&&(n=Math.min(n,t.viewport.to));while(this.parsedPos<n)this.parseLine(t);this.chunkStart<this.parsedPos&&this.finishChunk();if(this.parsedPos>=e)return this.finish();if(t&&this.parsedPos>=t.viewport.to){t.skipUntilInView(this.parsedPos,e);return this.finish()}return null}stopAt(t){this.stoppedAt=t}lineAfter(t){let e=this.input.chunk(t);if(this.input.lineChunks)e=="\n"&&(e="");else{let t=e.indexOf("\n");t>-1&&(e=e.slice(0,t))}return t+e.length<=this.to?e:e.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,e=this.lineAfter(t),n=t+e.length;for(let t=this.rangeIndex;;){let r=this.ranges[t].to;if(r>=n)break;e=e.slice(0,r-(n-e.length));t++;if(t==this.ranges.length)break;let s=this.ranges[t].from;let i=this.lineAfter(s);e+=i;n=s+i.length}return{line:e,end:n}}skipGapsTo(t,e,n){for(;;){let r=this.ranges[this.rangeIndex].to,s=t+e;if(n>0?r>s:r>=s)break;let i=this.ranges[++this.rangeIndex].from;e+=i-r}return e}moveRangeIndex(){while(this.ranges[this.rangeIndex].to<this.parsedPos)this.rangeIndex++}emitToken(t,e,n,r,s){if(this.ranges.length>1){s=this.skipGapsTo(e,s,1);e+=s;let t=this.chunk.length;s=this.skipGapsTo(n,s,-1);n+=s;r+=this.chunk.length-t}this.chunk.push(t,e,n,r);return s}parseLine(t){let{line:e,end:n}=this.nextLine(),r=0,{streamParser:s}=this.lang;let i=new StringStream(e,t?t.state.tabSize:4,t?getIndentUnit(t.state):2);if(i.eol())s.blankLine(this.state,i.indentUnit);else while(!i.eol()){let t=readToken(s.token,i,this.state);t&&(r=this.emitToken(this.lang.tokenTable.resolve(t),this.parsedPos+i.start,this.parsedPos+i.pos,4,r));if(i.start>1e4)break}this.parsedPos=n;this.moveRangeIndex();this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let t=e.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:dt,topID:0,maxBufferLength:2048,reused:this.chunkReused});t=new e(t.type,t.children,t.positions,t.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]);this.chunks.push(t);this.chunkPos.push(this.chunkStart-this.ranges[0].from);this.chunk=[];this.chunkReused=void 0;this.chunkStart=this.parsedPos}finish(){return new e(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function readToken(t,e,n){e.start=e.pos;for(let r=0;r<10;r++){let r=t(e,n);if(e.pos>e.start)return r}throw new Error("Stream parser failed to advance stream.")}const ct=Object.create(null);const ft=[i.none];const dt=new o(ft);const pt=[];const gt=Object.create(null);const mt=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])mt[t]=createTokenType(ct,e);class TokenTable{constructor(t){this.extra=t;this.table=Object.assign(Object.create(null),mt)}resolve(t){return t?this.table[t]||(this.table[t]=createTokenType(this.extra,t)):0}}const kt=new TokenTable(ct);function warnForPart(t,e){if(!(pt.indexOf(t)>-1)){pt.push(t);console.warn(e)}}function createTokenType(t,e){let n=[];for(let r of e.split(" ")){let e=[];for(let n of r.split(".")){let r=t[n]||L[n];r?typeof r=="function"?e.length?e=e.map(r):warnForPart(n,`Modifier ${n} used at start of tag`):e.length?warnForPart(n,`Tag ${n} used as modifier`):e=Array.isArray(r)?r:[r]:warnForPart(n,`Unknown highlighting tag ${n}`)}for(let t of e)n.push(t)}if(!n.length)return 0;let r=e.replace(/ /g,"_"),s=r+" "+n.map((t=>t.id));let o=gt[s];if(o)return o.id;let a=gt[s]=i.define({id:ft.length,name:r,props:[C({[r]:n})]});ft.push(a);return a.id}function docID(t){let e=i.define({id:ft.length,name:"Document",props:[D.add((()=>t))],top:true});ft.push(e);return e}function buildForLine(t){return t.length<=4096&&/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/.test(t)}function textHasRTL(t){for(let e=t.iter();!e.next().done;)if(buildForLine(e.value))return true;return false}function changeAddsRTL(t){let e=false;t.iterChanges(((t,n,r,s,i)=>{!e&&textHasRTL(i)&&(e=true)}));return e}const wt=a.define({combine:t=>t.some((t=>t))});function bidiIsolates(t={}){let e=[vt];t.alwaysIsolate&&e.push(wt.of(true));return e}const vt=k.fromClass(class{constructor(t){this.always=t.state.facet(wt)||t.textDirection!=S.LTR||t.state.facet(w.perLineTextDirection);this.hasRTL=!this.always&&textHasRTL(t.state.doc);this.tree=syntaxTree(t.state);this.decorations=this.always||this.hasRTL?buildDeco(t,this.tree,this.always):v.none}update(t){let e=t.state.facet(wt)||t.view.textDirection!=S.LTR||t.state.facet(w.perLineTextDirection);e||this.hasRTL||!changeAddsRTL(t.changes)||(this.hasRTL=true);if(!e&&!this.hasRTL)return;let n=syntaxTree(t.state);if(e!=this.always||n!=this.tree||t.docChanged||t.viewportChanged){this.tree=n;this.always=e;this.decorations=buildDeco(t.view,n,e)}}},{provide:t=>{function access(e){var n,r;return(r=(n=e.plugin(t))===null||n===void 0?void 0:n.decorations)!==null&&r!==void 0?r:v.none}return[w.outerDecorations.of(access),g.lowest(w.bidiIsolatedRanges.of(access))]}});function buildDeco(e,n,r){let s=new p;let i=e.visibleRanges;r||(i=clipRTLLines(i,e.state.doc));for(let{from:e,to:r}of i)n.iterate({enter:e=>{let n=e.type.prop(t.isolate);n&&s.add(e.from,e.to,xt[n])},from:e,to:r});return s.finish()}function clipRTLLines(t,e){let n=e.iter(),r=0,s=[],i=null;for(let{from:e,to:o}of t){if(e!=r){r<e&&n.next(e-r);r=e}for(;;){let t=r,e=r+n.value.length;!n.lineBreak&&buildForLine(n.value)&&(i&&i.to>t-10?i.to=Math.min(o,e):s.push(i={from:t,to:Math.min(o,e)}));if(r>=o)break;r=e;n.next()}}return s}const xt={rtl:v.mark({class:"cm-iso",inclusive:true,attributes:{dir:"rtl"},bidiIsolate:S.RTL}),ltr:v.mark({class:"cm-iso",inclusive:true,attributes:{dir:"ltr"},bidiIsolate:S.LTR}),auto:v.mark({class:"cm-iso",inclusive:true,attributes:{dir:"auto"},bidiIsolate:null})};export{DocInput,HighlightStyle,IndentContext,LRLanguage,Language,LanguageDescription,LanguageSupport,ParseContext,StreamLanguage,StringStream,TreeIndentContext,bidiIsolates,bracketMatching,ht as bracketMatchingHandle,codeFolding,continuedIndent,tt as defaultHighlightStyle,defineLanguageFacet,delimitedIndent,ensureSyntaxTree,flatIndent,foldAll,foldCode,z as foldEffect,foldGutter,foldInside,G as foldKeymap,j as foldNodeProp,W as foldService,$ as foldState,foldable,foldedRanges,forceParsing,getIndentUnit,getIndentation,highlightingFor,H as indentNodeProp,indentOnInput,indentRange,N as indentService,indentString,E as indentUnit,M as language,D as languageDataProp,matchBrackets,F as sublanguageProp,syntaxHighlighting,syntaxParserRunning,syntaxTree,syntaxTreeAvailable,toggleFold,unfoldAll,unfoldCode,V as unfoldEffect};
2
+
@@ -0,0 +1,2 @@
1
+ import{Decoration as e,showPanel as t,EditorView as i,getPanel as n,logException as s,ViewPlugin as o,WidgetType as r,GutterMarker as l,gutter as a,showTooltip as c,hoverTooltip as d}from"@codemirror/view";import{StateEffect as u,StateField as f,combineConfig as m,Facet as h,RangeSet as g}from"@codemirror/state";import p from"crelt";class SelectedDiagnostic{constructor(e,t,i){this.from=e;this.to=t;this.diagnostic=i}}class LintState{constructor(e,t,i){this.diagnostics=e;this.panel=t;this.selected=i}static init(t,i,n){let s=t;let o=n.facet(L).markerFilter;o&&(s=o(s,n));let r=e.set(s.map((t=>t.from==t.to||t.from==t.to-1&&n.doc.lineAt(t.from).to==t.from?e.widget({widget:new DiagnosticWidget(t),diagnostic:t}).range(t.from):e.mark({attributes:{class:"cm-lintRange cm-lintRange-"+t.severity+(t.markClass?" "+t.markClass:"")},diagnostic:t,inclusive:true}).range(t.from,t.to))),true);return new LintState(r,i,findDiagnostic(r))}}function findDiagnostic(e,t=null,i=0){let n=null;e.between(i,1e9,((e,i,{spec:s})=>{if(!t||s.diagnostic==t){n=new SelectedDiagnostic(e,i,s.diagnostic);return false}}));return n}function hideTooltip(e,t){let i=e.startState.doc.lineAt(t.pos);return!!(e.effects.some((e=>e.is(v)))||e.changes.touchesRange(i.from,i.to))}function maybeEnableLint(e,t){return e.field(k,false)?t:t.concat(u.appendConfig.of(A))}function setDiagnostics(e,t){return{effects:maybeEnableLint(e,[v.of(t)])}}const v=u.define();const w=u.define();const b=u.define();const k=f.define({create(){return new LintState(e.none,null,null)},update(e,t){if(t.docChanged){let i=e.diagnostics.map(t.changes),n=null;if(e.selected){let s=t.changes.mapPos(e.selected.from,1);n=findDiagnostic(i,e.selected.diagnostic,s)||findDiagnostic(i,null,s)}e=new LintState(i,e.panel,n)}for(let i of t.effects)i.is(v)?e=LintState.init(i.value,e.panel,t.state):i.is(w)?e=new LintState(e.diagnostics,i.value?LintPanel.open:null,e.selected):i.is(b)&&(e=new LintState(e.diagnostics,e.panel,i.value));return e},provide:e=>[t.from(e,(e=>e.panel)),i.decorations.from(e,(e=>e.diagnostics))]});function diagnosticCount(e){let t=e.field(k,false);return t?t.diagnostics.size:0}const y=e.mark({class:"cm-lintRange cm-lintRange-active",inclusive:true});function lintTooltip(e,t,i){let{diagnostics:n}=e.state.field(k);let s=[],o=2e8,r=0;n.between(t-(i<0?1:0),t+(i>0?1:0),((e,n,{spec:l})=>{if(t>=e&&t<=n&&(e==n||(t>e||i>0)&&(t<n||i<0))){s.push(l.diagnostic);o=Math.min(e,o);r=Math.max(n,r)}}));let l=e.state.facet(L).tooltipFilter;l&&(s=l(s,e.state));return s.length?{pos:o,end:r,above:e.state.doc.lineAt(o).to<r,create(){return{dom:diagnosticsTooltip(e,s)}}}:null}function diagnosticsTooltip(e,t){return p("ul",{class:"cm-tooltip-lint"},t.map((t=>renderDiagnostic(e,t,false))))}const openLintPanel=e=>{let t=e.state.field(k,false);t&&t.panel||e.dispatch({effects:maybeEnableLint(e.state,[w.of(true)])});let i=n(e,LintPanel.open);i&&i.dom.querySelector(".cm-panel-lint ul").focus();return true};const closeLintPanel=e=>{let t=e.state.field(k,false);if(!t||!t.panel)return false;e.dispatch({effects:w.of(false)});return true};const nextDiagnostic=e=>{let t=e.state.field(k,false);if(!t)return false;let i=e.state.selection.main,n=t.diagnostics.iter(i.to+1);if(!n.value){n=t.diagnostics.iter(0);if(!n.value||n.from==i.from&&n.to==i.to)return false}e.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:true});return true};const previousDiagnostic=e=>{let{state:t}=e,i=t.field(k,false);if(!i)return false;let n=t.selection.main;let s,o,r,l;i.diagnostics.between(0,t.doc.length,((e,t)=>{if(t<n.to&&(s==null||s<e)){s=e;o=t}if(r==null||e>r){r=e;l=t}}));if(r==null||s==null&&r==n.from)return false;e.dispatch({selection:{anchor:s!==null&&s!==void 0?s:r,head:o!==null&&o!==void 0?o:l},scrollIntoView:true});return true};const x=[{key:"Mod-Shift-m",run:openLintPanel,preventDefault:true},{key:"F8",run:nextDiagnostic}];const C=o.fromClass(class{constructor(e){this.view=e;this.timeout=-1;this.set=true;let{delay:t}=e.state.facet(L);this.lintTime=Date.now()+t;this.run=this.run.bind(this);this.timeout=setTimeout(this.run,t)}run(){let e=Date.now();if(e<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-e);else{this.set=false;let{state:e}=this.view,{sources:t}=e.facet(L);t.length&&Promise.all(t.map((e=>Promise.resolve(e(this.view))))).then((t=>{let i=t.reduce(((e,t)=>e.concat(t)));this.view.state.doc==e.doc&&this.view.dispatch(setDiagnostics(this.view.state,i))}),(e=>{s(this.view.state,e)}))}}update(e){let t=e.state.facet(L);if(e.docChanged||t!=e.startState.facet(L)||t.needsRefresh&&t.needsRefresh(e)){this.lintTime=Date.now()+t.delay;if(!this.set){this.set=true;this.timeout=setTimeout(this.run,t.delay)}}}force(){if(this.set){this.lintTime=Date.now();this.run()}}destroy(){clearTimeout(this.timeout)}});const L=h.define({combine(e){return Object.assign({sources:e.map((e=>e.source)).filter((e=>e!=null))},m(e.map((e=>e.config)),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null},{needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t}))}});function linter(e,t={}){return[L.of({source:e,config:t}),C,A]}function forceLinting(e){let t=e.plugin(C);t&&t.force()}function assignKeys(e){let t=[];if(e)e:for(let{name:i}of e){for(let e=0;e<i.length;e++){let n=i[e];if(/[a-zA-Z]/.test(n)&&!t.some((e=>e.toLowerCase()==n.toLowerCase()))){t.push(n);continue e}}t.push("")}return t}function renderDiagnostic(e,t,i){var n;let s=i?assignKeys(t.actions):[];return p("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},p("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage():t.message),(n=t.actions)===null||n===void 0?void 0:n.map(((i,n)=>{let o=false,click=n=>{n.preventDefault();if(o)return;o=true;let s=findDiagnostic(e.state.field(k).diagnostics,t);s&&i.apply(e,s.from,s.to)};let{name:r}=i,l=s[n]?r.indexOf(s[n]):-1;let a=l<0?r:[r.slice(0,l),p("u",r.slice(l,l+1)),r.slice(l+1)];return p("button",{type:"button",class:"cm-diagnosticAction",onclick:click,onmousedown:click,"aria-label":` Action: ${r}${l<0?"":` (access key "${s[n]})"`}.`},a)})),t.source&&p("div",{class:"cm-diagnosticSource"},t.source))}class DiagnosticWidget extends r{constructor(e){super();this.diagnostic=e}eq(e){return e.diagnostic==this.diagnostic}toDOM(){return p("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class PanelItem{constructor(e,t){this.diagnostic=t;this.id="item_"+Math.floor(Math.random()*4294967295).toString(16);this.dom=renderDiagnostic(e,t,true);this.dom.id=this.id;this.dom.setAttribute("role","option")}}class LintPanel{constructor(e){this.view=e;this.items=[];let onkeydown=t=>{if(t.keyCode==27){closeLintPanel(this.view);this.view.focus()}else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else{if(!(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],n=assignKeys(i.actions);for(let s=0;s<n.length;s++)if(n[s].toUpperCase().charCodeAt(0)==t.keyCode){let t=findDiagnostic(this.view.state.field(k).diagnostics,i);t&&i.actions[s].apply(e,t.from,t.to)}}}t.preventDefault()};let onclick=e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)};this.list=p("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:onkeydown,onclick:onclick});this.dom=p("div",{class:"cm-panel-lint"},this.list,p("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>closeLintPanel(this.view)},"×"));this.update()}get selectedIndex(){let e=this.view.state.field(k).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(k);let i=0,n=false,s=null;e.between(0,this.view.state.doc.length,((e,o,{spec:r})=>{let l,a=-1;for(let e=i;e<this.items.length;e++)if(this.items[e].diagnostic==r.diagnostic){a=e;break}if(a<0){l=new PanelItem(this.view,r.diagnostic);this.items.splice(i,0,l);n=true}else{l=this.items[a];if(a>i){this.items.splice(i,a-i);n=true}}if(t&&l.diagnostic==t.diagnostic){if(!l.dom.hasAttribute("aria-selected")){l.dom.setAttribute("aria-selected","true");s=l}}else l.dom.hasAttribute("aria-selected")&&l.dom.removeAttribute("aria-selected");i++}));while(i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0)){n=true;this.items.pop()}if(this.items.length==0){this.items.push(new PanelItem(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")}));n=true}if(s){this.list.setAttribute("aria-activedescendant",s.id);this.view.requestMeasure({key:this,read:()=>({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let i=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/i:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/i)}})}else this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant");n&&this.sync()}sync(){let e=this.list.firstChild;function rm(){let t=e;e=t.nextSibling;t.remove()}for(let t of this.items)if(t.dom.parentNode==this.list){while(e!=t.dom)rm();e=t.dom.nextSibling}else this.list.insertBefore(t.dom,e);while(e)rm()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(k);let i=findDiagnostic(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:true,effects:b.of(i)})}static open(e){return new LintPanel(e)}}function svg(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function underline(e){return svg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const D=i.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:underline("#d11")},".cm-lintRange-warning":{backgroundImage:underline("orange")},".cm-lintRange-info":{backgroundImage:underline("#999")},".cm-lintRange-hint":{backgroundImage:underline("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function severityWeight(e){return e=="error"?4:e=="warning"?3:e=="info"?2:1}class LintGutterMarker extends l{constructor(e){super();this.diagnostics=e;this.severity=e.reduce(((e,t)=>severityWeight(e)<severityWeight(t.severity)?t.severity:e),"hint")}toDOM(e){let t=document.createElement("div");t.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics;let n=e.state.facet(M).tooltipFilter;n&&(i=n(i,e.state));i.length&&(t.onmouseover=()=>gutterMarkerMouseOver(e,t,i));return t}}function trackHoverOn(e,t){let mousemove=i=>{let n=t.getBoundingClientRect();if(!(i.clientX>n.left-10&&i.clientX<n.right+10&&i.clientY>n.top-10&&i.clientY<n.bottom+10)){for(let e=i.target;e;e=e.parentNode)if(e.nodeType==1&&e.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",mousemove);e.state.field(I)&&e.dispatch({effects:R.of(null)})}};window.addEventListener("mousemove",mousemove)}function gutterMarkerMouseOver(e,t,i){function hovered(){let n=e.elementAtHeight(t.getBoundingClientRect().top+5-e.documentTop);const s=e.coordsAtPos(n.from);s&&e.dispatch({effects:R.of({pos:n.from,above:false,create(){return{dom:diagnosticsTooltip(e,i),getCoords:()=>t.getBoundingClientRect()}}})});t.onmouseout=t.onmousemove=null;trackHoverOn(e,t)}let{hoverTime:n}=e.state.facet(M);let s=setTimeout(hovered,n);t.onmouseout=()=>{clearTimeout(s);t.onmouseout=t.onmousemove=null};t.onmousemove=()=>{clearTimeout(s);s=setTimeout(hovered,n)}}function markersForDiagnostics(e,t){let i=Object.create(null);for(let n of t){let t=e.lineAt(n.from);(i[t.from]||(i[t.from]=[])).push(n)}let n=[];for(let e in i)n.push(new LintGutterMarker(i[e]).range(+e));return g.of(n,true)}const T=a({class:"cm-gutter-lint",markers:e=>e.state.field(S)});const S=f.define({create(){return g.empty},update(e,t){e=e.map(t.changes);let i=t.state.facet(M).markerFilter;for(let n of t.effects)if(n.is(v)){let s=n.value;i&&(s=i(s||[],t.state));e=markersForDiagnostics(t.state.doc,s.slice(0))}return e}});const R=u.define();const I=f.define({create(){return null},update(e,t){e&&t.docChanged&&(e=hideTooltip(t,e)?null:Object.assign(Object.assign({},e),{pos:t.changes.mapPos(e.pos)}));return t.effects.reduce(((e,t)=>t.is(R)?t.value:e),e)},provide:e=>c.from(e)});const P=i.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:svg('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:svg('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:svg('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}});const A=[k,i.decorations.compute([k],(t=>{let{selected:i,panel:n}=t.field(k);return i&&n&&i.from!=i.to?e.set([y.range(i.from,i.to)]):e.none})),d(lintTooltip,{hideOn:hideTooltip}),D];const M=h.define({combine(e){return m(e,{hoverTime:300,markerFilter:null,tooltipFilter:null})}});function lintGutter(e={}){return[M.of(e),S,T,P,I]}function forEachDiagnostic(e,t){let i=e.field(k,false);if(i&&i.diagnostics.size)for(let e=g.iter([i.diagnostics]);e.value;e.next())t(e.value.spec.diagnostic,e.from,e.to)}export{closeLintPanel,diagnosticCount,forEachDiagnostic,forceLinting,lintGutter,x as lintKeymap,linter,nextDiagnostic,openLintPanel,previousDiagnostic,setDiagnostics,v as setDiagnosticsEffect};
2
+
@@ -0,0 +1,2 @@
1
+ import{EditorView as e,showPanel as t,getPanel as r,Decoration as n,ViewPlugin as s,runScopeHandlers as i}from"@codemirror/view";import{codePointAt as o,fromCodePoint as a,codePointSize as l,EditorSelection as c,StateEffect as h,StateField as u,combineConfig as f,Facet as d,CharCategory as p,EditorState as m,findClusterBreak as g,RangeSetBuilder as v,Prec as x}from"@codemirror/state";import y from"crelt";const S=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class SearchCursor{constructor(e,t,r=0,n=e.length,s,i){this.test=i;this.value={from:0,to:0};this.done=false;this.matches=[];this.buffer="";this.bufferPos=0;this.iter=e.iterRange(r,n);this.bufferStart=r;this.normalize=s?e=>s(S(e)):S;this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){this.bufferStart+=this.buffer.length;this.iter.next();if(this.iter.done)return-1;this.bufferPos=0;this.buffer=this.iter.value}return o(this.buffer,this.bufferPos)}next(){while(this.matches.length)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0){this.done=true;return this}let t=a(e),r=this.bufferStart+this.bufferPos;this.bufferPos+=l(e);let n=this.normalize(t);for(let e=0,s=r;;e++){let i=n.charCodeAt(e);let o=this.match(i,s,this.bufferPos+this.bufferStart);if(e==n.length-1){if(o){this.value=o;return this}break}s==r&&e<t.length&&t.charCodeAt(e)==i&&s++}}}match(e,t,r){let n=null;for(let t=0;t<this.matches.length;t+=2){let s=this.matches[t],i=false;if(this.query.charCodeAt(s)==e)if(s==this.query.length-1)n={from:this.matches[t+1],to:r};else{this.matches[t]++;i=true}if(!i){this.matches.splice(t,2);t-=2}}this.query.charCodeAt(0)==e&&(this.query.length==1?n={from:t,to:r}:this.matches.push(1,t));n&&this.test&&!this.test(n.from,n.to,this.buffer,this.bufferStart)&&(n=null);return n}}typeof Symbol!="undefined"&&(SearchCursor.prototype[Symbol.iterator]=function(){return this});const b={from:-1,to:-1,match:/.*/.exec("")};const w="gm"+(/x/.unicode==null?"":"u");class RegExpCursor{constructor(e,t,r,n=0,s=e.length){this.text=e;this.to=s;this.curLine="";this.done=false;this.value=b;if(/\\[sWDnr]|\n|\r|\[\^/.test(t))return new MultilineRegExpCursor(e,t,r,n,s);this.re=new RegExp(t,w+((r===null||r===void 0?void 0:r.ignoreCase)?"i":""));this.test=r===null||r===void 0?void 0:r.test;this.iter=e.iter();let i=e.lineAt(n);this.curLineStart=i.from;this.matchPos=toCharEnd(e,n);this.getLine(this.curLineStart)}getLine(e){this.iter.next(e);if(this.iter.lineBreak)this.curLine="";else{this.curLine=this.iter.value;this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart));this.iter.next()}}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1;this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let r=this.curLineStart+t.index,n=r+t[0].length;this.matchPos=toCharEnd(this.text,n+(r==n?1:0));r==this.curLineStart+this.curLine.length&&this.nextLine();if((r<n||r>this.value.to)&&(!this.test||this.test(r,n,t))){this.value={from:r,to:n,match:t};return this}e=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to)){this.done=true;return this}this.nextLine();e=0}}}}const C=new WeakMap;class FlattenedDoc{constructor(e,t){this.from=e;this.text=t}get to(){return this.from+this.text.length}static get(e,t,r){let n=C.get(e);if(!n||n.from>=r||n.to<=t){let n=new FlattenedDoc(t,e.sliceString(t,r));C.set(e,n);return n}if(n.from==t&&n.to==r)return n;let{text:s,from:i}=n;if(i>t){s=e.sliceString(t,i)+s;i=t}n.to<r&&(s+=e.sliceString(n.to,r));C.set(e,new FlattenedDoc(i,s));return new FlattenedDoc(t,s.slice(t-i,r-i))}}class MultilineRegExpCursor{constructor(e,t,r,n,s){this.text=e;this.to=s;this.done=false;this.value=b;this.matchPos=toCharEnd(e,n);this.re=new RegExp(t,w+((r===null||r===void 0?void 0:r.ignoreCase)?"i":""));this.test=r===null||r===void 0?void 0:r.test;this.flat=FlattenedDoc.get(e,n,this.chunkEnd(n+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from;let t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e){this.re.lastIndex=e+1;t=this.re.exec(this.flat.text)}if(t){let e=this.flat.from+t.index,r=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,r,t))){this.value={from:e,to:r,match:t};this.matchPos=toCharEnd(this.text,r+(e==r?1:0));return this}}if(this.flat.to==this.to){this.done=true;return this}this.flat=FlattenedDoc.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol!="undefined"&&(RegExpCursor.prototype[Symbol.iterator]=MultilineRegExpCursor.prototype[Symbol.iterator]=function(){return this});function validRegExp(e){try{new RegExp(e,w);return true}catch(e){return false}}function toCharEnd(e,t){if(t>=e.length)return t;let r,n=e.lineAt(t);while(t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344)t++;return t}function createLineDialog(t){let r=String(t.state.doc.lineAt(t.state.selection.main.head).number);let n=y("input",{class:"cm-textfield",name:"line",value:r});let s=y("form",{class:"cm-gotoLine",onkeydown:e=>{if(e.keyCode==27){e.preventDefault();t.dispatch({effects:M.of(false)});t.focus()}else if(e.keyCode==13){e.preventDefault();go()}},onsubmit:e=>{e.preventDefault();go()}},y("label",t.state.phrase("Go to line"),": ",n)," ",y("button",{class:"cm-button",type:"submit"},t.state.phrase("go")));function go(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.value);if(!r)return;let{state:s}=t,i=s.doc.lineAt(s.selection.main.head);let[,o,a,l,h]=r;let u=l?+l.slice(1):0;let f=a?+a:i.number;if(a&&h){let e=f/100;o&&(e=e*(o=="-"?-1:1)+i.number/s.doc.lines);f=Math.round(s.doc.lines*e)}else a&&o&&(f=f*(o=="-"?-1:1)+i.number);let d=s.doc.line(Math.max(1,Math.min(s.doc.lines,f)));let p=c.cursor(d.from+Math.max(0,Math.min(u,d.length)));t.dispatch({effects:[M.of(false),e.scrollIntoView(p.from,{y:"center"})],selection:p});t.focus()}return{dom:s}}const M=h.define();const k=u.define({create(){return true},update(e,t){for(let r of t.effects)r.is(M)&&(e=r.value);return e},provide:e=>t.from(e,(e=>e?createLineDialog:null))});const gotoLine=e=>{let t=r(e,createLineDialog);if(!t){let n=[M.of(true)];e.state.field(k,false)==null&&n.push(h.appendConfig.of([k,W]));e.dispatch({effects:n});t=r(e,createLineDialog)}t&&t.dom.querySelector("input").select();return true};const W=e.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}});const L={highlightWordAroundCursor:false,minSelectionLength:1,maxMatches:100,wholeWords:false};const q=d.define({combine(e){return f(e,L,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function highlightSelectionMatches(e){let t=[A,E];e&&t.push(q.of(e));return t}const D=n.mark({class:"cm-selectionMatch"});const F=n.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function insideWordBoundaries(e,t,r,n){return(r==0||e(t.sliceDoc(r-1,r))!=p.Word)&&(n==t.doc.length||e(t.sliceDoc(n,n+1))!=p.Word)}function insideWord(e,t,r,n){return e(t.sliceDoc(r,r+1))==p.Word&&e(t.sliceDoc(n-1,n))==p.Word}const E=s.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(q);let{state:r}=e,s=r.selection;if(s.ranges.length>1)return n.none;let i,o=s.main,a=null;if(o.empty){if(!t.highlightWordAroundCursor)return n.none;let e=r.wordAt(o.head);if(!e)return n.none;a=r.charCategorizer(o.head);i=r.sliceDoc(e.from,e.to)}else{let e=o.to-o.from;if(e<t.minSelectionLength||e>200)return n.none;if(t.wholeWords){i=r.sliceDoc(o.from,o.to);a=r.charCategorizer(o.head);if(!(insideWordBoundaries(a,r,o.from,o.to)&&insideWord(a,r,o.from,o.to)))return n.none}else{i=r.sliceDoc(o.from,o.to);if(!i)return n.none}}let l=[];for(let s of e.visibleRanges){let e=new SearchCursor(r.doc,i,s.from,s.to);while(!e.next().done){let{from:s,to:i}=e.value;if(!a||insideWordBoundaries(a,r,s,i)){o.empty&&s<=o.from&&i>=o.to?l.push(F.range(s,i)):(s>=o.to||i<=o.from)&&l.push(D.range(s,i));if(l.length>t.maxMatches)return n.none}}}return n.set(l)}},{decorations:e=>e.decorations});const A=e.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const selectWord=({state:e,dispatch:t})=>{let{selection:r}=e;let n=c.create(r.ranges.map((t=>e.wordAt(t.head)||c.cursor(t.head))),r.mainIndex);if(n.eq(r))return false;t(e.update({selection:n}));return true};function findNextOccurrence(e,t){let{main:r,ranges:n}=e.selection;let s=e.wordAt(r.head),i=s&&s.from==r.from&&s.to==r.to;for(let r=false,s=new SearchCursor(e.doc,t,n[n.length-1].to);;){s.next();if(!s.done){if(r&&n.some((e=>e.from==s.value.from)))continue;if(i){let t=e.wordAt(s.value.from);if(!t||t.from!=s.value.from||t.to!=s.value.to)continue}return s.value}if(r)return null;s=new SearchCursor(e.doc,t,0,Math.max(0,n[n.length-1].from-1));r=true}}const selectNextOccurrence=({state:t,dispatch:r})=>{let{ranges:n}=t.selection;if(n.some((e=>e.from===e.to)))return selectWord({state:t,dispatch:r});let s=t.sliceDoc(n[0].from,n[0].to);if(t.selection.ranges.some((e=>t.sliceDoc(e.from,e.to)!=s)))return false;let i=findNextOccurrence(t,s);if(!i)return false;r(t.update({selection:t.selection.addRange(c.range(i.from,i.to),false),effects:e.scrollIntoView(i.to)}));return true};const R=d.define({combine(t){return f(t,{top:false,caseSensitive:false,literal:false,regexp:false,wholeWord:false,createPanel:e=>new SearchPanel(e),scrollToMatch:t=>e.scrollIntoView(t)})}});function search(e){return e?[R.of(e),U]:U}class SearchQuery{constructor(e){this.search=e.search;this.caseSensitive=!!e.caseSensitive;this.literal=!!e.literal;this.regexp=!!e.regexp;this.replace=e.replace||"";this.valid=!!this.search&&(!this.regexp||validRegExp(this.search));this.unquoted=this.unquote(this.search);this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,((e,t)=>t=="n"?"\n":t=="r"?"\r":t=="t"?"\t":"\\"))}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new RegExpQuery(this):new StringQuery(this)}getCursor(e,t=0,r){let n=e.doc?e:m.create({doc:e});r==null&&(r=n.doc.length);return this.regexp?regexpCursor(this,n,t,r):stringCursor(this,n,t,r)}}class QueryType{constructor(e){this.spec=e}}function stringCursor(e,t,r,n){return new SearchCursor(t.doc,e.unquoted,r,n,e.caseSensitive?void 0:e=>e.toLowerCase(),e.wholeWord?stringWordTest(t.doc,t.charCategorizer(t.selection.main.head)):void 0)}function stringWordTest(e,t){return(r,n,s,i)=>{if(i>r||i+s.length<n){i=Math.max(0,r-2);s=e.sliceString(i,Math.min(e.length,n+2))}return(t(charBefore(s,r-i))!=p.Word||t(charAfter(s,r-i))!=p.Word)&&(t(charAfter(s,n-i))!=p.Word||t(charBefore(s,n-i))!=p.Word)}}class StringQuery extends QueryType{constructor(e){super(e)}nextMatch(e,t,r){let n=stringCursor(this.spec,e,r,e.doc.length).nextOverlapping();n.done&&(n=stringCursor(this.spec,e,0,t).nextOverlapping());return n.done?null:n.value}prevMatchInRange(e,t,r){for(let n=r;;){let r=Math.max(t,n-1e4-this.spec.unquoted.length);let s=stringCursor(this.spec,e,r,n),i=null;while(!s.nextOverlapping().done)i=s.value;if(i)return i;if(r==t)return null;n-=1e4}}prevMatch(e,t,r){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,r,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let r=stringCursor(this.spec,e,0,e.doc.length),n=[];while(!r.next().done){if(n.length>=t)return null;n.push(r.value)}return n}highlight(e,t,r,n){let s=stringCursor(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,e.doc.length));while(!s.next().done)n(s.value.from,s.value.to)}}function regexpCursor(e,t,r,n){return new RegExpCursor(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:e.wholeWord?regexpWordTest(t.charCategorizer(t.selection.main.head)):void 0},r,n)}function charBefore(e,t){return e.slice(g(e,t,false),t)}function charAfter(e,t){return e.slice(t,g(e,t))}function regexpWordTest(e){return(t,r,n)=>!n[0].length||(e(charBefore(n.input,n.index))!=p.Word||e(charAfter(n.input,n.index))!=p.Word)&&(e(charAfter(n.input,n.index+n[0].length))!=p.Word||e(charBefore(n.input,n.index+n[0].length))!=p.Word)}class RegExpQuery extends QueryType{nextMatch(e,t,r){let n=regexpCursor(this.spec,e,r,e.doc.length).next();n.done&&(n=regexpCursor(this.spec,e,0,t).next());return n.done?null:n.value}prevMatchInRange(e,t,r){for(let n=1;;n++){let s=Math.max(t,r-n*1e4);let i=regexpCursor(this.spec,e,s,r),o=null;while(!i.next().done)o=i.value;if(o&&(s==t||o.from>s+10))return o;if(s==t)return null}}prevMatch(e,t,r){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,r,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,((t,r)=>r=="$"?"$":r=="&"?e.match[0]:r!="0"&&+r<e.match.length?e.match[r]:t))}matchAll(e,t){let r=regexpCursor(this.spec,e,0,e.doc.length),n=[];while(!r.next().done){if(n.length>=t)return null;n.push(r.value)}return n}highlight(e,t,r,n){let s=regexpCursor(this.spec,e,Math.max(0,t-250),Math.min(r+250,e.doc.length));while(!s.next().done)n(s.value.from,s.value.to)}}const P=h.define();const Q=h.define();const I=u.define({create(e){return new SearchState(defaultQuery(e).create(),null)},update(e,t){for(let r of t.effects)r.is(P)?e=new SearchState(r.value.create(),e.panel):r.is(Q)&&(e=new SearchState(e.query,r.value?createSearchPanel:null));return e},provide:e=>t.from(e,(e=>e.panel))});function getSearchQuery(e){let t=e.field(I,false);return t?t.query.spec:defaultQuery(e)}function searchPanelOpen(e){var t;return((t=e.field(I,false))===null||t===void 0?void 0:t.panel)!=null}class SearchState{constructor(e,t){this.query=e;this.panel=t}}const T=n.mark({class:"cm-searchMatch"}),O=n.mark({class:"cm-searchMatch cm-searchMatch-selected"});const z=s.fromClass(class{constructor(e){this.view=e;this.decorations=this.highlight(e.state.field(I))}update(e){let t=e.state.field(I);(t!=e.startState.field(I)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return n.none;let{view:r}=this;let s=new v;for(let t=0,n=r.visibleRanges,i=n.length;t<i;t++){let{from:o,to:a}=n[t];while(t<i-1&&a>n[t+1].from-500)a=n[++t].to;e.highlight(r.state,o,a,((e,t)=>{let n=r.state.selection.ranges.some((r=>r.from==e&&r.to==t));s.add(e,t,n?O:T)}))}return s.finish()}},{decorations:e=>e.decorations});function searchCommand(e){return t=>{let r=t.state.field(I,false);return r&&r.query.spec.valid?e(t,r):openSearchPanel(t)}}const $=searchCommand(((e,{query:t})=>{let{to:r}=e.state.selection.main;let n=t.nextMatch(e.state,r,r);if(!n)return false;let s=c.single(n.from,n.to);let i=e.state.facet(R);e.dispatch({selection:s,effects:[announceMatch(e,n),i.scrollToMatch(s.main,e)],userEvent:"select.search"});selectSearchInput(e);return true}));const B=searchCommand(((e,{query:t})=>{let{state:r}=e,{from:n}=r.selection.main;let s=t.prevMatch(r,n,n);if(!s)return false;let i=c.single(s.from,s.to);let o=e.state.facet(R);e.dispatch({selection:i,effects:[announceMatch(e,s),o.scrollToMatch(i.main,e)],userEvent:"select.search"});selectSearchInput(e);return true}));const N=searchCommand(((e,{query:t})=>{let r=t.matchAll(e.state,1e3);if(!r||!r.length)return false;e.dispatch({selection:c.create(r.map((e=>c.range(e.from,e.to)))),userEvent:"select.search.matches"});return true}));const selectSelectionMatches=({state:e,dispatch:t})=>{let r=e.selection;if(r.ranges.length>1||r.main.empty)return false;let{from:n,to:s}=r.main;let i=[],o=0;for(let t=new SearchCursor(e.doc,e.sliceDoc(n,s));!t.next().done;){if(i.length>1e3)return false;t.value.from==n&&(o=i.length);i.push(c.range(t.value.from,t.value.to))}t(e.update({selection:c.create(i,o),userEvent:"select.search.matches"}));return true};const V=searchCommand(((t,{query:r})=>{let{state:n}=t,{from:s,to:i}=n.selection.main;if(n.readOnly)return false;let o=r.nextMatch(n,s,s);if(!o)return false;let a,l,h=[];let u=[];if(o.from==s&&o.to==i){l=n.toText(r.getReplacement(o));h.push({from:o.from,to:o.to,insert:l});o=r.nextMatch(n,o.from,o.to);u.push(e.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(s).number)+"."))}if(o){let e=h.length==0||h[0].from>=o.to?0:o.to-o.from-l.length;a=c.single(o.from-e,o.to-e);u.push(announceMatch(t,o));u.push(n.facet(R).scrollToMatch(a.main,t))}t.dispatch({changes:h,selection:a,effects:u,userEvent:"input.replace"});return true}));const K=searchCommand(((t,{query:r})=>{if(t.state.readOnly)return false;let n=r.matchAll(t.state,1e9).map((e=>{let{from:t,to:n}=e;return{from:t,to:n,insert:r.getReplacement(e)}}));if(!n.length)return false;let s=t.state.phrase("replaced $ matches",n.length)+".";t.dispatch({changes:n,effects:e.announce.of(s),userEvent:"input.replace.all"});return true}));function createSearchPanel(e){return e.state.facet(R).createPanel(e)}function defaultQuery(e,t){var r,n,s,i,o;let a=e.selection.main;let l=a.empty||a.to>a.from+100?"":e.sliceDoc(a.from,a.to);if(t&&!l)return t;let c=e.facet(R);return new SearchQuery({search:((r=t===null||t===void 0?void 0:t.literal)!==null&&r!==void 0?r:c.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:(n=t===null||t===void 0?void 0:t.caseSensitive)!==null&&n!==void 0?n:c.caseSensitive,literal:(s=t===null||t===void 0?void 0:t.literal)!==null&&s!==void 0?s:c.literal,regexp:(i=t===null||t===void 0?void 0:t.regexp)!==null&&i!==void 0?i:c.regexp,wholeWord:(o=t===null||t===void 0?void 0:t.wholeWord)!==null&&o!==void 0?o:c.wholeWord})}function getSearchInput(e){let t=r(e,createSearchPanel);return t&&t.dom.querySelector("[main-field]")}function selectSearchInput(e){let t=getSearchInput(e);t&&t==e.root.activeElement&&t.select()}const openSearchPanel=e=>{let t=e.state.field(I,false);if(t&&t.panel){let r=getSearchInput(e);if(r&&r!=e.root.activeElement){let n=defaultQuery(e.state,t.query.spec);n.valid&&e.dispatch({effects:P.of(n)});r.focus();r.select()}}else e.dispatch({effects:[Q.of(true),t?P.of(defaultQuery(e.state,t.query.spec)):h.appendConfig.of(U)]});return true};const closeSearchPanel=e=>{let t=e.state.field(I,false);if(!t||!t.panel)return false;let n=r(e,createSearchPanel);n&&n.dom.contains(e.root.activeElement)&&e.focus();e.dispatch({effects:Q.of(false)});return true};const G=[{key:"Mod-f",run:openSearchPanel,scope:"editor search-panel"},{key:"F3",run:$,shift:B,scope:"editor search-panel",preventDefault:true},{key:"Mod-g",run:$,shift:B,scope:"editor search-panel",preventDefault:true},{key:"Escape",run:closeSearchPanel,scope:"editor search-panel"},{key:"Mod-Shift-l",run:selectSelectionMatches},{key:"Mod-Alt-g",run:gotoLine},{key:"Mod-d",run:selectNextOccurrence,preventDefault:true}];class SearchPanel{constructor(e){this.view=e;let t=this.query=e.state.field(I).query.spec;this.commit=this.commit.bind(this);this.searchField=y("input",{value:t.search,placeholder:phrase(e,"Find"),"aria-label":phrase(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit});this.replaceField=y("input",{value:t.replace,placeholder:phrase(e,"Replace"),"aria-label":phrase(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit});this.caseField=y("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit});this.reField=y("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit});this.wordField=y("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function button(e,t,r){return y("button",{class:"cm-button",name:e,onclick:t,type:"button"},r)}this.dom=y("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,button("next",(()=>$(e)),[phrase(e,"next")]),button("prev",(()=>B(e)),[phrase(e,"previous")]),button("select",(()=>N(e)),[phrase(e,"all")]),y("label",null,[this.caseField,phrase(e,"match case")]),y("label",null,[this.reField,phrase(e,"regexp")]),y("label",null,[this.wordField,phrase(e,"by word")]),...e.state.readOnly?[]:[y("br"),this.replaceField,button("replace",(()=>V(e)),[phrase(e,"replace")]),button("replaceAll",(()=>K(e)),[phrase(e,"replace all")])],y("button",{name:"close",onclick:()=>closeSearchPanel(e),"aria-label":phrase(e,"close"),type:"button"},["×"])])}commit(){let e=new SearchQuery({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});if(!e.eq(this.query)){this.query=e;this.view.dispatch({effects:P.of(e)})}}keydown(e){if(i(this.view,e,"search-panel"))e.preventDefault();else if(e.keyCode==13&&e.target==this.searchField){e.preventDefault();(e.shiftKey?B:$)(this.view)}else if(e.keyCode==13&&e.target==this.replaceField){e.preventDefault();V(this.view)}}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(P)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e;this.searchField.value=e.search;this.replaceField.value=e.replace;this.caseField.checked=e.caseSensitive;this.reField.checked=e.regexp;this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(R).top}}function phrase(e,t){return e.state.phrase(t)}const j=30;const H=/[\s\.,:;?!]/;function announceMatch(t,{from:r,to:n}){let s=t.state.doc.lineAt(r),i=t.state.doc.lineAt(n).to;let o=Math.max(s.from,r-j),a=Math.min(i,n+j);let l=t.state.sliceDoc(o,a);if(o!=s.from)for(let e=0;e<j;e++)if(!H.test(l[e+1])&&H.test(l[e])){l=l.slice(e);break}if(a!=i)for(let e=l.length-1;e>l.length-j;e--)if(!H.test(l[e-1])&&H.test(l[e])){l=l.slice(0,e);break}return e.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${s.number}.`)}const J=e.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}});const U=[I,x.low(z),J];export{RegExpCursor,SearchCursor,SearchQuery,closeSearchPanel,$ as findNext,B as findPrevious,getSearchQuery,gotoLine,highlightSelectionMatches,openSearchPanel,K as replaceAll,V as replaceNext,search,G as searchKeymap,searchPanelOpen,N as selectMatches,selectNextOccurrence,selectSelectionMatches,P as setSearchQuery};
2
+
@@ -0,0 +1,2 @@
1
+ class Text{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,false,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,true,1,0)}replace(e,t,n){[e,t]=clip(this,e,t);let i=[];this.decompose(0,e,i,2);n.length&&n.decompose(0,n.length,i,3);this.decompose(t,this.length,i,1);return TextNode.from(i,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=clip(this,e,t);let n=[];this.decompose(e,t,n,0);return TextNode.from(n,t-e)}eq(e){if(e==this)return true;if(e.length!=this.length||e.lines!=this.lines)return false;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1);let i=new RawTextCursor(this),s=new RawTextCursor(e);for(let e=t,r=t;;){i.next(e);s.next(e);e=0;if(i.lineBreak!=s.lineBreak||i.done!=s.done||i.value!=s.value)return false;r+=i.value.length;if(i.done||r>=n)return true}}iter(e=1){return new RawTextCursor(this,e)}iterRange(e,t=this.length){return new PartialTextCursor(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);let i=this.line(e).from;n=this.iterRange(i,Math.max(i,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new LineCursor(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];this.flatten(e);return e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length!=1||e[0]?e.length<=32?new TextLeaf(e):TextNode.from(TextLeaf.split(e,[])):Text.empty}}class TextLeaf extends Text{constructor(e,t=textLength(e)){super();this.text=e;this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,i){for(let s=0;;s++){let r=this.text[s],a=i+r.length;if((t?n:a)>=e)return new Line(i,a,n,r);i=a+1;n++}}decompose(e,t,n,i){let s=e<=0&&t>=this.length?this:new TextLeaf(sliceText(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(i&1){let e=n.pop();let t=appendText(s.text,e.text.slice(),0,s.length);if(t.length<=32)n.push(new TextLeaf(t,e.length+s.length));else{let e=t.length>>1;n.push(new TextLeaf(t.slice(0,e)),new TextLeaf(t.slice(e)))}}else n.push(s)}replace(e,t,n){if(!(n instanceof TextLeaf))return super.replace(e,t,n);[e,t]=clip(this,e,t);let i=appendText(this.text,appendText(n.text,sliceText(this.text,0,e)),t);let s=this.length+n.length-(t-e);return i.length<=32?new TextLeaf(i,s):TextNode.from(TextLeaf.split(i,[]),s)}sliceString(e,t=this.length,n="\n"){[e,t]=clip(this,e,t);let i="";for(let s=0,r=0;s<=t&&r<this.text.length;r++){let a=this.text[r],o=s+a.length;s>e&&r&&(i+=n);e<o&&t>s&&(i+=a.slice(Math.max(0,e-s),t-s));s=o+1}return i}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let n=[],i=-1;for(let s of e){n.push(s);i+=s.length+1;if(n.length==32){t.push(new TextLeaf(n,i));n=[];i=-1}}i>-1&&t.push(new TextLeaf(n,i));return t}}class TextNode extends Text{constructor(e,t){super();this.children=e;this.length=t;this.lines=0;for(let t of e)this.lines+=t.lines}lineInner(e,t,n,i){for(let s=0;;s++){let r=this.children[s],a=i+r.length,o=n+r.lines-1;if((t?o:a)>=e)return r.lineInner(e,t,n,i);i=a+1;n=o+1}}decompose(e,t,n,i){for(let s=0,r=0;r<=t&&s<this.children.length;s++){let a=this.children[s],o=r+a.length;if(e<=o&&t>=r){let s=i&((r<=e?1:0)|(o>=t?2:0));r>=e&&o<=t&&!s?n.push(a):a.decompose(e-r,t-r,n,s)}r=o+1}}replace(e,t,n){[e,t]=clip(this,e,t);if(n.lines<this.lines)for(let i=0,s=0;i<this.children.length;i++){let r=this.children[i],a=s+r.length;if(e>=s&&t<=a){let o=r.replace(e-s,t-s,n);let l=this.lines-r.lines+o.lines;if(o.lines<l>>4&&o.lines>l>>6){let s=this.children.slice();s[i]=o;return new TextNode(s,this.length-(t-e)+n.length)}return super.replace(s,a,o)}s=a+1}return super.replace(e,t,n)}sliceString(e,t=this.length,n="\n"){[e,t]=clip(this,e,t);let i="";for(let s=0,r=0;s<this.children.length&&r<=t;s++){let a=this.children[s],o=r+a.length;r>e&&s&&(i+=n);e<o&&t>r&&(i+=a.sliceString(e-r,t-r,n));r=o+1}return i}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof TextNode))return 0;let n=0;let[i,s,r,a]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;i+=t,s+=t){if(i==r||s==a)return n;let o=this.children[i],l=e.children[s];if(o!=l)return n+o.scanIdentical(l,t);n+=o.length+1}}static from(e,t=e.reduce(((e,t)=>e+t.length+1),-1)){let n=0;for(let t of e)n+=t.lines;if(n<32){let n=[];for(let t of e)t.flatten(n);return new TextLeaf(n,t)}let i=Math.max(32,n>>5),s=i<<1,r=i>>1;let a=[],o=0,l=-1,h=[];function add(e){let t;if(e.lines>s&&e instanceof TextNode)for(let t of e.children)add(t);else if(e.lines>r&&(o>r||!o)){flush();a.push(e)}else if(e instanceof TextLeaf&&o&&(t=h[h.length-1])instanceof TextLeaf&&e.lines+t.lines<=32){o+=e.lines;l+=e.length+1;h[h.length-1]=new TextLeaf(t.text.concat(e.text),t.length+1+e.length)}else{o+e.lines>i&&flush();o+=e.lines;l+=e.length+1;h.push(e)}}function flush(){if(o!=0){a.push(h.length==1?h[0]:TextNode.from(h,l));l=-1;o=h.length=0}}for(let t of e)add(t);flush();return a.length==1?a[0]:new TextNode(a,t)}}Text.empty=new TextLeaf([""],0);function textLength(e){let t=-1;for(let n of e)t+=n.length+1;return t}function appendText(e,t,n=0,i=1e9){for(let s=0,r=0,a=true;r<e.length&&s<=i;r++){let o=e[r],l=s+o.length;if(l>=n){l>i&&(o=o.slice(0,i-s));s<n&&(o=o.slice(n-s));if(a){t[t.length-1]+=o;a=false}else t.push(o)}s=l+1}return t}function sliceText(e,t,n){return appendText(e,[""],t,n)}class RawTextCursor{constructor(e,t=1){this.dir=t;this.done=false;this.lineBreak=false;this.value="";this.nodes=[e];this.offsets=[t>0?1:(e instanceof TextLeaf?e.text.length:e.children.length)<<1]}nextInner(e,t){this.done=this.lineBreak=false;for(;;){let n=this.nodes.length-1;let i=this.nodes[n],s=this.offsets[n],r=s>>1;let a=i instanceof TextLeaf?i.text.length:i.children.length;if(r==(t>0?a:0)){if(n==0){this.done=true;this.value="";return this}t>0&&this.offsets[n-1]++;this.nodes.pop();this.offsets.pop()}else if((s&1)==(t>0?0:1)){this.offsets[n]+=t;if(e==0){this.lineBreak=true;this.value="\n";return this}e--}else if(i instanceof TextLeaf){let s=i.text[r+(t<0?-1:0)];this.offsets[n]+=t;if(s.length>Math.max(0,e)){this.value=e==0?s:t>0?s.slice(e):s.slice(0,s.length-e);return this}e-=s.length}else{let s=i.children[r+(t<0?-1:0)];if(e>s.length){e-=s.length;this.offsets[n]+=t}else{t<0&&this.offsets[n]--;this.nodes.push(s);this.offsets.push(t>0?1:(s instanceof TextLeaf?s.text.length:s.children.length)<<1)}}}}next(e=0){if(e<0){this.nextInner(-e,-this.dir);e=this.value.length}return this.nextInner(e,this.dir)}}class PartialTextCursor{constructor(e,t,n){this.value="";this.done=false;this.cursor=new RawTextCursor(e,t>n?-1:1);this.pos=t>n?e.length:0;this.from=Math.min(t,n);this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to){this.value="";this.done=true;return this}e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n);n-=e;let{value:i}=this.cursor.next(e);this.pos+=(i.length+e)*t;this.value=i.length<=n?i:t<0?i.slice(i.length-n):i.slice(0,n);this.done=!this.value;return this}next(e=0){e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos));return this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class LineCursor{constructor(e){this.inner=e;this.afterBreak=true;this.value="";this.done=false}next(e=0){let{done:t,lineBreak:n,value:i}=this.inner.next(e);if(t&&this.afterBreak){this.value="";this.afterBreak=false}else if(t){this.done=true;this.value=""}else if(n)if(this.afterBreak)this.value="";else{this.afterBreak=true;this.next()}else{this.value=i;this.afterBreak=false}return this}get lineBreak(){return false}}if(typeof Symbol!="undefined"){Text.prototype[Symbol.iterator]=function(){return this.iter()};RawTextCursor.prototype[Symbol.iterator]=PartialTextCursor.prototype[Symbol.iterator]=LineCursor.prototype[Symbol.iterator]=function(){return this}}class Line{constructor(e,t,n,i){this.from=e;this.to=t;this.number=n;this.text=i}get length(){return this.to-this.from}}function clip(e,t,n){t=Math.max(0,Math.min(e.length,t));return[t,Math.max(t,Math.min(e.length,n))]}let e="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((e=>e?parseInt(e,36):1));for(let t=1;t<e.length;t++)e[t]+=e[t-1];function isExtendingChar(t){for(let n=1;n<e.length;n+=2)if(e[n]>t)return e[n-1]<=t;return false}function isRegionalIndicator(e){return e>=127462&&e<=127487}const t=8205;function findClusterBreak(e,t,n=true,i=true){return(n?nextClusterBreak:prevClusterBreak)(e,t,i)}function nextClusterBreak(e,n,i){if(n==e.length)return n;n&&surrogateLow(e.charCodeAt(n))&&surrogateHigh(e.charCodeAt(n-1))&&n--;let s=codePointAt(e,n);n+=codePointSize(s);while(n<e.length){let r=codePointAt(e,n);if(s==t||r==t||i&&isExtendingChar(r)){n+=codePointSize(r);s=r}else{if(!isRegionalIndicator(r))break;{let t=0,i=n-2;while(i>=0&&isRegionalIndicator(codePointAt(e,i))){t++;i-=2}if(t%2==0)break;n+=2}}}return n}function prevClusterBreak(e,t,n){while(t>0){let i=nextClusterBreak(e,t-2,n);if(i<t)return i;t--}return 0}function surrogateLow(e){return e>=56320&&e<57344}function surrogateHigh(e){return e>=55296&&e<56320}function codePointAt(e,t){let n=e.charCodeAt(t);if(!surrogateHigh(n)||t+1==e.length)return n;let i=e.charCodeAt(t+1);return surrogateLow(i)?i-56320+(n-55296<<10)+65536:n}function fromCodePoint(e){if(e<=65535)return String.fromCharCode(e);e-=65536;return String.fromCharCode(55296+(e>>10),56320+(e&1023))}function codePointSize(e){return e<65536?1:2}const n=/\r\n?|\n/;var i=function(e){e[e.Simple=0]="Simple";e[e.TrackDel=1]="TrackDel";e[e.TrackBefore=2]="TrackBefore";e[e.TrackAfter=3]="TrackAfter";return e}(i||(i={}));class ChangeDesc{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,i=0;t<this.sections.length;){let s=this.sections[t++],r=this.sections[t++];if(r<0){e(n,i,s);i+=s}else i+=r;n+=s}}iterChangedRanges(e,t=false){iterChanges(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let n=this.sections[t++],i=this.sections[t++];i<0?e.push(n,i):e.push(i,n)}return new ChangeDesc(e)}composeDesc(e){return this.empty?e:e.empty?this:composeSets(this,e)}mapDesc(e,t=false){return e.empty?this:mapSet(this,e,t)}mapPos(e,t=-1,n=i.Simple){let s=0,r=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],l=this.sections[a++],h=s+o;if(l<0){if(h>e)return r+(e-s);r+=o}else{if(n!=i.Simple&&h>=e&&(n==i.TrackDel&&s<e&&h>e||n==i.TrackBefore&&s<e||n==i.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!o)return e==s||t<0?r:r+l;r+=l}s=h}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let n=0,i=0;n<this.sections.length&&i<=t;){let s=this.sections[n++],r=this.sections[n++],a=i+s;if(r>=0&&i<=t&&a>=e)return!(i<e&&a>t)||"cover";i=a}return false}toString(){let e="";for(let t=0;t<this.sections.length;){let n=this.sections[t++],i=this.sections[t++];e+=(e?" ":"")+n+(i>=0?":"+i:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some((e=>typeof e!="number")))throw new RangeError("Invalid JSON representation of ChangeDesc");return new ChangeDesc(e)}static create(e){return new ChangeDesc(e)}}class ChangeSet extends ChangeDesc{constructor(e,t){super(e);this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");iterChanges(this,((t,n,i,s,r)=>e=e.replace(i,i+(n-t),r)),false);return e}mapDesc(e,t=false){return mapSet(this,e,t,true)}invert(e){let t=this.sections.slice(),n=[];for(let i=0,s=0;i<t.length;i+=2){let r=t[i],a=t[i+1];if(a>=0){t[i]=a;t[i+1]=r;let o=i>>1;while(n.length<o)n.push(Text.empty);n.push(r?e.slice(s,s+r):Text.empty)}s+=r}return new ChangeSet(t,n)}compose(e){return this.empty?e:e.empty?this:composeSets(this,e,true)}map(e,t=false){return e.empty?this:mapSet(this,e,t,true)}iterChanges(e,t=false){iterChanges(this,e,t)}get desc(){return ChangeDesc.create(this.sections)}filter(e){let t=[],n=[],i=[];let s=new SectionIter(this);e:for(let r=0,a=0;;){let o=r==e.length?1e9:e[r++];while(a<o||a==o&&s.len==0){if(s.done)break e;let e=Math.min(s.len,o-a);addSection(i,e,-1);let r=s.ins==-1?-1:s.off==0?s.ins:0;addSection(t,e,r);r>0&&addInsert(n,t,s.text);s.forward(e);a+=e}let l=e[r++];while(a<l){if(s.done)break e;let e=Math.min(s.len,l-a);addSection(t,e,-1);addSection(i,e,s.ins==-1?-1:s.off==0?s.ins:0);s.forward(e);a+=e}}return{changes:new ChangeSet(t,n),filtered:ChangeDesc.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],i=this.sections[t+1];i<0?e.push(n):i==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],a=0;let o=null;function flush(e=false){if(!e&&!s.length)return;a<t&&addSection(s,t-a,-1);let n=new ChangeSet(s,r);o=o?o.compose(n.map(o)):n;s=[];r=[];a=0}function process(e){if(Array.isArray(e))for(let t of e)process(t);else if(e instanceof ChangeSet){if(e.length!=t)throw new RangeError(`Mismatched change set length (got ${e.length}, expected ${t})`);flush();o=o?o.compose(e.map(o)):e}else{let{from:o,to:l=o,insert:h}=e;if(o>l||o<0||l>t)throw new RangeError(`Invalid change range ${o} to ${l} (in doc of length ${t})`);let c=h?typeof h=="string"?Text.of(h.split(i||n)):h:Text.empty;let f=c.length;if(o==l&&f==0)return;o<a&&flush();o>a&&addSection(s,o-a,-1);addSection(s,l-o,f);addInsert(r,s,c);a=l}}process(e);flush(!o);return o}static empty(e){return new ChangeSet(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],n=[];for(let i=0;i<e.length;i++){let s=e[i];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some(((e,t)=>t&&typeof e!="string")))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{while(n.length<i)n.push(Text.empty);n[i]=Text.of(s.slice(1));t.push(s[0],n[i].length)}}}return new ChangeSet(t,n)}static createSet(e,t){return new ChangeSet(e,t)}}function addSection(e,t,n,i=false){if(t==0&&n<=0)return;let s=e.length-2;if(s>=0&&n<=0&&n==e[s+1])e[s]+=t;else if(t==0&&e[s]==0)e[s+1]+=n;else if(i){e[s]+=t;e[s+1]+=n}else e.push(t,n)}function addInsert(e,t,n){if(n.length==0)return;let i=t.length-2>>1;if(i<e.length)e[e.length-1]=e[e.length-1].append(n);else{while(e.length<i)e.push(Text.empty);e.push(n)}}function iterChanges(e,t,n){let i=e.inserted;for(let s=0,r=0,a=0;a<e.sections.length;){let o=e.sections[a++],l=e.sections[a++];if(l<0){s+=o;r+=o}else{let h=s,c=r,f=Text.empty;for(;;){h+=o;c+=l;l&&i&&(f=f.append(i[a-2>>1]));if(n||a==e.sections.length||e.sections[a+1]<0)break;o=e.sections[a++];l=e.sections[a++]}t(s,h,r,c,f);s=h;r=c}}}function mapSet(e,t,n,i=false){let s=[],r=i?[]:null;let a=new SectionIter(e),o=new SectionIter(t);for(let e=-1;;)if(a.ins==-1&&o.ins==-1){let e=Math.min(a.len,o.len);addSection(s,e,-1);a.forward(e);o.forward(e)}else if(o.ins>=0&&(a.ins<0||e==a.i||a.off==0&&(o.len<a.len||o.len==a.len&&!n))){let t=o.len;addSection(s,o.ins,-1);while(t){let n=Math.min(a.len,t);if(a.ins>=0&&e<a.i&&a.len<=n){addSection(s,0,a.ins);r&&addInsert(r,s,a.text);e=a.i}a.forward(n);t-=n}o.next()}else{if(!(a.ins>=0)){if(a.done&&o.done)return r?ChangeSet.createSet(s,r):ChangeDesc.create(s);throw new Error("Mismatched change set lengths")}{let t=0,n=a.len;while(n)if(o.ins==-1){let e=Math.min(n,o.len);t+=e;n-=e;o.forward(e)}else{if(!(o.ins==0&&o.len<n))break;n-=o.len;o.next()}addSection(s,t,e<a.i?a.ins:0);r&&e<a.i&&addInsert(r,s,a.text);e=a.i;a.forward(a.len-n)}}}function composeSets(e,t,n=false){let i=[];let s=n?[]:null;let r=new SectionIter(e),a=new SectionIter(t);for(let e=false;;){if(r.done&&a.done)return s?ChangeSet.createSet(i,s):ChangeDesc.create(i);if(r.ins==0){addSection(i,r.len,0,e);r.next()}else if(a.len!=0||a.done){if(r.done||a.done)throw new Error("Mismatched change set lengths");{let t=Math.min(r.len2,a.len),n=i.length;if(r.ins==-1){let n=a.ins==-1?-1:a.off?0:a.ins;addSection(i,t,n,e);s&&n&&addInsert(s,i,a.text)}else if(a.ins==-1){addSection(i,r.off?0:r.len,t,e);s&&addInsert(s,i,r.textBit(t))}else{addSection(i,r.off?0:r.len,a.off?0:a.ins,e);s&&!a.off&&addInsert(s,i,a.text)}e=(r.ins>t||a.ins>=0&&a.len>t)&&(e||i.length>n);r.forward2(t);a.forward(t)}}else{addSection(i,0,a.ins,e);s&&addInsert(s,i,a.text);a.next()}}}class SectionIter{constructor(e){this.set=e;this.i=0;this.next()}next(){let{sections:e}=this.set;if(this.i<e.length){this.len=e[this.i++];this.ins=e[this.i++]}else{this.len=0;this.ins=-2}this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?Text.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?Text.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){if(e==this.len)this.next();else{this.len-=e;this.off+=e}}forward2(e){if(this.ins==-1)this.forward(e);else if(e==this.ins)this.next();else{this.ins-=e;this.off+=e}}}class SelectionRange{constructor(e,t,n){this.from=e;this.to=t;this.flags=n}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let n,i;if(this.empty)n=i=e.mapPos(this.from,t);else{n=e.mapPos(this.from,1);i=e.mapPos(this.to,-1)}return n==this.from&&i==this.to?this:new SelectionRange(n,i,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return EditorSelection.range(e,t);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return EditorSelection.range(this.anchor,n)}eq(e,t=false){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return EditorSelection.range(e.anchor,e.head)}static create(e,t,n){return new SelectionRange(e,t,n)}}class EditorSelection{constructor(e,t){this.ranges=e;this.mainIndex=t}map(e,t=-1){return e.empty?this:EditorSelection.create(this.ranges.map((n=>n.map(e,t))),this.mainIndex)}eq(e,t=false){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return false;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return false;return true}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new EditorSelection([this.main],0)}addRange(e,t=true){return EditorSelection.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let n=this.ranges.slice();n[t]=e;return EditorSelection.create(n,this.mainIndex)}toJSON(){return{ranges:this.ranges.map((e=>e.toJSON())),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new EditorSelection(e.ranges.map((e=>SelectionRange.fromJSON(e))),e.main)}static single(e,t=e){return new EditorSelection([EditorSelection.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let n=0,i=0;i<e.length;i++){let s=e[i];if(s.empty?s.from<=n:s.from<n)return EditorSelection.normalized(e.slice(),t);n=s.to}return new EditorSelection(e,t)}static cursor(e,t=0,n,i){return SelectionRange.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n))|(i!==null&&i!==void 0?i:16777215)<<6)}static range(e,t,n,i){let s=(n!==null&&n!==void 0?n:16777215)<<6|(i==null?7:Math.min(6,i));return t<e?SelectionRange.create(t,e,48|s):SelectionRange.create(e,t,(t>e?8:0)|s)}static normalized(e,t=0){let n=e[t];e.sort(((e,t)=>e.from-t.from));t=e.indexOf(n);for(let n=1;n<e.length;n++){let i=e[n],s=e[n-1];if(i.empty?i.from<=s.to:i.from<s.to){let r=s.from,a=Math.max(i.to,s.to);n<=t&&t--;e.splice(--n,2,i.anchor>i.head?EditorSelection.range(a,r):EditorSelection.range(r,a))}}return new EditorSelection(e,t)}}function checkSelection(e,t){for(let n of e.ranges)if(n.to>t)throw new RangeError("Selection points outside of document")}let s=0;class Facet{constructor(e,t,n,i,r){this.combine=e;this.compareInput=t;this.compare=n;this.isStatic=i;this.id=s++;this.default=e([]);this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new Facet(e.combine||(e=>e),e.compareInput||((e,t)=>e===t),e.compare||(e.combine?(e,t)=>e===t:sameArray),!!e.static,e.enables)}of(e){return new FacetProvider([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new FacetProvider(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new FacetProvider(e,this,2,t)}from(e,t){t||(t=e=>e);return this.compute([e],(n=>t(n.field(e))))}}function sameArray(e,t){return e==t||e.length==t.length&&e.every(((e,n)=>e===t[n]))}class FacetProvider{constructor(e,t,n,i){this.dependencies=e;this.facet=t;this.type=n;this.value=i;this.id=s++}dynamicSlot(e){var t;let n=this.value;let i=this.facet.compareInput;let s=this.id,r=e[s]>>1,a=this.type==2;let o=false,l=false,h=[];for(let n of this.dependencies)n=="doc"?o=true:n=="selection"?l=true:(((t=e[n.id])!==null&&t!==void 0?t:1)&1)==0&&h.push(e[n.id]);return{create(e){e.values[r]=n(e);return 1},update(e,t){if(o&&t.docChanged||l&&(t.docChanged||t.selection)||ensureAll(e,h)){let t=n(e);if(a?!compareArray(t,e.values[r],i):!i(t,e.values[r])){e.values[r]=t;return 1}}return 0},reconfigure:(e,t)=>{let o,l=t.config.address[s];if(l!=null){let s=getAddr(t,l);if(this.dependencies.every((n=>n instanceof Facet?t.facet(n)===e.facet(n):!(n instanceof StateField)||t.field(n,false)==e.field(n,false)))||(a?compareArray(o=n(e),s,i):i(o=n(e),s))){e.values[r]=s;return 0}}else o=n(e);e.values[r]=o;return 1}}}}function compareArray(e,t,n){if(e.length!=t.length)return false;for(let i=0;i<e.length;i++)if(!n(e[i],t[i]))return false;return true}function ensureAll(e,t){let n=false;for(let i of t)ensureAddr(e,i)&1&&(n=true);return n}function dynamicFacetSlot(e,t,n){let i=n.map((t=>e[t.id]));let s=n.map((e=>e.type));let r=i.filter((e=>!(e&1)));let a=e[t.id]>>1;function get(e){let n=[];for(let t=0;t<i.length;t++){let r=getAddr(e,i[t]);if(s[t]==2)for(let e of r)n.push(e);else n.push(r)}return t.combine(n)}return{create(e){for(let t of i)ensureAddr(e,t);e.values[a]=get(e);return 1},update(e,n){if(!ensureAll(e,r))return 0;let i=get(e);if(t.compare(i,e.values[a]))return 0;e.values[a]=i;return 1},reconfigure(e,s){let r=ensureAll(e,i);let o=s.config.facets[t.id],l=s.facet(t);if(o&&!r&&sameArray(n,o)){e.values[a]=l;return 0}let h=get(e);if(t.compare(h,l)){e.values[a]=l;return 0}e.values[a]=h;return 1}}}const r=Facet.define({static:true});class StateField{constructor(e,t,n,i,s){this.id=e;this.createF=t;this.updateF=n;this.compareF=i;this.spec=s;this.provides=void 0}static define(e){let t=new StateField(s++,e.create,e.update,e.compare||((e,t)=>e===t),e);e.provide&&(t.provides=e.provide(t));return t}create(e){let t=e.facet(r).find((e=>e.field==this));return((t===null||t===void 0?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>{e.values[t]=this.create(e);return 1},update:(e,n)=>{let i=e.values[t];let s=this.updateF(i,n);if(this.compareF(i,s))return 0;e.values[t]=s;return 1},reconfigure:(e,n)=>{if(n.config.address[this.id]!=null){e.values[t]=n.field(this);return 0}e.values[t]=this.create(e);return 1}}}init(e){return[this,r.of({field:this,create:e})]}get extension(){return this}}const a={lowest:4,low:3,default:2,high:1,highest:0};function prec(e){return t=>new PrecExtension(t,e)}const o={highest:prec(a.highest),high:prec(a.high),default:prec(a.default),low:prec(a.low),lowest:prec(a.lowest)};class PrecExtension{constructor(e,t){this.inner=e;this.prec=t}}class Compartment{of(e){return new CompartmentInstance(this,e)}reconfigure(e){return Compartment.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class CompartmentInstance{constructor(e,t){this.compartment=e;this.inner=t}}class Configuration{constructor(e,t,n,i,s,r){this.base=e;this.compartments=t;this.dynamicSlots=n;this.address=i;this.staticValues=s;this.facets=r;this.statusTemplate=[];while(this.statusTemplate.length<n.length)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,n){let i=[];let s=Object.create(null);let r=new Map;for(let n of flatten(e,t,r))n instanceof StateField?i.push(n):(s[n.facet.id]||(s[n.facet.id]=[])).push(n);let a=Object.create(null);let o=[];let l=[];for(let e of i){a[e.id]=l.length<<1;l.push((t=>e.slot(t)))}let h=n===null||n===void 0?void 0:n.config.facets;for(let e in s){let t=s[e],i=t[0].facet;let r=h&&h[e]||[];if(t.every((e=>e.type==0))){a[i.id]=o.length<<1|1;if(sameArray(r,t))o.push(n.facet(i));else{let e=i.combine(t.map((e=>e.value)));o.push(n&&i.compare(e,n.facet(i))?n.facet(i):e)}}else{for(let e of t)if(e.type==0){a[e.id]=o.length<<1|1;o.push(e.value)}else{a[e.id]=l.length<<1;l.push((t=>e.dynamicSlot(t)))}a[i.id]=l.length<<1;l.push((e=>dynamicFacetSlot(e,i,t)))}}let c=l.map((e=>e(a)));return new Configuration(e,r,c,a,o,s)}}function flatten(e,t,n){let i=[[],[],[],[],[]];let s=new Map;function inner(e,r){let o=s.get(e);if(o!=null){if(o<=r)return;let t=i[o].indexOf(e);t>-1&&i[o].splice(t,1);e instanceof CompartmentInstance&&n.delete(e.compartment)}s.set(e,r);if(Array.isArray(e))for(let t of e)inner(t,r);else if(e instanceof CompartmentInstance){if(n.has(e.compartment))throw new RangeError("Duplicate use of compartment in extensions");let i=t.get(e.compartment)||e.inner;n.set(e.compartment,i);inner(i,r)}else if(e instanceof PrecExtension)inner(e.inner,e.prec);else if(e instanceof StateField){i[r].push(e);e.provides&&inner(e.provides,r)}else if(e instanceof FacetProvider){i[r].push(e);e.facet.extensions&&inner(e.facet.extensions,a.default)}else{let t=e.extension;if(!t)throw new Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);inner(t,r)}}inner(e,a.default);return i.reduce(((e,t)=>e.concat(t)))}function ensureAddr(e,t){if(t&1)return 2;let n=t>>1;let i=e.status[n];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;e.status[n]=4;let s=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|s}function getAddr(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}const l=Facet.define();const h=Facet.define({combine:e=>e.some((e=>e)),static:true});const c=Facet.define({combine:e=>e.length?e[0]:void 0,static:true});const f=Facet.define();const u=Facet.define();const d=Facet.define();const g=Facet.define({combine:e=>!!e.length&&e[0]});class Annotation{constructor(e,t){this.type=e;this.value=t}static define(){return new AnnotationType}}class AnnotationType{of(e){return new Annotation(this,e)}}class StateEffectType{constructor(e){this.map=e}of(e){return new StateEffect(this,e)}}class StateEffect{constructor(e,t){this.type=e;this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new StateEffect(this.type,t)}is(e){return this.type==e}static define(e={}){return new StateEffectType(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let i of e){let e=i.map(t);e&&n.push(e)}return n}}StateEffect.reconfigure=StateEffect.define();StateEffect.appendConfig=StateEffect.define();class Transaction{constructor(e,t,n,i,s,r){this.startState=e;this.changes=t;this.selection=n;this.effects=i;this.annotations=s;this.scrollIntoView=r;this._doc=null;this._state=null;n&&checkSelection(n,t.newLength);s.some((e=>e.type==Transaction.time))||(this.annotations=s.concat(Transaction.time.of(Date.now())))}static create(e,t,n,i,s,r){return new Transaction(e,t,n,i,s,r)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){this._state||this.startState.applyTransaction(this);return this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(Transaction.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Transaction.time=Annotation.define();Transaction.userEvent=Annotation.define();Transaction.addToHistory=Annotation.define();Transaction.remote=Annotation.define();function joinRanges(e,t){let n=[];for(let i=0,s=0;;){let r,a;if(i<e.length&&(s==t.length||t[s]>=e[i])){r=e[i++];a=e[i++]}else{if(!(s<t.length))return n;r=t[s++];a=t[s++]}!n.length||n[n.length-1]<r?n.push(r,a):n[n.length-1]<a&&(n[n.length-1]=a)}}function mergeTransaction(e,t,n){var i;let s,r,a;if(n){s=t.changes;r=ChangeSet.empty(t.changes.length);a=e.changes.compose(t.changes)}else{s=t.changes.map(e.changes);r=e.changes.mapDesc(t.changes,true);a=e.changes.compose(s)}return{changes:a,selection:t.selection?t.selection.map(r):(i=e.selection)===null||i===void 0?void 0:i.map(s),effects:StateEffect.mapEffects(e.effects,s).concat(StateEffect.mapEffects(t.effects,r)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function resolveTransactionInner(e,t,n){let i=t.selection,s=asArray(t.annotations);t.userEvent&&(s=s.concat(Transaction.userEvent.of(t.userEvent)));return{changes:t.changes instanceof ChangeSet?t.changes:ChangeSet.of(t.changes||[],n,e.facet(c)),selection:i&&(i instanceof EditorSelection?i:EditorSelection.single(i.anchor,i.head)),effects:asArray(t.effects),annotations:s,scrollIntoView:!!t.scrollIntoView}}function resolveTransaction(e,t,n){let i=resolveTransactionInner(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===false&&(n=false);for(let s=1;s<t.length;s++){t[s].filter===false&&(n=false);let r=!!t[s].sequential;i=mergeTransaction(i,resolveTransactionInner(e,t[s],r?i.changes.newLength:e.doc.length),r)}let s=Transaction.create(e,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return extendTransaction(n?filterTransaction(s):s)}function filterTransaction(e){let t=e.startState;let n=true;for(let i of t.facet(f)){let t=i(e);if(t===false){n=false;break}Array.isArray(t)&&(n=n===true?t:joinRanges(n,t))}if(n!==true){let i,s;if(n===false){s=e.changes.invertedDesc;i=ChangeSet.empty(t.doc.length)}else{let t=e.changes.filter(n);i=t.changes;s=t.filtered.mapDesc(t.changes).invertedDesc}e=Transaction.create(t,i,e.selection&&e.selection.map(s),StateEffect.mapEffects(e.effects,s),e.annotations,e.scrollIntoView)}let i=t.facet(u);for(let n=i.length-1;n>=0;n--){let s=i[n](e);e=s instanceof Transaction?s:Array.isArray(s)&&s.length==1&&s[0]instanceof Transaction?s[0]:resolveTransaction(t,asArray(s),false)}return e}function extendTransaction(e){let t=e.startState,n=t.facet(d),i=e;for(let s=n.length-1;s>=0;s--){let r=n[s](e);r&&Object.keys(r).length&&(i=mergeTransaction(i,resolveTransactionInner(t,r,e.changes.newLength),true))}return i==e?e:Transaction.create(t,e.changes,e.selection,i.effects,i.annotations,i.scrollIntoView)}const p=[];function asArray(e){return e==null?p:Array.isArray(e)?e:[e]}var m=function(e){e[e.Word=0]="Word";e[e.Space=1]="Space";e[e.Other=2]="Other";return e}(m||(m={}));const S=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let x;try{x=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(e){}function hasWordChar(e){if(x)return x.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>"€"&&(n.toUpperCase()!=n.toLowerCase()||S.test(n)))return true}return false}function makeCategorizer(e){return t=>{if(!/\S/.test(t))return m.Space;if(hasWordChar(t))return m.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return m.Word;return m.Other}}class EditorState{constructor(e,t,n,i,s,r){this.config=e;this.doc=t;this.selection=n;this.values=i;this.status=e.statusTemplate.slice();this.computeSlot=s;r&&(r._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)ensureAddr(this,e<<1);this.computeSlot=null}field(e,t=true){let n=this.config.address[e.id];if(n!=null){ensureAddr(this,n);return getAddr(this,n)}if(t)throw new RangeError("Field is not present in this state")}update(...e){return resolveTransaction(this,e,true)}applyTransaction(e){let t=this.config,{base:n,compartments:i}=t;for(let s of e.effects)if(s.is(Compartment.reconfigure)){if(t){i=new Map;t.compartments.forEach(((e,t)=>i.set(t,e)));t=null}i.set(s.value.compartment,s.value.extension)}else if(s.is(StateEffect.reconfigure)){t=null;n=s.value}else if(s.is(StateEffect.appendConfig)){t=null;n=asArray(n).concat(s.value)}let s;if(t)s=e.startState.values.slice();else{t=Configuration.resolve(n,i,this);let e=new EditorState(t,this.doc,this.selection,t.dynamicSlots.map((()=>null)),((e,t)=>t.reconfigure(e,this)),null);s=e.values}let r=e.startState.facet(h)?e.newSelection:e.newSelection.asSingle();new EditorState(t,e.newDoc,r,s,((t,n)=>n.update(t,e)),e)}replaceSelection(e){typeof e=="string"&&(e=this.toText(e));return this.changeByRange((t=>({changes:{from:t.from,to:t.to,insert:e},range:EditorSelection.cursor(t.from+e.length)})))}changeByRange(e){let t=this.selection;let n=e(t.ranges[0]);let i=this.changes(n.changes),s=[n.range];let r=asArray(n.effects);for(let n=1;n<t.ranges.length;n++){let a=e(t.ranges[n]);let o=this.changes(a.changes),l=o.map(i);for(let e=0;e<n;e++)s[e]=s[e].map(l);let h=i.mapDesc(o,true);s.push(a.range.map(h));i=i.compose(l);r=StateEffect.mapEffects(r,l).concat(StateEffect.mapEffects(asArray(a.effects),h))}return{changes:i,selection:EditorSelection.create(s,t.mainIndex),effects:r}}changes(e=[]){return e instanceof ChangeSet?e:ChangeSet.of(e,this.doc.length,this.facet(EditorState.lineSeparator))}toText(e){return Text.of(e.split(this.facet(EditorState.lineSeparator)||n))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];if(t==null)return e.default;ensureAddr(this,t);return getAddr(this,t)}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let i=e[n];i instanceof StateField&&this.config.address[i.id]!=null&&(t[n]=i.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(e,t={},n){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let i=[];if(n)for(let t in n)if(Object.prototype.hasOwnProperty.call(e,t)){let s=n[t],r=e[t];i.push(s.init((e=>s.spec.fromJSON(r,e))))}return EditorState.create({doc:e.doc,selection:EditorSelection.fromJSON(e.selection),extensions:t.extensions?i.concat([t.extensions]):i})}static create(e={}){let t=Configuration.resolve(e.extensions||[],new Map);let i=e.doc instanceof Text?e.doc:Text.of((e.doc||"").split(t.staticFacet(EditorState.lineSeparator)||n));let s=e.selection?e.selection instanceof EditorSelection?e.selection:EditorSelection.single(e.selection.anchor,e.selection.head):EditorSelection.single(0);checkSelection(s,i.length);t.staticFacet(h)||(s=s.asSingle());return new EditorState(t,i,s,t.dynamicSlots.map((()=>null)),((e,t)=>t.create(e)),null)}get tabSize(){return this.facet(EditorState.tabSize)}get lineBreak(){return this.facet(EditorState.lineSeparator)||"\n"}get readOnly(){return this.facet(g)}phrase(e,...t){for(let t of this.facet(EditorState.phrases))if(Object.prototype.hasOwnProperty.call(t,e)){e=t[e];break}t.length&&(e=e.replace(/\$(\$|\d*)/g,((e,n)=>{if(n=="$")return"$";let i=+(n||1);return!i||i>t.length?e:t[i-1]})));return e}languageDataAt(e,t,n=-1){let i=[];for(let s of this.facet(l))for(let r of s(this,t,n))Object.prototype.hasOwnProperty.call(r,e)&&i.push(r[e]);return i}charCategorizer(e){return makeCategorizer(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:n,length:i}=this.doc.lineAt(e);let s=this.charCategorizer(e);let r=e-n,a=e-n;while(r>0){let e=findClusterBreak(t,r,false);if(s(t.slice(e,r))!=m.Word)break;r=e}while(a<i){let e=findClusterBreak(t,a);if(s(t.slice(a,e))!=m.Word)break;a=e}return r==a?null:EditorSelection.range(r+n,a+n)}}EditorState.allowMultipleSelections=h;EditorState.tabSize=Facet.define({combine:e=>e.length?e[0]:4});EditorState.lineSeparator=c;EditorState.readOnly=g;EditorState.phrases=Facet.define({compare(e,t){let n=Object.keys(e),i=Object.keys(t);return n.length==i.length&&n.every((n=>e[n]==t[n]))}});EditorState.languageData=l;EditorState.changeFilter=f;EditorState.transactionFilter=u;EditorState.transactionExtender=d;Compartment.reconfigure=StateEffect.define();function combineConfig(e,t,n={}){let i={};for(let t of e)for(let e of Object.keys(t)){let s=t[e],r=i[e];if(r===void 0)i[e]=s;else if(r===s||s===void 0);else{if(!Object.hasOwnProperty.call(n,e))throw new Error("Config merge conflict for field "+e);i[e]=n[e](r,s)}}for(let e in t)i[e]===void 0&&(i[e]=t[e]);return i}class RangeValue{eq(e){return this==e}range(e,t=e){return Range.create(e,t,this)}}RangeValue.prototype.startSide=RangeValue.prototype.endSide=0;RangeValue.prototype.point=false;RangeValue.prototype.mapMode=i.TrackDel;class Range{constructor(e,t,n){this.from=e;this.to=t;this.value=n}static create(e,t,n){return new Range(e,t,n)}}function cmpRange(e,t){return e.from-t.from||e.value.startSide-t.value.startSide}class Chunk{constructor(e,t,n,i){this.from=e;this.to=t;this.value=n;this.maxPoint=i}get length(){return this.to[this.to.length-1]}findIndex(e,t,n,i=0){let s=n?this.to:this.from;for(let r=i,a=s.length;;){if(r==a)return r;let i=r+a>>1;let o=s[i]-e||(n?this.value[i].endSide:this.value[i].startSide)-t;if(i==r)return o>=0?r:a;o>=0?a=i:r=i+1}}between(e,t,n,i){for(let s=this.findIndex(t,-1e9,true),r=this.findIndex(n,1e9,false,s);s<r;s++)if(i(this.from[s]+e,this.to[s]+e,this.value[s])===false)return false}map(e,t){let n=[],i=[],s=[],r=-1,a=-1;for(let o=0;o<this.value.length;o++){let l,h,c=this.value[o],f=this.from[o]+e,u=this.to[o]+e;if(f==u){let e=t.mapPos(f,c.startSide,c.mapMode);if(e==null)continue;l=h=e;if(c.startSide!=c.endSide){h=t.mapPos(f,c.endSide);if(h<l)continue}}else{l=t.mapPos(f,c.startSide);h=t.mapPos(u,c.endSide);if(l>h||l==h&&c.startSide>0&&c.endSide<=0)continue}if(!((h-l||c.endSide-c.startSide)<0)){r<0&&(r=l);c.point&&(a=Math.max(a,h-l));n.push(c);i.push(l-r);s.push(h-r)}}return{mapped:n.length?new Chunk(i,s,n,a):null,pos:r}}}class RangeSet{constructor(e,t,n,i){this.chunkPos=e;this.chunk=t;this.nextLayer=n;this.maxPoint=i}static create(e,t,n,i){return new RangeSet(e,t,n,i)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:n=false,filterFrom:i=0,filterTo:s=this.length}=e;let r=e.filter;if(t.length==0&&!r)return this;n&&(t=t.slice().sort(cmpRange));if(this.isEmpty)return t.length?RangeSet.of(t):this;let a=new LayerCursor(this,null,-1).goto(0),o=0,l=[];let h=new RangeSetBuilder;while(a.value||o<t.length)if(o<t.length&&(a.from-t[o].from||a.startSide-t[o].value.startSide)>=0){let e=t[o++];h.addInner(e.from,e.to,e.value)||l.push(e)}else if(a.rangeIndex==1&&a.chunkIndex<this.chunk.length&&(o==t.length||this.chunkEnd(a.chunkIndex)<t[o].from)&&(!r||i>this.chunkEnd(a.chunkIndex)||s<this.chunkPos[a.chunkIndex])&&h.addChunk(this.chunkPos[a.chunkIndex],this.chunk[a.chunkIndex]))a.nextChunk();else{(!r||i>a.to||s<a.from||r(a.from,a.to,a.value))&&(h.addInner(a.from,a.to,a.value)||l.push(Range.create(a.from,a.to,a.value)));a.next()}return h.finishInner(this.nextLayer.isEmpty&&!l.length?RangeSet.empty:this.nextLayer.update({add:l,filter:r,filterFrom:i,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],n=[],i=-1;for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],a=this.chunk[s];let o=e.touchesRange(r,r+a.length);if(o===false){i=Math.max(i,a.maxPoint);t.push(a);n.push(e.mapPos(r))}else if(o===true){let{mapped:s,pos:o}=a.map(r,e);if(s){i=Math.max(i,s.maxPoint);t.push(s);n.push(o)}}}let s=this.nextLayer.map(e);return t.length==0?s:new RangeSet(n,t,s||RangeSet.empty,i)}between(e,t,n){if(!this.isEmpty){for(let i=0;i<this.chunk.length;i++){let s=this.chunkPos[i],r=this.chunk[i];if(t>=s&&e<=s+r.length&&r.between(s,e-s,t-s,n)===false)return}this.nextLayer.between(e,t,n)}}iter(e=0){return HeapCursor.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return HeapCursor.from(e).goto(t)}static compare(e,t,n,i,s=-1){let r=e.filter((e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=s));let a=t.filter((e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=s));let o=findSharedChunks(r,a,n);let l=new SpanCursor(r,o,s);let h=new SpanCursor(a,o,s);n.iterGaps(((e,t,n)=>compare(l,e,h,t,n,i)));n.empty&&n.length==0&&compare(l,0,h,0,0,i)}static eq(e,t,n=0,i){i==null&&(i=999999999);let s=e.filter((e=>!e.isEmpty&&t.indexOf(e)<0));let r=t.filter((t=>!t.isEmpty&&e.indexOf(t)<0));if(s.length!=r.length)return false;if(!s.length)return true;let a=findSharedChunks(s,r);let o=new SpanCursor(s,a,0).goto(n),l=new SpanCursor(r,a,0).goto(n);for(;;){if(o.to!=l.to||!sameValues(o.active,l.active)||o.point&&(!l.point||!o.point.eq(l.point)))return false;if(o.to>i)return true;o.next();l.next()}}static spans(e,t,n,i,s=-1){let r=new SpanCursor(e,null,s).goto(t),a=t;let o=r.openStart;for(;;){let e=Math.min(r.to,n);if(r.point){let n=r.activeForPoint(r.to);let s=r.pointFrom<t?n.length+1:r.point.startSide<0?n.length:Math.min(n.length,o);i.point(a,e,r.point,n,s,r.pointRank);o=Math.min(r.openEnd(e),n.length)}else if(e>a){i.span(a,e,r.active,o);o=r.openEnd(e)}if(r.to>n)return o+(r.point&&r.to>n?1:0);a=r.to;r.next()}}static of(e,t=false){let n=new RangeSetBuilder;for(let i of e instanceof Range?[e]:t?lazySort(e):e)n.add(i.from,i.to,i.value);return n.finish()}static join(e){if(!e.length)return RangeSet.empty;let t=e[e.length-1];for(let n=e.length-2;n>=0;n--)for(let i=e[n];i!=RangeSet.empty;i=i.nextLayer)t=new RangeSet(i.chunkPos,i.chunk,t,Math.max(i.maxPoint,t.maxPoint));return t}}RangeSet.empty=new RangeSet([],[],null,-1);function lazySort(e){if(e.length>1)for(let t=e[0],n=1;n<e.length;n++){let i=e[n];if(cmpRange(t,i)>0)return e.slice().sort(cmpRange);t=i}return e}RangeSet.empty.nextLayer=RangeSet.empty;class RangeSetBuilder{finishChunk(e){this.chunks.push(new Chunk(this.from,this.to,this.value,this.maxPoint));this.chunkPos.push(this.chunkStart);this.chunkStart=-1;this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint);this.maxPoint=-1;if(e){this.from=[];this.to=[];this.value=[]}}constructor(){this.chunks=[];this.chunkPos=[];this.chunkStart=-1;this.last=null;this.lastFrom=-1e9;this.lastTo=-1e9;this.from=[];this.to=[];this.value=[];this.maxPoint=-1;this.setMaxPoint=-1;this.nextLayer=null}add(e,t,n){this.addInner(e,t,n)||(this.nextLayer||(this.nextLayer=new RangeSetBuilder)).add(e,t,n)}addInner(e,t,n){let i=e-this.lastTo||n.startSide-this.last.endSide;if(i<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");if(i<0)return false;this.from.length==250&&this.finishChunk(true);this.chunkStart<0&&(this.chunkStart=e);this.from.push(e-this.chunkStart);this.to.push(t-this.chunkStart);this.last=n;this.lastFrom=e;this.lastTo=t;this.value.push(n);n.point&&(this.maxPoint=Math.max(this.maxPoint,t-e));return true}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return false;this.from.length&&this.finishChunk(true);this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint);this.chunks.push(t);this.chunkPos.push(e);let n=t.value.length-1;this.last=t.value[n];this.lastFrom=t.from[n]+e;this.lastTo=t.to[n]+e;return true}finish(){return this.finishInner(RangeSet.empty)}finishInner(e){this.from.length&&this.finishChunk(false);if(this.chunks.length==0)return e;let t=RangeSet.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);this.from=null;return t}}function findSharedChunks(e,t,n){let i=new Map;for(let t of e)for(let e=0;e<t.chunk.length;e++)t.chunk[e].maxPoint<=0&&i.set(t.chunk[e],t.chunkPos[e]);let s=new Set;for(let e of t)for(let t=0;t<e.chunk.length;t++){let r=i.get(e.chunk[t]);r==null||(n?n.mapPos(r):r)!=e.chunkPos[t]||(n===null||n===void 0?void 0:n.touchesRange(r,r+e.chunk[t].length))||s.add(e.chunk[t])}return s}class LayerCursor{constructor(e,t,n,i=0){this.layer=e;this.skip=t;this.minPoint=n;this.rank=i}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){this.chunkIndex=this.rangeIndex=0;this.gotoInner(e,t,false);return this}gotoInner(e,t,n){while(this.chunkIndex<this.layer.chunk.length){let t=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(t)||this.layer.chunkEnd(this.chunkIndex)<e||t.maxPoint<this.minPoint))break;this.chunkIndex++;n=false}if(this.chunkIndex<this.layer.chunk.length){let i=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,true);(!n||this.rangeIndex<i)&&this.setRangeIndex(i)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,true)}next(){for(;;){if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9;this.value=null;break}{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex];let n=e+t.from[this.rangeIndex];this.from=n;this.to=e+t.to[this.rangeIndex];this.value=t.value[this.rangeIndex];this.setRangeIndex(this.rangeIndex+1);if(this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){this.chunkIndex++;if(this.skip)while(this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]))this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++;this.rangeIndex=0;this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class HeapCursor{constructor(e){this.heap=e}static from(e,t=null,n=-1){let i=[];for(let s=0;s<e.length;s++)for(let r=e[s];!r.isEmpty;r=r.nextLayer)r.maxPoint>=n&&i.push(new LayerCursor(r,t,n,s));return i.length==1?i[0]:new HeapCursor(i)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let e=this.heap.length>>1;e>=0;e--)heapBubble(this.heap,e);this.next();return this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let e=this.heap.length>>1;e>=0;e--)heapBubble(this.heap,e);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0){this.from=this.to=1e9;this.value=null;this.rank=-1}else{let e=this.heap[0];this.from=e.from;this.to=e.to;this.value=e.value;this.rank=e.rank;e.value&&e.next();heapBubble(this.heap,0)}}}function heapBubble(e,t){for(let n=e[t];;){let i=1+(t<<1);if(i>=e.length)break;let s=e[i];if(i+1<e.length&&s.compare(e[i+1])>=0){s=e[i+1];i++}if(n.compare(s)<0)break;e[i]=n;e[t]=s;t=i}}class SpanCursor{constructor(e,t,n){this.minPoint=n;this.active=[];this.activeTo=[];this.activeRank=[];this.minActive=-1;this.point=null;this.pointFrom=0;this.pointRank=0;this.to=-1e9;this.endSide=0;this.openStart=-1;this.cursor=HeapCursor.from(e,t,n)}goto(e,t=-1e9){this.cursor.goto(e,t);this.active.length=this.activeTo.length=this.activeRank.length=0;this.minActive=-1;this.to=e;this.endSide=t;this.openStart=-1;this.next();return this}forward(e,t){while(this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){remove(this.active,e);remove(this.activeTo,e);remove(this.activeRank,e);this.minActive=findMinIndex(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:i,rank:s}=this.cursor;while(t<this.activeRank.length&&(s-this.activeRank[t]||i-this.activeTo[t])>0)t++;insert(this.active,t,n);insert(this.activeTo,t,i);insert(this.activeRank,t,s);e&&insert(e,t,this.cursor.from);this.minActive=findMinIndex(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let i=this.minActive;if(i>-1&&(this.activeTo[i]-this.cursor.from||this.active[i].endSide-this.cursor.startSide)<0){if(this.activeTo[i]>e){this.to=this.activeTo[i];this.endSide=this.active[i].endSide;break}this.removeActive(i);n&&remove(n,i)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>e){this.to=this.cursor.from;this.endSide=this.cursor.startSide;break}{let e=this.cursor.value;if(e.point){if(!(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)){this.point=e;this.pointFrom=this.cursor.from;this.pointRank=this.cursor.rank;this.to=this.cursor.to;this.endSide=e.endSide;this.cursor.next();this.forward(this.to,this.endSide);break}this.cursor.next()}else{this.addActive(n);this.cursor.next()}}}}if(n){this.openStart=0;for(let t=n.length-1;t>=0&&n[t]<e;t--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let n=this.active.length-1;n>=0;n--){if(this.activeRank[n]<this.pointRank)break;(this.activeTo[n]>e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n])}return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}}function compare(e,t,n,i,s,r){e.goto(t);n.goto(i);let a=i+s;let o=i,l=i-t;for(;;){let t=e.to+l-n.to||e.endSide-n.endSide;let i=t<0?e.to+l:n.to,s=Math.min(i,a);e.point||n.point?e.point&&n.point&&(e.point==n.point||e.point.eq(n.point))&&sameValues(e.activeForPoint(e.to),n.activeForPoint(n.to))||r.comparePoint(o,s,e.point,n.point):s>o&&!sameValues(e.active,n.active)&&r.compareRange(o,s,e.active,n.active);if(i>a)break;o=i;t<=0&&e.next();t>=0&&n.next()}}function sameValues(e,t){if(e.length!=t.length)return false;for(let n=0;n<e.length;n++)if(e[n]!=t[n]&&!e[n].eq(t[n]))return false;return true}function remove(e,t){for(let n=t,i=e.length-1;n<i;n++)e[n]=e[n+1];e.pop()}function insert(e,t,n){for(let n=e.length-1;n>=t;n--)e[n+1]=e[n];e[t]=n}function findMinIndex(e,t){let n=-1,i=1e9;for(let s=0;s<t.length;s++)if((t[s]-i||e[s].endSide-e[n].endSide)<0){n=s;i=t[s]}return n}function countColumn(e,t,n=e.length){let i=0;for(let s=0;s<n;)if(e.charCodeAt(s)==9){i+=t-i%t;s++}else{i++;s=findClusterBreak(e,s)}return i}function findColumn(e,t,n,i){for(let i=0,s=0;;){if(s>=t)return i;if(i==e.length)break;s+=e.charCodeAt(i)==9?n-s%n:1;i=findClusterBreak(e,i)}return i===true?-1:e.length}export{Annotation,AnnotationType,ChangeDesc,ChangeSet,m as CharCategory,Compartment,EditorSelection,EditorState,Facet,Line,i as MapMode,o as Prec,Range,RangeSet,RangeSetBuilder,RangeValue,SelectionRange,StateEffect,StateEffectType,StateField,Text,Transaction,codePointAt,codePointSize,combineConfig,countColumn,findClusterBreak,findColumn,fromCodePoint};
2
+