@gsc-basic/components 1.0.1 → 1.0.3

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 (164) hide show
  1. package/README.md +59 -0
  2. package/dist/es/index.js +48 -30
  3. package/dist/es/node_modules/@codemirror/autocomplete/dist/index.js +15 -15
  4. package/dist/es/node_modules/@codemirror/commands/dist/index.js +31 -25
  5. package/dist/es/node_modules/@codemirror/lang-java/dist/index.js +3 -3
  6. package/dist/es/node_modules/@codemirror/lang-javascript/dist/index.js +8 -8
  7. package/dist/es/node_modules/@codemirror/lang-json/dist/index.js +1 -1
  8. package/dist/es/node_modules/@codemirror/lang-python/dist/index.js +1 -1
  9. package/dist/es/node_modules/@codemirror/lang-sql/dist/index.js +6 -6
  10. package/dist/es/node_modules/@codemirror/lang-xml/dist/index.js +3 -3
  11. package/dist/es/node_modules/@codemirror/lang-yaml/dist/index.js +1 -1
  12. package/dist/es/node_modules/@codemirror/language/dist/index.js +77 -77
  13. package/dist/es/node_modules/@codemirror/lint/dist/index.js +7 -7
  14. package/dist/es/node_modules/@codemirror/search/dist/index.js +432 -465
  15. package/dist/es/node_modules/@codemirror/state/dist/index.js +272 -268
  16. package/dist/es/node_modules/@codemirror/view/dist/index.js +1732 -1647
  17. package/dist/es/node_modules/@lezer/common/dist/index.js +191 -190
  18. package/dist/es/node_modules/@lezer/lr/dist/index.js +5 -3
  19. package/dist/es/node_modules/@tanstack/devtools-event-client/dist/esm/plugin.js +178 -0
  20. package/dist/es/node_modules/@tanstack/form-core/dist/esm/EventClient.js +13 -0
  21. package/dist/es/node_modules/@tanstack/form-core/dist/esm/FieldApi.js +406 -0
  22. package/dist/es/node_modules/@tanstack/form-core/dist/esm/FormApi.js +772 -0
  23. package/dist/es/node_modules/@tanstack/form-core/dist/esm/ValidationLogic.js +55 -0
  24. package/dist/es/node_modules/@tanstack/form-core/dist/esm/metaHelper.js +109 -0
  25. package/dist/es/node_modules/@tanstack/form-core/dist/esm/standardSchemaValidator.js +45 -0
  26. package/dist/es/node_modules/@tanstack/form-core/dist/esm/utils.js +213 -0
  27. package/dist/es/node_modules/@tanstack/pacer-lite/dist/lite-throttler.js +29 -0
  28. package/dist/es/node_modules/@tanstack/store/dist/esm/derived.js +74 -0
  29. package/dist/es/node_modules/@tanstack/store/dist/esm/scheduler.js +79 -0
  30. package/dist/es/node_modules/@tanstack/store/dist/esm/store.js +21 -0
  31. package/dist/es/node_modules/@tanstack/store/dist/esm/types.js +6 -0
  32. package/dist/es/node_modules/@tanstack/table-core/build/lib/index.js +1885 -0
  33. package/dist/es/node_modules/@tanstack/vue-form/dist/esm/useField.js +38 -0
  34. package/dist/es/node_modules/@tanstack/vue-form/dist/esm/useForm.js +33 -0
  35. package/dist/es/node_modules/@tanstack/vue-store/dist/esm/index.js +48 -0
  36. package/dist/es/node_modules/@tanstack/vue-table/build/lib/index.js +159 -0
  37. package/dist/es/node_modules/@vueuse/core/dist/index.js +1 -1
  38. package/dist/es/node_modules/codemirror/dist/index.js +3 -3
  39. package/dist/es/src/Button/index.js +6 -0
  40. package/dist/es/src/Button/src/Button.css +1 -0
  41. package/dist/es/src/Button/src/Button.vue.js +41 -0
  42. package/dist/es/src/Button/src/Button2.css +1 -0
  43. package/dist/es/src/CodeEditor/src/index.css +1 -1
  44. package/dist/es/src/CodeEditor/src/index.vue.js +54 -51
  45. package/dist/es/src/CodeEditor/src/index2.css +1 -1
  46. package/dist/es/src/ConfigProvider/index.js +1 -2
  47. package/dist/es/src/ConfigProvider/src/useGlobalConfig.js +9 -9
  48. package/dist/es/src/Form/index.js +6 -0
  49. package/dist/es/src/Form/src/Form.css +1 -0
  50. package/dist/es/src/Form/src/Form.vue.js +208 -0
  51. package/dist/es/src/Form/src/styles/form.css +1 -0
  52. package/dist/es/src/Grid/index.js +6 -0
  53. package/dist/es/src/Grid/src/Grid.css +1 -0
  54. package/dist/es/src/Grid/src/Grid.vue.js +180 -0
  55. package/dist/es/src/Grid/src/components/ActionBar.css +1 -0
  56. package/dist/es/src/Grid/src/components/ActionBar.vue.js +65 -0
  57. package/dist/es/src/Grid/src/components/CellEditor.css +1 -0
  58. package/dist/es/src/Grid/src/components/CellEditor.vue.js +132 -0
  59. package/dist/es/src/Grid/src/components/CellEditor2.css +1 -0
  60. package/dist/es/src/Grid/src/components/ColumnFilter.css +1 -0
  61. package/dist/es/src/Grid/src/components/ColumnFilter.vue.js +72 -0
  62. package/dist/es/src/Grid/src/components/ColumnSettings.css +1 -0
  63. package/dist/es/src/Grid/src/components/ColumnSettings.vue.js +109 -0
  64. package/dist/es/src/Grid/src/components/DataTable.css +1 -0
  65. package/dist/es/src/Grid/src/components/DataTable.vue.js +556 -0
  66. package/dist/es/src/Grid/src/components/Pager.css +1 -0
  67. package/dist/es/src/Grid/src/components/Pager.vue.js +64 -0
  68. package/dist/es/src/Grid/src/components/QueryBar.css +1 -0
  69. package/dist/es/src/Grid/src/components/QueryBar.vue.js +156 -0
  70. package/dist/es/src/Grid/src/composables/useCellEditor.js +20 -0
  71. package/dist/es/src/Grid/src/composables/useGridTable.js +213 -0
  72. package/dist/es/src/Grid/src/styles/table.css +1 -0
  73. package/dist/es/src/Overlay/index.js +61 -0
  74. package/dist/es/src/Overlay/src/Message.css +1 -0
  75. package/dist/es/src/Overlay/src/Message.vue.js +36 -0
  76. package/dist/es/src/Overlay/src/Message2.css +1 -0
  77. package/dist/es/src/Overlay/src/Modal.css +1 -0
  78. package/dist/es/src/Overlay/src/Modal.vue.js +67 -0
  79. package/dist/es/src/Overlay/src/Modal2.css +1 -0
  80. package/dist/es/src/Overlay/src/Notice.css +1 -0
  81. package/dist/es/src/Overlay/src/Notice.vue.js +37 -0
  82. package/dist/es/src/Overlay/src/Notice2.css +1 -0
  83. package/dist/es/src/ScaleScreen/src/index.vue.js +2 -2
  84. package/dist/es/src/VideoBackground/src/index.vue.js +8 -8
  85. package/dist/es/src/index.js +35 -19
  86. package/dist/es/src/locale/lang/en-US.js +40 -0
  87. package/dist/es/src/locale/lang/ja-JP.js +42 -2
  88. package/dist/es/src/locale/lang/zh-CN.js +42 -2
  89. package/dist/es/src/styles/tokens.css +1 -1
  90. package/dist/lib/index.js +1 -1
  91. package/dist/lib/node_modules/@codemirror/commands/dist/index.js +1 -1
  92. package/dist/lib/node_modules/@codemirror/language/dist/index.js +1 -1
  93. package/dist/lib/node_modules/@codemirror/search/dist/index.js +2 -2
  94. package/dist/lib/node_modules/@codemirror/state/dist/index.js +4 -4
  95. package/dist/lib/node_modules/@codemirror/view/dist/index.js +5 -5
  96. package/dist/lib/node_modules/@lezer/common/dist/index.js +1 -1
  97. package/dist/lib/node_modules/@lezer/lr/dist/index.js +1 -1
  98. package/dist/lib/node_modules/@tanstack/devtools-event-client/dist/esm/plugin.js +1 -0
  99. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/EventClient.js +1 -0
  100. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/FieldApi.js +1 -0
  101. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/FormApi.js +1 -0
  102. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/ValidationLogic.js +1 -0
  103. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/metaHelper.js +1 -0
  104. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/standardSchemaValidator.js +1 -0
  105. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/utils.js +1 -0
  106. package/dist/lib/node_modules/@tanstack/pacer-lite/dist/lite-throttler.js +1 -0
  107. package/dist/lib/node_modules/@tanstack/store/dist/esm/derived.js +1 -0
  108. package/dist/lib/node_modules/@tanstack/store/dist/esm/scheduler.js +1 -0
  109. package/dist/lib/node_modules/@tanstack/store/dist/esm/store.js +1 -0
  110. package/dist/lib/node_modules/@tanstack/store/dist/esm/types.js +1 -0
  111. package/dist/lib/node_modules/@tanstack/table-core/build/lib/index.js +4 -0
  112. package/dist/lib/node_modules/@tanstack/vue-form/dist/esm/useField.js +1 -0
  113. package/dist/lib/node_modules/@tanstack/vue-form/dist/esm/useForm.js +1 -0
  114. package/dist/lib/node_modules/@tanstack/vue-store/dist/esm/index.js +1 -0
  115. package/dist/lib/node_modules/@tanstack/vue-table/build/lib/index.js +1 -0
  116. package/dist/lib/src/Button/index.js +1 -0
  117. package/dist/lib/src/Button/src/Button.css +1 -0
  118. package/dist/lib/src/Button/src/Button.vue.js +1 -0
  119. package/dist/lib/src/Button/src/Button2.css +1 -0
  120. package/dist/lib/src/CodeEditor/src/index.css +1 -1
  121. package/dist/lib/src/CodeEditor/src/index.vue.js +1 -1
  122. package/dist/lib/src/CodeEditor/src/index2.css +1 -1
  123. package/dist/lib/src/ConfigProvider/index.js +1 -1
  124. package/dist/lib/src/Form/index.js +1 -0
  125. package/dist/lib/src/Form/src/Form.css +1 -0
  126. package/dist/lib/src/Form/src/Form.vue.js +1 -0
  127. package/dist/lib/src/Form/src/styles/form.css +1 -0
  128. package/dist/lib/src/Grid/index.js +1 -0
  129. package/dist/lib/src/Grid/src/Grid.css +1 -0
  130. package/dist/lib/src/Grid/src/Grid.vue.js +1 -0
  131. package/dist/lib/src/Grid/src/components/ActionBar.css +1 -0
  132. package/dist/lib/src/Grid/src/components/ActionBar.vue.js +1 -0
  133. package/dist/lib/src/Grid/src/components/CellEditor.css +1 -0
  134. package/dist/lib/src/Grid/src/components/CellEditor.vue.js +1 -0
  135. package/dist/lib/src/Grid/src/components/CellEditor2.css +1 -0
  136. package/dist/lib/src/Grid/src/components/ColumnFilter.css +1 -0
  137. package/dist/lib/src/Grid/src/components/ColumnFilter.vue.js +1 -0
  138. package/dist/lib/src/Grid/src/components/ColumnSettings.css +1 -0
  139. package/dist/lib/src/Grid/src/components/ColumnSettings.vue.js +1 -0
  140. package/dist/lib/src/Grid/src/components/DataTable.css +1 -0
  141. package/dist/lib/src/Grid/src/components/DataTable.vue.js +1 -0
  142. package/dist/lib/src/Grid/src/components/Pager.css +1 -0
  143. package/dist/lib/src/Grid/src/components/Pager.vue.js +1 -0
  144. package/dist/lib/src/Grid/src/components/QueryBar.css +1 -0
  145. package/dist/lib/src/Grid/src/components/QueryBar.vue.js +1 -0
  146. package/dist/lib/src/Grid/src/composables/useCellEditor.js +1 -0
  147. package/dist/lib/src/Grid/src/composables/useGridTable.js +1 -0
  148. package/dist/lib/src/Grid/src/styles/table.css +1 -0
  149. package/dist/lib/src/Overlay/index.js +1 -0
  150. package/dist/lib/src/Overlay/src/Message.css +1 -0
  151. package/dist/lib/src/Overlay/src/Message.vue.js +1 -0
  152. package/dist/lib/src/Overlay/src/Message2.css +1 -0
  153. package/dist/lib/src/Overlay/src/Modal.css +1 -0
  154. package/dist/lib/src/Overlay/src/Modal.vue.js +1 -0
  155. package/dist/lib/src/Overlay/src/Modal2.css +1 -0
  156. package/dist/lib/src/Overlay/src/Notice.css +1 -0
  157. package/dist/lib/src/Overlay/src/Notice.vue.js +1 -0
  158. package/dist/lib/src/Overlay/src/Notice2.css +1 -0
  159. package/dist/lib/src/index.js +1 -1
  160. package/dist/lib/src/locale/lang/en-US.js +1 -1
  161. package/dist/lib/src/locale/lang/ja-JP.js +1 -1
  162. package/dist/lib/src/locale/lang/zh-CN.js +1 -1
  163. package/dist/lib/src/styles/tokens.css +1 -1
  164. package/package.json +11 -8
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../../state/dist/index.js"),mt=require("../../../style-mod/src/style-mod.js"),ye=require("../../../w3c-keyname/index.js");let P=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ee=typeof document<"u"?document:{documentElement:{style:{}}};const Re=/Edge\/(\d+)/.exec(P.userAgent),es=/MSIE \d/.test(P.userAgent),Le=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(P.userAgent),ue=!!(es||Le||Re),ui=!ue&&/gecko\/(\d+)/i.test(P.userAgent),we=!ue&&/Chrome\/(\d+)/.exec(P.userAgent),ln="webkitFontSmoothing"in Ee.documentElement.style,Pe=!ue&&/Apple Computer/.test(P.vendor),pi=Pe&&(/Mobile\/\w+/.test(P.userAgent)||P.maxTouchPoints>2);var w={mac:pi||/Mac/.test(P.platform),windows:/Win/.test(P.platform),linux:/Linux|X11/.test(P.platform),ie:ue,ie_version:es?Ee.documentMode||6:Le?+Le[1]:Re?+Re[1]:0,gecko:ui,gecko_version:ui?+(/Firefox\/(\d+)/.exec(P.userAgent)||[0,0])[1]:0,chrome:!!we,chrome_version:we?+we[1]:0,ios:pi,android:/Android\b/.test(P.userAgent),webkit_version:ln?+(/\bAppleWebKit\/(\d+)/.exec(P.userAgent)||[0,0])[1]:0,safari:Pe,safari_version:Pe?+(/\bVersion\/(\d+(\.\d+)?)/.exec(P.userAgent)||[0,0])[1]:0,tabSize:Ee.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Je(n,t){for(let e in n)e=="class"&&t.class?t.class+=" "+n.class:e=="style"&&t.style?t.style+=";"+n.style:t[e]=n[e];return t}const re=Object.create(null);function Ze(n,t,e){if(n==t)return!0;n||(n=re),t||(t=re);let i=Object.keys(n),s=Object.keys(t);if(i.length-0!=s.length-0)return!1;for(let o of i)if(o!=e&&(s.indexOf(o)==-1||n[o]!==t[o]))return!1;return!0}function an(n,t){for(let e=n.attributes.length-1;e>=0;e--){let i=n.attributes[e].name;t[i]==null&&n.removeAttribute(i)}for(let e in t){let i=t[e];e=="style"?n.style.cssText=i:n.getAttribute(e)!=i&&n.setAttribute(e,i)}}function gi(n,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?n.style.cssText=e[s]:n.setAttribute(s,e[s]));return i}function hn(n){let t=Object.create(null);for(let e=0;e<n.attributes.length;e++){let i=n.attributes[e];t[i.name]=i.value}return t}class st{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}exports.BlockType=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(exports.BlockType||(exports.BlockType={}));class O extends p.RangeValue{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new Ft(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new at(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:o,end:r}=is(t,e);i=(o?e?-3e8:-1:5e8)-1,s=(r?e?2e8:1:-6e8)+1}return new at(t,i,s,e,t.widget||null,!0)}static line(t){return new It(t)}static set(t,e=!1){return p.RangeSet.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}O.none=p.RangeSet.empty;class Ft extends O{constructor(t){let{start:e,end:i}=is(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?Je(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||re}eq(t){return this==t||t instanceof Ft&&this.tagName==t.tagName&&Ze(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}Ft.prototype.point=!1;class It extends O{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof It&&this.spec.class==t.spec.class&&Ze(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}It.prototype.mapMode=p.MapMode.TrackBefore;It.prototype.point=!0;class at extends O{constructor(t,e,i,s,o,r){super(e,i,o,t),this.block=s,this.isReplace=r,this.mapMode=s?e<=0?p.MapMode.TrackBefore:p.MapMode.TrackAfter:p.MapMode.TrackDel}get type(){return this.startSide!=this.endSide?exports.BlockType.WidgetRange:this.startSide<=0?exports.BlockType.WidgetBefore:exports.BlockType.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof at&&cn(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}at.prototype.point=!0;function is(n,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=n;return e==null&&(e=n.inclusive),i==null&&(i=n.inclusive),{start:e??t,end:i??t}}function cn(n,t){return n==t||!!(n&&t&&n.compare(t))}function ut(n,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=n?e[s]=Math.max(e[s],t):e.push(n,t)}class bt extends p.RangeValue{constructor(t,e){super(),this.tagName=t,this.attributes=e}eq(t){return t==this||t instanceof bt&&this.tagName==t.tagName&&Ze(this.attributes,t.attributes)}static create(t){return new bt(t.tagName,t.attributes||re)}static set(t,e=!1){return p.RangeSet.of(t,e)}}bt.prototype.startSide=bt.prototype.endSide=-1;function Lt(n){let t;return n.nodeType==11?t=n.getSelection?n:n.ownerDocument:t=n,t.getSelection()}function He(n,t){return t?n==t||n.contains(t.nodeType!=1?t.parentNode:t):!1}function ie(n,t){if(!t.anchorNode)return!1;try{return He(n,t.anchorNode)}catch{return!1}}function Dt(n){return n.nodeType==3?Ht(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Ot(n,t,e,i){return e?mi(n,t,e,i,-1)||mi(n,t,e,i,1):!1}function it(n){for(var t=0;;t++)if(n=n.previousSibling,!n)return t}function le(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function mi(n,t,e,i,s){for(;;){if(n==e&&t==i)return!0;if(t==(s<0?0:U(n))){if(n.nodeName=="DIV")return!1;let o=n.parentNode;if(!o||o.nodeType!=1)return!1;t=it(n)+(s<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[t+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;t=s<0?U(n):0}else return!1}}function U(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Pt(n,t){let e=t?n.left:n.right;return{left:e,right:e,top:n.top,bottom:n.bottom}}function fn(n){let t=n.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function ss(n,t){let e=t.width/n.offsetWidth,i=t.height/n.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-n.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-n.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function dn(n,t,e,i,s,o,r,l){let a=n.ownerDocument,h=a.defaultView||window;for(let c=n,f=!1;c&&!f;)if(c.nodeType==1){let d,u=c==a.body,g=1,m=1;if(u)d=fn(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(f=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let x=c.getBoundingClientRect();({scaleX:g,scaleY:m}=ss(c,x)),d={left:x.left,right:x.left+c.clientWidth*g,top:x.top,bottom:x.top+c.clientHeight*m}}let b=0,y=0;if(s=="nearest")t.top<d.top?(y=t.top-(d.top+r),e>0&&t.bottom>d.bottom+y&&(y=t.bottom-d.bottom+r)):t.bottom>d.bottom&&(y=t.bottom-d.bottom+r,e<0&&t.top-y<d.top&&(y=t.top-(d.top+r)));else{let x=t.bottom-t.top,C=d.bottom-d.top;y=(s=="center"&&x<=C?t.top+x/2-C/2:s=="start"||s=="center"&&e<0?t.top-r:t.bottom-C+r)-d.top}if(i=="nearest"?t.left<d.left?(b=t.left-(d.left+o),e>0&&t.right>d.right+b&&(b=t.right-d.right+o)):t.right>d.right&&(b=t.right-d.right+o,e<0&&t.left<d.left+b&&(b=t.left-(d.left+o))):b=(i=="center"?t.left+(t.right-t.left)/2-(d.right-d.left)/2:i=="start"==l?t.left-o:t.right-(d.right-d.left)+o)-d.left,b||y)if(u)h.scrollBy(b,y);else{let x=0,C=0;if(y){let k=c.scrollTop;c.scrollTop+=y/m,C=(c.scrollTop-k)*m}if(b){let k=c.scrollLeft;c.scrollLeft+=b/g,x=(c.scrollLeft-k)*g}t={left:t.left-x,top:t.top-C,right:t.right-x,bottom:t.bottom-C},x&&Math.abs(x-b)<1&&(i="nearest"),C&&Math.abs(C-y)<1&&(s="nearest")}if(u)break;(t.top<d.top||t.bottom>d.bottom||t.left<d.left||t.right>d.right)&&(t={left:Math.max(t.left,d.left),right:Math.min(t.right,d.right),top:Math.max(t.top,d.top),bottom:Math.min(t.bottom,d.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function un(n){let t=n.ownerDocument,e,i;for(let s=n.parentNode;s&&!(s==t.body||e&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:e,y:i}}class pn{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?U(e):0),i,Math.min(t.focusOffset,i?U(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let rt=null;w.safari&&w.safari_version>=26&&(rt=!1);function ns(n){if(n.setActive)return n.setActive();if(rt)return n.focus(rt);let t=[];for(let e=n;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(n.focus(rt==null?{get preventScroll(){return rt={preventScroll:!0},!0}}:void 0),!rt){rt=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],o=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=o&&(i.scrollLeft=o)}}}let bi;function Ht(n,t,e=t){let i=bi||(bi=document.createRange());return i.setEnd(n,e),i.setStart(n,t),i}function pt(n,t,e,i){let s={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let o=new KeyboardEvent("keydown",s);o.synthetic=!0,n.dispatchEvent(o);let r=new KeyboardEvent("keyup",s);return r.synthetic=!0,n.dispatchEvent(r),o.defaultPrevented||r.defaultPrevented}function gn(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function mn(n,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,U(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=U(e))}else{if(e==n)return!0;i=it(e),e=e.parentNode}}function os(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function rs(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=U(e)}else if(e.parentNode&&!le(e))i=it(e),e=e.parentNode;else return null}}function ls(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!le(e))i=it(e)+1,e=e.parentNode;else return null}}class z{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new z(t.parentNode,it(t),e)}static after(t,e){return new z(t.parentNode,it(t)+1,e)}}exports.Direction=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(exports.Direction||(exports.Direction={}));const ht=exports.Direction.LTR,ti=exports.Direction.RTL;function as(n){let t=[];for(let e=0;e<n.length;e++)t.push(1<<+n[e]);return t}const bn=as("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),yn=as("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),We=Object.create(null),_=[];for(let n of["()","[]","{}"]){let t=n.charCodeAt(0),e=n.charCodeAt(1);We[t]=e,We[e]=-t}function hs(n){return n<=247?bn[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?yn[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const wn=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class G{get dir(){return this.level%2?ti:ht}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let o=-1;for(let r=0;r<t.length;r++){let l=t[r];if(l.from<=e&&l.to>=e){if(l.level==i)return r;(o<0||(s!=0?s<0?l.from<e:l.to>e:t[o].level>l.level))&&(o=r)}}if(o<0)throw new RangeError("Index out of range");return o}}function cs(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++){let i=n[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!cs(i.inner,s.inner))return!1}return!0}const A=[];function xn(n,t,e,i,s){for(let o=0;o<=i.length;o++){let r=o?i[o-1].to:t,l=o<i.length?i[o].from:e,a=o?256:s;for(let h=r,c=a,f=a;h<l;h++){let d=hs(n.charCodeAt(h));d==512?d=c:d==8&&f==4&&(d=16),A[h]=d==4?2:d,d&7&&(f=d),c=d}for(let h=r,c=a,f=a;h<l;h++){let d=A[h];if(d==128)h<l-1&&c==A[h+1]&&c&24?d=A[h]=c:A[h]=256;else if(d==64){let u=h+1;for(;u<l&&A[u]==64;)u++;let g=h&&c==8||u<e&&A[u]==8?f==1?1:8:256;for(let m=h;m<u;m++)A[m]=g;h=u-1}else d==8&&f==1&&(A[h]=1);c=d,d&7&&(f=d)}}}function Sn(n,t,e,i,s){let o=s==1?2:1;for(let r=0,l=0,a=0;r<=i.length;r++){let h=r?i[r-1].to:t,c=r<i.length?i[r].from:e;for(let f=h,d,u,g;f<c;f++)if(u=We[d=n.charCodeAt(f)])if(u<0){for(let m=l-3;m>=0;m-=3)if(_[m+1]==-u){let b=_[m+2],y=b&2?s:b&4?b&1?o:s:0;y&&(A[f]=A[_[m]]=y),l=m;break}}else{if(_.length==189)break;_[l++]=f,_[l++]=d,_[l++]=a}else if((g=A[f])==2||g==1){let m=g==s;a=m?0:1;for(let b=l-3;b>=0;b-=3){let y=_[b+2];if(y&2)break;if(m)_[b+2]|=2;else{if(y&4)break;_[b+2]|=4}}}}}function vn(n,t,e,i){for(let s=0,o=i;s<=e.length;s++){let r=s?e[s-1].to:n,l=s<e.length?e[s].from:t;for(let a=r;a<l;){let h=A[a];if(h==256){let c=a+1;for(;;)if(c==l){if(s==e.length)break;c=e[s++].to,l=s<e.length?e[s].from:t}else if(A[c]==256)c++;else break;let f=o==1,d=(c<t?A[c]:i)==1,u=f==d?f?1:2:i;for(let g=c,m=s,b=m?e[m-1].to:n;g>a;)g==b&&(g=e[--m].from,b=m?e[m-1].to:n),A[--g]=u;a=c}else o=h,a++}}}function Ne(n,t,e,i,s,o,r){let l=i%2?2:1;if(i%2==s%2)for(let a=t,h=0;a<e;){let c=!0,f=!1;if(h==o.length||a<o[h].from){let m=A[a];m!=l&&(c=!1,f=m==16)}let d=!c&&l==1?[]:null,u=c?i:i+1,g=a;t:for(;;)if(h<o.length&&g==o[h].from){if(f)break t;let m=o[h];if(!c)for(let b=m.to,y=h+1;;){if(b==e)break t;if(y<o.length&&o[y].from==b)b=o[y++].to;else{if(A[b]==l)break t;break}}if(h++,d)d.push(m);else{m.from>a&&r.push(new G(a,m.from,u));let b=m.direction==ht!=!(u%2);Ve(n,b?i+1:i,s,m.inner,m.from,m.to,r),a=m.to}g=m.to}else{if(g==e||(c?A[g]!=l:A[g]==l))break;g++}d?Ne(n,a,g,i+1,s,d,r):a<g&&r.push(new G(a,g,u)),a=g}else for(let a=e,h=o.length;a>t;){let c=!0,f=!1;if(!h||a>o[h-1].to){let m=A[a-1];m!=l&&(c=!1,f=m==16)}let d=!c&&l==1?[]:null,u=c?i:i+1,g=a;t:for(;;)if(h&&g==o[h-1].to){if(f)break t;let m=o[--h];if(!c)for(let b=m.from,y=h;;){if(b==t)break t;if(y&&o[y-1].to==b)b=o[--y].from;else{if(A[b-1]==l)break t;break}}if(d)d.push(m);else{m.to<a&&r.push(new G(m.to,a,u));let b=m.direction==ht!=!(u%2);Ve(n,b?i+1:i,s,m.inner,m.from,m.to,r),a=m.from}g=m.from}else{if(g==t||(c?A[g-1]!=l:A[g-1]==l))break;g--}d?Ne(n,g,a,i+1,s,d,r):g<a&&r.push(new G(g,a,u)),a=g}}function Ve(n,t,e,i,s,o,r){let l=t%2?2:1;xn(n,s,o,i,l),Sn(n,s,o,i,l),vn(s,o,i,l),Ne(n,s,o,t,e,i,r)}function Cn(n,t,e){if(!n)return[new G(0,0,t==ti?1:0)];if(t==ht&&!e.length&&!wn.test(n))return fs(n.length);if(e.length)for(;n.length>A.length;)A[A.length]=256;let i=[],s=t==ht?0:1;return Ve(n,s,s,e,0,n.length,i),i}function fs(n){return[new G(0,n,0)]}let ds="";function Mn(n,t,e,i,s){var o;let r=i.head-n.from,l=G.find(t,r,(o=i.bidiLevel)!==null&&o!==void 0?o:-1,i.assoc),a=t[l],h=a.side(s,e);if(r==h){let d=l+=s?1:-1;if(d<0||d>=t.length)return null;a=t[l=d],r=a.side(!s,e),h=a.side(s,e)}let c=p.findClusterBreak(n.text,r,a.forward(s,e));(c<a.from||c>a.to)&&(c=h),ds=n.text.slice(Math.min(r,c),Math.max(r,c));let f=l==(s?t.length-1:0)?null:t[l+(s?1:-1)];return f&&c==h&&f.level+(s?0:1)<a.level?p.EditorSelection.cursor(f.side(!s,e)+n.from,f.forward(s,e)?1:-1,f.level):p.EditorSelection.cursor(c+n.from,a.forward(s,e)?-1:1,a.level)}function kn(n,t,e){for(let i=t;i<e;i++){let s=hs(n.charCodeAt(i));if(s==1)return ht;if(s==2||s==4)return ti}return ht}const us=p.Facet.define(),ps=p.Facet.define(),gs=p.Facet.define(),ms=p.Facet.define(),Fe=p.Facet.define(),bs=p.Facet.define(),ys=p.Facet.define(),ei=p.Facet.define(),ii=p.Facet.define(),ws=p.Facet.define({combine:n=>n.some(t=>t)}),xs=p.Facet.define({combine:n=>n.some(t=>t)}),Ss=p.Facet.define();class gt{constructor(t,e="nearest",i="nearest",s=5,o=5,r=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=o,this.isSnapshot=r}map(t){return t.empty?this:new gt(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new gt(p.EditorSelection.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const jt=p.StateEffect.define({map:(n,t)=>n.map(t)}),vs=p.StateEffect.define();function K(n,t,e){let i=n.facet(ms);i.length?i[0](t):window.onerror&&window.onerror(String(t),e,void 0,void 0,t)||(e?console.error(e+":",t):console.error(t))}const $=p.Facet.define({combine:n=>n.length?n[0]:!0});let An=0;const ft=p.Facet.define({combine(n){return n.filter((t,e)=>{for(let i=0;i<e;i++)if(n[i].plugin==t.plugin)return!1;return!0})}});class L{constructor(t,e,i,s,o){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=o(this),this.extension=this.baseExtensions.concat(ft.of({plugin:this,arg:void 0}))}of(t){return this.baseExtensions.concat(ft.of({plugin:this,arg:t}))}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:o,decorations:r}=e||{};return new L(An++,t,i,s,l=>{let a=[];return r&&a.push(Wt.of(h=>{let c=h.plugin(l);return c?r(c):O.none})),o&&a.push(o(l)),a})}static fromClass(t,e){return L.define((i,s)=>new t(i,s),e)}}class xe{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(K(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){K(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){K(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Cs=p.Facet.define(),si=p.Facet.define(),Wt=p.Facet.define(),Ms=p.Facet.define(),ks=p.Facet.define(),zt=p.Facet.define(),As=p.Facet.define();function yi(n,t){let e=n.state.facet(As);if(!e.length)return e;let i=e.map(o=>o instanceof Function?o(n):o),s=[];return p.RangeSet.spans(i,t.from,t.to,{point(){},span(o,r,l,a){let h=o-t.from,c=r-t.from,f=s;for(let d=l.length-1;d>=0;d--,a--){let u=l[d].spec.bidiIsolate,g;if(u==null&&(u=kn(t.text,h,c)),a>0&&f.length&&(g=f[f.length-1]).to==h&&g.direction==u)g.to=c,f=g.inner;else{let m={from:h,to:c,direction:u,inner:[]};f.push(m),f=m.inner}}}}),s}const Ts=p.Facet.define();function ni(n){let t=0,e=0,i=0,s=0;for(let o of n.state.facet(Ts)){let r=o(n);r&&(r.left!=null&&(t=Math.max(t,r.left)),r.right!=null&&(e=Math.max(e,r.right)),r.top!=null&&(i=Math.max(i,r.top)),r.bottom!=null&&(s=Math.max(s,r.bottom)))}return{left:t,right:e,top:i,bottom:s}}const Mt=p.Facet.define();class F{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new F(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,o=0,r=0;;){let l=s<t.length?t[s].fromB:1e9,a=o<e.length?e[o]:1e9,h=Math.min(l,a);if(h==1e9)break;let c=h+r,f=h,d=c;for(;;)if(o<e.length&&e[o]<=f){let u=e[o+1];o+=2,f=Math.max(f,u);for(let g=s;g<t.length&&t[g].fromB<=f;g++)r=t[g].toA-t[g].toB;d=Math.max(d,u+r)}else if(s<t.length&&t[s].fromB<=f){let u=t[s++];f=Math.max(f,u.toB),d=Math.max(d,u.toA),r=u.toA-u.toB}else break;i.push(new F(c,d,h,f))}return i}}class Nt{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=p.ChangeSet.empty(this.startState.doc.length);for(let o of i)this.changes=this.changes.compose(o.changes);let s=[];this.changes.iterChangedRanges((o,r,l,a)=>s.push(new F(o,r,l,a))),this.changedRanges=s}static create(t,e,i){return new Nt(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const Tn=[];class B{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return this.flags&1}get children(){return Tn}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&an(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let s of this.children){if(s==t)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e){return null}domPosFor(t,e){let i=it(this.dom),s=this.length?t>0:e>0;return new z(this.parent.dom,i+(s?1:0),t==0||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof ge)return t;return null}static get(t){return t.cmTile}}class pe extends B{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(this.flags&2)return;super.sync(t);let e=this.dom,i=null,s,o=t?.node==e?t:null,r=0;for(let l of this.children){if(l.sync(t),r+=l.length+l.breakAfter,s=i?i.nextSibling:e.firstChild,o&&s!=l.dom&&(o.written=!0),l.dom.parentNode==e)for(;s&&s!=l.dom;)s=wi(s);else e.insertBefore(l.dom,s);i=l.dom}for(s=i?i.nextSibling:e.firstChild,o&&s&&(o.written=!0);s;)s=wi(s);this.length=r}}function wi(n){let t=n.nextSibling;return n.parentNode.removeChild(n),t}class ge extends pe{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=B.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,s=0,o=0;;)if(s==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&o++,s=e.pop()}else{let r=i.children[s++];if(r instanceof et)e.push(s),i=r,s=0;else{let l=o+r.length,a=t(r,o);if(a!==void 0)return a;o=l+r.breakAfter}}}resolveBlock(t,e){let i,s=-1,o,r=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(t>=a&&t<=h){if(l.isWidget()&&e>=-1&&e<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(a<t||t==h&&(e<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,s=t-a),(h>t||t==a&&(e>1?l.length:l.covers(-1)))&&(!o||!l.isWidget()&&o.isWidget())&&(o=l,r=t-a)}}),!i&&!o)throw new Error("No tile at position "+t);return i&&e<0||!o?{tile:i,offset:s}:{tile:o,offset:r}}}class et extends pe{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return this.children.length?t<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new et(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class yt extends pe{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let s=new yt(e||document.createElement("div"),t);return(!e||!i)&&(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(t,e,i){let s=null,o=-1,r=null,l=-1;function a(c,f){for(let d=0,u=0;d<c.children.length&&u<=f;d++){let g=c.children[d],m=u+g.length;m>=f&&(g.isComposite()?a(g,f-u):(!r||r.isHidden&&(e>0||i&&On(r,g)))&&(m>f||g.flags&32)?(r=g,l=f-u):(u<f||g.flags&16&&!g.isHidden)&&(s=g,o=f-u)),u=m}}a(this,t);let h=(e<0?s:r)||s||r;return h?{tile:h,offset:h==s?o:l}:null}coordsIn(t,e){let i=this.resolveInline(t,e,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),e):Dn(this)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:s,offset:o}=i;if(this.dom.contains(s.dom))return s.isText()?new z(s.dom,Math.min(s.dom.nodeValue.length,o)):s.domPosFor(o,s.flags&16?1:s.flags&32?-1:e);let r=i.tile.parent,l=!1;for(let a of r.children){if(l)return new z(a.dom,0);a==i.tile&&(l=!0)}}return new z(this.dom,0)}}function Dn(n){let t=n.dom.lastChild;if(!t)return n.dom.getBoundingClientRect();let e=Dt(t);return e[e.length-1]||null}function On(n,t){let e=n.coordsIn(0,1),i=t.coordsIn(0,1);return e&&i&&i.top<e.bottom}class W extends pe{constructor(t,e){super(t),this.mark=e}get domAttrs(){return this.mark.attrs}static of(t,e){let i=new W(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class lt extends B{constructor(t,e){super(t,e.length),this.text=e}sync(t){this.flags&2||(super.sync(t),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(t,e){let i=this.dom.nodeValue.length;t>i&&(t=i);let s=t,o=t,r=0;t==0&&e<0||t==i&&e>=0?w.chrome||w.gecko||(t?(s--,r=1):o<i&&(o++,r=-1)):e<0?s--:o<i&&o++;let l=Ht(this.dom,s,o).getClientRects();if(!l.length)return null;let a=l[(r?r<0:e>=0)?0:l.length-1];return w.safari&&!r&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),r?Pt(a,r<0):a||null}static of(t,e){let i=new lt(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class wt extends B{constructor(t,e,i,s){super(t,e,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return this.flags&48?!1:(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let s=this.widget.coordsAt(this.dom,t,e);if(s)return s;if(i)return Pt(this.dom.getBoundingClientRect(),this.length?t==0:e<=0);{let o=this.dom.getClientRects(),r=null;if(!o.length)return null;let l=this.flags&16?!0:this.flags&32?!1:t>0;for(let a=l?o.length-1:0;r=o[a],!(t>0?a==0:a==o.length-1||r.top<r.bottom);a+=l?-1:1);return Pt(r,!l)}}get overrideDOMText(){if(!this.length)return p.Text.empty;let{root:t}=this;if(!t)return p.Text.empty;let e=this.posAtStart;return t.view.state.doc.slice(e,e+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,e,i,s,o){return o||(o=t.toDOM(e),t.editable||(o.contentEditable="false")),new wt(o,i,t,s)}}class ae extends B{constructor(t){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),super(e,0,t)}get isHidden(){return!1}get overrideDOMText(){return p.Text.empty}coordsIn(t){return this.dom.getBoundingClientRect()}}class Bn{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:s,index:o,beforeBreak:r,parents:l}=this;for(;t||e>0;)if(s.isComposite())if(r){if(!t)break;i&&i.break(),t--,r=!1}else if(o==s.children.length){if(!t&&!l.length)break;i&&i.leave(s),r=!!s.breakAfter,{tile:s,index:o}=l.pop(),o++}else{let a=s.children[o],h=a.breakAfter;(e>0?a.length<=t:a.length<t)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(r=!!h,o++,t-=a.length):(l.push({tile:s,index:o}),s=a,o=0,i&&a.isComposite()&&i.enter(a))}else if(o==s.length)r=!!s.breakAfter,{tile:s,index:o}=l.pop(),o++;else if(t){let a=Math.min(t,s.length-o);i&&i.skip(s,o,o+a),t-=a,o+=a}else break;return this.tile=s,this.index=o,this.beforeBreak=r,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class En{constructor(t,e,i,s){this.from=t,this.to=e,this.wrapper=i,this.rank=s}}class Rn{constructor(t,e,i){this.cache=t,this.root=e,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(t,e,i,s){var o;this.flushBuffer();let r=this.ensureMarks(e,i),l=r.lastChild;if(l&&l.isText()&&!(l.flags&8)){this.cache.reused.set(l,2);let a=r.children[r.children.length-1]=new lt(l.dom,l.text+t);a.parent=r}else r.append(s||lt.of(t,(o=this.cache.find(lt))===null||o===void 0?void 0:o.dom));this.pos+=t.length,this.afterWidget=null}addComposition(t,e){let i=this.curLine;i.dom!=e.line.dom&&(i.setDOM(this.cache.reused.has(e.line)?Se(e.line.dom):e.line.dom),this.cache.reused.set(e.line,2));let s=i;for(let r=e.marks.length-1;r>=0;r--){let l=e.marks[r],a=s.lastChild;if(a instanceof W&&a.mark.eq(l.mark))a.dom!=l.dom&&a.setDOM(Se(l.dom)),s=a;else{if(this.cache.reused.get(l)){let c=B.get(l.dom);c&&c.setDOM(Se(l.dom))}let h=W.of(l.mark,l.dom);s.append(h),s=h}this.cache.reused.set(l,2)}let o=new lt(t.text,t.text.nodeValue);o.flags|=8,s.append(o)}addInlineWidget(t,e,i){let s=this.afterWidget&&t.flags&48&&(this.afterWidget.flags&48)==(t.flags&48);s||this.flushBuffer();let o=this.ensureMarks(e,i);!s&&!(t.flags&16)&&o.append(this.getBuffer(1)),o.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){let e=this.afterWidget||this.lastBlock;e.length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=Ds);let s=yt.start(t,e||((i=this.cache.find(yt))===null||i===void 0?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let s=this.curLine;for(let o=t.length-1;o>=0;o--){let r=t[o],l;if(e>0&&(l=s.lastChild)&&l instanceof W&&l.mark.eq(r))s=l,e--;else{let a=W.of(r,(i=this.cache.find(W,h=>h.mark.eq(r)))===null||i===void 0?void 0:i.dom);s.append(a),s=a,e=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;(!t||!xi(this.curLine,!1)||t.dom.nodeName!="BR"&&t.isWidget()&&!(w.ios&&xi(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(ve,0,32)||new wt(ve.toDOM(),0,ve,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to<this.pos&&this.wrappers.splice(t,1);for(let t=this.blockWrappers;t.value&&t.from<=this.pos;t.next())if(t.to>=this.pos){let e=new En(t.from,t.to,t.value,t.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-e.rank||this.wrappers[i-1].to-e.to)<0;)i--;this.wrappers.splice(i,0,e)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let s=e.lastChild;if(i.from<this.pos&&s instanceof et&&s.wrapper.eq(i.wrapper))e=s;else{let o=et.of(i.wrapper,(t=this.cache.find(et,r=>r.wrapper.eq(i.wrapper)))===null||t===void 0?void 0:t.dom);e.append(o),e=o}}return e}blockPosCovered(){let t=this.lastBlock;return t!=null&&!t.breakAfter&&(!t.isWidget()||(t.flags&160)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(ae,void 0,1);return i&&(i.flags=e),i||new ae(e)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class Ln{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:s,lineBreak:o,done:r}=this.cursor.next(this.skipCount);if(this.skipCount=0,r)throw new Error("Ran out of text content when drawing inline views");this.text=s;let l=this.textOff=Math.min(t,s.length);return o?null:s.slice(0,l)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const he=[wt,yt,lt,W,ae,et,ge];for(let n=0;n<he.length;n++)he[n].bucket=n;class Pn{constructor(t){this.view=t,this.buckets=he.map(()=>[]),this.index=he.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let s=t.bucket,o=this.buckets[s],r=this.index[s];for(let l=o.length-1;l>=0;l--){let a=(l+r)%o.length,h=o[a];if((!e||e(h))&&!this.reused.has(h))return o.splice(a,1),a<r&&this.index[s]--,this.reused.set(h,i),h}return null}findWidget(t,e,i){let s=this.buckets[0];if(s.length)for(let o=0,r=0;;o++){if(o==s.length){if(r)return null;r=1,o=0}let l=s[o];if(!this.reused.has(l)&&(r==0?l.widget.compare(t):l.widget.constructor==t.constructor&&t.updateDOM(l.dom,this.view)))return s.splice(o,1),o<this.index[0]&&this.index[0]--,this.reused.set(l,1),l.length=e,l.flags=l.flags&-498|i,l}}reuse(t){return this.reused.set(t,1),t}maybeReuse(t,e=2){if(!this.reused.has(t))return this.reused.set(t,e),t.dom}}class Hn{constructor(t,e,i,s,o){this.view=t,this.decorations=s,this.disallowBlockEffectsFor=o,this.openWidget=!1,this.openMarks=0,this.cache=new Pn(t),this.text=new Ln(t.state.doc),this.builder=new Rn(this.cache,new ge(t,t.contentDOM),p.RangeSet.iter(i)),this.cache.reused.set(e,2),this.old=new Bn(e)}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let s=0,o=0,r=0;;){let l=r<t.length?t[r++]:null,a=l?l.fromA:this.old.root.length;if(a>s){let h=a-s;this.preserve(h,!r,!l),s=a,o+=h}if(!l)break;this.forward(l.fromA,l.toA),e&&l.fromA<=e.range.fromA&&l.toA>=e.range.toA?(this.emit(o,e.range.fromB),this.builder.addComposition(e,i),this.emit(e.range.toB,l.toB)):this.emit(o,l.toB),o=l.toB,s=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(t,e,i){let s=Vn(this.old),o=this.openMarks;this.old.advance(t,i?1:-1,{skip:(r,l,a)=>{if(r.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<r.length?wt.of(r.widget,this.view,a-l,r.flags&496,this.cache.maybeReuse(r)):this.cache.reuse(r);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,s,o),o=s.length)}else if(r.isText())this.builder.ensureLine(null),!l&&a==r.length?this.builder.addText(r.text,s,o,this.cache.reuse(r)):(this.cache.add(r),this.builder.addText(r.text.slice(l,a),s,o)),o=s.length;else if(r.isLine())r.flags&=-2,this.cache.reused.set(r,1),this.builder.addLine(r);else if(r instanceof ae)this.cache.add(r);else if(r instanceof W)this.builder.ensureLine(null),this.builder.addMark(r,s,o),this.cache.reused.set(r,1),o=s.length;else return!1;this.openWidget=!1},enter:r=>{r.isLine()?this.builder.addLineStart(r.attrs,this.cache.maybeReuse(r)):(this.cache.add(r),r instanceof W&&s.unshift(r.mark)),this.openWidget=!1},leave:r=>{r.isLine()?s.length&&(s.length=o=0):r instanceof W&&(s.shift(),o=Math.min(o,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,s=this.builder,o=0,r=p.RangeSet.spans(this.decorations,t,e,{point:(l,a,h,c,f,d)=>{if(h instanceof at){if(this.disallowBlockEffectsFor[d]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(o=c.length,f>c.length)s.continueWidget(a-l);else{let u=h.widget||(h.block?xt.block:xt.inline),g=Wn(h),m=this.cache.findWidget(u,a-l,g)||wt.of(u,this.view,a-l,g);h.block?(h.startSide>0&&s.addLineStartIfNotCovered(i),s.addBlockWidget(m)):(s.ensureLine(i),s.addInlineWidget(m,c,f))}i=null}else i=Nn(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;f<a;){let d=this.text.next(Math.min(512,a-f));d==null?(s.addLineStartIfNotCovered(i),s.addBreak(),f++):(s.ensureLine(i),s.addText(d,h,c),f+=d.length),i=null}}});s.addLineStartIfNotCovered(i),this.openWidget=r>o,this.openMarks=r}forward(t,e){this.old.advance(e-t,1,{skip:(i,s,o)=>{(i.isText()||o==i.length)&&this.cache.add(i)},enter:i=>this.cache.add(i),leave:()=>{},break:()=>{}})}getCompositionContext(t){let e=[],i=null;for(let s=t.parentNode;;s=s.parentNode){let o=B.get(s);if(s==this.view.contentDOM)break;o instanceof W?e.push(o):o?.isLine()?i=o:s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM?i=new yt(s,Ds):e.push(W.of(new Ft({tagName:s.nodeName.toLowerCase(),attributes:hn(s)}),s))}return{line:i,marks:e}}}function xi(n,t){let e=i=>{for(let s of i.children)if((t?s.isText():s.length)||e(s))return!0;return!1};return e(n)}function Wn(n){let t=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(t|=256),t}const Ds={class:"cm-line"};function Nn(n,t){let e=t.spec.attributes,i=t.spec.class;return!e&&!i||(n||(n={class:"cm-line"}),e&&Je(e,n),i&&(n.class+=" "+i)),n}function Vn(n){let t=[];for(let e=n.parents.length;e>1;e--){let i=e==n.parents.length?n.tile:n.parents[e].tile;i instanceof W&&t.push(i.mark)}return t}function Se(n){let t=B.get(n);return t&&t.setDOM(n.cloneNode()),n}class xt extends st{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}xt.inline=new xt("span");xt.block=new xt("div");const ve=new class extends st{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Si{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=O.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new ge(t,t.contentDOM),this.updateInner([new F(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:f})=>f<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?s=this.domChanged.newSel.head:!Yn(t.changes,this.hasComposition)&&!t.selectionSet&&(s=t.state.selection.main.head));let o=s>-1?In(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;i=new F(c,f,t.changes.mapPos(c,-1),t.changes.mapPos(f,1)).addToSet(i.slice())}this.hasComposition=o?{from:o.range.fromB,to:o.range.toB}:null,(w.ie||w.chrome)&&!o&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=this.decorations,l=this.blockWrappers;this.updateDeco();let a=qn(r,this.decorations,t.changes);a.length&&(i=F.extendWithRanges(i,a));let h=jn(l,this.blockWrappers,t.changes);return h.length&&(i=F.extendWithRanges(i,h)),o&&!i.some(c=>c.fromA<=o.range.fromA&&c.toA>=o.range.toA)&&(i=o.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,o),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let r=this.tile,l=new Hn(this.view,r,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=l.run(t,e),Ie(r,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=w.chrome||w.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(o),o&&(o.written||i.selectionRange.focusNode!=o.node||!this.tile.dom.contains(o.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.tile.children)o.isWidget()&&o.widget instanceof Ce&&s.push(o.dom);i.updateGaps(s)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(vs)&&(this.editContextFormatting=i.value)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,o=s==i,r=!o&&!(this.view.state.facet($)||i.tabIndex>-1)&&ie(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(o||e||r))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),w.gecko&&a.empty&&!this.hasComposition&&Fn(h)){let d=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(d,h.node.childNodes[h.offset]||null)),h=c=new z(d,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!Ot(h.node,h.offset,f.anchorNode,f.anchorOffset)||!Ot(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{w.android&&w.chrome&&i.contains(f.focusNode)&&Gn(f.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let d=Lt(this.view.root);if(d)if(a.empty){if(w.gecko){let u=zn(h.node,h.offset);if(u&&u!=3){let g=(u==1?rs:ls)(h.node,h.offset);g&&(h=new z(g.node,g.offset))}}d.collapse(h.node,h.offset),a.bidiLevel!=null&&d.caretBidiLevel!==void 0&&(d.caretBidiLevel=a.bidiLevel)}else if(d.extend){d.collapse(h.node,h.offset);try{d.extend(c.node,c.offset)}catch{}}else{let u=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),u.setEnd(c.node,c.offset),u.setStart(h.node,h.offset),d.removeAllRanges(),d.addRange(u)}r&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new z(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new z(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Ot(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=Lt(t.root),{anchorNode:s,anchorOffset:o}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let r=this.lineAt(e.head,e.assoc);if(!r)return;let l=r.posAtStart;if(e.head==l||e.head==l+r.length)return;let a=this.coordsAt(e.head,-1),h=this.coordsAt(e.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(c.node,c.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(s,o)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return this.tile.dom.compareDocumentPosition(t)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let o;if(t==i.dom)o=i.dom.childNodes[e];else{let r=U(t)==0?0:e==0?-1:1;for(;;){let l=t.parentNode;if(l==i.dom)break;r==0&&l.firstChild!=l.lastChild&&(t==l.firstChild?r=-1:r=1),t=l}r<0?o=t:o=t.nextSibling}if(o==i.dom.firstChild)return s;for(;o&&!B.get(o);)o=o.nextSibling;if(!o)return s+i.length;for(let r=0,l=s;;r++){let a=i.children[r];if(a.dom==o)return l;l+=a.length+a.breakAfter}}else return i.isText()?t==i.dom?s+e:s+(e?i.length:0):s}domAtPos(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(t,e):i.domIn(s,e)}inlineDOMNearPos(t,e){let i,s=-1,o=!1,r,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=t)return!0;h.flags&16&&(o=!0)}else{let f=c+h.length;if(c<=t&&(i=h,s=t-c,o=f<t),f>=t&&!r&&(r=h,l=t-c,a=c>t),c>t&&r)return!0}}),!i&&!r?this.domAtPos(t,e):(o&&r?i=null:a&&i&&(r=null),i&&e<0||!r?i.domIn(s,e):r.domIn(l,e))}coordsAt(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.widget instanceof Ce?null:i.coordsInWidget(s,e,!0):i.coordsIn(s,e)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;function s(o,r){if(o.isComposite())for(let l of o.children){if(l.length>=r){let a=s(l,r);if(a)return a}if(r-=l.length,r<0)break}else if(o.isText()&&r<o.length){let l=p.findClusterBreak(o.text,r);if(l==r)return null;let a=Ht(o.dom,r,l).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(h==a.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return s(e,i)}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,o=this.view.contentDOM.clientWidth,r=o>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==exports.Direction.LTR,h=0,c=(f,d,u)=>{for(let g=0;g<f.children.length&&!(d>s);g++){let m=f.children[g],b=d+m.length,y=m.dom.getBoundingClientRect(),{height:x}=y;if(u&&!g&&(h+=y.top-u.top),m instanceof et)b>i&&c(m,d,y);else if(d>=i&&(h>0&&e.push(-h),e.push(x+h),h=0,r)){let C=m.dom.lastChild,k=C?Dt(C):[];if(k.length){let v=k[k.length-1],S=a?v.right-y.left:y.right-v.left;S>l&&(l=S,this.minWidth=o,this.minWidthFrom=d,this.minWidthTo=b)}}u&&g==f.children.length-1&&(h+=u.bottom-y.bottom),d=b+m.breakAfter}};return c(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return getComputedStyle(e.dom).direction=="rtl"?exports.Direction.RTL:exports.Direction.LTR}measureTextSize(){let t=this.tile.blockTiles(r=>{if(r.isLine()&&r.children.length&&r.length<=20){let l=0,a;for(let h of r.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=Dt(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:r.dom.getBoundingClientRect().height,charWidth:l/r.length,textHeight:a}}});if(t)return t;let e=document.createElement("div"),i,s,o;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(e);let r=Dt(e.firstChild)[0];i=e.getBoundingClientRect().height,s=r&&r.width?r.width/27:7,o=r&&r.height?r.height:i,e.remove()}),{lineHeight:i,charWidth:s,textHeight:o}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let o=s==e.viewports.length?null:e.viewports[s],r=o?o.from-1:this.view.state.doc.length;if(r>i){let l=(e.lineBlockAt(r).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(O.replace({widget:new Ce(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!o)break;i=o.to+1}return O.set(t)}updateDeco(){let t=1,e=this.view.state.facet(Wt).map(o=>(this.dynamicDecorationMap[t++]=typeof o=="function")?o(this.view):o),i=!1,s=this.view.state.facet(ks).map((o,r)=>{let l=typeof o=="function";return l&&(i=!0),l?o(this.view):o});for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(p.RangeSet.join(s))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;this.blockWrappers=this.view.state.facet(Ms).map(o=>typeof o=="function"?o(this.view):o)}scrollIntoView(t){if(t.isSnapshot){let h=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=h.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let h of this.view.state.facet(Ss))try{if(h(this.view,t.range,t))return!0}catch(c){K(this.view.state,c,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let o=ni(this.view),r={left:i.left-o.left,top:i.top-o.top,right:i.right+o.right,bottom:i.bottom+o.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;dn(this.view.scrollDOM,r,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,a),-a),this.view.textDirection==exports.Direction.LTR)}lineHasWidget(t){let e=i=>i.isWidget()||i.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){Ie(this.tile)}}function Ie(n,t){let e=t?.get(n);if(e!=1){e==null&&n.destroy();for(let i of n.children)Ie(i,t)}}function Fn(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function Os(n,t){let e=n.observer.selectionRange;if(!e.focusNode)return null;let i=rs(e.focusNode,e.focusOffset),s=ls(e.focusNode,e.focusOffset),o=i||s;if(s&&i&&s.node!=i.node){let l=B.get(s.node);if(!l||l.isText()&&l.text!=s.node.nodeValue)o=s;else if(n.docView.lastCompositionAfterCursor){let a=B.get(i.node);!a||a.isText()&&a.text!=i.node.nodeValue||(o=s)}}if(n.docView.lastCompositionAfterCursor=o!=i,!o)return null;let r=t-o.offset;return{from:r,to:r+o.node.nodeValue.length,node:o.node}}function In(n,t,e){let i=Os(n,e);if(!i)return null;let{node:s,from:o,to:r}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=t.invertedDesc;return{range:new F(a.mapPos(o),a.mapPos(r),o,r),text:s}}function zn(n,t){return n.nodeType!=1?0:(t&&n.childNodes[t-1].contentEditable=="false"?1:0)|(t<n.childNodes.length&&n.childNodes[t].contentEditable=="false"?2:0)}let Kn=class{constructor(){this.changes=[]}compareRange(t,e){ut(t,e,this.changes)}comparePoint(t,e){ut(t,e,this.changes)}boundChange(t){ut(t,t,this.changes)}};function qn(n,t,e){let i=new Kn;return p.RangeSet.compare(n,t,e,i),i.changes}class _n{constructor(){this.changes=[]}compareRange(t,e){ut(t,e,this.changes)}comparePoint(){}boundChange(t){ut(t,t,this.changes)}}function jn(n,t,e){let i=new _n;return p.RangeSet.compare(n,t,e,i),i.changes}function Gn(n,t){for(let e=n;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Yn(n,t){let e=!1;return t&&n.iterChangedRanges((i,s)=>{i<t.to&&s>t.from&&(e=!0)}),e}class Ce extends st{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Xn(n,t,e=1){let i=n.charCategorizer(t),s=n.doc.lineAt(t),o=t-s.from;if(s.length==0)return p.EditorSelection.cursor(t);o==0?e=1:o==s.length&&(e=-1);let r=o,l=o;e<0?r=p.findClusterBreak(s.text,o,!1):l=p.findClusterBreak(s.text,o);let a=i(s.text.slice(r,l));for(;r>0;){let h=p.findClusterBreak(s.text,r,!1);if(i(s.text.slice(h,r))!=a)break;r=h}for(;l<s.length;){let h=p.findClusterBreak(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return p.EditorSelection.range(r+s.from,l+s.from)}function $n(n,t,e,i,s){let o=Math.round((i-t.left)*n.defaultCharacterWidth);if(n.lineWrapping&&e.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-e.top-(n.defaultLineHeight-l)*.5)/l);o+=a*n.viewState.heightOracle.lineLength}let r=n.state.sliceDoc(e.from,e.to);return e.from+p.findColumn(r,o,n.state.tabSize)}function ze(n,t,e){let i=n.lineBlockAt(t);if(Array.isArray(i.type)){let s;for(let o of i.type){if(o.from>t)break;if(!(o.to<t)){if(o.from<t&&o.to>t)return o;(!s||o.type==exports.BlockType.Text&&(s.type!=o.type||(e<0?o.from<t:o.to>t)))&&(s=o)}}return s||i}return i}function Un(n,t,e,i){let s=ze(n,t.head,t.assoc||-1),o=!i||s.type!=exports.BlockType.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(o){let r=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:e==(l==exports.Direction.LTR)?r.right-1:r.left+1,y:(o.top+o.bottom)/2});if(a!=null)return p.EditorSelection.cursor(a,e?-1:1)}return p.EditorSelection.cursor(e?s.to:s.from,e?-1:1)}function vi(n,t,e,i){let s=n.state.doc.lineAt(t.head),o=n.bidiSpans(s),r=n.textDirectionAt(s.from);for(let l=t,a=null;;){let h=Mn(s,o,r,l,e),c=ds;if(!h){if(s.number==(e?n.state.doc.lines:1))return l;c=`
2
- `,s=n.state.doc.line(s.number+(e?1:-1)),o=n.bidiSpans(s),h=n.visualLineSide(s,!e)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function Qn(n,t,e){let i=n.state.charCategorizer(t),s=i(e);return o=>{let r=i(o);return s==p.CharCategory.Space&&(s=r),s==r}}function Jn(n,t,e,i){let s=t.head,o=e?1:-1;if(s==(e?n.state.doc.length:0))return p.EditorSelection.cursor(s,t.assoc);let r=t.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s,t.assoc||-1),c=n.documentTop;if(h)r==null&&(r=h.left-a.left),l=o<0?h.top:h.bottom;else{let u=n.viewState.lineBlockAt(s);r==null&&(r=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-u.from))),l=(o<0?u.top:u.bottom)+c}let f=a.left+r,d=i??n.viewState.heightOracle.textHeight>>1;for(let u=0;;u+=10){let g=l+(d+u)*o,m=Ke(n,{x:f,y:g},!1,o);return p.EditorSelection.cursor(m.pos,m.assoc,void 0,r)}}function Bt(n,t,e){for(;;){let i=0;for(let s of n)s.between(t-1,t+1,(o,r,l)=>{if(t>o&&t<r){let a=i||e||(t-o<r-t?-1:1);t=a<0?o:r,i=a}});if(!i)return t}}function Bs(n,t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],o=null;if(s.empty){let r=Bt(n,s.from,0);r!=s.from&&(o=p.EditorSelection.cursor(r,-1))}else{let r=Bt(n,s.from,-1),l=Bt(n,s.to,1);(r!=s.from||l!=s.to)&&(o=p.EditorSelection.range(s.from==s.anchor?r:l,s.from==s.head?r:l))}o&&(e||(e=t.ranges.slice()),e[i]=o)}return e?p.EditorSelection.create(e,t.mainIndex):t}function Me(n,t,e){let i=Bt(n.state.facet(zt).map(s=>s(n)),e.from,t.head>e.from?-1:1);return i==e.from?e:p.EditorSelection.cursor(i,i<e.from?1:-1)}class j{constructor(t,e){this.pos=t,this.assoc=e}}function Ke(n,t,e,i){let s=n.contentDOM.getBoundingClientRect(),o=s.top+n.viewState.paddingTop,{x:r,y:l}=t,a=l-o,h;for(;;){if(a<0)return new j(0,1);if(a>n.viewState.docHeight)return new j(n.state.doc.length,-1);if(h=n.elementAtHeight(a),i==null)break;if(h.type==exports.BlockType.Text){let d=n.docView.coordsAt(i<0?h.from:h.to,i);if(d&&(i<0?d.top<=a+o:d.bottom>=a+o))break}let f=n.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+f:h.top-f}if(n.viewport.from>=h.to||n.viewport.to<=h.from){if(e)return null;if(h.type==exports.BlockType.Text){let f=$n(n,s,h,r,l);return new j(f,f==h.from?1:-1)}}if(h.type!=exports.BlockType.Text)return a<(h.top+h.bottom)/2?new j(h.from,1):new j(h.to,-1);let c=n.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=n.docView.lineAt(h.from,-2)),Es(n,c,h.from,r,l)}function Es(n,t,e,i,s){let o=-1,r=null,l=1e9,a=1e9,h=s,c=s,f=(d,u)=>{for(let g=0;g<d.length;g++){let m=d[g];if(m.top==m.bottom)continue;let b=m.left>i?m.left-i:m.right<i?i-m.right:0,y=m.top>s?m.top-s:m.bottom<s?s-m.bottom:0;m.top<=c&&m.bottom>=h&&(h=Math.min(m.top,h),c=Math.max(m.bottom,c),y=0),(o<0||(y-a||b-l)<0)&&(o>=0&&a&&l<b&&r.top<=c-2&&r.bottom>=h+2?a=0:(o=u,l=b,a=y,r=m))}};if(t.isText()){for(let u=0;u<t.length;){let g=p.findClusterBreak(t.text,u);if(f(Ht(t.dom,u,g).getClientRects(),u),!l&&!a)break;u=g}return i>(r.left+r.right)/2==(Ci(n,o+e)==exports.Direction.LTR)?new j(e+p.findClusterBreak(t.text,o),-1):new j(e+o,1)}else{if(!t.length)return new j(e,1);for(let m=0;m<t.children.length;m++){let b=t.children[m];if(b.flags&48)continue;let y=(b.dom.nodeType==1?b.dom:Ht(b.dom,0,b.length)).getClientRects();if(f(y,m),!l&&!a)break}let d=t.children[o],u=t.posBefore(d,e);return d.isComposite()||d.isText()?Es(n,d,u,Math.max(r.left,Math.min(r.right,i)),s):i>(r.left+r.right)/2==(Ci(n,o+e)==exports.Direction.LTR)?new j(u+d.length,-1):new j(u,1)}}function Ci(n,t){let e=n.state.doc.lineAt(t);return n.bidiSpans(e)[G.find(n.bidiSpans(e),t-e.from,-1,1)].dir}const kt="￿";class Zn{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(p.EditorState.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=kt}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let o=this.text.length;this.readNode(s);let r=B.get(s),l=s.nextSibling;if(l==e){r?.breakAfter&&!l&&this.lineBreak();break}let a=B.get(l);(r&&a?r.breakAfter:(r?r.breakAfter:le(s))||le(l)&&(s.nodeName!="BR"||r?.isWidget())&&this.text.length>o)&&!eo(l,e)&&this.lineBreak(),s=l}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let o=-1,r=1,l;if(this.lineSeparator?(o=e.indexOf(this.lineSeparator,i),r=this.lineSeparator.length):(l=s.exec(e))&&(o=l.index,r=l[0].length),this.append(e.slice(i,o<0?e.length:o)),o<0)break;if(this.lineBreak(),r>1)for(let a of this.points)a.node==t&&a.pos>this.text.length&&(a.pos-=r-1);i=o+r}}readNode(t){let e=B.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(to(t,i.node,i.offset)?e:0))}}function to(n,t,e){for(;;){if(!t||e<U(t))return!1;if(t==n)return!0;e=it(t)+1,t=t.parentNode}}function eo(n,t){let e;for(;!(n==t||!n);n=n.nextSibling){let i=B.get(n);if(!i?.isWidget())return!1;i&&(e||(e=[])).push(i)}if(e)for(let i of e){let s=i.overrideDOMText;if(s?.length)return!1}return!0}class Mi{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class io{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:o,impreciseAnchor:r}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=Rs(t.docView.tile,e,i,0))){let l=o||r?[]:no(t),a=new Zn(l,t.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=oo(l,this.bounds.from)}else{let l=t.observer.selectionRange,a=o&&o.node==l.focusNode&&o.offset==l.focusOffset||!He(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),h=r&&r.node==l.anchorNode&&r.offset==l.anchorOffset||!He(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),c=t.viewport;if((w.ios||w.chrome)&&t.state.selection.main.empty&&a!=h&&(c.from>0||c.to<t.state.doc.length)){let f=Math.min(a,h),d=Math.max(a,h),u=c.from-f,g=c.to-d;(u==0||u==1||f==0)&&(g==0||g==-1||d==t.state.doc.length)&&(a=0,h=t.state.doc.length)}t.inputState.composing>-1&&t.state.selection.ranges.length>1?this.newSel=t.state.selection.replaceRange(p.EditorSelection.range(h,a)):this.newSel=p.EditorSelection.single(h,a)}}}function Rs(n,t,e,i){if(n.isComposite()){let s=-1,o=-1,r=-1,l=-1;for(let a=0,h=i,c=i;a<n.children.length;a++){let f=n.children[a],d=h+f.length;if(h<t&&d>e)return Rs(f,t,e,h);if(d>=t&&s==-1&&(s=a,o=h),h>e&&f.dom.parentNode==n.dom){r=a,l=c;break}c=d,h=d+f.breakAfter}return{from:o,to:l<0?i+n.length:l,startDOM:(s?n.children[s-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:r<n.children.length&&r>=0?n.children[r].dom:null}}else return n.isText()?{from:i,to:i+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function Ls(n,t){let e,{newSel:i}=t,s=n.state.selection.main,o=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(t.bounds){let{from:r,to:l}=t.bounds,a=s.from,h=null;(o===8||w.android&&t.text.length<l-r)&&(a=s.to,h="end");let c=Ps(n.state.doc.sliceString(r,l,kt),t.text,a-r,h);c&&(w.chrome&&o==13&&c.toB==c.from+2&&t.text.slice(c.from,c.toB)==kt+kt&&c.toB--,e={from:r+c.from,to:r+c.toA,insert:p.Text.of(t.text.slice(c.from,c.toB).split(kt))})}else i&&(!n.hasFocus&&n.state.facet($)||i.main.eq(s))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!s.empty&&i&&i.main.empty?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:(w.mac||w.android)&&e&&e.from==e.to&&e.from==s.head-1&&/^\. ?$/.test(e.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=p.EditorSelection.single(i.main.anchor-1,i.main.head-1)),e={from:e.from,to:e.to,insert:p.Text.of([e.insert.toString().replace("."," ")])}):e&&e.from>=s.from&&e.to<=s.to&&(e.from!=s.from||e.to!=s.to)&&s.to-s.from-(e.to-e.from)<=4?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,e.from).append(e.insert).append(n.state.doc.slice(e.to,s.to))}:n.state.doc.lineAt(s.from).to<s.to&&n.docView.lineHasWidget(s.to)&&n.inputState.insertingTextAt>Date.now()-50?e={from:s.from,to:s.to,insert:n.state.toText(n.inputState.insertingText)}:w.chrome&&e&&e.from==e.to&&e.from==s.head&&e.insert.toString()==`
3
- `&&n.lineWrapping&&(i&&(i=p.EditorSelection.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:p.Text.of([" "])}),e)return oi(n,e,i,o);if(i&&!i.main.eq(s)){let r=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(r=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=Bs(n.state.facet(zt).map(a=>a(n)),i))),n.dispatch({selection:i,scrollIntoView:r,userEvent:l}),!0}else return!1}function oi(n,t,e,i=-1){if(w.ios&&n.inputState.flushIOSKey(t))return!0;let s=n.state.selection.main;if(w.android&&(t.to==s.to&&(t.from==s.from||t.from==s.from-1&&n.state.sliceDoc(t.from,s.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&pt(n.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&pt(n.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&pt(n.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let r,l=()=>r||(r=so(n,t,e));return n.state.facet(bs).some(a=>a(n,t.from,t.to,o,l))||n.dispatch(l()),!0}function so(n,t,e){let i,s=n.state,o=s.selection.main,r=-1;if(t.from==t.to&&t.from<o.from||t.from>o.to){let a=t.from<o.from?-1:1,h=a<0?o.from:o.to,c=Bt(s.facet(zt).map(f=>f(n)),h,a);t.from==c&&(r=c)}if(r>-1)i={changes:t,selection:p.EditorSelection.cursor(t.from+t.insert.length,-1)};else if(t.from>=o.from&&t.to<=o.to&&t.to-t.from>=(o.to-o.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&n.inputState.composing<0){let a=o.from<t.from?s.sliceDoc(o.from,t.from):"",h=o.to>t.to?s.sliceDoc(t.to,o.to):"";i=s.replaceSelection(n.state.toText(a+t.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let a=s.changes(t),h=e&&e.main.to<=a.newLength?e.main:void 0;if(s.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&t.to<=o.to+10&&t.to>=o.to-10){let c=n.state.sliceDoc(t.from,t.to),f,d=e&&Os(n,e.main.head);if(d){let g=t.insert.length-(t.to-t.from);f={from:d.from,to:d.to-g}}else f=n.state.doc.lineAt(o.head);let u=o.to-t.to;i=s.changeByRange(g=>{if(g.from==o.from&&g.to==o.to)return{changes:a,range:h||g.map(a)};let m=g.to-u,b=m-c.length;if(n.state.sliceDoc(b,m)!=c||m>=f.from&&b<=f.to)return{range:g};let y=s.changes({from:b,to:m,insert:t.insert}),x=g.to-o.to;return{changes:y,range:h?p.EditorSelection.range(Math.max(0,h.anchor+x),Math.max(0,h.head+x)):g.map(y)}})}else i={changes:a,selection:h&&s.selection.replaceRange(h)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function Ps(n,t,e,i){let s=Math.min(n.length,t.length),o=0;for(;o<s&&n.charCodeAt(o)==t.charCodeAt(o);)o++;if(o==s&&n.length==t.length)return null;let r=n.length,l=t.length;for(;r>0&&l>0&&n.charCodeAt(r-1)==t.charCodeAt(l-1);)r--,l--;if(i=="end"){let a=Math.max(0,o-Math.min(r,l));e-=r+a-o}if(r<o&&n.length<t.length){let a=e<=o&&e>=r?o-e:0;o-=a,l=o+(l-r),r=o}else if(l<o){let a=e<=o&&e>=l?o-e:0;o-=a,r=o+(r-l),l=o}return{from:o,toA:r,toB:l}}function no(n){let t=[];if(n.root.activeElement!=n.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:o}=n.observer.selectionRange;return e&&(t.push(new Mi(e,i)),(s!=e||o!=i)&&t.push(new Mi(s,o))),t}function oo(n,t){if(n.length==0)return null;let e=n[0].pos,i=n.length==2?n[1].pos:e;return e>-1&&i>-1?p.EditorSelection.single(e+t,i+t):null}class ro{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,w.safari&&t.contentDOM.addEventListener("input",()=>null),w.gecko&&vo(t.contentDOM.ownerDocument)}handleEvent(t){!go(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let s of i.observers)s(this.view,e);for(let s of i.handlers){if(e.defaultPrevented)break;if(s(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=lo(t),i=this.handlers,s=this.view.contentDOM;for(let o in e)if(o!="scroll"){let r=!e[o].handlers.length,l=i[o];l&&r!=!l.handlers.length&&(s.removeEventListener(o,this.handleEvent),l=null),l||s.addEventListener(o,this.handleEvent,{passive:r})}for(let o in i)o!="scroll"&&!e[o]&&s.removeEventListener(o,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&Ws.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),w.android&&w.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return w.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=Hs.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||ao.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,pt(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return!/^key/.test(t.type)||t.synthetic?!1:this.composing>0?!0:w.safari&&!w.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function ki(n,t){return(e,i)=>{try{return t.call(n,i,e)}catch(s){K(e.state,s)}}}function lo(n){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec,o=s&&s.plugin.domEventHandlers,r=s&&s.plugin.domEventObservers;if(o)for(let l in o){let a=o[l];a&&e(l).handlers.push(ki(i.value,a))}if(r)for(let l in r){let a=r[l];a&&e(l).observers.push(ki(i.value,a))}}for(let i in q)e(i).handlers.push(q[i]);for(let i in I)e(i).observers.push(I[i]);return t}const Hs=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],ao="dthko",Ws=[16,17,18,20,91,92,224,225],Gt=6;function Yt(n){return Math.max(0,n)*.7+8}function ho(n,t){return Math.max(Math.abs(n.clientX-t.clientX),Math.abs(n.clientY-t.clientY))}class co{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=un(t.contentDOM),this.atoms=t.state.facet(zt).map(r=>r(t));let o=t.contentDOM.ownerDocument;o.addEventListener("mousemove",this.move=this.move.bind(this)),o.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(p.EditorState.allowMultipleSelections)&&fo(t,e),this.dragging=po(t,e)&&Fs(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&ho(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,s=0,o=0,r=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:r}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:o,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=ni(this.view);t.clientX-a.left<=s+Gt?e=-Yt(s-t.clientX):t.clientX+a.right>=r-Gt&&(e=Yt(t.clientX-r)),t.clientY-a.top<=o+Gt?i=-Yt(o-t.clientY):t.clientY+a.bottom>=l-Gt&&(i=Yt(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=Bs(this.atoms,this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function fo(n,t){let e=n.state.facet(us);return e.length?e[0](t):w.mac?t.metaKey:t.ctrlKey}function uo(n,t){let e=n.state.facet(ps);return e.length?e[0](t):w.mac?!t.altKey:!t.ctrlKey}function po(n,t){let{main:e}=n.state.selection;if(e.empty)return!1;let i=Lt(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let o=0;o<s.length;o++){let r=s[o];if(r.left<=t.clientX&&r.right>=t.clientX&&r.top<=t.clientY&&r.bottom>=t.clientY)return!0}return!1}function go(n,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=n.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=B.get(e))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(t))return!1;return!0}const q=Object.create(null),I=Object.create(null),Ns=w.ie&&w.ie_version<15||w.ios&&w.webkit_version<604;function mo(n){let t=n.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{n.focus(),e.remove(),Vs(n,e.value)},50)}function me(n,t,e){for(let i of n.facet(t))e=i(e,n);return e}function Vs(n,t){t=me(n.state,ei,t);let{state:e}=n,i,s=1,o=e.toText(t),r=o.lines==e.selection.ranges.length;if(qe!=null&&e.selection.ranges.every(a=>a.empty)&&qe==o.toString()){let a=-1;i=e.changeByRange(h=>{let c=e.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=e.toText((r?o.line(s++).text:t)+e.lineBreak);return{changes:{from:c.from,insert:f},range:p.EditorSelection.cursor(h.from+f.length)}})}else r?i=e.changeByRange(a=>{let h=o.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:p.EditorSelection.cursor(a.from+h.length)}}):i=e.replaceSelection(o);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}I.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};q.keydown=(n,t)=>(n.inputState.setSelectionOrigin("select"),t.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);I.touchstart=(n,t)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};I.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};q.mousedown=(n,t)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of n.state.facet(gs))if(e=i(n,t),e)break;if(!e&&t.button==0&&(e=yo(n,t)),e){let i=!n.hasFocus;n.inputState.startMouseSelection(new co(n,t,e,i)),i&&n.observer.ignore(()=>{ns(n.contentDOM);let o=n.root.activeElement;o&&!o.contains(n.contentDOM)&&o.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(t),s.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Ai(n,t,e,i){if(i==1)return p.EditorSelection.cursor(t,e);if(i==2)return Xn(n.state,t,e);{let s=n.docView.lineAt(t,e),o=n.state.doc.lineAt(s?s.posAtEnd:t),r=s?s.posAtStart:o.from,l=s?s.posAtEnd:o.to;return l<n.state.doc.length&&l==o.to&&l++,p.EditorSelection.range(r,l)}}const bo=w.ie&&w.ie_version<=11;let Ti=null,Di=0,Oi=0;function Fs(n){if(!bo)return n.detail;let t=Ti,e=Oi;return Ti=n,Oi=Date.now(),Di=!t||e>Date.now()-400&&Math.abs(t.clientX-n.clientX)<2&&Math.abs(t.clientY-n.clientY)<2?(Di+1)%3:1}function yo(n,t){let e=n.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),i=Fs(t),s=n.state.selection;return{update(o){o.docChanged&&(e.pos=o.changes.mapPos(e.pos),s=s.map(o.changes))},get(o,r,l){let a=n.posAndSideAtCoords({x:o.clientX,y:o.clientY},!1),h,c=Ai(n,a.pos,a.assoc,i);if(e.pos!=a.pos&&!r){let f=Ai(n,e.pos,e.assoc,i),d=Math.min(f.from,c.from),u=Math.max(f.to,c.to);c=d<c.from?p.EditorSelection.range(d,u):p.EditorSelection.range(u,d)}return r?s.replaceRange(s.main.extend(c.from,c.to)):l&&i==1&&s.ranges.length>1&&(h=wo(s,a.pos))?h:l?s.addRange(c):p.EditorSelection.create([c])}}}function wo(n,t){for(let e=0;e<n.ranges.length;e++){let{from:i,to:s}=n.ranges[e];if(i<=t&&s>=t)return p.EditorSelection.create(n.ranges.slice(0,e).concat(n.ranges.slice(e+1)),n.mainIndex==e?0:n.mainIndex-(n.mainIndex>e?1:0))}return null}q.dragstart=(n,t)=>{let{selection:{main:e}}=n.state;if(t.target.draggable){let s=n.docView.tile.nearest(t.target);if(s&&s.isWidget()){let o=s.posAtStart,r=o+s.length;(o>=e.to||r<=e.from)&&(e=p.EditorSelection.range(o,r))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",me(n.state,ii,n.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};q.dragend=n=>(n.inputState.draggedContent=null,!1);function Bi(n,t,e,i){if(e=me(n.state,ei,e),!e)return;let s=n.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:o}=n.inputState,r=i&&o&&uo(n,t)?{from:o.from,to:o.to}:null,l={from:s,insert:e},a=n.state.changes(r?[r,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:r?"move.drop":"input.drop"}),n.inputState.draggedContent=null}q.drop=(n,t)=>{if(!t.dataTransfer)return!1;if(n.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),s=0,o=()=>{++s==e.length&&Bi(n,t,i.filter(r=>r!=null).join(n.state.lineBreak),!1)};for(let r=0;r<e.length;r++){let l=new FileReader;l.onerror=o,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[r]=l.result),o()},l.readAsText(e[r])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return Bi(n,t,i,!0),!0}return!1};q.paste=(n,t)=>{if(n.state.readOnly)return!0;n.observer.flush();let e=Ns?null:t.clipboardData;return e?(Vs(n,e.getData("text/plain")||e.getData("text/uri-list")),!0):(mo(n),!1)};function xo(n,t){let e=n.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function So(n){let t=[],e=[],i=!1;for(let s of n.selection.ranges)s.empty||(t.push(n.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:o}of n.selection.ranges){let r=n.doc.lineAt(o);r.number>s&&(t.push(r.text),e.push({from:r.from,to:Math.min(n.doc.length,r.to+1)})),s=r.number}i=!0}return{text:me(n,ii,t.join(n.lineBreak)),ranges:e,linewise:i}}let qe=null;q.copy=q.cut=(n,t)=>{let{text:e,ranges:i,linewise:s}=So(n.state);if(!e&&!s)return!1;qe=s?e:null,t.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let o=Ns?null:t.clipboardData;return o?(o.clearData(),o.setData("text/plain",e),!0):(xo(n,e),!1)};const Is=p.Annotation.define();function zs(n,t){let e=[];for(let i of n.facet(ys)){let s=i(n,t);s&&e.push(s)}return e.length?n.update({effects:e,annotations:Is.of(!0)}):null}function Ks(n){setTimeout(()=>{let t=n.hasFocus;if(t!=n.inputState.notifiedFocused){let e=zs(n.state,t);e?n.dispatch(e):n.update([])}},10)}I.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Ks(n)};I.blur=n=>{n.observer.clearSelectionRange(),Ks(n)};I.compositionstart=I.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};I.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,w.chrome&&w.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};I.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};q.beforeinput=(n,t)=>{var e,i;if((t.inputType=="insertText"||t.inputType=="insertCompositionText")&&(n.inputState.insertingText=t.data,n.inputState.insertingTextAt=Date.now()),t.inputType=="insertReplacementText"&&n.observer.editContext){let o=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),r=t.getTargetRanges();if(o&&r.length){let l=r[0],a=n.posAtDOM(l.startContainer,l.startOffset),h=n.posAtDOM(l.endContainer,l.endOffset);return oi(n,{from:a,to:h,insert:n.state.toText(o)},null),!0}}let s;if(w.chrome&&w.android&&(s=Hs.find(o=>o.inputType==t.inputType))&&(n.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let o=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>o+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return w.ios&&t.inputType=="deleteContentForward"&&n.observer.flushSoon(),w.safari&&t.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>I.compositionend(n,t),20),!1};const Ei=new Set;function vo(n){Ei.has(n)||(Ei.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Ri=["pre-wrap","normal","pre-line","break-spaces"];let St=!1;function Li(){St=!1}class Co{constructor(t){this.lineWrapping=t,this.doc=p.Text.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Ri.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,o,r){let l=Ri.indexOf(t)>-1,a=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=o,a){this.heightSamples={};for(let h=0;h<r.length;h++){let c=r[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class Mo{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class V{constructor(t,e,i,s,o){this.from=t,this.length=e,this.top=i,this.height=s,this._content=o}get type(){return typeof this._content=="number"?exports.BlockType.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof at?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new V(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var T=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(T||(T={}));const se=.001;class H{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>se&&(St=!0),this.height=t)}replace(t,e,i){return H.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let o=this,r=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=s[l],d=o.lineAt(a,T.ByPosNoHeight,i.setDoc(e),0,0),u=d.to>=h?d:o.lineAt(h,T.ByPosNoHeight,i,0,0);for(f+=u.to-h,h=u.to;l>0&&d.from<=s[l-1].toA;)a=s[l-1].fromA,c=s[l-1].fromB,l--,a<d.from&&(d=o.lineAt(a,T.ByPosNoHeight,i,0,0));c+=d.from-a,a=d.from;let g=ri.build(i.setDoc(r),t,c,f);o=ce(o,o.replace(a,h,g))}return o.updateHeight(i,0)}static empty(){return new N(0,0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,o=0;for(;;)if(e==i)if(s>o*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(o>s*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,o-=l.size}else break;else if(s<o){let l=t[e++];l&&(s+=l.size)}else{let l=t[--i];l&&(o+=l.size)}let r=0;return t[e-1]==null?(r=1,e--):t[e]==null&&(r=1,i++),new Ao(H.of(t.slice(0,e)),r,H.of(t.slice(i)))}}function ce(n,t){return n==t?n:(n.constructor!=t.constructor&&(St=!0),t)}H.prototype.size=1;const ko=O.replace({});class qs extends H{constructor(t,e,i){super(t,e),this.deco=i,this.spaceAbove=0}mainBlock(t,e){return new V(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(t,e,i,s){return this.spaceAbove&&t<i+this.spaceAbove?new V(s,0,i,this.spaceAbove,ko):this.mainBlock(i,s)}lineAt(t,e,i,s,o){let r=this.mainBlock(s,o);return this.spaceAbove?this.blockAt(0,i,s,o).join(r):r}forEachLine(t,e,i,s,o,r){t<=o+this.length&&e>=o&&r(this.lineAt(0,T.ByPos,i,s,o))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class N extends qs{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new V(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof N||s instanceof R&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof R?s=new N(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):H.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class R extends H{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,o=s-i+1,r,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.lineHeight*o);r=a/o,this.length>o+1&&(l=(this.height-a)/(this.length-o-1))}else r=this.height/o;return{firstLine:i,lastLine:s,perLine:r,perChar:l}}blockAt(t,e,i,s){let{firstLine:o,lastLine:r,perLine:l,perChar:a}=this.heightMetrics(e,s);if(e.lineWrapping){let h=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),c=e.doc.lineAt(h),f=l+c.length*a,d=Math.max(i,t-f/2);return new V(c.from,c.length,d,f,0)}else{let h=Math.max(0,Math.min(r-o,Math.floor((t-i)/l))),{from:c,length:f}=e.doc.line(o+h);return new V(c,f,i+l*h,l,0)}}lineAt(t,e,i,s,o){if(e==T.ByHeight)return this.blockAt(t,i,s,o);if(e==T.ByPosNoHeight){let{from:u,to:g}=i.doc.lineAt(t);return new V(u,g-u,0,0,0)}let{firstLine:r,perLine:l,perChar:a}=this.heightMetrics(i,o),h=i.doc.lineAt(t),c=l+h.length*a,f=h.number-r,d=s+l*f+a*(h.from-o-f);return new V(h.from,h.length,Math.max(s,Math.min(d,s+this.height-c)),c,0)}forEachLine(t,e,i,s,o,r){t=Math.max(t,o),e=Math.min(e,o+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,o);for(let c=t,f=s;c<=e;){let d=i.doc.lineAt(c);if(c==t){let g=d.number-l;f+=a*g+h*(t-o-g)}let u=a+h*d.length;r(new V(d.from,d.length,f,u,0)),f+=u,c=d.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let o=i[i.length-1];o instanceof R?i[i.length-1]=new R(o.length+s):i.push(null,new R(s-1))}if(t>0){let o=i[0];o instanceof R?i[0]=new R(t+o.length):i.unshift(new R(t-1),null)}return H.of(i)}decomposeLeft(t,e){e.push(new R(t-1),null)}decomposeRight(t,e){e.push(null,new R(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let o=e+this.length;if(s&&s.from<=e+this.length&&s.more){let r=[],l=Math.max(e,s.from),a=-1;for(s.from>e&&r.push(new R(s.from-e-1).updateHeight(t,e));l<=o&&s.more;){let c=t.doc.lineAt(l).length;r.length&&r.push(null);let f=s.heights[s.index++],d=0;f<0&&(d=-f,f=s.heights[s.index++]),a==-1?a=f:Math.abs(f-a)>=se&&(a=-2);let u=new N(c,f,d);u.outdated=!1,r.push(u),l+=c+1}l<=o&&r.push(null,new R(o-l).updateHeight(t,l));let h=H.of(r);return(a<0||Math.abs(h.height-this.height)>=se||Math.abs(a-this.heightMetrics(t,e).perLine)>=se)&&(St=!0),ce(this,h)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Ao extends H{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let o=i+this.left.height;return t<o?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,o,s+this.left.length+this.break)}lineAt(t,e,i,s,o){let r=s+this.left.height,l=o+this.left.length+this.break,a=e==T.ByHeight?t<r:t<l,h=a?this.left.lineAt(t,e,i,s,o):this.right.lineAt(t,e,i,r,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=e==T.ByPosNoHeight?T.ByPosNoHeight:T.ByPos;return a?h.join(this.right.lineAt(l,c,i,r,l)):this.left.lineAt(l,c,i,s,o).join(h)}forEachLine(t,e,i,s,o,r){let l=s+this.left.height,a=o+this.left.length+this.break;if(this.break)t<a&&this.left.forEachLine(t,e,i,s,o,r),e>=a&&this.right.forEachLine(t,e,i,l,a,r);else{let h=this.lineAt(a,T.ByPos,i,s,o);t<h.from&&this.left.forEachLine(t,h.from-1,i,s,o,r),h.to>=t&&h.from<=e&&r(h),e>h.to&&this.right.forEachLine(h.to+1,e,i,l,a,r)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let o=[];t>0&&this.decomposeLeft(t,o);let r=o.length;for(let l of i)o.push(l);if(t>0&&Pi(o,r-1),e<this.length){let l=o.length;this.decomposeRight(e,o),Pi(o,l)}return H.of(o)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?H.of(this.break?[t,null,e]:[t,e]):(this.left=ce(this.left,t),this.right=ce(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:o,right:r}=this,l=e+o.length+this.break,a=null;return s&&s.from<=e+o.length&&s.more?a=o=o.updateHeight(t,e,i,s):o.updateHeight(t,e,i),s&&s.from<=l+r.length&&s.more?a=r=r.updateHeight(t,l,i,s):r.updateHeight(t,l,i),a?this.balanced(o,r):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Pi(n,t){let e,i;n[t]==null&&(e=n[t-1])instanceof R&&(i=n[t+1])instanceof R&&n.splice(t-1,3,new R(e.length+1+i.length))}const To=5;class ri{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof N?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new N(i-this.pos,-1,0)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,o=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let r=e-t;i.block?this.addBlock(new qs(r,s,i)):(r||o||s>=To)&&this.addLineDeco(s,o,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new N(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new R(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof N)return t;let e=new N(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof N)&&!this.isCovered?this.nodes.push(new N(0,-1,0)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof N&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let o=new ri(i,t);return p.RangeSet.spans(e,i,s,o,0),o.finish(i)}}function Do(n,t,e){let i=new Oo;return p.RangeSet.compare(n,t,e,i,0),i.changes}class Oo{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&ut(t,e,this.changes,5)}}function Bo(n,t){let e=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,o=Math.max(0,e.left),r=Math.min(s.innerWidth,e.right),l=Math.max(0,e.top),a=Math.min(s.innerHeight,e.bottom);for(let h=n.parentNode;h&&h!=i.body;)if(h.nodeType==1){let c=h,f=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&f.overflow!="visible"){let d=c.getBoundingClientRect();o=Math.max(o,d.left),r=Math.min(r,d.right),l=Math.max(l,d.top),a=Math.min(h==n.parentNode?s.innerHeight:a,d.bottom)}h=f.position=="absolute"||f.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:o-e.left,right:Math.max(o,r)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function Eo(n){let t=n.getBoundingClientRect(),e=n.ownerDocument.defaultView||window;return t.left<e.innerWidth&&t.right>0&&t.top<e.innerHeight&&t.bottom>0}function Ro(n,t){let e=n.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class ke{constructor(t,e,i,s){this.from=t,this.to=e,this.size=i,this.displaySize=s}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],o=e[i];if(s.from!=o.from||s.to!=o.to||s.size!=o.size)return!1}return!0}draw(t,e){return O.replace({widget:new Lo(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class Lo extends st{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class Hi{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Wi,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=exports.Direction.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(si).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Co(e),this.stateDeco=t.facet(Wt).filter(i=>typeof i!="function"),this.heightMap=H.empty().applyChanges(this.stateDeco,p.Text.empty,this.heightOracle.setDoc(t.doc),[new F(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=O.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:o,to:r})=>s>=o&&s<=r)){let{from:o,to:r}=this.lineBlockAt(s);t.push(new Xt(o,r))}}return this.viewports=t.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Wi:new li(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(At(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Wt).filter(c=>typeof c!="function");let s=t.changedRanges,o=F.extendWithRanges(s,Do(i,this.stateDeco,t?t.changes:p.ChangeSet.empty(this.state.doc.length))),r=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Li(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),o),(this.heightMap.height!=r||St)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let a=o.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,t.flags|=this.updateForViewport(),(h||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(xs)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,o=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?exports.Direction.RTL:exports.Direction.LTR;let r=this.heightOracle.mustRefreshForWrapping(o),l=e.getBoundingClientRect(),a=r||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:k,scaleY:v}=ss(e,l);(k>.005&&Math.abs(this.scaleX-k)>.005||v>.005&&Math.abs(this.scaleY-v)>.005)&&(this.scaleX=k,this.scaleY=v,h|=16,r=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,d=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=d)&&(this.paddingTop=f,this.paddingBottom=d,h|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,h|=16);let u=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=u&&(this.scrollAnchorHeight=-1,this.scrollTop=u),this.scrolledToBottom=os(t.scrollDOM);let g=(this.printing?Ro:Bo)(e,this.paddingTop),m=g.top-this.pixelViewport.top,b=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(a=!0)),!this.inView&&!this.scrollTarget&&!Eo(t.dom))return 0;let x=l.width;if((this.contentDOMWidth!=x||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,h|=16),a){let k=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(k)&&(r=!0),r||s.lineWrapping&&Math.abs(x-this.contentDOMWidth)>s.charWidth){let{lineHeight:v,charWidth:S,textHeight:D}=t.docView.measureTextSize();r=v>0&&s.refresh(o,v,S,D,Math.max(5,x/S),k),r&&(t.docView.minWidth=0,h|=16)}m>0&&b>0?c=Math.max(m,b):m<0&&b<0&&(c=Math.min(m,b)),Li();for(let v of this.viewports){let S=v.from==this.viewport.from?k:t.docView.measureVisibleLineHeights(v);this.heightMap=(r?H.empty().applyChanges(this.stateDeco,p.Text.empty,this.heightOracle,[new F(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,r,new Mo(v.from,S))}St&&(h|=2)}let C=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return C&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||C)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,o=this.heightOracle,{visibleTop:r,visibleBottom:l}=this,a=new Xt(s.lineAt(r-i*1e3,T.ByHeight,o,0,0).from,s.lineAt(l+(1-i)*1e3,T.ByHeight,o,0,0).to);if(e){let{head:h}=e.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(h,T.ByPos,o,0,0),d;e.y=="center"?d=(f.top+f.bottom)/2-c/2:e.y=="start"||e.y=="nearest"&&h<a.from?d=f.top:d=f.bottom-c,a=new Xt(s.lineAt(d-1e3/2,T.ByHeight,o,0,0).from,s.lineAt(d+c+1e3/2,T.ByHeight,o,0,0).to)}}return a}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new Xt(this.heightMap.lineAt(i,T.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,T.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,T.ByPos,this.heightOracle,0,0),{bottom:o}=this.heightMap.lineAt(e,T.ByPos,this.heightOracle,0,0),{visibleTop:r,visibleBottom:l}=this;return(t==0||s<=r-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||o>=l+Math.max(10,Math.min(i,250)))&&s>r-2*1e3&&o<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new ke(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,o=s>>1,r=s<<1;if(this.defaultTextDirection!=exports.Direction.LTR&&!i)return[];let l=[],a=(c,f,d,u)=>{if(f-c<o)return;let g=this.state.selection.main,m=[g.from];g.empty||m.push(g.to);for(let y of m)if(y>c&&y<f){a(c,y-10,d,u),a(y+10,f,d,u);return}let b=Ho(t,y=>y.from>=d.from&&y.to<=d.to&&Math.abs(y.from-c)<o&&Math.abs(y.to-f)<o&&!m.some(x=>y.from<x&&y.to>x));if(!b){if(f<d.to&&e&&i&&e.visibleRanges.some(C=>C.from<=f&&C.to>=f)){let C=e.moveToLineBoundary(p.EditorSelection.cursor(f),!1,!0).head;C>c&&(f=C)}let y=this.gapSize(d,c,f,u),x=i||y<2e6?y:2e6;b=new ke(c,f,y,x)}l.push(b)},h=c=>{if(c.length<r||c.type!=exports.BlockType.Text)return;let f=Po(c.from,c.to,this.stateDeco);if(f.total<r)return;let d=this.scrollTarget?this.scrollTarget.range.head:null,u,g;if(i){let m=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,b,y;if(d!=null){let x=Ut(f,d),C=((this.visibleBottom-this.visibleTop)/2+m)/c.height;b=x-C,y=x+C}else b=(this.visibleTop-c.top-m)/c.height,y=(this.visibleBottom-c.top+m)/c.height;u=$t(f,b),g=$t(f,y)}else{let m=f.total*this.heightOracle.charWidth,b=s*this.heightOracle.charWidth,y=0;if(m>2e6)for(let S of t)S.from>=c.from&&S.from<c.to&&S.size!=S.displaySize&&S.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=S.size-S.displaySize);let x=this.pixelViewport.left+y,C=this.pixelViewport.right+y,k,v;if(d!=null){let S=Ut(f,d),D=((C-x)/2+b)/m;k=S-D,v=S+D}else k=(x-b)/m,v=(C+b)/m;u=$t(f,k),g=$t(f,v)}u>c.from&&a(c.from,u,c,f),g<c.to&&a(g,c.to,c,f)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(t,e,i,s){let o=Ut(s,i)-Ut(s,e);return this.heightOracle.lineWrapping?t.height*o:s.total*this.heightOracle.charWidth*o}updateLineGaps(t){ke.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=O.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];p.RangeSet.spans(e,this.viewport.from,this.viewport.to,{span(o,r){i.push({from:o,to:r})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let o=0;o<i.length&&!(s&8);o++){let r=this.visibleRanges[o],l=i[o];(r.from!=l.from||r.to!=l.to)&&(s|=4,t&&t.mapPos(r.from,-1)==l.from&&t.mapPos(r.to,1)==l.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||At(this.heightMap.lineAt(t,T.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||At(this.heightMap.lineAt(this.scaler.fromDOM(t),T.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return At(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Xt{constructor(t,e){this.from=t,this.to=e}}function Po(n,t,e){let i=[],s=n,o=0;return p.RangeSet.spans(e,n,t,{span(){},point(r,l){r>s&&(i.push({from:s,to:r}),o+=r-s),s=l}},20),s<t&&(i.push({from:s,to:t}),o+=t-s),{total:o,ranges:i}}function $t({total:n,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(n*e);for(let s=0;;s++){let{from:o,to:r}=t[s],l=r-o;if(i<=l)return o+i;i-=l}}function Ut(n,t){let e=0;for(let{from:i,to:s}of n.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/n.total}function Ho(n,t){for(let e of n)if(t(e))return e}const Wi={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};class li{constructor(t,e,i){let s=0,o=0,r=0;this.viewports=i.map(({from:l,to:a})=>{let h=e.lineAt(l,T.ByPos,t,0,0).top,c=e.lineAt(a,T.ByPos,t,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let l of this.viewports)l.domTop=r+(l.top-o)*this.scale,r=l.domBottom=l.domTop+(l.bottom-l.top),o=l.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.top)return s+(t-i)*this.scale;if(t<=o.bottom)return o.domTop+(t-o.top);i=o.bottom,s=o.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.domTop)return i+(t-s)/this.scale;if(t<=o.domBottom)return o.top+(t-o.domTop);i=o.bottom,s=o.domBottom}}eq(t){return t instanceof li?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function At(n,t){if(t.scale==1)return n;let e=t.toDOM(n.top),i=t.toDOM(n.bottom);return new V(n.from,n.length,e,i-e,Array.isArray(n._content)?n._content.map(s=>At(s,t)):n._content)}const Qt=p.Facet.define({combine:n=>n.join(" ")}),_e=p.Facet.define({combine:n=>n.indexOf(!0)>-1}),je=mt.StyleModule.newName(),_s=mt.StyleModule.newName(),js=mt.StyleModule.newName(),Gs={"&light":"."+_s,"&dark":"."+js};function Ge(n,t,e){return new mt.StyleModule(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):n+" "+i}})}const Wo=Ge("."+je,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Gs),No={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ae=w.ie&&w.ie_version<=11;class Vo{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new pn,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(w.ie&&w.ie_version<=11||w.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&w.android&&t.constructor.EDIT_CONTEXT!==!1&&!(w.chrome&&w.chrome_version<126)&&(this.editContext=new Io(t),t.state.facet($)&&(t.contentDOM.editContext=this.editContext.editContext)),Ae&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet($)?i.root.activeElement!=this.dom:!ie(this.dom,s))return;let o=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(o&&o.isWidget()&&o.widget.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(w.ie&&w.ie_version<=11||w.android&&w.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Ot(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=Lt(t.root);if(!e)return!1;let i=w.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&Fo(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=ie(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&mn(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,No),Ae&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Ae&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let s=()=>{let o=this.delayedAndroidKey;o&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=o.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&o.force&&pt(this.dom,o.key,o.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let o of t){let r=this.readMutation(o);r&&(r.typeOver&&(s=!0),e==-1?{from:e,to:i}=r:(e=Math.min(r.from,e),i=Math.max(r.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&ie(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let o=new io(this.view,t,e,i);return this.view.docView.domChanged={newSel:o.newSel?o.newSel.main:null},o}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=Ls(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty(t.type=="attributes"),t.type=="childList"){let i=Ni(e,t.previousSibling||t.target.previousSibling,-1),s=Ni(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet($)!=t.state.facet($)&&(t.view.contentDOM.editContext=t.state.facet($)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function Ni(n,t,e){for(;t;){let i=B.get(t);if(i&&i.parent==n)return i;let s=t.parentNode;t=s!=n.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function Vi(n,t){let e=t.startContainer,i=t.startOffset,s=t.endContainer,o=t.endOffset,r=n.docView.domAtPos(n.state.selection.main.anchor,1);return Ot(r.node,r.offset,s,o)&&([e,i,s,o]=[s,o,e,i]),{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:o}}function Fo(n,t){if(t.getComposedRanges){let s=t.getComposedRanges(n.root)[0];if(s)return Vi(n,s)}let e=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),e=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),e?Vi(n,e):null}class Io{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let s=t.state.selection.main,{anchor:o,head:r}=s,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&o<this.from?l=o:a==this.to&&o>this.to&&(a=o);let c=Ps(t.state.sliceDoc(l,a),i.text,(h?s.from:s.to)-l,h?"end":null);if(!c){let d=p.EditorSelection.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));d.main.eq(s)||t.dispatch({selection:d,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:p.Text.of(i.text.slice(c.from,c.toB).split(`
4
- `))};if((w.mac||w.android)&&f.from==r-1&&/^\. ?$/.test(i.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:p.Text.of([i.text.replace("."," ")])}),this.pendingContextChange=f,!t.state.readOnly){let d=this.to-this.from+(f.to-f.from+f.insert.length);oi(t,f,p.EditorSelection.single(this.toEditorPos(i.selectionStart,d),this.toEditorPos(i.selectionEnd,d)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),f.from<f.to&&!f.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],o=null;for(let r=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);r<l;r++){let a=t.coordsForChar(r);o=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||o||new DOMRect,s.push(o)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let o of i.getTextFormats()){let r=o.underlineStyle,l=o.underlineThickness;if(!/none/i.test(r)&&!/none/i.test(l)){let a=this.toEditorPos(o.rangeStart),h=this.toEditorPos(o.rangeEnd);if(a<h){let c=`text-decoration: underline ${/^[a-z]/.test(r)?r+" ":r=="Dashed"?"dashed ":r=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(O.mark({attributes:{style:c}}).range(a,h))}}}t.dispatch({effects:vs.of(O.set(s))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(t.state)}};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=Lt(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((o,r,l,a,h)=>{if(i)return;let c=h.length-(r-o);if(s&&r>=s.to)if(s.from==o&&s.to==r&&s.insert.eq(h)){s=this.pendingContextChange=null,e+=c,this.to+=c;return}else s=null,this.revertPending(t.state);if(o+=e,r+=e,r<=this.from)this.from+=c,this.to+=c;else if(o<this.to){if(o<this.from||r>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(o),this.toContextPos(r),h.toString()),this.to+=c}e+=c}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class M{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(s=>s.forEach(o=>i(o,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=t.root||gn(t.parent)||document,this.viewState=new Hi(t.state||p.EditorState.create(t)),t.scrollTo&&t.scrollTo.is(jt)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(ft).map(s=>new xe(s));for(let s of this.plugins)s.update(this);this.observer=new Vo(this),this.inputState=new ro(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Si(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...t){let e=t.length==1&&t[0]instanceof p.Transaction?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,o=this.state;for(let d of t){if(d.startState!=o)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");o=d.state}if(this.destroyed){this.viewState.state=o;return}let r=this.hasFocus,l=0,a=null;t.some(d=>d.annotation(Is))?(this.inputState.notifiedFocused=r,l=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,a=zs(o,r),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(o.doc)||!this.state.selection.eq(o.selection))&&(c=null)):this.observer.clear(),o.facet(p.EditorState.phrases)!=this.state.facet(p.EditorState.phrases))return this.setState(o);s=Nt.create(this,o,t),s.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let d of t){if(f&&(f=f.map(d.changes)),d.scrollIntoView){let{main:u}=d.state.selection;f=new gt(u.empty?u:p.EditorSelection.cursor(u.head,u.head>u.anchor?-1:1))}for(let u of d.effects)u.is(jt)&&(f=u.value.clip(this.state))}this.viewState.update(s,f),this.bidiCache=fe.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(Mt)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(d=>d.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Qt)!=s.state.facet(Qt)&&(this.viewState.mustMeasureContent=!0),(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!s.empty)for(let d of this.state.facet(Fe))try{d(s)}catch(u){K(this.state,u,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Ls(this,c)&&h.force&&pt(this.contentDOM,h.key,h.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new Hi(t),this.plugins=t.facet(ft).map(i=>new xe(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Si(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(ft),i=t.state.facet(ft);if(e!=i){let s=[];for(let o of i){let r=e.indexOf(o);if(r<0)s.push(new xe(o));else{let l=this.plugins[r];l.mustUpdate=t,s.push(l)}}for(let o of this.plugins)o.mustUpdate!=t&&o.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){K(this.state,i,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:o,scrollAnchorHeight:r}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(r=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(r<0)if(os(i))o=-1,r=this.viewState.heightMap.height;else{let u=this.viewState.scrollAnchorAt(s);o=u.from,r=u.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let c=h.map(u=>{try{return u.read(this)}catch(g){return K(this.state,g),Fi}}),f=Nt.create(this,this.state,[]),d=!1;f.flags|=a,e?e.flags|=a:e=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),d=this.docView.update(f),d&&this.docViewUpdate());for(let u=0;u<h.length;u++)if(c[u]!=Fi)try{let g=h[u];g.write&&g.write(c[u],this)}catch(g){K(this.state,g)}if(d&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,r=-1;continue}else{let g=(o<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(o).top)-r;if(g>1||g<-1){s=s+g,i.scrollTop=s/this.scaleY,r=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Fe))l(e)}get themeClasses(){return je+" "+(this.state.facet(_e)?js:_s)+" "+this.state.facet(Qt)}updateAttrs(){let t=Ii(this,Cs,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet($)?"true":"false",class:"cm-content",style:`${w.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),Ii(this,si,e);let i=this.observer.ignore(()=>{let s=gi(this.contentDOM,this.contentAttrs,e),o=gi(this.dom,this.editorAttrs,t);return s||o});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(M.announce)){e&&(this.announceDOM.textContent=""),e=!1;let o=this.announceDOM.appendChild(document.createElement("div"));o.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Mt);let t=this.state.facet(M.cspNonce);mt.StyleModule.mount(this.root,this.styleModules.concat(Wo).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.plugin!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Me(this,t,vi(this,t,e,i))}moveByGroup(t,e){return Me(this,t,vi(this,t,e,i=>Qn(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),o=i[e?i.length-1:0];return p.EditorSelection.cursor(o.side(e,s)+t.from,o.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return Un(this,t,e,i)}moveVertically(t,e,i){return Me(this,t,Jn(this,t,e,i))}domAtPos(t,e=1){return this.docView.domAtPos(t,e)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){this.readMeasured();let i=Ke(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=!0){return this.readMeasured(),Ke(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),o=this.bidiSpans(s),r=o[G.find(o,t-s.from,-1,e)];return Pt(i,r.dir==exports.Direction.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(ws)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>zo)return fs(t.length);let e=this.textDirectionAt(t.from),i;for(let o of this.bidiCache)if(o.from==t.from&&o.dir==e&&(o.fresh||cs(o.isolates,i=yi(this,t))))return o.order;i||(i=yi(this,t));let s=Cn(t.text,e,i);return this.bidiCache.push(new fe(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||w.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{ns(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return jt.of(new gt(typeof t=="number"?p.EditorSelection.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return jt.of(new gt(p.EditorSelection.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return L.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return L.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=mt.StyleModule.newName(),s=[Qt.of(i),Mt.of(Ge(`.${i}`,t))];return e&&e.dark&&s.push(_e.of(!0)),s}static baseTheme(t){return p.Prec.lowest(Mt.of(Ge("."+je,t,Gs)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&B.get(i)||B.get(t);return((e=s?.root)===null||e===void 0?void 0:e.view)||null}}M.styleModule=Mt;M.inputHandler=bs;M.clipboardInputFilter=ei;M.clipboardOutputFilter=ii;M.scrollHandler=Ss;M.focusChangeEffect=ys;M.perLineTextDirection=ws;M.exceptionSink=ms;M.updateListener=Fe;M.editable=$;M.mouseSelectionStyle=gs;M.dragMovesSelection=ps;M.clickAddsSelectionRange=us;M.decorations=Wt;M.blockWrappers=Ms;M.outerDecorations=ks;M.atomicRanges=zt;M.bidiIsolatedRanges=As;M.scrollMargins=Ts;M.darkTheme=_e;M.cspNonce=p.Facet.define({combine:n=>n.length?n[0]:""});M.contentAttributes=si;M.editorAttributes=Cs;M.lineWrapping=M.contentAttributes.of({class:"cm-lineWrapping"});M.announce=p.StateEffect.define();const zo=4096,Fi={};class fe{constructor(t,e,i,s,o,r){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=o,this.order=r}static update(t,e){if(e.empty&&!t.some(o=>o.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:exports.Direction.LTR;for(let o=Math.max(0,t.length-10);o<t.length;o++){let r=t[o];r.dir==s&&!e.touchesRange(r.from,r.to)&&i.push(new fe(e.mapPos(r.from,1),e.mapPos(r.to,-1),r.dir,r.isolates,!1,r.order))}return i}}function Ii(n,t,e){for(let i=n.state.facet(t),s=i.length-1;s>=0;s--){let o=i[s],r=typeof o=="function"?o(n):o;r&&Je(r,e)}return e}const Ko=w.mac?"mac":w.windows?"win":w.linux?"linux":"key";function qo(n,t){const e=n.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let s,o,r,l;for(let a=0;a<e.length-1;++a){const h=e[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))s=!0;else if(/^(c|ctrl|control)$/i.test(h))o=!0;else if(/^s(hift)?$/i.test(h))r=!0;else if(/^mod$/i.test(h))t=="mac"?l=!0:o=!0;else throw new Error("Unrecognized modifier name: "+h)}return s&&(i="Alt-"+i),o&&(i="Ctrl-"+i),l&&(i="Meta-"+i),r&&(i="Shift-"+i),i}function Jt(n,t,e){return t.altKey&&(n="Alt-"+n),t.ctrlKey&&(n="Ctrl-"+n),t.metaKey&&(n="Meta-"+n),e!==!1&&t.shiftKey&&(n="Shift-"+n),n}const _o=p.Prec.default(M.domEventHandlers({keydown(n,t){return $s(Xs(t.state),n,t,"editor")}})),Ys=p.Facet.define({enables:_o}),zi=new WeakMap;function Xs(n){let t=n.facet(Ys),e=zi.get(t);return e||zi.set(t,e=Yo(t.reduce((i,s)=>i.concat(s),[]))),e}function jo(n,t,e){return $s(Xs(n.state),t,n,e)}let tt=null;const Go=4e3;function Yo(n,t=Ko){let e=Object.create(null),i=Object.create(null),s=(r,l)=>{let a=i[r];if(a==null)i[r]=l;else if(a!=l)throw new Error("Key binding "+r+" is used both as a regular binding and as a multi-stroke prefix")},o=(r,l,a,h,c)=>{var f,d;let u=e[r]||(e[r]=Object.create(null)),g=l.split(/ (?!$)/).map(y=>qo(y,t));for(let y=1;y<g.length;y++){let x=g.slice(0,y).join(" ");s(x,!0),u[x]||(u[x]={preventDefault:!0,stopPropagation:!1,run:[C=>{let k=tt={view:C,prefix:x,scope:r};return setTimeout(()=>{tt==k&&(tt=null)},Go),!0}]})}let m=g.join(" ");s(m,!1);let b=u[m]||(u[m]={preventDefault:!1,stopPropagation:!1,run:((d=(f=u._any)===null||f===void 0?void 0:f.run)===null||d===void 0?void 0:d.slice())||[]});a&&b.run.push(a),h&&(b.preventDefault=!0),c&&(b.stopPropagation=!0)};for(let r of n){let l=r.scope?r.scope.split(" "):["editor"];if(r.any)for(let h of l){let c=e[h]||(e[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=r;for(let d in c)c[d].run.push(u=>f(u,Ye))}let a=r[t]||r.key;if(a)for(let h of l)o(h,a,r.run,r.preventDefault,r.stopPropagation),r.shift&&o(h,"Shift-"+a,r.shift,r.preventDefault,r.stopPropagation)}return e}let Ye=null;function $s(n,t,e,i){Ye=t;let s=ye.keyName(t),o=p.codePointAt(s,0),r=p.codePointSize(o)==s.length&&s!=" ",l="",a=!1,h=!1,c=!1;tt&&tt.view==e&&tt.scope==i&&(l=tt.prefix+" ",Ws.indexOf(t.keyCode)<0&&(h=!0,tt=null));let f=new Set,d=b=>{if(b){for(let y of b.run)if(!f.has(y)&&(f.add(y),y(e)))return b.stopPropagation&&(c=!0),!0;b.preventDefault&&(b.stopPropagation&&(c=!0),h=!0)}return!1},u=n[i],g,m;return u&&(d(u[l+Jt(s,t,!r)])?a=!0:r&&(t.altKey||t.metaKey||t.ctrlKey)&&!(w.windows&&t.ctrlKey&&t.altKey)&&!(w.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(g=ye.base[t.keyCode])&&g!=s?(d(u[l+Jt(g,t,!0)])||t.shiftKey&&(m=ye.shift[t.keyCode])!=s&&m!=g&&d(u[l+Jt(m,t,!1)]))&&(a=!0):r&&t.shiftKey&&d(u[l+Jt(s,t,!0)])&&(a=!0),!a&&d(u._any)&&(a=!0)),h&&(a=!0),a&&c&&t.stopPropagation(),Ye=null,a}class vt{constructor(t,e,i,s,o){this.className=t,this.left=e,this.top=i,this.width=s,this.height=o}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let o=Us(t);return[new vt(e,s.left-o.left,s.top-o.top,null,s.bottom-s.top)]}else return Xo(t,e,i)}}function Us(n){let t=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==exports.Direction.LTR?t.left:t.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:t.top-n.scrollDOM.scrollTop*n.scaleY}}function Ki(n,t,e,i){let s=n.coordsAtPos(t,e*2);if(!s)return i;let o=n.dom.getBoundingClientRect(),r=(s.top+s.bottom)/2,l=n.posAtCoords({x:o.left+1,y:r}),a=n.posAtCoords({x:o.right-1,y:r});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function Xo(n,t,e){if(e.to<=n.viewport.from||e.from>=n.viewport.to)return[];let i=Math.max(e.from,n.viewport.from),s=Math.min(e.to,n.viewport.to),o=n.textDirection==exports.Direction.LTR,r=n.contentDOM,l=r.getBoundingClientRect(),a=Us(n),h=r.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),d=l.right-(c?parseInt(c.paddingRight):0),u=ze(n,i,1),g=ze(n,s,-1),m=u.type==exports.BlockType.Text?u:null,b=g.type==exports.BlockType.Text?g:null;if(m&&(n.lineWrapping||u.widgetLineBreaks)&&(m=Ki(n,i,1,m)),b&&(n.lineWrapping||g.widgetLineBreaks)&&(b=Ki(n,s,-1,b)),m&&b&&m.from==b.from&&m.to==b.to)return x(C(e.from,e.to,m));{let v=m?C(e.from,null,m):k(u,!1),S=b?C(null,e.to,b):k(g,!0),D=[];return(m||u).to<(b||g).from-(m&&b?1:0)||u.widgetLineBreaks>1&&v.bottom+n.defaultLineHeight/2<S.top?D.push(y(f,v.bottom,d,S.top)):v.bottom<S.top&&n.elementAtHeight((v.bottom+S.top)/2).type==exports.BlockType.Text&&(v.bottom=S.top=(v.bottom+S.top)/2),x(v).concat(D).concat(x(S))}function y(v,S,D,E){return new vt(t,v-a.left,S-a.top,D-v,E-S)}function x({top:v,bottom:S,horizontal:D}){let E=[];for(let J=0;J<D.length;J+=2)E.push(y(D[J],v,D[J+1],S));return E}function C(v,S,D){let E=1e9,J=-1e9,Kt=[];function di(nt,Z,ct,ot,Ct){let Y=n.coordsAtPos(nt,nt==D.to?-2:2),X=n.coordsAtPos(ct,ct==D.from?2:-2);!Y||!X||(E=Math.min(Y.top,X.top,E),J=Math.max(Y.bottom,X.bottom,J),Ct==exports.Direction.LTR?Kt.push(o&&Z?f:Y.left,o&&ot?d:X.right):Kt.push(!o&&ot?f:X.left,!o&&Z?d:Y.right))}let qt=v??D.from,_t=S??D.to;for(let nt of n.visibleRanges)if(nt.to>qt&&nt.from<_t)for(let Z=Math.max(nt.from,qt),ct=Math.min(nt.to,_t);;){let ot=n.state.doc.lineAt(Z);for(let Ct of n.bidiSpans(ot)){let Y=Ct.from+ot.from,X=Ct.to+ot.from;if(Y>=ct)break;X>Z&&di(Math.max(Y,Z),v==null&&Y<=qt,Math.min(X,ct),S==null&&X>=_t,Ct.dir)}if(Z=ot.to+1,Z>=ct)break}return Kt.length==0&&di(qt,v==null,_t,S==null,n.textDirection),{top:E,bottom:J,horizontal:Kt}}function k(v,S){let D=l.top+(S?v.top:v.bottom);return{top:D,bottom:D,horizontal:[]}}}function $o(n,t){return n.constructor==t.constructor&&n.eq(t)}class Uo{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(ne)!=t.state.facet(ne)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(ne);for(;e<i.length&&i[e]!=this.layer;)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;(t!=this.scaleX||e!=this.scaleY)&&(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some((e,i)=>!$o(e,this.drawn[i]))){let e=this.dom.firstChild,i=0;for(let s of t)s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(s.draw(),e);for(;e;){let s=e.nextSibling;e.remove(),e=s}this.drawn=t,w.safari&&w.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const ne=p.Facet.define();function ai(n){return[L.define(t=>new Uo(t,n)),ne.of(n)]}const Vt=p.Facet.define({combine(n){return p.combineConfig(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function Qo(n={}){return[Vt.of(n),Jo,Zo,tr,xs.of(!0)]}function Qs(n){return n.startState.facet(Vt)!=n.state.facet(Vt)}const Jo=ai({above:!0,markers(n){let{state:t}=n,e=t.facet(Vt),i=[];for(let s of t.selection.ranges){let o=s==t.selection.main;if(s.empty||e.drawRangeCursor){let r=o?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:p.EditorSelection.cursor(s.head,s.head>s.anchor?-1:1);for(let a of vt.forRange(n,r,l))i.push(a)}}return i},update(n,t){n.transactions.some(i=>i.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let e=Qs(n);return e&&qi(n.state,t),n.docChanged||n.selectionSet||e},mount(n,t){qi(t.state,n)},class:"cm-cursorLayer"});function qi(n,t){t.style.animationDuration=n.facet(Vt).cursorBlinkRate+"ms"}const Zo=ai({above:!1,markers(n){return n.state.selection.ranges.map(t=>t.empty?[]:vt.forRange(n,"cm-selectionBackground",t)).reduce((t,e)=>t.concat(e))},update(n,t){return n.docChanged||n.selectionSet||n.viewportChanged||Qs(n)},class:"cm-selectionLayer"}),tr=p.Prec.highest(M.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),Js=p.StateEffect.define({map(n,t){return n==null?null:t.mapPos(n)}}),Tt=p.StateField.define({create(){return null},update(n,t){return n!=null&&(n=t.changes.mapPos(n)),t.effects.reduce((e,i)=>i.is(Js)?i.value:e,n)}}),er=L.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var t;let e=n.state.field(Tt);e==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(Tt)!=e||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,t=n.state.field(Tt),e=t!=null&&n.coordsAtPos(t);if(!e)return null;let i=n.scrollDOM.getBoundingClientRect();return{left:e.left-i.left+n.scrollDOM.scrollLeft*n.scaleX,top:e.top-i.top+n.scrollDOM.scrollTop*n.scaleY,height:e.bottom-e.top}}drawCursor(n){if(this.cursor){let{scaleX:t,scaleY:e}=this.view;n?(this.cursor.style.left=n.left/t+"px",this.cursor.style.top=n.top/e+"px",this.cursor.style.height=n.height/e+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(Tt)!=n&&this.view.dispatch({effects:Js.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function ir(){return[Tt,er]}function _i(n,t,e,i,s){t.lastIndex=0;for(let o=n.iterRange(e,i),r=e,l;!o.next().done;r+=o.value.length)if(!o.lineBreak)for(;l=t.exec(o.value);)s(r+l.index,l)}function sr(n,t){let e=n.visibleRanges;if(e.length==1&&e[0].from==n.viewport.from&&e[0].to==n.viewport.to)return e;let i=[];for(let{from:s,to:o}of e)s=Math.max(n.state.doc.lineAt(s).from,s-t),o=Math.min(n.state.doc.lineAt(o).to,o+t),i.length&&i[i.length-1].to>=s?i[i.length-1].to=o:i.push({from:s,to:o});return i}class Zs{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:o,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,s)this.addMatch=(l,a,h,c)=>s(c,h,h+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,h,c)=>{let f=i(l,a,h);f&&c(h,h+l[0].length,f)};else if(i)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=o,this.maxLength=r}createDeco(t){let e=new p.RangeSetBuilder,i=e.add.bind(e);for(let{from:s,to:o}of sr(t,this.maxLength))_i(t.state.doc,this.regexp,s,o,(r,l)=>this.addMatch(l,t,r,i));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges((o,r,l,a)=>{a>=t.view.viewport.from&&l<=t.view.viewport.to&&(i=Math.min(l,i),s=Math.max(a,s))}),t.viewportMoved||s-i>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let o of t.visibleRanges){let r=Math.max(o.from,i),l=Math.min(o.to,s);if(l>=r){let a=t.state.doc.lineAt(r),h=a.to<l?t.state.doc.lineAt(l):a,c=Math.max(o.from,a.from),f=Math.min(o.to,h.to);if(this.boundary){for(;r>a.from;r--)if(this.boundary.test(a.text[r-1-a.from])){c=r;break}for(;l<h.to;l++)if(this.boundary.test(h.text[l-h.from])){f=l;break}}let d=[],u,g=(m,b,y)=>d.push(y.range(m,b));if(a==h)for(this.regexp.lastIndex=c-a.from;(u=this.regexp.exec(a.text))&&u.index<f-a.from;)this.addMatch(u,t,u.index+a.from,g);else _i(t.state.doc,this.regexp,c,f,(m,b)=>this.addMatch(b,t,m,g));e=e.update({filterFrom:c,filterTo:f,filter:(m,b)=>m<c||b>f,add:d})}}return e}}const Xe=/x/.unicode!=null?"gu":"g",nr=new RegExp(`[\0-\b
5
- --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Xe),or={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Te=null;function rr(){var n;if(Te==null&&typeof document<"u"&&document.body){let t=document.body.style;Te=((n=t.tabSize)!==null&&n!==void 0?n:t.MozTabSize)!=null}return Te||!1}const oe=p.Facet.define({combine(n){let t=p.combineConfig(n,{render:null,specialChars:nr,addSpecialChars:null});return(t.replaceTabs=!rr())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,Xe)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,Xe)),t}});function lr(n={}){return[oe.of(n),ar()]}let ji=null;function ar(){return ji||(ji=L.fromClass(class{constructor(n){this.view=n,this.decorations=O.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(oe)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new Zs({regexp:n.specialChars,decoration:(t,e,i)=>{let{doc:s}=e.state,o=p.codePointAt(t[0],0);if(o==9){let r=s.lineAt(i),l=e.state.tabSize,a=p.countColumn(r.text,l,i-r.from);return O.replace({widget:new dr((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[o]||(this.decorationCache[o]=O.replace({widget:new fr(n,o)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let t=n.state.facet(oe);n.startState.facet(oe)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const hr="•";function cr(n){return n>=32?hr:n==10?"␤":String.fromCharCode(9216+n)}class fr extends st{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=cr(this.code),i=t.state.phrase("Control character")+" "+(or[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let o=document.createElement("span");return o.textContent=e,o.title=i,o.setAttribute("aria-label",i),o.className="cm-specialChar",o}ignoreEvent(){return!1}}class dr extends st{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function ur(){return gr}const pr=O.line({class:"cm-activeLine"}),gr=L.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let t=-1,e=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>t&&(e.push(pr.range(s.from)),t=s.from)}return O.set(e)}},{decorations:n=>n.decorations});class mr extends st{constructor(t){super(),this.content=t}toDOM(t){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(t):this.content.cloneNode(!0)),e.setAttribute("aria-hidden","true"),e}coordsAt(t){let e=t.firstChild?Dt(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=Pt(e[0],i.direction!="rtl"),o=parseInt(i.lineHeight);return s.bottom-s.top>o*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+o}:s}ignoreEvent(){return!1}}function br(n){let t=L.fromClass(class{constructor(e){this.view=e,this.placeholder=n?O.set([O.widget({widget:new mr(n),side:1}).range(0)]):O.none}get decorations(){return this.view.state.doc.length?O.none:this.placeholder}},{decorations:e=>e.decorations});return typeof n=="string"?[t,M.contentAttributes.of({"aria-placeholder":n})]:t}const $e=2e3;function yr(n,t,e){let i=Math.min(t.line,e.line),s=Math.max(t.line,e.line),o=[];if(t.off>$e||e.off>$e||t.col<0||e.col<0){let r=Math.min(t.off,e.off),l=Math.max(t.off,e.off);for(let a=i;a<=s;a++){let h=n.doc.line(a);h.length<=l&&o.push(p.EditorSelection.range(h.from+r,h.to+l))}}else{let r=Math.min(t.col,e.col),l=Math.max(t.col,e.col);for(let a=i;a<=s;a++){let h=n.doc.line(a),c=p.findColumn(h.text,r,n.tabSize,!0);if(c<0)o.push(p.EditorSelection.cursor(h.to));else{let f=p.findColumn(h.text,l,n.tabSize);o.push(p.EditorSelection.range(h.from+c,h.from+f))}}}return o}function wr(n,t){let e=n.coordsAtPos(n.viewport.from);return e?Math.round(Math.abs((e.left-t)/n.defaultCharacterWidth)):-1}function Gi(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1),i=n.state.doc.lineAt(e),s=e-i.from,o=s>$e?-1:s==i.length?wr(n,t.clientX):p.countColumn(i.text,n.state.tabSize,e-i.from);return{line:i.number,col:o,off:s}}function xr(n,t){let e=Gi(n,t),i=n.state.selection;return e?{update(s){if(s.docChanged){let o=s.changes.mapPos(s.startState.doc.line(e.line).from),r=s.state.doc.lineAt(o);e={line:r.number,col:e.col,off:Math.min(e.off,r.length)},i=i.map(s.changes)}},get(s,o,r){let l=Gi(n,s);if(!l)return i;let a=yr(n.state,e,l);return a.length?r?p.EditorSelection.create(a.concat(i.ranges)):p.EditorSelection.create(a):i}}:null}function Sr(n){let t=(e=>e.altKey&&e.button==0);return M.mouseSelectionStyle.of((e,i)=>t(i)?xr(e,i):null)}const vr={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},Cr={style:"cursor: crosshair"};function Mr(n={}){let[t,e]=vr[n.key||"Alt"],i=L.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==t||e(s))},keyup(s){(s.keyCode==t||!e(s))&&this.set(!1)},mousemove(s){this.set(e(s))}}});return[i,M.contentAttributes.of(s=>{var o;return!((o=s.plugin(i))===null||o===void 0)&&o.isDown?Cr:null})]}const Zt="-10000px";class tn{constructor(t,e,i,s){this.facet=e,this.createTooltipView=i,this.removeTooltipView=s,this.input=t.state.facet(e),this.tooltips=this.input.filter(r=>r);let o=null;this.tooltipViews=this.tooltips.map(r=>o=i(r,o))}update(t,e){var i;let s=t.state.facet(this.facet),o=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(t);return!1}let r=[],l=e?[]:null;for(let a=0;a<o.length;a++){let h=o[a],c=-1;if(h){for(let f=0;f<this.tooltips.length;f++){let d=this.tooltips[f];d&&d.create==h.create&&(c=f)}if(c<0)r[a]=this.createTooltipView(h,a?r[a-1]:null),l&&(l[a]=!!h.above);else{let f=r[a]=this.tooltipViews[c];l&&(l[a]=e[c]),f.update&&f.update(t)}}}for(let a of this.tooltipViews)r.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return e&&(l.forEach((a,h)=>e[h]=a),e.length=l.length),this.input=s,this.tooltips=o,this.tooltipViews=r,!0}}function kr(n){let t=n.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:t.clientHeight,right:t.clientWidth}}const De=p.Facet.define({combine:n=>{var t,e,i;return{position:w.ios?"absolute":((t=n.find(s=>s.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=n.find(s=>s.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||kr}}}),Yi=new WeakMap,hi=L.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=n.state.facet(De);this.position=t.position,this.parent=t.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new tn(n,ci,(e,i)=>this.createTooltip(e,i),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(n,this.above);t&&this.observeIntersection();let e=t||n.geometryChanged,i=n.state.facet(De);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;e=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(n,t){let e=n.create(this.view),i=t?t.dom:null;if(e.dom.classList.add("cm-tooltip"),n.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",e.dom.appendChild(s)}return e.dom.style.position=this.position,e.dom.style.top=Zt,e.dom.style.left="0px",this.container.insertBefore(e.dom,i),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var n,t,e;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=1,t=1,e=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:o}=this.manager.tooltipViews[0];if(w.safari){let r=o.getBoundingClientRect();e=Math.abs(r.top+1e4)>1||Math.abs(r.left)>1}else e=!!o.offsetParent&&o.offsetParent!=this.container.ownerDocument.body}if(e||this.position=="absolute")if(this.parent){let o=this.parent.getBoundingClientRect();o.width&&o.height&&(n=o.width/this.parent.offsetWidth,t=o.height/this.parent.offsetHeight)}else({scaleX:n,scaleY:t}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),s=ni(this.view);return{visible:{left:i.left+s.left,top:i.top+s.top,right:i.right-s.right,bottom:i.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((o,r)=>{let l=this.manager.tooltipViews[r];return l.getCoords?l.getCoords(o.pos):this.view.coordsAtPos(o.pos)}),size:this.manager.tooltipViews.map(({dom:o})=>o.getBoundingClientRect()),space:this.view.state.facet(De).tooltipSpace(this.view),scaleX:n,scaleY:t,makeAbsolute:e}}writeMeasure(n){var t;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:e,space:i,scaleX:s,scaleY:o}=n,r=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,f=n.pos[l],d=n.size[l];if(!f||a.clip!==!1&&(f.bottom<=Math.max(e.top,i.top)||f.top>=Math.min(e.bottom,i.bottom)||f.right<Math.max(e.left,i.left)-.1||f.left>Math.min(e.right,i.right)+.1)){c.style.top=Zt;continue}let u=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,g=u?7:0,m=d.right-d.left,b=(t=Yi.get(h))!==null&&t!==void 0?t:d.bottom-d.top,y=h.offset||Tr,x=this.view.textDirection==exports.Direction.LTR,C=d.width>i.right-i.left?x?i.left:i.right-d.width:x?Math.max(i.left,Math.min(f.left-(u?14:0)+y.x,i.right-m)):Math.min(Math.max(i.left,f.left-m+(u?14:0)-y.x),i.right-m),k=this.above[l];!a.strictSide&&(k?f.top-b-g-y.y<i.top:f.bottom+b+g+y.y>i.bottom)&&k==i.bottom-f.bottom>f.top-i.top&&(k=this.above[l]=!k);let v=(k?f.top-i.top:i.bottom-f.bottom)-g;if(v<b&&h.resize!==!1){if(v<this.view.defaultLineHeight){c.style.top=Zt;continue}Yi.set(h,b),c.style.height=(b=v)/o+"px"}else c.style.height&&(c.style.height="");let S=k?f.top-b-g-y.y:f.bottom+g+y.y,D=C+m;if(h.overlap!==!0)for(let E of r)E.left<D&&E.right>C&&E.top<S+b&&E.bottom>S&&(S=k?E.top-b-2-g:E.bottom+g+2);if(this.position=="absolute"?(c.style.top=(S-n.parent.top)/o+"px",Xi(c,(C-n.parent.left)/s)):(c.style.top=S/o+"px",Xi(c,C/s)),u){let E=f.left+(x?y.x:-y.x)-(C+14-7);u.style.left=E/s+"px"}h.overlap!==!0&&r.push({left:C,top:S,right:D,bottom:S+b}),c.classList.toggle("cm-tooltip-above",k),c.classList.toggle("cm-tooltip-below",!k),h.positioned&&h.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=Zt}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Xi(n,t){let e=parseInt(n.style.left,10);(isNaN(e)||Math.abs(t-e)>1)&&(n.style.left=t+"px")}const Ar=M.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Tr={x:0,y:0},ci=p.Facet.define({enables:[hi,Ar]}),de=p.Facet.define({combine:n=>n.reduce((t,e)=>t.concat(e),[])});class be{static create(t){return new be(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new tn(t,de,(e,i)=>this.createHostedView(e,i),e=>e.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)(t=e.destroy)===null||t===void 0||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let s=i[t];if(s!==void 0){if(e===void 0)e=s;else if(e!==s)return}}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Dr=ci.compute([de],n=>{let t=n.facet(de);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var i;return(i=e.end)!==null&&i!==void 0?i:e.pos})),create:be.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class Or{constructor(t,e,i,s,o){this.view=t,this.source=e,this.field=i,this.setHover=s,this.hoverTime=o,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:e}=this,i=t.docView.tile.nearest(e.target);if(!i)return;let s,o=1;if(i.isWidget())s=i.posAtStart;else{if(s=t.posAtCoords(e),s==null)return;let l=t.coordsAtPos(s);if(!l||e.y<l.top||e.y>l.bottom||e.x<l.left-t.defaultCharacterWidth||e.x>l.right+t.defaultCharacterWidth)return;let a=t.bidiSpans(t.state.doc.lineAt(s)).find(c=>c.from<=s&&c.to>=s),h=a&&a.dir==exports.Direction.RTL?-1:1;o=e.x<l.left?-h:h}let r=this.source(t,s,o);if(r?.then){let l=this.pending={pos:s};r.then(a=>{this.pending==l&&(this.pending=null,a&&!(Array.isArray(a)&&!a.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(a)?a:[a])}))},a=>K(t.state,a,"hover tooltip"))}else r&&!(Array.isArray(r)&&!r.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(r)?r:[r])})}get tooltip(){let t=this.view.plugin(hi),e=t?t.manager.tooltips.findIndex(i=>i.create==be.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:o}=this;if(s.length&&o&&!Br(o.dom,t)||this.pending){let{pos:r}=s[0]||this.pending,l=(i=(e=s[0])===null||e===void 0?void 0:e.end)!==null&&i!==void 0?i:r;(r==l?this.view.posAtCoords(this.lastMove)!=r:!Er(this.view,r,l,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:i}=this;i&&i.dom.contains(t.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const te=4;function Br(n,t){let{left:e,right:i,top:s,bottom:o}=n.getBoundingClientRect(),r;if(r=n.querySelector(".cm-tooltip-arrow")){let l=r.getBoundingClientRect();s=Math.min(l.top,s),o=Math.max(l.bottom,o)}return t.clientX>=e-te&&t.clientX<=i+te&&t.clientY>=s-te&&t.clientY<=o+te}function Er(n,t,e,i,s,o){let r=n.scrollDOM.getBoundingClientRect(),l=n.documentTop+n.documentPadding.top+n.contentHeight;if(r.left>i||r.right<i||r.top>s||Math.min(r.bottom,l)<s)return!1;let a=n.posAtCoords({x:i,y:s},!1);return a>=t&&a<=e}function Rr(n,t={}){let e=p.StateEffect.define(),i=p.StateField.define({create(){return[]},update(s,o){if(s.length&&(t.hideOnChange&&(o.docChanged||o.selection)?s=[]:t.hideOn&&(s=s.filter(r=>!t.hideOn(o,r))),o.docChanged)){let r=[];for(let l of s){let a=o.changes.mapPos(l.pos,-1,p.MapMode.TrackDel);if(a!=null){let h=Object.assign(Object.create(null),l);h.pos=a,h.end!=null&&(h.end=o.changes.mapPos(h.end)),r.push(h)}}s=r}for(let r of o.effects)r.is(e)&&(s=r.value),r.is(Pr)&&(s=[]);return s},provide:s=>de.from(s)});return{active:i,extension:[i,L.define(s=>new Or(s,n,i,e,t.hoverTime||300)),Dr]}}function Lr(n,t){let e=n.plugin(hi);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}const Pr=p.StateEffect.define(),$i=p.Facet.define({combine(n){let t,e;for(let i of n)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function Hr(n,t){let e=n.plugin(en),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const en=L.fromClass(class{constructor(n){this.input=n.state.facet(Ue),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(n));let t=n.state.facet($i);this.top=new ee(n,!0,t.topContainer),this.bottom=new ee(n,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(n){let t=n.state.facet($i);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new ee(n.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new ee(n.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=n.state.facet(Ue);if(e!=this.input){let i=e.filter(a=>a),s=[],o=[],r=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(n.view),l.push(c)):(c=this.panels[h],c.update&&c.update(n)),s.push(c),(c.top?o:r).push(c)}this.specs=i,this.panels=s,this.top.sync(o),this.bottom.sync(r);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>M.scrollMargins.of(t=>{let e=t.plugin(n);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class ee{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=Ui(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Ui(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function Ui(n){let t=n.nextSibling;return n.remove(),t}const Ue=p.Facet.define({enables:en});class Q extends p.RangeValue{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Q.prototype.elementClass="";Q.prototype.toDOM=void 0;Q.prototype.mapMode=p.MapMode.TrackBefore;Q.prototype.startSide=Q.prototype.endSide=-1;Q.prototype.point=!0;const Et=p.Facet.define(),sn=p.Facet.define(),Wr={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>p.RangeSet.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Rt=p.Facet.define();function Nr(n){return[fi(),Rt.of({...Wr,...n})]}const Qi=p.Facet.define({combine:n=>n.some(t=>t)});function fi(n){return[Vr]}const Vr=L.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(Rt).map(t=>new Zi(n,t)),this.fixed=!n.state.facet(Qi);for(let t of this.gutters)t.config.side=="after"?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let t=this.prevViewport,e=n.view.viewport,i=Math.min(t.to,e.to)-Math.max(t.from,e.from);this.syncGutters(i<(e.to-e.from)*.8)}if(n.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Qi)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let t=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let e=p.RangeSet.iter(this.view.state.facet(Et),this.view.viewport.from),i=[],s=this.gutters.map(o=>new Fr(o,this.view.viewport,-this.view.documentPadding.top));for(let o of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(o.type)){let r=!0;for(let l of o.type)if(l.type==exports.BlockType.Text&&r){Qe(e,i,l.from);for(let a of s)a.line(this.view,l,i);r=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(o.type==exports.BlockType.Text){Qe(e,i,o.from);for(let r of s)r.line(this.view,o,i)}else if(o.widget)for(let r of s)r.widget(this.view,o);for(let o of s)o.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let t=n.startState.facet(Rt),e=n.state.facet(Rt),i=n.docChanged||n.heightChanged||n.viewportChanged||!p.RangeSet.eq(n.startState.facet(Et),n.state.facet(Et),n.view.viewport.from,n.view.viewport.to);if(t==e)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let o of e){let r=t.indexOf(o);r<0?s.push(new Zi(this.view,o)):(this.gutters[r].update(n),s.push(this.gutters[r]))}for(let o of this.gutters)o.dom.remove(),s.indexOf(o)<0&&o.destroy();for(let o of s)o.config.side=="after"?this.getDOMAfter().appendChild(o.dom):this.dom.appendChild(o.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>M.scrollMargins.of(t=>{let e=t.plugin(n);if(!e||e.gutters.length==0||!e.fixed)return null;let i=e.dom.offsetWidth*t.scaleX,s=e.domAfter?e.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==exports.Direction.LTR?{left:i,right:s}:{right:i,left:s}})});function Ji(n){return Array.isArray(n)?n:[n]}function Qe(n,t,e){for(;n.value&&n.from<=e;)n.from==e&&t.push(n.value),n.next()}class Fr{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=p.RangeSet.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,o=(e.top-this.height)/t.scaleY,r=e.height/t.scaleY;if(this.i==s.elements.length){let l=new nn(t,r,o,i);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(t,r,o,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];Qe(this.cursor,s,e.from),i.length&&(s=s.concat(i));let o=this.gutter.config.lineMarker(t,e,s);o&&s.unshift(o);let r=this.gutter;s.length==0&&!r.config.renderEmptyElements||this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),s=i?[i]:null;for(let o of t.state.facet(sn)){let r=o(t,e.widget,e);r&&(s||(s=[])).push(r)}s&&this.addElement(t,e,s)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Zi{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,s=>{let o=s.target,r;if(o!=this.dom&&this.dom.contains(o)){for(;o.parentNode!=this.dom;)o=o.parentNode;let a=o.getBoundingClientRect();r=(a.top+a.bottom)/2}else r=s.clientY;let l=t.lineBlockAtHeight(r-t.documentTop);e.domEventHandlers[i](t,l,s)&&s.preventDefault()});this.markers=Ji(e.markers(t)),e.initialSpacer&&(this.spacer=new nn(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=Ji(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],t);s!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[s])}let i=t.view.viewport;return!p.RangeSet.eq(this.markers,e,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class nn{constructor(t,e,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,s)}update(t,e,i,s){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),Ir(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let o=0,r=0;;){let l=r,a=o<e.length?e[o++]:null,h=!1;if(a){let c=a.elementClass;c&&(i+=" "+c);for(let f=r;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,h=!0;break}}else l=this.markers.length;for(;r<l;){let c=this.markers[r++];if(c.toDOM){c.destroy(s);let f=s.nextSibling;s.remove(),s=f}}if(!a)break;a.toDOM&&(h?s=s.nextSibling:this.dom.insertBefore(a.toDOM(t),s)),h&&r++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}function Ir(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++)if(!n[e].compare(t[e]))return!1;return!0}const on=p.Facet.define(),rn=p.Facet.define(),dt=p.Facet.define({combine(n){return p.combineConfig(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let s in e){let o=i[s],r=e[s];i[s]=o?(l,a,h)=>o(l,a,h)||r(l,a,h):r}return i}})}});class Oe extends Q{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Be(n,t){return n.state.facet(dt).formatNumber(t,n.state)}const zr=Rt.compute([dt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(on)},lineMarker(t,e,i){return i.some(s=>s.toDOM)?null:new Oe(Be(t,t.state.doc.lineAt(e.from).number))},widgetMarker:(t,e,i)=>{for(let s of t.state.facet(rn)){let o=s(t,e,i);if(o)return o}return null},lineMarkerChange:t=>t.startState.facet(dt)!=t.state.facet(dt),initialSpacer(t){return new Oe(Be(t,ts(t.state.doc.lines)))},updateSpacer(t,e){let i=Be(e.view,ts(e.view.state.doc.lines));return i==t.number?t:new Oe(i)},domEventHandlers:n.facet(dt).domEventHandlers,side:"before"}));function Kr(n={}){return[dt.of(n),fi(),zr]}function ts(n){let t=9;for(;t<n;)t=t*10+9;return t}const qr=new class extends Q{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},_r=Et.compute(["selection"],n=>{let t=[],e=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>e&&(e=s,t.push(qr.range(s)))}return p.RangeSet.of(t)});function jr(){return _r}exports.BidiSpan=G;exports.BlockInfo=V;exports.BlockWrapper=bt;exports.Decoration=O;exports.EditorView=M;exports.GutterMarker=Q;exports.MatchDecorator=Zs;exports.RectangleMarker=vt;exports.ViewPlugin=L;exports.ViewUpdate=Nt;exports.WidgetType=st;exports.crosshairCursor=Mr;exports.drawSelection=Qo;exports.dropCursor=ir;exports.getPanel=Hr;exports.getTooltip=Lr;exports.gutter=Nr;exports.gutterLineClass=Et;exports.gutterWidgetClass=sn;exports.gutters=fi;exports.highlightActiveLine=ur;exports.highlightActiveLineGutter=jr;exports.highlightSpecialChars=lr;exports.hoverTooltip=Rr;exports.keymap=Ys;exports.layer=ai;exports.lineNumberMarkers=on;exports.lineNumberWidgetMarker=rn;exports.lineNumbers=Kr;exports.logException=K;exports.placeholder=br;exports.rectangularSelection=Sr;exports.runScopeHandlers=jo;exports.showPanel=Ue;exports.showTooltip=ci;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../state/dist/index.js"),yt=require("../../../style-mod/src/style-mod.js"),Se=require("../../../w3c-keyname/index.js"),dt=require("../../../crelt/index.js");let P=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},He=typeof document<"u"?document:{documentElement:{style:{}}};const We=/Edge\/(\d+)/.exec(P.userAgent),rs=/MSIE \d/.test(P.userAgent),Ne=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(P.userAgent),ge=!!(rs||Ne||We),bi=!ge&&/gecko\/(\d+)/i.test(P.userAgent),ve=!ge&&/Chrome\/(\d+)/.exec(P.userAgent),un="webkitFontSmoothing"in He.documentElement.style,Fe=!ge&&/Apple Computer/.test(P.vendor),yi=Fe&&(/Mobile\/\w+/.test(P.userAgent)||P.maxTouchPoints>2);var w={mac:yi||/Mac/.test(P.platform),windows:/Win/.test(P.platform),linux:/Linux|X11/.test(P.platform),ie:ge,ie_version:rs?He.documentMode||6:Ne?+Ne[1]:We?+We[1]:0,gecko:bi,gecko_version:bi?+(/Firefox\/(\d+)/.exec(P.userAgent)||[0,0])[1]:0,chrome:!!ve,chrome_version:ve?+ve[1]:0,ios:yi,android:/Android\b/.test(P.userAgent),webkit_version:un?+(/\bAppleWebKit\/(\d+)/.exec(P.userAgent)||[0,0])[1]:0,safari:Fe,safari_version:Fe?+(/\bVersion\/(\d+(\.\d+)?)/.exec(P.userAgent)||[0,0])[1]:0,tabSize:He.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function ei(n,t){for(let e in n)e=="class"&&t.class?t.class+=" "+n.class:e=="style"&&t.style?t.style+=";"+n.style:t[e]=n[e];return t}const re=Object.create(null);function ii(n,t,e){if(n==t)return!0;n||(n=re),t||(t=re);let i=Object.keys(n),s=Object.keys(t);if(i.length-0!=s.length-0)return!1;for(let o of i)if(o!=e&&(s.indexOf(o)==-1||n[o]!==t[o]))return!1;return!0}function pn(n,t){for(let e=n.attributes.length-1;e>=0;e--){let i=n.attributes[e].name;t[i]==null&&n.removeAttribute(i)}for(let e in t){let i=t[e];e=="style"?n.style.cssText=i:n.getAttribute(e)!=i&&n.setAttribute(e,i)}}function wi(n,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?n.style.cssText=e[s]:n.setAttribute(s,e[s]));return i}function gn(n){let t=Object.create(null);for(let e=0;e<n.attributes.length;e++){let i=n.attributes[e];t[i.name]=i.value}return t}class st{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}exports.BlockType=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(exports.BlockType||(exports.BlockType={}));class O extends u.RangeValue{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new It(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new at(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:o,end:r}=ls(t,e);i=(o?e?-3e8:-1:5e8)-1,s=(r?e?2e8:1:-6e8)+1}return new at(t,i,s,e,t.widget||null,!0)}static line(t){return new zt(t)}static set(t,e=!1){return u.RangeSet.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}O.none=u.RangeSet.empty;class It extends O{constructor(t){let{start:e,end:i}=ls(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?ei(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||re}eq(t){return this==t||t instanceof It&&this.tagName==t.tagName&&ii(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}It.prototype.point=!1;class zt extends O{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof zt&&this.spec.class==t.spec.class&&ii(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}zt.prototype.mapMode=u.MapMode.TrackBefore;zt.prototype.point=!0;class at extends O{constructor(t,e,i,s,o,r){super(e,i,o,t),this.block=s,this.isReplace=r,this.mapMode=s?e<=0?u.MapMode.TrackBefore:u.MapMode.TrackAfter:u.MapMode.TrackDel}get type(){return this.startSide!=this.endSide?exports.BlockType.WidgetRange:this.startSide<=0?exports.BlockType.WidgetBefore:exports.BlockType.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof at&&mn(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}at.prototype.point=!0;function ls(n,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=n;return e==null&&(e=n.inclusive),i==null&&(i=n.inclusive),{start:e??t,end:i??t}}function mn(n,t){return n==t||!!(n&&t&&n.compare(t))}function gt(n,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=n?e[s]=Math.max(e[s],t):e.push(n,t)}class wt extends u.RangeValue{constructor(t,e){super(),this.tagName=t,this.attributes=e}eq(t){return t==this||t instanceof wt&&this.tagName==t.tagName&&ii(this.attributes,t.attributes)}static create(t){return new wt(t.tagName,t.attributes||re)}static set(t,e=!1){return u.RangeSet.of(t,e)}}wt.prototype.startSide=wt.prototype.endSide=-1;function xt(n){let t;return n.nodeType==11?t=n.getSelection?n:n.ownerDocument:t=n,t.getSelection()}function Ve(n,t){return t?n==t||n.contains(t.nodeType!=1?t.parentNode:t):!1}function Bt(n,t){if(!t.anchorNode)return!1;try{return Ve(n,t.anchorNode)}catch{return!1}}function Et(n){return n.nodeType==3?Nt(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Rt(n,t,e,i){return e?xi(n,t,e,i,-1)||xi(n,t,e,i,1):!1}function it(n){for(var t=0;;t++)if(n=n.previousSibling,!n)return t}function le(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function xi(n,t,e,i,s){for(;;){if(n==e&&t==i)return!0;if(t==(s<0?0:U(n))){if(n.nodeName=="DIV")return!1;let o=n.parentNode;if(!o||o.nodeType!=1)return!1;t=it(n)+(s<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[t+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;t=s<0?U(n):0}else return!1}}function U(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Wt(n,t){let e=t?n.left:n.right;return{left:e,right:e,top:n.top,bottom:n.bottom}}function bn(n){let t=n.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function as(n,t){let e=t.width/n.offsetWidth,i=t.height/n.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-n.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-n.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function yn(n,t,e,i,s,o,r,l){let a=n.ownerDocument,h=a.defaultView||window;for(let c=n,f=!1;c&&!f;)if(c.nodeType==1){let d,p=c==a.body,g=1,m=1;if(p)d=bn(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(f=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let x=c.getBoundingClientRect();({scaleX:g,scaleY:m}=as(c,x)),d={left:x.left,right:x.left+c.clientWidth*g,top:x.top,bottom:x.top+c.clientHeight*m}}let b=0,y=0;if(s=="nearest")t.top<d.top?(y=t.top-(d.top+r),e>0&&t.bottom>d.bottom+y&&(y=t.bottom-d.bottom+r)):t.bottom>d.bottom&&(y=t.bottom-d.bottom+r,e<0&&t.top-y<d.top&&(y=t.top-(d.top+r)));else{let x=t.bottom-t.top,C=d.bottom-d.top;y=(s=="center"&&x<=C?t.top+x/2-C/2:s=="start"||s=="center"&&e<0?t.top-r:t.bottom-C+r)-d.top}if(i=="nearest"?t.left<d.left?(b=t.left-(d.left+o),e>0&&t.right>d.right+b&&(b=t.right-d.right+o)):t.right>d.right&&(b=t.right-d.right+o,e<0&&t.left<d.left+b&&(b=t.left-(d.left+o))):b=(i=="center"?t.left+(t.right-t.left)/2-(d.right-d.left)/2:i=="start"==l?t.left-o:t.right-(d.right-d.left)+o)-d.left,b||y)if(p)h.scrollBy(b,y);else{let x=0,C=0;if(y){let k=c.scrollTop;c.scrollTop+=y/m,C=(c.scrollTop-k)*m}if(b){let k=c.scrollLeft;c.scrollLeft+=b/g,x=(c.scrollLeft-k)*g}t={left:t.left-x,top:t.top-C,right:t.right-x,bottom:t.bottom-C},x&&Math.abs(x-b)<1&&(i="nearest"),C&&Math.abs(C-y)<1&&(s="nearest")}if(p)break;(t.top<d.top||t.bottom>d.bottom||t.left<d.left||t.right>d.right)&&(t={left:Math.max(t.left,d.left),right:Math.min(t.right,d.right),top:Math.max(t.top,d.top),bottom:Math.min(t.bottom,d.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function wn(n){let t=n.ownerDocument,e,i;for(let s=n.parentNode;s&&!(s==t.body||e&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:e,y:i}}class xn{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?U(e):0),i,Math.min(t.focusOffset,i?U(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let rt=null;w.safari&&w.safari_version>=26&&(rt=!1);function hs(n){if(n.setActive)return n.setActive();if(rt)return n.focus(rt);let t=[];for(let e=n;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(n.focus(rt==null?{get preventScroll(){return rt={preventScroll:!0},!0}}:void 0),!rt){rt=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],o=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=o&&(i.scrollLeft=o)}}}let Si;function Nt(n,t,e=t){let i=Si||(Si=document.createRange());return i.setEnd(n,e),i.setStart(n,t),i}function mt(n,t,e,i){let s={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let o=new KeyboardEvent("keydown",s);o.synthetic=!0,n.dispatchEvent(o);let r=new KeyboardEvent("keyup",s);return r.synthetic=!0,n.dispatchEvent(r),o.defaultPrevented||r.defaultPrevented}function Sn(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function vn(n,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,U(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=U(e))}else{if(e==n)return!0;i=it(e),e=e.parentNode}}function cs(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function fs(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=U(e)}else if(e.parentNode&&!le(e))i=it(e),e=e.parentNode;else return null}}function ds(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!le(e))i=it(e)+1,e=e.parentNode;else return null}}class z{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new z(t.parentNode,it(t),e)}static after(t,e){return new z(t.parentNode,it(t)+1,e)}}exports.Direction=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(exports.Direction||(exports.Direction={}));const ht=exports.Direction.LTR,si=exports.Direction.RTL;function us(n){let t=[];for(let e=0;e<n.length;e++)t.push(1<<+n[e]);return t}const Cn=us("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Mn=us("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ie=Object.create(null),_=[];for(let n of["()","[]","{}"]){let t=n.charCodeAt(0),e=n.charCodeAt(1);Ie[t]=e,Ie[e]=-t}function ps(n){return n<=247?Cn[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?Mn[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const kn=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class G{get dir(){return this.level%2?si:ht}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let o=-1;for(let r=0;r<t.length;r++){let l=t[r];if(l.from<=e&&l.to>=e){if(l.level==i)return r;(o<0||(s!=0?s<0?l.from<e:l.to>e:t[o].level>l.level))&&(o=r)}}if(o<0)throw new RangeError("Index out of range");return o}}function gs(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++){let i=n[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!gs(i.inner,s.inner))return!1}return!0}const A=[];function An(n,t,e,i,s){for(let o=0;o<=i.length;o++){let r=o?i[o-1].to:t,l=o<i.length?i[o].from:e,a=o?256:s;for(let h=r,c=a,f=a;h<l;h++){let d=ps(n.charCodeAt(h));d==512?d=c:d==8&&f==4&&(d=16),A[h]=d==4?2:d,d&7&&(f=d),c=d}for(let h=r,c=a,f=a;h<l;h++){let d=A[h];if(d==128)h<l-1&&c==A[h+1]&&c&24?d=A[h]=c:A[h]=256;else if(d==64){let p=h+1;for(;p<l&&A[p]==64;)p++;let g=h&&c==8||p<e&&A[p]==8?f==1?1:8:256;for(let m=h;m<p;m++)A[m]=g;h=p-1}else d==8&&f==1&&(A[h]=1);c=d,d&7&&(f=d)}}}function Tn(n,t,e,i,s){let o=s==1?2:1;for(let r=0,l=0,a=0;r<=i.length;r++){let h=r?i[r-1].to:t,c=r<i.length?i[r].from:e;for(let f=h,d,p,g;f<c;f++)if(p=Ie[d=n.charCodeAt(f)])if(p<0){for(let m=l-3;m>=0;m-=3)if(_[m+1]==-p){let b=_[m+2],y=b&2?s:b&4?b&1?o:s:0;y&&(A[f]=A[_[m]]=y),l=m;break}}else{if(_.length==189)break;_[l++]=f,_[l++]=d,_[l++]=a}else if((g=A[f])==2||g==1){let m=g==s;a=m?0:1;for(let b=l-3;b>=0;b-=3){let y=_[b+2];if(y&2)break;if(m)_[b+2]|=2;else{if(y&4)break;_[b+2]|=4}}}}}function Dn(n,t,e,i){for(let s=0,o=i;s<=e.length;s++){let r=s?e[s-1].to:n,l=s<e.length?e[s].from:t;for(let a=r;a<l;){let h=A[a];if(h==256){let c=a+1;for(;;)if(c==l){if(s==e.length)break;c=e[s++].to,l=s<e.length?e[s].from:t}else if(A[c]==256)c++;else break;let f=o==1,d=(c<t?A[c]:i)==1,p=f==d?f?1:2:i;for(let g=c,m=s,b=m?e[m-1].to:n;g>a;)g==b&&(g=e[--m].from,b=m?e[m-1].to:n),A[--g]=p;a=c}else o=h,a++}}}function ze(n,t,e,i,s,o,r){let l=i%2?2:1;if(i%2==s%2)for(let a=t,h=0;a<e;){let c=!0,f=!1;if(h==o.length||a<o[h].from){let m=A[a];m!=l&&(c=!1,f=m==16)}let d=!c&&l==1?[]:null,p=c?i:i+1,g=a;t:for(;;)if(h<o.length&&g==o[h].from){if(f)break t;let m=o[h];if(!c)for(let b=m.to,y=h+1;;){if(b==e)break t;if(y<o.length&&o[y].from==b)b=o[y++].to;else{if(A[b]==l)break t;break}}if(h++,d)d.push(m);else{m.from>a&&r.push(new G(a,m.from,p));let b=m.direction==ht!=!(p%2);qe(n,b?i+1:i,s,m.inner,m.from,m.to,r),a=m.to}g=m.to}else{if(g==e||(c?A[g]!=l:A[g]==l))break;g++}d?ze(n,a,g,i+1,s,d,r):a<g&&r.push(new G(a,g,p)),a=g}else for(let a=e,h=o.length;a>t;){let c=!0,f=!1;if(!h||a>o[h-1].to){let m=A[a-1];m!=l&&(c=!1,f=m==16)}let d=!c&&l==1?[]:null,p=c?i:i+1,g=a;t:for(;;)if(h&&g==o[h-1].to){if(f)break t;let m=o[--h];if(!c)for(let b=m.from,y=h;;){if(b==t)break t;if(y&&o[y-1].to==b)b=o[--y].from;else{if(A[b-1]==l)break t;break}}if(d)d.push(m);else{m.to<a&&r.push(new G(m.to,a,p));let b=m.direction==ht!=!(p%2);qe(n,b?i+1:i,s,m.inner,m.from,m.to,r),a=m.from}g=m.from}else{if(g==t||(c?A[g-1]!=l:A[g-1]==l))break;g--}d?ze(n,g,a,i+1,s,d,r):g<a&&r.push(new G(g,a,p)),a=g}}function qe(n,t,e,i,s,o,r){let l=t%2?2:1;An(n,s,o,i,l),Tn(n,s,o,i,l),Dn(s,o,i,l),ze(n,s,o,t,e,i,r)}function On(n,t,e){if(!n)return[new G(0,0,t==si?1:0)];if(t==ht&&!e.length&&!kn.test(n))return ms(n.length);if(e.length)for(;n.length>A.length;)A[A.length]=256;let i=[],s=t==ht?0:1;return qe(n,s,s,e,0,n.length,i),i}function ms(n){return[new G(0,n,0)]}let bs="";function Bn(n,t,e,i,s){var o;let r=i.head-n.from,l=G.find(t,r,(o=i.bidiLevel)!==null&&o!==void 0?o:-1,i.assoc),a=t[l],h=a.side(s,e);if(r==h){let d=l+=s?1:-1;if(d<0||d>=t.length)return null;a=t[l=d],r=a.side(!s,e),h=a.side(s,e)}let c=u.findClusterBreak(n.text,r,a.forward(s,e));(c<a.from||c>a.to)&&(c=h),bs=n.text.slice(Math.min(r,c),Math.max(r,c));let f=l==(s?t.length-1:0)?null:t[l+(s?1:-1)];return f&&c==h&&f.level+(s?0:1)<a.level?u.EditorSelection.cursor(f.side(!s,e)+n.from,f.forward(s,e)?1:-1,f.level):u.EditorSelection.cursor(c+n.from,a.forward(s,e)?-1:1,a.level)}function En(n,t,e){for(let i=t;i<e;i++){let s=ps(n.charCodeAt(i));if(s==1)return ht;if(s==2||s==4)return si}return ht}const ys=u.Facet.define(),ws=u.Facet.define(),xs=u.Facet.define(),Ss=u.Facet.define(),Ke=u.Facet.define(),vs=u.Facet.define(),Cs=u.Facet.define(),ni=u.Facet.define(),oi=u.Facet.define(),Ms=u.Facet.define({combine:n=>n.some(t=>t)}),ks=u.Facet.define({combine:n=>n.some(t=>t)}),As=u.Facet.define();class bt{constructor(t,e="nearest",i="nearest",s=5,o=5,r=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=o,this.isSnapshot=r}map(t){return t.empty?this:new bt(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new bt(u.EditorSelection.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Gt=u.StateEffect.define({map:(n,t)=>n.map(t)}),Ts=u.StateEffect.define();function q(n,t,e){let i=n.facet(Ss);i.length?i[0](t):window.onerror&&window.onerror(String(t),e,void 0,void 0,t)||(e?console.error(e+":",t):console.error(t))}const $=u.Facet.define({combine:n=>n.length?n[0]:!0});let Rn=0;const ut=u.Facet.define({combine(n){return n.filter((t,e)=>{for(let i=0;i<e;i++)if(n[i].plugin==t.plugin)return!1;return!0})}});class L{constructor(t,e,i,s,o){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=o(this),this.extension=this.baseExtensions.concat(ut.of({plugin:this,arg:void 0}))}of(t){return this.baseExtensions.concat(ut.of({plugin:this,arg:t}))}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:o,decorations:r}=e||{};return new L(Rn++,t,i,s,l=>{let a=[];return r&&a.push(me.of(h=>{let c=h.plugin(l);return c?r(c):O.none})),o&&a.push(o(l)),a})}static fromClass(t,e){return L.define((i,s)=>new t(i,s),e)}}class Ce{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(q(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){q(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){q(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Ds=u.Facet.define(),ri=u.Facet.define(),me=u.Facet.define(),Os=u.Facet.define(),li=u.Facet.define(),qt=u.Facet.define(),Bs=u.Facet.define();function vi(n,t){let e=n.state.facet(Bs);if(!e.length)return e;let i=e.map(o=>o instanceof Function?o(n):o),s=[];return u.RangeSet.spans(i,t.from,t.to,{point(){},span(o,r,l,a){let h=o-t.from,c=r-t.from,f=s;for(let d=l.length-1;d>=0;d--,a--){let p=l[d].spec.bidiIsolate,g;if(p==null&&(p=En(t.text,h,c)),a>0&&f.length&&(g=f[f.length-1]).to==h&&g.direction==p)g.to=c,f=g.inner;else{let m={from:h,to:c,direction:p,inner:[]};f.push(m),f=m.inner}}}}),s}const Es=u.Facet.define();function ai(n){let t=0,e=0,i=0,s=0;for(let o of n.state.facet(Es)){let r=o(n);r&&(r.left!=null&&(t=Math.max(t,r.left)),r.right!=null&&(e=Math.max(e,r.right)),r.top!=null&&(i=Math.max(i,r.top)),r.bottom!=null&&(s=Math.max(s,r.bottom)))}return{left:t,right:e,top:i,bottom:s}}const At=u.Facet.define();class V{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new V(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,o=0,r=0;;){let l=s<t.length?t[s].fromB:1e9,a=o<e.length?e[o]:1e9,h=Math.min(l,a);if(h==1e9)break;let c=h+r,f=h,d=c;for(;;)if(o<e.length&&e[o]<=f){let p=e[o+1];o+=2,f=Math.max(f,p);for(let g=s;g<t.length&&t[g].fromB<=f;g++)r=t[g].toA-t[g].toB;d=Math.max(d,p+r)}else if(s<t.length&&t[s].fromB<=f){let p=t[s++];f=Math.max(f,p.toB),d=Math.max(d,p.toA),r=p.toA-p.toB}else break;i.push(new V(c,d,h,f))}return i}}class Ft{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=u.ChangeSet.empty(this.startState.doc.length);for(let o of i)this.changes=this.changes.compose(o.changes);let s=[];this.changes.iterChangedRanges((o,r,l,a)=>s.push(new V(o,r,l,a))),this.changedRanges=s}static create(t,e,i){return new Ft(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const Ln=[];class B{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return this.flags&1}get children(){return Ln}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&pn(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let s of this.children){if(s==t)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e){return null}domPosFor(t,e){let i=it(this.dom),s=this.length?t>0:e>0;return new z(this.parent.dom,i+(s?1:0),t==0||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof ye)return t;return null}static get(t){return t.cmTile}}class be extends B{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(this.flags&2)return;super.sync(t);let e=this.dom,i=null,s,o=t?.node==e?t:null,r=0;for(let l of this.children){if(l.sync(t),r+=l.length+l.breakAfter,s=i?i.nextSibling:e.firstChild,o&&s!=l.dom&&(o.written=!0),l.dom.parentNode==e)for(;s&&s!=l.dom;)s=Ci(s);else e.insertBefore(l.dom,s);i=l.dom}for(s=i?i.nextSibling:e.firstChild,o&&s&&(o.written=!0);s;)s=Ci(s);this.length=r}}function Ci(n){let t=n.nextSibling;return n.parentNode.removeChild(n),t}class ye extends be{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=B.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,s=0,o=0;;)if(s==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&o++,s=e.pop()}else{let r=i.children[s++];if(r instanceof et)e.push(s),i=r,s=0;else{let l=o+r.length,a=t(r,o);if(a!==void 0)return a;o=l+r.breakAfter}}}resolveBlock(t,e){let i,s=-1,o,r=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(t>=a&&t<=h){if(l.isWidget()&&e>=-1&&e<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(a<t||t==h&&(e<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,s=t-a),(h>t||t==a&&(e>1?l.length:l.covers(-1)))&&(!o||!l.isWidget()&&o.isWidget())&&(o=l,r=t-a)}}),!i&&!o)throw new Error("No tile at position "+t);return i&&e<0||!o?{tile:i,offset:s}:{tile:o,offset:r}}}class et extends be{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return this.children.length?t<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new et(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class St extends be{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let s=new St(e||document.createElement("div"),t);return(!e||!i)&&(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(t,e,i){let s=null,o=-1,r=null,l=-1;function a(c,f){for(let d=0,p=0;d<c.children.length&&p<=f;d++){let g=c.children[d],m=p+g.length;m>=f&&(g.isComposite()?a(g,f-p):(!r||r.isHidden&&(e>0||i&&Hn(r,g)))&&(m>f||g.flags&32)?(r=g,l=f-p):(p<f||g.flags&16&&!g.isHidden)&&(s=g,o=f-p)),p=m}}a(this,t);let h=(e<0?s:r)||s||r;return h?{tile:h,offset:h==s?o:l}:null}coordsIn(t,e){let i=this.resolveInline(t,e,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),e):Pn(this)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:s,offset:o}=i;if(this.dom.contains(s.dom))return s.isText()?new z(s.dom,Math.min(s.dom.nodeValue.length,o)):s.domPosFor(o,s.flags&16?1:s.flags&32?-1:e);let r=i.tile.parent,l=!1;for(let a of r.children){if(l)return new z(a.dom,0);a==i.tile&&(l=!0)}}return new z(this.dom,0)}}function Pn(n){let t=n.dom.lastChild;if(!t)return n.dom.getBoundingClientRect();let e=Et(t);return e[e.length-1]||null}function Hn(n,t){let e=n.coordsIn(0,1),i=t.coordsIn(0,1);return e&&i&&i.top<e.bottom}class W extends be{constructor(t,e){super(t),this.mark=e}get domAttrs(){return this.mark.attrs}static of(t,e){let i=new W(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class lt extends B{constructor(t,e){super(t,e.length),this.text=e}sync(t){this.flags&2||(super.sync(t),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(t,e){let i=this.dom.nodeValue.length;t>i&&(t=i);let s=t,o=t,r=0;t==0&&e<0||t==i&&e>=0?w.chrome||w.gecko||(t?(s--,r=1):o<i&&(o++,r=-1)):e<0?s--:o<i&&o++;let l=Nt(this.dom,s,o).getClientRects();if(!l.length)return null;let a=l[(r?r<0:e>=0)?0:l.length-1];return w.safari&&!r&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),r?Wt(a,r<0):a||null}static of(t,e){let i=new lt(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class ct extends B{constructor(t,e,i,s){super(t,e,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return this.flags&48?!1:(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let s=this.widget.coordsAt(this.dom,t,e);if(s)return s;if(i)return Wt(this.dom.getBoundingClientRect(),this.length?t==0:e<=0);{let o=this.dom.getClientRects(),r=null;if(!o.length)return null;let l=this.flags&16?!0:this.flags&32?!1:t>0;for(let a=l?o.length-1:0;r=o[a],!(t>0?a==0:a==o.length-1||r.top<r.bottom);a+=l?-1:1);return Wt(r,!l)}}get overrideDOMText(){if(!this.length)return u.Text.empty;let{root:t}=this;if(!t)return u.Text.empty;let e=this.posAtStart;return t.view.state.doc.slice(e,e+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,e,i,s,o){return o||(o=t.toDOM(e),t.editable||(o.contentEditable="false")),new ct(o,i,t,s)}}class ae extends B{constructor(t){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),super(e,0,t)}get isHidden(){return!0}get overrideDOMText(){return u.Text.empty}coordsIn(t){return this.dom.getBoundingClientRect()}}class Wn{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:s,index:o,beforeBreak:r,parents:l}=this;for(;t||e>0;)if(s.isComposite())if(r){if(!t)break;i&&i.break(),t--,r=!1}else if(o==s.children.length){if(!t&&!l.length)break;i&&i.leave(s),r=!!s.breakAfter,{tile:s,index:o}=l.pop(),o++}else{let a=s.children[o],h=a.breakAfter;(e>0?a.length<=t:a.length<t)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(r=!!h,o++,t-=a.length):(l.push({tile:s,index:o}),s=a,o=0,i&&a.isComposite()&&i.enter(a))}else if(o==s.length)r=!!s.breakAfter,{tile:s,index:o}=l.pop(),o++;else if(t){let a=Math.min(t,s.length-o);i&&i.skip(s,o,o+a),t-=a,o+=a}else break;return this.tile=s,this.index=o,this.beforeBreak=r,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class Nn{constructor(t,e,i,s){this.from=t,this.to=e,this.wrapper=i,this.rank=s}}class Fn{constructor(t,e,i){this.cache=t,this.root=e,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(t,e,i,s){var o;this.flushBuffer();let r=this.ensureMarks(e,i),l=r.lastChild;if(l&&l.isText()&&!(l.flags&8)){this.cache.reused.set(l,2);let a=r.children[r.children.length-1]=new lt(l.dom,l.text+t);a.parent=r}else r.append(s||lt.of(t,(o=this.cache.find(lt))===null||o===void 0?void 0:o.dom));this.pos+=t.length,this.afterWidget=null}addComposition(t,e){let i=this.curLine;i.dom!=e.line.dom&&(i.setDOM(this.cache.reused.has(e.line)?Me(e.line.dom):e.line.dom),this.cache.reused.set(e.line,2));let s=i;for(let l=e.marks.length-1;l>=0;l--){let a=e.marks[l],h=s.lastChild;if(h instanceof W&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(Me(a.dom)),s=h;else{if(this.cache.reused.get(a)){let f=B.get(a.dom);f&&f.setDOM(Me(a.dom))}let c=W.of(a.mark,a.dom);s.append(c),s=c}this.cache.reused.set(a,2)}let o=B.get(t.text);o&&this.cache.reused.set(o,2);let r=new lt(t.text,t.text.nodeValue);r.flags|=8,s.append(r)}addInlineWidget(t,e,i){let s=this.afterWidget&&t.flags&48&&(this.afterWidget.flags&48)==(t.flags&48);s||this.flushBuffer();let o=this.ensureMarks(e,i);!s&&!(t.flags&16)&&o.append(this.getBuffer(1)),o.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){let e=this.afterWidget||this.lastBlock;e.length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=Rs);let s=St.start(t,e||((i=this.cache.find(St))===null||i===void 0?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let s=this.curLine;for(let o=t.length-1;o>=0;o--){let r=t[o],l;if(e>0&&(l=s.lastChild)&&l instanceof W&&l.mark.eq(r))s=l,e--;else{let a=W.of(r,(i=this.cache.find(W,h=>h.mark.eq(r)))===null||i===void 0?void 0:i.dom);s.append(a),s=a,e=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;(!t||!Mi(this.curLine,!1)||t.dom.nodeName!="BR"&&t.isWidget()&&!(w.ios&&Mi(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(ke,0,32)||new ct(ke.toDOM(),0,ke,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to<this.pos&&this.wrappers.splice(t,1);for(let t=this.blockWrappers;t.value&&t.from<=this.pos;t.next())if(t.to>=this.pos){let e=new Nn(t.from,t.to,t.value,t.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-e.rank||this.wrappers[i-1].to-e.to)<0;)i--;this.wrappers.splice(i,0,e)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let s=e.lastChild;if(i.from<this.pos&&s instanceof et&&s.wrapper.eq(i.wrapper))e=s;else{let o=et.of(i.wrapper,(t=this.cache.find(et,r=>r.wrapper.eq(i.wrapper)))===null||t===void 0?void 0:t.dom);e.append(o),e=o}}return e}blockPosCovered(){let t=this.lastBlock;return t!=null&&!t.breakAfter&&(!t.isWidget()||(t.flags&160)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(ae,void 0,1);return i&&(i.flags=e),i||new ae(e)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class Vn{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:s,lineBreak:o,done:r}=this.cursor.next(this.skipCount);if(this.skipCount=0,r)throw new Error("Ran out of text content when drawing inline views");this.text=s;let l=this.textOff=Math.min(t,s.length);return o?null:s.slice(0,l)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const he=[ct,St,lt,W,ae,et,ye];for(let n=0;n<he.length;n++)he[n].bucket=n;class In{constructor(t){this.view=t,this.buckets=he.map(()=>[]),this.index=he.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let s=t.bucket,o=this.buckets[s],r=this.index[s];for(let l=o.length-1;l>=0;l--){let a=(l+r)%o.length,h=o[a];if((!e||e(h))&&!this.reused.has(h))return o.splice(a,1),a<r&&this.index[s]--,this.reused.set(h,i),h}return null}findWidget(t,e,i){let s=this.buckets[0];if(s.length)for(let o=0,r=0;;o++){if(o==s.length){if(r)return null;r=1,o=0}let l=s[o];if(!this.reused.has(l)&&(r==0?l.widget.compare(t):l.widget.constructor==t.constructor&&t.updateDOM(l.dom,this.view)))return s.splice(o,1),o<this.index[0]&&this.index[0]--,l.widget==t&&l.length==e&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new ct(l.dom,e,t,l.flags&-498|i))}}reuse(t){return this.reused.set(t,1),t}maybeReuse(t,e=2){if(!this.reused.has(t))return this.reused.set(t,e),t.dom}clear(){for(let t=0;t<this.buckets.length;t++)this.buckets[t].length=this.index[t]=0}}class zn{constructor(t,e,i,s,o){this.view=t,this.decorations=s,this.disallowBlockEffectsFor=o,this.openWidget=!1,this.openMarks=0,this.cache=new In(t),this.text=new Vn(t.state.doc),this.builder=new Fn(this.cache,new ye(t,t.contentDOM),u.RangeSet.iter(i)),this.cache.reused.set(e,2),this.old=new Wn(e),this.reuseWalker={skip:(r,l,a)=>{if(this.cache.add(r),r.isComposite())return!1},enter:r=>this.cache.add(r),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let s=0,o=0,r=0;;){let l=r<t.length?t[r++]:null,a=l?l.fromA:this.old.root.length;if(a>s){let h=a-s;this.preserve(h,!r,!l),s=a,o+=h}if(!l)break;e&&l.fromA<=e.range.fromA&&l.toA>=e.range.toA?(this.forward(l.fromA,e.range.fromA,e.range.fromA<e.range.toA?1:-1),this.emit(o,e.range.fromB),this.cache.clear(),this.builder.addComposition(e,i),this.text.skip(e.range.toB-e.range.fromB),this.forward(e.range.fromA,l.toA),this.emit(e.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(o,l.toB)),o=l.toB,s=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(t,e,i){let s=_n(this.old),o=this.openMarks;this.old.advance(t,i?1:-1,{skip:(r,l,a)=>{if(r.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<r.length?ct.of(r.widget,this.view,a-l,r.flags&496,this.cache.maybeReuse(r)):this.cache.reuse(r);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,s,o),o=s.length)}else if(r.isText())this.builder.ensureLine(null),!l&&a==r.length?this.builder.addText(r.text,s,o,this.cache.reuse(r)):(this.cache.add(r),this.builder.addText(r.text.slice(l,a),s,o)),o=s.length;else if(r.isLine())r.flags&=-2,this.cache.reused.set(r,1),this.builder.addLine(r);else if(r instanceof ae)this.cache.add(r);else if(r instanceof W)this.builder.ensureLine(null),this.builder.addMark(r,s,o),this.cache.reused.set(r,1),o=s.length;else return!1;this.openWidget=!1},enter:r=>{r.isLine()?this.builder.addLineStart(r.attrs,this.cache.maybeReuse(r)):(this.cache.add(r),r instanceof W&&s.unshift(r.mark)),this.openWidget=!1},leave:r=>{r.isLine()?s.length&&(s.length=o=0):r instanceof W&&(s.shift(),o=Math.min(o,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,s=this.builder,o=0,r=u.RangeSet.spans(this.decorations,t,e,{point:(l,a,h,c,f,d)=>{if(h instanceof at){if(this.disallowBlockEffectsFor[d]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(o=c.length,f>c.length)s.continueWidget(a-l);else{let p=h.widget||(h.block?vt.block:vt.inline),g=qn(h),m=this.cache.findWidget(p,a-l,g)||ct.of(p,this.view,a-l,g);h.block?(h.startSide>0&&s.addLineStartIfNotCovered(i),s.addBlockWidget(m)):(s.ensureLine(i),s.addInlineWidget(m,c,f))}i=null}else i=Kn(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;f<a;){let d=this.text.next(Math.min(512,a-f));d==null?(s.addLineStartIfNotCovered(i),s.addBreak(),f++):(s.ensureLine(i),s.addText(d,h,c),f+=d.length),i=null}}});s.addLineStartIfNotCovered(i),this.openWidget=r>o,this.openMarks=r}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(e-t-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(t){let e=[],i=null;for(let s=t.parentNode;;s=s.parentNode){let o=B.get(s);if(s==this.view.contentDOM)break;o instanceof W?e.push(o):o?.isLine()?i=o:s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM?i=new St(s,Rs):e.push(W.of(new It({tagName:s.nodeName.toLowerCase(),attributes:gn(s)}),s))}return{line:i,marks:e}}}function Mi(n,t){let e=i=>{for(let s of i.children)if((t?s.isText():s.length)||e(s))return!0;return!1};return e(n)}function qn(n){let t=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(t|=256),t}const Rs={class:"cm-line"};function Kn(n,t){let e=t.spec.attributes,i=t.spec.class;return!e&&!i||(n||(n={class:"cm-line"}),e&&ei(e,n),i&&(n.class+=" "+i)),n}function _n(n){let t=[];for(let e=n.parents.length;e>1;e--){let i=e==n.parents.length?n.tile:n.parents[e].tile;i instanceof W&&t.push(i.mark)}return t}function Me(n){let t=B.get(n);return t&&t.setDOM(n.cloneNode()),n}class vt extends st{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}vt.inline=new vt("span");vt.block=new vt("div");const ke=new class extends st{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class ki{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=O.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new ye(t,t.contentDOM),this.updateInner([new V(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:f})=>f<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?s=this.domChanged.newSel.head:!Zn(t.changes,this.hasComposition)&&!t.selectionSet&&(s=t.state.selection.main.head));let o=s>-1?Gn(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;i=new V(c,f,t.changes.mapPos(c,-1),t.changes.mapPos(f,1)).addToSet(i.slice())}this.hasComposition=o?{from:o.range.fromB,to:o.range.toB}:null,(w.ie||w.chrome)&&!o&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=this.decorations,l=this.blockWrappers;this.updateDeco();let a=$n(r,this.decorations,t.changes);a.length&&(i=V.extendWithRanges(i,a));let h=Qn(l,this.blockWrappers,t.changes);return h.length&&(i=V.extendWithRanges(i,h)),o&&!i.some(c=>c.fromA<=o.range.fromA&&c.toA>=o.range.toA)&&(i=o.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,o),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let r=this.tile,l=new zn(this.view,r,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=l.run(t,e),_e(r,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=w.chrome||w.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(o),o&&(o.written||i.selectionRange.focusNode!=o.node||!this.tile.dom.contains(o.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.tile.children)o.isWidget()&&o.widget instanceof Ae&&s.push(o.dom);i.updateGaps(s)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(Ts)&&(this.editContextFormatting=i.value)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,o=s==i,r=!o&&!(this.view.state.facet($)||i.tabIndex>-1)&&Bt(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(o||e||r))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),w.gecko&&a.empty&&!this.hasComposition&&jn(h)){let d=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(d,h.node.childNodes[h.offset]||null)),h=c=new z(d,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!Rt(h.node,h.offset,f.anchorNode,f.anchorOffset)||!Rt(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{w.android&&w.chrome&&i.contains(f.focusNode)&&Jn(f.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let d=xt(this.view.root);if(d)if(a.empty){if(w.gecko){let p=Yn(h.node,h.offset);if(p&&p!=3){let g=(p==1?fs:ds)(h.node,h.offset);g&&(h=new z(g.node,g.offset))}}d.collapse(h.node,h.offset),a.bidiLevel!=null&&d.caretBidiLevel!==void 0&&(d.caretBidiLevel=a.bidiLevel)}else if(d.extend){d.collapse(h.node,h.offset);try{d.extend(c.node,c.offset)}catch{}}else{let p=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),p.setEnd(c.node,c.offset),p.setStart(h.node,h.offset),d.removeAllRanges(),d.addRange(p)}r&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new z(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new z(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Rt(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=xt(t.root),{anchorNode:s,anchorOffset:o}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let r=this.lineAt(e.head,e.assoc);if(!r)return;let l=r.posAtStart;if(e.head==l||e.head==l+r.length)return;let a=this.coordsAt(e.head,-1),h=this.coordsAt(e.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(c.node,c.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(s,o)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return this.tile.dom.compareDocumentPosition(t)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let o;if(t==i.dom)o=i.dom.childNodes[e];else{let r=U(t)==0?0:e==0?-1:1;for(;;){let l=t.parentNode;if(l==i.dom)break;r==0&&l.firstChild!=l.lastChild&&(t==l.firstChild?r=-1:r=1),t=l}r<0?o=t:o=t.nextSibling}if(o==i.dom.firstChild)return s;for(;o&&!B.get(o);)o=o.nextSibling;if(!o)return s+i.length;for(let r=0,l=s;;r++){let a=i.children[r];if(a.dom==o)return l;l+=a.length+a.breakAfter}}else return i.isText()?t==i.dom?s+e:s+(e?i.length:0):s}domAtPos(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(t,e):i.domIn(s,e)}inlineDOMNearPos(t,e){let i,s=-1,o=!1,r,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=t)return!0;h.flags&16&&(o=!0)}else{let f=c+h.length;if(c<=t&&(i=h,s=t-c,o=f<t),f>=t&&!r&&(r=h,l=t-c,a=c>t),c>t&&r)return!0}}),!i&&!r?this.domAtPos(t,e):(o&&r?i=null:a&&i&&(r=null),i&&e<0||!r?i.domIn(s,e):r.domIn(l,e))}coordsAt(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.widget instanceof Ae?null:i.coordsInWidget(s,e,!0):i.coordsIn(s,e)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;function s(o,r){if(o.isComposite())for(let l of o.children){if(l.length>=r){let a=s(l,r);if(a)return a}if(r-=l.length,r<0)break}else if(o.isText()&&r<o.length){let l=u.findClusterBreak(o.text,r);if(l==r)return null;let a=Nt(o.dom,r,l).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(h==a.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return s(e,i)}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,o=this.view.contentDOM.clientWidth,r=o>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==exports.Direction.LTR,h=0,c=(f,d,p)=>{for(let g=0;g<f.children.length&&!(d>s);g++){let m=f.children[g],b=d+m.length,y=m.dom.getBoundingClientRect(),{height:x}=y;if(p&&!g&&(h+=y.top-p.top),m instanceof et)b>i&&c(m,d,y);else if(d>=i&&(h>0&&e.push(-h),e.push(x+h),h=0,r)){let C=m.dom.lastChild,k=C?Et(C):[];if(k.length){let v=k[k.length-1],S=a?v.right-y.left:y.right-v.left;S>l&&(l=S,this.minWidth=o,this.minWidthFrom=d,this.minWidthTo=b)}}p&&g==f.children.length-1&&(h+=p.bottom-y.bottom),d=b+m.breakAfter}};return c(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return getComputedStyle(e.dom).direction=="rtl"?exports.Direction.RTL:exports.Direction.LTR}measureTextSize(){let t=this.tile.blockTiles(r=>{if(r.isLine()&&r.children.length&&r.length<=20){let l=0,a;for(let h of r.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=Et(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:r.dom.getBoundingClientRect().height,charWidth:l/r.length,textHeight:a}}});if(t)return t;let e=document.createElement("div"),i,s,o;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(e);let r=Et(e.firstChild)[0];i=e.getBoundingClientRect().height,s=r&&r.width?r.width/27:7,o=r&&r.height?r.height:i,e.remove()}),{lineHeight:i,charWidth:s,textHeight:o}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let o=s==e.viewports.length?null:e.viewports[s],r=o?o.from-1:this.view.state.doc.length;if(r>i){let l=(e.lineBlockAt(r).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(O.replace({widget:new Ae(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!o)break;i=o.to+1}return O.set(t)}updateDeco(){let t=1,e=this.view.state.facet(me).map(o=>(this.dynamicDecorationMap[t++]=typeof o=="function")?o(this.view):o),i=!1,s=this.view.state.facet(li).map((o,r)=>{let l=typeof o=="function";return l&&(i=!0),l?o(this.view):o});for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(u.RangeSet.join(s))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;this.blockWrappers=this.view.state.facet(Os).map(o=>typeof o=="function"?o(this.view):o)}scrollIntoView(t){if(t.isSnapshot){let h=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=h.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let h of this.view.state.facet(As))try{if(h(this.view,t.range,t))return!0}catch(c){q(this.view.state,c,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let o=ai(this.view),r={left:i.left-o.left,top:i.top-o.top,right:i.right+o.right,bottom:i.bottom+o.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;yn(this.view.scrollDOM,r,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,a),-a),this.view.textDirection==exports.Direction.LTR)}lineHasWidget(t){let e=i=>i.isWidget()||i.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){_e(this.tile)}}function _e(n,t){let e=t?.get(n);if(e!=1){e==null&&n.destroy();for(let i of n.children)_e(i,t)}}function jn(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function Ls(n,t){let e=n.observer.selectionRange;if(!e.focusNode)return null;let i=fs(e.focusNode,e.focusOffset),s=ds(e.focusNode,e.focusOffset),o=i||s;if(s&&i&&s.node!=i.node){let l=B.get(s.node);if(!l||l.isText()&&l.text!=s.node.nodeValue)o=s;else if(n.docView.lastCompositionAfterCursor){let a=B.get(i.node);!a||a.isText()&&a.text!=i.node.nodeValue||(o=s)}}if(n.docView.lastCompositionAfterCursor=o!=i,!o)return null;let r=t-o.offset;return{from:r,to:r+o.node.nodeValue.length,node:o.node}}function Gn(n,t,e){let i=Ls(n,e);if(!i)return null;let{node:s,from:o,to:r}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=t.invertedDesc;return{range:new V(a.mapPos(o),a.mapPos(r),o,r),text:s}}function Yn(n,t){return n.nodeType!=1?0:(t&&n.childNodes[t-1].contentEditable=="false"?1:0)|(t<n.childNodes.length&&n.childNodes[t].contentEditable=="false"?2:0)}let Xn=class{constructor(){this.changes=[]}compareRange(t,e){gt(t,e,this.changes)}comparePoint(t,e){gt(t,e,this.changes)}boundChange(t){gt(t,t,this.changes)}};function $n(n,t,e){let i=new Xn;return u.RangeSet.compare(n,t,e,i),i.changes}class Un{constructor(){this.changes=[]}compareRange(t,e){gt(t,e,this.changes)}comparePoint(){}boundChange(t){gt(t,t,this.changes)}}function Qn(n,t,e){let i=new Un;return u.RangeSet.compare(n,t,e,i),i.changes}function Jn(n,t){for(let e=n;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Zn(n,t){let e=!1;return t&&n.iterChangedRanges((i,s)=>{i<t.to&&s>t.from&&(e=!0)}),e}class Ae extends st{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function to(n,t,e=1){let i=n.charCategorizer(t),s=n.doc.lineAt(t),o=t-s.from;if(s.length==0)return u.EditorSelection.cursor(t);o==0?e=1:o==s.length&&(e=-1);let r=o,l=o;e<0?r=u.findClusterBreak(s.text,o,!1):l=u.findClusterBreak(s.text,o);let a=i(s.text.slice(r,l));for(;r>0;){let h=u.findClusterBreak(s.text,r,!1);if(i(s.text.slice(h,r))!=a)break;r=h}for(;l<s.length;){let h=u.findClusterBreak(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return u.EditorSelection.range(r+s.from,l+s.from)}function eo(n,t,e,i,s){let o=Math.round((i-t.left)*n.defaultCharacterWidth);if(n.lineWrapping&&e.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-e.top-(n.defaultLineHeight-l)*.5)/l);o+=a*n.viewState.heightOracle.lineLength}let r=n.state.sliceDoc(e.from,e.to);return e.from+u.findColumn(r,o,n.state.tabSize)}function je(n,t,e){let i=n.lineBlockAt(t);if(Array.isArray(i.type)){let s;for(let o of i.type){if(o.from>t)break;if(!(o.to<t)){if(o.from<t&&o.to>t)return o;(!s||o.type==exports.BlockType.Text&&(s.type!=o.type||(e<0?o.from<t:o.to>t)))&&(s=o)}}return s||i}return i}function io(n,t,e,i){let s=je(n,t.head,t.assoc||-1),o=!i||s.type!=exports.BlockType.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(o){let r=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:e==(l==exports.Direction.LTR)?r.right-1:r.left+1,y:(o.top+o.bottom)/2});if(a!=null)return u.EditorSelection.cursor(a,e?-1:1)}return u.EditorSelection.cursor(e?s.to:s.from,e?-1:1)}function Ai(n,t,e,i){let s=n.state.doc.lineAt(t.head),o=n.bidiSpans(s),r=n.textDirectionAt(s.from);for(let l=t,a=null;;){let h=Bn(s,o,r,l,e),c=bs;if(!h){if(s.number==(e?n.state.doc.lines:1))return l;c=`
2
+ `,s=n.state.doc.line(s.number+(e?1:-1)),o=n.bidiSpans(s),h=n.visualLineSide(s,!e)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function so(n,t,e){let i=n.state.charCategorizer(t),s=i(e);return o=>{let r=i(o);return s==u.CharCategory.Space&&(s=r),s==r}}function no(n,t,e,i){let s=t.head,o=e?1:-1;if(s==(e?n.state.doc.length:0))return u.EditorSelection.cursor(s,t.assoc);let r=t.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s,t.assoc||-1),c=n.documentTop;if(h)r==null&&(r=h.left-a.left),l=o<0?h.top:h.bottom;else{let g=n.viewState.lineBlockAt(s);r==null&&(r=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-g.from))),l=(o<0?g.top:g.bottom)+c}let f=a.left+r,d=i??n.viewState.heightOracle.textHeight>>1,p=Ge(n,{x:f,y:l+d*o},!1,o);return u.EditorSelection.cursor(p.pos,p.assoc,void 0,r)}function Lt(n,t,e){for(;;){let i=0;for(let s of n)s.between(t-1,t+1,(o,r,l)=>{if(t>o&&t<r){let a=i||e||(t-o<r-t?-1:1);t=a<0?o:r,i=a}});if(!i)return t}}function Ps(n,t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],o=null;if(s.empty){let r=Lt(n,s.from,0);r!=s.from&&(o=u.EditorSelection.cursor(r,-1))}else{let r=Lt(n,s.from,-1),l=Lt(n,s.to,1);(r!=s.from||l!=s.to)&&(o=u.EditorSelection.range(s.from==s.anchor?r:l,s.from==s.head?r:l))}o&&(e||(e=t.ranges.slice()),e[i]=o)}return e?u.EditorSelection.create(e,t.mainIndex):t}function Te(n,t,e){let i=Lt(n.state.facet(qt).map(s=>s(n)),e.from,t.head>e.from?-1:1);return i==e.from?e:u.EditorSelection.cursor(i,i<e.from?1:-1)}class j{constructor(t,e){this.pos=t,this.assoc=e}}function Ge(n,t,e,i){let s=n.contentDOM.getBoundingClientRect(),o=s.top+n.viewState.paddingTop,{x:r,y:l}=t,a=l-o,h;for(;;){if(a<0)return new j(0,1);if(a>n.viewState.docHeight)return new j(n.state.doc.length,-1);if(h=n.elementAtHeight(a),i==null)break;if(h.type==exports.BlockType.Text){let d=n.docView.coordsAt(i<0?h.from:h.to,i);if(d&&(i<0?d.top<=a+o:d.bottom>=a+o))break}let f=n.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+f:h.top-f}if(n.viewport.from>=h.to||n.viewport.to<=h.from){if(e)return null;if(h.type==exports.BlockType.Text){let f=eo(n,s,h,r,l);return new j(f,f==h.from?1:-1)}}if(h.type!=exports.BlockType.Text)return a<(h.top+h.bottom)/2?new j(h.from,1):new j(h.to,-1);let c=n.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=n.docView.lineAt(h.from,-2)),Hs(n,c,h.from,r,l)}function Hs(n,t,e,i,s){let o=-1,r=null,l=1e9,a=1e9,h=s,c=s,f=(d,p)=>{for(let g=0;g<d.length;g++){let m=d[g];if(m.top==m.bottom)continue;let b=m.left>i?m.left-i:m.right<i?i-m.right:0,y=m.top>s?m.top-s:m.bottom<s?s-m.bottom:0;m.top<=c&&m.bottom>=h&&(h=Math.min(m.top,h),c=Math.max(m.bottom,c),y=0),(o<0||(y-a||b-l)<0)&&(o>=0&&a&&l<b&&r.top<=c-2&&r.bottom>=h+2?a=0:(o=p,l=b,a=y,r=m))}};if(t.isText()){for(let p=0;p<t.length;){let g=u.findClusterBreak(t.text,p);if(f(Nt(t.dom,p,g).getClientRects(),p),!l&&!a)break;p=g}return i>(r.left+r.right)/2==(Ti(n,o+e)==exports.Direction.LTR)?new j(e+u.findClusterBreak(t.text,o),-1):new j(e+o,1)}else{if(!t.length)return new j(e,1);for(let m=0;m<t.children.length;m++){let b=t.children[m];if(b.flags&48)continue;let y=(b.dom.nodeType==1?b.dom:Nt(b.dom,0,b.length)).getClientRects();if(f(y,m),!l&&!a)break}let d=t.children[o],p=t.posBefore(d,e);return d.isComposite()||d.isText()?Hs(n,d,p,Math.max(r.left,Math.min(r.right,i)),s):i>(r.left+r.right)/2==(Ti(n,o+e)==exports.Direction.LTR)?new j(p+d.length,-1):new j(p,1)}}function Ti(n,t){let e=n.state.doc.lineAt(t);return n.bidiSpans(e)[G.find(n.bidiSpans(e),t-e.from,-1,1)].dir}const Tt="￿";class oo{constructor(t,e){this.points=t,this.view=e,this.text="",this.lineSeparator=e.state.facet(u.EditorState.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Tt}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let o=this.text.length;this.readNode(s);let r=B.get(s),l=s.nextSibling;if(l==e){r?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=B.get(l);(r&&a?r.breakAfter:(r?r.breakAfter:le(s))||le(l)&&(s.nodeName!="BR"||r?.isWidget())&&this.text.length>o)&&!lo(l,e)&&this.lineBreak(),s=l}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let o=-1,r=1,l;if(this.lineSeparator?(o=e.indexOf(this.lineSeparator,i),r=this.lineSeparator.length):(l=s.exec(e))&&(o=l.index,r=l[0].length),this.append(e.slice(i,o<0?e.length:o)),o<0)break;if(this.lineBreak(),r>1)for(let a of this.points)a.node==t&&a.pos>this.text.length&&(a.pos-=r-1);i=o+r}}readNode(t){let e=B.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(ro(t,i.node,i.offset)?e:0))}}function ro(n,t,e){for(;;){if(!t||e<U(t))return!1;if(t==n)return!0;e=it(t)+1,t=t.parentNode}}function lo(n,t){let e;for(;!(n==t||!n);n=n.nextSibling){let i=B.get(n);if(!i?.isWidget())return!1;i&&(e||(e=[])).push(i)}if(e)for(let i of e){let s=i.overrideDOMText;if(s?.length)return!1}return!0}class Di{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class ao{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:o,impreciseAnchor:r}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=Ws(t.docView.tile,e,i,0))){let l=o||r?[]:co(t),a=new oo(l,t);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=fo(l,this.bounds.from)}else{let l=t.observer.selectionRange,a=o&&o.node==l.focusNode&&o.offset==l.focusOffset||!Ve(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),h=r&&r.node==l.anchorNode&&r.offset==l.anchorOffset||!Ve(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),c=t.viewport;if((w.ios||w.chrome)&&t.state.selection.main.empty&&a!=h&&(c.from>0||c.to<t.state.doc.length)){let f=Math.min(a,h),d=Math.max(a,h),p=c.from-f,g=c.to-d;(p==0||p==1||f==0)&&(g==0||g==-1||d==t.state.doc.length)&&(a=0,h=t.state.doc.length)}t.inputState.composing>-1&&t.state.selection.ranges.length>1?this.newSel=t.state.selection.replaceRange(u.EditorSelection.range(h,a)):this.newSel=u.EditorSelection.single(h,a)}}}function Ws(n,t,e,i){if(n.isComposite()){let s=-1,o=-1,r=-1,l=-1;for(let a=0,h=i,c=i;a<n.children.length;a++){let f=n.children[a],d=h+f.length;if(h<t&&d>e)return Ws(f,t,e,h);if(d>=t&&s==-1&&(s=a,o=h),h>e&&f.dom.parentNode==n.dom){r=a,l=c;break}c=d,h=d+f.breakAfter}return{from:o,to:l<0?i+n.length:l,startDOM:(s?n.children[s-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:r<n.children.length&&r>=0?n.children[r].dom:null}}else return n.isText()?{from:i,to:i+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function Ns(n,t){let e,{newSel:i}=t,s=n.state.selection.main,o=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(t.bounds){let{from:r,to:l}=t.bounds,a=s.from,h=null;(o===8||w.android&&t.text.length<l-r)&&(a=s.to,h="end");let c=Fs(n.state.doc.sliceString(r,l,Tt),t.text,a-r,h);c&&(w.chrome&&o==13&&c.toB==c.from+2&&t.text.slice(c.from,c.toB)==Tt+Tt&&c.toB--,e={from:r+c.from,to:r+c.toA,insert:u.Text.of(t.text.slice(c.from,c.toB).split(Tt))})}else i&&(!n.hasFocus&&n.state.facet($)||ce(i,s))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!s.empty&&i&&i.main.empty?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:(w.mac||w.android)&&e&&e.from==e.to&&e.from==s.head-1&&/^\. ?$/.test(e.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=u.EditorSelection.single(i.main.anchor-1,i.main.head-1)),e={from:e.from,to:e.to,insert:u.Text.of([e.insert.toString().replace("."," ")])}):e&&e.from>=s.from&&e.to<=s.to&&(e.from!=s.from||e.to!=s.to)&&s.to-s.from-(e.to-e.from)<=4?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,e.from).append(e.insert).append(n.state.doc.slice(e.to,s.to))}:n.state.doc.lineAt(s.from).to<s.to&&n.docView.lineHasWidget(s.to)&&n.inputState.insertingTextAt>Date.now()-50?e={from:s.from,to:s.to,insert:n.state.toText(n.inputState.insertingText)}:w.chrome&&e&&e.from==e.to&&e.from==s.head&&e.insert.toString()==`
3
+ `&&n.lineWrapping&&(i&&(i=u.EditorSelection.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:u.Text.of([" "])}),e)return hi(n,e,i,o);if(i&&!ce(i,s)){let r=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(r=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=Ps(n.state.facet(qt).map(a=>a(n)),i))),n.dispatch({selection:i,scrollIntoView:r,userEvent:l}),!0}else return!1}function hi(n,t,e,i=-1){if(w.ios&&n.inputState.flushIOSKey(t))return!0;let s=n.state.selection.main;if(w.android&&(t.to==s.to&&(t.from==s.from||t.from==s.from-1&&n.state.sliceDoc(t.from,s.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&mt(n.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&mt(n.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&mt(n.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let r,l=()=>r||(r=ho(n,t,e));return n.state.facet(vs).some(a=>a(n,t.from,t.to,o,l))||n.dispatch(l()),!0}function ho(n,t,e){let i,s=n.state,o=s.selection.main,r=-1;if(t.from==t.to&&t.from<o.from||t.from>o.to){let a=t.from<o.from?-1:1,h=a<0?o.from:o.to,c=Lt(s.facet(qt).map(f=>f(n)),h,a);t.from==c&&(r=c)}if(r>-1)i={changes:t,selection:u.EditorSelection.cursor(t.from+t.insert.length,-1)};else if(t.from>=o.from&&t.to<=o.to&&t.to-t.from>=(o.to-o.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&n.inputState.composing<0){let a=o.from<t.from?s.sliceDoc(o.from,t.from):"",h=o.to>t.to?s.sliceDoc(t.to,o.to):"";i=s.replaceSelection(n.state.toText(a+t.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let a=s.changes(t),h=e&&e.main.to<=a.newLength?e.main:void 0;if(s.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&t.to<=o.to+10&&t.to>=o.to-10){let c=n.state.sliceDoc(t.from,t.to),f,d=e&&Ls(n,e.main.head);if(d){let g=t.insert.length-(t.to-t.from);f={from:d.from,to:d.to-g}}else f=n.state.doc.lineAt(o.head);let p=o.to-t.to;i=s.changeByRange(g=>{if(g.from==o.from&&g.to==o.to)return{changes:a,range:h||g.map(a)};let m=g.to-p,b=m-c.length;if(n.state.sliceDoc(b,m)!=c||m>=f.from&&b<=f.to)return{range:g};let y=s.changes({from:b,to:m,insert:t.insert}),x=g.to-o.to;return{changes:y,range:h?u.EditorSelection.range(Math.max(0,h.anchor+x),Math.max(0,h.head+x)):g.map(y)}})}else i={changes:a,selection:h&&s.selection.replaceRange(h)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function Fs(n,t,e,i){let s=Math.min(n.length,t.length),o=0;for(;o<s&&n.charCodeAt(o)==t.charCodeAt(o);)o++;if(o==s&&n.length==t.length)return null;let r=n.length,l=t.length;for(;r>0&&l>0&&n.charCodeAt(r-1)==t.charCodeAt(l-1);)r--,l--;if(i=="end"){let a=Math.max(0,o-Math.min(r,l));e-=r+a-o}if(r<o&&n.length<t.length){let a=e<=o&&e>=r?o-e:0;o-=a,l=o+(l-r),r=o}else if(l<o){let a=e<=o&&e>=l?o-e:0;o-=a,r=o+(r-l),l=o}return{from:o,toA:r,toB:l}}function co(n){let t=[];if(n.root.activeElement!=n.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:o}=n.observer.selectionRange;return e&&(t.push(new Di(e,i)),(s!=e||o!=i)&&t.push(new Di(s,o))),t}function fo(n,t){if(n.length==0)return null;let e=n[0].pos,i=n.length==2?n[1].pos:e;return e>-1&&i>-1?u.EditorSelection.single(e+t,i+t):null}function ce(n,t){return t.head==n.main.head&&t.anchor==n.main.anchor}class uo{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,w.safari&&t.contentDOM.addEventListener("input",()=>null),w.gecko&&Do(t.contentDOM.ownerDocument)}handleEvent(t){!So(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let s of i.observers)s(this.view,e);for(let s of i.handlers){if(e.defaultPrevented)break;if(s(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=po(t),i=this.handlers,s=this.view.contentDOM;for(let o in e)if(o!="scroll"){let r=!e[o].handlers.length,l=i[o];l&&r!=!l.handlers.length&&(s.removeEventListener(o,this.handleEvent),l=null),l||s.addEventListener(o,this.handleEvent,{passive:r})}for(let o in i)o!="scroll"&&!e[o]&&s.removeEventListener(o,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&Is.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),w.android&&w.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return w.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=Vs.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||go.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,mt(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return!/^key/.test(t.type)||t.synthetic?!1:this.composing>0?!0:w.safari&&!w.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Oi(n,t){return(e,i)=>{try{return t.call(n,i,e)}catch(s){q(e.state,s)}}}function po(n){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec,o=s&&s.plugin.domEventHandlers,r=s&&s.plugin.domEventObservers;if(o)for(let l in o){let a=o[l];a&&e(l).handlers.push(Oi(i.value,a))}if(r)for(let l in r){let a=r[l];a&&e(l).observers.push(Oi(i.value,a))}}for(let i in K)e(i).handlers.push(K[i]);for(let i in I)e(i).observers.push(I[i]);return t}const Vs=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],go="dthko",Is=[16,17,18,20,91,92,224,225],Yt=6;function Xt(n){return Math.max(0,n)*.7+8}function mo(n,t){return Math.max(Math.abs(n.clientX-t.clientX),Math.abs(n.clientY-t.clientY))}class bo{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=wn(t.contentDOM),this.atoms=t.state.facet(qt).map(r=>r(t));let o=t.contentDOM.ownerDocument;o.addEventListener("mousemove",this.move=this.move.bind(this)),o.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(u.EditorState.allowMultipleSelections)&&yo(t,e),this.dragging=xo(t,e)&&Ks(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&mo(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,s=0,o=0,r=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:r}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:o,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=ai(this.view);t.clientX-a.left<=s+Yt?e=-Xt(s-t.clientX):t.clientX+a.right>=r-Yt&&(e=Xt(t.clientX-r)),t.clientY-a.top<=o+Yt?i=-Xt(o-t.clientY):t.clientY+a.bottom>=l-Yt&&(i=Xt(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=Ps(this.atoms,this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function yo(n,t){let e=n.state.facet(ys);return e.length?e[0](t):w.mac?t.metaKey:t.ctrlKey}function wo(n,t){let e=n.state.facet(ws);return e.length?e[0](t):w.mac?!t.altKey:!t.ctrlKey}function xo(n,t){let{main:e}=n.state.selection;if(e.empty)return!1;let i=xt(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let o=0;o<s.length;o++){let r=s[o];if(r.left<=t.clientX&&r.right>=t.clientX&&r.top<=t.clientY&&r.bottom>=t.clientY)return!0}return!1}function So(n,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=n.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=B.get(e))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(t))return!1;return!0}const K=Object.create(null),I=Object.create(null),zs=w.ie&&w.ie_version<15||w.ios&&w.webkit_version<604;function vo(n){let t=n.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{n.focus(),e.remove(),qs(n,e.value)},50)}function we(n,t,e){for(let i of n.facet(t))e=i(e,n);return e}function qs(n,t){t=we(n.state,ni,t);let{state:e}=n,i,s=1,o=e.toText(t),r=o.lines==e.selection.ranges.length;if(Ye!=null&&e.selection.ranges.every(a=>a.empty)&&Ye==o.toString()){let a=-1;i=e.changeByRange(h=>{let c=e.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=e.toText((r?o.line(s++).text:t)+e.lineBreak);return{changes:{from:c.from,insert:f},range:u.EditorSelection.cursor(h.from+f.length)}})}else r?i=e.changeByRange(a=>{let h=o.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:u.EditorSelection.cursor(a.from+h.length)}}):i=e.replaceSelection(o);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}I.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};K.keydown=(n,t)=>(n.inputState.setSelectionOrigin("select"),t.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);I.touchstart=(n,t)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};I.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};K.mousedown=(n,t)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of n.state.facet(xs))if(e=i(n,t),e)break;if(!e&&t.button==0&&(e=Mo(n,t)),e){let i=!n.hasFocus;n.inputState.startMouseSelection(new bo(n,t,e,i)),i&&n.observer.ignore(()=>{hs(n.contentDOM);let o=n.root.activeElement;o&&!o.contains(n.contentDOM)&&o.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(t),s.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Bi(n,t,e,i){if(i==1)return u.EditorSelection.cursor(t,e);if(i==2)return to(n.state,t,e);{let s=n.docView.lineAt(t,e),o=n.state.doc.lineAt(s?s.posAtEnd:t),r=s?s.posAtStart:o.from,l=s?s.posAtEnd:o.to;return l<n.state.doc.length&&l==o.to&&l++,u.EditorSelection.range(r,l)}}const Co=w.ie&&w.ie_version<=11;let Ei=null,Ri=0,Li=0;function Ks(n){if(!Co)return n.detail;let t=Ei,e=Li;return Ei=n,Li=Date.now(),Ri=!t||e>Date.now()-400&&Math.abs(t.clientX-n.clientX)<2&&Math.abs(t.clientY-n.clientY)<2?(Ri+1)%3:1}function Mo(n,t){let e=n.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),i=Ks(t),s=n.state.selection;return{update(o){o.docChanged&&(e.pos=o.changes.mapPos(e.pos),s=s.map(o.changes))},get(o,r,l){let a=n.posAndSideAtCoords({x:o.clientX,y:o.clientY},!1),h,c=Bi(n,a.pos,a.assoc,i);if(e.pos!=a.pos&&!r){let f=Bi(n,e.pos,e.assoc,i),d=Math.min(f.from,c.from),p=Math.max(f.to,c.to);c=d<c.from?u.EditorSelection.range(d,p):u.EditorSelection.range(p,d)}return r?s.replaceRange(s.main.extend(c.from,c.to)):l&&i==1&&s.ranges.length>1&&(h=ko(s,a.pos))?h:l?s.addRange(c):u.EditorSelection.create([c])}}}function ko(n,t){for(let e=0;e<n.ranges.length;e++){let{from:i,to:s}=n.ranges[e];if(i<=t&&s>=t)return u.EditorSelection.create(n.ranges.slice(0,e).concat(n.ranges.slice(e+1)),n.mainIndex==e?0:n.mainIndex-(n.mainIndex>e?1:0))}return null}K.dragstart=(n,t)=>{let{selection:{main:e}}=n.state;if(t.target.draggable){let s=n.docView.tile.nearest(t.target);if(s&&s.isWidget()){let o=s.posAtStart,r=o+s.length;(o>=e.to||r<=e.from)&&(e=u.EditorSelection.range(o,r))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",we(n.state,oi,n.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};K.dragend=n=>(n.inputState.draggedContent=null,!1);function Pi(n,t,e,i){if(e=we(n.state,ni,e),!e)return;let s=n.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:o}=n.inputState,r=i&&o&&wo(n,t)?{from:o.from,to:o.to}:null,l={from:s,insert:e},a=n.state.changes(r?[r,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:r?"move.drop":"input.drop"}),n.inputState.draggedContent=null}K.drop=(n,t)=>{if(!t.dataTransfer)return!1;if(n.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),s=0,o=()=>{++s==e.length&&Pi(n,t,i.filter(r=>r!=null).join(n.state.lineBreak),!1)};for(let r=0;r<e.length;r++){let l=new FileReader;l.onerror=o,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[r]=l.result),o()},l.readAsText(e[r])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return Pi(n,t,i,!0),!0}return!1};K.paste=(n,t)=>{if(n.state.readOnly)return!0;n.observer.flush();let e=zs?null:t.clipboardData;return e?(qs(n,e.getData("text/plain")||e.getData("text/uri-list")),!0):(vo(n),!1)};function Ao(n,t){let e=n.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function To(n){let t=[],e=[],i=!1;for(let s of n.selection.ranges)s.empty||(t.push(n.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:o}of n.selection.ranges){let r=n.doc.lineAt(o);r.number>s&&(t.push(r.text),e.push({from:r.from,to:Math.min(n.doc.length,r.to+1)})),s=r.number}i=!0}return{text:we(n,oi,t.join(n.lineBreak)),ranges:e,linewise:i}}let Ye=null;K.copy=K.cut=(n,t)=>{let e=xt(n.root);if(e&&!Bt(n.contentDOM,e))return!1;let{text:i,ranges:s,linewise:o}=To(n.state);if(!i&&!o)return!1;Ye=o?i:null,t.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:s,scrollIntoView:!0,userEvent:"delete.cut"});let r=zs?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",i),!0):(Ao(n,i),!1)};const _s=u.Annotation.define();function js(n,t){let e=[];for(let i of n.facet(Cs)){let s=i(n,t);s&&e.push(s)}return e.length?n.update({effects:e,annotations:_s.of(!0)}):null}function Gs(n){setTimeout(()=>{let t=n.hasFocus;if(t!=n.inputState.notifiedFocused){let e=js(n.state,t);e?n.dispatch(e):n.update([])}},10)}I.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Gs(n)};I.blur=n=>{n.observer.clearSelectionRange(),Gs(n)};I.compositionstart=I.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};I.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,w.chrome&&w.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};I.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};K.beforeinput=(n,t)=>{var e,i;if((t.inputType=="insertText"||t.inputType=="insertCompositionText")&&(n.inputState.insertingText=t.data,n.inputState.insertingTextAt=Date.now()),t.inputType=="insertReplacementText"&&n.observer.editContext){let o=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),r=t.getTargetRanges();if(o&&r.length){let l=r[0],a=n.posAtDOM(l.startContainer,l.startOffset),h=n.posAtDOM(l.endContainer,l.endOffset);return hi(n,{from:a,to:h,insert:n.state.toText(o)},null),!0}}let s;if(w.chrome&&w.android&&(s=Vs.find(o=>o.inputType==t.inputType))&&(n.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let o=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>o+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return w.ios&&t.inputType=="deleteContentForward"&&n.observer.flushSoon(),w.safari&&t.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>I.compositionend(n,t),20),!1};const Hi=new Set;function Do(n){Hi.has(n)||(Hi.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Wi=["pre-wrap","normal","pre-line","break-spaces"];let Ct=!1;function Ni(){Ct=!1}class Oo{constructor(t){this.lineWrapping=t,this.doc=u.Text.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Wi.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,o,r){let l=Wi.indexOf(t)>-1,a=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=o,a){this.heightSamples={};for(let h=0;h<r.length;h++){let c=r[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class Bo{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class F{constructor(t,e,i,s,o){this.from=t,this.length=e,this.top=i,this.height=s,this._content=o}get type(){return typeof this._content=="number"?exports.BlockType.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof at?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new F(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var T=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(T||(T={}));const se=.001;class H{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>se&&(Ct=!0),this.height=t)}replace(t,e,i){return H.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let o=this,r=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=s[l],d=o.lineAt(a,T.ByPosNoHeight,i.setDoc(e),0,0),p=d.to>=h?d:o.lineAt(h,T.ByPosNoHeight,i,0,0);for(f+=p.to-h,h=p.to;l>0&&d.from<=s[l-1].toA;)a=s[l-1].fromA,c=s[l-1].fromB,l--,a<d.from&&(d=o.lineAt(a,T.ByPosNoHeight,i,0,0));c+=d.from-a,a=d.from;let g=ci.build(i.setDoc(r),t,c,f);o=fe(o,o.replace(a,h,g))}return o.updateHeight(i,0)}static empty(){return new N(0,0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,o=0;for(;;)if(e==i)if(s>o*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(o>s*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,o-=l.size}else break;else if(s<o){let l=t[e++];l&&(s+=l.size)}else{let l=t[--i];l&&(o+=l.size)}let r=0;return t[e-1]==null?(r=1,e--):t[e]==null&&(r=1,i++),new Ro(H.of(t.slice(0,e)),r,H.of(t.slice(i)))}}function fe(n,t){return n==t?n:(n.constructor!=t.constructor&&(Ct=!0),t)}H.prototype.size=1;const Eo=O.replace({});class Ys extends H{constructor(t,e,i){super(t,e),this.deco=i,this.spaceAbove=0}mainBlock(t,e){return new F(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(t,e,i,s){return this.spaceAbove&&t<i+this.spaceAbove?new F(s,0,i,this.spaceAbove,Eo):this.mainBlock(i,s)}lineAt(t,e,i,s,o){let r=this.mainBlock(s,o);return this.spaceAbove?this.blockAt(0,i,s,o).join(r):r}forEachLine(t,e,i,s,o,r){t<=o+this.length&&e>=o&&r(this.lineAt(0,T.ByPos,i,s,o))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class N extends Ys{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new F(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof N||s instanceof R&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof R?s=new N(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):H.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class R extends H{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,o=s-i+1,r,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.lineHeight*o);r=a/o,this.length>o+1&&(l=(this.height-a)/(this.length-o-1))}else r=this.height/o;return{firstLine:i,lastLine:s,perLine:r,perChar:l}}blockAt(t,e,i,s){let{firstLine:o,lastLine:r,perLine:l,perChar:a}=this.heightMetrics(e,s);if(e.lineWrapping){let h=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),c=e.doc.lineAt(h),f=l+c.length*a,d=Math.max(i,t-f/2);return new F(c.from,c.length,d,f,0)}else{let h=Math.max(0,Math.min(r-o,Math.floor((t-i)/l))),{from:c,length:f}=e.doc.line(o+h);return new F(c,f,i+l*h,l,0)}}lineAt(t,e,i,s,o){if(e==T.ByHeight)return this.blockAt(t,i,s,o);if(e==T.ByPosNoHeight){let{from:p,to:g}=i.doc.lineAt(t);return new F(p,g-p,0,0,0)}let{firstLine:r,perLine:l,perChar:a}=this.heightMetrics(i,o),h=i.doc.lineAt(t),c=l+h.length*a,f=h.number-r,d=s+l*f+a*(h.from-o-f);return new F(h.from,h.length,Math.max(s,Math.min(d,s+this.height-c)),c,0)}forEachLine(t,e,i,s,o,r){t=Math.max(t,o),e=Math.min(e,o+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,o);for(let c=t,f=s;c<=e;){let d=i.doc.lineAt(c);if(c==t){let g=d.number-l;f+=a*g+h*(t-o-g)}let p=a+h*d.length;r(new F(d.from,d.length,f,p,0)),f+=p,c=d.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let o=i[i.length-1];o instanceof R?i[i.length-1]=new R(o.length+s):i.push(null,new R(s-1))}if(t>0){let o=i[0];o instanceof R?i[0]=new R(t+o.length):i.unshift(new R(t-1),null)}return H.of(i)}decomposeLeft(t,e){e.push(new R(t-1),null)}decomposeRight(t,e){e.push(null,new R(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let o=e+this.length;if(s&&s.from<=e+this.length&&s.more){let r=[],l=Math.max(e,s.from),a=-1;for(s.from>e&&r.push(new R(s.from-e-1).updateHeight(t,e));l<=o&&s.more;){let c=t.doc.lineAt(l).length;r.length&&r.push(null);let f=s.heights[s.index++],d=0;f<0&&(d=-f,f=s.heights[s.index++]),a==-1?a=f:Math.abs(f-a)>=se&&(a=-2);let p=new N(c,f,d);p.outdated=!1,r.push(p),l+=c+1}l<=o&&r.push(null,new R(o-l).updateHeight(t,l));let h=H.of(r);return(a<0||Math.abs(h.height-this.height)>=se||Math.abs(a-this.heightMetrics(t,e).perLine)>=se)&&(Ct=!0),fe(this,h)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Ro extends H{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let o=i+this.left.height;return t<o?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,o,s+this.left.length+this.break)}lineAt(t,e,i,s,o){let r=s+this.left.height,l=o+this.left.length+this.break,a=e==T.ByHeight?t<r:t<l,h=a?this.left.lineAt(t,e,i,s,o):this.right.lineAt(t,e,i,r,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=e==T.ByPosNoHeight?T.ByPosNoHeight:T.ByPos;return a?h.join(this.right.lineAt(l,c,i,r,l)):this.left.lineAt(l,c,i,s,o).join(h)}forEachLine(t,e,i,s,o,r){let l=s+this.left.height,a=o+this.left.length+this.break;if(this.break)t<a&&this.left.forEachLine(t,e,i,s,o,r),e>=a&&this.right.forEachLine(t,e,i,l,a,r);else{let h=this.lineAt(a,T.ByPos,i,s,o);t<h.from&&this.left.forEachLine(t,h.from-1,i,s,o,r),h.to>=t&&h.from<=e&&r(h),e>h.to&&this.right.forEachLine(h.to+1,e,i,l,a,r)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let o=[];t>0&&this.decomposeLeft(t,o);let r=o.length;for(let l of i)o.push(l);if(t>0&&Fi(o,r-1),e<this.length){let l=o.length;this.decomposeRight(e,o),Fi(o,l)}return H.of(o)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?H.of(this.break?[t,null,e]:[t,e]):(this.left=fe(this.left,t),this.right=fe(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:o,right:r}=this,l=e+o.length+this.break,a=null;return s&&s.from<=e+o.length&&s.more?a=o=o.updateHeight(t,e,i,s):o.updateHeight(t,e,i),s&&s.from<=l+r.length&&s.more?a=r=r.updateHeight(t,l,i,s):r.updateHeight(t,l,i),a?this.balanced(o,r):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Fi(n,t){let e,i;n[t]==null&&(e=n[t-1])instanceof R&&(i=n[t+1])instanceof R&&n.splice(t-1,3,new R(e.length+1+i.length))}const Lo=5;class ci{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof N?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new N(i-this.pos,-1,0)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,o=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let r=e-t;i.block?this.addBlock(new Ys(r,s,i)):(r||o||s>=Lo)&&this.addLineDeco(s,o,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new N(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new R(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof N)return t;let e=new N(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof N)&&!this.isCovered?this.nodes.push(new N(0,-1,0)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof N&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let o=new ci(i,t);return u.RangeSet.spans(e,i,s,o,0),o.finish(i)}}function Po(n,t,e){let i=new Ho;return u.RangeSet.compare(n,t,e,i,0),i.changes}class Ho{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&gt(t,e,this.changes,5)}}function Wo(n,t){let e=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,o=Math.max(0,e.left),r=Math.min(s.innerWidth,e.right),l=Math.max(0,e.top),a=Math.min(s.innerHeight,e.bottom);for(let h=n.parentNode;h&&h!=i.body;)if(h.nodeType==1){let c=h,f=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&f.overflow!="visible"){let d=c.getBoundingClientRect();o=Math.max(o,d.left),r=Math.min(r,d.right),l=Math.max(l,d.top),a=Math.min(h==n.parentNode?s.innerHeight:a,d.bottom)}h=f.position=="absolute"||f.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:o-e.left,right:Math.max(o,r)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function No(n){let t=n.getBoundingClientRect(),e=n.ownerDocument.defaultView||window;return t.left<e.innerWidth&&t.right>0&&t.top<e.innerHeight&&t.bottom>0}function Fo(n,t){let e=n.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class De{constructor(t,e,i,s){this.from=t,this.to=e,this.size=i,this.displaySize=s}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],o=e[i];if(s.from!=o.from||s.to!=o.to||s.size!=o.size)return!1}return!0}draw(t,e){return O.replace({widget:new Vo(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class Vo extends st{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class Vi{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Ii,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=exports.Direction.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(ri).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Oo(e),this.stateDeco=zi(t),this.heightMap=H.empty().applyChanges(this.stateDeco,u.Text.empty,this.heightOracle.setDoc(t.doc),[new V(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=O.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:o,to:r})=>s>=o&&s<=r)){let{from:o,to:r}=this.lineBlockAt(s);t.push(new $t(o,r))}}return this.viewports=t.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Ii:new fi(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Dt(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=zi(this.state);let s=t.changedRanges,o=V.extendWithRanges(s,Po(i,this.stateDeco,t?t.changes:u.ChangeSet.empty(this.state.doc.length))),r=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Ni(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),o),(this.heightMap.height!=r||Ct)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let a=o.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,t.flags|=this.updateForViewport(),(h||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(ks)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,o=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?exports.Direction.RTL:exports.Direction.LTR;let r=this.heightOracle.mustRefreshForWrapping(o)||this.mustMeasureContent,l=e.getBoundingClientRect(),a=r||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:k,scaleY:v}=as(e,l);(k>.005&&Math.abs(this.scaleX-k)>.005||v>.005&&Math.abs(this.scaleY-v)>.005)&&(this.scaleX=k,this.scaleY=v,h|=16,r=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,d=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=d)&&(this.paddingTop=f,this.paddingBottom=d,h|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,h|=16);let p=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=p&&(this.scrollAnchorHeight=-1,this.scrollTop=p),this.scrolledToBottom=cs(t.scrollDOM);let g=(this.printing?Fo:Wo)(e,this.paddingTop),m=g.top-this.pixelViewport.top,b=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(a=!0)),!this.inView&&!this.scrollTarget&&!No(t.dom))return 0;let x=l.width;if((this.contentDOMWidth!=x||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,h|=16),a){let k=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(k)&&(r=!0),r||s.lineWrapping&&Math.abs(x-this.contentDOMWidth)>s.charWidth){let{lineHeight:v,charWidth:S,textHeight:D}=t.docView.measureTextSize();r=v>0&&s.refresh(o,v,S,D,Math.max(5,x/S),k),r&&(t.docView.minWidth=0,h|=16)}m>0&&b>0?c=Math.max(m,b):m<0&&b<0&&(c=Math.min(m,b)),Ni();for(let v of this.viewports){let S=v.from==this.viewport.from?k:t.docView.measureVisibleLineHeights(v);this.heightMap=(r?H.empty().applyChanges(this.stateDeco,u.Text.empty,this.heightOracle,[new V(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,r,new Bo(v.from,S))}Ct&&(h|=2)}let C=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return C&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||C)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,o=this.heightOracle,{visibleTop:r,visibleBottom:l}=this,a=new $t(s.lineAt(r-i*1e3,T.ByHeight,o,0,0).from,s.lineAt(l+(1-i)*1e3,T.ByHeight,o,0,0).to);if(e){let{head:h}=e.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(h,T.ByPos,o,0,0),d;e.y=="center"?d=(f.top+f.bottom)/2-c/2:e.y=="start"||e.y=="nearest"&&h<a.from?d=f.top:d=f.bottom-c,a=new $t(s.lineAt(d-1e3/2,T.ByHeight,o,0,0).from,s.lineAt(d+c+1e3/2,T.ByHeight,o,0,0).to)}}return a}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new $t(this.heightMap.lineAt(i,T.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,T.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,T.ByPos,this.heightOracle,0,0),{bottom:o}=this.heightMap.lineAt(e,T.ByPos,this.heightOracle,0,0),{visibleTop:r,visibleBottom:l}=this;return(t==0||s<=r-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||o>=l+Math.max(10,Math.min(i,250)))&&s>r-2*1e3&&o<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new De(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,o=s>>1,r=s<<1;if(this.defaultTextDirection!=exports.Direction.LTR&&!i)return[];let l=[],a=(c,f,d,p)=>{if(f-c<o)return;let g=this.state.selection.main,m=[g.from];g.empty||m.push(g.to);for(let y of m)if(y>c&&y<f){a(c,y-10,d,p),a(y+10,f,d,p);return}let b=zo(t,y=>y.from>=d.from&&y.to<=d.to&&Math.abs(y.from-c)<o&&Math.abs(y.to-f)<o&&!m.some(x=>y.from<x&&y.to>x));if(!b){if(f<d.to&&e&&i&&e.visibleRanges.some(C=>C.from<=f&&C.to>=f)){let C=e.moveToLineBoundary(u.EditorSelection.cursor(f),!1,!0).head;C>c&&(f=C)}let y=this.gapSize(d,c,f,p),x=i||y<2e6?y:2e6;b=new De(c,f,y,x)}l.push(b)},h=c=>{if(c.length<r||c.type!=exports.BlockType.Text)return;let f=Io(c.from,c.to,this.stateDeco);if(f.total<r)return;let d=this.scrollTarget?this.scrollTarget.range.head:null,p,g;if(i){let m=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,b,y;if(d!=null){let x=Qt(f,d),C=((this.visibleBottom-this.visibleTop)/2+m)/c.height;b=x-C,y=x+C}else b=(this.visibleTop-c.top-m)/c.height,y=(this.visibleBottom-c.top+m)/c.height;p=Ut(f,b),g=Ut(f,y)}else{let m=f.total*this.heightOracle.charWidth,b=s*this.heightOracle.charWidth,y=0;if(m>2e6)for(let S of t)S.from>=c.from&&S.from<c.to&&S.size!=S.displaySize&&S.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=S.size-S.displaySize);let x=this.pixelViewport.left+y,C=this.pixelViewport.right+y,k,v;if(d!=null){let S=Qt(f,d),D=((C-x)/2+b)/m;k=S-D,v=S+D}else k=(x-b)/m,v=(C+b)/m;p=Ut(f,k),g=Ut(f,v)}p>c.from&&a(c.from,p,c,f),g<c.to&&a(g,c.to,c,f)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(t,e,i,s){let o=Qt(s,i)-Qt(s,e);return this.heightOracle.lineWrapping?t.height*o:s.total*this.heightOracle.charWidth*o}updateLineGaps(t){De.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=O.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];u.RangeSet.spans(e,this.viewport.from,this.viewport.to,{span(o,r){i.push({from:o,to:r})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let o=0;o<i.length&&!(s&8);o++){let r=this.visibleRanges[o],l=i[o];(r.from!=l.from||r.to!=l.to)&&(s|=4,t&&t.mapPos(r.from,-1)==l.from&&t.mapPos(r.to,1)==l.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Dt(this.heightMap.lineAt(t,T.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Dt(this.heightMap.lineAt(this.scaler.fromDOM(t),T.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Dt(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class $t{constructor(t,e){this.from=t,this.to=e}}function Io(n,t,e){let i=[],s=n,o=0;return u.RangeSet.spans(e,n,t,{span(){},point(r,l){r>s&&(i.push({from:s,to:r}),o+=r-s),s=l}},20),s<t&&(i.push({from:s,to:t}),o+=t-s),{total:o,ranges:i}}function Ut({total:n,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(n*e);for(let s=0;;s++){let{from:o,to:r}=t[s],l=r-o;if(i<=l)return o+i;i-=l}}function Qt(n,t){let e=0;for(let{from:i,to:s}of n.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/n.total}function zo(n,t){for(let e of n)if(t(e))return e}const Ii={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function zi(n){let t=n.facet(me).filter(i=>typeof i!="function"),e=n.facet(li).filter(i=>typeof i!="function");return e.length&&t.push(u.RangeSet.join(e)),t}class fi{constructor(t,e,i){let s=0,o=0,r=0;this.viewports=i.map(({from:l,to:a})=>{let h=e.lineAt(l,T.ByPos,t,0,0).top,c=e.lineAt(a,T.ByPos,t,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let l of this.viewports)l.domTop=r+(l.top-o)*this.scale,r=l.domBottom=l.domTop+(l.bottom-l.top),o=l.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.top)return s+(t-i)*this.scale;if(t<=o.bottom)return o.domTop+(t-o.top);i=o.bottom,s=o.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let o=e<this.viewports.length?this.viewports[e]:null;if(!o||t<o.domTop)return i+(t-s)/this.scale;if(t<=o.domBottom)return o.top+(t-o.domTop);i=o.bottom,s=o.domBottom}}eq(t){return t instanceof fi?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function Dt(n,t){if(t.scale==1)return n;let e=t.toDOM(n.top),i=t.toDOM(n.bottom);return new F(n.from,n.length,e,i-e,Array.isArray(n._content)?n._content.map(s=>Dt(s,t)):n._content)}const Jt=u.Facet.define({combine:n=>n.join(" ")}),Xe=u.Facet.define({combine:n=>n.indexOf(!0)>-1}),$e=yt.StyleModule.newName(),Xs=yt.StyleModule.newName(),$s=yt.StyleModule.newName(),Us={"&light":"."+Xs,"&dark":"."+$s};function Ue(n,t,e){return new yt.StyleModule(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):n+" "+i}})}const qo=Ue("."+$e,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Us),Ko={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Oe=w.ie&&w.ie_version<=11;class _o{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new xn,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(w.ie&&w.ie_version<=11||w.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&w.android&&t.constructor.EDIT_CONTEXT!==!1&&!(w.chrome&&w.chrome_version<126)&&(this.editContext=new Go(t),t.state.facet($)&&(t.contentDOM.editContext=this.editContext.editContext)),Oe&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet($)?i.root.activeElement!=this.dom:!Bt(this.dom,s))return;let o=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(o&&o.isWidget()&&o.widget.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(w.ie&&w.ie_version<=11||w.android&&w.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Rt(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=xt(t.root);if(!e)return!1;let i=w.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&jo(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=Bt(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&vn(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Ko),Oe&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Oe&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let s=()=>{let o=this.delayedAndroidKey;o&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=o.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&o.force&&mt(this.dom,o.key,o.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let o of t){let r=this.readMutation(o);r&&(r.typeOver&&(s=!0),e==-1?{from:e,to:i}=r:(e=Math.min(r.from,e),i=Math.max(r.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&Bt(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let o=new ao(this.view,t,e,i);return this.view.docView.domChanged={newSel:o.newSel?o.newSel.main:null},o}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=Ns(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!ce(this.view.state.selection,e.newSel.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty(t.type=="attributes"),t.type=="childList"){let i=qi(e,t.previousSibling||t.target.previousSibling,-1),s=qi(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet($)!=t.state.facet($)&&(t.view.contentDOM.editContext=t.state.facet($)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function qi(n,t,e){for(;t;){let i=B.get(t);if(i&&i.parent==n)return i;let s=t.parentNode;t=s!=n.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function Ki(n,t){let e=t.startContainer,i=t.startOffset,s=t.endContainer,o=t.endOffset,r=n.docView.domAtPos(n.state.selection.main.anchor,1);return Rt(r.node,r.offset,s,o)&&([e,i,s,o]=[s,o,e,i]),{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:o}}function jo(n,t){if(t.getComposedRanges){let s=t.getComposedRanges(n.root)[0];if(s)return Ki(n,s)}let e=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),e=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),e?Ki(n,e):null}class Go{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let s=t.state.selection.main,{anchor:o,head:r}=s,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&o<this.from?l=o:a==this.to&&o>this.to&&(a=o);let c=Fs(t.state.sliceDoc(l,a),i.text,(h?s.from:s.to)-l,h?"end":null);if(!c){let d=u.EditorSelection.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));ce(d,s)||t.dispatch({selection:d,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:u.Text.of(i.text.slice(c.from,c.toB).split(`
4
+ `))};if((w.mac||w.android)&&f.from==r-1&&/^\. ?$/.test(i.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:u.Text.of([i.text.replace("."," ")])}),this.pendingContextChange=f,!t.state.readOnly){let d=this.to-this.from+(f.to-f.from+f.insert.length);hi(t,f,u.EditorSelection.single(this.toEditorPos(i.selectionStart,d),this.toEditorPos(i.selectionEnd,d)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),f.from<f.to&&!f.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],o=null;for(let r=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);r<l;r++){let a=t.coordsForChar(r);o=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||o||new DOMRect,s.push(o)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let o of i.getTextFormats()){let r=o.underlineStyle,l=o.underlineThickness;if(!/none/i.test(r)&&!/none/i.test(l)){let a=this.toEditorPos(o.rangeStart),h=this.toEditorPos(o.rangeEnd);if(a<h){let c=`text-decoration: underline ${/^[a-z]/.test(r)?r+" ":r=="Dashed"?"dashed ":r=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(O.mark({attributes:{style:c}}).range(a,h))}}}t.dispatch({effects:Ts.of(O.set(s))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(t.state)}};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=xt(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((o,r,l,a,h)=>{if(i)return;let c=h.length-(r-o);if(s&&r>=s.to)if(s.from==o&&s.to==r&&s.insert.eq(h)){s=this.pendingContextChange=null,e+=c,this.to+=c;return}else s=null,this.revertPending(t.state);if(o+=e,r+=e,r<=this.from)this.from+=c,this.to+=c;else if(o<this.to){if(o<this.from||r>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(o),this.toContextPos(r),h.toString()),this.to+=c}e+=c}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class M{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(s=>s.forEach(o=>i(o,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=t.root||Sn(t.parent)||document,this.viewState=new Vi(t.state||u.EditorState.create(t)),t.scrollTo&&t.scrollTo.is(Gt)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(ut).map(s=>new Ce(s));for(let s of this.plugins)s.update(this);this.observer=new _o(this),this.inputState=new uo(this),this.inputState.ensureHandlers(this.plugins),this.docView=new ki(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent=!0,this.requestMeasure()})}dispatch(...t){let e=t.length==1&&t[0]instanceof u.Transaction?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,o=this.state;for(let d of t){if(d.startState!=o)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");o=d.state}if(this.destroyed){this.viewState.state=o;return}let r=this.hasFocus,l=0,a=null;t.some(d=>d.annotation(_s))?(this.inputState.notifiedFocused=r,l=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,a=js(o,r),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(o.doc)||!this.state.selection.eq(o.selection))&&(c=null)):this.observer.clear(),o.facet(u.EditorState.phrases)!=this.state.facet(u.EditorState.phrases))return this.setState(o);s=Ft.create(this,o,t),s.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let d of t){if(f&&(f=f.map(d.changes)),d.scrollIntoView){let{main:p}=d.state.selection;f=new bt(p.empty?p:u.EditorSelection.cursor(p.head,p.head>p.anchor?-1:1))}for(let p of d.effects)p.is(Gt)&&(f=p.value.clip(this.state))}this.viewState.update(s,f),this.bidiCache=de.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(At)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(d=>d.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Jt)!=s.state.facet(Jt)&&(this.viewState.mustMeasureContent=!0),(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!s.empty)for(let d of this.state.facet(Ke))try{d(s)}catch(p){q(this.state,p,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Ns(this,c)&&h.force&&mt(this.contentDOM,h.key,h.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new Vi(t),this.plugins=t.facet(ut).map(i=>new Ce(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new ki(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(ut),i=t.state.facet(ut);if(e!=i){let s=[];for(let o of i){let r=e.indexOf(o);if(r<0)s.push(new Ce(o));else{let l=this.plugins[r];l.mustUpdate=t,s.push(l)}}for(let o of this.plugins)o.mustUpdate!=t&&o.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){q(this.state,i,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:o,scrollAnchorHeight:r}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(r=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(r<0)if(cs(i))o=-1,r=this.viewState.heightMap.height;else{let p=this.viewState.scrollAnchorAt(s);o=p.from,r=p.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let c=h.map(p=>{try{return p.read(this)}catch(g){return q(this.state,g),_i}}),f=Ft.create(this,this.state,[]),d=!1;f.flags|=a,e?e.flags|=a:e=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),d=this.docView.update(f),d&&this.docViewUpdate());for(let p=0;p<h.length;p++)if(c[p]!=_i)try{let g=h[p];g.write&&g.write(c[p],this)}catch(g){q(this.state,g)}if(d&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,r=-1;continue}else{let g=(o<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(o).top)-r;if(g>1||g<-1){s=s+g,i.scrollTop=s/this.scaleY,r=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Ke))l(e)}get themeClasses(){return $e+" "+(this.state.facet(Xe)?$s:Xs)+" "+this.state.facet(Jt)}updateAttrs(){let t=ji(this,Ds,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet($)?"true":"false",class:"cm-content",style:`${w.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),ji(this,ri,e);let i=this.observer.ignore(()=>{let s=wi(this.contentDOM,this.contentAttrs,e),o=wi(this.dom,this.editorAttrs,t);return s||o});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(M.announce)){e&&(this.announceDOM.textContent=""),e=!1;let o=this.announceDOM.appendChild(document.createElement("div"));o.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(At);let t=this.state.facet(M.cspNonce);yt.StyleModule.mount(this.root,this.styleModules.concat(qo).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.plugin!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Te(this,t,Ai(this,t,e,i))}moveByGroup(t,e){return Te(this,t,Ai(this,t,e,i=>so(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),o=i[e?i.length-1:0];return u.EditorSelection.cursor(o.side(e,s)+t.from,o.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return io(this,t,e,i)}moveVertically(t,e,i){return Te(this,t,no(this,t,e,i))}domAtPos(t,e=1){return this.docView.domAtPos(t,e)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){this.readMeasured();let i=Ge(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=!0){return this.readMeasured(),Ge(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),o=this.bidiSpans(s),r=o[G.find(o,t-s.from,-1,e)];return Wt(i,r.dir==exports.Direction.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Ms)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Yo)return ms(t.length);let e=this.textDirectionAt(t.from),i;for(let o of this.bidiCache)if(o.from==t.from&&o.dir==e&&(o.fresh||gs(o.isolates,i=vi(this,t))))return o.order;i||(i=vi(this,t));let s=On(t.text,e,i);return this.bidiCache.push(new de(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||w.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{hs(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Gt.of(new bt(typeof t=="number"?u.EditorSelection.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Gt.of(new bt(u.EditorSelection.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return L.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return L.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=yt.StyleModule.newName(),s=[Jt.of(i),At.of(Ue(`.${i}`,t))];return e&&e.dark&&s.push(Xe.of(!0)),s}static baseTheme(t){return u.Prec.lowest(At.of(Ue("."+$e,t,Us)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&B.get(i)||B.get(t);return((e=s?.root)===null||e===void 0?void 0:e.view)||null}}M.styleModule=At;M.inputHandler=vs;M.clipboardInputFilter=ni;M.clipboardOutputFilter=oi;M.scrollHandler=As;M.focusChangeEffect=Cs;M.perLineTextDirection=Ms;M.exceptionSink=Ss;M.updateListener=Ke;M.editable=$;M.mouseSelectionStyle=xs;M.dragMovesSelection=ws;M.clickAddsSelectionRange=ys;M.decorations=me;M.blockWrappers=Os;M.outerDecorations=li;M.atomicRanges=qt;M.bidiIsolatedRanges=Bs;M.scrollMargins=Es;M.darkTheme=Xe;M.cspNonce=u.Facet.define({combine:n=>n.length?n[0]:""});M.contentAttributes=ri;M.editorAttributes=Ds;M.lineWrapping=M.contentAttributes.of({class:"cm-lineWrapping"});M.announce=u.StateEffect.define();const Yo=4096,_i={};class de{constructor(t,e,i,s,o,r){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=o,this.order=r}static update(t,e){if(e.empty&&!t.some(o=>o.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:exports.Direction.LTR;for(let o=Math.max(0,t.length-10);o<t.length;o++){let r=t[o];r.dir==s&&!e.touchesRange(r.from,r.to)&&i.push(new de(e.mapPos(r.from,1),e.mapPos(r.to,-1),r.dir,r.isolates,!1,r.order))}return i}}function ji(n,t,e){for(let i=n.state.facet(t),s=i.length-1;s>=0;s--){let o=i[s],r=typeof o=="function"?o(n):o;r&&ei(r,e)}return e}const Xo=w.mac?"mac":w.windows?"win":w.linux?"linux":"key";function $o(n,t){const e=n.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let s,o,r,l;for(let a=0;a<e.length-1;++a){const h=e[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))s=!0;else if(/^(c|ctrl|control)$/i.test(h))o=!0;else if(/^s(hift)?$/i.test(h))r=!0;else if(/^mod$/i.test(h))t=="mac"?l=!0:o=!0;else throw new Error("Unrecognized modifier name: "+h)}return s&&(i="Alt-"+i),o&&(i="Ctrl-"+i),l&&(i="Meta-"+i),r&&(i="Shift-"+i),i}function Zt(n,t,e){return t.altKey&&(n="Alt-"+n),t.ctrlKey&&(n="Ctrl-"+n),t.metaKey&&(n="Meta-"+n),e!==!1&&t.shiftKey&&(n="Shift-"+n),n}const Uo=u.Prec.default(M.domEventHandlers({keydown(n,t){return Zs(Js(t.state),n,t,"editor")}})),Qs=u.Facet.define({enables:Uo}),Gi=new WeakMap;function Js(n){let t=n.facet(Qs),e=Gi.get(t);return e||Gi.set(t,e=Zo(t.reduce((i,s)=>i.concat(s),[]))),e}function Qo(n,t,e){return Zs(Js(n.state),t,n,e)}let tt=null;const Jo=4e3;function Zo(n,t=Xo){let e=Object.create(null),i=Object.create(null),s=(r,l)=>{let a=i[r];if(a==null)i[r]=l;else if(a!=l)throw new Error("Key binding "+r+" is used both as a regular binding and as a multi-stroke prefix")},o=(r,l,a,h,c)=>{var f,d;let p=e[r]||(e[r]=Object.create(null)),g=l.split(/ (?!$)/).map(y=>$o(y,t));for(let y=1;y<g.length;y++){let x=g.slice(0,y).join(" ");s(x,!0),p[x]||(p[x]={preventDefault:!0,stopPropagation:!1,run:[C=>{let k=tt={view:C,prefix:x,scope:r};return setTimeout(()=>{tt==k&&(tt=null)},Jo),!0}]})}let m=g.join(" ");s(m,!1);let b=p[m]||(p[m]={preventDefault:!1,stopPropagation:!1,run:((d=(f=p._any)===null||f===void 0?void 0:f.run)===null||d===void 0?void 0:d.slice())||[]});a&&b.run.push(a),h&&(b.preventDefault=!0),c&&(b.stopPropagation=!0)};for(let r of n){let l=r.scope?r.scope.split(" "):["editor"];if(r.any)for(let h of l){let c=e[h]||(e[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=r;for(let d in c)c[d].run.push(p=>f(p,Qe))}let a=r[t]||r.key;if(a)for(let h of l)o(h,a,r.run,r.preventDefault,r.stopPropagation),r.shift&&o(h,"Shift-"+a,r.shift,r.preventDefault,r.stopPropagation)}return e}let Qe=null;function Zs(n,t,e,i){Qe=t;let s=Se.keyName(t),o=u.codePointAt(s,0),r=u.codePointSize(o)==s.length&&s!=" ",l="",a=!1,h=!1,c=!1;tt&&tt.view==e&&tt.scope==i&&(l=tt.prefix+" ",Is.indexOf(t.keyCode)<0&&(h=!0,tt=null));let f=new Set,d=b=>{if(b){for(let y of b.run)if(!f.has(y)&&(f.add(y),y(e)))return b.stopPropagation&&(c=!0),!0;b.preventDefault&&(b.stopPropagation&&(c=!0),h=!0)}return!1},p=n[i],g,m;return p&&(d(p[l+Zt(s,t,!r)])?a=!0:r&&(t.altKey||t.metaKey||t.ctrlKey)&&!(w.windows&&t.ctrlKey&&t.altKey)&&!(w.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(g=Se.base[t.keyCode])&&g!=s?(d(p[l+Zt(g,t,!0)])||t.shiftKey&&(m=Se.shift[t.keyCode])!=s&&m!=g&&d(p[l+Zt(m,t,!1)]))&&(a=!0):r&&t.shiftKey&&d(p[l+Zt(s,t,!0)])&&(a=!0),!a&&d(p._any)&&(a=!0)),h&&(a=!0),a&&c&&t.stopPropagation(),Qe=null,a}class Mt{constructor(t,e,i,s,o){this.className=t,this.left=e,this.top=i,this.width=s,this.height=o}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let o=tn(t);return[new Mt(e,s.left-o.left,s.top-o.top,null,s.bottom-s.top)]}else return tr(t,e,i)}}function tn(n){let t=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==exports.Direction.LTR?t.left:t.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:t.top-n.scrollDOM.scrollTop*n.scaleY}}function Yi(n,t,e,i){let s=n.coordsAtPos(t,e*2);if(!s)return i;let o=n.dom.getBoundingClientRect(),r=(s.top+s.bottom)/2,l=n.posAtCoords({x:o.left+1,y:r}),a=n.posAtCoords({x:o.right-1,y:r});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function tr(n,t,e){if(e.to<=n.viewport.from||e.from>=n.viewport.to)return[];let i=Math.max(e.from,n.viewport.from),s=Math.min(e.to,n.viewport.to),o=n.textDirection==exports.Direction.LTR,r=n.contentDOM,l=r.getBoundingClientRect(),a=tn(n),h=r.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),d=l.right-(c?parseInt(c.paddingRight):0),p=je(n,i,1),g=je(n,s,-1),m=p.type==exports.BlockType.Text?p:null,b=g.type==exports.BlockType.Text?g:null;if(m&&(n.lineWrapping||p.widgetLineBreaks)&&(m=Yi(n,i,1,m)),b&&(n.lineWrapping||g.widgetLineBreaks)&&(b=Yi(n,s,-1,b)),m&&b&&m.from==b.from&&m.to==b.to)return x(C(e.from,e.to,m));{let v=m?C(e.from,null,m):k(p,!1),S=b?C(null,e.to,b):k(g,!0),D=[];return(m||p).to<(b||g).from-(m&&b?1:0)||p.widgetLineBreaks>1&&v.bottom+n.defaultLineHeight/2<S.top?D.push(y(f,v.bottom,d,S.top)):v.bottom<S.top&&n.elementAtHeight((v.bottom+S.top)/2).type==exports.BlockType.Text&&(v.bottom=S.top=(v.bottom+S.top)/2),x(v).concat(D).concat(x(S))}function y(v,S,D,E){return new Mt(t,v-a.left,S-a.top,D-v,E-S)}function x({top:v,bottom:S,horizontal:D}){let E=[];for(let J=0;J<D.length;J+=2)E.push(y(D[J],v,D[J+1],S));return E}function C(v,S,D){let E=1e9,J=-1e9,Kt=[];function mi(nt,Z,ft,ot,kt){let Y=n.coordsAtPos(nt,nt==D.to?-2:2),X=n.coordsAtPos(ft,ft==D.from?2:-2);!Y||!X||(E=Math.min(Y.top,X.top,E),J=Math.max(Y.bottom,X.bottom,J),kt==exports.Direction.LTR?Kt.push(o&&Z?f:Y.left,o&&ot?d:X.right):Kt.push(!o&&ot?f:X.left,!o&&Z?d:Y.right))}let _t=v??D.from,jt=S??D.to;for(let nt of n.visibleRanges)if(nt.to>_t&&nt.from<jt)for(let Z=Math.max(nt.from,_t),ft=Math.min(nt.to,jt);;){let ot=n.state.doc.lineAt(Z);for(let kt of n.bidiSpans(ot)){let Y=kt.from+ot.from,X=kt.to+ot.from;if(Y>=ft)break;X>Z&&mi(Math.max(Y,Z),v==null&&Y<=_t,Math.min(X,ft),S==null&&X>=jt,kt.dir)}if(Z=ot.to+1,Z>=ft)break}return Kt.length==0&&mi(_t,v==null,jt,S==null,n.textDirection),{top:E,bottom:J,horizontal:Kt}}function k(v,S){let D=l.top+(S?v.top:v.bottom);return{top:D,bottom:D,horizontal:[]}}}function er(n,t){return n.constructor==t.constructor&&n.eq(t)}class ir{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(ne)!=t.state.facet(ne)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(ne);for(;e<i.length&&i[e]!=this.layer;)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;(t!=this.scaleX||e!=this.scaleY)&&(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some((e,i)=>!er(e,this.drawn[i]))){let e=this.dom.firstChild,i=0;for(let s of t)s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(s.draw(),e);for(;e;){let s=e.nextSibling;e.remove(),e=s}this.drawn=t,w.safari&&w.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const ne=u.Facet.define();function di(n){return[L.define(t=>new ir(t,n)),ne.of(n)]}const Vt=u.Facet.define({combine(n){return u.combineConfig(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function sr(n={}){return[Vt.of(n),nr,or,rr,ks.of(!0)]}function en(n){return n.startState.facet(Vt)!=n.state.facet(Vt)}const nr=di({above:!0,markers(n){let{state:t}=n,e=t.facet(Vt),i=[];for(let s of t.selection.ranges){let o=s==t.selection.main;if(s.empty||e.drawRangeCursor){let r=o?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:u.EditorSelection.cursor(s.head,s.head>s.anchor?-1:1);for(let a of Mt.forRange(n,r,l))i.push(a)}}return i},update(n,t){n.transactions.some(i=>i.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let e=en(n);return e&&Xi(n.state,t),n.docChanged||n.selectionSet||e},mount(n,t){Xi(t.state,n)},class:"cm-cursorLayer"});function Xi(n,t){t.style.animationDuration=n.facet(Vt).cursorBlinkRate+"ms"}const or=di({above:!1,markers(n){return n.state.selection.ranges.map(t=>t.empty?[]:Mt.forRange(n,"cm-selectionBackground",t)).reduce((t,e)=>t.concat(e))},update(n,t){return n.docChanged||n.selectionSet||n.viewportChanged||en(n)},class:"cm-selectionLayer"}),rr=u.Prec.highest(M.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),sn=u.StateEffect.define({map(n,t){return n==null?null:t.mapPos(n)}}),Ot=u.StateField.define({create(){return null},update(n,t){return n!=null&&(n=t.changes.mapPos(n)),t.effects.reduce((e,i)=>i.is(sn)?i.value:e,n)}}),lr=L.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var t;let e=n.state.field(Ot);e==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(Ot)!=e||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,t=n.state.field(Ot),e=t!=null&&n.coordsAtPos(t);if(!e)return null;let i=n.scrollDOM.getBoundingClientRect();return{left:e.left-i.left+n.scrollDOM.scrollLeft*n.scaleX,top:e.top-i.top+n.scrollDOM.scrollTop*n.scaleY,height:e.bottom-e.top}}drawCursor(n){if(this.cursor){let{scaleX:t,scaleY:e}=this.view;n?(this.cursor.style.left=n.left/t+"px",this.cursor.style.top=n.top/e+"px",this.cursor.style.height=n.height/e+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(Ot)!=n&&this.view.dispatch({effects:sn.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function ar(){return[Ot,lr]}function $i(n,t,e,i,s){t.lastIndex=0;for(let o=n.iterRange(e,i),r=e,l;!o.next().done;r+=o.value.length)if(!o.lineBreak)for(;l=t.exec(o.value);)s(r+l.index,l)}function hr(n,t){let e=n.visibleRanges;if(e.length==1&&e[0].from==n.viewport.from&&e[0].to==n.viewport.to)return e;let i=[];for(let{from:s,to:o}of e)s=Math.max(n.state.doc.lineAt(s).from,s-t),o=Math.min(n.state.doc.lineAt(o).to,o+t),i.length&&i[i.length-1].to>=s?i[i.length-1].to=o:i.push({from:s,to:o});return i}class nn{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:o,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,s)this.addMatch=(l,a,h,c)=>s(c,h,h+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,h,c)=>{let f=i(l,a,h);f&&c(h,h+l[0].length,f)};else if(i)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=o,this.maxLength=r}createDeco(t){let e=new u.RangeSetBuilder,i=e.add.bind(e);for(let{from:s,to:o}of hr(t,this.maxLength))$i(t.state.doc,this.regexp,s,o,(r,l)=>this.addMatch(l,t,r,i));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges((o,r,l,a)=>{a>=t.view.viewport.from&&l<=t.view.viewport.to&&(i=Math.min(l,i),s=Math.max(a,s))}),t.viewportMoved||s-i>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let o of t.visibleRanges){let r=Math.max(o.from,i),l=Math.min(o.to,s);if(l>=r){let a=t.state.doc.lineAt(r),h=a.to<l?t.state.doc.lineAt(l):a,c=Math.max(o.from,a.from),f=Math.min(o.to,h.to);if(this.boundary){for(;r>a.from;r--)if(this.boundary.test(a.text[r-1-a.from])){c=r;break}for(;l<h.to;l++)if(this.boundary.test(h.text[l-h.from])){f=l;break}}let d=[],p,g=(m,b,y)=>d.push(y.range(m,b));if(a==h)for(this.regexp.lastIndex=c-a.from;(p=this.regexp.exec(a.text))&&p.index<f-a.from;)this.addMatch(p,t,p.index+a.from,g);else $i(t.state.doc,this.regexp,c,f,(m,b)=>this.addMatch(b,t,m,g));e=e.update({filterFrom:c,filterTo:f,filter:(m,b)=>m<c||b>f,add:d})}}return e}}const Je=/x/.unicode!=null?"gu":"g",cr=new RegExp(`[\0-\b
5
+ --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Je),fr={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Be=null;function dr(){var n;if(Be==null&&typeof document<"u"&&document.body){let t=document.body.style;Be=((n=t.tabSize)!==null&&n!==void 0?n:t.MozTabSize)!=null}return Be||!1}const oe=u.Facet.define({combine(n){let t=u.combineConfig(n,{render:null,specialChars:cr,addSpecialChars:null});return(t.replaceTabs=!dr())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,Je)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,Je)),t}});function ur(n={}){return[oe.of(n),pr()]}let Ui=null;function pr(){return Ui||(Ui=L.fromClass(class{constructor(n){this.view=n,this.decorations=O.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(oe)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new nn({regexp:n.specialChars,decoration:(t,e,i)=>{let{doc:s}=e.state,o=u.codePointAt(t[0],0);if(o==9){let r=s.lineAt(i),l=e.state.tabSize,a=u.countColumn(r.text,l,i-r.from);return O.replace({widget:new yr((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[o]||(this.decorationCache[o]=O.replace({widget:new br(n,o)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let t=n.state.facet(oe);n.startState.facet(oe)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const gr="•";function mr(n){return n>=32?gr:n==10?"␤":String.fromCharCode(9216+n)}class br extends st{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=mr(this.code),i=t.state.phrase("Control character")+" "+(fr[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let o=document.createElement("span");return o.textContent=e,o.title=i,o.setAttribute("aria-label",i),o.className="cm-specialChar",o}ignoreEvent(){return!1}}class yr extends st{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function wr(){return Sr}const xr=O.line({class:"cm-activeLine"}),Sr=L.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let t=-1,e=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>t&&(e.push(xr.range(s.from)),t=s.from)}return O.set(e)}},{decorations:n=>n.decorations});class vr extends st{constructor(t){super(),this.content=t}toDOM(t){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(t):this.content.cloneNode(!0)),e.setAttribute("aria-hidden","true"),e}coordsAt(t){let e=t.firstChild?Et(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=Wt(e[0],i.direction!="rtl"),o=parseInt(i.lineHeight);return s.bottom-s.top>o*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+o}:s}ignoreEvent(){return!1}}function Cr(n){let t=L.fromClass(class{constructor(e){this.view=e,this.placeholder=n?O.set([O.widget({widget:new vr(n),side:1}).range(0)]):O.none}get decorations(){return this.view.state.doc.length?O.none:this.placeholder}},{decorations:e=>e.decorations});return typeof n=="string"?[t,M.contentAttributes.of({"aria-placeholder":n})]:t}const Ze=2e3;function Mr(n,t,e){let i=Math.min(t.line,e.line),s=Math.max(t.line,e.line),o=[];if(t.off>Ze||e.off>Ze||t.col<0||e.col<0){let r=Math.min(t.off,e.off),l=Math.max(t.off,e.off);for(let a=i;a<=s;a++){let h=n.doc.line(a);h.length<=l&&o.push(u.EditorSelection.range(h.from+r,h.to+l))}}else{let r=Math.min(t.col,e.col),l=Math.max(t.col,e.col);for(let a=i;a<=s;a++){let h=n.doc.line(a),c=u.findColumn(h.text,r,n.tabSize,!0);if(c<0)o.push(u.EditorSelection.cursor(h.to));else{let f=u.findColumn(h.text,l,n.tabSize);o.push(u.EditorSelection.range(h.from+c,h.from+f))}}}return o}function kr(n,t){let e=n.coordsAtPos(n.viewport.from);return e?Math.round(Math.abs((e.left-t)/n.defaultCharacterWidth)):-1}function Qi(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1),i=n.state.doc.lineAt(e),s=e-i.from,o=s>Ze?-1:s==i.length?kr(n,t.clientX):u.countColumn(i.text,n.state.tabSize,e-i.from);return{line:i.number,col:o,off:s}}function Ar(n,t){let e=Qi(n,t),i=n.state.selection;return e?{update(s){if(s.docChanged){let o=s.changes.mapPos(s.startState.doc.line(e.line).from),r=s.state.doc.lineAt(o);e={line:r.number,col:e.col,off:Math.min(e.off,r.length)},i=i.map(s.changes)}},get(s,o,r){let l=Qi(n,s);if(!l)return i;let a=Mr(n.state,e,l);return a.length?r?u.EditorSelection.create(a.concat(i.ranges)):u.EditorSelection.create(a):i}}:null}function Tr(n){let t=(e=>e.altKey&&e.button==0);return M.mouseSelectionStyle.of((e,i)=>t(i)?Ar(e,i):null)}const Dr={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},Or={style:"cursor: crosshair"};function Br(n={}){let[t,e]=Dr[n.key||"Alt"],i=L.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==t||e(s))},keyup(s){(s.keyCode==t||!e(s))&&this.set(!1)},mousemove(s){this.set(e(s))}}});return[i,M.contentAttributes.of(s=>{var o;return!((o=s.plugin(i))===null||o===void 0)&&o.isDown?Or:null})]}const te="-10000px";class on{constructor(t,e,i,s){this.facet=e,this.createTooltipView=i,this.removeTooltipView=s,this.input=t.state.facet(e),this.tooltips=this.input.filter(r=>r);let o=null;this.tooltipViews=this.tooltips.map(r=>o=i(r,o))}update(t,e){var i;let s=t.state.facet(this.facet),o=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(t);return!1}let r=[],l=e?[]:null;for(let a=0;a<o.length;a++){let h=o[a],c=-1;if(h){for(let f=0;f<this.tooltips.length;f++){let d=this.tooltips[f];d&&d.create==h.create&&(c=f)}if(c<0)r[a]=this.createTooltipView(h,a?r[a-1]:null),l&&(l[a]=!!h.above);else{let f=r[a]=this.tooltipViews[c];l&&(l[a]=e[c]),f.update&&f.update(t)}}}for(let a of this.tooltipViews)r.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return e&&(l.forEach((a,h)=>e[h]=a),e.length=l.length),this.input=s,this.tooltips=o,this.tooltipViews=r,!0}}function Er(n){let t=n.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:t.clientHeight,right:t.clientWidth}}const Ee=u.Facet.define({combine:n=>{var t,e,i;return{position:w.ios?"absolute":((t=n.find(s=>s.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=n.find(s=>s.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Er}}}),Ji=new WeakMap,ui=L.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=n.state.facet(Ee);this.position=t.position,this.parent=t.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new on(n,pi,(e,i)=>this.createTooltip(e,i),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(n,this.above);t&&this.observeIntersection();let e=t||n.geometryChanged,i=n.state.facet(Ee);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;e=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(n,t){let e=n.create(this.view),i=t?t.dom:null;if(e.dom.classList.add("cm-tooltip"),n.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",e.dom.appendChild(s)}return e.dom.style.position=this.position,e.dom.style.top=te,e.dom.style.left="0px",this.container.insertBefore(e.dom,i),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var n,t,e;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=1,t=1,e=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:o}=this.manager.tooltipViews[0];if(w.safari){let r=o.getBoundingClientRect();e=Math.abs(r.top+1e4)>1||Math.abs(r.left)>1}else e=!!o.offsetParent&&o.offsetParent!=this.container.ownerDocument.body}if(e||this.position=="absolute")if(this.parent){let o=this.parent.getBoundingClientRect();o.width&&o.height&&(n=o.width/this.parent.offsetWidth,t=o.height/this.parent.offsetHeight)}else({scaleX:n,scaleY:t}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),s=ai(this.view);return{visible:{left:i.left+s.left,top:i.top+s.top,right:i.right-s.right,bottom:i.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((o,r)=>{let l=this.manager.tooltipViews[r];return l.getCoords?l.getCoords(o.pos):this.view.coordsAtPos(o.pos)}),size:this.manager.tooltipViews.map(({dom:o})=>o.getBoundingClientRect()),space:this.view.state.facet(Ee).tooltipSpace(this.view),scaleX:n,scaleY:t,makeAbsolute:e}}writeMeasure(n){var t;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:e,space:i,scaleX:s,scaleY:o}=n,r=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,f=n.pos[l],d=n.size[l];if(!f||a.clip!==!1&&(f.bottom<=Math.max(e.top,i.top)||f.top>=Math.min(e.bottom,i.bottom)||f.right<Math.max(e.left,i.left)-.1||f.left>Math.min(e.right,i.right)+.1)){c.style.top=te;continue}let p=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,g=p?7:0,m=d.right-d.left,b=(t=Ji.get(h))!==null&&t!==void 0?t:d.bottom-d.top,y=h.offset||Lr,x=this.view.textDirection==exports.Direction.LTR,C=d.width>i.right-i.left?x?i.left:i.right-d.width:x?Math.max(i.left,Math.min(f.left-(p?14:0)+y.x,i.right-m)):Math.min(Math.max(i.left,f.left-m+(p?14:0)-y.x),i.right-m),k=this.above[l];!a.strictSide&&(k?f.top-b-g-y.y<i.top:f.bottom+b+g+y.y>i.bottom)&&k==i.bottom-f.bottom>f.top-i.top&&(k=this.above[l]=!k);let v=(k?f.top-i.top:i.bottom-f.bottom)-g;if(v<b&&h.resize!==!1){if(v<this.view.defaultLineHeight){c.style.top=te;continue}Ji.set(h,b),c.style.height=(b=v)/o+"px"}else c.style.height&&(c.style.height="");let S=k?f.top-b-g-y.y:f.bottom+g+y.y,D=C+m;if(h.overlap!==!0)for(let E of r)E.left<D&&E.right>C&&E.top<S+b&&E.bottom>S&&(S=k?E.top-b-2-g:E.bottom+g+2);if(this.position=="absolute"?(c.style.top=(S-n.parent.top)/o+"px",Zi(c,(C-n.parent.left)/s)):(c.style.top=S/o+"px",Zi(c,C/s)),p){let E=f.left+(x?y.x:-y.x)-(C+14-7);p.style.left=E/s+"px"}h.overlap!==!0&&r.push({left:C,top:S,right:D,bottom:S+b}),c.classList.toggle("cm-tooltip-above",k),c.classList.toggle("cm-tooltip-below",!k),h.positioned&&h.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=te}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Zi(n,t){let e=parseInt(n.style.left,10);(isNaN(e)||Math.abs(t-e)>1)&&(n.style.left=t+"px")}const Rr=M.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Lr={x:0,y:0},pi=u.Facet.define({enables:[ui,Rr]}),ue=u.Facet.define({combine:n=>n.reduce((t,e)=>t.concat(e),[])});class xe{static create(t){return new xe(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new on(t,ue,(e,i)=>this.createHostedView(e,i),e=>e.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)(t=e.destroy)===null||t===void 0||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let s=i[t];if(s!==void 0){if(e===void 0)e=s;else if(e!==s)return}}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Pr=pi.compute([ue],n=>{let t=n.facet(ue);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var i;return(i=e.end)!==null&&i!==void 0?i:e.pos})),create:xe.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class Hr{constructor(t,e,i,s,o){this.view=t,this.source=e,this.field=i,this.setHover=s,this.hoverTime=o,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:e}=this,i=t.docView.tile.nearest(e.target);if(!i)return;let s,o=1;if(i.isWidget())s=i.posAtStart;else{if(s=t.posAtCoords(e),s==null)return;let l=t.coordsAtPos(s);if(!l||e.y<l.top||e.y>l.bottom||e.x<l.left-t.defaultCharacterWidth||e.x>l.right+t.defaultCharacterWidth)return;let a=t.bidiSpans(t.state.doc.lineAt(s)).find(c=>c.from<=s&&c.to>=s),h=a&&a.dir==exports.Direction.RTL?-1:1;o=e.x<l.left?-h:h}let r=this.source(t,s,o);if(r?.then){let l=this.pending={pos:s};r.then(a=>{this.pending==l&&(this.pending=null,a&&!(Array.isArray(a)&&!a.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(a)?a:[a])}))},a=>q(t.state,a,"hover tooltip"))}else r&&!(Array.isArray(r)&&!r.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(r)?r:[r])})}get tooltip(){let t=this.view.plugin(ui),e=t?t.manager.tooltips.findIndex(i=>i.create==xe.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:o}=this;if(s.length&&o&&!Wr(o.dom,t)||this.pending){let{pos:r}=s[0]||this.pending,l=(i=(e=s[0])===null||e===void 0?void 0:e.end)!==null&&i!==void 0?i:r;(r==l?this.view.posAtCoords(this.lastMove)!=r:!Nr(this.view,r,l,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:i}=this;i&&i.dom.contains(t.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const ee=4;function Wr(n,t){let{left:e,right:i,top:s,bottom:o}=n.getBoundingClientRect(),r;if(r=n.querySelector(".cm-tooltip-arrow")){let l=r.getBoundingClientRect();s=Math.min(l.top,s),o=Math.max(l.bottom,o)}return t.clientX>=e-ee&&t.clientX<=i+ee&&t.clientY>=s-ee&&t.clientY<=o+ee}function Nr(n,t,e,i,s,o){let r=n.scrollDOM.getBoundingClientRect(),l=n.documentTop+n.documentPadding.top+n.contentHeight;if(r.left>i||r.right<i||r.top>s||Math.min(r.bottom,l)<s)return!1;let a=n.posAtCoords({x:i,y:s},!1);return a>=t&&a<=e}function Fr(n,t={}){let e=u.StateEffect.define(),i=u.StateField.define({create(){return[]},update(s,o){if(s.length&&(t.hideOnChange&&(o.docChanged||o.selection)?s=[]:t.hideOn&&(s=s.filter(r=>!t.hideOn(o,r))),o.docChanged)){let r=[];for(let l of s){let a=o.changes.mapPos(l.pos,-1,u.MapMode.TrackDel);if(a!=null){let h=Object.assign(Object.create(null),l);h.pos=a,h.end!=null&&(h.end=o.changes.mapPos(h.end)),r.push(h)}}s=r}for(let r of o.effects)r.is(e)&&(s=r.value),r.is(Ir)&&(s=[]);return s},provide:s=>ue.from(s)});return{active:i,extension:[i,L.define(s=>new Hr(s,n,i,e,t.hoverTime||300)),Pr]}}function Vr(n,t){let e=n.plugin(ui);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}const Ir=u.StateEffect.define(),ts=u.Facet.define({combine(n){let t,e;for(let i of n)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function zr(n,t){let e=n.plugin(rn),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const rn=L.fromClass(class{constructor(n){this.input=n.state.facet(pe),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(n));let t=n.state.facet(ts);this.top=new ie(n,!0,t.topContainer),this.bottom=new ie(n,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(n){let t=n.state.facet(ts);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new ie(n.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new ie(n.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=n.state.facet(pe);if(e!=this.input){let i=e.filter(a=>a),s=[],o=[],r=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(n.view),l.push(c)):(c=this.panels[h],c.update&&c.update(n)),s.push(c),(c.top?o:r).push(c)}this.specs=i,this.panels=s,this.top.sync(o),this.bottom.sync(r);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>M.scrollMargins.of(t=>{let e=t.plugin(n);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class ie{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=es(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=es(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function es(n){let t=n.nextSibling;return n.remove(),t}const pe=u.Facet.define({enables:rn});function qr(n,t){let e,i=new Promise(r=>e=r),s=r=>Kr(r,t,e);n.state.field(Re,!1)?n.dispatch({effects:ln.of(s)}):n.dispatch({effects:u.StateEffect.appendConfig.of(Re.init(()=>[s]))});let o=an.of(s);return{close:o,result:i.then(r=>((n.win.queueMicrotask||(a=>n.win.setTimeout(a,10)))(()=>{n.state.field(Re).indexOf(s)>-1&&n.dispatch({effects:o})}),r))}}const Re=u.StateField.define({create(){return[]},update(n,t){for(let e of t.effects)e.is(ln)?n=[e.value].concat(n):e.is(an)&&(n=n.filter(i=>i!=e.value));return n},provide:n=>pe.computeN([n],t=>t.field(n))}),ln=u.StateEffect.define(),an=u.StateEffect.define();function Kr(n,t,e){let i=t.content?t.content(n,()=>r(null)):null;if(!i){if(i=dt.default("form"),t.input){let l=dt.default("input",t.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(dt.default("label",(t.label||"")+": ",l))}else i.appendChild(document.createTextNode(t.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(dt.default("button",{class:"cm-button",type:"submit"},t.submitLabel||"OK"))}let s=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l<s.length;l++){let a=s[l];a.addEventListener("keydown",h=>{h.keyCode==27?(h.preventDefault(),r(null)):h.keyCode==13&&(h.preventDefault(),r(a))}),a.addEventListener("submit",h=>{h.preventDefault(),r(a)})}let o=dt.default("div",i,dt.default("button",{onclick:()=>r(null),"aria-label":n.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));t.class&&(o.className=t.class),o.classList.add("cm-dialog");function r(l){o.contains(o.ownerDocument.activeElement)&&n.focus(),e(l)}return{dom:o,top:t.top,mount:()=>{if(t.focus){let l;typeof t.focus=="string"?l=i.querySelector(t.focus):l=i.querySelector("input")||i.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class Q extends u.RangeValue{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Q.prototype.elementClass="";Q.prototype.toDOM=void 0;Q.prototype.mapMode=u.MapMode.TrackBefore;Q.prototype.startSide=Q.prototype.endSide=-1;Q.prototype.point=!0;const Pt=u.Facet.define(),hn=u.Facet.define(),_r={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>u.RangeSet.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Ht=u.Facet.define();function jr(n){return[gi(),Ht.of({..._r,...n})]}const is=u.Facet.define({combine:n=>n.some(t=>t)});function gi(n){return[Gr]}const Gr=L.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(Ht).map(t=>new ns(n,t)),this.fixed=!n.state.facet(is);for(let t of this.gutters)t.config.side=="after"?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let t=this.prevViewport,e=n.view.viewport,i=Math.min(t.to,e.to)-Math.max(t.from,e.from);this.syncGutters(i<(e.to-e.from)*.8)}if(n.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(is)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let t=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let e=u.RangeSet.iter(this.view.state.facet(Pt),this.view.viewport.from),i=[],s=this.gutters.map(o=>new Yr(o,this.view.viewport,-this.view.documentPadding.top));for(let o of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(o.type)){let r=!0;for(let l of o.type)if(l.type==exports.BlockType.Text&&r){ti(e,i,l.from);for(let a of s)a.line(this.view,l,i);r=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(o.type==exports.BlockType.Text){ti(e,i,o.from);for(let r of s)r.line(this.view,o,i)}else if(o.widget)for(let r of s)r.widget(this.view,o);for(let o of s)o.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let t=n.startState.facet(Ht),e=n.state.facet(Ht),i=n.docChanged||n.heightChanged||n.viewportChanged||!u.RangeSet.eq(n.startState.facet(Pt),n.state.facet(Pt),n.view.viewport.from,n.view.viewport.to);if(t==e)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let o of e){let r=t.indexOf(o);r<0?s.push(new ns(this.view,o)):(this.gutters[r].update(n),s.push(this.gutters[r]))}for(let o of this.gutters)o.dom.remove(),s.indexOf(o)<0&&o.destroy();for(let o of s)o.config.side=="after"?this.getDOMAfter().appendChild(o.dom):this.dom.appendChild(o.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>M.scrollMargins.of(t=>{let e=t.plugin(n);if(!e||e.gutters.length==0||!e.fixed)return null;let i=e.dom.offsetWidth*t.scaleX,s=e.domAfter?e.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==exports.Direction.LTR?{left:i,right:s}:{right:i,left:s}})});function ss(n){return Array.isArray(n)?n:[n]}function ti(n,t,e){for(;n.value&&n.from<=e;)n.from==e&&t.push(n.value),n.next()}class Yr{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=u.RangeSet.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,o=(e.top-this.height)/t.scaleY,r=e.height/t.scaleY;if(this.i==s.elements.length){let l=new cn(t,r,o,i);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(t,r,o,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];ti(this.cursor,s,e.from),i.length&&(s=s.concat(i));let o=this.gutter.config.lineMarker(t,e,s);o&&s.unshift(o);let r=this.gutter;s.length==0&&!r.config.renderEmptyElements||this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),s=i?[i]:null;for(let o of t.state.facet(hn)){let r=o(t,e.widget,e);r&&(s||(s=[])).push(r)}s&&this.addElement(t,e,s)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class ns{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,s=>{let o=s.target,r;if(o!=this.dom&&this.dom.contains(o)){for(;o.parentNode!=this.dom;)o=o.parentNode;let a=o.getBoundingClientRect();r=(a.top+a.bottom)/2}else r=s.clientY;let l=t.lineBlockAtHeight(r-t.documentTop);e.domEventHandlers[i](t,l,s)&&s.preventDefault()});this.markers=ss(e.markers(t)),e.initialSpacer&&(this.spacer=new cn(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=ss(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],t);s!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[s])}let i=t.view.viewport;return!u.RangeSet.eq(this.markers,e,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class cn{constructor(t,e,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,s)}update(t,e,i,s){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),Xr(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let o=0,r=0;;){let l=r,a=o<e.length?e[o++]:null,h=!1;if(a){let c=a.elementClass;c&&(i+=" "+c);for(let f=r;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,h=!0;break}}else l=this.markers.length;for(;r<l;){let c=this.markers[r++];if(c.toDOM){c.destroy(s);let f=s.nextSibling;s.remove(),s=f}}if(!a)break;a.toDOM&&(h?s=s.nextSibling:this.dom.insertBefore(a.toDOM(t),s)),h&&r++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}function Xr(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++)if(!n[e].compare(t[e]))return!1;return!0}const fn=u.Facet.define(),dn=u.Facet.define(),pt=u.Facet.define({combine(n){return u.combineConfig(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let s in e){let o=i[s],r=e[s];i[s]=o?(l,a,h)=>o(l,a,h)||r(l,a,h):r}return i}})}});class Le extends Q{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Pe(n,t){return n.state.facet(pt).formatNumber(t,n.state)}const $r=Ht.compute([pt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(fn)},lineMarker(t,e,i){return i.some(s=>s.toDOM)?null:new Le(Pe(t,t.state.doc.lineAt(e.from).number))},widgetMarker:(t,e,i)=>{for(let s of t.state.facet(dn)){let o=s(t,e,i);if(o)return o}return null},lineMarkerChange:t=>t.startState.facet(pt)!=t.state.facet(pt),initialSpacer(t){return new Le(Pe(t,os(t.state.doc.lines)))},updateSpacer(t,e){let i=Pe(e.view,os(e.view.state.doc.lines));return i==t.number?t:new Le(i)},domEventHandlers:n.facet(pt).domEventHandlers,side:"before"}));function Ur(n={}){return[pt.of(n),gi(),$r]}function os(n){let t=9;for(;t<n;)t=t*10+9;return t}const Qr=new class extends Q{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Jr=Pt.compute(["selection"],n=>{let t=[],e=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>e&&(e=s,t.push(Qr.range(s)))}return u.RangeSet.of(t)});function Zr(){return Jr}exports.BidiSpan=G;exports.BlockInfo=F;exports.BlockWrapper=wt;exports.Decoration=O;exports.EditorView=M;exports.GutterMarker=Q;exports.MatchDecorator=nn;exports.RectangleMarker=Mt;exports.ViewPlugin=L;exports.ViewUpdate=Ft;exports.WidgetType=st;exports.crosshairCursor=Br;exports.drawSelection=sr;exports.dropCursor=ar;exports.getPanel=zr;exports.getTooltip=Vr;exports.gutter=jr;exports.gutterLineClass=Pt;exports.gutterWidgetClass=hn;exports.gutters=gi;exports.highlightActiveLine=wr;exports.highlightActiveLineGutter=Zr;exports.highlightSpecialChars=ur;exports.hoverTooltip=Fr;exports.keymap=Qs;exports.layer=di;exports.lineNumberMarkers=fn;exports.lineNumberWidgetMarker=dn;exports.lineNumbers=Ur;exports.logException=q;exports.placeholder=Cr;exports.rectangularSelection=Tr;exports.runScopeHandlers=Qo;exports.showDialog=qr;exports.showPanel=pe;exports.showTooltip=pi;