wysio 0.0.1 → 0.2.0-alpha.0

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 (90) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +21 -0
  3. package/README.md +241 -3
  4. package/dist/auto-init.d.ts +12 -0
  5. package/dist/auto-init.d.ts.map +1 -0
  6. package/dist/cdn-full.d.ts +3 -0
  7. package/dist/cdn-full.d.ts.map +1 -0
  8. package/dist/cdn.d.ts +2 -0
  9. package/dist/cdn.d.ts.map +1 -0
  10. package/dist/commands.d.ts +19 -0
  11. package/dist/commands.d.ts.map +1 -0
  12. package/dist/content.d.ts +31 -0
  13. package/dist/content.d.ts.map +1 -0
  14. package/dist/editor.d.ts +158 -0
  15. package/dist/editor.d.ts.map +1 -0
  16. package/dist/emitter.d.ts +9 -0
  17. package/dist/emitter.d.ts.map +1 -0
  18. package/dist/format-html.d.ts +7 -0
  19. package/dist/format-html.d.ts.map +1 -0
  20. package/dist/i18n.d.ts +16 -0
  21. package/dist/i18n.d.ts.map +1 -0
  22. package/dist/icons.d.ts +34 -0
  23. package/dist/icons.d.ts.map +1 -0
  24. package/dist/index.d.ts +17 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/locales/nl.d.ts +81 -0
  27. package/dist/locales/nl.d.ts.map +1 -0
  28. package/dist/markdown/index.d.ts +17 -0
  29. package/dist/markdown/index.d.ts.map +1 -0
  30. package/dist/markdown.js +179 -0
  31. package/dist/markdown.js.map +1 -0
  32. package/dist/messages.d.ts +83 -0
  33. package/dist/messages.d.ts.map +1 -0
  34. package/dist/plugin.d.ts +94 -0
  35. package/dist/plugin.d.ts.map +1 -0
  36. package/dist/plugins/alignment.d.ts +10 -0
  37. package/dist/plugins/alignment.d.ts.map +1 -0
  38. package/dist/plugins/base.d.ts +7 -0
  39. package/dist/plugins/base.d.ts.map +1 -0
  40. package/dist/plugins/blocks.d.ts +4 -0
  41. package/dist/plugins/blocks.d.ts.map +1 -0
  42. package/dist/plugins/clear-formatting.d.ts +10 -0
  43. package/dist/plugins/clear-formatting.d.ts.map +1 -0
  44. package/dist/plugins/color.d.ts +36 -0
  45. package/dist/plugins/color.d.ts.map +1 -0
  46. package/dist/plugins/heading.d.ts +3 -0
  47. package/dist/plugins/heading.d.ts.map +1 -0
  48. package/dist/plugins/history.d.ts +2 -0
  49. package/dist/plugins/history.d.ts.map +1 -0
  50. package/dist/plugins/image.d.ts +56 -0
  51. package/dist/plugins/image.d.ts.map +1 -0
  52. package/dist/plugins/index.d.ts +29 -0
  53. package/dist/plugins/index.d.ts.map +1 -0
  54. package/dist/plugins/link.d.ts +15 -0
  55. package/dist/plugins/link.d.ts.map +1 -0
  56. package/dist/plugins/lists.d.ts +2 -0
  57. package/dist/plugins/lists.d.ts.map +1 -0
  58. package/dist/plugins/marks.d.ts +7 -0
  59. package/dist/plugins/marks.d.ts.map +1 -0
  60. package/dist/plugins/paste.d.ts +9 -0
  61. package/dist/plugins/paste.d.ts.map +1 -0
  62. package/dist/plugins/placeholder.d.ts +3 -0
  63. package/dist/plugins/placeholder.d.ts.map +1 -0
  64. package/dist/plugins/source.d.ts +5 -0
  65. package/dist/plugins/source.d.ts.map +1 -0
  66. package/dist/plugins/table.d.ts +14 -0
  67. package/dist/plugins/table.d.ts.map +1 -0
  68. package/dist/registry-BfhH2s8N.js +19 -0
  69. package/dist/registry-BfhH2s8N.js.map +1 -0
  70. package/dist/registry.d.ts +10 -0
  71. package/dist/registry.d.ts.map +1 -0
  72. package/dist/schema.d.ts +5 -0
  73. package/dist/schema.d.ts.map +1 -0
  74. package/dist/style.css +824 -0
  75. package/dist/toolbar/toolbar.d.ts +56 -0
  76. package/dist/toolbar/toolbar.d.ts.map +1 -0
  77. package/dist/ui/menu.d.ts +20 -0
  78. package/dist/ui/menu.d.ts.map +1 -0
  79. package/dist/ui/popover.d.ts +29 -0
  80. package/dist/ui/popover.d.ts.map +1 -0
  81. package/dist/url.d.ts +23 -0
  82. package/dist/url.d.ts.map +1 -0
  83. package/dist/web-component.d.ts +21 -0
  84. package/dist/web-component.d.ts.map +1 -0
  85. package/dist/wysio.full.iife.js +72 -0
  86. package/dist/wysio.iife.js +49 -0
  87. package/dist/wysio.js +2668 -0
  88. package/dist/wysio.js.map +1 -0
  89. package/package.json +68 -6
  90. package/index.js +0 -1
