@gramlot/gramlot 0.3.24 → 0.3.26

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 (131) hide show
  1. package/dist/components/editors/__init__.py +2 -2
  2. package/dist/components/editors/assets/collection.js +20 -19
  3. package/dist/components/editors/assets/index.js +1 -1
  4. package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
  5. package/dist/components/editors/assets/modules/{code-mirror-engine-QX4A5FVO.js → code-mirror-engine-RWQTR5G5.js} +29 -29
  6. package/dist/components/editors/assets/modules/{jodit-engine-MMSPIWM7.js → jodit-engine-MTSA4GZ3.js} +292 -292
  7. package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
  8. package/dist/components/editors/assets/modules/{prose-mirror-engine-IXTRTG6B.js → prose-mirror-engine-GMZPJPNN.js} +13 -13
  9. package/dist/components/grid/__init__.py +3 -2
  10. package/dist/components/grid/assets/collection.js +68 -17
  11. package/dist/components/grid/assets/index.js +1 -1
  12. package/dist/components/grid/grammar.json +57 -1
  13. package/dist/components/grouplets/__init__.py +2 -2
  14. package/dist/components/grouplets/assets/collection.js +3 -20
  15. package/dist/components/grouplets/assets/index.js +1 -1
  16. package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
  17. package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
  18. package/dist/components/inputs/__init__.py +1 -1
  19. package/dist/components/inputs/assets/collection.js +59 -34
  20. package/dist/components/inputs/assets/index.js +1 -1
  21. package/dist/components/inputs/grammar.json +64 -0
  22. package/dist/components/layout/__init__.py +1 -1
  23. package/dist/components/layout/assets/collection.js +67 -57
  24. package/dist/components/layout/assets/index.js +1 -1
  25. package/dist/components/layout/grammar.json +35 -0
  26. package/dist/components/selection_trial/__init__.py +1 -1
  27. package/dist/components/selection_trial/assets/collection.js +3 -3
  28. package/dist/components/selection_trial/assets/index.js +1 -1
  29. package/dist/components/selection_trial/grammar.json +35 -0
  30. package/dist/components/tree/__init__.py +1 -1
  31. package/dist/components/tree/assets/collection.js +26 -23
  32. package/dist/components/tree/assets/index.js +1 -1
  33. package/dist/components/tree/grammar.json +341 -1
  34. package/dist/components/uploads/__init__.py +13 -0
  35. package/dist/components/uploads/assets/collection.js +67 -0
  36. package/dist/components/uploads/assets/index.js +3 -0
  37. package/dist/components/uploads/commands.json +7 -0
  38. package/dist/components/uploads/grammar.json +789 -0
  39. package/dist/{components/editors/assets/modules/chunk-OCFLP2K4.js → gramlot-markdown.js} +12 -12
  40. package/dist/gramlot.js +4910 -566
  41. package/dist/gramlot.min.js +1587 -43
  42. package/dist/runtime-notices.json +28 -0
  43. package/package.json +4 -2
  44. package/src/binding/grid-struct.js +1 -1
  45. package/src/binding/providers.js +4 -1
  46. package/src/binding/remote-resolver.js +1 -8
  47. package/src/binding/runtime.js +40 -1
  48. package/src/binding/validation-context.js +40 -0
  49. package/src/browser-camera-provider.d.ts +8 -0
  50. package/src/browser-camera-provider.js +104 -0
  51. package/src/builder/source.js +13 -2
  52. package/src/components/attachment-manager.js +160 -0
  53. package/src/components/bases.js +17 -6
  54. package/src/components/border-container.js +86 -8
  55. package/src/components/buttons.js +11 -1
  56. package/src/components/choice-editor.js +20 -7
  57. package/src/components/database-choices.js +4 -2
  58. package/src/components/editing-status-styles.js +26 -0
  59. package/src/components/editing-status.js +115 -0
  60. package/src/components/field-state.js +37 -58
  61. package/src/components/grid-cell-editor.js +181 -0
  62. package/src/components/grid-grammar.json +21 -0
  63. package/src/components/grid-structure.js +2 -1
  64. package/src/components/grid-styles.js +51 -1
  65. package/src/components/grid.js +87 -10
  66. package/src/components/grouplet-card.js +11 -3
  67. package/src/components/html-preview.js +17 -4
  68. package/src/components/image-crop-dialog.js +272 -0
  69. package/src/components/image-crop.js +79 -0
  70. package/src/components/image-uploader.js +252 -0
  71. package/src/components/inputs.js +2 -1
  72. package/src/components/jodit-engine.js +1 -1
  73. package/src/components/markdown-document.js +2 -2
  74. package/src/components/screen-capture.js +43 -0
  75. package/src/components/selected-container.js +6 -2
  76. package/src/components/tree.js +416 -17
  77. package/src/components/typed-editor.js +19 -9
  78. package/src/components/upload-engine.js +156 -0
  79. package/src/components/uploader.js +208 -0
  80. package/src/components/uploads.js +7 -0
  81. package/src/editing-session.d.ts +25 -0
  82. package/src/editing-session.js +396 -0
  83. package/src/experiments/selection-trial.js +18 -2
  84. package/src/format.js +22 -7
  85. package/src/gramlot.d.ts +2 -0
  86. package/src/gramlot.js +2 -1
  87. package/src/handlers/device-handler.d.ts +2 -1
  88. package/src/handlers/rpc-handler.d.ts +3 -3
  89. package/src/index-page-styles.js +1 -0
  90. package/src/index.d.ts +13 -0
  91. package/src/index.js +13 -0
  92. package/src/inout.d.ts +2 -0
  93. package/src/inout.js +6 -0
  94. package/src/markdown-loader.d.ts +1 -0
  95. package/src/markdown-loader.js +4 -0
  96. package/src/markdown.d.ts +1 -0
  97. package/src/markdown.js +2 -0
  98. package/src/media-frame.js +9 -0
  99. package/src/renderer/attributes.js +7 -1
  100. package/src/renderer/gramlot-renderer.d.ts +2 -0
  101. package/src/renderer/gramlot-renderer.js +31 -2
  102. package/src/server/assets.d.ts +1 -1
  103. package/src/server/assets.js +1 -1
  104. package/src/server/gramlot-server.d.ts +8 -1
  105. package/src/server/gramlot-server.js +83 -7
  106. package/src/server/index.d.ts +2 -0
  107. package/src/server/index.js +2 -0
  108. package/src/server/page-base.js +17 -4
  109. package/src/server/page.d.ts +13 -1
  110. package/src/server/page.js +6 -0
  111. package/src/server/source-import.d.ts +2 -0
  112. package/src/server/source-import.js +31 -0
  113. package/src/server/upload.d.ts +20 -0
  114. package/src/server/upload.js +142 -0
  115. package/src/server/visual-editor.d.ts +11 -0
  116. package/src/server/visual-editor.js +149 -0
  117. package/src/source-picker.d.ts +9 -0
  118. package/src/source-picker.js +57 -0
  119. package/src/tree-store.d.ts +24 -0
  120. package/src/tree-store.js +193 -0
  121. package/src/validation-run.js +50 -0
  122. package/src/view/button.js +8 -5
  123. package/src/view/controls.js +9 -42
  124. package/src/view/html.js +10 -2
  125. package/src/visual-editor-icons.js +10 -0
  126. package/src/visual-editor.d.ts +56 -0
  127. package/src/visual-editor.js +844 -0
  128. package/themes/gramlot-base/theme.css +99 -0
  129. package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +0 -3
  130. package/src/form-state.d.ts +0 -20
  131. package/src/form-state.js +0 -198
@@ -1,24 +1,24 @@
1
- import{a as wr,b as Fe}from"./chunk-OCFLP2K4.js";import{a as Mr,c as Cr}from"./chunk-YSGSC7KM.js";import"./chunk-MMJXUHRQ.js";import"./chunk-AU4HFPIY.js";function z(r){this.content=r}z.prototype={constructor:z,find:function(r){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===r)return e;return-1},get:function(r){var e=this.find(r);return e==-1?void 0:this.content[e+1]},update:function(r,e,t){var n=t&&t!=r?this.remove(t):this,i=n.find(r),s=n.content.slice();return i==-1?s.push(t||r,e):(s[i+1]=e,t&&(s[i]=t)),new z(s)},remove:function(r){var e=this.find(r);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new z(t)},addToStart:function(r,e){return new z([r,e].concat(this.remove(r).content))},addToEnd:function(r,e){var t=this.remove(r).content.slice();return t.push(r,e),new z(t)},addBefore:function(r,e,t){var n=this.remove(e),i=n.content.slice(),s=n.find(r);return i.splice(s==-1?i.length:s,0,e,t),new z(i)},forEach:function(r){for(var e=0;e<this.content.length;e+=2)r(this.content[e],this.content[e+1])},prepend:function(r){return r=z.from(r),r.size?new z(r.content.concat(this.subtract(r).content)):this},append:function(r){return r=z.from(r),r.size?new z(this.subtract(r).content.concat(r.content)):this},subtract:function(r){var e=this;r=z.from(r);for(var t=0;t<r.content.length;t+=2)e=e.remove(r.content[t]);return e},toObject:function(){var r={};return this.forEach(function(e,t){r[e]=t}),r},get size(){return this.content.length>>1}};z.from=function(r){if(r instanceof z)return r;var e=[];if(r)for(var t in r)e.push(t,r[t]);return new z(e)};var cn=z;function zr(r,e,t){for(let n=0;;n++){if(n==r.childCount||n==e.childCount)return r.childCount==e.childCount?null:t;let i=r.child(n),s=e.child(n);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){let o=i.text,l=s.text,a=0;for(;o[a]==l[a];a++)t++;return a&&a<o.length&&a<l.length&&Vr(o.charCodeAt(a-1))&&Fr(o.charCodeAt(a))&&t--,t}if(i.content.size||s.content.size){let o=zr(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function vr(r,e,t,n){for(let i=r.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:n};let o=r.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,n-=a;continue}if(!o.sameMarkup(l))return{a:t,b:n};if(o.isText&&o.text!=l.text){let c=o.text,f=l.text,h=c.length,d=f.length;for(;h>0&&d>0&&c[h-1]==f[d-1];)h--,d--,t--,n--;return h&&d&&h<c.length&&Vr(c.charCodeAt(h-1))&&Fr(c.charCodeAt(h))&&(t++,n++),{a:t,b:n}}if(o.content.size||l.content.size){let c=vr(o.content,l.content,t-1,n-1);if(c)return c}t-=a,n-=a}}function Fr(r){return r>=56320&&r<57344}function Vr(r){return r>=55296&&r<56320}var k=class r{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,i=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&n(a,i+l,s||null,o)!==!1&&a.content.size){let f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),n,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new r(i,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let n=[],i=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),n.push(l),i+=l.nodeSize),o=a}return new r(n,i)}cutByIndex(e,t){return e==t?r.empty:e==0&&t==this.content.length?this:new r(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-n.nodeSize;return i[e]=t,new r(i,s)}addToStart(e){return new r([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new r(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let i=this.content[t];e(i,n,t),n+=i.nodeSize}}findDiffStart(e,t=0){return zr(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return vr(this,e,t,n)}findIndex(e){if(e==0)return Et(0,e);if(e==this.size)return Et(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let i=this.child(t),s=n+i.nodeSize;if(s>=e)return s==e?Et(t+1,s):Et(t,n);n=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return r.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return r.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return r.empty;let t,n=0;for(let i=0;i<e.length;i++){let s=e[i];n+=s.nodeSize,i&&s.isText&&e[i-1].sameMarkup(s)?(t||(t=e.slice(0,i)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new r(t||e,n)}static from(e){if(!e)return r.empty;if(e instanceof r)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new r([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}};k.empty=new k([],0);var fn={index:0,offset:0};function Et(r,e){return fn.index=r,fn.offset=e,fn}function Rt(r,e){if(r===e)return!0;if(!(r&&typeof r=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(r);if(Array.isArray(e)!=t)return!1;if(t){if(r.length!=e.length)return!1;for(let n=0;n<r.length;n++)if(!Rt(r[n],e[n]))return!1}else{for(let n in r)if(!(n in e)||!Rt(r[n],e[n]))return!1;for(let n in e)if(!(n in r))return!1}return!0}var C=class r{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let i=0;i<e.length;i++){let s=e[i];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,i));else{if(s.type.excludes(this.type))return e;!n&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Rt(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);return n.create(t.attrs)}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return r.none;if(e instanceof r)return[e];let t=e.slice();return t.sort((n,i)=>n.type.rank-i.type.rank),t}};C.none=[];var he=class extends Error{},b=class r{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=Wr(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new r(n,this.openStart,this.openEnd)}removeBetween(e,t){return new r(Lr(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return r.empty;let n=t.openStart||0,i=t.openEnd||0;if(typeof n!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new r(k.fromJSON(e,t.content),n,i)}static maxOpen(e,t=!0){let n=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)n++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new r(e,n,i)}};b.empty=new b(k.empty,0,0);function Lr(r,e,t){let{index:n,offset:i}=r.findIndex(e),s=r.maybeChild(n),{index:o,offset:l}=r.findIndex(t);if(i==e||s.isText){if(l!=t&&!r.child(o).isText)throw new RangeError("Removing non-flat range");return r.cut(0,e).append(r.cut(t))}if(n!=o)throw new RangeError("Removing non-flat range");return r.replaceChild(n,s.copy(Lr(s.content,e-i-1,t-i-1)))}function Wr(r,e,t,n,i,s){let{index:o,offset:l}=r.findIndex(e),a=r.maybeChild(o);if(l==e||a.isText)return s&&n<=0&&i<=0&&!s.canReplace(o,o,t)?null:r.cut(0,e).append(t).append(r.cut(e));let c=Wr(a.content,e-l-1,t,o==0?n-1:0,o==r.childCount-1?i-1:0,a);return c&&r.replaceChild(o,a.copy(c))}function Gs(r,e,t){if(t.openStart>r.depth)throw new he("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new he("Inconsistent open depths");return Jr(r,e,t,0)}function Jr(r,e,t,n){let i=r.index(n),s=r.node(n);if(i==e.index(n)&&n<r.depth-t.openStart){let o=Jr(r,e,t,n+1);return s.copy(s.content.replaceChild(i,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&r.depth==n&&e.depth==n){let o=r.parent,l=o.content;return be(o,l.cut(0,r.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=Ys(t,r);return be(s,$r(r,o,l,e,n))}else return be(s,Bt(r,e,n))}function qr(r,e){if(!e.type.compatibleContent(r.type))throw new he("Cannot join "+e.type.name+" onto "+r.type.name)}function hn(r,e,t){let n=r.node(t);return qr(n,e.node(t)),n}function ke(r,e){let t=e.length-1;t>=0&&r.isText&&r.sameMarkup(e[t])?e[t]=r.withText(e[t].text+r.text):e.push(r)}function et(r,e,t,n){let i=(e||r).node(t),s=0,o=e?e.index(t):i.childCount;r&&(s=r.index(t),r.depth>t?s++:r.textOffset&&(ke(r.nodeAfter,n),s++));for(let l=s;l<o;l++)ke(i.child(l),n);e&&e.depth==t&&e.textOffset&&ke(e.nodeBefore,n)}function be(r,e){if(!r.type.validContent(e))throw new he("Invalid content for node "+r.type.name);return r.copy(e)}function $r(r,e,t,n,i){let s=r.depth>i&&hn(r,e,i+1),o=n.depth>i&&hn(t,n,i+1),l=[];return et(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(qr(s,o),ke(be(s,$r(r,e,t,n,i+1)),l)):(s&&ke(be(s,Bt(r,e,i+1)),l),et(e,t,i,l),o&&ke(be(o,Bt(t,n,i+1)),l)),et(n,null,i,l),new k(l)}function Bt(r,e,t){let n=[];if(et(null,r,t,n),r.depth>t){let i=hn(r,e,t+1);ke(be(i,Bt(r,e,t+1)),n)}return et(e,null,t,n),new k(n)}function Ys(r,e){let t=e.depth-r.openStart,i=e.node(t).copy(r.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(k.from(i));return{start:i.resolveNoCache(r.openStart+t),end:i.resolveNoCache(i.content.size-r.openEnd-t)}}var Pt=class r{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],i=e.child(t);return n?e.child(t).cut(n):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)i+=n.child(s).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return C.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),i=e.maybeChild(t);if(!n){let l=n;n=i,i=l}let s=n.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!i||!s[o].isInSet(i.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,i=e.parent.maybeChild(e.index());for(var s=0;s<n.length;s++)n[s].type.spec.inclusive===!1&&(!i||!n[s].isInSet(i.marks))&&(n=n[s--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new dn(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(n.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new r(t,n,s)}static resolveCached(e,t){let n=Or.get(e);if(n)for(let s=0;s<n.elts.length;s++){let o=n.elts[s];if(o.pos==t)return o}else Or.set(e,n=new un);let i=n.elts[n.i]=r.resolve(e,t);return n.i=(n.i+1)%Xs,i}},un=class{constructor(){this.elts=[],this.i=0}},Xs=12,Or=new WeakMap,dn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},Zs=Object.create(null),Q=class r{constructor(e,t,n,i=C.none){this.type=e,this.attrs=t,this.marks=i,this.content=n||k.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,i=0){this.content.nodesBetween(e,t,n,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,i){return this.content.textBetween(e,t,n,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&Rt(this.attrs,t||e.defaultAttrs||Zs)&&C.sameSet(this.marks,n||C.none)}copy(e=null){return e==this.content?this:new r(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new r(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return b.empty;let i=this.resolve(e),s=this.resolve(t),o=n?0:i.sharedDepth(t),l=i.start(o),c=i.node(o).content.cut(i.pos-l,s.pos-l);return new b(c,i.depth-o,s.depth-o)}replace(e,t,n){return Gs(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(i==e||t.isText)return t;e-=i+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let i=this.content.child(t-1);return{node:i,index:t-1,offset:n-i.nodeSize}}resolve(e){return Pt.resolveCached(this,e)}resolveNoCache(e){return Pt.resolve(this,e)}rangeHasMark(e,t,n){let i=!1;return t>e&&this.nodesBetween(e,t,s=>(n.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Kr(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=k.empty,i=0,s=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;a<s;a++)if(!this.type.allowsMarks(n.child(a).marks))return!1;return!0}canReplaceWith(e,t,n,i){if(i&&!this.type.allowsMarks(i))return!1;let s=this.contentMatchAt(e).matchType(n),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),Nr(this.type.attrs,this.attrs,"node",this.type.name);let e=C.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];Nr(n.type.attrs,n.attrs,"mark",n.type.name),e=n.addToSet(e)}if(!C.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let i=k.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,n)}};Q.prototype.text=void 0;var pn=class r extends Q{constructor(e,t,n,i){if(super(e,t,null,i),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Kr(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new r(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new r(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Kr(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}function Nr(r,e,t,n){for(let i in e)if(!(i in r))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${n}`);for(let i in r)r[i].validate&&r[i].validate(e[i])}var xe=class r{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new mn(e,t);if(n.next==null)return r.empty;let i=Hr(n);n.next&&n.err("Unexpected trailing text");let s=so(io(i));return oo(s,n),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let i=this;for(let s=t;i&&s<n;s++)i=i.matchType(e.child(s).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let i=[this];function s(o,l){let a=o.matchFragment(e,n);if(a&&(!t||a.validEnd))return k.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:f,next:h}=o.next[c];if(!(f.isText||f.hasRequiredAttrs())&&i.indexOf(h)==-1){i.push(h);let d=s(h,l.concat(f));if(d)return d}}return null}return s(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let i=n.shift(),s=i.match;if(s.matchType(e)){let o=[];for(let l=i;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!i.type||a.validEnd)&&(n.push({match:l.contentMatch,type:l,via:i}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let i=0;i<n.next.length;i++)e.indexOf(n.next[i].next)==-1&&t(n.next[i].next)}return t(this),e.map((n,i)=>{let s=i+(n.validEnd?"*":" ")+" ";for(let o=0;o<n.next.length;o++)s+=(o?", ":"")+n.next[o].type.name+"->"+e.indexOf(n.next[o].next);return s}).join(`
2
- `)}};xe.empty=new xe(!0);var mn=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Hr(r){let e=[];do e.push(Qs(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Qs(r){let e=[];do e.push(eo(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function eo(r){let e=ro(r);for(;;)if(r.eat("+"))e={type:"plus",expr:e};else if(r.eat("*"))e={type:"star",expr:e};else if(r.eat("?"))e={type:"opt",expr:e};else if(r.eat("{"))e=to(r,e);else break;return e}function Dr(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function to(r,e){let t=Dr(r),n=t;return r.eat(",")&&(r.next!="}"?n=Dr(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function no(r,e){let t=r.nodeTypes,n=t[e];if(n)return[n];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&r.err("No node type or group '"+e+"' found"),i}function ro(r){if(r.eat("(")){let e=Hr(r);return r.eat(")")||r.err("Missing closing paren"),e}else if(/\W/.test(r.next))r.err("Unexpected token '"+r.next+"'");else{let e=no(r,r.next).map(t=>(r.inline==null?r.inline=t.isInline:r.inline!=t.isInline&&r.err("Mixing inline and block content"),{type:"name",value:t}));return r.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function io(r){let e=[[]];return i(s(r,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return n(l,a),i(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let f=t();i(s(o.expr,a),f),a=f}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let f=t();n(a,f),i(s(o.expr,a),f),a=f}return[n(a)]}else{if(o.type=="name")return[n(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function _r(r,e){return e-r}function Tr(r,e){let t=[];return n(e),t.sort(_r);function n(i){let s=r[i];if(s.length==1&&!s[0].term)return n(s[0].to);t.push(i);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&n(a)}}}function so(r){let e=Object.create(null);return t(Tr(r,0));function t(n){let i=[];n.forEach(o=>{r[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f<i.length;f++)i[f][0]==l&&(c=i[f][1]);Tr(r,a).forEach(f=>{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let s=e[n.join(",")]=new xe(n.indexOf(r.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(_r);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function oo(r,e){for(let t=0,n=[r];t<n.length;t++){let i=n[t],s=!i.validEnd,o=[];for(let l=0;l<i.next.length;l++){let{type:a,next:c}=i.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),n.indexOf(c)==-1&&n.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function jr(r){let e=Object.create(null);for(let t in r){let n=r[t];if(!n.hasDefault)return null;e[t]=n.default}return e}function Ur(r,e){let t=Object.create(null);for(let n in r){let i=r[n],s=e&&e[n];if(s===void 0)if(i.hasDefault)s=i.default;else throw new RangeError("No value supplied for attribute "+n);else i.validate&&i.validate(s);t[n]=s}return t}function Gr(r,e){let t=Object.create(null);if(e)for(let n in e)t[n]=new gn(r,n,e[n]);return t}var zt=class r{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=Gr(e,n.attrs),this.defaultAttrs=jr(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==xe.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Ur(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Q(this,this.computeAttrs(e),k.from(t),C.setFrom(n))}createChecked(e=null,t,n){return t=k.from(t),this.checkContent(t),new Q(this,this.computeAttrs(e),t,C.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=k.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(k.empty,!0);return s?new Q(this,e,t.append(s),C.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let n=0;n<e.childCount;n++)if(!this.allowsMarks(e.child(n).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:C.none:e}static compile(e,t){let n=Object.create(null);e.forEach((s,o)=>n[s]=new r(s,t,o));let i=t.spec.topNode||"doc";if(!n[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let s in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}};function lo(r,e,t){let n=t.split("|");return i=>{let s=i===null?"null":typeof i;if(n.indexOf(s)<0)throw new RangeError(`Expected value of type ${n} for attribute ${e} on type ${r}, got ${s}`)}}var gn=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?lo(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},nt=class r{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=Gr(e,i.attrs),this.excluded=null;let s=jr(this.attrs);this.instance=s?new C(this,s):null}create(e=null){return!e&&this.instance?this.instance:new C(this,Ur(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new r(s,i++,t,o)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}excludes(e){return this.excluded.indexOf(e)>-1}},Le=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=cn.from(e.nodes),t.marks=cn.from(e.marks||{}),this.nodes=zt.compile(this.spec.nodes,this),this.marks=nt.compile(this.spec.marks,this);let n=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=n[o]||(n[o]=xe.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Er(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Er(this,o.split(" "))}this.nodeFromJSON=i=>Q.fromJSON(this,i),this.markFromJSON=i=>C.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof zt){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,n,i)}text(e,t){let n=this.nodes.text;return new pn(n,n.defaultAttrs,e,C.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Er(r,e){let t=[];for(let n=0;n<e.length;n++){let i=e[n],s=r.marks[i],o=s;if(s)t.push(s);else for(let l in r.marks){let a=r.marks[l];(i=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(i)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[n]+"'")}return t}function ao(r){return r.tag!=null}function co(r){return r.style!=null}var rt=class r{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(i=>{if(ao(i))this.tags.push(i);else if(co(i)){let s=/[^=]*/.exec(i.style)[0];n.indexOf(s)<0&&n.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let n=new vt(this,t,!1);return n.addAll(e,C.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new vt(this,t,!0);return n.addAll(e,C.none,t.from,t.to),b.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;i<this.tags.length;i++){let s=this.tags[i];if(uo(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,n,i){for(let s=i?this.styles.indexOf(i)+1:0;s<this.styles.length;s++){let o=this.styles[s],l=o.style;if(!(l.indexOf(e)!=0||o.context&&!n.matchesContext(o.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function n(i){let s=i.priority==null?50:i.priority,o=0;for(;o<t.length;o++){let l=t[o];if((l.priority==null?50:l.priority)<s)break}t.splice(o,0,i)}for(let i in e.marks){let s=e.marks[i].spec.parseDOM;s&&s.forEach(o=>{n(o=Ir(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{n(o=Ir(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new r(e,r.schemaRules(e)))}},Yr={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},fo={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Xr={ol:!0,ul:!0},it=1,yn=2,tt=4;function Ar(r,e,t){return e!=null?(e?it:0)|(e==="full"?yn:0):r&&r.whitespace=="pre"?it|yn:t&~tt}var Ve=class{constructor(e,t,n,i,s,o){this.type=e,this.attrs=t,this.marks=n,this.solid=i,this.options=o,this.content=[],this.activeMarks=C.none,this.match=s||(o&tt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(k.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let n=this.type.contentMatch,i;return(i=n.findWrapping(e.type))?(this.match=n,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&it)){let n=this.content[this.content.length-1],i;if(n&&n.isText&&(i=/[ \t\r\n\u000c]+$/.exec(n.text))){let s=n;n.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=k.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(k.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Yr.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},vt=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let i=t.topNode,s,o=Ar(null,t.preserveWhitespace,0)|(n?tt:0);i?s=new Ve(i.type,i.attrs,C.none,!0,t.topMatch||i.type.contentMatch,o):n?s=new Ve(null,null,C.none,!0,null,o):s=new Ve(e.schema.topNodeType,null,C.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,i=this.top,s=i.options&yn?"full":this.localPreserveWS||(i.options&it)>0,{schema:o}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if(s==="full")n=n.replace(/\r\n?/g,`
3
- `);else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=n.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(o.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(o.text(l[a]),t,!/\S/.test(l[a]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let l=i.content[i.content.length-1],a=e.previousSibling;(!l||a&&a.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(n=n.slice(1))}n&&this.insertNode(o.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let i=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;Xr.hasOwnProperty(o)&&this.parser.normalizeLists&&ho(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,n));e:if(a?a.ignore:fo.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let c,f=this.needsBlock;if(Yr.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let h=a&&a.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),c&&this.sync(s),this.needsBlock=f}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
4
- `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let s=this.parser.matchedStyles[i],o=n.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(c=>!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,n,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName=="BR")||this.leafFallback(e,n);else{let a=this.enter(o,t.attrs||null,n,t.preserveWhitespace);a&&(s=!0,n=a)}else{let a=this.parser.schema.marks[t.mark];n=n.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,n,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,n,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,n),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,n,i){let s=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,n){let i,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!i||i.length>c.length+l)&&(i=c,s=a,!c.length))break;if(a.solid){if(n)break;l+=2}}if(!i)return null;this.sync(s);for(let o=0;o<i.length;o++)t=this.enterInner(i[o],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let i=this.findPlace(e,t,n);if(i){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=C.none;for(let l of i.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):Rr(l.type,e.type))&&(o=l.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,n,i){let s=this.findPlace(e.create(t),n,!1);return s&&(s=this.enterInner(e,t,n,!0,i)),s}enterInner(e,t,n,i=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=Ar(e,s,o.options);o.options&tt&&o.content.length==0&&(l|=tt);let a=C.none;return n=n.filter(c=>(o.type?o.type.allowsMarkType(c.type):Rr(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ve(e,t,a,i,null,l)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=it)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let i=n.length-1;i>=0;i--)e+=n[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&t.compareDocumentPosition(this.find[i].node)&(n?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,i=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!f||f.name!=c&&!f.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}};function ho(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Xr.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function uo(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function Ir(r){let e={};for(let t in r)e[t]=r[t];return e}function Rr(r,e){let t=e.schema.nodes;for(let n in t){let i=t[n];if(!i.allowsMarkType(r))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:c,next:f}=l.edge(a);if(c==e||s.indexOf(f)<0&&o(f))return!0}};if(o(i.contentMatch))return!0}}var Se=class r{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=At(t).createDocumentFragment());let i=n,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let c=o.marks[a];if(!this.marks[c.type.name]){a++;continue}if(!c.eq(s[l][0])||c.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)i=s.pop()[1];for(;a<o.marks.length;){let c=o.marks[a++],f=this.serializeMark(c,o.isInline,t);f&&(s.push([c,i]),i.appendChild(f.dom),i=f.contentDOM||f.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),n}serializeNodeInner(e,t){if(e.isText)return At(t).createTextNode(e.text);let{dom:n,contentDOM:i}=It(At(t),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,i)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let i=e.marks.length-1;i>=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let i=this.marks[e.type.name];return i&&It(At(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return typeof t=="string"?{dom:e.createTextNode(t)}:It(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new r(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Br(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return Br(e.marks)}};function Br(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function At(r){return r.document||window.document}var Pr=new WeakMap;function po(r){let e=Pr.get(r);return e===void 0&&Pr.set(r,e=mo(r)),e}function mo(r){let e=null;function t(n){if(n&&typeof n=="object")if(Array.isArray(n))if(typeof n[0]=="string")e||(e=[]),e.push(n);else for(let i=0;i<n.length;i++)t(n[i]);else for(let i in n)t(n[i])}return t(r),e}function It(r,e,t,n){if(e.nodeType==1)return{dom:e};if(e.dom&&e.dom.nodeType==1)return e;let i=e[0],s;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(n&&(s=po(n))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?r.createElementNS(t,i):r.createElement(i),c=e[1],f=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){f=2;for(let h in c)if(c[h]!=null){let d=h.indexOf(" ");d>0?a.setAttributeNS(h.slice(0,d),h.slice(d+1),c[h]):h=="style"&&a.style?a.style.cssText=c[h]:a.setAttribute(h,c[h])}}for(let h=f;h<e.length;h++){let d=e[h];if(d===0){if(h<e.length-1||h>f)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else if(typeof d=="string")a.appendChild(r.createTextNode(d));else{let{dom:p,contentDOM:u}=It(r,d,t,n);if(a.appendChild(p),u){if(l)throw new RangeError("Multiple content holes");l=u}}}return{dom:a,contentDOM:l}}var ti=65535,ni=Math.pow(2,16);function go(r,e){return r+e*ni}function Zr(r){return r&ti}function yo(r){return(r-(r&ti))/ni}var ri=1,ii=2,Ft=4,si=8,lt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&si)>0}get deletedBefore(){return(this.delInfo&(ri|Ft))>0}get deletedAfter(){return(this.delInfo&(ii|Ft))>0}get deletedAcross(){return(this.delInfo&Ft)>0}},re=class r{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&r.empty)return r.empty}recover(e){let t=0,n=Zr(e);if(!this.inverted)for(let i=0;i<n;i++)t+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[n*3]+t+yo(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],f=this.ranges[l+o],h=a+c;if(e<=h){let d=c?e==a?-1:e==h?1:t:t,p=a+i+(d<0?0:f);if(n)return p;let u=e==(t<0?a:h)?null:go(l/3,e-a),m=0;return c&&(m|=e==a?ii:e==h?ri:Ft,(t<0?e!=a:e!=h)&&(m|=si)),new lt(p,m,u)}i+=f-c}return n?e+i:new lt(e+i,0,null)}touches(e,t){let n=0,i=Zr(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?n:0);if(a>e)break;let c=this.ranges[l+s],f=a+c;if(e<=f&&l==i*3)return!0;n+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[i+t],f=this.ranges[i+n];e(l,l+c,a,a+f),s+=f-c}}invert(){return new r(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?r.empty:new r(e<0?[0,-e,0]:[0,0,e])}};re.empty=new re([]);var at=class r{constructor(e,t,n=0,i=e?e.length:0){this.mirror=t,this.from=n,this.to=i,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new r(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let i=e.getMirror(t);this.appendMap(e._maps[t],i!=null&&i<t?n+i:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),i!=null&&i>t?n-i-1:void 0)}}invert(){let e=new r;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let i=0;for(let s=this.from;s<this.to;s++){let o=this._maps[s],l=o.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this._maps[a].recover(l.recover);continue}}i|=l.delInfo,e=l.pos}return n?e:new lt(e,i,null)}},kn=Object.create(null),T=class{getMap(){return re.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=kn[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in kn)throw new RangeError("Duplicate use of step JSON ID "+e);return kn[e]=t,t.prototype.jsonID=e,t}},I=class r{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new r(e,null)}static fail(e){return new r(null,e)}static fromReplace(e,t,n,i){try{return r.ok(e.replace(t,n,i))}catch(s){if(s instanceof he)return r.fail(s.message);throw s}}};function Mn(r,e,t){let n=[];for(let i=0;i<r.childCount;i++){let s=r.child(i);s.content.size&&(s=s.copy(Mn(s.content,e,s))),s.isInline&&(s=e(s,t,i)),n.push(s)}return k.fromArray(n)}var ct=class r extends T{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),i=n.node(n.sharedDepth(this.to)),s=new b(Mn(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,s)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,i)=>{if(n.isInline&&n.isAtom){let s=this.mark.addToSet(n.marks);if(!C.sameSet(s,n.marks)){let o=Math.max(this.from,i),l=Math.min(this.to,i+n.nodeSize);Vt(We,o,l,this.mark,t);for(let a of n.marks)a.isInSet(s)||Vt(r,o,l,a,t)}}}),t.length==1?t[0]:new ft(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new r(t,n,this.mark)}merge(e){return e instanceof r&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new r(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new r(t.from,t.to,e.markFromJSON(t.mark))}};T.jsonID("addMark",ct);var We=class r extends T{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new b(Mn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,n)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,i)=>{n.isInline&&n.isAtom&&this.mark.isInSet(n.marks)&&Vt(ct,Math.max(this.from,i),Math.min(this.to,i+n.nodeSize),this.mark,t)}),t.length==1?t[0]:new ft(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new r(t,n,this.mark)}merge(e){return e instanceof r&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new r(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new r(t.from,t.to,e.markFromJSON(t.mark))}};T.jsonID("removeMark",We);function Vt(r,e,t,n,i){let s=i.length?i[i.length-1]:null;s&&s instanceof r&&s.to==e&&s.mark.eq(n)?i[i.length-1]=new r(s.from,t,n):i.push(new r(e,t,n))}var ft=class r extends T{constructor(e){super(),this.steps=e}apply(e){for(let t of this.steps){let n=t.apply(e);if(!n.doc)return n;e=n.doc}return new I(e,null)}invert(e){return new r(this.steps.map(t=>t.invert(e)))}map(e){let t=[];for(let n of this.steps){let i=n.map(e);i&&t.push(i)}return t.length?new r(t):null}toJSON(){return{stepType:"markSet",steps:this.steps.map(e=>e.toJSON())}}static fromJSON(e,t){if(!Array.isArray(t.steps)||!t.steps.every(n=>n.stepType=="addMark"||n.stepType=="removeMark"))throw new RangeError("Invalid JSON for MarkSetStep");return new r(t.steps.map(n=>T.fromJSON(e,n)))}};T.jsonID("markSet",ft);var ht=class r extends T{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new b(k.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let n=this.mark.addToSet(t.marks);if(n.length==t.marks.length){for(let i=0;i<t.marks.length;i++)if(!t.marks[i].isInSet(n))return new r(this.pos,t.marks[i]);return new r(this.pos,this.mark)}}return new Je(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new r(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new r(t.pos,e.markFromJSON(t.mark))}};T.jsonID("addNodeMark",ht);var Je=class r extends T{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new b(k.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new ht(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new r(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new r(t.pos,e.markFromJSON(t.mark))}};T.jsonID("removeNodeMark",Je);var $=class r extends T{constructor(e,t,n,i=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=i}apply(e){return this.structure&&xn(e,this.from,this.to)?I.fail("Structure replace would overwrite content"):I.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new re([this.from,this.to-this.from,this.slice.size])}invert(e){return new r(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&r.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new r(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof r)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?b.empty:new b(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new r(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?b.empty:new b(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new r(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new r(t.from,t.to,b.fromJSON(e,t.slice),!!t.structure)}};$.MAP_BIAS=1;T.jsonID("replace",$);var H=class r extends T{constructor(e,t,n,i,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=i,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(xn(e,this.from,this.gapFrom)||xn(e,this.gapTo,this.to)))return I.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return I.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?I.fromReplace(e,this.from,this.to,n):I.fail("Content does not fit in gap")}getMap(){return new re([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new r(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||i<t.pos||s>n.pos?null:new r(t.pos,n.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new r(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};T.jsonID("replaceAround",H);function xn(r,e,t){let n=r.resolve(e),i=t-e,s=n.depth;for(;i>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,i--;if(i>0){let o=n.node(s).maybeChild(n.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function ko(r,e,t,n){let i=[];r.doc.nodesBetween(e,t,(s,o,l)=>{if(!s.isInline)return;let a=s.marks;if(!n.isInSet(a)&&l.type.allowsMarkType(n.type)){let c=Math.max(o,e),f=Math.min(o+s.nodeSize,t);Vt(ct,c,f,n,i)}}),i.forEach(s=>r.step(s))}function bo(r,e,t,n){let i=[],s=0;r.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline||!o.isAtom)return;s++;let a=null;if(n instanceof nt){let c=o.marks,f;for(;f=n.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let f=0;f<a.length;f++){let h=a[f],d;for(let p=0;p<i.length;p++){let u=i[p];u.step==s-1&&h.eq(i[p].style)&&(d=u)}d?(d.to=c,d.step=s):i.push({style:h,from:Math.max(l,e),to:c,step:s})}}}),i.forEach(o=>r.step(new We(o.from,o.to,o.style)))}function Cn(r,e,t,n=t.contentMatch,i=!0){let s=r.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let c=s.child(a),f=l+c.nodeSize,h=n.matchType(c.type);if(!h)o.push(new $(l,f,b.empty));else{n=h;for(let d=0;d<c.marks.length;d++)t.allowsMarkType(c.marks[d].type)||r.step(new We(l,f,c.marks[d]));if(i&&c.isText&&t.whitespace!="pre"){let d,p=/\r?\n|\r/g,u;for(;d=p.exec(c.text);)u||(u=new b(k.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new $(l+d.index,l+d.index+d[0].length,u))}}l=f}if(!n.validEnd){let a=n.fillBefore(k.empty,!0);r.replace(l,l,new b(a,0,0))}for(let a=o.length-1;a>=0;a--)r.step(o[a])}function xo(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function qt(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth,i=0,s=0;;--n){let o=r.$from.node(n),l=r.$from.index(n)+i,a=r.$to.indexAfter(n)-s;if(n<r.depth&&o.canReplace(l,a,t))return n;if(n==0||o.type.spec.isolating||!xo(o,l,a))break;l&&(i=1),a<o.childCount&&(s=1)}return null}function So(r,e,t){let{$from:n,$to:i,depth:s}=e,o=n.before(s+1),l=i.after(s+1),a=o,c=l,f=k.empty,h=0;for(let u=s,m=!1;u>t;u--)m||n.index(u)>0?(m=!0,f=k.from(n.node(u).copy(f)),h++):a--;let d=k.empty,p=0;for(let u=s,m=!1;u>t;u--)m||i.after(u+1)<i.end(u)?(m=!0,d=k.from(i.node(u).copy(d)),p++):c++;r.step(new H(a,c,o,l,new b(f.append(d),h,p),f.size-h,!0))}function Mo(r,e,t){let n=k.empty;for(let o=t.length-1;o>=0;o--){if(n.size){let l=t[o].type.contentMatch.matchFragment(n);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}n=k.from(t[o].type.create(t[o].attrs,n))}let i=e.start,s=e.end;r.step(new H(i,s,i,s,new b(n,0,0),t.length,!0))}function Co(r,e,t,n,i){if(!n.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=r.steps.length;r.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(n,a)&&wo(r.doc,r.mapping.slice(s).map(l),n)){let c=null;if(n.schema.linebreakReplacement){let p=n.whitespace=="pre",u=!!n.contentMatch.matchType(n.schema.linebreakReplacement);p&&!u?c=!1:!p&&u&&(c=!0)}c===!1&&li(r,o,l,s),Cn(r,r.mapping.slice(s).map(l,1),n,void 0,c===null);let f=r.mapping.slice(s),h=f.map(l,1),d=f.map(l+o.nodeSize,1);return r.step(new H(h,d,h+1,d-1,new b(k.from(n.create(a,null,o.marks)),0,0),1,!0)),c===!0&&oi(r,o,l,s),!1}})}function oi(r,e,t,n){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=r.mapping.slice(n).map(t+1+s+o.index);r.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function li(r,e,t,n){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=r.mapping.slice(n).map(t+1+s);r.replaceWith(o,o+1,e.type.schema.text(`
5
- `))}})}function wo(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function Oo(r,e,t,n,i){let s=r.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(n,null,i||s.marks);if(s.isLeaf)return r.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);r.step(new H(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(k.from(o),0,0),1,!0))}function ut(r,e,t=1,n){let i=r.resolve(e),s=i.depth-t,o=n&&n[n.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,f=t-2;c>s;c--,f--){let h=i.node(c),d=i.index(c);if(h.type.spec.isolating)return!1;let p=h.content.cutByIndex(d,h.childCount),u=n&&n[f+1];u&&(p=p.replaceChild(0,u.type.create(u.attrs)));let m=n&&n[f]||h;if(!h.canReplace(d+1,h.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function No(r,e,t=1,n){let i=r.doc.resolve(e),s=k.empty,o=k.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=k.from(i.node(l).copy(s));let f=n&&n[c];o=k.from(f?f.type.create(f.attrs,o):i.node(l).copy(o))}r.step(new $(e,e,new b(s.append(o),t,t),!0))}function wn(r,e){let t=r.resolve(e),n=t.index();return To(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function Do(r,e){e.content.size||r.type.compatibleContent(e.type);let t=r.contentMatchAt(r.childCount),{linebreakReplacement:n}=r.type.schema;for(let i=0;i<e.childCount;i++){let s=e.child(i),o=s.type==n?r.type.schema.nodes.text:s.type;if(t=t.matchType(o),!t||!r.type.allowsMarks(s.marks))return!1}return t.validEnd}function To(r,e){return!!(r&&e&&!r.isLeaf&&Do(r,e))}function Eo(r,e,t){let n=null,{linebreakReplacement:i}=r.doc.type.schema,s=r.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let f=o.whitespace=="pre",h=!!o.contentMatch.matchType(i);f&&!h?n=!1:!f&&h&&(n=!0)}let l=r.steps.length;if(n===!1){let f=r.doc.resolve(e+t);li(r,f.node(),f.before(),l)}o.inlineContent&&Cn(r,e+t-1,o,s.node().contentMatchAt(s.index()),n==null);let a=r.mapping.slice(l),c=a.map(e-t);if(r.step(new $(c,a.map(e+t,-1),b.empty,!0)),n===!0){let f=r.doc.resolve(c);oi(r,f.node(),f.before(),r.steps.length)}return r}function Ao(r,e,t){let n=r.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),t))return e;if(n.parentOffset==0)for(let i=n.depth-1;i>=0;i--){let s=n.index(i);if(n.node(i).canReplaceWith(s,s,t))return n.before(i+1);if(s>0)return null}if(n.parentOffset==n.parent.content.size)for(let i=n.depth-1;i>=0;i--){let s=n.indexAfter(i);if(n.node(i).canReplaceWith(s,s,t))return n.after(i+1);if(s<n.node(i).childCount)return null}return null}function ai(r,e,t){let n=r.resolve(e);if(!t.content.size)return e;let i=t.content;for(let s=0;s<t.openStart;s++)i=i.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let o=n.depth;o>=0;o--){let l=o==n.depth?0:n.pos<=(n.start(o+1)+n.end(o+1))/2?-1:1,a=n.index(o)+(l>0?1:0),c=n.node(o),f=!1;if(s==1)f=c.canReplace(a,a,i);else{let h=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=h&&c.canReplaceWith(a,a,h[0])}if(f)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function $t(r,e,t=e,n=b.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return ci(i,s,n)?new $(e,t,n):new Sn(i,s,n).fit()}function ci(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}var Sn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=k.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=k.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let s=this.placed,o=n.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new b(s,o,l);return e>-1?new H(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new $(n.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,i=this.unplaced.openEnd;n<e;n++){let s=t.firstChild;if(t.childCount>1&&(i=0),s.type.spec.isolating&&i<=n){e=n;break}t=s.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let i,s=null;n?(s=Qr(this.unplaced.content,n-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,h=null;if(t==1&&(o?c.matchType(o.type)||(h=c.fillBefore(k.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:h};if(t==2&&o&&(f=c.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:f};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return ei(e,-1)<=t?!1:(this.unplaced.size>1&&ei(e,1)>n&&n++,this.unplaced=new b(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=Qr(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(st(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new b(st(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=n?n.content:o.content,a=o.openStart-e,c=0,f=[],{match:h,type:d}=this.frontier[t];if(i){for(let m=0;m<i.childCount;m++)f.push(i.child(m));h=h.matchFragment(i)}let p=l.size+e-(o.content.size-o.openEnd);for(;c<l.childCount;){let m=l.child(c),g=h.matchType(m.type);if(!g)break;c++,(c>1||a==0||m.content.size)&&(h=g,f.push(fi(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let u=c==l.childCount;u||(p=-1),this.placed=ot(this.placed,t,k.from(f)),this.frontier[t].match=h,u&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<p;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=u?e==0?b.empty:new b(st(o.content,e-1,1),e-1,p<0?o.openEnd:e-1):new b(st(o.content,e,c),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!bn(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,i=this.$to.after(n);for(;n>1&&i==this.$to.end(--n);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:i}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=bn(e,t,i,n,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],f=bn(e,l,c,a,!0);if(!f||f.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=ot(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let i=e.node(n),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(n));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ot(this.placed,this.depth,k.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(k.empty,!0);t.childCount&&(this.placed=ot(this.placed,this.frontier.length,t))}};function st(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(st(r.firstChild.content,e-1,t)))}function ot(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(ot(r.lastChild.content,e-1,t)))}function Qr(r,e){for(let t=0;t<e;t++)r=r.firstChild.content;return r}function fi(r,e,t){if(e<=0)return r;let n=r.content;return e>1&&(n=n.replaceChild(0,fi(n.firstChild,e-1,n.childCount==1?t-1:0))),e>0&&(n=r.type.contentMatch.fillBefore(n).append(n),t<=0&&(n=n.append(r.type.contentMatch.matchFragment(n).fillBefore(k.empty,!0)))),r.copy(n)}function bn(r,e,t,n,i){let s=r.node(e),o=i?r.indexAfter(e):r.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!Io(t,s.content,o)?l:null}function Io(r,e,t){for(let n=t;n<e.childCount;n++)if(!r.allowsMarks(e.child(n).marks))return!0;return!1}function Ro(r){return r.spec.defining||r.spec.definingForContent}function ei(r,e){for(let t=0;;t++){let n=e<0?r.firstChild:r.lastChild;if(!n||n.isAtom)return t;r=n.content}}function Bo(r,e,t,n){if(!n.size)return r.deleteRange(e,t);let i=r.doc.resolve(e),s=r.doc.resolve(t);if(ci(i,s,n))return r.step(new $(e,t,n));let o=ui(i,s);o[o.length-1]==0&&o.pop();let l=-(i.depth+1);o.unshift(l);for(let d=i.depth,p=i.pos-1;d>0;d--,p--){let u=i.node(d).type.spec;if(u.defining||u.definingAsContext||u.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==p&&o.splice(1,0,-d)}let a=o.indexOf(l),c=[],f=n.openStart;for(let d=n.content,p=0;;p++){let u=d.firstChild;if(c.push(u),p==n.openStart)break;d=u.content}for(let d=f-1;d>=0;d--){let p=c[d],u=Ro(p.type);if(u&&!p.sameMarkup(i.node(Math.abs(l)-1)))f=d;else if(u||!p.type.isTextblock)break}for(let d=n.openStart;d>=0;d--){let p=(d+f+1)%(n.openStart+1),u=c[p];if(u)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],y=!0;g<0&&(y=!1,g=-g);let M=i.node(g-1),O=i.index(g-1);if(M.canReplaceWith(O,O,u.type,u.marks))return r.replace(i.before(g),y?s.after(g):t,new b(hi(n.content,0,n.openStart,p),p,n.openEnd))}}let h=r.steps.length;for(let d=o.length-1;d>=0&&(r.replace(e,t,n),!(r.steps.length>h));d--){let p=o[d];p<0||(e=i.before(p),t=s.after(p))}}function hi(r,e,t,n,i){if(e<t){let s=r.firstChild;r=r.replaceChild(0,s.copy(hi(s.content,e+1,t,n,s)))}if(e>n){let s=i.contentMatchAt(0),o=s.fillBefore(r).append(r);r=o.append(s.matchFragment(o).fillBefore(k.empty,!0))}return r}function Po(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=Ao(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new b(k.from(n),0,0))}function zo(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t);if(n.parent.isTextblock&&i.parent.isTextblock&&n.start()!=i.start()&&n.parentOffset==0&&i.parentOffset==0){let o=n.sharedDepth(t),l=!1;for(let a=n.depth;a>o;a--)n.node(a).type.spec.isolating&&(l=!0);for(let a=i.depth;a>o;a--)i.node(a).type.spec.isolating&&(l=!0);if(!l){for(let a=n.depth;a>0&&e==n.start(a);a--)e=n.before(a);for(let a=i.depth;a>0&&t==i.start(a);a--)t=i.before(a);n=r.doc.resolve(e),i=r.doc.resolve(t)}}let s=ui(n,i);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||n.node(l).type.contentMatch.validEnd)return r.delete(n.start(l),i.end(l));if(l>0&&(a||n.node(l-1).canReplace(n.index(l-1),i.indexAfter(l-1))))return r.delete(n.before(l),i.after(l))}for(let o=1;o<=n.depth&&o<=i.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&i.end(o)-t!=i.depth-o&&n.start(o-1)==i.start(o-1)&&n.node(o-1).canReplace(n.index(o-1),i.index(o-1)))return r.delete(n.before(o),t);r.delete(e,t)}function ui(r,e){let t=[],n=Math.min(r.depth,e.depth);for(let i=n;i>=0;i--){let s=r.start(i);if(s<r.pos-(r.depth-i)||e.end(i)>e.pos+(e.depth-i)||r.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==r.depth&&i==e.depth&&r.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Lt=class r extends T{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let i=t.type.create(n,null,t.marks);return I.fromReplace(e,this.pos,this.pos+1,new b(k.from(i),0,t.isLeaf?0:1))}getMap(){return re.empty}invert(e){return new r(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new r(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new r(t.pos,t.attr,t.value)}};T.jsonID("attr",Lt);var Wt=class r extends T{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return I.ok(n)}getMap(){return re.empty}invert(e){return new r(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new r(t.attr,t.value)}};T.jsonID("docAttr",Wt);var qe=class extends Error{};qe=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t};qe.prototype=Object.create(Error.prototype);qe.prototype.constructor=qe;qe.prototype.name="TransformError";var Jt=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new at}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new qe(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let i=this.mapping.maps[n];n&&(e=i.map(e,1),t=i.map(t,-1)),i.forEach((s,o,l,a)=>{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=b.empty){let i=$t(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new b(k.from(n),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return Bo(this,e,t,n),this}replaceRangeWith(e,t,n){return Po(this,e,t,n),this}deleteRange(e,t){return zo(this,e,t),this}lift(e,t){return So(this,e,t),this}join(e,t=1){return Eo(this,e,t),this}wrap(e,t){return Mo(this,e,t),this}setBlockType(e,t=e,n,i=null){return Co(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return Oo(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Lt(e,t,n)),this}setDocAttribute(e,t){return this.step(new Wt(e,t)),this}addNodeMark(e,t){return this.step(new ht(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof C)t.isInSet(n.marks)&&this.step(new Je(e,t));else{let i=n.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new Je(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,n){return No(this,e,t,n),this}addMark(e,t,n){return ko(this,e,t,n),this}removeMark(e,t,n){return bo(this,e,t,n),this}clearIncompatible(e,t,n){return Cn(this,e,t,n),this}};var On=Object.create(null),N=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Ke(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=b.empty){let n=t.content.lastChild,i=null;for(let l=0;l<t.openEnd;l++)i=n,n=n.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],f=e.mapping.slice(s);e.replaceRange(f.map(a.pos),f.map(c.pos),l?b.empty:t),l==0&&mi(e,s,(n?n.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:o,$to:l}=i[s],a=e.mapping.slice(n),c=a.map(o.pos),f=a.map(l.pos);s?e.deleteRange(c,f):(e.replaceRangeWith(c,f,t),mi(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let i=e.parent.inlineContent?new D(e):$e(e.node(0),e.parent,e.pos,e.index(),t,n);if(i)return i;for(let s=e.depth-1;s>=0;s--){let o=t<0?$e(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):$e(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new _(e.node(0))}static atStart(e){return $e(e,e,0,0,1)||new _(e)}static atEnd(e){return $e(e,e,e.content.size,e.childCount,-1)||new _(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=On[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in On)throw new RangeError("Duplicate use of selection JSON ID "+e);return On[e]=t,t.prototype.jsonID=e,t}getBookmark(){return D.between(this.$anchor,this.$head).getBookmark()}};N.prototype.visible=!0;var Ke=class{constructor(e,t){this.$from=e,this.$to=t}},di=!1;function pi(r){!di&&!r.parent.inlineContent&&(di=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}var D=class r extends N{constructor(e,t=e){pi(e),pi(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return N.near(n);let i=e.resolve(t.map(this.anchor));return new r(i.parent.inlineContent?i:n,n)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof r&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Ht(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new r(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let i=e.resolve(t);return new this(i,n==t?i:e.resolve(n))}static between(e,t,n){let i=e.pos-t.pos;if((!n||i)&&(n=i>=0?1:-1),!t.parent.inlineContent){let s=N.findFrom(t,n,!0)||N.findFrom(t,-n,!0);if(s)t=s.$head;else return N.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(N.findFrom(e,-n,!0)||N.findFrom(e,n,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new r(e,t)}};N.jsonID("text",D);var Ht=class r{constructor(e,t){this.anchor=e,this.head=t}map(e){return new r(e.map(this.anchor),e.map(this.head))}resolve(e){return D.between(e.resolve(this.anchor),e.resolve(this.head))}},S=class r extends N{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:i}=t.mapResult(this.anchor),s=e.resolve(i);return n?N.near(s):new r(s)}content(){return new b(k.from(this.node),0,0)}eq(e){return e instanceof r&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Dn(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new r(e.resolve(t.anchor))}static create(e,t){return new r(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};S.prototype.visible=!1;N.jsonID("node",S);var Dn=class r{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Ht(n,n):new r(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&S.isSelectable(n)?new S(t):N.near(t)}},_=class r extends N{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=b.empty){if(t==b.empty){e.delete(0,e.doc.content.size);let n=N.atStart(e.doc);n.eq(e.selection)||e.setSelection(n)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new r(e)}map(e){return new r(e)}eq(e){return e instanceof r}getBookmark(){return vo}};N.jsonID("all",_);var vo={map(){return this},resolve(r){return new _(r)}};function $e(r,e,t,n,i,s=!1){if(e.inlineContent)return D.create(r,t);for(let o=n-(i>0?0:1);i>0?o<e.childCount:o>=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&S.isSelectable(l))return S.create(r,t-(i<0?l.nodeSize:0))}else{let a=$e(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function mi(r,e,t){let n=r.steps.length-1;if(n<e)return;let i=r.steps[n];if(!(i instanceof $||i instanceof H))return;let s=r.mapping.maps[n],o;s.forEach((l,a,c,f)=>{o==null&&(o=f)}),r.setSelection(N.near(r.doc.resolve(o),t))}var gi=1,Kt=2,yi=4,Tn=class extends Jt{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|gi)&~Kt,this.storedMarks=null,this}get selectionSet(){return(this.updated&gi)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Kt,this}ensureMarks(e){return C.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Kt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Kt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||C.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),n=n??t,!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,i.text(e,s)),this.selection.empty||this.setSelection(N.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=yi,this}get scrolledIntoView(){return(this.updated&yi)>0}};function ki(r,e){return!e||!r?r:r.bind(e)}var Me=class{constructor(e,t,n){this.name=e,this.init=ki(t.init,n),this.apply=ki(t.apply,n)}},Fo=[new Me("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new Me("selection",{init(r,e){return r.selection||N.atStart(e.doc)},apply(r){return r.selection}}),new Me("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new Me("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})],dt=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Fo.slice(),t&&t.forEach(n=>{if(this.pluginsByKey[n.key])throw new RangeError("Adding different instances of a keyed plugin ("+n.key+")");this.plugins.push(n),this.pluginsByKey[n.key]=n,n.spec.state&&this.fields.push(new Me(n.key,n.spec.state,n))})}},_t=class r{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let i=this.config.plugins[n];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),i=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=i?i[o].n:0,c=i?i[o].state:this,f=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,n);if(f&&n.filterTransaction(f,o)){if(f.setMeta("appendedTransaction",e),!i){i=[];for(let h=0;h<this.config.plugins.length;h++)i.push(h<o?{state:n,n:t.length}:{state:this,n:0})}t.push(f),n=n.applyInner(f),s=!0}i&&(i[o]={state:n,n:t.length})}}if(!s)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new r(this.config),n=this.config.fields;for(let i=0;i<n.length;i++){let s=n[i];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new Tn(this)}static create(e){let t=new dt(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new r(t);for(let i=0;i<t.fields.length;i++)n[t.fields[i].name]=t.fields[i].init(e,n);return n}reconfigure(e){let t=new dt(this.schema,e.plugins),n=t.fields,i=new r(t);for(let s=0;s<n.length;s++){let o=n[s].name;i[o]=this.hasOwnProperty(o)?this[o]:n[s].init(e,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(n=>n.toJSON())),e&&typeof e=="object")for(let n in e){if(n=="doc"||n=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[n],s=i.spec.state;s&&s.toJSON&&(t[n]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new dt(e.schema,e.plugins),s=new r(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Q.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=N.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let l in n){let a=n[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function bi(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=bi(i,e,{})),t[n]=i}return t}var He=class{constructor(e){this.spec=e,this.props={},e.props&&bi(e.props,this,this.props),this.key=e.key?e.key.key:xi("plugin")}getState(e){return e[this.key]}},Nn=Object.create(null);function xi(r){return r in Nn?r+"$"+ ++Nn[r]:(Nn[r]=0,r+"$")}var pt=class{constructor(e="key"){this.key=xi(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var R=function(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e},Ge=function(r){let e=r.assignedSlot||r.parentNode;return e&&e.nodeType==11?e.host:e},Bn=null,se=function(r,e,t){let n=Bn||(Bn=document.createRange());return n.setEnd(r,t??r.nodeValue.length),n.setStart(r,e||0),n},Vo=function(){Bn=null},Ae=function(r,e,t,n){return t&&(Si(r,e,t,n,-1)||Si(r,e,t,n,1))},Lo=/^(img|br|input|textarea|hr)$/i;function Si(r,e,t,n,i){for(var s;;){if(r==t&&e==n)return!0;if(e==(i<0?0:F(r))){let o=r.parentNode;if(!o||!x(o)||Ct(r)||Lo.test(r.nodeName)||r.contentEditable=="false")return!1;e=R(r)+(i<0?0:1),r=o}else if(x(r)){let o=r.childNodes[e+(i<0?-1:0)];if(x(o)&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=i;else return!1;else r=o,e=i<0?F(r):0}else return!1}}function F(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function x(r){return r.nodeType==1}function E(r){return r.nodeType==3}function Ie(r,e){return e?r.contains(x(e)?e:e.parentNode):!1}function Wo(r,e){for(;;){if(E(r)&&e)return r;if(x(r)&&e>0){if(r.contentEditable=="false")return null;r=r.childNodes[e-1],e=F(r)}else if(r.parentNode&&!Ct(r))e=R(r),r=r.parentNode;else return null}}function Jo(r,e){for(;;){if(E(r)&&e<r.nodeValue.length)return r;if(x(r)&&e<r.childNodes.length){if(r.contentEditable=="false")return null;r=r.childNodes[e],e=0}else if(r.parentNode&&!Ct(r))e=R(r)+1,r=r.parentNode;else return null}}function qo(r,e,t){for(let n=e==0,i=e==F(r);n||i;){if(r==t)return!0;let s=R(r);if(r=r.parentNode,!r)return!1;n=n&&s==0,i=i&&s==F(r)}}function Ct(r){let e;for(let t=r;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==r||e.contentDOM==r)}var rn=function(r){return r.focusNode&&Ae(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)};function Ce(r,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=r,t.key=t.code=e,t}function $o(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Ko(r,e,t){if(r.caretPositionFromPoint)try{let n=r.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:Math.min(F(n.offsetNode),n.offset)}}catch{}if(r.caretRangeFromPoint){let n=r.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:Math.min(F(n.startContainer),n.startOffset)}}}var ee=typeof navigator<"u"?navigator:null,Mi=typeof document<"u"?document:null,ye=ee&&ee.userAgent||"",Pn=/Edge\/(\d+)/.exec(ye),Xi=/MSIE \d/.exec(ye),zn=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ye),K=!!(Xi||zn||Pn),pe=Xi?document.documentMode:zn?+zn[1]:Pn?+Pn[1]:0,j=!K&&/gecko\/(\d+)/i.test(ye);j&&+(/Firefox\/(\d+)/.exec(ye)||[0,0])[1];var vn=!K&&/Chrome\/(\d+)/.exec(ye),B=!!vn,Zi=vn?+vn[1]:0,V=!K&&!!ee&&/Apple Computer/.test(ee.vendor),Ye=V&&(/Mobile\/\w+/.test(ye)||!!ee&&ee.maxTouchPoints>2),U=Ye||(ee?/Mac/.test(ee.platform):!1),Qi=ee?/Win/.test(ee.platform):!1,oe=/Android \d/.test(ye),sn=!!Mi&&"webkitFontSmoothing"in Mi.documentElement.style,Ho=sn?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function _o(r){let e=r.defaultView&&r.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:r.documentElement.clientWidth,top:0,bottom:r.documentElement.clientHeight}}function ie(r,e){return typeof r=="number"?r:r[e]}function jo(r){let e=r.getBoundingClientRect(),t=e.width/r.offsetWidth||1,n=e.height/r.offsetHeight||1;return{left:e.left,right:e.left+r.clientWidth*t,top:e.top,bottom:e.top+r.clientHeight*n}}function Ci(r,e,t){if(!Fn(e)&&e.left==0)return;let n=r.someProp("scrollThreshold")||0,i=r.someProp("scrollMargin")||5,s=r.dom.ownerDocument;for(let o=t||r.dom;o;){if(!x(o)){o=Ge(o);continue}let l=o==s.body,a=l?_o(s):jo(o),c=0,f=0;if(e.top<a.top+ie(n,"top")?f=-(a.top-e.top+ie(i,"top")):e.bottom>a.bottom-ie(n,"bottom")&&(f=e.bottom-e.top>a.bottom-a.top?e.top+ie(i,"top")-a.top:e.bottom-a.bottom+ie(i,"bottom")),e.left<a.left+ie(n,"left")?c=-(a.left-e.left+ie(i,"left")):e.right>a.right-ie(n,"right")&&(c=e.right-a.right+ie(i,"right")),c||f)if(l)s.defaultView.scrollBy(c,f);else{let d=o.scrollLeft,p=o.scrollTop;f&&(o.scrollTop+=f),c&&(o.scrollLeft+=c);let u=o.scrollLeft-d,m=o.scrollTop-p;e={left:e.left-u,top:e.top-m,right:e.right-u,bottom:e.bottom-m}}let h=l?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(h))break;o=h=="absolute"?o.offsetParent:Ge(o)}}function Uo(r){let e=r.dom.getBoundingClientRect(),t=Math.max(0,e.top),n,i;for(let s=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let l=r.root.elementFromPoint(s,o);if(!l||l==r.dom||!r.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){n=l,i=a.top;break}}return{refDOM:n,refTop:i,stack:es(r.dom)}}function es(r){let e=[],t=r.ownerDocument;for(let n=r;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),r!=t);n=Ge(n));return e}function Go({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;ts(t,n==0?0:n-e)}function ts(r,e){for(let t=0;t<r.length;t++){let{dom:n,top:i,left:s}=r[t];n.scrollTop!=i+e&&(n.scrollTop=i+e),n.scrollLeft!=s&&(n.scrollLeft=s)}}var _e=null;function Yo(r){if(r.setActive)return r.setActive();if(_e)return r.focus(_e);let e=es(r);r.focus(_e==null?{get preventScroll(){return _e={preventScroll:!0},!0}}:void 0),_e||(_e=!1,ts(e,0))}function ns(r,e){let t,n=2e8,i,s=0,o=e.top,l=e.top,a,c;for(let f=r.firstChild,h=0;f;f=f.nextSibling,h++){let d;if(x(f))d=f.getClientRects();else if(E(f))d=se(f).getClientRects();else continue;for(let p=0;p<d.length;p++){let u=d[p];if(u.top<=o&&u.bottom>=l){o=Math.max(u.bottom,o),l=Math.min(u.top,l);let m=u.left>e.left?u.left-e.left:u.right<e.left?e.left-u.right:0;if(m<n){t=f,n=m,i=m&&E(t)?{left:u.right<e.left?u.right:u.left,top:e.top}:e,x(f)&&m&&(s=h+(e.left>=(u.left+u.right)/2?1:0));continue}}else u.top>e.top&&!a&&u.left<=e.left&&u.right>=e.left&&(a=f,c={left:Math.max(u.left,Math.min(u.right,e.left)),top:u.top});!t&&(e.left>=u.right&&e.top>=u.top||e.left>=u.left&&e.top>=u.bottom)&&(s=h+1)}}return!t&&a&&(t=a,i=c,n=0),t&&E(t)?Xo(t,i):!t||n?{node:r,offset:s}:ns(t,i)}function Xo(r,e){let t=r.nodeValue.length,n=document.createRange(),i;for(let s=0;s<t;s++){n.setEnd(r,s+1),n.setStart(r,s);let o=ue(n,1);if(o.top!=o.bottom&&Qn(e,o)){i={node:r,offset:s+(e.left>=(o.left+o.right)/2?1:0)};break}}return n.detach(),i||{node:r,offset:0}}function Qn(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function Zo(r,e){let t=r.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<r.getBoundingClientRect().left?t:r}function Qo(r,e,t){let{node:n,offset:i}=ns(e,t),s=-1;if(x(n)&&!n.firstChild){let o=n.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return r.docView.posFromDOM(n,i,s)}function el(r,e,t,n){let i=-1;for(let s=e,o=!1;s!=r.dom;){let l=r.docView.nearestDesc(s,!0),a;if(!l)return null;if(x(l.dom)&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!o&&a.left>n.left||a.top>n.top?i=l.posBefore:(!o&&a.right<n.left||a.bottom<n.top)&&(i=l.posAfter),o=!0),!l.contentDOM&&i<0&&!l.node.isText))return(l.node.isBlock?n.top<(a.top+a.bottom)/2:n.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return i>-1?i:r.docView.posFromDOM(e,t,-1)}function rs(r,e,t){let n=r.childNodes.length;if(n&&t.top<t.bottom)for(let i=Math.max(0,Math.min(n-1,Math.floor(n*(e.top-t.top)/(t.bottom-t.top))-2)),s=i;;){let o=r.childNodes[s];if(x(o)){let l=o.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(Qn(e,c))return rs(o,e,c)}}if((s=(s+1)%n)==i)break}return r}function tl(r,e){let t=r.dom.ownerDocument,n,i=0,s=Ko(t,e.left,e.top);s&&({node:n,offset:i}=s);let o=(r.root.elementFromPoint?r.root:t).elementFromPoint(e.left,e.top),l;if(!o||!r.dom.contains(o)){let c=r.dom.getBoundingClientRect();if(!Qn(e,c)||(o=rs(r.dom,e,c),!o))return null}if(V)for(let c=o;n&&c;c=Ge(c))c.draggable&&(n=void 0);if(o=Zo(o,e),n){if(j&&x(n)&&(i=Math.min(i,n.childNodes.length),i<n.childNodes.length)){let f=n.childNodes[i],h;f.nodeName=="IMG"&&(h=f.getBoundingClientRect()).right<=e.left&&h.bottom>e.top&&i++}let c;sn&&i&&x(n)&&x(c=n.childNodes[i-1])&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,n==r.dom&&i==n.childNodes.length-1&&x(n.lastChild)&&e.top>n.lastChild.getBoundingClientRect().bottom?l=r.state.doc.content.size:(i==0||!x(n)||n.childNodes[i-1].nodeName!="BR")&&(l=el(r,n,i,e))}l==null&&(l=Qo(r,o,e));let a=r.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Fn(r){return r.top<r.bottom||r.left<r.right}function ue(r,e){let t=r.getClientRects();if(t.length){let n=t[e<0?0:t.length-1];if(Fn(n))return n}return Array.prototype.find.call(t,Fn)||r.getBoundingClientRect()}var nl=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function is(r,e,t){let{node:n,offset:i,atom:s}=r.docView.domFromPos(e,t<0?-1:1),o=sn||j;if(E(n))if(o&&(nl.test(n.nodeValue)||(t<0?!i:i==n.nodeValue.length))){let a=ue(se(n,i,i),t);if(j&&i&&/\s/.test(n.nodeValue[i-1])&&i<n.nodeValue.length){let c=ue(se(n,i-1,i-1),-1);if(c.top==a.top){let f=ue(se(n,i,i+1),-1);if(f.top!=a.top)return mt(f,f.left<c.left)}}return a}else{let a=i,c=i,f=t<0?1:-1;return t<0&&!i?(c++,f=-1):t>=0&&i==n.nodeValue.length?(a--,f=1):t<0?a--:c++,mt(ue(se(n,a,c),f),f<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==F(n))){let a=n.childNodes[i-1];if(x(a))return En(a.getBoundingClientRect(),!1)}if(s==null&&i<F(n)){let a=n.childNodes[i];if(x(a))return En(a.getBoundingClientRect(),!0)}return En(n.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==F(n))){let a=n.childNodes[i-1],c=E(a)?se(a,F(a)-(o?0:1)):x(a)&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return mt(ue(c,1),!1)}if(s==null&&i<F(n)){let a=n.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?E(a)?se(a,0,o?0:1):x(a)?a:null:null;if(c)return mt(ue(c,-1),!0)}return mt(ue(E(n)?se(n):n,-t),t>=0)}function mt(r,e){if(r.width==0)return r;let t=e?r.left:r.right;return{top:r.top,bottom:r.bottom,left:t,right:t}}function En(r,e){if(r.height==0)return r;let t=e?r.top:r.bottom;return{top:t,bottom:t,left:r.left,right:r.right}}function ss(r,e,t){let n=r.state,i=r.root.activeElement;n!=e&&r.updateState(e),i!=r.dom&&r.focus();try{return t()}finally{n!=e&&r.updateState(n),i!=r.dom&&i&&i.focus()}}function rl(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return ss(r,e,()=>{let{node:s}=r.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=r.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=is(r,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(x(l))a=l.getClientRects();else if(E(l))a=se(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let f=a[c];if(f.bottom>f.top+1&&(t=="up"?o.top-f.top>(f.bottom-o.top)*2:f.bottom-o.bottom>(o.bottom-f.top)*2))return!1}}return!0})}var il=/[\u0590-\u08ac]/;function sl(r,e,t){let{$head:n}=e.selection;if(!n.parent.isTextblock)return!1;let i=n.parentOffset,s=!i,o=i==n.parent.content.size,l=r.domSelection();return l?!il.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:ss(r,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:h}=r.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:u,focusOffset:m}=r.domSelectionRange(),g=u&&!Ie(p,u)||a==u&&c==m;try{l.collapse(f,h),a&&(a!=f||c!=h)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):n.pos==n.start()||n.pos==n.end()}var wi=null,Oi=null,Ni=!1;function ol(r,e,t){return wi==e&&Oi==t?Ni:(wi=e,Oi=t,Ni=t=="up"||t=="down"?rl(r,e,t):sl(r,e,t))}var G=0,Di=1,we=2,Z=3,Re=class{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=G,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(e){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let i=this.children[t];if(i==e)return n;n+=i.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){if(this.contentDOM&&Ie(this.contentDOM,e))if(n<0){let s,o;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(o)+o.size:this.posAtStart}else{let s,o;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(o):this.posAtEnd}let i;if(e==this.dom&&this.contentDOM)i=t>R(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=!!(e.compareDocumentPosition(this.contentDOM)&4);else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(n&&(o=s.nodeDOM)&&!(x(o)?Ie(o,e):o==e))n=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let i=this.children[t],s=n+i.size;if(n==e&&s!=n){for(;!i.border&&i.children.length;)for(let o=0;o<i.children.length;o++){let l=i.children[o];if(l.size){i=l;break}}return i}if(e<s)return i.descAt(e-n-i.border);n=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,i=0;for(let s=0;n<this.children.length;n++){let o=this.children[n],l=s+o.size;if(l>e){i=e-s;break}s=l}if(i)return this.children[n].domFromPos(i-this.children[n].border,t);for(;n>0;n--){let s=this.children[n-1];if(s.size||!(s instanceof Gt||s instanceof jt&&s.side>=0))break}if(t<=0){let s,o=!0;for(;s=n?this.children[n-1]:null,!(!s||s.dom.parentNode==this.contentDOM);n--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?R(s.dom)+1:0}}else{let s,o=!0;for(;s=n<this.children.length?this.children[n]:null,!(!s||s.dom.parentNode==this.contentDOM);n++,o=!1);return s&&o&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?R(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,s=-1;for(let o=n,l=0;;l++){let a=this.children[l],c=o+a.size;if(i==-1&&e<=c){let f=o+a.border;if(e>=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=o;for(let h=l;h>0;h--){let d=this.children[h-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=R(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;f<this.children.length;f++){let h=this.children[f];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(-1)){s=R(h.dom);break}t+=h.size}s==-1&&(s=this.contentDOM.childNodes.length);break}o=c}return{node:this.contentDOM,from:e,to:t,fromOffset:i,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(!x(t)||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,i=!1){let s=Math.min(e,t),o=Math.max(e,t);for(let p=0,u=0;p<this.children.length;p++){let m=this.children[p],g=u+m.size;if(s>u&&o<g)return m.setSelection(e-u-m.border,t-u-m.border,n,i);u=g}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),c=n.root.getSelection(),f=n.domSelectionRange(),h=!1;if((j||V)&&e==t){let{node:p,offset:u}=l;if(E(p)){if(h=!!(u&&p.nodeValue[u-1]==`
6
- `),h&&u==p.nodeValue.length)for(let m=p,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:R(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=p.childNodes[u-1];h=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(j&&f.focusNode&&f.focusNode!=a.node&&x(f.focusNode)){let p=f.focusNode.childNodes[f.focusOffset];p&&p.contentEditable=="false"&&(i=!0)}if(!(i||h&&V)&&Ae(l.node,l.offset,f.anchorNode,f.anchorOffset)&&Ae(a.node,a.offset,f.focusNode,f.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(h&&j)){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),d=!0}catch{}}if(!d){if(e>t){let u=l;l=a,a=u}let p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,i=0;i<this.children.length;i++){let s=this.children[i],o=n+s.size;if(n==o?e<=o&&t>=n:e<o&&t>n){let l=n+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==n||t==o?we:Di,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Z:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?we:Z}n=o}this.dirty=we}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?we:Di;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},jt=class extends Re{constructor(e,t,n,i){let s,o=t.type.toDOM;if(typeof o=="function"&&(o=o(n,()=>{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){let l=x(o)?o:document.createElement("span");l!=o&&l.appendChild(o),l.hasAttribute("contenteditable")||(l.contentEditable="false"),l.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==G&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Vn=class extends Re{constructor(e,t,n,i){super(e,[],t,null),this.textDOM=n,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Ne=class r extends Re{constructor(e,t,n,i,s){super(e,[],n,i),this.mark=t,this.spec=s}static create(e,t,n,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,n);return(!o||!o.dom)&&(o=Se.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new r(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Z||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Z&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=G){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty<this.dirty&&(n.dirty=this.dirty),this.dirty=G}}slice(e,t,n){let i=r.create(this.parent,this.mark,!0,n),s=this.children,o=this.size;t<o&&(s=qn(s,t,o,n)),e>0&&(s=qn(s,0,e,n));for(let l=0;l<s.length;l++)s[l].parent=i;return i.children=s,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},me=class r extends Re{constructor(e,t,n,i,s,o,l){super(e,[],s,o),this.node=t,this.outerDeco=n,this.innerDeco=i,this.nodeDOM=l}static create(e,t,n,i,s,o){let l=s.nodeViews[t.type.name],a,c=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,i),f=c&&c.dom,h=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(!E(f))throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:h}=Se.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!h&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let d=f;return f=cs(f,n,t),c?a=new Ln(e,t,n,i,f,h||null,d,c):t.isText?new Ut(e,t,n,i,f,d):new r(e,t,n,i,f,h||null,d)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(t.preserveWhitespace="full"),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let i=this.children[n];if(this.dom.contains(i.dom.parentNode)){t.contentElement=i.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(i=>x(i)&&e.indexOf(i.parentNode)<0&&this.dom.contains(i));n?t.contentElement=n:t.getContent=()=>k.empty}}return t}matchesNode(e,t,n){return this.dirty==G&&e.eq(this.node)&&Yt(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new Jn(this,o&&o.node,e),c=this.node.inlineContent,f=c&&this.node.isBlock;fl(this.node,this.innerDeco,(h,d,p)=>{h.spec.marks?a.syncToMarks(h.spec.marks,n,e,d):h.type.side>=0&&!p&&a.syncToMarks(d==this.node.childCount?C.none:this.node.child(d).marks,n,e,d),a.placeWidget(h,e,i)},(h,d,p,u)=>{a.syncToMarks(h.marks,n,e,u),f&&h.isAtom&&!h.isText&&a.addHackNode("IMG",a.top);let m;a.findNodeMatch(h,d,p,u)||l&&e.state.selection.from>i&&e.state.selection.to<i+h.nodeSize&&(m=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(h,d,p,m,e)||a.updateNextNode(h,d,p,e,u,i)||a.addNode(h,d,p,e,i),i+=h.nodeSize,c&&(f=h.isAtom&&!h.isText)}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==we)&&(o&&this.protectLocalComposition(e,o),ls(this.contentDOM,this.children,e),Ye&&hl(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof D)||n<t||i>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=ul(this.node.content,o,n-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Vn(this,s,t,i);e.input.compositionNodes.push(o),this.children=qn(this.children,n,n+i.length,e,o)}update(e,t,n,i){return this.dirty==Z||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,i),!0)}updateInner(e,t,n,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=G}updateOuterDeco(e){if(Yt(e,this.outerDeco))return;let t=!x(this.nodeDOM),n=this.dom;this.dom=as(this.dom,this.nodeDOM,Wn(this.outerDeco,this.node,t),Wn(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){x(this.nodeDOM)&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){x(this.nodeDOM)&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Ti(r,e,t,n,i){cs(n,e,r);let s=new me(void 0,r,e,t,n,n,n);return s.contentDOM&&s.updateChildren(i,0),s}var Ut=class r extends me{constructor(e,t,n,i,s,o){super(e,t,n,i,s,null,o)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,i){return this.dirty==Z||this.dirty!=G&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=G||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=G,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,n){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new r(this.parent,i,this.outerDeco,this.innerDeco,s,s)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Z)}get domAtom(){return!1}isText(e){return this.node.text==e}},Gt=class extends Re{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==G&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Ln=class extends me{constructor(e,t,n,i,s,o,l,a){super(e,t,n,i,s,o,l),this.spec=a}update(e,t,n,i){if(this.dirty==Z)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,n);return s&&this.updateInner(e,t,n,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,i){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function ls(r,e,t){let n=r.firstChild,i=!1;for(let s=0;s<e.length;s++){let o=e[s],l=o.dom;if(l.parentNode==r){for(;l!=n;)n=Ei(n),i=!0;n=n.nextSibling}else i=!0,r.insertBefore(l,n);if(o instanceof Ne){let a=n?n.previousSibling:r.lastChild;ls(o.contentDOM,o.children,t),n=a?a.nextSibling:r.firstChild}}for(;n;)n=Ei(n),i=!0;i&&t.trackWrites==r&&(t.trackWrites=null)}var yt=function(r){r&&(this.nodeName=r)};yt.prototype=Object.create(null);var Oe=[new yt];function Wn(r,e,t){if(r.length==0)return Oe;let n=t?Oe[0]:new yt,i=[n];for(let s=0;s<r.length;s++){let o=r[s].type.attrs;if(o){o.nodeName&&i.push(n=new yt(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&i.length==1&&i.push(n=new yt(e.isInline?"span":"div")),l=="class"?n.class=(n.class?n.class+" ":"")+a:l=="style"?n.style=(n.style?n.style+";":"")+a:l!="nodeName"&&(n[l]=a))}}}return i}function as(r,e,t,n){if(t==Oe&&n==Oe)return e;let i=e;for(let s=0;s<n.length;s++){let o=n[s],l=t[s];if(s){let a;l&&l.nodeName==o.nodeName&&i!=r&&(a=i.parentNode)&&a.nodeName.toLowerCase()==o.nodeName||(a=document.createElement(o.nodeName),a.pmIsDeco=!0,a.appendChild(i),l=Oe[0]),i=a}ll(i,l||Oe[0],o)}return i}function ll(r,e,t){for(let n in e)n!="class"&&n!="style"&&n!="nodeName"&&!(n in t)&&r.removeAttribute(n);for(let n in t)n!="class"&&n!="style"&&n!="nodeName"&&t[n]!=e[n]&&r.setAttribute(n,t[n]);if(e.class!=t.class){let n=e.class?e.class.split(" ").filter(Boolean):[],i=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<n.length;s++)i.indexOf(n[s])==-1&&r.classList.remove(n[s]);for(let s=0;s<i.length;s++)n.indexOf(i[s])==-1&&r.classList.add(i[s]);r.classList.length==0&&r.removeAttribute("class")}if(e.style!=t.style){if(e.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=n.exec(e.style);)r.style.removeProperty(i[1])}t.style&&(r.style.cssText+=t.style)}}function cs(r,e,t){return as(r,r,Oe,Wn(e,t,!x(r)))}function Yt(r,e){if(r.length!=e.length)return!1;for(let t=0;t<r.length;t++)if(!r[t].type.eq(e[t].type))return!1;return!0}function Ei(r){let e=r.nextSibling;return r.parentNode.removeChild(r),e}var Jn=class{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=al(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,i){let s=0,o=this.stack.length>>1,l=Math.min(o,e.length);for(;s<l&&(s==o-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<o;)this.destroyRest(),this.top.dirty=G,this.index=this.stack.pop(),this.top=this.stack.pop(),o--;for(;o<e.length;){this.stack.push(this.top,this.index+1);let a=-1,c=this.top.children.length;i<this.preMatch.index&&(c=Math.min(this.index+3,c));for(let f=this.index;f<c;f++){let h=this.top.children[f];if(h.matchesMark(e[o])&&!this.isLocked(h.dom)){a=f;break}}if(a<0&&this.index<this.top.children.length){let f=this.top.children[this.index];f instanceof Ne&&f.dirty!=Z&&f.mark.type==e[o].type&&f.spec.update&&!this.isLocked(f.dom)&&f.spec.update(e[o])&&(f.mark=e[o],a=this.index,this.changed=!0)}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let f=Ne.create(this.top,e[o],t,n);this.top.children.splice(this.index,0,f),this.top=f,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,n,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,n)&&!this.preMatch.matched.has(c)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,n,i,s){let o=this.top.children[i];return o.dirty==Z&&o.dom==o.contentDOM&&(o.dirty=we),o.update(e,t,n,s)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let n=e.pmViewDesc;if(n){for(let i=this.index;i<this.top.children.length;i++)if(this.top.children[i]==n)return i}return-1}e=t}}updateNextNode(e,t,n,i,s,o){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof me){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let f=a.dom,h,d=this.isLocked(f)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=Z&&Yt(t,a.outerDeco));if(!d&&a.update(e,t,n,i))return this.destroyBetween(this.index,l),a.dom!=f&&(this.changed=!0),this.index++,!0;if(!d&&(h=this.recreateWrapper(a,e,t,n,i,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=h,h.contentDOM&&(h.dirty=we,h.updateChildren(i,o+1),h.dirty=G),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,i,s,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!Yt(n,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=me.create(this.top,t,n,i,s,o);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,n,i,s){let o=me.create(this.top,e,t,n,i,s);o.contentDOM&&o.updateChildren(i,s+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,n){let i=this.index<this.top.children.length?this.top.children[this.index]:null;if(i&&i.matchesWidget(e)&&(e==i.widget||!i.widget.type.toDOM.parentNode))this.index++;else{let s=new jt(this.top,e,t,n);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Ne;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Ut)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((V||B)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);e=="IMG"&&(n.className="ProseMirror-separator",n.alt=""),e=="BR"&&(n.className="ProseMirror-trailingBreak");let i=new Gt(this.top,[],n,null);t!=this.top?t.children.push(i):t.children.splice(this.index++,0,i),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||x(e)&&e.contains(this.lock.parentNode))}};function al(r,e){let t=e,n=t.children.length,i=r.childCount,s=new Map,o=[];e:for(;i>0;){let l;for(;;)if(n){let c=t.children[n-1];if(c instanceof Ne)t=c,n=c.children.length;else{l=c,n--;break}}else{if(t==e)break e;n=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=r.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function cl(r,e){return r.type.side-e.type.side}function fl(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let c=0;c<r.childCount;c++){let f=r.child(c);n(f,i,e.forChild(s,f),c),s+=f.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let f,h;for(;o<i.length&&i[o].to==s;){let g=i[o++];g.widget&&(f?(h||(h=[f])).push(g):f=g)}if(f)if(h){h.sort(cl);for(let g=0;g<h.length;g++)t(h[g],c,!!a)}else t(f,c,!!a);let d,p;if(a)p=-1,d=a,a=null;else if(c<r.childCount)p=c,d=r.child(c++);else break;for(let g=0;g<l.length;g++)l[g].to<=s&&l.splice(g--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)l.push(i[o++]);let u=s+d.nodeSize;if(d.isText){let g=u;o<i.length&&i[o].from<g&&(g=i[o].from);for(let y=0;y<l.length;y++)l[y].to<g&&(g=l[y].to);g<u&&(a=d.cut(g-s),d=d.cut(0,g-s),u=g,p=-1)}else for(;o<i.length&&i[o].to<u;)o++;let m=d.isInline&&!d.isLeaf?l.filter(g=>!g.inline):l.slice();n(d,m,e.forChild(s,d),p),s=u}}function hl(r){if(r.nodeName=="UL"||r.nodeName=="OL"){let e=r.style.cssText;r.style.cssText=e+"; list-style: square !important",window.getComputedStyle(r).listStyle,r.style.cssText=e}}function ul(r,e,t,n){for(let i=0,s=0;i<r.childCount&&s<=n;){let o=r.child(i++),l=s;if(s+=o.nodeSize,!o.isText)continue;let a=o.text;for(;i<r.childCount;){let c=r.child(i++);if(s+=c.nodeSize,!c.isText)break;a+=c.text}if(s>=t){if(s>=n&&a.slice(n-e.length-l,n-l)==e)return n-e.length;let c=l<n?a.lastIndexOf(e,n-l-1):-1;if(c>=0&&c+e.length+l>=t)return l+c;if(t==n&&a.length>=n+e.length-l&&a.slice(n-l,n-l+e.length)==e)return n}}return-1}function qn(r,e,t,n,i){let s=[];for(let o=0,l=0;o<r.length;o++){let a=r[o],c=l,f=l+=a.size;c>=t||f<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,n)),i&&(s.push(i),i=void 0),f>t&&s.push(a.slice(t-c,a.size,n)))}return s}function er(r,e=null){let t=r.domSelectionRange(),n=r.state.doc;if(!t.focusNode)return null;let i=r.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=r.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,c;if(rn(t)){for(a=o;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&S.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&qo(t.focusNode,t.focusOffset,i.dom))){let h=i.posBefore;c=new S(o==h?l:n.resolve(h))}else if(j&&e=="key"&&o>r.state.selection.to&&x(t.focusNode)&&t.focusOffset==t.focusNode.childNodes.length&&i&&i.posAtStart>r.state.selection.to)for(let h=t.focusNode;;h=h.parentNode){if(getComputedStyle(h).overflow!="visible"){c=N.findFrom(n.resolve(i.posAtStart),1);break}if(h==i.dom||h.nextSibling||!h.parentNode||!x(h.parentNode))break}}else{if(t instanceof r.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let h=o,d=o;for(let p=0;p<t.rangeCount;p++){let u=t.getRangeAt(p);h=Math.min(h,r.docView.posFromDOM(u.startContainer,u.startOffset,1)),d=Math.max(d,r.docView.posFromDOM(u.endContainer,u.endOffset,-1))}if(h<0)return null;[a,o]=d==r.state.selection.anchor?[d,h]:[h,d],l=n.resolve(o)}else a=r.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let f=n.resolve(a);if(!c){let h=e=="pointer"||r.state.selection.head<l.pos&&!s?1:-1;c=tr(r,f,l,h)}return c}function fs(r){return r.editable?r.hasFocus():us(r)&&document.activeElement&&document.activeElement.contains(r.dom)}function ae(r,e=!1){let t=r.state.selection;if(hs(r,t),!fs(r))return;let n=r.input.mouseDown;if(!e&&B&&n){let i=r.domSelectionRange(),s=r.domObserver.currentSelection;if(i.anchorNode&&s.anchorNode&&Ae(i.anchorNode,i.anchorOffset,s.anchorNode,s.anchorOffset)&&n.delaySelUpdate()){r.domObserver.setCurSelection();return}}if(r.domObserver.disconnectSelection(),r.cursorWrapper)pl(r);else{let{anchor:i,head:s}=t,o,l;Ai&&!(t instanceof D)&&(t.$from.parent.inlineContent||(o=Ii(r,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(l=Ii(r,t.to))),r.docView.setSelection(i,s,r,e),Ai&&(o&&Ri(o),l&&Ri(l)),t.visible?r.dom.classList.remove("ProseMirror-hideselection"):(r.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&dl(r))}r.domObserver.setCurSelection(),r.domObserver.connectSelection()}var Ai=V||B&&Zi<63;function Ii(r,e){let{node:t,offset:n}=r.docView.domFromPos(e,0),i=n<t.childNodes.length?t.childNodes[n]:null,s=n?t.childNodes[n-1]:null;if(V&&i&&i.contentEditable=="false")return An(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return An(i);if(s)return An(s)}}function An(r){return r.contentEditable="true",V&&r.draggable&&(r.draggable=!1,r.wasDraggable=!0),r}function Ri(r){r.contentEditable="false",r.wasDraggable&&(r.draggable=!0,r.wasDraggable=null)}function dl(r){let e=r.dom.ownerDocument;e.removeEventListener("selectionchange",r.input.hideSelectionGuard);let t=r.domSelectionRange(),n=t.anchorNode,i=t.anchorOffset;e.addEventListener("selectionchange",r.input.hideSelectionGuard=()=>{(t.anchorNode!=n||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!fs(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function pl(r){let e=r.domSelection();if(!e)return;let t=r.cursorWrapper.dom,n=t.nodeName=="IMG";n?e.collapse(t.parentNode,R(t)+1):e.collapse(t,0),!n&&!r.state.selection.visible&&K&&pe<=11&&(t.disabled=!0,t.disabled=!1)}function hs(r,e){if(e instanceof S){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(Bi(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else Bi(r)}function Bi(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function tr(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||D.between(e,t,n)}function Pi(r){return r.editable&&!r.hasFocus()?!1:us(r)}function us(r){let e=r.domSelectionRange();if(!e.anchorNode)return!1;try{return Ie(r.dom,e.anchorNode)&&(r.editable||Ie(r.dom,e.focusNode))}catch{return!1}}function ml(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return Ae(e.node,e.offset,t.anchorNode,t.anchorOffset)}function $n(r,e){let{$anchor:t,$head:n}=r.selection,i=e>0?t.max(n):t.min(n),s=i.parent.inlineContent?i.depth?r.doc.resolve(e>0?i.after():i.before()):null:i;return s&&N.findFrom(s,e)}function de(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function zi(r,e,t){let n=r.state.selection;if(n instanceof D)if(t.indexOf("s")>-1){let{$head:i}=n,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=r.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return de(r,new D(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=$n(r.state,e);return i&&i instanceof S?de(r,i):!1}else if(!(U&&t.indexOf("m")>-1)){let i=n.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=r.docView.descAt(l))&&!o.contentDOM?S.isSelectable(s)?de(r,new S(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):de(r,new D(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1}}else return!1;else{if(n instanceof S&&n.node.isInline)return de(r,new D(e>0?n.$to:n.$from));{let i=$n(r.state,e);return i?de(r,i):!1}}}function kt(r,e){let t=r.pmViewDesc;return t?t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR"):x(r)&&r.contentEditable=="false"}function je(r,e){return e<0?gl(r):yl(r)}function gl(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(j&&x(t)&&n<F(t)&&kt(t.childNodes[n],-1)&&(o=!0);;)if(n>0){if(!x(t))break;let l=t.childNodes[n-1];if(kt(l,-1))i=t,s=--n;else if(E(l))t=l,n=t.nodeValue.length;else break}else{if(ds(t))break;{let l=t.previousSibling;for(;l&&kt(l,-1);)i=t.parentNode,s=R(l),l=l.previousSibling;if(l)t=l,n=F(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?Kn(r,t,n):i&&Kn(r,i,s)}function yl(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=F(t),s,o;for(;;)if(n<i){if(!x(t))break;let l=t.childNodes[n];if(kt(l,1))s=t,o=++n;else break}else{if(ds(t))break;{let l=t.nextSibling;for(;l&&kt(l,1);)s=l.parentNode,o=R(l)+1,l=l.nextSibling;if(l)t=l,n=0,i=F(t);else{if(t=t.parentNode,t==r.dom)break;n=i=0}}}s&&Kn(r,s,o)}function ds(r){let e=r.pmViewDesc;return e&&e.node&&e.node.isBlock}function kl(r,e){for(;r&&e==r.childNodes.length&&!Ct(r);)e=R(r)+1,r=r.parentNode;for(;r&&e<r.childNodes.length;){let t=r.childNodes[e];if(E(t))return t;if(x(t)&&t.contentEditable=="false")break;r=t,e=0}}function bl(r,e){for(;r&&!e&&!Ct(r);)e=R(r),r=r.parentNode;for(;r&&e;){let t=r.childNodes[e-1];if(E(t))return t;if(x(t)&&t.contentEditable=="false")break;r=t,e=r.childNodes.length}}function Kn(r,e,t){if(!E(e)){let s,o;(o=kl(e,t))?(e=o,t=0):(s=bl(e,t))&&(e=s,t=s.nodeValue.length)}let n=r.domSelection();if(!n)return;if(rn(n)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),n.removeAllRanges(),n.addRange(s)}else n.extend&&n.extend(e,t);r.domObserver.setCurSelection();let{state:i}=r;setTimeout(()=>{r.state==i&&ae(r)},50)}function vi(r,e){let t=r.state.doc.resolve(e);if(!(B||Qi)&&t.parent.inlineContent){let i=r.coordsAtPos(e);if(e>t.start()){let s=r.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left<i.left?"ltr":"rtl"}if(e<t.end()){let s=r.coordsAtPos(e+1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(r.dom).direction=="rtl"?"rtl":"ltr"}function Fi(r,e,t){let n=r.state.selection;if(n instanceof D&&!n.empty||t.indexOf("s")>-1||U&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=$n(r.state,e);if(o&&o instanceof S)return de(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof _?N.near(o,e):N.findFrom(o,e);return l?de(r,l):!1}return!1}function Vi(r,e){if(!(r.state.selection instanceof D))return!0;let{$head:t,$anchor:n,empty:i}=r.state.selection;if(!t.sameParent(n))return!0;if(!i)return!1;if(r.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=r.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),r.dispatch(o),!0}return!1}function Li(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function xl(r){if(!V||r.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(e&&x(e)&&t==0&&e.firstChild&&x(e.firstChild)&&e.firstChild.contentEditable=="false"){let n=e.firstChild;Li(r,n,"true"),setTimeout(()=>Li(r,n,"false"),20)}return!1}function Sl(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function Ml(r,e){let t=e.keyCode,n=Sl(e);if(t==8||U&&t==72&&n=="c")return Vi(r,-1)||je(r,-1);if(t==46&&!e.shiftKey||U&&t==68&&n=="c")return Vi(r,1)||je(r,1);if(t==13||t==27)return!0;if(t==37||U&&t==66&&n=="c"){let i=t==37?vi(r,r.state.selection.from)=="ltr"?-1:1:-1;return zi(r,i,n)||je(r,i)}else if(t==39||U&&t==70&&n=="c"){let i=t==39?vi(r,r.state.selection.from)=="ltr"?1:-1:1;return zi(r,i,n)||je(r,i)}else{if(t==38||U&&t==80&&n=="c")return Fi(r,-1,n)||je(r,-1);if(t==40||U&&t==78&&n=="c")return xl(r)||Fi(r,1,n)||je(r,1);if(n==(U?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function nr(r,e){r.someProp("transformCopied",p=>{e=p(e,r)});let t=[],{content:n,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){i--,s--;let p=n.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),n=p.content}let o=r.someProp("clipboardSerializer")||Se.fromSchema(r.state.schema),l=bs(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let c=a.firstChild,f,h=0;for(;c&&x(c)&&(f=ks[c.nodeName.toLowerCase()]);){for(let p=f.length-1;p>=0;p--){let u=l.createElement(f[p]);for(;a.firstChild;)u.appendChild(a.firstChild);a.appendChild(u),h++}c=a.firstChild}c&&x(c)&&c.setAttribute("data-pm-slice",`${i} ${s}${h?` -${h}`:""} ${JSON.stringify(t)}`);let d=r.someProp("clipboardTextSerializer",p=>p(e,r))||e.content.textBetween(0,e.content.size,`
1
+ import{a as Mr,c as Cr}from"./chunk-YSGSC7KM.js";import{a as Fe}from"./chunk-74O4WKIV.js";import"./chunk-AU4HFPIY.js";function z(r){this.content=r}z.prototype={constructor:z,find:function(r){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===r)return e;return-1},get:function(r){var e=this.find(r);return e==-1?void 0:this.content[e+1]},update:function(r,e,t){var n=t&&t!=r?this.remove(t):this,i=n.find(r),s=n.content.slice();return i==-1?s.push(t||r,e):(s[i+1]=e,t&&(s[i]=t)),new z(s)},remove:function(r){var e=this.find(r);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new z(t)},addToStart:function(r,e){return new z([r,e].concat(this.remove(r).content))},addToEnd:function(r,e){var t=this.remove(r).content.slice();return t.push(r,e),new z(t)},addBefore:function(r,e,t){var n=this.remove(e),i=n.content.slice(),s=n.find(r);return i.splice(s==-1?i.length:s,0,e,t),new z(i)},forEach:function(r){for(var e=0;e<this.content.length;e+=2)r(this.content[e],this.content[e+1])},prepend:function(r){return r=z.from(r),r.size?new z(r.content.concat(this.subtract(r).content)):this},append:function(r){return r=z.from(r),r.size?new z(this.subtract(r).content.concat(r.content)):this},subtract:function(r){var e=this;r=z.from(r);for(var t=0;t<r.content.length;t+=2)e=e.remove(r.content[t]);return e},toObject:function(){var r={};return this.forEach(function(e,t){r[e]=t}),r},get size(){return this.content.length>>1}};z.from=function(r){if(r instanceof z)return r;var e=[];if(r)for(var t in r)e.push(t,r[t]);return new z(e)};var cn=z;function Pr(r,e,t){for(let n=0;;n++){if(n==r.childCount||n==e.childCount)return r.childCount==e.childCount?null:t;let i=r.child(n),s=e.child(n);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){let o=i.text,l=s.text,a=0;for(;o[a]==l[a];a++)t++;return a&&a<o.length&&a<l.length&&Fr(o.charCodeAt(a-1))&&vr(o.charCodeAt(a))&&t--,t}if(i.content.size||s.content.size){let o=Pr(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function zr(r,e,t,n){for(let i=r.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:n};let o=r.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,n-=a;continue}if(!o.sameMarkup(l))return{a:t,b:n};if(o.isText&&o.text!=l.text){let c=o.text,f=l.text,h=c.length,d=f.length;for(;h>0&&d>0&&c[h-1]==f[d-1];)h--,d--,t--,n--;return h&&d&&h<c.length&&Fr(c.charCodeAt(h-1))&&vr(c.charCodeAt(h))&&(t++,n++),{a:t,b:n}}if(o.content.size||l.content.size){let c=zr(o.content,l.content,t-1,n-1);if(c)return c}t-=a,n-=a}}function vr(r){return r>=56320&&r<57344}function Fr(r){return r>=55296&&r<56320}var k=class r{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,i=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&n(a,i+l,s||null,o)!==!1&&a.content.size){let f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),n,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new r(i,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let n=[],i=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),n.push(l),i+=l.nodeSize),o=a}return new r(n,i)}cutByIndex(e,t){return e==t?r.empty:e==0&&t==this.content.length?this:new r(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-n.nodeSize;return i[e]=t,new r(i,s)}addToStart(e){return new r([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new r(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let i=this.content[t];e(i,n,t),n+=i.nodeSize}}findDiffStart(e,t=0){return Pr(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return zr(this,e,t,n)}findIndex(e){if(e==0)return Et(0,e);if(e==this.size)return Et(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let i=this.child(t),s=n+i.nodeSize;if(s>=e)return s==e?Et(t+1,s):Et(t,n);n=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return r.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return r.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return r.empty;let t,n=0;for(let i=0;i<e.length;i++){let s=e[i];n+=s.nodeSize,i&&s.isText&&e[i-1].sameMarkup(s)?(t||(t=e.slice(0,i)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new r(t||e,n)}static from(e){if(!e)return r.empty;if(e instanceof r)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new r([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}};k.empty=new k([],0);var fn={index:0,offset:0};function Et(r,e){return fn.index=r,fn.offset=e,fn}function Rt(r,e){if(r===e)return!0;if(!(r&&typeof r=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(r);if(Array.isArray(e)!=t)return!1;if(t){if(r.length!=e.length)return!1;for(let n=0;n<r.length;n++)if(!Rt(r[n],e[n]))return!1}else{for(let n in r)if(!(n in e)||!Rt(r[n],e[n]))return!1;for(let n in e)if(!(n in r))return!1}return!0}var C=class r{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let i=0;i<e.length;i++){let s=e[i];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,i));else{if(s.type.excludes(this.type))return e;!n&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Rt(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);return n.create(t.attrs)}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return r.none;if(e instanceof r)return[e];let t=e.slice();return t.sort((n,i)=>n.type.rank-i.type.rank),t}};C.none=[];var he=class extends Error{},b=class r{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=Lr(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new r(n,this.openStart,this.openEnd)}removeBetween(e,t){return new r(Vr(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return r.empty;let n=t.openStart||0,i=t.openEnd||0;if(typeof n!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new r(k.fromJSON(e,t.content),n,i)}static maxOpen(e,t=!0){let n=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)n++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new r(e,n,i)}};b.empty=new b(k.empty,0,0);function Vr(r,e,t){let{index:n,offset:i}=r.findIndex(e),s=r.maybeChild(n),{index:o,offset:l}=r.findIndex(t);if(i==e||s.isText){if(l!=t&&!r.child(o).isText)throw new RangeError("Removing non-flat range");return r.cut(0,e).append(r.cut(t))}if(n!=o)throw new RangeError("Removing non-flat range");return r.replaceChild(n,s.copy(Vr(s.content,e-i-1,t-i-1)))}function Lr(r,e,t,n,i,s){let{index:o,offset:l}=r.findIndex(e),a=r.maybeChild(o);if(l==e||a.isText)return s&&n<=0&&i<=0&&!s.canReplace(o,o,t)?null:r.cut(0,e).append(t).append(r.cut(e));let c=Lr(a.content,e-l-1,t,o==0?n-1:0,o==r.childCount-1?i-1:0,a);return c&&r.replaceChild(o,a.copy(c))}function Us(r,e,t){if(t.openStart>r.depth)throw new he("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new he("Inconsistent open depths");return Wr(r,e,t,0)}function Wr(r,e,t,n){let i=r.index(n),s=r.node(n);if(i==e.index(n)&&n<r.depth-t.openStart){let o=Wr(r,e,t,n+1);return s.copy(s.content.replaceChild(i,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&r.depth==n&&e.depth==n){let o=r.parent,l=o.content;return be(o,l.cut(0,r.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=Gs(t,r);return be(s,qr(r,o,l,e,n))}else return be(s,Bt(r,e,n))}function Jr(r,e){if(!e.type.compatibleContent(r.type))throw new he("Cannot join "+e.type.name+" onto "+r.type.name)}function hn(r,e,t){let n=r.node(t);return Jr(n,e.node(t)),n}function ke(r,e){let t=e.length-1;t>=0&&r.isText&&r.sameMarkup(e[t])?e[t]=r.withText(e[t].text+r.text):e.push(r)}function et(r,e,t,n){let i=(e||r).node(t),s=0,o=e?e.index(t):i.childCount;r&&(s=r.index(t),r.depth>t?s++:r.textOffset&&(ke(r.nodeAfter,n),s++));for(let l=s;l<o;l++)ke(i.child(l),n);e&&e.depth==t&&e.textOffset&&ke(e.nodeBefore,n)}function be(r,e){if(!r.type.validContent(e))throw new he("Invalid content for node "+r.type.name);return r.copy(e)}function qr(r,e,t,n,i){let s=r.depth>i&&hn(r,e,i+1),o=n.depth>i&&hn(t,n,i+1),l=[];return et(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Jr(s,o),ke(be(s,qr(r,e,t,n,i+1)),l)):(s&&ke(be(s,Bt(r,e,i+1)),l),et(e,t,i,l),o&&ke(be(o,Bt(t,n,i+1)),l)),et(n,null,i,l),new k(l)}function Bt(r,e,t){let n=[];if(et(null,r,t,n),r.depth>t){let i=hn(r,e,t+1);ke(be(i,Bt(r,e,t+1)),n)}return et(e,null,t,n),new k(n)}function Gs(r,e){let t=e.depth-r.openStart,i=e.node(t).copy(r.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(k.from(i));return{start:i.resolveNoCache(r.openStart+t),end:i.resolveNoCache(i.content.size-r.openEnd-t)}}var Pt=class r{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],i=e.child(t);return n?e.child(t).cut(n):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)i+=n.child(s).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return C.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),i=e.maybeChild(t);if(!n){let l=n;n=i,i=l}let s=n.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!i||!s[o].isInSet(i.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,i=e.parent.maybeChild(e.index());for(var s=0;s<n.length;s++)n[s].type.spec.inclusive===!1&&(!i||!n[s].isInSet(i.marks))&&(n=n[s--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new dn(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(n.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new r(t,n,s)}static resolveCached(e,t){let n=wr.get(e);if(n)for(let s=0;s<n.elts.length;s++){let o=n.elts[s];if(o.pos==t)return o}else wr.set(e,n=new un);let i=n.elts[n.i]=r.resolve(e,t);return n.i=(n.i+1)%Ys,i}},un=class{constructor(){this.elts=[],this.i=0}},Ys=12,wr=new WeakMap,dn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},Xs=Object.create(null),Q=class r{constructor(e,t,n,i=C.none){this.type=e,this.attrs=t,this.marks=i,this.content=n||k.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,i=0){this.content.nodesBetween(e,t,n,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,i){return this.content.textBetween(e,t,n,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&Rt(this.attrs,t||e.defaultAttrs||Xs)&&C.sameSet(this.marks,n||C.none)}copy(e=null){return e==this.content?this:new r(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new r(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return b.empty;let i=this.resolve(e),s=this.resolve(t),o=n?0:i.sharedDepth(t),l=i.start(o),c=i.node(o).content.cut(i.pos-l,s.pos-l);return new b(c,i.depth-o,s.depth-o)}replace(e,t,n){return Us(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(i==e||t.isText)return t;e-=i+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let i=this.content.child(t-1);return{node:i,index:t-1,offset:n-i.nodeSize}}resolve(e){return Pt.resolveCached(this,e)}resolveNoCache(e){return Pt.resolve(this,e)}rangeHasMark(e,t,n){let i=!1;return t>e&&this.nodesBetween(e,t,s=>(n.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),$r(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=k.empty,i=0,s=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;a<s;a++)if(!this.type.allowsMarks(n.child(a).marks))return!1;return!0}canReplaceWith(e,t,n,i){if(i&&!this.type.allowsMarks(i))return!1;let s=this.contentMatchAt(e).matchType(n),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),Or(this.type.attrs,this.attrs,"node",this.type.name);let e=C.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];Or(n.type.attrs,n.attrs,"mark",n.type.name),e=n.addToSet(e)}if(!C.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let i=k.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,n)}};Q.prototype.text=void 0;var pn=class r extends Q{constructor(e,t,n,i){if(super(e,t,null,i),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):$r(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new r(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new r(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function $r(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}function Or(r,e,t,n){for(let i in e)if(!(i in r))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${n}`);for(let i in r)r[i].validate&&r[i].validate(e[i])}var xe=class r{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new mn(e,t);if(n.next==null)return r.empty;let i=Kr(n);n.next&&n.err("Unexpected trailing text");let s=io(ro(i));return so(s,n),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let i=this;for(let s=t;i&&s<n;s++)i=i.matchType(e.child(s).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let i=[this];function s(o,l){let a=o.matchFragment(e,n);if(a&&(!t||a.validEnd))return k.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:f,next:h}=o.next[c];if(!(f.isText||f.hasRequiredAttrs())&&i.indexOf(h)==-1){i.push(h);let d=s(h,l.concat(f));if(d)return d}}return null}return s(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let i=n.shift(),s=i.match;if(s.matchType(e)){let o=[];for(let l=i;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!i.type||a.validEnd)&&(n.push({match:l.contentMatch,type:l,via:i}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let i=0;i<n.next.length;i++)e.indexOf(n.next[i].next)==-1&&t(n.next[i].next)}return t(this),e.map((n,i)=>{let s=i+(n.validEnd?"*":" ")+" ";for(let o=0;o<n.next.length;o++)s+=(o?", ":"")+n.next[o].type.name+"->"+e.indexOf(n.next[o].next);return s}).join(`
2
+ `)}};xe.empty=new xe(!0);var mn=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Kr(r){let e=[];do e.push(Zs(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Zs(r){let e=[];do e.push(Qs(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Qs(r){let e=no(r);for(;;)if(r.eat("+"))e={type:"plus",expr:e};else if(r.eat("*"))e={type:"star",expr:e};else if(r.eat("?"))e={type:"opt",expr:e};else if(r.eat("{"))e=eo(r,e);else break;return e}function Nr(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function eo(r,e){let t=Nr(r),n=t;return r.eat(",")&&(r.next!="}"?n=Nr(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function to(r,e){let t=r.nodeTypes,n=t[e];if(n)return[n];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&r.err("No node type or group '"+e+"' found"),i}function no(r){if(r.eat("(")){let e=Kr(r);return r.eat(")")||r.err("Missing closing paren"),e}else if(/\W/.test(r.next))r.err("Unexpected token '"+r.next+"'");else{let e=to(r,r.next).map(t=>(r.inline==null?r.inline=t.isInline:r.inline!=t.isInline&&r.err("Mixing inline and block content"),{type:"name",value:t}));return r.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function ro(r){let e=[[]];return i(s(r,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return n(l,a),i(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let f=t();i(s(o.expr,a),f),a=f}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let f=t();n(a,f),i(s(o.expr,a),f),a=f}return[n(a)]}else{if(o.type=="name")return[n(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Hr(r,e){return e-r}function Dr(r,e){let t=[];return n(e),t.sort(Hr);function n(i){let s=r[i];if(s.length==1&&!s[0].term)return n(s[0].to);t.push(i);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&n(a)}}}function io(r){let e=Object.create(null);return t(Dr(r,0));function t(n){let i=[];n.forEach(o=>{r[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f<i.length;f++)i[f][0]==l&&(c=i[f][1]);Dr(r,a).forEach(f=>{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let s=e[n.join(",")]=new xe(n.indexOf(r.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(Hr);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function so(r,e){for(let t=0,n=[r];t<n.length;t++){let i=n[t],s=!i.validEnd,o=[];for(let l=0;l<i.next.length;l++){let{type:a,next:c}=i.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),n.indexOf(c)==-1&&n.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function _r(r){let e=Object.create(null);for(let t in r){let n=r[t];if(!n.hasDefault)return null;e[t]=n.default}return e}function jr(r,e){let t=Object.create(null);for(let n in r){let i=r[n],s=e&&e[n];if(s===void 0)if(i.hasDefault)s=i.default;else throw new RangeError("No value supplied for attribute "+n);else i.validate&&i.validate(s);t[n]=s}return t}function Ur(r,e){let t=Object.create(null);if(e)for(let n in e)t[n]=new gn(r,n,e[n]);return t}var zt=class r{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=Ur(e,n.attrs),this.defaultAttrs=_r(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==xe.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:jr(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Q(this,this.computeAttrs(e),k.from(t),C.setFrom(n))}createChecked(e=null,t,n){return t=k.from(t),this.checkContent(t),new Q(this,this.computeAttrs(e),t,C.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=k.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(k.empty,!0);return s?new Q(this,e,t.append(s),C.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let n=0;n<e.childCount;n++)if(!this.allowsMarks(e.child(n).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:C.none:e}static compile(e,t){let n=Object.create(null);e.forEach((s,o)=>n[s]=new r(s,t,o));let i=t.spec.topNode||"doc";if(!n[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let s in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}};function oo(r,e,t){let n=t.split("|");return i=>{let s=i===null?"null":typeof i;if(n.indexOf(s)<0)throw new RangeError(`Expected value of type ${n} for attribute ${e} on type ${r}, got ${s}`)}}var gn=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?oo(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},nt=class r{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=Ur(e,i.attrs),this.excluded=null;let s=_r(this.attrs);this.instance=s?new C(this,s):null}create(e=null){return!e&&this.instance?this.instance:new C(this,jr(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new r(s,i++,t,o)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}excludes(e){return this.excluded.indexOf(e)>-1}},Le=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=cn.from(e.nodes),t.marks=cn.from(e.marks||{}),this.nodes=zt.compile(this.spec.nodes,this),this.marks=nt.compile(this.spec.marks,this);let n=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=n[o]||(n[o]=xe.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Tr(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Tr(this,o.split(" "))}this.nodeFromJSON=i=>Q.fromJSON(this,i),this.markFromJSON=i=>C.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof zt){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,n,i)}text(e,t){let n=this.nodes.text;return new pn(n,n.defaultAttrs,e,C.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Tr(r,e){let t=[];for(let n=0;n<e.length;n++){let i=e[n],s=r.marks[i],o=s;if(s)t.push(s);else for(let l in r.marks){let a=r.marks[l];(i=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(i)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[n]+"'")}return t}function lo(r){return r.tag!=null}function ao(r){return r.style!=null}var rt=class r{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(i=>{if(lo(i))this.tags.push(i);else if(ao(i)){let s=/[^=]*/.exec(i.style)[0];n.indexOf(s)<0&&n.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let n=new vt(this,t,!1);return n.addAll(e,C.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new vt(this,t,!0);return n.addAll(e,C.none,t.from,t.to),b.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;i<this.tags.length;i++){let s=this.tags[i];if(ho(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,n,i){for(let s=i?this.styles.indexOf(i)+1:0;s<this.styles.length;s++){let o=this.styles[s],l=o.style;if(!(l.indexOf(e)!=0||o.context&&!n.matchesContext(o.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function n(i){let s=i.priority==null?50:i.priority,o=0;for(;o<t.length;o++){let l=t[o];if((l.priority==null?50:l.priority)<s)break}t.splice(o,0,i)}for(let i in e.marks){let s=e.marks[i].spec.parseDOM;s&&s.forEach(o=>{n(o=Ar(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{n(o=Ar(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new r(e,r.schemaRules(e)))}},Gr={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},co={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Yr={ol:!0,ul:!0},it=1,yn=2,tt=4;function Er(r,e,t){return e!=null?(e?it:0)|(e==="full"?yn:0):r&&r.whitespace=="pre"?it|yn:t&~tt}var Ve=class{constructor(e,t,n,i,s,o){this.type=e,this.attrs=t,this.marks=n,this.solid=i,this.options=o,this.content=[],this.activeMarks=C.none,this.match=s||(o&tt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(k.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let n=this.type.contentMatch,i;return(i=n.findWrapping(e.type))?(this.match=n,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&it)){let n=this.content[this.content.length-1],i;if(n&&n.isText&&(i=/[ \t\r\n\u000c]+$/.exec(n.text))){let s=n;n.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=k.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(k.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Gr.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},vt=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let i=t.topNode,s,o=Er(null,t.preserveWhitespace,0)|(n?tt:0);i?s=new Ve(i.type,i.attrs,C.none,!0,t.topMatch||i.type.contentMatch,o):n?s=new Ve(null,null,C.none,!0,null,o):s=new Ve(e.schema.topNodeType,null,C.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,i=this.top,s=i.options&yn?"full":this.localPreserveWS||(i.options&it)>0,{schema:o}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if(s==="full")n=n.replace(/\r\n?/g,`
3
+ `);else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=n.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(o.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(o.text(l[a]),t,!/\S/.test(l[a]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let l=i.content[i.content.length-1],a=e.previousSibling;(!l||a&&a.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(n=n.slice(1))}n&&this.insertNode(o.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let i=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;Yr.hasOwnProperty(o)&&this.parser.normalizeLists&&fo(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,n));e:if(a?a.ignore:co.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let c,f=this.needsBlock;if(Gr.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let h=a&&a.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),c&&this.sync(s),this.needsBlock=f}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
4
+ `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let s=this.parser.matchedStyles[i],o=n.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(c=>!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,n,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName=="BR")||this.leafFallback(e,n);else{let a=this.enter(o,t.attrs||null,n,t.preserveWhitespace);a&&(s=!0,n=a)}else{let a=this.parser.schema.marks[t.mark];n=n.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,n,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,n,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,n),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,n,i){let s=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,n){let i,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!i||i.length>c.length+l)&&(i=c,s=a,!c.length))break;if(a.solid){if(n)break;l+=2}}if(!i)return null;this.sync(s);for(let o=0;o<i.length;o++)t=this.enterInner(i[o],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let i=this.findPlace(e,t,n);if(i){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=C.none;for(let l of i.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):Ir(l.type,e.type))&&(o=l.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,n,i){let s=this.findPlace(e.create(t),n,!1);return s&&(s=this.enterInner(e,t,n,!0,i)),s}enterInner(e,t,n,i=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=Er(e,s,o.options);o.options&tt&&o.content.length==0&&(l|=tt);let a=C.none;return n=n.filter(c=>(o.type?o.type.allowsMarkType(c.type):Ir(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ve(e,t,a,i,null,l)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=it)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let i=n.length-1;i>=0;i--)e+=n[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&t.compareDocumentPosition(this.find[i].node)&(n?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,i=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!f||f.name!=c&&!f.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}};function fo(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Yr.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function ho(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function Ar(r){let e={};for(let t in r)e[t]=r[t];return e}function Ir(r,e){let t=e.schema.nodes;for(let n in t){let i=t[n];if(!i.allowsMarkType(r))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:c,next:f}=l.edge(a);if(c==e||s.indexOf(f)<0&&o(f))return!0}};if(o(i.contentMatch))return!0}}var Se=class r{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=At(t).createDocumentFragment());let i=n,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let c=o.marks[a];if(!this.marks[c.type.name]){a++;continue}if(!c.eq(s[l][0])||c.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)i=s.pop()[1];for(;a<o.marks.length;){let c=o.marks[a++],f=this.serializeMark(c,o.isInline,t);f&&(s.push([c,i]),i.appendChild(f.dom),i=f.contentDOM||f.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),n}serializeNodeInner(e,t){if(e.isText)return At(t).createTextNode(e.text);let{dom:n,contentDOM:i}=It(At(t),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,i)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let i=e.marks.length-1;i>=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let i=this.marks[e.type.name];return i&&It(At(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return typeof t=="string"?{dom:e.createTextNode(t)}:It(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new r(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Rr(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return Rr(e.marks)}};function Rr(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function At(r){return r.document||window.document}var Br=new WeakMap;function uo(r){let e=Br.get(r);return e===void 0&&Br.set(r,e=po(r)),e}function po(r){let e=null;function t(n){if(n&&typeof n=="object")if(Array.isArray(n))if(typeof n[0]=="string")e||(e=[]),e.push(n);else for(let i=0;i<n.length;i++)t(n[i]);else for(let i in n)t(n[i])}return t(r),e}function It(r,e,t,n){if(e.nodeType==1)return{dom:e};if(e.dom&&e.dom.nodeType==1)return e;let i=e[0],s;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(n&&(s=uo(n))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?r.createElementNS(t,i):r.createElement(i),c=e[1],f=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){f=2;for(let h in c)if(c[h]!=null){let d=h.indexOf(" ");d>0?a.setAttributeNS(h.slice(0,d),h.slice(d+1),c[h]):h=="style"&&a.style?a.style.cssText=c[h]:a.setAttribute(h,c[h])}}for(let h=f;h<e.length;h++){let d=e[h];if(d===0){if(h<e.length-1||h>f)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else if(typeof d=="string")a.appendChild(r.createTextNode(d));else{let{dom:p,contentDOM:u}=It(r,d,t,n);if(a.appendChild(p),u){if(l)throw new RangeError("Multiple content holes");l=u}}}return{dom:a,contentDOM:l}}var ei=65535,ti=Math.pow(2,16);function mo(r,e){return r+e*ti}function Xr(r){return r&ei}function go(r){return(r-(r&ei))/ti}var ni=1,ri=2,Ft=4,ii=8,lt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&ii)>0}get deletedBefore(){return(this.delInfo&(ni|Ft))>0}get deletedAfter(){return(this.delInfo&(ri|Ft))>0}get deletedAcross(){return(this.delInfo&Ft)>0}},re=class r{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&r.empty)return r.empty}recover(e){let t=0,n=Xr(e);if(!this.inverted)for(let i=0;i<n;i++)t+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[n*3]+t+go(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],f=this.ranges[l+o],h=a+c;if(e<=h){let d=c?e==a?-1:e==h?1:t:t,p=a+i+(d<0?0:f);if(n)return p;let u=e==(t<0?a:h)?null:mo(l/3,e-a),m=0;return c&&(m|=e==a?ri:e==h?ni:Ft,(t<0?e!=a:e!=h)&&(m|=ii)),new lt(p,m,u)}i+=f-c}return n?e+i:new lt(e+i,0,null)}touches(e,t){let n=0,i=Xr(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?n:0);if(a>e)break;let c=this.ranges[l+s],f=a+c;if(e<=f&&l==i*3)return!0;n+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[i+t],f=this.ranges[i+n];e(l,l+c,a,a+f),s+=f-c}}invert(){return new r(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?r.empty:new r(e<0?[0,-e,0]:[0,0,e])}};re.empty=new re([]);var at=class r{constructor(e,t,n=0,i=e?e.length:0){this.mirror=t,this.from=n,this.to=i,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new r(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let i=e.getMirror(t);this.appendMap(e._maps[t],i!=null&&i<t?n+i:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),i!=null&&i>t?n-i-1:void 0)}}invert(){let e=new r;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let i=0;for(let s=this.from;s<this.to;s++){let o=this._maps[s],l=o.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this._maps[a].recover(l.recover);continue}}i|=l.delInfo,e=l.pos}return n?e:new lt(e,i,null)}},kn=Object.create(null),T=class{getMap(){return re.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=kn[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in kn)throw new RangeError("Duplicate use of step JSON ID "+e);return kn[e]=t,t.prototype.jsonID=e,t}},I=class r{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new r(e,null)}static fail(e){return new r(null,e)}static fromReplace(e,t,n,i){try{return r.ok(e.replace(t,n,i))}catch(s){if(s instanceof he)return r.fail(s.message);throw s}}};function Mn(r,e,t){let n=[];for(let i=0;i<r.childCount;i++){let s=r.child(i);s.content.size&&(s=s.copy(Mn(s.content,e,s))),s.isInline&&(s=e(s,t,i)),n.push(s)}return k.fromArray(n)}var ct=class r extends T{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),i=n.node(n.sharedDepth(this.to)),s=new b(Mn(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,s)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,i)=>{if(n.isInline&&n.isAtom){let s=this.mark.addToSet(n.marks);if(!C.sameSet(s,n.marks)){let o=Math.max(this.from,i),l=Math.min(this.to,i+n.nodeSize);Vt(We,o,l,this.mark,t);for(let a of n.marks)a.isInSet(s)||Vt(r,o,l,a,t)}}}),t.length==1?t[0]:new ft(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new r(t,n,this.mark)}merge(e){return e instanceof r&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new r(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new r(t.from,t.to,e.markFromJSON(t.mark))}};T.jsonID("addMark",ct);var We=class r extends T{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new b(Mn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,n)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,i)=>{n.isInline&&n.isAtom&&this.mark.isInSet(n.marks)&&Vt(ct,Math.max(this.from,i),Math.min(this.to,i+n.nodeSize),this.mark,t)}),t.length==1?t[0]:new ft(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new r(t,n,this.mark)}merge(e){return e instanceof r&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new r(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new r(t.from,t.to,e.markFromJSON(t.mark))}};T.jsonID("removeMark",We);function Vt(r,e,t,n,i){let s=i.length?i[i.length-1]:null;s&&s instanceof r&&s.to==e&&s.mark.eq(n)?i[i.length-1]=new r(s.from,t,n):i.push(new r(e,t,n))}var ft=class r extends T{constructor(e){super(),this.steps=e}apply(e){for(let t of this.steps){let n=t.apply(e);if(!n.doc)return n;e=n.doc}return new I(e,null)}invert(e){return new r(this.steps.map(t=>t.invert(e)))}map(e){let t=[];for(let n of this.steps){let i=n.map(e);i&&t.push(i)}return t.length?new r(t):null}toJSON(){return{stepType:"markSet",steps:this.steps.map(e=>e.toJSON())}}static fromJSON(e,t){if(!Array.isArray(t.steps)||!t.steps.every(n=>n.stepType=="addMark"||n.stepType=="removeMark"))throw new RangeError("Invalid JSON for MarkSetStep");return new r(t.steps.map(n=>T.fromJSON(e,n)))}};T.jsonID("markSet",ft);var ht=class r extends T{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new b(k.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let n=this.mark.addToSet(t.marks);if(n.length==t.marks.length){for(let i=0;i<t.marks.length;i++)if(!t.marks[i].isInSet(n))return new r(this.pos,t.marks[i]);return new r(this.pos,this.mark)}}return new Je(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new r(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new r(t.pos,e.markFromJSON(t.mark))}};T.jsonID("addNodeMark",ht);var Je=class r extends T{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new b(k.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new ht(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new r(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new r(t.pos,e.markFromJSON(t.mark))}};T.jsonID("removeNodeMark",Je);var $=class r extends T{constructor(e,t,n,i=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=i}apply(e){return this.structure&&xn(e,this.from,this.to)?I.fail("Structure replace would overwrite content"):I.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new re([this.from,this.to-this.from,this.slice.size])}invert(e){return new r(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&r.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new r(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof r)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?b.empty:new b(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new r(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?b.empty:new b(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new r(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new r(t.from,t.to,b.fromJSON(e,t.slice),!!t.structure)}};$.MAP_BIAS=1;T.jsonID("replace",$);var H=class r extends T{constructor(e,t,n,i,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=i,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(xn(e,this.from,this.gapFrom)||xn(e,this.gapTo,this.to)))return I.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return I.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?I.fromReplace(e,this.from,this.to,n):I.fail("Content does not fit in gap")}getMap(){return new re([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new r(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||i<t.pos||s>n.pos?null:new r(t.pos,n.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new r(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};T.jsonID("replaceAround",H);function xn(r,e,t){let n=r.resolve(e),i=t-e,s=n.depth;for(;i>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,i--;if(i>0){let o=n.node(s).maybeChild(n.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function yo(r,e,t,n){let i=[];r.doc.nodesBetween(e,t,(s,o,l)=>{if(!s.isInline)return;let a=s.marks;if(!n.isInSet(a)&&l.type.allowsMarkType(n.type)){let c=Math.max(o,e),f=Math.min(o+s.nodeSize,t);Vt(ct,c,f,n,i)}}),i.forEach(s=>r.step(s))}function ko(r,e,t,n){let i=[],s=0;r.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline||!o.isAtom)return;s++;let a=null;if(n instanceof nt){let c=o.marks,f;for(;f=n.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let f=0;f<a.length;f++){let h=a[f],d;for(let p=0;p<i.length;p++){let u=i[p];u.step==s-1&&h.eq(i[p].style)&&(d=u)}d?(d.to=c,d.step=s):i.push({style:h,from:Math.max(l,e),to:c,step:s})}}}),i.forEach(o=>r.step(new We(o.from,o.to,o.style)))}function Cn(r,e,t,n=t.contentMatch,i=!0){let s=r.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let c=s.child(a),f=l+c.nodeSize,h=n.matchType(c.type);if(!h)o.push(new $(l,f,b.empty));else{n=h;for(let d=0;d<c.marks.length;d++)t.allowsMarkType(c.marks[d].type)||r.step(new We(l,f,c.marks[d]));if(i&&c.isText&&t.whitespace!="pre"){let d,p=/\r?\n|\r/g,u;for(;d=p.exec(c.text);)u||(u=new b(k.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new $(l+d.index,l+d.index+d[0].length,u))}}l=f}if(!n.validEnd){let a=n.fillBefore(k.empty,!0);r.replace(l,l,new b(a,0,0))}for(let a=o.length-1;a>=0;a--)r.step(o[a])}function bo(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function qt(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth,i=0,s=0;;--n){let o=r.$from.node(n),l=r.$from.index(n)+i,a=r.$to.indexAfter(n)-s;if(n<r.depth&&o.canReplace(l,a,t))return n;if(n==0||o.type.spec.isolating||!bo(o,l,a))break;l&&(i=1),a<o.childCount&&(s=1)}return null}function xo(r,e,t){let{$from:n,$to:i,depth:s}=e,o=n.before(s+1),l=i.after(s+1),a=o,c=l,f=k.empty,h=0;for(let u=s,m=!1;u>t;u--)m||n.index(u)>0?(m=!0,f=k.from(n.node(u).copy(f)),h++):a--;let d=k.empty,p=0;for(let u=s,m=!1;u>t;u--)m||i.after(u+1)<i.end(u)?(m=!0,d=k.from(i.node(u).copy(d)),p++):c++;r.step(new H(a,c,o,l,new b(f.append(d),h,p),f.size-h,!0))}function So(r,e,t){let n=k.empty;for(let o=t.length-1;o>=0;o--){if(n.size){let l=t[o].type.contentMatch.matchFragment(n);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}n=k.from(t[o].type.create(t[o].attrs,n))}let i=e.start,s=e.end;r.step(new H(i,s,i,s,new b(n,0,0),t.length,!0))}function Mo(r,e,t,n,i){if(!n.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=r.steps.length;r.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(n,a)&&Co(r.doc,r.mapping.slice(s).map(l),n)){let c=null;if(n.schema.linebreakReplacement){let p=n.whitespace=="pre",u=!!n.contentMatch.matchType(n.schema.linebreakReplacement);p&&!u?c=!1:!p&&u&&(c=!0)}c===!1&&oi(r,o,l,s),Cn(r,r.mapping.slice(s).map(l,1),n,void 0,c===null);let f=r.mapping.slice(s),h=f.map(l,1),d=f.map(l+o.nodeSize,1);return r.step(new H(h,d,h+1,d-1,new b(k.from(n.create(a,null,o.marks)),0,0),1,!0)),c===!0&&si(r,o,l,s),!1}})}function si(r,e,t,n){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=r.mapping.slice(n).map(t+1+s+o.index);r.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function oi(r,e,t,n){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=r.mapping.slice(n).map(t+1+s);r.replaceWith(o,o+1,e.type.schema.text(`
5
+ `))}})}function Co(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function wo(r,e,t,n,i){let s=r.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(n,null,i||s.marks);if(s.isLeaf)return r.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);r.step(new H(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(k.from(o),0,0),1,!0))}function ut(r,e,t=1,n){let i=r.resolve(e),s=i.depth-t,o=n&&n[n.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,f=t-2;c>s;c--,f--){let h=i.node(c),d=i.index(c);if(h.type.spec.isolating)return!1;let p=h.content.cutByIndex(d,h.childCount),u=n&&n[f+1];u&&(p=p.replaceChild(0,u.type.create(u.attrs)));let m=n&&n[f]||h;if(!h.canReplace(d+1,h.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function Oo(r,e,t=1,n){let i=r.doc.resolve(e),s=k.empty,o=k.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=k.from(i.node(l).copy(s));let f=n&&n[c];o=k.from(f?f.type.create(f.attrs,o):i.node(l).copy(o))}r.step(new $(e,e,new b(s.append(o),t,t),!0))}function wn(r,e){let t=r.resolve(e),n=t.index();return Do(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function No(r,e){e.content.size||r.type.compatibleContent(e.type);let t=r.contentMatchAt(r.childCount),{linebreakReplacement:n}=r.type.schema;for(let i=0;i<e.childCount;i++){let s=e.child(i),o=s.type==n?r.type.schema.nodes.text:s.type;if(t=t.matchType(o),!t||!r.type.allowsMarks(s.marks))return!1}return t.validEnd}function Do(r,e){return!!(r&&e&&!r.isLeaf&&No(r,e))}function To(r,e,t){let n=null,{linebreakReplacement:i}=r.doc.type.schema,s=r.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let f=o.whitespace=="pre",h=!!o.contentMatch.matchType(i);f&&!h?n=!1:!f&&h&&(n=!0)}let l=r.steps.length;if(n===!1){let f=r.doc.resolve(e+t);oi(r,f.node(),f.before(),l)}o.inlineContent&&Cn(r,e+t-1,o,s.node().contentMatchAt(s.index()),n==null);let a=r.mapping.slice(l),c=a.map(e-t);if(r.step(new $(c,a.map(e+t,-1),b.empty,!0)),n===!0){let f=r.doc.resolve(c);si(r,f.node(),f.before(),r.steps.length)}return r}function Eo(r,e,t){let n=r.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),t))return e;if(n.parentOffset==0)for(let i=n.depth-1;i>=0;i--){let s=n.index(i);if(n.node(i).canReplaceWith(s,s,t))return n.before(i+1);if(s>0)return null}if(n.parentOffset==n.parent.content.size)for(let i=n.depth-1;i>=0;i--){let s=n.indexAfter(i);if(n.node(i).canReplaceWith(s,s,t))return n.after(i+1);if(s<n.node(i).childCount)return null}return null}function li(r,e,t){let n=r.resolve(e);if(!t.content.size)return e;let i=t.content;for(let s=0;s<t.openStart;s++)i=i.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let o=n.depth;o>=0;o--){let l=o==n.depth?0:n.pos<=(n.start(o+1)+n.end(o+1))/2?-1:1,a=n.index(o)+(l>0?1:0),c=n.node(o),f=!1;if(s==1)f=c.canReplace(a,a,i);else{let h=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=h&&c.canReplaceWith(a,a,h[0])}if(f)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function $t(r,e,t=e,n=b.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return ai(i,s,n)?new $(e,t,n):new Sn(i,s,n).fit()}function ai(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}var Sn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=k.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=k.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let s=this.placed,o=n.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new b(s,o,l);return e>-1?new H(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new $(n.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,i=this.unplaced.openEnd;n<e;n++){let s=t.firstChild;if(t.childCount>1&&(i=0),s.type.spec.isolating&&i<=n){e=n;break}t=s.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let i,s=null;n?(s=Zr(this.unplaced.content,n-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,h=null;if(t==1&&(o?c.matchType(o.type)||(h=c.fillBefore(k.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:h};if(t==2&&o&&(f=c.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:f};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return Qr(e,-1)<=t?!1:(this.unplaced.size>1&&Qr(e,1)>n&&n++,this.unplaced=new b(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=Zr(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(st(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new b(st(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=n?n.content:o.content,a=o.openStart-e,c=0,f=[],{match:h,type:d}=this.frontier[t];if(i){for(let m=0;m<i.childCount;m++)f.push(i.child(m));h=h.matchFragment(i)}let p=l.size+e-(o.content.size-o.openEnd);for(;c<l.childCount;){let m=l.child(c),g=h.matchType(m.type);if(!g)break;c++,(c>1||a==0||m.content.size)&&(h=g,f.push(ci(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let u=c==l.childCount;u||(p=-1),this.placed=ot(this.placed,t,k.from(f)),this.frontier[t].match=h,u&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<p;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=u?e==0?b.empty:new b(st(o.content,e-1,1),e-1,p<0?o.openEnd:e-1):new b(st(o.content,e,c),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!bn(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,i=this.$to.after(n);for(;n>1&&i==this.$to.end(--n);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:i}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=bn(e,t,i,n,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],f=bn(e,l,c,a,!0);if(!f||f.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=ot(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let i=e.node(n),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(n));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ot(this.placed,this.depth,k.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(k.empty,!0);t.childCount&&(this.placed=ot(this.placed,this.frontier.length,t))}};function st(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(st(r.firstChild.content,e-1,t)))}function ot(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(ot(r.lastChild.content,e-1,t)))}function Zr(r,e){for(let t=0;t<e;t++)r=r.firstChild.content;return r}function ci(r,e,t){if(e<=0)return r;let n=r.content;return e>1&&(n=n.replaceChild(0,ci(n.firstChild,e-1,n.childCount==1?t-1:0))),e>0&&(n=r.type.contentMatch.fillBefore(n).append(n),t<=0&&(n=n.append(r.type.contentMatch.matchFragment(n).fillBefore(k.empty,!0)))),r.copy(n)}function bn(r,e,t,n,i){let s=r.node(e),o=i?r.indexAfter(e):r.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!Ao(t,s.content,o)?l:null}function Ao(r,e,t){for(let n=t;n<e.childCount;n++)if(!r.allowsMarks(e.child(n).marks))return!0;return!1}function Io(r){return r.spec.defining||r.spec.definingForContent}function Qr(r,e){for(let t=0;;t++){let n=e<0?r.firstChild:r.lastChild;if(!n||n.isAtom)return t;r=n.content}}function Ro(r,e,t,n){if(!n.size)return r.deleteRange(e,t);let i=r.doc.resolve(e),s=r.doc.resolve(t);if(ai(i,s,n))return r.step(new $(e,t,n));let o=hi(i,s);o[o.length-1]==0&&o.pop();let l=-(i.depth+1);o.unshift(l);for(let d=i.depth,p=i.pos-1;d>0;d--,p--){let u=i.node(d).type.spec;if(u.defining||u.definingAsContext||u.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==p&&o.splice(1,0,-d)}let a=o.indexOf(l),c=[],f=n.openStart;for(let d=n.content,p=0;;p++){let u=d.firstChild;if(c.push(u),p==n.openStart)break;d=u.content}for(let d=f-1;d>=0;d--){let p=c[d],u=Io(p.type);if(u&&!p.sameMarkup(i.node(Math.abs(l)-1)))f=d;else if(u||!p.type.isTextblock)break}for(let d=n.openStart;d>=0;d--){let p=(d+f+1)%(n.openStart+1),u=c[p];if(u)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],y=!0;g<0&&(y=!1,g=-g);let M=i.node(g-1),O=i.index(g-1);if(M.canReplaceWith(O,O,u.type,u.marks))return r.replace(i.before(g),y?s.after(g):t,new b(fi(n.content,0,n.openStart,p),p,n.openEnd))}}let h=r.steps.length;for(let d=o.length-1;d>=0&&(r.replace(e,t,n),!(r.steps.length>h));d--){let p=o[d];p<0||(e=i.before(p),t=s.after(p))}}function fi(r,e,t,n,i){if(e<t){let s=r.firstChild;r=r.replaceChild(0,s.copy(fi(s.content,e+1,t,n,s)))}if(e>n){let s=i.contentMatchAt(0),o=s.fillBefore(r).append(r);r=o.append(s.matchFragment(o).fillBefore(k.empty,!0))}return r}function Bo(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=Eo(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new b(k.from(n),0,0))}function Po(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t);if(n.parent.isTextblock&&i.parent.isTextblock&&n.start()!=i.start()&&n.parentOffset==0&&i.parentOffset==0){let o=n.sharedDepth(t),l=!1;for(let a=n.depth;a>o;a--)n.node(a).type.spec.isolating&&(l=!0);for(let a=i.depth;a>o;a--)i.node(a).type.spec.isolating&&(l=!0);if(!l){for(let a=n.depth;a>0&&e==n.start(a);a--)e=n.before(a);for(let a=i.depth;a>0&&t==i.start(a);a--)t=i.before(a);n=r.doc.resolve(e),i=r.doc.resolve(t)}}let s=hi(n,i);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||n.node(l).type.contentMatch.validEnd)return r.delete(n.start(l),i.end(l));if(l>0&&(a||n.node(l-1).canReplace(n.index(l-1),i.indexAfter(l-1))))return r.delete(n.before(l),i.after(l))}for(let o=1;o<=n.depth&&o<=i.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&i.end(o)-t!=i.depth-o&&n.start(o-1)==i.start(o-1)&&n.node(o-1).canReplace(n.index(o-1),i.index(o-1)))return r.delete(n.before(o),t);r.delete(e,t)}function hi(r,e){let t=[],n=Math.min(r.depth,e.depth);for(let i=n;i>=0;i--){let s=r.start(i);if(s<r.pos-(r.depth-i)||e.end(i)>e.pos+(e.depth-i)||r.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==r.depth&&i==e.depth&&r.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Lt=class r extends T{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let i=t.type.create(n,null,t.marks);return I.fromReplace(e,this.pos,this.pos+1,new b(k.from(i),0,t.isLeaf?0:1))}getMap(){return re.empty}invert(e){return new r(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new r(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new r(t.pos,t.attr,t.value)}};T.jsonID("attr",Lt);var Wt=class r extends T{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return I.ok(n)}getMap(){return re.empty}invert(e){return new r(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new r(t.attr,t.value)}};T.jsonID("docAttr",Wt);var qe=class extends Error{};qe=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t};qe.prototype=Object.create(Error.prototype);qe.prototype.constructor=qe;qe.prototype.name="TransformError";var Jt=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new at}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new qe(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let i=this.mapping.maps[n];n&&(e=i.map(e,1),t=i.map(t,-1)),i.forEach((s,o,l,a)=>{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=b.empty){let i=$t(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new b(k.from(n),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return Ro(this,e,t,n),this}replaceRangeWith(e,t,n){return Bo(this,e,t,n),this}deleteRange(e,t){return Po(this,e,t),this}lift(e,t){return xo(this,e,t),this}join(e,t=1){return To(this,e,t),this}wrap(e,t){return So(this,e,t),this}setBlockType(e,t=e,n,i=null){return Mo(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return wo(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Lt(e,t,n)),this}setDocAttribute(e,t){return this.step(new Wt(e,t)),this}addNodeMark(e,t){return this.step(new ht(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof C)t.isInSet(n.marks)&&this.step(new Je(e,t));else{let i=n.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new Je(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,n){return Oo(this,e,t,n),this}addMark(e,t,n){return yo(this,e,t,n),this}removeMark(e,t,n){return ko(this,e,t,n),this}clearIncompatible(e,t,n){return Cn(this,e,t,n),this}};var On=Object.create(null),N=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Ke(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=b.empty){let n=t.content.lastChild,i=null;for(let l=0;l<t.openEnd;l++)i=n,n=n.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],f=e.mapping.slice(s);e.replaceRange(f.map(a.pos),f.map(c.pos),l?b.empty:t),l==0&&pi(e,s,(n?n.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:o,$to:l}=i[s],a=e.mapping.slice(n),c=a.map(o.pos),f=a.map(l.pos);s?e.deleteRange(c,f):(e.replaceRangeWith(c,f,t),pi(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let i=e.parent.inlineContent?new D(e):$e(e.node(0),e.parent,e.pos,e.index(),t,n);if(i)return i;for(let s=e.depth-1;s>=0;s--){let o=t<0?$e(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):$e(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new _(e.node(0))}static atStart(e){return $e(e,e,0,0,1)||new _(e)}static atEnd(e){return $e(e,e,e.content.size,e.childCount,-1)||new _(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=On[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in On)throw new RangeError("Duplicate use of selection JSON ID "+e);return On[e]=t,t.prototype.jsonID=e,t}getBookmark(){return D.between(this.$anchor,this.$head).getBookmark()}};N.prototype.visible=!0;var Ke=class{constructor(e,t){this.$from=e,this.$to=t}},ui=!1;function di(r){!ui&&!r.parent.inlineContent&&(ui=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}var D=class r extends N{constructor(e,t=e){di(e),di(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return N.near(n);let i=e.resolve(t.map(this.anchor));return new r(i.parent.inlineContent?i:n,n)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof r&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Ht(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new r(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let i=e.resolve(t);return new this(i,n==t?i:e.resolve(n))}static between(e,t,n){let i=e.pos-t.pos;if((!n||i)&&(n=i>=0?1:-1),!t.parent.inlineContent){let s=N.findFrom(t,n,!0)||N.findFrom(t,-n,!0);if(s)t=s.$head;else return N.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(N.findFrom(e,-n,!0)||N.findFrom(e,n,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new r(e,t)}};N.jsonID("text",D);var Ht=class r{constructor(e,t){this.anchor=e,this.head=t}map(e){return new r(e.map(this.anchor),e.map(this.head))}resolve(e){return D.between(e.resolve(this.anchor),e.resolve(this.head))}},S=class r extends N{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:i}=t.mapResult(this.anchor),s=e.resolve(i);return n?N.near(s):new r(s)}content(){return new b(k.from(this.node),0,0)}eq(e){return e instanceof r&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Dn(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new r(e.resolve(t.anchor))}static create(e,t){return new r(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};S.prototype.visible=!1;N.jsonID("node",S);var Dn=class r{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Ht(n,n):new r(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&S.isSelectable(n)?new S(t):N.near(t)}},_=class r extends N{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=b.empty){if(t==b.empty){e.delete(0,e.doc.content.size);let n=N.atStart(e.doc);n.eq(e.selection)||e.setSelection(n)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new r(e)}map(e){return new r(e)}eq(e){return e instanceof r}getBookmark(){return zo}};N.jsonID("all",_);var zo={map(){return this},resolve(r){return new _(r)}};function $e(r,e,t,n,i,s=!1){if(e.inlineContent)return D.create(r,t);for(let o=n-(i>0?0:1);i>0?o<e.childCount:o>=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&S.isSelectable(l))return S.create(r,t-(i<0?l.nodeSize:0))}else{let a=$e(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function pi(r,e,t){let n=r.steps.length-1;if(n<e)return;let i=r.steps[n];if(!(i instanceof $||i instanceof H))return;let s=r.mapping.maps[n],o;s.forEach((l,a,c,f)=>{o==null&&(o=f)}),r.setSelection(N.near(r.doc.resolve(o),t))}var mi=1,Kt=2,gi=4,Tn=class extends Jt{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|mi)&~Kt,this.storedMarks=null,this}get selectionSet(){return(this.updated&mi)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Kt,this}ensureMarks(e){return C.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Kt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Kt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||C.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),n=n??t,!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,i.text(e,s)),this.selection.empty||this.setSelection(N.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=gi,this}get scrolledIntoView(){return(this.updated&gi)>0}};function yi(r,e){return!e||!r?r:r.bind(e)}var Me=class{constructor(e,t,n){this.name=e,this.init=yi(t.init,n),this.apply=yi(t.apply,n)}},vo=[new Me("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new Me("selection",{init(r,e){return r.selection||N.atStart(e.doc)},apply(r){return r.selection}}),new Me("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new Me("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})],dt=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=vo.slice(),t&&t.forEach(n=>{if(this.pluginsByKey[n.key])throw new RangeError("Adding different instances of a keyed plugin ("+n.key+")");this.plugins.push(n),this.pluginsByKey[n.key]=n,n.spec.state&&this.fields.push(new Me(n.key,n.spec.state,n))})}},_t=class r{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let i=this.config.plugins[n];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),i=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=i?i[o].n:0,c=i?i[o].state:this,f=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,n);if(f&&n.filterTransaction(f,o)){if(f.setMeta("appendedTransaction",e),!i){i=[];for(let h=0;h<this.config.plugins.length;h++)i.push(h<o?{state:n,n:t.length}:{state:this,n:0})}t.push(f),n=n.applyInner(f),s=!0}i&&(i[o]={state:n,n:t.length})}}if(!s)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new r(this.config),n=this.config.fields;for(let i=0;i<n.length;i++){let s=n[i];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new Tn(this)}static create(e){let t=new dt(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new r(t);for(let i=0;i<t.fields.length;i++)n[t.fields[i].name]=t.fields[i].init(e,n);return n}reconfigure(e){let t=new dt(this.schema,e.plugins),n=t.fields,i=new r(t);for(let s=0;s<n.length;s++){let o=n[s].name;i[o]=this.hasOwnProperty(o)?this[o]:n[s].init(e,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(n=>n.toJSON())),e&&typeof e=="object")for(let n in e){if(n=="doc"||n=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[n],s=i.spec.state;s&&s.toJSON&&(t[n]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new dt(e.schema,e.plugins),s=new r(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Q.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=N.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let l in n){let a=n[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function ki(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=ki(i,e,{})),t[n]=i}return t}var He=class{constructor(e){this.spec=e,this.props={},e.props&&ki(e.props,this,this.props),this.key=e.key?e.key.key:bi("plugin")}getState(e){return e[this.key]}},Nn=Object.create(null);function bi(r){return r in Nn?r+"$"+ ++Nn[r]:(Nn[r]=0,r+"$")}var pt=class{constructor(e="key"){this.key=bi(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var R=function(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e},Ge=function(r){let e=r.assignedSlot||r.parentNode;return e&&e.nodeType==11?e.host:e},Bn=null,se=function(r,e,t){let n=Bn||(Bn=document.createRange());return n.setEnd(r,t??r.nodeValue.length),n.setStart(r,e||0),n},Fo=function(){Bn=null},Ae=function(r,e,t,n){return t&&(xi(r,e,t,n,-1)||xi(r,e,t,n,1))},Vo=/^(img|br|input|textarea|hr)$/i;function xi(r,e,t,n,i){for(var s;;){if(r==t&&e==n)return!0;if(e==(i<0?0:F(r))){let o=r.parentNode;if(!o||!x(o)||Ct(r)||Vo.test(r.nodeName)||r.contentEditable=="false")return!1;e=R(r)+(i<0?0:1),r=o}else if(x(r)){let o=r.childNodes[e+(i<0?-1:0)];if(x(o)&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=i;else return!1;else r=o,e=i<0?F(r):0}else return!1}}function F(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function x(r){return r.nodeType==1}function E(r){return r.nodeType==3}function Ie(r,e){return e?r.contains(x(e)?e:e.parentNode):!1}function Lo(r,e){for(;;){if(E(r)&&e)return r;if(x(r)&&e>0){if(r.contentEditable=="false")return null;r=r.childNodes[e-1],e=F(r)}else if(r.parentNode&&!Ct(r))e=R(r),r=r.parentNode;else return null}}function Wo(r,e){for(;;){if(E(r)&&e<r.nodeValue.length)return r;if(x(r)&&e<r.childNodes.length){if(r.contentEditable=="false")return null;r=r.childNodes[e],e=0}else if(r.parentNode&&!Ct(r))e=R(r)+1,r=r.parentNode;else return null}}function Jo(r,e,t){for(let n=e==0,i=e==F(r);n||i;){if(r==t)return!0;let s=R(r);if(r=r.parentNode,!r)return!1;n=n&&s==0,i=i&&s==F(r)}}function Ct(r){let e;for(let t=r;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==r||e.contentDOM==r)}var rn=function(r){return r.focusNode&&Ae(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)};function Ce(r,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=r,t.key=t.code=e,t}function qo(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function $o(r,e,t){if(r.caretPositionFromPoint)try{let n=r.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:Math.min(F(n.offsetNode),n.offset)}}catch{}if(r.caretRangeFromPoint){let n=r.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:Math.min(F(n.startContainer),n.startOffset)}}}var ee=typeof navigator<"u"?navigator:null,Si=typeof document<"u"?document:null,ye=ee&&ee.userAgent||"",Pn=/Edge\/(\d+)/.exec(ye),Yi=/MSIE \d/.exec(ye),zn=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ye),K=!!(Yi||zn||Pn),pe=Yi?document.documentMode:zn?+zn[1]:Pn?+Pn[1]:0,j=!K&&/gecko\/(\d+)/i.test(ye);j&&+(/Firefox\/(\d+)/.exec(ye)||[0,0])[1];var vn=!K&&/Chrome\/(\d+)/.exec(ye),B=!!vn,Xi=vn?+vn[1]:0,V=!K&&!!ee&&/Apple Computer/.test(ee.vendor),Ye=V&&(/Mobile\/\w+/.test(ye)||!!ee&&ee.maxTouchPoints>2),U=Ye||(ee?/Mac/.test(ee.platform):!1),Zi=ee?/Win/.test(ee.platform):!1,oe=/Android \d/.test(ye),sn=!!Si&&"webkitFontSmoothing"in Si.documentElement.style,Ko=sn?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ho(r){let e=r.defaultView&&r.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:r.documentElement.clientWidth,top:0,bottom:r.documentElement.clientHeight}}function ie(r,e){return typeof r=="number"?r:r[e]}function _o(r){let e=r.getBoundingClientRect(),t=e.width/r.offsetWidth||1,n=e.height/r.offsetHeight||1;return{left:e.left,right:e.left+r.clientWidth*t,top:e.top,bottom:e.top+r.clientHeight*n}}function Mi(r,e,t){if(!Fn(e)&&e.left==0)return;let n=r.someProp("scrollThreshold")||0,i=r.someProp("scrollMargin")||5,s=r.dom.ownerDocument;for(let o=t||r.dom;o;){if(!x(o)){o=Ge(o);continue}let l=o==s.body,a=l?Ho(s):_o(o),c=0,f=0;if(e.top<a.top+ie(n,"top")?f=-(a.top-e.top+ie(i,"top")):e.bottom>a.bottom-ie(n,"bottom")&&(f=e.bottom-e.top>a.bottom-a.top?e.top+ie(i,"top")-a.top:e.bottom-a.bottom+ie(i,"bottom")),e.left<a.left+ie(n,"left")?c=-(a.left-e.left+ie(i,"left")):e.right>a.right-ie(n,"right")&&(c=e.right-a.right+ie(i,"right")),c||f)if(l)s.defaultView.scrollBy(c,f);else{let d=o.scrollLeft,p=o.scrollTop;f&&(o.scrollTop+=f),c&&(o.scrollLeft+=c);let u=o.scrollLeft-d,m=o.scrollTop-p;e={left:e.left-u,top:e.top-m,right:e.right-u,bottom:e.bottom-m}}let h=l?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(h))break;o=h=="absolute"?o.offsetParent:Ge(o)}}function jo(r){let e=r.dom.getBoundingClientRect(),t=Math.max(0,e.top),n,i;for(let s=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let l=r.root.elementFromPoint(s,o);if(!l||l==r.dom||!r.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){n=l,i=a.top;break}}return{refDOM:n,refTop:i,stack:Qi(r.dom)}}function Qi(r){let e=[],t=r.ownerDocument;for(let n=r;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),r!=t);n=Ge(n));return e}function Uo({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;es(t,n==0?0:n-e)}function es(r,e){for(let t=0;t<r.length;t++){let{dom:n,top:i,left:s}=r[t];n.scrollTop!=i+e&&(n.scrollTop=i+e),n.scrollLeft!=s&&(n.scrollLeft=s)}}var _e=null;function Go(r){if(r.setActive)return r.setActive();if(_e)return r.focus(_e);let e=Qi(r);r.focus(_e==null?{get preventScroll(){return _e={preventScroll:!0},!0}}:void 0),_e||(_e=!1,es(e,0))}function ts(r,e){let t,n=2e8,i,s=0,o=e.top,l=e.top,a,c;for(let f=r.firstChild,h=0;f;f=f.nextSibling,h++){let d;if(x(f))d=f.getClientRects();else if(E(f))d=se(f).getClientRects();else continue;for(let p=0;p<d.length;p++){let u=d[p];if(u.top<=o&&u.bottom>=l){o=Math.max(u.bottom,o),l=Math.min(u.top,l);let m=u.left>e.left?u.left-e.left:u.right<e.left?e.left-u.right:0;if(m<n){t=f,n=m,i=m&&E(t)?{left:u.right<e.left?u.right:u.left,top:e.top}:e,x(f)&&m&&(s=h+(e.left>=(u.left+u.right)/2?1:0));continue}}else u.top>e.top&&!a&&u.left<=e.left&&u.right>=e.left&&(a=f,c={left:Math.max(u.left,Math.min(u.right,e.left)),top:u.top});!t&&(e.left>=u.right&&e.top>=u.top||e.left>=u.left&&e.top>=u.bottom)&&(s=h+1)}}return!t&&a&&(t=a,i=c,n=0),t&&E(t)?Yo(t,i):!t||n?{node:r,offset:s}:ts(t,i)}function Yo(r,e){let t=r.nodeValue.length,n=document.createRange(),i;for(let s=0;s<t;s++){n.setEnd(r,s+1),n.setStart(r,s);let o=ue(n,1);if(o.top!=o.bottom&&Qn(e,o)){i={node:r,offset:s+(e.left>=(o.left+o.right)/2?1:0)};break}}return n.detach(),i||{node:r,offset:0}}function Qn(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function Xo(r,e){let t=r.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<r.getBoundingClientRect().left?t:r}function Zo(r,e,t){let{node:n,offset:i}=ts(e,t),s=-1;if(x(n)&&!n.firstChild){let o=n.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return r.docView.posFromDOM(n,i,s)}function Qo(r,e,t,n){let i=-1;for(let s=e,o=!1;s!=r.dom;){let l=r.docView.nearestDesc(s,!0),a;if(!l)return null;if(x(l.dom)&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!o&&a.left>n.left||a.top>n.top?i=l.posBefore:(!o&&a.right<n.left||a.bottom<n.top)&&(i=l.posAfter),o=!0),!l.contentDOM&&i<0&&!l.node.isText))return(l.node.isBlock?n.top<(a.top+a.bottom)/2:n.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return i>-1?i:r.docView.posFromDOM(e,t,-1)}function ns(r,e,t){let n=r.childNodes.length;if(n&&t.top<t.bottom)for(let i=Math.max(0,Math.min(n-1,Math.floor(n*(e.top-t.top)/(t.bottom-t.top))-2)),s=i;;){let o=r.childNodes[s];if(x(o)){let l=o.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(Qn(e,c))return ns(o,e,c)}}if((s=(s+1)%n)==i)break}return r}function el(r,e){let t=r.dom.ownerDocument,n,i=0,s=$o(t,e.left,e.top);s&&({node:n,offset:i}=s);let o=(r.root.elementFromPoint?r.root:t).elementFromPoint(e.left,e.top),l;if(!o||!r.dom.contains(o)){let c=r.dom.getBoundingClientRect();if(!Qn(e,c)||(o=ns(r.dom,e,c),!o))return null}if(V)for(let c=o;n&&c;c=Ge(c))c.draggable&&(n=void 0);if(o=Xo(o,e),n){if(j&&x(n)&&(i=Math.min(i,n.childNodes.length),i<n.childNodes.length)){let f=n.childNodes[i],h;f.nodeName=="IMG"&&(h=f.getBoundingClientRect()).right<=e.left&&h.bottom>e.top&&i++}let c;sn&&i&&x(n)&&x(c=n.childNodes[i-1])&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,n==r.dom&&i==n.childNodes.length-1&&x(n.lastChild)&&e.top>n.lastChild.getBoundingClientRect().bottom?l=r.state.doc.content.size:(i==0||!x(n)||n.childNodes[i-1].nodeName!="BR")&&(l=Qo(r,n,i,e))}l==null&&(l=Zo(r,o,e));let a=r.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Fn(r){return r.top<r.bottom||r.left<r.right}function ue(r,e){let t=r.getClientRects();if(t.length){let n=t[e<0?0:t.length-1];if(Fn(n))return n}return Array.prototype.find.call(t,Fn)||r.getBoundingClientRect()}var tl=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function rs(r,e,t){let{node:n,offset:i,atom:s}=r.docView.domFromPos(e,t<0?-1:1),o=sn||j;if(E(n))if(o&&(tl.test(n.nodeValue)||(t<0?!i:i==n.nodeValue.length))){let a=ue(se(n,i,i),t);if(j&&i&&/\s/.test(n.nodeValue[i-1])&&i<n.nodeValue.length){let c=ue(se(n,i-1,i-1),-1);if(c.top==a.top){let f=ue(se(n,i,i+1),-1);if(f.top!=a.top)return mt(f,f.left<c.left)}}return a}else{let a=i,c=i,f=t<0?1:-1;return t<0&&!i?(c++,f=-1):t>=0&&i==n.nodeValue.length?(a--,f=1):t<0?a--:c++,mt(ue(se(n,a,c),f),f<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==F(n))){let a=n.childNodes[i-1];if(x(a))return En(a.getBoundingClientRect(),!1)}if(s==null&&i<F(n)){let a=n.childNodes[i];if(x(a))return En(a.getBoundingClientRect(),!0)}return En(n.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==F(n))){let a=n.childNodes[i-1],c=E(a)?se(a,F(a)-(o?0:1)):x(a)&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return mt(ue(c,1),!1)}if(s==null&&i<F(n)){let a=n.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?E(a)?se(a,0,o?0:1):x(a)?a:null:null;if(c)return mt(ue(c,-1),!0)}return mt(ue(E(n)?se(n):n,-t),t>=0)}function mt(r,e){if(r.width==0)return r;let t=e?r.left:r.right;return{top:r.top,bottom:r.bottom,left:t,right:t}}function En(r,e){if(r.height==0)return r;let t=e?r.top:r.bottom;return{top:t,bottom:t,left:r.left,right:r.right}}function is(r,e,t){let n=r.state,i=r.root.activeElement;n!=e&&r.updateState(e),i!=r.dom&&r.focus();try{return t()}finally{n!=e&&r.updateState(n),i!=r.dom&&i&&i.focus()}}function nl(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return is(r,e,()=>{let{node:s}=r.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=r.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=rs(r,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(x(l))a=l.getClientRects();else if(E(l))a=se(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let f=a[c];if(f.bottom>f.top+1&&(t=="up"?o.top-f.top>(f.bottom-o.top)*2:f.bottom-o.bottom>(o.bottom-f.top)*2))return!1}}return!0})}var rl=/[\u0590-\u08ac]/;function il(r,e,t){let{$head:n}=e.selection;if(!n.parent.isTextblock)return!1;let i=n.parentOffset,s=!i,o=i==n.parent.content.size,l=r.domSelection();return l?!rl.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:is(r,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:h}=r.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:u,focusOffset:m}=r.domSelectionRange(),g=u&&!Ie(p,u)||a==u&&c==m;try{l.collapse(f,h),a&&(a!=f||c!=h)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):n.pos==n.start()||n.pos==n.end()}var Ci=null,wi=null,Oi=!1;function sl(r,e,t){return Ci==e&&wi==t?Oi:(Ci=e,wi=t,Oi=t=="up"||t=="down"?nl(r,e,t):il(r,e,t))}var G=0,Ni=1,we=2,Z=3,Re=class{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=G,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(e){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let i=this.children[t];if(i==e)return n;n+=i.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){if(this.contentDOM&&Ie(this.contentDOM,e))if(n<0){let s,o;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(o)+o.size:this.posAtStart}else{let s,o;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(o):this.posAtEnd}let i;if(e==this.dom&&this.contentDOM)i=t>R(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=!!(e.compareDocumentPosition(this.contentDOM)&4);else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(n&&(o=s.nodeDOM)&&!(x(o)?Ie(o,e):o==e))n=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let i=this.children[t],s=n+i.size;if(n==e&&s!=n){for(;!i.border&&i.children.length;)for(let o=0;o<i.children.length;o++){let l=i.children[o];if(l.size){i=l;break}}return i}if(e<s)return i.descAt(e-n-i.border);n=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,i=0;for(let s=0;n<this.children.length;n++){let o=this.children[n],l=s+o.size;if(l>e){i=e-s;break}s=l}if(i)return this.children[n].domFromPos(i-this.children[n].border,t);for(;n>0;n--){let s=this.children[n-1];if(s.size||!(s instanceof Gt||s instanceof jt&&s.side>=0))break}if(t<=0){let s,o=!0;for(;s=n?this.children[n-1]:null,!(!s||s.dom.parentNode==this.contentDOM);n--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?R(s.dom)+1:0}}else{let s,o=!0;for(;s=n<this.children.length?this.children[n]:null,!(!s||s.dom.parentNode==this.contentDOM);n++,o=!1);return s&&o&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?R(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,s=-1;for(let o=n,l=0;;l++){let a=this.children[l],c=o+a.size;if(i==-1&&e<=c){let f=o+a.border;if(e>=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=o;for(let h=l;h>0;h--){let d=this.children[h-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=R(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;f<this.children.length;f++){let h=this.children[f];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(-1)){s=R(h.dom);break}t+=h.size}s==-1&&(s=this.contentDOM.childNodes.length);break}o=c}return{node:this.contentDOM,from:e,to:t,fromOffset:i,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(!x(t)||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,i=!1){let s=Math.min(e,t),o=Math.max(e,t);for(let p=0,u=0;p<this.children.length;p++){let m=this.children[p],g=u+m.size;if(s>u&&o<g)return m.setSelection(e-u-m.border,t-u-m.border,n,i);u=g}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),c=n.root.getSelection(),f=n.domSelectionRange(),h=!1;if((j||V)&&e==t){let{node:p,offset:u}=l;if(E(p)){if(h=!!(u&&p.nodeValue[u-1]==`
6
+ `),h&&u==p.nodeValue.length)for(let m=p,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:R(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=p.childNodes[u-1];h=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(j&&f.focusNode&&f.focusNode!=a.node&&x(f.focusNode)){let p=f.focusNode.childNodes[f.focusOffset];p&&p.contentEditable=="false"&&(i=!0)}if(!(i||h&&V)&&Ae(l.node,l.offset,f.anchorNode,f.anchorOffset)&&Ae(a.node,a.offset,f.focusNode,f.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(h&&j)){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),d=!0}catch{}}if(!d){if(e>t){let u=l;l=a,a=u}let p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,i=0;i<this.children.length;i++){let s=this.children[i],o=n+s.size;if(n==o?e<=o&&t>=n:e<o&&t>n){let l=n+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==n||t==o?we:Ni,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Z:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?we:Z}n=o}this.dirty=we}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?we:Ni;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},jt=class extends Re{constructor(e,t,n,i){let s,o=t.type.toDOM;if(typeof o=="function"&&(o=o(n,()=>{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){let l=x(o)?o:document.createElement("span");l!=o&&l.appendChild(o),l.hasAttribute("contenteditable")||(l.contentEditable="false"),l.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==G&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Vn=class extends Re{constructor(e,t,n,i){super(e,[],t,null),this.textDOM=n,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Ne=class r extends Re{constructor(e,t,n,i,s){super(e,[],n,i),this.mark=t,this.spec=s}static create(e,t,n,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,n);return(!o||!o.dom)&&(o=Se.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new r(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Z||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Z&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=G){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty<this.dirty&&(n.dirty=this.dirty),this.dirty=G}}slice(e,t,n){let i=r.create(this.parent,this.mark,!0,n),s=this.children,o=this.size;t<o&&(s=qn(s,t,o,n)),e>0&&(s=qn(s,0,e,n));for(let l=0;l<s.length;l++)s[l].parent=i;return i.children=s,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},me=class r extends Re{constructor(e,t,n,i,s,o,l){super(e,[],s,o),this.node=t,this.outerDeco=n,this.innerDeco=i,this.nodeDOM=l}static create(e,t,n,i,s,o){let l=s.nodeViews[t.type.name],a,c=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,i),f=c&&c.dom,h=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(!E(f))throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:h}=Se.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!h&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let d=f;return f=as(f,n,t),c?a=new Ln(e,t,n,i,f,h||null,d,c):t.isText?new Ut(e,t,n,i,f,d):new r(e,t,n,i,f,h||null,d)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(t.preserveWhitespace="full"),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let i=this.children[n];if(this.dom.contains(i.dom.parentNode)){t.contentElement=i.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(i=>x(i)&&e.indexOf(i.parentNode)<0&&this.dom.contains(i));n?t.contentElement=n:t.getContent=()=>k.empty}}return t}matchesNode(e,t,n){return this.dirty==G&&e.eq(this.node)&&Yt(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new Jn(this,o&&o.node,e),c=this.node.inlineContent,f=c&&this.node.isBlock;cl(this.node,this.innerDeco,(h,d,p)=>{h.spec.marks?a.syncToMarks(h.spec.marks,n,e,d):h.type.side>=0&&!p&&a.syncToMarks(d==this.node.childCount?C.none:this.node.child(d).marks,n,e,d),a.placeWidget(h,e,i)},(h,d,p,u)=>{a.syncToMarks(h.marks,n,e,u),f&&h.isAtom&&!h.isText&&a.addHackNode("IMG",a.top);let m;a.findNodeMatch(h,d,p,u)||l&&e.state.selection.from>i&&e.state.selection.to<i+h.nodeSize&&(m=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(h,d,p,m,e)||a.updateNextNode(h,d,p,e,u,i)||a.addNode(h,d,p,e,i),i+=h.nodeSize,c&&(f=h.isAtom&&!h.isText)}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==we)&&(o&&this.protectLocalComposition(e,o),ss(this.contentDOM,this.children,e),Ye&&fl(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof D)||n<t||i>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=hl(this.node.content,o,n-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Vn(this,s,t,i);e.input.compositionNodes.push(o),this.children=qn(this.children,n,n+i.length,e,o)}update(e,t,n,i){return this.dirty==Z||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,i),!0)}updateInner(e,t,n,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=G}updateOuterDeco(e){if(Yt(e,this.outerDeco))return;let t=!x(this.nodeDOM),n=this.dom;this.dom=ls(this.dom,this.nodeDOM,Wn(this.outerDeco,this.node,t),Wn(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){x(this.nodeDOM)&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){x(this.nodeDOM)&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Di(r,e,t,n,i){as(n,e,r);let s=new me(void 0,r,e,t,n,n,n);return s.contentDOM&&s.updateChildren(i,0),s}var Ut=class r extends me{constructor(e,t,n,i,s,o){super(e,t,n,i,s,null,o)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,i){return this.dirty==Z||this.dirty!=G&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=G||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=G,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,n){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new r(this.parent,i,this.outerDeco,this.innerDeco,s,s)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Z)}get domAtom(){return!1}isText(e){return this.node.text==e}},Gt=class extends Re{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==G&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Ln=class extends me{constructor(e,t,n,i,s,o,l,a){super(e,t,n,i,s,o,l),this.spec=a}update(e,t,n,i){if(this.dirty==Z)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,n);return s&&this.updateInner(e,t,n,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,i){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function ss(r,e,t){let n=r.firstChild,i=!1;for(let s=0;s<e.length;s++){let o=e[s],l=o.dom;if(l.parentNode==r){for(;l!=n;)n=Ti(n),i=!0;n=n.nextSibling}else i=!0,r.insertBefore(l,n);if(o instanceof Ne){let a=n?n.previousSibling:r.lastChild;ss(o.contentDOM,o.children,t),n=a?a.nextSibling:r.firstChild}}for(;n;)n=Ti(n),i=!0;i&&t.trackWrites==r&&(t.trackWrites=null)}var yt=function(r){r&&(this.nodeName=r)};yt.prototype=Object.create(null);var Oe=[new yt];function Wn(r,e,t){if(r.length==0)return Oe;let n=t?Oe[0]:new yt,i=[n];for(let s=0;s<r.length;s++){let o=r[s].type.attrs;if(o){o.nodeName&&i.push(n=new yt(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&i.length==1&&i.push(n=new yt(e.isInline?"span":"div")),l=="class"?n.class=(n.class?n.class+" ":"")+a:l=="style"?n.style=(n.style?n.style+";":"")+a:l!="nodeName"&&(n[l]=a))}}}return i}function ls(r,e,t,n){if(t==Oe&&n==Oe)return e;let i=e;for(let s=0;s<n.length;s++){let o=n[s],l=t[s];if(s){let a;l&&l.nodeName==o.nodeName&&i!=r&&(a=i.parentNode)&&a.nodeName.toLowerCase()==o.nodeName||(a=document.createElement(o.nodeName),a.pmIsDeco=!0,a.appendChild(i),l=Oe[0]),i=a}ol(i,l||Oe[0],o)}return i}function ol(r,e,t){for(let n in e)n!="class"&&n!="style"&&n!="nodeName"&&!(n in t)&&r.removeAttribute(n);for(let n in t)n!="class"&&n!="style"&&n!="nodeName"&&t[n]!=e[n]&&r.setAttribute(n,t[n]);if(e.class!=t.class){let n=e.class?e.class.split(" ").filter(Boolean):[],i=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<n.length;s++)i.indexOf(n[s])==-1&&r.classList.remove(n[s]);for(let s=0;s<i.length;s++)n.indexOf(i[s])==-1&&r.classList.add(i[s]);r.classList.length==0&&r.removeAttribute("class")}if(e.style!=t.style){if(e.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=n.exec(e.style);)r.style.removeProperty(i[1])}t.style&&(r.style.cssText+=t.style)}}function as(r,e,t){return ls(r,r,Oe,Wn(e,t,!x(r)))}function Yt(r,e){if(r.length!=e.length)return!1;for(let t=0;t<r.length;t++)if(!r[t].type.eq(e[t].type))return!1;return!0}function Ti(r){let e=r.nextSibling;return r.parentNode.removeChild(r),e}var Jn=class{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=ll(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,i){let s=0,o=this.stack.length>>1,l=Math.min(o,e.length);for(;s<l&&(s==o-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<o;)this.destroyRest(),this.top.dirty=G,this.index=this.stack.pop(),this.top=this.stack.pop(),o--;for(;o<e.length;){this.stack.push(this.top,this.index+1);let a=-1,c=this.top.children.length;i<this.preMatch.index&&(c=Math.min(this.index+3,c));for(let f=this.index;f<c;f++){let h=this.top.children[f];if(h.matchesMark(e[o])&&!this.isLocked(h.dom)){a=f;break}}if(a<0&&this.index<this.top.children.length){let f=this.top.children[this.index];f instanceof Ne&&f.dirty!=Z&&f.mark.type==e[o].type&&f.spec.update&&!this.isLocked(f.dom)&&f.spec.update(e[o])&&(f.mark=e[o],a=this.index,this.changed=!0)}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let f=Ne.create(this.top,e[o],t,n);this.top.children.splice(this.index,0,f),this.top=f,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,n,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,n)&&!this.preMatch.matched.has(c)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,n,i,s){let o=this.top.children[i];return o.dirty==Z&&o.dom==o.contentDOM&&(o.dirty=we),o.update(e,t,n,s)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let n=e.pmViewDesc;if(n){for(let i=this.index;i<this.top.children.length;i++)if(this.top.children[i]==n)return i}return-1}e=t}}updateNextNode(e,t,n,i,s,o){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof me){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let f=a.dom,h,d=this.isLocked(f)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=Z&&Yt(t,a.outerDeco));if(!d&&a.update(e,t,n,i))return this.destroyBetween(this.index,l),a.dom!=f&&(this.changed=!0),this.index++,!0;if(!d&&(h=this.recreateWrapper(a,e,t,n,i,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=h,h.contentDOM&&(h.dirty=we,h.updateChildren(i,o+1),h.dirty=G),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,i,s,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!Yt(n,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=me.create(this.top,t,n,i,s,o);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,n,i,s){let o=me.create(this.top,e,t,n,i,s);o.contentDOM&&o.updateChildren(i,s+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,n){let i=this.index<this.top.children.length?this.top.children[this.index]:null;if(i&&i.matchesWidget(e)&&(e==i.widget||!i.widget.type.toDOM.parentNode))this.index++;else{let s=new jt(this.top,e,t,n);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Ne;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Ut)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((V||B)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);e=="IMG"&&(n.className="ProseMirror-separator",n.alt=""),e=="BR"&&(n.className="ProseMirror-trailingBreak");let i=new Gt(this.top,[],n,null);t!=this.top?t.children.push(i):t.children.splice(this.index++,0,i),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||x(e)&&e.contains(this.lock.parentNode))}};function ll(r,e){let t=e,n=t.children.length,i=r.childCount,s=new Map,o=[];e:for(;i>0;){let l;for(;;)if(n){let c=t.children[n-1];if(c instanceof Ne)t=c,n=c.children.length;else{l=c,n--;break}}else{if(t==e)break e;n=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=r.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function al(r,e){return r.type.side-e.type.side}function cl(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let c=0;c<r.childCount;c++){let f=r.child(c);n(f,i,e.forChild(s,f),c),s+=f.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let f,h;for(;o<i.length&&i[o].to==s;){let g=i[o++];g.widget&&(f?(h||(h=[f])).push(g):f=g)}if(f)if(h){h.sort(al);for(let g=0;g<h.length;g++)t(h[g],c,!!a)}else t(f,c,!!a);let d,p;if(a)p=-1,d=a,a=null;else if(c<r.childCount)p=c,d=r.child(c++);else break;for(let g=0;g<l.length;g++)l[g].to<=s&&l.splice(g--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)l.push(i[o++]);let u=s+d.nodeSize;if(d.isText){let g=u;o<i.length&&i[o].from<g&&(g=i[o].from);for(let y=0;y<l.length;y++)l[y].to<g&&(g=l[y].to);g<u&&(a=d.cut(g-s),d=d.cut(0,g-s),u=g,p=-1)}else for(;o<i.length&&i[o].to<u;)o++;let m=d.isInline&&!d.isLeaf?l.filter(g=>!g.inline):l.slice();n(d,m,e.forChild(s,d),p),s=u}}function fl(r){if(r.nodeName=="UL"||r.nodeName=="OL"){let e=r.style.cssText;r.style.cssText=e+"; list-style: square !important",window.getComputedStyle(r).listStyle,r.style.cssText=e}}function hl(r,e,t,n){for(let i=0,s=0;i<r.childCount&&s<=n;){let o=r.child(i++),l=s;if(s+=o.nodeSize,!o.isText)continue;let a=o.text;for(;i<r.childCount;){let c=r.child(i++);if(s+=c.nodeSize,!c.isText)break;a+=c.text}if(s>=t){if(s>=n&&a.slice(n-e.length-l,n-l)==e)return n-e.length;let c=l<n?a.lastIndexOf(e,n-l-1):-1;if(c>=0&&c+e.length+l>=t)return l+c;if(t==n&&a.length>=n+e.length-l&&a.slice(n-l,n-l+e.length)==e)return n}}return-1}function qn(r,e,t,n,i){let s=[];for(let o=0,l=0;o<r.length;o++){let a=r[o],c=l,f=l+=a.size;c>=t||f<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,n)),i&&(s.push(i),i=void 0),f>t&&s.push(a.slice(t-c,a.size,n)))}return s}function er(r,e=null){let t=r.domSelectionRange(),n=r.state.doc;if(!t.focusNode)return null;let i=r.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=r.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,c;if(rn(t)){for(a=o;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&S.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&Jo(t.focusNode,t.focusOffset,i.dom))){let h=i.posBefore;c=new S(o==h?l:n.resolve(h))}else if(j&&e=="key"&&o>r.state.selection.to&&x(t.focusNode)&&t.focusOffset==t.focusNode.childNodes.length&&i&&i.posAtStart>r.state.selection.to)for(let h=t.focusNode;;h=h.parentNode){if(getComputedStyle(h).overflow!="visible"){c=N.findFrom(n.resolve(i.posAtStart),1);break}if(h==i.dom||h.nextSibling||!h.parentNode||!x(h.parentNode))break}}else{if(t instanceof r.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let h=o,d=o;for(let p=0;p<t.rangeCount;p++){let u=t.getRangeAt(p);h=Math.min(h,r.docView.posFromDOM(u.startContainer,u.startOffset,1)),d=Math.max(d,r.docView.posFromDOM(u.endContainer,u.endOffset,-1))}if(h<0)return null;[a,o]=d==r.state.selection.anchor?[d,h]:[h,d],l=n.resolve(o)}else a=r.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let f=n.resolve(a);if(!c){let h=e=="pointer"||r.state.selection.head<l.pos&&!s?1:-1;c=tr(r,f,l,h)}return c}function cs(r){return r.editable?r.hasFocus():hs(r)&&document.activeElement&&document.activeElement.contains(r.dom)}function ae(r,e=!1){let t=r.state.selection;if(fs(r,t),!cs(r))return;let n=r.input.mouseDown;if(!e&&B&&n){let i=r.domSelectionRange(),s=r.domObserver.currentSelection;if(i.anchorNode&&s.anchorNode&&Ae(i.anchorNode,i.anchorOffset,s.anchorNode,s.anchorOffset)&&n.delaySelUpdate()){r.domObserver.setCurSelection();return}}if(r.domObserver.disconnectSelection(),r.cursorWrapper)dl(r);else{let{anchor:i,head:s}=t,o,l;Ei&&!(t instanceof D)&&(t.$from.parent.inlineContent||(o=Ai(r,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(l=Ai(r,t.to))),r.docView.setSelection(i,s,r,e),Ei&&(o&&Ii(o),l&&Ii(l)),t.visible?r.dom.classList.remove("ProseMirror-hideselection"):(r.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&ul(r))}r.domObserver.setCurSelection(),r.domObserver.connectSelection()}var Ei=V||B&&Xi<63;function Ai(r,e){let{node:t,offset:n}=r.docView.domFromPos(e,0),i=n<t.childNodes.length?t.childNodes[n]:null,s=n?t.childNodes[n-1]:null;if(V&&i&&i.contentEditable=="false")return An(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return An(i);if(s)return An(s)}}function An(r){return r.contentEditable="true",V&&r.draggable&&(r.draggable=!1,r.wasDraggable=!0),r}function Ii(r){r.contentEditable="false",r.wasDraggable&&(r.draggable=!0,r.wasDraggable=null)}function ul(r){let e=r.dom.ownerDocument;e.removeEventListener("selectionchange",r.input.hideSelectionGuard);let t=r.domSelectionRange(),n=t.anchorNode,i=t.anchorOffset;e.addEventListener("selectionchange",r.input.hideSelectionGuard=()=>{(t.anchorNode!=n||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!cs(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function dl(r){let e=r.domSelection();if(!e)return;let t=r.cursorWrapper.dom,n=t.nodeName=="IMG";n?e.collapse(t.parentNode,R(t)+1):e.collapse(t,0),!n&&!r.state.selection.visible&&K&&pe<=11&&(t.disabled=!0,t.disabled=!1)}function fs(r,e){if(e instanceof S){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(Ri(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else Ri(r)}function Ri(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function tr(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||D.between(e,t,n)}function Bi(r){return r.editable&&!r.hasFocus()?!1:hs(r)}function hs(r){let e=r.domSelectionRange();if(!e.anchorNode)return!1;try{return Ie(r.dom,e.anchorNode)&&(r.editable||Ie(r.dom,e.focusNode))}catch{return!1}}function pl(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return Ae(e.node,e.offset,t.anchorNode,t.anchorOffset)}function $n(r,e){let{$anchor:t,$head:n}=r.selection,i=e>0?t.max(n):t.min(n),s=i.parent.inlineContent?i.depth?r.doc.resolve(e>0?i.after():i.before()):null:i;return s&&N.findFrom(s,e)}function de(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function Pi(r,e,t){let n=r.state.selection;if(n instanceof D)if(t.indexOf("s")>-1){let{$head:i}=n,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=r.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return de(r,new D(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=$n(r.state,e);return i&&i instanceof S?de(r,i):!1}else if(!(U&&t.indexOf("m")>-1)){let i=n.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=r.docView.descAt(l))&&!o.contentDOM?S.isSelectable(s)?de(r,new S(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):de(r,new D(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1}}else return!1;else{if(n instanceof S&&n.node.isInline)return de(r,new D(e>0?n.$to:n.$from));{let i=$n(r.state,e);return i?de(r,i):!1}}}function kt(r,e){let t=r.pmViewDesc;return t?t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR"):x(r)&&r.contentEditable=="false"}function je(r,e){return e<0?ml(r):gl(r)}function ml(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(j&&x(t)&&n<F(t)&&kt(t.childNodes[n],-1)&&(o=!0);;)if(n>0){if(!x(t))break;let l=t.childNodes[n-1];if(kt(l,-1))i=t,s=--n;else if(E(l))t=l,n=t.nodeValue.length;else break}else{if(us(t))break;{let l=t.previousSibling;for(;l&&kt(l,-1);)i=t.parentNode,s=R(l),l=l.previousSibling;if(l)t=l,n=F(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?Kn(r,t,n):i&&Kn(r,i,s)}function gl(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=F(t),s,o;for(;;)if(n<i){if(!x(t))break;let l=t.childNodes[n];if(kt(l,1))s=t,o=++n;else break}else{if(us(t))break;{let l=t.nextSibling;for(;l&&kt(l,1);)s=l.parentNode,o=R(l)+1,l=l.nextSibling;if(l)t=l,n=0,i=F(t);else{if(t=t.parentNode,t==r.dom)break;n=i=0}}}s&&Kn(r,s,o)}function us(r){let e=r.pmViewDesc;return e&&e.node&&e.node.isBlock}function yl(r,e){for(;r&&e==r.childNodes.length&&!Ct(r);)e=R(r)+1,r=r.parentNode;for(;r&&e<r.childNodes.length;){let t=r.childNodes[e];if(E(t))return t;if(x(t)&&t.contentEditable=="false")break;r=t,e=0}}function kl(r,e){for(;r&&!e&&!Ct(r);)e=R(r),r=r.parentNode;for(;r&&e;){let t=r.childNodes[e-1];if(E(t))return t;if(x(t)&&t.contentEditable=="false")break;r=t,e=r.childNodes.length}}function Kn(r,e,t){if(!E(e)){let s,o;(o=yl(e,t))?(e=o,t=0):(s=kl(e,t))&&(e=s,t=s.nodeValue.length)}let n=r.domSelection();if(!n)return;if(rn(n)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),n.removeAllRanges(),n.addRange(s)}else n.extend&&n.extend(e,t);r.domObserver.setCurSelection();let{state:i}=r;setTimeout(()=>{r.state==i&&ae(r)},50)}function zi(r,e){let t=r.state.doc.resolve(e);if(!(B||Zi)&&t.parent.inlineContent){let i=r.coordsAtPos(e);if(e>t.start()){let s=r.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left<i.left?"ltr":"rtl"}if(e<t.end()){let s=r.coordsAtPos(e+1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(r.dom).direction=="rtl"?"rtl":"ltr"}function vi(r,e,t){let n=r.state.selection;if(n instanceof D&&!n.empty||t.indexOf("s")>-1||U&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=$n(r.state,e);if(o&&o instanceof S)return de(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof _?N.near(o,e):N.findFrom(o,e);return l?de(r,l):!1}return!1}function Fi(r,e){if(!(r.state.selection instanceof D))return!0;let{$head:t,$anchor:n,empty:i}=r.state.selection;if(!t.sameParent(n))return!0;if(!i)return!1;if(r.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=r.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),r.dispatch(o),!0}return!1}function Vi(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function bl(r){if(!V||r.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(e&&x(e)&&t==0&&e.firstChild&&x(e.firstChild)&&e.firstChild.contentEditable=="false"){let n=e.firstChild;Vi(r,n,"true"),setTimeout(()=>Vi(r,n,"false"),20)}return!1}function xl(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function Sl(r,e){let t=e.keyCode,n=xl(e);if(t==8||U&&t==72&&n=="c")return Fi(r,-1)||je(r,-1);if(t==46&&!e.shiftKey||U&&t==68&&n=="c")return Fi(r,1)||je(r,1);if(t==13||t==27)return!0;if(t==37||U&&t==66&&n=="c"){let i=t==37?zi(r,r.state.selection.from)=="ltr"?-1:1:-1;return Pi(r,i,n)||je(r,i)}else if(t==39||U&&t==70&&n=="c"){let i=t==39?zi(r,r.state.selection.from)=="ltr"?1:-1:1;return Pi(r,i,n)||je(r,i)}else{if(t==38||U&&t==80&&n=="c")return vi(r,-1,n)||je(r,-1);if(t==40||U&&t==78&&n=="c")return bl(r)||vi(r,1,n)||je(r,1);if(n==(U?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function nr(r,e){r.someProp("transformCopied",p=>{e=p(e,r)});let t=[],{content:n,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){i--,s--;let p=n.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),n=p.content}let o=r.someProp("clipboardSerializer")||Se.fromSchema(r.state.schema),l=ks(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let c=a.firstChild,f,h=0;for(;c&&x(c)&&(f=ys[c.nodeName.toLowerCase()]);){for(let p=f.length-1;p>=0;p--){let u=l.createElement(f[p]);for(;a.firstChild;)u.appendChild(a.firstChild);a.appendChild(u),h++}c=a.firstChild}c&&x(c)&&c.setAttribute("data-pm-slice",`${i} ${s}${h?` -${h}`:""} ${JSON.stringify(t)}`);let d=r.someProp("clipboardTextSerializer",p=>p(e,r))||e.content.textBetween(0,e.content.size,`
7
7
 
8
- `);return{dom:a,text:d,slice:e}}function ps(r,e,t,n,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=!!e&&(n||s||!t);if(a){if(r.someProp("transformPastedText",d=>{e=d(e,s||n,r)}),s)return l=new b(k.from(r.state.schema.text(e.replace(/\r\n?/g,`
9
- `))),0,0),r.someProp("transformPasted",d=>{l=d(l,r,!0)}),l;let h=r.someProp("clipboardTextParser",d=>d(e,i,n,r));if(h)l=h;else{let d=i.marks(),{schema:p}=r.state,u=Se.fromSchema(p);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(u.serializeNode(p.text(m,d)))})}}else r.someProp("transformPastedHTML",h=>{t=h(t,r)}),o=Nl(t),sn&&Dl(o);let c=o&&o.querySelector("[data-pm-slice]"),f=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let h=+f[3];h>0;h--){let d=o.firstChild;for(;d&&!x(d);)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||rt.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Cl.test(d.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Tl(Wi(l,+f[1],+f[2]),f[4]);else if(l=b.maxOpen(wl(l.content,i),!0),l.openStart||l.openEnd){let h=0,d=0;for(let p=l.content.firstChild;h<l.openStart&&!p.type.spec.isolating;h++,p=p.firstChild);for(let p=l.content.lastChild;d<l.openEnd&&!p.type.spec.isolating;d++,p=p.lastChild);l=Wi(l,h,d)}return r.someProp("transformPasted",h=>{l=h(l,r,a)}),l}var Cl=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function wl(r,e){if(r.childCount<2)return r;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(r.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&gs(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=ys(o[o.length-1],s.length));let f=ms(l,a);o.push(f),i=i.matchType(f.type),s=a}}),o)return k.from(o)}return r}function ms(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,k.from(r));return r}function gs(r,e,t,n,i){if(i<r.length&&i<e.length&&r[i]==e[i]){let s=gs(r,e,t,n.lastChild,i+1);if(s)return n.copy(n.content.replaceChild(n.childCount-1,s));if(n.contentMatchAt(n.childCount).matchType(i==r.length-1?t.type:r[i+1]))return n.copy(n.content.append(k.from(ms(t,r,i+1))))}}function ys(r,e){if(e==0)return r;let t=r.content.replaceChild(r.childCount-1,ys(r.lastChild,e-1)),n=r.contentMatchAt(r.childCount).fillBefore(k.empty,!0);return r.copy(t.append(n))}function Hn(r,e,t,n,i,s){let o=e<0?r.firstChild:r.lastChild,l=o.content;return r.childCount>1&&(s=0),i<n-1&&(l=Hn(l,e,t,n,i+1,s)),i>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(k.empty,!0))),r.replaceChild(e<0?0:r.childCount-1,o.copy(l))}function Wi(r,e,t){return e<r.openStart&&(r=new b(Hn(r.content,-1,e,r.openStart,0,r.openEnd),e,r.openEnd)),t<r.openEnd&&(r=new b(Hn(r.content,1,t,r.openEnd,0,0),r.openStart,t)),r}var ks={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function bs(){return document.implementation.createHTMLDocument("title")}var gt=null;function Ol(r){let e=window.trustedTypes;if(!e)return r;if(!gt){if(gt=e.defaultPolicy)try{return gt.createHTML(r)}catch{}gt=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})}return gt.createHTML(r)}function Nl(r){let e=/^(\s*<meta [^>]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=bs(),n=t.body,i=/<([a-z][^>\s]+)/i.exec(r),s;if((s=i&&ks[i[1].toLowerCase()])&&(r=s.map(o=>"<"+o+">").join("")+r+s.map(o=>"</"+o+">").reverse().join("")),n.innerHTML=Ol(r),s)for(let o=0;o<s.length;o++)n=n.querySelector(s[o])||n;for(let o=0;o<t.styleSheets.length;o++){let l=t.styleSheets[o];for(let a=0;a<l.rules.length;a++){let c=l.rules[a];if(c instanceof CSSStyleRule){let f=n.querySelectorAll(c.selectorText);for(let h=0;h<f.length;h++)f[h].style.cssText+=c.style.cssText}}}return n}function Dl(r){let e=r.querySelectorAll(B?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let n=e[t];n.childNodes.length==1&&n.textContent=="\xA0"&&n.parentNode&&n.parentNode.replaceChild(r.ownerDocument.createTextNode(" "),n)}}function Tl(r,e){if(!r.size)return r;let t=r.content.firstChild.type.schema,n;try{n=JSON.parse(e)}catch{return r}let{content:i,openStart:s,openEnd:o}=r;for(let l=n.length-2;l>=0;l-=2){let a=t.nodes[n[l]];if(!a||a.hasRequiredAttrs())break;try{i=k.from(a.create(n[l+1],i))}catch{break}s++,o++}return new b(i,s,o)}var W={},J={},El={touchstart:!0,touchmove:!0},_n=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Al(r){for(let e in W){let t=W[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Rl(r,n)&&!rr(r,n)&&(r.editable||!(n.type in J))&&t(r,n)},El[e]?{passive:!0}:void 0)}V&&r.dom.addEventListener("input",()=>null),jn(r)}function le(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function Il(r){r.input.mouseDown&&r.input.mouseDown.done(),r.domObserver.stop();for(let e in r.input.eventHandlers)r.dom.removeEventListener(e,r.input.eventHandlers[e]);clearTimeout(r.input.composingTimeout),clearTimeout(r.input.lastIOSEnterFallbackTimeout)}function jn(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>rr(r,n))})}function rr(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Rl(r,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=r.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Bl(r,e){!rr(r,e)&&W[e.type]&&(r.editable||!(e.type in J))&&W[e.type](r,e)}J.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!Ms(r)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(oe&&B&&t.keyCode==13)))if(t.keyCode!=229&&r.domObserver.forceFlush(),Ye&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let n=Date.now();r.input.lastIOSEnter=n,r.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{r.input.lastIOSEnter==n&&(r.someProp("handleKeyDown",i=>i(r,Ce(13,"Enter"))),r.input.lastIOSEnter=0)},200)}else r.someProp("handleKeyDown",n=>n(r,t))||Ml(r,t)?t.preventDefault():le(r,"key")};J.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)};J.keypress=(r,e)=>{let t=e;if(Ms(r)||!t.charCode||t.ctrlKey&&!t.altKey||U&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof D)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode),s=()=>r.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",o=>o(r,n.$from.pos,n.$to.pos,i,s))&&r.dispatch(s()),t.preventDefault()}};function wt(r){return{left:r.clientX,top:r.clientY}}function Pl(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function ir(r,e,t,n,i){if(n==-1)return!1;let s=r.state.doc.resolve(n);for(let o=s.depth+1;o>0;o--)if(r.someProp(e,l=>o>s.depth?l(r,t,s.nodeAfter,s.before(o),i,!0):l(r,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function Ot(r,e,t){if(r.focused||r.focus(),r.state.selection.eq(e))return;let n=r.state.tr.setSelection(e);n.setMeta("pointer",!0),r.dispatch(n)}function zl(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&S.isSelectable(n)?(Ot(r,new S(t)),!0):!1}function vl(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof S&&(n=t.node);let s=r.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(S.isSelectable(l)){n&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(Ot(r,S.create(r.state.doc,i)),!0):!1}function Fl(r,e,t,n,i){return ir(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?vl(r,t):zl(r,t))}function Vl(r,e,t,n){return ir(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function Ll(r,e,t,n){return ir(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||Wl(r,t,n)}function Wl(r,e,t){if(t.button!=0)return!1;let n=xs(r,e,!0),i=r.state.doc;return n?(Ot(r,n),n instanceof D&&i.eq(r.state.doc)&&(r.input.mouseDown=new Gn(r,n)),!0):!1}function xs(r,e,t){let n=r.state.doc;if(e==-1)return n.inlineContent?D.create(n,0,n.content.size):null;let i=n.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)return D.create(n,l+1,l+1+o.content.size);if(t&&S.isSelectable(o))return S.create(n,l)}return null}function sr(r){return Zt(r)}var Ss=U?"metaKey":"ctrlKey";W.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=sr(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&Pl(t,r.input.lastClick)&&!t[Ss]&&r.input.lastClick.button==t.button&&(r.input.lastClick.type=="singleClick"?s="doubleClick":r.input.lastClick.type=="doubleClick"&&(s="tripleClick")),r.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s,button:t.button},r.input.mouseDown&&r.input.mouseDown.done();let o=r.posAtCoords(wt(t));o&&(s=="singleClick"?r.input.mouseDown=new Un(r,o,t,!!n):(s=="doubleClick"?Vl:Ll)(r,o.pos,o.inside,t)?t.preventDefault():le(r,"pointer"))};var Xt=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},Un=class extends Xt{constructor(e,t,n,i){super(e),this.pos=t,this.event=n,this.flushed=i,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[Ss],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let f=e.state.doc.resolve(t.pos);s=f.parent,o=f.depth?f.before():0}let l=i?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&x(a.nodeDOM)?a.nodeDOM:null;let{selection:c}=e.state;n.button==0&&(s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof S&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&j&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),le(e,"pointer")}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||ae(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(wt(e))),this.updateAllowDefault(e),this.allowDefault||!t?le(this.view,"pointer"):Fl(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||V&&this.mightDrag&&!this.mightDrag.node.isAtom||B&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Ot(this.view,N.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):le(this.view,"pointer")}move(e){this.updateAllowDefault(e),le(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},Gn=class extends Xt{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),le(this.view,"pointer");let t=this.view.posAtCoords(wt(e)),n=t&&xs(this.view,t.inside,!1);if(!n)return;let{doc:i}=this.view.state,s=this.startSelection,[o,l]=n.from<s.from?[s.to,n.from]:[s.from,n.to];Ot(this.view,D.create(i,o,l))}};W.touchstart=r=>{r.input.lastTouch=Date.now(),sr(r),le(r,"pointer")};W.touchmove=r=>{r.input.lastTouch=Date.now(),le(r,"pointer")};W.contextmenu=r=>sr(r);function Ms(r,e){return r.composing?!0:V&&Math.abs(Date.now()-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}var Jl=oe?5e3:-1;J.compositionstart=J.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$to;if(e.selection instanceof D&&e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)||B&&Qi&&ql(r)))r.markCursor=r.state.storedMarks||t.marks(),Zt(r,!0),r.markCursor=null;else if(Zt(r,!e.selection.empty),j&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let n=r.domSelectionRange();for(let i=n.focusNode,s=n.focusOffset;i&&x(i)&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(E(o)){let l=r.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}r.input.composing=!0}Cs(r,Jl)};function ql(r){let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(!e||!x(e)||t>=e.childNodes.length)return!1;let n=e.childNodes[t];return x(n)&&n.contentEditable=="false"}J.compositionend=(r,e)=>{r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Date.now(),r.input.compositionPendingChanges=r.domObserver.pendingRecords().length?r.input.compositionID:0,r.input.compositionNode=null,r.input.badSafariComposition?r.domObserver.forceFlush():r.input.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,Cs(r,20))};function Cs(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>Zt(r),e))}function ws(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Date.now());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function $l(r){let e=r.domSelectionRange();if(!e.focusNode)return null;let t=Wo(e.focusNode,e.focusOffset),n=Jo(e.focusNode,e.focusOffset);if(t&&n&&t!=n){let i=n.pmViewDesc,s=r.domObserver.lastChangedTextNode;if(t==s||n==s)return s;if(!i||!i.isText(n.nodeValue))return n;if(r.input.compositionNode==n){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return n}}return t||n}function Zt(r,e=!1){if(!(oe&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),ws(r),e||r.docView&&r.docView.dirty){let t=er(r),n=r.state.selection;return t&&!t.eq(n)?r.dispatch(r.state.tr.setSelection(t)):(r.markCursor||e)&&!n.$from.node(n.$from.sharedDepth(n.to)).inlineContent?r.dispatch(r.state.tr.deleteSelection()):r.updateState(r.state),!0}return!1}}function Kl(r,e){if(!r.dom.parentNode)return;let t=r.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),i=document.createRange();i.selectNodeContents(e),r.dom.blur(),n.removeAllRanges(),n.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),r.focus()},50)}var bt=K&&pe<15||Ye&&Ho<604;W.copy=J.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=bt?null:t.clipboardData,o=n.content(),{dom:l,text:a}=nr(r,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):Kl(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Hl(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function _l(r,e){if(!r.dom.parentNode)return;let t=r.input.shiftKey||r.state.selection.$from.parent.type.spec.code,n=r.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let i=r.input.shiftKey&&r.input.lastKeyCode!=45;setTimeout(()=>{r.focus(),n.parentNode&&n.parentNode.removeChild(n),t?xt(r,n.value,null,i,e):xt(r,n.textContent,n.innerHTML,i,e)},50)}function xt(r,e,t,n,i){let s=ps(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||b.empty)))return!0;if(!s)return!1;let o=Hl(s),l=o?r.state.tr.replaceSelectionWith(o,n):r.state.tr.replaceSelection(s);return r.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Os(r){let e=r.getData("text/plain")||r.getData("Text");if(e)return e;let t=r.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}J.paste=(r,e)=>{let t=e;if(r.composing&&!oe)return;let n=bt?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&xt(r,Os(n),n.getData("text/html"),i,t)?t.preventDefault():_l(r,t)};var Qt=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},jl=U?"altKey":"ctrlKey";function Ns(r,e){let t;return r.someProp("dragCopies",n=>{t=t||n(e)}),t!=null?!t:!e[jl]}W.dragstart=(r,e)=>{let t=e,n=r.input.mouseDown;if(n&&n.done(),!t.dataTransfer)return;let i=r.state.selection,s=i.empty?null:r.posAtCoords(wt(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof S?i.to-1:i.to))){if(n&&n.mightDrag)o=S.create(r.state.doc,n.mightDrag.pos);else if(t.target&&x(t.target)){let h=r.docView.nearestDesc(t.target,!0);h&&h.node.type.spec.draggable&&h!=r.docView&&(o=S.create(r.state.doc,h.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:c,slice:f}=nr(r,l);(!t.dataTransfer.files.length||!B||Zi>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(bt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",bt||t.dataTransfer.setData("text/plain",c),r.dragging=new Qt(f,Ns(r,t),o)};W.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)};J.dragover=J.dragenter=(r,e)=>e.preventDefault();J.drop=(r,e)=>{try{Ul(r,e,r.dragging)}finally{r.dragging=null}};function Ul(r,e,t){if(!e.dataTransfer)return;let n=r.posAtCoords(wt(e));if(!n)return;let i=r.state.doc.resolve(n.pos),s=t&&t.slice;s?r.someProp("transformPasted",p=>{s=p(s,r,!1)}):s=ps(r,Os(e.dataTransfer),bt?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(t&&Ns(r,e));if(r.someProp("handleDrop",p=>p(r,e,s||b.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?ai(r.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let a=r.state.tr;if(o){let{node:p}=t;p?p.replace(a):a.deleteSelection()}let c=a.mapping.map(l),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,h=a.doc;if(f?a.replaceRangeWith(c,c,s.content.firstChild):a.replaceRange(c,c,s),a.doc.eq(h))return;let d=a.doc.resolve(c);if(f&&S.isSelectable(s.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new S(d));else{let p=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((u,m,g,y)=>p=y),a.setSelection(tr(r,d,a.doc.resolve(p)))}r.focus(),r.dispatch(a.setMeta("uiEvent","drop"))}W.focus=r=>{r.input.lastFocus=Date.now(),r.focused||(r.domObserver.stop(),r.dom.classList.add("ProseMirror-focused"),r.domObserver.start(),r.focused=!0,setTimeout(()=>{r.docView&&r.hasFocus()&&!r.domObserver.currentSelection.eq(r.domSelectionRange())&&ae(r)},20))};W.blur=(r,e)=>{let t=e;r.focused&&(r.domObserver.stop(),r.dom.classList.remove("ProseMirror-focused"),r.domObserver.start(),t.relatedTarget&&r.dom.contains(t.relatedTarget)&&r.domObserver.currentSelection.clear(),r.focused=!1)};W.beforeinput=(r,e)=>{if(oe&&e.inputType=="deleteContentBackward"){r.domObserver.flushSoon();let{domChangeCount:n}=r.input;setTimeout(()=>{if(r.input.domChangeCount!=n||(r.dom.blur(),r.focus(),r.someProp("handleKeyDown",s=>s(r,Ce(8,"Backspace")))))return;let{$cursor:i}=r.state.selection;i&&i.pos>0&&r.dispatch(r.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let r in J)W[r]=J[r];function St(r,e){if(r==e)return!0;for(let t in r)if(r[t]!==e[t])return!1;for(let t in e)if(!(t in r))return!1;return!0}var en=class r{constructor(e,t){this.toDOM=e,this.spec=t||Te,this.side=this.spec.side||0}map(e,t,n,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ge(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof r&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&St(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},De=class r{constructor(e,t){this.attrs=e,this.spec=t||Te}map(e,t,n,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-n;return s>=o?null:new ge(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof r&&St(this.attrs,e.attrs)&&St(this.spec,e.spec)}static is(e){return e.type instanceof r}destroy(){}},Yn=class r{constructor(e,t){this.attrs=e,this.spec=t||Te}map(e,t,n,i){let s=e.mapResult(t.from+i,1);if(s.deleted)return null;let o=e.mapResult(t.to+i,-1);return o.deleted||o.pos<=s.pos?null:new ge(s.pos-n,o.pos-n,this)}valid(e,t){let{index:n,offset:i}=e.content.findIndex(t.from),s;return i==t.from&&!(s=e.child(n)).isText&&i+s.nodeSize==t.to}eq(e){return this==e||e instanceof r&&St(this.attrs,e.attrs)&&St(this.spec,e.spec)}destroy(){}},ge=class r{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new r(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new r(e,e,new en(t,n))}static inline(e,t,n,i){return new r(e,t,new De(n,i))}static node(e,t,n,i){return new r(e,t,new Yn(n,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof De}get widget(){return this.type instanceof en}},Ue=[],Te={},Y=class r{constructor(e,t){this.local=e.length?e:Ue,this.children=t.length?t:Ue}static create(e,t){return t.length?nn(t,e,0,Te):v}find(e,t,n){let i=[];return this.findInner(e??0,t??1e9,i,0,n),i}findInner(e,t,n,i,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&n.push(l.copy(l.from+i,l.to+i))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,n,i+l,s)}}map(e,t,n){return this==v||e.maps.length==0?this:this.mapInner(e,t,0,0,n||Te)}mapInner(e,t,n,i,s){let o;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,n,i);a&&a.type.valid(t,a)?(o||(o=[])).push(a):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?Gl(this.children,o||[],e,t,n,i,s):o?new r(o.sort(Ee),Ue):v}add(e,t){return t.length?this==v?r.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let i,s=0;e.forEach((l,a)=>{let c=a+n,f;if(f=Ts(t,l,c)){for(i||(i=this.children.slice());s<i.length&&i[s]<a;)s+=3;i[s]==a?i[s+2]=i[s+2].addInner(l,f,c+1):i.splice(s,0,a,a+l.nodeSize,nn(f,l,c+1,Te)),s+=3}});let o=Ds(s?Es(t):t,-n);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new r(o.length?this.local.concat(o).sort(Ee):this.local,i||this.children)}remove(e){return e.length==0||this==v?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,i=this.local;for(let s=0;s<n.length;s+=3){let o,l=n[s]+t,a=n[s+1]+t;for(let f=0,h;f<e.length;f++)(h=e[f])&&h.from>l&&h.to<a&&(e[f]=null,(o||(o=[])).push(h));if(!o)continue;n==this.children&&(n=this.children.slice());let c=n[s+2].removeInner(o,l+1);c!=v?n[s+2]=c:(n.splice(s,3),s-=3)}if(i.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<i.length;l++)i[l].eq(o,t)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return n==this.children&&i==this.local?this:i.length||n.length?new r(i,n):v}forChild(e,t){if(this==v)return this;if(t.isLeaf)return r.empty;let n,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(n=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<o&&a.to>s&&a.type instanceof De){let c=Math.max(s,a.from)-s,f=Math.min(o,a.to)-s;c<f&&(i||(i=[])).push(a.copy(c,f))}}if(i){let l=new r(i.sort(Ee),Ue);return n?new tn([l,n]):l}return n||v}eq(e){if(this==e)return!0;if(!(e instanceof r)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return or(this.localsInner(e))}localsInner(e){if(this==v)return Ue;if(e.inlineContent||!this.local.some(De.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof De||t.push(this.local[n]);return t}forEachSet(e){e(this)}};Y.empty=new Y([],[]);Y.removeOverlap=or;var v=Y.empty,tn=class r{constructor(e){this.members=e}map(e,t){let n=this.members.map(i=>i.map(e,t,Te));return r.from(n)}forChild(e,t){if(t.isLeaf)return Y.empty;let n=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=v&&(s instanceof r?n=n.concat(s.members):n.push(s))}return r.from(n)}eq(e){if(!(e instanceof r)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let i=0;i<this.members.length;i++){let s=this.members[i].localsInner(e);if(s.length)if(!t)t=s;else{n&&(t=t.slice(),n=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?or(n?t:t.sort(Ee)):Ue}static from(e){switch(e.length){case 0:return v;case 1:return e[0];default:return new r(e.every(t=>t instanceof Y)?e:e.reduce((t,n)=>t.concat(n instanceof Y?n:n.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function Gl(r,e,t,n,i,s,o){let l=r.slice();for(let c=0,f=s;c<t.maps.length;c++){let h=0;t.maps[c].forEach((d,p,u,m)=>{let g=m-u-(p-d);for(let y=0;y<l.length;y+=3){let M=l[y+1];if(M<0||d>M+f-h)continue;let O=l[y]+f-h;p>=O?l[y+1]=d<=O?-2:-1:d>=f&&g&&(l[y]+=g,l[y+1]+=g)}h+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let f=t.map(r[c]+s),h=f-i;if(h<0||h>=n.content.size){a=!0;continue}let d=t.map(r[c+1]+s,-1),p=d-i,{index:u,offset:m}=n.content.findIndex(h),g=n.maybeChild(u);if(g&&m==h&&m+g.nodeSize==p){let y=l[c+2].mapInner(t,g,f+1,r[c]+s+1,o);y!=v?(l[c]=h,l[c+1]=p,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=Yl(l,r,e,t,i,s,o),f=nn(c,n,0,o);e=f.local;for(let h=0;h<l.length;h+=3)l[h+1]<0&&(l.splice(h,3),h-=3);for(let h=0,d=0;h<f.children.length;h+=3){let p=f.children[h];for(;d<l.length&&l[d]<p;)d+=3;l.splice(d,0,f.children[h],f.children[h+1],f.children[h+2])}}return new Y(e.sort(Ee),l)}function Ds(r,e){if(!e||!r.length)return r;let t=[];for(let n=0;n<r.length;n++){let i=r[n];t.push(new ge(i.from+e,i.to+e,i.type))}return t}function Yl(r,e,t,n,i,s,o){function l(a,c){for(let f=0;f<a.local.length;f++){let h=a.local[f].map(n,i,c);h?t.push(h):o.onRemove&&o.onRemove(a.local[f].spec)}for(let f=0;f<a.children.length;f+=3)l(a.children[f+2],a.children[f]+c+1)}for(let a=0;a<r.length;a+=3)r[a+1]==-1&&l(r[a+2],e[a]+s+1);return t}function Ts(r,e,t){if(e.isLeaf)return null;let n=t+e.nodeSize,i=null;for(let s=0,o;s<r.length;s++)(o=r[s])&&o.from>t&&o.to<n&&((i||(i=[])).push(o),r[s]=null);return i}function Es(r){let e=[];for(let t=0;t<r.length;t++)r[t]!=null&&e.push(r[t]);return e}function nn(r,e,t,n){let i=[],s=!1;e.forEach((l,a)=>{let c=Ts(r,l,a+t);if(c){s=!0;let f=nn(c,l,t+a+1,n);f!=v&&i.push(a,a+l.nodeSize,f)}});let o=Ds(s?Es(r):r,-t).sort(Ee);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||(n.onRemove&&n.onRemove(o[l].spec),o.splice(l--,1));return o.length||i.length?new Y(o,i):v}function Ee(r,e){return r.from-e.from||r.to-e.to}function or(r){let e=r;for(let t=0;t<e.length-1;t++){let n=e[t];if(n.from!=n.to)for(let i=t+1;i<e.length;i++){let s=e[i];if(s.from==n.from){s.to!=n.to&&(e==r&&(e=r.slice()),e[i]=s.copy(s.from,n.to),Ji(e,i+1,s.copy(n.to,s.to)));continue}else{s.from<n.to&&(e==r&&(e=r.slice()),e[t]=n.copy(n.from,s.from),Ji(e,i,n.copy(s.from,n.to)));break}}}return e}function Ji(r,e,t){for(;e<r.length&&Ee(t,r[e])>0;)e++;r.splice(e,0,t)}function In(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=v&&e.push(n)}),r.cursorWrapper&&e.push(Y.create(r.state.doc,[r.cursorWrapper.deco])),tn.from(e)}var Xl={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Zl=K&&pe<=11,Xn=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},Zn=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Xn,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let i=0;i<n.length;i++)this.queue.push(n[i]);K&&pe<=11&&n.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():V&&e.composing&&n.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Zl&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Xl)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Pi(this.view)){if(this.suppressingSelectionUpdates)return ae(this.view);if(K&&pe<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ae(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let s=e.focusNode;s;s=Ge(s))t.add(s);for(let s=e.anchorNode;s;s=Ge(s))if(t.has(s)){n=s;break}let i=n&&this.view.docView.nearestDesc(n);if(i&&i.ignoreMutation({type:"selection",target:E(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Pi(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let f=0;f<t.length;f++){let h=this.registerMutation(t[f],a);h&&(s=s<0?h.from:Math.min(h.from,s),o=o<0?h.to:Math.max(h.to,o),h.typeOver&&(l=!0))}if(a.some(f=>f.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||B&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(f=>f.type=="childList"&&f.removedNodes.length))){for(let f of a)if(f.nodeName=="BR"&&f.parentNode){let h=f.nextSibling;for(;h&&x(h);){if(h.contentEditable=="false"){f.parentNode.removeChild(f);break}h=h.firstChild}}}else if(j&&a.length){let f=a.filter(h=>h.nodeName=="BR");if(f.length==2){let[h,d]=f;h.parentNode&&h.parentNode.parentNode==d.parentNode?d.remove():h.remove()}else{let{focusNode:h}=this.currentSelection;for(let d of f){let p=d.parentNode;p&&p.nodeName=="LI"&&(!h||ta(e,h)!=p)&&d.remove()}}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&rn(n)&&(c=er(e))&&c.eq(N.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ae(e),this.currentSelection.set(n),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),Ql(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,na(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||ae(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(n==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if(e.type=="childList"){for(let f=0;f<e.addedNodes.length;f++){let h=e.addedNodes[f];t.push(h),E(h)&&(this.lastChangedTextNode=h)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let i=e.previousSibling,s=e.nextSibling;if(K&&pe<=11&&e.addedNodes.length)for(let f=0;f<e.addedNodes.length;f++){let{previousSibling:h,nextSibling:d}=e.addedNodes[f];(!h||Array.prototype.indexOf.call(e.addedNodes,h)<0)&&(i=h),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(s=d)}let o=i&&i.parentNode==e.target?R(i)+1:0,l=n.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?R(s):e.target.childNodes.length,c=n.localPosFromDOM(e.target,a,1);return{from:l,to:c}}else return e.type=="attributes"?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},qi=new WeakMap,$i=!1;function Ql(r){if(!qi.has(r)&&(qi.set(r,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(r.dom).whiteSpace)!==-1)){if(r.requiresGeckoHackNode=j,$i)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),$i=!0}}function Ki(r,e){let t=e.startContainer,n=e.startOffset,i=e.endContainer,s=e.endOffset,o=r.domAtPos(r.state.selection.anchor);return Ae(o.node,o.offset,i,s)&&([t,n,i,s]=[i,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:i,focusOffset:s}}function ea(r,e){if(e.getComposedRanges){let i=e.getComposedRanges(r.root)[0];if(i)return Ki(r,i)}let t;function n(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return r.dom.addEventListener("beforeinput",n,!0),document.execCommand("indent"),r.dom.removeEventListener("beforeinput",n,!0),t?Ki(r,t):null}function ta(r,e){for(let t=e.parentNode;t&&t!=r.dom;t=t.parentNode){let n=r.docView.nearestDesc(t,!0);if(n&&n.node.isBlock)return t}return null}function na(r,e){var t;let{focusNode:n,focusOffset:i}=r.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let o=s.nextSibling;for(;o&&o.nodeName!="TD"&&o.nodeName!="TH";)o=o.nextSibling;if(o){let l=o;for(;;){let a=l.firstChild;if(!a||!x(a)||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),n==s&&r.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}function ra(r,e,t,n){let{node:i,fromOffset:s,toOffset:o,from:l,to:a}=r.docView.parseRange(e,t),c=r.domSelectionRange(),f,h=c.anchorNode;if(h&&Ie(r.dom,h)&&(f=[{node:h,offset:c.anchorOffset}],rn(c)||f.push({node:c.focusNode,offset:c.focusOffset})),B&&r.input.lastKeyCode===8)for(let y=o;y>s;y--){let M=i.childNodes[y-1],O=M.pmViewDesc;if(M.nodeName=="BR"&&!O){o=y;break}if(!O||O.size)break}let d=r.state.doc,p=r.someProp("domParser")||rt.fromSchema(r.state.schema),u=d.resolve(l),m=null,g=p.parse(i,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:s,to:o,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:f,ruleFromNode:ia(n),context:u});if(f&&f[0].pos!=null){let y=f[0].pos,M=f[1]&&f[1].pos;M==null&&(M=y),m={anchor:y+l,head:M+l}}return{doc:g,sel:m,from:l,to:a}}var ia=r=>e=>{let t=e.pmViewDesc;if(t)return t.parseRule(r);if(e.nodeName=="BR"&&e.parentNode){if(V&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(e.parentNode.lastChild==e||V&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName=="IMG"&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null},sa=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function oa(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let w=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,A=er(r,w);if(A&&!r.state.selection.eq(A)){if(B&&oe&&r.input.lastKeyCode===13&&Date.now()-100<r.input.lastKeyCodeTime&&r.someProp("handleKeyDown",Us=>Us(r,Ce(13,"Enter"))))return;let q=r.state.tr.setSelection(A);w=="pointer"?q.setMeta("pointer",!0):w=="key"&&q.scrollIntoView(),s&&q.setMeta("composition",s),r.dispatch(q)}return}let o=r.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=r.state.doc.resolve(t).after(l+1);let a=r.state.selection,c=ra(r,e,t,i),f=r.state.doc,h=f.slice(c.from,c.to),d,p;r.input.lastKeyCode===8&&Date.now()-100<r.input.lastKeyCodeTime?(d=r.state.selection.to,p="end"):(d=r.state.selection.from,p="start"),r.input.lastKeyCode=null;let u=fa(h.content,c.doc.content,c.from,d,p);if(u&&r.input.domChangeCount++,(Ye&&r.input.lastIOSEnter>Date.now()-225||oe)&&i.some(w=>x(w)&&!sa.test(w.nodeName))&&(!u||u.endA>=u.endB)&&r.someProp("handleKeyDown",w=>w(r,Ce(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!u)if(n&&a instanceof D&&!a.empty&&a.$head.sameParent(a.$anchor)&&!r.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))u={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let w=Hi(r,r.state.doc,c.sel);if(w&&!w.eq(r.state.selection)){let A=r.state.tr.setSelection(w);s&&A.setMeta("composition",s),r.dispatch(A)}}return}r.state.selection.from<r.state.selection.to&&u.start==u.endB&&r.state.selection instanceof D&&(u.start>r.state.selection.from&&u.start<=r.state.selection.from+2&&r.state.selection.from>=c.from?u.start=r.state.selection.from:u.endA<r.state.selection.to&&u.endA>=r.state.selection.to-2&&r.state.selection.to<=c.to&&(u.endB+=r.state.selection.to-u.endA,u.endA=r.state.selection.to)),K&&pe<=11&&u.endB==u.start+1&&u.endA==u.start&&u.start>c.from&&c.doc.textBetween(u.start-c.from-1,u.start-c.from+1)==" \xA0"&&(u.start--,u.endA--,u.endB--);let m=c.doc.resolveNoCache(u.start-c.from),g=c.doc.resolveNoCache(u.endB-c.from),y=f.resolve(u.start),M=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=u.endA;if((Ye&&r.input.lastIOSEnter>Date.now()-225&&(!M||i.some(w=>w.nodeName=="DIV"||w.nodeName=="P"))||!M&&ca(c.doc,m.pos,g.pos))&&r.someProp("handleKeyDown",w=>w(r,Ce(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>u.start&&aa(f,u.start,u.endA,m,g)&&r.someProp("handleKeyDown",w=>w(r,Ce(8,"Backspace")))){oe&&B&&r.domObserver.suppressSelectionUpdates();return}B&&u.endB==u.start&&(r.input.lastChromeDelete=Date.now()),oe&&!M&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==u.endA&&(u.endB-=2,g=c.doc.resolveNoCache(u.endB-c.from),setTimeout(()=>{r.someProp("handleKeyDown",function(w){return w(r,Ce(13,"Enter"))})},20));let O=u.start,L=u.endA,X=w=>{let A=w||r.state.tr.replace(O,L,c.doc.slice(u.start-c.from,u.endB-c.from));if(c.sel){let q=Hi(r,A.doc,c.sel);q&&!(B&&r.composing&&q.empty&&(u.start!=u.endB||r.input.lastChromeDelete<Date.now()-100)&&(q.head==O||q.head==A.mapping.map(L)-1)||K&&q.empty&&q.head==O)&&A.setSelection(q)}return s&&A.setMeta("composition",s),A.scrollIntoView()},fe;if(M)if(m.pos==g.pos){K&&pe<=11&&m.parentOffset==0&&(r.domObserver.suppressSelectionUpdates(),setTimeout(()=>ae(r),20));let w=X(r.state.tr.delete(O,L)),A=f.resolve(u.start).marksAcross(f.resolve(u.endA));A&&w.ensureMarks(A),r.dispatch(w)}else if(u.endA==u.endB&&(fe=la(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,u.endA-y.start())))){let w=X(r.state.tr);fe.type=="add"?w.addMark(O,L,fe.mark):w.removeMark(O,L,fe.mark),r.dispatch(w)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let w=m.parent.textBetween(m.parentOffset,g.parentOffset),A=()=>X(r.state.tr.insertText(w,O,L));r.someProp("handleTextInput",q=>q(r,O,L,w,A))||r.dispatch(A())}else r.dispatch(X());else r.dispatch(X())}function Hi(r,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:tr(r,e.resolve(t.anchor),e.resolve(t.head))}function la(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let f=0;f<n.length;f++)i=n[f].removeFromSet(i);for(let f=0;f<t.length;f++)s=t[f].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",a=f=>f.mark(l.addToSet(f.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=f=>f.mark(l.removeFromSet(f.marks));else return null;let c=[];for(let f=0;f<e.childCount;f++)c.push(a(e.child(f)));if(k.from(c).eq(r))return{mark:l,type:o}}function aa(r,e,t,n,i){if(t-e<=i.pos-n.pos||Rn(n,!0,!1)<i.pos)return!1;let s=r.resolve(e);if(!n.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=r.resolve(Rn(s,!0,!0));return!o.parent.isTextblock||o.pos>t||Rn(o,!0,!1)<t?!1:n.parent.content.cut(n.parentOffset).eq(o.parent.content)}function ca(r,e,t){let n=0,i=0;return r.nodesBetween(e,t,(s,o)=>{s.isTextblock&&o>=e&&o<t?n++:(s.isText?/\S/.test(s.text.slice(Math.max(0,e-o),Math.min(s.nodeSize,t-o))):s.isLeaf)&&i++}),i==0&&n==1}function Rn(r,e,t){let n=r.depth,i=e?r.end():r.pos;for(;n>0&&(e||r.indexAfter(n)==r.node(n).childCount);)n--,i++,e=!1;if(t){let s=r.node(n).maybeChild(r.indexAfter(n));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function fa(r,e,t,n,i){let s=r.findDiffStart(e,t),o=t+r.size,l=t+e.size;if(s==null)return null;let{a,b:c}=r.findDiffEnd(e,o,l);if(i=="end"){let f=Math.max(0,s-Math.min(a,c));n-=a+f-s}if(a<s&&o<l){let f=n<=s&&n>=a?s-n:0;s-=f,c=s+(c-a),a=s}else if(c<s){let f=n<=s&&n>=c?s-n:0;s-=f,a=s+(a-c),c=s}return{start:s,endA:a,endB:c}}var Mt=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new _n,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Yi),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Ui(this),ji(this),this.nodeViews=Gi(this),this.docView=Ti(this.state.doc,_i(this),In(this),this.dom,this),this.domObserver=new Zn(this,(n,i,s,o)=>oa(this,n,i,s,o)),this.domObserver.start(),Al(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&jn(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Yi),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(ws(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Gi(this);ua(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&jn(this),this.editable=Ui(this),ji(this);let a=In(this),c=_i(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",h=s||!this.docView.matchesNode(e.doc,c,a);(h||!e.selection.eq(i.selection))&&(o=!0);let d=f=="preserve"&&o&&this.dom.style.overflowAnchor==null&&Uo(this);if(o){this.domObserver.stop();let p=h&&(K||B)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&ha(i.selection,e.selection);if(h){let m=B?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=$l(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Ti(e.doc,c,a,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}let u=this.input.mouseDown;p||!(u&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&ml(this)&&u.delaySelUpdate())?ae(this,p):(hs(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((n=this.dragging)===null||n===void 0)&&n.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():d&&Go(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!Ie(this.dom,e))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof S){let t=this.docView.domAfterPos(this.state.selection.from);x(t)&&Ci(this,t.getBoundingClientRect(),e)}else Ci(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let n=this.directPlugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let n=this.state.plugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}updateDraggedNode(e,t){let n=e.node,i=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)i=n.from;else{let s=n.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&s<this.state.doc.content.size&&this.state.doc.nodeAt(s))==n.node&&(i=s)}this.dragging=new Qt(e.slice,e.move,i<0?void 0:S.create(this.state.doc,i))}someProp(e,t){let n=this._props&&this._props[e],i;if(n!=null&&(i=t?t(n):n))return i;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(i=t?t(l):l))return i}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(i=t?t(l):l))return i}}hasFocus(){if(K){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&Yo(this.dom),ae(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return tl(this,e)}coordsAtPos(e,t=1){return is(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let i=this.docView.posFromDOM(e,t,n);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return ol(this,t||this.state,e)}pasteHTML(e,t){return xt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return xt(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return nr(this,e)}destroy(){this.docView&&(Il(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],In(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Vo())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Bl(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?V&&this.root.nodeType===11&&$o(this.dom.ownerDocument)==this.dom&&ea(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Mt.prototype.dispatch=function(r){let e=this._props.dispatchTransaction;e?e.call(this,r):this.updateState(this.state.apply(r))};function _i(r){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(r.editable),r.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(r.state)),t)for(let n in t)n=="class"?e.class+=" "+t[n]:n=="style"?e.style=(e.style?e.style+";":"")+t[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(t[n]))}),e.translate||(e.translate="no"),[ge.node(0,r.state.doc.content.size,e)]}function ji(r){if(r.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),r.cursorWrapper={dom:e,deco:ge.widget(r.state.selection.from,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function Ui(r){return!r.someProp("editable",e=>e(r.state)===!1)}function ha(r,e){let t=Math.min(r.$anchor.sharedDepth(r.head),e.$anchor.sharedDepth(e.head));return r.$anchor.start(t)!=e.$anchor.start(t)}function Gi(r){let e=Object.create(null);function t(n){for(let i in n)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=n[i])}return r.someProp("nodeViews",t),r.someProp("markViews",t),e}function ua(r,e){let t=0,n=0;for(let i in r){if(r[i]!=e[i])return!0;t++}for(let i in e)n++;return t!=n}function Yi(r){if(r.spec.state||r.spec.filterTransaction||r.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Is=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function da(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}var pa=(r,e,t)=>{let n=da(r,t);if(!n)return!1;let i=Rs(n);if(!i){let o=n.blockRange(),l=o&&qt(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Ps(r,i,e,-1))return!0;if(n.parent.content.size==0&&(Xe(s,"end")||S.isSelectable(s)))for(let o=n.depth;;o--){let l=$t(r.doc,n.before(o),n.after(o),b.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=r.tr.step(l);a.setSelection(Xe(s,"end")?N.findFrom(a.doc.resolve(a.mapping.map(i.pos,-1)),-1):S.create(a.doc,i.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(o==1||n.node(o-1).childCount>1)break}return s.isAtom&&i.depth==n.depth-1?(e&&e(r.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Xe(r,e,t=!1){for(let n=r;n;n=e=="start"?n.firstChild:n.lastChild){if(n.isTextblock)return!0;if(t&&n.childCount!=1)return!1}return!1}var ma=(r,e,t)=>{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("backward",r):n.parentOffset>0)return!1;s=Rs(n)}let o=s&&s.nodeBefore;return!o||!S.isSelectable(o)?!1:(e&&e(r.tr.setSelection(S.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Rs(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){if(r.index(e)>0)return r.doc.resolve(r.before(e+1));if(r.node(e).type.spec.isolating)break}return null}function ga(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset<t.parent.content.size)?null:t}var ya=(r,e,t)=>{let n=ga(r,t);if(!n)return!1;let i=Bs(n);if(!i)return!1;let s=i.nodeAfter;if(Ps(r,i,e,1))return!0;if(n.parent.content.size==0&&(Xe(s,"start")||S.isSelectable(s))){let o=$t(r.doc,n.before(),n.after(),b.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=r.tr.step(o);l.setSelection(Xe(s,"start")?N.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):S.create(l.doc,l.mapping.map(i.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&i.depth==n.depth-1?(e&&e(r.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0):!1},ka=(r,e,t)=>{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("forward",r):n.parentOffset<n.parent.content.size)return!1;s=Bs(n)}let o=s&&s.nodeAfter;return!o||!S.isSelectable(o)?!1:(e&&e(r.tr.setSelection(S.create(r.doc,s.pos)).scrollIntoView()),!0)};function Bs(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){let t=r.node(e);if(r.index(e)+1<t.childCount)return r.doc.resolve(r.after(e+1));if(t.type.spec.isolating)break}return null}var ba=(r,e)=>{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(`
10
- `).scrollIntoView()),!0)};function ar(r){for(let e=0;e<r.edgeCount;e++){let{type:t}=r.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}var xa=(r,e)=>{let{$head:t,$anchor:n}=r.selection;if(!t.parent.type.spec.code||!t.sameParent(n))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=ar(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=r.tr.replaceWith(l,l,o.createAndFill());a.setSelection(N.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Sa=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof _||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=ar(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!n.parentOffset&&i.index()<i.parent.childCount?n:i).pos,l=r.tr.insert(o,s.createAndFill());l.setSelection(D.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},Ma=(r,e)=>{let{$cursor:t}=r.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(ut(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&&qt(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function Ca(r){return(e,t)=>{let{$from:n,$to:i}=e.selection;if(e.selection instanceof S&&e.selection.node.isBlock)return!n.parentOffset||!ut(e.doc,n.pos)?!1:(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let p=n.depth;;p--)if(n.node(p).isBlock){a=n.end(p)==n.pos+(n.depth-p),c=n.start(p)==n.pos-(n.depth-p),l=ar(n.node(p-1).contentMatchAt(n.indexAfter(p-1)));let m=r&&r(i.parent,a,n);s.unshift(m||(a&&l?{type:l}:null)),o=p;break}else{if(p==1)return!1;s.unshift(null)}let f=e.tr;(e.selection instanceof D||e.selection instanceof _)&&f.deleteSelection();let h=f.mapping.map(n.pos),d=ut(f.doc,h,s.length,s);if(d||(s[0]=l?{type:l}:null,d=ut(f.doc,h,s.length,s)),f.split(h,s.length,s),!a&&c&&n.node(o).type!=l){let p=f.mapping.map(n.before(o)),u=f.doc.resolve(p);l&&n.node(o-1).canReplaceWith(u.index(),u.index()+1,l)&&f.setNodeMarkup(f.mapping.map(n.before(o)),l)}return t&&t(f.scrollIntoView()),!0}}var wa=Ca();var Oa=(r,e)=>(e&&e(r.tr.setSelection(new _(r.doc))),!0);function Na(r,e,t){let n=e.nodeBefore,i=e.nodeAfter,s=e.index();return!n||!i||!n.type.compatibleContent(i.type)?!1:!n.content.size&&e.parent.canReplace(s-1,s)?(t&&t(r.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||wn(r.doc,e.pos))?!1:(t&&t(r.tr.join(e.pos).scrollIntoView()),!0)}function Ps(r,e,t,n){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Na(r,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let p=e.pos+s.nodeSize,u=k.empty;for(let y=o.length-1;y>=0;y--)u=k.from(o[y].create(null,u));u=k.from(i.copy(u));let m=r.tr.step(new H(e.pos-1,p,e.pos,p,new b(u,1,0),o.length,!0)),g=m.doc.resolve(p+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&wn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let f=s.type.spec.isolating||n>0&&a?null:N.findFrom(e,1),h=f&&f.$from.blockRange(f.$to),d=h&&qt(h);if(d!=null&&d>=e.depth)return t&&t(r.tr.lift(h,d).scrollIntoView()),!0;if(c&&Xe(s,"start",!0)&&Xe(i,"end")){let p=i,u=[];for(;u.push(p),!p.isTextblock;)p=p.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(t){let y=k.empty;for(let O=u.length-1;O>=0;O--)y=k.from(u[O].copy(y));let M=r.tr.step(new H(e.pos-u.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,u.length,0),0,!0));t(M.scrollIntoView())}return!0}}return!1}function zs(r){return function(e,t){let n=e.selection,i=r<0?n.$from:n.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(D.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}var Da=zs(-1),Ta=zs(1);function Ea(r,e,t,n){for(let i=0;i<e.length;i++){let{$from:s,$to:o}=e[i],l=s.depth==0?r.inlineContent&&r.type.allowsMarkType(t):!1;if(r.nodesBetween(s.pos,o.pos,(a,c)=>{if(l||!n&&a.isAtom&&a.isInline&&c>=s.pos&&c+a.nodeSize<=o.pos)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function Aa(r){let e=[];for(let t=0;t<r.length;t++){let{$from:n,$to:i}=r[t];n.doc.nodesBetween(n.pos,i.pos,(s,o)=>{if(s.isAtom&&s.content.size&&s.isInline&&o>=n.pos&&o+s.nodeSize<=i.pos)return o+1>n.pos&&e.push(new Ke(n,n.doc.resolve(o+1))),n=n.doc.resolve(o+1+s.content.size),!1}),n.pos<i.pos&&e.push(new Ke(n,i))}return e}function Be(r,e=null,t){let n=(t&&t.removeWhenPresent)!==!1,i=(t&&t.enterInlineAtoms)!==!1;return function(s,o){let{empty:l,$cursor:a,ranges:c}=s.selection;if(l&&!a||!Ea(s.doc,c,r,i))return!1;if(o)if(a)r.isInSet(s.storedMarks||a.marks())?o(s.tr.removeStoredMark(r)):o(s.tr.addStoredMark(r.create(e)));else{let f,h=s.tr;i||(c=Aa(c)),n?f=!c.some(d=>s.doc.rangeHasMark(d.$from.pos,d.$to.pos,r)):f=!c.every(d=>{let p=!1;return h.doc.nodesBetween(d.$from.pos,d.$to.pos,(u,m,g)=>{if(p)return!1;p=!r.isInSet(u.marks)&&!!g&&g.type.allowsMarkType(r)&&!(u.isText&&/^\s*$/.test(u.textBetween(Math.max(0,d.$from.pos-m),Math.min(u.nodeSize,d.$to.pos-m))))}),!p});for(let d=0;d<c.length;d++){let{$from:p,$to:u}=c[d];if(!f)h.removeMark(p.pos,u.pos,r);else{let m=p.pos,g=u.pos,y=p.nodeAfter,M=u.nodeBefore,O=y&&y.isText?/^\s*/.exec(y.text)[0].length:0,L=M&&M.isText?/\s*$/.exec(M.text)[0].length:0;m+O<g&&(m+=O,g-=L),h.addMark(m,g,r.create(e))}}o(h.scrollIntoView())}return!0}}function cr(...r){return function(e,t,n){for(let i=0;i<r.length;i++)if(r[i](e,t,n))return!0;return!1}}var lr=cr(Is,pa,ma),As=cr(Is,ya,ka),ce={Enter:cr(ba,Sa,Ma,wa),"Mod-Enter":xa,Backspace:lr,"Mod-Backspace":lr,"Shift-Backspace":lr,Delete:As,"Mod-Delete":As,"Mod-a":Oa},vs={"Ctrl-h":ce.Backspace,"Alt-Backspace":ce["Mod-Backspace"],"Ctrl-d":ce.Delete,"Ctrl-Alt-Backspace":ce["Mod-Delete"],"Alt-Delete":ce["Mod-Delete"],"Alt-d":ce["Mod-Delete"],"Ctrl-a":Da,"Ctrl-e":Ta};for(let r in ce)vs[r]=ce[r];var Ia=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Fs=Ia?vs:ce;var Ra=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Ba(r){let e=r.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,i,s,o;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))n=!0;else if(/^(c|ctrl|control)$/i.test(a))i=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Ra?o=!0:i=!0;else throw new Error("Unrecognized modifier name: "+a)}return n&&(t="Alt-"+t),i&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function Pa(r){let e=Object.create(null);for(let t in r)e[Ba(t)]=r[t];return e}function fr(r,e,t=!0){return e.altKey&&(r="Alt-"+r),e.ctrlKey&&(r="Ctrl-"+r),e.metaKey&&(r="Meta-"+r),t&&e.shiftKey&&(r="Shift-"+r),r}function hr(r){return new He({props:{handleKeyDown:za(r)}})}function za(r){let e=Pa(r);return function(t,n){let i=Cr(n),s,o=e[fr(i,n)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(n.shiftKey){let l=e[fr(i,n,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((n.shiftKey||n.altKey||n.metaKey||i.charCodeAt(0)>127)&&(s=Mr[n.keyCode])&&s!=i){let l=e[fr(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var on=200,P=function(){};P.prototype.append=function(e){return e.length?(e=P.from(e),!this.length&&e||e.length<on&&this.leafAppend(e)||this.length<on&&e.leafPrepend(this)||this.appendInner(e)):this};P.prototype.prepend=function(e){return e.length?P.from(e).append(this):this};P.prototype.appendInner=function(e){return new va(this,e)};P.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?P.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};P.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};P.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)};P.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,n),i};P.from=function(e){return e instanceof P?e:e&&e.length?new Vs(e):P.empty};var Vs=(function(r){function e(n){r.call(this),this.values=n}r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a<o;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,s,o,l){for(var a=s-1;a>=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=on)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=on)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(P);P.empty=new Vs([]);var va=(function(r){function e(t,n){r.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},e.prototype.forEachInner=function(n,i,s,o){var l=this.left.length;if(i<l&&this.left.forEachInner(n,i,Math.min(s,l),o)===!1||s>l&&this.right.forEachInner(n,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(n,i-l,Math.max(s,l)-l,o+l)===!1||s<l&&this.left.forEachInvertedInner(n,Math.min(i,l),s,o)===!1)return!1},e.prototype.sliceInner=function(n,i){if(n==0&&i==this.length)return this;var s=this.left.length;return i<=s?this.left.slice(n,i):n>=s?this.right.slice(n-s,i-s):this.left.slice(n,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e})(P),ur=P;var Fa=500,ze=class r{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,s;t&&(i=this.remapping(n,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],f=[];return this.items.forEach((h,d)=>{if(!h.step){i||(i=this.remapping(n,d+1),s=i.maps.length),s--,f.push(h);return}if(i){f.push(new te(h.map));let p=h.step.map(i.slice(s)),u;p&&o.maybeStep(p).doc&&(u=o.mapping.maps[o.mapping.maps.length-1],c.push(new te(u,void 0,void 0,c.length+f.length))),s--,u&&i.appendMap(u,s)}else o.maybeStep(h.step);if(h.selection)return l=i?h.selection.map(i.slice(s)):h.selection,a=new r(this.items.slice(0,n).append(f.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,n,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let f=0;f<e.steps.length;f++){let h=e.steps[f].invert(e.docs[f]),d=new te(e.mapping.maps[f],h,t),p;(p=a&&a.merge(d))&&(d=p,f?s.pop():l=l.slice(0,l.length-1)),s.push(d),t&&(o++,t=void 0),i||(a=d)}let c=o-n.depth;return c>La&&(l=Va(l,c),o-=c),new r(l.append(s),o)}remapping(e,t){let n=new at;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?n.maps.length-i.mirrorOffset:void 0;n.appendMap(i.map,o)},e,t),n}addMaps(e){return this.eventCount==0?this:new r(this.items.append(e.map(t=>new te(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let p=s.getMirror(--a);if(p==null)return;o=Math.min(o,p);let u=s.maps[p];if(d.step){let m=e.steps[p].invert(e.docs[p]),g=d.selection&&d.selection.map(s.slice(a+1,p));g&&l++,n.push(new te(u,m,g))}else n.push(new te(u))},i);let c=[];for(let d=t;d<o;d++)c.push(new te(s.maps[d]));let f=this.items.slice(0,i).append(c).append(n),h=new r(f,l);return h.emptyItemCount()>Fa&&(h=h.compress(this.items.length-n.length)),h}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(n)),c=a&&a.getMap();if(n--,c&&t.appendMap(c,n),a){let f=o.selection&&o.selection.map(t.slice(n));f&&s++;let h=new te(c.invert(),a,f),d,p=i.length-1;(d=i.length&&i[p].merge(h))?i[p]=d:i.push(h)}}else o.map&&n--},this.items.length,0),new r(ur.from(i.reverse()),s)}};ze.empty=new ze(ur.empty,0);function Va(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}var te=class r{constructor(e,t,n,i){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new r(t.getMap().invert(),t,this.selection)}}},ne=class{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}},La=20;function Wa(r,e,t,n){let i=t.getMeta(Pe),s;if(i)return i.historyState;t.getMeta(Js)&&(r=new ne(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(Pe))return o.getMeta(Pe).redo?new ne(r.done.addTransform(t,void 0,n,ln(e)),r.undone,Ls(t.mapping.maps),r.prevTime,r.prevComposition):new ne(r.done,r.undone.addTransform(t,void 0,n,ln(e)),null,r.prevTime,r.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=r.prevTime==0||!o&&r.prevComposition!=l&&(r.prevTime<(t.time||0)-n.newGroupDelay||!Ja(t,r.prevRanges)),c=o?dr(r.prevRanges,t.mapping):Ls(t.mapping.maps);return new ne(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,ln(e)),ze.empty,c,t.time,l??r.prevComposition)}else return(s=t.getMeta("rebased"))?new ne(r.done.rebased(t,s),r.undone.rebased(t,s),dr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new ne(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),dr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function Ja(r,e){if(!e)return!1;if(!r.docChanged)return!0;let t=!1;return r.mapping.maps[0].forEach((n,i)=>{for(let s=0;s<e.length;s+=2)n<=e[s+1]&&i>=e[s]&&(t=!0)}),t}function Ls(r){let e=[];for(let t=r.length-1;t>=0&&e.length==0;t--)r[t].forEach((n,i,s,o)=>e.push(s,o));return e}function dr(r,e){if(!r)return null;let t=[];for(let n=0;n<r.length;n+=2){let i=e.map(r[n],1),s=e.map(r[n+1],-1);i<=s&&t.push(i,s)}return t}function qa(r,e,t){let n=ln(e),i=Pe.get(e).spec.config,s=(t?r.undone:r.done).popEvent(e,n);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?r.done:r.undone).addTransform(s.transform,e.selection.getBookmark(),i,n),a=new ne(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Pe,{redo:t,historyState:a})}var pr=!1,Ws=null;function ln(r){let e=r.plugins;if(Ws!=e){pr=!1,Ws=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){pr=!0;break}}return pr}function mr(r){return r.setMeta(Js,!0)}var Pe=new pt("history"),Js=new pt("closeHistory");function qs(r={}){return r={depth:r.depth||100,newGroupDelay:r.newGroupDelay||500},new He({key:Pe,state:{init(){return new ne(ze.empty,ze.empty,null,0,-1)},apply(e,t,n){return Wa(t,n,e,r)}},config:r,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,i=n=="historyUndo"?Ze:n=="historyRedo"?ve:null;return i?(t.preventDefault(),i(e.state,e.dispatch)):!1}}}})}function an(r,e){return(t,n)=>{let i=Pe.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let s=qa(i,t,r);s&&n(e?s.scrollIntoView():s)}return!0}}var Ze=an(!1,!0),ve=an(!0,!0),xc=an(!1,!1),Sc=an(!0,!1);var Qe=new Le({nodes:{doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return["p",0]}},blockquote:{content:"block+",group:"block",parseDOM:[{tag:"blockquote"}],toDOM(){return["blockquote",0]}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return["div",["hr"]]}},heading:{attrs:{level:{default:1}},content:"(text | image)*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(r){return["h"+r.attrs.level,0]}},code_block:{content:"text*",group:"block",code:!0,defining:!0,marks:"",attrs:{params:{default:""}},parseDOM:[{tag:"pre",preserveWhitespace:"full",getAttrs:r=>({params:r.getAttribute("data-params")||""})}],toDOM(r){return["pre",r.attrs.params?{"data-params":r.attrs.params}:{},["code",0]]}},ordered_list:{content:"list_item+",group:"block",attrs:{order:{default:1},tight:{default:!1}},parseDOM:[{tag:"ol",getAttrs(r){return{order:r.hasAttribute("start")?+r.getAttribute("start"):1,tight:r.hasAttribute("data-tight")}}}],toDOM(r){return["ol",{start:r.attrs.order==1?null:r.attrs.order,"data-tight":r.attrs.tight?"true":null},0]}},bullet_list:{content:"list_item+",group:"block",attrs:{tight:{default:!1}},parseDOM:[{tag:"ul",getAttrs:r=>({tight:r.hasAttribute("data-tight")})}],toDOM(r){return["ul",{"data-tight":r.attrs.tight?"true":null},0]}},list_item:{content:"block+",defining:!0,parseDOM:[{tag:"li"}],toDOM(){return["li",0]}},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(r){return{src:r.getAttribute("src"),title:r.getAttribute("title"),alt:r.getAttribute("alt")}}}],toDOM(r){return["img",r.attrs]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return["br"]}}},marks:{em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:r=>r.type.name=="em"}],toDOM(){return["em"]}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:r=>r.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:r=>r.type.name=="strong"},{style:"font-weight",getAttrs:r=>/^(bold(er)?|[5-9]\d{2,})$/.test(r)&&null}],toDOM(){return["strong"]}},link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(r){return{href:r.getAttribute("href"),title:r.getAttribute("title")}}}],toDOM(r){return["a",r.attrs]}},code:{parseDOM:[{tag:"code"}],toDOM(){return["code"]}}}});function $a(r,e){if(r.isText&&e.isText&&C.sameSet(r.marks,e.marks))return r.withText(r.text+e.text)}var kr=class{constructor(e,t){this.schema=e,this.tokenHandlers=t,this.stack=[{type:e.topNodeType,attrs:null,content:[],marks:C.none}]}top(){return this.stack[this.stack.length-1]}push(e){this.stack.length&&this.top().content.push(e)}addText(e){if(!e)return;let t=this.top(),n=t.content,i=n[n.length-1],s=this.schema.text(e,t.marks),o;i&&(o=$a(i,s))?n[n.length-1]=o:n.push(s)}openMark(e){let t=this.top();t.marks=e.addToSet(t.marks)}closeMark(e){let t=this.top();t.marks=e.removeFromSet(t.marks)}parseTokens(e){for(let t=0;t<e.length;t++){let n=e[t],i=this.tokenHandlers[n.type];if(!i)throw new Error("Token type `"+n.type+"` not supported by Markdown parser");i(this,n,e,t)}}addNode(e,t,n){let i=this.top(),s=e.createAndFill(t,n,i?i.marks:[]);return s?(this.push(s),s):null}openNode(e,t){this.stack.push({type:e,attrs:t,content:[],marks:C.none})}closeNode(){let e=this.stack.pop();return this.addNode(e.type,e.attrs,e.content)}};function Nt(r,e,t,n){return r.getAttrs?r.getAttrs(e,t,n):r.attrs instanceof Function?r.attrs(e):r.attrs}function gr(r,e){return r.noCloseToken||e=="code_inline"||e=="code_block"||e=="fence"}function $s(r){return r[r.length-1]==`
11
- `?r.slice(0,r.length-1):r}function yr(){}function Ka(r,e){let t=Object.create(null);for(let n in e){let i=e[n];if(i.block){let s=r.nodeType(i.block);gr(i,n)?t[n]=(o,l,a,c)=>{o.openNode(s,Nt(i,l,a,c)),o.addText($s(l.content)),o.closeNode()}:(t[n+"_open"]=(o,l,a,c)=>o.openNode(s,Nt(i,l,a,c)),t[n+"_close"]=o=>o.closeNode())}else if(i.node){let s=r.nodeType(i.node);t[n]=(o,l,a,c)=>o.addNode(s,Nt(i,l,a,c))}else if(i.mark){let s=r.marks[i.mark];gr(i,n)?t[n]=(o,l,a,c)=>{o.openMark(s.create(Nt(i,l,a,c))),o.addText($s(l.content)),o.closeMark(s)}:(t[n+"_open"]=(o,l,a,c)=>o.openMark(s.create(Nt(i,l,a,c))),t[n+"_close"]=o=>o.closeMark(s))}else if(i.ignore)gr(i,n)?t[n]=yr:(t[n+"_open"]=yr,t[n+"_close"]=yr);else throw new RangeError("Unrecognized parsing spec "+JSON.stringify(i))}return t.text=(n,i)=>n.addText(i.content),t.inline=(n,i)=>n.parseTokens(i.children),t.softbreak=t.softbreak||(n=>n.addText(" ")),t}var Dt=class{constructor(e,t,n){this.schema=e,this.tokenizer=t,this.tokens=n,this.tokenHandlers=Ka(e,n)}parse(e,t={}){let n=new kr(this.schema,this.tokenHandlers),i;n.parseTokens(this.tokenizer.parse(e,t));do i=n.closeNode();while(n.stack.length);return i||this.schema.topNodeType.createAndFill()}};function Ks(r,e){for(;++e<r.length;)if(r[e].type!="list_item_open")return r[e].hidden;return!1}var xr=new Dt(Qe,wr("commonmark",{html:!1}),{blockquote:{block:"blockquote"},paragraph:{block:"paragraph"},list_item:{block:"list_item"},bullet_list:{block:"bullet_list",getAttrs:(r,e,t)=>({tight:Ks(e,t)})},ordered_list:{block:"ordered_list",getAttrs:(r,e,t)=>({order:+r.attrGet("start")||1,tight:Ks(e,t)})},heading:{block:"heading",getAttrs:r=>({level:+r.tag.slice(1)})},code_block:{block:"code_block",noCloseToken:!0},fence:{block:"code_block",getAttrs:r=>({params:r.info||""}),noCloseToken:!0},hr:{node:"horizontal_rule"},image:{node:"image",getAttrs:r=>({src:r.attrGet("src"),title:r.attrGet("title")||null,alt:r.children[0]&&r.children[0].content||null})},hardbreak:{node:"hard_break"},em:{mark:"em"},strong:{mark:"strong"},link:{mark:"link",getAttrs:r=>({href:r.attrGet("href"),title:r.attrGet("title")||null})},code_inline:{mark:"code",noCloseToken:!0}}),Ha={open:"",close:"",mixable:!0},Tt=class{constructor(e,t,n={}){this.nodes=e,this.marks=t,this.options=n}serialize(e,t={}){t=Object.assign({},this.options,t);let n=new br(this.nodes,this.marks,t);return n.renderContent(e),n.out}},Sr=new Tt({blockquote(r,e){r.wrapBlock("> ",null,e,()=>r.renderContent(e))},code_block(r,e){let t=e.textContent.match(/`{3,}/gm),n=t?t.sort().slice(-1)[0]+"`":"```";r.write(n+(e.attrs.params||"")+`
8
+ `);return{dom:a,text:d,slice:e}}function ds(r,e,t,n,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=!!e&&(n||s||!t);if(a){if(r.someProp("transformPastedText",d=>{e=d(e,s||n,r)}),s)return l=new b(k.from(r.state.schema.text(e.replace(/\r\n?/g,`
9
+ `))),0,0),r.someProp("transformPasted",d=>{l=d(l,r,!0)}),l;let h=r.someProp("clipboardTextParser",d=>d(e,i,n,r));if(h)l=h;else{let d=i.marks(),{schema:p}=r.state,u=Se.fromSchema(p);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(u.serializeNode(p.text(m,d)))})}}else r.someProp("transformPastedHTML",h=>{t=h(t,r)}),o=Ol(t),sn&&Nl(o);let c=o&&o.querySelector("[data-pm-slice]"),f=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let h=+f[3];h>0;h--){let d=o.firstChild;for(;d&&!x(d);)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||rt.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Ml.test(d.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Dl(Li(l,+f[1],+f[2]),f[4]);else if(l=b.maxOpen(Cl(l.content,i),!0),l.openStart||l.openEnd){let h=0,d=0;for(let p=l.content.firstChild;h<l.openStart&&!p.type.spec.isolating;h++,p=p.firstChild);for(let p=l.content.lastChild;d<l.openEnd&&!p.type.spec.isolating;d++,p=p.lastChild);l=Li(l,h,d)}return r.someProp("transformPasted",h=>{l=h(l,r,a)}),l}var Ml=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Cl(r,e){if(r.childCount<2)return r;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(r.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&ms(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=gs(o[o.length-1],s.length));let f=ps(l,a);o.push(f),i=i.matchType(f.type),s=a}}),o)return k.from(o)}return r}function ps(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,k.from(r));return r}function ms(r,e,t,n,i){if(i<r.length&&i<e.length&&r[i]==e[i]){let s=ms(r,e,t,n.lastChild,i+1);if(s)return n.copy(n.content.replaceChild(n.childCount-1,s));if(n.contentMatchAt(n.childCount).matchType(i==r.length-1?t.type:r[i+1]))return n.copy(n.content.append(k.from(ps(t,r,i+1))))}}function gs(r,e){if(e==0)return r;let t=r.content.replaceChild(r.childCount-1,gs(r.lastChild,e-1)),n=r.contentMatchAt(r.childCount).fillBefore(k.empty,!0);return r.copy(t.append(n))}function Hn(r,e,t,n,i,s){let o=e<0?r.firstChild:r.lastChild,l=o.content;return r.childCount>1&&(s=0),i<n-1&&(l=Hn(l,e,t,n,i+1,s)),i>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(k.empty,!0))),r.replaceChild(e<0?0:r.childCount-1,o.copy(l))}function Li(r,e,t){return e<r.openStart&&(r=new b(Hn(r.content,-1,e,r.openStart,0,r.openEnd),e,r.openEnd)),t<r.openEnd&&(r=new b(Hn(r.content,1,t,r.openEnd,0,0),r.openStart,t)),r}var ys={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function ks(){return document.implementation.createHTMLDocument("title")}var gt=null;function wl(r){let e=window.trustedTypes;if(!e)return r;if(!gt){if(gt=e.defaultPolicy)try{return gt.createHTML(r)}catch{}gt=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})}return gt.createHTML(r)}function Ol(r){let e=/^(\s*<meta [^>]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=ks(),n=t.body,i=/<([a-z][^>\s]+)/i.exec(r),s;if((s=i&&ys[i[1].toLowerCase()])&&(r=s.map(o=>"<"+o+">").join("")+r+s.map(o=>"</"+o+">").reverse().join("")),n.innerHTML=wl(r),s)for(let o=0;o<s.length;o++)n=n.querySelector(s[o])||n;for(let o=0;o<t.styleSheets.length;o++){let l=t.styleSheets[o];for(let a=0;a<l.rules.length;a++){let c=l.rules[a];if(c instanceof CSSStyleRule){let f=n.querySelectorAll(c.selectorText);for(let h=0;h<f.length;h++)f[h].style.cssText+=c.style.cssText}}}return n}function Nl(r){let e=r.querySelectorAll(B?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let n=e[t];n.childNodes.length==1&&n.textContent=="\xA0"&&n.parentNode&&n.parentNode.replaceChild(r.ownerDocument.createTextNode(" "),n)}}function Dl(r,e){if(!r.size)return r;let t=r.content.firstChild.type.schema,n;try{n=JSON.parse(e)}catch{return r}let{content:i,openStart:s,openEnd:o}=r;for(let l=n.length-2;l>=0;l-=2){let a=t.nodes[n[l]];if(!a||a.hasRequiredAttrs())break;try{i=k.from(a.create(n[l+1],i))}catch{break}s++,o++}return new b(i,s,o)}var W={},J={},Tl={touchstart:!0,touchmove:!0},_n=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function El(r){for(let e in W){let t=W[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Il(r,n)&&!rr(r,n)&&(r.editable||!(n.type in J))&&t(r,n)},Tl[e]?{passive:!0}:void 0)}V&&r.dom.addEventListener("input",()=>null),jn(r)}function le(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function Al(r){r.input.mouseDown&&r.input.mouseDown.done(),r.domObserver.stop();for(let e in r.input.eventHandlers)r.dom.removeEventListener(e,r.input.eventHandlers[e]);clearTimeout(r.input.composingTimeout),clearTimeout(r.input.lastIOSEnterFallbackTimeout)}function jn(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>rr(r,n))})}function rr(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Il(r,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=r.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Rl(r,e){!rr(r,e)&&W[e.type]&&(r.editable||!(e.type in J))&&W[e.type](r,e)}J.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!Ss(r)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(oe&&B&&t.keyCode==13)))if(t.keyCode!=229&&r.domObserver.forceFlush(),Ye&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let n=Date.now();r.input.lastIOSEnter=n,r.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{r.input.lastIOSEnter==n&&(r.someProp("handleKeyDown",i=>i(r,Ce(13,"Enter"))),r.input.lastIOSEnter=0)},200)}else r.someProp("handleKeyDown",n=>n(r,t))||Sl(r,t)?t.preventDefault():le(r,"key")};J.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)};J.keypress=(r,e)=>{let t=e;if(Ss(r)||!t.charCode||t.ctrlKey&&!t.altKey||U&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof D)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode),s=()=>r.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",o=>o(r,n.$from.pos,n.$to.pos,i,s))&&r.dispatch(s()),t.preventDefault()}};function wt(r){return{left:r.clientX,top:r.clientY}}function Bl(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function ir(r,e,t,n,i){if(n==-1)return!1;let s=r.state.doc.resolve(n);for(let o=s.depth+1;o>0;o--)if(r.someProp(e,l=>o>s.depth?l(r,t,s.nodeAfter,s.before(o),i,!0):l(r,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function Ot(r,e,t){if(r.focused||r.focus(),r.state.selection.eq(e))return;let n=r.state.tr.setSelection(e);n.setMeta("pointer",!0),r.dispatch(n)}function Pl(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&S.isSelectable(n)?(Ot(r,new S(t)),!0):!1}function zl(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof S&&(n=t.node);let s=r.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(S.isSelectable(l)){n&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(Ot(r,S.create(r.state.doc,i)),!0):!1}function vl(r,e,t,n,i){return ir(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?zl(r,t):Pl(r,t))}function Fl(r,e,t,n){return ir(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function Vl(r,e,t,n){return ir(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||Ll(r,t,n)}function Ll(r,e,t){if(t.button!=0)return!1;let n=bs(r,e,!0),i=r.state.doc;return n?(Ot(r,n),n instanceof D&&i.eq(r.state.doc)&&(r.input.mouseDown=new Gn(r,n)),!0):!1}function bs(r,e,t){let n=r.state.doc;if(e==-1)return n.inlineContent?D.create(n,0,n.content.size):null;let i=n.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)return D.create(n,l+1,l+1+o.content.size);if(t&&S.isSelectable(o))return S.create(n,l)}return null}function sr(r){return Zt(r)}var xs=U?"metaKey":"ctrlKey";W.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=sr(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&Bl(t,r.input.lastClick)&&!t[xs]&&r.input.lastClick.button==t.button&&(r.input.lastClick.type=="singleClick"?s="doubleClick":r.input.lastClick.type=="doubleClick"&&(s="tripleClick")),r.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s,button:t.button},r.input.mouseDown&&r.input.mouseDown.done();let o=r.posAtCoords(wt(t));o&&(s=="singleClick"?r.input.mouseDown=new Un(r,o,t,!!n):(s=="doubleClick"?Fl:Vl)(r,o.pos,o.inside,t)?t.preventDefault():le(r,"pointer"))};var Xt=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},Un=class extends Xt{constructor(e,t,n,i){super(e),this.pos=t,this.event=n,this.flushed=i,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[xs],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let f=e.state.doc.resolve(t.pos);s=f.parent,o=f.depth?f.before():0}let l=i?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&x(a.nodeDOM)?a.nodeDOM:null;let{selection:c}=e.state;n.button==0&&(s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof S&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&j&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),le(e,"pointer")}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||ae(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(wt(e))),this.updateAllowDefault(e),this.allowDefault||!t?le(this.view,"pointer"):vl(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||V&&this.mightDrag&&!this.mightDrag.node.isAtom||B&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Ot(this.view,N.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):le(this.view,"pointer")}move(e){this.updateAllowDefault(e),le(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},Gn=class extends Xt{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),le(this.view,"pointer");let t=this.view.posAtCoords(wt(e)),n=t&&bs(this.view,t.inside,!1);if(!n)return;let{doc:i}=this.view.state,s=this.startSelection,[o,l]=n.from<s.from?[s.to,n.from]:[s.from,n.to];Ot(this.view,D.create(i,o,l))}};W.touchstart=r=>{r.input.lastTouch=Date.now(),sr(r),le(r,"pointer")};W.touchmove=r=>{r.input.lastTouch=Date.now(),le(r,"pointer")};W.contextmenu=r=>sr(r);function Ss(r,e){return r.composing?!0:V&&Math.abs(Date.now()-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}var Wl=oe?5e3:-1;J.compositionstart=J.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$to;if(e.selection instanceof D&&e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)||B&&Zi&&Jl(r)))r.markCursor=r.state.storedMarks||t.marks(),Zt(r,!0),r.markCursor=null;else if(Zt(r,!e.selection.empty),j&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let n=r.domSelectionRange();for(let i=n.focusNode,s=n.focusOffset;i&&x(i)&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(E(o)){let l=r.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}r.input.composing=!0}Ms(r,Wl)};function Jl(r){let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(!e||!x(e)||t>=e.childNodes.length)return!1;let n=e.childNodes[t];return x(n)&&n.contentEditable=="false"}J.compositionend=(r,e)=>{r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Date.now(),r.input.compositionPendingChanges=r.domObserver.pendingRecords().length?r.input.compositionID:0,r.input.compositionNode=null,r.input.badSafariComposition?r.domObserver.forceFlush():r.input.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,Ms(r,20))};function Ms(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>Zt(r),e))}function Cs(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Date.now());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function ql(r){let e=r.domSelectionRange();if(!e.focusNode)return null;let t=Lo(e.focusNode,e.focusOffset),n=Wo(e.focusNode,e.focusOffset);if(t&&n&&t!=n){let i=n.pmViewDesc,s=r.domObserver.lastChangedTextNode;if(t==s||n==s)return s;if(!i||!i.isText(n.nodeValue))return n;if(r.input.compositionNode==n){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return n}}return t||n}function Zt(r,e=!1){if(!(oe&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),Cs(r),e||r.docView&&r.docView.dirty){let t=er(r),n=r.state.selection;return t&&!t.eq(n)?r.dispatch(r.state.tr.setSelection(t)):(r.markCursor||e)&&!n.$from.node(n.$from.sharedDepth(n.to)).inlineContent?r.dispatch(r.state.tr.deleteSelection()):r.updateState(r.state),!0}return!1}}function $l(r,e){if(!r.dom.parentNode)return;let t=r.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),i=document.createRange();i.selectNodeContents(e),r.dom.blur(),n.removeAllRanges(),n.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),r.focus()},50)}var bt=K&&pe<15||Ye&&Ko<604;W.copy=J.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=bt?null:t.clipboardData,o=n.content(),{dom:l,text:a}=nr(r,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):$l(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Kl(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function Hl(r,e){if(!r.dom.parentNode)return;let t=r.input.shiftKey||r.state.selection.$from.parent.type.spec.code,n=r.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let i=r.input.shiftKey&&r.input.lastKeyCode!=45;setTimeout(()=>{r.focus(),n.parentNode&&n.parentNode.removeChild(n),t?xt(r,n.value,null,i,e):xt(r,n.textContent,n.innerHTML,i,e)},50)}function xt(r,e,t,n,i){let s=ds(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||b.empty)))return!0;if(!s)return!1;let o=Kl(s),l=o?r.state.tr.replaceSelectionWith(o,n):r.state.tr.replaceSelection(s);return r.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ws(r){let e=r.getData("text/plain")||r.getData("Text");if(e)return e;let t=r.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}J.paste=(r,e)=>{let t=e;if(r.composing&&!oe)return;let n=bt?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&xt(r,ws(n),n.getData("text/html"),i,t)?t.preventDefault():Hl(r,t)};var Qt=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},_l=U?"altKey":"ctrlKey";function Os(r,e){let t;return r.someProp("dragCopies",n=>{t=t||n(e)}),t!=null?!t:!e[_l]}W.dragstart=(r,e)=>{let t=e,n=r.input.mouseDown;if(n&&n.done(),!t.dataTransfer)return;let i=r.state.selection,s=i.empty?null:r.posAtCoords(wt(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof S?i.to-1:i.to))){if(n&&n.mightDrag)o=S.create(r.state.doc,n.mightDrag.pos);else if(t.target&&x(t.target)){let h=r.docView.nearestDesc(t.target,!0);h&&h.node.type.spec.draggable&&h!=r.docView&&(o=S.create(r.state.doc,h.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:c,slice:f}=nr(r,l);(!t.dataTransfer.files.length||!B||Xi>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(bt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",bt||t.dataTransfer.setData("text/plain",c),r.dragging=new Qt(f,Os(r,t),o)};W.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)};J.dragover=J.dragenter=(r,e)=>e.preventDefault();J.drop=(r,e)=>{try{jl(r,e,r.dragging)}finally{r.dragging=null}};function jl(r,e,t){if(!e.dataTransfer)return;let n=r.posAtCoords(wt(e));if(!n)return;let i=r.state.doc.resolve(n.pos),s=t&&t.slice;s?r.someProp("transformPasted",p=>{s=p(s,r,!1)}):s=ds(r,ws(e.dataTransfer),bt?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(t&&Os(r,e));if(r.someProp("handleDrop",p=>p(r,e,s||b.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?li(r.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let a=r.state.tr;if(o){let{node:p}=t;p?p.replace(a):a.deleteSelection()}let c=a.mapping.map(l),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,h=a.doc;if(f?a.replaceRangeWith(c,c,s.content.firstChild):a.replaceRange(c,c,s),a.doc.eq(h))return;let d=a.doc.resolve(c);if(f&&S.isSelectable(s.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new S(d));else{let p=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((u,m,g,y)=>p=y),a.setSelection(tr(r,d,a.doc.resolve(p)))}r.focus(),r.dispatch(a.setMeta("uiEvent","drop"))}W.focus=r=>{r.input.lastFocus=Date.now(),r.focused||(r.domObserver.stop(),r.dom.classList.add("ProseMirror-focused"),r.domObserver.start(),r.focused=!0,setTimeout(()=>{r.docView&&r.hasFocus()&&!r.domObserver.currentSelection.eq(r.domSelectionRange())&&ae(r)},20))};W.blur=(r,e)=>{let t=e;r.focused&&(r.domObserver.stop(),r.dom.classList.remove("ProseMirror-focused"),r.domObserver.start(),t.relatedTarget&&r.dom.contains(t.relatedTarget)&&r.domObserver.currentSelection.clear(),r.focused=!1)};W.beforeinput=(r,e)=>{if(oe&&e.inputType=="deleteContentBackward"){r.domObserver.flushSoon();let{domChangeCount:n}=r.input;setTimeout(()=>{if(r.input.domChangeCount!=n||(r.dom.blur(),r.focus(),r.someProp("handleKeyDown",s=>s(r,Ce(8,"Backspace")))))return;let{$cursor:i}=r.state.selection;i&&i.pos>0&&r.dispatch(r.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let r in J)W[r]=J[r];function St(r,e){if(r==e)return!0;for(let t in r)if(r[t]!==e[t])return!1;for(let t in e)if(!(t in r))return!1;return!0}var en=class r{constructor(e,t){this.toDOM=e,this.spec=t||Te,this.side=this.spec.side||0}map(e,t,n,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ge(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof r&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&St(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},De=class r{constructor(e,t){this.attrs=e,this.spec=t||Te}map(e,t,n,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-n;return s>=o?null:new ge(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof r&&St(this.attrs,e.attrs)&&St(this.spec,e.spec)}static is(e){return e.type instanceof r}destroy(){}},Yn=class r{constructor(e,t){this.attrs=e,this.spec=t||Te}map(e,t,n,i){let s=e.mapResult(t.from+i,1);if(s.deleted)return null;let o=e.mapResult(t.to+i,-1);return o.deleted||o.pos<=s.pos?null:new ge(s.pos-n,o.pos-n,this)}valid(e,t){let{index:n,offset:i}=e.content.findIndex(t.from),s;return i==t.from&&!(s=e.child(n)).isText&&i+s.nodeSize==t.to}eq(e){return this==e||e instanceof r&&St(this.attrs,e.attrs)&&St(this.spec,e.spec)}destroy(){}},ge=class r{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new r(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new r(e,e,new en(t,n))}static inline(e,t,n,i){return new r(e,t,new De(n,i))}static node(e,t,n,i){return new r(e,t,new Yn(n,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof De}get widget(){return this.type instanceof en}},Ue=[],Te={},Y=class r{constructor(e,t){this.local=e.length?e:Ue,this.children=t.length?t:Ue}static create(e,t){return t.length?nn(t,e,0,Te):v}find(e,t,n){let i=[];return this.findInner(e??0,t??1e9,i,0,n),i}findInner(e,t,n,i,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&n.push(l.copy(l.from+i,l.to+i))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,n,i+l,s)}}map(e,t,n){return this==v||e.maps.length==0?this:this.mapInner(e,t,0,0,n||Te)}mapInner(e,t,n,i,s){let o;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,n,i);a&&a.type.valid(t,a)?(o||(o=[])).push(a):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?Ul(this.children,o||[],e,t,n,i,s):o?new r(o.sort(Ee),Ue):v}add(e,t){return t.length?this==v?r.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let i,s=0;e.forEach((l,a)=>{let c=a+n,f;if(f=Ds(t,l,c)){for(i||(i=this.children.slice());s<i.length&&i[s]<a;)s+=3;i[s]==a?i[s+2]=i[s+2].addInner(l,f,c+1):i.splice(s,0,a,a+l.nodeSize,nn(f,l,c+1,Te)),s+=3}});let o=Ns(s?Ts(t):t,-n);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new r(o.length?this.local.concat(o).sort(Ee):this.local,i||this.children)}remove(e){return e.length==0||this==v?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,i=this.local;for(let s=0;s<n.length;s+=3){let o,l=n[s]+t,a=n[s+1]+t;for(let f=0,h;f<e.length;f++)(h=e[f])&&h.from>l&&h.to<a&&(e[f]=null,(o||(o=[])).push(h));if(!o)continue;n==this.children&&(n=this.children.slice());let c=n[s+2].removeInner(o,l+1);c!=v?n[s+2]=c:(n.splice(s,3),s-=3)}if(i.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<i.length;l++)i[l].eq(o,t)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return n==this.children&&i==this.local?this:i.length||n.length?new r(i,n):v}forChild(e,t){if(this==v)return this;if(t.isLeaf)return r.empty;let n,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(n=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<o&&a.to>s&&a.type instanceof De){let c=Math.max(s,a.from)-s,f=Math.min(o,a.to)-s;c<f&&(i||(i=[])).push(a.copy(c,f))}}if(i){let l=new r(i.sort(Ee),Ue);return n?new tn([l,n]):l}return n||v}eq(e){if(this==e)return!0;if(!(e instanceof r)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return or(this.localsInner(e))}localsInner(e){if(this==v)return Ue;if(e.inlineContent||!this.local.some(De.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof De||t.push(this.local[n]);return t}forEachSet(e){e(this)}};Y.empty=new Y([],[]);Y.removeOverlap=or;var v=Y.empty,tn=class r{constructor(e){this.members=e}map(e,t){let n=this.members.map(i=>i.map(e,t,Te));return r.from(n)}forChild(e,t){if(t.isLeaf)return Y.empty;let n=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=v&&(s instanceof r?n=n.concat(s.members):n.push(s))}return r.from(n)}eq(e){if(!(e instanceof r)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let i=0;i<this.members.length;i++){let s=this.members[i].localsInner(e);if(s.length)if(!t)t=s;else{n&&(t=t.slice(),n=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?or(n?t:t.sort(Ee)):Ue}static from(e){switch(e.length){case 0:return v;case 1:return e[0];default:return new r(e.every(t=>t instanceof Y)?e:e.reduce((t,n)=>t.concat(n instanceof Y?n:n.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function Ul(r,e,t,n,i,s,o){let l=r.slice();for(let c=0,f=s;c<t.maps.length;c++){let h=0;t.maps[c].forEach((d,p,u,m)=>{let g=m-u-(p-d);for(let y=0;y<l.length;y+=3){let M=l[y+1];if(M<0||d>M+f-h)continue;let O=l[y]+f-h;p>=O?l[y+1]=d<=O?-2:-1:d>=f&&g&&(l[y]+=g,l[y+1]+=g)}h+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let f=t.map(r[c]+s),h=f-i;if(h<0||h>=n.content.size){a=!0;continue}let d=t.map(r[c+1]+s,-1),p=d-i,{index:u,offset:m}=n.content.findIndex(h),g=n.maybeChild(u);if(g&&m==h&&m+g.nodeSize==p){let y=l[c+2].mapInner(t,g,f+1,r[c]+s+1,o);y!=v?(l[c]=h,l[c+1]=p,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=Gl(l,r,e,t,i,s,o),f=nn(c,n,0,o);e=f.local;for(let h=0;h<l.length;h+=3)l[h+1]<0&&(l.splice(h,3),h-=3);for(let h=0,d=0;h<f.children.length;h+=3){let p=f.children[h];for(;d<l.length&&l[d]<p;)d+=3;l.splice(d,0,f.children[h],f.children[h+1],f.children[h+2])}}return new Y(e.sort(Ee),l)}function Ns(r,e){if(!e||!r.length)return r;let t=[];for(let n=0;n<r.length;n++){let i=r[n];t.push(new ge(i.from+e,i.to+e,i.type))}return t}function Gl(r,e,t,n,i,s,o){function l(a,c){for(let f=0;f<a.local.length;f++){let h=a.local[f].map(n,i,c);h?t.push(h):o.onRemove&&o.onRemove(a.local[f].spec)}for(let f=0;f<a.children.length;f+=3)l(a.children[f+2],a.children[f]+c+1)}for(let a=0;a<r.length;a+=3)r[a+1]==-1&&l(r[a+2],e[a]+s+1);return t}function Ds(r,e,t){if(e.isLeaf)return null;let n=t+e.nodeSize,i=null;for(let s=0,o;s<r.length;s++)(o=r[s])&&o.from>t&&o.to<n&&((i||(i=[])).push(o),r[s]=null);return i}function Ts(r){let e=[];for(let t=0;t<r.length;t++)r[t]!=null&&e.push(r[t]);return e}function nn(r,e,t,n){let i=[],s=!1;e.forEach((l,a)=>{let c=Ds(r,l,a+t);if(c){s=!0;let f=nn(c,l,t+a+1,n);f!=v&&i.push(a,a+l.nodeSize,f)}});let o=Ns(s?Ts(r):r,-t).sort(Ee);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||(n.onRemove&&n.onRemove(o[l].spec),o.splice(l--,1));return o.length||i.length?new Y(o,i):v}function Ee(r,e){return r.from-e.from||r.to-e.to}function or(r){let e=r;for(let t=0;t<e.length-1;t++){let n=e[t];if(n.from!=n.to)for(let i=t+1;i<e.length;i++){let s=e[i];if(s.from==n.from){s.to!=n.to&&(e==r&&(e=r.slice()),e[i]=s.copy(s.from,n.to),Wi(e,i+1,s.copy(n.to,s.to)));continue}else{s.from<n.to&&(e==r&&(e=r.slice()),e[t]=n.copy(n.from,s.from),Wi(e,i,n.copy(s.from,n.to)));break}}}return e}function Wi(r,e,t){for(;e<r.length&&Ee(t,r[e])>0;)e++;r.splice(e,0,t)}function In(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=v&&e.push(n)}),r.cursorWrapper&&e.push(Y.create(r.state.doc,[r.cursorWrapper.deco])),tn.from(e)}var Yl={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Xl=K&&pe<=11,Xn=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},Zn=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Xn,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let i=0;i<n.length;i++)this.queue.push(n[i]);K&&pe<=11&&n.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():V&&e.composing&&n.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Xl&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Yl)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Bi(this.view)){if(this.suppressingSelectionUpdates)return ae(this.view);if(K&&pe<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ae(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let s=e.focusNode;s;s=Ge(s))t.add(s);for(let s=e.anchorNode;s;s=Ge(s))if(t.has(s)){n=s;break}let i=n&&this.view.docView.nearestDesc(n);if(i&&i.ignoreMutation({type:"selection",target:E(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Bi(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let f=0;f<t.length;f++){let h=this.registerMutation(t[f],a);h&&(s=s<0?h.from:Math.min(h.from,s),o=o<0?h.to:Math.max(h.to,o),h.typeOver&&(l=!0))}if(a.some(f=>f.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||B&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(f=>f.type=="childList"&&f.removedNodes.length))){for(let f of a)if(f.nodeName=="BR"&&f.parentNode){let h=f.nextSibling;for(;h&&x(h);){if(h.contentEditable=="false"){f.parentNode.removeChild(f);break}h=h.firstChild}}}else if(j&&a.length){let f=a.filter(h=>h.nodeName=="BR");if(f.length==2){let[h,d]=f;h.parentNode&&h.parentNode.parentNode==d.parentNode?d.remove():h.remove()}else{let{focusNode:h}=this.currentSelection;for(let d of f){let p=d.parentNode;p&&p.nodeName=="LI"&&(!h||ea(e,h)!=p)&&d.remove()}}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&rn(n)&&(c=er(e))&&c.eq(N.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ae(e),this.currentSelection.set(n),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),Zl(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,ta(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||ae(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(n==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if(e.type=="childList"){for(let f=0;f<e.addedNodes.length;f++){let h=e.addedNodes[f];t.push(h),E(h)&&(this.lastChangedTextNode=h)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let i=e.previousSibling,s=e.nextSibling;if(K&&pe<=11&&e.addedNodes.length)for(let f=0;f<e.addedNodes.length;f++){let{previousSibling:h,nextSibling:d}=e.addedNodes[f];(!h||Array.prototype.indexOf.call(e.addedNodes,h)<0)&&(i=h),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(s=d)}let o=i&&i.parentNode==e.target?R(i)+1:0,l=n.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?R(s):e.target.childNodes.length,c=n.localPosFromDOM(e.target,a,1);return{from:l,to:c}}else return e.type=="attributes"?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},Ji=new WeakMap,qi=!1;function Zl(r){if(!Ji.has(r)&&(Ji.set(r,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(r.dom).whiteSpace)!==-1)){if(r.requiresGeckoHackNode=j,qi)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),qi=!0}}function $i(r,e){let t=e.startContainer,n=e.startOffset,i=e.endContainer,s=e.endOffset,o=r.domAtPos(r.state.selection.anchor);return Ae(o.node,o.offset,i,s)&&([t,n,i,s]=[i,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:i,focusOffset:s}}function Ql(r,e){if(e.getComposedRanges){let i=e.getComposedRanges(r.root)[0];if(i)return $i(r,i)}let t;function n(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return r.dom.addEventListener("beforeinput",n,!0),document.execCommand("indent"),r.dom.removeEventListener("beforeinput",n,!0),t?$i(r,t):null}function ea(r,e){for(let t=e.parentNode;t&&t!=r.dom;t=t.parentNode){let n=r.docView.nearestDesc(t,!0);if(n&&n.node.isBlock)return t}return null}function ta(r,e){var t;let{focusNode:n,focusOffset:i}=r.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let o=s.nextSibling;for(;o&&o.nodeName!="TD"&&o.nodeName!="TH";)o=o.nextSibling;if(o){let l=o;for(;;){let a=l.firstChild;if(!a||!x(a)||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),n==s&&r.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}function na(r,e,t,n){let{node:i,fromOffset:s,toOffset:o,from:l,to:a}=r.docView.parseRange(e,t),c=r.domSelectionRange(),f,h=c.anchorNode;if(h&&Ie(r.dom,h)&&(f=[{node:h,offset:c.anchorOffset}],rn(c)||f.push({node:c.focusNode,offset:c.focusOffset})),B&&r.input.lastKeyCode===8)for(let y=o;y>s;y--){let M=i.childNodes[y-1],O=M.pmViewDesc;if(M.nodeName=="BR"&&!O){o=y;break}if(!O||O.size)break}let d=r.state.doc,p=r.someProp("domParser")||rt.fromSchema(r.state.schema),u=d.resolve(l),m=null,g=p.parse(i,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:s,to:o,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:f,ruleFromNode:ra(n),context:u});if(f&&f[0].pos!=null){let y=f[0].pos,M=f[1]&&f[1].pos;M==null&&(M=y),m={anchor:y+l,head:M+l}}return{doc:g,sel:m,from:l,to:a}}var ra=r=>e=>{let t=e.pmViewDesc;if(t)return t.parseRule(r);if(e.nodeName=="BR"&&e.parentNode){if(V&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(e.parentNode.lastChild==e||V&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName=="IMG"&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null},ia=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function sa(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let w=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,A=er(r,w);if(A&&!r.state.selection.eq(A)){if(B&&oe&&r.input.lastKeyCode===13&&Date.now()-100<r.input.lastKeyCodeTime&&r.someProp("handleKeyDown",js=>js(r,Ce(13,"Enter"))))return;let q=r.state.tr.setSelection(A);w=="pointer"?q.setMeta("pointer",!0):w=="key"&&q.scrollIntoView(),s&&q.setMeta("composition",s),r.dispatch(q)}return}let o=r.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=r.state.doc.resolve(t).after(l+1);let a=r.state.selection,c=na(r,e,t,i),f=r.state.doc,h=f.slice(c.from,c.to),d,p;r.input.lastKeyCode===8&&Date.now()-100<r.input.lastKeyCodeTime?(d=r.state.selection.to,p="end"):(d=r.state.selection.from,p="start"),r.input.lastKeyCode=null;let u=ca(h.content,c.doc.content,c.from,d,p);if(u&&r.input.domChangeCount++,(Ye&&r.input.lastIOSEnter>Date.now()-225||oe)&&i.some(w=>x(w)&&!ia.test(w.nodeName))&&(!u||u.endA>=u.endB)&&r.someProp("handleKeyDown",w=>w(r,Ce(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!u)if(n&&a instanceof D&&!a.empty&&a.$head.sameParent(a.$anchor)&&!r.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))u={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let w=Ki(r,r.state.doc,c.sel);if(w&&!w.eq(r.state.selection)){let A=r.state.tr.setSelection(w);s&&A.setMeta("composition",s),r.dispatch(A)}}return}r.state.selection.from<r.state.selection.to&&u.start==u.endB&&r.state.selection instanceof D&&(u.start>r.state.selection.from&&u.start<=r.state.selection.from+2&&r.state.selection.from>=c.from?u.start=r.state.selection.from:u.endA<r.state.selection.to&&u.endA>=r.state.selection.to-2&&r.state.selection.to<=c.to&&(u.endB+=r.state.selection.to-u.endA,u.endA=r.state.selection.to)),K&&pe<=11&&u.endB==u.start+1&&u.endA==u.start&&u.start>c.from&&c.doc.textBetween(u.start-c.from-1,u.start-c.from+1)==" \xA0"&&(u.start--,u.endA--,u.endB--);let m=c.doc.resolveNoCache(u.start-c.from),g=c.doc.resolveNoCache(u.endB-c.from),y=f.resolve(u.start),M=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=u.endA;if((Ye&&r.input.lastIOSEnter>Date.now()-225&&(!M||i.some(w=>w.nodeName=="DIV"||w.nodeName=="P"))||!M&&aa(c.doc,m.pos,g.pos))&&r.someProp("handleKeyDown",w=>w(r,Ce(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>u.start&&la(f,u.start,u.endA,m,g)&&r.someProp("handleKeyDown",w=>w(r,Ce(8,"Backspace")))){oe&&B&&r.domObserver.suppressSelectionUpdates();return}B&&u.endB==u.start&&(r.input.lastChromeDelete=Date.now()),oe&&!M&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==u.endA&&(u.endB-=2,g=c.doc.resolveNoCache(u.endB-c.from),setTimeout(()=>{r.someProp("handleKeyDown",function(w){return w(r,Ce(13,"Enter"))})},20));let O=u.start,L=u.endA,X=w=>{let A=w||r.state.tr.replace(O,L,c.doc.slice(u.start-c.from,u.endB-c.from));if(c.sel){let q=Ki(r,A.doc,c.sel);q&&!(B&&r.composing&&q.empty&&(u.start!=u.endB||r.input.lastChromeDelete<Date.now()-100)&&(q.head==O||q.head==A.mapping.map(L)-1)||K&&q.empty&&q.head==O)&&A.setSelection(q)}return s&&A.setMeta("composition",s),A.scrollIntoView()},fe;if(M)if(m.pos==g.pos){K&&pe<=11&&m.parentOffset==0&&(r.domObserver.suppressSelectionUpdates(),setTimeout(()=>ae(r),20));let w=X(r.state.tr.delete(O,L)),A=f.resolve(u.start).marksAcross(f.resolve(u.endA));A&&w.ensureMarks(A),r.dispatch(w)}else if(u.endA==u.endB&&(fe=oa(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,u.endA-y.start())))){let w=X(r.state.tr);fe.type=="add"?w.addMark(O,L,fe.mark):w.removeMark(O,L,fe.mark),r.dispatch(w)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let w=m.parent.textBetween(m.parentOffset,g.parentOffset),A=()=>X(r.state.tr.insertText(w,O,L));r.someProp("handleTextInput",q=>q(r,O,L,w,A))||r.dispatch(A())}else r.dispatch(X());else r.dispatch(X())}function Ki(r,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:tr(r,e.resolve(t.anchor),e.resolve(t.head))}function oa(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let f=0;f<n.length;f++)i=n[f].removeFromSet(i);for(let f=0;f<t.length;f++)s=t[f].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",a=f=>f.mark(l.addToSet(f.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=f=>f.mark(l.removeFromSet(f.marks));else return null;let c=[];for(let f=0;f<e.childCount;f++)c.push(a(e.child(f)));if(k.from(c).eq(r))return{mark:l,type:o}}function la(r,e,t,n,i){if(t-e<=i.pos-n.pos||Rn(n,!0,!1)<i.pos)return!1;let s=r.resolve(e);if(!n.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=r.resolve(Rn(s,!0,!0));return!o.parent.isTextblock||o.pos>t||Rn(o,!0,!1)<t?!1:n.parent.content.cut(n.parentOffset).eq(o.parent.content)}function aa(r,e,t){let n=0,i=0;return r.nodesBetween(e,t,(s,o)=>{s.isTextblock&&o>=e&&o<t?n++:(s.isText?/\S/.test(s.text.slice(Math.max(0,e-o),Math.min(s.nodeSize,t-o))):s.isLeaf)&&i++}),i==0&&n==1}function Rn(r,e,t){let n=r.depth,i=e?r.end():r.pos;for(;n>0&&(e||r.indexAfter(n)==r.node(n).childCount);)n--,i++,e=!1;if(t){let s=r.node(n).maybeChild(r.indexAfter(n));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function ca(r,e,t,n,i){let s=r.findDiffStart(e,t),o=t+r.size,l=t+e.size;if(s==null)return null;let{a,b:c}=r.findDiffEnd(e,o,l);if(i=="end"){let f=Math.max(0,s-Math.min(a,c));n-=a+f-s}if(a<s&&o<l){let f=n<=s&&n>=a?s-n:0;s-=f,c=s+(c-a),a=s}else if(c<s){let f=n<=s&&n>=c?s-n:0;s-=f,a=s+(a-c),c=s}return{start:s,endA:a,endB:c}}var Mt=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new _n,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Gi),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=ji(this),_i(this),this.nodeViews=Ui(this),this.docView=Di(this.state.doc,Hi(this),In(this),this.dom,this),this.domObserver=new Zn(this,(n,i,s,o)=>sa(this,n,i,s,o)),this.domObserver.start(),El(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&jn(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Gi),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Cs(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Ui(this);ha(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&jn(this),this.editable=ji(this),_i(this);let a=In(this),c=Hi(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",h=s||!this.docView.matchesNode(e.doc,c,a);(h||!e.selection.eq(i.selection))&&(o=!0);let d=f=="preserve"&&o&&this.dom.style.overflowAnchor==null&&jo(this);if(o){this.domObserver.stop();let p=h&&(K||B)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&fa(i.selection,e.selection);if(h){let m=B?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=ql(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Di(e.doc,c,a,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}let u=this.input.mouseDown;p||!(u&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&pl(this)&&u.delaySelUpdate())?ae(this,p):(fs(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((n=this.dragging)===null||n===void 0)&&n.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():d&&Uo(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!Ie(this.dom,e))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof S){let t=this.docView.domAfterPos(this.state.selection.from);x(t)&&Mi(this,t.getBoundingClientRect(),e)}else Mi(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let n=this.directPlugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let n=this.state.plugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}updateDraggedNode(e,t){let n=e.node,i=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)i=n.from;else{let s=n.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&s<this.state.doc.content.size&&this.state.doc.nodeAt(s))==n.node&&(i=s)}this.dragging=new Qt(e.slice,e.move,i<0?void 0:S.create(this.state.doc,i))}someProp(e,t){let n=this._props&&this._props[e],i;if(n!=null&&(i=t?t(n):n))return i;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(i=t?t(l):l))return i}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(i=t?t(l):l))return i}}hasFocus(){if(K){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&Go(this.dom),ae(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return el(this,e)}coordsAtPos(e,t=1){return rs(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let i=this.docView.posFromDOM(e,t,n);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return sl(this,t||this.state,e)}pasteHTML(e,t){return xt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return xt(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return nr(this,e)}destroy(){this.docView&&(Al(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],In(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Fo())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Rl(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?V&&this.root.nodeType===11&&qo(this.dom.ownerDocument)==this.dom&&Ql(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Mt.prototype.dispatch=function(r){let e=this._props.dispatchTransaction;e?e.call(this,r):this.updateState(this.state.apply(r))};function Hi(r){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(r.editable),r.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(r.state)),t)for(let n in t)n=="class"?e.class+=" "+t[n]:n=="style"?e.style=(e.style?e.style+";":"")+t[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(t[n]))}),e.translate||(e.translate="no"),[ge.node(0,r.state.doc.content.size,e)]}function _i(r){if(r.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),r.cursorWrapper={dom:e,deco:ge.widget(r.state.selection.from,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function ji(r){return!r.someProp("editable",e=>e(r.state)===!1)}function fa(r,e){let t=Math.min(r.$anchor.sharedDepth(r.head),e.$anchor.sharedDepth(e.head));return r.$anchor.start(t)!=e.$anchor.start(t)}function Ui(r){let e=Object.create(null);function t(n){for(let i in n)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=n[i])}return r.someProp("nodeViews",t),r.someProp("markViews",t),e}function ha(r,e){let t=0,n=0;for(let i in r){if(r[i]!=e[i])return!0;t++}for(let i in e)n++;return t!=n}function Gi(r){if(r.spec.state||r.spec.filterTransaction||r.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var As=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function ua(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}var da=(r,e,t)=>{let n=ua(r,t);if(!n)return!1;let i=Is(n);if(!i){let o=n.blockRange(),l=o&&qt(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Bs(r,i,e,-1))return!0;if(n.parent.content.size==0&&(Xe(s,"end")||S.isSelectable(s)))for(let o=n.depth;;o--){let l=$t(r.doc,n.before(o),n.after(o),b.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=r.tr.step(l);a.setSelection(Xe(s,"end")?N.findFrom(a.doc.resolve(a.mapping.map(i.pos,-1)),-1):S.create(a.doc,i.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(o==1||n.node(o-1).childCount>1)break}return s.isAtom&&i.depth==n.depth-1?(e&&e(r.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Xe(r,e,t=!1){for(let n=r;n;n=e=="start"?n.firstChild:n.lastChild){if(n.isTextblock)return!0;if(t&&n.childCount!=1)return!1}return!1}var pa=(r,e,t)=>{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("backward",r):n.parentOffset>0)return!1;s=Is(n)}let o=s&&s.nodeBefore;return!o||!S.isSelectable(o)?!1:(e&&e(r.tr.setSelection(S.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Is(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){if(r.index(e)>0)return r.doc.resolve(r.before(e+1));if(r.node(e).type.spec.isolating)break}return null}function ma(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset<t.parent.content.size)?null:t}var ga=(r,e,t)=>{let n=ma(r,t);if(!n)return!1;let i=Rs(n);if(!i)return!1;let s=i.nodeAfter;if(Bs(r,i,e,1))return!0;if(n.parent.content.size==0&&(Xe(s,"start")||S.isSelectable(s))){let o=$t(r.doc,n.before(),n.after(),b.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=r.tr.step(o);l.setSelection(Xe(s,"start")?N.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):S.create(l.doc,l.mapping.map(i.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&i.depth==n.depth-1?(e&&e(r.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0):!1},ya=(r,e,t)=>{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("forward",r):n.parentOffset<n.parent.content.size)return!1;s=Rs(n)}let o=s&&s.nodeAfter;return!o||!S.isSelectable(o)?!1:(e&&e(r.tr.setSelection(S.create(r.doc,s.pos)).scrollIntoView()),!0)};function Rs(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){let t=r.node(e);if(r.index(e)+1<t.childCount)return r.doc.resolve(r.after(e+1));if(t.type.spec.isolating)break}return null}var ka=(r,e)=>{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(`
10
+ `).scrollIntoView()),!0)};function ar(r){for(let e=0;e<r.edgeCount;e++){let{type:t}=r.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}var ba=(r,e)=>{let{$head:t,$anchor:n}=r.selection;if(!t.parent.type.spec.code||!t.sameParent(n))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=ar(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=r.tr.replaceWith(l,l,o.createAndFill());a.setSelection(N.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},xa=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof _||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=ar(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!n.parentOffset&&i.index()<i.parent.childCount?n:i).pos,l=r.tr.insert(o,s.createAndFill());l.setSelection(D.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},Sa=(r,e)=>{let{$cursor:t}=r.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(ut(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&&qt(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function Ma(r){return(e,t)=>{let{$from:n,$to:i}=e.selection;if(e.selection instanceof S&&e.selection.node.isBlock)return!n.parentOffset||!ut(e.doc,n.pos)?!1:(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let p=n.depth;;p--)if(n.node(p).isBlock){a=n.end(p)==n.pos+(n.depth-p),c=n.start(p)==n.pos-(n.depth-p),l=ar(n.node(p-1).contentMatchAt(n.indexAfter(p-1)));let m=r&&r(i.parent,a,n);s.unshift(m||(a&&l?{type:l}:null)),o=p;break}else{if(p==1)return!1;s.unshift(null)}let f=e.tr;(e.selection instanceof D||e.selection instanceof _)&&f.deleteSelection();let h=f.mapping.map(n.pos),d=ut(f.doc,h,s.length,s);if(d||(s[0]=l?{type:l}:null,d=ut(f.doc,h,s.length,s)),f.split(h,s.length,s),!a&&c&&n.node(o).type!=l){let p=f.mapping.map(n.before(o)),u=f.doc.resolve(p);l&&n.node(o-1).canReplaceWith(u.index(),u.index()+1,l)&&f.setNodeMarkup(f.mapping.map(n.before(o)),l)}return t&&t(f.scrollIntoView()),!0}}var Ca=Ma();var wa=(r,e)=>(e&&e(r.tr.setSelection(new _(r.doc))),!0);function Oa(r,e,t){let n=e.nodeBefore,i=e.nodeAfter,s=e.index();return!n||!i||!n.type.compatibleContent(i.type)?!1:!n.content.size&&e.parent.canReplace(s-1,s)?(t&&t(r.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||wn(r.doc,e.pos))?!1:(t&&t(r.tr.join(e.pos).scrollIntoView()),!0)}function Bs(r,e,t,n){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Oa(r,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let p=e.pos+s.nodeSize,u=k.empty;for(let y=o.length-1;y>=0;y--)u=k.from(o[y].create(null,u));u=k.from(i.copy(u));let m=r.tr.step(new H(e.pos-1,p,e.pos,p,new b(u,1,0),o.length,!0)),g=m.doc.resolve(p+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&wn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let f=s.type.spec.isolating||n>0&&a?null:N.findFrom(e,1),h=f&&f.$from.blockRange(f.$to),d=h&&qt(h);if(d!=null&&d>=e.depth)return t&&t(r.tr.lift(h,d).scrollIntoView()),!0;if(c&&Xe(s,"start",!0)&&Xe(i,"end")){let p=i,u=[];for(;u.push(p),!p.isTextblock;)p=p.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(t){let y=k.empty;for(let O=u.length-1;O>=0;O--)y=k.from(u[O].copy(y));let M=r.tr.step(new H(e.pos-u.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,u.length,0),0,!0));t(M.scrollIntoView())}return!0}}return!1}function Ps(r){return function(e,t){let n=e.selection,i=r<0?n.$from:n.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(D.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}var Na=Ps(-1),Da=Ps(1);function Ta(r,e,t,n){for(let i=0;i<e.length;i++){let{$from:s,$to:o}=e[i],l=s.depth==0?r.inlineContent&&r.type.allowsMarkType(t):!1;if(r.nodesBetween(s.pos,o.pos,(a,c)=>{if(l||!n&&a.isAtom&&a.isInline&&c>=s.pos&&c+a.nodeSize<=o.pos)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function Ea(r){let e=[];for(let t=0;t<r.length;t++){let{$from:n,$to:i}=r[t];n.doc.nodesBetween(n.pos,i.pos,(s,o)=>{if(s.isAtom&&s.content.size&&s.isInline&&o>=n.pos&&o+s.nodeSize<=i.pos)return o+1>n.pos&&e.push(new Ke(n,n.doc.resolve(o+1))),n=n.doc.resolve(o+1+s.content.size),!1}),n.pos<i.pos&&e.push(new Ke(n,i))}return e}function Be(r,e=null,t){let n=(t&&t.removeWhenPresent)!==!1,i=(t&&t.enterInlineAtoms)!==!1;return function(s,o){let{empty:l,$cursor:a,ranges:c}=s.selection;if(l&&!a||!Ta(s.doc,c,r,i))return!1;if(o)if(a)r.isInSet(s.storedMarks||a.marks())?o(s.tr.removeStoredMark(r)):o(s.tr.addStoredMark(r.create(e)));else{let f,h=s.tr;i||(c=Ea(c)),n?f=!c.some(d=>s.doc.rangeHasMark(d.$from.pos,d.$to.pos,r)):f=!c.every(d=>{let p=!1;return h.doc.nodesBetween(d.$from.pos,d.$to.pos,(u,m,g)=>{if(p)return!1;p=!r.isInSet(u.marks)&&!!g&&g.type.allowsMarkType(r)&&!(u.isText&&/^\s*$/.test(u.textBetween(Math.max(0,d.$from.pos-m),Math.min(u.nodeSize,d.$to.pos-m))))}),!p});for(let d=0;d<c.length;d++){let{$from:p,$to:u}=c[d];if(!f)h.removeMark(p.pos,u.pos,r);else{let m=p.pos,g=u.pos,y=p.nodeAfter,M=u.nodeBefore,O=y&&y.isText?/^\s*/.exec(y.text)[0].length:0,L=M&&M.isText?/\s*$/.exec(M.text)[0].length:0;m+O<g&&(m+=O,g-=L),h.addMark(m,g,r.create(e))}}o(h.scrollIntoView())}return!0}}function cr(...r){return function(e,t,n){for(let i=0;i<r.length;i++)if(r[i](e,t,n))return!0;return!1}}var lr=cr(As,da,pa),Es=cr(As,ga,ya),ce={Enter:cr(ka,xa,Sa,Ca),"Mod-Enter":ba,Backspace:lr,"Mod-Backspace":lr,"Shift-Backspace":lr,Delete:Es,"Mod-Delete":Es,"Mod-a":wa},zs={"Ctrl-h":ce.Backspace,"Alt-Backspace":ce["Mod-Backspace"],"Ctrl-d":ce.Delete,"Ctrl-Alt-Backspace":ce["Mod-Delete"],"Alt-Delete":ce["Mod-Delete"],"Alt-d":ce["Mod-Delete"],"Ctrl-a":Na,"Ctrl-e":Da};for(let r in ce)zs[r]=ce[r];var Aa=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,vs=Aa?zs:ce;var Ia=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Ra(r){let e=r.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,i,s,o;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))n=!0;else if(/^(c|ctrl|control)$/i.test(a))i=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Ia?o=!0:i=!0;else throw new Error("Unrecognized modifier name: "+a)}return n&&(t="Alt-"+t),i&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function Ba(r){let e=Object.create(null);for(let t in r)e[Ra(t)]=r[t];return e}function fr(r,e,t=!0){return e.altKey&&(r="Alt-"+r),e.ctrlKey&&(r="Ctrl-"+r),e.metaKey&&(r="Meta-"+r),t&&e.shiftKey&&(r="Shift-"+r),r}function hr(r){return new He({props:{handleKeyDown:Pa(r)}})}function Pa(r){let e=Ba(r);return function(t,n){let i=Cr(n),s,o=e[fr(i,n)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(n.shiftKey){let l=e[fr(i,n,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((n.shiftKey||n.altKey||n.metaKey||i.charCodeAt(0)>127)&&(s=Mr[n.keyCode])&&s!=i){let l=e[fr(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var on=200,P=function(){};P.prototype.append=function(e){return e.length?(e=P.from(e),!this.length&&e||e.length<on&&this.leafAppend(e)||this.length<on&&e.leafPrepend(this)||this.appendInner(e)):this};P.prototype.prepend=function(e){return e.length?P.from(e).append(this):this};P.prototype.appendInner=function(e){return new za(this,e)};P.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?P.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};P.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};P.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)};P.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,n),i};P.from=function(e){return e instanceof P?e:e&&e.length?new Fs(e):P.empty};var Fs=(function(r){function e(n){r.call(this),this.values=n}r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a<o;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,s,o,l){for(var a=s-1;a>=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=on)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=on)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(P);P.empty=new Fs([]);var za=(function(r){function e(t,n){r.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},e.prototype.forEachInner=function(n,i,s,o){var l=this.left.length;if(i<l&&this.left.forEachInner(n,i,Math.min(s,l),o)===!1||s>l&&this.right.forEachInner(n,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(n,i-l,Math.max(s,l)-l,o+l)===!1||s<l&&this.left.forEachInvertedInner(n,Math.min(i,l),s,o)===!1)return!1},e.prototype.sliceInner=function(n,i){if(n==0&&i==this.length)return this;var s=this.left.length;return i<=s?this.left.slice(n,i):n>=s?this.right.slice(n-s,i-s):this.left.slice(n,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e})(P),ur=P;var va=500,ze=class r{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,s;t&&(i=this.remapping(n,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],f=[];return this.items.forEach((h,d)=>{if(!h.step){i||(i=this.remapping(n,d+1),s=i.maps.length),s--,f.push(h);return}if(i){f.push(new te(h.map));let p=h.step.map(i.slice(s)),u;p&&o.maybeStep(p).doc&&(u=o.mapping.maps[o.mapping.maps.length-1],c.push(new te(u,void 0,void 0,c.length+f.length))),s--,u&&i.appendMap(u,s)}else o.maybeStep(h.step);if(h.selection)return l=i?h.selection.map(i.slice(s)):h.selection,a=new r(this.items.slice(0,n).append(f.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,n,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let f=0;f<e.steps.length;f++){let h=e.steps[f].invert(e.docs[f]),d=new te(e.mapping.maps[f],h,t),p;(p=a&&a.merge(d))&&(d=p,f?s.pop():l=l.slice(0,l.length-1)),s.push(d),t&&(o++,t=void 0),i||(a=d)}let c=o-n.depth;return c>Va&&(l=Fa(l,c),o-=c),new r(l.append(s),o)}remapping(e,t){let n=new at;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?n.maps.length-i.mirrorOffset:void 0;n.appendMap(i.map,o)},e,t),n}addMaps(e){return this.eventCount==0?this:new r(this.items.append(e.map(t=>new te(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let p=s.getMirror(--a);if(p==null)return;o=Math.min(o,p);let u=s.maps[p];if(d.step){let m=e.steps[p].invert(e.docs[p]),g=d.selection&&d.selection.map(s.slice(a+1,p));g&&l++,n.push(new te(u,m,g))}else n.push(new te(u))},i);let c=[];for(let d=t;d<o;d++)c.push(new te(s.maps[d]));let f=this.items.slice(0,i).append(c).append(n),h=new r(f,l);return h.emptyItemCount()>va&&(h=h.compress(this.items.length-n.length)),h}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(n)),c=a&&a.getMap();if(n--,c&&t.appendMap(c,n),a){let f=o.selection&&o.selection.map(t.slice(n));f&&s++;let h=new te(c.invert(),a,f),d,p=i.length-1;(d=i.length&&i[p].merge(h))?i[p]=d:i.push(h)}}else o.map&&n--},this.items.length,0),new r(ur.from(i.reverse()),s)}};ze.empty=new ze(ur.empty,0);function Fa(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}var te=class r{constructor(e,t,n,i){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new r(t.getMap().invert(),t,this.selection)}}},ne=class{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}},Va=20;function La(r,e,t,n){let i=t.getMeta(Pe),s;if(i)return i.historyState;t.getMeta(Ws)&&(r=new ne(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(Pe))return o.getMeta(Pe).redo?new ne(r.done.addTransform(t,void 0,n,ln(e)),r.undone,Vs(t.mapping.maps),r.prevTime,r.prevComposition):new ne(r.done,r.undone.addTransform(t,void 0,n,ln(e)),null,r.prevTime,r.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=r.prevTime==0||!o&&r.prevComposition!=l&&(r.prevTime<(t.time||0)-n.newGroupDelay||!Wa(t,r.prevRanges)),c=o?dr(r.prevRanges,t.mapping):Vs(t.mapping.maps);return new ne(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,ln(e)),ze.empty,c,t.time,l??r.prevComposition)}else return(s=t.getMeta("rebased"))?new ne(r.done.rebased(t,s),r.undone.rebased(t,s),dr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new ne(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),dr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function Wa(r,e){if(!e)return!1;if(!r.docChanged)return!0;let t=!1;return r.mapping.maps[0].forEach((n,i)=>{for(let s=0;s<e.length;s+=2)n<=e[s+1]&&i>=e[s]&&(t=!0)}),t}function Vs(r){let e=[];for(let t=r.length-1;t>=0&&e.length==0;t--)r[t].forEach((n,i,s,o)=>e.push(s,o));return e}function dr(r,e){if(!r)return null;let t=[];for(let n=0;n<r.length;n+=2){let i=e.map(r[n],1),s=e.map(r[n+1],-1);i<=s&&t.push(i,s)}return t}function Ja(r,e,t){let n=ln(e),i=Pe.get(e).spec.config,s=(t?r.undone:r.done).popEvent(e,n);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?r.done:r.undone).addTransform(s.transform,e.selection.getBookmark(),i,n),a=new ne(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Pe,{redo:t,historyState:a})}var pr=!1,Ls=null;function ln(r){let e=r.plugins;if(Ls!=e){pr=!1,Ls=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){pr=!0;break}}return pr}function mr(r){return r.setMeta(Ws,!0)}var Pe=new pt("history"),Ws=new pt("closeHistory");function Js(r={}){return r={depth:r.depth||100,newGroupDelay:r.newGroupDelay||500},new He({key:Pe,state:{init(){return new ne(ze.empty,ze.empty,null,0,-1)},apply(e,t,n){return La(t,n,e,r)}},config:r,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,i=n=="historyUndo"?Ze:n=="historyRedo"?ve:null;return i?(t.preventDefault(),i(e.state,e.dispatch)):!1}}}})}function an(r,e){return(t,n)=>{let i=Pe.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let s=Ja(i,t,r);s&&n(e?s.scrollIntoView():s)}return!0}}var Ze=an(!1,!0),ve=an(!0,!0),xc=an(!1,!1),Sc=an(!0,!1);import qa from"@gramlot/gramlot/markdown";var Qe=new Le({nodes:{doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return["p",0]}},blockquote:{content:"block+",group:"block",parseDOM:[{tag:"blockquote"}],toDOM(){return["blockquote",0]}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return["div",["hr"]]}},heading:{attrs:{level:{default:1}},content:"(text | image)*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(r){return["h"+r.attrs.level,0]}},code_block:{content:"text*",group:"block",code:!0,defining:!0,marks:"",attrs:{params:{default:""}},parseDOM:[{tag:"pre",preserveWhitespace:"full",getAttrs:r=>({params:r.getAttribute("data-params")||""})}],toDOM(r){return["pre",r.attrs.params?{"data-params":r.attrs.params}:{},["code",0]]}},ordered_list:{content:"list_item+",group:"block",attrs:{order:{default:1},tight:{default:!1}},parseDOM:[{tag:"ol",getAttrs(r){return{order:r.hasAttribute("start")?+r.getAttribute("start"):1,tight:r.hasAttribute("data-tight")}}}],toDOM(r){return["ol",{start:r.attrs.order==1?null:r.attrs.order,"data-tight":r.attrs.tight?"true":null},0]}},bullet_list:{content:"list_item+",group:"block",attrs:{tight:{default:!1}},parseDOM:[{tag:"ul",getAttrs:r=>({tight:r.hasAttribute("data-tight")})}],toDOM(r){return["ul",{"data-tight":r.attrs.tight?"true":null},0]}},list_item:{content:"block+",defining:!0,parseDOM:[{tag:"li"}],toDOM(){return["li",0]}},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(r){return{src:r.getAttribute("src"),title:r.getAttribute("title"),alt:r.getAttribute("alt")}}}],toDOM(r){return["img",r.attrs]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return["br"]}}},marks:{em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:r=>r.type.name=="em"}],toDOM(){return["em"]}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:r=>r.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:r=>r.type.name=="strong"},{style:"font-weight",getAttrs:r=>/^(bold(er)?|[5-9]\d{2,})$/.test(r)&&null}],toDOM(){return["strong"]}},link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(r){return{href:r.getAttribute("href"),title:r.getAttribute("title")}}}],toDOM(r){return["a",r.attrs]}},code:{parseDOM:[{tag:"code"}],toDOM(){return["code"]}}}});function $a(r,e){if(r.isText&&e.isText&&C.sameSet(r.marks,e.marks))return r.withText(r.text+e.text)}var kr=class{constructor(e,t){this.schema=e,this.tokenHandlers=t,this.stack=[{type:e.topNodeType,attrs:null,content:[],marks:C.none}]}top(){return this.stack[this.stack.length-1]}push(e){this.stack.length&&this.top().content.push(e)}addText(e){if(!e)return;let t=this.top(),n=t.content,i=n[n.length-1],s=this.schema.text(e,t.marks),o;i&&(o=$a(i,s))?n[n.length-1]=o:n.push(s)}openMark(e){let t=this.top();t.marks=e.addToSet(t.marks)}closeMark(e){let t=this.top();t.marks=e.removeFromSet(t.marks)}parseTokens(e){for(let t=0;t<e.length;t++){let n=e[t],i=this.tokenHandlers[n.type];if(!i)throw new Error("Token type `"+n.type+"` not supported by Markdown parser");i(this,n,e,t)}}addNode(e,t,n){let i=this.top(),s=e.createAndFill(t,n,i?i.marks:[]);return s?(this.push(s),s):null}openNode(e,t){this.stack.push({type:e,attrs:t,content:[],marks:C.none})}closeNode(){let e=this.stack.pop();return this.addNode(e.type,e.attrs,e.content)}};function Nt(r,e,t,n){return r.getAttrs?r.getAttrs(e,t,n):r.attrs instanceof Function?r.attrs(e):r.attrs}function gr(r,e){return r.noCloseToken||e=="code_inline"||e=="code_block"||e=="fence"}function qs(r){return r[r.length-1]==`
11
+ `?r.slice(0,r.length-1):r}function yr(){}function Ka(r,e){let t=Object.create(null);for(let n in e){let i=e[n];if(i.block){let s=r.nodeType(i.block);gr(i,n)?t[n]=(o,l,a,c)=>{o.openNode(s,Nt(i,l,a,c)),o.addText(qs(l.content)),o.closeNode()}:(t[n+"_open"]=(o,l,a,c)=>o.openNode(s,Nt(i,l,a,c)),t[n+"_close"]=o=>o.closeNode())}else if(i.node){let s=r.nodeType(i.node);t[n]=(o,l,a,c)=>o.addNode(s,Nt(i,l,a,c))}else if(i.mark){let s=r.marks[i.mark];gr(i,n)?t[n]=(o,l,a,c)=>{o.openMark(s.create(Nt(i,l,a,c))),o.addText(qs(l.content)),o.closeMark(s)}:(t[n+"_open"]=(o,l,a,c)=>o.openMark(s.create(Nt(i,l,a,c))),t[n+"_close"]=o=>o.closeMark(s))}else if(i.ignore)gr(i,n)?t[n]=yr:(t[n+"_open"]=yr,t[n+"_close"]=yr);else throw new RangeError("Unrecognized parsing spec "+JSON.stringify(i))}return t.text=(n,i)=>n.addText(i.content),t.inline=(n,i)=>n.parseTokens(i.children),t.softbreak=t.softbreak||(n=>n.addText(" ")),t}var Dt=class{constructor(e,t,n){this.schema=e,this.tokenizer=t,this.tokens=n,this.tokenHandlers=Ka(e,n)}parse(e,t={}){let n=new kr(this.schema,this.tokenHandlers),i;n.parseTokens(this.tokenizer.parse(e,t));do i=n.closeNode();while(n.stack.length);return i||this.schema.topNodeType.createAndFill()}};function $s(r,e){for(;++e<r.length;)if(r[e].type!="list_item_open")return r[e].hidden;return!1}var xr=new Dt(Qe,qa("commonmark",{html:!1}),{blockquote:{block:"blockquote"},paragraph:{block:"paragraph"},list_item:{block:"list_item"},bullet_list:{block:"bullet_list",getAttrs:(r,e,t)=>({tight:$s(e,t)})},ordered_list:{block:"ordered_list",getAttrs:(r,e,t)=>({order:+r.attrGet("start")||1,tight:$s(e,t)})},heading:{block:"heading",getAttrs:r=>({level:+r.tag.slice(1)})},code_block:{block:"code_block",noCloseToken:!0},fence:{block:"code_block",getAttrs:r=>({params:r.info||""}),noCloseToken:!0},hr:{node:"horizontal_rule"},image:{node:"image",getAttrs:r=>({src:r.attrGet("src"),title:r.attrGet("title")||null,alt:r.children[0]&&r.children[0].content||null})},hardbreak:{node:"hard_break"},em:{mark:"em"},strong:{mark:"strong"},link:{mark:"link",getAttrs:r=>({href:r.attrGet("href"),title:r.attrGet("title")||null})},code_inline:{mark:"code",noCloseToken:!0}}),Ha={open:"",close:"",mixable:!0},Tt=class{constructor(e,t,n={}){this.nodes=e,this.marks=t,this.options=n}serialize(e,t={}){t=Object.assign({},this.options,t);let n=new br(this.nodes,this.marks,t);return n.renderContent(e),n.out}},Sr=new Tt({blockquote(r,e){r.wrapBlock("> ",null,e,()=>r.renderContent(e))},code_block(r,e){let t=e.textContent.match(/`{3,}/gm),n=t?t.sort().slice(-1)[0]+"`":"```";r.write(n+(e.attrs.params||"")+`
12
12
  `),r.text(e.textContent,!1),r.write(`
13
13
  `),r.write(n),r.closeBlock(e)},heading(r,e){r.write(r.repeat("#",e.attrs.level)+" "),r.renderInline(e,!1),r.closeBlock(e)},horizontal_rule(r,e){r.write(e.attrs.markup||"---"),r.closeBlock(e)},bullet_list(r,e){r.renderList(e," ",()=>(e.attrs.bullet||"*")+" ")},ordered_list(r,e){let t=e.attrs.order||1,n=String(t+e.childCount-1).length,i=r.repeat(" ",n+2);r.renderList(e,i,s=>{let o=String(t+s);return r.repeat(" ",n-o.length)+o+". "})},list_item(r,e){r.renderContent(e)},paragraph(r,e){r.renderInline(e),r.closeBlock(e)},image(r,e){r.write("!["+r.esc(e.attrs.alt||"")+"]("+e.attrs.src.replace(/[\(\)]/g,"\\$&")+(e.attrs.title?' "'+e.attrs.title.replace(/"/g,'\\"')+'"':"")+")")},hard_break(r,e,t,n){for(let i=n+1;i<t.childCount;i++)if(t.child(i).type!=e.type){r.write(`\\
14
- `);return}},text(r,e){r.text(e.text,!r.inAutolink)}},{em:{open:"*",close:"*",mixable:!0,expelEnclosingWhitespace:!0},strong:{open:"**",close:"**",mixable:!0,expelEnclosingWhitespace:!0},link:{open(r,e,t,n){return r.inAutolink=_a(e,t,n),r.inAutolink?"<":"["},close(r,e,t,n){let{inAutolink:i}=r;return r.inAutolink=void 0,i?">":"]("+e.attrs.href.replace(/[\(\)"]/g,"\\$&")+(e.attrs.title?` "${e.attrs.title.replace(/"/g,'\\"')}"`:"")+")"},mixable:!0},code:{open(r,e,t,n){return Hs(t.child(n),-1)},close(r,e,t,n){return Hs(t.child(n-1),1)},escape:!1}});function Hs(r,e){let t=/`+/g,n,i=0;if(r.isText)for(;n=t.exec(r.text);)i=Math.max(i,n[0].length);let s=i>0&&e>0?" `":"`";for(let o=0;o<i;o++)s+="`";return i>0&&e<0&&(s+=" "),s}function _a(r,e,t){if(r.attrs.title||!/^\w+:/.test(r.attrs.href))return!1;let n=e.child(t);return!n.isText||n.text!=r.attrs.href||n.marks[n.marks.length-1]!=r?!1:t==e.childCount-1||!r.isInSet(e.child(t+1).marks)}var br=class{constructor(e,t,n){this.nodes=e,this.marks=t,this.options=n,this.delim="",this.out="",this.closed=null,this.inAutolink=void 0,this.atBlockStart=!1,this.inTightList=!1,typeof this.options.tightLists>"u"&&(this.options.tightLists=!1),typeof this.options.hardBreakNodeName>"u"&&(this.options.hardBreakNodeName="hard_break")}flushClose(e=2){if(this.closed){if(this.atBlank()||(this.out+=`
14
+ `);return}},text(r,e){r.text(e.text,!r.inAutolink)}},{em:{open:"*",close:"*",mixable:!0,expelEnclosingWhitespace:!0},strong:{open:"**",close:"**",mixable:!0,expelEnclosingWhitespace:!0},link:{open(r,e,t,n){return r.inAutolink=_a(e,t,n),r.inAutolink?"<":"["},close(r,e,t,n){let{inAutolink:i}=r;return r.inAutolink=void 0,i?">":"]("+e.attrs.href.replace(/[\(\)"]/g,"\\$&")+(e.attrs.title?` "${e.attrs.title.replace(/"/g,'\\"')}"`:"")+")"},mixable:!0},code:{open(r,e,t,n){return Ks(t.child(n),-1)},close(r,e,t,n){return Ks(t.child(n-1),1)},escape:!1}});function Ks(r,e){let t=/`+/g,n,i=0;if(r.isText)for(;n=t.exec(r.text);)i=Math.max(i,n[0].length);let s=i>0&&e>0?" `":"`";for(let o=0;o<i;o++)s+="`";return i>0&&e<0&&(s+=" "),s}function _a(r,e,t){if(r.attrs.title||!/^\w+:/.test(r.attrs.href))return!1;let n=e.child(t);return!n.isText||n.text!=r.attrs.href||n.marks[n.marks.length-1]!=r?!1:t==e.childCount-1||!r.isInSet(e.child(t+1).marks)}var br=class{constructor(e,t,n){this.nodes=e,this.marks=t,this.options=n,this.delim="",this.out="",this.closed=null,this.inAutolink=void 0,this.atBlockStart=!1,this.inTightList=!1,typeof this.options.tightLists>"u"&&(this.options.tightLists=!1),typeof this.options.hardBreakNodeName>"u"&&(this.options.hardBreakNodeName="hard_break")}flushClose(e=2){if(this.closed){if(this.atBlank()||(this.out+=`
15
15
  `),e>1){let t=this.delim,n=/\s+$/.exec(t);n&&(t=t.slice(0,t.length-n[0].length));for(let i=1;i<e;i++)this.out+=t+`
16
16
  `}this.closed=null}}getMark(e){let t=this.marks[e];if(!t){if(this.options.strict!==!1)throw new Error(`Mark type \`${e}\` not supported by Markdown renderer`);t=Ha}return t}wrapBlock(e,t,n,i){let s=this.delim;this.write(t??e),this.delim+=e,i(),this.delim=s,this.closeBlock(n)}atBlank(){return/(^|\n)$/.test(this.out)}ensureNewLine(){this.atBlank()||(this.out+=`
17
17
  `)}write(e){this.flushClose(),this.delim&&this.atBlank()&&(this.out+=this.delim),e&&(this.out+=e)}closeBlock(e){this.closed=e}text(e,t=!0){let n=e.split(`
18
18
  `);for(let i=0;i<n.length;i++)this.write(),!t&&n[i][0]=="["&&/(^|[^\\])\!$/.test(this.out)&&(this.out=this.out.slice(0,this.out.length-1)+"\\!"),this.out+=t?this.esc(n[i],this.atBlockStart):n[i],i!=n.length-1&&(this.out+=`
19
- `)}render(e,t,n){if(this.nodes[e.type.name])this.nodes[e.type.name](this,e,t,n);else{if(this.options.strict!==!1)throw new Error("Token type `"+e.type.name+"` not supported by Markdown renderer");e.type.isLeaf||(e.type.inlineContent?this.renderInline(e):this.renderContent(e),e.isBlock&&this.closeBlock(e))}}renderContent(e){e.forEach((t,n,i)=>this.render(t,e,i))}renderInline(e,t=!0){this.atBlockStart=t;let n=[],i="",s=(o,l,a)=>{let c=o?o.marks:[];o&&o.type.name===this.options.hardBreakNodeName&&(c=c.filter(m=>{if(a+1==e.childCount)return!1;let g=e.child(a+1);return m.isInSet(g.marks)&&(!g.isText||/\S/.test(g.text))}));let f=i;if(i="",o&&o.isText&&c.some(m=>{let g=this.getMark(m.type.name);return g&&g.expelEnclosingWhitespace&&!m.isInSet(n)})){let[m,g,y]=/^(\s*)(.*)$/m.exec(o.text);g&&(f+=g,o=y?o.withText(y):null,o||(c=n))}if(o&&o.isText&&c.some(m=>{let g=this.getMark(m.type.name);return g&&g.expelEnclosingWhitespace&&(a==e.childCount-1||!m.isInSet(e.child(a+1).marks))})){let[m,g,y]=/^(.*?)(\s*)$/m.exec(o.text);y&&(i=y,o=g?o.withText(g):null,o||(c=n))}let h=c.length?c[c.length-1]:null,d=h&&this.getMark(h.type.name).escape===!1,p=c.length-(d?1:0);e:for(let m=0;m<p;m++){let g=c[m];if(!this.getMark(g.type.name).mixable)break;for(let y=0;y<n.length;y++){let M=n[y];if(!this.getMark(M.type.name).mixable)break;if(g.eq(M)){m>y?c=c.slice(0,y).concat(g).concat(c.slice(y,m)).concat(c.slice(m+1,p)):y>m&&(c=c.slice(0,m).concat(c.slice(m+1,y)).concat(g).concat(c.slice(y,p)));continue e}}}let u=0;for(;u<Math.min(n.length,p)&&c[u].eq(n[u]);)++u;for(;u<n.length;)this.text(this.markString(n.pop(),!1,e,a),!1);if(f&&this.text(f),o){for(;n.length<p;){let m=c[n.length];n.push(m),this.text(this.markString(m,!0,e,a),!1),this.atBlockStart=!1}d&&o.isText?this.text(this.markString(h,!0,e,a)+o.text+this.markString(h,!1,e,a+1),!1):this.render(o,e,a),this.atBlockStart=!1}o?.isText&&o.nodeSize>0&&(this.atBlockStart=!1)};e.forEach(s),s(null,0,e.childCount),this.atBlockStart=!1}renderList(e,t,n){this.closed&&this.closed.type==e.type?this.flushClose(3):this.inTightList&&this.flushClose(1);let i=typeof e.attrs.tight<"u"?e.attrs.tight:this.options.tightLists,s=this.inTightList;this.inTightList=i,e.forEach((o,l,a)=>{a&&i&&this.flushClose(1),this.wrapBlock(t,n(a),e,()=>this.render(o,e,a))}),this.inTightList=s}esc(e,t=!1){return e=e.replace(/[`*\\~\[\]_]/g,(n,i)=>n=="_"&&i>0&&i+1<e.length&&e[i-1].match(/\w/)&&e[i+1].match(/\w/)?n:"\\"+n),t&&(e=e.replace(/^(\+[ ]|[\-*>])/,"\\$&").replace(/^(\s*)(#{1,6})(\s|$)/,"$1\\$2$3").replace(/^(\s*\d+)\.\s/,"$1\\. ")),this.options.escapeExtraCharacters&&(e=e.replace(this.options.escapeExtraCharacters,"\\$&")),e}quote(e){let t=e.indexOf('"')==-1?'""':e.indexOf("'")==-1?"''":"()";return t[0]+e+t[1]}repeat(e,t){let n="";for(let i=0;i<t;i++)n+=e;return n}markString(e,t,n,i){let s=this.getMark(e.type.name),o=t?s.open:s.close;return typeof o=="string"?o:o(this,e,n,i)}getEnclosingWhitespace(e){return{leading:(e.match(/^(\s+)/)||[void 0])[0],trailing:(e.match(/(\s+)$/)||[void 0])[0]}}};function _s(r){let e={...Qe.spec.nodes.get("image"),parseDOM:[{tag:"img[src]",getAttrs:l=>Fe.validateLink(l.getAttribute("src"))?{src:l.getAttribute("src"),alt:l.getAttribute("alt"),title:l.getAttribute("title")}:!1}]},t={...Qe.spec.marks.get("link"),parseDOM:[{tag:"a[href]",getAttrs:l=>Fe.validateLink(l.getAttribute("href"))?{href:l.getAttribute("href"),title:l.getAttribute("title")}:!1}]},n=new Le({nodes:Qe.spec.nodes.update("image",e).append({source_block:{group:"block",atom:!0,attrs:{source:{}},toDOM:l=>{let a=r.createElement("div");return a.className="markdown-source-block",a.contentEditable="false",a.title="Preserved Markdown block \u2014 edit in Code",a.innerHTML=Fe.render(l.attrs.source),a}}}),marks:Qe.spec.marks.update("link",t)}),i=new Dt(n,xr.tokenizer,xr.tokens),s=new Tt({...Sr.nodes,source_block:(l,a)=>{l.write(a.attrs.source),l.closeBlock(a)}},Sr.marks);function o(l){if(typeof l!="string")throw new TypeError("Markdown editor value must be a string");let a=d=>n.nodes.source_block.create({source:d});if(/^ {0,3}\[[^\]]+\]:/m.test(l)||/^---\r?\n/.test(l))return n.node("doc",null,[a(l)]);let c=l.split(`
19
+ `)}render(e,t,n){if(this.nodes[e.type.name])this.nodes[e.type.name](this,e,t,n);else{if(this.options.strict!==!1)throw new Error("Token type `"+e.type.name+"` not supported by Markdown renderer");e.type.isLeaf||(e.type.inlineContent?this.renderInline(e):this.renderContent(e),e.isBlock&&this.closeBlock(e))}}renderContent(e){e.forEach((t,n,i)=>this.render(t,e,i))}renderInline(e,t=!0){this.atBlockStart=t;let n=[],i="",s=(o,l,a)=>{let c=o?o.marks:[];o&&o.type.name===this.options.hardBreakNodeName&&(c=c.filter(m=>{if(a+1==e.childCount)return!1;let g=e.child(a+1);return m.isInSet(g.marks)&&(!g.isText||/\S/.test(g.text))}));let f=i;if(i="",o&&o.isText&&c.some(m=>{let g=this.getMark(m.type.name);return g&&g.expelEnclosingWhitespace&&!m.isInSet(n)})){let[m,g,y]=/^(\s*)(.*)$/m.exec(o.text);g&&(f+=g,o=y?o.withText(y):null,o||(c=n))}if(o&&o.isText&&c.some(m=>{let g=this.getMark(m.type.name);return g&&g.expelEnclosingWhitespace&&(a==e.childCount-1||!m.isInSet(e.child(a+1).marks))})){let[m,g,y]=/^(.*?)(\s*)$/m.exec(o.text);y&&(i=y,o=g?o.withText(g):null,o||(c=n))}let h=c.length?c[c.length-1]:null,d=h&&this.getMark(h.type.name).escape===!1,p=c.length-(d?1:0);e:for(let m=0;m<p;m++){let g=c[m];if(!this.getMark(g.type.name).mixable)break;for(let y=0;y<n.length;y++){let M=n[y];if(!this.getMark(M.type.name).mixable)break;if(g.eq(M)){m>y?c=c.slice(0,y).concat(g).concat(c.slice(y,m)).concat(c.slice(m+1,p)):y>m&&(c=c.slice(0,m).concat(c.slice(m+1,y)).concat(g).concat(c.slice(y,p)));continue e}}}let u=0;for(;u<Math.min(n.length,p)&&c[u].eq(n[u]);)++u;for(;u<n.length;)this.text(this.markString(n.pop(),!1,e,a),!1);if(f&&this.text(f),o){for(;n.length<p;){let m=c[n.length];n.push(m),this.text(this.markString(m,!0,e,a),!1),this.atBlockStart=!1}d&&o.isText?this.text(this.markString(h,!0,e,a)+o.text+this.markString(h,!1,e,a+1),!1):this.render(o,e,a),this.atBlockStart=!1}o?.isText&&o.nodeSize>0&&(this.atBlockStart=!1)};e.forEach(s),s(null,0,e.childCount),this.atBlockStart=!1}renderList(e,t,n){this.closed&&this.closed.type==e.type?this.flushClose(3):this.inTightList&&this.flushClose(1);let i=typeof e.attrs.tight<"u"?e.attrs.tight:this.options.tightLists,s=this.inTightList;this.inTightList=i,e.forEach((o,l,a)=>{a&&i&&this.flushClose(1),this.wrapBlock(t,n(a),e,()=>this.render(o,e,a))}),this.inTightList=s}esc(e,t=!1){return e=e.replace(/[`*\\~\[\]_]/g,(n,i)=>n=="_"&&i>0&&i+1<e.length&&e[i-1].match(/\w/)&&e[i+1].match(/\w/)?n:"\\"+n),t&&(e=e.replace(/^(\+[ ]|[\-*>])/,"\\$&").replace(/^(\s*)(#{1,6})(\s|$)/,"$1\\$2$3").replace(/^(\s*\d+)\.\s/,"$1\\. ")),this.options.escapeExtraCharacters&&(e=e.replace(this.options.escapeExtraCharacters,"\\$&")),e}quote(e){let t=e.indexOf('"')==-1?'""':e.indexOf("'")==-1?"''":"()";return t[0]+e+t[1]}repeat(e,t){let n="";for(let i=0;i<t;i++)n+=e;return n}markString(e,t,n,i){let s=this.getMark(e.type.name),o=t?s.open:s.close;return typeof o=="string"?o:o(this,e,n,i)}getEnclosingWhitespace(e){return{leading:(e.match(/^(\s+)/)||[void 0])[0],trailing:(e.match(/(\s+)$/)||[void 0])[0]}}};function Hs(r){let e={...Qe.spec.nodes.get("image"),parseDOM:[{tag:"img[src]",getAttrs:l=>Fe.validateLink(l.getAttribute("src"))?{src:l.getAttribute("src"),alt:l.getAttribute("alt"),title:l.getAttribute("title")}:!1}]},t={...Qe.spec.marks.get("link"),parseDOM:[{tag:"a[href]",getAttrs:l=>Fe.validateLink(l.getAttribute("href"))?{href:l.getAttribute("href"),title:l.getAttribute("title")}:!1}]},n=new Le({nodes:Qe.spec.nodes.update("image",e).append({source_block:{group:"block",atom:!0,attrs:{source:{}},toDOM:l=>{let a=r.createElement("div");return a.className="markdown-source-block",a.contentEditable="false",a.title="Preserved Markdown block \u2014 edit in Code",a.innerHTML=Fe.render(l.attrs.source),a}}}),marks:Qe.spec.marks.update("link",t)}),i=new Dt(n,xr.tokenizer,xr.tokens),s=new Tt({...Sr.nodes,source_block:(l,a)=>{l.write(a.attrs.source),l.closeBlock(a)}},Sr.marks);function o(l){if(typeof l!="string")throw new TypeError("Markdown editor value must be a string");let a=d=>n.nodes.source_block.create({source:d});if(/^ {0,3}\[[^\]]+\]:/m.test(l)||/^---\r?\n/.test(l))return n.node("doc",null,[a(l)]);let c=l.split(`
20
20
  `),f=Fe.parse(l,{}),h=[];for(let d of f){if(d.level!==0||!d.map||d.nesting===-1)continue;let p=c.slice(d.map[0],d.map[1]).join(`
21
21
  `);!["fence","code_block"].includes(d.type)&&(Fe.parse(p,{}).some(m=>m.type==="table_open")||/<\/?[A-Za-z][^>]*>|<!--|~~/.test(p)||/^\s*[-+*]\s+\[[ xX]\]/m.test(p))?h.push(a(p)):i.parse(p).content.forEach(m=>h.push(m))}return n.node("doc",null,h.length?h:[n.node("paragraph")])}return{schema:n,parse:o,serialize:l=>s.serialize(l)}}var ja=`.markdown-editor-control{display:flex;flex-direction:column;border:1px solid var(--gramlot-border-control,#aaa);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,white);color:var(--gramlot-ink,#243449)}
22
22
  .markdown-tools{display:flex;gap:4px;align-items:center;flex-wrap:wrap;padding:5px 8px;border-bottom:1px solid var(--gramlot-border-control,#aaa);background:var(--gramlot-surface-subtle,#edf1f7)}
23
23
  .markdown-tools button{border:0;background:transparent;color:inherit;border-radius:var(--gramlot-radius-sm,4px);padding:6px 10px;font:inherit;cursor:pointer}.markdown-tools button:hover:not(:disabled),.markdown-tools button[aria-pressed=true]{background:var(--gramlot-selected,#eaf0fc)}.markdown-tools button:disabled{opacity:.4;cursor:default}
24
- .markdown-content{flex:1;min-height:0;overflow:auto}.ProseMirror{padding:20px;min-height:100%;outline:0;white-space:pre-wrap;overflow-wrap:break-word;line-height:1.6}.ProseMirror:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}.ProseMirror pre{white-space:pre-wrap;background:var(--gramlot-surface-subtle,#edf1f7);padding:12px}.ProseMirror li{position:relative}.ProseMirror img{max-width:100%}.ProseMirror a{color:var(--gramlot-action,LinkText)}.ProseMirror blockquote{border-left:3px solid var(--gramlot-border-control,#aaa);padding-left:16px;margin-left:0}.ProseMirror table{border-collapse:collapse}.ProseMirror td,.ProseMirror th{border:1px solid var(--gramlot-border-control,#aaa);padding:6px 12px}.markdown-source-block{border:1px dashed var(--gramlot-border-control,#aaa);padding:10px;margin:12px 0;background:var(--gramlot-surface-subtle,#edf1f7);white-space:normal}.ProseMirror-selectednode{outline:2px solid var(--gramlot-focus-ring,Highlight)}.ProseMirror-hideselection *::selection{background:transparent}.ProseMirror-hideselection{caret-color:transparent}`,js=new WeakSet;function vc(r){let e=r.ownerDocument;if(!js.has(r.shadowRoot)){let m=e.createElement("style");m.textContent=ja,r.shadowRoot.append(m),js.add(r.shadowRoot)}let t=e.createElement("div");t.className="markdown-tools",t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Markdown formatting");let n=e.createElement("div");n.className="markdown-content",r.control.append(t,n);let i=r.readControlValue(),s=_s(e),o=s.parse(i),l=()=>!!(r.parameters.readonly||r.parameters.disabled),a=!1,c=!1,f,h=[];function d(){for(let{button:m,command:g,mark:y}of h)if(m.disabled=l()||!g(u.state),y){let{from:M,to:O,empty:L,$from:X}=u.state.selection;m.setAttribute("aria-pressed",String(L?!!y.isInSet(u.state.storedMarks||X.marks()):u.state.doc.rangeHasMark(M,O,y)))}c||(c=!0,queueMicrotask(()=>{if(c=!1,a)return;let m={canUndo:!l()&&Ze(u.state),canRedo:!l()&&ve(u.state)};f&&m.canUndo===f.canUndo&&m.canRedo===f.canRedo||(f=m,r.pageContext.publish("historyChanged",m))}))}let p=()=>(l()||r.pageContext.publish("save",{value:r.readControlValue()}),!0),u=new Mt(n,{state:_t.create({doc:o,plugins:[qs(),hr({"Mod-z":Ze,"Mod-Shift-z":ve,"Mod-y":ve,"Mod-b":Be(s.schema.marks.strong),"Mod-i":Be(s.schema.marks.em),"Mod-`":Be(s.schema.marks.code),"Mod-s":p}),hr(Fs)]}),editable:()=>!l(),attributes:()=>({"aria-label":"Markdown editor",role:"textbox","aria-multiline":"true","aria-readonly":String(l()),tabindex:r.parameters.disabled?"-1":"0"}),handleDOMEvents:{blur:()=>(a||r.editorBlurred(),!1),click:(m,g)=>g.target.closest("a")?(g.preventDefault(),!0):!1},dispatchTransaction:m=>{a||m.docChanged&&l()||(u.updateState(u.state.apply(m)),m.docChanged&&r.editorChanged(u.state.doc.eq(o)?i:s.serialize(u.state.doc)),d())}});for(let[m,g,y]of[["Bold",Be(s.schema.marks.strong),s.schema.marks.strong],["Italic",Be(s.schema.marks.em),s.schema.marks.em],["Code",Be(s.schema.marks.code),s.schema.marks.code],["Undo",Ze],["Redo",ve]]){let M=e.createElement("button");M.type="button",M.textContent=m,M.title=m,M.addEventListener("mousedown",O=>O.preventDefault()),M.addEventListener("click",()=>{l()||(g(u.state,u.dispatch,u),u.focus())}),t.append(M),h.push({button:M,command:g,mark:y})}return d(),{view:u,replace(m){let g=s.parse(m),y=u.state.doc.content,M=g.content,O=y.findDiffStart(M);if(O===null)return;let{a:L,b:X}=y.findDiffEnd(M),fe=O-Math.min(L,X);fe>0&&(L+=fe,X+=fe);let w=mr(u.state.tr).replace(O,L,g.slice(O,X));u.updateState(u.state.apply(w)),u.updateState(u.state.apply(mr(u.state.tr))),d()},configure(){u.setProps({editable:()=>!l()}),d()},undo(){return!l()&&Ze(u.state,u.dispatch,u)},redo(){return!l()&&ve(u.state,u.dispatch,u)},focus(){u.focus()},destroy(){a=!0,u.destroy()}}}export{vc as createMarkdownEditor};
24
+ .markdown-content{flex:1;min-height:0;overflow:auto}.ProseMirror{padding:20px;min-height:100%;outline:0;white-space:pre-wrap;overflow-wrap:break-word;line-height:1.6}.ProseMirror:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}.ProseMirror pre{white-space:pre-wrap;background:var(--gramlot-surface-subtle,#edf1f7);padding:12px}.ProseMirror li{position:relative}.ProseMirror img{max-width:100%}.ProseMirror a{color:var(--gramlot-action,LinkText)}.ProseMirror blockquote{border-left:3px solid var(--gramlot-border-control,#aaa);padding-left:16px;margin-left:0}.ProseMirror table{border-collapse:collapse}.ProseMirror td,.ProseMirror th{border:1px solid var(--gramlot-border-control,#aaa);padding:6px 12px}.markdown-source-block{border:1px dashed var(--gramlot-border-control,#aaa);padding:10px;margin:12px 0;background:var(--gramlot-surface-subtle,#edf1f7);white-space:normal}.ProseMirror-selectednode{outline:2px solid var(--gramlot-focus-ring,Highlight)}.ProseMirror-hideselection *::selection{background:transparent}.ProseMirror-hideselection{caret-color:transparent}`,_s=new WeakSet;function vc(r){let e=r.ownerDocument;if(!_s.has(r.shadowRoot)){let m=e.createElement("style");m.textContent=ja,r.shadowRoot.append(m),_s.add(r.shadowRoot)}let t=e.createElement("div");t.className="markdown-tools",t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Markdown formatting");let n=e.createElement("div");n.className="markdown-content",r.control.append(t,n);let i=r.readControlValue(),s=Hs(e),o=s.parse(i),l=()=>!!(r.parameters.readonly||r.parameters.disabled),a=!1,c=!1,f,h=[];function d(){for(let{button:m,command:g,mark:y}of h)if(m.disabled=l()||!g(u.state),y){let{from:M,to:O,empty:L,$from:X}=u.state.selection;m.setAttribute("aria-pressed",String(L?!!y.isInSet(u.state.storedMarks||X.marks()):u.state.doc.rangeHasMark(M,O,y)))}c||(c=!0,queueMicrotask(()=>{if(c=!1,a)return;let m={canUndo:!l()&&Ze(u.state),canRedo:!l()&&ve(u.state)};f&&m.canUndo===f.canUndo&&m.canRedo===f.canRedo||(f=m,r.pageContext.publish("historyChanged",m))}))}let p=()=>(l()||r.pageContext.publish("save",{value:r.readControlValue()}),!0),u=new Mt(n,{state:_t.create({doc:o,plugins:[Js(),hr({"Mod-z":Ze,"Mod-Shift-z":ve,"Mod-y":ve,"Mod-b":Be(s.schema.marks.strong),"Mod-i":Be(s.schema.marks.em),"Mod-`":Be(s.schema.marks.code),"Mod-s":p}),hr(vs)]}),editable:()=>!l(),attributes:()=>({"aria-label":"Markdown editor",role:"textbox","aria-multiline":"true","aria-readonly":String(l()),tabindex:r.parameters.disabled?"-1":"0"}),handleDOMEvents:{blur:()=>(a||r.editorBlurred(),!1),click:(m,g)=>g.target.closest("a")?(g.preventDefault(),!0):!1},dispatchTransaction:m=>{a||m.docChanged&&l()||(u.updateState(u.state.apply(m)),m.docChanged&&r.editorChanged(u.state.doc.eq(o)?i:s.serialize(u.state.doc)),d())}});for(let[m,g,y]of[["Bold",Be(s.schema.marks.strong),s.schema.marks.strong],["Italic",Be(s.schema.marks.em),s.schema.marks.em],["Code",Be(s.schema.marks.code),s.schema.marks.code],["Undo",Ze],["Redo",ve]]){let M=e.createElement("button");M.type="button",M.textContent=m,M.title=m,M.addEventListener("mousedown",O=>O.preventDefault()),M.addEventListener("click",()=>{l()||(g(u.state,u.dispatch,u),u.focus())}),t.append(M),h.push({button:M,command:g,mark:y})}return d(),{view:u,replace(m){let g=s.parse(m),y=u.state.doc.content,M=g.content,O=y.findDiffStart(M);if(O===null)return;let{a:L,b:X}=y.findDiffEnd(M),fe=O-Math.min(L,X);fe>0&&(L+=fe,X+=fe);let w=mr(u.state.tr).replace(O,L,g.slice(O,X));u.updateState(u.state.apply(w)),u.updateState(u.state.apply(mr(u.state.tr))),d()},configure(){u.setProps({editable:()=>!l()}),d()},undo(){return!l()&&Ze(u.state,u.dispatch,u)},redo(){return!l()&&ve(u.state,u.dispatch,u)},focus(){u.focus()},destroy(){a=!0,u.destroy()}}}export{vc as createMarkdownEditor};