rhua-chatgpt-web 1.0.99 → 1.1.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 (46) hide show
  1. package/dist/{api_chain-C2BsZcfa.js → api_chain-6WuaFa6d.js} +2 -2
  2. package/dist/{api_chain-D2AEAwf2.cjs → api_chain-z7-hferR.cjs} +1 -1
  3. package/dist/{combine_docs_chain-BwUcmS0t.cjs → combine_docs_chain-CFAXRlyi.cjs} +1 -1
  4. package/dist/{combine_docs_chain-D0ygQAil.js → combine_docs_chain-CO7HVb4R.js} +2 -2
  5. package/dist/{few_shot-CHQMukLV.js → few_shot-D1fV7wmE.js} +1 -1
  6. package/dist/{few_shot-CQMLIcvu.cjs → few_shot-GynjP3JZ.cjs} +1 -1
  7. package/dist/{index-3uuVdHPW.js → index-B3AeHb0J.js} +1 -1
  8. package/dist/{index-D1EyeOGY.cjs → index-BcePyLfy.cjs} +1 -1
  9. package/dist/{index-DiJKM8e3.cjs → index-BdHsAk36.cjs} +1 -1
  10. package/dist/index-BiyXJ5nZ.js +4 -0
  11. package/dist/{index-DkwjGulR.cjs → index-BjVIOIdk.cjs} +1 -1
  12. package/dist/index-C4FSTC-Y.js +4 -0
  13. package/dist/{index-CvkY01OP.cjs → index-CFCSEDxn.cjs} +1 -1
  14. package/dist/{index-CUbh3CUk.cjs → index-CMmMjajZ.cjs} +1 -1
  15. package/dist/{index-D9geeS71.js → index-CYZSWzuu.js} +2 -2
  16. package/dist/{index-DPo7N7-F.js → index-Cfz7TnCH.js} +131 -14
  17. package/dist/{index-DDNOIr8O.js → index-D0o12JtU.js} +1 -1
  18. package/dist/{index-vJhPvv3A.js → index-DKYlRoiR.js} +2 -2
  19. package/dist/{index-NFb6Ikqb.cjs → index-DL_ocleL.cjs} +1 -1
  20. package/dist/{index-D3WYQbg9.cjs → index-DaVkrct-.cjs} +1 -1
  21. package/dist/index-De7_kMn7.js +4 -0
  22. package/dist/{index-5hC-EuRW.cjs → index-Dift2gpr.cjs} +1 -1
  23. package/dist/{index-Ddt8e4jQ.js → index-Dkq6Ss_h.js} +1 -1
  24. package/dist/{index-xQlqRtFE.cjs → index-DsPuml45.cjs} +2 -2
  25. package/dist/index-Gi2kGbCW.js +4 -0
  26. package/dist/{index-DKj4xxCF.cjs → index-KDG7mz5O.cjs} +1 -1
  27. package/dist/{index-DlDIFIcy.js → index-PRwtvON1.js} +1 -1
  28. package/dist/{index-B4HXYy58.js → index-gI4Ks2P3.js} +1 -1
  29. package/dist/{index-CUTMmRLO.cjs → index-jr5i21r1.cjs} +1 -1
  30. package/dist/{index-DDtVKZHe.cjs → index-oel1bTo0.cjs} +1 -1
  31. package/dist/index.cjs.js +1 -1
  32. package/dist/{index.es-muo7iWsn.js → index.es-Fq7tEj25.js} +11 -11
  33. package/dist/{index.es-B9waF7p1.cjs → index.es-QDwz4eEz.cjs} +2 -2
  34. package/dist/index.esm.js +1 -1
  35. package/dist/{llm_chain-FiDBkCHX.js → llm_chain-5NVYgTDC.js} +1 -1
  36. package/dist/{llm_chain-BVEQefX9.cjs → llm_chain-HMEylFLR.cjs} +1 -1
  37. package/dist/{sequential_chain-C89zWQZZ.js → sequential_chain-B3aNFa_8.js} +1 -1
  38. package/dist/{sequential_chain-hcM_0OeZ.cjs → sequential_chain-BIwygM6l.cjs} +1 -1
  39. package/dist/style.css +1 -1
  40. package/dist/{vector_db_qa-Cxtn-hGw.js → vector_db_qa-BlC0aeM2.js} +3 -3
  41. package/dist/{vector_db_qa-DpnOTF2e.cjs → vector_db_qa-C_vzGRYC.cjs} +1 -1
  42. package/package.json +1 -1
  43. package/dist/index-BMeyd5Mb.js +0 -4
  44. package/dist/index-CE38VgAV.js +0 -4
  45. package/dist/index-D5IEaWdP.js +0 -4
  46. package/dist/index-Da-yc0Sn.js +0 -4
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./vue.runtime.esm-bundler-l6P5-Bcy.cjs"),t=require("react-dom"),n=require("react"),o=require("./index-xQlqRtFE.cjs");function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const i=r(t),s=r(n);function l(){return"undefined"!=typeof window}function a(e){return u(e)?(e.nodeName||"").toLowerCase():"#document"}function c(e){var t;return(null==e||null==(t=e.ownerDocument)?void 0:t.defaultView)||window}function d(e){var t;return null==(t=(u(e)?e.ownerDocument:e.document)||window.document)?void 0:t.documentElement}function u(e){return!!l()&&(e instanceof Node||e instanceof c(e).Node)}function h(e){return!!l()&&(e instanceof Element||e instanceof c(e).Element)}function p(e){return!!l()&&(e instanceof HTMLElement||e instanceof c(e).HTMLElement)}function f(e){return!(!l()||"undefined"==typeof ShadowRoot)&&(e instanceof ShadowRoot||e instanceof c(e).ShadowRoot)}const m=new Set(["inline","contents"]);function g(e){const{overflow:t,overflowX:n,overflowY:o,display:r}=T(e);return/auto|scroll|overlay|hidden|clip/.test(t+o+n)&&!m.has(r)}const y=new Set(["table","td","th"]);function b(e){return y.has(a(e))}const v=[":popover-open",":modal"];function x(e){return v.some(t=>{try{return e.matches(t)}catch(n){return!1}})}const w=["transform","translate","scale","rotate","perspective"],k=["transform","translate","scale","rotate","perspective","filter"],C=["paint","layout","strict","content"];function E(e){const t=S(),n=h(e)?T(e):e;return w.some(e=>!!n[e]&&"none"!==n[e])||!!n.containerType&&"normal"!==n.containerType||!t&&!!n.backdropFilter&&"none"!==n.backdropFilter||!t&&!!n.filter&&"none"!==n.filter||k.some(e=>(n.willChange||"").includes(e))||C.some(e=>(n.contain||"").includes(e))}function S(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}const M=new Set(["html","body","#document"]);function R(e){return M.has(a(e))}function T(e){return c(e).getComputedStyle(e)}function j(e){return h(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function N(e){if("html"===a(e))return e;const t=e.assignedSlot||e.parentNode||f(e)&&e.host||d(e);return f(t)?t.host:t}function A(e){const t=N(e);return R(t)?e.ownerDocument?e.ownerDocument.body:e.body:p(t)&&g(t)?t:A(t)}function O(e,t,n){var o;void 0===t&&(t=[]),void 0===n&&(n=!0);const r=A(e),i=r===(null==(o=e.ownerDocument)?void 0:o.body),s=c(r);if(i){const e=_(s);return t.concat(s,s.visualViewport||[],g(r)?r:[],e&&n?O(e):[])}return t.concat(r,O(r,[],n))}function _(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function P(e){let t=e.activeElement;for(;null!=(null==(n=t)||null==(n=n.shadowRoot)?void 0:n.activeElement);){var n;t=t.shadowRoot.activeElement}return t}function I(e,t){if(!e||!t)return!1;const n=null==t.getRootNode?void 0:t.getRootNode();if(e.contains(t))return!0;if(n&&f(n)){let n=t;for(;n;){if(e===n)return!0;n=n.parentNode||n.host}}return!1}function L(){const e=navigator.userAgentData;return null!=e&&e.platform?e.platform:navigator.platform}function D(){const e=navigator.userAgentData;return e&&Array.isArray(e.brands)?e.brands.map(e=>{let{brand:t,version:n}=e;return t+"/"+n}).join(" "):navigator.userAgent}function B(e){return!D().includes("jsdom/")&&(!V()&&0===e.width&&0===e.height||V()&&1===e.width&&1===e.height&&0===e.pressure&&0===e.detail&&"mouse"===e.pointerType||e.width<1&&e.height<1&&0===e.pressure&&0===e.detail&&"touch"===e.pointerType)}function H(){return/apple/i.test(navigator.vendor)}function V(){const e=/android/i;return e.test(L())||e.test(D())}function $(e,t){const n=["mouse","pen"];return n.push("",void 0),n.includes(e)}function z(e){return(null==e?void 0:e.ownerDocument)||document}function F(e,t){if(null==t)return!1;if("composedPath"in e)return e.composedPath().includes(t);const n=e;return null!=n.target&&t.contains(n.target)}function U(e){return"composedPath"in e?e.composedPath()[0]:e.target}const W=Math.min,q=Math.max,G=Math.round,K=Math.floor,Z=e=>({x:e,y:e}),J={left:"right",right:"left",bottom:"top",top:"bottom"},X={start:"end",end:"start"};function Y(e,t,n){return q(e,W(t,n))}function Q(e,t){return"function"==typeof e?e(t):e}function ee(e){return e.split("-")[0]}function te(e){return e.split("-")[1]}function ne(e){return"x"===e?"y":"x"}function oe(e){return"y"===e?"height":"width"}const re=new Set(["top","bottom"]);function ie(e){return re.has(ee(e))?"y":"x"}function se(e){return ne(ie(e))}function le(e){return e.replace(/start|end/g,e=>X[e])}const ae=["left","right"],ce=["right","left"],de=["top","bottom"],ue=["bottom","top"];function he(e,t,n,o){const r=te(e);let i=function(e,t,n){switch(e){case"top":case"bottom":return n?t?ce:ae:t?ae:ce;case"left":case"right":return t?de:ue;default:return[]}}(ee(e),"start"===n,o);return r&&(i=i.map(e=>e+"-"+r),t&&(i=i.concat(i.map(le)))),i}function pe(e){return e.replace(/left|right|bottom|top/g,e=>J[e])}function fe(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}function me(e){const{x:t,y:n,width:o,height:r}=e;return{width:o,height:r,top:n,left:t,right:t+o,bottom:n+r,x:t,y:n}}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./vue.runtime.esm-bundler-l6P5-Bcy.cjs"),t=require("react-dom"),n=require("react"),o=require("./index-DsPuml45.cjs");function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const i=r(t),s=r(n);function l(){return"undefined"!=typeof window}function a(e){return u(e)?(e.nodeName||"").toLowerCase():"#document"}function c(e){var t;return(null==e||null==(t=e.ownerDocument)?void 0:t.defaultView)||window}function d(e){var t;return null==(t=(u(e)?e.ownerDocument:e.document)||window.document)?void 0:t.documentElement}function u(e){return!!l()&&(e instanceof Node||e instanceof c(e).Node)}function h(e){return!!l()&&(e instanceof Element||e instanceof c(e).Element)}function p(e){return!!l()&&(e instanceof HTMLElement||e instanceof c(e).HTMLElement)}function f(e){return!(!l()||"undefined"==typeof ShadowRoot)&&(e instanceof ShadowRoot||e instanceof c(e).ShadowRoot)}const m=new Set(["inline","contents"]);function g(e){const{overflow:t,overflowX:n,overflowY:o,display:r}=T(e);return/auto|scroll|overlay|hidden|clip/.test(t+o+n)&&!m.has(r)}const y=new Set(["table","td","th"]);function b(e){return y.has(a(e))}const v=[":popover-open",":modal"];function x(e){return v.some(t=>{try{return e.matches(t)}catch(n){return!1}})}const w=["transform","translate","scale","rotate","perspective"],k=["transform","translate","scale","rotate","perspective","filter"],C=["paint","layout","strict","content"];function E(e){const t=S(),n=h(e)?T(e):e;return w.some(e=>!!n[e]&&"none"!==n[e])||!!n.containerType&&"normal"!==n.containerType||!t&&!!n.backdropFilter&&"none"!==n.backdropFilter||!t&&!!n.filter&&"none"!==n.filter||k.some(e=>(n.willChange||"").includes(e))||C.some(e=>(n.contain||"").includes(e))}function S(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}const M=new Set(["html","body","#document"]);function R(e){return M.has(a(e))}function T(e){return c(e).getComputedStyle(e)}function j(e){return h(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function N(e){if("html"===a(e))return e;const t=e.assignedSlot||e.parentNode||f(e)&&e.host||d(e);return f(t)?t.host:t}function A(e){const t=N(e);return R(t)?e.ownerDocument?e.ownerDocument.body:e.body:p(t)&&g(t)?t:A(t)}function O(e,t,n){var o;void 0===t&&(t=[]),void 0===n&&(n=!0);const r=A(e),i=r===(null==(o=e.ownerDocument)?void 0:o.body),s=c(r);if(i){const e=_(s);return t.concat(s,s.visualViewport||[],g(r)?r:[],e&&n?O(e):[])}return t.concat(r,O(r,[],n))}function _(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function P(e){let t=e.activeElement;for(;null!=(null==(n=t)||null==(n=n.shadowRoot)?void 0:n.activeElement);){var n;t=t.shadowRoot.activeElement}return t}function I(e,t){if(!e||!t)return!1;const n=null==t.getRootNode?void 0:t.getRootNode();if(e.contains(t))return!0;if(n&&f(n)){let n=t;for(;n;){if(e===n)return!0;n=n.parentNode||n.host}}return!1}function L(){const e=navigator.userAgentData;return null!=e&&e.platform?e.platform:navigator.platform}function D(){const e=navigator.userAgentData;return e&&Array.isArray(e.brands)?e.brands.map(e=>{let{brand:t,version:n}=e;return t+"/"+n}).join(" "):navigator.userAgent}function B(e){return!D().includes("jsdom/")&&(!V()&&0===e.width&&0===e.height||V()&&1===e.width&&1===e.height&&0===e.pressure&&0===e.detail&&"mouse"===e.pointerType||e.width<1&&e.height<1&&0===e.pressure&&0===e.detail&&"touch"===e.pointerType)}function H(){return/apple/i.test(navigator.vendor)}function V(){const e=/android/i;return e.test(L())||e.test(D())}function $(e,t){const n=["mouse","pen"];return n.push("",void 0),n.includes(e)}function z(e){return(null==e?void 0:e.ownerDocument)||document}function F(e,t){if(null==t)return!1;if("composedPath"in e)return e.composedPath().includes(t);const n=e;return null!=n.target&&t.contains(n.target)}function U(e){return"composedPath"in e?e.composedPath()[0]:e.target}const W=Math.min,q=Math.max,G=Math.round,K=Math.floor,Z=e=>({x:e,y:e}),J={left:"right",right:"left",bottom:"top",top:"bottom"},X={start:"end",end:"start"};function Y(e,t,n){return q(e,W(t,n))}function Q(e,t){return"function"==typeof e?e(t):e}function ee(e){return e.split("-")[0]}function te(e){return e.split("-")[1]}function ne(e){return"x"===e?"y":"x"}function oe(e){return"y"===e?"height":"width"}const re=new Set(["top","bottom"]);function ie(e){return re.has(ee(e))?"y":"x"}function se(e){return ne(ie(e))}function le(e){return e.replace(/start|end/g,e=>X[e])}const ae=["left","right"],ce=["right","left"],de=["top","bottom"],ue=["bottom","top"];function he(e,t,n,o){const r=te(e);let i=function(e,t,n){switch(e){case"top":case"bottom":return n?t?ce:ae:t?ae:ce;case"left":case"right":return t?de:ue;default:return[]}}(ee(e),"start"===n,o);return r&&(i=i.map(e=>e+"-"+r),t&&(i=i.concat(i.map(le)))),i}function pe(e){return e.replace(/left|right|bottom|top/g,e=>J[e])}function fe(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}function me(e){const{x:t,y:n,width:o,height:r}=e;return{width:o,height:r,top:n,left:t,right:t+o,bottom:n+r,x:t,y:n}}
2
2
  /*!
3
3
  * tabbable 6.3.0
4
4
  * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
5
- */var ge=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"].join(","),ye="undefined"==typeof Element,be=ye?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,ve=!ye&&Element.prototype.getRootNode?function(e){var t;return null==e||null===(t=e.getRootNode)||void 0===t?void 0:t.call(e)}:function(e){return null==e?void 0:e.ownerDocument},xe=function(e,t){var n;void 0===t&&(t=!0);var o=null==e||null===(n=e.getAttribute)||void 0===n?void 0:n.call(e,"inert");return""===o||"true"===o||t&&e&&xe(e.parentNode)},we=function(e,t,n){for(var o=[],r=Array.from(e);r.length;){var i=r.shift();if(!xe(i,!1))if("SLOT"===i.tagName){var s=i.assignedElements(),l=s.length?s:i.children,a=we(l,!0,n);n.flatten?o.push.apply(o,a):o.push({scopeParent:i,candidates:a})}else{be.call(i,ge)&&n.filter(i)&&(t||!e.includes(i))&&o.push(i);var c=i.shadowRoot||"function"==typeof n.getShadowRoot&&n.getShadowRoot(i),d=!xe(c,!1)&&(!n.shadowRootFilter||n.shadowRootFilter(i));if(c&&d){var u=we(!0===c?i.children:c.children,!0,n);n.flatten?o.push.apply(o,u):o.push({scopeParent:i,candidates:u})}else r.unshift.apply(r,i.children)}}return o},ke=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},Ce=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||function(e){var t,n=null==e||null===(t=e.getAttribute)||void 0===t?void 0:t.call(e,"contenteditable");return""===n||"true"===n}(e))&&!ke(e)?0:e.tabIndex},Ee=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},Se=function(e){return"INPUT"===e.tagName},Me=function(e){return function(e){return Se(e)&&"radio"===e.type}(e)&&!function(e){if(!e.name)return!0;var t,n=e.form||ve(e),o=function(e){return n.querySelectorAll('input[type="radio"][name="'+e+'"]')};if("undefined"!=typeof window&&void 0!==window.CSS&&"function"==typeof window.CSS.escape)t=o(window.CSS.escape(e.name));else try{t=o(e.name)}catch(i){return!1}var r=function(e,t){for(var n=0;n<e.length;n++)if(e[n].checked&&e[n].form===t)return e[n]}(t,e.form);return!r||r===e}(e)},Re=function(e){var t=e.getBoundingClientRect(),n=t.width,o=t.height;return 0===n&&0===o},Te=function(e,t){var n=t.displayCheck,o=t.getShadowRoot;if("full-native"===n&&"checkVisibility"in e)return!e.checkVisibility({checkOpacity:!1,opacityProperty:!1,contentVisibilityAuto:!0,visibilityProperty:!0,checkVisibilityCSS:!0});if("hidden"===getComputedStyle(e).visibility)return!0;var r=be.call(e,"details>summary:first-of-type")?e.parentElement:e;if(be.call(r,"details:not([open]) *"))return!0;if(n&&"full"!==n&&"full-native"!==n&&"legacy-full"!==n){if("non-zero-area"===n)return Re(e)}else{if("function"==typeof o){for(var i=e;e;){var s=e.parentElement,l=ve(e);if(s&&!s.shadowRoot&&!0===o(s))return Re(e);e=e.assignedSlot?e.assignedSlot:s||l===e.ownerDocument?s:l.host}e=i}if(function(e){var t,n,o,r,i=e&&ve(e),s=null===(t=i)||void 0===t?void 0:t.host,l=!1;if(i&&i!==e)for(l=!!(null!==(n=s)&&void 0!==n&&null!==(o=n.ownerDocument)&&void 0!==o&&o.contains(s)||null!=e&&null!==(r=e.ownerDocument)&&void 0!==r&&r.contains(e));!l&&s;){var a,c,d;l=!(null===(c=s=null===(a=i=ve(s))||void 0===a?void 0:a.host)||void 0===c||null===(d=c.ownerDocument)||void 0===d||!d.contains(s))}return l}(e))return!e.getClientRects().length;if("legacy-full"!==n)return!0}return!1},je=function(e,t){return!(t.disabled||xe(t)||function(e){return Se(e)&&"hidden"===e.type}(t)||Te(t,e)||function(e){return"DETAILS"===e.tagName&&Array.prototype.slice.apply(e.children).some(function(e){return"SUMMARY"===e.tagName})}(t)||function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var t=e.parentElement;t;){if("FIELDSET"===t.tagName&&t.disabled){for(var n=0;n<t.children.length;n++){var o=t.children.item(n);if("LEGEND"===o.tagName)return!!be.call(t,"fieldset[disabled] *")||!o.contains(e)}return!0}t=t.parentElement}return!1}(t))},Ne=function(e,t){return!(Me(t)||Ce(t)<0||!je(e,t))},Ae=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(t)||t>=0)},Oe=function(e){var t=[],n=[];return e.forEach(function(e,o){var r=!!e.scopeParent,i=r?e.scopeParent:e,s=function(e,t){var n=Ce(e);return n<0&&t&&!ke(e)?0:n}(i,r),l=r?Oe(e.candidates):i;0===s?r?t.push.apply(t,l):t.push(i):n.push({documentOrder:o,tabIndex:s,item:e,isScope:r,content:l})}),n.sort(Ee).reduce(function(e,t){return t.isScope?e.push.apply(e,t.content):e.push(t.content),e},[]).concat(t)},_e=function(e,t){var n;return n=(t=t||{}).getShadowRoot?we([e],t.includeContainer,{filter:Ne.bind(null,t),flatten:!1,getShadowRoot:t.getShadowRoot,shadowRootFilter:Ae}):function(e,t,n){if(xe(e))return[];var o=Array.prototype.slice.apply(e.querySelectorAll(ge));return t&&be.call(e,ge)&&o.unshift(e),o.filter(n)}(e,t.includeContainer,Ne.bind(null,t)),Oe(n)};function Pe(e,t,n){let{reference:o,floating:r}=e;const i=ie(t),s=se(t),l=oe(s),a=ee(t),c="y"===i,d=o.x+o.width/2-r.width/2,u=o.y+o.height/2-r.height/2,h=o[l]/2-r[l]/2;let p;switch(a){case"top":p={x:d,y:o.y-r.height};break;case"bottom":p={x:d,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:u};break;case"left":p={x:o.x-r.width,y:u};break;default:p={x:o.x,y:o.y}}switch(te(t)){case"start":p[s]-=h*(n&&c?-1:1);break;case"end":p[s]+=h*(n&&c?-1:1)}return p}async function Ie(e,t){var n;void 0===t&&(t={});const{x:o,y:r,platform:i,rects:s,elements:l,strategy:a}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:h=!1,padding:p=0}=Q(t,e),f=fe(p),m=l[h?"floating"===u?"reference":"floating":u],g=me(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(m)))||n?m:m.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(l.floating)),boundary:c,rootBoundary:d,strategy:a})),y="floating"===u?{x:o,y:r,width:s.floating.width,height:s.floating.height}:s.reference,b=await(null==i.getOffsetParent?void 0:i.getOffsetParent(l.floating)),v=await(null==i.isElement?void 0:i.isElement(b))&&await(null==i.getScale?void 0:i.getScale(b))||{x:1,y:1},x=me(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:y,offsetParent:b,strategy:a}):y);return{top:(g.top-x.top+f.top)/v.y,bottom:(x.bottom-g.bottom+f.bottom)/v.y,left:(g.left-x.left+f.left)/v.x,right:(x.right-g.right+f.right)/v.x}}function Le(e){const t=W(...e.map(e=>e.left)),n=W(...e.map(e=>e.top));return{x:t,y:n,width:q(...e.map(e=>e.right))-t,height:q(...e.map(e=>e.bottom))-n}}const De=new Set(["left","top"]);function Be(e){const t=T(e);let n=parseFloat(t.width)||0,o=parseFloat(t.height)||0;const r=p(e),i=r?e.offsetWidth:n,s=r?e.offsetHeight:o,l=G(n)!==i||G(o)!==s;return l&&(n=i,o=s),{width:n,height:o,$:l}}function He(e){return h(e)?e:e.contextElement}function Ve(e){const t=He(e);if(!p(t))return Z(1);const n=t.getBoundingClientRect(),{width:o,height:r,$:i}=Be(t);let s=(i?G(n.width):n.width)/o,l=(i?G(n.height):n.height)/r;return s&&Number.isFinite(s)||(s=1),l&&Number.isFinite(l)||(l=1),{x:s,y:l}}const $e=Z(0);function ze(e){const t=c(e);return S()&&t.visualViewport?{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}:$e}function Fe(e,t,n,o){void 0===t&&(t=!1),void 0===n&&(n=!1);const r=e.getBoundingClientRect(),i=He(e);let s=Z(1);t&&(o?h(o)&&(s=Ve(o)):s=Ve(e));const l=function(e,t,n){return void 0===t&&(t=!1),!(!n||t&&n!==c(e))&&t}(i,n,o)?ze(i):Z(0);let a=(r.left+l.x)/s.x,d=(r.top+l.y)/s.y,u=r.width/s.x,p=r.height/s.y;if(i){const e=c(i),t=o&&h(o)?c(o):o;let n=e,r=_(n);for(;r&&o&&t!==n;){const e=Ve(r),t=r.getBoundingClientRect(),o=T(r),i=t.left+(r.clientLeft+parseFloat(o.paddingLeft))*e.x,s=t.top+(r.clientTop+parseFloat(o.paddingTop))*e.y;a*=e.x,d*=e.y,u*=e.x,p*=e.y,a+=i,d+=s,n=c(r),r=_(n)}}return me({width:u,height:p,x:a,y:d})}function Ue(e,t){const n=j(e).scrollLeft;return t?t.left+n:Fe(d(e)).left+n}function We(e,t){const n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Ue(e,n),y:n.top+t.scrollTop}}const qe=new Set(["absolute","fixed"]);function Ge(e,t,n){let o;if("viewport"===t)o=function(e,t){const n=c(e),o=d(e),r=n.visualViewport;let i=o.clientWidth,s=o.clientHeight,l=0,a=0;if(r){i=r.width,s=r.height;const e=S();(!e||e&&"fixed"===t)&&(l=r.offsetLeft,a=r.offsetTop)}const u=Ue(o);if(u<=0){const e=o.ownerDocument,t=e.body,n=getComputedStyle(t),r="CSS1Compat"===e.compatMode&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,s=Math.abs(o.clientWidth-t.clientWidth-r);s<=25&&(i-=s)}else u<=25&&(i+=u);return{width:i,height:s,x:l,y:a}}(e,n);else if("document"===t)o=function(e){const t=d(e),n=j(e),o=e.ownerDocument.body,r=q(t.scrollWidth,t.clientWidth,o.scrollWidth,o.clientWidth),i=q(t.scrollHeight,t.clientHeight,o.scrollHeight,o.clientHeight);let s=-n.scrollLeft+Ue(e);const l=-n.scrollTop;return"rtl"===T(o).direction&&(s+=q(t.clientWidth,o.clientWidth)-r),{width:r,height:i,x:s,y:l}}(d(e));else if(h(t))o=function(e,t){const n=Fe(e,!0,"fixed"===t),o=n.top+e.clientTop,r=n.left+e.clientLeft,i=p(e)?Ve(e):Z(1);return{width:e.clientWidth*i.x,height:e.clientHeight*i.y,x:r*i.x,y:o*i.y}}(t,n);else{const n=ze(e);o={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return me(o)}function Ke(e,t){const n=N(e);return!(n===t||!h(n)||R(n))&&("fixed"===T(n).position||Ke(n,t))}function Ze(e,t,n){const o=p(t),r=d(t),i="fixed"===n,s=Fe(e,!0,i,t);let l={scrollLeft:0,scrollTop:0};const c=Z(0);function u(){c.x=Ue(r)}if(o||!o&&!i)if(("body"!==a(t)||g(r))&&(l=j(t)),o){const e=Fe(t,!0,i,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else r&&u();i&&!o&&r&&u();const h=!r||o||i?Z(0):We(r,l);return{x:s.left+l.scrollLeft-c.x-h.x,y:s.top+l.scrollTop-c.y-h.y,width:s.width,height:s.height}}function Je(e){return"static"===T(e).position}function Xe(e,t){if(!p(e)||"fixed"===T(e).position)return null;if(t)return t(e);let n=e.offsetParent;return d(e)===n&&(n=n.ownerDocument.body),n}function Ye(e,t){const n=c(e);if(x(e))return n;if(!p(e)){let t=N(e);for(;t&&!R(t);){if(h(t)&&!Je(t))return t;t=N(t)}return n}let o=Xe(e,t);for(;o&&b(o)&&Je(o);)o=Xe(o,t);return o&&R(o)&&Je(o)&&!E(o)?n:o||function(e){let t=N(e);for(;p(t)&&!R(t);){if(E(t))return t;if(x(t))return null;t=N(t)}return null}(e)||n}const Qe={convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{elements:t,rect:n,offsetParent:o,strategy:r}=e;const i="fixed"===r,s=d(o),l=!!t&&x(t.floating);if(o===s||l&&i)return n;let c={scrollLeft:0,scrollTop:0},u=Z(1);const h=Z(0),f=p(o);if((f||!f&&!i)&&(("body"!==a(o)||g(s))&&(c=j(o)),p(o))){const e=Fe(o);u=Ve(o),h.x=e.x+o.clientLeft,h.y=e.y+o.clientTop}const m=!s||f||i?Z(0):We(s,c);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-c.scrollLeft*u.x+h.x+m.x,y:n.y*u.y-c.scrollTop*u.y+h.y+m.y}},getDocumentElement:d,getClippingRect:function(e){let{element:t,boundary:n,rootBoundary:o,strategy:r}=e;const i=[..."clippingAncestors"===n?x(t)?[]:function(e,t){const n=t.get(e);if(n)return n;let o=O(e,[],!1).filter(e=>h(e)&&"body"!==a(e)),r=null;const i="fixed"===T(e).position;let s=i?N(e):e;for(;h(s)&&!R(s);){const t=T(s),n=E(s);n||"fixed"!==t.position||(r=null),(i?!n&&!r:!n&&"static"===t.position&&r&&qe.has(r.position)||g(s)&&!n&&Ke(e,s))?o=o.filter(e=>e!==s):r=t,s=N(s)}return t.set(e,o),o}(t,this._c):[].concat(n),o],s=i[0],l=i.reduce((e,n)=>{const o=Ge(t,n,r);return e.top=q(o.top,e.top),e.right=W(o.right,e.right),e.bottom=W(o.bottom,e.bottom),e.left=q(o.left,e.left),e},Ge(t,s,r));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}},getOffsetParent:Ye,getElementRects:async function(e){const t=this.getOffsetParent||Ye,n=this.getDimensions,o=await n(e.floating);return{reference:Ze(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(e){return Array.from(e.getClientRects())},getDimensions:function(e){const{width:t,height:n}=Be(e);return{width:t,height:n}},getScale:Ve,isElement:h,isRTL:function(e){return"rtl"===T(e).direction}};function et(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function tt(e,t,n,o){void 0===o&&(o={});const{ancestorScroll:r=!0,ancestorResize:i=!0,elementResize:s="function"==typeof ResizeObserver,layoutShift:l="function"==typeof IntersectionObserver,animationFrame:a=!1}=o,c=He(e),u=r||i?[...c?O(c):[],...O(t)]:[];u.forEach(e=>{r&&e.addEventListener("scroll",n,{passive:!0}),i&&e.addEventListener("resize",n)});const h=c&&l?function(e,t){let n,o=null;const r=d(e);function i(){var e;clearTimeout(n),null==(e=o)||e.disconnect(),o=null}return function s(l,a){void 0===l&&(l=!1),void 0===a&&(a=1),i();const c=e.getBoundingClientRect(),{left:d,top:u,width:h,height:p}=c;if(l||t(),!h||!p)return;const f={rootMargin:-K(u)+"px "+-K(r.clientWidth-(d+h))+"px "+-K(r.clientHeight-(u+p))+"px "+-K(d)+"px",threshold:q(0,W(1,a))||1};let m=!0;function g(t){const o=t[0].intersectionRatio;if(o!==a){if(!m)return s();o?s(!1,o):n=setTimeout(()=>{s(!1,1e-7)},1e3)}1!==o||et(c,e.getBoundingClientRect())||s(),m=!1}try{o=new IntersectionObserver(g,{...f,root:r.ownerDocument})}catch(y){o=new IntersectionObserver(g,f)}o.observe(e)}(!0),i}(c,n):null;let p,f=-1,m=null;s&&(m=new ResizeObserver(e=>{let[o]=e;o&&o.target===c&&m&&(m.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;null==(e=m)||e.observe(t)})),n()}),c&&!a&&m.observe(c),m.observe(t));let g=a?Fe(e):null;return a&&function t(){const o=Fe(e);g&&!et(g,o)&&n();g=o,p=requestAnimationFrame(t)}(),n(),()=>{var e;u.forEach(e=>{r&&e.removeEventListener("scroll",n),i&&e.removeEventListener("resize",n)}),null==h||h(),null==(e=m)||e.disconnect(),m=null,a&&cancelAnimationFrame(p)}}const nt=function(e){return void 0===e&&(e=0),{name:"offset",options:e,async fn(t){var n,o;const{x:r,y:i,placement:s,middlewareData:l}=t,a=await async function(e,t){const{placement:n,platform:o,elements:r}=e,i=await(null==o.isRTL?void 0:o.isRTL(r.floating)),s=ee(n),l=te(n),a="y"===ie(n),c=De.has(s)?-1:1,d=i&&a?-1:1,u=Q(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:f}="number"==typeof u?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return l&&"number"==typeof f&&(p="end"===l?-1*f:f),a?{x:p*d,y:h*c}:{x:h*c,y:p*d}}(t,e);return s===(null==(n=l.offset)?void 0:n.placement)&&null!=(o=l.arrow)&&o.alignmentOffset?{}:{x:r+a.x,y:i+a.y,data:{...a,placement:s}}}}},ot=function(e){return void 0===e&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:o,placement:r}=t,{mainAxis:i=!0,crossAxis:s=!1,limiter:l={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...a}=Q(e,t),c={x:n,y:o},d=await Ie(t,a),u=ie(ee(r)),h=ne(u);let p=c[h],f=c[u];if(i){const e="y"===h?"bottom":"right";p=Y(p+d["y"===h?"top":"left"],p,p-d[e])}if(s){const e="y"===u?"bottom":"right";f=Y(f+d["y"===u?"top":"left"],f,f-d[e])}const m=l.fn({...t,[h]:p,[u]:f});return{...m,data:{x:m.x-n,y:m.y-o,enabled:{[h]:i,[u]:s}}}}}},rt=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(t){var n,o;const{placement:r,middlewareData:i,rects:s,initialPlacement:l,platform:a,elements:c}=t,{mainAxis:d=!0,crossAxis:u=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=Q(e,t);if(null!=(n=i.arrow)&&n.alignmentOffset)return{};const y=ee(r),b=ie(l),v=ee(l)===l,x=await(null==a.isRTL?void 0:a.isRTL(c.floating)),w=h||(v||!m?[pe(l)]:function(e){const t=pe(e);return[le(e),t,le(t)]}(l)),k="none"!==f;!h&&k&&w.push(...he(l,m,f,x));const C=[l,...w],E=await Ie(t,g),S=[];let M=(null==(o=i.flip)?void 0:o.overflows)||[];if(d&&S.push(E[y]),u){const e=function(e,t,n){void 0===n&&(n=!1);const o=te(e),r=se(e),i=oe(r);let s="x"===r?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return t.reference[i]>t.floating[i]&&(s=pe(s)),[s,pe(s)]}(r,s,x);S.push(E[e[0]],E[e[1]])}if(M=[...M,{placement:r,overflows:S}],!S.every(e=>e<=0)){var R,T;const e=((null==(R=i.flip)?void 0:R.index)||0)+1,t=C[e];if(t){if(!("alignment"===u&&b!==ie(t))||M.every(e=>ie(e.placement)!==b||e.overflows[0]>0))return{data:{index:e,overflows:M},reset:{placement:t}}}let n=null==(T=M.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0])?void 0:T.placement;if(!n)switch(p){case"bestFit":{var j;const e=null==(j=M.filter(e=>{if(k){const t=ie(e.placement);return t===b||"y"===t}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0])?void 0:j[0];e&&(n=e);break}case"initialPlacement":n=l}if(r!==n)return{reset:{placement:n}}}return{}}}},it=function(e){return void 0===e&&(e={}),{name:"size",options:e,async fn(t){var n,o;const{placement:r,rects:i,platform:s,elements:l}=t,{apply:a=()=>{},...c}=Q(e,t),d=await Ie(t,c),u=ee(r),h=te(r),p="y"===ie(r),{width:f,height:m}=i.floating;let g,y;"top"===u||"bottom"===u?(g=u,y=h===(await(null==s.isRTL?void 0:s.isRTL(l.floating))?"start":"end")?"left":"right"):(y=u,g="end"===h?"top":"bottom");const b=m-d.top-d.bottom,v=f-d.left-d.right,x=W(m-d[g],b),w=W(f-d[y],v),k=!t.middlewareData.shift;let C=x,E=w;if(null!=(n=t.middlewareData.shift)&&n.enabled.x&&(E=v),null!=(o=t.middlewareData.shift)&&o.enabled.y&&(C=b),k&&!h){const e=q(d.left,0),t=q(d.right,0),n=q(d.top,0),o=q(d.bottom,0);p?E=f-2*(0!==e||0!==t?e+t:q(d.left,d.right)):C=m-2*(0!==n||0!==o?n+o:q(d.top,d.bottom))}await a({...t,availableWidth:E,availableHeight:C});const S=await s.getDimensions(l.floating);return f!==S.width||m!==S.height?{reset:{rects:!0}}:{}}}},st=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:o,placement:r,rects:i,platform:s,elements:l,middlewareData:a}=t,{element:c,padding:d=0}=Q(e,t)||{};if(null==c)return{};const u=fe(d),h={x:n,y:o},p=se(r),f=oe(p),m=await s.getDimensions(c),g="y"===p,y=g?"top":"left",b=g?"bottom":"right",v=g?"clientHeight":"clientWidth",x=i.reference[f]+i.reference[p]-h[p]-i.floating[f],w=h[p]-i.reference[p],k=await(null==s.getOffsetParent?void 0:s.getOffsetParent(c));let C=k?k[v]:0;C&&await(null==s.isElement?void 0:s.isElement(k))||(C=l.floating[v]||i.floating[f]);const E=x/2-w/2,S=C/2-m[f]/2-1,M=W(u[y],S),R=W(u[b],S),T=M,j=C-m[f]-R,N=C/2-m[f]/2+E,A=Y(T,N,j),O=!a.arrow&&null!=te(r)&&N!==A&&i.reference[f]/2-(N<T?M:R)-m[f]/2<0,_=O?N<T?N-T:N-j:0;return{[p]:h[p]+_,data:{[p]:A,centerOffset:N-A-_,...O&&{alignmentOffset:_}},reset:O}}}),lt=function(e){return void 0===e&&(e={}),{name:"inline",options:e,async fn(t){const{placement:n,elements:o,rects:r,platform:i,strategy:s}=t,{padding:l=2,x:a,y:c}=Q(e,t),d=Array.from(await(null==i.getClientRects?void 0:i.getClientRects(o.reference))||[]),u=function(e){const t=e.slice().sort((e,t)=>e.y-t.y),n=[];let o=null;for(let r=0;r<t.length;r++){const e=t[r];!o||e.y-o.y>o.height/2?n.push([e]):n[n.length-1].push(e),o=e}return n.map(e=>me(Le(e)))}(d),h=me(Le(d)),p=fe(l);const f=await i.getElementRects({reference:{getBoundingClientRect:function(){if(2===u.length&&u[0].left>u[1].right&&null!=a&&null!=c)return u.find(e=>a>e.left-p.left&&a<e.right+p.right&&c>e.top-p.top&&c<e.bottom+p.bottom)||h;if(u.length>=2){if("y"===ie(n)){const e=u[0],t=u[u.length-1],o="top"===ee(n),r=e.top,i=t.bottom,s=o?e.left:t.left,l=o?e.right:t.right;return{top:r,bottom:i,left:s,right:l,width:l-s,height:i-r,x:s,y:r}}const e="left"===ee(n),t=q(...u.map(e=>e.right)),o=W(...u.map(e=>e.left)),r=u.filter(n=>e?n.left===o:n.right===t),i=r[0].top,s=r[r.length-1].bottom;return{top:i,bottom:s,left:o,right:t,width:t-o,height:s-i,x:o,y:i}}return h}},floating:o.floating,strategy:s});return r.reference.x!==f.reference.x||r.reference.y!==f.reference.y||r.reference.width!==f.reference.width||r.reference.height!==f.reference.height?{reset:{rects:f}}:{}}}},at=function(e){return void 0===e&&(e={}),{options:e,fn(t){const{x:n,y:o,placement:r,rects:i,middlewareData:s}=t,{offset:l=0,mainAxis:a=!0,crossAxis:c=!0}=Q(e,t),d={x:n,y:o},u=ie(r),h=ne(u);let p=d[h],f=d[u];const m=Q(l,t),g="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(a){const e="y"===h?"height":"width",t=i.reference[h]-i.floating[e]+g.mainAxis,n=i.reference[h]+i.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(c){var y,b;const e="y"===h?"width":"height",t=De.has(ee(r)),n=i.reference[u]-i.floating[e]+(t&&(null==(y=s.offset)?void 0:y[u])||0)+(t?0:g.crossAxis),o=i.reference[u]+i.reference[e]+(t?0:(null==(b=s.offset)?void 0:b[u])||0)-(t?g.crossAxis:0);f<n?f=n:f>o&&(f=o)}return{[h]:p,[u]:f}}}},ct=(e,t,n)=>{const o=new Map,r={platform:Qe,...n},i={...r.platform,_c:o};return(async(e,t,n)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:s}=n,l=i.filter(Boolean),a=await(null==s.isRTL?void 0:s.isRTL(t));let c=await s.getElementRects({reference:e,floating:t,strategy:r}),{x:d,y:u}=Pe(c,o,a),h=o,p={},f=0;for(let m=0;m<l.length;m++){const{name:n,fn:i}=l[m],{x:g,y:y,data:b,reset:v}=await i({x:d,y:u,initialPlacement:o,placement:h,strategy:r,middlewareData:p,rects:c,platform:s,elements:{reference:e,floating:t}});d=null!=g?g:d,u=null!=y?y:u,p={...p,[n]:{...p[n],...b}},v&&f<=50&&(f++,"object"==typeof v&&(v.placement&&(h=v.placement),v.rects&&(c=!0===v.rects?await s.getElementRects({reference:e,floating:t,strategy:r}):v.rects),({x:d,y:u}=Pe(c,h,a))),m=-1)}return{x:d,y:u,placement:h,strategy:r,middlewareData:p}})(e,t,{...r,platform:i})};var dt="undefined"!=typeof document?n.useLayoutEffect:function(){};function ut(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if("function"==typeof e&&e.toString()===t.toString())return!0;let n,o,r;if(e&&t&&"object"==typeof e){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(o=n;0!==o--;)if(!ut(e[o],t[o]))return!1;return!0}if(r=Object.keys(e),n=r.length,n!==Object.keys(t).length)return!1;for(o=n;0!==o--;)if(!{}.hasOwnProperty.call(t,r[o]))return!1;for(o=n;0!==o--;){const n=r[o];if(("_owner"!==n||!e.$$typeof)&&!ut(e[n],t[n]))return!1}return!0}return e!=e&&t!=t}function ht(e){if("undefined"==typeof window)return 1;return(e.ownerDocument.defaultView||window).devicePixelRatio||1}function pt(e,t){const n=ht(e);return Math.round(t*n)/n}function ft(e){const t=s.useRef(e);return dt(()=>{t.current=e}),t}const mt=e=>({name:"arrow",options:e,fn(t){const{element:n,padding:o}="function"==typeof e?e(t):e;return n&&(r=n,{}.hasOwnProperty.call(r,"current"))?null!=n.current?st({element:n.current,padding:o}).fn(t):{}:n?st({element:n,padding:o}).fn(t):{};var r}}),gt=(e,t)=>({...nt(e),options:[e,t]}),yt=(e,t)=>({...ot(e),options:[e,t]}),bt=(e,t)=>({...at(e),options:[e,t]}),vt=(e,t)=>({...rt(e),options:[e,t]}),xt=(e,t)=>({...it(e),options:[e,t]}),wt=(e,t)=>({...lt(e),options:[e,t]}),kt=(e,t)=>({...mt(e),options:[e,t]}),Ct={...s},Et=Ct.useInsertionEffect||(e=>e());function St(e){const t=s.useRef(()=>{if("production"!==process.env.NODE_ENV)throw new Error("Cannot call an event handler while rendering.")});return Et(()=>{t.current=e}),s.useCallback(function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];return null==t.current?void 0:t.current(...n)},[])}var Mt="undefined"!=typeof document?n.useLayoutEffect:n.useEffect;function Rt(){return Rt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Rt.apply(this,arguments)}let Tt=!1,jt=0;const Nt=()=>"floating-ui-"+Math.random().toString(36).slice(2,6)+jt++;const At=Ct.useId||function(){const[e,t]=s.useState(()=>Tt?Nt():void 0);return Mt(()=>{null==e&&t(Nt())},[]),s.useEffect(()=>{Tt=!0},[]),e};let Ot;"production"!==process.env.NODE_ENV&&(Ot=new Set);const _t=s.createContext(null),Pt=s.createContext(null),It=()=>{var e;return(null==(e=s.useContext(_t))?void 0:e.id)||null},Lt=()=>s.useContext(Pt);function Dt(e){return"data-floating-ui-"+e}function Bt(e){const t=n.useRef(e);return Mt(()=>{t.current=e}),t}const Ht=Dt("safe-polygon");function Vt(e,t,n){return n&&!$(n)?0:"number"==typeof e?e:null==e?void 0:e[t]}function $t(e,t){void 0===t&&(t={});const{open:n,onOpenChange:o,dataRef:r,events:i,elements:l}=e,{enabled:a=!0,delay:c=0,handleClose:d=null,mouseOnly:u=!1,restMs:p=0,move:f=!0}=t,m=Lt(),g=It(),y=Bt(d),b=Bt(c),v=Bt(n),x=s.useRef(),w=s.useRef(-1),k=s.useRef(),C=s.useRef(-1),E=s.useRef(!0),S=s.useRef(!1),M=s.useRef(()=>{}),R=s.useRef(!1),T=s.useCallback(()=>{var e;const t=null==(e=r.current.openEvent)?void 0:e.type;return(null==t?void 0:t.includes("mouse"))&&"mousedown"!==t},[r]);s.useEffect(()=>{if(a)return i.on("openchange",e),()=>{i.off("openchange",e)};function e(e){let{open:t}=e;t||(clearTimeout(w.current),clearTimeout(C.current),E.current=!0,R.current=!1)}},[a,i]),s.useEffect(()=>{if(!a)return;if(!y.current)return;if(!n)return;function e(e){T()&&o(!1,e,"hover")}const t=z(l.floating).documentElement;return t.addEventListener("mouseleave",e),()=>{t.removeEventListener("mouseleave",e)}},[l.floating,n,o,a,y,T]);const j=s.useCallback(function(e,t,n){void 0===t&&(t=!0),void 0===n&&(n="hover");const r=Vt(b.current,"close",x.current);r&&!k.current?(clearTimeout(w.current),w.current=window.setTimeout(()=>o(!1,e,n),r)):t&&(clearTimeout(w.current),o(!1,e,n))},[b,o]),N=St(()=>{M.current(),k.current=void 0}),A=St(()=>{if(S.current){const e=z(l.floating).body;e.style.pointerEvents="",e.removeAttribute(Ht),S.current=!1}}),O=St(()=>!!r.current.openEvent&&["click","mousedown"].includes(r.current.openEvent.type));s.useEffect(()=>{if(a&&h(l.domReference)){var e;const o=l.domReference;return n&&o.addEventListener("mouseleave",s),null==(e=l.floating)||e.addEventListener("mouseleave",s),f&&o.addEventListener("mousemove",t,{once:!0}),o.addEventListener("mouseenter",t),o.addEventListener("mouseleave",i),()=>{var e;n&&o.removeEventListener("mouseleave",s),null==(e=l.floating)||e.removeEventListener("mouseleave",s),f&&o.removeEventListener("mousemove",t),o.removeEventListener("mouseenter",t),o.removeEventListener("mouseleave",i)}}function t(e){if(clearTimeout(w.current),E.current=!1,u&&!$(x.current)||p>0&&!Vt(b.current,"open"))return;const t=Vt(b.current,"open",x.current);t?w.current=window.setTimeout(()=>{v.current||o(!0,e,"hover")},t):n||o(!0,e,"hover")}function i(e){if(O())return;M.current();const t=z(l.floating);if(clearTimeout(C.current),R.current=!1,y.current&&r.current.floatingContext){n||clearTimeout(w.current),k.current=y.current({...r.current.floatingContext,tree:m,x:e.clientX,y:e.clientY,onClose(){A(),N(),O()||j(e,!0,"safe-polygon")}});const o=k.current;return t.addEventListener("mousemove",o),void(M.current=()=>{t.removeEventListener("mousemove",o)})}("touch"!==x.current||!I(l.floating,e.relatedTarget))&&j(e)}function s(e){O()||r.current.floatingContext&&(null==y.current||y.current({...r.current.floatingContext,tree:m,x:e.clientX,y:e.clientY,onClose(){A(),N(),O()||j(e)}})(e))}},[l,a,e,u,p,f,j,N,A,o,n,v,m,b,y,r,O]),Mt(()=>{var e;if(a&&n&&null!=(e=y.current)&&e.__options.blockPointerEvents&&T()){S.current=!0;const e=l.floating;if(h(l.domReference)&&e){var t;const n=z(l.floating).body;n.setAttribute(Ht,"");const o=l.domReference,r=null==m||null==(t=m.nodesRef.current.find(e=>e.id===g))||null==(t=t.context)?void 0:t.elements.floating;return r&&(r.style.pointerEvents=""),n.style.pointerEvents="none",o.style.pointerEvents="auto",e.style.pointerEvents="auto",()=>{n.style.pointerEvents="",o.style.pointerEvents="",e.style.pointerEvents=""}}}},[a,n,g,l,m,y,T]),Mt(()=>{n||(x.current=void 0,R.current=!1,N(),A())},[n,N,A]),s.useEffect(()=>()=>{N(),clearTimeout(w.current),clearTimeout(C.current),A()},[a,l.domReference,N,A]);const _=s.useMemo(()=>{function e(e){x.current=e.pointerType}return{onPointerDown:e,onPointerEnter:e,onMouseMove(e){const{nativeEvent:t}=e;function r(){E.current||v.current||o(!0,t,"hover")}u&&!$(x.current)||n||0===p||R.current&&e.movementX**2+e.movementY**2<2||(clearTimeout(C.current),"touch"===x.current?r():(R.current=!0,C.current=window.setTimeout(r,p)))}}},[u,o,n,v,p]),P=s.useMemo(()=>({onMouseEnter(){clearTimeout(w.current)},onMouseLeave(e){O()||j(e.nativeEvent,!1)}}),[j,O]);return s.useMemo(()=>a?{reference:_,floating:P}:{},[a,_,P])}const zt=()=>{},Ft=s.createContext({delay:0,initialDelay:0,timeoutMs:0,currentId:null,setCurrentId:zt,setState:zt,isInstantPhase:!1});function Ut(e){const{children:t,delay:n,timeoutMs:o=0}=e,[r,i]=s.useReducer((e,t)=>({...e,...t}),{delay:n,timeoutMs:o,initialDelay:n,currentId:null,isInstantPhase:!1}),l=s.useRef(null),a=s.useCallback(e=>{i({currentId:e})},[]);return Mt(()=>{r.currentId?null===l.current?l.current=r.currentId:r.isInstantPhase||i({isInstantPhase:!0}):(r.isInstantPhase&&i({isInstantPhase:!1}),l.current=null)},[r.currentId,r.isInstantPhase]),s.createElement(Ft.Provider,{value:s.useMemo(()=>({...r,setState:i,setCurrentId:a}),[r,a])},t)}function Wt(e,t){void 0===t&&(t={});const{open:n,onOpenChange:o,floatingId:r}=e,{id:i,enabled:l=!0}=t,a=null!=i?i:r,c=s.useContext(Ft),{currentId:d,setCurrentId:u,initialDelay:h,setState:p,timeoutMs:f}=c;return Mt(()=>{l&&d&&(p({delay:{open:1,close:Vt(h,"close")}}),d!==a&&o(!1))},[l,a,o,p,d,h]),Mt(()=>{function e(){o(!1),p({delay:h,currentId:null})}if(l&&d&&!n&&d===a){if(f){const t=window.setTimeout(e,f);return()=>{clearTimeout(t)}}e()}},[l,n,p,d,a,o,h,f]),Mt(()=>{l&&u!==zt&&n&&u(a)},[l,n,u,a]),c}function qt(e,t){let n=e.filter(e=>{var n;return e.parentId===t&&(null==(n=e.context)?void 0:n.open)}),o=n;for(;o.length;)o=e.filter(e=>{var t;return null==(t=o)?void 0:t.some(t=>{var n;return e.parentId===t.id&&(null==(n=e.context)?void 0:n.open)})}),n=n.concat(o);return n}const Gt=()=>({getShadowRoot:!0,displayCheck:"function"==typeof ResizeObserver&&ResizeObserver.toString().includes("[native code]")?"full":"none"});function Kt(e,t){const n=_e(e,Gt());"prev"===t&&n.reverse();const o=n.indexOf(P(z(e)));return n.slice(o+1)[0]}function Zt(e,t){const n=t||e.currentTarget,o=e.relatedTarget;return!o||!I(n,o)}function Jt(e){_e(e,Gt()).forEach(e=>{e.dataset.tabindex=e.getAttribute("tabindex")||"",e.setAttribute("tabindex","-1")})}function Xt(e){e.querySelectorAll("[data-tabindex]").forEach(e=>{const t=e.dataset.tabindex;delete e.dataset.tabindex,t?e.setAttribute("tabindex",t):e.removeAttribute("tabindex")})}const Yt={border:0,clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"fixed",whiteSpace:"nowrap",width:"1px",top:0,left:0};function Qt(e){"Tab"===e.key&&(e.target,clearTimeout(undefined))}const en=s.forwardRef(function(e,t){const[n,o]=s.useState();Mt(()=>(H()&&o("button"),document.addEventListener("keydown",Qt),()=>{document.removeEventListener("keydown",Qt)}),[]);const r={ref:t,tabIndex:0,role:n,"aria-hidden":!n||void 0,[Dt("focus-guard")]:"",style:Yt};return s.createElement("span",Rt({},e,r))}),tn=s.createContext(null),nn=Dt("portal");function on(e){const{children:t,id:n,root:o,preserveTabOrder:r=!0}=e,l=function(e){void 0===e&&(e={});const{id:t,root:n}=e,o=At(),r=rn(),[i,l]=s.useState(null),a=s.useRef(null);return Mt(()=>()=>{null==i||i.remove(),queueMicrotask(()=>{a.current=null})},[i]),Mt(()=>{if(!o)return;if(a.current)return;const e=t?document.getElementById(t):null;if(!e)return;const n=document.createElement("div");n.id=o,n.setAttribute(nn,""),e.appendChild(n),a.current=n,l(n)},[t,o]),Mt(()=>{if(null===n)return;if(!o)return;if(a.current)return;let e=n||(null==r?void 0:r.portalNode);e&&!h(e)&&(e=e.current),e=e||document.body;let i=null;t&&(i=document.createElement("div"),i.id=t,e.appendChild(i));const s=document.createElement("div");s.id=o,s.setAttribute(nn,""),e=i||e,e.appendChild(s),a.current=s,l(s)},[t,n,o,r]),i}({id:n,root:o}),[a,c]=s.useState(null),d=s.useRef(null),u=s.useRef(null),p=s.useRef(null),f=s.useRef(null),m=null==a?void 0:a.modal,g=null==a?void 0:a.open,y=!!a&&!a.modal&&a.open&&r&&!(!o&&!l);return s.useEffect(()=>{if(l&&r&&!m)return l.addEventListener("focusin",e,!0),l.addEventListener("focusout",e,!0),()=>{l.removeEventListener("focusin",e,!0),l.removeEventListener("focusout",e,!0)};function e(e){if(l&&Zt(e)){("focusin"===e.type?Xt:Jt)(l)}}},[l,r,m]),s.useEffect(()=>{l&&(g||Xt(l))},[g,l]),s.createElement(tn.Provider,{value:s.useMemo(()=>({preserveTabOrder:r,beforeOutsideRef:d,afterOutsideRef:u,beforeInsideRef:p,afterInsideRef:f,portalNode:l,setFocusManagerState:c}),[r,l])},y&&l&&s.createElement(en,{"data-type":"outside",ref:d,onFocus:e=>{if(Zt(e,l)){var t;null==(t=p.current)||t.focus()}else{const e=Kt(document.body,"prev")||(null==a?void 0:a.refs.domReference.current);null==e||e.focus()}}}),y&&l&&s.createElement("span",{"aria-owns":l.id,style:Yt}),l&&i.createPortal(t,l),y&&l&&s.createElement(en,{"data-type":"outside",ref:u,onFocus:e=>{if(Zt(e,l)){var t;null==(t=f.current)||t.focus()}else{const t=Kt(document.body,"next")||(null==a?void 0:a.refs.domReference.current);null==t||t.focus(),(null==a?void 0:a.closeOnFocusOut)&&(null==a||a.onOpenChange(!1,e.nativeEvent,"focus-out"))}}}))}const rn=()=>s.useContext(tn),sn="data-floating-ui-focusable",ln={pointerdown:"onPointerDown",mousedown:"onMouseDown",click:"onClick"},an={pointerdown:"onPointerDownCapture",mousedown:"onMouseDownCapture",click:"onClickCapture"},cn=e=>{var t,n;return{escapeKey:"boolean"==typeof e?e:null!=(t=null==e?void 0:e.escapeKey)&&t,outsidePress:"boolean"==typeof e?e:null==(n=null==e?void 0:e.outsidePress)||n}};function dn(e,t){void 0===t&&(t={});const{open:n,onOpenChange:o,elements:r,dataRef:i}=e,{enabled:l=!0,escapeKey:a=!0,outsidePress:c=!0,outsidePressEvent:d="pointerdown",referencePress:u=!1,referencePressEvent:f="pointerdown",ancestorScroll:m=!1,bubbles:g,capture:y}=t,b=Lt(),v=St("function"==typeof c?c:()=>!1),x="function"==typeof c?v:c,w=s.useRef(!1),k=s.useRef(!1),{escapeKey:C,outsidePress:E}=cn(g),{escapeKey:M,outsidePress:j}=cn(y),A=s.useRef(!1),_=St(e=>{var t;if(!n||!l||!a||"Escape"!==e.key)return;if(A.current)return;const r=null==(t=i.current.floatingContext)?void 0:t.nodeId,s=b?qt(b.nodesRef.current,r):[];if(!C&&(e.stopPropagation(),s.length>0)){let e=!0;if(s.forEach(t=>{var n;null==(n=t.context)||!n.open||t.context.dataRef.current.__escapeKeyBubbles||(e=!1)}),!e)return}o(!1,function(e){return"nativeEvent"in e}(e)?e.nativeEvent:e,"escape-key")}),P=St(e=>{var t;const n=()=>{var t;_(e),null==(t=U(e))||t.removeEventListener("keydown",n)};null==(t=U(e))||t.addEventListener("keydown",n)}),L=St(e=>{var t;const n=w.current;w.current=!1;const s=k.current;if(k.current=!1,"click"===d&&s)return;if(n)return;if("function"==typeof x&&!x(e))return;const l=U(e),a="["+Dt("inert")+"]",c=z(r.floating).querySelectorAll(a);let u=h(l)?l:null;for(;u&&!R(u);){const e=N(u);if(R(e)||!h(e))break;u=e}if(c.length&&h(l)&&!l.matches("html,body")&&!I(l,r.floating)&&Array.from(c).every(e=>!I(u,e)))return;if(p(l)&&H){const t=l.clientWidth>0&&l.scrollWidth>l.clientWidth,n=l.clientHeight>0&&l.scrollHeight>l.clientHeight;let o=n&&e.offsetX>l.clientWidth;if(n){"rtl"===T(l).direction&&(o=e.offsetX<=l.offsetWidth-l.clientWidth)}if(o||t&&e.offsetY>l.clientHeight)return}const f=null==(t=i.current.floatingContext)?void 0:t.nodeId,m=b&&qt(b.nodesRef.current,f).some(t=>{var n;return F(e,null==(n=t.context)?void 0:n.elements.floating)});if(F(e,r.floating)||F(e,r.domReference)||m)return;const g=b?qt(b.nodesRef.current,f):[];if(g.length>0){let e=!0;if(g.forEach(t=>{var n;null==(n=t.context)||!n.open||t.context.dataRef.current.__outsidePressBubbles||(e=!1)}),!e)return}o(!1,e,"outside-press")}),D=St(e=>{var t;const n=()=>{var t;L(e),null==(t=U(e))||t.removeEventListener(d,n)};null==(t=U(e))||t.addEventListener(d,n)});s.useEffect(()=>{if(!n||!l)return;i.current.__escapeKeyBubbles=C,i.current.__outsidePressBubbles=E;let e=-1;function t(e){o(!1,e,"ancestor-scroll")}function s(){window.clearTimeout(e),A.current=!0}function c(){e=window.setTimeout(()=>{A.current=!1},S()?5:0)}const u=z(r.floating);a&&(u.addEventListener("keydown",M?P:_,M),u.addEventListener("compositionstart",s),u.addEventListener("compositionend",c)),x&&u.addEventListener(d,j?D:L,j);let p=[];return m&&(h(r.domReference)&&(p=O(r.domReference)),h(r.floating)&&(p=p.concat(O(r.floating))),!h(r.reference)&&r.reference&&r.reference.contextElement&&(p=p.concat(O(r.reference.contextElement)))),p=p.filter(e=>{var t;return e!==(null==(t=u.defaultView)?void 0:t.visualViewport)}),p.forEach(e=>{e.addEventListener("scroll",t,{passive:!0})}),()=>{a&&(u.removeEventListener("keydown",M?P:_,M),u.removeEventListener("compositionstart",s),u.removeEventListener("compositionend",c)),x&&u.removeEventListener(d,j?D:L,j),p.forEach(e=>{e.removeEventListener("scroll",t)}),window.clearTimeout(e)}},[i,r,a,x,d,n,o,m,l,C,E,_,M,P,L,j,D]),s.useEffect(()=>{w.current=!1},[x,d]);const B=s.useMemo(()=>({onKeyDown:_,[ln[f]]:e=>{u&&o(!1,e.nativeEvent,"reference-press")}}),[_,o,u,f]),H=s.useMemo(()=>({onKeyDown:_,onMouseDown(){k.current=!0},onMouseUp(){k.current=!0},[an[d]]:()=>{w.current=!0}}),[_,d]);return s.useMemo(()=>l?{reference:B,floating:H}:{},[l,B,H])}function un(e){const{open:t=!1,onOpenChange:n,elements:o}=e,r=At(),i=s.useRef({}),[l]=s.useState(()=>function(){const e=new Map;return{emit(t,n){var o;null==(o=e.get(t))||o.forEach(e=>e(n))},on(t,n){e.set(t,[...e.get(t)||[],n])},off(t,n){var o;e.set(t,(null==(o=e.get(t))?void 0:o.filter(e=>e!==n))||[])}}}()),a=null!=It();if("production"!==process.env.NODE_ENV){const e=o.reference;e&&!h(e)&&function(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];const r="Floating UI: "+n.join(" ");var i;null!=(e=Ot)&&e.has(r)||null==(i=Ot)||i.add(r)}("Cannot pass a virtual element to the `elements.reference` option,","as it must be a real DOM element. Use `refs.setPositionReference()`","instead.")}const[c,d]=s.useState(o.reference),u=St((e,t,o)=>{i.current.openEvent=e?t:void 0,l.emit("openchange",{open:e,event:t,reason:o,nested:a}),null==n||n(e,t,o)}),p=s.useMemo(()=>({setPositionReference:d}),[]),f=s.useMemo(()=>({reference:c||o.reference||null,floating:o.floating||null,domReference:o.reference}),[c,o.reference,o.floating]);return s.useMemo(()=>({dataRef:i,open:t,onOpenChange:u,elements:f,events:l,floatingId:r,refs:p}),[t,u,f,l,r,p])}function hn(e){void 0===e&&(e={});const{nodeId:t}=e,n=un({...e,elements:{reference:null,floating:null,...e.elements}}),o=e.rootContext||n,r=o.elements,[l,a]=s.useState(null),[c,d]=s.useState(null),u=(null==r?void 0:r.domReference)||l,p=s.useRef(null),f=Lt();Mt(()=>{u&&(p.current=u)},[u]);const m=function(e){void 0===e&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:o=[],platform:r,elements:{reference:l,floating:a}={},transform:c=!0,whileElementsMounted:d,open:u}=e,[h,p]=s.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,m]=s.useState(o);ut(f,o)||m(o);const[g,y]=s.useState(null),[b,v]=s.useState(null),x=s.useCallback(e=>{e!==E.current&&(E.current=e,y(e))},[]),w=s.useCallback(e=>{e!==S.current&&(S.current=e,v(e))},[]),k=l||g,C=a||b,E=s.useRef(null),S=s.useRef(null),M=s.useRef(h),R=null!=d,T=ft(d),j=ft(r),N=ft(u),A=s.useCallback(()=>{if(!E.current||!S.current)return;const e={placement:t,strategy:n,middleware:f};j.current&&(e.platform=j.current),ct(E.current,S.current,e).then(e=>{const t={...e,isPositioned:!1!==N.current};O.current&&!ut(M.current,t)&&(M.current=t,i.flushSync(()=>{p(t)}))})},[f,t,n,j,N]);dt(()=>{!1===u&&M.current.isPositioned&&(M.current.isPositioned=!1,p(e=>({...e,isPositioned:!1})))},[u]);const O=s.useRef(!1);dt(()=>(O.current=!0,()=>{O.current=!1}),[]),dt(()=>{if(k&&(E.current=k),C&&(S.current=C),k&&C){if(T.current)return T.current(k,C,A);A()}},[k,C,A,T,R]);const _=s.useMemo(()=>({reference:E,floating:S,setReference:x,setFloating:w}),[x,w]),P=s.useMemo(()=>({reference:k,floating:C}),[k,C]),I=s.useMemo(()=>{const e={position:n,left:0,top:0};if(!P.floating)return e;const t=pt(P.floating,h.x),o=pt(P.floating,h.y);return c?{...e,transform:"translate("+t+"px, "+o+"px)",...ht(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:t,top:o}},[n,c,P.floating,h.x,h.y]);return s.useMemo(()=>({...h,update:A,refs:_,elements:P,floatingStyles:I}),[h,A,_,P,I])}({...e,elements:{...r,...c&&{reference:c}}}),g=s.useCallback(e=>{const t=h(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),contextElement:e}:e;d(t),m.refs.setReference(t)},[m.refs]),y=s.useCallback(e=>{(h(e)||null===e)&&(p.current=e,a(e)),(h(m.refs.reference.current)||null===m.refs.reference.current||null!==e&&!h(e))&&m.refs.setReference(e)},[m.refs]),b=s.useMemo(()=>({...m.refs,setReference:y,setPositionReference:g,domReference:p}),[m.refs,y,g]),v=s.useMemo(()=>({...m.elements,domReference:u}),[m.elements,u]),x=s.useMemo(()=>({...m,...o,refs:b,elements:v,nodeId:t}),[m,b,v,t,o]);return Mt(()=>{o.dataRef.current.floatingContext=x;const e=null==f?void 0:f.nodesRef.current.find(e=>e.id===t);e&&(e.context=x)}),s.useMemo(()=>({...m,context:x,refs:b,elements:v}),[m,b,v,x])}function pn(e,t){void 0===t&&(t={});const{open:n,onOpenChange:o,events:r,dataRef:i,elements:l}=e,{enabled:a=!0,visibleOnly:d=!0}=t,u=s.useRef(!1),f=s.useRef(),m=s.useRef(!0);s.useEffect(()=>{if(!a)return;const e=c(l.domReference);function t(){!n&&p(l.domReference)&&l.domReference===P(z(l.domReference))&&(u.current=!0)}function o(){m.current=!0}return e.addEventListener("blur",t),e.addEventListener("keydown",o,!0),()=>{e.removeEventListener("blur",t),e.removeEventListener("keydown",o,!0)}},[l.domReference,n,a]),s.useEffect(()=>{if(a)return r.on("openchange",e),()=>{r.off("openchange",e)};function e(e){let{reason:t}=e;"reference-press"!==t&&"escape-key"!==t||(u.current=!0)}},[r,a]),s.useEffect(()=>()=>{clearTimeout(f.current)},[]);const g=s.useMemo(()=>({onPointerDown(e){B(e.nativeEvent)||(m.current=!1)},onMouseLeave(){u.current=!1},onFocus(e){if(u.current)return;const t=U(e.nativeEvent);if(d&&h(t))try{if(H()&&L().toLowerCase().startsWith("mac")&&!navigator.maxTouchPoints)throw Error();if(!t.matches(":focus-visible"))return}catch(r){if(!m.current&&(!p(n=t)||!n.matches("input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])")))return}var n;o(!0,e.nativeEvent,"focus")},onBlur(e){u.current=!1;const t=e.relatedTarget,n=e.nativeEvent,r=h(t)&&t.hasAttribute(Dt("focus-guard"))&&"outside"===t.getAttribute("data-type");f.current=window.setTimeout(()=>{var e;const s=P(l.domReference?l.domReference.ownerDocument:document);(t||s!==l.domReference)&&(I(null==(e=i.current.floatingContext)?void 0:e.refs.floating.current,s)||I(l.domReference,s)||r||o(!1,n,"focus"))})}}),[i,l.domReference,o,d]);return s.useMemo(()=>a?{reference:g}:{},[a,g])}const fn="active",mn="selected";function gn(e,t,n){const o=new Map,r="item"===n;let i=e;if(r&&e){const{[fn]:t,[mn]:n,...o}=e;i=o}return{..."floating"===n&&{tabIndex:-1,[sn]:""},...i,...t.map(t=>{const o=t?t[n]:null;return"function"==typeof o?e?o(e):null:o}).concat(e).reduce((e,t)=>t?(Object.entries(t).forEach(t=>{let[n,i]=t;var s;r&&[fn,mn].includes(n)||(0===n.indexOf("on")?(o.has(n)||o.set(n,[]),"function"==typeof i&&(null==(s=o.get(n))||s.push(i),e[n]=function(){for(var e,t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];return null==(e=o.get(n))?void 0:e.map(e=>e(...r)).find(e=>void 0!==e)})):e[n]=i)}),e):e,{})}}function yn(e){void 0===e&&(e=[]);const t=e.map(e=>null==e?void 0:e.reference),n=e.map(e=>null==e?void 0:e.floating),o=e.map(e=>null==e?void 0:e.item),r=s.useCallback(t=>gn(t,e,"reference"),t),i=s.useCallback(t=>gn(t,e,"floating"),n),l=s.useCallback(t=>gn(t,e,"item"),o);return s.useMemo(()=>({getReferenceProps:r,getFloatingProps:i,getItemProps:l}),[r,i,l])}const bn=new Map([["select","listbox"],["combobox","listbox"],["label",!1]]);function vn(e,t){var n;void 0===t&&(t={});const{open:o,floatingId:r}=e,{enabled:i=!0,role:l="dialog"}=t,a=null!=(n=bn.get(l))?n:l,c=At(),d=null!=It(),u=s.useMemo(()=>"tooltip"===a||"label"===l?{["aria-"+("label"===l?"labelledby":"describedby")]:o?r:void 0}:{"aria-expanded":o?"true":"false","aria-haspopup":"alertdialog"===a?"dialog":a,"aria-controls":o?r:void 0,..."listbox"===a&&{role:"combobox"},..."menu"===a&&{id:c},..."menu"===a&&d&&{role:"menuitem"},..."select"===l&&{"aria-autocomplete":"none"},..."combobox"===l&&{"aria-autocomplete":"list"}},[a,r,d,o,c,l]),h=s.useMemo(()=>{const e={id:r,...a&&{role:a}};return"tooltip"===a||"label"===l?e:{...e,..."menu"===a&&{"aria-labelledby":c}}},[a,r,c,l]),p=s.useCallback(e=>{let{active:t,selected:n}=e;const o={role:"option",...t&&{id:r+"-option"}};switch(l){case"select":return{...o,"aria-selected":t&&n};case"combobox":return{...o,...t&&{"aria-selected":!0}}}return{}},[r,l]);return s.useMemo(()=>i?{reference:u,floating:h,item:p}:{},[i,u,h,p])}const xn=e=>e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,(e,t)=>(t?"-":"")+e.toLowerCase());function wn(e,t){return"function"==typeof e?e(t):e}function kn(e,t){void 0===t&&(t={});const{open:n,elements:{floating:o}}=e,{duration:r=250}=t,i=("number"==typeof r?r:r.close)||0,[l,a]=s.useState("unmounted"),c=function(e,t){const[n,o]=s.useState(e);return e&&!n&&o(!0),s.useEffect(()=>{if(!e&&n){const e=setTimeout(()=>o(!1),t);return()=>clearTimeout(e)}},[e,n,t]),n}(n,i);return c||"close"!==l||a("unmounted"),Mt(()=>{if(o){if(n){a("initial");const e=requestAnimationFrame(()=>{a("open")});return()=>{cancelAnimationFrame(e)}}a("close")}},[n,o]),{isMounted:c,status:l}}function Cn(e,t){void 0===t&&(t={});const{initial:n={opacity:0},open:o,close:r,common:i,duration:l=250}=t,a=e.placement,c=a.split("-")[0],d=s.useMemo(()=>({side:c,placement:a}),[c,a]),u="number"==typeof l,h=(u?l:l.open)||0,p=(u?l:l.close)||0,[f,m]=s.useState(()=>({...wn(i,d),...wn(n,d)})),{isMounted:g,status:y}=kn(e,{duration:l}),b=Bt(n),v=Bt(o),x=Bt(r),w=Bt(i);return Mt(()=>{const e=wn(b.current,d),t=wn(x.current,d),n=wn(w.current,d),o=wn(v.current,d)||Object.keys(e).reduce((e,t)=>(e[t]="",e),{});if("initial"===y&&m(t=>({transitionProperty:t.transitionProperty,...n,...e})),"open"===y&&m({transitionProperty:Object.keys(o).map(xn).join(","),transitionDuration:h+"ms",...n,...o}),"close"===y){const o=t||e;m({transitionProperty:Object.keys(o).map(xn).join(","),transitionDuration:p+"ms",...n,...o})}},[p,x,b,v,w,h,y,d]),{isMounted:g,styles:f}}function En(e){this.content=e}function Sn(e,t,n){for(let o=0;;o++){if(o==e.childCount||o==t.childCount)return e.childCount==t.childCount?null:n;let r=e.child(o),i=t.child(o);if(r!=i){if(!r.sameMarkup(i))return n;if(r.isText&&r.text!=i.text){for(let e=0;r.text[e]==i.text[e];e++)n++;return n}if(r.content.size||i.content.size){let e=Sn(r.content,i.content,n+1);if(null!=e)return e}n+=r.nodeSize}else n+=r.nodeSize}}function Mn(e,t,n,o){for(let r=e.childCount,i=t.childCount;;){if(0==r||0==i)return r==i?null:{a:n,b:o};let s=e.child(--r),l=t.child(--i),a=s.nodeSize;if(s!=l){if(!s.sameMarkup(l))return{a:n,b:o};if(s.isText&&s.text!=l.text){let e=0,t=Math.min(s.text.length,l.text.length);for(;e<t&&s.text[s.text.length-e-1]==l.text[l.text.length-e-1];)e++,n--,o--;return{a:n,b:o}}if(s.content.size||l.content.size){let e=Mn(s.content,l.content,n-1,o-1);if(e)return e}n-=a,o-=a}else n-=a,o-=a}}En.prototype={constructor:En,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-1==t?void 0:this.content[t+1]},update:function(e,t,n){var o=n&&n!=e?this.remove(n):this,r=o.find(e),i=o.content.slice();return-1==r?i.push(n||e,t):(i[r+1]=t,n&&(i[r]=n)),new En(i)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new En(n)},addToStart:function(e,t){return new En([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new En(n)},addBefore:function(e,t,n){var o=this.remove(t),r=o.content.slice(),i=o.find(e);return r.splice(-1==i?r.length:i,0,t,n),new En(r)},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=En.from(e)).size?new En(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=En.from(e)).size?new En(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=En.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},En.from=function(e){if(e instanceof En)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new En(t)};class Rn{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,o=0,r){for(let i=0,s=0;s<t;i++){let l=this.content[i],a=s+l.nodeSize;if(a>e&&!1!==n(l,o+s,r||null,i)&&l.content.size){let r=s+1;l.nodesBetween(Math.max(0,e-r),Math.min(l.content.size,t-r),n,o+r)}s=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,o){let r="",i=!0;return this.nodesBetween(e,t,(s,l)=>{let a=s.isText?s.text.slice(Math.max(e,l)-l,t-l):s.isLeaf?o?"function"==typeof o?o(s):o:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&a||s.isTextblock)&&n&&(i?i=!1:r+=n),r+=a},0),r}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,o=this.content.slice(),r=0;for(t.isText&&t.sameMarkup(n)&&(o[o.length-1]=t.withText(t.text+n.text),r=1);r<e.content.length;r++)o.push(e.content[r]);return new Rn(o,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],o=0;if(t>e)for(let r=0,i=0;i<t;r++){let s=this.content[r],l=i+s.nodeSize;l>e&&((i<e||l>t)&&(s=s.isText?s.cut(Math.max(0,e-i),Math.min(s.text.length,t-i)):s.cut(Math.max(0,e-i-1),Math.min(s.content.size,t-i-1))),n.push(s),o+=s.nodeSize),i=l}return new Rn(n,o)}cutByIndex(e,t){return e==t?Rn.empty:0==e&&t==this.content.length?this:new Rn(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let o=this.content.slice(),r=this.size+t.nodeSize-n.nodeSize;return o[e]=t,new Rn(o,r)}addToStart(e){return new Rn([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new Rn(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let o=this.content[t];e(o,n,t),n+=o.nodeSize}}findDiffStart(e,t=0){return Sn(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return Mn(this,e,t,n)}findIndex(e){if(0==e)return jn(0,e);if(e==this.size)return jn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let o=n+this.child(t).nodeSize;if(o>=e)return o==e?jn(t+1,o):jn(t,n);n=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return Rn.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new Rn(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return Rn.empty;let t,n=0;for(let o=0;o<e.length;o++){let r=e[o];n+=r.nodeSize,o&&r.isText&&e[o-1].sameMarkup(r)?(t||(t=e.slice(0,o)),t[t.length-1]=r.withText(t[t.length-1].text+r.text)):t&&t.push(r)}return new Rn(t||e,n)}static from(e){if(!e)return Rn.empty;if(e instanceof Rn)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new Rn([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}Rn.empty=new Rn([],0);const Tn={index:0,offset:0};function jn(e,t){return Tn.index=e,Tn.offset=t,Tn}function Nn(e,t){if(e===t)return!0;if(!e||"object"!=typeof e||!t||"object"!=typeof t)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(!Nn(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!Nn(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}let An=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let o=0;o<e.length;o++){let r=e[o];if(this.eq(r))return e;if(this.type.excludes(r.type))t||(t=e.slice(0,o));else{if(r.type.excludes(this.type))return e;!n&&r.type.rank>this.type.rank&&(t||(t=e.slice(0,o)),t.push(this),n=!0),t&&t.push(r)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Nn(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);let o=n.create(t.attrs);return n.checkAttrs(o.attrs),o}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)&&0==t.length)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}};An.none=[];class On extends Error{}class _n{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=In(this.content,e+this.openStart,t);return n&&new _n(n,this.openStart,this.openEnd)}removeBetween(e,t){return new _n(Pn(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return _n.empty;let n=t.openStart||0,o=t.openEnd||0;if("number"!=typeof n||"number"!=typeof o)throw new RangeError("Invalid input for Slice.fromJSON");return new _n(Rn.fromJSON(e,t.content),n,o)}static maxOpen(e,t=!0){let n=0,o=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let r=e.lastChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.lastChild)o++;return new _n(e,n,o)}}function Pn(e,t,n){let{index:o,offset:r}=e.findIndex(t),i=e.maybeChild(o),{index:s,offset:l}=e.findIndex(n);if(r==t||i.isText){if(l!=n&&!e.child(s).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(o!=s)throw new RangeError("Removing non-flat range");return e.replaceChild(o,i.copy(Pn(i.content,t-r-1,n-r-1)))}function In(e,t,n,o){let{index:r,offset:i}=e.findIndex(t),s=e.maybeChild(r);if(i==t||s.isText)return o&&!o.canReplace(r,r,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=In(s.content,t-i-1,n,s);return l&&e.replaceChild(r,s.copy(l))}function Ln(e,t,n){if(n.openStart>e.depth)throw new On("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new On("Inconsistent open depths");return Dn(e,t,n,0)}function Dn(e,t,n,o){let r=e.index(o),i=e.node(o);if(r==t.index(o)&&o<e.depth-n.openStart){let s=Dn(e,t,n,o+1);return i.copy(i.content.replaceChild(r,s))}if(n.content.size){if(n.openStart||n.openEnd||e.depth!=o||t.depth!=o){let{start:r,end:s}=function(e,t){let n=t.depth-e.openStart,o=t.node(n).copy(e.content);for(let r=n-1;r>=0;r--)o=t.node(r).copy(Rn.from(o));return{start:o.resolveNoCache(e.openStart+n),end:o.resolveNoCache(o.content.size-e.openEnd-n)}}(n,e);return zn(i,Fn(e,r,s,t,o))}{let o=e.parent,r=o.content;return zn(o,r.cut(0,e.parentOffset).append(n.content).append(r.cut(t.parentOffset)))}}return zn(i,Un(e,t,o))}function Bn(e,t){if(!t.type.compatibleContent(e.type))throw new On("Cannot join "+t.type.name+" onto "+e.type.name)}function Hn(e,t,n){let o=e.node(n);return Bn(o,t.node(n)),o}function Vn(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 $n(e,t,n,o){let r=(t||e).node(n),i=0,s=t?t.index(n):r.childCount;e&&(i=e.index(n),e.depth>n?i++:e.textOffset&&(Vn(e.nodeAfter,o),i++));for(let l=i;l<s;l++)Vn(r.child(l),o);t&&t.depth==n&&t.textOffset&&Vn(t.nodeBefore,o)}function zn(e,t){return e.type.checkContent(t),e.copy(t)}function Fn(e,t,n,o,r){let i=e.depth>r&&Hn(e,t,r+1),s=o.depth>r&&Hn(n,o,r+1),l=[];return $n(null,e,r,l),i&&s&&t.index(r)==n.index(r)?(Bn(i,s),Vn(zn(i,Fn(e,t,n,o,r+1)),l)):(i&&Vn(zn(i,Un(e,t,r+1)),l),$n(t,n,r,l),s&&Vn(zn(s,Un(n,o,r+1)),l)),$n(o,null,r,l),new Rn(l)}function Un(e,t,n){let o=[];if($n(null,e,n,o),e.depth>n){Vn(zn(Hn(e,t,n+1),Un(e,t,n+1)),o)}return $n(t,null,n,o),new Rn(o)}_n.empty=new _n(Rn.empty,0,0);class Wn{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?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[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].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],o=e.child(t);return n?e.child(t).cut(n):o}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):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],o=0==t?0:this.path[3*t-1]+1;for(let r=0;r<e;r++)o+=n.child(r).nodeSize;return o}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return An.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),o=e.maybeChild(t);if(!n){let e=n;n=o,o=e}let r=n.marks;for(var i=0;i<r.length;i++)!1!==r[i].type.spec.inclusive||o&&r[i].isInSet(o.marks)||(r=r[i--].removeFromSet(r));return r}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,o=e.parent.maybeChild(e.index());for(var r=0;r<n.length;r++)!1!==n[r].type.spec.inclusive||o&&n[r].isInSet(o.marks)||(n=n[r--].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 Zn(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],o=0,r=t;for(let i=e;;){let{index:e,offset:t}=i.content.findIndex(r),s=r-t;if(n.push(i,e,o+t),!s)break;if(i=i.child(e),i.isText)break;r=s-1,o+=t+1}return new Wn(t,n,r)}static resolveCached(e,t){let n=Kn.get(e);if(n)for(let r=0;r<n.elts.length;r++){let e=n.elts[r];if(e.pos==t)return e}else Kn.set(e,n=new qn);let o=n.elts[n.i]=Wn.resolve(e,t);return n.i=(n.i+1)%Gn,o}}class qn{constructor(){this.elts=[],this.i=0}}const Gn=12,Kn=new WeakMap;class Zn{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)}}const Jn=Object.create(null);let Xn=class e{constructor(e,t,n,o=An.none){this.type=e,this.attrs=t,this.marks=o,this.content=n||Rn.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,o=0){this.content.nodesBetween(e,t,n,o,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,o){return this.content.textBetween(e,t,n,o)}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&&Nn(this.attrs,t||e.defaultAttrs||Jn)&&An.sameSet(this.marks,n||An.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 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return _n.empty;let o=this.resolve(e),r=this.resolve(t),i=n?0:o.sharedDepth(t),s=o.start(i),l=o.node(i).content.cut(o.pos-s,r.pos-s);return new _n(l,o.depth-i,r.depth-i)}replace(e,t,n){return Ln(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:o}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(o==e||t.isText)return t;e-=o+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(0==e)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 o=this.content.child(t-1);return{node:o,index:t-1,offset:n-o.nodeSize}}resolve(e){return Wn.resolveCached(this,e)}resolveNoCache(e){return Wn.resolve(this,e)}rangeHasMark(e,t,n){let o=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(o=!0),!o)),o}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()+")"),Qn(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=Rn.empty,o=0,r=n.childCount){let i=this.contentMatchAt(e).matchFragment(n,o,r),s=i&&i.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let l=o;l<r;l++)if(!this.type.allowsMarks(n.child(l).marks))return!1;return!0}canReplaceWith(e,t,n,o){if(o&&!this.type.allowsMarks(o))return!1;let r=this.contentMatchAt(e).matchType(n),i=r&&r.matchFragment(this.content,t);return!!i&&i.validEnd}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),this.type.checkAttrs(this.attrs);let e=An.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!An.sameSet(e,this.marks))throw new 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 new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let o=Rn.fromJSON(e,t.content),r=e.nodeType(t.type).create(t.attrs,o,n);return r.type.checkAttrs(r.attrs),r}};Xn.prototype.text=void 0;class Yn extends Xn{constructor(e,t,n,o){if(super(e,t,null,o),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Qn(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Yn(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Yn(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Qn(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class eo{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new to(e,t);if(null==n.next)return eo.empty;let o=no(n);n.next&&n.err("Unexpected trailing text");let r=function(e){let t=Object.create(null);return n(ao(e,0));function n(o){let r=[];o.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let o;for(let e=0;e<r.length;e++)r[e][0]==t&&(o=r[e][1]);ao(e,n).forEach(e=>{o||r.push([t,o=[]]),-1==o.indexOf(e)&&o.push(e)})})});let i=t[o.join(",")]=new eo(o.indexOf(e.length-1)>-1);for(let e=0;e<r.length;e++){let o=r[e][1].sort(lo);i.next.push({type:r[e][0],next:t[o.join(",")]||n(o)})}return i}}(function(e){let t=[[]];return r(i(e,0),n()),t;function n(){return t.push([])-1}function o(e,n,o){let r={term:o,to:n};return t[e].push(r),r}function r(e,t){e.forEach(e=>e.to=t)}function i(e,t){if("choice"==e.type)return e.exprs.reduce((e,n)=>e.concat(i(n,t)),[]);if("seq"!=e.type){if("star"==e.type){let s=n();return o(t,s),r(i(e.expr,s),s),[o(s)]}if("plus"==e.type){let s=n();return r(i(e.expr,t),s),r(i(e.expr,s),s),[o(s)]}if("opt"==e.type)return[o(t)].concat(i(e.expr,t));if("range"==e.type){let s=t;for(let t=0;t<e.min;t++){let t=n();r(i(e.expr,s),t),s=t}if(-1==e.max)r(i(e.expr,s),s);else for(let t=e.min;t<e.max;t++){let t=n();o(s,t),r(i(e.expr,s),t),s=t}return[o(s)]}if("name"==e.type)return[o(t,void 0,e.value)];throw new Error("Unknown expr type")}for(let o=0;;o++){let s=i(e.exprs[o],t);if(o==e.exprs.length-1)return s;r(s,t=n())}}}(o));return function(e,t){for(let n=0,o=[e];n<o.length;n++){let e=o[n],r=!e.validEnd,i=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];i.push(n.name),!r||n.isText||n.hasRequiredAttrs()||(r=!1),-1==o.indexOf(s)&&o.push(s)}r&&t.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,n),r}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 o=this;for(let r=t;o&&r<n;r++)o=o.matchType(e.child(r).type);return o}get inlineContent(){return 0!=this.next.length&&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 o=[this];return function r(i,s){let l=i.matchFragment(e,n);if(l&&(!t||l.validEnd))return Rn.from(s.map(e=>e.createAndFill()));for(let e=0;e<i.next.length;e++){let{type:t,next:n}=i.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==o.indexOf(n)){o.push(n);let e=r(n,s.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let o=n.shift(),r=o.match;if(r.matchType(e)){let e=[];for(let t=o;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<r.next.length;e++){let{type:i,next:s}=r.next[e];i.isLeaf||i.hasRequiredAttrs()||i.name in t||o.type&&!s.validEnd||(n.push({match:i.contentMatch,type:i,via:o}),t[i.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return function t(n){e.push(n);for(let o=0;o<n.next.length;o++)-1==e.indexOf(n.next[o].next)&&t(n.next[o].next)}(this),e.map((t,n)=>{let o=n+(t.validEnd?"*":" ")+" ";for(let r=0;r<t.next.length;r++)o+=(r?", ":"")+t.next[r].type.name+"->"+e.indexOf(t.next[r].next);return o}).join("\n")}}eo.empty=new eo(!0);class to{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function no(e){let t=[];do{t.push(oo(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function oo(e){let t=[];do{t.push(ro(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function ro(e){let t=function(e){if(e.eat("(")){let t=no(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,o=n[t];if(o)return[o];let r=[];for(let i in n){let e=n[i];e.isInGroup(t)&&r.push(e)}0==r.length&&e.err("No node type or group '"+t+"' found");return r}(e,e.next).map(t=>(null==e.inline?e.inline=t.isInline:e.inline!=t.isInline&&e.err("Mixing inline and block content"),{type:"name",value:t}));return e.pos++,1==t.length?t[0]:{type:"choice",exprs:t}}e.err("Unexpected token '"+e.next+"'")}(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("{"))break;t=so(e,t)}return t}function io(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function so(e,t){let n=io(e),o=n;return e.eat(",")&&(o="}"!=e.next?io(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:o,expr:t}}function lo(e,t){return t-e}function ao(e,t){let n=[];return function t(o){let r=e[o];if(1==r.length&&!r[0].term)return t(r[0].to);n.push(o);for(let e=0;e<r.length;e++){let{term:o,to:i}=r[e];o||-1!=n.indexOf(i)||t(i)}}(t),n.sort(lo)}function co(e){let t=Object.create(null);for(let n in e){let o=e[n];if(!o.hasDefault)return null;t[n]=o.default}return t}function uo(e,t){let n=Object.create(null);for(let o in e){let r=t&&t[o];if(void 0===r){let t=e[o];if(!t.hasDefault)throw new RangeError("No value supplied for attribute "+o);r=t.default}n[o]=r}return n}function ho(e,t,n,o){for(let r in t)if(!(r in e))throw new RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let r in e){let n=e[r];n.validate&&n.validate(t[r])}}function po(e,t){let n=Object.create(null);if(t)for(let o in t)n[o]=new mo(e,o,t[o]);return n}let fo=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=po(e,n.attrs),this.defaultAttrs=co(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==eo.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:uo(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Xn(this,this.computeAttrs(e),Rn.from(t),An.setFrom(n))}createChecked(e=null,t,n){return t=Rn.from(t),this.checkContent(t),new Xn(this,this.computeAttrs(e),t,An.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=Rn.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let o=this.contentMatch.matchFragment(t),r=o&&o.fillBefore(Rn.empty,!0);return r?new Xn(this,e,t.append(r),An.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let n=0;n<e.childCount;n++)if(!this.allowsMarks(e.child(n).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){ho(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(null==this.markSet)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:An.none:e}static compile(t,n){let o=Object.create(null);t.forEach((t,r)=>o[t]=new e(t,n,r));let r=n.spec.topNode||"doc";if(!o[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!o.text)throw new RangeError("Every schema needs a 'text' type");for(let e in o.text.attrs)throw new RangeError("The text node type should not have attributes");return o}};class mo{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let o=n.split("|");return n=>{let r=null===n?"null":typeof n;if(o.indexOf(r)<0)throw new RangeError(`Expected value of type ${o} for attribute ${t} on type ${e}, got ${r}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class go{constructor(e,t,n,o){this.name=e,this.rank=t,this.schema=n,this.spec=o,this.attrs=po(e,o.attrs),this.excluded=null;let r=co(this.attrs);this.instance=r?new An(this,r):null}create(e=null){return!e&&this.instance?this.instance:new An(this,uo(this.attrs,e))}static compile(e,t){let n=Object.create(null),o=0;return e.forEach((e,r)=>n[e]=new go(e,o++,t,r)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){ho(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class yo{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let o in e)t[o]=e[o];t.nodes=En.from(e.nodes),t.marks=En.from(e.marks||{}),this.nodes=fo.compile(this.spec.nodes,this),this.marks=go.compile(this.spec.marks,this);let n=Object.create(null);for(let o in this.nodes){if(o in this.marks)throw new RangeError(o+" can not be both a node and a mark");let e=this.nodes[o],t=e.spec.content||"",r=e.spec.marks;if(e.contentMatch=n[t]||(n[t]=eo.parse(t,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet="_"==r?null:r?bo(this,r.split(" ")):""!=r&&e.inlineContent?null:[]}for(let o in this.marks){let e=this.marks[o],t=e.spec.excludes;e.excluded=null==t?[e]:""==t?[]:bo(this,t.split(" "))}this.nodeFromJSON=e=>Xn.fromJSON(this,e),this.markFromJSON=e=>An.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,o){if("string"==typeof e)e=this.nodeType(e);else{if(!(e instanceof fo))throw new RangeError("Invalid node type: "+e);if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}return e.createChecked(t,n,o)}text(e,t){let n=this.nodes.text;return new Yn(n,n.defaultAttrs,e,An.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function bo(e,t){let n=[];for(let o=0;o<t.length;o++){let r=t[o],i=e.marks[r],s=i;if(i)n.push(i);else for(let t in e.marks){let o=e.marks[t];("_"==r||o.spec.group&&o.spec.group.split(" ").indexOf(r)>-1)&&n.push(s=o)}if(!s)throw new SyntaxError("Unknown mark type: '"+t[o]+"'")}return n}let vo=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(function(e){return null!=e.tag}(e))this.tags.push(e);else if(function(e){return null!=e.style}(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 So(this,t,!1);return n.addAll(e,An.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new So(this,t,!0);return n.addAll(e,An.none,t.from,t.to),_n.maxOpen(n.finish())}matchTag(e,t,n){for(let o=n?this.tags.indexOf(n)+1:0;o<this.tags.length;o++){let n=this.tags[o];if(Mo(e,n.tag)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,o){for(let r=o?this.styles.indexOf(o)+1:0;r<this.styles.length;r++){let o=this.styles[r],i=o.style;if(!(0!=i.indexOf(e)||o.context&&!n.matchesContext(o.context)||i.length>e.length&&(61!=i.charCodeAt(e.length)||i.slice(e.length+1)!=t))){if(o.getAttrs){let e=o.getAttrs(t);if(!1===e)continue;o.attrs=e||void 0}return o}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,o=0;for(;o<t.length;o++){let e=t[o];if((null==e.priority?50:e.priority)<n)break}t.splice(o,0,e)}for(let o in e.marks){let t=e.marks[o].spec.parseDOM;t&&t.forEach(e=>{n(e=Ro(e)),e.mark||e.ignore||e.clearMark||(e.mark=o)})}for(let o in e.nodes){let t=e.nodes[o].spec.parseDOM;t&&t.forEach(e=>{n(e=Ro(e)),e.node||e.ignore||e.mark||(e.node=o)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}};const xo={address:!0,article:!0,aside:!0,blockquote:!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},wo={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ko={ol:!0,ul:!0};function Co(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class Eo{constructor(e,t,n,o,r,i){this.type=e,this.attrs=t,this.marks=n,this.solid=o,this.options=i,this.content=[],this.activeMarks=An.none,this.match=r||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Rn.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[0].length))}}let t=Rn.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Rn.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&&!xo.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class So{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let o,r=t.topNode,i=Co(null,t.preserveWhitespace,0)|(n?4:0);o=r?new Eo(r.type,r.attrs,An.none,!0,t.topMatch||r.type.contentMatch,i):new Eo(n?null:e.schema.topNodeType,null,An.none,!0,null,i),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,o=this.top,r=2&o.options?"full":this.localPreserveWS||(1&o.options)>0,{schema:i}=this.parser;if("full"===r||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r)if("full"===r)n=n.replace(/\r\n?/g,"\n");else if(i.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(i.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(i.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(i.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=o.content[o.content.length-1],r=e.previousSibling;(!t||r&&"BR"==r.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(i.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let o=this.localPreserveWS,r=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i,s=e.nodeName.toLowerCase();ko.hasOwnProperty(s)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&ko.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));e:if(l?l.ignore:wo.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let n,o=this.needsBlock;if(xo.hasOwnProperty(s))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),n=!0,r.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let i=l&&l.skip?t:this.readStyles(e,t);i&&this.addAll(e,i),n&&this.sync(r),this.needsBlock=o}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,l,n,!1===l.consuming?i:void 0)}this.localPreserveWS=o}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||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 o=0;o<this.parser.matchedStyles.length;o++){let e=this.parser.matchedStyles[o],r=n.getPropertyValue(e);if(r)for(let n;;){let o=this.parser.matchStyle(e,r,this,n);if(!o)break;if(o.ignore)return null;if(t=o.clearMark?t.filter(e=>!o.clearMark(e)):t.concat(this.parser.schema.marks[o.mark].create(o.attrs)),!1!==o.consuming)break;n=o}}return t}addElementByRule(e,t,n,o){let r,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(i,t.attrs||null,n,t.preserveWhitespace);e&&(r=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let s=this.top;if(i&&i.isLeaf)this.findInside(e);else if(o)this.addElement(e,n,o);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let o=e;"string"==typeof t.contentElement?o=e.querySelector(t.contentElement):"function"==typeof t.contentElement?o=t.contentElement(e):t.contentElement&&(o=t.contentElement),this.findAround(e,o,!0),this.addAll(o,n),this.findAround(e,o,!1)}r&&this.sync(s)&&this.open--}addAll(e,t,n,o){let r=n||0;for(let i=n?e.childNodes[n]:e.firstChild,s=null==o?null:e.childNodes[o];i!=s;i=i.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(i,t);this.findAtPoint(e,r)}findPlace(e,t,n){let o,r;for(let i=this.open,s=0;i>=0;i--){let t=this.nodes[i],l=t.findWrapping(e);if(l&&(!o||o.length>l.length+s)&&(o=l,r=t,!l.length))break;if(t.solid){if(n)break;s+=2}}if(!o)return null;this.sync(r);for(let i=0;i<o.length;i++)t=this.enterInner(o[i],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 o=this.findPlace(e,t,n);if(o){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=An.none;for(let r of o.concat(e.marks))(t.type?t.type.allowsMarkType(r.type):To(r.type,e.type))&&(n=r.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,o){let r=this.findPlace(e.create(t),n,!1);return r&&(r=this.enterInner(e,t,n,!0,o)),r}enterInner(e,t,n,o=!1,r){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let s=Co(e,r,i.options);4&i.options&&0==i.content.length&&(s|=4);let l=An.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):To(t.type,e))||(l=t.addToSet(l),!1)),this.nodes.push(new Eo(e,t,l,o,null,s)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!(!this.isOpen&&!this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=1)}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++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let o=0;o<this.find.length;o++)if(null==this.find[o].pos&&1==e.nodeType&&e.contains(this.find[o].node)){t.compareDocumentPosition(this.find[o].node)&(n?2:4)&&(this.find[o].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,o=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),r=-(n?n.depth+1:0)+(o?0:1),i=(e,s)=>{for(;e>=0;e--){let l=t[e];if(""==l){if(e==t.length-1||0==e)continue;for(;s>=r;s--)if(i(e-1,s))return!0;return!1}{let e=s>0||0==s&&o?this.nodes[s].type:n&&s>=r?n.node(s-r).type:null;if(!e||e.name!=l&&!e.isInGroup(l))return!1;s--}}return!0};return i(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}}function Mo(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Ro(e){let t={};for(let n in e)t[n]=e[n];return t}function To(e,t){let n=t.schema.nodes;for(let o in n){let r=n[o];if(!r.allowsMarkType(e))continue;let i=[],s=e=>{i.push(e);for(let n=0;n<e.edgeCount;n++){let{type:o,next:r}=e.edge(n);if(o==t)return!0;if(i.indexOf(r)<0&&s(r))return!0}};if(s(r.contentMatch))return!0}}class jo{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=Ao(t).createDocumentFragment());let o=n,r=[];return e.forEach(e=>{if(r.length||e.marks.length){let n=0,i=0;for(;n<r.length&&i<e.marks.length;){let t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(r[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<r.length;)o=r.pop()[1];for(;i<e.marks.length;){let n=e.marks[i++],s=this.serializeMark(n,e.isInline,t);s&&(r.push([n,o]),o.appendChild(s.dom),o=s.contentDOM||s.dom)}}o.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:o}=Po(Ao(t),this.nodes[e.type.name](e),null,e.attrs);if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,o)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let o=e.marks.length-1;o>=0;o--){let r=this.serializeMark(e.marks[o],e.isInline,t);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(e,t,n={}){let o=this.marks[e.type.name];return o&&Po(Ao(n),o(e,t),null,e.attrs)}static renderSpec(e,t,n=null,o){return Po(e,t,n,o)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new jo(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=No(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return No(e.marks)}}function No(e){let t={};for(let n in e){let o=e[n].spec.toDOM;o&&(t[n]=o)}return t}function Ao(e){return e.document||window.document}const Oo=new WeakMap;function _o(e){let t=Oo.get(e);return void 0===t&&Oo.set(e,t=function(e){let t=null;function n(e){if(e&&"object"==typeof e)if(Array.isArray(e))if("string"==typeof e[0])t||(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}(e)),t}function Po(e,t,n,o){if("string"==typeof t)return{dom:e.createTextNode(t)};if(null!=t.nodeType)return{dom:t};if(t.dom&&null!=t.dom.nodeType)return t;let r,i=t[0];if("string"!=typeof i)throw new RangeError("Invalid array passed to renderSpec");if(o&&(r=_o(o))&&r.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s,l=i.indexOf(" ");l>0&&(n=i.slice(0,l),i=i.slice(l+1));let a=n?e.createElementNS(n,i):e.createElement(i),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?a.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):"style"==e&&a.style?a.style.cssText=c[e]:a.setAttribute(e,c[e])}}for(let u=d;u<t.length;u++){let r=t[u];if(0===r){if(u<t.length-1||u>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}{let{dom:t,contentDOM:i}=Po(e,r,n,o);if(a.appendChild(t),i){if(s)throw new RangeError("Multiple content holes");s=i}}}return{dom:a,contentDOM:s}}const Io=Math.pow(2,16);function Lo(e,t){return e+t*Io}function Do(e){return 65535&e}class Bo{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class Ho{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Ho.empty)return Ho.empty}recover(e){let t=0,n=Do(e);if(!this.inverted)for(let o=0;o<n;o++)t+=this.ranges[3*o+2]-this.ranges[3*o+1];return this.ranges[3*n]+t+function(e){return(e-(65535&e))/Io}(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 o=0,r=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let l=this.ranges[s]-(this.inverted?o:0);if(l>e)break;let a=this.ranges[s+r],c=this.ranges[s+i],d=l+a;if(e<=d){let r=l+o+((a?e==l?-1:e==d?1:t:t)<0?0:c);if(n)return r;let i=e==(t<0?l:d)?null:Lo(s/3,e-l),u=e==l?2:e==d?1:4;return(t<0?e!=l:e!=d)&&(u|=8),new Bo(r,u,i)}o+=c-a}return n?e+o:new Bo(e+o,0,null)}touches(e,t){let n=0,o=Do(t),r=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let t=this.ranges[s]-(this.inverted?n:0);if(t>e)break;let l=this.ranges[s+r];if(e<=t+l&&s==3*o)return!0;n+=this.ranges[s+i]-l}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let o=0,r=0;o<this.ranges.length;o+=3){let i=this.ranges[o],s=i-(this.inverted?r:0),l=i+(this.inverted?0:r),a=this.ranges[o+t],c=this.ranges[o+n];e(s,s+a,l,l+c),r+=c-a}}invert(){return new Ho(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?Ho.empty:new Ho(e<0?[0,-e,0]:[0,0,e])}}Ho.empty=new Ho([]);class Vo{constructor(e,t,n=0,o=(e?e.length:0)){this.mirror=t,this.from=n,this.to=o,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new Vo(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let o=e.getMirror(t);this.appendMap(e._maps[t],null!=o&&o<t?n+o:void 0)}}getMirror(e){if(this.mirror)for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let o=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=o&&o>t?n-o-1:void 0)}}invert(){let e=new Vo;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let o=0;for(let r=this.from;r<this.to;r++){let n=this._maps[r].mapResult(e,t);if(null!=n.recover){let t=this.getMirror(r);if(null!=t&&t>r&&t<this.to){r=t,e=this._maps[t].recover(n.recover);continue}}o|=n.delInfo,e=n.pos}return n?e:new Bo(e,o,null)}}const $o=Object.create(null);class zo{getMap(){return Ho.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=$o[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in $o)throw new RangeError("Duplicate use of step JSON ID "+e);return $o[e]=t,t.prototype.jsonID=e,t}}class Fo{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new Fo(e,null)}static fail(e){return new Fo(null,e)}static fromReplace(e,t,n,o){try{return Fo.ok(e.replace(t,n,o))}catch(r){if(r instanceof On)return Fo.fail(r.message);throw r}}}function Uo(e,t,n){let o=[];for(let r=0;r<e.childCount;r++){let i=e.child(r);i.content.size&&(i=i.copy(Uo(i.content,t,i))),i.isInline&&(i=t(i,n,r)),o.push(i)}return Rn.fromArray(o)}class Wo extends zo{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),o=n.node(n.sharedDepth(this.to)),r=new _n(Uo(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,o),t.openStart,t.openEnd);return Fo.fromReplace(e,this.from,this.to,r)}invert(){return new qo(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new Wo(t.pos,n.pos,this.mark)}merge(e){return e instanceof Wo&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Wo(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Wo(t.from,t.to,e.markFromJSON(t.mark))}}zo.jsonID("addMark",Wo);class qo extends zo{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 _n(Uo(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return Fo.fromReplace(e,this.from,this.to,n)}invert(){return new Wo(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new qo(t.pos,n.pos,this.mark)}merge(e){return e instanceof qo&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new qo(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new qo(t.from,t.to,e.markFromJSON(t.mark))}}zo.jsonID("removeMark",qo);class Go extends zo{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Fo.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Fo.fromReplace(e,this.pos,this.pos+1,new _n(Rn.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new Go(this.pos,t.marks[n]);return new Go(this.pos,this.mark)}}return new Ko(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Go(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Go(t.pos,e.markFromJSON(t.mark))}}zo.jsonID("addNodeMark",Go);class Ko extends zo{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Fo.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Fo.fromReplace(e,this.pos,this.pos+1,new _n(Rn.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new Go(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ko(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ko(t.pos,e.markFromJSON(t.mark))}}zo.jsonID("removeNodeMark",Ko);class Zo extends zo{constructor(e,t,n,o=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=o}apply(e){return this.structure&&Xo(e,this.from,this.to)?Fo.fail("Structure replace would overwrite content"):Fo.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ho([this.from,this.to-this.from,this.slice.size])}invert(e){return new Zo(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deletedAcross&&n.deletedAcross?null:new Zo(t.pos,Math.max(t.pos,n.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Zo)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart){if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;{let t=this.slice.size+e.slice.size==0?_n.empty:new _n(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Zo(e.from,this.to,t,this.structure)}}{let t=this.slice.size+e.slice.size==0?_n.empty:new _n(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Zo(this.from,this.to+(e.to-e.from),t,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Zo(t.from,t.to,_n.fromJSON(e,t.slice),!!t.structure)}}zo.jsonID("replace",Zo);class Jo extends zo{constructor(e,t,n,o,r,i,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=o,this.slice=r,this.insert=i,this.structure=s}apply(e){if(this.structure&&(Xo(e,this.from,this.gapFrom)||Xo(e,this.gapTo,this.to)))return Fo.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Fo.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?Fo.fromReplace(e,this.from,this.to,n):Fo.fail("Content does not fit in gap")}getMap(){return new Ho([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new Jo(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),o=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),r=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||o<t.pos||r>n.pos?null:new Jo(t.pos,n.pos,o,r,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Jo(t.from,t.to,t.gapFrom,t.gapTo,_n.fromJSON(e,t.slice),t.insert,!!t.structure)}}function Xo(e,t,n){let o=e.resolve(t),r=n-t,i=o.depth;for(;r>0&&i>0&&o.indexAfter(i)==o.node(i).childCount;)i--,r--;if(r>0){let e=o.node(i).maybeChild(o.indexAfter(i));for(;r>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,r--}}return!1}function Yo(e,t,n,o=n.contentMatch,r=!0){let i=e.doc.nodeAt(t),s=[],l=t+1;for(let a=0;a<i.childCount;a++){let t=i.child(a),c=l+t.nodeSize,d=o.matchType(t.type);if(d){o=d;for(let o=0;o<t.marks.length;o++)n.allowsMarkType(t.marks[o].type)||e.step(new qo(l,c,t.marks[o]));if(r&&t.isText&&"pre"!=n.whitespace){let e,o,r=/\r?\n|\r/g;for(;e=r.exec(t.text);)o||(o=new _n(Rn.from(n.schema.text(" ",n.allowedMarks(t.marks))),0,0)),s.push(new Zo(l+e.index,l+e.index+e[0].length,o))}}else s.push(new Zo(l,c,_n.empty));l=c}if(!o.validEnd){let t=o.fillBefore(Rn.empty,!0);e.replace(l,l,new _n(t,0,0))}for(let a=s.length-1;a>=0;a--)e.step(s[a])}function Qo(e,t,n){return(0==t||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function er(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth;;--n){let o=e.$from.node(n),r=e.$from.index(n),i=e.$to.indexAfter(n);if(n<e.depth&&o.canReplace(r,i,t))return n;if(0==n||o.type.spec.isolating||!Qo(o,r,i))break}return null}function tr(e,t,n=null,o=e){let r=function(e,t){let{parent:n,startIndex:o,endIndex:r}=e,i=n.contentMatchAt(o).findWrapping(t);if(!i)return null;let s=i.length?i[0]:t;return n.canReplaceWith(o,r,s)?i:null}(e,t),i=r&&function(e,t){let{parent:n,startIndex:o,endIndex:r}=e,i=n.child(o),s=t.contentMatch.findWrapping(i.type);if(!s)return null;let l=(s.length?s[s.length-1]:t).contentMatch;for(let a=o;l&&a<r;a++)l=l.matchType(n.child(a).type);return l&&l.validEnd?s:null}(o,t);return i?r.map(nr).concat({type:t,attrs:n}).concat(i.map(nr)):null}function nr(e){return{type:e,attrs:null}}function or(e,t,n,o){t.forEach((r,i)=>{if(r.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(r.text);){let r=e.mapping.slice(o).map(n+1+i+s.index);e.replaceWith(r,r+1,t.type.schema.linebreakReplacement.create())}}})}function rr(e,t,n,o){t.forEach((r,i)=>{if(r.type==r.type.schema.linebreakReplacement){let r=e.mapping.slice(o).map(n+1+i);e.replaceWith(r,r+1,t.type.schema.text("\n"))}})}function ir(e,t,n=1,o){let r=e.resolve(t),i=r.depth-n,s=o&&o[o.length-1]||r.parent;if(i<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!s.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let c=r.depth-1,d=n-2;c>i;c--,d--){let e=r.node(c),t=r.index(c);if(e.type.spec.isolating)return!1;let n=e.content.cutByIndex(t,e.childCount),i=o&&o[d+1];i&&(n=n.replaceChild(0,i.type.create(i.attrs)));let s=o&&o[d]||e;if(!e.canReplace(t+1,e.childCount)||!s.type.validContent(n))return!1}let l=r.indexAfter(i),a=o&&o[0];return r.node(i).canReplaceWith(l,l,a?a.type:r.node(i+1).type)}function sr(e,t){let n=e.resolve(t),o=n.index();return lr(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(o,o+1)}function lr(e,t){return!(!e||!t||e.isLeaf||!function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:o}=e.type.schema;for(let r=0;r<t.childCount;r++){let i=t.child(r),s=i.type==o?e.type.schema.nodes.text:i.type;if(n=n.matchType(s),!n)return!1;if(!e.type.allowsMarks(i.marks))return!1}return n.validEnd}(e,t))}function ar(e,t,n=-1){let o=e.resolve(t);for(let r=o.depth;;r--){let e,i,s=o.index(r);if(r==o.depth?(e=o.nodeBefore,i=o.nodeAfter):n>0?(e=o.node(r+1),s++,i=o.node(r).maybeChild(s)):(e=o.node(r).maybeChild(s-1),i=o.node(r+1)),e&&!e.isTextblock&&lr(e,i)&&o.node(r).canReplace(s,s+1))return t;if(0==r)break;t=n<0?o.before(r):o.after(r)}}function cr(e,t,n){let o=e.resolve(t);if(!n.content.size)return t;let r=n.content;for(let i=0;i<n.openStart;i++)r=r.firstChild.content;for(let i=1;i<=(0==n.openStart&&n.size?2:1);i++)for(let e=o.depth;e>=0;e--){let t=e==o.depth?0:o.pos<=(o.start(e+1)+o.end(e+1))/2?-1:1,n=o.index(e)+(t>0?1:0),s=o.node(e),l=!1;if(1==i)l=s.canReplace(n,n,r);else{let e=s.contentMatchAt(n).findWrapping(r.firstChild.type);l=e&&s.canReplaceWith(n,n,e[0])}if(l)return 0==t?o.pos:t<0?o.before(e+1):o.after(e+1)}return null}function dr(e,t,n=t,o=_n.empty){if(t==n&&!o.size)return null;let r=e.resolve(t),i=e.resolve(n);return ur(r,i,o)?new Zo(t,n,o):new hr(r,i,o).fit()}function ur(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}zo.jsonID("replaceAround",Jo);class hr{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=Rn.empty;for(let o=0;o<=e.depth;o++){let t=e.node(o);this.frontier.push({type:t.type,match:t.contentMatchAt(e.indexAfter(o))})}for(let o=e.depth;o>0;o--)this.placed=Rn.from(e.node(o).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,o=this.close(e<0?this.$to:n.doc.resolve(e));if(!o)return null;let r=this.placed,i=n.depth,s=o.depth;for(;i&&s&&1==r.childCount;)r=r.firstChild.content,i--,s--;let l=new _n(r,i,s);return e>-1?new Jo(n.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||n.pos!=this.$to.pos?new Zo(n.pos,o.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,o=this.unplaced.openEnd;n<e;n++){let r=t.firstChild;if(t.childCount>1&&(o=0),r.type.spec.isolating&&o<=n){e=n;break}t=r.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e,o=null;n?(o=mr(this.unplaced.content,n-1).firstChild,e=o.content):e=this.unplaced.content;let r=e.firstChild;for(let i=this.depth;i>=0;i--){let e,{type:s,match:l}=this.frontier[i],a=null;if(1==t&&(r?l.matchType(r.type)||(a=l.fillBefore(Rn.from(r),!1)):o&&s.compatibleContent(o.type)))return{sliceDepth:n,frontierDepth:i,parent:o,inject:a};if(2==t&&r&&(e=l.findWrapping(r.type)))return{sliceDepth:n,frontierDepth:i,parent:o,wrap:e};if(o&&l.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,o=mr(e,t);return!(!o.childCount||o.firstChild.isLeaf)&&(this.unplaced=new _n(e,t+1,Math.max(n,o.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,o=mr(e,t);if(o.childCount<=1&&t>0){let r=e.size-t<=t+o.size;this.unplaced=new _n(pr(e,t-1,1),t-1,r?t-1:n)}else this.unplaced=new _n(pr(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:o,wrap:r}){for(;this.depth>t;)this.closeFrontierNode();if(r)for(let f=0;f<r.length;f++)this.openFrontierNode(r[f]);let i=this.unplaced,s=n?n.content:i.content,l=i.openStart-e,a=0,c=[],{match:d,type:u}=this.frontier[t];if(o){for(let e=0;e<o.childCount;e++)c.push(o.child(e));d=d.matchFragment(o)}let h=s.size+e-(i.content.size-i.openEnd);for(;a<s.childCount;){let e=s.child(a),t=d.matchType(e.type);if(!t)break;a++,(a>1||0==l||e.content.size)&&(d=t,c.push(gr(e.mark(u.allowedMarks(e.marks)),1==a?l:0,a==s.childCount?h:-1)))}let p=a==s.childCount;p||(h=-1),this.placed=fr(this.placed,t,Rn.from(c)),this.frontier[t].match=d,p&&h<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let f=0,m=s;f<h;f++){let e=m.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),m=e.content}this.unplaced=p?0==e?_n.empty:new _n(pr(i.content,e-1,1),e-1,h<0?i.openEnd:e-1):new _n(pr(i.content,e,a),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e,t=this.frontier[this.depth];if(!t.type.isTextblock||!yr(this.$to,this.$to.depth,t.type,t.match,!1)||this.$to.depth==this.depth&&(e=this.findCloseLevel(this.$to))&&e.depth==this.depth)return-1;let{depth:n}=this.$to,o=this.$to.after(n);for(;n>1&&o==this.$to.end(--n);)++o;return o}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:o}=this.frontier[t],r=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),i=yr(e,t,o,n,r);if(i){for(let n=t-1;n>=0;n--){let{match:t,type:o}=this.frontier[n],r=yr(e,n,o,t,!0);if(!r||r.childCount)continue e}return{depth:t,fit:i,move:r?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=fr(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),o=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,o)}return e}openFrontierNode(e,t=null,n){let o=this.frontier[this.depth];o.match=o.match.matchType(e),this.placed=fr(this.placed,this.depth,Rn.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(Rn.empty,!0);e.childCount&&(this.placed=fr(this.placed,this.frontier.length,e))}}function pr(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(pr(e.firstChild.content,t-1,n)))}function fr(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(fr(e.lastChild.content,t-1,n)))}function mr(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function gr(e,t,n){if(t<=0)return e;let o=e.content;return t>1&&(o=o.replaceChild(0,gr(o.firstChild,t-1,1==o.childCount?n-1:0))),t>0&&(o=e.type.contentMatch.fillBefore(o).append(o),n<=0&&(o=o.append(e.type.contentMatch.matchFragment(o).fillBefore(Rn.empty,!0)))),e.copy(o)}function yr(e,t,n,o,r){let i=e.node(t),s=r?e.indexAfter(t):e.index(t);if(s==i.childCount&&!n.compatibleContent(i.type))return null;let l=o.fillBefore(i.content,!0,s);return l&&!function(e,t,n){for(let o=n;o<t.childCount;o++)if(!e.allowsMarks(t.child(o).marks))return!0;return!1}(n,i.content,s)?l:null}function br(e){return e.spec.defining||e.spec.definingForContent}function vr(e,t,n,o,r){if(t<n){let r=e.firstChild;e=e.replaceChild(0,r.copy(vr(r.content,t+1,n,o,r)))}if(t>o){let t=r.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(Rn.empty,!0))}return e}function xr(e,t){let n=[];for(let o=Math.min(e.depth,t.depth);o>=0;o--){let r=e.start(o);if(r<e.pos-(e.depth-o)||t.end(o)>t.pos+(t.depth-o)||e.node(o).type.spec.isolating||t.node(o).type.spec.isolating)break;(r==t.start(o)||o==e.depth&&o==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&o&&t.start(o-1)==r-1)&&n.push(o)}return n}class wr extends zo{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 Fo.fail("No node at attribute step's position");let n=Object.create(null);for(let r in t.attrs)n[r]=t.attrs[r];n[this.attr]=this.value;let o=t.type.create(n,null,t.marks);return Fo.fromReplace(e,this.pos,this.pos+1,new _n(Rn.from(o),0,t.isLeaf?0:1))}getMap(){return Ho.empty}invert(e){return new wr(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new wr(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new wr(t.pos,t.attr,t.value)}}zo.jsonID("attr",wr);class kr extends zo{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let o in e.attrs)t[o]=e.attrs[o];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return Fo.ok(n)}getMap(){return Ho.empty}invert(e){return new kr(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new kr(t.attr,t.value)}}zo.jsonID("docAttr",kr);let Cr=class extends Error{};Cr=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},(Cr.prototype=Object.create(Error.prototype)).constructor=Cr,Cr.prototype.name="TransformError";class Er{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Vo}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Cr(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}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=_n.empty){let o=dr(this.doc,e,t,n);return o&&this.step(o),this}replaceWith(e,t,n){return this.replace(e,t,new _n(Rn.from(n),0,0))}delete(e,t){return this.replace(e,t,_n.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return function(e,t,n,o){if(!o.size)return e.deleteRange(t,n);let r=e.doc.resolve(t),i=e.doc.resolve(n);if(ur(r,i,o))return e.step(new Zo(t,n,o));let s=xr(r,e.doc.resolve(n));0==s[s.length-1]&&s.pop();let l=-(r.depth+1);s.unshift(l);for(let h=r.depth,p=r.pos-1;h>0;h--,p--){let e=r.node(h).type.spec;if(e.defining||e.definingAsContext||e.isolating)break;s.indexOf(h)>-1?l=h:r.before(h)==p&&s.splice(1,0,-h)}let a=s.indexOf(l),c=[],d=o.openStart;for(let h=o.content,p=0;;p++){let e=h.firstChild;if(c.push(e),p==o.openStart)break;h=e.content}for(let h=d-1;h>=0;h--){let e=c[h],t=br(e.type);if(t&&!e.sameMarkup(r.node(Math.abs(l)-1)))d=h;else if(t||!e.type.isTextblock)break}for(let h=o.openStart;h>=0;h--){let t=(h+d+1)%(o.openStart+1),l=c[t];if(l)for(let c=0;c<s.length;c++){let d=s[(c+a)%s.length],u=!0;d<0&&(u=!1,d=-d);let h=r.node(d-1),p=r.index(d-1);if(h.canReplaceWith(p,p,l.type,l.marks))return e.replace(r.before(d),u?i.after(d):n,new _n(vr(o.content,0,o.openStart,t),t,o.openEnd))}}let u=e.steps.length;for(let h=s.length-1;h>=0&&(e.replace(t,n,o),!(e.steps.length>u));h--){let e=s[h];e<0||(t=r.before(e),n=i.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){return function(e,t,n,o){if(!o.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let r=function(e,t,n){let o=e.resolve(t);if(o.parent.canReplaceWith(o.index(),o.index(),n))return t;if(0==o.parentOffset)for(let r=o.depth-1;r>=0;r--){let e=o.index(r);if(o.node(r).canReplaceWith(e,e,n))return o.before(r+1);if(e>0)return null}if(o.parentOffset==o.parent.content.size)for(let r=o.depth-1;r>=0;r--){let e=o.indexAfter(r);if(o.node(r).canReplaceWith(e,e,n))return o.after(r+1);if(e<o.node(r).childCount)return null}return null}(e.doc,t,o.type);null!=r&&(t=n=r)}e.replaceRange(t,n,new _n(Rn.from(o),0,0))}(this,e,t,n),this}deleteRange(e,t){return function(e,t,n){let o=e.doc.resolve(t),r=e.doc.resolve(n),i=xr(o,r);for(let s=0;s<i.length;s++){let t=i[s],n=s==i.length-1;if(n&&0==t||o.node(t).type.contentMatch.validEnd)return e.delete(o.start(t),r.end(t));if(t>0&&(n||o.node(t-1).canReplace(o.index(t-1),r.indexAfter(t-1))))return e.delete(o.before(t),r.after(t))}for(let s=1;s<=o.depth&&s<=r.depth;s++)if(t-o.start(s)==o.depth-s&&n>o.end(s)&&r.end(s)-n!=r.depth-s&&o.start(s-1)==r.start(s-1)&&o.node(s-1).canReplace(o.index(s-1),r.index(s-1)))return e.delete(o.before(s),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return function(e,t,n){let{$from:o,$to:r,depth:i}=t,s=o.before(i+1),l=r.after(i+1),a=s,c=l,d=Rn.empty,u=0;for(let f=i,m=!1;f>n;f--)m||o.index(f)>0?(m=!0,d=Rn.from(o.node(f).copy(d)),u++):a--;let h=Rn.empty,p=0;for(let f=i,m=!1;f>n;f--)m||r.after(f+1)<r.end(f)?(m=!0,h=Rn.from(r.node(f).copy(h)),p++):c++;e.step(new Jo(a,c,s,l,new _n(d.append(h),u,p),d.size-u,!0))}(this,e,t),this}join(e,t=1){return function(e,t,n){let o=null,{linebreakReplacement:r}=e.doc.type.schema,i=e.doc.resolve(t-n),s=i.node().type;if(r&&s.inlineContent){let e="pre"==s.whitespace,t=!!s.contentMatch.matchType(r);e&&!t?o=!1:!e&&t&&(o=!0)}let l=e.steps.length;if(!1===o){let o=e.doc.resolve(t+n);rr(e,o.node(),o.before(),l)}s.inlineContent&&Yo(e,t+n-1,s,i.node().contentMatchAt(i.index()),null==o);let a=e.mapping.slice(l),c=a.map(t-n);if(e.step(new Zo(c,a.map(t+n,-1),_n.empty,!0)),!0===o){let t=e.doc.resolve(c);or(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return function(e,t,n){let o=Rn.empty;for(let s=n.length-1;s>=0;s--){if(o.size){let e=n[s].type.contentMatch.matchFragment(o);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}o=Rn.from(n[s].type.create(n[s].attrs,o))}let r=t.start,i=t.end;e.step(new Jo(r,i,r,i,new _n(o,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,o=null){return function(e,t,n,o,r){if(!o.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let i=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let s="function"==typeof r?r(t):r;if(t.isTextblock&&!t.hasMarkup(o,s)&&function(e,t,n){let o=e.resolve(t),r=o.index();return o.parent.canReplaceWith(r,r+1,n)}(e.doc,e.mapping.slice(i).map(n),o)){let r=null;if(o.schema.linebreakReplacement){let e="pre"==o.whitespace,t=!!o.contentMatch.matchType(o.schema.linebreakReplacement);e&&!t?r=!1:!e&&t&&(r=!0)}!1===r&&rr(e,t,n,i),Yo(e,e.mapping.slice(i).map(n,1),o,void 0,null===r);let l=e.mapping.slice(i),a=l.map(n,1),c=l.map(n+t.nodeSize,1);return e.step(new Jo(a,c,a+1,c-1,new _n(Rn.from(o.create(s,null,t.marks)),0,0),1,!0)),!0===r&&or(e,t,n,i),!1}})}(this,e,t,n,o),this}setNodeMarkup(e,t,n=null,o){return function(e,t,n,o,r){let i=e.doc.nodeAt(t);if(!i)throw new RangeError("No node at given position");n||(n=i.type);let s=n.create(o,null,r||i.marks);if(i.isLeaf)return e.replaceWith(t,t+i.nodeSize,s);if(!n.validContent(i.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new Jo(t,t+i.nodeSize,t+1,t+i.nodeSize-1,new _n(Rn.from(s),0,0),1,!0))}(this,e,t,n,o),this}setNodeAttribute(e,t,n){return this.step(new wr(e,t,n)),this}setDocAttribute(e,t){return this.step(new kr(e,t)),this}addNodeMark(e,t){return this.step(new Go(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof An)t.isInSet(n.marks)&&this.step(new Ko(e,t));else{let o,r=n.marks,i=[];for(;o=t.isInSet(r);)i.push(new Ko(e,o)),r=o.removeFromSet(r);for(let e=i.length-1;e>=0;e--)this.step(i[e])}return this}split(e,t=1,n){return function(e,t,n=1,o){let r=e.doc.resolve(t),i=Rn.empty,s=Rn.empty;for(let l=r.depth,a=r.depth-n,c=n-1;l>a;l--,c--){i=Rn.from(r.node(l).copy(i));let e=o&&o[c];s=Rn.from(e?e.type.create(e.attrs,s):r.node(l).copy(s))}e.step(new Zo(t,t,new _n(i.append(s),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){return function(e,t,n,o){let r,i,s=[],l=[];e.doc.nodesBetween(t,n,(e,a,c)=>{if(!e.isInline)return;let d=e.marks;if(!o.isInSet(d)&&c.type.allowsMarkType(o.type)){let c=Math.max(a,t),u=Math.min(a+e.nodeSize,n),h=o.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(h)||(r&&r.to==c&&r.mark.eq(d[e])?r.to=u:s.push(r=new qo(c,u,d[e])));i&&i.to==c?i.to=u:l.push(i=new Wo(c,u,o))}}),s.forEach(t=>e.step(t)),l.forEach(t=>e.step(t))}(this,e,t,n),this}removeMark(e,t,n){return function(e,t,n,o){let r=[],i=0;e.doc.nodesBetween(t,n,(e,s)=>{if(!e.isInline)return;i++;let l=null;if(o instanceof go){let t,n=e.marks;for(;t=o.isInSet(n);)(l||(l=[])).push(t),n=t.removeFromSet(n)}else o?o.isInSet(e.marks)&&(l=[o]):l=e.marks;if(l&&l.length){let o=Math.min(s+e.nodeSize,n);for(let e=0;e<l.length;e++){let n,a=l[e];for(let e=0;e<r.length;e++){let t=r[e];t.step==i-1&&a.eq(r[e].style)&&(n=t)}n?(n.to=o,n.step=i):r.push({style:a,from:Math.max(s,t),to:o,step:i})}}}),r.forEach(t=>e.step(new qo(t.from,t.to,t.style)))}(this,e,t,n),this}clearIncompatible(e,t,n){return Yo(this,e,t,n),this}}const Sr=Object.create(null);class Mr{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Rr(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=_n.empty){let n=t.content.lastChild,o=null;for(let s=0;s<t.openEnd;s++)o=n,n=n.lastChild;let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:l,$to:a}=i[s],c=e.mapping.slice(r);e.replaceRange(c.map(l.pos),c.map(a.pos),s?_n.empty:t),0==s&&Dr(e,r,(n?n.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,o=this.ranges;for(let r=0;r<o.length;r++){let{$from:i,$to:s}=o[r],l=e.mapping.slice(n),a=l.map(i.pos),c=l.map(s.pos);r?e.deleteRange(a,c):(e.replaceRangeWith(a,c,t),Dr(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let o=e.parent.inlineContent?new Nr(e):Lr(e.node(0),e.parent,e.pos,e.index(),t,n);if(o)return o;for(let r=e.depth-1;r>=0;r--){let o=t<0?Lr(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):Lr(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Pr(e.node(0))}static atStart(e){return Lr(e,e,0,0,1)||new Pr(e)}static atEnd(e){return Lr(e,e,e.content.size,e.childCount,-1)||new Pr(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Sr[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in Sr)throw new RangeError("Duplicate use of selection JSON ID "+e);return Sr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Nr.between(this.$anchor,this.$head).getBookmark()}}Mr.prototype.visible=!0;class Rr{constructor(e,t){this.$from=e,this.$to=t}}let Tr=!1;function jr(e){Tr||e.parent.inlineContent||(Tr=!0)}class Nr extends Mr{constructor(e,t=e){jr(e),jr(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return Mr.near(n);let o=e.resolve(t.map(this.anchor));return new Nr(o.parent.inlineContent?o:n,n)}replace(e,t=_n.empty){if(super.replace(e,t),t==_n.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof Nr&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Ar(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new Nr(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let o=e.resolve(t);return new this(o,n==t?o:e.resolve(n))}static between(e,t,n){let o=e.pos-t.pos;if(n&&!o||(n=o>=0?1:-1),!t.parent.inlineContent){let e=Mr.findFrom(t,n,!0)||Mr.findFrom(t,-n,!0);if(!e)return Mr.near(t,n);t=e.$head}return e.parent.inlineContent||(0==o||(e=(Mr.findFrom(e,-n,!0)||Mr.findFrom(e,n,!0)).$anchor).pos<t.pos!=o<0)&&(e=t),new Nr(e,t)}}Mr.jsonID("text",Nr);class Ar{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Ar(e.map(this.anchor),e.map(this.head))}resolve(e){return Nr.between(e.resolve(this.anchor),e.resolve(this.head))}}class Or extends Mr{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:o}=t.mapResult(this.anchor),r=e.resolve(o);return n?Mr.near(r):new Or(r)}content(){return new _n(Rn.from(this.node),0,0)}eq(e){return e instanceof Or&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new _r(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Or(e.resolve(t.anchor))}static create(e,t){return new Or(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}Or.prototype.visible=!1,Mr.jsonID("node",Or);class _r{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Ar(n,n):new _r(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&Or.isSelectable(n)?new Or(t):Mr.near(t)}}class Pr extends Mr{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=_n.empty){if(t==_n.empty){e.delete(0,e.doc.content.size);let t=Mr.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new Pr(e)}map(e){return new Pr(e)}eq(e){return e instanceof Pr}getBookmark(){return Ir}}Mr.jsonID("all",Pr);const Ir={map(){return this},resolve:e=>new Pr(e)};function Lr(e,t,n,o,r,i=!1){if(t.inlineContent)return Nr.create(e,n);for(let s=o-(r>0?0:1);r>0?s<t.childCount:s>=0;s+=r){let o=t.child(s);if(o.isAtom){if(!i&&Or.isSelectable(o))return Or.create(e,n-(r<0?o.nodeSize:0))}else{let t=Lr(e,o,n+r,r<0?o.childCount:0,r,i);if(t)return t}n+=o.nodeSize*r}return null}function Dr(e,t,n){let o=e.steps.length-1;if(o<t)return;let r,i=e.steps[o];(i instanceof Zo||i instanceof Jo)&&(e.mapping.maps[o].forEach((e,t,n,o)=>{null==r&&(r=o)}),e.setSelection(Mr.near(e.doc.resolve(r),n)))}let Br=class extends Er{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=-3&this.updated|1,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return An.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(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,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)||An.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let o=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(o.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),n=null==n?t:n,!e)return this.deleteRange(t,n);let r=this.storedMarks;if(!r){let e=this.doc.resolve(t);r=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,o.text(e,r)),this.selection.empty||this.setSelection(Mr.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}};function Hr(e,t){return t&&e?e.bind(t):e}class Vr{constructor(e,t,n){this.name=e,this.init=Hr(t.init,n),this.apply=Hr(t.apply,n)}}const $r=[new Vr("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new Vr("selection",{init:(e,t)=>e.selection||Mr.atStart(t.doc),apply:e=>e.selection}),new Vr("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,o)=>o.selection.$cursor?e.storedMarks:null}),new Vr("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class zr{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=$r.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw new 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 Vr(e.key,e.spec.state,e))})}}class Fr{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),o=null;for(;;){let r=!1;for(let i=0;i<this.config.plugins.length;i++){let s=this.config.plugins[i];if(s.spec.appendTransaction){let l=o?o[i].n:0,a=o?o[i].state:this,c=l<t.length&&s.spec.appendTransaction.call(s,l?t.slice(l):t,a,n);if(c&&n.filterTransaction(c,i)){if(c.setMeta("appendedTransaction",e),!o){o=[];for(let e=0;e<this.config.plugins.length;e++)o.push(e<i?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),r=!0}o&&(o[i]={state:n,n:t.length})}}if(!r)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new Fr(this.config),n=this.config.fields;for(let o=0;o<n.length;o++){let r=n[o];t[r.name]=r.apply(e,this[r.name],this,t)}return t}get tr(){return new Br(this)}static create(e){let t=new zr(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new Fr(t);for(let o=0;o<t.fields.length;o++)n[t.fields[o].name]=t.fields[o].init(e,n);return n}reconfigure(e){let t=new zr(this.schema,e.plugins),n=t.fields,o=new Fr(t);for(let r=0;r<n.length;r++){let t=n[r].name;o[t]=this.hasOwnProperty(t)?this[t]:n[r].init(e,o)}return o}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let o=e[n],r=o.spec.state;r&&r.toJSON&&(t[n]=r.toJSON.call(o,this[o.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let o=new zr(e.schema,e.plugins),r=new Fr(o);return o.fields.forEach(o=>{if("doc"==o.name)r.doc=Xn.fromJSON(e.schema,t.doc);else if("selection"==o.name)r.selection=Mr.fromJSON(r.doc,t.selection);else if("storedMarks"==o.name)t.storedMarks&&(r.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let i in n){let s=n[i],l=s.spec.state;if(s.key==o.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(t,i))return void(r[o.name]=l.fromJSON.call(s,e,t[i],r))}r[o.name]=o.init(e,r)}}),r}}function Ur(e,t,n){for(let o in e){let r=e[o];r instanceof Function?r=r.bind(t):"handleDOMEvents"==o&&(r=Ur(r,t,{})),n[o]=r}return n}class Wr{constructor(e){this.spec=e,this.props={},e.props&&Ur(e.props,this,this.props),this.key=e.key?e.key.key:Gr("plugin")}getState(e){return e[this.key]}}const qr=Object.create(null);function Gr(e){return e in qr?e+"$"+ ++qr[e]:(qr[e]=0,e+"$")}class Kr{constructor(e="key"){this.key=Gr(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Zr=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},Jr=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t};let Xr=null;const Yr=function(e,t,n){let o=Xr||(Xr=document.createRange());return o.setEnd(e,null==n?e.nodeValue.length:n),o.setStart(e,t||0),o},Qr=function(e,t,n,o){return n&&(ti(e,t,n,o,-1)||ti(e,t,n,o,1))},ei=/^(img|br|input|textarea|hr)$/i;function ti(e,t,n,o,r){for(var i;;){if(e==n&&t==o)return!0;if(t==(r<0?0:ni(e))){let n=e.parentNode;if(!n||1!=n.nodeType||oi(e)||ei.test(e.nodeName)||"false"==e.contentEditable)return!1;t=Zr(e)+(r<0?0:1),e=n}else{if(1!=e.nodeType)return!1;{let n=e.childNodes[t+(r<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable){if(!(null===(i=n.pmViewDesc)||void 0===i?void 0:i.ignoreForSelection))return!1;t+=r}else e=n,t=r<0?ni(e):0}}}}function ni(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function oi(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}const ri=function(e){return e.focusNode&&Qr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function ii(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}const si="undefined"!=typeof navigator?navigator:null,li="undefined"!=typeof document?document:null,ai=si&&si.userAgent||"",ci=/Edge\/(\d+)/.exec(ai),di=/MSIE \d/.exec(ai),ui=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ai),hi=!!(di||ui||ci),pi=di?document.documentMode:ui?+ui[1]:ci?+ci[1]:0,fi=!hi&&/gecko\/(\d+)/i.test(ai);fi&&(/Firefox\/(\d+)/.exec(ai)||[0,0])[1];const mi=!hi&&/Chrome\/(\d+)/.exec(ai),gi=!!mi,yi=mi?+mi[1]:0,bi=!hi&&!!si&&/Apple Computer/.test(si.vendor),vi=bi&&(/Mobile\/\w+/.test(ai)||!!si&&si.maxTouchPoints>2),xi=vi||!!si&&/Mac/.test(si.platform),wi=!!si&&/Win/.test(si.platform),ki=/Android \d/.test(ai),Ci=!!li&&"webkitFontSmoothing"in li.documentElement.style,Ei=Ci?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Si(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 Mi(e,t){return"number"==typeof e?e:e[t]}function Ri(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,o=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*o}}function Ti(e,t,n){let o=e.someProp("scrollThreshold")||0,r=e.someProp("scrollMargin")||5,i=e.dom.ownerDocument;for(let s=n||e.dom;s;){if(1!=s.nodeType){s=Jr(s);continue}let e=s,n=e==i.body,l=n?Si(i):Ri(e),a=0,c=0;if(t.top<l.top+Mi(o,"top")?c=-(l.top-t.top+Mi(r,"top")):t.bottom>l.bottom-Mi(o,"bottom")&&(c=t.bottom-t.top>l.bottom-l.top?t.top+Mi(r,"top")-l.top:t.bottom-l.bottom+Mi(r,"bottom")),t.left<l.left+Mi(o,"left")?a=-(l.left-t.left+Mi(r,"left")):t.right>l.right-Mi(o,"right")&&(a=t.right-l.right+Mi(r,"right")),a||c)if(n)i.defaultView.scrollBy(a,c);else{let n=e.scrollLeft,o=e.scrollTop;c&&(e.scrollTop+=c),a&&(e.scrollLeft+=a);let r=e.scrollLeft-n,i=e.scrollTop-o;t={left:t.left-r,top:t.top-i,right:t.right-r,bottom:t.bottom-i}}let d=n?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s="absolute"==d?s.offsetParent:Jr(s)}}function ji(e){let t=[],n=e.ownerDocument;for(let o=e;o&&(t.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),e!=n);o=Jr(o));return t}function Ni(e,t){for(let n=0;n<e.length;n++){let{dom:o,top:r,left:i}=e[n];o.scrollTop!=r+t&&(o.scrollTop=r+t),o.scrollLeft!=i&&(o.scrollLeft=i)}}let Ai=null;function Oi(e,t){let n,o,r,i,s=2e8,l=0,a=t.top,c=t.top;for(let d=e.firstChild,u=0;d;d=d.nextSibling,u++){let e;if(1==d.nodeType)e=d.getClientRects();else{if(3!=d.nodeType)continue;e=Yr(d).getClientRects()}for(let h=0;h<e.length;h++){let p=e[h];if(p.top<=a&&p.bottom>=c){a=Math.max(p.bottom,a),c=Math.min(p.top,c);let e=p.left>t.left?p.left-t.left:p.right<t.left?t.left-p.right:0;if(e<s){n=d,s=e,o=e&&3==n.nodeType?{left:p.right<t.left?p.right:p.left,top:t.top}:t,1==d.nodeType&&e&&(l=u+(t.left>=(p.left+p.right)/2?1:0));continue}}else p.top>t.top&&!r&&p.left<=t.left&&p.right>=t.left&&(r=d,i={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)&&(l=u+1)}}return!n&&r&&(n=r,o=i,s=0),n&&3==n.nodeType?function(e,t){let n=e.nodeValue.length,o=document.createRange();for(let r=0;r<n;r++){o.setEnd(e,r+1),o.setStart(e,r);let n=Di(o,1);if(n.top!=n.bottom&&_i(t,n))return{node:e,offset:r+(t.left>=(n.left+n.right)/2?1:0)}}return{node:e,offset:0}}(n,o):!n||s&&1==n.nodeType?{node:e,offset:l}:Oi(n,o)}function _i(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Pi(e,t,n){let o=e.childNodes.length;if(o&&n.top<n.bottom)for(let r=Math.max(0,Math.min(o-1,Math.floor(o*(t.top-n.top)/(n.bottom-n.top))-2)),i=r;;){let n=e.childNodes[i];if(1==n.nodeType){let e=n.getClientRects();for(let o=0;o<e.length;o++){let r=e[o];if(_i(t,r))return Pi(n,t,r)}}if((i=(i+1)%o)==r)break}return e}function Ii(e,t){let n,o=e.dom.ownerDocument,r=0,i=function(e,t,n){if(e.caretPositionFromPoint)try{let o=e.caretPositionFromPoint(t,n);if(o)return{node:o.offsetNode,offset:Math.min(ni(o.offsetNode),o.offset)}}catch(o){}if(e.caretRangeFromPoint){let o=e.caretRangeFromPoint(t,n);if(o)return{node:o.startContainer,offset:Math.min(ni(o.startContainer),o.startOffset)}}}(o,t.left,t.top);i&&({node:n,offset:r}=i);let s,l=(e.root.elementFromPoint?e.root:o).elementFromPoint(t.left,t.top);if(!l||!e.dom.contains(1!=l.nodeType?l.parentNode:l)){let n=e.dom.getBoundingClientRect();if(!_i(t,n))return null;if(l=Pi(e.dom,t,n),!l)return null}if(bi)for(let c=l;n&&c;c=Jr(c))c.draggable&&(n=void 0);if(l=function(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}(l,t),n){if(fi&&1==n.nodeType&&(r=Math.min(r,n.childNodes.length),r<n.childNodes.length)){let e,o=n.childNodes[r];"IMG"==o.nodeName&&(e=o.getBoundingClientRect()).right<=t.left&&e.bottom>t.top&&r++}let o;Ci&&r&&1==n.nodeType&&1==(o=n.childNodes[r-1]).nodeType&&"false"==o.contentEditable&&o.getBoundingClientRect().top>=t.top&&r--,n==e.dom&&r==n.childNodes.length-1&&1==n.lastChild.nodeType&&t.top>n.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:0!=r&&1==n.nodeType&&"BR"==n.childNodes[r-1].nodeName||(s=function(e,t,n,o){let r=-1;for(let i=t,s=!1;i!=e.dom;){let t,n=e.docView.nearestDesc(i,!0);if(!n)return null;if(1==n.dom.nodeType&&(n.node.isBlock&&n.parent||!n.contentDOM)&&((t=n.dom.getBoundingClientRect()).width||t.height)&&(n.node.isBlock&&n.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(n.dom.nodeName)&&(!s&&t.left>o.left||t.top>o.top?r=n.posBefore:(!s&&t.right<o.left||t.bottom<o.top)&&(r=n.posAfter),s=!0),!n.contentDOM&&r<0&&!n.node.isText))return(n.node.isBlock?o.top<(t.top+t.bottom)/2:o.left<(t.left+t.right)/2)?n.posBefore:n.posAfter;i=n.dom.parentNode}return r>-1?r:e.docView.posFromDOM(t,n,-1)}(e,n,r,t))}null==s&&(s=function(e,t,n){let{node:o,offset:r}=Oi(t,n),i=-1;if(1==o.nodeType&&!o.firstChild){let e=o.getBoundingClientRect();i=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(o,r,i)}(e,l,t));let a=e.docView.nearestDesc(l,!0);return{pos:s,inside:a?a.posAtStart-a.border:-1}}function Li(e){return e.top<e.bottom||e.left<e.right}function Di(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(Li(e))return e}return Array.prototype.find.call(n,Li)||e.getBoundingClientRect()}const Bi=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Hi(e,t,n){let{node:o,offset:r,atom:i}=e.docView.domFromPos(t,n<0?-1:1),s=Ci||fi;if(3==o.nodeType){if(!s||!Bi.test(o.nodeValue)&&(n<0?r:r!=o.nodeValue.length)){let e=r,t=r,i=n<0?1:-1;return n<0&&!r?(t++,i=-1):n>=0&&r==o.nodeValue.length?(e--,i=1):n<0?e--:t++,Vi(Di(Yr(o,e,t),i),i<0)}{let e=Di(Yr(o,r,r),n);if(fi&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let t=Di(Yr(o,r-1,r-1),-1);if(t.top==e.top){let n=Di(Yr(o,r,r+1),-1);if(n.top!=e.top)return Vi(n,n.left<t.left)}}return e}}if(!e.state.doc.resolve(t-(i||0)).parent.inlineContent){if(null==i&&r&&(n<0||r==ni(o))){let e=o.childNodes[r-1];if(1==e.nodeType)return $i(e.getBoundingClientRect(),!1)}if(null==i&&r<ni(o)){let e=o.childNodes[r];if(1==e.nodeType)return $i(e.getBoundingClientRect(),!0)}return $i(o.getBoundingClientRect(),n>=0)}if(null==i&&r&&(n<0||r==ni(o))){let e=o.childNodes[r-1],t=3==e.nodeType?Yr(e,ni(e)-(s?0:1)):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return Vi(Di(t,1),!1)}if(null==i&&r<ni(o)){let e=o.childNodes[r];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?Yr(e,0,s?0:1):1==e.nodeType?e:null:null;if(t)return Vi(Di(t,-1),!0)}return Vi(Di(3==o.nodeType?Yr(o):o,-n),n>=0)}function Vi(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function $i(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function zi(e,t,n){let o=e.state,r=e.root.activeElement;o!=t&&e.updateState(t),r!=e.dom&&e.focus();try{return n()}finally{o!=t&&e.updateState(o),r!=e.dom&&r&&r.focus()}}const Fi=/[\u0590-\u08ac]/;let Ui=null,Wi=null,qi=!1;function Gi(e,t,n){return Ui==t&&Wi==n?qi:(Ui=t,Wi=n,qi="up"==n||"down"==n?function(e,t,n){let o=t.selection,r="up"==n?o.$from:o.$to;return zi(e,t,()=>{let{node:t}=e.docView.domFromPos(r.pos,"up"==n?-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 o=Hi(e,r.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=Yr(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let r=t[e];if(r.bottom>r.top+1&&("up"==n?o.top-r.top>2*(r.bottom-o.top):r.bottom-o.bottom>2*(o.bottom-r.top)))return!1}}return!0})}(e,t,n):function(e,t,n){let{$head:o}=t.selection;if(!o.parent.isTextblock)return!1;let r=o.parentOffset,i=!r,s=r==o.parent.content.size,l=e.domSelection();return l?Fi.test(o.parent.textContent)&&l.modify?zi(e,t,()=>{let{focusNode:t,focusOffset:r,anchorNode:i,anchorOffset:s}=e.domSelectionRange(),a=l.caretBidiLevel;l.modify("move",n,"character");let c=o.depth?e.docView.domAfterPos(o.before()):e.dom,{focusNode:d,focusOffset:u}=e.domSelectionRange(),h=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&r==u;try{l.collapse(i,s),t&&(t!=i||r!=s)&&l.extend&&l.extend(t,r)}catch(p){}return null!=a&&(l.caretBidiLevel=a),h}):"left"==n||"backward"==n?i:s:o.pos==o.start()||o.pos==o.end()}(e,t,n))}class Ki{constructor(e,t,n,o){this.parent=e,this.children=t,this.dom=n,this.contentDOM=o,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){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 o=this.children[t];if(o==e)return n;n+=o.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&&this.contentDOM.contains(1==e.nodeType?e:e.parentNode)){if(n<0){let n,o;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.previousSibling;return n?this.posBeforeChild(o)+o.size:this.posAtStart}{let n,o;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.nextSibling;return n?this.posBeforeChild(o):this.posAtEnd}}let o;if(e==this.dom&&this.contentDOM)o=t>Zr(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))o=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!1;break}if(t.previousSibling)break}if(null==o&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!0;break}if(t.nextSibling)break}}return(null==o?n>0:o)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,o=e;o;o=o.parentNode){let r,i=this.getDesc(o);if(i&&(!t||i.node)){if(!n||!(r=i.nodeDOM)||(1==r.nodeType?r.contains(1==e.nodeType?e:e.parentNode):r==e))return i;n=!1}}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let o=e;o;o=o.parentNode){let r=this.getDesc(o);if(r)return r.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let o=this.children[t],r=n+o.size;if(n==e&&r!=n){for(;!o.border&&o.children.length;)for(let e=0;e<o.children.length;e++){let t=o.children[e];if(t.size){o=t;break}}return o}if(e<r)return o.descAt(e-n-o.border);n=r}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,o=0;for(let r=0;n<this.children.length;n++){let t=this.children[n],i=r+t.size;if(i>e||t instanceof ts){o=e-r;break}r=i}if(o)return this.children[n].domFromPos(o-this.children[n].border,t);for(let r;n&&!(r=this.children[n-1]).size&&r instanceof Zi&&r.side>=0;n--);if(t<=0){let e,o=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,o=!1);return e&&t&&o&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Zr(e.dom)+1:0}}{let e,o=!0;for(;e=n<this.children.length?this.children[n]:null,e&&e.dom.parentNode!=this.contentDOM;n++,o=!1);return e&&o&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?Zr(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(0==this.children.length)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let o=-1,r=-1;for(let i=n,s=0;;s++){let n=this.children[s],l=i+n.size;if(-1==o&&e<=l){let r=i+n.border;if(e>=r&&t<=l-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,r);e=i;for(let t=s;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){o=Zr(n.dom)+1;break}e-=n.size}-1==o&&(o=0)}if(o>-1&&(l>t||s==this.children.length-1)){t=l;for(let e=s+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){r=Zr(n.dom);break}t+=n.size}-1==r&&(r=this.contentDOM.childNodes.length);break}i=l}return{node:this.contentDOM,from:e,to:t,fromOffset:o,toOffset:r}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return 0==t.size||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(1!=t.nodeType||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,o=!1){let r=Math.min(e,t),i=Math.max(e,t);for(let p=0,f=0;p<this.children.length;p++){let s=this.children[p],l=f+s.size;if(r>f&&i<l)return s.setSelection(e-f-s.border,t-f-s.border,n,o);f=l}let s=this.domFromPos(e,e?-1:1),l=t==e?s:this.domFromPos(t,t?-1:1),a=n.root.getSelection(),c=n.domSelectionRange(),d=!1;if((fi||bi)&&e==t){let{node:e,offset:t}=s;if(3==e.nodeType){if(d=!(!t||"\n"!=e.nodeValue[t-1]),d&&t==e.nodeValue.length)for(let n,o=e;o;o=o.parentNode){if(n=o.nextSibling){"BR"==n.nodeName&&(s=l={node:n.parentNode,offset:Zr(n)+1});break}let e=o.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(fi&&c.focusNode&&c.focusNode!=l.node&&1==c.focusNode.nodeType){let e=c.focusNode.childNodes[c.focusOffset];e&&"false"==e.contentEditable&&(o=!0)}if(!(o||d&&bi)&&Qr(s.node,s.offset,c.anchorNode,c.anchorOffset)&&Qr(l.node,l.offset,c.focusNode,c.focusOffset))return;let u=!1;if((a.extend||e==t)&&(!d||!fi)){a.collapse(s.node,s.offset);try{e!=t&&a.extend(l.node,l.offset),u=!0}catch(h){}}if(!u){if(e>t){let e=s;s=l,l=e}let n=document.createRange();n.setEnd(l.node,l.offset),n.setStart(s.node,s.offset),a.removeAllRanges(),a.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,o=0;o<this.children.length;o++){let r=this.children[o],i=n+r.size;if(n==i?e<=i&&t>=n:e<i&&t>n){let o=n+r.border,s=i-r.border;if(e>=o&&t<=s)return this.dirty=e==n||t==i?2:1,void(e!=o||t!=s||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(e-o,t-o):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.children.length?3:2}n=i}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Zi extends Ki{constructor(e,t,n,o){let r,i=t.type.toDOM;if("function"==typeof i&&(i=i(n,()=>r?r.parent?r.parent.posBeforeChild(r):void 0:o)),!t.type.spec.raw){if(1!=i.nodeType){let e=document.createElement("span");e.appendChild(i),i=e}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,r=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||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}}class Ji extends Ki{constructor(e,t,n,o){super(e,[],t,null),this.textDOM=n,this.text=o}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class Xi extends Ki{constructor(e,t,n,o,r){super(e,[],n,o),this.mark=t,this.spec=r}static create(e,t,n,o){let r=o.nodeViews[t.type.name],i=r&&r(t,o,n);return i&&i.dom||(i=jo.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new Xi(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=0}}slice(e,t,n){let o=Xi.create(this.parent,this.mark,!0,n),r=this.children,i=this.size;t<i&&(r=ms(r,t,i,n)),e>0&&(r=ms(r,0,e,n));for(let s=0;s<r.length;s++)r[s].parent=o;return o.children=r,o}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Yi extends Ki{constructor(e,t,n,o,r,i,s,l,a){super(e,[],r,i),this.node=t,this.outerDeco=n,this.innerDeco=o,this.nodeDOM=s}static create(e,t,n,o,r,i){let s,l=r.nodeViews[t.type.name],a=l&&l(t,r,()=>s?s.parent?s.parent.posBeforeChild(s):void 0:i,n,o),c=a&&a.dom,d=a&&a.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(t.text);else if(!c){let e=jo.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:d}=e)}d||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return c=ds(c,n,t),a?s=new ns(e,t,n,o,c,d||null,u,a,r,i+1):t.isText?new es(e,t,n,o,c,u,r):new Yi(e,t,n,o,c,d||null,u,r,i+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>Rn.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&us(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,o=t,r=e.composing?this.localCompositionInfo(e,t):null,i=r&&r.pos>-1?r:null,s=r&&r.pos<0,l=new ps(this,i&&i.node,e);!function(e,t,n,o){let r=t.locals(e),i=0;if(0==r.length){for(let n=0;n<e.childCount;n++){let s=e.child(n);o(s,r,t.forChild(i,s),n),i+=s.nodeSize}return}let s=0,l=[],a=null;for(let c=0;;){let d,u,h,p;for(;s<r.length&&r[s].to==i;){let e=r[s++];e.widget&&(d?(u||(u=[d])).push(e):d=e)}if(d)if(u){u.sort(fs);for(let e=0;e<u.length;e++)n(u[e],c,!!a)}else n(d,c,!!a);if(a)p=-1,h=a,a=null;else{if(!(c<e.childCount))break;p=c,h=e.child(c++)}for(let e=0;e<l.length;e++)l[e].to<=i&&l.splice(e--,1);for(;s<r.length&&r[s].from<=i&&r[s].to>i;)l.push(r[s++]);let f=i+h.nodeSize;if(h.isText){let e=f;s<r.length&&r[s].from<e&&(e=r[s].from);for(let t=0;t<l.length;t++)l[t].to<e&&(e=l[t].to);e<f&&(a=h.cut(e-i),h=h.cut(0,e-i),f=e,p=-1)}else for(;s<r.length&&r[s].to<f;)s++;o(h,h.isInline&&!h.isLeaf?l.filter(e=>!e.inline):l.slice(),t.forChild(i,h),p),i=f}}(this.node,this.innerDeco,(t,r,i)=>{t.spec.marks?l.syncToMarks(t.spec.marks,n,e):t.type.side>=0&&!i&&l.syncToMarks(r==this.node.childCount?An.none:this.node.child(r).marks,n,e),l.placeWidget(t,e,o)},(t,i,a,c)=>{let d;l.syncToMarks(t.marks,n,e),l.findNodeMatch(t,i,a,c)||s&&e.state.selection.from>o&&e.state.selection.to<o+t.nodeSize&&(d=l.findIndexWithChild(r.node))>-1&&l.updateNodeAt(t,i,a,d,e)||l.updateNextNode(t,i,a,e,c,o)||l.addNode(t,i,a,e,o),o+=t.nodeSize}),l.syncToMarks([],n,e),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||2==this.dirty)&&(i&&this.protectLocalComposition(e,i),rs(this.contentDOM,this.children,e),vi&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:o}=e.state.selection;if(!(e.state.selection instanceof Nr)||n<t||o>t+this.node.content.size)return null;let r=e.input.compositionNode;if(!r||!this.dom.contains(r.parentNode))return null;if(this.node.inlineContent){let e=r.nodeValue,i=function(e,t,n,o){for(let r=0,i=0;r<e.childCount&&i<=o;){let s=e.child(r++),l=i;if(i+=s.nodeSize,!s.isText)continue;let a=s.text;for(;r<e.childCount;){let t=e.child(r++);if(i+=t.nodeSize,!t.isText)break;a+=t.text}if(i>=n){if(i>=o&&a.slice(o-t.length-l,o-l)==t)return o-t.length;let e=l<o?a.lastIndexOf(t,o-l-1):-1;if(e>=0&&e+t.length+l>=n)return l+e;if(n==o&&a.length>=o+t.length-l&&a.slice(o-l,o-l+t.length)==t)return o}}return-1}(this.node.content,e,n-t,o-t);return i<0?null:{node:r,pos:i,text:e}}return{node:r,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:o}){if(this.getDesc(t))return;let r=t;for(;r.parentNode!=this.contentDOM;r=r.parentNode){for(;r.previousSibling;)r.parentNode.removeChild(r.previousSibling);for(;r.nextSibling;)r.parentNode.removeChild(r.nextSibling);r.pmViewDesc&&(r.pmViewDesc=void 0)}let i=new Ji(this,r,t,o);e.input.compositionNodes.push(i),this.children=ms(this.children,n,n+o.length,e,i)}update(e,t,n,o){return!(3==this.dirty||!e.sameMarkup(this.node))&&(this.updateInner(e,t,n,o),!0)}updateInner(e,t,n,o){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(o,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(us(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=as(this.dom,this.nodeDOM,ls(this.outerDeco,this.node,t),ls(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Qi(e,t,n,o,r){ds(o,t,e);let i=new Yi(void 0,e,t,n,o,o,o,r,0);return i.contentDOM&&i.updateChildren(r,0),i}class es extends Yi{constructor(e,t,n,o,r,i,s){super(e,t,n,o,r,null,i,s,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,o){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!e.sameMarkup(this.node))&&(this.updateOuterDeco(t),0==this.dirty&&e.text==this.node.text||e.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=e.text,o.trackWrites==this.nodeDOM&&(o.trackWrites=null)),this.node=e,this.dirty=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"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let o=this.node.cut(e,t),r=document.createTextNode(o.text);return new es(this.parent,o,this.outerDeco,this.innerDeco,r,r,n)}markDirty(e,t){super.markDirty(e,t),this.dom==this.nodeDOM||0!=e&&t!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}isText(e){return this.node.text==e}}class ts extends Ki{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class ns extends Yi{constructor(e,t,n,o,r,i,s,l,a,c){super(e,t,n,o,r,i,s,a,c),this.spec=l}update(e,t,n,o){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let r=this.spec.update(e,t,n);return r&&this.updateInner(e,t,n,o),r}return!(!this.contentDOM&&!e.isLeaf)&&super.update(e,t,n,o)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,o){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,o)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function rs(e,t,n){let o=e.firstChild,r=!1;for(let i=0;i<t.length;i++){let s=t[i],l=s.dom;if(l.parentNode==e){for(;l!=o;)o=hs(o),r=!0;o=o.nextSibling}else r=!0,e.insertBefore(l,o);if(s instanceof Xi){let t=o?o.previousSibling:e.lastChild;rs(s.contentDOM,s.children,n),o=t?t.nextSibling:e.firstChild}}for(;o;)o=hs(o),r=!0;r&&n.trackWrites==e&&(n.trackWrites=null)}const is=function(e){e&&(this.nodeName=e)};is.prototype=Object.create(null);const ss=[new is];function ls(e,t,n){if(0==e.length)return ss;let o=n?ss[0]:new is,r=[o];for(let i=0;i<e.length;i++){let s=e[i].type.attrs;if(s){s.nodeName&&r.push(o=new is(s.nodeName));for(let e in s){let i=s[e];null!=i&&(n&&1==r.length&&r.push(o=new is(t.isInline?"span":"div")),"class"==e?o.class=(o.class?o.class+" ":"")+i:"style"==e?o.style=(o.style?o.style+";":"")+i:"nodeName"!=e&&(o[e]=i))}}}return r}function as(e,t,n,o){if(n==ss&&o==ss)return t;let r=t;for(let i=0;i<o.length;i++){let t=o[i],s=n[i];if(i){let n;s&&s.nodeName==t.nodeName&&r!=e&&(n=r.parentNode)&&n.nodeName.toLowerCase()==t.nodeName||(n=document.createElement(t.nodeName),n.pmIsDeco=!0,n.appendChild(r),s=ss[0]),r=n}cs(r,s||ss[0],t)}return r}function cs(e,t,n){for(let o in t)"class"==o||"style"==o||"nodeName"==o||o in n||e.removeAttribute(o);for(let o in n)"class"!=o&&"style"!=o&&"nodeName"!=o&&n[o]!=t[o]&&e.setAttribute(o,n[o]);if(t.class!=n.class){let o=t.class?t.class.split(" ").filter(Boolean):[],r=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<o.length;t++)-1==r.indexOf(o[t])&&e.classList.remove(o[t]);for(let t=0;t<r.length;t++)-1==o.indexOf(r[t])&&e.classList.add(r[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n,o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;n=o.exec(t.style);)e.style.removeProperty(n[1])}n.style&&(e.style.cssText+=n.style)}}function ds(e,t,n){return as(e,e,ss,ls(t,n,1!=e.nodeType))}function us(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 hs(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class ps{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=function(e,t){let n=t,o=n.children.length,r=e.childCount,i=new Map,s=[];e:for(;r>0;){let l;for(;;)if(o){let e=n.children[o-1];if(!(e instanceof Xi)){l=e,o--;break}n=e,o=e.children.length}else{if(n==t)break e;o=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=e.child(r-1))break;--r,i.set(l,r),s.push(l)}}return{index:r,matched:i,matches:s.reverse()}}(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){let o=0,r=this.stack.length>>1,i=Math.min(r,e.length);for(;o<i&&(o==r-1?this.top:this.stack[o+1<<1]).matchesMark(e[o])&&!1!==e[o].type.spec.spanning;)o++;for(;o<r;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),r--;for(;r<e.length;){this.stack.push(this.top,this.index+1);let o=-1;for(let t=this.index;t<Math.min(this.index+3,this.top.children.length);t++){let n=this.top.children[t];if(n.matchesMark(e[r])&&!this.isLocked(n.dom)){o=t;break}}if(o>-1)o>this.index&&(this.changed=!0,this.destroyBetween(this.index,o)),this.top=this.top.children[this.index];else{let o=Xi.create(this.top,e[r],t,n);this.top.children.splice(this.index,0,o),this.top=o,this.changed=!0}this.index=0,r++}}findNodeMatch(e,t,n,o){let r,i=-1;if(o>=this.preMatch.index&&(r=this.preMatch.matches[o-this.preMatch.index]).parent==this.top&&r.matchesNode(e,t,n))i=this.top.children.indexOf(r,this.index);else for(let s=this.index,l=Math.min(this.top.children.length,s+5);s<l;s++){let o=this.top.children[s];if(o.matchesNode(e,t,n)&&!this.preMatch.matched.has(o)){i=s;break}}return!(i<0)&&(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,o,r){let i=this.top.children[o];return 3==i.dirty&&i.dom==i.contentDOM&&(i.dirty=2),!!i.update(e,t,n,r)&&(this.destroyBetween(this.index,o),this.index++,!0)}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,o,r,i){for(let s=this.index;s<this.top.children.length;s++){let l=this.top.children[s];if(l instanceof Yi){let a=this.preMatch.matched.get(l);if(null!=a&&a!=r)return!1;let c,d=l.dom,u=this.isLocked(d)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&3!=l.dirty&&us(t,l.outerDeco));if(!u&&l.update(e,t,n,o))return this.destroyBetween(this.index,s),l.dom!=d&&(this.changed=!0),this.index++,!0;if(!u&&(c=this.recreateWrapper(l,e,t,n,o,i)))return this.destroyBetween(this.index,s),this.top.children[this.index]=c,c.contentDOM&&(c.dirty=2,c.updateChildren(o,i+1),c.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,o,r,i){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!us(n,e.outerDeco)||!o.eq(e.innerDeco))return null;let s=Yi.create(this.top,t,n,o,r,i);if(s.contentDOM){s.children=e.children,e.children=[];for(let e of s.children)e.parent=s}return e.destroy(),s}addNode(e,t,n,o,r){let i=Yi.create(this.top,e,t,n,o,r);i.contentDOM&&i.updateChildren(o,r+1),this.top.children.splice(this.index++,0,i),this.changed=!0}placeWidget(e,t,n){let o=this.index<this.top.children.length?this.top.children[this.index]:null;if(!o||!o.matchesWidget(e)||e!=o.widget&&o.widget.type.toDOM.parentNode){let o=new Zi(this.top,e,t,n);this.top.children.splice(this.index++,0,o),this.changed=!0}else this.index++}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Xi;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof es)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((bi||gi)&&e&&"false"==e.dom.contentEditable&&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);"IMG"==e&&(n.className="ProseMirror-separator",n.alt=""),"BR"==e&&(n.className="ProseMirror-trailingBreak");let o=new ts(this.top,[],n,null);t!=this.top?t.children.push(o):t.children.splice(this.index++,0,o),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function fs(e,t){return e.type.side-t.type.side}function ms(e,t,n,o,r){let i=[];for(let s=0,l=0;s<e.length;s++){let a=e[s],c=l,d=l+=a.size;c>=n||d<=t?i.push(a):(c<t&&i.push(a.slice(0,t-c,o)),r&&(i.push(r),r=void 0),d>n&&i.push(a.slice(n-c,a.size,o)))}return i}function gs(e,t=null){let n=e.domSelectionRange(),o=e.state.doc;if(!n.focusNode)return null;let r=e.docView.nearestDesc(n.focusNode),i=r&&0==r.size,s=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l,a,c=o.resolve(s);if(ri(n)){for(l=s;r&&!r.node;)r=r.parent;let e=r.node;if(r&&e.isAtom&&Or.isSelectable(e)&&r.parent&&(!e.isInline||!function(e,t,n){for(let o=0==t,r=t==ni(e);o||r;){if(e==n)return!0;let t=Zr(e);if(!(e=e.parentNode))return!1;o=o&&0==t,r=r&&t==ni(e)}}(n.focusNode,n.focusOffset,r.dom))){let e=r.posBefore;a=new Or(s==e?c:o.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=s,r=s;for(let o=0;o<n.rangeCount;o++){let i=n.getRangeAt(o);t=Math.min(t,e.docView.posFromDOM(i.startContainer,i.startOffset,1)),r=Math.max(r,e.docView.posFromDOM(i.endContainer,i.endOffset,-1))}if(t<0)return null;[l,s]=r==e.state.selection.anchor?[r,t]:[t,r],c=o.resolve(s)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=o.resolve(l);if(!a){a=Ss(e,d,c,"pointer"==t||e.state.selection.head<c.pos&&!i?1:-1)}return a}function ys(e){return e.editable?e.hasFocus():Rs(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function bs(e,t=!1){let n=e.state.selection;if(Cs(e,n),ys(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&gi){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&Qr(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset))return e.input.mouseDown.delayedSelectionSync=!0,void e.domObserver.setCurSelection()}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,o="IMG"==n.nodeName;o?t.collapse(n.parentNode,Zr(n)+1):t.collapse(n,0);!o&&!e.state.selection.visible&&hi&&pi<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let o,r,{anchor:i,head:s}=n;!vs||n instanceof Nr||(n.$from.parent.inlineContent||(o=xs(e,n.from)),n.empty||n.$from.parent.inlineContent||(r=xs(e,n.to))),e.docView.setSelection(i,s,e,t),vs&&(o&&ks(o),r&&ks(r)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(e){let t=e.dom.ownerDocument;t.removeEventListener("selectionchange",e.input.hideSelectionGuard);let n=e.domSelectionRange(),o=n.anchorNode,r=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==o&&n.anchorOffset==r||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{ys(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const vs=bi||gi&&yi<63;function xs(e,t){let{node:n,offset:o}=e.docView.domFromPos(t,0),r=o<n.childNodes.length?n.childNodes[o]:null,i=o?n.childNodes[o-1]:null;if(bi&&r&&"false"==r.contentEditable)return ws(r);if(!(r&&"false"!=r.contentEditable||i&&"false"!=i.contentEditable)){if(r)return ws(r);if(i)return ws(i)}}function ws(e){return e.contentEditable="true",bi&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function ks(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function Cs(e,t){if(t instanceof Or){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(Es(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else Es(e)}function Es(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function Ss(e,t,n,o){return e.someProp("createSelectionBetween",o=>o(e,t,n))||Nr.between(t,n,o)}function Ms(e){return!(e.editable&&!e.hasFocus())&&Rs(e)}function Rs(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(n){return!1}}function Ts(e,t){let{$anchor:n,$head:o}=e.selection,r=t>0?n.max(o):n.min(o),i=r.parent.inlineContent?r.depth?e.doc.resolve(t>0?r.after():r.before()):null:r;return i&&Mr.findFrom(i,t)}function js(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Ns(e,t,n){let o=e.state.selection;if(!(o instanceof Nr)){if(o instanceof Or&&o.node.isInline)return js(e,new Nr(t>0?o.$to:o.$from));{let n=Ts(e.state,t);return!!n&&js(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=o,r=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let i=e.state.doc.resolve(n.pos+r.nodeSize*(t<0?-1:1));return js(e,new Nr(o.$anchor,i))}if(!o.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Ts(e.state,t);return!!(n&&n instanceof Or)&&js(e,n)}if(!(xi&&n.indexOf("m")>-1)){let n,r=o.$head,i=r.textOffset?null:t<0?r.nodeBefore:r.nodeAfter;if(!i||i.isText)return!1;let s=t<0?r.pos-i.nodeSize:r.pos;return!!(i.isAtom||(n=e.docView.descAt(s))&&!n.contentDOM)&&(Or.isSelectable(i)?js(e,new Or(t<0?e.state.doc.resolve(r.pos-i.nodeSize):r)):!!Ci&&js(e,new Nr(e.state.doc.resolve(t<0?s:s+i.nodeSize))))}}function As(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Os(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function _s(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let r,i,s=!1;fi&&1==n.nodeType&&o<As(n)&&Os(n.childNodes[o],-1)&&(s=!0);for(;;)if(o>0){if(1!=n.nodeType)break;{let e=n.childNodes[o-1];if(Os(e,-1))r=n,i=--o;else{if(3!=e.nodeType)break;n=e,o=n.nodeValue.length}}}else{if(Ps(n))break;{let t=n.previousSibling;for(;t&&Os(t,-1);)r=n.parentNode,i=Zr(t),t=t.previousSibling;if(t)n=t,o=As(n);else{if(n=n.parentNode,n==e.dom)break;o=0}}}s?Is(e,n,o):r&&Is(e,r,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let r,i,s=As(n);for(;;)if(o<s){if(1!=n.nodeType)break;if(!Os(n.childNodes[o],1))break;r=n,i=++o}else{if(Ps(n))break;{let t=n.nextSibling;for(;t&&Os(t,1);)r=t.parentNode,i=Zr(t)+1,t=t.nextSibling;if(t)n=t,o=0,s=As(n);else{if(n=n.parentNode,n==e.dom)break;o=s=0}}}r&&Is(e,r,i)}(e)}function Ps(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Is(e,t,n){if(3!=t.nodeType){let e,o;(o=function(e,t){for(;e&&t==e.childNodes.length&&!oi(e);)t=Zr(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=o,n=0):(e=function(e,t){for(;e&&!t&&!oi(e);)t=Zr(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let o=e.domSelection();if(!o)return;if(ri(o)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),o.removeAllRanges(),o.addRange(e)}else o.extend&&o.extend(t,n);e.domObserver.setCurSelection();let{state:r}=e;setTimeout(()=>{e.state==r&&bs(e)},50)}function Ls(e,t){let n=e.state.doc.resolve(t);if(!gi&&!wi&&n.parent.inlineContent){let o=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),r=(n.top+n.bottom)/2;if(r>o.top&&r<o.bottom&&Math.abs(n.left-o.left)>1)return n.left<o.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),r=(n.top+n.bottom)/2;if(r>o.top&&r<o.bottom&&Math.abs(n.left-o.left)>1)return n.left>o.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function Ds(e,t,n){let o=e.state.selection;if(o instanceof Nr&&!o.empty||n.indexOf("s")>-1)return!1;if(xi&&n.indexOf("m")>-1)return!1;let{$from:r,$to:i}=o;if(!r.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Ts(e.state,t);if(n&&n instanceof Or)return js(e,n)}if(!r.parent.inlineContent){let n=t<0?r:i,s=o instanceof Pr?Mr.near(n,t):Mr.findFrom(n,t);return!!s&&js(e,s)}return!1}function Bs(e,t){if(!(e.state.selection instanceof Nr))return!0;let{$head:n,$anchor:o,empty:r}=e.state.selection;if(!n.sameParent(o))return!0;if(!r)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let i=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let o=e.state.tr;return t<0?o.delete(n.pos-i.nodeSize,n.pos):o.delete(n.pos,n.pos+i.nodeSize),e.dispatch(o),!0}return!1}function Hs(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Vs(e,t){let n=t.keyCode,o=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);if(8==n||xi&&72==n&&"c"==o)return Bs(e,-1)||_s(e,-1);if(46==n&&!t.shiftKey||xi&&68==n&&"c"==o)return Bs(e,1)||_s(e,1);if(13==n||27==n)return!0;if(37==n||xi&&66==n&&"c"==o){let t=37==n?"ltr"==Ls(e,e.state.selection.from)?-1:1:-1;return Ns(e,t,o)||_s(e,t)}if(39==n||xi&&70==n&&"c"==o){let t=39==n?"ltr"==Ls(e,e.state.selection.from)?1:-1:1;return Ns(e,t,o)||_s(e,t)}return 38==n||xi&&80==n&&"c"==o?Ds(e,-1,o)||_s(e,-1):40==n||xi&&78==n&&"c"==o?function(e){if(!bi||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;Hs(e,n,"true"),setTimeout(()=>Hs(e,n,"false"),20)}return!1}(e)||Ds(e,1,o)||_s(e,1):o==(xi?"m":"c")&&(66==n||73==n||89==n||90==n)}function $s(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:o,openStart:r,openEnd:i}=t;for(;r>1&&i>1&&1==o.childCount&&1==o.firstChild.childCount;){r--,i--;let e=o.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),o=e.content}let s=e.someProp("clipboardSerializer")||jo.fromSchema(e.state.schema),l=Xs(),a=l.createElement("div");a.appendChild(s.serializeFragment(o,{document:l}));let c,d=a.firstChild,u=0;for(;d&&1==d.nodeType&&(c=Zs[d.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=l.createElement(c[e]);for(;a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t),u++}d=a.firstChild}return d&&1==d.nodeType&&d.setAttribute("data-pm-slice",`${r} ${i}${u?` -${u}`:""} ${JSON.stringify(n)}`),{dom:a,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function zs(e,t,n,o,r){let i,s,l=r.parent.type.spec.code;if(!n&&!t)return null;let a=!!t&&(o||l||!n);if(a){if(e.someProp("transformPastedText",n=>{t=n(t,l||o,e)}),l)return s=new _n(Rn.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{s=t(s,e,!0)}),s;let n=e.someProp("clipboardTextParser",n=>n(t,r,o,e));if(n)s=n;else{let n=r.marks(),{schema:o}=e.state,s=jo.fromSchema(o);i=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=i.appendChild(document.createElement("p"));e&&t.appendChild(s.serializeNode(o.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),i=function(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,o=Xs().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(e);(n=r&&Zs[r[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join(""));if(o.innerHTML=function(e){let t=window.trustedTypes;if(!t)return e;Ys||(Ys=t.defaultPolicy||t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e}));return Ys.createHTML(e)}(e),n)for(let i=0;i<n.length;i++)o=o.querySelector(n[i])||o;return o}(n),Ci&&function(e){let t=e.querySelectorAll(gi?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let o=t[n];1==o.childNodes.length&&" "==o.textContent&&o.parentNode&&o.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),o)}}(i);let c=i&&i.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let u=+d[3];u>0;u--){let e=i.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;i=e}if(!s){let t=e.someProp("clipboardParser")||e.someProp("domParser")||vo.fromSchema(e.state.schema);s=t.parseSlice(i,{preserveWhitespace:!(!a&&!d),context:r,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||Fs.test(e.parentNode.nodeName)?null:{ignore:!0}})}if(d)s=function(e,t){if(!e.size)return e;let n,o=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(l){return e}let{content:r,openStart:i,openEnd:s}=e;for(let a=n.length-2;a>=0;a-=2){let e=o.nodes[n[a]];if(!e||e.hasRequiredAttrs())break;r=Rn.from(e.create(n[a+1],r)),i++,s++}return new _n(r,i,s)}(Ks(s,+d[1],+d[2]),d[4]);else if(s=_n.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let o,r=t.node(n).contentMatchAt(t.index(n)),i=[];if(e.forEach(e=>{if(!i)return;let t,n=r.findWrapping(e.type);if(!n)return i=null;if(t=i.length&&o.length&&Ws(n,o,e,i[i.length-1],0))i[i.length-1]=t;else{i.length&&(i[i.length-1]=qs(i[i.length-1],o.length));let t=Us(e,n);i.push(t),r=r.matchType(t.type),o=n}}),i)return Rn.from(i)}return e}(s.content,r),!0),s.openStart||s.openEnd){let e=0,t=0;for(let n=s.content.firstChild;e<s.openStart&&!n.type.spec.isolating;e++,n=n.firstChild);for(let n=s.content.lastChild;t<s.openEnd&&!n.type.spec.isolating;t++,n=n.lastChild);s=Ks(s,e,t)}return e.someProp("transformPasted",t=>{s=t(s,e,a)}),s}const Fs=/^(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 Us(e,t,n=0){for(let o=t.length-1;o>=n;o--)e=t[o].create(null,Rn.from(e));return e}function Ws(e,t,n,o,r){if(r<e.length&&r<t.length&&e[r]==t[r]){let i=Ws(e,t,n,o.lastChild,r+1);if(i)return o.copy(o.content.replaceChild(o.childCount-1,i));if(o.contentMatchAt(o.childCount).matchType(r==e.length-1?n.type:e[r+1]))return o.copy(o.content.append(Rn.from(Us(n,e,r+1))))}}function qs(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,qs(e.lastChild,t-1)),o=e.contentMatchAt(e.childCount).fillBefore(Rn.empty,!0);return e.copy(n.append(o))}function Gs(e,t,n,o,r,i){let s=t<0?e.firstChild:e.lastChild,l=s.content;return e.childCount>1&&(i=0),r<o-1&&(l=Gs(l,t,n,o,r+1,i)),r>=n&&(l=t<0?s.contentMatchAt(0).fillBefore(l,i<=r).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(Rn.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,s.copy(l))}function Ks(e,t,n){return t<e.openStart&&(e=new _n(Gs(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new _n(Gs(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}const Zs={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let Js=null;function Xs(){return Js||(Js=document.implementation.createHTMLDocument("title"))}let Ys=null;const Qs={},el={},tl={touchstart:!0,touchmove:!0};class nl{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function ol(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function rl(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>il(e,t))})}function il(e,t){return e.someProp("handleDOMEvents",n=>{let o=n[t.type];return!!o&&(o(e,t)||t.defaultPrevented)})}function sl(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||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function ll(e){return{left:e.clientX,top:e.clientY}}function al(e,t,n,o,r){if(-1==o)return!1;let i=e.state.doc.resolve(o);for(let s=i.depth+1;s>0;s--)if(e.someProp(t,t=>s>i.depth?t(e,n,i.nodeAfter,i.before(s),r,!0):t(e,n,i.node(s),i.before(s),r,!1)))return!0;return!1}function cl(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let o=e.state.tr.setSelection(t);o.setMeta("pointer",!0),e.dispatch(o)}function dl(e,t,n,o,r){return al(e,"handleClickOn",t,n,o)||e.someProp("handleClick",n=>n(e,t,o))||(r?function(e,t){if(-1==t)return!1;let n,o,r=e.state.selection;r instanceof Or&&(n=r.node);let i=e.state.doc.resolve(t);for(let s=i.depth+1;s>0;s--){let e=s>i.depth?i.nodeAfter:i.node(s);if(Or.isSelectable(e)){o=n&&r.$from.depth>0&&s>=r.$from.depth&&i.before(r.$from.depth+1)==r.$from.pos?i.before(r.$from.depth):i.before(s);break}}return null!=o&&(cl(e,Or.create(e.state.doc,o)),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),o=n.nodeAfter;return!!(o&&o.isAtom&&Or.isSelectable(o))&&(cl(e,new Or(n)),!0)}(e,n))}function ul(e,t,n,o){return al(e,"handleDoubleClickOn",t,n,o)||e.someProp("handleDoubleClick",n=>n(e,t,o))}function hl(e,t,n,o){return al(e,"handleTripleClickOn",t,n,o)||e.someProp("handleTripleClick",n=>n(e,t,o))||function(e,t,n){if(0!=n.button)return!1;let o=e.state.doc;if(-1==t)return!!o.inlineContent&&(cl(e,Nr.create(o,0,o.content.size)),!0);let r=o.resolve(t);for(let i=r.depth+1;i>0;i--){let t=i>r.depth?r.nodeAfter:r.node(i),n=r.before(i);if(t.inlineContent)cl(e,Nr.create(o,n+1,n+1+t.content.size));else{if(!Or.isSelectable(t))continue;cl(e,Or.create(o,n))}return!0}}(e,n,o)}function pl(e){return wl(e)}el.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!gl(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!ki||!gi||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!vi||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",t=>t(e,n))||Vs(e,n)?n.preventDefault():ol(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",t=>t(e,ii(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},el.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},el.keypress=(e,t)=>{let n=t;if(gl(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||xi&&n.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,n)))return void n.preventDefault();let o=e.state.selection;if(!(o instanceof Nr&&o.$from.sameParent(o.$to))){let t=String.fromCharCode(n.charCode),r=()=>e.state.tr.insertText(t).scrollIntoView();/[\r\n]/.test(t)||e.someProp("handleTextInput",n=>n(e,o.$from.pos,o.$to.pos,t,r))||e.dispatch(r()),n.preventDefault()}};const fl=xi?"metaKey":"ctrlKey";Qs.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let o=pl(e),r=Date.now(),i="singleClick";r-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,o=t.y-e.clientY;return n*n+o*o<100}(n,e.input.lastClick)&&!n[fl]&&e.input.lastClick.button==n.button&&("singleClick"==e.input.lastClick.type?i="doubleClick":"doubleClick"==e.input.lastClick.type&&(i="tripleClick")),e.input.lastClick={time:r,x:n.clientX,y:n.clientY,type:i,button:n.button};let s=e.posAtCoords(ll(n));s&&("singleClick"==i?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new ml(e,s,n,!!o)):("doubleClick"==i?ul:hl)(e,s.pos,s.inside,n)?n.preventDefault():ol(e,"pointer"))};class ml{constructor(e,t,n,o){let r,i;if(this.view=e,this.pos=t,this.event=n,this.flushed=o,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[fl],this.allowDefault=n.shiftKey,t.inside>-1)r=e.state.doc.nodeAt(t.inside),i=t.inside;else{let n=e.state.doc.resolve(t.pos);r=n.parent,i=n.depth?n.before():0}const s=o?null:n.target,l=s?e.docView.nearestDesc(s,!0):null;this.target=l&&1==l.nodeDOM.nodeType?l.nodeDOM:null;let{selection:a}=e.state;(0==n.button&&r.type.spec.draggable&&!1!==r.type.spec.selectable||a instanceof Or&&a.from<=i&&a.to>i)&&(this.mightDrag={node:r,pos:i,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!fi||this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),ol(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>bs(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(ll(e))),this.updateAllowDefault(e),this.allowDefault||!t?ol(this.view,"pointer"):dl(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||bi&&this.mightDrag&&!this.mightDrag.node.isAtom||gi&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(cl(this.view,Mr.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):ol(this.view,"pointer")}move(e){this.updateAllowDefault(e),ol(this.view,"pointer"),0==e.buttons&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}function gl(e,t){return!!e.composing||!!(bi&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}Qs.touchstart=e=>{e.input.lastTouch=Date.now(),pl(e),ol(e,"pointer")},Qs.touchmove=e=>{e.input.lastTouch=Date.now(),ol(e,"pointer")},Qs.contextmenu=e=>pl(e);const yl=ki?5e3:-1;function bl(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>wl(e),t))}function vl(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=function(){let e=document.createEvent("Event");return e.initEvent("event",!0,!0),e.timeStamp}());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function xl(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=ni(e=e.childNodes[t-1])}else{if(!e.parentNode||oi(e))return null;t=Zr(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),o=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||oi(e))return null;t=Zr(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&o&&n!=o){let t=o.pmViewDesc,r=e.domObserver.lastChangedTextNode;if(n==r||o==r)return r;if(!t||!t.isText(o.nodeValue))return o;if(e.input.compositionNode==o){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return o}}return n||o}function wl(e,t=!1){if(!(ki&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),vl(e),t||e.docView&&e.docView.dirty){let n=gs(e),o=e.state.selection;return n&&!n.eq(o)?e.dispatch(e.state.tr.setSelection(n)):!e.markCursor&&!t||o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?e.updateState(e.state):e.dispatch(e.state.tr.deleteSelection()),!0}return!1}}el.compositionstart=el.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof Nr&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)))e.markCursor=e.state.storedMarks||n.marks(),wl(e,!0),e.markCursor=null;else if(wl(e,!t.selection.empty),fi&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,o=t.focusOffset;n&&1==n.nodeType&&0!=o;){let t=o<0?n.lastChild:n.childNodes[o-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,o=-1}}e.input.composing=!0}bl(e,yl)},el.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,bl(e,20))};const kl=hi&&pi<15||vi&&Ei<604;function Cl(e,t,n,o,r){let i=zs(e,t,n,o,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,r,i||_n.empty)))return!0;if(!i)return!1;let s=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(i),l=s?e.state.tr.replaceSelectionWith(s,o):e.state.tr.replaceSelection(i);return e.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function El(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," "):""}Qs.copy=el.cut=(e,t)=>{let n=t,o=e.state.selection,r="cut"==n.type;if(o.empty)return;let i=kl?null:n.clipboardData,s=o.content(),{dom:l,text:a}=$s(e,s);i?(n.preventDefault(),i.clearData(),i.setData("text/html",l.innerHTML),i.setData("text/plain",a)):function(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 o=getSelection(),r=document.createRange();r.selectNodeContents(t),e.dom.blur(),o.removeAllRanges(),o.addRange(r),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,l),r&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},el.paste=(e,t)=>{let n=t;if(e.composing&&!ki)return;let o=kl?null:n.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;o&&Cl(e,El(o),o.getData("text/html"),r,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,o=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(o.contentEditable="true"),o.style.cssText="position: fixed; left: -10000px; top: 10px",o.focus();let r=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),o.parentNode&&o.parentNode.removeChild(o),n?Cl(e,o.value,null,r,t):Cl(e,o.textContent,o.innerHTML,r,t)},50)}(e,n)};class Sl{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const Ml=xi?"altKey":"ctrlKey";function Rl(e,t){let n=e.someProp("dragCopies",e=>!e(t));return null!=n?n:!t[Ml]}Qs.dragstart=(e,t)=>{let n=t,o=e.input.mouseDown;if(o&&o.done(),!n.dataTransfer)return;let r,i=e.state.selection,s=i.empty?null:e.posAtCoords(ll(n));if(s&&s.pos>=i.from&&s.pos<=(i instanceof Or?i.to-1:i.to));else if(o&&o.mightDrag)r=Or.create(e.state.doc,o.mightDrag.pos);else if(n.target&&1==n.target.nodeType){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(r=Or.create(e.state.doc,t.posBefore))}let l=(r||e.state.selection).content(),{dom:a,text:c,slice:d}=$s(e,l);(!n.dataTransfer.files.length||!gi||yi>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(kl?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",kl||n.dataTransfer.setData("text/plain",c),e.dragging=new Sl(d,Rl(e,n),r)},Qs.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},el.dragover=el.dragenter=(e,t)=>t.preventDefault(),el.drop=(e,t)=>{let n=t,o=e.dragging;if(e.dragging=null,!n.dataTransfer)return;let r=e.posAtCoords(ll(n));if(!r)return;let i=e.state.doc.resolve(r.pos),s=o&&o.slice;s?e.someProp("transformPasted",t=>{s=t(s,e,!1)}):s=zs(e,El(n.dataTransfer),kl?null:n.dataTransfer.getData("text/html"),!1,i);let l=!(!o||!Rl(e,n));if(e.someProp("handleDrop",t=>t(e,n,s||_n.empty,l)))return void n.preventDefault();if(!s)return;n.preventDefault();let a=s?cr(e.state.doc,i.pos,s):i.pos;null==a&&(a=i.pos);let c=e.state.tr;if(l){let{node:e}=o;e?e.replace(c):c.deleteSelection()}let d=c.mapping.map(a),u=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,h=c.doc;if(u?c.replaceRangeWith(d,d,s.content.firstChild):c.replaceRange(d,d,s),c.doc.eq(h))return;let p=c.doc.resolve(d);if(u&&Or.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new Or(p));else{let t=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,o,r)=>t=r),c.setSelection(Ss(e,p,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta("uiEvent","drop"))},Qs.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&bs(e)},20))},Qs.blur=(e,t)=>{let n=t;e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},Qs.beforeinput=(e,t)=>{if(gi&&ki&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t)return;if(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,ii(8,"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 os in el)Qs[os]=el[os];function Tl(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}class jl{constructor(e,t){this.toDOM=e,this.spec=t||Pl,this.side=this.spec.side||0}map(e,t,n,o){let{pos:r,deleted:i}=e.mapResult(t.from+o,this.side<0?-1:1);return i?null:new Ol(r-n,r-n,this)}valid(){return!0}eq(e){return this==e||e instanceof jl&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Tl(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Nl{constructor(e,t){this.attrs=e,this.spec=t||Pl}map(e,t,n,o){let r=e.map(t.from+o,this.spec.inclusiveStart?-1:1)-n,i=e.map(t.to+o,this.spec.inclusiveEnd?1:-1)-n;return r>=i?null:new Ol(r,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Nl&&Tl(this.attrs,e.attrs)&&Tl(this.spec,e.spec)}static is(e){return e.type instanceof Nl}destroy(){}}class Al{constructor(e,t){this.attrs=e,this.spec=t||Pl}map(e,t,n,o){let r=e.mapResult(t.from+o,1);if(r.deleted)return null;let i=e.mapResult(t.to+o,-1);return i.deleted||i.pos<=r.pos?null:new Ol(r.pos-n,i.pos-n,this)}valid(e,t){let n,{index:o,offset:r}=e.content.findIndex(t.from);return r==t.from&&!(n=e.child(o)).isText&&r+n.nodeSize==t.to}eq(e){return this==e||e instanceof Al&&Tl(this.attrs,e.attrs)&&Tl(this.spec,e.spec)}destroy(){}}class Ol{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new Ol(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new Ol(e,e,new jl(t,n))}static inline(e,t,n,o){return new Ol(e,t,new Nl(n,o))}static node(e,t,n,o){return new Ol(e,t,new Al(n,o))}get spec(){return this.type.spec}get inline(){return this.type instanceof Nl}get widget(){return this.type instanceof jl}}const _l=[],Pl={};class Il{constructor(e,t){this.local=e.length?e:_l,this.children=t.length?t:_l}static create(e,t){return t.length?$l(t,e,0,Pl):Ll}find(e,t,n){let o=[];return this.findInner(null==e?0:e,null==t?1e9:t,o,0,n),o}findInner(e,t,n,o,r){for(let i=0;i<this.local.length;i++){let s=this.local[i];s.from<=t&&s.to>=e&&(!r||r(s.spec))&&n.push(s.copy(s.from+o,s.to+o))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let s=this.children[i]+1;this.children[i+2].findInner(e-s,t-s,n,o+s,r)}}map(e,t,n){return this==Ll||0==e.maps.length?this:this.mapInner(e,t,0,0,n||Pl)}mapInner(e,t,n,o,r){let i;for(let s=0;s<this.local.length;s++){let l=this.local[s].map(e,n,o);l&&l.type.valid(t,l)?(i||(i=[])).push(l):r.onRemove&&r.onRemove(this.local[s].spec)}return this.children.length?function(e,t,n,o,r,i,s){let l=e.slice();for(let c=0,d=i;c<n.maps.length;c++){let e=0;n.maps[c].forEach((t,n,o,r)=>{let i=r-o-(n-t);for(let s=0;s<l.length;s+=3){let o=l[s+1];if(o<0||t>o+d-e)continue;let r=l[s]+d-e;n>=r?l[s+1]=t<=r?-2:-1:t>=d&&i&&(l[s]+=i,l[s+1]+=i)}e+=i}),d=n.maps[c].map(d,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(-2==l[c+1]){a=!0,l[c+1]=-1;continue}let t=n.map(e[c]+i),d=t-r;if(d<0||d>=o.content.size){a=!0;continue}let u=n.map(e[c+1]+i,-1)-r,{index:h,offset:p}=o.content.findIndex(d),f=o.maybeChild(h);if(f&&p==d&&p+f.nodeSize==u){let o=l[c+2].mapInner(n,f,t+1,e[c]+i+1,s);o!=Ll?(l[c]=d,l[c+1]=u,l[c+2]=o):(l[c+1]=-2,a=!0)}else a=!0}if(a){let a=function(e,t,n,o,r,i,s){function l(e,t){for(let i=0;i<e.local.length;i++){let l=e.local[i].map(o,r,t);l?n.push(l):s.onRemove&&s.onRemove(e.local[i].spec)}for(let n=0;n<e.children.length;n+=3)l(e.children[n+2],e.children[n]+t+1)}for(let a=0;a<e.length;a+=3)-1==e[a+1]&&l(e[a+2],t[a]+i+1);return n}(l,e,t,n,r,i,s),c=$l(a,o,0,s);t=c.local;for(let e=0;e<l.length;e+=3)l[e+1]<0&&(l.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<l.length&&l[t]<n;)t+=3;l.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new Il(t.sort(zl),l)}(this.children,i||[],e,t,n,o,r):i?new Il(i.sort(zl),_l):Ll}add(e,t){return t.length?this==Ll?Il.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let o,r=0;e.forEach((e,i)=>{let s,l=i+n;if(s=Hl(t,e,l)){for(o||(o=this.children.slice());r<o.length&&o[r]<i;)r+=3;o[r]==i?o[r+2]=o[r+2].addInner(e,s,l+1):o.splice(r,0,i,i+e.nodeSize,$l(s,e,l+1,Pl)),r+=3}});let i=Bl(r?Vl(t):t,-n);for(let s=0;s<i.length;s++)i[s].type.valid(e,i[s])||i.splice(s--,1);return new Il(i.length?this.local.concat(i).sort(zl):this.local,o||this.children)}remove(e){return 0==e.length||this==Ll?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,o=this.local;for(let r=0;r<n.length;r+=3){let o,i=n[r]+t,s=n[r+1]+t;for(let t,n=0;n<e.length;n++)(t=e[n])&&t.from>i&&t.to<s&&(e[n]=null,(o||(o=[])).push(t));if(!o)continue;n==this.children&&(n=this.children.slice());let l=n[r+2].removeInner(o,i+1);l!=Ll?n[r+2]=l:(n.splice(r,3),r-=3)}if(o.length)for(let r,i=0;i<e.length;i++)if(r=e[i])for(let e=0;e<o.length;e++)o[e].eq(r,t)&&(o==this.local&&(o=this.local.slice()),o.splice(e--,1));return n==this.children&&o==this.local?this:o.length||n.length?new Il(o,n):Ll}forChild(e,t){if(this==Ll)return this;if(t.isLeaf)return Il.empty;let n,o;for(let s=0;s<this.children.length;s+=3)if(this.children[s]>=e){this.children[s]==e&&(n=this.children[s+2]);break}let r=e+1,i=r+t.content.size;for(let s=0;s<this.local.length;s++){let e=this.local[s];if(e.from<i&&e.to>r&&e.type instanceof Nl){let t=Math.max(r,e.from)-r,n=Math.min(i,e.to)-r;t<n&&(o||(o=[])).push(e.copy(t,n))}}if(o){let e=new Il(o.sort(zl),_l);return n?new Dl([e,n]):e}return n||Ll}eq(e){if(this==e)return!0;if(!(e instanceof Il)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return Fl(this.localsInner(e))}localsInner(e){if(this==Ll)return _l;if(e.inlineContent||!this.local.some(Nl.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Nl||t.push(this.local[n]);return t}forEachSet(e){e(this)}}Il.empty=new Il([],[]),Il.removeOverlap=Fl;const Ll=Il.empty;class Dl{constructor(e){this.members=e}map(e,t){const n=this.members.map(n=>n.map(e,t,Pl));return Dl.from(n)}forChild(e,t){if(t.isLeaf)return Il.empty;let n=[];for(let o=0;o<this.members.length;o++){let r=this.members[o].forChild(e,t);r!=Ll&&(r instanceof Dl?n=n.concat(r.members):n.push(r))}return Dl.from(n)}eq(e){if(!(e instanceof Dl)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let o=0;o<this.members.length;o++){let r=this.members[o].localsInner(e);if(r.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<r.length;e++)t.push(r[e])}else t=r}return t?Fl(n?t:t.sort(zl)):_l}static from(e){switch(e.length){case 0:return Ll;case 1:return e[0];default:return new Dl(e.every(e=>e instanceof Il)?e:e.reduce((e,t)=>e.concat(t instanceof Il?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function Bl(e,t){if(!t||!e.length)return e;let n=[];for(let o=0;o<e.length;o++){let r=e[o];n.push(new Ol(r.from+t,r.to+t,r.type))}return n}function Hl(e,t,n){if(t.isLeaf)return null;let o=n+t.nodeSize,r=null;for(let i,s=0;s<e.length;s++)(i=e[s])&&i.from>n&&i.to<o&&((r||(r=[])).push(i),e[s]=null);return r}function Vl(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function $l(e,t,n,o){let r=[],i=!1;t.forEach((t,s)=>{let l=Hl(e,t,s+n);if(l){i=!0;let e=$l(l,t,n+s+1,o);e!=Ll&&r.push(s,s+t.nodeSize,e)}});let s=Bl(i?Vl(e):e,-n).sort(zl);for(let l=0;l<s.length;l++)s[l].type.valid(t,s[l])||(o.onRemove&&o.onRemove(s[l].spec),s.splice(l--,1));return s.length||r.length?new Il(s,r):Ll}function zl(e,t){return e.from-t.from||e.to-t.to}function Fl(e){let t=e;for(let n=0;n<t.length-1;n++){let o=t[n];if(o.from!=o.to)for(let r=n+1;r<t.length;r++){let i=t[r];if(i.from!=o.from){i.from<o.to&&(t==e&&(t=e.slice()),t[n]=o.copy(o.from,i.from),Ul(t,r,o.copy(i.from,o.to)));break}i.to!=o.to&&(t==e&&(t=e.slice()),t[r]=i.copy(i.from,o.to),Ul(t,r+1,i.copy(o.to,i.to)))}}return t}function Ul(e,t,n){for(;t<e.length&&zl(n,e[t])>0;)t++;e.splice(t,0,n)}function Wl(e){let t=[];return e.someProp("decorations",n=>{let o=n(e.state);o&&o!=Ll&&t.push(o)}),e.cursorWrapper&&t.push(Il.create(e.state.doc,[e.cursorWrapper.deco])),Dl.from(t)}const ql={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Gl=hi&&pi<=11;class Kl{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class Zl{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Kl,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);hi&&pi<=11&&e.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),Gl&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,ql)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Ms(this.view)){if(this.suppressingSelectionUpdates)return bs(this.view);if(hi&&pi<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Qr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t,n=new Set;for(let r=e.focusNode;r;r=Jr(r))n.add(r);for(let r=e.anchorNode;r;r=Jr(r))if(n.has(r)){t=r;break}let o=t&&this.view.docView.nearestDesc(t);return o&&o.ignoreMutation({type:"selection",target:3==t.nodeType?t.parentNode:t})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),o=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Ms(e)&&!this.ignoreSelectionChange(n),r=-1,i=-1,s=!1,l=[];if(e.editable)for(let c=0;c<t.length;c++){let e=this.registerMutation(t[c],l);e&&(r=r<0?e.from:Math.min(e.from,r),i=i<0?e.to:Math.max(e.to,i),e.typeOver&&(s=!0))}if(fi&&l.length){let t=l.filter(e=>"BR"==e.nodeName);if(2==t.length){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let o of t){let t=o.parentNode;!t||"LI"!=t.nodeName||n&&Ql(e,n)==t||o.remove()}}}let a=null;r<0&&o&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&ri(n)&&(a=gs(e))&&a.eq(Mr.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,bs(e),this.currentSelection.set(n),e.scrollToSelection()):(r>-1||o)&&(r>-1&&(e.docView.markDirty(r,i),function(e){if(Jl.has(e))return;if(Jl.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace)){if(e.requiresGeckoHackNode=fi,Xl)return;Xl=!0}}(e)),this.handleDOMChange(r,i,s,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||bs(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style")))return null;if(!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;n<e.addedNodes.length;n++){let o=e.addedNodes[n];t.push(o),3==o.nodeType&&(this.lastChangedTextNode=o)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let o=e.previousSibling,r=e.nextSibling;if(hi&&pi<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:i}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(o=n),(!i||Array.prototype.indexOf.call(e.addedNodes,i)<0)&&(r=i)}let i=o&&o.parentNode==e.target?Zr(o)+1:0,s=n.localPosFromDOM(e.target,i,-1),l=r&&r.parentNode==e.target?Zr(r):e.target.childNodes.length;return{from:s,to:n.localPosFromDOM(e.target,l,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let Jl=new WeakMap,Xl=!1;function Yl(e,t){let n=t.startContainer,o=t.startOffset,r=t.endContainer,i=t.endOffset,s=e.domAtPos(e.state.selection.anchor);return Qr(s.node,s.offset,r,i)&&([n,o,r,i]=[r,i,n,o]),{anchorNode:n,anchorOffset:o,focusNode:r,focusOffset:i}}function Ql(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 ea(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(bi&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement("div");return e.appendChild(document.createElement("li")),{skip:e}}if(e.parentNode.lastChild==e||bi&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if("IMG"==e.nodeName&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null}const ta=/^(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 na(e,t,n,o,r){let i=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=gs(e,t);if(n&&!e.state.selection.eq(n)){if(gi&&ki&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,ii(13,"Enter"))))return;let o=e.state.tr.setSelection(n);"pointer"==t?o.setMeta("pointer",!0):"key"==t&&o.scrollIntoView(),i&&o.setMeta("composition",i),e.dispatch(o)}return}let s=e.state.doc.resolve(t),l=s.sharedDepth(n);t=s.before(l+1),n=e.state.doc.resolve(n).after(l+1);let a,c,d=e.state.selection,u=function(e,t,n){let o,{node:r,fromOffset:i,toOffset:s,from:l,to:a}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(o=[{node:d,offset:c.anchorOffset}],ri(c)||o.push({node:c.focusNode,offset:c.focusOffset})),gi&&8===e.input.lastKeyCode)for(let g=s;g>i;g--){let e=r.childNodes[g-1],t=e.pmViewDesc;if("BR"==e.nodeName&&!t){s=g;break}if(!t||t.size)break}let u=e.state.doc,h=e.someProp("domParser")||vo.fromSchema(e.state.schema),p=u.resolve(l),f=null,m=h.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:s,preserveWhitespace:"pre"!=p.parent.type.whitespace||"full",findPositions:o,ruleFromNode:ea,context:p});if(o&&null!=o[0].pos){let e=o[0].pos,t=o[1]&&o[1].pos;null==t&&(t=e),f={anchor:e+l,head:t+l}}return{doc:m,sel:f,from:l,to:a}}(e,t,n),h=e.state.doc,p=h.slice(u.from,u.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(a=e.state.selection.to,c="end"):(a=e.state.selection.from,c="start"),e.input.lastKeyCode=null;let f=function(e,t,n,o,r){let i=e.findDiffStart(t,n);if(null==i)return null;let{a:s,b:l}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==r){o-=s+Math.max(0,i-Math.min(s,l))-i}if(s<i&&e.size<t.size){let e=o<=i&&o>=s?i-o:0;i-=e,i&&i<t.size&&ia(t.textBetween(i-1,i+1))&&(i+=e?1:-1),l=i+(l-s),s=i}else if(l<i){let t=o<=i&&o>=l?i-o:0;i-=t,i&&i<e.size&&ia(e.textBetween(i-1,i+1))&&(i+=t?1:-1),s=i+(s-l),l=i}return{start:i,endA:s,endB:l}}(p.content,u.doc.content,u.from,a,c);if(f&&e.input.domChangeCount++,(vi&&e.input.lastIOSEnter>Date.now()-225||ki)&&r.some(e=>1==e.nodeType&&!ta.test(e.nodeName))&&(!f||f.endA>=f.endB)&&e.someProp("handleKeyDown",t=>t(e,ii(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(!f){if(!(o&&d instanceof Nr&&!d.empty&&d.$head.sameParent(d.$anchor))||e.composing||u.sel&&u.sel.anchor!=u.sel.head){if(u.sel){let t=oa(e,e.state.doc,u.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);i&&n.setMeta("composition",i),e.dispatch(n)}}return}f={start:d.from,endA:d.to,endB:d.to}}e.state.selection.from<e.state.selection.to&&f.start==f.endB&&e.state.selection instanceof Nr&&(f.start>e.state.selection.from&&f.start<=e.state.selection.from+2&&e.state.selection.from>=u.from?f.start=e.state.selection.from:f.endA<e.state.selection.to&&f.endA>=e.state.selection.to-2&&e.state.selection.to<=u.to&&(f.endB+=e.state.selection.to-f.endA,f.endA=e.state.selection.to)),hi&&pi<=11&&f.endB==f.start+1&&f.endA==f.start&&f.start>u.from&&"  "==u.doc.textBetween(f.start-u.from-1,f.start-u.from+1)&&(f.start--,f.endA--,f.endB--);let m=u.doc.resolveNoCache(f.start-u.from),g=u.doc.resolveNoCache(f.endB-u.from),y=h.resolve(f.start),b=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=f.endA;if((vi&&e.input.lastIOSEnter>Date.now()-225&&(!b||r.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!b&&m.pos<u.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&m.pos<g.pos&&!/\S/.test(u.doc.textBetween(m.pos,g.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,ii(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(e.state.selection.anchor>f.start&&function(e,t,n,o,r){if(n-t<=r.pos-o.pos||ra(o,!0,!1)<r.pos)return!1;let i=e.resolve(t);if(!o.parent.isTextblock){let e=i.nodeAfter;return null!=e&&n==t+e.nodeSize}if(i.parentOffset<i.parent.content.size||!i.parent.isTextblock)return!1;let s=e.resolve(ra(i,!0,!0));return!(!s.parent.isTextblock||s.pos>n||ra(s,!0,!1)<n)&&o.parent.content.cut(o.parentOffset).eq(s.parent.content)}(h,f.start,f.endA,m,g)&&e.someProp("handleKeyDown",t=>t(e,ii(8,"Backspace"))))return void(ki&&gi&&e.domObserver.suppressSelectionUpdates());gi&&f.endB==f.start&&(e.input.lastChromeDelete=Date.now()),ki&&!b&&m.start()!=g.start()&&0==g.parentOffset&&m.depth==g.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==f.endA&&(f.endB-=2,g=u.doc.resolveNoCache(f.endB-u.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,ii(13,"Enter"))})},20));let v,x=f.start,w=f.endA,k=t=>{let n=t||e.state.tr.replace(x,w,u.doc.slice(f.start-u.from,f.endB-u.from));if(u.sel){let t=oa(e,n.doc,u.sel);t&&!(gi&&e.composing&&t.empty&&(f.start!=f.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==x||t.head==n.mapping.map(w)-1)||hi&&t.empty&&t.head==x)&&n.setSelection(t)}return i&&n.setMeta("composition",i),n.scrollIntoView()};if(b)if(m.pos==g.pos){hi&&pi<=11&&0==m.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>bs(e),20));let t=k(e.state.tr.delete(x,w)),n=h.resolve(f.start).marksAcross(h.resolve(f.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(f.endA==f.endB&&(v=function(e,t){let n,o,r,i=e.firstChild.marks,s=t.firstChild.marks,l=i,a=s;for(let d=0;d<s.length;d++)l=s[d].removeFromSet(l);for(let d=0;d<i.length;d++)a=i[d].removeFromSet(a);if(1==l.length&&0==a.length)o=l[0],n="add",r=e=>e.mark(o.addToSet(e.marks));else{if(0!=l.length||1!=a.length)return null;o=a[0],n="remove",r=e=>e.mark(o.removeFromSet(e.marks))}let c=[];for(let d=0;d<t.childCount;d++)c.push(r(t.child(d)));if(Rn.from(c).eq(e))return{mark:o,type:n}}(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,f.endA-y.start())))){let t=k(e.state.tr);"add"==v.type?t.addMark(x,w,v.mark):t.removeMark(x,w,v.mark),e.dispatch(t)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let t=m.parent.textBetween(m.parentOffset,g.parentOffset),n=()=>k(e.state.tr.insertText(t,x,w));e.someProp("handleTextInput",o=>o(e,x,w,t,n))||e.dispatch(n())}else e.dispatch(k());else e.dispatch(k())}function oa(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:Ss(e,t.resolve(n.anchor),t.resolve(n.head))}function ra(e,t,n){let o=e.depth,r=t?e.end():e.pos;for(;o>0&&(t||e.indexAfter(o)==e.node(o).childCount);)o--,r++,t=!1;if(n){let t=e.node(o).maybeChild(e.indexAfter(o));for(;t&&!t.isLeaf;)t=t.firstChild,r++}return r}function ia(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}class sa{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 nl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ua),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=ca(this),aa(this),this.nodeViews=da(this),this.docView=Qi(this.state.doc,la(this),Wl(this),this.dom,this),this.domObserver=new Zl(this,(e,t,n,o)=>na(this,e,t,n,o)),this.domObserver.start(),function(e){for(let t in Qs){let n=Qs[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!sl(e,t)||il(e,t)||!e.editable&&t.type in el||n(e,t)},tl[t]?{passive:!0}:void 0)}bi&&e.dom.addEventListener("input",()=>null),rl(e)}(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&&rl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ua),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let o=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(vl(this),i=!0),this.state=e;let s=o.plugins!=e.plugins||this._props.plugins!=t.plugins;if(s||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=da(this);(function(e,t){let n=0,o=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let r in t)o++;return n!=o})(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(s||t.handleDOMEvents!=this._props.handleDOMEvents)&&rl(this),this.editable=ca(this),aa(this);let l=Wl(this),a=la(this),c=o.plugins==e.plugins||o.doc.eq(e.doc)?e.scrollToSelection>o.scrollToSelection?"to selection":"preserve":"reset",d=r||!this.docView.matchesNode(e.doc,a,l);!d&&e.selection.eq(o.selection)||(i=!0);let u="preserve"==c&&i&&null==this.dom.style.overflowAnchor&&function(e){let t,n,o=e.dom.getBoundingClientRect(),r=Math.max(0,o.top);for(let i=(o.left+o.right)/2,s=r+1;s<Math.min(innerHeight,o.bottom);s+=5){let o=e.root.elementFromPoint(i,s);if(!o||o==e.dom||!e.dom.contains(o))continue;let l=o.getBoundingClientRect();if(l.top>=r-20){t=o,n=l.top;break}}return{refDOM:t,refTop:n,stack:ji(e.dom)}}(this);if(i){this.domObserver.stop();let t=d&&(hi||gi)&&!this.composing&&!o.selection.empty&&!e.selection.empty&&function(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)}(o.selection,e.selection);if(d){let n=gi?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=xl(this)),!r&&this.docView.update(e.doc,a,l,this)||(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Qi(e.doc,a,l,this.dom,this)),n&&!this.trackWrites&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return Qr(t.node,t.offset,n.anchorNode,n.anchorOffset)}(this))?bs(this,t):(Cs(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(o),(null===(n=this.dragging)||void 0===n?void 0:n.node)&&!o.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,o),"reset"==c?this.dom.scrollTop=0:"to selection"==c?this.scrollToSelection():u&&function({refDOM:e,refTop:t,stack:n}){let o=e?e.getBoundingClientRect().top:0;Ni(n,0==o?0:o-t)}(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&this.dom.contains(1==e.nodeType?e:e.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof Or){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&Ti(this,t.getBoundingClientRect(),e)}else Ti(this,this.coordsAtPos(this.state.selection.head,1),e);else;}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)for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}else{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))}}}updateDraggedNode(e,t){let n=e.node,o=-1;if(this.state.doc.nodeAt(n.from)==n.node)o=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&this.state.doc.nodeAt(e))==n.node&&(o=e)}this.dragging=new Sl(e.slice,e.move,o<0?void 0:Or.create(this.state.doc,o))}someProp(e,t){let n,o=this._props&&this._props[e];if(null!=o&&(n=t?t(o):o))return n;for(let i=0;i<this.directPlugins.length;i++){let o=this.directPlugins[i].props[e];if(null!=o&&(n=t?t(o):o))return n}let r=this.state.plugins;if(r)for(let i=0;i<r.length;i++){let o=r[i].props[e];if(null!=o&&(n=t?t(o):o))return n}}hasFocus(){if(hi){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if("false"==e.contentEditable)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(e){if(e.setActive)return e.setActive();if(Ai)return e.focus(Ai);let t=ji(e);e.focus(null==Ai?{get preventScroll(){return Ai={preventScroll:!0},!0}}:void 0),Ai||(Ai=!1,Ni(t,0))}(this.dom),bs(this),this.domObserver.start()}get root(){let e=this._root;if(null==e)for(let t=this.dom.parentNode;t;t=t.parentNode)if(9==t.nodeType||11==t.nodeType&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t;return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ii(this,e)}coordsAtPos(e,t=1){return Hi(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 o=this.docView.posFromDOM(e,t,n);if(null==o)throw new RangeError("DOM position not inside the editor");return o}endOfTextblock(e,t){return Gi(this,t||this.state,e)}pasteHTML(e,t){return Cl(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Cl(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return $s(this,e)}destroy(){this.docView&&(!function(e){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)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Wl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Xr=null)}get isDestroyed(){return null==this.docView}dispatchEvent(e){return function(e,t){il(e,t)||!Qs[t.type]||!e.editable&&t.type in el||Qs[t.type](e,t)}(this,e)}domSelectionRange(){let e=this.domSelection();return e?bi&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Yl(e,n)}let n;function o(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",o,!0),n?Yl(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function la(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),e.someProp("attributes",n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e?t.class+=" "+n[e]:"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))}),t.translate||(t.translate="no"),[Ol.node(0,e.state.doc.content.size,t)]}function aa(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:Ol.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function ca(e){return!e.someProp("editable",t=>!1===t(e.state))}function da(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 ua(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}sa.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var ha={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:"'"},pa={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},fa="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),ma="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ga=0;ga<10;ga++)ha[48+ga]=ha[96+ga]=String(ga);for(ga=1;ga<=24;ga++)ha[ga+111]="F"+ga;for(ga=65;ga<=90;ga++)ha[ga]=String.fromCharCode(ga+32),pa[ga]=String.fromCharCode(ga);for(var ya in ha)pa.hasOwnProperty(ya)||(pa[ya]=ha[ya]);const ba="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),va="undefined"!=typeof navigator&&/Win/.test(navigator.platform);function xa(e){let t,n,o,r,i=e.split(/-(?!$)/),s=i[i.length-1];"Space"==s&&(s=" ");for(let l=0;l<i.length-1;l++){let e=i[l];if(/^(cmd|meta|m)$/i.test(e))r=!0;else if(/^a(lt)?$/i.test(e))t=!0;else if(/^(c|ctrl|control)$/i.test(e))n=!0;else if(/^s(hift)?$/i.test(e))o=!0;else{if(!/^mod$/i.test(e))throw new Error("Unrecognized modifier name: "+e);ba?r=!0:n=!0}}return t&&(s="Alt-"+s),n&&(s="Ctrl-"+s),r&&(s="Meta-"+s),o&&(s="Shift-"+s),s}function wa(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 ka(e){let t=function(e){let t=Object.create(null);for(let n in e)t[xa(n)]=e[n];return t}(e);return function(e,n){let o,r=function(e){var t=!(fa&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||ma&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?pa:ha)[e.keyCode]||e.key||"Unidentified";return"Esc"==t&&(t="Escape"),"Del"==t&&(t="Delete"),"Left"==t&&(t="ArrowLeft"),"Up"==t&&(t="ArrowUp"),"Right"==t&&(t="ArrowRight"),"Down"==t&&(t="ArrowDown"),t}(n),i=t[wa(r,n)];if(i&&i(e.state,e.dispatch,e))return!0;if(1==r.length&&" "!=r){if(n.shiftKey){let o=t[wa(r,n,!1)];if(o&&o(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(va&&n.ctrlKey&&n.altKey)&&(o=ha[n.keyCode])&&o!=r){let r=t[wa(o,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}const Ca=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Ea(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("backward",e):n.parentOffset>0)?null:n}const Sa=(e,t,n)=>{let o=Ea(e,n);if(!o)return!1;let r=ja(o);if(!r){let n=o.blockRange(),r=n&&er(n);return null!=r&&(t&&t(e.tr.lift(n,r).scrollIntoView()),!0)}let i=r.nodeBefore;if(Ha(e,r,t,-1))return!0;if(0==o.parent.content.size&&(Ra(i,"end")||Or.isSelectable(i)))for(let s=o.depth;;s--){let n=dr(e.doc,o.before(s),o.after(s),_n.empty);if(n&&n.slice.size<n.to-n.from){if(t){let o=e.tr.step(n);o.setSelection(Ra(i,"end")?Mr.findFrom(o.doc.resolve(o.mapping.map(r.pos,-1)),-1):Or.create(o.doc,r.pos-i.nodeSize)),t(o.scrollIntoView())}return!0}if(1==s||o.node(s-1).childCount>1)break}return!(!i.isAtom||r.depth!=o.depth-1)&&(t&&t(e.tr.delete(r.pos-i.nodeSize,r.pos).scrollIntoView()),!0)};function Ma(e,t,n){let o=t.nodeBefore,r=t.pos-1;for(;!o.isTextblock;r--){if(o.type.spec.isolating)return!1;let e=o.lastChild;if(!e)return!1;o=e}let i=t.nodeAfter,s=t.pos+1;for(;!i.isTextblock;s++){if(i.type.spec.isolating)return!1;let e=i.firstChild;if(!e)return!1;i=e}let l=dr(e.doc,r,s,_n.empty);if(!l||l.from!=r||l instanceof Zo&&l.slice.size>=s-r)return!1;if(n){let t=e.tr.step(l);t.setSelection(Nr.create(t.doc,r)),n(t.scrollIntoView())}return!0}function Ra(e,t,n=!1){for(let o=e;o;o="start"==t?o.firstChild:o.lastChild){if(o.isTextblock)return!0;if(n&&1!=o.childCount)return!1}return!1}const Ta=(e,t,n)=>{let{$head:o,empty:r}=e.selection,i=o;if(!r)return!1;if(o.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):o.parentOffset>0)return!1;i=ja(o)}let s=i&&i.nodeBefore;return!(!s||!Or.isSelectable(s))&&(t&&t(e.tr.setSelection(Or.create(e.doc,i.pos-s.nodeSize)).scrollIntoView()),!0)};function ja(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 Na(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("forward",e):n.parentOffset<n.parent.content.size)?null:n}const Aa=(e,t,n)=>{let o=Na(e,n);if(!o)return!1;let r=_a(o);if(!r)return!1;let i=r.nodeAfter;if(Ha(e,r,t,1))return!0;if(0==o.parent.content.size&&(Ra(i,"start")||Or.isSelectable(i))){let n=dr(e.doc,o.before(),o.after(),_n.empty);if(n&&n.slice.size<n.to-n.from){if(t){let o=e.tr.step(n);o.setSelection(Ra(i,"start")?Mr.findFrom(o.doc.resolve(o.mapping.map(r.pos)),1):Or.create(o.doc,o.mapping.map(r.pos))),t(o.scrollIntoView())}return!0}}return!(!i.isAtom||r.depth!=o.depth-1)&&(t&&t(e.tr.delete(r.pos,r.pos+i.nodeSize).scrollIntoView()),!0)},Oa=(e,t,n)=>{let{$head:o,empty:r}=e.selection,i=o;if(!r)return!1;if(o.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):o.parentOffset<o.parent.content.size)return!1;i=_a(o)}let s=i&&i.nodeAfter;return!(!s||!Or.isSelectable(s))&&(t&&t(e.tr.setSelection(Or.create(e.doc,i.pos)).scrollIntoView()),!0)};function _a(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}const Pa=(e,t)=>{let{$head:n,$anchor:o}=e.selection;return!(!n.parent.type.spec.code||!n.sameParent(o))&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)};function Ia(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}const La=(e,t)=>{let n=e.selection,{$from:o,$to:r}=n;if(n instanceof Pr||o.parent.inlineContent||r.parent.inlineContent)return!1;let i=Ia(r.parent.contentMatchAt(r.indexAfter()));if(!i||!i.isTextblock)return!1;if(t){let n=(!o.parentOffset&&r.index()<r.parent.childCount?o:r).pos,s=e.tr.insert(n,i.createAndFill());s.setSelection(Nr.create(s.doc,n+1)),t(s.scrollIntoView())}return!0},Da=(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 o=n.before();if(ir(e.doc,o))return t&&t(e.tr.split(o).scrollIntoView()),!0}let o=n.blockRange(),r=o&&er(o);return null!=r&&(t&&t(e.tr.lift(o,r).scrollIntoView()),!0)};const Ba=(e,t)=>{let{$from:n,$to:o}=e.selection;if(e.selection instanceof Or&&e.selection.node.isBlock)return!(!n.parentOffset||!ir(e.doc,n.pos)||(t&&t(e.tr.split(n.pos).scrollIntoView()),0));if(!n.depth)return!1;let r,i,s=[],l=!1,a=!1;for(let h=n.depth;;h--){if(n.node(h).isBlock){l=n.end(h)==n.pos+(n.depth-h),a=n.start(h)==n.pos-(n.depth-h),i=Ia(n.node(h-1).contentMatchAt(n.indexAfter(h-1))),s.unshift(l&&i?{type:i}:null),r=h;break}if(1==h)return!1;s.unshift(null)}let c=e.tr;(e.selection instanceof Nr||e.selection instanceof Pr)&&c.deleteSelection();let d=c.mapping.map(n.pos),u=ir(c.doc,d,s.length,s);if(u||(s[0]=i?{type:i}:null,u=ir(c.doc,d,s.length,s)),!u)return!1;if(c.split(d,s.length,s),!l&&a&&n.node(r).type!=i){let e=c.mapping.map(n.before(r)),t=c.doc.resolve(e);i&&n.node(r-1).canReplaceWith(t.index(),t.index()+1,i)&&c.setNodeMarkup(c.mapping.map(n.before(r)),i)}return t&&t(c.scrollIntoView()),!0};function Ha(e,t,n,o){let r,i,s=t.nodeBefore,l=t.nodeAfter,a=s.type.spec.isolating||l.type.spec.isolating;if(!a&&function(e,t,n){let o=t.nodeBefore,r=t.nodeAfter,i=t.index();return!(!(o&&r&&o.type.compatibleContent(r.type))||(!o.content.size&&t.parent.canReplace(i-1,i)?(n&&n(e.tr.delete(t.pos-o.nodeSize,t.pos).scrollIntoView()),0):!t.parent.canReplace(i,i+1)||!r.isTextblock&&!sr(e.doc,t.pos)||(n&&n(e.tr.join(t.pos).scrollIntoView()),0)))}(e,t,n))return!0;let c=!a&&t.parent.canReplace(t.index(),t.index()+1);if(c&&(r=(i=s.contentMatchAt(s.childCount)).findWrapping(l.type))&&i.matchType(r[0]||l.type).validEnd){if(n){let o=t.pos+l.nodeSize,i=Rn.empty;for(let e=r.length-1;e>=0;e--)i=Rn.from(r[e].create(null,i));i=Rn.from(s.copy(i));let a=e.tr.step(new Jo(t.pos-1,o,t.pos,o,new _n(i,1,0),r.length,!0)),c=a.doc.resolve(o+2*r.length);c.nodeAfter&&c.nodeAfter.type==s.type&&sr(a.doc,c.pos)&&a.join(c.pos),n(a.scrollIntoView())}return!0}let d=l.type.spec.isolating||o>0&&a?null:Mr.findFrom(t,1),u=d&&d.$from.blockRange(d.$to),h=u&&er(u);if(null!=h&&h>=t.depth)return n&&n(e.tr.lift(u,h).scrollIntoView()),!0;if(c&&Ra(l,"start",!0)&&Ra(s,"end")){let o=s,r=[];for(;r.push(o),!o.isTextblock;)o=o.lastChild;let i=l,a=1;for(;!i.isTextblock;i=i.firstChild)a++;if(o.canReplace(o.childCount,o.childCount,i.content)){if(n){let o=Rn.empty;for(let e=r.length-1;e>=0;e--)o=Rn.from(r[e].copy(o));n(e.tr.step(new Jo(t.pos-r.length,t.pos+l.nodeSize,t.pos+a,t.pos+l.nodeSize-a,new _n(o,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function Va(e){return function(t,n){let o=t.selection,r=e<0?o.$from:o.$to,i=r.depth;for(;r.node(i).isInline;){if(!i)return!1;i--}return!!r.node(i).isTextblock&&(n&&n(t.tr.setSelection(Nr.create(t.doc,e<0?r.start(i):r.end(i)))),!0)}}const $a=Va(-1),za=Va(1);function Fa(e,t=null){return function(n,o){let r=!1;for(let i=0;i<n.selection.ranges.length&&!r;i++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[i];n.doc.nodesBetween(o,s,(o,i)=>{if(r)return!1;if(o.isTextblock&&!o.hasMarkup(e,t))if(o.type==e)r=!0;else{let t=n.doc.resolve(i),o=t.index();r=t.parent.canReplaceWith(o,o+1,e)}})}if(!r)return!1;if(o){let r=n.tr;for(let o=0;o<n.selection.ranges.length;o++){let{$from:{pos:i},$to:{pos:s}}=n.selection.ranges[o];r.setBlockType(i,s,e,t)}o(r.scrollIntoView())}return!0}}function Ua(...e){return function(t,n,o){for(let r=0;r<e.length;r++)if(e[r](t,n,o))return!0;return!1}}function Wa(e,t=null){return function(n,o){let{$from:r,$to:i}=n.selection,s=r.blockRange(i);if(!s)return!1;let l=o?n.tr:null;return!!function(e,t,n,o=null){let r=!1,i=t,s=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=s.resolve(t.start-2);i=new Zn(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new Zn(t.$from,s.resolve(t.$to.end(t.depth)),t.depth)),r=!0}let l=tr(i,n,o,t);if(!l)return!1;e&&function(e,t,n,o,r){let i=Rn.empty;for(let d=n.length-1;d>=0;d--)i=Rn.from(n[d].type.create(n[d].attrs,i));e.step(new Jo(t.start-(o?2:0),t.end,t.start,t.end,new _n(i,0,0),n.length,!0));let s=0;for(let d=0;d<n.length;d++)n[d].type==r&&(s=d+1);let l=n.length-s,a=t.start+n.length-(o?2:0),c=t.parent;for(let d=t.startIndex,u=t.endIndex,h=!0;d<u;d++,h=!1)!h&&ir(e.doc,a,l)&&(e.split(a,l),a+=2*l),a+=c.child(d).nodeSize}(e,t,l,r,n);return!0}(l,s,e,t)&&(o&&o(l.scrollIntoView()),!0)}}function qa(e){return function(t,n){let{$from:o,$to:r}=t.selection,i=o.blockRange(r,t=>t.childCount>0&&t.firstChild.type==e);return!!i&&(!n||(o.node(i.depth-1).type==e?function(e,t,n,o){let r=e.tr,i=o.end,s=o.$to.end(o.depth);i<s&&(r.step(new Jo(i-1,s,i,s,new _n(Rn.from(n.create(null,o.parent.copy())),1,0),1,!0)),o=new Zn(r.doc.resolve(o.$from.pos),r.doc.resolve(s),o.depth));const l=er(o);if(null==l)return!1;r.lift(o,l);let a=r.doc.resolve(r.mapping.map(i,-1)-1);sr(r.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&r.join(a.pos);return t(r.scrollIntoView()),!0}(t,n,e,i):function(e,t,n){let o=e.tr,r=n.parent;for(let p=n.end,f=n.endIndex-1,m=n.startIndex;f>m;f--)p-=r.child(f).nodeSize,o.delete(p-1,p+1);let i=o.doc.resolve(n.start),s=i.nodeAfter;if(o.mapping.map(n.end)!=n.start+i.nodeAfter.nodeSize)return!1;let l=0==n.startIndex,a=n.endIndex==r.childCount,c=i.node(-1),d=i.index(-1);if(!c.canReplace(d+(l?0:1),d+1,s.content.append(a?Rn.empty:Rn.from(r))))return!1;let u=i.pos,h=u+s.nodeSize;return o.step(new Jo(u-(l?1:0),h+(a?1:0),u+1,h-1,new _n((l?Rn.empty:Rn.from(r.copy(Rn.empty))).append(a?Rn.empty:Rn.from(r.copy(Rn.empty))),l?0:1,a?0:1),l?0:1)),t(o.scrollIntoView()),!0}(t,n,i)))}}function Ga(e){const{state:t,transaction:n}=e;let{selection:o}=n,{doc:r}=n,{storedMarks:i}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return i},get selection(){return o},get doc(){return r},get tr(){return o=n.selection,r=n.doc,i=n.storedMarks,n}}}Ua(Ca,Sa,Ta),Ua(Ca,Aa,Oa),Ua(Pa,La,Da,Ba),"undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&os.platform();class Ka{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:t,state:n}=this,{view:o}=t,{tr:r}=n,i=this.buildProps(r);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{const n=t(...e)(i);return r.getMeta("preventDispatch")||this.hasCustomState||o.dispatch(r),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:n,editor:o,state:r}=this,{view:i}=o,s=[],l=!!e,a=e||r.tr,c={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{const o=this.buildProps(a,t),r=n(...e)(o);return s.push(r),c}])),run:()=>(l||!t||a.getMeta("preventDispatch")||this.hasCustomState||i.dispatch(a),s.every(e=>!0===e))};return c}createCan(e){const{rawCommands:t,state:n}=this,o=!1,r=e||n.tr,i=this.buildProps(r,o);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,o)}}buildProps(e,t=!0){const{rawCommands:n,editor:o,state:r}=this,{view:i}=o,s={tr:e,editor:o,view:i,state:Ga({state:r,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(s)]))}};return s}}class Za{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){const n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){const n=(...o)=>{this.off(e,n),t.apply(this,o)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}}function Ja(e,t,n){if(void 0===e.config[t]&&e.parent)return Ja(e.parent,t,n);if("function"==typeof e.config[t]){return e.config[t].bind({...n,parent:e.parent?Ja(e.parent,t,n):null})}return e.config[t]}function Xa(e){return{baseExtensions:e.filter(e=>"extension"===e.type),nodeExtensions:e.filter(e=>"node"===e.type),markExtensions:e.filter(e=>"mark"===e.type)}}function Ya(e){const t=[],{nodeExtensions:n,markExtensions:o}=Xa(e),r=[...n,...o],i={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return e.forEach(e=>{const n=Ja(e,"addGlobalAttributes",{name:e.name,options:e.options,storage:e.storage,extensions:r});if(!n)return;n().forEach(e=>{e.types.forEach(n=>{Object.entries(e.attributes).forEach(([e,o])=>{t.push({type:n,name:e,attribute:{...i,...o}})})})})}),r.forEach(e=>{const n={name:e.name,options:e.options,storage:e.storage},o=Ja(e,"addAttributes",n);if(!o)return;const r=o();Object.entries(r).forEach(([n,o])=>{const r={...i,...o};"function"==typeof(null==r?void 0:r.default)&&(r.default=r.default()),(null==r?void 0:r.isRequired)&&void 0===(null==r?void 0:r.default)&&delete r.default,t.push({type:e.name,name:n,attribute:r})})}),t}function Qa(e,t){if("string"==typeof e){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function ec(...e){return e.filter(e=>!!e).reduce((e,t)=>{const n={...e};return Object.entries(t).forEach(([e,t])=>{if(n[e])if("class"===e){const o=t?String(t).split(" "):[],r=n[e]?n[e].split(" "):[],i=o.filter(e=>!r.includes(e));n[e]=[...r,...i].join(" ")}else if("style"===e){const o=t?t.split(";").map(e=>e.trim()).filter(Boolean):[],r=n[e]?n[e].split(";").map(e=>e.trim()).filter(Boolean):[],i=new Map;r.forEach(e=>{const[t,n]=e.split(":").map(e=>e.trim());i.set(t,n)}),o.forEach(e=>{const[t,n]=e.split(":").map(e=>e.trim());i.set(t,n)}),n[e]=Array.from(i.entries()).map(([e,t])=>`${e}: ${t}`).join("; ")}else n[e]=t;else n[e]=t}),n},{})}function tc(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>ec(e,t),{})}function nc(e){return"function"==typeof e}function oc(e,t=void 0,...n){return nc(e)?t?e.bind(t)(...n):e(...n):e}function rc(e,t){return"style"in e?e:{...e,getAttrs:n=>{const o=e.getAttrs?e.getAttrs(n):e.attrs;if(!1===o)return!1;const r=t.reduce((e,t)=>{const o=t.attribute.parseHTML?t.attribute.parseHTML(n):function(e){return"string"!=typeof e?e:e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):"true"===e||"false"!==e&&e}(n.getAttribute(t.name));return null==o?e:{...e,[t.name]:o}},{});return{...o,...r}}}}function ic(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>("attrs"!==e||!function(e={}){return 0===Object.keys(e).length&&e.constructor===Object}(t))&&null!=t))}function sc(e,t){var n;const o=Ya(e),{nodeExtensions:r,markExtensions:i}=Xa(e),s=null===(n=r.find(e=>Ja(e,"topNode")))||void 0===n?void 0:n.name,l=Object.fromEntries(r.map(n=>{const r=o.filter(e=>e.type===n.name),i={name:n.name,options:n.options,storage:n.storage,editor:t},s=ic({...e.reduce((e,t)=>{const o=Ja(t,"extendNodeSchema",i);return{...e,...o?o(n):{}}},{}),content:oc(Ja(n,"content",i)),marks:oc(Ja(n,"marks",i)),group:oc(Ja(n,"group",i)),inline:oc(Ja(n,"inline",i)),atom:oc(Ja(n,"atom",i)),selectable:oc(Ja(n,"selectable",i)),draggable:oc(Ja(n,"draggable",i)),code:oc(Ja(n,"code",i)),whitespace:oc(Ja(n,"whitespace",i)),linebreakReplacement:oc(Ja(n,"linebreakReplacement",i)),defining:oc(Ja(n,"defining",i)),isolating:oc(Ja(n,"isolating",i)),attrs:Object.fromEntries(r.map(e=>{var t;return[e.name,{default:null===(t=null==e?void 0:e.attribute)||void 0===t?void 0:t.default}]}))}),l=oc(Ja(n,"parseHTML",i));l&&(s.parseDOM=l.map(e=>rc(e,r)));const a=Ja(n,"renderHTML",i);a&&(s.toDOM=e=>a({node:e,HTMLAttributes:tc(e,r)}));const c=Ja(n,"renderText",i);return c&&(s.toText=c),[n.name,s]})),a=Object.fromEntries(i.map(n=>{const r=o.filter(e=>e.type===n.name),i={name:n.name,options:n.options,storage:n.storage,editor:t},s=ic({...e.reduce((e,t)=>{const o=Ja(t,"extendMarkSchema",i);return{...e,...o?o(n):{}}},{}),inclusive:oc(Ja(n,"inclusive",i)),excludes:oc(Ja(n,"excludes",i)),group:oc(Ja(n,"group",i)),spanning:oc(Ja(n,"spanning",i)),code:oc(Ja(n,"code",i)),attrs:Object.fromEntries(r.map(e=>{var t;return[e.name,{default:null===(t=null==e?void 0:e.attribute)||void 0===t?void 0:t.default}]}))}),l=oc(Ja(n,"parseHTML",i));l&&(s.parseDOM=l.map(e=>rc(e,r)));const a=Ja(n,"renderHTML",i);return a&&(s.toDOM=e=>a({mark:e,HTMLAttributes:tc(e,r)})),[n.name,s]}));return new yo({topNode:s,nodes:l,marks:a})}function lc(e,t){return t.nodes[e]||t.marks[e]||null}function ac(e,t){return Array.isArray(t)?t.some(t=>("string"==typeof t?t:t.name)===e.name):t}function cc(e,t){const n=jo.fromSchema(t).serializeFragment(e),o=document.implementation.createHTMLDocument().createElement("div");return o.appendChild(n),o.innerHTML}function dc(e){return"[object RegExp]"===Object.prototype.toString.call(e)}class uc{constructor(e){this.find=e.find,this.handler=e.handler}}function hc(e){var t;const{editor:n,from:o,to:r,text:i,rules:s,plugin:l}=e,{view:a}=n;if(a.composing)return!1;const c=a.state.doc.resolve(o);if(c.parent.type.spec.code||(null===(t=c.nodeBefore||c.nodeAfter)||void 0===t?void 0:t.marks.find(e=>e.type.spec.code)))return!1;let d=!1;const u=((e,t=500)=>{let n="";const o=e.parentOffset;return e.parent.nodesBetween(Math.max(0,o-t),o,(e,t,r,i)=>{var s,l;const a=(null===(l=(s=e.type.spec).toText)||void 0===l?void 0:l.call(s,{node:e,pos:t,parent:r,index:i}))||e.textContent||"%leaf%";n+=e.isAtom&&!e.isText?a:a.slice(0,Math.max(0,o-t))}),n})(c)+i;return s.forEach(e=>{if(d)return;const t=((e,t)=>{if(dc(t))return t.exec(e);const n=t(e);if(!n)return null;const o=[n.text];return o.index=n.index,o.input=e,o.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith),o.push(n.replaceWith)),o})(u,e.find);if(!t)return;const s=a.state.tr,c=Ga({state:a.state,transaction:s}),h={from:o-(t[0].length-i.length),to:r},{commands:p,chain:f,can:m}=new Ka({editor:n,state:c});null!==e.handler({state:c,range:h,match:t,commands:p,chain:f,can:m})&&s.steps.length&&(s.setMeta(l,{transform:s,from:o,to:r,text:i}),a.dispatch(s),d=!0)}),d}function pc(e){const{editor:t,rules:n}=e,o=new Wr({state:{init:()=>null,apply(e,r,i){const s=e.getMeta(o);if(s)return s;const l=e.getMeta("applyInputRules");return!!l&&setTimeout(()=>{let{text:e}=l;"string"==typeof e||(e=cc(Rn.from(e),i.schema));const{from:r}=l,s=r+e.length;hc({editor:t,from:r,to:s,text:e,rules:n,plugin:o})}),e.selectionSet||e.docChanged?null:r}},props:{handleTextInput:(e,r,i,s)=>hc({editor:t,from:r,to:i,text:s,rules:n,plugin:o}),handleDOMEvents:{compositionend:e=>(setTimeout(()=>{const{$cursor:r}=e.state.selection;r&&hc({editor:t,from:r.pos,to:r.pos,text:"",rules:n,plugin:o})}),!1)},handleKeyDown(e,r){if("Enter"!==r.key)return!1;const{$cursor:i}=e.state.selection;return!!i&&hc({editor:t,from:i.pos,to:i.pos,text:"\n",rules:n,plugin:o})}},isInputRules:!0});return o}function fc(e){return"Object"===function(e){return Object.prototype.toString.call(e).slice(8,-1)}(e)&&(e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype)}function mc(e,t){const n={...e};return fc(e)&&fc(t)&&Object.keys(t).forEach(o=>{fc(t[o])&&fc(e[o])?n[o]=mc(e[o],t[o]):n[o]=t[o]}),n}class gc{constructor(e={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=oc(Ja(this,"addOptions",{name:this.name}))),this.storage=oc(Ja(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new gc(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>mc(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new gc(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,t.options=oc(Ja(t,"addOptions",{name:t.name})),t.storage=oc(Ja(t,"addStorage",{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){const{tr:n}=e.state,o=e.state.selection.$from;if(o.pos===o.end()){const r=o.marks();if(!!!r.find(e=>(null==e?void 0:e.type.name)===t.name))return!1;const i=r.find(e=>(null==e?void 0:e.type.name)===t.name);return i&&n.removeStoredMark(i),n.insertText(" ",o.pos),e.view.dispatch(n),!0}return!1}}class yc{constructor(e){this.find=e.find,this.handler=e.handler}}function bc(e){const{editor:t,state:n,from:o,to:r,rule:i,pasteEvent:s,dropEvent:l}=e,{commands:a,chain:c,can:d}=new Ka({editor:t,state:n}),u=[];n.doc.nodesBetween(o,r,(e,t)=>{if(!e.isTextblock||e.type.spec.code)return;const h=Math.max(o,t),p=Math.min(r,t+e.content.size);((e,t,n)=>{if(dc(t))return[...e.matchAll(t)];const o=t(e,n);return o?o.map(t=>{const n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith),n.push(t.replaceWith)),n}):[]})(e.textBetween(h-t,p-t,void 0,""),i.find,s).forEach(e=>{if(void 0===e.index)return;const t=h+e.index+1,o=t+e[0].length,r={from:n.tr.mapping.map(t),to:n.tr.mapping.map(o)},p=i.handler({state:n,range:r,match:e,commands:a,chain:c,can:d,pasteEvent:s,dropEvent:l});u.push(p)})});return u.every(e=>null!==e)}let vc=null;function xc(e){const{editor:t,rules:n}=e;let o,r=null,i=!1,s=!1,l="undefined"!=typeof ClipboardEvent?new ClipboardEvent("paste"):null;try{o="undefined"!=typeof DragEvent?new DragEvent("drop"):null}catch{o=null}const a=({state:e,from:n,to:r,rule:i,pasteEvt:s})=>{const a=e.tr,c=Ga({state:e,transaction:a});if(bc({editor:t,state:c,from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:s,dropEvent:o})&&a.steps.length){try{o="undefined"!=typeof DragEvent?new DragEvent("drop"):null}catch{o=null}return l="undefined"!=typeof ClipboardEvent?new ClipboardEvent("paste"):null,a}};return n.map(e=>new Wr({view(e){const n=n=>{var o;r=(null===(o=e.dom.parentElement)||void 0===o?void 0:o.contains(n.target))?e.dom.parentElement:null,r&&(vc=t)},o=()=>{vc&&(vc=null)};return window.addEventListener("dragstart",n),window.addEventListener("dragend",o),{destroy(){window.removeEventListener("dragstart",n),window.removeEventListener("dragend",o)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(s=r===e.dom.parentElement,o=t,!s){const e=vc;(null==e?void 0:e.isEditable)&&setTimeout(()=>{const t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{var n;const o=null===(n=t.clipboardData)||void 0===n?void 0:n.getData("text/html");return l=t,i=!!(null==o?void 0:o.includes("data-pm-slice")),!1}}},appendTransaction:(t,n,o)=>{const r=t[0],c="paste"===r.getMeta("uiEvent")&&!i,d="drop"===r.getMeta("uiEvent")&&!s,u=r.getMeta("applyPasteRules"),h=!!u;if(!c&&!d&&!h)return;if(h){let{text:t}=u;"string"==typeof t||(t=cc(Rn.from(t),o.schema));const{from:n}=u,r=n+t.length,i=(e=>{var t;const n=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return null===(t=n.clipboardData)||void 0===t||t.setData("text/html",e),n})(t);return a({rule:e,state:o,from:n,to:{b:r},pasteEvt:i})}const p=n.doc.content.findDiffStart(o.doc.content),f=n.doc.content.findDiffEnd(o.doc.content);return"number"==typeof p&&f&&p!==f.b?a({rule:e,state:o,from:p,to:f,pasteEvt:l}):void 0}}))}class wc{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=wc.resolve(e),this.schema=sc(this.extensions,t),this.setupExtensions()}static resolve(e){const t=wc.sort(wc.flatten(e));return function(e){const t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}(t.map(e=>e.name)).length,t}static flatten(e){return e.map(e=>{const t=Ja(e,"addExtensions",{name:e.name,options:e.options,storage:e.storage});return t?[e,...this.flatten(t())]:e}).flat(10)}static sort(e){return e.sort((e,t)=>{const n=Ja(e,"priority")||100,o=Ja(t,"priority")||100;return n>o?-1:n<o?1:0})}get commands(){return this.extensions.reduce((e,t)=>{const n=Ja(t,"addCommands",{name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:lc(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){const{editor:e}=this,t=wc.sort([...this.extensions].reverse()),n=[],o=[],r=t.map(t=>{const r={name:t.name,options:t.options,storage:t.storage,editor:e,type:lc(t.name,this.schema)},i=[],s=Ja(t,"addKeyboardShortcuts",r);let l={};if("mark"===t.type&&Ja(t,"exitable",r)&&(l.ArrowRight=()=>gc.handleExit({editor:e,mark:t})),s){const t=Object.fromEntries(Object.entries(s()).map(([t,n])=>[t,()=>n({editor:e})]));l={...l,...t}}const a=new Wr({props:{handleKeyDown:ka(l)}});i.push(a);const c=Ja(t,"addInputRules",r);ac(t,e.options.enableInputRules)&&c&&n.push(...c());const d=Ja(t,"addPasteRules",r);ac(t,e.options.enablePasteRules)&&d&&o.push(...d());const u=Ja(t,"addProseMirrorPlugins",r);if(u){const e=u();i.push(...e)}return i}).flat();return[pc({editor:e,rules:n}),...xc({editor:e,rules:o}),...r]}get attributes(){return Ya(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=Xa(this.extensions);return Object.fromEntries(t.filter(e=>!!Ja(e,"addNodeView")).map(t=>{const n=this.attributes.filter(e=>e.type===t.name),o={name:t.name,options:t.options,storage:t.storage,editor:e,type:Qa(t.name,this.schema)},r=Ja(t,"addNodeView",o);if(!r)return[];return[t.name,(o,i,s,l,a)=>{const c=tc(o,n);return r()({node:o,view:i,getPos:s,decorations:l,innerDecorations:a,editor:e,extension:t,HTMLAttributes:c})}]}))}setupExtensions(){this.extensions.forEach(e=>{var t;this.editor.extensionStorage[e.name]=e.storage;const n={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:lc(e.name,this.schema)};if("mark"===e.type){(null===(t=oc(Ja(e,"keepOnSplit",n)))||void 0===t||t)&&this.splittableMarks.push(e.name)}const o=Ja(e,"onBeforeCreate",n),r=Ja(e,"onCreate",n),i=Ja(e,"onUpdate",n),s=Ja(e,"onSelectionUpdate",n),l=Ja(e,"onTransaction",n),a=Ja(e,"onFocus",n),c=Ja(e,"onBlur",n),d=Ja(e,"onDestroy",n);o&&this.editor.on("beforeCreate",o),r&&this.editor.on("create",r),i&&this.editor.on("update",i),s&&this.editor.on("selectionUpdate",s),l&&this.editor.on("transaction",l),a&&this.editor.on("focus",a),c&&this.editor.on("blur",c),d&&this.editor.on("destroy",d)})}}class kc{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=oc(Ja(this,"addOptions",{name:this.name}))),this.storage=oc(Ja(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new kc(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>mc(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new kc({...this.config,...e});return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,t.options=oc(Ja(t,"addOptions",{name:t.name})),t.storage=oc(Ja(t,"addStorage",{name:t.name,options:t.options})),t}}function Cc(e,t,n){const{from:o,to:r}=t,{blockSeparator:i="\n\n",textSerializers:s={}}=n||{};let l="";return e.nodesBetween(o,r,(e,n,a,c)=>{var d;e.isBlock&&n>o&&(l+=i);const u=null==s?void 0:s[e.type.name];if(u)return a&&(l+=u({node:e,pos:n,parent:a,index:c,range:t})),!1;e.isText&&(l+=null===(d=null==e?void 0:e.text)||void 0===d?void 0:d.slice(Math.max(o,n)-n,r-n))}),l}function Ec(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const Sc=kc.create({name:"clipboardTextSerializer",addOptions:()=>({blockSeparator:void 0}),addProseMirrorPlugins(){return[new Wr({key:new Kr("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:o,selection:r}=t,{ranges:i}=r,s=Math.min(...i.map(e=>e.$from.pos)),l=Math.max(...i.map(e=>e.$to.pos)),a=Ec(n);return Cc(o,{from:s,to:l},{...void 0!==this.options.blockSeparator?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}});function Mc(e,t,n={strict:!0}){const o=Object.keys(t);return!o.length||o.every(o=>n.strict?t[o]===e[o]:dc(t[o])?t[o].test(e[o]):t[o]===e[o])}function Rc(e,t,n={}){return e.find(e=>e.type===t&&Mc(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function Tc(e,t,n={}){return!!Rc(e,t,n)}function jc(e,t,n){var o;if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;n=n||(null===(o=r.node.marks[0])||void 0===o?void 0:o.attrs);if(!Rc([...r.node.marks],t,n))return;let i=r.index,s=e.start()+r.offset,l=i+1,a=s+r.node.nodeSize;for(;i>0&&Tc([...e.parent.child(i-1).marks],t,n);)i-=1,s-=e.parent.child(i).nodeSize;for(;l<e.parent.childCount&&Tc([...e.parent.child(l).marks],t,n);)a+=e.parent.child(l).nodeSize,l+=1;return{from:s,to:a}}function Nc(e,t){if("string"==typeof e){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}function Ac(e){return e instanceof Nr}function Oc(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function _c(e,t=null){if(!t)return null;const n=Mr.atStart(e),o=Mr.atEnd(e);if("start"===t||!0===t)return n;if("end"===t)return o;const r=n.from,i=o.to;return"all"===t?Nr.create(e,Oc(0,r,i),Oc(e.content.size,r,i)):Nr.create(e,Oc(t,r,i),Oc(t,r,i))}function Pc(){return"Android"===navigator.platform||/android/i.test(navigator.userAgent)}function Ic(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const Lc=e=>{const t=e.childNodes;for(let n=t.length-1;n>=0;n-=1){const o=t[n];3===o.nodeType&&o.nodeValue&&/^(\n\s\s|\n)$/.test(o.nodeValue)?e.removeChild(o):1===o.nodeType&&Lc(o)}return e};function Dc(e){const t=`<body>${e}</body>`,n=(new window.DOMParser).parseFromString(t,"text/html").body;return Lc(n)}function Bc(e,t,n){if(e instanceof Xn||e instanceof Rn)return e;n={slice:!0,parseOptions:{},...n};const o="string"==typeof e;if("object"==typeof e&&null!==e)try{if(Array.isArray(e)&&e.length>0)return Rn.fromArray(e.map(e=>t.nodeFromJSON(e)));const o=t.nodeFromJSON(e);return n.errorOnInvalidContent&&o.check(),o}catch(r){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:r});return Bc("",t,n)}if(o){if(n.errorOnInvalidContent){let o=!1,r="";const i=new yo({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:e=>(o=!0,r="string"==typeof e?e:e.outerHTML,null)}]}})});if(n.slice?vo.fromSchema(i).parseSlice(Dc(e),n.parseOptions):vo.fromSchema(i).parse(Dc(e),n.parseOptions),n.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${r}`)})}const o=vo.fromSchema(t);return n.slice?o.parseSlice(Dc(e),n.parseOptions).content:o.parse(Dc(e),n.parseOptions)}return Bc("",t,n)}function Hc(e,t,n){const o=e.steps.length-1;if(o<t)return;const r=e.steps[o];if(!(r instanceof Zo||r instanceof Jo))return;const i=e.mapping.maps[o];let s=0;i.forEach((e,t,n,o)=>{0===s&&(s=o)}),e.setSelection(Mr.near(e.doc.resolve(s),n))}function Vc(){return"undefined"!=typeof navigator&&/Mac/.test(navigator.platform)}function $c(e,t,n={}){const{from:o,to:r,empty:i}=e.selection,s=t?Qa(t,e.schema):null,l=[];e.doc.nodesBetween(o,r,(e,t)=>{if(e.isText)return;const n=Math.max(o,t),i=Math.min(r,t+e.nodeSize);l.push({node:e,from:n,to:i})});const a=r-o,c=l.filter(e=>!s||s.name===e.node.type.name).filter(e=>Mc(e.node.attrs,n,{strict:!1}));if(i)return!!c.length;return c.reduce((e,t)=>e+t.to-t.from,0)>=a}function zc(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function Fc(e,t){const n="string"==typeof t?[t]:t;return Object.keys(e).reduce((t,o)=>(n.includes(o)||(t[o]=e[o]),t),{})}function Uc(e,t,n={},o={}){return Bc(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:o.errorOnInvalidContent})}function Wc(e,t){const n=Nc(t,e.schema),{from:o,to:r,empty:i}=e.selection,s=[];i?(e.storedMarks&&s.push(...e.storedMarks),s.push(...e.selection.$head.marks())):e.doc.nodesBetween(o,r,e=>{s.push(...e.marks)});const l=s.find(e=>e.type.name===n.name);return l?{...l.attrs}:{}}function qc(e,t){const n=new Er(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function Gc(e,t){const n=[];return e.descendants((e,o)=>{t(e)&&n.push({node:e,pos:o})}),n}function Kc(e,t,n){const o=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&o.push({node:e,pos:t})}),o}function Zc(e){return t=>function(e,t){for(let n=e.depth;n>0;n-=1){const o=e.node(n);if(t(o))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:o}}}(t.$from,e)}function Jc(e,t){const n=zc("string"==typeof t?t:t.name,e.schema);return"node"===n?function(e,t){const n=Qa(t,e.schema),{from:o,to:r}=e.selection,i=[];e.doc.nodesBetween(o,r,e=>{i.push(e)});const s=i.reverse().find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}(e,t):"mark"===n?Wc(e,t):{}}function Xc(e){const t=function(e,t=JSON.stringify){const n={};return e.filter(e=>{const o=t(e);return!Object.prototype.hasOwnProperty.call(n,o)&&(n[o]=!0)})}(e);return 1===t.length?t:t.filter((e,n)=>{const o=t.filter((e,t)=>t!==n);return!o.some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to)})}function Yc(e){const{mapping:t,steps:n}=e,o=[];return t.maps.forEach((e,r)=>{const i=[];if(e.ranges.length)e.forEach((e,t)=>{i.push({from:e,to:t})});else{const{from:e,to:t}=n[r];if(void 0===e||void 0===t)return;i.push({from:e,to:t})}i.forEach(({from:e,to:n})=>{const i=t.slice(r).map(e,-1),s=t.slice(r).map(n),l=t.invert().map(i,-1),a=t.invert().map(s);o.push({oldRange:{from:l,to:a},newRange:{from:i,to:s}})})}),Xc(o)}function Qc(e,t,n){const o=[];return e===t?n.resolve(e).marks().forEach(t=>{const r=jc(n.resolve(e),t.type);r&&o.push({mark:t,...r})}):n.nodesBetween(e,t,(e,t)=>{e&&void 0!==(null==e?void 0:e.nodeSize)&&o.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),o}function ed(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{const o=e.find(e=>e.type===t&&e.name===n);return!!o&&o.attribute.keepOnSplit}))}function td(e,t,n={}){const{empty:o,ranges:r}=e.selection,i=t?Nc(t,e.schema):null;if(o)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!i||i.name===e.type.name).find(e=>Mc(e.attrs,n,{strict:!1}));let s=0;const l=[];if(r.forEach(({$from:t,$to:n})=>{const o=t.pos,r=n.pos;e.doc.nodesBetween(o,r,(e,t)=>{if(!e.isText&&!e.marks.length)return;const n=Math.max(o,t),i=Math.min(r,t+e.nodeSize);s+=i-n,l.push(...e.marks.map(e=>({mark:e,from:n,to:i})))})}),0===s)return!1;const a=l.filter(e=>!i||i.name===e.mark.type.name).filter(e=>Mc(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),c=l.filter(e=>!i||e.mark.type!==i&&e.mark.type.excludes(i)).reduce((e,t)=>e+t.to-t.from,0);return(a>0?a+c:a)>=s}function nd(e,t){const{nodeExtensions:n}=Xa(t),o=n.find(t=>t.name===e);if(!o)return!1;const r=oc(Ja(o,"group",{name:o.name,options:o.options,storage:o.storage}));return"string"==typeof r&&r.split(" ").includes("list")}function od(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){var o;if(n){if("hardBreak"===e.type.name)return!0;if(e.isText)return/^\s*$/m.test(null!==(o=e.text)&&void 0!==o?o:"")}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(0===e.content.childCount)return!0;if(t){let o=!0;return e.content.forEach(e=>{!1!==o&&(od(e,{ignoreWhitespace:n,checkChildren:t})||(o=!1))}),o}return!1}function rd(e){return e instanceof Or}function id(e,t,n){const o=e.state.doc.content.size,r=Oc(t,0,o),i=Oc(n,0,o),s=e.coordsAtPos(r),l=e.coordsAtPos(i,-1),a=Math.min(s.top,l.top),c=Math.max(s.bottom,l.bottom),d=Math.min(s.left,l.left),u=Math.max(s.right,l.right),h={top:a,bottom:c,left:d,right:u,width:u-d,height:c-a,x:d,y:a};return{...h,toJSON:()=>h}}function sd(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const o=n.filter(e=>null==t?void 0:t.includes(e.type.name));e.tr.ensureMarks(o)}}const ld=(e,t)=>{const n=Zc(e=>e.type===t)(e.selection);if(!n)return!0;const o=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(void 0===o)return!0;const r=e.doc.nodeAt(o);return n.node.type!==(null==r?void 0:r.type)||!sr(e.doc,n.pos)||(e.join(n.pos),!0)},ad=(e,t)=>{const n=Zc(e=>e.type===t)(e.selection);if(!n)return!0;const o=e.doc.resolve(n.start).after(n.depth);if(void 0===o)return!0;const r=e.doc.nodeAt(o);return n.node.type!==(null==r?void 0:r.type)||!sr(e.doc,o)||(e.join(o),!0)};var cd=Object.freeze({__proto__:null,blur:()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),null===(n=null===window||void 0===window?void 0:window.getSelection())||void 0===n||n.removeAllRanges())}),!0),clearContent:(e=!1)=>({commands:t})=>t.setContent("",e),clearNodes:()=>({state:e,tr:t,dispatch:n})=>{const{selection:o}=t,{ranges:r}=o;return!n||(r.forEach(({$from:n,$to:o})=>{e.doc.nodesBetween(n.pos,o.pos,(e,n)=>{if(e.type.isText)return;const{doc:o,mapping:r}=t,i=o.resolve(r.map(n)),s=o.resolve(r.map(n+e.nodeSize)),l=i.blockRange(s);if(!l)return;const a=er(l);if(e.type.isTextblock){const{defaultType:e}=i.parent.contentMatchAt(i.index());t.setNodeMarkup(l.start,e)}(a||0===a)&&t.lift(l,a)})}),!0)},command:e=>t=>e(t),createParagraphNear:()=>({state:e,dispatch:t})=>La(e,t),cut:(e,t)=>({editor:n,tr:o})=>{const{state:r}=n,i=r.doc.slice(e.from,e.to);o.deleteRange(e.from,e.to);const s=o.mapping.map(t);return o.insert(s,i.content),o.setSelection(new Nr(o.doc.resolve(Math.max(s-1,0)))),!0},deleteCurrentNode:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,o=n.$anchor.node();if(o.content.size>0)return!1;const r=e.selection.$anchor;for(let i=r.depth;i>0;i-=1){if(r.node(i).type===o.type){if(t){const t=r.before(i),n=r.after(i);e.delete(t,n).scrollIntoView()}return!0}}return!1},deleteNode:e=>({tr:t,state:n,dispatch:o})=>{const r=Qa(e,n.schema),i=t.selection.$anchor;for(let e=i.depth;e>0;e-=1){if(i.node(e).type===r){if(o){const n=i.before(e),o=i.after(e);t.delete(n,o).scrollIntoView()}return!0}}return!1},deleteRange:e=>({tr:t,dispatch:n})=>{const{from:o,to:r}=e;return n&&t.delete(o,r),!0},deleteSelection:()=>({state:e,dispatch:t})=>Ca(e,t),enter:()=>({commands:e})=>e.keyboardShortcut("Enter"),exitCode:()=>({state:e,dispatch:t})=>((e,t)=>{let{$head:n,$anchor:o}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(o))return!1;let r=n.node(-1),i=n.indexAfter(-1),s=Ia(r.contentMatchAt(i));if(!s||!r.canReplaceWith(i,i,s))return!1;if(t){let o=n.after(),r=e.tr.replaceWith(o,o,s.createAndFill());r.setSelection(Mr.near(r.doc.resolve(o),1)),t(r.scrollIntoView())}return!0})(e,t),extendMarkRange:(e,t={})=>({tr:n,state:o,dispatch:r})=>{const i=Nc(e,o.schema),{doc:s,selection:l}=n,{$from:a,from:c,to:d}=l;if(r){const e=jc(a,i,t);if(e&&e.from<=c&&e.to>=d){const t=Nr.create(s,e.from,e.to);n.setSelection(t)}}return!0},first:e=>t=>{const n="function"==typeof e?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1},focus:(e=null,t={})=>({editor:n,view:o,tr:r,dispatch:i})=>{t={scrollIntoView:!0,...t};const s=()=>{(Ic()||Pc())&&o.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(o.focus(),(null==t?void 0:t.scrollIntoView)&&n.commands.scrollIntoView())})};if(o.hasFocus()&&null===e||!1===e)return!0;if(i&&null===e&&!Ac(n.state.selection))return s(),!0;const l=_c(r.doc,e)||n.state.selection,a=n.state.selection.eq(l);return i&&(a||r.setSelection(l),a&&r.storedMarks&&r.setStoredMarks(r.storedMarks),s()),!0},forEach:(e,t)=>n=>e.every((e,o)=>t(e,{...n,index:o})),insertContent:(e,t)=>({tr:n,commands:o})=>o.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),insertContentAt:(e,t,n)=>({tr:o,dispatch:r,editor:i})=>{var s;if(r){let r;const a=e=>{i.emit("contentError",{editor:i,error:e,disableCollaboration:()=>{i.storage.collaboration&&(i.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...(n={parseOptions:i.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n}).parseOptions};if(!n.errorOnInvalidContent&&!i.options.enableContentCheck&&i.options.emitContentError)try{Bc(t,i.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(l){a(l)}try{r=Bc(t,i.schema,{parseOptions:c,errorOnInvalidContent:null!==(s=n.errorOnInvalidContent)&&void 0!==s?s:i.options.enableContentCheck})}catch(l){return a(l),!1}let{from:d,to:u}="number"==typeof e?{from:e,to:e}:{from:e.from,to:e.to},h=!0,p=!0;if(("type"in r?[r]:r).forEach(e=>{e.check(),h=!!h&&(e.isText&&0===e.marks.length),p=!!p&&e.isBlock}),d===u&&p){const{parent:e}=o.doc.resolve(d);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(d-=1,u+=1)}let f;if(h){if(Array.isArray(t))f=t.map(e=>e.text||"").join("");else if(t instanceof Rn){let e="";t.forEach(t=>{t.text&&(e+=t.text)}),f=e}else f="object"==typeof t&&t&&t.text?t.text:t;o.insertText(f,d,u)}else f=r,o.replaceWith(d,u,f);n.updateSelection&&Hc(o,o.steps.length-1,-1),n.applyInputRules&&o.setMeta("applyInputRules",{from:d,text:f}),n.applyPasteRules&&o.setMeta("applyPasteRules",{from:d,text:f})}return!0},joinBackward:()=>({state:e,dispatch:t})=>Sa(e,t),joinDown:()=>({state:e,dispatch:t})=>((e,t)=>{let n,o=e.selection;if(o instanceof Or){if(o.node.isTextblock||!sr(e.doc,o.to))return!1;n=o.to}else if(n=ar(e.doc,o.to,1),null==n)return!1;return t&&t(e.tr.join(n).scrollIntoView()),!0})(e,t),joinForward:()=>({state:e,dispatch:t})=>Aa(e,t),joinItemBackward:()=>({state:e,dispatch:t,tr:n})=>{try{const o=ar(e.doc,e.selection.$from.pos,-1);return null!=o&&(n.join(o,2),t&&t(n),!0)}catch{return!1}},joinItemForward:()=>({state:e,dispatch:t,tr:n})=>{try{const o=ar(e.doc,e.selection.$from.pos,1);return null!=o&&(n.join(o,2),t&&t(n),!0)}catch{return!1}},joinTextblockBackward:()=>({state:e,dispatch:t})=>((e,t,n)=>{let o=Ea(e,n);if(!o)return!1;let r=ja(o);return!!r&&Ma(e,r,t)})(e,t),joinTextblockForward:()=>({state:e,dispatch:t})=>((e,t,n)=>{let o=Na(e,n);if(!o)return!1;let r=_a(o);return!!r&&Ma(e,r,t)})(e,t),joinUp:()=>({state:e,dispatch:t})=>((e,t)=>{let n,o=e.selection,r=o instanceof Or;if(r){if(o.node.isTextblock||!sr(e.doc,o.from))return!1;n=o.from}else if(n=ar(e.doc,o.from,-1),null==n)return!1;if(t){let o=e.tr.join(n);r&&o.setSelection(Or.create(o.doc,n-e.doc.resolve(n).nodeBefore.nodeSize)),t(o.scrollIntoView())}return!0})(e,t),keyboardShortcut:e=>({editor:t,view:n,tr:o,dispatch:r})=>{const i=function(e){const t=e.split(/-(?!$)/);let n,o,r,i,s=t[t.length-1];"Space"===s&&(s=" ");for(let l=0;l<t.length-1;l+=1){const e=t[l];if(/^(cmd|meta|m)$/i.test(e))i=!0;else if(/^a(lt)?$/i.test(e))n=!0;else if(/^(c|ctrl|control)$/i.test(e))o=!0;else if(/^s(hift)?$/i.test(e))r=!0;else{if(!/^mod$/i.test(e))throw new Error(`Unrecognized modifier name: ${e}`);Ic()||Vc()?i=!0:o=!0}}return n&&(s=`Alt-${s}`),o&&(s=`Ctrl-${s}`),i&&(s=`Meta-${s}`),r&&(s=`Shift-${s}`),s}(e).split(/-(?!$)/),s=i.find(e=>!["Alt","Ctrl","Meta","Shift"].includes(e)),l=new KeyboardEvent("keydown",{key:"Space"===s?" ":s,altKey:i.includes("Alt"),ctrlKey:i.includes("Ctrl"),metaKey:i.includes("Meta"),shiftKey:i.includes("Shift"),bubbles:!0,cancelable:!0}),a=t.captureTransaction(()=>{n.someProp("handleKeyDown",e=>e(n,l))});return null==a||a.steps.forEach(e=>{const t=e.map(o.mapping);t&&r&&o.maybeStep(t)}),!0},lift:(e,t={})=>({state:n,dispatch:o})=>!!$c(n,Qa(e,n.schema),t)&&((e,t)=>{let{$from:n,$to:o}=e.selection,r=n.blockRange(o),i=r&&er(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)})(n,o),liftEmptyBlock:()=>({state:e,dispatch:t})=>Da(e,t),liftListItem:e=>({state:t,dispatch:n})=>qa(Qa(e,t.schema))(t,n),newlineInCode:()=>({state:e,dispatch:t})=>Pa(e,t),resetAttributes:(e,t)=>({tr:n,state:o,dispatch:r})=>{let i=null,s=null;const l=zc("string"==typeof e?e:e.name,o.schema);return!!l&&("node"===l&&(i=Qa(e,o.schema)),"mark"===l&&(s=Nc(e,o.schema)),r&&n.selection.ranges.forEach(e=>{o.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,o)=>{i&&i===e.type&&n.setNodeMarkup(o,void 0,Fc(e.attrs,t)),s&&e.marks.length&&e.marks.forEach(r=>{s===r.type&&n.addMark(o,o+e.nodeSize,s.create(Fc(r.attrs,t)))})})}),!0)},scrollIntoView:()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),selectAll:()=>({tr:e,dispatch:t})=>{if(t){const t=new Pr(e.doc);e.setSelection(t)}return!0},selectNodeBackward:()=>({state:e,dispatch:t})=>Ta(e,t),selectNodeForward:()=>({state:e,dispatch:t})=>Oa(e,t),selectParentNode:()=>({state:e,dispatch:t})=>((e,t)=>{let n,{$from:o,to:r}=e.selection,i=o.sharedDepth(r);return 0!=i&&(n=o.before(i),t&&t(e.tr.setSelection(Or.create(e.doc,n))),!0)})(e,t),selectTextblockEnd:()=>({state:e,dispatch:t})=>za(e,t),selectTextblockStart:()=>({state:e,dispatch:t})=>$a(e,t),setContent:(e,t=!1,n={},o={})=>({editor:r,tr:i,dispatch:s,commands:l})=>{var a,c;const{doc:d}=i;if("full"!==n.preserveWhitespace){const l=Uc(e,r.schema,n,{errorOnInvalidContent:null!==(a=o.errorOnInvalidContent)&&void 0!==a?a:r.options.enableContentCheck});return s&&i.replaceWith(0,d.content.size,l).setMeta("preventUpdate",!t),!0}return s&&i.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:d.content.size},e,{parseOptions:n,errorOnInvalidContent:null!==(c=o.errorOnInvalidContent)&&void 0!==c?c:r.options.enableContentCheck})},setMark:(e,t={})=>({tr:n,state:o,dispatch:r})=>{const{selection:i}=n,{empty:s,ranges:l}=i,a=Nc(e,o.schema);if(r)if(s){const e=Wc(o,a);n.addStoredMark(a.create({...e,...t}))}else l.forEach(e=>{const r=e.$from.pos,i=e.$to.pos;o.doc.nodesBetween(r,i,(e,o)=>{const s=Math.max(o,r),l=Math.min(o+e.nodeSize,i);e.marks.find(e=>e.type===a)?e.marks.forEach(e=>{a===e.type&&n.addMark(s,l,a.create({...e.attrs,...t}))}):n.addMark(s,l,a.create(t))})});return function(e,t,n){var o;const{selection:r}=t;let i=null;if(Ac(r)&&(i=r.$cursor),i){const t=null!==(o=e.storedMarks)&&void 0!==o?o:i.marks();return!!n.isInSet(t)||!t.some(e=>e.type.excludes(n))}const{ranges:s}=r;return s.some(({$from:t,$to:o})=>{let r=0===t.depth&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,o.pos,(e,t,o)=>{if(r)return!1;if(e.isInline){const t=!o||o.type.allowsMarkType(n),i=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));r=t&&i}return!r}),r})}(o,n,a)},setMeta:(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),setNode:(e,t={})=>({state:n,dispatch:o,chain:r})=>{const i=Qa(e,n.schema);let s;return n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),!!i.isTextblock&&r().command(({commands:e})=>!!Fa(i,{...s,...t})(n)||e.clearNodes()).command(({state:e})=>Fa(i,{...s,...t})(e,o)).run()},setNodeSelection:e=>({tr:t,dispatch:n})=>{if(n){const{doc:n}=t,o=Oc(e,0,n.content.size),r=Or.create(n,o);t.setSelection(r)}return!0},setTextSelection:e=>({tr:t,dispatch:n})=>{if(n){const{doc:n}=t,{from:o,to:r}="number"==typeof e?{from:e,to:e}:e,i=Nr.atStart(n).from,s=Nr.atEnd(n).to,l=Oc(o,i,s),a=Oc(r,i,s),c=Nr.create(n,l,a);t.setSelection(c)}return!0},sinkListItem:e=>({state:t,dispatch:n})=>{const o=Qa(e,t.schema);return(r=o,function(e,t){let{$from:n,$to:o}=e.selection,i=n.blockRange(o,e=>e.childCount>0&&e.firstChild.type==r);if(!i)return!1;let s=i.startIndex;if(0==s)return!1;let l=i.parent,a=l.child(s-1);if(a.type!=r)return!1;if(t){let n=a.lastChild&&a.lastChild.type==l.type,o=Rn.from(n?r.create():null),s=new _n(Rn.from(r.create(null,Rn.from(l.type.create(null,o)))),n?3:1,0),c=i.start,d=i.end;t(e.tr.step(new Jo(c-(n?3:1),d,c,d,s,1,!0)).scrollIntoView())}return!0})(t,n);var r},splitBlock:({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:o,editor:r})=>{const{selection:i,doc:s}=t,{$from:l,$to:a}=i,c=ed(r.extensionManager.attributes,l.node().type.name,l.node().attrs);if(i instanceof Or&&i.node.isBlock)return!(!l.parentOffset||!ir(s,l.pos))&&(o&&(e&&sd(n,r.extensionManager.splittableMarks),t.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const d=a.parentOffset===a.parent.content.size,u=0===l.depth?void 0:function(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=d&&u?[{type:u,attrs:c}]:void 0,p=ir(t.doc,t.mapping.map(l.pos),1,h);if(h||p||!ir(t.doc,t.mapping.map(l.pos),1,u?[{type:u}]:void 0)||(p=!0,h=u?[{type:u,attrs:c}]:void 0),o){if(p&&(i instanceof Nr&&t.deleteSelection(),t.split(t.mapping.map(l.pos),1,h),u&&!d&&!l.parentOffset&&l.parent.type!==u)){const e=t.mapping.map(l.before()),n=t.doc.resolve(e);l.node(-1).canReplaceWith(n.index(),n.index()+1,u)&&t.setNodeMarkup(t.mapping.map(l.before()),u)}e&&sd(n,r.extensionManager.splittableMarks),t.scrollIntoView()}return p},splitListItem:(e,t={})=>({tr:n,state:o,dispatch:r,editor:i})=>{var s;const l=Qa(e,o.schema),{$from:a,$to:c}=o.selection,d=o.selection.node;if(d&&d.isBlock||a.depth<2||!a.sameParent(c))return!1;const u=a.node(-1);if(u.type!==l)return!1;const h=i.extensionManager.attributes;if(0===a.parent.content.size&&a.node(-1).childCount===a.indexAfter(-1)){if(2===a.depth||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(r){let e=Rn.empty;const o=a.index(-1)?1:a.index(-2)?2:3;for(let t=a.depth-o;t>=a.depth-3;t-=1)e=Rn.from(a.node(t).copy(e));const r=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,i={...ed(h,a.node().type.name,a.node().attrs),...t},c=(null===(s=l.contentMatch.defaultType)||void 0===s?void 0:s.createAndFill(i))||void 0;e=e.append(Rn.from(l.createAndFill(null,c)||void 0));const d=a.before(a.depth-(o-1));n.replace(d,a.after(-r),new _n(e,4-o,0));let u=-1;n.doc.nodesBetween(d,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&0===e.content.size&&(u=t+1)}),u>-1&&n.setSelection(Nr.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}const p=c.pos===a.end()?u.contentMatchAt(0).defaultType:null,f={...ed(h,u.type.name,u.attrs),...t},m={...ed(h,a.node().type.name,a.node().attrs),...t};n.delete(a.pos,c.pos);const g=p?[{type:l,attrs:f},{type:p,attrs:m}]:[{type:l,attrs:f}];if(!ir(n.doc,a.pos,2))return!1;if(r){const{selection:e,storedMarks:t}=o,{splittableMarks:s}=i.extensionManager,l=t||e.$to.parentOffset&&e.$from.marks();if(n.split(a.pos,2,g).scrollIntoView(),!l||!r)return!0;const c=l.filter(e=>s.includes(e.type.name));n.ensureMarks(c)}return!0},toggleList:(e,t,n,o={})=>({editor:r,tr:i,state:s,dispatch:l,chain:a,commands:c,can:d})=>{const{extensions:u,splittableMarks:h}=r.extensionManager,p=Qa(e,s.schema),f=Qa(t,s.schema),{selection:m,storedMarks:g}=s,{$from:y,$to:b}=m,v=y.blockRange(b),x=g||m.$to.parentOffset&&m.$from.marks();if(!v)return!1;const w=Zc(e=>nd(e.type.name,u))(m);if(v.depth>=1&&w&&v.depth-w.depth<=1){if(w.node.type===p)return c.liftListItem(f);if(nd(w.node.type.name,u)&&p.validContent(w.node.content)&&l)return a().command(()=>(i.setNodeMarkup(w.pos,p),!0)).command(()=>ld(i,p)).command(()=>ad(i,p)).run()}return n&&x&&l?a().command(()=>{const e=d().wrapInList(p,o),t=x.filter(e=>h.includes(e.type.name));return i.ensureMarks(t),!!e||c.clearNodes()}).wrapInList(p,o).command(()=>ld(i,p)).command(()=>ad(i,p)).run():a().command(()=>!!d().wrapInList(p,o)||c.clearNodes()).wrapInList(p,o).command(()=>ld(i,p)).command(()=>ad(i,p)).run()},toggleMark:(e,t={},n={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:i=!1}=n,s=Nc(e,o.schema);return td(o,s,t)?r.unsetMark(s,{extendEmptyMarkRange:i}):r.setMark(s,t)},toggleNode:(e,t,n={})=>({state:o,commands:r})=>{const i=Qa(e,o.schema),s=Qa(t,o.schema),l=$c(o,i,n);let a;return o.selection.$anchor.sameParent(o.selection.$head)&&(a=o.selection.$anchor.parent.attrs),l?r.setNode(s,a):r.setNode(i,{...a,...n})},toggleWrap:(e,t={})=>({state:n,commands:o})=>{const r=Qa(e,n.schema);return $c(n,r,t)?o.lift(r):o.wrapIn(r,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let o=0;o<n.length;o+=1){const r=n[o];let i;if(r.spec.isInputRules&&(i=r.getState(e))){if(t){const t=e.tr,n=i.transform;for(let e=n.steps.length-1;e>=0;e-=1)t.step(n.steps[e].invert(n.docs[e]));if(i.text){const n=t.doc.resolve(i.from).marks();t.replaceWith(i.from,i.to,e.schema.text(i.text,n))}else t.delete(i.from,i.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:o,ranges:r}=n;return o||t&&r.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:o,dispatch:r})=>{var i;const{extendEmptyMarkRange:s=!1}=t,{selection:l}=n,a=Nc(e,o.schema),{$from:c,empty:d,ranges:u}=l;if(!r)return!0;if(d&&s){let{from:e,to:t}=l;const o=null===(i=c.marks().find(e=>e.type===a))||void 0===i?void 0:i.attrs,r=jc(c,a,o);r&&(e=r.from,t=r.to),n.removeMark(e,t,a)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,a)});return n.removeStoredMark(a),!0},updateAttributes:(e,t={})=>({tr:n,state:o,dispatch:r})=>{let i=null,s=null;const l=zc("string"==typeof e?e:e.name,o.schema);return!!l&&("node"===l&&(i=Qa(e,o.schema)),"mark"===l&&(s=Nc(e,o.schema)),r&&n.selection.ranges.forEach(e=>{const r=e.$from.pos,l=e.$to.pos;let a,c,d,u;n.selection.empty?o.doc.nodesBetween(r,l,(e,t)=>{i&&i===e.type&&(d=Math.max(t,r),u=Math.min(t+e.nodeSize,l),a=t,c=e)}):o.doc.nodesBetween(r,l,(e,o)=>{o<r&&i&&i===e.type&&(d=Math.max(o,r),u=Math.min(o+e.nodeSize,l),a=o,c=e),o>=r&&o<=l&&(i&&i===e.type&&n.setNodeMarkup(o,void 0,{...e.attrs,...t}),s&&e.marks.length&&e.marks.forEach(i=>{if(s===i.type){const a=Math.max(o,r),c=Math.min(o+e.nodeSize,l);n.addMark(a,c,s.create({...i.attrs,...t}))}}))}),c&&(void 0!==a&&n.setNodeMarkup(a,void 0,{...c.attrs,...t}),s&&c.marks.length&&c.marks.forEach(e=>{s===e.type&&n.addMark(d,u,s.create({...e.attrs,...t}))}))}),!0)},wrapIn:(e,t={})=>({state:n,dispatch:o})=>function(e,t=null){return function(n,o){let{$from:r,$to:i}=n.selection,s=r.blockRange(i),l=s&&tr(s,e,t);return!!l&&(o&&o(n.tr.wrap(s,l).scrollIntoView()),!0)}}(Qa(e,n.schema),t)(n,o),wrapInList:(e,t={})=>({state:n,dispatch:o})=>Wa(Qa(e,n.schema),t)(n,o)});const dd=kc.create({name:"commands",addCommands:()=>({...cd})}),ud=kc.create({name:"drop",addProseMirrorPlugins(){return[new Wr({key:new Kr("tiptapDrop"),props:{handleDrop:(e,t,n,o)=>{this.editor.emit("drop",{editor:this.editor,event:t,slice:n,moved:o})}}})]}}),hd=kc.create({name:"editable",addProseMirrorPlugins(){return[new Wr({key:new Kr("editable"),props:{editable:()=>this.editor.options.editable}})]}}),pd=new Kr("focusEvents"),fd=kc.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new Wr({key:pd,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const o=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(o),!1},blur:(t,n)=>{e.isFocused=!1;const o=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(o),!1}}}})]}}),md=kc.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{const{selection:n,doc:o}=t,{empty:r,$anchor:i}=n,{pos:s,parent:l}=i,a=i.parent.isTextblock&&s>0?t.doc.resolve(s-1):i,c=a.parent.type.spec.isolating,d=i.pos-i.parentOffset,u=c&&1===a.parent.childCount?d===i.pos:Mr.atStart(o).from===s;return!(!r||!l.type.isTextblock||l.textContent.length||!u||u&&"paragraph"===i.parent.type.name)&&e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},o={...n},r={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Ic()||Vc()?r:o},addProseMirrorPlugins(){return[new Wr({key:new Kr("clearDocument"),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta("composition")))return;const o=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),r=e.some(e=>e.getMeta("preventClearDocument"));if(!o||r)return;const{empty:i,from:s,to:l}=t.selection,a=Mr.atStart(t.doc).from,c=Mr.atEnd(t.doc).to;if(i||!(s===a&&l===c))return;if(!od(n.doc))return;const d=n.tr,u=Ga({state:n,transaction:d}),{commands:h}=new Ka({editor:this.editor,state:u});return h.clearNodes(),d.steps.length?d:void 0}})]}}),gd=kc.create({name:"paste",addProseMirrorPlugins(){return[new Wr({key:new Kr("tiptapPaste"),props:{handlePaste:(e,t,n)=>{this.editor.emit("paste",{editor:this.editor,event:t,slice:n})}}})]}}),yd=kc.create({name:"tabindex",addProseMirrorPlugins(){return[new Wr({key:new Kr("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});var bd=Object.freeze({__proto__:null,ClipboardTextSerializer:Sc,Commands:dd,Drop:ud,Editable:hd,FocusEvents:fd,Keymap:md,Paste:gd,Tabindex:yd,focusEventsPluginKey:pd});class vd{get name(){return this.node.type.name}constructor(e,t,n=!1,o=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=o}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return null!==(e=this.actualDepth)&&void 0!==e?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(0===this.content.size)return;t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(0===this.depth)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new vd(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new vd(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new vd(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,n)=>{const o=t.isBlock&&!t.isTextblock,r=t.isAtom&&!t.isText,i=this.pos+n+(r?0:1);if(i<0||i>this.resolvedPos.doc.nodeSize-2)return;const s=this.resolvedPos.doc.resolve(i);if(!o&&s.depth<=this.depth)return;const l=new vd(s,this.editor,o,o?t:null);o&&(l.actualDepth=this.depth+1),e.push(new vd(s,this.editor,o,o?t:null))}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,o=this.parent;for(;o&&!n;){if(o.node.type.name===e)if(Object.keys(t).length>0){const e=o.node.attrs,n=Object.keys(t);for(let o=0;o<n.length;o+=1){const r=n[o];if(e[r]!==t[r])break}}else n=o;o=o.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let o=[];if(!this.children||0===this.children.length)return o;const r=Object.keys(t);return this.children.forEach(i=>{if(!(n&&o.length>0)){if(i.node.type.name===e){r.every(e=>t[e]===i.node.attrs[e])&&o.push(i)}n&&o.length>0||(o=o.concat(i.querySelectorAll(e,t,n)))}}),o}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}}class xd extends Za{constructor(e={}){super(),this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("contentError",this.options.onContentError),this.createView(),this.injectCSS(),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on("paste",({event:e,slice:t})=>this.options.onPaste(e,t)),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&document&&(this.css=function(e,t){const n=document.querySelector("style[data-tiptap-style]");if(null!==n)return n;const o=document.createElement("style");return t&&o.setAttribute("nonce",t),o.setAttribute("data-tiptap-style",""),o.innerHTML=e,document.getElementsByTagName("head")[0].appendChild(o),o}('.ProseMirror {\n position: relative;\n}\n\n.ProseMirror {\n word-wrap: break-word;\n white-space: pre-wrap;\n white-space: break-spaces;\n -webkit-font-variant-ligatures: none;\n font-variant-ligatures: none;\n font-feature-settings: "liga" 0; /* the above doesn\'t seem to work in Edge */\n}\n\n.ProseMirror [contenteditable="false"] {\n white-space: normal;\n}\n\n.ProseMirror [contenteditable="false"] [contenteditable="true"] {\n white-space: pre-wrap;\n}\n\n.ProseMirror pre {\n white-space: pre-wrap;\n}\n\nimg.ProseMirror-separator {\n display: inline !important;\n border: none !important;\n margin: 0 !important;\n width: 0 !important;\n height: 0 !important;\n}\n\n.ProseMirror-gapcursor {\n display: none;\n pointer-events: none;\n position: absolute;\n margin: 0;\n}\n\n.ProseMirror-gapcursor:after {\n content: "";\n display: block;\n position: absolute;\n top: -2px;\n width: 20px;\n border-top: 1px solid black;\n animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;\n}\n\n@keyframes ProseMirror-cursor-blink {\n to {\n visibility: hidden;\n }\n}\n\n.ProseMirror-hideselection *::selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection *::-moz-selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection * {\n caret-color: transparent;\n}\n\n.ProseMirror-focused .ProseMirror-gapcursor {\n display: block;\n}\n\n.tippy-box[data-animation=fade][data-state=hidden] {\n opacity: 0\n}',this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},this.view&&this.state&&!this.isDestroyed&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit("update",{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,t){const n=nc(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],o=this.state.reconfigure({plugins:n});return this.view.updateState(o),o}unregisterPlugin(e){if(this.isDestroyed)return;const t=this.state.plugins;let n=t;if([].concat(e).forEach(e=>{const t="string"==typeof e?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;const o=this.state.reconfigure({plugins:n});return this.view.updateState(o),o}createExtensionManager(){var e,t;const n=[...this.options.enableCoreExtensions?[hd,Sc.configure({blockSeparator:null===(t=null===(e=this.options.coreExtensionOptions)||void 0===e?void 0:e.clipboardTextSerializer)||void 0===t?void 0:t.blockSeparator}),dd,fd,md,yd,ud,gd].filter(e=>"object"!=typeof this.options.enableCoreExtensions||!1!==this.options.enableCoreExtensions[e.name]):[],...this.options.extensions].filter(e=>["extension","node","mark"].includes(null==e?void 0:e.type));this.extensionManager=new wc(n,this)}createCommandManager(){this.commandManager=new Ka({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let t;try{t=Uc(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(r){if(!(r instanceof Error&&["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(r.message)))throw r;this.emit("contentError",{editor:this,error:r,disableCollaboration:()=>{this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>"collaboration"!==e.name),this.createExtensionManager()}}),t=Uc(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const n=_c(t,this.options.autofocus);this.view=new sa(this.options.element,{...this.options.editorProps,attributes:{role:"textbox",...null===(e=this.options.editorProps)||void 0===e?void 0:e.attributes},dispatchTransaction:this.dispatchTransaction.bind(this),state:Fr.create({doc:t,selection:n||void 0})});const o=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(o),this.createNodeViews(),this.prependClass();this.view.dom.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`tiptap ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction)return this.capturedTransaction?void e.steps.forEach(e=>{var t;return null===(t=this.capturedTransaction)||void 0===t?void 0:t.step(e)}):void(this.capturedTransaction=e);const t=this.state.apply(e),n=!this.state.selection.eq(t.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),n&&this.emit("selectionUpdate",{editor:this,transaction:e});const o=e.getMeta("focus"),r=e.getMeta("blur");o&&this.emit("focus",{editor:this,event:o.event,transaction:e}),r&&this.emit("blur",{editor:this,event:r.event,transaction:e}),e.docChanged&&!e.getMeta("preventUpdate")&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return Jc(this.state,e)}isActive(e,t){const n="string"==typeof e?e:null,o="string"==typeof e?t:e;return function(e,t,n={}){if(!t)return $c(e,null,n)||td(e,null,n);const o=zc(t,e.schema);return"node"===o?$c(e,t,n):"mark"===o&&td(e,t,n)}(this.state,n,o)}getJSON(){return this.state.doc.toJSON()}getHTML(){return cc(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t="\n\n",textSerializers:n={}}=e||{};return function(e,t){return Cc(e,{from:0,to:e.content.size},t)}(this.state.doc,{blockSeparator:t,textSerializers:{...Ec(this.schema),...n}})}get isEmpty(){return od(this.state.doc)}getCharacterCount(){return this.state.doc.content.size-2}destroy(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(null===(e=this.view)||void 0===e?void 0:e.docView)}$node(e,t){var n;return(null===(n=this.$doc)||void 0===n?void 0:n.querySelector(e,t))||null}$nodes(e,t){var n;return(null===(n=this.$doc)||void 0===n?void 0:n.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new vd(t,this)}get $doc(){return this.$pos(0)}}function wd(e){return new uc({find:e.find,handler:({state:t,range:n,match:o})=>{const r=oc(e.getAttributes,void 0,o);if(!1===r||null===r)return null;const{tr:i}=t,s=o[o.length-1],l=o[0];if(s){const o=l.search(/\S/),a=n.from+l.indexOf(s),c=a+s.length;if(Qc(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>a).length)return null;c<n.to&&i.delete(c,n.to),a>n.from&&i.delete(n.from+o,a);const d=n.from+o+s.length;i.addMark(n.from+o,d,e.type.create(r||{})),i.removeStoredMark(e.type)}}})}let kd=class e{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=oc(Ja(this,"addOptions",{name:this.name}))),this.storage=oc(Ja(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new e(t)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>mc(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(t={}){const n=new e(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&Object.keys(t.defaultOptions).length,n.options=oc(Ja(n,"addOptions",{name:n.name})),n.storage=oc(Ja(n,"addStorage",{name:n.name,options:n.options})),n}};class Cd{constructor(e,t,n){this.isDragging=!1,this.component=e,this.editor=t.editor,this.options={stopEvent:null,ignoreMutation:null,...n},this.extension=t.extension,this.node=t.node,this.decorations=t.decorations,this.innerDecorations=t.innerDecorations,this.view=t.view,this.HTMLAttributes=t.HTMLAttributes,this.getPos=t.getPos,this.mount()}mount(){}get dom(){return this.editor.view.dom}get contentDOM(){return null}onDragStart(e){var t,n,o,r,i,s,l;const{view:a}=this.editor,c=e.target,d=3===c.nodeType?null===(t=c.parentElement)||void 0===t?void 0:t.closest("[data-drag-handle]"):c.closest("[data-drag-handle]");if(!this.dom||(null===(n=this.contentDOM)||void 0===n?void 0:n.contains(c))||!d)return;let u=0,h=0;if(this.dom!==d){const t=this.dom.getBoundingClientRect(),n=d.getBoundingClientRect(),l=null!==(o=e.offsetX)&&void 0!==o?o:null===(r=e.nativeEvent)||void 0===r?void 0:r.offsetX,a=null!==(i=e.offsetY)&&void 0!==i?i:null===(s=e.nativeEvent)||void 0===s?void 0:s.offsetY;u=n.x-t.x+l,h=n.y-t.y+a}const p=this.dom.cloneNode(!0);null===(l=e.dataTransfer)||void 0===l||l.setDragImage(p,u,h);const f=this.getPos();if("number"!=typeof f)return;const m=Or.create(a.state.doc,f),g=a.state.tr.setSelection(m);a.dispatch(g)}stopEvent(e){var t;if(!this.dom)return!1;if("function"==typeof this.options.stopEvent)return this.options.stopEvent({event:e});const n=e.target;if(!(this.dom.contains(n)&&!(null===(t=this.contentDOM)||void 0===t?void 0:t.contains(n))))return!1;const o=e.type.startsWith("drag"),r="drop"===e.type;if((["INPUT","BUTTON","SELECT","TEXTAREA"].includes(n.tagName)||n.isContentEditable)&&!r&&!o)return!0;const{isEditable:i}=this.editor,{isDragging:s}=this,l=!!this.node.type.spec.draggable,a=Or.isSelectable(this.node),c="copy"===e.type,d="paste"===e.type,u="cut"===e.type,h="mousedown"===e.type;if(!l&&a&&o&&e.target===this.dom&&e.preventDefault(),l&&o&&!s&&e.target===this.dom)return e.preventDefault(),!1;if(l&&i&&!s&&h){const e=n.closest("[data-drag-handle]");e&&(this.dom===e||this.dom.contains(e))&&(this.isDragging=!0,document.addEventListener("dragend",()=>{this.isDragging=!1},{once:!0}),document.addEventListener("drop",()=>{this.isDragging=!1},{once:!0}),document.addEventListener("mouseup",()=>{this.isDragging=!1},{once:!0}))}return!(s||r||c||d||u||h&&a)}ignoreMutation(e){if(!this.dom||!this.contentDOM)return!0;if("function"==typeof this.options.ignoreMutation)return this.options.ignoreMutation({mutation:e});if(this.node.isLeaf||this.node.isAtom)return!0;if("selection"===e.type)return!1;if(this.dom.contains(e.target)&&"childList"===e.type&&(Ic()||Pc())&&this.editor.isFocused){if([...Array.from(e.addedNodes),...Array.from(e.removedNodes)].every(e=>e.isContentEditable))return!1}return this.contentDOM===e.target&&"attributes"===e.type||!this.contentDOM.contains(e.target)}updateAttributes(e){this.editor.commands.command(({tr:t})=>{const n=this.getPos();return"number"==typeof n&&(t.setNodeMarkup(n,void 0,{...this.node.attrs,...e}),!0)})}deleteNode(){const e=this.getPos();if("number"!=typeof e)return;const t=e+this.node.nodeSize;this.editor.commands.deleteRange({from:e,to:t})}}function Ed(e){return new yc({find:e.find,handler:({state:t,range:n,match:o,pasteEvent:r})=>{const i=oc(e.getAttributes,void 0,o,r);if(!1===i||null===i)return null;const{tr:s}=t,l=o[o.length-1],a=o[0];let c=n.to;if(l){const o=a.search(/\S/),r=n.from+a.indexOf(l),d=r+l.length;if(Qc(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>r).length)return null;d<n.to&&s.delete(d,n.to),r>n.from&&s.delete(n.from+o,r),c=n.from+o+l.length,s.addMark(n.from+o,c,e.type.create(i||{})),s.removeStoredMark(e.type)}}})}var Sd,Md=new Uint8Array(16);function Rd(){if(!Sd&&!(Sd="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Sd(Md)}const Td=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var jd,Nd,Ad=[],Od=0;Od<256;++Od)Ad.push((Od+256).toString(16).substr(1));function _d(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Ad[e[t+0]]+Ad[e[t+1]]+Ad[e[t+2]]+Ad[e[t+3]]+"-"+Ad[e[t+4]]+Ad[e[t+5]]+"-"+Ad[e[t+6]]+Ad[e[t+7]]+"-"+Ad[e[t+8]]+Ad[e[t+9]]+"-"+Ad[e[t+10]]+Ad[e[t+11]]+Ad[e[t+12]]+Ad[e[t+13]]+Ad[e[t+14]]+Ad[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&Td.test(e)}(n))throw TypeError("Stringified UUID is invalid");return n}function Pd(e,t,n){var o=(e=e||{}).random||(e.rng||Rd)();return o[6]=15&o[6]|64,o[8]=63&o[8]|128,_d(o)}if("undefined"!=typeof WeakMap){let e=new WeakMap;jd=t=>e.get(t),Nd=(t,n)=>(e.set(t,n),n)}else{const e=[],t=10;let n=0;jd=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},Nd=(o,r)=>(n==t&&(n=0),e[n++]=o,e[n++]=r)}var Id=class{constructor(e,t,n,o){this.width=e,this.height=t,this.map=n,this.problems=o}findCell(e){for(let t=0;t<this.map.length;t++){const n=this.map[t];if(n!=e)continue;const o=t%this.width,r=t/this.width|0;let i=o+1,s=r+1;for(let e=1;i<this.width&&this.map[t+e]==n;e++)i++;for(let e=1;s<this.height&&this.map[t+this.width*e]==n;e++)s++;return{left:o,top:r,right:i,bottom:s}}throw new 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 new RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){const{left:o,right:r,top:i,bottom:s}=this.findCell(e);return"horiz"==t?(n<0?0==o:r==this.width)?null:this.map[i*this.width+(n<0?o-1:r)]:(n<0?0==i:s==this.height)?null:this.map[o+this.width*(n<0?i-1:s)]}rectBetween(e,t){const{left:n,right:o,top:r,bottom:i}=this.findCell(e),{left:s,right:l,top:a,bottom:c}=this.findCell(t);return{left:Math.min(n,s),top:Math.min(r,a),right:Math.max(o,l),bottom:Math.max(i,c)}}cellsInRect(e){const t=[],n={};for(let o=e.top;o<e.bottom;o++)for(let r=e.left;r<e.right;r++){const i=o*this.width+r,s=this.map[i];n[s]||(n[s]=!0,r==e.left&&r&&this.map[i-1]==s||o==e.top&&o&&this.map[i-this.width]==s||t.push(s))}return t}positionAt(e,t,n){for(let o=0,r=0;;o++){const i=r+n.child(o).nodeSize;if(o==e){let n=t+e*this.width;const o=(e+1)*this.width;for(;n<o&&this.map[n]<r;)n++;return n==o?i-1:this.map[n]}r=i}}static get(e){return jd(e)||Nd(e,function(e){if("table"!=e.type.spec.tableRole)throw new RangeError("Not a table node: "+e.type.name);const t=function(e){let t=-1,n=!1;for(let o=0;o<e.childCount;o++){const r=e.child(o);let i=0;if(n)for(let t=0;t<o;t++){const n=e.child(t);for(let e=0;e<n.childCount;e++){const r=n.child(e);t+r.attrs.rowspan>o&&(i+=r.attrs.colspan)}}for(let e=0;e<r.childCount;e++){const t=r.child(e);i+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}-1==t?t=i:t!=i&&(t=Math.max(t,i))}return t}(e),n=e.childCount,o=[];let r=0,i=null;const s=[];for(let c=0,d=t*n;c<d;c++)o[c]=0;for(let c=0,d=0;c<n;c++){const l=e.child(c);d++;for(let e=0;;e++){for(;r<o.length&&0!=o[r];)r++;if(e==l.childCount)break;const a=l.child(e),{colspan:u,rowspan:h,colwidth:p}=a.attrs;for(let e=0;e<h;e++){if(e+c>=n){(i||(i=[])).push({type:"overlong_rowspan",pos:d,n:h-e});break}const l=r+e*t;for(let e=0;e<u;e++){0==o[l+e]?o[l+e]=d:(i||(i=[])).push({type:"collision",row:c,pos:d,n:u-e});const n=p&&p[e];if(n){const o=(l+e)%t*2,r=s[o];null==r||r!=n&&1==s[o+1]?(s[o]=n,s[o+1]=1):r==n&&s[o+1]++}}}r+=u,d+=a.nodeSize}const a=(c+1)*t;let u=0;for(;r<a;)0==o[r++]&&u++;u&&(i||(i=[])).push({type:"missing",row:c,n:u}),d++}0!==t&&0!==n||(i||(i=[])).push({type:"zero_sized"});const l=new Id(t,n,o,i);let a=!1;for(let c=0;!a&&c<s.length;c+=2)null!=s[c]&&s[c+1]<n&&(a=!0);a&&function(e,t,n){e.problems||(e.problems=[]);const o={};for(let r=0;r<e.map.length;r++){const i=e.map[r];if(o[i])continue;o[i]=!0;const s=n.nodeAt(i);if(!s)throw new RangeError(`No cell with offset ${i} found`);let l=null;const a=s.attrs;for(let n=0;n<a.colspan;n++){const o=t[2*((r+n)%e.width)];null==o||a.colwidth&&a.colwidth[n]==o||((l||(l=Ld(a)))[n]=o)}l&&e.problems.unshift({type:"colwidth mismatch",pos:i,colwidth:l})}}(l,s,e);return l}(e))}};function Ld(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function Dd(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(const n in e.nodes){const o=e.nodes[n],r=o.spec.tableRole;r&&(t[r]=o)}}return t}var Bd=new Kr("selectingCells");function Hd(e){for(let t=e.depth-1;t>0;t--)if("row"==e.node(t).type.spec.tableRole)return e.node(0).resolve(e.before(t+1));return null}function Vd(e){const t=e.selection.$head;for(let n=t.depth;n>0;n--)if("row"==t.node(n).type.spec.tableRole)return!0;return!1}function $d(e){const 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&&"cell"==t.node.type.spec.tableRole)return t.$anchor;const n=Hd(t.$head)||function(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){const o=t.type.spec.tableRole;if("cell"==o||"header_cell"==o)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){const o=t.type.spec.tableRole;if("cell"==o||"header_cell"==o)return e.doc.resolve(n-t.nodeSize)}}(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function zd(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function Fd(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function Ud(e,t,n){const o=e.node(-1),r=Id.get(o),i=e.start(-1),s=r.nextCell(e.pos-i,t,n);return null==s?null:e.node(0).resolve(i+s)}function Wd(e,t,n=1){const o={...e,colspan:e.colspan-n};return o.colwidth&&(o.colwidth=o.colwidth.slice(),o.colwidth.splice(t,n),o.colwidth.some(e=>e>0)||(o.colwidth=null)),o}function qd(e,t,n=1){const o={...e,colspan:e.colspan+n};if(o.colwidth){o.colwidth=o.colwidth.slice();for(let e=0;e<n;e++)o.colwidth.splice(t,0,0)}return o}var Gd=class e extends Mr{constructor(e,t=e){const n=e.node(-1),o=Id.get(n),r=e.start(-1),i=o.rectBetween(e.pos-r,t.pos-r),s=e.node(0),l=o.cellsInRect(i).filter(e=>e!=t.pos-r);l.unshift(t.pos-r);const a=l.map(e=>{const t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);const o=r+e+1;return new Rr(s.resolve(o),s.resolve(o+t.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(t,n){const o=t.resolve(n.map(this.$anchorCell.pos)),r=t.resolve(n.map(this.$headCell.pos));if(zd(o)&&zd(r)&&Fd(o,r)){const t=this.$anchorCell.node(-1)!=o.node(-1);return t&&this.isRowSelection()?e.rowSelection(o,r):t&&this.isColSelection()?e.colSelection(o,r):new e(o,r)}return Nr.between(o,r)}content(){const e=this.$anchorCell.node(-1),t=Id.get(e),n=this.$anchorCell.start(-1),o=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),r={},i=[];for(let l=o.top;l<o.bottom;l++){const n=[];for(let i=l*t.width+o.left,s=o.left;s<o.right;s++,i++){const s=t.map[i];if(r[s])continue;r[s]=!0;const l=t.findCell(s);let a=e.nodeAt(s);if(!a)throw RangeError(`No cell with offset ${s} found`);const c=o.left-l.left,d=l.right-o.right;if(c>0||d>0){let e=a.attrs;if(c>0&&(e=Wd(e,0,c)),d>0&&(e=Wd(e,e.colspan-d,d)),l.left<o.left){if(a=a.type.createAndFill(e),!a)throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else a=a.type.create(e,a.content)}if(l.top<o.top||l.bottom>o.bottom){const e={...a.attrs,rowspan:Math.min(l.bottom,o.bottom)-Math.max(l.top,o.top)};a=l.top<o.top?a.type.createAndFill(e):a.type.create(e,a.content)}n.push(a)}i.push(e.child(l).copy(Rn.from(n)))}const s=this.isColSelection()&&this.isRowSelection()?e:i;return new _n(Rn.from(s),1,1)}replace(e,t=_n.empty){const n=e.steps.length,o=this.ranges;for(let i=0;i<o.length;i++){const{$from:r,$to:s}=o[i],l=e.mapping.slice(n);e.replace(l.map(r.pos),l.map(s.pos),i?_n.empty:t)}const r=Mr.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);r&&e.setSelection(r)}replaceWith(e,t){this.replace(e,new _n(Rn.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),n=Id.get(t),o=this.$anchorCell.start(-1),r=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-o,this.$headCell.pos-o));for(let i=0;i<r.length;i++)e(t.nodeAt(r[i]),o+r[i])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,o=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,o)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){const o=t.node(-1),r=Id.get(o),i=t.start(-1),s=r.findCell(t.pos-i),l=r.findCell(n.pos-i),a=t.node(0);return s.top<=l.top?(s.top>0&&(t=a.resolve(i+r.map[s.left])),l.bottom<r.height&&(n=a.resolve(i+r.map[r.width*(r.height-1)+l.right-1]))):(l.top>0&&(n=a.resolve(i+r.map[l.left])),s.bottom<r.height&&(t=a.resolve(i+r.map[r.width*(r.height-1)+s.right-1]))),new e(t,n)}isRowSelection(){const e=this.$anchorCell.node(-1),t=Id.get(e),n=this.$anchorCell.start(-1),o=t.colCount(this.$anchorCell.pos-n),r=t.colCount(this.$headCell.pos-n);if(Math.min(o,r)>0)return!1;const i=o+this.$anchorCell.nodeAfter.attrs.colspan,s=r+this.$headCell.nodeAfter.attrs.colspan;return Math.max(i,s)==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){const o=t.node(-1),r=Id.get(o),i=t.start(-1),s=r.findCell(t.pos-i),l=r.findCell(n.pos-i),a=t.node(0);return s.left<=l.left?(s.left>0&&(t=a.resolve(i+r.map[s.top*r.width])),l.right<r.width&&(n=a.resolve(i+r.map[r.width*(l.top+1)-1]))):(l.left>0&&(n=a.resolve(i+r.map[l.top*r.width])),s.right<r.width&&(t=a.resolve(i+r.map[r.width*(s.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,o=n){return new e(t.resolve(n),t.resolve(o))}getBookmark(){return new Kd(this.$anchorCell.pos,this.$headCell.pos)}};Gd.prototype.visible=!1,Mr.jsonID("cell",Gd);var Kd=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){const t=e.resolve(this.anchor),n=e.resolve(this.head);return"row"==t.parent.type.spec.tableRole&&"row"==n.parent.type.spec.tableRole&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&Fd(t,n)?new Gd(t,n):Mr.near(n,1)}};function Zd(e){if(!(e.selection instanceof Gd))return null;const t=[];return e.selection.forEachCell((e,n)=>{t.push(Ol.node(n,n+e.nodeSize,{class:"selectedCell"}))}),Il.create(e.doc,t)}var Jd=new Kr("fix-tables");function Xd(e,t,n,o){const r=e.childCount,i=t.childCount;e:for(let s=0,l=0;s<i;s++){const i=t.child(s);for(let t=l,o=Math.min(r,s+3);t<o;t++)if(e.child(t)==i){l=t+1,n+=i.nodeSize;continue e}o(i,n),l<r&&e.child(l).sameMarkup(i)?Xd(e.child(l),i,n+1,o):i.nodesBetween(0,i.content.size,o,n+1),n+=i.nodeSize}}function Yd(e,t){let n;const o=(t,o)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,o){const r=Id.get(t);if(!r.problems)return o;o||(o=e.tr);const i=[];for(let a=0;a<r.height;a++)i.push(0);for(let a=0;a<r.problems.length;a++){const e=r.problems[a];if("collision"==e.type){const r=t.nodeAt(e.pos);if(!r)continue;const s=r.attrs;for(let t=0;t<s.rowspan;t++)i[e.row+t]+=e.n;o.setNodeMarkup(o.mapping.map(n+1+e.pos),null,Wd(s,s.colspan-e.n,e.n))}else if("missing"==e.type)i[e.row]+=e.n;else if("overlong_rowspan"==e.type){const r=t.nodeAt(e.pos);if(!r)continue;o.setNodeMarkup(o.mapping.map(n+1+e.pos),null,{...r.attrs,rowspan:r.attrs.rowspan-e.n})}else if("colwidth mismatch"==e.type){const r=t.nodeAt(e.pos);if(!r)continue;o.setNodeMarkup(o.mapping.map(n+1+e.pos),null,{...r.attrs,colwidth:e.colwidth})}else if("zero_sized"==e.type){const e=o.mapping.map(n);o.delete(e,e+t.nodeSize)}}let s,l;for(let a=0;a<i.length;a++)i[a]&&(null==s&&(s=a),l=a);for(let a=0,c=n+1;a<r.height;a++){const n=t.child(a),r=c+n.nodeSize,d=i[a];if(d>0){let t="cell";n.firstChild&&(t=n.firstChild.type.spec.tableRole);const i=[];for(let n=0;n<d;n++){const n=Dd(e.schema)[t].createAndFill();n&&i.push(n)}const u=0!=a&&s!=a-1||l!=a?r-1:c+1;o.insert(o.mapping.map(u),i)}c=r}return o.setMeta(Jd,{fixTables:!0})}(e,t,o,n))};return t?t.doc!=e.doc&&Xd(t.doc,e.doc,0,o):e.doc.descendants(o),n}function Qd(e){const t=e.selection,n=$d(e),o=n.node(-1),r=n.start(-1),i=Id.get(o);return{...t instanceof Gd?i.rectBetween(t.$anchorCell.pos-r,t.$headCell.pos-r):i.findCell(n.pos-r),tableStart:r,map:i,table:o}}function eu(e,{map:t,tableStart:n,table:o},r){let i=r>0?-1:0;(function(e,t,n){const o=Dd(t.type.schema).header_cell;for(let r=0;r<e.height;r++)if(t.nodeAt(e.map[n+r*e.width]).type!=o)return!1;return!0})(t,o,r+i)&&(i=0==r||r==t.width?null:0);for(let s=0;s<t.height;s++){const l=s*t.width+r;if(r>0&&r<t.width&&t.map[l-1]==t.map[l]){const i=t.map[l],a=o.nodeAt(i);e.setNodeMarkup(e.mapping.map(n+i),null,qd(a.attrs,r-t.colCount(i))),s+=a.attrs.rowspan-1}else{const a=null==i?Dd(o.type.schema).cell:o.nodeAt(t.map[l+i]).type,c=t.positionAt(s,r,o);e.insert(e.mapping.map(n+c),a.createAndFill())}}return e}function tu(e,{map:t,table:n,tableStart:o},r){const i=e.mapping.maps.length;for(let s=0;s<t.height;){const l=s*t.width+r,a=t.map[l],c=n.nodeAt(a),d=c.attrs;if(r>0&&t.map[l-1]==a||r<t.width-1&&t.map[l+1]==a)e.setNodeMarkup(e.mapping.slice(i).map(o+a),null,Wd(d,r-t.colCount(a)));else{const t=e.mapping.slice(i).map(o+a);e.delete(t,t+c.nodeSize)}s+=d.rowspan}}function nu(e,{map:t,tableStart:n,table:o},r){var i;let s=n;for(let c=0;c<r;c++)s+=o.child(c).nodeSize;const l=[];let a=r>0?-1:0;(function(e,t,n){var o;const r=Dd(t.type.schema).header_cell;for(let i=0;i<e.width;i++)if((null==(o=t.nodeAt(e.map[i+n*e.width]))?void 0:o.type)!=r)return!1;return!0})(t,o,r+a)&&(a=0==r||r==t.height?null:0);for(let c=0,d=t.width*r;c<t.width;c++,d++)if(r>0&&r<t.height&&t.map[d]==t.map[d-t.width]){const r=t.map[d],i=o.nodeAt(r).attrs;e.setNodeMarkup(n+r,null,{...i,rowspan:i.rowspan+1}),c+=i.colspan-1}else{const e=null==a?Dd(o.type.schema).cell:null==(i=o.nodeAt(t.map[d+a*t.width]))?void 0:i.type,n=null==e?void 0:e.createAndFill();n&&l.push(n)}return e.insert(s,Dd(o.type.schema).row.create(null,l)),e}function ou(e,{map:t,table:n,tableStart:o},r){let i=0;for(let c=0;c<r;c++)i+=n.child(c).nodeSize;const s=i+n.child(r).nodeSize,l=e.mapping.maps.length;e.delete(i+o,s+o);const a=new Set;for(let c=0,d=r*t.width;c<t.width;c++,d++){const i=t.map[d];if(!a.has(i))if(a.add(i),r>0&&i==t.map[d-t.width]){const t=n.nodeAt(i).attrs;e.setNodeMarkup(e.mapping.slice(l).map(i+o),null,{...t,rowspan:t.rowspan-1}),c+=t.colspan-1}else if(r<t.height&&i==t.map[d+t.width]){const s=n.nodeAt(i),a=s.attrs,d=s.type.create({...a,rowspan:s.attrs.rowspan-1},s.content),u=t.positionAt(r+1,c,n);e.insert(e.mapping.slice(l).map(o+u),d),c+=a.colspan-1}}}function ru(e){const t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function iu(e,t){const n=Dd(e.schema);return(o=({node:e})=>n[e.type.spec.tableRole],(e,t)=>{var n;const r=e.selection;let i,s;if(r instanceof Gd){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,s=r.$anchorCell.pos}else{if(i=function(e){for(let t=e.depth;t>0;t--){const n=e.node(t).type.spec.tableRole;if("cell"===n||"header_cell"===n)return e.node(t)}return null}(r.$from),!i)return!1;s=null==(n=Hd(r.$from))?void 0:n.pos}if(null==i||null==s)return!1;if(1==i.attrs.colspan&&1==i.attrs.rowspan)return!1;if(t){let n=i.attrs;const l=[],a=n.colwidth;n.rowspan>1&&(n={...n,rowspan:1}),n.colspan>1&&(n={...n,colspan:1});const c=Qd(e),d=e.tr;for(let e=0;e<c.right-c.left;e++)l.push(a?{...n,colwidth:a&&a[e]?[a[e]]:null}:n);let u;for(let e=c.top;e<c.bottom;e++){let t=c.map.positionAt(e,c.left,c.table);e==c.top&&(t+=i.nodeSize);for(let n=c.left,r=0;n<c.right;n++,r++)n==c.left&&e==c.top||d.insert(u=d.mapping.map(t+c.tableStart,1),o({node:i,row:e,col:n}).createAndFill(l[r]))}d.setNodeMarkup(s,o({node:i,row:c.top,col:c.left}),l[0]),r instanceof Gd&&d.setSelection(new Gd(d.doc.resolve(r.$anchorCell.pos),u?d.doc.resolve(u):void 0)),t(d)}return!0})(e,t);var o}function su(e,t,n){const o=t.map.cellsInRect({left:0,top:0,right:"row"==e?t.map.width:1,bottom:"column"==e?t.map.height:1});for(let r=0;r<o.length;r++){const e=t.table.nodeAt(o[r]);if(e&&e.type!==n.header_cell)return!1}return!0}function lu(e,t){return(t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic?function(e){return function(t,n){if(!Vd(t))return!1;if(n){const o=Dd(t.schema),r=Qd(t),i=t.tr,s=r.map.cellsInRect("column"==e?{left:r.left,top:0,right:r.right,bottom:r.map.height}:"row"==e?{left:0,top:r.top,right:r.map.width,bottom:r.bottom}:r),l=s.map(e=>r.table.nodeAt(e));for(let e=0;e<s.length;e++)l[e].type==o.header_cell&&i.setNodeMarkup(r.tableStart+s[e],o.cell,l[e].attrs);if(0==i.steps.length)for(let e=0;e<s.length;e++)i.setNodeMarkup(r.tableStart+s[e],o.header_cell,l[e].attrs);n(i)}return!0}}(e):function(t,n){if(!Vd(t))return!1;if(n){const o=Dd(t.schema),r=Qd(t),i=t.tr,s=su("row",r,o),l=su("column",r,o),a=("column"===e?s:"row"===e&&l)?1:0,c="column"==e?{left:0,top:a,right:1,bottom:r.map.height}:"row"==e?{left:a,top:0,right:r.map.width,bottom:1}:r,d="column"==e?l?o.cell:o.header_cell:"row"==e?s?o.cell:o.header_cell:o.cell;r.map.cellsInRect(c).forEach(e=>{const t=e+r.tableStart,n=i.doc.nodeAt(t);n&&i.setNodeMarkup(t,d,n.attrs)}),n(i)}return!0}}function au(e){return function(t,n){if(!Vd(t))return!1;const o=function(e,t){if(t<0){const t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let n=e.index(-1)-1,o=e.before();n>=0;n--){const t=e.node(-1).child(n),r=t.lastChild;if(r)return o-1-r.nodeSize;o-=t.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;const t=e.node(-1);for(let n=e.indexAfter(-1),o=e.after();n<t.childCount;n++){const e=t.child(n);if(e.childCount)return o+1;o+=e.nodeSize}}return null}($d(t),e);if(null==o)return!1;if(n){const e=t.doc.resolve(o);n(t.tr.setSelection(Nr.between(e,(r=e,r.node(0).resolve(r.pos+r.nodeAfter.nodeSize)))).scrollIntoView())}var r;return!0}}function cu(e,t){const n=e.selection;if(!(n instanceof Gd))return!1;if(t){const o=e.tr,r=Dd(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(r)||o.replace(o.mapping.map(t+1),o.mapping.map(t+e.nodeSize-1),new _n(r,0,0))}),o.docChanged&&t(o)}return!0}function du(e){if(!e.size)return null;let{content:t,openStart:n,openEnd:o}=e;for(;1==t.childCount&&(n>0&&o>0||"table"==t.child(0).type.spec.tableRole);)n--,o--,t=t.child(0).content;const r=t.child(0),i=r.type.spec.tableRole,s=r.type.schema,l=[];if("row"==i)for(let a=0;a<t.childCount;a++){let e=t.child(a).content;const r=a?0:Math.max(0,n-1),i=a<t.childCount-1?0:Math.max(0,o-1);(r||i)&&(e=uu(Dd(s).row,new _n(e,r,i)).content),l.push(e)}else{if("cell"!=i&&"header_cell"!=i)return null;l.push(n||o?uu(Dd(s).row,new _n(t,n,o)).content:t)}return function(e,t){const n=[];for(let r=0;r<t.length;r++){const e=t[r];for(let t=e.childCount-1;t>=0;t--){const{rowspan:o,colspan:i}=e.child(t).attrs;for(let e=r;e<r+o;e++)n[e]=(n[e]||0)+i}}let o=0;for(let r=0;r<n.length;r++)o=Math.max(o,n[r]);for(let r=0;r<n.length;r++)if(r>=t.length&&t.push(Rn.empty),n[r]<o){const i=Dd(e).cell.createAndFill(),s=[];for(let e=n[r];e<o;e++)s.push(i);t[r]=t[r].append(Rn.from(s))}return{height:t.length,width:o,rows:t}}(s,l)}function uu(e,t){const n=e.createAndFill();return new Er(n).replace(0,n.content.size,t).doc}function hu(e,t,n,o,r,i,s,l){if(0==s||s==t.height)return!1;let a=!1;for(let c=r;c<i;c++){const r=s*t.width+c,i=t.map[r];if(t.map[r-t.width]==i){a=!0;const r=n.nodeAt(i),{top:d,left:u}=t.findCell(i);e.setNodeMarkup(e.mapping.slice(l).map(i+o),null,{...r.attrs,rowspan:s-d}),e.insert(e.mapping.slice(l).map(t.positionAt(s,u,n)),r.type.createAndFill({...r.attrs,rowspan:d+r.attrs.rowspan-s})),c+=r.attrs.colspan-1}}return a}function pu(e,t,n,o,r,i,s,l){if(0==s||s==t.width)return!1;let a=!1;for(let c=r;c<i;c++){const r=c*t.width+s,i=t.map[r];if(t.map[r-1]==i){a=!0;const r=n.nodeAt(i),d=t.colCount(i),u=e.mapping.slice(l).map(i+o);e.setNodeMarkup(u,null,Wd(r.attrs,s-d,r.attrs.colspan-(s-d))),e.insert(u+r.nodeSize,r.type.createAndFill(Wd(r.attrs,0,s-d))),c+=r.attrs.rowspan-1}}return a}function fu(e,t,n,o,r){let i=n?e.doc.nodeAt(n-1):e.doc;if(!i)throw new Error("No table found");let s=Id.get(i);const{top:l,left:a}=o,c=a+r.width,d=l+r.height,u=e.tr;let h=0;function p(){if(i=n?u.doc.nodeAt(n-1):u.doc,!i)throw new Error("No table found");s=Id.get(i),h=u.mapping.maps.length}(function(e,t,n,o,r,i,s){const l=Dd(e.doc.type.schema);let a,c;if(r>t.width)for(let d=0,u=0;d<t.height;d++){const i=n.child(d);u+=i.nodeSize;const h=[];let p;p=null==i.lastChild||i.lastChild.type==l.cell?a||(a=l.cell.createAndFill()):c||(c=l.header_cell.createAndFill());for(let e=t.width;e<r;e++)h.push(p);e.insert(e.mapping.slice(s).map(u-1+o),h)}if(i>t.height){const d=[];for(let e=0,o=(t.height-1)*t.width;e<Math.max(t.width,r);e++){const r=!(e>=t.width)&&n.nodeAt(t.map[o+e]).type==l.header_cell;d.push(r?c||(c=l.header_cell.createAndFill()):a||(a=l.cell.createAndFill()))}const u=l.row.create(null,Rn.from(d)),h=[];for(let e=t.height;e<i;e++)h.push(u);e.insert(e.mapping.slice(s).map(o+n.nodeSize-2),h)}return!(!a&&!c)})(u,s,i,n,c,d,h)&&p(),hu(u,s,i,n,a,c,l,h)&&p(),hu(u,s,i,n,a,c,d,h)&&p(),pu(u,s,i,n,l,d,a,h)&&p(),pu(u,s,i,n,l,d,c,h)&&p();for(let f=l;f<d;f++){const e=s.positionAt(f,a,i),t=s.positionAt(f,c,i);u.replace(u.mapping.slice(h).map(e+n),u.mapping.slice(h).map(t+n),new _n(r.rows[f-l],0,0))}p(),u.setSelection(new Gd(u.doc.resolve(n+s.positionAt(l,a,i)),u.doc.resolve(n+s.positionAt(d-1,c-1,i)))),t(u)}lu("row",{useDeprecatedLogic:!0}),lu("column",{useDeprecatedLogic:!0}),lu("cell",{useDeprecatedLogic:!0});var mu=ka({ArrowLeft:yu("horiz",-1),ArrowRight:yu("horiz",1),ArrowUp:yu("vert",-1),ArrowDown:yu("vert",1),"Shift-ArrowLeft":bu("horiz",-1),"Shift-ArrowRight":bu("horiz",1),"Shift-ArrowUp":bu("vert",-1),"Shift-ArrowDown":bu("vert",1),Backspace:cu,"Mod-Backspace":cu,Delete:cu,"Mod-Delete":cu});function gu(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function yu(e,t){return(n,o,r)=>{if(!r)return!1;const i=n.selection;if(i instanceof Gd)return gu(n,o,Mr.near(i.$headCell,t));if("horiz"!=e&&!i.empty)return!1;const s=ku(r,e,t);if(null==s)return!1;if("horiz"==e)return gu(n,o,Mr.near(n.doc.resolve(i.head+t),t));{const r=n.doc.resolve(s),i=Ud(r,e,t);let l;return l=i?Mr.near(i,1):t<0?Mr.near(n.doc.resolve(r.before(-1)),-1):Mr.near(n.doc.resolve(r.after(-1)),1),gu(n,o,l)}}}function bu(e,t){return(n,o,r)=>{if(!r)return!1;const i=n.selection;let s;if(i instanceof Gd)s=i;else{const o=ku(r,e,t);if(null==o)return!1;s=new Gd(n.doc.resolve(o))}const l=Ud(s.$headCell,e,t);return!!l&&gu(n,o,new Gd(s.$anchorCell,l))}}function vu(e,t){const n=Hd(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new Gd(n))),!0)}function xu(e,t,n){if(!Vd(e.state))return!1;let o=du(n);const r=e.state.selection;if(r instanceof Gd){o||(o={width:1,height:1,rows:[Rn.from(uu(Dd(e.state.schema).cell,n))]});const t=r.$anchorCell.node(-1),i=r.$anchorCell.start(-1),s=Id.get(t).rectBetween(r.$anchorCell.pos-i,r.$headCell.pos-i);return o=function({width:e,height:t,rows:n},o,r){if(e!=o){const t=[],r=[];for(let e=0;e<n.length;e++){const i=n[e],s=[];for(let n=t[e]||0,r=0;n<o;r++){let l=i.child(r%i.childCount);n+l.attrs.colspan>o&&(l=l.type.createChecked(Wd(l.attrs,l.attrs.colspan,n+l.attrs.colspan-o),l.content)),s.push(l),n+=l.attrs.colspan;for(let n=1;n<l.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+l.attrs.colspan}r.push(Rn.from(s))}n=r,e=o}if(t!=r){const e=[];for(let o=0,i=0;o<r;o++,i++){const s=[],l=n[i%t];for(let e=0;e<l.childCount;e++){let t=l.child(e);o+t.attrs.rowspan>r&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,r-t.attrs.rowspan)},t.content)),s.push(t)}e.push(Rn.from(s))}n=e,t=r}return{width:e,height:t,rows:n}}(o,s.right-s.left,s.bottom-s.top),fu(e.state,e.dispatch,i,s,o),!0}if(o){const t=$d(e.state),n=t.start(-1);return fu(e.state,e.dispatch,n,Id.get(t.node(-1)).findCell(t.pos-n),o),!0}return!1}function wu(e,t){var n;if(t.ctrlKey||t.metaKey)return;const o=Cu(e,t.target);let r;if(t.shiftKey&&e.state.selection instanceof Gd)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&o&&null!=(r=Hd(e.state.selection.$anchor))&&(null==(n=Eu(e,t))?void 0:n.pos)!=r.pos)i(r,t),t.preventDefault();else if(!o)return;function i(t,n){let o=Eu(e,n);const r=null==Bd.getState(e.state);if(!o||!Fd(t,o)){if(!r)return;o=t}const i=new Gd(t,o);if(r||!e.state.selection.eq(i)){const n=e.state.tr.setSelection(i);r&&n.setMeta(Bd,t.pos),e.dispatch(n)}}function s(){e.root.removeEventListener("mouseup",s),e.root.removeEventListener("dragstart",s),e.root.removeEventListener("mousemove",l),null!=Bd.getState(e.state)&&e.dispatch(e.state.tr.setMeta(Bd,-1))}function l(n){const r=n,l=Bd.getState(e.state);let a;if(null!=l)a=e.state.doc.resolve(l);else if(Cu(e,r.target)!=o&&(a=Eu(e,t),!a))return s();a&&i(a,r)}e.root.addEventListener("mouseup",s),e.root.addEventListener("dragstart",s),e.root.addEventListener("mousemove",l)}function ku(e,t,n){if(!(e.state.selection instanceof Nr))return null;const{$head:o}=e.state.selection;for(let r=o.depth-1;r>=0;r--){const i=o.node(r);if((n<0?o.index(r):o.indexAfter(r))!=(n<0?0:i.childCount))return null;if("cell"==i.type.spec.tableRole||"header_cell"==i.type.spec.tableRole){const i=o.before(r),s="vert"==t?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(s)?i:null}}return null}function Cu(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function Eu(e,t){const n=e.posAtCoords({left:t.clientX,top:t.clientY});return n&&n?Hd(e.state.doc.resolve(n.pos)):null}var Su=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Mu(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type==this.node.type&&(this.node=e,Mu(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function Mu(e,t,n,o,r,i){var s;let l=0,a=!0,c=t.firstChild;const d=e.firstChild;if(d){for(let e=0,n=0;e<d.childCount;e++){const{colspan:s,colwidth:u}=d.child(e).attrs;for(let e=0;e<s;e++,n++){const s=r==n?i:u&&u[e],d=s?s+"px":"";if(l+=s||o,s||(a=!1),c)c.style.width!=d&&(c.style.width=d),c=c.nextSibling;else{const e=document.createElement("col");e.style.width=d,t.appendChild(e)}}}for(;c;){const e=c.nextSibling;null==(s=c.parentNode)||s.removeChild(c),c=e}a?(n.style.width=l+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=l+"px")}}var Ru=new Kr("tableColumnResizing");function Tu({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:o=Su,lastColumnResizable:r=!0}={}){const i=new Wr({key:Ru,state:{init(e,t){var r,s;const l=null==(s=null==(r=i.spec)?void 0:r.props)?void 0:s.nodeViews,a=Dd(t.schema).table.name;return o&&l&&(l[a]=(e,t)=>new o(e,n,t)),new ju(-1,!1)},apply:(e,t)=>t.apply(e)},props:{attributes:e=>{const t=Ru.getState(e);return t&&t.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(t,n)=>{!function(e,t,n,o){if(!e.editable)return;const r=Ru.getState(e.state);if(!r)return;if(!r.dragging){const i=function(e){for(;e&&"TD"!=e.nodeName&&"TH"!=e.nodeName;)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}(t.target);let s=-1;if(i){const{left:o,right:r}=i.getBoundingClientRect();t.clientX-o<=n?s=Nu(e,t,"left",n):r-t.clientX<=n&&(s=Nu(e,t,"right",n))}if(s!=r.activeHandle){if(!o&&-1!==s){const t=e.state.doc.resolve(s),n=t.node(-1),o=Id.get(n),r=t.start(-1);if(o.colCount(t.pos-r)+t.nodeAfter.attrs.colspan-1==o.width-1)return}Ou(e,s)}}}(t,n,e,r)},mouseleave:e=>{!function(e){if(!e.editable)return;const t=Ru.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Ou(e,-1)}(e)},mousedown:(e,o)=>{!function(e,t,n,o){var r;if(!e.editable)return!1;const i=null!=(r=e.dom.ownerDocument.defaultView)?r:window,s=Ru.getState(e.state);if(!s||-1==s.activeHandle||s.dragging)return!1;const l=e.state.doc.nodeAt(s.activeHandle),a=function(e,t,{colspan:n,colwidth:o}){const r=o&&o[o.length-1];if(r)return r;const i=e.domAtPos(t);let s=i.node.childNodes[i.offset].offsetWidth,l=n;if(o)for(let a=0;a<n;a++)o[a]&&(s-=o[a],l--);return s/l}(e,s.activeHandle,l.attrs);function c(t){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",d);const o=Ru.getState(e.state);(null==o?void 0:o.dragging)&&(!function(e,t,n){const o=e.state.doc.resolve(t),r=o.node(-1),i=Id.get(r),s=o.start(-1),l=i.colCount(o.pos-s)+o.nodeAfter.attrs.colspan-1,a=e.state.tr;for(let c=0;c<i.height;c++){const e=c*i.width+l;if(c&&i.map[e]==i.map[e-i.width])continue;const t=i.map[e],o=r.nodeAt(t).attrs,d=1==o.colspan?0:l-i.colCount(t);if(o.colwidth&&o.colwidth[d]==n)continue;const u=o.colwidth?o.colwidth.slice():Pu(o.colspan);u[d]=n,a.setNodeMarkup(s+t,null,{...o,colwidth:u})}a.docChanged&&e.dispatch(a)}(e,o.activeHandle,Au(o.dragging,t,n)),e.dispatch(e.state.tr.setMeta(Ru,{setDragging:null})))}function d(t){if(!t.which)return c(t);const r=Ru.getState(e.state);if(r&&r.dragging){const i=Au(r.dragging,t,n);_u(e,r.activeHandle,i,o)}}e.dispatch(e.state.tr.setMeta(Ru,{setDragging:{startX:t.clientX,startWidth:a}})),_u(e,s.activeHandle,a,o),i.addEventListener("mouseup",c),i.addEventListener("mousemove",d),t.preventDefault()}(e,o,t,n)}},decorations:e=>{const t=Ru.getState(e);if(t&&t.activeHandle>-1)return function(e,t){var n;const o=[],r=e.doc.resolve(t),i=r.node(-1);if(!i)return Il.empty;const s=Id.get(i),l=r.start(-1),a=s.colCount(r.pos-l)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<s.height;c++){const t=a+c*s.width;if(!(a!=s.width-1&&s.map[t]==s.map[t+1]||0!=c&&s.map[t]==s.map[t-s.width])){const r=s.map[t],a=l+r+i.nodeAt(r).nodeSize-1,c=document.createElement("div");c.className="column-resize-handle",(null==(n=Ru.getState(e))?void 0:n.dragging)&&o.push(Ol.node(l+r,l+r+i.nodeAt(r).nodeSize,{class:"column-resize-dragging"})),o.push(Ol.widget(a,c))}}return Il.create(e.doc,o)}(e,t.activeHandle)},nodeViews:{}}});return i}var ju=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){const n=this,o=t.getMeta(Ru);if(o&&null!=o.setHandle)return new e(o.setHandle,!1);if(o&&void 0!==o.setDragging)return new e(n.activeHandle,o.setDragging);if(n.activeHandle>-1&&t.docChanged){let o=t.mapping.map(n.activeHandle,-1);return zd(t.doc.resolve(o))||(o=-1),new e(o,n.dragging)}return n}};function Nu(e,t,n,o){const r="right"==n?-o:o,i=e.posAtCoords({left:t.clientX+r,top:t.clientY});if(!i)return-1;const{pos:s}=i,l=Hd(e.state.doc.resolve(s));if(!l)return-1;if("right"==n)return l.pos;const a=Id.get(l.node(-1)),c=l.start(-1),d=a.map.indexOf(l.pos-c);return d%a.width==0?-1:c+a.map[d-1]}function Au(e,t,n){const o=t.clientX-e.startX;return Math.max(n,e.startWidth+o)}function Ou(e,t){e.dispatch(e.state.tr.setMeta(Ru,{setHandle:t}))}function _u(e,t,n,o){const r=e.state.doc.resolve(t),i=r.node(-1),s=r.start(-1),l=Id.get(i).colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;let a=e.domAtPos(r.start(-1)).node;for(;a&&"TABLE"!=a.nodeName;)a=a.parentNode;a&&Mu(i,a.firstChild,a,o,l,n)}function Pu(e){return Array(e).fill(0)}function Iu({allowTableNodeSelection:e=!1}={}){return new Wr({key:Bd,state:{init:()=>null,apply(e,t){const n=e.getMeta(Bd);if(null!=n)return-1==n?null:n;if(null==t||!e.docChanged)return t;const{deleted:o,pos:r}=e.mapping.mapResult(t);return o?null:r}},props:{decorations:Zd,handleDOMEvents:{mousedown:wu},createSelectionBetween:e=>null!=Bd.getState(e.state)?e.state.selection:null,handleTripleClick:vu,handleKeyDown:mu,handlePaste:xu},appendTransaction:(t,n,o)=>function(e,t,n){const o=(t||e).selection,r=(t||e).doc;let i,s;if(o instanceof Or&&(s=o.node.type.spec.tableRole)){if("cell"==s||"header_cell"==s)i=Gd.create(r,o.from);else if("row"==s){const e=r.resolve(o.from+1);i=Gd.rowSelection(e,e)}else if(!n){const e=Id.get(o.node),t=o.from+1,n=t+e.map[e.width*e.height-1];i=Gd.create(r,t+1,n)}}else o instanceof Nr&&function({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,o=t.pos,r=e.depth;for(;r>=0&&!(e.after(r+1)<e.end(r));r--,n++);for(let i=t.depth;i>=0&&!(t.before(i+1)>t.start(i));i--,o--);return n==o&&/row|table/.test(e.node(r).type.spec.tableRole)}(o)?i=Nr.create(r,o.from):o instanceof Nr&&function({$from:e,$to:t}){let n,o;for(let r=e.depth;r>0;r--){const t=e.node(r);if("cell"===t.type.spec.tableRole||"header_cell"===t.type.spec.tableRole){n=t;break}}for(let r=t.depth;r>0;r--){const e=t.node(r);if("cell"===e.type.spec.tableRole||"header_cell"===e.type.spec.tableRole){o=e;break}}return n!==o&&0===t.parentOffset}(o)&&(i=Nr.create(r,o.$from.start(),o.$from.end()));return i&&(t||(t=e.tr)).setSelection(i),t}(o,Yd(o,n),e)})}var Lu=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var o,r,i;if(Array.isArray(t)){if((o=t.length)!=n.length)return!1;for(r=o;0!==r--;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((o=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(r=o;0!==r--;)if(!Object.prototype.hasOwnProperty.call(n,i[r]))return!1;for(r=o;0!==r--;){var s=i[r];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n};const Du=o.getDefaultExportFromCjs(Lu);var Bu=class e{constructor(e){this.cache=new Map(e)}get(e){return this.cache.get(e)}set(e,t,n){e<0||this.cache.set(e,[t,n])}replace(e,t,n,o){this.remove(e),this.set(t,n,o)}remove(e){this.cache.delete(e)}invalidate(t){const n=new e(this.cache),o=t.mapping;return this.cache.forEach(([e,r],i)=>{if(i<0)return;const s=o.mapResult(i),l=t.doc.nodeAt(s.pos);if(s.deleted||!(null==l?void 0:l.eq(e)))n.remove(i);else if(i!==s.pos){const e=r.map(e=>e.map(o,0,0)).filter(e=>null!=e);n.replace(i,s.pos,l,e)}}),n}};function Hu({parser:e,nodeTypes:t=["code_block","codeBlock"],languageExtractor:n=e=>e.attrs.language}){const o=new Kr("prosemirror-highlight");return new Wr({key:o,state:{init(o,r){const i=new Bu,[s,l]=Vu(r.doc,e,t,n,i);return{cache:i,decorations:s,promises:l}},apply:(o,r)=>{const i=r.cache.invalidate(o),s=!!o.getMeta("prosemirror-highlight-refresh");if(!o.docChanged&&!s){return{cache:i,decorations:r.decorations.map(o.mapping,o.doc),promises:r.promises}}const[l,a]=Vu(o.doc,e,t,n,i);return{cache:i,decorations:l,promises:a}}},view:e=>{const t=new Set,n=()=>{if(t.size>0)return;const n=e.state.tr.setMeta("prosemirror-highlight-refresh",!0);e.dispatch(n)},r=()=>{var r;const i=o.getState(e.state);for(const e of null!=(r=null==i?void 0:i.promises)?r:[])t.add(e),e.then(()=>{t.delete(e),n()}).catch(()=>{t.delete(e)})};return r(),{update:()=>{r()}}},props:{decorations(e){var t;return null==(t=this.getState(e))?void 0:t.decorations}}})}function Vu(e,t,n,o,r){const i=[],s=[];return e.descendants((e,l)=>{if(!e.type.isTextblock)return!0;if(n.includes(e.type.name)){const n=o(e),a=r.get(l);if(a){const[e,t]=a;i.push(...t)}else{const o=t({content:e.textContent,language:n||void 0,pos:l,size:e.nodeSize});o&&Array.isArray(o)?(r.set(l,e,o),i.push(...o)):o instanceof Promise&&(r.remove(l),s.push(o))}}return!1}),[Il.create(e,i),s]}function $u(e){return"string"==typeof e?e:Object.entries(e).map(([e,t])=>`${e}:${t}`).join(";")}const zu=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,Fu=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,Uu=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,Wu=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,qu=gc.create({name:"bold",addOptions:()=>({HTMLAttributes:{}}),parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:e=>"normal"!==e.style.fontWeight&&null},{style:"font-weight=400",clearMark:e=>e.type.name===this.name},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return["strong",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[wd({find:zu,type:this.type}),wd({find:Uu,type:this.type})]},addPasteRules(){return[Ed({find:Fu,type:this.type}),Ed({find:Wu,type:this.type})]}}),Gu=/(^|[^`])`([^`]+)`(?!`)/,Ku=/(^|[^`])`([^`]+)`(?!`)/g,Zu=gc.create({name:"code",addOptions:()=>({HTMLAttributes:{}}),excludes:"_",code:!0,exitable:!0,parseHTML:()=>[{tag:"code"}],renderHTML({HTMLAttributes:e}){return["code",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[wd({find:Gu,type:this.type})]},addPasteRules(){return[Ed({find:Ku,type:this.type})]}}),Ju=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Xu=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,Yu=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Qu=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,eh=gc.create({name:"italic",addOptions:()=>({HTMLAttributes:{}}),parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:e=>"normal"!==e.style.fontStyle&&null},{style:"font-style=normal",clearMark:e=>e.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:e}){return["em",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[wd({find:Ju,type:this.type}),wd({find:Yu,type:this.type})]},addPasteRules(){return[Ed({find:Xu,type:this.type}),Ed({find:Qu,type:this.type})]}}),th=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,nh=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,oh=gc.create({name:"strike",addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:e=>!!e.includes("line-through")&&{}}],renderHTML({HTMLAttributes:e}){return["s",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[wd({find:th,type:this.type})]},addPasteRules(){return[Ed({find:nh,type:this.type})]}}),rh=gc.create({name:"underline",addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:e=>!!e.includes("underline")&&{}}],renderHTML({HTMLAttributes:e}){return["u",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),ih=kd.create({name:"tableCell",addOptions:()=>({HTMLAttributes:{}}),content:"block+",addAttributes:()=>({colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(e=>parseInt(e,10)):null}}}),tableRole:"cell",isolating:!0,parseHTML:()=>[{tag:"td"}],renderHTML({HTMLAttributes:e}){return["td",ec(this.options.HTMLAttributes,e),0]}}),sh=kd.create({name:"tableHeader",addOptions:()=>({HTMLAttributes:{}}),content:"block+",addAttributes:()=>({colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(e=>parseInt(e,10)):null}}}),tableRole:"header_cell",isolating:!0,parseHTML:()=>[{tag:"th"}],renderHTML({HTMLAttributes:e}){return["th",ec(this.options.HTMLAttributes,e),0]}});class lh extends Mr{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return lh.valid(n)?new lh(n):Mr.near(n)}content(){return _n.empty}eq(e){return e instanceof lh&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for GapCursor.fromJSON");return new lh(e.resolve(t.pos))}getBookmark(){return new ah(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!function(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),o=e.node(t);if(0!=n)for(let e=o.child(n-1);;e=e.lastChild){if(0==e.childCount&&!e.inlineContent||ch(e.type))return!0;if(e.inlineContent)return!1}else if(o.type.spec.isolating)return!0}return!0}(e)||!function(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),o=e.node(t);if(n!=o.childCount)for(let e=o.child(n);;e=e.firstChild){if(0==e.childCount&&!e.inlineContent||ch(e.type))return!0;if(e.inlineContent)return!1}else if(o.type.spec.isolating)return!0}return!0}(e))return!1;let n=t.type.spec.allowGapCursor;if(null!=n)return n;let o=t.contentMatchAt(e.index()).defaultType;return o&&o.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&lh.valid(e))return e;let o=e.pos,r=null;for(let n=e.depth;;n--){let i=e.node(n);if(t>0?e.indexAfter(n)<i.childCount:e.index(n)>0){r=i.child(t>0?e.indexAfter(n):e.index(n)-1);break}if(0==n)return null;o+=t;let s=e.doc.resolve(o);if(lh.valid(s))return s}for(;;){let i=t>0?r.firstChild:r.lastChild;if(!i){if(r.isAtom&&!r.isText&&!Or.isSelectable(r)){e=e.doc.resolve(o+r.nodeSize*t),n=!1;continue e}break}r=i,o+=t;let s=e.doc.resolve(o);if(lh.valid(s))return s}return null}}}lh.prototype.visible=!1,lh.findFrom=lh.findGapCursorFrom,Mr.jsonID("gapcursor",lh);class ah{constructor(e){this.pos=e}map(e){return new ah(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return lh.valid(t)?new lh(t):Mr.near(t)}}function ch(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}const dh=ka({ArrowLeft:uh("horiz",-1),ArrowRight:uh("horiz",1),ArrowUp:uh("vert",-1),ArrowDown:uh("vert",1)});function uh(e,t){const n="vert"==e?t>0?"down":"up":t>0?"right":"left";return function(e,o,r){let i=e.selection,s=t>0?i.$to:i.$from,l=i.empty;if(i instanceof Nr){if(!r.endOfTextblock(n)||0==s.depth)return!1;l=!1,s=e.doc.resolve(t>0?s.after():s.before())}let a=lh.findGapCursorFrom(s,t,l);return!!a&&(o&&o(e.tr.setSelection(new lh(a))),!0)}}function hh(e,t,n){if(!e||!e.editable)return!1;let o=e.state.doc.resolve(t);if(!lh.valid(o))return!1;let r=e.posAtCoords({left:n.clientX,top:n.clientY});return!(r&&r.inside>-1&&Or.isSelectable(e.state.doc.nodeAt(r.inside)))&&(e.dispatch(e.state.tr.setSelection(new lh(o))),!0)}function ph(e,t){if("insertCompositionText"!=t.inputType||!(e.state.selection instanceof lh))return!1;let{$from:n}=e.state.selection,o=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!o)return!1;let r=Rn.empty;for(let s=o.length-1;s>=0;s--)r=Rn.from(o[s].createAndFill(null,r));let i=e.state.tr.replace(n.pos,n.pos,new _n(r,0,0));return i.setSelection(Nr.near(i.doc.resolve(n.pos+1))),e.dispatch(i),!1}function fh(e){if(!(e.selection instanceof lh))return null;let t=document.createElement("div");return t.className="ProseMirror-gapcursor",Il.create(e.doc,[Ol.widget(e.selection.head,t,{key:"gapcursor"})])}const mh=kc.create({name:"gapCursor",addProseMirrorPlugins:()=>[new Wr({props:{decorations:fh,createSelectionBetween:(e,t,n)=>t.pos==n.pos&&lh.valid(n)?new lh(n):null,handleClick:hh,handleKeyDown:dh,handleDOMEvents:{beforeinput:ph}}})],extendNodeSchema(e){var t;return{allowGapCursor:null!==(t=oc(Ja(e,"allowGapCursor",{name:e.name,options:e.options,storage:e.storage})))&&void 0!==t?t:null}}});var gh=200,yh=function(){};yh.prototype.append=function(e){return e.length?(e=yh.from(e),!this.length&&e||e.length<gh&&this.leafAppend(e)||this.length<gh&&e.leafPrepend(this)||this.appendInner(e)):this},yh.prototype.prepend=function(e){return e.length?yh.from(e).append(this):this},yh.prototype.appendInner=function(e){return new vh(this,e)},yh.prototype.slice=function(e,t){return void 0===e&&(e=0),void 0===t&&(t=this.length),e>=t?yh.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},yh.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},yh.prototype.forEach=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},yh.prototype.map=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length);var o=[];return this.forEach(function(t,n){return o.push(e(t,n))},t,n),o},yh.from=function(e){return e instanceof yh?e:e&&e.length?new bh(e):yh.empty};var bh=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 0==e&&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,o){for(var r=t;r<n;r++)if(!1===e(this.values[r],o+r))return!1},t.prototype.forEachInvertedInner=function(e,t,n,o){for(var r=t-1;r>=n;r--)if(!1===e(this.values[r],o+r))return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=gh)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=gh)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}(yh);yh.empty=new bh([]);var vh=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,o){var r=this.left.length;return!(t<r&&!1===this.left.forEachInner(e,t,Math.min(n,r),o))&&(!(n>r&&!1===this.right.forEachInner(e,Math.max(t-r,0),Math.min(this.length,n)-r,o+r))&&void 0)},t.prototype.forEachInvertedInner=function(e,t,n,o){var r=this.left.length;return!(t>r&&!1===this.right.forEachInvertedInner(e,t-r,Math.max(n,r)-r,o+r))&&(!(n<r&&!1===this.left.forEachInvertedInner(e,Math.min(t,r),n,o))&&void 0)},t.prototype.sliceInner=function(e,t){if(0==e&&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}(yh);class xh{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(0==this.eventCount)return null;let n,o,r=this.items.length;for(;;r--){if(this.items.get(r-1).selection){--r;break}}t&&(n=this.remapping(r,this.items.length),o=n.maps.length);let i,s,l=e.tr,a=[],c=[];return this.items.forEach((e,t)=>{if(!e.step)return n||(n=this.remapping(r,t+1),o=n.maps.length),o--,void c.push(e);if(n){c.push(new wh(e.map));let t,r=e.step.map(n.slice(o));r&&l.maybeStep(r).doc&&(t=l.mapping.maps[l.mapping.maps.length-1],a.push(new wh(t,void 0,void 0,a.length+c.length))),o--,t&&n.appendMap(t,o)}else l.maybeStep(e.step);return e.selection?(i=n?e.selection.map(n.slice(o)):e.selection,s=new xh(this.items.slice(0,r).append(c.reverse().concat(a)),this.eventCount-1),!1):void 0},this.items.length,0),{remaining:s,transform:l,selection:i}}addTransform(e,t,n,o){let r=[],i=this.eventCount,s=this.items,l=!o&&s.length?s.get(s.length-1):null;for(let c=0;c<e.steps.length;c++){let n,a=e.steps[c].invert(e.docs[c]),d=new wh(e.mapping.maps[c],a,t);(n=l&&l.merge(d))&&(d=n,c?r.pop():s=s.slice(0,s.length-1)),r.push(d),t&&(i++,t=void 0),o||(l=d)}let a=i-n.depth;return a>Ch&&(s=function(e,t){let n;return e.forEach((e,o)=>{if(e.selection&&0==t--)return n=o,!1}),e.slice(n)}(s,a),i-=a),new xh(s.append(r),i)}remapping(e,t){let n=new Vo;return this.items.forEach((t,o)=>{let r=null!=t.mirrorOffset&&o-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,r)},e,t),n}addMaps(e){return 0==this.eventCount?this:new xh(this.items.append(e.map(e=>new wh(e))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],o=Math.max(0,this.items.length-t),r=e.mapping,i=e.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},o);let l=t;this.items.forEach(t=>{let o=r.getMirror(--l);if(null==o)return;i=Math.min(i,o);let a=r.maps[o];if(t.step){let i=e.steps[o].invert(e.docs[o]),c=t.selection&&t.selection.map(r.slice(l+1,o));c&&s++,n.push(new wh(a,i,c))}else n.push(new wh(a))},o);let a=[];for(let u=t;u<i;u++)a.push(new wh(r.maps[u]));let c=this.items.slice(0,o).append(a).append(n),d=new xh(c,s);return d.emptyItemCount()>500&&(d=d.compress(this.items.length-n.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,o=[],r=0;return this.items.forEach((i,s)=>{if(s>=e)o.push(i),i.selection&&r++;else if(i.step){let e=i.step.map(t.slice(n)),s=e&&e.getMap();if(n--,s&&t.appendMap(s,n),e){let l=i.selection&&i.selection.map(t.slice(n));l&&r++;let a,c=new wh(s.invert(),e,l),d=o.length-1;(a=o.length&&o[d].merge(c))?o[d]=a:o.push(c)}}else i.map&&n--},this.items.length,0),new xh(yh.from(o.reverse()),r)}}xh.empty=new xh(yh.empty,0);let wh=class e{constructor(e,t,n,o){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=o}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)}}};class kh{constructor(e,t,n,o,r){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=o,this.prevComposition=r}}const Ch=20;function Eh(e){let t=[];for(let n=e.length-1;n>=0&&0==t.length;n--)e[n].forEach((e,n,o,r)=>t.push(o,r));return t}function Sh(e,t){if(!e)return null;let n=[];for(let o=0;o<e.length;o+=2){let r=t.map(e[o],1),i=t.map(e[o+1],-1);r<=i&&n.push(r,i)}return n}let Mh=!1,Rh=null;function Th(e){let t=e.plugins;if(Rh!=t){Mh=!1,Rh=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){Mh=!0;break}}return Mh}const jh=new Kr("history"),Nh=new Kr("closeHistory");function Ah(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Wr({key:jh,state:{init:()=>new kh(xh.empty,xh.empty,null,0,-1),apply:(t,n,o)=>function(e,t,n,o){let r,i=n.getMeta(jh);if(i)return i.historyState;n.getMeta(Nh)&&(e=new kh(e.done,e.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(0==n.steps.length)return e;if(s&&s.getMeta(jh))return s.getMeta(jh).redo?new kh(e.done.addTransform(n,void 0,o,Th(t)),e.undone,Eh(n.mapping.maps),e.prevTime,e.prevComposition):new kh(e.done,e.undone.addTransform(n,void 0,o,Th(t)),null,e.prevTime,e.prevComposition);if(!1===n.getMeta("addToHistory")||s&&!1===s.getMeta("addToHistory"))return(r=n.getMeta("rebased"))?new kh(e.done.rebased(n,r),e.undone.rebased(n,r),Sh(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new kh(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Sh(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);{let r=n.getMeta("composition"),i=0==e.prevTime||!s&&e.prevComposition!=r&&(e.prevTime<(n.time||0)-o.newGroupDelay||!function(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,o)=>{for(let r=0;r<t.length;r+=2)e<=t[r+1]&&o>=t[r]&&(n=!0)}),n}(n,e.prevRanges)),l=s?Sh(e.prevRanges,n.mapping):Eh(n.mapping.maps);return new kh(e.done.addTransform(n,i?t.selection.getBookmark():void 0,o,Th(t)),xh.empty,l,n.time,null==r?e.prevComposition:r)}}(n,o,t,e)},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,o="historyUndo"==n?_h:"historyRedo"==n?Ph:null;return!!o&&(t.preventDefault(),o(e.state,e.dispatch))}}}})}function Oh(e,t){return(n,o)=>{let r=jh.getState(n);if(!r||0==(e?r.undone:r.done).eventCount)return!1;if(o){let i=function(e,t,n){let o=Th(t),r=jh.get(t).spec.config,i=(n?e.undone:e.done).popEvent(t,o);if(!i)return null;let s=i.selection.resolve(i.transform.doc),l=(n?e.done:e.undone).addTransform(i.transform,t.selection.getBookmark(),r,o),a=new kh(n?l:i.remaining,n?i.remaining:l,null,0,-1);return i.transform.setSelection(s).setMeta(jh,{redo:n,historyState:a})}(r,n,e);i&&o(t?i.scrollIntoView():i)}return!0}}const _h=Oh(!1,!0),Ph=Oh(!0,!0),Ih=kc.create({name:"history",addOptions:()=>({depth:100,newGroupDelay:500}),addCommands:()=>({undo:()=>({state:e,dispatch:t})=>_h(e,t),redo:()=>({state:e,dispatch:t})=>Ph(e,t)}),addProseMirrorPlugins(){return[Ah(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Lh="numeric",Dh="ascii",Bh="alpha",Hh="asciinumeric",Vh="alphanumeric",$h="domain",zh="emoji",Fh="scheme",Uh="slashscheme",Wh="whitespace";function qh(e,t){return e in t||(t[e]=[]),t[e]}function Gh(e,t,n){t[Lh]&&(t[Hh]=!0,t[Vh]=!0),t[Dh]&&(t[Hh]=!0,t[Bh]=!0),t[Hh]&&(t[Vh]=!0),t[Bh]&&(t[Vh]=!0),t[Vh]&&(t[$h]=!0),t[zh]&&(t[$h]=!0);for(const o in t){const t=qh(o,n);t.indexOf(e)<0&&t.push(e)}}function Kh(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}Kh.groups={},Kh.prototype={accepts(){return!!this.t},go(e){const t=this,n=t.j[e];if(n)return n;for(let o=0;o<t.jr.length;o++){const n=t.jr[o][0],r=t.jr[o][1];if(r&&n.test(e))return r}return t.jd},has(e,t=!1){return t?e in this.j:!!this.go(e)},ta(e,t,n,o){for(let r=0;r<e.length;r++)this.tt(e[r],t,n,o)},tr(e,t,n,o){let r;return o=o||Kh.groups,t&&t.j?r=t:(r=new Kh(t),n&&o&&Gh(t,n,o)),this.jr.push([e,r]),r},ts(e,t,n,o){let r=this;const i=e.length;if(!i)return r;for(let s=0;s<i-1;s++)r=r.tt(e[s]);return r.tt(e[i-1],t,n,o)},tt(e,t,n,o){o=o||Kh.groups;const r=this;if(t&&t.j)return r.j[e]=t,t;const i=t;let s,l=r.go(e);if(l?(s=new Kh,Object.assign(s.j,l.j),s.jr.push.apply(s.jr,l.jr),s.jd=l.jd,s.t=l.t):s=new Kh,i){if(o)if(s.t&&"string"==typeof s.t){const e=Object.assign(function(e,t){const n={};for(const o in t)t[o].indexOf(e)>=0&&(n[o]=!0);return n}(s.t,o),n);Gh(i,e,o)}else n&&Gh(i,n,o);s.t=i}return r.j[e]=s,s}};const Zh=(e,t,n,o,r)=>e.ta(t,n,o,r),Jh=(e,t,n,o,r)=>e.tr(t,n,o,r),Xh=(e,t,n,o,r)=>e.ts(t,n,o,r),Yh=(e,t,n,o,r)=>e.tt(t,n,o,r),Qh="WORD",ep="UWORD",tp="ASCIINUMERICAL",np="ALPHANUMERICAL",op="LOCALHOST",rp="TLD",ip="UTLD",sp="SCHEME",lp="SLASH_SCHEME",ap="NUM",cp="WS",dp="NL",up="OPENBRACE",hp="CLOSEBRACE",pp="OPENBRACKET",fp="CLOSEBRACKET",mp="OPENPAREN",gp="CLOSEPAREN",yp="OPENANGLEBRACKET",bp="CLOSEANGLEBRACKET",vp="FULLWIDTHLEFTPAREN",xp="FULLWIDTHRIGHTPAREN",wp="LEFTCORNERBRACKET",kp="RIGHTCORNERBRACKET",Cp="LEFTWHITECORNERBRACKET",Ep="RIGHTWHITECORNERBRACKET",Sp="FULLWIDTHLESSTHAN",Mp="FULLWIDTHGREATERTHAN",Rp="AMPERSAND",Tp="APOSTROPHE",jp="ASTERISK",Np="AT",Ap="BACKSLASH",Op="BACKTICK",_p="CARET",Pp="COLON",Ip="COMMA",Lp="DOLLAR",Dp="DOT",Bp="EQUALS",Hp="EXCLAMATION",Vp="HYPHEN",$p="PERCENT",zp="PIPE",Fp="PLUS",Up="POUND",Wp="QUERY",qp="QUOTE",Gp="FULLWIDTHMIDDLEDOT",Kp="SEMI",Zp="SLASH",Jp="TILDE",Xp="UNDERSCORE",Yp="EMOJI",Qp="SYM";var ef=Object.freeze({__proto__:null,ALPHANUMERICAL:np,AMPERSAND:Rp,APOSTROPHE:Tp,ASCIINUMERICAL:tp,ASTERISK:jp,AT:Np,BACKSLASH:Ap,BACKTICK:Op,CARET:_p,CLOSEANGLEBRACKET:bp,CLOSEBRACE:hp,CLOSEBRACKET:fp,CLOSEPAREN:gp,COLON:Pp,COMMA:Ip,DOLLAR:Lp,DOT:Dp,EMOJI:Yp,EQUALS:Bp,EXCLAMATION:Hp,FULLWIDTHGREATERTHAN:Mp,FULLWIDTHLEFTPAREN:vp,FULLWIDTHLESSTHAN:Sp,FULLWIDTHMIDDLEDOT:Gp,FULLWIDTHRIGHTPAREN:xp,HYPHEN:Vp,LEFTCORNERBRACKET:wp,LEFTWHITECORNERBRACKET:Cp,LOCALHOST:op,NL:dp,NUM:ap,OPENANGLEBRACKET:yp,OPENBRACE:up,OPENBRACKET:pp,OPENPAREN:mp,PERCENT:$p,PIPE:zp,PLUS:Fp,POUND:Up,QUERY:Wp,QUOTE:qp,RIGHTCORNERBRACKET:kp,RIGHTWHITECORNERBRACKET:Ep,SCHEME:sp,SEMI:Kp,SLASH:Zp,SLASH_SCHEME:lp,SYM:Qp,TILDE:Jp,TLD:rp,UNDERSCORE:Xp,UTLD:ip,UWORD:ep,WORD:Qh,WS:cp});const tf=/[a-z]/,nf=new RegExp("\\p{L}","u"),of=new RegExp("\\p{Emoji}","u"),rf=/\d/,sf=/\s/;let lf=null,af=null;function cf(e,t){const n=function(e){const t=[],n=e.length;let o=0;for(;o<n;){let r,i=e.charCodeAt(o),s=i<55296||i>56319||o+1===n||(r=e.charCodeAt(o+1))<56320||r>57343?e[o]:e.slice(o,o+2);t.push(s),o+=s.length}return t}(t.replace(/[A-Z]/g,e=>e.toLowerCase())),o=n.length,r=[];let i=0,s=0;for(;s<o;){let l=e,a=null,c=0,d=null,u=-1,h=-1;for(;s<o&&(a=l.go(n[s]));)l=a,l.accepts()?(u=0,h=0,d=l):u>=0&&(u+=n[s].length,h++),c+=n[s].length,i+=n[s].length,s++;i-=u,s-=h,c-=u,r.push({t:d.t,v:t.slice(i-c,i),s:i-c,e:i})}return r}function df(e,t,n,o,r){let i;const s=t.length;for(let l=0;l<s-1;l++){const n=t[l];e.j[n]?i=e.j[n]:(i=new Kh(o),i.jr=r.slice(),e.j[n]=i),e=i}return i=new Kh(n),i.jr=r.slice(),e.j[t[s-1]]=i,i}function uf(e){const t=[],n=[];let o=0;for(;o<e.length;){let r=0;for(;"0123456789".indexOf(e[o+r])>=0;)r++;if(r>0){t.push(n.join(""));for(let t=parseInt(e.substring(o,o+r),10);t>0;t--)n.pop();o+=r}else n.push(e[o]),o++}return t}const hf={defaultProtocol:"http",events:null,format:ff,formatHref:ff,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function pf(e,t=null){let n=Object.assign({},hf);e&&(n=Object.assign(n,e instanceof pf?e.o:e));const o=n.ignoreTags,r=[];for(let i=0;i<o.length;i++)r.push(o[i].toUpperCase());this.o=n,t&&(this.defaultRender=t),this.ignoreTags=r}function ff(e){return e}function mf(e,t){this.t="token",this.v=e,this.tk=t}function gf(e,t){class n extends mf{constructor(t,n){super(t,n),this.t=e}}for(const o in t)n.prototype[o]=t[o];return n.t=e,n}pf.prototype={o:hf,ignoreTags:[],defaultRender:e=>e,check(e){return this.get("validate",e.toString(),e)},get(e,t,n){const o=null!=t;let r=this.o[e];return r?("object"==typeof r?(r=n.t in r?r[n.t]:hf[e],"function"==typeof r&&o&&(r=r(t,n))):"function"==typeof r&&o&&(r=r(t,n.t,n)),r):r},getObj(e,t,n){let o=this.o[e];return"function"==typeof o&&null!=t&&(o=o(t,n.t,n)),o},render(e){const t=e.render(this);return(this.get("render",null,e)||this.defaultRender)(t,e.t,e)}},mf.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){const t=this.toString(),n=e.get("truncate",t,this),o=e.get("format",t,this);return n&&o.length>n?o.substring(0,n)+"…":o},toFormattedHref(e){return e.get("formatHref",this.toHref(e.get("defaultProtocol")),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=hf.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get("validate",this.toString(),this)},render(e){const t=this,n=this.toHref(e.get("defaultProtocol")),o=e.get("formatHref",n,this),r=e.get("tagName",n,t),i=this.toFormattedString(e),s={},l=e.get("className",n,t),a=e.get("target",n,t),c=e.get("rel",n,t),d=e.getObj("attributes",n,t),u=e.getObj("events",n,t);return s.href=o,l&&(s.class=l),a&&(s.target=a),c&&(s.rel=c),d&&Object.assign(s,d),{tagName:r,attributes:s,content:i,eventListeners:u}}};const yf=gf("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),bf=gf("text"),vf=gf("nl"),xf=gf("url",{isLink:!0,toHref(e=hf.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){const e=this.tk;return e.length>=2&&e[0].t!==op&&e[1].t===Pp}}),wf=e=>new Kh(e);function kf(e,t,n){const o=n[0].s,r=n[n.length-1].e;return new e(t.slice(o,r),n)}const Cf="undefined"!=typeof console&&console&&console.warn||(()=>{}),Ef={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function Sf(e,t=!1){if(Ef.initialized&&Cf(`linkifyjs: already initialized - will not register custom scheme "${e}" until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw new Error('linkifyjs: incorrect scheme format.\n1. Must only contain digits, lowercase ASCII letters or "-"\n2. Cannot start or end with "-"\n3. "-" cannot repeat');Ef.customSchemes.push([e,t])}function Mf(){Ef.scanner=function(e=[]){const t={};Kh.groups=t;const n=new Kh;null==lf&&(lf=uf("aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2")),null==af&&(af=uf("ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2")),Yh(n,"'",Tp),Yh(n,"{",up),Yh(n,"}",hp),Yh(n,"[",pp),Yh(n,"]",fp),Yh(n,"(",mp),Yh(n,")",gp),Yh(n,"<",yp),Yh(n,">",bp),Yh(n,"(",vp),Yh(n,")",xp),Yh(n,"「",wp),Yh(n,"」",kp),Yh(n,"『",Cp),Yh(n,"』",Ep),Yh(n,"<",Sp),Yh(n,">",Mp),Yh(n,"&",Rp),Yh(n,"*",jp),Yh(n,"@",Np),Yh(n,"`",Op),Yh(n,"^",_p),Yh(n,":",Pp),Yh(n,",",Ip),Yh(n,"$",Lp),Yh(n,".",Dp),Yh(n,"=",Bp),Yh(n,"!",Hp),Yh(n,"-",Vp),Yh(n,"%",$p),Yh(n,"|",zp),Yh(n,"+",Fp),Yh(n,"#",Up),Yh(n,"?",Wp),Yh(n,'"',qp),Yh(n,"/",Zp),Yh(n,";",Kp),Yh(n,"~",Jp),Yh(n,"_",Xp),Yh(n,"\\",Ap),Yh(n,"・",Gp);const o=Jh(n,rf,ap,{[Lh]:!0});Jh(o,rf,o);const r=Jh(o,tf,tp,{[Hh]:!0}),i=Jh(o,nf,np,{[Vh]:!0}),s=Jh(n,tf,Qh,{[Dh]:!0});Jh(s,rf,r),Jh(s,tf,s),Jh(r,rf,r),Jh(r,tf,r);const l=Jh(n,nf,ep,{[Bh]:!0});Jh(l,tf),Jh(l,rf,i),Jh(l,nf,l),Jh(i,rf,i),Jh(i,tf),Jh(i,nf,i);const a=Yh(n,"\n",dp,{[Wh]:!0}),c=Yh(n,"\r",cp,{[Wh]:!0}),d=Jh(n,sf,cp,{[Wh]:!0});Yh(n,"",d),Yh(c,"\n",a),Yh(c,"",d),Jh(c,sf,d),Yh(d,"\r"),Yh(d,"\n"),Jh(d,sf,d),Yh(d,"",d);const u=Jh(n,of,Yp,{[zh]:!0});Yh(u,"#"),Jh(u,of,u),Yh(u,"️",u);const h=Yh(u,"‍");Yh(h,"#"),Jh(h,of,u);const p=[[tf,s],[rf,r]],f=[[tf,null],[nf,l],[rf,i]];for(let m=0;m<lf.length;m++)df(n,lf[m],rp,Qh,p);for(let m=0;m<af.length;m++)df(n,af[m],ip,ep,f);Gh(rp,{tld:!0,ascii:!0},t),Gh(ip,{utld:!0,alpha:!0},t),df(n,"file",sp,Qh,p),df(n,"mailto",sp,Qh,p),df(n,"http",lp,Qh,p),df(n,"https",lp,Qh,p),df(n,"ftp",lp,Qh,p),df(n,"ftps",lp,Qh,p),Gh(sp,{scheme:!0,ascii:!0},t),Gh(lp,{slashscheme:!0,ascii:!0},t),e=e.sort((e,t)=>e[0]>t[0]?1:-1);for(let m=0;m<e.length;m++){const t=e[m][0],o=e[m][1]?{[Fh]:!0}:{[Uh]:!0};t.indexOf("-")>=0?o[$h]=!0:tf.test(t)?rf.test(t)?o[Hh]=!0:o[Dh]=!0:o[Lh]=!0,Xh(n,t,t,o)}return Xh(n,"localhost",op,{ascii:!0}),n.jd=new Kh(Qp),{start:n,tokens:Object.assign({groups:t},ef)}}(Ef.customSchemes);for(let e=0;e<Ef.tokenQueue.length;e++)Ef.tokenQueue[e][1]({scanner:Ef.scanner});Ef.parser=function({groups:e}){const t=e.domain.concat([Rp,jp,Np,Ap,Op,_p,Lp,Bp,Vp,ap,$p,zp,Fp,Up,Zp,Qp,Jp,Xp]),n=[Tp,Pp,Ip,Dp,Hp,$p,Wp,qp,Kp,yp,bp,up,hp,fp,pp,mp,gp,vp,xp,wp,kp,Cp,Ep,Sp,Mp],o=[Rp,Tp,jp,Ap,Op,_p,Lp,Bp,Vp,up,hp,$p,zp,Fp,Up,Wp,Zp,Qp,Jp,Xp],r=wf(),i=Yh(r,Jp);Zh(i,o,i),Zh(i,e.domain,i);const s=wf(),l=wf(),a=wf();Zh(r,e.domain,s),Zh(r,e.scheme,l),Zh(r,e.slashscheme,a),Zh(s,o,i),Zh(s,e.domain,s);const c=Yh(s,Np);Yh(i,Np,c),Yh(l,Np,c),Yh(a,Np,c);const d=Yh(i,Dp);Zh(d,o,i),Zh(d,e.domain,i);const u=wf();Zh(c,e.domain,u),Zh(u,e.domain,u);const h=Yh(u,Dp);Zh(h,e.domain,u);const p=wf(yf);Zh(h,e.tld,p),Zh(h,e.utld,p),Yh(c,op,p);const f=Yh(u,Vp);Yh(f,Vp,f),Zh(f,e.domain,u),Zh(p,e.domain,u),Yh(p,Dp,h),Yh(p,Vp,f);const m=Yh(p,Pp);Zh(m,e.numeric,yf);const g=Yh(s,Vp),y=Yh(s,Dp);Yh(g,Vp,g),Zh(g,e.domain,s),Zh(y,o,i),Zh(y,e.domain,s);const b=wf(xf);Zh(y,e.tld,b),Zh(y,e.utld,b),Zh(b,e.domain,s),Zh(b,o,i),Yh(b,Dp,y),Yh(b,Vp,g),Yh(b,Np,c);const v=Yh(b,Pp),x=wf(xf);Zh(v,e.numeric,x);const w=wf(xf),k=wf();Zh(w,t,w),Zh(w,n,k),Zh(k,t,w),Zh(k,n,k),Yh(b,Zp,w),Yh(x,Zp,w);const C=Yh(l,Pp),E=Yh(a,Pp),S=Yh(E,Zp),M=Yh(S,Zp);Zh(l,e.domain,s),Yh(l,Dp,y),Yh(l,Vp,g),Zh(a,e.domain,s),Yh(a,Dp,y),Yh(a,Vp,g),Zh(C,e.domain,w),Yh(C,Zp,w),Yh(C,Wp,w),Zh(M,e.domain,w),Zh(M,t,w),Yh(M,Zp,w);const R=[[up,hp],[pp,fp],[mp,gp],[yp,bp],[vp,xp],[wp,kp],[Cp,Ep],[Sp,Mp]];for(let T=0;T<R.length;T++){const[e,o]=R[T],r=Yh(w,e);Yh(k,e,r),Yh(r,o,w);const i=wf(xf);Zh(r,t,i);const s=wf();Zh(r,n),Zh(i,t,i),Zh(i,n,s),Zh(s,t,i),Zh(s,n,s),Yh(i,o,w),Yh(s,o,w)}return Yh(r,op,b),Yh(r,dp,vf),{start:r,tokens:ef}}(Ef.scanner.tokens);for(let e=0;e<Ef.pluginQueue.length;e++)Ef.pluginQueue[e][1]({scanner:Ef.scanner,parser:Ef.parser});return Ef.initialized=!0,Ef}function Rf(e){return Ef.initialized||Mf(),function(e,t,n){let o=n.length,r=0,i=[],s=[];for(;r<o;){let l=e,a=null,c=null,d=0,u=null,h=-1;for(;r<o&&!(a=l.go(n[r].t));)s.push(n[r++]);for(;r<o&&(c=a||l.go(n[r].t));)a=null,l=c,l.accepts()?(h=0,u=l):h>=0&&h++,r++,d++;if(h<0)r-=d,r<o&&(s.push(n[r]),r++);else{s.length>0&&(i.push(kf(bf,t,s)),s=[]),r-=h,d-=h;const e=u.t,o=n.slice(r-d,r);i.push(kf(e,t,o))}}return s.length>0&&i.push(kf(bf,t,s)),i}(Ef.parser.start,e,cf(Ef.scanner.start,e))}function Tf(e,t=null,n=null){if(t&&"object"==typeof t){if(n)throw Error(`linkifyjs: Invalid link type ${t}; must be a string`);n=t,t=null}const o=new pf(n),r=Rf(e),i=[];for(let s=0;s<r.length;s++){const e=r[s];!e.isLink||t&&e.t!==t||!o.check(e)||i.push(e.toFormattedObject(o))}return i}Rf.scan=cf;const jf="[\0-   ᠎ -\u2029  ]",Nf=new RegExp(jf),Af=new RegExp(`${jf}$`),Of=new RegExp(jf,"g");function _f(e,t){const n=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return t&&t.forEach(e=>{const t="string"==typeof e?e:e.scheme;t&&n.push(t)}),!e||e.replace(Of,"").match(new RegExp(`^(?:(?:${n.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}const Pf=gc.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate),this.options.protocols.forEach(e=>{"string"!=typeof e?Sf(e.scheme,e.optionalSlashes):Sf(e)})},onDestroy(){Kh.groups={},Ef.scanner=null,Ef.parser=null,Ef.tokenQueue=[],Ef.pluginQueue=[],Ef.customSchemes=[],Ef.initialized=!1},inclusive(){return this.options.autolink},addOptions:()=>({openOnClick:!0,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(e,t)=>!!_f(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>!!e}),addAttributes(){return{href:{default:null,parseHTML:e=>e.getAttribute("href")},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class}}},parseHTML(){return[{tag:"a[href]",getAttrs:e=>{const t=e.getAttribute("href");return!(!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!_f(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}))&&null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!_f(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",ec(this.options.HTMLAttributes,e),0]:["a",ec(this.options.HTMLAttributes,{...e,href:""}),0]},addCommands(){return{setLink:e=>({chain:t})=>{const{href:n}=e;return!!this.options.isAllowedUri(n,{defaultValidate:e=>!!_f(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})&&t().setMark(this.name,e).setMeta("preventAutolink",!0).run()},toggleLink:e=>({chain:t})=>{const{href:n}=e;return!!this.options.isAllowedUri(n,{defaultValidate:e=>!!_f(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})&&t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[Ed({find:e=>{const t=[];if(e){const{protocols:n,defaultProtocol:o}=this.options,r=Tf(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!_f(e,n),protocols:n,defaultProtocol:o}));r.length&&r.forEach(e=>t.push({text:e.value,data:{href:e.href},index:e.start}))}return t},type:this.type,getAttributes:e=>{var t;return{href:null===(t=e.data)||void 0===t?void 0:t.href}}})]},addProseMirrorPlugins(){const e=[],{protocols:t,defaultProtocol:n}=this.options;var o;return this.options.autolink&&e.push((o={type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!_f(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink},new Wr({key:new Kr("autolink"),appendTransaction:(e,t,n)=>{const r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta("preventAutolink"));if(!r||i)return;const{tr:s}=n;return Yc(qc(t.doc,[...e])).forEach(({newRange:e})=>{const t=Kc(n.doc,e,e=>e.isTextblock);let r,i;if(t.length>1)r=t[0],i=n.doc.textBetween(r.pos,r.pos+r.node.nodeSize,void 0," ");else if(t.length){const o=n.doc.textBetween(e.from,e.to," "," ");if(!Af.test(o))return;r=t[0],i=n.doc.textBetween(r.pos,e.to,void 0," ")}if(r&&i){const e=i.split(Nf).filter(Boolean);if(e.length<=0)return!1;const t=e[e.length-1],a=r.pos+i.lastIndexOf(t);if(!t)return!1;const c=Rf(t).map(e=>e.toObject(o.defaultProtocol));if(!(1===(l=c).length?l[0].isLink:3===l.length&&l[1].isLink&&["()","[]"].includes(l[0].value+l[2].value)))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:a+e.start+1,to:a+e.end+1})).filter(e=>!n.schema.marks.code||!n.doc.rangeHasMark(e.from,e.to,n.schema.marks.code)).filter(e=>o.validate(e.value)).filter(e=>o.shouldAutoLink(e.value)).forEach(e=>{Qc(e.from,e.to,n.doc).some(e=>e.mark.type===o.type)||s.addMark(e.from,e.to,o.type.create({href:e.href}))})}var l}),s.steps.length?s:void 0}}))),!0===this.options.openOnClick&&e.push(function(e){return new Wr({key:new Kr("handleClickLink"),props:{handleClick:(t,n,o)=>{var r,i;if(0!==o.button)return!1;if(!t.editable)return!1;let s=o.target;const l=[];for(;"DIV"!==s.nodeName;)l.push(s),s=s.parentNode;if(!l.find(e=>"A"===e.nodeName))return!1;const a=Jc(t.state,e.type.name),c=o.target,d=null!==(r=null==c?void 0:c.href)&&void 0!==r?r:a.href,u=null!==(i=null==c?void 0:c.target)&&void 0!==i?i:a.target;return!(!c||!d||(window.open(d,u),0))}}})}({type:this.type})),this.options.linkOnPaste&&e.push(function(e){return new Wr({key:new Kr("handlePasteLink"),props:{handlePaste:(t,n,o)=>{const{state:r}=t,{selection:i}=r,{empty:s}=i;if(s)return!1;let l="";o.content.forEach(e=>{l+=e.textContent});const a=Tf(l,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===l);return!(!l||!a)&&e.editor.commands.setMark(e.type,{href:a.href})}}})}({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type})),e}}),If=kd.create({name:"text",group:"inline"}),Lf=()=>new Map,Df=e=>{const t=Lf();return e.forEach((e,n)=>{t.set(n,e)}),t},Bf=(e,t,n)=>{let o=e.get(t);return void 0===o&&e.set(t,o=n()),o},Hf=()=>new Set,Vf=e=>e[e.length-1],$f=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},zf=Array.from,Ff=Array.isArray;class Uf{constructor(){this._observers=Lf()}on(e,t){return Bf(this._observers,e,Hf).add(t),t}once(e,t){const n=(...o)=>{this.off(e,n),t(...o)};this.on(e,n)}off(e,t){const n=this._observers.get(e);void 0!==n&&(n.delete(t),0===n.size&&this._observers.delete(e))}emit(e,t){return zf((this._observers.get(e)||Lf()).values()).forEach(e=>e(...t))}destroy(){this._observers=Lf()}}const Wf=Math.floor,qf=Math.abs,Gf=(e,t)=>e<t?e:t,Kf=(e,t)=>e>t?e:t,Zf=e=>0!==e?e<0:1/e<0,Jf=64,Xf=128,Yf=127,Qf=Number.MAX_SAFE_INTEGER,em=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&Wf(e)===e),tm=String.fromCharCode,nm=/^\s*/g,om=/([A-Z])/g,rm=(e,t)=>(e=>e.replace(nm,""))(e.replace(om,e=>`${t}${(e=>e.toLowerCase())(e)}`)),im="undefined"!=typeof TextEncoder?new TextEncoder:null,sm=im?e=>im.encode(e):e=>{const t=unescape(encodeURIComponent(e)),n=t.length,o=new Uint8Array(n);for(let r=0;r<n;r++)o[r]=t.codePointAt(r);return o};let lm="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});lm&&1===lm.decode(new Uint8Array).length&&(lm=null);class am{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const cm=()=>new am,dm=e=>{const t=new Uint8Array((e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t})(e));let n=0;for(let o=0;o<e.bufs.length;o++){const r=e.bufs[o];t.set(r,n),n+=r.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},um=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*n),e.cpos=0),e.cbuf[e.cpos++]=t},hm=um,pm=(e,t)=>{for(;t>Yf;)um(e,Xf|Yf&t),t=Wf(t/128);um(e,Yf&t)},fm=(e,t)=>{const n=Zf(t);for(n&&(t=-t),um(e,(t>63?Xf:0)|(n?Jf:0)|63&t),t=Wf(t/64);t>0;)um(e,(t>Yf?Xf:0)|Yf&t),t=Wf(t/128)},mm=new Uint8Array(3e4),gm=mm.length/3,ym=im&&im.encodeInto?(e,t)=>{if(t.length<gm){const n=im.encodeInto(t,mm).written||0;pm(e,n);for(let t=0;t<n;t++)um(e,mm[t])}else vm(e,sm(t))}:(e,t)=>{const n=unescape(encodeURIComponent(t)),o=n.length;pm(e,o);for(let r=0;r<o;r++)um(e,n.codePointAt(r))},bm=(e,t)=>{const n=e.cbuf.length,o=e.cpos,r=Gf(n-o,t.length),i=t.length-r;e.cbuf.set(t.subarray(0,r),o),e.cpos+=r,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Kf(2*n,i)),e.cbuf.set(t.subarray(r)),e.cpos=i)},vm=(e,t)=>{pm(e,t.byteLength),bm(e,t)},xm=(e,t)=>{((e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*Kf(n,t)),e.cpos=0)})(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},wm=new DataView(new ArrayBuffer(4)),km=(e,t)=>{switch(typeof t){case"string":um(e,119),ym(e,t);break;case"number":em(t)&&qf(t)<=2147483647?(um(e,125),fm(e,t)):(n=t,wm.setFloat32(0,n),wm.getFloat32(0)===n?(um(e,124),((e,t)=>{xm(e,4).setFloat32(0,t,!1)})(e,t)):(um(e,123),((e,t)=>{xm(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":um(e,122),((e,t)=>{xm(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)um(e,126);else if(Ff(t)){um(e,117),pm(e,t.length);for(let n=0;n<t.length;n++)km(e,t[n])}else if(t instanceof Uint8Array)um(e,116),vm(e,t);else{um(e,118);const n=Object.keys(t);pm(e,n.length);for(let o=0;o<n.length;o++){const r=n[o];ym(e,r),km(e,t[r])}}break;case"boolean":um(e,t?120:121);break;default:um(e,127)}var n};class Cm extends am{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&pm(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const Em=e=>{e.count>0&&(fm(e.encoder,1===e.count?e.s:-e.s),e.count>1&&pm(e.encoder,e.count-2))};class Sm{constructor(){this.encoder=new am,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Em(this),this.count=1,this.s=e)}toUint8Array(){return Em(this),dm(this.encoder)}}const Mm=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);fm(e.encoder,t),e.count>1&&pm(e.encoder,e.count-2)}};class Rm{constructor(){this.encoder=new am,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Mm(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Mm(this),dm(this.encoder)}}class Tm{constructor(){this.sarr=[],this.s="",this.lensE=new Sm}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new am;return this.sarr.push(this.s),this.s="",ym(e,this.sarr.join("")),bm(e,this.lensE.toUint8Array()),dm(e)}}const jm=e=>new Error(e),Nm=()=>{throw jm("Method unimplemented")},Am=()=>{throw jm("Unexpected case")},Om=jm("Unexpected end of array"),_m=jm("Integer out of Range");class Pm{constructor(e){this.arr=e,this.pos=0}}const Im=e=>new Pm(e),Lm=e=>((e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n})(e,Bm(e)),Dm=e=>e.arr[e.pos++],Bm=e=>{let t=0,n=1;const o=e.arr.length;for(;e.pos<o;){const o=e.arr[e.pos++];if(t+=(o&Yf)*n,n*=128,o<Xf)return t;if(t>Qf)throw _m}throw Om},Hm=e=>{let t=e.arr[e.pos++],n=63&t,o=64;const r=(t&Jf)>0?-1:1;if(0===(t&Xf))return r*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n+=(t&Yf)*o,o*=128,t<Xf)return r*n;if(n>Qf)throw _m}throw Om},Vm=lm?e=>lm.decode(Lm(e)):e=>{let t=Bm(e);if(0===t)return"";{let n=String.fromCodePoint(Dm(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Dm(e));else for(;t>0;){const o=t<1e4?t:1e4,r=e.arr.subarray(e.pos,e.pos+o);e.pos+=o,n+=String.fromCodePoint.apply(null,r),t-=o}return decodeURIComponent(escape(n))}},$m=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},zm=[e=>{},e=>null,Hm,e=>$m(e,4).getFloat32(0,!1),e=>$m(e,8).getFloat64(0,!1),e=>$m(e,8).getBigInt64(0,!1),e=>!1,e=>!0,Vm,e=>{const t=Bm(e),n={};for(let o=0;o<t;o++){n[Vm(e)]=Fm(e)}return n},e=>{const t=Bm(e),n=[];for(let o=0;o<t;o++)n.push(Fm(e));return n},Lm],Fm=e=>zm[127-Dm(e)](e);class Um extends Pm{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){var e;return 0===this.count&&(this.s=this.reader(this),(e=this).pos!==e.arr.length?this.count=Bm(this)+1:this.count=-1),this.count--,this.s}}class Wm extends Pm{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=Hm(this);const e=Zf(this.s);this.count=1,e&&(this.s=-this.s,this.count=Bm(this)+2)}return this.count--,this.s}}class qm extends Pm{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=Hm(this),t=1&e;this.diff=Wf(e/2),this.count=1,t&&(this.count=Bm(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Gm{constructor(e){this.decoder=new Wm(e),this.str=Vm(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}const Km=crypto.getRandomValues.bind(crypto),Zm=Math.random,Jm=()=>Km(new Uint32Array(1))[0],Xm="10000000-1000-4000-8000-100000000000",Ym=()=>Xm.replace(/[018]/g,e=>(e^Jm()&15>>e/4).toString(16)),Qm=Date.now,eg=e=>new Promise(e);Promise.all.bind(Promise);const tg=e=>void 0===e?null:e;let ng=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},og=!0;try{"undefined"!=typeof localStorage&&localStorage&&(ng=localStorage,og=!1)}catch(VD){}const rg=ng,ig=Object.assign,sg=Object.keys,lg=e=>sg(e).length,ag=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},cg=(e,t)=>e===t||lg(e)===lg(t)&&ag(e,(e,n)=>(void 0!==e||((e,t)=>Object.prototype.hasOwnProperty.call(e,t))(t,n))&&t[n]===e),dg=Object.freeze,ug=e=>{for(const t in e){const n=e[t];"object"!=typeof n&&"function"!=typeof n||ug(e[t])}return dg(e)},hg=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&hg(e,t,n+1)}},pg=e=>e,fg="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),mg="undefined"!=typeof window&&"undefined"!=typeof document&&!fg;let gg;const yg=e=>(()=>{if(void 0===gg)if(fg){gg=Lf();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const o=e[n];"-"===o[0]?(null!==t&&gg.set(t,""),t=o):null!==t&&(gg.set(t,o),t=null)}null!==t&&gg.set(t,"")}else"object"==typeof location?(gg=Lf(),(location.search||"?").slice(1).split("&").forEach(e=>{if(0!==e.length){const[t,n]=e.split("=");gg.set(`--${rm(t,"-")}`,n),gg.set(`-${rm(t,"-")}`,n)}})):gg=Lf();return gg})().has(e),bg=e=>tg(fg?process.env[e.toUpperCase().replaceAll("-","_")]:rg.getItem(e)),vg=e=>yg("--"+e)||null!==bg(e);vg("production");var xg;fg&&(xg=process.env.FORCE_COLOR,["true","1","2"].includes(xg))||!yg("--no-colors")&&!vg("no-color")&&(!fg||process.stdout.isTTY)&&(!fg||yg("--color")||null!==bg("COLORTERM")||(bg("TERM")||"").includes("color"));const wg=mg?e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=tm(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),kg=e=>{const t=(n=e.byteLength,new Uint8Array(n));var n;return t.set(e),t},Cg=e=>(e=>{const t=cm();return e(t),dm(t)})(t=>km(t,e));class Eg{constructor(e,t){this.left=e,this.right=t}}const Sg=(e,t)=>new Eg(e,t),Mg="undefined"!=typeof document?document:{};"undefined"!=typeof DOMParser&&new DOMParser;const Rg=(Tg=clearTimeout,class{constructor(e){this._=e}destroy(){Tg(this._)}});var Tg;const jg=(e,t)=>new Rg(setTimeout(t,e)),Ng=Symbol,Ag=Ng(),Og=Ng(),_g=Ng(),Pg=Ng(),Ig=Ng(),Lg=Ng(),Dg=Ng(),Bg=Ng(),Hg=Ng(),Vg=(Sg("font-weight","bold"),Sg("font-weight","normal"),Sg("color","blue"),Sg("color","green"),Sg("color","grey"),Sg("color","red"),Sg("color","purple"),Sg("color","orange"),Sg("color","black"),(...e)=>{e.unshift(Bg),$g.forEach(t=>t.print(e))}),$g=Hf(),zg=e=>({[Symbol.iterator](){return this},next:e}),Fg=(e,t)=>zg(()=>{const{done:n,value:o}=e.next();return{done:n,value:n?void 0:t(o)}});class Ug{constructor(e,t){this.clock=e,this.len=t}}class Wg{constructor(){this.clients=new Map}}const qg=(e,t,n)=>t.clients.forEach((t,o)=>{const r=e.doc.store.clients.get(o);if(null!=r){const o=r[r.length-1],i=o.id.clock+o.length;for(let s=0,l=t[s];s<t.length&&l.clock<i;l=t[++s])Yy(e,r,l.clock,l.len,n)}}),Gg=(e,t)=>{const n=e.clients.get(t.client);return void 0!==n&&null!==((e,t)=>{let n=0,o=e.length-1;for(;n<=o;){const r=Wf((n+o)/2),i=e[r],s=i.clock;if(s<=t){if(t<s+i.len)return r;n=r+1}else o=r-1}return null})(n,t.clock)},Kg=e=>{e.clients.forEach(e=>{let t,n;for(e.sort((e,t)=>e.clock-t.clock),t=1,n=1;t<e.length;t++){const o=e[n-1],r=e[t];o.clock+o.len>=r.clock?o.len=Kf(o.len,r.clock+r.len-o.clock):(n<t&&(e[n]=r),n++)}e.length=n})},Zg=e=>{const t=new Wg;for(let n=0;n<e.length;n++)e[n].clients.forEach((o,r)=>{if(!t.clients.has(r)){const i=o.slice();for(let t=n+1;t<e.length;t++)$f(i,e[t].clients.get(r)||[]);t.clients.set(r,i)}});return Kg(t),t},Jg=(e,t,n,o)=>{Bf(e.clients,t,()=>[]).push(new Ug(n,o))},Xg=()=>new Wg,Yg=e=>{const t=Xg();return e.clients.forEach((e,n)=>{const o=[];for(let t=0;t<e.length;t++){const n=e[t];if(n.deleted){const r=n.id.clock;let i=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[1+ ++t])i+=n.length;o.push(new Ug(r,i))}}o.length>0&&t.clients.set(n,o)}),t},Qg=(e,t)=>{pm(e.restEncoder,t.clients.size),zf(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),pm(e.restEncoder,t);const o=n.length;pm(e.restEncoder,o);for(let r=0;r<o;r++){const t=n[r];e.writeDsClock(t.clock),e.writeDsLen(t.len)}})},ey=e=>{const t=new Wg,n=Bm(e.restDecoder);for(let o=0;o<n;o++){e.resetDsCurVal();const n=Bm(e.restDecoder),o=Bm(e.restDecoder);if(o>0){const r=Bf(t.clients,n,()=>[]);for(let t=0;t<o;t++)r.push(new Ug(e.readDsClock(),e.readDsLen()))}}return t},ty=(e,t,n)=>{const o=new Wg,r=Bm(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const r=Bm(e.restDecoder),i=Bm(e.restDecoder),s=n.clients.get(r)||[],l=Wy(n,r);for(let n=0;n<i;n++){const n=e.readDsClock(),i=n+e.readDsLen();if(n<l){l<i&&Jg(o,r,l,i-l);let e=Gy(s,n),a=s[e];for(!a.deleted&&a.id.clock<n&&(s.splice(e+1,0,zv(t,a,n-a.id.clock)),e++);e<s.length&&(a=s[e++],a.id.clock<i);)a.deleted||(i<a.id.clock+a.length&&s.splice(e,0,zv(t,a,i-a.id.clock)),a.delete(t))}else Jg(o,r,n,i-n)}}if(o.clients.size>0){const e=new uy;return pm(e.restEncoder,0),Qg(e,o),e.toUint8Array()}return null},ny=Jm;class oy extends Uf{constructor({guid:e=Ym(),collectionid:t=null,gc:n=!0,gcFilter:o=()=>!0,meta:r=null,autoLoad:i=!1,shouldLoad:s=!0}={}){super(),this.gc=n,this.gcFilter=o,this.clientID=ny(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Fy,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=s,this.autoLoad=i,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=eg(e=>{this.on("load",()=>{this.isLoaded=!0,e(this)})});const l=()=>eg(e=>{const t=n=>{void 0!==n&&!0!==n||(this.off("sync",t),e())};this.on("sync",t)});this.on("sync",e=>{!1===e&&this.isSynced&&(this.whenSynced=l()),this.isSynced=void 0===e||!0===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;null===e||this.shouldLoad||rb(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(zf(this.subdocs).map(e=>e.guid))}transact(e,t=null){return rb(this,e,t)}get(e,t=jb){const n=Bf(this.share,e,()=>{const e=new t;return e._integrate(this,null),e}),o=n.constructor;if(t!==jb&&o!==t){if(o===jb){const o=new t;o._map=n._map,n._map.forEach(e=>{for(;null!==e;e=e.left)e.parent=o}),o._start=n._start;for(let e=o._start;null!==e;e=e.right)e.parent=o;return o._length=n._length,this.share.set(e,o),o._integrate(this,null),o}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=""){return this.get(e,Kb)}getText(e=""){return this.get(e,hv)}getMap(e=""){return this.get(e,Jb)}getXmlElement(e=""){return this.get(e,mv)}getXmlFragment(e=""){return this.get(e,fv)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,zf(this.subdocs).forEach(e=>e.destroy());const e=this._item;if(null!==e){this._item=null;const t=e.content;t.doc=new oy({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,rb(e.parent.doc,n=>{const o=t.doc;e.deleted||n.subdocsAdded.add(o),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class ry{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Bm(this.restDecoder)}readDsLen(){return Bm(this.restDecoder)}}class iy extends ry{readLeftID(){return Ty(Bm(this.restDecoder),Bm(this.restDecoder))}readRightID(){return Ty(Bm(this.restDecoder),Bm(this.restDecoder))}readClient(){return Bm(this.restDecoder)}readInfo(){return Dm(this.restDecoder)}readString(){return Vm(this.restDecoder)}readParentInfo(){return 1===Bm(this.restDecoder)}readTypeRef(){return Bm(this.restDecoder)}readLen(){return Bm(this.restDecoder)}readAny(){return Fm(this.restDecoder)}readBuf(){return kg(Lm(this.restDecoder))}readJSON(){return JSON.parse(Vm(this.restDecoder))}readKey(){return Vm(this.restDecoder)}}class sy{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Bm(this.restDecoder),this.dsCurrVal}readDsLen(){const e=Bm(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class ly extends sy{constructor(e){super(e),this.keys=[],Bm(e),this.keyClockDecoder=new qm(Lm(e)),this.clientDecoder=new Wm(Lm(e)),this.leftClockDecoder=new qm(Lm(e)),this.rightClockDecoder=new qm(Lm(e)),this.infoDecoder=new Um(Lm(e),Dm),this.stringDecoder=new Gm(Lm(e)),this.parentInfoDecoder=new Um(Lm(e),Dm),this.typeRefDecoder=new Wm(Lm(e)),this.lenDecoder=new Wm(Lm(e))}readLeftID(){return new My(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new My(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Fm(this.restDecoder)}readBuf(){return Lm(this.restDecoder)}readJSON(){return Fm(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class ay{constructor(){this.restEncoder=cm()}toUint8Array(){return dm(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){pm(this.restEncoder,e)}writeDsLen(e){pm(this.restEncoder,e)}}class cy extends ay{writeLeftID(e){pm(this.restEncoder,e.client),pm(this.restEncoder,e.clock)}writeRightID(e){pm(this.restEncoder,e.client),pm(this.restEncoder,e.clock)}writeClient(e){pm(this.restEncoder,e)}writeInfo(e){hm(this.restEncoder,e)}writeString(e){ym(this.restEncoder,e)}writeParentInfo(e){pm(this.restEncoder,e?1:0)}writeTypeRef(e){pm(this.restEncoder,e)}writeLen(e){pm(this.restEncoder,e)}writeAny(e){km(this.restEncoder,e)}writeBuf(e){vm(this.restEncoder,e)}writeJSON(e){ym(this.restEncoder,JSON.stringify(e))}writeKey(e){ym(this.restEncoder,e)}}class dy{constructor(){this.restEncoder=cm(),this.dsCurrVal=0}toUint8Array(){return dm(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,pm(this.restEncoder,t)}writeDsLen(e){0===e&&Am(),pm(this.restEncoder,e-1),this.dsCurrVal+=e}}class uy extends dy{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Rm,this.clientEncoder=new Sm,this.leftClockEncoder=new Rm,this.rightClockEncoder=new Rm,this.infoEncoder=new Cm(hm),this.stringEncoder=new Tm,this.parentInfoEncoder=new Cm(hm),this.typeRefEncoder=new Sm,this.lenEncoder=new Sm}toUint8Array(){const e=cm();return pm(e,0),vm(e,this.keyClockEncoder.toUint8Array()),vm(e,this.clientEncoder.toUint8Array()),vm(e,this.leftClockEncoder.toUint8Array()),vm(e,this.rightClockEncoder.toUint8Array()),vm(e,dm(this.infoEncoder)),vm(e,this.stringEncoder.toUint8Array()),vm(e,dm(this.parentInfoEncoder)),vm(e,this.typeRefEncoder.toUint8Array()),vm(e,this.lenEncoder.toUint8Array()),bm(e,dm(this.restEncoder)),dm(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){km(this.restEncoder,e)}writeBuf(e){vm(this.restEncoder,e)}writeJSON(e){km(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const hy=(e,t,n)=>{const o=new Map;n.forEach((e,n)=>{Wy(t,n)>e&&o.set(n,e)}),Uy(t).forEach((e,t)=>{n.has(t)||o.set(t,0)}),pm(e.restEncoder,o.size),zf(o.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,o])=>{((e,t,n,o)=>{o=Kf(o,t[0].id.clock);const r=Gy(t,o);pm(e.restEncoder,t.length-r),e.writeClient(n),pm(e.restEncoder,o);const i=t[r];i.write(e,o-i.id.clock);for(let s=r+1;s<t.length;s++)t[s].write(e,0)})(e,t.clients.get(n),n,o)})},py=(e,t,n,o=new ly(e))=>rb(t,e=>{e.local=!1;let t=!1;const n=e.doc,r=n.store,i=((e,t)=>{const n=Lf(),o=Bm(e.restDecoder);for(let r=0;r<o;r++){const o=Bm(e.restDecoder),r=new Array(o),i=e.readClient();let s=Bm(e.restDecoder);n.set(i,{i:0,refs:r});for(let n=0;n<o;n++){const o=e.readInfo();switch(31&o){case 0:{const t=e.readLen();r[n]=new xv(Ty(i,s),t),s+=t;break}case 10:{const t=Bm(e.restDecoder);r[n]=new Kv(Ty(i,s),t),s+=t;break}default:{const l=!(192&o),a=new Wv(Ty(i,s),null,(o&Xf)===Xf?e.readLeftID():null,null,(o&Jf)===Jf?e.readRightID():null,l?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,!l||32&~o?null:e.readString(),qv(e,o));r[n]=a,s+=a.length}}}}return n})(o,n),s=((e,t,n)=>{const o=[];let r=zf(n.keys()).sort((e,t)=>e-t);if(0===r.length)return null;const i=()=>{if(0===r.length)return null;let e=n.get(r[r.length-1]);for(;e.refs.length===e.i;){if(r.pop(),!(r.length>0))return null;e=n.get(r[r.length-1])}return e};let s=i();if(null===s)return null;const l=new Fy,a=new Map,c=(e,t)=>{const n=a.get(e);(null==n||n>t)&&a.set(e,t)};let d=s.refs[s.i++];const u=new Map,h=()=>{for(const e of o){const t=e.id.client,o=n.get(t);o?(o.i--,l.clients.set(t,o.refs.slice(o.i)),n.delete(t),o.i=0,o.refs=[]):l.clients.set(t,[e]),r=r.filter(e=>e!==t)}o.length=0};for(;;){if(d.constructor!==Kv){const r=Bf(u,d.id.client,()=>Wy(t,d.id.client))-d.id.clock;if(r<0)o.push(d),c(d.id.client,d.id.clock-1),h();else{const i=d.getMissing(e,t);if(null!==i){o.push(d);const e=n.get(i)||{refs:[],i:0};if(e.refs.length!==e.i){d=e.refs[e.i++];continue}c(i,Wy(t,i)),h()}else(0===r||r<d.length)&&(d.integrate(e,r),u.set(d.id.client,d.id.clock+d.length))}}if(o.length>0)d=o.pop();else if(null!==s&&s.i<s.refs.length)d=s.refs[s.i++];else{if(s=i(),null===s)break;d=s.refs[s.i++]}}if(l.clients.size>0){const e=new uy;return hy(e,l,new Map),pm(e.restEncoder,0),{missing:a,update:e.toUint8Array()}}return null})(e,r,i),l=r.pendingStructs;if(l){for(const[e,n]of l.missing)if(n<Wy(r,e)){t=!0;break}if(s){for(const[e,t]of s.missing){const n=l.missing.get(e);(null==n||n>t)&&l.missing.set(e,t)}l.update=pb([l.update,s.update])}}else r.pendingStructs=s;const a=ty(o,e,r);if(r.pendingDs){const t=new ly(Im(r.pendingDs));Bm(t.restDecoder);const n=ty(t,e,r);r.pendingDs=a&&n?pb([a,n]):a||n}else r.pendingDs=a;if(t){const t=r.pendingStructs.update;r.pendingStructs=null,fy(e.doc,t)}},n,!1),fy=(e,t,n,o=ly)=>{const r=Im(t);py(r,e,n,new o(r))},my=(e,t,n)=>fy(e,t,n,iy),gy=(e,t=new Uint8Array([0]),n=new uy)=>{((e,t,n=new Map)=>{hy(e,t.store,n),Qg(e,Yg(t.store))})(n,e,by(t));const o=[n.toUint8Array()];if(e.store.pendingDs&&o.push(e.store.pendingDs),e.store.pendingStructs&&o.push(fb(e.store.pendingStructs.update,t)),o.length>1){if(n.constructor===cy)return ub(o.map((e,t)=>0===t?e:bb(e)));if(n.constructor===uy)return pb(o)}return o[0]},yy=(e,t)=>gy(e,t,new cy),by=e=>(e=>{const t=new Map,n=Bm(e.restDecoder);for(let o=0;o<n;o++){const n=Bm(e.restDecoder),o=Bm(e.restDecoder);t.set(n,o)}return t})(new ry(Im(e))),vy=(e,t)=>(pm(e.restEncoder,t.size),zf(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{pm(e.restEncoder,t),pm(e.restEncoder,n)}),e),xy=(e,t=new dy)=>(e instanceof Map?vy(t,e):((e,t)=>{vy(e,Uy(t.store))})(t,e),t.toUint8Array());class wy{constructor(){this.l=[]}}const ky=()=>new wy,Cy=(e,t)=>e.l.push(t),Ey=(e,t)=>{const n=e.l;n.length;e.l=n.filter(e=>t!==e),e.l.length},Sy=(e,t,n)=>hg(e.l,[t,n]);class My{constructor(e,t){this.client=e,this.clock=t}}const Ry=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,Ty=(e,t)=>new My(e,t),jy=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Am()},Ny=(e,t)=>{for(;null!==t;){if(t.parent===e)return!0;t=t.parent._item}return!1};class Ay{constructor(e,t,n,o=0){this.type=e,this.tname=t,this.item=n,this.assoc=o}}const Oy=e=>new Ay(null==e.type?null:Ty(e.type.client,e.type.clock),e.tname??null,null==e.item?null:Ty(e.item.client,e.item.clock),null==e.assoc?0:e.assoc);class _y{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}}const Py=(e,t,n)=>{let o=null,r=null;return null===e._item?r=jy(e):o=Ty(e._item.id.client,e._item.id.clock),new Ay(o,r,t,n)},Iy=(e,t,n=0)=>{let o=e._start;if(n<0){if(0===t)return Py(e,null,n);t--}for(;null!==o;){if(!o.deleted&&o.countable){if(o.length>t)return Py(e,Ty(o.id.client,o.id.clock+t),n);t-=o.length}if(null===o.right&&n<0)return Py(e,o.lastId,n);o=o.right}return Py(e,null,n)},Ly=(e,t,n=!0)=>{const o=t.store,r=e.item,i=e.type,s=e.tname,l=e.assoc;let a=null,c=0;if(null!==r){if(Wy(o,r.client)<=r.clock)return null;const e=n?Vv(o,r):((e,t)=>{const n=Ky(e,t);return{item:n,diff:t.clock-n.id.clock}})(o,r),t=e.item;if(!(t instanceof Wv))return null;if(a=t.parent,null===a._item||!a._item.deleted){c=t.deleted||!t.countable?0:e.diff+(l>=0?0:1);let n=t.left;for(;null!==n;)!n.deleted&&n.countable&&(c+=n.length),n=n.left}}else{if(null!==s)a=t.get(s);else{if(null===i)throw Am();{if(Wy(o,i.client)<=i.clock)return null;const{item:e}=n?Vv(o,i):{item:Ky(o,i)};if(!(e instanceof Wv&&e.content instanceof Hv))return null;a=e.content.type}}c=l>=0?a._length:0}return((e,t,n=0)=>new _y(e,t,n))(a,c,e.assoc)},Dy=(e,t)=>e===t||null!==e&&null!==t&&e.tname===t.tname&&Ry(e.item,t.item)&&Ry(e.type,t.type)&&e.assoc===t.assoc;class By{constructor(e,t){this.ds=e,this.sv=t}}const Hy=(e,t)=>new By(e,t),Vy=e=>Hy(Yg(e.store),Uy(e.store)),$y=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Gg(t.ds,e.id),zy=(e,t)=>{const n=Bf(e.meta,zy,Hf),o=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<Wy(o,n)&&Jy(e,Ty(n,t))}),qg(e,t.ds,e=>{}),n.add(t))};class Fy{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Uy=e=>{const t=new Map;return e.clients.forEach((e,n)=>{const o=e[e.length-1];t.set(n,o.id.clock+o.length)}),t},Wy=(e,t)=>{const n=e.clients.get(t);if(void 0===n)return 0;const o=n[n.length-1];return o.id.clock+o.length},qy=(e,t)=>{let n=e.clients.get(t.id.client);if(void 0===n)n=[],e.clients.set(t.id.client,n);else{const e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw Am()}n.push(t)},Gy=(e,t)=>{let n=0,o=e.length-1,r=e[o],i=r.id.clock;if(i===t)return o;let s=Wf(t/(i+r.length-1)*o);for(;n<=o;){if(r=e[s],i=r.id.clock,i<=t){if(t<i+r.length)return s;n=s+1}else o=s-1;s=Wf((n+o)/2)}throw Am()},Ky=(e,t)=>{const n=e.clients.get(t.client);return n[Gy(n,t.clock)]},Zy=(e,t,n)=>{const o=Gy(t,n),r=t[o];return r.id.clock<n&&r instanceof Wv?(t.splice(o+1,0,zv(e,r,n-r.id.clock)),o+1):o},Jy=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Zy(e,n,t.clock)]},Xy=(e,t,n)=>{const o=t.clients.get(n.client),r=Gy(o,n.clock),i=o[r];return n.clock!==i.id.clock+i.length-1&&i.constructor!==xv&&o.splice(r+1,0,zv(e,i,n.clock-i.id.clock+1)),i},Yy=(e,t,n,o,r)=>{if(0===o)return;const i=n+o;let s,l=Zy(e,t,n);do{s=t[l++],i<s.id.clock+s.length&&Zy(e,t,i),r(s)}while(l<t.length&&t[l].id.clock<i)};class Qy{constructor(e,t,n){this.doc=e,this.deleteSet=new Wg,this.beforeState=Uy(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const eb=(e,t)=>!(0===t.deleteSet.clients.size&&!((e,t)=>{for(const[n,o]of e)if(t(o,n))return!0;return!1})(t.afterState,(e,n)=>t.beforeState.get(n)!==e))&&(Kg(t.deleteSet),((e,t)=>{hy(e,t.doc.store,t.beforeState)})(e,t),Qg(e,t.deleteSet),!0),tb=(e,t,n)=>{const o=t._item;(null===o||o.id.clock<(e.beforeState.get(o.id.client)||0)&&!o.deleted)&&Bf(e.changed,t,Hf).add(n)},nb=(e,t)=>{let n=e[t],o=e[t-1],r=t;for(;r>0&&(o.deleted===n.deleted&&o.constructor===n.constructor&&o.mergeWith(n));n=o,o=e[--r-1])n instanceof Wv&&null!==n.parentSub&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,o);const i=t-r;return i&&e.splice(t+1-i,i),i},ob=(e,t)=>{if(t<e.length){const n=e[t],o=n.doc,r=o.store,i=n.deleteSet,s=n._mergeStructs;try{Kg(i),n.afterState=Uy(n.doc.store),o.emit("beforeObserverCalls",[n,o]);const e=[];n.changed.forEach((t,o)=>e.push(()=>{null!==o._item&&o._item.deleted||o._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((e,t)=>{t._dEH.l.length>0&&(null===t._item||!t._item.deleted)&&((e=e.filter(e=>null===e.target._item||!e.target._item.deleted)).forEach(e=>{e.currentTarget=t,e._path=null}),e.sort((e,t)=>e.path.length-t.path.length),Sy(t._dEH,e,n))})}),e.push(()=>o.emit("afterTransaction",[n,o])),hg(e,[]),n._needFormattingCleanup&&cv(n)}finally{o.gc&&((e,t,n)=>{for(const[o,r]of e.clients.entries()){const e=t.clients.get(o);for(let o=r.length-1;o>=0;o--){const i=r[o],s=i.clock+i.len;for(let o=Gy(e,i.clock),r=e[o];o<e.length&&r.id.clock<s;r=e[++o]){const r=e[o];if(i.clock+i.len<=r.id.clock)break;r instanceof Wv&&r.deleted&&!r.keep&&n(r)&&r.gc(t,!1)}}}})(i,r,o.gcFilter),((e,t)=>{e.clients.forEach((e,n)=>{const o=t.clients.get(n);for(let t=e.length-1;t>=0;t--){const n=e[t];for(let e=Gf(o.length-1,1+Gy(o,n.clock+n.len-1)),t=o[e];e>0&&t.id.clock>=n.clock;t=o[e])e-=1+nb(o,e)}})})(i,r),n.afterState.forEach((e,t)=>{const o=n.beforeState.get(t)||0;if(o!==e){const e=r.clients.get(t),n=Kf(Gy(e,o),1);for(let t=e.length-1;t>=n;)t-=1+nb(e,t)}});for(let e=s.length-1;e>=0;e--){const{client:t,clock:n}=s[e].id,o=r.clients.get(t),i=Gy(o,n);i+1<o.length&&nb(o,i+1)>1||i>0&&nb(o,i)}if(n.local||n.afterState.get(o.clientID)===n.beforeState.get(o.clientID)||(((...e)=>{$g.forEach(t=>t.print(e))})(Bg,Ag,"[yjs] ",Og,Lg,"Changed the client-id because another client seems to be using it."),o.clientID=ny()),o.emit("afterTransactionCleanup",[n,o]),o._observers.has("update")){const e=new cy;eb(e,n)&&o.emit("update",[e.toUint8Array(),n.origin,o,n])}if(o._observers.has("updateV2")){const e=new uy;eb(e,n)&&o.emit("updateV2",[e.toUint8Array(),n.origin,o,n])}const{subdocsAdded:l,subdocsLoaded:a,subdocsRemoved:c}=n;(l.size>0||c.size>0||a.size>0)&&(l.forEach(e=>{e.clientID=o.clientID,null==e.collectionid&&(e.collectionid=o.collectionid),o.subdocs.add(e)}),c.forEach(e=>o.subdocs.delete(e)),o.emit("subdocs",[{loaded:a,added:l,removed:c},o,n]),c.forEach(e=>e.destroy())),e.length<=t+1?(o._transactionCleanups=[],o.emit("afterAllTransactions",[o,e])):ob(e,t+1)}}},rb=(e,t,n=null,o=!0)=>{const r=e._transactionCleanups;let i=!1,s=null;null===e._transaction&&(i=!0,e._transaction=new Qy(e,n,o),r.push(e._transaction),1===r.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{s=t(e._transaction)}finally{if(i){const t=e._transaction===r[0];e._transaction=null,t&&ob(r,0)}}return s};class ib{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}}const sb=(e,t,n)=>{qg(e,n.deletions,n=>{n instanceof Wv&&t.scope.some(t=>t===e.doc||Ny(t,n))&&$v(n,!1)})},lb=(e,t,n)=>{let o=null;const r=e.doc,i=e.scope;rb(r,n=>{for(;t.length>0&&null===e.currStackItem;){const o=r.store,s=t.pop(),l=new Set,a=[];let c=!1;qg(n,s.insertions,e=>{if(e instanceof Wv){if(null!==e.redone){let{item:t,diff:r}=Vv(o,e.id);r>0&&(t=Jy(n,Ty(t.id.client,t.id.clock+r))),e=t}!e.deleted&&i.some(t=>t===n.doc||Ny(t,e))&&a.push(e)}}),qg(n,s.deletions,e=>{e instanceof Wv&&i.some(t=>t===n.doc||Ny(t,e))&&!Gg(s.insertions,e.id)&&l.add(e)}),l.forEach(t=>{c=null!==Uv(n,t,l,s.insertions,e.ignoreRemoteMapChanges,e)||c});for(let t=a.length-1;t>=0;t--){const o=a[t];e.deleteFilter(o)&&(o.delete(n),c=!0)}e.currStackItem=c?s:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),o=n},e);const s=e.currStackItem;if(null!=s){const t=o.changedParentTypes;e.emit("stack-item-popped",[{stackItem:s,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return s};class ab extends Uf{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:o=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:s=(Ff(e)?e[0].doc:e instanceof oy?e:e.doc)}={}){super(),this.scope=[],this.doc=s,this.addToScope(e),this.deleteFilter=o,r.add(this),this.trackedOrigins=r,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!(this.captureTransaction(e)&&this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)&&(this.trackedOrigins.has(e.origin)||e.origin&&this.trackedOrigins.has(e.origin.constructor))))return;const t=this.undoing,n=this.redoing,o=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);const r=new Wg;e.afterState.forEach((t,n)=>{const o=e.beforeState.get(n)||0,i=t-o;i>0&&Jg(r,n,o,i)});const i=Qm();let s=!1;if(this.lastChange>0&&i-this.lastChange<this.captureTimeout&&o.length>0&&!t&&!n){const t=o[o.length-1];t.deletions=Zg([t.deletions,e.deleteSet]),t.insertions=Zg([t.insertions,r])}else o.push(new ib(e.deleteSet,r)),s=!0;t||n||(this.lastChange=i),qg(e,e.deleteSet,t=>{t instanceof Wv&&this.scope.some(n=>n===e.doc||Ny(n,t))&&$v(t,!0)});const l=[{stackItem:o[o.length-1],origin:e.origin,type:t?"redo":"undo",changedParentTypes:e.changedParentTypes},this];s?this.emit("stack-item-added",l):this.emit("stack-item-updated",l)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){const t=new Set(this.scope);(e=Ff(e)?e:[e]).forEach(e=>{t.has(e)||(t.add(e),(e instanceof jb?e.doc!==this.doc:e!==this.doc)&&Vg("[yjs#509] Not same Y.Doc"),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>sb(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>sb(n,this,e)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){let e;this.undoing=!0;try{e=lb(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){let e;this.redoing=!0;try{e=lb(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}class cb{constructor(e,t){this.gen=function*(e){const t=Bm(e.restDecoder);for(let n=0;n<t;n++){const t=Bm(e.restDecoder),n=e.readClient();let o=Bm(e.restDecoder);for(let r=0;r<t;r++){const t=e.readInfo();if(10===t){const t=Bm(e.restDecoder);yield new Kv(Ty(n,o),t),o+=t}else if(31&t){const r=!(192&t),i=new Wv(Ty(n,o),null,(t&Xf)===Xf?e.readLeftID():null,null,(t&Jf)===Jf?e.readRightID():null,r?e.readParentInfo()?e.readString():e.readLeftID():null,!r||32&~t?null:e.readString(),qv(e,t));yield i,o+=i.length}else{const t=e.readLen();yield new xv(Ty(n,o),t),o+=t}}}}(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Kv);return this.curr}}class db{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const ub=e=>pb(e,iy,cy),hb=(e,t)=>{if(e.constructor===xv){const{client:n,clock:o}=e.id;return new xv(Ty(n,o+t),e.length-t)}if(e.constructor===Kv){const{client:n,clock:o}=e.id;return new Kv(Ty(n,o+t),e.length-t)}{const n=e,{client:o,clock:r}=n.id;return new Wv(Ty(o,r+t),null,Ty(o,r+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},pb=(e,t=ly,n=uy)=>{if(1===e.length)return e[0];const o=e.map(e=>new t(Im(e)));let r=o.map(e=>new cb(e,!0)),i=null;const s=new n,l=new db(s);for(;r=r.filter(e=>null!==e.curr),r.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){const n=e.curr.id.clock-t.curr.id.clock;return 0===n?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===Kv?1:-1:n}return t.curr.id.client-e.curr.id.client}),0!==r.length;){const e=r[0],t=e.curr.id.client;if(null!==i){let n=e.curr,o=!1;for(;null!==n&&n.id.clock+n.length<=i.struct.id.clock+i.struct.length&&n.id.client>=i.struct.id.client;)n=e.next(),o=!0;if(null===n||n.id.client!==t||o&&n.id.clock>i.struct.id.clock+i.struct.length)continue;if(t!==i.struct.id.client)gb(l,i.struct,i.offset),i={struct:n,offset:0},e.next();else if(i.struct.id.clock+i.struct.length<n.id.clock)if(i.struct.constructor===Kv)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{gb(l,i.struct,i.offset);const e=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new Kv(Ty(t,i.struct.id.clock+i.struct.length),e),offset:0}}else{const t=i.struct.id.clock+i.struct.length-n.id.clock;t>0&&(i.struct.constructor===Kv?i.struct.length-=t:n=hb(n,t)),i.struct.mergeWith(n)||(gb(l,i.struct,i.offset),i={struct:n,offset:0},e.next())}}else i={struct:e.curr,offset:0},e.next();for(let n=e.curr;null!==n&&n.id.client===t&&n.id.clock===i.struct.id.clock+i.struct.length&&n.constructor!==Kv;n=e.next())gb(l,i.struct,i.offset),i={struct:n,offset:0}}null!==i&&(gb(l,i.struct,i.offset),i=null),yb(l);const a=o.map(e=>ey(e)),c=Zg(a);return Qg(s,c),s.toUint8Array()},fb=(e,t,n=ly,o=uy)=>{const r=by(t),i=new o,s=new db(i),l=new n(Im(e)),a=new cb(l,!1);for(;a.curr;){const e=a.curr,t=e.id.client,n=r.get(t)||0;if(a.curr.constructor!==Kv)if(e.id.clock+e.length>n)for(gb(s,e,Kf(n-e.id.clock,0)),a.next();a.curr&&a.curr.id.client===t;)gb(s,a.curr,0),a.next();else for(;a.curr&&a.curr.id.client===t&&a.curr.id.clock+a.curr.length<=n;)a.next();else a.next()}yb(s);const c=ey(l);return Qg(i,c),i.toUint8Array()},mb=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:dm(e.encoder.restEncoder)}),e.encoder.restEncoder=cm(),e.written=0)},gb=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&mb(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),pm(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},yb=e=>{mb(e);const t=e.encoder.restEncoder;pm(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const o=e.clientStructs[n];pm(t,o.written),bm(t,o.restEncoder)}},bb=e=>((e,t,n,o)=>{const r=new n(Im(e)),i=new cb(r,!1),s=new o,l=new db(s);for(let c=i.curr;null!==c;c=i.next())gb(l,t(c),0);yb(l);const a=ey(r);return Qg(s,a),s.toUint8Array()})(e,pg,ly,cy),vb="You must not compute changes after the event-handler fired.";class xb{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=wb(this.currentTarget,this.target))}deletes(e){return Gg(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw jm(vb);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(null!==n){const o=t._map.get(n);let r,i;if(this.adds(o)){let e=o.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(o)){if(null===e||!this.deletes(e))return;r="delete",i=Vf(e.content.getContent())}else null!==e&&this.deletes(e)?(r="update",i=Vf(e.content.getContent())):(r="add",i=void 0)}else{if(!this.deletes(o))return;r="delete",i=Vf(o.content.getContent())}e.set(n,{action:r,oldValue:i})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw jm(vb);const t=this.target,n=Hf(),o=Hf(),r=[];e={added:n,deleted:o,delta:r,keys:this.keys};if(this.transaction.changed.get(t).has(null)){let e=null;const i=()=>{e&&r.push(e)};for(let r=t._start;null!==r;r=r.right)r.deleted?this.deletes(r)&&!this.adds(r)&&(null!==e&&void 0!==e.delete||(i(),e={delete:0}),e.delete+=r.length,o.add(r)):this.adds(r)?(null!==e&&void 0!==e.insert||(i(),e={insert:[]}),e.insert=e.insert.concat(r.content.getContent()),n.add(r)):(null!==e&&void 0!==e.retain||(i(),e={retain:0}),e.retain+=r.length);null!==e&&void 0===e.retain&&i()}this._changes=e}return e}}const wb=(e,t)=>{const n=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)n.unshift(t._item.parentSub);else{let e=0,o=t._item.parent._start;for(;o!==t._item&&null!==o;)!o.deleted&&o.countable&&(e+=o.length),o=o.right;n.unshift(e)}t=t._item.parent}return n},kb=()=>{Vg("Invalid access: Add Yjs type to a document before reading data.")};let Cb=0;class Eb{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Cb++}}const Sb=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Cb++},Mb=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const n=0===e._searchMarker.length?null:e._searchMarker.reduce((e,n)=>qf(t-e.index)<qf(t-n.index)?e:n);let o=e._start,r=0;for(null!==n&&(o=n.p,r=n.index,(e=>{e.timestamp=Cb++})(n));null!==o.right&&r<t;){if(!o.deleted&&o.countable){if(t<r+o.length)break;r+=o.length}o=o.right}for(;null!==o.left&&r>t;)o=o.left,!o.deleted&&o.countable&&(r-=o.length);for(;null!==o.left&&o.left.id.client===o.id.client&&o.left.id.clock+o.left.length===o.id.clock;)o=o.left,!o.deleted&&o.countable&&(r-=o.length);return null!==n&&qf(n.index-r)<o.parent.length/80?(Sb(n,o,r),n):((e,t,n)=>{if(e.length>=80){const o=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return Sb(o,t,n),o}{const o=new Eb(t,n);return e.push(o),o}})(e._searchMarker,o,r)},Rb=(e,t,n)=>{for(let o=e.length-1;o>=0;o--){const r=e[o];if(n>0){let t=r.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(r.index-=t.length);if(null===t||!0===t.marker){e.splice(o,1);continue}r.p=t,t.marker=!0}(t<r.index||n>0&&t===r.index)&&(r.index=Kf(t,r.index+n))}},Tb=(e,t,n)=>{const o=e,r=t.changedParentTypes;for(;Bf(r,e,()=>[]).push(n),null!==e._item;)e=e._item.parent;Sy(o._eH,n,t)};class jb{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ky(),this._dEH=ky(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Nm()}clone(){throw Nm()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Cy(this._eH,e)}observeDeep(e){Cy(this._dEH,e)}unobserve(e){Ey(this._eH,e)}unobserveDeep(e){Ey(this._dEH,e)}toJSON(){}}const Nb=(e,t,n)=>{e.doc??kb(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let o=n-t;const r=[];let i=e._start;for(;null!==i&&o>0;){if(i.countable&&!i.deleted){const e=i.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&o>0;n++)r.push(e[n]),o--;t=0}}i=i.right}return r},Ab=e=>{e.doc??kb();const t=[];let n=e._start;for(;null!==n;){if(n.countable&&!n.deleted){const e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},Ob=(e,t)=>{const n=[];let o=e._start;for(;null!==o;){if(o.countable&&$y(o,t)){const e=o.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}o=o.right}return n},_b=(e,t)=>{let n=0,o=e._start;for(e.doc??kb();null!==o;){if(o.countable&&!o.deleted){const r=o.content.getContent();for(let o=0;o<r.length;o++)t(r[o],n++,e)}o=o.right}},Pb=(e,t)=>{const n=[];return _b(e,(o,r)=>{n.push(t(o,r,e))}),n},Ib=e=>{let t=e._start,n=null,o=0;return{[Symbol.iterator](){return this},next:()=>{if(null===n){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return{done:!0,value:void 0};n=t.content.getContent(),o=0,t=t.right}const e=n[o++];return n.length<=o&&(n=null),{done:!1,value:e}}}},Lb=(e,t)=>{e.doc??kb();const n=Mb(e,t);let o=e._start;for(null!==n&&(o=n.p,t-=n.index);null!==o;o=o.right)if(!o.deleted&&o.countable){if(t<o.length)return o.content.getContent()[t];t-=o.length}},Db=(e,t,n,o)=>{let r=n;const i=e.doc,s=i.clientID,l=i.store,a=null===n?t._start:n.right;let c=[];const d=()=>{c.length>0&&(r=new Wv(Ty(s,Wy(l,s)),r,r&&r.lastId,a,a&&a.id,t,null,new jv(c)),r.integrate(e,0),c=[])};o.forEach(n=>{if(null===n)c.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(n);break;default:switch(d(),n.constructor){case Uint8Array:case ArrayBuffer:r=new Wv(Ty(s,Wy(l,s)),r,r&&r.lastId,a,a&&a.id,t,null,new wv(new Uint8Array(n))),r.integrate(e,0);break;case oy:r=new Wv(Ty(s,Wy(l,s)),r,r&&r.lastId,a,a&&a.id,t,null,new Ev(n)),r.integrate(e,0);break;default:if(!(n instanceof jb))throw new Error("Unexpected content type in insert operation");r=new Wv(Ty(s,Wy(l,s)),r,r&&r.lastId,a,a&&a.id,t,null,new Hv(n)),r.integrate(e,0)}}}),d()},Bb=()=>jm("Length exceeded!"),Hb=(e,t,n,o)=>{if(n>t._length)throw Bb();if(0===n)return t._searchMarker&&Rb(t._searchMarker,n,o.length),Db(e,t,null,o);const r=n,i=Mb(t,n);let s=t._start;for(null!==i&&(s=i.p,0===(n-=i.index)&&(s=s.prev,n+=s&&s.countable&&!s.deleted?s.length:0));null!==s;s=s.right)if(!s.deleted&&s.countable){if(n<=s.length){n<s.length&&Jy(e,Ty(s.id.client,s.id.clock+n));break}n-=s.length}return t._searchMarker&&Rb(t._searchMarker,r,o.length),Db(e,t,s,o)},Vb=(e,t,n,o)=>{if(0===o)return;const r=n,i=o,s=Mb(t,n);let l=t._start;for(null!==s&&(l=s.p,n-=s.index);null!==l&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&Jy(e,Ty(l.id.client,l.id.clock+n)),n-=l.length);for(;o>0&&null!==l;)l.deleted||(o<l.length&&Jy(e,Ty(l.id.client,l.id.clock+o)),l.delete(e),o-=l.length),l=l.right;if(o>0)throw Bb();t._searchMarker&&Rb(t._searchMarker,r,-i+o)},$b=(e,t,n)=>{const o=t._map.get(n);void 0!==o&&o.delete(e)},zb=(e,t,n,o)=>{const r=t._map.get(n)||null,i=e.doc,s=i.clientID;let l;if(null==o)l=new jv([o]);else switch(o.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new jv([o]);break;case Uint8Array:l=new wv(o);break;case oy:l=new Ev(o);break;default:if(!(o instanceof jb))throw new Error("Unexpected content type");l=new Hv(o)}new Wv(Ty(s,Wy(i.store,s)),r,r&&r.lastId,null,null,t,n,l).integrate(e,0)},Fb=(e,t)=>{e.doc??kb();const n=e._map.get(t);return void 0===n||n.deleted?void 0:n.content.getContent()[n.length-1]},Ub=e=>{const t={};return e.doc??kb(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Wb=(e,t)=>{e.doc??kb();const n=e._map.get(t);return void 0!==n&&!n.deleted},qb=e=>{return e.doc??kb(),t=e._map.entries(),n=e=>!e[1].deleted,zg(()=>{let e;do{e=t.next()}while(!e.done&&!n(e.value));return e});var t,n};class Gb extends xb{}class Kb extends jb{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new Kb;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Kb}clone(){const e=new Kb;return e.insert(0,this.toArray().map(e=>e instanceof jb?e.clone():e)),e}get length(){return this.doc??kb(),this._length}_callObserver(e,t){super._callObserver(e,t),Tb(this,e,new Gb(this,e))}insert(e,t){null!==this.doc?rb(this.doc,n=>{Hb(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?rb(this.doc,t=>{((e,t,n)=>{let o=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(o)for(;o.right;)o=o.right;Db(e,t,o,n)})(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){null!==this.doc?rb(this.doc,n=>{Vb(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Lb(this,e)}toArray(){return Ab(this)}slice(e=0,t=this.length){return Nb(this,e,t)}toJSON(){return this.map(e=>e instanceof jb?e.toJSON():e)}map(e){return Pb(this,e)}forEach(e){_b(this,e)}[Symbol.iterator](){return Ib(this)}_write(e){e.writeTypeRef(Ov)}}class Zb extends xb{constructor(e,t,n){super(e,t),this.keysChanged=n}}class Jb extends jb{constructor(e){super(),this._prelimContent=null,this._prelimContent=void 0===e?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new Jb}clone(){const e=new Jb;return this.forEach((t,n)=>{e.set(n,t instanceof jb?t.clone():t)}),e}_callObserver(e,t){Tb(this,e,new Zb(this,e,t))}toJSON(){this.doc??kb();const e={};return this._map.forEach((t,n)=>{if(!t.deleted){const o=t.content.getContent()[t.length-1];e[n]=o instanceof jb?o.toJSON():o}}),e}get size(){return[...qb(this)].length}keys(){return Fg(qb(this),e=>e[0])}values(){return Fg(qb(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Fg(qb(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??kb(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?rb(this.doc,t=>{$b(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?rb(this.doc,n=>{zb(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Fb(this,e)}has(e){return Wb(this,e)}clear(){null!==this.doc?rb(this.doc,e=>{this.forEach(function(t,n,o){$b(e,o,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(_v)}}const Xb=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&cg(e,t);class Yb{constructor(e,t,n,o){this.left=e,this.right=t,this.index=n,this.currentAttributes=o}forward(){if(null===this.right&&Am(),this.right.content.constructor===Mv)this.right.deleted||nv(this.currentAttributes,this.right.content);else this.right.deleted||(this.index+=this.right.length);this.left=this.right,this.right=this.right.right}}const Qb=(e,t,n)=>{for(;null!==t.right&&n>0;){if(t.right.content.constructor===Mv)t.right.deleted||nv(t.currentAttributes,t.right.content);else t.right.deleted||(n<t.right.length&&Jy(e,Ty(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);t.left=t.right,t.right=t.right.right}return t},ev=(e,t,n,o)=>{const r=new Map,i=o?Mb(t,n):null;if(i){const t=new Yb(i.p.left,i.p,i.index,r);return Qb(e,t,n-i.index)}{const o=new Yb(null,t._start,0,r);return Qb(e,o,n)}},tv=(e,t,n,o)=>{for(;null!==n.right&&(!0===n.right.deleted||n.right.content.constructor===Mv&&Xb(o.get(n.right.content.key),n.right.content.value));)n.right.deleted||o.delete(n.right.content.key),n.forward();const r=e.doc,i=r.clientID;o.forEach((o,s)=>{const l=n.left,a=n.right,c=new Wv(Ty(i,Wy(r.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new Mv(s,o));c.integrate(e,0),n.right=c,n.forward()})},nv=(e,t)=>{const{key:n,value:o}=t;null===o?e.delete(n):e.set(n,o)},ov=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===Mv&&Xb(t[e.right.content.key]??null,e.right.content.value));)e.forward()},rv=(e,t,n,o)=>{const r=e.doc,i=r.clientID,s=new Map;for(const l in o){const a=o[l],c=n.currentAttributes.get(l)??null;if(!Xb(c,a)){s.set(l,c);const{left:o,right:d}=n;n.right=new Wv(Ty(i,Wy(r.store,i)),o,o&&o.lastId,d,d&&d.id,t,null,new Mv(l,a)),n.right.integrate(e,0),n.forward()}}return s},iv=(e,t,n,o,r)=>{n.currentAttributes.forEach((e,t)=>{void 0===r[t]&&(r[t]=null)});const i=e.doc,s=i.clientID;ov(n,r);const l=rv(e,t,n,r),a=o.constructor===String?new Nv(o):o instanceof jb?new Hv(o):new Sv(o);let{left:c,right:d,index:u}=n;t._searchMarker&&Rb(t._searchMarker,n.index,a.getLength()),d=new Wv(Ty(s,Wy(i.store,s)),c,c&&c.lastId,d,d&&d.id,t,null,a),d.integrate(e,0),n.right=d,n.index=u,n.forward(),tv(e,t,n,l)},sv=(e,t,n,o,r)=>{const i=e.doc,s=i.clientID;ov(n,r);const l=rv(e,t,n,r);e:for(;null!==n.right&&(o>0||l.size>0&&(n.right.deleted||n.right.content.constructor===Mv));){if(!n.right.deleted)switch(n.right.content.constructor){case Mv:{const{key:t,value:i}=n.right.content,s=r[t];if(void 0!==s){if(Xb(s,i))l.delete(t);else{if(0===o)break e;l.set(t,i)}n.right.delete(e)}else n.currentAttributes.set(t,i);break}default:o<n.right.length&&Jy(e,Ty(n.right.id.client,n.right.id.clock+o)),o-=n.right.length}n.forward()}if(o>0){let r="";for(;o>0;o--)r+="\n";n.right=new Wv(Ty(s,Wy(i.store,s)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Nv(r)),n.right.integrate(e,0),n.forward()}tv(e,t,n,l)},lv=(e,t,n,o,r)=>{let i=t;const s=Lf();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===Mv){const e=i.content;s.set(e.key,e)}i=i.right}let l=0,a=!1;for(;t!==i;){if(n===t&&(a=!0),!t.deleted){const n=t.content;switch(n.constructor){case Mv:{const{key:i,value:c}=n,d=o.get(i)??null;s.get(i)===n&&d!==c||(t.delete(e),l++,a||(r.get(i)??null)!==c||d===c||(null===d?r.delete(i):r.set(i,d))),a||t.deleted||nv(r,n);break}}}t=t.right}return l},av=e=>{let t=0;return rb(e.doc,n=>{let o=e._start,r=e._start,i=Lf();const s=Df(i);for(;r;){if(!1===r.deleted)if(r.content.constructor===Mv)nv(s,r.content);else t+=lv(n,o,r,i,s),i=Df(s),o=r;r=r.right}}),t},cv=e=>{const t=new Set,n=e.doc;for(const[o,r]of e.afterState.entries()){const i=e.beforeState.get(o)||0;r!==i&&Yy(e,n.store.clients.get(o),i,r,e=>{e.deleted||e.content.constructor!==Mv||e.constructor===xv||t.add(e.parent)})}rb(n,n=>{qg(e,e.deleteSet,e=>{if(e instanceof xv||!e.parent._hasFormatting||t.has(e.parent))return;const o=e.parent;e.content.constructor===Mv?t.add(o):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Mv){const o=t.content.key;n.has(o)?t.delete(e):n.add(o)}t=t.left}})(n,e)});for(const e of t)av(e)})},dv=(e,t,n)=>{const o=n,r=Df(t.currentAttributes),i=t.right;for(;n>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case Hv:case Sv:case Nv:n<t.right.length&&Jy(e,Ty(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}i&&lv(e,i,t.right,r,t.currentAttributes);const s=(t.left||t.right).parent;return s._searchMarker&&Rb(s._searchMarker,t.index,-o+n),t};class uv extends xb{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{null===e?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(null===this._changes){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(null===this._delta){const e=this.target.doc,t=[];rb(e,e=>{const n=new Map,o=new Map;let r=this.target._start,i=null;const s={};let l="",a=0,c=0;const d=()=>{if(null!==i){let e=null;switch(i){case"delete":c>0&&(e={delete:c}),c=0;break;case"insert":("object"==typeof l||l.length>0)&&(e={insert:l},n.size>0&&(e.attributes={},n.forEach((t,n)=>{null!==t&&(e.attributes[n]=t)}))),l="";break;case"retain":a>0&&(e={retain:a},(e=>{for(const t in e)return!1;return!0})(s)||(e.attributes=ig({},s))),a=0}e&&t.push(e),i=null}};for(;null!==r;){switch(r.content.constructor){case Hv:case Sv:this.adds(r)?this.deletes(r)||(d(),i="insert",l=r.content.getContent()[0],d()):this.deletes(r)?("delete"!==i&&(d(),i="delete"),c+=1):r.deleted||("retain"!==i&&(d(),i="retain"),a+=1);break;case Nv:this.adds(r)?this.deletes(r)||("insert"!==i&&(d(),i="insert"),l+=r.content.str):this.deletes(r)?("delete"!==i&&(d(),i="delete"),c+=r.length):r.deleted||("retain"!==i&&(d(),i="retain"),a+=r.length);break;case Mv:{const{key:t,value:l}=r.content;if(this.adds(r)){if(!this.deletes(r)){const a=n.get(t)??null;Xb(a,l)?null!==l&&r.delete(e):("retain"===i&&d(),Xb(l,o.get(t)??null)?delete s[t]:s[t]=l)}}else if(this.deletes(r)){o.set(t,l);const e=n.get(t)??null;Xb(e,l)||("retain"===i&&d(),s[t]=e)}else if(!r.deleted){o.set(t,l);const n=s[t];void 0!==n&&(Xb(n,l)?null!==n&&r.delete(e):("retain"===i&&d(),null===l?delete s[t]:s[t]=l))}r.deleted||("insert"===i&&d(),nv(n,r.content));break}}r=r.right}for(d();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop()}}),this._delta=t}return this._delta}}class hv extends jb{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??kb(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(VD){}this._pending=null}_copy(){return new hv}clone(){const e=new hv;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const n=new uv(this,e,t);Tb(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??kb();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===Nv&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){null!==this.doc?rb(this.doc,n=>{const o=new Yb(null,this._start,0,new Map);for(let r=0;r<e.length;r++){const i=e[r];if(void 0!==i.insert){const s=t||"string"!=typeof i.insert||r!==e.length-1||null!==o.right||"\n"!==i.insert.slice(-1)?i.insert:i.insert.slice(0,-1);("string"!=typeof s||s.length>0)&&iv(n,this,o,s,i.attributes||{})}else void 0!==i.retain?sv(n,this,o,i.retain,i.attributes||{}):void 0!==i.delete&&dv(n,o,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){this.doc??kb();const o=[],r=new Map,i=this.doc;let s="",l=this._start;function a(){if(s.length>0){const e={};let t=!1;r.forEach((n,o)=>{t=!0,e[o]=n});const n={insert:s};t&&(n.attributes=e),o.push(n),s=""}}const c=()=>{for(;null!==l;){if($y(l,e)||void 0!==t&&$y(l,t))switch(l.content.constructor){case Nv:{const o=r.get("ychange");void 0===e||$y(l,e)?void 0===t||$y(l,t)?void 0!==o&&(a(),r.delete("ychange")):void 0!==o&&o.user===l.id.client&&"added"===o.type||(a(),r.set("ychange",n?n("added",l.id):{type:"added"})):void 0!==o&&o.user===l.id.client&&"removed"===o.type||(a(),r.set("ychange",n?n("removed",l.id):{type:"removed"})),s+=l.content.str;break}case Hv:case Sv:{a();const e={insert:l.content.getContent()[0]};if(r.size>0){const t={};e.attributes=t,r.forEach((e,n)=>{t[n]=e})}o.push(e);break}case Mv:$y(l,e)&&(a(),nv(r,l.content))}l=l.right}a()};return e||t?rb(i,n=>{e&&zy(n,e),t&&zy(n,t),c()},"cleanup"):c(),o}insert(e,t,n){if(t.length<=0)return;const o=this.doc;null!==o?rb(o,o=>{const r=ev(o,this,e,!n);n||(n={},r.currentAttributes.forEach((e,t)=>{n[t]=e})),iv(o,this,r,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const o=this.doc;null!==o?rb(o,o=>{const r=ev(o,this,e,!n);iv(o,this,r,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(0===t)return;const n=this.doc;null!==n?rb(n,n=>{dv(n,ev(n,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(0===t)return;const o=this.doc;null!==o?rb(o,o=>{const r=ev(o,this,e,!1);null!==r.right&&sv(o,this,r,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){null!==this.doc?rb(this.doc,t=>{$b(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){null!==this.doc?rb(this.doc,n=>{zb(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Fb(this,e)}getAttributes(){return Ub(this)}_write(e){e.writeTypeRef(Pv)}}class pv{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??kb()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(null!==e&&(!this._firstCall||e.deleted||!this._filter(t)))do{if(t=e.content.type,e.deleted||t.constructor!==mv&&t.constructor!==fv||null===t._start)for(;null!==e;){const t=e.next;if(null!==t){e=t;break}e=e.parent===this._root?null:e.parent._item}else e=t._start}while(null!==e&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,null===e?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class fv extends jb{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new fv}clone(){const e=new fv;return e.insert(0,this.toArray().map(e=>e instanceof jb?e.clone():e)),e}get length(){return this.doc??kb(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new pv(this,e)}querySelector(e){e=e.toUpperCase();const t=new pv(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),zf(new pv(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){Tb(this,e,new gv(this,t,e))}toString(){return Pb(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const o=e.createDocumentFragment();return void 0!==n&&n._createAssociation(o,this),_b(this,r=>{o.insertBefore(r.toDOM(e,t,n),null)}),o}insert(e,t){null!==this.doc?rb(this.doc,n=>{Hb(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)rb(this.doc,n=>{const o=e&&e instanceof jb?e._item:e;Db(n,this,o,t)});else{const n=this._prelimContent,o=null===e?0:n.findIndex(t=>t===e)+1;if(0===o&&null!==e)throw jm("Reference item not found");n.splice(o,0,...t)}}delete(e,t=1){null!==this.doc?rb(this.doc,n=>{Vb(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Ab(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Lb(this,e)}slice(e=0,t=this.length){return Nb(this,e,t)}forEach(e){_b(this,e)}_write(e){e.writeTypeRef(Lv)}}class mv extends fv{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new mv(this.nodeName)}clone(){const e=new mv(this.nodeName);return((e,t)=>{for(const n in e)t(e[n],n)})(this.getAttributes(),(t,n)=>{"string"==typeof t&&e.setAttribute(n,t)}),e.insert(0,this.toArray().map(e=>e instanceof jb?e.clone():e)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const i in e)n.push(i);n.sort();const o=n.length;for(let i=0;i<o;i++){const o=n[i];t.push(o+'="'+e[o]+'"')}const r=this.nodeName.toLocaleLowerCase();return`<${r}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${r}>`}removeAttribute(e){null!==this.doc?rb(this.doc,t=>{$b(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?rb(this.doc,n=>{zb(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Fb(this,e)}hasAttribute(e){return Wb(this,e)}getAttributes(e){return e?((e,t)=>{const n={};return e._map.forEach((e,o)=>{let r=e;for(;null!==r&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;null!==r&&$y(r,t)&&(n[o]=r.content.getContent()[r.length-1])}),n})(this,e):Ub(this)}toDOM(e=document,t={},n){const o=e.createElement(this.nodeName),r=this.getAttributes();for(const i in r){const e=r[i];"string"==typeof e&&o.setAttribute(i,e)}return _b(this,r=>{o.appendChild(r.toDOM(e,t,n))}),void 0!==n&&n._createAssociation(o,this),o}_write(e){e.writeTypeRef(Iv),e.writeKey(this.nodeName)}}class gv extends xb{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{null===e?this.childListChanged=!0:this.attributesChanged.add(e)})}}class yv extends Jb{constructor(e){super(),this.hookName=e}_copy(){return new yv(this.hookName)}clone(){const e=new yv(this.hookName);return this.forEach((t,n)=>{e.set(n,t)}),e}toDOM(e=document,t={},n){const o=t[this.hookName];let r;return r=void 0!==o?o.createDom(this):document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),void 0!==n&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Dv),e.writeKey(this.hookName)}}class bv extends hv{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new bv}clone(){const e=new bv;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,n){const o=e.createTextNode(this.toString());return void 0!==n&&n._createAssociation(o,this),o}toString(){return this.toDelta().map(e=>{const t=[];for(const o in e.attributes){const n=[];for(const t in e.attributes[o])n.push({key:t,value:e.attributes[o][t]});n.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:o,attrs:n})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n="";for(let o=0;o<t.length;o++){const e=t[o];n+=`<${e.nodeName}`;for(let t=0;t<e.attrs.length;t++){const o=e.attrs[t];n+=` ${o.key}="${o.value}"`}n+=">"}n+=e.insert;for(let o=t.length-1;o>=0;o--)n+=`</${t[o].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Bv)}}class vv{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Nm()}mergeWith(e){return!1}write(e,t,n){throw Nm()}integrate(e,t){throw Nm()}}class xv extends vv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),qy(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}}class wv{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new wv(this.content)}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class kv{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new kv(this.len)}splice(e){const t=new kv(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Jg(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const Cv=(e,t)=>new oy({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Ev{constructor(e){e._item,this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),null!==e.meta&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Ev(Cv(this.doc.guid,this.opts))}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}class Sv{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Sv(this.embed)}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class Mv{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Mv(this.key,this.value)}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}class Rv{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Rv(this.arr)}splice(e){const t=new Rv(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let o=t;o<n;o++){const t=this.arr[o];e.writeString(void 0===t?"undefined":JSON.stringify(t))}}getRef(){return 2}}const Tv="development"===bg("node_env");class jv{constructor(e){this.arr=e,Tv&&ug(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new jv(this.arr)}splice(e){const t=new jv(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let o=t;o<n;o++){const t=this.arr[o];e.writeAny(t)}}getRef(){return 8}}class Nv{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Nv(this.str)}splice(e){const t=new Nv(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(0===t?this.str:this.str.slice(t))}getRef(){return 4}}const Av=[e=>new Kb,e=>new Jb,e=>new hv,e=>new mv(e.readKey()),e=>new fv,e=>new yv(e.readKey()),e=>new bv],Ov=0,_v=1,Pv=2,Iv=3,Lv=4,Dv=5,Bv=6;class Hv{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Hv(this.type._copy())}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;null!==t;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;null!==t;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;null!==t;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const Vv=(e,t)=>{let n,o=t,r=0;do{r>0&&(o=Ty(o.client,o.clock+r)),n=Ky(e,o),r=o.clock-n.id.clock,o=n.redone}while(null!==o&&n instanceof Wv);return{item:n,diff:r}},$v=(e,t)=>{for(;null!==e&&e.keep!==t;)e.keep=t,e=e.parent._item},zv=(e,t,n)=>{const{client:o,clock:r}=t.id,i=new Wv(Ty(o,r+n),t,Ty(o,r+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),null!==t.redone&&(i.redone=Ty(t.redone.client,t.redone.clock+n)),t.right=i,null!==i.right&&(i.right.left=i),e._mergeStructs.push(i),null!==i.parentSub&&null===i.right&&i.parent._map.set(i.parentSub,i),t.length=n,i},Fv=(e,t)=>((e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1})(e,e=>Gg(e.deletions,t)),Uv=(e,t,n,o,r,i)=>{const s=e.doc,l=s.store,a=s.clientID,c=t.redone;if(null!==c)return Jy(e,c);let d,u=t.parent._item,h=null;if(null!==u&&!0===u.deleted){if(null===u.redone&&(!n.has(u)||null===Uv(e,u,n,o,r,i)))return null;for(;null!==u.redone;)u=Jy(e,u.redone)}const p=null===u?t.parent:u.content.type;if(null===t.parentSub){for(h=t.left,d=t;null!==h;){let t=h;for(;null!==t&&t.parent._item!==u;)t=null===t.redone?null:Jy(e,t.redone);if(null!==t&&t.parent._item===u){h=t;break}h=h.left}for(;null!==d;){let t=d;for(;null!==t&&t.parent._item!==u;)t=null===t.redone?null:Jy(e,t.redone);if(null!==t&&t.parent._item===u){d=t;break}d=d.right}}else if(d=null,t.right&&!r){for(h=t;null!==h&&null!==h.right&&(h.right.redone||Gg(o,h.right.id)||Fv(i.undoStack,h.right.id)||Fv(i.redoStack,h.right.id));)for(h=h.right;h.redone;)h=Jy(e,h.redone);if(h&&null!==h.right)return null}else h=p._map.get(t.parentSub)||null;const f=Wy(l,a),m=Ty(a,f),g=new Wv(m,h,h&&h.lastId,d,d&&d.id,p,t.parentSub,t.content.copy());return t.redone=m,$v(g,!0),g.integrate(e,0),g};class Wv extends vv{constructor(e,t,n,o,r,i,s,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=o,this.rightOrigin=r,this.parent=i,this.parentSub=s,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(e){(8&this.info)>0!==e&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Wy(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Wy(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===My&&this.id.client!==this.parent.client&&this.parent.clock>=Wy(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Xy(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Jy(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===xv||this.right&&this.right.constructor===xv)this.parent=null;else if(this.parent){if(this.parent.constructor===My){const e=Ky(t,this.parent);e.constructor===xv?this.parent=null:this.parent=e.content.type}}else this.left&&this.left.constructor===Wv?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Wv&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Xy(e,e.doc.store,Ty(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let t,n=this.left;if(null!==n)t=n.right;else if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start;const o=new Set,r=new Set;for(;null!==t&&t!==this.right;){if(r.add(t),o.add(t),Ry(this.origin,t.origin)){if(t.id.client<this.id.client)n=t,o.clear();else if(Ry(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!r.has(Ky(e.doc.store,t.origin)))break;o.has(Ky(e.doc.store,t.origin))||(n=t,o.clear())}t=t.right}this.left=n}if(null!==this.left){const e=this.left.right;this.right=e,this.left.right=this}else{let e;if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(e)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),qy(e.doc.store,this),this.content.integrate(e,this),tb(e,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(e)}else new xv(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;null!==e&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;null!==e&&e.deleted;)e=e.left;return e}get lastId(){return 1===this.length?this.id:Ty(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Ry(e.origin,this.lastId)&&this.right===e&&Ry(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&null===this.redone&&null===e.redone&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,null!==this.right&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&null===this.parentSub&&(t._length-=this.length),this.markDeleted(),Jg(e.deleteSet,this.id.client,this.id.clock,this.length),tb(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw Am();this.content.gc(e),t?((e,t,n)=>{const o=e.clients.get(t.id.client);o[Gy(o,t.id.clock)]=n})(e,this,new xv(this.id,this.length)):this.content=new kv(this.length)}write(e,t){const n=t>0?Ty(this.id.client,this.id.clock+t-1):this.origin,o=this.rightOrigin,r=this.parentSub,i=31&this.content.getRef()|(null===n?0:Xf)|(null===o?0:Jf)|(null===r?0:32);if(e.writeInfo(i),null!==n&&e.writeLeftID(n),null!==o&&e.writeRightID(o),null===n&&null===o){const t=this.parent;if(void 0!==t._item){const n=t._item;if(null===n){const n=jy(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===My?(e.writeParentInfo(!1),e.writeLeftID(t)):Am();null!==r&&e.writeString(r)}this.content.write(e,t)}}const qv=(e,t)=>Gv[31&t](e),Gv=[()=>{Am()},e=>new kv(e.readLen()),e=>{const t=e.readLen(),n=[];for(let o=0;o<t;o++){const t=e.readString();"undefined"===t?n.push(void 0):n.push(JSON.parse(t))}return new Rv(n)},e=>new wv(e.readBuf()),e=>new Nv(e.readString()),e=>new Sv(e.readJSON()),e=>new Mv(e.readKey(),e.readJSON()),e=>new Hv(Av[e.readTypeRef()](e)),e=>{const t=e.readLen(),n=[];for(let o=0;o<t;o++)n.push(e.readAny());return new jv(n)},e=>new Ev(Cv(e.readString(),e.readAny())),()=>{Am()}];class Kv extends vv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){Am()}write(e,t){e.writeInfo(10),pm(e.restEncoder,this.length-t)}getMissing(e,t){return null}}const Zv="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Jv="__ $YJS$ __";Zv[Jv],Zv[Jv]=!0;const Xv=/[\uD800-\uDBFF]/,Yv=/[\uDC00-\uDFFF]/,Qv=(e,t)=>{let n=0,o=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&Xv.test(e[n-1])&&n--;o+n<e.length&&o+n<t.length&&e[e.length-o-1]===t[t.length-o-1];)o++;return o>0&&Yv.test(e[e.length-o])&&o--,{index:n,remove:e.length-n-o,insert:t.slice(n,t.length-o)}},ex=new Kr("y-sync"),tx=new Kr("y-undo"),nx=new Kr("yjs-cursor"),ox=(e,t)=>e>>>t|e<<32-t,rx=e=>ox(e,2)^ox(e,13)^ox(e,22),ix=e=>ox(e,6)^ox(e,11)^ox(e,25),sx=e=>ox(e,7)^ox(e,18)^e>>>3,lx=e=>ox(e,17)^ox(e,19)^e>>>10,ax=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),cx=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class dx{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(cx),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,t=this._W;for(let d=16;d<64;d++)t[d]=lx(t[d-2])+t[d-7]+sx(t[d-15])+t[d-16];let n=e[0],o=e[1],r=e[2],i=e[3],s=e[4],l=e[5],a=e[6],c=e[7];for(let d,u,h=0;h<64;h++)d=c+ix(s)+(s&l^~s&a)+ax[h]+t[h]>>>0,u=rx(n)+(n&o^n&r^o&r)>>>0,c=a,a=l,l=s,s=i+d>>>0,i=r,r=o,o=n,n=d+u>>>0;e[0]+=n,e[1]+=o,e[2]+=r,e[3]+=i,e[4]+=s,e[5]+=l,e[6]+=a,e[7]+=c}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3<e.length;n++)this._W[n]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!=0){for(this._W.fill(0,n,16);t<e.length;)this._W[n]|=e[t]<<8*(3-t%4),t++;this._W[n]|=Xf<<8*(3-t%4)}this._updateHash()}const n=t%64!=0;this._W.fill(0,0,16);let o=0;for(;t<e.length;o++)for(let n=3;n>=0&&t<e.length;n--)this._W[o]|=e[t++]<<8*n;n||(this._W[o-(t%4==0?0:1)]|=Xf<<8*(3-t%4)),this._W[14]=e.byteLength/536870912,this._W[15]=8*e.byteLength,this._updateHash();const r=new Uint8Array(32);for(let i=0;i<this._H.length;i++)for(let e=0;e<4;e++)r[4*i+e]=this._H[i]>>>8*(3-e);return r}}const ux=e=>{return wg((e=>{for(let t=6;t<e.length;t++)e[t%6]=e[t%6]^e[t];return e.slice(0,6)})((t=Cg(e),(new dx).digest(t))));var t},hx=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Gg(t.ds,e.id),px=[{light:"#ecd44433",dark:"#ecd444"}],fx=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const n=Hf();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,(o=t)[Wf(Zm()*o.length)])}var o;return e.get(n)},mx=(e,t)=>({type:t.selection.jsonID,anchor:Dx(t.selection.anchor,e.type,e.mapping),head:Dx(t.selection.head,e.type,e.mapping)});class gx{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=(()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else void 0!==n&&n()}})(),this.mapping=t,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{null===this.beforeTransactionSelection&&null!=this.prosemirrorView&&(this.beforeTransactionSelection=mx(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return!!this.prosemirrorView.hasFocus()&&(mg&&null===this._domSelectionInView&&(jg(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView)}_isDomSelectionInView(){const e=this.prosemirrorView._root.getSelection();if(null==e||null==e.anchorNode)return!1;const t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset);0===t.getClientRects().length&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);const n=t.getBoundingClientRect(),o=Mg.documentElement;return n.bottom>=0&&n.right>=0&&n.left<=(window.innerWidth||o.clientWidth||0)&&n.top<=(window.innerHeight||o.clientHeight||0)}renderSnapshot(e,t){t||(t=Hy(Xg(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(ex,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(e=>bx(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _n(Rn.from(e),0,0));t.setMeta(ex,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const e=null!==this.beforeTransactionSelection?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(e=>bx(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _n(Rn.from(t),0,0));if(e){const t=Gf(Kf(e.anchor,0),n.doc.content.size),o=Gf(Kf(e.head,0),n.doc.content.size);n.setSelection(Nr.create(n.doc,t,o))}this.prosemirrorView.dispatch(n.setMeta(ex,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let o=this.doc,r=this.type;if(e||(e=Vy(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if(e instanceof Uint8Array&&t instanceof Uint8Array||Am(),o=new oy({gc:!1}),fy(o,t),t=Vy(o),fy(o,e),e=Vy(o),null===r._item){const e=Array.from(this.doc.share.keys()).find(e=>this.doc.share.get(e)===this.type);r=o.getXmlFragment(e)}else{const e=o.store.clients.get(r._item.id.client)??[],t=e[Gy(e,r._item.id.clock)].content;r=t.type}this.mapping.clear(),this.mux(()=>{o.transact(o=>{const i=n.permanentUserData;i&&i.dss.forEach(e=>{qg(o,e,e=>{})});const s=(e,t)=>{const o="added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t);return{user:o,type:e,color:fx(n.colorMapping,n.colors,o)}},l=Ob(r,new By(t.ds,e.sv)).map(n=>!n._item.deleted||hx(n._item,e)||hx(n._item,t)?bx(n,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,s):null).filter(e=>null!==e),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _n(Rn.from(l),0,0));this.prosemirrorView.dispatch(a.setMeta(ex,{isChangeOrigin:!0}))},ex)})}_typeChanged(e,t){if(null==this.prosemirrorView)return;const n=ex.getState(this.prosemirrorView.state);0!==e.length&&null==n.snapshot&&null==n.prevSnapshot?this.mux(()=>{const e=(e,t)=>this.mapping.delete(t);qg(t,t.deleteSet,e=>{if(e.constructor===Wv){const t=e.content.type;t&&this.mapping.delete(t)}}),t.changed.forEach(e),t.changedParentTypes.forEach(e);const n=this.type.toArray().map(e=>yx(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e);let o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _n(Rn.from(n),0,0));((e,t,n)=>{if(null!==t&&null!==t.anchor&&null!==t.head)if("all"===t.type)e.setSelection(new Pr(e.doc));else if("node"===t.type){const o=Hx(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Or.create(e.doc,o))}else{const o=Hx(n.doc,n.type,t.anchor,n.mapping),r=Hx(n.doc,n.type,t.head,n.mapping);if(null!==o&&null!==r){const t=Nr.between(e.doc.resolve(o),e.doc.resolve(r));e.setSelection(t)}}})(o,this.beforeTransactionSelection,this),o=o.setMeta(ex,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof ab}),null!==this.beforeTransactionSelection&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)}):this.renderSnapshot(n.snapshot,n.prevSnapshot)}_prosemirrorChanged(e){this.doc.transact(()=>{_x(this.doc,this.type,e,this),this.beforeTransactionSelection=mx(this,this.prosemirrorView.state)},ex)}initView(e){null!=this.prosemirrorView&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){null!=this.prosemirrorView&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const yx=(e,t,n,o,r,i)=>{const s=n.mapping.get(e);if(void 0===s){if(e instanceof mv)return bx(e,t,n,o,r,i);throw Nm()}return s},bx=(e,t,n,o,r,i)=>{const s=[],l=e=>{var l,a;if(e instanceof mv){const l=yx(e,t,n,o,r,i);null!==l&&s.push(l)}else{const c=null==(a=null==(l=e._item.right)?void 0:l.content)?void 0:a.type;c instanceof hv&&!c._item.deleted&&c._item.id.client===c.doc.clientID&&(e.applyDelta([{retain:e.length},...c.toDelta()]),c.doc.transact(e=>{c._item.delete(e)}));const d=vx(e,t,n,o,r,i);null!==d&&d.forEach(e=>{null!==e&&s.push(e)})}};void 0===o||void 0===r?e.toArray().forEach(l):Ob(e,new By(r.ds,o.sv)).forEach(l);try{const l=e.getAttributes(o);void 0!==o&&(hx(e._item,o)?hx(e._item,r)||(l.ychange=i?i("added",e._item.id):{type:"added"}):l.ychange=i?i("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,l,s);return n.mapping.set(e,a),a}catch(VD){return e.doc.transact(t=>{e._item.delete(t)},ex),n.mapping.delete(e),null}},vx=(e,t,n,o,r,i)=>{const s=[],l=e.toDelta(o,r,i);try{for(let e=0;e<l.length;e++){const n=l[e];s.push(t.text(n.insert,Ax(n.attributes,t)))}}catch(VD){return e.doc.transact(t=>{e._item.delete(t)},ex),null}return s},xx=(e,t)=>e instanceof Array?((e,t)=>{const n=new bv,o=e.map(e=>({insert:e.text,attributes:Ox(e.marks,t)}));return n.applyDelta(o),t.mapping.set(n,e),n})(e,t):((e,t)=>{const n=new mv(e.type.name);for(const o in e.attrs){const t=e.attrs[o];null!==t&&"ychange"!==o&&n.setAttribute(o,t)}return n.insert(0,Cx(e).map(e=>xx(e,t))),t.mapping.set(n,e),n})(e,t),wx=e=>"object"==typeof e&&null!==e,kx=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);let o=n.length===(null==t?0:Object.keys(t).filter(e=>null!==t[e]).length);for(let r=0;r<n.length&&o;r++){const i=n[r],s=e[i],l=t[i];o="ychange"===i||s===l||wx(s)&&wx(l)&&kx(s,l)}return o},Cx=e=>{const t=e.content.content,n=[];for(let o=0;o<t.length;o++){const e=t[o];if(e.isText){const e=[];for(let n=t[o];o<t.length&&n.isText;n=t[++o])e.push(n);o--,n.push(e)}else n.push(e)}return n},Ex=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&sg(e.attributes||{}).length===t[n].marks.length&&ag(e.attributes,(e,o)=>{var r;const i=Nx(o),s=t[n].marks;return kx(e,null==(r=s.find(e=>e.type.name===i))?void 0:r.attrs)}))},Sx=(e,t)=>{if(e instanceof mv&&!(t instanceof Array)&&Px(e,t)){const n=Cx(t);return e._length===n.length&&kx(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>Sx(e,n[t]))}return e instanceof bv&&t instanceof Array&&Ex(e,t)},Mx=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Rx=(e,t,n)=>{const o=e.toArray(),r=Cx(t),i=r.length,s=o.length,l=Gf(s,i);let a=0,c=0,d=!1;for(;a<l;a++){const e=o[a],t=r[a];if(Mx(n.mapping.get(e),t))d=!0;else if(!Sx(e,t))break}for(;a+c<l;c++){const e=o[s-c-1],t=r[i-c-1];if(Mx(n.mapping.get(e),t))d=!0;else if(!Sx(e,t))break}return{equalityFactor:a+c,foundMappedChild:d}},Tx=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:o,str:r}=(e=>{let t="",n=e._start;const o={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof Nv?t+=n.content.str:n.content instanceof Mv&&(o[n.content.key]=null)),n=n.right;return{str:t,nAttrs:o}})(e),i=t.map(e=>({insert:e.text,attributes:Object.assign({},o,Ox(e.marks,n))})),{insert:s,remove:l,index:a}=Qv(r,i.map(e=>e.insert).join(""));e.delete(a,l),e.insert(a,s),e.applyDelta(i.map(e=>({retain:e.insert.length,attributes:e.attributes})))},jx=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Nx=e=>{var t;return(null==(t=jx.exec(e))?void 0:t[1])??e},Ax=(e,t)=>{const n=[];for(const o in e)n.push(t.mark(Nx(o),e[o]));return n},Ox=(e,t)=>{const n={};return e.forEach(e=>{if("ychange"!==e.type.name){const o=Bf(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[o?`${e.type.name}--${ux(e.toJSON())}`:e.type.name]=e.attrs}}),n},_x=(e,t,n,o)=>{if(t instanceof mv&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(o.mapping.set(t,n),t instanceof mv){const e=t.getAttributes(),o=n.attrs;for(const n in o)null!==o[n]?e[n]!==o[n]&&"ychange"!==n&&t.setAttribute(n,o[n]):t.removeAttribute(n);for(const n in e)void 0===o[n]&&t.removeAttribute(n)}const r=Cx(n),i=r.length,s=t.toArray(),l=s.length,a=Gf(i,l);let c=0,d=0;for(;c<a;c++){const e=s[c],t=r[c];if(!Mx(o.mapping.get(e),t)){if(!Sx(e,t))break;o.mapping.set(e,t)}}for(;d+c<a;d++){const e=s[l-d-1],t=r[i-d-1];if(!Mx(o.mapping.get(e),t)){if(!Sx(e,t))break;o.mapping.set(e,t)}}e.transact(()=>{for(;l-c-d>0&&i-c-d>0;){const n=s[c],a=r[c],u=s[l-d-1],h=r[i-d-1];if(n instanceof bv&&a instanceof Array)Ex(n,a)||Tx(n,a,o),c+=1;else{let r=n instanceof mv&&Px(n,a),i=u instanceof mv&&Px(u,h);if(r&&i){const e=Rx(n,a,o),t=Rx(u,h,o);e.foundMappedChild&&!t.foundMappedChild?i=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?r=!1:i=!1}r?(_x(e,n,a,o),c+=1):i?(_x(e,u,h,o),d+=1):(o.mapping.delete(t.get(c)),t.delete(c,1),t.insert(c,[xx(a,o)]),c+=1)}}const n=l-c-d;if(1===l&&0===i&&s[0]instanceof bv?(o.mapping.delete(s[0]),s[0].delete(0,s[0].length)):n>0&&(t.slice(c,c+n).forEach(e=>o.mapping.delete(e)),t.delete(c,n)),c+d<i){const e=[];for(let t=c;t<i-d;t++)e.push(xx(r[t],o));t.insert(c,e)}},ex)},Px=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name;let Ix=null;const Lx=()=>{const e=Ix;Ix=null,e.forEach((e,t)=>{const n=t.state.tr,o=ex.getState(t.state);o&&o.binding&&!o.binding.isDestroyed&&(e.forEach((e,t)=>{n.setMeta(t,e)}),t.dispatch(n))})},Dx=(e,t,n)=>{if(0===e)return Iy(t,0,0===t.length?-1:0);let o=null===t._first?null:t._first.content.type;for(;null!==o&&t!==o;){if(o instanceof bv){if(o._length>=e)return Iy(o,e,0===t.length?-1:0);if(e-=o._length,null!==o._item&&null!==o._item.next)o=o._item.next.content.type;else{do{o=null===o._item?null:o._item.parent,e--}while(o!==t&&null!==o&&null!==o._item&&null===o._item.next);null!==o&&o!==t&&(o=null===o._item?null:o._item.next.content.type)}}else{const r=(n.get(o)||{nodeSize:0}).nodeSize;if(null!==o._first&&e<r)o=o._first.content.type,e--;else{if(1===e&&0===o._length&&r>1)return new Ay(null===o._item?null:o._item.id,null===o._item?jy(o):null,null);if(e-=r,null!==o._item&&null!==o._item.next)o=o._item.next.content.type;else{if(0===e)return o=null===o._item?o:o._item.parent,new Ay(null===o._item?null:o._item.id,null===o._item?jy(o):null,null);do{o=o._item.parent,e--}while(o!==t&&null===o._item.next);o!==t&&(o=o._item.next.content.type)}}}if(null===o)throw Am();if(0===e&&o.constructor!==bv&&o!==t)return Bx(o._item.parent,o._item)}return Iy(t,t._length,0===t.length?-1:0)},Bx=(e,t)=>{let n=null,o=null;return null===e._item?o=jy(e):n=Ty(e._item.id.client,e._item.id.clock),new Ay(n,o,t.id)},Hx=(e,t,n,o)=>{const r=Ly(n,e);if(null===r||r.type!==t&&!Ny(t,r.type._item))return null;let i=r.type,s=0;if(i.constructor===bv)s=r.index;else if(null===i._item||!i._item.deleted){let e=i._first,t=0;for(;t<i._length&&t<r.index&&null!==e;){if(!e.deleted){const n=e.content.type;t++,s+=n instanceof bv?n._length:o.get(n).nodeSize}e=e.right}s+=1}for(;i!==t&&null!==i._item;){const e=i._item.parent;if(null===e._item||!e._item.deleted){s+=1;let t=e._first;for(;null!==t;){const e=t.content.type;if(e===i)break;t.deleted||(s+=e instanceof bv?e._length:o.get(e).nodeSize),t=t.right}}i=e}return s-1},Vx=(e,t,n)=>e!==t,$x=e=>{const t=document.createElement("span");t.classList.add("ProseMirror-yjs-cursor"),t.setAttribute("style",`border-color: ${e.color}`);const n=document.createElement("div");n.setAttribute("style",`background-color: ${e.color}`),n.insertBefore(document.createTextNode(e.name),null);const o=document.createTextNode("⁠"),r=document.createTextNode("⁠");return t.insertBefore(o,null),t.insertBefore(n,null),t.insertBefore(r,null),t},zx=e=>({style:`background-color: ${e.color}70`,class:"ProseMirror-yjs-selection"}),Fx=/^#[0-9a-fA-F]{6}$/,Ux=(e,t,n,o,r)=>{const i=ex.getState(e),s=i.doc,l=[];return null!=i.snapshot||null!=i.prevSnapshot||0===i.binding.mapping.size?Il.create(e.doc,[]):(t.getStates().forEach((t,a)=>{if(n(s.clientID,a,t)&&null!=t.cursor){const n=t.user||{};null==n.color?n.color="#ffa500":Fx.test(n.color),null==n.name&&(n.name=`User: ${a}`);let c=Hx(s,i.type,Oy(t.cursor.anchor),i.binding.mapping),d=Hx(s,i.type,Oy(t.cursor.head),i.binding.mapping);if(null!==c&&null!==d){const t=Kf(e.doc.content.size-1,0);c=Gf(c,t),d=Gf(d,t),l.push(Ol.widget(d,()=>o(n,a),{key:a+"",side:10}));const i=Gf(c,d),s=Kf(c,d);l.push(Ol.inline(i,s,r(n,a),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),Il.create(e.doc,l))},Wx=(e,{awarenessStateFilter:t=Vx,cursorBuilder:n=$x,selectionBuilder:o=zx,getSelection:r=e=>e.selection}={},i="cursor")=>new Wr({key:nx,state:{init:(r,i)=>Ux(i,e,t,n,o),apply(r,i,s,l){const a=ex.getState(l),c=r.getMeta(nx);return a&&a.isChangeOrigin||c&&c.awarenessUpdated?Ux(l,e,t,n,o):i.map(r.mapping,r.doc)}},props:{decorations:e=>nx.getState(e)},view:t=>{const n=()=>{t.docView&&((e,t,n)=>{Ix||(Ix=new Map,jg(0,Lx)),Bf(Ix,e,Lf).set(t,n)})(t,nx,{awarenessUpdated:!0})},o=()=>{const n=ex.getState(t.state),o=e.getLocalState()||{};if(t.hasFocus()){const s=r(t.state),l=Dx(s.anchor,n.type,n.binding.mapping),a=Dx(s.head,n.type,n.binding.mapping);null!=o.cursor&&Dy(Oy(o.cursor.anchor),l)&&Dy(Oy(o.cursor.head),a)||e.setLocalStateField(i,{anchor:l,head:a})}else null!=o.cursor&&null!==Hx(n.doc,n.type,Oy(o.cursor.anchor),n.binding.mapping)&&e.setLocalStateField(i,null)};return e.on("change",n),t.dom.addEventListener("focusin",o),t.dom.addEventListener("focusout",o),{update:o,destroy:()=>{t.dom.removeEventListener("focusin",o),t.dom.removeEventListener("focusout",o),e.off("change",n),e.setLocalStateField(i,null)}}}}),qx=(e,t)=>{var n,o;return null==t?null==(o=null==(n=tx.getState(e))?void 0:n.undoManager)?void 0:o.canUndo():(e=>{var t,n;return null!=(null==(n=null==(t=tx.getState(e))?void 0:t.undoManager)?void 0:n.undo())})(e)},Gx=(e,t)=>{var n,o;return null==t?null==(o=null==(n=tx.getState(e))?void 0:n.undoManager)?void 0:o.canRedo():(e=>{var t,n;return null!=(null==(n=null==(t=tx.getState(e))?void 0:t.undoManager)?void 0:n.redo())})(e)},Kx=new Set(["paragraph"]),Zx=({protectedNodes:e=Kx,trackedOrigins:t=[],undoManager:n=null}={})=>new Wr({key:tx,state:{init:(o,r)=>{const i=ex.getState(r),s=n||new ab(i.type,{trackedOrigins:new Set([ex].concat(t)),deleteFilter:t=>((e,t)=>!(e instanceof Wv&&e.content instanceof Hv&&(e.content.type instanceof hv||e.content.type instanceof mv&&t.has(e.content.type.nodeName))&&0!==e.content.type._length))(t,e),captureTransaction:e=>!1!==e.meta.get("addToHistory")});return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0}},apply:(e,t,n,o)=>{const r=ex.getState(o).binding,i=t.undoManager,s=i.undoStack.length>0,l=i.redoStack.length>0;return r?{undoManager:i,prevSel:mx(r,n),hasUndoOps:s,hasRedoOps:l}:s!==t.hasUndoOps||l!==t.hasRedoOps?Object.assign({},t,{hasUndoOps:i.undoStack.length>0,hasRedoOps:i.redoStack.length>0}):t}},view:e=>{const t=ex.getState(e.state),n=tx.getState(e.state).undoManager;return n.on("stack-item-added",({stackItem:n})=>{const o=t.binding;o&&n.meta.set(o,tx.getState(e.state).prevSel)}),n.on("stack-item-popped",({stackItem:e})=>{const n=t.binding;n&&(n.beforeTransactionSelection=e.meta.get(n)||n.beforeTransactionSelection)}),{destroy:()=>{n.destroy()}}}});function Jx(e={}){return new Wr({view:t=>new Xx(t,e)})}class Xx{constructor(e,t){var n;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=null!==(n=t.width)&&void 0!==n?n:1,this.color=!1===t.color?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.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){null!=this.cursorPos&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,null==e?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e,t=this.editorView.state.doc.resolve(this.cursorPos),n=!t.parent.inlineContent,o=this.editorView.dom,r=o.getBoundingClientRect(),i=r.width/o.offsetWidth,s=r.height/o.offsetHeight;if(n){let n=t.nodeBefore,o=t.nodeAfter;if(n||o){let t=this.editorView.nodeDOM(this.cursorPos-(n?n.nodeSize:0));if(t){let r=t.getBoundingClientRect(),i=n?r.bottom:r.top;n&&o&&(i=(i+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let l=this.width/2*s;e={left:r.left,right:r.right,top:i-l,bottom:i+l}}}}if(!e){let t=this.editorView.coordsAtPos(this.cursorPos),n=this.width/2*i;e={left:t.left-n,right:t.left+n,top:t.top,bottom:t.bottom}}let l,a,c=this.editorView.dom.offsetParent;if(this.element||(this.element=c.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",n),this.element.classList.toggle("prosemirror-dropcursor-inline",!n),!c||c==document.body&&"static"==getComputedStyle(c).position)l=-pageXOffset,a=-pageYOffset;else{let e=c.getBoundingClientRect(),t=e.width/c.offsetWidth,n=e.height/c.offsetHeight;l=e.left-c.scrollLeft*t,a=e.top-c.scrollTop*n}this.element.style.left=(e.left-l)/i+"px",this.element.style.top=(e.top-a)/s+"px",this.element.style.width=(e.right-e.left)/i+"px",this.element.style.height=(e.bottom-e.top)/s+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),o=n&&n.type.spec.disableDropCursor,r="function"==typeof o?o(this.editorView,t,e):o;if(t&&!r){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=cr(this.editorView.state.doc,e,this.editorView.dragging.slice);null!=t&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}const Yx={slash_menu:{heading:{title:"Heading 1",subtext:"Top-level heading",aliases:["h","heading1","h1"],group:"Headings"},heading_2:{title:"Heading 2",subtext:"Key section heading",aliases:["h2","heading2","subheading"],group:"Headings"},heading_3:{title:"Heading 3",subtext:"Subsection and group heading",aliases:["h3","heading3","subheading"],group:"Headings"},heading_4:{title:"Heading 4",subtext:"Minor subsection heading",aliases:["h4","heading4","subheading4"],group:"Subheadings"},heading_5:{title:"Heading 5",subtext:"Small subsection heading",aliases:["h5","heading5","subheading5"],group:"Subheadings"},heading_6:{title:"Heading 6",subtext:"Lowest-level heading",aliases:["h6","heading6","subheading6"],group:"Subheadings"},toggle_heading:{title:"Toggle Heading 1",subtext:"Toggleable top-level heading",aliases:["h","heading1","h1","collapsable"],group:"Subheadings"},toggle_heading_2:{title:"Toggle Heading 2",subtext:"Toggleable key section heading",aliases:["h2","heading2","subheading","collapsable"],group:"Subheadings"},toggle_heading_3:{title:"Toggle Heading 3",subtext:"Toggleable subsection and group heading",aliases:["h3","heading3","subheading","collapsable"],group:"Subheadings"},quote:{title:"Quote",subtext:"Quote or excerpt",aliases:["quotation","blockquote","bq"],group:"Basic blocks"},toggle_list:{title:"Toggle List",subtext:"List with hideable sub-items",aliases:["li","list","toggleList","toggle list","collapsable list"],group:"Basic blocks"},numbered_list:{title:"Numbered List",subtext:"List with ordered items",aliases:["ol","li","list","numberedlist","numbered list"],group:"Basic blocks"},bullet_list:{title:"Bullet List",subtext:"List with unordered items",aliases:["ul","li","list","bulletlist","bullet list"],group:"Basic blocks"},check_list:{title:"Check List",subtext:"List with checkboxes",aliases:["ul","li","list","checklist","check list","checked list","checkbox"],group:"Basic blocks"},paragraph:{title:"Paragraph",subtext:"The body of your document",aliases:["p","paragraph"],group:"Basic blocks"},code_block:{title:"Code Block",subtext:"Code block with syntax highlighting",aliases:["code","pre"],group:"Basic blocks"},page_break:{title:"Page Break",subtext:"Page separator",aliases:["page","break","separator"],group:"Basic blocks"},table:{title:"Table",subtext:"Table with editable cells",aliases:["table"],group:"Advanced"},image:{title:"Image",subtext:"Resizable image with caption",aliases:["image","imageUpload","upload","img","picture","media","url"],group:"Media"},video:{title:"Video",subtext:"Resizable video with caption",aliases:["video","videoUpload","upload","mp4","film","media","url"],group:"Media"},audio:{title:"Audio",subtext:"Embedded audio with caption",aliases:["audio","audioUpload","upload","mp3","sound","media","url"],group:"Media"},file:{title:"File",subtext:"Embedded file",aliases:["file","upload","embed","media","url"],group:"Media"},emoji:{title:"Emoji",subtext:"Search for and insert an emoji",aliases:["emoji","emote","emotion","face"],group:"Others"}},placeholders:{default:"Enter text or type '/' for commands",heading:"Heading",toggleListItem:"Toggle",bulletListItem:"List",numberedListItem:"List",checkListItem:"List",emptyDocument:void 0,new_comment:"Write a comment...",edit_comment:"Edit comment...",comment_reply:"Add comment..."},file_blocks:{image:{add_button_text:"Add image"},video:{add_button_text:"Add video"},audio:{add_button_text:"Add audio"},file:{add_button_text:"Add file"}},toggle_blocks:{add_block_button:"Empty toggle. Click to add a block."},side_menu:{add_block_label:"Add block",drag_handle_label:"Open block menu"},drag_handle:{delete_menuitem:"Delete",colors_menuitem:"Colors",header_row_menuitem:"Header row",header_column_menuitem:"Header column"},table_handle:{delete_column_menuitem:"Delete column",delete_row_menuitem:"Delete row",add_left_menuitem:"Add column left",add_right_menuitem:"Add column right",add_above_menuitem:"Add row above",add_below_menuitem:"Add row below",split_cell_menuitem:"Split cell",merge_cells_menuitem:"Merge cells",background_color_menuitem:"Background color"},suggestion_menu:{no_items_title:"No items found"},color_picker:{text_title:"Text",background_title:"Background",colors:{default:"Default",gray:"Gray",brown:"Brown",red:"Red",orange:"Orange",yellow:"Yellow",green:"Green",blue:"Blue",purple:"Purple",pink:"Pink"}},formatting_toolbar:{bold:{tooltip:"Bold",secondary_tooltip:"Mod+B"},italic:{tooltip:"Italic",secondary_tooltip:"Mod+I"},underline:{tooltip:"Underline",secondary_tooltip:"Mod+U"},strike:{tooltip:"Strike",secondary_tooltip:"Mod+Shift+S"},code:{tooltip:"Code",secondary_tooltip:""},colors:{tooltip:"Colors"},link:{tooltip:"Create link",secondary_tooltip:"Mod+K"},file_caption:{tooltip:"Edit caption",input_placeholder:"Edit caption"},file_replace:{tooltip:{image:"Replace image",video:"Replace video",audio:"Replace audio",file:"Replace file"}},file_rename:{tooltip:{image:"Rename image",video:"Rename video",audio:"Rename audio",file:"Rename file"},input_placeholder:{image:"Rename image",video:"Rename video",audio:"Rename audio",file:"Rename file"}},file_download:{tooltip:{image:"Download image",video:"Download video",audio:"Download audio",file:"Download file"}},file_delete:{tooltip:{image:"Delete image",video:"Delete video",audio:"Delete audio",file:"Delete file"}},file_preview_toggle:{tooltip:"Toggle preview"},nest:{tooltip:"Nest block",secondary_tooltip:"Tab"},unnest:{tooltip:"Unnest block",secondary_tooltip:"Shift+Tab"},align_left:{tooltip:"Align text left"},align_center:{tooltip:"Align text center"},align_right:{tooltip:"Align text right"},align_justify:{tooltip:"Justify text"},table_cell_merge:{tooltip:"Merge cells"},comment:{tooltip:"Add comment"}},file_panel:{upload:{title:"Upload",file_placeholder:{image:"Upload image",video:"Upload video",audio:"Upload audio",file:"Upload file"},upload_error:"Error: Upload failed"},embed:{title:"Embed",embed_button:{image:"Embed image",video:"Embed video",audio:"Embed audio",file:"Embed file"},url_placeholder:"Enter URL"}},link_toolbar:{delete:{tooltip:"Remove link"},edit:{text:"Edit link",tooltip:"Edit"},open:{tooltip:"Open in new tab"},form:{title_placeholder:"Edit title",url_placeholder:"Edit URL"}},comments:{edited:"edited",save_button_text:"Save",cancel_button_text:"Cancel",actions:{add_reaction:"Add reaction",resolve:"Resolve",edit_comment:"Edit comment",delete_comment:"Delete comment",more_actions:"More actions"},reactions:{reacted_by:"Reacted by"},sidebar:{marked_as_resolved:"Marked as resolved",more_replies:e=>`${e} more replies`}},generic:{ctrl_shortcut:"Ctrl"}};var Qx=Object.defineProperty,ew=(e,t,n)=>((e,t,n)=>t in e?Qx(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);function tw(e){return function(e,t=JSON.stringify){const n={};return e.filter(e=>{const o=t(e);return!Object.prototype.hasOwnProperty.call(n,o)&&(n[o]=!0)})}(e.filter((t,n)=>e.indexOf(t)!==n))}const nw=kc.create({name:"uniqueID",priority:1e4,addOptions:()=>({attributeName:"id",types:[],setIdAttribute:!1,generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const e=window.__TEST_OPTIONS;return void 0===e.mockID?e.mockID=0:e.mockID++,e.mockID.toString()}return Pd()},filterTransaction:null}),addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:e=>e.getAttribute(`data-${this.options.attributeName}`),renderHTML:e=>{const t={[`data-${this.options.attributeName}`]:e[this.options.attributeName]};return this.options.setIdAttribute?{...t,id:e[this.options.attributeName]}:t}}}}]},addProseMirrorPlugins(){let e=null,t=!1;return[new Wr({key:new Kr("uniqueID"),appendTransaction:(e,t,n)=>{const o=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),r=this.options.filterTransaction&&e.some(e=>{let t,n;return!(null!==(n=(t=this.options).filterTransaction)&&void 0!==n&&n.call(t,e))});if(!o||r)return;const{tr:i}=n,{types:s,attributeName:l,generateID:a}=this.options,c=qc(t.doc,e),{mapping:d}=c;return Yc(c).forEach(({newRange:e})=>{const o=Kc(n.doc,e,e=>s.includes(e.type.name)),r=tw(o.map(({node:e})=>e.attrs[l]).filter(e=>null!==e));o.forEach(({node:e,pos:o})=>{let s;const c=null===(s=i.doc.nodeAt(o))||void 0===s?void 0:s.attrs[l];if(null===c){const r=t.doc.type.createAndFill().content;if(null===t.doc.content.findDiffStart(r)){const t=JSON.parse(JSON.stringify(n.doc.toJSON()));if(t.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(t.content)===JSON.stringify(r.toJSON()))return void i.setNodeMarkup(o,void 0,{...e.attrs,[l]:"initialBlockId"})}return void i.setNodeMarkup(o,void 0,{...e.attrs,[l]:a()})}const{deleted:u}=d.invert().mapResult(o);u&&r.includes(c)&&i.setNodeMarkup(o,void 0,{...e.attrs,[l]:a()})})}),i.steps.length?i:void 0},view(t){const n=n=>{let o;e=null!==(o=t.dom.parentElement)&&void 0!==o&&o.contains(n.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(n,o)=>{let r;return t=e!==n.dom.parentElement||"copy"===(null===(r=o.dataTransfer)||void 0===r?void 0:r.effectAllowed),e=null,!1},paste:()=>(t=!0,!1)},transformPasted:e=>{if(!t)return e;const{types:n,attributeName:o}=this.options,r=e=>{const t=[];return e.forEach(e=>{if(e.isText)return void t.push(e);if(!n.includes(e.type.name))return void t.push(e.copy(r(e.content)));const i=e.type.create({...e.attrs,[o]:null},r(e.content),e.marks);t.push(i)}),Rn.from(t)};return t=!1,new _n(r(e.content),e.openStart,e.openEnd)}}})]}});function ow(e){return"link"===e.type}function rw(e){return"string"!=typeof e&&"link"===e.type}function iw(e){return"string"!=typeof e&&"text"===e.type}function sw(e){var t,n,o,r,i;return aw(e)?{...e}:lw(e)?{type:"tableCell",content:[].concat(e.content),props:{backgroundColor:(null==(t=e.props)?void 0:t.backgroundColor)??"default",textColor:(null==(n=e.props)?void 0:n.textColor)??"default",textAlignment:(null==(o=e.props)?void 0:o.textAlignment)??"left",colspan:(null==(r=e.props)?void 0:r.colspan)??1,rowspan:(null==(i=e.props)?void 0:i.rowspan)??1}}:{type:"tableCell",content:[].concat(e),props:{backgroundColor:"default",textColor:"default",textAlignment:"left",colspan:1,rowspan:1}}}function lw(e){return null!=e&&"string"!=typeof e&&!Array.isArray(e)&&"tableCell"===e.type}function aw(e){return lw(e)&&void 0!==e.props&&void 0!==e.content}function cw(e){return aw(e)?e.props.colspan??1:1}function dw(e){return aw(e)?e.props.rowspan??1:1}class uw extends Error{constructor(e){super(`Unreachable case: ${e}`)}}function hw(e,t=!0){const{"data-test":n,...o}=e;if(Object.keys(o).length>0&&t)throw new Error("Object must be empty "+JSON.stringify(e))}function pw(e,t="Ctrl"){return typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent))?e.replace("Mod","⌘"):e.replace("Mod",t)}function fw(...e){return[...new Set(e.filter(e=>e).join(" ").split(" "))].join(" ")}const mw=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function gw(e,t,n,o){const r=document.createElement("div");r.className=fw("bn-block-content",n.class),r.setAttribute("data-content-type",e);for(const[s,l]of Object.entries(n))"class"!==s&&r.setAttribute(s,l);const i=document.createElement(t);i.className=fw("bn-inline-content",o.class);for(const[s,l]of Object.entries(o))"class"!==s&&i.setAttribute(s,l);return r.appendChild(i),{dom:r,contentDOM:i}}const yw=(e,t)=>{let n=pk(e,t.pmSchema);"blockContainer"===n.type.name&&(n=n.firstChild);const o=t.pmSchema.nodes[n.type.name].spec.toDOM;if(void 0===o)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const r=o(n);if("object"!=typeof r||!("dom"in r))throw new Error("Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.");return r};const bw={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},vw=["backgroundColor","textColor"];function xw(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ww(e){const t=e.split("/");return t.length&&""!==t[t.length-1]?t[t.length-1]:e}function kw(e){const t={};return Object.entries(e).filter(([e,t])=>!vw.includes(e)).forEach(([e,n])=>{t[e]={default:n.default,keepOnSplit:!0,parseHTML:t=>{const o=t.getAttribute(xw(e));if(null===o)return null;if(void 0===n.default&&"boolean"===n.type||void 0!==n.default&&"boolean"==typeof n.default)return"true"===o||"false"!==o&&null;if(void 0===n.default&&"number"===n.type||void 0!==n.default&&"number"==typeof n.default){const e=parseFloat(o);return!Number.isNaN(e)&&Number.isFinite(e)?e:null}return o},renderHTML:t=>t[e]!==n.default?{[xw(e)]:t[e]}:{}}}),t}function Cw(e,t,n,o){if("boolean"==typeof e)throw new Error("Cannot find node position as getPos is a boolean, not a function.");const r=e(),i=n.state.doc.resolve(r).node().attrs.id;if(!i)throw new Error("Block doesn't have id");const s=t.getBlock(i);if(s.type!==o)throw new Error("Block type does not match");return s}function Ew(e,t,n,o,r=!1,i){const s=document.createElement("div");if(void 0!==i)for(const[l,a]of Object.entries(i))"class"!==l&&s.setAttribute(l,a);s.className=fw("bn-block-content",(null==i?void 0:i.class)||""),s.setAttribute("data-content-type",t);for(const[l,a]of Object.entries(n)){const e=o[l].default;!vw.includes(l)&&a!==e&&s.setAttribute(xw(l),a)}return r&&s.setAttribute("data-file-block",""),s.appendChild(e.dom),void 0!==e.contentDOM&&(e.contentDOM.className=fw("bn-inline-content",e.contentDOM.className)),{...e,dom:s}}function Sw(e){return kd.create(e)}function Mw(e,t){return{config:e,implementation:t}}function Rw(e,t,n){return Mw({type:e.name,content:"inline*"===e.config.content?"inline":"tableRow+"===e.config.content?"table":"none",propSchema:t},{node:e,requiredExtensions:n,toInternalHTML:yw,toExternalHTML:yw})}function Tw(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.config]))}function jw(e,t){e.stopEvent=e=>("mousedown"===e.type&&setTimeout(()=>{t.view.dom.blur()},10),!0)}function Nw(e,t){const n=[{tag:"[data-content-type="+e.type+"]",contentElement:".bn-inline-content"}];return t&&n.push({tag:"*",getAttrs(e){if("string"==typeof e)return!1;const n=null==t?void 0:t(e);return void 0!==n&&n}}),n}function Aw(e,t){const n=Sw({name:e.type,content:"inline"===e.content?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes:()=>kw(e.propSchema),parseHTML:()=>Nw(e,t.parse),renderHTML({HTMLAttributes:t}){const n=document.createElement("div");return Ew({dom:n,contentDOM:"inline"===e.content?n:void 0},e.type,{},e.propSchema,e.isFileBlock,t)},addNodeView(){return({getPos:n})=>{var o;const r=this.options.editor,i=Cw(n,r,this.editor,e.type),s=(null==(o=this.options.domAttributes)?void 0:o.blockContent)||{},l=Ew(t.render(i,r),i.type,i.props,e.propSchema,e.isFileBlock,s);return!1===e.isSelectable&&jw(l,this.editor),l}}});if(n.name!==e.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return Mw(e,{node:n,toInternalHTML:(o,r)=>{var i;const s=(null==(i=n.options.domAttributes)?void 0:i.blockContent)||{};return Ew(t.render(o,r),o.type,o.props,e.propSchema,e.isFileBlock,s)},toExternalHTML:(o,r)=>{var i,s;const l=(null==(i=n.options.domAttributes)?void 0:i.blockContent)||{};let a=null==(s=t.toExternalHTML)?void 0:s.call(t,o,r);return void 0===a&&(a=t.render(o,r)),Ew(a,o.type,o.props,e.propSchema,l)}})}function Ow(e,t){const n=e.resolve(t);if(n.nodeAfter&&n.nodeAfter.type.isInGroup("bnBlock"))return{posBeforeNode:n.pos,node:n.nodeAfter};let o=n.depth,r=n.node(o);for(;o>0;){if(r.type.isInGroup("bnBlock"))return{posBeforeNode:n.before(o),node:r};o--,r=n.node(o)}const i=[];e.descendants((e,t)=>{e.type.isInGroup("bnBlock")&&i.push(t)});const s=e.resolve(i.find(e=>e>=t)||i[i.length-1]);return{posBeforeNode:s.pos,node:s.nodeAfter}}function _w(e,t){if(!e.type.isInGroup("bnBlock"))throw new Error(`Attempted to get bnBlock node at position but found node of different type ${e.type.name}`);const n=e,o=t,r=o+n.nodeSize,i={node:n,beforePos:o,afterPos:r};if("blockContainer"===n.type.name){let e,t;if(n.forEach((n,r)=>{if("blockContent"===n.type.spec.group){const t=n,i=o+r+1,s=i+n.nodeSize;e={node:t,beforePos:i,afterPos:s}}else if("blockGroup"===n.type.name){const e=n,i=o+r+1,s=i+n.nodeSize;t={node:e,beforePos:i,afterPos:s}}}),!e)throw new Error(`blockContainer node does not contain a blockContent node in its children: ${n}`);return{isBlockContainer:!0,bnBlock:i,blockContent:e,childContainer:t,blockNoteType:e.node.type.name}}if(!i.node.type.isInGroup("childContainer"))throw new Error(`bnBlock node is not in the childContainer group: ${i.node}`);return{isBlockContainer:!1,bnBlock:i,childContainer:i,blockNoteType:i.node.type.name}}function Pw(e){return _w(e.node,e.posBeforeNode)}function Iw(e){if(!e.nodeAfter)throw new Error(`Attempted to get blockContainer node at position ${e.pos} but a node at this position does not exist`);return _w(e.nodeAfter,e.pos)}function Lw(e){return Pw(Ow(e.doc,e.selection.anchor))}function Dw(e){return Pw(Ow(e.doc,e.selection.anchor))}function Bw(e){return"doc"in e?e.doc.type.schema:e.type.schema}function Hw(e){return e.cached.blockNoteEditor}function Vw(e){return Hw(e).schema}function $w(e){return Vw(e).blockSchema}function zw(e){return Vw(e).inlineContentSchema}function Fw(e){return Vw(e).styleSchema}function Uw(e){return Hw(e).blockCache}function Ww(e,t,n){var o,r;const i={type:"tableContent",columnWidths:[],headerRows:void 0,headerCols:void 0,rows:[]},s=[];e.content.forEach((e,o,r)=>{const l={cells:[]};0===r&&e.content.forEach(e=>{let t=e.attrs.colwidth;null==t&&(t=new Array(e.attrs.colspan??1).fill(void 0)),i.columnWidths.push(...t)}),l.cells=e.content.content.map((e,o)=>(s[r]||(s[r]=[]),s[r][o]="tableHeader"===e.type.name,{type:"tableCell",content:e.content.content.map(e=>qw(e,t,n)).reduce((e,t)=>{if(!e.length)return t;const n=e[e.length-1],o=t[0];return o&&iw(n)&&iw(o)&&JSON.stringify(n.styles)===JSON.stringify(o.styles)?(n.text+="\n"+o.text,e.push(...t.slice(1)),e):(e.push(...t),e)},[]),props:{colspan:e.attrs.colspan,rowspan:e.attrs.rowspan,backgroundColor:e.attrs.backgroundColor,textColor:e.attrs.textColor,textAlignment:e.attrs.textAlignment}})),i.rows.push(l)});for(let l=0;l<s.length;l++)null!=(o=s[l])&&o.every(e=>e)&&(i.headerRows=(i.headerRows??0)+1);for(let l=0;l<(null==(r=s[0])?void 0:r.length);l++)null!=s&&s.every(e=>e[l])&&(i.headerCols=(i.headerCols??0)+1);return i}function qw(e,t,n){const o=[];let r;return e.content.forEach(e=>{if("hardBreak"===e.type.name){if(r)if(iw(r))r.text+="\n";else{if(!ow(r))throw new Error("unexpected");r.content[r.content.length-1].text+="\n"}else r={type:"text",text:"\n",styles:{}};return}if("link"!==e.type.name&&"text"!==e.type.name){if(!t[e.type.name])return;return r&&(o.push(r),r=void 0),void o.push(function(e,t,n){if("text"===e.type.name||"link"===e.type.name)throw new Error("unexpected");const o={},r=t[e.type.name];for(const[s,l]of Object.entries(e.attrs)){if(!r)throw Error("ic node is of an unrecognized type: "+e.type.name);s in r.propSchema&&(o[s]=l)}let i;return i="styled"===r.content?qw(e,t,n):void 0,{type:e.type.name,props:o,content:i}}(e,t,n))}const i={};let s;for(const t of e.marks)if("link"===t.type.name)s=t;else{const e=n[t.type.name];if(!e){if(t.type.spec.blocknoteIgnore)continue;throw new Error(`style ${t.type.name} not found in styleSchema`)}if("boolean"===e.propSchema)i[e.type]=!0;else{if("string"!==e.propSchema)throw new uw(e.propSchema);i[e.type]=t.attrs.stringValue}}r?iw(r)?s?(o.push(r),r={type:"link",href:s.attrs.href,content:[{type:"text",text:e.textContent,styles:i}]}):JSON.stringify(r.styles)===JSON.stringify(i)?r.text+=e.textContent:(o.push(r),r={type:"text",text:e.textContent,styles:i}):ow(r)&&(s?r.href===s.attrs.href?JSON.stringify(r.content[r.content.length-1].styles)===JSON.stringify(i)?r.content[r.content.length-1].text+=e.textContent:r.content.push({type:"text",text:e.textContent,styles:i}):(o.push(r),r={type:"link",href:s.attrs.href,content:[{type:"text",text:e.textContent,styles:i}]}):(o.push(r),r={type:"text",text:e.textContent,styles:i})):r=s?{type:"link",href:s.attrs.href,content:[{type:"text",text:e.textContent,styles:i}]}:{type:"text",text:e.textContent,styles:i}}),r&&o.push(r),o}function Gw(e,t,n=$w(t),o=zw(t),r=Fw(t),i=Uw(t)){var s;if(!e.type.isInGroup("bnBlock"))throw Error("Node should be a bnBlock, but is instead: "+e.type.name);const l=null==i?void 0:i.get(e);if(l)return l;const a=_w(e,0);let c=a.bnBlock.node.attrs.id;null===c&&(c=nw.options.generateID());const d=n[a.blockNoteType];if(!d)throw Error("Block is of an unrecognized type: "+a.blockNoteType);const u={};for(const[g,y]of Object.entries({...e.attrs,...a.isBlockContainer?a.blockContent.node.attrs:{}})){const e=d.propSchema;g in e&&(void 0!==e[g].default||void 0!==y)&&(u[g]=y)}const h=n[a.blockNoteType],p=[];let f;if(null==(s=a.childContainer)||s.node.forEach(e=>{p.push(Gw(e,t,n,o,r,i))}),"inline"===h.content){if(!a.isBlockContainer)throw new Error("impossible");f=qw(a.blockContent.node,o,r)}else if("table"===h.content){if(!a.isBlockContainer)throw new Error("impossible");f=Ww(a.blockContent.node,o,r)}else{if("none"!==h.content)throw new uw(h.content);f=void 0}const m={id:c,type:h.type,props:u,content:f,children:p};return null==i||i.set(e,m),m}function Kw(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.config]))}function Zw(e,t){return function(e,t){return{config:e,implementation:t}}({type:e.name,propSchema:t},{mark:e})}function Jw(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.config]))}function Xw(e){const{height:t,width:n}=ek(e),o=new Array(t).fill(!1).map(()=>new Array(n).fill(null)),r=(e,r)=>{for(let i=e;i<t;i++)for(let e=r;e<n;e++)if(!o[i][e])return{row:i,col:e};throw new Error("Unable to create occupancy grid for table, no more available cells")};for(let i=0;i<e.content.rows.length;i++)for(let t=0;t<e.content.rows[i].cells.length;t++){const n=sw(e.content.rows[i].cells[t]),s=dw(n),l=cw(n),{row:a,col:c}=r(i,t);for(let e=a;e<a+s;e++)for(let r=c;r<c+l;r++){if(o[e][r])throw new Error(`Unable to create occupancy grid for table, cell at ${e},${r} is already occupied`);o[e][r]={row:i,col:t,rowspan:s,colspan:l,cell:n}}}return o}function Yw(e){const t=new Set;return e.map(e=>({cells:e.map(e=>!t.has(e.row+":"+e.col)&&(t.add(e.row+":"+e.col),e.cell)).filter(e=>!1!==e)}))}function Qw(e,t,n=Xw(t)){for(let o=0;o<n.length;o++)for(let t=0;t<n[o].length;t++){const r=n[o][t];if(r.row===e.row&&r.col===e.col)return{row:o,col:t,cell:r.cell}}throw new Error(`Unable to resolve relative table cell indices for table, cell at ${e.row},${e.col} is not occupied`)}function ek(e){const t=e.content.rows.length;let n=0;return e.content.rows.forEach(e=>{let t=0;e.cells.forEach(e=>{t+=cw(e)}),n=Math.max(n,t)}),{height:t,width:n}}function tk(e,t,n=Xw(t)){var o;const r=null==(o=n[e.row])?void 0:o[e.col];if(r)return{row:r.row,col:r.col,cell:r.cell}}function nk(e,t){var n;const o=Xw(e);if(t<0||t>=o.length)return[];let r=0;for(let s=0;s<t;s++){const e=null==(n=o[r])?void 0:n[0];if(!e)return[];r+=e.rowspan}const i=new Array(o[0].length).fill(!1).map((t,n)=>tk({row:r,col:n},e,o)).filter(e=>void 0!==e);return i.filter((e,t)=>i.findIndex(t=>t.row===e.row&&t.col===e.col)===t)}function ok(e,t){var n;const o=Xw(e);if(t<0||t>=o[0].length)return[];let r=0;for(let s=0;s<t;s++){const e=null==(n=o[0])?void 0:n[r];if(!e)return[];r+=e.colspan}const i=new Array(o.length).fill(!1).map((t,n)=>tk({row:n,col:r},e,o)).filter(e=>void 0!==e);return i.filter((e,t)=>i.findIndex(t=>t.row===e.row&&t.col===e.col)===t)}function rk(e){return!e||(lw(e)?rk(e.content):"string"==typeof e?0===e.length:!!Array.isArray(e)&&e.every(e=>"string"==typeof e?0===e.length:iw(e)?0===e.text.length:!!rw(e)&&("string"==typeof e.content?0===e.content.length:e.content.every(e=>0===e.text.length))))}function ik(e,t,n){const o=nk(e,n);if(!o.some(e=>dw(e.cell)>1))return!0;let r=n,i=n;return o.forEach(e=>{const t=dw(e.cell);r=Math.max(r,e.row+t-1),i=Math.min(i,e.row)}),t<n?n===r:n===i}function sk(e,t,n){const o=ok(e,n);if(!o.some(e=>cw(e.cell)>1))return!0;let r=n,i=n;return o.forEach(e=>{const t=cw(e.cell);r=Math.max(r,e.col+t-1),i=Math.min(i,e.col)}),t<n?n===r:n===i}function lk(e,t,n,o){const r=[];for(const[i,s]of Object.entries(e.styles||{})){const e=n[i];if(!e)throw new Error(`style ${i} not found in styleSchema`);if("boolean"===e.propSchema)s&&r.push(t.mark(i));else{if("string"!==e.propSchema)throw new uw(e.propSchema);s&&r.push(t.mark(i,{stringValue:s}))}}return o&&t.nodes[o].spec.code?e.text.length>0?[t.text(e.text,r)]:[]:e.text.split(/(\n)/g).filter(e=>e.length>0).map(e=>"\n"===e?t.nodes.hardBreak.createChecked():t.text(e,r))}function ak(e,t,n){const o=t.marks.link.create({href:e.href});return ck(e.content,t,n).map(e=>{if("text"===e.type.name)return e.mark([...e.marks,o]);if("hardBreak"===e.type.name)return e;throw new Error("unexpected node type")})}function ck(e,t,n,o){const r=[];if("string"==typeof e)return r.push(...lk({text:e,styles:{}},t,n,o)),r;for(const i of e)r.push(...lk(i,t,n,o));return r}function dk(e,t,n,o=Fw(t)){const r=[];for(const i of e)"string"==typeof i?r.push(...ck(i,t,o,n)):rw(i)?r.push(...ak(i,t,o)):iw(i)?r.push(...ck([i],t,o,n)):r.push(hk(i,t,o));return r}function uk(e,t,n=Fw(t)){const o=[],r=new Array(e.headerRows??0).fill(!0),i=new Array(e.headerCols??0).fill(!0),s=e.columnWidths??[];for(let l=0;l<e.rows.length;l++){const a=e.rows[l],c=[],d=r[l];for(let o=0;o<a.cells.length;o++){const r=a.cells[o],u=i[o],h=void 0;let p=null;const f=Qw({row:l,col:o},{content:e});let m=s[f.col]?[s[f.col]]:null;if(r)if("string"==typeof r)p=t.text(r);else if(lw(r)){r.content&&(p=dk(r.content,t,"tableParagraph",n));const e=cw(r);e>1&&(m=new Array(e).fill(!1).map((e,t)=>s[f.col+t]??void 0))}else p=dk(r,t,"tableParagraph",n);const g=t.nodes[u||d?"tableHeader":"tableCell"].createChecked({...lw(r)?r.props:{},colwidth:m},t.nodes.tableParagraph.createChecked(h,p));c.push(g)}const u=t.nodes.tableRow.createChecked({},c);o.push(u)}return o}function hk(e,t,n){let o,r=e.type;if(void 0===r&&(r="paragraph"),!t.nodes[r])throw new Error(`node type ${r} not found in schema`);if(e.content)if("string"==typeof e.content){const i=dk([e.content],t,r,n);o=t.nodes[r].createChecked(e.props,i)}else if(Array.isArray(e.content)){const i=dk(e.content,t,r,n);o=t.nodes[r].createChecked(e.props,i)}else{if("tableContent"!==e.content.type)throw new uw(e.content.type);{const i=uk(e.content,t,n);o=t.nodes[r].createChecked(e.props,i)}}else o=t.nodes[r].createChecked(e.props);return o}function pk(e,t,n=Fw(t)){let o=e.id;void 0===o&&(o=nw.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(pk(i,t,n));if(!e.type||t.nodes[e.type].isInGroup("blockContent")){const i=hk(e,t,n),s=r.length>0?t.nodes.blockGroup.createChecked({},r):void 0;return t.nodes.blockContainer.createChecked({id:o,...e.props},s?[i,s]:i)}if(t.nodes[e.type].isInGroup("bnBlock"))return t.nodes[e.type].createChecked({id:o,...e.props},r);throw new Error(`block type ${e.type} doesn't match blockContent or bnBlock group`)}function fk(e,t){let n,o;if(t.firstChild.descendants((t,r)=>!n&&(!mk(t)||t.attrs.id!==e||(n=t,o=r+1,!1))),void 0!==n&&void 0!==o)return{node:n,posBeforeNode:o}}function mk(e){return e.type.isInGroup("bnBlock")}function gk(e,t,n){const o=Bw(e),r=n.map(e=>pk(e,o)),i=new Set(t.map(e=>"string"==typeof e?e:e.id)),s=[],l="string"==typeof t[0]?t[0]:t[0].id;let a=0;if(e.doc.descendants((t,c)=>{if(0===i.size)return!1;if(!t.type.isInGroup("bnBlock")||!i.has(t.attrs.id))return!0;if(s.push(Gw(t,o)),i.delete(t.attrs.id),n.length>0&&t.attrs.id===l){const t=e.doc.nodeSize;e.insert(c,r);const n=e.doc.nodeSize;a+=t-n}const d=e.doc.nodeSize,u=e.doc.resolve(c-a);"blockGroup"===u.node().type.name&&"doc"!==u.node(u.depth-1).type.name&&1===u.node().childCount?e.delete(u.before(),u.after()):e.delete(c-a,c-a+t.nodeSize);const h=e.doc.nodeSize;return a+=d-h,!1}),i.size>0){const e=[...i].join("\n");throw Error("Blocks with the following IDs could not be found in the editor: "+e)}return{insertedBlocks:r.map(e=>Gw(e,o)),removedBlocks:s}}const yk=(e,t)=>({tr:n,dispatch:o})=>(o&&bk(n,e,t),!0);function bk(e,t,n,o,r){const i=Iw(e.doc.resolve(t));let s=null;"table"===i.blockNoteType&&(s=function(e){const t="selection"in e?e.selection:null;if(!(t instanceof Nr))return null;const n=e.doc.resolve(t.head);let o=-1,r=-1;for(let m=n.depth;m>=0;m--){const e=n.node(m).type.name;if(o<0&&("tableCell"===e||"tableHeader"===e)&&(o=m),"table"===e){r=m;break}}if(o<0||r<0)return null;const i=n.before(o),s=n.before(r),l=e.doc.nodeAt(s);if(!l||"table"!==l.type.name)return null;const a=Id.get(l),c=i-(s+1),d=a.map.indexOf(c);if(d<0)return null;const u=Math.floor(d/a.width),h=d%a.width,p=i+1+1,f=Math.max(0,t.head-p);return{row:u,col:h,offset:f}}(e));const l=Bw(e),a=l.nodes[i.blockNoteType],c=l.nodes[n.type||i.blockNoteType],d=c.isInGroup("bnBlock")?c:l.nodes.blockContainer;if(i.isBlockContainer&&c.isInGroup("blockContent"))vk(n,e,i),function(e,t,n,o,r){const i=Bw(t);let s="keep";if(e.content)if("string"==typeof e.content)s=dk([e.content],i,o.name);else if(Array.isArray(e.content))s=dk(e.content,i,o.name);else{if("tableContent"!==e.content.type)throw new uw(e.content.type);s=uk(e.content,i)}else""===n.spec.content||o.spec.content!==n.spec.content&&(s=[]);"keep"===s?t.setNodeMarkup(r.blockContent.beforePos,o,{...r.blockContent.node.attrs,...e.props}):t.replaceWith(r.blockContent.beforePos,r.blockContent.afterPos,o.createChecked({...r.blockContent.node.attrs,...e.props},s))}(n,e,a,c,i);else{if(i.isBlockContainer||!c.isInGroup("bnBlock")){const t=Gw(i.bnBlock.node,l);return void e.replaceWith(i.bnBlock.beforePos,i.bnBlock.afterPos,pk({children:t.children,...n},l))}vk(n,e,i)}e.setNodeMarkup(i.bnBlock.beforePos,d,{...i.bnBlock.node.attrs,...n.props}),s&&function(e,t,n){var o;if("table"!==t.blockNoteType)return!1;let r=-1;if(t.isBlockContainer)r=e.mapping.map(t.blockContent.beforePos);else{const n=e.mapping.map(t.bnBlock.beforePos),i=n+((null==(o=e.doc.nodeAt(n))?void 0:o.nodeSize)||0);e.doc.nodesBetween(n,i,(e,t)=>"table"!==e.type.name||(r=t,!1))}const i=r>=0?e.doc.nodeAt(r):null;if(!i||"table"!==i.type.name)return!1;const s=Id.get(i),l=Math.max(0,Math.min(n.row,s.height-1)),a=Math.max(0,Math.min(n.col,s.width-1)),c=l*s.width+a,d=s.map[c];if(null==d)return!1;const u=r+1+d+1,h=e.doc.nodeAt(u),p=u+1,f=h?h.content.size:0,m=p+Math.max(0,Math.min(n.offset,f));"selection"in e&&e.setSelection(Nr.create(e.doc,m))}(e,i,s)}function vk(e,t,n){const o=Bw(t);if(void 0!==e.children&&e.children.length>0){const r=e.children.map(e=>pk(e,o));if(n.childContainer)t.step(new Zo(n.childContainer.beforePos+1,n.childContainer.afterPos-1,new _n(Rn.from(r),0,0)));else{if(!n.isBlockContainer)throw new Error("impossible");t.insert(n.blockContent.afterPos,o.nodes.blockGroup.createChecked({},r))}}}function xk(e){const t=Array.from(e.classList).filter(e=>!e.startsWith("bn-"))||[];t.length>0?e.className=t.join(" "):e.removeAttribute("class")}function wk(e,t,n,o){let r;if(!t)throw new Error("blockContent is required");if("string"==typeof t)r=dk([t],e.pmSchema);else if(Array.isArray(t))r=dk(t,e.pmSchema);else{if("tableContent"!==t.type)throw new uw(t.type);r=uk(t,e.pmSchema)}const i=n.serializeFragment(Rn.from(r),o);return 1===i.nodeType&&xk(i),i}function kk(e,t,n,o,r,i,s){var l,a,c,d,u,h,p,f;const m=(null==s?void 0:s.document)??document,g=t.pmSchema.nodes.blockContainer;let y=n.props;if(!n.props){y={};for(const[e,o]of Object.entries(t.schema.blockSchema[n.type].propSchema))void 0!==o.default&&(y[e]=o.default)}const b=null==(a=null==(l=g.spec)?void 0:l.toDOM)?void 0:a.call(l,g.create({id:n.id,...y})),v=Array.from(b.dom.attributes),x=t.blockImplementations[n.type].implementation.toExternalHTML({...n,props:y},t),w=m.createDocumentFragment();if(x.dom.classList.contains("bn-block-content")){const e=[...v,...Array.from(x.dom.attributes)].filter(e=>e.name.startsWith("data")&&"data-content-type"!==e.name&&"data-file-block"!==e.name&&"data-node-view-wrapper"!==e.name&&"data-node-type"!==e.name&&"data-id"!==e.name&&"data-index"!==e.name&&"data-editable"!==e.name);for(const t of e)x.dom.firstChild.setAttribute(t.name,t.value);xk(x.dom.firstChild),w.append(...Array.from(x.dom.childNodes))}else w.append(x.dom);if(x.contentDOM&&n.content){const e=wk(t,n.content,o,s);x.contentDOM.appendChild(e)}let k;if(r.has(n.type)?k="OL":i.has(n.type)&&(k="UL"),k){if((null==(c=e.lastChild)?void 0:c.nodeName)!==k){const t=m.createElement(k);"OL"===k&&null!=y&&y.start&&1!==(null==y?void 0:y.start)&&t.setAttribute("start",y.start+""),e.append(t)}const t=m.createElement("li");t.append(w),e.lastChild.appendChild(t)}else e.append(w);if(n.children&&n.children.length>0){const l=m.createDocumentFragment();if(Ck(l,t,n.children,o,r,i,s),"UL"===(null==(d=e.lastChild)?void 0:d.nodeName)||"OL"===(null==(u=e.lastChild)?void 0:u.nodeName))for(;"UL"===(null==(h=l.firstChild)?void 0:h.nodeName)||"OL"===(null==(p=l.firstChild)?void 0:p.nodeName);)e.lastChild.lastChild.appendChild(l.firstChild);t.pmSchema.nodes[n.type].isInGroup("blockContent")?e.append(l):null==(f=x.contentDOM)||f.append(l)}}const Ck=(e,t,n,o,r,i,s)=>{for(const l of n)kk(e,t,l,o,r,i,s)},Ek=(e,t)=>{const n=jo.fromSchema(e);return{exportBlocks:(e,o)=>{const r=((e,t,n,o,r,i)=>{const s=((null==i?void 0:i.document)??document).createDocumentFragment();return Ck(s,e,t,n,o,r,i),s})(t,e,n,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem"]),o),i=document.createElement("div");return i.append(r),i.innerHTML},exportInlineContent:(e,o)=>{const r=wk(t,e,n,o),i=document.createElement("div");return i.append(r.cloneNode(!0)),i.innerHTML}}};function Sk(e,t,n,o,r){var i,s,l,a,c;const d=e.pmSchema.nodes.blockContainer;let u=t.props;if(!t.props){u={};for(const[n,o]of Object.entries(e.schema.blockSchema[t.type].propSchema))void 0!==o.default&&(u[n]=o.default)}const h=e.blockImplementations[t.type].implementation.toInternalHTML({...t,props:u},e);if("numberedListItem"===t.type&&h.dom.setAttribute("data-index",o.toString()),h.contentDOM&&t.content){const o=function(e,t,n,o,r){let i;if(!t)throw new Error("blockContent is required");if("string"==typeof t)i=dk([t],e.pmSchema,o);else if(Array.isArray(t))i=dk(t,e.pmSchema,o);else{if("tableContent"!==t.type)throw new uw(t.type);i=uk(t,e.pmSchema)}return n.serializeFragment(Rn.from(i),r)}(e,t.content,n,t.type,r);h.contentDOM.appendChild(o)}if(e.pmSchema.nodes[t.type].isInGroup("bnBlock")){if(t.children&&t.children.length>0){const o=Mk(e,t.children,n,r);null==(i=h.contentDOM)||i.append(o)}return h.dom}const p=null==(l=null==(s=d.spec)?void 0:s.toDOM)?void 0:l.call(s,d.create({id:t.id,...u}));return null==(a=p.contentDOM)||a.appendChild(h.dom),t.children&&t.children.length>0&&(null==(c=p.contentDOM)||c.appendChild(Rk(e,t.children,n,r))),p.dom}function Mk(e,t,n,o){const r=((null==o?void 0:o.document)??document).createDocumentFragment();let i=0;for(const s of t){"numberedListItem"===s.type?i++:i=0;const t=Sk(e,s,n,i,o);r.appendChild(t)}return r}const Rk=(e,t,n,o)=>{var r;const i=e.pmSchema.nodes.blockGroup,s=i.spec.toDOM(i.create({})),l=Mk(e,t,n,o);return null==(r=s.contentDOM)||r.appendChild(l),s.dom};function Tk(e){const t={},n={},o=Bw(e);return e.descendants((r,i)=>{if(!mk(r))return!0;const s=function(e,t){if(0===t)return;const n=e.resolve(t);for(let o=n.depth;o>0;o--){const e=n.node(o);if(mk(e))return e.attrs.id}}(e,i),l=s??"__root__";n[l]||(n[l]=[]);const a=Gw(r,o);return t[r.attrs.id]={block:a,parentId:s},n[l].push(r.attrs.id),!0}),{byId:t,childrenByParent:n}}function jk(e,t=[]){const n=function(e){return e.getMeta("paste")?{type:"paste"}:"drop"===e.getMeta("uiEvent")?{type:"drop"}:e.getMeta("history$")?{type:e.getMeta("history$").redo?"redo":"undo"}:e.getMeta("y-sync$")?e.getMeta("y-sync$").isUndoRedoOperation?{type:"undo-redo"}:{type:"yjs-remote"}:{type:"local"}}(e),o=qc(e.before,[e,...t]),r=Tk(o.before),i=Tk(o.doc),s=[],l=new Set;Object.keys(i.byId).filter(e=>!(e in r.byId)).forEach(e=>{s.push({type:"insert",block:i.byId[e].block,source:n,prevBlock:void 0}),l.add(e)}),Object.keys(r.byId).filter(e=>!(e in i.byId)).forEach(e=>{s.push({type:"delete",block:r.byId[e].block,source:n,prevBlock:void 0}),l.add(e)}),Object.keys(i.byId).filter(e=>e in r.byId).forEach(e=>{var t,o;const a=r.byId[e],c=i.byId[e];a.parentId!==c.parentId?(s.push({type:"move",block:c.block,prevBlock:a.block,source:n,prevParent:a.parentId?null==(t=r.byId[a.parentId])?void 0:t.block:void 0,currentParent:c.parentId?null==(o=i.byId[c.parentId])?void 0:o.block:void 0}),l.add(e)):Du({...a.block,children:void 0},{...c.block,children:void 0})||(s.push({type:"update",block:c.block,prevBlock:a.block,source:n}),l.add(e))});const a=r.childrenByParent,c=i.childrenByParent,d=new Set([...Object.keys(a),...Object.keys(c)]),u=new Set;return d.forEach(e=>{const t=function(e,t){const n=new Set;if(!e||!t)return n;const o=new Set(e),r=t.filter(e=>o.has(e)),i=e.filter(e=>r.includes(e));if(i.length<=1||r.length<=1)return n;const s={};for(let m=0;m<i.length;m++)s[i[m]]=m;const l=r.map(e=>s[e]),a=l.length,c=[],d=[],u=new Array(a).fill(-1),h=(e,t)=>{let n=0,o=e.length;for(;n<o;){const r=n+o>>>1;e[r]<t?n=r+1:o=r}return n};for(let m=0;m<a;m++){const e=l[m],t=h(c,e);t>0&&(u[m]=d[t-1]),t===c.length?(c.push(e),d.push(m)):(c[t]=e,d[t]=m)}const p=new Set;let f=d[d.length-1]??-1;for(;-1!==f;)p.add(f),f=u[f];for(let m=0;m<r.length;m++)p.has(m)||n.add(r[m]);return n}(a[e],c[e]);0!==t.size&&t.forEach(t=>{var o,a;const c=r.byId[t],d=i.byId[t];!c||!d||c.parentId!==d.parentId||l.has(t)||(c.parentId??"__root__")!==e||u.has(t)||(u.add(t),s.push({type:"move",block:d.block,prevBlock:c.block,source:n,prevParent:c.parentId?null==(o=r.byId[c.parentId])?void 0:o.block:void 0,currentParent:d.parentId?null==(a=i.byId[d.parentId])?void 0:a.block:void 0}),l.add(t))})}),s}const Nk=(e,t)=>{const n=e.querySelector(t);if(!n)return;const o=e.querySelector("figcaption");return{targetElement:n,caption:(null==o?void 0:o.textContent)??void 0}},Ak=(e,t,n,o,r)=>{const i=document.createElement("div");if(i.className="bn-file-block-content-wrapper",""===e.props.url){const n=((e,t,n,o)=>{const r=document.createElement("div");r.className="bn-add-file-button";const i=document.createElement("div");i.className="bn-add-file-button-icon",o?i.appendChild(o):i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',r.appendChild(i);const s=document.createElement("p");s.className="bn-add-file-button-text",s.innerHTML=n||t.dictionary.file_blocks.file.add_button_text,r.appendChild(s);const l=e=>{e.preventDefault()},a=()=>{t.transact(n=>n.setMeta(t.filePanel.plugins[0],{block:e}))};return r.addEventListener("mousedown",l,!0),r.addEventListener("click",a,!0),{dom:r,destroy:()=>{r.removeEventListener("mousedown",l,!0),r.removeEventListener("click",a,!0)}}})(e,t,o,r);i.appendChild(n.dom);const s=t.onUploadStart(t=>{if(t===e.id){i.removeChild(n.dom);const e=document.createElement("div");e.className="bn-file-loading-preview",e.textContent="Loading...",i.appendChild(e)}});return{dom:i,destroy:()=>{s(),n.destroy()}}}const s={dom:i};if(!1!==e.props.showPreview&&n)i.appendChild(n.dom);else{const t=(e=>{const t=document.createElement("div");t.className="bn-file-name-with-icon";const n=document.createElement("div");n.className="bn-file-icon",n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',t.appendChild(n);const o=document.createElement("p");return o.className="bn-file-name",o.textContent=e.props.name,t.appendChild(o),{dom:t}})(e);i.appendChild(t.dom),s.destroy=()=>{var e;null==(e=t.destroy)||e.call(t)}}if(e.props.caption){const t=document.createElement("p");t.className="bn-file-caption",t.textContent=e.props.caption,i.appendChild(t)}return s},Ok=(e,t)=>{const n=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=t,n.appendChild(e),n.appendChild(o),{dom:n}},_k=(e,t)=>{const n=document.createElement("div"),o=document.createElement("p");return o.textContent=t,n.appendChild(e),n.appendChild(o),{dom:n}},Pk=e=>({url:e.src||void 0}),Ik={type:"audio",propSchema:{backgroundColor:bw.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},Lk=e=>{if("AUDIO"===e.tagName)return e.closest("figure")?void 0:Pk(e);if("FIGURE"===e.tagName){const t=Nk(e,"audio");if(!t)return;const{targetElement:n,caption:o}=t;return{...Pk(n),caption:o}}},Dk=Aw(Ik,{render:(e,t)=>{const n=document.createElement("div");n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>';const o=document.createElement("audio");return o.className="bn-audio",t.resolveFileUrl?t.resolveFileUrl(e.props.url).then(e=>{o.src=e}):o.src=e.props.url,o.controls=!0,o.contentEditable="false",o.draggable=!1,Ak(e,t,{dom:o},t.dictionary.file_blocks.audio.add_button_text,n.firstElementChild)},parse:Lk,toExternalHTML:e=>{if(!e.props.url){const e=document.createElement("p");return e.textContent="Add audio",{dom:e}}let t;return e.props.showPreview?(t=document.createElement("audio"),t.src=e.props.url):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ok(t,e.props.caption):_k(t,e.props.caption):{dom:t}}}),Bk=Symbol.for("blocknote.shikiParser"),Hk=Symbol.for("blocknote.shikiHighlighterPromise"),Vk=Sw({name:"codeBlock",content:"inline*",group:"blockContent",marks:"insertion deletion modification",code:!0,defining:!0,addOptions:()=>({defaultLanguage:"text",indentLineWithTab:!0,supportedLanguages:{}}),addAttributes(){const e=this.options;return{language:{default:e.editor.settings.codeBlock.defaultLanguage,parseHTML:t=>{let n=t,o=null;"DIV"===(null==n?void 0:n.tagName)&&"codeBlock"===(null==n?void 0:n.dataset.contentType)&&(n=n.children[0]),"PRE"===(null==n?void 0:n.tagName)&&(n=null==n?void 0:n.children[0]);const r=null==n?void 0:n.getAttribute("data-language");if(r)o=r.toLowerCase();else{const e=[...(null==n?void 0:n.className.split(" "))||[]].filter(e=>e.startsWith("language-")).map(e=>e.replace("language-",""));e.length>0&&(o=e[0].toLowerCase())}return o?zk(e.editor.settings.codeBlock,o)??o:null},renderHTML:e=>e.language?{class:`language-${e.language}`,"data-language":e.language}:{}}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"pre",preserveWhitespace:"full"}]},renderHTML({HTMLAttributes:e}){var t,n;const o=document.createElement("pre"),{dom:r,contentDOM:i}=gw(this.name,"code",(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},{...(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{},...e});return r.removeChild(i),r.appendChild(o),o.appendChild(i),{dom:r,contentDOM:i}},addNodeView(){const e=this.options;return({editor:t,node:n,getPos:o,HTMLAttributes:r})=>{var i,s;const l=document.createElement("pre"),a=document.createElement("select"),c=document.createElement("div"),{dom:d,contentDOM:u}=gw(this.name,"code",{...(null==(i=this.options.domAttributes)?void 0:i.blockContent)||{},...r},(null==(s=this.options.domAttributes)?void 0:s.inlineContent)||{}),h=e=>{const n=e.target.value;t.commands.command(({tr:e})=>(e.setNodeAttribute(o(),"language",n),!0))};return Object.entries(e.editor.settings.codeBlock.supportedLanguages).forEach(([e,{name:t}])=>{const n=document.createElement("option");n.value=e,n.text=t,a.appendChild(n)}),c.contentEditable="false",a.value=n.attrs.language||e.editor.settings.codeBlock.defaultLanguage,d.removeChild(u),d.appendChild(c),d.appendChild(l),l.appendChild(u),c.appendChild(a),a.addEventListener("change",h),{dom:d,contentDOM:u,update:e=>e.type===this.type,destroy:()=>{a.removeEventListener("change",h)}}}},addProseMirrorPlugins(){const e=this.options,t=globalThis;let n,o,r=!1;return[Hu({parser:i=>{if(!e.editor.settings.codeBlock.createHighlighter)return"development"===process.env.NODE_ENV&&!r&&(r=!0),[];if(!n)return t[Hk]=t[Hk]||e.editor.settings.codeBlock.createHighlighter(),t[Hk].then(e=>{n=e});const s=zk(e.editor.settings.codeBlock,i.language);return s&&"text"!==s&&"none"!==s&&"plaintext"!==s&&"txt"!==s?n.getLoadedLanguages().includes(s)?(o||(o=t[Bk]||(l=n,function({content:e,language:t,pos:n,size:o}){var r;const i=[],{tokens:s,fg:a,bg:c,rootStyle:d}=l.codeToTokens(e,{lang:t,theme:l.getLoadedThemes()[0]}),u=d||(a&&c?`--prosemirror-highlight:${a};--prosemirror-highlight-bg:${c}`:"");if(u){const e=Ol.node(n,n+o,{style:u});i.push(e)}let h=n+1;for(const l of s){for(const e of l){const t=h+e.content.length,n=Ol.inline(h,t,{style:$u(null!=(r=e.htmlStyle)?r:`color: ${e.color}`),class:"shiki"});i.push(n),h=t}h+=1}return i}),t[Bk]=o),o(i)):n.loadLanguage(s):[];var l},languageExtractor:e=>e.attrs.language,nodeTypes:[this.name]})]},addInputRules(){const e=this.options;return[new uc({find:/^```(.*?)\s$/,handler:({state:t,range:n,match:o})=>{const r=t.doc.resolve(n.from),i=o[1].trim(),s={language:zk(e.editor.settings.codeBlock,i)??i};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),this.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,this.type,s).setSelection(Nr.create(t.tr.doc,n.from))}})]},addKeyboardShortcuts(){return{Delete:({editor:e})=>{const{selection:t}=e.state,{$from:n}=t;if(e.isActive(this.name)&&!n.parent.textContent&&Ac(t)){const t=n.pos-n.parentOffset-2;return e.chain().setNodeSelection(t).deleteSelection().run(),!0}return!1},Tab:({editor:e})=>!(!this.options.indentLineWithTab||!e.isActive(this.name))&&(e.commands.insertContent(" "),!0),Enter:({editor:e})=>{const{$from:t}=e.state.selection;if(!e.isActive(this.name))return!1;const n=t.parentOffset===t.parent.nodeSize-2,o=t.parent.textContent.endsWith("\n\n");return n&&o?e.chain().command(({tr:e})=>(e.delete(t.pos-2,t.pos),!0)).exitCode().run():(e.commands.insertContent("\n"),!0)},"Shift-Enter":({editor:e})=>{const{$from:t}=e.state.selection;return!!e.isActive(this.name)&&(e.chain().insertContentAt(t.pos-t.parentOffset+t.parent.nodeSize,{type:"paragraph"}).run(),!0)}}}}),$k=Rw(Vk,{language:{default:"text"}});function zk(e,t){var n;return null==(n=Object.entries(e.supportedLanguages).find(([e,{aliases:n}])=>(null==n?void 0:n.includes(t))||e===t))?void 0:n[0]}const Fk=Zw(gc.create({name:"backgroundColor",addAttributes:()=>({stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-background-color"),renderHTML:e=>({"data-background-color":e.stringValue})}}),parseHTML:()=>[{tag:"span",getAttrs:e=>"string"!=typeof e&&(!!e.hasAttribute("data-background-color")&&{stringValue:e.getAttribute("data-background-color")})}],renderHTML:({HTMLAttributes:e})=>["span",e,0]}),"string"),Uk=Zw(gc.create({name:"textColor",addAttributes:()=>({stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-text-color"),renderHTML:e=>({"data-text-color":e.stringValue})}}),parseHTML:()=>[{tag:"span",getAttrs:e=>"string"!=typeof e&&(!!e.hasAttribute("data-text-color")&&{stringValue:e.getAttribute("data-text-color")})}],renderHTML:({HTMLAttributes:e})=>["span",e,0]}),"string"),Wk=e=>({url:e.src||void 0}),qk={type:"file",propSchema:{backgroundColor:bw.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},content:"none",isFileBlock:!0},Gk=e=>{if("EMBED"===e.tagName)return e.closest("figure")?void 0:Wk(e);if("FIGURE"===e.tagName){const t=Nk(e,"embed");if(!t)return;const{targetElement:n,caption:o}=t;return{...Wk(n),caption:o}}},Kk=Aw(qk,{render:(e,t)=>Ak(e,t),parse:Gk,toExternalHTML:e=>{if(!e.props.url){const e=document.createElement("p");return e.textContent="Add file",{dom:e}}const t=document.createElement("a");return t.href=e.props.url,t.textContent=e.props.name||e.props.url,e.props.caption?_k(t,e.props.caption):{dom:t}}}),Zk={set:(e,t)=>window.localStorage.setItem(`toggle-${e.id}`,t?"true":"false"),get:e=>"true"===window.localStorage.getItem(`toggle-${e.id}`)},Jk=(e,t,n,o=Zk)=>{if("isToggleable"in e.props&&!e.props.isToggleable)return{dom:n};const r=document.createElement("div"),i=document.createElement("div");i.className="bn-toggle-wrapper";const s=document.createElement("button");s.className="bn-toggle-button",s.type="button",s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="CURRENTCOLOR"><path d="M320-200v-560l440 280-440 280Z"/></svg>';const l=e=>e.preventDefault();s.addEventListener("mousedown",l);const a=()=>{var n;"true"===i.getAttribute("data-show-children")?(i.setAttribute("data-show-children","false"),o.set(t.getBlock(e),!1),r.contains(c)&&r.removeChild(c)):(i.setAttribute("data-show-children","true"),o.set(t.getBlock(e),!0),0===(null==(n=t.getBlock(e))?void 0:n.children.length)&&!r.contains(c)&&r.appendChild(c))};s.addEventListener("click",a),i.appendChild(s),i.appendChild(n);const c=document.createElement("button");c.className="bn-toggle-add-block-button",c.type="button",c.textContent=t.dictionary.toggle_blocks.add_block_button;const d=e=>e.preventDefault();c.addEventListener("mousedown",d);const u=()=>{t.transact(()=>{const n=t.updateBlock(e,{children:[{}]});t.setTextCursorPosition(n.children[0].id,"end"),t.focus()})};c.addEventListener("click",u),r.appendChild(i);let h=e.children.length;const p=t.onChange(()=>{var n;const s=(null==(n=t.getBlock(e))?void 0:n.children.length)??0;s>h?("false"===i.getAttribute("data-show-children")&&(i.setAttribute("data-show-children","true"),o.set(t.getBlock(e),!0)),r.contains(c)&&r.removeChild(c)):0===s&&s<h&&("true"===i.getAttribute("data-show-children")&&(i.setAttribute("data-show-children","false"),o.set(t.getBlock(e),!1)),r.contains(c)&&r.removeChild(c)),h=s});return o.get(e)?(i.setAttribute("data-show-children","true"),0===e.children.length&&r.appendChild(c)):i.setAttribute("data-show-children","false"),{dom:r,ignoreMutation:e=>e instanceof MutationRecord&&("attributes"===e.type&&e.target===i&&"data-show-children"===e.attributeName||"childList"===e.type&&(e.addedNodes[0]===c||e.removedNodes[0]===c)),destroy:()=>{s.removeEventListener("mousedown",l),s.removeEventListener("click",a),c.removeEventListener("mousedown",d),c.removeEventListener("click",u),null==p||p()}}},Xk={...bw,level:{default:1,values:[1,2,3,4,5,6]},isToggleable:{default:!1}},Yk=Sw({name:"heading",content:"inline*",group:"blockContent",addAttributes:()=>kw(Xk),addInputRules(){return[...this.options.editor.settings.heading.levels.map(e=>new uc({find:new RegExp(`^(#{${e}})\\s$`),handler:({state:t,chain:n,range:o})=>{const r=Lw(t);!r.isBlockContainer||"inline*"!==r.blockContent.node.type.spec.content||n().command(yk(r.bnBlock.beforePos,{type:"heading",props:{level:e}})).deleteRange({from:o.from,to:o.to}).run()}}))]},addKeyboardShortcuts(){const e=this.options.editor;return Object.fromEntries(e.settings.heading.levels.map(e=>[`Mod-Alt-${e}`,()=>{const t=Lw(this.editor.state);return!t.isBlockContainer||"inline*"!==t.blockContent.node.type.spec.content||this.editor.commands.command(yk(t.bnBlock.beforePos,{type:"heading",props:{level:e}}))}]))},parseHTML(){const e=this.options.editor;return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},...e.settings.heading.levels.map(e=>({tag:`h${e}`,attrs:{level:e},node:"heading"}))]},renderHTML({node:e,HTMLAttributes:t}){var n,o;return gw(this.name,`h${e.attrs.level}`,{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...t},(null==(o=this.options.domAttributes)?void 0:o.inlineContent)||{})},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n})=>{var o,r;const{dom:i,contentDOM:s}=gw(this.name,`h${e.attrs.level}`,{...(null==(o=this.options.domAttributes)?void 0:o.blockContent)||{},...t},(null==(r=this.options.domAttributes)?void 0:r.inlineContent)||{});i.removeChild(s);const l=this.options.editor,a=Cw(n,l,this.editor,this.name),c=Jk(a,l,s);return i.appendChild(c.dom),{dom:i,contentDOM:s,ignoreMutation:c.ignoreMutation,destroy:c.destroy}}}}),Qk=Rw(Yk,Xk),eC=(e,t,n,o,r,i)=>{const{dom:s,destroy:l}=Ak(e,t,n,r,i),a=s;e.props.url&&e.props.showPreview&&(e.props.previewWidth?a.style.width=`${e.props.previewWidth}px`:a.style.width="fit-content");const c=document.createElement("div");c.className="bn-resize-handle",c.style.left="4px";const d=document.createElement("div");d.className="bn-resize-handle",d.style.right="4px";let u,h=e.props.previewWidth;const p=n=>{var r,i;if(!u)return void(!t.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d)));let s;s="center"===e.props.textAlignment?"left"===u.handleUsed?u.initialWidth+2*(u.initialClientX-n.clientX):u.initialWidth+2*(n.clientX-u.initialClientX):"left"===u.handleUsed?u.initialWidth+u.initialClientX-n.clientX:u.initialWidth+n.clientX-u.initialClientX,h=Math.min(Math.max(s,64),(null==(i=null==(r=t.domElement)?void 0:r.firstElementChild)?void 0:i.clientWidth)||Number.MAX_VALUE),a.style.width=`${h}px`},f=n=>{(!n.target||!a.contains(n.target)||!t.isEditable)&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d)),u&&(u=void 0,t.updateBlock(e,{props:{previewWidth:h}}))},m=()=>{t.isEditable&&(o.appendChild(c),o.appendChild(d))},g=e=>{e.relatedTarget===c||e.relatedTarget===d||u||t.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d))},y=e=>{e.preventDefault(),u={handleUsed:"left",initialWidth:a.clientWidth,initialClientX:e.clientX}},b=e=>{e.preventDefault(),u={handleUsed:"right",initialWidth:a.clientWidth,initialClientX:e.clientX}};return window.addEventListener("mousemove",p),window.addEventListener("mouseup",f),a.addEventListener("mouseenter",m),a.addEventListener("mouseleave",g),c.addEventListener("mousedown",y),d.addEventListener("mousedown",b),{dom:a,destroy:()=>{null==l||l(),window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",f),a.removeEventListener("mouseenter",m),a.removeEventListener("mouseleave",g),c.removeEventListener("mousedown",y),d.removeEventListener("mousedown",b)}}},tC=e=>({url:e.src||void 0,previewWidth:e.width||void 0,name:e.alt||void 0}),nC={type:"image",propSchema:{textAlignment:bw.textAlignment,backgroundColor:bw.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},content:"none",isFileBlock:!0,fileBlockAccept:["image/*"]},oC=e=>{if("IMG"===e.tagName)return e.closest("figure")?void 0:tC(e);if("FIGURE"===e.tagName){const t=Nk(e,"img");if(!t)return;const{targetElement:n,caption:o}=t;return{...tC(n),caption:o}}},rC=Aw(nC,{render:(e,t)=>{const n=document.createElement("div");n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M5 11.1005L7 9.1005L12.5 14.6005L16 11.1005L19 14.1005V5H5V11.1005ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM15.5 10C14.6716 10 14 9.32843 14 8.5C14 7.67157 14.6716 7 15.5 7C16.3284 7 17 7.67157 17 8.5C17 9.32843 16.3284 10 15.5 10Z"></path></svg>';const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("img");return r.className="bn-visual-media",t.resolveFileUrl?t.resolveFileUrl(e.props.url).then(e=>{r.src=e}):r.src=e.props.url,r.alt=e.props.name||e.props.caption||"BlockNote image",r.contentEditable="false",r.draggable=!1,o.appendChild(r),eC(e,t,{dom:o},o,t.dictionary.file_blocks.image.add_button_text,n.firstElementChild)},parse:oC,toExternalHTML:e=>{if(!e.props.url){const e=document.createElement("p");return e.textContent="Add image",{dom:e}}let t;return e.props.showPreview?(t=document.createElement("img"),t.src=e.props.url,t.alt=e.props.name||e.props.caption||"BlockNote image",e.props.previewWidth&&(t.width=e.props.previewWidth)):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ok(t,e.props.caption):_k(t,e.props.caption):{dom:t}}}),iC=(e,t,n)=>({state:o,dispatch:r})=>{const i=Pw(Ow(o.doc,e));if(!i.isBlockContainer)throw new Error(`BlockContainer expected when calling splitBlock, position ${e}`);const s=[{type:i.bnBlock.node.type,attrs:n?{...i.bnBlock.node.attrs,id:void 0}:{}},{type:t?i.blockContent.node.type:o.schema.nodes.paragraph,attrs:n?{...i.blockContent.node.attrs}:{}}];return r&&o.tr.split(e,2,s),!0},sC=e=>{const{blockInfo:t,selectionEmpty:n}=e.transact(e=>({blockInfo:Dw(e),selectionEmpty:e.selection.anchor===e.selection.head}));if(!t.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=t;return!("toggleListItem"!==r.node.type.name&&"bulletListItem"!==r.node.type.name&&"numberedListItem"!==r.node.type.name&&"checkListItem"!==r.node.type.name||!n)&&e._tiptapEditor.commands.first(({state:e,chain:t,commands:n})=>[()=>n.command(()=>0===r.node.childCount&&n.command(yk(o.beforePos,{type:"paragraph",props:{}}))),()=>n.command(()=>r.node.childCount>0&&(t().deleteSelection().command(iC(e.selection.from,!0)).run(),!0))])},lC={...bw},aC=Sw({name:"toggleListItem",content:"inline*",group:"blockContent",priority:90,addKeyboardShortcuts(){return{Enter:()=>sC(this.options.editor),"Mod-Shift-6":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"toggleListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"p",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})},addNodeView(){return({HTMLAttributes:e,getPos:t})=>{var n,o;const{dom:r,contentDOM:i}=gw(this.name,"p",{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...e},(null==(o=this.options.domAttributes)?void 0:o.inlineContent)||{}),s=this.options.editor,l=Cw(t,s,this.editor,this.name),a=Jk(l,s,i);return r.appendChild(a.dom),{dom:r,contentDOM:i,ignoreMutation:a.ignoreMutation,destroy:a.destroy}}}}),cC=Rw(aC,lC);function dC(e,t,n){var o,r,i;const s=vo.fromSchema(t),l=e,a=document.createElement("div");a.setAttribute("data-node-type","blockGroup");for(const p of Array.from(l.childNodes))a.appendChild(p.cloneNode(!0));let c=s.parse(a,{topNode:t.nodes.blockGroup.create()});"checkListItem"===(null==(r=null==(o=c.firstChild)?void 0:o.firstChild)?void 0:r.type.name)&&(c=c.copy(c.content.cut(c.firstChild.firstChild.nodeSize+2)));const d=null==(i=c.firstChild)?void 0:i.firstChild;if(null==d||!d.isTextblock)return Rn.from(c);const u=t.nodes[n].create({},d.content),h=c.content.cut(d.nodeSize+2);if(h.size>0){const e=c.copy(h);return u.content.addToEnd(e)}return u.content}const uC={...bw},hC=Rw(Sw({name:"bulletListItem",content:"inline*",group:"blockContent",priority:90,addInputRules:()=>[new uc({find:new RegExp("^[-+*]\\s$"),handler:({state:e,chain:t,range:n})=>{const o=Lw(e);!o.isBlockContainer||"inline*"!==o.blockContent.node.type.spec.content||"heading"===o.blockNoteType||t().command(yk(o.bnBlock.beforePos,{type:"bulletListItem",props:{}})).deleteRange({from:n.from,to:n.to})}})],addKeyboardShortcuts(){return{Enter:()=>sC(this.options.editor),"Mod-Shift-8":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"bulletListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if("string"==typeof e)return!1;const n=e.parentElement;return null!==n&&(("UL"===n.tagName||"DIV"===n.tagName&&"UL"===(null==(t=n.parentElement)?void 0:t.tagName))&&{})},getContent:(e,t)=>dC(e,t,this.name),node:"bulletListItem"}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"p",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})}}),uC),pC={...bw,checked:{default:!1}},fC=Sw({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes:()=>kw(pC),addInputRules:()=>[new uc({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:t,range:n})=>{const o=Lw(e);!o.isBlockContainer||"inline*"!==o.blockContent.node.type.spec.content||t().command(yk(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!1}})).deleteRange({from:n.from,to:n.to})}}),new uc({find:new RegExp("\\[[Xx]\\]\\s$"),handler:({state:e,chain:t,range:n})=>{const o=Lw(e);!o.isBlockContainer||"inline*"!==o.blockContent.node.type.spec.content||t().command(yk(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!0}})).deleteRange({from:n.from,to:n.to})}})],addKeyboardShortcuts(){return{Enter:()=>sC(this.options.editor),"Mod-Shift-9":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"checkListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"input",getAttrs:e=>"string"!=typeof e&&!e.closest("[data-content-type]")&&!e.closest("li")&&("checkbox"===e.type&&{checked:e.checked}),node:"checkListItem"},{tag:"li",getAttrs:e=>{var t;if("string"==typeof e)return!1;const n=e.parentElement;if(null===n)return!1;if("UL"===n.tagName||"DIV"===n.tagName&&"UL"===(null==(t=n.parentElement)?void 0:t.tagName)){const t=e.querySelector("input[type=checkbox]")||null;return null!==t&&{checked:t.checked}}return!1},getContent:(e,t)=>dC(e,t,this.name),node:"checkListItem"}]},renderHTML({node:e,HTMLAttributes:t}){var n,o;const r=document.createElement("input");r.type="checkbox",r.checked=e.attrs.checked,e.attrs.checked&&r.setAttribute("checked","");const{dom:i,contentDOM:s}=gw(this.name,"p",{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...t},(null==(o=this.options.domAttributes)?void 0:o.inlineContent)||{});return i.insertBefore(r,s),{dom:i,contentDOM:s}},addNodeView(){return({node:e,getPos:t,editor:n,HTMLAttributes:o})=>{var r,i;const s=document.createElement("div"),l=document.createElement("div");l.contentEditable="false";const a=document.createElement("input");a.type="checkbox",a.checked=e.attrs.checked,e.attrs.checked&&a.setAttribute("checked","");const c=()=>{if(n.isEditable){if("boolean"!=typeof t){const e=Ow(n.state.doc,t());if("blockContainer"!==e.node.type.name)throw new Error(`Expected blockContainer node, got ${e.node.type.name}`);this.editor.commands.command(yk(e.posBeforeNode,{type:"checkListItem",props:{checked:a.checked}}))}}else a.checked=!a.checked};a.addEventListener("change",c);const{dom:d,contentDOM:u}=gw(this.name,"p",{...(null==(r=this.options.domAttributes)?void 0:r.blockContent)||{},...o},(null==(i=this.options.domAttributes)?void 0:i.inlineContent)||{});if("boolean"!=typeof t){const e="label-"+this.editor.state.doc.resolve(t()).node().attrs.id;a.setAttribute("aria-labelledby",e),u.id=e}return d.removeChild(u),d.appendChild(s),s.appendChild(l),s.appendChild(u),l.appendChild(a),{dom:d,contentDOM:u,destroy:()=>{a.removeEventListener("change",c)}}}}}),mC=Rw(fC,pC),gC=new Kr("numbered-list-indexing"),yC={...bw,start:{default:void 0,type:"number"}},bC=Sw({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes:()=>({...kw(yC),index:{default:null,parseHTML:e=>e.getAttribute("data-index"),renderHTML:e=>({"data-index":e.index})}}),addInputRules:()=>[new uc({find:new RegExp("^(\\d+)\\.\\s$"),handler:({state:e,chain:t,range:n,match:o})=>{const r=Lw(e);if(!r.isBlockContainer||"inline*"!==r.blockContent.node.type.spec.content||"numberedListItem"===r.blockNoteType||"heading"===r.blockNoteType)return;const i=parseInt(o[1]);t().command(yk(r.bnBlock.beforePos,{type:"numberedListItem",props:1===i&&{}||{start:i}})).deleteRange({from:n.from,to:n.to})}})],addKeyboardShortcuts(){return{Enter:()=>sC(this.options.editor),"Mod-Shift-7":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"numberedListItem",props:{}}))}}},addProseMirrorPlugins:()=>[new Wr({key:gC,appendTransaction:(e,t,n)=>{const o=n.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return n.doc.descendants((e,t)=>{var n;if("blockContainer"===e.type.name&&"numberedListItem"===e.firstChild.type.name){let i=`${e.firstChild.attrs.start||1}`;const s=Pw({posBeforeNode:t,node:e});if(!s.isBlockContainer)throw new Error("impossible");const l=o.doc.resolve(s.bnBlock.beforePos).nodeBefore;if(l){const e=Pw({posBeforeNode:s.bnBlock.beforePos-l.nodeSize,node:l});if("numberedListItem"===e.blockNoteType){if(!e.isBlockContainer)throw new Error("impossible");const t=e.blockContent.node.attrs.index;i=(parseInt(t)+1).toString()}}const a=s.blockContent.node,c=a.attrs.index,d="numberedListItem"!==(null==(n=null==l?void 0:l.firstChild)?void 0:n.type.name);if(c!==i||a.attrs.start&&!d){r=!0;const{start:e,...t}=a.attrs;o.setNodeMarkup(s.blockContent.beforePos,void 0,{...t,index:i,..."number"==typeof e&&d&&{start:e}})}}}),r?o:null}})],parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if("string"==typeof e)return!1;const n=e.parentElement;if(null===n)return!1;if("OL"===n.tagName||"DIV"===n.tagName&&"OL"===(null==(t=n.parentElement)?void 0:t.tagName)){const t=parseInt(n.getAttribute("start")||"1")||1;return e.previousSibling||1===t?{}:{start:t}}return!1},getContent:(e,t)=>dC(e,t,this.name),priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"p",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})}}),vC=Rw(bC,yC),xC={...bw},wC=Rw(Sw({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"paragraph",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"p",getAttrs:e=>{var t;return!("string"==typeof e||null==(t=e.textContent)||!t.trim())&&{}},node:"paragraph"}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"p",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})}}),xC),kC={...bw},CC=Rw(Sw({name:"quote",content:"inline*",group:"blockContent",addInputRules:()=>[new uc({find:new RegExp("^>\\s$"),handler:({state:e,chain:t,range:n})=>{const o=Lw(e);!o.isBlockContainer||"inline*"!==o.blockContent.node.type.spec.content||t().command(yk(o.bnBlock.beforePos,{type:"quote",props:{}})).deleteRange({from:n.from,to:n.to})}})],addKeyboardShortcuts(){return{"Mod-Alt-q":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"quote"}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"blockquote",node:"quote",getContent:(e,t)=>{const n=e.cloneNode(!0);return function(e){const t=e.querySelectorAll("p");if(t.length>1){const e=t[0];for(let n=1;n<t.length;n++){const o=t[n];e.innerHTML+="<br>"+o.innerHTML,o.remove()}}}(n),vo.fromSchema(t).parse(n,{topNode:t.nodes.paragraph.create()}).content}}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"blockquote",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})}}),kC),EC=kc.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[Tu({cellMinWidth:35,defaultCellMinWidth:120,View:null}),Iu()],addKeyboardShortcuts(){return{Enter:()=>!(!this.editor.state.selection.empty||"tableParagraph"!==this.editor.state.selection.$head.parent.type.name)&&(this.editor.commands.insertContent({type:"hardBreak"}),!0),Backspace:()=>{const e=this.editor.state.selection,t=e.empty,n=0===e.$head.parentOffset,o="tableParagraph"===e.$head.node().type.name;return t&&n&&o},Tab:()=>this.editor.commands.command(({state:e,dispatch:t,view:n})=>au(1)(e,t,n)),"Shift-Tab":()=>this.editor.commands.command(({state:e,dispatch:t,view:n})=>au(-1)(e,t,n))}},extendNodeSchema:e=>({tableRole:oc(Ja(e,"tableRole",{name:e.name,options:e.options,storage:e.storage}))})}),SC={textColor:bw.textColor},MC=Sw({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",marks:"deletion insertion modification",isolating:!0,parseHTML:()=>[{tag:"table"}],renderHTML({node:e,HTMLAttributes:t}){var n,o,r;const i=gw(this.name,"table",{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...t},(null==(o=this.options.domAttributes)?void 0:o.inlineContent)||{}),s=document.createElement("colgroup");for(const l of e.children[0].children)if(l.attrs.colwidth)for(const e of l.attrs.colwidth){const t=document.createElement("col");e&&(t.style=`width: ${e}px`),s.appendChild(t)}else s.appendChild(document.createElement("col"));return null==(r=i.dom.firstChild)||r.appendChild(s),i},addNodeView(){return({node:e,HTMLAttributes:t})=>{var n;return new class extends Su{constructor(e,t,n){super(e,t),this.node=e,this.cellMinWidth=t,this.blockContentHTMLAttributes=n;const o=document.createElement("div");o.className=fw("bn-block-content",n.class),o.setAttribute("data-content-type","table");for(const[l,a]of Object.entries(n))"class"!==l&&o.setAttribute(l,a);const r=this.dom,i=document.createElement("div");i.className="tableWrapper-inner",i.appendChild(r.firstChild),r.appendChild(i),o.appendChild(r);const s=document.createElement("div");s.className="table-widgets-container",s.style.position="relative",r.appendChild(s),this.dom=o}ignoreMutation(e){return!e.target.closest(".tableWrapper-inner")||super.ignoreMutation(e)}}(e,120,{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...t})}}}),RC=Sw({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML:()=>[{tag:"p",getAttrs:e=>{if("string"==typeof e||!e.textContent||!e.closest("[data-content-type]"))return!1;const t=e.parentElement;return null!==t&&(("TD"===t.tagName||"TH"===t.tagName)&&{})},node:"tableParagraph"}],renderHTML:({node:e,HTMLAttributes:t})=>["p",t,e.childCount?0:["br"]]}),TC=kd.create({name:"tableRow",addOptions:()=>({HTMLAttributes:{}}),content:"(tableCell | tableHeader)+",tableRole:"row",marks:"deletion insertion modification",parseHTML:()=>[{tag:"tr"}],renderHTML({HTMLAttributes:e}){return["tr",ec(this.options.HTMLAttributes,e),0]}});function jC(e,t){const n=vo.fromSchema(t).parse(e,{topNode:t.nodes.blockGroup.create()}),o=[];return n.content.descendants(e=>{if(e.isInline)return o.push(e),!1}),Rn.fromArray(o)}const NC=Rw(MC,SC,[EC,RC,sh.extend({content:"tableContent+",parseHTML:()=>[{tag:"th",getContent:(e,t)=>jC(e,t)}]}),ih.extend({content:"tableContent+",parseHTML:()=>[{tag:"td",getContent:(e,t)=>jC(e,t)}]}),TC]),AC=e=>({url:e.src||void 0,previewWidth:e.width||void 0}),OC={type:"video",propSchema:{textAlignment:bw.textAlignment,backgroundColor:bw.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},content:"none",isFileBlock:!0,fileBlockAccept:["video/*"]},_C=e=>{if("VIDEO"===e.tagName)return e.closest("figure")?void 0:AC(e);if("FIGURE"===e.tagName){const t=Nk(e,"video");if(!t)return;const{targetElement:n,caption:o}=t;return{...AC(n),caption:o}}},PC={paragraph:wC,heading:Qk,quote:CC,codeBlock:$k,toggleListItem:cC,bulletListItem:hC,numberedListItem:vC,checkListItem:mC,table:NC,file:Kk,image:rC,video:Aw(OC,{render:(e,t)=>{const n=document.createElement("div");n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>';const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("video");return r.className="bn-visual-media",t.resolveFileUrl?t.resolveFileUrl(e.props.url).then(e=>{r.src=e}):r.src=e.props.url,r.controls=!0,r.contentEditable="false",r.draggable=!1,r.width=e.props.previewWidth,o.appendChild(r),eC(e,t,{dom:o},o,t.dictionary.file_blocks.video.add_button_text,n.firstElementChild)},parse:_C,toExternalHTML:e=>{if(!e.props.url){const e=document.createElement("p");return e.textContent="Add video",{dom:e}}let t;return e.props.showPreview?(t=document.createElement("video"),t.src=e.props.url,e.props.previewWidth&&(t.width=e.props.previewWidth)):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ok(t,e.props.caption):_k(t,e.props.caption):{dom:t}}}),audio:Dk},IC=Tw(PC),LC={bold:Zw(qu,"boolean"),italic:Zw(eh,"boolean"),underline:Zw(rh,"boolean"),strike:Zw(oh,"boolean"),code:Zw(Zu,"boolean"),textColor:Uk,backgroundColor:Fk};Jw(LC);const DC={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},BC=Kw(DC);function HC(e,t){return e in t.schema.blockSchema&&t.schema.blockSchema[e]===IC[e]}function VC(e,t){return e.type in t.schema.blockSchema&&t.schema.blockSchema[e.type].isFileBlock||!1}function $C(e,t){return t.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function zC(e,t,n){return t in n.schema.blockSchema&&e in n.schema.blockSchema[t].propSchema&&n.schema.blockSchema[t].propSchema[e]===bw[e]}function FC(e,t,n){return zC(e,t.type,n)}function UC(e){return e instanceof Gd}function WC(e,t){const n=e.getTextCursorPosition().block;if(void 0===n.content)throw new Error("Slash Menu open in a block that doesn't contain content.");let o;return Array.isArray(n.content)&&(1===n.content.length&&iw(n.content[0])&&"text"===n.content[0].type&&"/"===n.content[0].text||0===n.content.length)?(o=e.updateBlock(n,t),e.setTextCursorPosition(o)):(o=e.insertBlocks([t],n,"after")[0],e.setTextCursorPosition(e.getTextCursorPosition().nextBlock)),function(e){let t=e.getTextCursorPosition().block,n=e.schema.blockSchema[t.type].content;for(;"none"===n;){if(t=e.getTextCursorPosition().nextBlock,void 0===t)return;n=e.schema.blockSchema[t.type].content,e.setTextCursorPosition(t,"end")}}(e),o}function qC(e){return e&&Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e))}let GC=class e{constructor(e){ew(this,"blockSpecs"),ew(this,"inlineContentSpecs"),ew(this,"styleSpecs"),ew(this,"blockSchema"),ew(this,"inlineContentSchema"),ew(this,"styleSchema"),ew(this,"BlockNoteEditor","only for types"),ew(this,"Block","only for types"),ew(this,"PartialBlock","only for types"),this.blockSpecs=qC(null==e?void 0:e.blockSpecs)||PC,this.inlineContentSpecs=qC(null==e?void 0:e.inlineContentSpecs)||DC,this.styleSpecs=qC(null==e?void 0:e.styleSpecs)||LC,this.blockSchema=Tw(this.blockSpecs),this.inlineContentSchema=Kw(this.inlineContentSpecs),this.styleSchema=Jw(this.styleSpecs)}static create(t){return new e(t)}};const KC=Aw({type:"pageBreak",propSchema:{},content:"none",isFileBlock:!1,isSelectable:!1},{render:()=>{const e=document.createElement("div");return e.className="bn-page-break",e.setAttribute("data-page-break",""),{dom:e}},parse:e=>{if("DIV"===e.tagName&&e.hasAttribute("data-page-break"))return{type:"pageBreak"}},toExternalHTML:()=>{const e=document.createElement("div");return e.setAttribute("data-page-break",""),{dom:e}}});function ZC(e){return e.map(e=>"columnList"===e.type?e.children.map(e=>ZC(e.children)).flat():{...e,children:ZC(e.children)}).flat()}function JC(e,t,n){e.transact(o=>{var r;const i=(null==(r=e.getSelection())?void 0:r.blocks)||[e.getTextCursorPosition().block],s=function(e){return e.transact(e=>{const t=Ow(e.doc,e.selection.anchor);if(e.selection instanceof Gd)return{type:"cell",anchorBlockId:t.node.attrs.id,anchorCellOffset:e.selection.$anchorCell.pos-t.posBeforeNode,headCellOffset:e.selection.$headCell.pos-t.posBeforeNode};if(e.selection instanceof Or)return{type:"node",anchorBlockId:t.node.attrs.id};{const n=Ow(e.doc,e.selection.head);return{type:"text",anchorBlockId:t.node.attrs.id,headBlockId:n.node.attrs.id,anchorOffset:e.selection.anchor-t.posBeforeNode,headOffset:e.selection.head-n.posBeforeNode}}})}(e);e.removeBlocks(i),e.insertBlocks(ZC(i),t,n),function(e,t){var n,o;const r=null==(n=fk(t.anchorBlockId,e.doc))?void 0:n.posBeforeNode;if(void 0===r)throw new Error(`Could not find block with ID ${t.anchorBlockId} to update selection`);let i;if("cell"===t.type)i=Gd.create(e.doc,r+t.anchorCellOffset,r+t.headCellOffset);else if("node"===t.type)i=Or.create(e.doc,r+1);else{const n=null==(o=fk(t.headBlockId,e.doc))?void 0:o.posBeforeNode;if(void 0===n)throw new Error(`Could not find block with ID ${t.headBlockId} to update selection`);i=Nr.create(e.doc,r+t.anchorOffset,n+t.headOffset)}e.setSelection(i)}(o,s)})}function XC(e){return!e||"columnList"!==e.type}function YC(e,t,n){let o,r;if(t?t.children.length>0?(o=t.children[t.children.length-1],r="after"):(o=t,r="before"):n&&(o=n,r="before"),!o||!r)return;const i=e.getParentBlock(o);return XC(i)?{referenceBlock:o,placement:r}:YC(e,"after"===r?o:e.getPrevBlock(o),i)}function QC(e,t,n){let o,r;if(t?t.children.length>0?(o=t.children[0],r="before"):(o=t,r="after"):n&&(o=n,r="after"),!o||!r)return;const i=e.getParentBlock(o);return XC(i)?{referenceBlock:o,placement:r}:QC(e,"before"===r?o:e.getNextBlock(o),i)}function eE(e){e.transact(()=>{const t=e.getSelection(),n=(null==t?void 0:t.blocks[0])||e.getTextCursorPosition().block,o=YC(e,e.getPrevBlock(n),e.getParentBlock(n));o&&JC(e,o.referenceBlock,o.placement)})}function tE(e){e.transact(()=>{const t=e.getSelection(),n=(null==t?void 0:t.blocks[(null==t?void 0:t.blocks.length)-1])||e.getTextCursorPosition().block,o=QC(e,e.getNextBlock(n),e.getParentBlock(n));o&&JC(e,o.referenceBlock,o.placement)})}function nE(e){return e.transact(t=>function(e,t,n){const{$from:o,$to:r}=e.selection,i=o.blockRange(r,e=>e.childCount>0&&("blockGroup"===e.type.name||"column"===e.type.name));if(!i)return!1;const s=i.startIndex;if(0===s)return!1;const l=i.parent.child(s-1);if(l.type!==t)return!1;const a=l.lastChild&&l.lastChild.type===n,c=Rn.from(a?t.create():null),d=new _n(Rn.from(t.create(null,Rn.from(n.create(null,c)))),a?3:1,0),u=i.start,h=i.end;return e.step(new Jo(u-(a?3:1),h,u,h,d,1,!0)).scrollIntoView(),!0}(t,e.pmSchema.nodes.blockContainer,e.pmSchema.nodes.blockGroup))}function oE(e){const t=Bw(e);let n=e.selection.$from,o=e.selection.$to;for(;o.parentOffset>=o.parent.nodeSize-2&&o.depth>0;)o=e.doc.resolve(o.pos+1);for(;0===o.parentOffset&&o.depth>0;)o=e.doc.resolve(o.pos-1);for(;0===n.parentOffset&&n.depth>0;)n=e.doc.resolve(n.pos-1);for(;n.parentOffset>=n.parent.nodeSize-2&&n.depth>0;)n=e.doc.resolve(n.pos+1);const r=function(e,t,n=$w(t),o=zw(t),r=Fw(t),i=Uw(t)){if(0===e.content.childCount)return{blocks:[],blockCutAtStart:void 0,blockCutAtEnd:void 0};if(1!==e.content.childCount)throw new Error("slice must be a single block, did you forget includeParents=true?");return function e(s,l,a){if("blockGroup"!==s.type.name)throw new Error("unexpected");const c=[];let d,u;return s.forEach((h,p,f)=>{if("blockContainer"!==h.type.name)throw new Error("unexpected");if(0===h.childCount)return;if(0===h.childCount||h.childCount>2)throw new Error("unexpected, blockContainer.childCount: "+h.childCount);const m=0===f,g=f===s.childCount-1;if("blockGroup"===h.firstChild.type.name){if(!m)throw new Error("unexpected");const t=e(h.firstChild,Math.max(0,l-1),g?Math.max(0,a-1):0);return d=t.blockCutAtStart,g&&(u=t.blockCutAtEnd),void c.push(...t.blocks)}const y=Gw(h,t,n,o,r,i),b=h.childCount>1?h.child(1):void 0;let v=[];if(b){const t=e(b,0,g?Math.max(0,a-1):0);v=t.blocks,g&&(u=t.blockCutAtEnd)}g&&!b&&a>1&&(u=y.id),m&&l>1&&(d=y.id),c.push({...y,children:v})}),{blocks:c,blockCutAtStart:d,blockCutAtEnd:u}}(e.content.firstChild,Math.max(e.openStart-1,0),Math.max(e.openEnd-1,0))}(e.doc.slice(n.pos,o.pos,!0),t);return{_meta:{startPos:n.pos,endPos:o.pos},...r}}function rE(e,t,n="start"){const o="string"==typeof t?t:t.id,r=Vw(Bw(e.doc)),i=fk(o,e.doc);if(!i)throw new Error(`Block with ID ${o} not found`);const s=Pw(i),l=r.blockSchema[s.blockNoteType].content;if(s.isBlockContainer){const t=s.blockContent;if("none"===l)return void e.setSelection(Or.create(e.doc,t.beforePos));if("inline"===l)"start"===n?e.setSelection(Nr.create(e.doc,t.beforePos+1)):e.setSelection(Nr.create(e.doc,t.afterPos-1));else{if("table"!==l)throw new uw(l);"start"===n?e.setSelection(Nr.create(e.doc,t.beforePos+4)):e.setSelection(Nr.create(e.doc,t.afterPos-4))}}else{rE(e,("start"===n?s.childContainer.node.firstChild:s.childContainer.node.lastChild).attrs.id,n)}}let iE;async function sE(){if(iE)return iE;const e=await Promise.all([Promise.resolve().then(()=>require("./index-CUTMmRLO.cjs")),Promise.resolve().then(()=>require("./index-D1EyeOGY.cjs")),Promise.resolve().then(()=>require("./index-D3WYQbg9.cjs")),Promise.resolve().then(()=>require("./index-DkwjGulR.cjs")),Promise.resolve().then(()=>require("./index-NFb6Ikqb.cjs")),Promise.resolve().then(()=>require("./index-CvkY01OP.cjs")),Promise.resolve().then(()=>require("./index-5hC-EuRW.cjs")),Promise.resolve().then(()=>require("./index-CUbh3CUk.cjs")),Promise.resolve().then(()=>require("./index-DKj4xxCF.cjs")),Promise.resolve().then(()=>require("./index-DiJKM8e3.cjs"))]);return iE={rehypeParse:e[0],rehypeStringify:e[1],unified:e[2],hastUtilFromDom:e[3],rehypeRemark:e[4],remarkGfm:e[5],remarkStringify:e[6],remarkParse:e[7],remarkRehype:e[8],rehypeFormat:e[9]},iE}function lE(){const e=t=>{let n=t.children.length;for(let o=0;o<n;o++){const r=t.children[o];if("element"===r.type&&(e(r),"u"===r.tagName))if(r.children.length>0){t.children.splice(o,1,...r.children);const e=r.children.length-1;n+=e,o+=e}else t.children.splice(o,1),n--,o--}};return e}function aE(){const e=iE;if(!e)throw new Error("addSpacesToCheckboxes requires ESM dependencies to be initialized");const t=n=>{var o;if(n.children&&"length"in n.children&&n.children.length)for(let r=n.children.length-1;r>=0;r--){const i=n.children[r],s=r+1<n.children.length?n.children[r+1]:void 0;"element"===i.type&&"input"===i.tagName&&"checkbox"===(null==(o=i.properties)?void 0:o.type)&&"element"===(null==s?void 0:s.type)&&"p"===s.tagName?(s.tagName="span",s.children.splice(0,0,e.hastUtilFromDom.fromDom(document.createTextNode(" ")))):t(i)}};return t}function cE(e){const t=iE;if(!t)throw new Error("cleanHTMLToMarkdown requires ESM dependencies to be initialized");return t.unified.unified().use(t.rehypeParse.default,{fragment:!0}).use(lE).use(aE).use(t.rehypeRemark.default).use(t.remarkGfm.default).use(t.remarkStringify.default,{handlers:{text:e=>e.value}}).processSync(e).value}function dE(e){e.querySelectorAll("li > ul, li > ol").forEach(e=>{const t=function(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}(e),n=e.parentElement,o=Array.from(n.childNodes).slice(t+1);e.remove(),o.forEach(e=>{e.remove()}),n.insertAdjacentElement("afterend",e),o.reverse().forEach(t=>{if(function(e){return 3===e.nodeType&&!/\S/.test(e.nodeValue||"")}(t))return;const n=document.createElement("li");n.append(t),e.insertAdjacentElement("afterend",n)}),0===n.childNodes.length&&n.remove()})}GC.create({blockSpecs:{pageBreak:KC}});let uE=null;function hE(e){if("string"==typeof e){const t=(uE||(uE=document.implementation.createHTMLDocument("title"))).createElement("div");t.innerHTML=e,e=t}return dE(e),function(e){e.querySelectorAll("li + ul, li + ol").forEach(e=>{var t,n;const o=e.previousElementSibling,r=document.createElement("div");o.insertAdjacentElement("afterend",r),r.append(o);const i=document.createElement("div");for(i.setAttribute("data-node-type","blockGroup"),r.append(i);"UL"===(null==(t=r.nextElementSibling)?void 0:t.nodeName)||"OL"===(null==(n=r.nextElementSibling)?void 0:n.nodeName);)i.append(r.nextElementSibling)})}(e),e}async function pE(e,t){const n=hE(e),o=vo.fromSchema(t).parse(n,{topNode:t.nodes.blockGroup.create()}),r=[];for(let i=0;i<o.childCount;i++)r.push(Gw(o.child(i),t));return r}function fE(e,t){const n=t.value?t.value:"",o={};t.lang&&(o["data-language"]=t.lang);let r={type:"element",tagName:"code",properties:o,children:[{type:"text",value:n}]};return t.meta&&(r.data={meta:t.meta}),e.patch(t,r),r=e.applyData(t,r),r={type:"element",tagName:"pre",properties:{},children:[r]},e.patch(t,r),r}async function mE(e){const t=await sE();return t.unified.unified().use(t.remarkParse.default).use(t.remarkGfm.default).use(t.remarkRehype.default,{handlers:{...t.remarkRehype.defaultHandlers,code:fE}}).use(t.rehypeStringify.default).processSync(e).value}const gE=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function yE(e,t){if(!e.startsWith(".")||!t.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return e===t}function bE(e,t){const n=e.split("/"),o=t.split("/");if(2!==n.length)throw new Error(`The string ${e} is not a valid MIME type.`);if(2!==o.length)throw new Error(`The string ${t} is not a valid MIME type.`);return"*"===n[1]||"*"===o[1]?n[0]===o[0]:("*"===n[0]||"*"===o[0]||n[0]===o[0])&&n[1]===o[1]}function vE(e,t,n,o="after"){let r;return r=Array.isArray(t.content)&&0===t.content.length?e.updateBlock(t,n).id:e.insertBlocks([n],t,o)[0].id,r}async function xE(e,t){var n;if(!t.uploadFile)return;const o="dataTransfer"in e?e.dataTransfer:e.clipboardData;if(null===o)return;let r=null;for(const l of gE)if(o.types.includes(l)){r=l;break}if("Files"!==r)return;const i=o.items;if(!i)return;e.preventDefault();const s=Object.values(t.schema.blockSchema).filter(e=>e.isFileBlock);for(let l=0;l<i.length;l++){let o="file";for(const e of s)for(const t of e.fileBlockAccept||[]){const n=t.startsWith("."),r=i[l].getAsFile();if(r&&(!n&&r.type&&bE(i[l].type,t)||n&&yE("."+r.name.split(".").pop(),t))){o=e.type;break}}const r=i[l].getAsFile();if(r){const i={type:o,props:{name:r.name}};let s;if("paste"===e.type){const e=t.getTextCursorPosition().block;s=vE(t,e,i)}else{if("drop"!==e.type)return;{const o={left:e.clientX,top:e.clientY},r=null==(n=t.prosemirrorView)?void 0:n.posAtCoords(o);if(!r)return;s=t.transact(e=>{var n;const s=Ow(e.doc,r.pos),l=null==(n=t.prosemirrorView)?void 0:n.dom.querySelector(`[data-id="${s.node.attrs.id}"]`),a=null==l?void 0:l.getBoundingClientRect();return vE(t,t.getBlock(s.node.attrs.id),i,a&&(a.top+a.bottom)/2>o.top?"before":"after")})}}const l=await t.uploadFile(r,s),a="string"==typeof l?{props:{url:l}}:{...l};t.updateBlock(s,a)}}}const wE=e=>kc.create({name:"dropFile",addProseMirrorPlugins:()=>[new Wr({props:{handleDOMEvents:{drop(t,n){if(!e.isEditable)return;let o=null;for(const e of gE)if(n.dataTransfer.types.includes(e)){o=e;break}return null===o||"Files"===o&&(xE(n,e),!0)}}}})]}),kE=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,CE=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,EE=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,SE=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,ME=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,RE=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,TE=/\n{2} {0,3}-{2,48}\n{2}/,jE=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,NE=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,AE=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,OE=/^\s*\|(.+\|)+\s*$/m,_E=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,PE=/^\s*\|(.+\|)+\s*$/m;function IE({event:e,editor:t,prioritizeMarkdownOverHTML:n,plainTextAsMarkdown:o}){var r;if(t.transact(e=>e.selection.$from.parent.type.spec.code&&e.selection.$to.parent.type.spec.code)){const n=null==(r=e.clipboardData)?void 0:r.getData("text/plain");if(n)return t.pasteText(n),!0}let i;for(const l of gE)if(e.clipboardData.types.includes(l)){i=l;break}if(!i)return!0;if("vscode-editor-data"===i)return async function(e,t){const{schema:n}=t.state;if(!e.clipboardData)return!1;const o=e.clipboardData.getData("text/plain");if(!o)return!1;if(!n.nodes.codeBlock)return t.pasteText(o),!0;const r=e.clipboardData.getData("vscode-editor-data"),i=r?JSON.parse(r):void 0,s=null==i?void 0:i.mode;!!s&&t.pasteHTML(`<pre><code class="language-${s}">${o.replace(/\r\n?/g,"\n")}</code></pre>`)}(e,t.prosemirrorView),!0;if("Files"===i)return xE(e,t),!0;const s=e.clipboardData.getData(i);if("blocknote/html"===i)return t.pasteHTML(s,!0),!0;if("text/markdown"===i)return t.pasteMarkdown(s),!0;if(n){const n=e.clipboardData.getData("text/plain");if((e=>kE.test(e)||CE.test(e)||EE.test(e)||SE.test(e)||ME.test(e)||RE.test(e)||TE.test(e)||jE.test(e)||NE.test(e)||AE.test(e)||OE.test(e)||_E.test(e)||PE.test(e))(n))return t.pasteMarkdown(n),!0}return"text/html"===i?(t.pasteHTML(s),!0):o?(t.pasteMarkdown(s),!0):(t.pasteText(s),!0)}const LE=(e,t)=>kc.create({name:"pasteFromClipboard",addProseMirrorPlugins:()=>[new Wr({props:{handleDOMEvents:{paste(n,o){if(o.preventDefault(),e.isEditable)return t({event:o,editor:e,defaultPasteHandler:({prioritizeMarkdownOverHTML:t=!0,plainTextAsMarkdown:n=!0}={})=>IE({event:o,editor:e,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:n})})}}}})]});function DE(e){const t=[];return e.descendants(e=>{var n,o;const r=Bw(e);return"blockContainer"===e.type.name&&"blockGroup"===(null==(n=e.firstChild)?void 0:n.type.name)||("columnList"===e.type.name&&1===e.childCount?(null==(o=e.firstChild)||o.forEach(e=>{t.push(Gw(e,r))}),!1):!e.type.isInGroup("bnBlock")||(t.push(Gw(e,r)),!1))}),t}function BE(e,t){"node"in e.state.selection&&"blockContent"===e.state.selection.node.type.spec.group&&t.transact(t=>t.setSelection(new Or(t.doc.resolve(e.state.selection.from-1))));const n=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,o=e.state.selection.content().content,r=function(e,t,n){var o;let r=!1;const i=e.state.selection instanceof Gd;if(!i){const n=e.state.doc.slice(e.state.selection.from,e.state.selection.to,!1).content,o=[];for(let e=0;e<n.childCount;e++)o.push(n.child(e));r=void 0===o.find(e=>e.type.isInGroup("bnBlock")||"blockGroup"===e.type.name||"blockContent"===e.type.spec.group),r&&(t=n)}let s;const l=Ek(e.state.schema,n);if(i){"table"===(null==(o=t.firstChild)?void 0:o.type.name)&&(t=t.firstChild.content);const e=Ww(t,n.schema.inlineContentSchema,n.schema.styleSchema);s=`<table>${l.exportInlineContent(e,{})}</table>`}else if(r){const e=qw(t,n.schema.inlineContentSchema,n.schema.styleSchema);s=l.exportInlineContent(e,{})}else{const e=DE(t);s=l.exportBlocks(e,{})}return s}(e,o,t);return{clipboardHTML:n,externalHTML:r,markdown:cE(r)}}const HE=()=>{const e=window.getSelection();if(!e||e.isCollapsed)return!0;let t=e.focusNode;for(;t;){if(t instanceof HTMLElement&&"false"===t.getAttribute("contenteditable"))return!0;t=t.parentElement}return!1},VE=(e,t,n)=>{n.preventDefault(),n.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:i}=BE(t,e);n.clipboardData.setData("blocknote/html",o),n.clipboardData.setData("text/html",r),n.clipboardData.setData("text/plain",i)},$E=e=>kc.create({name:"copyToClipboard",addProseMirrorPlugins:()=>(sE(),[new Wr({props:{handleDOMEvents:{copy:(t,n)=>(HE()||VE(e,t,n),!0),cut:(t,n)=>(HE()||(VE(e,t,n),t.editable&&t.dispatch(t.state.tr.deleteSelection())),!0),dragstart(t,n){if(!("node"in t.state.selection)||"blockContent"!==t.state.selection.node.type.spec.group)return;e.transact(e=>e.setSelection(new Or(e.doc.resolve(t.state.selection.from-1)))),n.preventDefault(),n.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:i}=BE(t,e);return n.dataTransfer.setData("blocknote/html",o),n.dataTransfer.setData("text/html",r),n.dataTransfer.setData("text/plain",i),!0}}}})])}),zE=kc.create({name:"blockBackgroundColor",addGlobalAttributes:()=>[{types:["blockContainer","tableCell","tableHeader"],attributes:{backgroundColor:{default:bw.backgroundColor.default,parseHTML:e=>e.hasAttribute("data-background-color")?e.getAttribute("data-background-color"):bw.backgroundColor.default,renderHTML:e=>e.backgroundColor===bw.backgroundColor.default?{}:{"data-background-color":e.backgroundColor}}}}]});class FE{constructor(){ew(this,"callbacks",{})}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),()=>this.off(e,t)}emit(e,...t){const n=this.callbacks[e];n&&n.forEach(e=>e.apply(this,t))}off(e,t){const n=this.callbacks[e];n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e])}removeAllListeners(){this.callbacks={}}}let UE=class extends FE{constructor(...e){super(),ew(this,"plugins",[])}static key(){throw new Error("You must implement the key method in your extension")}addProsemirrorPlugin(e){this.plugins.push(e)}get priority(){}};class WE extends UE{constructor(){super(),ew(this,"beforeChangeCallbacks",[]),this.addProsemirrorPlugin(new Wr({filterTransaction:e=>{let t;return this.beforeChangeCallbacks.reduce((n,o)=>!1===n?n:!1!==o({getChanges:()=>t||(t=jk(e),t),tr:e}),!0)}}))}static key(){return"blockChange"}subscribe(e){return this.beforeChangeCallbacks.push(e),()=>{this.beforeChangeCallbacks=this.beforeChangeCallbacks.filter(t=>t!==e)}}}const qE=class e extends UE{constructor(t){super(),ew(this,"provider"),ew(this,"recentlyUpdatedCursors"),ew(this,"renderCursor",(t,n)=>{let o=this.recentlyUpdatedCursors.get(n);if(!o){const r=(this.collaboration.renderCursor??e.defaultCursorRender)(t);"always"!==this.collaboration.showCursorLabels&&(r.addEventListener("mouseenter",()=>{const e=this.recentlyUpdatedCursors.get(n);e.element.setAttribute("data-active",""),e.hideTimeout&&(clearTimeout(e.hideTimeout),this.recentlyUpdatedCursors.set(n,{element:e.element,hideTimeout:void 0}))}),r.addEventListener("mouseleave",()=>{const e=this.recentlyUpdatedCursors.get(n);this.recentlyUpdatedCursors.set(n,{element:e.element,hideTimeout:setTimeout(()=>{e.element.removeAttribute("data-active")},2e3)})})),o={element:r,hideTimeout:void 0},this.recentlyUpdatedCursors.set(n,o)}return o.element}),ew(this,"updateUser",e=>{this.provider.awareness.setLocalStateField("user",e)}),this.collaboration=t,this.provider=t.provider,this.recentlyUpdatedCursors=new Map,this.provider.awareness.setLocalStateField("user",t.user),"always"!==t.showCursorLabels&&this.provider.awareness.on("change",({updated:e})=>{for(const t of e){const e=this.recentlyUpdatedCursors.get(t);e&&(e.element.setAttribute("data-active",""),e.hideTimeout&&clearTimeout(e.hideTimeout),this.recentlyUpdatedCursors.set(t,{element:e.element,hideTimeout:setTimeout(()=>{e.element.removeAttribute("data-active")},2e3)}))}}),this.addProsemirrorPlugin(Wx(this.provider.awareness,{selectionBuilder:zx,cursorBuilder:this.renderCursor}))}static key(){return"yCursorPlugin"}get priority(){return 999}static isDarkColor(e){const t="#"===e.charAt(0)?e.substring(1,7):e,n=[parseInt(t.substring(0,2),16)/255,parseInt(t.substring(2,4),16)/255,parseInt(t.substring(4,6),16)/255].map(e=>e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4));return.2126*n[0]+.7152*n[1]+.0722*n[2]<=.179}};ew(qE,"defaultCursorRender",e=>{const t=document.createElement("span");t.classList.add("bn-collaboration-cursor__base");const n=document.createElement("span");n.setAttribute("contentedEditable","false"),n.classList.add("bn-collaboration-cursor__caret"),n.setAttribute("style",`background-color: ${e.color}; color: ${qE.isDarkColor(e.color)?"white":"black"}`);const o=document.createElement("span");return o.classList.add("bn-collaboration-cursor__label"),o.setAttribute("style",`background-color: ${e.color}; color: ${qE.isDarkColor(e.color)?"white":"black"}`),o.insertBefore(document.createTextNode(e.name),null),n.insertBefore(o,null),t.insertBefore(document.createTextNode("⁠"),null),t.insertBefore(n,null),t.insertBefore(document.createTextNode("⁠"),null),t});let GE=qE,KE=class extends UE{static key(){return"ySyncPlugin"}constructor(e){super(),this.addProsemirrorPlugin(((e,{colors:t=px,colorMapping:n=new Map,permanentUserData:o=null,onFirstRender:r=()=>{},mapping:i}={})=>{let s=!1;const l=new gx(e,i),a=new Wr({props:{editable:e=>{const t=ex.getState(e);return null==t.snapshot&&null==t.prevSnapshot}},key:ex,state:{init:(r,i)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:o}),apply:(e,t)=>{const n=e.getMeta(ex);if(void 0!==n){t=Object.assign({},t);for(const e in n)t[e]=n[e]}return t.addToHistory=!1!==e.getMeta("addToHistory"),t.isChangeOrigin=void 0!==n&&!!n.isChangeOrigin,t.isUndoRedoOperation=void 0!==n&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,null!==l.prosemirrorView&&(void 0===n||null==n.snapshot&&null==n.prevSnapshot||jg(0,()=>{null!=l.prosemirrorView&&(null==n.restore?l._renderSnapshot(n.snapshot,n.prevSnapshot,t):(l._renderSnapshot(n.snapshot,n.snapshot,t),delete t.restore,delete t.snapshot,delete t.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))})),t}},view:e=>(l.initView(e),null==i&&l._forceRerender(),r(),{update:()=>{const t=a.getState(e.state);if(null==t.snapshot&&null==t.prevSnapshot&&(s||null!==e.state.doc.content.findDiffStart(e.state.doc.type.createAndFill().content))){if(s=!0,!1===t.addToHistory&&!t.isChangeOrigin){const t=tx.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}l.mux(()=>{t.doc.transact(n=>{n.meta.set("addToHistory",t.addToHistory),l._prosemirrorChanged(e.state.doc)},ex)})}},destroy:()=>{l.destroy()}})});return a})(e))}get priority(){return 1001}},ZE=class extends UE{static key(){return"yUndoPlugin"}constructor({editor:e}){super(),this.addProsemirrorPlugin(Zx({trackedOrigins:[e]}))}get priority(){return 1e3}};const JE=gc.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes:()=>({orphan:{parseHTML:e=>!!e.getAttribute("data-orphan"),renderHTML:e=>e.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:e=>e.getAttribute("data-bn-thread-id"),renderHTML:e=>({"data-bn-thread-id":e.threadId}),default:""}}),renderHTML:({HTMLAttributes:e})=>["span",ec(e,{class:"bn-thread-mark"})],parseHTML:()=>[{tag:"span.bn-thread-mark"}],extendMarkSchema:e=>"comment"===e.name?{blocknoteIgnore:!0}:{}});class XE extends FE{constructor(e){super(),ew(this,"userCache",new Map),ew(this,"loadingUsers",new Set),this.resolveUsers=e}async loadUsers(e){const t=e.filter(e=>!this.userCache.has(e)&&!this.loadingUsers.has(e));if(0!==t.length){for(const e of t)this.loadingUsers.add(e);try{const e=await this.resolveUsers(t);for(const t of e)this.userCache.set(t.id,t);this.emit("update",this.userCache)}finally{for(const e of t)this.loadingUsers.delete(e)}}}getUser(e){return this.userCache.get(e)}subscribe(e){return this.on("update",e)}}const YE=new Kr("blocknote-comments");class QE extends UE{constructor(e,t,n){if(super(),ew(this,"userStore"),ew(this,"pendingComment",!1),ew(this,"selectedThreadId"),ew(this,"threadPositions",new Map),ew(this,"updateMarksFromThreads",e=>{this.editor.transact(t=>{t.doc.descendants((n,o)=>{n.marks.forEach(r=>{if(r.type.name===this.markType){const i=r.type,s=r.attrs.threadId,l=e.get(s),a=!(l&&!l.resolved&&!l.deletedAt);if(a!==r.attrs.orphan){const e=Math.max(o,0),l=Math.min(o+n.nodeSize,t.doc.content.size-1,t.doc.content.size-1);t.removeMark(e,l,r),t.addMark(e,l,i.create({...r.attrs,orphan:a})),a&&this.selectedThreadId===s&&(this.selectedThreadId=void 0,this.emitStateUpdate())}}})})})}),this.editor=e,this.threadStore=t,this.markType=n,!e.resolveUsers)throw new Error("resolveUsers is required for comments");this.userStore=new XE(e.resolveUsers),this.threadStore.subscribe(this.updateMarksFromThreads),e.onCreate(()=>{this.updateMarksFromThreads(this.threadStore.getThreads()),e.onSelectionChange(()=>{this.pendingComment&&(this.pendingComment=!1,this.emitStateUpdate())})});const o=this;this.addProsemirrorPlugin(new Wr({key:YE,state:{init:()=>({decorations:Il.empty}),apply(e,t){const n=e.getMeta(YE);if(!e.docChanged&&!n)return t;const r=e.docChanged?function(e,t){const n=new Map;return e.descendants((e,o)=>{e.marks.forEach(r=>{if(r.type.name===t){const t=r.attrs.threadId;if(!t)return;const i=o,s=i+e.nodeSize,l=n.get(t)??{from:1/0,to:0};n.set(t,{from:Math.min(i,l.from),to:Math.max(s,l.to)})}})}),n}(e.doc,o.markType):o.threadPositions;(r.size>0||o.threadPositions.size>0)&&(o.threadPositions=r,o.emitStateUpdate());const i=[];if(o.selectedThreadId){const e=r.get(o.selectedThreadId);e&&i.push(Ol.inline(e.from,e.to,{class:"bn-thread-mark-selected"}))}return{decorations:Il.create(e.doc,i)}}},props:{decorations(e){var t;return(null==(t=YE.getState(e))?void 0:t.decorations)??Il.empty},handleClick:(e,t,r)=>{if(0!==r.button)return;const i=e.state.doc.nodeAt(t);if(!i)return void o.selectThread(void 0);const s=i.marks.find(e=>e.type.name===n&&!0!==e.attrs.orphan),l=null==s?void 0:s.attrs.threadId;o.selectThread(l,!1)}}}))}static key(){return"comments"}emitStateUpdate(){this.emit("update",{selectedThreadId:this.selectedThreadId,pendingComment:this.pendingComment,threadPositions:this.threadPositions})}onUpdate(e){return this.on("update",e)}selectThread(e,t=!0){var n,o;if(this.selectedThreadId!==e&&(this.selectedThreadId=e,this.emitStateUpdate(),this.editor.transact(e=>e.setMeta(YE,{name:"SET_SELECTED_THREAD_ID"})),e&&t)){const t=this.threadPositions.get(e);if(!t)return;null==(o=null==(n=this.editor.prosemirrorView)?void 0:n.domAtPos(t.from).node)||o.scrollIntoView({behavior:"smooth",block:"center"})}}startPendingComment(){this.pendingComment=!0,this.emitStateUpdate()}stopPendingComment(){this.pendingComment=!1,this.emitStateUpdate()}async createThread(e){const t=await this.threadStore.createThread(e);if(this.threadStore.addThreadToDocument){const e=this.editor.prosemirrorView,n=e.state.selection,o=ex.getState(e.state),r={prosemirror:{head:n.head,anchor:n.anchor},yjs:o?mx(o.binding,e.state):void 0};await this.threadStore.addThreadToDocument({threadId:t.id,selection:r})}else this.editor._tiptapEditor.commands.setMark(this.markType,{orphan:!1,threadId:t.id})}}class eS{constructor(e,t,n,o){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"mouseDownHandler",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"dragstartHandler",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"scrollHandler",()=>{var e;if(null!=(e=this.state)&&e.show){const e=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);if(!e)return;this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate()}}),ew(this,"closeMenu",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),this.editor=e,this.pluginKey=t,this.pmView=n,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");o(this.state)},n.dom.addEventListener("mousedown",this.mouseDownHandler),n.dom.addEventListener("dragstart",this.dragstartHandler),n.root.addEventListener("scroll",this.scrollHandler,!0)}update(e,t){var n,o;const r=this.pluginKey.getState(e.state),i=this.pluginKey.getState(t);if((null==(n=this.state)||!n.show)&&null!=r&&r.block&&this.editor.isEditable){const e=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${r.block.id}"]`);if(!e)return;return this.state={show:!0,referencePos:e.getBoundingClientRect(),block:r.block},void this.emitUpdate()}const s=(null==r?void 0:r.block)&&!(null!=i&&i.block),l=!(null!=r&&r.block)&&(null==i?void 0:i.block);s&&this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate()),l&&null!=(o=this.state)&&o.show&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const tS=new Kr("FilePanelPlugin");class nS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"closeMenu",()=>{var e;return null==(e=this.view)?void 0:e.closeMenu()}),this.addProsemirrorPlugin(new Wr({key:tS,view:t=>(this.view=new eS(e,tS,t,e=>{this.emit("update",e)}),this.view),props:{handleKeyDown:(e,t)=>{var n;return!("Escape"!==t.key||!this.shown)&&(null==(n=this.view)||n.closeMenu(),!0)}},state:{init:()=>({block:void 0}),apply:(e,t)=>e.getMeta(tS)||(e.getMeta(ex)||!e.selectionSet&&!e.docChanged?t:{block:void 0})}}))}static key(){return"filePanel"}get shown(){var e,t;return(null==(t=null==(e=this.view)?void 0:e.state)?void 0:t.show)||!1}onUpdate(e){return this.on("update",e)}}class oS{constructor(e,t,n){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"preventHide",!1),ew(this,"preventShow",!1),ew(this,"shouldShow",({view:e,state:t,from:n,to:o})=>{const{doc:r,selection:i}=t,{empty:s}=i,l=!r.textBetween(n,o).length&&Ac(t.selection);if(i.$from.parent.type.spec.code||rd(i)&&i.node.type.spec.code||s||l)return!1;const a=document.activeElement;return!(!this.isElementWithinEditorWrapper(a)&&e.editable)}),ew(this,"blurHandler",e=>{var t;if(this.preventHide)return void(this.preventHide=!1);const n=this.pmView.dom.parentElement;e&&e.relatedTarget&&(n===e.relatedTarget||n.contains(e.relatedTarget)||e.relatedTarget.matches(".bn-ui-container, .bn-ui-container *"))||null!=(t=this.state)&&t.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"isElementWithinEditorWrapper",e=>{if(!e)return!1;const t=this.pmView.dom.parentElement;return!!t&&t.contains(e)}),ew(this,"viewMousedownHandler",e=>{(!this.isElementWithinEditorWrapper(e.target)||0===e.button)&&(this.preventShow=!0)}),ew(this,"mouseupHandler",()=>{this.preventShow&&(this.preventShow=!1,setTimeout(()=>this.update(this.pmView)))}),ew(this,"dragHandler",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"scrollHandler",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())}),ew(this,"closeMenu",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");n(this.state)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.root.addEventListener("mouseup",this.mouseupHandler),t.dom.addEventListener("dragstart",this.dragHandler),t.dom.addEventListener("dragover",this.dragHandler),t.dom.addEventListener("blur",this.blurHandler),t.root.addEventListener("scroll",this.scrollHandler,!0)}update(e,t){var n,o,r;const{state:i,composing:s}=e,{doc:l,selection:a}=i,c=t&&t.doc.eq(l)&&t.selection.eq(a);if(s||c)return;const{ranges:d}=a,u=Math.min(...d.map(e=>e.$from.pos)),h=Math.max(...d.map(e=>e.$to.pos)),p=this.shouldShow({view:e,state:i,from:u,to:h}),f=typeof Range.prototype.getClientRects>"u";if(!this.preventShow&&(p||this.preventHide)&&!f){const t=this.getSelectionBoundingBox();if(0===t.height&&0===t.width)return void queueMicrotask(()=>{const t={show:!0,referencePos:this.getSelectionBoundingBox()};this.state=t,this.emitUpdate(),e.dispatch(e.state.tr.setSelection(Nr.create(e.state.doc,e.state.selection.from+1,e.state.selection.to))),e.dispatch(e.state.tr.setSelection(Nr.create(e.state.doc,e.state.selection.from-1,e.state.selection.to)))});const r={show:!0,referencePos:this.getSelectionBoundingBox()};return void((r.show!==(null==(n=this.state)?void 0:n.show)||r.referencePos.toJSON()!==(null==(o=this.state)?void 0:o.referencePos.toJSON()))&&(this.state=r,this.emitUpdate()))}return null==(r=this.state)||!r.show||this.preventHide||p&&!this.preventShow&&this.editor.isEditable?void 0:(this.state.show=!1,void this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("mouseup",this.mouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:e}=this.pmView,{selection:t}=e,{ranges:n}=t,o=Math.min(...n.map(e=>e.$from.pos)),r=Math.max(...n.map(e=>e.$to.pos));if(rd(t)){const e=this.pmView.nodeDOM(o);if(e)return e.getBoundingClientRect()}return id(this.pmView,o,r)}}const rS=new Kr("FormattingToolbarPlugin");class iS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"closeMenu",()=>this.view.closeMenu()),this.addProsemirrorPlugin(new Wr({key:rS,view:t=>(this.view=new oS(e,t,e=>{this.emit("update",e)}),this.view),props:{handleKeyDown:(e,t)=>!("Escape"!==t.key||!this.shown)&&(this.view.closeMenu(),!0)}}))}static key(){return"formattingToolbar"}get shown(){var e,t;return(null==(t=null==(e=this.view)?void 0:e.state)?void 0:t.show)||!1}onUpdate(e){return this.on("update",e)}}const sS=kd.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML:()=>[{tag:"br"}],renderHTML({HTMLAttributes:e}){return["br",ec(this.options.HTMLAttributes,e)]},renderText:()=>"\n"}),lS=(e,t)=>{const n=e.resolve(t);if(n.depth<=1)return;const o=n.posAtIndex(n.index(n.depth-1),n.depth-1);return Iw(e.resolve(o))},aS=(e,t)=>{const n=e.resolve(t),o=n.index();if(0===o)return;const r=n.posAtIndex(o-1);return Iw(e.resolve(r))},cS=(e,t)=>{for(;t.childContainer;){const n=t.childContainer.node,o=e.resolve(t.childContainer.beforePos+1).posAtIndex(n.childCount-1);t=Iw(e.resolve(o))}return t},dS=e=>({state:t,dispatch:n})=>{const o=Iw(t.doc.resolve(e)),r=aS(t.doc,o.bnBlock.beforePos);if(!r)return!1;const i=cS(t.doc,r);return!!((e,t)=>e.isBlockContainer&&"inline*"===e.blockContent.node.type.spec.content&&e.blockContent.node.childCount>0&&t.isBlockContainer&&"inline*"===t.blockContent.node.type.spec.content)(i,o)&&((e,t,n,o)=>{if(!o.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but next block is not a block container`);if(o.childContainer){const n=e.doc.resolve(o.childContainer.beforePos+1),r=e.doc.resolve(o.childContainer.afterPos-1),i=n.blockRange(r);if(t){const t=e.doc.resolve(o.bnBlock.beforePos);e.tr.lift(i,t.depth)}}if(t){if(!n.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but previous block is not a block container`);t(e.tr.delete(n.blockContent.afterPos-1,o.blockContent.beforePos+1))}return!0})(t,n,i,o)},uS=kc.create({priority:50,addKeyboardShortcuts(){const e=(e=!1)=>this.editor.commands.first(({commands:t,tr:n})=>[()=>t.command(({state:e})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n,{depth:i}=e.doc.resolve(o.beforePos),s=0===e.selection.$anchor.parentOffset,l=e.selection.anchor===e.selection.head,a=0===r.node.childCount;return!!(s&&l&&a&&i>1)&&t.liftListItem("blockContainer")}),()=>t.command(({state:t})=>{const o=Lw(t),r=this.options.editor.schema.blockSchema[o.blockNoteType].hardBreakShortcut??"shift+enter";if("none"===r)return!1;if("shift+enter"===r&&e||"enter"===r){const e=n.storedMarks||n.selection.$head.marks().filter(e=>this.editor.extensionManager.splittableMarks.includes(e.type.name));return n.insert(n.selection.head,n.doc.type.schema.nodes.hardBreak.create()).ensureMarks(e),!0}return!1}),()=>t.command(({state:e,dispatch:t})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n,i=0===e.selection.$anchor.parentOffset,s=e.selection.anchor===e.selection.head,l=0===r.node.childCount;if(i&&s&&l){const n=o.afterPos,r=n+2;if(t){const t=e.schema.nodes.blockContainer.createAndFill();e.tr.insert(n,t).scrollIntoView(),e.tr.setSelection(new Nr(e.doc.resolve(r)))}return!0}return!1}),()=>t.command(({state:e,chain:t})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const{blockContent:o}=n,r=0===e.selection.$anchor.parentOffset;return 0!==o.node.childCount&&(t().deleteSelection().command(iC(e.selection.from,r,r)).run(),!0)})]);return{Backspace:()=>this.editor.commands.first(({chain:e,commands:t})=>[()=>t.deleteSelection(),()=>t.undoInputRule(),()=>t.command(({state:e})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const o=e.selection.from===n.blockContent.beforePos+1,r="paragraph"===n.blockContent.node.type.name;return!(!o||r)&&t.command(yk(n.bnBlock.beforePos,{type:"paragraph",props:{}}))}),()=>t.command(({state:e})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const{blockContent:o}=n;return e.selection.from===o.beforePos+1&&t.liftListItem("blockContainer")}),()=>t.command(({state:t})=>{const n=Lw(t);if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n,i=t.selection.from===r.beforePos+1,s=t.selection.empty,l=o.beforePos;return!(!i||!s)&&e().command(dS(l)).scrollIntoView().run()}),()=>t.command(({state:e,dispatch:t})=>{const n=Lw(e);if(!n.isBlockContainer||e.selection.from!==n.blockContent.beforePos+1||aS(e.doc,n.bnBlock.beforePos))return!1;const o=lS(e.doc,n.bnBlock.beforePos);if("column"!==(null==o?void 0:o.blockNoteType))return!1;const r=o,i=lS(e.doc,r.bnBlock.beforePos);if("columnList"!==(null==i?void 0:i.blockNoteType))throw new Error("parent of column is not a column list");const s=1===r.childContainer.node.childCount,l=s&&2===i.childContainer.node.childCount,a=i.childContainer.node.firstChild===r.bnBlock.node;if(t){const t=e.doc.slice(n.bnBlock.beforePos,n.bnBlock.afterPos,!1);if(l)if(a){e.tr.step(new Jo(i.bnBlock.beforePos,i.bnBlock.afterPos,r.bnBlock.afterPos+1,i.bnBlock.afterPos-2,t,t.size,!1));const n=e.tr.doc.resolve(r.bnBlock.beforePos);e.tr.setSelection(Nr.between(n,n))}else{e.tr.step(new Jo(i.bnBlock.beforePos,i.bnBlock.afterPos,i.bnBlock.beforePos+2,r.bnBlock.beforePos-1,t,0,!1));const n=e.tr.doc.resolve(e.tr.mapping.map(r.bnBlock.beforePos-1));e.tr.setSelection(Nr.between(n,n))}else if(s)if(a){e.tr.delete(r.bnBlock.beforePos,r.bnBlock.afterPos),e.tr.insert(i.bnBlock.beforePos,t.content);const n=e.tr.doc.resolve(i.bnBlock.beforePos);e.tr.setSelection(Nr.between(n,n))}else e.tr.delete(r.bnBlock.beforePos-1,r.bnBlock.beforePos+1);else{e.tr.delete(n.bnBlock.beforePos,n.bnBlock.afterPos),a?e.tr.insert(i.bnBlock.beforePos-1,t.content):e.tr.insert(r.bnBlock.beforePos-1,t.content);const o=e.tr.doc.resolve(r.bnBlock.beforePos-1);e.tr.setSelection(Nr.between(o,o))}}return!0}),()=>t.command(({state:t})=>{const n=Lw(t);if(!n.isBlockContainer)return!1;if(0===n.blockContent.node.childCount&&"inline*"===n.blockContent.node.type.spec.content){const o=aS(t.doc,n.bnBlock.beforePos);if(!o||!o.isBlockContainer)return!1;let r=e();if("tableRow+"===o.blockContent.node.type.spec.content){const e=n.bnBlock.beforePos-1-1-1-1-1;r=r.setTextSelection(e)}else if(""===o.blockContent.node.type.spec.content){const e=o.blockContent.afterPos-o.blockContent.node.nodeSize;r=r.setNodeSelection(e)}else{const e=o.blockContent.afterPos-o.blockContent.node.nodeSize;r=r.setTextSelection(e)}return r.deleteRange({from:n.bnBlock.beforePos,to:n.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>t.command(({state:t})=>{const n=Lw(t);if(!n.isBlockContainer)throw new Error("todo");const o=t.selection.from===n.blockContent.beforePos+1,r=t.selection.empty,i=aS(t.doc,n.bnBlock.beforePos);if(i&&o&&r){const o=cS(t.doc,i);if(!o.isBlockContainer)throw new Error("todo");if(""===o.blockContent.node.type.spec.content||"inline*"===o.blockContent.node.type.spec.content&&0===o.blockContent.node.childCount)return e().cut({from:n.bnBlock.beforePos,to:n.bnBlock.afterPos},o.bnBlock.afterPos).deleteRange({from:o.bnBlock.beforePos,to:o.bnBlock.afterPos}).run()}return!1})]),Delete:()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.command(({state:t})=>{const n=Lw(t);if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r,childContainer:i}=n,{depth:s}=t.doc.resolve(o.beforePos),l=o.afterPos===t.doc.nodeSize-3,a=t.selection.from===r.afterPos-1,c=t.selection.empty;if(!l&&a&&c&&void 0===i){let n=s,r=o.afterPos+1,i=t.doc.resolve(r).depth;for(;i<n;)n=i,r+=2,i=t.doc.resolve(r).depth;return e.command(dS(r-1))}return!1})]),Enter:()=>e(),"Shift-Enter":()=>e(!0),Tab:()=>{var e,t,n;return("prefer-indent"===this.options.tabBehavior||!(null!=(e=this.options.editor.formattingToolbar)&&e.shown||null!=(t=this.options.editor.linkToolbar)&&t.shown||null!=(n=this.options.editor.filePanel)&&n.shown))&&nE(this.options.editor)},"Shift-Tab":()=>{var e,t,n;return("prefer-indent"===this.options.tabBehavior||!(null!=(e=this.options.editor.formattingToolbar)&&e.shown||null!=(t=this.options.editor.linkToolbar)&&t.shown||null!=(n=this.options.editor.filePanel)&&n.shown))&&(this.editor.commands.liftListItem("blockContainer"),!0)},"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}});class hS{constructor(e,t,n){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"menuUpdateTimer"),ew(this,"startMenuUpdateTimer"),ew(this,"stopMenuUpdateTimer"),ew(this,"mouseHoveredLinkMark"),ew(this,"mouseHoveredLinkMarkRange"),ew(this,"keyboardHoveredLinkMark"),ew(this,"keyboardHoveredLinkMarkRange"),ew(this,"linkMark"),ew(this,"linkMarkRange"),ew(this,"mouseOverHandler",e=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),e.target instanceof HTMLAnchorElement&&"A"===e.target.nodeName){const t=e.target,n=this.pmView.posAtDOM(t,0)+1,o=this.pmView.state.doc.resolve(n),r=o.marks();for(const e of r)if(e.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=e,this.mouseHoveredLinkMarkRange=jc(o,e.type,e.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1}),ew(this,"clickHandler",e=>{var t;const n=this.pmView.dom.parentElement;this.linkMark&&e&&e.target&&n!==e.target&&!n.contains(e.target)&&null!=(t=this.state)&&t.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"scrollHandler",()=>{var e;void 0!==this.linkMark&&null!=(e=this.state)&&e.show&&(this.state.referencePos=id(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())}),ew(this,"closeMenu",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");n(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update(this.pmView,void 0,!0)},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),this.pmView.root.addEventListener("click",this.clickHandler,!0),this.pmView.root.addEventListener("scroll",this.scrollHandler,!0)}editLink(e,t){var n;this.editor.transact(n=>{const o=Bw(n);n.insertText(t,this.linkMarkRange.from,this.linkMarkRange.to),n.addMark(this.linkMarkRange.from,this.linkMarkRange.from+t.length,o.mark("link",{href:e}))}),this.pmView.focus(),null!=(n=this.state)&&n.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var e;this.editor.transact(e=>e.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}update(e,t,n=!1){var o;const{state:r}=e;if(t&&t.selection.from===r.selection.from&&t.selection.to===r.selection.to||!this.pmView.hasFocus())return;const i=this.linkMark;if(this.linkMark=void 0,this.linkMarkRange=void 0,this.keyboardHoveredLinkMark=void 0,this.keyboardHoveredLinkMarkRange=void 0,this.pmView.state.selection.empty){const e=this.pmView.state.selection.$from.marks();for(const t of e)if(t.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=t,this.keyboardHoveredLinkMarkRange=jc(this.pmView.state.selection.$from,t.type,t.attrs)||void 0;break}}return this.mouseHoveredLinkMark&&n&&(this.linkMark=this.mouseHoveredLinkMark,this.linkMarkRange=this.mouseHoveredLinkMarkRange),this.keyboardHoveredLinkMark&&(this.linkMark=this.keyboardHoveredLinkMark,this.linkMarkRange=this.keyboardHoveredLinkMarkRange),this.linkMark&&this.editor.isEditable?(this.state={show:!0,referencePos:id(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),url:this.linkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.linkMarkRange.from,this.linkMarkRange.to)},void this.emitUpdate()):null==(o=this.state)||!o.show||!i||this.linkMark&&this.editor.isEditable?void 0:(this.state.show=!1,void this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0),this.pmView.root.removeEventListener("click",this.clickHandler,!0)}}const pS=new Kr("LinkToolbarPlugin");class fS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"editLink",(e,t)=>{this.view.editLink(e,t)}),ew(this,"deleteLink",()=>{this.view.deleteLink()}),ew(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()}),ew(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()}),ew(this,"closeMenu",()=>this.view.closeMenu()),this.addProsemirrorPlugin(new Wr({key:pS,view:t=>(this.view=new hS(e,t,e=>{this.emit("update",e)}),this.view),props:{handleKeyDown:(e,t)=>!("Escape"!==t.key||!this.shown)&&(this.view.closeMenu(),!0)}}))}static key(){return"linkToolbar"}onUpdate(e){return this.on("update",e)}get shown(){var e,t;return(null==(t=null==(e=this.view)?void 0:e.state)?void 0:t.show)||!1}}const mS=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],gS="https",yS=new Kr("node-selection-keyboard");class bS extends UE{static key(){return"nodeSelectionKeyboard"}constructor(){super(),this.addProsemirrorPlugin(new Wr({key:yS,props:{handleKeyDown:(e,t)=>{if("node"in e.state.selection){if(t.ctrlKey||t.metaKey)return!1;if(1===t.key.length)return t.preventDefault(),!0;if(!("Enter"!==t.key||t.shiftKey||t.altKey||t.ctrlKey||t.metaKey)){const t=e.state.tr;return e.dispatch(t.insert(e.state.tr.selection.$to.after(),e.state.schema.nodes.paragraph.createChecked()).setSelection(new Nr(t.doc.resolve(e.state.tr.selection.$to.after()+1)))),!0}}return!1}}}))}}const vS=new Kr("blocknote-placeholder");class xS extends UE{static key(){return"placeholder"}constructor(e,t){super(),this.addProsemirrorPlugin(new Wr({key:vS,view:n=>{var o,r;const i=`placeholder-selector-${Pd()}`;n.dom.classList.add(i);const s=document.createElement("style"),l=e._tiptapEditor.options.injectNonce;l&&s.setAttribute("nonce",l),(null==(o=e.prosemirrorView)?void 0:o.root)instanceof ShadowRoot?e.prosemirrorView.root.append(s):null==(r=e.prosemirrorView)||r.root.head.appendChild(s);const a=s.sheet,c=(e="")=>`.${i} .bn-block-content${e} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:e,emptyDocument:n,...o}=t;for(const[t,s]of Object.entries(o)){const e=`[data-content-type="${t}"]`;a.insertRule(`${c(e)} { content: ${JSON.stringify(s)}; }`)}const r="[data-is-only-empty-block]",i="[data-is-empty-and-focused]";a.insertRule(`${c(r)} { content: ${JSON.stringify(n)}; }`),a.insertRule(`${c(i)} { content: ${JSON.stringify(e)}; }`)}catch(d){}return{destroy:()=>{var t,n;(null==(t=e.prosemirrorView)?void 0:t.root)instanceof ShadowRoot?e.prosemirrorView.root.removeChild(s):null==(n=e.prosemirrorView)||n.root.head.removeChild(s)}}},props:{decorations:t=>{const{doc:n,selection:o}=t;if(!e.isEditable||!o.empty||o.$from.parent.type.spec.code)return;const r=[];6===t.doc.content.size&&r.push(Ol.node(2,4,{"data-is-only-empty-block":"true"}));const i=o.$anchor,s=i.parent;if(0===s.content.size){const e=i.before();r.push(Ol.node(e,e+s.nodeSize,{"data-is-empty-and-focused":"true"}))}return Il.create(n,r)}}}))}}const wS=new Kr("previous-blocks"),kS={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class CS extends UE{static key(){return"previousBlockType"}constructor(){let e;super(),this.addProsemirrorPlugin(new Wr({key:wS,view(t){return{update:async(t,n)=>{var o;(null==(o=this.key)?void 0:o.getState(t.state).updatedBlocks.size)>0&&(e=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(wS,{clearUpdate:!0}))},0))},destroy:()=>{e&&clearTimeout(e)}}},state:{init:()=>({prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}),apply(e,t,n,o){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||n.doc.eq(o.doc))return t;const r={},i=Gc(n.doc,e=>e.attrs.id),s=new Map(i.map(e=>[e.node.attrs.id,e])),l=Gc(o.doc,e=>e.attrs.id);for(const a of l){const i=s.get(a.node.attrs.id),l=null==i?void 0:i.node.firstChild,c=a.node.firstChild;if(i&&l&&c){const s={index:c.attrs.index,level:c.attrs.level,type:c.type.name,depth:o.doc.resolve(a.pos).depth};let d={index:l.attrs.index,level:l.attrs.level,type:l.type.name,depth:n.doc.resolve(i.pos).depth};r[a.node.attrs.id]=d,e.getMeta("numberedListIndexing")&&(a.node.attrs.id in t.prevTransactionOldBlockAttrs&&(d=t.prevTransactionOldBlockAttrs[a.node.attrs.id]),"numberedListItem"===s.type&&(d.index=s.index)),t.currentTransactionOldBlockAttrs[a.node.attrs.id]=d,JSON.stringify(d)!==JSON.stringify(s)&&(d["depth-change"]=d.depth-s.depth,t.updatedBlocks.add(a.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=r,t}},props:{decorations(e){const t=this.getState(e);if(0===t.updatedBlocks.size)return;const n=[];return e.doc.descendants((e,o)=>{if(!e.attrs.id||!t.updatedBlocks.has(e.attrs.id))return;const r=t.currentTransactionOldBlockAttrs[e.attrs.id],i={};for(const[t,n]of Object.entries(r))i["data-prev-"+kS[t]]=n||"none";const s=Ol.node(o,o+e.nodeSize,{...i});n.push(s)}),Il.create(e.doc,n)}}}))}}const ES=new Kr("blocknote-show-selection");class SS extends UE{constructor(e){super(),ew(this,"enabled",!1),this.editor=e,this.addProsemirrorPlugin(new Wr({key:ES,props:{decorations:e=>{const{doc:t,selection:n}=e;if(!this.enabled)return Il.empty;const o=Ol.inline(n.from,n.to,{"data-show-selection":"true"});return Il.create(t,[o])}}}))}static key(){return"showSelection"}setEnabled(e){this.enabled!==e&&(this.enabled=e,this.editor.transact(e=>e.setMeta(ES,{})))}getEnabled(){return this.enabled}}function MS(e,t){for(var n,o;e&&e.parentElement&&e.parentElement!==t.dom&&"blockContainer"!==(null==(n=e.getAttribute)?void 0:n.call(e,"data-node-type"));)e=e.parentElement;if("blockContainer"===(null==(o=e.getAttribute)?void 0:o.call(e,"data-node-type")))return{node:e,id:e.getAttribute("data-id")}}let RS,TS=class e extends Mr{constructor(e,t){super(e,t),ew(this,"nodes");const n=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,t.pos,(e,t,o)=>{if(null!==o&&o.eq(n))return this.nodes.push(e),!1})}static create(t,n,o=n){return new e(t.resolve(n),t.resolve(o))}content(){return new _n(Rn.from(this.nodes),0,0)}eq(t){if(!(t instanceof e)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let e=0;e<this.nodes.length;e++)if(!this.nodes[e].eq(t.nodes[e]))return!1;return!0}map(t,n){const o=n.mapResult(this.from),r=n.mapResult(this.to);return r.deleted?Mr.near(t.resolve(o.pos)):o.deleted?Mr.near(t.resolve(r.pos)):new e(t.resolve(o.pos),t.resolve(r.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}};function jS(e,t,n=t){t===n&&(n+=e.state.doc.resolve(t+1).node().nodeSize);const o=e.domAtPos(t).node.cloneNode(!0),r=e.domAtPos(t).node,i=(e,t)=>Array.prototype.indexOf.call(e.children,t),s=i(r,e.domAtPos(t+1).node.parentElement),l=i(r,e.domAtPos(n-1).node.parentElement);for(let d=r.childElementCount-1;d>=0;d--)(d>l||d<s)&&o.removeChild(o.children[d]);NS(e.root),RS=o;const a=RS.getElementsByTagName("iframe");for(let d=0;d<a.length;d++){const e=a[d],t=e.parentElement;t&&t.removeChild(e)}const c=e.dom.className.split(" ").filter(e=>"ProseMirror"!==e&&"bn-root"!==e&&"bn-editor"!==e).join(" ");RS.className=RS.className+" bn-drag-preview "+c,e.root instanceof ShadowRoot?e.root.appendChild(RS):e.root.body.appendChild(RS)}function NS(e){void 0!==RS&&(e instanceof ShadowRoot?e.removeChild(RS):e.body.removeChild(RS),RS=void 0)}function AS(e,t,n){if(!e.dataTransfer)return;const o=n.prosemirrorView;if(!o)return;const r=fk(t.id,o.state.doc);if(!r)throw new Error(`Block with ID ${t.id} not found`);const i=r.posBeforeNode;if(null!=i){const t=o.state.selection,r=o.state.doc,{from:s,to:l}=function(e,t){let n,o;const r="blockContent"===t.resolve(e.from).node().type.spec.group,i="blockContent"===t.resolve(e.to).node().type.spec.group,s=Math.min(e.$anchor.depth,e.$head.depth);if(r&&i){const r=e.$from.start(s-1),i=e.$to.end(s-1);n=t.resolve(r-1).pos,o=t.resolve(i+1).pos}else n=e.from,o=e.to;return{from:n,to:o}}(t,r),a=s<=i&&i<l,c=t.$anchor.node()!==t.$head.node()||t instanceof TS;a&&c?(o.dispatch(o.state.tr.setSelection(TS.create(r,s,l))),jS(o,s,l)):(o.dispatch(o.state.tr.setSelection(Or.create(o.state.doc,i))),jS(o,i));const d=o.state.selection.content(),u=n.pmSchema,h=o.serializeForClipboard(d).dom.innerHTML,p=Ek(u,n),f=DE(d.content),m=p.exportBlocks(f,{}),g=cE(m);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",h),e.dataTransfer.setData("text/html",m),e.dataTransfer.setData("text/plain",g),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(RS,0,0)}}Mr.jsonID("multiple-node",TS);function OS(e,t,n=!0){const o=e.root.elementsFromPoint(t.left,t.top);for(const r of o)if(e.dom.contains(r))return n&&r.closest("[data-node-type=columnList]")?OS(e,{left:t.left+50,top:t.top},!1):MS(r,e)}class _S{constructor(e,t,n){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"mousePos"),ew(this,"hoveredBlock"),ew(this,"menuFrozen",!1),ew(this,"isDragOrigin",!1),ew(this,"updateState",e=>{this.state=e,this.emitUpdate(this.state)}),ew(this,"updateStateFromMousePos",()=>{var e,t,n,o,r;if(this.menuFrozen||!this.mousePos)return;const i=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if((null==i?void 0:i.element)!==this.pmView.dom||i.distance>250)return void(null!=(e=this.state)&&e.show&&(this.state.show=!1,this.updateState(this.state)));const s=function(e,t){if(!t.dom.firstChild)return;const n=t.dom.firstChild.getBoundingClientRect(),o=OS(t,{left:Math.min(Math.max(n.left+10,e.x),n.right-10),top:e.y});if(!o)return;return OS(t,{left:o.node.getBoundingClientRect().right-10,top:e.y},!1)}(this.mousePos,this.pmView);if(s&&this.editor.isEditable){if((null==(n=this.state)||!n.show||null==(o=this.hoveredBlock)||!o.hasAttribute("data-id")||(null==(r=this.hoveredBlock)?void 0:r.getAttribute("data-id"))!==s.id)&&(this.hoveredBlock=s.node,this.editor.isEditable)){const e=s.node.getBoundingClientRect(),t=s.node.closest("[data-node-type=column]");this.state={show:!0,referencePos:new DOMRect(t?t.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,e.y,e.width,e.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateState(this.state)}}else null!=(t=this.state)&&t.show&&(this.state.show=!1,this.updateState(this.state))}),ew(this,"onDragStart",e=>{var t;const n=null==(t=e.dataTransfer)?void 0:t.getData("blocknote/html");if(!n||this.pmView.dragging)return;const o=document.createElement("div");o.innerHTML=n;const r=vo.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new _n(r.content,0,0),move:!0}}),ew(this,"findClosestEditorElement",e=>{const t=Array.from(this.pmView.root.querySelectorAll(".bn-editor"));if(0===t.length)return null;let n=t[0],o=Number.MAX_VALUE;return t.forEach(t=>{const r=t.querySelector(".bn-block-group").getBoundingClientRect(),i=e.clientX<r.left?r.left-e.clientX:e.clientX>r.right?e.clientX-r.right:0,s=e.clientY<r.top?r.top-e.clientY:e.clientY>r.bottom?e.clientY-r.bottom:0,l=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));l<o&&(o=l,n=t)}),{element:n,distance:o}}),ew(this,"onDragOver",e=>{if(e.synthetic)return;const t=this.getDragEventContext(e);t&&t.isDropPoint?t.isDropPoint&&!t.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(e):this.closeDropCursor()}),ew(this,"closeDropCursor",()=>{const e=new Event("dragleave",{bubbles:!1});e.synthetic=!0,this.pmView.dom.dispatchEvent(e)}),ew(this,"getDragEventContext",e=>{var t;const n=!(null!=(t=e.dataTransfer)&&t.types.includes("blocknote/html")||!this.pmView.dragging),o=!!this.isDragOrigin,r=n||o,i=this.findClosestEditorElement(e);if(!i||i.distance>250)return;const s=i.element===this.pmView.dom,l=s&&0===i.distance;return s||r?{isDropPoint:s,isDropWithinEditorBounds:l,isDragOrigin:r}:void 0}),ew(this,"onDrop",e=>{if(e.synthetic)return;const t=this.getDragEventContext(e);if(!t)return void this.closeDropCursor();const{isDropPoint:n,isDropWithinEditorBounds:o,isDragOrigin:r}=t;if(!o&&n&&this.dispatchSyntheticEvent(e),n){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(Nr.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.anchor)))}else r&&setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0)}),ew(this,"onDragEnd",e=>{e.synthetic||(this.pmView.dragging=null)}),ew(this,"onKeyDown",e=>{var t;null!=(t=this.state)&&t.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))}),ew(this,"onMouseMove",e=>{var t;if(this.menuFrozen)return;this.mousePos={x:e.clientX,y:e.clientY};const n=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>n.left&&this.mousePos.x<n.right&&this.mousePos.y>n.top&&this.mousePos.y<n.bottom,r=this.pmView.dom.parentElement;o&&e&&e.target&&r!==e.target&&!r.contains(e.target)?null!=(t=this.state)&&t.show&&(this.state.show=!1,this.emitUpdate(this.state)):this.updateStateFromMousePos()}),ew(this,"onScroll",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.referencePos=this.hoveredBlock.getBoundingClientRect(),this.emitUpdate(this.state)),this.updateStateFromMousePos()}),this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");n(this.state)},this.pmView.root.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragend",this.onDragEnd,!0),sE(),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),t.root.addEventListener("scroll",this.onScroll,!0)}dispatchSyntheticEvent(e){const t=new Event(e.type,e),n=this.pmView.dom.firstChild.getBoundingClientRect();t.clientX=e.clientX,t.clientY=e.clientY,t.clientX=Math.min(Math.max(e.clientX,n.left),n.left+n.width),t.clientY=Math.min(Math.max(e.clientY,n.top),n.top+n.height),t.dataTransfer=e.dataTransfer,t.preventDefault=()=>e.preventDefault(),t.synthetic=!0,this.pmView.dom.dispatchEvent(t)}update(e,t){var n;!t.doc.eq(this.pmView.state.doc)&&null!=(n=this.state)&&n.show&&this.updateStateFromMousePos()}destroy(){var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.pmView.root.removeEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("dragover",this.onDragOver),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("dragend",this.onDragEnd,!0),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0),this.pmView.root.removeEventListener("scroll",this.onScroll,!0)}}const PS=new Kr("SideMenuPlugin");class IS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"blockDragStart",(e,t)=>{this.view&&(this.view.isDragOrigin=!0),AS(e,t,this.editor)}),ew(this,"blockDragEnd",()=>{this.editor.prosemirrorView&&NS(this.editor.prosemirrorView.root),this.view&&(this.view.isDragOrigin=!1)}),ew(this,"freezeMenu",()=>{this.view.menuFrozen=!0,this.view.state.show=!0,this.view.emitUpdate(this.view.state)}),ew(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)}),this.editor=e,this.addProsemirrorPlugin(new Wr({key:PS,view:t=>(this.view=new _S(e,t,e=>{this.emit("update",e)}),this.view)}))}static key(){return"sideMenu"}onUpdate(e){return this.on("update",e)}}const LS=new Map;function DS(e,t,n="left"){const o=ex.getState(e._tiptapEditor.state);if(!o){const o=function(e){if(LS.has(e))return LS.get(e);const t=new Vo;return e._tiptapEditor.on("transaction",({transaction:e})=>{t.appendMapping(e.mapping)}),e._tiptapEditor.on("destroy",()=>{LS.delete(e)}),LS.set(e,t),t}(e),r=o.maps.length;return()=>o.slice(r).map(t,"left"===n?-1:1)}const r=Dx(t+("right"===n?1:0),o.binding.type,o.binding.mapping);return()=>{const t=ex.getState(e._tiptapEditor.state),o=Hx(t.doc,t.binding.type,r,t.binding.mapping);if(null===o)throw new Error("Position not found, cannot track positions");return o+("right"===n?-1:0)}}const BS=Zc(e=>"blockContainer"===e.type.name);class HS{constructor(e,t){var n,o;ew(this,"state"),ew(this,"emitUpdate"),ew(this,"rootEl"),ew(this,"pluginState"),ew(this,"handleScroll",()=>{var e,t;if(null!=(e=this.state)&&e.show){const e=null==(t=this.rootEl)?void 0:t.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!e)return;this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}}),ew(this,"closeMenu",()=>{this.editor.transact(e=>e.setMeta(VS,null))}),ew(this,"clearQuery",()=>{void 0!==this.pluginState&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos()-(this.pluginState.deleteTriggerCharacter?this.pluginState.triggerCharacter.length:0),to:this.editor.transact(e=>e.selection.from)}).run()}),this.editor=e,this.pluginState=void 0,this.emitUpdate=e=>{var n;if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");t(e,{...this.state,ignoreQueryLength:null==(n=this.pluginState)?void 0:n.ignoreQueryLength})},this.rootEl=null==(n=this.editor.prosemirrorView)?void 0:n.root,null==(o=this.rootEl)||o.addEventListener("scroll",this.handleScroll,!0)}update(e,t){var n;const o=VS.getState(t),r=VS.getState(e.state),i=void 0!==o&&void 0===r;if(!(void 0===o&&void 0!==r||void 0!==o&&void 0!==r||i))return;if(this.pluginState=i?o:r,i||!this.editor.isEditable)return this.state&&(this.state.show=!1),void this.emitUpdate(this.pluginState.triggerCharacter);const s=null==(n=this.rootEl)?void 0:n.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&s&&(this.state={show:!0,referencePos:s.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){var e;null==(e=this.rootEl)||e.removeEventListener("scroll",this.handleScroll,!0)}}const VS=new Kr("SuggestionMenuPlugin");class $S extends UE{constructor(e){super(),ew(this,"view"),ew(this,"triggerCharacters",[]),ew(this,"addTriggerCharacter",e=>{this.triggerCharacters.push(e)}),ew(this,"removeTriggerCharacter",e=>{this.triggerCharacters=this.triggerCharacters.filter(t=>t!==e)}),ew(this,"closeMenu",()=>this.view.closeMenu()),ew(this,"clearQuery",()=>this.view.clearQuery());const t=this.triggerCharacters;this.addProsemirrorPlugin(new Wr({key:VS,view:()=>(this.view=new HS(e,(e,t)=>{this.emit(`update ${e}`,t)}),this.view),state:{init(){},apply:(t,n,o,r)=>{if(void 0!==t.getMeta("orderedListIndexing")||t.selection.$from.parent.type.spec.code)return n;const i=t.getMeta(VS);if("object"==typeof i&&null!==i){n&&this.closeMenu();const t=DS(e,r.selection.from-i.triggerCharacter.length);return{triggerCharacter:i.triggerCharacter,deleteTriggerCharacter:!1!==i.deleteTriggerCharacter,queryStartPos:()=>t()+i.triggerCharacter.length,query:"",decorationId:`id_${Math.floor(4294967295*Math.random())}`,ignoreQueryLength:null==i?void 0:i.ignoreQueryLength}}if(void 0===n)return n;if(r.selection.from!==r.selection.to||null===i||t.getMeta("focus")||t.getMeta("blur")||t.getMeta("pointer")||void 0!==n.triggerCharacter&&r.selection.from<n.queryStartPos()||!r.selection.$from.sameParent(r.doc.resolve(n.queryStartPos())))return;const s={...n};return s.query=r.doc.textBetween(n.queryStartPos(),r.selection.from),s}},props:{handleTextInput(e,n,o,r){if(n===o){const o=e.state.doc;for(const i of t){const t=i.length>1?o.textBetween(n-i.length,n)+r:r;if(i===t)return e.dispatch(e.state.tr.insertText(r)),e.dispatch(e.state.tr.setMeta(VS,{triggerCharacter:t}).scrollIntoView()),!0}}return!1},decorations(e){const t=this.getState(e);if(void 0===t)return null;if(!t.deleteTriggerCharacter){const n=BS(e.selection);if(n)return Il.create(e.doc,[Ol.node(n.pos,n.pos+n.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":t.decorationId})])}return Il.create(e.doc,[Ol.inline(t.queryStartPos()-t.triggerCharacter.length,t.queryStartPos(),{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":t.decorationId})])}}}))}static key(){return"suggestionMenu"}onUpdate(e,t){return this.triggerCharacters.includes(e)||this.addTriggerCharacter(e),this.on(`update ${e}`,t)}get shown(){var e,t;return(null==(t=null==(e=this.view)?void 0:e.state)?void 0:t.show)||!1}}const zS=gc.create({name:"insertion",inclusive:!1,excludes:"deletion modification insertion",addAttributes:()=>({id:{default:null,validate:"number"}}),extendMarkSchema:e=>"insertion"!==e.name?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM:(e,t)=>["ins",{"data-id":String(e.attrs.id),"data-inline":String(t),...!t&&{style:"display: contents"}},0],parseDOM:[{tag:"ins",getAttrs:e=>!!e.dataset.id&&{id:parseInt(e.dataset.id,10)}}]}}),FS=gc.create({name:"deletion",inclusive:!1,excludes:"insertion modification deletion",addAttributes:()=>({id:{default:null,validate:"number"}}),extendMarkSchema:e=>"deletion"!==e.name?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM:(e,t)=>["del",{"data-id":String(e.attrs.id),"data-inline":String(t),...!t&&{style:"display: contents"}},0],parseDOM:[{tag:"del",getAttrs:e=>!!e.dataset.id&&{id:parseInt(e.dataset.id,10)}}]}}),US=gc.create({name:"modification",inclusive:!1,excludes:"deletion insertion",addAttributes:()=>({id:{default:null,validate:"number"},type:{validate:"string"},attrName:{default:null,validate:"string|null"},previousValue:{default:null},newValue:{default:null}}),extendMarkSchema:e=>"modification"!==e.name?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM:(e,t)=>[t?"span":"div",{"data-type":"modification","data-id":String(e.attrs.id),"data-mod-type":e.attrs.type,"data-mod-prev-val":JSON.stringify(e.attrs.previousValue),"data-mod-new-val":JSON.stringify(e.attrs.newValue)},0],parseDOM:[{tag:"span[data-type='modification']",getAttrs:e=>!!e.dataset.id&&{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal,newValue:e.dataset.modNewVal}},{tag:"div[data-type='modification']",getAttrs:e=>!!e.dataset.id&&{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal}}]}});let WS;function qS(e){WS||(WS=document.createElement("div"),WS.innerHTML="_",WS.style.opacity="0",WS.style.height="1px",WS.style.width="1px",e instanceof Document?e.body.appendChild(WS):e.appendChild(WS))}function GS(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}class KS{constructor(e,t,n){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"tableId"),ew(this,"tablePos"),ew(this,"tableElement"),ew(this,"menuFrozen",!1),ew(this,"mouseState","up"),ew(this,"prevWasEditable",null),ew(this,"viewMousedownHandler",()=>{this.mouseState="down"}),ew(this,"mouseUpHandler",e=>{this.mouseState="up",this.mouseMoveHandler(e)}),ew(this,"mouseMoveHandler",e=>{var t,n,o,r,i,s,l;if(this.menuFrozen||"selecting"===this.mouseState||!(e.target instanceof Element)||!this.pmView.dom.contains(e.target))return;const a=function(e){let t=e;for(;t&&"TD"!==t.nodeName&&"TH"!==t.nodeName&&!t.classList.contains("tableWrapper");){if(t.classList.contains("ProseMirror"))return;const e=t.parentNode;if(!(e&&e instanceof Element))return;t=e}return"TD"===t.nodeName||"TH"===t.nodeName?{type:"cell",domNode:t,tbodyNode:t.closest("tbody")}:{type:"wrapper",domNode:t,tbodyNode:t.querySelector("tbody")}}(e.target);if("cell"===(null==a?void 0:a.type)&&"down"===this.mouseState&&(null==(t=this.state)||!t.draggingState))return this.mouseState="selecting",void(null!=(n=this.state)&&n.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate()));if(!a||!this.editor.isEditable)return void(null!=(o=this.state)&&o.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate()));if(!a.tbodyNode)return;const c=a.tbodyNode.getBoundingClientRect(),d=MS(a.domNode,this.pmView);if(!d)return;let u;this.tableElement=d.node;const h=this.editor.transact(e=>fk(d.id,e.doc));if(!h)throw new Error(`Block with ID ${d.id} not found`);const p=Gw(h.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(function(e,t,n){return t.type===e&&t.type in n.schema.blockSchema&&HC(t.type,n)}("table",p,this.editor)&&(this.tablePos=h.posBeforeNode+1,u=p),!u)return;this.tableId=d.id;const f=null==(r=a.domNode.closest(".tableWrapper"))?void 0:r.querySelector(".table-widgets-container");if("wrapper"===(null==a?void 0:a.type)){const t=e.clientY>=c.bottom-1&&e.clientY<c.bottom+20,n=e.clientX>=c.right-1&&e.clientX<c.right+20,o=e.clientX>c.right||e.clientY>c.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:t,showAddOrRemoveColumnsButton:n,referencePosTable:c,block:u,widgetContainer:f,colIndex:o||null==(i=this.state)?void 0:i.colIndex,rowIndex:o||null==(s=this.state)?void 0:s.rowIndex,referencePosCell:o||null==(l=this.state)?void 0:l.referencePosCell}}else{const e=GS(a.domNode),t=GS(a.domNode.parentElement),n=a.domNode.getBoundingClientRect();if(void 0!==this.state&&this.state.show&&this.tableId===d.id&&this.state.rowIndex===t&&this.state.colIndex===e)return;this.state={show:!0,showAddOrRemoveColumnsButton:e===u.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:t===u.content.rows.length-1,referencePosTable:c,block:u,draggingState:void 0,referencePosCell:n,colIndex:e,rowIndex:t,widgetContainer:f}}return this.emitUpdate(),!1}),ew(this,"dragOverHandler",e=>{var t;if(void 0===(null==(t=this.state)?void 0:t.draggingState))return;e.preventDefault(),e.dataTransfer.dropEffect="move",function(e,t){const n=t.querySelectorAll(e);for(let o=0;o<n.length;o++)n[o].style.visibility="hidden"}(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const n={left:Math.min(Math.max(e.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(e.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=this.pmView.root.elementsFromPoint(n.left,n.top).filter(e=>"TD"===e.tagName||"TH"===e.tagName);if(0===o.length)return;const r=o[0];let i=!1;const s=GS(r.parentElement),l=GS(r),a="row"===this.state.draggingState.draggedCellOrientation?this.state.rowIndex:this.state.colIndex,c=("row"===this.state.draggingState.draggedCellOrientation?s:l)!==a;(this.state.rowIndex!==s||this.state.colIndex!==l)&&(this.state.rowIndex=s,this.state.colIndex=l,this.state.referencePosCell=r.getBoundingClientRect(),i=!0);const d="row"===this.state.draggingState.draggedCellOrientation?n.top:n.left;this.state.draggingState.mousePos!==d&&(this.state.draggingState.mousePos=d,i=!0),i&&this.emitUpdate(),c&&this.editor.transact(e=>e.setMeta(ZS,!0))}),ew(this,"dropHandler",e=>{if(this.mouseState="up",void 0===this.state||void 0===this.state.draggingState)return!1;if(void 0===this.state.rowIndex||void 0===this.state.colIndex)throw new Error("Attempted to drop table row or column, but no table block was hovered prior.");e.preventDefault();const{draggingState:t,colIndex:n,rowIndex:o}=this.state,r=this.state.block.content.columnWidths;if("row"===t.draggedCellOrientation){if(!ik(this.state.block,t.originalIndex,o))return!1;const e=function(e,t,n,o=Xw(e)){const{row:r}=Qw({row:t,col:0},e,o),{row:i}=Qw({row:n,col:0},e,o),[s]=o.splice(r,1);return o.splice(i,0,s),Yw(o)}(this.state.block,t.originalIndex,o);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:e}})}else{if(!sk(this.state.block,t.originalIndex,n))return!1;const e=function(e,t,n,o=Xw(e)){const{col:r}=Qw({row:0,col:t},e,o),{col:i}=Qw({row:0,col:n},e,o);return o.forEach(e=>{const[t]=e.splice(r,1);e.splice(i,0,t)}),Yw(o)}(this.state.block,t.originalIndex,n),[o]=r.splice(t.originalIndex,1);r.splice(n,0,o),this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,columnWidths:r,rows:e}})}return this.editor.setTextCursorPosition(this.state.block.id),!0}),this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");n(this.state)},t.dom.addEventListener("mousemove",this.mouseMoveHandler),t.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),t.root.addEventListener("dragover",this.dragOverHandler),t.root.addEventListener("drop",this.dropHandler)}update(){var e;if(!this.state||!this.state.show)return;if(this.state.block=this.editor.getBlock(this.state.block.id),!this.state.block||"table"!==this.state.block.type||null==(e=this.tableElement)||!e.isConnected)return this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,void this.emitUpdate();const{height:t,width:n}=ek(this.state.block);void 0!==this.state.rowIndex&&void 0!==this.state.colIndex&&(this.state.rowIndex>=t&&(this.state.rowIndex=t-1),this.state.colIndex>=n&&(this.state.colIndex=n-1));const o=this.tableElement.querySelector("tbody");if(!o)throw new Error("Table block does not contain a 'tbody' HTML element. This should never happen.");if(void 0!==this.state.rowIndex&&void 0!==this.state.colIndex){const e=o.children[this.state.rowIndex].children[this.state.colIndex];e?this.state.referencePosCell=e.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=o.getBoundingClientRect(),this.emitUpdate()}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),window.removeEventListener("mouseup",this.mouseUpHandler),this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler)}}const ZS=new Kr("TableHandlesPlugin");class JS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"colDragStart",e=>{if(void 0===this.view.state||void 0===this.view.state.colIndex)throw new Error("Attempted to drag table column, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:e.clientX},this.view.emitUpdate(),this.editor.transact(e=>e.setMeta(ZS,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");qS(this.editor.prosemirrorView.root),e.dataTransfer.setDragImage(WS,0,0),e.dataTransfer.effectAllowed="move"}),ew(this,"rowDragStart",e=>{if(void 0===this.view.state||void 0===this.view.state.rowIndex)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:e.clientY},this.view.emitUpdate(),this.editor.transact(e=>e.setMeta(ZS,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");qS(this.editor.prosemirrorView.root),e.dataTransfer.setDragImage(WS,0,0),e.dataTransfer.effectAllowed="copyMove"}),ew(this,"dragEnd",()=>{if(void 0===this.view.state)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor.transact(e=>e.setMeta(ZS,null)),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");var e;e=this.editor.prosemirrorView.root,WS&&(e instanceof Document?e.body.removeChild(WS):e.removeChild(WS),WS=void 0)}),ew(this,"freezeHandles",()=>{this.view.menuFrozen=!0}),ew(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1}),ew(this,"getCellsAtRowHandle",(e,t)=>nk(e,t)),ew(this,"getCellsAtColumnHandle",(e,t)=>ok(e,t)),ew(this,"setCellSelection",(e,t,n=t)=>{const o=this.view;if(!o)throw new Error("Table handles view not initialized");const r=e.doc.resolve(o.tablePos+1),i=e.doc.resolve(r.posAtIndex(t.row)+1),s=e.doc.resolve(i.posAtIndex(t.col)),l=e.doc.resolve(r.posAtIndex(n.row)+1),a=e.doc.resolve(l.posAtIndex(n.col)),c=e.tr;return c.setSelection(new Gd(s,a)),e.apply(c)}),ew(this,"addRowOrColumn",(e,t)=>{this.editor.exec((n,o)=>{const r=this.setCellSelection(n,"row"===t.orientation?{row:e,col:0}:{row:0,col:e});return"row"===t.orientation?"above"===t.side?function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e);t(nu(e.tr,n,n.top))}return!0}(r,o):function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e);t(nu(e.tr,n,n.bottom))}return!0}(r,o):"left"===t.side?function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e);t(eu(e.tr,n,n.left))}return!0}(r,o):function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e);t(eu(e.tr,n,n.right))}return!0}(r,o)})}),ew(this,"removeRowOrColumn",(e,t)=>"row"===t?this.editor.exec((t,n)=>function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e),o=e.tr;if(0==n.top&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;ou(o,n,e),e!=n.top;e--){const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw RangeError("No table found");n.table=e,n.map=Id.get(n.table)}t(o)}return!0}(this.setCellSelection(t,{row:e,col:0}),n)):this.editor.exec((t,n)=>function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e),o=e.tr;if(0==n.left&&n.right==n.map.width)return!1;for(let e=n.right-1;tu(o,n,e),e!=n.left;e--){const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw RangeError("No table found");n.table=e,n.map=Id.get(e)}t(o)}return!0}(this.setCellSelection(t,{row:0,col:e}),n))),ew(this,"mergeCells",e=>this.editor.exec((t,n)=>function(e,t){const n=e.selection;if(!(n instanceof Gd)||n.$anchorCell.pos==n.$headCell.pos)return!1;const o=Qd(e),{map:r}=o;if(function({width:e,height:t,map:n},o){let r=o.top*e+o.left,i=r,s=(o.bottom-1)*e+o.left,l=r+(o.right-o.left-1);for(let a=o.top;a<o.bottom;a++){if(o.left>0&&n[i]==n[i-1]||o.right<e&&n[l]==n[l+1])return!0;i+=e,l+=e}for(let a=o.left;a<o.right;a++){if(o.top>0&&n[r]==n[r-e]||o.bottom<t&&n[s]==n[s+e])return!0;r++,s++}return!1}(r,o))return!1;if(t){const n=e.tr,i={};let s,l,a=Rn.empty;for(let e=o.top;e<o.bottom;e++)for(let t=o.left;t<o.right;t++){const c=r.map[e*r.width+t],d=o.table.nodeAt(c);if(!i[c]&&d)if(i[c]=!0,null==s)s=c,l=d;else{ru(d)||(a=a.append(d.content));const e=n.mapping.map(c+o.tableStart);n.delete(e,e+d.nodeSize)}}if(null==s||null==l)return!0;if(n.setNodeMarkup(s+o.tableStart,null,{...qd(l.attrs,l.attrs.colspan,o.right-o.left-l.attrs.colspan),rowspan:o.bottom-o.top}),a.size){const e=s+1+l.content.size,t=ru(l)?s+1:e;n.replaceWith(t+o.tableStart,e+o.tableStart,a)}n.setSelection(new Gd(n.doc.resolve(s+o.tableStart))),t(n)}return!0}(e?this.setCellSelection(t,e.relativeStartCell,e.relativeEndCell):t,n))),ew(this,"splitCell",e=>this.editor.exec((t,n)=>iu(e?this.setCellSelection(t,e):t,n))),ew(this,"getCellSelection",()=>this.editor.transact(e=>{const t=e.selection;let n=t.$from,o=t.$to;if(UC(t)){const{ranges:e}=t;e.forEach(e=>{n=e.$from.min(n??e.$from),o=e.$to.max(o??e.$to)})}else if(n=e.doc.resolve(t.$from.pos-t.$from.parentOffset-1),o=e.doc.resolve(t.$to.pos-t.$to.parentOffset-1),0===n.pos||0===o.pos)return;const r=e.doc.resolve(n.pos-n.parentOffset-1),i=e.doc.resolve(o.pos-o.parentOffset-1),s=e.doc.resolve(r.pos-r.parentOffset-1),l=n.index(r.depth),a=r.index(s.depth),c=o.index(i.depth),d=i.index(s.depth),u=[];for(let h=a;h<=d;h++)for(let e=l;e<=c;e++)u.push({row:h,col:e});return{from:{row:a,col:l},to:{row:d,col:c},cells:u}})),ew(this,"getMergeDirection",e=>this.editor.transact(t=>{const n=UC(t.selection)?t.selection:void 0;if(!n||!e||n.ranges.length<=1)return;const o=this.getCellSelection();return o?function(e,t,n){const o=Qw(e,n),r=Qw(t,n);return o.col===r.col}(o.from,o.to,e)?"vertical":"horizontal":void 0})),ew(this,"cropEmptyRowsOrColumns",(e,t)=>function(e,t,n=Xw(e)){if("columns"===t){let e=0;for(let t=n[0].length-1;t>=0&&n.every(e=>rk(e[t].cell)&&1===e[t].colspan);t--)e++;for(let t=n.length-1;t>=0;t--){const o=Math.max(n[t].length-e,1);n[t]=n[t].slice(0,o)}return Yw(n)}let o=0;for(let i=n.length-1;i>=0&&n[i].every(e=>rk(e.cell)&&1===e.rowspan);i--)o++;const r=Math.min(o,n.length-1);return n.splice(n.length-r,r),Yw(n)}(e,t)),ew(this,"addRowsOrColumns",(e,t,n)=>function(e,t,n,o=Xw(e)){const{width:r,height:i}=ek(e);if("columns"===t)o.forEach((e,t)=>{if(n>=0)for(let o=0;o<n;o++)e.push({row:t,col:Math.max(...e.map(e=>e.col))+1,rowspan:1,colspan:1,cell:sw("")});else e.splice(r+n,-1*n)});else if(n>0)for(let s=0;s<n;s++){const e=new Array(r).fill(null).map((e,t)=>({row:i+s,col:t,rowspan:1,colspan:1,cell:sw("")}));o.push(e)}else n<0&&o.splice(i+n,-1*n);return Yw(o)}(e,t,n)),this.editor=e,this.addProsemirrorPlugin(new Wr({key:ZS,view:t=>(this.view=new KS(e,t,e=>{this.emit("update",e)}),this.view),props:{decorations:e=>{if(void 0===this.view||void 0===this.view.state||void 0===this.view.state.draggingState||void 0===this.view.tablePos)return;const t="row"===this.view.state.draggingState.draggedCellOrientation?this.view.state.rowIndex:this.view.state.colIndex;if(void 0===t)return;const n=[],{block:o,draggingState:r}=this.view.state,{originalIndex:i,draggedCellOrientation:s}=r;if(t===i||!o||"row"===s&&!ik(o,i,t)||"col"===s&&!sk(o,i,t))return Il.create(e.doc,n);const l=e.doc.resolve(this.view.tablePos+1);return"row"===this.view.state.draggingState.draggedCellOrientation?nk(this.view.state.block,t).forEach(({row:o,col:r})=>{const s=e.doc.resolve(l.posAtIndex(o)+1),a=e.doc.resolve(s.posAtIndex(r)+1),c=a.node(),d=a.pos+(t>i?c.nodeSize-2:0);n.push(Ol.widget(d,()=>{const e=document.createElement("div");return e.className="bn-table-drop-cursor",e.style.left="0",e.style.right="0",t>i?e.style.bottom="-2px":e.style.top="-3px",e.style.height="4px",e}))}):ok(this.view.state.block,t).forEach(({row:o,col:r})=>{const s=e.doc.resolve(l.posAtIndex(o)+1),a=e.doc.resolve(s.posAtIndex(r)+1),c=a.node(),d=a.pos+(t>i?c.nodeSize-2:0);n.push(Ol.widget(d,()=>{const e=document.createElement("div");return e.className="bn-table-drop-cursor",e.style.top="0",e.style.bottom="0",t>i?e.style.right="-2px":e.style.left="-3px",e.style.width="4px",e}))}),Il.create(e.doc,n)}}}))}static key(){return"tableHandles"}onUpdate(e){return this.on("update",e)}}const XS=kc.create({name:"textAlignment",addGlobalAttributes:()=>[{types:["paragraph","heading","bulletListItem","numberedListItem","checkListItem","tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:e=>e.getAttribute("data-text-alignment"),renderHTML:e=>"left"===e.textAlignment?{}:{"data-text-alignment":e.textAlignment}}}}]}),YS=kc.create({name:"blockTextColor",addGlobalAttributes:()=>[{types:["blockContainer","tableCell","tableHeader"],attributes:{textColor:{default:bw.textColor.default,parseHTML:e=>e.hasAttribute("data-text-color")?e.getAttribute("data-text-color"):bw.textColor.default,renderHTML:e=>e.textColor===bw.textColor.default?{}:{"data-text-color":e.textColor}}}}]}),QS=kc.create({name:"trailingNode",addProseMirrorPlugins(){const e=new Kr(this.name);return[new Wr({key:e,appendTransaction:(t,n,o)=>{const{doc:r,tr:i,schema:s}=o,l=e.getState(o),a=r.content.size-2,c=s.nodes.blockContainer,d=s.nodes.paragraph;if(l)return i.insert(a,c.create(void 0,d.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let n=e.doc.lastChild;if(!n||"blockGroup"!==n.type.name)throw new Error("Expected blockGroup");if(n=n.lastChild,!n||"blockContainer"!==n.type.name)return!0;const o=n.firstChild;if(!o)throw new Error("Expected blockContent");return n.nodeSize>4||"inline*"!==o.type.spec.content}}})]}}),eM={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},tM=kd.create({name:"blockContainer",group:"blockGroupChild bnBlock",content:"blockContent blockGroup?",priority:50,defining:!0,marks:"insertion modification deletion",parseHTML(){return[{tag:"div[data-node-type="+this.name+"]",getAttrs:e=>{if("string"==typeof e)return!1;const t={};for(const[n,o]of Object.entries(eM))e.getAttribute(o)&&(t[n]=e.getAttribute(o));return t}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:e}){var t;const n=document.createElement("div");n.className="bn-block-outer",n.setAttribute("data-node-type","blockOuter");for(const[i,s]of Object.entries(e))"class"!==i&&n.setAttribute(i,s);const o={...(null==(t=this.options.domAttributes)?void 0:t.block)||{},...e},r=document.createElement("div");r.className=fw("bn-block",o.class),r.setAttribute("data-node-type",this.name);for(const[i,s]of Object.entries(o))"class"!==i&&r.setAttribute(i,s);return n.appendChild(r),{dom:n,contentDOM:r}}}),nM=kd.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",marks:"deletion insertion modification",parseHTML:()=>[{tag:"div",getAttrs:e=>"string"!=typeof e&&("blockGroup"===e.getAttribute("data-node-type")&&null)}],renderHTML({HTMLAttributes:e}){var t;const n={...(null==(t=this.options.domAttributes)?void 0:t.blockGroup)||{},...e},o=document.createElement("div");o.className=fw("bn-block-group",n.class),o.setAttribute("data-node-type","blockGroup");for(const[r,i]of Object.entries(n))"class"!==r&&o.setAttribute(r,i);return{dom:o,contentDOM:o}}}),oM=kd.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"});class rM extends UE{constructor({editor:e,collaboration:t}){super(e),ew(this,"editor"),ew(this,"collaboration"),ew(this,"forkedState"),this.editor=e,this.collaboration=t}static key(){return"ForkYDocPlugin"}findTypeInOtherYdoc(e,t){const n=e.doc;if(null===e._item){const o=Array.from(n.share.keys()).find(t=>n.share.get(t)===e);if(null==o)throw new Error("type does not exist in other ydoc");return t.get(o,e.constructor)}{const n=e._item,o=t.store.clients.get(n.id.client)??[];return o[Gy(o,n.id.clock)].content.type}}get isForkedFromRemote(){return void 0!==this.forkedState}fork(){var e;if(this.isForkedFromRemote)return;const t=null==(e=this.collaboration)?void 0:e.fragment;if(!t)throw new Error("No fragment to fork from");const n=new oy;my(n,yy(t.doc));const o=this.findTypeInOtherYdoc(t,n);this.forkedState={undoStack:tx.getState(this.editor.prosemirrorState).undoManager.undoStack,originalFragment:t,forkedFragment:o},this.editor._tiptapEditor.unregisterPlugin([nx,tx,ex]),this.editor._tiptapEditor.registerPlugin(new KE(o).plugins[0]),this.editor._tiptapEditor.registerPlugin(new ZE({editor:this.editor}).plugins[0]),this.emit("forked",!0)}merge({keepChanges:e}){if(!this.forkedState)return;this.editor._tiptapEditor.unregisterPlugin(ex),this.editor._tiptapEditor.unregisterPlugin(tx);const{originalFragment:t,forkedFragment:n,undoStack:o}=this.forkedState;if(this.editor.extensions.ySyncPlugin=new KE(t),this.editor.extensions.yCursorPlugin=new GE(this.collaboration),this.editor.extensions.yUndoPlugin=new ZE({editor:this.editor}),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.ySyncPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yCursorPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yUndoPlugin.plugins[0]),tx.getState(this.editor.prosemirrorState).undoManager.undoStack=o,e){const e=yy(n.doc,(r=t.doc,xy(r,new ay)));my(t.doc,e,this.editor)}var r;this.forkedState=void 0,this.emit("forked",!1)}}let iM=!1;const sM=e=>{const t=[bd.ClipboardTextSerializer,bd.Commands,bd.Editable,bd.FocusEvents,bd.Tabindex,mh,kc.create({name:"dropCursor",addProseMirrorPlugins:()=>[e.dropCursor({width:5,color:"#ddeeff",editor:e.editor})]}),nw.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),sS,If,zS,FS,US,Pf.extend({inclusive:!1}).configure({defaultProtocol:gS,protocols:iM?[]:mS}),...Object.values(e.styleSpecs).map(t=>t.implementation.mark.configure({editor:e.editor})),YS,zE,XS,kc.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>!e.editor.suggestionMenus.shown&&this.editor.commands.blur()}}}),oM,tM.configure({editor:e.editor,domAttributes:e.domAttributes}),uS.configure({editor:e.editor,tabBehavior:e.tabBehavior}),nM.configure({domAttributes:e.domAttributes}),...Object.values(e.inlineContentSpecs).filter(e=>"link"!==e.config&&"text"!==e.config).map(t=>t.implementation.node.configure({editor:e.editor})),...Object.values(e.blockSpecs).flatMap(t=>[...(t.implementation.requiredExtensions||[]).map(t=>t.configure({editor:e.editor,domAttributes:e.domAttributes})),t.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),$E(e.editor),LE(e.editor,e.pasteHandler||(e=>e.defaultPasteHandler())),wE(e.editor),...void 0===e.trailingBlock||e.trailingBlock?[QS]:[],...e.comments?[JE]:[]];return iM=!0,e.collaboration||t.push(Ih),t};function lM(e,t){const n=[];return e.forEach((e,o,r)=>{r!==t&&n.push(e)}),Rn.from(n)}function aM(e,t){let n=Rn.from(e.content);if(n=function(e,t){const n=[];for(let o=0;o<e.childCount;o++)if("tableRow"===e.child(o).type.name)if(n.length>0&&"table"===n[n.length-1].type.name){const t=n[n.length-1],r=t.copy(t.content.addToEnd(e.child(o)));n[n.length-1]=r}else{const r=t.nodes.table.createChecked(void 0,e.child(o));n.push(r)}else n.push(e.child(o));return Rn.from(n)}(n,t.state.schema),!function(e,t){var n,o;const r=1===e.childCount,i="inline*"===(null==(n=e.firstChild)?void 0:n.type.spec.content),s="tableRow+"===(null==(o=e.firstChild)?void 0:o.type.spec.content);if(r){if(i)return!1;if(s){const e=Lw(t.state);if(e.isBlockContainer)return!("tableRow+"===e.blockContent.node.type.spec.content)}}return!0}(n,t))return new _n(n,e.openStart,e.openEnd);for(let o=0;o<n.childCount;o++)if("blockContent"===n.child(o).type.spec.group){const e=[n.child(o)];if(o+1<n.childCount&&"blockGroup"===n.child(o+1).type.name){const t=n.child(o+1).child(0).child(0);("bulletListItem"===t.type.name||"numberedListItem"===t.type.name||"checkListItem"===t.type.name)&&(e.push(n.child(o+1)),n=lM(n,o+1))}const r=t.state.schema.nodes.blockContainer.createChecked(void 0,e);n=n.replaceChild(o,r)}return new _n(n,e.openStart,e.openEnd)}const cM=class extends xd{constructor(e,t){super({...e,content:void 0}),ew(this,"_state"),ew(this,"mount",(e,t,n)=>{t?(this.options.element=t,this.createViewAlternative(e,n)):(this.destroy(),this.isInitialized=!1)});const n=this.schema;let o;const r=n.nodes.doc.createAndFill;let i;n.nodes.doc.createAndFill=(...e)=>{if(o)return o;const t=r.apply(n.nodes.doc,e),i=JSON.parse(JSON.stringify(t.toJSON()));return i.content[0].content[0].attrs.id="initialBlockId",o=Xn.fromJSON(n,i),o};try{i=Uc({type:"doc",content:[{type:"blockGroup",content:null==e?void 0:e.content.map(e=>pk(e,this.schema,t).toJSON())}]},this.schema,this.options.parseOptions)}catch(s){throw new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(e.content))}this._state=Fr.create({doc:i,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}dispatch(e){if(!this.view)return this._state=this.state.apply(e),void this.emit("transaction",{editor:this,transaction:e});if(this.view.isDestroyed)return;if(this.isCapturingTransaction)return void this.dispatchTransaction(e);const{state:t,transactions:n}=this.state.applyTransaction(e),o=!this.state.selection.eq(t.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),o&&this.emit("selectionUpdate",{editor:this,transaction:e});const r=e.getMeta("focus"),i=e.getMeta("blur");r&&this.emit("focus",{editor:this,event:r.event,transaction:e}),i&&this.emit("blur",{editor:this,event:i.event,transaction:e}),e.docChanged&&!e.getMeta("preventUpdate")&&(this.emit("update",{editor:this,transaction:e}),this.emit("v3-update",{editor:this,transaction:e,appendedTransactions:n.slice(1)}))}forceEnablePlugins(){if(this.view)throw new Error("forcePluginsEnabled called after view has been initialized");this._state=this.state.reconfigure({plugins:this.extensionManager.plugins})}createViewAlternative(e,t){this.contentComponent=t;const n={};this.extensionManager.extensions.forEach(t=>{"mark"===t.type&&t.config.addMarkView&&(n[t.name]=t.config.addMarkView(e))}),this.view=new sa({mount:this.options.element},{...this.options.editorProps,dispatchTransaction:this.dispatch.bind(this),state:this.state,markViews:n,nodeViews:this.extensionManager.nodeViews});const o=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(o),this.commands.focus(this.options.autofocus||"true"===this.options.element.getAttribute("data-bn-autofocus"),{scrollIntoView:!1}),this.emit("create",{editor:this}),this.isInitialized=!0}};ew(cM,"create",(e,t)=>{var n,o;const r=null==(n=null==globalThis?void 0:globalThis.window)?void 0:n.setTimeout;typeof(null==(o=null==globalThis?void 0:globalThis.window)?void 0:o.setTimeout)<"u"&&(globalThis.window.setTimeout=()=>0);try{return new cM(e,t)}finally{r&&(globalThis.window.setTimeout=r)}});let dM=cM;dM.prototype.createView=function(){this.options.onPaste=this.options.onDrop=void 0};const uM={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};let hM,pM=class e extends FE{constructor(e){var t,n,o,r,i,s,l,a,c,d,u,h,p,f,m,g;super(),ew(this,"pmSchema"),ew(this,"extensions",{}),ew(this,"headless",!1),ew(this,"_tiptapEditor"),ew(this,"elementRenderer",null),ew(this,"blockCache",new WeakMap),ew(this,"dictionary"),ew(this,"schema"),ew(this,"blockImplementations"),ew(this,"inlineContentImplementations"),ew(this,"styleImplementations"),ew(this,"formattingToolbar"),ew(this,"linkToolbar"),ew(this,"sideMenu"),ew(this,"suggestionMenus"),ew(this,"filePanel"),ew(this,"tableHandles"),ew(this,"comments"),ew(this,"showSelectionPlugin"),ew(this,"forkYDocPlugin"),ew(this,"uploadFile"),ew(this,"onUploadStartCallbacks",[]),ew(this,"onUploadEndCallbacks",[]),ew(this,"resolveFileUrl"),ew(this,"resolveUsers"),ew(this,"settings"),ew(this,"activeTransaction",null),ew(this,"mount",(e,t)=>{this._tiptapEditor.mount(this,e,t)}),this.options=e;const y=e;if(y.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(y.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(y.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(y.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=e.dictionary||Yx,this.settings={tables:{splitCells:(null==(t=null==e?void 0:e.tables)?void 0:t.splitCells)??!1,cellBackgroundColor:(null==(n=null==e?void 0:e.tables)?void 0:n.cellBackgroundColor)??!1,cellTextColor:(null==(o=null==e?void 0:e.tables)?void 0:o.cellTextColor)??!1,headers:(null==(r=null==e?void 0:e.tables)?void 0:r.headers)??!1},codeBlock:{indentLineWithTab:(null==(i=null==e?void 0:e.codeBlock)?void 0:i.indentLineWithTab)??!0,defaultLanguage:(null==(s=null==e?void 0:e.codeBlock)?void 0:s.defaultLanguage)??"text",supportedLanguages:(null==(l=null==e?void 0:e.codeBlock)?void 0:l.supportedLanguages)??{},createHighlighter:(null==(a=null==e?void 0:e.codeBlock)?void 0:a.createHighlighter)??void 0},heading:{levels:(null==(c=null==e?void 0:e.heading)?void 0:c.levels)??[1,2,3]}};const b={defaultStyles:!0,schema:e.schema||GC.create(),_headless:!1,...e,placeholders:{...this.dictionary.placeholders,...e.placeholders}};if(b.comments&&!b.resolveUsers)throw new Error("resolveUsers is required when using comments");this.resolveUsers=b.resolveUsers,this.schema=b.schema,this.blockImplementations=b.schema.blockSpecs,this.inlineContentImplementations=b.schema.inlineContentSpecs,this.styleImplementations=b.schema.styleSpecs,this.extensions=(e=>{var t;const n={},o=sM(e);for(const i of o)n[i.name]=i;e.collaboration&&(n.ySyncPlugin=new KE(e.collaboration.fragment),n.yUndoPlugin=new ZE({editor:e.editor}),null!=(t=e.collaboration.provider)&&t.awareness&&(n.yCursorPlugin=new GE(e.collaboration)),n.forkYDocPlugin=new rM({editor:e.editor,collaboration:e.collaboration})),n.formattingToolbar=new iS(e.editor),n.linkToolbar=new fS(e.editor),n.sideMenu=new IS(e.editor),n.suggestionMenus=new $S(e.editor),n.filePanel=new nS(e.editor),n.placeholder=new xS(e.editor,e.placeholders),(e.animations??!0)&&(n.animations=new CS),e.tableHandles&&(n.tableHandles=new JS(e.editor)),n.nodeSelectionKeyboard=new bS,n.blockChange=new WE,n.showSelection=new SS(e.editor),e.comments&&(n.comments=new QE(e.editor,e.comments.threadStore,JE.name));const r=e.disableExtensions||[];for(const i of r)delete n[i];return n})({editor:this,domAttributes:b.domAttributes||{},blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:b.collaboration,trailingBlock:b.trailingBlock,disableExtensions:b.disableExtensions,setIdAttribute:b.setIdAttribute,animations:b.animations??!0,tableHandles:HC("table",this),dropCursor:this.options.dropCursor??Jx,placeholders:b.placeholders,tabBehavior:b.tabBehavior,comments:b.comments,pasteHandler:b.pasteHandler}),((null==(d=b._tiptapOptions)?void 0:d.extensions)||[]).forEach(e=>{this.extensions[e.name]=e});for(let S of b.extensions||[]){"function"==typeof S&&(S=S(this));const e=S.constructor.key();if(!e)throw new Error(`Extension ${S.constructor.name} does not have a key method`);if(this.extensions[e])throw new Error(`Extension ${S.constructor.name} already exists with key ${e}`);this.extensions[e]=S}if(Object.entries(b._extensions||{}).forEach(([e,t])=>{const n="function"==typeof t?t(this):t;this.extensions[e]="plugin"in n?new class extends UE{static key(){return e}constructor(){super(),this.addProsemirrorPlugin(n.plugin)}get priority(){return n.priority}}:n}),this.formattingToolbar=this.extensions.formattingToolbar,this.linkToolbar=this.extensions.linkToolbar,this.sideMenu=this.extensions.sideMenu,this.suggestionMenus=this.extensions.suggestionMenus,this.filePanel=this.extensions.filePanel,this.tableHandles=this.extensions.tableHandles,this.comments=this.extensions.comments,this.showSelectionPlugin=this.extensions.showSelection,this.forkYDocPlugin=this.extensions.forkYDocPlugin,b.uploadFile){const e=b.uploadFile;this.uploadFile=async(t,n)=>{this.onUploadStartCallbacks.forEach(e=>e.apply(this,[n]));try{return await e(t,n)}finally{this.onUploadEndCallbacks.forEach(e=>e.apply(this,[n]))}}}this.resolveFileUrl=b.resolveFileUrl,this.headless=b._headless;const v="ySyncPlugin"in this.extensions||"liveblocksExtension"in this.extensions;v&&b.initialContent;const x=b.initialContent||(v?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:nw.options.generateID()}]);if(!Array.isArray(x)||0===x.length)throw new Error("initialContent must be a non-empty array of blocks, received: "+x);const w=[...Object.entries(this.extensions).map(([e,t])=>t instanceof kc||t instanceof kd||t instanceof gc?t:t instanceof UE&&!t.plugins.length?void 0:kc.create({name:e,priority:t.priority,addProseMirrorPlugins:()=>t.plugins}))].filter(e=>void 0!==e),k={...uM,...b._tiptapOptions,content:x,extensions:w,editorProps:{...null==(u=b._tiptapOptions)?void 0:u.editorProps,attributes:{tabIndex:"0",...null==(p=null==(h=b._tiptapOptions)?void 0:h.editorProps)?void 0:p.attributes,...null==(f=b.domAttributes)?void 0:f.editor,class:fw("bn-editor",b.defaultStyles?"bn-default-styles":"",(null==(g=null==(m=b.domAttributes)?void 0:m.editor)?void 0:g.class)||"")},transformPasted:aM}};var C,E;this.headless?this.pmSchema=(C=k.extensions,sc(wc.resolve(C),E)):(this._tiptapEditor=dM.create(k,this.schema.styleSchema),this.pmSchema=this._tiptapEditor.schema),this.pmSchema.cached.blockNoteEditor=this,this.emit("create")}static create(t={}){return new e(t)}exec(e){if(this.activeTransaction)throw new Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");return e(this._tiptapEditor.state,e=>this._tiptapEditor.dispatch(e),this._tiptapEditor.view)}canExec(e){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");return e(this._tiptapEditor.state,void 0,this._tiptapEditor.view)}transact(e){if(this.activeTransaction)return e(this.activeTransaction);try{this.activeTransaction=this._tiptapEditor.state.tr;const t=e(this.activeTransaction),n=this.activeTransaction;return this.activeTransaction=null,n&&(n.docChanged||n.selectionSet||n.scrolledIntoView||n.storedMarksSet||!n.isGeneric)&&this._tiptapEditor.dispatch(n),t}finally{this.activeTransaction=null}}extension(e,t=e.key()){const n=this.extensions[t];if(!n)throw new Error(`Extension ${t} not found`);return n}get prosemirrorState(){if(this.activeTransaction)throw new Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this._tiptapEditor.state}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){var e;return null==(e=this.prosemirrorView)?void 0:e.dom}isFocused(){var e;return(null==(e=this.prosemirrorView)?void 0:e.hasFocus())||!1}focus(){var e;null==(e=this.prosemirrorView)||e.focus()}onUploadStart(e){return this.onUploadStartCallbacks.push(e),()=>{const t=this.onUploadStartCallbacks.indexOf(e);t>-1&&this.onUploadStartCallbacks.splice(t,1)}}onUploadEnd(e){return this.onUploadEndCallbacks.push(e),()=>{const t=this.onUploadEndCallbacks.indexOf(e);t>-1&&this.onUploadEndCallbacks.splice(t,1)}}get topLevelBlocks(){return this.document}get document(){return this.transact(e=>function(e,t,n=$w(t),o=zw(t),r=Fw(t),i=Uw(t)){const s=[];return e.firstChild.descendants(e=>(s.push(Gw(e,t,n,o,r,i)),!1)),s}(e.doc,this.pmSchema))}getBlock(e){return this.transact(t=>function(e,t){const n="string"==typeof t?t:t.id,o=Bw(e),r=fk(n,e);if(r)return Gw(r.node,o)}(t.doc,e))}getPrevBlock(e){return this.transact(t=>function(e,t){const n=fk("string"==typeof t?t:t.id,e),o=Bw(e);if(!n)return;const r=e.resolve(n.posBeforeNode).nodeBefore;return r?Gw(r,o):void 0}(t.doc,e))}getNextBlock(e){return this.transact(t=>function(e,t){const n=fk("string"==typeof t?t:t.id,e),o=Bw(e);if(!n)return;const r=e.resolve(n.posBeforeNode+n.node.nodeSize).nodeAfter;return r?Gw(r,o):void 0}(t.doc,e))}getParentBlock(e){return this.transact(t=>function(e,t){const n="string"==typeof t?t:t.id,o=Bw(e),r=fk(n,e);if(!r)return;const i=e.resolve(r.posBeforeNode),s=i.node(),l=i.node(-1),a="doc"!==l.type.name?"blockGroup"===s.type.name?l:s:void 0;return a?Gw(a,o):void 0}(t.doc,e))}forEachBlock(e,t=!1){const n=this.document.slice();t&&n.reverse(),function n(o){for(const r of o){if(!1===e(r))return!1;if(!n(t?r.children.slice().reverse():r.children))return!1}return!0}(n)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}getTextCursorPosition(){return this.transact(e=>function(e){const{bnBlock:t}=Dw(e),n=Bw(e.doc),o=e.doc.resolve(t.beforePos),r=o.nodeBefore,i=e.doc.resolve(t.afterPos).nodeAfter;let s;return o.depth>1&&(s=o.node(),s.type.isInGroup("bnBlock")||(s=o.node(o.depth-1))),{block:Gw(t.node,n),prevBlock:null===r?void 0:Gw(r,n),nextBlock:null===i?void 0:Gw(i,n),parentBlock:void 0===s?void 0:Gw(s,n)}}(e))}setTextCursorPosition(e,t="start"){return this.transact(n=>rE(n,e,t))}getSelection(){return this.transact(e=>function(e){const t=Bw(e);if(e.selection.empty||"node"in e.selection)return;const n=e.doc.resolve(Ow(e.doc,e.selection.from).posBeforeNode),o=e.doc.resolve(Ow(e.doc,e.selection.to).posBeforeNode),r=(o,r)=>{const i=n.posAtIndex(o,r),s=e.doc.resolve(i).nodeAfter;if(!s)throw new Error(`Error getting selection - node not found at position ${i}`);return Gw(s,t)},i=[],s=n.sharedDepth(o.pos),l=n.index(s),a=o.index(s);if(n.depth>s){i.push(Gw(n.nodeAfter,t));for(let e=n.depth;e>s;e--)if(n.node(e).type.isInGroup("childContainer")){const t=n.index(e)+1,o=n.node(e).childCount;for(let n=t;n<o;n++)i.push(r(n,e))}}else i.push(r(l,s));for(let c=l+1;c<=a;c++)i.push(r(c,s));if(0===i.length)throw new Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);return{blocks:i}}(e))}getSelectionCutBlocks(){return this.transact(e=>oE(e))}setSelection(e,t){return this.transact(n=>function(e,t,n){const o="string"==typeof t?t:t.id,r="string"==typeof n?n:n.id,i=Vw(Bw(e));if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const s=fk(o,e.doc);if(!s)throw new Error(`Block with ID ${o} not found`);const l=fk(r,e.doc);if(!l)throw new Error(`Block with ID ${r} not found`);const a=Pw(s),c=Pw(l),d=i.blockSchema[a.blockNoteType],u=i.blockSchema[c.blockNoteType];if(!a.isBlockContainer||"none"===d.content)throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!c.isBlockContainer||"none"===u.content)throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let h,p;if("table"===d.content){const e=Id.get(a.blockContent.node);h=a.blockContent.beforePos+e.positionAt(0,0,a.blockContent.node)+1+2}else h=a.blockContent.beforePos+1;if("table"===u.content){const t=Id.get(c.blockContent.node),n=c.blockContent.beforePos+t.positionAt(t.height-1,t.width-1,c.blockContent.node)+1;p=n+e.doc.resolve(n).nodeAfter.nodeSize-2}else p=c.blockContent.afterPos-1;e.setSelection(Nr.create(e.doc,h,p))}(n,e,t))}get isEditable(){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return!1}return void 0===this._tiptapEditor.isEditable||this._tiptapEditor.isEditable}set isEditable(e){if(this._tiptapEditor)this._tiptapEditor.options.editable!==e&&this._tiptapEditor.setEditable(e);else if(!this.headless)throw new Error("no editor, but also not headless?")}insertBlocks(e,t,n="before"){return this.transact(o=>function(e,t,n,o="before"){const r="string"==typeof n?n:n.id,i=Bw(e),s=t.map(e=>pk(e,i)),l=fk(r,e.doc);if(!l)throw new Error(`Block with ID ${r} not found`);let a=l.posBeforeNode;return"after"===o&&(a+=l.node.nodeSize),e.step(new Zo(a,a,new _n(Rn.from(s),0,0))),s.map(e=>Gw(e,i))}(o,e,t,n))}updateBlock(e,t){return this.transact(n=>function(e,t,n){const o="string"==typeof t?t:t.id,r=fk(o,e.doc);if(!r)throw new Error(`Block with ID ${o} not found`);return bk(e,r.posBeforeNode,n),Gw(e.doc.resolve(r.posBeforeNode+1).node(),Bw(e))}(n,e,t))}removeBlocks(e){return this.transact(t=>gk(t,e,[]).removedBlocks)}replaceBlocks(e,t){return this.transact(n=>gk(n,e,t))}undo(){return this.options.collaboration?this.exec(qx):this.exec(_h)}redo(){return this.options.collaboration?this.exec(Gx):this.exec(Ph)}insertInlineContent(e,{updateSelection:t=!1}={}){const n=dk(e,this.pmSchema);this.transact(e=>{!function(e,t,n,o={updateSelection:!0}){let{from:r,to:i}="number"==typeof t?{from:t,to:t}:{from:t.from,to:t.to},s=!0,l=!0,a="";if(n.forEach(e=>{e.check(),s&&e.isText&&0===e.marks.length?a+=e.text:s=!1,l=!!l&&e.isBlock}),r===i&&l){const{parent:t}=e.doc.resolve(r);t.isTextblock&&!t.type.spec.code&&!t.childCount&&(r-=1,i+=1)}s?e.insertText(a,r,i):e.replaceWith(r,i,n),o.updateSelection&&Hc(e,e.steps.length-1,-1)}(e,{from:e.selection.from,to:e.selection.to},n,{updateSelection:t})})}getActiveStyles(){return this.transact(e=>{const t={},n=e.selection.$to.marks();for(const o of n){const e=this.schema.styleSchema[o.type.name];e?"boolean"===e.propSchema?t[e.type]=!0:t[e.type]=o.attrs.stringValue:"link"!==o.type.name&&o.type.spec.blocknoteIgnore}return t})}addStyles(e){for(const[t,n]of Object.entries(e)){const e=this.schema.styleSchema[t];if(!e)throw new Error(`style ${t} not found in styleSchema`);if("boolean"===e.propSchema)this._tiptapEditor.commands.setMark(t);else{if("string"!==e.propSchema)throw new uw(e.propSchema);this._tiptapEditor.commands.setMark(t,{stringValue:n})}}}removeStyles(e){for(const t of Object.keys(e))this._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){for(const[t,n]of Object.entries(e)){const e=this.schema.styleSchema[t];if(!e)throw new Error(`style ${t} not found in styleSchema`);if("boolean"===e.propSchema)this._tiptapEditor.commands.toggleMark(t);else{if("string"!==e.propSchema)throw new uw(e.propSchema);this._tiptapEditor.commands.toggleMark(t,{stringValue:n})}}}getSelectedText(){return this.transact(e=>e.doc.textBetween(e.selection.from,e.selection.to))}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(e,t){if(""===e)return;const n=this.pmSchema.mark("link",{href:e});this.transact(e=>{const{from:o,to:r}=e.selection;t?e.insertText(t,o,r).addMark(o,o+t.length,n):e.setSelection(Nr.create(e.doc,r)).addMark(o,r,n)})}canNestBlock(){return this.transact(e=>{const{bnBlock:t}=Dw(e);return null!==e.doc.resolve(t.beforePos).nodeBefore})}nestBlock(){nE(this)}canUnnestBlock(){return this.transact(e=>{const{bnBlock:t}=Dw(e);return e.doc.resolve(t.beforePos).depth>1})}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}moveBlocksUp(){return eE(this)}moveBlocksDown(){return tE(this)}async blocksToHTMLLossy(e=this.document){return Ek(this.pmSchema,this).exportBlocks(e,{})}async blocksToFullHTML(e){return((e,t)=>{const n=jo.fromSchema(e);return{serializeBlocks:(e,o)=>Rk(t,e,n,o).outerHTML}})(this.pmSchema,this).serializeBlocks(e,{})}async tryParseHTMLToBlocks(e){return pE(e,this.pmSchema)}async blocksToMarkdownLossy(e=this.document){return async function(e,t,n,o){return await sE(),cE(Ek(t,n).exportBlocks(e,o))}(e,this.pmSchema,this,{})}async tryParseMarkdownToBlocks(e){return async function(e,t){return pE(await mE(e),t)}(e,this.pmSchema)}updateCollaborationUserInfo(e){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this.extensions.yCursorPlugin.updateUser(e)}onBeforeChange(e){return this.headless?()=>{}:this.extensions.blockChange.subscribe(t=>e(this,t))}onChange(e){if(this.headless)return;const t=({transaction:t,appendedTransactions:n})=>{e(this,{getChanges:()=>jk(t,n)})};return this._tiptapEditor.on("v3-update",t),()=>{this._tiptapEditor.off("v3-update",t)}}onSelectionChange(e,t){if(this.headless)return;const n=n=>{n.transaction.getMeta(ex)&&!t||e(this)};return this._tiptapEditor.on("selectionUpdate",n),()=>{this._tiptapEditor.off("selectionUpdate",n)}}onCreate(e){return this.on("create",e),()=>{this.off("create",e)}}getSelectionBoundingBox(){if(!this.prosemirrorView)return;const{selection:e}=this.prosemirrorState,{ranges:t}=e,n=Math.min(...t.map(e=>e.$from.pos)),o=Math.max(...t.map(e=>e.$to.pos));if(rd(e)){const e=this.prosemirrorView.nodeDOM(n);if(e)return e.getBoundingClientRect()}return id(this.prosemirrorView,n,o)}get isEmpty(){const e=this.document;return 0===e.length||1===e.length&&"paragraph"===e[0].type&&0===e[0].content.length}openSuggestionMenu(e,t){this.prosemirrorView&&(this.focus(),this.transact(n=>{null!=t&&t.deleteTriggerCharacter&&n.insertText(e),n.scrollIntoView().setMeta(this.suggestionMenus.plugins[0],{triggerCharacter:e,deleteTriggerCharacter:(null==t?void 0:t.deleteTriggerCharacter)||!1,ignoreQueryLength:(null==t?void 0:t.ignoreQueryLength)||!1})}))}getForceSelectionVisible(){return this.showSelectionPlugin.getEnabled()}setForceSelectionVisible(e){this.showSelectionPlugin.setEnabled(e)}convertHtmlToBlockNoteHtml(e){return hE(e.trim()).innerHTML}pasteHTML(e,t=!1){var n;let o=e;t||(o=this.convertHtmlToBlockNoteHtml(e)),o&&(null==(n=this.prosemirrorView)||n.pasteHTML(o))}pasteText(e){var t;return null==(t=this.prosemirrorView)?void 0:t.pasteText(e)}async pasteMarkdown(e){return this.pasteHTML(await mE(e))}};async function fM(e,t){if(!function(e,t){return e in t.schema.inlineContentSchema&&t.schema.inlineContentSchema[e]===BC[e]}("text",e))return[];const{emojiData:n,emojiMart:o}=await async function(){return hM||(hM=(async()=>{const[e,t]=await Promise.all([Promise.resolve().then(()=>require("./module-B6LwlNJR.cjs")),Promise.resolve().then(()=>require("./native-CLBO_ikU.cjs"))]),n="default"in e?e.default:e,o="default"in t?t.default:t;return await n.init({data:o}),{emojiMart:n,emojiData:o}})(),hM)}();return(""===t.trim()?Object.values(n.emojis):await o.SearchIndex.search(t)).map(t=>({id:t.skins[0].native,onItemClick:()=>e.insertInlineContent(t.skins[0].native+" ")}))}var mM,gM={exports:{}},yM={};var bM,vM={};
5
+ */var ge=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"].join(","),ye="undefined"==typeof Element,be=ye?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,ve=!ye&&Element.prototype.getRootNode?function(e){var t;return null==e||null===(t=e.getRootNode)||void 0===t?void 0:t.call(e)}:function(e){return null==e?void 0:e.ownerDocument},xe=function(e,t){var n;void 0===t&&(t=!0);var o=null==e||null===(n=e.getAttribute)||void 0===n?void 0:n.call(e,"inert");return""===o||"true"===o||t&&e&&xe(e.parentNode)},we=function(e,t,n){for(var o=[],r=Array.from(e);r.length;){var i=r.shift();if(!xe(i,!1))if("SLOT"===i.tagName){var s=i.assignedElements(),l=s.length?s:i.children,a=we(l,!0,n);n.flatten?o.push.apply(o,a):o.push({scopeParent:i,candidates:a})}else{be.call(i,ge)&&n.filter(i)&&(t||!e.includes(i))&&o.push(i);var c=i.shadowRoot||"function"==typeof n.getShadowRoot&&n.getShadowRoot(i),d=!xe(c,!1)&&(!n.shadowRootFilter||n.shadowRootFilter(i));if(c&&d){var u=we(!0===c?i.children:c.children,!0,n);n.flatten?o.push.apply(o,u):o.push({scopeParent:i,candidates:u})}else r.unshift.apply(r,i.children)}}return o},ke=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},Ce=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||function(e){var t,n=null==e||null===(t=e.getAttribute)||void 0===t?void 0:t.call(e,"contenteditable");return""===n||"true"===n}(e))&&!ke(e)?0:e.tabIndex},Ee=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},Se=function(e){return"INPUT"===e.tagName},Me=function(e){return function(e){return Se(e)&&"radio"===e.type}(e)&&!function(e){if(!e.name)return!0;var t,n=e.form||ve(e),o=function(e){return n.querySelectorAll('input[type="radio"][name="'+e+'"]')};if("undefined"!=typeof window&&void 0!==window.CSS&&"function"==typeof window.CSS.escape)t=o(window.CSS.escape(e.name));else try{t=o(e.name)}catch(i){return!1}var r=function(e,t){for(var n=0;n<e.length;n++)if(e[n].checked&&e[n].form===t)return e[n]}(t,e.form);return!r||r===e}(e)},Re=function(e){var t=e.getBoundingClientRect(),n=t.width,o=t.height;return 0===n&&0===o},Te=function(e,t){var n=t.displayCheck,o=t.getShadowRoot;if("full-native"===n&&"checkVisibility"in e)return!e.checkVisibility({checkOpacity:!1,opacityProperty:!1,contentVisibilityAuto:!0,visibilityProperty:!0,checkVisibilityCSS:!0});if("hidden"===getComputedStyle(e).visibility)return!0;var r=be.call(e,"details>summary:first-of-type")?e.parentElement:e;if(be.call(r,"details:not([open]) *"))return!0;if(n&&"full"!==n&&"full-native"!==n&&"legacy-full"!==n){if("non-zero-area"===n)return Re(e)}else{if("function"==typeof o){for(var i=e;e;){var s=e.parentElement,l=ve(e);if(s&&!s.shadowRoot&&!0===o(s))return Re(e);e=e.assignedSlot?e.assignedSlot:s||l===e.ownerDocument?s:l.host}e=i}if(function(e){var t,n,o,r,i=e&&ve(e),s=null===(t=i)||void 0===t?void 0:t.host,l=!1;if(i&&i!==e)for(l=!!(null!==(n=s)&&void 0!==n&&null!==(o=n.ownerDocument)&&void 0!==o&&o.contains(s)||null!=e&&null!==(r=e.ownerDocument)&&void 0!==r&&r.contains(e));!l&&s;){var a,c,d;l=!(null===(c=s=null===(a=i=ve(s))||void 0===a?void 0:a.host)||void 0===c||null===(d=c.ownerDocument)||void 0===d||!d.contains(s))}return l}(e))return!e.getClientRects().length;if("legacy-full"!==n)return!0}return!1},je=function(e,t){return!(t.disabled||xe(t)||function(e){return Se(e)&&"hidden"===e.type}(t)||Te(t,e)||function(e){return"DETAILS"===e.tagName&&Array.prototype.slice.apply(e.children).some(function(e){return"SUMMARY"===e.tagName})}(t)||function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var t=e.parentElement;t;){if("FIELDSET"===t.tagName&&t.disabled){for(var n=0;n<t.children.length;n++){var o=t.children.item(n);if("LEGEND"===o.tagName)return!!be.call(t,"fieldset[disabled] *")||!o.contains(e)}return!0}t=t.parentElement}return!1}(t))},Ne=function(e,t){return!(Me(t)||Ce(t)<0||!je(e,t))},Ae=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(t)||t>=0)},Oe=function(e){var t=[],n=[];return e.forEach(function(e,o){var r=!!e.scopeParent,i=r?e.scopeParent:e,s=function(e,t){var n=Ce(e);return n<0&&t&&!ke(e)?0:n}(i,r),l=r?Oe(e.candidates):i;0===s?r?t.push.apply(t,l):t.push(i):n.push({documentOrder:o,tabIndex:s,item:e,isScope:r,content:l})}),n.sort(Ee).reduce(function(e,t){return t.isScope?e.push.apply(e,t.content):e.push(t.content),e},[]).concat(t)},_e=function(e,t){var n;return n=(t=t||{}).getShadowRoot?we([e],t.includeContainer,{filter:Ne.bind(null,t),flatten:!1,getShadowRoot:t.getShadowRoot,shadowRootFilter:Ae}):function(e,t,n){if(xe(e))return[];var o=Array.prototype.slice.apply(e.querySelectorAll(ge));return t&&be.call(e,ge)&&o.unshift(e),o.filter(n)}(e,t.includeContainer,Ne.bind(null,t)),Oe(n)};function Pe(e,t,n){let{reference:o,floating:r}=e;const i=ie(t),s=se(t),l=oe(s),a=ee(t),c="y"===i,d=o.x+o.width/2-r.width/2,u=o.y+o.height/2-r.height/2,h=o[l]/2-r[l]/2;let p;switch(a){case"top":p={x:d,y:o.y-r.height};break;case"bottom":p={x:d,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:u};break;case"left":p={x:o.x-r.width,y:u};break;default:p={x:o.x,y:o.y}}switch(te(t)){case"start":p[s]-=h*(n&&c?-1:1);break;case"end":p[s]+=h*(n&&c?-1:1)}return p}async function Ie(e,t){var n;void 0===t&&(t={});const{x:o,y:r,platform:i,rects:s,elements:l,strategy:a}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:h=!1,padding:p=0}=Q(t,e),f=fe(p),m=l[h?"floating"===u?"reference":"floating":u],g=me(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(m)))||n?m:m.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(l.floating)),boundary:c,rootBoundary:d,strategy:a})),y="floating"===u?{x:o,y:r,width:s.floating.width,height:s.floating.height}:s.reference,b=await(null==i.getOffsetParent?void 0:i.getOffsetParent(l.floating)),v=await(null==i.isElement?void 0:i.isElement(b))&&await(null==i.getScale?void 0:i.getScale(b))||{x:1,y:1},x=me(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:y,offsetParent:b,strategy:a}):y);return{top:(g.top-x.top+f.top)/v.y,bottom:(x.bottom-g.bottom+f.bottom)/v.y,left:(g.left-x.left+f.left)/v.x,right:(x.right-g.right+f.right)/v.x}}function Le(e){const t=W(...e.map(e=>e.left)),n=W(...e.map(e=>e.top));return{x:t,y:n,width:q(...e.map(e=>e.right))-t,height:q(...e.map(e=>e.bottom))-n}}const De=new Set(["left","top"]);function Be(e){const t=T(e);let n=parseFloat(t.width)||0,o=parseFloat(t.height)||0;const r=p(e),i=r?e.offsetWidth:n,s=r?e.offsetHeight:o,l=G(n)!==i||G(o)!==s;return l&&(n=i,o=s),{width:n,height:o,$:l}}function He(e){return h(e)?e:e.contextElement}function Ve(e){const t=He(e);if(!p(t))return Z(1);const n=t.getBoundingClientRect(),{width:o,height:r,$:i}=Be(t);let s=(i?G(n.width):n.width)/o,l=(i?G(n.height):n.height)/r;return s&&Number.isFinite(s)||(s=1),l&&Number.isFinite(l)||(l=1),{x:s,y:l}}const $e=Z(0);function ze(e){const t=c(e);return S()&&t.visualViewport?{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}:$e}function Fe(e,t,n,o){void 0===t&&(t=!1),void 0===n&&(n=!1);const r=e.getBoundingClientRect(),i=He(e);let s=Z(1);t&&(o?h(o)&&(s=Ve(o)):s=Ve(e));const l=function(e,t,n){return void 0===t&&(t=!1),!(!n||t&&n!==c(e))&&t}(i,n,o)?ze(i):Z(0);let a=(r.left+l.x)/s.x,d=(r.top+l.y)/s.y,u=r.width/s.x,p=r.height/s.y;if(i){const e=c(i),t=o&&h(o)?c(o):o;let n=e,r=_(n);for(;r&&o&&t!==n;){const e=Ve(r),t=r.getBoundingClientRect(),o=T(r),i=t.left+(r.clientLeft+parseFloat(o.paddingLeft))*e.x,s=t.top+(r.clientTop+parseFloat(o.paddingTop))*e.y;a*=e.x,d*=e.y,u*=e.x,p*=e.y,a+=i,d+=s,n=c(r),r=_(n)}}return me({width:u,height:p,x:a,y:d})}function Ue(e,t){const n=j(e).scrollLeft;return t?t.left+n:Fe(d(e)).left+n}function We(e,t){const n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Ue(e,n),y:n.top+t.scrollTop}}const qe=new Set(["absolute","fixed"]);function Ge(e,t,n){let o;if("viewport"===t)o=function(e,t){const n=c(e),o=d(e),r=n.visualViewport;let i=o.clientWidth,s=o.clientHeight,l=0,a=0;if(r){i=r.width,s=r.height;const e=S();(!e||e&&"fixed"===t)&&(l=r.offsetLeft,a=r.offsetTop)}const u=Ue(o);if(u<=0){const e=o.ownerDocument,t=e.body,n=getComputedStyle(t),r="CSS1Compat"===e.compatMode&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,s=Math.abs(o.clientWidth-t.clientWidth-r);s<=25&&(i-=s)}else u<=25&&(i+=u);return{width:i,height:s,x:l,y:a}}(e,n);else if("document"===t)o=function(e){const t=d(e),n=j(e),o=e.ownerDocument.body,r=q(t.scrollWidth,t.clientWidth,o.scrollWidth,o.clientWidth),i=q(t.scrollHeight,t.clientHeight,o.scrollHeight,o.clientHeight);let s=-n.scrollLeft+Ue(e);const l=-n.scrollTop;return"rtl"===T(o).direction&&(s+=q(t.clientWidth,o.clientWidth)-r),{width:r,height:i,x:s,y:l}}(d(e));else if(h(t))o=function(e,t){const n=Fe(e,!0,"fixed"===t),o=n.top+e.clientTop,r=n.left+e.clientLeft,i=p(e)?Ve(e):Z(1);return{width:e.clientWidth*i.x,height:e.clientHeight*i.y,x:r*i.x,y:o*i.y}}(t,n);else{const n=ze(e);o={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return me(o)}function Ke(e,t){const n=N(e);return!(n===t||!h(n)||R(n))&&("fixed"===T(n).position||Ke(n,t))}function Ze(e,t,n){const o=p(t),r=d(t),i="fixed"===n,s=Fe(e,!0,i,t);let l={scrollLeft:0,scrollTop:0};const c=Z(0);function u(){c.x=Ue(r)}if(o||!o&&!i)if(("body"!==a(t)||g(r))&&(l=j(t)),o){const e=Fe(t,!0,i,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else r&&u();i&&!o&&r&&u();const h=!r||o||i?Z(0):We(r,l);return{x:s.left+l.scrollLeft-c.x-h.x,y:s.top+l.scrollTop-c.y-h.y,width:s.width,height:s.height}}function Je(e){return"static"===T(e).position}function Xe(e,t){if(!p(e)||"fixed"===T(e).position)return null;if(t)return t(e);let n=e.offsetParent;return d(e)===n&&(n=n.ownerDocument.body),n}function Ye(e,t){const n=c(e);if(x(e))return n;if(!p(e)){let t=N(e);for(;t&&!R(t);){if(h(t)&&!Je(t))return t;t=N(t)}return n}let o=Xe(e,t);for(;o&&b(o)&&Je(o);)o=Xe(o,t);return o&&R(o)&&Je(o)&&!E(o)?n:o||function(e){let t=N(e);for(;p(t)&&!R(t);){if(E(t))return t;if(x(t))return null;t=N(t)}return null}(e)||n}const Qe={convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{elements:t,rect:n,offsetParent:o,strategy:r}=e;const i="fixed"===r,s=d(o),l=!!t&&x(t.floating);if(o===s||l&&i)return n;let c={scrollLeft:0,scrollTop:0},u=Z(1);const h=Z(0),f=p(o);if((f||!f&&!i)&&(("body"!==a(o)||g(s))&&(c=j(o)),p(o))){const e=Fe(o);u=Ve(o),h.x=e.x+o.clientLeft,h.y=e.y+o.clientTop}const m=!s||f||i?Z(0):We(s,c);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-c.scrollLeft*u.x+h.x+m.x,y:n.y*u.y-c.scrollTop*u.y+h.y+m.y}},getDocumentElement:d,getClippingRect:function(e){let{element:t,boundary:n,rootBoundary:o,strategy:r}=e;const i=[..."clippingAncestors"===n?x(t)?[]:function(e,t){const n=t.get(e);if(n)return n;let o=O(e,[],!1).filter(e=>h(e)&&"body"!==a(e)),r=null;const i="fixed"===T(e).position;let s=i?N(e):e;for(;h(s)&&!R(s);){const t=T(s),n=E(s);n||"fixed"!==t.position||(r=null),(i?!n&&!r:!n&&"static"===t.position&&r&&qe.has(r.position)||g(s)&&!n&&Ke(e,s))?o=o.filter(e=>e!==s):r=t,s=N(s)}return t.set(e,o),o}(t,this._c):[].concat(n),o],s=i[0],l=i.reduce((e,n)=>{const o=Ge(t,n,r);return e.top=q(o.top,e.top),e.right=W(o.right,e.right),e.bottom=W(o.bottom,e.bottom),e.left=q(o.left,e.left),e},Ge(t,s,r));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}},getOffsetParent:Ye,getElementRects:async function(e){const t=this.getOffsetParent||Ye,n=this.getDimensions,o=await n(e.floating);return{reference:Ze(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(e){return Array.from(e.getClientRects())},getDimensions:function(e){const{width:t,height:n}=Be(e);return{width:t,height:n}},getScale:Ve,isElement:h,isRTL:function(e){return"rtl"===T(e).direction}};function et(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function tt(e,t,n,o){void 0===o&&(o={});const{ancestorScroll:r=!0,ancestorResize:i=!0,elementResize:s="function"==typeof ResizeObserver,layoutShift:l="function"==typeof IntersectionObserver,animationFrame:a=!1}=o,c=He(e),u=r||i?[...c?O(c):[],...O(t)]:[];u.forEach(e=>{r&&e.addEventListener("scroll",n,{passive:!0}),i&&e.addEventListener("resize",n)});const h=c&&l?function(e,t){let n,o=null;const r=d(e);function i(){var e;clearTimeout(n),null==(e=o)||e.disconnect(),o=null}return function s(l,a){void 0===l&&(l=!1),void 0===a&&(a=1),i();const c=e.getBoundingClientRect(),{left:d,top:u,width:h,height:p}=c;if(l||t(),!h||!p)return;const f={rootMargin:-K(u)+"px "+-K(r.clientWidth-(d+h))+"px "+-K(r.clientHeight-(u+p))+"px "+-K(d)+"px",threshold:q(0,W(1,a))||1};let m=!0;function g(t){const o=t[0].intersectionRatio;if(o!==a){if(!m)return s();o?s(!1,o):n=setTimeout(()=>{s(!1,1e-7)},1e3)}1!==o||et(c,e.getBoundingClientRect())||s(),m=!1}try{o=new IntersectionObserver(g,{...f,root:r.ownerDocument})}catch(y){o=new IntersectionObserver(g,f)}o.observe(e)}(!0),i}(c,n):null;let p,f=-1,m=null;s&&(m=new ResizeObserver(e=>{let[o]=e;o&&o.target===c&&m&&(m.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;null==(e=m)||e.observe(t)})),n()}),c&&!a&&m.observe(c),m.observe(t));let g=a?Fe(e):null;return a&&function t(){const o=Fe(e);g&&!et(g,o)&&n();g=o,p=requestAnimationFrame(t)}(),n(),()=>{var e;u.forEach(e=>{r&&e.removeEventListener("scroll",n),i&&e.removeEventListener("resize",n)}),null==h||h(),null==(e=m)||e.disconnect(),m=null,a&&cancelAnimationFrame(p)}}const nt=function(e){return void 0===e&&(e=0),{name:"offset",options:e,async fn(t){var n,o;const{x:r,y:i,placement:s,middlewareData:l}=t,a=await async function(e,t){const{placement:n,platform:o,elements:r}=e,i=await(null==o.isRTL?void 0:o.isRTL(r.floating)),s=ee(n),l=te(n),a="y"===ie(n),c=De.has(s)?-1:1,d=i&&a?-1:1,u=Q(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:f}="number"==typeof u?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return l&&"number"==typeof f&&(p="end"===l?-1*f:f),a?{x:p*d,y:h*c}:{x:h*c,y:p*d}}(t,e);return s===(null==(n=l.offset)?void 0:n.placement)&&null!=(o=l.arrow)&&o.alignmentOffset?{}:{x:r+a.x,y:i+a.y,data:{...a,placement:s}}}}},ot=function(e){return void 0===e&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:o,placement:r}=t,{mainAxis:i=!0,crossAxis:s=!1,limiter:l={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...a}=Q(e,t),c={x:n,y:o},d=await Ie(t,a),u=ie(ee(r)),h=ne(u);let p=c[h],f=c[u];if(i){const e="y"===h?"bottom":"right";p=Y(p+d["y"===h?"top":"left"],p,p-d[e])}if(s){const e="y"===u?"bottom":"right";f=Y(f+d["y"===u?"top":"left"],f,f-d[e])}const m=l.fn({...t,[h]:p,[u]:f});return{...m,data:{x:m.x-n,y:m.y-o,enabled:{[h]:i,[u]:s}}}}}},rt=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(t){var n,o;const{placement:r,middlewareData:i,rects:s,initialPlacement:l,platform:a,elements:c}=t,{mainAxis:d=!0,crossAxis:u=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...g}=Q(e,t);if(null!=(n=i.arrow)&&n.alignmentOffset)return{};const y=ee(r),b=ie(l),v=ee(l)===l,x=await(null==a.isRTL?void 0:a.isRTL(c.floating)),w=h||(v||!m?[pe(l)]:function(e){const t=pe(e);return[le(e),t,le(t)]}(l)),k="none"!==f;!h&&k&&w.push(...he(l,m,f,x));const C=[l,...w],E=await Ie(t,g),S=[];let M=(null==(o=i.flip)?void 0:o.overflows)||[];if(d&&S.push(E[y]),u){const e=function(e,t,n){void 0===n&&(n=!1);const o=te(e),r=se(e),i=oe(r);let s="x"===r?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return t.reference[i]>t.floating[i]&&(s=pe(s)),[s,pe(s)]}(r,s,x);S.push(E[e[0]],E[e[1]])}if(M=[...M,{placement:r,overflows:S}],!S.every(e=>e<=0)){var R,T;const e=((null==(R=i.flip)?void 0:R.index)||0)+1,t=C[e];if(t){if(!("alignment"===u&&b!==ie(t))||M.every(e=>ie(e.placement)!==b||e.overflows[0]>0))return{data:{index:e,overflows:M},reset:{placement:t}}}let n=null==(T=M.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0])?void 0:T.placement;if(!n)switch(p){case"bestFit":{var j;const e=null==(j=M.filter(e=>{if(k){const t=ie(e.placement);return t===b||"y"===t}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0])?void 0:j[0];e&&(n=e);break}case"initialPlacement":n=l}if(r!==n)return{reset:{placement:n}}}return{}}}},it=function(e){return void 0===e&&(e={}),{name:"size",options:e,async fn(t){var n,o;const{placement:r,rects:i,platform:s,elements:l}=t,{apply:a=()=>{},...c}=Q(e,t),d=await Ie(t,c),u=ee(r),h=te(r),p="y"===ie(r),{width:f,height:m}=i.floating;let g,y;"top"===u||"bottom"===u?(g=u,y=h===(await(null==s.isRTL?void 0:s.isRTL(l.floating))?"start":"end")?"left":"right"):(y=u,g="end"===h?"top":"bottom");const b=m-d.top-d.bottom,v=f-d.left-d.right,x=W(m-d[g],b),w=W(f-d[y],v),k=!t.middlewareData.shift;let C=x,E=w;if(null!=(n=t.middlewareData.shift)&&n.enabled.x&&(E=v),null!=(o=t.middlewareData.shift)&&o.enabled.y&&(C=b),k&&!h){const e=q(d.left,0),t=q(d.right,0),n=q(d.top,0),o=q(d.bottom,0);p?E=f-2*(0!==e||0!==t?e+t:q(d.left,d.right)):C=m-2*(0!==n||0!==o?n+o:q(d.top,d.bottom))}await a({...t,availableWidth:E,availableHeight:C});const S=await s.getDimensions(l.floating);return f!==S.width||m!==S.height?{reset:{rects:!0}}:{}}}},st=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:o,placement:r,rects:i,platform:s,elements:l,middlewareData:a}=t,{element:c,padding:d=0}=Q(e,t)||{};if(null==c)return{};const u=fe(d),h={x:n,y:o},p=se(r),f=oe(p),m=await s.getDimensions(c),g="y"===p,y=g?"top":"left",b=g?"bottom":"right",v=g?"clientHeight":"clientWidth",x=i.reference[f]+i.reference[p]-h[p]-i.floating[f],w=h[p]-i.reference[p],k=await(null==s.getOffsetParent?void 0:s.getOffsetParent(c));let C=k?k[v]:0;C&&await(null==s.isElement?void 0:s.isElement(k))||(C=l.floating[v]||i.floating[f]);const E=x/2-w/2,S=C/2-m[f]/2-1,M=W(u[y],S),R=W(u[b],S),T=M,j=C-m[f]-R,N=C/2-m[f]/2+E,A=Y(T,N,j),O=!a.arrow&&null!=te(r)&&N!==A&&i.reference[f]/2-(N<T?M:R)-m[f]/2<0,_=O?N<T?N-T:N-j:0;return{[p]:h[p]+_,data:{[p]:A,centerOffset:N-A-_,...O&&{alignmentOffset:_}},reset:O}}}),lt=function(e){return void 0===e&&(e={}),{name:"inline",options:e,async fn(t){const{placement:n,elements:o,rects:r,platform:i,strategy:s}=t,{padding:l=2,x:a,y:c}=Q(e,t),d=Array.from(await(null==i.getClientRects?void 0:i.getClientRects(o.reference))||[]),u=function(e){const t=e.slice().sort((e,t)=>e.y-t.y),n=[];let o=null;for(let r=0;r<t.length;r++){const e=t[r];!o||e.y-o.y>o.height/2?n.push([e]):n[n.length-1].push(e),o=e}return n.map(e=>me(Le(e)))}(d),h=me(Le(d)),p=fe(l);const f=await i.getElementRects({reference:{getBoundingClientRect:function(){if(2===u.length&&u[0].left>u[1].right&&null!=a&&null!=c)return u.find(e=>a>e.left-p.left&&a<e.right+p.right&&c>e.top-p.top&&c<e.bottom+p.bottom)||h;if(u.length>=2){if("y"===ie(n)){const e=u[0],t=u[u.length-1],o="top"===ee(n),r=e.top,i=t.bottom,s=o?e.left:t.left,l=o?e.right:t.right;return{top:r,bottom:i,left:s,right:l,width:l-s,height:i-r,x:s,y:r}}const e="left"===ee(n),t=q(...u.map(e=>e.right)),o=W(...u.map(e=>e.left)),r=u.filter(n=>e?n.left===o:n.right===t),i=r[0].top,s=r[r.length-1].bottom;return{top:i,bottom:s,left:o,right:t,width:t-o,height:s-i,x:o,y:i}}return h}},floating:o.floating,strategy:s});return r.reference.x!==f.reference.x||r.reference.y!==f.reference.y||r.reference.width!==f.reference.width||r.reference.height!==f.reference.height?{reset:{rects:f}}:{}}}},at=function(e){return void 0===e&&(e={}),{options:e,fn(t){const{x:n,y:o,placement:r,rects:i,middlewareData:s}=t,{offset:l=0,mainAxis:a=!0,crossAxis:c=!0}=Q(e,t),d={x:n,y:o},u=ie(r),h=ne(u);let p=d[h],f=d[u];const m=Q(l,t),g="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(a){const e="y"===h?"height":"width",t=i.reference[h]-i.floating[e]+g.mainAxis,n=i.reference[h]+i.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(c){var y,b;const e="y"===h?"width":"height",t=De.has(ee(r)),n=i.reference[u]-i.floating[e]+(t&&(null==(y=s.offset)?void 0:y[u])||0)+(t?0:g.crossAxis),o=i.reference[u]+i.reference[e]+(t?0:(null==(b=s.offset)?void 0:b[u])||0)-(t?g.crossAxis:0);f<n?f=n:f>o&&(f=o)}return{[h]:p,[u]:f}}}},ct=(e,t,n)=>{const o=new Map,r={platform:Qe,...n},i={...r.platform,_c:o};return(async(e,t,n)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:s}=n,l=i.filter(Boolean),a=await(null==s.isRTL?void 0:s.isRTL(t));let c=await s.getElementRects({reference:e,floating:t,strategy:r}),{x:d,y:u}=Pe(c,o,a),h=o,p={},f=0;for(let m=0;m<l.length;m++){const{name:n,fn:i}=l[m],{x:g,y:y,data:b,reset:v}=await i({x:d,y:u,initialPlacement:o,placement:h,strategy:r,middlewareData:p,rects:c,platform:s,elements:{reference:e,floating:t}});d=null!=g?g:d,u=null!=y?y:u,p={...p,[n]:{...p[n],...b}},v&&f<=50&&(f++,"object"==typeof v&&(v.placement&&(h=v.placement),v.rects&&(c=!0===v.rects?await s.getElementRects({reference:e,floating:t,strategy:r}):v.rects),({x:d,y:u}=Pe(c,h,a))),m=-1)}return{x:d,y:u,placement:h,strategy:r,middlewareData:p}})(e,t,{...r,platform:i})};var dt="undefined"!=typeof document?n.useLayoutEffect:function(){};function ut(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if("function"==typeof e&&e.toString()===t.toString())return!0;let n,o,r;if(e&&t&&"object"==typeof e){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(o=n;0!==o--;)if(!ut(e[o],t[o]))return!1;return!0}if(r=Object.keys(e),n=r.length,n!==Object.keys(t).length)return!1;for(o=n;0!==o--;)if(!{}.hasOwnProperty.call(t,r[o]))return!1;for(o=n;0!==o--;){const n=r[o];if(("_owner"!==n||!e.$$typeof)&&!ut(e[n],t[n]))return!1}return!0}return e!=e&&t!=t}function ht(e){if("undefined"==typeof window)return 1;return(e.ownerDocument.defaultView||window).devicePixelRatio||1}function pt(e,t){const n=ht(e);return Math.round(t*n)/n}function ft(e){const t=s.useRef(e);return dt(()=>{t.current=e}),t}const mt=e=>({name:"arrow",options:e,fn(t){const{element:n,padding:o}="function"==typeof e?e(t):e;return n&&(r=n,{}.hasOwnProperty.call(r,"current"))?null!=n.current?st({element:n.current,padding:o}).fn(t):{}:n?st({element:n,padding:o}).fn(t):{};var r}}),gt=(e,t)=>({...nt(e),options:[e,t]}),yt=(e,t)=>({...ot(e),options:[e,t]}),bt=(e,t)=>({...at(e),options:[e,t]}),vt=(e,t)=>({...rt(e),options:[e,t]}),xt=(e,t)=>({...it(e),options:[e,t]}),wt=(e,t)=>({...lt(e),options:[e,t]}),kt=(e,t)=>({...mt(e),options:[e,t]}),Ct={...s},Et=Ct.useInsertionEffect||(e=>e());function St(e){const t=s.useRef(()=>{if("production"!==process.env.NODE_ENV)throw new Error("Cannot call an event handler while rendering.")});return Et(()=>{t.current=e}),s.useCallback(function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];return null==t.current?void 0:t.current(...n)},[])}var Mt="undefined"!=typeof document?n.useLayoutEffect:n.useEffect;function Rt(){return Rt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Rt.apply(this,arguments)}let Tt=!1,jt=0;const Nt=()=>"floating-ui-"+Math.random().toString(36).slice(2,6)+jt++;const At=Ct.useId||function(){const[e,t]=s.useState(()=>Tt?Nt():void 0);return Mt(()=>{null==e&&t(Nt())},[]),s.useEffect(()=>{Tt=!0},[]),e};let Ot;"production"!==process.env.NODE_ENV&&(Ot=new Set);const _t=s.createContext(null),Pt=s.createContext(null),It=()=>{var e;return(null==(e=s.useContext(_t))?void 0:e.id)||null},Lt=()=>s.useContext(Pt);function Dt(e){return"data-floating-ui-"+e}function Bt(e){const t=n.useRef(e);return Mt(()=>{t.current=e}),t}const Ht=Dt("safe-polygon");function Vt(e,t,n){return n&&!$(n)?0:"number"==typeof e?e:null==e?void 0:e[t]}function $t(e,t){void 0===t&&(t={});const{open:n,onOpenChange:o,dataRef:r,events:i,elements:l}=e,{enabled:a=!0,delay:c=0,handleClose:d=null,mouseOnly:u=!1,restMs:p=0,move:f=!0}=t,m=Lt(),g=It(),y=Bt(d),b=Bt(c),v=Bt(n),x=s.useRef(),w=s.useRef(-1),k=s.useRef(),C=s.useRef(-1),E=s.useRef(!0),S=s.useRef(!1),M=s.useRef(()=>{}),R=s.useRef(!1),T=s.useCallback(()=>{var e;const t=null==(e=r.current.openEvent)?void 0:e.type;return(null==t?void 0:t.includes("mouse"))&&"mousedown"!==t},[r]);s.useEffect(()=>{if(a)return i.on("openchange",e),()=>{i.off("openchange",e)};function e(e){let{open:t}=e;t||(clearTimeout(w.current),clearTimeout(C.current),E.current=!0,R.current=!1)}},[a,i]),s.useEffect(()=>{if(!a)return;if(!y.current)return;if(!n)return;function e(e){T()&&o(!1,e,"hover")}const t=z(l.floating).documentElement;return t.addEventListener("mouseleave",e),()=>{t.removeEventListener("mouseleave",e)}},[l.floating,n,o,a,y,T]);const j=s.useCallback(function(e,t,n){void 0===t&&(t=!0),void 0===n&&(n="hover");const r=Vt(b.current,"close",x.current);r&&!k.current?(clearTimeout(w.current),w.current=window.setTimeout(()=>o(!1,e,n),r)):t&&(clearTimeout(w.current),o(!1,e,n))},[b,o]),N=St(()=>{M.current(),k.current=void 0}),A=St(()=>{if(S.current){const e=z(l.floating).body;e.style.pointerEvents="",e.removeAttribute(Ht),S.current=!1}}),O=St(()=>!!r.current.openEvent&&["click","mousedown"].includes(r.current.openEvent.type));s.useEffect(()=>{if(a&&h(l.domReference)){var e;const o=l.domReference;return n&&o.addEventListener("mouseleave",s),null==(e=l.floating)||e.addEventListener("mouseleave",s),f&&o.addEventListener("mousemove",t,{once:!0}),o.addEventListener("mouseenter",t),o.addEventListener("mouseleave",i),()=>{var e;n&&o.removeEventListener("mouseleave",s),null==(e=l.floating)||e.removeEventListener("mouseleave",s),f&&o.removeEventListener("mousemove",t),o.removeEventListener("mouseenter",t),o.removeEventListener("mouseleave",i)}}function t(e){if(clearTimeout(w.current),E.current=!1,u&&!$(x.current)||p>0&&!Vt(b.current,"open"))return;const t=Vt(b.current,"open",x.current);t?w.current=window.setTimeout(()=>{v.current||o(!0,e,"hover")},t):n||o(!0,e,"hover")}function i(e){if(O())return;M.current();const t=z(l.floating);if(clearTimeout(C.current),R.current=!1,y.current&&r.current.floatingContext){n||clearTimeout(w.current),k.current=y.current({...r.current.floatingContext,tree:m,x:e.clientX,y:e.clientY,onClose(){A(),N(),O()||j(e,!0,"safe-polygon")}});const o=k.current;return t.addEventListener("mousemove",o),void(M.current=()=>{t.removeEventListener("mousemove",o)})}("touch"!==x.current||!I(l.floating,e.relatedTarget))&&j(e)}function s(e){O()||r.current.floatingContext&&(null==y.current||y.current({...r.current.floatingContext,tree:m,x:e.clientX,y:e.clientY,onClose(){A(),N(),O()||j(e)}})(e))}},[l,a,e,u,p,f,j,N,A,o,n,v,m,b,y,r,O]),Mt(()=>{var e;if(a&&n&&null!=(e=y.current)&&e.__options.blockPointerEvents&&T()){S.current=!0;const e=l.floating;if(h(l.domReference)&&e){var t;const n=z(l.floating).body;n.setAttribute(Ht,"");const o=l.domReference,r=null==m||null==(t=m.nodesRef.current.find(e=>e.id===g))||null==(t=t.context)?void 0:t.elements.floating;return r&&(r.style.pointerEvents=""),n.style.pointerEvents="none",o.style.pointerEvents="auto",e.style.pointerEvents="auto",()=>{n.style.pointerEvents="",o.style.pointerEvents="",e.style.pointerEvents=""}}}},[a,n,g,l,m,y,T]),Mt(()=>{n||(x.current=void 0,R.current=!1,N(),A())},[n,N,A]),s.useEffect(()=>()=>{N(),clearTimeout(w.current),clearTimeout(C.current),A()},[a,l.domReference,N,A]);const _=s.useMemo(()=>{function e(e){x.current=e.pointerType}return{onPointerDown:e,onPointerEnter:e,onMouseMove(e){const{nativeEvent:t}=e;function r(){E.current||v.current||o(!0,t,"hover")}u&&!$(x.current)||n||0===p||R.current&&e.movementX**2+e.movementY**2<2||(clearTimeout(C.current),"touch"===x.current?r():(R.current=!0,C.current=window.setTimeout(r,p)))}}},[u,o,n,v,p]),P=s.useMemo(()=>({onMouseEnter(){clearTimeout(w.current)},onMouseLeave(e){O()||j(e.nativeEvent,!1)}}),[j,O]);return s.useMemo(()=>a?{reference:_,floating:P}:{},[a,_,P])}const zt=()=>{},Ft=s.createContext({delay:0,initialDelay:0,timeoutMs:0,currentId:null,setCurrentId:zt,setState:zt,isInstantPhase:!1});function Ut(e){const{children:t,delay:n,timeoutMs:o=0}=e,[r,i]=s.useReducer((e,t)=>({...e,...t}),{delay:n,timeoutMs:o,initialDelay:n,currentId:null,isInstantPhase:!1}),l=s.useRef(null),a=s.useCallback(e=>{i({currentId:e})},[]);return Mt(()=>{r.currentId?null===l.current?l.current=r.currentId:r.isInstantPhase||i({isInstantPhase:!0}):(r.isInstantPhase&&i({isInstantPhase:!1}),l.current=null)},[r.currentId,r.isInstantPhase]),s.createElement(Ft.Provider,{value:s.useMemo(()=>({...r,setState:i,setCurrentId:a}),[r,a])},t)}function Wt(e,t){void 0===t&&(t={});const{open:n,onOpenChange:o,floatingId:r}=e,{id:i,enabled:l=!0}=t,a=null!=i?i:r,c=s.useContext(Ft),{currentId:d,setCurrentId:u,initialDelay:h,setState:p,timeoutMs:f}=c;return Mt(()=>{l&&d&&(p({delay:{open:1,close:Vt(h,"close")}}),d!==a&&o(!1))},[l,a,o,p,d,h]),Mt(()=>{function e(){o(!1),p({delay:h,currentId:null})}if(l&&d&&!n&&d===a){if(f){const t=window.setTimeout(e,f);return()=>{clearTimeout(t)}}e()}},[l,n,p,d,a,o,h,f]),Mt(()=>{l&&u!==zt&&n&&u(a)},[l,n,u,a]),c}function qt(e,t){let n=e.filter(e=>{var n;return e.parentId===t&&(null==(n=e.context)?void 0:n.open)}),o=n;for(;o.length;)o=e.filter(e=>{var t;return null==(t=o)?void 0:t.some(t=>{var n;return e.parentId===t.id&&(null==(n=e.context)?void 0:n.open)})}),n=n.concat(o);return n}const Gt=()=>({getShadowRoot:!0,displayCheck:"function"==typeof ResizeObserver&&ResizeObserver.toString().includes("[native code]")?"full":"none"});function Kt(e,t){const n=_e(e,Gt());"prev"===t&&n.reverse();const o=n.indexOf(P(z(e)));return n.slice(o+1)[0]}function Zt(e,t){const n=t||e.currentTarget,o=e.relatedTarget;return!o||!I(n,o)}function Jt(e){_e(e,Gt()).forEach(e=>{e.dataset.tabindex=e.getAttribute("tabindex")||"",e.setAttribute("tabindex","-1")})}function Xt(e){e.querySelectorAll("[data-tabindex]").forEach(e=>{const t=e.dataset.tabindex;delete e.dataset.tabindex,t?e.setAttribute("tabindex",t):e.removeAttribute("tabindex")})}const Yt={border:0,clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"fixed",whiteSpace:"nowrap",width:"1px",top:0,left:0};function Qt(e){"Tab"===e.key&&(e.target,clearTimeout(undefined))}const en=s.forwardRef(function(e,t){const[n,o]=s.useState();Mt(()=>(H()&&o("button"),document.addEventListener("keydown",Qt),()=>{document.removeEventListener("keydown",Qt)}),[]);const r={ref:t,tabIndex:0,role:n,"aria-hidden":!n||void 0,[Dt("focus-guard")]:"",style:Yt};return s.createElement("span",Rt({},e,r))}),tn=s.createContext(null),nn=Dt("portal");function on(e){const{children:t,id:n,root:o,preserveTabOrder:r=!0}=e,l=function(e){void 0===e&&(e={});const{id:t,root:n}=e,o=At(),r=rn(),[i,l]=s.useState(null),a=s.useRef(null);return Mt(()=>()=>{null==i||i.remove(),queueMicrotask(()=>{a.current=null})},[i]),Mt(()=>{if(!o)return;if(a.current)return;const e=t?document.getElementById(t):null;if(!e)return;const n=document.createElement("div");n.id=o,n.setAttribute(nn,""),e.appendChild(n),a.current=n,l(n)},[t,o]),Mt(()=>{if(null===n)return;if(!o)return;if(a.current)return;let e=n||(null==r?void 0:r.portalNode);e&&!h(e)&&(e=e.current),e=e||document.body;let i=null;t&&(i=document.createElement("div"),i.id=t,e.appendChild(i));const s=document.createElement("div");s.id=o,s.setAttribute(nn,""),e=i||e,e.appendChild(s),a.current=s,l(s)},[t,n,o,r]),i}({id:n,root:o}),[a,c]=s.useState(null),d=s.useRef(null),u=s.useRef(null),p=s.useRef(null),f=s.useRef(null),m=null==a?void 0:a.modal,g=null==a?void 0:a.open,y=!!a&&!a.modal&&a.open&&r&&!(!o&&!l);return s.useEffect(()=>{if(l&&r&&!m)return l.addEventListener("focusin",e,!0),l.addEventListener("focusout",e,!0),()=>{l.removeEventListener("focusin",e,!0),l.removeEventListener("focusout",e,!0)};function e(e){if(l&&Zt(e)){("focusin"===e.type?Xt:Jt)(l)}}},[l,r,m]),s.useEffect(()=>{l&&(g||Xt(l))},[g,l]),s.createElement(tn.Provider,{value:s.useMemo(()=>({preserveTabOrder:r,beforeOutsideRef:d,afterOutsideRef:u,beforeInsideRef:p,afterInsideRef:f,portalNode:l,setFocusManagerState:c}),[r,l])},y&&l&&s.createElement(en,{"data-type":"outside",ref:d,onFocus:e=>{if(Zt(e,l)){var t;null==(t=p.current)||t.focus()}else{const e=Kt(document.body,"prev")||(null==a?void 0:a.refs.domReference.current);null==e||e.focus()}}}),y&&l&&s.createElement("span",{"aria-owns":l.id,style:Yt}),l&&i.createPortal(t,l),y&&l&&s.createElement(en,{"data-type":"outside",ref:u,onFocus:e=>{if(Zt(e,l)){var t;null==(t=f.current)||t.focus()}else{const t=Kt(document.body,"next")||(null==a?void 0:a.refs.domReference.current);null==t||t.focus(),(null==a?void 0:a.closeOnFocusOut)&&(null==a||a.onOpenChange(!1,e.nativeEvent,"focus-out"))}}}))}const rn=()=>s.useContext(tn),sn="data-floating-ui-focusable",ln={pointerdown:"onPointerDown",mousedown:"onMouseDown",click:"onClick"},an={pointerdown:"onPointerDownCapture",mousedown:"onMouseDownCapture",click:"onClickCapture"},cn=e=>{var t,n;return{escapeKey:"boolean"==typeof e?e:null!=(t=null==e?void 0:e.escapeKey)&&t,outsidePress:"boolean"==typeof e?e:null==(n=null==e?void 0:e.outsidePress)||n}};function dn(e,t){void 0===t&&(t={});const{open:n,onOpenChange:o,elements:r,dataRef:i}=e,{enabled:l=!0,escapeKey:a=!0,outsidePress:c=!0,outsidePressEvent:d="pointerdown",referencePress:u=!1,referencePressEvent:f="pointerdown",ancestorScroll:m=!1,bubbles:g,capture:y}=t,b=Lt(),v=St("function"==typeof c?c:()=>!1),x="function"==typeof c?v:c,w=s.useRef(!1),k=s.useRef(!1),{escapeKey:C,outsidePress:E}=cn(g),{escapeKey:M,outsidePress:j}=cn(y),A=s.useRef(!1),_=St(e=>{var t;if(!n||!l||!a||"Escape"!==e.key)return;if(A.current)return;const r=null==(t=i.current.floatingContext)?void 0:t.nodeId,s=b?qt(b.nodesRef.current,r):[];if(!C&&(e.stopPropagation(),s.length>0)){let e=!0;if(s.forEach(t=>{var n;null==(n=t.context)||!n.open||t.context.dataRef.current.__escapeKeyBubbles||(e=!1)}),!e)return}o(!1,function(e){return"nativeEvent"in e}(e)?e.nativeEvent:e,"escape-key")}),P=St(e=>{var t;const n=()=>{var t;_(e),null==(t=U(e))||t.removeEventListener("keydown",n)};null==(t=U(e))||t.addEventListener("keydown",n)}),L=St(e=>{var t;const n=w.current;w.current=!1;const s=k.current;if(k.current=!1,"click"===d&&s)return;if(n)return;if("function"==typeof x&&!x(e))return;const l=U(e),a="["+Dt("inert")+"]",c=z(r.floating).querySelectorAll(a);let u=h(l)?l:null;for(;u&&!R(u);){const e=N(u);if(R(e)||!h(e))break;u=e}if(c.length&&h(l)&&!l.matches("html,body")&&!I(l,r.floating)&&Array.from(c).every(e=>!I(u,e)))return;if(p(l)&&H){const t=l.clientWidth>0&&l.scrollWidth>l.clientWidth,n=l.clientHeight>0&&l.scrollHeight>l.clientHeight;let o=n&&e.offsetX>l.clientWidth;if(n){"rtl"===T(l).direction&&(o=e.offsetX<=l.offsetWidth-l.clientWidth)}if(o||t&&e.offsetY>l.clientHeight)return}const f=null==(t=i.current.floatingContext)?void 0:t.nodeId,m=b&&qt(b.nodesRef.current,f).some(t=>{var n;return F(e,null==(n=t.context)?void 0:n.elements.floating)});if(F(e,r.floating)||F(e,r.domReference)||m)return;const g=b?qt(b.nodesRef.current,f):[];if(g.length>0){let e=!0;if(g.forEach(t=>{var n;null==(n=t.context)||!n.open||t.context.dataRef.current.__outsidePressBubbles||(e=!1)}),!e)return}o(!1,e,"outside-press")}),D=St(e=>{var t;const n=()=>{var t;L(e),null==(t=U(e))||t.removeEventListener(d,n)};null==(t=U(e))||t.addEventListener(d,n)});s.useEffect(()=>{if(!n||!l)return;i.current.__escapeKeyBubbles=C,i.current.__outsidePressBubbles=E;let e=-1;function t(e){o(!1,e,"ancestor-scroll")}function s(){window.clearTimeout(e),A.current=!0}function c(){e=window.setTimeout(()=>{A.current=!1},S()?5:0)}const u=z(r.floating);a&&(u.addEventListener("keydown",M?P:_,M),u.addEventListener("compositionstart",s),u.addEventListener("compositionend",c)),x&&u.addEventListener(d,j?D:L,j);let p=[];return m&&(h(r.domReference)&&(p=O(r.domReference)),h(r.floating)&&(p=p.concat(O(r.floating))),!h(r.reference)&&r.reference&&r.reference.contextElement&&(p=p.concat(O(r.reference.contextElement)))),p=p.filter(e=>{var t;return e!==(null==(t=u.defaultView)?void 0:t.visualViewport)}),p.forEach(e=>{e.addEventListener("scroll",t,{passive:!0})}),()=>{a&&(u.removeEventListener("keydown",M?P:_,M),u.removeEventListener("compositionstart",s),u.removeEventListener("compositionend",c)),x&&u.removeEventListener(d,j?D:L,j),p.forEach(e=>{e.removeEventListener("scroll",t)}),window.clearTimeout(e)}},[i,r,a,x,d,n,o,m,l,C,E,_,M,P,L,j,D]),s.useEffect(()=>{w.current=!1},[x,d]);const B=s.useMemo(()=>({onKeyDown:_,[ln[f]]:e=>{u&&o(!1,e.nativeEvent,"reference-press")}}),[_,o,u,f]),H=s.useMemo(()=>({onKeyDown:_,onMouseDown(){k.current=!0},onMouseUp(){k.current=!0},[an[d]]:()=>{w.current=!0}}),[_,d]);return s.useMemo(()=>l?{reference:B,floating:H}:{},[l,B,H])}function un(e){const{open:t=!1,onOpenChange:n,elements:o}=e,r=At(),i=s.useRef({}),[l]=s.useState(()=>function(){const e=new Map;return{emit(t,n){var o;null==(o=e.get(t))||o.forEach(e=>e(n))},on(t,n){e.set(t,[...e.get(t)||[],n])},off(t,n){var o;e.set(t,(null==(o=e.get(t))?void 0:o.filter(e=>e!==n))||[])}}}()),a=null!=It();if("production"!==process.env.NODE_ENV){const e=o.reference;e&&!h(e)&&function(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];const r="Floating UI: "+n.join(" ");var i;null!=(e=Ot)&&e.has(r)||null==(i=Ot)||i.add(r)}("Cannot pass a virtual element to the `elements.reference` option,","as it must be a real DOM element. Use `refs.setPositionReference()`","instead.")}const[c,d]=s.useState(o.reference),u=St((e,t,o)=>{i.current.openEvent=e?t:void 0,l.emit("openchange",{open:e,event:t,reason:o,nested:a}),null==n||n(e,t,o)}),p=s.useMemo(()=>({setPositionReference:d}),[]),f=s.useMemo(()=>({reference:c||o.reference||null,floating:o.floating||null,domReference:o.reference}),[c,o.reference,o.floating]);return s.useMemo(()=>({dataRef:i,open:t,onOpenChange:u,elements:f,events:l,floatingId:r,refs:p}),[t,u,f,l,r,p])}function hn(e){void 0===e&&(e={});const{nodeId:t}=e,n=un({...e,elements:{reference:null,floating:null,...e.elements}}),o=e.rootContext||n,r=o.elements,[l,a]=s.useState(null),[c,d]=s.useState(null),u=(null==r?void 0:r.domReference)||l,p=s.useRef(null),f=Lt();Mt(()=>{u&&(p.current=u)},[u]);const m=function(e){void 0===e&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:o=[],platform:r,elements:{reference:l,floating:a}={},transform:c=!0,whileElementsMounted:d,open:u}=e,[h,p]=s.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,m]=s.useState(o);ut(f,o)||m(o);const[g,y]=s.useState(null),[b,v]=s.useState(null),x=s.useCallback(e=>{e!==E.current&&(E.current=e,y(e))},[]),w=s.useCallback(e=>{e!==S.current&&(S.current=e,v(e))},[]),k=l||g,C=a||b,E=s.useRef(null),S=s.useRef(null),M=s.useRef(h),R=null!=d,T=ft(d),j=ft(r),N=ft(u),A=s.useCallback(()=>{if(!E.current||!S.current)return;const e={placement:t,strategy:n,middleware:f};j.current&&(e.platform=j.current),ct(E.current,S.current,e).then(e=>{const t={...e,isPositioned:!1!==N.current};O.current&&!ut(M.current,t)&&(M.current=t,i.flushSync(()=>{p(t)}))})},[f,t,n,j,N]);dt(()=>{!1===u&&M.current.isPositioned&&(M.current.isPositioned=!1,p(e=>({...e,isPositioned:!1})))},[u]);const O=s.useRef(!1);dt(()=>(O.current=!0,()=>{O.current=!1}),[]),dt(()=>{if(k&&(E.current=k),C&&(S.current=C),k&&C){if(T.current)return T.current(k,C,A);A()}},[k,C,A,T,R]);const _=s.useMemo(()=>({reference:E,floating:S,setReference:x,setFloating:w}),[x,w]),P=s.useMemo(()=>({reference:k,floating:C}),[k,C]),I=s.useMemo(()=>{const e={position:n,left:0,top:0};if(!P.floating)return e;const t=pt(P.floating,h.x),o=pt(P.floating,h.y);return c?{...e,transform:"translate("+t+"px, "+o+"px)",...ht(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:t,top:o}},[n,c,P.floating,h.x,h.y]);return s.useMemo(()=>({...h,update:A,refs:_,elements:P,floatingStyles:I}),[h,A,_,P,I])}({...e,elements:{...r,...c&&{reference:c}}}),g=s.useCallback(e=>{const t=h(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),contextElement:e}:e;d(t),m.refs.setReference(t)},[m.refs]),y=s.useCallback(e=>{(h(e)||null===e)&&(p.current=e,a(e)),(h(m.refs.reference.current)||null===m.refs.reference.current||null!==e&&!h(e))&&m.refs.setReference(e)},[m.refs]),b=s.useMemo(()=>({...m.refs,setReference:y,setPositionReference:g,domReference:p}),[m.refs,y,g]),v=s.useMemo(()=>({...m.elements,domReference:u}),[m.elements,u]),x=s.useMemo(()=>({...m,...o,refs:b,elements:v,nodeId:t}),[m,b,v,t,o]);return Mt(()=>{o.dataRef.current.floatingContext=x;const e=null==f?void 0:f.nodesRef.current.find(e=>e.id===t);e&&(e.context=x)}),s.useMemo(()=>({...m,context:x,refs:b,elements:v}),[m,b,v,x])}function pn(e,t){void 0===t&&(t={});const{open:n,onOpenChange:o,events:r,dataRef:i,elements:l}=e,{enabled:a=!0,visibleOnly:d=!0}=t,u=s.useRef(!1),f=s.useRef(),m=s.useRef(!0);s.useEffect(()=>{if(!a)return;const e=c(l.domReference);function t(){!n&&p(l.domReference)&&l.domReference===P(z(l.domReference))&&(u.current=!0)}function o(){m.current=!0}return e.addEventListener("blur",t),e.addEventListener("keydown",o,!0),()=>{e.removeEventListener("blur",t),e.removeEventListener("keydown",o,!0)}},[l.domReference,n,a]),s.useEffect(()=>{if(a)return r.on("openchange",e),()=>{r.off("openchange",e)};function e(e){let{reason:t}=e;"reference-press"!==t&&"escape-key"!==t||(u.current=!0)}},[r,a]),s.useEffect(()=>()=>{clearTimeout(f.current)},[]);const g=s.useMemo(()=>({onPointerDown(e){B(e.nativeEvent)||(m.current=!1)},onMouseLeave(){u.current=!1},onFocus(e){if(u.current)return;const t=U(e.nativeEvent);if(d&&h(t))try{if(H()&&L().toLowerCase().startsWith("mac")&&!navigator.maxTouchPoints)throw Error();if(!t.matches(":focus-visible"))return}catch(r){if(!m.current&&(!p(n=t)||!n.matches("input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])")))return}var n;o(!0,e.nativeEvent,"focus")},onBlur(e){u.current=!1;const t=e.relatedTarget,n=e.nativeEvent,r=h(t)&&t.hasAttribute(Dt("focus-guard"))&&"outside"===t.getAttribute("data-type");f.current=window.setTimeout(()=>{var e;const s=P(l.domReference?l.domReference.ownerDocument:document);(t||s!==l.domReference)&&(I(null==(e=i.current.floatingContext)?void 0:e.refs.floating.current,s)||I(l.domReference,s)||r||o(!1,n,"focus"))})}}),[i,l.domReference,o,d]);return s.useMemo(()=>a?{reference:g}:{},[a,g])}const fn="active",mn="selected";function gn(e,t,n){const o=new Map,r="item"===n;let i=e;if(r&&e){const{[fn]:t,[mn]:n,...o}=e;i=o}return{..."floating"===n&&{tabIndex:-1,[sn]:""},...i,...t.map(t=>{const o=t?t[n]:null;return"function"==typeof o?e?o(e):null:o}).concat(e).reduce((e,t)=>t?(Object.entries(t).forEach(t=>{let[n,i]=t;var s;r&&[fn,mn].includes(n)||(0===n.indexOf("on")?(o.has(n)||o.set(n,[]),"function"==typeof i&&(null==(s=o.get(n))||s.push(i),e[n]=function(){for(var e,t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];return null==(e=o.get(n))?void 0:e.map(e=>e(...r)).find(e=>void 0!==e)})):e[n]=i)}),e):e,{})}}function yn(e){void 0===e&&(e=[]);const t=e.map(e=>null==e?void 0:e.reference),n=e.map(e=>null==e?void 0:e.floating),o=e.map(e=>null==e?void 0:e.item),r=s.useCallback(t=>gn(t,e,"reference"),t),i=s.useCallback(t=>gn(t,e,"floating"),n),l=s.useCallback(t=>gn(t,e,"item"),o);return s.useMemo(()=>({getReferenceProps:r,getFloatingProps:i,getItemProps:l}),[r,i,l])}const bn=new Map([["select","listbox"],["combobox","listbox"],["label",!1]]);function vn(e,t){var n;void 0===t&&(t={});const{open:o,floatingId:r}=e,{enabled:i=!0,role:l="dialog"}=t,a=null!=(n=bn.get(l))?n:l,c=At(),d=null!=It(),u=s.useMemo(()=>"tooltip"===a||"label"===l?{["aria-"+("label"===l?"labelledby":"describedby")]:o?r:void 0}:{"aria-expanded":o?"true":"false","aria-haspopup":"alertdialog"===a?"dialog":a,"aria-controls":o?r:void 0,..."listbox"===a&&{role:"combobox"},..."menu"===a&&{id:c},..."menu"===a&&d&&{role:"menuitem"},..."select"===l&&{"aria-autocomplete":"none"},..."combobox"===l&&{"aria-autocomplete":"list"}},[a,r,d,o,c,l]),h=s.useMemo(()=>{const e={id:r,...a&&{role:a}};return"tooltip"===a||"label"===l?e:{...e,..."menu"===a&&{"aria-labelledby":c}}},[a,r,c,l]),p=s.useCallback(e=>{let{active:t,selected:n}=e;const o={role:"option",...t&&{id:r+"-option"}};switch(l){case"select":return{...o,"aria-selected":t&&n};case"combobox":return{...o,...t&&{"aria-selected":!0}}}return{}},[r,l]);return s.useMemo(()=>i?{reference:u,floating:h,item:p}:{},[i,u,h,p])}const xn=e=>e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,(e,t)=>(t?"-":"")+e.toLowerCase());function wn(e,t){return"function"==typeof e?e(t):e}function kn(e,t){void 0===t&&(t={});const{open:n,elements:{floating:o}}=e,{duration:r=250}=t,i=("number"==typeof r?r:r.close)||0,[l,a]=s.useState("unmounted"),c=function(e,t){const[n,o]=s.useState(e);return e&&!n&&o(!0),s.useEffect(()=>{if(!e&&n){const e=setTimeout(()=>o(!1),t);return()=>clearTimeout(e)}},[e,n,t]),n}(n,i);return c||"close"!==l||a("unmounted"),Mt(()=>{if(o){if(n){a("initial");const e=requestAnimationFrame(()=>{a("open")});return()=>{cancelAnimationFrame(e)}}a("close")}},[n,o]),{isMounted:c,status:l}}function Cn(e,t){void 0===t&&(t={});const{initial:n={opacity:0},open:o,close:r,common:i,duration:l=250}=t,a=e.placement,c=a.split("-")[0],d=s.useMemo(()=>({side:c,placement:a}),[c,a]),u="number"==typeof l,h=(u?l:l.open)||0,p=(u?l:l.close)||0,[f,m]=s.useState(()=>({...wn(i,d),...wn(n,d)})),{isMounted:g,status:y}=kn(e,{duration:l}),b=Bt(n),v=Bt(o),x=Bt(r),w=Bt(i);return Mt(()=>{const e=wn(b.current,d),t=wn(x.current,d),n=wn(w.current,d),o=wn(v.current,d)||Object.keys(e).reduce((e,t)=>(e[t]="",e),{});if("initial"===y&&m(t=>({transitionProperty:t.transitionProperty,...n,...e})),"open"===y&&m({transitionProperty:Object.keys(o).map(xn).join(","),transitionDuration:h+"ms",...n,...o}),"close"===y){const o=t||e;m({transitionProperty:Object.keys(o).map(xn).join(","),transitionDuration:p+"ms",...n,...o})}},[p,x,b,v,w,h,y,d]),{isMounted:g,styles:f}}function En(e){this.content=e}function Sn(e,t,n){for(let o=0;;o++){if(o==e.childCount||o==t.childCount)return e.childCount==t.childCount?null:n;let r=e.child(o),i=t.child(o);if(r!=i){if(!r.sameMarkup(i))return n;if(r.isText&&r.text!=i.text){for(let e=0;r.text[e]==i.text[e];e++)n++;return n}if(r.content.size||i.content.size){let e=Sn(r.content,i.content,n+1);if(null!=e)return e}n+=r.nodeSize}else n+=r.nodeSize}}function Mn(e,t,n,o){for(let r=e.childCount,i=t.childCount;;){if(0==r||0==i)return r==i?null:{a:n,b:o};let s=e.child(--r),l=t.child(--i),a=s.nodeSize;if(s!=l){if(!s.sameMarkup(l))return{a:n,b:o};if(s.isText&&s.text!=l.text){let e=0,t=Math.min(s.text.length,l.text.length);for(;e<t&&s.text[s.text.length-e-1]==l.text[l.text.length-e-1];)e++,n--,o--;return{a:n,b:o}}if(s.content.size||l.content.size){let e=Mn(s.content,l.content,n-1,o-1);if(e)return e}n-=a,o-=a}else n-=a,o-=a}}En.prototype={constructor:En,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-1==t?void 0:this.content[t+1]},update:function(e,t,n){var o=n&&n!=e?this.remove(n):this,r=o.find(e),i=o.content.slice();return-1==r?i.push(n||e,t):(i[r+1]=t,n&&(i[r]=n)),new En(i)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new En(n)},addToStart:function(e,t){return new En([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new En(n)},addBefore:function(e,t,n){var o=this.remove(t),r=o.content.slice(),i=o.find(e);return r.splice(-1==i?r.length:i,0,t,n),new En(r)},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=En.from(e)).size?new En(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=En.from(e)).size?new En(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=En.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},En.from=function(e){if(e instanceof En)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new En(t)};class Rn{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,o=0,r){for(let i=0,s=0;s<t;i++){let l=this.content[i],a=s+l.nodeSize;if(a>e&&!1!==n(l,o+s,r||null,i)&&l.content.size){let r=s+1;l.nodesBetween(Math.max(0,e-r),Math.min(l.content.size,t-r),n,o+r)}s=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,o){let r="",i=!0;return this.nodesBetween(e,t,(s,l)=>{let a=s.isText?s.text.slice(Math.max(e,l)-l,t-l):s.isLeaf?o?"function"==typeof o?o(s):o:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&a||s.isTextblock)&&n&&(i?i=!1:r+=n),r+=a},0),r}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,o=this.content.slice(),r=0;for(t.isText&&t.sameMarkup(n)&&(o[o.length-1]=t.withText(t.text+n.text),r=1);r<e.content.length;r++)o.push(e.content[r]);return new Rn(o,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],o=0;if(t>e)for(let r=0,i=0;i<t;r++){let s=this.content[r],l=i+s.nodeSize;l>e&&((i<e||l>t)&&(s=s.isText?s.cut(Math.max(0,e-i),Math.min(s.text.length,t-i)):s.cut(Math.max(0,e-i-1),Math.min(s.content.size,t-i-1))),n.push(s),o+=s.nodeSize),i=l}return new Rn(n,o)}cutByIndex(e,t){return e==t?Rn.empty:0==e&&t==this.content.length?this:new Rn(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let o=this.content.slice(),r=this.size+t.nodeSize-n.nodeSize;return o[e]=t,new Rn(o,r)}addToStart(e){return new Rn([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new Rn(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let o=this.content[t];e(o,n,t),n+=o.nodeSize}}findDiffStart(e,t=0){return Sn(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return Mn(this,e,t,n)}findIndex(e){if(0==e)return jn(0,e);if(e==this.size)return jn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let o=n+this.child(t).nodeSize;if(o>=e)return o==e?jn(t+1,o):jn(t,n);n=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return Rn.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new Rn(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return Rn.empty;let t,n=0;for(let o=0;o<e.length;o++){let r=e[o];n+=r.nodeSize,o&&r.isText&&e[o-1].sameMarkup(r)?(t||(t=e.slice(0,o)),t[t.length-1]=r.withText(t[t.length-1].text+r.text)):t&&t.push(r)}return new Rn(t||e,n)}static from(e){if(!e)return Rn.empty;if(e instanceof Rn)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new Rn([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}Rn.empty=new Rn([],0);const Tn={index:0,offset:0};function jn(e,t){return Tn.index=e,Tn.offset=t,Tn}function Nn(e,t){if(e===t)return!0;if(!e||"object"!=typeof e||!t||"object"!=typeof t)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(!Nn(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!Nn(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}let An=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let o=0;o<e.length;o++){let r=e[o];if(this.eq(r))return e;if(this.type.excludes(r.type))t||(t=e.slice(0,o));else{if(r.type.excludes(this.type))return e;!n&&r.type.rank>this.type.rank&&(t||(t=e.slice(0,o)),t.push(this),n=!0),t&&t.push(r)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Nn(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);let o=n.create(t.attrs);return n.checkAttrs(o.attrs),o}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)&&0==t.length)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}};An.none=[];class On extends Error{}class _n{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=In(this.content,e+this.openStart,t);return n&&new _n(n,this.openStart,this.openEnd)}removeBetween(e,t){return new _n(Pn(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return _n.empty;let n=t.openStart||0,o=t.openEnd||0;if("number"!=typeof n||"number"!=typeof o)throw new RangeError("Invalid input for Slice.fromJSON");return new _n(Rn.fromJSON(e,t.content),n,o)}static maxOpen(e,t=!0){let n=0,o=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let r=e.lastChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.lastChild)o++;return new _n(e,n,o)}}function Pn(e,t,n){let{index:o,offset:r}=e.findIndex(t),i=e.maybeChild(o),{index:s,offset:l}=e.findIndex(n);if(r==t||i.isText){if(l!=n&&!e.child(s).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(o!=s)throw new RangeError("Removing non-flat range");return e.replaceChild(o,i.copy(Pn(i.content,t-r-1,n-r-1)))}function In(e,t,n,o){let{index:r,offset:i}=e.findIndex(t),s=e.maybeChild(r);if(i==t||s.isText)return o&&!o.canReplace(r,r,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=In(s.content,t-i-1,n,s);return l&&e.replaceChild(r,s.copy(l))}function Ln(e,t,n){if(n.openStart>e.depth)throw new On("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new On("Inconsistent open depths");return Dn(e,t,n,0)}function Dn(e,t,n,o){let r=e.index(o),i=e.node(o);if(r==t.index(o)&&o<e.depth-n.openStart){let s=Dn(e,t,n,o+1);return i.copy(i.content.replaceChild(r,s))}if(n.content.size){if(n.openStart||n.openEnd||e.depth!=o||t.depth!=o){let{start:r,end:s}=function(e,t){let n=t.depth-e.openStart,o=t.node(n).copy(e.content);for(let r=n-1;r>=0;r--)o=t.node(r).copy(Rn.from(o));return{start:o.resolveNoCache(e.openStart+n),end:o.resolveNoCache(o.content.size-e.openEnd-n)}}(n,e);return zn(i,Fn(e,r,s,t,o))}{let o=e.parent,r=o.content;return zn(o,r.cut(0,e.parentOffset).append(n.content).append(r.cut(t.parentOffset)))}}return zn(i,Un(e,t,o))}function Bn(e,t){if(!t.type.compatibleContent(e.type))throw new On("Cannot join "+t.type.name+" onto "+e.type.name)}function Hn(e,t,n){let o=e.node(n);return Bn(o,t.node(n)),o}function Vn(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 $n(e,t,n,o){let r=(t||e).node(n),i=0,s=t?t.index(n):r.childCount;e&&(i=e.index(n),e.depth>n?i++:e.textOffset&&(Vn(e.nodeAfter,o),i++));for(let l=i;l<s;l++)Vn(r.child(l),o);t&&t.depth==n&&t.textOffset&&Vn(t.nodeBefore,o)}function zn(e,t){return e.type.checkContent(t),e.copy(t)}function Fn(e,t,n,o,r){let i=e.depth>r&&Hn(e,t,r+1),s=o.depth>r&&Hn(n,o,r+1),l=[];return $n(null,e,r,l),i&&s&&t.index(r)==n.index(r)?(Bn(i,s),Vn(zn(i,Fn(e,t,n,o,r+1)),l)):(i&&Vn(zn(i,Un(e,t,r+1)),l),$n(t,n,r,l),s&&Vn(zn(s,Un(n,o,r+1)),l)),$n(o,null,r,l),new Rn(l)}function Un(e,t,n){let o=[];if($n(null,e,n,o),e.depth>n){Vn(zn(Hn(e,t,n+1),Un(e,t,n+1)),o)}return $n(t,null,n,o),new Rn(o)}_n.empty=new _n(Rn.empty,0,0);class Wn{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?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[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].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],o=e.child(t);return n?e.child(t).cut(n):o}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):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],o=0==t?0:this.path[3*t-1]+1;for(let r=0;r<e;r++)o+=n.child(r).nodeSize;return o}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return An.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),o=e.maybeChild(t);if(!n){let e=n;n=o,o=e}let r=n.marks;for(var i=0;i<r.length;i++)!1!==r[i].type.spec.inclusive||o&&r[i].isInSet(o.marks)||(r=r[i--].removeFromSet(r));return r}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,o=e.parent.maybeChild(e.index());for(var r=0;r<n.length;r++)!1!==n[r].type.spec.inclusive||o&&n[r].isInSet(o.marks)||(n=n[r--].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 Zn(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],o=0,r=t;for(let i=e;;){let{index:e,offset:t}=i.content.findIndex(r),s=r-t;if(n.push(i,e,o+t),!s)break;if(i=i.child(e),i.isText)break;r=s-1,o+=t+1}return new Wn(t,n,r)}static resolveCached(e,t){let n=Kn.get(e);if(n)for(let r=0;r<n.elts.length;r++){let e=n.elts[r];if(e.pos==t)return e}else Kn.set(e,n=new qn);let o=n.elts[n.i]=Wn.resolve(e,t);return n.i=(n.i+1)%Gn,o}}class qn{constructor(){this.elts=[],this.i=0}}const Gn=12,Kn=new WeakMap;class Zn{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)}}const Jn=Object.create(null);let Xn=class e{constructor(e,t,n,o=An.none){this.type=e,this.attrs=t,this.marks=o,this.content=n||Rn.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,o=0){this.content.nodesBetween(e,t,n,o,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,o){return this.content.textBetween(e,t,n,o)}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&&Nn(this.attrs,t||e.defaultAttrs||Jn)&&An.sameSet(this.marks,n||An.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 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return _n.empty;let o=this.resolve(e),r=this.resolve(t),i=n?0:o.sharedDepth(t),s=o.start(i),l=o.node(i).content.cut(o.pos-s,r.pos-s);return new _n(l,o.depth-i,r.depth-i)}replace(e,t,n){return Ln(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:o}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(o==e||t.isText)return t;e-=o+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(0==e)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 o=this.content.child(t-1);return{node:o,index:t-1,offset:n-o.nodeSize}}resolve(e){return Wn.resolveCached(this,e)}resolveNoCache(e){return Wn.resolve(this,e)}rangeHasMark(e,t,n){let o=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(o=!0),!o)),o}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()+")"),Qn(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=Rn.empty,o=0,r=n.childCount){let i=this.contentMatchAt(e).matchFragment(n,o,r),s=i&&i.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let l=o;l<r;l++)if(!this.type.allowsMarks(n.child(l).marks))return!1;return!0}canReplaceWith(e,t,n,o){if(o&&!this.type.allowsMarks(o))return!1;let r=this.contentMatchAt(e).matchType(n),i=r&&r.matchFragment(this.content,t);return!!i&&i.validEnd}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),this.type.checkAttrs(this.attrs);let e=An.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!An.sameSet(e,this.marks))throw new 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 new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let o=Rn.fromJSON(e,t.content),r=e.nodeType(t.type).create(t.attrs,o,n);return r.type.checkAttrs(r.attrs),r}};Xn.prototype.text=void 0;class Yn extends Xn{constructor(e,t,n,o){if(super(e,t,null,o),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Qn(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Yn(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Yn(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Qn(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class eo{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new to(e,t);if(null==n.next)return eo.empty;let o=no(n);n.next&&n.err("Unexpected trailing text");let r=function(e){let t=Object.create(null);return n(ao(e,0));function n(o){let r=[];o.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let o;for(let e=0;e<r.length;e++)r[e][0]==t&&(o=r[e][1]);ao(e,n).forEach(e=>{o||r.push([t,o=[]]),-1==o.indexOf(e)&&o.push(e)})})});let i=t[o.join(",")]=new eo(o.indexOf(e.length-1)>-1);for(let e=0;e<r.length;e++){let o=r[e][1].sort(lo);i.next.push({type:r[e][0],next:t[o.join(",")]||n(o)})}return i}}(function(e){let t=[[]];return r(i(e,0),n()),t;function n(){return t.push([])-1}function o(e,n,o){let r={term:o,to:n};return t[e].push(r),r}function r(e,t){e.forEach(e=>e.to=t)}function i(e,t){if("choice"==e.type)return e.exprs.reduce((e,n)=>e.concat(i(n,t)),[]);if("seq"!=e.type){if("star"==e.type){let s=n();return o(t,s),r(i(e.expr,s),s),[o(s)]}if("plus"==e.type){let s=n();return r(i(e.expr,t),s),r(i(e.expr,s),s),[o(s)]}if("opt"==e.type)return[o(t)].concat(i(e.expr,t));if("range"==e.type){let s=t;for(let t=0;t<e.min;t++){let t=n();r(i(e.expr,s),t),s=t}if(-1==e.max)r(i(e.expr,s),s);else for(let t=e.min;t<e.max;t++){let t=n();o(s,t),r(i(e.expr,s),t),s=t}return[o(s)]}if("name"==e.type)return[o(t,void 0,e.value)];throw new Error("Unknown expr type")}for(let o=0;;o++){let s=i(e.exprs[o],t);if(o==e.exprs.length-1)return s;r(s,t=n())}}}(o));return function(e,t){for(let n=0,o=[e];n<o.length;n++){let e=o[n],r=!e.validEnd,i=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];i.push(n.name),!r||n.isText||n.hasRequiredAttrs()||(r=!1),-1==o.indexOf(s)&&o.push(s)}r&&t.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,n),r}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 o=this;for(let r=t;o&&r<n;r++)o=o.matchType(e.child(r).type);return o}get inlineContent(){return 0!=this.next.length&&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 o=[this];return function r(i,s){let l=i.matchFragment(e,n);if(l&&(!t||l.validEnd))return Rn.from(s.map(e=>e.createAndFill()));for(let e=0;e<i.next.length;e++){let{type:t,next:n}=i.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==o.indexOf(n)){o.push(n);let e=r(n,s.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let o=n.shift(),r=o.match;if(r.matchType(e)){let e=[];for(let t=o;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<r.next.length;e++){let{type:i,next:s}=r.next[e];i.isLeaf||i.hasRequiredAttrs()||i.name in t||o.type&&!s.validEnd||(n.push({match:i.contentMatch,type:i,via:o}),t[i.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return function t(n){e.push(n);for(let o=0;o<n.next.length;o++)-1==e.indexOf(n.next[o].next)&&t(n.next[o].next)}(this),e.map((t,n)=>{let o=n+(t.validEnd?"*":" ")+" ";for(let r=0;r<t.next.length;r++)o+=(r?", ":"")+t.next[r].type.name+"->"+e.indexOf(t.next[r].next);return o}).join("\n")}}eo.empty=new eo(!0);class to{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function no(e){let t=[];do{t.push(oo(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function oo(e){let t=[];do{t.push(ro(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function ro(e){let t=function(e){if(e.eat("(")){let t=no(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,o=n[t];if(o)return[o];let r=[];for(let i in n){let e=n[i];e.isInGroup(t)&&r.push(e)}0==r.length&&e.err("No node type or group '"+t+"' found");return r}(e,e.next).map(t=>(null==e.inline?e.inline=t.isInline:e.inline!=t.isInline&&e.err("Mixing inline and block content"),{type:"name",value:t}));return e.pos++,1==t.length?t[0]:{type:"choice",exprs:t}}e.err("Unexpected token '"+e.next+"'")}(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("{"))break;t=so(e,t)}return t}function io(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function so(e,t){let n=io(e),o=n;return e.eat(",")&&(o="}"!=e.next?io(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:o,expr:t}}function lo(e,t){return t-e}function ao(e,t){let n=[];return function t(o){let r=e[o];if(1==r.length&&!r[0].term)return t(r[0].to);n.push(o);for(let e=0;e<r.length;e++){let{term:o,to:i}=r[e];o||-1!=n.indexOf(i)||t(i)}}(t),n.sort(lo)}function co(e){let t=Object.create(null);for(let n in e){let o=e[n];if(!o.hasDefault)return null;t[n]=o.default}return t}function uo(e,t){let n=Object.create(null);for(let o in e){let r=t&&t[o];if(void 0===r){let t=e[o];if(!t.hasDefault)throw new RangeError("No value supplied for attribute "+o);r=t.default}n[o]=r}return n}function ho(e,t,n,o){for(let r in t)if(!(r in e))throw new RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let r in e){let n=e[r];n.validate&&n.validate(t[r])}}function po(e,t){let n=Object.create(null);if(t)for(let o in t)n[o]=new mo(e,o,t[o]);return n}let fo=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=po(e,n.attrs),this.defaultAttrs=co(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==eo.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:uo(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Xn(this,this.computeAttrs(e),Rn.from(t),An.setFrom(n))}createChecked(e=null,t,n){return t=Rn.from(t),this.checkContent(t),new Xn(this,this.computeAttrs(e),t,An.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=Rn.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let o=this.contentMatch.matchFragment(t),r=o&&o.fillBefore(Rn.empty,!0);return r?new Xn(this,e,t.append(r),An.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let n=0;n<e.childCount;n++)if(!this.allowsMarks(e.child(n).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){ho(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(null==this.markSet)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:An.none:e}static compile(t,n){let o=Object.create(null);t.forEach((t,r)=>o[t]=new e(t,n,r));let r=n.spec.topNode||"doc";if(!o[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!o.text)throw new RangeError("Every schema needs a 'text' type");for(let e in o.text.attrs)throw new RangeError("The text node type should not have attributes");return o}};class mo{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let o=n.split("|");return n=>{let r=null===n?"null":typeof n;if(o.indexOf(r)<0)throw new RangeError(`Expected value of type ${o} for attribute ${t} on type ${e}, got ${r}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class go{constructor(e,t,n,o){this.name=e,this.rank=t,this.schema=n,this.spec=o,this.attrs=po(e,o.attrs),this.excluded=null;let r=co(this.attrs);this.instance=r?new An(this,r):null}create(e=null){return!e&&this.instance?this.instance:new An(this,uo(this.attrs,e))}static compile(e,t){let n=Object.create(null),o=0;return e.forEach((e,r)=>n[e]=new go(e,o++,t,r)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){ho(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class yo{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let o in e)t[o]=e[o];t.nodes=En.from(e.nodes),t.marks=En.from(e.marks||{}),this.nodes=fo.compile(this.spec.nodes,this),this.marks=go.compile(this.spec.marks,this);let n=Object.create(null);for(let o in this.nodes){if(o in this.marks)throw new RangeError(o+" can not be both a node and a mark");let e=this.nodes[o],t=e.spec.content||"",r=e.spec.marks;if(e.contentMatch=n[t]||(n[t]=eo.parse(t,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet="_"==r?null:r?bo(this,r.split(" ")):""!=r&&e.inlineContent?null:[]}for(let o in this.marks){let e=this.marks[o],t=e.spec.excludes;e.excluded=null==t?[e]:""==t?[]:bo(this,t.split(" "))}this.nodeFromJSON=e=>Xn.fromJSON(this,e),this.markFromJSON=e=>An.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,o){if("string"==typeof e)e=this.nodeType(e);else{if(!(e instanceof fo))throw new RangeError("Invalid node type: "+e);if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}return e.createChecked(t,n,o)}text(e,t){let n=this.nodes.text;return new Yn(n,n.defaultAttrs,e,An.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function bo(e,t){let n=[];for(let o=0;o<t.length;o++){let r=t[o],i=e.marks[r],s=i;if(i)n.push(i);else for(let t in e.marks){let o=e.marks[t];("_"==r||o.spec.group&&o.spec.group.split(" ").indexOf(r)>-1)&&n.push(s=o)}if(!s)throw new SyntaxError("Unknown mark type: '"+t[o]+"'")}return n}let vo=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(function(e){return null!=e.tag}(e))this.tags.push(e);else if(function(e){return null!=e.style}(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 So(this,t,!1);return n.addAll(e,An.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new So(this,t,!0);return n.addAll(e,An.none,t.from,t.to),_n.maxOpen(n.finish())}matchTag(e,t,n){for(let o=n?this.tags.indexOf(n)+1:0;o<this.tags.length;o++){let n=this.tags[o];if(Mo(e,n.tag)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,o){for(let r=o?this.styles.indexOf(o)+1:0;r<this.styles.length;r++){let o=this.styles[r],i=o.style;if(!(0!=i.indexOf(e)||o.context&&!n.matchesContext(o.context)||i.length>e.length&&(61!=i.charCodeAt(e.length)||i.slice(e.length+1)!=t))){if(o.getAttrs){let e=o.getAttrs(t);if(!1===e)continue;o.attrs=e||void 0}return o}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,o=0;for(;o<t.length;o++){let e=t[o];if((null==e.priority?50:e.priority)<n)break}t.splice(o,0,e)}for(let o in e.marks){let t=e.marks[o].spec.parseDOM;t&&t.forEach(e=>{n(e=Ro(e)),e.mark||e.ignore||e.clearMark||(e.mark=o)})}for(let o in e.nodes){let t=e.nodes[o].spec.parseDOM;t&&t.forEach(e=>{n(e=Ro(e)),e.node||e.ignore||e.mark||(e.node=o)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}};const xo={address:!0,article:!0,aside:!0,blockquote:!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},wo={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ko={ol:!0,ul:!0};function Co(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class Eo{constructor(e,t,n,o,r,i){this.type=e,this.attrs=t,this.marks=n,this.solid=o,this.options=i,this.content=[],this.activeMarks=An.none,this.match=r||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Rn.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[0].length))}}let t=Rn.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Rn.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&&!xo.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class So{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let o,r=t.topNode,i=Co(null,t.preserveWhitespace,0)|(n?4:0);o=r?new Eo(r.type,r.attrs,An.none,!0,t.topMatch||r.type.contentMatch,i):new Eo(n?null:e.schema.topNodeType,null,An.none,!0,null,i),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,o=this.top,r=2&o.options?"full":this.localPreserveWS||(1&o.options)>0,{schema:i}=this.parser;if("full"===r||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r)if("full"===r)n=n.replace(/\r\n?/g,"\n");else if(i.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(i.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(i.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(i.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=o.content[o.content.length-1],r=e.previousSibling;(!t||r&&"BR"==r.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(i.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let o=this.localPreserveWS,r=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i,s=e.nodeName.toLowerCase();ko.hasOwnProperty(s)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&ko.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));e:if(l?l.ignore:wo.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let n,o=this.needsBlock;if(xo.hasOwnProperty(s))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),n=!0,r.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let i=l&&l.skip?t:this.readStyles(e,t);i&&this.addAll(e,i),n&&this.sync(r),this.needsBlock=o}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,l,n,!1===l.consuming?i:void 0)}this.localPreserveWS=o}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||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 o=0;o<this.parser.matchedStyles.length;o++){let e=this.parser.matchedStyles[o],r=n.getPropertyValue(e);if(r)for(let n;;){let o=this.parser.matchStyle(e,r,this,n);if(!o)break;if(o.ignore)return null;if(t=o.clearMark?t.filter(e=>!o.clearMark(e)):t.concat(this.parser.schema.marks[o.mark].create(o.attrs)),!1!==o.consuming)break;n=o}}return t}addElementByRule(e,t,n,o){let r,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(i,t.attrs||null,n,t.preserveWhitespace);e&&(r=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let s=this.top;if(i&&i.isLeaf)this.findInside(e);else if(o)this.addElement(e,n,o);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let o=e;"string"==typeof t.contentElement?o=e.querySelector(t.contentElement):"function"==typeof t.contentElement?o=t.contentElement(e):t.contentElement&&(o=t.contentElement),this.findAround(e,o,!0),this.addAll(o,n),this.findAround(e,o,!1)}r&&this.sync(s)&&this.open--}addAll(e,t,n,o){let r=n||0;for(let i=n?e.childNodes[n]:e.firstChild,s=null==o?null:e.childNodes[o];i!=s;i=i.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(i,t);this.findAtPoint(e,r)}findPlace(e,t,n){let o,r;for(let i=this.open,s=0;i>=0;i--){let t=this.nodes[i],l=t.findWrapping(e);if(l&&(!o||o.length>l.length+s)&&(o=l,r=t,!l.length))break;if(t.solid){if(n)break;s+=2}}if(!o)return null;this.sync(r);for(let i=0;i<o.length;i++)t=this.enterInner(o[i],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 o=this.findPlace(e,t,n);if(o){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=An.none;for(let r of o.concat(e.marks))(t.type?t.type.allowsMarkType(r.type):To(r.type,e.type))&&(n=r.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,o){let r=this.findPlace(e.create(t),n,!1);return r&&(r=this.enterInner(e,t,n,!0,o)),r}enterInner(e,t,n,o=!1,r){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let s=Co(e,r,i.options);4&i.options&&0==i.content.length&&(s|=4);let l=An.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):To(t.type,e))||(l=t.addToSet(l),!1)),this.nodes.push(new Eo(e,t,l,o,null,s)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!(!this.isOpen&&!this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=1)}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++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let o=0;o<this.find.length;o++)if(null==this.find[o].pos&&1==e.nodeType&&e.contains(this.find[o].node)){t.compareDocumentPosition(this.find[o].node)&(n?2:4)&&(this.find[o].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,o=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),r=-(n?n.depth+1:0)+(o?0:1),i=(e,s)=>{for(;e>=0;e--){let l=t[e];if(""==l){if(e==t.length-1||0==e)continue;for(;s>=r;s--)if(i(e-1,s))return!0;return!1}{let e=s>0||0==s&&o?this.nodes[s].type:n&&s>=r?n.node(s-r).type:null;if(!e||e.name!=l&&!e.isInGroup(l))return!1;s--}}return!0};return i(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}}function Mo(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Ro(e){let t={};for(let n in e)t[n]=e[n];return t}function To(e,t){let n=t.schema.nodes;for(let o in n){let r=n[o];if(!r.allowsMarkType(e))continue;let i=[],s=e=>{i.push(e);for(let n=0;n<e.edgeCount;n++){let{type:o,next:r}=e.edge(n);if(o==t)return!0;if(i.indexOf(r)<0&&s(r))return!0}};if(s(r.contentMatch))return!0}}class jo{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=Ao(t).createDocumentFragment());let o=n,r=[];return e.forEach(e=>{if(r.length||e.marks.length){let n=0,i=0;for(;n<r.length&&i<e.marks.length;){let t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(r[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<r.length;)o=r.pop()[1];for(;i<e.marks.length;){let n=e.marks[i++],s=this.serializeMark(n,e.isInline,t);s&&(r.push([n,o]),o.appendChild(s.dom),o=s.contentDOM||s.dom)}}o.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:o}=Po(Ao(t),this.nodes[e.type.name](e),null,e.attrs);if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,o)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let o=e.marks.length-1;o>=0;o--){let r=this.serializeMark(e.marks[o],e.isInline,t);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(e,t,n={}){let o=this.marks[e.type.name];return o&&Po(Ao(n),o(e,t),null,e.attrs)}static renderSpec(e,t,n=null,o){return Po(e,t,n,o)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new jo(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=No(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return No(e.marks)}}function No(e){let t={};for(let n in e){let o=e[n].spec.toDOM;o&&(t[n]=o)}return t}function Ao(e){return e.document||window.document}const Oo=new WeakMap;function _o(e){let t=Oo.get(e);return void 0===t&&Oo.set(e,t=function(e){let t=null;function n(e){if(e&&"object"==typeof e)if(Array.isArray(e))if("string"==typeof e[0])t||(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}(e)),t}function Po(e,t,n,o){if("string"==typeof t)return{dom:e.createTextNode(t)};if(null!=t.nodeType)return{dom:t};if(t.dom&&null!=t.dom.nodeType)return t;let r,i=t[0];if("string"!=typeof i)throw new RangeError("Invalid array passed to renderSpec");if(o&&(r=_o(o))&&r.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s,l=i.indexOf(" ");l>0&&(n=i.slice(0,l),i=i.slice(l+1));let a=n?e.createElementNS(n,i):e.createElement(i),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?a.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):"style"==e&&a.style?a.style.cssText=c[e]:a.setAttribute(e,c[e])}}for(let u=d;u<t.length;u++){let r=t[u];if(0===r){if(u<t.length-1||u>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}{let{dom:t,contentDOM:i}=Po(e,r,n,o);if(a.appendChild(t),i){if(s)throw new RangeError("Multiple content holes");s=i}}}return{dom:a,contentDOM:s}}const Io=Math.pow(2,16);function Lo(e,t){return e+t*Io}function Do(e){return 65535&e}class Bo{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class Ho{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Ho.empty)return Ho.empty}recover(e){let t=0,n=Do(e);if(!this.inverted)for(let o=0;o<n;o++)t+=this.ranges[3*o+2]-this.ranges[3*o+1];return this.ranges[3*n]+t+function(e){return(e-(65535&e))/Io}(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 o=0,r=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let l=this.ranges[s]-(this.inverted?o:0);if(l>e)break;let a=this.ranges[s+r],c=this.ranges[s+i],d=l+a;if(e<=d){let r=l+o+((a?e==l?-1:e==d?1:t:t)<0?0:c);if(n)return r;let i=e==(t<0?l:d)?null:Lo(s/3,e-l),u=e==l?2:e==d?1:4;return(t<0?e!=l:e!=d)&&(u|=8),new Bo(r,u,i)}o+=c-a}return n?e+o:new Bo(e+o,0,null)}touches(e,t){let n=0,o=Do(t),r=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let t=this.ranges[s]-(this.inverted?n:0);if(t>e)break;let l=this.ranges[s+r];if(e<=t+l&&s==3*o)return!0;n+=this.ranges[s+i]-l}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let o=0,r=0;o<this.ranges.length;o+=3){let i=this.ranges[o],s=i-(this.inverted?r:0),l=i+(this.inverted?0:r),a=this.ranges[o+t],c=this.ranges[o+n];e(s,s+a,l,l+c),r+=c-a}}invert(){return new Ho(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?Ho.empty:new Ho(e<0?[0,-e,0]:[0,0,e])}}Ho.empty=new Ho([]);class Vo{constructor(e,t,n=0,o=(e?e.length:0)){this.mirror=t,this.from=n,this.to=o,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new Vo(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let o=e.getMirror(t);this.appendMap(e._maps[t],null!=o&&o<t?n+o:void 0)}}getMirror(e){if(this.mirror)for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let o=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=o&&o>t?n-o-1:void 0)}}invert(){let e=new Vo;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let o=0;for(let r=this.from;r<this.to;r++){let n=this._maps[r].mapResult(e,t);if(null!=n.recover){let t=this.getMirror(r);if(null!=t&&t>r&&t<this.to){r=t,e=this._maps[t].recover(n.recover);continue}}o|=n.delInfo,e=n.pos}return n?e:new Bo(e,o,null)}}const $o=Object.create(null);class zo{getMap(){return Ho.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=$o[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in $o)throw new RangeError("Duplicate use of step JSON ID "+e);return $o[e]=t,t.prototype.jsonID=e,t}}class Fo{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new Fo(e,null)}static fail(e){return new Fo(null,e)}static fromReplace(e,t,n,o){try{return Fo.ok(e.replace(t,n,o))}catch(r){if(r instanceof On)return Fo.fail(r.message);throw r}}}function Uo(e,t,n){let o=[];for(let r=0;r<e.childCount;r++){let i=e.child(r);i.content.size&&(i=i.copy(Uo(i.content,t,i))),i.isInline&&(i=t(i,n,r)),o.push(i)}return Rn.fromArray(o)}class Wo extends zo{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),o=n.node(n.sharedDepth(this.to)),r=new _n(Uo(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,o),t.openStart,t.openEnd);return Fo.fromReplace(e,this.from,this.to,r)}invert(){return new qo(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new Wo(t.pos,n.pos,this.mark)}merge(e){return e instanceof Wo&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Wo(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Wo(t.from,t.to,e.markFromJSON(t.mark))}}zo.jsonID("addMark",Wo);class qo extends zo{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 _n(Uo(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return Fo.fromReplace(e,this.from,this.to,n)}invert(){return new Wo(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new qo(t.pos,n.pos,this.mark)}merge(e){return e instanceof qo&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new qo(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new qo(t.from,t.to,e.markFromJSON(t.mark))}}zo.jsonID("removeMark",qo);class Go extends zo{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Fo.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Fo.fromReplace(e,this.pos,this.pos+1,new _n(Rn.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new Go(this.pos,t.marks[n]);return new Go(this.pos,this.mark)}}return new Ko(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Go(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Go(t.pos,e.markFromJSON(t.mark))}}zo.jsonID("addNodeMark",Go);class Ko extends zo{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Fo.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Fo.fromReplace(e,this.pos,this.pos+1,new _n(Rn.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new Go(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ko(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ko(t.pos,e.markFromJSON(t.mark))}}zo.jsonID("removeNodeMark",Ko);class Zo extends zo{constructor(e,t,n,o=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=o}apply(e){return this.structure&&Xo(e,this.from,this.to)?Fo.fail("Structure replace would overwrite content"):Fo.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ho([this.from,this.to-this.from,this.slice.size])}invert(e){return new Zo(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deletedAcross&&n.deletedAcross?null:new Zo(t.pos,Math.max(t.pos,n.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Zo)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart){if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;{let t=this.slice.size+e.slice.size==0?_n.empty:new _n(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Zo(e.from,this.to,t,this.structure)}}{let t=this.slice.size+e.slice.size==0?_n.empty:new _n(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Zo(this.from,this.to+(e.to-e.from),t,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Zo(t.from,t.to,_n.fromJSON(e,t.slice),!!t.structure)}}zo.jsonID("replace",Zo);class Jo extends zo{constructor(e,t,n,o,r,i,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=o,this.slice=r,this.insert=i,this.structure=s}apply(e){if(this.structure&&(Xo(e,this.from,this.gapFrom)||Xo(e,this.gapTo,this.to)))return Fo.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Fo.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?Fo.fromReplace(e,this.from,this.to,n):Fo.fail("Content does not fit in gap")}getMap(){return new Ho([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new Jo(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),o=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),r=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||o<t.pos||r>n.pos?null:new Jo(t.pos,n.pos,o,r,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Jo(t.from,t.to,t.gapFrom,t.gapTo,_n.fromJSON(e,t.slice),t.insert,!!t.structure)}}function Xo(e,t,n){let o=e.resolve(t),r=n-t,i=o.depth;for(;r>0&&i>0&&o.indexAfter(i)==o.node(i).childCount;)i--,r--;if(r>0){let e=o.node(i).maybeChild(o.indexAfter(i));for(;r>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,r--}}return!1}function Yo(e,t,n,o=n.contentMatch,r=!0){let i=e.doc.nodeAt(t),s=[],l=t+1;for(let a=0;a<i.childCount;a++){let t=i.child(a),c=l+t.nodeSize,d=o.matchType(t.type);if(d){o=d;for(let o=0;o<t.marks.length;o++)n.allowsMarkType(t.marks[o].type)||e.step(new qo(l,c,t.marks[o]));if(r&&t.isText&&"pre"!=n.whitespace){let e,o,r=/\r?\n|\r/g;for(;e=r.exec(t.text);)o||(o=new _n(Rn.from(n.schema.text(" ",n.allowedMarks(t.marks))),0,0)),s.push(new Zo(l+e.index,l+e.index+e[0].length,o))}}else s.push(new Zo(l,c,_n.empty));l=c}if(!o.validEnd){let t=o.fillBefore(Rn.empty,!0);e.replace(l,l,new _n(t,0,0))}for(let a=s.length-1;a>=0;a--)e.step(s[a])}function Qo(e,t,n){return(0==t||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function er(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth;;--n){let o=e.$from.node(n),r=e.$from.index(n),i=e.$to.indexAfter(n);if(n<e.depth&&o.canReplace(r,i,t))return n;if(0==n||o.type.spec.isolating||!Qo(o,r,i))break}return null}function tr(e,t,n=null,o=e){let r=function(e,t){let{parent:n,startIndex:o,endIndex:r}=e,i=n.contentMatchAt(o).findWrapping(t);if(!i)return null;let s=i.length?i[0]:t;return n.canReplaceWith(o,r,s)?i:null}(e,t),i=r&&function(e,t){let{parent:n,startIndex:o,endIndex:r}=e,i=n.child(o),s=t.contentMatch.findWrapping(i.type);if(!s)return null;let l=(s.length?s[s.length-1]:t).contentMatch;for(let a=o;l&&a<r;a++)l=l.matchType(n.child(a).type);return l&&l.validEnd?s:null}(o,t);return i?r.map(nr).concat({type:t,attrs:n}).concat(i.map(nr)):null}function nr(e){return{type:e,attrs:null}}function or(e,t,n,o){t.forEach((r,i)=>{if(r.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(r.text);){let r=e.mapping.slice(o).map(n+1+i+s.index);e.replaceWith(r,r+1,t.type.schema.linebreakReplacement.create())}}})}function rr(e,t,n,o){t.forEach((r,i)=>{if(r.type==r.type.schema.linebreakReplacement){let r=e.mapping.slice(o).map(n+1+i);e.replaceWith(r,r+1,t.type.schema.text("\n"))}})}function ir(e,t,n=1,o){let r=e.resolve(t),i=r.depth-n,s=o&&o[o.length-1]||r.parent;if(i<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!s.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let c=r.depth-1,d=n-2;c>i;c--,d--){let e=r.node(c),t=r.index(c);if(e.type.spec.isolating)return!1;let n=e.content.cutByIndex(t,e.childCount),i=o&&o[d+1];i&&(n=n.replaceChild(0,i.type.create(i.attrs)));let s=o&&o[d]||e;if(!e.canReplace(t+1,e.childCount)||!s.type.validContent(n))return!1}let l=r.indexAfter(i),a=o&&o[0];return r.node(i).canReplaceWith(l,l,a?a.type:r.node(i+1).type)}function sr(e,t){let n=e.resolve(t),o=n.index();return lr(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(o,o+1)}function lr(e,t){return!(!e||!t||e.isLeaf||!function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:o}=e.type.schema;for(let r=0;r<t.childCount;r++){let i=t.child(r),s=i.type==o?e.type.schema.nodes.text:i.type;if(n=n.matchType(s),!n)return!1;if(!e.type.allowsMarks(i.marks))return!1}return n.validEnd}(e,t))}function ar(e,t,n=-1){let o=e.resolve(t);for(let r=o.depth;;r--){let e,i,s=o.index(r);if(r==o.depth?(e=o.nodeBefore,i=o.nodeAfter):n>0?(e=o.node(r+1),s++,i=o.node(r).maybeChild(s)):(e=o.node(r).maybeChild(s-1),i=o.node(r+1)),e&&!e.isTextblock&&lr(e,i)&&o.node(r).canReplace(s,s+1))return t;if(0==r)break;t=n<0?o.before(r):o.after(r)}}function cr(e,t,n){let o=e.resolve(t);if(!n.content.size)return t;let r=n.content;for(let i=0;i<n.openStart;i++)r=r.firstChild.content;for(let i=1;i<=(0==n.openStart&&n.size?2:1);i++)for(let e=o.depth;e>=0;e--){let t=e==o.depth?0:o.pos<=(o.start(e+1)+o.end(e+1))/2?-1:1,n=o.index(e)+(t>0?1:0),s=o.node(e),l=!1;if(1==i)l=s.canReplace(n,n,r);else{let e=s.contentMatchAt(n).findWrapping(r.firstChild.type);l=e&&s.canReplaceWith(n,n,e[0])}if(l)return 0==t?o.pos:t<0?o.before(e+1):o.after(e+1)}return null}function dr(e,t,n=t,o=_n.empty){if(t==n&&!o.size)return null;let r=e.resolve(t),i=e.resolve(n);return ur(r,i,o)?new Zo(t,n,o):new hr(r,i,o).fit()}function ur(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}zo.jsonID("replaceAround",Jo);class hr{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=Rn.empty;for(let o=0;o<=e.depth;o++){let t=e.node(o);this.frontier.push({type:t.type,match:t.contentMatchAt(e.indexAfter(o))})}for(let o=e.depth;o>0;o--)this.placed=Rn.from(e.node(o).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,o=this.close(e<0?this.$to:n.doc.resolve(e));if(!o)return null;let r=this.placed,i=n.depth,s=o.depth;for(;i&&s&&1==r.childCount;)r=r.firstChild.content,i--,s--;let l=new _n(r,i,s);return e>-1?new Jo(n.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||n.pos!=this.$to.pos?new Zo(n.pos,o.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,o=this.unplaced.openEnd;n<e;n++){let r=t.firstChild;if(t.childCount>1&&(o=0),r.type.spec.isolating&&o<=n){e=n;break}t=r.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e,o=null;n?(o=mr(this.unplaced.content,n-1).firstChild,e=o.content):e=this.unplaced.content;let r=e.firstChild;for(let i=this.depth;i>=0;i--){let e,{type:s,match:l}=this.frontier[i],a=null;if(1==t&&(r?l.matchType(r.type)||(a=l.fillBefore(Rn.from(r),!1)):o&&s.compatibleContent(o.type)))return{sliceDepth:n,frontierDepth:i,parent:o,inject:a};if(2==t&&r&&(e=l.findWrapping(r.type)))return{sliceDepth:n,frontierDepth:i,parent:o,wrap:e};if(o&&l.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,o=mr(e,t);return!(!o.childCount||o.firstChild.isLeaf)&&(this.unplaced=new _n(e,t+1,Math.max(n,o.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,o=mr(e,t);if(o.childCount<=1&&t>0){let r=e.size-t<=t+o.size;this.unplaced=new _n(pr(e,t-1,1),t-1,r?t-1:n)}else this.unplaced=new _n(pr(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:o,wrap:r}){for(;this.depth>t;)this.closeFrontierNode();if(r)for(let f=0;f<r.length;f++)this.openFrontierNode(r[f]);let i=this.unplaced,s=n?n.content:i.content,l=i.openStart-e,a=0,c=[],{match:d,type:u}=this.frontier[t];if(o){for(let e=0;e<o.childCount;e++)c.push(o.child(e));d=d.matchFragment(o)}let h=s.size+e-(i.content.size-i.openEnd);for(;a<s.childCount;){let e=s.child(a),t=d.matchType(e.type);if(!t)break;a++,(a>1||0==l||e.content.size)&&(d=t,c.push(gr(e.mark(u.allowedMarks(e.marks)),1==a?l:0,a==s.childCount?h:-1)))}let p=a==s.childCount;p||(h=-1),this.placed=fr(this.placed,t,Rn.from(c)),this.frontier[t].match=d,p&&h<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let f=0,m=s;f<h;f++){let e=m.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),m=e.content}this.unplaced=p?0==e?_n.empty:new _n(pr(i.content,e-1,1),e-1,h<0?i.openEnd:e-1):new _n(pr(i.content,e,a),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e,t=this.frontier[this.depth];if(!t.type.isTextblock||!yr(this.$to,this.$to.depth,t.type,t.match,!1)||this.$to.depth==this.depth&&(e=this.findCloseLevel(this.$to))&&e.depth==this.depth)return-1;let{depth:n}=this.$to,o=this.$to.after(n);for(;n>1&&o==this.$to.end(--n);)++o;return o}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:o}=this.frontier[t],r=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),i=yr(e,t,o,n,r);if(i){for(let n=t-1;n>=0;n--){let{match:t,type:o}=this.frontier[n],r=yr(e,n,o,t,!0);if(!r||r.childCount)continue e}return{depth:t,fit:i,move:r?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=fr(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),o=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,o)}return e}openFrontierNode(e,t=null,n){let o=this.frontier[this.depth];o.match=o.match.matchType(e),this.placed=fr(this.placed,this.depth,Rn.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(Rn.empty,!0);e.childCount&&(this.placed=fr(this.placed,this.frontier.length,e))}}function pr(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(pr(e.firstChild.content,t-1,n)))}function fr(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(fr(e.lastChild.content,t-1,n)))}function mr(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function gr(e,t,n){if(t<=0)return e;let o=e.content;return t>1&&(o=o.replaceChild(0,gr(o.firstChild,t-1,1==o.childCount?n-1:0))),t>0&&(o=e.type.contentMatch.fillBefore(o).append(o),n<=0&&(o=o.append(e.type.contentMatch.matchFragment(o).fillBefore(Rn.empty,!0)))),e.copy(o)}function yr(e,t,n,o,r){let i=e.node(t),s=r?e.indexAfter(t):e.index(t);if(s==i.childCount&&!n.compatibleContent(i.type))return null;let l=o.fillBefore(i.content,!0,s);return l&&!function(e,t,n){for(let o=n;o<t.childCount;o++)if(!e.allowsMarks(t.child(o).marks))return!0;return!1}(n,i.content,s)?l:null}function br(e){return e.spec.defining||e.spec.definingForContent}function vr(e,t,n,o,r){if(t<n){let r=e.firstChild;e=e.replaceChild(0,r.copy(vr(r.content,t+1,n,o,r)))}if(t>o){let t=r.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(Rn.empty,!0))}return e}function xr(e,t){let n=[];for(let o=Math.min(e.depth,t.depth);o>=0;o--){let r=e.start(o);if(r<e.pos-(e.depth-o)||t.end(o)>t.pos+(t.depth-o)||e.node(o).type.spec.isolating||t.node(o).type.spec.isolating)break;(r==t.start(o)||o==e.depth&&o==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&o&&t.start(o-1)==r-1)&&n.push(o)}return n}class wr extends zo{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 Fo.fail("No node at attribute step's position");let n=Object.create(null);for(let r in t.attrs)n[r]=t.attrs[r];n[this.attr]=this.value;let o=t.type.create(n,null,t.marks);return Fo.fromReplace(e,this.pos,this.pos+1,new _n(Rn.from(o),0,t.isLeaf?0:1))}getMap(){return Ho.empty}invert(e){return new wr(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new wr(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new wr(t.pos,t.attr,t.value)}}zo.jsonID("attr",wr);class kr extends zo{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let o in e.attrs)t[o]=e.attrs[o];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return Fo.ok(n)}getMap(){return Ho.empty}invert(e){return new kr(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new kr(t.attr,t.value)}}zo.jsonID("docAttr",kr);let Cr=class extends Error{};Cr=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},(Cr.prototype=Object.create(Error.prototype)).constructor=Cr,Cr.prototype.name="TransformError";class Er{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Vo}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Cr(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}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=_n.empty){let o=dr(this.doc,e,t,n);return o&&this.step(o),this}replaceWith(e,t,n){return this.replace(e,t,new _n(Rn.from(n),0,0))}delete(e,t){return this.replace(e,t,_n.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return function(e,t,n,o){if(!o.size)return e.deleteRange(t,n);let r=e.doc.resolve(t),i=e.doc.resolve(n);if(ur(r,i,o))return e.step(new Zo(t,n,o));let s=xr(r,e.doc.resolve(n));0==s[s.length-1]&&s.pop();let l=-(r.depth+1);s.unshift(l);for(let h=r.depth,p=r.pos-1;h>0;h--,p--){let e=r.node(h).type.spec;if(e.defining||e.definingAsContext||e.isolating)break;s.indexOf(h)>-1?l=h:r.before(h)==p&&s.splice(1,0,-h)}let a=s.indexOf(l),c=[],d=o.openStart;for(let h=o.content,p=0;;p++){let e=h.firstChild;if(c.push(e),p==o.openStart)break;h=e.content}for(let h=d-1;h>=0;h--){let e=c[h],t=br(e.type);if(t&&!e.sameMarkup(r.node(Math.abs(l)-1)))d=h;else if(t||!e.type.isTextblock)break}for(let h=o.openStart;h>=0;h--){let t=(h+d+1)%(o.openStart+1),l=c[t];if(l)for(let c=0;c<s.length;c++){let d=s[(c+a)%s.length],u=!0;d<0&&(u=!1,d=-d);let h=r.node(d-1),p=r.index(d-1);if(h.canReplaceWith(p,p,l.type,l.marks))return e.replace(r.before(d),u?i.after(d):n,new _n(vr(o.content,0,o.openStart,t),t,o.openEnd))}}let u=e.steps.length;for(let h=s.length-1;h>=0&&(e.replace(t,n,o),!(e.steps.length>u));h--){let e=s[h];e<0||(t=r.before(e),n=i.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){return function(e,t,n,o){if(!o.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let r=function(e,t,n){let o=e.resolve(t);if(o.parent.canReplaceWith(o.index(),o.index(),n))return t;if(0==o.parentOffset)for(let r=o.depth-1;r>=0;r--){let e=o.index(r);if(o.node(r).canReplaceWith(e,e,n))return o.before(r+1);if(e>0)return null}if(o.parentOffset==o.parent.content.size)for(let r=o.depth-1;r>=0;r--){let e=o.indexAfter(r);if(o.node(r).canReplaceWith(e,e,n))return o.after(r+1);if(e<o.node(r).childCount)return null}return null}(e.doc,t,o.type);null!=r&&(t=n=r)}e.replaceRange(t,n,new _n(Rn.from(o),0,0))}(this,e,t,n),this}deleteRange(e,t){return function(e,t,n){let o=e.doc.resolve(t),r=e.doc.resolve(n),i=xr(o,r);for(let s=0;s<i.length;s++){let t=i[s],n=s==i.length-1;if(n&&0==t||o.node(t).type.contentMatch.validEnd)return e.delete(o.start(t),r.end(t));if(t>0&&(n||o.node(t-1).canReplace(o.index(t-1),r.indexAfter(t-1))))return e.delete(o.before(t),r.after(t))}for(let s=1;s<=o.depth&&s<=r.depth;s++)if(t-o.start(s)==o.depth-s&&n>o.end(s)&&r.end(s)-n!=r.depth-s&&o.start(s-1)==r.start(s-1)&&o.node(s-1).canReplace(o.index(s-1),r.index(s-1)))return e.delete(o.before(s),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return function(e,t,n){let{$from:o,$to:r,depth:i}=t,s=o.before(i+1),l=r.after(i+1),a=s,c=l,d=Rn.empty,u=0;for(let f=i,m=!1;f>n;f--)m||o.index(f)>0?(m=!0,d=Rn.from(o.node(f).copy(d)),u++):a--;let h=Rn.empty,p=0;for(let f=i,m=!1;f>n;f--)m||r.after(f+1)<r.end(f)?(m=!0,h=Rn.from(r.node(f).copy(h)),p++):c++;e.step(new Jo(a,c,s,l,new _n(d.append(h),u,p),d.size-u,!0))}(this,e,t),this}join(e,t=1){return function(e,t,n){let o=null,{linebreakReplacement:r}=e.doc.type.schema,i=e.doc.resolve(t-n),s=i.node().type;if(r&&s.inlineContent){let e="pre"==s.whitespace,t=!!s.contentMatch.matchType(r);e&&!t?o=!1:!e&&t&&(o=!0)}let l=e.steps.length;if(!1===o){let o=e.doc.resolve(t+n);rr(e,o.node(),o.before(),l)}s.inlineContent&&Yo(e,t+n-1,s,i.node().contentMatchAt(i.index()),null==o);let a=e.mapping.slice(l),c=a.map(t-n);if(e.step(new Zo(c,a.map(t+n,-1),_n.empty,!0)),!0===o){let t=e.doc.resolve(c);or(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return function(e,t,n){let o=Rn.empty;for(let s=n.length-1;s>=0;s--){if(o.size){let e=n[s].type.contentMatch.matchFragment(o);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}o=Rn.from(n[s].type.create(n[s].attrs,o))}let r=t.start,i=t.end;e.step(new Jo(r,i,r,i,new _n(o,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,o=null){return function(e,t,n,o,r){if(!o.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let i=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let s="function"==typeof r?r(t):r;if(t.isTextblock&&!t.hasMarkup(o,s)&&function(e,t,n){let o=e.resolve(t),r=o.index();return o.parent.canReplaceWith(r,r+1,n)}(e.doc,e.mapping.slice(i).map(n),o)){let r=null;if(o.schema.linebreakReplacement){let e="pre"==o.whitespace,t=!!o.contentMatch.matchType(o.schema.linebreakReplacement);e&&!t?r=!1:!e&&t&&(r=!0)}!1===r&&rr(e,t,n,i),Yo(e,e.mapping.slice(i).map(n,1),o,void 0,null===r);let l=e.mapping.slice(i),a=l.map(n,1),c=l.map(n+t.nodeSize,1);return e.step(new Jo(a,c,a+1,c-1,new _n(Rn.from(o.create(s,null,t.marks)),0,0),1,!0)),!0===r&&or(e,t,n,i),!1}})}(this,e,t,n,o),this}setNodeMarkup(e,t,n=null,o){return function(e,t,n,o,r){let i=e.doc.nodeAt(t);if(!i)throw new RangeError("No node at given position");n||(n=i.type);let s=n.create(o,null,r||i.marks);if(i.isLeaf)return e.replaceWith(t,t+i.nodeSize,s);if(!n.validContent(i.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new Jo(t,t+i.nodeSize,t+1,t+i.nodeSize-1,new _n(Rn.from(s),0,0),1,!0))}(this,e,t,n,o),this}setNodeAttribute(e,t,n){return this.step(new wr(e,t,n)),this}setDocAttribute(e,t){return this.step(new kr(e,t)),this}addNodeMark(e,t){return this.step(new Go(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof An)t.isInSet(n.marks)&&this.step(new Ko(e,t));else{let o,r=n.marks,i=[];for(;o=t.isInSet(r);)i.push(new Ko(e,o)),r=o.removeFromSet(r);for(let e=i.length-1;e>=0;e--)this.step(i[e])}return this}split(e,t=1,n){return function(e,t,n=1,o){let r=e.doc.resolve(t),i=Rn.empty,s=Rn.empty;for(let l=r.depth,a=r.depth-n,c=n-1;l>a;l--,c--){i=Rn.from(r.node(l).copy(i));let e=o&&o[c];s=Rn.from(e?e.type.create(e.attrs,s):r.node(l).copy(s))}e.step(new Zo(t,t,new _n(i.append(s),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){return function(e,t,n,o){let r,i,s=[],l=[];e.doc.nodesBetween(t,n,(e,a,c)=>{if(!e.isInline)return;let d=e.marks;if(!o.isInSet(d)&&c.type.allowsMarkType(o.type)){let c=Math.max(a,t),u=Math.min(a+e.nodeSize,n),h=o.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(h)||(r&&r.to==c&&r.mark.eq(d[e])?r.to=u:s.push(r=new qo(c,u,d[e])));i&&i.to==c?i.to=u:l.push(i=new Wo(c,u,o))}}),s.forEach(t=>e.step(t)),l.forEach(t=>e.step(t))}(this,e,t,n),this}removeMark(e,t,n){return function(e,t,n,o){let r=[],i=0;e.doc.nodesBetween(t,n,(e,s)=>{if(!e.isInline)return;i++;let l=null;if(o instanceof go){let t,n=e.marks;for(;t=o.isInSet(n);)(l||(l=[])).push(t),n=t.removeFromSet(n)}else o?o.isInSet(e.marks)&&(l=[o]):l=e.marks;if(l&&l.length){let o=Math.min(s+e.nodeSize,n);for(let e=0;e<l.length;e++){let n,a=l[e];for(let e=0;e<r.length;e++){let t=r[e];t.step==i-1&&a.eq(r[e].style)&&(n=t)}n?(n.to=o,n.step=i):r.push({style:a,from:Math.max(s,t),to:o,step:i})}}}),r.forEach(t=>e.step(new qo(t.from,t.to,t.style)))}(this,e,t,n),this}clearIncompatible(e,t,n){return Yo(this,e,t,n),this}}const Sr=Object.create(null);class Mr{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Rr(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=_n.empty){let n=t.content.lastChild,o=null;for(let s=0;s<t.openEnd;s++)o=n,n=n.lastChild;let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:l,$to:a}=i[s],c=e.mapping.slice(r);e.replaceRange(c.map(l.pos),c.map(a.pos),s?_n.empty:t),0==s&&Dr(e,r,(n?n.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,o=this.ranges;for(let r=0;r<o.length;r++){let{$from:i,$to:s}=o[r],l=e.mapping.slice(n),a=l.map(i.pos),c=l.map(s.pos);r?e.deleteRange(a,c):(e.replaceRangeWith(a,c,t),Dr(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let o=e.parent.inlineContent?new Nr(e):Lr(e.node(0),e.parent,e.pos,e.index(),t,n);if(o)return o;for(let r=e.depth-1;r>=0;r--){let o=t<0?Lr(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):Lr(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Pr(e.node(0))}static atStart(e){return Lr(e,e,0,0,1)||new Pr(e)}static atEnd(e){return Lr(e,e,e.content.size,e.childCount,-1)||new Pr(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Sr[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in Sr)throw new RangeError("Duplicate use of selection JSON ID "+e);return Sr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Nr.between(this.$anchor,this.$head).getBookmark()}}Mr.prototype.visible=!0;class Rr{constructor(e,t){this.$from=e,this.$to=t}}let Tr=!1;function jr(e){Tr||e.parent.inlineContent||(Tr=!0)}class Nr extends Mr{constructor(e,t=e){jr(e),jr(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return Mr.near(n);let o=e.resolve(t.map(this.anchor));return new Nr(o.parent.inlineContent?o:n,n)}replace(e,t=_n.empty){if(super.replace(e,t),t==_n.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof Nr&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Ar(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new Nr(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let o=e.resolve(t);return new this(o,n==t?o:e.resolve(n))}static between(e,t,n){let o=e.pos-t.pos;if(n&&!o||(n=o>=0?1:-1),!t.parent.inlineContent){let e=Mr.findFrom(t,n,!0)||Mr.findFrom(t,-n,!0);if(!e)return Mr.near(t,n);t=e.$head}return e.parent.inlineContent||(0==o||(e=(Mr.findFrom(e,-n,!0)||Mr.findFrom(e,n,!0)).$anchor).pos<t.pos!=o<0)&&(e=t),new Nr(e,t)}}Mr.jsonID("text",Nr);class Ar{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Ar(e.map(this.anchor),e.map(this.head))}resolve(e){return Nr.between(e.resolve(this.anchor),e.resolve(this.head))}}class Or extends Mr{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:o}=t.mapResult(this.anchor),r=e.resolve(o);return n?Mr.near(r):new Or(r)}content(){return new _n(Rn.from(this.node),0,0)}eq(e){return e instanceof Or&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new _r(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Or(e.resolve(t.anchor))}static create(e,t){return new Or(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}Or.prototype.visible=!1,Mr.jsonID("node",Or);class _r{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Ar(n,n):new _r(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&Or.isSelectable(n)?new Or(t):Mr.near(t)}}class Pr extends Mr{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=_n.empty){if(t==_n.empty){e.delete(0,e.doc.content.size);let t=Mr.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new Pr(e)}map(e){return new Pr(e)}eq(e){return e instanceof Pr}getBookmark(){return Ir}}Mr.jsonID("all",Pr);const Ir={map(){return this},resolve:e=>new Pr(e)};function Lr(e,t,n,o,r,i=!1){if(t.inlineContent)return Nr.create(e,n);for(let s=o-(r>0?0:1);r>0?s<t.childCount:s>=0;s+=r){let o=t.child(s);if(o.isAtom){if(!i&&Or.isSelectable(o))return Or.create(e,n-(r<0?o.nodeSize:0))}else{let t=Lr(e,o,n+r,r<0?o.childCount:0,r,i);if(t)return t}n+=o.nodeSize*r}return null}function Dr(e,t,n){let o=e.steps.length-1;if(o<t)return;let r,i=e.steps[o];(i instanceof Zo||i instanceof Jo)&&(e.mapping.maps[o].forEach((e,t,n,o)=>{null==r&&(r=o)}),e.setSelection(Mr.near(e.doc.resolve(r),n)))}let Br=class extends Er{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=-3&this.updated|1,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return An.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(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,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)||An.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let o=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(o.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),n=null==n?t:n,!e)return this.deleteRange(t,n);let r=this.storedMarks;if(!r){let e=this.doc.resolve(t);r=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,o.text(e,r)),this.selection.empty||this.setSelection(Mr.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}};function Hr(e,t){return t&&e?e.bind(t):e}class Vr{constructor(e,t,n){this.name=e,this.init=Hr(t.init,n),this.apply=Hr(t.apply,n)}}const $r=[new Vr("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new Vr("selection",{init:(e,t)=>e.selection||Mr.atStart(t.doc),apply:e=>e.selection}),new Vr("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,o)=>o.selection.$cursor?e.storedMarks:null}),new Vr("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class zr{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=$r.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw new 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 Vr(e.key,e.spec.state,e))})}}class Fr{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),o=null;for(;;){let r=!1;for(let i=0;i<this.config.plugins.length;i++){let s=this.config.plugins[i];if(s.spec.appendTransaction){let l=o?o[i].n:0,a=o?o[i].state:this,c=l<t.length&&s.spec.appendTransaction.call(s,l?t.slice(l):t,a,n);if(c&&n.filterTransaction(c,i)){if(c.setMeta("appendedTransaction",e),!o){o=[];for(let e=0;e<this.config.plugins.length;e++)o.push(e<i?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),r=!0}o&&(o[i]={state:n,n:t.length})}}if(!r)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new Fr(this.config),n=this.config.fields;for(let o=0;o<n.length;o++){let r=n[o];t[r.name]=r.apply(e,this[r.name],this,t)}return t}get tr(){return new Br(this)}static create(e){let t=new zr(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new Fr(t);for(let o=0;o<t.fields.length;o++)n[t.fields[o].name]=t.fields[o].init(e,n);return n}reconfigure(e){let t=new zr(this.schema,e.plugins),n=t.fields,o=new Fr(t);for(let r=0;r<n.length;r++){let t=n[r].name;o[t]=this.hasOwnProperty(t)?this[t]:n[r].init(e,o)}return o}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let o=e[n],r=o.spec.state;r&&r.toJSON&&(t[n]=r.toJSON.call(o,this[o.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let o=new zr(e.schema,e.plugins),r=new Fr(o);return o.fields.forEach(o=>{if("doc"==o.name)r.doc=Xn.fromJSON(e.schema,t.doc);else if("selection"==o.name)r.selection=Mr.fromJSON(r.doc,t.selection);else if("storedMarks"==o.name)t.storedMarks&&(r.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let i in n){let s=n[i],l=s.spec.state;if(s.key==o.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(t,i))return void(r[o.name]=l.fromJSON.call(s,e,t[i],r))}r[o.name]=o.init(e,r)}}),r}}function Ur(e,t,n){for(let o in e){let r=e[o];r instanceof Function?r=r.bind(t):"handleDOMEvents"==o&&(r=Ur(r,t,{})),n[o]=r}return n}class Wr{constructor(e){this.spec=e,this.props={},e.props&&Ur(e.props,this,this.props),this.key=e.key?e.key.key:Gr("plugin")}getState(e){return e[this.key]}}const qr=Object.create(null);function Gr(e){return e in qr?e+"$"+ ++qr[e]:(qr[e]=0,e+"$")}class Kr{constructor(e="key"){this.key=Gr(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Zr=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},Jr=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t};let Xr=null;const Yr=function(e,t,n){let o=Xr||(Xr=document.createRange());return o.setEnd(e,null==n?e.nodeValue.length:n),o.setStart(e,t||0),o},Qr=function(e,t,n,o){return n&&(ti(e,t,n,o,-1)||ti(e,t,n,o,1))},ei=/^(img|br|input|textarea|hr)$/i;function ti(e,t,n,o,r){for(var i;;){if(e==n&&t==o)return!0;if(t==(r<0?0:ni(e))){let n=e.parentNode;if(!n||1!=n.nodeType||oi(e)||ei.test(e.nodeName)||"false"==e.contentEditable)return!1;t=Zr(e)+(r<0?0:1),e=n}else{if(1!=e.nodeType)return!1;{let n=e.childNodes[t+(r<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable){if(!(null===(i=n.pmViewDesc)||void 0===i?void 0:i.ignoreForSelection))return!1;t+=r}else e=n,t=r<0?ni(e):0}}}}function ni(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function oi(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}const ri=function(e){return e.focusNode&&Qr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function ii(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}const si="undefined"!=typeof navigator?navigator:null,li="undefined"!=typeof document?document:null,ai=si&&si.userAgent||"",ci=/Edge\/(\d+)/.exec(ai),di=/MSIE \d/.exec(ai),ui=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ai),hi=!!(di||ui||ci),pi=di?document.documentMode:ui?+ui[1]:ci?+ci[1]:0,fi=!hi&&/gecko\/(\d+)/i.test(ai);fi&&(/Firefox\/(\d+)/.exec(ai)||[0,0])[1];const mi=!hi&&/Chrome\/(\d+)/.exec(ai),gi=!!mi,yi=mi?+mi[1]:0,bi=!hi&&!!si&&/Apple Computer/.test(si.vendor),vi=bi&&(/Mobile\/\w+/.test(ai)||!!si&&si.maxTouchPoints>2),xi=vi||!!si&&/Mac/.test(si.platform),wi=!!si&&/Win/.test(si.platform),ki=/Android \d/.test(ai),Ci=!!li&&"webkitFontSmoothing"in li.documentElement.style,Ei=Ci?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Si(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 Mi(e,t){return"number"==typeof e?e:e[t]}function Ri(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,o=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*o}}function Ti(e,t,n){let o=e.someProp("scrollThreshold")||0,r=e.someProp("scrollMargin")||5,i=e.dom.ownerDocument;for(let s=n||e.dom;s;){if(1!=s.nodeType){s=Jr(s);continue}let e=s,n=e==i.body,l=n?Si(i):Ri(e),a=0,c=0;if(t.top<l.top+Mi(o,"top")?c=-(l.top-t.top+Mi(r,"top")):t.bottom>l.bottom-Mi(o,"bottom")&&(c=t.bottom-t.top>l.bottom-l.top?t.top+Mi(r,"top")-l.top:t.bottom-l.bottom+Mi(r,"bottom")),t.left<l.left+Mi(o,"left")?a=-(l.left-t.left+Mi(r,"left")):t.right>l.right-Mi(o,"right")&&(a=t.right-l.right+Mi(r,"right")),a||c)if(n)i.defaultView.scrollBy(a,c);else{let n=e.scrollLeft,o=e.scrollTop;c&&(e.scrollTop+=c),a&&(e.scrollLeft+=a);let r=e.scrollLeft-n,i=e.scrollTop-o;t={left:t.left-r,top:t.top-i,right:t.right-r,bottom:t.bottom-i}}let d=n?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s="absolute"==d?s.offsetParent:Jr(s)}}function ji(e){let t=[],n=e.ownerDocument;for(let o=e;o&&(t.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),e!=n);o=Jr(o));return t}function Ni(e,t){for(let n=0;n<e.length;n++){let{dom:o,top:r,left:i}=e[n];o.scrollTop!=r+t&&(o.scrollTop=r+t),o.scrollLeft!=i&&(o.scrollLeft=i)}}let Ai=null;function Oi(e,t){let n,o,r,i,s=2e8,l=0,a=t.top,c=t.top;for(let d=e.firstChild,u=0;d;d=d.nextSibling,u++){let e;if(1==d.nodeType)e=d.getClientRects();else{if(3!=d.nodeType)continue;e=Yr(d).getClientRects()}for(let h=0;h<e.length;h++){let p=e[h];if(p.top<=a&&p.bottom>=c){a=Math.max(p.bottom,a),c=Math.min(p.top,c);let e=p.left>t.left?p.left-t.left:p.right<t.left?t.left-p.right:0;if(e<s){n=d,s=e,o=e&&3==n.nodeType?{left:p.right<t.left?p.right:p.left,top:t.top}:t,1==d.nodeType&&e&&(l=u+(t.left>=(p.left+p.right)/2?1:0));continue}}else p.top>t.top&&!r&&p.left<=t.left&&p.right>=t.left&&(r=d,i={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)&&(l=u+1)}}return!n&&r&&(n=r,o=i,s=0),n&&3==n.nodeType?function(e,t){let n=e.nodeValue.length,o=document.createRange();for(let r=0;r<n;r++){o.setEnd(e,r+1),o.setStart(e,r);let n=Di(o,1);if(n.top!=n.bottom&&_i(t,n))return{node:e,offset:r+(t.left>=(n.left+n.right)/2?1:0)}}return{node:e,offset:0}}(n,o):!n||s&&1==n.nodeType?{node:e,offset:l}:Oi(n,o)}function _i(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Pi(e,t,n){let o=e.childNodes.length;if(o&&n.top<n.bottom)for(let r=Math.max(0,Math.min(o-1,Math.floor(o*(t.top-n.top)/(n.bottom-n.top))-2)),i=r;;){let n=e.childNodes[i];if(1==n.nodeType){let e=n.getClientRects();for(let o=0;o<e.length;o++){let r=e[o];if(_i(t,r))return Pi(n,t,r)}}if((i=(i+1)%o)==r)break}return e}function Ii(e,t){let n,o=e.dom.ownerDocument,r=0,i=function(e,t,n){if(e.caretPositionFromPoint)try{let o=e.caretPositionFromPoint(t,n);if(o)return{node:o.offsetNode,offset:Math.min(ni(o.offsetNode),o.offset)}}catch(o){}if(e.caretRangeFromPoint){let o=e.caretRangeFromPoint(t,n);if(o)return{node:o.startContainer,offset:Math.min(ni(o.startContainer),o.startOffset)}}}(o,t.left,t.top);i&&({node:n,offset:r}=i);let s,l=(e.root.elementFromPoint?e.root:o).elementFromPoint(t.left,t.top);if(!l||!e.dom.contains(1!=l.nodeType?l.parentNode:l)){let n=e.dom.getBoundingClientRect();if(!_i(t,n))return null;if(l=Pi(e.dom,t,n),!l)return null}if(bi)for(let c=l;n&&c;c=Jr(c))c.draggable&&(n=void 0);if(l=function(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}(l,t),n){if(fi&&1==n.nodeType&&(r=Math.min(r,n.childNodes.length),r<n.childNodes.length)){let e,o=n.childNodes[r];"IMG"==o.nodeName&&(e=o.getBoundingClientRect()).right<=t.left&&e.bottom>t.top&&r++}let o;Ci&&r&&1==n.nodeType&&1==(o=n.childNodes[r-1]).nodeType&&"false"==o.contentEditable&&o.getBoundingClientRect().top>=t.top&&r--,n==e.dom&&r==n.childNodes.length-1&&1==n.lastChild.nodeType&&t.top>n.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:0!=r&&1==n.nodeType&&"BR"==n.childNodes[r-1].nodeName||(s=function(e,t,n,o){let r=-1;for(let i=t,s=!1;i!=e.dom;){let t,n=e.docView.nearestDesc(i,!0);if(!n)return null;if(1==n.dom.nodeType&&(n.node.isBlock&&n.parent||!n.contentDOM)&&((t=n.dom.getBoundingClientRect()).width||t.height)&&(n.node.isBlock&&n.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(n.dom.nodeName)&&(!s&&t.left>o.left||t.top>o.top?r=n.posBefore:(!s&&t.right<o.left||t.bottom<o.top)&&(r=n.posAfter),s=!0),!n.contentDOM&&r<0&&!n.node.isText))return(n.node.isBlock?o.top<(t.top+t.bottom)/2:o.left<(t.left+t.right)/2)?n.posBefore:n.posAfter;i=n.dom.parentNode}return r>-1?r:e.docView.posFromDOM(t,n,-1)}(e,n,r,t))}null==s&&(s=function(e,t,n){let{node:o,offset:r}=Oi(t,n),i=-1;if(1==o.nodeType&&!o.firstChild){let e=o.getBoundingClientRect();i=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(o,r,i)}(e,l,t));let a=e.docView.nearestDesc(l,!0);return{pos:s,inside:a?a.posAtStart-a.border:-1}}function Li(e){return e.top<e.bottom||e.left<e.right}function Di(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(Li(e))return e}return Array.prototype.find.call(n,Li)||e.getBoundingClientRect()}const Bi=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Hi(e,t,n){let{node:o,offset:r,atom:i}=e.docView.domFromPos(t,n<0?-1:1),s=Ci||fi;if(3==o.nodeType){if(!s||!Bi.test(o.nodeValue)&&(n<0?r:r!=o.nodeValue.length)){let e=r,t=r,i=n<0?1:-1;return n<0&&!r?(t++,i=-1):n>=0&&r==o.nodeValue.length?(e--,i=1):n<0?e--:t++,Vi(Di(Yr(o,e,t),i),i<0)}{let e=Di(Yr(o,r,r),n);if(fi&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let t=Di(Yr(o,r-1,r-1),-1);if(t.top==e.top){let n=Di(Yr(o,r,r+1),-1);if(n.top!=e.top)return Vi(n,n.left<t.left)}}return e}}if(!e.state.doc.resolve(t-(i||0)).parent.inlineContent){if(null==i&&r&&(n<0||r==ni(o))){let e=o.childNodes[r-1];if(1==e.nodeType)return $i(e.getBoundingClientRect(),!1)}if(null==i&&r<ni(o)){let e=o.childNodes[r];if(1==e.nodeType)return $i(e.getBoundingClientRect(),!0)}return $i(o.getBoundingClientRect(),n>=0)}if(null==i&&r&&(n<0||r==ni(o))){let e=o.childNodes[r-1],t=3==e.nodeType?Yr(e,ni(e)-(s?0:1)):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return Vi(Di(t,1),!1)}if(null==i&&r<ni(o)){let e=o.childNodes[r];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?Yr(e,0,s?0:1):1==e.nodeType?e:null:null;if(t)return Vi(Di(t,-1),!0)}return Vi(Di(3==o.nodeType?Yr(o):o,-n),n>=0)}function Vi(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function $i(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function zi(e,t,n){let o=e.state,r=e.root.activeElement;o!=t&&e.updateState(t),r!=e.dom&&e.focus();try{return n()}finally{o!=t&&e.updateState(o),r!=e.dom&&r&&r.focus()}}const Fi=/[\u0590-\u08ac]/;let Ui=null,Wi=null,qi=!1;function Gi(e,t,n){return Ui==t&&Wi==n?qi:(Ui=t,Wi=n,qi="up"==n||"down"==n?function(e,t,n){let o=t.selection,r="up"==n?o.$from:o.$to;return zi(e,t,()=>{let{node:t}=e.docView.domFromPos(r.pos,"up"==n?-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 o=Hi(e,r.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=Yr(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let r=t[e];if(r.bottom>r.top+1&&("up"==n?o.top-r.top>2*(r.bottom-o.top):r.bottom-o.bottom>2*(o.bottom-r.top)))return!1}}return!0})}(e,t,n):function(e,t,n){let{$head:o}=t.selection;if(!o.parent.isTextblock)return!1;let r=o.parentOffset,i=!r,s=r==o.parent.content.size,l=e.domSelection();return l?Fi.test(o.parent.textContent)&&l.modify?zi(e,t,()=>{let{focusNode:t,focusOffset:r,anchorNode:i,anchorOffset:s}=e.domSelectionRange(),a=l.caretBidiLevel;l.modify("move",n,"character");let c=o.depth?e.docView.domAfterPos(o.before()):e.dom,{focusNode:d,focusOffset:u}=e.domSelectionRange(),h=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&r==u;try{l.collapse(i,s),t&&(t!=i||r!=s)&&l.extend&&l.extend(t,r)}catch(p){}return null!=a&&(l.caretBidiLevel=a),h}):"left"==n||"backward"==n?i:s:o.pos==o.start()||o.pos==o.end()}(e,t,n))}class Ki{constructor(e,t,n,o){this.parent=e,this.children=t,this.dom=n,this.contentDOM=o,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){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 o=this.children[t];if(o==e)return n;n+=o.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&&this.contentDOM.contains(1==e.nodeType?e:e.parentNode)){if(n<0){let n,o;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.previousSibling;return n?this.posBeforeChild(o)+o.size:this.posAtStart}{let n,o;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.nextSibling;return n?this.posBeforeChild(o):this.posAtEnd}}let o;if(e==this.dom&&this.contentDOM)o=t>Zr(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))o=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!1;break}if(t.previousSibling)break}if(null==o&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!0;break}if(t.nextSibling)break}}return(null==o?n>0:o)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,o=e;o;o=o.parentNode){let r,i=this.getDesc(o);if(i&&(!t||i.node)){if(!n||!(r=i.nodeDOM)||(1==r.nodeType?r.contains(1==e.nodeType?e:e.parentNode):r==e))return i;n=!1}}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let o=e;o;o=o.parentNode){let r=this.getDesc(o);if(r)return r.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let o=this.children[t],r=n+o.size;if(n==e&&r!=n){for(;!o.border&&o.children.length;)for(let e=0;e<o.children.length;e++){let t=o.children[e];if(t.size){o=t;break}}return o}if(e<r)return o.descAt(e-n-o.border);n=r}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,o=0;for(let r=0;n<this.children.length;n++){let t=this.children[n],i=r+t.size;if(i>e||t instanceof ts){o=e-r;break}r=i}if(o)return this.children[n].domFromPos(o-this.children[n].border,t);for(let r;n&&!(r=this.children[n-1]).size&&r instanceof Zi&&r.side>=0;n--);if(t<=0){let e,o=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,o=!1);return e&&t&&o&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Zr(e.dom)+1:0}}{let e,o=!0;for(;e=n<this.children.length?this.children[n]:null,e&&e.dom.parentNode!=this.contentDOM;n++,o=!1);return e&&o&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?Zr(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(0==this.children.length)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let o=-1,r=-1;for(let i=n,s=0;;s++){let n=this.children[s],l=i+n.size;if(-1==o&&e<=l){let r=i+n.border;if(e>=r&&t<=l-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,r);e=i;for(let t=s;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){o=Zr(n.dom)+1;break}e-=n.size}-1==o&&(o=0)}if(o>-1&&(l>t||s==this.children.length-1)){t=l;for(let e=s+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){r=Zr(n.dom);break}t+=n.size}-1==r&&(r=this.contentDOM.childNodes.length);break}i=l}return{node:this.contentDOM,from:e,to:t,fromOffset:o,toOffset:r}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return 0==t.size||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(1!=t.nodeType||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,o=!1){let r=Math.min(e,t),i=Math.max(e,t);for(let p=0,f=0;p<this.children.length;p++){let s=this.children[p],l=f+s.size;if(r>f&&i<l)return s.setSelection(e-f-s.border,t-f-s.border,n,o);f=l}let s=this.domFromPos(e,e?-1:1),l=t==e?s:this.domFromPos(t,t?-1:1),a=n.root.getSelection(),c=n.domSelectionRange(),d=!1;if((fi||bi)&&e==t){let{node:e,offset:t}=s;if(3==e.nodeType){if(d=!(!t||"\n"!=e.nodeValue[t-1]),d&&t==e.nodeValue.length)for(let n,o=e;o;o=o.parentNode){if(n=o.nextSibling){"BR"==n.nodeName&&(s=l={node:n.parentNode,offset:Zr(n)+1});break}let e=o.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(fi&&c.focusNode&&c.focusNode!=l.node&&1==c.focusNode.nodeType){let e=c.focusNode.childNodes[c.focusOffset];e&&"false"==e.contentEditable&&(o=!0)}if(!(o||d&&bi)&&Qr(s.node,s.offset,c.anchorNode,c.anchorOffset)&&Qr(l.node,l.offset,c.focusNode,c.focusOffset))return;let u=!1;if((a.extend||e==t)&&(!d||!fi)){a.collapse(s.node,s.offset);try{e!=t&&a.extend(l.node,l.offset),u=!0}catch(h){}}if(!u){if(e>t){let e=s;s=l,l=e}let n=document.createRange();n.setEnd(l.node,l.offset),n.setStart(s.node,s.offset),a.removeAllRanges(),a.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,o=0;o<this.children.length;o++){let r=this.children[o],i=n+r.size;if(n==i?e<=i&&t>=n:e<i&&t>n){let o=n+r.border,s=i-r.border;if(e>=o&&t<=s)return this.dirty=e==n||t==i?2:1,void(e!=o||t!=s||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(e-o,t-o):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.children.length?3:2}n=i}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Zi extends Ki{constructor(e,t,n,o){let r,i=t.type.toDOM;if("function"==typeof i&&(i=i(n,()=>r?r.parent?r.parent.posBeforeChild(r):void 0:o)),!t.type.spec.raw){if(1!=i.nodeType){let e=document.createElement("span");e.appendChild(i),i=e}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,r=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||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}}class Ji extends Ki{constructor(e,t,n,o){super(e,[],t,null),this.textDOM=n,this.text=o}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class Xi extends Ki{constructor(e,t,n,o,r){super(e,[],n,o),this.mark=t,this.spec=r}static create(e,t,n,o){let r=o.nodeViews[t.type.name],i=r&&r(t,o,n);return i&&i.dom||(i=jo.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new Xi(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=0}}slice(e,t,n){let o=Xi.create(this.parent,this.mark,!0,n),r=this.children,i=this.size;t<i&&(r=ms(r,t,i,n)),e>0&&(r=ms(r,0,e,n));for(let s=0;s<r.length;s++)r[s].parent=o;return o.children=r,o}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Yi extends Ki{constructor(e,t,n,o,r,i,s,l,a){super(e,[],r,i),this.node=t,this.outerDeco=n,this.innerDeco=o,this.nodeDOM=s}static create(e,t,n,o,r,i){let s,l=r.nodeViews[t.type.name],a=l&&l(t,r,()=>s?s.parent?s.parent.posBeforeChild(s):void 0:i,n,o),c=a&&a.dom,d=a&&a.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(t.text);else if(!c){let e=jo.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:d}=e)}d||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return c=ds(c,n,t),a?s=new ns(e,t,n,o,c,d||null,u,a,r,i+1):t.isText?new es(e,t,n,o,c,u,r):new Yi(e,t,n,o,c,d||null,u,r,i+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>Rn.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&us(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,o=t,r=e.composing?this.localCompositionInfo(e,t):null,i=r&&r.pos>-1?r:null,s=r&&r.pos<0,l=new ps(this,i&&i.node,e);!function(e,t,n,o){let r=t.locals(e),i=0;if(0==r.length){for(let n=0;n<e.childCount;n++){let s=e.child(n);o(s,r,t.forChild(i,s),n),i+=s.nodeSize}return}let s=0,l=[],a=null;for(let c=0;;){let d,u,h,p;for(;s<r.length&&r[s].to==i;){let e=r[s++];e.widget&&(d?(u||(u=[d])).push(e):d=e)}if(d)if(u){u.sort(fs);for(let e=0;e<u.length;e++)n(u[e],c,!!a)}else n(d,c,!!a);if(a)p=-1,h=a,a=null;else{if(!(c<e.childCount))break;p=c,h=e.child(c++)}for(let e=0;e<l.length;e++)l[e].to<=i&&l.splice(e--,1);for(;s<r.length&&r[s].from<=i&&r[s].to>i;)l.push(r[s++]);let f=i+h.nodeSize;if(h.isText){let e=f;s<r.length&&r[s].from<e&&(e=r[s].from);for(let t=0;t<l.length;t++)l[t].to<e&&(e=l[t].to);e<f&&(a=h.cut(e-i),h=h.cut(0,e-i),f=e,p=-1)}else for(;s<r.length&&r[s].to<f;)s++;o(h,h.isInline&&!h.isLeaf?l.filter(e=>!e.inline):l.slice(),t.forChild(i,h),p),i=f}}(this.node,this.innerDeco,(t,r,i)=>{t.spec.marks?l.syncToMarks(t.spec.marks,n,e):t.type.side>=0&&!i&&l.syncToMarks(r==this.node.childCount?An.none:this.node.child(r).marks,n,e),l.placeWidget(t,e,o)},(t,i,a,c)=>{let d;l.syncToMarks(t.marks,n,e),l.findNodeMatch(t,i,a,c)||s&&e.state.selection.from>o&&e.state.selection.to<o+t.nodeSize&&(d=l.findIndexWithChild(r.node))>-1&&l.updateNodeAt(t,i,a,d,e)||l.updateNextNode(t,i,a,e,c,o)||l.addNode(t,i,a,e,o),o+=t.nodeSize}),l.syncToMarks([],n,e),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||2==this.dirty)&&(i&&this.protectLocalComposition(e,i),rs(this.contentDOM,this.children,e),vi&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:o}=e.state.selection;if(!(e.state.selection instanceof Nr)||n<t||o>t+this.node.content.size)return null;let r=e.input.compositionNode;if(!r||!this.dom.contains(r.parentNode))return null;if(this.node.inlineContent){let e=r.nodeValue,i=function(e,t,n,o){for(let r=0,i=0;r<e.childCount&&i<=o;){let s=e.child(r++),l=i;if(i+=s.nodeSize,!s.isText)continue;let a=s.text;for(;r<e.childCount;){let t=e.child(r++);if(i+=t.nodeSize,!t.isText)break;a+=t.text}if(i>=n){if(i>=o&&a.slice(o-t.length-l,o-l)==t)return o-t.length;let e=l<o?a.lastIndexOf(t,o-l-1):-1;if(e>=0&&e+t.length+l>=n)return l+e;if(n==o&&a.length>=o+t.length-l&&a.slice(o-l,o-l+t.length)==t)return o}}return-1}(this.node.content,e,n-t,o-t);return i<0?null:{node:r,pos:i,text:e}}return{node:r,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:o}){if(this.getDesc(t))return;let r=t;for(;r.parentNode!=this.contentDOM;r=r.parentNode){for(;r.previousSibling;)r.parentNode.removeChild(r.previousSibling);for(;r.nextSibling;)r.parentNode.removeChild(r.nextSibling);r.pmViewDesc&&(r.pmViewDesc=void 0)}let i=new Ji(this,r,t,o);e.input.compositionNodes.push(i),this.children=ms(this.children,n,n+o.length,e,i)}update(e,t,n,o){return!(3==this.dirty||!e.sameMarkup(this.node))&&(this.updateInner(e,t,n,o),!0)}updateInner(e,t,n,o){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(o,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(us(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=as(this.dom,this.nodeDOM,ls(this.outerDeco,this.node,t),ls(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Qi(e,t,n,o,r){ds(o,t,e);let i=new Yi(void 0,e,t,n,o,o,o,r,0);return i.contentDOM&&i.updateChildren(r,0),i}class es extends Yi{constructor(e,t,n,o,r,i,s){super(e,t,n,o,r,null,i,s,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,o){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!e.sameMarkup(this.node))&&(this.updateOuterDeco(t),0==this.dirty&&e.text==this.node.text||e.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=e.text,o.trackWrites==this.nodeDOM&&(o.trackWrites=null)),this.node=e,this.dirty=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"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let o=this.node.cut(e,t),r=document.createTextNode(o.text);return new es(this.parent,o,this.outerDeco,this.innerDeco,r,r,n)}markDirty(e,t){super.markDirty(e,t),this.dom==this.nodeDOM||0!=e&&t!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}isText(e){return this.node.text==e}}class ts extends Ki{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class ns extends Yi{constructor(e,t,n,o,r,i,s,l,a,c){super(e,t,n,o,r,i,s,a,c),this.spec=l}update(e,t,n,o){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let r=this.spec.update(e,t,n);return r&&this.updateInner(e,t,n,o),r}return!(!this.contentDOM&&!e.isLeaf)&&super.update(e,t,n,o)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,o){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,o)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function rs(e,t,n){let o=e.firstChild,r=!1;for(let i=0;i<t.length;i++){let s=t[i],l=s.dom;if(l.parentNode==e){for(;l!=o;)o=hs(o),r=!0;o=o.nextSibling}else r=!0,e.insertBefore(l,o);if(s instanceof Xi){let t=o?o.previousSibling:e.lastChild;rs(s.contentDOM,s.children,n),o=t?t.nextSibling:e.firstChild}}for(;o;)o=hs(o),r=!0;r&&n.trackWrites==e&&(n.trackWrites=null)}const is=function(e){e&&(this.nodeName=e)};is.prototype=Object.create(null);const ss=[new is];function ls(e,t,n){if(0==e.length)return ss;let o=n?ss[0]:new is,r=[o];for(let i=0;i<e.length;i++){let s=e[i].type.attrs;if(s){s.nodeName&&r.push(o=new is(s.nodeName));for(let e in s){let i=s[e];null!=i&&(n&&1==r.length&&r.push(o=new is(t.isInline?"span":"div")),"class"==e?o.class=(o.class?o.class+" ":"")+i:"style"==e?o.style=(o.style?o.style+";":"")+i:"nodeName"!=e&&(o[e]=i))}}}return r}function as(e,t,n,o){if(n==ss&&o==ss)return t;let r=t;for(let i=0;i<o.length;i++){let t=o[i],s=n[i];if(i){let n;s&&s.nodeName==t.nodeName&&r!=e&&(n=r.parentNode)&&n.nodeName.toLowerCase()==t.nodeName||(n=document.createElement(t.nodeName),n.pmIsDeco=!0,n.appendChild(r),s=ss[0]),r=n}cs(r,s||ss[0],t)}return r}function cs(e,t,n){for(let o in t)"class"==o||"style"==o||"nodeName"==o||o in n||e.removeAttribute(o);for(let o in n)"class"!=o&&"style"!=o&&"nodeName"!=o&&n[o]!=t[o]&&e.setAttribute(o,n[o]);if(t.class!=n.class){let o=t.class?t.class.split(" ").filter(Boolean):[],r=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<o.length;t++)-1==r.indexOf(o[t])&&e.classList.remove(o[t]);for(let t=0;t<r.length;t++)-1==o.indexOf(r[t])&&e.classList.add(r[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n,o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;n=o.exec(t.style);)e.style.removeProperty(n[1])}n.style&&(e.style.cssText+=n.style)}}function ds(e,t,n){return as(e,e,ss,ls(t,n,1!=e.nodeType))}function us(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 hs(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class ps{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=function(e,t){let n=t,o=n.children.length,r=e.childCount,i=new Map,s=[];e:for(;r>0;){let l;for(;;)if(o){let e=n.children[o-1];if(!(e instanceof Xi)){l=e,o--;break}n=e,o=e.children.length}else{if(n==t)break e;o=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=e.child(r-1))break;--r,i.set(l,r),s.push(l)}}return{index:r,matched:i,matches:s.reverse()}}(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){let o=0,r=this.stack.length>>1,i=Math.min(r,e.length);for(;o<i&&(o==r-1?this.top:this.stack[o+1<<1]).matchesMark(e[o])&&!1!==e[o].type.spec.spanning;)o++;for(;o<r;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),r--;for(;r<e.length;){this.stack.push(this.top,this.index+1);let o=-1;for(let t=this.index;t<Math.min(this.index+3,this.top.children.length);t++){let n=this.top.children[t];if(n.matchesMark(e[r])&&!this.isLocked(n.dom)){o=t;break}}if(o>-1)o>this.index&&(this.changed=!0,this.destroyBetween(this.index,o)),this.top=this.top.children[this.index];else{let o=Xi.create(this.top,e[r],t,n);this.top.children.splice(this.index,0,o),this.top=o,this.changed=!0}this.index=0,r++}}findNodeMatch(e,t,n,o){let r,i=-1;if(o>=this.preMatch.index&&(r=this.preMatch.matches[o-this.preMatch.index]).parent==this.top&&r.matchesNode(e,t,n))i=this.top.children.indexOf(r,this.index);else for(let s=this.index,l=Math.min(this.top.children.length,s+5);s<l;s++){let o=this.top.children[s];if(o.matchesNode(e,t,n)&&!this.preMatch.matched.has(o)){i=s;break}}return!(i<0)&&(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,o,r){let i=this.top.children[o];return 3==i.dirty&&i.dom==i.contentDOM&&(i.dirty=2),!!i.update(e,t,n,r)&&(this.destroyBetween(this.index,o),this.index++,!0)}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,o,r,i){for(let s=this.index;s<this.top.children.length;s++){let l=this.top.children[s];if(l instanceof Yi){let a=this.preMatch.matched.get(l);if(null!=a&&a!=r)return!1;let c,d=l.dom,u=this.isLocked(d)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&3!=l.dirty&&us(t,l.outerDeco));if(!u&&l.update(e,t,n,o))return this.destroyBetween(this.index,s),l.dom!=d&&(this.changed=!0),this.index++,!0;if(!u&&(c=this.recreateWrapper(l,e,t,n,o,i)))return this.destroyBetween(this.index,s),this.top.children[this.index]=c,c.contentDOM&&(c.dirty=2,c.updateChildren(o,i+1),c.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,o,r,i){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!us(n,e.outerDeco)||!o.eq(e.innerDeco))return null;let s=Yi.create(this.top,t,n,o,r,i);if(s.contentDOM){s.children=e.children,e.children=[];for(let e of s.children)e.parent=s}return e.destroy(),s}addNode(e,t,n,o,r){let i=Yi.create(this.top,e,t,n,o,r);i.contentDOM&&i.updateChildren(o,r+1),this.top.children.splice(this.index++,0,i),this.changed=!0}placeWidget(e,t,n){let o=this.index<this.top.children.length?this.top.children[this.index]:null;if(!o||!o.matchesWidget(e)||e!=o.widget&&o.widget.type.toDOM.parentNode){let o=new Zi(this.top,e,t,n);this.top.children.splice(this.index++,0,o),this.changed=!0}else this.index++}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Xi;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof es)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((bi||gi)&&e&&"false"==e.dom.contentEditable&&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);"IMG"==e&&(n.className="ProseMirror-separator",n.alt=""),"BR"==e&&(n.className="ProseMirror-trailingBreak");let o=new ts(this.top,[],n,null);t!=this.top?t.children.push(o):t.children.splice(this.index++,0,o),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function fs(e,t){return e.type.side-t.type.side}function ms(e,t,n,o,r){let i=[];for(let s=0,l=0;s<e.length;s++){let a=e[s],c=l,d=l+=a.size;c>=n||d<=t?i.push(a):(c<t&&i.push(a.slice(0,t-c,o)),r&&(i.push(r),r=void 0),d>n&&i.push(a.slice(n-c,a.size,o)))}return i}function gs(e,t=null){let n=e.domSelectionRange(),o=e.state.doc;if(!n.focusNode)return null;let r=e.docView.nearestDesc(n.focusNode),i=r&&0==r.size,s=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l,a,c=o.resolve(s);if(ri(n)){for(l=s;r&&!r.node;)r=r.parent;let e=r.node;if(r&&e.isAtom&&Or.isSelectable(e)&&r.parent&&(!e.isInline||!function(e,t,n){for(let o=0==t,r=t==ni(e);o||r;){if(e==n)return!0;let t=Zr(e);if(!(e=e.parentNode))return!1;o=o&&0==t,r=r&&t==ni(e)}}(n.focusNode,n.focusOffset,r.dom))){let e=r.posBefore;a=new Or(s==e?c:o.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=s,r=s;for(let o=0;o<n.rangeCount;o++){let i=n.getRangeAt(o);t=Math.min(t,e.docView.posFromDOM(i.startContainer,i.startOffset,1)),r=Math.max(r,e.docView.posFromDOM(i.endContainer,i.endOffset,-1))}if(t<0)return null;[l,s]=r==e.state.selection.anchor?[r,t]:[t,r],c=o.resolve(s)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=o.resolve(l);if(!a){a=Ss(e,d,c,"pointer"==t||e.state.selection.head<c.pos&&!i?1:-1)}return a}function ys(e){return e.editable?e.hasFocus():Rs(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function bs(e,t=!1){let n=e.state.selection;if(Cs(e,n),ys(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&gi){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&Qr(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset))return e.input.mouseDown.delayedSelectionSync=!0,void e.domObserver.setCurSelection()}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,o="IMG"==n.nodeName;o?t.collapse(n.parentNode,Zr(n)+1):t.collapse(n,0);!o&&!e.state.selection.visible&&hi&&pi<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let o,r,{anchor:i,head:s}=n;!vs||n instanceof Nr||(n.$from.parent.inlineContent||(o=xs(e,n.from)),n.empty||n.$from.parent.inlineContent||(r=xs(e,n.to))),e.docView.setSelection(i,s,e,t),vs&&(o&&ks(o),r&&ks(r)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(e){let t=e.dom.ownerDocument;t.removeEventListener("selectionchange",e.input.hideSelectionGuard);let n=e.domSelectionRange(),o=n.anchorNode,r=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==o&&n.anchorOffset==r||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{ys(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const vs=bi||gi&&yi<63;function xs(e,t){let{node:n,offset:o}=e.docView.domFromPos(t,0),r=o<n.childNodes.length?n.childNodes[o]:null,i=o?n.childNodes[o-1]:null;if(bi&&r&&"false"==r.contentEditable)return ws(r);if(!(r&&"false"!=r.contentEditable||i&&"false"!=i.contentEditable)){if(r)return ws(r);if(i)return ws(i)}}function ws(e){return e.contentEditable="true",bi&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function ks(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function Cs(e,t){if(t instanceof Or){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(Es(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else Es(e)}function Es(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function Ss(e,t,n,o){return e.someProp("createSelectionBetween",o=>o(e,t,n))||Nr.between(t,n,o)}function Ms(e){return!(e.editable&&!e.hasFocus())&&Rs(e)}function Rs(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(n){return!1}}function Ts(e,t){let{$anchor:n,$head:o}=e.selection,r=t>0?n.max(o):n.min(o),i=r.parent.inlineContent?r.depth?e.doc.resolve(t>0?r.after():r.before()):null:r;return i&&Mr.findFrom(i,t)}function js(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Ns(e,t,n){let o=e.state.selection;if(!(o instanceof Nr)){if(o instanceof Or&&o.node.isInline)return js(e,new Nr(t>0?o.$to:o.$from));{let n=Ts(e.state,t);return!!n&&js(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=o,r=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let i=e.state.doc.resolve(n.pos+r.nodeSize*(t<0?-1:1));return js(e,new Nr(o.$anchor,i))}if(!o.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Ts(e.state,t);return!!(n&&n instanceof Or)&&js(e,n)}if(!(xi&&n.indexOf("m")>-1)){let n,r=o.$head,i=r.textOffset?null:t<0?r.nodeBefore:r.nodeAfter;if(!i||i.isText)return!1;let s=t<0?r.pos-i.nodeSize:r.pos;return!!(i.isAtom||(n=e.docView.descAt(s))&&!n.contentDOM)&&(Or.isSelectable(i)?js(e,new Or(t<0?e.state.doc.resolve(r.pos-i.nodeSize):r)):!!Ci&&js(e,new Nr(e.state.doc.resolve(t<0?s:s+i.nodeSize))))}}function As(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Os(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function _s(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let r,i,s=!1;fi&&1==n.nodeType&&o<As(n)&&Os(n.childNodes[o],-1)&&(s=!0);for(;;)if(o>0){if(1!=n.nodeType)break;{let e=n.childNodes[o-1];if(Os(e,-1))r=n,i=--o;else{if(3!=e.nodeType)break;n=e,o=n.nodeValue.length}}}else{if(Ps(n))break;{let t=n.previousSibling;for(;t&&Os(t,-1);)r=n.parentNode,i=Zr(t),t=t.previousSibling;if(t)n=t,o=As(n);else{if(n=n.parentNode,n==e.dom)break;o=0}}}s?Is(e,n,o):r&&Is(e,r,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let r,i,s=As(n);for(;;)if(o<s){if(1!=n.nodeType)break;if(!Os(n.childNodes[o],1))break;r=n,i=++o}else{if(Ps(n))break;{let t=n.nextSibling;for(;t&&Os(t,1);)r=t.parentNode,i=Zr(t)+1,t=t.nextSibling;if(t)n=t,o=0,s=As(n);else{if(n=n.parentNode,n==e.dom)break;o=s=0}}}r&&Is(e,r,i)}(e)}function Ps(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Is(e,t,n){if(3!=t.nodeType){let e,o;(o=function(e,t){for(;e&&t==e.childNodes.length&&!oi(e);)t=Zr(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=o,n=0):(e=function(e,t){for(;e&&!t&&!oi(e);)t=Zr(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let o=e.domSelection();if(!o)return;if(ri(o)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),o.removeAllRanges(),o.addRange(e)}else o.extend&&o.extend(t,n);e.domObserver.setCurSelection();let{state:r}=e;setTimeout(()=>{e.state==r&&bs(e)},50)}function Ls(e,t){let n=e.state.doc.resolve(t);if(!gi&&!wi&&n.parent.inlineContent){let o=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),r=(n.top+n.bottom)/2;if(r>o.top&&r<o.bottom&&Math.abs(n.left-o.left)>1)return n.left<o.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),r=(n.top+n.bottom)/2;if(r>o.top&&r<o.bottom&&Math.abs(n.left-o.left)>1)return n.left>o.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function Ds(e,t,n){let o=e.state.selection;if(o instanceof Nr&&!o.empty||n.indexOf("s")>-1)return!1;if(xi&&n.indexOf("m")>-1)return!1;let{$from:r,$to:i}=o;if(!r.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Ts(e.state,t);if(n&&n instanceof Or)return js(e,n)}if(!r.parent.inlineContent){let n=t<0?r:i,s=o instanceof Pr?Mr.near(n,t):Mr.findFrom(n,t);return!!s&&js(e,s)}return!1}function Bs(e,t){if(!(e.state.selection instanceof Nr))return!0;let{$head:n,$anchor:o,empty:r}=e.state.selection;if(!n.sameParent(o))return!0;if(!r)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let i=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let o=e.state.tr;return t<0?o.delete(n.pos-i.nodeSize,n.pos):o.delete(n.pos,n.pos+i.nodeSize),e.dispatch(o),!0}return!1}function Hs(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Vs(e,t){let n=t.keyCode,o=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);if(8==n||xi&&72==n&&"c"==o)return Bs(e,-1)||_s(e,-1);if(46==n&&!t.shiftKey||xi&&68==n&&"c"==o)return Bs(e,1)||_s(e,1);if(13==n||27==n)return!0;if(37==n||xi&&66==n&&"c"==o){let t=37==n?"ltr"==Ls(e,e.state.selection.from)?-1:1:-1;return Ns(e,t,o)||_s(e,t)}if(39==n||xi&&70==n&&"c"==o){let t=39==n?"ltr"==Ls(e,e.state.selection.from)?1:-1:1;return Ns(e,t,o)||_s(e,t)}return 38==n||xi&&80==n&&"c"==o?Ds(e,-1,o)||_s(e,-1):40==n||xi&&78==n&&"c"==o?function(e){if(!bi||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;Hs(e,n,"true"),setTimeout(()=>Hs(e,n,"false"),20)}return!1}(e)||Ds(e,1,o)||_s(e,1):o==(xi?"m":"c")&&(66==n||73==n||89==n||90==n)}function $s(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:o,openStart:r,openEnd:i}=t;for(;r>1&&i>1&&1==o.childCount&&1==o.firstChild.childCount;){r--,i--;let e=o.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),o=e.content}let s=e.someProp("clipboardSerializer")||jo.fromSchema(e.state.schema),l=Xs(),a=l.createElement("div");a.appendChild(s.serializeFragment(o,{document:l}));let c,d=a.firstChild,u=0;for(;d&&1==d.nodeType&&(c=Zs[d.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=l.createElement(c[e]);for(;a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t),u++}d=a.firstChild}return d&&1==d.nodeType&&d.setAttribute("data-pm-slice",`${r} ${i}${u?` -${u}`:""} ${JSON.stringify(n)}`),{dom:a,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function zs(e,t,n,o,r){let i,s,l=r.parent.type.spec.code;if(!n&&!t)return null;let a=!!t&&(o||l||!n);if(a){if(e.someProp("transformPastedText",n=>{t=n(t,l||o,e)}),l)return s=new _n(Rn.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{s=t(s,e,!0)}),s;let n=e.someProp("clipboardTextParser",n=>n(t,r,o,e));if(n)s=n;else{let n=r.marks(),{schema:o}=e.state,s=jo.fromSchema(o);i=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=i.appendChild(document.createElement("p"));e&&t.appendChild(s.serializeNode(o.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),i=function(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,o=Xs().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(e);(n=r&&Zs[r[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join(""));if(o.innerHTML=function(e){let t=window.trustedTypes;if(!t)return e;Ys||(Ys=t.defaultPolicy||t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e}));return Ys.createHTML(e)}(e),n)for(let i=0;i<n.length;i++)o=o.querySelector(n[i])||o;return o}(n),Ci&&function(e){let t=e.querySelectorAll(gi?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let o=t[n];1==o.childNodes.length&&" "==o.textContent&&o.parentNode&&o.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),o)}}(i);let c=i&&i.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let u=+d[3];u>0;u--){let e=i.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;i=e}if(!s){let t=e.someProp("clipboardParser")||e.someProp("domParser")||vo.fromSchema(e.state.schema);s=t.parseSlice(i,{preserveWhitespace:!(!a&&!d),context:r,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||Fs.test(e.parentNode.nodeName)?null:{ignore:!0}})}if(d)s=function(e,t){if(!e.size)return e;let n,o=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(l){return e}let{content:r,openStart:i,openEnd:s}=e;for(let a=n.length-2;a>=0;a-=2){let e=o.nodes[n[a]];if(!e||e.hasRequiredAttrs())break;r=Rn.from(e.create(n[a+1],r)),i++,s++}return new _n(r,i,s)}(Ks(s,+d[1],+d[2]),d[4]);else if(s=_n.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let o,r=t.node(n).contentMatchAt(t.index(n)),i=[];if(e.forEach(e=>{if(!i)return;let t,n=r.findWrapping(e.type);if(!n)return i=null;if(t=i.length&&o.length&&Ws(n,o,e,i[i.length-1],0))i[i.length-1]=t;else{i.length&&(i[i.length-1]=qs(i[i.length-1],o.length));let t=Us(e,n);i.push(t),r=r.matchType(t.type),o=n}}),i)return Rn.from(i)}return e}(s.content,r),!0),s.openStart||s.openEnd){let e=0,t=0;for(let n=s.content.firstChild;e<s.openStart&&!n.type.spec.isolating;e++,n=n.firstChild);for(let n=s.content.lastChild;t<s.openEnd&&!n.type.spec.isolating;t++,n=n.lastChild);s=Ks(s,e,t)}return e.someProp("transformPasted",t=>{s=t(s,e,a)}),s}const Fs=/^(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 Us(e,t,n=0){for(let o=t.length-1;o>=n;o--)e=t[o].create(null,Rn.from(e));return e}function Ws(e,t,n,o,r){if(r<e.length&&r<t.length&&e[r]==t[r]){let i=Ws(e,t,n,o.lastChild,r+1);if(i)return o.copy(o.content.replaceChild(o.childCount-1,i));if(o.contentMatchAt(o.childCount).matchType(r==e.length-1?n.type:e[r+1]))return o.copy(o.content.append(Rn.from(Us(n,e,r+1))))}}function qs(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,qs(e.lastChild,t-1)),o=e.contentMatchAt(e.childCount).fillBefore(Rn.empty,!0);return e.copy(n.append(o))}function Gs(e,t,n,o,r,i){let s=t<0?e.firstChild:e.lastChild,l=s.content;return e.childCount>1&&(i=0),r<o-1&&(l=Gs(l,t,n,o,r+1,i)),r>=n&&(l=t<0?s.contentMatchAt(0).fillBefore(l,i<=r).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(Rn.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,s.copy(l))}function Ks(e,t,n){return t<e.openStart&&(e=new _n(Gs(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new _n(Gs(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}const Zs={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let Js=null;function Xs(){return Js||(Js=document.implementation.createHTMLDocument("title"))}let Ys=null;const Qs={},el={},tl={touchstart:!0,touchmove:!0};class nl{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function ol(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function rl(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>il(e,t))})}function il(e,t){return e.someProp("handleDOMEvents",n=>{let o=n[t.type];return!!o&&(o(e,t)||t.defaultPrevented)})}function sl(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||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function ll(e){return{left:e.clientX,top:e.clientY}}function al(e,t,n,o,r){if(-1==o)return!1;let i=e.state.doc.resolve(o);for(let s=i.depth+1;s>0;s--)if(e.someProp(t,t=>s>i.depth?t(e,n,i.nodeAfter,i.before(s),r,!0):t(e,n,i.node(s),i.before(s),r,!1)))return!0;return!1}function cl(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let o=e.state.tr.setSelection(t);o.setMeta("pointer",!0),e.dispatch(o)}function dl(e,t,n,o,r){return al(e,"handleClickOn",t,n,o)||e.someProp("handleClick",n=>n(e,t,o))||(r?function(e,t){if(-1==t)return!1;let n,o,r=e.state.selection;r instanceof Or&&(n=r.node);let i=e.state.doc.resolve(t);for(let s=i.depth+1;s>0;s--){let e=s>i.depth?i.nodeAfter:i.node(s);if(Or.isSelectable(e)){o=n&&r.$from.depth>0&&s>=r.$from.depth&&i.before(r.$from.depth+1)==r.$from.pos?i.before(r.$from.depth):i.before(s);break}}return null!=o&&(cl(e,Or.create(e.state.doc,o)),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),o=n.nodeAfter;return!!(o&&o.isAtom&&Or.isSelectable(o))&&(cl(e,new Or(n)),!0)}(e,n))}function ul(e,t,n,o){return al(e,"handleDoubleClickOn",t,n,o)||e.someProp("handleDoubleClick",n=>n(e,t,o))}function hl(e,t,n,o){return al(e,"handleTripleClickOn",t,n,o)||e.someProp("handleTripleClick",n=>n(e,t,o))||function(e,t,n){if(0!=n.button)return!1;let o=e.state.doc;if(-1==t)return!!o.inlineContent&&(cl(e,Nr.create(o,0,o.content.size)),!0);let r=o.resolve(t);for(let i=r.depth+1;i>0;i--){let t=i>r.depth?r.nodeAfter:r.node(i),n=r.before(i);if(t.inlineContent)cl(e,Nr.create(o,n+1,n+1+t.content.size));else{if(!Or.isSelectable(t))continue;cl(e,Or.create(o,n))}return!0}}(e,n,o)}function pl(e){return wl(e)}el.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!gl(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!ki||!gi||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!vi||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",t=>t(e,n))||Vs(e,n)?n.preventDefault():ol(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",t=>t(e,ii(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},el.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},el.keypress=(e,t)=>{let n=t;if(gl(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||xi&&n.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,n)))return void n.preventDefault();let o=e.state.selection;if(!(o instanceof Nr&&o.$from.sameParent(o.$to))){let t=String.fromCharCode(n.charCode),r=()=>e.state.tr.insertText(t).scrollIntoView();/[\r\n]/.test(t)||e.someProp("handleTextInput",n=>n(e,o.$from.pos,o.$to.pos,t,r))||e.dispatch(r()),n.preventDefault()}};const fl=xi?"metaKey":"ctrlKey";Qs.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let o=pl(e),r=Date.now(),i="singleClick";r-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,o=t.y-e.clientY;return n*n+o*o<100}(n,e.input.lastClick)&&!n[fl]&&e.input.lastClick.button==n.button&&("singleClick"==e.input.lastClick.type?i="doubleClick":"doubleClick"==e.input.lastClick.type&&(i="tripleClick")),e.input.lastClick={time:r,x:n.clientX,y:n.clientY,type:i,button:n.button};let s=e.posAtCoords(ll(n));s&&("singleClick"==i?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new ml(e,s,n,!!o)):("doubleClick"==i?ul:hl)(e,s.pos,s.inside,n)?n.preventDefault():ol(e,"pointer"))};class ml{constructor(e,t,n,o){let r,i;if(this.view=e,this.pos=t,this.event=n,this.flushed=o,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[fl],this.allowDefault=n.shiftKey,t.inside>-1)r=e.state.doc.nodeAt(t.inside),i=t.inside;else{let n=e.state.doc.resolve(t.pos);r=n.parent,i=n.depth?n.before():0}const s=o?null:n.target,l=s?e.docView.nearestDesc(s,!0):null;this.target=l&&1==l.nodeDOM.nodeType?l.nodeDOM:null;let{selection:a}=e.state;(0==n.button&&r.type.spec.draggable&&!1!==r.type.spec.selectable||a instanceof Or&&a.from<=i&&a.to>i)&&(this.mightDrag={node:r,pos:i,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!fi||this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),ol(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>bs(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(ll(e))),this.updateAllowDefault(e),this.allowDefault||!t?ol(this.view,"pointer"):dl(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||bi&&this.mightDrag&&!this.mightDrag.node.isAtom||gi&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(cl(this.view,Mr.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):ol(this.view,"pointer")}move(e){this.updateAllowDefault(e),ol(this.view,"pointer"),0==e.buttons&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}function gl(e,t){return!!e.composing||!!(bi&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}Qs.touchstart=e=>{e.input.lastTouch=Date.now(),pl(e),ol(e,"pointer")},Qs.touchmove=e=>{e.input.lastTouch=Date.now(),ol(e,"pointer")},Qs.contextmenu=e=>pl(e);const yl=ki?5e3:-1;function bl(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>wl(e),t))}function vl(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=function(){let e=document.createEvent("Event");return e.initEvent("event",!0,!0),e.timeStamp}());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function xl(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=ni(e=e.childNodes[t-1])}else{if(!e.parentNode||oi(e))return null;t=Zr(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),o=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||oi(e))return null;t=Zr(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&o&&n!=o){let t=o.pmViewDesc,r=e.domObserver.lastChangedTextNode;if(n==r||o==r)return r;if(!t||!t.isText(o.nodeValue))return o;if(e.input.compositionNode==o){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return o}}return n||o}function wl(e,t=!1){if(!(ki&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),vl(e),t||e.docView&&e.docView.dirty){let n=gs(e),o=e.state.selection;return n&&!n.eq(o)?e.dispatch(e.state.tr.setSelection(n)):!e.markCursor&&!t||o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?e.updateState(e.state):e.dispatch(e.state.tr.deleteSelection()),!0}return!1}}el.compositionstart=el.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof Nr&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)))e.markCursor=e.state.storedMarks||n.marks(),wl(e,!0),e.markCursor=null;else if(wl(e,!t.selection.empty),fi&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,o=t.focusOffset;n&&1==n.nodeType&&0!=o;){let t=o<0?n.lastChild:n.childNodes[o-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,o=-1}}e.input.composing=!0}bl(e,yl)},el.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,bl(e,20))};const kl=hi&&pi<15||vi&&Ei<604;function Cl(e,t,n,o,r){let i=zs(e,t,n,o,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,r,i||_n.empty)))return!0;if(!i)return!1;let s=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(i),l=s?e.state.tr.replaceSelectionWith(s,o):e.state.tr.replaceSelection(i);return e.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function El(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," "):""}Qs.copy=el.cut=(e,t)=>{let n=t,o=e.state.selection,r="cut"==n.type;if(o.empty)return;let i=kl?null:n.clipboardData,s=o.content(),{dom:l,text:a}=$s(e,s);i?(n.preventDefault(),i.clearData(),i.setData("text/html",l.innerHTML),i.setData("text/plain",a)):function(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 o=getSelection(),r=document.createRange();r.selectNodeContents(t),e.dom.blur(),o.removeAllRanges(),o.addRange(r),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,l),r&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},el.paste=(e,t)=>{let n=t;if(e.composing&&!ki)return;let o=kl?null:n.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;o&&Cl(e,El(o),o.getData("text/html"),r,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,o=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(o.contentEditable="true"),o.style.cssText="position: fixed; left: -10000px; top: 10px",o.focus();let r=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),o.parentNode&&o.parentNode.removeChild(o),n?Cl(e,o.value,null,r,t):Cl(e,o.textContent,o.innerHTML,r,t)},50)}(e,n)};class Sl{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const Ml=xi?"altKey":"ctrlKey";function Rl(e,t){let n=e.someProp("dragCopies",e=>!e(t));return null!=n?n:!t[Ml]}Qs.dragstart=(e,t)=>{let n=t,o=e.input.mouseDown;if(o&&o.done(),!n.dataTransfer)return;let r,i=e.state.selection,s=i.empty?null:e.posAtCoords(ll(n));if(s&&s.pos>=i.from&&s.pos<=(i instanceof Or?i.to-1:i.to));else if(o&&o.mightDrag)r=Or.create(e.state.doc,o.mightDrag.pos);else if(n.target&&1==n.target.nodeType){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(r=Or.create(e.state.doc,t.posBefore))}let l=(r||e.state.selection).content(),{dom:a,text:c,slice:d}=$s(e,l);(!n.dataTransfer.files.length||!gi||yi>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(kl?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",kl||n.dataTransfer.setData("text/plain",c),e.dragging=new Sl(d,Rl(e,n),r)},Qs.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},el.dragover=el.dragenter=(e,t)=>t.preventDefault(),el.drop=(e,t)=>{let n=t,o=e.dragging;if(e.dragging=null,!n.dataTransfer)return;let r=e.posAtCoords(ll(n));if(!r)return;let i=e.state.doc.resolve(r.pos),s=o&&o.slice;s?e.someProp("transformPasted",t=>{s=t(s,e,!1)}):s=zs(e,El(n.dataTransfer),kl?null:n.dataTransfer.getData("text/html"),!1,i);let l=!(!o||!Rl(e,n));if(e.someProp("handleDrop",t=>t(e,n,s||_n.empty,l)))return void n.preventDefault();if(!s)return;n.preventDefault();let a=s?cr(e.state.doc,i.pos,s):i.pos;null==a&&(a=i.pos);let c=e.state.tr;if(l){let{node:e}=o;e?e.replace(c):c.deleteSelection()}let d=c.mapping.map(a),u=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,h=c.doc;if(u?c.replaceRangeWith(d,d,s.content.firstChild):c.replaceRange(d,d,s),c.doc.eq(h))return;let p=c.doc.resolve(d);if(u&&Or.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new Or(p));else{let t=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,o,r)=>t=r),c.setSelection(Ss(e,p,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta("uiEvent","drop"))},Qs.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&bs(e)},20))},Qs.blur=(e,t)=>{let n=t;e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},Qs.beforeinput=(e,t)=>{if(gi&&ki&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t)return;if(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,ii(8,"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 os in el)Qs[os]=el[os];function Tl(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}class jl{constructor(e,t){this.toDOM=e,this.spec=t||Pl,this.side=this.spec.side||0}map(e,t,n,o){let{pos:r,deleted:i}=e.mapResult(t.from+o,this.side<0?-1:1);return i?null:new Ol(r-n,r-n,this)}valid(){return!0}eq(e){return this==e||e instanceof jl&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Tl(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Nl{constructor(e,t){this.attrs=e,this.spec=t||Pl}map(e,t,n,o){let r=e.map(t.from+o,this.spec.inclusiveStart?-1:1)-n,i=e.map(t.to+o,this.spec.inclusiveEnd?1:-1)-n;return r>=i?null:new Ol(r,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Nl&&Tl(this.attrs,e.attrs)&&Tl(this.spec,e.spec)}static is(e){return e.type instanceof Nl}destroy(){}}class Al{constructor(e,t){this.attrs=e,this.spec=t||Pl}map(e,t,n,o){let r=e.mapResult(t.from+o,1);if(r.deleted)return null;let i=e.mapResult(t.to+o,-1);return i.deleted||i.pos<=r.pos?null:new Ol(r.pos-n,i.pos-n,this)}valid(e,t){let n,{index:o,offset:r}=e.content.findIndex(t.from);return r==t.from&&!(n=e.child(o)).isText&&r+n.nodeSize==t.to}eq(e){return this==e||e instanceof Al&&Tl(this.attrs,e.attrs)&&Tl(this.spec,e.spec)}destroy(){}}class Ol{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new Ol(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new Ol(e,e,new jl(t,n))}static inline(e,t,n,o){return new Ol(e,t,new Nl(n,o))}static node(e,t,n,o){return new Ol(e,t,new Al(n,o))}get spec(){return this.type.spec}get inline(){return this.type instanceof Nl}get widget(){return this.type instanceof jl}}const _l=[],Pl={};class Il{constructor(e,t){this.local=e.length?e:_l,this.children=t.length?t:_l}static create(e,t){return t.length?$l(t,e,0,Pl):Ll}find(e,t,n){let o=[];return this.findInner(null==e?0:e,null==t?1e9:t,o,0,n),o}findInner(e,t,n,o,r){for(let i=0;i<this.local.length;i++){let s=this.local[i];s.from<=t&&s.to>=e&&(!r||r(s.spec))&&n.push(s.copy(s.from+o,s.to+o))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let s=this.children[i]+1;this.children[i+2].findInner(e-s,t-s,n,o+s,r)}}map(e,t,n){return this==Ll||0==e.maps.length?this:this.mapInner(e,t,0,0,n||Pl)}mapInner(e,t,n,o,r){let i;for(let s=0;s<this.local.length;s++){let l=this.local[s].map(e,n,o);l&&l.type.valid(t,l)?(i||(i=[])).push(l):r.onRemove&&r.onRemove(this.local[s].spec)}return this.children.length?function(e,t,n,o,r,i,s){let l=e.slice();for(let c=0,d=i;c<n.maps.length;c++){let e=0;n.maps[c].forEach((t,n,o,r)=>{let i=r-o-(n-t);for(let s=0;s<l.length;s+=3){let o=l[s+1];if(o<0||t>o+d-e)continue;let r=l[s]+d-e;n>=r?l[s+1]=t<=r?-2:-1:t>=d&&i&&(l[s]+=i,l[s+1]+=i)}e+=i}),d=n.maps[c].map(d,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(-2==l[c+1]){a=!0,l[c+1]=-1;continue}let t=n.map(e[c]+i),d=t-r;if(d<0||d>=o.content.size){a=!0;continue}let u=n.map(e[c+1]+i,-1)-r,{index:h,offset:p}=o.content.findIndex(d),f=o.maybeChild(h);if(f&&p==d&&p+f.nodeSize==u){let o=l[c+2].mapInner(n,f,t+1,e[c]+i+1,s);o!=Ll?(l[c]=d,l[c+1]=u,l[c+2]=o):(l[c+1]=-2,a=!0)}else a=!0}if(a){let a=function(e,t,n,o,r,i,s){function l(e,t){for(let i=0;i<e.local.length;i++){let l=e.local[i].map(o,r,t);l?n.push(l):s.onRemove&&s.onRemove(e.local[i].spec)}for(let n=0;n<e.children.length;n+=3)l(e.children[n+2],e.children[n]+t+1)}for(let a=0;a<e.length;a+=3)-1==e[a+1]&&l(e[a+2],t[a]+i+1);return n}(l,e,t,n,r,i,s),c=$l(a,o,0,s);t=c.local;for(let e=0;e<l.length;e+=3)l[e+1]<0&&(l.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<l.length&&l[t]<n;)t+=3;l.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new Il(t.sort(zl),l)}(this.children,i||[],e,t,n,o,r):i?new Il(i.sort(zl),_l):Ll}add(e,t){return t.length?this==Ll?Il.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let o,r=0;e.forEach((e,i)=>{let s,l=i+n;if(s=Hl(t,e,l)){for(o||(o=this.children.slice());r<o.length&&o[r]<i;)r+=3;o[r]==i?o[r+2]=o[r+2].addInner(e,s,l+1):o.splice(r,0,i,i+e.nodeSize,$l(s,e,l+1,Pl)),r+=3}});let i=Bl(r?Vl(t):t,-n);for(let s=0;s<i.length;s++)i[s].type.valid(e,i[s])||i.splice(s--,1);return new Il(i.length?this.local.concat(i).sort(zl):this.local,o||this.children)}remove(e){return 0==e.length||this==Ll?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,o=this.local;for(let r=0;r<n.length;r+=3){let o,i=n[r]+t,s=n[r+1]+t;for(let t,n=0;n<e.length;n++)(t=e[n])&&t.from>i&&t.to<s&&(e[n]=null,(o||(o=[])).push(t));if(!o)continue;n==this.children&&(n=this.children.slice());let l=n[r+2].removeInner(o,i+1);l!=Ll?n[r+2]=l:(n.splice(r,3),r-=3)}if(o.length)for(let r,i=0;i<e.length;i++)if(r=e[i])for(let e=0;e<o.length;e++)o[e].eq(r,t)&&(o==this.local&&(o=this.local.slice()),o.splice(e--,1));return n==this.children&&o==this.local?this:o.length||n.length?new Il(o,n):Ll}forChild(e,t){if(this==Ll)return this;if(t.isLeaf)return Il.empty;let n,o;for(let s=0;s<this.children.length;s+=3)if(this.children[s]>=e){this.children[s]==e&&(n=this.children[s+2]);break}let r=e+1,i=r+t.content.size;for(let s=0;s<this.local.length;s++){let e=this.local[s];if(e.from<i&&e.to>r&&e.type instanceof Nl){let t=Math.max(r,e.from)-r,n=Math.min(i,e.to)-r;t<n&&(o||(o=[])).push(e.copy(t,n))}}if(o){let e=new Il(o.sort(zl),_l);return n?new Dl([e,n]):e}return n||Ll}eq(e){if(this==e)return!0;if(!(e instanceof Il)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return Fl(this.localsInner(e))}localsInner(e){if(this==Ll)return _l;if(e.inlineContent||!this.local.some(Nl.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Nl||t.push(this.local[n]);return t}forEachSet(e){e(this)}}Il.empty=new Il([],[]),Il.removeOverlap=Fl;const Ll=Il.empty;class Dl{constructor(e){this.members=e}map(e,t){const n=this.members.map(n=>n.map(e,t,Pl));return Dl.from(n)}forChild(e,t){if(t.isLeaf)return Il.empty;let n=[];for(let o=0;o<this.members.length;o++){let r=this.members[o].forChild(e,t);r!=Ll&&(r instanceof Dl?n=n.concat(r.members):n.push(r))}return Dl.from(n)}eq(e){if(!(e instanceof Dl)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let o=0;o<this.members.length;o++){let r=this.members[o].localsInner(e);if(r.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<r.length;e++)t.push(r[e])}else t=r}return t?Fl(n?t:t.sort(zl)):_l}static from(e){switch(e.length){case 0:return Ll;case 1:return e[0];default:return new Dl(e.every(e=>e instanceof Il)?e:e.reduce((e,t)=>e.concat(t instanceof Il?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function Bl(e,t){if(!t||!e.length)return e;let n=[];for(let o=0;o<e.length;o++){let r=e[o];n.push(new Ol(r.from+t,r.to+t,r.type))}return n}function Hl(e,t,n){if(t.isLeaf)return null;let o=n+t.nodeSize,r=null;for(let i,s=0;s<e.length;s++)(i=e[s])&&i.from>n&&i.to<o&&((r||(r=[])).push(i),e[s]=null);return r}function Vl(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function $l(e,t,n,o){let r=[],i=!1;t.forEach((t,s)=>{let l=Hl(e,t,s+n);if(l){i=!0;let e=$l(l,t,n+s+1,o);e!=Ll&&r.push(s,s+t.nodeSize,e)}});let s=Bl(i?Vl(e):e,-n).sort(zl);for(let l=0;l<s.length;l++)s[l].type.valid(t,s[l])||(o.onRemove&&o.onRemove(s[l].spec),s.splice(l--,1));return s.length||r.length?new Il(s,r):Ll}function zl(e,t){return e.from-t.from||e.to-t.to}function Fl(e){let t=e;for(let n=0;n<t.length-1;n++){let o=t[n];if(o.from!=o.to)for(let r=n+1;r<t.length;r++){let i=t[r];if(i.from!=o.from){i.from<o.to&&(t==e&&(t=e.slice()),t[n]=o.copy(o.from,i.from),Ul(t,r,o.copy(i.from,o.to)));break}i.to!=o.to&&(t==e&&(t=e.slice()),t[r]=i.copy(i.from,o.to),Ul(t,r+1,i.copy(o.to,i.to)))}}return t}function Ul(e,t,n){for(;t<e.length&&zl(n,e[t])>0;)t++;e.splice(t,0,n)}function Wl(e){let t=[];return e.someProp("decorations",n=>{let o=n(e.state);o&&o!=Ll&&t.push(o)}),e.cursorWrapper&&t.push(Il.create(e.state.doc,[e.cursorWrapper.deco])),Dl.from(t)}const ql={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Gl=hi&&pi<=11;class Kl{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class Zl{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Kl,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);hi&&pi<=11&&e.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),Gl&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,ql)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Ms(this.view)){if(this.suppressingSelectionUpdates)return bs(this.view);if(hi&&pi<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Qr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t,n=new Set;for(let r=e.focusNode;r;r=Jr(r))n.add(r);for(let r=e.anchorNode;r;r=Jr(r))if(n.has(r)){t=r;break}let o=t&&this.view.docView.nearestDesc(t);return o&&o.ignoreMutation({type:"selection",target:3==t.nodeType?t.parentNode:t})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),o=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Ms(e)&&!this.ignoreSelectionChange(n),r=-1,i=-1,s=!1,l=[];if(e.editable)for(let c=0;c<t.length;c++){let e=this.registerMutation(t[c],l);e&&(r=r<0?e.from:Math.min(e.from,r),i=i<0?e.to:Math.max(e.to,i),e.typeOver&&(s=!0))}if(fi&&l.length){let t=l.filter(e=>"BR"==e.nodeName);if(2==t.length){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let o of t){let t=o.parentNode;!t||"LI"!=t.nodeName||n&&Ql(e,n)==t||o.remove()}}}let a=null;r<0&&o&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&ri(n)&&(a=gs(e))&&a.eq(Mr.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,bs(e),this.currentSelection.set(n),e.scrollToSelection()):(r>-1||o)&&(r>-1&&(e.docView.markDirty(r,i),function(e){if(Jl.has(e))return;if(Jl.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace)){if(e.requiresGeckoHackNode=fi,Xl)return;Xl=!0}}(e)),this.handleDOMChange(r,i,s,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||bs(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style")))return null;if(!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;n<e.addedNodes.length;n++){let o=e.addedNodes[n];t.push(o),3==o.nodeType&&(this.lastChangedTextNode=o)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let o=e.previousSibling,r=e.nextSibling;if(hi&&pi<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:i}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(o=n),(!i||Array.prototype.indexOf.call(e.addedNodes,i)<0)&&(r=i)}let i=o&&o.parentNode==e.target?Zr(o)+1:0,s=n.localPosFromDOM(e.target,i,-1),l=r&&r.parentNode==e.target?Zr(r):e.target.childNodes.length;return{from:s,to:n.localPosFromDOM(e.target,l,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let Jl=new WeakMap,Xl=!1;function Yl(e,t){let n=t.startContainer,o=t.startOffset,r=t.endContainer,i=t.endOffset,s=e.domAtPos(e.state.selection.anchor);return Qr(s.node,s.offset,r,i)&&([n,o,r,i]=[r,i,n,o]),{anchorNode:n,anchorOffset:o,focusNode:r,focusOffset:i}}function Ql(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 ea(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(bi&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement("div");return e.appendChild(document.createElement("li")),{skip:e}}if(e.parentNode.lastChild==e||bi&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if("IMG"==e.nodeName&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null}const ta=/^(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 na(e,t,n,o,r){let i=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=gs(e,t);if(n&&!e.state.selection.eq(n)){if(gi&&ki&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,ii(13,"Enter"))))return;let o=e.state.tr.setSelection(n);"pointer"==t?o.setMeta("pointer",!0):"key"==t&&o.scrollIntoView(),i&&o.setMeta("composition",i),e.dispatch(o)}return}let s=e.state.doc.resolve(t),l=s.sharedDepth(n);t=s.before(l+1),n=e.state.doc.resolve(n).after(l+1);let a,c,d=e.state.selection,u=function(e,t,n){let o,{node:r,fromOffset:i,toOffset:s,from:l,to:a}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(o=[{node:d,offset:c.anchorOffset}],ri(c)||o.push({node:c.focusNode,offset:c.focusOffset})),gi&&8===e.input.lastKeyCode)for(let g=s;g>i;g--){let e=r.childNodes[g-1],t=e.pmViewDesc;if("BR"==e.nodeName&&!t){s=g;break}if(!t||t.size)break}let u=e.state.doc,h=e.someProp("domParser")||vo.fromSchema(e.state.schema),p=u.resolve(l),f=null,m=h.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:s,preserveWhitespace:"pre"!=p.parent.type.whitespace||"full",findPositions:o,ruleFromNode:ea,context:p});if(o&&null!=o[0].pos){let e=o[0].pos,t=o[1]&&o[1].pos;null==t&&(t=e),f={anchor:e+l,head:t+l}}return{doc:m,sel:f,from:l,to:a}}(e,t,n),h=e.state.doc,p=h.slice(u.from,u.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(a=e.state.selection.to,c="end"):(a=e.state.selection.from,c="start"),e.input.lastKeyCode=null;let f=function(e,t,n,o,r){let i=e.findDiffStart(t,n);if(null==i)return null;let{a:s,b:l}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==r){o-=s+Math.max(0,i-Math.min(s,l))-i}if(s<i&&e.size<t.size){let e=o<=i&&o>=s?i-o:0;i-=e,i&&i<t.size&&ia(t.textBetween(i-1,i+1))&&(i+=e?1:-1),l=i+(l-s),s=i}else if(l<i){let t=o<=i&&o>=l?i-o:0;i-=t,i&&i<e.size&&ia(e.textBetween(i-1,i+1))&&(i+=t?1:-1),s=i+(s-l),l=i}return{start:i,endA:s,endB:l}}(p.content,u.doc.content,u.from,a,c);if(f&&e.input.domChangeCount++,(vi&&e.input.lastIOSEnter>Date.now()-225||ki)&&r.some(e=>1==e.nodeType&&!ta.test(e.nodeName))&&(!f||f.endA>=f.endB)&&e.someProp("handleKeyDown",t=>t(e,ii(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(!f){if(!(o&&d instanceof Nr&&!d.empty&&d.$head.sameParent(d.$anchor))||e.composing||u.sel&&u.sel.anchor!=u.sel.head){if(u.sel){let t=oa(e,e.state.doc,u.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);i&&n.setMeta("composition",i),e.dispatch(n)}}return}f={start:d.from,endA:d.to,endB:d.to}}e.state.selection.from<e.state.selection.to&&f.start==f.endB&&e.state.selection instanceof Nr&&(f.start>e.state.selection.from&&f.start<=e.state.selection.from+2&&e.state.selection.from>=u.from?f.start=e.state.selection.from:f.endA<e.state.selection.to&&f.endA>=e.state.selection.to-2&&e.state.selection.to<=u.to&&(f.endB+=e.state.selection.to-f.endA,f.endA=e.state.selection.to)),hi&&pi<=11&&f.endB==f.start+1&&f.endA==f.start&&f.start>u.from&&"  "==u.doc.textBetween(f.start-u.from-1,f.start-u.from+1)&&(f.start--,f.endA--,f.endB--);let m=u.doc.resolveNoCache(f.start-u.from),g=u.doc.resolveNoCache(f.endB-u.from),y=h.resolve(f.start),b=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=f.endA;if((vi&&e.input.lastIOSEnter>Date.now()-225&&(!b||r.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!b&&m.pos<u.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&m.pos<g.pos&&!/\S/.test(u.doc.textBetween(m.pos,g.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,ii(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(e.state.selection.anchor>f.start&&function(e,t,n,o,r){if(n-t<=r.pos-o.pos||ra(o,!0,!1)<r.pos)return!1;let i=e.resolve(t);if(!o.parent.isTextblock){let e=i.nodeAfter;return null!=e&&n==t+e.nodeSize}if(i.parentOffset<i.parent.content.size||!i.parent.isTextblock)return!1;let s=e.resolve(ra(i,!0,!0));return!(!s.parent.isTextblock||s.pos>n||ra(s,!0,!1)<n)&&o.parent.content.cut(o.parentOffset).eq(s.parent.content)}(h,f.start,f.endA,m,g)&&e.someProp("handleKeyDown",t=>t(e,ii(8,"Backspace"))))return void(ki&&gi&&e.domObserver.suppressSelectionUpdates());gi&&f.endB==f.start&&(e.input.lastChromeDelete=Date.now()),ki&&!b&&m.start()!=g.start()&&0==g.parentOffset&&m.depth==g.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==f.endA&&(f.endB-=2,g=u.doc.resolveNoCache(f.endB-u.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,ii(13,"Enter"))})},20));let v,x=f.start,w=f.endA,k=t=>{let n=t||e.state.tr.replace(x,w,u.doc.slice(f.start-u.from,f.endB-u.from));if(u.sel){let t=oa(e,n.doc,u.sel);t&&!(gi&&e.composing&&t.empty&&(f.start!=f.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==x||t.head==n.mapping.map(w)-1)||hi&&t.empty&&t.head==x)&&n.setSelection(t)}return i&&n.setMeta("composition",i),n.scrollIntoView()};if(b)if(m.pos==g.pos){hi&&pi<=11&&0==m.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>bs(e),20));let t=k(e.state.tr.delete(x,w)),n=h.resolve(f.start).marksAcross(h.resolve(f.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(f.endA==f.endB&&(v=function(e,t){let n,o,r,i=e.firstChild.marks,s=t.firstChild.marks,l=i,a=s;for(let d=0;d<s.length;d++)l=s[d].removeFromSet(l);for(let d=0;d<i.length;d++)a=i[d].removeFromSet(a);if(1==l.length&&0==a.length)o=l[0],n="add",r=e=>e.mark(o.addToSet(e.marks));else{if(0!=l.length||1!=a.length)return null;o=a[0],n="remove",r=e=>e.mark(o.removeFromSet(e.marks))}let c=[];for(let d=0;d<t.childCount;d++)c.push(r(t.child(d)));if(Rn.from(c).eq(e))return{mark:o,type:n}}(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,f.endA-y.start())))){let t=k(e.state.tr);"add"==v.type?t.addMark(x,w,v.mark):t.removeMark(x,w,v.mark),e.dispatch(t)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let t=m.parent.textBetween(m.parentOffset,g.parentOffset),n=()=>k(e.state.tr.insertText(t,x,w));e.someProp("handleTextInput",o=>o(e,x,w,t,n))||e.dispatch(n())}else e.dispatch(k());else e.dispatch(k())}function oa(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:Ss(e,t.resolve(n.anchor),t.resolve(n.head))}function ra(e,t,n){let o=e.depth,r=t?e.end():e.pos;for(;o>0&&(t||e.indexAfter(o)==e.node(o).childCount);)o--,r++,t=!1;if(n){let t=e.node(o).maybeChild(e.indexAfter(o));for(;t&&!t.isLeaf;)t=t.firstChild,r++}return r}function ia(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}class sa{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 nl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ua),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=ca(this),aa(this),this.nodeViews=da(this),this.docView=Qi(this.state.doc,la(this),Wl(this),this.dom,this),this.domObserver=new Zl(this,(e,t,n,o)=>na(this,e,t,n,o)),this.domObserver.start(),function(e){for(let t in Qs){let n=Qs[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!sl(e,t)||il(e,t)||!e.editable&&t.type in el||n(e,t)},tl[t]?{passive:!0}:void 0)}bi&&e.dom.addEventListener("input",()=>null),rl(e)}(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&&rl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ua),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let o=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(vl(this),i=!0),this.state=e;let s=o.plugins!=e.plugins||this._props.plugins!=t.plugins;if(s||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=da(this);(function(e,t){let n=0,o=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let r in t)o++;return n!=o})(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(s||t.handleDOMEvents!=this._props.handleDOMEvents)&&rl(this),this.editable=ca(this),aa(this);let l=Wl(this),a=la(this),c=o.plugins==e.plugins||o.doc.eq(e.doc)?e.scrollToSelection>o.scrollToSelection?"to selection":"preserve":"reset",d=r||!this.docView.matchesNode(e.doc,a,l);!d&&e.selection.eq(o.selection)||(i=!0);let u="preserve"==c&&i&&null==this.dom.style.overflowAnchor&&function(e){let t,n,o=e.dom.getBoundingClientRect(),r=Math.max(0,o.top);for(let i=(o.left+o.right)/2,s=r+1;s<Math.min(innerHeight,o.bottom);s+=5){let o=e.root.elementFromPoint(i,s);if(!o||o==e.dom||!e.dom.contains(o))continue;let l=o.getBoundingClientRect();if(l.top>=r-20){t=o,n=l.top;break}}return{refDOM:t,refTop:n,stack:ji(e.dom)}}(this);if(i){this.domObserver.stop();let t=d&&(hi||gi)&&!this.composing&&!o.selection.empty&&!e.selection.empty&&function(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)}(o.selection,e.selection);if(d){let n=gi?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=xl(this)),!r&&this.docView.update(e.doc,a,l,this)||(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Qi(e.doc,a,l,this.dom,this)),n&&!this.trackWrites&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return Qr(t.node,t.offset,n.anchorNode,n.anchorOffset)}(this))?bs(this,t):(Cs(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(o),(null===(n=this.dragging)||void 0===n?void 0:n.node)&&!o.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,o),"reset"==c?this.dom.scrollTop=0:"to selection"==c?this.scrollToSelection():u&&function({refDOM:e,refTop:t,stack:n}){let o=e?e.getBoundingClientRect().top:0;Ni(n,0==o?0:o-t)}(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&this.dom.contains(1==e.nodeType?e:e.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof Or){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&Ti(this,t.getBoundingClientRect(),e)}else Ti(this,this.coordsAtPos(this.state.selection.head,1),e);else;}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)for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}else{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))}}}updateDraggedNode(e,t){let n=e.node,o=-1;if(this.state.doc.nodeAt(n.from)==n.node)o=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&this.state.doc.nodeAt(e))==n.node&&(o=e)}this.dragging=new Sl(e.slice,e.move,o<0?void 0:Or.create(this.state.doc,o))}someProp(e,t){let n,o=this._props&&this._props[e];if(null!=o&&(n=t?t(o):o))return n;for(let i=0;i<this.directPlugins.length;i++){let o=this.directPlugins[i].props[e];if(null!=o&&(n=t?t(o):o))return n}let r=this.state.plugins;if(r)for(let i=0;i<r.length;i++){let o=r[i].props[e];if(null!=o&&(n=t?t(o):o))return n}}hasFocus(){if(hi){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if("false"==e.contentEditable)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(e){if(e.setActive)return e.setActive();if(Ai)return e.focus(Ai);let t=ji(e);e.focus(null==Ai?{get preventScroll(){return Ai={preventScroll:!0},!0}}:void 0),Ai||(Ai=!1,Ni(t,0))}(this.dom),bs(this),this.domObserver.start()}get root(){let e=this._root;if(null==e)for(let t=this.dom.parentNode;t;t=t.parentNode)if(9==t.nodeType||11==t.nodeType&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t;return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ii(this,e)}coordsAtPos(e,t=1){return Hi(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 o=this.docView.posFromDOM(e,t,n);if(null==o)throw new RangeError("DOM position not inside the editor");return o}endOfTextblock(e,t){return Gi(this,t||this.state,e)}pasteHTML(e,t){return Cl(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Cl(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return $s(this,e)}destroy(){this.docView&&(!function(e){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)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Wl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Xr=null)}get isDestroyed(){return null==this.docView}dispatchEvent(e){return function(e,t){il(e,t)||!Qs[t.type]||!e.editable&&t.type in el||Qs[t.type](e,t)}(this,e)}domSelectionRange(){let e=this.domSelection();return e?bi&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Yl(e,n)}let n;function o(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",o,!0),n?Yl(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function la(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),e.someProp("attributes",n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e?t.class+=" "+n[e]:"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))}),t.translate||(t.translate="no"),[Ol.node(0,e.state.doc.content.size,t)]}function aa(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:Ol.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function ca(e){return!e.someProp("editable",t=>!1===t(e.state))}function da(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 ua(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}sa.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var ha={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:"'"},pa={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},fa="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),ma="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ga=0;ga<10;ga++)ha[48+ga]=ha[96+ga]=String(ga);for(ga=1;ga<=24;ga++)ha[ga+111]="F"+ga;for(ga=65;ga<=90;ga++)ha[ga]=String.fromCharCode(ga+32),pa[ga]=String.fromCharCode(ga);for(var ya in ha)pa.hasOwnProperty(ya)||(pa[ya]=ha[ya]);const ba="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),va="undefined"!=typeof navigator&&/Win/.test(navigator.platform);function xa(e){let t,n,o,r,i=e.split(/-(?!$)/),s=i[i.length-1];"Space"==s&&(s=" ");for(let l=0;l<i.length-1;l++){let e=i[l];if(/^(cmd|meta|m)$/i.test(e))r=!0;else if(/^a(lt)?$/i.test(e))t=!0;else if(/^(c|ctrl|control)$/i.test(e))n=!0;else if(/^s(hift)?$/i.test(e))o=!0;else{if(!/^mod$/i.test(e))throw new Error("Unrecognized modifier name: "+e);ba?r=!0:n=!0}}return t&&(s="Alt-"+s),n&&(s="Ctrl-"+s),r&&(s="Meta-"+s),o&&(s="Shift-"+s),s}function wa(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 ka(e){let t=function(e){let t=Object.create(null);for(let n in e)t[xa(n)]=e[n];return t}(e);return function(e,n){let o,r=function(e){var t=!(fa&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||ma&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?pa:ha)[e.keyCode]||e.key||"Unidentified";return"Esc"==t&&(t="Escape"),"Del"==t&&(t="Delete"),"Left"==t&&(t="ArrowLeft"),"Up"==t&&(t="ArrowUp"),"Right"==t&&(t="ArrowRight"),"Down"==t&&(t="ArrowDown"),t}(n),i=t[wa(r,n)];if(i&&i(e.state,e.dispatch,e))return!0;if(1==r.length&&" "!=r){if(n.shiftKey){let o=t[wa(r,n,!1)];if(o&&o(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(va&&n.ctrlKey&&n.altKey)&&(o=ha[n.keyCode])&&o!=r){let r=t[wa(o,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}const Ca=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Ea(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("backward",e):n.parentOffset>0)?null:n}const Sa=(e,t,n)=>{let o=Ea(e,n);if(!o)return!1;let r=ja(o);if(!r){let n=o.blockRange(),r=n&&er(n);return null!=r&&(t&&t(e.tr.lift(n,r).scrollIntoView()),!0)}let i=r.nodeBefore;if(Ha(e,r,t,-1))return!0;if(0==o.parent.content.size&&(Ra(i,"end")||Or.isSelectable(i)))for(let s=o.depth;;s--){let n=dr(e.doc,o.before(s),o.after(s),_n.empty);if(n&&n.slice.size<n.to-n.from){if(t){let o=e.tr.step(n);o.setSelection(Ra(i,"end")?Mr.findFrom(o.doc.resolve(o.mapping.map(r.pos,-1)),-1):Or.create(o.doc,r.pos-i.nodeSize)),t(o.scrollIntoView())}return!0}if(1==s||o.node(s-1).childCount>1)break}return!(!i.isAtom||r.depth!=o.depth-1)&&(t&&t(e.tr.delete(r.pos-i.nodeSize,r.pos).scrollIntoView()),!0)};function Ma(e,t,n){let o=t.nodeBefore,r=t.pos-1;for(;!o.isTextblock;r--){if(o.type.spec.isolating)return!1;let e=o.lastChild;if(!e)return!1;o=e}let i=t.nodeAfter,s=t.pos+1;for(;!i.isTextblock;s++){if(i.type.spec.isolating)return!1;let e=i.firstChild;if(!e)return!1;i=e}let l=dr(e.doc,r,s,_n.empty);if(!l||l.from!=r||l instanceof Zo&&l.slice.size>=s-r)return!1;if(n){let t=e.tr.step(l);t.setSelection(Nr.create(t.doc,r)),n(t.scrollIntoView())}return!0}function Ra(e,t,n=!1){for(let o=e;o;o="start"==t?o.firstChild:o.lastChild){if(o.isTextblock)return!0;if(n&&1!=o.childCount)return!1}return!1}const Ta=(e,t,n)=>{let{$head:o,empty:r}=e.selection,i=o;if(!r)return!1;if(o.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):o.parentOffset>0)return!1;i=ja(o)}let s=i&&i.nodeBefore;return!(!s||!Or.isSelectable(s))&&(t&&t(e.tr.setSelection(Or.create(e.doc,i.pos-s.nodeSize)).scrollIntoView()),!0)};function ja(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 Na(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("forward",e):n.parentOffset<n.parent.content.size)?null:n}const Aa=(e,t,n)=>{let o=Na(e,n);if(!o)return!1;let r=_a(o);if(!r)return!1;let i=r.nodeAfter;if(Ha(e,r,t,1))return!0;if(0==o.parent.content.size&&(Ra(i,"start")||Or.isSelectable(i))){let n=dr(e.doc,o.before(),o.after(),_n.empty);if(n&&n.slice.size<n.to-n.from){if(t){let o=e.tr.step(n);o.setSelection(Ra(i,"start")?Mr.findFrom(o.doc.resolve(o.mapping.map(r.pos)),1):Or.create(o.doc,o.mapping.map(r.pos))),t(o.scrollIntoView())}return!0}}return!(!i.isAtom||r.depth!=o.depth-1)&&(t&&t(e.tr.delete(r.pos,r.pos+i.nodeSize).scrollIntoView()),!0)},Oa=(e,t,n)=>{let{$head:o,empty:r}=e.selection,i=o;if(!r)return!1;if(o.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):o.parentOffset<o.parent.content.size)return!1;i=_a(o)}let s=i&&i.nodeAfter;return!(!s||!Or.isSelectable(s))&&(t&&t(e.tr.setSelection(Or.create(e.doc,i.pos)).scrollIntoView()),!0)};function _a(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}const Pa=(e,t)=>{let{$head:n,$anchor:o}=e.selection;return!(!n.parent.type.spec.code||!n.sameParent(o))&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)};function Ia(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}const La=(e,t)=>{let n=e.selection,{$from:o,$to:r}=n;if(n instanceof Pr||o.parent.inlineContent||r.parent.inlineContent)return!1;let i=Ia(r.parent.contentMatchAt(r.indexAfter()));if(!i||!i.isTextblock)return!1;if(t){let n=(!o.parentOffset&&r.index()<r.parent.childCount?o:r).pos,s=e.tr.insert(n,i.createAndFill());s.setSelection(Nr.create(s.doc,n+1)),t(s.scrollIntoView())}return!0},Da=(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 o=n.before();if(ir(e.doc,o))return t&&t(e.tr.split(o).scrollIntoView()),!0}let o=n.blockRange(),r=o&&er(o);return null!=r&&(t&&t(e.tr.lift(o,r).scrollIntoView()),!0)};const Ba=(e,t)=>{let{$from:n,$to:o}=e.selection;if(e.selection instanceof Or&&e.selection.node.isBlock)return!(!n.parentOffset||!ir(e.doc,n.pos)||(t&&t(e.tr.split(n.pos).scrollIntoView()),0));if(!n.depth)return!1;let r,i,s=[],l=!1,a=!1;for(let h=n.depth;;h--){if(n.node(h).isBlock){l=n.end(h)==n.pos+(n.depth-h),a=n.start(h)==n.pos-(n.depth-h),i=Ia(n.node(h-1).contentMatchAt(n.indexAfter(h-1))),s.unshift(l&&i?{type:i}:null),r=h;break}if(1==h)return!1;s.unshift(null)}let c=e.tr;(e.selection instanceof Nr||e.selection instanceof Pr)&&c.deleteSelection();let d=c.mapping.map(n.pos),u=ir(c.doc,d,s.length,s);if(u||(s[0]=i?{type:i}:null,u=ir(c.doc,d,s.length,s)),!u)return!1;if(c.split(d,s.length,s),!l&&a&&n.node(r).type!=i){let e=c.mapping.map(n.before(r)),t=c.doc.resolve(e);i&&n.node(r-1).canReplaceWith(t.index(),t.index()+1,i)&&c.setNodeMarkup(c.mapping.map(n.before(r)),i)}return t&&t(c.scrollIntoView()),!0};function Ha(e,t,n,o){let r,i,s=t.nodeBefore,l=t.nodeAfter,a=s.type.spec.isolating||l.type.spec.isolating;if(!a&&function(e,t,n){let o=t.nodeBefore,r=t.nodeAfter,i=t.index();return!(!(o&&r&&o.type.compatibleContent(r.type))||(!o.content.size&&t.parent.canReplace(i-1,i)?(n&&n(e.tr.delete(t.pos-o.nodeSize,t.pos).scrollIntoView()),0):!t.parent.canReplace(i,i+1)||!r.isTextblock&&!sr(e.doc,t.pos)||(n&&n(e.tr.join(t.pos).scrollIntoView()),0)))}(e,t,n))return!0;let c=!a&&t.parent.canReplace(t.index(),t.index()+1);if(c&&(r=(i=s.contentMatchAt(s.childCount)).findWrapping(l.type))&&i.matchType(r[0]||l.type).validEnd){if(n){let o=t.pos+l.nodeSize,i=Rn.empty;for(let e=r.length-1;e>=0;e--)i=Rn.from(r[e].create(null,i));i=Rn.from(s.copy(i));let a=e.tr.step(new Jo(t.pos-1,o,t.pos,o,new _n(i,1,0),r.length,!0)),c=a.doc.resolve(o+2*r.length);c.nodeAfter&&c.nodeAfter.type==s.type&&sr(a.doc,c.pos)&&a.join(c.pos),n(a.scrollIntoView())}return!0}let d=l.type.spec.isolating||o>0&&a?null:Mr.findFrom(t,1),u=d&&d.$from.blockRange(d.$to),h=u&&er(u);if(null!=h&&h>=t.depth)return n&&n(e.tr.lift(u,h).scrollIntoView()),!0;if(c&&Ra(l,"start",!0)&&Ra(s,"end")){let o=s,r=[];for(;r.push(o),!o.isTextblock;)o=o.lastChild;let i=l,a=1;for(;!i.isTextblock;i=i.firstChild)a++;if(o.canReplace(o.childCount,o.childCount,i.content)){if(n){let o=Rn.empty;for(let e=r.length-1;e>=0;e--)o=Rn.from(r[e].copy(o));n(e.tr.step(new Jo(t.pos-r.length,t.pos+l.nodeSize,t.pos+a,t.pos+l.nodeSize-a,new _n(o,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function Va(e){return function(t,n){let o=t.selection,r=e<0?o.$from:o.$to,i=r.depth;for(;r.node(i).isInline;){if(!i)return!1;i--}return!!r.node(i).isTextblock&&(n&&n(t.tr.setSelection(Nr.create(t.doc,e<0?r.start(i):r.end(i)))),!0)}}const $a=Va(-1),za=Va(1);function Fa(e,t=null){return function(n,o){let r=!1;for(let i=0;i<n.selection.ranges.length&&!r;i++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[i];n.doc.nodesBetween(o,s,(o,i)=>{if(r)return!1;if(o.isTextblock&&!o.hasMarkup(e,t))if(o.type==e)r=!0;else{let t=n.doc.resolve(i),o=t.index();r=t.parent.canReplaceWith(o,o+1,e)}})}if(!r)return!1;if(o){let r=n.tr;for(let o=0;o<n.selection.ranges.length;o++){let{$from:{pos:i},$to:{pos:s}}=n.selection.ranges[o];r.setBlockType(i,s,e,t)}o(r.scrollIntoView())}return!0}}function Ua(...e){return function(t,n,o){for(let r=0;r<e.length;r++)if(e[r](t,n,o))return!0;return!1}}function Wa(e,t=null){return function(n,o){let{$from:r,$to:i}=n.selection,s=r.blockRange(i);if(!s)return!1;let l=o?n.tr:null;return!!function(e,t,n,o=null){let r=!1,i=t,s=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=s.resolve(t.start-2);i=new Zn(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new Zn(t.$from,s.resolve(t.$to.end(t.depth)),t.depth)),r=!0}let l=tr(i,n,o,t);if(!l)return!1;e&&function(e,t,n,o,r){let i=Rn.empty;for(let d=n.length-1;d>=0;d--)i=Rn.from(n[d].type.create(n[d].attrs,i));e.step(new Jo(t.start-(o?2:0),t.end,t.start,t.end,new _n(i,0,0),n.length,!0));let s=0;for(let d=0;d<n.length;d++)n[d].type==r&&(s=d+1);let l=n.length-s,a=t.start+n.length-(o?2:0),c=t.parent;for(let d=t.startIndex,u=t.endIndex,h=!0;d<u;d++,h=!1)!h&&ir(e.doc,a,l)&&(e.split(a,l),a+=2*l),a+=c.child(d).nodeSize}(e,t,l,r,n);return!0}(l,s,e,t)&&(o&&o(l.scrollIntoView()),!0)}}function qa(e){return function(t,n){let{$from:o,$to:r}=t.selection,i=o.blockRange(r,t=>t.childCount>0&&t.firstChild.type==e);return!!i&&(!n||(o.node(i.depth-1).type==e?function(e,t,n,o){let r=e.tr,i=o.end,s=o.$to.end(o.depth);i<s&&(r.step(new Jo(i-1,s,i,s,new _n(Rn.from(n.create(null,o.parent.copy())),1,0),1,!0)),o=new Zn(r.doc.resolve(o.$from.pos),r.doc.resolve(s),o.depth));const l=er(o);if(null==l)return!1;r.lift(o,l);let a=r.doc.resolve(r.mapping.map(i,-1)-1);sr(r.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&r.join(a.pos);return t(r.scrollIntoView()),!0}(t,n,e,i):function(e,t,n){let o=e.tr,r=n.parent;for(let p=n.end,f=n.endIndex-1,m=n.startIndex;f>m;f--)p-=r.child(f).nodeSize,o.delete(p-1,p+1);let i=o.doc.resolve(n.start),s=i.nodeAfter;if(o.mapping.map(n.end)!=n.start+i.nodeAfter.nodeSize)return!1;let l=0==n.startIndex,a=n.endIndex==r.childCount,c=i.node(-1),d=i.index(-1);if(!c.canReplace(d+(l?0:1),d+1,s.content.append(a?Rn.empty:Rn.from(r))))return!1;let u=i.pos,h=u+s.nodeSize;return o.step(new Jo(u-(l?1:0),h+(a?1:0),u+1,h-1,new _n((l?Rn.empty:Rn.from(r.copy(Rn.empty))).append(a?Rn.empty:Rn.from(r.copy(Rn.empty))),l?0:1,a?0:1),l?0:1)),t(o.scrollIntoView()),!0}(t,n,i)))}}function Ga(e){const{state:t,transaction:n}=e;let{selection:o}=n,{doc:r}=n,{storedMarks:i}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return i},get selection(){return o},get doc(){return r},get tr(){return o=n.selection,r=n.doc,i=n.storedMarks,n}}}Ua(Ca,Sa,Ta),Ua(Ca,Aa,Oa),Ua(Pa,La,Da,Ba),"undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&os.platform();class Ka{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:t,state:n}=this,{view:o}=t,{tr:r}=n,i=this.buildProps(r);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{const n=t(...e)(i);return r.getMeta("preventDispatch")||this.hasCustomState||o.dispatch(r),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:n,editor:o,state:r}=this,{view:i}=o,s=[],l=!!e,a=e||r.tr,c={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{const o=this.buildProps(a,t),r=n(...e)(o);return s.push(r),c}])),run:()=>(l||!t||a.getMeta("preventDispatch")||this.hasCustomState||i.dispatch(a),s.every(e=>!0===e))};return c}createCan(e){const{rawCommands:t,state:n}=this,o=!1,r=e||n.tr,i=this.buildProps(r,o);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,o)}}buildProps(e,t=!0){const{rawCommands:n,editor:o,state:r}=this,{view:i}=o,s={tr:e,editor:o,view:i,state:Ga({state:r,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(s)]))}};return s}}class Za{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){const n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){const n=(...o)=>{this.off(e,n),t.apply(this,o)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}}function Ja(e,t,n){if(void 0===e.config[t]&&e.parent)return Ja(e.parent,t,n);if("function"==typeof e.config[t]){return e.config[t].bind({...n,parent:e.parent?Ja(e.parent,t,n):null})}return e.config[t]}function Xa(e){return{baseExtensions:e.filter(e=>"extension"===e.type),nodeExtensions:e.filter(e=>"node"===e.type),markExtensions:e.filter(e=>"mark"===e.type)}}function Ya(e){const t=[],{nodeExtensions:n,markExtensions:o}=Xa(e),r=[...n,...o],i={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return e.forEach(e=>{const n=Ja(e,"addGlobalAttributes",{name:e.name,options:e.options,storage:e.storage,extensions:r});if(!n)return;n().forEach(e=>{e.types.forEach(n=>{Object.entries(e.attributes).forEach(([e,o])=>{t.push({type:n,name:e,attribute:{...i,...o}})})})})}),r.forEach(e=>{const n={name:e.name,options:e.options,storage:e.storage},o=Ja(e,"addAttributes",n);if(!o)return;const r=o();Object.entries(r).forEach(([n,o])=>{const r={...i,...o};"function"==typeof(null==r?void 0:r.default)&&(r.default=r.default()),(null==r?void 0:r.isRequired)&&void 0===(null==r?void 0:r.default)&&delete r.default,t.push({type:e.name,name:n,attribute:r})})}),t}function Qa(e,t){if("string"==typeof e){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function ec(...e){return e.filter(e=>!!e).reduce((e,t)=>{const n={...e};return Object.entries(t).forEach(([e,t])=>{if(n[e])if("class"===e){const o=t?String(t).split(" "):[],r=n[e]?n[e].split(" "):[],i=o.filter(e=>!r.includes(e));n[e]=[...r,...i].join(" ")}else if("style"===e){const o=t?t.split(";").map(e=>e.trim()).filter(Boolean):[],r=n[e]?n[e].split(";").map(e=>e.trim()).filter(Boolean):[],i=new Map;r.forEach(e=>{const[t,n]=e.split(":").map(e=>e.trim());i.set(t,n)}),o.forEach(e=>{const[t,n]=e.split(":").map(e=>e.trim());i.set(t,n)}),n[e]=Array.from(i.entries()).map(([e,t])=>`${e}: ${t}`).join("; ")}else n[e]=t;else n[e]=t}),n},{})}function tc(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>ec(e,t),{})}function nc(e){return"function"==typeof e}function oc(e,t=void 0,...n){return nc(e)?t?e.bind(t)(...n):e(...n):e}function rc(e,t){return"style"in e?e:{...e,getAttrs:n=>{const o=e.getAttrs?e.getAttrs(n):e.attrs;if(!1===o)return!1;const r=t.reduce((e,t)=>{const o=t.attribute.parseHTML?t.attribute.parseHTML(n):function(e){return"string"!=typeof e?e:e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):"true"===e||"false"!==e&&e}(n.getAttribute(t.name));return null==o?e:{...e,[t.name]:o}},{});return{...o,...r}}}}function ic(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>("attrs"!==e||!function(e={}){return 0===Object.keys(e).length&&e.constructor===Object}(t))&&null!=t))}function sc(e,t){var n;const o=Ya(e),{nodeExtensions:r,markExtensions:i}=Xa(e),s=null===(n=r.find(e=>Ja(e,"topNode")))||void 0===n?void 0:n.name,l=Object.fromEntries(r.map(n=>{const r=o.filter(e=>e.type===n.name),i={name:n.name,options:n.options,storage:n.storage,editor:t},s=ic({...e.reduce((e,t)=>{const o=Ja(t,"extendNodeSchema",i);return{...e,...o?o(n):{}}},{}),content:oc(Ja(n,"content",i)),marks:oc(Ja(n,"marks",i)),group:oc(Ja(n,"group",i)),inline:oc(Ja(n,"inline",i)),atom:oc(Ja(n,"atom",i)),selectable:oc(Ja(n,"selectable",i)),draggable:oc(Ja(n,"draggable",i)),code:oc(Ja(n,"code",i)),whitespace:oc(Ja(n,"whitespace",i)),linebreakReplacement:oc(Ja(n,"linebreakReplacement",i)),defining:oc(Ja(n,"defining",i)),isolating:oc(Ja(n,"isolating",i)),attrs:Object.fromEntries(r.map(e=>{var t;return[e.name,{default:null===(t=null==e?void 0:e.attribute)||void 0===t?void 0:t.default}]}))}),l=oc(Ja(n,"parseHTML",i));l&&(s.parseDOM=l.map(e=>rc(e,r)));const a=Ja(n,"renderHTML",i);a&&(s.toDOM=e=>a({node:e,HTMLAttributes:tc(e,r)}));const c=Ja(n,"renderText",i);return c&&(s.toText=c),[n.name,s]})),a=Object.fromEntries(i.map(n=>{const r=o.filter(e=>e.type===n.name),i={name:n.name,options:n.options,storage:n.storage,editor:t},s=ic({...e.reduce((e,t)=>{const o=Ja(t,"extendMarkSchema",i);return{...e,...o?o(n):{}}},{}),inclusive:oc(Ja(n,"inclusive",i)),excludes:oc(Ja(n,"excludes",i)),group:oc(Ja(n,"group",i)),spanning:oc(Ja(n,"spanning",i)),code:oc(Ja(n,"code",i)),attrs:Object.fromEntries(r.map(e=>{var t;return[e.name,{default:null===(t=null==e?void 0:e.attribute)||void 0===t?void 0:t.default}]}))}),l=oc(Ja(n,"parseHTML",i));l&&(s.parseDOM=l.map(e=>rc(e,r)));const a=Ja(n,"renderHTML",i);return a&&(s.toDOM=e=>a({mark:e,HTMLAttributes:tc(e,r)})),[n.name,s]}));return new yo({topNode:s,nodes:l,marks:a})}function lc(e,t){return t.nodes[e]||t.marks[e]||null}function ac(e,t){return Array.isArray(t)?t.some(t=>("string"==typeof t?t:t.name)===e.name):t}function cc(e,t){const n=jo.fromSchema(t).serializeFragment(e),o=document.implementation.createHTMLDocument().createElement("div");return o.appendChild(n),o.innerHTML}function dc(e){return"[object RegExp]"===Object.prototype.toString.call(e)}class uc{constructor(e){this.find=e.find,this.handler=e.handler}}function hc(e){var t;const{editor:n,from:o,to:r,text:i,rules:s,plugin:l}=e,{view:a}=n;if(a.composing)return!1;const c=a.state.doc.resolve(o);if(c.parent.type.spec.code||(null===(t=c.nodeBefore||c.nodeAfter)||void 0===t?void 0:t.marks.find(e=>e.type.spec.code)))return!1;let d=!1;const u=((e,t=500)=>{let n="";const o=e.parentOffset;return e.parent.nodesBetween(Math.max(0,o-t),o,(e,t,r,i)=>{var s,l;const a=(null===(l=(s=e.type.spec).toText)||void 0===l?void 0:l.call(s,{node:e,pos:t,parent:r,index:i}))||e.textContent||"%leaf%";n+=e.isAtom&&!e.isText?a:a.slice(0,Math.max(0,o-t))}),n})(c)+i;return s.forEach(e=>{if(d)return;const t=((e,t)=>{if(dc(t))return t.exec(e);const n=t(e);if(!n)return null;const o=[n.text];return o.index=n.index,o.input=e,o.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith),o.push(n.replaceWith)),o})(u,e.find);if(!t)return;const s=a.state.tr,c=Ga({state:a.state,transaction:s}),h={from:o-(t[0].length-i.length),to:r},{commands:p,chain:f,can:m}=new Ka({editor:n,state:c});null!==e.handler({state:c,range:h,match:t,commands:p,chain:f,can:m})&&s.steps.length&&(s.setMeta(l,{transform:s,from:o,to:r,text:i}),a.dispatch(s),d=!0)}),d}function pc(e){const{editor:t,rules:n}=e,o=new Wr({state:{init:()=>null,apply(e,r,i){const s=e.getMeta(o);if(s)return s;const l=e.getMeta("applyInputRules");return!!l&&setTimeout(()=>{let{text:e}=l;"string"==typeof e||(e=cc(Rn.from(e),i.schema));const{from:r}=l,s=r+e.length;hc({editor:t,from:r,to:s,text:e,rules:n,plugin:o})}),e.selectionSet||e.docChanged?null:r}},props:{handleTextInput:(e,r,i,s)=>hc({editor:t,from:r,to:i,text:s,rules:n,plugin:o}),handleDOMEvents:{compositionend:e=>(setTimeout(()=>{const{$cursor:r}=e.state.selection;r&&hc({editor:t,from:r.pos,to:r.pos,text:"",rules:n,plugin:o})}),!1)},handleKeyDown(e,r){if("Enter"!==r.key)return!1;const{$cursor:i}=e.state.selection;return!!i&&hc({editor:t,from:i.pos,to:i.pos,text:"\n",rules:n,plugin:o})}},isInputRules:!0});return o}function fc(e){return"Object"===function(e){return Object.prototype.toString.call(e).slice(8,-1)}(e)&&(e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype)}function mc(e,t){const n={...e};return fc(e)&&fc(t)&&Object.keys(t).forEach(o=>{fc(t[o])&&fc(e[o])?n[o]=mc(e[o],t[o]):n[o]=t[o]}),n}class gc{constructor(e={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=oc(Ja(this,"addOptions",{name:this.name}))),this.storage=oc(Ja(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new gc(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>mc(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new gc(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,t.options=oc(Ja(t,"addOptions",{name:t.name})),t.storage=oc(Ja(t,"addStorage",{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){const{tr:n}=e.state,o=e.state.selection.$from;if(o.pos===o.end()){const r=o.marks();if(!!!r.find(e=>(null==e?void 0:e.type.name)===t.name))return!1;const i=r.find(e=>(null==e?void 0:e.type.name)===t.name);return i&&n.removeStoredMark(i),n.insertText(" ",o.pos),e.view.dispatch(n),!0}return!1}}class yc{constructor(e){this.find=e.find,this.handler=e.handler}}function bc(e){const{editor:t,state:n,from:o,to:r,rule:i,pasteEvent:s,dropEvent:l}=e,{commands:a,chain:c,can:d}=new Ka({editor:t,state:n}),u=[];n.doc.nodesBetween(o,r,(e,t)=>{if(!e.isTextblock||e.type.spec.code)return;const h=Math.max(o,t),p=Math.min(r,t+e.content.size);((e,t,n)=>{if(dc(t))return[...e.matchAll(t)];const o=t(e,n);return o?o.map(t=>{const n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith),n.push(t.replaceWith)),n}):[]})(e.textBetween(h-t,p-t,void 0,""),i.find,s).forEach(e=>{if(void 0===e.index)return;const t=h+e.index+1,o=t+e[0].length,r={from:n.tr.mapping.map(t),to:n.tr.mapping.map(o)},p=i.handler({state:n,range:r,match:e,commands:a,chain:c,can:d,pasteEvent:s,dropEvent:l});u.push(p)})});return u.every(e=>null!==e)}let vc=null;function xc(e){const{editor:t,rules:n}=e;let o,r=null,i=!1,s=!1,l="undefined"!=typeof ClipboardEvent?new ClipboardEvent("paste"):null;try{o="undefined"!=typeof DragEvent?new DragEvent("drop"):null}catch{o=null}const a=({state:e,from:n,to:r,rule:i,pasteEvt:s})=>{const a=e.tr,c=Ga({state:e,transaction:a});if(bc({editor:t,state:c,from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:s,dropEvent:o})&&a.steps.length){try{o="undefined"!=typeof DragEvent?new DragEvent("drop"):null}catch{o=null}return l="undefined"!=typeof ClipboardEvent?new ClipboardEvent("paste"):null,a}};return n.map(e=>new Wr({view(e){const n=n=>{var o;r=(null===(o=e.dom.parentElement)||void 0===o?void 0:o.contains(n.target))?e.dom.parentElement:null,r&&(vc=t)},o=()=>{vc&&(vc=null)};return window.addEventListener("dragstart",n),window.addEventListener("dragend",o),{destroy(){window.removeEventListener("dragstart",n),window.removeEventListener("dragend",o)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(s=r===e.dom.parentElement,o=t,!s){const e=vc;(null==e?void 0:e.isEditable)&&setTimeout(()=>{const t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{var n;const o=null===(n=t.clipboardData)||void 0===n?void 0:n.getData("text/html");return l=t,i=!!(null==o?void 0:o.includes("data-pm-slice")),!1}}},appendTransaction:(t,n,o)=>{const r=t[0],c="paste"===r.getMeta("uiEvent")&&!i,d="drop"===r.getMeta("uiEvent")&&!s,u=r.getMeta("applyPasteRules"),h=!!u;if(!c&&!d&&!h)return;if(h){let{text:t}=u;"string"==typeof t||(t=cc(Rn.from(t),o.schema));const{from:n}=u,r=n+t.length,i=(e=>{var t;const n=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return null===(t=n.clipboardData)||void 0===t||t.setData("text/html",e),n})(t);return a({rule:e,state:o,from:n,to:{b:r},pasteEvt:i})}const p=n.doc.content.findDiffStart(o.doc.content),f=n.doc.content.findDiffEnd(o.doc.content);return"number"==typeof p&&f&&p!==f.b?a({rule:e,state:o,from:p,to:f,pasteEvt:l}):void 0}}))}class wc{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=wc.resolve(e),this.schema=sc(this.extensions,t),this.setupExtensions()}static resolve(e){const t=wc.sort(wc.flatten(e));return function(e){const t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}(t.map(e=>e.name)).length,t}static flatten(e){return e.map(e=>{const t=Ja(e,"addExtensions",{name:e.name,options:e.options,storage:e.storage});return t?[e,...this.flatten(t())]:e}).flat(10)}static sort(e){return e.sort((e,t)=>{const n=Ja(e,"priority")||100,o=Ja(t,"priority")||100;return n>o?-1:n<o?1:0})}get commands(){return this.extensions.reduce((e,t)=>{const n=Ja(t,"addCommands",{name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:lc(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){const{editor:e}=this,t=wc.sort([...this.extensions].reverse()),n=[],o=[],r=t.map(t=>{const r={name:t.name,options:t.options,storage:t.storage,editor:e,type:lc(t.name,this.schema)},i=[],s=Ja(t,"addKeyboardShortcuts",r);let l={};if("mark"===t.type&&Ja(t,"exitable",r)&&(l.ArrowRight=()=>gc.handleExit({editor:e,mark:t})),s){const t=Object.fromEntries(Object.entries(s()).map(([t,n])=>[t,()=>n({editor:e})]));l={...l,...t}}const a=new Wr({props:{handleKeyDown:ka(l)}});i.push(a);const c=Ja(t,"addInputRules",r);ac(t,e.options.enableInputRules)&&c&&n.push(...c());const d=Ja(t,"addPasteRules",r);ac(t,e.options.enablePasteRules)&&d&&o.push(...d());const u=Ja(t,"addProseMirrorPlugins",r);if(u){const e=u();i.push(...e)}return i}).flat();return[pc({editor:e,rules:n}),...xc({editor:e,rules:o}),...r]}get attributes(){return Ya(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=Xa(this.extensions);return Object.fromEntries(t.filter(e=>!!Ja(e,"addNodeView")).map(t=>{const n=this.attributes.filter(e=>e.type===t.name),o={name:t.name,options:t.options,storage:t.storage,editor:e,type:Qa(t.name,this.schema)},r=Ja(t,"addNodeView",o);if(!r)return[];return[t.name,(o,i,s,l,a)=>{const c=tc(o,n);return r()({node:o,view:i,getPos:s,decorations:l,innerDecorations:a,editor:e,extension:t,HTMLAttributes:c})}]}))}setupExtensions(){this.extensions.forEach(e=>{var t;this.editor.extensionStorage[e.name]=e.storage;const n={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:lc(e.name,this.schema)};if("mark"===e.type){(null===(t=oc(Ja(e,"keepOnSplit",n)))||void 0===t||t)&&this.splittableMarks.push(e.name)}const o=Ja(e,"onBeforeCreate",n),r=Ja(e,"onCreate",n),i=Ja(e,"onUpdate",n),s=Ja(e,"onSelectionUpdate",n),l=Ja(e,"onTransaction",n),a=Ja(e,"onFocus",n),c=Ja(e,"onBlur",n),d=Ja(e,"onDestroy",n);o&&this.editor.on("beforeCreate",o),r&&this.editor.on("create",r),i&&this.editor.on("update",i),s&&this.editor.on("selectionUpdate",s),l&&this.editor.on("transaction",l),a&&this.editor.on("focus",a),c&&this.editor.on("blur",c),d&&this.editor.on("destroy",d)})}}class kc{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=oc(Ja(this,"addOptions",{name:this.name}))),this.storage=oc(Ja(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new kc(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>mc(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new kc({...this.config,...e});return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,t.options=oc(Ja(t,"addOptions",{name:t.name})),t.storage=oc(Ja(t,"addStorage",{name:t.name,options:t.options})),t}}function Cc(e,t,n){const{from:o,to:r}=t,{blockSeparator:i="\n\n",textSerializers:s={}}=n||{};let l="";return e.nodesBetween(o,r,(e,n,a,c)=>{var d;e.isBlock&&n>o&&(l+=i);const u=null==s?void 0:s[e.type.name];if(u)return a&&(l+=u({node:e,pos:n,parent:a,index:c,range:t})),!1;e.isText&&(l+=null===(d=null==e?void 0:e.text)||void 0===d?void 0:d.slice(Math.max(o,n)-n,r-n))}),l}function Ec(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const Sc=kc.create({name:"clipboardTextSerializer",addOptions:()=>({blockSeparator:void 0}),addProseMirrorPlugins(){return[new Wr({key:new Kr("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:o,selection:r}=t,{ranges:i}=r,s=Math.min(...i.map(e=>e.$from.pos)),l=Math.max(...i.map(e=>e.$to.pos)),a=Ec(n);return Cc(o,{from:s,to:l},{...void 0!==this.options.blockSeparator?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}});function Mc(e,t,n={strict:!0}){const o=Object.keys(t);return!o.length||o.every(o=>n.strict?t[o]===e[o]:dc(t[o])?t[o].test(e[o]):t[o]===e[o])}function Rc(e,t,n={}){return e.find(e=>e.type===t&&Mc(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function Tc(e,t,n={}){return!!Rc(e,t,n)}function jc(e,t,n){var o;if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;n=n||(null===(o=r.node.marks[0])||void 0===o?void 0:o.attrs);if(!Rc([...r.node.marks],t,n))return;let i=r.index,s=e.start()+r.offset,l=i+1,a=s+r.node.nodeSize;for(;i>0&&Tc([...e.parent.child(i-1).marks],t,n);)i-=1,s-=e.parent.child(i).nodeSize;for(;l<e.parent.childCount&&Tc([...e.parent.child(l).marks],t,n);)a+=e.parent.child(l).nodeSize,l+=1;return{from:s,to:a}}function Nc(e,t){if("string"==typeof e){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}function Ac(e){return e instanceof Nr}function Oc(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function _c(e,t=null){if(!t)return null;const n=Mr.atStart(e),o=Mr.atEnd(e);if("start"===t||!0===t)return n;if("end"===t)return o;const r=n.from,i=o.to;return"all"===t?Nr.create(e,Oc(0,r,i),Oc(e.content.size,r,i)):Nr.create(e,Oc(t,r,i),Oc(t,r,i))}function Pc(){return"Android"===navigator.platform||/android/i.test(navigator.userAgent)}function Ic(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const Lc=e=>{const t=e.childNodes;for(let n=t.length-1;n>=0;n-=1){const o=t[n];3===o.nodeType&&o.nodeValue&&/^(\n\s\s|\n)$/.test(o.nodeValue)?e.removeChild(o):1===o.nodeType&&Lc(o)}return e};function Dc(e){const t=`<body>${e}</body>`,n=(new window.DOMParser).parseFromString(t,"text/html").body;return Lc(n)}function Bc(e,t,n){if(e instanceof Xn||e instanceof Rn)return e;n={slice:!0,parseOptions:{},...n};const o="string"==typeof e;if("object"==typeof e&&null!==e)try{if(Array.isArray(e)&&e.length>0)return Rn.fromArray(e.map(e=>t.nodeFromJSON(e)));const o=t.nodeFromJSON(e);return n.errorOnInvalidContent&&o.check(),o}catch(r){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:r});return Bc("",t,n)}if(o){if(n.errorOnInvalidContent){let o=!1,r="";const i=new yo({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:e=>(o=!0,r="string"==typeof e?e:e.outerHTML,null)}]}})});if(n.slice?vo.fromSchema(i).parseSlice(Dc(e),n.parseOptions):vo.fromSchema(i).parse(Dc(e),n.parseOptions),n.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${r}`)})}const o=vo.fromSchema(t);return n.slice?o.parseSlice(Dc(e),n.parseOptions).content:o.parse(Dc(e),n.parseOptions)}return Bc("",t,n)}function Hc(e,t,n){const o=e.steps.length-1;if(o<t)return;const r=e.steps[o];if(!(r instanceof Zo||r instanceof Jo))return;const i=e.mapping.maps[o];let s=0;i.forEach((e,t,n,o)=>{0===s&&(s=o)}),e.setSelection(Mr.near(e.doc.resolve(s),n))}function Vc(){return"undefined"!=typeof navigator&&/Mac/.test(navigator.platform)}function $c(e,t,n={}){const{from:o,to:r,empty:i}=e.selection,s=t?Qa(t,e.schema):null,l=[];e.doc.nodesBetween(o,r,(e,t)=>{if(e.isText)return;const n=Math.max(o,t),i=Math.min(r,t+e.nodeSize);l.push({node:e,from:n,to:i})});const a=r-o,c=l.filter(e=>!s||s.name===e.node.type.name).filter(e=>Mc(e.node.attrs,n,{strict:!1}));if(i)return!!c.length;return c.reduce((e,t)=>e+t.to-t.from,0)>=a}function zc(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function Fc(e,t){const n="string"==typeof t?[t]:t;return Object.keys(e).reduce((t,o)=>(n.includes(o)||(t[o]=e[o]),t),{})}function Uc(e,t,n={},o={}){return Bc(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:o.errorOnInvalidContent})}function Wc(e,t){const n=Nc(t,e.schema),{from:o,to:r,empty:i}=e.selection,s=[];i?(e.storedMarks&&s.push(...e.storedMarks),s.push(...e.selection.$head.marks())):e.doc.nodesBetween(o,r,e=>{s.push(...e.marks)});const l=s.find(e=>e.type.name===n.name);return l?{...l.attrs}:{}}function qc(e,t){const n=new Er(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function Gc(e,t){const n=[];return e.descendants((e,o)=>{t(e)&&n.push({node:e,pos:o})}),n}function Kc(e,t,n){const o=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&o.push({node:e,pos:t})}),o}function Zc(e){return t=>function(e,t){for(let n=e.depth;n>0;n-=1){const o=e.node(n);if(t(o))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:o}}}(t.$from,e)}function Jc(e,t){const n=zc("string"==typeof t?t:t.name,e.schema);return"node"===n?function(e,t){const n=Qa(t,e.schema),{from:o,to:r}=e.selection,i=[];e.doc.nodesBetween(o,r,e=>{i.push(e)});const s=i.reverse().find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}(e,t):"mark"===n?Wc(e,t):{}}function Xc(e){const t=function(e,t=JSON.stringify){const n={};return e.filter(e=>{const o=t(e);return!Object.prototype.hasOwnProperty.call(n,o)&&(n[o]=!0)})}(e);return 1===t.length?t:t.filter((e,n)=>{const o=t.filter((e,t)=>t!==n);return!o.some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to)})}function Yc(e){const{mapping:t,steps:n}=e,o=[];return t.maps.forEach((e,r)=>{const i=[];if(e.ranges.length)e.forEach((e,t)=>{i.push({from:e,to:t})});else{const{from:e,to:t}=n[r];if(void 0===e||void 0===t)return;i.push({from:e,to:t})}i.forEach(({from:e,to:n})=>{const i=t.slice(r).map(e,-1),s=t.slice(r).map(n),l=t.invert().map(i,-1),a=t.invert().map(s);o.push({oldRange:{from:l,to:a},newRange:{from:i,to:s}})})}),Xc(o)}function Qc(e,t,n){const o=[];return e===t?n.resolve(e).marks().forEach(t=>{const r=jc(n.resolve(e),t.type);r&&o.push({mark:t,...r})}):n.nodesBetween(e,t,(e,t)=>{e&&void 0!==(null==e?void 0:e.nodeSize)&&o.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),o}function ed(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{const o=e.find(e=>e.type===t&&e.name===n);return!!o&&o.attribute.keepOnSplit}))}function td(e,t,n={}){const{empty:o,ranges:r}=e.selection,i=t?Nc(t,e.schema):null;if(o)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!i||i.name===e.type.name).find(e=>Mc(e.attrs,n,{strict:!1}));let s=0;const l=[];if(r.forEach(({$from:t,$to:n})=>{const o=t.pos,r=n.pos;e.doc.nodesBetween(o,r,(e,t)=>{if(!e.isText&&!e.marks.length)return;const n=Math.max(o,t),i=Math.min(r,t+e.nodeSize);s+=i-n,l.push(...e.marks.map(e=>({mark:e,from:n,to:i})))})}),0===s)return!1;const a=l.filter(e=>!i||i.name===e.mark.type.name).filter(e=>Mc(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),c=l.filter(e=>!i||e.mark.type!==i&&e.mark.type.excludes(i)).reduce((e,t)=>e+t.to-t.from,0);return(a>0?a+c:a)>=s}function nd(e,t){const{nodeExtensions:n}=Xa(t),o=n.find(t=>t.name===e);if(!o)return!1;const r=oc(Ja(o,"group",{name:o.name,options:o.options,storage:o.storage}));return"string"==typeof r&&r.split(" ").includes("list")}function od(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){var o;if(n){if("hardBreak"===e.type.name)return!0;if(e.isText)return/^\s*$/m.test(null!==(o=e.text)&&void 0!==o?o:"")}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(0===e.content.childCount)return!0;if(t){let o=!0;return e.content.forEach(e=>{!1!==o&&(od(e,{ignoreWhitespace:n,checkChildren:t})||(o=!1))}),o}return!1}function rd(e){return e instanceof Or}function id(e,t,n){const o=e.state.doc.content.size,r=Oc(t,0,o),i=Oc(n,0,o),s=e.coordsAtPos(r),l=e.coordsAtPos(i,-1),a=Math.min(s.top,l.top),c=Math.max(s.bottom,l.bottom),d=Math.min(s.left,l.left),u=Math.max(s.right,l.right),h={top:a,bottom:c,left:d,right:u,width:u-d,height:c-a,x:d,y:a};return{...h,toJSON:()=>h}}function sd(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const o=n.filter(e=>null==t?void 0:t.includes(e.type.name));e.tr.ensureMarks(o)}}const ld=(e,t)=>{const n=Zc(e=>e.type===t)(e.selection);if(!n)return!0;const o=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(void 0===o)return!0;const r=e.doc.nodeAt(o);return n.node.type!==(null==r?void 0:r.type)||!sr(e.doc,n.pos)||(e.join(n.pos),!0)},ad=(e,t)=>{const n=Zc(e=>e.type===t)(e.selection);if(!n)return!0;const o=e.doc.resolve(n.start).after(n.depth);if(void 0===o)return!0;const r=e.doc.nodeAt(o);return n.node.type!==(null==r?void 0:r.type)||!sr(e.doc,o)||(e.join(o),!0)};var cd=Object.freeze({__proto__:null,blur:()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),null===(n=null===window||void 0===window?void 0:window.getSelection())||void 0===n||n.removeAllRanges())}),!0),clearContent:(e=!1)=>({commands:t})=>t.setContent("",e),clearNodes:()=>({state:e,tr:t,dispatch:n})=>{const{selection:o}=t,{ranges:r}=o;return!n||(r.forEach(({$from:n,$to:o})=>{e.doc.nodesBetween(n.pos,o.pos,(e,n)=>{if(e.type.isText)return;const{doc:o,mapping:r}=t,i=o.resolve(r.map(n)),s=o.resolve(r.map(n+e.nodeSize)),l=i.blockRange(s);if(!l)return;const a=er(l);if(e.type.isTextblock){const{defaultType:e}=i.parent.contentMatchAt(i.index());t.setNodeMarkup(l.start,e)}(a||0===a)&&t.lift(l,a)})}),!0)},command:e=>t=>e(t),createParagraphNear:()=>({state:e,dispatch:t})=>La(e,t),cut:(e,t)=>({editor:n,tr:o})=>{const{state:r}=n,i=r.doc.slice(e.from,e.to);o.deleteRange(e.from,e.to);const s=o.mapping.map(t);return o.insert(s,i.content),o.setSelection(new Nr(o.doc.resolve(Math.max(s-1,0)))),!0},deleteCurrentNode:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,o=n.$anchor.node();if(o.content.size>0)return!1;const r=e.selection.$anchor;for(let i=r.depth;i>0;i-=1){if(r.node(i).type===o.type){if(t){const t=r.before(i),n=r.after(i);e.delete(t,n).scrollIntoView()}return!0}}return!1},deleteNode:e=>({tr:t,state:n,dispatch:o})=>{const r=Qa(e,n.schema),i=t.selection.$anchor;for(let e=i.depth;e>0;e-=1){if(i.node(e).type===r){if(o){const n=i.before(e),o=i.after(e);t.delete(n,o).scrollIntoView()}return!0}}return!1},deleteRange:e=>({tr:t,dispatch:n})=>{const{from:o,to:r}=e;return n&&t.delete(o,r),!0},deleteSelection:()=>({state:e,dispatch:t})=>Ca(e,t),enter:()=>({commands:e})=>e.keyboardShortcut("Enter"),exitCode:()=>({state:e,dispatch:t})=>((e,t)=>{let{$head:n,$anchor:o}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(o))return!1;let r=n.node(-1),i=n.indexAfter(-1),s=Ia(r.contentMatchAt(i));if(!s||!r.canReplaceWith(i,i,s))return!1;if(t){let o=n.after(),r=e.tr.replaceWith(o,o,s.createAndFill());r.setSelection(Mr.near(r.doc.resolve(o),1)),t(r.scrollIntoView())}return!0})(e,t),extendMarkRange:(e,t={})=>({tr:n,state:o,dispatch:r})=>{const i=Nc(e,o.schema),{doc:s,selection:l}=n,{$from:a,from:c,to:d}=l;if(r){const e=jc(a,i,t);if(e&&e.from<=c&&e.to>=d){const t=Nr.create(s,e.from,e.to);n.setSelection(t)}}return!0},first:e=>t=>{const n="function"==typeof e?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1},focus:(e=null,t={})=>({editor:n,view:o,tr:r,dispatch:i})=>{t={scrollIntoView:!0,...t};const s=()=>{(Ic()||Pc())&&o.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(o.focus(),(null==t?void 0:t.scrollIntoView)&&n.commands.scrollIntoView())})};if(o.hasFocus()&&null===e||!1===e)return!0;if(i&&null===e&&!Ac(n.state.selection))return s(),!0;const l=_c(r.doc,e)||n.state.selection,a=n.state.selection.eq(l);return i&&(a||r.setSelection(l),a&&r.storedMarks&&r.setStoredMarks(r.storedMarks),s()),!0},forEach:(e,t)=>n=>e.every((e,o)=>t(e,{...n,index:o})),insertContent:(e,t)=>({tr:n,commands:o})=>o.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),insertContentAt:(e,t,n)=>({tr:o,dispatch:r,editor:i})=>{var s;if(r){let r;const a=e=>{i.emit("contentError",{editor:i,error:e,disableCollaboration:()=>{i.storage.collaboration&&(i.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...(n={parseOptions:i.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n}).parseOptions};if(!n.errorOnInvalidContent&&!i.options.enableContentCheck&&i.options.emitContentError)try{Bc(t,i.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(l){a(l)}try{r=Bc(t,i.schema,{parseOptions:c,errorOnInvalidContent:null!==(s=n.errorOnInvalidContent)&&void 0!==s?s:i.options.enableContentCheck})}catch(l){return a(l),!1}let{from:d,to:u}="number"==typeof e?{from:e,to:e}:{from:e.from,to:e.to},h=!0,p=!0;if(("type"in r?[r]:r).forEach(e=>{e.check(),h=!!h&&(e.isText&&0===e.marks.length),p=!!p&&e.isBlock}),d===u&&p){const{parent:e}=o.doc.resolve(d);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(d-=1,u+=1)}let f;if(h){if(Array.isArray(t))f=t.map(e=>e.text||"").join("");else if(t instanceof Rn){let e="";t.forEach(t=>{t.text&&(e+=t.text)}),f=e}else f="object"==typeof t&&t&&t.text?t.text:t;o.insertText(f,d,u)}else f=r,o.replaceWith(d,u,f);n.updateSelection&&Hc(o,o.steps.length-1,-1),n.applyInputRules&&o.setMeta("applyInputRules",{from:d,text:f}),n.applyPasteRules&&o.setMeta("applyPasteRules",{from:d,text:f})}return!0},joinBackward:()=>({state:e,dispatch:t})=>Sa(e,t),joinDown:()=>({state:e,dispatch:t})=>((e,t)=>{let n,o=e.selection;if(o instanceof Or){if(o.node.isTextblock||!sr(e.doc,o.to))return!1;n=o.to}else if(n=ar(e.doc,o.to,1),null==n)return!1;return t&&t(e.tr.join(n).scrollIntoView()),!0})(e,t),joinForward:()=>({state:e,dispatch:t})=>Aa(e,t),joinItemBackward:()=>({state:e,dispatch:t,tr:n})=>{try{const o=ar(e.doc,e.selection.$from.pos,-1);return null!=o&&(n.join(o,2),t&&t(n),!0)}catch{return!1}},joinItemForward:()=>({state:e,dispatch:t,tr:n})=>{try{const o=ar(e.doc,e.selection.$from.pos,1);return null!=o&&(n.join(o,2),t&&t(n),!0)}catch{return!1}},joinTextblockBackward:()=>({state:e,dispatch:t})=>((e,t,n)=>{let o=Ea(e,n);if(!o)return!1;let r=ja(o);return!!r&&Ma(e,r,t)})(e,t),joinTextblockForward:()=>({state:e,dispatch:t})=>((e,t,n)=>{let o=Na(e,n);if(!o)return!1;let r=_a(o);return!!r&&Ma(e,r,t)})(e,t),joinUp:()=>({state:e,dispatch:t})=>((e,t)=>{let n,o=e.selection,r=o instanceof Or;if(r){if(o.node.isTextblock||!sr(e.doc,o.from))return!1;n=o.from}else if(n=ar(e.doc,o.from,-1),null==n)return!1;if(t){let o=e.tr.join(n);r&&o.setSelection(Or.create(o.doc,n-e.doc.resolve(n).nodeBefore.nodeSize)),t(o.scrollIntoView())}return!0})(e,t),keyboardShortcut:e=>({editor:t,view:n,tr:o,dispatch:r})=>{const i=function(e){const t=e.split(/-(?!$)/);let n,o,r,i,s=t[t.length-1];"Space"===s&&(s=" ");for(let l=0;l<t.length-1;l+=1){const e=t[l];if(/^(cmd|meta|m)$/i.test(e))i=!0;else if(/^a(lt)?$/i.test(e))n=!0;else if(/^(c|ctrl|control)$/i.test(e))o=!0;else if(/^s(hift)?$/i.test(e))r=!0;else{if(!/^mod$/i.test(e))throw new Error(`Unrecognized modifier name: ${e}`);Ic()||Vc()?i=!0:o=!0}}return n&&(s=`Alt-${s}`),o&&(s=`Ctrl-${s}`),i&&(s=`Meta-${s}`),r&&(s=`Shift-${s}`),s}(e).split(/-(?!$)/),s=i.find(e=>!["Alt","Ctrl","Meta","Shift"].includes(e)),l=new KeyboardEvent("keydown",{key:"Space"===s?" ":s,altKey:i.includes("Alt"),ctrlKey:i.includes("Ctrl"),metaKey:i.includes("Meta"),shiftKey:i.includes("Shift"),bubbles:!0,cancelable:!0}),a=t.captureTransaction(()=>{n.someProp("handleKeyDown",e=>e(n,l))});return null==a||a.steps.forEach(e=>{const t=e.map(o.mapping);t&&r&&o.maybeStep(t)}),!0},lift:(e,t={})=>({state:n,dispatch:o})=>!!$c(n,Qa(e,n.schema),t)&&((e,t)=>{let{$from:n,$to:o}=e.selection,r=n.blockRange(o),i=r&&er(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)})(n,o),liftEmptyBlock:()=>({state:e,dispatch:t})=>Da(e,t),liftListItem:e=>({state:t,dispatch:n})=>qa(Qa(e,t.schema))(t,n),newlineInCode:()=>({state:e,dispatch:t})=>Pa(e,t),resetAttributes:(e,t)=>({tr:n,state:o,dispatch:r})=>{let i=null,s=null;const l=zc("string"==typeof e?e:e.name,o.schema);return!!l&&("node"===l&&(i=Qa(e,o.schema)),"mark"===l&&(s=Nc(e,o.schema)),r&&n.selection.ranges.forEach(e=>{o.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,o)=>{i&&i===e.type&&n.setNodeMarkup(o,void 0,Fc(e.attrs,t)),s&&e.marks.length&&e.marks.forEach(r=>{s===r.type&&n.addMark(o,o+e.nodeSize,s.create(Fc(r.attrs,t)))})})}),!0)},scrollIntoView:()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),selectAll:()=>({tr:e,dispatch:t})=>{if(t){const t=new Pr(e.doc);e.setSelection(t)}return!0},selectNodeBackward:()=>({state:e,dispatch:t})=>Ta(e,t),selectNodeForward:()=>({state:e,dispatch:t})=>Oa(e,t),selectParentNode:()=>({state:e,dispatch:t})=>((e,t)=>{let n,{$from:o,to:r}=e.selection,i=o.sharedDepth(r);return 0!=i&&(n=o.before(i),t&&t(e.tr.setSelection(Or.create(e.doc,n))),!0)})(e,t),selectTextblockEnd:()=>({state:e,dispatch:t})=>za(e,t),selectTextblockStart:()=>({state:e,dispatch:t})=>$a(e,t),setContent:(e,t=!1,n={},o={})=>({editor:r,tr:i,dispatch:s,commands:l})=>{var a,c;const{doc:d}=i;if("full"!==n.preserveWhitespace){const l=Uc(e,r.schema,n,{errorOnInvalidContent:null!==(a=o.errorOnInvalidContent)&&void 0!==a?a:r.options.enableContentCheck});return s&&i.replaceWith(0,d.content.size,l).setMeta("preventUpdate",!t),!0}return s&&i.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:d.content.size},e,{parseOptions:n,errorOnInvalidContent:null!==(c=o.errorOnInvalidContent)&&void 0!==c?c:r.options.enableContentCheck})},setMark:(e,t={})=>({tr:n,state:o,dispatch:r})=>{const{selection:i}=n,{empty:s,ranges:l}=i,a=Nc(e,o.schema);if(r)if(s){const e=Wc(o,a);n.addStoredMark(a.create({...e,...t}))}else l.forEach(e=>{const r=e.$from.pos,i=e.$to.pos;o.doc.nodesBetween(r,i,(e,o)=>{const s=Math.max(o,r),l=Math.min(o+e.nodeSize,i);e.marks.find(e=>e.type===a)?e.marks.forEach(e=>{a===e.type&&n.addMark(s,l,a.create({...e.attrs,...t}))}):n.addMark(s,l,a.create(t))})});return function(e,t,n){var o;const{selection:r}=t;let i=null;if(Ac(r)&&(i=r.$cursor),i){const t=null!==(o=e.storedMarks)&&void 0!==o?o:i.marks();return!!n.isInSet(t)||!t.some(e=>e.type.excludes(n))}const{ranges:s}=r;return s.some(({$from:t,$to:o})=>{let r=0===t.depth&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,o.pos,(e,t,o)=>{if(r)return!1;if(e.isInline){const t=!o||o.type.allowsMarkType(n),i=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));r=t&&i}return!r}),r})}(o,n,a)},setMeta:(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),setNode:(e,t={})=>({state:n,dispatch:o,chain:r})=>{const i=Qa(e,n.schema);let s;return n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),!!i.isTextblock&&r().command(({commands:e})=>!!Fa(i,{...s,...t})(n)||e.clearNodes()).command(({state:e})=>Fa(i,{...s,...t})(e,o)).run()},setNodeSelection:e=>({tr:t,dispatch:n})=>{if(n){const{doc:n}=t,o=Oc(e,0,n.content.size),r=Or.create(n,o);t.setSelection(r)}return!0},setTextSelection:e=>({tr:t,dispatch:n})=>{if(n){const{doc:n}=t,{from:o,to:r}="number"==typeof e?{from:e,to:e}:e,i=Nr.atStart(n).from,s=Nr.atEnd(n).to,l=Oc(o,i,s),a=Oc(r,i,s),c=Nr.create(n,l,a);t.setSelection(c)}return!0},sinkListItem:e=>({state:t,dispatch:n})=>{const o=Qa(e,t.schema);return(r=o,function(e,t){let{$from:n,$to:o}=e.selection,i=n.blockRange(o,e=>e.childCount>0&&e.firstChild.type==r);if(!i)return!1;let s=i.startIndex;if(0==s)return!1;let l=i.parent,a=l.child(s-1);if(a.type!=r)return!1;if(t){let n=a.lastChild&&a.lastChild.type==l.type,o=Rn.from(n?r.create():null),s=new _n(Rn.from(r.create(null,Rn.from(l.type.create(null,o)))),n?3:1,0),c=i.start,d=i.end;t(e.tr.step(new Jo(c-(n?3:1),d,c,d,s,1,!0)).scrollIntoView())}return!0})(t,n);var r},splitBlock:({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:o,editor:r})=>{const{selection:i,doc:s}=t,{$from:l,$to:a}=i,c=ed(r.extensionManager.attributes,l.node().type.name,l.node().attrs);if(i instanceof Or&&i.node.isBlock)return!(!l.parentOffset||!ir(s,l.pos))&&(o&&(e&&sd(n,r.extensionManager.splittableMarks),t.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const d=a.parentOffset===a.parent.content.size,u=0===l.depth?void 0:function(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=d&&u?[{type:u,attrs:c}]:void 0,p=ir(t.doc,t.mapping.map(l.pos),1,h);if(h||p||!ir(t.doc,t.mapping.map(l.pos),1,u?[{type:u}]:void 0)||(p=!0,h=u?[{type:u,attrs:c}]:void 0),o){if(p&&(i instanceof Nr&&t.deleteSelection(),t.split(t.mapping.map(l.pos),1,h),u&&!d&&!l.parentOffset&&l.parent.type!==u)){const e=t.mapping.map(l.before()),n=t.doc.resolve(e);l.node(-1).canReplaceWith(n.index(),n.index()+1,u)&&t.setNodeMarkup(t.mapping.map(l.before()),u)}e&&sd(n,r.extensionManager.splittableMarks),t.scrollIntoView()}return p},splitListItem:(e,t={})=>({tr:n,state:o,dispatch:r,editor:i})=>{var s;const l=Qa(e,o.schema),{$from:a,$to:c}=o.selection,d=o.selection.node;if(d&&d.isBlock||a.depth<2||!a.sameParent(c))return!1;const u=a.node(-1);if(u.type!==l)return!1;const h=i.extensionManager.attributes;if(0===a.parent.content.size&&a.node(-1).childCount===a.indexAfter(-1)){if(2===a.depth||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(r){let e=Rn.empty;const o=a.index(-1)?1:a.index(-2)?2:3;for(let t=a.depth-o;t>=a.depth-3;t-=1)e=Rn.from(a.node(t).copy(e));const r=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,i={...ed(h,a.node().type.name,a.node().attrs),...t},c=(null===(s=l.contentMatch.defaultType)||void 0===s?void 0:s.createAndFill(i))||void 0;e=e.append(Rn.from(l.createAndFill(null,c)||void 0));const d=a.before(a.depth-(o-1));n.replace(d,a.after(-r),new _n(e,4-o,0));let u=-1;n.doc.nodesBetween(d,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&0===e.content.size&&(u=t+1)}),u>-1&&n.setSelection(Nr.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}const p=c.pos===a.end()?u.contentMatchAt(0).defaultType:null,f={...ed(h,u.type.name,u.attrs),...t},m={...ed(h,a.node().type.name,a.node().attrs),...t};n.delete(a.pos,c.pos);const g=p?[{type:l,attrs:f},{type:p,attrs:m}]:[{type:l,attrs:f}];if(!ir(n.doc,a.pos,2))return!1;if(r){const{selection:e,storedMarks:t}=o,{splittableMarks:s}=i.extensionManager,l=t||e.$to.parentOffset&&e.$from.marks();if(n.split(a.pos,2,g).scrollIntoView(),!l||!r)return!0;const c=l.filter(e=>s.includes(e.type.name));n.ensureMarks(c)}return!0},toggleList:(e,t,n,o={})=>({editor:r,tr:i,state:s,dispatch:l,chain:a,commands:c,can:d})=>{const{extensions:u,splittableMarks:h}=r.extensionManager,p=Qa(e,s.schema),f=Qa(t,s.schema),{selection:m,storedMarks:g}=s,{$from:y,$to:b}=m,v=y.blockRange(b),x=g||m.$to.parentOffset&&m.$from.marks();if(!v)return!1;const w=Zc(e=>nd(e.type.name,u))(m);if(v.depth>=1&&w&&v.depth-w.depth<=1){if(w.node.type===p)return c.liftListItem(f);if(nd(w.node.type.name,u)&&p.validContent(w.node.content)&&l)return a().command(()=>(i.setNodeMarkup(w.pos,p),!0)).command(()=>ld(i,p)).command(()=>ad(i,p)).run()}return n&&x&&l?a().command(()=>{const e=d().wrapInList(p,o),t=x.filter(e=>h.includes(e.type.name));return i.ensureMarks(t),!!e||c.clearNodes()}).wrapInList(p,o).command(()=>ld(i,p)).command(()=>ad(i,p)).run():a().command(()=>!!d().wrapInList(p,o)||c.clearNodes()).wrapInList(p,o).command(()=>ld(i,p)).command(()=>ad(i,p)).run()},toggleMark:(e,t={},n={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:i=!1}=n,s=Nc(e,o.schema);return td(o,s,t)?r.unsetMark(s,{extendEmptyMarkRange:i}):r.setMark(s,t)},toggleNode:(e,t,n={})=>({state:o,commands:r})=>{const i=Qa(e,o.schema),s=Qa(t,o.schema),l=$c(o,i,n);let a;return o.selection.$anchor.sameParent(o.selection.$head)&&(a=o.selection.$anchor.parent.attrs),l?r.setNode(s,a):r.setNode(i,{...a,...n})},toggleWrap:(e,t={})=>({state:n,commands:o})=>{const r=Qa(e,n.schema);return $c(n,r,t)?o.lift(r):o.wrapIn(r,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let o=0;o<n.length;o+=1){const r=n[o];let i;if(r.spec.isInputRules&&(i=r.getState(e))){if(t){const t=e.tr,n=i.transform;for(let e=n.steps.length-1;e>=0;e-=1)t.step(n.steps[e].invert(n.docs[e]));if(i.text){const n=t.doc.resolve(i.from).marks();t.replaceWith(i.from,i.to,e.schema.text(i.text,n))}else t.delete(i.from,i.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:o,ranges:r}=n;return o||t&&r.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:o,dispatch:r})=>{var i;const{extendEmptyMarkRange:s=!1}=t,{selection:l}=n,a=Nc(e,o.schema),{$from:c,empty:d,ranges:u}=l;if(!r)return!0;if(d&&s){let{from:e,to:t}=l;const o=null===(i=c.marks().find(e=>e.type===a))||void 0===i?void 0:i.attrs,r=jc(c,a,o);r&&(e=r.from,t=r.to),n.removeMark(e,t,a)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,a)});return n.removeStoredMark(a),!0},updateAttributes:(e,t={})=>({tr:n,state:o,dispatch:r})=>{let i=null,s=null;const l=zc("string"==typeof e?e:e.name,o.schema);return!!l&&("node"===l&&(i=Qa(e,o.schema)),"mark"===l&&(s=Nc(e,o.schema)),r&&n.selection.ranges.forEach(e=>{const r=e.$from.pos,l=e.$to.pos;let a,c,d,u;n.selection.empty?o.doc.nodesBetween(r,l,(e,t)=>{i&&i===e.type&&(d=Math.max(t,r),u=Math.min(t+e.nodeSize,l),a=t,c=e)}):o.doc.nodesBetween(r,l,(e,o)=>{o<r&&i&&i===e.type&&(d=Math.max(o,r),u=Math.min(o+e.nodeSize,l),a=o,c=e),o>=r&&o<=l&&(i&&i===e.type&&n.setNodeMarkup(o,void 0,{...e.attrs,...t}),s&&e.marks.length&&e.marks.forEach(i=>{if(s===i.type){const a=Math.max(o,r),c=Math.min(o+e.nodeSize,l);n.addMark(a,c,s.create({...i.attrs,...t}))}}))}),c&&(void 0!==a&&n.setNodeMarkup(a,void 0,{...c.attrs,...t}),s&&c.marks.length&&c.marks.forEach(e=>{s===e.type&&n.addMark(d,u,s.create({...e.attrs,...t}))}))}),!0)},wrapIn:(e,t={})=>({state:n,dispatch:o})=>function(e,t=null){return function(n,o){let{$from:r,$to:i}=n.selection,s=r.blockRange(i),l=s&&tr(s,e,t);return!!l&&(o&&o(n.tr.wrap(s,l).scrollIntoView()),!0)}}(Qa(e,n.schema),t)(n,o),wrapInList:(e,t={})=>({state:n,dispatch:o})=>Wa(Qa(e,n.schema),t)(n,o)});const dd=kc.create({name:"commands",addCommands:()=>({...cd})}),ud=kc.create({name:"drop",addProseMirrorPlugins(){return[new Wr({key:new Kr("tiptapDrop"),props:{handleDrop:(e,t,n,o)=>{this.editor.emit("drop",{editor:this.editor,event:t,slice:n,moved:o})}}})]}}),hd=kc.create({name:"editable",addProseMirrorPlugins(){return[new Wr({key:new Kr("editable"),props:{editable:()=>this.editor.options.editable}})]}}),pd=new Kr("focusEvents"),fd=kc.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new Wr({key:pd,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const o=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(o),!1},blur:(t,n)=>{e.isFocused=!1;const o=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(o),!1}}}})]}}),md=kc.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{const{selection:n,doc:o}=t,{empty:r,$anchor:i}=n,{pos:s,parent:l}=i,a=i.parent.isTextblock&&s>0?t.doc.resolve(s-1):i,c=a.parent.type.spec.isolating,d=i.pos-i.parentOffset,u=c&&1===a.parent.childCount?d===i.pos:Mr.atStart(o).from===s;return!(!r||!l.type.isTextblock||l.textContent.length||!u||u&&"paragraph"===i.parent.type.name)&&e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},o={...n},r={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Ic()||Vc()?r:o},addProseMirrorPlugins(){return[new Wr({key:new Kr("clearDocument"),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta("composition")))return;const o=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),r=e.some(e=>e.getMeta("preventClearDocument"));if(!o||r)return;const{empty:i,from:s,to:l}=t.selection,a=Mr.atStart(t.doc).from,c=Mr.atEnd(t.doc).to;if(i||!(s===a&&l===c))return;if(!od(n.doc))return;const d=n.tr,u=Ga({state:n,transaction:d}),{commands:h}=new Ka({editor:this.editor,state:u});return h.clearNodes(),d.steps.length?d:void 0}})]}}),gd=kc.create({name:"paste",addProseMirrorPlugins(){return[new Wr({key:new Kr("tiptapPaste"),props:{handlePaste:(e,t,n)=>{this.editor.emit("paste",{editor:this.editor,event:t,slice:n})}}})]}}),yd=kc.create({name:"tabindex",addProseMirrorPlugins(){return[new Wr({key:new Kr("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});var bd=Object.freeze({__proto__:null,ClipboardTextSerializer:Sc,Commands:dd,Drop:ud,Editable:hd,FocusEvents:fd,Keymap:md,Paste:gd,Tabindex:yd,focusEventsPluginKey:pd});class vd{get name(){return this.node.type.name}constructor(e,t,n=!1,o=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=o}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return null!==(e=this.actualDepth)&&void 0!==e?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(0===this.content.size)return;t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(0===this.depth)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new vd(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new vd(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new vd(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,n)=>{const o=t.isBlock&&!t.isTextblock,r=t.isAtom&&!t.isText,i=this.pos+n+(r?0:1);if(i<0||i>this.resolvedPos.doc.nodeSize-2)return;const s=this.resolvedPos.doc.resolve(i);if(!o&&s.depth<=this.depth)return;const l=new vd(s,this.editor,o,o?t:null);o&&(l.actualDepth=this.depth+1),e.push(new vd(s,this.editor,o,o?t:null))}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,o=this.parent;for(;o&&!n;){if(o.node.type.name===e)if(Object.keys(t).length>0){const e=o.node.attrs,n=Object.keys(t);for(let o=0;o<n.length;o+=1){const r=n[o];if(e[r]!==t[r])break}}else n=o;o=o.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let o=[];if(!this.children||0===this.children.length)return o;const r=Object.keys(t);return this.children.forEach(i=>{if(!(n&&o.length>0)){if(i.node.type.name===e){r.every(e=>t[e]===i.node.attrs[e])&&o.push(i)}n&&o.length>0||(o=o.concat(i.querySelectorAll(e,t,n)))}}),o}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}}class xd extends Za{constructor(e={}){super(),this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("contentError",this.options.onContentError),this.createView(),this.injectCSS(),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on("paste",({event:e,slice:t})=>this.options.onPaste(e,t)),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&document&&(this.css=function(e,t){const n=document.querySelector("style[data-tiptap-style]");if(null!==n)return n;const o=document.createElement("style");return t&&o.setAttribute("nonce",t),o.setAttribute("data-tiptap-style",""),o.innerHTML=e,document.getElementsByTagName("head")[0].appendChild(o),o}('.ProseMirror {\n position: relative;\n}\n\n.ProseMirror {\n word-wrap: break-word;\n white-space: pre-wrap;\n white-space: break-spaces;\n -webkit-font-variant-ligatures: none;\n font-variant-ligatures: none;\n font-feature-settings: "liga" 0; /* the above doesn\'t seem to work in Edge */\n}\n\n.ProseMirror [contenteditable="false"] {\n white-space: normal;\n}\n\n.ProseMirror [contenteditable="false"] [contenteditable="true"] {\n white-space: pre-wrap;\n}\n\n.ProseMirror pre {\n white-space: pre-wrap;\n}\n\nimg.ProseMirror-separator {\n display: inline !important;\n border: none !important;\n margin: 0 !important;\n width: 0 !important;\n height: 0 !important;\n}\n\n.ProseMirror-gapcursor {\n display: none;\n pointer-events: none;\n position: absolute;\n margin: 0;\n}\n\n.ProseMirror-gapcursor:after {\n content: "";\n display: block;\n position: absolute;\n top: -2px;\n width: 20px;\n border-top: 1px solid black;\n animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;\n}\n\n@keyframes ProseMirror-cursor-blink {\n to {\n visibility: hidden;\n }\n}\n\n.ProseMirror-hideselection *::selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection *::-moz-selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection * {\n caret-color: transparent;\n}\n\n.ProseMirror-focused .ProseMirror-gapcursor {\n display: block;\n}\n\n.tippy-box[data-animation=fade][data-state=hidden] {\n opacity: 0\n}',this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},this.view&&this.state&&!this.isDestroyed&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit("update",{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,t){const n=nc(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],o=this.state.reconfigure({plugins:n});return this.view.updateState(o),o}unregisterPlugin(e){if(this.isDestroyed)return;const t=this.state.plugins;let n=t;if([].concat(e).forEach(e=>{const t="string"==typeof e?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;const o=this.state.reconfigure({plugins:n});return this.view.updateState(o),o}createExtensionManager(){var e,t;const n=[...this.options.enableCoreExtensions?[hd,Sc.configure({blockSeparator:null===(t=null===(e=this.options.coreExtensionOptions)||void 0===e?void 0:e.clipboardTextSerializer)||void 0===t?void 0:t.blockSeparator}),dd,fd,md,yd,ud,gd].filter(e=>"object"!=typeof this.options.enableCoreExtensions||!1!==this.options.enableCoreExtensions[e.name]):[],...this.options.extensions].filter(e=>["extension","node","mark"].includes(null==e?void 0:e.type));this.extensionManager=new wc(n,this)}createCommandManager(){this.commandManager=new Ka({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let t;try{t=Uc(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(r){if(!(r instanceof Error&&["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(r.message)))throw r;this.emit("contentError",{editor:this,error:r,disableCollaboration:()=>{this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>"collaboration"!==e.name),this.createExtensionManager()}}),t=Uc(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const n=_c(t,this.options.autofocus);this.view=new sa(this.options.element,{...this.options.editorProps,attributes:{role:"textbox",...null===(e=this.options.editorProps)||void 0===e?void 0:e.attributes},dispatchTransaction:this.dispatchTransaction.bind(this),state:Fr.create({doc:t,selection:n||void 0})});const o=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(o),this.createNodeViews(),this.prependClass();this.view.dom.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`tiptap ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction)return this.capturedTransaction?void e.steps.forEach(e=>{var t;return null===(t=this.capturedTransaction)||void 0===t?void 0:t.step(e)}):void(this.capturedTransaction=e);const t=this.state.apply(e),n=!this.state.selection.eq(t.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),n&&this.emit("selectionUpdate",{editor:this,transaction:e});const o=e.getMeta("focus"),r=e.getMeta("blur");o&&this.emit("focus",{editor:this,event:o.event,transaction:e}),r&&this.emit("blur",{editor:this,event:r.event,transaction:e}),e.docChanged&&!e.getMeta("preventUpdate")&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return Jc(this.state,e)}isActive(e,t){const n="string"==typeof e?e:null,o="string"==typeof e?t:e;return function(e,t,n={}){if(!t)return $c(e,null,n)||td(e,null,n);const o=zc(t,e.schema);return"node"===o?$c(e,t,n):"mark"===o&&td(e,t,n)}(this.state,n,o)}getJSON(){return this.state.doc.toJSON()}getHTML(){return cc(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t="\n\n",textSerializers:n={}}=e||{};return function(e,t){return Cc(e,{from:0,to:e.content.size},t)}(this.state.doc,{blockSeparator:t,textSerializers:{...Ec(this.schema),...n}})}get isEmpty(){return od(this.state.doc)}getCharacterCount(){return this.state.doc.content.size-2}destroy(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(null===(e=this.view)||void 0===e?void 0:e.docView)}$node(e,t){var n;return(null===(n=this.$doc)||void 0===n?void 0:n.querySelector(e,t))||null}$nodes(e,t){var n;return(null===(n=this.$doc)||void 0===n?void 0:n.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new vd(t,this)}get $doc(){return this.$pos(0)}}function wd(e){return new uc({find:e.find,handler:({state:t,range:n,match:o})=>{const r=oc(e.getAttributes,void 0,o);if(!1===r||null===r)return null;const{tr:i}=t,s=o[o.length-1],l=o[0];if(s){const o=l.search(/\S/),a=n.from+l.indexOf(s),c=a+s.length;if(Qc(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>a).length)return null;c<n.to&&i.delete(c,n.to),a>n.from&&i.delete(n.from+o,a);const d=n.from+o+s.length;i.addMark(n.from+o,d,e.type.create(r||{})),i.removeStoredMark(e.type)}}})}let kd=class e{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length,this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=oc(Ja(this,"addOptions",{name:this.name}))),this.storage=oc(Ja(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new e(t)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>mc(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(t={}){const n=new e(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&Object.keys(t.defaultOptions).length,n.options=oc(Ja(n,"addOptions",{name:n.name})),n.storage=oc(Ja(n,"addStorage",{name:n.name,options:n.options})),n}};class Cd{constructor(e,t,n){this.isDragging=!1,this.component=e,this.editor=t.editor,this.options={stopEvent:null,ignoreMutation:null,...n},this.extension=t.extension,this.node=t.node,this.decorations=t.decorations,this.innerDecorations=t.innerDecorations,this.view=t.view,this.HTMLAttributes=t.HTMLAttributes,this.getPos=t.getPos,this.mount()}mount(){}get dom(){return this.editor.view.dom}get contentDOM(){return null}onDragStart(e){var t,n,o,r,i,s,l;const{view:a}=this.editor,c=e.target,d=3===c.nodeType?null===(t=c.parentElement)||void 0===t?void 0:t.closest("[data-drag-handle]"):c.closest("[data-drag-handle]");if(!this.dom||(null===(n=this.contentDOM)||void 0===n?void 0:n.contains(c))||!d)return;let u=0,h=0;if(this.dom!==d){const t=this.dom.getBoundingClientRect(),n=d.getBoundingClientRect(),l=null!==(o=e.offsetX)&&void 0!==o?o:null===(r=e.nativeEvent)||void 0===r?void 0:r.offsetX,a=null!==(i=e.offsetY)&&void 0!==i?i:null===(s=e.nativeEvent)||void 0===s?void 0:s.offsetY;u=n.x-t.x+l,h=n.y-t.y+a}const p=this.dom.cloneNode(!0);null===(l=e.dataTransfer)||void 0===l||l.setDragImage(p,u,h);const f=this.getPos();if("number"!=typeof f)return;const m=Or.create(a.state.doc,f),g=a.state.tr.setSelection(m);a.dispatch(g)}stopEvent(e){var t;if(!this.dom)return!1;if("function"==typeof this.options.stopEvent)return this.options.stopEvent({event:e});const n=e.target;if(!(this.dom.contains(n)&&!(null===(t=this.contentDOM)||void 0===t?void 0:t.contains(n))))return!1;const o=e.type.startsWith("drag"),r="drop"===e.type;if((["INPUT","BUTTON","SELECT","TEXTAREA"].includes(n.tagName)||n.isContentEditable)&&!r&&!o)return!0;const{isEditable:i}=this.editor,{isDragging:s}=this,l=!!this.node.type.spec.draggable,a=Or.isSelectable(this.node),c="copy"===e.type,d="paste"===e.type,u="cut"===e.type,h="mousedown"===e.type;if(!l&&a&&o&&e.target===this.dom&&e.preventDefault(),l&&o&&!s&&e.target===this.dom)return e.preventDefault(),!1;if(l&&i&&!s&&h){const e=n.closest("[data-drag-handle]");e&&(this.dom===e||this.dom.contains(e))&&(this.isDragging=!0,document.addEventListener("dragend",()=>{this.isDragging=!1},{once:!0}),document.addEventListener("drop",()=>{this.isDragging=!1},{once:!0}),document.addEventListener("mouseup",()=>{this.isDragging=!1},{once:!0}))}return!(s||r||c||d||u||h&&a)}ignoreMutation(e){if(!this.dom||!this.contentDOM)return!0;if("function"==typeof this.options.ignoreMutation)return this.options.ignoreMutation({mutation:e});if(this.node.isLeaf||this.node.isAtom)return!0;if("selection"===e.type)return!1;if(this.dom.contains(e.target)&&"childList"===e.type&&(Ic()||Pc())&&this.editor.isFocused){if([...Array.from(e.addedNodes),...Array.from(e.removedNodes)].every(e=>e.isContentEditable))return!1}return this.contentDOM===e.target&&"attributes"===e.type||!this.contentDOM.contains(e.target)}updateAttributes(e){this.editor.commands.command(({tr:t})=>{const n=this.getPos();return"number"==typeof n&&(t.setNodeMarkup(n,void 0,{...this.node.attrs,...e}),!0)})}deleteNode(){const e=this.getPos();if("number"!=typeof e)return;const t=e+this.node.nodeSize;this.editor.commands.deleteRange({from:e,to:t})}}function Ed(e){return new yc({find:e.find,handler:({state:t,range:n,match:o,pasteEvent:r})=>{const i=oc(e.getAttributes,void 0,o,r);if(!1===i||null===i)return null;const{tr:s}=t,l=o[o.length-1],a=o[0];let c=n.to;if(l){const o=a.search(/\S/),r=n.from+a.indexOf(l),d=r+l.length;if(Qc(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>r).length)return null;d<n.to&&s.delete(d,n.to),r>n.from&&s.delete(n.from+o,r),c=n.from+o+l.length,s.addMark(n.from+o,c,e.type.create(i||{})),s.removeStoredMark(e.type)}}})}var Sd,Md=new Uint8Array(16);function Rd(){if(!Sd&&!(Sd="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Sd(Md)}const Td=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var jd,Nd,Ad=[],Od=0;Od<256;++Od)Ad.push((Od+256).toString(16).substr(1));function _d(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Ad[e[t+0]]+Ad[e[t+1]]+Ad[e[t+2]]+Ad[e[t+3]]+"-"+Ad[e[t+4]]+Ad[e[t+5]]+"-"+Ad[e[t+6]]+Ad[e[t+7]]+"-"+Ad[e[t+8]]+Ad[e[t+9]]+"-"+Ad[e[t+10]]+Ad[e[t+11]]+Ad[e[t+12]]+Ad[e[t+13]]+Ad[e[t+14]]+Ad[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&Td.test(e)}(n))throw TypeError("Stringified UUID is invalid");return n}function Pd(e,t,n){var o=(e=e||{}).random||(e.rng||Rd)();return o[6]=15&o[6]|64,o[8]=63&o[8]|128,_d(o)}if("undefined"!=typeof WeakMap){let e=new WeakMap;jd=t=>e.get(t),Nd=(t,n)=>(e.set(t,n),n)}else{const e=[],t=10;let n=0;jd=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},Nd=(o,r)=>(n==t&&(n=0),e[n++]=o,e[n++]=r)}var Id=class{constructor(e,t,n,o){this.width=e,this.height=t,this.map=n,this.problems=o}findCell(e){for(let t=0;t<this.map.length;t++){const n=this.map[t];if(n!=e)continue;const o=t%this.width,r=t/this.width|0;let i=o+1,s=r+1;for(let e=1;i<this.width&&this.map[t+e]==n;e++)i++;for(let e=1;s<this.height&&this.map[t+this.width*e]==n;e++)s++;return{left:o,top:r,right:i,bottom:s}}throw new 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 new RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){const{left:o,right:r,top:i,bottom:s}=this.findCell(e);return"horiz"==t?(n<0?0==o:r==this.width)?null:this.map[i*this.width+(n<0?o-1:r)]:(n<0?0==i:s==this.height)?null:this.map[o+this.width*(n<0?i-1:s)]}rectBetween(e,t){const{left:n,right:o,top:r,bottom:i}=this.findCell(e),{left:s,right:l,top:a,bottom:c}=this.findCell(t);return{left:Math.min(n,s),top:Math.min(r,a),right:Math.max(o,l),bottom:Math.max(i,c)}}cellsInRect(e){const t=[],n={};for(let o=e.top;o<e.bottom;o++)for(let r=e.left;r<e.right;r++){const i=o*this.width+r,s=this.map[i];n[s]||(n[s]=!0,r==e.left&&r&&this.map[i-1]==s||o==e.top&&o&&this.map[i-this.width]==s||t.push(s))}return t}positionAt(e,t,n){for(let o=0,r=0;;o++){const i=r+n.child(o).nodeSize;if(o==e){let n=t+e*this.width;const o=(e+1)*this.width;for(;n<o&&this.map[n]<r;)n++;return n==o?i-1:this.map[n]}r=i}}static get(e){return jd(e)||Nd(e,function(e){if("table"!=e.type.spec.tableRole)throw new RangeError("Not a table node: "+e.type.name);const t=function(e){let t=-1,n=!1;for(let o=0;o<e.childCount;o++){const r=e.child(o);let i=0;if(n)for(let t=0;t<o;t++){const n=e.child(t);for(let e=0;e<n.childCount;e++){const r=n.child(e);t+r.attrs.rowspan>o&&(i+=r.attrs.colspan)}}for(let e=0;e<r.childCount;e++){const t=r.child(e);i+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}-1==t?t=i:t!=i&&(t=Math.max(t,i))}return t}(e),n=e.childCount,o=[];let r=0,i=null;const s=[];for(let c=0,d=t*n;c<d;c++)o[c]=0;for(let c=0,d=0;c<n;c++){const l=e.child(c);d++;for(let e=0;;e++){for(;r<o.length&&0!=o[r];)r++;if(e==l.childCount)break;const a=l.child(e),{colspan:u,rowspan:h,colwidth:p}=a.attrs;for(let e=0;e<h;e++){if(e+c>=n){(i||(i=[])).push({type:"overlong_rowspan",pos:d,n:h-e});break}const l=r+e*t;for(let e=0;e<u;e++){0==o[l+e]?o[l+e]=d:(i||(i=[])).push({type:"collision",row:c,pos:d,n:u-e});const n=p&&p[e];if(n){const o=(l+e)%t*2,r=s[o];null==r||r!=n&&1==s[o+1]?(s[o]=n,s[o+1]=1):r==n&&s[o+1]++}}}r+=u,d+=a.nodeSize}const a=(c+1)*t;let u=0;for(;r<a;)0==o[r++]&&u++;u&&(i||(i=[])).push({type:"missing",row:c,n:u}),d++}0!==t&&0!==n||(i||(i=[])).push({type:"zero_sized"});const l=new Id(t,n,o,i);let a=!1;for(let c=0;!a&&c<s.length;c+=2)null!=s[c]&&s[c+1]<n&&(a=!0);a&&function(e,t,n){e.problems||(e.problems=[]);const o={};for(let r=0;r<e.map.length;r++){const i=e.map[r];if(o[i])continue;o[i]=!0;const s=n.nodeAt(i);if(!s)throw new RangeError(`No cell with offset ${i} found`);let l=null;const a=s.attrs;for(let n=0;n<a.colspan;n++){const o=t[2*((r+n)%e.width)];null==o||a.colwidth&&a.colwidth[n]==o||((l||(l=Ld(a)))[n]=o)}l&&e.problems.unshift({type:"colwidth mismatch",pos:i,colwidth:l})}}(l,s,e);return l}(e))}};function Ld(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function Dd(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(const n in e.nodes){const o=e.nodes[n],r=o.spec.tableRole;r&&(t[r]=o)}}return t}var Bd=new Kr("selectingCells");function Hd(e){for(let t=e.depth-1;t>0;t--)if("row"==e.node(t).type.spec.tableRole)return e.node(0).resolve(e.before(t+1));return null}function Vd(e){const t=e.selection.$head;for(let n=t.depth;n>0;n--)if("row"==t.node(n).type.spec.tableRole)return!0;return!1}function $d(e){const 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&&"cell"==t.node.type.spec.tableRole)return t.$anchor;const n=Hd(t.$head)||function(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){const o=t.type.spec.tableRole;if("cell"==o||"header_cell"==o)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){const o=t.type.spec.tableRole;if("cell"==o||"header_cell"==o)return e.doc.resolve(n-t.nodeSize)}}(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function zd(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function Fd(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function Ud(e,t,n){const o=e.node(-1),r=Id.get(o),i=e.start(-1),s=r.nextCell(e.pos-i,t,n);return null==s?null:e.node(0).resolve(i+s)}function Wd(e,t,n=1){const o={...e,colspan:e.colspan-n};return o.colwidth&&(o.colwidth=o.colwidth.slice(),o.colwidth.splice(t,n),o.colwidth.some(e=>e>0)||(o.colwidth=null)),o}function qd(e,t,n=1){const o={...e,colspan:e.colspan+n};if(o.colwidth){o.colwidth=o.colwidth.slice();for(let e=0;e<n;e++)o.colwidth.splice(t,0,0)}return o}var Gd=class e extends Mr{constructor(e,t=e){const n=e.node(-1),o=Id.get(n),r=e.start(-1),i=o.rectBetween(e.pos-r,t.pos-r),s=e.node(0),l=o.cellsInRect(i).filter(e=>e!=t.pos-r);l.unshift(t.pos-r);const a=l.map(e=>{const t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);const o=r+e+1;return new Rr(s.resolve(o),s.resolve(o+t.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(t,n){const o=t.resolve(n.map(this.$anchorCell.pos)),r=t.resolve(n.map(this.$headCell.pos));if(zd(o)&&zd(r)&&Fd(o,r)){const t=this.$anchorCell.node(-1)!=o.node(-1);return t&&this.isRowSelection()?e.rowSelection(o,r):t&&this.isColSelection()?e.colSelection(o,r):new e(o,r)}return Nr.between(o,r)}content(){const e=this.$anchorCell.node(-1),t=Id.get(e),n=this.$anchorCell.start(-1),o=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),r={},i=[];for(let l=o.top;l<o.bottom;l++){const n=[];for(let i=l*t.width+o.left,s=o.left;s<o.right;s++,i++){const s=t.map[i];if(r[s])continue;r[s]=!0;const l=t.findCell(s);let a=e.nodeAt(s);if(!a)throw RangeError(`No cell with offset ${s} found`);const c=o.left-l.left,d=l.right-o.right;if(c>0||d>0){let e=a.attrs;if(c>0&&(e=Wd(e,0,c)),d>0&&(e=Wd(e,e.colspan-d,d)),l.left<o.left){if(a=a.type.createAndFill(e),!a)throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else a=a.type.create(e,a.content)}if(l.top<o.top||l.bottom>o.bottom){const e={...a.attrs,rowspan:Math.min(l.bottom,o.bottom)-Math.max(l.top,o.top)};a=l.top<o.top?a.type.createAndFill(e):a.type.create(e,a.content)}n.push(a)}i.push(e.child(l).copy(Rn.from(n)))}const s=this.isColSelection()&&this.isRowSelection()?e:i;return new _n(Rn.from(s),1,1)}replace(e,t=_n.empty){const n=e.steps.length,o=this.ranges;for(let i=0;i<o.length;i++){const{$from:r,$to:s}=o[i],l=e.mapping.slice(n);e.replace(l.map(r.pos),l.map(s.pos),i?_n.empty:t)}const r=Mr.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);r&&e.setSelection(r)}replaceWith(e,t){this.replace(e,new _n(Rn.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),n=Id.get(t),o=this.$anchorCell.start(-1),r=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-o,this.$headCell.pos-o));for(let i=0;i<r.length;i++)e(t.nodeAt(r[i]),o+r[i])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,o=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,o)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){const o=t.node(-1),r=Id.get(o),i=t.start(-1),s=r.findCell(t.pos-i),l=r.findCell(n.pos-i),a=t.node(0);return s.top<=l.top?(s.top>0&&(t=a.resolve(i+r.map[s.left])),l.bottom<r.height&&(n=a.resolve(i+r.map[r.width*(r.height-1)+l.right-1]))):(l.top>0&&(n=a.resolve(i+r.map[l.left])),s.bottom<r.height&&(t=a.resolve(i+r.map[r.width*(r.height-1)+s.right-1]))),new e(t,n)}isRowSelection(){const e=this.$anchorCell.node(-1),t=Id.get(e),n=this.$anchorCell.start(-1),o=t.colCount(this.$anchorCell.pos-n),r=t.colCount(this.$headCell.pos-n);if(Math.min(o,r)>0)return!1;const i=o+this.$anchorCell.nodeAfter.attrs.colspan,s=r+this.$headCell.nodeAfter.attrs.colspan;return Math.max(i,s)==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){const o=t.node(-1),r=Id.get(o),i=t.start(-1),s=r.findCell(t.pos-i),l=r.findCell(n.pos-i),a=t.node(0);return s.left<=l.left?(s.left>0&&(t=a.resolve(i+r.map[s.top*r.width])),l.right<r.width&&(n=a.resolve(i+r.map[r.width*(l.top+1)-1]))):(l.left>0&&(n=a.resolve(i+r.map[l.top*r.width])),s.right<r.width&&(t=a.resolve(i+r.map[r.width*(s.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,o=n){return new e(t.resolve(n),t.resolve(o))}getBookmark(){return new Kd(this.$anchorCell.pos,this.$headCell.pos)}};Gd.prototype.visible=!1,Mr.jsonID("cell",Gd);var Kd=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){const t=e.resolve(this.anchor),n=e.resolve(this.head);return"row"==t.parent.type.spec.tableRole&&"row"==n.parent.type.spec.tableRole&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&Fd(t,n)?new Gd(t,n):Mr.near(n,1)}};function Zd(e){if(!(e.selection instanceof Gd))return null;const t=[];return e.selection.forEachCell((e,n)=>{t.push(Ol.node(n,n+e.nodeSize,{class:"selectedCell"}))}),Il.create(e.doc,t)}var Jd=new Kr("fix-tables");function Xd(e,t,n,o){const r=e.childCount,i=t.childCount;e:for(let s=0,l=0;s<i;s++){const i=t.child(s);for(let t=l,o=Math.min(r,s+3);t<o;t++)if(e.child(t)==i){l=t+1,n+=i.nodeSize;continue e}o(i,n),l<r&&e.child(l).sameMarkup(i)?Xd(e.child(l),i,n+1,o):i.nodesBetween(0,i.content.size,o,n+1),n+=i.nodeSize}}function Yd(e,t){let n;const o=(t,o)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,o){const r=Id.get(t);if(!r.problems)return o;o||(o=e.tr);const i=[];for(let a=0;a<r.height;a++)i.push(0);for(let a=0;a<r.problems.length;a++){const e=r.problems[a];if("collision"==e.type){const r=t.nodeAt(e.pos);if(!r)continue;const s=r.attrs;for(let t=0;t<s.rowspan;t++)i[e.row+t]+=e.n;o.setNodeMarkup(o.mapping.map(n+1+e.pos),null,Wd(s,s.colspan-e.n,e.n))}else if("missing"==e.type)i[e.row]+=e.n;else if("overlong_rowspan"==e.type){const r=t.nodeAt(e.pos);if(!r)continue;o.setNodeMarkup(o.mapping.map(n+1+e.pos),null,{...r.attrs,rowspan:r.attrs.rowspan-e.n})}else if("colwidth mismatch"==e.type){const r=t.nodeAt(e.pos);if(!r)continue;o.setNodeMarkup(o.mapping.map(n+1+e.pos),null,{...r.attrs,colwidth:e.colwidth})}else if("zero_sized"==e.type){const e=o.mapping.map(n);o.delete(e,e+t.nodeSize)}}let s,l;for(let a=0;a<i.length;a++)i[a]&&(null==s&&(s=a),l=a);for(let a=0,c=n+1;a<r.height;a++){const n=t.child(a),r=c+n.nodeSize,d=i[a];if(d>0){let t="cell";n.firstChild&&(t=n.firstChild.type.spec.tableRole);const i=[];for(let n=0;n<d;n++){const n=Dd(e.schema)[t].createAndFill();n&&i.push(n)}const u=0!=a&&s!=a-1||l!=a?r-1:c+1;o.insert(o.mapping.map(u),i)}c=r}return o.setMeta(Jd,{fixTables:!0})}(e,t,o,n))};return t?t.doc!=e.doc&&Xd(t.doc,e.doc,0,o):e.doc.descendants(o),n}function Qd(e){const t=e.selection,n=$d(e),o=n.node(-1),r=n.start(-1),i=Id.get(o);return{...t instanceof Gd?i.rectBetween(t.$anchorCell.pos-r,t.$headCell.pos-r):i.findCell(n.pos-r),tableStart:r,map:i,table:o}}function eu(e,{map:t,tableStart:n,table:o},r){let i=r>0?-1:0;(function(e,t,n){const o=Dd(t.type.schema).header_cell;for(let r=0;r<e.height;r++)if(t.nodeAt(e.map[n+r*e.width]).type!=o)return!1;return!0})(t,o,r+i)&&(i=0==r||r==t.width?null:0);for(let s=0;s<t.height;s++){const l=s*t.width+r;if(r>0&&r<t.width&&t.map[l-1]==t.map[l]){const i=t.map[l],a=o.nodeAt(i);e.setNodeMarkup(e.mapping.map(n+i),null,qd(a.attrs,r-t.colCount(i))),s+=a.attrs.rowspan-1}else{const a=null==i?Dd(o.type.schema).cell:o.nodeAt(t.map[l+i]).type,c=t.positionAt(s,r,o);e.insert(e.mapping.map(n+c),a.createAndFill())}}return e}function tu(e,{map:t,table:n,tableStart:o},r){const i=e.mapping.maps.length;for(let s=0;s<t.height;){const l=s*t.width+r,a=t.map[l],c=n.nodeAt(a),d=c.attrs;if(r>0&&t.map[l-1]==a||r<t.width-1&&t.map[l+1]==a)e.setNodeMarkup(e.mapping.slice(i).map(o+a),null,Wd(d,r-t.colCount(a)));else{const t=e.mapping.slice(i).map(o+a);e.delete(t,t+c.nodeSize)}s+=d.rowspan}}function nu(e,{map:t,tableStart:n,table:o},r){var i;let s=n;for(let c=0;c<r;c++)s+=o.child(c).nodeSize;const l=[];let a=r>0?-1:0;(function(e,t,n){var o;const r=Dd(t.type.schema).header_cell;for(let i=0;i<e.width;i++)if((null==(o=t.nodeAt(e.map[i+n*e.width]))?void 0:o.type)!=r)return!1;return!0})(t,o,r+a)&&(a=0==r||r==t.height?null:0);for(let c=0,d=t.width*r;c<t.width;c++,d++)if(r>0&&r<t.height&&t.map[d]==t.map[d-t.width]){const r=t.map[d],i=o.nodeAt(r).attrs;e.setNodeMarkup(n+r,null,{...i,rowspan:i.rowspan+1}),c+=i.colspan-1}else{const e=null==a?Dd(o.type.schema).cell:null==(i=o.nodeAt(t.map[d+a*t.width]))?void 0:i.type,n=null==e?void 0:e.createAndFill();n&&l.push(n)}return e.insert(s,Dd(o.type.schema).row.create(null,l)),e}function ou(e,{map:t,table:n,tableStart:o},r){let i=0;for(let c=0;c<r;c++)i+=n.child(c).nodeSize;const s=i+n.child(r).nodeSize,l=e.mapping.maps.length;e.delete(i+o,s+o);const a=new Set;for(let c=0,d=r*t.width;c<t.width;c++,d++){const i=t.map[d];if(!a.has(i))if(a.add(i),r>0&&i==t.map[d-t.width]){const t=n.nodeAt(i).attrs;e.setNodeMarkup(e.mapping.slice(l).map(i+o),null,{...t,rowspan:t.rowspan-1}),c+=t.colspan-1}else if(r<t.height&&i==t.map[d+t.width]){const s=n.nodeAt(i),a=s.attrs,d=s.type.create({...a,rowspan:s.attrs.rowspan-1},s.content),u=t.positionAt(r+1,c,n);e.insert(e.mapping.slice(l).map(o+u),d),c+=a.colspan-1}}}function ru(e){const t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function iu(e,t){const n=Dd(e.schema);return(o=({node:e})=>n[e.type.spec.tableRole],(e,t)=>{var n;const r=e.selection;let i,s;if(r instanceof Gd){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,s=r.$anchorCell.pos}else{if(i=function(e){for(let t=e.depth;t>0;t--){const n=e.node(t).type.spec.tableRole;if("cell"===n||"header_cell"===n)return e.node(t)}return null}(r.$from),!i)return!1;s=null==(n=Hd(r.$from))?void 0:n.pos}if(null==i||null==s)return!1;if(1==i.attrs.colspan&&1==i.attrs.rowspan)return!1;if(t){let n=i.attrs;const l=[],a=n.colwidth;n.rowspan>1&&(n={...n,rowspan:1}),n.colspan>1&&(n={...n,colspan:1});const c=Qd(e),d=e.tr;for(let e=0;e<c.right-c.left;e++)l.push(a?{...n,colwidth:a&&a[e]?[a[e]]:null}:n);let u;for(let e=c.top;e<c.bottom;e++){let t=c.map.positionAt(e,c.left,c.table);e==c.top&&(t+=i.nodeSize);for(let n=c.left,r=0;n<c.right;n++,r++)n==c.left&&e==c.top||d.insert(u=d.mapping.map(t+c.tableStart,1),o({node:i,row:e,col:n}).createAndFill(l[r]))}d.setNodeMarkup(s,o({node:i,row:c.top,col:c.left}),l[0]),r instanceof Gd&&d.setSelection(new Gd(d.doc.resolve(r.$anchorCell.pos),u?d.doc.resolve(u):void 0)),t(d)}return!0})(e,t);var o}function su(e,t,n){const o=t.map.cellsInRect({left:0,top:0,right:"row"==e?t.map.width:1,bottom:"column"==e?t.map.height:1});for(let r=0;r<o.length;r++){const e=t.table.nodeAt(o[r]);if(e&&e.type!==n.header_cell)return!1}return!0}function lu(e,t){return(t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic?function(e){return function(t,n){if(!Vd(t))return!1;if(n){const o=Dd(t.schema),r=Qd(t),i=t.tr,s=r.map.cellsInRect("column"==e?{left:r.left,top:0,right:r.right,bottom:r.map.height}:"row"==e?{left:0,top:r.top,right:r.map.width,bottom:r.bottom}:r),l=s.map(e=>r.table.nodeAt(e));for(let e=0;e<s.length;e++)l[e].type==o.header_cell&&i.setNodeMarkup(r.tableStart+s[e],o.cell,l[e].attrs);if(0==i.steps.length)for(let e=0;e<s.length;e++)i.setNodeMarkup(r.tableStart+s[e],o.header_cell,l[e].attrs);n(i)}return!0}}(e):function(t,n){if(!Vd(t))return!1;if(n){const o=Dd(t.schema),r=Qd(t),i=t.tr,s=su("row",r,o),l=su("column",r,o),a=("column"===e?s:"row"===e&&l)?1:0,c="column"==e?{left:0,top:a,right:1,bottom:r.map.height}:"row"==e?{left:a,top:0,right:r.map.width,bottom:1}:r,d="column"==e?l?o.cell:o.header_cell:"row"==e?s?o.cell:o.header_cell:o.cell;r.map.cellsInRect(c).forEach(e=>{const t=e+r.tableStart,n=i.doc.nodeAt(t);n&&i.setNodeMarkup(t,d,n.attrs)}),n(i)}return!0}}function au(e){return function(t,n){if(!Vd(t))return!1;const o=function(e,t){if(t<0){const t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let n=e.index(-1)-1,o=e.before();n>=0;n--){const t=e.node(-1).child(n),r=t.lastChild;if(r)return o-1-r.nodeSize;o-=t.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;const t=e.node(-1);for(let n=e.indexAfter(-1),o=e.after();n<t.childCount;n++){const e=t.child(n);if(e.childCount)return o+1;o+=e.nodeSize}}return null}($d(t),e);if(null==o)return!1;if(n){const e=t.doc.resolve(o);n(t.tr.setSelection(Nr.between(e,(r=e,r.node(0).resolve(r.pos+r.nodeAfter.nodeSize)))).scrollIntoView())}var r;return!0}}function cu(e,t){const n=e.selection;if(!(n instanceof Gd))return!1;if(t){const o=e.tr,r=Dd(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(r)||o.replace(o.mapping.map(t+1),o.mapping.map(t+e.nodeSize-1),new _n(r,0,0))}),o.docChanged&&t(o)}return!0}function du(e){if(!e.size)return null;let{content:t,openStart:n,openEnd:o}=e;for(;1==t.childCount&&(n>0&&o>0||"table"==t.child(0).type.spec.tableRole);)n--,o--,t=t.child(0).content;const r=t.child(0),i=r.type.spec.tableRole,s=r.type.schema,l=[];if("row"==i)for(let a=0;a<t.childCount;a++){let e=t.child(a).content;const r=a?0:Math.max(0,n-1),i=a<t.childCount-1?0:Math.max(0,o-1);(r||i)&&(e=uu(Dd(s).row,new _n(e,r,i)).content),l.push(e)}else{if("cell"!=i&&"header_cell"!=i)return null;l.push(n||o?uu(Dd(s).row,new _n(t,n,o)).content:t)}return function(e,t){const n=[];for(let r=0;r<t.length;r++){const e=t[r];for(let t=e.childCount-1;t>=0;t--){const{rowspan:o,colspan:i}=e.child(t).attrs;for(let e=r;e<r+o;e++)n[e]=(n[e]||0)+i}}let o=0;for(let r=0;r<n.length;r++)o=Math.max(o,n[r]);for(let r=0;r<n.length;r++)if(r>=t.length&&t.push(Rn.empty),n[r]<o){const i=Dd(e).cell.createAndFill(),s=[];for(let e=n[r];e<o;e++)s.push(i);t[r]=t[r].append(Rn.from(s))}return{height:t.length,width:o,rows:t}}(s,l)}function uu(e,t){const n=e.createAndFill();return new Er(n).replace(0,n.content.size,t).doc}function hu(e,t,n,o,r,i,s,l){if(0==s||s==t.height)return!1;let a=!1;for(let c=r;c<i;c++){const r=s*t.width+c,i=t.map[r];if(t.map[r-t.width]==i){a=!0;const r=n.nodeAt(i),{top:d,left:u}=t.findCell(i);e.setNodeMarkup(e.mapping.slice(l).map(i+o),null,{...r.attrs,rowspan:s-d}),e.insert(e.mapping.slice(l).map(t.positionAt(s,u,n)),r.type.createAndFill({...r.attrs,rowspan:d+r.attrs.rowspan-s})),c+=r.attrs.colspan-1}}return a}function pu(e,t,n,o,r,i,s,l){if(0==s||s==t.width)return!1;let a=!1;for(let c=r;c<i;c++){const r=c*t.width+s,i=t.map[r];if(t.map[r-1]==i){a=!0;const r=n.nodeAt(i),d=t.colCount(i),u=e.mapping.slice(l).map(i+o);e.setNodeMarkup(u,null,Wd(r.attrs,s-d,r.attrs.colspan-(s-d))),e.insert(u+r.nodeSize,r.type.createAndFill(Wd(r.attrs,0,s-d))),c+=r.attrs.rowspan-1}}return a}function fu(e,t,n,o,r){let i=n?e.doc.nodeAt(n-1):e.doc;if(!i)throw new Error("No table found");let s=Id.get(i);const{top:l,left:a}=o,c=a+r.width,d=l+r.height,u=e.tr;let h=0;function p(){if(i=n?u.doc.nodeAt(n-1):u.doc,!i)throw new Error("No table found");s=Id.get(i),h=u.mapping.maps.length}(function(e,t,n,o,r,i,s){const l=Dd(e.doc.type.schema);let a,c;if(r>t.width)for(let d=0,u=0;d<t.height;d++){const i=n.child(d);u+=i.nodeSize;const h=[];let p;p=null==i.lastChild||i.lastChild.type==l.cell?a||(a=l.cell.createAndFill()):c||(c=l.header_cell.createAndFill());for(let e=t.width;e<r;e++)h.push(p);e.insert(e.mapping.slice(s).map(u-1+o),h)}if(i>t.height){const d=[];for(let e=0,o=(t.height-1)*t.width;e<Math.max(t.width,r);e++){const r=!(e>=t.width)&&n.nodeAt(t.map[o+e]).type==l.header_cell;d.push(r?c||(c=l.header_cell.createAndFill()):a||(a=l.cell.createAndFill()))}const u=l.row.create(null,Rn.from(d)),h=[];for(let e=t.height;e<i;e++)h.push(u);e.insert(e.mapping.slice(s).map(o+n.nodeSize-2),h)}return!(!a&&!c)})(u,s,i,n,c,d,h)&&p(),hu(u,s,i,n,a,c,l,h)&&p(),hu(u,s,i,n,a,c,d,h)&&p(),pu(u,s,i,n,l,d,a,h)&&p(),pu(u,s,i,n,l,d,c,h)&&p();for(let f=l;f<d;f++){const e=s.positionAt(f,a,i),t=s.positionAt(f,c,i);u.replace(u.mapping.slice(h).map(e+n),u.mapping.slice(h).map(t+n),new _n(r.rows[f-l],0,0))}p(),u.setSelection(new Gd(u.doc.resolve(n+s.positionAt(l,a,i)),u.doc.resolve(n+s.positionAt(d-1,c-1,i)))),t(u)}lu("row",{useDeprecatedLogic:!0}),lu("column",{useDeprecatedLogic:!0}),lu("cell",{useDeprecatedLogic:!0});var mu=ka({ArrowLeft:yu("horiz",-1),ArrowRight:yu("horiz",1),ArrowUp:yu("vert",-1),ArrowDown:yu("vert",1),"Shift-ArrowLeft":bu("horiz",-1),"Shift-ArrowRight":bu("horiz",1),"Shift-ArrowUp":bu("vert",-1),"Shift-ArrowDown":bu("vert",1),Backspace:cu,"Mod-Backspace":cu,Delete:cu,"Mod-Delete":cu});function gu(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function yu(e,t){return(n,o,r)=>{if(!r)return!1;const i=n.selection;if(i instanceof Gd)return gu(n,o,Mr.near(i.$headCell,t));if("horiz"!=e&&!i.empty)return!1;const s=ku(r,e,t);if(null==s)return!1;if("horiz"==e)return gu(n,o,Mr.near(n.doc.resolve(i.head+t),t));{const r=n.doc.resolve(s),i=Ud(r,e,t);let l;return l=i?Mr.near(i,1):t<0?Mr.near(n.doc.resolve(r.before(-1)),-1):Mr.near(n.doc.resolve(r.after(-1)),1),gu(n,o,l)}}}function bu(e,t){return(n,o,r)=>{if(!r)return!1;const i=n.selection;let s;if(i instanceof Gd)s=i;else{const o=ku(r,e,t);if(null==o)return!1;s=new Gd(n.doc.resolve(o))}const l=Ud(s.$headCell,e,t);return!!l&&gu(n,o,new Gd(s.$anchorCell,l))}}function vu(e,t){const n=Hd(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new Gd(n))),!0)}function xu(e,t,n){if(!Vd(e.state))return!1;let o=du(n);const r=e.state.selection;if(r instanceof Gd){o||(o={width:1,height:1,rows:[Rn.from(uu(Dd(e.state.schema).cell,n))]});const t=r.$anchorCell.node(-1),i=r.$anchorCell.start(-1),s=Id.get(t).rectBetween(r.$anchorCell.pos-i,r.$headCell.pos-i);return o=function({width:e,height:t,rows:n},o,r){if(e!=o){const t=[],r=[];for(let e=0;e<n.length;e++){const i=n[e],s=[];for(let n=t[e]||0,r=0;n<o;r++){let l=i.child(r%i.childCount);n+l.attrs.colspan>o&&(l=l.type.createChecked(Wd(l.attrs,l.attrs.colspan,n+l.attrs.colspan-o),l.content)),s.push(l),n+=l.attrs.colspan;for(let n=1;n<l.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+l.attrs.colspan}r.push(Rn.from(s))}n=r,e=o}if(t!=r){const e=[];for(let o=0,i=0;o<r;o++,i++){const s=[],l=n[i%t];for(let e=0;e<l.childCount;e++){let t=l.child(e);o+t.attrs.rowspan>r&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,r-t.attrs.rowspan)},t.content)),s.push(t)}e.push(Rn.from(s))}n=e,t=r}return{width:e,height:t,rows:n}}(o,s.right-s.left,s.bottom-s.top),fu(e.state,e.dispatch,i,s,o),!0}if(o){const t=$d(e.state),n=t.start(-1);return fu(e.state,e.dispatch,n,Id.get(t.node(-1)).findCell(t.pos-n),o),!0}return!1}function wu(e,t){var n;if(t.ctrlKey||t.metaKey)return;const o=Cu(e,t.target);let r;if(t.shiftKey&&e.state.selection instanceof Gd)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&o&&null!=(r=Hd(e.state.selection.$anchor))&&(null==(n=Eu(e,t))?void 0:n.pos)!=r.pos)i(r,t),t.preventDefault();else if(!o)return;function i(t,n){let o=Eu(e,n);const r=null==Bd.getState(e.state);if(!o||!Fd(t,o)){if(!r)return;o=t}const i=new Gd(t,o);if(r||!e.state.selection.eq(i)){const n=e.state.tr.setSelection(i);r&&n.setMeta(Bd,t.pos),e.dispatch(n)}}function s(){e.root.removeEventListener("mouseup",s),e.root.removeEventListener("dragstart",s),e.root.removeEventListener("mousemove",l),null!=Bd.getState(e.state)&&e.dispatch(e.state.tr.setMeta(Bd,-1))}function l(n){const r=n,l=Bd.getState(e.state);let a;if(null!=l)a=e.state.doc.resolve(l);else if(Cu(e,r.target)!=o&&(a=Eu(e,t),!a))return s();a&&i(a,r)}e.root.addEventListener("mouseup",s),e.root.addEventListener("dragstart",s),e.root.addEventListener("mousemove",l)}function ku(e,t,n){if(!(e.state.selection instanceof Nr))return null;const{$head:o}=e.state.selection;for(let r=o.depth-1;r>=0;r--){const i=o.node(r);if((n<0?o.index(r):o.indexAfter(r))!=(n<0?0:i.childCount))return null;if("cell"==i.type.spec.tableRole||"header_cell"==i.type.spec.tableRole){const i=o.before(r),s="vert"==t?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(s)?i:null}}return null}function Cu(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function Eu(e,t){const n=e.posAtCoords({left:t.clientX,top:t.clientY});return n&&n?Hd(e.state.doc.resolve(n.pos)):null}var Su=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Mu(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type==this.node.type&&(this.node=e,Mu(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function Mu(e,t,n,o,r,i){var s;let l=0,a=!0,c=t.firstChild;const d=e.firstChild;if(d){for(let e=0,n=0;e<d.childCount;e++){const{colspan:s,colwidth:u}=d.child(e).attrs;for(let e=0;e<s;e++,n++){const s=r==n?i:u&&u[e],d=s?s+"px":"";if(l+=s||o,s||(a=!1),c)c.style.width!=d&&(c.style.width=d),c=c.nextSibling;else{const e=document.createElement("col");e.style.width=d,t.appendChild(e)}}}for(;c;){const e=c.nextSibling;null==(s=c.parentNode)||s.removeChild(c),c=e}a?(n.style.width=l+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=l+"px")}}var Ru=new Kr("tableColumnResizing");function Tu({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:o=Su,lastColumnResizable:r=!0}={}){const i=new Wr({key:Ru,state:{init(e,t){var r,s;const l=null==(s=null==(r=i.spec)?void 0:r.props)?void 0:s.nodeViews,a=Dd(t.schema).table.name;return o&&l&&(l[a]=(e,t)=>new o(e,n,t)),new ju(-1,!1)},apply:(e,t)=>t.apply(e)},props:{attributes:e=>{const t=Ru.getState(e);return t&&t.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(t,n)=>{!function(e,t,n,o){if(!e.editable)return;const r=Ru.getState(e.state);if(!r)return;if(!r.dragging){const i=function(e){for(;e&&"TD"!=e.nodeName&&"TH"!=e.nodeName;)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}(t.target);let s=-1;if(i){const{left:o,right:r}=i.getBoundingClientRect();t.clientX-o<=n?s=Nu(e,t,"left",n):r-t.clientX<=n&&(s=Nu(e,t,"right",n))}if(s!=r.activeHandle){if(!o&&-1!==s){const t=e.state.doc.resolve(s),n=t.node(-1),o=Id.get(n),r=t.start(-1);if(o.colCount(t.pos-r)+t.nodeAfter.attrs.colspan-1==o.width-1)return}Ou(e,s)}}}(t,n,e,r)},mouseleave:e=>{!function(e){if(!e.editable)return;const t=Ru.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Ou(e,-1)}(e)},mousedown:(e,o)=>{!function(e,t,n,o){var r;if(!e.editable)return!1;const i=null!=(r=e.dom.ownerDocument.defaultView)?r:window,s=Ru.getState(e.state);if(!s||-1==s.activeHandle||s.dragging)return!1;const l=e.state.doc.nodeAt(s.activeHandle),a=function(e,t,{colspan:n,colwidth:o}){const r=o&&o[o.length-1];if(r)return r;const i=e.domAtPos(t);let s=i.node.childNodes[i.offset].offsetWidth,l=n;if(o)for(let a=0;a<n;a++)o[a]&&(s-=o[a],l--);return s/l}(e,s.activeHandle,l.attrs);function c(t){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",d);const o=Ru.getState(e.state);(null==o?void 0:o.dragging)&&(!function(e,t,n){const o=e.state.doc.resolve(t),r=o.node(-1),i=Id.get(r),s=o.start(-1),l=i.colCount(o.pos-s)+o.nodeAfter.attrs.colspan-1,a=e.state.tr;for(let c=0;c<i.height;c++){const e=c*i.width+l;if(c&&i.map[e]==i.map[e-i.width])continue;const t=i.map[e],o=r.nodeAt(t).attrs,d=1==o.colspan?0:l-i.colCount(t);if(o.colwidth&&o.colwidth[d]==n)continue;const u=o.colwidth?o.colwidth.slice():Pu(o.colspan);u[d]=n,a.setNodeMarkup(s+t,null,{...o,colwidth:u})}a.docChanged&&e.dispatch(a)}(e,o.activeHandle,Au(o.dragging,t,n)),e.dispatch(e.state.tr.setMeta(Ru,{setDragging:null})))}function d(t){if(!t.which)return c(t);const r=Ru.getState(e.state);if(r&&r.dragging){const i=Au(r.dragging,t,n);_u(e,r.activeHandle,i,o)}}e.dispatch(e.state.tr.setMeta(Ru,{setDragging:{startX:t.clientX,startWidth:a}})),_u(e,s.activeHandle,a,o),i.addEventListener("mouseup",c),i.addEventListener("mousemove",d),t.preventDefault()}(e,o,t,n)}},decorations:e=>{const t=Ru.getState(e);if(t&&t.activeHandle>-1)return function(e,t){var n;const o=[],r=e.doc.resolve(t),i=r.node(-1);if(!i)return Il.empty;const s=Id.get(i),l=r.start(-1),a=s.colCount(r.pos-l)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<s.height;c++){const t=a+c*s.width;if(!(a!=s.width-1&&s.map[t]==s.map[t+1]||0!=c&&s.map[t]==s.map[t-s.width])){const r=s.map[t],a=l+r+i.nodeAt(r).nodeSize-1,c=document.createElement("div");c.className="column-resize-handle",(null==(n=Ru.getState(e))?void 0:n.dragging)&&o.push(Ol.node(l+r,l+r+i.nodeAt(r).nodeSize,{class:"column-resize-dragging"})),o.push(Ol.widget(a,c))}}return Il.create(e.doc,o)}(e,t.activeHandle)},nodeViews:{}}});return i}var ju=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){const n=this,o=t.getMeta(Ru);if(o&&null!=o.setHandle)return new e(o.setHandle,!1);if(o&&void 0!==o.setDragging)return new e(n.activeHandle,o.setDragging);if(n.activeHandle>-1&&t.docChanged){let o=t.mapping.map(n.activeHandle,-1);return zd(t.doc.resolve(o))||(o=-1),new e(o,n.dragging)}return n}};function Nu(e,t,n,o){const r="right"==n?-o:o,i=e.posAtCoords({left:t.clientX+r,top:t.clientY});if(!i)return-1;const{pos:s}=i,l=Hd(e.state.doc.resolve(s));if(!l)return-1;if("right"==n)return l.pos;const a=Id.get(l.node(-1)),c=l.start(-1),d=a.map.indexOf(l.pos-c);return d%a.width==0?-1:c+a.map[d-1]}function Au(e,t,n){const o=t.clientX-e.startX;return Math.max(n,e.startWidth+o)}function Ou(e,t){e.dispatch(e.state.tr.setMeta(Ru,{setHandle:t}))}function _u(e,t,n,o){const r=e.state.doc.resolve(t),i=r.node(-1),s=r.start(-1),l=Id.get(i).colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;let a=e.domAtPos(r.start(-1)).node;for(;a&&"TABLE"!=a.nodeName;)a=a.parentNode;a&&Mu(i,a.firstChild,a,o,l,n)}function Pu(e){return Array(e).fill(0)}function Iu({allowTableNodeSelection:e=!1}={}){return new Wr({key:Bd,state:{init:()=>null,apply(e,t){const n=e.getMeta(Bd);if(null!=n)return-1==n?null:n;if(null==t||!e.docChanged)return t;const{deleted:o,pos:r}=e.mapping.mapResult(t);return o?null:r}},props:{decorations:Zd,handleDOMEvents:{mousedown:wu},createSelectionBetween:e=>null!=Bd.getState(e.state)?e.state.selection:null,handleTripleClick:vu,handleKeyDown:mu,handlePaste:xu},appendTransaction:(t,n,o)=>function(e,t,n){const o=(t||e).selection,r=(t||e).doc;let i,s;if(o instanceof Or&&(s=o.node.type.spec.tableRole)){if("cell"==s||"header_cell"==s)i=Gd.create(r,o.from);else if("row"==s){const e=r.resolve(o.from+1);i=Gd.rowSelection(e,e)}else if(!n){const e=Id.get(o.node),t=o.from+1,n=t+e.map[e.width*e.height-1];i=Gd.create(r,t+1,n)}}else o instanceof Nr&&function({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,o=t.pos,r=e.depth;for(;r>=0&&!(e.after(r+1)<e.end(r));r--,n++);for(let i=t.depth;i>=0&&!(t.before(i+1)>t.start(i));i--,o--);return n==o&&/row|table/.test(e.node(r).type.spec.tableRole)}(o)?i=Nr.create(r,o.from):o instanceof Nr&&function({$from:e,$to:t}){let n,o;for(let r=e.depth;r>0;r--){const t=e.node(r);if("cell"===t.type.spec.tableRole||"header_cell"===t.type.spec.tableRole){n=t;break}}for(let r=t.depth;r>0;r--){const e=t.node(r);if("cell"===e.type.spec.tableRole||"header_cell"===e.type.spec.tableRole){o=e;break}}return n!==o&&0===t.parentOffset}(o)&&(i=Nr.create(r,o.$from.start(),o.$from.end()));return i&&(t||(t=e.tr)).setSelection(i),t}(o,Yd(o,n),e)})}var Lu=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var o,r,i;if(Array.isArray(t)){if((o=t.length)!=n.length)return!1;for(r=o;0!==r--;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((o=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(r=o;0!==r--;)if(!Object.prototype.hasOwnProperty.call(n,i[r]))return!1;for(r=o;0!==r--;){var s=i[r];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n};const Du=o.getDefaultExportFromCjs(Lu);var Bu=class e{constructor(e){this.cache=new Map(e)}get(e){return this.cache.get(e)}set(e,t,n){e<0||this.cache.set(e,[t,n])}replace(e,t,n,o){this.remove(e),this.set(t,n,o)}remove(e){this.cache.delete(e)}invalidate(t){const n=new e(this.cache),o=t.mapping;return this.cache.forEach(([e,r],i)=>{if(i<0)return;const s=o.mapResult(i),l=t.doc.nodeAt(s.pos);if(s.deleted||!(null==l?void 0:l.eq(e)))n.remove(i);else if(i!==s.pos){const e=r.map(e=>e.map(o,0,0)).filter(e=>null!=e);n.replace(i,s.pos,l,e)}}),n}};function Hu({parser:e,nodeTypes:t=["code_block","codeBlock"],languageExtractor:n=e=>e.attrs.language}){const o=new Kr("prosemirror-highlight");return new Wr({key:o,state:{init(o,r){const i=new Bu,[s,l]=Vu(r.doc,e,t,n,i);return{cache:i,decorations:s,promises:l}},apply:(o,r)=>{const i=r.cache.invalidate(o),s=!!o.getMeta("prosemirror-highlight-refresh");if(!o.docChanged&&!s){return{cache:i,decorations:r.decorations.map(o.mapping,o.doc),promises:r.promises}}const[l,a]=Vu(o.doc,e,t,n,i);return{cache:i,decorations:l,promises:a}}},view:e=>{const t=new Set,n=()=>{if(t.size>0)return;const n=e.state.tr.setMeta("prosemirror-highlight-refresh",!0);e.dispatch(n)},r=()=>{var r;const i=o.getState(e.state);for(const e of null!=(r=null==i?void 0:i.promises)?r:[])t.add(e),e.then(()=>{t.delete(e),n()}).catch(()=>{t.delete(e)})};return r(),{update:()=>{r()}}},props:{decorations(e){var t;return null==(t=this.getState(e))?void 0:t.decorations}}})}function Vu(e,t,n,o,r){const i=[],s=[];return e.descendants((e,l)=>{if(!e.type.isTextblock)return!0;if(n.includes(e.type.name)){const n=o(e),a=r.get(l);if(a){const[e,t]=a;i.push(...t)}else{const o=t({content:e.textContent,language:n||void 0,pos:l,size:e.nodeSize});o&&Array.isArray(o)?(r.set(l,e,o),i.push(...o)):o instanceof Promise&&(r.remove(l),s.push(o))}}return!1}),[Il.create(e,i),s]}function $u(e){return"string"==typeof e?e:Object.entries(e).map(([e,t])=>`${e}:${t}`).join(";")}const zu=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,Fu=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,Uu=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,Wu=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,qu=gc.create({name:"bold",addOptions:()=>({HTMLAttributes:{}}),parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:e=>"normal"!==e.style.fontWeight&&null},{style:"font-weight=400",clearMark:e=>e.type.name===this.name},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return["strong",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[wd({find:zu,type:this.type}),wd({find:Uu,type:this.type})]},addPasteRules(){return[Ed({find:Fu,type:this.type}),Ed({find:Wu,type:this.type})]}}),Gu=/(^|[^`])`([^`]+)`(?!`)/,Ku=/(^|[^`])`([^`]+)`(?!`)/g,Zu=gc.create({name:"code",addOptions:()=>({HTMLAttributes:{}}),excludes:"_",code:!0,exitable:!0,parseHTML:()=>[{tag:"code"}],renderHTML({HTMLAttributes:e}){return["code",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[wd({find:Gu,type:this.type})]},addPasteRules(){return[Ed({find:Ku,type:this.type})]}}),Ju=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Xu=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,Yu=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Qu=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,eh=gc.create({name:"italic",addOptions:()=>({HTMLAttributes:{}}),parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:e=>"normal"!==e.style.fontStyle&&null},{style:"font-style=normal",clearMark:e=>e.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:e}){return["em",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[wd({find:Ju,type:this.type}),wd({find:Yu,type:this.type})]},addPasteRules(){return[Ed({find:Xu,type:this.type}),Ed({find:Qu,type:this.type})]}}),th=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,nh=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,oh=gc.create({name:"strike",addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:e=>!!e.includes("line-through")&&{}}],renderHTML({HTMLAttributes:e}){return["s",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[wd({find:th,type:this.type})]},addPasteRules(){return[Ed({find:nh,type:this.type})]}}),rh=gc.create({name:"underline",addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:e=>!!e.includes("underline")&&{}}],renderHTML({HTMLAttributes:e}){return["u",ec(this.options.HTMLAttributes,e),0]},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),ih=kd.create({name:"tableCell",addOptions:()=>({HTMLAttributes:{}}),content:"block+",addAttributes:()=>({colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(e=>parseInt(e,10)):null}}}),tableRole:"cell",isolating:!0,parseHTML:()=>[{tag:"td"}],renderHTML({HTMLAttributes:e}){return["td",ec(this.options.HTMLAttributes,e),0]}}),sh=kd.create({name:"tableHeader",addOptions:()=>({HTMLAttributes:{}}),content:"block+",addAttributes:()=>({colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{const t=e.getAttribute("colwidth");return t?t.split(",").map(e=>parseInt(e,10)):null}}}),tableRole:"header_cell",isolating:!0,parseHTML:()=>[{tag:"th"}],renderHTML({HTMLAttributes:e}){return["th",ec(this.options.HTMLAttributes,e),0]}});class lh extends Mr{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return lh.valid(n)?new lh(n):Mr.near(n)}content(){return _n.empty}eq(e){return e instanceof lh&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for GapCursor.fromJSON");return new lh(e.resolve(t.pos))}getBookmark(){return new ah(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!function(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),o=e.node(t);if(0!=n)for(let e=o.child(n-1);;e=e.lastChild){if(0==e.childCount&&!e.inlineContent||ch(e.type))return!0;if(e.inlineContent)return!1}else if(o.type.spec.isolating)return!0}return!0}(e)||!function(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),o=e.node(t);if(n!=o.childCount)for(let e=o.child(n);;e=e.firstChild){if(0==e.childCount&&!e.inlineContent||ch(e.type))return!0;if(e.inlineContent)return!1}else if(o.type.spec.isolating)return!0}return!0}(e))return!1;let n=t.type.spec.allowGapCursor;if(null!=n)return n;let o=t.contentMatchAt(e.index()).defaultType;return o&&o.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&lh.valid(e))return e;let o=e.pos,r=null;for(let n=e.depth;;n--){let i=e.node(n);if(t>0?e.indexAfter(n)<i.childCount:e.index(n)>0){r=i.child(t>0?e.indexAfter(n):e.index(n)-1);break}if(0==n)return null;o+=t;let s=e.doc.resolve(o);if(lh.valid(s))return s}for(;;){let i=t>0?r.firstChild:r.lastChild;if(!i){if(r.isAtom&&!r.isText&&!Or.isSelectable(r)){e=e.doc.resolve(o+r.nodeSize*t),n=!1;continue e}break}r=i,o+=t;let s=e.doc.resolve(o);if(lh.valid(s))return s}return null}}}lh.prototype.visible=!1,lh.findFrom=lh.findGapCursorFrom,Mr.jsonID("gapcursor",lh);class ah{constructor(e){this.pos=e}map(e){return new ah(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return lh.valid(t)?new lh(t):Mr.near(t)}}function ch(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}const dh=ka({ArrowLeft:uh("horiz",-1),ArrowRight:uh("horiz",1),ArrowUp:uh("vert",-1),ArrowDown:uh("vert",1)});function uh(e,t){const n="vert"==e?t>0?"down":"up":t>0?"right":"left";return function(e,o,r){let i=e.selection,s=t>0?i.$to:i.$from,l=i.empty;if(i instanceof Nr){if(!r.endOfTextblock(n)||0==s.depth)return!1;l=!1,s=e.doc.resolve(t>0?s.after():s.before())}let a=lh.findGapCursorFrom(s,t,l);return!!a&&(o&&o(e.tr.setSelection(new lh(a))),!0)}}function hh(e,t,n){if(!e||!e.editable)return!1;let o=e.state.doc.resolve(t);if(!lh.valid(o))return!1;let r=e.posAtCoords({left:n.clientX,top:n.clientY});return!(r&&r.inside>-1&&Or.isSelectable(e.state.doc.nodeAt(r.inside)))&&(e.dispatch(e.state.tr.setSelection(new lh(o))),!0)}function ph(e,t){if("insertCompositionText"!=t.inputType||!(e.state.selection instanceof lh))return!1;let{$from:n}=e.state.selection,o=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!o)return!1;let r=Rn.empty;for(let s=o.length-1;s>=0;s--)r=Rn.from(o[s].createAndFill(null,r));let i=e.state.tr.replace(n.pos,n.pos,new _n(r,0,0));return i.setSelection(Nr.near(i.doc.resolve(n.pos+1))),e.dispatch(i),!1}function fh(e){if(!(e.selection instanceof lh))return null;let t=document.createElement("div");return t.className="ProseMirror-gapcursor",Il.create(e.doc,[Ol.widget(e.selection.head,t,{key:"gapcursor"})])}const mh=kc.create({name:"gapCursor",addProseMirrorPlugins:()=>[new Wr({props:{decorations:fh,createSelectionBetween:(e,t,n)=>t.pos==n.pos&&lh.valid(n)?new lh(n):null,handleClick:hh,handleKeyDown:dh,handleDOMEvents:{beforeinput:ph}}})],extendNodeSchema(e){var t;return{allowGapCursor:null!==(t=oc(Ja(e,"allowGapCursor",{name:e.name,options:e.options,storage:e.storage})))&&void 0!==t?t:null}}});var gh=200,yh=function(){};yh.prototype.append=function(e){return e.length?(e=yh.from(e),!this.length&&e||e.length<gh&&this.leafAppend(e)||this.length<gh&&e.leafPrepend(this)||this.appendInner(e)):this},yh.prototype.prepend=function(e){return e.length?yh.from(e).append(this):this},yh.prototype.appendInner=function(e){return new vh(this,e)},yh.prototype.slice=function(e,t){return void 0===e&&(e=0),void 0===t&&(t=this.length),e>=t?yh.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},yh.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},yh.prototype.forEach=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},yh.prototype.map=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length);var o=[];return this.forEach(function(t,n){return o.push(e(t,n))},t,n),o},yh.from=function(e){return e instanceof yh?e:e&&e.length?new bh(e):yh.empty};var bh=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 0==e&&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,o){for(var r=t;r<n;r++)if(!1===e(this.values[r],o+r))return!1},t.prototype.forEachInvertedInner=function(e,t,n,o){for(var r=t-1;r>=n;r--)if(!1===e(this.values[r],o+r))return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=gh)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=gh)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}(yh);yh.empty=new bh([]);var vh=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,o){var r=this.left.length;return!(t<r&&!1===this.left.forEachInner(e,t,Math.min(n,r),o))&&(!(n>r&&!1===this.right.forEachInner(e,Math.max(t-r,0),Math.min(this.length,n)-r,o+r))&&void 0)},t.prototype.forEachInvertedInner=function(e,t,n,o){var r=this.left.length;return!(t>r&&!1===this.right.forEachInvertedInner(e,t-r,Math.max(n,r)-r,o+r))&&(!(n<r&&!1===this.left.forEachInvertedInner(e,Math.min(t,r),n,o))&&void 0)},t.prototype.sliceInner=function(e,t){if(0==e&&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}(yh);class xh{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(0==this.eventCount)return null;let n,o,r=this.items.length;for(;;r--){if(this.items.get(r-1).selection){--r;break}}t&&(n=this.remapping(r,this.items.length),o=n.maps.length);let i,s,l=e.tr,a=[],c=[];return this.items.forEach((e,t)=>{if(!e.step)return n||(n=this.remapping(r,t+1),o=n.maps.length),o--,void c.push(e);if(n){c.push(new wh(e.map));let t,r=e.step.map(n.slice(o));r&&l.maybeStep(r).doc&&(t=l.mapping.maps[l.mapping.maps.length-1],a.push(new wh(t,void 0,void 0,a.length+c.length))),o--,t&&n.appendMap(t,o)}else l.maybeStep(e.step);return e.selection?(i=n?e.selection.map(n.slice(o)):e.selection,s=new xh(this.items.slice(0,r).append(c.reverse().concat(a)),this.eventCount-1),!1):void 0},this.items.length,0),{remaining:s,transform:l,selection:i}}addTransform(e,t,n,o){let r=[],i=this.eventCount,s=this.items,l=!o&&s.length?s.get(s.length-1):null;for(let c=0;c<e.steps.length;c++){let n,a=e.steps[c].invert(e.docs[c]),d=new wh(e.mapping.maps[c],a,t);(n=l&&l.merge(d))&&(d=n,c?r.pop():s=s.slice(0,s.length-1)),r.push(d),t&&(i++,t=void 0),o||(l=d)}let a=i-n.depth;return a>Ch&&(s=function(e,t){let n;return e.forEach((e,o)=>{if(e.selection&&0==t--)return n=o,!1}),e.slice(n)}(s,a),i-=a),new xh(s.append(r),i)}remapping(e,t){let n=new Vo;return this.items.forEach((t,o)=>{let r=null!=t.mirrorOffset&&o-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,r)},e,t),n}addMaps(e){return 0==this.eventCount?this:new xh(this.items.append(e.map(e=>new wh(e))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],o=Math.max(0,this.items.length-t),r=e.mapping,i=e.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},o);let l=t;this.items.forEach(t=>{let o=r.getMirror(--l);if(null==o)return;i=Math.min(i,o);let a=r.maps[o];if(t.step){let i=e.steps[o].invert(e.docs[o]),c=t.selection&&t.selection.map(r.slice(l+1,o));c&&s++,n.push(new wh(a,i,c))}else n.push(new wh(a))},o);let a=[];for(let u=t;u<i;u++)a.push(new wh(r.maps[u]));let c=this.items.slice(0,o).append(a).append(n),d=new xh(c,s);return d.emptyItemCount()>500&&(d=d.compress(this.items.length-n.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,o=[],r=0;return this.items.forEach((i,s)=>{if(s>=e)o.push(i),i.selection&&r++;else if(i.step){let e=i.step.map(t.slice(n)),s=e&&e.getMap();if(n--,s&&t.appendMap(s,n),e){let l=i.selection&&i.selection.map(t.slice(n));l&&r++;let a,c=new wh(s.invert(),e,l),d=o.length-1;(a=o.length&&o[d].merge(c))?o[d]=a:o.push(c)}}else i.map&&n--},this.items.length,0),new xh(yh.from(o.reverse()),r)}}xh.empty=new xh(yh.empty,0);let wh=class e{constructor(e,t,n,o){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=o}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)}}};class kh{constructor(e,t,n,o,r){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=o,this.prevComposition=r}}const Ch=20;function Eh(e){let t=[];for(let n=e.length-1;n>=0&&0==t.length;n--)e[n].forEach((e,n,o,r)=>t.push(o,r));return t}function Sh(e,t){if(!e)return null;let n=[];for(let o=0;o<e.length;o+=2){let r=t.map(e[o],1),i=t.map(e[o+1],-1);r<=i&&n.push(r,i)}return n}let Mh=!1,Rh=null;function Th(e){let t=e.plugins;if(Rh!=t){Mh=!1,Rh=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){Mh=!0;break}}return Mh}const jh=new Kr("history"),Nh=new Kr("closeHistory");function Ah(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Wr({key:jh,state:{init:()=>new kh(xh.empty,xh.empty,null,0,-1),apply:(t,n,o)=>function(e,t,n,o){let r,i=n.getMeta(jh);if(i)return i.historyState;n.getMeta(Nh)&&(e=new kh(e.done,e.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(0==n.steps.length)return e;if(s&&s.getMeta(jh))return s.getMeta(jh).redo?new kh(e.done.addTransform(n,void 0,o,Th(t)),e.undone,Eh(n.mapping.maps),e.prevTime,e.prevComposition):new kh(e.done,e.undone.addTransform(n,void 0,o,Th(t)),null,e.prevTime,e.prevComposition);if(!1===n.getMeta("addToHistory")||s&&!1===s.getMeta("addToHistory"))return(r=n.getMeta("rebased"))?new kh(e.done.rebased(n,r),e.undone.rebased(n,r),Sh(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new kh(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Sh(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);{let r=n.getMeta("composition"),i=0==e.prevTime||!s&&e.prevComposition!=r&&(e.prevTime<(n.time||0)-o.newGroupDelay||!function(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,o)=>{for(let r=0;r<t.length;r+=2)e<=t[r+1]&&o>=t[r]&&(n=!0)}),n}(n,e.prevRanges)),l=s?Sh(e.prevRanges,n.mapping):Eh(n.mapping.maps);return new kh(e.done.addTransform(n,i?t.selection.getBookmark():void 0,o,Th(t)),xh.empty,l,n.time,null==r?e.prevComposition:r)}}(n,o,t,e)},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,o="historyUndo"==n?_h:"historyRedo"==n?Ph:null;return!!o&&(t.preventDefault(),o(e.state,e.dispatch))}}}})}function Oh(e,t){return(n,o)=>{let r=jh.getState(n);if(!r||0==(e?r.undone:r.done).eventCount)return!1;if(o){let i=function(e,t,n){let o=Th(t),r=jh.get(t).spec.config,i=(n?e.undone:e.done).popEvent(t,o);if(!i)return null;let s=i.selection.resolve(i.transform.doc),l=(n?e.done:e.undone).addTransform(i.transform,t.selection.getBookmark(),r,o),a=new kh(n?l:i.remaining,n?i.remaining:l,null,0,-1);return i.transform.setSelection(s).setMeta(jh,{redo:n,historyState:a})}(r,n,e);i&&o(t?i.scrollIntoView():i)}return!0}}const _h=Oh(!1,!0),Ph=Oh(!0,!0),Ih=kc.create({name:"history",addOptions:()=>({depth:100,newGroupDelay:500}),addCommands:()=>({undo:()=>({state:e,dispatch:t})=>_h(e,t),redo:()=>({state:e,dispatch:t})=>Ph(e,t)}),addProseMirrorPlugins(){return[Ah(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Lh="numeric",Dh="ascii",Bh="alpha",Hh="asciinumeric",Vh="alphanumeric",$h="domain",zh="emoji",Fh="scheme",Uh="slashscheme",Wh="whitespace";function qh(e,t){return e in t||(t[e]=[]),t[e]}function Gh(e,t,n){t[Lh]&&(t[Hh]=!0,t[Vh]=!0),t[Dh]&&(t[Hh]=!0,t[Bh]=!0),t[Hh]&&(t[Vh]=!0),t[Bh]&&(t[Vh]=!0),t[Vh]&&(t[$h]=!0),t[zh]&&(t[$h]=!0);for(const o in t){const t=qh(o,n);t.indexOf(e)<0&&t.push(e)}}function Kh(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}Kh.groups={},Kh.prototype={accepts(){return!!this.t},go(e){const t=this,n=t.j[e];if(n)return n;for(let o=0;o<t.jr.length;o++){const n=t.jr[o][0],r=t.jr[o][1];if(r&&n.test(e))return r}return t.jd},has(e,t=!1){return t?e in this.j:!!this.go(e)},ta(e,t,n,o){for(let r=0;r<e.length;r++)this.tt(e[r],t,n,o)},tr(e,t,n,o){let r;return o=o||Kh.groups,t&&t.j?r=t:(r=new Kh(t),n&&o&&Gh(t,n,o)),this.jr.push([e,r]),r},ts(e,t,n,o){let r=this;const i=e.length;if(!i)return r;for(let s=0;s<i-1;s++)r=r.tt(e[s]);return r.tt(e[i-1],t,n,o)},tt(e,t,n,o){o=o||Kh.groups;const r=this;if(t&&t.j)return r.j[e]=t,t;const i=t;let s,l=r.go(e);if(l?(s=new Kh,Object.assign(s.j,l.j),s.jr.push.apply(s.jr,l.jr),s.jd=l.jd,s.t=l.t):s=new Kh,i){if(o)if(s.t&&"string"==typeof s.t){const e=Object.assign(function(e,t){const n={};for(const o in t)t[o].indexOf(e)>=0&&(n[o]=!0);return n}(s.t,o),n);Gh(i,e,o)}else n&&Gh(i,n,o);s.t=i}return r.j[e]=s,s}};const Zh=(e,t,n,o,r)=>e.ta(t,n,o,r),Jh=(e,t,n,o,r)=>e.tr(t,n,o,r),Xh=(e,t,n,o,r)=>e.ts(t,n,o,r),Yh=(e,t,n,o,r)=>e.tt(t,n,o,r),Qh="WORD",ep="UWORD",tp="ASCIINUMERICAL",np="ALPHANUMERICAL",op="LOCALHOST",rp="TLD",ip="UTLD",sp="SCHEME",lp="SLASH_SCHEME",ap="NUM",cp="WS",dp="NL",up="OPENBRACE",hp="CLOSEBRACE",pp="OPENBRACKET",fp="CLOSEBRACKET",mp="OPENPAREN",gp="CLOSEPAREN",yp="OPENANGLEBRACKET",bp="CLOSEANGLEBRACKET",vp="FULLWIDTHLEFTPAREN",xp="FULLWIDTHRIGHTPAREN",wp="LEFTCORNERBRACKET",kp="RIGHTCORNERBRACKET",Cp="LEFTWHITECORNERBRACKET",Ep="RIGHTWHITECORNERBRACKET",Sp="FULLWIDTHLESSTHAN",Mp="FULLWIDTHGREATERTHAN",Rp="AMPERSAND",Tp="APOSTROPHE",jp="ASTERISK",Np="AT",Ap="BACKSLASH",Op="BACKTICK",_p="CARET",Pp="COLON",Ip="COMMA",Lp="DOLLAR",Dp="DOT",Bp="EQUALS",Hp="EXCLAMATION",Vp="HYPHEN",$p="PERCENT",zp="PIPE",Fp="PLUS",Up="POUND",Wp="QUERY",qp="QUOTE",Gp="FULLWIDTHMIDDLEDOT",Kp="SEMI",Zp="SLASH",Jp="TILDE",Xp="UNDERSCORE",Yp="EMOJI",Qp="SYM";var ef=Object.freeze({__proto__:null,ALPHANUMERICAL:np,AMPERSAND:Rp,APOSTROPHE:Tp,ASCIINUMERICAL:tp,ASTERISK:jp,AT:Np,BACKSLASH:Ap,BACKTICK:Op,CARET:_p,CLOSEANGLEBRACKET:bp,CLOSEBRACE:hp,CLOSEBRACKET:fp,CLOSEPAREN:gp,COLON:Pp,COMMA:Ip,DOLLAR:Lp,DOT:Dp,EMOJI:Yp,EQUALS:Bp,EXCLAMATION:Hp,FULLWIDTHGREATERTHAN:Mp,FULLWIDTHLEFTPAREN:vp,FULLWIDTHLESSTHAN:Sp,FULLWIDTHMIDDLEDOT:Gp,FULLWIDTHRIGHTPAREN:xp,HYPHEN:Vp,LEFTCORNERBRACKET:wp,LEFTWHITECORNERBRACKET:Cp,LOCALHOST:op,NL:dp,NUM:ap,OPENANGLEBRACKET:yp,OPENBRACE:up,OPENBRACKET:pp,OPENPAREN:mp,PERCENT:$p,PIPE:zp,PLUS:Fp,POUND:Up,QUERY:Wp,QUOTE:qp,RIGHTCORNERBRACKET:kp,RIGHTWHITECORNERBRACKET:Ep,SCHEME:sp,SEMI:Kp,SLASH:Zp,SLASH_SCHEME:lp,SYM:Qp,TILDE:Jp,TLD:rp,UNDERSCORE:Xp,UTLD:ip,UWORD:ep,WORD:Qh,WS:cp});const tf=/[a-z]/,nf=new RegExp("\\p{L}","u"),of=new RegExp("\\p{Emoji}","u"),rf=/\d/,sf=/\s/;let lf=null,af=null;function cf(e,t){const n=function(e){const t=[],n=e.length;let o=0;for(;o<n;){let r,i=e.charCodeAt(o),s=i<55296||i>56319||o+1===n||(r=e.charCodeAt(o+1))<56320||r>57343?e[o]:e.slice(o,o+2);t.push(s),o+=s.length}return t}(t.replace(/[A-Z]/g,e=>e.toLowerCase())),o=n.length,r=[];let i=0,s=0;for(;s<o;){let l=e,a=null,c=0,d=null,u=-1,h=-1;for(;s<o&&(a=l.go(n[s]));)l=a,l.accepts()?(u=0,h=0,d=l):u>=0&&(u+=n[s].length,h++),c+=n[s].length,i+=n[s].length,s++;i-=u,s-=h,c-=u,r.push({t:d.t,v:t.slice(i-c,i),s:i-c,e:i})}return r}function df(e,t,n,o,r){let i;const s=t.length;for(let l=0;l<s-1;l++){const n=t[l];e.j[n]?i=e.j[n]:(i=new Kh(o),i.jr=r.slice(),e.j[n]=i),e=i}return i=new Kh(n),i.jr=r.slice(),e.j[t[s-1]]=i,i}function uf(e){const t=[],n=[];let o=0;for(;o<e.length;){let r=0;for(;"0123456789".indexOf(e[o+r])>=0;)r++;if(r>0){t.push(n.join(""));for(let t=parseInt(e.substring(o,o+r),10);t>0;t--)n.pop();o+=r}else n.push(e[o]),o++}return t}const hf={defaultProtocol:"http",events:null,format:ff,formatHref:ff,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function pf(e,t=null){let n=Object.assign({},hf);e&&(n=Object.assign(n,e instanceof pf?e.o:e));const o=n.ignoreTags,r=[];for(let i=0;i<o.length;i++)r.push(o[i].toUpperCase());this.o=n,t&&(this.defaultRender=t),this.ignoreTags=r}function ff(e){return e}function mf(e,t){this.t="token",this.v=e,this.tk=t}function gf(e,t){class n extends mf{constructor(t,n){super(t,n),this.t=e}}for(const o in t)n.prototype[o]=t[o];return n.t=e,n}pf.prototype={o:hf,ignoreTags:[],defaultRender:e=>e,check(e){return this.get("validate",e.toString(),e)},get(e,t,n){const o=null!=t;let r=this.o[e];return r?("object"==typeof r?(r=n.t in r?r[n.t]:hf[e],"function"==typeof r&&o&&(r=r(t,n))):"function"==typeof r&&o&&(r=r(t,n.t,n)),r):r},getObj(e,t,n){let o=this.o[e];return"function"==typeof o&&null!=t&&(o=o(t,n.t,n)),o},render(e){const t=e.render(this);return(this.get("render",null,e)||this.defaultRender)(t,e.t,e)}},mf.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){const t=this.toString(),n=e.get("truncate",t,this),o=e.get("format",t,this);return n&&o.length>n?o.substring(0,n)+"…":o},toFormattedHref(e){return e.get("formatHref",this.toHref(e.get("defaultProtocol")),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=hf.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get("validate",this.toString(),this)},render(e){const t=this,n=this.toHref(e.get("defaultProtocol")),o=e.get("formatHref",n,this),r=e.get("tagName",n,t),i=this.toFormattedString(e),s={},l=e.get("className",n,t),a=e.get("target",n,t),c=e.get("rel",n,t),d=e.getObj("attributes",n,t),u=e.getObj("events",n,t);return s.href=o,l&&(s.class=l),a&&(s.target=a),c&&(s.rel=c),d&&Object.assign(s,d),{tagName:r,attributes:s,content:i,eventListeners:u}}};const yf=gf("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),bf=gf("text"),vf=gf("nl"),xf=gf("url",{isLink:!0,toHref(e=hf.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){const e=this.tk;return e.length>=2&&e[0].t!==op&&e[1].t===Pp}}),wf=e=>new Kh(e);function kf(e,t,n){const o=n[0].s,r=n[n.length-1].e;return new e(t.slice(o,r),n)}const Cf="undefined"!=typeof console&&console&&console.warn||(()=>{}),Ef={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function Sf(e,t=!1){if(Ef.initialized&&Cf(`linkifyjs: already initialized - will not register custom scheme "${e}" until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw new Error('linkifyjs: incorrect scheme format.\n1. Must only contain digits, lowercase ASCII letters or "-"\n2. Cannot start or end with "-"\n3. "-" cannot repeat');Ef.customSchemes.push([e,t])}function Mf(){Ef.scanner=function(e=[]){const t={};Kh.groups=t;const n=new Kh;null==lf&&(lf=uf("aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2")),null==af&&(af=uf("ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2")),Yh(n,"'",Tp),Yh(n,"{",up),Yh(n,"}",hp),Yh(n,"[",pp),Yh(n,"]",fp),Yh(n,"(",mp),Yh(n,")",gp),Yh(n,"<",yp),Yh(n,">",bp),Yh(n,"(",vp),Yh(n,")",xp),Yh(n,"「",wp),Yh(n,"」",kp),Yh(n,"『",Cp),Yh(n,"』",Ep),Yh(n,"<",Sp),Yh(n,">",Mp),Yh(n,"&",Rp),Yh(n,"*",jp),Yh(n,"@",Np),Yh(n,"`",Op),Yh(n,"^",_p),Yh(n,":",Pp),Yh(n,",",Ip),Yh(n,"$",Lp),Yh(n,".",Dp),Yh(n,"=",Bp),Yh(n,"!",Hp),Yh(n,"-",Vp),Yh(n,"%",$p),Yh(n,"|",zp),Yh(n,"+",Fp),Yh(n,"#",Up),Yh(n,"?",Wp),Yh(n,'"',qp),Yh(n,"/",Zp),Yh(n,";",Kp),Yh(n,"~",Jp),Yh(n,"_",Xp),Yh(n,"\\",Ap),Yh(n,"・",Gp);const o=Jh(n,rf,ap,{[Lh]:!0});Jh(o,rf,o);const r=Jh(o,tf,tp,{[Hh]:!0}),i=Jh(o,nf,np,{[Vh]:!0}),s=Jh(n,tf,Qh,{[Dh]:!0});Jh(s,rf,r),Jh(s,tf,s),Jh(r,rf,r),Jh(r,tf,r);const l=Jh(n,nf,ep,{[Bh]:!0});Jh(l,tf),Jh(l,rf,i),Jh(l,nf,l),Jh(i,rf,i),Jh(i,tf),Jh(i,nf,i);const a=Yh(n,"\n",dp,{[Wh]:!0}),c=Yh(n,"\r",cp,{[Wh]:!0}),d=Jh(n,sf,cp,{[Wh]:!0});Yh(n,"",d),Yh(c,"\n",a),Yh(c,"",d),Jh(c,sf,d),Yh(d,"\r"),Yh(d,"\n"),Jh(d,sf,d),Yh(d,"",d);const u=Jh(n,of,Yp,{[zh]:!0});Yh(u,"#"),Jh(u,of,u),Yh(u,"️",u);const h=Yh(u,"‍");Yh(h,"#"),Jh(h,of,u);const p=[[tf,s],[rf,r]],f=[[tf,null],[nf,l],[rf,i]];for(let m=0;m<lf.length;m++)df(n,lf[m],rp,Qh,p);for(let m=0;m<af.length;m++)df(n,af[m],ip,ep,f);Gh(rp,{tld:!0,ascii:!0},t),Gh(ip,{utld:!0,alpha:!0},t),df(n,"file",sp,Qh,p),df(n,"mailto",sp,Qh,p),df(n,"http",lp,Qh,p),df(n,"https",lp,Qh,p),df(n,"ftp",lp,Qh,p),df(n,"ftps",lp,Qh,p),Gh(sp,{scheme:!0,ascii:!0},t),Gh(lp,{slashscheme:!0,ascii:!0},t),e=e.sort((e,t)=>e[0]>t[0]?1:-1);for(let m=0;m<e.length;m++){const t=e[m][0],o=e[m][1]?{[Fh]:!0}:{[Uh]:!0};t.indexOf("-")>=0?o[$h]=!0:tf.test(t)?rf.test(t)?o[Hh]=!0:o[Dh]=!0:o[Lh]=!0,Xh(n,t,t,o)}return Xh(n,"localhost",op,{ascii:!0}),n.jd=new Kh(Qp),{start:n,tokens:Object.assign({groups:t},ef)}}(Ef.customSchemes);for(let e=0;e<Ef.tokenQueue.length;e++)Ef.tokenQueue[e][1]({scanner:Ef.scanner});Ef.parser=function({groups:e}){const t=e.domain.concat([Rp,jp,Np,Ap,Op,_p,Lp,Bp,Vp,ap,$p,zp,Fp,Up,Zp,Qp,Jp,Xp]),n=[Tp,Pp,Ip,Dp,Hp,$p,Wp,qp,Kp,yp,bp,up,hp,fp,pp,mp,gp,vp,xp,wp,kp,Cp,Ep,Sp,Mp],o=[Rp,Tp,jp,Ap,Op,_p,Lp,Bp,Vp,up,hp,$p,zp,Fp,Up,Wp,Zp,Qp,Jp,Xp],r=wf(),i=Yh(r,Jp);Zh(i,o,i),Zh(i,e.domain,i);const s=wf(),l=wf(),a=wf();Zh(r,e.domain,s),Zh(r,e.scheme,l),Zh(r,e.slashscheme,a),Zh(s,o,i),Zh(s,e.domain,s);const c=Yh(s,Np);Yh(i,Np,c),Yh(l,Np,c),Yh(a,Np,c);const d=Yh(i,Dp);Zh(d,o,i),Zh(d,e.domain,i);const u=wf();Zh(c,e.domain,u),Zh(u,e.domain,u);const h=Yh(u,Dp);Zh(h,e.domain,u);const p=wf(yf);Zh(h,e.tld,p),Zh(h,e.utld,p),Yh(c,op,p);const f=Yh(u,Vp);Yh(f,Vp,f),Zh(f,e.domain,u),Zh(p,e.domain,u),Yh(p,Dp,h),Yh(p,Vp,f);const m=Yh(p,Pp);Zh(m,e.numeric,yf);const g=Yh(s,Vp),y=Yh(s,Dp);Yh(g,Vp,g),Zh(g,e.domain,s),Zh(y,o,i),Zh(y,e.domain,s);const b=wf(xf);Zh(y,e.tld,b),Zh(y,e.utld,b),Zh(b,e.domain,s),Zh(b,o,i),Yh(b,Dp,y),Yh(b,Vp,g),Yh(b,Np,c);const v=Yh(b,Pp),x=wf(xf);Zh(v,e.numeric,x);const w=wf(xf),k=wf();Zh(w,t,w),Zh(w,n,k),Zh(k,t,w),Zh(k,n,k),Yh(b,Zp,w),Yh(x,Zp,w);const C=Yh(l,Pp),E=Yh(a,Pp),S=Yh(E,Zp),M=Yh(S,Zp);Zh(l,e.domain,s),Yh(l,Dp,y),Yh(l,Vp,g),Zh(a,e.domain,s),Yh(a,Dp,y),Yh(a,Vp,g),Zh(C,e.domain,w),Yh(C,Zp,w),Yh(C,Wp,w),Zh(M,e.domain,w),Zh(M,t,w),Yh(M,Zp,w);const R=[[up,hp],[pp,fp],[mp,gp],[yp,bp],[vp,xp],[wp,kp],[Cp,Ep],[Sp,Mp]];for(let T=0;T<R.length;T++){const[e,o]=R[T],r=Yh(w,e);Yh(k,e,r),Yh(r,o,w);const i=wf(xf);Zh(r,t,i);const s=wf();Zh(r,n),Zh(i,t,i),Zh(i,n,s),Zh(s,t,i),Zh(s,n,s),Yh(i,o,w),Yh(s,o,w)}return Yh(r,op,b),Yh(r,dp,vf),{start:r,tokens:ef}}(Ef.scanner.tokens);for(let e=0;e<Ef.pluginQueue.length;e++)Ef.pluginQueue[e][1]({scanner:Ef.scanner,parser:Ef.parser});return Ef.initialized=!0,Ef}function Rf(e){return Ef.initialized||Mf(),function(e,t,n){let o=n.length,r=0,i=[],s=[];for(;r<o;){let l=e,a=null,c=null,d=0,u=null,h=-1;for(;r<o&&!(a=l.go(n[r].t));)s.push(n[r++]);for(;r<o&&(c=a||l.go(n[r].t));)a=null,l=c,l.accepts()?(h=0,u=l):h>=0&&h++,r++,d++;if(h<0)r-=d,r<o&&(s.push(n[r]),r++);else{s.length>0&&(i.push(kf(bf,t,s)),s=[]),r-=h,d-=h;const e=u.t,o=n.slice(r-d,r);i.push(kf(e,t,o))}}return s.length>0&&i.push(kf(bf,t,s)),i}(Ef.parser.start,e,cf(Ef.scanner.start,e))}function Tf(e,t=null,n=null){if(t&&"object"==typeof t){if(n)throw Error(`linkifyjs: Invalid link type ${t}; must be a string`);n=t,t=null}const o=new pf(n),r=Rf(e),i=[];for(let s=0;s<r.length;s++){const e=r[s];!e.isLink||t&&e.t!==t||!o.check(e)||i.push(e.toFormattedObject(o))}return i}Rf.scan=cf;const jf="[\0-   ᠎ -\u2029  ]",Nf=new RegExp(jf),Af=new RegExp(`${jf}$`),Of=new RegExp(jf,"g");function _f(e,t){const n=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return t&&t.forEach(e=>{const t="string"==typeof e?e:e.scheme;t&&n.push(t)}),!e||e.replace(Of,"").match(new RegExp(`^(?:(?:${n.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}const Pf=gc.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate),this.options.protocols.forEach(e=>{"string"!=typeof e?Sf(e.scheme,e.optionalSlashes):Sf(e)})},onDestroy(){Kh.groups={},Ef.scanner=null,Ef.parser=null,Ef.tokenQueue=[],Ef.pluginQueue=[],Ef.customSchemes=[],Ef.initialized=!1},inclusive(){return this.options.autolink},addOptions:()=>({openOnClick:!0,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(e,t)=>!!_f(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>!!e}),addAttributes(){return{href:{default:null,parseHTML:e=>e.getAttribute("href")},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class}}},parseHTML(){return[{tag:"a[href]",getAttrs:e=>{const t=e.getAttribute("href");return!(!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!_f(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}))&&null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!_f(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",ec(this.options.HTMLAttributes,e),0]:["a",ec(this.options.HTMLAttributes,{...e,href:""}),0]},addCommands(){return{setLink:e=>({chain:t})=>{const{href:n}=e;return!!this.options.isAllowedUri(n,{defaultValidate:e=>!!_f(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})&&t().setMark(this.name,e).setMeta("preventAutolink",!0).run()},toggleLink:e=>({chain:t})=>{const{href:n}=e;return!!this.options.isAllowedUri(n,{defaultValidate:e=>!!_f(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})&&t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[Ed({find:e=>{const t=[];if(e){const{protocols:n,defaultProtocol:o}=this.options,r=Tf(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!_f(e,n),protocols:n,defaultProtocol:o}));r.length&&r.forEach(e=>t.push({text:e.value,data:{href:e.href},index:e.start}))}return t},type:this.type,getAttributes:e=>{var t;return{href:null===(t=e.data)||void 0===t?void 0:t.href}}})]},addProseMirrorPlugins(){const e=[],{protocols:t,defaultProtocol:n}=this.options;var o;return this.options.autolink&&e.push((o={type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!_f(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink},new Wr({key:new Kr("autolink"),appendTransaction:(e,t,n)=>{const r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta("preventAutolink"));if(!r||i)return;const{tr:s}=n;return Yc(qc(t.doc,[...e])).forEach(({newRange:e})=>{const t=Kc(n.doc,e,e=>e.isTextblock);let r,i;if(t.length>1)r=t[0],i=n.doc.textBetween(r.pos,r.pos+r.node.nodeSize,void 0," ");else if(t.length){const o=n.doc.textBetween(e.from,e.to," "," ");if(!Af.test(o))return;r=t[0],i=n.doc.textBetween(r.pos,e.to,void 0," ")}if(r&&i){const e=i.split(Nf).filter(Boolean);if(e.length<=0)return!1;const t=e[e.length-1],a=r.pos+i.lastIndexOf(t);if(!t)return!1;const c=Rf(t).map(e=>e.toObject(o.defaultProtocol));if(!(1===(l=c).length?l[0].isLink:3===l.length&&l[1].isLink&&["()","[]"].includes(l[0].value+l[2].value)))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:a+e.start+1,to:a+e.end+1})).filter(e=>!n.schema.marks.code||!n.doc.rangeHasMark(e.from,e.to,n.schema.marks.code)).filter(e=>o.validate(e.value)).filter(e=>o.shouldAutoLink(e.value)).forEach(e=>{Qc(e.from,e.to,n.doc).some(e=>e.mark.type===o.type)||s.addMark(e.from,e.to,o.type.create({href:e.href}))})}var l}),s.steps.length?s:void 0}}))),!0===this.options.openOnClick&&e.push(function(e){return new Wr({key:new Kr("handleClickLink"),props:{handleClick:(t,n,o)=>{var r,i;if(0!==o.button)return!1;if(!t.editable)return!1;let s=o.target;const l=[];for(;"DIV"!==s.nodeName;)l.push(s),s=s.parentNode;if(!l.find(e=>"A"===e.nodeName))return!1;const a=Jc(t.state,e.type.name),c=o.target,d=null!==(r=null==c?void 0:c.href)&&void 0!==r?r:a.href,u=null!==(i=null==c?void 0:c.target)&&void 0!==i?i:a.target;return!(!c||!d||(window.open(d,u),0))}}})}({type:this.type})),this.options.linkOnPaste&&e.push(function(e){return new Wr({key:new Kr("handlePasteLink"),props:{handlePaste:(t,n,o)=>{const{state:r}=t,{selection:i}=r,{empty:s}=i;if(s)return!1;let l="";o.content.forEach(e=>{l+=e.textContent});const a=Tf(l,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===l);return!(!l||!a)&&e.editor.commands.setMark(e.type,{href:a.href})}}})}({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type})),e}}),If=kd.create({name:"text",group:"inline"}),Lf=()=>new Map,Df=e=>{const t=Lf();return e.forEach((e,n)=>{t.set(n,e)}),t},Bf=(e,t,n)=>{let o=e.get(t);return void 0===o&&e.set(t,o=n()),o},Hf=()=>new Set,Vf=e=>e[e.length-1],$f=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},zf=Array.from,Ff=Array.isArray;class Uf{constructor(){this._observers=Lf()}on(e,t){return Bf(this._observers,e,Hf).add(t),t}once(e,t){const n=(...o)=>{this.off(e,n),t(...o)};this.on(e,n)}off(e,t){const n=this._observers.get(e);void 0!==n&&(n.delete(t),0===n.size&&this._observers.delete(e))}emit(e,t){return zf((this._observers.get(e)||Lf()).values()).forEach(e=>e(...t))}destroy(){this._observers=Lf()}}const Wf=Math.floor,qf=Math.abs,Gf=(e,t)=>e<t?e:t,Kf=(e,t)=>e>t?e:t,Zf=e=>0!==e?e<0:1/e<0,Jf=64,Xf=128,Yf=127,Qf=Number.MAX_SAFE_INTEGER,em=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&Wf(e)===e),tm=String.fromCharCode,nm=/^\s*/g,om=/([A-Z])/g,rm=(e,t)=>(e=>e.replace(nm,""))(e.replace(om,e=>`${t}${(e=>e.toLowerCase())(e)}`)),im="undefined"!=typeof TextEncoder?new TextEncoder:null,sm=im?e=>im.encode(e):e=>{const t=unescape(encodeURIComponent(e)),n=t.length,o=new Uint8Array(n);for(let r=0;r<n;r++)o[r]=t.codePointAt(r);return o};let lm="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});lm&&1===lm.decode(new Uint8Array).length&&(lm=null);class am{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const cm=()=>new am,dm=e=>{const t=new Uint8Array((e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t})(e));let n=0;for(let o=0;o<e.bufs.length;o++){const r=e.bufs[o];t.set(r,n),n+=r.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},um=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*n),e.cpos=0),e.cbuf[e.cpos++]=t},hm=um,pm=(e,t)=>{for(;t>Yf;)um(e,Xf|Yf&t),t=Wf(t/128);um(e,Yf&t)},fm=(e,t)=>{const n=Zf(t);for(n&&(t=-t),um(e,(t>63?Xf:0)|(n?Jf:0)|63&t),t=Wf(t/64);t>0;)um(e,(t>Yf?Xf:0)|Yf&t),t=Wf(t/128)},mm=new Uint8Array(3e4),gm=mm.length/3,ym=im&&im.encodeInto?(e,t)=>{if(t.length<gm){const n=im.encodeInto(t,mm).written||0;pm(e,n);for(let t=0;t<n;t++)um(e,mm[t])}else vm(e,sm(t))}:(e,t)=>{const n=unescape(encodeURIComponent(t)),o=n.length;pm(e,o);for(let r=0;r<o;r++)um(e,n.codePointAt(r))},bm=(e,t)=>{const n=e.cbuf.length,o=e.cpos,r=Gf(n-o,t.length),i=t.length-r;e.cbuf.set(t.subarray(0,r),o),e.cpos+=r,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Kf(2*n,i)),e.cbuf.set(t.subarray(r)),e.cpos=i)},vm=(e,t)=>{pm(e,t.byteLength),bm(e,t)},xm=(e,t)=>{((e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*Kf(n,t)),e.cpos=0)})(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},wm=new DataView(new ArrayBuffer(4)),km=(e,t)=>{switch(typeof t){case"string":um(e,119),ym(e,t);break;case"number":em(t)&&qf(t)<=2147483647?(um(e,125),fm(e,t)):(n=t,wm.setFloat32(0,n),wm.getFloat32(0)===n?(um(e,124),((e,t)=>{xm(e,4).setFloat32(0,t,!1)})(e,t)):(um(e,123),((e,t)=>{xm(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":um(e,122),((e,t)=>{xm(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)um(e,126);else if(Ff(t)){um(e,117),pm(e,t.length);for(let n=0;n<t.length;n++)km(e,t[n])}else if(t instanceof Uint8Array)um(e,116),vm(e,t);else{um(e,118);const n=Object.keys(t);pm(e,n.length);for(let o=0;o<n.length;o++){const r=n[o];ym(e,r),km(e,t[r])}}break;case"boolean":um(e,t?120:121);break;default:um(e,127)}var n};class Cm extends am{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&pm(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const Em=e=>{e.count>0&&(fm(e.encoder,1===e.count?e.s:-e.s),e.count>1&&pm(e.encoder,e.count-2))};class Sm{constructor(){this.encoder=new am,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Em(this),this.count=1,this.s=e)}toUint8Array(){return Em(this),dm(this.encoder)}}const Mm=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);fm(e.encoder,t),e.count>1&&pm(e.encoder,e.count-2)}};class Rm{constructor(){this.encoder=new am,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Mm(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Mm(this),dm(this.encoder)}}class Tm{constructor(){this.sarr=[],this.s="",this.lensE=new Sm}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new am;return this.sarr.push(this.s),this.s="",ym(e,this.sarr.join("")),bm(e,this.lensE.toUint8Array()),dm(e)}}const jm=e=>new Error(e),Nm=()=>{throw jm("Method unimplemented")},Am=()=>{throw jm("Unexpected case")},Om=jm("Unexpected end of array"),_m=jm("Integer out of Range");class Pm{constructor(e){this.arr=e,this.pos=0}}const Im=e=>new Pm(e),Lm=e=>((e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n})(e,Bm(e)),Dm=e=>e.arr[e.pos++],Bm=e=>{let t=0,n=1;const o=e.arr.length;for(;e.pos<o;){const o=e.arr[e.pos++];if(t+=(o&Yf)*n,n*=128,o<Xf)return t;if(t>Qf)throw _m}throw Om},Hm=e=>{let t=e.arr[e.pos++],n=63&t,o=64;const r=(t&Jf)>0?-1:1;if(0===(t&Xf))return r*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n+=(t&Yf)*o,o*=128,t<Xf)return r*n;if(n>Qf)throw _m}throw Om},Vm=lm?e=>lm.decode(Lm(e)):e=>{let t=Bm(e);if(0===t)return"";{let n=String.fromCodePoint(Dm(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Dm(e));else for(;t>0;){const o=t<1e4?t:1e4,r=e.arr.subarray(e.pos,e.pos+o);e.pos+=o,n+=String.fromCodePoint.apply(null,r),t-=o}return decodeURIComponent(escape(n))}},$m=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},zm=[e=>{},e=>null,Hm,e=>$m(e,4).getFloat32(0,!1),e=>$m(e,8).getFloat64(0,!1),e=>$m(e,8).getBigInt64(0,!1),e=>!1,e=>!0,Vm,e=>{const t=Bm(e),n={};for(let o=0;o<t;o++){n[Vm(e)]=Fm(e)}return n},e=>{const t=Bm(e),n=[];for(let o=0;o<t;o++)n.push(Fm(e));return n},Lm],Fm=e=>zm[127-Dm(e)](e);class Um extends Pm{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){var e;return 0===this.count&&(this.s=this.reader(this),(e=this).pos!==e.arr.length?this.count=Bm(this)+1:this.count=-1),this.count--,this.s}}class Wm extends Pm{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=Hm(this);const e=Zf(this.s);this.count=1,e&&(this.s=-this.s,this.count=Bm(this)+2)}return this.count--,this.s}}class qm extends Pm{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=Hm(this),t=1&e;this.diff=Wf(e/2),this.count=1,t&&(this.count=Bm(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Gm{constructor(e){this.decoder=new Wm(e),this.str=Vm(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}const Km=crypto.getRandomValues.bind(crypto),Zm=Math.random,Jm=()=>Km(new Uint32Array(1))[0],Xm="10000000-1000-4000-8000-100000000000",Ym=()=>Xm.replace(/[018]/g,e=>(e^Jm()&15>>e/4).toString(16)),Qm=Date.now,eg=e=>new Promise(e);Promise.all.bind(Promise);const tg=e=>void 0===e?null:e;let ng=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},og=!0;try{"undefined"!=typeof localStorage&&localStorage&&(ng=localStorage,og=!1)}catch(VD){}const rg=ng,ig=Object.assign,sg=Object.keys,lg=e=>sg(e).length,ag=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},cg=(e,t)=>e===t||lg(e)===lg(t)&&ag(e,(e,n)=>(void 0!==e||((e,t)=>Object.prototype.hasOwnProperty.call(e,t))(t,n))&&t[n]===e),dg=Object.freeze,ug=e=>{for(const t in e){const n=e[t];"object"!=typeof n&&"function"!=typeof n||ug(e[t])}return dg(e)},hg=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&hg(e,t,n+1)}},pg=e=>e,fg="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),mg="undefined"!=typeof window&&"undefined"!=typeof document&&!fg;let gg;const yg=e=>(()=>{if(void 0===gg)if(fg){gg=Lf();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const o=e[n];"-"===o[0]?(null!==t&&gg.set(t,""),t=o):null!==t&&(gg.set(t,o),t=null)}null!==t&&gg.set(t,"")}else"object"==typeof location?(gg=Lf(),(location.search||"?").slice(1).split("&").forEach(e=>{if(0!==e.length){const[t,n]=e.split("=");gg.set(`--${rm(t,"-")}`,n),gg.set(`-${rm(t,"-")}`,n)}})):gg=Lf();return gg})().has(e),bg=e=>tg(fg?process.env[e.toUpperCase().replaceAll("-","_")]:rg.getItem(e)),vg=e=>yg("--"+e)||null!==bg(e);vg("production");var xg;fg&&(xg=process.env.FORCE_COLOR,["true","1","2"].includes(xg))||!yg("--no-colors")&&!vg("no-color")&&(!fg||process.stdout.isTTY)&&(!fg||yg("--color")||null!==bg("COLORTERM")||(bg("TERM")||"").includes("color"));const wg=mg?e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=tm(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),kg=e=>{const t=(n=e.byteLength,new Uint8Array(n));var n;return t.set(e),t},Cg=e=>(e=>{const t=cm();return e(t),dm(t)})(t=>km(t,e));class Eg{constructor(e,t){this.left=e,this.right=t}}const Sg=(e,t)=>new Eg(e,t),Mg="undefined"!=typeof document?document:{};"undefined"!=typeof DOMParser&&new DOMParser;const Rg=(Tg=clearTimeout,class{constructor(e){this._=e}destroy(){Tg(this._)}});var Tg;const jg=(e,t)=>new Rg(setTimeout(t,e)),Ng=Symbol,Ag=Ng(),Og=Ng(),_g=Ng(),Pg=Ng(),Ig=Ng(),Lg=Ng(),Dg=Ng(),Bg=Ng(),Hg=Ng(),Vg=(Sg("font-weight","bold"),Sg("font-weight","normal"),Sg("color","blue"),Sg("color","green"),Sg("color","grey"),Sg("color","red"),Sg("color","purple"),Sg("color","orange"),Sg("color","black"),(...e)=>{e.unshift(Bg),$g.forEach(t=>t.print(e))}),$g=Hf(),zg=e=>({[Symbol.iterator](){return this},next:e}),Fg=(e,t)=>zg(()=>{const{done:n,value:o}=e.next();return{done:n,value:n?void 0:t(o)}});class Ug{constructor(e,t){this.clock=e,this.len=t}}class Wg{constructor(){this.clients=new Map}}const qg=(e,t,n)=>t.clients.forEach((t,o)=>{const r=e.doc.store.clients.get(o);if(null!=r){const o=r[r.length-1],i=o.id.clock+o.length;for(let s=0,l=t[s];s<t.length&&l.clock<i;l=t[++s])Yy(e,r,l.clock,l.len,n)}}),Gg=(e,t)=>{const n=e.clients.get(t.client);return void 0!==n&&null!==((e,t)=>{let n=0,o=e.length-1;for(;n<=o;){const r=Wf((n+o)/2),i=e[r],s=i.clock;if(s<=t){if(t<s+i.len)return r;n=r+1}else o=r-1}return null})(n,t.clock)},Kg=e=>{e.clients.forEach(e=>{let t,n;for(e.sort((e,t)=>e.clock-t.clock),t=1,n=1;t<e.length;t++){const o=e[n-1],r=e[t];o.clock+o.len>=r.clock?o.len=Kf(o.len,r.clock+r.len-o.clock):(n<t&&(e[n]=r),n++)}e.length=n})},Zg=e=>{const t=new Wg;for(let n=0;n<e.length;n++)e[n].clients.forEach((o,r)=>{if(!t.clients.has(r)){const i=o.slice();for(let t=n+1;t<e.length;t++)$f(i,e[t].clients.get(r)||[]);t.clients.set(r,i)}});return Kg(t),t},Jg=(e,t,n,o)=>{Bf(e.clients,t,()=>[]).push(new Ug(n,o))},Xg=()=>new Wg,Yg=e=>{const t=Xg();return e.clients.forEach((e,n)=>{const o=[];for(let t=0;t<e.length;t++){const n=e[t];if(n.deleted){const r=n.id.clock;let i=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[1+ ++t])i+=n.length;o.push(new Ug(r,i))}}o.length>0&&t.clients.set(n,o)}),t},Qg=(e,t)=>{pm(e.restEncoder,t.clients.size),zf(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),pm(e.restEncoder,t);const o=n.length;pm(e.restEncoder,o);for(let r=0;r<o;r++){const t=n[r];e.writeDsClock(t.clock),e.writeDsLen(t.len)}})},ey=e=>{const t=new Wg,n=Bm(e.restDecoder);for(let o=0;o<n;o++){e.resetDsCurVal();const n=Bm(e.restDecoder),o=Bm(e.restDecoder);if(o>0){const r=Bf(t.clients,n,()=>[]);for(let t=0;t<o;t++)r.push(new Ug(e.readDsClock(),e.readDsLen()))}}return t},ty=(e,t,n)=>{const o=new Wg,r=Bm(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const r=Bm(e.restDecoder),i=Bm(e.restDecoder),s=n.clients.get(r)||[],l=Wy(n,r);for(let n=0;n<i;n++){const n=e.readDsClock(),i=n+e.readDsLen();if(n<l){l<i&&Jg(o,r,l,i-l);let e=Gy(s,n),a=s[e];for(!a.deleted&&a.id.clock<n&&(s.splice(e+1,0,zv(t,a,n-a.id.clock)),e++);e<s.length&&(a=s[e++],a.id.clock<i);)a.deleted||(i<a.id.clock+a.length&&s.splice(e,0,zv(t,a,i-a.id.clock)),a.delete(t))}else Jg(o,r,n,i-n)}}if(o.clients.size>0){const e=new uy;return pm(e.restEncoder,0),Qg(e,o),e.toUint8Array()}return null},ny=Jm;class oy extends Uf{constructor({guid:e=Ym(),collectionid:t=null,gc:n=!0,gcFilter:o=()=>!0,meta:r=null,autoLoad:i=!1,shouldLoad:s=!0}={}){super(),this.gc=n,this.gcFilter=o,this.clientID=ny(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Fy,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=s,this.autoLoad=i,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=eg(e=>{this.on("load",()=>{this.isLoaded=!0,e(this)})});const l=()=>eg(e=>{const t=n=>{void 0!==n&&!0!==n||(this.off("sync",t),e())};this.on("sync",t)});this.on("sync",e=>{!1===e&&this.isSynced&&(this.whenSynced=l()),this.isSynced=void 0===e||!0===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;null===e||this.shouldLoad||rb(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(zf(this.subdocs).map(e=>e.guid))}transact(e,t=null){return rb(this,e,t)}get(e,t=jb){const n=Bf(this.share,e,()=>{const e=new t;return e._integrate(this,null),e}),o=n.constructor;if(t!==jb&&o!==t){if(o===jb){const o=new t;o._map=n._map,n._map.forEach(e=>{for(;null!==e;e=e.left)e.parent=o}),o._start=n._start;for(let e=o._start;null!==e;e=e.right)e.parent=o;return o._length=n._length,this.share.set(e,o),o._integrate(this,null),o}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=""){return this.get(e,Kb)}getText(e=""){return this.get(e,hv)}getMap(e=""){return this.get(e,Jb)}getXmlElement(e=""){return this.get(e,mv)}getXmlFragment(e=""){return this.get(e,fv)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,zf(this.subdocs).forEach(e=>e.destroy());const e=this._item;if(null!==e){this._item=null;const t=e.content;t.doc=new oy({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,rb(e.parent.doc,n=>{const o=t.doc;e.deleted||n.subdocsAdded.add(o),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class ry{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Bm(this.restDecoder)}readDsLen(){return Bm(this.restDecoder)}}class iy extends ry{readLeftID(){return Ty(Bm(this.restDecoder),Bm(this.restDecoder))}readRightID(){return Ty(Bm(this.restDecoder),Bm(this.restDecoder))}readClient(){return Bm(this.restDecoder)}readInfo(){return Dm(this.restDecoder)}readString(){return Vm(this.restDecoder)}readParentInfo(){return 1===Bm(this.restDecoder)}readTypeRef(){return Bm(this.restDecoder)}readLen(){return Bm(this.restDecoder)}readAny(){return Fm(this.restDecoder)}readBuf(){return kg(Lm(this.restDecoder))}readJSON(){return JSON.parse(Vm(this.restDecoder))}readKey(){return Vm(this.restDecoder)}}class sy{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Bm(this.restDecoder),this.dsCurrVal}readDsLen(){const e=Bm(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class ly extends sy{constructor(e){super(e),this.keys=[],Bm(e),this.keyClockDecoder=new qm(Lm(e)),this.clientDecoder=new Wm(Lm(e)),this.leftClockDecoder=new qm(Lm(e)),this.rightClockDecoder=new qm(Lm(e)),this.infoDecoder=new Um(Lm(e),Dm),this.stringDecoder=new Gm(Lm(e)),this.parentInfoDecoder=new Um(Lm(e),Dm),this.typeRefDecoder=new Wm(Lm(e)),this.lenDecoder=new Wm(Lm(e))}readLeftID(){return new My(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new My(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Fm(this.restDecoder)}readBuf(){return Lm(this.restDecoder)}readJSON(){return Fm(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class ay{constructor(){this.restEncoder=cm()}toUint8Array(){return dm(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){pm(this.restEncoder,e)}writeDsLen(e){pm(this.restEncoder,e)}}class cy extends ay{writeLeftID(e){pm(this.restEncoder,e.client),pm(this.restEncoder,e.clock)}writeRightID(e){pm(this.restEncoder,e.client),pm(this.restEncoder,e.clock)}writeClient(e){pm(this.restEncoder,e)}writeInfo(e){hm(this.restEncoder,e)}writeString(e){ym(this.restEncoder,e)}writeParentInfo(e){pm(this.restEncoder,e?1:0)}writeTypeRef(e){pm(this.restEncoder,e)}writeLen(e){pm(this.restEncoder,e)}writeAny(e){km(this.restEncoder,e)}writeBuf(e){vm(this.restEncoder,e)}writeJSON(e){ym(this.restEncoder,JSON.stringify(e))}writeKey(e){ym(this.restEncoder,e)}}class dy{constructor(){this.restEncoder=cm(),this.dsCurrVal=0}toUint8Array(){return dm(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,pm(this.restEncoder,t)}writeDsLen(e){0===e&&Am(),pm(this.restEncoder,e-1),this.dsCurrVal+=e}}class uy extends dy{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Rm,this.clientEncoder=new Sm,this.leftClockEncoder=new Rm,this.rightClockEncoder=new Rm,this.infoEncoder=new Cm(hm),this.stringEncoder=new Tm,this.parentInfoEncoder=new Cm(hm),this.typeRefEncoder=new Sm,this.lenEncoder=new Sm}toUint8Array(){const e=cm();return pm(e,0),vm(e,this.keyClockEncoder.toUint8Array()),vm(e,this.clientEncoder.toUint8Array()),vm(e,this.leftClockEncoder.toUint8Array()),vm(e,this.rightClockEncoder.toUint8Array()),vm(e,dm(this.infoEncoder)),vm(e,this.stringEncoder.toUint8Array()),vm(e,dm(this.parentInfoEncoder)),vm(e,this.typeRefEncoder.toUint8Array()),vm(e,this.lenEncoder.toUint8Array()),bm(e,dm(this.restEncoder)),dm(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){km(this.restEncoder,e)}writeBuf(e){vm(this.restEncoder,e)}writeJSON(e){km(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const hy=(e,t,n)=>{const o=new Map;n.forEach((e,n)=>{Wy(t,n)>e&&o.set(n,e)}),Uy(t).forEach((e,t)=>{n.has(t)||o.set(t,0)}),pm(e.restEncoder,o.size),zf(o.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,o])=>{((e,t,n,o)=>{o=Kf(o,t[0].id.clock);const r=Gy(t,o);pm(e.restEncoder,t.length-r),e.writeClient(n),pm(e.restEncoder,o);const i=t[r];i.write(e,o-i.id.clock);for(let s=r+1;s<t.length;s++)t[s].write(e,0)})(e,t.clients.get(n),n,o)})},py=(e,t,n,o=new ly(e))=>rb(t,e=>{e.local=!1;let t=!1;const n=e.doc,r=n.store,i=((e,t)=>{const n=Lf(),o=Bm(e.restDecoder);for(let r=0;r<o;r++){const o=Bm(e.restDecoder),r=new Array(o),i=e.readClient();let s=Bm(e.restDecoder);n.set(i,{i:0,refs:r});for(let n=0;n<o;n++){const o=e.readInfo();switch(31&o){case 0:{const t=e.readLen();r[n]=new xv(Ty(i,s),t),s+=t;break}case 10:{const t=Bm(e.restDecoder);r[n]=new Kv(Ty(i,s),t),s+=t;break}default:{const l=!(192&o),a=new Wv(Ty(i,s),null,(o&Xf)===Xf?e.readLeftID():null,null,(o&Jf)===Jf?e.readRightID():null,l?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,!l||32&~o?null:e.readString(),qv(e,o));r[n]=a,s+=a.length}}}}return n})(o,n),s=((e,t,n)=>{const o=[];let r=zf(n.keys()).sort((e,t)=>e-t);if(0===r.length)return null;const i=()=>{if(0===r.length)return null;let e=n.get(r[r.length-1]);for(;e.refs.length===e.i;){if(r.pop(),!(r.length>0))return null;e=n.get(r[r.length-1])}return e};let s=i();if(null===s)return null;const l=new Fy,a=new Map,c=(e,t)=>{const n=a.get(e);(null==n||n>t)&&a.set(e,t)};let d=s.refs[s.i++];const u=new Map,h=()=>{for(const e of o){const t=e.id.client,o=n.get(t);o?(o.i--,l.clients.set(t,o.refs.slice(o.i)),n.delete(t),o.i=0,o.refs=[]):l.clients.set(t,[e]),r=r.filter(e=>e!==t)}o.length=0};for(;;){if(d.constructor!==Kv){const r=Bf(u,d.id.client,()=>Wy(t,d.id.client))-d.id.clock;if(r<0)o.push(d),c(d.id.client,d.id.clock-1),h();else{const i=d.getMissing(e,t);if(null!==i){o.push(d);const e=n.get(i)||{refs:[],i:0};if(e.refs.length!==e.i){d=e.refs[e.i++];continue}c(i,Wy(t,i)),h()}else(0===r||r<d.length)&&(d.integrate(e,r),u.set(d.id.client,d.id.clock+d.length))}}if(o.length>0)d=o.pop();else if(null!==s&&s.i<s.refs.length)d=s.refs[s.i++];else{if(s=i(),null===s)break;d=s.refs[s.i++]}}if(l.clients.size>0){const e=new uy;return hy(e,l,new Map),pm(e.restEncoder,0),{missing:a,update:e.toUint8Array()}}return null})(e,r,i),l=r.pendingStructs;if(l){for(const[e,n]of l.missing)if(n<Wy(r,e)){t=!0;break}if(s){for(const[e,t]of s.missing){const n=l.missing.get(e);(null==n||n>t)&&l.missing.set(e,t)}l.update=pb([l.update,s.update])}}else r.pendingStructs=s;const a=ty(o,e,r);if(r.pendingDs){const t=new ly(Im(r.pendingDs));Bm(t.restDecoder);const n=ty(t,e,r);r.pendingDs=a&&n?pb([a,n]):a||n}else r.pendingDs=a;if(t){const t=r.pendingStructs.update;r.pendingStructs=null,fy(e.doc,t)}},n,!1),fy=(e,t,n,o=ly)=>{const r=Im(t);py(r,e,n,new o(r))},my=(e,t,n)=>fy(e,t,n,iy),gy=(e,t=new Uint8Array([0]),n=new uy)=>{((e,t,n=new Map)=>{hy(e,t.store,n),Qg(e,Yg(t.store))})(n,e,by(t));const o=[n.toUint8Array()];if(e.store.pendingDs&&o.push(e.store.pendingDs),e.store.pendingStructs&&o.push(fb(e.store.pendingStructs.update,t)),o.length>1){if(n.constructor===cy)return ub(o.map((e,t)=>0===t?e:bb(e)));if(n.constructor===uy)return pb(o)}return o[0]},yy=(e,t)=>gy(e,t,new cy),by=e=>(e=>{const t=new Map,n=Bm(e.restDecoder);for(let o=0;o<n;o++){const n=Bm(e.restDecoder),o=Bm(e.restDecoder);t.set(n,o)}return t})(new ry(Im(e))),vy=(e,t)=>(pm(e.restEncoder,t.size),zf(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{pm(e.restEncoder,t),pm(e.restEncoder,n)}),e),xy=(e,t=new dy)=>(e instanceof Map?vy(t,e):((e,t)=>{vy(e,Uy(t.store))})(t,e),t.toUint8Array());class wy{constructor(){this.l=[]}}const ky=()=>new wy,Cy=(e,t)=>e.l.push(t),Ey=(e,t)=>{const n=e.l;n.length;e.l=n.filter(e=>t!==e),e.l.length},Sy=(e,t,n)=>hg(e.l,[t,n]);class My{constructor(e,t){this.client=e,this.clock=t}}const Ry=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,Ty=(e,t)=>new My(e,t),jy=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Am()},Ny=(e,t)=>{for(;null!==t;){if(t.parent===e)return!0;t=t.parent._item}return!1};class Ay{constructor(e,t,n,o=0){this.type=e,this.tname=t,this.item=n,this.assoc=o}}const Oy=e=>new Ay(null==e.type?null:Ty(e.type.client,e.type.clock),e.tname??null,null==e.item?null:Ty(e.item.client,e.item.clock),null==e.assoc?0:e.assoc);class _y{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}}const Py=(e,t,n)=>{let o=null,r=null;return null===e._item?r=jy(e):o=Ty(e._item.id.client,e._item.id.clock),new Ay(o,r,t,n)},Iy=(e,t,n=0)=>{let o=e._start;if(n<0){if(0===t)return Py(e,null,n);t--}for(;null!==o;){if(!o.deleted&&o.countable){if(o.length>t)return Py(e,Ty(o.id.client,o.id.clock+t),n);t-=o.length}if(null===o.right&&n<0)return Py(e,o.lastId,n);o=o.right}return Py(e,null,n)},Ly=(e,t,n=!0)=>{const o=t.store,r=e.item,i=e.type,s=e.tname,l=e.assoc;let a=null,c=0;if(null!==r){if(Wy(o,r.client)<=r.clock)return null;const e=n?Vv(o,r):((e,t)=>{const n=Ky(e,t);return{item:n,diff:t.clock-n.id.clock}})(o,r),t=e.item;if(!(t instanceof Wv))return null;if(a=t.parent,null===a._item||!a._item.deleted){c=t.deleted||!t.countable?0:e.diff+(l>=0?0:1);let n=t.left;for(;null!==n;)!n.deleted&&n.countable&&(c+=n.length),n=n.left}}else{if(null!==s)a=t.get(s);else{if(null===i)throw Am();{if(Wy(o,i.client)<=i.clock)return null;const{item:e}=n?Vv(o,i):{item:Ky(o,i)};if(!(e instanceof Wv&&e.content instanceof Hv))return null;a=e.content.type}}c=l>=0?a._length:0}return((e,t,n=0)=>new _y(e,t,n))(a,c,e.assoc)},Dy=(e,t)=>e===t||null!==e&&null!==t&&e.tname===t.tname&&Ry(e.item,t.item)&&Ry(e.type,t.type)&&e.assoc===t.assoc;class By{constructor(e,t){this.ds=e,this.sv=t}}const Hy=(e,t)=>new By(e,t),Vy=e=>Hy(Yg(e.store),Uy(e.store)),$y=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Gg(t.ds,e.id),zy=(e,t)=>{const n=Bf(e.meta,zy,Hf),o=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<Wy(o,n)&&Jy(e,Ty(n,t))}),qg(e,t.ds,e=>{}),n.add(t))};class Fy{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Uy=e=>{const t=new Map;return e.clients.forEach((e,n)=>{const o=e[e.length-1];t.set(n,o.id.clock+o.length)}),t},Wy=(e,t)=>{const n=e.clients.get(t);if(void 0===n)return 0;const o=n[n.length-1];return o.id.clock+o.length},qy=(e,t)=>{let n=e.clients.get(t.id.client);if(void 0===n)n=[],e.clients.set(t.id.client,n);else{const e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw Am()}n.push(t)},Gy=(e,t)=>{let n=0,o=e.length-1,r=e[o],i=r.id.clock;if(i===t)return o;let s=Wf(t/(i+r.length-1)*o);for(;n<=o;){if(r=e[s],i=r.id.clock,i<=t){if(t<i+r.length)return s;n=s+1}else o=s-1;s=Wf((n+o)/2)}throw Am()},Ky=(e,t)=>{const n=e.clients.get(t.client);return n[Gy(n,t.clock)]},Zy=(e,t,n)=>{const o=Gy(t,n),r=t[o];return r.id.clock<n&&r instanceof Wv?(t.splice(o+1,0,zv(e,r,n-r.id.clock)),o+1):o},Jy=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Zy(e,n,t.clock)]},Xy=(e,t,n)=>{const o=t.clients.get(n.client),r=Gy(o,n.clock),i=o[r];return n.clock!==i.id.clock+i.length-1&&i.constructor!==xv&&o.splice(r+1,0,zv(e,i,n.clock-i.id.clock+1)),i},Yy=(e,t,n,o,r)=>{if(0===o)return;const i=n+o;let s,l=Zy(e,t,n);do{s=t[l++],i<s.id.clock+s.length&&Zy(e,t,i),r(s)}while(l<t.length&&t[l].id.clock<i)};class Qy{constructor(e,t,n){this.doc=e,this.deleteSet=new Wg,this.beforeState=Uy(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const eb=(e,t)=>!(0===t.deleteSet.clients.size&&!((e,t)=>{for(const[n,o]of e)if(t(o,n))return!0;return!1})(t.afterState,(e,n)=>t.beforeState.get(n)!==e))&&(Kg(t.deleteSet),((e,t)=>{hy(e,t.doc.store,t.beforeState)})(e,t),Qg(e,t.deleteSet),!0),tb=(e,t,n)=>{const o=t._item;(null===o||o.id.clock<(e.beforeState.get(o.id.client)||0)&&!o.deleted)&&Bf(e.changed,t,Hf).add(n)},nb=(e,t)=>{let n=e[t],o=e[t-1],r=t;for(;r>0&&(o.deleted===n.deleted&&o.constructor===n.constructor&&o.mergeWith(n));n=o,o=e[--r-1])n instanceof Wv&&null!==n.parentSub&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,o);const i=t-r;return i&&e.splice(t+1-i,i),i},ob=(e,t)=>{if(t<e.length){const n=e[t],o=n.doc,r=o.store,i=n.deleteSet,s=n._mergeStructs;try{Kg(i),n.afterState=Uy(n.doc.store),o.emit("beforeObserverCalls",[n,o]);const e=[];n.changed.forEach((t,o)=>e.push(()=>{null!==o._item&&o._item.deleted||o._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((e,t)=>{t._dEH.l.length>0&&(null===t._item||!t._item.deleted)&&((e=e.filter(e=>null===e.target._item||!e.target._item.deleted)).forEach(e=>{e.currentTarget=t,e._path=null}),e.sort((e,t)=>e.path.length-t.path.length),Sy(t._dEH,e,n))})}),e.push(()=>o.emit("afterTransaction",[n,o])),hg(e,[]),n._needFormattingCleanup&&cv(n)}finally{o.gc&&((e,t,n)=>{for(const[o,r]of e.clients.entries()){const e=t.clients.get(o);for(let o=r.length-1;o>=0;o--){const i=r[o],s=i.clock+i.len;for(let o=Gy(e,i.clock),r=e[o];o<e.length&&r.id.clock<s;r=e[++o]){const r=e[o];if(i.clock+i.len<=r.id.clock)break;r instanceof Wv&&r.deleted&&!r.keep&&n(r)&&r.gc(t,!1)}}}})(i,r,o.gcFilter),((e,t)=>{e.clients.forEach((e,n)=>{const o=t.clients.get(n);for(let t=e.length-1;t>=0;t--){const n=e[t];for(let e=Gf(o.length-1,1+Gy(o,n.clock+n.len-1)),t=o[e];e>0&&t.id.clock>=n.clock;t=o[e])e-=1+nb(o,e)}})})(i,r),n.afterState.forEach((e,t)=>{const o=n.beforeState.get(t)||0;if(o!==e){const e=r.clients.get(t),n=Kf(Gy(e,o),1);for(let t=e.length-1;t>=n;)t-=1+nb(e,t)}});for(let e=s.length-1;e>=0;e--){const{client:t,clock:n}=s[e].id,o=r.clients.get(t),i=Gy(o,n);i+1<o.length&&nb(o,i+1)>1||i>0&&nb(o,i)}if(n.local||n.afterState.get(o.clientID)===n.beforeState.get(o.clientID)||(((...e)=>{$g.forEach(t=>t.print(e))})(Bg,Ag,"[yjs] ",Og,Lg,"Changed the client-id because another client seems to be using it."),o.clientID=ny()),o.emit("afterTransactionCleanup",[n,o]),o._observers.has("update")){const e=new cy;eb(e,n)&&o.emit("update",[e.toUint8Array(),n.origin,o,n])}if(o._observers.has("updateV2")){const e=new uy;eb(e,n)&&o.emit("updateV2",[e.toUint8Array(),n.origin,o,n])}const{subdocsAdded:l,subdocsLoaded:a,subdocsRemoved:c}=n;(l.size>0||c.size>0||a.size>0)&&(l.forEach(e=>{e.clientID=o.clientID,null==e.collectionid&&(e.collectionid=o.collectionid),o.subdocs.add(e)}),c.forEach(e=>o.subdocs.delete(e)),o.emit("subdocs",[{loaded:a,added:l,removed:c},o,n]),c.forEach(e=>e.destroy())),e.length<=t+1?(o._transactionCleanups=[],o.emit("afterAllTransactions",[o,e])):ob(e,t+1)}}},rb=(e,t,n=null,o=!0)=>{const r=e._transactionCleanups;let i=!1,s=null;null===e._transaction&&(i=!0,e._transaction=new Qy(e,n,o),r.push(e._transaction),1===r.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{s=t(e._transaction)}finally{if(i){const t=e._transaction===r[0];e._transaction=null,t&&ob(r,0)}}return s};class ib{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}}const sb=(e,t,n)=>{qg(e,n.deletions,n=>{n instanceof Wv&&t.scope.some(t=>t===e.doc||Ny(t,n))&&$v(n,!1)})},lb=(e,t,n)=>{let o=null;const r=e.doc,i=e.scope;rb(r,n=>{for(;t.length>0&&null===e.currStackItem;){const o=r.store,s=t.pop(),l=new Set,a=[];let c=!1;qg(n,s.insertions,e=>{if(e instanceof Wv){if(null!==e.redone){let{item:t,diff:r}=Vv(o,e.id);r>0&&(t=Jy(n,Ty(t.id.client,t.id.clock+r))),e=t}!e.deleted&&i.some(t=>t===n.doc||Ny(t,e))&&a.push(e)}}),qg(n,s.deletions,e=>{e instanceof Wv&&i.some(t=>t===n.doc||Ny(t,e))&&!Gg(s.insertions,e.id)&&l.add(e)}),l.forEach(t=>{c=null!==Uv(n,t,l,s.insertions,e.ignoreRemoteMapChanges,e)||c});for(let t=a.length-1;t>=0;t--){const o=a[t];e.deleteFilter(o)&&(o.delete(n),c=!0)}e.currStackItem=c?s:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),o=n},e);const s=e.currStackItem;if(null!=s){const t=o.changedParentTypes;e.emit("stack-item-popped",[{stackItem:s,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return s};class ab extends Uf{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:o=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:s=(Ff(e)?e[0].doc:e instanceof oy?e:e.doc)}={}){super(),this.scope=[],this.doc=s,this.addToScope(e),this.deleteFilter=o,r.add(this),this.trackedOrigins=r,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!(this.captureTransaction(e)&&this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)&&(this.trackedOrigins.has(e.origin)||e.origin&&this.trackedOrigins.has(e.origin.constructor))))return;const t=this.undoing,n=this.redoing,o=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);const r=new Wg;e.afterState.forEach((t,n)=>{const o=e.beforeState.get(n)||0,i=t-o;i>0&&Jg(r,n,o,i)});const i=Qm();let s=!1;if(this.lastChange>0&&i-this.lastChange<this.captureTimeout&&o.length>0&&!t&&!n){const t=o[o.length-1];t.deletions=Zg([t.deletions,e.deleteSet]),t.insertions=Zg([t.insertions,r])}else o.push(new ib(e.deleteSet,r)),s=!0;t||n||(this.lastChange=i),qg(e,e.deleteSet,t=>{t instanceof Wv&&this.scope.some(n=>n===e.doc||Ny(n,t))&&$v(t,!0)});const l=[{stackItem:o[o.length-1],origin:e.origin,type:t?"redo":"undo",changedParentTypes:e.changedParentTypes},this];s?this.emit("stack-item-added",l):this.emit("stack-item-updated",l)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){const t=new Set(this.scope);(e=Ff(e)?e:[e]).forEach(e=>{t.has(e)||(t.add(e),(e instanceof jb?e.doc!==this.doc:e!==this.doc)&&Vg("[yjs#509] Not same Y.Doc"),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>sb(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>sb(n,this,e)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){let e;this.undoing=!0;try{e=lb(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){let e;this.redoing=!0;try{e=lb(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}class cb{constructor(e,t){this.gen=function*(e){const t=Bm(e.restDecoder);for(let n=0;n<t;n++){const t=Bm(e.restDecoder),n=e.readClient();let o=Bm(e.restDecoder);for(let r=0;r<t;r++){const t=e.readInfo();if(10===t){const t=Bm(e.restDecoder);yield new Kv(Ty(n,o),t),o+=t}else if(31&t){const r=!(192&t),i=new Wv(Ty(n,o),null,(t&Xf)===Xf?e.readLeftID():null,null,(t&Jf)===Jf?e.readRightID():null,r?e.readParentInfo()?e.readString():e.readLeftID():null,!r||32&~t?null:e.readString(),qv(e,t));yield i,o+=i.length}else{const t=e.readLen();yield new xv(Ty(n,o),t),o+=t}}}}(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Kv);return this.curr}}class db{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const ub=e=>pb(e,iy,cy),hb=(e,t)=>{if(e.constructor===xv){const{client:n,clock:o}=e.id;return new xv(Ty(n,o+t),e.length-t)}if(e.constructor===Kv){const{client:n,clock:o}=e.id;return new Kv(Ty(n,o+t),e.length-t)}{const n=e,{client:o,clock:r}=n.id;return new Wv(Ty(o,r+t),null,Ty(o,r+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},pb=(e,t=ly,n=uy)=>{if(1===e.length)return e[0];const o=e.map(e=>new t(Im(e)));let r=o.map(e=>new cb(e,!0)),i=null;const s=new n,l=new db(s);for(;r=r.filter(e=>null!==e.curr),r.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){const n=e.curr.id.clock-t.curr.id.clock;return 0===n?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===Kv?1:-1:n}return t.curr.id.client-e.curr.id.client}),0!==r.length;){const e=r[0],t=e.curr.id.client;if(null!==i){let n=e.curr,o=!1;for(;null!==n&&n.id.clock+n.length<=i.struct.id.clock+i.struct.length&&n.id.client>=i.struct.id.client;)n=e.next(),o=!0;if(null===n||n.id.client!==t||o&&n.id.clock>i.struct.id.clock+i.struct.length)continue;if(t!==i.struct.id.client)gb(l,i.struct,i.offset),i={struct:n,offset:0},e.next();else if(i.struct.id.clock+i.struct.length<n.id.clock)if(i.struct.constructor===Kv)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{gb(l,i.struct,i.offset);const e=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new Kv(Ty(t,i.struct.id.clock+i.struct.length),e),offset:0}}else{const t=i.struct.id.clock+i.struct.length-n.id.clock;t>0&&(i.struct.constructor===Kv?i.struct.length-=t:n=hb(n,t)),i.struct.mergeWith(n)||(gb(l,i.struct,i.offset),i={struct:n,offset:0},e.next())}}else i={struct:e.curr,offset:0},e.next();for(let n=e.curr;null!==n&&n.id.client===t&&n.id.clock===i.struct.id.clock+i.struct.length&&n.constructor!==Kv;n=e.next())gb(l,i.struct,i.offset),i={struct:n,offset:0}}null!==i&&(gb(l,i.struct,i.offset),i=null),yb(l);const a=o.map(e=>ey(e)),c=Zg(a);return Qg(s,c),s.toUint8Array()},fb=(e,t,n=ly,o=uy)=>{const r=by(t),i=new o,s=new db(i),l=new n(Im(e)),a=new cb(l,!1);for(;a.curr;){const e=a.curr,t=e.id.client,n=r.get(t)||0;if(a.curr.constructor!==Kv)if(e.id.clock+e.length>n)for(gb(s,e,Kf(n-e.id.clock,0)),a.next();a.curr&&a.curr.id.client===t;)gb(s,a.curr,0),a.next();else for(;a.curr&&a.curr.id.client===t&&a.curr.id.clock+a.curr.length<=n;)a.next();else a.next()}yb(s);const c=ey(l);return Qg(i,c),i.toUint8Array()},mb=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:dm(e.encoder.restEncoder)}),e.encoder.restEncoder=cm(),e.written=0)},gb=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&mb(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),pm(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},yb=e=>{mb(e);const t=e.encoder.restEncoder;pm(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const o=e.clientStructs[n];pm(t,o.written),bm(t,o.restEncoder)}},bb=e=>((e,t,n,o)=>{const r=new n(Im(e)),i=new cb(r,!1),s=new o,l=new db(s);for(let c=i.curr;null!==c;c=i.next())gb(l,t(c),0);yb(l);const a=ey(r);return Qg(s,a),s.toUint8Array()})(e,pg,ly,cy),vb="You must not compute changes after the event-handler fired.";class xb{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=wb(this.currentTarget,this.target))}deletes(e){return Gg(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw jm(vb);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(null!==n){const o=t._map.get(n);let r,i;if(this.adds(o)){let e=o.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(o)){if(null===e||!this.deletes(e))return;r="delete",i=Vf(e.content.getContent())}else null!==e&&this.deletes(e)?(r="update",i=Vf(e.content.getContent())):(r="add",i=void 0)}else{if(!this.deletes(o))return;r="delete",i=Vf(o.content.getContent())}e.set(n,{action:r,oldValue:i})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw jm(vb);const t=this.target,n=Hf(),o=Hf(),r=[];e={added:n,deleted:o,delta:r,keys:this.keys};if(this.transaction.changed.get(t).has(null)){let e=null;const i=()=>{e&&r.push(e)};for(let r=t._start;null!==r;r=r.right)r.deleted?this.deletes(r)&&!this.adds(r)&&(null!==e&&void 0!==e.delete||(i(),e={delete:0}),e.delete+=r.length,o.add(r)):this.adds(r)?(null!==e&&void 0!==e.insert||(i(),e={insert:[]}),e.insert=e.insert.concat(r.content.getContent()),n.add(r)):(null!==e&&void 0!==e.retain||(i(),e={retain:0}),e.retain+=r.length);null!==e&&void 0===e.retain&&i()}this._changes=e}return e}}const wb=(e,t)=>{const n=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)n.unshift(t._item.parentSub);else{let e=0,o=t._item.parent._start;for(;o!==t._item&&null!==o;)!o.deleted&&o.countable&&(e+=o.length),o=o.right;n.unshift(e)}t=t._item.parent}return n},kb=()=>{Vg("Invalid access: Add Yjs type to a document before reading data.")};let Cb=0;class Eb{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Cb++}}const Sb=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Cb++},Mb=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const n=0===e._searchMarker.length?null:e._searchMarker.reduce((e,n)=>qf(t-e.index)<qf(t-n.index)?e:n);let o=e._start,r=0;for(null!==n&&(o=n.p,r=n.index,(e=>{e.timestamp=Cb++})(n));null!==o.right&&r<t;){if(!o.deleted&&o.countable){if(t<r+o.length)break;r+=o.length}o=o.right}for(;null!==o.left&&r>t;)o=o.left,!o.deleted&&o.countable&&(r-=o.length);for(;null!==o.left&&o.left.id.client===o.id.client&&o.left.id.clock+o.left.length===o.id.clock;)o=o.left,!o.deleted&&o.countable&&(r-=o.length);return null!==n&&qf(n.index-r)<o.parent.length/80?(Sb(n,o,r),n):((e,t,n)=>{if(e.length>=80){const o=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return Sb(o,t,n),o}{const o=new Eb(t,n);return e.push(o),o}})(e._searchMarker,o,r)},Rb=(e,t,n)=>{for(let o=e.length-1;o>=0;o--){const r=e[o];if(n>0){let t=r.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(r.index-=t.length);if(null===t||!0===t.marker){e.splice(o,1);continue}r.p=t,t.marker=!0}(t<r.index||n>0&&t===r.index)&&(r.index=Kf(t,r.index+n))}},Tb=(e,t,n)=>{const o=e,r=t.changedParentTypes;for(;Bf(r,e,()=>[]).push(n),null!==e._item;)e=e._item.parent;Sy(o._eH,n,t)};class jb{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ky(),this._dEH=ky(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Nm()}clone(){throw Nm()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Cy(this._eH,e)}observeDeep(e){Cy(this._dEH,e)}unobserve(e){Ey(this._eH,e)}unobserveDeep(e){Ey(this._dEH,e)}toJSON(){}}const Nb=(e,t,n)=>{e.doc??kb(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let o=n-t;const r=[];let i=e._start;for(;null!==i&&o>0;){if(i.countable&&!i.deleted){const e=i.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&o>0;n++)r.push(e[n]),o--;t=0}}i=i.right}return r},Ab=e=>{e.doc??kb();const t=[];let n=e._start;for(;null!==n;){if(n.countable&&!n.deleted){const e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},Ob=(e,t)=>{const n=[];let o=e._start;for(;null!==o;){if(o.countable&&$y(o,t)){const e=o.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}o=o.right}return n},_b=(e,t)=>{let n=0,o=e._start;for(e.doc??kb();null!==o;){if(o.countable&&!o.deleted){const r=o.content.getContent();for(let o=0;o<r.length;o++)t(r[o],n++,e)}o=o.right}},Pb=(e,t)=>{const n=[];return _b(e,(o,r)=>{n.push(t(o,r,e))}),n},Ib=e=>{let t=e._start,n=null,o=0;return{[Symbol.iterator](){return this},next:()=>{if(null===n){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return{done:!0,value:void 0};n=t.content.getContent(),o=0,t=t.right}const e=n[o++];return n.length<=o&&(n=null),{done:!1,value:e}}}},Lb=(e,t)=>{e.doc??kb();const n=Mb(e,t);let o=e._start;for(null!==n&&(o=n.p,t-=n.index);null!==o;o=o.right)if(!o.deleted&&o.countable){if(t<o.length)return o.content.getContent()[t];t-=o.length}},Db=(e,t,n,o)=>{let r=n;const i=e.doc,s=i.clientID,l=i.store,a=null===n?t._start:n.right;let c=[];const d=()=>{c.length>0&&(r=new Wv(Ty(s,Wy(l,s)),r,r&&r.lastId,a,a&&a.id,t,null,new jv(c)),r.integrate(e,0),c=[])};o.forEach(n=>{if(null===n)c.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(n);break;default:switch(d(),n.constructor){case Uint8Array:case ArrayBuffer:r=new Wv(Ty(s,Wy(l,s)),r,r&&r.lastId,a,a&&a.id,t,null,new wv(new Uint8Array(n))),r.integrate(e,0);break;case oy:r=new Wv(Ty(s,Wy(l,s)),r,r&&r.lastId,a,a&&a.id,t,null,new Ev(n)),r.integrate(e,0);break;default:if(!(n instanceof jb))throw new Error("Unexpected content type in insert operation");r=new Wv(Ty(s,Wy(l,s)),r,r&&r.lastId,a,a&&a.id,t,null,new Hv(n)),r.integrate(e,0)}}}),d()},Bb=()=>jm("Length exceeded!"),Hb=(e,t,n,o)=>{if(n>t._length)throw Bb();if(0===n)return t._searchMarker&&Rb(t._searchMarker,n,o.length),Db(e,t,null,o);const r=n,i=Mb(t,n);let s=t._start;for(null!==i&&(s=i.p,0===(n-=i.index)&&(s=s.prev,n+=s&&s.countable&&!s.deleted?s.length:0));null!==s;s=s.right)if(!s.deleted&&s.countable){if(n<=s.length){n<s.length&&Jy(e,Ty(s.id.client,s.id.clock+n));break}n-=s.length}return t._searchMarker&&Rb(t._searchMarker,r,o.length),Db(e,t,s,o)},Vb=(e,t,n,o)=>{if(0===o)return;const r=n,i=o,s=Mb(t,n);let l=t._start;for(null!==s&&(l=s.p,n-=s.index);null!==l&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&Jy(e,Ty(l.id.client,l.id.clock+n)),n-=l.length);for(;o>0&&null!==l;)l.deleted||(o<l.length&&Jy(e,Ty(l.id.client,l.id.clock+o)),l.delete(e),o-=l.length),l=l.right;if(o>0)throw Bb();t._searchMarker&&Rb(t._searchMarker,r,-i+o)},$b=(e,t,n)=>{const o=t._map.get(n);void 0!==o&&o.delete(e)},zb=(e,t,n,o)=>{const r=t._map.get(n)||null,i=e.doc,s=i.clientID;let l;if(null==o)l=new jv([o]);else switch(o.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new jv([o]);break;case Uint8Array:l=new wv(o);break;case oy:l=new Ev(o);break;default:if(!(o instanceof jb))throw new Error("Unexpected content type");l=new Hv(o)}new Wv(Ty(s,Wy(i.store,s)),r,r&&r.lastId,null,null,t,n,l).integrate(e,0)},Fb=(e,t)=>{e.doc??kb();const n=e._map.get(t);return void 0===n||n.deleted?void 0:n.content.getContent()[n.length-1]},Ub=e=>{const t={};return e.doc??kb(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Wb=(e,t)=>{e.doc??kb();const n=e._map.get(t);return void 0!==n&&!n.deleted},qb=e=>{return e.doc??kb(),t=e._map.entries(),n=e=>!e[1].deleted,zg(()=>{let e;do{e=t.next()}while(!e.done&&!n(e.value));return e});var t,n};class Gb extends xb{}class Kb extends jb{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new Kb;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Kb}clone(){const e=new Kb;return e.insert(0,this.toArray().map(e=>e instanceof jb?e.clone():e)),e}get length(){return this.doc??kb(),this._length}_callObserver(e,t){super._callObserver(e,t),Tb(this,e,new Gb(this,e))}insert(e,t){null!==this.doc?rb(this.doc,n=>{Hb(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?rb(this.doc,t=>{((e,t,n)=>{let o=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(o)for(;o.right;)o=o.right;Db(e,t,o,n)})(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){null!==this.doc?rb(this.doc,n=>{Vb(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Lb(this,e)}toArray(){return Ab(this)}slice(e=0,t=this.length){return Nb(this,e,t)}toJSON(){return this.map(e=>e instanceof jb?e.toJSON():e)}map(e){return Pb(this,e)}forEach(e){_b(this,e)}[Symbol.iterator](){return Ib(this)}_write(e){e.writeTypeRef(Ov)}}class Zb extends xb{constructor(e,t,n){super(e,t),this.keysChanged=n}}class Jb extends jb{constructor(e){super(),this._prelimContent=null,this._prelimContent=void 0===e?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new Jb}clone(){const e=new Jb;return this.forEach((t,n)=>{e.set(n,t instanceof jb?t.clone():t)}),e}_callObserver(e,t){Tb(this,e,new Zb(this,e,t))}toJSON(){this.doc??kb();const e={};return this._map.forEach((t,n)=>{if(!t.deleted){const o=t.content.getContent()[t.length-1];e[n]=o instanceof jb?o.toJSON():o}}),e}get size(){return[...qb(this)].length}keys(){return Fg(qb(this),e=>e[0])}values(){return Fg(qb(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Fg(qb(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??kb(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?rb(this.doc,t=>{$b(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?rb(this.doc,n=>{zb(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Fb(this,e)}has(e){return Wb(this,e)}clear(){null!==this.doc?rb(this.doc,e=>{this.forEach(function(t,n,o){$b(e,o,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(_v)}}const Xb=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&cg(e,t);class Yb{constructor(e,t,n,o){this.left=e,this.right=t,this.index=n,this.currentAttributes=o}forward(){if(null===this.right&&Am(),this.right.content.constructor===Mv)this.right.deleted||nv(this.currentAttributes,this.right.content);else this.right.deleted||(this.index+=this.right.length);this.left=this.right,this.right=this.right.right}}const Qb=(e,t,n)=>{for(;null!==t.right&&n>0;){if(t.right.content.constructor===Mv)t.right.deleted||nv(t.currentAttributes,t.right.content);else t.right.deleted||(n<t.right.length&&Jy(e,Ty(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);t.left=t.right,t.right=t.right.right}return t},ev=(e,t,n,o)=>{const r=new Map,i=o?Mb(t,n):null;if(i){const t=new Yb(i.p.left,i.p,i.index,r);return Qb(e,t,n-i.index)}{const o=new Yb(null,t._start,0,r);return Qb(e,o,n)}},tv=(e,t,n,o)=>{for(;null!==n.right&&(!0===n.right.deleted||n.right.content.constructor===Mv&&Xb(o.get(n.right.content.key),n.right.content.value));)n.right.deleted||o.delete(n.right.content.key),n.forward();const r=e.doc,i=r.clientID;o.forEach((o,s)=>{const l=n.left,a=n.right,c=new Wv(Ty(i,Wy(r.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new Mv(s,o));c.integrate(e,0),n.right=c,n.forward()})},nv=(e,t)=>{const{key:n,value:o}=t;null===o?e.delete(n):e.set(n,o)},ov=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===Mv&&Xb(t[e.right.content.key]??null,e.right.content.value));)e.forward()},rv=(e,t,n,o)=>{const r=e.doc,i=r.clientID,s=new Map;for(const l in o){const a=o[l],c=n.currentAttributes.get(l)??null;if(!Xb(c,a)){s.set(l,c);const{left:o,right:d}=n;n.right=new Wv(Ty(i,Wy(r.store,i)),o,o&&o.lastId,d,d&&d.id,t,null,new Mv(l,a)),n.right.integrate(e,0),n.forward()}}return s},iv=(e,t,n,o,r)=>{n.currentAttributes.forEach((e,t)=>{void 0===r[t]&&(r[t]=null)});const i=e.doc,s=i.clientID;ov(n,r);const l=rv(e,t,n,r),a=o.constructor===String?new Nv(o):o instanceof jb?new Hv(o):new Sv(o);let{left:c,right:d,index:u}=n;t._searchMarker&&Rb(t._searchMarker,n.index,a.getLength()),d=new Wv(Ty(s,Wy(i.store,s)),c,c&&c.lastId,d,d&&d.id,t,null,a),d.integrate(e,0),n.right=d,n.index=u,n.forward(),tv(e,t,n,l)},sv=(e,t,n,o,r)=>{const i=e.doc,s=i.clientID;ov(n,r);const l=rv(e,t,n,r);e:for(;null!==n.right&&(o>0||l.size>0&&(n.right.deleted||n.right.content.constructor===Mv));){if(!n.right.deleted)switch(n.right.content.constructor){case Mv:{const{key:t,value:i}=n.right.content,s=r[t];if(void 0!==s){if(Xb(s,i))l.delete(t);else{if(0===o)break e;l.set(t,i)}n.right.delete(e)}else n.currentAttributes.set(t,i);break}default:o<n.right.length&&Jy(e,Ty(n.right.id.client,n.right.id.clock+o)),o-=n.right.length}n.forward()}if(o>0){let r="";for(;o>0;o--)r+="\n";n.right=new Wv(Ty(s,Wy(i.store,s)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Nv(r)),n.right.integrate(e,0),n.forward()}tv(e,t,n,l)},lv=(e,t,n,o,r)=>{let i=t;const s=Lf();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===Mv){const e=i.content;s.set(e.key,e)}i=i.right}let l=0,a=!1;for(;t!==i;){if(n===t&&(a=!0),!t.deleted){const n=t.content;switch(n.constructor){case Mv:{const{key:i,value:c}=n,d=o.get(i)??null;s.get(i)===n&&d!==c||(t.delete(e),l++,a||(r.get(i)??null)!==c||d===c||(null===d?r.delete(i):r.set(i,d))),a||t.deleted||nv(r,n);break}}}t=t.right}return l},av=e=>{let t=0;return rb(e.doc,n=>{let o=e._start,r=e._start,i=Lf();const s=Df(i);for(;r;){if(!1===r.deleted)if(r.content.constructor===Mv)nv(s,r.content);else t+=lv(n,o,r,i,s),i=Df(s),o=r;r=r.right}}),t},cv=e=>{const t=new Set,n=e.doc;for(const[o,r]of e.afterState.entries()){const i=e.beforeState.get(o)||0;r!==i&&Yy(e,n.store.clients.get(o),i,r,e=>{e.deleted||e.content.constructor!==Mv||e.constructor===xv||t.add(e.parent)})}rb(n,n=>{qg(e,e.deleteSet,e=>{if(e instanceof xv||!e.parent._hasFormatting||t.has(e.parent))return;const o=e.parent;e.content.constructor===Mv?t.add(o):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Mv){const o=t.content.key;n.has(o)?t.delete(e):n.add(o)}t=t.left}})(n,e)});for(const e of t)av(e)})},dv=(e,t,n)=>{const o=n,r=Df(t.currentAttributes),i=t.right;for(;n>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case Hv:case Sv:case Nv:n<t.right.length&&Jy(e,Ty(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}i&&lv(e,i,t.right,r,t.currentAttributes);const s=(t.left||t.right).parent;return s._searchMarker&&Rb(s._searchMarker,t.index,-o+n),t};class uv extends xb{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{null===e?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(null===this._changes){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(null===this._delta){const e=this.target.doc,t=[];rb(e,e=>{const n=new Map,o=new Map;let r=this.target._start,i=null;const s={};let l="",a=0,c=0;const d=()=>{if(null!==i){let e=null;switch(i){case"delete":c>0&&(e={delete:c}),c=0;break;case"insert":("object"==typeof l||l.length>0)&&(e={insert:l},n.size>0&&(e.attributes={},n.forEach((t,n)=>{null!==t&&(e.attributes[n]=t)}))),l="";break;case"retain":a>0&&(e={retain:a},(e=>{for(const t in e)return!1;return!0})(s)||(e.attributes=ig({},s))),a=0}e&&t.push(e),i=null}};for(;null!==r;){switch(r.content.constructor){case Hv:case Sv:this.adds(r)?this.deletes(r)||(d(),i="insert",l=r.content.getContent()[0],d()):this.deletes(r)?("delete"!==i&&(d(),i="delete"),c+=1):r.deleted||("retain"!==i&&(d(),i="retain"),a+=1);break;case Nv:this.adds(r)?this.deletes(r)||("insert"!==i&&(d(),i="insert"),l+=r.content.str):this.deletes(r)?("delete"!==i&&(d(),i="delete"),c+=r.length):r.deleted||("retain"!==i&&(d(),i="retain"),a+=r.length);break;case Mv:{const{key:t,value:l}=r.content;if(this.adds(r)){if(!this.deletes(r)){const a=n.get(t)??null;Xb(a,l)?null!==l&&r.delete(e):("retain"===i&&d(),Xb(l,o.get(t)??null)?delete s[t]:s[t]=l)}}else if(this.deletes(r)){o.set(t,l);const e=n.get(t)??null;Xb(e,l)||("retain"===i&&d(),s[t]=e)}else if(!r.deleted){o.set(t,l);const n=s[t];void 0!==n&&(Xb(n,l)?null!==n&&r.delete(e):("retain"===i&&d(),null===l?delete s[t]:s[t]=l))}r.deleted||("insert"===i&&d(),nv(n,r.content));break}}r=r.right}for(d();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop()}}),this._delta=t}return this._delta}}class hv extends jb{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??kb(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(VD){}this._pending=null}_copy(){return new hv}clone(){const e=new hv;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const n=new uv(this,e,t);Tb(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??kb();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===Nv&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){null!==this.doc?rb(this.doc,n=>{const o=new Yb(null,this._start,0,new Map);for(let r=0;r<e.length;r++){const i=e[r];if(void 0!==i.insert){const s=t||"string"!=typeof i.insert||r!==e.length-1||null!==o.right||"\n"!==i.insert.slice(-1)?i.insert:i.insert.slice(0,-1);("string"!=typeof s||s.length>0)&&iv(n,this,o,s,i.attributes||{})}else void 0!==i.retain?sv(n,this,o,i.retain,i.attributes||{}):void 0!==i.delete&&dv(n,o,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){this.doc??kb();const o=[],r=new Map,i=this.doc;let s="",l=this._start;function a(){if(s.length>0){const e={};let t=!1;r.forEach((n,o)=>{t=!0,e[o]=n});const n={insert:s};t&&(n.attributes=e),o.push(n),s=""}}const c=()=>{for(;null!==l;){if($y(l,e)||void 0!==t&&$y(l,t))switch(l.content.constructor){case Nv:{const o=r.get("ychange");void 0===e||$y(l,e)?void 0===t||$y(l,t)?void 0!==o&&(a(),r.delete("ychange")):void 0!==o&&o.user===l.id.client&&"added"===o.type||(a(),r.set("ychange",n?n("added",l.id):{type:"added"})):void 0!==o&&o.user===l.id.client&&"removed"===o.type||(a(),r.set("ychange",n?n("removed",l.id):{type:"removed"})),s+=l.content.str;break}case Hv:case Sv:{a();const e={insert:l.content.getContent()[0]};if(r.size>0){const t={};e.attributes=t,r.forEach((e,n)=>{t[n]=e})}o.push(e);break}case Mv:$y(l,e)&&(a(),nv(r,l.content))}l=l.right}a()};return e||t?rb(i,n=>{e&&zy(n,e),t&&zy(n,t),c()},"cleanup"):c(),o}insert(e,t,n){if(t.length<=0)return;const o=this.doc;null!==o?rb(o,o=>{const r=ev(o,this,e,!n);n||(n={},r.currentAttributes.forEach((e,t)=>{n[t]=e})),iv(o,this,r,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const o=this.doc;null!==o?rb(o,o=>{const r=ev(o,this,e,!n);iv(o,this,r,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(0===t)return;const n=this.doc;null!==n?rb(n,n=>{dv(n,ev(n,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(0===t)return;const o=this.doc;null!==o?rb(o,o=>{const r=ev(o,this,e,!1);null!==r.right&&sv(o,this,r,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){null!==this.doc?rb(this.doc,t=>{$b(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){null!==this.doc?rb(this.doc,n=>{zb(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Fb(this,e)}getAttributes(){return Ub(this)}_write(e){e.writeTypeRef(Pv)}}class pv{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??kb()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(null!==e&&(!this._firstCall||e.deleted||!this._filter(t)))do{if(t=e.content.type,e.deleted||t.constructor!==mv&&t.constructor!==fv||null===t._start)for(;null!==e;){const t=e.next;if(null!==t){e=t;break}e=e.parent===this._root?null:e.parent._item}else e=t._start}while(null!==e&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,null===e?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class fv extends jb{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new fv}clone(){const e=new fv;return e.insert(0,this.toArray().map(e=>e instanceof jb?e.clone():e)),e}get length(){return this.doc??kb(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new pv(this,e)}querySelector(e){e=e.toUpperCase();const t=new pv(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),zf(new pv(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){Tb(this,e,new gv(this,t,e))}toString(){return Pb(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const o=e.createDocumentFragment();return void 0!==n&&n._createAssociation(o,this),_b(this,r=>{o.insertBefore(r.toDOM(e,t,n),null)}),o}insert(e,t){null!==this.doc?rb(this.doc,n=>{Hb(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)rb(this.doc,n=>{const o=e&&e instanceof jb?e._item:e;Db(n,this,o,t)});else{const n=this._prelimContent,o=null===e?0:n.findIndex(t=>t===e)+1;if(0===o&&null!==e)throw jm("Reference item not found");n.splice(o,0,...t)}}delete(e,t=1){null!==this.doc?rb(this.doc,n=>{Vb(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Ab(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Lb(this,e)}slice(e=0,t=this.length){return Nb(this,e,t)}forEach(e){_b(this,e)}_write(e){e.writeTypeRef(Lv)}}class mv extends fv{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new mv(this.nodeName)}clone(){const e=new mv(this.nodeName);return((e,t)=>{for(const n in e)t(e[n],n)})(this.getAttributes(),(t,n)=>{"string"==typeof t&&e.setAttribute(n,t)}),e.insert(0,this.toArray().map(e=>e instanceof jb?e.clone():e)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const i in e)n.push(i);n.sort();const o=n.length;for(let i=0;i<o;i++){const o=n[i];t.push(o+'="'+e[o]+'"')}const r=this.nodeName.toLocaleLowerCase();return`<${r}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${r}>`}removeAttribute(e){null!==this.doc?rb(this.doc,t=>{$b(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?rb(this.doc,n=>{zb(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Fb(this,e)}hasAttribute(e){return Wb(this,e)}getAttributes(e){return e?((e,t)=>{const n={};return e._map.forEach((e,o)=>{let r=e;for(;null!==r&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;null!==r&&$y(r,t)&&(n[o]=r.content.getContent()[r.length-1])}),n})(this,e):Ub(this)}toDOM(e=document,t={},n){const o=e.createElement(this.nodeName),r=this.getAttributes();for(const i in r){const e=r[i];"string"==typeof e&&o.setAttribute(i,e)}return _b(this,r=>{o.appendChild(r.toDOM(e,t,n))}),void 0!==n&&n._createAssociation(o,this),o}_write(e){e.writeTypeRef(Iv),e.writeKey(this.nodeName)}}class gv extends xb{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{null===e?this.childListChanged=!0:this.attributesChanged.add(e)})}}class yv extends Jb{constructor(e){super(),this.hookName=e}_copy(){return new yv(this.hookName)}clone(){const e=new yv(this.hookName);return this.forEach((t,n)=>{e.set(n,t)}),e}toDOM(e=document,t={},n){const o=t[this.hookName];let r;return r=void 0!==o?o.createDom(this):document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),void 0!==n&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Dv),e.writeKey(this.hookName)}}class bv extends hv{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new bv}clone(){const e=new bv;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,n){const o=e.createTextNode(this.toString());return void 0!==n&&n._createAssociation(o,this),o}toString(){return this.toDelta().map(e=>{const t=[];for(const o in e.attributes){const n=[];for(const t in e.attributes[o])n.push({key:t,value:e.attributes[o][t]});n.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:o,attrs:n})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n="";for(let o=0;o<t.length;o++){const e=t[o];n+=`<${e.nodeName}`;for(let t=0;t<e.attrs.length;t++){const o=e.attrs[t];n+=` ${o.key}="${o.value}"`}n+=">"}n+=e.insert;for(let o=t.length-1;o>=0;o--)n+=`</${t[o].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Bv)}}class vv{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Nm()}mergeWith(e){return!1}write(e,t,n){throw Nm()}integrate(e,t){throw Nm()}}class xv extends vv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),qy(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}}class wv{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new wv(this.content)}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class kv{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new kv(this.len)}splice(e){const t=new kv(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Jg(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const Cv=(e,t)=>new oy({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Ev{constructor(e){e._item,this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),null!==e.meta&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Ev(Cv(this.doc.guid,this.opts))}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}class Sv{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Sv(this.embed)}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class Mv{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Mv(this.key,this.value)}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}class Rv{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Rv(this.arr)}splice(e){const t=new Rv(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let o=t;o<n;o++){const t=this.arr[o];e.writeString(void 0===t?"undefined":JSON.stringify(t))}}getRef(){return 2}}const Tv="development"===bg("node_env");class jv{constructor(e){this.arr=e,Tv&&ug(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new jv(this.arr)}splice(e){const t=new jv(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let o=t;o<n;o++){const t=this.arr[o];e.writeAny(t)}}getRef(){return 8}}class Nv{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Nv(this.str)}splice(e){const t=new Nv(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(0===t?this.str:this.str.slice(t))}getRef(){return 4}}const Av=[e=>new Kb,e=>new Jb,e=>new hv,e=>new mv(e.readKey()),e=>new fv,e=>new yv(e.readKey()),e=>new bv],Ov=0,_v=1,Pv=2,Iv=3,Lv=4,Dv=5,Bv=6;class Hv{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Hv(this.type._copy())}splice(e){throw Nm()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;null!==t;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;null!==t;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;null!==t;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const Vv=(e,t)=>{let n,o=t,r=0;do{r>0&&(o=Ty(o.client,o.clock+r)),n=Ky(e,o),r=o.clock-n.id.clock,o=n.redone}while(null!==o&&n instanceof Wv);return{item:n,diff:r}},$v=(e,t)=>{for(;null!==e&&e.keep!==t;)e.keep=t,e=e.parent._item},zv=(e,t,n)=>{const{client:o,clock:r}=t.id,i=new Wv(Ty(o,r+n),t,Ty(o,r+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),null!==t.redone&&(i.redone=Ty(t.redone.client,t.redone.clock+n)),t.right=i,null!==i.right&&(i.right.left=i),e._mergeStructs.push(i),null!==i.parentSub&&null===i.right&&i.parent._map.set(i.parentSub,i),t.length=n,i},Fv=(e,t)=>((e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1})(e,e=>Gg(e.deletions,t)),Uv=(e,t,n,o,r,i)=>{const s=e.doc,l=s.store,a=s.clientID,c=t.redone;if(null!==c)return Jy(e,c);let d,u=t.parent._item,h=null;if(null!==u&&!0===u.deleted){if(null===u.redone&&(!n.has(u)||null===Uv(e,u,n,o,r,i)))return null;for(;null!==u.redone;)u=Jy(e,u.redone)}const p=null===u?t.parent:u.content.type;if(null===t.parentSub){for(h=t.left,d=t;null!==h;){let t=h;for(;null!==t&&t.parent._item!==u;)t=null===t.redone?null:Jy(e,t.redone);if(null!==t&&t.parent._item===u){h=t;break}h=h.left}for(;null!==d;){let t=d;for(;null!==t&&t.parent._item!==u;)t=null===t.redone?null:Jy(e,t.redone);if(null!==t&&t.parent._item===u){d=t;break}d=d.right}}else if(d=null,t.right&&!r){for(h=t;null!==h&&null!==h.right&&(h.right.redone||Gg(o,h.right.id)||Fv(i.undoStack,h.right.id)||Fv(i.redoStack,h.right.id));)for(h=h.right;h.redone;)h=Jy(e,h.redone);if(h&&null!==h.right)return null}else h=p._map.get(t.parentSub)||null;const f=Wy(l,a),m=Ty(a,f),g=new Wv(m,h,h&&h.lastId,d,d&&d.id,p,t.parentSub,t.content.copy());return t.redone=m,$v(g,!0),g.integrate(e,0),g};class Wv extends vv{constructor(e,t,n,o,r,i,s,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=o,this.rightOrigin=r,this.parent=i,this.parentSub=s,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(e){(8&this.info)>0!==e&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Wy(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Wy(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===My&&this.id.client!==this.parent.client&&this.parent.clock>=Wy(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Xy(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Jy(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===xv||this.right&&this.right.constructor===xv)this.parent=null;else if(this.parent){if(this.parent.constructor===My){const e=Ky(t,this.parent);e.constructor===xv?this.parent=null:this.parent=e.content.type}}else this.left&&this.left.constructor===Wv?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Wv&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Xy(e,e.doc.store,Ty(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let t,n=this.left;if(null!==n)t=n.right;else if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start;const o=new Set,r=new Set;for(;null!==t&&t!==this.right;){if(r.add(t),o.add(t),Ry(this.origin,t.origin)){if(t.id.client<this.id.client)n=t,o.clear();else if(Ry(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!r.has(Ky(e.doc.store,t.origin)))break;o.has(Ky(e.doc.store,t.origin))||(n=t,o.clear())}t=t.right}this.left=n}if(null!==this.left){const e=this.left.right;this.right=e,this.left.right=this}else{let e;if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(e)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),qy(e.doc.store,this),this.content.integrate(e,this),tb(e,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(e)}else new xv(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;null!==e&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;null!==e&&e.deleted;)e=e.left;return e}get lastId(){return 1===this.length?this.id:Ty(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Ry(e.origin,this.lastId)&&this.right===e&&Ry(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&null===this.redone&&null===e.redone&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,null!==this.right&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&null===this.parentSub&&(t._length-=this.length),this.markDeleted(),Jg(e.deleteSet,this.id.client,this.id.clock,this.length),tb(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw Am();this.content.gc(e),t?((e,t,n)=>{const o=e.clients.get(t.id.client);o[Gy(o,t.id.clock)]=n})(e,this,new xv(this.id,this.length)):this.content=new kv(this.length)}write(e,t){const n=t>0?Ty(this.id.client,this.id.clock+t-1):this.origin,o=this.rightOrigin,r=this.parentSub,i=31&this.content.getRef()|(null===n?0:Xf)|(null===o?0:Jf)|(null===r?0:32);if(e.writeInfo(i),null!==n&&e.writeLeftID(n),null!==o&&e.writeRightID(o),null===n&&null===o){const t=this.parent;if(void 0!==t._item){const n=t._item;if(null===n){const n=jy(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===My?(e.writeParentInfo(!1),e.writeLeftID(t)):Am();null!==r&&e.writeString(r)}this.content.write(e,t)}}const qv=(e,t)=>Gv[31&t](e),Gv=[()=>{Am()},e=>new kv(e.readLen()),e=>{const t=e.readLen(),n=[];for(let o=0;o<t;o++){const t=e.readString();"undefined"===t?n.push(void 0):n.push(JSON.parse(t))}return new Rv(n)},e=>new wv(e.readBuf()),e=>new Nv(e.readString()),e=>new Sv(e.readJSON()),e=>new Mv(e.readKey(),e.readJSON()),e=>new Hv(Av[e.readTypeRef()](e)),e=>{const t=e.readLen(),n=[];for(let o=0;o<t;o++)n.push(e.readAny());return new jv(n)},e=>new Ev(Cv(e.readString(),e.readAny())),()=>{Am()}];class Kv extends vv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){Am()}write(e,t){e.writeInfo(10),pm(e.restEncoder,this.length-t)}getMissing(e,t){return null}}const Zv="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Jv="__ $YJS$ __";Zv[Jv],Zv[Jv]=!0;const Xv=/[\uD800-\uDBFF]/,Yv=/[\uDC00-\uDFFF]/,Qv=(e,t)=>{let n=0,o=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&Xv.test(e[n-1])&&n--;o+n<e.length&&o+n<t.length&&e[e.length-o-1]===t[t.length-o-1];)o++;return o>0&&Yv.test(e[e.length-o])&&o--,{index:n,remove:e.length-n-o,insert:t.slice(n,t.length-o)}},ex=new Kr("y-sync"),tx=new Kr("y-undo"),nx=new Kr("yjs-cursor"),ox=(e,t)=>e>>>t|e<<32-t,rx=e=>ox(e,2)^ox(e,13)^ox(e,22),ix=e=>ox(e,6)^ox(e,11)^ox(e,25),sx=e=>ox(e,7)^ox(e,18)^e>>>3,lx=e=>ox(e,17)^ox(e,19)^e>>>10,ax=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),cx=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class dx{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(cx),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,t=this._W;for(let d=16;d<64;d++)t[d]=lx(t[d-2])+t[d-7]+sx(t[d-15])+t[d-16];let n=e[0],o=e[1],r=e[2],i=e[3],s=e[4],l=e[5],a=e[6],c=e[7];for(let d,u,h=0;h<64;h++)d=c+ix(s)+(s&l^~s&a)+ax[h]+t[h]>>>0,u=rx(n)+(n&o^n&r^o&r)>>>0,c=a,a=l,l=s,s=i+d>>>0,i=r,r=o,o=n,n=d+u>>>0;e[0]+=n,e[1]+=o,e[2]+=r,e[3]+=i,e[4]+=s,e[5]+=l,e[6]+=a,e[7]+=c}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3<e.length;n++)this._W[n]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!=0){for(this._W.fill(0,n,16);t<e.length;)this._W[n]|=e[t]<<8*(3-t%4),t++;this._W[n]|=Xf<<8*(3-t%4)}this._updateHash()}const n=t%64!=0;this._W.fill(0,0,16);let o=0;for(;t<e.length;o++)for(let n=3;n>=0&&t<e.length;n--)this._W[o]|=e[t++]<<8*n;n||(this._W[o-(t%4==0?0:1)]|=Xf<<8*(3-t%4)),this._W[14]=e.byteLength/536870912,this._W[15]=8*e.byteLength,this._updateHash();const r=new Uint8Array(32);for(let i=0;i<this._H.length;i++)for(let e=0;e<4;e++)r[4*i+e]=this._H[i]>>>8*(3-e);return r}}const ux=e=>{return wg((e=>{for(let t=6;t<e.length;t++)e[t%6]=e[t%6]^e[t];return e.slice(0,6)})((t=Cg(e),(new dx).digest(t))));var t},hx=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Gg(t.ds,e.id),px=[{light:"#ecd44433",dark:"#ecd444"}],fx=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const n=Hf();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,(o=t)[Wf(Zm()*o.length)])}var o;return e.get(n)},mx=(e,t)=>({type:t.selection.jsonID,anchor:Dx(t.selection.anchor,e.type,e.mapping),head:Dx(t.selection.head,e.type,e.mapping)});class gx{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=(()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else void 0!==n&&n()}})(),this.mapping=t,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{null===this.beforeTransactionSelection&&null!=this.prosemirrorView&&(this.beforeTransactionSelection=mx(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return!!this.prosemirrorView.hasFocus()&&(mg&&null===this._domSelectionInView&&(jg(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView)}_isDomSelectionInView(){const e=this.prosemirrorView._root.getSelection();if(null==e||null==e.anchorNode)return!1;const t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset);0===t.getClientRects().length&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);const n=t.getBoundingClientRect(),o=Mg.documentElement;return n.bottom>=0&&n.right>=0&&n.left<=(window.innerWidth||o.clientWidth||0)&&n.top<=(window.innerHeight||o.clientHeight||0)}renderSnapshot(e,t){t||(t=Hy(Xg(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(ex,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(e=>bx(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _n(Rn.from(e),0,0));t.setMeta(ex,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const e=null!==this.beforeTransactionSelection?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(e=>bx(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _n(Rn.from(t),0,0));if(e){const t=Gf(Kf(e.anchor,0),n.doc.content.size),o=Gf(Kf(e.head,0),n.doc.content.size);n.setSelection(Nr.create(n.doc,t,o))}this.prosemirrorView.dispatch(n.setMeta(ex,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let o=this.doc,r=this.type;if(e||(e=Vy(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if(e instanceof Uint8Array&&t instanceof Uint8Array||Am(),o=new oy({gc:!1}),fy(o,t),t=Vy(o),fy(o,e),e=Vy(o),null===r._item){const e=Array.from(this.doc.share.keys()).find(e=>this.doc.share.get(e)===this.type);r=o.getXmlFragment(e)}else{const e=o.store.clients.get(r._item.id.client)??[],t=e[Gy(e,r._item.id.clock)].content;r=t.type}this.mapping.clear(),this.mux(()=>{o.transact(o=>{const i=n.permanentUserData;i&&i.dss.forEach(e=>{qg(o,e,e=>{})});const s=(e,t)=>{const o="added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t);return{user:o,type:e,color:fx(n.colorMapping,n.colors,o)}},l=Ob(r,new By(t.ds,e.sv)).map(n=>!n._item.deleted||hx(n._item,e)||hx(n._item,t)?bx(n,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,s):null).filter(e=>null!==e),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _n(Rn.from(l),0,0));this.prosemirrorView.dispatch(a.setMeta(ex,{isChangeOrigin:!0}))},ex)})}_typeChanged(e,t){if(null==this.prosemirrorView)return;const n=ex.getState(this.prosemirrorView.state);0!==e.length&&null==n.snapshot&&null==n.prevSnapshot?this.mux(()=>{const e=(e,t)=>this.mapping.delete(t);qg(t,t.deleteSet,e=>{if(e.constructor===Wv){const t=e.content.type;t&&this.mapping.delete(t)}}),t.changed.forEach(e),t.changedParentTypes.forEach(e);const n=this.type.toArray().map(e=>yx(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e);let o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new _n(Rn.from(n),0,0));((e,t,n)=>{if(null!==t&&null!==t.anchor&&null!==t.head)if("all"===t.type)e.setSelection(new Pr(e.doc));else if("node"===t.type){const o=Hx(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Or.create(e.doc,o))}else{const o=Hx(n.doc,n.type,t.anchor,n.mapping),r=Hx(n.doc,n.type,t.head,n.mapping);if(null!==o&&null!==r){const t=Nr.between(e.doc.resolve(o),e.doc.resolve(r));e.setSelection(t)}}})(o,this.beforeTransactionSelection,this),o=o.setMeta(ex,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof ab}),null!==this.beforeTransactionSelection&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)}):this.renderSnapshot(n.snapshot,n.prevSnapshot)}_prosemirrorChanged(e){this.doc.transact(()=>{_x(this.doc,this.type,e,this),this.beforeTransactionSelection=mx(this,this.prosemirrorView.state)},ex)}initView(e){null!=this.prosemirrorView&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){null!=this.prosemirrorView&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const yx=(e,t,n,o,r,i)=>{const s=n.mapping.get(e);if(void 0===s){if(e instanceof mv)return bx(e,t,n,o,r,i);throw Nm()}return s},bx=(e,t,n,o,r,i)=>{const s=[],l=e=>{var l,a;if(e instanceof mv){const l=yx(e,t,n,o,r,i);null!==l&&s.push(l)}else{const c=null==(a=null==(l=e._item.right)?void 0:l.content)?void 0:a.type;c instanceof hv&&!c._item.deleted&&c._item.id.client===c.doc.clientID&&(e.applyDelta([{retain:e.length},...c.toDelta()]),c.doc.transact(e=>{c._item.delete(e)}));const d=vx(e,t,n,o,r,i);null!==d&&d.forEach(e=>{null!==e&&s.push(e)})}};void 0===o||void 0===r?e.toArray().forEach(l):Ob(e,new By(r.ds,o.sv)).forEach(l);try{const l=e.getAttributes(o);void 0!==o&&(hx(e._item,o)?hx(e._item,r)||(l.ychange=i?i("added",e._item.id):{type:"added"}):l.ychange=i?i("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,l,s);return n.mapping.set(e,a),a}catch(VD){return e.doc.transact(t=>{e._item.delete(t)},ex),n.mapping.delete(e),null}},vx=(e,t,n,o,r,i)=>{const s=[],l=e.toDelta(o,r,i);try{for(let e=0;e<l.length;e++){const n=l[e];s.push(t.text(n.insert,Ax(n.attributes,t)))}}catch(VD){return e.doc.transact(t=>{e._item.delete(t)},ex),null}return s},xx=(e,t)=>e instanceof Array?((e,t)=>{const n=new bv,o=e.map(e=>({insert:e.text,attributes:Ox(e.marks,t)}));return n.applyDelta(o),t.mapping.set(n,e),n})(e,t):((e,t)=>{const n=new mv(e.type.name);for(const o in e.attrs){const t=e.attrs[o];null!==t&&"ychange"!==o&&n.setAttribute(o,t)}return n.insert(0,Cx(e).map(e=>xx(e,t))),t.mapping.set(n,e),n})(e,t),wx=e=>"object"==typeof e&&null!==e,kx=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);let o=n.length===(null==t?0:Object.keys(t).filter(e=>null!==t[e]).length);for(let r=0;r<n.length&&o;r++){const i=n[r],s=e[i],l=t[i];o="ychange"===i||s===l||wx(s)&&wx(l)&&kx(s,l)}return o},Cx=e=>{const t=e.content.content,n=[];for(let o=0;o<t.length;o++){const e=t[o];if(e.isText){const e=[];for(let n=t[o];o<t.length&&n.isText;n=t[++o])e.push(n);o--,n.push(e)}else n.push(e)}return n},Ex=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&sg(e.attributes||{}).length===t[n].marks.length&&ag(e.attributes,(e,o)=>{var r;const i=Nx(o),s=t[n].marks;return kx(e,null==(r=s.find(e=>e.type.name===i))?void 0:r.attrs)}))},Sx=(e,t)=>{if(e instanceof mv&&!(t instanceof Array)&&Px(e,t)){const n=Cx(t);return e._length===n.length&&kx(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>Sx(e,n[t]))}return e instanceof bv&&t instanceof Array&&Ex(e,t)},Mx=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Rx=(e,t,n)=>{const o=e.toArray(),r=Cx(t),i=r.length,s=o.length,l=Gf(s,i);let a=0,c=0,d=!1;for(;a<l;a++){const e=o[a],t=r[a];if(Mx(n.mapping.get(e),t))d=!0;else if(!Sx(e,t))break}for(;a+c<l;c++){const e=o[s-c-1],t=r[i-c-1];if(Mx(n.mapping.get(e),t))d=!0;else if(!Sx(e,t))break}return{equalityFactor:a+c,foundMappedChild:d}},Tx=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:o,str:r}=(e=>{let t="",n=e._start;const o={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof Nv?t+=n.content.str:n.content instanceof Mv&&(o[n.content.key]=null)),n=n.right;return{str:t,nAttrs:o}})(e),i=t.map(e=>({insert:e.text,attributes:Object.assign({},o,Ox(e.marks,n))})),{insert:s,remove:l,index:a}=Qv(r,i.map(e=>e.insert).join(""));e.delete(a,l),e.insert(a,s),e.applyDelta(i.map(e=>({retain:e.insert.length,attributes:e.attributes})))},jx=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Nx=e=>{var t;return(null==(t=jx.exec(e))?void 0:t[1])??e},Ax=(e,t)=>{const n=[];for(const o in e)n.push(t.mark(Nx(o),e[o]));return n},Ox=(e,t)=>{const n={};return e.forEach(e=>{if("ychange"!==e.type.name){const o=Bf(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[o?`${e.type.name}--${ux(e.toJSON())}`:e.type.name]=e.attrs}}),n},_x=(e,t,n,o)=>{if(t instanceof mv&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(o.mapping.set(t,n),t instanceof mv){const e=t.getAttributes(),o=n.attrs;for(const n in o)null!==o[n]?e[n]!==o[n]&&"ychange"!==n&&t.setAttribute(n,o[n]):t.removeAttribute(n);for(const n in e)void 0===o[n]&&t.removeAttribute(n)}const r=Cx(n),i=r.length,s=t.toArray(),l=s.length,a=Gf(i,l);let c=0,d=0;for(;c<a;c++){const e=s[c],t=r[c];if(!Mx(o.mapping.get(e),t)){if(!Sx(e,t))break;o.mapping.set(e,t)}}for(;d+c<a;d++){const e=s[l-d-1],t=r[i-d-1];if(!Mx(o.mapping.get(e),t)){if(!Sx(e,t))break;o.mapping.set(e,t)}}e.transact(()=>{for(;l-c-d>0&&i-c-d>0;){const n=s[c],a=r[c],u=s[l-d-1],h=r[i-d-1];if(n instanceof bv&&a instanceof Array)Ex(n,a)||Tx(n,a,o),c+=1;else{let r=n instanceof mv&&Px(n,a),i=u instanceof mv&&Px(u,h);if(r&&i){const e=Rx(n,a,o),t=Rx(u,h,o);e.foundMappedChild&&!t.foundMappedChild?i=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?r=!1:i=!1}r?(_x(e,n,a,o),c+=1):i?(_x(e,u,h,o),d+=1):(o.mapping.delete(t.get(c)),t.delete(c,1),t.insert(c,[xx(a,o)]),c+=1)}}const n=l-c-d;if(1===l&&0===i&&s[0]instanceof bv?(o.mapping.delete(s[0]),s[0].delete(0,s[0].length)):n>0&&(t.slice(c,c+n).forEach(e=>o.mapping.delete(e)),t.delete(c,n)),c+d<i){const e=[];for(let t=c;t<i-d;t++)e.push(xx(r[t],o));t.insert(c,e)}},ex)},Px=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name;let Ix=null;const Lx=()=>{const e=Ix;Ix=null,e.forEach((e,t)=>{const n=t.state.tr,o=ex.getState(t.state);o&&o.binding&&!o.binding.isDestroyed&&(e.forEach((e,t)=>{n.setMeta(t,e)}),t.dispatch(n))})},Dx=(e,t,n)=>{if(0===e)return Iy(t,0,0===t.length?-1:0);let o=null===t._first?null:t._first.content.type;for(;null!==o&&t!==o;){if(o instanceof bv){if(o._length>=e)return Iy(o,e,0===t.length?-1:0);if(e-=o._length,null!==o._item&&null!==o._item.next)o=o._item.next.content.type;else{do{o=null===o._item?null:o._item.parent,e--}while(o!==t&&null!==o&&null!==o._item&&null===o._item.next);null!==o&&o!==t&&(o=null===o._item?null:o._item.next.content.type)}}else{const r=(n.get(o)||{nodeSize:0}).nodeSize;if(null!==o._first&&e<r)o=o._first.content.type,e--;else{if(1===e&&0===o._length&&r>1)return new Ay(null===o._item?null:o._item.id,null===o._item?jy(o):null,null);if(e-=r,null!==o._item&&null!==o._item.next)o=o._item.next.content.type;else{if(0===e)return o=null===o._item?o:o._item.parent,new Ay(null===o._item?null:o._item.id,null===o._item?jy(o):null,null);do{o=o._item.parent,e--}while(o!==t&&null===o._item.next);o!==t&&(o=o._item.next.content.type)}}}if(null===o)throw Am();if(0===e&&o.constructor!==bv&&o!==t)return Bx(o._item.parent,o._item)}return Iy(t,t._length,0===t.length?-1:0)},Bx=(e,t)=>{let n=null,o=null;return null===e._item?o=jy(e):n=Ty(e._item.id.client,e._item.id.clock),new Ay(n,o,t.id)},Hx=(e,t,n,o)=>{const r=Ly(n,e);if(null===r||r.type!==t&&!Ny(t,r.type._item))return null;let i=r.type,s=0;if(i.constructor===bv)s=r.index;else if(null===i._item||!i._item.deleted){let e=i._first,t=0;for(;t<i._length&&t<r.index&&null!==e;){if(!e.deleted){const n=e.content.type;t++,s+=n instanceof bv?n._length:o.get(n).nodeSize}e=e.right}s+=1}for(;i!==t&&null!==i._item;){const e=i._item.parent;if(null===e._item||!e._item.deleted){s+=1;let t=e._first;for(;null!==t;){const e=t.content.type;if(e===i)break;t.deleted||(s+=e instanceof bv?e._length:o.get(e).nodeSize),t=t.right}}i=e}return s-1},Vx=(e,t,n)=>e!==t,$x=e=>{const t=document.createElement("span");t.classList.add("ProseMirror-yjs-cursor"),t.setAttribute("style",`border-color: ${e.color}`);const n=document.createElement("div");n.setAttribute("style",`background-color: ${e.color}`),n.insertBefore(document.createTextNode(e.name),null);const o=document.createTextNode("⁠"),r=document.createTextNode("⁠");return t.insertBefore(o,null),t.insertBefore(n,null),t.insertBefore(r,null),t},zx=e=>({style:`background-color: ${e.color}70`,class:"ProseMirror-yjs-selection"}),Fx=/^#[0-9a-fA-F]{6}$/,Ux=(e,t,n,o,r)=>{const i=ex.getState(e),s=i.doc,l=[];return null!=i.snapshot||null!=i.prevSnapshot||0===i.binding.mapping.size?Il.create(e.doc,[]):(t.getStates().forEach((t,a)=>{if(n(s.clientID,a,t)&&null!=t.cursor){const n=t.user||{};null==n.color?n.color="#ffa500":Fx.test(n.color),null==n.name&&(n.name=`User: ${a}`);let c=Hx(s,i.type,Oy(t.cursor.anchor),i.binding.mapping),d=Hx(s,i.type,Oy(t.cursor.head),i.binding.mapping);if(null!==c&&null!==d){const t=Kf(e.doc.content.size-1,0);c=Gf(c,t),d=Gf(d,t),l.push(Ol.widget(d,()=>o(n,a),{key:a+"",side:10}));const i=Gf(c,d),s=Kf(c,d);l.push(Ol.inline(i,s,r(n,a),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),Il.create(e.doc,l))},Wx=(e,{awarenessStateFilter:t=Vx,cursorBuilder:n=$x,selectionBuilder:o=zx,getSelection:r=e=>e.selection}={},i="cursor")=>new Wr({key:nx,state:{init:(r,i)=>Ux(i,e,t,n,o),apply(r,i,s,l){const a=ex.getState(l),c=r.getMeta(nx);return a&&a.isChangeOrigin||c&&c.awarenessUpdated?Ux(l,e,t,n,o):i.map(r.mapping,r.doc)}},props:{decorations:e=>nx.getState(e)},view:t=>{const n=()=>{t.docView&&((e,t,n)=>{Ix||(Ix=new Map,jg(0,Lx)),Bf(Ix,e,Lf).set(t,n)})(t,nx,{awarenessUpdated:!0})},o=()=>{const n=ex.getState(t.state),o=e.getLocalState()||{};if(t.hasFocus()){const s=r(t.state),l=Dx(s.anchor,n.type,n.binding.mapping),a=Dx(s.head,n.type,n.binding.mapping);null!=o.cursor&&Dy(Oy(o.cursor.anchor),l)&&Dy(Oy(o.cursor.head),a)||e.setLocalStateField(i,{anchor:l,head:a})}else null!=o.cursor&&null!==Hx(n.doc,n.type,Oy(o.cursor.anchor),n.binding.mapping)&&e.setLocalStateField(i,null)};return e.on("change",n),t.dom.addEventListener("focusin",o),t.dom.addEventListener("focusout",o),{update:o,destroy:()=>{t.dom.removeEventListener("focusin",o),t.dom.removeEventListener("focusout",o),e.off("change",n),e.setLocalStateField(i,null)}}}}),qx=(e,t)=>{var n,o;return null==t?null==(o=null==(n=tx.getState(e))?void 0:n.undoManager)?void 0:o.canUndo():(e=>{var t,n;return null!=(null==(n=null==(t=tx.getState(e))?void 0:t.undoManager)?void 0:n.undo())})(e)},Gx=(e,t)=>{var n,o;return null==t?null==(o=null==(n=tx.getState(e))?void 0:n.undoManager)?void 0:o.canRedo():(e=>{var t,n;return null!=(null==(n=null==(t=tx.getState(e))?void 0:t.undoManager)?void 0:n.redo())})(e)},Kx=new Set(["paragraph"]),Zx=({protectedNodes:e=Kx,trackedOrigins:t=[],undoManager:n=null}={})=>new Wr({key:tx,state:{init:(o,r)=>{const i=ex.getState(r),s=n||new ab(i.type,{trackedOrigins:new Set([ex].concat(t)),deleteFilter:t=>((e,t)=>!(e instanceof Wv&&e.content instanceof Hv&&(e.content.type instanceof hv||e.content.type instanceof mv&&t.has(e.content.type.nodeName))&&0!==e.content.type._length))(t,e),captureTransaction:e=>!1!==e.meta.get("addToHistory")});return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0}},apply:(e,t,n,o)=>{const r=ex.getState(o).binding,i=t.undoManager,s=i.undoStack.length>0,l=i.redoStack.length>0;return r?{undoManager:i,prevSel:mx(r,n),hasUndoOps:s,hasRedoOps:l}:s!==t.hasUndoOps||l!==t.hasRedoOps?Object.assign({},t,{hasUndoOps:i.undoStack.length>0,hasRedoOps:i.redoStack.length>0}):t}},view:e=>{const t=ex.getState(e.state),n=tx.getState(e.state).undoManager;return n.on("stack-item-added",({stackItem:n})=>{const o=t.binding;o&&n.meta.set(o,tx.getState(e.state).prevSel)}),n.on("stack-item-popped",({stackItem:e})=>{const n=t.binding;n&&(n.beforeTransactionSelection=e.meta.get(n)||n.beforeTransactionSelection)}),{destroy:()=>{n.destroy()}}}});function Jx(e={}){return new Wr({view:t=>new Xx(t,e)})}class Xx{constructor(e,t){var n;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=null!==(n=t.width)&&void 0!==n?n:1,this.color=!1===t.color?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.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){null!=this.cursorPos&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,null==e?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e,t=this.editorView.state.doc.resolve(this.cursorPos),n=!t.parent.inlineContent,o=this.editorView.dom,r=o.getBoundingClientRect(),i=r.width/o.offsetWidth,s=r.height/o.offsetHeight;if(n){let n=t.nodeBefore,o=t.nodeAfter;if(n||o){let t=this.editorView.nodeDOM(this.cursorPos-(n?n.nodeSize:0));if(t){let r=t.getBoundingClientRect(),i=n?r.bottom:r.top;n&&o&&(i=(i+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let l=this.width/2*s;e={left:r.left,right:r.right,top:i-l,bottom:i+l}}}}if(!e){let t=this.editorView.coordsAtPos(this.cursorPos),n=this.width/2*i;e={left:t.left-n,right:t.left+n,top:t.top,bottom:t.bottom}}let l,a,c=this.editorView.dom.offsetParent;if(this.element||(this.element=c.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",n),this.element.classList.toggle("prosemirror-dropcursor-inline",!n),!c||c==document.body&&"static"==getComputedStyle(c).position)l=-pageXOffset,a=-pageYOffset;else{let e=c.getBoundingClientRect(),t=e.width/c.offsetWidth,n=e.height/c.offsetHeight;l=e.left-c.scrollLeft*t,a=e.top-c.scrollTop*n}this.element.style.left=(e.left-l)/i+"px",this.element.style.top=(e.top-a)/s+"px",this.element.style.width=(e.right-e.left)/i+"px",this.element.style.height=(e.bottom-e.top)/s+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),o=n&&n.type.spec.disableDropCursor,r="function"==typeof o?o(this.editorView,t,e):o;if(t&&!r){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=cr(this.editorView.state.doc,e,this.editorView.dragging.slice);null!=t&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}const Yx={slash_menu:{heading:{title:"Heading 1",subtext:"Top-level heading",aliases:["h","heading1","h1"],group:"Headings"},heading_2:{title:"Heading 2",subtext:"Key section heading",aliases:["h2","heading2","subheading"],group:"Headings"},heading_3:{title:"Heading 3",subtext:"Subsection and group heading",aliases:["h3","heading3","subheading"],group:"Headings"},heading_4:{title:"Heading 4",subtext:"Minor subsection heading",aliases:["h4","heading4","subheading4"],group:"Subheadings"},heading_5:{title:"Heading 5",subtext:"Small subsection heading",aliases:["h5","heading5","subheading5"],group:"Subheadings"},heading_6:{title:"Heading 6",subtext:"Lowest-level heading",aliases:["h6","heading6","subheading6"],group:"Subheadings"},toggle_heading:{title:"Toggle Heading 1",subtext:"Toggleable top-level heading",aliases:["h","heading1","h1","collapsable"],group:"Subheadings"},toggle_heading_2:{title:"Toggle Heading 2",subtext:"Toggleable key section heading",aliases:["h2","heading2","subheading","collapsable"],group:"Subheadings"},toggle_heading_3:{title:"Toggle Heading 3",subtext:"Toggleable subsection and group heading",aliases:["h3","heading3","subheading","collapsable"],group:"Subheadings"},quote:{title:"Quote",subtext:"Quote or excerpt",aliases:["quotation","blockquote","bq"],group:"Basic blocks"},toggle_list:{title:"Toggle List",subtext:"List with hideable sub-items",aliases:["li","list","toggleList","toggle list","collapsable list"],group:"Basic blocks"},numbered_list:{title:"Numbered List",subtext:"List with ordered items",aliases:["ol","li","list","numberedlist","numbered list"],group:"Basic blocks"},bullet_list:{title:"Bullet List",subtext:"List with unordered items",aliases:["ul","li","list","bulletlist","bullet list"],group:"Basic blocks"},check_list:{title:"Check List",subtext:"List with checkboxes",aliases:["ul","li","list","checklist","check list","checked list","checkbox"],group:"Basic blocks"},paragraph:{title:"Paragraph",subtext:"The body of your document",aliases:["p","paragraph"],group:"Basic blocks"},code_block:{title:"Code Block",subtext:"Code block with syntax highlighting",aliases:["code","pre"],group:"Basic blocks"},page_break:{title:"Page Break",subtext:"Page separator",aliases:["page","break","separator"],group:"Basic blocks"},table:{title:"Table",subtext:"Table with editable cells",aliases:["table"],group:"Advanced"},image:{title:"Image",subtext:"Resizable image with caption",aliases:["image","imageUpload","upload","img","picture","media","url"],group:"Media"},video:{title:"Video",subtext:"Resizable video with caption",aliases:["video","videoUpload","upload","mp4","film","media","url"],group:"Media"},audio:{title:"Audio",subtext:"Embedded audio with caption",aliases:["audio","audioUpload","upload","mp3","sound","media","url"],group:"Media"},file:{title:"File",subtext:"Embedded file",aliases:["file","upload","embed","media","url"],group:"Media"},emoji:{title:"Emoji",subtext:"Search for and insert an emoji",aliases:["emoji","emote","emotion","face"],group:"Others"}},placeholders:{default:"Enter text or type '/' for commands",heading:"Heading",toggleListItem:"Toggle",bulletListItem:"List",numberedListItem:"List",checkListItem:"List",emptyDocument:void 0,new_comment:"Write a comment...",edit_comment:"Edit comment...",comment_reply:"Add comment..."},file_blocks:{image:{add_button_text:"Add image"},video:{add_button_text:"Add video"},audio:{add_button_text:"Add audio"},file:{add_button_text:"Add file"}},toggle_blocks:{add_block_button:"Empty toggle. Click to add a block."},side_menu:{add_block_label:"Add block",drag_handle_label:"Open block menu"},drag_handle:{delete_menuitem:"Delete",colors_menuitem:"Colors",header_row_menuitem:"Header row",header_column_menuitem:"Header column"},table_handle:{delete_column_menuitem:"Delete column",delete_row_menuitem:"Delete row",add_left_menuitem:"Add column left",add_right_menuitem:"Add column right",add_above_menuitem:"Add row above",add_below_menuitem:"Add row below",split_cell_menuitem:"Split cell",merge_cells_menuitem:"Merge cells",background_color_menuitem:"Background color"},suggestion_menu:{no_items_title:"No items found"},color_picker:{text_title:"Text",background_title:"Background",colors:{default:"Default",gray:"Gray",brown:"Brown",red:"Red",orange:"Orange",yellow:"Yellow",green:"Green",blue:"Blue",purple:"Purple",pink:"Pink"}},formatting_toolbar:{bold:{tooltip:"Bold",secondary_tooltip:"Mod+B"},italic:{tooltip:"Italic",secondary_tooltip:"Mod+I"},underline:{tooltip:"Underline",secondary_tooltip:"Mod+U"},strike:{tooltip:"Strike",secondary_tooltip:"Mod+Shift+S"},code:{tooltip:"Code",secondary_tooltip:""},colors:{tooltip:"Colors"},link:{tooltip:"Create link",secondary_tooltip:"Mod+K"},file_caption:{tooltip:"Edit caption",input_placeholder:"Edit caption"},file_replace:{tooltip:{image:"Replace image",video:"Replace video",audio:"Replace audio",file:"Replace file"}},file_rename:{tooltip:{image:"Rename image",video:"Rename video",audio:"Rename audio",file:"Rename file"},input_placeholder:{image:"Rename image",video:"Rename video",audio:"Rename audio",file:"Rename file"}},file_download:{tooltip:{image:"Download image",video:"Download video",audio:"Download audio",file:"Download file"}},file_delete:{tooltip:{image:"Delete image",video:"Delete video",audio:"Delete audio",file:"Delete file"}},file_preview_toggle:{tooltip:"Toggle preview"},nest:{tooltip:"Nest block",secondary_tooltip:"Tab"},unnest:{tooltip:"Unnest block",secondary_tooltip:"Shift+Tab"},align_left:{tooltip:"Align text left"},align_center:{tooltip:"Align text center"},align_right:{tooltip:"Align text right"},align_justify:{tooltip:"Justify text"},table_cell_merge:{tooltip:"Merge cells"},comment:{tooltip:"Add comment"}},file_panel:{upload:{title:"Upload",file_placeholder:{image:"Upload image",video:"Upload video",audio:"Upload audio",file:"Upload file"},upload_error:"Error: Upload failed"},embed:{title:"Embed",embed_button:{image:"Embed image",video:"Embed video",audio:"Embed audio",file:"Embed file"},url_placeholder:"Enter URL"}},link_toolbar:{delete:{tooltip:"Remove link"},edit:{text:"Edit link",tooltip:"Edit"},open:{tooltip:"Open in new tab"},form:{title_placeholder:"Edit title",url_placeholder:"Edit URL"}},comments:{edited:"edited",save_button_text:"Save",cancel_button_text:"Cancel",actions:{add_reaction:"Add reaction",resolve:"Resolve",edit_comment:"Edit comment",delete_comment:"Delete comment",more_actions:"More actions"},reactions:{reacted_by:"Reacted by"},sidebar:{marked_as_resolved:"Marked as resolved",more_replies:e=>`${e} more replies`}},generic:{ctrl_shortcut:"Ctrl"}};var Qx=Object.defineProperty,ew=(e,t,n)=>((e,t,n)=>t in e?Qx(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);function tw(e){return function(e,t=JSON.stringify){const n={};return e.filter(e=>{const o=t(e);return!Object.prototype.hasOwnProperty.call(n,o)&&(n[o]=!0)})}(e.filter((t,n)=>e.indexOf(t)!==n))}const nw=kc.create({name:"uniqueID",priority:1e4,addOptions:()=>({attributeName:"id",types:[],setIdAttribute:!1,generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const e=window.__TEST_OPTIONS;return void 0===e.mockID?e.mockID=0:e.mockID++,e.mockID.toString()}return Pd()},filterTransaction:null}),addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:e=>e.getAttribute(`data-${this.options.attributeName}`),renderHTML:e=>{const t={[`data-${this.options.attributeName}`]:e[this.options.attributeName]};return this.options.setIdAttribute?{...t,id:e[this.options.attributeName]}:t}}}}]},addProseMirrorPlugins(){let e=null,t=!1;return[new Wr({key:new Kr("uniqueID"),appendTransaction:(e,t,n)=>{const o=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),r=this.options.filterTransaction&&e.some(e=>{let t,n;return!(null!==(n=(t=this.options).filterTransaction)&&void 0!==n&&n.call(t,e))});if(!o||r)return;const{tr:i}=n,{types:s,attributeName:l,generateID:a}=this.options,c=qc(t.doc,e),{mapping:d}=c;return Yc(c).forEach(({newRange:e})=>{const o=Kc(n.doc,e,e=>s.includes(e.type.name)),r=tw(o.map(({node:e})=>e.attrs[l]).filter(e=>null!==e));o.forEach(({node:e,pos:o})=>{let s;const c=null===(s=i.doc.nodeAt(o))||void 0===s?void 0:s.attrs[l];if(null===c){const r=t.doc.type.createAndFill().content;if(null===t.doc.content.findDiffStart(r)){const t=JSON.parse(JSON.stringify(n.doc.toJSON()));if(t.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(t.content)===JSON.stringify(r.toJSON()))return void i.setNodeMarkup(o,void 0,{...e.attrs,[l]:"initialBlockId"})}return void i.setNodeMarkup(o,void 0,{...e.attrs,[l]:a()})}const{deleted:u}=d.invert().mapResult(o);u&&r.includes(c)&&i.setNodeMarkup(o,void 0,{...e.attrs,[l]:a()})})}),i.steps.length?i:void 0},view(t){const n=n=>{let o;e=null!==(o=t.dom.parentElement)&&void 0!==o&&o.contains(n.target)?t.dom.parentElement:null};return window.addEventListener("dragstart",n),{destroy(){window.removeEventListener("dragstart",n)}}},props:{handleDOMEvents:{drop:(n,o)=>{let r;return t=e!==n.dom.parentElement||"copy"===(null===(r=o.dataTransfer)||void 0===r?void 0:r.effectAllowed),e=null,!1},paste:()=>(t=!0,!1)},transformPasted:e=>{if(!t)return e;const{types:n,attributeName:o}=this.options,r=e=>{const t=[];return e.forEach(e=>{if(e.isText)return void t.push(e);if(!n.includes(e.type.name))return void t.push(e.copy(r(e.content)));const i=e.type.create({...e.attrs,[o]:null},r(e.content),e.marks);t.push(i)}),Rn.from(t)};return t=!1,new _n(r(e.content),e.openStart,e.openEnd)}}})]}});function ow(e){return"link"===e.type}function rw(e){return"string"!=typeof e&&"link"===e.type}function iw(e){return"string"!=typeof e&&"text"===e.type}function sw(e){var t,n,o,r,i;return aw(e)?{...e}:lw(e)?{type:"tableCell",content:[].concat(e.content),props:{backgroundColor:(null==(t=e.props)?void 0:t.backgroundColor)??"default",textColor:(null==(n=e.props)?void 0:n.textColor)??"default",textAlignment:(null==(o=e.props)?void 0:o.textAlignment)??"left",colspan:(null==(r=e.props)?void 0:r.colspan)??1,rowspan:(null==(i=e.props)?void 0:i.rowspan)??1}}:{type:"tableCell",content:[].concat(e),props:{backgroundColor:"default",textColor:"default",textAlignment:"left",colspan:1,rowspan:1}}}function lw(e){return null!=e&&"string"!=typeof e&&!Array.isArray(e)&&"tableCell"===e.type}function aw(e){return lw(e)&&void 0!==e.props&&void 0!==e.content}function cw(e){return aw(e)?e.props.colspan??1:1}function dw(e){return aw(e)?e.props.rowspan??1:1}class uw extends Error{constructor(e){super(`Unreachable case: ${e}`)}}function hw(e,t=!0){const{"data-test":n,...o}=e;if(Object.keys(o).length>0&&t)throw new Error("Object must be empty "+JSON.stringify(e))}function pw(e,t="Ctrl"){return typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent))?e.replace("Mod","⌘"):e.replace("Mod",t)}function fw(...e){return[...new Set(e.filter(e=>e).join(" ").split(" "))].join(" ")}const mw=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function gw(e,t,n,o){const r=document.createElement("div");r.className=fw("bn-block-content",n.class),r.setAttribute("data-content-type",e);for(const[s,l]of Object.entries(n))"class"!==s&&r.setAttribute(s,l);const i=document.createElement(t);i.className=fw("bn-inline-content",o.class);for(const[s,l]of Object.entries(o))"class"!==s&&i.setAttribute(s,l);return r.appendChild(i),{dom:r,contentDOM:i}}const yw=(e,t)=>{let n=pk(e,t.pmSchema);"blockContainer"===n.type.name&&(n=n.firstChild);const o=t.pmSchema.nodes[n.type.name].spec.toDOM;if(void 0===o)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const r=o(n);if("object"!=typeof r||!("dom"in r))throw new Error("Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.");return r};const bw={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},vw=["backgroundColor","textColor"];function xw(e){return"data-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ww(e){const t=e.split("/");return t.length&&""!==t[t.length-1]?t[t.length-1]:e}function kw(e){const t={};return Object.entries(e).filter(([e,t])=>!vw.includes(e)).forEach(([e,n])=>{t[e]={default:n.default,keepOnSplit:!0,parseHTML:t=>{const o=t.getAttribute(xw(e));if(null===o)return null;if(void 0===n.default&&"boolean"===n.type||void 0!==n.default&&"boolean"==typeof n.default)return"true"===o||"false"!==o&&null;if(void 0===n.default&&"number"===n.type||void 0!==n.default&&"number"==typeof n.default){const e=parseFloat(o);return!Number.isNaN(e)&&Number.isFinite(e)?e:null}return o},renderHTML:t=>t[e]!==n.default?{[xw(e)]:t[e]}:{}}}),t}function Cw(e,t,n,o){if("boolean"==typeof e)throw new Error("Cannot find node position as getPos is a boolean, not a function.");const r=e(),i=n.state.doc.resolve(r).node().attrs.id;if(!i)throw new Error("Block doesn't have id");const s=t.getBlock(i);if(s.type!==o)throw new Error("Block type does not match");return s}function Ew(e,t,n,o,r=!1,i){const s=document.createElement("div");if(void 0!==i)for(const[l,a]of Object.entries(i))"class"!==l&&s.setAttribute(l,a);s.className=fw("bn-block-content",(null==i?void 0:i.class)||""),s.setAttribute("data-content-type",t);for(const[l,a]of Object.entries(n)){const e=o[l].default;!vw.includes(l)&&a!==e&&s.setAttribute(xw(l),a)}return r&&s.setAttribute("data-file-block",""),s.appendChild(e.dom),void 0!==e.contentDOM&&(e.contentDOM.className=fw("bn-inline-content",e.contentDOM.className)),{...e,dom:s}}function Sw(e){return kd.create(e)}function Mw(e,t){return{config:e,implementation:t}}function Rw(e,t,n){return Mw({type:e.name,content:"inline*"===e.config.content?"inline":"tableRow+"===e.config.content?"table":"none",propSchema:t},{node:e,requiredExtensions:n,toInternalHTML:yw,toExternalHTML:yw})}function Tw(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.config]))}function jw(e,t){e.stopEvent=e=>("mousedown"===e.type&&setTimeout(()=>{t.view.dom.blur()},10),!0)}function Nw(e,t){const n=[{tag:"[data-content-type="+e.type+"]",contentElement:".bn-inline-content"}];return t&&n.push({tag:"*",getAttrs(e){if("string"==typeof e)return!1;const n=null==t?void 0:t(e);return void 0!==n&&n}}),n}function Aw(e,t){const n=Sw({name:e.type,content:"inline"===e.content?"inline*":"",group:"blockContent",selectable:e.isSelectable??!0,isolating:!0,addAttributes:()=>kw(e.propSchema),parseHTML:()=>Nw(e,t.parse),renderHTML({HTMLAttributes:t}){const n=document.createElement("div");return Ew({dom:n,contentDOM:"inline"===e.content?n:void 0},e.type,{},e.propSchema,e.isFileBlock,t)},addNodeView(){return({getPos:n})=>{var o;const r=this.options.editor,i=Cw(n,r,this.editor,e.type),s=(null==(o=this.options.domAttributes)?void 0:o.blockContent)||{},l=Ew(t.render(i,r),i.type,i.props,e.propSchema,e.isFileBlock,s);return!1===e.isSelectable&&jw(l,this.editor),l}}});if(n.name!==e.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return Mw(e,{node:n,toInternalHTML:(o,r)=>{var i;const s=(null==(i=n.options.domAttributes)?void 0:i.blockContent)||{};return Ew(t.render(o,r),o.type,o.props,e.propSchema,e.isFileBlock,s)},toExternalHTML:(o,r)=>{var i,s;const l=(null==(i=n.options.domAttributes)?void 0:i.blockContent)||{};let a=null==(s=t.toExternalHTML)?void 0:s.call(t,o,r);return void 0===a&&(a=t.render(o,r)),Ew(a,o.type,o.props,e.propSchema,l)}})}function Ow(e,t){const n=e.resolve(t);if(n.nodeAfter&&n.nodeAfter.type.isInGroup("bnBlock"))return{posBeforeNode:n.pos,node:n.nodeAfter};let o=n.depth,r=n.node(o);for(;o>0;){if(r.type.isInGroup("bnBlock"))return{posBeforeNode:n.before(o),node:r};o--,r=n.node(o)}const i=[];e.descendants((e,t)=>{e.type.isInGroup("bnBlock")&&i.push(t)});const s=e.resolve(i.find(e=>e>=t)||i[i.length-1]);return{posBeforeNode:s.pos,node:s.nodeAfter}}function _w(e,t){if(!e.type.isInGroup("bnBlock"))throw new Error(`Attempted to get bnBlock node at position but found node of different type ${e.type.name}`);const n=e,o=t,r=o+n.nodeSize,i={node:n,beforePos:o,afterPos:r};if("blockContainer"===n.type.name){let e,t;if(n.forEach((n,r)=>{if("blockContent"===n.type.spec.group){const t=n,i=o+r+1,s=i+n.nodeSize;e={node:t,beforePos:i,afterPos:s}}else if("blockGroup"===n.type.name){const e=n,i=o+r+1,s=i+n.nodeSize;t={node:e,beforePos:i,afterPos:s}}}),!e)throw new Error(`blockContainer node does not contain a blockContent node in its children: ${n}`);return{isBlockContainer:!0,bnBlock:i,blockContent:e,childContainer:t,blockNoteType:e.node.type.name}}if(!i.node.type.isInGroup("childContainer"))throw new Error(`bnBlock node is not in the childContainer group: ${i.node}`);return{isBlockContainer:!1,bnBlock:i,childContainer:i,blockNoteType:i.node.type.name}}function Pw(e){return _w(e.node,e.posBeforeNode)}function Iw(e){if(!e.nodeAfter)throw new Error(`Attempted to get blockContainer node at position ${e.pos} but a node at this position does not exist`);return _w(e.nodeAfter,e.pos)}function Lw(e){return Pw(Ow(e.doc,e.selection.anchor))}function Dw(e){return Pw(Ow(e.doc,e.selection.anchor))}function Bw(e){return"doc"in e?e.doc.type.schema:e.type.schema}function Hw(e){return e.cached.blockNoteEditor}function Vw(e){return Hw(e).schema}function $w(e){return Vw(e).blockSchema}function zw(e){return Vw(e).inlineContentSchema}function Fw(e){return Vw(e).styleSchema}function Uw(e){return Hw(e).blockCache}function Ww(e,t,n){var o,r;const i={type:"tableContent",columnWidths:[],headerRows:void 0,headerCols:void 0,rows:[]},s=[];e.content.forEach((e,o,r)=>{const l={cells:[]};0===r&&e.content.forEach(e=>{let t=e.attrs.colwidth;null==t&&(t=new Array(e.attrs.colspan??1).fill(void 0)),i.columnWidths.push(...t)}),l.cells=e.content.content.map((e,o)=>(s[r]||(s[r]=[]),s[r][o]="tableHeader"===e.type.name,{type:"tableCell",content:e.content.content.map(e=>qw(e,t,n)).reduce((e,t)=>{if(!e.length)return t;const n=e[e.length-1],o=t[0];return o&&iw(n)&&iw(o)&&JSON.stringify(n.styles)===JSON.stringify(o.styles)?(n.text+="\n"+o.text,e.push(...t.slice(1)),e):(e.push(...t),e)},[]),props:{colspan:e.attrs.colspan,rowspan:e.attrs.rowspan,backgroundColor:e.attrs.backgroundColor,textColor:e.attrs.textColor,textAlignment:e.attrs.textAlignment}})),i.rows.push(l)});for(let l=0;l<s.length;l++)null!=(o=s[l])&&o.every(e=>e)&&(i.headerRows=(i.headerRows??0)+1);for(let l=0;l<(null==(r=s[0])?void 0:r.length);l++)null!=s&&s.every(e=>e[l])&&(i.headerCols=(i.headerCols??0)+1);return i}function qw(e,t,n){const o=[];let r;return e.content.forEach(e=>{if("hardBreak"===e.type.name){if(r)if(iw(r))r.text+="\n";else{if(!ow(r))throw new Error("unexpected");r.content[r.content.length-1].text+="\n"}else r={type:"text",text:"\n",styles:{}};return}if("link"!==e.type.name&&"text"!==e.type.name){if(!t[e.type.name])return;return r&&(o.push(r),r=void 0),void o.push(function(e,t,n){if("text"===e.type.name||"link"===e.type.name)throw new Error("unexpected");const o={},r=t[e.type.name];for(const[s,l]of Object.entries(e.attrs)){if(!r)throw Error("ic node is of an unrecognized type: "+e.type.name);s in r.propSchema&&(o[s]=l)}let i;return i="styled"===r.content?qw(e,t,n):void 0,{type:e.type.name,props:o,content:i}}(e,t,n))}const i={};let s;for(const t of e.marks)if("link"===t.type.name)s=t;else{const e=n[t.type.name];if(!e){if(t.type.spec.blocknoteIgnore)continue;throw new Error(`style ${t.type.name} not found in styleSchema`)}if("boolean"===e.propSchema)i[e.type]=!0;else{if("string"!==e.propSchema)throw new uw(e.propSchema);i[e.type]=t.attrs.stringValue}}r?iw(r)?s?(o.push(r),r={type:"link",href:s.attrs.href,content:[{type:"text",text:e.textContent,styles:i}]}):JSON.stringify(r.styles)===JSON.stringify(i)?r.text+=e.textContent:(o.push(r),r={type:"text",text:e.textContent,styles:i}):ow(r)&&(s?r.href===s.attrs.href?JSON.stringify(r.content[r.content.length-1].styles)===JSON.stringify(i)?r.content[r.content.length-1].text+=e.textContent:r.content.push({type:"text",text:e.textContent,styles:i}):(o.push(r),r={type:"link",href:s.attrs.href,content:[{type:"text",text:e.textContent,styles:i}]}):(o.push(r),r={type:"text",text:e.textContent,styles:i})):r=s?{type:"link",href:s.attrs.href,content:[{type:"text",text:e.textContent,styles:i}]}:{type:"text",text:e.textContent,styles:i}}),r&&o.push(r),o}function Gw(e,t,n=$w(t),o=zw(t),r=Fw(t),i=Uw(t)){var s;if(!e.type.isInGroup("bnBlock"))throw Error("Node should be a bnBlock, but is instead: "+e.type.name);const l=null==i?void 0:i.get(e);if(l)return l;const a=_w(e,0);let c=a.bnBlock.node.attrs.id;null===c&&(c=nw.options.generateID());const d=n[a.blockNoteType];if(!d)throw Error("Block is of an unrecognized type: "+a.blockNoteType);const u={};for(const[g,y]of Object.entries({...e.attrs,...a.isBlockContainer?a.blockContent.node.attrs:{}})){const e=d.propSchema;g in e&&(void 0!==e[g].default||void 0!==y)&&(u[g]=y)}const h=n[a.blockNoteType],p=[];let f;if(null==(s=a.childContainer)||s.node.forEach(e=>{p.push(Gw(e,t,n,o,r,i))}),"inline"===h.content){if(!a.isBlockContainer)throw new Error("impossible");f=qw(a.blockContent.node,o,r)}else if("table"===h.content){if(!a.isBlockContainer)throw new Error("impossible");f=Ww(a.blockContent.node,o,r)}else{if("none"!==h.content)throw new uw(h.content);f=void 0}const m={id:c,type:h.type,props:u,content:f,children:p};return null==i||i.set(e,m),m}function Kw(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.config]))}function Zw(e,t){return function(e,t){return{config:e,implementation:t}}({type:e.name,propSchema:t},{mark:e})}function Jw(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.config]))}function Xw(e){const{height:t,width:n}=ek(e),o=new Array(t).fill(!1).map(()=>new Array(n).fill(null)),r=(e,r)=>{for(let i=e;i<t;i++)for(let e=r;e<n;e++)if(!o[i][e])return{row:i,col:e};throw new Error("Unable to create occupancy grid for table, no more available cells")};for(let i=0;i<e.content.rows.length;i++)for(let t=0;t<e.content.rows[i].cells.length;t++){const n=sw(e.content.rows[i].cells[t]),s=dw(n),l=cw(n),{row:a,col:c}=r(i,t);for(let e=a;e<a+s;e++)for(let r=c;r<c+l;r++){if(o[e][r])throw new Error(`Unable to create occupancy grid for table, cell at ${e},${r} is already occupied`);o[e][r]={row:i,col:t,rowspan:s,colspan:l,cell:n}}}return o}function Yw(e){const t=new Set;return e.map(e=>({cells:e.map(e=>!t.has(e.row+":"+e.col)&&(t.add(e.row+":"+e.col),e.cell)).filter(e=>!1!==e)}))}function Qw(e,t,n=Xw(t)){for(let o=0;o<n.length;o++)for(let t=0;t<n[o].length;t++){const r=n[o][t];if(r.row===e.row&&r.col===e.col)return{row:o,col:t,cell:r.cell}}throw new Error(`Unable to resolve relative table cell indices for table, cell at ${e.row},${e.col} is not occupied`)}function ek(e){const t=e.content.rows.length;let n=0;return e.content.rows.forEach(e=>{let t=0;e.cells.forEach(e=>{t+=cw(e)}),n=Math.max(n,t)}),{height:t,width:n}}function tk(e,t,n=Xw(t)){var o;const r=null==(o=n[e.row])?void 0:o[e.col];if(r)return{row:r.row,col:r.col,cell:r.cell}}function nk(e,t){var n;const o=Xw(e);if(t<0||t>=o.length)return[];let r=0;for(let s=0;s<t;s++){const e=null==(n=o[r])?void 0:n[0];if(!e)return[];r+=e.rowspan}const i=new Array(o[0].length).fill(!1).map((t,n)=>tk({row:r,col:n},e,o)).filter(e=>void 0!==e);return i.filter((e,t)=>i.findIndex(t=>t.row===e.row&&t.col===e.col)===t)}function ok(e,t){var n;const o=Xw(e);if(t<0||t>=o[0].length)return[];let r=0;for(let s=0;s<t;s++){const e=null==(n=o[0])?void 0:n[r];if(!e)return[];r+=e.colspan}const i=new Array(o.length).fill(!1).map((t,n)=>tk({row:n,col:r},e,o)).filter(e=>void 0!==e);return i.filter((e,t)=>i.findIndex(t=>t.row===e.row&&t.col===e.col)===t)}function rk(e){return!e||(lw(e)?rk(e.content):"string"==typeof e?0===e.length:!!Array.isArray(e)&&e.every(e=>"string"==typeof e?0===e.length:iw(e)?0===e.text.length:!!rw(e)&&("string"==typeof e.content?0===e.content.length:e.content.every(e=>0===e.text.length))))}function ik(e,t,n){const o=nk(e,n);if(!o.some(e=>dw(e.cell)>1))return!0;let r=n,i=n;return o.forEach(e=>{const t=dw(e.cell);r=Math.max(r,e.row+t-1),i=Math.min(i,e.row)}),t<n?n===r:n===i}function sk(e,t,n){const o=ok(e,n);if(!o.some(e=>cw(e.cell)>1))return!0;let r=n,i=n;return o.forEach(e=>{const t=cw(e.cell);r=Math.max(r,e.col+t-1),i=Math.min(i,e.col)}),t<n?n===r:n===i}function lk(e,t,n,o){const r=[];for(const[i,s]of Object.entries(e.styles||{})){const e=n[i];if(!e)throw new Error(`style ${i} not found in styleSchema`);if("boolean"===e.propSchema)s&&r.push(t.mark(i));else{if("string"!==e.propSchema)throw new uw(e.propSchema);s&&r.push(t.mark(i,{stringValue:s}))}}return o&&t.nodes[o].spec.code?e.text.length>0?[t.text(e.text,r)]:[]:e.text.split(/(\n)/g).filter(e=>e.length>0).map(e=>"\n"===e?t.nodes.hardBreak.createChecked():t.text(e,r))}function ak(e,t,n){const o=t.marks.link.create({href:e.href});return ck(e.content,t,n).map(e=>{if("text"===e.type.name)return e.mark([...e.marks,o]);if("hardBreak"===e.type.name)return e;throw new Error("unexpected node type")})}function ck(e,t,n,o){const r=[];if("string"==typeof e)return r.push(...lk({text:e,styles:{}},t,n,o)),r;for(const i of e)r.push(...lk(i,t,n,o));return r}function dk(e,t,n,o=Fw(t)){const r=[];for(const i of e)"string"==typeof i?r.push(...ck(i,t,o,n)):rw(i)?r.push(...ak(i,t,o)):iw(i)?r.push(...ck([i],t,o,n)):r.push(hk(i,t,o));return r}function uk(e,t,n=Fw(t)){const o=[],r=new Array(e.headerRows??0).fill(!0),i=new Array(e.headerCols??0).fill(!0),s=e.columnWidths??[];for(let l=0;l<e.rows.length;l++){const a=e.rows[l],c=[],d=r[l];for(let o=0;o<a.cells.length;o++){const r=a.cells[o],u=i[o],h=void 0;let p=null;const f=Qw({row:l,col:o},{content:e});let m=s[f.col]?[s[f.col]]:null;if(r)if("string"==typeof r)p=t.text(r);else if(lw(r)){r.content&&(p=dk(r.content,t,"tableParagraph",n));const e=cw(r);e>1&&(m=new Array(e).fill(!1).map((e,t)=>s[f.col+t]??void 0))}else p=dk(r,t,"tableParagraph",n);const g=t.nodes[u||d?"tableHeader":"tableCell"].createChecked({...lw(r)?r.props:{},colwidth:m},t.nodes.tableParagraph.createChecked(h,p));c.push(g)}const u=t.nodes.tableRow.createChecked({},c);o.push(u)}return o}function hk(e,t,n){let o,r=e.type;if(void 0===r&&(r="paragraph"),!t.nodes[r])throw new Error(`node type ${r} not found in schema`);if(e.content)if("string"==typeof e.content){const i=dk([e.content],t,r,n);o=t.nodes[r].createChecked(e.props,i)}else if(Array.isArray(e.content)){const i=dk(e.content,t,r,n);o=t.nodes[r].createChecked(e.props,i)}else{if("tableContent"!==e.content.type)throw new uw(e.content.type);{const i=uk(e.content,t,n);o=t.nodes[r].createChecked(e.props,i)}}else o=t.nodes[r].createChecked(e.props);return o}function pk(e,t,n=Fw(t)){let o=e.id;void 0===o&&(o=nw.options.generateID());const r=[];if(e.children)for(const i of e.children)r.push(pk(i,t,n));if(!e.type||t.nodes[e.type].isInGroup("blockContent")){const i=hk(e,t,n),s=r.length>0?t.nodes.blockGroup.createChecked({},r):void 0;return t.nodes.blockContainer.createChecked({id:o,...e.props},s?[i,s]:i)}if(t.nodes[e.type].isInGroup("bnBlock"))return t.nodes[e.type].createChecked({id:o,...e.props},r);throw new Error(`block type ${e.type} doesn't match blockContent or bnBlock group`)}function fk(e,t){let n,o;if(t.firstChild.descendants((t,r)=>!n&&(!mk(t)||t.attrs.id!==e||(n=t,o=r+1,!1))),void 0!==n&&void 0!==o)return{node:n,posBeforeNode:o}}function mk(e){return e.type.isInGroup("bnBlock")}function gk(e,t,n){const o=Bw(e),r=n.map(e=>pk(e,o)),i=new Set(t.map(e=>"string"==typeof e?e:e.id)),s=[],l="string"==typeof t[0]?t[0]:t[0].id;let a=0;if(e.doc.descendants((t,c)=>{if(0===i.size)return!1;if(!t.type.isInGroup("bnBlock")||!i.has(t.attrs.id))return!0;if(s.push(Gw(t,o)),i.delete(t.attrs.id),n.length>0&&t.attrs.id===l){const t=e.doc.nodeSize;e.insert(c,r);const n=e.doc.nodeSize;a+=t-n}const d=e.doc.nodeSize,u=e.doc.resolve(c-a);"blockGroup"===u.node().type.name&&"doc"!==u.node(u.depth-1).type.name&&1===u.node().childCount?e.delete(u.before(),u.after()):e.delete(c-a,c-a+t.nodeSize);const h=e.doc.nodeSize;return a+=d-h,!1}),i.size>0){const e=[...i].join("\n");throw Error("Blocks with the following IDs could not be found in the editor: "+e)}return{insertedBlocks:r.map(e=>Gw(e,o)),removedBlocks:s}}const yk=(e,t)=>({tr:n,dispatch:o})=>(o&&bk(n,e,t),!0);function bk(e,t,n,o,r){const i=Iw(e.doc.resolve(t));let s=null;"table"===i.blockNoteType&&(s=function(e){const t="selection"in e?e.selection:null;if(!(t instanceof Nr))return null;const n=e.doc.resolve(t.head);let o=-1,r=-1;for(let m=n.depth;m>=0;m--){const e=n.node(m).type.name;if(o<0&&("tableCell"===e||"tableHeader"===e)&&(o=m),"table"===e){r=m;break}}if(o<0||r<0)return null;const i=n.before(o),s=n.before(r),l=e.doc.nodeAt(s);if(!l||"table"!==l.type.name)return null;const a=Id.get(l),c=i-(s+1),d=a.map.indexOf(c);if(d<0)return null;const u=Math.floor(d/a.width),h=d%a.width,p=i+1+1,f=Math.max(0,t.head-p);return{row:u,col:h,offset:f}}(e));const l=Bw(e),a=l.nodes[i.blockNoteType],c=l.nodes[n.type||i.blockNoteType],d=c.isInGroup("bnBlock")?c:l.nodes.blockContainer;if(i.isBlockContainer&&c.isInGroup("blockContent"))vk(n,e,i),function(e,t,n,o,r){const i=Bw(t);let s="keep";if(e.content)if("string"==typeof e.content)s=dk([e.content],i,o.name);else if(Array.isArray(e.content))s=dk(e.content,i,o.name);else{if("tableContent"!==e.content.type)throw new uw(e.content.type);s=uk(e.content,i)}else""===n.spec.content||o.spec.content!==n.spec.content&&(s=[]);"keep"===s?t.setNodeMarkup(r.blockContent.beforePos,o,{...r.blockContent.node.attrs,...e.props}):t.replaceWith(r.blockContent.beforePos,r.blockContent.afterPos,o.createChecked({...r.blockContent.node.attrs,...e.props},s))}(n,e,a,c,i);else{if(i.isBlockContainer||!c.isInGroup("bnBlock")){const t=Gw(i.bnBlock.node,l);return void e.replaceWith(i.bnBlock.beforePos,i.bnBlock.afterPos,pk({children:t.children,...n},l))}vk(n,e,i)}e.setNodeMarkup(i.bnBlock.beforePos,d,{...i.bnBlock.node.attrs,...n.props}),s&&function(e,t,n){var o;if("table"!==t.blockNoteType)return!1;let r=-1;if(t.isBlockContainer)r=e.mapping.map(t.blockContent.beforePos);else{const n=e.mapping.map(t.bnBlock.beforePos),i=n+((null==(o=e.doc.nodeAt(n))?void 0:o.nodeSize)||0);e.doc.nodesBetween(n,i,(e,t)=>"table"!==e.type.name||(r=t,!1))}const i=r>=0?e.doc.nodeAt(r):null;if(!i||"table"!==i.type.name)return!1;const s=Id.get(i),l=Math.max(0,Math.min(n.row,s.height-1)),a=Math.max(0,Math.min(n.col,s.width-1)),c=l*s.width+a,d=s.map[c];if(null==d)return!1;const u=r+1+d+1,h=e.doc.nodeAt(u),p=u+1,f=h?h.content.size:0,m=p+Math.max(0,Math.min(n.offset,f));"selection"in e&&e.setSelection(Nr.create(e.doc,m))}(e,i,s)}function vk(e,t,n){const o=Bw(t);if(void 0!==e.children&&e.children.length>0){const r=e.children.map(e=>pk(e,o));if(n.childContainer)t.step(new Zo(n.childContainer.beforePos+1,n.childContainer.afterPos-1,new _n(Rn.from(r),0,0)));else{if(!n.isBlockContainer)throw new Error("impossible");t.insert(n.blockContent.afterPos,o.nodes.blockGroup.createChecked({},r))}}}function xk(e){const t=Array.from(e.classList).filter(e=>!e.startsWith("bn-"))||[];t.length>0?e.className=t.join(" "):e.removeAttribute("class")}function wk(e,t,n,o){let r;if(!t)throw new Error("blockContent is required");if("string"==typeof t)r=dk([t],e.pmSchema);else if(Array.isArray(t))r=dk(t,e.pmSchema);else{if("tableContent"!==t.type)throw new uw(t.type);r=uk(t,e.pmSchema)}const i=n.serializeFragment(Rn.from(r),o);return 1===i.nodeType&&xk(i),i}function kk(e,t,n,o,r,i,s){var l,a,c,d,u,h,p,f;const m=(null==s?void 0:s.document)??document,g=t.pmSchema.nodes.blockContainer;let y=n.props;if(!n.props){y={};for(const[e,o]of Object.entries(t.schema.blockSchema[n.type].propSchema))void 0!==o.default&&(y[e]=o.default)}const b=null==(a=null==(l=g.spec)?void 0:l.toDOM)?void 0:a.call(l,g.create({id:n.id,...y})),v=Array.from(b.dom.attributes),x=t.blockImplementations[n.type].implementation.toExternalHTML({...n,props:y},t),w=m.createDocumentFragment();if(x.dom.classList.contains("bn-block-content")){const e=[...v,...Array.from(x.dom.attributes)].filter(e=>e.name.startsWith("data")&&"data-content-type"!==e.name&&"data-file-block"!==e.name&&"data-node-view-wrapper"!==e.name&&"data-node-type"!==e.name&&"data-id"!==e.name&&"data-index"!==e.name&&"data-editable"!==e.name);for(const t of e)x.dom.firstChild.setAttribute(t.name,t.value);xk(x.dom.firstChild),w.append(...Array.from(x.dom.childNodes))}else w.append(x.dom);if(x.contentDOM&&n.content){const e=wk(t,n.content,o,s);x.contentDOM.appendChild(e)}let k;if(r.has(n.type)?k="OL":i.has(n.type)&&(k="UL"),k){if((null==(c=e.lastChild)?void 0:c.nodeName)!==k){const t=m.createElement(k);"OL"===k&&null!=y&&y.start&&1!==(null==y?void 0:y.start)&&t.setAttribute("start",y.start+""),e.append(t)}const t=m.createElement("li");t.append(w),e.lastChild.appendChild(t)}else e.append(w);if(n.children&&n.children.length>0){const l=m.createDocumentFragment();if(Ck(l,t,n.children,o,r,i,s),"UL"===(null==(d=e.lastChild)?void 0:d.nodeName)||"OL"===(null==(u=e.lastChild)?void 0:u.nodeName))for(;"UL"===(null==(h=l.firstChild)?void 0:h.nodeName)||"OL"===(null==(p=l.firstChild)?void 0:p.nodeName);)e.lastChild.lastChild.appendChild(l.firstChild);t.pmSchema.nodes[n.type].isInGroup("blockContent")?e.append(l):null==(f=x.contentDOM)||f.append(l)}}const Ck=(e,t,n,o,r,i,s)=>{for(const l of n)kk(e,t,l,o,r,i,s)},Ek=(e,t)=>{const n=jo.fromSchema(e);return{exportBlocks:(e,o)=>{const r=((e,t,n,o,r,i)=>{const s=((null==i?void 0:i.document)??document).createDocumentFragment();return Ck(s,e,t,n,o,r,i),s})(t,e,n,new Set(["numberedListItem"]),new Set(["bulletListItem","checkListItem"]),o),i=document.createElement("div");return i.append(r),i.innerHTML},exportInlineContent:(e,o)=>{const r=wk(t,e,n,o),i=document.createElement("div");return i.append(r.cloneNode(!0)),i.innerHTML}}};function Sk(e,t,n,o,r){var i,s,l,a,c;const d=e.pmSchema.nodes.blockContainer;let u=t.props;if(!t.props){u={};for(const[n,o]of Object.entries(e.schema.blockSchema[t.type].propSchema))void 0!==o.default&&(u[n]=o.default)}const h=e.blockImplementations[t.type].implementation.toInternalHTML({...t,props:u},e);if("numberedListItem"===t.type&&h.dom.setAttribute("data-index",o.toString()),h.contentDOM&&t.content){const o=function(e,t,n,o,r){let i;if(!t)throw new Error("blockContent is required");if("string"==typeof t)i=dk([t],e.pmSchema,o);else if(Array.isArray(t))i=dk(t,e.pmSchema,o);else{if("tableContent"!==t.type)throw new uw(t.type);i=uk(t,e.pmSchema)}return n.serializeFragment(Rn.from(i),r)}(e,t.content,n,t.type,r);h.contentDOM.appendChild(o)}if(e.pmSchema.nodes[t.type].isInGroup("bnBlock")){if(t.children&&t.children.length>0){const o=Mk(e,t.children,n,r);null==(i=h.contentDOM)||i.append(o)}return h.dom}const p=null==(l=null==(s=d.spec)?void 0:s.toDOM)?void 0:l.call(s,d.create({id:t.id,...u}));return null==(a=p.contentDOM)||a.appendChild(h.dom),t.children&&t.children.length>0&&(null==(c=p.contentDOM)||c.appendChild(Rk(e,t.children,n,r))),p.dom}function Mk(e,t,n,o){const r=((null==o?void 0:o.document)??document).createDocumentFragment();let i=0;for(const s of t){"numberedListItem"===s.type?i++:i=0;const t=Sk(e,s,n,i,o);r.appendChild(t)}return r}const Rk=(e,t,n,o)=>{var r;const i=e.pmSchema.nodes.blockGroup,s=i.spec.toDOM(i.create({})),l=Mk(e,t,n,o);return null==(r=s.contentDOM)||r.appendChild(l),s.dom};function Tk(e){const t={},n={},o=Bw(e);return e.descendants((r,i)=>{if(!mk(r))return!0;const s=function(e,t){if(0===t)return;const n=e.resolve(t);for(let o=n.depth;o>0;o--){const e=n.node(o);if(mk(e))return e.attrs.id}}(e,i),l=s??"__root__";n[l]||(n[l]=[]);const a=Gw(r,o);return t[r.attrs.id]={block:a,parentId:s},n[l].push(r.attrs.id),!0}),{byId:t,childrenByParent:n}}function jk(e,t=[]){const n=function(e){return e.getMeta("paste")?{type:"paste"}:"drop"===e.getMeta("uiEvent")?{type:"drop"}:e.getMeta("history$")?{type:e.getMeta("history$").redo?"redo":"undo"}:e.getMeta("y-sync$")?e.getMeta("y-sync$").isUndoRedoOperation?{type:"undo-redo"}:{type:"yjs-remote"}:{type:"local"}}(e),o=qc(e.before,[e,...t]),r=Tk(o.before),i=Tk(o.doc),s=[],l=new Set;Object.keys(i.byId).filter(e=>!(e in r.byId)).forEach(e=>{s.push({type:"insert",block:i.byId[e].block,source:n,prevBlock:void 0}),l.add(e)}),Object.keys(r.byId).filter(e=>!(e in i.byId)).forEach(e=>{s.push({type:"delete",block:r.byId[e].block,source:n,prevBlock:void 0}),l.add(e)}),Object.keys(i.byId).filter(e=>e in r.byId).forEach(e=>{var t,o;const a=r.byId[e],c=i.byId[e];a.parentId!==c.parentId?(s.push({type:"move",block:c.block,prevBlock:a.block,source:n,prevParent:a.parentId?null==(t=r.byId[a.parentId])?void 0:t.block:void 0,currentParent:c.parentId?null==(o=i.byId[c.parentId])?void 0:o.block:void 0}),l.add(e)):Du({...a.block,children:void 0},{...c.block,children:void 0})||(s.push({type:"update",block:c.block,prevBlock:a.block,source:n}),l.add(e))});const a=r.childrenByParent,c=i.childrenByParent,d=new Set([...Object.keys(a),...Object.keys(c)]),u=new Set;return d.forEach(e=>{const t=function(e,t){const n=new Set;if(!e||!t)return n;const o=new Set(e),r=t.filter(e=>o.has(e)),i=e.filter(e=>r.includes(e));if(i.length<=1||r.length<=1)return n;const s={};for(let m=0;m<i.length;m++)s[i[m]]=m;const l=r.map(e=>s[e]),a=l.length,c=[],d=[],u=new Array(a).fill(-1),h=(e,t)=>{let n=0,o=e.length;for(;n<o;){const r=n+o>>>1;e[r]<t?n=r+1:o=r}return n};for(let m=0;m<a;m++){const e=l[m],t=h(c,e);t>0&&(u[m]=d[t-1]),t===c.length?(c.push(e),d.push(m)):(c[t]=e,d[t]=m)}const p=new Set;let f=d[d.length-1]??-1;for(;-1!==f;)p.add(f),f=u[f];for(let m=0;m<r.length;m++)p.has(m)||n.add(r[m]);return n}(a[e],c[e]);0!==t.size&&t.forEach(t=>{var o,a;const c=r.byId[t],d=i.byId[t];!c||!d||c.parentId!==d.parentId||l.has(t)||(c.parentId??"__root__")!==e||u.has(t)||(u.add(t),s.push({type:"move",block:d.block,prevBlock:c.block,source:n,prevParent:c.parentId?null==(o=r.byId[c.parentId])?void 0:o.block:void 0,currentParent:d.parentId?null==(a=i.byId[d.parentId])?void 0:a.block:void 0}),l.add(t))})}),s}const Nk=(e,t)=>{const n=e.querySelector(t);if(!n)return;const o=e.querySelector("figcaption");return{targetElement:n,caption:(null==o?void 0:o.textContent)??void 0}},Ak=(e,t,n,o,r)=>{const i=document.createElement("div");if(i.className="bn-file-block-content-wrapper",""===e.props.url){const n=((e,t,n,o)=>{const r=document.createElement("div");r.className="bn-add-file-button";const i=document.createElement("div");i.className="bn-add-file-button-icon",o?i.appendChild(o):i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',r.appendChild(i);const s=document.createElement("p");s.className="bn-add-file-button-text",s.innerHTML=n||t.dictionary.file_blocks.file.add_button_text,r.appendChild(s);const l=e=>{e.preventDefault()},a=()=>{t.transact(n=>n.setMeta(t.filePanel.plugins[0],{block:e}))};return r.addEventListener("mousedown",l,!0),r.addEventListener("click",a,!0),{dom:r,destroy:()=>{r.removeEventListener("mousedown",l,!0),r.removeEventListener("click",a,!0)}}})(e,t,o,r);i.appendChild(n.dom);const s=t.onUploadStart(t=>{if(t===e.id){i.removeChild(n.dom);const e=document.createElement("div");e.className="bn-file-loading-preview",e.textContent="Loading...",i.appendChild(e)}});return{dom:i,destroy:()=>{s(),n.destroy()}}}const s={dom:i};if(!1!==e.props.showPreview&&n)i.appendChild(n.dom);else{const t=(e=>{const t=document.createElement("div");t.className="bn-file-name-with-icon";const n=document.createElement("div");n.className="bn-file-icon",n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>',t.appendChild(n);const o=document.createElement("p");return o.className="bn-file-name",o.textContent=e.props.name,t.appendChild(o),{dom:t}})(e);i.appendChild(t.dom),s.destroy=()=>{var e;null==(e=t.destroy)||e.call(t)}}if(e.props.caption){const t=document.createElement("p");t.className="bn-file-caption",t.textContent=e.props.caption,i.appendChild(t)}return s},Ok=(e,t)=>{const n=document.createElement("figure"),o=document.createElement("figcaption");return o.textContent=t,n.appendChild(e),n.appendChild(o),{dom:n}},_k=(e,t)=>{const n=document.createElement("div"),o=document.createElement("p");return o.textContent=t,n.appendChild(e),n.appendChild(o),{dom:n}},Pk=e=>({url:e.src||void 0}),Ik={type:"audio",propSchema:{backgroundColor:bw.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0}},content:"none",isFileBlock:!0,fileBlockAccept:["audio/*"]},Lk=e=>{if("AUDIO"===e.tagName)return e.closest("figure")?void 0:Pk(e);if("FIGURE"===e.tagName){const t=Nk(e,"audio");if(!t)return;const{targetElement:n,caption:o}=t;return{...Pk(n),caption:o}}},Dk=Aw(Ik,{render:(e,t)=>{const n=document.createElement("div");n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>';const o=document.createElement("audio");return o.className="bn-audio",t.resolveFileUrl?t.resolveFileUrl(e.props.url).then(e=>{o.src=e}):o.src=e.props.url,o.controls=!0,o.contentEditable="false",o.draggable=!1,Ak(e,t,{dom:o},t.dictionary.file_blocks.audio.add_button_text,n.firstElementChild)},parse:Lk,toExternalHTML:e=>{if(!e.props.url){const e=document.createElement("p");return e.textContent="Add audio",{dom:e}}let t;return e.props.showPreview?(t=document.createElement("audio"),t.src=e.props.url):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ok(t,e.props.caption):_k(t,e.props.caption):{dom:t}}}),Bk=Symbol.for("blocknote.shikiParser"),Hk=Symbol.for("blocknote.shikiHighlighterPromise"),Vk=Sw({name:"codeBlock",content:"inline*",group:"blockContent",marks:"insertion deletion modification",code:!0,defining:!0,addOptions:()=>({defaultLanguage:"text",indentLineWithTab:!0,supportedLanguages:{}}),addAttributes(){const e=this.options;return{language:{default:e.editor.settings.codeBlock.defaultLanguage,parseHTML:t=>{let n=t,o=null;"DIV"===(null==n?void 0:n.tagName)&&"codeBlock"===(null==n?void 0:n.dataset.contentType)&&(n=n.children[0]),"PRE"===(null==n?void 0:n.tagName)&&(n=null==n?void 0:n.children[0]);const r=null==n?void 0:n.getAttribute("data-language");if(r)o=r.toLowerCase();else{const e=[...(null==n?void 0:n.className.split(" "))||[]].filter(e=>e.startsWith("language-")).map(e=>e.replace("language-",""));e.length>0&&(o=e[0].toLowerCase())}return o?zk(e.editor.settings.codeBlock,o)??o:null},renderHTML:e=>e.language?{class:`language-${e.language}`,"data-language":e.language}:{}}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"pre",preserveWhitespace:"full"}]},renderHTML({HTMLAttributes:e}){var t,n;const o=document.createElement("pre"),{dom:r,contentDOM:i}=gw(this.name,"code",(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},{...(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{},...e});return r.removeChild(i),r.appendChild(o),o.appendChild(i),{dom:r,contentDOM:i}},addNodeView(){const e=this.options;return({editor:t,node:n,getPos:o,HTMLAttributes:r})=>{var i,s;const l=document.createElement("pre"),a=document.createElement("select"),c=document.createElement("div"),{dom:d,contentDOM:u}=gw(this.name,"code",{...(null==(i=this.options.domAttributes)?void 0:i.blockContent)||{},...r},(null==(s=this.options.domAttributes)?void 0:s.inlineContent)||{}),h=e=>{const n=e.target.value;t.commands.command(({tr:e})=>(e.setNodeAttribute(o(),"language",n),!0))};return Object.entries(e.editor.settings.codeBlock.supportedLanguages).forEach(([e,{name:t}])=>{const n=document.createElement("option");n.value=e,n.text=t,a.appendChild(n)}),c.contentEditable="false",a.value=n.attrs.language||e.editor.settings.codeBlock.defaultLanguage,d.removeChild(u),d.appendChild(c),d.appendChild(l),l.appendChild(u),c.appendChild(a),a.addEventListener("change",h),{dom:d,contentDOM:u,update:e=>e.type===this.type,destroy:()=>{a.removeEventListener("change",h)}}}},addProseMirrorPlugins(){const e=this.options,t=globalThis;let n,o,r=!1;return[Hu({parser:i=>{if(!e.editor.settings.codeBlock.createHighlighter)return"development"===process.env.NODE_ENV&&!r&&(r=!0),[];if(!n)return t[Hk]=t[Hk]||e.editor.settings.codeBlock.createHighlighter(),t[Hk].then(e=>{n=e});const s=zk(e.editor.settings.codeBlock,i.language);return s&&"text"!==s&&"none"!==s&&"plaintext"!==s&&"txt"!==s?n.getLoadedLanguages().includes(s)?(o||(o=t[Bk]||(l=n,function({content:e,language:t,pos:n,size:o}){var r;const i=[],{tokens:s,fg:a,bg:c,rootStyle:d}=l.codeToTokens(e,{lang:t,theme:l.getLoadedThemes()[0]}),u=d||(a&&c?`--prosemirror-highlight:${a};--prosemirror-highlight-bg:${c}`:"");if(u){const e=Ol.node(n,n+o,{style:u});i.push(e)}let h=n+1;for(const l of s){for(const e of l){const t=h+e.content.length,n=Ol.inline(h,t,{style:$u(null!=(r=e.htmlStyle)?r:`color: ${e.color}`),class:"shiki"});i.push(n),h=t}h+=1}return i}),t[Bk]=o),o(i)):n.loadLanguage(s):[];var l},languageExtractor:e=>e.attrs.language,nodeTypes:[this.name]})]},addInputRules(){const e=this.options;return[new uc({find:/^```(.*?)\s$/,handler:({state:t,range:n,match:o})=>{const r=t.doc.resolve(n.from),i=o[1].trim(),s={language:zk(e.editor.settings.codeBlock,i)??i};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),this.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,this.type,s).setSelection(Nr.create(t.tr.doc,n.from))}})]},addKeyboardShortcuts(){return{Delete:({editor:e})=>{const{selection:t}=e.state,{$from:n}=t;if(e.isActive(this.name)&&!n.parent.textContent&&Ac(t)){const t=n.pos-n.parentOffset-2;return e.chain().setNodeSelection(t).deleteSelection().run(),!0}return!1},Tab:({editor:e})=>!(!this.options.indentLineWithTab||!e.isActive(this.name))&&(e.commands.insertContent(" "),!0),Enter:({editor:e})=>{const{$from:t}=e.state.selection;if(!e.isActive(this.name))return!1;const n=t.parentOffset===t.parent.nodeSize-2,o=t.parent.textContent.endsWith("\n\n");return n&&o?e.chain().command(({tr:e})=>(e.delete(t.pos-2,t.pos),!0)).exitCode().run():(e.commands.insertContent("\n"),!0)},"Shift-Enter":({editor:e})=>{const{$from:t}=e.state.selection;return!!e.isActive(this.name)&&(e.chain().insertContentAt(t.pos-t.parentOffset+t.parent.nodeSize,{type:"paragraph"}).run(),!0)}}}}),$k=Rw(Vk,{language:{default:"text"}});function zk(e,t){var n;return null==(n=Object.entries(e.supportedLanguages).find(([e,{aliases:n}])=>(null==n?void 0:n.includes(t))||e===t))?void 0:n[0]}const Fk=Zw(gc.create({name:"backgroundColor",addAttributes:()=>({stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-background-color"),renderHTML:e=>({"data-background-color":e.stringValue})}}),parseHTML:()=>[{tag:"span",getAttrs:e=>"string"!=typeof e&&(!!e.hasAttribute("data-background-color")&&{stringValue:e.getAttribute("data-background-color")})}],renderHTML:({HTMLAttributes:e})=>["span",e,0]}),"string"),Uk=Zw(gc.create({name:"textColor",addAttributes:()=>({stringValue:{default:void 0,parseHTML:e=>e.getAttribute("data-text-color"),renderHTML:e=>({"data-text-color":e.stringValue})}}),parseHTML:()=>[{tag:"span",getAttrs:e=>"string"!=typeof e&&(!!e.hasAttribute("data-text-color")&&{stringValue:e.getAttribute("data-text-color")})}],renderHTML:({HTMLAttributes:e})=>["span",e,0]}),"string"),Wk=e=>({url:e.src||void 0}),qk={type:"file",propSchema:{backgroundColor:bw.backgroundColor,name:{default:""},url:{default:""},caption:{default:""}},content:"none",isFileBlock:!0},Gk=e=>{if("EMBED"===e.tagName)return e.closest("figure")?void 0:Wk(e);if("FIGURE"===e.tagName){const t=Nk(e,"embed");if(!t)return;const{targetElement:n,caption:o}=t;return{...Wk(n),caption:o}}},Kk=Aw(qk,{render:(e,t)=>Ak(e,t),parse:Gk,toExternalHTML:e=>{if(!e.props.url){const e=document.createElement("p");return e.textContent="Add file",{dom:e}}const t=document.createElement("a");return t.href=e.props.url,t.textContent=e.props.name||e.props.url,e.props.caption?_k(t,e.props.caption):{dom:t}}}),Zk={set:(e,t)=>window.localStorage.setItem(`toggle-${e.id}`,t?"true":"false"),get:e=>"true"===window.localStorage.getItem(`toggle-${e.id}`)},Jk=(e,t,n,o=Zk)=>{if("isToggleable"in e.props&&!e.props.isToggleable)return{dom:n};const r=document.createElement("div"),i=document.createElement("div");i.className="bn-toggle-wrapper";const s=document.createElement("button");s.className="bn-toggle-button",s.type="button",s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="CURRENTCOLOR"><path d="M320-200v-560l440 280-440 280Z"/></svg>';const l=e=>e.preventDefault();s.addEventListener("mousedown",l);const a=()=>{var n;"true"===i.getAttribute("data-show-children")?(i.setAttribute("data-show-children","false"),o.set(t.getBlock(e),!1),r.contains(c)&&r.removeChild(c)):(i.setAttribute("data-show-children","true"),o.set(t.getBlock(e),!0),0===(null==(n=t.getBlock(e))?void 0:n.children.length)&&!r.contains(c)&&r.appendChild(c))};s.addEventListener("click",a),i.appendChild(s),i.appendChild(n);const c=document.createElement("button");c.className="bn-toggle-add-block-button",c.type="button",c.textContent=t.dictionary.toggle_blocks.add_block_button;const d=e=>e.preventDefault();c.addEventListener("mousedown",d);const u=()=>{t.transact(()=>{const n=t.updateBlock(e,{children:[{}]});t.setTextCursorPosition(n.children[0].id,"end"),t.focus()})};c.addEventListener("click",u),r.appendChild(i);let h=e.children.length;const p=t.onChange(()=>{var n;const s=(null==(n=t.getBlock(e))?void 0:n.children.length)??0;s>h?("false"===i.getAttribute("data-show-children")&&(i.setAttribute("data-show-children","true"),o.set(t.getBlock(e),!0)),r.contains(c)&&r.removeChild(c)):0===s&&s<h&&("true"===i.getAttribute("data-show-children")&&(i.setAttribute("data-show-children","false"),o.set(t.getBlock(e),!1)),r.contains(c)&&r.removeChild(c)),h=s});return o.get(e)?(i.setAttribute("data-show-children","true"),0===e.children.length&&r.appendChild(c)):i.setAttribute("data-show-children","false"),{dom:r,ignoreMutation:e=>e instanceof MutationRecord&&("attributes"===e.type&&e.target===i&&"data-show-children"===e.attributeName||"childList"===e.type&&(e.addedNodes[0]===c||e.removedNodes[0]===c)),destroy:()=>{s.removeEventListener("mousedown",l),s.removeEventListener("click",a),c.removeEventListener("mousedown",d),c.removeEventListener("click",u),null==p||p()}}},Xk={...bw,level:{default:1,values:[1,2,3,4,5,6]},isToggleable:{default:!1}},Yk=Sw({name:"heading",content:"inline*",group:"blockContent",addAttributes:()=>kw(Xk),addInputRules(){return[...this.options.editor.settings.heading.levels.map(e=>new uc({find:new RegExp(`^(#{${e}})\\s$`),handler:({state:t,chain:n,range:o})=>{const r=Lw(t);!r.isBlockContainer||"inline*"!==r.blockContent.node.type.spec.content||n().command(yk(r.bnBlock.beforePos,{type:"heading",props:{level:e}})).deleteRange({from:o.from,to:o.to}).run()}}))]},addKeyboardShortcuts(){const e=this.options.editor;return Object.fromEntries(e.settings.heading.levels.map(e=>[`Mod-Alt-${e}`,()=>{const t=Lw(this.editor.state);return!t.isBlockContainer||"inline*"!==t.blockContent.node.type.spec.content||this.editor.commands.command(yk(t.bnBlock.beforePos,{type:"heading",props:{level:e}}))}]))},parseHTML(){const e=this.options.editor;return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},...e.settings.heading.levels.map(e=>({tag:`h${e}`,attrs:{level:e},node:"heading"}))]},renderHTML({node:e,HTMLAttributes:t}){var n,o;return gw(this.name,`h${e.attrs.level}`,{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...t},(null==(o=this.options.domAttributes)?void 0:o.inlineContent)||{})},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n})=>{var o,r;const{dom:i,contentDOM:s}=gw(this.name,`h${e.attrs.level}`,{...(null==(o=this.options.domAttributes)?void 0:o.blockContent)||{},...t},(null==(r=this.options.domAttributes)?void 0:r.inlineContent)||{});i.removeChild(s);const l=this.options.editor,a=Cw(n,l,this.editor,this.name),c=Jk(a,l,s);return i.appendChild(c.dom),{dom:i,contentDOM:s,ignoreMutation:c.ignoreMutation,destroy:c.destroy}}}}),Qk=Rw(Yk,Xk),eC=(e,t,n,o,r,i)=>{const{dom:s,destroy:l}=Ak(e,t,n,r,i),a=s;e.props.url&&e.props.showPreview&&(e.props.previewWidth?a.style.width=`${e.props.previewWidth}px`:a.style.width="fit-content");const c=document.createElement("div");c.className="bn-resize-handle",c.style.left="4px";const d=document.createElement("div");d.className="bn-resize-handle",d.style.right="4px";let u,h=e.props.previewWidth;const p=n=>{var r,i;if(!u)return void(!t.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d)));let s;s="center"===e.props.textAlignment?"left"===u.handleUsed?u.initialWidth+2*(u.initialClientX-n.clientX):u.initialWidth+2*(n.clientX-u.initialClientX):"left"===u.handleUsed?u.initialWidth+u.initialClientX-n.clientX:u.initialWidth+n.clientX-u.initialClientX,h=Math.min(Math.max(s,64),(null==(i=null==(r=t.domElement)?void 0:r.firstElementChild)?void 0:i.clientWidth)||Number.MAX_VALUE),a.style.width=`${h}px`},f=n=>{(!n.target||!a.contains(n.target)||!t.isEditable)&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d)),u&&(u=void 0,t.updateBlock(e,{props:{previewWidth:h}}))},m=()=>{t.isEditable&&(o.appendChild(c),o.appendChild(d))},g=e=>{e.relatedTarget===c||e.relatedTarget===d||u||t.isEditable&&o.contains(c)&&o.contains(d)&&(o.removeChild(c),o.removeChild(d))},y=e=>{e.preventDefault(),u={handleUsed:"left",initialWidth:a.clientWidth,initialClientX:e.clientX}},b=e=>{e.preventDefault(),u={handleUsed:"right",initialWidth:a.clientWidth,initialClientX:e.clientX}};return window.addEventListener("mousemove",p),window.addEventListener("mouseup",f),a.addEventListener("mouseenter",m),a.addEventListener("mouseleave",g),c.addEventListener("mousedown",y),d.addEventListener("mousedown",b),{dom:a,destroy:()=>{null==l||l(),window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",f),a.removeEventListener("mouseenter",m),a.removeEventListener("mouseleave",g),c.removeEventListener("mousedown",y),d.removeEventListener("mousedown",b)}}},tC=e=>({url:e.src||void 0,previewWidth:e.width||void 0,name:e.alt||void 0}),nC={type:"image",propSchema:{textAlignment:bw.textAlignment,backgroundColor:bw.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},content:"none",isFileBlock:!0,fileBlockAccept:["image/*"]},oC=e=>{if("IMG"===e.tagName)return e.closest("figure")?void 0:tC(e);if("FIGURE"===e.tagName){const t=Nk(e,"img");if(!t)return;const{targetElement:n,caption:o}=t;return{...tC(n),caption:o}}},rC=Aw(nC,{render:(e,t)=>{const n=document.createElement("div");n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M5 11.1005L7 9.1005L12.5 14.6005L16 11.1005L19 14.1005V5H5V11.1005ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM15.5 10C14.6716 10 14 9.32843 14 8.5C14 7.67157 14.6716 7 15.5 7C16.3284 7 17 7.67157 17 8.5C17 9.32843 16.3284 10 15.5 10Z"></path></svg>';const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("img");return r.className="bn-visual-media",t.resolveFileUrl?t.resolveFileUrl(e.props.url).then(e=>{r.src=e}):r.src=e.props.url,r.alt=e.props.name||e.props.caption||"BlockNote image",r.contentEditable="false",r.draggable=!1,o.appendChild(r),eC(e,t,{dom:o},o,t.dictionary.file_blocks.image.add_button_text,n.firstElementChild)},parse:oC,toExternalHTML:e=>{if(!e.props.url){const e=document.createElement("p");return e.textContent="Add image",{dom:e}}let t;return e.props.showPreview?(t=document.createElement("img"),t.src=e.props.url,t.alt=e.props.name||e.props.caption||"BlockNote image",e.props.previewWidth&&(t.width=e.props.previewWidth)):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ok(t,e.props.caption):_k(t,e.props.caption):{dom:t}}}),iC=(e,t,n)=>({state:o,dispatch:r})=>{const i=Pw(Ow(o.doc,e));if(!i.isBlockContainer)throw new Error(`BlockContainer expected when calling splitBlock, position ${e}`);const s=[{type:i.bnBlock.node.type,attrs:n?{...i.bnBlock.node.attrs,id:void 0}:{}},{type:t?i.blockContent.node.type:o.schema.nodes.paragraph,attrs:n?{...i.blockContent.node.attrs}:{}}];return r&&o.tr.split(e,2,s),!0},sC=e=>{const{blockInfo:t,selectionEmpty:n}=e.transact(e=>({blockInfo:Dw(e),selectionEmpty:e.selection.anchor===e.selection.head}));if(!t.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=t;return!("toggleListItem"!==r.node.type.name&&"bulletListItem"!==r.node.type.name&&"numberedListItem"!==r.node.type.name&&"checkListItem"!==r.node.type.name||!n)&&e._tiptapEditor.commands.first(({state:e,chain:t,commands:n})=>[()=>n.command(()=>0===r.node.childCount&&n.command(yk(o.beforePos,{type:"paragraph",props:{}}))),()=>n.command(()=>r.node.childCount>0&&(t().deleteSelection().command(iC(e.selection.from,!0)).run(),!0))])},lC={...bw},aC=Sw({name:"toggleListItem",content:"inline*",group:"blockContent",priority:90,addKeyboardShortcuts(){return{Enter:()=>sC(this.options.editor),"Mod-Shift-6":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"toggleListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"p",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})},addNodeView(){return({HTMLAttributes:e,getPos:t})=>{var n,o;const{dom:r,contentDOM:i}=gw(this.name,"p",{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...e},(null==(o=this.options.domAttributes)?void 0:o.inlineContent)||{}),s=this.options.editor,l=Cw(t,s,this.editor,this.name),a=Jk(l,s,i);return r.appendChild(a.dom),{dom:r,contentDOM:i,ignoreMutation:a.ignoreMutation,destroy:a.destroy}}}}),cC=Rw(aC,lC);function dC(e,t,n){var o,r,i;const s=vo.fromSchema(t),l=e,a=document.createElement("div");a.setAttribute("data-node-type","blockGroup");for(const p of Array.from(l.childNodes))a.appendChild(p.cloneNode(!0));let c=s.parse(a,{topNode:t.nodes.blockGroup.create()});"checkListItem"===(null==(r=null==(o=c.firstChild)?void 0:o.firstChild)?void 0:r.type.name)&&(c=c.copy(c.content.cut(c.firstChild.firstChild.nodeSize+2)));const d=null==(i=c.firstChild)?void 0:i.firstChild;if(null==d||!d.isTextblock)return Rn.from(c);const u=t.nodes[n].create({},d.content),h=c.content.cut(d.nodeSize+2);if(h.size>0){const e=c.copy(h);return u.content.addToEnd(e)}return u.content}const uC={...bw},hC=Rw(Sw({name:"bulletListItem",content:"inline*",group:"blockContent",priority:90,addInputRules:()=>[new uc({find:new RegExp("^[-+*]\\s$"),handler:({state:e,chain:t,range:n})=>{const o=Lw(e);!o.isBlockContainer||"inline*"!==o.blockContent.node.type.spec.content||"heading"===o.blockNoteType||t().command(yk(o.bnBlock.beforePos,{type:"bulletListItem",props:{}})).deleteRange({from:n.from,to:n.to})}})],addKeyboardShortcuts(){return{Enter:()=>sC(this.options.editor),"Mod-Shift-8":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"bulletListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if("string"==typeof e)return!1;const n=e.parentElement;return null!==n&&(("UL"===n.tagName||"DIV"===n.tagName&&"UL"===(null==(t=n.parentElement)?void 0:t.tagName))&&{})},getContent:(e,t)=>dC(e,t,this.name),node:"bulletListItem"}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"p",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})}}),uC),pC={...bw,checked:{default:!1}},fC=Sw({name:"checkListItem",content:"inline*",group:"blockContent",addAttributes:()=>kw(pC),addInputRules:()=>[new uc({find:new RegExp("\\[\\s*\\]\\s$"),handler:({state:e,chain:t,range:n})=>{const o=Lw(e);!o.isBlockContainer||"inline*"!==o.blockContent.node.type.spec.content||t().command(yk(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!1}})).deleteRange({from:n.from,to:n.to})}}),new uc({find:new RegExp("\\[[Xx]\\]\\s$"),handler:({state:e,chain:t,range:n})=>{const o=Lw(e);!o.isBlockContainer||"inline*"!==o.blockContent.node.type.spec.content||t().command(yk(o.bnBlock.beforePos,{type:"checkListItem",props:{checked:!0}})).deleteRange({from:n.from,to:n.to})}})],addKeyboardShortcuts(){return{Enter:()=>sC(this.options.editor),"Mod-Shift-9":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"checkListItem",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"input",getAttrs:e=>"string"!=typeof e&&!e.closest("[data-content-type]")&&!e.closest("li")&&("checkbox"===e.type&&{checked:e.checked}),node:"checkListItem"},{tag:"li",getAttrs:e=>{var t;if("string"==typeof e)return!1;const n=e.parentElement;if(null===n)return!1;if("UL"===n.tagName||"DIV"===n.tagName&&"UL"===(null==(t=n.parentElement)?void 0:t.tagName)){const t=e.querySelector("input[type=checkbox]")||null;return null!==t&&{checked:t.checked}}return!1},getContent:(e,t)=>dC(e,t,this.name),node:"checkListItem"}]},renderHTML({node:e,HTMLAttributes:t}){var n,o;const r=document.createElement("input");r.type="checkbox",r.checked=e.attrs.checked,e.attrs.checked&&r.setAttribute("checked","");const{dom:i,contentDOM:s}=gw(this.name,"p",{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...t},(null==(o=this.options.domAttributes)?void 0:o.inlineContent)||{});return i.insertBefore(r,s),{dom:i,contentDOM:s}},addNodeView(){return({node:e,getPos:t,editor:n,HTMLAttributes:o})=>{var r,i;const s=document.createElement("div"),l=document.createElement("div");l.contentEditable="false";const a=document.createElement("input");a.type="checkbox",a.checked=e.attrs.checked,e.attrs.checked&&a.setAttribute("checked","");const c=()=>{if(n.isEditable){if("boolean"!=typeof t){const e=Ow(n.state.doc,t());if("blockContainer"!==e.node.type.name)throw new Error(`Expected blockContainer node, got ${e.node.type.name}`);this.editor.commands.command(yk(e.posBeforeNode,{type:"checkListItem",props:{checked:a.checked}}))}}else a.checked=!a.checked};a.addEventListener("change",c);const{dom:d,contentDOM:u}=gw(this.name,"p",{...(null==(r=this.options.domAttributes)?void 0:r.blockContent)||{},...o},(null==(i=this.options.domAttributes)?void 0:i.inlineContent)||{});if("boolean"!=typeof t){const e="label-"+this.editor.state.doc.resolve(t()).node().attrs.id;a.setAttribute("aria-labelledby",e),u.id=e}return d.removeChild(u),d.appendChild(s),s.appendChild(l),s.appendChild(u),l.appendChild(a),{dom:d,contentDOM:u,destroy:()=>{a.removeEventListener("change",c)}}}}}),mC=Rw(fC,pC),gC=new Kr("numbered-list-indexing"),yC={...bw,start:{default:void 0,type:"number"}},bC=Sw({name:"numberedListItem",content:"inline*",group:"blockContent",priority:90,addAttributes:()=>({...kw(yC),index:{default:null,parseHTML:e=>e.getAttribute("data-index"),renderHTML:e=>({"data-index":e.index})}}),addInputRules:()=>[new uc({find:new RegExp("^(\\d+)\\.\\s$"),handler:({state:e,chain:t,range:n,match:o})=>{const r=Lw(e);if(!r.isBlockContainer||"inline*"!==r.blockContent.node.type.spec.content||"numberedListItem"===r.blockNoteType||"heading"===r.blockNoteType)return;const i=parseInt(o[1]);t().command(yk(r.bnBlock.beforePos,{type:"numberedListItem",props:1===i&&{}||{start:i}})).deleteRange({from:n.from,to:n.to})}})],addKeyboardShortcuts(){return{Enter:()=>sC(this.options.editor),"Mod-Shift-7":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"numberedListItem",props:{}}))}}},addProseMirrorPlugins:()=>[new Wr({key:gC,appendTransaction:(e,t,n)=>{const o=n.tr;o.setMeta("numberedListIndexing",!0);let r=!1;return n.doc.descendants((e,t)=>{var n;if("blockContainer"===e.type.name&&"numberedListItem"===e.firstChild.type.name){let i=`${e.firstChild.attrs.start||1}`;const s=Pw({posBeforeNode:t,node:e});if(!s.isBlockContainer)throw new Error("impossible");const l=o.doc.resolve(s.bnBlock.beforePos).nodeBefore;if(l){const e=Pw({posBeforeNode:s.bnBlock.beforePos-l.nodeSize,node:l});if("numberedListItem"===e.blockNoteType){if(!e.isBlockContainer)throw new Error("impossible");const t=e.blockContent.node.attrs.index;i=(parseInt(t)+1).toString()}}const a=s.blockContent.node,c=a.attrs.index,d="numberedListItem"!==(null==(n=null==l?void 0:l.firstChild)?void 0:n.type.name);if(c!==i||a.attrs.start&&!d){r=!0;const{start:e,...t}=a.attrs;o.setNodeMarkup(s.blockContent.beforePos,void 0,{...t,index:i,..."number"==typeof e&&d&&{start:e}})}}}),r?o:null}})],parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"li",getAttrs:e=>{var t;if("string"==typeof e)return!1;const n=e.parentElement;if(null===n)return!1;if("OL"===n.tagName||"DIV"===n.tagName&&"OL"===(null==(t=n.parentElement)?void 0:t.tagName)){const t=parseInt(n.getAttribute("start")||"1")||1;return e.previousSibling||1===t?{}:{start:t}}return!1},getContent:(e,t)=>dC(e,t,this.name),priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"p",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})}}),vC=Rw(bC,yC),xC={...bw},wC=Rw(Sw({name:"paragraph",content:"inline*",group:"blockContent",addKeyboardShortcuts(){return{"Mod-Alt-0":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"paragraph",props:{}}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"p",getAttrs:e=>{var t;return!("string"==typeof e||null==(t=e.textContent)||!t.trim())&&{}},node:"paragraph"}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"p",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})}}),xC),kC={...bw},CC=Rw(Sw({name:"quote",content:"inline*",group:"blockContent",addInputRules:()=>[new uc({find:new RegExp("^>\\s$"),handler:({state:e,chain:t,range:n})=>{const o=Lw(e);!o.isBlockContainer||"inline*"!==o.blockContent.node.type.spec.content||t().command(yk(o.bnBlock.beforePos,{type:"quote",props:{}})).deleteRange({from:n.from,to:n.to})}})],addKeyboardShortcuts(){return{"Mod-Alt-q":()=>{const e=Lw(this.editor.state);return!e.isBlockContainer||"inline*"!==e.blockContent.node.type.spec.content||this.editor.commands.command(yk(e.bnBlock.beforePos,{type:"quote"}))}}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",contentElement:".bn-inline-content"},{tag:"blockquote",node:"quote",getContent:(e,t)=>{const n=e.cloneNode(!0);return function(e){const t=e.querySelectorAll("p");if(t.length>1){const e=t[0];for(let n=1;n<t.length;n++){const o=t[n];e.innerHTML+="<br>"+o.innerHTML,o.remove()}}}(n),vo.fromSchema(t).parse(n,{topNode:t.nodes.paragraph.create()}).content}}]},renderHTML({HTMLAttributes:e}){var t,n;return gw(this.name,"blockquote",{...(null==(t=this.options.domAttributes)?void 0:t.blockContent)||{},...e},(null==(n=this.options.domAttributes)?void 0:n.inlineContent)||{})}}),kC),EC=kc.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[Tu({cellMinWidth:35,defaultCellMinWidth:120,View:null}),Iu()],addKeyboardShortcuts(){return{Enter:()=>!(!this.editor.state.selection.empty||"tableParagraph"!==this.editor.state.selection.$head.parent.type.name)&&(this.editor.commands.insertContent({type:"hardBreak"}),!0),Backspace:()=>{const e=this.editor.state.selection,t=e.empty,n=0===e.$head.parentOffset,o="tableParagraph"===e.$head.node().type.name;return t&&n&&o},Tab:()=>this.editor.commands.command(({state:e,dispatch:t,view:n})=>au(1)(e,t,n)),"Shift-Tab":()=>this.editor.commands.command(({state:e,dispatch:t,view:n})=>au(-1)(e,t,n))}},extendNodeSchema:e=>({tableRole:oc(Ja(e,"tableRole",{name:e.name,options:e.options,storage:e.storage}))})}),SC={textColor:bw.textColor},MC=Sw({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",marks:"deletion insertion modification",isolating:!0,parseHTML:()=>[{tag:"table"}],renderHTML({node:e,HTMLAttributes:t}){var n,o,r;const i=gw(this.name,"table",{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...t},(null==(o=this.options.domAttributes)?void 0:o.inlineContent)||{}),s=document.createElement("colgroup");for(const l of e.children[0].children)if(l.attrs.colwidth)for(const e of l.attrs.colwidth){const t=document.createElement("col");e&&(t.style=`width: ${e}px`),s.appendChild(t)}else s.appendChild(document.createElement("col"));return null==(r=i.dom.firstChild)||r.appendChild(s),i},addNodeView(){return({node:e,HTMLAttributes:t})=>{var n;return new class extends Su{constructor(e,t,n){super(e,t),this.node=e,this.cellMinWidth=t,this.blockContentHTMLAttributes=n;const o=document.createElement("div");o.className=fw("bn-block-content",n.class),o.setAttribute("data-content-type","table");for(const[l,a]of Object.entries(n))"class"!==l&&o.setAttribute(l,a);const r=this.dom,i=document.createElement("div");i.className="tableWrapper-inner",i.appendChild(r.firstChild),r.appendChild(i),o.appendChild(r);const s=document.createElement("div");s.className="table-widgets-container",s.style.position="relative",r.appendChild(s),this.dom=o}ignoreMutation(e){return!e.target.closest(".tableWrapper-inner")||super.ignoreMutation(e)}}(e,120,{...(null==(n=this.options.domAttributes)?void 0:n.blockContent)||{},...t})}}}),RC=Sw({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML:()=>[{tag:"p",getAttrs:e=>{if("string"==typeof e||!e.textContent||!e.closest("[data-content-type]"))return!1;const t=e.parentElement;return null!==t&&(("TD"===t.tagName||"TH"===t.tagName)&&{})},node:"tableParagraph"}],renderHTML:({node:e,HTMLAttributes:t})=>["p",t,e.childCount?0:["br"]]}),TC=kd.create({name:"tableRow",addOptions:()=>({HTMLAttributes:{}}),content:"(tableCell | tableHeader)+",tableRole:"row",marks:"deletion insertion modification",parseHTML:()=>[{tag:"tr"}],renderHTML({HTMLAttributes:e}){return["tr",ec(this.options.HTMLAttributes,e),0]}});function jC(e,t){const n=vo.fromSchema(t).parse(e,{topNode:t.nodes.blockGroup.create()}),o=[];return n.content.descendants(e=>{if(e.isInline)return o.push(e),!1}),Rn.fromArray(o)}const NC=Rw(MC,SC,[EC,RC,sh.extend({content:"tableContent+",parseHTML:()=>[{tag:"th",getContent:(e,t)=>jC(e,t)}]}),ih.extend({content:"tableContent+",parseHTML:()=>[{tag:"td",getContent:(e,t)=>jC(e,t)}]}),TC]),AC=e=>({url:e.src||void 0,previewWidth:e.width||void 0}),OC={type:"video",propSchema:{textAlignment:bw.textAlignment,backgroundColor:bw.backgroundColor,name:{default:""},url:{default:""},caption:{default:""},showPreview:{default:!0},previewWidth:{default:void 0,type:"number"}},content:"none",isFileBlock:!0,fileBlockAccept:["video/*"]},_C=e=>{if("VIDEO"===e.tagName)return e.closest("figure")?void 0:AC(e);if("FIGURE"===e.tagName){const t=Nk(e,"video");if(!t)return;const{targetElement:n,caption:o}=t;return{...AC(n),caption:o}}},PC={paragraph:wC,heading:Qk,quote:CC,codeBlock:$k,toggleListItem:cC,bulletListItem:hC,numberedListItem:vC,checkListItem:mC,table:NC,file:Kk,image:rC,video:Aw(OC,{render:(e,t)=>{const n=document.createElement("div");n.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>';const o=document.createElement("div");o.className="bn-visual-media-wrapper";const r=document.createElement("video");return r.className="bn-visual-media",t.resolveFileUrl?t.resolveFileUrl(e.props.url).then(e=>{r.src=e}):r.src=e.props.url,r.controls=!0,r.contentEditable="false",r.draggable=!1,r.width=e.props.previewWidth,o.appendChild(r),eC(e,t,{dom:o},o,t.dictionary.file_blocks.video.add_button_text,n.firstElementChild)},parse:_C,toExternalHTML:e=>{if(!e.props.url){const e=document.createElement("p");return e.textContent="Add video",{dom:e}}let t;return e.props.showPreview?(t=document.createElement("video"),t.src=e.props.url,e.props.previewWidth&&(t.width=e.props.previewWidth)):(t=document.createElement("a"),t.href=e.props.url,t.textContent=e.props.name||e.props.url),e.props.caption?e.props.showPreview?Ok(t,e.props.caption):_k(t,e.props.caption):{dom:t}}}),audio:Dk},IC=Tw(PC),LC={bold:Zw(qu,"boolean"),italic:Zw(eh,"boolean"),underline:Zw(rh,"boolean"),strike:Zw(oh,"boolean"),code:Zw(Zu,"boolean"),textColor:Uk,backgroundColor:Fk};Jw(LC);const DC={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},BC=Kw(DC);function HC(e,t){return e in t.schema.blockSchema&&t.schema.blockSchema[e]===IC[e]}function VC(e,t){return e.type in t.schema.blockSchema&&t.schema.blockSchema[e.type].isFileBlock||!1}function $C(e,t){return t.schema.blockSchema[e.type].isFileBlock&&!e.props.url}function zC(e,t,n){return t in n.schema.blockSchema&&e in n.schema.blockSchema[t].propSchema&&n.schema.blockSchema[t].propSchema[e]===bw[e]}function FC(e,t,n){return zC(e,t.type,n)}function UC(e){return e instanceof Gd}function WC(e,t){const n=e.getTextCursorPosition().block;if(void 0===n.content)throw new Error("Slash Menu open in a block that doesn't contain content.");let o;return Array.isArray(n.content)&&(1===n.content.length&&iw(n.content[0])&&"text"===n.content[0].type&&"/"===n.content[0].text||0===n.content.length)?(o=e.updateBlock(n,t),e.setTextCursorPosition(o)):(o=e.insertBlocks([t],n,"after")[0],e.setTextCursorPosition(e.getTextCursorPosition().nextBlock)),function(e){let t=e.getTextCursorPosition().block,n=e.schema.blockSchema[t.type].content;for(;"none"===n;){if(t=e.getTextCursorPosition().nextBlock,void 0===t)return;n=e.schema.blockSchema[t.type].content,e.setTextCursorPosition(t,"end")}}(e),o}function qC(e){return e&&Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e))}let GC=class e{constructor(e){ew(this,"blockSpecs"),ew(this,"inlineContentSpecs"),ew(this,"styleSpecs"),ew(this,"blockSchema"),ew(this,"inlineContentSchema"),ew(this,"styleSchema"),ew(this,"BlockNoteEditor","only for types"),ew(this,"Block","only for types"),ew(this,"PartialBlock","only for types"),this.blockSpecs=qC(null==e?void 0:e.blockSpecs)||PC,this.inlineContentSpecs=qC(null==e?void 0:e.inlineContentSpecs)||DC,this.styleSpecs=qC(null==e?void 0:e.styleSpecs)||LC,this.blockSchema=Tw(this.blockSpecs),this.inlineContentSchema=Kw(this.inlineContentSpecs),this.styleSchema=Jw(this.styleSpecs)}static create(t){return new e(t)}};const KC=Aw({type:"pageBreak",propSchema:{},content:"none",isFileBlock:!1,isSelectable:!1},{render:()=>{const e=document.createElement("div");return e.className="bn-page-break",e.setAttribute("data-page-break",""),{dom:e}},parse:e=>{if("DIV"===e.tagName&&e.hasAttribute("data-page-break"))return{type:"pageBreak"}},toExternalHTML:()=>{const e=document.createElement("div");return e.setAttribute("data-page-break",""),{dom:e}}});function ZC(e){return e.map(e=>"columnList"===e.type?e.children.map(e=>ZC(e.children)).flat():{...e,children:ZC(e.children)}).flat()}function JC(e,t,n){e.transact(o=>{var r;const i=(null==(r=e.getSelection())?void 0:r.blocks)||[e.getTextCursorPosition().block],s=function(e){return e.transact(e=>{const t=Ow(e.doc,e.selection.anchor);if(e.selection instanceof Gd)return{type:"cell",anchorBlockId:t.node.attrs.id,anchorCellOffset:e.selection.$anchorCell.pos-t.posBeforeNode,headCellOffset:e.selection.$headCell.pos-t.posBeforeNode};if(e.selection instanceof Or)return{type:"node",anchorBlockId:t.node.attrs.id};{const n=Ow(e.doc,e.selection.head);return{type:"text",anchorBlockId:t.node.attrs.id,headBlockId:n.node.attrs.id,anchorOffset:e.selection.anchor-t.posBeforeNode,headOffset:e.selection.head-n.posBeforeNode}}})}(e);e.removeBlocks(i),e.insertBlocks(ZC(i),t,n),function(e,t){var n,o;const r=null==(n=fk(t.anchorBlockId,e.doc))?void 0:n.posBeforeNode;if(void 0===r)throw new Error(`Could not find block with ID ${t.anchorBlockId} to update selection`);let i;if("cell"===t.type)i=Gd.create(e.doc,r+t.anchorCellOffset,r+t.headCellOffset);else if("node"===t.type)i=Or.create(e.doc,r+1);else{const n=null==(o=fk(t.headBlockId,e.doc))?void 0:o.posBeforeNode;if(void 0===n)throw new Error(`Could not find block with ID ${t.headBlockId} to update selection`);i=Nr.create(e.doc,r+t.anchorOffset,n+t.headOffset)}e.setSelection(i)}(o,s)})}function XC(e){return!e||"columnList"!==e.type}function YC(e,t,n){let o,r;if(t?t.children.length>0?(o=t.children[t.children.length-1],r="after"):(o=t,r="before"):n&&(o=n,r="before"),!o||!r)return;const i=e.getParentBlock(o);return XC(i)?{referenceBlock:o,placement:r}:YC(e,"after"===r?o:e.getPrevBlock(o),i)}function QC(e,t,n){let o,r;if(t?t.children.length>0?(o=t.children[0],r="before"):(o=t,r="after"):n&&(o=n,r="after"),!o||!r)return;const i=e.getParentBlock(o);return XC(i)?{referenceBlock:o,placement:r}:QC(e,"before"===r?o:e.getNextBlock(o),i)}function eE(e){e.transact(()=>{const t=e.getSelection(),n=(null==t?void 0:t.blocks[0])||e.getTextCursorPosition().block,o=YC(e,e.getPrevBlock(n),e.getParentBlock(n));o&&JC(e,o.referenceBlock,o.placement)})}function tE(e){e.transact(()=>{const t=e.getSelection(),n=(null==t?void 0:t.blocks[(null==t?void 0:t.blocks.length)-1])||e.getTextCursorPosition().block,o=QC(e,e.getNextBlock(n),e.getParentBlock(n));o&&JC(e,o.referenceBlock,o.placement)})}function nE(e){return e.transact(t=>function(e,t,n){const{$from:o,$to:r}=e.selection,i=o.blockRange(r,e=>e.childCount>0&&("blockGroup"===e.type.name||"column"===e.type.name));if(!i)return!1;const s=i.startIndex;if(0===s)return!1;const l=i.parent.child(s-1);if(l.type!==t)return!1;const a=l.lastChild&&l.lastChild.type===n,c=Rn.from(a?t.create():null),d=new _n(Rn.from(t.create(null,Rn.from(n.create(null,c)))),a?3:1,0),u=i.start,h=i.end;return e.step(new Jo(u-(a?3:1),h,u,h,d,1,!0)).scrollIntoView(),!0}(t,e.pmSchema.nodes.blockContainer,e.pmSchema.nodes.blockGroup))}function oE(e){const t=Bw(e);let n=e.selection.$from,o=e.selection.$to;for(;o.parentOffset>=o.parent.nodeSize-2&&o.depth>0;)o=e.doc.resolve(o.pos+1);for(;0===o.parentOffset&&o.depth>0;)o=e.doc.resolve(o.pos-1);for(;0===n.parentOffset&&n.depth>0;)n=e.doc.resolve(n.pos-1);for(;n.parentOffset>=n.parent.nodeSize-2&&n.depth>0;)n=e.doc.resolve(n.pos+1);const r=function(e,t,n=$w(t),o=zw(t),r=Fw(t),i=Uw(t)){if(0===e.content.childCount)return{blocks:[],blockCutAtStart:void 0,blockCutAtEnd:void 0};if(1!==e.content.childCount)throw new Error("slice must be a single block, did you forget includeParents=true?");return function e(s,l,a){if("blockGroup"!==s.type.name)throw new Error("unexpected");const c=[];let d,u;return s.forEach((h,p,f)=>{if("blockContainer"!==h.type.name)throw new Error("unexpected");if(0===h.childCount)return;if(0===h.childCount||h.childCount>2)throw new Error("unexpected, blockContainer.childCount: "+h.childCount);const m=0===f,g=f===s.childCount-1;if("blockGroup"===h.firstChild.type.name){if(!m)throw new Error("unexpected");const t=e(h.firstChild,Math.max(0,l-1),g?Math.max(0,a-1):0);return d=t.blockCutAtStart,g&&(u=t.blockCutAtEnd),void c.push(...t.blocks)}const y=Gw(h,t,n,o,r,i),b=h.childCount>1?h.child(1):void 0;let v=[];if(b){const t=e(b,0,g?Math.max(0,a-1):0);v=t.blocks,g&&(u=t.blockCutAtEnd)}g&&!b&&a>1&&(u=y.id),m&&l>1&&(d=y.id),c.push({...y,children:v})}),{blocks:c,blockCutAtStart:d,blockCutAtEnd:u}}(e.content.firstChild,Math.max(e.openStart-1,0),Math.max(e.openEnd-1,0))}(e.doc.slice(n.pos,o.pos,!0),t);return{_meta:{startPos:n.pos,endPos:o.pos},...r}}function rE(e,t,n="start"){const o="string"==typeof t?t:t.id,r=Vw(Bw(e.doc)),i=fk(o,e.doc);if(!i)throw new Error(`Block with ID ${o} not found`);const s=Pw(i),l=r.blockSchema[s.blockNoteType].content;if(s.isBlockContainer){const t=s.blockContent;if("none"===l)return void e.setSelection(Or.create(e.doc,t.beforePos));if("inline"===l)"start"===n?e.setSelection(Nr.create(e.doc,t.beforePos+1)):e.setSelection(Nr.create(e.doc,t.afterPos-1));else{if("table"!==l)throw new uw(l);"start"===n?e.setSelection(Nr.create(e.doc,t.beforePos+4)):e.setSelection(Nr.create(e.doc,t.afterPos-4))}}else{rE(e,("start"===n?s.childContainer.node.firstChild:s.childContainer.node.lastChild).attrs.id,n)}}let iE;async function sE(){if(iE)return iE;const e=await Promise.all([Promise.resolve().then(()=>require("./index-jr5i21r1.cjs")),Promise.resolve().then(()=>require("./index-BcePyLfy.cjs")),Promise.resolve().then(()=>require("./index-DaVkrct-.cjs")),Promise.resolve().then(()=>require("./index-BjVIOIdk.cjs")),Promise.resolve().then(()=>require("./index-DL_ocleL.cjs")),Promise.resolve().then(()=>require("./index-CFCSEDxn.cjs")),Promise.resolve().then(()=>require("./index-Dift2gpr.cjs")),Promise.resolve().then(()=>require("./index-CMmMjajZ.cjs")),Promise.resolve().then(()=>require("./index-KDG7mz5O.cjs")),Promise.resolve().then(()=>require("./index-BdHsAk36.cjs"))]);return iE={rehypeParse:e[0],rehypeStringify:e[1],unified:e[2],hastUtilFromDom:e[3],rehypeRemark:e[4],remarkGfm:e[5],remarkStringify:e[6],remarkParse:e[7],remarkRehype:e[8],rehypeFormat:e[9]},iE}function lE(){const e=t=>{let n=t.children.length;for(let o=0;o<n;o++){const r=t.children[o];if("element"===r.type&&(e(r),"u"===r.tagName))if(r.children.length>0){t.children.splice(o,1,...r.children);const e=r.children.length-1;n+=e,o+=e}else t.children.splice(o,1),n--,o--}};return e}function aE(){const e=iE;if(!e)throw new Error("addSpacesToCheckboxes requires ESM dependencies to be initialized");const t=n=>{var o;if(n.children&&"length"in n.children&&n.children.length)for(let r=n.children.length-1;r>=0;r--){const i=n.children[r],s=r+1<n.children.length?n.children[r+1]:void 0;"element"===i.type&&"input"===i.tagName&&"checkbox"===(null==(o=i.properties)?void 0:o.type)&&"element"===(null==s?void 0:s.type)&&"p"===s.tagName?(s.tagName="span",s.children.splice(0,0,e.hastUtilFromDom.fromDom(document.createTextNode(" ")))):t(i)}};return t}function cE(e){const t=iE;if(!t)throw new Error("cleanHTMLToMarkdown requires ESM dependencies to be initialized");return t.unified.unified().use(t.rehypeParse.default,{fragment:!0}).use(lE).use(aE).use(t.rehypeRemark.default).use(t.remarkGfm.default).use(t.remarkStringify.default,{handlers:{text:e=>e.value}}).processSync(e).value}function dE(e){e.querySelectorAll("li > ul, li > ol").forEach(e=>{const t=function(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}(e),n=e.parentElement,o=Array.from(n.childNodes).slice(t+1);e.remove(),o.forEach(e=>{e.remove()}),n.insertAdjacentElement("afterend",e),o.reverse().forEach(t=>{if(function(e){return 3===e.nodeType&&!/\S/.test(e.nodeValue||"")}(t))return;const n=document.createElement("li");n.append(t),e.insertAdjacentElement("afterend",n)}),0===n.childNodes.length&&n.remove()})}GC.create({blockSpecs:{pageBreak:KC}});let uE=null;function hE(e){if("string"==typeof e){const t=(uE||(uE=document.implementation.createHTMLDocument("title"))).createElement("div");t.innerHTML=e,e=t}return dE(e),function(e){e.querySelectorAll("li + ul, li + ol").forEach(e=>{var t,n;const o=e.previousElementSibling,r=document.createElement("div");o.insertAdjacentElement("afterend",r),r.append(o);const i=document.createElement("div");for(i.setAttribute("data-node-type","blockGroup"),r.append(i);"UL"===(null==(t=r.nextElementSibling)?void 0:t.nodeName)||"OL"===(null==(n=r.nextElementSibling)?void 0:n.nodeName);)i.append(r.nextElementSibling)})}(e),e}async function pE(e,t){const n=hE(e),o=vo.fromSchema(t).parse(n,{topNode:t.nodes.blockGroup.create()}),r=[];for(let i=0;i<o.childCount;i++)r.push(Gw(o.child(i),t));return r}function fE(e,t){const n=t.value?t.value:"",o={};t.lang&&(o["data-language"]=t.lang);let r={type:"element",tagName:"code",properties:o,children:[{type:"text",value:n}]};return t.meta&&(r.data={meta:t.meta}),e.patch(t,r),r=e.applyData(t,r),r={type:"element",tagName:"pre",properties:{},children:[r]},e.patch(t,r),r}async function mE(e){const t=await sE();return t.unified.unified().use(t.remarkParse.default).use(t.remarkGfm.default).use(t.remarkRehype.default,{handlers:{...t.remarkRehype.defaultHandlers,code:fE}}).use(t.rehypeStringify.default).processSync(e).value}const gE=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function yE(e,t){if(!e.startsWith(".")||!t.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return e===t}function bE(e,t){const n=e.split("/"),o=t.split("/");if(2!==n.length)throw new Error(`The string ${e} is not a valid MIME type.`);if(2!==o.length)throw new Error(`The string ${t} is not a valid MIME type.`);return"*"===n[1]||"*"===o[1]?n[0]===o[0]:("*"===n[0]||"*"===o[0]||n[0]===o[0])&&n[1]===o[1]}function vE(e,t,n,o="after"){let r;return r=Array.isArray(t.content)&&0===t.content.length?e.updateBlock(t,n).id:e.insertBlocks([n],t,o)[0].id,r}async function xE(e,t){var n;if(!t.uploadFile)return;const o="dataTransfer"in e?e.dataTransfer:e.clipboardData;if(null===o)return;let r=null;for(const l of gE)if(o.types.includes(l)){r=l;break}if("Files"!==r)return;const i=o.items;if(!i)return;e.preventDefault();const s=Object.values(t.schema.blockSchema).filter(e=>e.isFileBlock);for(let l=0;l<i.length;l++){let o="file";for(const e of s)for(const t of e.fileBlockAccept||[]){const n=t.startsWith("."),r=i[l].getAsFile();if(r&&(!n&&r.type&&bE(i[l].type,t)||n&&yE("."+r.name.split(".").pop(),t))){o=e.type;break}}const r=i[l].getAsFile();if(r){const i={type:o,props:{name:r.name}};let s;if("paste"===e.type){const e=t.getTextCursorPosition().block;s=vE(t,e,i)}else{if("drop"!==e.type)return;{const o={left:e.clientX,top:e.clientY},r=null==(n=t.prosemirrorView)?void 0:n.posAtCoords(o);if(!r)return;s=t.transact(e=>{var n;const s=Ow(e.doc,r.pos),l=null==(n=t.prosemirrorView)?void 0:n.dom.querySelector(`[data-id="${s.node.attrs.id}"]`),a=null==l?void 0:l.getBoundingClientRect();return vE(t,t.getBlock(s.node.attrs.id),i,a&&(a.top+a.bottom)/2>o.top?"before":"after")})}}const l=await t.uploadFile(r,s),a="string"==typeof l?{props:{url:l}}:{...l};t.updateBlock(s,a)}}}const wE=e=>kc.create({name:"dropFile",addProseMirrorPlugins:()=>[new Wr({props:{handleDOMEvents:{drop(t,n){if(!e.isEditable)return;let o=null;for(const e of gE)if(n.dataTransfer.types.includes(e)){o=e;break}return null===o||"Files"===o&&(xE(n,e),!0)}}}})]}),kE=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,CE=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,EE=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,SE=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,ME=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,RE=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,TE=/\n{2} {0,3}-{2,48}\n{2}/,jE=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,NE=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,AE=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,OE=/^\s*\|(.+\|)+\s*$/m,_E=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,PE=/^\s*\|(.+\|)+\s*$/m;function IE({event:e,editor:t,prioritizeMarkdownOverHTML:n,plainTextAsMarkdown:o}){var r;if(t.transact(e=>e.selection.$from.parent.type.spec.code&&e.selection.$to.parent.type.spec.code)){const n=null==(r=e.clipboardData)?void 0:r.getData("text/plain");if(n)return t.pasteText(n),!0}let i;for(const l of gE)if(e.clipboardData.types.includes(l)){i=l;break}if(!i)return!0;if("vscode-editor-data"===i)return async function(e,t){const{schema:n}=t.state;if(!e.clipboardData)return!1;const o=e.clipboardData.getData("text/plain");if(!o)return!1;if(!n.nodes.codeBlock)return t.pasteText(o),!0;const r=e.clipboardData.getData("vscode-editor-data"),i=r?JSON.parse(r):void 0,s=null==i?void 0:i.mode;!!s&&t.pasteHTML(`<pre><code class="language-${s}">${o.replace(/\r\n?/g,"\n")}</code></pre>`)}(e,t.prosemirrorView),!0;if("Files"===i)return xE(e,t),!0;const s=e.clipboardData.getData(i);if("blocknote/html"===i)return t.pasteHTML(s,!0),!0;if("text/markdown"===i)return t.pasteMarkdown(s),!0;if(n){const n=e.clipboardData.getData("text/plain");if((e=>kE.test(e)||CE.test(e)||EE.test(e)||SE.test(e)||ME.test(e)||RE.test(e)||TE.test(e)||jE.test(e)||NE.test(e)||AE.test(e)||OE.test(e)||_E.test(e)||PE.test(e))(n))return t.pasteMarkdown(n),!0}return"text/html"===i?(t.pasteHTML(s),!0):o?(t.pasteMarkdown(s),!0):(t.pasteText(s),!0)}const LE=(e,t)=>kc.create({name:"pasteFromClipboard",addProseMirrorPlugins:()=>[new Wr({props:{handleDOMEvents:{paste(n,o){if(o.preventDefault(),e.isEditable)return t({event:o,editor:e,defaultPasteHandler:({prioritizeMarkdownOverHTML:t=!0,plainTextAsMarkdown:n=!0}={})=>IE({event:o,editor:e,prioritizeMarkdownOverHTML:t,plainTextAsMarkdown:n})})}}}})]});function DE(e){const t=[];return e.descendants(e=>{var n,o;const r=Bw(e);return"blockContainer"===e.type.name&&"blockGroup"===(null==(n=e.firstChild)?void 0:n.type.name)||("columnList"===e.type.name&&1===e.childCount?(null==(o=e.firstChild)||o.forEach(e=>{t.push(Gw(e,r))}),!1):!e.type.isInGroup("bnBlock")||(t.push(Gw(e,r)),!1))}),t}function BE(e,t){"node"in e.state.selection&&"blockContent"===e.state.selection.node.type.spec.group&&t.transact(t=>t.setSelection(new Or(t.doc.resolve(e.state.selection.from-1))));const n=e.serializeForClipboard(e.state.selection.content()).dom.innerHTML,o=e.state.selection.content().content,r=function(e,t,n){var o;let r=!1;const i=e.state.selection instanceof Gd;if(!i){const n=e.state.doc.slice(e.state.selection.from,e.state.selection.to,!1).content,o=[];for(let e=0;e<n.childCount;e++)o.push(n.child(e));r=void 0===o.find(e=>e.type.isInGroup("bnBlock")||"blockGroup"===e.type.name||"blockContent"===e.type.spec.group),r&&(t=n)}let s;const l=Ek(e.state.schema,n);if(i){"table"===(null==(o=t.firstChild)?void 0:o.type.name)&&(t=t.firstChild.content);const e=Ww(t,n.schema.inlineContentSchema,n.schema.styleSchema);s=`<table>${l.exportInlineContent(e,{})}</table>`}else if(r){const e=qw(t,n.schema.inlineContentSchema,n.schema.styleSchema);s=l.exportInlineContent(e,{})}else{const e=DE(t);s=l.exportBlocks(e,{})}return s}(e,o,t);return{clipboardHTML:n,externalHTML:r,markdown:cE(r)}}const HE=()=>{const e=window.getSelection();if(!e||e.isCollapsed)return!0;let t=e.focusNode;for(;t;){if(t instanceof HTMLElement&&"false"===t.getAttribute("contenteditable"))return!0;t=t.parentElement}return!1},VE=(e,t,n)=>{n.preventDefault(),n.clipboardData.clearData();const{clipboardHTML:o,externalHTML:r,markdown:i}=BE(t,e);n.clipboardData.setData("blocknote/html",o),n.clipboardData.setData("text/html",r),n.clipboardData.setData("text/plain",i)},$E=e=>kc.create({name:"copyToClipboard",addProseMirrorPlugins:()=>(sE(),[new Wr({props:{handleDOMEvents:{copy:(t,n)=>(HE()||VE(e,t,n),!0),cut:(t,n)=>(HE()||(VE(e,t,n),t.editable&&t.dispatch(t.state.tr.deleteSelection())),!0),dragstart(t,n){if(!("node"in t.state.selection)||"blockContent"!==t.state.selection.node.type.spec.group)return;e.transact(e=>e.setSelection(new Or(e.doc.resolve(t.state.selection.from-1)))),n.preventDefault(),n.dataTransfer.clearData();const{clipboardHTML:o,externalHTML:r,markdown:i}=BE(t,e);return n.dataTransfer.setData("blocknote/html",o),n.dataTransfer.setData("text/html",r),n.dataTransfer.setData("text/plain",i),!0}}}})])}),zE=kc.create({name:"blockBackgroundColor",addGlobalAttributes:()=>[{types:["blockContainer","tableCell","tableHeader"],attributes:{backgroundColor:{default:bw.backgroundColor.default,parseHTML:e=>e.hasAttribute("data-background-color")?e.getAttribute("data-background-color"):bw.backgroundColor.default,renderHTML:e=>e.backgroundColor===bw.backgroundColor.default?{}:{"data-background-color":e.backgroundColor}}}}]});class FE{constructor(){ew(this,"callbacks",{})}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),()=>this.off(e,t)}emit(e,...t){const n=this.callbacks[e];n&&n.forEach(e=>e.apply(this,t))}off(e,t){const n=this.callbacks[e];n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e])}removeAllListeners(){this.callbacks={}}}let UE=class extends FE{constructor(...e){super(),ew(this,"plugins",[])}static key(){throw new Error("You must implement the key method in your extension")}addProsemirrorPlugin(e){this.plugins.push(e)}get priority(){}};class WE extends UE{constructor(){super(),ew(this,"beforeChangeCallbacks",[]),this.addProsemirrorPlugin(new Wr({filterTransaction:e=>{let t;return this.beforeChangeCallbacks.reduce((n,o)=>!1===n?n:!1!==o({getChanges:()=>t||(t=jk(e),t),tr:e}),!0)}}))}static key(){return"blockChange"}subscribe(e){return this.beforeChangeCallbacks.push(e),()=>{this.beforeChangeCallbacks=this.beforeChangeCallbacks.filter(t=>t!==e)}}}const qE=class e extends UE{constructor(t){super(),ew(this,"provider"),ew(this,"recentlyUpdatedCursors"),ew(this,"renderCursor",(t,n)=>{let o=this.recentlyUpdatedCursors.get(n);if(!o){const r=(this.collaboration.renderCursor??e.defaultCursorRender)(t);"always"!==this.collaboration.showCursorLabels&&(r.addEventListener("mouseenter",()=>{const e=this.recentlyUpdatedCursors.get(n);e.element.setAttribute("data-active",""),e.hideTimeout&&(clearTimeout(e.hideTimeout),this.recentlyUpdatedCursors.set(n,{element:e.element,hideTimeout:void 0}))}),r.addEventListener("mouseleave",()=>{const e=this.recentlyUpdatedCursors.get(n);this.recentlyUpdatedCursors.set(n,{element:e.element,hideTimeout:setTimeout(()=>{e.element.removeAttribute("data-active")},2e3)})})),o={element:r,hideTimeout:void 0},this.recentlyUpdatedCursors.set(n,o)}return o.element}),ew(this,"updateUser",e=>{this.provider.awareness.setLocalStateField("user",e)}),this.collaboration=t,this.provider=t.provider,this.recentlyUpdatedCursors=new Map,this.provider.awareness.setLocalStateField("user",t.user),"always"!==t.showCursorLabels&&this.provider.awareness.on("change",({updated:e})=>{for(const t of e){const e=this.recentlyUpdatedCursors.get(t);e&&(e.element.setAttribute("data-active",""),e.hideTimeout&&clearTimeout(e.hideTimeout),this.recentlyUpdatedCursors.set(t,{element:e.element,hideTimeout:setTimeout(()=>{e.element.removeAttribute("data-active")},2e3)}))}}),this.addProsemirrorPlugin(Wx(this.provider.awareness,{selectionBuilder:zx,cursorBuilder:this.renderCursor}))}static key(){return"yCursorPlugin"}get priority(){return 999}static isDarkColor(e){const t="#"===e.charAt(0)?e.substring(1,7):e,n=[parseInt(t.substring(0,2),16)/255,parseInt(t.substring(2,4),16)/255,parseInt(t.substring(4,6),16)/255].map(e=>e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4));return.2126*n[0]+.7152*n[1]+.0722*n[2]<=.179}};ew(qE,"defaultCursorRender",e=>{const t=document.createElement("span");t.classList.add("bn-collaboration-cursor__base");const n=document.createElement("span");n.setAttribute("contentedEditable","false"),n.classList.add("bn-collaboration-cursor__caret"),n.setAttribute("style",`background-color: ${e.color}; color: ${qE.isDarkColor(e.color)?"white":"black"}`);const o=document.createElement("span");return o.classList.add("bn-collaboration-cursor__label"),o.setAttribute("style",`background-color: ${e.color}; color: ${qE.isDarkColor(e.color)?"white":"black"}`),o.insertBefore(document.createTextNode(e.name),null),n.insertBefore(o,null),t.insertBefore(document.createTextNode("⁠"),null),t.insertBefore(n,null),t.insertBefore(document.createTextNode("⁠"),null),t});let GE=qE,KE=class extends UE{static key(){return"ySyncPlugin"}constructor(e){super(),this.addProsemirrorPlugin(((e,{colors:t=px,colorMapping:n=new Map,permanentUserData:o=null,onFirstRender:r=()=>{},mapping:i}={})=>{let s=!1;const l=new gx(e,i),a=new Wr({props:{editable:e=>{const t=ex.getState(e);return null==t.snapshot&&null==t.prevSnapshot}},key:ex,state:{init:(r,i)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:o}),apply:(e,t)=>{const n=e.getMeta(ex);if(void 0!==n){t=Object.assign({},t);for(const e in n)t[e]=n[e]}return t.addToHistory=!1!==e.getMeta("addToHistory"),t.isChangeOrigin=void 0!==n&&!!n.isChangeOrigin,t.isUndoRedoOperation=void 0!==n&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,null!==l.prosemirrorView&&(void 0===n||null==n.snapshot&&null==n.prevSnapshot||jg(0,()=>{null!=l.prosemirrorView&&(null==n.restore?l._renderSnapshot(n.snapshot,n.prevSnapshot,t):(l._renderSnapshot(n.snapshot,n.snapshot,t),delete t.restore,delete t.snapshot,delete t.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))})),t}},view:e=>(l.initView(e),null==i&&l._forceRerender(),r(),{update:()=>{const t=a.getState(e.state);if(null==t.snapshot&&null==t.prevSnapshot&&(s||null!==e.state.doc.content.findDiffStart(e.state.doc.type.createAndFill().content))){if(s=!0,!1===t.addToHistory&&!t.isChangeOrigin){const t=tx.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}l.mux(()=>{t.doc.transact(n=>{n.meta.set("addToHistory",t.addToHistory),l._prosemirrorChanged(e.state.doc)},ex)})}},destroy:()=>{l.destroy()}})});return a})(e))}get priority(){return 1001}},ZE=class extends UE{static key(){return"yUndoPlugin"}constructor({editor:e}){super(),this.addProsemirrorPlugin(Zx({trackedOrigins:[e]}))}get priority(){return 1e3}};const JE=gc.create({name:"comment",excludes:"",inclusive:!1,keepOnSplit:!0,addAttributes:()=>({orphan:{parseHTML:e=>!!e.getAttribute("data-orphan"),renderHTML:e=>e.orphan?{"data-orphan":"true"}:{},default:!1},threadId:{parseHTML:e=>e.getAttribute("data-bn-thread-id"),renderHTML:e=>({"data-bn-thread-id":e.threadId}),default:""}}),renderHTML:({HTMLAttributes:e})=>["span",ec(e,{class:"bn-thread-mark"})],parseHTML:()=>[{tag:"span.bn-thread-mark"}],extendMarkSchema:e=>"comment"===e.name?{blocknoteIgnore:!0}:{}});class XE extends FE{constructor(e){super(),ew(this,"userCache",new Map),ew(this,"loadingUsers",new Set),this.resolveUsers=e}async loadUsers(e){const t=e.filter(e=>!this.userCache.has(e)&&!this.loadingUsers.has(e));if(0!==t.length){for(const e of t)this.loadingUsers.add(e);try{const e=await this.resolveUsers(t);for(const t of e)this.userCache.set(t.id,t);this.emit("update",this.userCache)}finally{for(const e of t)this.loadingUsers.delete(e)}}}getUser(e){return this.userCache.get(e)}subscribe(e){return this.on("update",e)}}const YE=new Kr("blocknote-comments");class QE extends UE{constructor(e,t,n){if(super(),ew(this,"userStore"),ew(this,"pendingComment",!1),ew(this,"selectedThreadId"),ew(this,"threadPositions",new Map),ew(this,"updateMarksFromThreads",e=>{this.editor.transact(t=>{t.doc.descendants((n,o)=>{n.marks.forEach(r=>{if(r.type.name===this.markType){const i=r.type,s=r.attrs.threadId,l=e.get(s),a=!(l&&!l.resolved&&!l.deletedAt);if(a!==r.attrs.orphan){const e=Math.max(o,0),l=Math.min(o+n.nodeSize,t.doc.content.size-1,t.doc.content.size-1);t.removeMark(e,l,r),t.addMark(e,l,i.create({...r.attrs,orphan:a})),a&&this.selectedThreadId===s&&(this.selectedThreadId=void 0,this.emitStateUpdate())}}})})})}),this.editor=e,this.threadStore=t,this.markType=n,!e.resolveUsers)throw new Error("resolveUsers is required for comments");this.userStore=new XE(e.resolveUsers),this.threadStore.subscribe(this.updateMarksFromThreads),e.onCreate(()=>{this.updateMarksFromThreads(this.threadStore.getThreads()),e.onSelectionChange(()=>{this.pendingComment&&(this.pendingComment=!1,this.emitStateUpdate())})});const o=this;this.addProsemirrorPlugin(new Wr({key:YE,state:{init:()=>({decorations:Il.empty}),apply(e,t){const n=e.getMeta(YE);if(!e.docChanged&&!n)return t;const r=e.docChanged?function(e,t){const n=new Map;return e.descendants((e,o)=>{e.marks.forEach(r=>{if(r.type.name===t){const t=r.attrs.threadId;if(!t)return;const i=o,s=i+e.nodeSize,l=n.get(t)??{from:1/0,to:0};n.set(t,{from:Math.min(i,l.from),to:Math.max(s,l.to)})}})}),n}(e.doc,o.markType):o.threadPositions;(r.size>0||o.threadPositions.size>0)&&(o.threadPositions=r,o.emitStateUpdate());const i=[];if(o.selectedThreadId){const e=r.get(o.selectedThreadId);e&&i.push(Ol.inline(e.from,e.to,{class:"bn-thread-mark-selected"}))}return{decorations:Il.create(e.doc,i)}}},props:{decorations(e){var t;return(null==(t=YE.getState(e))?void 0:t.decorations)??Il.empty},handleClick:(e,t,r)=>{if(0!==r.button)return;const i=e.state.doc.nodeAt(t);if(!i)return void o.selectThread(void 0);const s=i.marks.find(e=>e.type.name===n&&!0!==e.attrs.orphan),l=null==s?void 0:s.attrs.threadId;o.selectThread(l,!1)}}}))}static key(){return"comments"}emitStateUpdate(){this.emit("update",{selectedThreadId:this.selectedThreadId,pendingComment:this.pendingComment,threadPositions:this.threadPositions})}onUpdate(e){return this.on("update",e)}selectThread(e,t=!0){var n,o;if(this.selectedThreadId!==e&&(this.selectedThreadId=e,this.emitStateUpdate(),this.editor.transact(e=>e.setMeta(YE,{name:"SET_SELECTED_THREAD_ID"})),e&&t)){const t=this.threadPositions.get(e);if(!t)return;null==(o=null==(n=this.editor.prosemirrorView)?void 0:n.domAtPos(t.from).node)||o.scrollIntoView({behavior:"smooth",block:"center"})}}startPendingComment(){this.pendingComment=!0,this.emitStateUpdate()}stopPendingComment(){this.pendingComment=!1,this.emitStateUpdate()}async createThread(e){const t=await this.threadStore.createThread(e);if(this.threadStore.addThreadToDocument){const e=this.editor.prosemirrorView,n=e.state.selection,o=ex.getState(e.state),r={prosemirror:{head:n.head,anchor:n.anchor},yjs:o?mx(o.binding,e.state):void 0};await this.threadStore.addThreadToDocument({threadId:t.id,selection:r})}else this.editor._tiptapEditor.commands.setMark(this.markType,{orphan:!1,threadId:t.id})}}class eS{constructor(e,t,n,o){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"mouseDownHandler",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"dragstartHandler",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"scrollHandler",()=>{var e;if(null!=(e=this.state)&&e.show){const e=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`);if(!e)return;this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate()}}),ew(this,"closeMenu",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),this.editor=e,this.pluginKey=t,this.pmView=n,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized file panel");o(this.state)},n.dom.addEventListener("mousedown",this.mouseDownHandler),n.dom.addEventListener("dragstart",this.dragstartHandler),n.root.addEventListener("scroll",this.scrollHandler,!0)}update(e,t){var n,o;const r=this.pluginKey.getState(e.state),i=this.pluginKey.getState(t);if((null==(n=this.state)||!n.show)&&null!=r&&r.block&&this.editor.isEditable){const e=this.pmView.root.querySelector(`[data-node-type="blockContainer"][data-id="${r.block.id}"]`);if(!e)return;return this.state={show:!0,referencePos:e.getBoundingClientRect(),block:r.block},void this.emitUpdate()}const s=(null==r?void 0:r.block)&&!(null!=i&&i.block),l=!(null!=r&&r.block)&&(null==i?void 0:i.block);s&&this.state&&!this.state.show&&(this.state.show=!0,this.emitUpdate()),l&&null!=(o=this.state)&&o.show&&(this.state.show=!1,this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}}const tS=new Kr("FilePanelPlugin");class nS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"closeMenu",()=>{var e;return null==(e=this.view)?void 0:e.closeMenu()}),this.addProsemirrorPlugin(new Wr({key:tS,view:t=>(this.view=new eS(e,tS,t,e=>{this.emit("update",e)}),this.view),props:{handleKeyDown:(e,t)=>{var n;return!("Escape"!==t.key||!this.shown)&&(null==(n=this.view)||n.closeMenu(),!0)}},state:{init:()=>({block:void 0}),apply:(e,t)=>e.getMeta(tS)||(e.getMeta(ex)||!e.selectionSet&&!e.docChanged?t:{block:void 0})}}))}static key(){return"filePanel"}get shown(){var e,t;return(null==(t=null==(e=this.view)?void 0:e.state)?void 0:t.show)||!1}onUpdate(e){return this.on("update",e)}}class oS{constructor(e,t,n){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"preventHide",!1),ew(this,"preventShow",!1),ew(this,"shouldShow",({view:e,state:t,from:n,to:o})=>{const{doc:r,selection:i}=t,{empty:s}=i,l=!r.textBetween(n,o).length&&Ac(t.selection);if(i.$from.parent.type.spec.code||rd(i)&&i.node.type.spec.code||s||l)return!1;const a=document.activeElement;return!(!this.isElementWithinEditorWrapper(a)&&e.editable)}),ew(this,"blurHandler",e=>{var t;if(this.preventHide)return void(this.preventHide=!1);const n=this.pmView.dom.parentElement;e&&e.relatedTarget&&(n===e.relatedTarget||n.contains(e.relatedTarget)||e.relatedTarget.matches(".bn-ui-container, .bn-ui-container *"))||null!=(t=this.state)&&t.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"isElementWithinEditorWrapper",e=>{if(!e)return!1;const t=this.pmView.dom.parentElement;return!!t&&t.contains(e)}),ew(this,"viewMousedownHandler",e=>{(!this.isElementWithinEditorWrapper(e.target)||0===e.button)&&(this.preventShow=!0)}),ew(this,"mouseupHandler",()=>{this.preventShow&&(this.preventShow=!1,setTimeout(()=>this.update(this.pmView)))}),ew(this,"dragHandler",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"scrollHandler",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.referencePos=this.getSelectionBoundingBox(),this.emitUpdate())}),ew(this,"closeMenu",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized formatting toolbar");n(this.state)},t.dom.addEventListener("mousedown",this.viewMousedownHandler),t.root.addEventListener("mouseup",this.mouseupHandler),t.dom.addEventListener("dragstart",this.dragHandler),t.dom.addEventListener("dragover",this.dragHandler),t.dom.addEventListener("blur",this.blurHandler),t.root.addEventListener("scroll",this.scrollHandler,!0)}update(e,t){var n,o,r;const{state:i,composing:s}=e,{doc:l,selection:a}=i,c=t&&t.doc.eq(l)&&t.selection.eq(a);if(s||c)return;const{ranges:d}=a,u=Math.min(...d.map(e=>e.$from.pos)),h=Math.max(...d.map(e=>e.$to.pos)),p=this.shouldShow({view:e,state:i,from:u,to:h}),f=typeof Range.prototype.getClientRects>"u";if(!this.preventShow&&(p||this.preventHide)&&!f){const t=this.getSelectionBoundingBox();if(0===t.height&&0===t.width)return void queueMicrotask(()=>{const t={show:!0,referencePos:this.getSelectionBoundingBox()};this.state=t,this.emitUpdate(),e.dispatch(e.state.tr.setSelection(Nr.create(e.state.doc,e.state.selection.from+1,e.state.selection.to))),e.dispatch(e.state.tr.setSelection(Nr.create(e.state.doc,e.state.selection.from-1,e.state.selection.to)))});const r={show:!0,referencePos:this.getSelectionBoundingBox()};return void((r.show!==(null==(n=this.state)?void 0:n.show)||r.referencePos.toJSON()!==(null==(o=this.state)?void 0:o.referencePos.toJSON()))&&(this.state=r,this.emitUpdate()))}return null==(r=this.state)||!r.show||this.preventHide||p&&!this.preventShow&&this.editor.isEditable?void 0:(this.state.show=!1,void this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("mouseup",this.mouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragHandler),this.pmView.dom.removeEventListener("dragover",this.dragHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0)}getSelectionBoundingBox(){const{state:e}=this.pmView,{selection:t}=e,{ranges:n}=t,o=Math.min(...n.map(e=>e.$from.pos)),r=Math.max(...n.map(e=>e.$to.pos));if(rd(t)){const e=this.pmView.nodeDOM(o);if(e)return e.getBoundingClientRect()}return id(this.pmView,o,r)}}const rS=new Kr("FormattingToolbarPlugin");class iS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"closeMenu",()=>this.view.closeMenu()),this.addProsemirrorPlugin(new Wr({key:rS,view:t=>(this.view=new oS(e,t,e=>{this.emit("update",e)}),this.view),props:{handleKeyDown:(e,t)=>!("Escape"!==t.key||!this.shown)&&(this.view.closeMenu(),!0)}}))}static key(){return"formattingToolbar"}get shown(){var e,t;return(null==(t=null==(e=this.view)?void 0:e.state)?void 0:t.show)||!1}onUpdate(e){return this.on("update",e)}}const sS=kd.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML:()=>[{tag:"br"}],renderHTML({HTMLAttributes:e}){return["br",ec(this.options.HTMLAttributes,e)]},renderText:()=>"\n"}),lS=(e,t)=>{const n=e.resolve(t);if(n.depth<=1)return;const o=n.posAtIndex(n.index(n.depth-1),n.depth-1);return Iw(e.resolve(o))},aS=(e,t)=>{const n=e.resolve(t),o=n.index();if(0===o)return;const r=n.posAtIndex(o-1);return Iw(e.resolve(r))},cS=(e,t)=>{for(;t.childContainer;){const n=t.childContainer.node,o=e.resolve(t.childContainer.beforePos+1).posAtIndex(n.childCount-1);t=Iw(e.resolve(o))}return t},dS=e=>({state:t,dispatch:n})=>{const o=Iw(t.doc.resolve(e)),r=aS(t.doc,o.bnBlock.beforePos);if(!r)return!1;const i=cS(t.doc,r);return!!((e,t)=>e.isBlockContainer&&"inline*"===e.blockContent.node.type.spec.content&&e.blockContent.node.childCount>0&&t.isBlockContainer&&"inline*"===t.blockContent.node.type.spec.content)(i,o)&&((e,t,n,o)=>{if(!o.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but next block is not a block container`);if(o.childContainer){const n=e.doc.resolve(o.childContainer.beforePos+1),r=e.doc.resolve(o.childContainer.afterPos-1),i=n.blockRange(r);if(t){const t=e.doc.resolve(o.bnBlock.beforePos);e.tr.lift(i,t.depth)}}if(t){if(!n.isBlockContainer)throw new Error(`Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but previous block is not a block container`);t(e.tr.delete(n.blockContent.afterPos-1,o.blockContent.beforePos+1))}return!0})(t,n,i,o)},uS=kc.create({priority:50,addKeyboardShortcuts(){const e=(e=!1)=>this.editor.commands.first(({commands:t,tr:n})=>[()=>t.command(({state:e})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n,{depth:i}=e.doc.resolve(o.beforePos),s=0===e.selection.$anchor.parentOffset,l=e.selection.anchor===e.selection.head,a=0===r.node.childCount;return!!(s&&l&&a&&i>1)&&t.liftListItem("blockContainer")}),()=>t.command(({state:t})=>{const o=Lw(t),r=this.options.editor.schema.blockSchema[o.blockNoteType].hardBreakShortcut??"shift+enter";if("none"===r)return!1;if("shift+enter"===r&&e||"enter"===r){const e=n.storedMarks||n.selection.$head.marks().filter(e=>this.editor.extensionManager.splittableMarks.includes(e.type.name));return n.insert(n.selection.head,n.doc.type.schema.nodes.hardBreak.create()).ensureMarks(e),!0}return!1}),()=>t.command(({state:e,dispatch:t})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n,i=0===e.selection.$anchor.parentOffset,s=e.selection.anchor===e.selection.head,l=0===r.node.childCount;if(i&&s&&l){const n=o.afterPos,r=n+2;if(t){const t=e.schema.nodes.blockContainer.createAndFill();e.tr.insert(n,t).scrollIntoView(),e.tr.setSelection(new Nr(e.doc.resolve(r)))}return!0}return!1}),()=>t.command(({state:e,chain:t})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const{blockContent:o}=n,r=0===e.selection.$anchor.parentOffset;return 0!==o.node.childCount&&(t().deleteSelection().command(iC(e.selection.from,r,r)).run(),!0)})]);return{Backspace:()=>this.editor.commands.first(({chain:e,commands:t})=>[()=>t.deleteSelection(),()=>t.undoInputRule(),()=>t.command(({state:e})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const o=e.selection.from===n.blockContent.beforePos+1,r="paragraph"===n.blockContent.node.type.name;return!(!o||r)&&t.command(yk(n.bnBlock.beforePos,{type:"paragraph",props:{}}))}),()=>t.command(({state:e})=>{const n=Lw(e);if(!n.isBlockContainer)return!1;const{blockContent:o}=n;return e.selection.from===o.beforePos+1&&t.liftListItem("blockContainer")}),()=>t.command(({state:t})=>{const n=Lw(t);if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r}=n,i=t.selection.from===r.beforePos+1,s=t.selection.empty,l=o.beforePos;return!(!i||!s)&&e().command(dS(l)).scrollIntoView().run()}),()=>t.command(({state:e,dispatch:t})=>{const n=Lw(e);if(!n.isBlockContainer||e.selection.from!==n.blockContent.beforePos+1||aS(e.doc,n.bnBlock.beforePos))return!1;const o=lS(e.doc,n.bnBlock.beforePos);if("column"!==(null==o?void 0:o.blockNoteType))return!1;const r=o,i=lS(e.doc,r.bnBlock.beforePos);if("columnList"!==(null==i?void 0:i.blockNoteType))throw new Error("parent of column is not a column list");const s=1===r.childContainer.node.childCount,l=s&&2===i.childContainer.node.childCount,a=i.childContainer.node.firstChild===r.bnBlock.node;if(t){const t=e.doc.slice(n.bnBlock.beforePos,n.bnBlock.afterPos,!1);if(l)if(a){e.tr.step(new Jo(i.bnBlock.beforePos,i.bnBlock.afterPos,r.bnBlock.afterPos+1,i.bnBlock.afterPos-2,t,t.size,!1));const n=e.tr.doc.resolve(r.bnBlock.beforePos);e.tr.setSelection(Nr.between(n,n))}else{e.tr.step(new Jo(i.bnBlock.beforePos,i.bnBlock.afterPos,i.bnBlock.beforePos+2,r.bnBlock.beforePos-1,t,0,!1));const n=e.tr.doc.resolve(e.tr.mapping.map(r.bnBlock.beforePos-1));e.tr.setSelection(Nr.between(n,n))}else if(s)if(a){e.tr.delete(r.bnBlock.beforePos,r.bnBlock.afterPos),e.tr.insert(i.bnBlock.beforePos,t.content);const n=e.tr.doc.resolve(i.bnBlock.beforePos);e.tr.setSelection(Nr.between(n,n))}else e.tr.delete(r.bnBlock.beforePos-1,r.bnBlock.beforePos+1);else{e.tr.delete(n.bnBlock.beforePos,n.bnBlock.afterPos),a?e.tr.insert(i.bnBlock.beforePos-1,t.content):e.tr.insert(r.bnBlock.beforePos-1,t.content);const o=e.tr.doc.resolve(r.bnBlock.beforePos-1);e.tr.setSelection(Nr.between(o,o))}}return!0}),()=>t.command(({state:t})=>{const n=Lw(t);if(!n.isBlockContainer)return!1;if(0===n.blockContent.node.childCount&&"inline*"===n.blockContent.node.type.spec.content){const o=aS(t.doc,n.bnBlock.beforePos);if(!o||!o.isBlockContainer)return!1;let r=e();if("tableRow+"===o.blockContent.node.type.spec.content){const e=n.bnBlock.beforePos-1-1-1-1-1;r=r.setTextSelection(e)}else if(""===o.blockContent.node.type.spec.content){const e=o.blockContent.afterPos-o.blockContent.node.nodeSize;r=r.setNodeSelection(e)}else{const e=o.blockContent.afterPos-o.blockContent.node.nodeSize;r=r.setTextSelection(e)}return r.deleteRange({from:n.bnBlock.beforePos,to:n.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>t.command(({state:t})=>{const n=Lw(t);if(!n.isBlockContainer)throw new Error("todo");const o=t.selection.from===n.blockContent.beforePos+1,r=t.selection.empty,i=aS(t.doc,n.bnBlock.beforePos);if(i&&o&&r){const o=cS(t.doc,i);if(!o.isBlockContainer)throw new Error("todo");if(""===o.blockContent.node.type.spec.content||"inline*"===o.blockContent.node.type.spec.content&&0===o.blockContent.node.childCount)return e().cut({from:n.bnBlock.beforePos,to:n.bnBlock.afterPos},o.bnBlock.afterPos).deleteRange({from:o.bnBlock.beforePos,to:o.bnBlock.afterPos}).run()}return!1})]),Delete:()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.command(({state:t})=>{const n=Lw(t);if(!n.isBlockContainer)return!1;const{bnBlock:o,blockContent:r,childContainer:i}=n,{depth:s}=t.doc.resolve(o.beforePos),l=o.afterPos===t.doc.nodeSize-3,a=t.selection.from===r.afterPos-1,c=t.selection.empty;if(!l&&a&&c&&void 0===i){let n=s,r=o.afterPos+1,i=t.doc.resolve(r).depth;for(;i<n;)n=i,r+=2,i=t.doc.resolve(r).depth;return e.command(dS(r-1))}return!1})]),Enter:()=>e(),"Shift-Enter":()=>e(!0),Tab:()=>{var e,t,n;return("prefer-indent"===this.options.tabBehavior||!(null!=(e=this.options.editor.formattingToolbar)&&e.shown||null!=(t=this.options.editor.linkToolbar)&&t.shown||null!=(n=this.options.editor.filePanel)&&n.shown))&&nE(this.options.editor)},"Shift-Tab":()=>{var e,t,n;return("prefer-indent"===this.options.tabBehavior||!(null!=(e=this.options.editor.formattingToolbar)&&e.shown||null!=(t=this.options.editor.linkToolbar)&&t.shown||null!=(n=this.options.editor.filePanel)&&n.shown))&&(this.editor.commands.liftListItem("blockContainer"),!0)},"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}});class hS{constructor(e,t,n){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"menuUpdateTimer"),ew(this,"startMenuUpdateTimer"),ew(this,"stopMenuUpdateTimer"),ew(this,"mouseHoveredLinkMark"),ew(this,"mouseHoveredLinkMarkRange"),ew(this,"keyboardHoveredLinkMark"),ew(this,"keyboardHoveredLinkMarkRange"),ew(this,"linkMark"),ew(this,"linkMarkRange"),ew(this,"mouseOverHandler",e=>{if(this.mouseHoveredLinkMark=void 0,this.mouseHoveredLinkMarkRange=void 0,this.stopMenuUpdateTimer(),e.target instanceof HTMLAnchorElement&&"A"===e.target.nodeName){const t=e.target,n=this.pmView.posAtDOM(t,0)+1,o=this.pmView.state.doc.resolve(n),r=o.marks();for(const e of r)if(e.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredLinkMark=e,this.mouseHoveredLinkMarkRange=jc(o,e.type,e.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1}),ew(this,"clickHandler",e=>{var t;const n=this.pmView.dom.parentElement;this.linkMark&&e&&e.target&&n!==e.target&&!n.contains(e.target)&&null!=(t=this.state)&&t.show&&(this.state.show=!1,this.emitUpdate())}),ew(this,"scrollHandler",()=>{var e;void 0!==this.linkMark&&null!=(e=this.state)&&e.show&&(this.state.referencePos=id(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),this.emitUpdate())}),ew(this,"closeMenu",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}),this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized link toolbar");n(this.state)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update(this.pmView,void 0,!0)},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),this.pmView.root.addEventListener("click",this.clickHandler,!0),this.pmView.root.addEventListener("scroll",this.scrollHandler,!0)}editLink(e,t){var n;this.editor.transact(n=>{const o=Bw(n);n.insertText(t,this.linkMarkRange.from,this.linkMarkRange.to),n.addMark(this.linkMarkRange.from,this.linkMarkRange.from+t.length,o.mark("link",{href:e}))}),this.pmView.focus(),null!=(n=this.state)&&n.show&&(this.state.show=!1,this.emitUpdate())}deleteLink(){var e;this.editor.transact(e=>e.removeMark(this.linkMarkRange.from,this.linkMarkRange.to,this.linkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate())}update(e,t,n=!1){var o;const{state:r}=e;if(t&&t.selection.from===r.selection.from&&t.selection.to===r.selection.to||!this.pmView.hasFocus())return;const i=this.linkMark;if(this.linkMark=void 0,this.linkMarkRange=void 0,this.keyboardHoveredLinkMark=void 0,this.keyboardHoveredLinkMarkRange=void 0,this.pmView.state.selection.empty){const e=this.pmView.state.selection.$from.marks();for(const t of e)if(t.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredLinkMark=t,this.keyboardHoveredLinkMarkRange=jc(this.pmView.state.selection.$from,t.type,t.attrs)||void 0;break}}return this.mouseHoveredLinkMark&&n&&(this.linkMark=this.mouseHoveredLinkMark,this.linkMarkRange=this.mouseHoveredLinkMarkRange),this.keyboardHoveredLinkMark&&(this.linkMark=this.keyboardHoveredLinkMark,this.linkMarkRange=this.keyboardHoveredLinkMarkRange),this.linkMark&&this.editor.isEditable?(this.state={show:!0,referencePos:id(this.pmView,this.linkMarkRange.from,this.linkMarkRange.to),url:this.linkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.linkMarkRange.from,this.linkMarkRange.to)},void this.emitUpdate()):null==(o=this.state)||!o.show||!i||this.linkMark&&this.editor.isEditable?void 0:(this.state.show=!1,void this.emitUpdate())}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),this.pmView.root.removeEventListener("scroll",this.scrollHandler,!0),this.pmView.root.removeEventListener("click",this.clickHandler,!0)}}const pS=new Kr("LinkToolbarPlugin");class fS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"editLink",(e,t)=>{this.view.editLink(e,t)}),ew(this,"deleteLink",()=>{this.view.deleteLink()}),ew(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()}),ew(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()}),ew(this,"closeMenu",()=>this.view.closeMenu()),this.addProsemirrorPlugin(new Wr({key:pS,view:t=>(this.view=new hS(e,t,e=>{this.emit("update",e)}),this.view),props:{handleKeyDown:(e,t)=>!("Escape"!==t.key||!this.shown)&&(this.view.closeMenu(),!0)}}))}static key(){return"linkToolbar"}onUpdate(e){return this.on("update",e)}get shown(){var e,t;return(null==(t=null==(e=this.view)?void 0:e.state)?void 0:t.show)||!1}}const mS=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"],gS="https",yS=new Kr("node-selection-keyboard");class bS extends UE{static key(){return"nodeSelectionKeyboard"}constructor(){super(),this.addProsemirrorPlugin(new Wr({key:yS,props:{handleKeyDown:(e,t)=>{if("node"in e.state.selection){if(t.ctrlKey||t.metaKey)return!1;if(1===t.key.length)return t.preventDefault(),!0;if(!("Enter"!==t.key||t.shiftKey||t.altKey||t.ctrlKey||t.metaKey)){const t=e.state.tr;return e.dispatch(t.insert(e.state.tr.selection.$to.after(),e.state.schema.nodes.paragraph.createChecked()).setSelection(new Nr(t.doc.resolve(e.state.tr.selection.$to.after()+1)))),!0}}return!1}}}))}}const vS=new Kr("blocknote-placeholder");class xS extends UE{static key(){return"placeholder"}constructor(e,t){super(),this.addProsemirrorPlugin(new Wr({key:vS,view:n=>{var o,r;const i=`placeholder-selector-${Pd()}`;n.dom.classList.add(i);const s=document.createElement("style"),l=e._tiptapEditor.options.injectNonce;l&&s.setAttribute("nonce",l),(null==(o=e.prosemirrorView)?void 0:o.root)instanceof ShadowRoot?e.prosemirrorView.root.append(s):null==(r=e.prosemirrorView)||r.root.head.appendChild(s);const a=s.sheet,c=(e="")=>`.${i} .bn-block-content${e} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;try{const{default:e,emptyDocument:n,...o}=t;for(const[t,s]of Object.entries(o)){const e=`[data-content-type="${t}"]`;a.insertRule(`${c(e)} { content: ${JSON.stringify(s)}; }`)}const r="[data-is-only-empty-block]",i="[data-is-empty-and-focused]";a.insertRule(`${c(r)} { content: ${JSON.stringify(n)}; }`),a.insertRule(`${c(i)} { content: ${JSON.stringify(e)}; }`)}catch(d){}return{destroy:()=>{var t,n;(null==(t=e.prosemirrorView)?void 0:t.root)instanceof ShadowRoot?e.prosemirrorView.root.removeChild(s):null==(n=e.prosemirrorView)||n.root.head.removeChild(s)}}},props:{decorations:t=>{const{doc:n,selection:o}=t;if(!e.isEditable||!o.empty||o.$from.parent.type.spec.code)return;const r=[];6===t.doc.content.size&&r.push(Ol.node(2,4,{"data-is-only-empty-block":"true"}));const i=o.$anchor,s=i.parent;if(0===s.content.size){const e=i.before();r.push(Ol.node(e,e+s.nodeSize,{"data-is-empty-and-focused":"true"}))}return Il.create(n,r)}}}))}}const wS=new Kr("previous-blocks"),kS={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"};class CS extends UE{static key(){return"previousBlockType"}constructor(){let e;super(),this.addProsemirrorPlugin(new Wr({key:wS,view(t){return{update:async(t,n)=>{var o;(null==(o=this.key)?void 0:o.getState(t.state).updatedBlocks.size)>0&&(e=setTimeout(()=>{t.dispatch(t.state.tr.setMeta(wS,{clearUpdate:!0}))},0))},destroy:()=>{e&&clearTimeout(e)}}},state:{init:()=>({prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}),apply(e,t,n,o){if(t.currentTransactionOldBlockAttrs={},t.updatedBlocks.clear(),!e.docChanged||n.doc.eq(o.doc))return t;const r={},i=Gc(n.doc,e=>e.attrs.id),s=new Map(i.map(e=>[e.node.attrs.id,e])),l=Gc(o.doc,e=>e.attrs.id);for(const a of l){const i=s.get(a.node.attrs.id),l=null==i?void 0:i.node.firstChild,c=a.node.firstChild;if(i&&l&&c){const s={index:c.attrs.index,level:c.attrs.level,type:c.type.name,depth:o.doc.resolve(a.pos).depth};let d={index:l.attrs.index,level:l.attrs.level,type:l.type.name,depth:n.doc.resolve(i.pos).depth};r[a.node.attrs.id]=d,e.getMeta("numberedListIndexing")&&(a.node.attrs.id in t.prevTransactionOldBlockAttrs&&(d=t.prevTransactionOldBlockAttrs[a.node.attrs.id]),"numberedListItem"===s.type&&(d.index=s.index)),t.currentTransactionOldBlockAttrs[a.node.attrs.id]=d,JSON.stringify(d)!==JSON.stringify(s)&&(d["depth-change"]=d.depth-s.depth,t.updatedBlocks.add(a.node.attrs.id))}}return t.prevTransactionOldBlockAttrs=r,t}},props:{decorations(e){const t=this.getState(e);if(0===t.updatedBlocks.size)return;const n=[];return e.doc.descendants((e,o)=>{if(!e.attrs.id||!t.updatedBlocks.has(e.attrs.id))return;const r=t.currentTransactionOldBlockAttrs[e.attrs.id],i={};for(const[t,n]of Object.entries(r))i["data-prev-"+kS[t]]=n||"none";const s=Ol.node(o,o+e.nodeSize,{...i});n.push(s)}),Il.create(e.doc,n)}}}))}}const ES=new Kr("blocknote-show-selection");class SS extends UE{constructor(e){super(),ew(this,"enabled",!1),this.editor=e,this.addProsemirrorPlugin(new Wr({key:ES,props:{decorations:e=>{const{doc:t,selection:n}=e;if(!this.enabled)return Il.empty;const o=Ol.inline(n.from,n.to,{"data-show-selection":"true"});return Il.create(t,[o])}}}))}static key(){return"showSelection"}setEnabled(e){this.enabled!==e&&(this.enabled=e,this.editor.transact(e=>e.setMeta(ES,{})))}getEnabled(){return this.enabled}}function MS(e,t){for(var n,o;e&&e.parentElement&&e.parentElement!==t.dom&&"blockContainer"!==(null==(n=e.getAttribute)?void 0:n.call(e,"data-node-type"));)e=e.parentElement;if("blockContainer"===(null==(o=e.getAttribute)?void 0:o.call(e,"data-node-type")))return{node:e,id:e.getAttribute("data-id")}}let RS,TS=class e extends Mr{constructor(e,t){super(e,t),ew(this,"nodes");const n=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,t.pos,(e,t,o)=>{if(null!==o&&o.eq(n))return this.nodes.push(e),!1})}static create(t,n,o=n){return new e(t.resolve(n),t.resolve(o))}content(){return new _n(Rn.from(this.nodes),0,0)}eq(t){if(!(t instanceof e)||this.nodes.length!==t.nodes.length||this.from!==t.from||this.to!==t.to)return!1;for(let e=0;e<this.nodes.length;e++)if(!this.nodes[e].eq(t.nodes[e]))return!1;return!0}map(t,n){const o=n.mapResult(this.from),r=n.mapResult(this.to);return r.deleted?Mr.near(t.resolve(o.pos)):o.deleted?Mr.near(t.resolve(r.pos)):new e(t.resolve(o.pos),t.resolve(r.pos))}toJSON(){return{type:"multiple-node",anchor:this.anchor,head:this.head}}};function jS(e,t,n=t){t===n&&(n+=e.state.doc.resolve(t+1).node().nodeSize);const o=e.domAtPos(t).node.cloneNode(!0),r=e.domAtPos(t).node,i=(e,t)=>Array.prototype.indexOf.call(e.children,t),s=i(r,e.domAtPos(t+1).node.parentElement),l=i(r,e.domAtPos(n-1).node.parentElement);for(let d=r.childElementCount-1;d>=0;d--)(d>l||d<s)&&o.removeChild(o.children[d]);NS(e.root),RS=o;const a=RS.getElementsByTagName("iframe");for(let d=0;d<a.length;d++){const e=a[d],t=e.parentElement;t&&t.removeChild(e)}const c=e.dom.className.split(" ").filter(e=>"ProseMirror"!==e&&"bn-root"!==e&&"bn-editor"!==e).join(" ");RS.className=RS.className+" bn-drag-preview "+c,e.root instanceof ShadowRoot?e.root.appendChild(RS):e.root.body.appendChild(RS)}function NS(e){void 0!==RS&&(e instanceof ShadowRoot?e.removeChild(RS):e.body.removeChild(RS),RS=void 0)}function AS(e,t,n){if(!e.dataTransfer)return;const o=n.prosemirrorView;if(!o)return;const r=fk(t.id,o.state.doc);if(!r)throw new Error(`Block with ID ${t.id} not found`);const i=r.posBeforeNode;if(null!=i){const t=o.state.selection,r=o.state.doc,{from:s,to:l}=function(e,t){let n,o;const r="blockContent"===t.resolve(e.from).node().type.spec.group,i="blockContent"===t.resolve(e.to).node().type.spec.group,s=Math.min(e.$anchor.depth,e.$head.depth);if(r&&i){const r=e.$from.start(s-1),i=e.$to.end(s-1);n=t.resolve(r-1).pos,o=t.resolve(i+1).pos}else n=e.from,o=e.to;return{from:n,to:o}}(t,r),a=s<=i&&i<l,c=t.$anchor.node()!==t.$head.node()||t instanceof TS;a&&c?(o.dispatch(o.state.tr.setSelection(TS.create(r,s,l))),jS(o,s,l)):(o.dispatch(o.state.tr.setSelection(Or.create(o.state.doc,i))),jS(o,i));const d=o.state.selection.content(),u=n.pmSchema,h=o.serializeForClipboard(d).dom.innerHTML,p=Ek(u,n),f=DE(d.content),m=p.exportBlocks(f,{}),g=cE(m);e.dataTransfer.clearData(),e.dataTransfer.setData("blocknote/html",h),e.dataTransfer.setData("text/html",m),e.dataTransfer.setData("text/plain",g),e.dataTransfer.effectAllowed="move",e.dataTransfer.setDragImage(RS,0,0)}}Mr.jsonID("multiple-node",TS);function OS(e,t,n=!0){const o=e.root.elementsFromPoint(t.left,t.top);for(const r of o)if(e.dom.contains(r))return n&&r.closest("[data-node-type=columnList]")?OS(e,{left:t.left+50,top:t.top},!1):MS(r,e)}class _S{constructor(e,t,n){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"mousePos"),ew(this,"hoveredBlock"),ew(this,"menuFrozen",!1),ew(this,"isDragOrigin",!1),ew(this,"updateState",e=>{this.state=e,this.emitUpdate(this.state)}),ew(this,"updateStateFromMousePos",()=>{var e,t,n,o,r;if(this.menuFrozen||!this.mousePos)return;const i=this.findClosestEditorElement({clientX:this.mousePos.x,clientY:this.mousePos.y});if((null==i?void 0:i.element)!==this.pmView.dom||i.distance>250)return void(null!=(e=this.state)&&e.show&&(this.state.show=!1,this.updateState(this.state)));const s=function(e,t){if(!t.dom.firstChild)return;const n=t.dom.firstChild.getBoundingClientRect(),o=OS(t,{left:Math.min(Math.max(n.left+10,e.x),n.right-10),top:e.y});if(!o)return;return OS(t,{left:o.node.getBoundingClientRect().right-10,top:e.y},!1)}(this.mousePos,this.pmView);if(s&&this.editor.isEditable){if((null==(n=this.state)||!n.show||null==(o=this.hoveredBlock)||!o.hasAttribute("data-id")||(null==(r=this.hoveredBlock)?void 0:r.getAttribute("data-id"))!==s.id)&&(this.hoveredBlock=s.node,this.editor.isEditable)){const e=s.node.getBoundingClientRect(),t=s.node.closest("[data-node-type=column]");this.state={show:!0,referencePos:new DOMRect(t?t.firstElementChild.getBoundingClientRect().x:this.pmView.dom.firstChild.getBoundingClientRect().x,e.y,e.width,e.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateState(this.state)}}else null!=(t=this.state)&&t.show&&(this.state.show=!1,this.updateState(this.state))}),ew(this,"onDragStart",e=>{var t;const n=null==(t=e.dataTransfer)?void 0:t.getData("blocknote/html");if(!n||this.pmView.dragging)return;const o=document.createElement("div");o.innerHTML=n;const r=vo.fromSchema(this.pmView.state.schema).parse(o,{topNode:this.pmView.state.schema.nodes.blockGroup.create()});this.pmView.dragging={slice:new _n(r.content,0,0),move:!0}}),ew(this,"findClosestEditorElement",e=>{const t=Array.from(this.pmView.root.querySelectorAll(".bn-editor"));if(0===t.length)return null;let n=t[0],o=Number.MAX_VALUE;return t.forEach(t=>{const r=t.querySelector(".bn-block-group").getBoundingClientRect(),i=e.clientX<r.left?r.left-e.clientX:e.clientX>r.right?e.clientX-r.right:0,s=e.clientY<r.top?r.top-e.clientY:e.clientY>r.bottom?e.clientY-r.bottom:0,l=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));l<o&&(o=l,n=t)}),{element:n,distance:o}}),ew(this,"onDragOver",e=>{if(e.synthetic)return;const t=this.getDragEventContext(e);t&&t.isDropPoint?t.isDropPoint&&!t.isDropWithinEditorBounds&&this.dispatchSyntheticEvent(e):this.closeDropCursor()}),ew(this,"closeDropCursor",()=>{const e=new Event("dragleave",{bubbles:!1});e.synthetic=!0,this.pmView.dom.dispatchEvent(e)}),ew(this,"getDragEventContext",e=>{var t;const n=!(null!=(t=e.dataTransfer)&&t.types.includes("blocknote/html")||!this.pmView.dragging),o=!!this.isDragOrigin,r=n||o,i=this.findClosestEditorElement(e);if(!i||i.distance>250)return;const s=i.element===this.pmView.dom,l=s&&0===i.distance;return s||r?{isDropPoint:s,isDropWithinEditorBounds:l,isDragOrigin:r}:void 0}),ew(this,"onDrop",e=>{if(e.synthetic)return;const t=this.getDragEventContext(e);if(!t)return void this.closeDropCursor();const{isDropPoint:n,isDropWithinEditorBounds:o,isDragOrigin:r}=t;if(!o&&n&&this.dispatchSyntheticEvent(e),n){if(this.pmView.dragging)return;this.pmView.dispatch(this.pmView.state.tr.setSelection(Nr.create(this.pmView.state.tr.doc,this.pmView.state.tr.selection.anchor)))}else r&&setTimeout(()=>this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),0)}),ew(this,"onDragEnd",e=>{e.synthetic||(this.pmView.dragging=null)}),ew(this,"onKeyDown",e=>{var t;null!=(t=this.state)&&t.show&&this.editor.isFocused()&&(this.state.show=!1,this.emitUpdate(this.state))}),ew(this,"onMouseMove",e=>{var t;if(this.menuFrozen)return;this.mousePos={x:e.clientX,y:e.clientY};const n=this.pmView.dom.getBoundingClientRect(),o=this.mousePos.x>n.left&&this.mousePos.x<n.right&&this.mousePos.y>n.top&&this.mousePos.y<n.bottom,r=this.pmView.dom.parentElement;o&&e&&e.target&&r!==e.target&&!r.contains(e.target)?null!=(t=this.state)&&t.show&&(this.state.show=!1,this.emitUpdate(this.state)):this.updateStateFromMousePos()}),ew(this,"onScroll",()=>{var e;null!=(e=this.state)&&e.show&&(this.state.referencePos=this.hoveredBlock.getBoundingClientRect(),this.emitUpdate(this.state)),this.updateStateFromMousePos()}),this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized side menu");n(this.state)},this.pmView.root.addEventListener("dragstart",this.onDragStart),this.pmView.root.addEventListener("dragover",this.onDragOver),this.pmView.root.addEventListener("drop",this.onDrop,!0),this.pmView.root.addEventListener("dragend",this.onDragEnd,!0),sE(),this.pmView.root.addEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.addEventListener("keydown",this.onKeyDown,!0),t.root.addEventListener("scroll",this.onScroll,!0)}dispatchSyntheticEvent(e){const t=new Event(e.type,e),n=this.pmView.dom.firstChild.getBoundingClientRect();t.clientX=e.clientX,t.clientY=e.clientY,t.clientX=Math.min(Math.max(e.clientX,n.left),n.left+n.width),t.clientY=Math.min(Math.max(e.clientY,n.top),n.top+n.height),t.dataTransfer=e.dataTransfer,t.preventDefault=()=>e.preventDefault(),t.synthetic=!0,this.pmView.dom.dispatchEvent(t)}update(e,t){var n;!t.doc.eq(this.pmView.state.doc)&&null!=(n=this.state)&&n.show&&this.updateStateFromMousePos()}destroy(){var e;null!=(e=this.state)&&e.show&&(this.state.show=!1,this.emitUpdate(this.state)),this.pmView.root.removeEventListener("mousemove",this.onMouseMove,!0),this.pmView.root.removeEventListener("dragstart",this.onDragStart),this.pmView.root.removeEventListener("dragover",this.onDragOver),this.pmView.root.removeEventListener("drop",this.onDrop,!0),this.pmView.root.removeEventListener("dragend",this.onDragEnd,!0),this.pmView.root.removeEventListener("keydown",this.onKeyDown,!0),this.pmView.root.removeEventListener("scroll",this.onScroll,!0)}}const PS=new Kr("SideMenuPlugin");class IS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"blockDragStart",(e,t)=>{this.view&&(this.view.isDragOrigin=!0),AS(e,t,this.editor)}),ew(this,"blockDragEnd",()=>{this.editor.prosemirrorView&&NS(this.editor.prosemirrorView.root),this.view&&(this.view.isDragOrigin=!1)}),ew(this,"freezeMenu",()=>{this.view.menuFrozen=!0,this.view.state.show=!0,this.view.emitUpdate(this.view.state)}),ew(this,"unfreezeMenu",()=>{this.view.menuFrozen=!1,this.view.state.show=!1,this.view.emitUpdate(this.view.state)}),this.editor=e,this.addProsemirrorPlugin(new Wr({key:PS,view:t=>(this.view=new _S(e,t,e=>{this.emit("update",e)}),this.view)}))}static key(){return"sideMenu"}onUpdate(e){return this.on("update",e)}}const LS=new Map;function DS(e,t,n="left"){const o=ex.getState(e._tiptapEditor.state);if(!o){const o=function(e){if(LS.has(e))return LS.get(e);const t=new Vo;return e._tiptapEditor.on("transaction",({transaction:e})=>{t.appendMapping(e.mapping)}),e._tiptapEditor.on("destroy",()=>{LS.delete(e)}),LS.set(e,t),t}(e),r=o.maps.length;return()=>o.slice(r).map(t,"left"===n?-1:1)}const r=Dx(t+("right"===n?1:0),o.binding.type,o.binding.mapping);return()=>{const t=ex.getState(e._tiptapEditor.state),o=Hx(t.doc,t.binding.type,r,t.binding.mapping);if(null===o)throw new Error("Position not found, cannot track positions");return o+("right"===n?-1:0)}}const BS=Zc(e=>"blockContainer"===e.type.name);class HS{constructor(e,t){var n,o;ew(this,"state"),ew(this,"emitUpdate"),ew(this,"rootEl"),ew(this,"pluginState"),ew(this,"handleScroll",()=>{var e,t;if(null!=(e=this.state)&&e.show){const e=null==(t=this.rootEl)?void 0:t.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);if(!e)return;this.state.referencePos=e.getBoundingClientRect(),this.emitUpdate(this.pluginState.triggerCharacter)}}),ew(this,"closeMenu",()=>{this.editor.transact(e=>e.setMeta(VS,null))}),ew(this,"clearQuery",()=>{void 0!==this.pluginState&&this.editor._tiptapEditor.chain().focus().deleteRange({from:this.pluginState.queryStartPos()-(this.pluginState.deleteTriggerCharacter?this.pluginState.triggerCharacter.length:0),to:this.editor.transact(e=>e.selection.from)}).run()}),this.editor=e,this.pluginState=void 0,this.emitUpdate=e=>{var n;if(!this.state)throw new Error("Attempting to update uninitialized suggestions menu");t(e,{...this.state,ignoreQueryLength:null==(n=this.pluginState)?void 0:n.ignoreQueryLength})},this.rootEl=null==(n=this.editor.prosemirrorView)?void 0:n.root,null==(o=this.rootEl)||o.addEventListener("scroll",this.handleScroll,!0)}update(e,t){var n;const o=VS.getState(t),r=VS.getState(e.state),i=void 0!==o&&void 0===r;if(!(void 0===o&&void 0!==r||void 0!==o&&void 0!==r||i))return;if(this.pluginState=i?o:r,i||!this.editor.isEditable)return this.state&&(this.state.show=!1),void this.emitUpdate(this.pluginState.triggerCharacter);const s=null==(n=this.rootEl)?void 0:n.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&s&&(this.state={show:!0,referencePos:s.getBoundingClientRect(),query:this.pluginState.query},this.emitUpdate(this.pluginState.triggerCharacter))}destroy(){var e;null==(e=this.rootEl)||e.removeEventListener("scroll",this.handleScroll,!0)}}const VS=new Kr("SuggestionMenuPlugin");class $S extends UE{constructor(e){super(),ew(this,"view"),ew(this,"triggerCharacters",[]),ew(this,"addTriggerCharacter",e=>{this.triggerCharacters.push(e)}),ew(this,"removeTriggerCharacter",e=>{this.triggerCharacters=this.triggerCharacters.filter(t=>t!==e)}),ew(this,"closeMenu",()=>this.view.closeMenu()),ew(this,"clearQuery",()=>this.view.clearQuery());const t=this.triggerCharacters;this.addProsemirrorPlugin(new Wr({key:VS,view:()=>(this.view=new HS(e,(e,t)=>{this.emit(`update ${e}`,t)}),this.view),state:{init(){},apply:(t,n,o,r)=>{if(void 0!==t.getMeta("orderedListIndexing")||t.selection.$from.parent.type.spec.code)return n;const i=t.getMeta(VS);if("object"==typeof i&&null!==i){n&&this.closeMenu();const t=DS(e,r.selection.from-i.triggerCharacter.length);return{triggerCharacter:i.triggerCharacter,deleteTriggerCharacter:!1!==i.deleteTriggerCharacter,queryStartPos:()=>t()+i.triggerCharacter.length,query:"",decorationId:`id_${Math.floor(4294967295*Math.random())}`,ignoreQueryLength:null==i?void 0:i.ignoreQueryLength}}if(void 0===n)return n;if(r.selection.from!==r.selection.to||null===i||t.getMeta("focus")||t.getMeta("blur")||t.getMeta("pointer")||void 0!==n.triggerCharacter&&r.selection.from<n.queryStartPos()||!r.selection.$from.sameParent(r.doc.resolve(n.queryStartPos())))return;const s={...n};return s.query=r.doc.textBetween(n.queryStartPos(),r.selection.from),s}},props:{handleTextInput(e,n,o,r){if(n===o){const o=e.state.doc;for(const i of t){const t=i.length>1?o.textBetween(n-i.length,n)+r:r;if(i===t)return e.dispatch(e.state.tr.insertText(r)),e.dispatch(e.state.tr.setMeta(VS,{triggerCharacter:t}).scrollIntoView()),!0}}return!1},decorations(e){const t=this.getState(e);if(void 0===t)return null;if(!t.deleteTriggerCharacter){const n=BS(e.selection);if(n)return Il.create(e.doc,[Ol.node(n.pos,n.pos+n.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":t.decorationId})])}return Il.create(e.doc,[Ol.inline(t.queryStartPos()-t.triggerCharacter.length,t.queryStartPos(),{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":t.decorationId})])}}}))}static key(){return"suggestionMenu"}onUpdate(e,t){return this.triggerCharacters.includes(e)||this.addTriggerCharacter(e),this.on(`update ${e}`,t)}get shown(){var e,t;return(null==(t=null==(e=this.view)?void 0:e.state)?void 0:t.show)||!1}}const zS=gc.create({name:"insertion",inclusive:!1,excludes:"deletion modification insertion",addAttributes:()=>({id:{default:null,validate:"number"}}),extendMarkSchema:e=>"insertion"!==e.name?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM:(e,t)=>["ins",{"data-id":String(e.attrs.id),"data-inline":String(t),...!t&&{style:"display: contents"}},0],parseDOM:[{tag:"ins",getAttrs:e=>!!e.dataset.id&&{id:parseInt(e.dataset.id,10)}}]}}),FS=gc.create({name:"deletion",inclusive:!1,excludes:"insertion modification deletion",addAttributes:()=>({id:{default:null,validate:"number"}}),extendMarkSchema:e=>"deletion"!==e.name?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM:(e,t)=>["del",{"data-id":String(e.attrs.id),"data-inline":String(t),...!t&&{style:"display: contents"}},0],parseDOM:[{tag:"del",getAttrs:e=>!!e.dataset.id&&{id:parseInt(e.dataset.id,10)}}]}}),US=gc.create({name:"modification",inclusive:!1,excludes:"deletion insertion",addAttributes:()=>({id:{default:null,validate:"number"},type:{validate:"string"},attrName:{default:null,validate:"string|null"},previousValue:{default:null},newValue:{default:null}}),extendMarkSchema:e=>"modification"!==e.name?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM:(e,t)=>[t?"span":"div",{"data-type":"modification","data-id":String(e.attrs.id),"data-mod-type":e.attrs.type,"data-mod-prev-val":JSON.stringify(e.attrs.previousValue),"data-mod-new-val":JSON.stringify(e.attrs.newValue)},0],parseDOM:[{tag:"span[data-type='modification']",getAttrs:e=>!!e.dataset.id&&{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal,newValue:e.dataset.modNewVal}},{tag:"div[data-type='modification']",getAttrs:e=>!!e.dataset.id&&{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal}}]}});let WS;function qS(e){WS||(WS=document.createElement("div"),WS.innerHTML="_",WS.style.opacity="0",WS.style.height="1px",WS.style.width="1px",e instanceof Document?e.body.appendChild(WS):e.appendChild(WS))}function GS(e){return Array.prototype.indexOf.call(e.parentElement.childNodes,e)}class KS{constructor(e,t,n){ew(this,"state"),ew(this,"emitUpdate"),ew(this,"tableId"),ew(this,"tablePos"),ew(this,"tableElement"),ew(this,"menuFrozen",!1),ew(this,"mouseState","up"),ew(this,"prevWasEditable",null),ew(this,"viewMousedownHandler",()=>{this.mouseState="down"}),ew(this,"mouseUpHandler",e=>{this.mouseState="up",this.mouseMoveHandler(e)}),ew(this,"mouseMoveHandler",e=>{var t,n,o,r,i,s,l;if(this.menuFrozen||"selecting"===this.mouseState||!(e.target instanceof Element)||!this.pmView.dom.contains(e.target))return;const a=function(e){let t=e;for(;t&&"TD"!==t.nodeName&&"TH"!==t.nodeName&&!t.classList.contains("tableWrapper");){if(t.classList.contains("ProseMirror"))return;const e=t.parentNode;if(!(e&&e instanceof Element))return;t=e}return"TD"===t.nodeName||"TH"===t.nodeName?{type:"cell",domNode:t,tbodyNode:t.closest("tbody")}:{type:"wrapper",domNode:t,tbodyNode:t.querySelector("tbody")}}(e.target);if("cell"===(null==a?void 0:a.type)&&"down"===this.mouseState&&(null==(t=this.state)||!t.draggingState))return this.mouseState="selecting",void(null!=(n=this.state)&&n.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate()));if(!a||!this.editor.isEditable)return void(null!=(o=this.state)&&o.show&&(this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,this.emitUpdate()));if(!a.tbodyNode)return;const c=a.tbodyNode.getBoundingClientRect(),d=MS(a.domNode,this.pmView);if(!d)return;let u;this.tableElement=d.node;const h=this.editor.transact(e=>fk(d.id,e.doc));if(!h)throw new Error(`Block with ID ${d.id} not found`);const p=Gw(h.node,this.editor.pmSchema,this.editor.schema.blockSchema,this.editor.schema.inlineContentSchema,this.editor.schema.styleSchema);if(function(e,t,n){return t.type===e&&t.type in n.schema.blockSchema&&HC(t.type,n)}("table",p,this.editor)&&(this.tablePos=h.posBeforeNode+1,u=p),!u)return;this.tableId=d.id;const f=null==(r=a.domNode.closest(".tableWrapper"))?void 0:r.querySelector(".table-widgets-container");if("wrapper"===(null==a?void 0:a.type)){const t=e.clientY>=c.bottom-1&&e.clientY<c.bottom+20,n=e.clientX>=c.right-1&&e.clientX<c.right+20,o=e.clientX>c.right||e.clientY>c.bottom;this.state={...this.state,show:!0,showAddOrRemoveRowsButton:t,showAddOrRemoveColumnsButton:n,referencePosTable:c,block:u,widgetContainer:f,colIndex:o||null==(i=this.state)?void 0:i.colIndex,rowIndex:o||null==(s=this.state)?void 0:s.rowIndex,referencePosCell:o||null==(l=this.state)?void 0:l.referencePosCell}}else{const e=GS(a.domNode),t=GS(a.domNode.parentElement),n=a.domNode.getBoundingClientRect();if(void 0!==this.state&&this.state.show&&this.tableId===d.id&&this.state.rowIndex===t&&this.state.colIndex===e)return;this.state={show:!0,showAddOrRemoveColumnsButton:e===u.content.rows[0].cells.length-1,showAddOrRemoveRowsButton:t===u.content.rows.length-1,referencePosTable:c,block:u,draggingState:void 0,referencePosCell:n,colIndex:e,rowIndex:t,widgetContainer:f}}return this.emitUpdate(),!1}),ew(this,"dragOverHandler",e=>{var t;if(void 0===(null==(t=this.state)?void 0:t.draggingState))return;e.preventDefault(),e.dataTransfer.dropEffect="move",function(e,t){const n=t.querySelectorAll(e);for(let o=0;o<n.length;o++)n[o].style.visibility="hidden"}(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",this.pmView.root);const n={left:Math.min(Math.max(e.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(e.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=this.pmView.root.elementsFromPoint(n.left,n.top).filter(e=>"TD"===e.tagName||"TH"===e.tagName);if(0===o.length)return;const r=o[0];let i=!1;const s=GS(r.parentElement),l=GS(r),a="row"===this.state.draggingState.draggedCellOrientation?this.state.rowIndex:this.state.colIndex,c=("row"===this.state.draggingState.draggedCellOrientation?s:l)!==a;(this.state.rowIndex!==s||this.state.colIndex!==l)&&(this.state.rowIndex=s,this.state.colIndex=l,this.state.referencePosCell=r.getBoundingClientRect(),i=!0);const d="row"===this.state.draggingState.draggedCellOrientation?n.top:n.left;this.state.draggingState.mousePos!==d&&(this.state.draggingState.mousePos=d,i=!0),i&&this.emitUpdate(),c&&this.editor.transact(e=>e.setMeta(ZS,!0))}),ew(this,"dropHandler",e=>{if(this.mouseState="up",void 0===this.state||void 0===this.state.draggingState)return!1;if(void 0===this.state.rowIndex||void 0===this.state.colIndex)throw new Error("Attempted to drop table row or column, but no table block was hovered prior.");e.preventDefault();const{draggingState:t,colIndex:n,rowIndex:o}=this.state,r=this.state.block.content.columnWidths;if("row"===t.draggedCellOrientation){if(!ik(this.state.block,t.originalIndex,o))return!1;const e=function(e,t,n,o=Xw(e)){const{row:r}=Qw({row:t,col:0},e,o),{row:i}=Qw({row:n,col:0},e,o),[s]=o.splice(r,1);return o.splice(i,0,s),Yw(o)}(this.state.block,t.originalIndex,o);this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,rows:e}})}else{if(!sk(this.state.block,t.originalIndex,n))return!1;const e=function(e,t,n,o=Xw(e)){const{col:r}=Qw({row:0,col:t},e,o),{col:i}=Qw({row:0,col:n},e,o);return o.forEach(e=>{const[t]=e.splice(r,1);e.splice(i,0,t)}),Yw(o)}(this.state.block,t.originalIndex,n),[o]=r.splice(t.originalIndex,1);r.splice(n,0,o),this.editor.updateBlock(this.state.block,{type:"table",content:{...this.state.block.content,columnWidths:r,rows:e}})}return this.editor.setTextCursorPosition(this.state.block.id),!0}),this.editor=e,this.pmView=t,this.emitUpdate=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");n(this.state)},t.dom.addEventListener("mousemove",this.mouseMoveHandler),t.dom.addEventListener("mousedown",this.viewMousedownHandler),window.addEventListener("mouseup",this.mouseUpHandler),t.root.addEventListener("dragover",this.dragOverHandler),t.root.addEventListener("drop",this.dropHandler)}update(){var e;if(!this.state||!this.state.show)return;if(this.state.block=this.editor.getBlock(this.state.block.id),!this.state.block||"table"!==this.state.block.type||null==(e=this.tableElement)||!e.isConnected)return this.state.show=!1,this.state.showAddOrRemoveRowsButton=!1,this.state.showAddOrRemoveColumnsButton=!1,void this.emitUpdate();const{height:t,width:n}=ek(this.state.block);void 0!==this.state.rowIndex&&void 0!==this.state.colIndex&&(this.state.rowIndex>=t&&(this.state.rowIndex=t-1),this.state.colIndex>=n&&(this.state.colIndex=n-1));const o=this.tableElement.querySelector("tbody");if(!o)throw new Error("Table block does not contain a 'tbody' HTML element. This should never happen.");if(void 0!==this.state.rowIndex&&void 0!==this.state.colIndex){const e=o.children[this.state.rowIndex].children[this.state.colIndex];e?this.state.referencePosCell=e.getBoundingClientRect():(this.state.rowIndex=void 0,this.state.colIndex=void 0)}this.state.referencePosTable=o.getBoundingClientRect(),this.emitUpdate()}destroy(){this.pmView.dom.removeEventListener("mousemove",this.mouseMoveHandler),window.removeEventListener("mouseup",this.mouseUpHandler),this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.root.removeEventListener("dragover",this.dragOverHandler),this.pmView.root.removeEventListener("drop",this.dropHandler)}}const ZS=new Kr("TableHandlesPlugin");class JS extends UE{constructor(e){super(),ew(this,"view"),ew(this,"colDragStart",e=>{if(void 0===this.view.state||void 0===this.view.state.colIndex)throw new Error("Attempted to drag table column, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:e.clientX},this.view.emitUpdate(),this.editor.transact(e=>e.setMeta(ZS,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");qS(this.editor.prosemirrorView.root),e.dataTransfer.setDragImage(WS,0,0),e.dataTransfer.effectAllowed="move"}),ew(this,"rowDragStart",e=>{if(void 0===this.view.state||void 0===this.view.state.rowIndex)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:e.clientY},this.view.emitUpdate(),this.editor.transact(e=>e.setMeta(ZS,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");qS(this.editor.prosemirrorView.root),e.dataTransfer.setDragImage(WS,0,0),e.dataTransfer.effectAllowed="copyMove"}),ew(this,"dragEnd",()=>{if(void 0===this.view.state)throw new Error("Attempted to drag table row, but no table block was hovered prior.");if(this.view.state.draggingState=void 0,this.view.emitUpdate(),this.editor.transact(e=>e.setMeta(ZS,null)),!this.editor.prosemirrorView)throw new Error("Editor view not initialized.");var e;e=this.editor.prosemirrorView.root,WS&&(e instanceof Document?e.body.removeChild(WS):e.removeChild(WS),WS=void 0)}),ew(this,"freezeHandles",()=>{this.view.menuFrozen=!0}),ew(this,"unfreezeHandles",()=>{this.view.menuFrozen=!1}),ew(this,"getCellsAtRowHandle",(e,t)=>nk(e,t)),ew(this,"getCellsAtColumnHandle",(e,t)=>ok(e,t)),ew(this,"setCellSelection",(e,t,n=t)=>{const o=this.view;if(!o)throw new Error("Table handles view not initialized");const r=e.doc.resolve(o.tablePos+1),i=e.doc.resolve(r.posAtIndex(t.row)+1),s=e.doc.resolve(i.posAtIndex(t.col)),l=e.doc.resolve(r.posAtIndex(n.row)+1),a=e.doc.resolve(l.posAtIndex(n.col)),c=e.tr;return c.setSelection(new Gd(s,a)),e.apply(c)}),ew(this,"addRowOrColumn",(e,t)=>{this.editor.exec((n,o)=>{const r=this.setCellSelection(n,"row"===t.orientation?{row:e,col:0}:{row:0,col:e});return"row"===t.orientation?"above"===t.side?function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e);t(nu(e.tr,n,n.top))}return!0}(r,o):function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e);t(nu(e.tr,n,n.bottom))}return!0}(r,o):"left"===t.side?function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e);t(eu(e.tr,n,n.left))}return!0}(r,o):function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e);t(eu(e.tr,n,n.right))}return!0}(r,o)})}),ew(this,"removeRowOrColumn",(e,t)=>"row"===t?this.editor.exec((t,n)=>function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e),o=e.tr;if(0==n.top&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;ou(o,n,e),e!=n.top;e--){const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw RangeError("No table found");n.table=e,n.map=Id.get(n.table)}t(o)}return!0}(this.setCellSelection(t,{row:e,col:0}),n)):this.editor.exec((t,n)=>function(e,t){if(!Vd(e))return!1;if(t){const n=Qd(e),o=e.tr;if(0==n.left&&n.right==n.map.width)return!1;for(let e=n.right-1;tu(o,n,e),e!=n.left;e--){const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw RangeError("No table found");n.table=e,n.map=Id.get(e)}t(o)}return!0}(this.setCellSelection(t,{row:0,col:e}),n))),ew(this,"mergeCells",e=>this.editor.exec((t,n)=>function(e,t){const n=e.selection;if(!(n instanceof Gd)||n.$anchorCell.pos==n.$headCell.pos)return!1;const o=Qd(e),{map:r}=o;if(function({width:e,height:t,map:n},o){let r=o.top*e+o.left,i=r,s=(o.bottom-1)*e+o.left,l=r+(o.right-o.left-1);for(let a=o.top;a<o.bottom;a++){if(o.left>0&&n[i]==n[i-1]||o.right<e&&n[l]==n[l+1])return!0;i+=e,l+=e}for(let a=o.left;a<o.right;a++){if(o.top>0&&n[r]==n[r-e]||o.bottom<t&&n[s]==n[s+e])return!0;r++,s++}return!1}(r,o))return!1;if(t){const n=e.tr,i={};let s,l,a=Rn.empty;for(let e=o.top;e<o.bottom;e++)for(let t=o.left;t<o.right;t++){const c=r.map[e*r.width+t],d=o.table.nodeAt(c);if(!i[c]&&d)if(i[c]=!0,null==s)s=c,l=d;else{ru(d)||(a=a.append(d.content));const e=n.mapping.map(c+o.tableStart);n.delete(e,e+d.nodeSize)}}if(null==s||null==l)return!0;if(n.setNodeMarkup(s+o.tableStart,null,{...qd(l.attrs,l.attrs.colspan,o.right-o.left-l.attrs.colspan),rowspan:o.bottom-o.top}),a.size){const e=s+1+l.content.size,t=ru(l)?s+1:e;n.replaceWith(t+o.tableStart,e+o.tableStart,a)}n.setSelection(new Gd(n.doc.resolve(s+o.tableStart))),t(n)}return!0}(e?this.setCellSelection(t,e.relativeStartCell,e.relativeEndCell):t,n))),ew(this,"splitCell",e=>this.editor.exec((t,n)=>iu(e?this.setCellSelection(t,e):t,n))),ew(this,"getCellSelection",()=>this.editor.transact(e=>{const t=e.selection;let n=t.$from,o=t.$to;if(UC(t)){const{ranges:e}=t;e.forEach(e=>{n=e.$from.min(n??e.$from),o=e.$to.max(o??e.$to)})}else if(n=e.doc.resolve(t.$from.pos-t.$from.parentOffset-1),o=e.doc.resolve(t.$to.pos-t.$to.parentOffset-1),0===n.pos||0===o.pos)return;const r=e.doc.resolve(n.pos-n.parentOffset-1),i=e.doc.resolve(o.pos-o.parentOffset-1),s=e.doc.resolve(r.pos-r.parentOffset-1),l=n.index(r.depth),a=r.index(s.depth),c=o.index(i.depth),d=i.index(s.depth),u=[];for(let h=a;h<=d;h++)for(let e=l;e<=c;e++)u.push({row:h,col:e});return{from:{row:a,col:l},to:{row:d,col:c},cells:u}})),ew(this,"getMergeDirection",e=>this.editor.transact(t=>{const n=UC(t.selection)?t.selection:void 0;if(!n||!e||n.ranges.length<=1)return;const o=this.getCellSelection();return o?function(e,t,n){const o=Qw(e,n),r=Qw(t,n);return o.col===r.col}(o.from,o.to,e)?"vertical":"horizontal":void 0})),ew(this,"cropEmptyRowsOrColumns",(e,t)=>function(e,t,n=Xw(e)){if("columns"===t){let e=0;for(let t=n[0].length-1;t>=0&&n.every(e=>rk(e[t].cell)&&1===e[t].colspan);t--)e++;for(let t=n.length-1;t>=0;t--){const o=Math.max(n[t].length-e,1);n[t]=n[t].slice(0,o)}return Yw(n)}let o=0;for(let i=n.length-1;i>=0&&n[i].every(e=>rk(e.cell)&&1===e.rowspan);i--)o++;const r=Math.min(o,n.length-1);return n.splice(n.length-r,r),Yw(n)}(e,t)),ew(this,"addRowsOrColumns",(e,t,n)=>function(e,t,n,o=Xw(e)){const{width:r,height:i}=ek(e);if("columns"===t)o.forEach((e,t)=>{if(n>=0)for(let o=0;o<n;o++)e.push({row:t,col:Math.max(...e.map(e=>e.col))+1,rowspan:1,colspan:1,cell:sw("")});else e.splice(r+n,-1*n)});else if(n>0)for(let s=0;s<n;s++){const e=new Array(r).fill(null).map((e,t)=>({row:i+s,col:t,rowspan:1,colspan:1,cell:sw("")}));o.push(e)}else n<0&&o.splice(i+n,-1*n);return Yw(o)}(e,t,n)),this.editor=e,this.addProsemirrorPlugin(new Wr({key:ZS,view:t=>(this.view=new KS(e,t,e=>{this.emit("update",e)}),this.view),props:{decorations:e=>{if(void 0===this.view||void 0===this.view.state||void 0===this.view.state.draggingState||void 0===this.view.tablePos)return;const t="row"===this.view.state.draggingState.draggedCellOrientation?this.view.state.rowIndex:this.view.state.colIndex;if(void 0===t)return;const n=[],{block:o,draggingState:r}=this.view.state,{originalIndex:i,draggedCellOrientation:s}=r;if(t===i||!o||"row"===s&&!ik(o,i,t)||"col"===s&&!sk(o,i,t))return Il.create(e.doc,n);const l=e.doc.resolve(this.view.tablePos+1);return"row"===this.view.state.draggingState.draggedCellOrientation?nk(this.view.state.block,t).forEach(({row:o,col:r})=>{const s=e.doc.resolve(l.posAtIndex(o)+1),a=e.doc.resolve(s.posAtIndex(r)+1),c=a.node(),d=a.pos+(t>i?c.nodeSize-2:0);n.push(Ol.widget(d,()=>{const e=document.createElement("div");return e.className="bn-table-drop-cursor",e.style.left="0",e.style.right="0",t>i?e.style.bottom="-2px":e.style.top="-3px",e.style.height="4px",e}))}):ok(this.view.state.block,t).forEach(({row:o,col:r})=>{const s=e.doc.resolve(l.posAtIndex(o)+1),a=e.doc.resolve(s.posAtIndex(r)+1),c=a.node(),d=a.pos+(t>i?c.nodeSize-2:0);n.push(Ol.widget(d,()=>{const e=document.createElement("div");return e.className="bn-table-drop-cursor",e.style.top="0",e.style.bottom="0",t>i?e.style.right="-2px":e.style.left="-3px",e.style.width="4px",e}))}),Il.create(e.doc,n)}}}))}static key(){return"tableHandles"}onUpdate(e){return this.on("update",e)}}const XS=kc.create({name:"textAlignment",addGlobalAttributes:()=>[{types:["paragraph","heading","bulletListItem","numberedListItem","checkListItem","tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:e=>e.getAttribute("data-text-alignment"),renderHTML:e=>"left"===e.textAlignment?{}:{"data-text-alignment":e.textAlignment}}}}]}),YS=kc.create({name:"blockTextColor",addGlobalAttributes:()=>[{types:["blockContainer","tableCell","tableHeader"],attributes:{textColor:{default:bw.textColor.default,parseHTML:e=>e.hasAttribute("data-text-color")?e.getAttribute("data-text-color"):bw.textColor.default,renderHTML:e=>e.textColor===bw.textColor.default?{}:{"data-text-color":e.textColor}}}}]}),QS=kc.create({name:"trailingNode",addProseMirrorPlugins(){const e=new Kr(this.name);return[new Wr({key:e,appendTransaction:(t,n,o)=>{const{doc:r,tr:i,schema:s}=o,l=e.getState(o),a=r.content.size-2,c=s.nodes.blockContainer,d=s.nodes.paragraph;if(l)return i.insert(a,c.create(void 0,d.create()))},state:{init:(e,t)=>{},apply:(e,t)=>{if(!e.docChanged)return t;let n=e.doc.lastChild;if(!n||"blockGroup"!==n.type.name)throw new Error("Expected blockGroup");if(n=n.lastChild,!n||"blockContainer"!==n.type.name)return!0;const o=n.firstChild;if(!o)throw new Error("Expected blockContent");return n.nodeSize>4||"inline*"!==o.type.spec.content}}})]}}),eM={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},tM=kd.create({name:"blockContainer",group:"blockGroupChild bnBlock",content:"blockContent blockGroup?",priority:50,defining:!0,marks:"insertion modification deletion",parseHTML(){return[{tag:"div[data-node-type="+this.name+"]",getAttrs:e=>{if("string"==typeof e)return!1;const t={};for(const[n,o]of Object.entries(eM))e.getAttribute(o)&&(t[n]=e.getAttribute(o));return t}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:e}){var t;const n=document.createElement("div");n.className="bn-block-outer",n.setAttribute("data-node-type","blockOuter");for(const[i,s]of Object.entries(e))"class"!==i&&n.setAttribute(i,s);const o={...(null==(t=this.options.domAttributes)?void 0:t.block)||{},...e},r=document.createElement("div");r.className=fw("bn-block",o.class),r.setAttribute("data-node-type",this.name);for(const[i,s]of Object.entries(o))"class"!==i&&r.setAttribute(i,s);return n.appendChild(r),{dom:n,contentDOM:r}}}),nM=kd.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",marks:"deletion insertion modification",parseHTML:()=>[{tag:"div",getAttrs:e=>"string"!=typeof e&&("blockGroup"===e.getAttribute("data-node-type")&&null)}],renderHTML({HTMLAttributes:e}){var t;const n={...(null==(t=this.options.domAttributes)?void 0:t.blockGroup)||{},...e},o=document.createElement("div");o.className=fw("bn-block-group",n.class),o.setAttribute("data-node-type","blockGroup");for(const[r,i]of Object.entries(n))"class"!==r&&o.setAttribute(r,i);return{dom:o,contentDOM:o}}}),oM=kd.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"});class rM extends UE{constructor({editor:e,collaboration:t}){super(e),ew(this,"editor"),ew(this,"collaboration"),ew(this,"forkedState"),this.editor=e,this.collaboration=t}static key(){return"ForkYDocPlugin"}findTypeInOtherYdoc(e,t){const n=e.doc;if(null===e._item){const o=Array.from(n.share.keys()).find(t=>n.share.get(t)===e);if(null==o)throw new Error("type does not exist in other ydoc");return t.get(o,e.constructor)}{const n=e._item,o=t.store.clients.get(n.id.client)??[];return o[Gy(o,n.id.clock)].content.type}}get isForkedFromRemote(){return void 0!==this.forkedState}fork(){var e;if(this.isForkedFromRemote)return;const t=null==(e=this.collaboration)?void 0:e.fragment;if(!t)throw new Error("No fragment to fork from");const n=new oy;my(n,yy(t.doc));const o=this.findTypeInOtherYdoc(t,n);this.forkedState={undoStack:tx.getState(this.editor.prosemirrorState).undoManager.undoStack,originalFragment:t,forkedFragment:o},this.editor._tiptapEditor.unregisterPlugin([nx,tx,ex]),this.editor._tiptapEditor.registerPlugin(new KE(o).plugins[0]),this.editor._tiptapEditor.registerPlugin(new ZE({editor:this.editor}).plugins[0]),this.emit("forked",!0)}merge({keepChanges:e}){if(!this.forkedState)return;this.editor._tiptapEditor.unregisterPlugin(ex),this.editor._tiptapEditor.unregisterPlugin(tx);const{originalFragment:t,forkedFragment:n,undoStack:o}=this.forkedState;if(this.editor.extensions.ySyncPlugin=new KE(t),this.editor.extensions.yCursorPlugin=new GE(this.collaboration),this.editor.extensions.yUndoPlugin=new ZE({editor:this.editor}),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.ySyncPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yCursorPlugin.plugins[0]),this.editor._tiptapEditor.registerPlugin(this.editor.extensions.yUndoPlugin.plugins[0]),tx.getState(this.editor.prosemirrorState).undoManager.undoStack=o,e){const e=yy(n.doc,(r=t.doc,xy(r,new ay)));my(t.doc,e,this.editor)}var r;this.forkedState=void 0,this.emit("forked",!1)}}let iM=!1;const sM=e=>{const t=[bd.ClipboardTextSerializer,bd.Commands,bd.Editable,bd.FocusEvents,bd.Tabindex,mh,kc.create({name:"dropCursor",addProseMirrorPlugins:()=>[e.dropCursor({width:5,color:"#ddeeff",editor:e.editor})]}),nw.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),sS,If,zS,FS,US,Pf.extend({inclusive:!1}).configure({defaultProtocol:gS,protocols:iM?[]:mS}),...Object.values(e.styleSpecs).map(t=>t.implementation.mark.configure({editor:e.editor})),YS,zE,XS,kc.create({name:"OverrideEscape",addKeyboardShortcuts(){return{Escape:()=>!e.editor.suggestionMenus.shown&&this.editor.commands.blur()}}}),oM,tM.configure({editor:e.editor,domAttributes:e.domAttributes}),uS.configure({editor:e.editor,tabBehavior:e.tabBehavior}),nM.configure({domAttributes:e.domAttributes}),...Object.values(e.inlineContentSpecs).filter(e=>"link"!==e.config&&"text"!==e.config).map(t=>t.implementation.node.configure({editor:e.editor})),...Object.values(e.blockSpecs).flatMap(t=>[...(t.implementation.requiredExtensions||[]).map(t=>t.configure({editor:e.editor,domAttributes:e.domAttributes})),t.implementation.node.configure({editor:e.editor,domAttributes:e.domAttributes})]),$E(e.editor),LE(e.editor,e.pasteHandler||(e=>e.defaultPasteHandler())),wE(e.editor),...void 0===e.trailingBlock||e.trailingBlock?[QS]:[],...e.comments?[JE]:[]];return iM=!0,e.collaboration||t.push(Ih),t};function lM(e,t){const n=[];return e.forEach((e,o,r)=>{r!==t&&n.push(e)}),Rn.from(n)}function aM(e,t){let n=Rn.from(e.content);if(n=function(e,t){const n=[];for(let o=0;o<e.childCount;o++)if("tableRow"===e.child(o).type.name)if(n.length>0&&"table"===n[n.length-1].type.name){const t=n[n.length-1],r=t.copy(t.content.addToEnd(e.child(o)));n[n.length-1]=r}else{const r=t.nodes.table.createChecked(void 0,e.child(o));n.push(r)}else n.push(e.child(o));return Rn.from(n)}(n,t.state.schema),!function(e,t){var n,o;const r=1===e.childCount,i="inline*"===(null==(n=e.firstChild)?void 0:n.type.spec.content),s="tableRow+"===(null==(o=e.firstChild)?void 0:o.type.spec.content);if(r){if(i)return!1;if(s){const e=Lw(t.state);if(e.isBlockContainer)return!("tableRow+"===e.blockContent.node.type.spec.content)}}return!0}(n,t))return new _n(n,e.openStart,e.openEnd);for(let o=0;o<n.childCount;o++)if("blockContent"===n.child(o).type.spec.group){const e=[n.child(o)];if(o+1<n.childCount&&"blockGroup"===n.child(o+1).type.name){const t=n.child(o+1).child(0).child(0);("bulletListItem"===t.type.name||"numberedListItem"===t.type.name||"checkListItem"===t.type.name)&&(e.push(n.child(o+1)),n=lM(n,o+1))}const r=t.state.schema.nodes.blockContainer.createChecked(void 0,e);n=n.replaceChild(o,r)}return new _n(n,e.openStart,e.openEnd)}const cM=class extends xd{constructor(e,t){super({...e,content:void 0}),ew(this,"_state"),ew(this,"mount",(e,t,n)=>{t?(this.options.element=t,this.createViewAlternative(e,n)):(this.destroy(),this.isInitialized=!1)});const n=this.schema;let o;const r=n.nodes.doc.createAndFill;let i;n.nodes.doc.createAndFill=(...e)=>{if(o)return o;const t=r.apply(n.nodes.doc,e),i=JSON.parse(JSON.stringify(t.toJSON()));return i.content[0].content[0].attrs.id="initialBlockId",o=Xn.fromJSON(n,i),o};try{i=Uc({type:"doc",content:[{type:"blockGroup",content:null==e?void 0:e.content.map(e=>pk(e,this.schema,t).toJSON())}]},this.schema,this.options.parseOptions)}catch(s){throw new Error("Error creating document from blocks passed as `initialContent`:\n"+ +JSON.stringify(e.content))}this._state=Fr.create({doc:i,schema:this.schema})}get state(){return this.view&&(this._state=this.view.state),this._state}dispatch(e){if(!this.view)return this._state=this.state.apply(e),void this.emit("transaction",{editor:this,transaction:e});if(this.view.isDestroyed)return;if(this.isCapturingTransaction)return void this.dispatchTransaction(e);const{state:t,transactions:n}=this.state.applyTransaction(e),o=!this.state.selection.eq(t.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),o&&this.emit("selectionUpdate",{editor:this,transaction:e});const r=e.getMeta("focus"),i=e.getMeta("blur");r&&this.emit("focus",{editor:this,event:r.event,transaction:e}),i&&this.emit("blur",{editor:this,event:i.event,transaction:e}),e.docChanged&&!e.getMeta("preventUpdate")&&(this.emit("update",{editor:this,transaction:e}),this.emit("v3-update",{editor:this,transaction:e,appendedTransactions:n.slice(1)}))}forceEnablePlugins(){if(this.view)throw new Error("forcePluginsEnabled called after view has been initialized");this._state=this.state.reconfigure({plugins:this.extensionManager.plugins})}createViewAlternative(e,t){this.contentComponent=t;const n={};this.extensionManager.extensions.forEach(t=>{"mark"===t.type&&t.config.addMarkView&&(n[t.name]=t.config.addMarkView(e))}),this.view=new sa({mount:this.options.element},{...this.options.editorProps,dispatchTransaction:this.dispatch.bind(this),state:this.state,markViews:n,nodeViews:this.extensionManager.nodeViews});const o=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(o),this.commands.focus(this.options.autofocus||"true"===this.options.element.getAttribute("data-bn-autofocus"),{scrollIntoView:!1}),this.emit("create",{editor:this}),this.isInitialized=!0}};ew(cM,"create",(e,t)=>{var n,o;const r=null==(n=null==globalThis?void 0:globalThis.window)?void 0:n.setTimeout;typeof(null==(o=null==globalThis?void 0:globalThis.window)?void 0:o.setTimeout)<"u"&&(globalThis.window.setTimeout=()=>0);try{return new cM(e,t)}finally{r&&(globalThis.window.setTimeout=r)}});let dM=cM;dM.prototype.createView=function(){this.options.onPaste=this.options.onDrop=void 0};const uM={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};let hM,pM=class e extends FE{constructor(e){var t,n,o,r,i,s,l,a,c,d,u,h,p,f,m,g;super(),ew(this,"pmSchema"),ew(this,"extensions",{}),ew(this,"headless",!1),ew(this,"_tiptapEditor"),ew(this,"elementRenderer",null),ew(this,"blockCache",new WeakMap),ew(this,"dictionary"),ew(this,"schema"),ew(this,"blockImplementations"),ew(this,"inlineContentImplementations"),ew(this,"styleImplementations"),ew(this,"formattingToolbar"),ew(this,"linkToolbar"),ew(this,"sideMenu"),ew(this,"suggestionMenus"),ew(this,"filePanel"),ew(this,"tableHandles"),ew(this,"comments"),ew(this,"showSelectionPlugin"),ew(this,"forkYDocPlugin"),ew(this,"uploadFile"),ew(this,"onUploadStartCallbacks",[]),ew(this,"onUploadEndCallbacks",[]),ew(this,"resolveFileUrl"),ew(this,"resolveUsers"),ew(this,"settings"),ew(this,"activeTransaction",null),ew(this,"mount",(e,t)=>{this._tiptapEditor.mount(this,e,t)}),this.options=e;const y=e;if(y.onEditorContentChange)throw new Error("onEditorContentChange initialization option is deprecated, use <BlockNoteView onChange={...} />, the useEditorChange(...) hook, or editor.onChange(...)");if(y.onTextCursorPositionChange)throw new Error("onTextCursorPositionChange initialization option is deprecated, use <BlockNoteView onSelectionChange={...} />, the useEditorSelectionChange(...) hook, or editor.onSelectionChange(...)");if(y.onEditorReady)throw new Error("onEditorReady is deprecated. Editor is immediately ready for use after creation.");if(y.editable)throw new Error("editable initialization option is deprecated, use <BlockNoteView editable={true/false} />, or alternatively editor.isEditable = true/false");this.dictionary=e.dictionary||Yx,this.settings={tables:{splitCells:(null==(t=null==e?void 0:e.tables)?void 0:t.splitCells)??!1,cellBackgroundColor:(null==(n=null==e?void 0:e.tables)?void 0:n.cellBackgroundColor)??!1,cellTextColor:(null==(o=null==e?void 0:e.tables)?void 0:o.cellTextColor)??!1,headers:(null==(r=null==e?void 0:e.tables)?void 0:r.headers)??!1},codeBlock:{indentLineWithTab:(null==(i=null==e?void 0:e.codeBlock)?void 0:i.indentLineWithTab)??!0,defaultLanguage:(null==(s=null==e?void 0:e.codeBlock)?void 0:s.defaultLanguage)??"text",supportedLanguages:(null==(l=null==e?void 0:e.codeBlock)?void 0:l.supportedLanguages)??{},createHighlighter:(null==(a=null==e?void 0:e.codeBlock)?void 0:a.createHighlighter)??void 0},heading:{levels:(null==(c=null==e?void 0:e.heading)?void 0:c.levels)??[1,2,3]}};const b={defaultStyles:!0,schema:e.schema||GC.create(),_headless:!1,...e,placeholders:{...this.dictionary.placeholders,...e.placeholders}};if(b.comments&&!b.resolveUsers)throw new Error("resolveUsers is required when using comments");this.resolveUsers=b.resolveUsers,this.schema=b.schema,this.blockImplementations=b.schema.blockSpecs,this.inlineContentImplementations=b.schema.inlineContentSpecs,this.styleImplementations=b.schema.styleSpecs,this.extensions=(e=>{var t;const n={},o=sM(e);for(const i of o)n[i.name]=i;e.collaboration&&(n.ySyncPlugin=new KE(e.collaboration.fragment),n.yUndoPlugin=new ZE({editor:e.editor}),null!=(t=e.collaboration.provider)&&t.awareness&&(n.yCursorPlugin=new GE(e.collaboration)),n.forkYDocPlugin=new rM({editor:e.editor,collaboration:e.collaboration})),n.formattingToolbar=new iS(e.editor),n.linkToolbar=new fS(e.editor),n.sideMenu=new IS(e.editor),n.suggestionMenus=new $S(e.editor),n.filePanel=new nS(e.editor),n.placeholder=new xS(e.editor,e.placeholders),(e.animations??!0)&&(n.animations=new CS),e.tableHandles&&(n.tableHandles=new JS(e.editor)),n.nodeSelectionKeyboard=new bS,n.blockChange=new WE,n.showSelection=new SS(e.editor),e.comments&&(n.comments=new QE(e.editor,e.comments.threadStore,JE.name));const r=e.disableExtensions||[];for(const i of r)delete n[i];return n})({editor:this,domAttributes:b.domAttributes||{},blockSpecs:this.schema.blockSpecs,styleSpecs:this.schema.styleSpecs,inlineContentSpecs:this.schema.inlineContentSpecs,collaboration:b.collaboration,trailingBlock:b.trailingBlock,disableExtensions:b.disableExtensions,setIdAttribute:b.setIdAttribute,animations:b.animations??!0,tableHandles:HC("table",this),dropCursor:this.options.dropCursor??Jx,placeholders:b.placeholders,tabBehavior:b.tabBehavior,comments:b.comments,pasteHandler:b.pasteHandler}),((null==(d=b._tiptapOptions)?void 0:d.extensions)||[]).forEach(e=>{this.extensions[e.name]=e});for(let S of b.extensions||[]){"function"==typeof S&&(S=S(this));const e=S.constructor.key();if(!e)throw new Error(`Extension ${S.constructor.name} does not have a key method`);if(this.extensions[e])throw new Error(`Extension ${S.constructor.name} already exists with key ${e}`);this.extensions[e]=S}if(Object.entries(b._extensions||{}).forEach(([e,t])=>{const n="function"==typeof t?t(this):t;this.extensions[e]="plugin"in n?new class extends UE{static key(){return e}constructor(){super(),this.addProsemirrorPlugin(n.plugin)}get priority(){return n.priority}}:n}),this.formattingToolbar=this.extensions.formattingToolbar,this.linkToolbar=this.extensions.linkToolbar,this.sideMenu=this.extensions.sideMenu,this.suggestionMenus=this.extensions.suggestionMenus,this.filePanel=this.extensions.filePanel,this.tableHandles=this.extensions.tableHandles,this.comments=this.extensions.comments,this.showSelectionPlugin=this.extensions.showSelection,this.forkYDocPlugin=this.extensions.forkYDocPlugin,b.uploadFile){const e=b.uploadFile;this.uploadFile=async(t,n)=>{this.onUploadStartCallbacks.forEach(e=>e.apply(this,[n]));try{return await e(t,n)}finally{this.onUploadEndCallbacks.forEach(e=>e.apply(this,[n]))}}}this.resolveFileUrl=b.resolveFileUrl,this.headless=b._headless;const v="ySyncPlugin"in this.extensions||"liveblocksExtension"in this.extensions;v&&b.initialContent;const x=b.initialContent||(v?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:nw.options.generateID()}]);if(!Array.isArray(x)||0===x.length)throw new Error("initialContent must be a non-empty array of blocks, received: "+x);const w=[...Object.entries(this.extensions).map(([e,t])=>t instanceof kc||t instanceof kd||t instanceof gc?t:t instanceof UE&&!t.plugins.length?void 0:kc.create({name:e,priority:t.priority,addProseMirrorPlugins:()=>t.plugins}))].filter(e=>void 0!==e),k={...uM,...b._tiptapOptions,content:x,extensions:w,editorProps:{...null==(u=b._tiptapOptions)?void 0:u.editorProps,attributes:{tabIndex:"0",...null==(p=null==(h=b._tiptapOptions)?void 0:h.editorProps)?void 0:p.attributes,...null==(f=b.domAttributes)?void 0:f.editor,class:fw("bn-editor",b.defaultStyles?"bn-default-styles":"",(null==(g=null==(m=b.domAttributes)?void 0:m.editor)?void 0:g.class)||"")},transformPasted:aM}};var C,E;this.headless?this.pmSchema=(C=k.extensions,sc(wc.resolve(C),E)):(this._tiptapEditor=dM.create(k,this.schema.styleSchema),this.pmSchema=this._tiptapEditor.schema),this.pmSchema.cached.blockNoteEditor=this,this.emit("create")}static create(t={}){return new e(t)}exec(e){if(this.activeTransaction)throw new Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");return e(this._tiptapEditor.state,e=>this._tiptapEditor.dispatch(e),this._tiptapEditor.view)}canExec(e){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");return e(this._tiptapEditor.state,void 0,this._tiptapEditor.view)}transact(e){if(this.activeTransaction)return e(this.activeTransaction);try{this.activeTransaction=this._tiptapEditor.state.tr;const t=e(this.activeTransaction),n=this.activeTransaction;return this.activeTransaction=null,n&&(n.docChanged||n.selectionSet||n.scrolledIntoView||n.storedMarksSet||!n.isGeneric)&&this._tiptapEditor.dispatch(n),t}finally{this.activeTransaction=null}}extension(e,t=e.key()){const n=this.extensions[t];if(!n)throw new Error(`Extension ${t} not found`);return n}get prosemirrorState(){if(this.activeTransaction)throw new Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this._tiptapEditor.state}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){var e;return null==(e=this.prosemirrorView)?void 0:e.dom}isFocused(){var e;return(null==(e=this.prosemirrorView)?void 0:e.hasFocus())||!1}focus(){var e;null==(e=this.prosemirrorView)||e.focus()}onUploadStart(e){return this.onUploadStartCallbacks.push(e),()=>{const t=this.onUploadStartCallbacks.indexOf(e);t>-1&&this.onUploadStartCallbacks.splice(t,1)}}onUploadEnd(e){return this.onUploadEndCallbacks.push(e),()=>{const t=this.onUploadEndCallbacks.indexOf(e);t>-1&&this.onUploadEndCallbacks.splice(t,1)}}get topLevelBlocks(){return this.document}get document(){return this.transact(e=>function(e,t,n=$w(t),o=zw(t),r=Fw(t),i=Uw(t)){const s=[];return e.firstChild.descendants(e=>(s.push(Gw(e,t,n,o,r,i)),!1)),s}(e.doc,this.pmSchema))}getBlock(e){return this.transact(t=>function(e,t){const n="string"==typeof t?t:t.id,o=Bw(e),r=fk(n,e);if(r)return Gw(r.node,o)}(t.doc,e))}getPrevBlock(e){return this.transact(t=>function(e,t){const n=fk("string"==typeof t?t:t.id,e),o=Bw(e);if(!n)return;const r=e.resolve(n.posBeforeNode).nodeBefore;return r?Gw(r,o):void 0}(t.doc,e))}getNextBlock(e){return this.transact(t=>function(e,t){const n=fk("string"==typeof t?t:t.id,e),o=Bw(e);if(!n)return;const r=e.resolve(n.posBeforeNode+n.node.nodeSize).nodeAfter;return r?Gw(r,o):void 0}(t.doc,e))}getParentBlock(e){return this.transact(t=>function(e,t){const n="string"==typeof t?t:t.id,o=Bw(e),r=fk(n,e);if(!r)return;const i=e.resolve(r.posBeforeNode),s=i.node(),l=i.node(-1),a="doc"!==l.type.name?"blockGroup"===s.type.name?l:s:void 0;return a?Gw(a,o):void 0}(t.doc,e))}forEachBlock(e,t=!1){const n=this.document.slice();t&&n.reverse(),function n(o){for(const r of o){if(!1===e(r))return!1;if(!n(t?r.children.slice().reverse():r.children))return!1}return!0}(n)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}getTextCursorPosition(){return this.transact(e=>function(e){const{bnBlock:t}=Dw(e),n=Bw(e.doc),o=e.doc.resolve(t.beforePos),r=o.nodeBefore,i=e.doc.resolve(t.afterPos).nodeAfter;let s;return o.depth>1&&(s=o.node(),s.type.isInGroup("bnBlock")||(s=o.node(o.depth-1))),{block:Gw(t.node,n),prevBlock:null===r?void 0:Gw(r,n),nextBlock:null===i?void 0:Gw(i,n),parentBlock:void 0===s?void 0:Gw(s,n)}}(e))}setTextCursorPosition(e,t="start"){return this.transact(n=>rE(n,e,t))}getSelection(){return this.transact(e=>function(e){const t=Bw(e);if(e.selection.empty||"node"in e.selection)return;const n=e.doc.resolve(Ow(e.doc,e.selection.from).posBeforeNode),o=e.doc.resolve(Ow(e.doc,e.selection.to).posBeforeNode),r=(o,r)=>{const i=n.posAtIndex(o,r),s=e.doc.resolve(i).nodeAfter;if(!s)throw new Error(`Error getting selection - node not found at position ${i}`);return Gw(s,t)},i=[],s=n.sharedDepth(o.pos),l=n.index(s),a=o.index(s);if(n.depth>s){i.push(Gw(n.nodeAfter,t));for(let e=n.depth;e>s;e--)if(n.node(e).type.isInGroup("childContainer")){const t=n.index(e)+1,o=n.node(e).childCount;for(let n=t;n<o;n++)i.push(r(n,e))}}else i.push(r(l,s));for(let c=l+1;c<=a;c++)i.push(r(c,s));if(0===i.length)throw new Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);return{blocks:i}}(e))}getSelectionCutBlocks(){return this.transact(e=>oE(e))}setSelection(e,t){return this.transact(n=>function(e,t,n){const o="string"==typeof t?t:t.id,r="string"==typeof n?n:n.id,i=Vw(Bw(e));if(o===r)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${o})`);const s=fk(o,e.doc);if(!s)throw new Error(`Block with ID ${o} not found`);const l=fk(r,e.doc);if(!l)throw new Error(`Block with ID ${r} not found`);const a=Pw(s),c=Pw(l),d=i.blockSchema[a.blockNoteType],u=i.blockSchema[c.blockNoteType];if(!a.isBlockContainer||"none"===d.content)throw new Error(`Attempting to set selection anchor in block without content (id ${o})`);if(!c.isBlockContainer||"none"===u.content)throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);let h,p;if("table"===d.content){const e=Id.get(a.blockContent.node);h=a.blockContent.beforePos+e.positionAt(0,0,a.blockContent.node)+1+2}else h=a.blockContent.beforePos+1;if("table"===u.content){const t=Id.get(c.blockContent.node),n=c.blockContent.beforePos+t.positionAt(t.height-1,t.width-1,c.blockContent.node)+1;p=n+e.doc.resolve(n).nodeAfter.nodeSize-2}else p=c.blockContent.afterPos-1;e.setSelection(Nr.create(e.doc,h,p))}(n,e,t))}get isEditable(){if(!this._tiptapEditor){if(!this.headless)throw new Error("no editor, but also not headless?");return!1}return void 0===this._tiptapEditor.isEditable||this._tiptapEditor.isEditable}set isEditable(e){if(this._tiptapEditor)this._tiptapEditor.options.editable!==e&&this._tiptapEditor.setEditable(e);else if(!this.headless)throw new Error("no editor, but also not headless?")}insertBlocks(e,t,n="before"){return this.transact(o=>function(e,t,n,o="before"){const r="string"==typeof n?n:n.id,i=Bw(e),s=t.map(e=>pk(e,i)),l=fk(r,e.doc);if(!l)throw new Error(`Block with ID ${r} not found`);let a=l.posBeforeNode;return"after"===o&&(a+=l.node.nodeSize),e.step(new Zo(a,a,new _n(Rn.from(s),0,0))),s.map(e=>Gw(e,i))}(o,e,t,n))}updateBlock(e,t){return this.transact(n=>function(e,t,n){const o="string"==typeof t?t:t.id,r=fk(o,e.doc);if(!r)throw new Error(`Block with ID ${o} not found`);return bk(e,r.posBeforeNode,n),Gw(e.doc.resolve(r.posBeforeNode+1).node(),Bw(e))}(n,e,t))}removeBlocks(e){return this.transact(t=>gk(t,e,[]).removedBlocks)}replaceBlocks(e,t){return this.transact(n=>gk(n,e,t))}undo(){return this.options.collaboration?this.exec(qx):this.exec(_h)}redo(){return this.options.collaboration?this.exec(Gx):this.exec(Ph)}insertInlineContent(e,{updateSelection:t=!1}={}){const n=dk(e,this.pmSchema);this.transact(e=>{!function(e,t,n,o={updateSelection:!0}){let{from:r,to:i}="number"==typeof t?{from:t,to:t}:{from:t.from,to:t.to},s=!0,l=!0,a="";if(n.forEach(e=>{e.check(),s&&e.isText&&0===e.marks.length?a+=e.text:s=!1,l=!!l&&e.isBlock}),r===i&&l){const{parent:t}=e.doc.resolve(r);t.isTextblock&&!t.type.spec.code&&!t.childCount&&(r-=1,i+=1)}s?e.insertText(a,r,i):e.replaceWith(r,i,n),o.updateSelection&&Hc(e,e.steps.length-1,-1)}(e,{from:e.selection.from,to:e.selection.to},n,{updateSelection:t})})}getActiveStyles(){return this.transact(e=>{const t={},n=e.selection.$to.marks();for(const o of n){const e=this.schema.styleSchema[o.type.name];e?"boolean"===e.propSchema?t[e.type]=!0:t[e.type]=o.attrs.stringValue:"link"!==o.type.name&&o.type.spec.blocknoteIgnore}return t})}addStyles(e){for(const[t,n]of Object.entries(e)){const e=this.schema.styleSchema[t];if(!e)throw new Error(`style ${t} not found in styleSchema`);if("boolean"===e.propSchema)this._tiptapEditor.commands.setMark(t);else{if("string"!==e.propSchema)throw new uw(e.propSchema);this._tiptapEditor.commands.setMark(t,{stringValue:n})}}}removeStyles(e){for(const t of Object.keys(e))this._tiptapEditor.commands.unsetMark(t)}toggleStyles(e){for(const[t,n]of Object.entries(e)){const e=this.schema.styleSchema[t];if(!e)throw new Error(`style ${t} not found in styleSchema`);if("boolean"===e.propSchema)this._tiptapEditor.commands.toggleMark(t);else{if("string"!==e.propSchema)throw new uw(e.propSchema);this._tiptapEditor.commands.toggleMark(t,{stringValue:n})}}}getSelectedText(){return this.transact(e=>e.doc.textBetween(e.selection.from,e.selection.to))}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(e,t){if(""===e)return;const n=this.pmSchema.mark("link",{href:e});this.transact(e=>{const{from:o,to:r}=e.selection;t?e.insertText(t,o,r).addMark(o,o+t.length,n):e.setSelection(Nr.create(e.doc,r)).addMark(o,r,n)})}canNestBlock(){return this.transact(e=>{const{bnBlock:t}=Dw(e);return null!==e.doc.resolve(t.beforePos).nodeBefore})}nestBlock(){nE(this)}canUnnestBlock(){return this.transact(e=>{const{bnBlock:t}=Dw(e);return e.doc.resolve(t.beforePos).depth>1})}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}moveBlocksUp(){return eE(this)}moveBlocksDown(){return tE(this)}async blocksToHTMLLossy(e=this.document){return Ek(this.pmSchema,this).exportBlocks(e,{})}async blocksToFullHTML(e){return((e,t)=>{const n=jo.fromSchema(e);return{serializeBlocks:(e,o)=>Rk(t,e,n,o).outerHTML}})(this.pmSchema,this).serializeBlocks(e,{})}async tryParseHTMLToBlocks(e){return pE(e,this.pmSchema)}async blocksToMarkdownLossy(e=this.document){return async function(e,t,n,o){return await sE(),cE(Ek(t,n).exportBlocks(e,o))}(e,this.pmSchema,this,{})}async tryParseMarkdownToBlocks(e){return async function(e,t){return pE(await mE(e),t)}(e,this.pmSchema)}updateCollaborationUserInfo(e){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this.extensions.yCursorPlugin.updateUser(e)}onBeforeChange(e){return this.headless?()=>{}:this.extensions.blockChange.subscribe(t=>e(this,t))}onChange(e){if(this.headless)return;const t=({transaction:t,appendedTransactions:n})=>{e(this,{getChanges:()=>jk(t,n)})};return this._tiptapEditor.on("v3-update",t),()=>{this._tiptapEditor.off("v3-update",t)}}onSelectionChange(e,t){if(this.headless)return;const n=n=>{n.transaction.getMeta(ex)&&!t||e(this)};return this._tiptapEditor.on("selectionUpdate",n),()=>{this._tiptapEditor.off("selectionUpdate",n)}}onCreate(e){return this.on("create",e),()=>{this.off("create",e)}}getSelectionBoundingBox(){if(!this.prosemirrorView)return;const{selection:e}=this.prosemirrorState,{ranges:t}=e,n=Math.min(...t.map(e=>e.$from.pos)),o=Math.max(...t.map(e=>e.$to.pos));if(rd(e)){const e=this.prosemirrorView.nodeDOM(n);if(e)return e.getBoundingClientRect()}return id(this.prosemirrorView,n,o)}get isEmpty(){const e=this.document;return 0===e.length||1===e.length&&"paragraph"===e[0].type&&0===e[0].content.length}openSuggestionMenu(e,t){this.prosemirrorView&&(this.focus(),this.transact(n=>{null!=t&&t.deleteTriggerCharacter&&n.insertText(e),n.scrollIntoView().setMeta(this.suggestionMenus.plugins[0],{triggerCharacter:e,deleteTriggerCharacter:(null==t?void 0:t.deleteTriggerCharacter)||!1,ignoreQueryLength:(null==t?void 0:t.ignoreQueryLength)||!1})}))}getForceSelectionVisible(){return this.showSelectionPlugin.getEnabled()}setForceSelectionVisible(e){this.showSelectionPlugin.setEnabled(e)}convertHtmlToBlockNoteHtml(e){return hE(e.trim()).innerHTML}pasteHTML(e,t=!1){var n;let o=e;t||(o=this.convertHtmlToBlockNoteHtml(e)),o&&(null==(n=this.prosemirrorView)||n.pasteHTML(o))}pasteText(e){var t;return null==(t=this.prosemirrorView)?void 0:t.pasteText(e)}async pasteMarkdown(e){return this.pasteHTML(await mE(e))}};async function fM(e,t){if(!function(e,t){return e in t.schema.inlineContentSchema&&t.schema.inlineContentSchema[e]===BC[e]}("text",e))return[];const{emojiData:n,emojiMart:o}=await async function(){return hM||(hM=(async()=>{const[e,t]=await Promise.all([Promise.resolve().then(()=>require("./module-B6LwlNJR.cjs")),Promise.resolve().then(()=>require("./native-CLBO_ikU.cjs"))]),n="default"in e?e.default:e,o="default"in t?t.default:t;return await n.init({data:o}),{emojiMart:n,emojiData:o}})(),hM)}();return(""===t.trim()?Object.values(n.emojis):await o.SearchIndex.search(t)).map(t=>({id:t.skins[0].native,onItemClick:()=>e.insertInlineContent(t.skins[0].native+" ")}))}var mM,gM={exports:{}},yM={};var bM,vM={};
6
6
  /**
7
7
  * @license React
8
8
  * use-sync-external-store-shim.development.js