kritzel-stencil 0.2.2 → 0.2.4
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.
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/kritzel-active-users_42.cjs.entry.js +83 -30
- package/dist/cjs/{workspace.migrations-BPwtowiJ.js → workspace.migrations-B89-6fP-.js} +42 -8
- package/dist/collection/classes/core/core.class.js +9 -2
- package/dist/collection/classes/handlers/line-handle.handler.js +1 -0
- package/dist/collection/classes/handlers/move.handler.js +2 -0
- package/dist/collection/classes/handlers/resize.handler.js +2 -0
- package/dist/collection/classes/handlers/rotation.handler.js +2 -0
- package/dist/collection/classes/structures/object-map.structure.js +44 -3
- package/dist/collection/classes/tools/brush-tool.class.js +2 -0
- package/dist/collection/classes/tools/eraser-tool.class.js +22 -8
- package/dist/collection/classes/tools/line-tool.class.js +2 -0
- package/dist/collection/classes/tools/shape-tool.class.js +1 -0
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +5 -5
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +7 -0
- package/dist/collection/components/shared/kritzel-dialog/kritzel-dialog.css +3 -2
- package/dist/collection/components/shared/kritzel-dialog/kritzel-dialog.js +3 -2
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +7 -10
- package/dist/collection/components/ui/kritzel-current-user/kritzel-current-user.js +1 -1
- package/dist/collection/components/ui/kritzel-current-user-dialog/kritzel-current-user-dialog.js +1 -1
- package/dist/collection/components/ui/kritzel-export/kritzel-export.js +1 -1
- package/dist/collection/components/ui/kritzel-login-dialog/kritzel-login-dialog.js +1 -1
- package/dist/collection/components/ui/kritzel-more-menu/kritzel-more-menu.js +1 -1
- package/dist/collection/components/ui/kritzel-settings/kritzel-settings.js +1 -1
- package/dist/collection/components/ui/kritzel-share-dialog/kritzel-share-dialog.js +2 -2
- package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +1 -1
- package/dist/collection/constants/version.js +1 -1
- package/dist/collection/themes/dark-theme.js +4 -0
- package/dist/collection/themes/light-theme.js +4 -0
- package/dist/components/index.js +1 -1
- package/dist/components/kritzel-awareness-cursors.js +1 -1
- package/dist/components/kritzel-color-palette.js +1 -1
- package/dist/components/kritzel-color.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-current-user-dialog.js +1 -1
- package/dist/components/kritzel-current-user.js +1 -1
- package/dist/components/kritzel-dialog.js +1 -1
- package/dist/components/kritzel-editor.js +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-export.js +1 -1
- package/dist/components/kritzel-login-dialog.js +1 -1
- package/dist/components/kritzel-more-menu.js +1 -1
- package/dist/components/kritzel-settings.js +1 -1
- package/dist/components/kritzel-share-dialog.js +1 -1
- package/dist/components/kritzel-stroke-size.js +1 -1
- package/dist/components/kritzel-tool-config.js +1 -1
- package/dist/components/kritzel-utility-panel.js +1 -1
- package/dist/components/p-0F9_lw6l.js +1 -0
- package/dist/components/{p-DfB7uJ0N.js → p-3YivOJM2.js} +1 -1
- package/dist/components/p-B2dVTxsc.js +9 -0
- package/dist/components/{p-mYhFNPgz.js → p-BAjrJjMX.js} +1 -1
- package/dist/components/{p-R9M5PnAz.js → p-BDOSy6zd.js} +1 -1
- package/dist/components/{p-DE2xDwUM.js → p-BabNumqA.js} +1 -1
- package/dist/components/{p-574MVXxi.js → p-Be6E_RMf.js} +1 -1
- package/dist/components/{p-CoyqJSjT.js → p-BmYsz1bP.js} +1 -1
- package/dist/components/p-C-qyWv4d.js +1 -0
- package/dist/components/{p-BYOIzv_f.js → p-C1Fv9rVN.js} +1 -1
- package/dist/components/{p-Bfa-Amjn.js → p-C2MdRsg6.js} +1 -1
- package/dist/components/{p-u-827ZX7.js → p-CsMMZSAP.js} +1 -1
- package/dist/components/p-DMYfjC1C.js +1 -0
- package/dist/components/{p-Dxb22STM.js → p-DYHF_MSN.js} +1 -1
- package/dist/components/{p-BWrxz4mM.js → p-Dg_nGsFe.js} +1 -1
- package/dist/components/{p-BtJB7FsW.js → p-DoDI-v-H.js} +1 -1
- package/dist/components/p-Dqpa31TI.js +1 -0
- package/dist/components/p-R60vdaIY.js +1 -0
- package/dist/components/{p-CU6kJPth.js → p-ZpItdhxS.js} +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/kritzel-active-users_42.entry.js +83 -30
- package/dist/esm/{workspace.migrations-C_uxbvuH.js → workspace.migrations-D_y5zlxK.js} +42 -8
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/p-74898384.entry.js +9 -0
- package/dist/stencil/p-D_y5zlxK.js +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/structures/object-map.structure.d.ts +19 -0
- package/dist/types/constants/version.d.ts +1 -1
- package/dist/types/interfaces/theme.interface.d.ts +5 -5
- package/package.json +1 -1
- package/dist/components/p-BCzbwL4m.js +0 -1
- package/dist/components/p-BfJav4Zz.js +0 -1
- package/dist/components/p-BmcAX-1k.js +0 -1
- package/dist/components/p-C6Td7I4k.js +0 -1
- package/dist/components/p-CqYIRmoh.js +0 -1
- package/dist/components/p-DFeyobdy.js +0 -9
- package/dist/stencil/p-4d28c496.entry.js +0 -9
- package/dist/stencil/p-C_uxbvuH.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as t,b as i,K as e,a as s}from"./p-CsMMZSAP.js";import{a as r,D as n}from"./p-C-qyWv4d.js";import{K as h}from"./p-D8W6LE-c.js";import{K as o}from"./p-jGOpkGDl.js";class l{static registry={};static registerTool(t,i,e){const s=new i(e);return s.name=t,this.registry[t]=s,s}static getTool(t){return this.registry[t]||(console.warn(`Unknown tool: ${t}`),null)}static getToolByIndex(t){return Object.values(this.registry)[t]??null}}class u{static forceHideKeyboard(){document.activeElement instanceof HTMLElement&&document.activeElement.blur()}static enableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let i=t.getAttribute("content");i?.includes("interactive-widget=resizes-content")||(i+=", interactive-widget=resizes-content"),i&&t.setAttribute("content",i)}}static disableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let i=t.getAttribute("content"),e=i?.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");void 0!==e&&(e=e.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim(),t.setAttribute("content",e))}}static onKeyboardVisibleChanged(t){if("visualViewport"in window){const i=.75,e=e=>{const s=e.target,r=o.isMobile(),n=s.height*s.scale/window.screen.height<i;t(r&&n)};return window.visualViewport?.addEventListener("resize",e),()=>window.visualViewport?.removeEventListener("resize",e)}return console.warn("Listening for keyboard visibility changes is not reliably supported in this browser."),()=>{}}}function f(t){this.content=t}function a(t,i,e){for(let s=0;;s++){if(s==t.childCount||s==i.childCount)return t.childCount==i.childCount?null:e;let r=t.child(s),n=i.child(s);if(r!=n){if(!r.sameMarkup(n))return e;if(r.isText&&r.text!=n.text){for(let t=0;r.text[t]==n.text[t];t++)e++;return e}if(r.content.size||n.content.size){let t=a(r.content,n.content,e+1);if(null!=t)return t}e+=r.nodeSize}else e+=r.nodeSize}}function c(t,i,e,s){for(let r=t.childCount,n=i.childCount;;){if(0==r||0==n)return r==n?null:{a:e,b:s};let h=t.child(--r),o=i.child(--n),l=h.nodeSize;if(h!=o){if(!h.sameMarkup(o))return{a:e,b:s};if(h.isText&&h.text!=o.text){let t=0,i=Math.min(h.text.length,o.text.length);for(;t<i&&h.text[h.text.length-t-1]==o.text[o.text.length-t-1];)t++,e--,s--;return{a:e,b:s}}if(h.content.size||o.content.size){let t=c(h.content,o.content,e-1,s-1);if(t)return t}e-=l,s-=l}else e-=l,s-=l}}f.prototype={constructor:f,find:function(t){for(var i=0;i<this.content.length;i+=2)if(this.content[i]===t)return i;return-1},get:function(t){var i=this.find(t);return-1==i?void 0:this.content[i+1]},update:function(t,i,e){var s=e&&e!=t?this.remove(e):this,r=s.find(t),n=s.content.slice();return-1==r?n.push(e||t,i):(n[r+1]=i,e&&(n[r]=e)),new f(n)},remove:function(t){var i=this.find(t);if(-1==i)return this;var e=this.content.slice();return e.splice(i,2),new f(e)},addToStart:function(t,i){return new f([t,i].concat(this.remove(t).content))},addToEnd:function(t,i){var e=this.remove(t).content.slice();return e.push(t,i),new f(e)},addBefore:function(t,i,e){var s=this.remove(i),r=s.content.slice(),n=s.find(t);return r.splice(-1==n?r.length:n,0,i,e),new f(r)},forEach:function(t){for(var i=0;i<this.content.length;i+=2)t(this.content[i],this.content[i+1])},prepend:function(t){return(t=f.from(t)).size?new f(t.content.concat(this.subtract(t).content)):this},append:function(t){return(t=f.from(t)).size?new f(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var i=this;t=f.from(t);for(var e=0;e<t.content.length;e+=2)i=i.remove(t.content[e]);return i},toObject:function(){var t={};return this.forEach((function(i,e){t[i]=e})),t},get size(){return this.content.length>>1}},f.from=function(t){if(t instanceof f)return t;var i=[];if(t)for(var e in t)i.push(e,t[e]);return new f(i)};class d{constructor(t,i){if(this.content=t,this.size=i||0,null==i)for(let i=0;i<t.length;i++)this.size+=t[i].nodeSize}nodesBetween(t,i,e,s=0,r){for(let n=0,h=0;h<i;n++){let o=this.content[n],l=h+o.nodeSize;if(l>t&&!1!==e(o,s+h,r||null,n)&&o.content.size){let r=h+1;o.nodesBetween(Math.max(0,t-r),Math.min(o.content.size,i-r),e,s+r)}h=l}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,i,e,s){let r="",n=!0;return this.nodesBetween(t,i,((h,o)=>{let l=h.isText?h.text.slice(Math.max(t,o)-o,i-o):h.isLeaf?s?"function"==typeof s?s(h):s:h.type.spec.leafText?h.type.spec.leafText(h):"":"";h.isBlock&&(h.isLeaf&&l||h.isTextblock)&&e&&(n?n=!1:r+=e),r+=l}),0),r}append(t){if(!t.size)return this;if(!this.size)return t;let i=this.lastChild,e=t.firstChild,s=this.content.slice(),r=0;for(i.isText&&i.sameMarkup(e)&&(s[s.length-1]=i.withText(i.text+e.text),r=1);r<t.content.length;r++)s.push(t.content[r]);return new d(s,this.size+t.size)}cut(t,i=this.size){if(0==t&&i==this.size)return this;let e=[],s=0;if(i>t)for(let r=0,n=0;n<i;r++){let h=this.content[r],o=n+h.nodeSize;o>t&&((n<t||o>i)&&(h=h.isText?h.cut(Math.max(0,t-n),Math.min(h.text.length,i-n)):h.cut(Math.max(0,t-n-1),Math.min(h.content.size,i-n-1))),e.push(h),s+=h.nodeSize),n=o}return new d(e,s)}cutByIndex(t,i){return t==i?d.empty:0==t&&i==this.content.length?this:new d(this.content.slice(t,i))}replaceChild(t,i){let e=this.content[t];if(e==i)return this;let s=this.content.slice(),r=this.size+i.nodeSize-e.nodeSize;return s[t]=i,new d(s,r)}addToStart(t){return new d([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new d(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let i=0;i<this.content.length;i++)if(!this.content[i].eq(t.content[i]))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(t){let i=this.content[t];if(!i)throw new RangeError("Index "+t+" out of range for "+this);return i}maybeChild(t){return this.content[t]||null}forEach(t){for(let i=0,e=0;i<this.content.length;i++){let s=this.content[i];t(s,e,i),e+=s.nodeSize}}findDiffStart(t,i=0){return a(this,t,i)}findDiffEnd(t,i=this.size,e=t.size){return c(this,t,i,e)}findIndex(t){if(0==t)return m(0,t);if(t==this.size)return m(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let i=0,e=0;;i++){let s=e+this.child(i).nodeSize;if(s>=t)return s==t?m(i+1,s):m(i,e);e=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((t=>t.toJSON())):null}static fromJSON(t,i){if(!i)return d.empty;if(!Array.isArray(i))throw new RangeError("Invalid input for Fragment.fromJSON");return new d(i.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return d.empty;let i,e=0;for(let s=0;s<t.length;s++){let r=t[s];e+=r.nodeSize,s&&r.isText&&t[s-1].sameMarkup(r)?(i||(i=t.slice(0,s)),i[i.length-1]=r.withText(i[i.length-1].text+r.text)):i&&i.push(r)}return new d(i||t,e)}static from(t){if(!t)return d.empty;if(t instanceof d)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new d([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}d.empty=new d([],0);const p={index:0,offset:0};function m(t,i){return p.index=t,p.offset=i,p}function w(t,i){if(t===i)return!0;if(!t||"object"!=typeof t||!i||"object"!=typeof i)return!1;let e=Array.isArray(t);if(Array.isArray(i)!=e)return!1;if(e){if(t.length!=i.length)return!1;for(let e=0;e<t.length;e++)if(!w(t[e],i[e]))return!1}else{for(let e in t)if(!(e in i)||!w(t[e],i[e]))return!1;for(let e in i)if(!(e in t))return!1}return!0}class g{constructor(t,i){this.type=t,this.attrs=i}addToSet(t){let i,e=!1;for(let s=0;s<t.length;s++){let r=t[s];if(this.eq(r))return t;if(this.type.excludes(r.type))i||(i=t.slice(0,s));else{if(r.type.excludes(this.type))return t;!e&&r.type.rank>this.type.rank&&(i||(i=t.slice(0,s)),i.push(this),e=!0),i&&i.push(r)}}return i||(i=t.slice()),e||i.push(this),i}removeFromSet(t){for(let i=0;i<t.length;i++)if(this.eq(t[i]))return t.slice(0,i).concat(t.slice(i+1));return t}isInSet(t){for(let i=0;i<t.length;i++)if(this.eq(t[i]))return!0;return!1}eq(t){return this==t||this.type==t.type&&w(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let i in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,i){if(!i)throw new RangeError("Invalid input for Mark.fromJSON");let e=t.marks[i.type];if(!e)throw new RangeError(`There is no mark type ${i.type} in this schema`);let s=e.create(i.attrs);return e.checkAttrs(s.attrs),s}static sameSet(t,i){if(t==i)return!0;if(t.length!=i.length)return!1;for(let e=0;e<t.length;e++)if(!t[e].eq(i[e]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return g.none;if(t instanceof g)return[t];let i=t.slice();return i.sort(((t,i)=>t.type.rank-i.type.rank)),i}}g.none=[];class y extends Error{}class b{constructor(t,i,e){this.content=t,this.openStart=i,this.openEnd=e}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,i){let e=v(this.content,t+this.openStart,i);return e&&new b(e,this.openStart,this.openEnd)}removeBetween(t,i){return new b(M(this.content,t+this.openStart,i+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,i){if(!i)return b.empty;let e=i.openStart||0,s=i.openEnd||0;if("number"!=typeof e||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new b(d.fromJSON(t,i.content),e,s)}static maxOpen(t,i=!0){let e=0,s=0;for(let s=t.firstChild;s&&!s.isLeaf&&(i||!s.type.spec.isolating);s=s.firstChild)e++;for(let e=t.lastChild;e&&!e.isLeaf&&(i||!e.type.spec.isolating);e=e.lastChild)s++;return new b(t,e,s)}}function M(t,i,e){let{index:s,offset:r}=t.findIndex(i),n=t.maybeChild(s),{index:h,offset:o}=t.findIndex(e);if(r==i||n.isText){if(o!=e&&!t.child(h).isText)throw new RangeError("Removing non-flat range");return t.cut(0,i).append(t.cut(e))}if(s!=h)throw new RangeError("Removing non-flat range");return t.replaceChild(s,n.copy(M(n.content,i-r-1,e-r-1)))}function v(t,i,e,s){let{index:r,offset:n}=t.findIndex(i),h=t.maybeChild(r);if(n==i||h.isText)return s&&!s.canReplace(r,r,e)?null:t.cut(0,i).append(e).append(t.cut(i));let o=v(h.content,i-n-1,e,h);return o&&t.replaceChild(r,h.copy(o))}function k(t,i,e){if(e.openStart>t.depth)throw new y("Inserted content deeper than insertion position");if(t.depth-e.openStart!=i.depth-e.openEnd)throw new y("Inconsistent open depths");return S(t,i,e,0)}function S(t,i,e,s){let r=t.index(s),n=t.node(s);if(r==i.index(s)&&s<t.depth-e.openStart){let h=S(t,i,e,s+1);return n.copy(n.content.replaceChild(r,h))}if(e.content.size){if(e.openStart||e.openEnd||t.depth!=s||i.depth!=s){let{start:r,end:h}=function(t,i){let e=i.depth-t.openStart,s=i.node(e).copy(t.content);for(let t=e-1;t>=0;t--)s=i.node(t).copy(d.from(s));return{start:s.resolveNoCache(t.openStart+e),end:s.resolveNoCache(s.content.size-t.openEnd-e)}}(e,t);return A(n,R(t,r,h,i,s))}{let s=t.parent,r=s.content;return A(s,r.cut(0,t.parentOffset).append(e.content).append(r.cut(i.parentOffset)))}}return A(n,E(t,i,s))}function x(t,i){if(!i.type.compatibleContent(t.type))throw new y("Cannot join "+i.type.name+" onto "+t.type.name)}function O(t,i,e){let s=t.node(e);return x(s,i.node(e)),s}function T(t,i){let e=i.length-1;e>=0&&t.isText&&t.sameMarkup(i[e])?i[e]=t.withText(i[e].text+t.text):i.push(t)}function D(t,i,e,s){let r=(i||t).node(e),n=0,h=i?i.index(e):r.childCount;t&&(n=t.index(e),t.depth>e?n++:t.textOffset&&(T(t.nodeAfter,s),n++));for(let t=n;t<h;t++)T(r.child(t),s);i&&i.depth==e&&i.textOffset&&T(i.nodeBefore,s)}function A(t,i){return t.type.checkContent(i),t.copy(i)}function R(t,i,e,s,r){let n=t.depth>r&&O(t,i,r+1),h=s.depth>r&&O(e,s,r+1),o=[];return D(null,t,r,o),n&&h&&i.index(r)==e.index(r)?(x(n,h),T(A(n,R(t,i,e,s,r+1)),o)):(n&&T(A(n,E(t,i,r+1)),o),D(i,e,r,o),h&&T(A(h,E(e,s,r+1)),o)),D(s,null,r,o),new d(o)}function E(t,i,e){let s=[];return D(null,t,e,s),t.depth>e&&T(A(O(t,i,e+1),E(t,i,e+1)),s),D(i,null,e,s),new d(s)}b.empty=new b(d.empty,0,0);class ${constructor(t,i,e){this.pos=t,this.path=i,this.parentOffset=e,this.depth=i.length/3-1}resolveDepth(t){return null==t?this.depth:t<0?this.depth+t:t}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(t){return this.path[3*this.resolveDepth(t)]}index(t){return this.path[3*this.resolveDepth(t)+1]}indexAfter(t){return t=this.resolveDepth(t),this.index(t)+(t!=this.depth||this.textOffset?1:0)}start(t){return 0==(t=this.resolveDepth(t))?0:this.path[3*t-1]+1}end(t){return t=this.resolveDepth(t),this.start(t)+this.node(t).content.size}before(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position before the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]}after(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position after the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]+this.path[3*t].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let t=this.parent,i=this.index(this.depth);if(i==t.childCount)return null;let e=this.pos-this.path[this.path.length-1],s=t.child(i);return e?t.child(i).cut(e):s}get nodeBefore(){let t=this.index(this.depth),i=this.pos-this.path[this.path.length-1];return i?this.parent.child(t).cut(0,i):0==t?null:this.parent.child(t-1)}posAtIndex(t,i){i=this.resolveDepth(i);let e=this.path[3*i],s=0==i?0:this.path[3*i-1]+1;for(let i=0;i<t;i++)s+=e.child(i).nodeSize;return s}marks(){let t=this.parent,i=this.index();if(0==t.content.size)return g.none;if(this.textOffset)return t.child(i).marks;let e=t.maybeChild(i-1),s=t.maybeChild(i);if(!e){let t=e;e=s,s=t}let r=e.marks;for(var n=0;n<r.length;n++)!1!==r[n].type.spec.inclusive||s&&r[n].isInSet(s.marks)||(r=r[n--].removeFromSet(r));return r}marksAcross(t){let i=this.parent.maybeChild(this.index());if(!i||!i.isInline)return null;let e=i.marks,s=t.parent.maybeChild(t.index());for(var r=0;r<e.length;r++)!1!==e[r].type.spec.inclusive||s&&e[r].isInSet(s.marks)||(e=e[r--].removeFromSet(e));return e}sharedDepth(t){for(let i=this.depth;i>0;i--)if(this.start(i)<=t&&this.end(i)>=t)return i;return 0}blockRange(t=this,i){if(t.pos<this.pos)return t.blockRange(this);for(let e=this.depth-(this.parent.inlineContent||this.pos==t.pos?1:0);e>=0;e--)if(t.pos<=this.end(e)&&(!i||i(this.node(e))))return new I(this,t,e);return null}sameParent(t){return this.pos-this.parentOffset==t.pos-t.parentOffset}max(t){return t.pos>this.pos?t:this}min(t){return t.pos<this.pos?t:this}toString(){let t="";for(let i=1;i<=this.depth;i++)t+=(t?"/":"")+this.node(i).type.name+"_"+this.index(i-1);return t+":"+this.parentOffset}static resolve(t,i){if(!(i>=0&&i<=t.content.size))throw new RangeError("Position "+i+" out of range");let e=[],s=0,r=i;for(let i=t;;){let{index:t,offset:n}=i.content.findIndex(r),h=r-n;if(e.push(i,t,s+n),!h)break;if(i=i.child(t),i.isText)break;r=h-1,s+=n+1}return new $(i,e,r)}static resolveCached(t,i){let e=N.get(t);if(e)for(let t=0;t<e.elts.length;t++){let s=e.elts[t];if(s.pos==i)return s}else N.set(t,e=new C);let s=e.elts[e.i]=$.resolve(t,i);return e.i=(e.i+1)%P,s}}class C{constructor(){this.elts=[],this.i=0}}const P=12,N=new WeakMap;class I{constructor(t,i,e){this.$from=t,this.$to=i,this.depth=e}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 z=Object.create(null);class _{constructor(t,i,e,s=g.none){this.type=t,this.attrs=i,this.marks=s,this.content=e||d.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(t){return this.content.child(t)}maybeChild(t){return this.content.maybeChild(t)}forEach(t){this.content.forEach(t)}nodesBetween(t,i,e,s=0){this.content.nodesBetween(t,i,e,s,this)}descendants(t){this.nodesBetween(0,this.content.size,t)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(t,i,e,s){return this.content.textBetween(t,i,e,s)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(t){return this==t||this.sameMarkup(t)&&this.content.eq(t.content)}sameMarkup(t){return this.hasMarkup(t.type,t.attrs,t.marks)}hasMarkup(t,i,e){return this.type==t&&w(this.attrs,i||t.defaultAttrs||z)&&g.sameSet(this.marks,e||g.none)}copy(t=null){return t==this.content?this:new _(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new _(this.type,this.attrs,this.content,t)}cut(t,i=this.content.size){return 0==t&&i==this.content.size?this:this.copy(this.content.cut(t,i))}slice(t,i=this.content.size,e=!1){if(t==i)return b.empty;let s=this.resolve(t),r=this.resolve(i),n=e?0:s.sharedDepth(i),h=s.start(n),o=s.node(n).content.cut(s.pos-h,r.pos-h);return new b(o,s.depth-n,r.depth-n)}replace(t,i,e){return k(this.resolve(t),this.resolve(i),e)}nodeAt(t){for(let i=this;;){let{index:e,offset:s}=i.content.findIndex(t);if(i=i.maybeChild(e),!i)return null;if(s==t||i.isText)return i;t-=s+1}}childAfter(t){let{index:i,offset:e}=this.content.findIndex(t);return{node:this.content.maybeChild(i),index:i,offset:e}}childBefore(t){if(0==t)return{node:null,index:0,offset:0};let{index:i,offset:e}=this.content.findIndex(t);if(e<t)return{node:this.content.child(i),index:i,offset:e};let s=this.content.child(i-1);return{node:s,index:i-1,offset:e-s.nodeSize}}resolve(t){return $.resolveCached(this,t)}resolveNoCache(t){return $.resolve(this,t)}rangeHasMark(t,i,e){let s=!1;return i>t&&this.nodesBetween(t,i,(t=>(e.isInSet(t.marks)&&(s=!0),!s))),s}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 t=this.type.name;return this.content.size&&(t+="("+this.content.toStringInner()+")"),F(this.marks,t)}contentMatchAt(t){let i=this.type.contentMatch.matchFragment(this.content,0,t);if(!i)throw new Error("Called contentMatchAt on a node with invalid content");return i}canReplace(t,i,e=d.empty,s=0,r=e.childCount){let n=this.contentMatchAt(t).matchFragment(e,s,r),h=n&&n.matchFragment(this.content,i);if(!h||!h.validEnd)return!1;for(let t=s;t<r;t++)if(!this.type.allowsMarks(e.child(t).marks))return!1;return!0}canReplaceWith(t,i,e,s){if(s&&!this.type.allowsMarks(s))return!1;let r=this.contentMatchAt(t).matchType(e),n=r&&r.matchFragment(this.content,i);return!!n&&n.validEnd}canAppend(t){return t.content.size?this.canReplace(this.childCount,this.childCount,t.content):this.type.compatibleContent(t.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let t=g.none;for(let i=0;i<this.marks.length;i++){let e=this.marks[i];e.type.checkAttrs(e.attrs),t=e.addToSet(t)}if(!g.sameSet(t,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((t=>t.type.name))}`);this.content.forEach((t=>t.check()))}toJSON(){let t={type:this.type.name};for(let i in this.attrs){t.attrs=this.attrs;break}return this.content.size&&(t.content=this.content.toJSON()),this.marks.length&&(t.marks=this.marks.map((t=>t.toJSON()))),t}static fromJSON(t,i){if(!i)throw new RangeError("Invalid input for Node.fromJSON");let e;if(i.marks){if(!Array.isArray(i.marks))throw new RangeError("Invalid mark data for Node.fromJSON");e=i.marks.map(t.markFromJSON)}if("text"==i.type){if("string"!=typeof i.text)throw new RangeError("Invalid text node in JSON");return t.text(i.text,e)}let s=d.fromJSON(t,i.content),r=t.nodeType(i.type).create(i.attrs,s,e);return r.type.checkAttrs(r.attrs),r}}_.prototype.text=void 0;class j extends _{constructor(t,i,e,s){if(super(t,i,null,s),!e)throw new RangeError("Empty text nodes are not allowed");this.text=e}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):F(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(t,i){return this.text.slice(t,i)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new j(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new j(this.type,this.attrs,t,this.marks)}cut(t=0,i=this.text.length){return 0==t&&i==this.text.length?this:this.withText(this.text.slice(t,i))}eq(t){return this.sameMarkup(t)&&this.text==t.text}toJSON(){let t=super.toJSON();return t.text=this.text,t}}function F(t,i){for(let e=t.length-1;e>=0;e--)i=t[e].type.name+"("+i+")";return i}class B{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,i){let e=new W(t,i);if(null==e.next)return B.empty;let s=J(e);e.next&&e.err("Unexpected trailing text");let r=function(t){let i=Object.create(null);return function e(s){let r=[];s.forEach((i=>{t[i].forEach((({term:i,to:e})=>{if(!i)return;let s;for(let t=0;t<r.length;t++)r[t][0]==i&&(s=r[t][1]);K(t,e).forEach((t=>{s||r.push([i,s=[]]),-1==s.indexOf(t)&&s.push(t)}))}))}));let n=i[s.join(",")]=new B(s.indexOf(t.length-1)>-1);for(let t=0;t<r.length;t++){let s=r[t][1].sort(H);n.next.push({type:r[t][0],next:i[s.join(",")]||e(s)})}return n}(K(t,0))}(function(t){let i=[[]];return r(function t(i,n){if("choice"==i.type)return i.exprs.reduce(((i,e)=>i.concat(t(e,n))),[]);if("seq"!=i.type){if("star"==i.type){let h=e();return s(n,h),r(t(i.expr,h),h),[s(h)]}if("plus"==i.type){let h=e();return r(t(i.expr,n),h),r(t(i.expr,h),h),[s(h)]}if("opt"==i.type)return[s(n)].concat(t(i.expr,n));if("range"==i.type){let h=n;for(let s=0;s<i.min;s++){let s=e();r(t(i.expr,h),s),h=s}if(-1==i.max)r(t(i.expr,h),h);else for(let n=i.min;n<i.max;n++){let n=e();s(h,n),r(t(i.expr,h),n),h=n}return[s(h)]}if("name"==i.type)return[s(n,void 0,i.value)];throw new Error("Unknown expr type")}for(let s=0;;s++){let h=t(i.exprs[s],n);if(s==i.exprs.length-1)return h;r(h,n=e())}}(t,0),e()),i;function e(){return i.push([])-1}function s(t,e,s){let r={term:s,to:e};return i[t].push(r),r}function r(t,i){t.forEach((t=>t.to=i))}}(s));return function(t,i){for(let e=0,s=[t];e<s.length;e++){let t=s[e],r=!t.validEnd,n=[];for(let i=0;i<t.next.length;i++){let{type:e,next:h}=t.next[i];n.push(e.name),!r||e.isText||e.hasRequiredAttrs()||(r=!1),-1==s.indexOf(h)&&s.push(h)}r&&i.err("Only non-generatable nodes ("+n.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,e),r}matchType(t){for(let i=0;i<this.next.length;i++)if(this.next[i].type==t)return this.next[i].next;return null}matchFragment(t,i=0,e=t.childCount){let s=this;for(let r=i;s&&r<e;r++)s=s.matchType(t.child(r).type);return s}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let t=0;t<this.next.length;t++){let{type:i}=this.next[t];if(!i.isText&&!i.hasRequiredAttrs())return i}return null}compatible(t){for(let i=0;i<this.next.length;i++)for(let e=0;e<t.next.length;e++)if(this.next[i].type==t.next[e].type)return!0;return!1}fillBefore(t,i=!1,e=0){let s=[this];return function r(n,h){let o=n.matchFragment(t,e);if(o&&(!i||o.validEnd))return d.from(h.map((t=>t.createAndFill())));for(let t=0;t<n.next.length;t++){let{type:i,next:e}=n.next[t];if(!i.isText&&!i.hasRequiredAttrs()&&-1==s.indexOf(e)){s.push(e);let t=r(e,h.concat(i));if(t)return t}}return null}(this,[])}findWrapping(t){for(let i=0;i<this.wrapCache.length;i+=2)if(this.wrapCache[i]==t)return this.wrapCache[i+1];let i=this.computeWrapping(t);return this.wrapCache.push(t,i),i}computeWrapping(t){let i=Object.create(null),e=[{match:this,type:null,via:null}];for(;e.length;){let s=e.shift(),r=s.match;if(r.matchType(t)){let t=[];for(let i=s;i.type;i=i.via)t.push(i.type);return t.reverse()}for(let t=0;t<r.next.length;t++){let{type:n,next:h}=r.next[t];n.isLeaf||n.hasRequiredAttrs()||n.name in i||s.type&&!h.validEnd||(e.push({match:n.contentMatch,type:n,via:s}),i[n.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(t){if(t>=this.next.length)throw new RangeError(`There's no ${t}th edge in this content match`);return this.next[t]}toString(){let t=[];return function i(e){t.push(e);for(let s=0;s<e.next.length;s++)-1==t.indexOf(e.next[s].next)&&i(e.next[s].next)}(this),t.map(((i,e)=>{let s=e+(i.validEnd?"*":" ")+" ";for(let e=0;e<i.next.length;e++)s+=(e?", ":"")+i.next[e].type.name+"->"+t.indexOf(i.next[e].next);return s})).join("\n")}}B.empty=new B(!0);class W{constructor(t,i){this.string=t,this.nodeTypes=i,this.inline=null,this.pos=0,this.tokens=t.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(t){return this.next==t&&(this.pos++||!0)}err(t){throw new SyntaxError(t+" (in content expression '"+this.string+"')")}}function J(t){let i=[];do{i.push(L(t))}while(t.eat("|"));return 1==i.length?i[0]:{type:"choice",exprs:i}}function L(t){let i=[];do{i.push(Y(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==i.length?i[0]:{type:"seq",exprs:i}}function Y(t){let i=function(t){if(t.eat("(")){let i=J(t);return t.eat(")")||t.err("Missing closing paren"),i}if(!/\W/.test(t.next)){let i=function(t,i){let e=t.nodeTypes,s=e[i];if(s)return[s];let r=[];for(let t in e){let s=e[t];s.isInGroup(i)&&r.push(s)}return 0==r.length&&t.err("No node type or group '"+i+"' found"),r}(t,t.next).map((i=>(null==t.inline?t.inline=i.isInline:t.inline!=i.isInline&&t.err("Mixing inline and block content"),{type:"name",value:i})));return t.pos++,1==i.length?i[0]:{type:"choice",exprs:i}}t.err("Unexpected token '"+t.next+"'")}(t);for(;;)if(t.eat("+"))i={type:"plus",expr:i};else if(t.eat("*"))i={type:"star",expr:i};else if(t.eat("?"))i={type:"opt",expr:i};else{if(!t.eat("{"))break;i=U(t,i)}return i}function X(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let i=Number(t.next);return t.pos++,i}function U(t,i){let e=X(t),s=e;return t.eat(",")&&(s="}"!=t.next?X(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:e,max:s,expr:i}}function H(t,i){return i-t}function K(t,i){let e=[];return function i(s){let r=t[s];if(1==r.length&&!r[0].term)return i(r[0].to);e.push(s);for(let t=0;t<r.length;t++){let{term:s,to:n}=r[t];s||-1!=e.indexOf(n)||i(n)}}(i),e.sort(H)}function q(t){let i=Object.create(null);for(let e in t){let s=t[e];if(!s.hasDefault)return null;i[e]=s.default}return i}function G(t,i){let e=Object.create(null);for(let s in t){let r=i&&i[s];if(void 0===r){let i=t[s];if(!i.hasDefault)throw new RangeError("No value supplied for attribute "+s);r=i.default}e[s]=r}return e}function V(t,i,e){for(let s in i)if(!(s in t))throw new RangeError(`Unsupported attribute ${s} for ${e} of type ${s}`);for(let e in t){let s=t[e];s.validate&&s.validate(i[e])}}function Z(t,i){let e=Object.create(null);if(i)for(let s in i)e[s]=new tt(t,s,i[s]);return e}let Q=class t{constructor(t,i,e){this.name=t,this.schema=i,this.spec=e,this.markSet=null,this.groups=e.group?e.group.split(" "):[],this.attrs=Z(t,e.attrs),this.defaultAttrs=q(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(e.inline||"text"==t),this.isText="text"==t}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==B.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(t){return this.groups.indexOf(t)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let t in this.attrs)if(this.attrs[t].isRequired)return!0;return!1}compatibleContent(t){return this==t||this.contentMatch.compatible(t.contentMatch)}computeAttrs(t){return!t&&this.defaultAttrs?this.defaultAttrs:G(this.attrs,t)}create(t=null,i,e){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new _(this,this.computeAttrs(t),d.from(i),g.setFrom(e))}createChecked(t=null,i,e){return i=d.from(i),this.checkContent(i),new _(this,this.computeAttrs(t),i,g.setFrom(e))}createAndFill(t=null,i,e){if(t=this.computeAttrs(t),(i=d.from(i)).size){let t=this.contentMatch.fillBefore(i);if(!t)return null;i=t.append(i)}let s=this.contentMatch.matchFragment(i),r=s&&s.fillBefore(d.empty,!0);return r?new _(this,t,i.append(r),g.setFrom(e)):null}validContent(t){let i=this.contentMatch.matchFragment(t);if(!i||!i.validEnd)return!1;for(let i=0;i<t.childCount;i++)if(!this.allowsMarks(t.child(i).marks))return!1;return!0}checkContent(t){if(!this.validContent(t))throw new RangeError(`Invalid content for node ${this.name}: ${t.toString().slice(0,50)}`)}checkAttrs(t){V(this.attrs,t,"node")}allowsMarkType(t){return null==this.markSet||this.markSet.indexOf(t)>-1}allowsMarks(t){if(null==this.markSet)return!0;for(let i=0;i<t.length;i++)if(!this.allowsMarkType(t[i].type))return!1;return!0}allowedMarks(t){if(null==this.markSet)return t;let i;for(let e=0;e<t.length;e++)this.allowsMarkType(t[e].type)?i&&i.push(t[e]):i||(i=t.slice(0,e));return i?i.length?i:g.none:t}static compile(i,e){let s=Object.create(null);i.forEach(((i,r)=>s[i]=new t(i,e,r)));let r=e.spec.topNode||"doc";if(!s[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!s.text)throw new RangeError("Every schema needs a 'text' type");for(let t in s.text.attrs)throw new RangeError("The text node type should not have attributes");return s}};class tt{constructor(t,i,e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default,this.validate="string"==typeof e.validate?function(t,i,e){let s=e.split("|");return e=>{let r=null===e?"null":typeof e;if(s.indexOf(r)<0)throw new RangeError(`Expected value of type ${s} for attribute ${i} on type ${t}, got ${r}`)}}(t,i,e.validate):e.validate}get isRequired(){return!this.hasDefault}}class it{constructor(t,i,e,s){this.name=t,this.rank=i,this.schema=e,this.spec=s,this.attrs=Z(t,s.attrs),this.excluded=null;let r=q(this.attrs);this.instance=r?new g(this,r):null}create(t=null){return!t&&this.instance?this.instance:new g(this,G(this.attrs,t))}static compile(t,i){let e=Object.create(null),s=0;return t.forEach(((t,r)=>e[t]=new it(t,s++,i,r))),e}removeFromSet(t){for(var i=0;i<t.length;i++)t[i].type==this&&(t=t.slice(0,i).concat(t.slice(i+1)),i--);return t}isInSet(t){for(let i=0;i<t.length;i++)if(t[i].type==this)return t[i]}checkAttrs(t){V(this.attrs,t,"mark")}excludes(t){return this.excluded.indexOf(t)>-1}}class et{constructor(t){this.linebreakReplacement=null,this.cached=Object.create(null);let i=this.spec={};for(let e in t)i[e]=t[e];i.nodes=f.from(t.nodes),i.marks=f.from(t.marks||{}),this.nodes=Q.compile(this.spec.nodes,this),this.marks=it.compile(this.spec.marks,this);let e=Object.create(null);for(let t in this.nodes){if(t in this.marks)throw new RangeError(t+" can not be both a node and a mark");let i=this.nodes[t],s=i.spec.content||"",r=i.spec.marks;if(i.contentMatch=e[s]||(e[s]=B.parse(s,this.nodes)),i.inlineContent=i.contentMatch.inlineContent,i.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!i.isInline||!i.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=i}i.markSet="_"==r?null:r?st(this,r.split(" ")):""!=r&&i.inlineContent?null:[]}for(let t in this.marks){let i=this.marks[t],e=i.spec.excludes;i.excluded=null==e?[i]:""==e?[]:st(this,e.split(" "))}this.nodeFromJSON=t=>_.fromJSON(this,t),this.markFromJSON=t=>g.fromJSON(this,t),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(t,i=null,e,s){if("string"==typeof t)t=this.nodeType(t);else{if(!(t instanceof Q))throw new RangeError("Invalid node type: "+t);if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")")}return t.createChecked(i,e,s)}text(t,i){let e=this.nodes.text;return new j(e,e.defaultAttrs,t,g.setFrom(i))}mark(t,i){return"string"==typeof t&&(t=this.marks[t]),t.create(i)}nodeType(t){let i=this.nodes[t];if(!i)throw new RangeError("Unknown node type: "+t);return i}}function st(t,i){let e=[];for(let s=0;s<i.length;s++){let r=i[s],n=t.marks[r],h=n;if(n)e.push(n);else for(let i in t.marks){let s=t.marks[i];("_"==r||s.spec.group&&s.spec.group.split(" ").indexOf(r)>-1)&&e.push(h=s)}if(!h)throw new SyntaxError("Unknown mark type: '"+i[s]+"'")}return e}class rt{constructor(t,i){this.schema=t,this.rules=i,this.tags=[],this.styles=[];let e=this.matchedStyles=[];i.forEach((t=>{if(function(t){return null!=t.tag}(t))this.tags.push(t);else if(function(t){return null!=t.style}(t)){let i=/[^=]*/.exec(t.style)[0];e.indexOf(i)<0&&e.push(i),this.styles.push(t)}})),this.normalizeLists=!this.tags.some((i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let e=t.nodes[i.node];return e.contentMatch.matchType(e)}))}parse(t,i={}){let e=new ft(this,i,!1);return e.addAll(t,g.none,i.from,i.to),e.finish()}parseSlice(t,i={}){let e=new ft(this,i,!0);return e.addAll(t,g.none,i.from,i.to),b.maxOpen(e.finish())}matchTag(t,i,e){for(let s=e?this.tags.indexOf(e)+1:0;s<this.tags.length;s++){let e=this.tags[s];if(at(t,e.tag)&&(void 0===e.namespace||t.namespaceURI==e.namespace)&&(!e.context||i.matchesContext(e.context))){if(e.getAttrs){let i=e.getAttrs(t);if(!1===i)continue;e.attrs=i||void 0}return e}}}matchStyle(t,i,e,s){for(let r=s?this.styles.indexOf(s)+1:0;r<this.styles.length;r++){let s=this.styles[r],n=s.style;if(!(0!=n.indexOf(t)||s.context&&!e.matchesContext(s.context)||n.length>t.length&&(61!=n.charCodeAt(t.length)||n.slice(t.length+1)!=i))){if(s.getAttrs){let t=s.getAttrs(i);if(!1===t)continue;s.attrs=t||void 0}return s}}}static schemaRules(t){let i=[];function e(t){let e=null==t.priority?50:t.priority,s=0;for(;s<i.length;s++){let t=i[s];if((null==t.priority?50:t.priority)<e)break}i.splice(s,0,t)}for(let i in t.marks){let s=t.marks[i].spec.parseDOM;s&&s.forEach((t=>{e(t=ct(t)),t.mark||t.ignore||t.clearMark||(t.mark=i)}))}for(let i in t.nodes){let s=t.nodes[i].spec.parseDOM;s&&s.forEach((t=>{e(t=ct(t)),t.node||t.ignore||t.mark||(t.node=i)}))}return i}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new rt(t,rt.schemaRules(t)))}}const nt={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},ht={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ot={ol:!0,ul:!0};function lt(t,i,e){return null!=i?(i?1:0)|("full"===i?2:0):t&&"pre"==t.whitespace?3:-5&e}class ut{constructor(t,i,e,s,r,n){this.type=t,this.attrs=i,this.marks=e,this.solid=s,this.options=n,this.content=[],this.activeMarks=g.none,this.match=r||(4&n?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let i=this.type.contentMatch.fillBefore(d.from(t));if(!i){let i,e=this.type.contentMatch;return(i=e.findWrapping(t.type))?(this.match=e,i):null}this.match=this.type.contentMatch.matchFragment(i)}return this.match.findWrapping(t.type)}finish(t){if(!(1&this.options)){let t,i=this.content[this.content.length-1];if(i&&i.isText&&(t=/[ \t\r\n\u000c]+$/.exec(i.text))){let e=i;i.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=e.withText(e.text.slice(0,e.text.length-t[0].length))}}let i=d.from(this.content);return!t&&this.match&&(i=i.append(this.match.fillBefore(d.empty,!0))),this.type?this.type.create(this.attrs,i,this.marks):i}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!nt.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class ft{constructor(t,i,e){this.parser=t,this.options=i,this.isOpen=e,this.open=0,this.localPreserveWS=!1;let s,r=i.topNode,n=lt(null,i.preserveWhitespace,0)|(e?4:0);s=r?new ut(r.type,r.attrs,g.none,!0,i.topMatch||r.type.contentMatch,n):new ut(e?null:t.schema.topNodeType,null,g.none,!0,null,n),this.nodes=[s],this.find=i.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t,i){3==t.nodeType?this.addTextNode(t,i):1==t.nodeType&&this.addElement(t,i)}addTextNode(t,i){let e=t.nodeValue,s=this.top,r=2&s.options?"full":this.localPreserveWS||(1&s.options)>0,{schema:n}=this.parser;if("full"===r||s.inlineContext(t)||/[^ \t\r\n\u000c]/.test(e)){if(r)if("full"===r)e=e.replace(/\r\n?/g,"\n");else if(n.linebreakReplacement&&/[\r\n]/.test(e)&&this.top.findWrapping(n.linebreakReplacement.create())){let t=e.split(/\r?\n|\r/);for(let e=0;e<t.length;e++)e&&this.insertNode(n.linebreakReplacement.create(),i,!0),t[e]&&this.insertNode(n.text(t[e]),i,!/\S/.test(t[e]));e=""}else e=e.replace(/\r?\n|\r/g," ");else if(e=e.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(e)&&this.open==this.nodes.length-1){let i=s.content[s.content.length-1],r=t.previousSibling;(!i||r&&"BR"==r.nodeName||i.isText&&/[ \t\r\n\u000c]$/.test(i.text))&&(e=e.slice(1))}e&&this.insertNode(n.text(e),i,!/\S/.test(e)),this.findInText(t)}else this.findInside(t)}addElement(t,i,e){let s=this.localPreserveWS,r=this.top;("PRE"==t.tagName||/pre/.test(t.style&&t.style.whiteSpace))&&(this.localPreserveWS=!0);let n,h=t.nodeName.toLowerCase();ot.hasOwnProperty(h)&&this.parser.normalizeLists&&function(t){for(let i=t.firstChild,e=null;i;i=i.nextSibling){let t=1==i.nodeType?i.nodeName.toLowerCase():null;t&&ot.hasOwnProperty(t)&&e?(e.appendChild(i),i=e):"li"==t?e=i:t&&(e=null)}}(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(n=this.parser.matchTag(t,this,e));t:if(o?o.ignore:ht.hasOwnProperty(h))this.findInside(t),this.ignoreFallback(t,i);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(t=o.skip);let e,s=this.needsBlock;if(nt.hasOwnProperty(h))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),e=!0,r.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t,i);break t}let n=o&&o.skip?i:this.readStyles(t,i);n&&this.addAll(t,n),e&&this.sync(r),this.needsBlock=s}else{let e=this.readStyles(t,i);e&&this.addElementByRule(t,o,e,!1===o.consuming?n:void 0)}this.localPreserveWS=s}leafFallback(t,i){"BR"==t.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode("\n"),i)}ignoreFallback(t,i){"BR"!=t.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),i,!0)}readStyles(t,i){let e=t.style;if(e&&e.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let s=this.parser.matchedStyles[t],r=e.getPropertyValue(s);if(r)for(let t;;){let e=this.parser.matchStyle(s,r,this,t);if(!e)break;if(e.ignore)return null;if(i=e.clearMark?i.filter((t=>!e.clearMark(t))):i.concat(this.parser.schema.marks[e.mark].create(e.attrs)),!1!==e.consuming)break;t=e}}return i}addElementByRule(t,i,e,s){let r,n;if(i.node)if(n=this.parser.schema.nodes[i.node],n.isLeaf)this.insertNode(n.create(i.attrs),e,"BR"==t.nodeName)||this.leafFallback(t,e);else{let t=this.enter(n,i.attrs||null,e,i.preserveWhitespace);t&&(r=!0,e=t)}else e=e.concat(this.parser.schema.marks[i.mark].create(i.attrs));let h=this.top;if(n&&n.isLeaf)this.findInside(t);else if(s)this.addElement(t,e,s);else if(i.getContent)this.findInside(t),i.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,e,!1)));else{let s=t;"string"==typeof i.contentElement?s=t.querySelector(i.contentElement):"function"==typeof i.contentElement?s=i.contentElement(t):i.contentElement&&(s=i.contentElement),this.findAround(t,s,!0),this.addAll(s,e),this.findAround(t,s,!1)}r&&this.sync(h)&&this.open--}addAll(t,i,e,s){let r=e||0;for(let n=e?t.childNodes[e]:t.firstChild,h=null==s?null:t.childNodes[s];n!=h;n=n.nextSibling,++r)this.findAtPoint(t,r),this.addDOM(n,i);this.findAtPoint(t,r)}findPlace(t,i,e){let s,r;for(let i=this.open,n=0;i>=0;i--){let h=this.nodes[i],o=h.findWrapping(t);if(o&&(!s||s.length>o.length+n)&&(s=o,r=h,!o.length))break;if(h.solid){if(e)break;n+=2}}if(!s)return null;this.sync(r);for(let t=0;t<s.length;t++)i=this.enterInner(s[t],null,i,!1);return i}insertNode(t,i,e){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();t&&(i=this.enterInner(t,null,i))}let s=this.findPlace(t,i,e);if(s){this.closeExtra();let i=this.top;i.match&&(i.match=i.match.matchType(t.type));let e=g.none;for(let r of s.concat(t.marks))(i.type?i.type.allowsMarkType(r.type):dt(r.type,t.type))&&(e=r.addToSet(e));return i.content.push(t.mark(e)),!0}return!1}enter(t,i,e,s){let r=this.findPlace(t.create(i),e,!1);return r&&(r=this.enterInner(t,i,e,!0,s)),r}enterInner(t,i,e,s=!1,r){this.closeExtra();let n=this.top;n.match=n.match&&n.match.matchType(t);let h=lt(t,r,n.options);4&n.options&&0==n.content.length&&(h|=4);let o=g.none;return e=e.filter((i=>!(n.type?n.type.allowsMarkType(i.type):dt(i.type,t))||(o=i.addToSet(o),!1))),this.nodes.push(new ut(t,i,o,s,null,h)),this.open++,e}closeExtra(t=!1){let i=this.nodes.length-1;if(i>this.open){for(;i>this.open;i--)this.nodes[i-1].content.push(this.nodes[i].finish(t));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(t){for(let i=this.open;i>=0;i--){if(this.nodes[i]==t)return this.open=i,!0;this.localPreserveWS&&(this.nodes[i].options|=1)}return!1}get currentPos(){this.closeExtra();let t=0;for(let i=this.open;i>=0;i--){let e=this.nodes[i].content;for(let i=e.length-1;i>=0;i--)t+=e[i].nodeSize;i&&t++}return t}findAtPoint(t,i){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].node==t&&this.find[e].offset==i&&(this.find[e].pos=this.currentPos)}findInside(t){if(this.find)for(let i=0;i<this.find.length;i++)null==this.find[i].pos&&1==t.nodeType&&t.contains(this.find[i].node)&&(this.find[i].pos=this.currentPos)}findAround(t,i,e){if(t!=i&&this.find)for(let s=0;s<this.find.length;s++)null==this.find[s].pos&&1==t.nodeType&&t.contains(this.find[s].node)&&i.compareDocumentPosition(this.find[s].node)&(e?2:4)&&(this.find[s].pos=this.currentPos)}findInText(t){if(this.find)for(let i=0;i<this.find.length;i++)this.find[i].node==t&&(this.find[i].pos=this.currentPos-(t.nodeValue.length-this.find[i].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let i=t.split("/"),e=this.options.context,s=!(this.isOpen||e&&e.parent.type!=this.nodes[0].type),r=(s?0:1)-(e?e.depth+1:0),n=(t,h)=>{for(;t>=0;t--){let o=i[t];if(""==o){if(t==i.length-1||0==t)continue;for(;h>=r;h--)if(n(t-1,h))return!0;return!1}{let t=h>0||0==h&&s?this.nodes[h].type:e&&h>=r?e.node(h-r).type:null;if(!t||t.name!=o&&!t.isInGroup(o))return!1;h--}}return!0};return n(i.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let i=t.depth;i>=0;i--){let e=t.node(i).contentMatchAt(t.indexAfter(i)).defaultType;if(e&&e.isTextblock&&e.defaultAttrs)return e}for(let t in this.parser.schema.nodes){let i=this.parser.schema.nodes[t];if(i.isTextblock&&i.defaultAttrs)return i}}}function at(t,i){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,i)}function ct(t){let i={};for(let e in t)i[e]=t[e];return i}function dt(t,i){let e=i.schema.nodes;for(let s in e){let r=e[s];if(!r.allowsMarkType(t))continue;let n=[],h=t=>{n.push(t);for(let e=0;e<t.edgeCount;e++){let{type:s,next:r}=t.edge(e);if(s==i)return!0;if(n.indexOf(r)<0&&h(r))return!0}};if(h(r.contentMatch))return!0}}class pt{constructor(t,i){this.nodes=t,this.marks=i}serializeFragment(t,i={},e){e||(e=wt(i).createDocumentFragment());let s=e,r=[];return t.forEach((t=>{if(r.length||t.marks.length){let e=0,n=0;for(;e<r.length&&n<t.marks.length;){let i=t.marks[n];if(this.marks[i.type.name]){if(!i.eq(r[e][0])||!1===i.type.spec.spanning)break;e++,n++}else n++}for(;e<r.length;)s=r.pop()[1];for(;n<t.marks.length;){let e=t.marks[n++],h=this.serializeMark(e,t.isInline,i);h&&(r.push([e,s]),s.appendChild(h.dom),s=h.contentDOM||h.dom)}}s.appendChild(this.serializeNodeInner(t,i))})),e}serializeNodeInner(t,i){let{dom:e,contentDOM:s}=yt(wt(i),this.nodes[t.type.name](t),null,t.attrs);if(s){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,i,s)}return e}serializeNode(t,i={}){let e=this.serializeNodeInner(t,i);for(let s=t.marks.length-1;s>=0;s--){let r=this.serializeMark(t.marks[s],t.isInline,i);r&&((r.contentDOM||r.dom).appendChild(e),e=r.dom)}return e}serializeMark(t,i,e={}){let s=this.marks[t.type.name];return s&&yt(wt(e),s(t,i),null,t.attrs)}static renderSpec(t,i,e=null,s){return yt(t,i,e,s)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new pt(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let i=mt(t.nodes);return i.text||(i.text=t=>t.text),i}static marksFromSchema(t){return mt(t.marks)}}function mt(t){let i={};for(let e in t){let s=t[e].spec.toDOM;s&&(i[e]=s)}return i}function wt(t){return t.document||window.document}const gt=new WeakMap;function yt(t,i,e,s){if("string"==typeof i)return{dom:t.createTextNode(i)};if(null!=i.nodeType)return{dom:i};if(i.dom&&null!=i.dom.nodeType)return i;let r,n=i[0];if("string"!=typeof n)throw new RangeError("Invalid array passed to renderSpec");if(s&&(r=function(t){let i=gt.get(t);return void 0===i&>.set(t,i=function(t){let i=null;return function t(e){if(e&&"object"==typeof e)if(Array.isArray(e))if("string"==typeof e[0])i||(i=[]),i.push(e);else for(let i=0;i<e.length;i++)t(e[i]);else for(let i in e)t(e[i])}(t),i}(t)),i}(s))&&r.indexOf(i)>-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 h,o=n.indexOf(" ");o>0&&(e=n.slice(0,o),n=n.slice(o+1));let l=e?t.createElementNS(e,n):t.createElement(n),u=i[1],f=1;if(u&&"object"==typeof u&&null==u.nodeType&&!Array.isArray(u)){f=2;for(let t in u)if(null!=u[t]){let i=t.indexOf(" ");i>0?l.setAttributeNS(t.slice(0,i),t.slice(i+1),u[t]):"style"==t&&l.style?l.style.cssText=u[t]:l.setAttribute(t,u[t])}}for(let r=f;r<i.length;r++){let n=i[r];if(0===n){if(r<i.length-1||r>f)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:i,contentDOM:r}=yt(t,n,e,s);if(l.appendChild(i),r){if(h)throw new RangeError("Multiple content holes");h=r}}}return{dom:l,contentDOM:h}}const bt=Math.pow(2,16);function Mt(t){return 65535&t}class vt{constructor(t,i,e){this.pos=t,this.delInfo=i,this.recover=e}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 kt{constructor(t,i=!1){if(this.ranges=t,this.inverted=i,!t.length&&kt.empty)return kt.empty}recover(t){let i=0,e=Mt(t);if(!this.inverted)for(let t=0;t<e;t++)i+=this.ranges[3*t+2]-this.ranges[3*t+1];return this.ranges[3*e]+i+function(t){return(t-(65535&t))/bt}(t)}mapResult(t,i=1){return this._map(t,i,!1)}map(t,i=1){return this._map(t,i,!0)}_map(t,i,e){let s=0,r=this.inverted?2:1,n=this.inverted?1:2;for(let h=0;h<this.ranges.length;h+=3){let o=this.ranges[h]-(this.inverted?s:0);if(o>t)break;let l=this.ranges[h+r],u=this.ranges[h+n],f=o+l;if(t<=f){let r=o+s+((l?t==o?-1:t==f?1:i:i)<0?0:u);if(e)return r;let n=t==o?2:t==f?1:4;return(i<0?t!=o:t!=f)&&(n|=8),new vt(r,n,t==(i<0?o:f)?null:h/3+(t-o)*bt)}s+=u-l}return e?t+s:new vt(t+s,0,null)}touches(t,i){let e=0,s=Mt(i),r=this.inverted?2:1,n=this.inverted?1:2;for(let i=0;i<this.ranges.length;i+=3){let h=this.ranges[i]-(this.inverted?e:0);if(h>t)break;let o=this.ranges[i+r];if(t<=h+o&&i==3*s)return!0;e+=this.ranges[i+n]-o}return!1}forEach(t){let i=this.inverted?2:1,e=this.inverted?1:2;for(let s=0,r=0;s<this.ranges.length;s+=3){let n=this.ranges[s],h=n-(this.inverted?r:0),o=n+(this.inverted?0:r),l=this.ranges[s+i],u=this.ranges[s+e];t(h,h+l,o,o+u),r+=u-l}}invert(){return new kt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?kt.empty:new kt(t<0?[0,-t,0]:[0,0,t])}}kt.empty=new kt([]);class St{constructor(t,i,e=0,s=(t?t.length:0)){this.mirror=i,this.from=e,this.to=s,this._maps=t||[],this.ownData=!(t||i)}get maps(){return this._maps}slice(t=0,i=this.maps.length){return new St(this._maps,this.mirror,t,i)}appendMap(t,i){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(t),null!=i&&this.setMirror(this._maps.length-1,i)}appendMapping(t){for(let i=0,e=this._maps.length;i<t._maps.length;i++){let s=t.getMirror(i);this.appendMap(t._maps[i],null!=s&&s<i?e+s:void 0)}}getMirror(t){if(this.mirror)for(let i=0;i<this.mirror.length;i++)if(this.mirror[i]==t)return this.mirror[i+(i%2?-1:1)]}setMirror(t,i){this.mirror||(this.mirror=[]),this.mirror.push(t,i)}appendMappingInverted(t){for(let i=t.maps.length-1,e=this._maps.length+t._maps.length;i>=0;i--){let s=t.getMirror(i);this.appendMap(t._maps[i].invert(),null!=s&&s>i?e-s-1:void 0)}}invert(){let t=new St;return t.appendMappingInverted(this),t}map(t,i=1){if(this.mirror)return this._map(t,i,!0);for(let e=this.from;e<this.to;e++)t=this._maps[e].map(t,i);return t}mapResult(t,i=1){return this._map(t,i,!1)}_map(t,i,e){let s=0;for(let e=this.from;e<this.to;e++){let r=this._maps[e].mapResult(t,i);if(null!=r.recover){let i=this.getMirror(e);if(null!=i&&i>e&&i<this.to){e=i,t=this._maps[i].recover(r.recover);continue}}s|=r.delInfo,t=r.pos}return e?t:new vt(t,s,null)}}const xt=Object.create(null);class Ot{getMap(){return kt.empty}merge(t){return null}static fromJSON(t,i){if(!i||!i.stepType)throw new RangeError("Invalid input for Step.fromJSON");let e=xt[i.stepType];if(!e)throw new RangeError(`No step type ${i.stepType} defined`);return e.fromJSON(t,i)}static jsonID(t,i){if(t in xt)throw new RangeError("Duplicate use of step JSON ID "+t);return xt[t]=i,i.prototype.jsonID=t,i}}class Tt{constructor(t,i){this.doc=t,this.failed=i}static ok(t){return new Tt(t,null)}static fail(t){return new Tt(null,t)}static fromReplace(t,i,e,s){try{return Tt.ok(t.replace(i,e,s))}catch(t){if(t instanceof y)return Tt.fail(t.message);throw t}}}function Dt(t,i,e){let s=[];for(let r=0;r<t.childCount;r++){let n=t.child(r);n.content.size&&(n=n.copy(Dt(n.content,i,n))),n.isInline&&(n=i(n,e,r)),s.push(n)}return d.fromArray(s)}class At extends Ot{constructor(t,i,e){super(),this.from=t,this.to=i,this.mark=e}apply(t){let i=t.slice(this.from,this.to),e=t.resolve(this.from),s=e.node(e.sharedDepth(this.to)),r=new b(Dt(i.content,((t,i)=>t.isAtom&&i.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),s),i.openStart,i.openEnd);return Tt.fromReplace(t,this.from,this.to,r)}invert(){return new Rt(this.from,this.to,this.mark)}map(t){let i=t.mapResult(this.from,1),e=t.mapResult(this.to,-1);return i.deleted&&e.deleted||i.pos>=e.pos?null:new At(i.pos,e.pos,this.mark)}merge(t){return t instanceof At&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new At(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,i){if("number"!=typeof i.from||"number"!=typeof i.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new At(i.from,i.to,t.markFromJSON(i.mark))}}Ot.jsonID("addMark",At);class Rt extends Ot{constructor(t,i,e){super(),this.from=t,this.to=i,this.mark=e}apply(t){let i=t.slice(this.from,this.to),e=new b(Dt(i.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),i.openStart,i.openEnd);return Tt.fromReplace(t,this.from,this.to,e)}invert(){return new At(this.from,this.to,this.mark)}map(t){let i=t.mapResult(this.from,1),e=t.mapResult(this.to,-1);return i.deleted&&e.deleted||i.pos>=e.pos?null:new Rt(i.pos,e.pos,this.mark)}merge(t){return t instanceof Rt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Rt(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,i){if("number"!=typeof i.from||"number"!=typeof i.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Rt(i.from,i.to,t.markFromJSON(i.mark))}}Ot.jsonID("removeMark",Rt);class Et extends Ot{constructor(t,i){super(),this.pos=t,this.mark=i}apply(t){let i=t.nodeAt(this.pos);if(!i)return Tt.fail("No node at mark step's position");let e=i.type.create(i.attrs,null,this.mark.addToSet(i.marks));return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(e),0,i.isLeaf?0:1))}invert(t){let i=t.nodeAt(this.pos);if(i){let t=this.mark.addToSet(i.marks);if(t.length==i.marks.length){for(let e=0;e<i.marks.length;e++)if(!i.marks[e].isInSet(t))return new Et(this.pos,i.marks[e]);return new Et(this.pos,this.mark)}}return new $t(this.pos,this.mark)}map(t){let i=t.mapResult(this.pos,1);return i.deletedAfter?null:new Et(i.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,i){if("number"!=typeof i.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Et(i.pos,t.markFromJSON(i.mark))}}Ot.jsonID("addNodeMark",Et);class $t extends Ot{constructor(t,i){super(),this.pos=t,this.mark=i}apply(t){let i=t.nodeAt(this.pos);if(!i)return Tt.fail("No node at mark step's position");let e=i.type.create(i.attrs,null,this.mark.removeFromSet(i.marks));return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(e),0,i.isLeaf?0:1))}invert(t){let i=t.nodeAt(this.pos);return i&&this.mark.isInSet(i.marks)?new Et(this.pos,this.mark):this}map(t){let i=t.mapResult(this.pos,1);return i.deletedAfter?null:new $t(i.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,i){if("number"!=typeof i.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new $t(i.pos,t.markFromJSON(i.mark))}}Ot.jsonID("removeNodeMark",$t);class Ct extends Ot{constructor(t,i,e,s=!1){super(),this.from=t,this.to=i,this.slice=e,this.structure=s}apply(t){return this.structure&&Nt(t,this.from,this.to)?Tt.fail("Structure replace would overwrite content"):Tt.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new kt([this.from,this.to-this.from,this.slice.size])}invert(t){return new Ct(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let i=t.mapResult(this.to,-1),e=this.from==this.to&&Ct.MAP_BIAS<0?i:t.mapResult(this.from,1);return e.deletedAcross&&i.deletedAcross?null:new Ct(e.pos,Math.max(e.pos,i.pos),this.slice,this.structure)}merge(t){if(!(t instanceof Ct)||t.structure||this.structure)return null;if(this.from+this.slice.size!=t.from||this.slice.openEnd||t.slice.openStart){if(t.to!=this.from||this.slice.openStart||t.slice.openEnd)return null;{let i=this.slice.size+t.slice.size==0?b.empty:new b(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new Ct(t.from,this.to,i,this.structure)}}{let i=this.slice.size+t.slice.size==0?b.empty:new b(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new Ct(this.from,this.to+(t.to-t.from),i,this.structure)}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,i){if("number"!=typeof i.from||"number"!=typeof i.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Ct(i.from,i.to,b.fromJSON(t,i.slice),!!i.structure)}}Ct.MAP_BIAS=1,Ot.jsonID("replace",Ct);class Pt extends Ot{constructor(t,i,e,s,r,n,h=!1){super(),this.from=t,this.to=i,this.gapFrom=e,this.gapTo=s,this.slice=r,this.insert=n,this.structure=h}apply(t){if(this.structure&&(Nt(t,this.from,this.gapFrom)||Nt(t,this.gapTo,this.to)))return Tt.fail("Structure gap-replace would overwrite content");let i=t.slice(this.gapFrom,this.gapTo);if(i.openStart||i.openEnd)return Tt.fail("Gap is not a flat range");let e=this.slice.insertAt(this.insert,i.content);return e?Tt.fromReplace(t,this.from,this.to,e):Tt.fail("Content does not fit in gap")}getMap(){return new kt([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let i=this.gapTo-this.gapFrom;return new Pt(this.from,this.from+this.slice.size+i,this.from+this.insert,this.from+this.insert+i,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let i=t.mapResult(this.from,1),e=t.mapResult(this.to,-1),s=this.from==this.gapFrom?i.pos:t.map(this.gapFrom,-1),r=this.to==this.gapTo?e.pos:t.map(this.gapTo,1);return i.deletedAcross&&e.deletedAcross||s<i.pos||r>e.pos?null:new Pt(i.pos,e.pos,s,r,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,i){if("number"!=typeof i.from||"number"!=typeof i.to||"number"!=typeof i.gapFrom||"number"!=typeof i.gapTo||"number"!=typeof i.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Pt(i.from,i.to,i.gapFrom,i.gapTo,b.fromJSON(t,i.slice),i.insert,!!i.structure)}}function Nt(t,i,e){let s=t.resolve(i),r=e-i,n=s.depth;for(;r>0&&n>0&&s.indexAfter(n)==s.node(n).childCount;)n--,r--;if(r>0){let t=s.node(n).maybeChild(s.indexAfter(n));for(;r>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,r--}}return!1}function It(t,i,e,s=e.contentMatch,r=!0){let n=t.doc.nodeAt(i),h=[],o=i+1;for(let i=0;i<n.childCount;i++){let l=n.child(i),u=o+l.nodeSize,f=s.matchType(l.type);if(f){s=f;for(let i=0;i<l.marks.length;i++)e.allowsMarkType(l.marks[i].type)||t.step(new Rt(o,u,l.marks[i]));if(r&&l.isText&&"pre"!=e.whitespace){let t,i,s=/\r?\n|\r/g;for(;t=s.exec(l.text);)i||(i=new b(d.from(e.schema.text(" ",e.allowedMarks(l.marks))),0,0)),h.push(new Ct(o+t.index,o+t.index+t[0].length,i))}}else h.push(new Ct(o,u,b.empty));o=u}if(!s.validEnd){let i=s.fillBefore(d.empty,!0);t.replace(o,o,new b(i,0,0))}for(let i=h.length-1;i>=0;i--)t.step(h[i])}function zt(t,i,e){return(0==i||t.canReplace(i,t.childCount))&&(e==t.childCount||t.canReplace(0,e))}function _t(t){let i=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let e=t.depth,s=0,r=0;;--e){let n=t.$from.node(e),h=t.$from.index(e)+s,o=t.$to.indexAfter(e)-r;if(e<t.depth&&n.canReplace(h,o,i))return e;if(0==e||n.type.spec.isolating||!zt(n,h,o))break;h&&(s=1),o<n.childCount&&(r=1)}return null}function jt(t,i,e,s){i.forEach(((r,n)=>{if(r.isText){let h,o=/\r?\n|\r/g;for(;h=o.exec(r.text);){let r=t.mapping.slice(s).map(e+1+n+h.index);t.replaceWith(r,r+1,i.type.schema.linebreakReplacement.create())}}}))}function Ft(t,i,e,s){i.forEach(((r,n)=>{if(r.type==r.type.schema.linebreakReplacement){let r=t.mapping.slice(s).map(e+1+n);t.replaceWith(r,r+1,i.type.schema.text("\n"))}}))}function Bt(t,i,e=1,s){let r=t.resolve(i),n=r.depth-e,h=s&&s[s.length-1]||r.parent;if(n<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!h.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let t=r.depth-1,i=e-2;t>n;t--,i--){let e=r.node(t),n=r.index(t);if(e.type.spec.isolating)return!1;let h=e.content.cutByIndex(n,e.childCount),o=s&&s[i+1];o&&(h=h.replaceChild(0,o.type.create(o.attrs)));let l=s&&s[i]||e;if(!e.canReplace(n+1,e.childCount)||!l.type.validContent(h))return!1}let o=r.indexAfter(n),l=s&&s[0];return r.node(n).canReplaceWith(o,o,l?l.type:r.node(n+1).type)}function Wt(t,i){let e=t.resolve(i),s=e.index();return n=e.nodeAfter,!(!(r=e.nodeBefore)||!n||r.isLeaf||!function(t,i){i.content.size||t.type.compatibleContent(i.type);let e=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let r=0;r<i.childCount;r++){let n=i.child(r);if(e=e.matchType(n.type==s?t.type.schema.nodes.text:n.type),!e)return!1;if(!t.type.allowsMarks(n.marks))return!1}return e.validEnd}(r,n))&&e.parent.canReplace(s,s+1);var r,n}function Jt(t,i,e=i,s=b.empty){if(i==e&&!s.size)return null;let r=t.resolve(i),n=t.resolve(e);return Lt(r,n,s)?new Ct(i,e,s):new Yt(r,n,s).fit()}function Lt(t,i,e){return!e.openStart&&!e.openEnd&&t.start()==i.start()&&t.parent.canReplace(t.index(),i.index(),e.content)}Ot.jsonID("replaceAround",Pt);class Yt{constructor(t,i,e){this.$from=t,this.$to=i,this.unplaced=e,this.frontier=[],this.placed=d.empty;for(let i=0;i<=t.depth;i++){let e=t.node(i);this.frontier.push({type:e.type,match:e.contentMatchAt(t.indexAfter(i))})}for(let i=t.depth;i>0;i--)this.placed=d.from(t.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let t=this.findFittable();t?this.placeNodes(t):this.openMore()||this.dropNode()}let t=this.mustMoveInline(),i=this.placed.size-this.depth-this.$from.depth,e=this.$from,s=this.close(t<0?this.$to:e.doc.resolve(t));if(!s)return null;let r=this.placed,n=e.depth,h=s.depth;for(;n&&h&&1==r.childCount;)r=r.firstChild.content,n--,h--;let o=new b(r,n,h);return t>-1?new Pt(e.pos,t,this.$to.pos,this.$to.end(),o,i):o.size||e.pos!=this.$to.pos?new Ct(e.pos,s.pos,o):null}findFittable(){let t=this.unplaced.openStart;for(let i=this.unplaced.content,e=0,s=this.unplaced.openEnd;e<t;e++){let r=i.firstChild;if(i.childCount>1&&(s=0),r.type.spec.isolating&&s<=e){t=e;break}i=r.content}for(let i=1;i<=2;i++)for(let e=1==i?t:this.unplaced.openStart;e>=0;e--){let t,s=null;e?(s=Ht(this.unplaced.content,e-1).firstChild,t=s.content):t=this.unplaced.content;let r=t.firstChild;for(let t=this.depth;t>=0;t--){let n,{type:h,match:o}=this.frontier[t],l=null;if(1==i&&(r?o.matchType(r.type)||(l=o.fillBefore(d.from(r),!1)):s&&h.compatibleContent(s.type)))return{sliceDepth:e,frontierDepth:t,parent:s,inject:l};if(2==i&&r&&(n=o.findWrapping(r.type)))return{sliceDepth:e,frontierDepth:t,parent:s,wrap:n};if(s&&o.matchType(s.type))break}}}openMore(){let{content:t,openStart:i,openEnd:e}=this.unplaced,s=Ht(t,i);return!(!s.childCount||s.firstChild.isLeaf||(this.unplaced=new b(t,i+1,Math.max(e,s.size+i>=t.size-e?i+1:0)),0))}dropNode(){let{content:t,openStart:i,openEnd:e}=this.unplaced,s=Ht(t,i);if(s.childCount<=1&&i>0){let r=t.size-i<=i+s.size;this.unplaced=new b(Xt(t,i-1,1),i-1,r?i-1:e)}else this.unplaced=new b(Xt(t,i,1),i,e)}placeNodes({sliceDepth:t,frontierDepth:i,parent:e,inject:s,wrap:r}){for(;this.depth>i;)this.closeFrontierNode();if(r)for(let t=0;t<r.length;t++)this.openFrontierNode(r[t]);let n=this.unplaced,h=e?e.content:n.content,o=n.openStart-t,l=0,u=[],{match:f,type:a}=this.frontier[i];if(s){for(let t=0;t<s.childCount;t++)u.push(s.child(t));f=f.matchFragment(s)}let c=h.size+t-(n.content.size-n.openEnd);for(;l<h.childCount;){let t=h.child(l),i=f.matchType(t.type);if(!i)break;l++,(l>1||0==o||t.content.size)&&(f=i,u.push(Kt(t.mark(a.allowedMarks(t.marks)),1==l?o:0,l==h.childCount?c:-1)))}let p=l==h.childCount;p||(c=-1),this.placed=Ut(this.placed,i,d.from(u)),this.frontier[i].match=f,p&&c<0&&e&&e.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,i=h;t<c;t++){let t=i.lastChild;this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)}),i=t.content}this.unplaced=p?0==t?b.empty:new b(Xt(n.content,t-1,1),t-1,c<0?n.openEnd:t-1):new b(Xt(n.content,t,l),n.openStart,n.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t,i=this.frontier[this.depth];if(!i.type.isTextblock||!qt(this.$to,this.$to.depth,i.type,i.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:e}=this.$to,s=this.$to.after(e);for(;e>1&&s==this.$to.end(--e);)++s;return s}findCloseLevel(t){t:for(let i=Math.min(this.depth,t.depth);i>=0;i--){let{match:e,type:s}=this.frontier[i],r=i<t.depth&&t.end(i+1)==t.pos+(t.depth-(i+1)),n=qt(t,i,s,e,r);if(n){for(let e=i-1;e>=0;e--){let{match:i,type:s}=this.frontier[e],r=qt(t,e,s,i,!0);if(!r||r.childCount)continue t}return{depth:i,fit:n,move:r?t.doc.resolve(t.after(i+1)):t}}}}close(t){let i=this.findCloseLevel(t);if(!i)return null;for(;this.depth>i.depth;)this.closeFrontierNode();i.fit.childCount&&(this.placed=Ut(this.placed,i.depth,i.fit)),t=i.move;for(let e=i.depth+1;e<=t.depth;e++){let i=t.node(e),s=i.type.contentMatch.fillBefore(i.content,!0,t.index(e));this.openFrontierNode(i.type,i.attrs,s)}return t}openFrontierNode(t,i=null,e){let s=this.frontier[this.depth];s.match=s.match.matchType(t),this.placed=Ut(this.placed,this.depth,d.from(t.create(i,e))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(d.empty,!0);t.childCount&&(this.placed=Ut(this.placed,this.frontier.length,t))}}function Xt(t,i,e){return 0==i?t.cutByIndex(e,t.childCount):t.replaceChild(0,t.firstChild.copy(Xt(t.firstChild.content,i-1,e)))}function Ut(t,i,e){return 0==i?t.append(e):t.replaceChild(t.childCount-1,t.lastChild.copy(Ut(t.lastChild.content,i-1,e)))}function Ht(t,i){for(let e=0;e<i;e++)t=t.firstChild.content;return t}function Kt(t,i,e){if(i<=0)return t;let s=t.content;return i>1&&(s=s.replaceChild(0,Kt(s.firstChild,i-1,1==s.childCount?e-1:0))),i>0&&(s=t.type.contentMatch.fillBefore(s).append(s),e<=0&&(s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(d.empty,!0)))),t.copy(s)}function qt(t,i,e,s,r){let n=t.node(i),h=r?t.indexAfter(i):t.index(i);if(h==n.childCount&&!e.compatibleContent(n.type))return null;let o=s.fillBefore(n.content,!0,h);return o&&!function(t,i,e){for(let s=e;s<i.childCount;s++)if(!t.allowsMarks(i.child(s).marks))return!0;return!1}(e,n.content,h)?o:null}function Gt(t,i,e,s,r){if(i<e){let r=t.firstChild;t=t.replaceChild(0,r.copy(Gt(r.content,i+1,e,s,r)))}if(i>s){let i=r.contentMatchAt(0),e=i.fillBefore(t).append(t);t=e.append(i.matchFragment(e).fillBefore(d.empty,!0))}return t}function Vt(t,i){let e=[];for(let s=Math.min(t.depth,i.depth);s>=0;s--){let r=t.start(s);if(r<t.pos-(t.depth-s)||i.end(s)>i.pos+(i.depth-s)||t.node(s).type.spec.isolating||i.node(s).type.spec.isolating)break;(r==i.start(s)||s==t.depth&&s==i.depth&&t.parent.inlineContent&&i.parent.inlineContent&&s&&i.start(s-1)==r-1)&&e.push(s)}return e}class Zt extends Ot{constructor(t,i,e){super(),this.pos=t,this.attr=i,this.value=e}apply(t){let i=t.nodeAt(this.pos);if(!i)return Tt.fail("No node at attribute step's position");let e=Object.create(null);for(let t in i.attrs)e[t]=i.attrs[t];e[this.attr]=this.value;let s=i.type.create(e,null,i.marks);return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(s),0,i.isLeaf?0:1))}getMap(){return kt.empty}invert(t){return new Zt(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let i=t.mapResult(this.pos,1);return i.deletedAfter?null:new Zt(i.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,i){if("number"!=typeof i.pos||"string"!=typeof i.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new Zt(i.pos,i.attr,i.value)}}Ot.jsonID("attr",Zt);class Qt extends Ot{constructor(t,i){super(),this.attr=t,this.value=i}apply(t){let i=Object.create(null);for(let e in t.attrs)i[e]=t.attrs[e];i[this.attr]=this.value;let e=t.type.create(i,t.content,t.marks);return Tt.ok(e)}getMap(){return kt.empty}invert(t){return new Qt(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,i){if("string"!=typeof i.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Qt(i.attr,i.value)}}Ot.jsonID("docAttr",Qt);let ti=class extends Error{};ti=function t(i){let e=Error.call(this,i);return e.__proto__=t.prototype,e},(ti.prototype=Object.create(Error.prototype)).constructor=ti,ti.prototype.name="TransformError";class ii{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new St}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let i=this.maybeStep(t);if(i.failed)throw new ti(i.failed);return this}maybeStep(t){let i=t.apply(this.doc);return i.failed||this.addStep(t,i.doc),i}get docChanged(){return this.steps.length>0}changedRange(){let t=1e9,i=-1e9;for(let e=0;e<this.mapping.maps.length;e++){let s=this.mapping.maps[e];e&&(t=s.map(t,1),i=s.map(i,-1)),s.forEach(((e,s,r,n)=>{t=Math.min(t,r),i=Math.max(i,n)}))}return 1e9==t?null:{from:t,to:i}}addStep(t,i){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=i}replace(t,i=t,e=b.empty){let s=Jt(this.doc,t,i,e);return s&&this.step(s),this}replaceWith(t,i,e){return this.replace(t,i,new b(d.from(e),0,0))}delete(t,i){return this.replace(t,i,b.empty)}insert(t,i){return this.replaceWith(t,t,i)}replaceRange(t,i,e){return function(t,i,e,s){if(!s.size)return t.deleteRange(i,e);let r=t.doc.resolve(i),n=t.doc.resolve(e);if(Lt(r,n,s))return t.step(new Ct(i,e,s));let h=Vt(r,n);0==h[h.length-1]&&h.pop();let o=-(r.depth+1);h.unshift(o);for(let t=r.depth,i=r.pos-1;t>0;t--,i--){let e=r.node(t).type.spec;if(e.defining||e.definingAsContext||e.isolating)break;h.indexOf(t)>-1?o=t:r.before(t)==i&&h.splice(1,0,-t)}let l=h.indexOf(o),u=[],f=s.openStart;for(let t=s.content,i=0;;i++){let e=t.firstChild;if(u.push(e),i==s.openStart)break;t=e.content}for(let t=f-1;t>=0;t--){let i=u[t],e=(a=i.type).spec.defining||a.spec.definingForContent;if(e&&!i.sameMarkup(r.node(Math.abs(o)-1)))f=t;else if(e||!i.type.isTextblock)break}var a;for(let i=s.openStart;i>=0;i--){let o=(i+f+1)%(s.openStart+1),a=u[o];if(a)for(let i=0;i<h.length;i++){let u=h[(i+l)%h.length],f=!0;u<0&&(f=!1,u=-u);let c=r.node(u-1),d=r.index(u-1);if(c.canReplaceWith(d,d,a.type,a.marks))return t.replace(r.before(u),f?n.after(u):e,new b(Gt(s.content,0,s.openStart,o),o,s.openEnd))}}let c=t.steps.length;for(let o=h.length-1;o>=0&&(t.replace(i,e,s),!(t.steps.length>c));o--){let t=h[o];t<0||(i=r.before(t),e=n.after(t))}}(this,t,i,e),this}replaceRangeWith(t,i,e){return function(t,i,e,s){if(!s.isInline&&i==e&&t.doc.resolve(i).parent.content.size){let r=function(t,i,e){let s=t.resolve(i);if(s.parent.canReplaceWith(s.index(),s.index(),e))return i;if(0==s.parentOffset)for(let t=s.depth-1;t>=0;t--){let i=s.index(t);if(s.node(t).canReplaceWith(i,i,e))return s.before(t+1);if(i>0)return null}if(s.parentOffset==s.parent.content.size)for(let t=s.depth-1;t>=0;t--){let i=s.indexAfter(t);if(s.node(t).canReplaceWith(i,i,e))return s.after(t+1);if(i<s.node(t).childCount)return null}return null}(t.doc,i,s.type);null!=r&&(i=e=r)}t.replaceRange(i,e,new b(d.from(s),0,0))}(this,t,i,e),this}deleteRange(t,i){return function(t,i,e){let s=t.doc.resolve(i),r=t.doc.resolve(e);if(s.parent.isTextblock&&r.parent.isTextblock&&s.start()!=r.start()&&0==s.parentOffset&&0==r.parentOffset){let n=s.sharedDepth(e),h=!1;for(let t=s.depth;t>n;t--)s.node(t).type.spec.isolating&&(h=!0);for(let t=r.depth;t>n;t--)r.node(t).type.spec.isolating&&(h=!0);if(!h){for(let t=s.depth;t>0&&i==s.start(t);t--)i=s.before(t);for(let t=r.depth;t>0&&e==r.start(t);t--)e=r.before(t);s=t.doc.resolve(i),r=t.doc.resolve(e)}}let n=Vt(s,r);for(let i=0;i<n.length;i++){let e=n[i],h=i==n.length-1;if(h&&0==e||s.node(e).type.contentMatch.validEnd)return t.delete(s.start(e),r.end(e));if(e>0&&(h||s.node(e-1).canReplace(s.index(e-1),r.indexAfter(e-1))))return t.delete(s.before(e),r.after(e))}for(let n=1;n<=s.depth&&n<=r.depth;n++)if(i-s.start(n)==s.depth-n&&e>s.end(n)&&r.end(n)-e!=r.depth-n&&s.start(n-1)==r.start(n-1)&&s.node(n-1).canReplace(s.index(n-1),r.index(n-1)))return t.delete(s.before(n),e);t.delete(i,e)}(this,t,i),this}lift(t,i){return function(t,i,e){let{$from:s,$to:r,depth:n}=i,h=s.before(n+1),o=r.after(n+1),l=h,u=o,f=d.empty,a=0;for(let t=n,i=!1;t>e;t--)i||s.index(t)>0?(i=!0,f=d.from(s.node(t).copy(f)),a++):l--;let c=d.empty,p=0;for(let t=n,i=!1;t>e;t--)i||r.after(t+1)<r.end(t)?(i=!0,c=d.from(r.node(t).copy(c)),p++):u++;t.step(new Pt(l,u,h,o,new b(f.append(c),a,p),f.size-a,!0))}(this,t,i),this}join(t,i=1){return function(t,i,e){let s=null,{linebreakReplacement:r}=t.doc.type.schema,n=t.doc.resolve(i-e),h=n.node().type;if(r&&h.inlineContent){let t="pre"==h.whitespace,i=!!h.contentMatch.matchType(r);t&&!i?s=!1:!t&&i&&(s=!0)}let o=t.steps.length;if(!1===s){let s=t.doc.resolve(i+e);Ft(t,s.node(),s.before(),o)}h.inlineContent&&It(t,i+e-1,h,n.node().contentMatchAt(n.index()),null==s);let l=t.mapping.slice(o),u=l.map(i-e);if(t.step(new Ct(u,l.map(i+e,-1),b.empty,!0)),!0===s){let i=t.doc.resolve(u);jt(t,i.node(),i.before(),t.steps.length)}}(this,t,i),this}wrap(t,i){return function(t,i,e){let s=d.empty;for(let t=e.length-1;t>=0;t--){if(s.size){let i=e[t].type.contentMatch.matchFragment(s);if(!i||!i.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=d.from(e[t].type.create(e[t].attrs,s))}let r=i.start,n=i.end;t.step(new Pt(r,n,r,n,new b(s,0,0),e.length,!0))}(this,t,i),this}setBlockType(t,i=t,e,s=null){return function(t,i,e,s,r){if(!s.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let n=t.steps.length;t.doc.nodesBetween(i,e,((i,e)=>{let h="function"==typeof r?r(i):r;if(i.isTextblock&&!i.hasMarkup(s,h)&&function(t,i,e){let s=t.resolve(i),r=s.index();return s.parent.canReplaceWith(r,r+1,e)}(t.doc,t.mapping.slice(n).map(e),s)){let r=null;if(s.schema.linebreakReplacement){let t="pre"==s.whitespace,i=!!s.contentMatch.matchType(s.schema.linebreakReplacement);t&&!i?r=!1:!t&&i&&(r=!0)}!1===r&&Ft(t,i,e,n),It(t,t.mapping.slice(n).map(e,1),s,void 0,null===r);let o=t.mapping.slice(n),l=o.map(e,1),u=o.map(e+i.nodeSize,1);return t.step(new Pt(l,u,l+1,u-1,new b(d.from(s.create(h,null,i.marks)),0,0),1,!0)),!0===r&&jt(t,i,e,n),!1}}))}(this,t,i,e,s),this}setNodeMarkup(t,i,e=null,s){return function(t,i,e,s,r){let n=t.doc.nodeAt(i);if(!n)throw new RangeError("No node at given position");e||(e=n.type);let h=e.create(s,null,r||n.marks);if(n.isLeaf)return t.replaceWith(i,i+n.nodeSize,h);if(!e.validContent(n.content))throw new RangeError("Invalid content for node type "+e.name);t.step(new Pt(i,i+n.nodeSize,i+1,i+n.nodeSize-1,new b(d.from(h),0,0),1,!0))}(this,t,i,e,s),this}setNodeAttribute(t,i,e){return this.step(new Zt(t,i,e)),this}setDocAttribute(t,i){return this.step(new Qt(t,i)),this}addNodeMark(t,i){return this.step(new Et(t,i)),this}removeNodeMark(t,i){let e=this.doc.nodeAt(t);if(!e)throw new RangeError("No node at position "+t);if(i instanceof g)i.isInSet(e.marks)&&this.step(new $t(t,i));else{let s,r=e.marks,n=[];for(;s=i.isInSet(r);)n.push(new $t(t,s)),r=s.removeFromSet(r);for(let t=n.length-1;t>=0;t--)this.step(n[t])}return this}split(t,i=1,e){return function(t,i,e=1,s){let r=t.doc.resolve(i),n=d.empty,h=d.empty;for(let t=r.depth,i=r.depth-e,o=e-1;t>i;t--,o--){n=d.from(r.node(t).copy(n));let i=s&&s[o];h=d.from(i?i.type.create(i.attrs,h):r.node(t).copy(h))}t.step(new Ct(i,i,new b(n.append(h),e,e),!0))}(this,t,i,e),this}addMark(t,i,e){return function(t,i,e,s){let r,n,h=[],o=[];t.doc.nodesBetween(i,e,((t,l,u)=>{if(!t.isInline)return;let f=t.marks;if(!s.isInSet(f)&&u.type.allowsMarkType(s.type)){let u=Math.max(l,i),a=Math.min(l+t.nodeSize,e),c=s.addToSet(f);for(let t=0;t<f.length;t++)f[t].isInSet(c)||(r&&r.to==u&&r.mark.eq(f[t])?r.to=a:h.push(r=new Rt(u,a,f[t])));n&&n.to==u?n.to=a:o.push(n=new At(u,a,s))}})),h.forEach((i=>t.step(i))),o.forEach((i=>t.step(i)))}(this,t,i,e),this}removeMark(t,i,e){return function(t,i,e,s){let r=[],n=0;t.doc.nodesBetween(i,e,((t,h)=>{if(!t.isInline)return;n++;let o=null;if(s instanceof it){let i,e=t.marks;for(;i=s.isInSet(e);)(o||(o=[])).push(i),e=i.removeFromSet(e)}else s?s.isInSet(t.marks)&&(o=[s]):o=t.marks;if(o&&o.length){let s=Math.min(h+t.nodeSize,e);for(let t=0;t<o.length;t++){let e,l=o[t];for(let t=0;t<r.length;t++){let i=r[t];i.step==n-1&&l.eq(r[t].style)&&(e=i)}e?(e.to=s,e.step=n):r.push({style:l,from:Math.max(h,i),to:s,step:n})}}})),r.forEach((i=>t.step(new Rt(i.from,i.to,i.style))))}(this,t,i,e),this}clearIncompatible(t,i,e){return It(this,t,i,e),this}}const ei=Object.create(null);class si{constructor(t,i,e){this.$anchor=t,this.$head=i,this.ranges=e||[new ri(t.min(i),t.max(i))]}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 t=this.ranges;for(let i=0;i<t.length;i++)if(t[i].$from.pos!=t[i].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,i=b.empty){let e=i.content.lastChild,s=null;for(let t=0;t<i.openEnd;t++)s=e,e=e.lastChild;let r=t.steps.length,n=this.ranges;for(let h=0;h<n.length;h++){let{$from:o,$to:l}=n[h],u=t.mapping.slice(r);t.replaceRange(u.map(o.pos),u.map(l.pos),h?b.empty:i),0==h&&pi(t,r,(e?e.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(t,i){let e=t.steps.length,s=this.ranges;for(let r=0;r<s.length;r++){let{$from:n,$to:h}=s[r],o=t.mapping.slice(e),l=o.map(n.pos),u=o.map(h.pos);r?t.deleteRange(l,u):(t.replaceRangeWith(l,u,i),pi(t,e,i.isInline?-1:1))}}static findFrom(t,i,e=!1){let s=t.parent.inlineContent?new oi(t):di(t.node(0),t.parent,t.pos,t.index(),i,e);if(s)return s;for(let s=t.depth-1;s>=0;s--){let r=i<0?di(t.node(0),t.node(s),t.before(s+1),t.index(s),i,e):di(t.node(0),t.node(s),t.after(s+1),t.index(s)+1,i,e);if(r)return r}return null}static near(t,i=1){return this.findFrom(t,i)||this.findFrom(t,-i)||new ai(t.node(0))}static atStart(t){return di(t,t,0,0,1)||new ai(t)}static atEnd(t){return di(t,t,t.content.size,t.childCount,-1)||new ai(t)}static fromJSON(t,i){if(!i||!i.type)throw new RangeError("Invalid input for Selection.fromJSON");let e=ei[i.type];if(!e)throw new RangeError(`No selection type ${i.type} defined`);return e.fromJSON(t,i)}static jsonID(t,i){if(t in ei)throw new RangeError("Duplicate use of selection JSON ID "+t);return ei[t]=i,i.prototype.jsonID=t,i}getBookmark(){return oi.between(this.$anchor,this.$head).getBookmark()}}si.prototype.visible=!0;class ri{constructor(t,i){this.$from=t,this.$to=i}}let ni=!1;function hi(t){ni||t.parent.inlineContent||(ni=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class oi extends si{constructor(t,i=t){hi(t),hi(i),super(t,i)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,i){let e=t.resolve(i.map(this.head));if(!e.parent.inlineContent)return si.near(e);let s=t.resolve(i.map(this.anchor));return new oi(s.parent.inlineContent?s:e,e)}replace(t,i=b.empty){if(super.replace(t,i),i==b.empty){let i=this.$from.marksAcross(this.$to);i&&t.ensureMarks(i)}}eq(t){return t instanceof oi&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new li(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,i){if("number"!=typeof i.anchor||"number"!=typeof i.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new oi(t.resolve(i.anchor),t.resolve(i.head))}static create(t,i,e=i){let s=t.resolve(i);return new this(s,e==i?s:t.resolve(e))}static between(t,i,e){let s=t.pos-i.pos;if(e&&!s||(e=s>=0?1:-1),!i.parent.inlineContent){let t=si.findFrom(i,e,!0)||si.findFrom(i,-e,!0);if(!t)return si.near(i,e);i=t.$head}return t.parent.inlineContent||(0==s||(t=(si.findFrom(t,-e,!0)||si.findFrom(t,e,!0)).$anchor).pos<i.pos!=s<0)&&(t=i),new oi(t,i)}}si.jsonID("text",oi);class li{constructor(t,i){this.anchor=t,this.head=i}map(t){return new li(t.map(this.anchor),t.map(this.head))}resolve(t){return oi.between(t.resolve(this.anchor),t.resolve(this.head))}}class ui extends si{constructor(t){let i=t.nodeAfter,e=t.node(0).resolve(t.pos+i.nodeSize);super(t,e),this.node=i}map(t,i){let{deleted:e,pos:s}=i.mapResult(this.anchor),r=t.resolve(s);return e?si.near(r):new ui(r)}content(){return new b(d.from(this.node),0,0)}eq(t){return t instanceof ui&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new fi(this.anchor)}static fromJSON(t,i){if("number"!=typeof i.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new ui(t.resolve(i.anchor))}static create(t,i){return new ui(t.resolve(i))}static isSelectable(t){return!t.isText&&!1!==t.type.spec.selectable}}ui.prototype.visible=!1,si.jsonID("node",ui);class fi{constructor(t){this.anchor=t}map(t){let{deleted:i,pos:e}=t.mapResult(this.anchor);return i?new li(e,e):new fi(e)}resolve(t){let i=t.resolve(this.anchor),e=i.nodeAfter;return e&&ui.isSelectable(e)?new ui(i):si.near(i)}}class ai extends si{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,i=b.empty){if(i==b.empty){t.delete(0,t.doc.content.size);let i=si.atStart(t.doc);i.eq(t.selection)||t.setSelection(i)}else super.replace(t,i)}toJSON(){return{type:"all"}}static fromJSON(t){return new ai(t)}map(t){return new ai(t)}eq(t){return t instanceof ai}getBookmark(){return ci}}si.jsonID("all",ai);const ci={map(){return this},resolve:t=>new ai(t)};function di(t,i,e,s,r,n=!1){if(i.inlineContent)return oi.create(t,e);for(let h=s-(r>0?0:1);r>0?h<i.childCount:h>=0;h+=r){let s=i.child(h);if(s.isAtom){if(!n&&ui.isSelectable(s))return ui.create(t,e-(r<0?s.nodeSize:0))}else{let i=di(t,s,e+r,r<0?s.childCount:0,r,n);if(i)return i}e+=s.nodeSize*r}return null}function pi(t,i,e){let s=t.steps.length-1;if(s<i)return;let r,n=t.steps[s];(n instanceof Ct||n instanceof Pt)&&(t.mapping.maps[s].forEach(((t,i,e,s)=>{null==r&&(r=s)})),t.setSelection(si.near(t.doc.resolve(r),e)))}class mi extends ii{constructor(t){super(t.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=t.selection,this.storedMarks=t.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(t){if(t.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=t,this.curSelectionFor=this.steps.length,this.updated=-3&this.updated|1,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(t){return this.storedMarks=t,this.updated|=2,this}ensureMarks(t){return g.sameSet(this.storedMarks||this.selection.$from.marks(),t)||this.setStoredMarks(t),this}addStoredMark(t){return this.ensureMarks(t.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(t){return this.ensureMarks(t.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(t,i){super.addStep(t,i),this.updated=-3&this.updated,this.storedMarks=null}setTime(t){return this.time=t,this}replaceSelection(t){return this.selection.replace(this,t),this}replaceSelectionWith(t,i=!0){let e=this.selection;return i&&(t=t.mark(this.storedMarks||(e.empty?e.$from.marks():e.$from.marksAcross(e.$to)||g.none))),e.replaceWith(this,t),this}deleteSelection(){return this.selection.replace(this),this}insertText(t,i,e){let s=this.doc.type.schema;if(null==i)return t?this.replaceSelectionWith(s.text(t),!0):this.deleteSelection();{if(null==e&&(e=i),!t)return this.deleteRange(i,e);let r=this.storedMarks;if(!r){let t=this.doc.resolve(i);r=e==i?t.marks():t.marksAcross(this.doc.resolve(e))}return this.replaceRangeWith(i,e,s.text(t,r)),this.selection.empty||this.selection.to!=i+t.length||this.setSelection(si.near(this.selection.$to)),this}}setMeta(t,i){return this.meta["string"==typeof t?t:t.key]=i,this}getMeta(t){return this.meta["string"==typeof t?t:t.key]}get isGeneric(){for(let t in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function wi(t,i){return i&&t?t.bind(i):t}class gi{constructor(t,i,e){this.name=t,this.init=wi(i.init,e),this.apply=wi(i.apply,e)}}const yi=[new gi("doc",{init:t=>t.doc||t.schema.topNodeType.createAndFill(),apply:t=>t.doc}),new gi("selection",{init:(t,i)=>t.selection||si.atStart(i.doc),apply:t=>t.selection}),new gi("storedMarks",{init:t=>t.storedMarks||null,apply:(t,i,e,s)=>s.selection.$cursor?t.storedMarks:null}),new gi("scrollToSelection",{init:()=>0,apply:(t,i)=>t.scrolledIntoView?i+1:i})];class bi{constructor(t,i){this.schema=t,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=yi.slice(),i&&i.forEach((t=>{if(this.pluginsByKey[t.key])throw new RangeError("Adding different instances of a keyed plugin ("+t.key+")");this.plugins.push(t),this.pluginsByKey[t.key]=t,t.spec.state&&this.fields.push(new gi(t.key,t.spec.state,t))}))}}class Mi{constructor(t){this.config=t}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(t){return this.applyTransaction(t).state}filterTransaction(t,i=-1){for(let e=0;e<this.config.plugins.length;e++)if(e!=i){let i=this.config.plugins[e];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,t,this))return!1}return!0}applyTransaction(t){if(!this.filterTransaction(t))return{state:this,transactions:[]};let i=[t],e=this.applyInner(t),s=null;for(;;){let r=!1;for(let n=0;n<this.config.plugins.length;n++){let h=this.config.plugins[n];if(h.spec.appendTransaction){let o=s?s[n].n:0,l=s?s[n].state:this,u=o<i.length&&h.spec.appendTransaction.call(h,o?i.slice(o):i,l,e);if(u&&e.filterTransaction(u,n)){if(u.setMeta("appendedTransaction",t),!s){s=[];for(let t=0;t<this.config.plugins.length;t++)s.push(t<n?{state:e,n:i.length}:{state:this,n:0})}i.push(u),e=e.applyInner(u),r=!0}s&&(s[n]={state:e,n:i.length})}}if(!r)return{state:e,transactions:i}}}applyInner(t){if(!t.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let i=new Mi(this.config),e=this.config.fields;for(let s=0;s<e.length;s++){let r=e[s];i[r.name]=r.apply(t,this[r.name],this,i)}return i}get tr(){return new mi(this)}static create(t){let i=new bi(t.doc?t.doc.type.schema:t.schema,t.plugins),e=new Mi(i);for(let s=0;s<i.fields.length;s++)e[i.fields[s].name]=i.fields[s].init(t,e);return e}reconfigure(t){let i=new bi(this.schema,t.plugins),e=i.fields,s=new Mi(i);for(let i=0;i<e.length;i++){let r=e[i].name;s[r]=this.hasOwnProperty(r)?this[r]:e[i].init(t,s)}return s}toJSON(t){let i={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(i.storedMarks=this.storedMarks.map((t=>t.toJSON()))),t&&"object"==typeof t)for(let e in t){if("doc"==e||"selection"==e)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let s=t[e],r=s.spec.state;r&&r.toJSON&&(i[e]=r.toJSON.call(s,this[s.key]))}return i}static fromJSON(t,i,e){if(!i)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let s=new bi(t.schema,t.plugins),r=new Mi(s);return s.fields.forEach((s=>{if("doc"==s.name)r.doc=_.fromJSON(t.schema,i.doc);else if("selection"==s.name)r.selection=si.fromJSON(r.doc,i.selection);else if("storedMarks"==s.name)i.storedMarks&&(r.storedMarks=i.storedMarks.map(t.schema.markFromJSON));else{if(e)for(let n in e){let h=e[n],o=h.spec.state;if(h.key==s.name&&o&&o.fromJSON&&Object.prototype.hasOwnProperty.call(i,n))return void(r[s.name]=o.fromJSON.call(h,t,i[n],r))}r[s.name]=s.init(t,r)}})),r}}function vi(t,i,e){for(let s in t){let r=t[s];r instanceof Function?r=r.bind(i):"handleDOMEvents"==s&&(r=vi(r,i,{})),e[s]=r}return e}class ki{constructor(t){var i;this.spec=t,this.props={},t.props&&vi(t.props,this,this.props),this.key=t.key?t.key.key:(i="plugin")in Si?i+"$"+ ++Si[i]:(Si[i]=0,i+"$")}getState(t){return t[this.key]}}const Si=Object.create(null),xi=function(t){for(var i=0;;i++)if(!(t=t.previousSibling))return i},Oi=function(t){let i=t.assignedSlot||t.parentNode;return i&&11==i.nodeType?i.host:i};let Ti=null;const Di=function(t,i,e){let s=Ti||(Ti=document.createRange());return s.setEnd(t,null==e?t.nodeValue.length:e),s.setStart(t,i||0),s},Ai=function(t,i,e,s){return e&&(Ei(t,i,e,s,-1)||Ei(t,i,e,s,1))},Ri=/^(img|br|input|textarea|hr)$/i;function Ei(t,i,e,s,r){for(var n;;){if(t==e&&i==s)return!0;if(i==(r<0?0:$i(t))){let e=t.parentNode;if(!e||1!=e.nodeType||Ci(t)||Ri.test(t.nodeName)||"false"==t.contentEditable)return!1;i=xi(t)+(r<0?0:1),t=e}else{if(1!=t.nodeType)return!1;{let e=t.childNodes[i+(r<0?-1:0)];if(1==e.nodeType&&"false"==e.contentEditable){if(!(null===(n=e.pmViewDesc)||void 0===n?void 0:n.ignoreForSelection))return!1;i+=r}else t=e,i=r<0?$i(t):0}}}}function $i(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Ci(t){let i;for(let e=t;e&&!(i=e.pmViewDesc);e=e.parentNode);return i&&i.node&&i.node.isBlock&&(i.dom==t||i.contentDOM==t)}const Pi=function(t){return t.focusNode&&Ai(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Ni(t,i){let e=document.createEvent("Event");return e.initEvent("keydown",!0,!0),e.keyCode=t,e.key=e.code=i,e}const Ii="undefined"!=typeof navigator?navigator:null,zi="undefined"!=typeof document?document:null,_i=Ii&&Ii.userAgent||"",ji=/Edge\/(\d+)/.exec(_i),Fi=/MSIE \d/.exec(_i),Bi=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(_i),Wi=!!(Fi||Bi||ji),Ji=Fi?document.documentMode:Bi?+Bi[1]:ji?+ji[1]:0,Li=!Wi&&/gecko\/(\d+)/i.test(_i),Yi=!Wi&&/Chrome\/(\d+)/.exec(_i),Xi=!!Yi,Ui=Yi?+Yi[1]:0,Hi=!Wi&&!!Ii&&/Apple Computer/.test(Ii.vendor),Ki=Hi&&(/Mobile\/\w+/.test(_i)||!!Ii&&Ii.maxTouchPoints>2),qi=Ki||!!Ii&&/Mac/.test(Ii.platform),Gi=!!Ii&&/Win/.test(Ii.platform),Vi=/Android \d/.test(_i),Zi=!!zi&&"webkitFontSmoothing"in zi.documentElement.style,Qi=Zi?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function te(t){let i=t.defaultView&&t.defaultView.visualViewport;return i?{left:0,right:i.width,top:0,bottom:i.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function ie(t,i){return"number"==typeof t?t:t[i]}function ee(t){let i=t.getBoundingClientRect();return{left:i.left,right:i.left+t.clientWidth*(i.width/t.offsetWidth||1),top:i.top,bottom:i.top+t.clientHeight*(i.height/t.offsetHeight||1)}}function se(t,i,e){let s=t.someProp("scrollThreshold")||0,r=t.someProp("scrollMargin")||5,n=t.dom.ownerDocument;for(let h=e||t.dom;h;){if(1!=h.nodeType){h=Oi(h);continue}let t=h,e=t==n.body,o=e?te(n):ee(t),l=0,u=0;if(i.top<o.top+ie(s,"top")?u=-(o.top-i.top+ie(r,"top")):i.bottom>o.bottom-ie(s,"bottom")&&(u=i.bottom-i.top>o.bottom-o.top?i.top+ie(r,"top")-o.top:i.bottom-o.bottom+ie(r,"bottom")),i.left<o.left+ie(s,"left")?l=-(o.left-i.left+ie(r,"left")):i.right>o.right-ie(s,"right")&&(l=i.right-o.right+ie(r,"right")),l||u)if(e)n.defaultView.scrollBy(l,u);else{let e=t.scrollLeft,s=t.scrollTop;u&&(t.scrollTop+=u),l&&(t.scrollLeft+=l);let r=t.scrollLeft-e,n=t.scrollTop-s;i={left:i.left-r,top:i.top-n,right:i.right-r,bottom:i.bottom-n}}let f=e?"fixed":getComputedStyle(h).position;if(/^(fixed|sticky)$/.test(f))break;h="absolute"==f?h.offsetParent:Oi(h)}}function re(t){let i=[],e=t.ownerDocument;for(let s=t;s&&(i.push({dom:s,top:s.scrollTop,left:s.scrollLeft}),t!=e);s=Oi(s));return i}function ne(t,i){for(let e=0;e<t.length;e++){let{dom:s,top:r,left:n}=t[e];s.scrollTop!=r+i&&(s.scrollTop=r+i),s.scrollLeft!=n&&(s.scrollLeft=n)}}let he=null;function oe(t,i){let e,s,r,n,h=2e8,o=0,l=i.top,u=i.top;for(let f=t.firstChild,a=0;f;f=f.nextSibling,a++){let t;if(1==f.nodeType)t=f.getClientRects();else{if(3!=f.nodeType)continue;t=Di(f).getClientRects()}for(let c=0;c<t.length;c++){let d=t[c];if(d.top<=l&&d.bottom>=u){l=Math.max(d.bottom,l),u=Math.min(d.top,u);let t=d.left>i.left?d.left-i.left:d.right<i.left?i.left-d.right:0;if(t<h){e=f,h=t,s=t&&3==e.nodeType?{left:d.right<i.left?d.right:d.left,top:i.top}:i,1==f.nodeType&&t&&(o=a+(i.left>=(d.left+d.right)/2?1:0));continue}}else d.top>i.top&&!r&&d.left<=i.left&&d.right>=i.left&&(r=f,n={left:Math.max(d.left,Math.min(d.right,i.left)),top:d.top});!e&&(i.left>=d.right&&i.top>=d.top||i.left>=d.left&&i.top>=d.bottom)&&(o=a+1)}}return!e&&r&&(e=r,s=n,h=0),e&&3==e.nodeType?function(t,i){let e,s=t.nodeValue.length,r=document.createRange();for(let n=0;n<s;n++){r.setEnd(t,n+1),r.setStart(t,n);let s=ce(r,1);if(s.top!=s.bottom&&le(i,s)){e={node:t,offset:n+(i.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),e||{node:t,offset:0}}(e,s):!e||h&&1==e.nodeType?{node:t,offset:o}:oe(e,s)}function le(t,i){return t.left>=i.left-1&&t.left<=i.right+1&&t.top>=i.top-1&&t.top<=i.bottom+1}function ue(t,i,e){let s=t.childNodes.length;if(s&&e.top<e.bottom)for(let r=Math.max(0,Math.min(s-1,Math.floor(s*(i.top-e.top)/(e.bottom-e.top))-2)),n=r;;){let e=t.childNodes[n];if(1==e.nodeType){let t=e.getClientRects();for(let s=0;s<t.length;s++){let r=t[s];if(le(i,r))return ue(e,i,r)}}if((n=(n+1)%s)==r)break}return t}function fe(t,i){let e,s=t.dom.ownerDocument,r=0,n=function(t,i,e){if(t.caretPositionFromPoint)try{let s=t.caretPositionFromPoint(i,e);if(s)return{node:s.offsetNode,offset:Math.min($i(s.offsetNode),s.offset)}}catch(t){}if(t.caretRangeFromPoint){let s=t.caretRangeFromPoint(i,e);if(s)return{node:s.startContainer,offset:Math.min($i(s.startContainer),s.startOffset)}}}(s,i.left,i.top);n&&({node:e,offset:r}=n);let h,o=(t.root.elementFromPoint?t.root:s).elementFromPoint(i.left,i.top);if(!o||!t.dom.contains(1!=o.nodeType?o.parentNode:o)){let e=t.dom.getBoundingClientRect();if(!le(i,e))return null;if(o=ue(t.dom,i,e),!o)return null}if(Hi)for(let t=o;e&&t;t=Oi(t))t.draggable&&(e=void 0);if(o=function(t,i){let e=t.parentNode;return e&&/^li$/i.test(e.nodeName)&&i.left<t.getBoundingClientRect().left?e:t}(o,i),e){if(Li&&1==e.nodeType&&(r=Math.min(r,e.childNodes.length),r<e.childNodes.length)){let t,s=e.childNodes[r];"IMG"==s.nodeName&&(t=s.getBoundingClientRect()).right<=i.left&&t.bottom>i.top&&r++}let s;Zi&&r&&1==e.nodeType&&1==(s=e.childNodes[r-1]).nodeType&&"false"==s.contentEditable&&s.getBoundingClientRect().top>=i.top&&r--,e==t.dom&&r==e.childNodes.length-1&&1==e.lastChild.nodeType&&i.top>e.lastChild.getBoundingClientRect().bottom?h=t.state.doc.content.size:0!=r&&1==e.nodeType&&"BR"==e.childNodes[r-1].nodeName||(h=function(t,i,e,s){let r=-1;for(let e=i,n=!1;e!=t.dom;){let i,h=t.docView.nearestDesc(e,!0);if(!h)return null;if(1==h.dom.nodeType&&(h.node.isBlock&&h.parent||!h.contentDOM)&&((i=h.dom.getBoundingClientRect()).width||i.height)&&(h.node.isBlock&&h.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(h.dom.nodeName)&&(!n&&i.left>s.left||i.top>s.top?r=h.posBefore:(!n&&i.right<s.left||i.bottom<s.top)&&(r=h.posAfter),n=!0),!h.contentDOM&&r<0&&!h.node.isText))return(h.node.isBlock?s.top<(i.top+i.bottom)/2:s.left<(i.left+i.right)/2)?h.posBefore:h.posAfter;e=h.dom.parentNode}return r>-1?r:t.docView.posFromDOM(i,e,-1)}(t,e,r,i))}null==h&&(h=function(t,i,e){let{node:s,offset:r}=oe(i,e),n=-1;if(1==s.nodeType&&!s.firstChild){let t=s.getBoundingClientRect();n=t.left!=t.right&&e.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(s,r,n)}(t,o,i));let l=t.docView.nearestDesc(o,!0);return{pos:h,inside:l?l.posAtStart-l.border:-1}}function ae(t){return t.top<t.bottom||t.left<t.right}function ce(t,i){let e=t.getClientRects();if(e.length){let t=e[i<0?0:e.length-1];if(ae(t))return t}return Array.prototype.find.call(e,ae)||t.getBoundingClientRect()}const de=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function pe(t,i,e){let{node:s,offset:r,atom:n}=t.docView.domFromPos(i,e<0?-1:1),h=Zi||Li;if(3==s.nodeType){if(!h||!de.test(s.nodeValue)&&(e<0?r:r!=s.nodeValue.length)){let t=r,i=r,n=e<0?1:-1;return e<0&&!r?(i++,n=-1):e>=0&&r==s.nodeValue.length?(t--,n=1):e<0?t--:i++,me(ce(Di(s,t,i),n),n<0)}{let t=ce(Di(s,r,r),e);if(Li&&r&&/\s/.test(s.nodeValue[r-1])&&r<s.nodeValue.length){let i=ce(Di(s,r-1,r-1),-1);if(i.top==t.top){let e=ce(Di(s,r,r+1),-1);if(e.top!=t.top)return me(e,e.left<i.left)}}return t}}if(!t.state.doc.resolve(i-(n||0)).parent.inlineContent){if(null==n&&r&&(e<0||r==$i(s))){let t=s.childNodes[r-1];if(1==t.nodeType)return we(t.getBoundingClientRect(),!1)}if(null==n&&r<$i(s)){let t=s.childNodes[r];if(1==t.nodeType)return we(t.getBoundingClientRect(),!0)}return we(s.getBoundingClientRect(),e>=0)}if(null==n&&r&&(e<0||r==$i(s))){let t=s.childNodes[r-1],i=3==t.nodeType?Di(t,$i(t)-(h?0:1)):1!=t.nodeType||"BR"==t.nodeName&&t.nextSibling?null:t;if(i)return me(ce(i,1),!1)}if(null==n&&r<$i(s)){let t=s.childNodes[r];for(;t.pmViewDesc&&t.pmViewDesc.ignoreForCoords;)t=t.nextSibling;let i=t?3==t.nodeType?Di(t,0,h?0:1):1==t.nodeType?t:null:null;if(i)return me(ce(i,-1),!0)}return me(ce(3==s.nodeType?Di(s):s,-e),e>=0)}function me(t,i){if(0==t.width)return t;let e=i?t.left:t.right;return{top:t.top,bottom:t.bottom,left:e,right:e}}function we(t,i){if(0==t.height)return t;let e=i?t.top:t.bottom;return{top:e,bottom:e,left:t.left,right:t.right}}function ge(t,i,e){let s=t.state,r=t.root.activeElement;s!=i&&t.updateState(i),r!=t.dom&&t.focus();try{return e()}finally{s!=i&&t.updateState(s),r!=t.dom&&r&&r.focus()}}const ye=/[\u0590-\u08ac]/;let be=null,Me=null,ve=!1;class ke{constructor(t,i,e,s){this.parent=t,this.children=i,this.dom=e,this.contentDOM=s,this.dirty=0,e.pmViewDesc=this}matchesWidget(t){return!1}matchesMark(t){return!1}matchesNode(t,i,e){return!1}matchesHack(t){return!1}parseRule(){return null}stopEvent(t){return!1}get size(){let t=0;for(let i=0;i<this.children.length;i++)t+=this.children[i].size;return t}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let t=0;t<this.children.length;t++)this.children[t].destroy()}posBeforeChild(t){for(let i=0,e=this.posAtStart;;i++){let s=this.children[i];if(s==t)return e;e+=s.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(t,i,e){if(this.contentDOM&&this.contentDOM.contains(1==t.nodeType?t:t.parentNode)){if(e<0){let e,s;if(t==this.contentDOM)e=t.childNodes[i-1];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;e=t.previousSibling}for(;e&&(!(s=e.pmViewDesc)||s.parent!=this);)e=e.previousSibling;return e?this.posBeforeChild(s)+s.size:this.posAtStart}{let e,s;if(t==this.contentDOM)e=t.childNodes[i];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;e=t.nextSibling}for(;e&&(!(s=e.pmViewDesc)||s.parent!=this);)e=e.nextSibling;return e?this.posBeforeChild(s):this.posAtEnd}}let s;if(t==this.dom&&this.contentDOM)s=i>xi(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))s=2&t.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==i)for(let i=t;;i=i.parentNode){if(i==this.dom){s=!1;break}if(i.previousSibling)break}if(null==s&&i==t.childNodes.length)for(let i=t;;i=i.parentNode){if(i==this.dom){s=!0;break}if(i.nextSibling)break}}return(null==s?e>0:s)?this.posAtEnd:this.posAtStart}nearestDesc(t,i=!1){for(let e=!0,s=t;s;s=s.parentNode){let r,n=this.getDesc(s);if(n&&(!i||n.node)){if(!e||!(r=n.nodeDOM)||(1==r.nodeType?r.contains(1==t.nodeType?t:t.parentNode):r==t))return n;e=!1}}}getDesc(t){let i=t.pmViewDesc;for(let t=i;t;t=t.parent)if(t==this)return i}posFromDOM(t,i,e){for(let s=t;s;s=s.parentNode){let r=this.getDesc(s);if(r)return r.localPosFromDOM(t,i,e)}return-1}descAt(t){for(let i=0,e=0;i<this.children.length;i++){let s=this.children[i],r=e+s.size;if(e==t&&r!=e){for(;!s.border&&s.children.length;)for(let t=0;t<s.children.length;t++){let i=s.children[t];if(i.size){s=i;break}}return s}if(t<r)return s.descAt(t-e-s.border);e=r}}domFromPos(t,i){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let e=0,s=0;for(let i=0;e<this.children.length;e++){let r=this.children[e],n=i+r.size;if(n>t||r instanceof Re){s=t-i;break}i=n}if(s)return this.children[e].domFromPos(s-this.children[e].border,i);for(let t;e&&!(t=this.children[e-1]).size&&t instanceof Se&&t.side>=0;e--);if(i<=0){let t,s=!0;for(;t=e?this.children[e-1]:null,t&&t.dom.parentNode!=this.contentDOM;e--,s=!1);return t&&i&&s&&!t.border&&!t.domAtom?t.domFromPos(t.size,i):{node:this.contentDOM,offset:t?xi(t.dom)+1:0}}{let t,s=!0;for(;t=e<this.children.length?this.children[e]:null,t&&t.dom.parentNode!=this.contentDOM;e++,s=!1);return t&&s&&!t.border&&!t.domAtom?t.domFromPos(0,i):{node:this.contentDOM,offset:t?xi(t.dom):this.contentDOM.childNodes.length}}}parseRange(t,i,e=0){if(0==this.children.length)return{node:this.contentDOM,from:t,to:i,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let s=-1,r=-1;for(let n=e,h=0;;h++){let e=this.children[h],o=n+e.size;if(-1==s&&t<=o){let r=n+e.border;if(t>=r&&i<=o-e.border&&e.node&&e.contentDOM&&this.contentDOM.contains(e.contentDOM))return e.parseRange(t,i,r);t=n;for(let i=h;i>0;i--){let e=this.children[i-1];if(e.size&&e.dom.parentNode==this.contentDOM&&!e.emptyChildAt(1)){s=xi(e.dom)+1;break}t-=e.size}-1==s&&(s=0)}if(s>-1&&(o>i||h==this.children.length-1)){i=o;for(let t=h+1;t<this.children.length;t++){let e=this.children[t];if(e.size&&e.dom.parentNode==this.contentDOM&&!e.emptyChildAt(-1)){r=xi(e.dom);break}i+=e.size}-1==r&&(r=this.contentDOM.childNodes.length);break}n=o}return{node:this.contentDOM,from:t,to:i,fromOffset:s,toOffset:r}}emptyChildAt(t){if(this.border||!this.contentDOM||!this.children.length)return!1;let i=this.children[t<0?0:this.children.length-1];return 0==i.size||i.emptyChildAt(t)}domAfterPos(t){let{node:i,offset:e}=this.domFromPos(t,0);if(1!=i.nodeType||e==i.childNodes.length)throw new RangeError("No node after pos "+t);return i.childNodes[e]}setSelection(t,i,e,s=!1){let r=Math.min(t,i),n=Math.max(t,i);for(let h=0,o=0;h<this.children.length;h++){let l=this.children[h],u=o+l.size;if(r>o&&n<u)return l.setSelection(t-o-l.border,i-o-l.border,e,s);o=u}let h=this.domFromPos(t,t?-1:1),o=i==t?h:this.domFromPos(i,i?-1:1),l=e.root.getSelection(),u=e.domSelectionRange(),f=!1;if((Li||Hi)&&t==i){let{node:t,offset:i}=h;if(3==t.nodeType){if(f=!(!i||"\n"!=t.nodeValue[i-1]),f&&i==t.nodeValue.length)for(let i,e=t;e;e=e.parentNode){if(i=e.nextSibling){"BR"==i.nodeName&&(h=o={node:i.parentNode,offset:xi(i)+1});break}let t=e.pmViewDesc;if(t&&t.node&&t.node.isBlock)break}}else{let e=t.childNodes[i-1];f=e&&("BR"==e.nodeName||"false"==e.contentEditable)}}if(Li&&u.focusNode&&u.focusNode!=o.node&&1==u.focusNode.nodeType){let t=u.focusNode.childNodes[u.focusOffset];t&&"false"==t.contentEditable&&(s=!0)}if(!(s||f&&Hi)&&Ai(h.node,h.offset,u.anchorNode,u.anchorOffset)&&Ai(o.node,o.offset,u.focusNode,u.focusOffset))return;let a=!1;if((l.extend||t==i)&&(!f||!Li)){l.collapse(h.node,h.offset);try{t!=i&&l.extend(o.node,o.offset),a=!0}catch(t){}}if(!a){if(t>i){let t=h;h=o,o=t}let e=document.createRange();e.setEnd(o.node,o.offset),e.setStart(h.node,h.offset),l.removeAllRanges(),l.addRange(e)}}ignoreMutation(t){return!this.contentDOM&&"selection"!=t.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(t,i){for(let e=0,s=0;s<this.children.length;s++){let r=this.children[s],n=e+r.size;if(e==n?t<=n&&i>=e:t<n&&i>e){let s=e+r.border,h=n-r.border;if(t>=s&&i<=h)return this.dirty=t==e||i==n?2:1,void(t!=s||i!=h||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(t-s,i-s):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.children.length?3:2}e=n}this.dirty=2}markParentsDirty(){let t=1;for(let i=this.parent;i;i=i.parent,t++){let e=1==t?2:1;i.dirty<e&&(i.dirty=e)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(t){return!1}}class Se extends ke{constructor(t,i,e,s){let r,n=i.type.toDOM;if("function"==typeof n&&(n=n(e,(()=>r?r.parent?r.parent.posBeforeChild(r):void 0:s))),!i.type.spec.raw){if(1!=n.nodeType){let t=document.createElement("span");t.appendChild(n),n=t}n.contentEditable="false",n.classList.add("ProseMirror-widget")}super(t,[],n,null),this.widget=i,this.widget=i,r=this}matchesWidget(t){return 0==this.dirty&&t.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(t){let i=this.widget.spec.stopEvent;return!!i&&i(t)}ignoreMutation(t){return"selection"!=t.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 xe extends ke{constructor(t,i,e,s){super(t,[],i,null),this.textDOM=e,this.text=s}get size(){return this.text.length}localPosFromDOM(t,i){return t!=this.textDOM?this.posAtStart+(i?this.size:0):this.posAtStart+i}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return"characterData"===t.type&&t.target.nodeValue==t.oldValue}}class Oe extends ke{constructor(t,i,e,s,r){super(t,[],e,s),this.mark=i,this.spec=r}static create(t,i,e,s){let r=s.nodeViews[i.type.name],n=r&&r(i,s,e);return n&&n.dom||(n=pt.renderSpec(document,i.type.spec.toDOM(i,e),null,i.attrs)),new Oe(t,i,n.dom,n.contentDOM||n.dom,n)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(t){return 3!=this.dirty&&this.mark.eq(t)}markDirty(t,i){if(super.markDirty(t,i),0!=this.dirty){let t=this.parent;for(;!t.node;)t=t.parent;t.dirty<this.dirty&&(t.dirty=this.dirty),this.dirty=0}}slice(t,i,e){let s=Oe.create(this.parent,this.mark,!0,e),r=this.children,n=this.size;i<n&&(r=Je(r,i,n,e)),t>0&&(r=Je(r,0,t,e));for(let t=0;t<r.length;t++)r[t].parent=s;return s.children=r,s}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Te extends ke{constructor(t,i,e,s,r,n,h,o,l){super(t,[],r,n),this.node=i,this.outerDeco=e,this.innerDeco=s,this.nodeDOM=h}static create(t,i,e,s,r,n){let h,o=r.nodeViews[i.type.name],l=o&&o(i,r,(()=>h?h.parent?h.parent.posBeforeChild(h):void 0:n),e,s),u=l&&l.dom,f=l&&l.contentDOM;if(i.isText)if(u){if(3!=u.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else u=document.createTextNode(i.text);else if(!u){let t=pt.renderSpec(document,i.type.spec.toDOM(i),null,i.attrs);({dom:u,contentDOM:f}=t)}f||i.isText||"BR"==u.nodeName||(u.hasAttribute("contenteditable")||(u.contentEditable="false"),i.type.spec.draggable&&(u.draggable=!0));let a=u;return u=_e(u,e,i),l?h=new Ee(t,i,e,s,u,f||null,a,l,r,n+1):i.isText?new Ae(t,i,e,s,u,a,r):new Te(t,i,e,s,u,f||null,a,r,n+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(t.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let i=this.children.length-1;i>=0;i--){let e=this.children[i];if(this.dom.contains(e.dom.parentNode)){t.contentElement=e.dom.parentNode;break}}t.contentElement||(t.getContent=()=>d.empty)}else t.contentElement=this.contentDOM;else t.getContent=()=>this.node.content;return t}matchesNode(t,i,e){return 0==this.dirty&&t.eq(this.node)&&je(i,this.outerDeco)&&e.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(t,i){let e=this.node.inlineContent,s=i,r=t.composing?this.localCompositionInfo(t,i):null,n=r&&r.pos>-1?r:null,h=r&&r.pos<0,o=new Be(this,n&&n.node,t);!function(t,i,e,s){let r=i.locals(t),n=0;if(0==r.length){for(let e=0;e<t.childCount;e++){let h=t.child(e);s(h,r,i.forChild(n,h),e),n+=h.nodeSize}return}let h=0,o=[],l=null;for(let u=0;;){let f,a,c,d;for(;h<r.length&&r[h].to==n;){let t=r[h++];t.widget&&(f?(a||(a=[f])).push(t):f=t)}if(f)if(a){a.sort(We);for(let t=0;t<a.length;t++)e(a[t],u,!!l)}else e(f,u,!!l);if(l)d=-1,c=l,l=null;else{if(!(u<t.childCount))break;d=u,c=t.child(u++)}for(let t=0;t<o.length;t++)o[t].to<=n&&o.splice(t--,1);for(;h<r.length&&r[h].from<=n&&r[h].to>n;)o.push(r[h++]);let p=n+c.nodeSize;if(c.isText){let t=p;h<r.length&&r[h].from<t&&(t=r[h].from);for(let i=0;i<o.length;i++)o[i].to<t&&(t=o[i].to);t<p&&(l=c.cut(t-n),c=c.cut(0,t-n),p=t,d=-1)}else for(;h<r.length&&r[h].to<p;)h++;s(c,c.isInline&&!c.isLeaf?o.filter((t=>!t.inline)):o.slice(),i.forChild(n,c),d),n=p}}(this.node,this.innerDeco,((i,r,n)=>{i.spec.marks?o.syncToMarks(i.spec.marks,e,t,r):i.type.side>=0&&!n&&o.syncToMarks(r==this.node.childCount?g.none:this.node.child(r).marks,e,t,r),o.placeWidget(i,t,s)}),((i,n,l,u)=>{let f;o.syncToMarks(i.marks,e,t,u),o.findNodeMatch(i,n,l,u)||h&&t.state.selection.from>s&&t.state.selection.to<s+i.nodeSize&&(f=o.findIndexWithChild(r.node))>-1&&o.updateNodeAt(i,n,l,f,t)||o.updateNextNode(i,n,l,t,u,s)||o.addNode(i,n,l,t,s),s+=i.nodeSize})),o.syncToMarks([],e,t,0),this.node.isTextblock&&o.addTextblockHacks(),o.destroyRest(),(o.changed||2==this.dirty)&&(n&&this.protectLocalComposition(t,n),$e(this.contentDOM,this.children,t),Ki&&function(t){if("UL"==t.nodeName||"OL"==t.nodeName){let i=t.style.cssText;t.style.cssText=i+"; list-style: square !important",window.getComputedStyle(t),t.style.cssText=i}}(this.dom))}localCompositionInfo(t,i){let{from:e,to:s}=t.state.selection;if(!(t.state.selection instanceof oi)||e<i||s>i+this.node.content.size)return null;let r=t.input.compositionNode;if(!r||!this.dom.contains(r.parentNode))return null;if(this.node.inlineContent){let t=r.nodeValue,n=function(t,i,e,s){for(let r=0,n=0;r<t.childCount&&n<=s;){let h=t.child(r++),o=n;if(n+=h.nodeSize,!h.isText)continue;let l=h.text;for(;r<t.childCount;){let i=t.child(r++);if(n+=i.nodeSize,!i.isText)break;l+=i.text}if(n>=e){if(n>=s&&l.slice(s-i.length-o,s-o)==i)return s-i.length;let t=o<s?l.lastIndexOf(i,s-o-1):-1;if(t>=0&&t+i.length+o>=e)return o+t;if(e==s&&l.length>=s+i.length-o&&l.slice(s-o,s-o+i.length)==i)return s}}return-1}(this.node.content,t,e-i,s-i);return n<0?null:{node:r,pos:n,text:t}}return{node:r,pos:-1,text:""}}protectLocalComposition(t,{node:i,pos:e,text:s}){if(this.getDesc(i))return;let r=i;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 n=new xe(this,r,i,s);t.input.compositionNodes.push(n),this.children=Je(this.children,e,e+s.length,t,n)}update(t,i,e,s){return!(3==this.dirty||!t.sameMarkup(this.node)||(this.updateInner(t,i,e,s),0))}updateInner(t,i,e,s){this.updateOuterDeco(i),this.node=t,this.innerDeco=e,this.contentDOM&&this.updateChildren(s,this.posAtStart),this.dirty=0}updateOuterDeco(t){if(je(t,this.outerDeco))return;let i=1!=this.nodeDOM.nodeType,e=this.dom;this.dom=Ie(this.dom,this.nodeDOM,Ne(this.outerDeco,this.node,i),Ne(t,this.node,i)),this.dom!=e&&(e.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=t}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 De(t,i,e,s,r){_e(s,i,t);let n=new Te(void 0,t,i,e,s,s,s,r,0);return n.contentDOM&&n.updateChildren(r,0),n}class Ae extends Te{constructor(t,i,e,s,r,n,h){super(t,i,e,s,r,null,n,h,0)}parseRule(){let t=this.nodeDOM.parentNode;for(;t&&t!=this.dom&&!t.pmIsDeco;)t=t.parentNode;return{skip:t||!0}}update(t,i,e,s){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!t.sameMarkup(this.node)||(this.updateOuterDeco(i),0==this.dirty&&t.text==this.node.text||t.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=t.text,s.trackWrites==this.nodeDOM&&(s.trackWrites=null)),this.node=t,this.dirty=0,0))}inParent(){let t=this.parent.contentDOM;for(let i=this.nodeDOM;i;i=i.parentNode)if(i==t)return!0;return!1}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,i,e){return t==this.nodeDOM?this.posAtStart+Math.min(i,this.node.text.length):super.localPosFromDOM(t,i,e)}ignoreMutation(t){return"characterData"!=t.type&&"selection"!=t.type}slice(t,i,e){let s=this.node.cut(t,i),r=document.createTextNode(s.text);return new Ae(this.parent,s,this.outerDeco,this.innerDeco,r,r,e)}markDirty(t,i){super.markDirty(t,i),this.dom==this.nodeDOM||0!=t&&i!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}isText(t){return this.node.text==t}}class Re extends ke{parseRule(){return{ignore:!0}}matchesHack(t){return 0==this.dirty&&this.dom.nodeName==t}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class Ee extends Te{constructor(t,i,e,s,r,n,h,o,l,u){super(t,i,e,s,r,n,h,l,u),this.spec=o}update(t,i,e,s){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==t.type||this.spec.multiType)){let r=this.spec.update(t,i,e);return r&&this.updateInner(t,i,e,s),r}return!(!this.contentDOM&&!t.isLeaf)&&super.update(t,i,e,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,i,e,s){this.spec.setSelection?this.spec.setSelection(t,i,e.root):super.setSelection(t,i,e,s)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(t){return!!this.spec.stopEvent&&this.spec.stopEvent(t)}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}}function $e(t,i,e){let s=t.firstChild,r=!1;for(let n=0;n<i.length;n++){let h=i[n],o=h.dom;if(o.parentNode==t){for(;o!=s;)s=Fe(s),r=!0;s=s.nextSibling}else r=!0,t.insertBefore(o,s);if(h instanceof Oe){let i=s?s.previousSibling:t.lastChild;$e(h.contentDOM,h.children,e),s=i?i.nextSibling:t.firstChild}}for(;s;)s=Fe(s),r=!0;r&&e.trackWrites==t&&(e.trackWrites=null)}const Ce=function(t){t&&(this.nodeName=t)};Ce.prototype=Object.create(null);const Pe=[new Ce];function Ne(t,i,e){if(0==t.length)return Pe;let s=e?Pe[0]:new Ce,r=[s];for(let n=0;n<t.length;n++){let h=t[n].type.attrs;if(h){h.nodeName&&r.push(s=new Ce(h.nodeName));for(let t in h){let n=h[t];null!=n&&(e&&1==r.length&&r.push(s=new Ce(i.isInline?"span":"div")),"class"==t?s.class=(s.class?s.class+" ":"")+n:"style"==t?s.style=(s.style?s.style+";":"")+n:"nodeName"!=t&&(s[t]=n))}}}return r}function Ie(t,i,e,s){if(e==Pe&&s==Pe)return i;let r=i;for(let i=0;i<s.length;i++){let n=s[i],h=e[i];if(i){let i;h&&h.nodeName==n.nodeName&&r!=t&&(i=r.parentNode)&&i.nodeName.toLowerCase()==n.nodeName||(i=document.createElement(n.nodeName),i.pmIsDeco=!0,i.appendChild(r),h=Pe[0]),r=i}ze(r,h||Pe[0],n)}return r}function ze(t,i,e){for(let s in i)"class"==s||"style"==s||"nodeName"==s||s in e||t.removeAttribute(s);for(let s in e)"class"!=s&&"style"!=s&&"nodeName"!=s&&e[s]!=i[s]&&t.setAttribute(s,e[s]);if(i.class!=e.class){let s=i.class?i.class.split(" ").filter(Boolean):[],r=e.class?e.class.split(" ").filter(Boolean):[];for(let i=0;i<s.length;i++)-1==r.indexOf(s[i])&&t.classList.remove(s[i]);for(let i=0;i<r.length;i++)-1==s.indexOf(r[i])&&t.classList.add(r[i]);0==t.classList.length&&t.removeAttribute("class")}if(i.style!=e.style){if(i.style){let e,s=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;e=s.exec(i.style);)t.style.removeProperty(e[1])}e.style&&(t.style.cssText+=e.style)}}function _e(t,i,e){return Ie(t,t,Pe,Ne(i,e,1!=t.nodeType))}function je(t,i){if(t.length!=i.length)return!1;for(let e=0;e<t.length;e++)if(!t[e].type.eq(i[e].type))return!1;return!0}function Fe(t){let i=t.nextSibling;return t.parentNode.removeChild(t),i}class Be{constructor(t,i,e){this.lock=i,this.view=e,this.index=0,this.stack=[],this.changed=!1,this.top=t,this.preMatch=function(t,i){let e=i,s=e.children.length,r=t.childCount,n=new Map,h=[];t:for(;r>0;){let o;for(;;)if(s){let t=e.children[s-1];if(!(t instanceof Oe)){o=t,s--;break}e=t,s=t.children.length}else{if(e==i)break t;s=e.parent.children.indexOf(e),e=e.parent}let l=o.node;if(l){if(l!=t.child(r-1))break;--r,n.set(o,r),h.push(o)}}return{index:r,matched:n,matches:h.reverse()}}(t.node.content,t)}destroyBetween(t,i){if(t!=i){for(let e=t;e<i;e++)this.top.children[e].destroy();this.top.children.splice(t,i-t),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(t,i,e,s){let r=0,n=this.stack.length>>1,h=Math.min(n,t.length);for(;r<h&&(r==n-1?this.top:this.stack[r+1<<1]).matchesMark(t[r])&&!1!==t[r].type.spec.spanning;)r++;for(;r<n;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),n--;for(;n<t.length;){this.stack.push(this.top,this.index+1);let r=-1,h=this.top.children.length;s<this.preMatch.index&&(h=Math.min(this.index+3,h));for(let i=this.index;i<h;i++){let e=this.top.children[i];if(e.matchesMark(t[n])&&!this.isLocked(e.dom)){r=i;break}}if(r>-1)r>this.index&&(this.changed=!0,this.destroyBetween(this.index,r)),this.top=this.top.children[this.index];else{let s=Oe.create(this.top,t[n],i,e);this.top.children.splice(this.index,0,s),this.top=s,this.changed=!0}this.index=0,n++}}findNodeMatch(t,i,e,s){let r,n=-1;if(s>=this.preMatch.index&&(r=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&r.matchesNode(t,i,e))n=this.top.children.indexOf(r,this.index);else for(let s=this.index,r=Math.min(this.top.children.length,s+5);s<r;s++){let r=this.top.children[s];if(r.matchesNode(t,i,e)&&!this.preMatch.matched.has(r)){n=s;break}}return!(n<0||(this.destroyBetween(this.index,n),this.index++,0))}updateNodeAt(t,i,e,s,r){let n=this.top.children[s];return 3==n.dirty&&n.dom==n.contentDOM&&(n.dirty=2),!!n.update(t,i,e,r)&&(this.destroyBetween(this.index,s),this.index++,!0)}findIndexWithChild(t){for(;;){let i=t.parentNode;if(!i)return-1;if(i==this.top.contentDOM){let i=t.pmViewDesc;if(i)for(let t=this.index;t<this.top.children.length;t++)if(this.top.children[t]==i)return t;return-1}t=i}}updateNextNode(t,i,e,s,r,n){for(let h=this.index;h<this.top.children.length;h++){let o=this.top.children[h];if(o instanceof Te){let l=this.preMatch.matched.get(o);if(null!=l&&l!=r)return!1;let u,f=o.dom,a=this.isLocked(f)&&!(t.isText&&o.node&&o.node.isText&&o.nodeDOM.nodeValue==t.text&&3!=o.dirty&&je(i,o.outerDeco));if(!a&&o.update(t,i,e,s))return this.destroyBetween(this.index,h),o.dom!=f&&(this.changed=!0),this.index++,!0;if(!a&&(u=this.recreateWrapper(o,t,i,e,s,n)))return this.destroyBetween(this.index,h),this.top.children[this.index]=u,u.contentDOM&&(u.dirty=2,u.updateChildren(s,n+1),u.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(t,i,e,s,r,n){if(t.dirty||i.isAtom||!t.children.length||!t.node.content.eq(i.content)||!je(e,t.outerDeco)||!s.eq(t.innerDeco))return null;let h=Te.create(this.top,i,e,s,r,n);if(h.contentDOM){h.children=t.children,t.children=[];for(let t of h.children)t.parent=h}return t.destroy(),h}addNode(t,i,e,s,r){let n=Te.create(this.top,t,i,e,s,r);n.contentDOM&&n.updateChildren(s,r+1),this.top.children.splice(this.index++,0,n),this.changed=!0}placeWidget(t,i,e){let s=this.index<this.top.children.length?this.top.children[this.index]:null;if(!s||!s.matchesWidget(t)||t!=s.widget&&s.widget.type.toDOM.parentNode){let s=new Se(this.top,t,i,e);this.top.children.splice(this.index++,0,s),this.changed=!0}else this.index++}addTextblockHacks(){let t=this.top.children[this.index-1],i=this.top;for(;t instanceof Oe;)i=t,t=i.children[i.children.length-1];(!t||!(t instanceof Ae)||/\n$/.test(t.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(t.node.text))&&((Hi||Xi)&&t&&"false"==t.dom.contentEditable&&this.addHackNode("IMG",i),this.addHackNode("BR",this.top))}addHackNode(t,i){if(i==this.top&&this.index<i.children.length&&i.children[this.index].matchesHack(t))this.index++;else{let e=document.createElement(t);"IMG"==t&&(e.className="ProseMirror-separator",e.alt=""),"BR"==t&&(e.className="ProseMirror-trailingBreak");let s=new Re(this.top,[],e,null);i!=this.top?i.children.push(s):i.children.splice(this.index++,0,s),this.changed=!0}}isLocked(t){return this.lock&&(t==this.lock||1==t.nodeType&&t.contains(this.lock.parentNode))}}function We(t,i){return t.type.side-i.type.side}function Je(t,i,e,s,r){let n=[];for(let h=0,o=0;h<t.length;h++){let l=t[h],u=o,f=o+=l.size;u>=e||f<=i?n.push(l):(u<i&&n.push(l.slice(0,i-u,s)),r&&(n.push(r),r=void 0),f>e&&n.push(l.slice(e-u,l.size,s)))}return n}function Le(t,i=null){let e=t.domSelectionRange(),s=t.state.doc;if(!e.focusNode)return null;let r=t.docView.nearestDesc(e.focusNode),n=r&&0==r.size,h=t.docView.posFromDOM(e.focusNode,e.focusOffset,1);if(h<0)return null;let o,l,u=s.resolve(h);if(Pi(e)){for(o=h;r&&!r.node;)r=r.parent;let t=r.node;if(r&&t.isAtom&&ui.isSelectable(t)&&r.parent&&(!t.isInline||!function(t,i,e){for(let s=0==i,r=i==$i(t);s||r;){if(t==e)return!0;let i=xi(t);if(!(t=t.parentNode))return!1;s=s&&0==i,r=r&&i==$i(t)}}(e.focusNode,e.focusOffset,r.dom))){let t=r.posBefore;l=new ui(h==t?u:s.resolve(t))}}else{if(e instanceof t.dom.ownerDocument.defaultView.Selection&&e.rangeCount>1){let i=h,r=h;for(let s=0;s<e.rangeCount;s++){let n=e.getRangeAt(s);i=Math.min(i,t.docView.posFromDOM(n.startContainer,n.startOffset,1)),r=Math.max(r,t.docView.posFromDOM(n.endContainer,n.endOffset,-1))}if(i<0)return null;[o,h]=r==t.state.selection.anchor?[r,i]:[i,r],u=s.resolve(h)}else o=t.docView.posFromDOM(e.anchorNode,e.anchorOffset,1);if(o<0)return null}let f=s.resolve(o);return l||(l=Ze(t,f,u,"pointer"==i||t.state.selection.head<u.pos&&!n?1:-1)),l}function Ye(t){return t.editable?t.hasFocus():ts(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function Xe(t,i=!1){let e=t.state.selection;if(Ge(t,e),Ye(t)){if(!i&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Xi){let i=t.domSelectionRange(),e=t.domObserver.currentSelection;if(i.anchorNode&&e.anchorNode&&Ai(i.anchorNode,i.anchorOffset,e.anchorNode,e.anchorOffset))return t.input.mouseDown.delayedSelectionSync=!0,void t.domObserver.setCurSelection()}if(t.domObserver.disconnectSelection(),t.cursorWrapper)!function(t){let i=t.domSelection();if(!i)return;let e=t.cursorWrapper.dom,s="IMG"==e.nodeName;s?i.collapse(e.parentNode,xi(e)+1):i.collapse(e,0),!s&&!t.state.selection.visible&&Wi&&Ji<=11&&(e.disabled=!0,e.disabled=!1)}(t);else{let s,r,{anchor:n,head:h}=e;!Ue||e instanceof oi||(e.$from.parent.inlineContent||(s=He(t,e.from)),e.empty||e.$from.parent.inlineContent||(r=He(t,e.to))),t.docView.setSelection(n,h,t,i),Ue&&(s&&qe(s),r&&qe(r)),e.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(t){let i=t.dom.ownerDocument;i.removeEventListener("selectionchange",t.input.hideSelectionGuard);let e=t.domSelectionRange(),s=e.anchorNode,r=e.anchorOffset;i.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{e.anchorNode==s&&e.anchorOffset==r||(i.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout((()=>{Ye(t)&&!t.state.selection.visible||t.dom.classList.remove("ProseMirror-hideselection")}),20))})}(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}const Ue=Hi||Xi&&Ui<63;function He(t,i){let{node:e,offset:s}=t.docView.domFromPos(i,0),r=s<e.childNodes.length?e.childNodes[s]:null,n=s?e.childNodes[s-1]:null;if(Hi&&r&&"false"==r.contentEditable)return Ke(r);if(!(r&&"false"!=r.contentEditable||n&&"false"!=n.contentEditable)){if(r)return Ke(r);if(n)return Ke(n)}}function Ke(t){return t.contentEditable="true",Hi&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function qe(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function Ge(t,i){if(i instanceof ui){let e=t.docView.descAt(i.from);e!=t.lastSelectedViewDesc&&(Ve(t),e&&e.selectNode(),t.lastSelectedViewDesc=e)}else Ve(t)}function Ve(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Ze(t,i,e,s){return t.someProp("createSelectionBetween",(s=>s(t,i,e)))||oi.between(i,e,s)}function Qe(t){return!(t.editable&&!t.hasFocus())&&ts(t)}function ts(t){let i=t.domSelectionRange();if(!i.anchorNode)return!1;try{return t.dom.contains(3==i.anchorNode.nodeType?i.anchorNode.parentNode:i.anchorNode)&&(t.editable||t.dom.contains(3==i.focusNode.nodeType?i.focusNode.parentNode:i.focusNode))}catch(t){return!1}}function is(t,i){let{$anchor:e,$head:s}=t.selection,r=i>0?e.max(s):e.min(s),n=r.parent.inlineContent?r.depth?t.doc.resolve(i>0?r.after():r.before()):null:r;return n&&si.findFrom(n,i)}function es(t,i){return t.dispatch(t.state.tr.setSelection(i).scrollIntoView()),!0}function ss(t,i,e){let s=t.state.selection;if(!(s instanceof oi)){if(s instanceof ui&&s.node.isInline)return es(t,new oi(i>0?s.$to:s.$from));{let e=is(t.state,i);return!!e&&es(t,e)}}if(e.indexOf("s")>-1){let{$head:e}=s,r=e.textOffset?null:i<0?e.nodeBefore:e.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let n=t.state.doc.resolve(e.pos+r.nodeSize*(i<0?-1:1));return es(t,new oi(s.$anchor,n))}if(!s.empty)return!1;if(t.endOfTextblock(i>0?"forward":"backward")){let e=is(t.state,i);return!!(e&&e instanceof ui)&&es(t,e)}if(!(qi&&e.indexOf("m")>-1)){let e,r=s.$head,n=r.textOffset?null:i<0?r.nodeBefore:r.nodeAfter;if(!n||n.isText)return!1;let h=i<0?r.pos-n.nodeSize:r.pos;return!!(n.isAtom||(e=t.docView.descAt(h))&&!e.contentDOM)&&(ui.isSelectable(n)?es(t,new ui(i<0?t.state.doc.resolve(r.pos-n.nodeSize):r)):!!Zi&&es(t,new oi(t.state.doc.resolve(i<0?h:h+n.nodeSize))))}}function rs(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function ns(t,i){let e=t.pmViewDesc;return e&&0==e.size&&(i<0||t.nextSibling||"BR"!=t.nodeName)}function hs(t,i){return i<0?function(t){let i=t.domSelectionRange(),e=i.focusNode,s=i.focusOffset;if(!e)return;let r,n,h=!1;for(Li&&1==e.nodeType&&s<rs(e)&&ns(e.childNodes[s],-1)&&(h=!0);;)if(s>0){if(1!=e.nodeType)break;{let t=e.childNodes[s-1];if(ns(t,-1))r=e,n=--s;else{if(3!=t.nodeType)break;e=t,s=e.nodeValue.length}}}else{if(ls(e))break;{let i=e.previousSibling;for(;i&&ns(i,-1);)r=e.parentNode,n=xi(i),i=i.previousSibling;if(i)e=i,s=rs(e);else{if(e=e.parentNode,e==t.dom)break;s=0}}}h?us(t,e,s):r&&us(t,r,n)}(t):function(t){let i=t.domSelectionRange(),e=i.focusNode,s=i.focusOffset;if(!e)return;let r,n,h=rs(e);for(;;)if(s<h){if(1!=e.nodeType)break;if(!ns(e.childNodes[s],1))break;r=e,n=++s}else{if(ls(e))break;{let i=e.nextSibling;for(;i&&ns(i,1);)r=i.parentNode,n=xi(i)+1,i=i.nextSibling;if(i)e=i,s=0,h=rs(e);else{if(e=e.parentNode,e==t.dom)break;s=h=0}}}r&&us(t,r,n)}(t)}function ls(t){let i=t.pmViewDesc;return i&&i.node&&i.node.isBlock}function us(t,i,e){if(3!=i.nodeType){let t,s;(s=function(t,i){for(;t&&i==t.childNodes.length&&!Ci(t);)i=xi(t)+1,t=t.parentNode;for(;t&&i<t.childNodes.length;){let e=t.childNodes[i];if(3==e.nodeType)return e;if(1==e.nodeType&&"false"==e.contentEditable)break;t=e,i=0}}(i,e))?(i=s,e=0):(t=function(t,i){for(;t&&!i&&!Ci(t);)i=xi(t),t=t.parentNode;for(;t&&i;){let e=t.childNodes[i-1];if(3==e.nodeType)return e;if(1==e.nodeType&&"false"==e.contentEditable)break;i=(t=e).childNodes.length}}(i,e))&&(i=t,e=t.nodeValue.length)}let s=t.domSelection();if(!s)return;if(Pi(s)){let t=document.createRange();t.setEnd(i,e),t.setStart(i,e),s.removeAllRanges(),s.addRange(t)}else s.extend&&s.extend(i,e);t.domObserver.setCurSelection();let{state:r}=t;setTimeout((()=>{t.state==r&&Xe(t)}),50)}function fs(t,i){let e=t.state.doc.resolve(i);if(!Xi&&!Gi&&e.parent.inlineContent){let s=t.coordsAtPos(i);if(i>e.start()){let e=t.coordsAtPos(i-1),r=(e.top+e.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(e.left-s.left)>1)return e.left<s.left?"ltr":"rtl"}if(i<e.end()){let e=t.coordsAtPos(i+1),r=(e.top+e.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(e.left-s.left)>1)return e.left>s.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(t.dom).direction?"rtl":"ltr"}function as(t,i,e){let s=t.state.selection;if(s instanceof oi&&!s.empty||e.indexOf("s")>-1)return!1;if(qi&&e.indexOf("m")>-1)return!1;let{$from:r,$to:n}=s;if(!r.parent.inlineContent||t.endOfTextblock(i<0?"up":"down")){let e=is(t.state,i);if(e&&e instanceof ui)return es(t,e)}if(!r.parent.inlineContent){let e=i<0?r:n,h=s instanceof ai?si.near(e,i):si.findFrom(e,i);return!!h&&es(t,h)}return!1}function cs(t,i){if(!(t.state.selection instanceof oi))return!0;let{$head:e,$anchor:s,empty:r}=t.state.selection;if(!e.sameParent(s))return!0;if(!r)return!1;if(t.endOfTextblock(i>0?"forward":"backward"))return!0;let n=!e.textOffset&&(i<0?e.nodeBefore:e.nodeAfter);if(n&&!n.isText){let s=t.state.tr;return i<0?s.delete(e.pos-n.nodeSize,e.pos):s.delete(e.pos,e.pos+n.nodeSize),t.dispatch(s),!0}return!1}function ds(t,i,e){t.domObserver.stop(),i.contentEditable=e,t.domObserver.start()}function ps(t,i){t.someProp("transformCopied",(e=>{i=e(i,t)}));let e=[],{content:s,openStart:r,openEnd:n}=i;for(;r>1&&n>1&&1==s.childCount&&1==s.firstChild.childCount;){r--,n--;let t=s.firstChild;e.push(t.type.name,t.attrs!=t.type.defaultAttrs?t.attrs:null),s=t.content}let h=t.someProp("clipboardSerializer")||pt.fromSchema(t.state.schema),o=xs(),l=o.createElement("div");l.appendChild(h.serializeFragment(s,{document:o}));let u,f=l.firstChild,a=0;for(;f&&1==f.nodeType&&(u=ks[f.nodeName.toLowerCase()]);){for(let t=u.length-1;t>=0;t--){let i=o.createElement(u[t]);for(;l.firstChild;)i.appendChild(l.firstChild);l.appendChild(i),a++}f=l.firstChild}return f&&1==f.nodeType&&f.setAttribute("data-pm-slice",`${r} ${n}${a?` -${a}`:""} ${JSON.stringify(e)}`),{dom:l,text:t.someProp("clipboardTextSerializer",(e=>e(i,t)))||i.content.textBetween(0,i.content.size,"\n\n"),slice:i}}function ms(t,i,e,s,r){let n,h,o=r.parent.type.spec.code;if(!e&&!i)return null;let l=!!i&&(s||o||!e);if(l){if(t.someProp("transformPastedText",(e=>{i=e(i,o||s,t)})),o)return h=new b(d.from(t.state.schema.text(i.replace(/\r\n?/g,"\n"))),0,0),t.someProp("transformPasted",(i=>{h=i(h,t,!0)})),h;let e=t.someProp("clipboardTextParser",(e=>e(i,r,s,t)));if(e)h=e;else{let e=r.marks(),{schema:s}=t.state,h=pt.fromSchema(s);n=document.createElement("div"),i.split(/(?:\r\n?|\n)+/).forEach((t=>{let i=n.appendChild(document.createElement("p"));t&&i.appendChild(h.serializeNode(s.text(t,e)))}))}}else t.someProp("transformPastedHTML",(i=>{e=i(e,t)})),n=function(t){let i=/^(\s*<meta [^>]*>)*/.exec(t);i&&(t=t.slice(i[0].length));let e,s=xs().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t);if((e=r&&ks[r[1].toLowerCase()])&&(t=e.map((t=>"<"+t+">")).join("")+t+e.map((t=>"</"+t+">")).reverse().join("")),s.innerHTML=function(t){let i=window.trustedTypes;return i?(Os||(Os=i.defaultPolicy||i.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Os.createHTML(t)):t}(t),e)for(let t=0;t<e.length;t++)s=s.querySelector(e[t])||s;return s}(e),Zi&&function(t){let i=t.querySelectorAll(Xi?"span:not([class]):not([style])":"span.Apple-converted-space");for(let e=0;e<i.length;e++){let s=i[e];1==s.childNodes.length&&" "==s.textContent&&s.parentNode&&s.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),s)}}(n);let u=n&&n.querySelector("[data-pm-slice]"),f=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let t=+f[3];t>0;t--){let t=n.firstChild;for(;t&&1!=t.nodeType;)t=t.nextSibling;if(!t)break;n=t}if(!h){let i=t.someProp("clipboardParser")||t.someProp("domParser")||rt.fromSchema(t.state.schema);h=i.parseSlice(n,{preserveWhitespace:!(!l&&!f),context:r,ruleFromNode:t=>"BR"!=t.nodeName||t.nextSibling||!t.parentNode||ws.test(t.parentNode.nodeName)?null:{ignore:!0}})}if(f)h=function(t,i){if(!t.size)return t;let e,s=t.content.firstChild.type.schema;try{e=JSON.parse(i)}catch(i){return t}let{content:r,openStart:n,openEnd:h}=t;for(let t=e.length-2;t>=0;t-=2){let i=s.nodes[e[t]];if(!i||i.hasRequiredAttrs())break;r=d.from(i.create(e[t+1],r)),n++,h++}return new b(r,n,h)}(vs(h,+f[1],+f[2]),f[4]);else if(h=b.maxOpen(function(t,i){if(t.childCount<2)return t;for(let e=i.depth;e>=0;e--){let s,r=i.node(e).contentMatchAt(i.index(e)),n=[];if(t.forEach((t=>{if(!n)return;let i,e=r.findWrapping(t.type);if(!e)return n=null;if(i=n.length&&s.length&&ys(e,s,t,n[n.length-1],0))n[n.length-1]=i;else{n.length&&(n[n.length-1]=bs(n[n.length-1],s.length));let i=gs(t,e);n.push(i),r=r.matchType(i.type),s=e}})),n)return d.from(n)}return t}(h.content,r),!0),h.openStart||h.openEnd){let t=0,i=0;for(let i=h.content.firstChild;t<h.openStart&&!i.type.spec.isolating;t++,i=i.firstChild);for(let t=h.content.lastChild;i<h.openEnd&&!t.type.spec.isolating;i++,t=t.lastChild);h=vs(h,t,i)}return t.someProp("transformPasted",(i=>{h=i(h,t,l)})),h}const ws=/^(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 gs(t,i,e=0){for(let s=i.length-1;s>=e;s--)t=i[s].create(null,d.from(t));return t}function ys(t,i,e,s,r){if(r<t.length&&r<i.length&&t[r]==i[r]){let n=ys(t,i,e,s.lastChild,r+1);if(n)return s.copy(s.content.replaceChild(s.childCount-1,n));if(s.contentMatchAt(s.childCount).matchType(r==t.length-1?e.type:t[r+1]))return s.copy(s.content.append(d.from(gs(e,t,r+1))))}}function bs(t,i){if(0==i)return t;let e=t.content.replaceChild(t.childCount-1,bs(t.lastChild,i-1)),s=t.contentMatchAt(t.childCount).fillBefore(d.empty,!0);return t.copy(e.append(s))}function Ms(t,i,e,s,r,n){let h=i<0?t.firstChild:t.lastChild,o=h.content;return t.childCount>1&&(n=0),r<s-1&&(o=Ms(o,i,e,s,r+1,n)),r>=e&&(o=i<0?h.contentMatchAt(0).fillBefore(o,n<=r).append(o):o.append(h.contentMatchAt(h.childCount).fillBefore(d.empty,!0))),t.replaceChild(i<0?0:t.childCount-1,h.copy(o))}function vs(t,i,e){return i<t.openStart&&(t=new b(Ms(t.content,-1,i,t.openStart,0,t.openEnd),i,t.openEnd)),e<t.openEnd&&(t=new b(Ms(t.content,1,e,t.openEnd,0,0),t.openStart,e)),t}const ks={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let Ss=null;function xs(){return Ss||(Ss=document.implementation.createHTMLDocument("title"))}let Os=null;const Ts={},Ds={},As={touchstart:!0,touchmove:!0};class Rs{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Es(t,i){t.input.lastSelectionOrigin=i,t.input.lastSelectionTime=Date.now()}function $s(t){t.someProp("handleDOMEvents",(i=>{for(let e in i)t.input.eventHandlers[e]||t.dom.addEventListener(e,t.input.eventHandlers[e]=i=>Cs(t,i))}))}function Cs(t,i){return t.someProp("handleDOMEvents",(e=>{let s=e[i.type];return!!s&&(s(t,i)||i.defaultPrevented)}))}function Ps(t,i){if(!i.bubbles)return!0;if(i.defaultPrevented)return!1;for(let e=i.target;e!=t.dom;e=e.parentNode)if(!e||11==e.nodeType||e.pmViewDesc&&e.pmViewDesc.stopEvent(i))return!1;return!0}function Ns(t){return{left:t.clientX,top:t.clientY}}function Is(t,i,e,s,r){if(-1==s)return!1;let n=t.state.doc.resolve(s);for(let s=n.depth+1;s>0;s--)if(t.someProp(i,(i=>s>n.depth?i(t,e,n.nodeAfter,n.before(s),r,!0):i(t,e,n.node(s),n.before(s),r,!1))))return!0;return!1}function zs(t,i){if(t.focused||t.focus(),t.state.selection.eq(i))return;let e=t.state.tr.setSelection(i);e.setMeta("pointer",!0),t.dispatch(e)}function _s(t,i,e,s){return Is(t,"handleDoubleClickOn",i,e,s)||t.someProp("handleDoubleClick",(e=>e(t,i,s)))}function js(t,i,e,s){return Is(t,"handleTripleClickOn",i,e,s)||t.someProp("handleTripleClick",(e=>e(t,i,s)))||function(t,i,e){if(0!=e.button)return!1;let s=t.state.doc;if(-1==i)return!!s.inlineContent&&(zs(t,oi.create(s,0,s.content.size)),!0);let r=s.resolve(i);for(let i=r.depth+1;i>0;i--){let e=i>r.depth?r.nodeAfter:r.node(i),n=r.before(i);if(e.inlineContent)zs(t,oi.create(s,n+1,n+1+e.content.size));else{if(!ui.isSelectable(e))continue;zs(t,ui.create(s,n))}return!0}}(t,e,s)}function Fs(t){return Us(t)}Ds.keydown=(t,i)=>{let e=i;if(t.input.shiftKey=16==e.keyCode||e.shiftKey,!Js(t,e)&&(t.input.lastKeyCode=e.keyCode,t.input.lastKeyCodeTime=Date.now(),!Vi||!Xi||13!=e.keyCode))if(229!=e.keyCode&&t.domObserver.forceFlush(),!Ki||13!=e.keyCode||e.ctrlKey||e.altKey||e.metaKey)t.someProp("handleKeyDown",(i=>i(t,e)))||function(t,i){let e=i.keyCode,s=function(t){let i="";return t.ctrlKey&&(i+="c"),t.metaKey&&(i+="m"),t.altKey&&(i+="a"),t.shiftKey&&(i+="s"),i}(i);if(8==e||qi&&72==e&&"c"==s)return cs(t,-1)||hs(t,-1);if(46==e&&!i.shiftKey||qi&&68==e&&"c"==s)return cs(t,1)||hs(t,1);if(13==e||27==e)return!0;if(37==e||qi&&66==e&&"c"==s){let i=37==e?"ltr"==fs(t,t.state.selection.from)?-1:1:-1;return ss(t,i,s)||hs(t,i)}if(39==e||qi&&70==e&&"c"==s){let i=39==e?"ltr"==fs(t,t.state.selection.from)?1:-1:1;return ss(t,i,s)||hs(t,i)}return 38==e||qi&&80==e&&"c"==s?as(t,-1,s)||hs(t,-1):40==e||qi&&78==e&&"c"==s?function(t){if(!Hi||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:i,focusOffset:e}=t.domSelectionRange();if(i&&1==i.nodeType&&0==e&&i.firstChild&&"false"==i.firstChild.contentEditable){let e=i.firstChild;ds(t,e,"true"),setTimeout((()=>ds(t,e,"false")),20)}return!1}(t)||as(t,1,s)||hs(t,1):s==(qi?"m":"c")&&(66==e||73==e||89==e||90==e)}(t,e)?e.preventDefault():Es(t,"key");else{let i=Date.now();t.input.lastIOSEnter=i,t.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{t.input.lastIOSEnter==i&&(t.someProp("handleKeyDown",(i=>i(t,Ni(13,"Enter")))),t.input.lastIOSEnter=0)}),200)}},Ds.keyup=(t,i)=>{16==i.keyCode&&(t.input.shiftKey=!1)},Ds.keypress=(t,i)=>{let e=i;if(Js(t,e)||!e.charCode||e.ctrlKey&&!e.altKey||qi&&e.metaKey)return;if(t.someProp("handleKeyPress",(i=>i(t,e))))return void e.preventDefault();let s=t.state.selection;if(!(s instanceof oi&&s.$from.sameParent(s.$to))){let i=String.fromCharCode(e.charCode),r=()=>t.state.tr.insertText(i).scrollIntoView();/[\r\n]/.test(i)||t.someProp("handleTextInput",(e=>e(t,s.$from.pos,s.$to.pos,i,r)))||t.dispatch(r()),e.preventDefault()}};const Bs=qi?"metaKey":"ctrlKey";Ts.mousedown=(t,i)=>{let e=i;t.input.shiftKey=e.shiftKey;let s=Fs(t),r=Date.now(),n="singleClick";r-t.input.lastClick.time<500&&function(t,i){let e=i.x-t.clientX,s=i.y-t.clientY;return e*e+s*s<100}(e,t.input.lastClick)&&!e[Bs]&&t.input.lastClick.button==e.button&&("singleClick"==t.input.lastClick.type?n="doubleClick":"doubleClick"==t.input.lastClick.type&&(n="tripleClick")),t.input.lastClick={time:r,x:e.clientX,y:e.clientY,type:n,button:e.button};let h=t.posAtCoords(Ns(e));h&&("singleClick"==n?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Ws(t,h,e,!!s)):("doubleClick"==n?_s:js)(t,h.pos,h.inside,e)?e.preventDefault():Es(t,"pointer"))};class Ws{constructor(t,i,e,s){let r,n;if(this.view=t,this.pos=i,this.event=e,this.flushed=s,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!e[Bs],this.allowDefault=e.shiftKey,i.inside>-1)r=t.state.doc.nodeAt(i.inside),n=i.inside;else{let e=t.state.doc.resolve(i.pos);r=e.parent,n=e.depth?e.before():0}const h=s?null:e.target,o=h?t.docView.nearestDesc(h,!0):null;this.target=o&&1==o.nodeDOM.nodeType?o.nodeDOM:null;let{selection:l}=t.state;0==e.button&&(r.type.spec.draggable&&!1!==r.type.spec.selectable||l instanceof ui&&l.from<=n&&l.to>n)&&(this.mightDrag={node:r,pos:n,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!Li||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()),t.root.addEventListener("mouseup",this.up=this.up.bind(this)),t.root.addEventListener("mousemove",this.move=this.move.bind(this)),Es(t,"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((()=>Xe(this.view))),this.view.input.mouseDown=null}up(t){if(this.done(),!this.view.dom.contains(t.target))return;let i=this.pos;this.view.state.doc!=this.startDoc&&(i=this.view.posAtCoords(Ns(t))),this.updateAllowDefault(t),this.allowDefault||!i?Es(this.view,"pointer"):function(t,i,e,s,r){return Is(t,"handleClickOn",i,e,s)||t.someProp("handleClick",(e=>e(t,i,s)))||(r?function(t,i){if(-1==i)return!1;let e,s,r=t.state.selection;r instanceof ui&&(e=r.node);let n=t.state.doc.resolve(i);for(let t=n.depth+1;t>0;t--){let i=t>n.depth?n.nodeAfter:n.node(t);if(ui.isSelectable(i)){s=e&&r.$from.depth>0&&t>=r.$from.depth&&n.before(r.$from.depth+1)==r.$from.pos?n.before(r.$from.depth):n.before(t);break}}return null!=s&&(zs(t,ui.create(t.state.doc,s)),!0)}(t,e):function(t,i){if(-1==i)return!1;let e=t.state.doc.resolve(i),s=e.nodeAfter;return!!(s&&s.isAtom&&ui.isSelectable(s))&&(zs(t,new ui(e)),!0)}(t,e))}(this.view,i.pos,i.inside,t,this.selectNode)?t.preventDefault():0==t.button&&(this.flushed||Hi&&this.mightDrag&&!this.mightDrag.node.isAtom||Xi&&!this.view.state.selection.visible&&Math.min(Math.abs(i.pos-this.view.state.selection.from),Math.abs(i.pos-this.view.state.selection.to))<=2)?(zs(this.view,si.near(this.view.state.doc.resolve(i.pos))),t.preventDefault()):Es(this.view,"pointer")}move(t){this.updateAllowDefault(t),Es(this.view,"pointer"),0==t.buttons&&this.done()}updateAllowDefault(t){!this.allowDefault&&(Math.abs(this.event.x-t.clientX)>4||Math.abs(this.event.y-t.clientY)>4)&&(this.allowDefault=!0)}}function Js(t,i){return!!t.composing||!!(Hi&&Math.abs(i.timeStamp-t.input.compositionEndedAt)<500)&&(t.input.compositionEndedAt=-2e8,!0)}Ts.touchstart=t=>{t.input.lastTouch=Date.now(),Fs(t),Es(t,"pointer")},Ts.touchmove=t=>{t.input.lastTouch=Date.now(),Es(t,"pointer")},Ts.contextmenu=t=>Fs(t);const Ls=Vi?5e3:-1;function Ys(t,i){clearTimeout(t.input.composingTimeout),i>-1&&(t.input.composingTimeout=setTimeout((()=>Us(t)),i))}function Xs(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=function(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function Us(t,i=!1){if(!(Vi&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Xs(t),i||t.docView&&t.docView.dirty){let e=Le(t),s=t.state.selection;return e&&!e.eq(s)?t.dispatch(t.state.tr.setSelection(e)):!t.markCursor&&!i||s.$from.node(s.$from.sharedDepth(s.to)).inlineContent?t.updateState(t.state):t.dispatch(t.state.tr.deleteSelection()),!0}return!1}}Ds.compositionstart=Ds.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:i}=t,e=i.selection.$to;if(i.selection instanceof oi&&(i.storedMarks||!e.textOffset&&e.parentOffset&&e.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))||Xi&&Gi&&function(t){let{focusNode:i,focusOffset:e}=t.domSelectionRange();if(!i||1!=i.nodeType||e>=i.childNodes.length)return!1;let s=i.childNodes[e];return 1==s.nodeType&&"false"==s.contentEditable}(t)))t.markCursor=t.state.storedMarks||e.marks(),Us(t,!0),t.markCursor=null;else if(Us(t,!i.selection.empty),Li&&i.selection.empty&&e.parentOffset&&!e.textOffset&&e.nodeBefore.marks.length){let i=t.domSelectionRange();for(let e=i.focusNode,s=i.focusOffset;e&&1==e.nodeType&&0!=s;){let i=s<0?e.lastChild:e.childNodes[s-1];if(!i)break;if(3==i.nodeType){let e=t.domSelection();e&&e.collapse(i,i.nodeValue.length);break}e=i,s=-1}}t.input.composing=!0}Ys(t,Ls)},Ds.compositionend=(t,i)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=i.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then((()=>t.domObserver.flush())),t.input.compositionID++,Ys(t,20))};const Hs=Wi&&Ji<15||Ki&&Qi<604;function Ks(t,i,e,s,r){let n=ms(t,i,e,s,t.state.selection.$from);if(t.someProp("handlePaste",(i=>i(t,r,n||b.empty))))return!0;if(!n)return!1;let h=function(t){return 0==t.openStart&&0==t.openEnd&&1==t.content.childCount?t.content.firstChild:null}(n),o=h?t.state.tr.replaceSelectionWith(h,s):t.state.tr.replaceSelection(n);return t.dispatch(o.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function qs(t){let i=t.getData("text/plain")||t.getData("Text");if(i)return i;let e=t.getData("text/uri-list");return e?e.replace(/\r?\n/g," "):""}Ts.copy=Ds.cut=(t,i)=>{let e=i,s=t.state.selection,r="cut"==e.type;if(s.empty)return;let n=Hs?null:e.clipboardData,h=s.content(),{dom:o,text:l}=ps(t,h);n?(e.preventDefault(),n.clearData(),n.setData("text/html",o.innerHTML),n.setData("text/plain",l)):function(t,i){if(!t.dom.parentNode)return;let e=t.dom.parentNode.appendChild(document.createElement("div"));e.appendChild(i),e.style.cssText="position: fixed; left: -10000px; top: 10px";let s=getSelection(),r=document.createRange();r.selectNodeContents(i),t.dom.blur(),s.removeAllRanges(),s.addRange(r),setTimeout((()=>{e.parentNode&&e.parentNode.removeChild(e),t.focus()}),50)}(t,o),r&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},Ds.paste=(t,i)=>{let e=i;if(t.composing&&!Vi)return;let s=Hs?null:e.clipboardData,r=t.input.shiftKey&&45!=t.input.lastKeyCode;s&&Ks(t,qs(s),s.getData("text/html"),r,e)?e.preventDefault():function(t,i){if(!t.dom.parentNode)return;let e=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,s=t.dom.parentNode.appendChild(document.createElement(e?"textarea":"div"));e||(s.contentEditable="true"),s.style.cssText="position: fixed; left: -10000px; top: 10px",s.focus();let r=t.input.shiftKey&&45!=t.input.lastKeyCode;setTimeout((()=>{t.focus(),s.parentNode&&s.parentNode.removeChild(s),e?Ks(t,s.value,null,r,i):Ks(t,s.textContent,s.innerHTML,r,i)}),50)}(t,e)};class Gs{constructor(t,i,e){this.slice=t,this.move=i,this.node=e}}const Vs=qi?"altKey":"ctrlKey";function Zs(t,i){let e;return t.someProp("dragCopies",(t=>{e=e||t(i)})),null!=e?!e:!i[Vs]}Ts.dragstart=(t,i)=>{let e=i,s=t.input.mouseDown;if(s&&s.done(),!e.dataTransfer)return;let r,n=t.state.selection,h=n.empty?null:t.posAtCoords(Ns(e));if(h&&h.pos>=n.from&&h.pos<=(n instanceof ui?n.to-1:n.to));else if(s&&s.mightDrag)r=ui.create(t.state.doc,s.mightDrag.pos);else if(e.target&&1==e.target.nodeType){let i=t.docView.nearestDesc(e.target,!0);i&&i.node.type.spec.draggable&&i!=t.docView&&(r=ui.create(t.state.doc,i.posBefore))}let o=(r||t.state.selection).content(),{dom:l,text:u,slice:f}=ps(t,o);(!e.dataTransfer.files.length||!Xi||Ui>120)&&e.dataTransfer.clearData(),e.dataTransfer.setData(Hs?"Text":"text/html",l.innerHTML),e.dataTransfer.effectAllowed="copyMove",Hs||e.dataTransfer.setData("text/plain",u),t.dragging=new Gs(f,Zs(t,e),r)},Ts.dragend=t=>{let i=t.dragging;window.setTimeout((()=>{t.dragging==i&&(t.dragging=null)}),50)},Ds.dragover=Ds.dragenter=(t,i)=>i.preventDefault(),Ds.drop=(t,i)=>{try{!function(t,i,e){if(!i.dataTransfer)return;let s=t.posAtCoords(Ns(i));if(!s)return;let r=t.state.doc.resolve(s.pos),n=e&&e.slice;n?t.someProp("transformPasted",(i=>{n=i(n,t,!1)})):n=ms(t,qs(i.dataTransfer),Hs?null:i.dataTransfer.getData("text/html"),!1,r);let h=!(!e||!Zs(t,i));if(t.someProp("handleDrop",(e=>e(t,i,n||b.empty,h))))return void i.preventDefault();if(!n)return;i.preventDefault();let o=n?function(t,i,e){let s=t.resolve(i);if(!e.content.size)return i;let r=e.content;for(let t=0;t<e.openStart;t++)r=r.firstChild.content;for(let t=1;t<=(0==e.openStart&&e.size?2:1);t++)for(let i=s.depth;i>=0;i--){let e=i==s.depth?0:s.pos<=(s.start(i+1)+s.end(i+1))/2?-1:1,n=s.index(i)+(e>0?1:0),h=s.node(i),o=!1;if(1==t)o=h.canReplace(n,n,r);else{let t=h.contentMatchAt(n).findWrapping(r.firstChild.type);o=t&&h.canReplaceWith(n,n,t[0])}if(o)return 0==e?s.pos:e<0?s.before(i+1):s.after(i+1)}return null}(t.state.doc,r.pos,n):r.pos;null==o&&(o=r.pos);let l=t.state.tr;if(h){let{node:t}=e;t?t.replace(l):l.deleteSelection()}let u=l.mapping.map(o),f=0==n.openStart&&0==n.openEnd&&1==n.content.childCount,a=l.doc;if(f?l.replaceRangeWith(u,u,n.content.firstChild):l.replaceRange(u,u,n),l.doc.eq(a))return;let c=l.doc.resolve(u);if(f&&ui.isSelectable(n.content.firstChild)&&c.nodeAfter&&c.nodeAfter.sameMarkup(n.content.firstChild))l.setSelection(new ui(c));else{let i=l.mapping.map(o);l.mapping.maps[l.mapping.maps.length-1].forEach(((t,e,s,r)=>i=r)),l.setSelection(Ze(t,c,l.doc.resolve(i)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}(t,i,t.dragging)}finally{t.dragging=null}},Ts.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout((()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&Xe(t)}),20))},Ts.blur=(t,i)=>{let e=i;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),e.relatedTarget&&t.dom.contains(e.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)},Ts.beforeinput=(t,i)=>{if(Xi&&Vi&&"deleteContentBackward"==i.inputType){t.domObserver.flushSoon();let{domChangeCount:i}=t.input;setTimeout((()=>{if(t.input.domChangeCount!=i)return;if(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",(i=>i(t,Ni(8,"Backspace")))))return;let{$cursor:e}=t.state.selection;e&&e.pos>0&&t.dispatch(t.state.tr.delete(e.pos-1,e.pos).scrollIntoView())}),50)}};for(let t in Ds)Ts[t]=Ds[t];function Qs(t,i){if(t==i)return!0;for(let e in t)if(t[e]!==i[e])return!1;for(let e in i)if(!(e in t))return!1;return!0}class tr{constructor(t,i){this.toDOM=t,this.spec=i||nr,this.side=this.spec.side||0}map(t,i,e,s){let{pos:r,deleted:n}=t.mapResult(i.from+s,this.side<0?-1:1);return n?null:new sr(r-e,r-e,this)}valid(){return!0}eq(t){return this==t||t instanceof tr&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&Qs(this.spec,t.spec))}destroy(t){this.spec.destroy&&this.spec.destroy(t)}}class ir{constructor(t,i){this.attrs=t,this.spec=i||nr}map(t,i,e,s){let r=t.map(i.from+s,this.spec.inclusiveStart?-1:1)-e,n=t.map(i.to+s,this.spec.inclusiveEnd?1:-1)-e;return r>=n?null:new sr(r,n,this)}valid(t,i){return i.from<i.to}eq(t){return this==t||t instanceof ir&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}static is(t){return t.type instanceof ir}destroy(){}}class er{constructor(t,i){this.attrs=t,this.spec=i||nr}map(t,i,e,s){let r=t.mapResult(i.from+s,1);if(r.deleted)return null;let n=t.mapResult(i.to+s,-1);return n.deleted||n.pos<=r.pos?null:new sr(r.pos-e,n.pos-e,this)}valid(t,i){let e,{index:s,offset:r}=t.content.findIndex(i.from);return r==i.from&&!(e=t.child(s)).isText&&r+e.nodeSize==i.to}eq(t){return this==t||t instanceof er&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}destroy(){}}class sr{constructor(t,i,e){this.from=t,this.to=i,this.type=e}copy(t,i){return new sr(t,i,this.type)}eq(t,i=0){return this.type.eq(t.type)&&this.from+i==t.from&&this.to+i==t.to}map(t,i,e){return this.type.map(t,this,i,e)}static widget(t,i,e){return new sr(t,t,new tr(i,e))}static inline(t,i,e,s){return new sr(t,i,new ir(e,s))}static node(t,i,e,s){return new sr(t,i,new er(e,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof ir}get widget(){return this.type instanceof tr}}const rr=[],nr={};class hr{constructor(t,i){this.local=t.length?t:rr,this.children=i.length?i:rr}static create(t,i){return i.length?cr(i,t,0,nr):or}find(t,i,e){let s=[];return this.findInner(null==t?0:t,null==i?1e9:i,s,0,e),s}findInner(t,i,e,s,r){for(let n=0;n<this.local.length;n++){let h=this.local[n];h.from<=i&&h.to>=t&&(!r||r(h.spec))&&e.push(h.copy(h.from+s,h.to+s))}for(let n=0;n<this.children.length;n+=3)if(this.children[n]<i&&this.children[n+1]>t){let h=this.children[n]+1;this.children[n+2].findInner(t-h,i-h,e,s+h,r)}}map(t,i,e){return this==or||0==t.maps.length?this:this.mapInner(t,i,0,0,e||nr)}mapInner(t,i,e,s,r){let n;for(let h=0;h<this.local.length;h++){let o=this.local[h].map(t,e,s);o&&o.type.valid(i,o)?(n||(n=[])).push(o):r.onRemove&&r.onRemove(this.local[h].spec)}return this.children.length?function(t,i,e,s,r,n,h){let o=t.slice();for(let t=0,i=n;t<e.maps.length;t++){let s=0;e.maps[t].forEach(((t,e,r,n)=>{let h=n-r-(e-t);for(let r=0;r<o.length;r+=3){let n=o[r+1];if(n<0||t>n+i-s)continue;let l=o[r]+i-s;e>=l?o[r+1]=t<=l?-2:-1:t>=i&&h&&(o[r]+=h,o[r+1]+=h)}s+=h})),i=e.maps[t].map(i,-1)}let l=!1;for(let i=0;i<o.length;i+=3)if(o[i+1]<0){if(-2==o[i+1]){l=!0,o[i+1]=-1;continue}let u=e.map(t[i]+n),f=u-r;if(f<0||f>=s.content.size){l=!0;continue}let a=e.map(t[i+1]+n,-1)-r,{index:c,offset:d}=s.content.findIndex(f),p=s.maybeChild(c);if(p&&d==f&&d+p.nodeSize==a){let s=o[i+2].mapInner(e,p,u+1,t[i]+n+1,h);s!=or?(o[i]=f,o[i+1]=a,o[i+2]=s):(o[i+1]=-2,l=!0)}else l=!0}if(l){let l=function(t,i,e,s,r,n,h){function o(t,i){for(let n=0;n<t.local.length;n++){let o=t.local[n].map(s,r,i);o?e.push(o):h.onRemove&&h.onRemove(t.local[n].spec)}for(let e=0;e<t.children.length;e+=3)o(t.children[e+2],t.children[e]+i+1)}for(let e=0;e<t.length;e+=3)-1==t[e+1]&&o(t[e+2],i[e]+n+1);return e}(o,t,i,e,r,n,h),u=cr(l,s,0,h);i=u.local;for(let t=0;t<o.length;t+=3)o[t+1]<0&&(o.splice(t,3),t-=3);for(let t=0,i=0;t<u.children.length;t+=3){let e=u.children[t];for(;i<o.length&&o[i]<e;)i+=3;o.splice(i,0,u.children[t],u.children[t+1],u.children[t+2])}}return new hr(i.sort(dr),o)}(this.children,n||[],t,i,e,s,r):n?new hr(n.sort(dr),rr):or}add(t,i){return i.length?this==or?hr.create(t,i):this.addInner(t,i,0):this}addInner(t,i,e){let s,r=0;t.forEach(((t,n)=>{let h,o=n+e;if(h=fr(i,t,o)){for(s||(s=this.children.slice());r<s.length&&s[r]<n;)r+=3;s[r]==n?s[r+2]=s[r+2].addInner(t,h,o+1):s.splice(r,0,n,n+t.nodeSize,cr(h,t,o+1,nr)),r+=3}}));let n=ur(r?ar(i):i,-e);for(let i=0;i<n.length;i++)n[i].type.valid(t,n[i])||n.splice(i--,1);return new hr(n.length?this.local.concat(n).sort(dr):this.local,s||this.children)}remove(t){return 0==t.length||this==or?this:this.removeInner(t,0)}removeInner(t,i){let e=this.children,s=this.local;for(let s=0;s<e.length;s+=3){let r,n=e[s]+i,h=e[s+1]+i;for(let i,e=0;e<t.length;e++)(i=t[e])&&i.from>n&&i.to<h&&(t[e]=null,(r||(r=[])).push(i));if(!r)continue;e==this.children&&(e=this.children.slice());let o=e[s+2].removeInner(r,n+1);o!=or?e[s+2]=o:(e.splice(s,3),s-=3)}if(s.length)for(let e,r=0;r<t.length;r++)if(e=t[r])for(let t=0;t<s.length;t++)s[t].eq(e,i)&&(s==this.local&&(s=this.local.slice()),s.splice(t--,1));return e==this.children&&s==this.local?this:s.length||e.length?new hr(s,e):or}forChild(t,i){if(this==or)return this;if(i.isLeaf)return hr.empty;let e,s;for(let i=0;i<this.children.length;i+=3)if(this.children[i]>=t){this.children[i]==t&&(e=this.children[i+2]);break}let r=t+1,n=r+i.content.size;for(let t=0;t<this.local.length;t++){let i=this.local[t];if(i.from<n&&i.to>r&&i.type instanceof ir){let t=Math.max(r,i.from)-r,e=Math.min(n,i.to)-r;t<e&&(s||(s=[])).push(i.copy(t,e))}}if(s){let t=new hr(s.sort(dr),rr);return e?new lr([t,e]):t}return e||or}eq(t){if(this==t)return!0;if(!(t instanceof hr)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let i=0;i<this.local.length;i++)if(!this.local[i].eq(t.local[i]))return!1;for(let i=0;i<this.children.length;i+=3)if(this.children[i]!=t.children[i]||this.children[i+1]!=t.children[i+1]||!this.children[i+2].eq(t.children[i+2]))return!1;return!0}locals(t){return pr(this.localsInner(t))}localsInner(t){if(this==or)return rr;if(t.inlineContent||!this.local.some(ir.is))return this.local;let i=[];for(let t=0;t<this.local.length;t++)this.local[t].type instanceof ir||i.push(this.local[t]);return i}forEachSet(t){t(this)}}hr.empty=new hr([],[]),hr.removeOverlap=pr;const or=hr.empty;class lr{constructor(t){this.members=t}map(t,i){const e=this.members.map((e=>e.map(t,i,nr)));return lr.from(e)}forChild(t,i){if(i.isLeaf)return hr.empty;let e=[];for(let s=0;s<this.members.length;s++){let r=this.members[s].forChild(t,i);r!=or&&(r instanceof lr?e=e.concat(r.members):e.push(r))}return lr.from(e)}eq(t){if(!(t instanceof lr)||t.members.length!=this.members.length)return!1;for(let i=0;i<this.members.length;i++)if(!this.members[i].eq(t.members[i]))return!1;return!0}locals(t){let i,e=!0;for(let s=0;s<this.members.length;s++){let r=this.members[s].localsInner(t);if(r.length)if(i){e&&(i=i.slice(),e=!1);for(let t=0;t<r.length;t++)i.push(r[t])}else i=r}return i?pr(e?i:i.sort(dr)):rr}static from(t){switch(t.length){case 0:return or;case 1:return t[0];default:return new lr(t.every((t=>t instanceof hr))?t:t.reduce(((t,i)=>t.concat(i instanceof hr?i:i.members)),[]))}}forEachSet(t){for(let i=0;i<this.members.length;i++)this.members[i].forEachSet(t)}}function ur(t,i){if(!i||!t.length)return t;let e=[];for(let s=0;s<t.length;s++){let r=t[s];e.push(new sr(r.from+i,r.to+i,r.type))}return e}function fr(t,i,e){if(i.isLeaf)return null;let s=e+i.nodeSize,r=null;for(let i,n=0;n<t.length;n++)(i=t[n])&&i.from>e&&i.to<s&&((r||(r=[])).push(i),t[n]=null);return r}function ar(t){let i=[];for(let e=0;e<t.length;e++)null!=t[e]&&i.push(t[e]);return i}function cr(t,i,e,s){let r=[],n=!1;i.forEach(((i,h)=>{let o=fr(t,i,h+e);if(o){n=!0;let t=cr(o,i,e+h+1,s);t!=or&&r.push(h,h+i.nodeSize,t)}}));let h=ur(n?ar(t):t,-e).sort(dr);for(let t=0;t<h.length;t++)h[t].type.valid(i,h[t])||(s.onRemove&&s.onRemove(h[t].spec),h.splice(t--,1));return h.length||r.length?new hr(h,r):or}function dr(t,i){return t.from-i.from||t.to-i.to}function pr(t){let i=t;for(let e=0;e<i.length-1;e++){let s=i[e];if(s.from!=s.to)for(let r=e+1;r<i.length;r++){let n=i[r];if(n.from!=s.from){n.from<s.to&&(i==t&&(i=t.slice()),i[e]=s.copy(s.from,n.from),mr(i,r,s.copy(n.from,s.to)));break}n.to!=s.to&&(i==t&&(i=t.slice()),i[r]=n.copy(n.from,s.to),mr(i,r+1,n.copy(s.to,n.to)))}}return i}function mr(t,i,e){for(;i<t.length&&dr(e,t[i])>0;)i++;t.splice(i,0,e)}function wr(t){let i=[];return t.someProp("decorations",(e=>{let s=e(t.state);s&&s!=or&&i.push(s)})),t.cursorWrapper&&i.push(hr.create(t.state.doc,[t.cursorWrapper.deco])),lr.from(i)}const gr={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},yr=Wi&&Ji<=11;class br{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(t){this.anchorNode=t.anchorNode,this.anchorOffset=t.anchorOffset,this.focusNode=t.focusNode,this.focusOffset=t.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(t){return t.anchorNode==this.anchorNode&&t.anchorOffset==this.anchorOffset&&t.focusNode==this.focusNode&&t.focusOffset==this.focusOffset}}class Mr{constructor(t,i){this.view=t,this.handleDOMChange=i,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new br,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver((i=>{for(let t=0;t<i.length;t++)this.queue.push(i[t]);Wi&&Ji<=11&&i.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():Hi&&t.composing&&i.some((t=>"childList"==t.type&&"TR"==t.target.nodeName))?(t.input.badSafariComposition=!0,this.flushSoon()):this.flush()})),yr&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.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,gr)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let t=this.observer.takeRecords();if(t.length){for(let i=0;i<t.length;i++)this.queue.push(t[i]);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(Qe(this.view)){if(this.suppressingSelectionUpdates)return Xe(this.view);if(Wi&&Ji<=11&&!this.view.state.selection.empty){let t=this.view.domSelectionRange();if(t.focusNode&&Ai(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(t){if(!t.focusNode)return!0;let i,e=new Set;for(let i=t.focusNode;i;i=Oi(i))e.add(i);for(let s=t.anchorNode;s;s=Oi(s))if(e.has(s)){i=s;break}let s=i&&this.view.docView.nearestDesc(i);return s&&s.ignoreMutation({type:"selection",target:3==i.nodeType?i.parentNode:i})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}flush(){let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let i=this.pendingRecords();i.length&&(this.queue=[]);let e=t.domSelectionRange(),s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&Qe(t)&&!this.ignoreSelectionChange(e),r=-1,n=-1,h=!1,o=[];if(t.editable)for(let t=0;t<i.length;t++){let e=this.registerMutation(i[t],o);e&&(r=r<0?e.from:Math.min(e.from,r),n=n<0?e.to:Math.max(e.to,n),e.typeOver&&(h=!0))}if(!o.some((t=>"BR"==t.nodeName))||8!=t.input.lastKeyCode&&46!=t.input.lastKeyCode){if(Li&&o.length){let i=o.filter((t=>"BR"==t.nodeName));if(2==i.length){let[t,e]=i;t.parentNode&&t.parentNode.parentNode==e.parentNode?e.remove():t.remove()}else{let{focusNode:e}=this.currentSelection;for(let s of i){let i=s.parentNode;!i||"LI"!=i.nodeName||e&&xr(t,e)==i||s.remove()}}}}else for(let t of o)if("BR"==t.nodeName&&t.parentNode){let i=t.nextSibling;for(;i&&1==i.nodeType;){if("false"==i.contentEditable){t.parentNode.removeChild(t);break}i=i.firstChild}}let l=null;r<0&&s&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&Pi(e)&&(l=Le(t))&&l.eq(si.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,Xe(t),this.currentSelection.set(e),t.scrollToSelection()):(r>-1||s)&&(r>-1&&(t.docView.markDirty(r,n),function(t){if(!vr.has(t)&&(vr.set(t,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace))){if(t.requiresGeckoHackNode=Li,kr)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),kr=!0}}(t)),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,function(t,i){var e;let{focusNode:s,focusOffset:r}=t.domSelectionRange();for(let n of i)if("TR"==(null===(e=n.parentNode)||void 0===e?void 0:e.nodeName)){let i=n.nextSibling;for(;i&&"TD"!=i.nodeName&&"TH"!=i.nodeName;)i=i.nextSibling;if(i){let e=i;for(;;){let t=e.firstChild;if(!t||1!=t.nodeType||"false"==t.contentEditable||/^(BR|IMG)$/.test(t.nodeName))break;e=t}e.insertBefore(n,e.firstChild),s==n&&t.domSelection().collapse(n,r)}else n.parentNode.removeChild(n)}}(t,o)),this.handleDOMChange(r,n,h,o),t.docView&&t.docView.dirty?t.updateState(t.state):this.currentSelection.eq(e)||Xe(t),this.currentSelection.set(e))}registerMutation(t,i){if(i.indexOf(t.target)>-1)return null;let e=this.view.docView.nearestDesc(t.target);if("attributes"==t.type&&(e==this.view.docView||"contenteditable"==t.attributeName||"style"==t.attributeName&&!t.oldValue&&!t.target.getAttribute("style")))return null;if(!e||e.ignoreMutation(t))return null;if("childList"==t.type){for(let e=0;e<t.addedNodes.length;e++){let s=t.addedNodes[e];i.push(s),3==s.nodeType&&(this.lastChangedTextNode=s)}if(e.contentDOM&&e.contentDOM!=e.dom&&!e.contentDOM.contains(t.target))return{from:e.posBefore,to:e.posAfter};let s=t.previousSibling,r=t.nextSibling;if(Wi&&Ji<=11&&t.addedNodes.length)for(let i=0;i<t.addedNodes.length;i++){let{previousSibling:e,nextSibling:n}=t.addedNodes[i];(!e||Array.prototype.indexOf.call(t.addedNodes,e)<0)&&(s=e),(!n||Array.prototype.indexOf.call(t.addedNodes,n)<0)&&(r=n)}let n=s&&s.parentNode==t.target?xi(s)+1:0,h=e.localPosFromDOM(t.target,n,-1),o=r&&r.parentNode==t.target?xi(r):t.target.childNodes.length;return{from:h,to:e.localPosFromDOM(t.target,o,1)}}return"attributes"==t.type?{from:e.posAtStart-e.border,to:e.posAtEnd+e.border}:(this.lastChangedTextNode=t.target,{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue})}}let vr=new WeakMap,kr=!1;function Sr(t,i){let e=i.startContainer,s=i.startOffset,r=i.endContainer,n=i.endOffset,h=t.domAtPos(t.state.selection.anchor);return Ai(h.node,h.offset,r,n)&&([e,s,r,n]=[r,n,e,s]),{anchorNode:e,anchorOffset:s,focusNode:r,focusOffset:n}}function xr(t,i){for(let e=i.parentNode;e&&e!=t.dom;e=e.parentNode){let i=t.docView.nearestDesc(e,!0);if(i&&i.node.isBlock)return e}return null}function Or(t){let i=t.pmViewDesc;if(i)return i.parseRule();if("BR"==t.nodeName&&t.parentNode){if(Hi&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}if(t.parentNode.lastChild==t||Hi&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if("IMG"==t.nodeName&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Tr=/^(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 Dr(t,i,e){return Math.max(e.anchor,e.head)>i.content.size?null:Ze(t,i.resolve(e.anchor),i.resolve(e.head))}function Ar(t,i,e){let s=t.depth,r=i?t.end():t.pos;for(;s>0&&(i||t.indexAfter(s)==t.node(s).childCount);)s--,r++,i=!1;if(e){let i=t.node(s).maybeChild(t.indexAfter(s));for(;i&&!i.isLeaf;)i=i.firstChild,r++}return r}function Rr(t){if(2!=t.length)return!1;let i=t.charCodeAt(0),e=t.charCodeAt(1);return i>=56320&&i<=57343&&e>=55296&&e<=56319}class Er{constructor(t,i){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 Rs,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=i,this.state=i.state,this.directPlugins=i.plugins||[],this.directPlugins.forEach(Ir),this.dispatch=this.dispatch.bind(this),this.dom=t&&t.mount||document.createElement("div"),t&&(t.appendChild?t.appendChild(this.dom):"function"==typeof t?t(this.dom):t.mount&&(this.mounted=!0)),this.editable=Pr(this),Cr(this),this.nodeViews=Nr(this),this.docView=De(this.state.doc,$r(this),wr(this),this.dom,this),this.domObserver=new Mr(this,((t,i,e,s)=>function(t,i,e,s,r){let n=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,i<0){let i=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,e=Le(t,i);if(e&&!t.state.selection.eq(e)){if(Xi&&Vi&&13===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(i=>i(t,Ni(13,"Enter")))))return;let s=t.state.tr.setSelection(e);"pointer"==i?s.setMeta("pointer",!0):"key"==i&&s.scrollIntoView(),n&&s.setMeta("composition",n),t.dispatch(s)}return}let h=t.state.doc.resolve(i),o=h.sharedDepth(e);i=h.before(o+1),e=t.state.doc.resolve(e).after(o+1);let l,u,f=t.state.selection,a=function(t,i,e){let s,{node:r,fromOffset:n,toOffset:h,from:o,to:l}=t.docView.parseRange(i,e),u=t.domSelectionRange(),f=u.anchorNode;if(f&&t.dom.contains(1==f.nodeType?f:f.parentNode)&&(s=[{node:f,offset:u.anchorOffset}],Pi(u)||s.push({node:u.focusNode,offset:u.focusOffset})),Xi&&8===t.input.lastKeyCode)for(let t=h;t>n;t--){let i=r.childNodes[t-1],e=i.pmViewDesc;if("BR"==i.nodeName&&!e){h=t;break}if(!e||e.size)break}let a=t.state.doc,c=t.someProp("domParser")||rt.fromSchema(t.state.schema),d=a.resolve(o),p=null,m=c.parse(r,{topNode:d.parent,topMatch:d.parent.contentMatchAt(d.index()),topOpen:!0,from:n,to:h,preserveWhitespace:"pre"!=d.parent.type.whitespace||"full",findPositions:s,ruleFromNode:Or,context:d});if(s&&null!=s[0].pos){let t=s[0].pos,i=s[1]&&s[1].pos;null==i&&(i=t),p={anchor:t+o,head:i+o}}return{doc:m,sel:p,from:o,to:l}}(t,i,e),c=t.state.doc,p=c.slice(a.from,a.to);8===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime?(l=t.state.selection.to,u="end"):(l=t.state.selection.from,u="start"),t.input.lastKeyCode=null;let m=function(t,i,e,s,r){let n=t.findDiffStart(i,e);if(null==n)return null;let{a:h,b:o}=t.findDiffEnd(i,e+t.size,e+i.size);if("end"==r&&(s-=h+Math.max(0,n-Math.min(h,o))-n),h<n&&t.size<i.size){let t=s<=n&&s>=h?n-s:0;n-=t,n&&n<i.size&&Rr(i.textBetween(n-1,n+1))&&(n+=t?1:-1),o=n+(o-h),h=n}else if(o<n){let i=s<=n&&s>=o?n-s:0;n-=i,n&&n<t.size&&Rr(t.textBetween(n-1,n+1))&&(n+=i?1:-1),h=n+(h-o),o=n}return{start:n,endA:h,endB:o}}(p.content,a.doc.content,a.from,l,u);if(m&&t.input.domChangeCount++,(Ki&&t.input.lastIOSEnter>Date.now()-225||Vi)&&r.some((t=>1==t.nodeType&&!Tr.test(t.nodeName)))&&(!m||m.endA>=m.endB)&&t.someProp("handleKeyDown",(i=>i(t,Ni(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!m){if(!(s&&f instanceof oi&&!f.empty&&f.$head.sameParent(f.$anchor))||t.composing||a.sel&&a.sel.anchor!=a.sel.head){if(a.sel){let i=Dr(t,t.state.doc,a.sel);if(i&&!i.eq(t.state.selection)){let e=t.state.tr.setSelection(i);n&&e.setMeta("composition",n),t.dispatch(e)}}return}m={start:f.from,endA:f.to,endB:f.to}}t.state.selection.from<t.state.selection.to&&m.start==m.endB&&t.state.selection instanceof oi&&(m.start>t.state.selection.from&&m.start<=t.state.selection.from+2&&t.state.selection.from>=a.from?m.start=t.state.selection.from:m.endA<t.state.selection.to&&m.endA>=t.state.selection.to-2&&t.state.selection.to<=a.to&&(m.endB+=t.state.selection.to-m.endA,m.endA=t.state.selection.to)),Wi&&Ji<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>a.from&&" "==a.doc.textBetween(m.start-a.from-1,m.start-a.from+1)&&(m.start--,m.endA--,m.endB--);let w=a.doc.resolveNoCache(m.start-a.from),g=a.doc.resolveNoCache(m.endB-a.from),y=c.resolve(m.start),b=w.sameParent(g)&&w.parent.inlineContent&&y.end()>=m.endA;if((Ki&&t.input.lastIOSEnter>Date.now()-225&&(!b||r.some((t=>"DIV"==t.nodeName||"P"==t.nodeName)))||!b&&w.pos<a.doc.content.size&&(!w.sameParent(g)||!w.parent.inlineContent)&&w.pos<g.pos&&!/\S/.test(a.doc.textBetween(w.pos,g.pos,"","")))&&t.someProp("handleKeyDown",(i=>i(t,Ni(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>m.start&&function(t,i,e,s,r){if(e-i<=r.pos-s.pos||Ar(s,!0,!1)<r.pos)return!1;let n=t.resolve(i);if(!s.parent.isTextblock){let t=n.nodeAfter;return null!=t&&e==i+t.nodeSize}if(n.parentOffset<n.parent.content.size||!n.parent.isTextblock)return!1;let h=t.resolve(Ar(n,!0,!0));return!(!h.parent.isTextblock||h.pos>e||Ar(h,!0,!1)<e)&&s.parent.content.cut(s.parentOffset).eq(h.parent.content)}(c,m.start,m.endA,w,g)&&t.someProp("handleKeyDown",(i=>i(t,Ni(8,"Backspace")))))return void(Vi&&Xi&&t.domObserver.suppressSelectionUpdates());Xi&&m.endB==m.start&&(t.input.lastChromeDelete=Date.now()),Vi&&!b&&w.start()!=g.start()&&0==g.parentOffset&&w.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==m.endA&&(m.endB-=2,g=a.doc.resolveNoCache(m.endB-a.from),setTimeout((()=>{t.someProp("handleKeyDown",(function(i){return i(t,Ni(13,"Enter"))}))}),20));let M,v=m.start,k=m.endA,S=i=>{let e=i||t.state.tr.replace(v,k,a.doc.slice(m.start-a.from,m.endB-a.from));if(a.sel){let i=Dr(t,e.doc,a.sel);i&&!(Xi&&t.composing&&i.empty&&(m.start!=m.endB||t.input.lastChromeDelete<Date.now()-100)&&(i.head==v||i.head==e.mapping.map(k)-1)||Wi&&i.empty&&i.head==v)&&e.setSelection(i)}return n&&e.setMeta("composition",n),e.scrollIntoView()};if(b)if(w.pos==g.pos){Wi&&Ji<=11&&0==w.parentOffset&&(t.domObserver.suppressSelectionUpdates(),setTimeout((()=>Xe(t)),20));let i=S(t.state.tr.delete(v,k)),e=c.resolve(m.start).marksAcross(c.resolve(m.endA));e&&i.ensureMarks(e),t.dispatch(i)}else if(m.endA==m.endB&&(M=function(t,i){let e,s,r,n=t.firstChild.marks,h=i.firstChild.marks,o=n,l=h;for(let t=0;t<h.length;t++)o=h[t].removeFromSet(o);for(let t=0;t<n.length;t++)l=n[t].removeFromSet(l);if(1==o.length&&0==l.length)s=o[0],e="add",r=t=>t.mark(s.addToSet(t.marks));else{if(0!=o.length||1!=l.length)return null;s=l[0],e="remove",r=t=>t.mark(s.removeFromSet(t.marks))}let u=[];for(let t=0;t<i.childCount;t++)u.push(r(i.child(t)));if(d.from(u).eq(t))return{mark:s,type:e}}(w.parent.content.cut(w.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,m.endA-y.start())))){let i=S(t.state.tr);"add"==M.type?i.addMark(v,k,M.mark):i.removeMark(v,k,M.mark),t.dispatch(i)}else if(w.parent.child(w.index()).isText&&w.index()==g.index()-(g.textOffset?0:1)){let i=w.parent.textBetween(w.parentOffset,g.parentOffset),e=()=>S(t.state.tr.insertText(i,v,k));t.someProp("handleTextInput",(s=>s(t,v,k,i,e)))||t.dispatch(e())}else t.dispatch(S());else t.dispatch(S())}(this,t,i,e,s))),this.domObserver.start(),function(t){for(let i in Ts){let e=Ts[i];t.dom.addEventListener(i,t.input.eventHandlers[i]=i=>{!Ps(t,i)||Cs(t,i)||!t.editable&&i.type in Ds||e(t,i)},As[i]?{passive:!0}:void 0)}Hi&&t.dom.addEventListener("input",(()=>null)),$s(t)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let t=this._props;this._props={};for(let i in t)this._props[i]=t[i];this._props.state=this.state}return this._props}update(t){t.handleDOMEvents!=this._props.handleDOMEvents&&$s(this);let i=this._props;this._props=t,t.plugins&&(t.plugins.forEach(Ir),this.directPlugins=t.plugins),this.updateStateInner(t.state,i)}setProps(t){let i={};for(let t in this._props)i[t]=this._props[t];i.state=this.state;for(let e in t)i[e]=t[e];this.update(i)}updateState(t){this.updateStateInner(t,this._props)}updateStateInner(t,i){var e;let s=this.state,r=!1,n=!1;t.storedMarks&&this.composing&&(Xs(this),n=!0),this.state=t;let h=s.plugins!=t.plugins||this._props.plugins!=i.plugins;if(h||this._props.plugins!=i.plugins||this._props.nodeViews!=i.nodeViews){let t=Nr(this);(function(t,i){let e=0,s=0;for(let s in t){if(t[s]!=i[s])return!0;e++}for(let t in i)s++;return e!=s})(t,this.nodeViews)&&(this.nodeViews=t,r=!0)}(h||i.handleDOMEvents!=this._props.handleDOMEvents)&&$s(this),this.editable=Pr(this),Cr(this);let o=wr(this),l=$r(this),u=s.plugins==t.plugins||s.doc.eq(t.doc)?t.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",f=r||!this.docView.matchesNode(t.doc,l,o);!f&&t.selection.eq(s.selection)||(n=!0);let a="preserve"==u&&n&&null==this.dom.style.overflowAnchor&&function(t){let i,e,s=t.dom.getBoundingClientRect(),r=Math.max(0,s.top);for(let n=(s.left+s.right)/2,h=r+1;h<Math.min(innerHeight,s.bottom);h+=5){let s=t.root.elementFromPoint(n,h);if(!s||s==t.dom||!t.dom.contains(s))continue;let o=s.getBoundingClientRect();if(o.top>=r-20){i=s,e=o.top;break}}return{refDOM:i,refTop:e,stack:re(t.dom)}}(this);if(n){this.domObserver.stop();let i=f&&(Wi||Xi)&&!this.composing&&!s.selection.empty&&!t.selection.empty&&function(t,i){let e=Math.min(t.$anchor.sharedDepth(t.head),i.$anchor.sharedDepth(i.head));return t.$anchor.start(e)!=i.$anchor.start(e)}(s.selection,t.selection);if(f){let e=Xi?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(t){let i=t.domSelectionRange();if(!i.focusNode)return null;let e=function(t,i){for(;;){if(3==t.nodeType&&i)return t;if(1==t.nodeType&&i>0){if("false"==t.contentEditable)return null;i=$i(t=t.childNodes[i-1])}else{if(!t.parentNode||Ci(t))return null;i=xi(t),t=t.parentNode}}}(i.focusNode,i.focusOffset),s=function(t,i){for(;;){if(3==t.nodeType&&i<t.nodeValue.length)return t;if(1==t.nodeType&&i<t.childNodes.length){if("false"==t.contentEditable)return null;t=t.childNodes[i],i=0}else{if(!t.parentNode||Ci(t))return null;i=xi(t)+1,t=t.parentNode}}}(i.focusNode,i.focusOffset);if(e&&s&&e!=s){let i=s.pmViewDesc,r=t.domObserver.lastChangedTextNode;if(e==r||s==r)return r;if(!i||!i.isText(s.nodeValue))return s;if(t.input.compositionNode==s){let t=e.pmViewDesc;if(t&&t.isText(e.nodeValue))return s}}return e||s}(this)),!r&&this.docView.update(t.doc,l,o,this)||(this.docView.updateOuterDeco(l),this.docView.destroy(),this.docView=De(t.doc,l,o,this.dom,this)),!e||this.trackWrites&&this.dom.contains(this.trackWrites)||(i=!0)}i||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(t){let i=t.docView.domFromPos(t.state.selection.anchor,0),e=t.domSelectionRange();return Ai(i.node,i.offset,e.anchorNode,e.anchorOffset)}(this))?Xe(this,i):(Ge(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null===(e=this.dragging)||void 0===e?void 0:e.node)&&!s.doc.eq(t.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==u?this.dom.scrollTop=0:"to selection"==u?this.scrollToSelection():a&&function({refDOM:t,refTop:i,stack:e}){let s=t?t.getBoundingClientRect().top:0;ne(e,0==s?0:s-i)}(a)}scrollToSelection(){let t=this.domSelectionRange().focusNode;if(t&&this.dom.contains(1==t.nodeType?t:t.parentNode))if(this.someProp("handleScrollToSelection",(t=>t(this))));else if(this.state.selection instanceof ui){let i=this.docView.domAfterPos(this.state.selection.from);1==i.nodeType&&se(this,i.getBoundingClientRect(),t)}else se(this,this.coordsAtPos(this.state.selection.head,1),t)}destroyPluginViews(){let t;for(;t=this.pluginViews.pop();)t.destroy&&t.destroy()}updatePluginViews(t){if(t&&t.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let i=0;i<this.pluginViews.length;i++){let e=this.pluginViews[i];e.update&&e.update(this,t)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let i=this.directPlugins[t];i.spec.view&&this.pluginViews.push(i.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let i=this.state.plugins[t];i.spec.view&&this.pluginViews.push(i.spec.view(this))}}}updateDraggedNode(t,i){let e=t.node,s=-1;if(e.from<this.state.doc.content.size&&this.state.doc.nodeAt(e.from)==e.node)s=e.from;else{let t=e.from+(this.state.doc.content.size-i.doc.content.size);(t>0&&t<this.state.doc.content.size&&this.state.doc.nodeAt(t))==e.node&&(s=t)}this.dragging=new Gs(t.slice,t.move,s<0?void 0:ui.create(this.state.doc,s))}someProp(t,i){let e,s=this._props&&this._props[t];if(null!=s&&(e=i?i(s):s))return e;for(let s=0;s<this.directPlugins.length;s++){let r=this.directPlugins[s].props[t];if(null!=r&&(e=i?i(r):r))return e}let r=this.state.plugins;if(r)for(let s=0;s<r.length;s++){let n=r[s].props[t];if(null!=n&&(e=i?i(n):n))return e}}hasFocus(){if(Wi){let t=this.root.activeElement;if(t==this.dom)return!0;if(!t||!this.dom.contains(t))return!1;for(;t&&this.dom!=t&&this.dom.contains(t);){if("false"==t.contentEditable)return!1;t=t.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(t){if(t.setActive)return t.setActive();if(he)return t.focus(he);let i=re(t);t.focus(null==he?{get preventScroll(){return he={preventScroll:!0},!0}}:void 0),he||(he=!1,ne(i,0))}(this.dom),Xe(this),this.domObserver.start()}get root(){let t=this._root;if(null==t)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 t||document}updateRoot(){this._root=null}posAtCoords(t){return fe(this,t)}coordsAtPos(t,i=1){return pe(this,t,i)}domAtPos(t,i=0){return this.docView.domFromPos(t,i)}nodeDOM(t){let i=this.docView.descAt(t);return i?i.nodeDOM:null}posAtDOM(t,i,e=-1){let s=this.docView.posFromDOM(t,i,e);if(null==s)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(t,i){return function(t,i,e){return be==i&&Me==e?ve:(be=i,Me=e,ve="up"==e||"down"==e?function(t,i,e){let s=i.selection,r="up"==e?s.$from:s.$to;return ge(t,i,(()=>{let{node:i}=t.docView.domFromPos(r.pos,"up"==e?-1:1);for(;;){let e=t.docView.nearestDesc(i,!0);if(!e)break;if(e.node.isBlock){i=e.contentDOM||e.dom;break}i=e.dom.parentNode}let s=pe(t,r.pos,1);for(let t=i.firstChild;t;t=t.nextSibling){let i;if(1==t.nodeType)i=t.getClientRects();else{if(3!=t.nodeType)continue;i=Di(t,0,t.nodeValue.length).getClientRects()}for(let t=0;t<i.length;t++){let r=i[t];if(r.bottom>r.top+1&&("up"==e?s.top-r.top>2*(r.bottom-s.top):r.bottom-s.bottom>2*(s.bottom-r.top)))return!1}}return!0}))}(t,i,e):function(t,i,e){let{$head:s}=i.selection;if(!s.parent.isTextblock)return!1;let r=s.parentOffset,n=!r,h=r==s.parent.content.size,o=t.domSelection();return o?ye.test(s.parent.textContent)&&o.modify?ge(t,i,(()=>{let{focusNode:i,focusOffset:r,anchorNode:n,anchorOffset:h}=t.domSelectionRange(),l=o.caretBidiLevel;o.modify("move",e,"character");let u=s.depth?t.docView.domAfterPos(s.before()):t.dom,{focusNode:f,focusOffset:a}=t.domSelectionRange(),c=f&&!u.contains(1==f.nodeType?f:f.parentNode)||i==f&&r==a;try{o.collapse(n,h),i&&(i!=n||r!=h)&&o.extend&&o.extend(i,r)}catch(t){}return null!=l&&(o.caretBidiLevel=l),c})):"left"==e||"backward"==e?n:h:s.pos==s.start()||s.pos==s.end()}(t,i,e))}(this,i||this.state,t)}pasteHTML(t,i){return Ks(this,"",t,!1,i||new ClipboardEvent("paste"))}pasteText(t,i){return Ks(this,t,null,!0,i||new ClipboardEvent("paste"))}serializeForClipboard(t){return ps(this,t)}destroy(){this.docView&&(function(t){t.domObserver.stop();for(let i in t.input.eventHandlers)t.dom.removeEventListener(i,t.input.eventHandlers[i]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],wr(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ti=null)}get isDestroyed(){return null==this.docView}dispatchEvent(t){return function(t,i){Cs(t,i)||!Ts[i.type]||!t.editable&&i.type in Ds||Ts[i.type](t,i)}(this,t)}domSelectionRange(){let t=this.domSelection();return t?Hi&&11===this.root.nodeType&&function(t){let i=t.activeElement;for(;i&&i.shadowRoot;)i=i.shadowRoot.activeElement;return i}(this.dom.ownerDocument)==this.dom&&function(t,i){if(i.getComposedRanges){let e=i.getComposedRanges(t.root)[0];if(e)return Sr(t,e)}let e;function s(t){t.preventDefault(),t.stopImmediatePropagation(),e=t.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",s,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",s,!0),e?Sr(t,e):null}(this,t)||t:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function $r(t){let i=Object.create(null);return i.class="ProseMirror",i.contenteditable=String(t.editable),t.someProp("attributes",(e=>{if("function"==typeof e&&(e=e(t.state)),e)for(let t in e)"class"==t?i.class+=" "+e[t]:"style"==t?i.style=(i.style?i.style+";":"")+e[t]:i[t]||"contenteditable"==t||"nodeName"==t||(i[t]=String(e[t]))})),i.translate||(i.translate="no"),[sr.node(0,t.state.doc.content.size,i)]}function Cr(t){if(t.markCursor){let i=document.createElement("img");i.className="ProseMirror-separator",i.setAttribute("mark-placeholder","true"),i.setAttribute("alt",""),t.cursorWrapper={dom:i,deco:sr.widget(t.state.selection.from,i,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Pr(t){return!t.someProp("editable",(i=>!1===i(t.state)))}function Nr(t){let i=Object.create(null);function e(t){for(let e in t)Object.prototype.hasOwnProperty.call(i,e)||(i[e]=t[e])}return t.someProp("nodeViews",e),t.someProp("markViews",e),i}function Ir(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}Er.prototype.dispatch=function(t){let i=this._props.dispatchTransaction;i?i.call(this,t):this.updateState(this.state.apply(t))};const zr=["p",0],_r=["blockquote",0],jr=["hr"],Fr=["pre",["code",0]],Br=["br"],Wr=["em",0],Jr=["strong",0],Lr=["code",0],Yr=new et({nodes:{doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:()=>zr},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>_r},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>jr},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM:t=>["h"+t.attrs.level,0]},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM:()=>Fr},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs:t=>({src:t.getAttribute("src"),title:t.getAttribute("title"),alt:t.getAttribute("alt")})}],toDOM(t){let{src:i,alt:e,title:s}=t.attrs;return["img",{src:i,alt:e,title:s}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>Br}},marks:{link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs:t=>({href:t.getAttribute("href"),title:t.getAttribute("title")})}],toDOM(t){let{href:i,title:e}=t.attrs;return["a",{href:i,title:e},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:t=>"em"==t.type.name}],toDOM:()=>Wr},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:t=>"normal"!=t.style.fontWeight&&null},{style:"font-weight=400",clearMark:t=>"strong"==t.type.name},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}],toDOM:()=>Jr},code:{code:!0,parseDOM:[{tag:"code"}],toDOM:()=>Lr}}}),Xr=["ol",0],Ur=["ul",0],Hr=["li",0],Kr={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs:t=>({order:t.hasAttribute("start")?+t.getAttribute("start"):1})}],toDOM:t=>1==t.attrs.order?Xr:["ol",{start:t.attrs.order},0]},qr={parseDOM:[{tag:"ul"}],toDOM:()=>Ur},Gr={parseDOM:[{tag:"li"}],toDOM:()=>Hr,defining:!0};function Vr(t,i){let e={};for(let i in t)e[i]=t[i];for(let t in i)e[t]=i[t];return e}function Zr(t,i,e){return t.append({ordered_list:Vr(Kr,{content:"list_item+",group:e}),bullet_list:Vr(qr,{content:"list_item+",group:e}),list_item:Vr(Gr,{content:i})})}for(var Qr={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:"'"},tn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},en="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),sn="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),rn=0;rn<10;rn++)Qr[48+rn]=Qr[96+rn]=String(rn);for(rn=1;rn<=24;rn++)Qr[rn+111]="F"+rn;for(rn=65;rn<=90;rn++)Qr[rn]=String.fromCharCode(rn+32),tn[rn]=String.fromCharCode(rn);for(var nn in Qr)tn.hasOwnProperty(nn)||(tn[nn]=Qr[nn]);const hn="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),on="undefined"!=typeof navigator&&/Win/.test(navigator.platform);function ln(t){let i,e,s,r,n=t.split(/-(?!$)/),h=n[n.length-1];"Space"==h&&(h=" ");for(let t=0;t<n.length-1;t++){let h=n[t];if(/^(cmd|meta|m)$/i.test(h))r=!0;else if(/^a(lt)?$/i.test(h))i=!0;else if(/^(c|ctrl|control)$/i.test(h))e=!0;else if(/^s(hift)?$/i.test(h))s=!0;else{if(!/^mod$/i.test(h))throw new Error("Unrecognized modifier name: "+h);hn?r=!0:e=!0}}return i&&(h="Alt-"+h),e&&(h="Ctrl-"+h),r&&(h="Meta-"+h),s&&(h="Shift-"+h),h}function un(t,i,e=!0){return i.altKey&&(t="Alt-"+t),i.ctrlKey&&(t="Ctrl-"+t),i.metaKey&&(t="Meta-"+t),e&&i.shiftKey&&(t="Shift-"+t),t}function fn(t){return new ki({props:{handleKeyDown:an(t)}})}function an(t){let i=function(t){let i=Object.create(null);for(let e in t)i[ln(e)]=t[e];return i}(t);return function(t,e){let s,r=function(t){var i=!(en&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||sn&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?tn:Qr)[t.keyCode]||t.key||"Unidentified";return"Esc"==i&&(i="Escape"),"Del"==i&&(i="Delete"),"Left"==i&&(i="ArrowLeft"),"Up"==i&&(i="ArrowUp"),"Right"==i&&(i="ArrowRight"),"Down"==i&&(i="ArrowDown"),i}(e),n=i[un(r,e)];if(n&&n(t.state,t.dispatch,t))return!0;if(1==r.length&&" "!=r){if(e.shiftKey){let s=i[un(r,e,!1)];if(s&&s(t.state,t.dispatch,t))return!0}if((e.altKey||e.metaKey||e.ctrlKey)&&!(on&&e.ctrlKey&&e.altKey)&&(s=Qr[e.keyCode])&&s!=r){let r=i[un(s,e)];if(r&&r(t.state,t.dispatch,t))return!0}}return!1}}const cn=(t,i)=>!t.selection.empty&&(i&&i(t.tr.deleteSelection().scrollIntoView()),!0);function dn(t,i,e=!1){for(let s=t;s;s="start"==i?s.firstChild:s.lastChild){if(s.isTextblock)return!0;if(e&&1!=s.childCount)return!1}return!1}function pn(t){if(!t.parent.type.spec.isolating)for(let i=t.depth-1;i>=0;i--){if(t.index(i)>0)return t.doc.resolve(t.before(i+1));if(t.node(i).type.spec.isolating)break}return null}function mn(t){if(!t.parent.type.spec.isolating)for(let i=t.depth-1;i>=0;i--){let e=t.node(i);if(t.index(i)+1<e.childCount)return t.doc.resolve(t.after(i+1));if(e.type.spec.isolating)break}return null}function wn(t){for(let i=0;i<t.edgeCount;i++){let{type:e}=t.edge(i);if(e.isTextblock&&!e.hasRequiredAttrs())return e}return null}function gn(t,i,e,s){let r,n,h=i.nodeBefore,o=i.nodeAfter,l=h.type.spec.isolating||o.type.spec.isolating;if(!l&&function(t,i,e){let s=i.nodeBefore,r=i.nodeAfter,n=i.index();return!(!(s&&r&&s.type.compatibleContent(r.type))||(!s.content.size&&i.parent.canReplace(n-1,n)?(e&&e(t.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),0):!i.parent.canReplace(n,n+1)||!r.isTextblock&&!Wt(t.doc,i.pos)||(e&&e(t.tr.join(i.pos).scrollIntoView()),0)))}(t,i,e))return!0;let u=!l&&i.parent.canReplace(i.index(),i.index()+1);if(u&&(r=(n=h.contentMatchAt(h.childCount)).findWrapping(o.type))&&n.matchType(r[0]||o.type).validEnd){if(e){let s=i.pos+o.nodeSize,n=d.empty;for(let t=r.length-1;t>=0;t--)n=d.from(r[t].create(null,n));n=d.from(h.copy(n));let l=t.tr.step(new Pt(i.pos-1,s,i.pos,s,new b(n,1,0),r.length,!0)),u=l.doc.resolve(s+2*r.length);u.nodeAfter&&u.nodeAfter.type==h.type&&Wt(l.doc,u.pos)&&l.join(u.pos),e(l.scrollIntoView())}return!0}let f=o.type.spec.isolating||s>0&&l?null:si.findFrom(i,1),a=f&&f.$from.blockRange(f.$to),c=a&&_t(a);if(null!=c&&c>=i.depth)return e&&e(t.tr.lift(a,c).scrollIntoView()),!0;if(u&&dn(o,"start",!0)&&dn(h,"end")){let s=h,r=[];for(;r.push(s),!s.isTextblock;)s=s.lastChild;let n=o,l=1;for(;!n.isTextblock;n=n.firstChild)l++;if(s.canReplace(s.childCount,s.childCount,n.content)){if(e){let s=d.empty;for(let t=r.length-1;t>=0;t--)s=d.from(r[t].copy(s));e(t.tr.step(new Pt(i.pos-r.length,i.pos+o.nodeSize,i.pos+l,i.pos+o.nodeSize-l,new b(s,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function yn(t){return function(i,e){let s=i.selection,r=t<0?s.$from:s.$to,n=r.depth;for(;r.node(n).isInline;){if(!n)return!1;n--}return!!r.node(n).isTextblock&&(e&&e(i.tr.setSelection(oi.create(i.doc,t<0?r.start(n):r.end(n)))),!0)}}const bn=yn(-1),Mn=yn(1);function vn(...t){return function(i,e,s){for(let r=0;r<t.length;r++)if(t[r](i,e,s))return!0;return!1}}let kn=vn(cn,((t,i,e)=>{let s=function(t,i){let{$cursor:e}=t.selection;return!e||(i?!i.endOfTextblock("backward",t):e.parentOffset>0)?null:e}(t,e);if(!s)return!1;let r=pn(s);if(!r){let e=s.blockRange(),r=e&&_t(e);return null!=r&&(i&&i(t.tr.lift(e,r).scrollIntoView()),!0)}let n=r.nodeBefore;if(gn(t,r,i,-1))return!0;if(0==s.parent.content.size&&(dn(n,"end")||ui.isSelectable(n)))for(let e=s.depth;;e--){let h=Jt(t.doc,s.before(e),s.after(e),b.empty);if(h&&h.slice.size<h.to-h.from){if(i){let e=t.tr.step(h);e.setSelection(dn(n,"end")?si.findFrom(e.doc.resolve(e.mapping.map(r.pos,-1)),-1):ui.create(e.doc,r.pos-n.nodeSize)),i(e.scrollIntoView())}return!0}if(1==e||s.node(e-1).childCount>1)break}return!(!n.isAtom||r.depth!=s.depth-1||(i&&i(t.tr.delete(r.pos-n.nodeSize,r.pos).scrollIntoView()),0))}),((t,i,e)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(e?!e.endOfTextblock("backward",t):s.parentOffset>0)return!1;n=pn(s)}let h=n&&n.nodeBefore;return!(!h||!ui.isSelectable(h)||(i&&i(t.tr.setSelection(ui.create(t.doc,n.pos-h.nodeSize)).scrollIntoView()),0))})),Sn=vn(cn,((t,i,e)=>{let s=function(t,i){let{$cursor:e}=t.selection;return!e||(i?!i.endOfTextblock("forward",t):e.parentOffset<e.parent.content.size)?null:e}(t,e);if(!s)return!1;let r=mn(s);if(!r)return!1;let n=r.nodeAfter;if(gn(t,r,i,1))return!0;if(0==s.parent.content.size&&(dn(n,"start")||ui.isSelectable(n))){let e=Jt(t.doc,s.before(),s.after(),b.empty);if(e&&e.slice.size<e.to-e.from){if(i){let s=t.tr.step(e);s.setSelection(dn(n,"start")?si.findFrom(s.doc.resolve(s.mapping.map(r.pos)),1):ui.create(s.doc,s.mapping.map(r.pos))),i(s.scrollIntoView())}return!0}}return!(!n.isAtom||r.depth!=s.depth-1||(i&&i(t.tr.delete(r.pos,r.pos+n.nodeSize).scrollIntoView()),0))}),((t,i,e)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(e?!e.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;n=mn(s)}let h=n&&n.nodeAfter;return!(!h||!ui.isSelectable(h)||(i&&i(t.tr.setSelection(ui.create(t.doc,n.pos)).scrollIntoView()),0))}));const xn={Enter:vn(((t,i)=>{let{$head:e,$anchor:s}=t.selection;return!(!e.parent.type.spec.code||!e.sameParent(s)||(i&&i(t.tr.insertText("\n").scrollIntoView()),0))}),((t,i)=>{let e=t.selection,{$from:s,$to:r}=e;if(e instanceof ai||s.parent.inlineContent||r.parent.inlineContent)return!1;let n=wn(r.parent.contentMatchAt(r.indexAfter()));if(!n||!n.isTextblock)return!1;if(i){let e=(!s.parentOffset&&r.index()<r.parent.childCount?s:r).pos,h=t.tr.insert(e,n.createAndFill());h.setSelection(oi.create(h.doc,e+1)),i(h.scrollIntoView())}return!0}),((t,i)=>{let{$cursor:e}=t.selection;if(!e||e.parent.content.size)return!1;if(e.depth>1&&e.after()!=e.end(-1)){let s=e.before();if(Bt(t.doc,s))return i&&i(t.tr.split(s).scrollIntoView()),!0}let s=e.blockRange(),r=s&&_t(s);return null!=r&&(i&&i(t.tr.lift(s,r).scrollIntoView()),!0)}),((t,i)=>{let{$from:e}=t.selection;if(t.selection instanceof ui&&t.selection.node.isBlock)return!(!e.parentOffset||!Bt(t.doc,e.pos)||(i&&i(t.tr.split(e.pos).scrollIntoView()),0));if(!e.depth)return!1;let s,r,n=[],h=!1,o=!1;for(let t=e.depth;;t--){if(e.node(t).isBlock){h=e.end(t)==e.pos+(e.depth-t),o=e.start(t)==e.pos-(e.depth-t),r=wn(e.node(t-1).contentMatchAt(e.indexAfter(t-1))),n.unshift(h&&r?{type:r}:null),s=t;break}if(1==t)return!1;n.unshift(null)}let l=t.tr;(t.selection instanceof oi||t.selection instanceof ai)&&l.deleteSelection();let u=l.mapping.map(e.pos),f=Bt(l.doc,u,n.length,n);if(f||(n[0]=r?{type:r}:null,f=Bt(l.doc,u,n.length,n)),!f)return!1;if(l.split(u,n.length,n),!h&&o&&e.node(s).type!=r){let t=l.mapping.map(e.before(s)),i=l.doc.resolve(t);r&&e.node(s-1).canReplaceWith(i.index(),i.index()+1,r)&&l.setNodeMarkup(l.mapping.map(e.before(s)),r)}return i&&i(l.scrollIntoView()),!0})),"Mod-Enter":(t,i)=>{let{$head:e,$anchor:s}=t.selection;if(!e.parent.type.spec.code||!e.sameParent(s))return!1;let r=e.node(-1),n=e.indexAfter(-1),h=wn(r.contentMatchAt(n));if(!h||!r.canReplaceWith(n,n,h))return!1;if(i){let s=e.after(),r=t.tr.replaceWith(s,s,h.createAndFill());r.setSelection(si.near(r.doc.resolve(s),1)),i(r.scrollIntoView())}return!0},Backspace:kn,"Mod-Backspace":kn,"Shift-Backspace":kn,Delete:Sn,"Mod-Delete":Sn,"Mod-a":(t,i)=>(i&&i(t.tr.setSelection(new ai(t.doc))),!0)},On={"Ctrl-h":xn.Backspace,"Alt-Backspace":xn["Mod-Backspace"],"Ctrl-d":xn.Delete,"Ctrl-Alt-Backspace":xn["Mod-Delete"],"Alt-Delete":xn["Mod-Delete"],"Alt-d":xn["Mod-Delete"],"Ctrl-a":bn,"Ctrl-e":Mn};for(let t in xn)On[t]=xn[t];const Tn=("undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&"darwin"==os.platform())?On:xn;class Dn extends t{__class__="KritzelText";fontFamily="Arial";fontSize=8;fontColor={light:"#000000",dark:"#ffffff"};initialWidth=1;initialHeight=1;scale=1;scaleFactor=1;isDebugInfoVisible=!0;isEditable=!0;isEditing=!1;editor=null;content=null;_schema=new et({nodes:Zr(Yr.spec.nodes,"paragraph block*","block"),marks:Yr.spec.marks});uneditedObject=null;rows=1;get isEmpty(){if(!this.editor)return!0;const t=this.editor.state.doc;return 0===t.content.size||0===t.textContent.trim().length}constructor(t){if(super(),this.editor=this.createEditor(),t){this.translateX=t.translateX||0,this.translateY=t.translateY||0,this.fontSize=t.fontSize||8,this.fontFamily=t.fontFamily||"Arial",this.fontColor=t.fontColor||{light:"#000000",dark:"#ffffff"};const i=this._core?.store?.state?.scale,e=null!=i&&i<0?i:1;this.width=this.initialWidth/e,this.height=1.2*this.fontSize/e,this.scale=t.scale||1,this.scaleFactor=t.scaleX??1,t.text&&this.setContent({type:"doc",content:[{type:"paragraph",content:[{type:"text",text:t.text}]}]})}}static create(t,i,e,s){const r=new Dn;r._core=t,r.id=r.generateId(),r.workspaceId=t.store.state.activeWorkspace.id,r.userId=t.user?.id,r.fontSize=i||8,r.fontFamily=e||"Arial",r.translateX=0,r.translateY=0;const n=t.store.state.scale,h=n<0?n:1;return r.width=r.initialWidth/h,r.height=1.2*r.fontSize/h,r.backgroundColor={light:"transparent",dark:"transparent"},r.initialWidth=r.width,r.initialHeight=r.height,r.scaleFactor=1,r.scale=s??n,r.zIndex=t.store.currentZIndex,r}mount(t){null!==t&&!1!==this.isInViewport()&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=r.resolveThemeColor(this.fontColor),this.isMounted&&this.elementRef===t&&this.editor.dom.parentElement===t?this._core.store.state.isScaling||this._core.store.state.isPanning||requestAnimationFrame((()=>this.adjustSizeOnInput())):(this.elementRef=t,this.elementRef.style.whiteSpace="pre-wrap",this.elementRef.style.wordWrap="break-word",this.elementRef.innerHTML="",this.elementRef.appendChild(this.editor.dom),this.isMounted=!0,requestAnimationFrame((()=>this.adjustSizeOnInput()))))}createEditor(){const t=this._schema.node("doc",null,[this._schema.node("paragraph")]);return new Er(null,{state:Mi.create({doc:t,plugins:[fn(Tn)]}),editable:()=>!1,dispatchTransaction:t=>{const i=this.editor.state.apply(t);this.editor.updateState(i),t.docChanged&&(this.content=i.doc.toJSON(),this.adjustSizeOnInput(),t.getMeta("fromRemote")||this._core.store.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const i=this.editor.state.schema.nodeFromJSON(t),e=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,i.content);e.setMeta("fromRemote",!0),this.editor.dispatch(e)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const i=this.totalWidth,e=this.totalHeight,s=t.scrollHeight;if(this.width=t.scrollWidth*this.scaleFactor,this.height=s*this.scaleFactor,0!==this.rotation){const t=(this.totalWidth-i)/2/this.scale,s=(this.totalHeight-e)/2/this.scale;if(0!==t||0!==s){const i=Math.cos(this.rotation),e=Math.sin(this.rotation),r=e*t+i*s;this.translateX+=i*t-e*s-t,this.translateY+=r-s}}}}resize(t,i,e,s){if(e<=1||s<=1)return;const r=this.width/this.scaleFactor,n=this.height/this.scaleFactor;this.scaleFactor=Math.min(e/r,s/n),this.width=r*this.scaleFactor,this.height=n*this.scaleFactor,this.translateX=t,this.translateY=i,this._core.store.objects.update(this)}focus(t){if(this.editor){const i=this.editor.state.doc;if(t.x&&t.y&&!this.isEmpty){const e=this.editor.posAtCoords({left:t.x,top:t.y});if(e)return this.editor.dispatch(this.editor.state.tr.setSelection(oi.create(i,e.pos))),this.editor.focus(),void(o.isIOS()&&this.scrollIntoViewOnIOS())}const e=Math.max(1,i.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(oi.create(i,e))),this.editor.focus(),o.isIOS()&&this.scrollIntoViewOnIOS()}}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(t){u.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",l.getTool("text")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),this.adjustSizeOnInput(),t?.clientX&&t?.clientY&&this.focus({x:t?.clientX,y:t?.clientY}),u.enableInteractiveWidget()}save(){requestAnimationFrame((()=>this.adjustSizeOnInput())),this.content=this.editor.state.doc.toJSON(),this.editor.setProps({editable:()=>!1}),this.editor.dom.blur(),this.isEditing=!1,this._core.store.objects.consolidateTemporaryItems(),this._core.store.objects.update(this),this._core.engine.emitObjectsChange()}handleEscape(){if(!this.editor||!this.isEditing)return;const{state:t}=this.editor;if(!t.selection.empty)return this.editor.dispatch(t.tr.setSelection(oi.create(t.doc,t.selection.head))),void this.editor.focus();this._core.resetActiveText(),this._core.clearSelection(),this._core.store.setState("activeTool",l.getTool("selection"))}handlePointerDown(t){this.isEditing&&t.stopPropagation()}handlePointerMove(t){this.isEditing&&(this._core.store.state.pointers.has(t.pointerId)||t.stopPropagation())}handlePointerUp(t){this.isEditing&&(this._core.store.state.pointers.has(t.pointerId)||t.stopPropagation())}copy(){const t=super.copy();return t.editor=t.createEditor(),this.content&&t.setContent(this.content),t}serialize(){const{_core:t,_elementRef:i,_schema:e,element:s,totalWidth:r,totalHeight:n,editor:h,uneditedObject:o,...l}=this,u=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(u.element=s.cloneNode(!0)),u}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}}const An="blobs",Rn="metadata";class En{type="local";name="IndexedDBAssetProvider";_dbName;_quiet;_db=null;_urlCache=new Map;_knownIds=new Set;constructor(t){this._dbName=t?.dbName??"kritzel-assets",this._quiet=t?.quiet??!1}static with(t){return{create:()=>new En(t)}}async init(){this._db||(this._db=await this.openDatabase(),await this.loadKnownIds(),this._quiet||console.info(`IndexedDBAssetProvider initialized: ${this._dbName}`))}destroy(){for(const t of this._urlCache.values())try{URL.revokeObjectURL(t)}catch{}this._urlCache.clear(),this._knownIds.clear(),this._db&&(this._db.close(),this._db=null),this._quiet||console.info(`IndexedDBAssetProvider destroyed: ${this._dbName}`)}canResolve(t){return this._knownIds.has(t)}async put(t,i){const e=await this.ensureDb(),s=i.id??this.generateUuid(),r={id:s,kind:i.kind??"file",mimeType:i.mimeType,size:t.size,createdAt:Date.now(),width:i.width,height:i.height,durationMs:i.durationMs,originalFilename:i.originalFilename};return await new Promise(((i,n)=>{const h=e.transaction([An,Rn],"readwrite");h.oncomplete=()=>i(),h.onerror=()=>n(h.error),h.onabort=()=>n(h.error),h.objectStore(An).put(t,s),h.objectStore(Rn).put(r,s)})),this._knownIds.add(s),r}async resolve(t){const i=this._urlCache.get(t);if(i)return i;const e=await this.fetch(t),s=URL.createObjectURL(e);return this._urlCache.set(t,s),s}async fetch(t){const i=await this.ensureDb(),e=await new Promise(((e,s)=>{const r=i.transaction(An,"readonly").objectStore(An).get(t);r.onsuccess=()=>e(r.result),r.onerror=()=>s(r.error)}));if(!e)throw new Error(`[IndexedDBAssetProvider] Asset ${t} not found`);return this._knownIds.add(t),e}async delete(t){const i=await this.ensureDb();await new Promise(((e,s)=>{const r=i.transaction([An,Rn],"readwrite");r.oncomplete=()=>e(),r.onerror=()=>s(r.error),r.objectStore(An).delete(t),r.objectStore(Rn).delete(t)}));const e=this._urlCache.get(t);if(e){try{URL.revokeObjectURL(e)}catch{}this._urlCache.delete(t)}this._knownIds.delete(t)}async getMetadata(t){const i=await this.ensureDb();return new Promise(((e,s)=>{const r=i.transaction(Rn,"readonly").objectStore(Rn).get(t);r.onsuccess=()=>e(r.result),r.onerror=()=>s(r.error)}))}async listAssetsWithPendingRemotes(){const t=await this.ensureDb();return new Promise(((i,e)=>{const s=t.transaction(Rn,"readonly").objectStore(Rn).getAll();s.onsuccess=()=>{i((s.result??[]).filter((t=>Array.isArray(t.pendingRemotes)&&t.pendingRemotes.length>0)))},s.onerror=()=>e(s.error)}))}async setPendingRemotes(t,i){const e=await this.ensureDb();await new Promise(((s,r)=>{const n=e.transaction(Rn,"readwrite");n.oncomplete=()=>s(),n.onerror=()=>r(n.error);const h=n.objectStore(Rn),o=h.get(t);o.onsuccess=()=>{const e=o.result;if(!e)return;const s={...e};i.length>0?s.pendingRemotes=i:delete s.pendingRemotes,h.put(s,t)}}))}async ensureDb(){return this._db||await this.init(),this._db}openDatabase(){return new Promise(((t,i)=>{const e=indexedDB.open(this._dbName,1);e.onupgradeneeded=()=>{const t=e.result;t.objectStoreNames.contains(An)||t.createObjectStore(An),t.objectStoreNames.contains(Rn)||t.createObjectStore(Rn)},e.onsuccess=()=>t(e.result),e.onerror=()=>i(e.error)}))}async loadKnownIds(){const t=this._db;t&&await new Promise(((i,e)=>{const s=t.transaction(Rn,"readonly").objectStore(Rn).getAllKeys();s.onsuccess=()=>{for(const t of s.result)"string"==typeof t&&this._knownIds.add(t);i()},s.onerror=()=>e(s.error)}))}generateUuid(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=crypto.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const i=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}`}}class $n extends Error{assetId;constructor(t,i){super(i??`[KritzelAssetResolver] Asset ${t} not found in any configured provider.`),this.name="AssetNotFoundError",this.assetId=t}}class Cn{_providers=[];_local=null;_remoteProviders=[];_initialized=!1;_readyPromise=null;_resolveReady=null;_rejectReady=null;_pending=new Map;_flushTimer=null;_destroyed=!1;_quiet=!1;_resolvePromises=new Map;get hasRemoteProvider(){return this._remoteProviders.length>0}get localProvider(){return this._local}async init(t){if(this._initialized)return;this.getReadyPromise(),this._quiet=t?.quiet??!1;const i=this.instantiateProviders(t?.providers??[]);i.some((t=>"local"===t.type))||i.unshift(new En),i.sort(((t,i)=>"local"===t.type&&"local"!==i.type?-1:"local"!==t.type&&"local"===i.type?1:0)),this._providers=i,this._local=i.find((t=>"local"===t.type&&"IndexedDBAssetProvider"===t.name))??null,this._remoteProviders=i.filter((t=>"remote"===t.type)),this._local&&await this._local.init();for(const t of this._remoteProviders)try{await t.init()}catch(i){console.warn(`[KritzelAssetResolver] Remote provider "${t.name}" failed to initialize. Assets will be served from the local provider until the remote becomes available.`,i)}await this.recoverPendingUploads(),this._initialized=!0,this._resolveReady&&(this._resolveReady(),this._resolveReady=null,this._rejectReady=null),this._quiet||this.logProviderConfiguration(),this._pending.size>0&&this.scheduleFlush(0)}destroy(){this._quiet||console.info("Asset resolver destroyed"),this._destroyed=!0,this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null);for(const t of this._providers)try{t.destroy()}catch{}this._providers=[],this._local=null,this._remoteProviders=[],this._pending.clear(),this._resolvePromises.clear(),this._initialized=!1,this._rejectReady&&this._rejectReady(new Error("[KritzelAssetResolver] Destroyed before initialization completed.")),this._readyPromise=null,this._resolveReady=null,this._rejectReady=null}async put(t,i){await this.ensureReady();const e=i.id??this.generateUuid(),s={...i,id:e};let r=null;if(this._local&&(r=await this._local.put(t,s)),this._remoteProviders.length>0){const t=this._remoteProviders.map((t=>t.name));this._local&&await this._local.setPendingRemotes(e,t);for(const i of t)this._pending.set(this.pendingKey(e,i),{id:e,providerName:i,attempts:0,nextAttemptAt:Date.now()})}if(!r){if(0===this._remoteProviders.length)throw new Error("[KritzelAssetResolver] No providers configured to store asset.");r=await this._remoteProviders[0].put(t,s)}return this.scheduleFlush(0),r}async resolve(t){await this.ensureReady();const i=this._resolvePromises.get(t);if(i)return i;const e=(async()=>{if(this._local&&this._local.canResolve(t))return this._local.resolve(t);let i,e=0;for(const s of this._providers)if(s!==this._local){e++;try{const i=await s.fetch(t);if(this._local){try{await this._local.put(i,{id:t,mimeType:i.type||"application/octet-stream",kind:"file"})}catch{}return this._local.resolve(t)}return URL.createObjectURL(i)}catch(t){i=t}}if(0===e)throw new $n(t);throw new Error(`[KritzelAssetResolver] Failed to resolve asset ${t}: ${String(i)}`)})();this._resolvePromises.set(t,e);try{return await e}finally{this._resolvePromises.delete(t)}}async fetchBlob(t){let i;await this.ensureReady();let e=!1,s=!1,r=0;const n=this._local?[this._local,...this._providers.filter((t=>t!==this._local))]:this._providers;for(const h of n){h===this._local?e=!0:r++;try{return await h.fetch(t)}catch(t){h===this._local&&(s=!0),i=t}}if(0===r&&(!e||s))throw new $n(t);throw new Error(`[KritzelAssetResolver] Failed to fetch blob for ${t}: ${String(i)}`)}async putDataUrl(t,i){const e=await this.dataUrlToBlob(t);return this.put(e,{...i,mimeType:i.mimeType??e.type??"application/octet-stream"})}logProviderConfiguration(){const t=[`Asset resolver initialized with ${this._providers.length} provider(s):`];for(const i of this._providers)t.push(` - ${i.name} [${i===this._local?"local (primary write target)":i.type}]`);this._local&&t.push(`Write strategy: local-first (${this._local.name} → immediate, remote → background queue)`),this._remoteProviders.length>0&&t.push(`Remote replication: ${this._remoteProviders.map((t=>t.name)).join(", ")}`),this._pending.size>0&&t.push(`Pending uploads recovered: ${this._pending.size}`),console.info(t.join("\n"))}instantiateProviders(t){return t.map((t=>"function"==typeof t?new t:t.create()))}pendingKey(t,i){return`${t}::${i}`}async recoverPendingUploads(){if(!this._local||0===this._remoteProviders.length)return;const t=await this._local.listAssetsWithPendingRemotes(),i=new Set(this._remoteProviders.map((t=>t.name))),e=Date.now();let s=0;for(const r of t){const t=(r.pendingRemotes??[]).filter((t=>i.has(t)));if(0!==t.length)for(const i of t)this._pending.set(this.pendingKey(r.id,i),{id:r.id,providerName:i,attempts:0,nextAttemptAt:e}),s++;else await this._local.setPendingRemotes(r.id,[])}!this._quiet&&s>0&&console.info(`Asset resolver: recovered ${s} pending upload(s)`)}scheduleFlush(t){this._destroyed||(this._flushTimer&&clearTimeout(this._flushTimer),this._flushTimer=setTimeout((()=>{this._flushTimer=null,this.flushQueue()}),Math.max(0,t)))}async flushQueue(){if(this._destroyed)return;if(!this._local)return;const t=Date.now();let i=Number.POSITIVE_INFINITY;for(const[e,s]of Array.from(this._pending.entries())){if(s.nextAttemptAt>t){i=Math.min(i,s.nextAttemptAt-t);continue}const r=this._remoteProviders.find((t=>t.name===s.providerName));if(!r){this._pending.delete(e);continue}let n,h;try{[n,h]=await Promise.all([this._local.fetch(s.id),this._local.getMetadata(s.id)])}catch{this._pending.delete(e);continue}try{await r.put(n,{id:s.id,mimeType:h?.mimeType??n.type??"application/octet-stream",kind:h?.kind,width:h?.width,height:h?.height,durationMs:h?.durationMs,originalFilename:h?.originalFilename}),this._pending.delete(e),await this.clearPendingRemote(s.id,s.providerName),this._quiet||console.info(`Asset resolver: uploaded ${s.id} to ${r.name}`)}catch(t){s.attempts+=1;const e=Math.min(3e5,2e3*Math.pow(2,s.attempts-1));s.nextAttemptAt=Date.now()+e,i=Math.min(i,e),console.warn(`[KritzelAssetResolver] Upload to ${r.name} failed for ${s.id} (attempt ${s.attempts}). Retrying in ${Math.round(e/1e3)}s.`,t)}}this._pending.size>0&&Number.isFinite(i)&&this.scheduleFlush(i)}async clearPendingRemote(t,i){if(!this._local)return;const e=await this._local.getMetadata(t);if(!e)return;const s=(e.pendingRemotes??[]).filter((t=>t!==i));await this._local.setPendingRemotes(t,s)}ensureReady(){return this._initialized?Promise.resolve():this._destroyed?Promise.reject(new Error("[KritzelAssetResolver] Resolver was destroyed.")):this.getReadyPromise()}getReadyPromise(){return this._readyPromise||(this._readyPromise=new Promise(((t,i)=>{this._resolveReady=t,this._rejectReady=i}))),this._readyPromise}generateUuid(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=crypto.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const i=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}`}async dataUrlToBlob(t){return(await fetch(t)).blob()}}class Pn extends t{__class__="KritzelImage";assetId="";mimeType="";src="";maxWidth=300;maxHeight=300;maxCompressionSize=1200;isDebugInfoVisible=!0;resolvedSrc;loadState="idle";maxLoadAttempts=3;loadAttempts=0;maxTransientRetryDurationMs=3e4;transientRetryStartedAt=null;constructor(t){super(),this.assetId=t?.assetId||"",this.mimeType=t?.mimeType||"",this.src=t?.src||"",this.x=t?.x||0,this.y=t?.y||0,this.translateX=t?.translateX||0,this.translateY=t?.translateY||0,this.scale=t?.scale||1,this.width=t?.width||0,this.height=t?.height||0,this.maxWidth=t?.maxWidth??300,this.maxHeight=t?.maxHeight??300,this.maxLoadAttempts=t?.maxLoadAttempts??3}static create(t){const i=new Pn;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.id,i.x=0,i.y=0,i.translateX=0,i.translateY=0,i.scale=i._core.store.state.scale,i.zIndex=t.store.currentZIndex,i}resize(t,i,e,s){if(e<=1||s<=1)return;const r=s/this.height;this.width=this.width*r,this.height=this.height*r,this.translateX=t,this.translateY=i,this._core.store.objects.update(this)}serialize(){const t=super.serialize();return delete t.resolvedSrc,delete t.loadState,delete t.loadAttempts,delete t.transientRetryStartedAt,t}adoptTransientStateFrom(t){t instanceof Pn&&t.assetId===this.assetId&&(this.resolvedSrc=t.resolvedSrc,this.loadState=t.loadState,this.loadAttempts=t.loadAttempts,this.transientRetryStartedAt=t.transientRetryStartedAt)}ensureResolved(){if("loading"===this.loadState||"ready"===this.loadState)return;if("error"===this.loadState)return;if(!this.assetId)return;if(!this._core?.assetResolver)return;if(this.loadAttempts>=this.maxLoadAttempts)return void(this.loadState="error");this.loadState="loading";const t=this.loadAttempts;this._core.assetResolver.resolve(this.assetId).then((t=>{this.resolvedSrc=t,this.loadState="ready",this.transientRetryStartedAt=null,this._core?.rerender()})).catch((i=>{if(i instanceof $n){this.loadAttempts+=1,this.transientRetryStartedAt=null;const t=this.loadAttempts>=this.maxLoadAttempts;return console.warn(`[KritzelImage] Asset ${this.assetId} not found (attempt ${this.loadAttempts}/${this.maxLoadAttempts}):`,i),t?(this.loadState="error",void this._core?.rerender()):void this.scheduleRetry(this.loadAttempts)}const e=Date.now();null===this.transientRetryStartedAt&&(this.transientRetryStartedAt=e);const s=e-this.transientRetryStartedAt,r=s>=this.maxTransientRetryDurationMs;if(console.warn(`[KritzelImage] Transient resolve failure for asset ${this.assetId} (elapsed ${Math.round(s/1e3)}s/${Math.round(this.maxTransientRetryDurationMs/1e3)}s):`,i),r)return this.loadState="error",void this._core?.rerender();this.scheduleRetry(t+1)}))}scheduleRetry(t){this.loadState="idle";const i=Math.min(2e3,250*Math.pow(2,Math.max(0,t-1)));setTimeout((()=>{"idle"===this.loadState&&this.ensureResolved()}),i)}migrateLegacyDataUrlIfNeeded(){if(this.assetId)return;if(!this.src||!this.src.startsWith("data:"))return;if(!this._core?.assetResolver)return;const t=this.src;this.resolvedSrc=t,this.loadState="ready",this._core.assetResolver.putDataUrl(t,{kind:"image"}).then((t=>{this.assetId=t.id,this.mimeType=t.mimeType,this.src="",this._core?.store.objects?.update(this)})).catch((t=>{console.warn("[KritzelImage] Failed to migrate legacy data URL to asset storage:",t)}))}ensureLoaded(){this.assetId&&!this.resolvedSrc?this.ensureResolved():!this.assetId&&this.src?.startsWith("data:")&&this.migrateLegacyDataUrlIfNeeded()}mount(t){super.mount(t),this.ensureLoaded()}static fromUrl(t,i){return new Promise(((e,s)=>{const r=new Image;r.onload=()=>{const s=new Pn({...i,src:t}),{scaledWidth:n,scaledHeight:h}=s.calculateScaledDimensions(r);s.width=n,s.height=h,e(s)},r.onerror=t=>s(t),r.src=t}))}calculateScaledDimensions(t){let i=t.width,e=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);i=t.width*s,e=t.height*s}return{scaledWidth:i,scaledHeight:e}}}class Nn{static isInstanceOf(t,i){return!!t&&t.__class__===i}}class In extends t{__class__="KritzelGroup";childIds=[];_pendingChildren=[];unchangedChildSnapshots=new Map;snapshotRotation=0;snapshotTranslateX=0;snapshotTranslateY=0;snapshotTotalWidth=0;snapshotTotalHeight=0;snapshotScale=1;get children(){return this._core?this.childIds.map((t=>{const i=this._core.store.objects.filter((i=>i.id===t));return i.length>0?i[0]:null})).filter((t=>null!==t)):this._pendingChildren}get length(){return this.childIds.length}static create(t){const i=new In;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.id,i.scale=t.store.state.scale,i.zIndex=t.store.currentZIndex,i}static createFromObjects(t,i){const e=In.create(t);return i.forEach((t=>{e.childIds.push(t.id)})),e.refreshBoundingBox(),e.captureChildSnapshots(),e}static findParentGroup(t,i){const e=t.store.objects.filter((t=>"KritzelGroup"===t.__class__));for(const t of e)if(t.childIds.includes(i))return t;return null}static collectDescendantIds(t,i=new Set){for(const e of t.children)i.add(e.id),e instanceof In&&In.collectDescendantIds(e,i);return i}addChild(t){if(!this.childIds.includes(t.id)){if(this.childIds.push(t.id),!this._core)return void this._pendingChildren.push(t);this.refreshBoundingBox(),this.captureChildSnapshots()}}removeChild(t){const i=this.childIds.indexOf(t);-1!==i&&(this.childIds.splice(i,1),this.refreshBoundingBox(),this.captureChildSnapshots())}ungroup(){return this.children}finalize(){for(const t of this.children)t instanceof In&&t.finalize();this.refreshBoundingBox(),this.captureChildSnapshots()}centerInViewport(){const{viewportWidth:t,viewportHeight:i,translateX:e,translateY:s,scale:r}=this._core.store.state,{x:n,y:h,width:o,height:l}=this.rotatedBoundingBox,u=(t/2-e)/r-(n+o/2),f=(i/2-s)/r-(h+l/2);this.translateX+=u,this.translateY+=f,this.children.forEach((t=>{t.translateX+=u,t.translateY+=f})),this.captureChildSnapshots()}refreshBoundingBox(){if(0===this.children.length)return this.width=0,this.height=0,this.translateX=0,void(this.translateY=0);if(1===this.children.length){const t=this.children[0];return this.translateX=t.boundingBox.x,this.translateY=t.boundingBox.y,this.width=t.boundingBox.width*this.scale,void(this.height=t.boundingBox.height*this.scale)}const t=this.rotation,i=Math.cos(-t),e=Math.sin(-t);let s=1/0,r=-1/0,n=1/0,h=-1/0;this.children.forEach((t=>{const o=t.rotatedPolygon;[o.topLeft,o.topRight,o.bottomRight,o.bottomLeft].forEach((t=>{const o=t.x*i-t.y*e,l=t.x*e+t.y*i;o<s&&(s=o),o>r&&(r=o),l<n&&(n=l),l>h&&(h=l)}))}));const o=h-n;this.width=(r-s-this.padding)*this.scale,this.height=(o-this.padding)*this.scale;const l=(s+r)/2,u=(n+h)/2,f=Math.cos(t),a=Math.sin(t),c=l*a+u*f;this.translateX=l*f-u*a-(this.width/this.scale+2*this.padding)/2,this.translateY=c-(this.height/this.scale+2*this.padding)/2}captureChildSnapshots(){this.unchangedChildSnapshots.clear(),this.snapshotRotation=this.rotation,this.snapshotTranslateX=this.translateX,this.snapshotTranslateY=this.translateY,this.snapshotTotalWidth=this.totalWidth,this.snapshotTotalHeight=this.totalHeight,this.snapshotScale=this.scale||1,this.children.forEach((t=>{this.unchangedChildSnapshots.set(t.id,{id:t.id,translateX:t.translateX,translateY:t.translateY,rotation:t.rotation,width:t.width,height:t.height,totalWidth:t.totalWidth,totalHeight:t.totalHeight,scale:t.scale})}))}move(t,i,e,s){const r=(t-e)/this._core.store.state.scale,n=(i-s)/this._core.store.state.scale;this.translateX+=r,this.translateY+=n,this._core.store.objects.transaction((()=>{this._core.store.objects.update(this),this.children.forEach((r=>{r.move(t,i,e,s),this._core.anchorManager.updateAnchorsForObject(r.id)}))})),this.unchangedChildSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}resize(t,i,e,s){const r=this.snapshotTotalWidth>0?this.snapshotTotalWidth-2*this.padding:this.width,n=this.snapshotTotalHeight>0?this.snapshotTotalHeight-2*this.padding:this.height,h=this.snapshotScale||this.scale||1,o=0!==r?e/r:1,l=0!==n?s/n:1,u=this.snapshotTranslateX+(this.snapshotTotalWidth||this.width+2*this.padding)/2/h,f=this.snapshotTranslateY+(this.snapshotTotalHeight||this.height+2*this.padding)/2/h,a=t+(e+2*this.padding)/2/this.scale,c=i+(s+2*this.padding)/2/this.scale,d=this.rotation,p=Math.cos(-d),m=Math.sin(-d),w=Math.cos(d),g=Math.sin(d);this._core.store.objects.transaction((()=>{this.children.forEach((t=>{const i=this.unchangedChildSnapshots.get(t.id),e=i?i.width:t.width,s=i?i.height:t.height,r=(i?i.scale:t.scale)||1,n=(i?i.translateX:t.translateX)+(i?i.totalWidth:t.totalWidth)/2/r-u,h=(i?i.translateY:t.translateY)+(i?i.totalHeight:t.totalHeight)/2/r-f,y=(n*p-h*m)*o,b=(n*m+h*p)*l,M=a+(y*w-b*g),v=c+(y*g+b*w),k=(i?i.rotation:t.rotation)-d,S=Math.cos(k),x=Math.sin(k),O=e*Math.sqrt(Math.pow(o*S,2)+Math.pow(l*x,2)),T=s*Math.sqrt(Math.pow(o*x,2)+Math.pow(l*S,2));t.resize(M-(O+2*t.padding)/2/t.scale,v-(T+2*t.padding)/2/t.scale,O,T),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshBoundingBox(),this._core.store.state.isResizing||this.captureChildSnapshots(),this._core.store.objects.update(this)}))}rotate(t){this.rotation=t;const i=this.translateX+this.totalWidth/2/this.scale,e=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,r=Math.cos(s),n=Math.sin(s);this._core.store.objects.transaction((()=>{this._core.store.objects.update(this),this.children.forEach((h=>{const o=this.unchangedChildSnapshots.get(h.id);if(!o)return;const l=this.getOffsetXToCenterFromSnapshot(o),u=this.getOffsetYToCenterFromSnapshot(o),f=n*l+r*u;h.translateX=i+(r*l-n*u)-h.totalWidth/2/h.scale,h.translateY=e+f-h.totalHeight/2/h.scale,h.rotate(1===this.children.length?t:o.rotation+s)}))}))}getOffsetXToCenterFromSnapshot(t){return t.translateX+t.totalWidth/t.scale/2-(this.snapshotTranslateX+this.snapshotTotalWidth/(this.snapshotScale||this.scale||1)/2)}getOffsetYToCenterFromSnapshot(t){return t.translateY+t.totalHeight/t.scale/2-(this.snapshotTranslateY+this.snapshotTotalHeight/(this.snapshotScale||this.scale||1)/2)}hitTest(t,i){return this.children.some((e=>e.hitTest(t,i)))}hitTestPolygon(t){return this.children.some((i=>i.hitTestPolygon(t)))}copy(){const t=In.create(this._core),i=[];return this.children.sort(((t,i)=>t.zIndex-i.zIndex)).forEach((e=>{const s=e.copy();i.push(s),t.childIds.push(s.id)})),t._pendingChildren=i,t.rotation=this.rotation,t.translateX=this.translateX,t.translateY=this.translateY,t.width=this.width,t.height=this.height,t}serialize(){const{_core:t,_elementRef:i,element:e,totalWidth:s,totalHeight:r,unchangedChildSnapshots:n,_pendingChildren:h,...o}=this,l=structuredClone(o);return l.unchangedChildSnapshots=Object.fromEntries(this.unchangedChildSnapshots),l}deserialize(t){return super.deserialize(t),t.unchangedChildSnapshots&&(this.unchangedChildSnapshots=new Map(Object.entries(t.unchangedChildSnapshots))),this}update(){this._core.store.objects.update(this)}updateWorkspaceId(t){this.workspaceId=t,this.children.forEach((i=>{i.workspaceId=t,Nn.isInstanceOf(i,"KritzelGroup")&&i.updateWorkspaceId(t)}))}}var zn,_n;!function(t){t.Rectangle="rectangle",t.Ellipse="ellipse",t.Triangle="triangle"}(zn||(zn={}));class jn extends t{__class__="KritzelShape";shapeType=zn.Rectangle;fillColor={light:"transparent",dark:"transparent"};strokeColor={light:"#000000",dark:"#ffffff"};strokeWidth=4;fontFamily="Arial";fontSize=16;fontColor={light:"#000000",dark:"#ffffff"};x=0;y=0;scale=1;scaleFactor=1;isDebugInfoVisible=!0;isEditable=!0;isEditing=!1;editor=null;content=null;_schema=new et({nodes:Zr(Yr.spec.nodes,"paragraph block*","block"),marks:Yr.spec.marks});uneditedObject=null;get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),t&&(this.x=t.x??0,this.y=t.y??0,this.translateX=t.translateX??0,this.translateY=t.translateY??0,this.width=t.width??100,this.height=t.height??100,this.shapeType=t.shapeType??zn.Rectangle,this.fillColor=t.fillColor??{light:"transparent",dark:"transparent"},this.strokeColor=t.strokeColor??t.fillColor??{light:"#000000",dark:"#ffffff"},this.strokeWidth=t.strokeWidth??4,this.fontSize=t.fontSize??16,this.fontFamily=t.fontFamily??"Arial",this.fontColor=t.fontColor??r.determineTextColor(this.fillColor),this.scale=t.scale??1,this.scaleFactor=t.scaleX??1)}static create(t,i){const e=new jn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.x=i?.x??0,e.y=i?.y??0,e.translateX=i?.translateX??0,e.translateY=i?.translateY??0,e.width=i?.width??100,e.height=i?.height??100,e.shapeType=i?.shapeType??zn.Rectangle,e.fillColor=i?.fillColor??{light:"transparent",dark:"transparent"},e.strokeColor=i?.strokeColor??i?.fillColor??{light:"#000000",dark:"#ffffff"},e.strokeWidth=i?.strokeWidth??4,e.opacity=i?.opacity??1,e.fontSize=i?.fontSize??16,e.fontFamily=i?.fontFamily??"Arial",e.fontColor=i?.fontColor??r.determineTextColor(e.fillColor),e.backgroundColor={light:"transparent",dark:"transparent"},e.scaleFactor=1,e.scale=i?.scale??t.store.state.scale,e.zIndex=t.store.currentZIndex,e.editor=e.createEditor(),e.updateDimensions(),e}updateDimensions(){this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}mount(t){null!==t&&!1!==this.isInViewport()&&(this.isMounted&&this.elementRef===t&&this.editor.dom.parentElement===t||(this.elementRef=t,this.isMounted=!0))}mountTextEditor(t){null!==t&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=r.resolveThemeColor(this.fontColor),t.style.whiteSpace="pre-wrap",t.style.wordWrap="break-word",this.editor.dom.parentElement!==t&&(t.innerHTML="",t.appendChild(this.editor.dom)))}createEditor(){const t=this._schema.node("doc",null,[this._schema.node("paragraph")]);return new Er(null,{state:Mi.create({doc:t,plugins:[fn(Tn)]}),editable:()=>!1,dispatchTransaction:t=>{const i=this.editor.state.apply(t);this.editor.updateState(i),t.docChanged&&(this.content=i.doc.toJSON(),t.getMeta("fromRemote")||this._core.store.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const i=this.editor.state.schema.nodeFromJSON(t),e=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,i.content);e.setMeta("fromRemote",!0),this.editor.dispatch(e)}}resize(t,i,e,s){e<=1||s<=1||(this.width=e,this.height=s,this.translateX=t,this.translateY=i,this._core.store.objects.update(this))}focus(t){if(!this.editor)return;const i=this.editor.state.doc;if(t?.x&&t?.y){const e=this.editor.posAtCoords({left:t.x,top:t.y});if(e)return this.editor.dispatch(this.editor.state.tr.setSelection(oi.create(i,e.pos))),this.editor.focus(),void(o.isIOS()&&this.scrollIntoViewOnIOS())}const e=Math.max(1,i.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(oi.create(i,e))),this.editor.focus(),o.isIOS()&&this.scrollIntoViewOnIOS()}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(t){u.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",l.getTool("shape")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),t?.clientX&&t?.clientY&&this.focus({x:t.clientX,y:t.clientY}),u.enableInteractiveWidget()}save(){this.content=this.editor.state.doc.toJSON(),this.editor.setProps({editable:()=>!1}),this.editor.dom.blur(),this.isEditing=!1,this._core.store.objects.consolidateTemporaryItems(),this._core.store.objects.update(this),this._core.engine.emitObjectsChange()}handleEscape(){if(!this.editor||!this.isEditing)return;const{state:t}=this.editor;if(!t.selection.empty)return this.editor.dispatch(t.tr.setSelection(oi.create(t.doc,t.selection.head))),void this.editor.focus();this._core.resetActiveShape(),this._core.clearSelection(),this._core.store.setState("activeTool",l.getTool("selection"))}handlePointerDown(t){this.isEditing&&(this._core.store.state.pointers.has(t.pointerId)||t.stopPropagation())}handlePointerMove(t){this.isEditing&&(this._core.store.state.pointers.has(t.pointerId)||t.stopPropagation())}handlePointerUp(t){this.isEditing&&(this._core.store.state.pointers.has(t.pointerId)||t.stopPropagation())}copy(){const t=super.copy();return t.editor=t.createEditor(),this.content&&t.setContent(this.content),t}serialize(){const{_core:t,_elementRef:i,_schema:e,element:s,totalWidth:r,totalHeight:n,editor:h,uneditedObject:o,...l}=this,u=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(u.element=s.cloneNode(!0)),u}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}onAfterUpdate(t){t.includes("fillColor")?(this.fontColor=r.determineTextColor(this.fillColor),this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=r.resolveThemeColor(this.fontColor))):t.includes("fontColor")&&this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=r.resolveThemeColor(this.fontColor))}getClipPolygon(){const t=this.totalWidth/this.scale,e=this.totalHeight/this.scale,s=this.translateX+t/2,r=this.translateY+e/2,n=this.strokeWidth/this.scale/2;switch(this.shapeType){case zn.Ellipse:return i.getEllipsePolygonApproximation(s,r,t/2+n,e/2+n,32,this.rotation);case zn.Triangle:const h=(t,i)=>{const e=t-s,h=i-r,o=Math.sqrt(e*e+h*h);if(0===o)return{x:t,y:i};const l=(o+n)/o;return{x:s+e*l,y:r+h*l}},o=this.translateX,l=this.translateY+e,u=this.translateX+t,f=this.translateY+e,a=h(this.translateX+t/2,this.translateY),c=h(u,f),d=h(o,l);if(0!==this.rotation){const t=Math.cos(this.rotation),i=Math.sin(this.rotation),e=e=>{const n=e.x-s,h=e.y-r;return{x:s+n*t-h*i,y:r+n*i+h*t}};return[e(a),e(c),e(d)]}return[a,c,d];default:return null}}getSvgPath(){const t=this.width,i=this.height;switch(this.shapeType){case zn.Rectangle:return`M ${this.x} ${this.y} L ${this.x+t} ${this.y} L ${this.x+t} ${this.y+i} L ${this.x} ${this.y+i} Z`;case zn.Ellipse:const e=this.x+t/2,s=this.y+i/2,r=t/2,n=i/2;return`M ${e-r} ${s} A ${r} ${n} 0 1 0 ${e+r} ${s} A ${r} ${n} 0 1 0 ${e-r} ${s}`;case zn.Triangle:return`M ${this.x+t/2} ${this.y} L ${this.x+t} ${this.y+i} L ${this.x} ${this.y+i} Z`;default:return`M ${this.x} ${this.y} L ${this.x+t} ${this.y} L ${this.x+t} ${this.y+i} L ${this.x} ${this.y+i} Z`}}}class Fn{static isRightClick(t){return t.button===h.Right}static isLeftClick(t){return t.button===h.Left}static isPointerEventOnContextMenu(t){return!!t.composedPath().find((t=>t.classList&&t.classList.contains("context-menu")))}static onLongPress(t,i,e){if("touch"!==t.pointerType)return e?.(),()=>{};const s=t.clientX,r=t.clientY,n=t.target;if(!n)return e?.(),()=>{};const h=setTimeout((()=>{a(),i(t)}),400),o=()=>{clearTimeout(h),a(),e?.()},l=t=>{(Math.abs(t.clientX-s)>10||Math.abs(t.clientY-r)>10)&&o()},u=()=>{o()},f=()=>{o()},a=()=>{n.removeEventListener("pointermove",l),n.removeEventListener("pointerup",u),n.removeEventListener("pointercancel",f)};return n.addEventListener("pointermove",l,{passive:!0}),n.addEventListener("pointerup",u,{once:!0}),n.addEventListener("pointercancel",f,{once:!0}),o}}class Bn{__class__=this.constructor.name;name="base-tool";_core;constructor(t){this._core=t}onActivate(){}onDeactivate(){}handlePointerDown(t){}handlePointerMove(t){}handlePointerUp(t){}handleWheel(t){}serialize(){return{__class__:this.__class__,name:this.name}}deserialize(t){return Object.assign(this,t),this}}class Wn extends Bn{color=n[0];size=6;opacity=1;palette=[...n];_currentPathId=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&Fn.isLeftClick(t)){this._core.store.state.isDrawing=!0;const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=e.create(this._core,{points:[[(t.clientX-this._core.store.offsetX)/r,(t.clientY-this._core.store.offsetY)/r]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?1:i,fill:this.color,strokeWidth:this.size,opacity:this.opacity});n.isCompleted=!1,this._currentPathId=n.id,this._core.store.objects.insert(n),this._core.store.objects?.setActiveDrawingObject(n.id)}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/r),h=Math.round((t[0].clientY-this._core.store.offsetY)/r);this._core.store.state.isDrawing=!0;const o=e.create(this._core,{points:[[n,h]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?1:i,fill:this.color,strokeWidth:this.size,opacity:this.opacity});o.isCompleted=!1,this._currentPathId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentPathId){const i=this._core.store.objects.findById(this._currentPathId);if(i){const s=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?s:1,h=e.create(this._core,{points:[...i.points,[(t.clientX-this._core.store.offsetX)/n,(t.clientY-this._core.store.offsetY)/n]],translateX:-this._core.store.state.translateX/n,translateY:-this._core.store.state.translateY/n,scale:r?1:s,fill:this.color,strokeWidth:this.size,opacity:this.opacity});h.id=i.id,h.workspaceId=i.workspaceId,h.zIndex=i.zIndex,h.isCompleted=!1,this._core.store.objects.update(h)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length&&this._currentPathId){const i=this._core.store.objects.findById(this._currentPathId);if(i){const s=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?s:1,h=Math.round((t[0].clientX-this._core.store.offsetX)/n),o=Math.round((t[0].clientY-this._core.store.offsetY)/n),l=e.create(this._core,{points:[...i.points,[h,o]],translateX:-this._core.store.state.translateX/n,translateY:-this._core.store.state.translateY/n,scale:r?1:s,fill:this.color,strokeWidth:this.size,opacity:this.opacity});l.id=i.id,l.workspaceId=i.workspaceId,l.zIndex=i.zIndex,l.isCompleted=!1,this._core.store.objects.update(l)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}}}class Jn extends t{__class__="KritzelSelectionGroup";_objectIds=[];_cachedObjects=null;_cachedObjectIdsHash="";unchangedObjectSnapshots=new Map;snapshotRotation=0;snapshotWidth=0;snapshotHeight=0;snapshotTranslateX=0;snapshotTranslateY=0;clientId;minX=0;maxX=0;minY=0;maxY=0;handleColor;handleStrokeColor;handleSize=6;_lastChildPersistTime=0;static CHILD_PERSIST_THROTTLE_MS=100;get objectIds(){return this._objectIds}set objectIds(t){this._objectIds=t,this._cachedObjects=null}invalidateObjectsCache(){this._cachedObjects=null}get objects(){const t=this._objectIds.join(",");if(null!==this._cachedObjects&&this._cachedObjectIdsHash===t)return this._cachedObjects;const i=new Set(this._objectIds),e=this._core.store.objects.filter((t=>i.has(t.id))),s=new Map(e.map((t=>[t.id,t])));return this._cachedObjects=this._objectIds.map((t=>s.get(t))).filter((t=>void 0!==t)),this._cachedObjectIdsHash=t,this._cachedObjects}get length(){return this.objectIds.length}static create(t){const i=new Jn;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.id,i.clientId=t.store.objects?.localClientId??void 0,i.scale=t.store.state.scale,i.zIndex=99999,i.borderColor={light:"#007AFF",dark:"#0A84FF"},i.borderWidth=2,i.handleColor={light:"#ffffff",dark:"#1a1a1a"},i.handleStrokeColor={light:"#007AFF",dark:"#0A84FF"},i.handleSize=6,i}addObjects(t){let i=!1;for(const e of t)this._objectIds.includes(e.id)||(this._objectIds.push(e.id),i=!0);if(i){this._cachedObjects=null;const t=this.objects;1===t.length?this.rotation=t[0].rotation:t.length>1&&(this.rotation=0),this.captureUnchangedSnapshots(t),this.refreshObjectDimensions(t)}}addOrRemove(t){const i=this._objectIds.findIndex((i=>i===t.id));-1===i?this._objectIds.push(t.id):this._objectIds.splice(i,1),this._cachedObjects=null;const e=this.objects;1===e.length?this.rotation=e[0].rotation:e.length>1&&(this.rotation=0),this.captureUnchangedSnapshots(e),this.refreshObjectDimensions(e)}beginTransform(){const t=this.objects;this.refreshObjectDimensions(t),this.captureUnchangedSnapshots(t);for(const i of t)Nn.isInstanceOf(i,"KritzelGroup")&&i.finalize()}deselectAllChildren(){const t=this.objects;for(const i of t)i.isSelected=!1}updateWorkspaceId(t){this.workspaceId=t;const i=this.objects;for(const e of i)e.workspaceId=t}updateZIndices(t){const i=this.objects;for(let e=0;e<i.length;e++)i[e].zIndex=t+e}updatePosition(t,i){const e=this.objects;for(const s of e)s.updatePosition(t+(s.translateX-this.translateX),i+(s.translateY-this.translateY));this.unchangedObjectSnapshots.forEach((e=>{const s=e.translateY-this.translateY;e.translateX=t+(e.translateX-this.translateX),e.translateY=i+s})),this.translateX=t,this.translateY=i,this._core.store.objects.update(this)}captureUnchangedSnapshots(t){this.unchangedObjectSnapshots.clear(),this.snapshotRotation=this.rotation,this.snapshotWidth=this.width,this.snapshotHeight=this.height,this.snapshotTranslateX=this.translateX,this.snapshotTranslateY=this.translateY,(t??this.objects).forEach((t=>{this.unchangedObjectSnapshots.set(t.id,{id:t.id,translateX:t.translateX,translateY:t.translateY,rotation:t.rotation,width:t.width,height:t.height,totalWidth:t.totalWidth,totalHeight:t.totalHeight,scale:t.scale})}))}serialize(){const{_core:t,_elementRef:i,element:e,totalWidth:s,totalHeight:r,unchangedObjectSnapshots:n,_cachedObjects:h,_cachedObjectIdsHash:o,snapshotWidth:l,snapshotHeight:u,snapshotTranslateX:f,snapshotTranslateY:a,snapshotRotation:c,...d}=this,p=structuredClone(d);return p.objectIds=this.objectIds,delete p._objectIds,e&&"object"==typeof e&&"nodeType"in e&&1===e.nodeType&&(p.element=e.cloneNode(!0)),p.unchangedObjectSnapshots=Object.fromEntries(this.unchangedObjectSnapshots),p}deserialize(t){return super.deserialize(t),t.objectIds&&(this.objectIds=t.objectIds),t.unchangedObjectSnapshots&&(this.unchangedObjectSnapshots=new Map(Object.entries(t.unchangedObjectSnapshots))),this}update(){this._core.store.objects.update(this)}move(t,i,e,s){const r=(t-e)/this._core.store.state.scale,n=(i-s)/this._core.store.state.scale;this.translateX+=r,this.translateY+=n;const h=Date.now();h-this._lastChildPersistTime>=Jn.CHILD_PERSIST_THROTTLE_MS?(this._core.store.objects.transaction((()=>{this._core.store.objects.update(this);const r=this.objects;for(const n of r)n.move(t,i,e,s),this._core.anchorManager.updateAnchorsForObject(n.id)})),this._lastChildPersistTime=h):(this._core.store.objects.update(this),this._core.store.objects.withLocalUpdatesOnly((()=>{const r=this.objects;for(const n of r)n.move(t,i,e,s),this._core.anchorManager.updateAnchorsForObject(n.id)}))),this.unchangedObjectSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}persistChildren(){this._core.store.objects.transaction((()=>{const t=this.objects;for(const i of t)this._core.store.objects.update(i)}))}resize(t,i,e,s){const r=e/this.snapshotWidth,n=s/this.snapshotHeight,h=this.snapshotTranslateX+(this.snapshotWidth+2*this.padding)/2/this.scale,o=this.snapshotTranslateY+(this.snapshotHeight+2*this.padding)/2/this.scale,l=t+(e+2*this.padding)/2/this.scale,u=i+(s+2*this.padding)/2/this.scale,f=this.rotation,a=Math.cos(-f),c=Math.sin(-f),d=Math.cos(f),p=Math.sin(f);this._core.store.objects.transaction((()=>{const t=this.objects;t.forEach((t=>{const i=this.unchangedObjectSnapshots.get(t.id);if(!i)return;const e=i.translateX+i.totalWidth/2/i.scale-h,s=i.translateY+i.totalHeight/2/i.scale-o,m=(e*a-s*c)*r,w=(e*c+s*a)*n,g=l+(m*d-w*p),y=u+(m*p+w*d),b=i.rotation-f,M=Math.cos(b),v=Math.sin(b),k=Math.sqrt(Math.pow(r*M,2)+Math.pow(n*v,2)),S=Math.sqrt(Math.pow(r*v,2)+Math.pow(n*M,2)),x=i.width*k,O=i.height*S;t.resize(g-(x+2*t.padding)/2/t.scale,y-(O+2*t.padding)/2/t.scale,x,O),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshObjectDimensions(t),this._core.store.objects.update(this)}))}rotate(t){this.rotation=t;const i=this.translateX+this.totalWidth/2/this.scale,e=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,r=Math.cos(s),n=Math.sin(s),h=this.objects;this._core.store.objects.transaction((()=>{this._core.store.objects.update(this);const o=h.length;for(const l of h){const h=this.unchangedObjectSnapshots.get(l.id);if(!h)continue;const u=this.getOffsetXToCenterFromSnapshot(h),f=this.getOffsetYToCenterFromSnapshot(h),a=n*u+r*f;l.translateX=i+(r*u-n*f)-l.totalWidth/2/l.scale,l.translateY=e+a-l.totalHeight/2/l.scale,l.rotate(1===o?t:h.rotation+s)}}))}copy(){const t=Jn.create(this._core),i=this.objects,e=[...i].sort(((t,i)=>t.zIndex-i.zIndex));for(const i of e){const e=i.copy();t.addOrRemove(e)}return t.captureUnchangedSnapshots(),1===i.length&&(t.rotation=i[0].rotation),t}refreshObjectDimensions(t,i=!1){const e=t??this.objects;if(1===e.length){const t=e[0];this.minX=t.boundingBox.x/this.scale,this.maxX=t.boundingBox.x/this.scale+t.boundingBox.width,this.minY=t.boundingBox.y/this.scale,this.maxY=t.boundingBox.y/this.scale+t.boundingBox.height,this.translateX=(this.minX-this.padding)*this.scale,this.translateY=(this.minY-this.padding)*this.scale,this.width=(this.maxX-this.minX-this.padding)*this.scale,this.height=(this.maxY-this.minY-this.padding)*this.scale}else{const t=this.rotation,i=Math.cos(-t),s=Math.sin(-t);let r=1/0,n=-1/0,h=1/0,o=-1/0;e.forEach((t=>{const e=t.rotatedPolygon;[e.topLeft,e.topRight,e.bottomRight,e.bottomLeft].forEach((t=>{const e=t.x*i-t.y*s,l=t.x*s+t.y*i;e<r&&(r=e),e>n&&(n=e),l<h&&(h=l),l>o&&(o=l)}))}));const l=o-h;this.width=(n-r-this.padding)*this.scale,this.height=(l-this.padding)*this.scale;const u=(r+n)/2,f=(h+o)/2,a=Math.cos(t),c=Math.sin(t),d=u*c+f*a;this.translateX=u*a-f*c-(this.width/this.scale+2*this.padding)/2,this.translateY=d-(this.height/this.scale+2*this.padding)/2}i||this._core.store.objects.update(this)}getOffsetXToCenterFromSnapshot(t){return t.translateX+t.totalWidth/t.scale/2-(this.translateX+this.totalWidth/this.scale/2)}getOffsetYToCenterFromSnapshot(t){return t.translateY+t.totalHeight/t.scale/2-(this.translateY+this.totalHeight/this.scale/2)}hitTest(t,e){const s=this.objects;if(1===s.length&&"KritzelLine"===s[0].__class__)return s[0].hitTest(t,e);const r=this.rotatedPolygon;if(i.isPointInPolygon({x:t,y:e},[r.topLeft,r.topRight,r.bottomRight,r.bottomLeft]))return!0;for(const i of s)if(i.hitTest(t,e))return!0;return!1}}class Ln extends Bn{color=n[0];size=4;opacity=1;palette=[...n];arrows;_startX=0;_startY=0;_currentLineId=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&Fn.isLeftClick(t)){this._core.store.state.isDrawing=!0;const i=this._core.store.state.scale,e=this._core.store.state.lockDrawingScale,r=e?i:1,n=(t.clientX-this._core.store.offsetX)/r,h=(t.clientY-this._core.store.offsetY)/r;this._startX=n,this._startY=h;const o=s.create(this._core,{startX:n,startY:h,endX:n,endY:h,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:e?1:i,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});o.isCompleted=!1,this._currentLineId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const i=this._core.store.state.scale,e=this._core.store.state.lockDrawingScale,r=e?i:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/r),h=Math.round((t[0].clientY-this._core.store.offsetY)/r);this._core.store.state.isDrawing=!0,this._startX=n,this._startY=h;const o=s.create(this._core,{startX:n,startY:h,endX:n,endY:h,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:e?1:i,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});o.isCompleted=!1,this._currentLineId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentLineId){const i=this._core.store.objects.findById(this._currentLineId);if(i){const e=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?e:1,h=s.create(this._core,{startX:this._startX,startY:this._startY,endX:(t.clientX-this._core.store.offsetX)/n,endY:(t.clientY-this._core.store.offsetY)/n,translateX:-this._core.store.state.translateX/n,translateY:-this._core.store.state.translateY/n,scale:r?1:e,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});h.id=i.id,h.workspaceId=i.workspaceId,h.zIndex=i.zIndex,h.isCompleted=!1,this._core.store.objects.update(h)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length&&this._currentLineId){const i=this._core.store.objects.findById(this._currentLineId);if(i){const e=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?e:1,h=Math.round((t[0].clientX-this._core.store.offsetX)/n),o=Math.round((t[0].clientY-this._core.store.offsetY)/n),l=s.create(this._core,{startX:this._startX,startY:this._startY,endX:h,endY:o,translateX:-this._core.store.state.translateX/n,translateY:-this._core.store.state.translateY/n,scale:r?1:e,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});l.id=i.id,l.workspaceId=i.workspaceId,l.zIndex=i.zIndex,l.isCompleted=!1,this._core.store.objects.update(l)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentLineId)){const t=this._core.store.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentLineId)){const t=this._core.store.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}}selectLineAndSwitchTool(t){const i=Jn.create(this._core);i.addOrRemove(t),i.isSelected=!0,i.rotation=t.rotation,this._core.addSelectionGroup(i),this._core.store.setState("activeTool",l.getTool("selection")),this._core.rerender()}}class Yn extends Bn{_fontFamily="Arial";_fontSize=16;_fontColor=n[0];_opacity=1;get fontFamily(){return this._fontFamily}set fontFamily(t){this._fontFamily=t,this.applyToActiveText({fontFamily:t})}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize=t,this.applyToActiveText({fontSize:t})}get fontColor(){return this._fontColor}set fontColor(t){this._fontColor=t,this.applyToActiveText({fontColor:t})}get opacity(){return this._opacity}set opacity(t){this._opacity=t,this.applyToActiveText({opacity:t})}palette=[...n];constructor(t){super(t)}applyToActiveText(t){const i=this._core?.store?.activeText;i&&(this._core.updateObject(i,t),this._core.rerender())}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const i=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),e=i?.id?this._core.findObjectById(i.id):null,s=this._core.store.activeText;if(null===s&&e instanceof Dn)return void e.edit(t);if(null!==s&&e instanceof Dn)return s.save(),void e.edit(t);if(null!==s&&e instanceof Dn==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",l.getTool("selection"));if(!1===Fn.isLeftClick(t))return;const r=t.clientX-this._core.store.offsetX,n=t.clientY-this._core.store.offsetY,h=this._core.store.state.scale,o=Dn.create(this._core,this.fontSize,this.fontFamily,this._core.store.state.lockDrawingScale?1:h);o.fontColor=this.fontColor,o.opacity=this.opacity,o.translateX=(r-this._core.store.state.translateX)/h,o.translateY=(n-this._core.store.state.translateY)/h,o.zIndex=this._core.store.currentZIndex,this._core.store.objects.insert(o),this._core.rerender(),o.edit(t)}if("touch"===t.pointerType||"pen"===t.pointerType){const i=Array.from(this._core.store.state.pointers.values()),e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=e?.id?this._core.findObjectById(e.id):null,r=this._core.store.activeText;if(null===r&&s instanceof Dn)return void s.edit(t);if(null!==r&&s instanceof Dn)return r.save(),void s.edit(t);if(null!==r&&s instanceof Dn==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",l.getTool("selection"));if(i.length>1)return;const n=Math.round(i[0].clientX-this._core.store.offsetX),h=Math.round(i[0].clientY-this._core.store.offsetY),o=this._core.store.state.scale,u=Dn.create(this._core,this.fontSize,this.fontFamily,this._core.store.state.lockDrawingScale?1:o);u.fontColor=this.fontColor,u.opacity=this.opacity,u.translateX=(n-this._core.store.state.translateX)/o,u.translateY=(h-this._core.store.state.translateY)/o,u.zIndex=this._core.store.currentZIndex,this._core.store.objects.insert(u),this._core.rerender(),u.edit(t)}}handlePointerUp(t){const i=this._core.store.activeText;i&&i.isMounted&&!i.editor?.hasFocus()&&i.focus({x:t.clientX,y:t.clientY})}}class Xn extends Bn{shapeType=zn.Rectangle;fillColor={light:"transparent",dark:"transparent"};strokeColor=n[0];strokeWidth=4;opacity=1;fontFamily="Arial";fontSize=16;fontColor=n[0];palette=[...n];startX=0;startY=0;isDrawing=!1;currentShape=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const i=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),e=this._core.findObjectById(i?.id),s=this._core.store.activeShape;if(null===s&&e instanceof jn)return void e.edit(t);if(null!==s&&e instanceof jn)return s.save(),void e.edit(t);if(null!==s&&e instanceof jn==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",l.getTool("selection"));if(!1===Fn.isLeftClick(t))return;this.startDrawing(t.clientX,t.clientY)}if("touch"===t.pointerType||"pen"===t.pointerType){const i=Array.from(this._core.store.state.pointers.values()),e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=this._core.findObjectById(e?.id),r=this._core.store.activeShape;if(null===r&&s instanceof jn)return void s.edit(t);if(null!==r&&s instanceof jn)return r.save(),void s.edit(t);if(null!==r&&s instanceof jn==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",l.getTool("selection"));if(i.length>1)return;const n=Math.round(i[0].clientX),h=Math.round(i[0].clientY);this.startDrawing(n,h)}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&("mouse"===t.pointerType&&this.updateShapeSize(t.clientX,t.clientY),"touch"===t.pointerType||"pen"===t.pointerType)){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const i=Math.round(t[0].clientX),e=Math.round(t[0].clientY);this.updateShapeSize(i,e)}}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&this.finishDrawing()}startDrawing(t,i){const e=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?e:1;this.startX=(t-this._core.store.offsetX)/r,this.startY=(i-this._core.store.offsetY)/r,this.isDrawing=!0,this.currentShape=jn.create(this._core,{x:this.startX,y:this.startY,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,width:1,height:1,shapeType:this.shapeType,fillColor:this.fillColor,strokeColor:this.strokeColor,strokeWidth:this.strokeWidth,opacity:this.opacity,fontSize:this.fontSize,fontFamily:this.fontFamily,scale:s?1:e}),this._core.store.objects.insert(this.currentShape),this._core.store.objects?.setActiveDrawingObject(this.currentShape.id),this._core.rerender()}updateShapeSize(t,i){if(!this.currentShape)return;const e=this._core.store.state.lockDrawingScale?this._core.store.state.scale:1,s=(t-this._core.store.offsetX)/e,r=(i-this._core.store.offsetY)/e,n=Math.min(this.startX,s),h=Math.min(this.startY,r),o=Math.abs(s-this.startX),l=Math.abs(r-this.startY);this.currentShape.x=n,this.currentShape.y=h,this.currentShape.width=Math.max(1,o),this.currentShape.height=Math.max(1,l),this.currentShape.translateX=-this._core.store.state.translateX/e,this.currentShape.translateY=-this._core.store.state.translateY/e,this.currentShape.updateDimensions(),this._core.store.objects.update(this.currentShape)}finishDrawing(){if(this.currentShape){if(this.currentShape.width<10&&this.currentShape.height<10){const t=this.currentShape.id;this._core.store.objects.remove((i=>i.id===t))}else this.currentShape.zIndex=this._core.store.currentZIndex,this._core.store.objects.update(this.currentShape),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([this.currentShape]),this._core.selectObjects([this.currentShape]),this._core.store.setState("activeTool",l.getTool("selection"));this.isDrawing=!1,this._core.store.objects?.setActiveDrawingObject(null),this.currentShape=null,this._core.store.objects?.stopUndoCapturing(),this._core.rerender()}}}class Un{_core;constructor(t){this._core=t}}class Hn extends Un{dragStartX=0;dragStartY=0;startX=0;startY=0;endX=0;endY=0;initialDragX=0;initialDragY=0;disconnectedLineIds=new Set;hasMoved=!1;trackedPointerId=null;constructor(t){super(t)}reset(){this.dragStartX=0,this.dragStartY=0,this.startX=0,this.startY=0,this.endX=0,this.endY=0,this.initialDragX=0,this.initialDragY=0,this.disconnectedLineIds.clear(),this.hasMoved=!1,this.trackedPointerId=null}cancelPendingDrag(){this._core.store.state.isDragging=!1,this.reset()}handlePointerDown(t){if("mouse"===t.pointerType)if(Fn.isLeftClick(t)){const i=this._core.store.selectionGroup,e=t.shiftKey||t.ctrlKey;if(!i?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||e)this.trackedPointerId=null;else{const i=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;this._core.store.state.isDragging=!0,this.dragStartX=i,this.dragStartY=e,this.startX=this.dragStartX,this.startY=this.dragStartY,this.initialDragX=i,this.initialDragY=e,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}else this.trackedPointerId=null;if("touch"===t.pointerType||"pen"===t.pointerType){const i=Array.from(this._core.store.state.pointers.values());if(1===this._core.store.state.pointers.size){if(this._core.store.state.isScaling)return void(this.trackedPointerId=null);const e=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(!e?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||s)this.trackedPointerId=null;else{const e=Math.round(i[0].clientX-this._core.store.offsetX),s=Math.round(i[0].clientY-this._core.store.offsetY);this.dragStartX=e,this.dragStartY=s,this.startX=e,this.startY=s,this.initialDragX=e,this.initialDragY=s,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}}}handlePointerMove(t){if(null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId){if("mouse"===t.pointerType){const i=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&i){const e=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this.endX=e,this.endY=s;const r=Math.abs(e-this.startX),n=Math.abs(s-this.startY),h=5;(this.hasMoved||r>h||n>h)&&(this.checkAndDisconnectAnchors(e,s),i.move(e,s,this.dragStartX,this.dragStartY),this.dragStartX=e,this.dragStartY=s,this.hasMoved=!0)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),i=this._core.store.selectionGroup;if(1===this._core.store.state.pointers.size&&i&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected&&!this._core.store.state.isScaling){const e=Math.round(t[0].clientX-this._core.store.offsetX),s=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDragging=!0,this.endX=e,this.endY=s;const r=Math.abs(e-this.startX),n=Math.abs(s-this.startY),h=5;if(this.hasMoved||r>h||n>h){const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t),this.checkAndDisconnectAnchors(e,s),i.move(e,s,this.dragStartX,this.dragStartY),this.dragStartX=e,this.dragStartY=s,this.hasMoved=!0}}}}}handlePointerUp(t){null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId&&("mouse"===t.pointerType&&this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.persistChildren(),this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing())),"touch"!==t.pointerType&&"pen"!==t.pointerType||this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.persistChildren(),this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing())),this.reset())}checkAndDisconnectAnchors(t,i){const e=t-this.initialDragX,r=i-this.initialDragY;if(Math.sqrt(e*e+r*r)<30)return;const n=this._core.store.selectionGroup;if(!n)return;const h=n.objects;if(h.every((t=>t instanceof s)))for(const t of h)if(!this.disconnectedLineIds.has(t.id)&&t instanceof s){const i=t;(i.startAnchor||i.endAnchor)&&(i.startAnchor&&this._core.anchorManager.removeAnchor(i.id,"start"),i.endAnchor&&this._core.anchorManager.removeAnchor(i.id,"end"),this.disconnectedLineIds.add(i.id),this._core.store.objects.update(i))}}}!function(t){t.TopLeft="top-left",t.TopRight="top-right",t.BottomLeft="bottom-left",t.BottomRight="bottom-right"}(_n||(_n={}));class Kn extends Un{initialMouseX=0;initialMouseY=0;initialSize={x:0,y:0,width:0,height:0};newSize={x:0,y:0,width:0,height:0};hasResized=!1;constructor(t){super(t)}reset(){this.initialMouseX=0,this.initialMouseY=0,this.initialSize={x:0,y:0,width:0,height:0},this.newSize={x:0,y:0,width:0,height:0},this.hasResized=!1}handlePointerDown(t){if("mouse"===t.pointerType&&Fn.isLeftClick(t)){const i=this._core.store.selectionGroup;if(i&&this._core.store.state.isResizeHandleSelected){i.beginTransform();const e=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=e,this.initialMouseY=s,this.initialSize.width=i.width,this.initialSize.height=i.height,this.initialSize.x=i.translateX,this.initialSize.y=i.translateY}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),i=t[0];if(!i)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isResizeHandleSelected){t.beginTransform();const e=Math.round(i.clientX-this._core.store.offsetX),s=Math.round(i.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=e,this.initialMouseY=s,this.initialSize.width=t.width,this.initialSize.height=t.height,this.initialSize.x=t.translateX,this.initialSize.y=t.translateY;const r=this._core.store.state.longTouchTimeout;r&&globalThis.clearTimeout?.(r)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const i=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&i){const e=t.clientX-this._core.store.offsetX-this.initialMouseX,s=t.clientY-this._core.store.offsetY-this.initialMouseY,r=Math.abs(e),n=Math.abs(s),h=5;if((r>h||n>h)&&(this.hasResized=!0),!this.hasResized)return;const o=i.rotation,l=Math.sin(o),u=Math.cos(o),f=i.scale||1,a=this._core.store.state.scale,c=(e*u+s*l)/a,d=(-e*l+s*u)/a,p=this.initialSize.x+this.initialSize.width/f/2+e/a/2,m=this.initialSize.y+this.initialSize.height/f/2+s/a/2;switch(this._core.store.state.resizeHandleType){case _n.TopLeft:this.newSize.width=this.initialSize.width-c*f,this.newSize.height=this.initialSize.height-d*f;break;case _n.TopRight:this.newSize.width=this.initialSize.width+c*f,this.newSize.height=this.initialSize.height-d*f;break;case _n.BottomLeft:this.newSize.width=this.initialSize.width-c*f,this.newSize.height=this.initialSize.height+d*f;break;case _n.BottomRight:this.newSize.width=this.initialSize.width+c*f,this.newSize.height=this.initialSize.height+d*f}t.shiftKey&&this.constrainToAspectRatio(),this.newSize.x=p-this.newSize.width/f/2,this.newSize.y=m-this.newSize.height/f/2,i.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;const i=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&i){const e=Math.round(t.clientX-this._core.store.offsetX),s=Math.round(t.clientY-this._core.store.offsetY),r=e-this.initialMouseX,n=s-this.initialMouseY,h=Math.abs(r),o=Math.abs(n),l=5;if(h>l||o>l){const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t),this.hasResized=!0}if(!this.hasResized)return;const u=i.rotation,f=Math.sin(u),a=Math.cos(u),c=i.scale||1,d=this._core.store.state.scale,p=(r*a+n*f)/d,m=(-r*f+n*a)/d,w=this.initialSize.x+this.initialSize.width/c/2+r/d/2,g=this.initialSize.y+this.initialSize.height/c/2+n/d/2;switch(this._core.store.state.resizeHandleType){case _n.TopLeft:this.newSize.width=this.initialSize.width-p*c,this.newSize.height=this.initialSize.height-m*c;break;case _n.TopRight:this.newSize.width=this.initialSize.width+p*c,this.newSize.height=this.initialSize.height-m*c;break;case _n.BottomLeft:this.newSize.width=this.initialSize.width-p*c,this.newSize.height=this.initialSize.height+m*c;break;case _n.BottomRight:this.newSize.width=this.initialSize.width+p*c,this.newSize.height=this.initialSize.height+m*c}this.newSize.x=w-this.newSize.width/c/2,this.newSize.y=g-this.newSize.height/c/2,i.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}}constrainToAspectRatio(){const t=this.initialSize.width,i=this.initialSize.height;if(0===t||0===i)return;const e=t/i,s=this.newSize.height/i;Math.abs(this.newSize.width/t-1)>Math.abs(s-1)?this.newSize.height=this.newSize.width/e:this.newSize.width=this.newSize.height*e}handlePointerUp(t){if("mouse"===t.pointerType&&this._core.store.state.isResizing&&(this._core.store.state.isResizing=!1,this.hasResized&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing()),this.reset()),("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isResizing){this._core.store.state.isResizing=!1,this.hasResized&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing()),this.reset();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}class qn extends Un{initialRotation=0;rotation=0;initialSelectionGroupRotation=0;constructor(t){super(t)}reset(){this.initialRotation=0,this.rotation=0}handlePointerDown(t){if("mouse"===t.pointerType&&Fn.isLeftClick(t)){const i=this._core.store.selectionGroup;if(i&&this._core.store.state.isRotationHandleSelected){i.beginTransform();const e=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=!0;const r=i.scale||1,n=i.translateX+i.width/2/r,h=i.translateY+i.height/2/r,o=(e-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=i.rotation,this.initialRotation=Math.atan2(h-l,n-o)-i.rotation}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),i=t[0];if(!i)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isRotationHandleSelected){t.beginTransform();const e=Math.round(i.clientX-this._core.store.offsetX),s=Math.round(i.clientY-this._core.store.offsetY);this._core.store.state.isRotating=!0;const r=t.scale||1,n=t.translateX+t.width/2/r,h=t.translateY+t.height/2/r,o=(e-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=t.rotation,this.initialRotation=Math.atan2(h-l,n-o)-t.rotation;const u=this._core.store.state.longTouchTimeout;u&&globalThis.clearTimeout?.(u)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const i=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&i){const e=i.scale||1,s=Math.atan2(i.translateY+i.height/2/e-(t.clientY-this._core.store.offsetY-this._core.store.state.translateY)/this._core.store.state.scale,i.translateX+i.width/2/e-(t.clientX-this._core.store.offsetX-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=s-this.initialRotation,i.rotate(this.rotation)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;const i=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&i){const e=Math.round(t.clientX-this._core.store.offsetX),s=Math.round(t.clientY-this._core.store.offsetY),r=i.scale||1,n=Math.atan2(i.translateY+i.height/2/r-(s-this._core.store.state.translateY)/this._core.store.state.scale,i.translateX+i.width/2/r-(e-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=n-this.initialRotation,i.rotate(this.rotation);const h=this._core.store.state.longTouchTimeout;h&&globalThis.clearTimeout?.(h)}}}handlePointerUp(t){if("mouse"===t.pointerType&&this._core.store.state.isRotating&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.isRotating=!1,this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing(),this.reset()),("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isRotating){this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.isRotating=!1,this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing(),this.reset();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}class Gn extends t{__class__="KritzelSelectionBox";static create(t){const i=new Gn;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.id,i.scale=t.store.state.scale,i.zIndex=99999,i.backgroundColor={light:"rgba(0, 122, 255, 0.2)",dark:"rgba(0, 122, 255, 0.2)"},i.borderColor={light:"rgba(0, 122, 255, 0.5)",dark:"rgba(0, 122, 255, 0.5)"},i.borderWidth=2,i.height=0,i.width=0,i}}class Vn extends Un{startX=0;startY=0;touchStartX=0;touchStartY=0;touchStartTimeout=null;_previouslySelectedObjects=new Set;get isSelectionClick(){const t=this._core.store.selectionBox;return t&&0===t.width&&0===t.height}get isSelectionDrag(){const t=this._core.store.selectionBox;return t&&(t.width>0||t.height>0)}constructor(t){super(t)}handlePointerDown(t){if(this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected)return;const i=t.shiftKey||t.ctrlKey;"mouse"===t.pointerType&&(!Fn.isLeftClick(t)||this._core.store.selectionGroup&&!i||this.startMouseSelection(t,i)),"touch"!==t.pointerType&&"pen"!==t.pointerType||(this.touchStartTimeout=setTimeout((()=>{1!==this._core.store.state.pointers.size||this._core.store.state.isScaling||this._core.store.selectionGroup&&!i||(this.startTouchSelection(t,i),this.updateTouchSelection())}),80))}handlePointerMove(t){if("mouse"===t.pointerType&&this._core.store.state.isSelecting&&this.updateMouseSelection(t),"touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),i=Math.round(t[0].clientX-this._core.store.offsetX),e=Math.round(t[0].clientY-this._core.store.offsetY),s=Math.abs(i-this.touchStartX),r=Math.abs(e-this.touchStartY),n=5;if((s>n||r>n)&&this._core.store.state.isSelecting){this.updateTouchSelection();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}handlePointerUp(t){if("mouse"===t.pointerType&&Fn.isLeftClick(t)){const i=this._core.store.state.hasObjectsChanged,e=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(1!==e?.objects.length||!1!==i||s||e.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting){if(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag){const i=t.shiftKey||t.ctrlKey;this.updateMouseSelection(t),this.addSelectedObjectsToSelectionGroup(i),this.removeSelectionBox()}this._core.engine.emitObjectsChange()}}if("touch"===t.pointerType||"pen"===t.pointerType){clearTimeout(this.touchStartTimeout);const i=this._core.store.state.hasObjectsChanged,e=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(1!==e?.objects.length||!1!==i||s||e.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting){if(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag){const i=t.shiftKey||t.ctrlKey;this.updateTouchSelection(),this.addSelectedObjectsToSelectionGroup(i),this.removeSelectionBox()}this._core.engine.emitObjectsChange(),this._core.store.state.skipContextMenu=!1}}}removeSelectionBox(){this._core.store.state.isSelecting=!1,this._core.store.objects.remove((t=>t instanceof Gn)),this._core.store.setSelectionBox(null),this._core.store.objects.clearLocalSelectionBox()}startMouseSelection(t,i=!1){let e,s;e=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;const r=Gn.create(this._core);this.startX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(s-this._core.store.state.translateY)/this._core.store.state.scale,r.translateX=this.startX,r.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.objects.remove((t=>t instanceof Gn||!i&&t instanceof Jn&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),i||this._core.store.setSelectionGroup(null),this._core.store.objects.insert(r),this._core.store.setSelectionBox(r)}startTouchSelection(t,i=!1){const e=Array.from(this._core.store.state.pointers.values())[0];if(!e)return;let s,r;s=Math.round(e.clientX-this._core.store.offsetX),r=Math.round(e.clientY-this._core.store.offsetY),this.touchStartX=s,this.touchStartY=r;const n=Gn.create(this._core);this.startX=(s-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(r-this._core.store.state.translateY)/this._core.store.state.scale,n.translateX=this.startX,n.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.objects.remove((t=>t instanceof Gn||!i&&t instanceof Jn&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),i||this._core.store.setSelectionGroup(null),this._core.store.objects.insert(n),this._core.store.setSelectionBox(n)}updateMouseSelection(t){let i,e;i=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;const s=this._core.store.selectionBox;if(s){const t=(i-this._core.store.state.translateX)/s.scale,r=(e-this._core.store.state.translateY)/s.scale,n=Math.abs(t-this.startX)*s.scale,h=Math.abs(r-this.startY)*s.scale;s.width=n,s.height=h,s.translateX=Math.min(t,this.startX),s.translateY=Math.min(r,this.startY),this._core.store.objects.setLocalSelectionBox({x:s.translateX,y:s.translateY,width:n/s.scale,height:h/s.scale}),n>0||h>0?this.updateSelectedObjects():this.clearSelectionPreview()}}updateTouchSelection(){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;let i,e;i=Math.round(t.clientX-this._core.store.offsetX),e=Math.round(t.clientY-this._core.store.offsetY);const s=this._core.store.selectionBox;if(s){const t=(i-this._core.store.state.translateX)/s.scale,r=(e-this._core.store.state.translateY)/s.scale,n=Math.abs(t-this.startX)*s.scale,h=Math.abs(r-this.startY)*s.scale;s.width=n,s.height=h,s.translateX=Math.min(t,this.startX),s.translateY=Math.min(r,this.startY),this._core.store.objects.setLocalSelectionBox({x:s.translateX,y:s.translateY,width:n/s.scale,height:h/s.scale}),n>0||h>0?this.updateSelectedObjects():this.clearSelectionPreview()}}updateSelectedObjects(){const t=this._core.store.selectionBox;if(!t)return;const i=t.rotatedPolygon,e=[i.topLeft.x,i.topRight.x,i.bottomRight.x,i.bottomLeft.x],s=[i.topLeft.y,i.topRight.y,i.bottomRight.y,i.bottomLeft.y],r=Math.min(...e),n=Math.max(...e),h=Math.min(...s),o=Math.max(...s),l=this._core.store.objects.query({x:r,y:h,z:t.scale,width:n-r,height:o-h}),u=new Set;for(const t of l){if(t instanceof Gn||t instanceof Jn)continue;const e=t.hitTestPolygon(i);t.isSelected=e,e&&u.add(t)}for(const t of this._previouslySelectedObjects)u.has(t)||(t.isSelected=!1);this._previouslySelectedObjects=u}handleSelectionClick(t){const i=this.getTopmostHitObject(t),e=t.shiftKey||t.ctrlKey;this.clearSelectionPreview(),i&&this.addObjectToSelectionGroup(i,e),this.removeSelectionBox()}getTopmostHitObject(t){const i=this._core.store.state.pointerX,e=this._core.store.state.pointerY,s=this._core.getObjectsFromPointerEvent(t,".object");for(const t of s)if(!(t instanceof Gn||t instanceof Jn)&&t.hitTest(i,e))return t;return null}clearSelectionPreview(){for(const t of this._previouslySelectedObjects)t.isSelected=!1;this._previouslySelectedObjects.clear()}addObjectToSelectionGroup(t,i=!1){if(!t)return;const e=In.findParentGroup(this._core,t.id)||t;e.isSelected=!1;const s=this._core.store.selectionGroup;if(i&&s)s.addOrRemove(e),this.removeDescendantsOfSelectedGroups(s),0===s.objects.length?this._core.removeSelectionGroup():this._core.rerender();else{const t=Jn.create(this._core);t.addOrRemove(e),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}addSelectedObjectsToSelectionGroup(t=!1){const i=this._core.store.selectedObjects;if(0===i.length)return;const e=this._core.store.objects.filter((t=>"KritzelGroup"===t.__class__)),s=new Map;for(const t of e)for(const i of t.childIds)s.set(i,t);const r=new Map;for(const t of i){const i=s.get(t.id)||t;r.set(i.id,i),t.isSelected=!1}const n=Array.from(r.values()),h=this.filterDescendantsOfSelectedGroups(n),o=this._core.store.selectionGroup;if(t&&o)o.addObjects(h),this.removeDescendantsOfSelectedGroups(o),this._core.rerender();else{const t=Jn.create(this._core);t.objectIds=h.map((t=>t.id)),1===t.length&&(t.rotation=t.objects[0].rotation),t.captureUnchangedSnapshots(),t.refreshObjectDimensions(),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}filterDescendantsOfSelectedGroups(t){const i=new Set;for(const e of t)e instanceof In&&In.collectDescendantIds(e,i);return 0===i.size?t:t.filter((t=>!i.has(t.id)))}removeDescendantsOfSelectedGroups(t){const i=this.filterDescendantsOfSelectedGroups(t.objects);i.length!==t.objects.length&&(t.objectIds=i.map((t=>t.id)))}}class Zn extends Un{constructor(t){super(t)}handlePointerMove(t){if("mouse"===t.pointerType){const i=this._core.getObjectFromPointerEvent(t,".object");if(!i)return;i.isHovered=i.hitTest(this._core.store.state.pointerX,this._core.store.state.pointerY)}}}class Qn extends Un{initialMouseX=0;initialMouseY=0;initialStartX=0;initialStartY=0;initialEndX=0;initialEndY=0;initialControlX;initialControlY;initialTranslateX=0;initialTranslateY=0;hasMoved=!1;currentSnapTarget=null;constructor(t){super(t)}reset(){this.initialMouseX=0,this.initialMouseY=0,this.initialStartX=0,this.initialStartY=0,this.initialEndX=0,this.initialEndY=0,this.initialControlX=void 0,this.initialControlY=void 0,this.initialTranslateX=0,this.initialTranslateY=0,this.hasMoved=!1,this.currentSnapTarget=null,this._core.anchorManager.clearSnapCandidate()}handlePointerDown(t){"mouse"===t.pointerType&&Fn.isLeftClick(t)&&this.startHandleDrag(t),("touch"===t.pointerType||"pen"===t.pointerType)&&1===Array.from(this._core.store.state.pointers.values()).length&&this.startHandleDrag(t)}startHandleDrag(t){const i=this.getSelectedLine();if(!i||!this._core.store.state.isLineHandleSelected)return;const e=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isLineHandleDragging=!0,this.initialMouseX=e,this.initialMouseY=s,this.initialStartX=i.startX,this.initialStartY=i.startY,this.initialEndX=i.endX,this.initialEndY=i.endY,this.initialControlX=i.controlX,this.initialControlY=i.controlY,this.initialTranslateX=i.translateX,this.initialTranslateY=i.translateY;const r=this._core.store.state.lineHandleType;"start"!==r&&"end"!==r||this._core.anchorManager.removeAnchor(i.id,r);const n=this._core.store.state.longTouchTimeout;n&&globalThis.clearTimeout?.(n)}handlePointerMove(t){const i=this.getSelectedLine();if(!i||!this._core.store.state.isLineHandleDragging)return;const e=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY,n=e-this.initialMouseX,h=s-this.initialMouseY;if((Math.abs(n)>3||Math.abs(h)>3)&&(this.hasMoved=!0),!this.hasMoved)return;const o=this._core.store.state.scale,l=i.scale||1,u=i.rotation,f=n/o,a=h/o,c=Math.cos(-u),d=Math.sin(-u),p=(f*c-a*d)*l,m=(f*d+a*c)*l,w=this._core.store.state.lineHandleType;if("start"===w){const t=(e-this._core.store.state.translateX)/o,n=(s-this._core.store.state.translateY)/o,h=i.endAnchor?.objectId,l=this._core.anchorManager.findSnapTarget(t,n,i.id,h);if(this.currentSnapTarget=l,l){const t=this.worldToLineLocal(i,l.centerX,l.centerY);this.updateLineEndpoint(i,t.x,t.y,this.initialEndX,this.initialEndY);const e=this.lineLocalToWorld(i,this.initialEndX,this.initialEndY),s=this._core.store.allNonSelectionObjects.find((t=>t.id===l.objectId));let n,h,o,u;if(s){const t=this._core.anchorManager.computeAnchorClipInfo(i,"start",s);t&&(n=t.worldX,h=t.worldY,o=t.t)}void 0!==i.controlX&&void 0!==i.controlY&&(u=this.lineLocalToWorld(i,i.controlX,i.controlY)),this._core.anchorManager.setSnapCandidate({objectId:l.objectId,endpoint:"start",centerX:l.centerX,centerY:l.centerY,lineEndpointX:e.x,lineEndpointY:e.y,controlX:u?.x,controlY:u?.y,t:o,edgeX:n,edgeY:h,lineStroke:r.resolveThemeColor(i.stroke),lineStrokeWidth:i.strokeWidth/i.scale,arrowOffset:i.hasStartArrow?i.getArrowSize("start")/i.scale:void 0,arrowStyle:i.hasStartArrow?i.arrows?.start?.style:void 0,arrowFill:i.hasStartArrow?i.getArrowFill("start"):void 0})}else this.updateLineEndpoint(i,this.initialStartX+p,this.initialStartY+m,this.initialEndX,this.initialEndY),this._core.anchorManager.clearSnapCandidate()}else if("end"===w){const t=(e-this._core.store.state.translateX)/o,n=(s-this._core.store.state.translateY)/o,h=i.startAnchor?.objectId,l=this._core.anchorManager.findSnapTarget(t,n,i.id,h);if(this.currentSnapTarget=l,l){const t=this.worldToLineLocal(i,l.centerX,l.centerY);this.updateLineEndpoint(i,this.initialStartX,this.initialStartY,t.x,t.y);const e=this.lineLocalToWorld(i,this.initialStartX,this.initialStartY),s=this._core.store.allNonSelectionObjects.find((t=>t.id===l.objectId));let n,h,o,u;if(s){const t=this._core.anchorManager.computeAnchorClipInfo(i,"end",s);t&&(n=t.worldX,h=t.worldY,o=t.t)}void 0!==i.controlX&&void 0!==i.controlY&&(u=this.lineLocalToWorld(i,i.controlX,i.controlY)),this._core.anchorManager.setSnapCandidate({objectId:l.objectId,endpoint:"end",centerX:l.centerX,centerY:l.centerY,lineEndpointX:e.x,lineEndpointY:e.y,controlX:u?.x,controlY:u?.y,t:o,edgeX:n,edgeY:h,lineStroke:r.resolveThemeColor(i.stroke),lineStrokeWidth:i.strokeWidth/i.scale,arrowOffset:i.hasEndArrow?i.getArrowSize("end")/i.scale:void 0,arrowStyle:i.hasEndArrow?i.arrows?.end?.style:void 0,arrowFill:i.hasEndArrow?i.getArrowFill("end"):void 0})}else this.updateLineEndpoint(i,this.initialStartX,this.initialStartY,this.initialEndX+p,this.initialEndY+m),this._core.anchorManager.clearSnapCandidate()}else if("center"===w){const t=(this.initialControlX??(this.initialStartX+this.initialEndX)/2)+2*p,e=(this.initialControlY??(this.initialStartY+this.initialEndY)/2)+2*m,s=i.startX,r=i.startY,n=i.endX,h=i.endY,o=n-s,l=h-r,u=o*o+l*l;let f,a,c=-1;0!==u&&(c=((t-s)*o+(e-r)*l)/u),c<0?(f=s,a=r):c>1?(f=n,a=h):(f=s+c*o,a=r+c*l);const d=t-f,w=e-a;Math.sqrt(d*d+w*w)<15?i.updateControlPoint(void 0,void 0):i.updateControlPoint(t,e)}this._core.rerender()}worldToLineLocal(t,i,e){const s=(i-t.translateX)*t.scale,r=(e-t.translateY)*t.scale,n=t.totalWidth/2,h=t.totalHeight/2,o=Math.cos(-t.rotation),l=Math.sin(-t.rotation);return{x:(s-n)*o-(r-h)*l+n+t.x,y:(s-n)*l+(r-h)*o+h+t.y}}lineLocalToWorld(t,i,e){const s=i-t.x,r=e-t.y,n=t.totalWidth/2,h=t.totalHeight/2,o=Math.cos(t.rotation),l=Math.sin(t.rotation);return{x:((s-n)*o-(r-h)*l+n)/t.scale+t.translateX,y:((s-n)*l+(r-h)*o+h)/t.scale+t.translateY}}updateLineEndpoint(t,i,e,r,n){const{minX:h,minY:o,maxX:l,maxY:u}=s.calculateBoundingBox(i,e,r,n,t.controlX,t.controlY,t.strokeWidth),f=l-h,a=u-o,{minX:c,minY:d,maxX:p,maxY:m}=s.calculateBoundingBox(this.initialStartX,this.initialStartY,this.initialEndX,this.initialEndY,this.initialControlX,this.initialControlY,t.strokeWidth),w=p-c,g=m-d,y=h-c+(f-w)/2,b=o-d+(a-g)/2,M=t.rotation,v=Math.cos(M),k=Math.sin(M),S=1/t.scale,x=this.initialTranslateX+S*(w-f)/2+S*(y*v-b*k),O=this.initialTranslateY+S*(g-a)/2+S*(y*k+b*v);t.startX=i,t.startY=e,t.endX=r,t.endY=n,t.x=h,t.y=o,t.width=f,t.height=a,t.translateX=x,t.translateY=O,t._adjustedPoints=null,this._core.store.objects.update(t)}handlePointerUp(t){if(this._core.store.state.isLineHandleDragging){const t=this.getSelectedLine(),i=this._core.store.state.lineHandleType;if(t&&this.hasMoved){!this.currentSnapTarget||"start"!==i&&"end"!==i||this._core.anchorManager.setAnchor(t.id,i,this.currentSnapTarget.objectId);const e=this._core.store.selectionGroup;e&&(e.refreshObjectDimensions(),e.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0),this._core.store.objects.stopUndoCapturing()}this._core.store.state.isLineHandleDragging=!1,this.reset(),this._core.rerender()}}getSelectedLine(){const t=this._core.store.selectionGroup;if(!t||1!==t.objects.length)return null;const i=t.objects[0];return i instanceof s?i:null}}class th extends Bn{selectionHandler;moveHandler;hoverHandler;resizeHandler;rotationHandler;lineHandleHandler;palette=[...n];hasSelection(){return!!this._core.store.selectionGroup&&this._core.store.selectionGroup.objects.length>0}getSelectedObjects(){return this._core.store.selectionGroup?.objects??[]}flattenObjects(t){let i=[];for(const e of t)Nn.isInstanceOf(e,"KritzelGroup")?i=i.concat(this.flattenObjects(e.children)):i.push(e);return i}get color(){const t=this.flattenObjects(this.getSelectedObjects());if(0===t.length)return n[0];for(const i of t){if(i instanceof e)return i.fill;if(i instanceof s)return i.stroke;if(i instanceof Dn)return i.fontColor;if(i instanceof jn)return i.strokeColor}return n[0]}set color(t){this.flattenObjects(this.getSelectedObjects()).forEach((i=>{i instanceof e&&this._core.updateObject(i,{fill:t}),i instanceof s&&this._core.updateObject(i,{stroke:t}),i instanceof Dn&&this._core.updateObject(i,{fontColor:t}),i instanceof jn&&this._core.updateObject(i,{strokeColor:t})})),this._core.rerender()}get opacity(){const t=this.flattenObjects(this.getSelectedObjects());return 0===t.length?1:t[0].opacity}set opacity(t){this.flattenObjects(this.getSelectedObjects()).forEach((i=>this._core.updateObject(i,{opacity:t}))),this._core.rerender()}get size(){const t=this.flattenObjects(this.getSelectedObjects());if(0===t.length)return 1;for(const i of t){if(i instanceof e)return i.strokeWidth;if(i instanceof s)return i.strokeWidth;if(i instanceof Dn)return i.fontSize;if(i instanceof jn)return i.strokeWidth}return 1}set size(t){this.flattenObjects(this.getSelectedObjects()).forEach((i=>{i instanceof e&&this._core.updateObject(i,{strokeWidth:t}),i instanceof s&&this._core.updateObject(i,{strokeWidth:t}),i instanceof Dn&&this._core.updateObject(i,{fontSize:t}),i instanceof jn&&this._core.updateObject(i,{strokeWidth:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}get fillColor(){const t=this.flattenObjects(this.getSelectedObjects());for(const i of t)if(i instanceof jn)return i.fillColor;return{light:"transparent",dark:"transparent"}}set fillColor(t){this.flattenObjects(this.getSelectedObjects()).forEach((i=>{if(i instanceof jn){const e=r.determineTextColor(t);this._core.updateObject(i,{fillColor:t,fontColor:e}),("string"==typeof t?"transparent"===t:"transparent"===t.light&&"transparent"===t.dark)||this._core.updateObject(i,{strokeColor:t})}})),this._core.rerender()}get fontFamily(){const t=this.flattenObjects(this.getSelectedObjects());for(const i of t){if(i instanceof Dn)return i.fontFamily;if(i instanceof jn)return i.fontFamily}return"Arial"}set fontFamily(t){this.flattenObjects(this.getSelectedObjects()).forEach((i=>{i instanceof Dn&&this._core.updateObject(i,{fontFamily:t}),i instanceof jn&&this._core.updateObject(i,{fontFamily:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}get arrows(){const t=this.flattenObjects(this.getSelectedObjects());for(const i of t)if(i instanceof s)return i.arrows??{start:{enabled:!1},end:{enabled:!1}};return{start:{enabled:!1},end:{enabled:!1}}}set arrows(t){this.flattenObjects(this.getSelectedObjects()).forEach((i=>{i instanceof s&&this._core.updateObject(i,{arrows:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}getToolConfig(){if(!this.hasSelection())return null;const t=this.flattenObjects(this.getSelectedObjects()),i=[],r=t.some((t=>t instanceof jn)),n=t.some((t=>t instanceof Dn)),h=t.some((t=>t instanceof s)),o=t.some((t=>t instanceof Pn)),l=t.some((t=>t instanceof e||t instanceof s||t instanceof jn));return!o||r||n||h||l?(n&&!l?(i.push({type:"font-size",propertyName:"size"}),i.push({type:"font-family",propertyName:"fontFamily"})):l&&!n?i.push({type:"stroke-size",propertyName:"size"}):(l&&i.push({type:"stroke-size",propertyName:"size"}),n&&i.push({type:"font-family",propertyName:"fontFamily"})),h&&i.push({type:"line-endings",propertyName:"arrows"}),r&&i.push({type:"shape-fill",propertyName:"fillColor"}),{type:"selection",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"palette",controls:i}):{type:"selection",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"none",controls:[]}}refreshSelectionGroupDimensions(){const t=this._core.store.selectionGroup;t&&requestAnimationFrame((()=>{requestAnimationFrame((()=>{t.refreshObjectDimensions(),this._core.rerender()}))}))}constructor(t){super(t),this.selectionHandler=new Vn(this._core),this.moveHandler=new Hn(this._core),this.hoverHandler=new Zn(this._core),this.resizeHandler=new Kn(this._core),this.rotationHandler=new qn(this._core),this.lineHandleHandler=new Qn(this._core)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){if(Fn.isLeftClick(t)){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t),this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t),this._core.store.state.isLineHandleSelected=this.isLineHandleSelected(t),this._core.store.state.resizeHandleType=this.getHandleType(t),this._core.store.state.lineHandleType=this.getLineHandleType(t);const i=this.getSelectedObject(t),e=this._core.store.selectionGroup;if(null!==i&&!(i&&e&&i.id!==e.id)||!e||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||t.shiftKey||t.ctrlKey||(this._core.removeSelectionGroup(),this._core.rerender()),i&&!1===i.isSelected&&1===i?.objects.length&&i.objects[0].isInteractive)return}this.lineHandleHandler.handlePointerDown(t),this.moveHandler.handlePointerDown(t),this.selectionHandler.handlePointerDown(t),this.resizeHandler.handlePointerDown(t),this.rotationHandler.handlePointerDown(t),this._core.rerender()}if("touch"===t.pointerType||"pen"===t.pointerType){if(!0===this._core.store.state.isScaling)return;if(1===this._core.store.state.pointers.size){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t),this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t),this._core.store.state.isLineHandleSelected=this.isLineHandleSelected(t),this._core.store.state.resizeHandleType=this.getHandleType(t),this._core.store.state.lineHandleType=this.getLineHandleType(t);const i=this.getSelectedObject(t),e=this._core.store.selectionGroup,s=i&&e&&i.id!==e.id,r=t.shiftKey||t.ctrlKey;!e&&i&&(this._core.store.state.skipContextMenu=!0),null!==i&&!s||!e||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||r||(this._core.removeSelectionGroup(),this._core.rerender())}this.lineHandleHandler.handlePointerDown(t),this.rotationHandler.handlePointerDown(t),this.resizeHandler.handlePointerDown(t),this.moveHandler.handlePointerDown(t),this.selectionHandler.handlePointerDown(t),this._core.rerender()}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&(this.lineHandleHandler.handlePointerMove(t),this.moveHandler.handlePointerMove(t),this.hoverHandler.handlePointerMove(t),this.selectionHandler.handlePointerMove(t),this.resizeHandler.handlePointerMove(t),this.rotationHandler.handlePointerMove(t),this._core.rerender()),"touch"===t.pointerType||"pen"===t.pointerType){if(!0===this._core.store.state.isScaling)return;this.lineHandleHandler.handlePointerMove(t),this.rotationHandler.handlePointerMove(t),this.resizeHandler.handlePointerMove(t),this.moveHandler.handlePointerMove(t),this.selectionHandler.handlePointerMove(t),this._core.rerender()}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&(this.lineHandleHandler.handlePointerUp(t),this.moveHandler.handlePointerUp(t),this.resizeHandler.handlePointerUp(t),this.rotationHandler.handlePointerUp(t),this.selectionHandler.handlePointerUp(t),this._core.rerender()),"touch"===t.pointerType||"pen"===t.pointerType){if(!0===this._core.store.state.isScaling)return;this.lineHandleHandler.handlePointerUp(t),this.rotationHandler.handlePointerUp(t),this.resizeHandler.handlePointerUp(t),this.moveHandler.handlePointerUp(t),this.selectionHandler.handlePointerUp(t),this._core.rerender()}}getSelectedObject(t){const i=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),e=i?.id?this._core.findObjectById(i.id):null;if(!e)return null;const{x:s,y:r}=this._core.getCanvasPoint(t);if(!e.hitTest(s,r))return null;if(e instanceof Jn)return e;{const t=Jn.create(this._core);return t.translateX=0,t.translateY=0,t.addOrRemove(e),t}}getHandleType(t){const i=this._core.store.state.host?.shadowRoot;if(!i)return;const e=i.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("resize-handle-overlay")));return e?.classList[1]}isHandleSelected(t){const i=this._core.store.state.host?.shadowRoot;return!!i&&i.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("resize-handle-overlay")))}isRotationHandleSelected(t){const i=this._core.store.state.host?.shadowRoot;return!!i&&i.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("rotation-handle-overlay")))}isLineHandleSelected(t){const i=this._core.store.state.host?.shadowRoot;return!!i&&i.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("selection-line-handle-overlay")))}getLineHandleType(t){const i=this._core.store.state.host?.shadowRoot;if(!i)return;const e=i.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("selection-line-handle-overlay")));return e?.classList[1]}}export{$n as A,En as I,Dn as K,zn as S,Pn as a,In as b,jn as c,Wn as d,Ln as e,Yn as f,Xn as g,th as h,Cn as i,Jn as j,Gn as k,u as l,Bn as m,Fn as n,l as o,Nn as p,Un as q}
|