signalpilot-ai-internal 0.7.6__py3-none-any.whl → 0.10.22__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. signalpilot_ai_internal/__init__.py +1 -0
  2. signalpilot_ai_internal/_version.py +1 -1
  3. signalpilot_ai_internal/databricks_schema_service.py +902 -0
  4. signalpilot_ai_internal/file_scanner_service.py +2 -1
  5. signalpilot_ai_internal/handlers.py +72 -2
  6. signalpilot_ai_internal/mcp_handlers.py +508 -0
  7. signalpilot_ai_internal/mcp_server_manager.py +298 -0
  8. signalpilot_ai_internal/mcp_service.py +1303 -0
  9. signalpilot_ai_internal/schema_search_config.yml +8 -8
  10. signalpilot_ai_internal/schema_search_service.py +62 -1
  11. signalpilot_ai_internal/test_dbt_mcp_server.py +180 -0
  12. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/package.json +5 -3
  13. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/schemas/signalpilot-ai-internal/package.json.orig +4 -2
  14. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/schemas/signalpilot-ai-internal/plugin.json +7 -1
  15. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/110.224e83db03814fd03955.js +7 -0
  16. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/353.972abe1d2d66f083f9cc.js +1 -0
  17. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/476.ad22ccddd74ee306fb56.js +1 -0
  18. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/57.c4232851631fb2e7e59a.js +1 -0
  19. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/726.318e4e791edb63cc788f.js +1 -0
  20. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/785.2d75de1a8d2c3131a8db.js +1 -0
  21. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/801.ca9e114a30896b669a3c.js +1 -0
  22. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/880.d9914229e4f120e7e9e4.js +1 -0
  23. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/936.d80de1e4da5b520d2f3b.js +1 -0
  24. signalpilot_ai_internal-0.10.22.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/remoteEntry.b63c429ca81e743b403c.js +1 -0
  25. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/third-party-licenses.json +38 -20
  26. {signalpilot_ai_internal-0.7.6.dist-info → signalpilot_ai_internal-0.10.22.dist-info}/METADATA +3 -2
  27. signalpilot_ai_internal-0.10.22.dist-info/RECORD +56 -0
  28. {signalpilot_ai_internal-0.7.6.dist-info → signalpilot_ai_internal-0.10.22.dist-info}/WHEEL +1 -1
  29. signalpilot_ai_internal-0.7.6.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/353.72484b768a04f89bd3dd.js +0 -1
  30. signalpilot_ai_internal-0.7.6.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/476.9b4f05a99f5003f82094.js +0 -1
  31. signalpilot_ai_internal-0.7.6.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/490.b4ccb9601c8112407c5d.js +0 -1
  32. signalpilot_ai_internal-0.7.6.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/785.3aa564fc148b37d1d719.js +0 -1
  33. signalpilot_ai_internal-0.7.6.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/839.ed04fa601a43e8dd24d1.js +0 -1
  34. signalpilot_ai_internal-0.7.6.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/898.4e9edb7f224152c1dcb4.js +0 -2
  35. signalpilot_ai_internal-0.7.6.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/898.4e9edb7f224152c1dcb4.js.LICENSE.txt +0 -1
  36. signalpilot_ai_internal-0.7.6.data/data/share/jupyter/labextensions/signalpilot-ai-internal/static/remoteEntry.ee8951353b00c13b8070.js +0 -1
  37. signalpilot_ai_internal-0.7.6.dist-info/RECORD +0 -49
  38. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/etc/jupyter/jupyter_server_config.d/signalpilot_ai.json +0 -0
  39. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/install.json +0 -0
  40. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/122.e2dadf63dc64d7b5f1ee.js +0 -0
  41. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/220.328403b5545f268b95c6.js +0 -0
  42. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/262.726e1da31a50868cb297.js +0 -0
  43. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/364.dbec4c2dc12e7b050dcc.js +0 -0
  44. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/384.fa432bdb7fb6b1c95ad6.js +0 -0
  45. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/439.37e271d7a80336daabe2.js +0 -0
  46. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/481.73c7a9290b7d35a8b9c1.js +0 -0
  47. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/512.b58fc0093d080b8ee61c.js +0 -0
  48. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/553.b4042a795c91d9ff71ef.js +0 -0
  49. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/553.b4042a795c91d9ff71ef.js.LICENSE.txt +0 -0
  50. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/635.9720593ee20b768da3ca.js +0 -0
  51. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/713.8e6edc9a965bdd578ca7.js +0 -0
  52. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/741.dc49867fafb03ea2ba4d.js +0 -0
  53. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/742.91e7b516c8699eea3373.js +0 -0
  54. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/888.34054db17bcf6e87ec95.js +0 -0
  55. {signalpilot_ai_internal-0.7.6.data → signalpilot_ai_internal-0.10.22.data}/data/share/jupyter/labextensions/signalpilot-ai-internal/static/style.js +0 -0
  56. {signalpilot_ai_internal-0.7.6.dist-info → signalpilot_ai_internal-0.10.22.dist-info}/licenses/LICENSE +0 -0
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunksignalpilot_ai_internal=self.webpackChunksignalpilot_ai_internal||[]).push([[785],{45785:(e,t,i)=>{i.r(t),i.d(t,{EditorView:()=>o.EditorView,basicSetup:()=>Nt,minimalSetup:()=>Ht});var o=i(45024),n=i(60195),s=i(72084),r=i(44353);function l(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var o in i)if(Object.prototype.hasOwnProperty.call(i,o)){var n=i[o];"string"==typeof n?e.setAttribute(o,n):null!=n&&(e[o]=n)}t++}for(;t<arguments.length;t++)a(e,arguments[t]);return e}function a(e,t){if("string"==typeof t)e.appendChild(document.createTextNode(t));else if(null==t);else if(null!=t.nodeType)e.appendChild(t);else{if(!Array.isArray(t))throw new RangeError("Unsupported child node: "+t);for(var i=0;i<t.length;i++)a(e,t[i])}}const c="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class h{constructor(e,t,i=0,o=e.length,n,s){this.test=s,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,o),this.bufferStart=i,this.normalize=n?e=>n(c(e)):c,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return(0,n.codePointAt)(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=(0,n.fromCodePoint)(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=(0,n.codePointSize)(e);let o=this.normalize(t);if(o.length)for(let e=0,n=i;;e++){let s=o.charCodeAt(e),r=this.match(s,n,this.bufferPos+this.bufferStart);if(e==o.length-1){if(r)return this.value=r,this;break}n==i&&e<t.length&&t.charCodeAt(e)==s&&n++}}}match(e,t,i){let o=null;for(let t=0;t<this.matches.length;t+=2){let n=this.matches[t],s=!1;this.query.charCodeAt(n)==e&&(n==this.query.length-1?o={from:this.matches[t+1],to:i}:(this.matches[t]++,s=!0)),s||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(1==this.query.length?o={from:t,to:i}:this.matches.push(1,t)),o&&this.test&&!this.test(o.from,o.to,this.buffer,this.bufferStart)&&(o=null),o}}"undefined"!=typeof Symbol&&(h.prototype[Symbol.iterator]=function(){return this});const d={from:-1,to:-1,match:/.*/.exec("")},u="gm"+(null==/x/.unicode?"":"u");class f{constructor(e,t,i,o=0,n=e.length){if(this.text=e,this.to=n,this.curLine="",this.done=!1,this.value=d,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new g(e,t,i,o,n);this.re=new RegExp(t,u+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.iter=e.iter();let s=e.lineAt(o);this.curLineStart=s.from,this.matchPos=v(e,o),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(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 i=this.curLineStart+t.index,o=i+t[0].length;if(this.matchPos=v(this.text,o+(i==o?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<o||i>this.value.to)&&(!this.test||this.test(i,o,t)))return this.value={from:i,to:o,match:t},this;e=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to))return this.done=!0,this;this.nextLine(),e=0}}}}const p=new WeakMap;class m{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let o=p.get(e);if(!o||o.from>=i||o.to<=t){let o=new m(t,e.sliceString(t,i));return p.set(e,o),o}if(o.from==t&&o.to==i)return o;let{text:n,from:s}=o;return s>t&&(n=e.sliceString(t,s)+n,s=t),o.to<i&&(n+=e.sliceString(o.to,i)),p.set(e,new m(s,n)),new m(t,n.slice(t-s,i-s))}}class g{constructor(e,t,i,o,n){this.text=e,this.to=n,this.done=!1,this.value=d,this.matchPos=v(e,o),this.re=new RegExp(t,u+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.flat=m.get(e,o,this.chunkEnd(o+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,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)),t){let e=this.flat.from+t.index,i=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,i,t)))return this.value={from:e,to:i,match:t},this.matchPos=v(this.text,i+(e==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=m.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function v(e,t){if(t>=e.length)return t;let i,o=e.lineAt(t);for(;t<o.to&&(i=o.text.charCodeAt(t-o.from))>=56320&&i<57344;)t++;return t}function b(e){let t=l("input",{class:"cm-textfield",name:"line",value:String(e.state.doc.lineAt(e.state.selection.main.head).number)});function i(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.value);if(!i)return;let{state:s}=e,r=s.doc.lineAt(s.selection.main.head),[,l,a,c,h]=i,d=c?+c.slice(1):0,u=a?+a:r.number;if(a&&h){let e=u/100;l&&(e=e*("-"==l?-1:1)+r.number/s.doc.lines),u=Math.round(s.doc.lines*e)}else a&&l&&(u=u*("-"==l?-1:1)+r.number);let f=s.doc.line(Math.max(1,Math.min(s.doc.lines,u))),p=n.EditorSelection.cursor(f.from+Math.max(0,Math.min(d,f.length)));e.dispatch({effects:[w.of(!1),o.EditorView.scrollIntoView(p.from,{y:"center"})],selection:p}),e.focus()}return{dom:l("form",{class:"cm-gotoLine",onkeydown:t=>{27==t.keyCode?(t.preventDefault(),e.dispatch({effects:w.of(!1)}),e.focus()):13==t.keyCode&&(t.preventDefault(),i())},onsubmit:e=>{e.preventDefault(),i()}},l("label",e.state.phrase("Go to line"),": ",t)," ",l("button",{class:"cm-button",type:"submit"},e.state.phrase("go")),l("button",{name:"close",onclick:()=>{e.dispatch({effects:w.of(!1)}),e.focus()},"aria-label":e.state.phrase("close"),type:"button"},["×"]))}}"undefined"!=typeof Symbol&&(f.prototype[Symbol.iterator]=g.prototype[Symbol.iterator]=function(){return this});const w=n.StateEffect.define(),y=n.StateField.define({create:()=>!0,update(e,t){for(let i of t.effects)i.is(w)&&(e=i.value);return e},provide:e=>o.showPanel.from(e,e=>e?b:null)}),x=o.EditorView.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}}}),C={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},S=n.Facet.define({combine:e=>(0,n.combineConfig)(e,C,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})});function k(e){let t=[P,D];return e&&t.push(S.of(e)),t}const E=o.Decoration.mark({class:"cm-selectionMatch"}),M=o.Decoration.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function A(e,t,i,o){return!(0!=i&&e(t.sliceDoc(i-1,i))==n.CharCategory.Word||o!=t.doc.length&&e(t.sliceDoc(o,o+1))==n.CharCategory.Word)}const D=o.ViewPlugin.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(S),{state:i}=e,s=i.selection;if(s.ranges.length>1)return o.Decoration.none;let r,l=s.main,a=null;if(l.empty){if(!t.highlightWordAroundCursor)return o.Decoration.none;let e=i.wordAt(l.head);if(!e)return o.Decoration.none;a=i.charCategorizer(l.head),r=i.sliceDoc(e.from,e.to)}else{let e=l.to-l.from;if(e<t.minSelectionLength||e>200)return o.Decoration.none;if(t.wholeWords){if(r=i.sliceDoc(l.from,l.to),a=i.charCategorizer(l.head),!A(a,i,l.from,l.to)||!function(e,t,i,o){return e(t.sliceDoc(i,i+1))==n.CharCategory.Word&&e(t.sliceDoc(o-1,o))==n.CharCategory.Word}(a,i,l.from,l.to))return o.Decoration.none}else if(r=i.sliceDoc(l.from,l.to),!r)return o.Decoration.none}let c=[];for(let n of e.visibleRanges){let e=new h(i.doc,r,n.from,n.to);for(;!e.next().done;){let{from:n,to:s}=e.value;if((!a||A(a,i,n,s))&&(l.empty&&n<=l.from&&s>=l.to?c.push(M.range(n,s)):(n>=l.to||s<=l.from)&&c.push(E.range(n,s)),c.length>t.maxMatches))return o.Decoration.none}}return o.Decoration.set(c)}},{decorations:e=>e.decorations}),P=o.EditorView.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),I=n.Facet.define({combine:e=>(0,n.combineConfig)(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new se(e),scrollToMatch:e=>o.EditorView.scrollIntoView(e)})});class L{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||function(e){try{return new RegExp(e,u),!0}catch(e){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>"n"==t?"\n":"r"==t?"\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 B(this):new T(this)}getCursor(e,t=0,i){let o=e.doc?e:n.EditorState.create({doc:e});return null==i&&(i=o.doc.length),this.regexp?F(this,o,t,i):O(this,o,t,i)}}class R{constructor(e){this.spec=e}}function O(e,t,i,o){return new h(t.doc,e.unquoted,i,o,e.caseSensitive?void 0:e=>e.toLowerCase(),e.wholeWord?(s=t.doc,r=t.charCategorizer(t.selection.main.head),(e,t,i,o)=>((o>e||o+i.length<t)&&(o=Math.max(0,e-2),i=s.sliceString(o,Math.min(s.length,t+2))),!(r(q(i,e-o))==n.CharCategory.Word&&r(W(i,e-o))==n.CharCategory.Word||r(W(i,t-o))==n.CharCategory.Word&&r(q(i,t-o))==n.CharCategory.Word))):void 0);var s,r}class T extends R{constructor(e){super(e)}nextMatch(e,t,i){let o=O(this.spec,e,i,e.doc.length).nextOverlapping();if(o.done){let i=Math.min(e.doc.length,t+this.spec.unquoted.length);o=O(this.spec,e,0,i).nextOverlapping()}return o.done||o.value.from==t&&o.value.to==i?null:o.value}prevMatchInRange(e,t,i){for(let o=i;;){let i=Math.max(t,o-1e4-this.spec.unquoted.length),n=O(this.spec,e,i,o),s=null;for(;!n.nextOverlapping().done;)s=n.value;if(s)return s;if(i==t)return null;o-=1e4}}prevMatch(e,t,i){let o=this.prevMatchInRange(e,0,t);return o||(o=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),!o||o.from==t&&o.to==i?null:o}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=O(this.spec,e,0,e.doc.length),o=[];for(;!i.next().done;){if(o.length>=t)return null;o.push(i.value)}return o}highlight(e,t,i,o){let n=O(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!n.next().done;)o(n.value.from,n.value.to)}}function F(e,t,i,o){return new f(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:e.wholeWord?(s=t.charCategorizer(t.selection.main.head),(e,t,i)=>!i[0].length||(s(q(i.input,i.index))!=n.CharCategory.Word||s(W(i.input,i.index))!=n.CharCategory.Word)&&(s(W(i.input,i.index+i[0].length))!=n.CharCategory.Word||s(q(i.input,i.index+i[0].length))!=n.CharCategory.Word)):void 0},i,o);var s}function q(e,t){return e.slice((0,n.findClusterBreak)(e,t,!1),t)}function W(e,t){return e.slice(t,(0,n.findClusterBreak)(e,t))}class B extends R{nextMatch(e,t,i){let o=F(this.spec,e,i,e.doc.length).next();return o.done&&(o=F(this.spec,e,0,t).next()),o.done?null:o.value}prevMatchInRange(e,t,i){for(let o=1;;o++){let n=Math.max(t,i-1e4*o),s=F(this.spec,e,n,i),r=null;for(;!s.next().done;)r=s.value;if(r&&(n==t||r.from>n+10))return r;if(n==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if("&"==i)return e.match[0];if("$"==i)return"$";for(let t=i.length;t>0;t--){let o=+i.slice(0,t);if(o>0&&o<e.match.length)return e.match[o]+i.slice(t)}return t})}matchAll(e,t){let i=F(this.spec,e,0,e.doc.length),o=[];for(;!i.next().done;){if(o.length>=t)return null;o.push(i.value)}return o}highlight(e,t,i,o){let n=F(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!n.next().done;)o(n.value.from,n.value.to)}}const $=n.StateEffect.define(),V=n.StateEffect.define(),z=n.StateField.define({create:e=>new N(J(e).create(),null),update(e,t){for(let i of t.effects)i.is($)?e=new N(i.value.create(),e.panel):i.is(V)&&(e=new N(e.query,i.value?Z:null));return e},provide:e=>o.showPanel.from(e,e=>e.panel)});class N{constructor(e,t){this.query=e,this.panel=t}}const H=o.Decoration.mark({class:"cm-searchMatch"}),U=o.Decoration.mark({class:"cm-searchMatch cm-searchMatch-selected"}),j=o.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(z))}update(e){let t=e.state.field(z);(t!=e.startState.field(z)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return o.Decoration.none;let{view:i}=this,s=new n.RangeSetBuilder;for(let t=0,o=i.visibleRanges,n=o.length;t<n;t++){let{from:r,to:l}=o[t];for(;t<n-1&&l>o[t+1].from-500;)l=o[++t].to;e.highlight(i.state,r,l,(e,t)=>{let o=i.state.selection.ranges.some(i=>i.from==e&&i.to==t);s.add(e,t,o?U:H)})}return s.finish()}},{decorations:e=>e.decorations});function K(e){return t=>{let i=t.state.field(z,!1);return i&&i.query.spec.valid?e(t,i):ie(t)}}const _=K((e,{query:t})=>{let{to:i}=e.state.selection.main,o=t.nextMatch(e.state,i,i);if(!o)return!1;let s=n.EditorSelection.single(o.from,o.to),r=e.state.facet(I);return e.dispatch({selection:s,effects:[ce(e,o),r.scrollToMatch(s.main,e)],userEvent:"select.search"}),te(e),!0}),Q=K((e,{query:t})=>{let{state:i}=e,{from:o}=i.selection.main,s=t.prevMatch(i,o,o);if(!s)return!1;let r=n.EditorSelection.single(s.from,s.to),l=e.state.facet(I);return e.dispatch({selection:r,effects:[ce(e,s),l.scrollToMatch(r.main,e)],userEvent:"select.search"}),te(e),!0}),G=K((e,{query:t})=>{let i=t.matchAll(e.state,1e3);return!(!i||!i.length||(e.dispatch({selection:n.EditorSelection.create(i.map(e=>n.EditorSelection.range(e.from,e.to))),userEvent:"select.search.matches"}),0))}),X=K((e,{query:t})=>{let{state:i}=e,{from:s,to:r}=i.selection.main;if(i.readOnly)return!1;let l=t.nextMatch(i,s,s);if(!l)return!1;let a,c,h=l,d=[],u=[];h.from==s&&h.to==r&&(c=i.toText(t.getReplacement(h)),d.push({from:h.from,to:h.to,insert:c}),h=t.nextMatch(i,h.from,h.to),u.push(o.EditorView.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(s).number)+".")));let f=e.state.changes(d);return h&&(a=n.EditorSelection.single(h.from,h.to).map(f),u.push(ce(e,h)),u.push(i.facet(I).scrollToMatch(a.main,e))),e.dispatch({changes:f,selection:a,effects:u,userEvent:"input.replace"}),!0}),Y=K((e,{query:t})=>{if(e.state.readOnly)return!1;let i=t.matchAll(e.state,1e9).map(e=>{let{from:i,to:o}=e;return{from:i,to:o,insert:t.getReplacement(e)}});if(!i.length)return!1;let n=e.state.phrase("replaced $ matches",i.length)+".";return e.dispatch({changes:i,effects:o.EditorView.announce.of(n),userEvent:"input.replace.all"}),!0});function Z(e){return e.state.facet(I).createPanel(e)}function J(e,t){var i,o,n,s,r;let l=e.selection.main,a=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!a)return t;let c=e.facet(I);return new L({search:(null!==(i=null==t?void 0:t.literal)&&void 0!==i?i:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:null!==(o=null==t?void 0:t.caseSensitive)&&void 0!==o?o:c.caseSensitive,literal:null!==(n=null==t?void 0:t.literal)&&void 0!==n?n:c.literal,regexp:null!==(s=null==t?void 0:t.regexp)&&void 0!==s?s:c.regexp,wholeWord:null!==(r=null==t?void 0:t.wholeWord)&&void 0!==r?r:c.wholeWord})}function ee(e){let t=(0,o.getPanel)(e,Z);return t&&t.dom.querySelector("[main-field]")}function te(e){let t=ee(e);t&&t==e.root.activeElement&&t.select()}const ie=e=>{let t=e.state.field(z,!1);if(t&&t.panel){let i=ee(e);if(i&&i!=e.root.activeElement){let o=J(e.state,t.query.spec);o.valid&&e.dispatch({effects:$.of(o)}),i.focus(),i.select()}}else e.dispatch({effects:[V.of(!0),t?$.of(J(e.state,t.query.spec)):n.StateEffect.appendConfig.of(de)]});return!0},oe=e=>{let t=e.state.field(z,!1);if(!t||!t.panel)return!1;let i=(0,o.getPanel)(e,Z);return i&&i.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:V.of(!1)}),!0},ne=[{key:"Mod-f",run:ie,scope:"editor search-panel"},{key:"F3",run:_,shift:Q,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:_,shift:Q,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:oe,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:e,dispatch:t})=>{let i=e.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:o,to:s}=i.main,r=[],l=0;for(let t=new h(e.doc,e.sliceDoc(o,s));!t.next().done;){if(r.length>1e3)return!1;t.value.from==o&&(l=r.length),r.push(n.EditorSelection.range(t.value.from,t.value.to))}return t(e.update({selection:n.EditorSelection.create(r,l),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:e=>{let t=(0,o.getPanel)(e,b);if(!t){let i=[w.of(!0)];null==e.state.field(y,!1)&&i.push(n.StateEffect.appendConfig.of([y,x])),e.dispatch({effects:i}),t=(0,o.getPanel)(e,b)}return t&&t.dom.querySelector("input").select(),!0}},{key:"Mod-d",run:({state:e,dispatch:t})=>{let{ranges:i}=e.selection;if(i.some(e=>e.from===e.to))return(({state:e,dispatch:t})=>{let{selection:i}=e,o=n.EditorSelection.create(i.ranges.map(t=>e.wordAt(t.head)||n.EditorSelection.cursor(t.head)),i.mainIndex);return!o.eq(i)&&(t(e.update({selection:o})),!0)})({state:e,dispatch:t});let s=e.sliceDoc(i[0].from,i[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=s))return!1;let r=function(e,t){let{main:i,ranges:o}=e.selection,n=e.wordAt(i.head),s=n&&n.from==i.from&&n.to==i.to;for(let i=!1,n=new h(e.doc,t,o[o.length-1].to);;){if(n.next(),!n.done){if(i&&o.some(e=>e.from==n.value.from))continue;if(s){let t=e.wordAt(n.value.from);if(!t||t.from!=n.value.from||t.to!=n.value.to)continue}return n.value}if(i)return null;n=new h(e.doc,t,0,Math.max(0,o[o.length-1].from-1)),i=!0}}(e,s);return!!r&&(t(e.update({selection:e.selection.addRange(n.EditorSelection.range(r.from,r.to),!1),effects:o.EditorView.scrollIntoView(r.to)})),!0)},preventDefault:!0}];class se{constructor(e){this.view=e;let t=this.query=e.state.field(z).query.spec;function i(e,t,i){return l("button",{class:"cm-button",name:e,onclick:t,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=l("input",{value:t.search,placeholder:re(e,"Find"),"aria-label":re(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=l("input",{value:t.replace,placeholder:re(e,"Replace"),"aria-label":re(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=l("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=l("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=l("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit}),this.dom=l("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,i("next",()=>_(e),[re(e,"next")]),i("prev",()=>Q(e),[re(e,"previous")]),i("select",()=>G(e),[re(e,"all")]),l("label",null,[this.caseField,re(e,"match case")]),l("label",null,[this.reField,re(e,"regexp")]),l("label",null,[this.wordField,re(e,"by word")]),...e.state.readOnly?[]:[l("br"),this.replaceField,i("replace",()=>X(e),[re(e,"replace")]),i("replaceAll",()=>Y(e),[re(e,"replace all")])],l("button",{name:"close",onclick:()=>oe(e),"aria-label":re(e,"close"),type:"button"},["×"])])}commit(){let e=new L({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:$.of(e)}))}keydown(e){(0,o.runScopeHandlers)(this.view,e,"search-panel")?e.preventDefault():13==e.keyCode&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Q:_)(this.view)):13==e.keyCode&&e.target==this.replaceField&&(e.preventDefault(),X(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is($)&&!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(I).top}}function re(e,t){return e.state.phrase(t)}const le=30,ae=/[\s\.,:;?!]/;function ce(e,{from:t,to:i}){let n=e.state.doc.lineAt(t),s=e.state.doc.lineAt(i).to,r=Math.max(n.from,t-le),l=Math.min(s,i+le),a=e.state.sliceDoc(r,l);if(r!=n.from)for(let e=0;e<le;e++)if(!ae.test(a[e+1])&&ae.test(a[e])){a=a.slice(e);break}if(l!=s)for(let e=a.length-1;e>a.length-le;e--)if(!ae.test(a[e-1])&&ae.test(a[e])){a=a.slice(0,e);break}return o.EditorView.announce.of(`${e.state.phrase("current match")}. ${a} ${e.state.phrase("on line")} ${n.number}.`)}const he=o.EditorView.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"}}),de=[z,n.Prec.low(j),he];class ue{constructor(e,t,i,o){this.state=e,this.pos=t,this.explicit=i,this.view=o,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=(0,s.syntaxTree)(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),o=t.text.slice(i-t.from,this.pos-t.from),n=o.search(ge(e,!1));return n<0?null:{from:i+n,to:this.pos,text:o.slice(n)}}get aborted(){return null==this.abortListeners}addEventListener(e,t,i){"abort"==e&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function fe(e){let t=Object.keys(e).join(""),i=/\w/.test(t);return i&&(t=t.replace(/\w/g,"")),`[${i?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}class pe{constructor(e,t,i,o){this.completion=e,this.source=t,this.match=i,this.score=o}}function me(e){return e.selection.main.from}function ge(e,t){var i;let{source:o}=e,n=t&&"^"!=o[0],s="$"!=o[o.length-1];return n||s?new RegExp(`${n?"^":""}(?:${o})${s?"$":""}`,null!==(i=e.flags)&&void 0!==i?i:e.ignoreCase?"i":""):e}const ve=n.Annotation.define();function be(e,t,i,o){let{main:s}=e.selection,r=i-s.from,l=o-s.from;return{...e.changeByRange(a=>{if(a!=s&&i!=o&&e.sliceDoc(a.from+r,a.from+l)!=e.sliceDoc(i,o))return{range:a};let c=e.toText(t);return{changes:{from:a.from+r,to:o==s.from?a.to:a.from+l,insert:c},range:n.EditorSelection.cursor(a.from+r+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const we=new WeakMap;function ye(e){if(!Array.isArray(e))return e;let t=we.get(e);return t||we.set(e,t=function(e){let t=e.map(e=>"string"==typeof e?{label:e}:e),[i,o]=t.every(e=>/^\w+$/.test(e.label))?[/\w*$/,/\w+$/]:function(e){let t=Object.create(null),i=Object.create(null);for(let{label:o}of e){t[o[0]]=!0;for(let e=1;e<o.length;e++)i[o[e]]=!0}let o=fe(t)+fe(i)+"*$";return[new RegExp("^"+o),new RegExp(o)]}(t);return e=>{let n=e.matchBefore(o);return n||e.explicit?{from:n?n.from:e.pos,options:t,validFor:i}:null}}(e)),t}const xe=n.StateEffect.define(),Ce=n.StateEffect.define();class Se{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=(0,n.codePointAt)(e,t),o=(0,n.codePointSize)(i);this.chars.push(i);let s=e.slice(t,t+o),r=s.toUpperCase();this.folded.push((0,n.codePointAt)(r==s?s.toLowerCase():r,0)),t+=o}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(0==this.pattern.length)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:o,precise:s,byWord:r}=this;if(1==t.length){let o=(0,n.codePointAt)(e,0),s=(0,n.codePointSize)(o),r=s==e.length?0:-100;if(o==t[0]);else{if(o!=i[0])return null;r+=-200}return this.ret(r,[0,s])}let l=e.indexOf(this.pattern);if(0==l)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,c=0;if(l<0){for(let s=0,r=Math.min(e.length,200);s<r&&c<a;){let r=(0,n.codePointAt)(e,s);r!=t[c]&&r!=i[c]||(o[c++]=s),s+=(0,n.codePointSize)(r)}if(c<a)return null}let h=0,d=0,u=!1,f=0,p=-1,m=-1,g=/[a-z]/.test(e),v=!0;for(let o=0,c=Math.min(e.length,200),b=0;o<c&&d<a;){let c=(0,n.codePointAt)(e,o);l<0&&(h<a&&c==t[h]&&(s[h++]=o),f<a&&(c==t[f]||c==i[f]?(0==f&&(p=o),m=o+1,f++):f=0));let w,y=c<255?c>=48&&c<=57||c>=97&&c<=122?2:c>=65&&c<=90?1:0:(w=(0,n.fromCodePoint)(c))!=w.toLowerCase()?1:w!=w.toUpperCase()?2:0;(!o||1==y&&g||0==b&&0!=y)&&(t[d]==c||i[d]==c&&(u=!0)?r[d++]=o:r.length&&(v=!1)),b=y,o+=(0,n.codePointSize)(c)}return d==a&&0==r[0]&&v?this.result((u?-200:0)-100,r,e):f==a&&0==p?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):f==a?this.ret(-900-e.length,[p,m]):d==a?this.result((u?-200:0)-100-700+(v?0:-1100),r,e):2==t.length?null:this.result((o[0]?-700:0)-200-1100,o,e)}result(e,t,i){let o=[],s=0;for(let e of t){let t=e+(this.astral?(0,n.codePointSize)((0,n.codePointAt)(i,e)):1);s&&o[s-1]==e?o[s-1]=t:(o[s++]=e,o[s++]=t)}return this.ret(e-i.length,o)}}class ke{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return null==i?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const Ee=n.Facet.define({combine:e=>(0,n.combineConfig)(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Ae,filterStrict:!1,compareCompletions:(e,t)=>e.label.localeCompare(t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>Me(e(i),t(i)),optionClass:(e,t)=>i=>Me(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})});function Me(e,t){return e?t?e+" "+t:e:t}function Ae(e,t,i,n,s,r){let l,a,c=e.textDirection==o.Direction.RTL,h=c,d=!1,u="top",f=t.left-s.left,p=s.right-t.right,m=n.right-n.left,g=n.bottom-n.top;if(h&&f<Math.min(m,p)?h=!1:!h&&p<Math.min(m,f)&&(h=!0),m<=(h?f:p))l=Math.max(s.top,Math.min(i.top,s.bottom-g))-t.top,a=Math.min(400,h?f:p);else{d=!0,a=Math.min(400,(c?t.right:s.right-t.left)-30);let e=s.bottom-t.bottom;e>=g||e>t.top?l=i.bottom-t.top:(u="bottom",l=t.bottom-i.top)}return{style:`${u}: ${l/((t.bottom-t.top)/r.offsetHeight)}px; max-width: ${a/((t.right-t.left)/r.offsetWidth)}px`,class:"cm-completionInfo-"+(d?c?"left-narrow":"right-narrow":h?"left":"right")}}function De(e,t,i){if(e<=i)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let e=Math.floor(t/i);return{from:e*i,to:(e+1)*i}}let o=Math.floor((e-t)/i);return{from:e-(o+1)*i,to:e-o*i}}class Pe{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:e=>this.placeInfo(e),key:this},this.space=null,this.currentClass="";let o=e.state.field(t),{options:n,selected:s}=o.open,r=e.state.facet(Ee);this.optionContent=function(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(e){let t=document.createElement("div");return t.classList.add("cm-completionIcon"),e.type&&t.classList.add(...e.type.split(/\s+/g).map(e=>"cm-completionIcon-"+e)),t.setAttribute("aria-hidden","true"),t},position:20}),t.push({render(e,t,i,o){let n=document.createElement("span");n.className="cm-completionLabel";let s=e.displayLabel||e.label,r=0;for(let e=0;e<o.length;){let t=o[e++],i=o[e++];t>r&&n.appendChild(document.createTextNode(s.slice(r,t)));let l=n.appendChild(document.createElement("span"));l.appendChild(document.createTextNode(s.slice(t,i))),l.className="cm-completionMatchedText",r=i}return r<s.length&&n.appendChild(document.createTextNode(s.slice(r))),n},position:50},{render(e){if(!e.detail)return null;let t=document.createElement("span");return t.className="cm-completionDetail",t.textContent=e.detail,t},position:80}),t.sort((e,t)=>e.position-t.position).map(e=>e.render)}(r),this.optionClass=r.optionClass,this.tooltipClass=r.tooltipClass,this.range=De(n.length,s,r.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",i=>{let{options:o}=e.state.field(t).open;for(let t,n=i.target;n&&n!=this.dom;n=n.parentNode)if("LI"==n.nodeName&&(t=/-(\d+)$/.exec(n.id))&&+t[1]<o.length)return this.applyCompletion(e,o[+t[1]]),void i.preventDefault()}),this.dom.addEventListener("focusout",t=>{let i=e.state.field(this.stateField,!1);i&&i.tooltip&&e.state.facet(Ee).closeOnBlur&&t.relatedTarget!=e.contentDOM&&e.dispatch({effects:Ce.of(null)})}),this.showOptions(n,o.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),o=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=o){let{options:n,selected:s,disabled:r}=i.open;o.open&&o.open.options==n||(this.range=De(n.length,s,e.state.facet(Ee).maxRenderedOptions),this.showOptions(n,i.id)),this.updateSel(),r!=(null===(t=o.open)||void 0===t?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!r)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let e of this.currentClass.split(" "))e&&this.dom.classList.remove(e);for(let e of t.split(" "))e&&this.dom.classList.add(e);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;if((t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=De(t.options.length,t.selected,this.view.state.facet(Ee).maxRenderedOptions),this.showOptions(t.options,e.id)),this.updateSelectedOption(t.selected)){this.destroyInfo();let{completion:i}=t.options[t.selected],{info:n}=i;if(!n)return;let s="string"==typeof n?document.createTextNode(n):n(i);if(!s)return;"then"in s?s.then(t=>{t&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(t,i)}).catch(e=>(0,o.logException)(this.view.state,e,"completion info")):this.addInfoPane(s,i)}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",null!=e.nodeType)i.appendChild(e),this.infoDestroy=null;else{let{dom:t,destroy:o}=e;i.appendChild(t),this.infoDestroy=o||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,o=this.range.from;i;i=i.nextSibling,o++)"LI"==i.nodeName&&i.id?o==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected"):o--;return t&&function(e,t){let i=e.getBoundingClientRect(),o=t.getBoundingClientRect(),n=i.height/e.offsetHeight;o.top<i.top?e.scrollTop-=(i.top-o.top)/n:o.bottom>i.bottom&&(e.scrollTop+=(o.bottom-i.bottom)/n)}(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),o=e.getBoundingClientRect(),n=this.space;if(!n){let e=this.dom.ownerDocument.documentElement;n={left:0,top:0,right:e.clientWidth,bottom:e.clientHeight}}return o.top>Math.min(n.bottom,t.bottom)-10||o.bottom<Math.max(n.top,t.top)+10?null:this.view.state.facet(Ee).positionInfo(this.view,t,o,i,n,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const o=document.createElement("ul");o.id=t,o.setAttribute("role","listbox"),o.setAttribute("aria-expanded","true"),o.setAttribute("aria-label",this.view.state.phrase("Completions")),o.addEventListener("mousedown",e=>{e.target==o&&e.preventDefault()});let n=null;for(let s=i.from;s<i.to;s++){let{completion:r,match:l}=e[s],{section:a}=r;if(a){let e="string"==typeof a?a:a.name;e!=n&&(s>i.from||0==i.from)&&(n=e,"string"!=typeof a&&a.header?o.appendChild(a.header(a)):o.appendChild(document.createElement("completion-section")).textContent=e)}const c=o.appendChild(document.createElement("li"));c.id=t+"-"+s,c.setAttribute("role","option");let h=this.optionClass(r);h&&(c.className=h);for(let e of this.optionContent){let t=e(r,this.view.state,this.view,l);t&&c.appendChild(t)}}return i.from&&o.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&o.classList.add("cm-completionListIncompleteBottom"),o}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Ie(e,t){return i=>new Pe(i,e,t)}function Le(e){return 100*(e.boost||0)+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}class Re{constructor(e,t,i,o,n,s){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=o,this.selected=n,this.disabled=s}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Re(this.options,qe(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,o,n,s){if(o&&!s&&e.some(e=>e.isPending))return o.setDisabled();let r=function(e,t){let i=[],o=null,n=e=>{i.push(e);let{section:t}=e.completion;if(t){o||(o=[]);let e="string"==typeof t?t:t.name;o.some(t=>t.name==e)||o.push("string"==typeof t?{name:e}:t)}},s=t.facet(Ee);for(let o of e)if(o.hasResult()){let e=o.result.getMatch;if(!1===o.result.filter)for(let t of o.result.options)n(new pe(t,o.source,e?e(t):[],1e9-i.length));else{let i,r=t.sliceDoc(o.from,o.to),l=s.filterStrict?new ke(r):new Se(r);for(let t of o.result.options)if(i=l.match(t.label)){let s=t.displayLabel?e?e(t,i.matched):[]:i.matched;n(new pe(t,o.source,s,i.score+(t.boost||0)))}}}if(o){let e=Object.create(null),t=0,n=(e,t)=>{var i,o;return(null!==(i=e.rank)&&void 0!==i?i:1e9)-(null!==(o=t.rank)&&void 0!==o?o:1e9)||(e.name<t.name?-1:1)};for(let i of o.sort(n))t-=1e5,e[i.name]=t;for(let t of i){let{section:i}=t.completion;i&&(t.score+=e["string"==typeof i?i:i.name])}}let r=[],l=null,a=s.compareCompletions;for(let e of i.sort((e,t)=>t.score-e.score||a(e.completion,t.completion))){let t=e.completion;!l||l.label!=t.label||l.detail!=t.detail||null!=l.type&&null!=t.type&&l.type!=t.type||l.apply!=t.apply||l.boost!=t.boost?r.push(e):Le(e.completion)>Le(l)&&(r[r.length-1]=e),l=e.completion}return r}(e,t);if(!r.length)return o&&e.some(e=>e.isPending)?o.setDisabled():null;let l=t.facet(Ee).selectOnOpen?0:-1;if(o&&o.selected!=l&&-1!=o.selected){let e=o.options[o.selected].completion;for(let t=0;t<r.length;t++)if(r[t].completion==e){l=t;break}}return new Re(r,qe(i,l),{pos:e.reduce((e,t)=>t.hasResult()?Math.min(e,t.from):e,1e8),create:je,above:n.aboveCursor},o?o.timestamp:Date.now(),l,!1)}map(e){return new Re(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Re(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class Oe{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new Oe(We,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(e){let{state:t}=e,i=t.facet(Ee),o=(i.override||t.languageDataAt("autocomplete",me(t)).map(ye)).map(t=>(this.active.find(e=>e.source==t)||new $e(t,this.active.some(e=>0!=e.state)?1:0)).update(e,i));o.length==this.active.length&&o.every((e,t)=>e==this.active[t])&&(o=this.active);let n=this.open,s=e.effects.some(e=>e.is(ze));n&&e.docChanged&&(n=n.map(e.changes)),e.selection||o.some(t=>t.hasResult()&&e.changes.touchesRange(t.from,t.to))||!function(e,t){if(e==t)return!0;for(let i=0,o=0;;){for(;i<e.length&&!e[i].hasResult();)i++;for(;o<t.length&&!t[o].hasResult();)o++;let n=i==e.length,s=o==t.length;if(n||s)return n==s;if(e[i++].result!=t[o++].result)return!1}}(o,this.active)||s?n=Re.build(o,t,this.id,n,i,s):n&&n.disabled&&!o.some(e=>e.isPending)&&(n=null),!n&&o.every(e=>!e.isPending)&&o.some(e=>e.hasResult())&&(o=o.map(e=>e.hasResult()?new $e(e.source,0):e));for(let t of e.effects)t.is(Ne)&&(n=n&&n.setSelected(t.value,this.id));return o==this.active&&n==this.open?this:new Oe(o,this.id,n)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Te:Fe}}const Te={"aria-autocomplete":"list"},Fe={};function qe(e,t){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(i["aria-activedescendant"]=e+"-"+t),i}const We=[];function Be(e,t){if(e.isUserEvent("input.complete")){let i=e.annotation(ve);if(i&&t.activateOnCompletion(i))return 12}let i=e.isUserEvent("input.type");return i&&t.activateOnTyping?5:i?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class $e{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return 1==this.state}update(e,t){let i=Be(e,t),o=this;(8&i||16&i&&this.touches(e))&&(o=new $e(o.source,0)),4&i&&0==o.state&&(o=new $e(this.source,1)),o=o.updateFor(e,i);for(let t of e.effects)if(t.is(xe))o=new $e(o.source,1,t.value);else if(t.is(Ce))o=new $e(o.source,0);else if(t.is(ze))for(let e of t.value)e.source==o.source&&(o=e);return o}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(me(e.state))}}class Ve extends $e{constructor(e,t,i,o,n,s){super(e,3,t),this.limit=i,this.result=o,this.from=n,this.to=s}hasResult(){return!0}updateFor(e,t){var i;if(!(3&t))return this.map(e.changes);let o=this.result;o.map&&!e.changes.empty&&(o=o.map(o,e.changes));let n=e.changes.mapPos(this.from),s=e.changes.mapPos(this.to,1),r=me(e.state);if(r>s||!o||2&t&&(me(e.startState)==this.from||r<this.limit))return new $e(this.source,4&t?1:0);let l=e.changes.mapPos(this.limit);return function(e,t,i,o){if(!e)return!1;let n=t.sliceDoc(i,o);return"function"==typeof e?e(n,i,o,t):ge(e,!0).test(n)}(o.validFor,e.state,n,s)?new Ve(this.source,this.explicit,l,o,n,s):o.update&&(o=o.update(o,n,s,new ue(e.state,r,!1)))?new Ve(this.source,this.explicit,l,o,o.from,null!==(i=o.to)&&void 0!==i?i:me(e.state)):new $e(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new Ve(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new $e(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}const ze=n.StateEffect.define({map:(e,t)=>e.map(e=>e.map(t))}),Ne=n.StateEffect.define(),He=n.StateField.define({create:()=>Oe.start(),update:(e,t)=>e.update(t),provide:e=>[o.showTooltip.from(e,e=>e.tooltip),o.EditorView.contentAttributes.from(e,e=>e.attrs)]});function Ue(e,t){const i=t.completion.apply||t.completion.label;let o=e.state.field(He).active.find(e=>e.source==t.source);return o instanceof Ve&&("string"==typeof i?e.dispatch({...be(e.state,i,o.from,o.to),annotations:ve.of(t.completion)}):i(e,t.completion,o.from,o.to),!0)}const je=Ie(He,Ue);function Ke(e,t="option"){return i=>{let n=i.state.field(He,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp<i.state.facet(Ee).interactionDelay)return!1;let s,r=1;"page"==t&&(s=(0,o.getTooltip)(i,n.open.tooltip))&&(r=Math.max(2,Math.floor(s.dom.offsetHeight/s.dom.querySelector("li").offsetHeight)-1));let{length:l}=n.open.options,a=n.open.selected>-1?n.open.selected+r*(e?1:-1):e?0:l-1;return a<0?a="page"==t?0:l-1:a>=l&&(a="page"==t?l-1:0),i.dispatch({effects:Ne.of(a)}),!0}}const _e=e=>!!e.state.field(He,!1)&&(e.dispatch({effects:xe.of(!0)}),!0);class Qe{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const Ge=o.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(He).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(He),i=e.state.facet(Ee);if(!e.selectionSet&&!e.docChanged&&e.startState.field(He)==t)return;let n=e.transactions.some(e=>{let t=Be(e,i);return 8&t||(e.selection||e.docChanged)&&!(3&t)});for(let t=0;t<this.running.length;t++){let i=this.running[t];if(n||i.context.abortOnDocChange&&e.docChanged||i.updates.length+e.transactions.length>50&&Date.now()-i.time>1e3){for(let e of i.context.abortListeners)try{e()}catch(e){(0,o.logException)(this.view.state,e)}i.context.abortListeners=null,this.running.splice(t--,1)}else i.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(e=>e.effects.some(e=>e.is(xe)))&&(this.pendingStart=!0);let s=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(e=>e.isPending&&!this.running.some(t=>t.active.source==e.source))?setTimeout(()=>this.startUpdate(),s):-1,0!=this.composing)for(let t of e.transactions)t.isUserEvent("input.type")?this.composing=2:2==this.composing&&t.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(He);for(let e of t.active)e.isPending&&!this.running.some(t=>t.active.source==e.source)&&this.startQuery(e);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Ee).updateSyncTime))}startQuery(e){let{state:t}=this.view,i=me(t),n=new ue(t,i,e.explicit,this.view),s=new Qe(e,n);this.running.push(s),Promise.resolve(e.source(n)).then(e=>{s.context.aborted||(s.done=e||null,this.scheduleAccept())},e=>{this.view.dispatch({effects:Ce.of(null)}),(0,o.logException)(this.view.state,e)})}scheduleAccept(){this.running.every(e=>void 0!==e.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Ee).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],i=this.view.state.facet(Ee),o=this.view.state.field(He);for(let n=0;n<this.running.length;n++){let s=this.running[n];if(void 0===s.done)continue;if(this.running.splice(n--,1),s.done){let o=me(s.updates.length?s.updates[0].startState:this.view.state),n=Math.min(o,s.done.from+(s.active.explicit?0:1)),r=new Ve(s.active.source,s.active.explicit,n,s.done,s.done.from,null!==(e=s.done.to)&&void 0!==e?e:o);for(let e of s.updates)r=r.update(e,i);if(r.hasResult()){t.push(r);continue}}let r=o.active.find(e=>e.source==s.active.source);if(r&&r.isPending)if(null==s.done){let e=new $e(s.active.source,0);for(let t of s.updates)e=e.update(t,i);e.isPending||t.push(e)}else this.startQuery(r)}(t.length||o.open&&o.open.disabled)&&this.view.dispatch({effects:ze.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(He,!1);if(t&&t.tooltip&&this.view.state.facet(Ee).closeOnBlur){let i=t.open&&(0,o.getTooltip)(this.view,t.open.tooltip);i&&i.dom.contains(e.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:Ce.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:xe.of(!1)}),20),this.composing=0}}}),Xe="object"==typeof navigator&&/Win/.test(navigator.platform),Ye=n.Prec.highest(o.EditorView.domEventHandlers({keydown(e,t){let i=t.state.field(He,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||e.key.length>1||e.ctrlKey&&(!Xe||!e.altKey)||e.metaKey)return!1;let o=i.open.options[i.open.selected],n=i.active.find(e=>e.source==o.source),s=o.completion.commitCharacters||n.result.commitCharacters;return s&&s.indexOf(e.key)>-1&&Ue(t,o),!1}})),Ze=o.EditorView.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),Je={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},et=n.StateEffect.define({map(e,t){let i=t.mapPos(e,-1,n.MapMode.TrackAfter);return null==i?void 0:i}}),tt=new class extends n.RangeValue{};tt.startSide=1,tt.endSide=-1;const it=n.StateField.define({create:()=>n.RangeSet.empty,update(e,t){if(e=e.map(t.changes),t.selection){let i=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:e=>e>=i.from&&e<=i.to})}for(let i of t.effects)i.is(et)&&(e=e.update({add:[tt.range(i.value,i.value+1)]}));return e}}),ot="()[]{}<>«»»«[]{}";function nt(e){for(let t=0;t<16;t+=2)if(ot.charCodeAt(t)==e)return ot.charAt(t+1);return(0,n.fromCodePoint)(e<128?e:e+1)}function st(e,t){return e.languageDataAt("closeBrackets",t)[0]||Je}const rt="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),lt=o.EditorView.inputHandler.of((e,t,i,o)=>{if((rt?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let s=e.state.selection.main;if(o.length>2||2==o.length&&1==(0,n.codePointSize)((0,n.codePointAt)(o,0))||t!=s.from||i!=s.to)return!1;let r=function(e,t){let i=st(e,e.selection.main.head),o=i.brackets||Je.brackets;for(let s of o){let r=nt((0,n.codePointAt)(s,0));if(t==s)return r==s?ft(e,s,o.indexOf(s+s+s)>-1,i):dt(e,s,r,i.before||Je.before);if(t==r&&ct(e,e.selection.main.from))return ut(e,0,r)}return null}(e.state,o);return!!r&&(e.dispatch(r),!0)}),at=[{key:"Backspace",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=st(e,e.selection.main.head).brackets||Je.brackets,o=null,s=e.changeByRange(t=>{if(t.empty){let o=function(e,t){let i=e.sliceString(t-2,t);return(0,n.codePointSize)((0,n.codePointAt)(i,0))==i.length?i:i.slice(1)}(e.doc,t.head);for(let s of i)if(s==o&&ht(e.doc,t.head)==nt((0,n.codePointAt)(s,0)))return{changes:{from:t.head-s.length,to:t.head+s.length},range:n.EditorSelection.cursor(t.head-s.length)}}return{range:o=t}});return o||t(e.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!o}}];function ct(e,t){let i=!1;return e.field(it).between(0,e.doc.length,e=>{e==t&&(i=!0)}),i}function ht(e,t){let i=e.sliceString(t,t+2);return i.slice(0,(0,n.codePointSize)((0,n.codePointAt)(i,0)))}function dt(e,t,i,o){let s=null,r=e.changeByRange(r=>{if(!r.empty)return{changes:[{insert:t,from:r.from},{insert:i,from:r.to}],effects:et.of(r.to+t.length),range:n.EditorSelection.range(r.anchor+t.length,r.head+t.length)};let l=ht(e.doc,r.head);return!l||/\s/.test(l)||o.indexOf(l)>-1?{changes:{insert:t+i,from:r.head},effects:et.of(r.head+t.length),range:n.EditorSelection.cursor(r.head+t.length)}:{range:s=r}});return s?null:e.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function ut(e,t,i){let o=null,s=e.changeByRange(t=>t.empty&&ht(e.doc,t.head)==i?{changes:{from:t.head,to:t.head+i.length,insert:i},range:n.EditorSelection.cursor(t.head+i.length)}:o={range:t});return o?null:e.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function ft(e,t,i,o){let r=o.stringPrefixes||Je.stringPrefixes,l=null,a=e.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:t,from:o.to}],effects:et.of(o.to+t.length),range:n.EditorSelection.range(o.anchor+t.length,o.head+t.length)};let a,c=o.head,h=ht(e.doc,c);if(h==t){if(pt(e,c))return{changes:{insert:t+t,from:c},effects:et.of(c+t.length),range:n.EditorSelection.cursor(c+t.length)};if(ct(e,c)){let o=i&&e.sliceDoc(c,c+3*t.length)==t+t+t?t+t+t:t;return{changes:{from:c,to:c+o.length,insert:o},range:n.EditorSelection.cursor(c+o.length)}}}else{if(i&&e.sliceDoc(c-2*t.length,c)==t+t&&(a=mt(e,c-2*t.length,r))>-1&&pt(e,a))return{changes:{insert:t+t+t+t,from:c},effects:et.of(c+t.length),range:n.EditorSelection.cursor(c+t.length)};if(e.charCategorizer(c)(h)!=n.CharCategory.Word&&mt(e,c,r)>-1&&!function(e,t,i,o){let n=(0,s.syntaxTree)(e).resolveInner(t,-1),r=o.reduce((e,t)=>Math.max(e,t.length),0);for(let s=0;s<5;s++){let s=e.sliceDoc(n.from,Math.min(n.to,n.from+i.length+r)),l=s.indexOf(i);if(!l||l>-1&&o.indexOf(s.slice(0,l))>-1){let t=n.firstChild;for(;t&&t.from==n.from&&t.to-t.from>i.length+l;){if(e.sliceDoc(t.to-i.length,t.to)==i)return!1;t=t.firstChild}return!0}let a=n.to==t&&n.parent;if(!a)break;n=a}return!1}(e,c,t,r))return{changes:{insert:t+t,from:c},effects:et.of(c+t.length),range:n.EditorSelection.cursor(c+t.length)}}return{range:l=o}});return l?null:e.update(a,{scrollIntoView:!0,userEvent:"input.type"})}function pt(e,t){let i=(0,s.syntaxTree)(e).resolveInner(t+1);return i.parent&&i.from==t}function mt(e,t,i){let o=e.charCategorizer(t);if(o(e.sliceDoc(t-1,t))!=n.CharCategory.Word)return t;for(let s of i){let i=t-s.length;if(e.sliceDoc(i,t)==s&&o(e.sliceDoc(i-1,i))!=n.CharCategory.Word)return i}return-1}function gt(e={}){return[Ye,He,Ee.of(e),Ge,bt,Ze]}const vt=[{key:"Ctrl-Space",run:_e},{mac:"Alt-`",run:_e},{mac:"Alt-i",run:_e},{key:"Escape",run:e=>{let t=e.state.field(He,!1);return!(!t||!t.active.some(e=>0!=e.state)||(e.dispatch({effects:Ce.of(null)}),0))}},{key:"ArrowDown",run:Ke(!0)},{key:"ArrowUp",run:Ke(!1)},{key:"PageDown",run:Ke(!0,"page")},{key:"PageUp",run:Ke(!1,"page")},{key:"Enter",run:e=>{let t=e.state.field(He,!1);return!(e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(Ee).interactionDelay)&&Ue(e,t.open.options[t.open.selected])}}],bt=n.Prec.highest(o.keymap.computeN([Ee],e=>e.facet(Ee).defaultKeymap?[vt]:[]));class wt{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class yt{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let s=i.facet(Lt).markerFilter;s&&(e=s(e,i));let r=e.slice().sort((e,t)=>e.from-t.from||e.to-t.to),l=new n.RangeSetBuilder,a=[],c=0;for(let e=0;;){let t,n,s=e==r.length?null:r[e];if(!s&&!a.length)break;for(a.length?(t=c,n=a.reduce((e,t)=>Math.min(e,t.to),s&&s.from>t?s.from:1e8)):(t=s.from,n=s.to,a.push(s),e++);e<r.length;){let i=r[e];if(i.from!=t||!(i.to>i.from||i.to==t)){n=Math.min(i.from,n);break}a.push(i),e++,n=Math.min(i.to,n)}let h=Vt(a);if(a.some(e=>e.from==e.to||e.from==e.to-1&&i.doc.lineAt(e.from).to==e.from))l.add(t,t,o.Decoration.widget({widget:new Tt(h),diagnostics:a.slice()}));else{let e=a.reduce((e,t)=>t.markClass?e+" "+t.markClass:e,"");l.add(t,n,o.Decoration.mark({class:"cm-lintRange cm-lintRange-"+h+e,diagnostics:a.slice(),inclusiveEnd:a.some(e=>e.to>n)}))}c=n;for(let e=0;e<a.length;e++)a[e].to<=c&&a.splice(e--,1)}let h=l.finish();return new yt(h,t,xt(h))}}function xt(e,t=null,i=0){let o=null;return e.between(i,1e9,(e,i,{spec:n})=>{if(!(t&&n.diagnostics.indexOf(t)<0))if(o){if(n.diagnostics.indexOf(o.diagnostic)<0)return!1;o=new wt(o.from,i,o.diagnostic)}else o=new wt(e,i,t||n.diagnostics[0])}),o}const Ct=n.StateEffect.define(),St=n.StateEffect.define(),kt=n.StateEffect.define(),Et=n.StateField.define({create:()=>new yt(o.Decoration.none,null,null),update(e,t){if(t.docChanged&&e.diagnostics.size){let i=e.diagnostics.map(t.changes),o=null,n=e.panel;if(e.selected){let n=t.changes.mapPos(e.selected.from,1);o=xt(i,e.selected.diagnostic,n)||xt(i,null,n)}!i.size&&n&&t.state.facet(Lt).autoPanel&&(n=null),e=new yt(i,n,o)}for(let i of t.effects)if(i.is(Ct)){let o=t.state.facet(Lt).autoPanel?i.value.length?qt.open:null:e.panel;e=yt.init(i.value,o,t.state)}else i.is(St)?e=new yt(e.diagnostics,i.value?qt.open:null,e.selected):i.is(kt)&&(e=new yt(e.diagnostics,e.panel,i.value));return e},provide:e=>[o.showPanel.from(e,e=>e.panel),o.EditorView.decorations.from(e,e=>e.diagnostics)]}),Mt=o.Decoration.mark({class:"cm-lintRange cm-lintRange-active"});function At(e,t,i){let o,{diagnostics:n}=e.state.field(Et),s=-1,r=-1;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)))return o=l.diagnostics,s=e,r=n,!1});let l=e.state.facet(Lt).tooltipFilter;return o&&l&&(o=l(o,e.state)),o?{pos:s,end:r,above:e.state.doc.lineAt(s).to<r,create:()=>({dom:Dt(e,o)})}:null}function Dt(e,t){return l("ul",{class:"cm-tooltip-lint"},t.map(t=>Ot(e,t,!1)))}const Pt=e=>{let t=e.state.field(Et,!1);return!(!t||!t.panel||(e.dispatch({effects:St.of(!1)}),0))},It=[{key:"Mod-Shift-m",run:e=>{let t=e.state.field(Et,!1);var i,s;t&&t.panel||e.dispatch({effects:(i=e.state,s=[St.of(!0)],i.field(Et,!1)?s:s.concat(n.StateEffect.appendConfig.of(zt)))});let r=(0,o.getPanel)(e,qt.open);return r&&r.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:e=>{let t=e.state.field(Et,!1);if(!t)return!1;let i=e.state.selection.main,o=t.diagnostics.iter(i.to+1);return!(!o.value&&(o=t.diagnostics.iter(0),!o.value||o.from==i.from&&o.to==i.to)||(e.dispatch({selection:{anchor:o.from,head:o.to},scrollIntoView:!0}),0))}}],Lt=n.Facet.define({combine:e=>Object.assign({sources:e.map(e=>e.source).filter(e=>null!=e)},(0,n.combineConfig)(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t}))});function Rt(e){let t=[];if(e)e:for(let{name:i}of e){for(let e=0;e<i.length;e++){let o=i[e];if(/[a-zA-Z]/.test(o)&&!t.some(e=>e.toLowerCase()==o.toLowerCase())){t.push(o);continue e}}t.push("")}return t}function Ot(e,t,i){var o;let n=i?Rt(t.actions):[];return l("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},l("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),null===(o=t.actions)||void 0===o?void 0:o.map((i,o)=>{let s=!1,r=o=>{if(o.preventDefault(),s)return;s=!0;let n=xt(e.state.field(Et).diagnostics,t);n&&i.apply(e,n.from,n.to)},{name:a}=i,c=n[o]?a.indexOf(n[o]):-1,h=c<0?a:[a.slice(0,c),l("u",a.slice(c,c+1)),a.slice(c+1)];return l("button",{type:"button",class:"cm-diagnosticAction",onclick:r,onmousedown:r,"aria-label":` Action: ${a}${c<0?"":` (access key "${n[o]})"`}.`},h)}),t.source&&l("div",{class:"cm-diagnosticSource"},t.source))}class Tt extends o.WidgetType{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return l("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class Ft{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=Ot(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class qt{constructor(e){this.view=e,this.items=[],this.list=l("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t=>{if(27==t.keyCode)Pt(this.view),this.view.focus();else if(38==t.keyCode||33==t.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==t.keyCode||34==t.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==t.keyCode)this.moveSelection(0);else if(35==t.keyCode)this.moveSelection(this.items.length-1);else if(13==t.keyCode)this.view.focus();else{if(!(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],o=Rt(i.actions);for(let n=0;n<o.length;n++)if(o[n].toUpperCase().charCodeAt(0)==t.keyCode){let t=xt(this.view.state.field(Et).diagnostics,i);t&&i.actions[n].apply(e,t.from,t.to)}}}t.preventDefault()},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=l("div",{class:"cm-panel-lint"},this.list,l("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Pt(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Et).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(Et),i=0,o=!1,n=null,s=new Set;for(e.between(0,this.view.state.doc.length,(e,r,{spec:l})=>{for(let e of l.diagnostics){if(s.has(e))continue;s.add(e);let r,l=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==e){l=t;break}l<0?(r=new Ft(this.view,e),this.items.splice(i,0,r),o=!0):(r=this.items[l],l>i&&(this.items.splice(i,l-i),o=!0)),t&&r.diagnostic==t.diagnostic?r.dom.hasAttribute("aria-selected")||(r.dom.setAttribute("aria-selected","true"),n=r):r.dom.hasAttribute("aria-selected")&&r.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(1==this.items.length&&this.items[0].diagnostic.from<0);)o=!0,this.items.pop();0==this.items.length&&(this.items.push(new Ft(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),o=!0),n?(this.list.setAttribute("aria-activedescendant",n.id),this.view.requestMeasure({key:this,read:()=>({sel:n.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)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),o&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=xt(this.view.state.field(Et).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:kt.of(t)})}static open(e){return new qt(e)}}function Wt(e){return function(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>')`}(`<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 Bt=o.EditorView.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:Wt("#d11")},".cm-lintRange-warning":{backgroundImage:Wt("orange")},".cm-lintRange-info":{backgroundImage:Wt("#999")},".cm-lintRange-hint":{backgroundImage:Wt("#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 $t(e){return"error"==e?4:"warning"==e?3:"info"==e?2:1}function Vt(e){let t="hint",i=1;for(let o of e){let e=$t(o.severity);e>i&&(i=e,t=o.severity)}return t}o.GutterMarker;const zt=[Et,o.EditorView.decorations.compute([Et],e=>{let{selected:t,panel:i}=e.field(Et);return t&&i&&t.from!=t.to?o.Decoration.set([Mt.range(t.from,t.to)]):o.Decoration.none}),(0,o.hoverTooltip)(At,{hideOn:function(e,t){let i=t.pos,o=t.end||i,n=e.state.facet(Lt).hideOn(e,i,o);if(null!=n)return n;let s=e.startState.doc.lineAt(t.pos);return!(!e.effects.some(e=>e.is(Ct))&&!e.changes.touchesRange(s.from,Math.max(s.to,o)))}}),Bt],Nt=(()=>[(0,o.lineNumbers)(),(0,o.highlightActiveLineGutter)(),(0,o.highlightSpecialChars)(),(0,r.b6)(),(0,s.foldGutter)(),(0,o.drawSelection)(),(0,o.dropCursor)(),n.EditorState.allowMultipleSelections.of(!0),(0,s.indentOnInput)(),(0,s.syntaxHighlighting)(s.defaultHighlightStyle,{fallback:!0}),(0,s.bracketMatching)(),[lt,it],gt(),(0,o.rectangularSelection)(),(0,o.crosshairCursor)(),(0,o.highlightActiveLine)(),k(),o.keymap.of([...at,...r.pw,...ne,...r.cL,...s.foldKeymap,...vt,...It])])(),Ht=(()=>[(0,o.highlightSpecialChars)(),(0,r.b6)(),(0,o.drawSelection)(),(0,s.syntaxHighlighting)(s.defaultHighlightStyle,{fallback:!0}),o.keymap.of([...r.pw,...r.cL])])()}}]);