@gsc-basic/components 1.0.1 → 1.0.2

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 (108) hide show
  1. package/README.md +59 -0
  2. package/dist/es/index.js +34 -30
  3. package/dist/es/node_modules/@codemirror/commands/dist/index.js +26 -20
  4. package/dist/es/node_modules/@codemirror/language/dist/index.js +77 -77
  5. package/dist/es/node_modules/@codemirror/search/dist/index.js +432 -465
  6. package/dist/es/node_modules/@codemirror/state/dist/index.js +272 -268
  7. package/dist/es/node_modules/@codemirror/view/dist/index.js +1732 -1647
  8. package/dist/es/node_modules/@lezer/common/dist/index.js +191 -190
  9. package/dist/es/node_modules/@lezer/lr/dist/index.js +3 -3
  10. package/dist/es/node_modules/@tanstack/devtools-event-client/dist/esm/plugin.js +178 -0
  11. package/dist/es/node_modules/@tanstack/form-core/dist/esm/EventClient.js +13 -0
  12. package/dist/es/node_modules/@tanstack/form-core/dist/esm/FieldApi.js +406 -0
  13. package/dist/es/node_modules/@tanstack/form-core/dist/esm/FormApi.js +768 -0
  14. package/dist/es/node_modules/@tanstack/form-core/dist/esm/ValidationLogic.js +55 -0
  15. package/dist/es/node_modules/@tanstack/form-core/dist/esm/metaHelper.js +109 -0
  16. package/dist/es/node_modules/@tanstack/form-core/dist/esm/standardSchemaValidator.js +45 -0
  17. package/dist/es/node_modules/@tanstack/form-core/dist/esm/utils.js +213 -0
  18. package/dist/es/node_modules/@tanstack/pacer-lite/dist/lite-throttler.js +29 -0
  19. package/dist/es/node_modules/@tanstack/store/dist/esm/derived.js +74 -0
  20. package/dist/es/node_modules/@tanstack/store/dist/esm/scheduler.js +79 -0
  21. package/dist/es/node_modules/@tanstack/store/dist/esm/store.js +21 -0
  22. package/dist/es/node_modules/@tanstack/store/dist/esm/types.js +6 -0
  23. package/dist/es/node_modules/@tanstack/table-core/build/lib/index.js +1885 -0
  24. package/dist/es/node_modules/@tanstack/vue-form/dist/esm/useField.js +38 -0
  25. package/dist/es/node_modules/@tanstack/vue-form/dist/esm/useForm.js +33 -0
  26. package/dist/es/node_modules/@tanstack/vue-store/dist/esm/index.js +48 -0
  27. package/dist/es/node_modules/@tanstack/vue-table/build/lib/index.js +159 -0
  28. package/dist/es/src/Grid/index.js +6 -0
  29. package/dist/es/src/Grid/src/Grid.css +1 -0
  30. package/dist/es/src/Grid/src/Grid.vue.js +186 -0
  31. package/dist/es/src/Grid/src/components/ActionBar.css +1 -0
  32. package/dist/es/src/Grid/src/components/ActionBar.vue.js +58 -0
  33. package/dist/es/src/Grid/src/components/CellEditor.css +1 -0
  34. package/dist/es/src/Grid/src/components/CellEditor.vue.js +121 -0
  35. package/dist/es/src/Grid/src/components/CellEditor2.css +1 -0
  36. package/dist/es/src/Grid/src/components/ColumnFilter.css +1 -0
  37. package/dist/es/src/Grid/src/components/ColumnFilter.vue.js +61 -0
  38. package/dist/es/src/Grid/src/components/ColumnSettings.css +1 -0
  39. package/dist/es/src/Grid/src/components/ColumnSettings.vue.js +86 -0
  40. package/dist/es/src/Grid/src/components/DataTable.css +1 -0
  41. package/dist/es/src/Grid/src/components/DataTable.vue.js +533 -0
  42. package/dist/es/src/Grid/src/components/Pager.css +1 -0
  43. package/dist/es/src/Grid/src/components/Pager.vue.js +55 -0
  44. package/dist/es/src/Grid/src/components/QueryBar.css +1 -0
  45. package/dist/es/src/Grid/src/components/QueryBar.vue.js +184 -0
  46. package/dist/es/src/Grid/src/composables/useCellEditor.js +20 -0
  47. package/dist/es/src/Grid/src/composables/useGridTable.js +212 -0
  48. package/dist/es/src/Grid/src/styles/antd.css +1 -0
  49. package/dist/es/src/Grid/src/utils/exportCsv.js +15 -0
  50. package/dist/es/src/index.js +23 -21
  51. package/dist/es/src/locale/lang/en-US.js +40 -0
  52. package/dist/es/src/locale/lang/ja-JP.js +42 -2
  53. package/dist/es/src/locale/lang/zh-CN.js +42 -2
  54. package/dist/es/src/styles/tokens.css +1 -1
  55. package/dist/lib/index.js +1 -1
  56. package/dist/lib/node_modules/@codemirror/commands/dist/index.js +1 -1
  57. package/dist/lib/node_modules/@codemirror/language/dist/index.js +1 -1
  58. package/dist/lib/node_modules/@codemirror/search/dist/index.js +2 -2
  59. package/dist/lib/node_modules/@codemirror/state/dist/index.js +4 -4
  60. package/dist/lib/node_modules/@codemirror/view/dist/index.js +5 -5
  61. package/dist/lib/node_modules/@lezer/common/dist/index.js +1 -1
  62. package/dist/lib/node_modules/@lezer/lr/dist/index.js +1 -1
  63. package/dist/lib/node_modules/@tanstack/devtools-event-client/dist/esm/plugin.js +1 -0
  64. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/EventClient.js +1 -0
  65. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/FieldApi.js +1 -0
  66. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/FormApi.js +1 -0
  67. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/ValidationLogic.js +1 -0
  68. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/metaHelper.js +1 -0
  69. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/standardSchemaValidator.js +1 -0
  70. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/utils.js +1 -0
  71. package/dist/lib/node_modules/@tanstack/pacer-lite/dist/lite-throttler.js +1 -0
  72. package/dist/lib/node_modules/@tanstack/store/dist/esm/derived.js +1 -0
  73. package/dist/lib/node_modules/@tanstack/store/dist/esm/scheduler.js +1 -0
  74. package/dist/lib/node_modules/@tanstack/store/dist/esm/store.js +1 -0
  75. package/dist/lib/node_modules/@tanstack/store/dist/esm/types.js +1 -0
  76. package/dist/lib/node_modules/@tanstack/table-core/build/lib/index.js +4 -0
  77. package/dist/lib/node_modules/@tanstack/vue-form/dist/esm/useField.js +1 -0
  78. package/dist/lib/node_modules/@tanstack/vue-form/dist/esm/useForm.js +1 -0
  79. package/dist/lib/node_modules/@tanstack/vue-store/dist/esm/index.js +1 -0
  80. package/dist/lib/node_modules/@tanstack/vue-table/build/lib/index.js +1 -0
  81. package/dist/lib/src/Grid/index.js +1 -0
  82. package/dist/lib/src/Grid/src/Grid.css +1 -0
  83. package/dist/lib/src/Grid/src/Grid.vue.js +1 -0
  84. package/dist/lib/src/Grid/src/components/ActionBar.css +1 -0
  85. package/dist/lib/src/Grid/src/components/ActionBar.vue.js +1 -0
  86. package/dist/lib/src/Grid/src/components/CellEditor.css +1 -0
  87. package/dist/lib/src/Grid/src/components/CellEditor.vue.js +1 -0
  88. package/dist/lib/src/Grid/src/components/CellEditor2.css +1 -0
  89. package/dist/lib/src/Grid/src/components/ColumnFilter.css +1 -0
  90. package/dist/lib/src/Grid/src/components/ColumnFilter.vue.js +1 -0
  91. package/dist/lib/src/Grid/src/components/ColumnSettings.css +1 -0
  92. package/dist/lib/src/Grid/src/components/ColumnSettings.vue.js +1 -0
  93. package/dist/lib/src/Grid/src/components/DataTable.css +1 -0
  94. package/dist/lib/src/Grid/src/components/DataTable.vue.js +1 -0
  95. package/dist/lib/src/Grid/src/components/Pager.css +1 -0
  96. package/dist/lib/src/Grid/src/components/Pager.vue.js +1 -0
  97. package/dist/lib/src/Grid/src/components/QueryBar.css +1 -0
  98. package/dist/lib/src/Grid/src/components/QueryBar.vue.js +1 -0
  99. package/dist/lib/src/Grid/src/composables/useCellEditor.js +1 -0
  100. package/dist/lib/src/Grid/src/composables/useGridTable.js +1 -0
  101. package/dist/lib/src/Grid/src/styles/antd.css +1 -0
  102. package/dist/lib/src/Grid/src/utils/exportCsv.js +3 -0
  103. package/dist/lib/src/index.js +1 -1
  104. package/dist/lib/src/locale/lang/en-US.js +1 -1
  105. package/dist/lib/src/locale/lang/ja-JP.js +1 -1
  106. package/dist/lib/src/locale/lang/zh-CN.js +1 -1
  107. package/dist/lib/src/styles/tokens.css +1 -1
  108. package/package.json +6 -3
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../state/dist/index.js"),C=require("../../view/dist/index.js"),h=require("../../language/dist/index.js"),G=require("../../../@lezer/common/dist/index.js"),ae=e=>{let{state:t}=e,r=t.doc.lineAt(t.selection.main.from),n=X(e.state,r.from);return n.line?de(e):n.block?me(e):!1};function Q(e,t){return({state:r,dispatch:n})=>{if(r.readOnly)return!1;let l=e(t,r);return l?(n(r.update(l)),!0):!1}}const de=Q(Ot,0),he=Q(pe,0),me=Q((e,t)=>pe(e,t,bt(t)),0);function X(e,t){let r=e.languageDataAt("commentTokens",t,1);return r.length?r[0]:{}}const E=50;function Tt(e,{open:t,close:r},n,l){let o=e.sliceDoc(n-E,n),i=e.sliceDoc(l,l+E),c=/\s*$/.exec(o)[0].length,s=/^\s*/.exec(i)[0].length,a=o.length-c;if(o.slice(a-t.length,a)==t&&i.slice(s,s+r.length)==r)return{open:{pos:n-c,margin:c&&1},close:{pos:l+s,margin:s&&1}};let f,d;l-n<=2*E?f=d=e.sliceDoc(n,l):(f=e.sliceDoc(n,n+E),d=e.sliceDoc(l-E,l));let g=/^\s*/.exec(f)[0].length,T=/\s*$/.exec(d)[0].length,D=d.length-T-r.length;return f.slice(g,g+t.length)==t&&d.slice(D,D+r.length)==r?{open:{pos:n+g+t.length,margin:/\s/.test(f.charAt(g+t.length))?1:0},close:{pos:l-T-r.length,margin:/\s/.test(d.charAt(D-1))?1:0}}:null}function bt(e){let t=[];for(let r of e.selection.ranges){let n=e.doc.lineAt(r.from),l=r.to<=n.to?n:e.doc.lineAt(r.to);l.from>n.from&&l.from==r.to&&(l=r.to==n.to+1?n:e.doc.lineAt(r.to-1));let o=t.length-1;o>=0&&t[o].to>n.from?t[o].to=l.to:t.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:l.to})}return t}function pe(e,t,r=t.selection.ranges){let n=r.map(o=>X(t,o.from).block);if(!n.every(o=>o))return null;let l=r.map((o,i)=>Tt(t,n[i],o.from,o.to));if(e!=2&&!l.every(o=>o))return{changes:t.changes(r.map((o,i)=>l[i]?[]:[{from:o.from,insert:n[i].open+" "},{from:o.to,insert:" "+n[i].close}]))};if(e!=1&&l.some(o=>o)){let o=[];for(let i=0,c;i<l.length;i++)if(c=l[i]){let s=n[i],{open:a,close:f}=c;o.push({from:a.pos-s.open.length,to:a.pos+a.margin},{from:f.pos-f.margin,to:f.pos+s.close.length})}return{changes:o}}return null}function Ot(e,t,r=t.selection.ranges){let n=[],l=-1;for(let{from:o,to:i}of r){let c=n.length,s=1e9,a=X(t,o).line;if(a){for(let f=o;f<=i;){let d=t.doc.lineAt(f);if(d.from>l&&(o==i||i>d.from)){l=d.from;let g=/^\s*/.exec(d.text)[0].length,T=g==d.length,D=d.text.slice(g,g+a.length)==a?g:-1;g<d.text.length&&g<s&&(s=g),n.push({line:d,comment:D,token:a,indent:g,empty:T,single:!1})}f=d.to+1}if(s<1e9)for(let f=c;f<n.length;f++)n[f].indent<n[f].line.text.length&&(n[f].indent=s);n.length==c+1&&(n[c].single=!0)}}if(e!=2&&n.some(o=>o.comment<0&&(!o.empty||o.single))){let o=[];for(let{line:c,token:s,indent:a,empty:f,single:d}of n)(d||!f)&&o.push({from:c.from+a,insert:s+" "});let i=t.changes(o);return{changes:i,selection:t.selection.map(i,1)}}else if(e!=1&&n.some(o=>o.comment>=0)){let o=[];for(let{line:i,comment:c,token:s}of n)if(c>=0){let a=i.from+c,f=a+s.length;i.text[f-i.from]==" "&&f++,o.push({from:a,to:f})}return{changes:o}}return null}const F=u.Annotation.define(),ge=u.Annotation.define(),ye=u.Facet.define(),ke=u.Facet.define({combine(e){return u.combineConfig(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,r)=>r},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,r)=>(n,l)=>t(n,l)||r(n,l)})}}),Se=u.StateField.define({create(){return A.empty},update(e,t){let r=t.state.facet(ke),n=t.annotation(F);if(n){let s=p.fromTransaction(t,n.selection),a=n.side,f=a==0?e.undone:e.done;return s?f=R(f,f.length,r.minDepth,s):f=Ce(f,t.startState.selection),new A(a==0?n.rest:f,a==0?f:n.rest)}let l=t.annotation(ge);if((l=="full"||l=="before")&&(e=e.isolate()),t.annotation(u.Transaction.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let o=p.fromTransaction(t),i=t.annotation(u.Transaction.time),c=t.annotation(u.Transaction.userEvent);return o?e=e.addChanges(o,i,c,r,t):t.selection&&(e=e.addSelection(t.startState.selection,i,c,r.newGroupDelay)),(l=="full"||l=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new A(e.done.map(p.fromJSON),e.undone.map(p.fromJSON))}});function Rt(e={}){return[Se,ke.of(e),C.EditorView.domEventHandlers({beforeinput(t,r){let n=t.inputType=="historyUndo"?Y:t.inputType=="historyRedo"?O:null;return n?(t.preventDefault(),n(r)):!1}})]}function U(e,t){return function({state:r,dispatch:n}){if(!t&&r.readOnly)return!1;let l=r.field(Se,!1);if(!l)return!1;let o=l.pop(e,r,t);return o?(n(o),!0):!1}}const Y=U(0,!1),O=U(1,!1),Be=U(0,!0),Ae=U(1,!0);class p{constructor(t,r,n,l,o){this.changes=t,this.effects=r,this.mapped=n,this.startSelection=l,this.selectionsAfter=o}setSelAfter(t){return new p(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,r,n;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(r=this.mapped)===null||r===void 0?void 0:r.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(l=>l.toJSON())}}static fromJSON(t){return new p(t.changes&&u.ChangeSet.fromJSON(t.changes),[],t.mapped&&u.ChangeDesc.fromJSON(t.mapped),t.startSelection&&u.EditorSelection.fromJSON(t.startSelection),t.selectionsAfter.map(u.EditorSelection.fromJSON))}static fromTransaction(t,r){let n=y;for(let l of t.startState.facet(ye)){let o=l(t);o.length&&(n=n.concat(o))}return!n.length&&t.changes.empty?null:new p(t.changes.invert(t.startState.doc),n,void 0,r||t.startState.selection,y)}static selection(t){return new p(void 0,y,void 0,void 0,t)}}function R(e,t,r,n){let l=t+1>r+20?t-r-1:0,o=e.slice(l,t);return o.push(n),o}function vt(e,t){let r=[],n=!1;return e.iterChangedRanges((l,o)=>r.push(l,o)),t.iterChangedRanges((l,o,i,c)=>{for(let s=0;s<r.length;){let a=r[s++],f=r[s++];c>=a&&i<=f&&(n=!0)}}),n}function It(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((r,n)=>r.empty!=t.ranges[n].empty).length===0}function Le(e,t){return e.length?t.length?e.concat(t):e:t}const y=[],Ut=200;function Ce(e,t){if(e.length){let r=e[e.length-1],n=r.selectionsAfter.slice(Math.max(0,r.selectionsAfter.length-Ut));return n.length&&n[n.length-1].eq(t)?e:(n.push(t),R(e,e.length-1,1e9,r.setSelAfter(n)))}else return[p.selection([t])]}function Pt(e){let t=e[e.length-1],r=e.slice();return r[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),r}function N(e,t){if(!e.length)return e;let r=e.length,n=y;for(;r;){let l=Vt(e[r-1],t,n);if(l.changes&&!l.changes.empty||l.effects.length){let o=e.slice(0,r);return o[r-1]=l,o}else t=l.mapped,r--,n=l.selectionsAfter}return n.length?[p.selection(n)]:y}function Vt(e,t,r){let n=Le(e.selectionsAfter.length?e.selectionsAfter.map(c=>c.map(t)):y,r);if(!e.changes)return p.selection(n);let l=e.changes.map(t),o=t.mapDesc(e.changes,!0),i=e.mapped?e.mapped.composeDesc(o):o;return new p(l,u.StateEffect.mapEffects(e.effects,t),i,e.startSelection.map(o),n)}const wt=/^(input\.type|delete)($|\.)/;class A{constructor(t,r,n=0,l=void 0){this.done=t,this.undone=r,this.prevTime=n,this.prevUserEvent=l}isolate(){return this.prevTime?new A(this.done,this.undone):this}addChanges(t,r,n,l,o){let i=this.done,c=i[i.length-1];return c&&c.changes&&!c.changes.empty&&t.changes&&(!n||wt.test(n))&&(!c.selectionsAfter.length&&r-this.prevTime<l.newGroupDelay&&l.joinToEvent(o,vt(c.changes,t.changes))||n=="input.type.compose")?i=R(i,i.length-1,l.minDepth,new p(t.changes.compose(c.changes),Le(u.StateEffect.mapEffects(t.effects,c.changes),c.effects),c.mapped,c.startSelection,y)):i=R(i,i.length,l.minDepth,t),new A(i,y,r,n)}addSelection(t,r,n,l){let o=this.done.length?this.done[this.done.length-1].selectionsAfter:y;return o.length>0&&r-this.prevTime<l&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&It(o[o.length-1],t)?this:new A(Ce(this.done,t),this.undone,r,n)}addMapping(t){return new A(N(this.done,t),N(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,r,n){let l=t==0?this.done:this.undone;if(l.length==0)return null;let o=l[l.length-1],i=o.selectionsAfter[0]||r.selection;if(n&&o.selectionsAfter.length)return r.update({selection:o.selectionsAfter[o.selectionsAfter.length-1],annotations:F.of({side:t,rest:Pt(l),selection:i}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(o.changes){let c=l.length==1?y:l.slice(0,l.length-1);return o.mapped&&(c=N(c,o.mapped)),r.update({changes:o.changes,selection:o.startSelection,effects:o.effects,annotations:F.of({side:t,rest:c,selection:i}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}A.empty=new A(y,y);const Nt=[{key:"Mod-z",run:Y,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:O,preventDefault:!0},{linux:"Ctrl-Shift-z",run:O,preventDefault:!0},{key:"Mod-u",run:Be,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Ae,preventDefault:!0}];function x(e,t){return u.EditorSelection.create(e.ranges.map(t),e.mainIndex)}function S(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function B({state:e,dispatch:t},r){let n=x(e.selection,r);return n.eq(e.selection,!0)?!1:(t(S(e,n)),!0)}function P(e,t){return u.EditorSelection.cursor(t?e.to:e.from)}function xe(e,t){return B(e,r=>r.empty?e.moveByChar(r,t):P(r,t))}function m(e){return e.textDirectionAt(e.state.selection.main.head)==C.Direction.LTR}const Z=e=>xe(e,!m(e)),_=e=>xe(e,m(e));function De(e,t){return B(e,r=>r.empty?e.moveByGroup(r,t):P(r,t))}const Ee=e=>De(e,!m(e)),Me=e=>De(e,m(e));function Gt(e,t,r){if(t.type.prop(r))return!0;let n=t.to-t.from;return n&&(n>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function V(e,t,r){let n=h.syntaxTree(e).resolveInner(t.head),l=r?G.NodeProp.closedBy:G.NodeProp.openedBy;for(let s=t.head;;){let a=r?n.childAfter(s):n.childBefore(s);if(!a)break;Gt(e,a,l)?n=a:s=r?a.to:a.from}let o=n.type.prop(l),i,c;return o&&(i=r?h.matchBrackets(e,n.from,1):h.matchBrackets(e,n.to,-1))&&i.matched?c=r?i.end.to:i.end.from:c=r?n.to:n.from,u.EditorSelection.cursor(c,r?-1:1)}const Te=e=>B(e,t=>V(e.state,t,!m(e))),be=e=>B(e,t=>V(e.state,t,m(e)));function Oe(e,t){return B(e,r=>{if(!r.empty)return P(r,t);let n=e.moveVertically(r,t);return n.head!=r.head?n:e.moveToLineBoundary(r,t)})}const ee=e=>Oe(e,!1),te=e=>Oe(e,!0);function Re(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,r=0,n=0,l;if(t){for(let o of e.state.facet(C.EditorView.scrollMargins)){let i=o(e);i?.top&&(r=Math.max(i?.top,r)),i?.bottom&&(n=Math.max(i?.bottom,n))}l=e.scrollDOM.clientHeight-r-n}else l=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:r,marginBottom:n,selfScroll:t,height:Math.max(e.defaultLineHeight,l-5)}}function ve(e,t){let r=Re(e),{state:n}=e,l=x(n.selection,i=>i.empty?e.moveVertically(i,t,r.height):P(i,t));if(l.eq(n.selection))return!1;let o;if(r.selfScroll){let i=e.coordsAtPos(n.selection.main.head),c=e.scrollDOM.getBoundingClientRect(),s=c.top+r.marginTop,a=c.bottom-r.marginBottom;i&&i.top>s&&i.bottom<a&&(o=C.EditorView.scrollIntoView(l.main.head,{y:"start",yMargin:i.top-s}))}return e.dispatch(S(n,l),{effects:o}),!0}const J=e=>ve(e,!1),v=e=>ve(e,!0);function L(e,t,r){let n=e.lineBlockAt(t.head),l=e.moveToLineBoundary(t,r);if(l.head==t.head&&l.head!=(r?n.to:n.from)&&(l=e.moveToLineBoundary(t,r,!1)),!r&&l.head==n.from&&n.length){let o=/^\s*/.exec(e.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;o&&t.head!=n.from+o&&(l=u.EditorSelection.cursor(n.from+o))}return l}const Ie=e=>B(e,t=>L(e,t,!0)),Ue=e=>B(e,t=>L(e,t,!1)),Pe=e=>B(e,t=>L(e,t,!m(e))),Ve=e=>B(e,t=>L(e,t,m(e))),we=e=>B(e,t=>u.EditorSelection.cursor(e.lineBlockAt(t.head).from,1)),Ne=e=>B(e,t=>u.EditorSelection.cursor(e.lineBlockAt(t.head).to,-1));function Ft(e,t,r){let n=!1,l=x(e.selection,o=>{let i=h.matchBrackets(e,o.head,-1)||h.matchBrackets(e,o.head,1)||o.head>0&&h.matchBrackets(e,o.head-1,1)||o.head<e.doc.length&&h.matchBrackets(e,o.head+1,-1);if(!i||!i.end)return o;n=!0;let c=i.start.from==o.head?i.end.to:i.end.from;return u.EditorSelection.cursor(c)});return n?(t(S(e,l)),!0):!1}const Ge=({state:e,dispatch:t})=>Ft(e,t);function k(e,t){let r=x(e.state.selection,n=>{let l=t(n);return u.EditorSelection.range(n.anchor,l.head,l.goalColumn,l.bidiLevel||void 0)});return r.eq(e.state.selection)?!1:(e.dispatch(S(e.state,r)),!0)}function Fe(e,t){return k(e,r=>e.moveByChar(r,t))}const ne=e=>Fe(e,!m(e)),re=e=>Fe(e,m(e));function Je(e,t){return k(e,r=>e.moveByGroup(r,t))}const qe=e=>Je(e,!m(e)),ze=e=>Je(e,m(e)),He=e=>k(e,t=>V(e.state,t,!m(e))),Ke=e=>k(e,t=>V(e.state,t,m(e)));function $e(e,t){return k(e,r=>e.moveVertically(r,t))}const oe=e=>$e(e,!1),le=e=>$e(e,!0);function We(e,t){return k(e,r=>e.moveVertically(r,t,Re(e).height))}const q=e=>We(e,!1),z=e=>We(e,!0),je=e=>k(e,t=>L(e,t,!0)),Qe=e=>k(e,t=>L(e,t,!1)),Xe=e=>k(e,t=>L(e,t,!m(e))),Ye=e=>k(e,t=>L(e,t,m(e))),Ze=e=>k(e,t=>u.EditorSelection.cursor(e.lineBlockAt(t.head).from)),_e=e=>k(e,t=>u.EditorSelection.cursor(e.lineBlockAt(t.head).to)),H=({state:e,dispatch:t})=>(t(S(e,{anchor:0})),!0),K=({state:e,dispatch:t})=>(t(S(e,{anchor:e.doc.length})),!0),$=({state:e,dispatch:t})=>(t(S(e,{anchor:e.selection.main.anchor,head:0})),!0),W=({state:e,dispatch:t})=>(t(S(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),et=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),tt=({state:e,dispatch:t})=>{let r=w(e).map(({from:n,to:l})=>u.EditorSelection.range(n,Math.min(l+1,e.doc.length)));return t(e.update({selection:u.EditorSelection.create(r),userEvent:"select"})),!0},nt=({state:e,dispatch:t})=>{let r=x(e.selection,n=>{let l=h.syntaxTree(e),o=l.resolveStack(n.from,1);if(n.empty){let i=l.resolveStack(n.from,-1);i.node.from>=o.node.from&&i.node.to<=o.node.to&&(o=i)}for(let i=o;i;i=i.next){let{node:c}=i;if((c.from<n.from&&c.to>=n.to||c.to>n.to&&c.from<=n.from)&&i.next)return u.EditorSelection.range(c.to,c.from)}return n});return r.eq(e.selection)?!1:(t(S(e,r)),!0)};function rt(e,t){let{state:r}=e,n=r.selection,l=r.selection.ranges.slice();for(let o of r.selection.ranges){let i=r.doc.lineAt(o.head);if(t?i.to<e.state.doc.length:i.from>0)for(let c=o;;){let s=e.moveVertically(c,t);if(s.head<i.from||s.head>i.to){l.some(a=>a.head==s.head)||l.push(s);break}else{if(s.head==c.head)break;c=s}}}return l.length==n.ranges.length?!1:(e.dispatch(S(r,u.EditorSelection.create(l,l.length-1))),!0)}const ot=e=>rt(e,!1),lt=e=>rt(e,!0),it=({state:e,dispatch:t})=>{let r=e.selection,n=null;return r.ranges.length>1?n=u.EditorSelection.create([r.main]):r.main.empty||(n=u.EditorSelection.create([u.EditorSelection.cursor(r.main.head)])),n?(t(S(e,n)),!0):!1};function M(e,t){if(e.state.readOnly)return!1;let r="delete.selection",{state:n}=e,l=n.changeByRange(o=>{let{from:i,to:c}=o;if(i==c){let s=t(o);s<i?(r="delete.backward",s=b(e,s,!1)):s>i&&(r="delete.forward",s=b(e,s,!0)),i=Math.min(i,s),c=Math.max(c,s)}else i=b(e,i,!1),c=b(e,c,!0);return i==c?{range:o}:{changes:{from:i,to:c},range:u.EditorSelection.cursor(i,i<o.head?-1:1)}});return l.changes.empty?!1:(e.dispatch(n.update(l,{scrollIntoView:!0,userEvent:r,effects:r=="delete.selection"?C.EditorView.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function b(e,t,r){if(e instanceof C.EditorView)for(let n of e.state.facet(C.EditorView.atomicRanges).map(l=>l(e)))n.between(t,t,(l,o)=>{l<t&&o>t&&(t=r?o:l)});return t}const ct=(e,t,r)=>M(e,n=>{let l=n.from,{state:o}=e,i=o.doc.lineAt(l),c,s;if(r&&!t&&l>i.from&&l<i.from+200&&!/[^ \t]/.test(c=i.text.slice(0,l-i.from))){if(c[c.length-1]==" ")return l-1;let a=u.countColumn(c,o.tabSize),f=a%h.getIndentUnit(o)||h.getIndentUnit(o);for(let d=0;d<f&&c[c.length-1-d]==" ";d++)l--;s=l}else s=u.findClusterBreak(i.text,l-i.from,t,t)+i.from,s==l&&i.number!=(t?o.doc.lines:1)?s+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(i.text.slice(s-i.from,l-i.from))&&(s=u.findClusterBreak(i.text,s-i.from,!1,!1)+i.from);return s}),I=e=>ct(e,!1,!0),ie=e=>ct(e,!0,!1),st=(e,t)=>M(e,r=>{let n=r.head,{state:l}=e,o=l.doc.lineAt(n),i=l.charCategorizer(n);for(let c=null;;){if(n==(t?o.to:o.from)){n==r.head&&o.number!=(t?l.doc.lines:1)&&(n+=t?1:-1);break}let s=u.findClusterBreak(o.text,n-o.from,t)+o.from,a=o.text.slice(Math.min(n,s)-o.from,Math.max(n,s)-o.from),f=i(a);if(c!=null&&f!=c)break;(a!=" "||n!=r.head)&&(c=f),n=s}return n}),ce=e=>st(e,!1),ut=e=>st(e,!0),ft=e=>M(e,t=>{let r=e.lineBlockAt(t.head).to;return t.head<r?r:Math.min(e.state.doc.length,t.head+1)}),at=e=>M(e,t=>{let r=e.moveToLineBoundary(t,!1).head;return t.head>r?r:Math.max(0,t.head-1)}),dt=e=>M(e,t=>{let r=e.moveToLineBoundary(t,!0).head;return t.head<r?r:Math.min(e.state.doc.length,t.head+1)}),ht=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:u.Text.of(["",""])},range:u.EditorSelection.cursor(n.from)}));return t(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0},mt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(n=>{if(!n.empty||n.from==0||n.from==e.doc.length)return{range:n};let l=n.from,o=e.doc.lineAt(l),i=l==o.from?l-1:u.findClusterBreak(o.text,l-o.from,!1)+o.from,c=l==o.to?l+1:u.findClusterBreak(o.text,l-o.from,!0)+o.from;return{changes:{from:i,to:c,insert:e.doc.slice(l,c).append(e.doc.slice(i,l))},range:u.EditorSelection.cursor(c)}});return r.changes.empty?!1:(t(e.update(r,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function w(e){let t=[],r=-1;for(let n of e.selection.ranges){let l=e.doc.lineAt(n.from),o=e.doc.lineAt(n.to);if(!n.empty&&n.to==o.from&&(o=e.doc.lineAt(n.to-1)),r>=l.number){let i=t[t.length-1];i.to=o.to,i.ranges.push(n)}else t.push({from:l.from,to:o.to,ranges:[n]});r=o.number+1}return t}function pt(e,t,r){if(e.readOnly)return!1;let n=[],l=[];for(let o of w(e)){if(r?o.to==e.doc.length:o.from==0)continue;let i=e.doc.lineAt(r?o.to+1:o.from-1),c=i.length+1;if(r){n.push({from:o.to,to:i.to},{from:o.from,insert:i.text+e.lineBreak});for(let s of o.ranges)l.push(u.EditorSelection.range(Math.min(e.doc.length,s.anchor+c),Math.min(e.doc.length,s.head+c)))}else{n.push({from:i.from,to:o.from},{from:o.to,insert:e.lineBreak+i.text});for(let s of o.ranges)l.push(u.EditorSelection.range(s.anchor-c,s.head-c))}}return n.length?(t(e.update({changes:n,scrollIntoView:!0,selection:u.EditorSelection.create(l,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const gt=({state:e,dispatch:t})=>pt(e,t,!1),yt=({state:e,dispatch:t})=>pt(e,t,!0);function kt(e,t,r){if(e.readOnly)return!1;let n=[];for(let l of w(e))r?n.push({from:l.from,insert:e.doc.slice(l.from,l.to)+e.lineBreak}):n.push({from:l.to,insert:e.lineBreak+e.doc.slice(l.from,l.to)});return t(e.update({changes:n,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const St=({state:e,dispatch:t})=>kt(e,t,!1),Bt=({state:e,dispatch:t})=>kt(e,t,!0),At=e=>{if(e.state.readOnly)return!1;let{state:t}=e,r=t.changes(w(t).map(({from:l,to:o})=>(l>0?l--:o<t.doc.length&&o++,{from:l,to:o}))),n=x(t.selection,l=>{let o;if(e.lineWrapping){let i=e.lineBlockAt(l.head),c=e.coordsAtPos(l.head,l.assoc||1);c&&(o=i.bottom+e.documentTop-c.bottom+e.defaultLineHeight/2)}return e.moveVertically(l,!0,o)}).map(r);return e.dispatch({changes:r,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Jt(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let r=h.syntaxTree(e).resolveInner(t),n=r.childBefore(t),l=r.childAfter(t),o;return n&&l&&n.to<=t&&l.from>=t&&(o=n.type.prop(G.NodeProp.closedBy))&&o.indexOf(l.name)>-1&&e.doc.lineAt(n.to).from==e.doc.lineAt(l.from).from&&!/\S/.test(e.sliceDoc(n.to,l.from))?{from:n.to,to:l.from}:null}const j=Ct(!1),Lt=Ct(!0);function Ct(e){return({state:t,dispatch:r})=>{if(t.readOnly)return!1;let n=t.changeByRange(l=>{let{from:o,to:i}=l,c=t.doc.lineAt(o),s=!e&&o==i&&Jt(t,o);e&&(o=i=(i<=c.to?c:t.doc.lineAt(i)).to);let a=new h.IndentContext(t,{simulateBreak:o,simulateDoubleBreak:!!s}),f=h.getIndentation(a,o);for(f==null&&(f=u.countColumn(/^\s*/.exec(t.doc.lineAt(o).text)[0],t.tabSize));i<c.to&&/\s/.test(c.text[i-c.from]);)i++;s?{from:o,to:i}=s:o>c.from&&o<c.from+100&&!/\S/.test(c.text.slice(0,o))&&(o=c.from);let d=["",h.indentString(t,f)];return s&&d.push(h.indentString(t,a.lineIndent(c.from,-1))),{changes:{from:o,to:i,insert:u.Text.of(d)},range:u.EditorSelection.cursor(o+1+d[1].length)}});return r(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function se(e,t){let r=-1;return e.changeByRange(n=>{let l=[];for(let i=n.from;i<=n.to;){let c=e.doc.lineAt(i);c.number>r&&(n.empty||n.to>c.from)&&(t(c,l,n),r=c.number),i=c.to+1}let o=e.changes(l);return{changes:l,range:u.EditorSelection.range(o.mapPos(n.anchor,1),o.mapPos(n.head,1))}})}const xt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=Object.create(null),n=new h.IndentContext(e,{overrideIndentation:o=>{let i=r[o];return i??-1}}),l=se(e,(o,i,c)=>{let s=h.getIndentation(n,o.from);if(s==null)return;/\S/.test(o.text)||(s=0);let a=/^\s*/.exec(o.text)[0],f=h.indentString(e,s);(a!=f||c.from<o.from+a.length)&&(r[o.from]=s,i.push({from:o.from,to:o.from+a.length,insert:f}))});return l.changes.empty||t(e.update(l,{userEvent:"indent"})),!0},ue=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(se(e,(r,n)=>{n.push({from:r.from,insert:e.facet(h.indentUnit)})}),{userEvent:"input.indent"})),!0),fe=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(se(e,(r,n)=>{let l=/^\s*/.exec(r.text)[0];if(!l)return;let o=u.countColumn(l,e.tabSize),i=0,c=h.indentString(e,Math.max(0,o-h.getIndentUnit(e)));for(;i<l.length&&i<c.length&&l.charCodeAt(i)==c.charCodeAt(i);)i++;n.push({from:r.from+i,to:r.from+l.length,insert:c.slice(i)})}),{userEvent:"delete.dedent"})),!0),Dt=e=>(e.setTabFocusMode(),!0),Et=[{key:"Ctrl-b",run:Z,shift:ne,preventDefault:!0},{key:"Ctrl-f",run:_,shift:re},{key:"Ctrl-p",run:ee,shift:oe},{key:"Ctrl-n",run:te,shift:le},{key:"Ctrl-a",run:we,shift:Ze},{key:"Ctrl-e",run:Ne,shift:_e},{key:"Ctrl-d",run:ie},{key:"Ctrl-h",run:I},{key:"Ctrl-k",run:ft},{key:"Ctrl-Alt-h",run:ce},{key:"Ctrl-o",run:ht},{key:"Ctrl-t",run:mt},{key:"Ctrl-v",run:v}],Mt=[{key:"ArrowLeft",run:Z,shift:ne,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Ee,shift:qe,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Pe,shift:Xe,preventDefault:!0},{key:"ArrowRight",run:_,shift:re,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Me,shift:ze,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Ve,shift:Ye,preventDefault:!0},{key:"ArrowUp",run:ee,shift:oe,preventDefault:!0},{mac:"Cmd-ArrowUp",run:H,shift:$},{mac:"Ctrl-ArrowUp",run:J,shift:q},{key:"ArrowDown",run:te,shift:le,preventDefault:!0},{mac:"Cmd-ArrowDown",run:K,shift:W},{mac:"Ctrl-ArrowDown",run:v,shift:z},{key:"PageUp",run:J,shift:q},{key:"PageDown",run:v,shift:z},{key:"Home",run:Ue,shift:Qe,preventDefault:!0},{key:"Mod-Home",run:H,shift:$},{key:"End",run:Ie,shift:je,preventDefault:!0},{key:"Mod-End",run:K,shift:W},{key:"Enter",run:j,shift:j},{key:"Mod-a",run:et},{key:"Backspace",run:I,shift:I,preventDefault:!0},{key:"Delete",run:ie,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:ce,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:ut,preventDefault:!0},{mac:"Mod-Backspace",run:at,preventDefault:!0},{mac:"Mod-Delete",run:dt,preventDefault:!0}].concat(Et.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),qt=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Te,shift:He},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:be,shift:Ke},{key:"Alt-ArrowUp",run:gt},{key:"Shift-Alt-ArrowUp",run:St},{key:"Alt-ArrowDown",run:yt},{key:"Shift-Alt-ArrowDown",run:Bt},{key:"Mod-Alt-ArrowUp",run:ot},{key:"Mod-Alt-ArrowDown",run:lt},{key:"Escape",run:it},{key:"Mod-Enter",run:Lt},{key:"Alt-l",mac:"Ctrl-l",run:tt},{key:"Mod-i",run:nt,preventDefault:!0},{key:"Mod-[",run:fe},{key:"Mod-]",run:ue},{key:"Mod-Alt-\\",run:xt},{key:"Shift-Mod-k",run:At},{key:"Shift-Mod-\\",run:Ge},{key:"Mod-/",run:ae},{key:"Alt-A",run:he},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Dt}].concat(Mt),zt={key:"Tab",run:ue,shift:fe};exports.addCursorAbove=ot;exports.addCursorBelow=lt;exports.copyLineDown=Bt;exports.copyLineUp=St;exports.cursorCharLeft=Z;exports.cursorCharRight=_;exports.cursorDocEnd=K;exports.cursorDocStart=H;exports.cursorGroupLeft=Ee;exports.cursorGroupRight=Me;exports.cursorLineBoundaryBackward=Ue;exports.cursorLineBoundaryForward=Ie;exports.cursorLineBoundaryLeft=Pe;exports.cursorLineBoundaryRight=Ve;exports.cursorLineDown=te;exports.cursorLineEnd=Ne;exports.cursorLineStart=we;exports.cursorLineUp=ee;exports.cursorMatchingBracket=Ge;exports.cursorPageDown=v;exports.cursorPageUp=J;exports.cursorSyntaxLeft=Te;exports.cursorSyntaxRight=be;exports.defaultKeymap=qt;exports.deleteCharBackward=I;exports.deleteCharForward=ie;exports.deleteGroupBackward=ce;exports.deleteGroupForward=ut;exports.deleteLine=At;exports.deleteLineBoundaryBackward=at;exports.deleteLineBoundaryForward=dt;exports.deleteToLineEnd=ft;exports.emacsStyleKeymap=Et;exports.history=Rt;exports.historyKeymap=Nt;exports.indentLess=fe;exports.indentMore=ue;exports.indentSelection=xt;exports.indentWithTab=zt;exports.insertBlankLine=Lt;exports.insertNewlineAndIndent=j;exports.invertedEffects=ye;exports.isolateHistory=ge;exports.moveLineDown=yt;exports.moveLineUp=gt;exports.redo=O;exports.redoSelection=Ae;exports.selectAll=et;exports.selectCharLeft=ne;exports.selectCharRight=re;exports.selectDocEnd=W;exports.selectDocStart=$;exports.selectGroupLeft=qe;exports.selectGroupRight=ze;exports.selectLine=tt;exports.selectLineBoundaryBackward=Qe;exports.selectLineBoundaryForward=je;exports.selectLineBoundaryLeft=Xe;exports.selectLineBoundaryRight=Ye;exports.selectLineDown=le;exports.selectLineEnd=_e;exports.selectLineStart=Ze;exports.selectLineUp=oe;exports.selectPageDown=z;exports.selectPageUp=q;exports.selectParentSyntax=nt;exports.selectSyntaxLeft=He;exports.selectSyntaxRight=Ke;exports.simplifySelection=it;exports.splitLine=ht;exports.standardKeymap=Mt;exports.toggleBlockComment=he;exports.toggleBlockCommentByLine=me;exports.toggleComment=ae;exports.toggleLineComment=de;exports.toggleTabFocusMode=Dt;exports.transposeChars=mt;exports.undo=Y;exports.undoSelection=Be;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../state/dist/index.js"),C=require("../../view/dist/index.js"),h=require("../../language/dist/index.js"),G=require("../../../@lezer/common/dist/index.js"),ae=e=>{let{state:t}=e,r=t.doc.lineAt(t.selection.main.from),n=X(e.state,r.from);return n.line?de(e):n.block?me(e):!1};function Q(e,t){return({state:r,dispatch:n})=>{if(r.readOnly)return!1;let l=e(t,r);return l?(n(r.update(l)),!0):!1}}const de=Q(Ot,0),he=Q(pe,0),me=Q((e,t)=>pe(e,t,bt(t)),0);function X(e,t){let r=e.languageDataAt("commentTokens",t,1);return r.length?r[0]:{}}const E=50;function Tt(e,{open:t,close:r},n,l){let o=e.sliceDoc(n-E,n),i=e.sliceDoc(l,l+E),c=/\s*$/.exec(o)[0].length,s=/^\s*/.exec(i)[0].length,a=o.length-c;if(o.slice(a-t.length,a)==t&&i.slice(s,s+r.length)==r)return{open:{pos:n-c,margin:c&&1},close:{pos:l+s,margin:s&&1}};let f,d;l-n<=2*E?f=d=e.sliceDoc(n,l):(f=e.sliceDoc(n,n+E),d=e.sliceDoc(l-E,l));let g=/^\s*/.exec(f)[0].length,T=/\s*$/.exec(d)[0].length,D=d.length-T-r.length;return f.slice(g,g+t.length)==t&&d.slice(D,D+r.length)==r?{open:{pos:n+g+t.length,margin:/\s/.test(f.charAt(g+t.length))?1:0},close:{pos:l-T-r.length,margin:/\s/.test(d.charAt(D-1))?1:0}}:null}function bt(e){let t=[];for(let r of e.selection.ranges){let n=e.doc.lineAt(r.from),l=r.to<=n.to?n:e.doc.lineAt(r.to);l.from>n.from&&l.from==r.to&&(l=r.to==n.to+1?n:e.doc.lineAt(r.to-1));let o=t.length-1;o>=0&&t[o].to>n.from?t[o].to=l.to:t.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:l.to})}return t}function pe(e,t,r=t.selection.ranges){let n=r.map(o=>X(t,o.from).block);if(!n.every(o=>o))return null;let l=r.map((o,i)=>Tt(t,n[i],o.from,o.to));if(e!=2&&!l.every(o=>o))return{changes:t.changes(r.map((o,i)=>l[i]?[]:[{from:o.from,insert:n[i].open+" "},{from:o.to,insert:" "+n[i].close}]))};if(e!=1&&l.some(o=>o)){let o=[];for(let i=0,c;i<l.length;i++)if(c=l[i]){let s=n[i],{open:a,close:f}=c;o.push({from:a.pos-s.open.length,to:a.pos+a.margin},{from:f.pos-f.margin,to:f.pos+s.close.length})}return{changes:o}}return null}function Ot(e,t,r=t.selection.ranges){let n=[],l=-1;for(let{from:o,to:i}of r){let c=n.length,s=1e9,a=X(t,o).line;if(a){for(let f=o;f<=i;){let d=t.doc.lineAt(f);if(d.from>l&&(o==i||i>d.from)){l=d.from;let g=/^\s*/.exec(d.text)[0].length,T=g==d.length,D=d.text.slice(g,g+a.length)==a?g:-1;g<d.text.length&&g<s&&(s=g),n.push({line:d,comment:D,token:a,indent:g,empty:T,single:!1})}f=d.to+1}if(s<1e9)for(let f=c;f<n.length;f++)n[f].indent<n[f].line.text.length&&(n[f].indent=s);n.length==c+1&&(n[c].single=!0)}}if(e!=2&&n.some(o=>o.comment<0&&(!o.empty||o.single))){let o=[];for(let{line:c,token:s,indent:a,empty:f,single:d}of n)(d||!f)&&o.push({from:c.from+a,insert:s+" "});let i=t.changes(o);return{changes:i,selection:t.selection.map(i,1)}}else if(e!=1&&n.some(o=>o.comment>=0)){let o=[];for(let{line:i,comment:c,token:s}of n)if(c>=0){let a=i.from+c,f=a+s.length;i.text[f-i.from]==" "&&f++,o.push({from:a,to:f})}return{changes:o}}return null}const F=u.Annotation.define(),ge=u.Annotation.define(),ye=u.Facet.define(),ke=u.Facet.define({combine(e){return u.combineConfig(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,r)=>r},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,r)=>(n,l)=>t(n,l)||r(n,l)})}}),Se=u.StateField.define({create(){return A.empty},update(e,t){let r=t.state.facet(ke),n=t.annotation(F);if(n){let s=p.fromTransaction(t,n.selection),a=n.side,f=a==0?e.undone:e.done;return s?f=R(f,f.length,r.minDepth,s):f=Ce(f,t.startState.selection),new A(a==0?n.rest:f,a==0?f:n.rest)}let l=t.annotation(ge);if((l=="full"||l=="before")&&(e=e.isolate()),t.annotation(u.Transaction.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let o=p.fromTransaction(t),i=t.annotation(u.Transaction.time),c=t.annotation(u.Transaction.userEvent);return o?e=e.addChanges(o,i,c,r,t):t.selection&&(e=e.addSelection(t.startState.selection,i,c,r.newGroupDelay)),(l=="full"||l=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new A(e.done.map(p.fromJSON),e.undone.map(p.fromJSON))}});function Rt(e={}){return[Se,ke.of(e),C.EditorView.domEventHandlers({beforeinput(t,r){let n=t.inputType=="historyUndo"?Y:t.inputType=="historyRedo"?O:null;return n?(t.preventDefault(),n(r)):!1}})]}function U(e,t){return function({state:r,dispatch:n}){if(!t&&r.readOnly)return!1;let l=r.field(Se,!1);if(!l)return!1;let o=l.pop(e,r,t);return o?(n(o),!0):!1}}const Y=U(0,!1),O=U(1,!1),Be=U(0,!0),Ae=U(1,!0);class p{constructor(t,r,n,l,o){this.changes=t,this.effects=r,this.mapped=n,this.startSelection=l,this.selectionsAfter=o}setSelAfter(t){return new p(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,r,n;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(r=this.mapped)===null||r===void 0?void 0:r.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(l=>l.toJSON())}}static fromJSON(t){return new p(t.changes&&u.ChangeSet.fromJSON(t.changes),[],t.mapped&&u.ChangeDesc.fromJSON(t.mapped),t.startSelection&&u.EditorSelection.fromJSON(t.startSelection),t.selectionsAfter.map(u.EditorSelection.fromJSON))}static fromTransaction(t,r){let n=y;for(let l of t.startState.facet(ye)){let o=l(t);o.length&&(n=n.concat(o))}return!n.length&&t.changes.empty?null:new p(t.changes.invert(t.startState.doc),n,void 0,r||t.startState.selection,y)}static selection(t){return new p(void 0,y,void 0,void 0,t)}}function R(e,t,r,n){let l=t+1>r+20?t-r-1:0,o=e.slice(l,t);return o.push(n),o}function vt(e,t){let r=[],n=!1;return e.iterChangedRanges((l,o)=>r.push(l,o)),t.iterChangedRanges((l,o,i,c)=>{for(let s=0;s<r.length;){let a=r[s++],f=r[s++];c>=a&&i<=f&&(n=!0)}}),n}function It(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((r,n)=>r.empty!=t.ranges[n].empty).length===0}function Le(e,t){return e.length?t.length?e.concat(t):e:t}const y=[],Ut=200;function Ce(e,t){if(e.length){let r=e[e.length-1],n=r.selectionsAfter.slice(Math.max(0,r.selectionsAfter.length-Ut));return n.length&&n[n.length-1].eq(t)?e:(n.push(t),R(e,e.length-1,1e9,r.setSelAfter(n)))}else return[p.selection([t])]}function Pt(e){let t=e[e.length-1],r=e.slice();return r[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),r}function w(e,t){if(!e.length)return e;let r=e.length,n=y;for(;r;){let l=Vt(e[r-1],t,n);if(l.changes&&!l.changes.empty||l.effects.length){let o=e.slice(0,r);return o[r-1]=l,o}else t=l.mapped,r--,n=l.selectionsAfter}return n.length?[p.selection(n)]:y}function Vt(e,t,r){let n=Le(e.selectionsAfter.length?e.selectionsAfter.map(c=>c.map(t)):y,r);if(!e.changes)return p.selection(n);let l=e.changes.map(t),o=t.mapDesc(e.changes,!0),i=e.mapped?e.mapped.composeDesc(o):o;return new p(l,u.StateEffect.mapEffects(e.effects,t),i,e.startSelection.map(o),n)}const Nt=/^(input\.type|delete)($|\.)/;class A{constructor(t,r,n=0,l=void 0){this.done=t,this.undone=r,this.prevTime=n,this.prevUserEvent=l}isolate(){return this.prevTime?new A(this.done,this.undone):this}addChanges(t,r,n,l,o){let i=this.done,c=i[i.length-1];return c&&c.changes&&!c.changes.empty&&t.changes&&(!n||Nt.test(n))&&(!c.selectionsAfter.length&&r-this.prevTime<l.newGroupDelay&&l.joinToEvent(o,vt(c.changes,t.changes))||n=="input.type.compose")?i=R(i,i.length-1,l.minDepth,new p(t.changes.compose(c.changes),Le(u.StateEffect.mapEffects(t.effects,c.changes),c.effects),c.mapped,c.startSelection,y)):i=R(i,i.length,l.minDepth,t),new A(i,y,r,n)}addSelection(t,r,n,l){let o=this.done.length?this.done[this.done.length-1].selectionsAfter:y;return o.length>0&&r-this.prevTime<l&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&It(o[o.length-1],t)?this:new A(Ce(this.done,t),this.undone,r,n)}addMapping(t){return new A(w(this.done,t),w(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,r,n){let l=t==0?this.done:this.undone;if(l.length==0)return null;let o=l[l.length-1],i=o.selectionsAfter[0]||r.selection;if(n&&o.selectionsAfter.length)return r.update({selection:o.selectionsAfter[o.selectionsAfter.length-1],annotations:F.of({side:t,rest:Pt(l),selection:i}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(o.changes){let c=l.length==1?y:l.slice(0,l.length-1);return o.mapped&&(c=w(c,o.mapped)),r.update({changes:o.changes,selection:o.startSelection,effects:o.effects,annotations:F.of({side:t,rest:c,selection:i}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}A.empty=new A(y,y);const wt=[{key:"Mod-z",run:Y,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:O,preventDefault:!0},{linux:"Ctrl-Shift-z",run:O,preventDefault:!0},{key:"Mod-u",run:Be,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Ae,preventDefault:!0}];function x(e,t){return u.EditorSelection.create(e.ranges.map(t),e.mainIndex)}function S(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function B({state:e,dispatch:t},r){let n=x(e.selection,r);return n.eq(e.selection,!0)?!1:(t(S(e,n)),!0)}function P(e,t){return u.EditorSelection.cursor(t?e.to:e.from)}function xe(e,t){return B(e,r=>r.empty?e.moveByChar(r,t):P(r,t))}function m(e){return e.textDirectionAt(e.state.selection.main.head)==C.Direction.LTR}const Z=e=>xe(e,!m(e)),_=e=>xe(e,m(e));function De(e,t){return B(e,r=>r.empty?e.moveByGroup(r,t):P(r,t))}const Ee=e=>De(e,!m(e)),Me=e=>De(e,m(e));function Gt(e,t,r){if(t.type.prop(r))return!0;let n=t.to-t.from;return n&&(n>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function V(e,t,r){let n=h.syntaxTree(e).resolveInner(t.head),l=r?G.NodeProp.closedBy:G.NodeProp.openedBy;for(let s=t.head;;){let a=r?n.childAfter(s):n.childBefore(s);if(!a)break;Gt(e,a,l)?n=a:s=r?a.to:a.from}let o=n.type.prop(l),i,c;return o&&(i=r?h.matchBrackets(e,n.from,1):h.matchBrackets(e,n.to,-1))&&i.matched?c=r?i.end.to:i.end.from:c=r?n.to:n.from,u.EditorSelection.cursor(c,r?-1:1)}const Te=e=>B(e,t=>V(e.state,t,!m(e))),be=e=>B(e,t=>V(e.state,t,m(e)));function Oe(e,t){return B(e,r=>{if(!r.empty)return P(r,t);let n=e.moveVertically(r,t);return n.head!=r.head?n:e.moveToLineBoundary(r,t)})}const ee=e=>Oe(e,!1),te=e=>Oe(e,!0);function Re(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,r=0,n=0,l;if(t){for(let o of e.state.facet(C.EditorView.scrollMargins)){let i=o(e);i?.top&&(r=Math.max(i?.top,r)),i?.bottom&&(n=Math.max(i?.bottom,n))}l=e.scrollDOM.clientHeight-r-n}else l=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:r,marginBottom:n,selfScroll:t,height:Math.max(e.defaultLineHeight,l-5)}}function ve(e,t){let r=Re(e),{state:n}=e,l=x(n.selection,i=>i.empty?e.moveVertically(i,t,r.height):P(i,t));if(l.eq(n.selection))return!1;let o;if(r.selfScroll){let i=e.coordsAtPos(n.selection.main.head),c=e.scrollDOM.getBoundingClientRect(),s=c.top+r.marginTop,a=c.bottom-r.marginBottom;i&&i.top>s&&i.bottom<a&&(o=C.EditorView.scrollIntoView(l.main.head,{y:"start",yMargin:i.top-s}))}return e.dispatch(S(n,l),{effects:o}),!0}const J=e=>ve(e,!1),v=e=>ve(e,!0);function L(e,t,r){let n=e.lineBlockAt(t.head),l=e.moveToLineBoundary(t,r);if(l.head==t.head&&l.head!=(r?n.to:n.from)&&(l=e.moveToLineBoundary(t,r,!1)),!r&&l.head==n.from&&n.length){let o=/^\s*/.exec(e.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;o&&t.head!=n.from+o&&(l=u.EditorSelection.cursor(n.from+o))}return l}const Ie=e=>B(e,t=>L(e,t,!0)),Ue=e=>B(e,t=>L(e,t,!1)),Pe=e=>B(e,t=>L(e,t,!m(e))),Ve=e=>B(e,t=>L(e,t,m(e))),Ne=e=>B(e,t=>u.EditorSelection.cursor(e.lineBlockAt(t.head).from,1)),we=e=>B(e,t=>u.EditorSelection.cursor(e.lineBlockAt(t.head).to,-1));function Ft(e,t,r){let n=!1,l=x(e.selection,o=>{let i=h.matchBrackets(e,o.head,-1)||h.matchBrackets(e,o.head,1)||o.head>0&&h.matchBrackets(e,o.head-1,1)||o.head<e.doc.length&&h.matchBrackets(e,o.head+1,-1);if(!i||!i.end)return o;n=!0;let c=i.start.from==o.head?i.end.to:i.end.from;return u.EditorSelection.cursor(c)});return n?(t(S(e,l)),!0):!1}const Ge=({state:e,dispatch:t})=>Ft(e,t);function k(e,t){let r=x(e.state.selection,n=>{let l=t(n);return u.EditorSelection.range(n.anchor,l.head,l.goalColumn,l.bidiLevel||void 0)});return r.eq(e.state.selection)?!1:(e.dispatch(S(e.state,r)),!0)}function Fe(e,t){return k(e,r=>e.moveByChar(r,t))}const ne=e=>Fe(e,!m(e)),re=e=>Fe(e,m(e));function Je(e,t){return k(e,r=>e.moveByGroup(r,t))}const qe=e=>Je(e,!m(e)),ze=e=>Je(e,m(e)),He=e=>k(e,t=>V(e.state,t,!m(e))),Ke=e=>k(e,t=>V(e.state,t,m(e)));function $e(e,t){return k(e,r=>e.moveVertically(r,t))}const oe=e=>$e(e,!1),le=e=>$e(e,!0);function We(e,t){return k(e,r=>e.moveVertically(r,t,Re(e).height))}const q=e=>We(e,!1),z=e=>We(e,!0),je=e=>k(e,t=>L(e,t,!0)),Qe=e=>k(e,t=>L(e,t,!1)),Xe=e=>k(e,t=>L(e,t,!m(e))),Ye=e=>k(e,t=>L(e,t,m(e))),Ze=e=>k(e,t=>u.EditorSelection.cursor(e.lineBlockAt(t.head).from)),_e=e=>k(e,t=>u.EditorSelection.cursor(e.lineBlockAt(t.head).to)),H=({state:e,dispatch:t})=>(t(S(e,{anchor:0})),!0),K=({state:e,dispatch:t})=>(t(S(e,{anchor:e.doc.length})),!0),$=({state:e,dispatch:t})=>(t(S(e,{anchor:e.selection.main.anchor,head:0})),!0),W=({state:e,dispatch:t})=>(t(S(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),et=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),tt=({state:e,dispatch:t})=>{let r=N(e).map(({from:n,to:l})=>u.EditorSelection.range(n,Math.min(l+1,e.doc.length)));return t(e.update({selection:u.EditorSelection.create(r),userEvent:"select"})),!0},nt=({state:e,dispatch:t})=>{let r=x(e.selection,n=>{let l=h.syntaxTree(e),o=l.resolveStack(n.from,1);if(n.empty){let i=l.resolveStack(n.from,-1);i.node.from>=o.node.from&&i.node.to<=o.node.to&&(o=i)}for(let i=o;i;i=i.next){let{node:c}=i;if((c.from<n.from&&c.to>=n.to||c.to>n.to&&c.from<=n.from)&&i.next)return u.EditorSelection.range(c.to,c.from)}return n});return r.eq(e.selection)?!1:(t(S(e,r)),!0)};function rt(e,t){let{state:r}=e,n=r.selection,l=r.selection.ranges.slice();for(let o of r.selection.ranges){let i=r.doc.lineAt(o.head);if(t?i.to<e.state.doc.length:i.from>0)for(let c=o;;){let s=e.moveVertically(c,t);if(s.head<i.from||s.head>i.to){l.some(a=>a.head==s.head)||l.push(s);break}else{if(s.head==c.head)break;c=s}}}return l.length==n.ranges.length?!1:(e.dispatch(S(r,u.EditorSelection.create(l,l.length-1))),!0)}const ot=e=>rt(e,!1),lt=e=>rt(e,!0),it=({state:e,dispatch:t})=>{let r=e.selection,n=null;return r.ranges.length>1?n=u.EditorSelection.create([r.main]):r.main.empty||(n=u.EditorSelection.create([u.EditorSelection.cursor(r.main.head)])),n?(t(S(e,n)),!0):!1};function M(e,t){if(e.state.readOnly)return!1;let r="delete.selection",{state:n}=e,l=n.changeByRange(o=>{let{from:i,to:c}=o;if(i==c){let s=t(o);s<i?(r="delete.backward",s=b(e,s,!1)):s>i&&(r="delete.forward",s=b(e,s,!0)),i=Math.min(i,s),c=Math.max(c,s)}else i=b(e,i,!1),c=b(e,c,!0);return i==c?{range:o}:{changes:{from:i,to:c},range:u.EditorSelection.cursor(i,i<o.head?-1:1)}});return l.changes.empty?!1:(e.dispatch(n.update(l,{scrollIntoView:!0,userEvent:r,effects:r=="delete.selection"?C.EditorView.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function b(e,t,r){if(e instanceof C.EditorView)for(let n of e.state.facet(C.EditorView.atomicRanges).map(l=>l(e)))n.between(t,t,(l,o)=>{l<t&&o>t&&(t=r?o:l)});return t}const ct=(e,t,r)=>M(e,n=>{let l=n.from,{state:o}=e,i=o.doc.lineAt(l),c,s;if(r&&!t&&l>i.from&&l<i.from+200&&!/[^ \t]/.test(c=i.text.slice(0,l-i.from))){if(c[c.length-1]==" ")return l-1;let a=u.countColumn(c,o.tabSize),f=a%h.getIndentUnit(o)||h.getIndentUnit(o);for(let d=0;d<f&&c[c.length-1-d]==" ";d++)l--;s=l}else s=u.findClusterBreak(i.text,l-i.from,t,t)+i.from,s==l&&i.number!=(t?o.doc.lines:1)?s+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(i.text.slice(s-i.from,l-i.from))&&(s=u.findClusterBreak(i.text,s-i.from,!1,!1)+i.from);return s}),I=e=>ct(e,!1,!0),ie=e=>ct(e,!0,!1),st=(e,t)=>M(e,r=>{let n=r.head,{state:l}=e,o=l.doc.lineAt(n),i=l.charCategorizer(n);for(let c=null;;){if(n==(t?o.to:o.from)){n==r.head&&o.number!=(t?l.doc.lines:1)&&(n+=t?1:-1);break}let s=u.findClusterBreak(o.text,n-o.from,t)+o.from,a=o.text.slice(Math.min(n,s)-o.from,Math.max(n,s)-o.from),f=i(a);if(c!=null&&f!=c)break;(a!=" "||n!=r.head)&&(c=f),n=s}return n}),ce=e=>st(e,!1),ut=e=>st(e,!0),ft=e=>M(e,t=>{let r=e.lineBlockAt(t.head).to;return t.head<r?r:Math.min(e.state.doc.length,t.head+1)}),at=e=>M(e,t=>{let r=e.moveToLineBoundary(t,!1).head;return t.head>r?r:Math.max(0,t.head-1)}),dt=e=>M(e,t=>{let r=e.moveToLineBoundary(t,!0).head;return t.head<r?r:Math.min(e.state.doc.length,t.head+1)}),ht=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:u.Text.of(["",""])},range:u.EditorSelection.cursor(n.from)}));return t(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0},mt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(n=>{if(!n.empty||n.from==0||n.from==e.doc.length)return{range:n};let l=n.from,o=e.doc.lineAt(l),i=l==o.from?l-1:u.findClusterBreak(o.text,l-o.from,!1)+o.from,c=l==o.to?l+1:u.findClusterBreak(o.text,l-o.from,!0)+o.from;return{changes:{from:i,to:c,insert:e.doc.slice(l,c).append(e.doc.slice(i,l))},range:u.EditorSelection.cursor(c)}});return r.changes.empty?!1:(t(e.update(r,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function N(e){let t=[],r=-1;for(let n of e.selection.ranges){let l=e.doc.lineAt(n.from),o=e.doc.lineAt(n.to);if(!n.empty&&n.to==o.from&&(o=e.doc.lineAt(n.to-1)),r>=l.number){let i=t[t.length-1];i.to=o.to,i.ranges.push(n)}else t.push({from:l.from,to:o.to,ranges:[n]});r=o.number+1}return t}function pt(e,t,r){if(e.readOnly)return!1;let n=[],l=[];for(let o of N(e)){if(r?o.to==e.doc.length:o.from==0)continue;let i=e.doc.lineAt(r?o.to+1:o.from-1),c=i.length+1;if(r){n.push({from:o.to,to:i.to},{from:o.from,insert:i.text+e.lineBreak});for(let s of o.ranges)l.push(u.EditorSelection.range(Math.min(e.doc.length,s.anchor+c),Math.min(e.doc.length,s.head+c)))}else{n.push({from:i.from,to:o.from},{from:o.to,insert:e.lineBreak+i.text});for(let s of o.ranges)l.push(u.EditorSelection.range(s.anchor-c,s.head-c))}}return n.length?(t(e.update({changes:n,scrollIntoView:!0,selection:u.EditorSelection.create(l,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const gt=({state:e,dispatch:t})=>pt(e,t,!1),yt=({state:e,dispatch:t})=>pt(e,t,!0);function kt(e,t,r){if(e.readOnly)return!1;let n=[];for(let o of N(e))r?n.push({from:o.from,insert:e.doc.slice(o.from,o.to)+e.lineBreak}):n.push({from:o.to,insert:e.lineBreak+e.doc.slice(o.from,o.to)});let l=e.changes(n);return t(e.update({changes:l,selection:e.selection.map(l,r?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const St=({state:e,dispatch:t})=>kt(e,t,!1),Bt=({state:e,dispatch:t})=>kt(e,t,!0),At=e=>{if(e.state.readOnly)return!1;let{state:t}=e,r=t.changes(N(t).map(({from:l,to:o})=>(l>0?l--:o<t.doc.length&&o++,{from:l,to:o}))),n=x(t.selection,l=>{let o;if(e.lineWrapping){let i=e.lineBlockAt(l.head),c=e.coordsAtPos(l.head,l.assoc||1);c&&(o=i.bottom+e.documentTop-c.bottom+e.defaultLineHeight/2)}return e.moveVertically(l,!0,o)}).map(r);return e.dispatch({changes:r,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Jt(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let r=h.syntaxTree(e).resolveInner(t),n=r.childBefore(t),l=r.childAfter(t),o;return n&&l&&n.to<=t&&l.from>=t&&(o=n.type.prop(G.NodeProp.closedBy))&&o.indexOf(l.name)>-1&&e.doc.lineAt(n.to).from==e.doc.lineAt(l.from).from&&!/\S/.test(e.sliceDoc(n.to,l.from))?{from:n.to,to:l.from}:null}const j=Ct(!1),Lt=Ct(!0);function Ct(e){return({state:t,dispatch:r})=>{if(t.readOnly)return!1;let n=t.changeByRange(l=>{let{from:o,to:i}=l,c=t.doc.lineAt(o),s=!e&&o==i&&Jt(t,o);e&&(o=i=(i<=c.to?c:t.doc.lineAt(i)).to);let a=new h.IndentContext(t,{simulateBreak:o,simulateDoubleBreak:!!s}),f=h.getIndentation(a,o);for(f==null&&(f=u.countColumn(/^\s*/.exec(t.doc.lineAt(o).text)[0],t.tabSize));i<c.to&&/\s/.test(c.text[i-c.from]);)i++;s?{from:o,to:i}=s:o>c.from&&o<c.from+100&&!/\S/.test(c.text.slice(0,o))&&(o=c.from);let d=["",h.indentString(t,f)];return s&&d.push(h.indentString(t,a.lineIndent(c.from,-1))),{changes:{from:o,to:i,insert:u.Text.of(d)},range:u.EditorSelection.cursor(o+1+d[1].length)}});return r(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function se(e,t){let r=-1;return e.changeByRange(n=>{let l=[];for(let i=n.from;i<=n.to;){let c=e.doc.lineAt(i);c.number>r&&(n.empty||n.to>c.from)&&(t(c,l,n),r=c.number),i=c.to+1}let o=e.changes(l);return{changes:l,range:u.EditorSelection.range(o.mapPos(n.anchor,1),o.mapPos(n.head,1))}})}const xt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=Object.create(null),n=new h.IndentContext(e,{overrideIndentation:o=>{let i=r[o];return i??-1}}),l=se(e,(o,i,c)=>{let s=h.getIndentation(n,o.from);if(s==null)return;/\S/.test(o.text)||(s=0);let a=/^\s*/.exec(o.text)[0],f=h.indentString(e,s);(a!=f||c.from<o.from+a.length)&&(r[o.from]=s,i.push({from:o.from,to:o.from+a.length,insert:f}))});return l.changes.empty||t(e.update(l,{userEvent:"indent"})),!0},ue=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(se(e,(r,n)=>{n.push({from:r.from,insert:e.facet(h.indentUnit)})}),{userEvent:"input.indent"})),!0),fe=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(se(e,(r,n)=>{let l=/^\s*/.exec(r.text)[0];if(!l)return;let o=u.countColumn(l,e.tabSize),i=0,c=h.indentString(e,Math.max(0,o-h.getIndentUnit(e)));for(;i<l.length&&i<c.length&&l.charCodeAt(i)==c.charCodeAt(i);)i++;n.push({from:r.from+i,to:r.from+l.length,insert:c.slice(i)})}),{userEvent:"delete.dedent"})),!0),Dt=e=>(e.setTabFocusMode(),!0),Et=[{key:"Ctrl-b",run:Z,shift:ne,preventDefault:!0},{key:"Ctrl-f",run:_,shift:re},{key:"Ctrl-p",run:ee,shift:oe},{key:"Ctrl-n",run:te,shift:le},{key:"Ctrl-a",run:Ne,shift:Ze},{key:"Ctrl-e",run:we,shift:_e},{key:"Ctrl-d",run:ie},{key:"Ctrl-h",run:I},{key:"Ctrl-k",run:ft},{key:"Ctrl-Alt-h",run:ce},{key:"Ctrl-o",run:ht},{key:"Ctrl-t",run:mt},{key:"Ctrl-v",run:v}],Mt=[{key:"ArrowLeft",run:Z,shift:ne,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Ee,shift:qe,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Pe,shift:Xe,preventDefault:!0},{key:"ArrowRight",run:_,shift:re,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Me,shift:ze,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Ve,shift:Ye,preventDefault:!0},{key:"ArrowUp",run:ee,shift:oe,preventDefault:!0},{mac:"Cmd-ArrowUp",run:H,shift:$},{mac:"Ctrl-ArrowUp",run:J,shift:q},{key:"ArrowDown",run:te,shift:le,preventDefault:!0},{mac:"Cmd-ArrowDown",run:K,shift:W},{mac:"Ctrl-ArrowDown",run:v,shift:z},{key:"PageUp",run:J,shift:q},{key:"PageDown",run:v,shift:z},{key:"Home",run:Ue,shift:Qe,preventDefault:!0},{key:"Mod-Home",run:H,shift:$},{key:"End",run:Ie,shift:je,preventDefault:!0},{key:"Mod-End",run:K,shift:W},{key:"Enter",run:j,shift:j},{key:"Mod-a",run:et},{key:"Backspace",run:I,shift:I,preventDefault:!0},{key:"Delete",run:ie,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:ce,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:ut,preventDefault:!0},{mac:"Mod-Backspace",run:at,preventDefault:!0},{mac:"Mod-Delete",run:dt,preventDefault:!0}].concat(Et.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),qt=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Te,shift:He},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:be,shift:Ke},{key:"Alt-ArrowUp",run:gt},{key:"Shift-Alt-ArrowUp",run:St},{key:"Alt-ArrowDown",run:yt},{key:"Shift-Alt-ArrowDown",run:Bt},{key:"Mod-Alt-ArrowUp",run:ot},{key:"Mod-Alt-ArrowDown",run:lt},{key:"Escape",run:it},{key:"Mod-Enter",run:Lt},{key:"Alt-l",mac:"Ctrl-l",run:tt},{key:"Mod-i",run:nt,preventDefault:!0},{key:"Mod-[",run:fe},{key:"Mod-]",run:ue},{key:"Mod-Alt-\\",run:xt},{key:"Shift-Mod-k",run:At},{key:"Shift-Mod-\\",run:Ge},{key:"Mod-/",run:ae},{key:"Alt-A",run:he},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Dt}].concat(Mt),zt={key:"Tab",run:ue,shift:fe};exports.addCursorAbove=ot;exports.addCursorBelow=lt;exports.copyLineDown=Bt;exports.copyLineUp=St;exports.cursorCharLeft=Z;exports.cursorCharRight=_;exports.cursorDocEnd=K;exports.cursorDocStart=H;exports.cursorGroupLeft=Ee;exports.cursorGroupRight=Me;exports.cursorLineBoundaryBackward=Ue;exports.cursorLineBoundaryForward=Ie;exports.cursorLineBoundaryLeft=Pe;exports.cursorLineBoundaryRight=Ve;exports.cursorLineDown=te;exports.cursorLineEnd=we;exports.cursorLineStart=Ne;exports.cursorLineUp=ee;exports.cursorMatchingBracket=Ge;exports.cursorPageDown=v;exports.cursorPageUp=J;exports.cursorSyntaxLeft=Te;exports.cursorSyntaxRight=be;exports.defaultKeymap=qt;exports.deleteCharBackward=I;exports.deleteCharForward=ie;exports.deleteGroupBackward=ce;exports.deleteGroupForward=ut;exports.deleteLine=At;exports.deleteLineBoundaryBackward=at;exports.deleteLineBoundaryForward=dt;exports.deleteToLineEnd=ft;exports.emacsStyleKeymap=Et;exports.history=Rt;exports.historyKeymap=wt;exports.indentLess=fe;exports.indentMore=ue;exports.indentSelection=xt;exports.indentWithTab=zt;exports.insertBlankLine=Lt;exports.insertNewlineAndIndent=j;exports.invertedEffects=ye;exports.isolateHistory=ge;exports.moveLineDown=yt;exports.moveLineUp=gt;exports.redo=O;exports.redoSelection=Ae;exports.selectAll=et;exports.selectCharLeft=ne;exports.selectCharRight=re;exports.selectDocEnd=W;exports.selectDocStart=$;exports.selectGroupLeft=qe;exports.selectGroupRight=ze;exports.selectLine=tt;exports.selectLineBoundaryBackward=Qe;exports.selectLineBoundaryForward=je;exports.selectLineBoundaryLeft=Xe;exports.selectLineBoundaryRight=Ye;exports.selectLineDown=le;exports.selectLineEnd=_e;exports.selectLineStart=Ze;exports.selectLineUp=oe;exports.selectPageDown=z;exports.selectPageUp=q;exports.selectParentSyntax=nt;exports.selectSyntaxLeft=He;exports.selectSyntaxRight=Ke;exports.simplifySelection=it;exports.splitLine=ht;exports.standardKeymap=Mt;exports.toggleBlockComment=he;exports.toggleBlockCommentByLine=me;exports.toggleComment=ae;exports.toggleLineComment=de;exports.toggleTabFocusMode=Dt;exports.transposeChars=mt;exports.undo=Y;exports.undoSelection=Be;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../../../@lezer/common/dist/index.js"),h=require("../../state/dist/index.js"),d=require("../../view/dist/index.js"),u=require("../../../@lezer/highlight/dist/index.js"),K=require("../../../style-mod/src/style-mod.js");var H;const v=new p.NodeProp;function ne(n){return h.Facet.define({combine:n?e=>e.concat(n):void 0})}const re=new p.NodeProp;class k{constructor(e,t,r=[],i=""){this.data=e,this.name=i,h.EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(h.EditorState.prototype,"tree",{get(){return b(this)}}),this.parser=t,this.extension=[w.of(this),h.EditorState.languageData.of((o,s,l)=>{let a=Q(o,s,l),c=a.type.prop(v);if(!c)return[];let f=o.facet(c),g=a.type.prop(re);if(g){let y=a.resolve(s-a.from,l);for(let m of g)if(m.test(y,o)){let x=o.facet(m.facet);return m.type=="replace"?x:x.concat(f)}}return f})].concat(r)}isActiveAt(e,t,r=-1){return Q(e,t,r).type.prop(v)==this.data}findRegions(e){let t=e.facet(w);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let r=[],i=(o,s)=>{if(o.prop(v)==this.data){r.push({from:s,to:s+o.length});return}let l=o.prop(p.NodeProp.mounted);if(l){if(l.tree.prop(v)==this.data){if(l.overlay)for(let a of l.overlay)r.push({from:a.from+s,to:a.to+s});else r.push({from:s,to:s+o.length});return}else if(l.overlay){let a=r.length;if(i(l.tree,l.overlay[0].from+s),r.length>a)return}}for(let a=0;a<o.children.length;a++){let c=o.children[a];c instanceof p.Tree&&i(c,o.positions[a]+s)}};return i(b(e),0),r}get allowsNesting(){return!0}}k.setState=h.StateEffect.define();function Q(n,e,t){let r=n.facet(w),i=b(n).topNode;if(!r||r.allowsNesting)for(let o=i;o;o=o.enter(e,t,p.IterMode.ExcludeBuffers))o.type.isTop&&(i=o);return i}class B extends k{constructor(e,t,r){super(e,t,[],r),this.parser=t}static define(e){let t=ne(e.languageData);return new B(t,e.parser.configure({props:[v.add(r=>r.isTop?t:void 0)]}),e.name)}configure(e,t){return new B(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function b(n){let e=n.field(k.state,!1);return e?e.tree:p.Tree.empty}class ie{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let r=this.cursorPos-this.string.length;return e<r||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-r,t-r)}}let A=null;class I{constructor(e,t,r=[],i,o,s,l,a){this.parser=e,this.state=t,this.fragments=r,this.tree=i,this.treeLen=o,this.viewport=s,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,r){return new I(e,t,[],p.Tree.empty,0,r,[],null)}startParse(){return this.parser.startParse(new ie(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=p.Tree.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let i=Date.now()+e;e=()=>Date.now()>i}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let i=this.parse.advance();if(i)if(this.fragments=this.withoutTempSkipped(p.TreeFragment.addTree(i,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=i,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(p.TreeFragment.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=A;A=this;try{return e()}finally{A=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=X(e,t.from,t.to);return e}changes(e,t){let{fragments:r,tree:i,treeLen:o,viewport:s,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((c,f,g,y)=>a.push({fromA:c,toA:f,fromB:g,toB:y})),r=p.TreeFragment.applyChanges(r,a),i=p.Tree.empty,o=0,s={from:e.mapPos(s.from,-1),to:e.mapPos(s.to,1)},this.skipped.length){l=[];for(let c of this.skipped){let f=e.mapPos(c.from,1),g=e.mapPos(c.to,-1);f<g&&l.push({from:f,to:g})}}}return new I(this.parser,t,r,i,o,s,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:i,to:o}=this.skipped[r];i<e.to&&o>e.from&&(this.fragments=X(this.fragments,i,o),this.skipped.splice(r--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends p.Parser{createParse(t,r,i){let o=i[0].from,s=i[i.length-1].to;return{parsedPos:o,advance(){let a=A;if(a){for(let c of i)a.tempSkipped.push(c);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=s,new p.Tree(p.NodeType.none,[],[],s-o)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return A}}function X(n,e,t){return p.TreeFragment.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class C{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,r)||t.takeTree(),new C(t)}static init(e){let t=Math.min(3e3,e.doc.length),r=I.create(e.facet(w).parser,e,{from:0,to:t});return r.work(20,t)||r.takeTree(),new C(r)}}k.state=h.StateField.define({create:C.init,update(n,e){for(let t of e.effects)if(t.is(k.setState))return t.value;return e.startState.facet(w)!=e.state.facet(w)?C.init(e.state):n.apply(e)}});let oe=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(oe=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const W=typeof navigator<"u"&&(!((H=navigator.scheduling)===null||H===void 0)&&H.isInputPending)?()=>navigator.scheduling.isInputPending():null,Ee=d.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(k.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(k.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=oe(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:i}}=this.view,o=r.field(k.state);if(o.tree==o.context.tree&&o.context.isDone(i+1e5))return;let s=Date.now()+Math.min(this.chunkBudget,100,e&&!W?Math.max(25,e.timeRemaining()-5):1e9),l=o.context.treeLen<i&&r.doc.length>i+1e3,a=o.context.work(()=>W&&W()||Date.now()>s,i+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(o.context.takeTree(),this.view.dispatch({effects:k.setState.of(new C(o.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(o.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>d.logException(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),w=h.Facet.define({combine(n){return n.length?n[0]:null},enables:n=>[k.state,Ee,d.EditorView.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class Me{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const se=h.Facet.define(),G=h.Facet.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function ae(n){let e=n.facet(G);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function le(n,e){let t="",r=n.tabSize,i=n.facet(G)[0];if(i==" "){for(;e>=r;)t+=" ",e-=r;i=" "}for(let o=0;o<e;o++)t+=i;return t}function ce(n,e){n instanceof h.EditorState&&(n=new z(n));for(let r of n.state.facet(se)){let i=r(n,e);if(i!==void 0)return i}let t=b(n.state);return t.length>=e?Be(n,t,e):null}class z{constructor(e,t={}){this.state=e,this.options=t,this.unit=ae(e)}lineAt(e,t=1){let r=this.state.doc.lineAt(e),{simulateBreak:i,simulateDoubleBreak:o}=this.options;return i!=null&&i>=r.from&&i<=r.to?o&&i==e?{text:"",from:e}:(t<0?i<e:i<=e)?{text:r.text.slice(i-r.from),from:i}:{text:r.text.slice(0,i-r.from),from:r.from}:r}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:i}=this.lineAt(e,t);return r.slice(e-i,Math.min(r.length,e+100-i))}column(e,t=1){let{text:r,from:i}=this.lineAt(e,t),o=this.countColumn(r,e-i),s=this.options.overrideIndentation?this.options.overrideIndentation(i):-1;return s>-1&&(o+=s-this.countColumn(r,r.search(/\S|$/))),o}countColumn(e,t=e.length){return h.countColumn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:r,from:i}=this.lineAt(e,t),o=this.options.overrideIndentation;if(o){let s=o(i);if(s>-1)return s}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const fe=new p.NodeProp;function Be(n,e,t){let r=e.resolveStack(t),i=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(i!=r.node){let o=[];for(let s=i;s&&!(s.from<r.node.from||s.to>r.node.to||s.from==r.node.from&&s.type==r.node.type);s=s.parent)o.push(s);for(let s=o.length-1;s>=0;s--)r={node:o[s],next:r}}return ue(r,n,t)}function ue(n,e,t){for(let r=n;r;r=r.next){let i=Fe(r.node);if(i)return i(F.create(e,t,r))}return 0}function Oe(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function Fe(n){let e=n.type.prop(fe);if(e)return e;let t=n.firstChild,r;if(t&&(r=t.type.prop(p.NodeProp.closedBy))){let i=n.lastChild,o=i&&r.indexOf(i.name)>-1;return s=>de(s,!0,1,void 0,o&&!Oe(s)?i.from:void 0)}return n.parent==null?Le:null}function Le(){return 0}class F extends z{constructor(e,t,r){super(e.state,e.options),this.base=e,this.pos=t,this.context=r}get node(){return this.context.node}static create(e,t,r){return new F(e,t,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(t.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(He(r,e))break;t=this.state.doc.lineAt(r.from)}return this.lineIndent(t.from)}continue(){return ue(this.context.next,this.base,this.pos)}}function He(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function We(n){let e=n.node,t=e.childAfter(e.from),r=e.lastChild;if(!t)return null;let i=n.options.simulateBreak,o=n.state.doc.lineAt(t.from),s=i==null||i<=o.from?o.to:Math.min(o.to,i);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==r)return null;if(!a.type.isSkipped){if(a.from>=s)return null;let c=/^ */.exec(o.text.slice(t.to-o.from))[0].length;return{from:t.from,to:t.to+c}}l=a.to}}function Re({closing:n,align:e=!0,units:t=1}){return r=>de(r,e,t,n)}function de(n,e,t,r,i){let o=n.textAfter,s=o.match(/^\s*/)[0].length,l=r&&o.slice(s,s+r.length)==r||i==n.pos+s,a=e?We(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}const Ue=n=>n.baseIndent;function Ve({except:n,units:e=1}={}){return t=>{let r=n&&n.test(t.textAfter);return t.baseIndent+(r?0:e*t.unit)}}const $e=200;function qe(){return h.EditorState.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:r}=n.newSelection.main,i=t.lineAt(r);if(r>i.from+$e)return n;let o=t.sliceString(i.from,r);if(!e.some(c=>c.test(o)))return n;let{state:s}=n,l=-1,a=[];for(let{head:c}of s.selection.ranges){let f=s.doc.lineAt(c);if(f.from==l)continue;l=f.from;let g=ce(s,f.from);if(g==null)continue;let y=/^\s*/.exec(f.text)[0],m=le(s,g);y!=m&&a.push({from:f.from,to:f.from+y.length,insert:m})}return a.length?[n,{changes:a,sequential:!0}]:n})}const he=h.Facet.define(),ge=new p.NodeProp;function je(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}function Ge(n,e,t){let r=b(n);if(r.length<t)return null;let i=r.resolveStack(t,1),o=null;for(let s=i;s;s=s.next){let l=s.node;if(l.to<=t||l.from>t)continue;if(o&&l.from<e)break;let a=l.type.prop(ge);if(a&&(l.to<r.length-50||r.length==n.doc.length||!ze(l))){let c=a(l,n);c&&c.from<=t&&c.from>=e&&c.to>t&&(o=c)}}return o}function ze(n){let e=n.lastChild;return e&&e.to==n.to&&e.type.isError}function N(n,e,t){for(let r of n.facet(he)){let i=r(n,e,t);if(i)return i}return Ge(n,e,t)}function pe(n,e){let t=e.mapPos(n.from,1),r=e.mapPos(n.to,-1);return t>=r?void 0:{from:t,to:r}}const E=h.StateEffect.define({map:pe}),P=h.StateEffect.define({map:pe});function me(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(r=>r.from<=t&&r.to>=t)||e.push(n.lineBlockAt(t));return e}const S=h.StateField.define({create(){return d.Decoration.none},update(n,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((t,r)=>n=Y(n,t,r)),n=n.map(e.changes);for(let t of e.effects)if(t.is(E)&&!Je(n,t.value.from,t.value.to)){let{preparePlaceholder:r}=e.state.facet(xe),i=r?d.Decoration.replace({widget:new Xe(r(e.state,t.value))}):Z;n=n.update({add:[i.range(t.value.from,t.value.to)]})}else t.is(P)&&(n=n.update({filter:(r,i)=>t.value.from!=r||t.value.to!=i,filterFrom:t.value.from,filterTo:t.value.to}));return e.selection&&(n=Y(n,e.selection.main.head)),n},provide:n=>d.EditorView.decorations.from(n),toJSON(n,e){let t=[];return n.between(0,e.doc.length,(r,i)=>{t.push(r,i)}),t},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<n.length;){let r=n[t++],i=n[t++];if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid JSON for fold state");e.push(Z.range(r,i))}return d.Decoration.set(e,!0)}});function Y(n,e,t=e){let r=!1;return n.between(e,t,(i,o)=>{i<t&&o>e&&(r=!0)}),r?n.update({filterFrom:e,filterTo:t,filter:(i,o)=>i>=t||o<=e}):n}function O(n,e,t){var r;let i=null;return(r=n.field(S,!1))===null||r===void 0||r.between(e,t,(o,s)=>{(!i||i.from>o)&&(i={from:o,to:s})}),i}function Je(n,e,t){let r=!1;return n.between(e,e,(i,o)=>{i==e&&o==t&&(r=!0)}),r}function ke(n,e){return n.field(S,!1)?e:e.concat(h.StateEffect.appendConfig.of(J()))}const ye=n=>{for(let e of me(n)){let t=N(n.state,e.from,e.to);if(t)return n.dispatch({effects:ke(n.state,[E.of(t),we(n,t)])}),!0}return!1},be=n=>{if(!n.state.field(S,!1))return!1;let e=[];for(let t of me(n)){let r=O(n.state,t.from,t.to);r&&e.push(P.of(r),we(n,r,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function we(n,e,t=!0){let r=n.state.doc.lineAt(e.from).number,i=n.state.doc.lineAt(e.to).number;return d.EditorView.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${r} ${n.state.phrase("to")} ${i}.`)}const Se=n=>{let{state:e}=n,t=[];for(let r=0;r<e.doc.length;){let i=n.lineBlockAt(r),o=N(e,i.from,i.to);o&&t.push(E.of(o)),r=(o?n.lineBlockAt(o.to):i).to+1}return t.length&&n.dispatch({effects:ke(n.state,t)}),!!t.length},ve=n=>{let e=n.state.field(S,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(r,i)=>{t.push(P.of({from:r,to:i}))}),n.dispatch({effects:t}),!0},Ke=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:ye},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:be},{key:"Ctrl-Alt-[",run:Se},{key:"Ctrl-Alt-]",run:ve}],Qe={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},xe=h.Facet.define({combine(n){return h.combineConfig(n,Qe)}});function J(n){return[S,_e]}function Te(n,e){let{state:t}=n,r=t.facet(xe),i=s=>{let l=n.lineBlockAt(n.posAtDOM(s.target)),a=O(n.state,l.from,l.to);a&&n.dispatch({effects:P.of(a)}),s.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(n,i,e);let o=document.createElement("span");return o.textContent=r.placeholderText,o.setAttribute("aria-label",t.phrase("folded code")),o.title=t.phrase("unfold"),o.className="cm-foldPlaceholder",o.onclick=i,o}const Z=d.Decoration.replace({widget:new class extends d.WidgetType{toDOM(n){return Te(n,null)}}});class Xe extends d.WidgetType{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return Te(e,this.value)}}const Ye={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class R extends d.GutterMarker{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function Ze(n={}){let e={...Ye,...n},t=new R(e,!0),r=new R(e,!1),i=d.ViewPlugin.fromClass(class{constructor(s){this.from=s.viewport.from,this.markers=this.buildMarkers(s)}update(s){(s.docChanged||s.viewportChanged||s.startState.facet(w)!=s.state.facet(w)||s.startState.field(S,!1)!=s.state.field(S,!1)||b(s.startState)!=b(s.state)||e.foldingChanged(s))&&(this.markers=this.buildMarkers(s.view))}buildMarkers(s){let l=new h.RangeSetBuilder;for(let a of s.viewportLineBlocks){let c=O(s.state,a.from,a.to)?r:N(s.state,a.from,a.to)?t:null;c&&l.add(a.from,a.from,c)}return l.finish()}}),{domEventHandlers:o}=e;return[i,d.gutter({class:"cm-foldGutter",markers(s){var l;return((l=s.plugin(i))===null||l===void 0?void 0:l.markers)||h.RangeSet.empty},initialSpacer(){return new R(e,!1)},domEventHandlers:{...o,click:(s,l,a)=>{if(o.click&&o.click(s,l,a))return!0;let c=O(s.state,l.from,l.to);if(c)return s.dispatch({effects:P.of(c)}),!0;let f=N(s.state,l.from,l.to);return f?(s.dispatch({effects:E.of(f)}),!0):!1}}}),J()]}const _e=d.EditorView.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class M{constructor(e,t){this.specs=e;let r;function i(l){let a=K.StyleModule.newName();return(r||(r=Object.create(null)))["."+a]=l,a}const o=typeof t.all=="string"?t.all:t.all?i(t.all):void 0,s=t.scope;this.scope=s instanceof k?l=>l.prop(v)==s.data:s?l=>l==s:void 0,this.style=u.tagHighlighter(e.map(l=>({tag:l.tag,class:l.class||i(Object.assign({},l,{tag:null}))})),{all:o}).style,this.module=r?new K.StyleModule(r):null,this.themeType=t.themeType}static define(e,t){return new M(e,t||{})}}const $=h.Facet.define(),Ce=h.Facet.define({combine(n){return n.length?[n[0]]:null}});function U(n){let e=n.facet($);return e.length?e:n.facet(Ce)}function et(n,e){let t=[nt],r;return n instanceof M&&(n.module&&t.push(d.EditorView.styleModule.of(n.module)),r=n.themeType),e?.fallback?t.push(Ce.of(n)):r?t.push($.computeN([d.EditorView.darkTheme],i=>i.facet(d.EditorView.darkTheme)==(r=="dark")?[n]:[])):t.push($.of(n)),t}class tt{constructor(e){this.markCache=Object.create(null),this.tree=b(e.state),this.decorations=this.buildDeco(e,U(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=b(e.state),r=U(e.state),i=r!=U(e.startState),{viewport:o}=e.view,s=e.changes.mapPos(this.decoratedTo,1);t.length<o.to&&!i&&t.type==this.tree.type&&s>=o.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=s):(t!=this.tree||e.viewportChanged||i)&&(this.tree=t,this.decorations=this.buildDeco(e.view,r),this.decoratedTo=o.to)}buildDeco(e,t){if(!t||!this.tree.length)return d.Decoration.none;let r=new h.RangeSetBuilder;for(let{from:i,to:o}of e.visibleRanges)u.highlightTree(this.tree,t,(s,l,a)=>{r.add(s,l,this.markCache[a]||(this.markCache[a]=d.Decoration.mark({class:a})))},i,o);return r.finish()}}const nt=h.Prec.high(d.ViewPlugin.fromClass(tt,{decorations:n=>n.decorations})),rt=M.define([{tag:u.tags.meta,color:"#404740"},{tag:u.tags.link,textDecoration:"underline"},{tag:u.tags.heading,textDecoration:"underline",fontWeight:"bold"},{tag:u.tags.emphasis,fontStyle:"italic"},{tag:u.tags.strong,fontWeight:"bold"},{tag:u.tags.strikethrough,textDecoration:"line-through"},{tag:u.tags.keyword,color:"#708"},{tag:[u.tags.atom,u.tags.bool,u.tags.url,u.tags.contentSeparator,u.tags.labelName],color:"#219"},{tag:[u.tags.literal,u.tags.inserted],color:"#164"},{tag:[u.tags.string,u.tags.deleted],color:"#a11"},{tag:[u.tags.regexp,u.tags.escape,u.tags.special(u.tags.string)],color:"#e40"},{tag:u.tags.definition(u.tags.variableName),color:"#00f"},{tag:u.tags.local(u.tags.variableName),color:"#30a"},{tag:[u.tags.typeName,u.tags.namespace],color:"#085"},{tag:u.tags.className,color:"#167"},{tag:[u.tags.special(u.tags.variableName),u.tags.macroName],color:"#256"},{tag:u.tags.definition(u.tags.propertyName),color:"#00c"},{tag:u.tags.comment,color:"#940"},{tag:u.tags.invalid,color:"#f00"}]),it=d.EditorView.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Pe=1e4,Ae="()[]{}",De=h.Facet.define({combine(n){return h.combineConfig(n,{afterCursor:!0,brackets:Ae,maxScanDistance:Pe,renderMatch:at})}}),ot=d.Decoration.mark({class:"cm-matchingBracket"}),st=d.Decoration.mark({class:"cm-nonmatchingBracket"});function at(n){let e=[],t=n.matched?ot:st;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}const lt=h.StateField.define({create(){return d.Decoration.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],r=e.state.facet(De);for(let i of e.state.selection.ranges){if(!i.empty)continue;let o=D(e.state,i.head,-1,r)||i.head>0&&D(e.state,i.head-1,1,r)||r.afterCursor&&(D(e.state,i.head,1,r)||i.head<e.state.doc.length&&D(e.state,i.head+1,-1,r));o&&(t=t.concat(r.renderMatch(o,e.state)))}return d.Decoration.set(t,!0)},provide:n=>d.EditorView.decorations.from(n)}),ct=[lt,it];function ft(n={}){return[De.of(n),ct]}const Ie=new p.NodeProp;function q(n,e,t){let r=n.prop(e<0?p.NodeProp.openedBy:p.NodeProp.closedBy);if(r)return r;if(n.name.length==1){let i=t.indexOf(n.name);if(i>-1&&i%2==(e<0?1:0))return[t[i+e]]}return null}function j(n){let e=n.type.prop(Ie);return e?e(n.node):n}function D(n,e,t,r={}){let i=r.maxScanDistance||Pe,o=r.brackets||Ae,s=b(n),l=s.resolveInner(e,t);for(let a=l;a;a=a.parent){let c=q(a.type,t,o);if(c&&a.from<a.to){let f=j(a);if(f&&(t>0?e>=f.from&&e<f.to:e>f.from&&e<=f.to))return ut(n,e,t,a,f,c,o)}}return dt(n,e,t,s,l.type,i,o)}function ut(n,e,t,r,i,o,s){let l=r.parent,a={from:i.from,to:i.to},c=0,f=l?.cursor();if(f&&(t<0?f.childBefore(r.from):f.childAfter(r.to)))do if(t<0?f.to<=r.from:f.from>=r.to){if(c==0&&o.indexOf(f.type.name)>-1&&f.from<f.to){let g=j(f);return{start:a,end:g?{from:g.from,to:g.to}:void 0,matched:!0}}else if(q(f.type,t,s))c++;else if(q(f.type,-t,s)){if(c==0){let g=j(f);return{start:a,end:g&&g.from<g.to?{from:g.from,to:g.to}:void 0,matched:!1}}c--}}while(t<0?f.prevSibling():f.nextSibling());return{start:a,matched:!1}}function dt(n,e,t,r,i,o,s){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=s.indexOf(l);if(a<0||a%2==0!=t>0)return null;let c={from:t<0?e-1:e,to:t>0?e+1:e},f=n.doc.iterRange(e,t>0?n.doc.length:0),g=0;for(let y=0;!f.next().done&&y<=o;){let m=f.value;t<0&&(y+=m.length);let x=e+y*t;for(let T=t>0?0:m.length-1,Ne=t>0?m.length:-1;T!=Ne;T+=t){let L=s.indexOf(m[T]);if(!(L<0||r.resolveInner(x+T,1).type!=i))if(L%2==0==t>0)g++;else{if(g==1)return{start:c,end:{from:x+T,to:x+T+1},matched:L>>1==a>>1};g--}}t>0&&(y+=m.length)}return f.done?{start:c,matched:!1}:null}const ht=Object.create(null),_=[p.NodeType.none],ee=[],te=Object.create(null),gt=Object.create(null);for(let[n,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"]])gt[n]=pt(ht,e);function V(n,e){ee.indexOf(n)>-1||(ee.push(n),console.warn(e))}function pt(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let c of l.split(".")){let f=n[c]||u.tags[c];f?typeof f=="function"?a.length?a=a.map(f):V(c,`Modifier ${c} used at start of tag`):a.length?V(c,`Tag ${c} used as modifier`):a=Array.isArray(f)?f:[f]:V(c,`Unknown highlighting tag ${c}`)}for(let c of a)t.push(c)}if(!t.length)return 0;let r=e.replace(/ /g,"_"),i=r+" "+t.map(l=>l.id),o=te[i];if(o)return o.id;let s=te[i]=p.NodeType.define({id:_.length,name:r,props:[u.styleTags({[r]:t})]});return _.push(s),s.id}d.Direction.RTL,d.Direction.LTR;exports.DocInput=ie;exports.HighlightStyle=M;exports.IndentContext=z;exports.LRLanguage=B;exports.Language=k;exports.LanguageSupport=Me;exports.ParseContext=I;exports.TreeIndentContext=F;exports.bracketMatching=ft;exports.bracketMatchingHandle=Ie;exports.codeFolding=J;exports.continuedIndent=Ve;exports.defaultHighlightStyle=rt;exports.defineLanguageFacet=ne;exports.delimitedIndent=Re;exports.flatIndent=Ue;exports.foldAll=Se;exports.foldCode=ye;exports.foldEffect=E;exports.foldGutter=Ze;exports.foldInside=je;exports.foldKeymap=Ke;exports.foldNodeProp=ge;exports.foldService=he;exports.foldState=S;exports.foldable=N;exports.getIndentUnit=ae;exports.getIndentation=ce;exports.indentNodeProp=fe;exports.indentOnInput=qe;exports.indentService=se;exports.indentString=le;exports.indentUnit=G;exports.language=w;exports.languageDataProp=v;exports.matchBrackets=D;exports.sublanguageProp=re;exports.syntaxHighlighting=et;exports.syntaxTree=b;exports.unfoldAll=ve;exports.unfoldCode=be;exports.unfoldEffect=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../../../@lezer/common/dist/index.js"),h=require("../../state/dist/index.js"),d=require("../../view/dist/index.js"),u=require("../../../@lezer/highlight/dist/index.js"),K=require("../../../style-mod/src/style-mod.js");var H;const v=new g.NodeProp;function ne(n){return h.Facet.define({combine:n?e=>e.concat(n):void 0})}const re=new g.NodeProp;class k{constructor(e,t,r=[],i=""){this.data=e,this.name=i,h.EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(h.EditorState.prototype,"tree",{get(){return b(this)}}),this.parser=t,this.extension=[w.of(this),h.EditorState.languageData.of((o,s,l)=>{let a=Q(o,s,l),c=a.type.prop(v);if(!c)return[];let f=o.facet(c),p=a.type.prop(re);if(p){let y=a.resolve(s-a.from,l);for(let m of p)if(m.test(y,o)){let x=o.facet(m.facet);return m.type=="replace"?x:x.concat(f)}}return f})].concat(r)}isActiveAt(e,t,r=-1){return Q(e,t,r).type.prop(v)==this.data}findRegions(e){let t=e.facet(w);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let r=[],i=(o,s)=>{if(o.prop(v)==this.data){r.push({from:s,to:s+o.length});return}let l=o.prop(g.NodeProp.mounted);if(l){if(l.tree.prop(v)==this.data){if(l.overlay)for(let a of l.overlay)r.push({from:a.from+s,to:a.to+s});else r.push({from:s,to:s+o.length});return}else if(l.overlay){let a=r.length;if(i(l.tree,l.overlay[0].from+s),r.length>a)return}}for(let a=0;a<o.children.length;a++){let c=o.children[a];c instanceof g.Tree&&i(c,o.positions[a]+s)}};return i(b(e),0),r}get allowsNesting(){return!0}}k.setState=h.StateEffect.define();function Q(n,e,t){let r=n.facet(w),i=b(n).topNode;if(!r||r.allowsNesting)for(let o=i;o;o=o.enter(e,t,g.IterMode.ExcludeBuffers|g.IterMode.EnterBracketed))o.type.isTop&&(i=o);return i}class B extends k{constructor(e,t,r){super(e,t,[],r),this.parser=t}static define(e){let t=ne(e.languageData);return new B(t,e.parser.configure({props:[v.add(r=>r.isTop?t:void 0)]}),e.name)}configure(e,t){return new B(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function b(n){let e=n.field(k.state,!1);return e?e.tree:g.Tree.empty}class ie{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let r=this.cursorPos-this.string.length;return e<r||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-r,t-r)}}let A=null;class I{constructor(e,t,r=[],i,o,s,l,a){this.parser=e,this.state=t,this.fragments=r,this.tree=i,this.treeLen=o,this.viewport=s,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,r){return new I(e,t,[],g.Tree.empty,0,r,[],null)}startParse(){return this.parser.startParse(new ie(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=g.Tree.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let i=Date.now()+e;e=()=>Date.now()>i}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let i=this.parse.advance();if(i)if(this.fragments=this.withoutTempSkipped(g.TreeFragment.addTree(i,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=i,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(g.TreeFragment.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=A;A=this;try{return e()}finally{A=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=X(e,t.from,t.to);return e}changes(e,t){let{fragments:r,tree:i,treeLen:o,viewport:s,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((c,f,p,y)=>a.push({fromA:c,toA:f,fromB:p,toB:y})),r=g.TreeFragment.applyChanges(r,a),i=g.Tree.empty,o=0,s={from:e.mapPos(s.from,-1),to:e.mapPos(s.to,1)},this.skipped.length){l=[];for(let c of this.skipped){let f=e.mapPos(c.from,1),p=e.mapPos(c.to,-1);f<p&&l.push({from:f,to:p})}}}return new I(this.parser,t,r,i,o,s,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:i,to:o}=this.skipped[r];i<e.to&&o>e.from&&(this.fragments=X(this.fragments,i,o),this.skipped.splice(r--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends g.Parser{createParse(t,r,i){let o=i[0].from,s=i[i.length-1].to;return{parsedPos:o,advance(){let a=A;if(a){for(let c of i)a.tempSkipped.push(c);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=s,new g.Tree(g.NodeType.none,[],[],s-o)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return A}}function X(n,e,t){return g.TreeFragment.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class C{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,r)||t.takeTree(),new C(t)}static init(e){let t=Math.min(3e3,e.doc.length),r=I.create(e.facet(w).parser,e,{from:0,to:t});return r.work(20,t)||r.takeTree(),new C(r)}}k.state=h.StateField.define({create:C.init,update(n,e){for(let t of e.effects)if(t.is(k.setState))return t.value;return e.startState.facet(w)!=e.state.facet(w)?C.init(e.state):n.apply(e)}});let oe=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(oe=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const W=typeof navigator<"u"&&(!((H=navigator.scheduling)===null||H===void 0)&&H.isInputPending)?()=>navigator.scheduling.isInputPending():null,Ee=d.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(k.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(k.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=oe(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:i}}=this.view,o=r.field(k.state);if(o.tree==o.context.tree&&o.context.isDone(i+1e5))return;let s=Date.now()+Math.min(this.chunkBudget,100,e&&!W?Math.max(25,e.timeRemaining()-5):1e9),l=o.context.treeLen<i&&r.doc.length>i+1e3,a=o.context.work(()=>W&&W()||Date.now()>s,i+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(o.context.takeTree(),this.view.dispatch({effects:k.setState.of(new C(o.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(o.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>d.logException(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),w=h.Facet.define({combine(n){return n.length?n[0]:null},enables:n=>[k.state,Ee,d.EditorView.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class Me{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const se=h.Facet.define(),G=h.Facet.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function ae(n){let e=n.facet(G);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function le(n,e){let t="",r=n.tabSize,i=n.facet(G)[0];if(i==" "){for(;e>=r;)t+=" ",e-=r;i=" "}for(let o=0;o<e;o++)t+=i;return t}function ce(n,e){n instanceof h.EditorState&&(n=new z(n));for(let r of n.state.facet(se)){let i=r(n,e);if(i!==void 0)return i}let t=b(n.state);return t.length>=e?Be(n,t,e):null}class z{constructor(e,t={}){this.state=e,this.options=t,this.unit=ae(e)}lineAt(e,t=1){let r=this.state.doc.lineAt(e),{simulateBreak:i,simulateDoubleBreak:o}=this.options;return i!=null&&i>=r.from&&i<=r.to?o&&i==e?{text:"",from:e}:(t<0?i<e:i<=e)?{text:r.text.slice(i-r.from),from:i}:{text:r.text.slice(0,i-r.from),from:r.from}:r}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:i}=this.lineAt(e,t);return r.slice(e-i,Math.min(r.length,e+100-i))}column(e,t=1){let{text:r,from:i}=this.lineAt(e,t),o=this.countColumn(r,e-i),s=this.options.overrideIndentation?this.options.overrideIndentation(i):-1;return s>-1&&(o+=s-this.countColumn(r,r.search(/\S|$/))),o}countColumn(e,t=e.length){return h.countColumn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:r,from:i}=this.lineAt(e,t),o=this.options.overrideIndentation;if(o){let s=o(i);if(s>-1)return s}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const fe=new g.NodeProp;function Be(n,e,t){let r=e.resolveStack(t),i=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(i!=r.node){let o=[];for(let s=i;s&&!(s.from<r.node.from||s.to>r.node.to||s.from==r.node.from&&s.type==r.node.type);s=s.parent)o.push(s);for(let s=o.length-1;s>=0;s--)r={node:o[s],next:r}}return ue(r,n,t)}function ue(n,e,t){for(let r=n;r;r=r.next){let i=Fe(r.node);if(i)return i(F.create(e,t,r))}return 0}function Oe(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function Fe(n){let e=n.type.prop(fe);if(e)return e;let t=n.firstChild,r;if(t&&(r=t.type.prop(g.NodeProp.closedBy))){let i=n.lastChild,o=i&&r.indexOf(i.name)>-1;return s=>de(s,!0,1,void 0,o&&!Oe(s)?i.from:void 0)}return n.parent==null?Le:null}function Le(){return 0}class F extends z{constructor(e,t,r){super(e.state,e.options),this.base=e,this.pos=t,this.context=r}get node(){return this.context.node}static create(e,t,r){return new F(e,t,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(t.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(He(r,e))break;t=this.state.doc.lineAt(r.from)}return this.lineIndent(t.from)}continue(){return ue(this.context.next,this.base,this.pos)}}function He(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function We(n){let e=n.node,t=e.childAfter(e.from),r=e.lastChild;if(!t)return null;let i=n.options.simulateBreak,o=n.state.doc.lineAt(t.from),s=i==null||i<=o.from?o.to:Math.min(o.to,i);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==r)return null;if(!a.type.isSkipped){if(a.from>=s)return null;let c=/^ */.exec(o.text.slice(t.to-o.from))[0].length;return{from:t.from,to:t.to+c}}l=a.to}}function Re({closing:n,align:e=!0,units:t=1}){return r=>de(r,e,t,n)}function de(n,e,t,r,i){let o=n.textAfter,s=o.match(/^\s*/)[0].length,l=r&&o.slice(s,s+r.length)==r||i==n.pos+s,a=e?We(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}const Ue=n=>n.baseIndent;function Ve({except:n,units:e=1}={}){return t=>{let r=n&&n.test(t.textAfter);return t.baseIndent+(r?0:e*t.unit)}}const $e=200;function qe(){return h.EditorState.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:r}=n.newSelection.main,i=t.lineAt(r);if(r>i.from+$e)return n;let o=t.sliceString(i.from,r);if(!e.some(c=>c.test(o)))return n;let{state:s}=n,l=-1,a=[];for(let{head:c}of s.selection.ranges){let f=s.doc.lineAt(c);if(f.from==l)continue;l=f.from;let p=ce(s,f.from);if(p==null)continue;let y=/^\s*/.exec(f.text)[0],m=le(s,p);y!=m&&a.push({from:f.from,to:f.from+y.length,insert:m})}return a.length?[n,{changes:a,sequential:!0}]:n})}const he=h.Facet.define(),ge=new g.NodeProp;function je(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}function Ge(n,e,t){let r=b(n);if(r.length<t)return null;let i=r.resolveStack(t,1),o=null;for(let s=i;s;s=s.next){let l=s.node;if(l.to<=t||l.from>t)continue;if(o&&l.from<e)break;let a=l.type.prop(ge);if(a&&(l.to<r.length-50||r.length==n.doc.length||!ze(l))){let c=a(l,n);c&&c.from<=t&&c.from>=e&&c.to>t&&(o=c)}}return o}function ze(n){let e=n.lastChild;return e&&e.to==n.to&&e.type.isError}function N(n,e,t){for(let r of n.facet(he)){let i=r(n,e,t);if(i)return i}return Ge(n,e,t)}function pe(n,e){let t=e.mapPos(n.from,1),r=e.mapPos(n.to,-1);return t>=r?void 0:{from:t,to:r}}const E=h.StateEffect.define({map:pe}),P=h.StateEffect.define({map:pe});function me(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(r=>r.from<=t&&r.to>=t)||e.push(n.lineBlockAt(t));return e}const S=h.StateField.define({create(){return d.Decoration.none},update(n,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((t,r)=>n=Y(n,t,r)),n=n.map(e.changes);for(let t of e.effects)if(t.is(E)&&!Je(n,t.value.from,t.value.to)){let{preparePlaceholder:r}=e.state.facet(xe),i=r?d.Decoration.replace({widget:new Xe(r(e.state,t.value))}):Z;n=n.update({add:[i.range(t.value.from,t.value.to)]})}else t.is(P)&&(n=n.update({filter:(r,i)=>t.value.from!=r||t.value.to!=i,filterFrom:t.value.from,filterTo:t.value.to}));return e.selection&&(n=Y(n,e.selection.main.head)),n},provide:n=>d.EditorView.decorations.from(n),toJSON(n,e){let t=[];return n.between(0,e.doc.length,(r,i)=>{t.push(r,i)}),t},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<n.length;){let r=n[t++],i=n[t++];if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid JSON for fold state");e.push(Z.range(r,i))}return d.Decoration.set(e,!0)}});function Y(n,e,t=e){let r=!1;return n.between(e,t,(i,o)=>{i<t&&o>e&&(r=!0)}),r?n.update({filterFrom:e,filterTo:t,filter:(i,o)=>i>=t||o<=e}):n}function O(n,e,t){var r;let i=null;return(r=n.field(S,!1))===null||r===void 0||r.between(e,t,(o,s)=>{(!i||i.from>o)&&(i={from:o,to:s})}),i}function Je(n,e,t){let r=!1;return n.between(e,e,(i,o)=>{i==e&&o==t&&(r=!0)}),r}function ke(n,e){return n.field(S,!1)?e:e.concat(h.StateEffect.appendConfig.of(J()))}const ye=n=>{for(let e of me(n)){let t=N(n.state,e.from,e.to);if(t)return n.dispatch({effects:ke(n.state,[E.of(t),we(n,t)])}),!0}return!1},be=n=>{if(!n.state.field(S,!1))return!1;let e=[];for(let t of me(n)){let r=O(n.state,t.from,t.to);r&&e.push(P.of(r),we(n,r,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function we(n,e,t=!0){let r=n.state.doc.lineAt(e.from).number,i=n.state.doc.lineAt(e.to).number;return d.EditorView.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${r} ${n.state.phrase("to")} ${i}.`)}const Se=n=>{let{state:e}=n,t=[];for(let r=0;r<e.doc.length;){let i=n.lineBlockAt(r),o=N(e,i.from,i.to);o&&t.push(E.of(o)),r=(o?n.lineBlockAt(o.to):i).to+1}return t.length&&n.dispatch({effects:ke(n.state,t)}),!!t.length},ve=n=>{let e=n.state.field(S,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(r,i)=>{t.push(P.of({from:r,to:i}))}),n.dispatch({effects:t}),!0},Ke=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:ye},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:be},{key:"Ctrl-Alt-[",run:Se},{key:"Ctrl-Alt-]",run:ve}],Qe={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},xe=h.Facet.define({combine(n){return h.combineConfig(n,Qe)}});function J(n){return[S,_e]}function Te(n,e){let{state:t}=n,r=t.facet(xe),i=s=>{let l=n.lineBlockAt(n.posAtDOM(s.target)),a=O(n.state,l.from,l.to);a&&n.dispatch({effects:P.of(a)}),s.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(n,i,e);let o=document.createElement("span");return o.textContent=r.placeholderText,o.setAttribute("aria-label",t.phrase("folded code")),o.title=t.phrase("unfold"),o.className="cm-foldPlaceholder",o.onclick=i,o}const Z=d.Decoration.replace({widget:new class extends d.WidgetType{toDOM(n){return Te(n,null)}}});class Xe extends d.WidgetType{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return Te(e,this.value)}}const Ye={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class R extends d.GutterMarker{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function Ze(n={}){let e={...Ye,...n},t=new R(e,!0),r=new R(e,!1),i=d.ViewPlugin.fromClass(class{constructor(s){this.from=s.viewport.from,this.markers=this.buildMarkers(s)}update(s){(s.docChanged||s.viewportChanged||s.startState.facet(w)!=s.state.facet(w)||s.startState.field(S,!1)!=s.state.field(S,!1)||b(s.startState)!=b(s.state)||e.foldingChanged(s))&&(this.markers=this.buildMarkers(s.view))}buildMarkers(s){let l=new h.RangeSetBuilder;for(let a of s.viewportLineBlocks){let c=O(s.state,a.from,a.to)?r:N(s.state,a.from,a.to)?t:null;c&&l.add(a.from,a.from,c)}return l.finish()}}),{domEventHandlers:o}=e;return[i,d.gutter({class:"cm-foldGutter",markers(s){var l;return((l=s.plugin(i))===null||l===void 0?void 0:l.markers)||h.RangeSet.empty},initialSpacer(){return new R(e,!1)},domEventHandlers:{...o,click:(s,l,a)=>{if(o.click&&o.click(s,l,a))return!0;let c=O(s.state,l.from,l.to);if(c)return s.dispatch({effects:P.of(c)}),!0;let f=N(s.state,l.from,l.to);return f?(s.dispatch({effects:E.of(f)}),!0):!1}}}),J()]}const _e=d.EditorView.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class M{constructor(e,t){this.specs=e;let r;function i(l){let a=K.StyleModule.newName();return(r||(r=Object.create(null)))["."+a]=l,a}const o=typeof t.all=="string"?t.all:t.all?i(t.all):void 0,s=t.scope;this.scope=s instanceof k?l=>l.prop(v)==s.data:s?l=>l==s:void 0,this.style=u.tagHighlighter(e.map(l=>({tag:l.tag,class:l.class||i(Object.assign({},l,{tag:null}))})),{all:o}).style,this.module=r?new K.StyleModule(r):null,this.themeType=t.themeType}static define(e,t){return new M(e,t||{})}}const $=h.Facet.define(),Ce=h.Facet.define({combine(n){return n.length?[n[0]]:null}});function U(n){let e=n.facet($);return e.length?e:n.facet(Ce)}function et(n,e){let t=[nt],r;return n instanceof M&&(n.module&&t.push(d.EditorView.styleModule.of(n.module)),r=n.themeType),e?.fallback?t.push(Ce.of(n)):r?t.push($.computeN([d.EditorView.darkTheme],i=>i.facet(d.EditorView.darkTheme)==(r=="dark")?[n]:[])):t.push($.of(n)),t}class tt{constructor(e){this.markCache=Object.create(null),this.tree=b(e.state),this.decorations=this.buildDeco(e,U(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=b(e.state),r=U(e.state),i=r!=U(e.startState),{viewport:o}=e.view,s=e.changes.mapPos(this.decoratedTo,1);t.length<o.to&&!i&&t.type==this.tree.type&&s>=o.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=s):(t!=this.tree||e.viewportChanged||i)&&(this.tree=t,this.decorations=this.buildDeco(e.view,r),this.decoratedTo=o.to)}buildDeco(e,t){if(!t||!this.tree.length)return d.Decoration.none;let r=new h.RangeSetBuilder;for(let{from:i,to:o}of e.visibleRanges)u.highlightTree(this.tree,t,(s,l,a)=>{r.add(s,l,this.markCache[a]||(this.markCache[a]=d.Decoration.mark({class:a})))},i,o);return r.finish()}}const nt=h.Prec.high(d.ViewPlugin.fromClass(tt,{decorations:n=>n.decorations})),rt=M.define([{tag:u.tags.meta,color:"#404740"},{tag:u.tags.link,textDecoration:"underline"},{tag:u.tags.heading,textDecoration:"underline",fontWeight:"bold"},{tag:u.tags.emphasis,fontStyle:"italic"},{tag:u.tags.strong,fontWeight:"bold"},{tag:u.tags.strikethrough,textDecoration:"line-through"},{tag:u.tags.keyword,color:"#708"},{tag:[u.tags.atom,u.tags.bool,u.tags.url,u.tags.contentSeparator,u.tags.labelName],color:"#219"},{tag:[u.tags.literal,u.tags.inserted],color:"#164"},{tag:[u.tags.string,u.tags.deleted],color:"#a11"},{tag:[u.tags.regexp,u.tags.escape,u.tags.special(u.tags.string)],color:"#e40"},{tag:u.tags.definition(u.tags.variableName),color:"#00f"},{tag:u.tags.local(u.tags.variableName),color:"#30a"},{tag:[u.tags.typeName,u.tags.namespace],color:"#085"},{tag:u.tags.className,color:"#167"},{tag:[u.tags.special(u.tags.variableName),u.tags.macroName],color:"#256"},{tag:u.tags.definition(u.tags.propertyName),color:"#00c"},{tag:u.tags.comment,color:"#940"},{tag:u.tags.invalid,color:"#f00"}]),it=d.EditorView.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Pe=1e4,Ae="()[]{}",De=h.Facet.define({combine(n){return h.combineConfig(n,{afterCursor:!0,brackets:Ae,maxScanDistance:Pe,renderMatch:at})}}),ot=d.Decoration.mark({class:"cm-matchingBracket"}),st=d.Decoration.mark({class:"cm-nonmatchingBracket"});function at(n){let e=[],t=n.matched?ot:st;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}const lt=h.StateField.define({create(){return d.Decoration.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],r=e.state.facet(De);for(let i of e.state.selection.ranges){if(!i.empty)continue;let o=D(e.state,i.head,-1,r)||i.head>0&&D(e.state,i.head-1,1,r)||r.afterCursor&&(D(e.state,i.head,1,r)||i.head<e.state.doc.length&&D(e.state,i.head+1,-1,r));o&&(t=t.concat(r.renderMatch(o,e.state)))}return d.Decoration.set(t,!0)},provide:n=>d.EditorView.decorations.from(n)}),ct=[lt,it];function ft(n={}){return[De.of(n),ct]}const Ie=new g.NodeProp;function q(n,e,t){let r=n.prop(e<0?g.NodeProp.openedBy:g.NodeProp.closedBy);if(r)return r;if(n.name.length==1){let i=t.indexOf(n.name);if(i>-1&&i%2==(e<0?1:0))return[t[i+e]]}return null}function j(n){let e=n.type.prop(Ie);return e?e(n.node):n}function D(n,e,t,r={}){let i=r.maxScanDistance||Pe,o=r.brackets||Ae,s=b(n),l=s.resolveInner(e,t);for(let a=l;a;a=a.parent){let c=q(a.type,t,o);if(c&&a.from<a.to){let f=j(a);if(f&&(t>0?e>=f.from&&e<f.to:e>f.from&&e<=f.to))return ut(n,e,t,a,f,c,o)}}return dt(n,e,t,s,l.type,i,o)}function ut(n,e,t,r,i,o,s){let l=r.parent,a={from:i.from,to:i.to},c=0,f=l?.cursor();if(f&&(t<0?f.childBefore(r.from):f.childAfter(r.to)))do if(t<0?f.to<=r.from:f.from>=r.to){if(c==0&&o.indexOf(f.type.name)>-1&&f.from<f.to){let p=j(f);return{start:a,end:p?{from:p.from,to:p.to}:void 0,matched:!0}}else if(q(f.type,t,s))c++;else if(q(f.type,-t,s)){if(c==0){let p=j(f);return{start:a,end:p&&p.from<p.to?{from:p.from,to:p.to}:void 0,matched:!1}}c--}}while(t<0?f.prevSibling():f.nextSibling());return{start:a,matched:!1}}function dt(n,e,t,r,i,o,s){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=s.indexOf(l);if(a<0||a%2==0!=t>0)return null;let c={from:t<0?e-1:e,to:t>0?e+1:e},f=n.doc.iterRange(e,t>0?n.doc.length:0),p=0;for(let y=0;!f.next().done&&y<=o;){let m=f.value;t<0&&(y+=m.length);let x=e+y*t;for(let T=t>0?0:m.length-1,Ne=t>0?m.length:-1;T!=Ne;T+=t){let L=s.indexOf(m[T]);if(!(L<0||r.resolveInner(x+T,1).type!=i))if(L%2==0==t>0)p++;else{if(p==1)return{start:c,end:{from:x+T,to:x+T+1},matched:L>>1==a>>1};p--}}t>0&&(y+=m.length)}return f.done?{start:c,matched:!1}:null}const ht=Object.create(null),_=[g.NodeType.none],ee=[],te=Object.create(null),gt=Object.create(null);for(let[n,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"]])gt[n]=pt(ht,e);function V(n,e){ee.indexOf(n)>-1||(ee.push(n),console.warn(e))}function pt(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let c of l.split(".")){let f=n[c]||u.tags[c];f?typeof f=="function"?a.length?a=a.map(f):V(c,`Modifier ${c} used at start of tag`):a.length?V(c,`Tag ${c} used as modifier`):a=Array.isArray(f)?f:[f]:V(c,`Unknown highlighting tag ${c}`)}for(let c of a)t.push(c)}if(!t.length)return 0;let r=e.replace(/ /g,"_"),i=r+" "+t.map(l=>l.id),o=te[i];if(o)return o.id;let s=te[i]=g.NodeType.define({id:_.length,name:r,props:[u.styleTags({[r]:t})]});return _.push(s),s.id}d.Direction.RTL,d.Direction.LTR;exports.DocInput=ie;exports.HighlightStyle=M;exports.IndentContext=z;exports.LRLanguage=B;exports.Language=k;exports.LanguageSupport=Me;exports.ParseContext=I;exports.TreeIndentContext=F;exports.bracketMatching=ft;exports.bracketMatchingHandle=Ie;exports.codeFolding=J;exports.continuedIndent=Ve;exports.defaultHighlightStyle=rt;exports.defineLanguageFacet=ne;exports.delimitedIndent=Re;exports.flatIndent=Ue;exports.foldAll=Se;exports.foldCode=ye;exports.foldEffect=E;exports.foldGutter=Ze;exports.foldInside=je;exports.foldKeymap=Ke;exports.foldNodeProp=ge;exports.foldService=he;exports.foldState=S;exports.foldable=N;exports.getIndentUnit=ae;exports.getIndentation=ce;exports.indentNodeProp=fe;exports.indentOnInput=qe;exports.indentService=se;exports.indentString=le;exports.indentUnit=G;exports.language=w;exports.languageDataProp=v;exports.matchBrackets=D;exports.sublanguageProp=re;exports.syntaxHighlighting=et;exports.syntaxTree=b;exports.unfoldAll=ve;exports.unfoldCode=be;exports.unfoldEffect=P;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../view/dist/index.js"),c=require("../../state/dist/index.js"),f=require("../../../crelt/index.js"),U=typeof String.prototype.normalize=="function"?t=>t.normalize("NFKD"):t=>t;class x{constructor(e,r,n=0,i=e.length,s,l){this.test=l,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=s?o=>s(U(o)):U,this.query=this.normalize(r)}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 c.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 r=c.fromCodePoint(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=c.codePointSize(e);let i=this.normalize(r);if(i.length)for(let s=0,l=n;;s++){let o=i.charCodeAt(s),a=this.match(o,l,this.bufferPos+this.bufferStart);if(s==i.length-1){if(a)return this.value=a,this;break}l==n&&s<r.length&&r.charCodeAt(s)==o&&l++}}}match(e,r,n){let i=null;for(let s=0;s<this.matches.length;s+=2){let l=this.matches[s],o=!1;this.query.charCodeAt(l)==e&&(l==this.query.length-1?i={from:this.matches[s+1],to:n}:(this.matches[s]++,o=!0)),o||(this.matches.splice(s,2),s-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?i={from:r,to:n}:this.matches.push(1,r)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(x.prototype[Symbol.iterator]=function(){return this});const Z={from:-1,to:-1,match:/.*/.exec("")},Q="gm"+(/x/.unicode==null?"":"u");class N{constructor(e,r,n,i=0,s=e.length){if(this.text=e,this.to=s,this.curLine="",this.done=!1,this.value=Z,/\\[sWDnr]|\n|\r|\[\^/.test(r))return new ee(e,r,n,i,s);this.re=new RegExp(r,Q+(n?.ignoreCase?"i":"")),this.test=n?.test,this.iter=e.iter();let l=e.lineAt(i);this.curLineStart=l.from,this.matchPos=F(e,i),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 r=this.matchPos<=this.to&&this.re.exec(this.curLine);if(r){let n=this.curLineStart+r.index,i=n+r[0].length;if(this.matchPos=F(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<i||n>this.value.to)&&(!this.test||this.test(n,i,r)))return this.value={from:n,to:i,match:r},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const I=new WeakMap;class C{constructor(e,r){this.from=e,this.text=r}get to(){return this.from+this.text.length}static get(e,r,n){let i=I.get(e);if(!i||i.from>=n||i.to<=r){let o=new C(r,e.sliceString(r,n));return I.set(e,o),o}if(i.from==r&&i.to==n)return i;let{text:s,from:l}=i;return l>r&&(s=e.sliceString(r,l)+s,l=r),i.to<n&&(s+=e.sliceString(i.to,n)),I.set(e,new C(l,s)),new C(r,s.slice(r-l,n-l))}}class ee{constructor(e,r,n,i,s){this.text=e,this.to=s,this.done=!1,this.value=Z,this.matchPos=F(e,i),this.re=new RegExp(r,Q+(n?.ignoreCase?"i":"")),this.test=n?.test,this.flat=C.get(e,i,this.chunkEnd(i+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,r=this.re.exec(this.flat.text);if(r&&!r[0]&&r.index==e&&(this.re.lastIndex=e+1,r=this.re.exec(this.flat.text)),r){let n=this.flat.from+r.index,i=n+r[0].length;if((this.flat.to>=this.to||r.index+r[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,i,r)))return this.value={from:n,to:i,match:r},this.matchPos=F(this.text,i+(n==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=C.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(N.prototype[Symbol.iterator]=ee.prototype[Symbol.iterator]=function(){return this});function ce(t){try{return new RegExp(t,Q),!0}catch{return!1}}function F(t,e){if(e>=t.length)return e;let r=t.lineAt(e),n;for(;e<r.to&&(n=r.text.charCodeAt(e-r.from))>=56320&&n<57344;)e++;return e}function V(t){let e=String(t.state.doc.lineAt(t.state.selection.main.head).number),r=f.default("input",{class:"cm-textfield",name:"line",value:e}),n=f.default("form",{class:"cm-gotoLine",onkeydown:s=>{s.keyCode==27?(s.preventDefault(),t.dispatch({effects:E.of(!1)}),t.focus()):s.keyCode==13&&(s.preventDefault(),i())},onsubmit:s=>{s.preventDefault(),i()}},f.default("label",t.state.phrase("Go to line"),": ",r)," ",f.default("button",{class:"cm-button",type:"submit"},t.state.phrase("go")),f.default("button",{name:"close",onclick:()=>{t.dispatch({effects:E.of(!1)}),t.focus()},"aria-label":t.state.phrase("close"),type:"button"},["×"]));function i(){let s=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(r.value);if(!s)return;let{state:l}=t,o=l.doc.lineAt(l.selection.main.head),[,a,u,d,m]=s,W=d?+d.slice(1):0,v=u?+u:o.number;if(u&&m){let w=v/100;a&&(w=w*(a=="-"?-1:1)+o.number/l.doc.lines),v=Math.round(l.doc.lines*w)}else u&&a&&(v=v*(a=="-"?-1:1)+o.number);let G=l.doc.line(Math.max(1,Math.min(l.doc.lines,v))),J=c.EditorSelection.cursor(G.from+Math.max(0,Math.min(W,G.length)));t.dispatch({effects:[E.of(!1),h.EditorView.scrollIntoView(J.from,{y:"center"})],selection:J}),t.focus()}return{dom:n}}const E=c.StateEffect.define(),X=c.StateField.define({create(){return!0},update(t,e){for(let r of e.effects)r.is(E)&&(t=r.value);return t},provide:t=>h.showPanel.from(t,e=>e?V:null)}),te=t=>{let e=h.getPanel(t,V);if(!e){let r=[E.of(!0)];t.state.field(X,!1)==null&&r.push(c.StateEffect.appendConfig.of([X,he])),t.dispatch({effects:r}),e=h.getPanel(t,V)}return e&&e.dom.querySelector("input").select(),!0},he=h.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"}}}),ue={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},fe=c.Facet.define({combine(t){return c.combineConfig(t,ue,{highlightWordAroundCursor:(e,r)=>e||r,minSelectionLength:Math.min,maxMatches:Math.min})}});function de(t){return[Se,xe]}const ge=h.Decoration.mark({class:"cm-selectionMatch"}),me=h.Decoration.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Y(t,e,r,n){return(r==0||t(e.sliceDoc(r-1,r))!=c.CharCategory.Word)&&(n==e.doc.length||t(e.sliceDoc(n,n+1))!=c.CharCategory.Word)}function pe(t,e,r,n){return t(e.sliceDoc(r,r+1))==c.CharCategory.Word&&t(e.sliceDoc(n-1,n))==c.CharCategory.Word}const xe=h.ViewPlugin.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(fe),{state:r}=t,n=r.selection;if(n.ranges.length>1)return h.Decoration.none;let i=n.main,s,l=null;if(i.empty){if(!e.highlightWordAroundCursor)return h.Decoration.none;let a=r.wordAt(i.head);if(!a)return h.Decoration.none;l=r.charCategorizer(i.head),s=r.sliceDoc(a.from,a.to)}else{let a=i.to-i.from;if(a<e.minSelectionLength||a>200)return h.Decoration.none;if(e.wholeWords){if(s=r.sliceDoc(i.from,i.to),l=r.charCategorizer(i.head),!(Y(l,r,i.from,i.to)&&pe(l,r,i.from,i.to)))return h.Decoration.none}else if(s=r.sliceDoc(i.from,i.to),!s)return h.Decoration.none}let o=[];for(let a of t.visibleRanges){let u=new x(r.doc,s,a.from,a.to);for(;!u.next().done;){let{from:d,to:m}=u.value;if((!l||Y(l,r,d,m))&&(i.empty&&d<=i.from&&m>=i.to?o.push(me.range(d,m)):(d>=i.to||m<=i.from)&&o.push(ge.range(d,m)),o.length>e.maxMatches))return h.Decoration.none}}return h.Decoration.set(o)}},{decorations:t=>t.decorations}),Se=h.EditorView.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),ye=({state:t,dispatch:e})=>{let{selection:r}=t,n=c.EditorSelection.create(r.ranges.map(i=>t.wordAt(i.head)||c.EditorSelection.cursor(i.head)),r.mainIndex);return n.eq(r)?!1:(e(t.update({selection:n})),!0)};function Ce(t,e){let{main:r,ranges:n}=t.selection,i=t.wordAt(r.head),s=i&&i.from==r.from&&i.to==r.to;for(let l=!1,o=new x(t.doc,e,n[n.length-1].to);;)if(o.next(),o.done){if(l)return null;o=new x(t.doc,e,0,Math.max(0,n[n.length-1].from-1)),l=!0}else{if(l&&n.some(a=>a.from==o.value.from))continue;if(s){let a=t.wordAt(o.value.from);if(!a||a.from!=o.value.from||a.to!=o.value.to)continue}return o.value}}const re=({state:t,dispatch:e})=>{let{ranges:r}=t.selection;if(r.some(s=>s.from===s.to))return ye({state:t,dispatch:e});let n=t.sliceDoc(r[0].from,r[0].to);if(t.selection.ranges.some(s=>t.sliceDoc(s.from,s.to)!=n))return!1;let i=Ce(t,n);return i?(e(t.update({selection:t.selection.addRange(c.EditorSelection.range(i.from,i.to),!1),effects:h.EditorView.scrollIntoView(i.to)})),!0):!1},b=c.Facet.define({combine(t){return c.combineConfig(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Pe(e),scrollToMatch:e=>h.EditorView.scrollIntoView(e)})}});class z{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||ce(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(r,n)=>n=="n"?`
2
- `:n=="r"?"\r":n=="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 Ee(this):new be(this)}getCursor(e,r=0,n){let i=e.doc?e:c.EditorState.create({doc:e});return n==null&&(n=i.doc.length),this.regexp?y(this,i,r,n):S(this,i,r,n)}}class ne{constructor(e){this.spec=e}}function S(t,e,r,n){return new x(e.doc,t.unquoted,r,n,t.caseSensitive?void 0:i=>i.toLowerCase(),t.wholeWord?Me(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function Me(t,e){return(r,n,i,s)=>((s>r||s+i.length<n)&&(s=Math.max(0,r-2),i=t.sliceString(s,Math.min(t.length,n+2))),(e(q(i,r-s))!=c.CharCategory.Word||e(R(i,r-s))!=c.CharCategory.Word)&&(e(R(i,n-s))!=c.CharCategory.Word||e(q(i,n-s))!=c.CharCategory.Word))}class be extends ne{constructor(e){super(e)}nextMatch(e,r,n){let i=S(this.spec,e,n,e.doc.length).nextOverlapping();if(i.done){let s=Math.min(e.doc.length,r+this.spec.unquoted.length);i=S(this.spec,e,0,s).nextOverlapping()}return i.done||i.value.from==r&&i.value.to==n?null:i.value}prevMatchInRange(e,r,n){for(let i=n;;){let s=Math.max(r,i-1e4-this.spec.unquoted.length),l=S(this.spec,e,s,i),o=null;for(;!l.nextOverlapping().done;)o=l.value;if(o)return o;if(s==r)return null;i-=1e4}}prevMatch(e,r,n){let i=this.prevMatchInRange(e,0,r);return i||(i=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length)),i&&(i.from!=r||i.to!=n)?i:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,r){let n=S(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=r)return null;i.push(n.value)}return i}highlight(e,r,n,i){let s=S(this.spec,e,Math.max(0,r-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}function y(t,e,r,n){return new N(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?ve(e.charCategorizer(e.selection.main.head)):void 0},r,n)}function q(t,e){return t.slice(c.findClusterBreak(t,e,!1),e)}function R(t,e){return t.slice(e,c.findClusterBreak(t,e))}function ve(t){return(e,r,n)=>!n[0].length||(t(q(n.input,n.index))!=c.CharCategory.Word||t(R(n.input,n.index))!=c.CharCategory.Word)&&(t(R(n.input,n.index+n[0].length))!=c.CharCategory.Word||t(q(n.input,n.index+n[0].length))!=c.CharCategory.Word)}class Ee extends ne{nextMatch(e,r,n){let i=y(this.spec,e,n,e.doc.length).next();return i.done&&(i=y(this.spec,e,0,r).next()),i.done?null:i.value}prevMatchInRange(e,r,n){for(let i=1;;i++){let s=Math.max(r,n-i*1e4),l=y(this.spec,e,s,n),o=null;for(;!l.next().done;)o=l.value;if(o&&(s==r||o.from>s+10))return o;if(s==r)return null}}prevMatch(e,r,n){return this.prevMatchInRange(e,0,r)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(r,n)=>{if(n=="&")return e.match[0];if(n=="$")return"$";for(let i=n.length;i>0;i--){let s=+n.slice(0,i);if(s>0&&s<e.match.length)return e.match[s]+n.slice(i)}return r})}matchAll(e,r){let n=y(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=r)return null;i.push(n.value)}return i}highlight(e,r,n,i){let s=y(this.spec,e,Math.max(0,r-250),Math.min(n+250,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}const M=c.StateEffect.define(),B=c.StateEffect.define(),p=c.StateField.define({create(t){return new T(O(t).create(),null)},update(t,e){for(let r of e.effects)r.is(M)?t=new T(r.value.create(),t.panel):r.is(B)&&(t=new T(t.query,r.value?_:null));return t},provide:t=>h.showPanel.from(t,e=>e.panel)});class T{constructor(e,r){this.query=e,this.panel=r}}const ke=h.Decoration.mark({class:"cm-searchMatch"}),De=h.Decoration.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Le=h.ViewPlugin.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(p))}update(t){let e=t.state.field(p);(e!=t.startState.field(p)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return h.Decoration.none;let{view:r}=this,n=new c.RangeSetBuilder;for(let i=0,s=r.visibleRanges,l=s.length;i<l;i++){let{from:o,to:a}=s[i];for(;i<l-1&&a>s[i+1].from-500;)a=s[++i].to;t.highlight(r.state,o,a,(u,d)=>{let m=r.state.selection.ranges.some(W=>W.from==u&&W.to==d);n.add(u,d,m?De:ke)})}return n.finish()}},{decorations:t=>t.decorations});function L(t){return e=>{let r=e.state.field(p,!1);return r&&r.query.spec.valid?t(e,r):H(e)}}const k=L((t,{query:e})=>{let{to:r}=t.state.selection.main,n=e.nextMatch(t.state,r,r);if(!n)return!1;let i=c.EditorSelection.single(n.from,n.to),s=t.state.facet(b);return t.dispatch({selection:i,effects:[j(t,n),s.scrollToMatch(i.main,t)],userEvent:"select.search"}),ae(t),!0}),D=L((t,{query:e})=>{let{state:r}=t,{from:n}=r.selection.main,i=e.prevMatch(r,n,n);if(!i)return!1;let s=c.EditorSelection.single(i.from,i.to),l=t.state.facet(b);return t.dispatch({selection:s,effects:[j(t,i),l.scrollToMatch(s.main,t)],userEvent:"select.search"}),ae(t),!0}),ie=L((t,{query:e})=>{let r=e.matchAll(t.state,1e3);return!r||!r.length?!1:(t.dispatch({selection:c.EditorSelection.create(r.map(n=>c.EditorSelection.range(n.from,n.to))),userEvent:"select.search.matches"}),!0)}),se=({state:t,dispatch:e})=>{let r=t.selection;if(r.ranges.length>1||r.main.empty)return!1;let{from:n,to:i}=r.main,s=[],l=0;for(let o=new x(t.doc,t.sliceDoc(n,i));!o.next().done;){if(s.length>1e3)return!1;o.value.from==n&&(l=s.length),s.push(c.EditorSelection.range(o.value.from,o.value.to))}return e(t.update({selection:c.EditorSelection.create(s,l),userEvent:"select.search.matches"})),!0},$=L((t,{query:e})=>{let{state:r}=t,{from:n,to:i}=r.selection.main;if(r.readOnly)return!1;let s=e.nextMatch(r,n,n);if(!s)return!1;let l=s,o=[],a,u,d=[];l.from==n&&l.to==i&&(u=r.toText(e.getReplacement(l)),o.push({from:l.from,to:l.to,insert:u}),l=e.nextMatch(r,l.from,l.to),d.push(h.EditorView.announce.of(r.phrase("replaced match on line $",r.doc.lineAt(n).number)+".")));let m=t.state.changes(o);return l&&(a=c.EditorSelection.single(l.from,l.to).map(m),d.push(j(t,l)),d.push(r.facet(b).scrollToMatch(a.main,t))),t.dispatch({changes:m,selection:a,effects:d,userEvent:"input.replace"}),!0}),le=L((t,{query:e})=>{if(t.state.readOnly)return!1;let r=e.matchAll(t.state,1e9).map(i=>{let{from:s,to:l}=i;return{from:s,to:l,insert:e.getReplacement(i)}});if(!r.length)return!1;let n=t.state.phrase("replaced $ matches",r.length)+".";return t.dispatch({changes:r,effects:h.EditorView.announce.of(n),userEvent:"input.replace.all"}),!0});function _(t){return t.state.facet(b).createPanel(t)}function O(t,e){var r,n,i,s,l;let o=t.selection.main,a=o.empty||o.to>o.from+100?"":t.sliceDoc(o.from,o.to);if(e&&!a)return e;let u=t.facet(b);return new z({search:((r=e?.literal)!==null&&r!==void 0?r:u.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(n=e?.caseSensitive)!==null&&n!==void 0?n:u.caseSensitive,literal:(i=e?.literal)!==null&&i!==void 0?i:u.literal,regexp:(s=e?.regexp)!==null&&s!==void 0?s:u.regexp,wholeWord:(l=e?.wholeWord)!==null&&l!==void 0?l:u.wholeWord})}function oe(t){let e=h.getPanel(t,_);return e&&e.dom.querySelector("[main-field]")}function ae(t){let e=oe(t);e&&e==t.root.activeElement&&e.select()}const H=t=>{let e=t.state.field(p,!1);if(e&&e.panel){let r=oe(t);if(r&&r!=t.root.activeElement){let n=O(t.state,e.query.spec);n.valid&&t.dispatch({effects:M.of(n)}),r.focus(),r.select()}}else t.dispatch({effects:[B.of(!0),e?M.of(O(t.state,e.query.spec)):c.StateEffect.appendConfig.of(Fe)]});return!0},K=t=>{let e=t.state.field(p,!1);if(!e||!e.panel)return!1;let r=h.getPanel(t,_);return r&&r.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:B.of(!1)}),!0},We=[{key:"Mod-f",run:H,scope:"editor search-panel"},{key:"F3",run:k,shift:D,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:k,shift:D,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:K,scope:"editor search-panel"},{key:"Mod-Shift-l",run:se},{key:"Mod-Alt-g",run:te},{key:"Mod-d",run:re,preventDefault:!0}];class Pe{constructor(e){this.view=e;let r=this.query=e.state.field(p).query.spec;this.commit=this.commit.bind(this),this.searchField=f.default("input",{value:r.search,placeholder:g(e,"Find"),"aria-label":g(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=f.default("input",{value:r.replace,placeholder:g(e,"Replace"),"aria-label":g(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=f.default("input",{type:"checkbox",name:"case",form:"",checked:r.caseSensitive,onchange:this.commit}),this.reField=f.default("input",{type:"checkbox",name:"re",form:"",checked:r.regexp,onchange:this.commit}),this.wordField=f.default("input",{type:"checkbox",name:"word",form:"",checked:r.wholeWord,onchange:this.commit});function n(i,s,l){return f.default("button",{class:"cm-button",name:i,onclick:s,type:"button"},l)}this.dom=f.default("div",{onkeydown:i=>this.keydown(i),class:"cm-search"},[this.searchField,n("next",()=>k(e),[g(e,"next")]),n("prev",()=>D(e),[g(e,"previous")]),n("select",()=>ie(e),[g(e,"all")]),f.default("label",null,[this.caseField,g(e,"match case")]),f.default("label",null,[this.reField,g(e,"regexp")]),f.default("label",null,[this.wordField,g(e,"by word")]),...e.state.readOnly?[]:[f.default("br"),this.replaceField,n("replace",()=>$(e),[g(e,"replace")]),n("replaceAll",()=>le(e),[g(e,"replace all")])],f.default("button",{name:"close",onclick:()=>K(e),"aria-label":g(e,"close"),type:"button"},["×"])])}commit(){let e=new z({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:M.of(e)}))}keydown(e){h.runScopeHandlers(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?D:k)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),$(this.view))}update(e){for(let r of e.transactions)for(let n of r.effects)n.is(M)&&!n.value.eq(this.query)&&this.setQuery(n.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(b).top}}function g(t,e){return t.state.phrase(e)}const P=30,A=/[\s\.,:;?!]/;function j(t,{from:e,to:r}){let n=t.state.doc.lineAt(e),i=t.state.doc.lineAt(r).to,s=Math.max(n.from,e-P),l=Math.min(i,r+P),o=t.state.sliceDoc(s,l);if(s!=n.from){for(let a=0;a<P;a++)if(!A.test(o[a+1])&&A.test(o[a])){o=o.slice(a);break}}if(l!=i){for(let a=o.length-1;a>o.length-P;a--)if(!A.test(o[a-1])&&A.test(o[a])){o=o.slice(0,a);break}}return h.EditorView.announce.of(`${t.state.phrase("current match")}. ${o} ${t.state.phrase("on line")} ${n.number}.`)}const Ae=h.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"}}),Fe=[p,c.Prec.low(Le),Ae];exports.RegExpCursor=N;exports.SearchCursor=x;exports.SearchQuery=z;exports.closeSearchPanel=K;exports.findNext=k;exports.findPrevious=D;exports.gotoLine=te;exports.highlightSelectionMatches=de;exports.openSearchPanel=H;exports.replaceAll=le;exports.replaceNext=$;exports.searchKeymap=We;exports.selectMatches=ie;exports.selectNextOccurrence=re;exports.selectSelectionMatches=se;exports.setSearchQuery=M;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../view/dist/index.js"),a=require("../../state/dist/index.js"),m=require("../../../crelt/index.js"),G=typeof String.prototype.normalize=="function"?r=>r.normalize("NFKD"):r=>r;class x{constructor(e,t,n=0,i=e.length,s,l){this.test=l,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=s?o=>s(G(o)):G,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 a.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=a.fromCodePoint(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=a.codePointSize(e);let i=this.normalize(t);if(i.length)for(let s=0,l=n;;s++){let o=i.charCodeAt(s),c=this.match(o,l,this.bufferPos+this.bufferStart);if(s==i.length-1){if(c)return this.value=c,this;break}l==n&&s<t.length&&t.charCodeAt(s)==o&&l++}}}match(e,t,n){let i=null;for(let s=0;s<this.matches.length;s+=2){let l=this.matches[s],o=!1;this.query.charCodeAt(l)==e&&(l==this.query.length-1?i={from:this.matches[s+1],to:n}:(this.matches[s]++,o=!0)),o||(this.matches.splice(s,2),s-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?i={from:t,to:n}:this.matches.push(1,t)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(x.prototype[Symbol.iterator]=function(){return this});const U={from:-1,to:-1,match:/.*/.exec("")},V="gm"+(/x/.unicode==null?"":"u");class ${constructor(e,t,n,i=0,s=e.length){if(this.text=e,this.to=s,this.curLine="",this.done=!1,this.value=U,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new X(e,t,n,i,s);this.re=new RegExp(t,V+(n?.ignoreCase?"i":"")),this.test=n?.test,this.iter=e.iter();let l=e.lineAt(i);this.curLineStart=l.from,this.matchPos=A(e,i),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 n=this.curLineStart+t.index,i=n+t[0].length;if(this.matchPos=A(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<i||n>this.value.to)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const P=new WeakMap;class C{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,n){let i=P.get(e);if(!i||i.from>=n||i.to<=t){let o=new C(t,e.sliceString(t,n));return P.set(e,o),o}if(i.from==t&&i.to==n)return i;let{text:s,from:l}=i;return l>t&&(s=e.sliceString(t,l)+s,l=t),i.to<n&&(s+=e.sliceString(i.to,n)),P.set(e,new C(l,s)),new C(t,s.slice(t-l,n-l))}}class X{constructor(e,t,n,i,s){this.text=e,this.to=s,this.done=!1,this.value=U,this.matchPos=A(e,i),this.re=new RegExp(t,V+(n?.ignoreCase?"i":"")),this.test=n?.test,this.flat=C.get(e,i,this.chunkEnd(i+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 n=this.flat.from+t.index,i=n+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this.matchPos=A(this.text,i+(n==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=C.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&($.prototype[Symbol.iterator]=X.prototype[Symbol.iterator]=function(){return this});function le(r){try{return new RegExp(r,V),!0}catch{return!1}}function A(r,e){if(e>=r.length)return e;let t=r.lineAt(e),n;for(;e<t.to&&(n=t.text.charCodeAt(e-t.from))>=56320&&n<57344;)e++;return e}const Y=r=>{let{state:e}=r,t=String(e.doc.lineAt(r.state.selection.main.head).number),{close:n,result:i}=h.showDialog(r,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:t},focus:!0,submitLabel:e.phrase("go")});return i.then(s=>{let l=s&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(s.elements.line.value);if(!l){r.dispatch({effects:n});return}let o=e.doc.lineAt(e.selection.main.head),[,c,u,f,g]=l,D=f?+f.slice(1):0,E=u?+u:o.number;if(u&&g){let R=E/100;c&&(R=R*(c=="-"?-1:1)+o.number/e.doc.lines),E=Math.round(e.doc.lines*R)}else u&&c&&(E=E*(c=="-"?-1:1)+o.number);let K=e.doc.line(Math.max(1,Math.min(e.doc.lines,E))),j=a.EditorSelection.cursor(K.from+Math.max(0,Math.min(D,K.length)));r.dispatch({effects:[n,h.EditorView.scrollIntoView(j.from,{y:"center"})],selection:j})}),!0},oe={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},ce=a.Facet.define({combine(r){return a.combineConfig(r,oe,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function ae(r){return[ge,de]}const he=h.Decoration.mark({class:"cm-selectionMatch"}),ue=h.Decoration.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function J(r,e,t,n){return(t==0||r(e.sliceDoc(t-1,t))!=a.CharCategory.Word)&&(n==e.doc.length||r(e.sliceDoc(n,n+1))!=a.CharCategory.Word)}function fe(r,e,t,n){return r(e.sliceDoc(t,t+1))==a.CharCategory.Word&&r(e.sliceDoc(n-1,n))==a.CharCategory.Word}const de=h.ViewPlugin.fromClass(class{constructor(r){this.decorations=this.getDeco(r)}update(r){(r.selectionSet||r.docChanged||r.viewportChanged)&&(this.decorations=this.getDeco(r.view))}getDeco(r){let e=r.state.facet(ce),{state:t}=r,n=t.selection;if(n.ranges.length>1)return h.Decoration.none;let i=n.main,s,l=null;if(i.empty){if(!e.highlightWordAroundCursor)return h.Decoration.none;let c=t.wordAt(i.head);if(!c)return h.Decoration.none;l=t.charCategorizer(i.head),s=t.sliceDoc(c.from,c.to)}else{let c=i.to-i.from;if(c<e.minSelectionLength||c>200)return h.Decoration.none;if(e.wholeWords){if(s=t.sliceDoc(i.from,i.to),l=t.charCategorizer(i.head),!(J(l,t,i.from,i.to)&&fe(l,t,i.from,i.to)))return h.Decoration.none}else if(s=t.sliceDoc(i.from,i.to),!s)return h.Decoration.none}let o=[];for(let c of r.visibleRanges){let u=new x(t.doc,s,c.from,c.to);for(;!u.next().done;){let{from:f,to:g}=u.value;if((!l||J(l,t,f,g))&&(i.empty&&f<=i.from&&g>=i.to?o.push(ue.range(f,g)):(f>=i.to||g<=i.from)&&o.push(he.range(f,g)),o.length>e.maxMatches))return h.Decoration.none}}return h.Decoration.set(o)}},{decorations:r=>r.decorations}),ge=h.EditorView.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),me=({state:r,dispatch:e})=>{let{selection:t}=r,n=a.EditorSelection.create(t.ranges.map(i=>r.wordAt(i.head)||a.EditorSelection.cursor(i.head)),t.mainIndex);return n.eq(t)?!1:(e(r.update({selection:n})),!0)};function pe(r,e){let{main:t,ranges:n}=r.selection,i=r.wordAt(t.head),s=i&&i.from==t.from&&i.to==t.to;for(let l=!1,o=new x(r.doc,e,n[n.length-1].to);;)if(o.next(),o.done){if(l)return null;o=new x(r.doc,e,0,Math.max(0,n[n.length-1].from-1)),l=!0}else{if(l&&n.some(c=>c.from==o.value.from))continue;if(s){let c=r.wordAt(o.value.from);if(!c||c.from!=o.value.from||c.to!=o.value.to)continue}return o.value}}const Z=({state:r,dispatch:e})=>{let{ranges:t}=r.selection;if(t.some(s=>s.from===s.to))return me({state:r,dispatch:e});let n=r.sliceDoc(t[0].from,t[0].to);if(r.selection.ranges.some(s=>r.sliceDoc(s.from,s.to)!=n))return!1;let i=pe(r,n);return i?(e(r.update({selection:r.selection.addRange(a.EditorSelection.range(i.from,i.to),!1),effects:h.EditorView.scrollIntoView(i.to)})),!0):!1},v=a.Facet.define({combine(r){return a.combineConfig(r,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new De(e),scrollToMatch:e=>h.EditorView.scrollIntoView(e)})}});class Q{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||le(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,n)=>n=="n"?`
2
+ `:n=="r"?"\r":n=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new ve(this):new ye(this)}getCursor(e,t=0,n){let i=e.doc?e:a.EditorState.create({doc:e});return n==null&&(n=i.doc.length),this.regexp?y(this,i,t,n):S(this,i,t,n)}}class ee{constructor(e){this.spec=e}}function xe(r,e,t){return(n,i,s,l)=>{if(t&&!t(n,i,s,l))return!1;let o=n>=l&&i<=l+s.length?s.slice(n-l,i-l):e.doc.sliceString(n,i);return r(o,e,n,i)}}function S(r,e,t,n){let i;return r.wholeWord&&(i=Se(e.doc,e.charCategorizer(e.selection.main.head))),r.test&&(i=xe(r.test,e,i)),new x(e.doc,r.unquoted,t,n,r.caseSensitive?void 0:s=>s.toLowerCase(),i)}function Se(r,e){return(t,n,i,s)=>((s>t||s+i.length<n)&&(s=Math.max(0,t-2),i=r.sliceString(s,Math.min(r.length,n+2))),(e(F(i,t-s))!=a.CharCategory.Word||e(q(i,t-s))!=a.CharCategory.Word)&&(e(q(i,n-s))!=a.CharCategory.Word||e(F(i,n-s))!=a.CharCategory.Word))}class ye extends ee{constructor(e){super(e)}nextMatch(e,t,n){let i=S(this.spec,e,n,e.doc.length).nextOverlapping();if(i.done){let s=Math.min(e.doc.length,t+this.spec.unquoted.length);i=S(this.spec,e,0,s).nextOverlapping()}return i.done||i.value.from==t&&i.value.to==n?null:i.value}prevMatchInRange(e,t,n){for(let i=n;;){let s=Math.max(t,i-1e4-this.spec.unquoted.length),l=S(this.spec,e,s,i),o=null;for(;!l.nextOverlapping().done;)o=l.value;if(o)return o;if(s==t)return null;i-=1e4}}prevMatch(e,t,n){let i=this.prevMatchInRange(e,0,t);return i||(i=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length)),i&&(i.from!=t||i.to!=n)?i:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=S(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let s=S(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}function Ce(r,e,t){return(n,i,s)=>(!t||t(n,i,s))&&r(s[0],e,n,i)}function y(r,e,t,n){let i;return r.wholeWord&&(i=Me(e.charCategorizer(e.selection.main.head))),r.test&&(i=Ce(r.test,e,i)),new $(e.doc,r.search,{ignoreCase:!r.caseSensitive,test:i},t,n)}function F(r,e){return r.slice(a.findClusterBreak(r,e,!1),e)}function q(r,e){return r.slice(e,a.findClusterBreak(r,e))}function Me(r){return(e,t,n)=>!n[0].length||(r(F(n.input,n.index))!=a.CharCategory.Word||r(q(n.input,n.index))!=a.CharCategory.Word)&&(r(q(n.input,n.index+n[0].length))!=a.CharCategory.Word||r(F(n.input,n.index+n[0].length))!=a.CharCategory.Word)}class ve extends ee{nextMatch(e,t,n){let i=y(this.spec,e,n,e.doc.length).next();return i.done&&(i=y(this.spec,e,0,t).next()),i.done?null:i.value}prevMatchInRange(e,t,n){for(let i=1;;i++){let s=Math.max(t,n-i*1e4),l=y(this.spec,e,s,n),o=null;for(;!l.next().done;)o=l.value;if(o&&(s==t||o.from>s+10))return o;if(s==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n=="&")return e.match[0];if(n=="$")return"$";for(let i=n.length;i>0;i--){let s=+n.slice(0,i);if(s>0&&s<e.match.length)return e.match[s]+n.slice(i)}return t})}matchAll(e,t){let n=y(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let s=y(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}const M=a.StateEffect.define(),N=a.StateEffect.define(),p=a.StateField.define({create(r){return new I(O(r).create(),null)},update(r,e){for(let t of e.effects)t.is(M)?r=new I(t.value.create(),r.panel):t.is(N)&&(r=new I(r.query,t.value?B:null));return r},provide:r=>h.showPanel.from(r,e=>e.panel)});class I{constructor(e,t){this.query=e,this.panel=t}}const Ee=h.Decoration.mark({class:"cm-searchMatch"}),be=h.Decoration.mark({class:"cm-searchMatch cm-searchMatch-selected"}),ke=h.ViewPlugin.fromClass(class{constructor(r){this.view=r,this.decorations=this.highlight(r.state.field(p))}update(r){let e=r.state.field(p);(e!=r.startState.field(p)||r.docChanged||r.selectionSet||r.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:r,panel:e}){if(!e||!r.spec.valid)return h.Decoration.none;let{view:t}=this,n=new a.RangeSetBuilder;for(let i=0,s=t.visibleRanges,l=s.length;i<l;i++){let{from:o,to:c}=s[i];for(;i<l-1&&c>s[i+1].from-500;)c=s[++i].to;r.highlight(t.state,o,c,(u,f)=>{let g=t.state.selection.ranges.some(D=>D.from==u&&D.to==f);n.add(u,f,g?be:Ee)})}return n.finish()}},{decorations:r=>r.decorations});function L(r){return e=>{let t=e.state.field(p,!1);return t&&t.query.spec.valid?r(e,t):_(e)}}const b=L((r,{query:e})=>{let{to:t}=r.state.selection.main,n=e.nextMatch(r.state,t,t);if(!n)return!1;let i=a.EditorSelection.single(n.from,n.to),s=r.state.facet(v);return r.dispatch({selection:i,effects:[H(r,n),s.scrollToMatch(i.main,r)],userEvent:"select.search"}),se(r),!0}),k=L((r,{query:e})=>{let{state:t}=r,{from:n}=t.selection.main,i=e.prevMatch(t,n,n);if(!i)return!1;let s=a.EditorSelection.single(i.from,i.to),l=r.state.facet(v);return r.dispatch({selection:s,effects:[H(r,i),l.scrollToMatch(s.main,r)],userEvent:"select.search"}),se(r),!0}),te=L((r,{query:e})=>{let t=e.matchAll(r.state,1e3);return!t||!t.length?!1:(r.dispatch({selection:a.EditorSelection.create(t.map(n=>a.EditorSelection.range(n.from,n.to))),userEvent:"select.search.matches"}),!0)}),re=({state:r,dispatch:e})=>{let t=r.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:n,to:i}=t.main,s=[],l=0;for(let o=new x(r.doc,r.sliceDoc(n,i));!o.next().done;){if(s.length>1e3)return!1;o.value.from==n&&(l=s.length),s.push(a.EditorSelection.range(o.value.from,o.value.to))}return e(r.update({selection:a.EditorSelection.create(s,l),userEvent:"select.search.matches"})),!0},T=L((r,{query:e})=>{let{state:t}=r,{from:n,to:i}=t.selection.main;if(t.readOnly)return!1;let s=e.nextMatch(t,n,n);if(!s)return!1;let l=s,o=[],c,u,f=[];l.from==n&&l.to==i&&(u=t.toText(e.getReplacement(l)),o.push({from:l.from,to:l.to,insert:u}),l=e.nextMatch(t,l.from,l.to),f.push(h.EditorView.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(n).number)+".")));let g=r.state.changes(o);return l&&(c=a.EditorSelection.single(l.from,l.to).map(g),f.push(H(r,l)),f.push(t.facet(v).scrollToMatch(c.main,r))),r.dispatch({changes:g,selection:c,effects:f,userEvent:"input.replace"}),!0}),ne=L((r,{query:e})=>{if(r.state.readOnly)return!1;let t=e.matchAll(r.state,1e9).map(i=>{let{from:s,to:l}=i;return{from:s,to:l,insert:e.getReplacement(i)}});if(!t.length)return!1;let n=r.state.phrase("replaced $ matches",t.length)+".";return r.dispatch({changes:t,effects:h.EditorView.announce.of(n),userEvent:"input.replace.all"}),!0});function B(r){return r.state.facet(v).createPanel(r)}function O(r,e){var t,n,i,s,l;let o=r.selection.main,c=o.empty||o.to>o.from+100?"":r.sliceDoc(o.from,o.to);if(e&&!c)return e;let u=r.facet(v);return new Q({search:((t=e?.literal)!==null&&t!==void 0?t:u.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(n=e?.caseSensitive)!==null&&n!==void 0?n:u.caseSensitive,literal:(i=e?.literal)!==null&&i!==void 0?i:u.literal,regexp:(s=e?.regexp)!==null&&s!==void 0?s:u.regexp,wholeWord:(l=e?.wholeWord)!==null&&l!==void 0?l:u.wholeWord})}function ie(r){let e=h.getPanel(r,B);return e&&e.dom.querySelector("[main-field]")}function se(r){let e=ie(r);e&&e==r.root.activeElement&&e.select()}const _=r=>{let e=r.state.field(p,!1);if(e&&e.panel){let t=ie(r);if(t&&t!=r.root.activeElement){let n=O(r.state,e.query.spec);n.valid&&r.dispatch({effects:M.of(n)}),t.focus(),t.select()}}else r.dispatch({effects:[N.of(!0),e?M.of(O(r.state,e.query.spec)):a.StateEffect.appendConfig.of(we)]});return!0},z=r=>{let e=r.state.field(p,!1);if(!e||!e.panel)return!1;let t=h.getPanel(r,B);return t&&t.dom.contains(r.root.activeElement)&&r.focus(),r.dispatch({effects:N.of(!1)}),!0},Le=[{key:"Mod-f",run:_,scope:"editor search-panel"},{key:"F3",run:b,shift:k,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:b,shift:k,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:z,scope:"editor search-panel"},{key:"Mod-Shift-l",run:re},{key:"Mod-Alt-g",run:Y},{key:"Mod-d",run:Z,preventDefault:!0}];class De{constructor(e){this.view=e;let t=this.query=e.state.field(p).query.spec;this.commit=this.commit.bind(this),this.searchField=m.default("input",{value:t.search,placeholder:d(e,"Find"),"aria-label":d(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=m.default("input",{value:t.replace,placeholder:d(e,"Replace"),"aria-label":d(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=m.default("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=m.default("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=m.default("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function n(i,s,l){return m.default("button",{class:"cm-button",name:i,onclick:s,type:"button"},l)}this.dom=m.default("div",{onkeydown:i=>this.keydown(i),class:"cm-search"},[this.searchField,n("next",()=>b(e),[d(e,"next")]),n("prev",()=>k(e),[d(e,"previous")]),n("select",()=>te(e),[d(e,"all")]),m.default("label",null,[this.caseField,d(e,"match case")]),m.default("label",null,[this.reField,d(e,"regexp")]),m.default("label",null,[this.wordField,d(e,"by word")]),...e.state.readOnly?[]:[m.default("br"),this.replaceField,n("replace",()=>T(e),[d(e,"replace")]),n("replaceAll",()=>ne(e),[d(e,"replace all")])],m.default("button",{name:"close",onclick:()=>z(e),"aria-label":d(e,"close"),type:"button"},["×"])])}commit(){let e=new Q({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:M.of(e)}))}keydown(e){h.runScopeHandlers(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?k:b)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),T(this.view))}update(e){for(let t of e.transactions)for(let n of t.effects)n.is(M)&&!n.value.eq(this.query)&&this.setQuery(n.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(v).top}}function d(r,e){return r.state.phrase(e)}const W=30,w=/[\s\.,:;?!]/;function H(r,{from:e,to:t}){let n=r.state.doc.lineAt(e),i=r.state.doc.lineAt(t).to,s=Math.max(n.from,e-W),l=Math.min(i,t+W),o=r.state.sliceDoc(s,l);if(s!=n.from){for(let c=0;c<W;c++)if(!w.test(o[c+1])&&w.test(o[c])){o=o.slice(c);break}}if(l!=i){for(let c=o.length-1;c>o.length-W;c--)if(!w.test(o[c-1])&&w.test(o[c])){o=o.slice(0,c);break}}return h.EditorView.announce.of(`${r.state.phrase("current match")}. ${o} ${r.state.phrase("on line")} ${n.number}.`)}const We=h.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"}}),we=[p,a.Prec.low(ke),We];exports.RegExpCursor=$;exports.SearchCursor=x;exports.SearchQuery=Q;exports.closeSearchPanel=z;exports.findNext=b;exports.findPrevious=k;exports.gotoLine=Y;exports.highlightSelectionMatches=ae;exports.openSearchPanel=_;exports.replaceAll=ne;exports.replaceNext=T;exports.searchKeymap=Le;exports.selectMatches=te;exports.selectNextOccurrence=Z;exports.selectSelectionMatches=re;exports.setSearchQuery=M;