@@ -0,0 +1,49 @@
1
+ var Wysio=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){this.content=e}t.prototype={constructor:t,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return t==-1?void 0:this.content[t+1]},update:function(e,n,r){var i=r&&r!=e?this.remove(r):this,a=i.find(e),o=i.content.slice();return a==-1?o.push(r||e,n):(o[a+1]=n,r&&(o[a]=r)),new t(o)},remove:function(e){var n=this.find(e);if(n==-1)return this;var r=this.content.slice();return r.splice(n,2),new t(r)},addToStart:function(e,n){return new t([e,n].concat(this.remove(e).content))},addToEnd:function(e,n){var r=this.remove(e).content.slice();return r.push(e,n),new t(r)},addBefore:function(e,n,r){var i=this.remove(n),a=i.content.slice(),o=i.find(e);return a.splice(o==-1?a.length:o,0,n,r),new t(a)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return e=t.from(e),e.size?new t(e.content.concat(this.subtract(e).content)):this},append:function(e){return e=t.from(e),e.size?new t(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var n=this;e=t.from(e);for(var r=0;r<e.content.length;r+=2)n=n.remove(e.content[r]);return n},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},t.from=function(e){if(e instanceof t)return e;var n=[];if(e)for(var r in e)n.push(r,e[r]);return new t(n)};function n(e,t,r){for(let o=0;;o++){if(o==e.childCount||o==t.childCount)return e.childCount==t.childCount?null:r;let s=e.child(o),c=t.child(o);if(s==c)r+=s.nodeSize;else{if(!s.sameMarkup(c))return r;if(s.isText&&s.text!=c.text){let e=s.text,t=c.text,n=0;for(;e[n]==t[n];n++)r++;return n&&n<e.length&&n<t.length&&a(e.charCodeAt(n-1))&&i(e.charCodeAt(n))&&r--,r}if(s.content.size||c.content.size){let e=n(s.content,c.content,r+1);if(e!=null)return e}r+=s.nodeSize}}}function r(e,t,n,o){for(let s=e.childCount,c=t.childCount;;){if(s==0||c==0)return s==c?null:{a:n,b:o};let l=e.child(--s),u=t.child(--c),d=l.nodeSize;if(l==u)n-=d,o-=d;else{if(!l.sameMarkup(u))return{a:n,b:o};if(l.isText&&l.text!=u.text){let e=l.text,t=u.text,r=e.length,s=t.length;for(;r>0&&s>0&&e[r-1]==t[s-1];)r--,s--,n--,o--;return r&&s&&r<e.length&&a(e.charCodeAt(r-1))&&i(e.charCodeAt(r))&&(n++,o++),{a:n,b:o}}if(l.content.size||u.content.size){let e=r(l.content,u.content,n-1,o-1);if(e)return e}n-=d,o-=d}}}function i(e){return e>=56320&&e<57344}function a(e){return e>=55296&&e<56320}var o=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let a=0,o=0;o<t;a++){let s=this.content[a],c=o+s.nodeSize;if(c>e&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);a<t.content.length;a++)i.push(t.content[a]);return new e(i,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],i=0;if(n>t)for(let e=0,a=0;a<n;e++){let o=this.content[e],s=a+o.nodeSize;s>t&&((a<t||s>n)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.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 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 r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return n(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return r(this,e,t,n)}findIndex(e){if(e==0)return c(0,e);if(e==this.size)return c(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?c(t+1,i):c(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let i=t[e];r+=i.nodeSize,e&&i.isText&&t[e-1].sameMarkup(i)?(n||=t.slice(0,e),n[n.length-1]=i.withText(n[n.length-1].text+i.text)):n&&n.push(i)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw RangeError(`Can not convert `+t+` to a Fragment`+(t.nodesBetween?` (looks like multiple versions of prosemirror-model were loaded)`:``))}};o.empty=new o([],0);var s={index:0,offset:0};function c(e,t){return s.index=e,s.offset=t,s}function l(e,t){if(e===t)return!0;if(!(e&&typeof e==`object`)||!(t&&typeof t==`object`))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!l(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!l(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var u=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||=e.slice(0,r);else if(i.type.excludes(this.type))return e;else!n&&i.type.rank>this.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return 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&&l(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 RangeError(`Invalid input for Mark.fromJSON`);let n=e.marks[t.type];if(!n)throw 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(t){if(!t||Array.isArray(t)&&t.length==0)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};u.none=[];var d=class extends Error{},f=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=m(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(p(this.content,t+this.openStart,n+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(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(o.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};f.empty=new f(o.empty,0,0);function p(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(p(a.content,t-i-1,n-i-1)))}function m(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=m(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function h(e,t,n){if(n.openStart>e.depth)throw new d(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new d(`Inconsistent open depths`);return g(e,t,n,0)}function g(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r<e.depth-n.openStart){let o=g(e,t,n,r+1);return a.copy(a.content.replaceChild(i,o))}if(!n.content.size)return b(a,ne(e,t,r));if(!n.openStart&&!n.openEnd&&e.depth==r&&t.depth==r){let r=e.parent,i=r.content;return b(r,i.cut(0,e.parentOffset).append(n.content).append(i.cut(t.parentOffset)))}{let{start:i,end:o}=re(n,e);return b(a,te(e,i,o,t,r))}}function _(e,t){if(!t.type.compatibleContent(e.type))throw new d(`Cannot join `+t.type.name+` onto `+e.type.name)}function ee(e,t,n){let r=e.node(n);return _(r,t.node(n)),r}function v(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function y(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(v(e.nodeAfter,r),a++));for(let e=a;e<o;e++)v(i.child(e),r);t&&t.depth==n&&t.textOffset&&v(t.nodeBefore,r)}function b(e,t){if(!e.type.validContent(t))throw new d(`Invalid content for node `+e.type.name);return e.copy(t)}function te(e,t,n,r,i){let a=e.depth>i&&ee(e,t,i+1),s=r.depth>i&&ee(n,r,i+1),c=[];return y(null,e,i,c),a&&s&&t.index(i)==n.index(i)?(_(a,s),v(b(a,te(e,t,n,r,i+1)),c)):(a&&v(b(a,ne(e,t,i+1)),c),y(t,n,i,c),s&&v(b(s,ne(n,r,i+1)),c)),y(r,null,i,c),new o(c)}function ne(e,t,n){let r=[];return y(null,e,n,r),e.depth>n&&v(b(ee(e,t,n+1),ne(e,t,n+1)),r),y(t,null,n,r),new o(r)}function re(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(o.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var ie=class e{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 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 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],r=e.child(t);return n?e.child(t).cut(n):r}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],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return u.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var a=0;a<i.length;a++)i[a].type.spec.inclusive!==!1||r&&i[a].isInSet(r.marks)||(i=i[a--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)n[i].type.spec.inclusive!==!1||r&&n[i].isInSet(r.marks)||(n=n[i--].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 ce(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(t,n){if(!(n>=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=se.get(t);if(r)for(let e=0;e<r.elts.length;e++){let t=r.elts[e];if(t.pos==n)return t}else se.set(t,r=new ae);let i=r.elts[r.i]=e.resolve(t,n);return r.i=(r.i+1)%oe,i}},ae=class{constructor(){this.elts=[],this.i=0}},oe=12,se=new WeakMap,ce=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)}},le=Object.create(null),ue=class e{constructor(e,t,n,r=u.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||o.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,r=0){this.content.nodesBetween(e,t,n,r,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,r){return this.content.textBetween(e,t,n,r)}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&&l(this.attrs,t||e.defaultAttrs||le)&&u.sameSet(this.marks,n||u.none)}copy(t=null){return t==this.content?this:new e(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.content,t)}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 f.empty;let r=this.resolve(e),i=this.resolve(t),a=n?0:r.sharedDepth(t),o=r.start(a);return new f(r.node(a).content.cut(r.pos-o,i.pos-o),r.depth-a,i.depth-a)}replace(e,t,n){return h(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+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 r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return ie.resolveCached(this,e)}resolveNoCache(e){return ie.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}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()+`)`),pe(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=o.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),s=a&&a.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),a=i&&i.matchFragment(this.content,t);return a?a.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),me(this.type.attrs,this.attrs,`node`,this.type.name);let e=u.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];me(n.type.attrs,n.attrs,`mark`,n.type.name),e=n.addToSet(e)}if(!u.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.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(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=o.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,r,n)}};ue.prototype.text=void 0;var de=(()=>{let{stack:e}=Error(`/`);if(!e||!/\n\s*at\s/.test(e))return e=>e;let t=Object.create(null);return e=>(t[e],e)})(),fe=class e extends ue{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):pe(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return de(this.text.slice(e,t))}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(de(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 pe(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}function me(e,t,n,r){for(let i in t)if(!(i in e))throw RangeError(`Unsupported attribute ${i} for ${n} of type ${r}`);for(let n in e)e[n].validate&&e[n].validate(t[n])}var he=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new ge(t,n);if(r.next==null)return e.empty;let i=_e(r);r.next&&r.err(`Unexpected trailing text`);let a=De(we(i));return Oe(a,r),a}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 r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}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 r=[this];function i(a,s){let c=a.matchFragment(e,n);if(c&&(!t||c.validEnd))return o.from(s.map(e=>e.createAndFill()));for(let e=0;e<a.next.length;e++){let{type:t,next:n}=a.next[e];if(!(t.isText||t.hasRequiredAttrs())&&r.indexOf(n)==-1){r.push(n);let e=i(n,s.concat(t));if(e)return e}}return null}return i(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+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 r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:a,next:o}=i.next[e];a.isLeaf||a.hasRequiredAttrs()||a.name in t||r.type&&!o.validEnd||(n.push({match:a.contentMatch,type:a,via:r}),t[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw 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 r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((t,n)=>{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n<t.next.length;n++)r+=(n?`, `:``)+t.next[n].type.name+`->`+e.indexOf(t.next[n].next);return r}).join(`
2
+ `)}};he.empty=new he(!0);var ge=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 SyntaxError(e+` (in content expression '`+this.string+`')`)}};function _e(e){let t=[];do t.push(ve(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function ve(e){let t=[];do t.push(ye(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function ye(e){let t=Ce(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=xe(e,t);else break;return t}function be(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function xe(e,t){let n=be(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:be(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function Se(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function Ce(e){if(e.eat(`(`)){let t=_e(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=Se(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function we(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t<e.min;t++){let t=n();i(a(e.expr,o),t),o=t}if(e.max==-1)i(a(e.expr,o),o);else for(let t=e.min;t<e.max;t++){let t=n();r(o,t),i(a(e.expr,o),t),o=t}return[r(o)]}else if(e.type==`name`)return[r(t,void 0,e.value)];else throw Error(`Unknown expr type`)}}function Te(e,t){return t-e}function Ee(e,t){let n=[];return r(t),n.sort(Te);function r(t){let i=e[t];if(i.length==1&&!i[0].term)return r(i[0].to);n.push(t);for(let e=0;e<i.length;e++){let{term:t,to:a}=i[e];!t&&n.indexOf(a)==-1&&r(a)}}}function De(e){let t=Object.create(null);return n(Ee(e,0));function n(r){let i=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<i.length;e++)i[e][0]==t&&(r=i[e][1]);Ee(e,n).forEach(e=>{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new he(r.indexOf(e.length-1)>-1);for(let e=0;e<i.length;e++){let r=i[e][1].sort(Te);a.next.push({type:i[e][0],next:t[r.join(`,`)]||n(r)})}return a}}function Oe(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,a=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];a.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),r.indexOf(o)==-1&&r.push(o)}i&&t.err(`Only non-generatable nodes (`+a.join(`, `)+`) in a required position (see https://prosemirror.net/docs/guide/#generatable)`)}}function ke(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function Ae(e,t){let n=Object.create(null);for(let r in e){let i=e[r],a=t&&t[r];if(a===void 0){if(i.hasDefault)a=i.default;else throw RangeError(`No value supplied for attribute `+r)}else i.validate&&i.validate(a);n[r]=a}return n}function je(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new Pe(e,r,t[r]);return n}var Me=class e{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=je(e,n.attrs),this.defaultAttrs=ke(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==he.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:Ae(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new ue(this,this.computeAttrs(e),o.from(t),u.setFrom(n))}createChecked(e=null,t,n){return t=o.from(t),this.checkContent(t),new ue(this,this.computeAttrs(e),t,u.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=o.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(o.empty,!0);return i?new ue(this,e,t.append(i),u.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw 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||=e.slice(0,n);return t?t.length?t:u.none:e}static compile(t,n){let r=Object.create(null);t.forEach((t,i)=>r[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function Ne(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var Pe=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?Ne(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},Fe=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=je(e,r.attrs),this.excluded=null;let i=ke(this.attrs);this.instance=i?new u(this,i):null}create(e=null){return!e&&this.instance?this.instance:new u(this,Ae(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}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}},Ie=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let t in e)n[t]=e[t];n.nodes=t.from(e.nodes),n.marks=t.from(e.marks||{}),this.nodes=Me.compile(this.spec.nodes,this),this.marks=Fe.compile(this.spec.marks,this);let r=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],n=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=r[n]||(r[n]=he.parse(n,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?Le(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:Le(this,n.split(` `))}this.nodeFromJSON=e=>ue.fromJSON(this,e),this.markFromJSON=e=>u.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof Me))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new fe(n,n.defaultAttrs,e,u.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 RangeError(`Unknown node type: `+e);return t}};function Le(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],a=e.marks[i],o=a;if(a)n.push(a);else for(let t in e.marks){let r=e.marks[t];(i==`_`||r.spec.group&&r.spec.group.split(` `).indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function Re(e){return e.tag!=null}function ze(e){return e.style!=null}var Be=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(Re(e))this.tags.push(e);else if(ze(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new Ye(this,t,!1);return n.addAll(e,u.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Ye(this,t,!0);return n.addAll(e,u.none,t.from,t.to),f.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(Ze(e,n.tag)&&(n.namespace===void 0||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(t===!1)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],a=r.style;if(!(a.indexOf(e)!=0||r.context&&!n.matchesContext(r.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((e.priority==null?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=Qe(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=Qe(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},Ve={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},He={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ue={ol:!0,ul:!0},We=1,Ge=2,Ke=4;function qe(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?We:0)|(t===`full`?Ge:0)}var Je=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=u.none,this.match=i||(a&Ke?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(o.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&We)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=o.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(o.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&&!Ve.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Ye=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=qe(null,t.preserveWhitespace,0)|(n?Ke:0);i=r?new Je(r.type,r.attrs,u.none,!0,t.topMatch||r.type.contentMatch,a):n?new Je(null,null,u.none,!0,null,a):new Je(e.schema.topNodeType,null,u.none,!0,null,a),this.nodes=[i],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,r=this.top,i=r.options&Ge?`full`:this.localPreserveWS||(r.options&We)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,`
3
+ `);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(a.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(a.text(e[n]),t,!/\S/.test(e[n]));n=``}else n=n.replace(/\r?\n|\r/g,` `);n&&this.insertNode(a.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;(e.tagName==`PRE`||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let a=e.nodeName.toLowerCase(),o;Ue.hasOwnProperty(a)&&this.parser.normalizeLists&&Xe(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));e:if(s?s.ignore:He.hasOwnProperty(a))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let n,r=this.needsBlock;if(Ve.hasOwnProperty(a))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let o=s&&s.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,s,n,s.consuming===!1?o:void 0)}this.localPreserveWS=r}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 e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node){if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&=t.match.matchType(e.type);let n=u.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):$e(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&=this.enterInner(e,t,n,!0,r),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let a=this.top;a.match=a.match&&a.match.matchType(e);let o=qe(e,i,a.options);a.options&Ke&&a.content.length==0&&(o|=Ke);let s=u.none;return n=n.filter(t=>!(a.type?a.type.allowsMarkType(t.type):$e(t.type,e))||(s=t.addToSet(s),!1)),this.nodes.push(new Je(e,t,s,r,null,o)),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;else this.localPreserveWS&&(this.nodes[t].options|=We);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 t=n.length-1;t>=0;t--)e+=n[t].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 r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].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,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(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 e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function Xe(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&Ue.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function Ze(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Qe(e){let t={};for(let n in e)t[n]=e[n];return t}function $e(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||a.indexOf(i)<0&&o(i))return!0}};if(o(i.contentMatch))return!0}}var et=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||=nt(t).createDocumentFragment();let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,a=0;for(;n<i.length&&a<e.marks.length;){let t=e.marks[a];if(!this.marks[t.type.name])a++;else{if(!t.eq(i[n][0])||t.type.spec.spanning===!1)break;n++,a++}}for(;n<i.length;)r=i.pop()[1];for(;a<e.marks.length;){let n=e.marks[a++],o=this.serializeMark(n,e.isInline,t);o&&(i.push([n,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return nt(t).createTextNode(e.text);let{dom:n,contentDOM:r}=ot(nt(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError(`Content hole not allowed in a leaf node spec`);this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&ot(nt(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t==`string`?{dom:e.createTextNode(t)}:ot(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=tt(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return tt(e.marks)}};function tt(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function nt(e){return e.document||window.document}var rt=new WeakMap;function it(e){let t=rt.get(e);return t===void 0&&rt.set(e,t=at(e)),t}function at(e){let t=null;function n(e){if(e&&typeof e==`object`){if(Array.isArray(e)){if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t<e.length;t++)n(e[t])}else for(let t in e)n(e[t])}}return n(e),t}function ot(e,t,n,r){if(t.nodeType==1)return{dom:t};if(t.dom&&t.dom.nodeType==1)return t;let i=t[0],a;if(typeof i!=`string`)throw RangeError(`Invalid array passed to renderSpec`);if(r&&(a=it(r))&&a.indexOf(t)>-1)throw 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&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;i<t.length;i++){let a=t[i];if(a===0){if(i<t.length-1||i>u)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}if(typeof a==`string`)c.appendChild(e.createTextNode(a));else{let{dom:t,contentDOM:i}=ot(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var st=65535,ct=2**16;function lt(e,t){return e+t*ct}function ut(e){return e&st}function dt(e){return(e-(e&st))/ct}var ft=1,pt=2,mt=4,ht=8,gt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&ht)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&mt)>0}},_t=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=ut(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+dt(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 r=0,i=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let s=this.ranges[o]-(this.inverted?r:0);if(s>e)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:lt(o/3,e-s),f=0;return c&&(f|=e==s?pt:e==u?ft:mt,(t<0?e!=s:e!=u)&&(f|=ht)),new gt(a,f,d)}r+=l-c}return n?e+r:new gt(e+r,0,null)}touches(e,t){let n=0,r=ut(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let o=this.ranges[t]-(this.inverted?n:0);if(o>e)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let a=this.ranges[r],o=a-(this.inverted?i:0),s=a+(this.inverted?0:i),c=this.ranges[r+t],l=this.ranges[r+n];e(o,o+c,s,s+l),i+=l-c}}invert(){return new e(this.ranges,!this.inverted)}toString(){return(this.inverted?`-`:``)+JSON.stringify(this.ranges)}static offset(t){return t==0?e.empty:new e(t<0?[0,-t,0]:[0,0,t])}};_t.empty=new _t([]);var vt=class e{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(t=0,n=this.maps.length){return new e(this._maps,this.mirror,t,n)}appendMap(e,t){this.ownData||=(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=e.from,n=this._maps.length;t<e.to;t++){let r=e.getMirror(t);r!=null&&(r=r<t&&r>=e.from?n+(r-e.from):void 0),this.appendMap(e._maps[t],r)}}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.push(e,t)}appendMappingInverted(e){for(let t=e.to-1,n=this._maps.length+e._maps.length;t>=e.from;t--){let r=e.getMirror(t);r!=null&&(r=r>t&&r<e.to?n-(r-e.from)-1:void 0),this.appendMap(e._maps[t].invert(),r)}}invert(){let t=new e;return t.appendMappingInverted(this),t}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 r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(i.recover!=null){let t=this.getMirror(n);if(t!=null&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new gt(e,r,null)}},yt=Object.create(null),x=class{getMap(){return _t.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError(`Invalid input for Step.fromJSON`);let n=yt[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in yt)throw RangeError(`Duplicate use of step JSON ID `+e);return yt[e]=t,t.prototype.jsonID=e,t}},S=class e{constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,i){try{return e.ok(t.replace(n,r,i))}catch(t){if(t instanceof d)return e.fail(t.message);throw t}}};function bt(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let a=e.child(i);a.content.size&&(a=a.copy(bt(a.content,t,a))),a.isInline&&(a=t(a,n,i)),r.push(a)}return o.fromArray(r)}var xt=class e extends x{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),r=n.node(n.sharedDepth(this.to)),i=new f(bt(t.content,(e,t)=>!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return S.fromReplace(e,this.from,this.to,i)}invert(t){let n=[];return t.nodesBetween(this.from,this.to,(t,r)=>{if(t.isInline&&t.isAtom){let i=this.mark.addToSet(t.marks);if(!u.sameSet(i,t.marks)){let a=Math.max(this.from,r),o=Math.min(this.to,r+t.nodeSize);Ct(St,a,o,this.mark,n);for(let r of t.marks)r.isInSet(i)||Ct(e,a,o,r,n)}}}),n.length==1?n[0]:new wt(n)}map(t){let n=t.map(this.from,1),r=t.map(this.to,-1);return n>=r?null:new e(n,r,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};x.jsonID(`addMark`,xt);var St=class e extends x{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 f(bt(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return S.fromReplace(e,this.from,this.to,n)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(e,n)=>{e.isInline&&e.isAtom&&this.mark.isInSet(e.marks)&&Ct(xt,Math.max(this.from,n),Math.min(this.to,n+e.nodeSize),this.mark,t)}),t.length==1?t[0]:new wt(t)}map(t){let n=t.map(this.from,1),r=t.map(this.to,-1);return n>=r?null:new e(n,r,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};x.jsonID(`removeMark`,St);function Ct(e,t,n,r,i){let a=i.length?i[i.length-1]:null;a&&a instanceof e&&a.to==t&&a.mark.eq(r)?i[i.length-1]=new e(a.from,n,r):i.push(new e(t,n,r))}var wt=class e extends x{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 S(e,null)}invert(t){return new e(this.steps.map(e=>e.invert(t)))}map(t){let n=[];for(let e of this.steps){let r=e.map(t);r&&n.push(r)}return n.length?new e(n):null}toJSON(){return{stepType:`markSet`,steps:this.steps.map(e=>e.toJSON())}}static fromJSON(t,n){if(!Array.isArray(n.steps)||!n.steps.every(e=>e.stepType==`addMark`||e.stepType==`removeMark`))throw RangeError(`Invalid JSON for MarkSetStep`);return new e(n.steps.map(e=>x.fromJSON(t,e)))}};x.jsonID(`markSet`,wt);var Tt=class e extends x{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return S.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return S.fromReplace(e,this.pos,this.pos+1,new f(o.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(t))return new e(this.pos,n.marks[r]);return new e(this.pos,this.mark)}}return new Et(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`addNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for AddNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};x.jsonID(`addNodeMark`,Tt);var Et=class e extends x{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return S.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return S.fromReplace(e,this.pos,this.pos+1,new f(o.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Tt(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`removeNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for RemoveNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};x.jsonID(`removeNodeMark`,Et);var Dt=class e extends x{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Ot(e,this.from,this.to)?S.fail(`Structure replace would overwrite content`):S.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new _t([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.to,-1),r=this.from==this.to&&e.MAP_BIAS<0?n:t.mapResult(this.from,1);return r.deletedAcross&&n.deletedAcross?null:new e(r.pos,Math.max(r.pos,n.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?f.empty:new f(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new e(this.from,this.to+(t.to-t.from),n,this.structure)}if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?f.empty:new f(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new e(t.from,this.to,n,this.structure)}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(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for ReplaceStep.fromJSON`);return new e(n.from,n.to,f.fromJSON(t,n.slice),!!n.structure)}};Dt.MAP_BIAS=1,x.jsonID(`replace`,Dt);var C=class e extends x{constructor(e,t,n,r,i,a,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=a,this.structure=o}apply(e){if(this.structure&&(Ot(e,this.from,this.gapFrom)||Ot(e,this.gapTo,this.to)))return S.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return S.fail(`Gap is not a flat range`);let n=this.slice.insertAt(this.insert,t.content);return n?S.fromReplace(e,this.from,this.to,n):S.fail(`Content does not fit in gap`)}getMap(){return new _t([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),a=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||a>r.pos||i>a?null:new e(n.pos,r.pos,i,a,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(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,f.fromJSON(t,n.slice),n.insert,!!n.structure)}};x.jsonID(`replaceAround`,C);function Ot(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function kt(e,t,n,r){let i=[];e.doc.nodesBetween(t,n,(e,a,o)=>{if(!e.isInline)return;let s=e.marks;!r.isInSet(s)&&o.type.allowsMarkType(r.type)&&Ct(xt,Math.max(a,t),Math.min(a+e.nodeSize,n),r,i)}),i.forEach(t=>e.step(t))}function At(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline||!e.isAtom)return;a++;let s=null;if(r instanceof Fe){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;e<s.length;e++){let n=s[e],c;for(let e=0;e<i.length;e++){let t=i[e];t.step==a-1&&n.eq(i[e].style)&&(c=t)}c?(c.to=r,c.step=a):i.push({style:n,from:Math.max(o,t),to:r,step:a})}}}),i.forEach(t=>e.step(new St(t.from,t.to,t.style)))}function jt(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),s=[],c=t+1;for(let t=0;t<a.childCount;t++){let l=a.child(t),u=c+l.nodeSize,d=r.matchType(l.type);if(!d)s.push(new Dt(c,u,f.empty));else{r=d;for(let t=0;t<l.marks.length;t++)n.allowsMarkType(l.marks[t].type)||e.step(new St(c,u,l.marks[t]));if(i&&l.isText&&n.whitespace!=`pre`){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(l.text);)r||=new f(o.from(n.schema.text(` `,n.allowedMarks(l.marks))),0,0),s.push(new Dt(c+e.index,c+e.index+e[0].length,r))}}c=u}if(!r.validEnd){let t=r.fillBefore(o.empty,!0);e.replace(c,c,new f(t,0,0))}for(let t=s.length-1;t>=0;t--)e.step(s[t])}function Mt(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Nt(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(n<e.depth&&a.canReplace(o,s,t))return n;if(n==0||a.type.spec.isolating||!Mt(a,o,s))break;o&&(r=1),s<a.childCount&&(i=1)}return null}function Pt(e,t,n){let{$from:r,$to:i,depth:a}=t,s=r.before(a+1),c=i.after(a+1),l=s,u=c,d=o.empty,p=0;for(let e=a,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=o.from(r.node(e).copy(d)),p++):l--;let m=o.empty,h=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,m=o.from(i.node(e).copy(m)),h++):u++;e.step(new C(l,u,s,c,new f(d.append(m),p,h),d.size-p,!0))}function Ft(e,t,n=null,r=e){let i=Lt(e,t),a=i&&Rt(r,t);return a?i.map(It).concat({type:t,attrs:n}).concat(a.map(It)):null}function It(e){return{type:e,attrs:null}}function Lt(e,t){let{parent:n,startIndex:r,endIndex:i}=e,a=n.contentMatchAt(r).findWrapping(t);if(!a)return null;let o=a.length?a[0]:t;return n.canReplaceWith(r,i,o)?a:null}function Rt(e,t){let{parent:n,startIndex:r,endIndex:i}=e,a=n.child(r),o=t.contentMatch.findWrapping(a.type);if(!o)return null;let s=(o.length?o[o.length-1]:t).contentMatch;for(let e=r;s&&e<i;e++)s=s.matchType(n.child(e).type);return!s||!s.validEnd?null:o}function zt(e,t,n){let r=o.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=o.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new C(i,a,i,a,new f(r,0,0),n.length,!0))}function Bt(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let s=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,s)&&Ut(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&Ht(e,t,n,a),jt(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let c=e.mapping.slice(a),l=c.map(n,1),u=c.map(n+t.nodeSize,1);return e.step(new C(l,u,l+1,u-1,new f(o.from(r.create(s,null,t.marks)),0,0),1,!0)),i===!0&&Vt(e,t,n,a),!1}})}function Vt(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function Ht(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(`
5
+ `))}})}function Ut(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function Wt(e,t,n,r,i){let a=e.doc.nodeAt(t);if(!a)throw RangeError(`No node at given position`);n||=a.type;let s=n.create(r,null,i||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,s);if(!n.validContent(a.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new C(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new f(o.from(s),0,0),1,!0))}function Gt(e,t,n=1,r){let i=e.resolve(t),a=i.depth-n,o=r&&r[r.length-1]||i.parent;if(a<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 e=i.depth-1,t=n-2;e>a;e--,t--){let n=i.node(e),a=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(a,n.childCount),s=r&&r[t+1];s&&(o=o.replaceChild(0,s.type.create(s.attrs)));let c=r&&r[t]||n;if(!n.canReplace(a+1,n.childCount)||!c.type.validContent(o))return!1}let s=i.indexAfter(a),c=r&&r[0];return i.node(a).canReplaceWith(s,s,c?c.type:i.node(a+1).type)}function Kt(e,t,n=1,r){let i=e.doc.resolve(t),a=o.empty,s=o.empty;for(let e=i.depth,t=i.depth-n,c=n-1;e>t;e--,c--){a=o.from(i.node(e).copy(a));let t=r&&r[c];s=o.from(t?t.type.create(t.attrs,s):i.node(e).copy(s))}e.step(new Dt(t,t,new f(a.append(s),n,n),!0))}function qt(e,t){let n=e.resolve(t),r=n.index();return Yt(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Jt(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let a=t.child(i),o=a.type==r?e.type.schema.nodes.text:a.type;if(n=n.matchType(o),!n||!e.type.allowsMarks(a.marks))return!1}return n.validEnd}function Yt(e,t){return!!(e&&t&&!e.isLeaf&&Jt(e,t))}function Xt(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,a=e.doc.resolve(t-n),o=a.node().type;if(i&&o.inlineContent){let e=o.whitespace==`pre`,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let s=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);Ht(e,r.node(),r.before(),s)}o.inlineContent&&jt(e,t+n-1,o,a.node().contentMatchAt(a.index()),r==null);let c=e.mapping.slice(s),l=c.map(t-n);if(e.step(new Dt(l,c.map(t+n,-1),f.empty,!0)),r===!0){let t=e.doc.resolve(l);Vt(e,t.node(),t.before(),e.steps.length)}return e}function Zt(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)return null}return null}function Qt(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(n.openStart==0&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1;for(let a=0;a<2;a++){if(a){if(!n)break;n=-n}let o=r.index(t)+ +(n>0),s=r.node(t),c=!1;if(e==1)c=s.canReplace(o,o,i);else{let e=s.contentMatchAt(o).findWrapping(i.firstChild.type);c=e&&s.canReplaceWith(o,o,e[0])}if(c)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}}return null}function $t(e,t,n=t,r=f.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),a=e.resolve(n);return en(i,a,r)?new Dt(t,n,r):new tn(i,a,r).fit()}function en(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var tn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=o.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=o.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,a=n.depth,o=r.depth;for(;a&&o&&i.childCount==1;)i=i.firstChild.content,a--,o--;let s=new f(i,a,o);return e>-1?new C(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new Dt(n.pos,r.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=an(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:a,match:s}=this.frontier[e],c,l=null;if(t==1&&(i?s.matchType(i.type)||(l=s.fillBefore(o.from(i),!1)):r&&a.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:l};if(t==2&&i&&(c=s.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:c};if(r&&s.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return un(e,-1)<=t?!1:(this.unplaced.size>1&&un(e,1)>n&&n++,this.unplaced=new f(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=an(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new f(nn(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new f(nn(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let a=this.unplaced,s=n?n.content:a.content,c=a.openStart-e,l=0,u=[],{match:d,type:p}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)u.push(r.child(e));d=d.matchFragment(r)}let m=s.size+e-(a.content.size-a.openEnd);for(;l<s.childCount;){let e=s.child(l),t=d.matchType(e.type);if(!t)break;l++,(l>1||c==0||e.content.size)&&(d=t,u.push(on(e.mark(p.allowedMarks(e.marks)),l==1?c:0,l==s.childCount?m:-1)))}let h=l==s.childCount;h||(m=-1),this.placed=rn(this.placed,t,o.from(u)),this.frontier[t].match=d,h&&m<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=u[u.length-1];t&&e<m;e++)this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)}),t=t.lastChild;this.unplaced=h?e==0?f.empty:new f(nn(a.content,e-1,1),e-1,m<0?a.openEnd:e-1):new f(nn(a.content,e,l),e,a.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!sn(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,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),a=sn(e,t,r,n,i);if(a){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=sn(e,n,r,t,!0);if(!i||i.childCount)continue e}return{depth:t,fit:a,move:i?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=rn(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=rn(this.placed,this.depth,o.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(o.empty,!0);e.childCount&&(this.placed=rn(this.placed,this.frontier.length,e))}};function nn(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(nn(e.firstChild.content,t-1,n)))}function rn(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(rn(e.lastChild.content,t-1,n)))}function an(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function on(e,t,n){if(t<=0)return e;let r=e.content;return t>1&&(r=r.replaceChild(0,on(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(o.empty,!0)))),e.copy(r)}function sn(e,t,n,r,i){let a=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==a.childCount&&!n.compatibleContent(a.type))return null;let s=r.fillBefore(a.content,!0,o);return s&&!cn(n,a.content,o)?s:null}function cn(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}function ln(e){return e.spec.defining||e.spec.definingForContent}function un(e,t){for(let n=0;;n++){let r=t<0?e.firstChild:e.lastChild;if(!r||r.isAtom)return n;e=r.content}}function dn(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),a=e.doc.resolve(n);if(en(i,a,r))return e.step(new Dt(t,n,r));let o=hn(i,a);o[o.length-1]==0&&o.pop();let s=-(i.depth+1);o.unshift(s);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?s=e:i.before(e)==t&&o.splice(1,0,-e)}let c=o.indexOf(s),l=[],u=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(l.push(n),t==r.openStart)break;e=n.content}for(let e=u-1;e>=0;e--){let t=l[e],n=ln(t.type);if(n&&!t.sameMarkup(i.node(Math.abs(s)-1)))u=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let s=(t+u+1)%(r.openStart+1),d=l[s];if(d)for(let t=0;t<o.length;t++){let l=o[(t+c)%o.length],u=!0;l<0&&(u=!1,l=-l);let p=i.node(l-1),m=i.index(l-1);if(p.canReplaceWith(m,m,d.type,d.marks))return e.replace(i.before(l),u?a.after(l):n,new f(fn(r.content,0,r.openStart,s),s,r.openEnd))}}let d=e.steps.length;for(let s=o.length-1;s>=0&&(e.replace(t,n,r),!(e.steps.length>d));s--){let e=o[s];e<0||(t=i.before(e),n=a.after(e))}}function fn(e,t,n,r,i){if(t<n){let i=e.firstChild;e=e.replaceChild(0,i.copy(fn(i.content,t+1,n,r,i)))}if(t>r){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(o.empty,!0))}return e}function pn(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=Zt(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new f(o.from(r),0,0))}function mn(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let a=r.sharedDepth(n),o=!1;for(let e=r.depth;e>a;e--)r.node(e).type.spec.isolating&&(o=!0);for(let e=i.depth;e>a;e--)i.node(e).type.spec.isolating&&(o=!0);if(!o){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let a=hn(r,i);for(let t=0;t<a.length;t++){let n=a[t],o=t==a.length-1;if(o&&n==0||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function hn(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}var gn=class e extends x{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 S.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return S.fromReplace(e,this.pos,this.pos+1,new f(o.from(r),0,+!t.isLeaf))}getMap(){return _t.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};x.jsonID(`attr`,gn);var _n=class e extends x{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return S.ok(n)}getMap(){return _t.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};x.jsonID(`docAttr`,_n);var vn=class extends Error{};vn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},vn.prototype=Object.create(Error.prototype),vn.prototype.constructor=vn,vn.prototype.name=`TransformError`;var yn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new vt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new vn(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 r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,a)=>{e=Math.min(e,i),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=f.empty){let r=$t(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new f(o.from(n),0,0))}delete(e,t){return this.replace(e,t,f.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return dn(this,e,t,n),this}replaceRangeWith(e,t,n){return pn(this,e,t,n),this}deleteRange(e,t){return mn(this,e,t),this}lift(e,t){return Pt(this,e,t),this}join(e,t=1){return Xt(this,e,t),this}wrap(e,t){return zt(this,e,t),this}setBlockType(e,t=e,n,r=null){return Bt(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return Wt(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new gn(e,t,n)),this}setDocAttribute(e,t){return this.step(new _n(e,t)),this}addNodeMark(e,t){return this.step(new Tt(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof u)t.isInSet(n.marks)&&this.step(new Et(e,t));else{let r=n.marks,i,a=[];for(;i=t.isInSet(r);)a.push(new Et(e,i)),r=i.removeFromSet(r);for(let e=a.length-1;e>=0;e--)this.step(a[e])}return this}split(e,t=1,n){return Kt(this,e,t,n),this}addMark(e,t,n){return kt(this,e,t,n),this}removeMark(e,t,n){return At(this,e,t,n),this}clearIncompatible(e,t,n){return jt(this,e,t,n),this}},bn=Object.create(null),w=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new xn(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=f.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:s,$to:c}=a[o],l=e.mapping.slice(i);e.replaceRange(l.map(s.pos),l.map(c.pos),o?f.empty:t),o==0&&kn(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n),c=s.map(a.pos),l=s.map(o.pos);i?e.deleteRange(c,l):(e.replaceRangeWith(c,l,t),kn(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new T(e):On(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?On(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):On(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new En(e.node(0))}static atStart(e){return On(e,e,0,0,1)||new En(e)}static atEnd(e){return On(e,e,e.content.size,e.childCount,-1)||new En(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=bn[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in bn)throw RangeError(`Duplicate use of selection JSON ID `+e);return bn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return T.between(this.$anchor,this.$head).getBookmark()}};w.prototype.visible=!0;var xn=class{constructor(e,t){this.$from=e,this.$to=t}},Sn=!1;function Cn(e){!Sn&&!e.parent.inlineContent&&(Sn=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var T=class e extends w{constructor(e,t=e){Cn(e),Cn(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return w.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}replace(e,t=f.empty){if(super.replace(e,t),t==f.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new wn(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let e=w.findFrom(n,r,!0)||w.findFrom(n,-r,!0);if(e)n=e.$head;else return w.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(w.findFrom(t,-r,!0)||w.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new e(t,n)}};w.jsonID(`text`,T);var wn=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return T.between(e.resolve(this.anchor),e.resolve(this.head))}},E=class e extends w{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(t,n){let{deleted:r,pos:i}=n.mapResult(this.anchor),a=t.resolve(i);return r?w.near(a):new e(a)}content(){return new f(o.from(this.node),0,0)}eq(t){return t instanceof e&&t.anchor==this.anchor}toJSON(){return{type:`node`,anchor:this.anchor}}getBookmark(){return new Tn(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!=`number`)throw RangeError(`Invalid input for NodeSelection.fromJSON`);return new e(t.resolve(n.anchor))}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};E.prototype.visible=!1,w.jsonID(`node`,E);var Tn=class e{constructor(e){this.anchor=e}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new wn(r,r):new e(r)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&E.isSelectable(n)?new E(t):w.near(t)}},En=class e extends w{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=f.empty){if(t==f.empty){e.delete(0,e.doc.content.size);let t=w.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:`all`}}static fromJSON(t){return new e(t)}map(t){return new e(t)}eq(t){return t instanceof e}getBookmark(){return Dn}};w.jsonID(`all`,En);var Dn={map(){return this},resolve(e){return new En(e)}};function On(e,t,n,r,i,a=!1){if(t.inlineContent)return T.create(e,n);for(let o=r-(i>0?0:1);i>0?o<t.childCount:o>=0;o+=i){let r=t.child(o);if(!r.isAtom){let t=On(e,r,n+i,i<0?r.childCount:0,i,a);if(t)return t}else if(!a&&E.isSelectable(r))return E.create(e,n-(i<0?r.nodeSize:0));n+=r.nodeSize*i}return null}function kn(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof Dt||i instanceof C))return;let a=e.mapping.maps[r],o;a.forEach((e,t,n,r)=>{o??=r}),e.setSelection(w.near(e.doc.resolve(o),n))}var An=1,jn=2,Mn=4,Nn=class extends yn{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 RangeError(`Selection passed to setSelection must point at the current document`);return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|An)&-3,this.storedMarks=null,this}get selectionSet(){return(this.updated&An)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=jn,this}ensureMarks(e){return u.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&jn)>0}addStep(e,t){super.addStep(e,t),this.updated&=-3,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)||u.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(w.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|=Mn,this}get scrolledIntoView(){return(this.updated&Mn)>0}};function Pn(e,t){return!t||!e?e:e.bind(t)}var Fn=class{constructor(e,t,n){this.name=e,this.init=Pn(t.init,n),this.apply=Pn(t.apply,n)}},In=[new Fn(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Fn(`selection`,{init(e,t){return e.selection||w.atStart(t.doc)},apply(e){return e.selection}}),new Fn(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Fn(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],Ln=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=In.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new Fn(e.key,e.spec.state,e))})}},Rn=class e{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 t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let a=0;a<this.config.plugins.length;a++){let o=this.config.plugins[a];if(o.spec.appendTransaction){let s=r?r[a].n:0,c=r?r[a].state:this,l=s<t.length&&o.spec.appendTransaction.call(o,s?t.slice(s):t,c,n);if(l&&n.filterTransaction(l,a)){if(l.setMeta(`appendedTransaction`,e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<a?{state:n,n:t.length}:{state:this,n:0})}t.push(l),n=n.applyInner(l),i=!0}r&&(r[a]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(t){if(!t.before.eq(this.doc))throw RangeError(`Applying a mismatched transaction`);let n=new e(this.config),r=this.config.fields;for(let e=0;e<r.length;e++){let i=r[e];n[i.name]=i.apply(t,this[i.name],this,n)}return n}get tr(){return new Nn(this)}static create(t){let n=new Ln(t.doc?t.doc.type.schema:t.schema,t.plugins),r=new e(n);for(let e=0;e<n.fields.length;e++)r[n.fields[e].name]=n.fields[e].init(t,r);return r}reconfigure(t){let n=new Ln(this.schema,t.plugins),r=n.fields,i=new e(n);for(let e=0;e<r.length;e++){let n=r[e].name;i[n]=this.hasOwnProperty(n)?this[n]:r[e].init(t,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let i=new Ln(t.schema,t.plugins),a=new e(i);return i.fields.forEach(e=>{if(e.name==`doc`)a.doc=ue.fromJSON(t.schema,n.doc);else if(e.name==`selection`)a.selection=w.fromJSON(a.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(a.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let i in r){let o=r[i],s=o.spec.state;if(o.key==e.name&&s&&s.fromJSON&&Object.prototype.hasOwnProperty.call(n,i)){a[e.name]=s.fromJSON.call(o,t,n[i],a);return}}a[e.name]=e.init(t,a)}}),a}};function zn(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r==`handleDOMEvents`&&(i=zn(i,t,{})),n[r]=i}return n}var Bn=class{constructor(e){this.spec=e,this.props={},e.props&&zn(e.props,this,this.props),this.key=e.key?e.key.key:Hn(`plugin`)}getState(e){return e[this.key]}},Vn=Object.create(null);function Hn(e){return e in Vn?e+`$`+ ++Vn[e]:(Vn[e]=0,e+`$`)}var Un=class{constructor(e=`key`){this.key=Hn(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},Wn=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Gn(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var Kn=(e,t,n)=>{let r=Gn(e,n);if(!r)return!1;let i=Yn(r);if(!i){let n=r.blockRange(),i=n&&Nt(n);return i!=null&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let a=i.nodeBefore;if(ur(e,i,t,-1))return!0;if(r.parent.content.size==0&&(qn(a,`end`)||E.isSelectable(a)))for(let n=r.depth;;n--){let o=$t(e.doc,r.before(n),r.after(n),f.empty);if(o&&o.slice.size<o.to-o.from){if(t){let n=e.tr.step(o);n.setSelection(qn(a,`end`)?w.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):E.create(n.doc,i.pos-a.nodeSize)),t(n.scrollIntoView())}return!0}if(n==1||r.node(n-1).childCount>1)break}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos-a.nodeSize,i.pos).scrollIntoView()),!0):!1};function qn(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Jn=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;a=Yn(r)}let o=a&&a.nodeBefore;return!o||!E.isSelectable(o)?!1:(t&&t(e.tr.setSelection(E.create(e.doc,a.pos-o.nodeSize)).scrollIntoView()),!0)};function Yn(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function Xn(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset<n.parent.content.size)?null:n}var Zn=(e,t,n)=>{let r=Xn(e,n);if(!r)return!1;let i=$n(r);if(!i)return!1;let a=i.nodeAfter;if(ur(e,i,t,1))return!0;if(r.parent.content.size==0&&(qn(a,`start`)||E.isSelectable(a))){let n=$t(e.doc,r.before(),r.after(),f.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(qn(a,`start`)?w.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):E.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos,i.pos+a.nodeSize).scrollIntoView()),!0):!1},Qn=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset<r.parent.content.size)return!1;a=$n(r)}let o=a&&a.nodeAfter;return!o||!E.isSelectable(o)?!1:(t&&t(e.tr.setSelection(E.create(e.doc,a.pos)).scrollIntoView()),!0)};function $n(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}var er=(e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),a=i&&Nt(i);return a!=null&&(t&&t(e.tr.lift(i,a).scrollIntoView()),!0)},tr=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(`
6
+ `).scrollIntoView()),!0)};function nr(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var rr=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),a=n.indexAfter(-1),o=nr(i.contentMatchAt(a));if(!o||!i.canReplaceWith(a,a,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(w.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},ir=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof En||r.parent.inlineContent||i.parent.inlineContent)return!1;let a=nr(i.parent.contentMatchAt(i.indexAfter()));if(!a||!a.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,o=e.tr.insert(n,a.createAndFill());o.setSelection(T.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},ar=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(Gt(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Nt(r);return i!=null&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function or(e){return(t,n)=>{if(t.selection instanceof E&&t.selection.node.isBlock){let{$from:e}=t.selection;return!e.parentOffset||!Gt(t.doc,e.pos)?!1:(n&&n(t.tr.split(e.pos).scrollIntoView()),!0)}if(!t.selection.$from.depth)return!1;let r=t.tr;!t.selection.empty&&(t.selection instanceof T||t.selection instanceof En)&&r.deleteSelection();let{$from:i}=r.selection,a=r.steps.length,o=[],s,c,l=!1,u=!1;for(let t=i.depth;;t--)if(i.node(t).isBlock){l=i.end(t)==i.pos+(i.depth-t),u=i.start(t)==i.pos-(i.depth-t),c=nr(i.node(t-1).contentMatchAt(i.indexAfter(t-1)));let n=e&&e(i.parent,l,i);o.unshift(n||(l&&c?{type:c}:null)),s=t;break}else{if(t==1)return!1;o.unshift(null)}let d=i.pos,f=Gt(r.doc,d,o.length,o);if(f||=(o[0]=c?{type:c}:null,Gt(r.doc,d,o.length,o)),!f)return!1;if(r.split(d,o.length,o),!l&&u&&i.node(s).type!=c){let e=r.mapping.slice(a),t=e.map(i.before(s)),n=r.doc.resolve(t);c&&i.node(s-1).canReplaceWith(n.index(),n.index()+1,c)&&r.setNodeMarkup(e.map(i.before(s)),c)}return n&&n(r.scrollIntoView()),!0}}var sr=or(),cr=(e,t)=>(t&&t(e.tr.setSelection(new En(e.doc))),!0);function lr(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,a=t.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&t.parent.canReplace(a-1,a)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(a,a+1)||!(i.isTextblock||qt(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function ur(e,t,n,r){let i=t.nodeBefore,a=t.nodeAfter,s,c,l=i.type.spec.isolating||a.type.spec.isolating;if(!l&&lr(e,t,n))return!0;let u=!l&&t.parent.canReplace(t.index(),t.index()+1);if(u&&(s=(c=i.contentMatchAt(i.childCount)).findWrapping(a.type))&&c.matchType(s[0]||a.type).validEnd){if(n){let r=t.pos+a.nodeSize,c=o.empty;for(let e=s.length-1;e>=0;e--)c=o.from(s[e].create(null,c));c=o.from(i.copy(c));let l=e.tr.step(new C(t.pos-1,r,t.pos,r,new f(c,1,0),s.length,!0)),u=l.doc.resolve(r+2*s.length);u.nodeAfter&&u.nodeAfter.type==i.type&&qt(l.doc,u.pos)&&l.join(u.pos),n(l.scrollIntoView())}return!0}let d=a.type.spec.isolating||r>0&&l?null:w.findFrom(t,1),p=d&&d.$from.blockRange(d.$to),m=p&&Nt(p);if(m!=null&&m>=t.depth)return n&&n(e.tr.lift(p,m).scrollIntoView()),!0;if(u&&qn(a,`start`,!0)&&qn(i,`end`)){let r=i,s=[];for(;s.push(r),!r.isTextblock;)r=r.lastChild;let c=a,l=1;for(;!c.isTextblock;c=c.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,c.content)){if(n){let r=o.empty;for(let e=s.length-1;e>=0;e--)r=o.from(s[e].copy(r));n(e.tr.step(new C(t.pos-s.length,t.pos+a.nodeSize,t.pos+l,t.pos+a.nodeSize-l,new f(r,s.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function dr(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,a=i.depth;for(;i.node(a).isInline;){if(!a)return!1;a--}return i.node(a).isTextblock?(n&&n(t.tr.setSelection(T.create(t.doc,e<0?i.start(a):i.end(a)))),!0):!1}}var fr=dr(-1),pr=dr(1);function mr(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a),s=o&&Ft(o,e,t);return s?(r&&r(n.tr.wrap(o,s).scrollIntoView()),!0):!1}}function hr(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:a},$to:{pos:o}}=n.selection.ranges[r];n.doc.nodesBetween(a,o,(r,a)=>{if(i)return!1;if(r.isTextblock&&!r.hasMarkup(e,t)){if(r.type==e)i=!0;else{let t=n.doc.resolve(a),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:a},$to:{pos:o}}=n.selection.ranges[r];i.setBlockType(a,o,e,t)}r(i.scrollIntoView())}return!0}}function gr(e,t,n,r){for(let i=0;i<t.length;i++){let{$from:a,$to:o}=t[i],s=a.depth==0&&e.inlineContent&&e.type.allowsMarkType(n);if(e.nodesBetween(a.pos,o.pos,(e,t)=>{if(s||!r&&e.isAtom&&e.isInline&&t>=a.pos&&t+e.nodeSize<=o.pos)return!1;s=e.inlineContent&&e.type.allowsMarkType(n)}),s)return!0}return!1}function _r(e){let t=[];for(let n=0;n<e.length;n++){let{$from:r,$to:i}=e[n];r.doc.nodesBetween(r.pos,i.pos,(e,n)=>{if(e.isAtom&&e.content.size&&e.isInline&&n>=r.pos&&n+e.nodeSize<=i.pos)return n+1>r.pos&&t.push(new xn(r,r.doc.resolve(n+1))),r=r.doc.resolve(n+1+e.content.size),!1}),r.pos<i.pos&&t.push(new xn(r,i))}return t}function vr(e,t=null,n){let r=(n&&n.removeWhenPresent)!==!1,i=(n&&n.enterInlineAtoms)!==!1,a=!(n&&n.includeWhitespace);return function(n,o){let{empty:s,$cursor:c,ranges:l}=n.selection;if(s&&!c||!gr(n.doc,l,e,i))return!1;if(o){if(c)e.isInSet(n.storedMarks||c.marks())?o(n.tr.removeStoredMark(e)):o(n.tr.addStoredMark(e.create(t)));else{let s,c=n.tr;i||(l=_r(l)),s=r?!l.some(t=>n.doc.rangeHasMark(t.$from.pos,t.$to.pos,e)):!l.every(t=>{let n=!1;return c.doc.nodesBetween(t.$from.pos,t.$to.pos,(r,i,a)=>{if(n)return!1;n=!e.isInSet(r.marks)&&!!a&&a.type.allowsMarkType(e)&&!(r.isText&&/^\s*$/.test(r.textBetween(Math.max(0,t.$from.pos-i),Math.min(r.nodeSize,t.$to.pos-i))))}),!n});for(let n=0;n<l.length;n++){let{$from:r,$to:i}=l[n];if(!s)c.removeMark(r.pos,i.pos,e);else{let n=r.pos,o=i.pos,s=r.nodeAfter,l=i.nodeBefore,u=a&&s&&s.isText?/^\s*/.exec(s.text)[0].length:0,d=a&&l&&l.isText?/\s*$/.exec(l.text)[0].length:0;n+u<o&&(n+=u,o-=d),c.addMark(n,o,e.create(t))}}o(c.scrollIntoView())}}return!0}}function yr(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}var br=yr(Wn,Kn,Jn),xr=yr(Wn,Zn,Qn),Sr={Enter:yr(tr,ir,ar,sr),"Mod-Enter":rr,Backspace:br,"Mod-Backspace":br,"Shift-Backspace":br,Delete:xr,"Mod-Delete":xr,"Mod-a":cr},Cr={"Ctrl-h":Sr.Backspace,"Alt-Backspace":Sr[`Mod-Backspace`],"Ctrl-d":Sr.Delete,"Ctrl-Alt-Backspace":Sr[`Mod-Delete`],"Alt-Delete":Sr[`Mod-Delete`],"Alt-d":Sr[`Mod-Delete`],"Ctrl-a":fr,"Ctrl-e":pr};for(let e in Sr)Cr[e]=Sr[e];var wr=(typeof navigator<`u`?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<`u`&&os.platform&&os.platform()==`darwin`)?Cr:Sr,Tr=class{constructor(e,t,n={}){this.match=e,this.match=e,this.handler=typeof t==`string`?Er(t):t,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1,this.inCodeMark=n.inCodeMark!==!1}};function Er(e){return function(t,n,r,i){let a=e;if(n[1]){let e=n[0].lastIndexOf(n[1]);a+=n[0].slice(e+n[1].length),r+=e;let t=r-i;t>0&&(a=n[0].slice(e-t,e)+a,r=i)}return t.tr.insertText(a,r,i)}}var Dr=500;function Or({rules:e}){let t=new Bn({state:{init(){return null},apply(e,t){return e.getMeta(this)||(e.selectionSet||e.docChanged?null:t)}},props:{handleTextInput(n,r,i,a){return kr(n,r,i,a,e,t)},handleDOMEvents:{compositionend:n=>{setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&kr(n,r.pos,r.pos,``,e,t)})}}},isInputRules:!0});return t}function kr(e,t,n,r,i,a){if(e.composing)return!1;let o=e.state,s=o.doc.resolve(t),c=e.state.selection,l=s.parent.textBetween(Math.max(0,s.parentOffset-Dr),s.parentOffset,null,``)+r,u=t==c.from&&n==c.to&&e.state.storedMarks||(t==n?s.marks():s.marksAcross(o.doc.resolve(n))||[]);for(let c=0;c<i.length;c++){let d=i[c];if(!d.inCodeMark&&u.some(e=>e.type.spec.code))continue;if(s.parent.type.spec.code){if(!d.inCode)continue}else if(d.inCode===`only`)continue;let f=d.match.exec(l);if(!f||f[0].length<r.length)continue;let p=t-(f[0].length-r.length);if(!d.inCodeMark){let e=!1;if(o.doc.nodesBetween(p,s.pos,t=>{t.isInline&&t.marks.some(e=>e.type.spec.code)&&(e=!0)}),e)continue}let m=d.handler(o,f,p,n,r);if(m)return d.undoable&&m.setMeta(a,{transform:m,from:t,to:n,text:r}),e.dispatch(m),!0}return!1}var Ar=(e,t)=>{let n=e.plugins;for(let r=0;r<n.length;r++){let i=n[r],a;if(i.spec.isInputRules&&(a=i.getState(e))){if(t){let n=e.tr,r=a.transform;for(let e=r.steps.length-1;e>=0;e--)n.step(r.steps[e].invert(r.docs[e]));if(a.text){let t=n.doc.resolve(a.from).marks();n.replaceWith(a.from,a.to,e.schema.text(a.text,t))}else n.delete(a.from,a.to);t(n)}return!0}}return!1};new Tr(/--$/,`—`,{inCodeMark:!1}),new Tr(/\.\.\.$/,`…`,{inCodeMark:!1}),new Tr(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,`“`,{inCodeMark:!1}),new Tr(/"$/,`”`,{inCodeMark:!1}),new Tr(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,`‘`,{inCodeMark:!1}),new Tr(/'$/,`’`,{inCodeMark:!1});function jr(e,t,n,r){let i,a;return t instanceof Me?a=t:(i=t,a=t.nodeType,n=t.getAttrs,r=t.joinPredicate),new Tr(e,(e,t,i,o)=>{let s=n instanceof Function?n(t):n,c=e.tr.delete(i,o),l=c.doc.resolve(i).blockRange(),u=l&&Ft(l,a,s);if(!u)return null;c.wrap(l,u);let d=c.doc.resolve(i-1).nodeBefore;return d&&d.type==a&&qt(c.doc,i-1)&&(!r||r(t,d))&&c.join(i-1),c},i)}function Mr(e,t,n){let r,i;return t instanceof Me?i=t:(r=t,i=t.nodeType,n=t.getAttrs),new Tr(e,(e,t,r,a)=>{let o=e.doc.resolve(r),s=n instanceof Function?n(t):n;return o.node(-1).canReplaceWith(o.index(-1),o.indexAfter(-1),i)?e.tr.delete(r,a).setBlockType(r,r,i,s):null},r)}for(var Nr={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},Pr={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},Fr=typeof navigator<`u`&&/Mac/.test(navigator.platform),Ir=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),D=0;D<10;D++)Nr[48+D]=Nr[96+D]=String(D);for(var D=1;D<=24;D++)Nr[D+111]=`F`+D;for(var D=65;D<=90;D++)Nr[D]=String.fromCharCode(D+32),Pr[D]=String.fromCharCode(D);for(var Lr in Nr)Pr.hasOwnProperty(Lr)||(Pr[Lr]=Nr[Lr]);function Rr(e){var t=!(Fr&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||Ir&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?Pr:Nr)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var zr=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),Br=typeof navigator<`u`&&/Win/.test(navigator.platform);function Vr(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e<t.length-1;e++){let n=t[e];if(/^(cmd|meta|m)$/i.test(n))o=!0;else if(/^a(lt)?$/i.test(n))r=!0;else if(/^(c|ctrl|control)$/i.test(n))i=!0;else if(/^s(hift)?$/i.test(n))a=!0;else if(/^mod$/i.test(n))zr?o=!0:i=!0;else throw Error(`Unrecognized modifier name: `+n)}return r&&(n=`Alt-`+n),i&&(n=`Ctrl-`+n),o&&(n=`Meta-`+n),a&&(n=`Shift-`+n),n}function Hr(e){let t=Object.create(null);for(let n in e)t[Vr(n)]=e[n];return t}function Ur(e,t,n=!0){return t.altKey&&(e=`Alt-`+e),t.ctrlKey&&(e=`Ctrl-`+e),t.metaKey&&(e=`Meta-`+e),n&&t.shiftKey&&(e=`Shift-`+e),e}function Wr(e){return new Bn({props:{handleKeyDown:Gr(e)}})}function Gr(e){let t=Hr(e);return function(e,n){let r=Rr(n),i,a=t[Ur(r,n)];if(a&&a(e.state,e.dispatch,e))return!0;if(r.length==1&&r!=` `){if(n.shiftKey){let i=t[Ur(r,n,!1)];if(i&&i(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(Br&&n.ctrlKey&&n.altKey)&&(i=Nr[n.keyCode])&&i!=r){let r=t[Ur(i,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}var O=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t};function Kr(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t}var qr=null;function k(e,t,n){let r=qr||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r}function Jr(){qr=null}function Yr(e,t,n,r){return n&&(Zr(e,t,n,r,-1)||Zr(e,t,n,r,1))}var Xr=/^(img|br|input|textarea|hr)$/i;function Zr(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:A(e))){let n=e.parentNode;if(!n||!j(n)||ni(e)||Xr.test(e.nodeName)||e.contentEditable==`false`)return!1;t=O(e)+(i<0?0:1),e=n}else if(j(e)){let n=e.childNodes[t+(i<0?-1:0)];if(j(n)&&n.contentEditable==`false`){if(n.pmViewDesc?.ignoreForSelection)t+=i;else return!1}else if(ni(n)||Xr.test(n.nodeName))return!1;else e=n,t=i<0?A(e):0}else return!1}}function A(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function j(e){return e.nodeType==1}function M(e){return e.nodeType==3}function Qr(e,t){return t?e.contains(j(t)?t:t.parentNode):!1}function $r(e,t){for(;;){if(M(e)&&t)return e;if(j(e)&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=A(e)}else if(e.parentNode&&!ni(e,!0))t=O(e),e=e.parentNode;else return null}}function ei(e,t){for(;;){if(M(e)&&t<e.nodeValue.length)return e;if(j(e)&&t<e.childNodes.length){if(e.contentEditable==`false`)return null;e=e.childNodes[t],t=0}else if(e.parentNode&&!ni(e,!0))t=O(e)+1,e=e.parentNode;else return null}}function ti(e,t,n){for(let r=t==0,i=t==A(e);r||i;){if(e==n)return!0;let t=O(e);if(e=e.parentNode,!e)return!1;r&&=t==0,i&&=t==A(e)}}function ni(e,t=!1){let n;for(let t=e;t&&!(n=t.pmViewDesc);t=t.parentNode);return n&&n.node&&(!t||n.node.isBlock)&&(n.dom==e||n.contentDOM==e)}function ri(e){return e.focusNode&&Yr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)}function ii(e,t){e.collapse(t.anchorNode,t.anchorOffset),(t.focusNode!=t.anchorNode||t.focusOffset!=t.anchorOffset)&&e.extend(t.focusNode,t.focusOffset)}function ai(e,t){let n=document.createEvent(`Event`);return n.initEvent(`keydown`,!0,!0),n.keyCode=e,n.key=n.code=t,n}function oi(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function si(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(A(r.offsetNode),r.offset)}}catch{}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(A(r.startContainer),r.startOffset)}}}var ci=typeof navigator<`u`?navigator:null,li=typeof document<`u`?document:null,ui=ci&&ci.userAgent||``,N=/gecko\/(\d+)/i.test(ui)&&!/edge?\//i.test(ui);N&&+(/Firefox\/(\d+)/.exec(ui)||[0,0])[1];var di=/Chrome\/(\d+)/.exec(ui),P=!!di,fi=di?+di[1]:0,F=!!ci&&/Apple Computer/.test(ci.vendor),pi=F&&(/Mobile\/\w+/.test(ui)||!!ci&&ci.maxTouchPoints>2),I=pi||(ci?/Mac/.test(ci.platform):!1),mi=ci?/Win/.test(ci.platform):!1,hi=/Android \d/.test(ui),gi=!!li&&`webkitFontSmoothing`in li.documentElement.style,_i=gi?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function vi(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function yi(e,t){return typeof e==`number`?e:e[t]}function bi(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function xi(e,t,n){for(;;)if(n<0?t:t<A(e)){if(M(e))return L(k(e,t+(n<0?-1:0),t+ +(n>0)),-n);let r=e.childNodes[n<0?t-1:t];if(M(r))e=r,t=n<0?r.nodeValue.length:0;else if(j(r))return L(r,-n);else return null}else if(ni(e,!0)||!e.parentNode)return null;else t=O(e)+(n<0?0:1),e=e.parentNode}function Si(e,t,n){if(!zi(t)&&t.left==0)return;let r=e.someProp(`scrollThreshold`)||0,i=e.someProp(`scrollMargin`)||5,a=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(!j(o)){o=Kr(o);continue}let e=o==a.body,n=e?vi(a):bi(o),s=0,c=0;if(t.top<n.top+yi(r,`top`)?c=-(n.top-t.top+yi(i,`top`)):t.bottom>n.bottom-yi(r,`bottom`)&&(c=t.bottom-t.top>n.bottom-n.top?t.top+yi(i,`top`)-n.top:t.bottom-n.bottom+yi(i,`bottom`)),t.left<n.left+yi(r,`left`)?s=-(n.left-t.left+yi(i,`left`)):t.right>n.right-yi(r,`right`)&&(s=t.right-n.right+yi(i,`right`)),s||c){if(e)a.defaultView.scrollBy(s,c);else{let e=o.scrollLeft,n=o.scrollTop;c&&(o.scrollTop+=c),s&&(o.scrollLeft+=s);let r=o.scrollLeft-e,i=o.scrollTop-n;t={left:t.left-r,top:t.top-i,right:t.right-r,bottom:t.bottom-i}}}let l=e?`fixed`:getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(l))break;o=l==`absolute`?o.offsetParent:Kr(o)}}function Ci(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,i;for(let a=(t.left+t.right)/2,o=n+1;o<Math.min(innerHeight,t.bottom);o+=5){let t=e.root.elementFromPoint(a,o);if(!t||t==e.dom||!e.dom.contains(t))continue;let s=t.getBoundingClientRect();if(s.top>=n-20){r=t,i=s.top;break}}return{refDOM:r,refTop:i,stack:wi(e.dom)}}function wi(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=Kr(r));return t}function Ti({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;Ei(n,r==0?0:r-t)}function Ei(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:a}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=a&&(r.scrollLeft=a)}}var Di=null;function Oi(e){if(e.setActive)return e.setActive();if(Di)return e.focus(Di);let t=wi(e);e.focus(Di==null?{get preventScroll(){return Di={preventScroll:!0},!0}}:void 0),Di||(Di=!1,Ei(t,0))}function ki(e,t){let n,r=2e8,i,a=0,o=t.top,s=t.top,c,l;for(let u=e.firstChild,d=0;u;u=u.nextSibling,d++){let e;if(j(u))e=u.getClientRects();else if(M(u))e=k(u).getClientRects();else continue;for(let f=0;f<e.length;f++){let p=e[f];if(p.top<=o&&p.bottom>=s){o=Math.max(p.bottom,o),s=Math.min(p.top,s);let e=p.left>t.left?p.left-t.left:p.right<t.left?t.left-p.right:0;if(e<r){n=u,r=e,i=e&&M(n)?{left:p.right<t.left?p.right:p.left,top:t.top}:t,j(u)&&e&&(a=d+ +(t.left>=(p.left+p.right)/2));continue}}else p.top>t.top&&!c&&p.left<=t.left&&p.right>=t.left&&(c=u,l={left:Math.max(p.left,Math.min(p.right,t.left)),top:p.top});!n&&(t.left>=p.right&&t.top>=p.top||t.left>=p.left&&t.top>=p.bottom)&&(a=d+1)}}return!n&&c&&(n=c,i=l,r=0),n&&M(n)?Ai(n,i):!n||r?{node:e,offset:a}:ki(n,i)}function Ai(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let a=0;a<n;a++){r.setEnd(e,a+1),r.setStart(e,a);let n=L(r,1);if(n.top!=n.bottom&&ji(t,n)){i={node:e,offset:a+ +(t.left>=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}function ji(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Mi(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}function Ni(e,t,n){let{node:r,offset:i}=ki(t,n),a=-1;if(j(r)&&!r.firstChild){let e=r.getBoundingClientRect();a=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return{pos:e.docView.posFromDOM(r,i,a),affinity:Fi(r,i,n)}}function Pi(e,t){return e<t.left?t.left-e:e>t.right?e-t.right:0}function Fi(e,t,n){let r=xi(e,t,-1),i=xi(e,t,1);return r?i?r.bottom<=i.top?n.top>(r.bottom+i.top)/2?1:-1:Pi(n.left,r)<Pi(n.left,i)?-1:1:-1:1}function Ii(e,t,n,r){let i=-1;for(let n=t;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),a;if(!t)return null;if(j(t.dom)&&((a=t.dom.getBoundingClientRect()).width||a.height)){if(!t.contentDOM&&!t.node.isText&&r.left>=a.left&&r.left<=a.right&&r.top>=a.top&&r.top<=a.bottom){let e=t.node.isBlock?r.top<(a.top+a.bottom)/2:r.left<(a.left+a.right)/2;return{pos:e?t.posBefore:t.posAfter,affinity:e?1:-1}}t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(r.top<a.top||r.top>a.bottom)&&(i=r.top<a.top?t.posBefore:t.posAfter)}n=t.dom.parentNode}return i>-1?{pos:i,affinity:0}:{pos:e.docView.posFromDOM(t,n,-1),affinity:Fi(t,n,r)}}function Li(e,t,n){let r=e.childNodes.length;if(r&&n.top<n.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(t.top-n.top)/(n.bottom-n.top))-2)),a=i;;){let n=e.childNodes[a];if(j(n)){let e=n.getClientRects();for(let r=0;r<e.length;r++){let i=e[r];if(ji(t,i))return Li(n,t,i)}}if((a=(a+1)%r)==i)break}return e}function Ri(e,t){let n=e.dom.ownerDocument,r,i=0,a=si(n,t.left,t.top);a&&({node:r,offset:i}=a);let o=(e.root.elementFromPoint?e.root:n).elementFromPoint(t.left,t.top),s,c=0;if(!o||!e.dom.contains(o)){let n=e.dom.getBoundingClientRect();if(!ji(t,n)||(o=Li(e.dom,t,n),!o))return null}if(F)for(let e=o;r&&e;e=Kr(e))e.draggable&&(r=void 0);if(o=Mi(o,t),r){if(N&&j(r)&&(i=Math.min(i,r.childNodes.length),i<r.childNodes.length)){let e=r.childNodes[i],n;e.nodeName==`IMG`&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&i++}let n;if(gi&&i&&j(r)&&j(n=r.childNodes[i-1])&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&i--,r==e.dom&&i==r.childNodes.length-1&&j(r.lastChild)&&t.top>r.lastChild.getBoundingClientRect().bottom)s=e.state.doc.content.size;else if(i==0||!j(r)||r.childNodes[i-1].nodeName!=`BR`){let n=Ii(e,r,i,t);n&&({pos:s,affinity:c}=n)}}s??({pos:s,affinity:c}=Ni(e,o,t));let l=e.docView.nearestDesc(o,!0);return{pos:s,inside:l?l.posAtStart-l.border:-1,affinity:c}}function zi(e){return e.top<e.bottom||e.left<e.right}function L(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(zi(e))return e}return Array.prototype.find.call(n,zi)||e.getBoundingClientRect()}var Bi=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Vi(e,t,n){let{node:r,offset:i,atom:a}=e.docView.domFromPos(t,n<0?-1:1),o=gi||N;if(M(r)){if(o&&(Bi.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=L(k(r,i,i),n);if(N&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=L(k(r,i-1,i-1),-1);if(t.top==e.top){let n=L(k(r,i,i+1),-1);if(n.top!=e.top)return Hi(n,n.left<t.left)}}return e}{let e=i,t=i,a=n<0?1:-1;return n<0&&!i?(t++,a=-1):n>=0&&i==r.nodeValue.length?(e--,a=1):n<0?e--:t++,Hi(L(k(r,e,t),a),a<0)}}if(!e.state.doc.resolve(t-(a||0)).parent.inlineContent){if(a==null&&i&&(n<0||i==A(r))){let e=r.childNodes[i-1];if(j(e))return Ui(e.getBoundingClientRect(),!1)}if(a==null&&i<A(r)){let e=r.childNodes[i];if(j(e))return Ui(e.getBoundingClientRect(),!0)}return Ui(r.getBoundingClientRect(),n>=0)}if(a==null&&i&&(n<0||i==A(r))){let e=r.childNodes[i-1],t=M(e)?k(e,A(e)-+!o):j(e)&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return Hi(L(t,1),!1)}if(a==null&&i<A(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?M(e)?k(e,0,+!o):j(e)?e:null:null;if(t)return Hi(L(t,-1),!0)}return Hi(L(M(r)?k(r):r,-n),n>=0)}function Hi(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function Ui(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function Wi(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}function Gi(e,t,n){let r=t.selection,i=n==`up`?r.$from:r.$to;return Wi(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=Vi(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(j(e))t=e.getClientRects();else if(M(e))t=k(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&(n==`up`?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})}var Ki=/[\u0590-\u08ac]/;function qi(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,a=!i,o=i==r.parent.content.size,s=e.domSelection();return s?!Ki.test(r.parent.textContent)||!s.modify?n==`left`||n==`backward`?a:o:Wi(e,t,()=>{let t=e.domSel.readRange(),i=s.caretBidiLevel;s.modify(`move`,n,`character`);let a=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:o,focusOffset:c}=e.domSel.readRange(),l=o&&!Qr(a,o)||t.focusNode==o&&t.focusOffset==c;return ii(s,t),i!=null&&(s.caretBidiLevel=i),l}):r.pos==r.start()||r.pos==r.end()}var Ji=null,Yi=null,Xi=!1;function Zi(e,t,n){return Ji==t&&Yi==n?Xi:(Ji=t,Yi=n,Xi=n==`up`||n==`down`?Gi(e,t,n):qi(e,t,n))}var Qi=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.damage=0,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 r=this.children[t];if(r==e)return n;n+=r.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&&Qr(this.contentDOM,e)){if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}}let r;if(e==this.dom&&this.contentDOM)r=t>O(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){let n=e.compareDocumentPosition(this.contentDOM);r=n&16?t>Array.from(e.childNodes).findIndex(e=>e.contains(this.contentDOM)):!(n&4)}else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),a;if(i&&(!t||i.node)){if(n&&(a=i.nodeDOM)&&!(j(a)?Qr(a,e):a==e))n=!1;else return i}}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let i=this.children[n],a=t+i.size;if(a>e){r=e-t;break}t=a}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(;n>0;n--){let e=this.children[n-1];if(e.size||!(e instanceof aa||e instanceof $i&&e.side>=0))break}if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?O(e.dom)+1:0}}{let e,r=!0;for(;e=n<this.children.length?this.children[n]:null,e&&e.dom.parentNode!=this.contentDOM;n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?O(e.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 r=-1,i=-1;for(let a=n,o=0;;o++){let n=this.children[o],s=a+n.size;if(r==-1&&e<=s){let i=a+n.border;if(e>=i&&t<=s-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=a;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=O(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(s>t||o==this.children.length-1)){t=s;for(let e=o+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=O(n.dom);break}t+=n.size}i==-1&&(i=this.contentDOM.childNodes.length);break}a=s}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}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(!j(t)||n==t.childNodes.length)throw RangeError(`No node after pos `+e);return t.childNodes[n]}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDamage(e){e&&(this.damage|=e,this.markParentDamage())}markParentDamage(){for(let e=this;;){let{parent:t}=e;if(!t||t.damage&1)break;t.damage|=1,e=t}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},$i=class extends Qi{constructor(e,t,n,r){let i,a=t.type.toDOM;if(typeof a==`function`&&(a=a(n,()=>{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){let e=j(a)?a:document.createElement(`span`);e!=a&&(e.appendChild(a),a=e),e.hasAttribute(`contenteditable`)||(e.contentEditable=`false`),e.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return!this.damage&&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}},ea=class extends Qi{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},ta=class e extends Qi{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return o&&o.dom||(o=et.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.damage&4||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return!(this.damage&4)&&this.mark.eq(e)}markDamage(e){var t;this.damage|=e,(t=this.parent)==null||t.markDamage(2)}slice(t,n,r){let i=e.create(this.parent,this.mark,!0,r),a=this.children,o=this.size;n<o&&(a=Sa(a,n,o,r)),t>0&&(a=Sa(a,0,t,r));for(let e=0;e<a.length;e++)a[e].parent=i;return i.children=a,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},na=class e extends Qi{constructor(e,t,n,r,i,a,o){super(e,[],i,a),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=o}static create(t,n,r,i,a,o){let s=a.nodeViews[n.type.name],c,l=s&&s(n,a,()=>{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(!M(u))throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=et.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=pa(u,r,n),l?c=new oa(t,n,r,i,u,d||null,f,l):n.isText?new ia(t,n,r,i,u,f):new e(t,n,r,i,u,d||null,f)}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 e=this.children.length-1;e>=0;e--){let n=this.children[e];if(this.dom.contains(n.dom.parentNode)){t.contentElement=n.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(t=>j(t)&&e.indexOf(t.parentNode)<0&&this.dom.contains(t));n?t.contentElement=n:t.getContent=()=>o.empty}}return t}matchesNode(e,t,n){return!this.damage&&e.eq(this.node)&&ma(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new ga(this,a&&a.node,e),c=this.node.inlineContent,l=c&&this.node.isBlock;ya(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?u.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,u,d)=>{s.syncToMarks(t.marks,n,e,d),l&&t.isAtom&&!t.isText&&s.addHackNode(`IMG`,s.top);let f;s.findNodeMatch(t,a,u,d)||o&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(f=s.findIndexWithChild(i.node))>-1&&s.updateNodeAt(t,a,u,f,e,r)||s.updateNextNode(t,a,u,e,d,r)||s.addNode(t,a,u,e,r),r+=t.nodeSize,c&&(l=t.isAtom&&!t.isText)}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.damage&2)&&(a&&this.protectLocalComposition(e,a),sa(this.contentDOM,this.children,e),pi&&ba(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof T)||n<t||r>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=xa(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let a=new ea(this,i,t,r);e.input.compositionNodes.push(a),this.children=Sa(this.children,n,n+r.length,e,a)}update(e,t,n,r,i){return this.damage&4||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r,i),!0)}updateInner(e,t,n,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,i+1),this.damage=0}updateOuterDeco(e){if(ma(e,this.outerDeco))return;let t=!j(this.nodeDOM),n=this.dom;this.dom=da(this.dom,this.nodeDOM,ua(this.outerDeco,this.node,t),ua(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){j(this.nodeDOM)&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){j(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 ra(e,t,n,r,i,a){a?da(r,r,ua(a,e,!1),ua(t,e,!1)):pa(r,t,e);let o=new na(void 0,e,t,n,r,r,r);return o.contentDOM&&o.updateChildren(i,0),o}var ia=class e extends na{constructor(e,t,n,r,i,a){super(e,t,n,r,i,null,a)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.damage&4||this.damage&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.damage&8||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.damage=0,!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!1}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a)}get domAtom(){return!1}isText(e){return this.node.text==e}},aa=class extends Qi{parseRule(){return{ignore:!0}}matchesHack(e){return!this.damage&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},oa=class extends na{constructor(e,t,n,r,i,a,o,s){super(e,t,n,r,i,a,o),this.spec=s}update(e,t,n,r,i){if(this.damage&4)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let a=this.spec.update(e,t,n);return a&&this.updateInner(e,t,n,r,i),a}return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}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 sa(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a<t.length;a++){let o=t[a],s=o.dom;if(s.parentNode==e){for(;s!=r;)r=ha(r),i=!0;r=r.nextSibling}else i=!0,e.insertBefore(s,r);if(o instanceof ta){let t=r?r.previousSibling:e.lastChild;sa(o.contentDOM,o.children,n),r=t?t.nextSibling:e.firstChild}}for(;r;)r=ha(r),i=!0;i&&n.trackWrites==e&&(n.trackWrites=null)}var ca=function(e){e&&(this.nodeName=e)};ca.prototype=Object.create(null);var la=[new ca];function ua(e,t,n){if(e.length==0)return la;let r=n?la[0]:new ca,i=[r];for(let a=0;a<e.length;a++){let o=e[a].type.attrs;if(o){o.nodeName&&i.push(r=new ca(o.nodeName));for(let e in o){let a=o[e];a!=null&&(n&&i.length==1&&i.push(r=new ca(t.isInline?`span`:`div`)),e==`class`?r.class=(r.class?r.class+` `:``)+a:e==`style`?r.style=(r.style?r.style+`;`:``)+a:e!=`nodeName`&&(r[e]=a))}}}return i}function da(e,t,n,r){if(n==la&&r==la)return t;let i=t;for(let t=0;t<r.length;t++){let a=r[t],o=n[t];if(t){let t;o&&o.nodeName==a.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==a.nodeName||(t=document.createElement(a.nodeName),t.pmIsDeco=!0,t.appendChild(i),o=la[0]),i=t}fa(i,o||la[0],a)}return i}function fa(e,t,n){for(let r in t)r!=`class`&&r!=`style`&&r!=`nodeName`&&!(r in n)&&e.removeAttribute(r);for(let r in n)r!=`class`&&r!=`style`&&r!=`nodeName`&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(` `).filter(Boolean):[],i=n.class?n.class.split(` `).filter(Boolean):[];for(let t=0;t<r.length;t++)i.indexOf(r[t])==-1&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)r.indexOf(i[t])==-1&&e.classList.add(i[t]);e.classList.length==0&&e.removeAttribute(`class`)}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}function pa(e,t,n){return da(e,e,la,ua(t,n,!j(e)))}function ma(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function ha(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}var ga=class{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=_a(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,r){let i=0,a=this.stack.length>>1,o=Math.min(a,e.length);for(;i<o&&(i==a-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&e[i].type.spec.spanning!==!1;)i++;for(;i<a;)this.destroyRest(),this.top.damage=0,this.index=this.stack.pop(),this.top=this.stack.pop(),a--;for(;a<e.length;){this.stack.push(this.top,this.index+1);let i=-1,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let t=this.index;t<o;t++){let n=this.top.children[t];if(n.matchesMark(e[a])&&!this.isLocked(n.dom)){i=t;break}}if(i<0&&this.index<this.top.children.length){let t=this.top.children[this.index];t instanceof ta&&!(t.damage&4)&&t.mark.type==e[a].type&&t.spec.update&&!this.isLocked(t.dom)&&t.spec.update(e[a])&&(t.mark=e[a],i=this.index,this.changed=!0)}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=ta.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r<a;r++){let a=this.top.children[r];if(a.matchesNode(e,t,n)&&!this.preMatch.matched.has(a)){i=r;break}}return i<0?!1:(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,r,i,a){let o=this.top.children[r];return o.damage&4&&o.dom==o.contentDOM&&(o.damage=2),o.update(e,t,n,i,a)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return-1}e=t}}updateNextNode(e,t,n,r,i,a){for(let o=this.index;o<this.top.children.length;o++){let s=this.top.children[o];if(s instanceof na){let c=this.preMatch.matched.get(s);if(c!=null&&c!=i)return!1;let l=s.dom,u,d=this.isLocked(l)&&!(e.isText&&s.node&&s.node.isText&&s.nodeDOM.nodeValue==e.text&&!(s.damage&4)&&ma(t,s.outerDeco));if(!d&&s.update(e,t,n,r,a))return this.destroyBetween(this.index,o),s.dom!=l&&(this.changed=!0),this.index++,!0;if(!d&&(u=this.recreateWrapper(s,e,t,n,r,a)))return this.destroyBetween(this.index,o),this.top.children[this.index]=u,u.contentDOM&&(u.damage|=2,u.updateChildren(r,a+1),u.damage=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,i,a){if(e.damage&3||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!ma(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=na.create(this.top,t,n,r,i,a);if(o.contentDOM){o.children=e.children,e.children=[];for(let e of o.children)e.parent=o}return e.destroy(),o}addNode(e,t,n,r,i){let a=na.create(this.top,e,t,n,r,i);a.contentDOM&&a.updateChildren(r,i+1),this.top.children.splice(this.index++,0,a),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new $i(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof ta;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof ia)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((F||P)&&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 r=new aa(this.top,[],n,null);t==this.top?t.children.splice(this.index++,0,r):t.children.push(r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||j(e)&&e.contains(this.lock.parentNode))}};function _a(e,t){let n=t,r=n.children.length,i=[],a=e.childCount,o=new Map,s=[];e:for(;a>0;){let c;for(;;)if(r){let e=n.children[r-1];if(e instanceof ta)i.push(r-1),n=e,r=e.children.length;else{c=e,r--;break}}else if(n==t)break e;else r=i.pop(),n=n.parent;let l=c.node;if(l){if(l!=e.child(a-1))break;--a,o.set(c,a),s.push(c)}}return{index:a,matched:o,matches:s.reverse()}}function va(e,t){return e.type.side-t.type.side}function ya(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;n<e.childCount;n++){let o=e.child(n);r(o,i,t.forChild(a,o),n),a+=o.nodeSize}return}let o=0,s=[],c=null;for(let l=0;;){let u,d;for(;o<i.length&&i[o].to==a;){let e=i[o++];e.widget&&(u?(d||=[u]).push(e):u=e)}if(u){if(d){d.sort(va);for(let e=0;e<d.length;e++)n(d[e],l,!!c)}else n(u,l,!!c)}let f,p;if(c)p=-1,f=c,c=null;else if(l<e.childCount)p=l,f=e.child(l++);else break;for(let e=0;e<s.length;e++)s[e].to<=a&&s.splice(e--,1);for(;o<i.length&&i[o].from<=a&&i[o].to>a;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o<i.length&&i[o].from<e&&(e=i[o].from);for(let t=0;t<s.length;t++)s[t].to<e&&(e=s[t].to);e<m&&(c=f.cut(e-a),f=f.cut(0,e-a),m=e,p=-1)}else for(;o<i.length&&i[o].to<m;)o++;let h=f.isInline&&!f.isLeaf?s.filter(e=>!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function ba(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function xa(e,t,n,r){for(let i=0,a=0;i<e.childCount&&a<=r;){let o=e.child(i++),s=a;if(a+=o.nodeSize,!o.isText)continue;let c=o.text;for(;i<e.childCount;){let t=e.child(i++);if(a+=t.nodeSize,!t.isText)break;c+=t.text}if(a>=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s<r?c.lastIndexOf(t,r-s-1):-1;if(e>=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function Sa(e,t,n,r,i){let a=[];for(let o=0,s=0;o<e.length;o++){let c=e[o],l=s,u=s+=c.size;l>=n||u<=t?a.push(c):(l<t&&a.push(c.slice(0,t-l,r)),i&&=(a.push(i),void 0),u>n&&a.push(c.slice(n-l,c.size,r)))}return a}function Ca(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&w.findFrom(a,t)}function wa(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Ta(e,t,n){let r=e.state.selection;if(r instanceof T){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return wa(e,new T(r.$anchor,a))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=Ca(e.state,t);return n&&n instanceof E?wa(e,n):!1}if(!I||n.indexOf(`m`)<0){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?E.isSelectable(i)?wa(e,new E(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):wa(e,new T(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1}}else if(r instanceof E&&r.node.isInline)return wa(e,new T(t>0?r.$to:r.$from));else{let n=Ca(e.state,t);return n?wa(e,n):!1}}function Ea(e,t){let n=e.pmViewDesc;return n?n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`):j(e)&&e.contentEditable==`false`}function Da(e,t){return t<0?Oa(e):ka(e)}function Oa(e){let t=e.domSel.readRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for(N&&j(n)&&r<A(n)&&Ea(n.childNodes[r],-1)&&(o=!0);;)if(r>0){if(!j(n))break;let e=n.childNodes[r-1];if(Ea(e,-1))i=n,a=--r;else if(M(e))n=e,r=n.nodeValue.length;else break}else if(Aa(n))break;else{let t=n.previousSibling;for(;t&&Ea(t,-1);)i=n.parentNode,a=O(t),t=t.previousSibling;if(t)n=t,r=A(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?ja(e,n,r):i&&ja(e,i,a)}function ka(e){let t=e.domSel.readRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=A(n),a,o;for(;;)if(r<i){if(!j(n))break;if(Ea(n.childNodes[r],1))a=n,o=++r;else break}else if(Aa(n))break;else{let t=n.nextSibling;for(;t&&Ea(t,1);)a=t.parentNode,o=O(t)+1,t=t.nextSibling;if(t)n=t,r=0,i=A(n);else{if(n=n.parentNode,n==e.dom)break;r=i=0}}a&&ja(e,a,o)}function Aa(e){for(let t=e;t;t=t.parentNode){let e=t.pmViewDesc;if(e)return e.node?e.node.isBlock:!1}return!1}function ja(e,t,n){if(!M(t)){let e,r;(r=ei(t,n))?(t=r,n=0):(e=$r(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection(),i=e.domSel.readRange();if(!r)return;ri(i)?r.collapse(t,n):r.extend&&(r.collapse(i.anchorNode,i.anchorOffset),r.extend(t,n)),e.domSel.ignore();let{state:a}=e;setTimeout(()=>{e.state==a&&e.domSel.sync()},50)}function Ma(e,t){let n=e.state.doc.resolve(t);if(!(P||mi)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?`ltr`:`rtl`}if(t<n.end()){let n=e.coordsAtPos(t+1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?`ltr`:`rtl`}}let r=e.dom;for(let t=n.depth;t>0;t--)if(n.node(t).isBlock){r=e.nodeDOM(n.before(t))||r;break}return getComputedStyle(r).direction==`rtl`?`rtl`:`ltr`}function Na(e,t,n){let r=e.state.selection;if(r instanceof T&&!r.empty||n.indexOf(`s`)>-1||I&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=Ca(e.state,t);if(n&&n instanceof E)return wa(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof En?w.near(n,t):w.findFrom(n,t);return o?wa(e,o):!1}return!1}function Pa(e,t){if(!(e.state.selection instanceof T))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function Fa(e,t,n){e.domObserver.stopped(()=>t.contentEditable=n)}function Ia(e){if(!F||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSel.readRange();if(t&&j(t)&&n==0&&t.firstChild&&j(t.firstChild)&&t.firstChild.contentEditable==`false`){let n=t.firstChild;Fa(e,n,`true`),setTimeout(()=>Fa(e,n,`false`),20)}return!1}function La(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function Ra(e,t){let n=t.keyCode,r=La(t);if(n==8||I&&n==72&&r==`c`)return Pa(e,-1)||Da(e,-1);if(n==46&&!t.shiftKey||I&&n==68&&r==`c`)return Pa(e,1)||Da(e,1);if(n==13||n==27)return!0;if(n==37||I&&n==66&&r==`c`){let t=n==37?Ma(e,e.state.selection.from)==`ltr`?-1:1:-1;return Ta(e,t,r)||Da(e,t)}if(n==39||I&&n==70&&r==`c`){let t=n==39?Ma(e,e.state.selection.from)==`ltr`?1:-1:1;return Ta(e,t,r)||Da(e,t)}return n==38||I&&n==80&&r==`c`?Na(e,-1,r)||Da(e,-1):n==40||I&&n==78&&r==`c`?Ia(e)||Na(e,1,r)||Da(e,1):!(r!=(I?`m`:`c`)||n!=66&&n!=73&&n!=89&&n!=90)}function za(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||et.fromSchema(e.state.schema),s=Ya(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&j(l)&&(u=Ja[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&j(l)&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,`
7
+
8
+ `),slice:t}}function Ba(e,t,n,r,i){let a=i.parent.type.spec.code,s,c;if(!n&&!t)return null;let l=!!t&&(r||a||!n);if(l){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return c=new f(o.from(e.state.schema.text(t.replace(/\r\n?/g,`
9
+ `))),0,0),e.someProp(`transformPasted`,t=>{c=t(c,e,!0)}),c;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)c=n;else{let n=i.marks(),{schema:r}=e.state,a=et.fromSchema(r);s=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=s.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),s=Qa(n),gi&&$a(s);let u=s&&s.querySelector(`[data-pm-slice]`),d=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute(`data-pm-slice`)||``);if(d&&d[3])for(let e=+d[3];e>0;e--){let e=s.firstChild;for(;e&&!j(e);)e=e.nextSibling;if(!e)break;s=e}if(c||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||Be.fromSchema(e.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||d),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!Va.test(e.parentNode.nodeName)?{ignore:!0}:null}}),d)c=eo(qa(c,+d[1],+d[2]),d[4]);else if(c=f.maxOpen(Ha(c.content,i),!0),c.openStart||c.openEnd){let e=0,t=0;for(let t=c.content.firstChild;e<c.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=c.content.lastChild;t<c.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);c=qa(c,e,t)}return e.someProp(`transformPasted`,t=>{c=t(c,e,r)}),c}var Va=/^(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 Ha(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&Wa(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=Ga(a[a.length-1],i.length));let n=Ua(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return o.from(a)}return e}function Ua(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,o.from(e));return e}function Wa(e,t,n,r,i){if(i<e.length&&i<t.length&&e[i]==t[i]){let a=Wa(e,t,n,r.lastChild,i+1);if(a)return r.copy(r.content.replaceChild(r.childCount-1,a));if(r.contentMatchAt(r.childCount).matchType(i==e.length-1?n.type:e[i+1]))return r.copy(r.content.append(o.from(Ua(n,e,i+1))))}}function Ga(e,t){if(t==0)return e;let n=e.content.replaceChild(e.childCount-1,Ga(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(o.empty,!0);return e.copy(n.append(r))}function Ka(e,t,n,r,i,a){let s=t<0?e.firstChild:e.lastChild,c=s.content;return e.childCount>1&&(a=0),i<r-1&&(c=Ka(c,t,n,r,i+1,a)),i>=n&&(c=t<0?s.contentMatchAt(0).fillBefore(c,a<=i).append(c):c.append(s.contentMatchAt(s.childCount).fillBefore(o.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,s.copy(c))}function qa(e,t,n){return t<e.openStart&&(e=new f(Ka(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new f(Ka(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var Ja={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 Ya(){return document.implementation.createHTMLDocument(`title`)}var Xa=null;function Za(e){let t=window.trustedTypes;if(!t)return e;if(!Xa){if(Xa=t.defaultPolicy)try{return Xa.createHTML(e)}catch{}Xa=t.createPolicy(`ProseMirrorClipboard`,{createHTML:e=>e})}return Xa.createHTML(e)}function Qa(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=Ya(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(e),a;if((a=i&&Ja[i[1].toLowerCase()])&&(e=a.map(e=>`<`+e+`>`).join(``)+e+a.map(e=>`</`+e+`>`).reverse().join(``)),r.innerHTML=Za(e),a)for(let e=0;e<a.length;e++)r=r.querySelector(a[e])||r;for(let e=0;e<n.styleSheets.length;e++){let t=n.styleSheets[e];for(let e=0;e<t.rules.length;e++){let n=t.rules[e];if(n instanceof CSSStyleRule){let e=r.querySelectorAll(n.selectorText);for(let t=0;t<e.length;t++)e[t].style.cssText+=n.style.cssText}}}return r}function $a(e){let t=e.querySelectorAll(P?`span:not([class]):not([style])`:`span.Apple-converted-space`);for(let n=0;n<t.length;n++){let r=t[n];r.childNodes.length==1&&r.textContent==`\xA0`&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(` `),r)}}function eo(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch{return e}let{content:i,openStart:a,openEnd:s}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs()||!t.createAndFill(null,i))break;try{i=o.from(t.create(r[e+1],i))}catch{break}a++,s++}return new f(i,a,s)}var R=class e{constructor(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}static from(t){return t instanceof e?t:new e(t.anchorNode,t.anchorOffset,t.focusNode,t.focusOffset)}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}};R.null=new R(null,0,null,0);var to=class{constructor(e){this.view=e,this.range=R.null,this.active=!1,this.synced=!1,this.suppress=!1,this.currentDocument=null,this.onSelectionChange=this.onSelectionChange.bind(this)}ensureListener(){let e=this.view.dom.ownerDocument;e!=this.currentDocument&&(this.currentDocument&&this.currentDocument.removeEventListener(`selectionchange`,this.onSelectionChange),this.currentDocument=e,e.addEventListener(`selectionchange`,this.onSelectionChange))}destroy(){this.currentDocument&&=(this.currentDocument.removeEventListener(`selectionchange`,this.onSelectionChange),null),this.active=!1,this.range=R.null}suppressChanges(){this.suppress=!0,setTimeout(()=>this.suppress=!1,50)}onSelectionChange(){if(this.suppress&&this.view.hasFocus())return this.sync();this.read()&&this.view.domObserver.flush(!1)}readRange(){let{view:e}=this,t=e.dom.isConnected!==!1&&e.domSelection();return t?F&&e.root.nodeType===11&&oi(e.dom.ownerDocument)==e.dom?R.from(no(e,t)||t):R.from(t):R.null}read(){this.ensureListener();let e=yo(this.view);if(!e)this.active=!1,this.range=R.null;else return this.active=!0,!this.range.eq(e)&&(this.range=e,this.synced=!1,!0)}sync(e=!1){let{view:t}=this;t.docView&&(this.ensureListener(),t.domObserver.stopped(()=>{go(t,t.state.selection);let n=t.state.selection;if(t.input.mouseSelecting||ao(t)){let{desc:r,start:i}=so(t.docView,n.from,n.to,0);t.cursorWrapper?ho(t):r instanceof oa&&r.spec.setSelection?r.spec.setSelection(n.anchor-i,n.head-i,t.root):oo(t,e,r,i),this.synced=this.active=!0}n.visible==t.dom.classList.contains(`ProseMirror-hideselection`)&&(n.visible?t.dom.classList.remove(`ProseMirror-hideselection`):(t.dom.classList.add(`ProseMirror-hideselection`),mo(t))),this.range=this.readRange()}))}ignore(e=this.readRange()){this.range=R.from(e),this.synced=!0}deactivate(){this.range=R.null,this.active=this.synced=!1}};function no(e,t){if(t.getComposedRanges){let n=t.getComposedRanges({shadowRoots:[e.root]})[0];if(n)return ro(e,n)}let n;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener(`beforeinput`,r,!0),document.execCommand(`indent`),e.dom.removeEventListener(`beforeinput`,r,!0),n?ro(e,n):null}function ro(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return Yr(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),new R(n,r,i,a)}function io(e,t,n=null){let r=e.state.doc;if(!t.focusNode)return null;let i=e.docView.nearestDesc(t.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(ri(t)){for(c=o;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&E.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&ti(t.focusNode,t.focusOffset,i.dom))){let e=i.posBefore;l=new E(o==e?s:r.resolve(e))}else if(N&&n==`key`&&o>e.state.selection.to&&j(t.focusNode)&&t.focusOffset==t.focusNode.childNodes.length&&i&&i.posAtStart>e.state.selection.to)for(let e=t.focusNode;;e=e.parentNode){if(getComputedStyle(e).overflow!=`visible`){l=w.findFrom(r.resolve(i.posAtStart),1);break}if(e==i.dom||e.nextSibling||!e.parentNode||!j(e.parentNode))break}}else{if(t instanceof e.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let n=o,i=o;for(let r=0;r<t.rangeCount;r++){let a=t.getRangeAt(r);n=Math.min(n,e.docView.posFromDOM(a.startContainer,a.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(a.endContainer,a.endOffset,-1))}if(n<0)return null;[c,o]=i==e.state.selection.anchor?[i,n]:[n,i],s=r.resolve(o)}else c=e.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null}let u=r.resolve(c);if(!l){let t=n==`pointer`||e.state.selection.head<s.pos&&!a?1:-1;l=vo(e,u,s,t)}return l}function ao(e){return e.editable?e.hasFocus():bo(e,e.domSel.readRange())&&(!document.activeElement||document.activeElement.contains(e.dom))}function oo(e,t,n,r){let i=e.state.selection,{anchor:a,head:o}=i,s,c;lo&&!(i instanceof T)&&(i.$from.parent.inlineContent||(s=uo(e,i.from)),!i.empty&&!i.$from.parent.inlineContent&&(c=uo(e,i.to)));let l=n.domFromPos(a-r,a>r?-1:1);co(a,o,l,o==a?l:n.domFromPos(o-r,o>r?-1:1),e,t),lo&&(s&&po(s),c&&po(c))}function so(e,t,n,r=0){for(let i=0,a=r;i<e.children.length;i++){let r=e.children[i],o=a+r.size;if(t>a&&n<o)return so(r,t,n,a+r.border);a=o}return{desc:e,start:r}}function co(e,t,n,r,i,a){let o=!1;if((N||F)&&e==t){let{node:e,offset:t}=n;if(M(e)){if(o=!!(t&&e.nodeValue[t-1]==`
10
+ `),o&&t==e.nodeValue.length)for(let t=e,i;t;t=t.parentNode){if(i=t.nextSibling){i.nodeName==`BR`&&(n=r={node:i.parentNode,offset:O(i)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];o=n&&(n.nodeName==`BR`||n.contentEditable==`false`)}}let s=i.domSel.readRange();if(N&&s.focusNode&&s.focusNode!=r.node&&j(s.focusNode)){let e=s.focusNode.childNodes[s.focusOffset];e&&e.contentEditable==`false`&&(a=!0)}if(!(a||o&&F)&&Yr(n.node,n.offset,s.anchorNode,s.anchorOffset)&&Yr(r.node,r.offset,s.focusNode,s.focusOffset))return;let c=i.domSelection(),l=i.input.mouseSelecting;if(l&&l.affinity&&e==t&&l.pos==e){let{affinity:e}=l,{node:t,offset:n}=r,a,o=0;if(M(t)&&(e>0?n<A(t):n>0)?(a=t,o=n+e):(a=(e>0?ei:$r)(t,n),a&&(o=e>0?1:a.nodeValue.length-1)),a){c.collapse(a,o),c.modify(`move`,e>0?`backward`:`forward`,`lineboundary`);let{focusNode:r,focusOffset:s}=c;if(F&&i.root.nodeType==11){let e=c.getComposedRanges({shadowRoots:[i.root]});e.length&&(r=e[0].startContainer,s=e[0].startOffset)}if(Yr(t,n,r,s))return}}ii(c,{focusNode:r.node,focusOffset:r.offset,anchorNode:n.node,anchorOffset:n.offset})}var lo=F||P&&fi<63;function uo(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,a=r?n.childNodes[r-1]:null;if(F&&i&&i.contentEditable==`false`)return fo(i);if((!i||i.contentEditable==`false`)&&(!a||a.contentEditable==`false`)){if(i)return fo(i);if(a)return fo(a)}}function fo(e){return e.contentEditable=`true`,F&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function po(e){e.contentEditable=`false`,e.wasDraggable&&=(e.draggable=!0,null)}function mo(e){let t=e.dom.ownerDocument;t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard);let n=e.domSel.readRange(),r=n.anchorNode,i=n.anchorOffset;t.addEventListener(`selectionchange`,e.input.hideSelectionGuard=()=>{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!ao(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function ho(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom;n.nodeName==`IMG`?t.collapse(n.parentNode,O(n)+1):t.collapse(n,0)}function go(e,t){if(t instanceof E){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(_o(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else _o(e)}function _o(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function vo(e,t,n,r){let i=e.someProp(`createSelectionBetween`,r=>r(e,t,n))||T.between(t,n,r);return e.someProp(`adjustSelectionFromDOM`,t=>{i=t(e,i)}),i}function yo(e){if(e.editable&&!e.hasFocus())return null;let t=e.domSel.readRange();return t&&bo(e,t)?t:null}function bo(e,t){if(!t.anchorNode)return!1;try{return Qr(e.dom,t.anchorNode)&&(e.editable||Qr(e.dom,t.focusNode))}catch{return!1}}var z={},B={},xo={touchstart:!0,touchmove:!0},So=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastKeyDispatched=!1,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.mouseSelecting=null,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Co(e){for(let t in z){let n=z[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{Oo(e,t)&&(e.input.composing&&(t.type==`keydown`||t.type==`beforeinput`)&&t.isComposing===!1&&Zo(e,!0),Do(e,t)||!e.editable&&t.type in B||n(e,t))},xo[t]?{passive:!0}:void 0)}F&&e.dom.addEventListener(`input`,()=>null),Eo(e)}function wo(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function To(e){e.input.mouseDown&&e.input.mouseDown.done(),e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function Eo(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>Do(e,t))})}function Do(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function Oo(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function ko(e,t){!Do(e,t)&&z[t.type]&&(e.editable||!(t.type in B))&&z[t.type](e,t)}function Ao(e,t){let{input:n}=e;return n.lastKeyDispatched||e.composing?!1:(n.lastKeyDispatched=!0,typeof t==`string`&&(t=ai(t==`Backspace`?8:13,t)),e.someProp(`handleKeyDown`,n=>n(e,t)))}B.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),e.input.lastKeyDispatched=!1,!(hi&&P&&n.keyCode==13)){if(pi&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(Ao(e,`Enter`),e.input.lastIOSEnter=0)},200)}else n.keyCode!=229&&e.domObserver.forceFlush(!0),Ao(e,n)||Ra(e,n)?n.preventDefault():wo(e,`key`)}},B.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},B.keypress=(e,t)=>{let n=t;if(Jo(e)||!n.charCode||n.ctrlKey&&!n.altKey||I&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof T)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function jo(e){return{left:e.clientX,top:e.clientY}}function Mo(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function No(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function Po(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);r.setMeta(`pointer`,!0),e.dispatch(r)}function Fo(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&E.isSelectable(r)?(Po(e,new E(n)),!0):!1}function Io(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof E&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(E.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i!=null&&(Po(e,E.create(e.state.doc,i)),!0)}function Lo(e,t,n,r,i){return No(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?Io(e,n):Fo(e,n))}function Ro(e,t,n,r){return No(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function zo(e,t,n,r){return No(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))}function Bo(e,t,n){if(t==-1)return e.inlineContent?T.create(e,0,e.content.size):null;let r=e.resolve(t);for(let t=r.depth+1;t>0;t--){let i=t>r.depth?r.nodeAfter:r.node(t),a=r.before(t);if(i.inlineContent)return T.create(e,a+1,a+1+i.content.size);if(n&&E.isSelectable(i))return E.create(e,a)}return null}var Vo=/[\w_\u00a1-\uffff]+/g;try{Vo=RegExp(`[\\p{L}\\p{N}_]+`,`gu`)}catch{}function Ho(e,t){let n=e.resolve(t),r=n.node(),i=``,a=t,o=t;for(let e=n.indexAfter(),o=!1;e>0;e--){let s=r.child(e-1);if(!s.text)break;let c=a==t?t-n.posAtIndex(e-1):s.text.length,l=c;for(;l>0;l--)if(/\S/.test(s.text[l-1]))o=!0;else if(o)break;if(i=s.text.slice(l,c)+i,a-=c-l,l||a<t-50)break}for(let e=n.index(),a=!1;e<r.childCount;e++){let s=r.child(e);if(!s.text)break;let c=o==t?t-n.posAtIndex(e):0,l=c;for(;l<s.text.length;l++)if(/\S/.test(s.text[l]))a=!0;else if(a)break;if(i+=s.text.slice(c,l),o+=l-c,l<s.text.length||o>t+50)break}let s=a,c=o;if(Intl.Segmenter){for(let n of new Intl.Segmenter(void 0,{granularity:`word`}).segment(i))if(n.isWordLike){let r=n.index+a,i=r+n.segment.length;if(i<t)s=i;else if(r>t){c=r;break}else return T.create(e,r,i)}}else{Vo.lastIndex=0;for(let n;n=Vo.exec(i);){let r=n.index+a,i=r+n[0].length;if(i<t)s=i;else if(r>t){c=r;break}else return T.create(e,r,i)}}let l=i.slice(s-a,t-a),u=i.slice(t-a,c-a),d=/\S*$/.exec(l)[0].length,f=/^\S*/.exec(u)[0].length;if(d||f)return T.create(e,t-d,t+f);let p=/\s*$/.exec(l)[0].length,m=/^\s*/.exec(u)[0].length;return T.create(e,t-p,t+m)}var Uo=I?`metaKey`:`ctrlKey`;z.mousedown=(e,t)=>{let n=t,r=Date.now();if(e.input.shiftKey=n.shiftKey,e.input.lastTouch>r-500)return!1;ts(e);let i=`singleClick`;r-e.input.lastClick.time<500&&Mo(n,e.input.lastClick)&&!n[Uo]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?i=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(i=`tripleClick`)),e.input.lastClick={time:r,x:n.clientX,y:n.clientY,type:i,button:n.button},e.input.mouseDown&&e.input.mouseDown.done();let a=e.posAtCoords(jo(n));if(a){if(n.button==0){if(!e.hasFocus()){Oi(e.dom);let t=e.root.activeElement;t&&!t.contains(e.dom)&&t.blur()}(e.input.mouseDown=new Wo(e,a,n,i)).mightDrag||n.preventDefault()}else wo(e,`pointer`)}};var Wo=class{constructor(e,t,n,r){this.view=e,this.startPos=t,this.event=n,this.type=r,this.didMove=!1,this.lastPos=-1,this.anchorRange=null,this.startDoc=e.state.doc,this.selectNode=!!n[Uo],this.extend=n.shiftKey,this.anchorDoc=this.startDoc;let i=Go(e);if(this.extend){let t=e.state.selection;this.anchorRange=t instanceof E?{from:t.from,to:t.to}:{from:t.anchor,to:t.anchor};let n=t instanceof E?e.nodeDOM(t.from).getBoundingClientRect():e.coordsAtPos(t.anchor);this.anchorOffset={x:(n.left+n.right)/2-i.x,y:(n.top+n.bottom)/2-i.y}}else this.anchorOffset={x:n.clientX-i.x,y:n.clientY-i.y};if(r==`singleClick`){let{selection:r}=e.state,i,a,o=!1;if(r instanceof E&&r.from<=t.pos&&r.to>=t.pos)a=r.from,i=r.node,o=!0;else if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():-1}if(o||a>-1&&i.type.spec.draggable&&i.type.spec.selectable!==!1){let t=e.docView.descAt(a)?.nodeDOM;this.mightDrag={node:i,elt:t,pos:a,addAttr:!1},t&&!t.draggable&&(this.mightDrag.addAttr=!0,e.domObserver.stopped(()=>t.draggable=!0))}else this.mightDrag=qo(e,n)}else this.mightDrag=!1;e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this)),this.mightDrag||this.select(this.startPos,!0)}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),typeof this.mightDrag==`object`&&this.mightDrag.addAttr&&this.view.domObserver.stopped(()=>this.mightDrag.elt.removeAttribute(`draggable`))}maybeRunHandler(e,t){return(this.type==`singleClick`?Lo:this.type==`doubleClick`?Ro:zo)(this.view,e.pos,e.inside,t,this.selectNode)}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.startPos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(jo(e))),t&&(this.didMove||this.maybeRunHandler(t,e)||this.select(t,!0),e.preventDefault())}move(e){if(e.buttons==0)this.done();else{if(!this.didMove&&(Math.abs(this.event.x-e.clientX)>8||Math.abs(this.event.y-e.clientY)>8)&&(this.didMove=!0,this.mightDrag=!1),!this.mightDrag){let t=this.view.posAtCoords(jo(e));t&&this.select(t,!1)}e.preventDefault()}}select(e,t){if(e.pos==this.lastPos)return;this.lastPos=e.pos;let{view:n}=this,{doc:r}=n.state,i=this.type==`singleClick`?Ko(n,r,e):this.type==`doubleClick`?Ho(r,e.pos):Bo(r,e.inside,t);i&&(t&&!this.extend?this.anchorRange=i:(!t||this.extend)&&(r.eq(this.anchorDoc)||this.restoreAnchor(),this.anchorRange&&this.anchorRange.from<i.from?i=vo(n,r.resolve(this.anchorRange.from),r.resolve(i.to)):this.anchorRange&&this.anchorRange.to>i.to&&(i=vo(n,r.resolve(this.anchorRange.to),r.resolve(i.from)))),i.eq(n.state.selection)||(n.input.mouseSelecting=e,n.dispatch(n.state.tr.setSelection(i).setMeta(`pointer`,!0).scrollIntoView()),n.input.mouseSelecting=null))}restoreAnchor(){let e=Go(this.view),t=this.view.posAtCoords({left:this.anchorOffset.x+e.x,top:this.anchorOffset.y+e.y});if(!t)this.anchorRange=null;else{let{doc:e}=this.view.state;this.anchorRange=this.type==`singleClick`?Ko(this.view,e,t):this.type==`doubleClick`?Ho(e,t.pos):Bo(e,t.inside,!1),this.anchorDoc=this.view.state.doc}}};function Go(e){let t=e.dom.getBoundingClientRect();return{x:t.left-e.dom.scrollLeft,y:t.top-e.dom.scrollTop}}function Ko(e,t,n){if(n.inside>-1){let e=t.nodeAt(n.inside);if(e.isAtom&&E.isSelectable(e))return E.create(t,n.inside)}let r=t.resolve(n.pos);return vo(e,r,r)}function qo(e,t){let{selection:n}=e.state;if(n.empty)return!1;let r=e.domSelection();if(!r||r.rangeCount==0)return!0;let i=r.getRangeAt(0).getClientRects();for(let e=0;e<i.length;e++){let n=i[e];if(n.left<=t.clientX&&n.right>=t.clientX&&n.top<=t.clientY&&n.bottom>=t.clientY)return!0}return!1}z.touchstart=e=>{e.input.lastTouch=Date.now(),ts(e),wo(e,`pointer`)},z.touchmove=e=>{e.input.lastTouch=Date.now(),wo(e,`pointer`)},z.contextmenu=e=>ts(e);function Jo(e,t){return e.composing?!0:F&&Math.abs(Date.now()-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var Yo=hi?5e3:-1;B.compositionstart=B.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof T&&t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||P&&mi&&Xo(e)))e.markCursor=e.state.storedMarks||n.marks(),ts(e,!0),e.markCursor=null;else if(ts(e,!t.selection.empty),N&&e.domSel.active&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length)for(let{focusNode:t,focusOffset:n}=e.domSel.range;t&&j(t)&&n!=0;){let r=n<0?t.lastChild:t.childNodes[n-1];if(!r)break;if(M(r)){let t=e.domSelection();t&&t.collapse(r,r.nodeValue.length);break}t=r,n=-1}e.input.composing=!0}Qo(e,Yo)};function Xo(e){let{focusNode:t,focusOffset:n}=e.domSel.range;if(!t||!j(t)||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return j(r)&&r.contentEditable==`false`}B.compositionend=(e,t)=>{e.composing&&Zo(e)};function Zo(e,t=!1){e.input.composing=!1,e.input.compositionEndedAt=Date.now(),e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,t?ts(e):Qo(e,20)}function Qo(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>ts(e),t))}function $o(e){e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now());for(let t;t=e.input.compositionNodes.pop();)t.markParentDamage()}function es(e){let t=e.domSel.range;if(!e.domSel.active||!t.focusNode)return null;let n=$r(t.focusNode,t.focusOffset),r=ei(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return r}}return n||r}function ts(e,t=!1){if(!(hi&&e.domObserver.flushingSoon>=0)&&(e.domObserver.forceFlush(),$o(e),t||e.docView&&e.docView.damage)){let n=io(e,e.domSel.readRange()),r=e.state.selection;n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state)}}function ns(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var rs=pi&&_i<604;z.copy=B.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=rs?null:n.clipboardData,{dom:o,text:s}=za(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):ns(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function is(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function as(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?ss(e,r.value,null,i,t):ss(e,r.textContent,r.innerHTML,i,t)},50)}function ss(e,t,n,r,i){let a=Ba(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||f.empty)))return!0;if(!a)return!1;let o=is(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function cs(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}B.paste=(e,t)=>{let n=t;if(e.composing&&!hi)return;let r=rs?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&ss(e,cs(r),r.getData(`text/html`),i,n)?n.preventDefault():as(e,n)};var ls=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},us=I?`altKey`:`ctrlKey`;function ds(e,t){let n;return e.someProp(`dragCopies`,e=>{n||=e(t)}),n==null?!t[us]:!n}z.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(jo(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof E?i.to-1:i.to))){if(r&&typeof r.mightDrag==`object`)o=E.create(e.state.doc,r.mightDrag.pos);else if(n.target&&j(n.target)){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=E.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=za(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!P||fi>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(rs?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,rs||n.dataTransfer.setData(`text/plain`,c),e.dragging=new ls(l,ds(e,n),o)},z.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},B.dragover=B.dragenter=(e,t)=>t.preventDefault(),B.drop=(e,t)=>{try{fs(e,t,e.dragging)}finally{e.dragging=null}};function fs(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(jo(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=Ba(e,cs(t.dataTransfer),rs?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&ds(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||f.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?Qt(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let p=c.doc.resolve(l);if(u&&E.isSelectable(a.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new E(p));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(vo(e,p,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}z.focus=e=>{if(e.input.lastFocus=Date.now(),!e.focused&&(e.domObserver.stopped(()=>e.dom.classList.add(`ProseMirror-focused`)),e.focused=!0,e.domSel.read(),!e.domSel.synced)){let t=e.domSel.range;setTimeout(()=>{let n=e.domSel.readRange();n&&t.eq(n)&&e.domSel.sync()},20)}},z.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stopped(()=>e.dom.classList.remove(`ProseMirror-focused`)),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domSel.deactivate(),!1)},z.beforeinput=(e,t)=>{if(hi&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||e.domObserver.pendingRecords().length||(e.dom.blur(),e.focus(),Ao(e,`Backspace`)))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in B)z[e]=B[e];function ps(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var ms=class{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index<this.frag.childCount;){let t=this.frag.child(this.index);if(this.off==e)return t;this.off+=t.nodeSize,this.index++}return null}},hs=class e{constructor(e,t){this.toDOM=e,this.spec=t||ys,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:a}=e.mapResult(t.from+r,this.side<0?-1:1);return a?null:new V(i-n,i-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&ps(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},gs=class e{constructor(e,t){this.attrs=e,this.spec=t||ys}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,a=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=a?null:new V(i,a,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&ps(this.attrs,t.attrs)&&ps(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},_s=class e{constructor(e,t){this.attrs=e,this.spec=t||ys}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let a=e.mapResult(t.to+r,-1);return a.deleted||a.pos<=i.pos?null:new V(i.pos-n,a.pos-n,this)}valid(e,t,n){let r=n.nodeAt(t.from);return!!r&&!r.isText&&t.from+r.nodeSize==t.to}eq(t){return this==t||t instanceof e&&ps(this.attrs,t.attrs)&&ps(this.spec,t.spec)}destroy(){}},V=class e{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(t,n){return new e(t,n,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(t,n,r){return new e(t,t,new hs(n,r))}static inline(t,n,r,i){return new e(t,n,new gs(r,i))}static node(t,n,r,i){return new e(t,n,new _s(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof gs}get widget(){return this.type instanceof hs}},vs=[],ys={},H=class e{constructor(e,t){this.local=e.length?e:vs,this.children=t.length?t:vs}static create(e,t){return t.length?Es(t,e,0,ys):U}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,i){for(let a=0;a<this.local.length;a++){let o=this.local[a];if(o.from>t)break;o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;a<this.children.length&&!(this.children[a]>=t);a+=3)if(this.children[a+1]>e){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==U||e.maps.length==0?this:this.mapInner(e,t,0,0,n||ys)}mapInner(t,n,r,i,a){let o;if(this.local.length){let e=new ms(n.content);for(let s=0;s<this.local.length;s++){let c=this.local[s].map(t,r,i);c&&c.type.valid(n,c,e)?(o||=[]).push(c):a.onRemove&&a.onRemove(this.local[s].spec)}}return this.children.length?xs(this.children,o||[],t,n,r,i,a):o?new e(o.sort(Ds),vs):U}add(t,n){return n.length?this==U?e.create(t,n):this.addInner(t,n,0):this}addInner(t,n,r){let i,a=0;t.forEach((e,t)=>{let o=t+r,s;if(s=ws(n,e,o)){for(i||=this.children.slice();a<i.length&&i[a]<t;)a+=3;i[a]==t?i[a+2]=i[a+2].addInner(e,s,o+1):i.splice(a,0,t,t+e.nodeSize,Es(s,e,o+1,ys)),a+=3}});let o=Ss(a?Ts(n):n,-r).sort(Ds);if(o.length){let e=new ms(t.content);for(let n=0;n<o.length;n++)o[n].type.valid(t,o[n],e)||o.splice(n--,1)}return new e(o.length?this.local.concat(o).sort(Ds):this.local,i||this.children)}remove(e){return e.length==0||this==U?this:this.removeInner(e,0)}removeInner(t,n){let r=this.children,i=this.local;for(let e=0;e<r.length;e+=3){let i,a=r[e]+n,o=r[e+1]+n;for(let e=0,n;e<t.length;e++)(n=t[e])&&n.from>a&&n.to<o&&(t[e]=null,(i||=[]).push(n));if(!i)continue;r==this.children&&(r=this.children.slice());let s=r[e+2].removeInner(i,a+1);s==U?(r.splice(e,3),e-=3):r[e+2]=s}if(i.length){for(let e=0,r;e<t.length;e++)if(r=t[e])for(let e=0;e<i.length;e++)i[e].eq(r,n)&&(i==this.local&&(i=this.local.slice()),i.splice(e--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new e(i,r):U}forChild(t,n){if(this==U)return this;if(n.isLeaf)return e.empty;let r,i,a=0,o=this.children.length/3;for(;a<o;){let e=a+o>>>1,n=e*3,i=this.children[n];if(i<t)a=e+1;else if(i>t)o=e;else{r=this.children[n+2];break}}let s=t+1,c=s+n.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<c&&t.to>s&&t.type instanceof gs){let e=Math.max(s,t.from)-s,n=Math.min(c,t.to)-s;e<n&&(i||=[]).push(t.copy(e,n))}}if(i){let t=new e(i.sort(Ds),vs);return r?new bs([t,r]):t}return r||U}eq(t){if(this==t)return!0;if(!(t instanceof e)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(e){return Os(this.localsInner(e))}localsInner(e){if(this==U)return vs;if(e.inlineContent||!this.local.some(gs.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof gs||t.push(this.local[e]);return t}forEachSet(e){e(this)}};H.empty=new H([],[]),H.removeOverlap=Os;var U=H.empty,bs=class e{constructor(e){this.members=e}map(t,n){let r=this.members.map(e=>e.map(t,n,ys));return e.from(r)}forChild(t,n){if(n.isLeaf)return H.empty;let r=[];for(let i=0;i<this.members.length;i++){let a=this.members[i].forChild(t,n);a!=U&&(a instanceof e?r=r.concat(a.members):r.push(a))}return e.from(r)}eq(t){if(!(t instanceof e)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length){if(!t)t=i;else{n&&=(t=t.slice(),!1);for(let e=0;e<i.length;e++)t.push(i[e])}}}return t?Os(n?t:t.sort(Ds)):vs}static from(t){switch(t.length){case 0:return U;case 1:return t[0];default:return new e(t.every(e=>e instanceof H)?t:t.reduce((e,t)=>e.concat(t instanceof H?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function xs(e,t,n,r,i,a,o){let s=e.slice();for(let e=0,t=a;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,a)=>{let o=a-i-(n-e);for(let i=0;i<s.length;i+=3){let a=s[i+1];if(a<0||e>a+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t<s.length;t+=3)if(s[t+1]<0){if(s[t+1]==-2){c=!0,s[t+1]=-1;continue}let l=n.map(e[t]+a),u=l-i;if(u<0||u>=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==U?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=Es(Cs(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;e<s.length;e+=3)s[e+1]<0&&(s.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<s.length&&s[t]<n;)t+=3;s.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new H(t.sort(Ds),s)}function Ss(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new V(i.from+t,i.to+t,i.type))}return n}function Cs(e,t,n,r,i,a,o){function s(e,t){for(let a=0;a<e.local.length;a++){let s=e.local[a].map(r,i,t);s?n.push(s):o.onRemove&&o.onRemove(e.local[a].spec)}for(let n=0;n<e.children.length;n+=3)s(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)e[n+1]==-1&&s(e[n+2],t[n]+a+1);return n}function ws(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,a;t<e.length;t++)(a=e[t])&&a.from>n&&a.to<r&&((i||=[]).push(a),e[t]=null);return i}function Ts(e){let t=[];for(let n=0;n<e.length;n++)e[n]!=null&&t.push(e[n]);return t}function Es(e,t,n,r){let i=[],a=!1;t.forEach((t,o)=>{let s=ws(e,t,o+n);if(s){a=!0;let e=Es(s,t,n+o+1,r);e!=U&&i.push(o,o+t.nodeSize,e)}});let o=Ss(a?Ts(e):e,-n).sort(Ds);if(o.length){let e=new ms(t.content);for(let n=0;n<o.length;n++)o[n].type.valid(t,o[n],e)||(r.onRemove&&r.onRemove(o[n].spec),o.splice(n--,1))}return o.length||i.length?new H(o,i):U}function Ds(e,t){return e.from-t.from||e.to-t.to}function Os(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let a=t[i];if(a.from==r.from)a.to!=r.to&&(t==e&&(t=e.slice()),t[i]=a.copy(a.from,r.to),ks(t,i+1,a.copy(r.to,a.to)));else{a.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,a.from),ks(t,i,r.copy(a.from,r.to)));break}}}return t}function ks(e,t,n){for(;t<e.length&&Ds(n,e[t])>0;)t++;e.splice(t,0,n)}function As(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=U&&t.push(r)}),e.cursorWrapper&&t.push(H.create(e.state.doc,[e.cursorWrapper.deco])),bs.from(t)}function js(e,t,n,r){let{node:i,fromOffset:a,toOffset:o,from:s,to:c}=e.docView.parseRange(t,n),l=e.domSel.range,u,d=l.anchorNode;if(d&&Qr(e.dom,d)&&(u=[{node:d,offset:l.anchorOffset}],ri(l)||u.push({node:l.focusNode,offset:l.focusOffset})),P&&e.input.lastKeyCode===8)for(let e=o;e>a;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){o=e;break}if(!n||n.size)break}let f=e.state.doc,p=e.someProp(`domParser`)||Be.fromSchema(e.state.schema),m=f.resolve(s),h=null,g=p.parse(i,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:a,to:o,preserveWhitespace:m.parent.type.whitespace!=`pre`||`full`,findPositions:u,ruleFromNode:Ms(r),context:m});if(u&&u[0].pos!=null){let e=u[0].pos,t=u[1]&&u[1].pos;t??=e,h={anchor:e+s,head:t+s}}return{doc:g,sel:h,from:s,to:c}}var Ms=e=>t=>{let n=t.pmViewDesc;if(n)return n.parseRule(e);if(t.nodeName==`BR`&&t.parentNode){if(F&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}if(t.parentNode.lastChild==t||F&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName==`IMG`&&t.getAttribute(`mark-placeholder`))return{ignore:!0};return null},Ns=/^(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 Ps(e,t,n,r,i,a){let o=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=io(e,e.domSel.range,t);if(n&&!e.state.selection.eq(n)&&e.domSel.active){if(P&&hi&&e.input.lastKeyCode===13&&Date.now()-100<e.input.lastKeyCodeTime&&Ao(e,`Enter`))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),o&&r.setMeta(`composition`,o),e.dispatch(r)}return}let s=e.state.doc.resolve(t),c=s.sharedDepth(n);t=s.before(c+1),n=e.state.doc.resolve(n).after(c+1);let l=e.state.selection,u=js(e,t,n,a),d=e.state.doc,f=d.slice(u.from,u.to),p,m;e.input.lastKeyCode===8&&Date.now()-100<e.input.lastKeyCodeTime?(p=e.state.selection.to,m=`end`):(p=e.state.selection.from,m=`start`),e.input.lastKeyCode=null;let h=Bs(f.content,u.doc.content,u.from,p,m);if(h&&e.input.domChangeCount++,(pi&&e.input.lastIOSEnter>Date.now()-225||hi)&&a.some(e=>j(e)&&!Ns.test(e.nodeName))&&(!h||h.endA>=h.endB)&&Ao(e,`Enter`)){e.input.lastIOSEnter=0;return}if(!h){if(i&&l instanceof T&&!l.empty&&l.$head.sameParent(l.$anchor)&&!e.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))h={start:l.from,endA:l.to,endB:l.to};else{if(u.sel){let t=Fs(e,e.state.doc,u.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);o&&n.setMeta(`composition`,o),e.dispatch(n)}}return}}e.state.selection.from<e.state.selection.to&&h.start==h.endB&&e.state.selection instanceof T&&(h.start>e.state.selection.from&&h.start<=e.state.selection.from+2&&e.state.selection.from>=u.from?h.start=e.state.selection.from:h.endA<e.state.selection.to&&h.endA>=e.state.selection.to-2&&e.state.selection.to<=u.to&&(h.endB+=e.state.selection.to-h.endA,h.endA=e.state.selection.to));let g=u.doc.resolveNoCache(h.start-u.from),_=u.doc.resolveNoCache(h.endB-u.from),ee=d.resolve(h.start),v=g.sameParent(_)&&g.parent.inlineContent&&ee.end()>=h.endA;if((pi&&e.input.lastIOSEnter>Date.now()-225&&(!v||a.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&Rs(u.doc,g.pos,_.pos))&&Ao(e,`Enter`)){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>h.start&&(v?h.endA>h.start&&h.endB==h.start:Ls(d,h.start,h.endA,g,_))&&Ao(e,`Backspace`)){hi&&P&&e.domSel.suppressChanges();return}P&&h.endB==h.start&&(e.input.lastChromeDelete=Date.now()),hi&&!v&&g.start()!=_.start()&&_.parentOffset==0&&g.depth==_.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==h.endA&&(h.endB-=2,_=u.doc.resolveNoCache(h.endB-u.from),setTimeout(()=>Ao(e,`Enter`),20));let y=h.start,b=h.endA,te=t=>{let n=t||e.state.tr.replace(y,b,u.doc.slice(h.start-u.from,h.endB-u.from));if(u.sel){let t=Fs(e,n.doc,u.sel);t&&!(P&&e.composing&&t.empty&&(h.start!=h.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==y||t.head==n.mapping.map(b)-1))&&n.setSelection(t)}return o&&n.setMeta(`composition`,o),n.scrollIntoView()},ne;if(v){if(g.pos==_.pos){let t=te(e.state.tr.delete(y,b)),n=d.resolve(h.start).marksAcross(d.resolve(h.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(h.endA==h.endB&&(ne=Is(g.parent.content.cut(g.parentOffset,_.parentOffset),ee.parent.content.cut(ee.parentOffset,h.endA-ee.start())))){let t=te(e.state.tr);ne.type==`add`?t.addMark(y,b,ne.mark):t.removeMark(y,b,ne.mark),e.dispatch(t)}else if(g.parent.child(g.index()).isText&&g.index()==_.index()-+!_.textOffset){let t=g.parent.textBetween(g.parentOffset,_.parentOffset),n=()=>te(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(te())}else e.dispatch(te())}function Fs(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:vo(e,t.resolve(n.anchor),t.resolve(n.head))}function Is(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,s,c,l;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)a=n[e].removeFromSet(a);if(i.length==1&&a.length==0)c=i[0],s=`add`,l=e=>e.mark(c.addToSet(e.marks));else if(i.length==0&&a.length==1)c=a[0],s=`remove`,l=e=>e.mark(c.removeFromSet(e.marks));else return null;let u=[];for(let e=0;e<t.childCount;e++)u.push(l(t.child(e)));if(o.from(u).eq(e))return{mark:c,type:s}}function Ls(e,t,n,r,i){if(n-t<=i.pos-r.pos||zs(r,!0,!1)<i.pos)return!1;let a=e.resolve(t);if(!r.parent.inlineContent){let e=a.nodeAfter;return e!=null&&n==t+e.nodeSize}if(a.parentOffset<a.parent.content.size||!a.parent.isTextblock)return!1;let o=e.resolve(zs(a,!0,!0));return!o.parent.isTextblock||o.pos>n||zs(o,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function Rs(e,t,n){let r=0,i=0;return e.nodesBetween(t,n,(e,a)=>{e.isTextblock&&a>=t&&a<n?r++:(e.isText?/\S/.test(e.text.slice(Math.max(0,t-a),Math.min(e.nodeSize,n-a))):e.isLeaf)&&i++}),i==0&&r==1}function zs(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function Bs(e,t,n,r,i){let a=e.findDiffStart(t,n),o=n+e.size,s=n+t.size;if(a==null)return null;let{a:c,b:l}=e.findDiffEnd(t,o,s);if(i==`end`){let e=Math.max(0,a-Math.min(c,l));r-=c+e-a}if(c<a&&o<s){let e=r<=a&&r>=c?a-r:0;a-=e,l=a+(l-c),c=a}else if(l<a){let e=r<=a&&r>=l?a-r:0;a-=e,c=a+(c-l),l=a}return{start:a,endA:c,endB:l}}var Vs={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Hs=class{constructor(e){this.view=e,this.queue=[],this.flushingSoon=-1,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.started=!1,this.observer=new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);F&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()})}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(e=!1){this.flushingSoon>-1?(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush(!0)):e&&this.flush(!0)}start(){this.observer.takeRecords(),this.observer.observe(this.view.dom,Vs),this.started=!0}stop(){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.started=!1}stopped(e){if(!this.started)return e();this.stop();try{return e()}finally{this.start()}}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=Kr(n))t.add(n);for(let r=e.anchorNode;r;r=Kr(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:M(n)?n.parentNode:n}))return this.view.domSel.ignore(e),!0}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(e=!0){let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]),e&&t.domSel.read();let r=!t.domSel.suppress&&!t.domSel.synced&&!!yo(t)&&!this.ignoreSelectionChange(t.domSel.range),i=-1,a=-1,o=!1,s=[];if(t.editable)for(let e=0;e<n.length;e++){let t=this.registerMutation(n[e],s);t&&(i=i<0?t.from:Math.min(t.from,i),a=a<0?t.to:Math.max(t.to,a),t.typeOver&&(o=!0))}if(s.some(e=>e.nodeName==`BR`)&&(t.input.lastKeyCode==8||t.input.lastKeyCode==46||P&&(t.composing||t.input.compositionEndedAt>Date.now()-50)&&n.some(e=>e.type==`childList`&&e.removedNodes.length))){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&j(t);){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(N&&s.length){let e=s.filter(e=>e.nodeName==`BR`);if(e.length==2){let[t,n]=e;t.parentNode&&t.parentNode.parentNode==n.parentNode?n.remove():t.remove()}else{let{focusNode:n}=t.domSel.range;for(let r of e){let e=r.parentNode;e&&e.nodeName==`LI`&&(!n||Ks(t,n)!=e)&&r.remove()}}}let c=null;i<0&&r&&t.domSel.active&&t.input.lastFocus>Date.now()-200&&t.input.lastTouch<Date.now()-300&&ri(t.domSel.range)&&(c=io(t,t.domSel.range))&&c.eq(w.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,t.domSel.sync(),t.scrollToSelection()):(i>-1||r)&&(i>-1&&Gs(t),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,qs(t,s)),Ps(this.view,i,a,r,o,s),t.docView&&t.docView.damage?t.updateState(t.state):r&&t.domSel.sync())}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n;for(let t=e.target;t&&!(n=this.view.docView.getDesc(t));t=t.parentNode);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 n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),M(r)&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return n.markDamage(4),{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling,a=r&&r.parentNode==e.target?O(r)+1:0,o=n.localPosFromDOM(e.target,a,-1),s=i&&i.parentNode==e.target?O(i):e.target.childNodes.length,c=n.localPosFromDOM(e.target,s,1);return n.markDamage(n.contentDOM?.contains(e.target)?2:4),{from:o,to:c}}return e.type==`attributes`?(n.markDamage(4),{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}):(this.lastChangedTextNode=e.target,n.markDamage(n instanceof ia&&e.target==n.nodeDOM?8:4),{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},Us=new WeakMap,Ws=!1;function Gs(e){if(!Us.has(e)&&(Us.set(e,null),[`normal`,`nowrap`,`pre-line`].indexOf(getComputedStyle(e.dom).whiteSpace)!==-1)){if(e.requiresGeckoHackNode=N,Ws)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.`),Ws=!0}}function Ks(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}function qs(e,t){let{focusNode:n,focusOffset:r}=e.domSel.range;for(let i of t)if(i.parentNode?.nodeName==`TR`){let t=i.nextSibling;for(;t&&t.nodeName!=`TD`&&t.nodeName!=`TH`;)t=t.nextSibling;if(t){let a=t;for(;;){let e=a.firstChild;if(!e||!j(e)||e.contentEditable==`false`||/^(BR|IMG)$/.test(e.nodeName))break;a=e}a.insertBefore(i,a.firstChild),n==i&&e.domSelection().collapse(i,r)}else i.parentNode.removeChild(i)}}var Js=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 So,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(tc),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=Zs(this),Xs(this),this.nodeViews=$s(this),this.docView=ra(this.state.doc,Ys(this),As(this),this.dom,this),this.domObserver=new Hs(this),this.domSel=new to(this),this.domObserver.start(),this.domSel.read(),Co(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&&Eo(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(tc),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];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){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&($o(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=$s(this);ec(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&Eo(this),this.editable=Zs(this),Xs(this);let o=As(this),s=Ys(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&Ci(this);i&&this.domObserver.stopped(()=>{let t=l&&P&&!this.composing&&!n.selection.empty&&!e.selection.empty&&Qs(n.selection,e.selection);if(l){let n=P?this.trackWrites=this.domSel.range.focusNode:null;if(this.composing&&(this.input.compositionNode=es(this)),r||!this.docView.update(e.doc,s,o,this,-1)){let t=this.docView.outerDeco;this.docView.destroy(),this.docView=ra(e.doc,s,o,this.dom,this,t)}!n||this.trackWrites&&this.dom.contains(this.trackWrites)||(t=!0)}this.domSel.sync(t)}),this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&Ti(u)}scrollToSelection(){let e=this.domSel.range.focusNode;if(e&&this.domSel.active&&!this.someProp(`handleScrollToSelection`,e=>e(this))){if(this.state.selection instanceof E){let t=this.docView.domAfterPos(this.state.selection.from);j(t)&&Si(this,t.getBoundingClientRect(),e)}else Si(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 e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.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,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new ls(e.slice,e.move,r<0?void 0:E.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let i=this.directPlugins[n].props[e];if(i!=null&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let a=i[n].props[e];if(a!=null&&(r=t?t(a):a))return r}}hasFocus(){return this.root.activeElement==this.dom}focus(){this.editable&&Oi(this.dom),this.domSel.sync()}get root(){let e=this.dom.isConnected!==!1;e||(this._root=null);let t=this._root;if(t==null&&e){for(let e=this.dom.parentNode;e;e=e.parentNode)if(e.nodeType==9||e.nodeType==11&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return t||document}updateRoot(){this._root=null}posAtCoords(e){return Ri(this,e)}coordsAtPos(e,t=1){return Vi(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 r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Zi(this,t||this.state,e)}pasteHTML(e,t){return ss(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return ss(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return za(this,e)}destroy(){this.docView&&(To(this),this.domSel.destroy(),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],As(this),this,-1),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Jr())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ko(this,e)}domSelection(){return this.root.getSelection()}};Js.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function Ys(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[V.node(0,e.state.doc.content.size,t)]}function Xs(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:V.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Zs(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function Qs(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function $s(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function ec(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function tc(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}function nc(e){let t=e??globalThis.document;if(!t)throw Error(`[wysio] A DOM document is required.`);return t}function rc(e,t,n){let r=new((nc(n).defaultView?.DOMParser)??globalThis.DOMParser)().parseFromString(t,`text/html`).body;return Be.fromSchema(e).parse(r)}function ic(e,t,n){let r=nc(n),i=r.createElement(`div`);return i.appendChild(et.fromSchema(e).serializeFragment(t.content,{document:r})),i.innerHTML}function ac(e,t,n){let r=nc(n),i=r.createElement(`div`);return i.appendChild(et.fromSchema(e).serializeFragment(t.content,{document:r})),Be.fromSchema(e).parse(i)}function oc(e,t,n){let r=ue.fromJSON(e,t);return r.check(),ac(e,r,n)}function sc(e,t,n){return t==null||t===``?e.topNodeType.createAndFill():typeof t==`string`?rc(e,t,n):oc(e,t,n)}function cc(e){let t=e.firstChild;return e.childCount===0||e.childCount===1&&!!t?.isTextblock&&t.content.size===0}var lc=class{listeners=new Map;on(e,t){let n=this.listeners.get(e);return n||this.listeners.set(e,n=new Set),n.add(t),()=>this.off(e,t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,...t){for(let n of[...this.listeners.get(e)??[]])n(...t)}has(e){return(this.listeners.get(e)?.size??0)>0}clear(){this.listeners.clear()}},uc={toolbar:`Opmaak`,"toolbar.more":`Meer`,editor:`Teksteditor`,bold:`Vet`,italic:`Cursief`,underline:`Onderstrepen`,strike:`Doorhalen`,code:`Code`,heading:`Tekststijl`,paragraph:`Alinea`,heading1:`Kop 1`,heading2:`Kop 2`,heading3:`Kop 3`,heading4:`Kop 4`,bulletList:`Opsommingslijst`,orderedList:`Genummerde lijst`,blockquote:`Citaat`,horizontalRule:`Horizontale lijn`,link:`Link`,unlink:`Link verwijderen`,image:`Afbeelding`,"image.dialog":`Afbeelding`,"image.url":`Afbeeldings-URL`,"image.alt":`Alternatieve tekst`,"image.altHint":`Beschrijf de afbeelding voor wie ze niet kan zien. Laat leeg als ze enkel decoratief is.`,"image.upload":`Uploaden vanaf computer…`,"image.uploading":`Bezig met uploaden van {name}`,"image.invalid":`Voer een geldige afbeeldings-URL in (http of https).`,"image.align":`Uitlijning`,"image.alignNone":`Geen`,"image.alignLeft":`Links`,"image.alignCenter":`Gecentreerd`,"image.alignRight":`Rechts`,"image.remove":`Afbeelding verwijderen`,table:`Tabel`,"table.insert":`Tabel invoegen`,"table.size":`Tabelgrootte`,"table.cells":`{rows} × {cols}`,"table.header":`Kopregel`,"table.addRowBefore":`Rij erboven invoegen`,"table.addRowAfter":`Rij eronder invoegen`,"table.addColumnBefore":`Kolom links invoegen`,"table.addColumnAfter":`Kolom rechts invoegen`,"table.deleteRow":`Rij verwijderen`,"table.deleteColumn":`Kolom verwijderen`,"table.toggleHeaderRow":`Kopregel aan/uit`,"table.delete":`Tabel verwijderen`,align:`Uitlijning`,alignLeft:`Links uitlijnen`,alignCenter:`Centreren`,alignRight:`Rechts uitlijnen`,alignJustify:`Uitvullen`,textColor:`Tekstkleur`,highlight:`Markeren`,"color.remove":`Kleur verwijderen`,"highlight.remove":`Markering verwijderen`,"color.gray":`Grijs`,"color.red":`Rood`,"color.orange":`Oranje`,"color.yellow":`Geel`,"color.green":`Groen`,"color.teal":`Blauwgroen`,"color.blue":`Blauw`,"color.violet":`Violet`,"color.pink":`Roze`,clearFormatting:`Opmaak wissen`,source:`Broncode`,"source.label":`HTML-broncode`,undo:`Ongedaan maken`,redo:`Opnieuw`,"link.dialog":`Link bewerken`,"link.url":`URL`,"link.newTab":`Openen in nieuw tabblad`,"dialog.apply":`Toepassen`,"dialog.cancel":`Annuleren`,"link.remove":`Verwijderen`,"link.invalid":`Voer een geldige URL in (http, https, mailto of tel).`},dc={toolbar:`Formatting`,"toolbar.more":`More`,editor:`Rich text editor`,bold:`Bold`,italic:`Italic`,underline:`Underline`,strike:`Strikethrough`,code:`Inline code`,heading:`Text style`,paragraph:`Paragraph`,heading1:`Heading 1`,heading2:`Heading 2`,heading3:`Heading 3`,heading4:`Heading 4`,bulletList:`Bulleted list`,orderedList:`Numbered list`,blockquote:`Quote`,horizontalRule:`Horizontal line`,link:`Link`,unlink:`Remove link`,image:`Image`,"image.dialog":`Image`,"image.url":`Image URL`,"image.alt":`Alternative text`,"image.altHint":`Describe the image for people who cannot see it. Leave empty if it is decorative.`,"image.upload":`Upload from computer…`,"image.uploading":`Uploading {name}`,"image.invalid":`Enter a valid image URL (http or https).`,"image.align":`Alignment`,"image.alignNone":`None`,"image.alignLeft":`Left`,"image.alignCenter":`Center`,"image.alignRight":`Right`,"image.remove":`Remove image`,table:`Table`,"table.insert":`Insert table`,"table.size":`Table size`,"table.cells":`{rows} × {cols}`,"table.header":`Header row`,"table.addRowBefore":`Insert row above`,"table.addRowAfter":`Insert row below`,"table.addColumnBefore":`Insert column left`,"table.addColumnAfter":`Insert column right`,"table.deleteRow":`Delete row`,"table.deleteColumn":`Delete column`,"table.toggleHeaderRow":`Toggle header row`,"table.delete":`Delete table`,align:`Alignment`,alignLeft:`Align left`,alignCenter:`Align center`,alignRight:`Align right`,alignJustify:`Justify`,textColor:`Text color`,highlight:`Highlight`,"color.remove":`Remove color`,"highlight.remove":`Remove highlight`,"color.gray":`Gray`,"color.red":`Red`,"color.orange":`Orange`,"color.yellow":`Yellow`,"color.green":`Green`,"color.teal":`Teal`,"color.blue":`Blue`,"color.violet":`Violet`,"color.pink":`Pink`,clearFormatting:`Clear formatting`,source:`Source code`,"source.label":`HTML source`,undo:`Undo`,redo:`Redo`,"link.dialog":`Edit link`,"link.url":`URL`,"link.newTab":`Open in new tab`,"dialog.apply":`Apply`,"dialog.cancel":`Cancel`,"link.remove":`Remove`,"link.invalid":`Enter a valid URL (http, https, mailto or tel).`},fc=new Map([[`en`,dc],[`nl`,uc]]);function pc(e){let t=e.toLowerCase().replace(`_`,`-`);for(let e of[t,t.split(`-`)[0]]){let t=fc.get(e);if(t)return{code:e,messages:t}}return null}function mc(e,t){return t?e.replace(/\{(\w+)\}/g,(e,n)=>n in t?String(t[n]):e):e}var W=e=>`<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${e}</svg>`,G={bold:`<span class="wysio-glyph" style="font-weight:700">B</span>`,italic:`<span class="wysio-glyph" style="font-style:italic;font-family:Georgia,serif">I</span>`,underline:`<span class="wysio-glyph" style="text-decoration:underline">U</span>`,strike:`<span class="wysio-glyph" style="text-decoration:line-through">S</span>`,code:W(`<path d="m8 7-5 5 5 5M16 7l5 5-5 5"/>`),bulletList:W(`<path d="M9 6h11M9 12h11M9 18h11"/><circle cx="4.5" cy="6" r="1" fill="currentColor"/><circle cx="4.5" cy="12" r="1" fill="currentColor"/><circle cx="4.5" cy="18" r="1" fill="currentColor"/>`),orderedList:W(`<path d="M10 6h10M10 12h10M10 18h10"/><path d="M4 4h1.5v5M4 9h3" stroke-width="1.5"/><path d="M4 14.5c.4-.8 2.8-.9 2.8.6 0 1.2-2.8 2.2-2.8 3.4h3" stroke-width="1.5"/>`),blockquote:W(`<path d="M4 7h5v5c0 3-2 4.5-4 5M14 7h5v5c0 3-2 4.5-4 5"/>`),horizontalRule:W(`<path d="M3 12h18"/>`),link:W(`<path d="M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1"/><path d="M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1"/>`),unlink:W(`<path d="M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1"/><path d="M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1"/><path d="M3 3l18 18"/>`),image:W(`<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="2"/><path d="m21 16-5-5-9 9"/>`),table:W(`<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16"/>`),tableRowBefore:W(`<path d="M3 14h18v6H3zM3 17h18M12 3v7M8.5 6.5h7"/>`),tableRowAfter:W(`<path d="M3 4h18v6H3zM3 7h18M12 14v7M8.5 17.5h7"/>`),tableColumnBefore:W(`<path d="M14 3h6v18h-6zM17 3v18M3 12h7M6.5 8.5v7"/>`),tableColumnAfter:W(`<path d="M4 3h6v18H4zM7 3v18M14 12h7M17.5 8.5v7"/>`),tableDeleteRow:W(`<path d="M3 9h18v6H3zM9 9v6M15 9v6M8 4l8 0M8 20h8"/>`),tableDeleteColumn:W(`<path d="M9 3h6v18H9zM9 9h6M9 15h6M4 8v8M20 8v8"/>`),tableHeaderRow:W(`<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M9 10v10M15 10v10"/><path d="M3 6h18" stroke-width="4"/>`),tableDelete:W(`<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m9 9 6 6M15 9l-6 6"/>`),alignLeft:W(`<path d="M4 6h16M4 10h10M4 14h16M4 18h10"/>`),alignCenter:W(`<path d="M4 6h16M7 10h10M4 14h16M7 18h10"/>`),alignRight:W(`<path d="M4 6h16M10 10h10M4 14h16M10 18h10"/>`),alignJustify:W(`<path d="M4 6h16M4 10h16M4 14h16M4 18h16"/>`),textColor:W(`<path d="m6 16 6-12 6 12M8.5 11h7"/><path d="M4 20h16" stroke-width="3" stroke="var(--wysio-icon-accent, currentColor)"/>`),highlight:W(`<path d="m9 11-5 5v3h3l5-5M9 11l4-4 4 4-4 4zM13 7l2-2a1.4 1.4 0 0 1 2 0l2 2a1.4 1.4 0 0 1 0 2l-2 2"/><path d="M14 20h6" stroke-width="3" stroke="var(--wysio-icon-accent, currentColor)"/>`),clearFormatting:W(`<path d="M6 5h11M11.5 5 8 19M4 4l16 16"/><path d="M12 19h3"/>`),source:W(`<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m10 9-3 3 3 3M14 9l3 3-3 3"/>`),undo:W(`<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/>`),redo:W(`<path d="m15 14 5-5-5-5"/><path d="M20 9H9.5a5.5 5.5 0 0 0 0 11H13"/>`)};function K(e){return e}var hc=0,gc=class{editor;dom;key=``;uid=`wysio-pop-${++hc}`;constructor(e,t){this.editor=e,this.dom=e.dom.ownerDocument.createElement(`div`),this.dom.className=`wysio-popover`,this.dom.setAttribute(`role`,`dialog`),e.locale&&(this.dom.lang=e.locale),this.dom.setAttribute(`aria-label`,t),this.dom.hidden=!0,this.dom.addEventListener(`focusout`,e=>{let t=e.relatedTarget;t&&!this.dom.contains(t)&&this.close(!1)}),this.dom.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),this.close())}),e.dom.appendChild(this.dom)}get isOpen(){return!this.dom.hidden}show(e,t){this.dom.hidden=!1,this.notify(!0),this.position(e),this.editor.dom.ownerDocument.addEventListener(`mousedown`,this.onOutside,!0),t.focus()}close(e=!0){this.isOpen&&(this.dom.hidden=!0,this.editor.dom.ownerDocument.removeEventListener(`mousedown`,this.onOutside,!0),this.notify(!1),e&&this.editor.focus())}notify(e){this.editor.dom.dispatchEvent(new CustomEvent(`wysio:popover`,{detail:{key:this.key,open:e}}))}destroy(){this.close(!1),this.dom.remove()}position(e){let{view:t}=this.editor;try{let n=t.coordsAtPos(Math.min(e,t.state.doc.content.size)),r=this.editor.dom.getBoundingClientRect(),i=Math.max(0,Math.min(n.left-r.left,r.width-this.dom.offsetWidth));this.dom.style.left=`${i}px`,this.dom.style.top=`${n.bottom-r.top+6}px`}catch{}}onOutside=e=>{this.dom.contains(e.target)||this.close(!1)}},_c=new WeakMap;function vc(e,t,n){let r=_c.get(e);if(!r){let t=new Map;_c.set(e,r=t),e.on(`destroy`,()=>{for(let e of t.values())e.destroy();_c.delete(e)})}let i=r.get(t);return i||(i=n(),i.key=t,r.set(t,i)),i}function yc(e,t,n){let r=e.createElement(`form`);return r.noValidate=!0,r.innerHTML=n.replaceAll(`{id}`,t),r}function q(e,t){let n=e.querySelector(t);if(!n)throw Error(`[wysio] Missing element ${t}`);return n}var bc=class extends gc{buttons=[];constructor(e,t,n){super(e,t);let r=e.dom.ownerDocument,i=r.createElement(`div`);i.className=`wysio-menu`;for(let e of n){let t=r.createElement(`button`);t.type=`button`,t.className=`wysio-menu-item`,t.dataset.action=e.id,t.innerHTML=e.icon??``,t.append(r.createTextNode(e.label)),e.isActive&&t.setAttribute(`aria-pressed`,`false`),t.addEventListener(`click`,()=>{this.close(!1),e.run(this.editor)}),i.appendChild(t),this.buttons.push({button:t,item:e})}i.addEventListener(`keydown`,this.onKey),this.dom.appendChild(i)}open(){let{state:e}=this.editor.view;for(let{button:t,item:n}of this.buttons)t.disabled=n.isEnabled?!n.isEnabled(e):!1,n.isActive&&t.setAttribute(`aria-pressed`,String(n.isActive(e)));let t=this.buttons.filter(e=>!e.button.disabled),n=t.find(e=>e.button.getAttribute(`aria-pressed`)===`true`)??t[0];this.show(e.selection.from,n?.button??this.dom)}onKey=e=>{let t=this.buttons.map(e=>e.button).filter(e=>!e.disabled),n=t.indexOf(e.target),r=null;e.key===`ArrowDown`?r=(n+1)%t.length:e.key===`ArrowUp`?r=(n-1+t.length)%t.length:e.key===`Home`?r=0:e.key===`End`&&(r=t.length-1),r!==null&&(e.preventDefault(),t[r]?.focus())}},xc=[`left`,`center`,`right`,`justify`],Sc=[`paragraph`,`heading`],Cc=e=>e===`center`||e===`right`||e===`justify`?e:null;function wc(e){for(let t of xc)if(e.classList.contains(`wysio-align-${t}`))return t;let t=(e.style.textAlign||e.getAttribute(`align`)||``).toLowerCase();return xc.includes(t)?t:null}function Tc(e,t){if(!Array.isArray(e))return e;let[n,r,...i]=e;if(typeof r==`object`&&r&&!Array.isArray(r)&&!(typeof Node<`u`&&r instanceof Node)){let e={...r};return e.class=e.class?`${e.class} ${t}`:t,[n,e,...i]}return[n,{class:t},...r===void 0?[]:[r],...i]}function Ec(e){let t=e.toDOM;return{...e,attrs:{...e.attrs,align:{default:null,validate:`string|null`}},parseDOM:e.parseDOM?.map(e=>{if(!(`tag`in e))return e;let t=e;return{...t,attrs:void 0,getAttrs:e=>{let n=t.getAttrs?t.getAttrs(e):null;return n!==!1&&{...t.attrs,...n,align:Cc(wc(e))}}}}),toDOM:t?e=>{let n=t(e),r=Cc(e.attrs.align);return r?Tc(n,`wysio-align-${r}`):n}:void 0}}function Dc(e){let t=[];for(let{$from:n,$to:r}of e.selection.ranges)e.doc.nodesBetween(n.pos,r.pos,(e,n)=>(e.isTextblock&&`align`in e.type.spec.attrs&&t.push({node:e,pos:n}),!e.isTextblock));return t}function Oc(e){return(t,n)=>{let r=Dc(t);if(!r.length)return!1;if(n){let i=t.tr,a=Cc(e);for(let{node:e,pos:t}of r)i.setNodeMarkup(t,void 0,{...e.attrs,align:a});n(i.scrollIntoView())}return!0}}function kc(e,t){let n=Dc(e);return n.length>0&&n.every(({node:e})=>(Cc(e.attrs.align)??`left`)===t)}var Ac={left:`Mod-Shift-l`,center:`Mod-Shift-e`,right:`Mod-Shift-r`,justify:`Mod-Shift-j`},jc=e=>`align${e[0].toUpperCase()}${e.slice(1)}`;function Mc(e){e.isEditable&&vc(e,`alignment`,()=>new bc(e,e.t(`align`),xc.map(t=>({id:jc(t),label:e.t(jc(t)),icon:G[jc(t)],run:e=>e.exec(Oc(t)),isActive:e=>kc(e,t),isEnabled:e=>Oc(t)(e)})))).open()}var Nc=K({name:`alignment`,schema:{extendNodes:Object.fromEntries(Sc.map(e=>[e,Ec]))},keymap:()=>Object.fromEntries(xc.map(e=>[Ac[e],Oc(e)])),toolbarItems:({editor:e})=>{let t={align:{label:e.t(`align`),icon:G.alignLeft,run:Mc,popover:`alignment`,dropdown:!0,render:(e,t)=>{let n=xc.find(t=>kc(e,t))??`left`;t.setIcon(G[jc(n)])},isActive:e=>xc.slice(1).some(t=>kc(e,t)),isEnabled:e=>Oc(`left`)(e)}};for(let n of xc)t[jc(n)]={label:e.t(jc(n)),icon:G[jc(n)],shortcut:Ac[n],command:Oc(n),isActive:e=>kc(e,n)};return t}});function Pc(e={}){return new Bn({view(t){return new Fc(t,e)}})}var Fc=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.lastDragEvent=null,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.setCursor(null),this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){if(this.cursorPos!=null&&t.doc!=e.state.doc){if(this.lastDragEvent){let e=this.computeTarget(this.lastDragEvent);e==this.cursorPos?this.updateOverlay():this.setCursor(e)}else this.updateOverlay()}}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}computeTarget(e){let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(!t||i)return null;let a=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let e=Qt(this.editorView.state.doc,a,this.editorView.dragging.slice);e!=null&&(a=e)}return a}dragover(e){if(!this.editorView.editable)return;this.lastDragEvent=e;let t=this.computeTarget(e);t!=null&&(this.setCursor(t),this.scheduleRemoval(5e3))}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},J=class e extends w{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):w.near(r)}content(){return f.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new Ic(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!Rc(e)||!zc(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){e:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)<o.childCount:t.index(r)>0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!E.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue e}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};J.prototype.visible=!1,J.findFrom=J.findGapCursorFrom,w.jsonID(`gapcursor`,J);var Ic=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return J.valid(t)?new J(t):w.near(t)}};function Lc(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function Rc(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0}else for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||Lc(e.type))return!0;if(e.inlineContent)return!1}}return!0}function zc(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0}else for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||Lc(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Bc(){return new Bn({props:{decorations:Gc,createSelectionBetween(e,t,n){return t.pos==n.pos&&J.valid(n)?new J(n):null},handleClick:Uc,handleKeyDown:Vc,handleDOMEvents:{beforeinput:Wc}}})}var Vc=Gr({ArrowLeft:Hc(`horiz`,-1),ArrowRight:Hc(`horiz`,1),ArrowUp:Hc(`vert`,-1),ArrowDown:Hc(`vert`,1)});function Hc(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof T){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=J.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new J(c))),!0):!1}}function Uc(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!J.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&E.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new J(r))),!0)}function Wc(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof J))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=o.empty;for(let e=r.length-1;e>=0;e--)i=o.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new f(i,0,0));return a.setSelection(T.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function Gc(e){if(!(e.selection instanceof J))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,H.create(e.doc,[V.widget(e.selection.head,t,{key:`gapcursor`})])}var Kc=K({name:`base`,schema:{nodes:{doc:{content:`block+`},paragraph:{content:`inline*`,group:`block`,parseDOM:[{tag:`p`}],toDOM:()=>[`p`,0]},text:{group:`inline`}}},prosemirrorPlugins:()=>[Bc(),Pc({class:`wysio-dropcursor`})]});function qc(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a);if(!o)return!1;let s=r?n.tr:null;return Jc(s,o,e,t)?(r&&r(s.scrollIntoView()),!0):!1}}function Jc(e,t,n,r=null){let i=!1,a=t,o=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=o.resolve(t.start-2);a=new ce(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new ce(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let s=Ft(a,n,r,t);return s?(e&&Yc(e,t,s,i,n),!0):!1}function Yc(e,t,n,r,i){let a=o.empty;for(let e=n.length-1;e>=0;e--)a=o.from(n[e].type.create(n[e].attrs,a));e.step(new C(t.start-(r?2:0),t.end,t.start,t.end,new f(a,0,0),n.length,!0));let s=0;for(let e=0;e<n.length;e++)n[e].type==i&&(s=e+1);let c=n.length-s,l=t.start+n.length-(r?2:0),u=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&c&&Gt(e.doc,l,c)&&(e.split(l,c),l+=2*c),l+=u.child(n).nodeSize;return e}function Xc(e,t){return e instanceof Me?t==e:e.indexOf(t)>-1}function Zc(e,t){return function(n,r){let{$from:i,$to:a,node:s}=n.selection;if(s&&s.isBlock||i.depth<2||!i.sameParent(a))return!1;let c=i.node(-1);if(!Xc(e,c.type))return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||!Xc(e,i.node(-3).type)||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let e=o.empty,t=i.index(-1)?1:i.index(-2)?2:3;for(let n=i.depth-t;n>=i.depth-3;n--)e=o.from(i.node(n).copy(e));let a=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;e=e.append(o.from(i.node(-3).type.createAndFill()));let s=i.before(i.depth-(t-1)),c=n.tr.replace(s,i.after(-a),new f(e,4-t,0)),l=-1;c.doc.nodesBetween(s,c.doc.content.size,(e,t)=>{if(l>-1)return!1;e.isTextblock&&e.content.size==0&&(l=t+1)}),l>-1&&c.setSelection(w.near(c.doc.resolve(l))),r(c.scrollIntoView())}return!0}let l=a.pos==i.end()?c.contentMatchAt(0).defaultType:null,u=n.tr.delete(i.pos,a.pos),d=l||t?[t?{type:c.type,attrs:t}:null,l?{type:l}:null]:void 0;return Gt(u.doc,i.pos,2,d)?(r&&r(u.split(i.pos,2,d).scrollIntoView()),!0):!1}}function Qc(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&Xc(e,t.firstChild.type));return a?n?Xc(e,r.node(a.depth-1).type)?$c(t,n,a):el(t,n,a):!0:!1}}function $c(e,t,n){let r=e.tr,i=n.end,a=n.$to.end(n.depth),s=n.parent.child(n.endIndex-1).type;i<a&&(r.step(new C(i-1,a,i,a,new f(o.from(s.create(null,n.parent.copy())),1,0),1,!0)),n=new ce(r.doc.resolve(n.$from.pos),r.doc.resolve(a),n.depth));let c=Nt(n);if(c==null)return!1;r.lift(n,c);let l=r.doc.resolve(r.mapping.map(i,-1)-1);return qt(r.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&r.join(l.pos),t(r.scrollIntoView()),!0}function el(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,a=n.startIndex;t>a;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),s=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let c=n.startIndex==0,l=n.endIndex==i.childCount,u=a.node(-1),d=a.index(-1);if(!u.canReplace(d+ +!c,d+1,s.content.append(l?o.empty:o.from(i))))return!1;let p=a.pos,m=p+s.nodeSize;return r.step(new C(p-+!!c,m+ +!!l,p+1,m-1,new f((c?o.empty:o.from(i.copy(o.empty))).append(l?o.empty:o.from(i.copy(o.empty))),+!c,+!l),+!c)),t(r.scrollIntoView()),!0}function tl(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&Xc(e,t.firstChild.type));if(!a)return!1;let s=a.startIndex;if(s==0)return!1;let c=a.parent,l=c.child(s-1);if(!Xc(e,l.type))return!1;if(n){let e=l.lastChild&&l.lastChild.type==c.type,r=o.from(e?l.lastChild.lastChild.type.create():null),i=new f(o.from(l.type.create(null,o.from(c.type.create(null,r)))),e?3:1,0),s=a.start,u=a.end;n(t.tr.step(new C(s-(e?3:1),u,s,u,i,1,!0)).scrollIntoView())}return!0}}function nl(e,t){let{from:n,to:r,empty:i,$from:a}=e.selection;return i?!!t.isInSet(e.storedMarks??a.marks()):e.doc.rangeHasMark(n,r,t)}function rl(e,t){let{$from:n}=e.selection;for(let e=n.depth;e>0;e--){let r=n.node(e);if(t.includes(r.type))return{node:r,depth:e,pos:n.before(e)}}return null}function il(e,t,n){return(r,i)=>{let a=rl(r,n);return a?a.node.type===e?Qc(t)(r,i):(i&&i(r.tr.setNodeMarkup(a.pos,e).scrollIntoView()),!0):qc(e)(r,i)}}function al(e){return(t,n)=>rl(t,[e])?er(t,n):mr(e)(t,n)}function ol(e,t){let n=e.parent,r=n.childAfter(e.parentOffset),i=r.node?t.isInSet(r.node.marks):void 0;if(!i&&(r=n.childBefore(e.parentOffset),i=r.node?t.isInSet(r.node.marks):void 0,!i||!r.node))return null;let a=e.start(),o=r.index,s=a+r.offset;for(;o>0&&i.isInSet(n.child(o-1).marks);)o--,s-=n.child(o).nodeSize;let c=r.index+1,l=a+r.offset+n.child(r.index).nodeSize;for(;c<n.childCount&&i.isInSet(n.child(c).marks);)l+=n.child(c).nodeSize,c++;return{from:s,to:l,mark:i}}var sl=K({name:`blockquote`,schema:{nodes:{blockquote:{content:`block+`,group:`block`,defining:!0,parseDOM:[{tag:`blockquote`}],toDOM:()=>[`blockquote`,0]}}},keymap:({schema:e})=>({"Mod-Shift-b":al(e.nodes.blockquote)}),inputRules:({schema:e})=>[jr(/^\s*>\s$/,e.nodes.blockquote)],toolbarItems:({schema:e,editor:t})=>{let n=e.nodes.blockquote;return{blockquote:{label:t.t(`blockquote`),icon:G.blockquote,shortcut:`Mod-Shift-b`,command:al(n),isActive:e=>!!rl(e,[n])}}}}),cl=K({name:`horizontalRule`,schema:{nodes:{horizontal_rule:{group:`block`,parseDOM:[{tag:`hr`}],toDOM:()=>[`hr`]}}},inputRules:({schema:e})=>[new Tr(/^(?:---|___|\*\*\*)$/,(t,n,r,i)=>{let a=t.doc.resolve(r),o=e.nodes.horizontal_rule.create();return!a.parent.isTextblock||a.parent.content.size!==i-r+1?null:t.tr.replaceRangeWith(a.before(),a.after(),o).scrollIntoView()})],toolbarItems:({schema:e,editor:t})=>{let n=e.nodes.horizontal_rule;return{horizontalRule:{label:t.t(`horizontalRule`),icon:G.horizontalRule,command:(e,t)=>!e.selection.$from.parent.canReplaceWith(0,0,n)&&!e.selection.$from.parent.isTextblock?!1:(t&&t(e.tr.replaceSelectionWith(n.create()).scrollIntoView()),!0)}}}}),ll=K({name:`hardBreak`,schema:{nodes:{hard_break:{inline:!0,group:`inline`,selectable:!1,parseDOM:[{tag:`br`}],toDOM:()=>[`br`]}}},keymap:({schema:e})=>{let t=e.nodes.hard_break,n=yr(rr,(e,n)=>(n&&n(e.tr.replaceSelectionWith(t.create()).scrollIntoView()),!0));return{"Shift-Enter":n,"Mod-Enter":n}}}),ul=[`align`],dl=new Set([`link`]),fl=(e,t)=>{let n=e.tr,r=!1,i=Object.values(e.schema.marks).filter(e=>!dl.has(e.name)),a=e=>{let t=n.doc.nodeAt(e);if(!t)return;let i={};for(let e of ul)e in t.type.spec.attrs&&t.attrs[e]!=null&&(i[e]=null);Object.keys(i).length&&(n.setNodeMarkup(e,void 0,{...t.attrs,...i}),r=!0)};for(let{$from:t,$to:o}of e.selection.ranges){let s=t.pos,c=o.pos;for(let t of i)s<c&&e.doc.rangeHasMark(s,c,t)&&(n.removeMark(s,c,t),r=!0);s===c?t.depth>0&&a(t.before()):e.doc.nodesBetween(s,c,(e,t)=>(e.isTextblock&&a(t),!e.isTextblock))}if(e.selection.empty){let t=e.storedMarks??e.selection.$from.marks();t.some(e=>!dl.has(e.type.name))&&(n.setStoredMarks(t.filter(e=>dl.has(e.type.name))),r=!0)}return r?(t&&t(n.scrollIntoView()),!0):!1},pl=K({name:`clearFormatting`,keymap:()=>({"Mod-\\":fl}),toolbarItems:({editor:e})=>({clearFormatting:{label:e.t(`clearFormatting`),icon:G.clearFormatting,shortcut:`Mod-\\`,command:fl}})}),ml=[{name:`gray`,value:`#868e96`},{name:`red`,value:`#e03131`},{name:`orange`,value:`#e8590c`},{name:`green`,value:`#2f9e44`},{name:`teal`,value:`#0c8599`},{name:`blue`,value:`#1971c2`},{name:`violet`,value:`#6741d9`},{name:`pink`,value:`#c2255c`}],hl=[{name:`yellow`,value:`#ffec99`},{name:`green`,value:`#b2f2bb`},{name:`blue`,value:`#a5d8ff`},{name:`pink`,value:`#fcc2d7`},{name:`orange`,value:`#ffd8a8`},{name:`violet`,value:`#d0bfff`},{name:`red`,value:`#ffc9c9`},{name:`gray`,value:`#e9ecef`}],gl=e=>e.toString(16).padStart(2,`0`);function _l(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase(),n=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(t);if(n)return`#${n[1]}${n[1]}${n[2]}${n[2]}${n[3]}${n[3]}`;if(/^#[0-9a-f]{6}$/.test(t))return t;if(n=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(1|1\.0+)\s*)?\)$/.exec(t),n){let e=[n[1],n[2],n[3]].map(Number);if(e.every(e=>e<=255))return`#${e.map(gl).join(``)}`}return null}var vl=/^[a-z][a-z0-9-]*$/;function yl(e){let t=e.map(e=>{let t=_l(e.value);if(!t||!vl.test(e.name))throw Error(`[wysio] Invalid palette colour "${e.name}" (${e.value}).`);return{...e,value:t}}),n=new Map(t.map(e=>[e.name,e])),r=new Map(t.map(e=>[e.value,e.name]));return{colors:t,name:e=>typeof e==`string`&&n.has(e)?e:null,fromCSS:e=>r.get(_l(e)??``)??null,fromClass:(e,t)=>{for(let r of e.classList)if(r.startsWith(t)&&n.has(r.slice(t.length)))return r.slice(t.length);return null},value:e=>n.get(e)?.value??null}}function bl(e,t,n){let r=n?t.value(n):null;r?e.style.setProperty(`--wysio-icon-accent`,r):e.style.removeProperty(`--wysio-icon-accent`)}function xl(e,t){return(n,r)=>{if(!vr(e)(n))return!1;if(r){let i=e.create({color:t}),a=n.tr;if(n.selection.empty)a.addStoredMark(i);else for(let{$from:e,$to:t}of n.selection.ranges)a.addMark(e.pos,t.pos,i);r(a.scrollIntoView())}return!0}}function Sl(e){return(t,n)=>{if(n){let r=t.tr;if(t.selection.empty)r.removeStoredMark(e);else for(let{$from:n,$to:i}of t.selection.ranges)r.removeMark(n.pos,i.pos,e);n(r.scrollIntoView())}return!0}}function Cl(e,t){let{empty:n,$from:r,from:i,to:a}=e.selection;if(n)return t.isInSet(e.storedMarks??r.marks())?.attrs.color??null;let o,s=!1;return e.doc.nodesBetween(i,a,e=>{if(!e.isText)return;let n=t.isInSet(e.marks)?.attrs.color??null;o===void 0?o=n:o!==n&&(s=!0)}),s?null:o??null}var wl=(e,t)=>{if(t.label)return t.label;let n=`color.${t.name}`,r=e.t(n);return r===n?t.name:r},Tl=4,El=class extends gc{type;swatches=[];constructor(e,t,n,r,i,a){super(e,t),this.type=n;let o=e.dom.ownerDocument,s=o.createElement(`div`);s.className=`wysio-palette`,s.setAttribute(`role`,`group`),s.setAttribute(`aria-label`,t);for(let t of r.colors){let n=o.createElement(`button`);n.type=`button`,n.className=`wysio-swatch wysio-swatch-${a}`,n.style.setProperty(`--wysio-swatch`,t.value),n.setAttribute(`aria-label`,wl(e,t)),n.title=wl(e,t),n.setAttribute(`aria-pressed`,`false`),n.tabIndex=-1,a===`text`&&(n.textContent=`A`),n.addEventListener(`click`,()=>this.apply(t.name)),s.appendChild(n),this.swatches.push({button:n,value:t.name})}s.addEventListener(`keydown`,this.onKey);let c=o.createElement(`button`);c.type=`button`,c.className=`wysio-button wysio-palette-remove`,c.dataset.action=`remove`,c.textContent=i,c.addEventListener(`click`,()=>{this.close(!1),this.editor.exec(Sl(this.type))}),this.dom.append(s,c)}open(){let{state:e}=this.editor.view,t=Cl(e,this.type),n=this.swatches[0];for(let e of this.swatches){let r=e.value===t;e.button.setAttribute(`aria-pressed`,String(r)),r&&(n=e)}for(let e of this.swatches)e.button.tabIndex=e===n?0:-1;this.show(e.selection.from,n?.button??this.dom)}apply(e){this.close(!1),this.editor.exec(xl(this.type,e))}onKey=e=>{let t=this.swatches.map(e=>e.button),n=t.indexOf(e.target);if(n===-1)return;let r={ArrowRight:1,ArrowLeft:-1,ArrowDown:Tl,ArrowUp:-4},i=null;e.key in r?i=Math.min(t.length-1,Math.max(0,n+r[e.key])):e.key===`Home`?i=0:e.key===`End`&&(i=t.length-1),i!==null&&(e.preventDefault(),t.forEach((e,t)=>e.tabIndex=t===i?0:-1),t[i]?.focus())}};function Dl(e={}){let t=yl(e.colors??ml);return K({name:`textColor`,schema:{marks:{text_color:{attrs:{color:{validate:`string`}},parseDOM:[{tag:`span`,getAttrs:e=>{let n=t.fromClass(e,`wysio-color-`);return n?{color:n}:!1}},{style:`color`,getAttrs:e=>{let n=t.fromCSS(e);return n?{color:n}:!1}}],toDOM:e=>{let n=t.name(e.attrs.color);return[`span`,n?{class:`wysio-color-${n}`}:{},0]}}}},toolbarItems:({schema:e,editor:n})=>{let r=e.marks.text_color;return{textColor:{label:n.t(`textColor`),icon:G.textColor,popover:`textColor`,dropdown:!0,render:(e,n)=>bl(n.el,t,Cl(e,r)),run:e=>vc(e,`textColor`,()=>new El(e,e.t(`textColor`),r,t,e.t(`color.remove`),`text`)).open(),isActive:e=>Cl(e,r)!==null,isEnabled:e=>vr(r)(e)}}}})}function Ol(e={}){let t=yl(e.colors??hl),n=t.colors[0]?.name;return K({name:`highlight`,schema:{marks:{highlight:{attrs:{color:{validate:`string`}},parseDOM:[{tag:`mark`,getAttrs:e=>{let r=e,i=t.fromClass(r,`wysio-highlight-`)??t.fromCSS(r.style.backgroundColor)??n;return i?{color:i}:!1}},{style:`background-color`,getAttrs:e=>{let n=t.fromCSS(e);return n?{color:n}:!1}}],toDOM:e=>{let n=t.name(e.attrs.color);return[`mark`,n?{class:`wysio-highlight-${n}`}:{},0]}}}},toolbarItems:({schema:e,editor:n})=>{let r=e.marks.highlight;return{highlight:{label:n.t(`highlight`),icon:G.highlight,popover:`highlight`,dropdown:!0,render:(e,n)=>bl(n.el,t,Cl(e,r)),run:e=>vc(e,`highlight`,()=>new El(e,e.t(`highlight`),r,t,e.t(`highlight.remove`),`background`)).open(),isActive:e=>Cl(e,r)!==null,isEnabled:e=>vr(r)(e)}}}})}var kl=[1,2,3,4],Al=e=>Math.min(4,Math.max(1,Math.trunc(Number(e))||1)),jl=K({name:`heading`,schema:{nodes:{heading:{attrs:{level:{default:1,validate:`number`}},content:`inline*`,group:`block`,defining:!0,parseDOM:[...kl.map(e=>({tag:`h${e}`,attrs:{level:e}})),{tag:`h5`,attrs:{level:4}},{tag:`h6`,attrs:{level:4}}],toDOM:e=>[`h${Al(e.attrs.level)}`,0]}}},keymap:({schema:e})=>{let t={"Mod-Alt-0":hr(e.nodes.paragraph)};for(let n of kl)t[`Mod-Alt-${n}`]=hr(e.nodes.heading,{level:n});return t},inputRules:({schema:e})=>[Mr(/^(#{1,4})\s$/,e.nodes.heading,e=>({level:e[1].length}))],toolbarItems:({schema:e,editor:t})=>{let{paragraph:n,heading:r}=e.nodes;return{heading:{type:`select`,label:t.t(`heading`),options:[{value:`p`,label:t.t(`paragraph`)},...kl.map(e=>({value:`h${e}`,label:t.t(`heading${e}`)}))],getValue:e=>{let{$from:t,$to:i}=e.selection,a=t.parent;return!t.sameParent(i)&&a!==i.parent?``:a.type===n?`p`:a.type===r?`h${a.attrs.level}`:``},isEnabled:e=>hr(n)(e)||hr(r,{level:1})(e),onSelect:(e,t)=>{let i=t===`p`?hr(n):hr(r,{level:Al(t.slice(1))});e.exec(i)}}}}}),Ml=200,Y=function(){};Y.prototype.append=function(e){return e.length?(e=Y.from(e),!this.length&&e||e.length<Ml&&this.leafAppend(e)||this.length<Ml&&e.leafPrepend(this)||this.appendInner(e)):this},Y.prototype.prepend=function(e){return e.length?Y.from(e).append(this):this},Y.prototype.appendInner=function(e){return new Pl(this,e)},Y.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?Y.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},Y.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},Y.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)},Y.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},Y.from=function(e){return e instanceof Y?e:e&&e.length?new Nl(e):Y.empty};var Nl=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i<n;i++)if(e(this.values[i],r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){for(var i=t-1;i>=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=Ml)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=Ml)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(Y);Y.empty=new Nl([]);var Pl=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,t,n,r){var i=this.left.length;if(t<i&&this.left.forEachInner(e,t,Math.min(n,i),r)===!1||n>i&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n<i&&this.left.forEachInvertedInner(e,Math.min(t,i),n,r)===!1)return!1},t.prototype.sliceInner=function(e,t){if(e==0&&t==this.length)return this;var n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(Y),Fl=500,Il=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step)i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);else{if(i){u.push(new Rl(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new Rl(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1}},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;e<t.steps.length;e++){let r=t.steps[e].invert(t.docs[e]),l=new Rl(t.mapping.maps[e],r,n),u;(u=c&&c.merge(l))&&(l=u,e?a.pop():s=s.slice(0,s.length-1)),a.push(l),n&&=(o++,void 0),i||(c=l)}let l=o-r.depth;return l>Bl&&(s=Ll(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new vt;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new Rl(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;n=Math.min(this.items.length,n);let r=[],i=this.items.length-n,a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new Rl(i,o,l))}else r.push(new Rl(i))},i);let l=[];for(let e=n;e<o;e++)l.push(new Rl(a.maps[e]));let u=this.items.slice(0,i).append(l).append(r),d=new e(u,s);return d.emptyItemCount()>Fl&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new Rl(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(Y.from(i.reverse()),a)}};Il.empty=new Il(Y.empty,0);function Ll(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var Rl=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},zl=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},Bl=20;function Vl(e,t,n,r){let i=n.getMeta(Xl),a;if(i)return i.historyState;n.getMeta(Zl)&&(e=new zl(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(Xl))return o.getMeta(Xl).redo?new zl(e.done.addTransform(n,void 0,r,Yl(t)),e.undone,Ul(n.mapping.maps),e.prevTime,e.prevComposition):new zl(e.done,e.undone.addTransform(n,void 0,r,Yl(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!Hl(n,e.prevRanges)),s=o?Wl(e.prevRanges,n.mapping):Ul(n.mapping.maps);return new zl(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,Yl(t)),Il.empty,s,n.time,i??e.prevComposition)}return(a=n.getMeta(`rebased`))?new zl(e.done.rebased(n,a),e.undone.rebased(n,a),Wl(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new zl(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Wl(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function Hl(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i<t.length;i+=2)e<=t[i+1]&&r>=t[i]&&(n=!0)}),n}function Ul(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function Wl(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),a=t.map(e[r+1],-1);i<=a&&n.push(i,a)}return n}function Gl(e,t){for(let n=0;n<t.steps.length;n++){let r=t.mapping.maps[n],i=-1;if(r.forEach((e,t)=>i=t),i<0){let e=t.steps[n];(e instanceof xt||e instanceof St)&&(i=e.to)}if(i>-1)return w.near(e.doc.resolve(i))}return e.selection}function Kl(e,t,n){let r=Yl(t),i=Xl.get(t).spec.config,a=(n?e.undone:e.done).popEvent(t,r);if(!a)return null;let o=a.selection.resolve(a.transform.doc),s=(n?e.done:e.undone).addTransform(a.transform,Gl(t,a.transform).getBookmark(),i,r),c=new zl(n?s:a.remaining,n?a.remaining:s,null,0,-1);return a.transform.setSelection(o).setMeta(Xl,{redo:n,historyState:c})}var ql=!1,Jl=null;function Yl(e){let t=e.plugins;if(Jl!=t){ql=!1,Jl=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){ql=!0;break}}return ql}var Xl=new Un(`history`),Zl=new Un(`closeHistory`);function Ql(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Bn({key:Xl,state:{init(){return new zl(Il.empty,Il.empty,null,0,-1)},apply(t,n,r){return Vl(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r=n==`historyUndo`?eu:n==`historyRedo`?tu:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function $l(e,t){return(n,r)=>{let i=Xl.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=Kl(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var eu=$l(!1,!0),tu=$l(!0,!0),nu=()=>typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),ru=K({name:`history`,prosemirrorPlugins:()=>[Ql()],keymap:()=>({"Mod-z":eu,"Mod-Shift-z":tu,...nu()?{}:{"Mod-y":tu}}),toolbarItems:({editor:e})=>({undo:{label:e.t(`undo`),icon:G.undo,shortcut:`Mod-z`,command:eu},redo:{label:e.t(`redo`),icon:G.redo,shortcut:`Mod-Shift-z`,command:tu}})}),iu=new Set([`http`,`https`,`mailto`,`tel`]),au=/[\u0000- \u007f-\u009f]/g,ou=/[\u0000-\u001f\u007f-\u009f]/g;function su(e){if(typeof e!=`string`)return null;let t=e.trim().replace(ou,``);if(!t)return null;let n=t.replace(au,``),r=/^([a-z][a-z0-9+.-]*):/i.exec(n);if(r)return iu.has(r[1].toLowerCase())?t:null;let i=n.indexOf(`:`);if(i!==-1){let e=n.search(/[/?#]/);if(e===-1||i<e)return null}return t}function cu(e){let t=e.trim();if(!t)return null;let n=/^[a-z][a-z0-9+.-]*:/i.test(t),r=/^([/?#.]|\/\/)/.test(t);if(!n&&!r){if(/^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(t))t=`mailto:${t}`;else if(/^[^\s/]+\.[^\s/]+/.test(t))t=`https://${t}`;else return null}let i=su(t);if(!i)return null;if(/^https?:/i.test(i))try{if(!new URL(i).hostname)return null}catch{return null}return i}var lu=/^data:image\/(png|gif|jpe?g|webp|avif|bmp);base64,[a-z0-9+/=\s]+$/i;function uu(e,{allowDataUrls:t=!1}={}){if(typeof e!=`string`)return null;let n=e.trim();if(/^data:/i.test(n.replace(au,``)))return t&&lu.test(n)?n:null;let r=su(n);return!r||/^(mailto|tel):/i.test(r.replace(au,``))?null:r}var du=[`left`,`center`,`right`],fu=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/avif`],pu=e=>{let t=typeof e==`number`?String(e):typeof e==`string`?e.trim():``;if(!/^\d+$/.test(t))return null;let n=Number(t);return n>0&&n<=1e4?n:null},mu=e=>typeof e==`string`?e:null,hu=e=>du.includes(e)?e:null;function gu(e){for(let t of du)if(e.classList.contains(`wysio-image-${t}`))return t;let t=e.style.cssFloat||e.style.getPropertyValue(`float`);if(t===`left`||t===`right`)return t;if(e.style.display===`block`&&e.style.marginLeft===`auto`&&e.style.marginRight===`auto`)return`center`;let n=e.getAttribute(`align`)?.toLowerCase();return n===`left`||n===`right`?n:n===`middle`||n===`center`?`center`:null}var _u=new WeakMap,vu=e=>_u.get(e)??{allowDataUrls:!1,types:fu};function yu(e,t){let n=uu(e.src,t);return n?{src:n,alt:mu(e.alt),title:mu(e.title),width:pu(e.width),height:pu(e.height),align:hu(e.align)}:null}var bu=new Un(`wysio-upload`),xu=new WeakMap;function Su(e,t){let n=bu.getState(e)?.find(void 0,void 0,e=>e.id===t);return n?.length?n[0].from:null}function Cu(e,t){let n=e.dom.ownerDocument,r=n.createElement(`span`);r.className=`wysio-upload`,r.setAttribute(`role`,`status`),r.setAttribute(`aria-label`,e.t(`image.uploading`,{name:t.name})),r.style.setProperty(`--wysio-progress`,`0`);let i=``;if(typeof URL.createObjectURL==`function`){i=URL.createObjectURL(t);let e=n.createElement(`img`);e.src=i,e.alt=``,r.appendChild(e)}let a=n.createElement(`span`);return a.className=`wysio-upload-bar`,r.appendChild(a),{dom:r,revoke:()=>i&&URL.revokeObjectURL(i)}}function wu(e,t,n){let r=e.options.upload,i=e.schema.nodes.image;if(!r||!i||!e.isEditable)return[];let a=vu(e),o=xu.get(e);if(!o){let t=new Set;xu.set(e,o=t),e.on(`destroy`,()=>t.forEach(e=>e.abort()))}let s=o;return[...t].map(async t=>{if(!a.types.includes(t.type)){e.reportError(Error(`Unsupported image type: ${t.type||`unknown`}`),{source:`upload`,file:t});return}let{view:o}=e,c={},l=Cu(e,t),u=o.state.tr;n===void 0&&!u.selection.empty&&u.deleteSelection();let d=n??u.selection.from;o.dispatch(u.setMeta(bu,{add:{id:c,pos:d,dom:l.dom}}).setMeta(`addToHistory`,!1));let f=new AbortController;s.add(f);try{let n=await r(t,{editor:e,signal:f.signal,onProgress:e=>l.dom.style.setProperty(`--wysio-progress`,String(Math.min(1,Math.max(0,e))))});if(f.signal.aborted)return;let{url:o,...s}=typeof n==`string`?{url:n}:n,u=yu({...s,src:o},a);if(!u)throw Error(`Upload handler returned an unsafe or empty URL`);let d=Su(e.view.state,c);if(d===null)return;e.view.dispatch(e.view.state.tr.insert(d,i.create(u)).setMeta(bu,{remove:{id:c}}))}catch(n){if(f.signal.aborted)return;Su(e.view.state,c)!==null&&e.view.dispatch(e.view.state.tr.setMeta(bu,{remove:{id:c}}).setMeta(`addToHistory`,!1)),e.reportError(n,{source:`upload`,file:t})}finally{s.delete(f),l.revoke()}})}function Tu(e,t){let{types:n}=vu(e);return[...t??[]].filter(e=>n.includes(e.type))}function Eu(e){return new Bn({key:bu,state:{init:()=>H.empty,apply(e,t){let n=t.map(e.mapping,e.doc),r=e.getMeta(bu);if(r?.add&&(n=n.add(e.doc,[V.widget(r.add.pos,r.add.dom,{id:r.add.id})])),r?.remove){let{id:e}=r.remove;n=n.remove(n.find(void 0,void 0,t=>t.id===e))}return n}},props:{decorations:e=>bu.getState(e),handlePaste:(t,n)=>{if(!e.options.upload)return!1;let r=n.clipboardData;if(!r||r.getData(`text/html`)||r.getData(`text/plain`))return!1;let i=Tu(e,r.files);return i.length?(n.preventDefault(),wu(e,i),!0):!1},handleDrop:(t,n,r,i)=>{if(i||!e.options.upload)return!1;let a=Tu(e,n.dataTransfer?.files);return a.length?(n.preventDefault(),wu(e,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos??t.state.selection.from),!0):!1}}})}function Du(e,t){let{selection:n}=e;return n instanceof E&&n.node.type===t?n.node:null}function Ou(e,t){let n=e.schema.nodes.image,r=n&&yu(t,vu(e));return!n||!r?!1:e.exec((e,i)=>{let a=Du(e,n);if(i){let o=Object.fromEntries(Object.entries(r).filter(([e])=>t[e]!==void 0));i((a?e.tr.setNodeMarkup(e.selection.from,void 0,{...a.attrs,...o}):e.tr.replaceSelectionWith(n.create(r))).scrollIntoView())}return!0})}function ku(e){let t=e.schema.nodes.image;return e.exec((e,n)=>!t||!Du(e,t)?!1:(n&&n(e.tr.deleteSelection().scrollIntoView()),!0))}function Au(e){e.isEditable&&e.schema.nodes.image&&vc(e,`image`,()=>new ju(e)).open()}var ju=class extends gc{src;alt;align;error;file;uploadRow;removeButton;pos=0;original=``;constructor(e){super(e,e.t(`image.dialog`));let t=yc(e.dom.ownerDocument,this.uid,`<label class="wysio-field" for="{id}-src" data-text="image.url"></label>
11
+ <input class="wysio-input" id="{id}-src" name="src" type="text" inputmode="url" autocomplete="off" spellcheck="false" aria-describedby="{id}-error">
12
+ <p class="wysio-error" id="{id}-error" role="alert" hidden></p>
13
+ <div class="wysio-upload-row">
14
+ <button type="button" class="wysio-button" data-action="upload" data-text="image.upload"></button>
15
+ <input type="file" name="file" hidden>
16
+ </div>
17
+ <label class="wysio-field" for="{id}-alt" data-text="image.alt"></label>
18
+ <input class="wysio-input" id="{id}-alt" name="alt" type="text" aria-describedby="{id}-alt-hint">
19
+ <p class="wysio-hint" id="{id}-alt-hint" data-text="image.altHint"></p>
20
+ <label class="wysio-field" for="{id}-align" data-text="image.align"></label>
21
+ <select class="wysio-input" id="{id}-align" name="align">
22
+ <option value="" data-text="image.alignNone"></option>
23
+ <option value="left" data-text="image.alignLeft"></option>
24
+ <option value="center" data-text="image.alignCenter"></option>
25
+ <option value="right" data-text="image.alignRight"></option>
26
+ </select>
27
+ <div class="wysio-actions">
28
+ <button type="submit" class="wysio-button wysio-button-primary" data-text="dialog.apply"></button>
29
+ <button type="button" class="wysio-button" data-action="remove" data-text="image.remove"></button>
30
+ <button type="button" class="wysio-button" data-action="cancel" data-text="dialog.cancel"></button>
31
+ </div>`);for(let n of t.querySelectorAll(`[data-text]`))n.textContent=e.t(n.dataset.text);this.src=q(t,`input[name=src]`),this.alt=q(t,`input[name=alt]`),this.align=q(t,`select[name=align]`),this.error=q(t,`.wysio-error`),this.file=q(t,`input[name=file]`),this.file.accept=vu(e).types.join(`,`),this.file.multiple=!0,this.uploadRow=q(t,`.wysio-upload-row`),this.removeButton=q(t,`[data-action=remove]`),t.addEventListener(`submit`,e=>{e.preventDefault(),this.apply()}),q(t,`[data-action=cancel]`).addEventListener(`click`,()=>this.close()),this.removeButton.addEventListener(`click`,()=>{this.close(!1),ku(this.editor)}),q(t,`[data-action=upload]`).addEventListener(`click`,()=>this.file.click()),this.file.addEventListener(`change`,()=>{let e=[...this.file.files??[]];this.file.value=``,e.length&&(this.close(!1),this.editor.focus(),wu(this.editor,e,this.pos))}),this.src.addEventListener(`input`,()=>this.setError(!1)),this.dom.appendChild(t)}open(){let{state:e}=this.editor.view,t=Du(e,this.editor.schema.nodes.image);this.pos=e.selection.from,this.original=t?.attrs.src??``,this.src.value=this.original,this.alt.value=t?.attrs.alt??``,this.align.value=t?.attrs.align??``,this.uploadRow.hidden=!this.editor.options.upload||!!t,this.removeButton.hidden=!t,this.setError(!1),this.show(this.pos,this.src),this.src.select()}apply(){let e=this.src.value.trim(),t=vu(this.editor),n=e===this.original||/^data:/i.test(e)||/^[^/:]+\.(png|jpe?g|gif|webp|avif|svg|bmp)$/i.test(e)?uu(e,t):uu(cu(e),t);n?(this.close(!1),Ou(this.editor,{src:n,alt:this.alt.value.trim(),align:hu(this.align.value)})):(this.setError(!0),this.src.focus())}setError(e){this.error.hidden=!e,this.error.textContent=e?this.editor.t(`image.invalid`):``,this.src.setAttribute(`aria-invalid`,String(e))}};function Mu(e={}){let t={allowDataUrls:e.allowDataUrls??!1,types:e.types??fu};return K({name:`image`,schema:{nodes:{image:{inline:!0,group:`inline`,draggable:!0,attrs:{src:{validate:`string`},alt:{default:null,validate:`string|null`},title:{default:null,validate:`string|null`},width:{default:null,validate:`number|null`},height:{default:null,validate:`number|null`},align:{default:null,validate:`string|null`}},parseDOM:[{tag:`img[src]`,getAttrs:e=>{let n=e;return yu({src:n.getAttribute(`src`)??``,alt:n.getAttribute(`alt`),title:n.getAttribute(`title`),width:pu(n.getAttribute(`width`)),height:pu(n.getAttribute(`height`)),align:gu(n)},t)??!1}}],toDOM:e=>{let n={},r=uu(e.attrs.src,t);r&&(n.src=r),typeof e.attrs.alt==`string`&&(n.alt=e.attrs.alt),typeof e.attrs.title==`string`&&(n.title=e.attrs.title);let i=pu(e.attrs.width),a=pu(e.attrs.height);i&&(n.width=String(i)),a&&(n.height=String(a));let o=hu(e.attrs.align);return o&&(n.class=`wysio-image-${o}`),[`img`,n]}}}},prosemirrorPlugins:({editor:e})=>(_u.set(e,t),[Eu(e)]),toolbarItems:({schema:e,editor:t})=>{let n=e.nodes.image;return{image:{label:t.t(`image`),icon:G.image,run:Au,popover:`image`,isActive:e=>!!Du(e,n),isEnabled:e=>!!Du(e,n)||e.selection.$from.parent.inlineContent}}}})}function Nu(e,t){let{from:n,to:r,empty:i,$from:a}=e.selection;if(!i)return{from:n,to:r};let o=ol(a,t);return o?{from:o.from,to:o.to}:null}function Pu(e){return(t,n)=>{let r=Nu(t,e);return!r||!t.doc.rangeHasMark(r.from,r.to,e)?!1:(n&&n(t.tr.removeMark(r.from,r.to,e).scrollIntoView()),!0)}}function Fu(e){let t=e.schema.marks.link;e.isEditable&&t&&vc(e,`link`,()=>new Iu(e,t)).open()}var Iu=class extends gc{type;input;newTab;error;removeButton;range=null;constructor(e,t){super(e,e.t(`link.dialog`)),this.type=t;let n=yc(e.dom.ownerDocument,this.uid,`<label class="wysio-field" for="{id}-url"></label>
32
+ <input class="wysio-input" id="{id}-url" name="href" type="text" inputmode="url" autocomplete="off" spellcheck="false" aria-describedby="{id}-error">
33
+ <p class="wysio-error" id="{id}-error" role="alert" hidden></p>
34
+ <label class="wysio-check"><input type="checkbox" name="newTab"> <span></span></label>
35
+ <div class="wysio-actions">
36
+ <button type="submit" class="wysio-button wysio-button-primary" data-action="apply"></button>
37
+ <button type="button" class="wysio-button" data-action="remove"></button>
38
+ <button type="button" class="wysio-button" data-action="cancel"></button>
39
+ </div>`);q(n,`.wysio-field`).textContent=e.t(`link.url`),q(n,`.wysio-check span`).textContent=e.t(`link.newTab`),q(n,`[data-action=apply]`).textContent=e.t(`dialog.apply`);let r=q(n,`[data-action=cancel]`);r.textContent=e.t(`dialog.cancel`),this.removeButton=q(n,`[data-action=remove]`),this.removeButton.textContent=e.t(`link.remove`),this.input=q(n,`input[name=href]`),this.newTab=q(n,`input[name=newTab]`),this.error=q(n,`.wysio-error`),n.addEventListener(`submit`,e=>{e.preventDefault(),this.apply()}),this.removeButton.addEventListener(`click`,()=>this.remove()),r.addEventListener(`click`,()=>this.close()),this.input.addEventListener(`input`,()=>this.setError(!1)),this.dom.appendChild(n)}open(){let{state:e}=this.editor.view,{from:t,to:n}=e.selection,r=ol(e.selection.$from,this.type);this.range=r&&(e.selection.empty||r.from<=t&&r.to>=n)?{from:r.from,to:r.to}:{from:t,to:n};let i=r?.mark;this.input.value=i?.attrs.href??``,this.newTab.checked=i?.attrs.target===`_blank`,this.removeButton.hidden=!i&&!nl(e,this.type),this.setError(!1),this.show(this.range.from,this.input),this.input.select()}apply(){let e=cu(this.input.value);if(!e){this.setError(!0),this.input.focus();return}let{view:t}=this.editor,n=this.clampRange(),r=this.type.create({href:e,target:this.newTab.checked?`_blank`:null}),i=t.state.tr;n.from===n.to?i.insertText(e,n.from).addMark(n.from,n.from+e.length,r):i.removeMark(n.from,n.to,this.type).addMark(n.from,n.to,r),t.dispatch(i.scrollIntoView()),this.close(!1),this.editor.focus()}remove(){let e=this.clampRange(),{view:t}=this.editor;t.dispatch(t.state.tr.removeMark(e.from,e.to,this.type)),this.close(!1),this.editor.focus()}clampRange(){let e=this.editor.view.state.doc.content.size,t=Math.min(this.range?.from??0,e);return{from:t,to:Math.min(this.range?.to??t,e)}}setError(e){this.error.hidden=!e,this.error.textContent=e?this.editor.t(`link.invalid`):``,this.input.setAttribute(`aria-invalid`,String(e))}},Lu=K({name:`link`,schema:{marks:{link:{attrs:{href:{validate:`string`},target:{default:null,validate:`string|null`}},inclusive:!1,parseDOM:[{tag:`a[href]`,getAttrs:e=>{let t=e,n=su(t.getAttribute(`href`));return n?{href:n,target:t.getAttribute(`target`)===`_blank`?`_blank`:null}:!1}}],toDOM:e=>{let t=su(e.attrs.href),n={};return t&&(n.href=t),e.attrs.target===`_blank`&&(n.target=`_blank`,n.rel=`noopener noreferrer`),[`a`,n,0]}}}},keymap:({editor:e})=>({"Mod-k":(t,n)=>e.isEditable?(n&&Fu(e),!0):!1}),toolbarItems:({schema:e,editor:t})=>{let n=e.marks.link;return{link:{label:t.t(`link`),icon:G.link,shortcut:`Mod-k`,run:Fu,popover:`link`,isActive:e=>nl(e,n),isEnabled:()=>!0},unlink:{label:t.t(`unlink`),icon:G.unlink,command:Pu(n)}}}}),Ru=e=>{let t=Math.trunc(Number(e));return Number.isFinite(t)?t:1},zu=K({name:`lists`,schema:{nodes:{bullet_list:{content:`list_item+`,group:`block`,parseDOM:[{tag:`ul`}],toDOM:()=>[`ul`,0]},ordered_list:{attrs:{start:{default:1,validate:`number`}},content:`list_item+`,group:`block`,parseDOM:[{tag:`ol`,getAttrs:e=>({start:Ru(e.getAttribute(`start`)??1)})}],toDOM:e=>{let t=Ru(e.attrs.start);return t===1?[`ol`,0]:[`ol`,{start:String(t)},0]}},list_item:{content:`paragraph block*`,defining:!0,parseDOM:[{tag:`li`}],toDOM:()=>[`li`,0]}}},keymap:({schema:e})=>{let t=e.nodes.list_item,n=[e.nodes.bullet_list,e.nodes.ordered_list];return{Enter:Zc(t),Tab:tl(t),"Shift-Tab":Qc(t),"Mod-Shift-8":il(n[0],t,n),"Mod-Shift-7":il(n[1],t,n)}},inputRules:({schema:e})=>[jr(/^\s*([-+*])\s$/,e.nodes.bullet_list),jr(/^(\d+)\.\s$/,e.nodes.ordered_list,e=>({start:Ru(e[1])}),(e,t)=>t.childCount+t.attrs.start===Ru(e[1]))],toolbarItems:({schema:e,editor:t})=>{let n=e.nodes.list_item,r=e.nodes.bullet_list,i=e.nodes.ordered_list,a=[r,i],o=e=>t=>rl(t,a)?.node.type===e;return{bulletList:{label:t.t(`bulletList`),icon:G.bulletList,shortcut:`Mod-Shift-8`,command:il(r,n,a),isActive:o(r)},orderedList:{label:t.t(`orderedList`),icon:G.orderedList,shortcut:`Mod-Shift-7`,command:il(i,n,a),isActive:o(i)}}}});function Bu(e,t,n){return K({name:e,schema:{marks:{[e]:t}},keymap:({schema:t})=>({[n]:vr(t.marks[e])}),toolbarItems:({schema:t,editor:r})=>{let i=t.marks[e];return{[e]:{label:r.t(e),icon:G[e],shortcut:n,command:vr(i),isActive:e=>nl(e,i)}}}})}var Vu=(e,t)=>e.includes(t)&&null,Hu=Bu(`bold`,{parseDOM:[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!==`normal`&&null},{style:`font-weight=400`,clearMark:e=>e.type.name===`bold`},{style:`font-weight`,getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:()=>[`strong`,0]},`Mod-b`),Uu=Bu(`italic`,{parseDOM:[{tag:`em`},{tag:`i`},{style:`font-style=italic`},{style:`font-style=normal`,clearMark:e=>e.type.name===`italic`}],toDOM:()=>[`em`,0]},`Mod-i`),Wu=Bu(`underline`,{parseDOM:[{tag:`u`},{style:`text-decoration`,getAttrs:e=>Vu(e,`underline`)},{style:`text-decoration-line`,getAttrs:e=>Vu(e,`underline`)}],toDOM:()=>[`u`,0]},`Mod-u`),Gu=Bu(`strike`,{parseDOM:[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,getAttrs:e=>Vu(e,`line-through`)},{style:`text-decoration-line`,getAttrs:e=>Vu(e,`line-through`)}],toDOM:()=>[`s`,0]},`Mod-Shift-x`),Ku=Bu(`code`,{code:!0,parseDOM:[{tag:`code`}],toDOM:()=>[`code`,0]},`Mod-e`),qu=`script, style, meta, link, title, xml, template, noscript, object, embed, iframe, svg, canvas, video, audio, button, input, select, textarea`,Ju=new Set(`P H1 H2 H3 H4 H5 H6 UL OL LI TABLE DIV BLOCKQUOTE HR PRE FIGURE SECTION ARTICLE HEADER FOOTER`.split(` `)),Yu=new Set([`href`,`target`,`src`,`alt`,`title`,`width`,`height`,`colspan`,`rowspan`,`start`]),Xu=`h1, h2, h3, h4, h5, h6`;function Zu(e){e.replaceWith(...e.childNodes)}function Qu(e,t){if(!t.length)return;let n=e.ownerDocument,r=n.createElement(t[0]),i=r;for(let e of t.slice(1))i=i.appendChild(n.createElement(e));i.append(...e.childNodes),e.appendChild(r)}function $u(e){let t=e.style,n=[],r=t.fontWeight;/^(bold(er)?|[6-9]\d\d)$/.test(r)&&!e.closest(Xu)&&n.push(`strong`),(t.fontStyle===`italic`||t.fontStyle===`oblique`)&&n.push(`em`);let i=`${t.textDecoration} ${t.getPropertyValue(`text-decoration-line`)}`;return i.includes(`underline`)&&!e.closest(`a`)&&n.push(`u`),i.includes(`line-through`)&&n.push(`s`),n}var ed=e=>/mso-list\s*:\s*l\d+/i.test(e.getAttribute(`style`)??``),td=e=>/mso-list\s*:\s*ignore/i.test(e.getAttribute(`style`)??``);function nd(e){let t=null;for(let n of[...e.querySelectorAll(`p`)].filter(ed)){let e=[...n.querySelectorAll(`span`)].find(td),r=(e?.textContent??``).replace(/[\s\u00a0]+/g,``),i=/^\(?(\d+|[a-z]{1,3})[.)]$/i.test(r)?`OL`:`UL`;e?.remove(),t&&t.tagName===i&&n.previousElementSibling===t||(t=n.ownerDocument.createElement(i),n.before(t));let a=n.ownerDocument.createElement(`li`);a.appendChild(n),t.appendChild(a)}}function rd(e){let t=(e,t)=>{for(;e&&e.nodeType===Node.TEXT_NODE&&id(e.textContent);)e=e[t];return e},n=e=>!e||Ju.has(e.tagName);return n(t(e.previousSibling,`previousSibling`))&&n(t(e.nextSibling,`nextSibling`))}var id=e=>!(e??``).replace(/[\s\u00a0\u200b]/g,``);function ad(e,t=document){if(/<[^>]+\sdata-pm-slice=/.test(e))return e;let n=new((t.defaultView?.DOMParser)??DOMParser)().parseFromString(e,`text/html`),r=n.body,i=[],a=n.createTreeWalker(r,NodeFilter.SHOW_COMMENT);for(;a.nextNode();)i.push(a.currentNode);i.forEach(e=>e.parentNode?.removeChild(e)),r.querySelectorAll(qu).forEach(e=>e.remove()),r.querySelectorAll(`br.Apple-interchange-newline`).forEach(e=>e.remove()),nd(r),r.querySelectorAll(`span[style]`).forEach(e=>{if(td(e)){let t=(e.textContent??``).replace(/[\s\u00a0]+/g,` `).trim();e.replaceWith(n.createTextNode(t?`${t} `:``))}}),r.querySelectorAll(`b, strong`).forEach(e=>{(/^(normal|[1-4]00)$/.test(e.style.fontWeight)||e.id.startsWith(`docs-internal-guid`))&&Zu(e)}),r.querySelectorAll(`span`).forEach(e=>{e.textContent&&/^[\s\u00a0]+$/.test(e.textContent)&&!e.children.length&&e.replaceWith(n.createTextNode(` `))}),[...r.querySelectorAll(`span[style], font[style]`)].reverse().forEach(e=>Qu(e,$u(e)));for(let e of[...r.querySelectorAll(`*`)]){if(e.tagName===`IMG`)continue;let t=[...e.classList].filter(e=>e.startsWith(`wysio-`));for(let t of[...e.attributes])Yu.has(t.name.toLowerCase())||e.removeAttribute(t.name);t.length&&e.setAttribute(`class`,t.join(` `))}return[...r.querySelectorAll(`*`)].reverse().forEach(e=>{((e.tagName===`SPAN`||e.tagName===`FONT`)&&!e.hasAttribute(`class`)||e.tagName.includes(`:`))&&Zu(e)}),r.querySelectorAll(`br`).forEach(e=>{rd(e)&&e.remove()}),r.querySelectorAll(`p`).forEach(e=>{id(e.textContent)&&!e.querySelector(`img, br, table, hr`)&&e.remove()}),r.innerHTML}var od=K({name:`paste`,prosemirrorPlugins:({editor:e})=>[new Bn({props:{transformPastedHTML:t=>ad(t,e.dom.ownerDocument)}})]}),sd=K({name:`placeholder`,prosemirrorPlugins:({editor:e})=>[new Bn({props:{decorations:t=>{let n=e.options.placeholder,r=t.doc.firstChild;return!n||!r||!cc(t.doc)?null:H.create(t.doc,[V.node(0,r.nodeSize,{class:`wysio-placeholder`,"data-placeholder":n})])},attributes:()=>{let t=e.options.placeholder;return t?{"aria-placeholder":t}:{}}}})]}),cd=new Set([`UL`,`OL`,`LI`,`BLOCKQUOTE`,`TABLE`,`THEAD`,`TBODY`,`TR`,`TD`,`TH`]),ld=new Set([...cd,`P`,`H1`,`H2`,`H3`,`H4`,`H5`,`H6`,`HR`,`PRE`,`DIV`]),ud=e=>[...e.children].some(e=>ld.has(e.tagName));function dd(e){let t=e.cloneNode(!1).outerHTML,n=t.lastIndexOf(`</`);return n===-1?t:t.slice(0,n)}function fd(e,t=` `,n=document){let r=n.createElement(`div`);r.innerHTML=e;let i=[],a=(e,n)=>{let r=t.repeat(n);if(e.nodeType===Node.TEXT_NODE){(e.textContent??``).trim()&&i.push(r+e.data.trim());return}if(e.nodeType!==Node.ELEMENT_NODE)return;let o=e;cd.has(o.tagName)&&ud(o)?(i.push(r+dd(o)),o.childNodes.forEach(e=>a(e,n+1)),i.push(`${r}</${o.tagName.toLowerCase()}>`)):i.push(r+o.outerHTML)};return r.childNodes.forEach(e=>a(e,0)),i.join(`
40
+ `)}var pd=new Un(`wysio-source`),md=class{editor;textarea;ownDoc=null;applying=!1;constructor(e){this.editor=e;let t=e.dom.ownerDocument;this.textarea=t.createElement(`textarea`),this.textarea.className=`wysio-source`,this.textarea.spellcheck=!1,this.textarea.hidden=!0,this.textarea.setAttribute(`aria-label`,e.t(`source.label`)),this.textarea.setAttribute(`autocapitalize`,`off`),this.textarea.setAttribute(`autocomplete`,`off`),this.textarea.addEventListener(`input`,()=>this.apply()),e.view.dom.parentElement.after(this.textarea)}get body(){return this.editor.view.dom.parentElement}open(){this.ownDoc=this.editor.view.state.doc,this.textarea.value=fd(this.editor.getHTML(),` `,this.editor.dom.ownerDocument),this.textarea.readOnly=!this.editor.isEditable;let e=this.body.offsetHeight;e&&(this.textarea.style.height=`${e}px`),this.body.hidden=!0,this.textarea.hidden=!1,this.editor.setMode(`source`),this.textarea.focus(),this.textarea.setSelectionRange(0,0),this.textarea.scrollTop=0}close(){this.textarea.hidden=!0,this.body.hidden=!1,this.editor.setMode(`wysiwyg`),this.editor.focus()}apply(){let{view:e,schema:t}=this.editor,n=sc(t,this.textarea.value,this.editor.dom.ownerDocument);if(!n.eq(e.state.doc)){this.applying=!0;try{e.dispatch(e.state.tr.replaceWith(0,e.state.doc.content.size,n.content).setMeta(pd,!0))}finally{this.applying=!1}this.ownDoc=e.state.doc}}sync(){if(this.editor.mode!==`source`||this.applying)return;this.textarea.readOnly=!this.editor.isEditable;let{doc:e}=this.editor.view.state;e!==this.ownDoc&&(this.ownDoc=e,this.textarea.value=fd(this.editor.getHTML(),` `,this.editor.dom.ownerDocument))}},hd=new WeakMap;function gd(e){let t=hd.get(e);return t||hd.set(e,t=new md(e)),t}function _d(e){if(!e.hasPlugin(`source`))return;let t=gd(e);e.mode===`source`?t.close():t.open()}var vd=K({name:`source`,prosemirrorPlugins:({editor:e})=>[new Bn({key:pd,view:()=>(hd.get(e)?.sync(),{update:()=>hd.get(e)?.sync()})})],toolbarItems:({editor:e})=>({source:{label:e.t(`source`),icon:G.source,run:_d,isActive:()=>e.mode===`source`,isEnabled:()=>!0,availableInSourceMode:!0}})}),yd,bd;if(typeof WeakMap<`u`){let e=new WeakMap;yd=t=>e.get(t),bd=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;yd=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},bd=(n,r)=>(t==10&&(t=0),e[t++]=n,e[t++]=r)}var X=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,a=r+1,o=i+1;for(let e=1;a<this.width&&this.map[t+e]==n;e++)a++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:a,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:a,bottom:o}=this.findCell(e);return t==`horiz`?(n<0?r==0:i==this.width)?null:this.map[a*this.width+(n<0?r-1:i)]:(n<0?a==0:o==this.height)?null:this.map[r+this.width*(n<0?a-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:a}=this.findCell(e),{left:o,right:s,top:c,bottom:l}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,c),right:Math.max(r,s),bottom:Math.max(a,l)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let a=r*this.width+i,o=this.map[a];n[o]||(n[o]=!0,i==e.left&&i&&this.map[a-1]==o||r==e.top&&r&&this.map[a-this.width]==o||t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let a=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?a-1:this.map[n]}i=a}}static get(e){return yd(e)||bd(e,xd(e))}};function xd(e){if(e.type.spec.tableRole!=`table`)throw RangeError(`Not a table node: `+e.type.name);let t=Sd(e),n=e.childCount,r=[],i=0,a=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let s=0,c=0;s<n;s++){let l=e.child(s);c++;for(let e=0;;e++){for(;i<r.length&&r[i]!=0;)i++;if(e==l.childCount)break;let u=l.child(e),{colspan:d,rowspan:f,colwidth:p}=u.attrs;for(let e=0;e<f;e++){if(e+s>=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;e<d;e++){r[l+e]==0?r[l+e]=c:(a||=[]).push({type:`collision`,row:s,pos:c,n:d-e});let n=p&&p[e];if(n){let r=(l+e)%t*2,i=o[r];i==null||i!=n&&o[r+1]==1?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=d,c+=u.nodeSize}let u=(s+1)*t,d=0;for(;i<u;)r[i++]==0&&d++;d&&(a||=[]).push({type:`missing`,row:s,n:d}),c++}(t===0||n===0)&&(a||=[]).push({type:`zero_sized`});let s=new X(t,n,r,a),c=!1;for(let e=0;!c&&e<o.length;e+=2)o[e]!=null&&o[e+1]<n&&(c=!0);return c&&Cd(s,o,e),s}function Sd(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),a=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(a+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);a+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function Cd(e,t,n){e.problems||=[];let r={};for(let i=0;i<e.map.length;i++){let a=e.map[i];if(r[a])continue;r[a]=!0;let o=n.nodeAt(a);if(!o)throw RangeError(`No cell with offset ${a} found`);let s=null,c=o.attrs;for(let n=0;n<c.colspan;n++){let r=t[(i+n)%e.width*2];r==null||c.colwidth&&c.colwidth[n]==r||((s||=wd(c))[n]=r)}s&&e.problems.unshift({type:`colwidth mismatch`,pos:a,colwidth:s})}}function wd(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function Z(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(let n in e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}}return t}var Td=new Un(`selectingCells`);function Ed(e){for(let t=e.depth-1;t>0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function Q(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function Dd(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=Ed(t.$head)||Od(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function Od(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function kd(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function Ad(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function jd(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function Md(e,t,n){let r=e.node(-1),i=X.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function Nd(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function Pd(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}function Fd(e,t,n){let r=Z(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0}var $=class e extends w{constructor(e,t=e){let n=e.node(-1),r=X.get(n),i=e.start(-1),a=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),s=r.cellsInRect(a).filter(e=>e!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new xn(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(kd(r)&&kd(i)&&jd(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return T.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=X.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n<r.bottom;n++){let s=[];for(let a=n*t.width+r.left,o=r.left;o<r.right;o++,a++){let n=t.map[a];if(i[n])continue;i[n]=!0;let o=t.findCell(n),c=e.nodeAt(n);if(!c)throw RangeError(`No cell with offset ${n} found`);let l=r.left-o.left,u=o.right-r.right;if(l>0||u>0){let e=c.attrs;if(l>0&&(e=Nd(e,0,l)),u>0&&(e=Nd(e,e.colspan-u,u)),o.left<r.left){if(c=c.type.createAndFill(e),!c)throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else c=c.type.create(e,c.content)}if(o.top<r.top||o.bottom>r.bottom){let e={...c.attrs,rowspan:Math.min(o.bottom,r.bottom)-Math.max(o.top,r.top)};c=o.top<r.top?c.type.createAndFill(e):c.type.create(e,c.content)}s.push(c)}a.push(e.child(n).copy(o.from(s)))}let s=this.isColSelection()&&this.isRowSelection()?e:a;return new f(o.from(s),1,1)}replace(e,t=f.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n);e.replace(s.map(a.pos),s.map(o.pos),i?f.empty:t)}let i=w.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new f(o.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=X.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=X.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom<i.height&&(n=c.resolve(a+i.map[i.width*(i.height-1)+s.right-1]))):(s.top>0&&(n=c.resolve(a+i.map[s.left])),o.bottom<i.height&&(t=c.resolve(a+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=X.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);if(Math.min(r,i)>0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=X.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right<i.width&&(n=c.resolve(a+i.map[i.width*(s.top+1)-1]))):(s.left>0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right<i.width&&(t=c.resolve(a+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:`cell`,anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new Id(this.$anchorCell.pos,this.$headCell.pos)}};$.prototype.visible=!1,w.jsonID(`cell`,$);var Id=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){let t=e.resolve(this.anchor),n=e.resolve(this.head);return t.parent.type.spec.tableRole==`row`&&n.parent.type.spec.tableRole==`row`&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&jd(t,n)?new $(t,n):w.near(n,1)}};function Ld(e){if(!(e.selection instanceof $))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(V.node(n,n+e.nodeSize,{class:`selectedCell`}))}),H.create(e.doc,t)}function Rd({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,r=t.pos,i=e.depth;for(;i>=0&&!(e.after(i+1)<e.end(i));i--,n++);for(let e=t.depth;e>=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function zd({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function Bd(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof E&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=$.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=$.rowSelection(e,e)}else if(!n){let e=X.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=$.create(i,t+1,n)}}else r instanceof T&&Rd(r)?a=T.create(i,r.from):r instanceof T&&zd(r)&&(a=T.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var Vd=new Un(`fix-tables`);function Hd(e,t,n,r){let i=e.childCount,a=t.childCount;e:for(let o=0,s=0;o<a;o++){let a=t.child(o);for(let t=s,r=Math.min(i,o+3);t<r;t++)if(e.child(t)==a){s=t+1,n+=a.nodeSize;continue e}r(a,n),s<i&&e.child(s).sameMarkup(a)?Hd(e.child(s),a,n+1,r):a.nodesBetween(0,a.content.size,r,n+1),n+=a.nodeSize}}function Ud(e,t){let n,r=(t,r)=>{t.type.spec.tableRole==`table`&&(n=Wd(e,t,r,n))};return t?t.doc!=e.doc&&Hd(t.doc,e.doc,0,r):e.doc.descendants(r),n}function Wd(e,t,n,r){let i=X.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e<i.height;e++)a.push(0);for(let e=0;e<i.problems.length;e++){let o=i.problems[e];if(o.type==`collision`){let e=t.nodeAt(o.pos);if(!e)continue;let i=e.attrs;for(let e=0;e<i.rowspan;e++)a[o.row+e]+=o.n;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,Nd(i,i.colspan-o.n,o.n))}else if(o.type==`missing`)a[o.row]+=o.n;else if(o.type==`overlong_rowspan`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-o.n})}else if(o.type==`colwidth mismatch`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,colwidth:o.colwidth})}else if(o.type==`zero_sized`){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}let o,s;for(let e=0;e<a.length;e++)a[e]&&(o??=e,s=e);for(let c=0,l=n+1;c<i.height;c++){let n=t.child(c),i=l+n.nodeSize,u=a[c];if(u>0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<u;n++){let n=Z(e.schema)[t].createAndFill();n&&a.push(n)}let d=(c==0||o==c-1)&&s==c?l+1:i-1;r.insert(r.mapping.map(d),a)}l=i}return r.setMeta(Vd,{fixTables:!0})}function Gd(e){let t=e.selection,n=Dd(e),r=n.node(-1),i=n.start(-1),a=X.get(r);return{...t instanceof $?a.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):a.findCell(n.pos-i),tableStart:i,map:a,table:r}}function Kd(e,{map:t,tableStart:n,table:r},i){let a=i>0?-1:0;Fd(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o<t.height;o++){let s=o*t.width+i;if(i>0&&i<t.width&&t.map[s-1]==t.map[s]){let a=t.map[s],c=r.nodeAt(a);e.setNodeMarkup(e.mapping.map(n+a),null,Pd(c.attrs,i-t.colCount(a))),o+=c.attrs.rowspan-1}else{let c=a==null?Z(r.type.schema).cell:r.nodeAt(t.map[s+a]).type,l=t.positionAt(o,i,r);e.insert(e.mapping.map(n+l),c.createAndFill())}}return e}function qd(e,t){if(!Q(e))return!1;if(t){let n=Gd(e);t(Kd(e.tr,n,n.left))}return!0}function Jd(e,t){if(!Q(e))return!1;if(t){let n=Gd(e);t(Kd(e.tr,n,n.right))}return!0}function Yd(e,{map:t,table:n,tableStart:r},i){let a=e.mapping.maps.length;for(let o=0;o<t.height;){let s=o*t.width+i,c=t.map[s],l=n.nodeAt(c),u=l.attrs;if(i>0&&t.map[s-1]==c||i<t.width-1&&t.map[s+1]==c)e.setNodeMarkup(e.mapping.slice(a).map(r+c),null,Nd(u,i-t.colCount(c)));else{let t=e.mapping.slice(a).map(r+c);e.delete(t,t+l.nodeSize)}o+=u.rowspan}}function Xd(e,t){if(!Q(e))return!1;if(t){let n=Gd(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let e=n.right-1;Yd(r,n,e),e!=n.left;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=X.get(e)}t(r)}return!0}function Zd(e,t,n){let r=Z(t.type.schema).header_cell;for(let i=0;i<e.width;i++)if(t.nodeAt(e.map[i+n*e.width])?.type!=r)return!1;return!0}function Qd(e,{map:t,tableStart:n,table:r},i){let a=n;for(let e=0;e<i;e++)a+=r.child(e).nodeSize;let o=[],s=i>0?-1:0;Zd(t,r,i+s)&&(s=i==0||i==t.height?null:0);for(let a=0,c=t.width*i;a<t.width;a++,c++)if(i>0&&i<t.height&&t.map[c]==t.map[c-t.width]){let i=t.map[c],o=r.nodeAt(i).attrs;e.setNodeMarkup(n+i,null,{...o,rowspan:o.rowspan+1}),a+=o.colspan-1}else{let e=(s==null?Z(r.type.schema).cell:r.nodeAt(t.map[c+s*t.width])?.type)?.createAndFill();e&&o.push(e)}return e.insert(a,Z(r.type.schema).row.create(null,o)),e}function $d(e,t){if(!Q(e))return!1;if(t){let n=Gd(e);t(Qd(e.tr,n,n.top))}return!0}function ef(e,t){if(!Q(e))return!1;if(t){let n=Gd(e);t(Qd(e.tr,n,n.bottom))}return!0}function tf(e,{map:t,table:n,tableStart:r},i){let a=0;for(let e=0;e<i;e++)a+=n.child(e).nodeSize;let o=a+n.child(i).nodeSize,s=e.mapping.maps.length;e.delete(a+r,o+r);let c=new Set;for(let a=0,o=i*t.width;a<t.width;a++,o++){let l=t.map[o];if(!c.has(l)){if(c.add(l),i>0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i<t.height&&l==t.map[o+t.width]){let o=n.nodeAt(l),c=o.attrs,u=o.type.create({...c,rowspan:o.attrs.rowspan-1},o.content),d=t.positionAt(i+1,a,n);e.insert(e.mapping.slice(s).map(r+d),u),a+=c.colspan-1}}}}function nf(e,t){if(!Q(e))return!1;if(t){let n=Gd(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;tf(r,n,e),e!=n.top;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=X.get(n.table)}t(r)}return!0}function rf(e){return function(t,n){if(!Q(t))return!1;if(n){let r=Z(t.schema),i=Gd(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)s[e].type==r.header_cell&&a.setNodeMarkup(i.tableStart+o[e],r.cell,s[e].attrs);if(a.steps.length===0)for(let e=0;e<o.length;e++)a.setNodeMarkup(i.tableStart+o[e],r.header_cell,s[e].attrs);n(a)}return!0}}function af(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:e==`row`?t.map.width:1,bottom:e==`column`?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function of(e,t){return t||={useDeprecatedLogic:!1},t.useDeprecatedLogic?rf(e):function(t,n){if(!Q(t))return!1;if(n){let r=Z(t.schema),i=Gd(t),a=t.tr,o=af(`row`,i,r),s=af(`column`,i,r),c=(e===`column`?o:e===`row`&&s)?1:0,l=e==`column`?{left:0,top:c,right:1,bottom:i.map.height}:e==`row`?{left:c,top:0,right:i.map.width,bottom:1}:i,u=e==`column`?s?r.cell:r.header_cell:e==`row`?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(l).forEach(e=>{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}of(`row`,{useDeprecatedLogic:!0}),of(`column`,{useDeprecatedLogic:!0}),of(`cell`,{useDeprecatedLogic:!0});function sf(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}function cf(e){return function(t,n){if(!Q(t))return!1;let r=sf(Dd(t),e);if(r==null)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(T.between(e,Ad(e))).scrollIntoView())}return!0}}function lf(e,t){let n=e.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function uf(e,t){let n=e.selection;if(!(n instanceof $))return!1;if(t){let r=e.tr,i=Z(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new f(i,0,0))}),r.docChanged&&t(r)}return!0}function df(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,a=e?0:Math.max(0,n-1),c=e<t.childCount-1?0:Math.max(0,r-1);(a||c)&&(i=pf(Z(o).row,new f(i,a,c)).content),s.push(i)}else if(a==`cell`||a==`header_cell`)s.push(n||r?pf(Z(o).row,new f(t,n,r)).content:t);else return null;return ff(o,s)}function ff(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+a}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(o.empty),n[i]<r){let a=Z(e).cell.createAndFill(),s=[];for(let e=n[i];e<r;e++)s.push(a);t[i]=t[i].append(o.from(s))}return{height:t.length,width:r,rows:t}}function pf(e,t){let n=e.createAndFill();return new yn(n).replace(0,n.content.size,t).doc}function mf({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let a=n[e],s=[];for(let n=t[e]||0,i=0;n<r;i++){let o=a.child(i%a.childCount);n+o.attrs.colspan>r&&(o=o.type.createChecked(Nd(o.attrs,o.attrs.colspan,n+o.attrs.colspan-r),o.content)),s.push(o),n+=o.attrs.colspan;for(let n=1;n<o.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+o.attrs.colspan}i.push(o.from(s))}n=i,e=r}if(t!=i){let e=[];for(let r=0,a=0;r<i;r++,a++){let s=[],c=n[a%t];for(let e=0;e<c.childCount;e++){let t=c.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),s.push(t)}e.push(o.from(s))}n=e,t=i}return{width:e,height:t,rows:n}}function hf(e,t,n,r,i,a,s){let c=Z(e.doc.type.schema),l,u;if(i>t.width)for(let a=0,o=0;a<t.height;a++){let d=n.child(a);o+=d.nodeSize;let f=[],p;p=d.lastChild==null||d.lastChild.type==c.cell?l||=c.cell.createAndFill():u||=c.header_cell.createAndFill();for(let e=t.width;e<i;e++)f.push(p);e.insert(e.mapping.slice(s).map(o-1+r),f)}if(a>t.height){let d=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=e>=t.width?!1:n.nodeAt(t.map[r+e]).type==c.header_cell;d.push(i?u||=c.header_cell.createAndFill():l||=c.cell.createAndFill())}let f=c.row.create(null,o.from(d)),p=[];for(let e=t.height;e<a;e++)p.push(f);e.insert(e.mapping.slice(s).map(r+n.nodeSize-2),p)}return!!(l||u)}function gf(e,t,n,r,i,a,o,s){if(o==0||o==t.height)return!1;let c=!1;for(let l=i;l<a;l++){let i=o*t.width+l,a=t.map[i];if(t.map[i-t.width]==a){c=!0;let i=n.nodeAt(a),{top:u,left:d}=t.findCell(a);e.setNodeMarkup(e.mapping.slice(s).map(a+r),null,{...i.attrs,rowspan:o-u}),e.insert(e.mapping.slice(s).map(t.positionAt(o,d,n)),i.type.createAndFill({...i.attrs,rowspan:u+i.attrs.rowspan-o})),l+=i.attrs.colspan-1}}return c}function _f(e,t,n,r,i,a,o,s){if(o==0||o==t.width)return!1;let c=!1;for(let l=i;l<a;l++){let i=l*t.width+o,a=t.map[i];if(t.map[i-1]==a){c=!0;let i=n.nodeAt(a),u=t.colCount(a),d=e.mapping.slice(s).map(a+r);e.setNodeMarkup(d,null,Nd(i.attrs,o-u,i.attrs.colspan-(o-u))),e.insert(d+i.nodeSize,i.type.createAndFill(Nd(i.attrs,0,o-u))),l+=i.attrs.rowspan-1}}return c}function vf(e,t,n,r,i){let a=n?e.doc.nodeAt(n-1):e.doc;if(!a)throw Error(`No table found`);let o=X.get(a),{top:s,left:c}=r,l=c+i.width,u=s+i.height,d=e.tr,p=0;function m(){if(a=n?d.doc.nodeAt(n-1):d.doc,!a)throw Error(`No table found`);o=X.get(a),p=d.mapping.maps.length}hf(d,o,a,n,l,u,p)&&m(),gf(d,o,a,n,c,l,s,p)&&m(),gf(d,o,a,n,c,l,u,p)&&m(),_f(d,o,a,n,s,u,c,p)&&m(),_f(d,o,a,n,s,u,l,p)&&m();for(let e=s;e<u;e++){let t=o.positionAt(e,c,a),r=o.positionAt(e,l,a);d.replace(d.mapping.slice(p).map(t+n),d.mapping.slice(p).map(r+n),new f(i.rows[e-s],0,0))}m(),d.setSelection(new $(d.doc.resolve(n+o.positionAt(s,c,a)),d.doc.resolve(n+o.positionAt(u-1,l-1,a)))),t(d)}var yf=Gr({ArrowLeft:xf(`horiz`,-1),ArrowRight:xf(`horiz`,1),ArrowUp:xf(`vert`,-1),ArrowDown:xf(`vert`,1),"Shift-ArrowLeft":Sf(`horiz`,-1),"Shift-ArrowRight":Sf(`horiz`,1),"Shift-ArrowUp":Sf(`vert`,-1),"Shift-ArrowDown":Sf(`vert`,1),Backspace:uf,"Mod-Backspace":uf,Delete:uf,"Mod-Delete":uf});function bf(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function xf(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection;if(a instanceof $)return bf(n,r,w.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=Ef(i,e,t);if(o==null)return!1;if(e==`horiz`)return bf(n,r,w.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=Md(i,e,t),s;return s=a?w.near(a,1):t<0?w.near(n.doc.resolve(i.before(-1)),-1):w.near(n.doc.resolve(i.after(-1)),1),bf(n,r,s)}}}function Sf(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof $)o=a;else{let r=Ef(i,e,t);if(r==null)return!1;o=new $(n.doc.resolve(r))}let s=Md(o.$headCell,e,t);return s?bf(n,r,new $(o.$anchorCell,s)):!1}}function Cf(e,t){let n=Ed(e.state.doc.resolve(t));return n?(e.dispatch(e.state.tr.setSelection(new $(n))),!0):!1}function wf(e,t,n){if(!Q(e.state))return!1;let r=df(n),i=e.state.selection;if(i instanceof $){r||={width:1,height:1,rows:[o.from(pf(Z(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),s=X.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=mf(r,s.right-s.left,s.bottom-s.top),vf(e.state,e.dispatch,a,s,r),!0}if(r){let t=Dd(e.state),n=t.start(-1);return vf(e.state,e.dispatch,n,X.get(t.node(-1)).findCell(t.pos-n),r),!0}return!1}function Tf(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=Df(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof $)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=Ed(e.state.selection.$anchor))!=null&&Of(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=Of(e,n),i=Td.getState(e.state)==null;if(!r||!jd(t,r)){if(i)r=t;else return}let a=new $(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(Td,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),Td.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(Td,-1))}function o(r){let o=r,s=Td.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(Df(e,o.target)!=n&&(c=Of(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function Ef(e,t,n){if(!(e.state.selection instanceof T))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function Df(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function Of(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&Ed(e.state.doc.resolve(r))||Ed(e.state.doc.resolve(i))}new Un(`tableColumnResizing`);function kf({allowTableNodeSelection:e=!1}={}){return new Bn({key:Td,state:{init(){return null},apply(e,t){let n=e.getMeta(Td);if(n!=null)return n==-1?null:n;if(t==null||!e.docChanged)return t;let{deleted:r,pos:i}=e.mapping.mapResult(t);return r?null:i}},props:{decorations:Ld,handleDOMEvents:{mousedown:Tf},createSelectionBetween(e){return Td.getState(e.state)==null?null:e.state.selection},handleTripleClick:Cf,handleKeyDown:yf,handlePaste:wf},appendTransaction(t,n,r){return Bd(r,Ud(r,n),e)}})}var Af=10,jf=50,Mf=e=>{let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=jf?t:1},Nf={colspan:{default:1,validate:`number`},rowspan:{default:1,validate:`number`},colwidth:{default:null}};function Pf(e,t){return{content:`block+`,attrs:Nf,tableRole:t,isolating:!0,parseDOM:[{tag:e,getAttrs:e=>{let t=e;return{colspan:Mf(t.getAttribute(`colspan`)??1),rowspan:Mf(t.getAttribute(`rowspan`)??1)}}}],toDOM:t=>{let n={},r=Mf(t.attrs.colspan),i=Mf(t.attrs.rowspan);return r!==1&&(n.colspan=String(r)),i!==1&&(n.rowspan=String(i)),[e,n,0]}}}function Ff(e,t,n,r=!0){let{table:i,table_row:a,table_cell:o,table_header:s}=e.nodes;if(!i||!a||!o||!s)throw Error(`[wysio] The table plugin is not enabled.`);let c=e=>Math.min(10,Math.max(1,Math.trunc(e)||1));return i.create(null,Array.from({length:c(t)},(e,t)=>a.create(null,Array.from({length:c(n)},()=>(r&&t===0?s:o).createAndFill()))))}function If(e,t,n=!0){return(r,i)=>{if(!r.schema.nodes.table||Q(r))return!1;let a=Ff(r.schema,e,t,n),{$from:o}=r.selection,s=!1;for(let e=o.depth;e>=0&&!s;e--){let t=o.index(e);s=o.node(e).canReplaceWith(t,t,a.type)}if(!s)return!1;if(i){let e=r.tr.replaceSelectionWith(a),t=-1;e.doc.descendants((e,n)=>(e===a&&(t=n),t===-1)),t!==-1&&e.setSelection(T.near(e.doc.resolve(t+4))),i(e.scrollIntoView())}return!0}}var Lf=(e,t)=>{let{table:n,table_cell:r,table_header:i}=e.schema.nodes,a=n&&r&&i?rl(e,[n]):null,o=a?.node.firstChild;if(!a||!o||!r||!i)return!1;if(t){let n=o.content.content.some(e=>e.type!==i),s=e.tr;o.forEach((e,t)=>{s.setNodeMarkup(a.pos+2+t,n?i:r,e.attrs)}),t(s)}return!0},Rf=(e,t,n)=>Q(e)?cf(1)(e,t,n)?!0:!t||!n?ef(e):(ef(e,t),cf(1)(n.state,t,n)):!1;function zf(e){return[{name:`tableAddRowBefore`,label:`table.addRowBefore`,command:$d,icon:G.tableRowBefore},{name:`tableAddRowAfter`,label:`table.addRowAfter`,command:ef,icon:G.tableRowAfter},{name:`tableAddColumnBefore`,label:`table.addColumnBefore`,command:qd,icon:G.tableColumnBefore},{name:`tableAddColumnAfter`,label:`table.addColumnAfter`,command:Jd,icon:G.tableColumnAfter},{name:`tableDeleteRow`,label:`table.deleteRow`,command:nf,icon:G.tableDeleteRow},{name:`tableDeleteColumn`,label:`table.deleteColumn`,command:Xd,icon:G.tableDeleteColumn},{name:`tableToggleHeaderRow`,label:`table.toggleHeaderRow`,command:Lf,icon:G.tableHeaderRow},{name:`tableDelete`,label:`table.delete`,command:lf,icon:G.tableDelete}].map(t=>({...t,label:e.t(t.label)}))}function Bf(e){e.isEditable&&e.schema.nodes.table&&vc(e,`table`,()=>new Vf(e)).open()}var Vf=class extends gc{picker;actions;cells=[];size;header;actionButtons=[];constructor(e){super(e,e.t(`table`));let t=e.dom.ownerDocument;this.dom.classList.add(`wysio-popover-table`);let n=yc(t,this.uid,`<div class="wysio-table-picker">
41
+ <div class="wysio-table-grid" role="group"></div>
42
+ <p class="wysio-table-size" aria-live="polite"></p>
43
+ <label class="wysio-check"><input type="checkbox" name="header" checked> <span></span></label>
44
+ </div>
45
+ <div class="wysio-table-actions"></div>`);this.picker=q(n,`.wysio-table-picker`),this.actions=q(n,`.wysio-table-actions`),this.size=q(n,`.wysio-table-size`),this.header=q(n,`input[name=header]`),q(n,`.wysio-check span`).textContent=e.t(`table.header`);let r=q(n,`.wysio-table-grid`);r.setAttribute(`aria-label`,e.t(`table.size`));for(let e=1;e<=10;e++)for(let n=1;n<=10;n++){let i=t.createElement(`button`);i.type=`button`,i.className=`wysio-table-cell`,i.tabIndex=-1,i.dataset.rows=String(e),i.dataset.cols=String(n),i.setAttribute(`aria-label`,this.sizeLabel(e,n)),i.addEventListener(`mouseenter`,()=>this.highlight(e,n)),i.addEventListener(`focus`,()=>this.highlight(e,n)),i.addEventListener(`click`,()=>this.insert(e,n)),r.appendChild(i),this.cells.push(i)}r.addEventListener(`keydown`,this.onGridKey);for(let n of zf(e)){let e=t.createElement(`button`);e.type=`button`,e.className=`wysio-menu-item`,e.dataset.action=n.name,e.innerHTML=n.icon,e.append(t.createTextNode(n.label)),e.addEventListener(`click`,()=>{this.close(!1),this.editor.exec(n.command)}),this.actions.appendChild(e),this.actionButtons.push({button:e,action:n})}this.actions.addEventListener(`keydown`,this.onActionsKey),this.dom.appendChild(n)}open(){let{state:e}=this.editor.view,t=Q(e);if(this.picker.hidden=t,this.actions.hidden=!t,this.dom.setAttribute(`aria-label`,this.editor.t(t?`table`:`table.insert`)),t){for(let{button:t,action:n}of this.actionButtons)t.disabled=!n.command(e);let t=this.actionButtons.find(e=>!e.button.disabled)?.button;this.show(e.selection.from,t??this.actions)}else this.highlight(1,1),this.show(e.selection.from,this.cell(1,1))}sizeLabel(e,t){return this.editor.t(`table.cells`,{rows:e,cols:t})}cell(e,t){return this.cells[(e-1)*10+(t-1)]}highlight(e,t){for(let n of this.cells){let r=Number(n.dataset.rows)<=e&&Number(n.dataset.cols)<=t;n.classList.toggle(`wysio-active`,r),n.tabIndex=Number(n.dataset.rows)===e&&Number(n.dataset.cols)===t?0:-1}this.size.textContent=this.sizeLabel(e,t)}insert(e,t){this.close(!1),this.editor.exec(If(e,t,this.header.checked))}onGridKey=e=>{let t=e.target,n=Number(t.dataset.rows),r=Number(t.dataset.cols);if(n&&r){if(e.key===`ArrowRight`)r++;else if(e.key===`ArrowLeft`)r--;else if(e.key===`ArrowDown`)n++;else if(e.key===`ArrowUp`)n--;else if(e.key===`Home`)r=1;else if(e.key===`End`)r=10;else return;e.preventDefault(),n=Math.min(10,Math.max(1,n)),r=Math.min(10,Math.max(1,r)),this.cell(n,r)?.focus()}};onActionsKey=e=>{let t=this.actionButtons.map(e=>e.button).filter(e=>!e.disabled),n=t.indexOf(e.target),r=null;e.key===`ArrowDown`?r=(n+1)%t.length:e.key===`ArrowUp`?r=(n-1+t.length)%t.length:e.key===`Home`?r=0:e.key===`End`&&(r=t.length-1),r!==null&&(e.preventDefault(),t[r]?.focus())}},Hf=e=>t=>Q(t)&&e(t),Uf=K({name:`table`,schema:{nodes:{table:{content:`table_row+`,tableRole:`table`,isolating:!0,group:`block`,parseDOM:[{tag:`table`}],toDOM:()=>[`table`,[`tbody`,0]]},table_row:{content:`(table_cell | table_header)*`,tableRole:`row`,parseDOM:[{tag:`tr`}],toDOM:()=>[`tr`,0]},table_cell:Pf(`td`,`cell`),table_header:Pf(`th`,`header_cell`)}},keymap:()=>({Tab:Rf,"Shift-Tab":cf(-1)}),prosemirrorPlugins:()=>[kf()],toolbarItems:({editor:e})=>{let t={table:{label:e.t(`table`),icon:G.table,run:Bf,popover:`table`,isActive:e=>Q(e),isEnabled:e=>Q(e)||If(1,1)(e)}};for(let n of zf(e))t[n.name]={label:n.label,icon:n.icon,command:n.command,isEnabled:Hf(n.command)};return t}}),Wf=[Kc,jl,sl,zu,cl,Uf,ll,Mu(),Lu,Hu,Uu,Wu,Gu,Ku,Dl(),Ol(),Nc,pl,od,vd,ru,sd],Gf=new Map;function Kf(e){return e.flatMap(e=>{if(typeof e!=`string`)return[e];let t=Gf.get(e);return t?[t()]:(console.warn(`[wysio] Unknown plugin "${e}". Register it with registerPlugin() (wysio/markdown registers "markdown").`),[])})}function qf(e){let t={},n={};for(let r of e){for(let[e,n]of Object.entries(r.schema?.nodes??{})){if(e in t)throw Error(`[wysio] Node "${e}" is defined twice (plugin "${r.name}").`);t[e]=n}for(let[e,t]of Object.entries(r.schema?.marks??{})){if(e in n)throw Error(`[wysio] Mark "${e}" is defined twice (plugin "${r.name}").`);n[e]=t}}for(let n of e)for(let[e,r]of Object.entries(n.schema?.extendNodes??{})){let n=t[e];n&&(t[e]=r(n))}return new Ie({nodes:t,marks:n})}var Jf=()=>typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform);function Yf(e){let t=Jf();return e.split(`-`).map(e=>{switch(e){case`Mod`:return t?`⌘`:`Ctrl`;case`Shift`:return t?`⇧`:`Shift`;case`Alt`:return t?`⌥`:`Alt`;case`Ctrl`:return t?`⌃`:`Ctrl`;default:return e.length===1?e.toUpperCase():e}}).join(t?``:`+`)}function Xf(e,t){let n=0;for(;n<e.length&&e[n]<=t;)n++;return n}var Zf=`<svg class="wysio-caret" viewBox="0 0 10 10" width="8" height="8" aria-hidden="true" focusable="false"><path d="m2 3.5 3 3 3-3" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,Qf=0,$f=class{editor;dom;controls=[];entries=[];more=null;panel=null;observer=null;constructor(e,t,n,{warnUnknown:r=!0,mode:i=`overflow`}={}){this.editor=e;let a=e.dom.ownerDocument;this.dom=a.createElement(`div`),this.dom.className=`wysio-toolbar`,this.dom.dataset.mode=i,this.dom.setAttribute(`role`,`toolbar`),e.locale&&(this.dom.lang=e.locale),this.dom.setAttribute(`aria-label`,e.t(`toolbar`)),this.dom.setAttribute(`aria-controls`,e.view.dom.id);let o=!0;for(let e of t){if(e===`|`){if(o)continue;let e=a.createElement(`span`);e.className=`wysio-separator`,e.setAttribute(`role`,`separator`),e.setAttribute(`aria-orientation`,`vertical`),this.entries.push(e),o=!0;continue}let t=n.get(e);if(!t){r&&console.warn(`[wysio] Unknown toolbar item "${e}".`);continue}let i=t.type===`select`?this.createSelect(e,t):this.createButton(e,t);this.controls.push(i),this.entries.push(i.el),o=!1}this.entries.at(-1)?.classList.contains(`wysio-separator`)&&this.entries.pop(),this.dom.append(...this.entries),i===`overflow`&&this.setUpOverflow(),this.dom.addEventListener(`keydown`,this.onKeyDown),this.dom.addEventListener(`focusin`,this.onFocusIn),e.dom.addEventListener(`wysio:popover`,this.onPopover),this.controls[0]?.el.setAttribute(`tabindex`,`0`)}label(e,t){return t.labelKey?this.editor.t(t.labelKey):t.label??e}createButton(e,t){let n=this.editor.dom.ownerDocument,r=n.createElement(`button`),i=this.label(e,t);r.type=`button`,r.className=`wysio-tool`,r.dataset.item=e,r.tabIndex=-1;let a=n.createElement(`span`);return a.className=`wysio-icon`,a.innerHTML=t.icon,r.appendChild(a),t.dropdown&&r.insertAdjacentHTML(`beforeend`,Zf),r.setAttribute(`aria-label`,i),r.title=t.shortcut?`${i} (${Yf(t.shortcut)})`:i,t.isActive&&r.setAttribute(`aria-pressed`,`false`),t.popover&&(r.setAttribute(`aria-haspopup`,`dialog`),r.setAttribute(`aria-expanded`,`false`)),r.addEventListener(`mousedown`,e=>e.preventDefault()),r.addEventListener(`click`,()=>{r.getAttribute(`aria-disabled`)!==`true`&&(t.run?t.run(this.editor):t.command&&this.editor.exec(t.command))}),{kind:`button`,item:t,el:r,icon:a}}createSelect(e,t){let n=this.editor.dom.ownerDocument,r=n.createElement(`select`),i=this.label(e,t);r.className=`wysio-select`,r.dataset.item=e,r.tabIndex=-1,r.setAttribute(`aria-label`,i),r.title=i;let a=n.createElement(`option`);a.value=``,a.hidden=!0,a.textContent=`—`,r.appendChild(a);for(let e of t.options){let t=n.createElement(`option`);t.value=e.value,t.textContent=e.label,r.appendChild(t)}return r.addEventListener(`change`,()=>{r.value&&t.onSelect(this.editor,r.value)}),{kind:`select`,item:t,el:r}}update(e){let t=this.editor.isEditable,n=this.editor.mode===`wysiwyg`;for(let r of this.controls){let{item:i,el:a}=r,o=i.availableInSourceMode||t&&n;if(o&&(i.isEnabled?o=i.isEnabled(e,this.editor):r.kind===`button`&&r.item.command&&(o=r.item.command(e))),r.kind===`select`){r.el.disabled=!o,r.el.value=r.item.getValue(e);continue}if(a.setAttribute(`aria-disabled`,String(!o)),r.item.isActive){let t=(n||!!i.availableInSourceMode)&&r.item.isActive(e);a.setAttribute(`aria-pressed`,String(t))}let{icon:s}=r;r.item.render?.(e,{el:r.el,setIcon:e=>{s.innerHTML!==e&&(s.innerHTML=e)}})}}focus(){let e=this.focusable();(e.find(e=>e.tabIndex===0)??e[0])?.focus()}destroy(){this.observer?.disconnect(),this.closePanel(!1),this.editor.dom.removeEventListener(`wysio:popover`,this.onPopover),this.dom.remove()}setUpOverflow(){let e=this.editor.dom.ownerDocument,t=`wysio-toolbar-more-${++Qf}`;this.more=e.createElement(`button`),this.more.type=`button`,this.more.className=`wysio-tool wysio-more`,this.more.tabIndex=-1,this.more.hidden=!0,this.more.innerHTML=`<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false"><circle cx="5" cy="12" r="1.75" fill="currentColor"/><circle cx="12" cy="12" r="1.75" fill="currentColor"/><circle cx="19" cy="12" r="1.75" fill="currentColor"/></svg>`,this.more.setAttribute(`aria-label`,this.editor.t(`toolbar.more`)),this.more.title=this.editor.t(`toolbar.more`),this.more.setAttribute(`aria-expanded`,`false`),this.more.setAttribute(`aria-controls`,t),this.more.addEventListener(`mousedown`,e=>e.preventDefault()),this.more.addEventListener(`click`,()=>{this.panel?.hidden?this.openPanel():this.closePanel(!0)}),this.panel=e.createElement(`div`),this.panel.id=t,this.panel.className=`wysio-toolbar-panel`,this.panel.hidden=!0,this.panel.setAttribute(`role`,`group`),this.panel.setAttribute(`aria-label`,this.editor.t(`toolbar.more`)),this.panel.addEventListener(`keydown`,this.onPanelKey),this.panel.addEventListener(`click`,e=>{let t=e.target.closest(`button`);t&&t.getAttribute(`aria-disabled`)!==`true`&&this.closePanel(!1)}),this.panel.addEventListener(`change`,()=>this.closePanel(!1)),this.dom.append(this.more,this.panel),typeof ResizeObserver<`u`&&(this.observer=new ResizeObserver(()=>this.layout()),this.observer.observe(this.dom))}layout(){let{more:e,panel:t}=this;if(!e||!t)return;let n=this.editor.dom.ownerDocument.activeElement;for(let t of this.entries)this.dom.insertBefore(t,e);if(e.hidden=!0,this.dom.scrollWidth<=this.dom.clientWidth){this.closePanel(!1),this.ensureTabStop();return}e.hidden=!1;let r=getComputedStyle(this.dom),i=parseFloat(r.columnGap)||0,a=this.dom.clientWidth-(parseFloat(r.paddingRight)||0)-e.offsetWidth-i,o=Xf(this.entries.map(e=>e.offsetLeft+e.offsetWidth),a);for(;o>0&&this.entries[o-1].classList.contains(`wysio-separator`);)o--;for(let e of this.entries.slice(o))t.appendChild(e);this.ensureTabStop(),n instanceof HTMLElement&&this.dom.contains(n)&&n.focus()}openPanel(){let{more:e,panel:t}=this;e&&t&&(t.hidden=!1,e.setAttribute(`aria-expanded`,`true`),this.editor.dom.ownerDocument.addEventListener(`mousedown`,this.onOutside,!0),this.panelItems()[0]?.focus())}closePanel(e){let{more:t,panel:n}=this;t&&n&&!n.hidden&&(n.hidden=!0,t.setAttribute(`aria-expanded`,`false`),this.editor.dom.ownerDocument.removeEventListener(`mousedown`,this.onOutside,!0),e&&t.focus())}panelItems(){return this.panel?this.controls.map(e=>e.el).filter(e=>this.panel.contains(e)&&!(e instanceof HTMLSelectElement&&e.disabled)):[]}onOutside=e=>{let t=e.target;!this.panel?.contains(t)&&!this.more?.contains(t)&&this.closePanel(!1)};onPanelKey=e=>{if(e.stopPropagation(),e.key===`Escape`){e.preventDefault(),this.closePanel(!0);return}if(e.target instanceof HTMLSelectElement&&(e.key===`ArrowUp`||e.key===`ArrowDown`))return;let t=this.panelItems(),n=t.indexOf(e.target),r=null;e.key===`ArrowRight`||e.key===`ArrowDown`?r=(n+1)%t.length:e.key===`ArrowLeft`||e.key===`ArrowUp`?r=(n-1+t.length)%t.length:e.key===`Home`?r=0:e.key===`End`&&(r=t.length-1),r!==null&&(e.preventDefault(),t[r]?.focus())};focusable(){let e=this.controls.map(e=>e.el).filter(e=>e.parentElement===this.dom&&!(e instanceof HTMLSelectElement&&e.disabled));return this.more&&!this.more.hidden?[...e,this.more]:e}ensureTabStop(){let e=this.focusable();if(!e.some(e=>e.tabIndex===0)){for(let e of this.controls)e.el.tabIndex=-1;this.more&&(this.more.tabIndex=-1),e[0]&&(e[0].tabIndex=0)}}onFocusIn=e=>{let t=e.target;if(this.focusable().includes(t)){for(let e of this.controls)e.el.tabIndex=e.el===t?0:-1;this.more&&(this.more.tabIndex=this.more===t?0:-1)}};onKeyDown=e=>{if(e.key===`Escape`){e.preventDefault(),this.editor.focus();return}let t=this.focusable();if(!t.length)return;let n=t.indexOf(e.target);if(n===-1)return;let r=null;e.key===`ArrowRight`?r=(n+1)%t.length:e.key===`ArrowLeft`?r=(n-1+t.length)%t.length:e.key===`Home`?r=0:e.key===`End`&&(r=t.length-1),r!==null&&(e.preventDefault(),t[r]?.focus())};onPopover=e=>{let{key:t,open:n}=e.detail;for(let e of this.controls)e.kind===`button`&&e.item.popover===t&&e.el.setAttribute(`aria-expanded`,String(n))}},ep=[`heading`,`|`,`bold`,`italic`,`underline`,`strike`,`code`,`|`,`textColor`,`highlight`,`clearFormatting`,`|`,`align`,`bulletList`,`orderedList`,`blockquote`,`horizontalRule`,`table`,`|`,`link`,`image`,`|`,`undo`,`redo`],tp=0,np=class{dom;view;schema;options;emitter=new lc;toolbar=null;textarea=null;input=null;form=null;initialContent=null;plugins;messages;locale;formats=new Map;editable;currentMode=`wysiwyg`;destroyed=!1;constructor(e,t={}){let n=typeof e==`string`?document.querySelector(e):e;if(!n)throw Error(`[wysio] Element not found: ${String(e)}`);this.options=t;let{locale:r,messages:i}=rp(t.locale);this.locale=r,this.messages={...dc,...i,...t.messages},this.editable=t.editable??!0,this.plugins=ip(t),this.schema=qf(this.plugins);let a=t.content,o=t.format;n instanceof HTMLTextAreaElement?(this.textarea=n,a??=n.value,this.dom=n.ownerDocument.createElement(`div`),n.insertAdjacentElement(`afterend`,this.dom),n.hidden=!0):(this.dom=n,a===void 0&&(a=n.innerHTML.trim(),o=`html`),n.innerHTML=``),this.dom.classList.add(`wysio`);let s=this.dom.ownerDocument,c={schema:this.schema,editor:this};for(let e of this.plugins)for(let[t,n]of Object.entries(e.formats?.(c)??{}))this.formats.set(t,n);let l=s.createElement(`div`);l.className=`wysio-body`,this.dom.appendChild(l);let u=`wysio-${++tp}`;if(this.view=new Js(l,{state:Rn.create({doc:this.parseContent(a,o),plugins:this.createProseMirrorPlugins(c)}),editable:()=>this.editable,attributes:{id:u,class:`wysio-content`,role:`textbox`,"aria-multiline":`true`,"aria-label":t.ariaLabel??this.t(`editor`)},dispatchTransaction:e=>this.dispatch(e),handleDOMEvents:{focus:(e,t)=>(this.emitter.emit(`focus`,this,t),!1),blur:(e,t)=>(this.emitter.emit(`blur`,this,t),!1)}}),t.toolbar!==!1){let e=new Map;for(let t of this.plugins)for(let[n,r]of Object.entries(t.toolbarItems?.(c)??{}))e.set(n,r);if(this.toolbar=new $f(this,t.toolbar??ep,e,{warnUnknown:!!t.toolbar,mode:t.toolbarMode??`overflow`}),t.sticky){this.dom.classList.add(`wysio-sticky`);let e=typeof t.sticky==`number`?t.sticky:0;this.dom.style.setProperty(`--wysio-sticky-top`,`${e}px`)}this.dom.insertBefore(this.toolbar.dom,l),this.toolbar.update(this.view.state)}t.name&&this.textarea?this.textarea.name=t.name:t.name&&(this.input=s.createElement(`input`),this.input.type=`hidden`,this.input.name=t.name,this.dom.appendChild(this.input)),this.form=(this.textarea??this.input)?.form??null,this.form?.addEventListener(`reset`,this.onFormReset),this.initialContent=this.isEmpty?null:this.getJSON(),this.syncTextarea()}createProseMirrorPlugins(e){return[Or({rules:this.plugins.flatMap(t=>t.inputRules?.(e)??[])}),Wr({Backspace:Ar,"Alt-F10":()=>(this.toolbar?.focus(),!!this.toolbar)}),...this.plugins.flatMap(t=>t.keymap?[Wr(t.keymap(e))]:[]),Wr(wr),...this.plugins.flatMap(t=>t.prosemirrorPlugins?.(e)??[])]}dispatch(e){this.destroyed||(this.view.updateState(this.view.state.apply(e)),this.toolbar?.update(this.view.state),this.emitter.emit(`transaction`,this,e),e.docChanged&&this.changed())}changed(){this.syncTextarea(),this.emitter.emit(`change`,this),this.options.onChange?.(this)}syncTextarea(){if(!this.textarea&&!this.input)return;let e=this.serialize(this.options.format??`html`);this.textarea&&(this.textarea.value=e),this.input&&(this.input.value=e)}onFormReset=()=>{queueMicrotask(()=>{this.destroyed||this.setContent(this.initialContent,{emitChange:!0})})};get state(){return this.view.state}get mode(){return this.currentMode}setMode(e){e!==this.currentMode&&(this.currentMode=e,this.dom.dataset.mode=e,this.toolbar?.update(this.view.state),this.emitter.emit(`mode`,this,e))}get isEditable(){return this.editable}get isEmpty(){return cc(this.view.state.doc)}t(e,t){return mc(this.messages[e]??e,t)}getHTML(){return this.isEmpty?``:ic(this.schema,this.view.state.doc,this.dom.ownerDocument)}getJSON(){return this.view.state.doc.toJSON()}getMarkdown(){return this.serialize(`markdown`)}serialize(e){if(e===`html`)return this.getHTML();if(e===`json`)return this.isEmpty?``:JSON.stringify(this.getJSON());let t=this.formatHandler(e);return this.isEmpty?``:t.serialize(this.view.state.doc)}formatHandler(e){let t=this.formats.get(e);if(!t)throw Error(`[wysio] No plugin provides the "${e}" format.${e===`markdown`?` Add it with: import { markdown } from 'wysio/markdown'; plugins: [markdown()]. On a CDN, use wysio.full.iife.js.`:``}`);return t}parseContent(e,t=`html`){let n=this.dom.ownerDocument;return typeof e!=`string`||e===``||t===`html`?sc(this.schema,e,n):t===`json`?sc(this.schema,JSON.parse(e),n):ac(this.schema,this.formatHandler(t).parse(e,this.schema),n)}getText(){let{doc:e}=this.view.state;return e.textBetween(0,e.content.size,`
46
+
47
+ `)}setContent(e,{emitChange:t=!1,format:n=this.options.format}={}){let r=Rn.create({doc:this.parseContent(e,n),plugins:this.view.state.plugins});this.view.updateState(r),this.toolbar?.update(r),this.syncTextarea(),t&&(this.emitter.emit(`change`,this),this.options.onChange?.(this))}setEditable(e){this.editable=e,this.view.setProps({}),this.toolbar?.update(this.view.state)}exec(e){if(!this.editable)return!1;let t=e(this.view.state,this.view.dispatch,this.view);return this.focus(),t}reportError(e,t){this.emitter.has(`error`)?this.emitter.emit(`error`,this,e,t):console.error(`[wysio] ${t.source} failed:`,e)}hasPlugin(e){return this.plugins.some(t=>t.name===e)}focus(){this.destroyed||this.view.focus()}on(e,t){return this.emitter.on(e,t)}off(e,t){this.emitter.off(e,t)}destroy(){if(this.destroyed)return;let e=this.getHTML(),t=this.serialize(this.options.format??`html`);this.emitter.emit(`destroy`,this),this.destroyed=!0,this.emitter.clear(),this.view.destroy(),this.toolbar?.destroy(),this.form?.removeEventListener(`reset`,this.onFormReset),this.input?.remove(),this.textarea?(this.textarea.value=t,this.textarea.hidden=!1,this.dom.remove()):(this.dom.classList.remove(`wysio`,`wysio-sticky`),this.dom.style.removeProperty(`--wysio-sticky-top`),delete this.dom.dataset.mode,this.dom.innerHTML=e)}};function rp(e){if(e==null)return{locale:`en`,messages:{}};if(typeof e!=`string`)return{locale:null,messages:e};let t=pc(e);return t?{locale:t.code,messages:t.messages}:(console.warn(`[wysio] Unknown locale "${e}", using English. Add it with registerLocale().`),{locale:`en`,messages:{}})}function ip(e){let t=new Set(e.removePlugins??[]);if(t.has(`base`))throw Error(`[wysio] The "base" plugin cannot be removed.`);let n=Kf(e.plugins??[]);return[...Wf.filter(e=>!t.has(e.name)).map(e=>{let t=n.findIndex(t=>t.name===e.name);return t===-1?e:n.splice(t,1)[0]}),...n]}function ap(e,t){return new np(e,t)}var op=[`readonly`,`disabled`];function sp(){return class extends HTMLElement{static formAssociated=!0;static observedAttributes=[`value`,`placeholder`,...op];#e=null;#t=null;#n=null;#r=!1;constructor(){super();try{this.#t=this.attachInternals()}catch{this.#t=null}}get editor(){return this.#e}get#i(){return this.getAttribute(`format`)||`html`}get#a(){return typeof this.#t?.setFormValue==`function`}get value(){return this.#e?this.#e.serialize(this.#i):this.#n??this.getAttribute(`value`)??``}set value(e){let t=e==null?``:String(e);this.#e?this.#e.setContent(t):this.#n=t,this.#s()}get form(){return this.#t?.form??this.closest(`form`)}get name(){return this.getAttribute(`name`)??``}connectedCallback(){if(this.#e)return;let e=this.getAttribute(`toolbar`),t=this.getAttribute(`plugins`);this.#e=ap(this,{content:this.#n??this.getAttribute(`value`)??``,format:this.#i,plugins:t?t.split(/[\s,]+/).filter(Boolean):void 0,name:this.#a?void 0:this.getAttribute(`name`)||void 0,placeholder:this.getAttribute(`placeholder`)??void 0,locale:this.getAttribute(`locale`)??void 0,ariaLabel:this.getAttribute(`aria-label`)??void 0,toolbar:e===`false`?!1:e?e.split(/[\s,]+/).filter(Boolean):void 0,editable:this.#o(),onChange:()=>{this.#s(),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}}),this.#n=null,this.#s()}disconnectedCallback(){this.#e&&(this.#n=this.#e.serialize(this.#i),this.#e.destroy(),this.#e=null,this.innerHTML=``)}attributeChangedCallback(e,t,n){t!==n&&this.#e&&(e===`value`?(n??``)!==this.value&&(this.value=n??``):op.includes(e)&&this.#e.setEditable(this.#o()))}formResetCallback(){this.value=this.getAttribute(`value`)??``}formDisabledCallback(e){this.#r=e,this.#e?.setEditable(this.#o())}formStateRestoreCallback(e){typeof e==`string`&&(this.value=e)}#o(){return!this.#r&&op.every(e=>!this.hasAttribute(e))}#s(){this.#a&&this.#t.setFormValue(this.value)}}}function cp(e=`wysio-editor`){typeof customElements>`u`||customElements.get(e)||customElements.define(e,sp())}var lp=new WeakMap;return cp(),e.ALIGNMENTS=xc,e.DEFAULT_HIGHLIGHT_COLORS=hl,e.DEFAULT_IMAGE_TYPES=fu,e.DEFAULT_TEXT_COLORS=ml,e.Editor=np,e.FORMATTING_ATTRIBUTES=ul,e.IMAGE_ALIGNMENTS=du,e.MAX_TABLE_SIZE=Af,e.activeColor=Cl,e.alignment=Nc,e.autoInit=function(e={},t=document){let n=[];for(let r of t.querySelectorAll(`[data-wysio]`)){if(lp.has(r))continue;let t;try{let e=r.dataset.wysioOptions;t=e?JSON.parse(e):{}}catch(e){console.error(`[wysio] Invalid JSON in data-wysio-options:`,r,e);continue}let i=typeof e==`function`?e(r):e,a;try{a=ap(r,{...i,...t,plugins:[...i.plugins??[],...t.plugins??[]],messages:{...i.messages,...t.messages}})}catch(e){console.error(`[wysio] Could not create an editor for`,r,e);continue}lp.set(r,a),a.on(`destroy`,()=>lp.delete(r)),n.push(a)}return n},e.availableLocales=function(){return[...fc.keys()]},e.base=Kc,e.blockquote=sl,e.bold=Hu,e.cleanPastedHTML=ad,e.clearFormatting=fl,e.clearFormattingPlugin=pl,e.code=Ku,e.createEditor=ap,e.createTable=Ff,e.defaultMessages=dc,e.defaultPlugins=Wf,e.defaultToolbar=ep,e.definePlugin=K,e.defineWysioElement=cp,e.findAncestor=rl,e.fitCount=Xf,e.formatHTML=fd,e.getEditor=function(e){return lp.get(e)??null},e.getMarkRange=ol,e.hardBreak=ll,e.heading=jl,e.highlight=Ol,e.history=ru,e.horizontalRule=cl,e.image=Mu,e.insertImage=Ou,e.insertTable=If,e.isAlignmentActive=kc,e.isMarkActive=nl,e.italic=Uu,e.link=Lu,e.lists=zu,e.nl=uc,e.normalizeColor=_l,e.openAlignmentMenu=Mc,e.openImageDialog=Au,e.openLinkDialog=Fu,e.openTableMenu=Bf,e.paletteCSS=function(e,t){return yl(t).colors.map(t=>e===`text`?`.wysio-color-${t.name} { color: ${t.value}; }`:`.wysio-highlight-${t.name} { background-color: ${t.value}; }`).join(`
48
+ `)},e.paste=od,e.placeholder=sd,e.registerLocale=function(e,t){fc.set(e.toLowerCase(),t)},e.registerPlugin=function(e,t){Gf.set(e,t)},e.removeColorMark=Sl,e.removeImage=ku,e.removeLink=Pu,e.sanitizeImageUrl=uu,e.sanitizeUrl=su,e.setAlignment=Oc,e.setColorMark=xl,e.setLink=function(e,t){return(n,r)=>{let i=su(t.href);if(!i)return!1;let a=e.create({href:i,target:t.target===`_blank`?`_blank`:null}),o=Nu(n,e);if(r){let t=n.tr;if(o)t.removeMark(o.from,o.to,e).addMark(o.from,o.to,a);else{let{from:e}=n.selection;t.insertText(i,e).addMark(e,e+i.length,a)}r(t.scrollIntoView())}return!0}},e.source=vd,e.strike=Gu,e.table=Uf,e.textColor=Dl,e.toggleHeaderRow=Lf,e.toggleList=il,e.toggleSourceView=_d,e.toggleWrap=al,e.underline=Wu,e.uploadImages=wu,e.version=`0.2.0-alpha.0`,e})({});
49
+ //# sourceMappingURL=wysio.iife.js.map