kritzel-stencil 0.2.1 → 0.2.2
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 +80 -39
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stencil.cjs.js +1 -1
- package/dist/cjs/{workspace.migrations-TAWnOE7r.js → workspace.migrations-BPwtowiJ.js} +159 -22
- package/dist/collection/classes/core/core.class.js +27 -19
- package/dist/collection/classes/handlers/selection.handler.js +36 -2
- package/dist/collection/classes/objects/group.class.js +69 -12
- package/dist/collection/classes/tools/text-tool.class.js +44 -8
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +34 -17
- package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js +23 -1
- package/dist/collection/constants/version.js +1 -1
- package/dist/collection/themes/dark-theme.js +5 -0
- package/dist/collection/themes/light-theme.js +5 -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-editor.js +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-menu-item.js +1 -1
- package/dist/components/kritzel-menu.js +1 -1
- package/dist/components/kritzel-more-menu.js +1 -1
- package/dist/components/kritzel-portal.js +1 -1
- package/dist/components/kritzel-settings.js +1 -1
- package/dist/components/kritzel-split-button.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-workspace-manager.js +1 -1
- package/dist/components/{p-CFzvz-B2.js → p-0YBCp8Wh.js} +1 -1
- package/dist/components/{p-DkT0CXfN.js → p-574MVXxi.js} +1 -1
- package/dist/components/p-BCzbwL4m.js +1 -0
- package/dist/components/p-BLjdzUzs.js +1 -0
- package/dist/components/{p-BFQVg_eQ.js → p-BSEdLfq2.js} +1 -1
- package/dist/components/{p-C3Dwuqka.js → p-BWrxz4mM.js} +1 -1
- package/dist/components/{p-ChqeIKg_.js → p-BYOIzv_f.js} +1 -1
- package/dist/components/{p-CekG3_ce.js → p-Bfa-Amjn.js} +1 -1
- package/dist/components/{p-mDz63oKF.js → p-BmcAX-1k.js} +1 -1
- package/dist/components/{p-CzIuqMQA.js → p-BtJB7FsW.js} +1 -1
- package/dist/components/{p-CVQBfO3r.js → p-C6Td7I4k.js} +1 -1
- package/dist/components/{p-ChQNi67Z.js → p-D9ifYAtg.js} +1 -1
- package/dist/components/{p-DoIOS3fS.js → p-DE2xDwUM.js} +1 -1
- package/dist/components/{p-B4wyWc66.js → p-DFeyobdy.js} +2 -2
- package/dist/components/{p--T9W9erA.js → p-DfB7uJ0N.js} +1 -1
- package/dist/components/{p-B2kHVHa_.js → p-u-827ZX7.js} +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/kritzel-active-users_42.entry.js +80 -39
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stencil.js +1 -1
- package/dist/esm/{workspace.migrations-Dta1Yewh.js → workspace.migrations-C_uxbvuH.js} +159 -22
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/{p-22753671.entry.js → p-4d28c496.entry.js} +2 -2
- package/dist/stencil/p-C_uxbvuH.js +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/handlers/selection.handler.d.ts +15 -0
- package/dist/types/classes/objects/group.class.d.ts +15 -0
- package/dist/types/classes/tools/text-tool.class.d.ts +26 -8
- package/dist/types/components/shared/kritzel-portal/kritzel-portal.d.ts +1 -0
- package/dist/types/constants/version.d.ts +1 -1
- package/dist/types/interfaces/theme.interface.d.ts +12 -4
- package/package.json +1 -1
- package/dist/components/p-BYX50YSd.js +0 -1
- package/dist/components/p-CjazGGq3.js +0 -1
- package/dist/stencil/p-Dta1Yewh.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as t,b as e,K as i,a as s}from"./p-B2kHVHa_.js";import{a as r,D as n}from"./p-CjazGGq3.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,e,i){const s=new e(i);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 e=t.getAttribute("content");e?.includes("interactive-widget=resizes-content")||(e+=", interactive-widget=resizes-content"),e&&t.setAttribute("content",e)}}static disableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let e=t.getAttribute("content"),i=e?.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");void 0!==i&&(i=i.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim(),t.setAttribute("content",i))}}static onKeyboardVisibleChanged(t){if("visualViewport"in window){const e=.75,i=i=>{const s=i.target,r=o.isMobile(),n=s.height*s.scale/window.screen.height<e;t(r&&n)};return window.visualViewport?.addEventListener("resize",i),()=>window.visualViewport?.removeEventListener("resize",i)}return console.warn("Listening for keyboard visibility changes is not reliably supported in this browser."),()=>{}}}function f(t){this.content=t}function a(t,e,i){for(let s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:i;let r=t.child(s),n=e.child(s);if(r!=n){if(!r.sameMarkup(n))return i;if(r.isText&&r.text!=n.text){for(let t=0;r.text[t]==n.text[t];t++)i++;return i}if(r.content.size||n.content.size){let t=a(r.content,n.content,i+1);if(null!=t)return t}i+=r.nodeSize}else i+=r.nodeSize}}function c(t,e,i,s){for(let r=t.childCount,n=e.childCount;;){if(0==r||0==n)return r==n?null:{a:i,b:s};let h=t.child(--r),o=e.child(--n),l=h.nodeSize;if(h!=o){if(!h.sameMarkup(o))return{a:i,b:s};if(h.isText&&h.text!=o.text){let t=0,e=Math.min(h.text.length,o.text.length);for(;t<e&&h.text[h.text.length-t-1]==o.text[o.text.length-t-1];)t++,i--,s--;return{a:i,b:s}}if(h.content.size||o.content.size){let t=c(h.content,o.content,i-1,s-1);if(t)return t}i-=l,s-=l}else i-=l,s-=l}}f.prototype={constructor:f,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return-1==e?void 0:this.content[e+1]},update:function(t,e,i){var s=i&&i!=t?this.remove(i):this,r=s.find(t),n=s.content.slice();return-1==r?n.push(i||t,e):(n[r+1]=e,i&&(n[r]=i)),new f(n)},remove:function(t){var e=this.find(t);if(-1==e)return this;var i=this.content.slice();return i.splice(e,2),new f(i)},addToStart:function(t,e){return new f([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var i=this.remove(t).content.slice();return i.push(t,e),new f(i)},addBefore:function(t,e,i){var s=this.remove(e),r=s.content.slice(),n=s.find(t);return r.splice(-1==n?r.length:n,0,e,i),new f(r)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+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 e=this;t=f.from(t);for(var i=0;i<t.content.length;i+=2)e=e.remove(t.content[i]);return e},toObject:function(){var t={};return this.forEach((function(e,i){t[e]=i})),t},get size(){return this.content.length>>1}},f.from=function(t){if(t instanceof f)return t;var e=[];if(t)for(var i in t)e.push(i,t[i]);return new f(e)};class d{constructor(t,e){if(this.content=t,this.size=e||0,null==e)for(let e=0;e<t.length;e++)this.size+=t[e].nodeSize}nodesBetween(t,e,i,s=0,r){for(let n=0,h=0;h<e;n++){let o=this.content[n],l=h+o.nodeSize;if(l>t&&!1!==i(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,e-r),i,s+r)}h=l}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,i,s){let r="",n=!0;return this.nodesBetween(t,e,((h,o)=>{let l=h.isText?h.text.slice(Math.max(t,o)-o,e-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)&&i&&(n?n=!1:r+=i),r+=l}),0),r}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,i=t.firstChild,s=this.content.slice(),r=0;for(e.isText&&e.sameMarkup(i)&&(s[s.length-1]=e.withText(e.text+i.text),r=1);r<t.content.length;r++)s.push(t.content[r]);return new d(s,this.size+t.size)}cut(t,e=this.size){if(0==t&&e==this.size)return this;let i=[],s=0;if(e>t)for(let r=0,n=0;n<e;r++){let h=this.content[r],o=n+h.nodeSize;o>t&&((n<t||o>e)&&(h=h.isText?h.cut(Math.max(0,t-n),Math.min(h.text.length,e-n)):h.cut(Math.max(0,t-n-1),Math.min(h.content.size,e-n-1))),i.push(h),s+=h.nodeSize),n=o}return new d(i,s)}cutByIndex(t,e){return t==e?d.empty:0==t&&e==this.content.length?this:new d(this.content.slice(t,e))}replaceChild(t,e){let i=this.content[t];if(i==e)return this;let s=this.content.slice(),r=this.size+e.nodeSize-i.nodeSize;return s[t]=e,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 e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))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 e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,i=0;e<this.content.length;e++){let s=this.content[e];t(s,i,e),i+=s.nodeSize}}findDiffStart(t,e=0){return a(this,t,e)}findDiffEnd(t,e=this.size,i=t.size){return c(this,t,e,i)}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 e=0,i=0;;e++){let s=i+this.child(e).nodeSize;if(s>=t)return s==t?m(e+1,s):m(e,i);i=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,e){if(!e)return d.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new d(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return d.empty;let e,i=0;for(let s=0;s<t.length;s++){let r=t[s];i+=r.nodeSize,s&&r.isText&&t[s-1].sameMarkup(r)?(e||(e=t.slice(0,s)),e[e.length-1]=r.withText(e[e.length-1].text+r.text)):e&&e.push(r)}return new d(e||t,i)}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,e){return p.index=t,p.offset=e,p}function w(t,e){if(t===e)return!0;if(!t||"object"!=typeof t||!e||"object"!=typeof e)return!1;let i=Array.isArray(t);if(Array.isArray(e)!=i)return!1;if(i){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!w(t[i],e[i]))return!1}else{for(let i in t)if(!(i in e)||!w(t[i],e[i]))return!1;for(let i in e)if(!(i in t))return!1}return!0}class g{constructor(t,e){this.type=t,this.attrs=e}addToSet(t){let e,i=!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))e||(e=t.slice(0,s));else{if(r.type.excludes(this.type))return t;!i&&r.type.rank>this.type.rank&&(e||(e=t.slice(0,s)),e.push(this),i=!0),e&&e.push(r)}}return e||(e=t.slice()),i||e.push(this),e}removeFromSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return t.slice(0,e).concat(t.slice(e+1));return t}isInSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))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 e in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Mark.fromJSON");let i=t.marks[e.type];if(!i)throw new RangeError(`There is no mark type ${e.type} in this schema`);let s=i.create(e.attrs);return i.checkAttrs(s.attrs),s}static sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].eq(e[i]))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 e=t.slice();return e.sort(((t,e)=>t.type.rank-e.type.rank)),e}}g.none=[];class y extends Error{}class b{constructor(t,e,i){this.content=t,this.openStart=e,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let i=v(this.content,t+this.openStart,e);return i&&new b(i,this.openStart,this.openEnd)}removeBetween(t,e){return new b(M(this.content,t+this.openStart,e+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,e){if(!e)return b.empty;let i=e.openStart||0,s=e.openEnd||0;if("number"!=typeof i||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new b(d.fromJSON(t,e.content),i,s)}static maxOpen(t,e=!0){let i=0,s=0;for(let s=t.firstChild;s&&!s.isLeaf&&(e||!s.type.spec.isolating);s=s.firstChild)i++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)s++;return new b(t,i,s)}}function M(t,e,i){let{index:s,offset:r}=t.findIndex(e),n=t.maybeChild(s),{index:h,offset:o}=t.findIndex(i);if(r==e||n.isText){if(o!=i&&!t.child(h).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(i))}if(s!=h)throw new RangeError("Removing non-flat range");return t.replaceChild(s,n.copy(M(n.content,e-r-1,i-r-1)))}function v(t,e,i,s){let{index:r,offset:n}=t.findIndex(e),h=t.maybeChild(r);if(n==e||h.isText)return s&&!s.canReplace(r,r,i)?null:t.cut(0,e).append(i).append(t.cut(e));let o=v(h.content,e-n-1,i,h);return o&&t.replaceChild(r,h.copy(o))}function k(t,e,i){if(i.openStart>t.depth)throw new y("Inserted content deeper than insertion position");if(t.depth-i.openStart!=e.depth-i.openEnd)throw new y("Inconsistent open depths");return S(t,e,i,0)}function S(t,e,i,s){let r=t.index(s),n=t.node(s);if(r==e.index(s)&&s<t.depth-i.openStart){let h=S(t,e,i,s+1);return n.copy(n.content.replaceChild(r,h))}if(i.content.size){if(i.openStart||i.openEnd||t.depth!=s||e.depth!=s){let{start:r,end:h}=function(t,e){let i=e.depth-t.openStart,s=e.node(i).copy(t.content);for(let t=i-1;t>=0;t--)s=e.node(t).copy(d.from(s));return{start:s.resolveNoCache(t.openStart+i),end:s.resolveNoCache(s.content.size-t.openEnd-i)}}(i,t);return A(n,R(t,r,h,e,s))}{let s=t.parent,r=s.content;return A(s,r.cut(0,t.parentOffset).append(i.content).append(r.cut(e.parentOffset)))}}return A(n,E(t,e,s))}function x(t,e){if(!e.type.compatibleContent(t.type))throw new y("Cannot join "+e.type.name+" onto "+t.type.name)}function O(t,e,i){let s=t.node(i);return x(s,e.node(i)),s}function T(t,e){let i=e.length-1;i>=0&&t.isText&&t.sameMarkup(e[i])?e[i]=t.withText(e[i].text+t.text):e.push(t)}function D(t,e,i,s){let r=(e||t).node(i),n=0,h=e?e.index(i):r.childCount;t&&(n=t.index(i),t.depth>i?n++:t.textOffset&&(T(t.nodeAfter,s),n++));for(let t=n;t<h;t++)T(r.child(t),s);e&&e.depth==i&&e.textOffset&&T(e.nodeBefore,s)}function A(t,e){return t.type.checkContent(e),t.copy(e)}function R(t,e,i,s,r){let n=t.depth>r&&O(t,e,r+1),h=s.depth>r&&O(i,s,r+1),o=[];return D(null,t,r,o),n&&h&&e.index(r)==i.index(r)?(x(n,h),T(A(n,R(t,e,i,s,r+1)),o)):(n&&T(A(n,E(t,e,r+1)),o),D(e,i,r,o),h&&T(A(h,E(i,s,r+1)),o)),D(s,null,r,o),new d(o)}function E(t,e,i){let s=[];return D(null,t,i,s),t.depth>i&&T(A(O(t,e,i+1),E(t,e,i+1)),s),D(e,null,i,s),new d(s)}b.empty=new b(d.empty,0,0);class ${constructor(t,e,i){this.pos=t,this.path=e,this.parentOffset=i,this.depth=e.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,e=this.index(this.depth);if(e==t.childCount)return null;let i=this.pos-this.path[this.path.length-1],s=t.child(e);return i?t.child(e).cut(i):s}get nodeBefore(){let t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):0==t?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let i=this.path[3*e],s=0==e?0:this.path[3*e-1]+1;for(let e=0;e<t;e++)s+=i.child(e).nodeSize;return s}marks(){let t=this.parent,e=this.index();if(0==t.content.size)return g.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),s=t.maybeChild(e);if(!i){let t=i;i=s,s=t}let r=i.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 e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let i=e.marks,s=t.parent.maybeChild(t.index());for(var r=0;r<i.length;r++)!1!==i[r].type.spec.inclusive||s&&i[r].isInSet(s.marks)||(i=i[r--].removeFromSet(i));return i}sharedDepth(t){for(let e=this.depth;e>0;e--)if(this.start(e)<=t&&this.end(e)>=t)return e;return 0}blockRange(t=this,e){if(t.pos<this.pos)return t.blockRange(this);for(let i=this.depth-(this.parent.inlineContent||this.pos==t.pos?1:0);i>=0;i--)if(t.pos<=this.end(i)&&(!e||e(this.node(i))))return new I(this,t,i);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 e=1;e<=this.depth;e++)t+=(t?"/":"")+this.node(e).type.name+"_"+this.index(e-1);return t+":"+this.parentOffset}static resolve(t,e){if(!(e>=0&&e<=t.content.size))throw new RangeError("Position "+e+" out of range");let i=[],s=0,r=e;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(r),h=r-n;if(i.push(e,t,s+n),!h)break;if(e=e.child(t),e.isText)break;r=h-1,s+=n+1}return new $(e,i,r)}static resolveCached(t,e){let i=N.get(t);if(i)for(let t=0;t<i.elts.length;t++){let s=i.elts[t];if(s.pos==e)return s}else N.set(t,i=new P);let s=i.elts[i.i]=$.resolve(t,e);return i.i=(i.i+1)%C,s}}class P{constructor(){this.elts=[],this.i=0}}const C=12,N=new WeakMap;class I{constructor(t,e,i){this.$from=t,this.$to=e,this.depth=i}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 j{constructor(t,e,i,s=g.none){this.type=t,this.attrs=e,this.marks=s,this.content=i||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,e,i,s=0){this.content.nodesBetween(t,e,i,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,e,i,s){return this.content.textBetween(t,e,i,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,e,i){return this.type==t&&w(this.attrs,e||t.defaultAttrs||z)&&g.sameSet(this.marks,i||g.none)}copy(t=null){return t==this.content?this:new j(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new j(this.type,this.attrs,this.content,t)}cut(t,e=this.content.size){return 0==t&&e==this.content.size?this:this.copy(this.content.cut(t,e))}slice(t,e=this.content.size,i=!1){if(t==e)return b.empty;let s=this.resolve(t),r=this.resolve(e),n=i?0:s.sharedDepth(e),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,e,i){return k(this.resolve(t),this.resolve(e),i)}nodeAt(t){for(let e=this;;){let{index:i,offset:s}=e.content.findIndex(t);if(e=e.maybeChild(i),!e)return null;if(s==t||e.isText)return e;t-=s+1}}childAfter(t){let{index:e,offset:i}=this.content.findIndex(t);return{node:this.content.maybeChild(e),index:e,offset:i}}childBefore(t){if(0==t)return{node:null,index:0,offset:0};let{index:e,offset:i}=this.content.findIndex(t);if(i<t)return{node:this.content.child(e),index:e,offset:i};let s=this.content.child(e-1);return{node:s,index:e-1,offset:i-s.nodeSize}}resolve(t){return $.resolveCached(this,t)}resolveNoCache(t){return $.resolve(this,t)}rangeHasMark(t,e,i){let s=!1;return e>t&&this.nodesBetween(t,e,(t=>(i.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 e=this.type.contentMatch.matchFragment(this.content,0,t);if(!e)throw new Error("Called contentMatchAt on a node with invalid content");return e}canReplace(t,e,i=d.empty,s=0,r=i.childCount){let n=this.contentMatchAt(t).matchFragment(i,s,r),h=n&&n.matchFragment(this.content,e);if(!h||!h.validEnd)return!1;for(let t=s;t<r;t++)if(!this.type.allowsMarks(i.child(t).marks))return!1;return!0}canReplaceWith(t,e,i,s){if(s&&!this.type.allowsMarks(s))return!1;let r=this.contentMatchAt(t).matchType(i),n=r&&r.matchFragment(this.content,e);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 e=0;e<this.marks.length;e++){let i=this.marks[e];i.type.checkAttrs(i.attrs),t=i.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 e 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,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");let i;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=e.marks.map(t.markFromJSON)}if("text"==e.type){if("string"!=typeof e.text)throw new RangeError("Invalid text node in JSON");return t.text(e.text,i)}let s=d.fromJSON(t,e.content),r=t.nodeType(e.type).create(e.attrs,s,i);return r.type.checkAttrs(r.attrs),r}}j.prototype.text=void 0;class _ extends j{constructor(t,e,i,s){if(super(t,e,null,s),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}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,e){return this.text.slice(t,e)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new _(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new _(this.type,this.attrs,t,this.marks)}cut(t=0,e=this.text.length){return 0==t&&e==this.text.length?this:this.withText(this.text.slice(t,e))}eq(t){return this.sameMarkup(t)&&this.text==t.text}toJSON(){let t=super.toJSON();return t.text=this.text,t}}function F(t,e){for(let i=t.length-1;i>=0;i--)e=t[i].type.name+"("+e+")";return e}class B{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,e){let i=new W(t,e);if(null==i.next)return B.empty;let s=J(i);i.next&&i.err("Unexpected trailing text");let r=function(t){let e=Object.create(null);return function i(s){let r=[];s.forEach((e=>{t[e].forEach((({term:e,to:i})=>{if(!e)return;let s;for(let t=0;t<r.length;t++)r[t][0]==e&&(s=r[t][1]);K(t,i).forEach((t=>{s||r.push([e,s=[]]),-1==s.indexOf(t)&&s.push(t)}))}))}));let n=e[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:e[s.join(",")]||i(s)})}return n}(K(t,0))}(function(t){let e=[[]];return r(function t(e,n){if("choice"==e.type)return e.exprs.reduce(((e,i)=>e.concat(t(i,n))),[]);if("seq"!=e.type){if("star"==e.type){let h=i();return s(n,h),r(t(e.expr,h),h),[s(h)]}if("plus"==e.type){let h=i();return r(t(e.expr,n),h),r(t(e.expr,h),h),[s(h)]}if("opt"==e.type)return[s(n)].concat(t(e.expr,n));if("range"==e.type){let h=n;for(let s=0;s<e.min;s++){let s=i();r(t(e.expr,h),s),h=s}if(-1==e.max)r(t(e.expr,h),h);else for(let n=e.min;n<e.max;n++){let n=i();s(h,n),r(t(e.expr,h),n),h=n}return[s(h)]}if("name"==e.type)return[s(n,void 0,e.value)];throw new Error("Unknown expr type")}for(let s=0;;s++){let h=t(e.exprs[s],n);if(s==e.exprs.length-1)return h;r(h,n=i())}}(t,0),i()),e;function i(){return e.push([])-1}function s(t,i,s){let r={term:s,to:i};return e[t].push(r),r}function r(t,e){t.forEach((t=>t.to=e))}}(s));return function(t,e){for(let i=0,s=[t];i<s.length;i++){let t=s[i],r=!t.validEnd,n=[];for(let e=0;e<t.next.length;e++){let{type:i,next:h}=t.next[e];n.push(i.name),!r||i.isText||i.hasRequiredAttrs()||(r=!1),-1==s.indexOf(h)&&s.push(h)}r&&e.err("Only non-generatable nodes ("+n.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,i),r}matchType(t){for(let e=0;e<this.next.length;e++)if(this.next[e].type==t)return this.next[e].next;return null}matchFragment(t,e=0,i=t.childCount){let s=this;for(let r=e;s&&r<i;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:e}=this.next[t];if(!e.isText&&!e.hasRequiredAttrs())return e}return null}compatible(t){for(let e=0;e<this.next.length;e++)for(let i=0;i<t.next.length;i++)if(this.next[e].type==t.next[i].type)return!0;return!1}fillBefore(t,e=!1,i=0){let s=[this];return function r(n,h){let o=n.matchFragment(t,i);if(o&&(!e||o.validEnd))return d.from(h.map((t=>t.createAndFill())));for(let t=0;t<n.next.length;t++){let{type:e,next:i}=n.next[t];if(!e.isText&&!e.hasRequiredAttrs()&&-1==s.indexOf(i)){s.push(i);let t=r(i,h.concat(e));if(t)return t}}return null}(this,[])}findWrapping(t){for(let e=0;e<this.wrapCache.length;e+=2)if(this.wrapCache[e]==t)return this.wrapCache[e+1];let e=this.computeWrapping(t);return this.wrapCache.push(t,e),e}computeWrapping(t){let e=Object.create(null),i=[{match:this,type:null,via:null}];for(;i.length;){let s=i.shift(),r=s.match;if(r.matchType(t)){let t=[];for(let e=s;e.type;e=e.via)t.push(e.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 e||s.type&&!h.validEnd||(i.push({match:n.contentMatch,type:n,via:s}),e[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 e(i){t.push(i);for(let s=0;s<i.next.length;s++)-1==t.indexOf(i.next[s].next)&&e(i.next[s].next)}(this),t.map(((e,i)=>{let s=i+(e.validEnd?"*":" ")+" ";for(let i=0;i<e.next.length;i++)s+=(i?", ":"")+e.next[i].type.name+"->"+t.indexOf(e.next[i].next);return s})).join("\n")}}B.empty=new B(!0);class W{constructor(t,e){this.string=t,this.nodeTypes=e,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 e=[];do{e.push(L(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function L(t){let e=[];do{e.push(Y(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==e.length?e[0]:{type:"seq",exprs:e}}function Y(t){let e=function(t){if(t.eat("(")){let e=J(t);return t.eat(")")||t.err("Missing closing paren"),e}if(!/\W/.test(t.next)){let e=function(t,e){let i=t.nodeTypes,s=i[e];if(s)return[s];let r=[];for(let t in i){let s=i[t];s.isInGroup(e)&&r.push(s)}return 0==r.length&&t.err("No node type or group '"+e+"' found"),r}(t,t.next).map((e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e})));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}t.err("Unexpected token '"+t.next+"'")}(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else{if(!t.eat("{"))break;e=U(t,e)}return e}function X(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function U(t,e){let i=X(t),s=i;return t.eat(",")&&(s="}"!=t.next?X(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:i,max:s,expr:e}}function H(t,e){return e-t}function K(t,e){let i=[];return function e(s){let r=t[s];if(1==r.length&&!r[0].term)return e(r[0].to);i.push(s);for(let t=0;t<r.length;t++){let{term:s,to:n}=r[t];s||-1!=i.indexOf(n)||e(n)}}(e),i.sort(H)}function q(t){let e=Object.create(null);for(let i in t){let s=t[i];if(!s.hasDefault)return null;e[i]=s.default}return e}function G(t,e){let i=Object.create(null);for(let s in t){let r=e&&e[s];if(void 0===r){let e=t[s];if(!e.hasDefault)throw new RangeError("No value supplied for attribute "+s);r=e.default}i[s]=r}return i}function V(t,e,i){for(let s in e)if(!(s in t))throw new RangeError(`Unsupported attribute ${s} for ${i} of type ${s}`);for(let i in t){let s=t[i];s.validate&&s.validate(e[i])}}function Z(t,e){let i=Object.create(null);if(e)for(let s in e)i[s]=new tt(t,s,e[s]);return i}let Q=class t{constructor(t,e,i){this.name=t,this.schema=e,this.spec=i,this.markSet=null,this.groups=i.group?i.group.split(" "):[],this.attrs=Z(t,i.attrs),this.defaultAttrs=q(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(i.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,e,i){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new j(this,this.computeAttrs(t),d.from(e),g.setFrom(i))}createChecked(t=null,e,i){return e=d.from(e),this.checkContent(e),new j(this,this.computeAttrs(t),e,g.setFrom(i))}createAndFill(t=null,e,i){if(t=this.computeAttrs(t),(e=d.from(e)).size){let t=this.contentMatch.fillBefore(e);if(!t)return null;e=t.append(e)}let s=this.contentMatch.matchFragment(e),r=s&&s.fillBefore(d.empty,!0);return r?new j(this,t,e.append(r),g.setFrom(i)):null}validContent(t){let e=this.contentMatch.matchFragment(t);if(!e||!e.validEnd)return!1;for(let e=0;e<t.childCount;e++)if(!this.allowsMarks(t.child(e).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 e=0;e<t.length;e++)if(!this.allowsMarkType(t[e].type))return!1;return!0}allowedMarks(t){if(null==this.markSet)return t;let e;for(let i=0;i<t.length;i++)this.allowsMarkType(t[i].type)?e&&e.push(t[i]):e||(e=t.slice(0,i));return e?e.length?e:g.none:t}static compile(e,i){let s=Object.create(null);e.forEach(((e,r)=>s[e]=new t(e,i,r)));let r=i.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,e,i){this.hasDefault=Object.prototype.hasOwnProperty.call(i,"default"),this.default=i.default,this.validate="string"==typeof i.validate?function(t,e,i){let s=i.split("|");return i=>{let r=null===i?"null":typeof i;if(s.indexOf(r)<0)throw new RangeError(`Expected value of type ${s} for attribute ${e} on type ${t}, got ${r}`)}}(t,e,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class et{constructor(t,e,i,s){this.name=t,this.rank=e,this.schema=i,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,e){let i=Object.create(null),s=0;return t.forEach(((t,r)=>i[t]=new et(t,s++,e,r))),i}removeFromSet(t){for(var e=0;e<t.length;e++)t[e].type==this&&(t=t.slice(0,e).concat(t.slice(e+1)),e--);return t}isInSet(t){for(let e=0;e<t.length;e++)if(t[e].type==this)return t[e]}checkAttrs(t){V(this.attrs,t,"mark")}excludes(t){return this.excluded.indexOf(t)>-1}}class it{constructor(t){this.linebreakReplacement=null,this.cached=Object.create(null);let e=this.spec={};for(let i in t)e[i]=t[i];e.nodes=f.from(t.nodes),e.marks=f.from(t.marks||{}),this.nodes=Q.compile(this.spec.nodes,this),this.marks=et.compile(this.spec.marks,this);let i=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 e=this.nodes[t],s=e.spec.content||"",r=e.spec.marks;if(e.contentMatch=i[s]||(i[s]=B.parse(s,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet="_"==r?null:r?st(this,r.split(" ")):""!=r&&e.inlineContent?null:[]}for(let t in this.marks){let e=this.marks[t],i=e.spec.excludes;e.excluded=null==i?[e]:""==i?[]:st(this,i.split(" "))}this.nodeFromJSON=t=>j.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,e=null,i,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(e,i,s)}text(t,e){let i=this.nodes.text;return new _(i,i.defaultAttrs,t,g.setFrom(e))}mark(t,e){return"string"==typeof t&&(t=this.marks[t]),t.create(e)}nodeType(t){let e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e}}function st(t,e){let i=[];for(let s=0;s<e.length;s++){let r=e[s],n=t.marks[r],h=n;if(n)i.push(n);else for(let e in t.marks){let s=t.marks[e];("_"==r||s.spec.group&&s.spec.group.split(" ").indexOf(r)>-1)&&i.push(h=s)}if(!h)throw new SyntaxError("Unknown mark type: '"+e[s]+"'")}return i}class rt{constructor(t,e){this.schema=t,this.rules=e,this.tags=[],this.styles=[];let i=this.matchedStyles=[];e.forEach((t=>{if(function(t){return null!=t.tag}(t))this.tags.push(t);else if(function(t){return null!=t.style}(t)){let e=/[^=]*/.exec(t.style)[0];i.indexOf(e)<0&&i.push(e),this.styles.push(t)}})),this.normalizeLists=!this.tags.some((e=>{if(!/^(ul|ol)\b/.test(e.tag)||!e.node)return!1;let i=t.nodes[e.node];return i.contentMatch.matchType(i)}))}parse(t,e={}){let i=new ft(this,e,!1);return i.addAll(t,g.none,e.from,e.to),i.finish()}parseSlice(t,e={}){let i=new ft(this,e,!0);return i.addAll(t,g.none,e.from,e.to),b.maxOpen(i.finish())}matchTag(t,e,i){for(let s=i?this.tags.indexOf(i)+1:0;s<this.tags.length;s++){let i=this.tags[s];if(at(t,i.tag)&&(void 0===i.namespace||t.namespaceURI==i.namespace)&&(!i.context||e.matchesContext(i.context))){if(i.getAttrs){let e=i.getAttrs(t);if(!1===e)continue;i.attrs=e||void 0}return i}}}matchStyle(t,e,i,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&&!i.matchesContext(s.context)||n.length>t.length&&(61!=n.charCodeAt(t.length)||n.slice(t.length+1)!=e))){if(s.getAttrs){let t=s.getAttrs(e);if(!1===t)continue;s.attrs=t||void 0}return s}}}static schemaRules(t){let e=[];function i(t){let i=null==t.priority?50:t.priority,s=0;for(;s<e.length;s++){let t=e[s];if((null==t.priority?50:t.priority)<i)break}e.splice(s,0,t)}for(let e in t.marks){let s=t.marks[e].spec.parseDOM;s&&s.forEach((t=>{i(t=ct(t)),t.mark||t.ignore||t.clearMark||(t.mark=e)}))}for(let e in t.nodes){let s=t.nodes[e].spec.parseDOM;s&&s.forEach((t=>{i(t=ct(t)),t.node||t.ignore||t.mark||(t.node=e)}))}return e}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,e,i){return null!=e?(e?1:0)|("full"===e?2:0):t&&"pre"==t.whitespace?3:-5&i}class ut{constructor(t,e,i,s,r,n){this.type=t,this.attrs=e,this.marks=i,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 e=this.type.contentMatch.fillBefore(d.from(t));if(!e){let e,i=this.type.contentMatch;return(e=i.findWrapping(t.type))?(this.match=i,e):null}this.match=this.type.contentMatch.matchFragment(e)}return this.match.findWrapping(t.type)}finish(t){if(!(1&this.options)){let t,e=this.content[this.content.length-1];if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let i=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-t[0].length))}}let e=d.from(this.content);return!t&&this.match&&(e=e.append(this.match.fillBefore(d.empty,!0))),this.type?this.type.create(this.attrs,e,this.marks):e}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,e,i){this.parser=t,this.options=e,this.isOpen=i,this.open=0,this.localPreserveWS=!1;let s,r=e.topNode,n=lt(null,e.preserveWhitespace,0)|(i?4:0);s=r?new ut(r.type,r.attrs,g.none,!0,e.topMatch||r.type.contentMatch,n):new ut(i?null:t.schema.topNodeType,null,g.none,!0,null,n),this.nodes=[s],this.find=e.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t,e){3==t.nodeType?this.addTextNode(t,e):1==t.nodeType&&this.addElement(t,e)}addTextNode(t,e){let i=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(i)){if(r)if("full"===r)i=i.replace(/\r\n?/g,"\n");else if(n.linebreakReplacement&&/[\r\n]/.test(i)&&this.top.findWrapping(n.linebreakReplacement.create())){let t=i.split(/\r?\n|\r/);for(let i=0;i<t.length;i++)i&&this.insertNode(n.linebreakReplacement.create(),e,!0),t[i]&&this.insertNode(n.text(t[i]),e,!/\S/.test(t[i]));i=""}else i=i.replace(/\r?\n|\r/g," ");else if(i=i.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(i)&&this.open==this.nodes.length-1){let e=s.content[s.content.length-1],r=t.previousSibling;(!e||r&&"BR"==r.nodeName||e.isText&&/[ \t\r\n\u000c]$/.test(e.text))&&(i=i.slice(1))}i&&this.insertNode(n.text(i),e,!/\S/.test(i)),this.findInText(t)}else this.findInside(t)}addElement(t,e,i){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 e=t.firstChild,i=null;e;e=e.nextSibling){let t=1==e.nodeType?e.nodeName.toLowerCase():null;t&&ot.hasOwnProperty(t)&&i?(i.appendChild(e),e=i):"li"==t?i=e:t&&(i=null)}}(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(n=this.parser.matchTag(t,this,i));t:if(o?o.ignore:ht.hasOwnProperty(h))this.findInside(t),this.ignoreFallback(t,e);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 i,s=this.needsBlock;if(nt.hasOwnProperty(h))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),i=!0,r.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t,e);break t}let n=o&&o.skip?e:this.readStyles(t,e);n&&this.addAll(t,n),i&&this.sync(r),this.needsBlock=s}else{let i=this.readStyles(t,e);i&&this.addElementByRule(t,o,i,!1===o.consuming?n:void 0)}this.localPreserveWS=s}leafFallback(t,e){"BR"==t.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode("\n"),e)}ignoreFallback(t,e){"BR"!=t.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),e,!0)}readStyles(t,e){let i=t.style;if(i&&i.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let s=this.parser.matchedStyles[t],r=i.getPropertyValue(s);if(r)for(let t;;){let i=this.parser.matchStyle(s,r,this,t);if(!i)break;if(i.ignore)return null;if(e=i.clearMark?e.filter((t=>!i.clearMark(t))):e.concat(this.parser.schema.marks[i.mark].create(i.attrs)),!1!==i.consuming)break;t=i}}return e}addElementByRule(t,e,i,s){let r,n;if(e.node)if(n=this.parser.schema.nodes[e.node],n.isLeaf)this.insertNode(n.create(e.attrs),i,"BR"==t.nodeName)||this.leafFallback(t,i);else{let t=this.enter(n,e.attrs||null,i,e.preserveWhitespace);t&&(r=!0,i=t)}else i=i.concat(this.parser.schema.marks[e.mark].create(e.attrs));let h=this.top;if(n&&n.isLeaf)this.findInside(t);else if(s)this.addElement(t,i,s);else if(e.getContent)this.findInside(t),e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,i,!1)));else{let s=t;"string"==typeof e.contentElement?s=t.querySelector(e.contentElement):"function"==typeof e.contentElement?s=e.contentElement(t):e.contentElement&&(s=e.contentElement),this.findAround(t,s,!0),this.addAll(s,i),this.findAround(t,s,!1)}r&&this.sync(h)&&this.open--}addAll(t,e,i,s){let r=i||0;for(let n=i?t.childNodes[i]:t.firstChild,h=null==s?null:t.childNodes[s];n!=h;n=n.nextSibling,++r)this.findAtPoint(t,r),this.addDOM(n,e);this.findAtPoint(t,r)}findPlace(t,e,i){let s,r;for(let e=this.open,n=0;e>=0;e--){let h=this.nodes[e],o=h.findWrapping(t);if(o&&(!s||s.length>o.length+n)&&(s=o,r=h,!o.length))break;if(h.solid){if(i)break;n+=2}}if(!s)return null;this.sync(r);for(let t=0;t<s.length;t++)e=this.enterInner(s[t],null,e,!1);return e}insertNode(t,e,i){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();t&&(e=this.enterInner(t,null,e))}let s=this.findPlace(t,e,i);if(s){this.closeExtra();let e=this.top;e.match&&(e.match=e.match.matchType(t.type));let i=g.none;for(let r of s.concat(t.marks))(e.type?e.type.allowsMarkType(r.type):dt(r.type,t.type))&&(i=r.addToSet(i));return e.content.push(t.mark(i)),!0}return!1}enter(t,e,i,s){let r=this.findPlace(t.create(e),i,!1);return r&&(r=this.enterInner(t,e,i,!0,s)),r}enterInner(t,e,i,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 i=i.filter((e=>!(n.type?n.type.allowsMarkType(e.type):dt(e.type,t))||(o=e.addToSet(o),!1))),this.nodes.push(new ut(t,e,o,s,null,h)),this.open++,i}closeExtra(t=!1){let e=this.nodes.length-1;if(e>this.open){for(;e>this.open;e--)this.nodes[e-1].content.push(this.nodes[e].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 e=this.open;e>=0;e--){if(this.nodes[e]==t)return this.open=e,!0;this.localPreserveWS&&(this.nodes[e].options|=1)}return!1}get currentPos(){this.closeExtra();let t=0;for(let e=this.open;e>=0;e--){let i=this.nodes[e].content;for(let e=i.length-1;e>=0;e--)t+=i[e].nodeSize;e&&t++}return t}findAtPoint(t,e){if(this.find)for(let i=0;i<this.find.length;i++)this.find[i].node==t&&this.find[i].offset==e&&(this.find[i].pos=this.currentPos)}findInside(t){if(this.find)for(let e=0;e<this.find.length;e++)null==this.find[e].pos&&1==t.nodeType&&t.contains(this.find[e].node)&&(this.find[e].pos=this.currentPos)}findAround(t,e,i){if(t!=e&&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)&&e.compareDocumentPosition(this.find[s].node)&(i?2:4)&&(this.find[s].pos=this.currentPos)}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].node==t&&(this.find[e].pos=this.currentPos-(t.nodeValue.length-this.find[e].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/"),i=this.options.context,s=!(this.isOpen||i&&i.parent.type!=this.nodes[0].type),r=(s?0:1)-(i?i.depth+1:0),n=(t,h)=>{for(;t>=0;t--){let o=e[t];if(""==o){if(t==e.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:i&&h>=r?i.node(h-r).type:null;if(!t||t.name!=o&&!t.isInGroup(o))return!1;h--}}return!0};return n(e.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let e=t.depth;e>=0;e--){let i=t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;if(i&&i.isTextblock&&i.defaultAttrs)return i}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}}function at(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function ct(t){let e={};for(let i in t)e[i]=t[i];return e}function dt(t,e){let i=e.schema.nodes;for(let s in i){let r=i[s];if(!r.allowsMarkType(t))continue;let n=[],h=t=>{n.push(t);for(let i=0;i<t.edgeCount;i++){let{type:s,next:r}=t.edge(i);if(s==e)return!0;if(n.indexOf(r)<0&&h(r))return!0}};if(h(r.contentMatch))return!0}}class pt{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},i){i||(i=wt(e).createDocumentFragment());let s=i,r=[];return t.forEach((t=>{if(r.length||t.marks.length){let i=0,n=0;for(;i<r.length&&n<t.marks.length;){let e=t.marks[n];if(this.marks[e.type.name]){if(!e.eq(r[i][0])||!1===e.type.spec.spanning)break;i++,n++}else n++}for(;i<r.length;)s=r.pop()[1];for(;n<t.marks.length;){let i=t.marks[n++],h=this.serializeMark(i,t.isInline,e);h&&(r.push([i,s]),s.appendChild(h.dom),s=h.contentDOM||h.dom)}}s.appendChild(this.serializeNodeInner(t,e))})),i}serializeNodeInner(t,e){let{dom:i,contentDOM:s}=yt(wt(e),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,e,s)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let s=t.marks.length-1;s>=0;s--){let r=this.serializeMark(t.marks[s],t.isInline,e);r&&((r.contentDOM||r.dom).appendChild(i),i=r.dom)}return i}serializeMark(t,e,i={}){let s=this.marks[t.type.name];return s&&yt(wt(i),s(t,e),null,t.attrs)}static renderSpec(t,e,i=null,s){return yt(t,e,i,s)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new pt(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=mt(t.nodes);return e.text||(e.text=t=>t.text),e}static marksFromSchema(t){return mt(t.marks)}}function mt(t){let e={};for(let i in t){let s=t[i].spec.toDOM;s&&(e[i]=s)}return e}function wt(t){return t.document||window.document}const gt=new WeakMap;function yt(t,e,i,s){if("string"==typeof e)return{dom:t.createTextNode(e)};if(null!=e.nodeType)return{dom:e};if(e.dom&&null!=e.dom.nodeType)return e;let r,n=e[0];if("string"!=typeof n)throw new RangeError("Invalid array passed to renderSpec");if(s&&(r=function(t){let e=gt.get(t);return void 0===e&>.set(t,e=function(t){let e=null;return function t(i){if(i&&"object"==typeof i)if(Array.isArray(i))if("string"==typeof i[0])e||(e=[]),e.push(i);else for(let e=0;e<i.length;e++)t(i[e]);else for(let e in i)t(i[e])}(t),e}(t)),e}(s))&&r.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let h,o=n.indexOf(" ");o>0&&(i=n.slice(0,o),n=n.slice(o+1));let l=i?t.createElementNS(i,n):t.createElement(n),u=e[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 e=t.indexOf(" ");e>0?l.setAttributeNS(t.slice(0,e),t.slice(e+1),u[t]):"style"==t&&l.style?l.style.cssText=u[t]:l.setAttribute(t,u[t])}}for(let r=f;r<e.length;r++){let n=e[r];if(0===n){if(r<e.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:e,contentDOM:r}=yt(t,n,i,s);if(l.appendChild(e),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,e,i){this.pos=t,this.delInfo=e,this.recover=i}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,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&kt.empty)return kt.empty}recover(t){let e=0,i=Mt(t);if(!this.inverted)for(let t=0;t<i;t++)e+=this.ranges[3*t+2]-this.ranges[3*t+1];return this.ranges[3*i]+e+function(t){return(t-(65535&t))/bt}(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,i){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:e:e)<0?0:u);if(i)return r;let n=t==o?2:t==f?1:4;return(e<0?t!=o:t!=f)&&(n|=8),new vt(r,n,t==(e<0?o:f)?null:h/3+(t-o)*bt)}s+=u-l}return i?t+s:new vt(t+s,0,null)}touches(t,e){let i=0,s=Mt(e),r=this.inverted?2:1,n=this.inverted?1:2;for(let e=0;e<this.ranges.length;e+=3){let h=this.ranges[e]-(this.inverted?i:0);if(h>t)break;let o=this.ranges[e+r];if(t<=h+o&&e==3*s)return!0;i+=this.ranges[e+n]-o}return!1}forEach(t){let e=this.inverted?2:1,i=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+e],u=this.ranges[s+i];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,e,i=0,s=(t?t.length:0)){this.mirror=e,this.from=i,this.to=s,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new St(this._maps,this.mirror,t,e)}appendMap(t,e){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(t),null!=e&&this.setMirror(this._maps.length-1,e)}appendMapping(t){for(let e=0,i=this._maps.length;e<t._maps.length;e++){let s=t.getMirror(e);this.appendMap(t._maps[e],null!=s&&s<e?i+s:void 0)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){this.mirror||(this.mirror=[]),this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,i=this._maps.length+t._maps.length;e>=0;e--){let s=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=s&&s>e?i-s-1:void 0)}}invert(){let t=new St;return t.appendMappingInverted(this),t}map(t,e=1){if(this.mirror)return this._map(t,e,!0);for(let i=this.from;i<this.to;i++)t=this._maps[i].map(t,e);return t}mapResult(t,e=1){return this._map(t,e,!1)}_map(t,e,i){let s=0;for(let i=this.from;i<this.to;i++){let r=this._maps[i].mapResult(t,e);if(null!=r.recover){let e=this.getMirror(i);if(null!=e&&e>i&&e<this.to){i=e,t=this._maps[e].recover(r.recover);continue}}s|=r.delInfo,t=r.pos}return i?t:new vt(t,s,null)}}const xt=Object.create(null);class Ot{getMap(){return kt.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=xt[e.stepType];if(!i)throw new RangeError(`No step type ${e.stepType} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in xt)throw new RangeError("Duplicate use of step JSON ID "+t);return xt[t]=e,e.prototype.jsonID=t,e}}class Tt{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new Tt(t,null)}static fail(t){return new Tt(null,t)}static fromReplace(t,e,i,s){try{return Tt.ok(t.replace(e,i,s))}catch(t){if(t instanceof y)return Tt.fail(t.message);throw t}}}function Dt(t,e,i){let s=[];for(let r=0;r<t.childCount;r++){let n=t.child(r);n.content.size&&(n=n.copy(Dt(n.content,e,n))),n.isInline&&(n=e(n,i,r)),s.push(n)}return d.fromArray(s)}class At extends Ot{constructor(t,e,i){super(),this.from=t,this.to=e,this.mark=i}apply(t){let e=t.slice(this.from,this.to),i=t.resolve(this.from),s=i.node(i.sharedDepth(this.to)),r=new b(Dt(e.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),s),e.openStart,e.openEnd);return Tt.fromReplace(t,this.from,this.to,r)}invert(){return new Rt(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);return e.deleted&&i.deleted||e.pos>=i.pos?null:new At(e.pos,i.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,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new At(e.from,e.to,t.markFromJSON(e.mark))}}Ot.jsonID("addMark",At);class Rt extends Ot{constructor(t,e,i){super(),this.from=t,this.to=e,this.mark=i}apply(t){let e=t.slice(this.from,this.to),i=new b(Dt(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return Tt.fromReplace(t,this.from,this.to,i)}invert(){return new At(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);return e.deleted&&i.deleted||e.pos>=i.pos?null:new Rt(e.pos,i.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,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Rt(e.from,e.to,t.markFromJSON(e.mark))}}Ot.jsonID("removeMark",Rt);class Et extends Ot{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Tt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let i=0;i<e.marks.length;i++)if(!e.marks[i].isInSet(t))return new Et(this.pos,e.marks[i]);return new Et(this.pos,this.mark)}}return new $t(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Et(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Et(e.pos,t.markFromJSON(e.mark))}}Ot.jsonID("addNodeMark",Et);class $t extends Ot{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Tt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new Et(this.pos,this.mark):this}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new $t(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new $t(e.pos,t.markFromJSON(e.mark))}}Ot.jsonID("removeNodeMark",$t);class Pt extends Ot{constructor(t,e,i,s=!1){super(),this.from=t,this.to=e,this.slice=i,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 Pt(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.to,-1),i=this.from==this.to&&Pt.MAP_BIAS<0?e:t.mapResult(this.from,1);return i.deletedAcross&&e.deletedAcross?null:new Pt(i.pos,Math.max(i.pos,e.pos),this.slice,this.structure)}merge(t){if(!(t instanceof Pt)||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 e=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 Pt(t.from,this.to,e,this.structure)}}{let e=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 Pt(this.from,this.to+(t.to-t.from),e,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,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Pt(e.from,e.to,b.fromJSON(t,e.slice),!!e.structure)}}Pt.MAP_BIAS=1,Ot.jsonID("replace",Pt);class Ct extends Ot{constructor(t,e,i,s,r,n,h=!1){super(),this.from=t,this.to=e,this.gapFrom=i,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 e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return Tt.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,e.content);return i?Tt.fromReplace(t,this.from,this.to,i):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 e=this.gapTo-this.gapFrom;return new Ct(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1),s=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),r=this.to==this.gapTo?i.pos:t.map(this.gapTo,1);return e.deletedAcross&&i.deletedAcross||s<e.pos||r>i.pos?null:new Ct(e.pos,i.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,e){if("number"!=typeof e.from||"number"!=typeof e.to||"number"!=typeof e.gapFrom||"number"!=typeof e.gapTo||"number"!=typeof e.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Ct(e.from,e.to,e.gapFrom,e.gapTo,b.fromJSON(t,e.slice),e.insert,!!e.structure)}}function Nt(t,e,i){let s=t.resolve(e),r=i-e,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,e,i,s=i.contentMatch,r=!0){let n=t.doc.nodeAt(e),h=[],o=e+1;for(let e=0;e<n.childCount;e++){let l=n.child(e),u=o+l.nodeSize,f=s.matchType(l.type);if(f){s=f;for(let e=0;e<l.marks.length;e++)i.allowsMarkType(l.marks[e].type)||t.step(new Rt(o,u,l.marks[e]));if(r&&l.isText&&"pre"!=i.whitespace){let t,e,s=/\r?\n|\r/g;for(;t=s.exec(l.text);)e||(e=new b(d.from(i.schema.text(" ",i.allowedMarks(l.marks))),0,0)),h.push(new Pt(o+t.index,o+t.index+t[0].length,e))}}else h.push(new Pt(o,u,b.empty));o=u}if(!s.validEnd){let e=s.fillBefore(d.empty,!0);t.replace(o,o,new b(e,0,0))}for(let e=h.length-1;e>=0;e--)t.step(h[e])}function zt(t,e,i){return(0==e||t.canReplace(e,t.childCount))&&(i==t.childCount||t.canReplace(0,i))}function jt(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let i=t.depth,s=0,r=0;;--i){let n=t.$from.node(i),h=t.$from.index(i)+s,o=t.$to.indexAfter(i)-r;if(i<t.depth&&n.canReplace(h,o,e))return i;if(0==i||n.type.spec.isolating||!zt(n,h,o))break;h&&(s=1),o<n.childCount&&(r=1)}return null}function _t(t,e,i,s){e.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(i+1+n+h.index);t.replaceWith(r,r+1,e.type.schema.linebreakReplacement.create())}}}))}function Ft(t,e,i,s){e.forEach(((r,n)=>{if(r.type==r.type.schema.linebreakReplacement){let r=t.mapping.slice(s).map(i+1+n);t.replaceWith(r,r+1,e.type.schema.text("\n"))}}))}function Bt(t,e,i=1,s){let r=t.resolve(e),n=r.depth-i,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,e=i-2;t>n;t--,e--){let i=r.node(t),n=r.index(t);if(i.type.spec.isolating)return!1;let h=i.content.cutByIndex(n,i.childCount),o=s&&s[e+1];o&&(h=h.replaceChild(0,o.type.create(o.attrs)));let l=s&&s[e]||i;if(!i.canReplace(n+1,i.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,e){let i=t.resolve(e),s=i.index();return n=i.nodeAfter,!(!(r=i.nodeBefore)||!n||r.isLeaf||!function(t,e){e.content.size||t.type.compatibleContent(e.type);let i=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let r=0;r<e.childCount;r++){let n=e.child(r);if(i=i.matchType(n.type==s?t.type.schema.nodes.text:n.type),!i)return!1;if(!t.type.allowsMarks(n.marks))return!1}return i.validEnd}(r,n))&&i.parent.canReplace(s,s+1);var r,n}function Jt(t,e,i=e,s=b.empty){if(e==i&&!s.size)return null;let r=t.resolve(e),n=t.resolve(i);return Lt(r,n,s)?new Pt(e,i,s):new Yt(r,n,s).fit()}function Lt(t,e,i){return!i.openStart&&!i.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),i.content)}Ot.jsonID("replaceAround",Ct);class Yt{constructor(t,e,i){this.$from=t,this.$to=e,this.unplaced=i,this.frontier=[],this.placed=d.empty;for(let e=0;e<=t.depth;e++){let i=t.node(e);this.frontier.push({type:i.type,match:i.contentMatchAt(t.indexAfter(e))})}for(let e=t.depth;e>0;e--)this.placed=d.from(t.node(e).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(),e=this.placed.size-this.depth-this.$from.depth,i=this.$from,s=this.close(t<0?this.$to:i.doc.resolve(t));if(!s)return null;let r=this.placed,n=i.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 Ct(i.pos,t,this.$to.pos,this.$to.end(),o,e):o.size||i.pos!=this.$to.pos?new Pt(i.pos,s.pos,o):null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,i=0,s=this.unplaced.openEnd;i<t;i++){let r=e.firstChild;if(e.childCount>1&&(s=0),r.type.spec.isolating&&s<=i){t=i;break}e=r.content}for(let e=1;e<=2;e++)for(let i=1==e?t:this.unplaced.openStart;i>=0;i--){let t,s=null;i?(s=Ht(this.unplaced.content,i-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==e&&(r?o.matchType(r.type)||(l=o.fillBefore(d.from(r),!1)):s&&h.compatibleContent(s.type)))return{sliceDepth:i,frontierDepth:t,parent:s,inject:l};if(2==e&&r&&(n=o.findWrapping(r.type)))return{sliceDepth:i,frontierDepth:t,parent:s,wrap:n};if(s&&o.matchType(s.type))break}}}openMore(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Ht(t,e);return!(!s.childCount||s.firstChild.isLeaf||(this.unplaced=new b(t,e+1,Math.max(i,s.size+e>=t.size-i?e+1:0)),0))}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Ht(t,e);if(s.childCount<=1&&e>0){let r=t.size-e<=e+s.size;this.unplaced=new b(Xt(t,e-1,1),e-1,r?e-1:i)}else this.unplaced=new b(Xt(t,e,1),e,i)}placeNodes({sliceDepth:t,frontierDepth:e,parent:i,inject:s,wrap:r}){for(;this.depth>e;)this.closeFrontierNode();if(r)for(let t=0;t<r.length;t++)this.openFrontierNode(r[t]);let n=this.unplaced,h=i?i.content:n.content,o=n.openStart-t,l=0,u=[],{match:f,type:a}=this.frontier[e];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),e=f.matchType(t.type);if(!e)break;l++,(l>1||0==o||t.content.size)&&(f=e,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,e,d.from(u)),this.frontier[e].match=f,p&&c<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,e=h;t<c;t++){let t=e.lastChild;this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)}),e=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,e=this.frontier[this.depth];if(!e.type.isTextblock||!qt(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:i}=this.$to,s=this.$to.after(i);for(;i>1&&s==this.$to.end(--i);)++s;return s}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:i,type:s}=this.frontier[e],r=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),n=qt(t,e,s,i,r);if(n){for(let i=e-1;i>=0;i--){let{match:e,type:s}=this.frontier[i],r=qt(t,i,s,e,!0);if(!r||r.childCount)continue t}return{depth:e,fit:n,move:r?t.doc.resolve(t.after(e+1)):t}}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;for(;this.depth>e.depth;)this.closeFrontierNode();e.fit.childCount&&(this.placed=Ut(this.placed,e.depth,e.fit)),t=e.move;for(let i=e.depth+1;i<=t.depth;i++){let e=t.node(i),s=e.type.contentMatch.fillBefore(e.content,!0,t.index(i));this.openFrontierNode(e.type,e.attrs,s)}return t}openFrontierNode(t,e=null,i){let s=this.frontier[this.depth];s.match=s.match.matchType(t),this.placed=Ut(this.placed,this.depth,d.from(t.create(e,i))),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,e,i){return 0==e?t.cutByIndex(i,t.childCount):t.replaceChild(0,t.firstChild.copy(Xt(t.firstChild.content,e-1,i)))}function Ut(t,e,i){return 0==e?t.append(i):t.replaceChild(t.childCount-1,t.lastChild.copy(Ut(t.lastChild.content,e-1,i)))}function Ht(t,e){for(let i=0;i<e;i++)t=t.firstChild.content;return t}function Kt(t,e,i){if(e<=0)return t;let s=t.content;return e>1&&(s=s.replaceChild(0,Kt(s.firstChild,e-1,1==s.childCount?i-1:0))),e>0&&(s=t.type.contentMatch.fillBefore(s).append(s),i<=0&&(s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(d.empty,!0)))),t.copy(s)}function qt(t,e,i,s,r){let n=t.node(e),h=r?t.indexAfter(e):t.index(e);if(h==n.childCount&&!i.compatibleContent(n.type))return null;let o=s.fillBefore(n.content,!0,h);return o&&!function(t,e,i){for(let s=i;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return!0;return!1}(i,n.content,h)?o:null}function Gt(t,e,i,s,r){if(e<i){let r=t.firstChild;t=t.replaceChild(0,r.copy(Gt(r.content,e+1,i,s,r)))}if(e>s){let e=r.contentMatchAt(0),i=e.fillBefore(t).append(t);t=i.append(e.matchFragment(i).fillBefore(d.empty,!0))}return t}function Vt(t,e){let i=[];for(let s=Math.min(t.depth,e.depth);s>=0;s--){let r=t.start(s);if(r<t.pos-(t.depth-s)||e.end(s)>e.pos+(e.depth-s)||t.node(s).type.spec.isolating||e.node(s).type.spec.isolating)break;(r==e.start(s)||s==t.depth&&s==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==r-1)&&i.push(s)}return i}class Zt extends Ot{constructor(t,e,i){super(),this.pos=t,this.attr=e,this.value=i}apply(t){let e=t.nodeAt(this.pos);if(!e)return Tt.fail("No node at attribute step's position");let i=Object.create(null);for(let t in e.attrs)i[t]=e.attrs[t];i[this.attr]=this.value;let s=e.type.create(i,null,e.marks);return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(s),0,e.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 e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Zt(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if("number"!=typeof e.pos||"string"!=typeof e.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new Zt(e.pos,e.attr,e.value)}}Ot.jsonID("attr",Zt);class Qt extends Ot{constructor(t,e){super(),this.attr=t,this.value=e}apply(t){let e=Object.create(null);for(let i in t.attrs)e[i]=t.attrs[i];e[this.attr]=this.value;let i=t.type.create(e,t.content,t.marks);return Tt.ok(i)}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,e){if("string"!=typeof e.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Qt(e.attr,e.value)}}Ot.jsonID("docAttr",Qt);let te=class extends Error{};te=function t(e){let i=Error.call(this,e);return i.__proto__=t.prototype,i},(te.prototype=Object.create(Error.prototype)).constructor=te,te.prototype.name="TransformError";class ee{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 e=this.maybeStep(t);if(e.failed)throw new te(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);return e.failed||this.addStep(t,e.doc),e}get docChanged(){return this.steps.length>0}changedRange(){let t=1e9,e=-1e9;for(let i=0;i<this.mapping.maps.length;i++){let s=this.mapping.maps[i];i&&(t=s.map(t,1),e=s.map(e,-1)),s.forEach(((i,s,r,n)=>{t=Math.min(t,r),e=Math.max(e,n)}))}return 1e9==t?null:{from:t,to:e}}addStep(t,e){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=e}replace(t,e=t,i=b.empty){let s=Jt(this.doc,t,e,i);return s&&this.step(s),this}replaceWith(t,e,i){return this.replace(t,e,new b(d.from(i),0,0))}delete(t,e){return this.replace(t,e,b.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(t,e,i){return function(t,e,i,s){if(!s.size)return t.deleteRange(e,i);let r=t.doc.resolve(e),n=t.doc.resolve(i);if(Lt(r,n,s))return t.step(new Pt(e,i,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,e=r.pos-1;t>0;t--,e--){let i=r.node(t).type.spec;if(i.defining||i.definingAsContext||i.isolating)break;h.indexOf(t)>-1?o=t:r.before(t)==e&&h.splice(1,0,-t)}let l=h.indexOf(o),u=[],f=s.openStart;for(let t=s.content,e=0;;e++){let i=t.firstChild;if(u.push(i),e==s.openStart)break;t=i.content}for(let t=f-1;t>=0;t--){let e=u[t],i=(a=e.type).spec.defining||a.spec.definingForContent;if(i&&!e.sameMarkup(r.node(Math.abs(o)-1)))f=t;else if(i||!e.type.isTextblock)break}var a;for(let e=s.openStart;e>=0;e--){let o=(e+f+1)%(s.openStart+1),a=u[o];if(a)for(let e=0;e<h.length;e++){let u=h[(e+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):i,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(e,i,s),!(t.steps.length>c));o--){let t=h[o];t<0||(e=r.before(t),i=n.after(t))}}(this,t,e,i),this}replaceRangeWith(t,e,i){return function(t,e,i,s){if(!s.isInline&&e==i&&t.doc.resolve(e).parent.content.size){let r=function(t,e,i){let s=t.resolve(e);if(s.parent.canReplaceWith(s.index(),s.index(),i))return e;if(0==s.parentOffset)for(let t=s.depth-1;t>=0;t--){let e=s.index(t);if(s.node(t).canReplaceWith(e,e,i))return s.before(t+1);if(e>0)return null}if(s.parentOffset==s.parent.content.size)for(let t=s.depth-1;t>=0;t--){let e=s.indexAfter(t);if(s.node(t).canReplaceWith(e,e,i))return s.after(t+1);if(e<s.node(t).childCount)return null}return null}(t.doc,e,s.type);null!=r&&(e=i=r)}t.replaceRange(e,i,new b(d.from(s),0,0))}(this,t,e,i),this}deleteRange(t,e){return function(t,e,i){let s=t.doc.resolve(e),r=t.doc.resolve(i);if(s.parent.isTextblock&&r.parent.isTextblock&&s.start()!=r.start()&&0==s.parentOffset&&0==r.parentOffset){let n=s.sharedDepth(i),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&&e==s.start(t);t--)e=s.before(t);for(let t=r.depth;t>0&&i==r.start(t);t--)i=r.before(t);s=t.doc.resolve(e),r=t.doc.resolve(i)}}let n=Vt(s,r);for(let e=0;e<n.length;e++){let i=n[e],h=e==n.length-1;if(h&&0==i||s.node(i).type.contentMatch.validEnd)return t.delete(s.start(i),r.end(i));if(i>0&&(h||s.node(i-1).canReplace(s.index(i-1),r.indexAfter(i-1))))return t.delete(s.before(i),r.after(i))}for(let n=1;n<=s.depth&&n<=r.depth;n++)if(e-s.start(n)==s.depth-n&&i>s.end(n)&&r.end(n)-i!=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),i);t.delete(e,i)}(this,t,e),this}lift(t,e){return function(t,e,i){let{$from:s,$to:r,depth:n}=e,h=s.before(n+1),o=r.after(n+1),l=h,u=o,f=d.empty,a=0;for(let t=n,e=!1;t>i;t--)e||s.index(t)>0?(e=!0,f=d.from(s.node(t).copy(f)),a++):l--;let c=d.empty,p=0;for(let t=n,e=!1;t>i;t--)e||r.after(t+1)<r.end(t)?(e=!0,c=d.from(r.node(t).copy(c)),p++):u++;t.step(new Ct(l,u,h,o,new b(f.append(c),a,p),f.size-a,!0))}(this,t,e),this}join(t,e=1){return function(t,e,i){let s=null,{linebreakReplacement:r}=t.doc.type.schema,n=t.doc.resolve(e-i),h=n.node().type;if(r&&h.inlineContent){let t="pre"==h.whitespace,e=!!h.contentMatch.matchType(r);t&&!e?s=!1:!t&&e&&(s=!0)}let o=t.steps.length;if(!1===s){let s=t.doc.resolve(e+i);Ft(t,s.node(),s.before(),o)}h.inlineContent&&It(t,e+i-1,h,n.node().contentMatchAt(n.index()),null==s);let l=t.mapping.slice(o),u=l.map(e-i);if(t.step(new Pt(u,l.map(e+i,-1),b.empty,!0)),!0===s){let e=t.doc.resolve(u);_t(t,e.node(),e.before(),t.steps.length)}}(this,t,e),this}wrap(t,e){return function(t,e,i){let s=d.empty;for(let t=i.length-1;t>=0;t--){if(s.size){let e=i[t].type.contentMatch.matchFragment(s);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=d.from(i[t].type.create(i[t].attrs,s))}let r=e.start,n=e.end;t.step(new Ct(r,n,r,n,new b(s,0,0),i.length,!0))}(this,t,e),this}setBlockType(t,e=t,i,s=null){return function(t,e,i,s,r){if(!s.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let n=t.steps.length;t.doc.nodesBetween(e,i,((e,i)=>{let h="function"==typeof r?r(e):r;if(e.isTextblock&&!e.hasMarkup(s,h)&&function(t,e,i){let s=t.resolve(e),r=s.index();return s.parent.canReplaceWith(r,r+1,i)}(t.doc,t.mapping.slice(n).map(i),s)){let r=null;if(s.schema.linebreakReplacement){let t="pre"==s.whitespace,e=!!s.contentMatch.matchType(s.schema.linebreakReplacement);t&&!e?r=!1:!t&&e&&(r=!0)}!1===r&&Ft(t,e,i,n),It(t,t.mapping.slice(n).map(i,1),s,void 0,null===r);let o=t.mapping.slice(n),l=o.map(i,1),u=o.map(i+e.nodeSize,1);return t.step(new Ct(l,u,l+1,u-1,new b(d.from(s.create(h,null,e.marks)),0,0),1,!0)),!0===r&&_t(t,e,i,n),!1}}))}(this,t,e,i,s),this}setNodeMarkup(t,e,i=null,s){return function(t,e,i,s,r){let n=t.doc.nodeAt(e);if(!n)throw new RangeError("No node at given position");i||(i=n.type);let h=i.create(s,null,r||n.marks);if(n.isLeaf)return t.replaceWith(e,e+n.nodeSize,h);if(!i.validContent(n.content))throw new RangeError("Invalid content for node type "+i.name);t.step(new Ct(e,e+n.nodeSize,e+1,e+n.nodeSize-1,new b(d.from(h),0,0),1,!0))}(this,t,e,i,s),this}setNodeAttribute(t,e,i){return this.step(new Zt(t,e,i)),this}setDocAttribute(t,e){return this.step(new Qt(t,e)),this}addNodeMark(t,e){return this.step(new Et(t,e)),this}removeNodeMark(t,e){let i=this.doc.nodeAt(t);if(!i)throw new RangeError("No node at position "+t);if(e instanceof g)e.isInSet(i.marks)&&this.step(new $t(t,e));else{let s,r=i.marks,n=[];for(;s=e.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,e=1,i){return function(t,e,i=1,s){let r=t.doc.resolve(e),n=d.empty,h=d.empty;for(let t=r.depth,e=r.depth-i,o=i-1;t>e;t--,o--){n=d.from(r.node(t).copy(n));let e=s&&s[o];h=d.from(e?e.type.create(e.attrs,h):r.node(t).copy(h))}t.step(new Pt(e,e,new b(n.append(h),i,i),!0))}(this,t,e,i),this}addMark(t,e,i){return function(t,e,i,s){let r,n,h=[],o=[];t.doc.nodesBetween(e,i,((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,e),a=Math.min(l+t.nodeSize,i),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((e=>t.step(e))),o.forEach((e=>t.step(e)))}(this,t,e,i),this}removeMark(t,e,i){return function(t,e,i,s){let r=[],n=0;t.doc.nodesBetween(e,i,((t,h)=>{if(!t.isInline)return;n++;let o=null;if(s instanceof et){let e,i=t.marks;for(;e=s.isInSet(i);)(o||(o=[])).push(e),i=e.removeFromSet(i)}else s?s.isInSet(t.marks)&&(o=[s]):o=t.marks;if(o&&o.length){let s=Math.min(h+t.nodeSize,i);for(let t=0;t<o.length;t++){let i,l=o[t];for(let t=0;t<r.length;t++){let e=r[t];e.step==n-1&&l.eq(r[t].style)&&(i=e)}i?(i.to=s,i.step=n):r.push({style:l,from:Math.max(h,e),to:s,step:n})}}})),r.forEach((e=>t.step(new Rt(e.from,e.to,e.style))))}(this,t,e,i),this}clearIncompatible(t,e,i){return It(this,t,e,i),this}}const ie=Object.create(null);class se{constructor(t,e,i){this.$anchor=t,this.$head=e,this.ranges=i||[new re(t.min(e),t.max(e))]}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 e=0;e<t.length;e++)if(t[e].$from.pos!=t[e].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,e=b.empty){let i=e.content.lastChild,s=null;for(let t=0;t<e.openEnd;t++)s=i,i=i.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:e),0==h&&pe(t,r,(i?i.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(t,e){let i=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(i),l=o.map(n.pos),u=o.map(h.pos);r?t.deleteRange(l,u):(t.replaceRangeWith(l,u,e),pe(t,i,e.isInline?-1:1))}}static findFrom(t,e,i=!1){let s=t.parent.inlineContent?new oe(t):de(t.node(0),t.parent,t.pos,t.index(),e,i);if(s)return s;for(let s=t.depth-1;s>=0;s--){let r=e<0?de(t.node(0),t.node(s),t.before(s+1),t.index(s),e,i):de(t.node(0),t.node(s),t.after(s+1),t.index(s)+1,e,i);if(r)return r}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new ae(t.node(0))}static atStart(t){return de(t,t,0,0,1)||new ae(t)}static atEnd(t){return de(t,t,t.content.size,t.childCount,-1)||new ae(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let i=ie[e.type];if(!i)throw new RangeError(`No selection type ${e.type} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in ie)throw new RangeError("Duplicate use of selection JSON ID "+t);return ie[t]=e,e.prototype.jsonID=t,e}getBookmark(){return oe.between(this.$anchor,this.$head).getBookmark()}}se.prototype.visible=!0;class re{constructor(t,e){this.$from=t,this.$to=e}}let ne=!1;function he(t){ne||t.parent.inlineContent||(ne=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class oe extends se{constructor(t,e=t){he(t),he(e),super(t,e)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,e){let i=t.resolve(e.map(this.head));if(!i.parent.inlineContent)return se.near(i);let s=t.resolve(e.map(this.anchor));return new oe(s.parent.inlineContent?s:i,i)}replace(t,e=b.empty){if(super.replace(t,e),e==b.empty){let e=this.$from.marksAcross(this.$to);e&&t.ensureMarks(e)}}eq(t){return t instanceof oe&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new le(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if("number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new oe(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,i=e){let s=t.resolve(e);return new this(s,i==e?s:t.resolve(i))}static between(t,e,i){let s=t.pos-e.pos;if(i&&!s||(i=s>=0?1:-1),!e.parent.inlineContent){let t=se.findFrom(e,i,!0)||se.findFrom(e,-i,!0);if(!t)return se.near(e,i);e=t.$head}return t.parent.inlineContent||(0==s||(t=(se.findFrom(t,-i,!0)||se.findFrom(t,i,!0)).$anchor).pos<e.pos!=s<0)&&(t=e),new oe(t,e)}}se.jsonID("text",oe);class le{constructor(t,e){this.anchor=t,this.head=e}map(t){return new le(t.map(this.anchor),t.map(this.head))}resolve(t){return oe.between(t.resolve(this.anchor),t.resolve(this.head))}}class ue extends se{constructor(t){let e=t.nodeAfter,i=t.node(0).resolve(t.pos+e.nodeSize);super(t,i),this.node=e}map(t,e){let{deleted:i,pos:s}=e.mapResult(this.anchor),r=t.resolve(s);return i?se.near(r):new ue(r)}content(){return new b(d.from(this.node),0,0)}eq(t){return t instanceof ue&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new fe(this.anchor)}static fromJSON(t,e){if("number"!=typeof e.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new ue(t.resolve(e.anchor))}static create(t,e){return new ue(t.resolve(e))}static isSelectable(t){return!t.isText&&!1!==t.type.spec.selectable}}ue.prototype.visible=!1,se.jsonID("node",ue);class fe{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:i}=t.mapResult(this.anchor);return e?new le(i,i):new fe(i)}resolve(t){let e=t.resolve(this.anchor),i=e.nodeAfter;return i&&ue.isSelectable(i)?new ue(e):se.near(e)}}class ae extends se{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,e=b.empty){if(e==b.empty){t.delete(0,t.doc.content.size);let e=se.atStart(t.doc);e.eq(t.selection)||t.setSelection(e)}else super.replace(t,e)}toJSON(){return{type:"all"}}static fromJSON(t){return new ae(t)}map(t){return new ae(t)}eq(t){return t instanceof ae}getBookmark(){return ce}}se.jsonID("all",ae);const ce={map(){return this},resolve:t=>new ae(t)};function de(t,e,i,s,r,n=!1){if(e.inlineContent)return oe.create(t,i);for(let h=s-(r>0?0:1);r>0?h<e.childCount:h>=0;h+=r){let s=e.child(h);if(s.isAtom){if(!n&&ue.isSelectable(s))return ue.create(t,i-(r<0?s.nodeSize:0))}else{let e=de(t,s,i+r,r<0?s.childCount:0,r,n);if(e)return e}i+=s.nodeSize*r}return null}function pe(t,e,i){let s=t.steps.length-1;if(s<e)return;let r,n=t.steps[s];(n instanceof Pt||n instanceof Ct)&&(t.mapping.maps[s].forEach(((t,e,i,s)=>{null==r&&(r=s)})),t.setSelection(se.near(t.doc.resolve(r),i)))}class me extends ee{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,e){super.addStep(t,e),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,e=!0){let i=this.selection;return e&&(t=t.mark(this.storedMarks||(i.empty?i.$from.marks():i.$from.marksAcross(i.$to)||g.none))),i.replaceWith(this,t),this}deleteSelection(){return this.selection.replace(this),this}insertText(t,e,i){let s=this.doc.type.schema;if(null==e)return t?this.replaceSelectionWith(s.text(t),!0):this.deleteSelection();{if(null==i&&(i=e),!t)return this.deleteRange(e,i);let r=this.storedMarks;if(!r){let t=this.doc.resolve(e);r=i==e?t.marks():t.marksAcross(this.doc.resolve(i))}return this.replaceRangeWith(e,i,s.text(t,r)),this.selection.empty||this.selection.to!=e+t.length||this.setSelection(se.near(this.selection.$to)),this}}setMeta(t,e){return this.meta["string"==typeof t?t:t.key]=e,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 we(t,e){return e&&t?t.bind(e):t}class ge{constructor(t,e,i){this.name=t,this.init=we(e.init,i),this.apply=we(e.apply,i)}}const ye=[new ge("doc",{init:t=>t.doc||t.schema.topNodeType.createAndFill(),apply:t=>t.doc}),new ge("selection",{init:(t,e)=>t.selection||se.atStart(e.doc),apply:t=>t.selection}),new ge("storedMarks",{init:t=>t.storedMarks||null,apply:(t,e,i,s)=>s.selection.$cursor?t.storedMarks:null}),new ge("scrollToSelection",{init:()=>0,apply:(t,e)=>t.scrolledIntoView?e+1:e})];class be{constructor(t,e){this.schema=t,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ye.slice(),e&&e.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 ge(t.key,t.spec.state,t))}))}}class Me{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,e=-1){for(let i=0;i<this.config.plugins.length;i++)if(i!=e){let e=this.config.plugins[i];if(e.spec.filterTransaction&&!e.spec.filterTransaction.call(e,t,this))return!1}return!0}applyTransaction(t){if(!this.filterTransaction(t))return{state:this,transactions:[]};let e=[t],i=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<e.length&&h.spec.appendTransaction.call(h,o?e.slice(o):e,l,i);if(u&&i.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:i,n:e.length}:{state:this,n:0})}e.push(u),i=i.applyInner(u),r=!0}s&&(s[n]={state:i,n:e.length})}}if(!r)return{state:i,transactions:e}}}applyInner(t){if(!t.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let e=new Me(this.config),i=this.config.fields;for(let s=0;s<i.length;s++){let r=i[s];e[r.name]=r.apply(t,this[r.name],this,e)}return e}get tr(){return new me(this)}static create(t){let e=new be(t.doc?t.doc.type.schema:t.schema,t.plugins),i=new Me(e);for(let s=0;s<e.fields.length;s++)i[e.fields[s].name]=e.fields[s].init(t,i);return i}reconfigure(t){let e=new be(this.schema,t.plugins),i=e.fields,s=new Me(e);for(let e=0;e<i.length;e++){let r=i[e].name;s[r]=this.hasOwnProperty(r)?this[r]:i[e].init(t,s)}return s}toJSON(t){let e={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(e.storedMarks=this.storedMarks.map((t=>t.toJSON()))),t&&"object"==typeof t)for(let i in t){if("doc"==i||"selection"==i)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let s=t[i],r=s.spec.state;r&&r.toJSON&&(e[i]=r.toJSON.call(s,this[s.key]))}return e}static fromJSON(t,e,i){if(!e)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let s=new be(t.schema,t.plugins),r=new Me(s);return s.fields.forEach((s=>{if("doc"==s.name)r.doc=j.fromJSON(t.schema,e.doc);else if("selection"==s.name)r.selection=se.fromJSON(r.doc,e.selection);else if("storedMarks"==s.name)e.storedMarks&&(r.storedMarks=e.storedMarks.map(t.schema.markFromJSON));else{if(i)for(let n in i){let h=i[n],o=h.spec.state;if(h.key==s.name&&o&&o.fromJSON&&Object.prototype.hasOwnProperty.call(e,n))return void(r[s.name]=o.fromJSON.call(h,t,e[n],r))}r[s.name]=s.init(t,r)}})),r}}function ve(t,e,i){for(let s in t){let r=t[s];r instanceof Function?r=r.bind(e):"handleDOMEvents"==s&&(r=ve(r,e,{})),i[s]=r}return i}class ke{constructor(t){var e;this.spec=t,this.props={},t.props&&ve(t.props,this,this.props),this.key=t.key?t.key.key:(e="plugin")in Se?e+"$"+ ++Se[e]:(Se[e]=0,e+"$")}getState(t){return t[this.key]}}const Se=Object.create(null),xe=function(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e},Oe=function(t){let e=t.assignedSlot||t.parentNode;return e&&11==e.nodeType?e.host:e};let Te=null;const De=function(t,e,i){let s=Te||(Te=document.createRange());return s.setEnd(t,null==i?t.nodeValue.length:i),s.setStart(t,e||0),s},Ae=function(t,e,i,s){return i&&(Ee(t,e,i,s,-1)||Ee(t,e,i,s,1))},Re=/^(img|br|input|textarea|hr)$/i;function Ee(t,e,i,s,r){for(var n;;){if(t==i&&e==s)return!0;if(e==(r<0?0:$e(t))){let i=t.parentNode;if(!i||1!=i.nodeType||Pe(t)||Re.test(t.nodeName)||"false"==t.contentEditable)return!1;e=xe(t)+(r<0?0:1),t=i}else{if(1!=t.nodeType)return!1;{let i=t.childNodes[e+(r<0?-1:0)];if(1==i.nodeType&&"false"==i.contentEditable){if(!(null===(n=i.pmViewDesc)||void 0===n?void 0:n.ignoreForSelection))return!1;e+=r}else t=i,e=r<0?$e(t):0}}}}function $e(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Pe(t){let e;for(let i=t;i&&!(e=i.pmViewDesc);i=i.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Ce=function(t){return t.focusNode&&Ae(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Ne(t,e){let i=document.createEvent("Event");return i.initEvent("keydown",!0,!0),i.keyCode=t,i.key=i.code=e,i}const Ie="undefined"!=typeof navigator?navigator:null,ze="undefined"!=typeof document?document:null,je=Ie&&Ie.userAgent||"",_e=/Edge\/(\d+)/.exec(je),Fe=/MSIE \d/.exec(je),Be=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(je),We=!!(Fe||Be||_e),Je=Fe?document.documentMode:Be?+Be[1]:_e?+_e[1]:0,Le=!We&&/gecko\/(\d+)/i.test(je),Ye=!We&&/Chrome\/(\d+)/.exec(je),Xe=!!Ye,Ue=Ye?+Ye[1]:0,He=!We&&!!Ie&&/Apple Computer/.test(Ie.vendor),Ke=He&&(/Mobile\/\w+/.test(je)||!!Ie&&Ie.maxTouchPoints>2),qe=Ke||!!Ie&&/Mac/.test(Ie.platform),Ge=!!Ie&&/Win/.test(Ie.platform),Ve=/Android \d/.test(je),Ze=!!ze&&"webkitFontSmoothing"in ze.documentElement.style,Qe=Ze?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ti(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function ei(t,e){return"number"==typeof t?t:t[e]}function ii(t){let e=t.getBoundingClientRect();return{left:e.left,right:e.left+t.clientWidth*(e.width/t.offsetWidth||1),top:e.top,bottom:e.top+t.clientHeight*(e.height/t.offsetHeight||1)}}function si(t,e,i){let s=t.someProp("scrollThreshold")||0,r=t.someProp("scrollMargin")||5,n=t.dom.ownerDocument;for(let h=i||t.dom;h;){if(1!=h.nodeType){h=Oe(h);continue}let t=h,i=t==n.body,o=i?ti(n):ii(t),l=0,u=0;if(e.top<o.top+ei(s,"top")?u=-(o.top-e.top+ei(r,"top")):e.bottom>o.bottom-ei(s,"bottom")&&(u=e.bottom-e.top>o.bottom-o.top?e.top+ei(r,"top")-o.top:e.bottom-o.bottom+ei(r,"bottom")),e.left<o.left+ei(s,"left")?l=-(o.left-e.left+ei(r,"left")):e.right>o.right-ei(s,"right")&&(l=e.right-o.right+ei(r,"right")),l||u)if(i)n.defaultView.scrollBy(l,u);else{let i=t.scrollLeft,s=t.scrollTop;u&&(t.scrollTop+=u),l&&(t.scrollLeft+=l);let r=t.scrollLeft-i,n=t.scrollTop-s;e={left:e.left-r,top:e.top-n,right:e.right-r,bottom:e.bottom-n}}let f=i?"fixed":getComputedStyle(h).position;if(/^(fixed|sticky)$/.test(f))break;h="absolute"==f?h.offsetParent:Oe(h)}}function ri(t){let e=[],i=t.ownerDocument;for(let s=t;s&&(e.push({dom:s,top:s.scrollTop,left:s.scrollLeft}),t!=i);s=Oe(s));return e}function ni(t,e){for(let i=0;i<t.length;i++){let{dom:s,top:r,left:n}=t[i];s.scrollTop!=r+e&&(s.scrollTop=r+e),s.scrollLeft!=n&&(s.scrollLeft=n)}}let hi=null;function oi(t,e){let i,s,r,n,h=2e8,o=0,l=e.top,u=e.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=De(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>e.left?d.left-e.left:d.right<e.left?e.left-d.right:0;if(t<h){i=f,h=t,s=t&&3==i.nodeType?{left:d.right<e.left?d.right:d.left,top:e.top}:e,1==f.nodeType&&t&&(o=a+(e.left>=(d.left+d.right)/2?1:0));continue}}else d.top>e.top&&!r&&d.left<=e.left&&d.right>=e.left&&(r=f,n={left:Math.max(d.left,Math.min(d.right,e.left)),top:d.top});!i&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom)&&(o=a+1)}}return!i&&r&&(i=r,s=n,h=0),i&&3==i.nodeType?function(t,e){let i,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=ci(r,1);if(s.top!=s.bottom&&li(e,s)){i={node:t,offset:n+(e.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}(i,s):!i||h&&1==i.nodeType?{node:t,offset:o}:oi(i,s)}function li(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function ui(t,e,i){let s=t.childNodes.length;if(s&&i.top<i.bottom)for(let r=Math.max(0,Math.min(s-1,Math.floor(s*(e.top-i.top)/(i.bottom-i.top))-2)),n=r;;){let i=t.childNodes[n];if(1==i.nodeType){let t=i.getClientRects();for(let s=0;s<t.length;s++){let r=t[s];if(li(e,r))return ui(i,e,r)}}if((n=(n+1)%s)==r)break}return t}function fi(t,e){let i,s=t.dom.ownerDocument,r=0,n=function(t,e,i){if(t.caretPositionFromPoint)try{let s=t.caretPositionFromPoint(e,i);if(s)return{node:s.offsetNode,offset:Math.min($e(s.offsetNode),s.offset)}}catch(t){}if(t.caretRangeFromPoint){let s=t.caretRangeFromPoint(e,i);if(s)return{node:s.startContainer,offset:Math.min($e(s.startContainer),s.startOffset)}}}(s,e.left,e.top);n&&({node:i,offset:r}=n);let h,o=(t.root.elementFromPoint?t.root:s).elementFromPoint(e.left,e.top);if(!o||!t.dom.contains(1!=o.nodeType?o.parentNode:o)){let i=t.dom.getBoundingClientRect();if(!li(e,i))return null;if(o=ui(t.dom,e,i),!o)return null}if(He)for(let t=o;i&&t;t=Oe(t))t.draggable&&(i=void 0);if(o=function(t,e){let i=t.parentNode;return i&&/^li$/i.test(i.nodeName)&&e.left<t.getBoundingClientRect().left?i:t}(o,e),i){if(Le&&1==i.nodeType&&(r=Math.min(r,i.childNodes.length),r<i.childNodes.length)){let t,s=i.childNodes[r];"IMG"==s.nodeName&&(t=s.getBoundingClientRect()).right<=e.left&&t.bottom>e.top&&r++}let s;Ze&&r&&1==i.nodeType&&1==(s=i.childNodes[r-1]).nodeType&&"false"==s.contentEditable&&s.getBoundingClientRect().top>=e.top&&r--,i==t.dom&&r==i.childNodes.length-1&&1==i.lastChild.nodeType&&e.top>i.lastChild.getBoundingClientRect().bottom?h=t.state.doc.content.size:0!=r&&1==i.nodeType&&"BR"==i.childNodes[r-1].nodeName||(h=function(t,e,i,s){let r=-1;for(let i=e,n=!1;i!=t.dom;){let e,h=t.docView.nearestDesc(i,!0);if(!h)return null;if(1==h.dom.nodeType&&(h.node.isBlock&&h.parent||!h.contentDOM)&&((e=h.dom.getBoundingClientRect()).width||e.height)&&(h.node.isBlock&&h.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(h.dom.nodeName)&&(!n&&e.left>s.left||e.top>s.top?r=h.posBefore:(!n&&e.right<s.left||e.bottom<s.top)&&(r=h.posAfter),n=!0),!h.contentDOM&&r<0&&!h.node.isText))return(h.node.isBlock?s.top<(e.top+e.bottom)/2:s.left<(e.left+e.right)/2)?h.posBefore:h.posAfter;i=h.dom.parentNode}return r>-1?r:t.docView.posFromDOM(e,i,-1)}(t,i,r,e))}null==h&&(h=function(t,e,i){let{node:s,offset:r}=oi(e,i),n=-1;if(1==s.nodeType&&!s.firstChild){let t=s.getBoundingClientRect();n=t.left!=t.right&&i.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(s,r,n)}(t,o,e));let l=t.docView.nearestDesc(o,!0);return{pos:h,inside:l?l.posAtStart-l.border:-1}}function ai(t){return t.top<t.bottom||t.left<t.right}function ci(t,e){let i=t.getClientRects();if(i.length){let t=i[e<0?0:i.length-1];if(ai(t))return t}return Array.prototype.find.call(i,ai)||t.getBoundingClientRect()}const di=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function pi(t,e,i){let{node:s,offset:r,atom:n}=t.docView.domFromPos(e,i<0?-1:1),h=Ze||Le;if(3==s.nodeType){if(!h||!di.test(s.nodeValue)&&(i<0?r:r!=s.nodeValue.length)){let t=r,e=r,n=i<0?1:-1;return i<0&&!r?(e++,n=-1):i>=0&&r==s.nodeValue.length?(t--,n=1):i<0?t--:e++,mi(ci(De(s,t,e),n),n<0)}{let t=ci(De(s,r,r),i);if(Le&&r&&/\s/.test(s.nodeValue[r-1])&&r<s.nodeValue.length){let e=ci(De(s,r-1,r-1),-1);if(e.top==t.top){let i=ci(De(s,r,r+1),-1);if(i.top!=t.top)return mi(i,i.left<e.left)}}return t}}if(!t.state.doc.resolve(e-(n||0)).parent.inlineContent){if(null==n&&r&&(i<0||r==$e(s))){let t=s.childNodes[r-1];if(1==t.nodeType)return wi(t.getBoundingClientRect(),!1)}if(null==n&&r<$e(s)){let t=s.childNodes[r];if(1==t.nodeType)return wi(t.getBoundingClientRect(),!0)}return wi(s.getBoundingClientRect(),i>=0)}if(null==n&&r&&(i<0||r==$e(s))){let t=s.childNodes[r-1],e=3==t.nodeType?De(t,$e(t)-(h?0:1)):1!=t.nodeType||"BR"==t.nodeName&&t.nextSibling?null:t;if(e)return mi(ci(e,1),!1)}if(null==n&&r<$e(s)){let t=s.childNodes[r];for(;t.pmViewDesc&&t.pmViewDesc.ignoreForCoords;)t=t.nextSibling;let e=t?3==t.nodeType?De(t,0,h?0:1):1==t.nodeType?t:null:null;if(e)return mi(ci(e,-1),!0)}return mi(ci(3==s.nodeType?De(s):s,-i),i>=0)}function mi(t,e){if(0==t.width)return t;let i=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:i,right:i}}function wi(t,e){if(0==t.height)return t;let i=e?t.top:t.bottom;return{top:i,bottom:i,left:t.left,right:t.right}}function gi(t,e,i){let s=t.state,r=t.root.activeElement;s!=e&&t.updateState(e),r!=t.dom&&t.focus();try{return i()}finally{s!=e&&t.updateState(s),r!=t.dom&&r&&r.focus()}}const yi=/[\u0590-\u08ac]/;let bi=null,Mi=null,vi=!1;class ki{constructor(t,e,i,s){this.parent=t,this.children=e,this.dom=i,this.contentDOM=s,this.dirty=0,i.pmViewDesc=this}matchesWidget(t){return!1}matchesMark(t){return!1}matchesNode(t,e,i){return!1}matchesHack(t){return!1}parseRule(){return null}stopEvent(t){return!1}get size(){let t=0;for(let e=0;e<this.children.length;e++)t+=this.children[e].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 e=0,i=this.posAtStart;;e++){let s=this.children[e];if(s==t)return i;i+=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,e,i){if(this.contentDOM&&this.contentDOM.contains(1==t.nodeType?t:t.parentNode)){if(i<0){let i,s;if(t==this.contentDOM)i=t.childNodes[e-1];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.previousSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.previousSibling;return i?this.posBeforeChild(s)+s.size:this.posAtStart}{let i,s;if(t==this.contentDOM)i=t.childNodes[e];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.nextSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.nextSibling;return i?this.posBeforeChild(s):this.posAtEnd}}let s;if(t==this.dom&&this.contentDOM)s=e>xe(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==e)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!1;break}if(e.previousSibling)break}if(null==s&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!0;break}if(e.nextSibling)break}}return(null==s?i>0:s)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=!1){for(let i=!0,s=t;s;s=s.parentNode){let r,n=this.getDesc(s);if(n&&(!e||n.node)){if(!i||!(r=n.nodeDOM)||(1==r.nodeType?r.contains(1==t.nodeType?t:t.parentNode):r==t))return n;i=!1}}}getDesc(t){let e=t.pmViewDesc;for(let t=e;t;t=t.parent)if(t==this)return e}posFromDOM(t,e,i){for(let s=t;s;s=s.parentNode){let r=this.getDesc(s);if(r)return r.localPosFromDOM(t,e,i)}return-1}descAt(t){for(let e=0,i=0;e<this.children.length;e++){let s=this.children[e],r=i+s.size;if(i==t&&r!=i){for(;!s.border&&s.children.length;)for(let t=0;t<s.children.length;t++){let e=s.children[t];if(e.size){s=e;break}}return s}if(t<r)return s.descAt(t-i-s.border);i=r}}domFromPos(t,e){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let i=0,s=0;for(let e=0;i<this.children.length;i++){let r=this.children[i],n=e+r.size;if(n>t||r instanceof Ri){s=t-e;break}e=n}if(s)return this.children[i].domFromPos(s-this.children[i].border,e);for(let t;i&&!(t=this.children[i-1]).size&&t instanceof Si&&t.side>=0;i--);if(e<=0){let t,s=!0;for(;t=i?this.children[i-1]:null,t&&t.dom.parentNode!=this.contentDOM;i--,s=!1);return t&&e&&s&&!t.border&&!t.domAtom?t.domFromPos(t.size,e):{node:this.contentDOM,offset:t?xe(t.dom)+1:0}}{let t,s=!0;for(;t=i<this.children.length?this.children[i]:null,t&&t.dom.parentNode!=this.contentDOM;i++,s=!1);return t&&s&&!t.border&&!t.domAtom?t.domFromPos(0,e):{node:this.contentDOM,offset:t?xe(t.dom):this.contentDOM.childNodes.length}}}parseRange(t,e,i=0){if(0==this.children.length)return{node:this.contentDOM,from:t,to:e,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let s=-1,r=-1;for(let n=i,h=0;;h++){let i=this.children[h],o=n+i.size;if(-1==s&&t<=o){let r=n+i.border;if(t>=r&&e<=o-i.border&&i.node&&i.contentDOM&&this.contentDOM.contains(i.contentDOM))return i.parseRange(t,e,r);t=n;for(let e=h;e>0;e--){let i=this.children[e-1];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(1)){s=xe(i.dom)+1;break}t-=i.size}-1==s&&(s=0)}if(s>-1&&(o>e||h==this.children.length-1)){e=o;for(let t=h+1;t<this.children.length;t++){let i=this.children[t];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(-1)){r=xe(i.dom);break}e+=i.size}-1==r&&(r=this.contentDOM.childNodes.length);break}n=o}return{node:this.contentDOM,from:t,to:e,fromOffset:s,toOffset:r}}emptyChildAt(t){if(this.border||!this.contentDOM||!this.children.length)return!1;let e=this.children[t<0?0:this.children.length-1];return 0==e.size||e.emptyChildAt(t)}domAfterPos(t){let{node:e,offset:i}=this.domFromPos(t,0);if(1!=e.nodeType||i==e.childNodes.length)throw new RangeError("No node after pos "+t);return e.childNodes[i]}setSelection(t,e,i,s=!1){let r=Math.min(t,e),n=Math.max(t,e);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,e-o-l.border,i,s);o=u}let h=this.domFromPos(t,t?-1:1),o=e==t?h:this.domFromPos(e,e?-1:1),l=i.root.getSelection(),u=i.domSelectionRange(),f=!1;if((Le||He)&&t==e){let{node:t,offset:e}=h;if(3==t.nodeType){if(f=!(!e||"\n"!=t.nodeValue[e-1]),f&&e==t.nodeValue.length)for(let e,i=t;i;i=i.parentNode){if(e=i.nextSibling){"BR"==e.nodeName&&(h=o={node:e.parentNode,offset:xe(e)+1});break}let t=i.pmViewDesc;if(t&&t.node&&t.node.isBlock)break}}else{let i=t.childNodes[e-1];f=i&&("BR"==i.nodeName||"false"==i.contentEditable)}}if(Le&&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&&He)&&Ae(h.node,h.offset,u.anchorNode,u.anchorOffset)&&Ae(o.node,o.offset,u.focusNode,u.focusOffset))return;let a=!1;if((l.extend||t==e)&&(!f||!Le)){l.collapse(h.node,h.offset);try{t!=e&&l.extend(o.node,o.offset),a=!0}catch(t){}}if(!a){if(t>e){let t=h;h=o,o=t}let i=document.createRange();i.setEnd(o.node,o.offset),i.setStart(h.node,h.offset),l.removeAllRanges(),l.addRange(i)}}ignoreMutation(t){return!this.contentDOM&&"selection"!=t.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(t,e){for(let i=0,s=0;s<this.children.length;s++){let r=this.children[s],n=i+r.size;if(i==n?t<=n&&e>=i:t<n&&e>i){let s=i+r.border,h=n-r.border;if(t>=s&&e<=h)return this.dirty=t==i||e==n?2:1,void(t!=s||e!=h||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(t-s,e-s):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.children.length?3:2}i=n}this.dirty=2}markParentsDirty(){let t=1;for(let e=this.parent;e;e=e.parent,t++){let i=1==t?2:1;e.dirty<i&&(e.dirty=i)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(t){return!1}}class Si extends ki{constructor(t,e,i,s){let r,n=e.type.toDOM;if("function"==typeof n&&(n=n(i,(()=>r?r.parent?r.parent.posBeforeChild(r):void 0:s))),!e.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=e,this.widget=e,r=this}matchesWidget(t){return 0==this.dirty&&t.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(t){let e=this.widget.spec.stopEvent;return!!e&&e(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 xi extends ki{constructor(t,e,i,s){super(t,[],e,null),this.textDOM=i,this.text=s}get size(){return this.text.length}localPosFromDOM(t,e){return t!=this.textDOM?this.posAtStart+(e?this.size:0):this.posAtStart+e}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return"characterData"===t.type&&t.target.nodeValue==t.oldValue}}class Oi extends ki{constructor(t,e,i,s,r){super(t,[],i,s),this.mark=e,this.spec=r}static create(t,e,i,s){let r=s.nodeViews[e.type.name],n=r&&r(e,s,i);return n&&n.dom||(n=pt.renderSpec(document,e.type.spec.toDOM(e,i),null,e.attrs)),new Oi(t,e,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,e){if(super.markDirty(t,e),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,e,i){let s=Oi.create(this.parent,this.mark,!0,i),r=this.children,n=this.size;e<n&&(r=Ji(r,e,n,i)),t>0&&(r=Ji(r,0,t,i));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 Ti extends ki{constructor(t,e,i,s,r,n,h,o,l){super(t,[],r,n),this.node=e,this.outerDeco=i,this.innerDeco=s,this.nodeDOM=h}static create(t,e,i,s,r,n){let h,o=r.nodeViews[e.type.name],l=o&&o(e,r,(()=>h?h.parent?h.parent.posBeforeChild(h):void 0:n),i,s),u=l&&l.dom,f=l&&l.contentDOM;if(e.isText)if(u){if(3!=u.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else u=document.createTextNode(e.text);else if(!u){let t=pt.renderSpec(document,e.type.spec.toDOM(e),null,e.attrs);({dom:u,contentDOM:f}=t)}f||e.isText||"BR"==u.nodeName||(u.hasAttribute("contenteditable")||(u.contentEditable="false"),e.type.spec.draggable&&(u.draggable=!0));let a=u;return u=ji(u,i,e),l?h=new Ei(t,e,i,s,u,f||null,a,l,r,n+1):e.isText?new Ai(t,e,i,s,u,a,r):new Ti(t,e,i,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 e=this.children.length-1;e>=0;e--){let i=this.children[e];if(this.dom.contains(i.dom.parentNode)){t.contentElement=i.dom.parentNode;break}}t.contentElement||(t.getContent=()=>d.empty)}else t.contentElement=this.contentDOM;else t.getContent=()=>this.node.content;return t}matchesNode(t,e,i){return 0==this.dirty&&t.eq(this.node)&&_i(e,this.outerDeco)&&i.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(t,e){let i=this.node.inlineContent,s=e,r=t.composing?this.localCompositionInfo(t,e):null,n=r&&r.pos>-1?r:null,h=r&&r.pos<0,o=new Bi(this,n&&n.node,t);!function(t,e,i,s){let r=e.locals(t),n=0;if(0==r.length){for(let i=0;i<t.childCount;i++){let h=t.child(i);s(h,r,e.forChild(n,h),i),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(Wi);for(let t=0;t<a.length;t++)i(a[t],u,!!l)}else i(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 e=0;e<o.length;e++)o[e].to<t&&(t=o[e].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(),e.forChild(n,c),d),n=p}}(this.node,this.innerDeco,((e,r,n)=>{e.spec.marks?o.syncToMarks(e.spec.marks,i,t,r):e.type.side>=0&&!n&&o.syncToMarks(r==this.node.childCount?g.none:this.node.child(r).marks,i,t,r),o.placeWidget(e,t,s)}),((e,n,l,u)=>{let f;o.syncToMarks(e.marks,i,t,u),o.findNodeMatch(e,n,l,u)||h&&t.state.selection.from>s&&t.state.selection.to<s+e.nodeSize&&(f=o.findIndexWithChild(r.node))>-1&&o.updateNodeAt(e,n,l,f,t)||o.updateNextNode(e,n,l,t,u,s)||o.addNode(e,n,l,t,s),s+=e.nodeSize})),o.syncToMarks([],i,t,0),this.node.isTextblock&&o.addTextblockHacks(),o.destroyRest(),(o.changed||2==this.dirty)&&(n&&this.protectLocalComposition(t,n),$i(this.contentDOM,this.children,t),Ke&&function(t){if("UL"==t.nodeName||"OL"==t.nodeName){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t),t.style.cssText=e}}(this.dom))}localCompositionInfo(t,e){let{from:i,to:s}=t.state.selection;if(!(t.state.selection instanceof oe)||i<e||s>e+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,e,i,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 e=t.child(r++);if(n+=e.nodeSize,!e.isText)break;l+=e.text}if(n>=i){if(n>=s&&l.slice(s-e.length-o,s-o)==e)return s-e.length;let t=o<s?l.lastIndexOf(e,s-o-1):-1;if(t>=0&&t+e.length+o>=i)return o+t;if(i==s&&l.length>=s+e.length-o&&l.slice(s-o,s-o+e.length)==e)return s}}return-1}(this.node.content,t,i-e,s-e);return n<0?null:{node:r,pos:n,text:t}}return{node:r,pos:-1,text:""}}protectLocalComposition(t,{node:e,pos:i,text:s}){if(this.getDesc(e))return;let r=e;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 xi(this,r,e,s);t.input.compositionNodes.push(n),this.children=Ji(this.children,i,i+s.length,t,n)}update(t,e,i,s){return!(3==this.dirty||!t.sameMarkup(this.node)||(this.updateInner(t,e,i,s),0))}updateInner(t,e,i,s){this.updateOuterDeco(e),this.node=t,this.innerDeco=i,this.contentDOM&&this.updateChildren(s,this.posAtStart),this.dirty=0}updateOuterDeco(t){if(_i(t,this.outerDeco))return;let e=1!=this.nodeDOM.nodeType,i=this.dom;this.dom=Ii(this.dom,this.nodeDOM,Ni(this.outerDeco,this.node,e),Ni(t,this.node,e)),this.dom!=i&&(i.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 Di(t,e,i,s,r){ji(s,e,t);let n=new Ti(void 0,t,e,i,s,s,s,r,0);return n.contentDOM&&n.updateChildren(r,0),n}class Ai extends Ti{constructor(t,e,i,s,r,n,h){super(t,e,i,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,e,i,s){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!t.sameMarkup(this.node)||(this.updateOuterDeco(e),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 e=this.nodeDOM;e;e=e.parentNode)if(e==t)return!0;return!1}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,e,i){return t==this.nodeDOM?this.posAtStart+Math.min(e,this.node.text.length):super.localPosFromDOM(t,e,i)}ignoreMutation(t){return"characterData"!=t.type&&"selection"!=t.type}slice(t,e,i){let s=this.node.cut(t,e),r=document.createTextNode(s.text);return new Ai(this.parent,s,this.outerDeco,this.innerDeco,r,r,i)}markDirty(t,e){super.markDirty(t,e),this.dom==this.nodeDOM||0!=t&&e!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}isText(t){return this.node.text==t}}class Ri extends ki{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 Ei extends Ti{constructor(t,e,i,s,r,n,h,o,l,u){super(t,e,i,s,r,n,h,l,u),this.spec=o}update(t,e,i,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,e,i);return r&&this.updateInner(t,e,i,s),r}return!(!this.contentDOM&&!t.isLeaf)&&super.update(t,e,i,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,e,i,s){this.spec.setSelection?this.spec.setSelection(t,e,i.root):super.setSelection(t,e,i,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 $i(t,e,i){let s=t.firstChild,r=!1;for(let n=0;n<e.length;n++){let h=e[n],o=h.dom;if(o.parentNode==t){for(;o!=s;)s=Fi(s),r=!0;s=s.nextSibling}else r=!0,t.insertBefore(o,s);if(h instanceof Oi){let e=s?s.previousSibling:t.lastChild;$i(h.contentDOM,h.children,i),s=e?e.nextSibling:t.firstChild}}for(;s;)s=Fi(s),r=!0;r&&i.trackWrites==t&&(i.trackWrites=null)}const Pi=function(t){t&&(this.nodeName=t)};Pi.prototype=Object.create(null);const Ci=[new Pi];function Ni(t,e,i){if(0==t.length)return Ci;let s=i?Ci[0]:new Pi,r=[s];for(let n=0;n<t.length;n++){let h=t[n].type.attrs;if(h){h.nodeName&&r.push(s=new Pi(h.nodeName));for(let t in h){let n=h[t];null!=n&&(i&&1==r.length&&r.push(s=new Pi(e.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 Ii(t,e,i,s){if(i==Ci&&s==Ci)return e;let r=e;for(let e=0;e<s.length;e++){let n=s[e],h=i[e];if(e){let e;h&&h.nodeName==n.nodeName&&r!=t&&(e=r.parentNode)&&e.nodeName.toLowerCase()==n.nodeName||(e=document.createElement(n.nodeName),e.pmIsDeco=!0,e.appendChild(r),h=Ci[0]),r=e}zi(r,h||Ci[0],n)}return r}function zi(t,e,i){for(let s in e)"class"==s||"style"==s||"nodeName"==s||s in i||t.removeAttribute(s);for(let s in i)"class"!=s&&"style"!=s&&"nodeName"!=s&&i[s]!=e[s]&&t.setAttribute(s,i[s]);if(e.class!=i.class){let s=e.class?e.class.split(" ").filter(Boolean):[],r=i.class?i.class.split(" ").filter(Boolean):[];for(let e=0;e<s.length;e++)-1==r.indexOf(s[e])&&t.classList.remove(s[e]);for(let e=0;e<r.length;e++)-1==s.indexOf(r[e])&&t.classList.add(r[e]);0==t.classList.length&&t.removeAttribute("class")}if(e.style!=i.style){if(e.style){let i,s=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;i=s.exec(e.style);)t.style.removeProperty(i[1])}i.style&&(t.style.cssText+=i.style)}}function ji(t,e,i){return Ii(t,t,Ci,Ni(e,i,1!=t.nodeType))}function _i(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].type.eq(e[i].type))return!1;return!0}function Fi(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class Bi{constructor(t,e,i){this.lock=e,this.view=i,this.index=0,this.stack=[],this.changed=!1,this.top=t,this.preMatch=function(t,e){let i=e,s=i.children.length,r=t.childCount,n=new Map,h=[];t:for(;r>0;){let o;for(;;)if(s){let t=i.children[s-1];if(!(t instanceof Oi)){o=t,s--;break}i=t,s=t.children.length}else{if(i==e)break t;s=i.parent.children.indexOf(i),i=i.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,e){if(t!=e){for(let i=t;i<e;i++)this.top.children[i].destroy();this.top.children.splice(t,e-t),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(t,e,i,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 e=this.index;e<h;e++){let i=this.top.children[e];if(i.matchesMark(t[n])&&!this.isLocked(i.dom)){r=e;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=Oi.create(this.top,t[n],e,i);this.top.children.splice(this.index,0,s),this.top=s,this.changed=!0}this.index=0,n++}}findNodeMatch(t,e,i,s){let r,n=-1;if(s>=this.preMatch.index&&(r=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&r.matchesNode(t,e,i))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,e,i)&&!this.preMatch.matched.has(r)){n=s;break}}return!(n<0||(this.destroyBetween(this.index,n),this.index++,0))}updateNodeAt(t,e,i,s,r){let n=this.top.children[s];return 3==n.dirty&&n.dom==n.contentDOM&&(n.dirty=2),!!n.update(t,e,i,r)&&(this.destroyBetween(this.index,s),this.index++,!0)}findIndexWithChild(t){for(;;){let e=t.parentNode;if(!e)return-1;if(e==this.top.contentDOM){let e=t.pmViewDesc;if(e)for(let t=this.index;t<this.top.children.length;t++)if(this.top.children[t]==e)return t;return-1}t=e}}updateNextNode(t,e,i,s,r,n){for(let h=this.index;h<this.top.children.length;h++){let o=this.top.children[h];if(o instanceof Ti){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&&_i(e,o.outerDeco));if(!a&&o.update(t,e,i,s))return this.destroyBetween(this.index,h),o.dom!=f&&(this.changed=!0),this.index++,!0;if(!a&&(u=this.recreateWrapper(o,t,e,i,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,e,i,s,r,n){if(t.dirty||e.isAtom||!t.children.length||!t.node.content.eq(e.content)||!_i(i,t.outerDeco)||!s.eq(t.innerDeco))return null;let h=Ti.create(this.top,e,i,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,e,i,s,r){let n=Ti.create(this.top,t,e,i,s,r);n.contentDOM&&n.updateChildren(s,r+1),this.top.children.splice(this.index++,0,n),this.changed=!0}placeWidget(t,e,i){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 Si(this.top,t,e,i);this.top.children.splice(this.index++,0,s),this.changed=!0}else this.index++}addTextblockHacks(){let t=this.top.children[this.index-1],e=this.top;for(;t instanceof Oi;)e=t,t=e.children[e.children.length-1];(!t||!(t instanceof Ai)||/\n$/.test(t.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(t.node.text))&&((He||Xe)&&t&&"false"==t.dom.contentEditable&&this.addHackNode("IMG",e),this.addHackNode("BR",this.top))}addHackNode(t,e){if(e==this.top&&this.index<e.children.length&&e.children[this.index].matchesHack(t))this.index++;else{let i=document.createElement(t);"IMG"==t&&(i.className="ProseMirror-separator",i.alt=""),"BR"==t&&(i.className="ProseMirror-trailingBreak");let s=new Ri(this.top,[],i,null);e!=this.top?e.children.push(s):e.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 Wi(t,e){return t.type.side-e.type.side}function Ji(t,e,i,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>=i||f<=e?n.push(l):(u<e&&n.push(l.slice(0,e-u,s)),r&&(n.push(r),r=void 0),f>i&&n.push(l.slice(i-u,l.size,s)))}return n}function Li(t,e=null){let i=t.domSelectionRange(),s=t.state.doc;if(!i.focusNode)return null;let r=t.docView.nearestDesc(i.focusNode),n=r&&0==r.size,h=t.docView.posFromDOM(i.focusNode,i.focusOffset,1);if(h<0)return null;let o,l,u=s.resolve(h);if(Ce(i)){for(o=h;r&&!r.node;)r=r.parent;let t=r.node;if(r&&t.isAtom&&ue.isSelectable(t)&&r.parent&&(!t.isInline||!function(t,e,i){for(let s=0==e,r=e==$e(t);s||r;){if(t==i)return!0;let e=xe(t);if(!(t=t.parentNode))return!1;s=s&&0==e,r=r&&e==$e(t)}}(i.focusNode,i.focusOffset,r.dom))){let t=r.posBefore;l=new ue(h==t?u:s.resolve(t))}}else{if(i instanceof t.dom.ownerDocument.defaultView.Selection&&i.rangeCount>1){let e=h,r=h;for(let s=0;s<i.rangeCount;s++){let n=i.getRangeAt(s);e=Math.min(e,t.docView.posFromDOM(n.startContainer,n.startOffset,1)),r=Math.max(r,t.docView.posFromDOM(n.endContainer,n.endOffset,-1))}if(e<0)return null;[o,h]=r==t.state.selection.anchor?[r,e]:[e,r],u=s.resolve(h)}else o=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1);if(o<0)return null}let f=s.resolve(o);return l||(l=Zi(t,f,u,"pointer"==e||t.state.selection.head<u.pos&&!n?1:-1)),l}function Yi(t){return t.editable?t.hasFocus():ts(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function Xi(t,e=!1){let i=t.state.selection;if(Gi(t,i),Yi(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Xe){let e=t.domSelectionRange(),i=t.domObserver.currentSelection;if(e.anchorNode&&i.anchorNode&&Ae(e.anchorNode,e.anchorOffset,i.anchorNode,i.anchorOffset))return t.input.mouseDown.delayedSelectionSync=!0,void t.domObserver.setCurSelection()}if(t.domObserver.disconnectSelection(),t.cursorWrapper)!function(t){let e=t.domSelection();if(!e)return;let i=t.cursorWrapper.dom,s="IMG"==i.nodeName;s?e.collapse(i.parentNode,xe(i)+1):e.collapse(i,0),!s&&!t.state.selection.visible&&We&&Je<=11&&(i.disabled=!0,i.disabled=!1)}(t);else{let s,r,{anchor:n,head:h}=i;!Ui||i instanceof oe||(i.$from.parent.inlineContent||(s=Hi(t,i.from)),i.empty||i.$from.parent.inlineContent||(r=Hi(t,i.to))),t.docView.setSelection(n,h,t,e),Ui&&(s&&qi(s),r&&qi(r)),i.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let i=t.domSelectionRange(),s=i.anchorNode,r=i.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{i.anchorNode==s&&i.anchorOffset==r||(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout((()=>{Yi(t)&&!t.state.selection.visible||t.dom.classList.remove("ProseMirror-hideselection")}),20))})}(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}const Ui=He||Xe&&Ue<63;function Hi(t,e){let{node:i,offset:s}=t.docView.domFromPos(e,0),r=s<i.childNodes.length?i.childNodes[s]:null,n=s?i.childNodes[s-1]:null;if(He&&r&&"false"==r.contentEditable)return Ki(r);if(!(r&&"false"!=r.contentEditable||n&&"false"!=n.contentEditable)){if(r)return Ki(r);if(n)return Ki(n)}}function Ki(t){return t.contentEditable="true",He&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function qi(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function Gi(t,e){if(e instanceof ue){let i=t.docView.descAt(e.from);i!=t.lastSelectedViewDesc&&(Vi(t),i&&i.selectNode(),t.lastSelectedViewDesc=i)}else Vi(t)}function Vi(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Zi(t,e,i,s){return t.someProp("createSelectionBetween",(s=>s(t,e,i)))||oe.between(e,i,s)}function Qi(t){return!(t.editable&&!t.hasFocus())&&ts(t)}function ts(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(3==e.anchorNode.nodeType?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(3==e.focusNode.nodeType?e.focusNode.parentNode:e.focusNode))}catch(t){return!1}}function es(t,e){let{$anchor:i,$head:s}=t.selection,r=e>0?i.max(s):i.min(s),n=r.parent.inlineContent?r.depth?t.doc.resolve(e>0?r.after():r.before()):null:r;return n&&se.findFrom(n,e)}function is(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function ss(t,e,i){let s=t.state.selection;if(!(s instanceof oe)){if(s instanceof ue&&s.node.isInline)return is(t,new oe(e>0?s.$to:s.$from));{let i=es(t.state,e);return!!i&&is(t,i)}}if(i.indexOf("s")>-1){let{$head:i}=s,r=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let n=t.state.doc.resolve(i.pos+r.nodeSize*(e<0?-1:1));return is(t,new oe(s.$anchor,n))}if(!s.empty)return!1;if(t.endOfTextblock(e>0?"forward":"backward")){let i=es(t.state,e);return!!(i&&i instanceof ue)&&is(t,i)}if(!(qe&&i.indexOf("m")>-1)){let i,r=s.$head,n=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!n||n.isText)return!1;let h=e<0?r.pos-n.nodeSize:r.pos;return!!(n.isAtom||(i=t.docView.descAt(h))&&!i.contentDOM)&&(ue.isSelectable(n)?is(t,new ue(e<0?t.state.doc.resolve(r.pos-n.nodeSize):r)):!!Ze&&is(t,new oe(t.state.doc.resolve(e<0?h:h+n.nodeSize))))}}function rs(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function ns(t,e){let i=t.pmViewDesc;return i&&0==i.size&&(e<0||t.nextSibling||"BR"!=t.nodeName)}function hs(t,e){return e<0?function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,h=!1;for(Le&&1==i.nodeType&&s<rs(i)&&ns(i.childNodes[s],-1)&&(h=!0);;)if(s>0){if(1!=i.nodeType)break;{let t=i.childNodes[s-1];if(ns(t,-1))r=i,n=--s;else{if(3!=t.nodeType)break;i=t,s=i.nodeValue.length}}}else{if(ls(i))break;{let e=i.previousSibling;for(;e&&ns(e,-1);)r=i.parentNode,n=xe(e),e=e.previousSibling;if(e)i=e,s=rs(i);else{if(i=i.parentNode,i==t.dom)break;s=0}}}h?us(t,i,s):r&&us(t,r,n)}(t):function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,h=rs(i);for(;;)if(s<h){if(1!=i.nodeType)break;if(!ns(i.childNodes[s],1))break;r=i,n=++s}else{if(ls(i))break;{let e=i.nextSibling;for(;e&&ns(e,1);)r=e.parentNode,n=xe(e)+1,e=e.nextSibling;if(e)i=e,s=0,h=rs(i);else{if(i=i.parentNode,i==t.dom)break;s=h=0}}}r&&us(t,r,n)}(t)}function ls(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function us(t,e,i){if(3!=e.nodeType){let t,s;(s=function(t,e){for(;t&&e==t.childNodes.length&&!Pe(t);)e=xe(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let i=t.childNodes[e];if(3==i.nodeType)return i;if(1==i.nodeType&&"false"==i.contentEditable)break;t=i,e=0}}(e,i))?(e=s,i=0):(t=function(t,e){for(;t&&!e&&!Pe(t);)e=xe(t),t=t.parentNode;for(;t&&e;){let i=t.childNodes[e-1];if(3==i.nodeType)return i;if(1==i.nodeType&&"false"==i.contentEditable)break;e=(t=i).childNodes.length}}(e,i))&&(e=t,i=t.nodeValue.length)}let s=t.domSelection();if(!s)return;if(Ce(s)){let t=document.createRange();t.setEnd(e,i),t.setStart(e,i),s.removeAllRanges(),s.addRange(t)}else s.extend&&s.extend(e,i);t.domObserver.setCurSelection();let{state:r}=t;setTimeout((()=>{t.state==r&&Xi(t)}),50)}function fs(t,e){let i=t.state.doc.resolve(e);if(!Xe&&!Ge&&i.parent.inlineContent){let s=t.coordsAtPos(e);if(e>i.start()){let i=t.coordsAtPos(e-1),r=(i.top+i.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(i.left-s.left)>1)return i.left<s.left?"ltr":"rtl"}if(e<i.end()){let i=t.coordsAtPos(e+1),r=(i.top+i.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(i.left-s.left)>1)return i.left>s.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(t.dom).direction?"rtl":"ltr"}function as(t,e,i){let s=t.state.selection;if(s instanceof oe&&!s.empty||i.indexOf("s")>-1)return!1;if(qe&&i.indexOf("m")>-1)return!1;let{$from:r,$to:n}=s;if(!r.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=es(t.state,e);if(i&&i instanceof ue)return is(t,i)}if(!r.parent.inlineContent){let i=e<0?r:n,h=s instanceof ae?se.near(i,e):se.findFrom(i,e);return!!h&&is(t,h)}return!1}function cs(t,e){if(!(t.state.selection instanceof oe))return!0;let{$head:i,$anchor:s,empty:r}=t.state.selection;if(!i.sameParent(s))return!0;if(!r)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let n=!i.textOffset&&(e<0?i.nodeBefore:i.nodeAfter);if(n&&!n.isText){let s=t.state.tr;return e<0?s.delete(i.pos-n.nodeSize,i.pos):s.delete(i.pos,i.pos+n.nodeSize),t.dispatch(s),!0}return!1}function ds(t,e,i){t.domObserver.stop(),e.contentEditable=i,t.domObserver.start()}function ps(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:s,openStart:r,openEnd:n}=e;for(;r>1&&n>1&&1==s.childCount&&1==s.firstChild.childCount;){r--,n--;let t=s.firstChild;i.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 e=o.createElement(u[t]);for(;l.firstChild;)e.appendChild(l.firstChild);l.appendChild(e),a++}f=l.firstChild}return f&&1==f.nodeType&&f.setAttribute("data-pm-slice",`${r} ${n}${a?` -${a}`:""} ${JSON.stringify(i)}`),{dom:l,text:t.someProp("clipboardTextSerializer",(i=>i(e,t)))||e.content.textBetween(0,e.content.size,"\n\n"),slice:e}}function ms(t,e,i,s,r){let n,h,o=r.parent.type.spec.code;if(!i&&!e)return null;let l=!!e&&(s||o||!i);if(l){if(t.someProp("transformPastedText",(i=>{e=i(e,o||s,t)})),o)return h=new b(d.from(t.state.schema.text(e.replace(/\r\n?/g,"\n"))),0,0),t.someProp("transformPasted",(e=>{h=e(h,t,!0)})),h;let i=t.someProp("clipboardTextParser",(i=>i(e,r,s,t)));if(i)h=i;else{let i=r.marks(),{schema:s}=t.state,h=pt.fromSchema(s);n=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=n.appendChild(document.createElement("p"));t&&e.appendChild(h.serializeNode(s.text(t,i)))}))}}else t.someProp("transformPastedHTML",(e=>{i=e(i,t)})),n=function(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let i,s=xs().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t);if((i=r&&ks[r[1].toLowerCase()])&&(t=i.map((t=>"<"+t+">")).join("")+t+i.map((t=>"</"+t+">")).reverse().join("")),s.innerHTML=function(t){let e=window.trustedTypes;return e?(Os||(Os=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Os.createHTML(t)):t}(t),i)for(let t=0;t<i.length;t++)s=s.querySelector(i[t])||s;return s}(i),Ze&&function(t){let e=t.querySelectorAll(Xe?"span:not([class]):not([style])":"span.Apple-converted-space");for(let i=0;i<e.length;i++){let s=e[i];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 e=t.someProp("clipboardParser")||t.someProp("domParser")||rt.fromSchema(t.state.schema);h=e.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,e){if(!t.size)return t;let i,s=t.content.firstChild.type.schema;try{i=JSON.parse(e)}catch(e){return t}let{content:r,openStart:n,openEnd:h}=t;for(let t=i.length-2;t>=0;t-=2){let e=s.nodes[i[t]];if(!e||e.hasRequiredAttrs())break;r=d.from(e.create(i[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,e){if(t.childCount<2)return t;for(let i=e.depth;i>=0;i--){let s,r=e.node(i).contentMatchAt(e.index(i)),n=[];if(t.forEach((t=>{if(!n)return;let e,i=r.findWrapping(t.type);if(!i)return n=null;if(e=n.length&&s.length&&ys(i,s,t,n[n.length-1],0))n[n.length-1]=e;else{n.length&&(n[n.length-1]=bs(n[n.length-1],s.length));let e=gs(t,i);n.push(e),r=r.matchType(e.type),s=i}})),n)return d.from(n)}return t}(h.content,r),!0),h.openStart||h.openEnd){let t=0,e=0;for(let e=h.content.firstChild;t<h.openStart&&!e.type.spec.isolating;t++,e=e.firstChild);for(let t=h.content.lastChild;e<h.openEnd&&!t.type.spec.isolating;e++,t=t.lastChild);h=vs(h,t,e)}return t.someProp("transformPasted",(e=>{h=e(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,e,i=0){for(let s=e.length-1;s>=i;s--)t=e[s].create(null,d.from(t));return t}function ys(t,e,i,s,r){if(r<t.length&&r<e.length&&t[r]==e[r]){let n=ys(t,e,i,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?i.type:t[r+1]))return s.copy(s.content.append(d.from(gs(i,t,r+1))))}}function bs(t,e){if(0==e)return t;let i=t.content.replaceChild(t.childCount-1,bs(t.lastChild,e-1)),s=t.contentMatchAt(t.childCount).fillBefore(d.empty,!0);return t.copy(i.append(s))}function Ms(t,e,i,s,r,n){let h=e<0?t.firstChild:t.lastChild,o=h.content;return t.childCount>1&&(n=0),r<s-1&&(o=Ms(o,e,i,s,r+1,n)),r>=i&&(o=e<0?h.contentMatchAt(0).fillBefore(o,n<=r).append(o):o.append(h.contentMatchAt(h.childCount).fillBefore(d.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,h.copy(o))}function vs(t,e,i){return e<t.openStart&&(t=new b(Ms(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),i<t.openEnd&&(t=new b(Ms(t.content,1,i,t.openEnd,0,0),t.openStart,i)),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,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function $s(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)t.input.eventHandlers[i]||t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>Ps(t,e))}))}function Ps(t,e){return t.someProp("handleDOMEvents",(i=>{let s=i[e.type];return!!s&&(s(t,e)||e.defaultPrevented)}))}function Cs(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i=e.target;i!=t.dom;i=i.parentNode)if(!i||11==i.nodeType||i.pmViewDesc&&i.pmViewDesc.stopEvent(e))return!1;return!0}function Ns(t){return{left:t.clientX,top:t.clientY}}function Is(t,e,i,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(e,(e=>s>n.depth?e(t,i,n.nodeAfter,n.before(s),r,!0):e(t,i,n.node(s),n.before(s),r,!1))))return!0;return!1}function zs(t,e){if(t.focused||t.focus(),t.state.selection.eq(e))return;let i=t.state.tr.setSelection(e);i.setMeta("pointer",!0),t.dispatch(i)}function js(t,e,i,s){return Is(t,"handleDoubleClickOn",e,i,s)||t.someProp("handleDoubleClick",(i=>i(t,e,s)))}function _s(t,e,i,s){return Is(t,"handleTripleClickOn",e,i,s)||t.someProp("handleTripleClick",(i=>i(t,e,s)))||function(t,e,i){if(0!=i.button)return!1;let s=t.state.doc;if(-1==e)return!!s.inlineContent&&(zs(t,oe.create(s,0,s.content.size)),!0);let r=s.resolve(e);for(let e=r.depth+1;e>0;e--){let i=e>r.depth?r.nodeAfter:r.node(e),n=r.before(e);if(i.inlineContent)zs(t,oe.create(s,n+1,n+1+i.content.size));else{if(!ue.isSelectable(i))continue;zs(t,ue.create(s,n))}return!0}}(t,i,s)}function Fs(t){return Us(t)}Ds.keydown=(t,e)=>{let i=e;if(t.input.shiftKey=16==i.keyCode||i.shiftKey,!Js(t,i)&&(t.input.lastKeyCode=i.keyCode,t.input.lastKeyCodeTime=Date.now(),!Ve||!Xe||13!=i.keyCode))if(229!=i.keyCode&&t.domObserver.forceFlush(),!Ke||13!=i.keyCode||i.ctrlKey||i.altKey||i.metaKey)t.someProp("handleKeyDown",(e=>e(t,i)))||function(t,e){let i=e.keyCode,s=function(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}(e);if(8==i||qe&&72==i&&"c"==s)return cs(t,-1)||hs(t,-1);if(46==i&&!e.shiftKey||qe&&68==i&&"c"==s)return cs(t,1)||hs(t,1);if(13==i||27==i)return!0;if(37==i||qe&&66==i&&"c"==s){let e=37==i?"ltr"==fs(t,t.state.selection.from)?-1:1:-1;return ss(t,e,s)||hs(t,e)}if(39==i||qe&&70==i&&"c"==s){let e=39==i?"ltr"==fs(t,t.state.selection.from)?1:-1:1;return ss(t,e,s)||hs(t,e)}return 38==i||qe&&80==i&&"c"==s?as(t,-1,s)||hs(t,-1):40==i||qe&&78==i&&"c"==s?function(t){if(!He||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(e&&1==e.nodeType&&0==i&&e.firstChild&&"false"==e.firstChild.contentEditable){let i=e.firstChild;ds(t,i,"true"),setTimeout((()=>ds(t,i,"false")),20)}return!1}(t)||as(t,1,s)||hs(t,1):s==(qe?"m":"c")&&(66==i||73==i||89==i||90==i)}(t,i)?i.preventDefault():Es(t,"key");else{let e=Date.now();t.input.lastIOSEnter=e,t.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{t.input.lastIOSEnter==e&&(t.someProp("handleKeyDown",(e=>e(t,Ne(13,"Enter")))),t.input.lastIOSEnter=0)}),200)}},Ds.keyup=(t,e)=>{16==e.keyCode&&(t.input.shiftKey=!1)},Ds.keypress=(t,e)=>{let i=e;if(Js(t,i)||!i.charCode||i.ctrlKey&&!i.altKey||qe&&i.metaKey)return;if(t.someProp("handleKeyPress",(e=>e(t,i))))return void i.preventDefault();let s=t.state.selection;if(!(s instanceof oe&&s.$from.sameParent(s.$to))){let e=String.fromCharCode(i.charCode),r=()=>t.state.tr.insertText(e).scrollIntoView();/[\r\n]/.test(e)||t.someProp("handleTextInput",(i=>i(t,s.$from.pos,s.$to.pos,e,r)))||t.dispatch(r()),i.preventDefault()}};const Bs=qe?"metaKey":"ctrlKey";Ts.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let s=Fs(t),r=Date.now(),n="singleClick";r-t.input.lastClick.time<500&&function(t,e){let i=e.x-t.clientX,s=e.y-t.clientY;return i*i+s*s<100}(i,t.input.lastClick)&&!i[Bs]&&t.input.lastClick.button==i.button&&("singleClick"==t.input.lastClick.type?n="doubleClick":"doubleClick"==t.input.lastClick.type&&(n="tripleClick")),t.input.lastClick={time:r,x:i.clientX,y:i.clientY,type:n,button:i.button};let h=t.posAtCoords(Ns(i));h&&("singleClick"==n?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Ws(t,h,i,!!s)):("doubleClick"==n?js:_s)(t,h.pos,h.inside,i)?i.preventDefault():Es(t,"pointer"))};class Ws{constructor(t,e,i,s){let r,n;if(this.view=t,this.pos=e,this.event=i,this.flushed=s,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!i[Bs],this.allowDefault=i.shiftKey,e.inside>-1)r=t.state.doc.nodeAt(e.inside),n=e.inside;else{let i=t.state.doc.resolve(e.pos);r=i.parent,n=i.depth?i.before():0}const h=s?null:i.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==i.button&&(r.type.spec.draggable&&!1!==r.type.spec.selectable||l instanceof ue&&l.from<=n&&l.to>n)&&(this.mightDrag={node:r,pos:n,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!Le||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((()=>Xi(this.view))),this.view.input.mouseDown=null}up(t){if(this.done(),!this.view.dom.contains(t.target))return;let e=this.pos;this.view.state.doc!=this.startDoc&&(e=this.view.posAtCoords(Ns(t))),this.updateAllowDefault(t),this.allowDefault||!e?Es(this.view,"pointer"):function(t,e,i,s,r){return Is(t,"handleClickOn",e,i,s)||t.someProp("handleClick",(i=>i(t,e,s)))||(r?function(t,e){if(-1==e)return!1;let i,s,r=t.state.selection;r instanceof ue&&(i=r.node);let n=t.state.doc.resolve(e);for(let t=n.depth+1;t>0;t--){let e=t>n.depth?n.nodeAfter:n.node(t);if(ue.isSelectable(e)){s=i&&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,ue.create(t.state.doc,s)),!0)}(t,i):function(t,e){if(-1==e)return!1;let i=t.state.doc.resolve(e),s=i.nodeAfter;return!!(s&&s.isAtom&&ue.isSelectable(s))&&(zs(t,new ue(i)),!0)}(t,i))}(this.view,e.pos,e.inside,t,this.selectNode)?t.preventDefault():0==t.button&&(this.flushed||He&&this.mightDrag&&!this.mightDrag.node.isAtom||Xe&&!this.view.state.selection.visible&&Math.min(Math.abs(e.pos-this.view.state.selection.from),Math.abs(e.pos-this.view.state.selection.to))<=2)?(zs(this.view,se.near(this.view.state.doc.resolve(e.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,e){return!!t.composing||!!(He&&Math.abs(e.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=Ve?5e3:-1;function Ys(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout((()=>Us(t)),e))}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,e=!1){if(!(Ve&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Xs(t),e||t.docView&&t.docView.dirty){let i=Li(t),s=t.state.selection;return i&&!i.eq(s)?t.dispatch(t.state.tr.setSelection(i)):!t.markCursor&&!e||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:e}=t,i=e.selection.$to;if(e.selection instanceof oe&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))||Xe&&Ge&&function(t){let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(!e||1!=e.nodeType||i>=e.childNodes.length)return!1;let s=e.childNodes[i];return 1==s.nodeType&&"false"==s.contentEditable}(t)))t.markCursor=t.state.storedMarks||i.marks(),Us(t,!0),t.markCursor=null;else if(Us(t,!e.selection.empty),Le&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,s=e.focusOffset;i&&1==i.nodeType&&0!=s;){let e=s<0?i.lastChild:i.childNodes[s-1];if(!e)break;if(3==e.nodeType){let i=t.domSelection();i&&i.collapse(e,e.nodeValue.length);break}i=e,s=-1}}t.input.composing=!0}Ys(t,Ls)},Ds.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.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=We&&Je<15||Ke&&Qe<604;function Ks(t,e,i,s,r){let n=ms(t,e,i,s,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(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 e=t.getData("text/plain")||t.getData("Text");if(e)return e;let i=t.getData("text/uri-list");return i?i.replace(/\r?\n/g," "):""}Ts.copy=Ds.cut=(t,e)=>{let i=e,s=t.state.selection,r="cut"==i.type;if(s.empty)return;let n=Hs?null:i.clipboardData,h=s.content(),{dom:o,text:l}=ps(t,h);n?(i.preventDefault(),n.clearData(),n.setData("text/html",o.innerHTML),n.setData("text/plain",l)):function(t,e){if(!t.dom.parentNode)return;let i=t.dom.parentNode.appendChild(document.createElement("div"));i.appendChild(e),i.style.cssText="position: fixed; left: -10000px; top: 10px";let s=getSelection(),r=document.createRange();r.selectNodeContents(e),t.dom.blur(),s.removeAllRanges(),s.addRange(r),setTimeout((()=>{i.parentNode&&i.parentNode.removeChild(i),t.focus()}),50)}(t,o),r&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},Ds.paste=(t,e)=>{let i=e;if(t.composing&&!Ve)return;let s=Hs?null:i.clipboardData,r=t.input.shiftKey&&45!=t.input.lastKeyCode;s&&Ks(t,qs(s),s.getData("text/html"),r,i)?i.preventDefault():function(t,e){if(!t.dom.parentNode)return;let i=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,s=t.dom.parentNode.appendChild(document.createElement(i?"textarea":"div"));i||(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),i?Ks(t,s.value,null,r,e):Ks(t,s.textContent,s.innerHTML,r,e)}),50)}(t,i)};class Gs{constructor(t,e,i){this.slice=t,this.move=e,this.node=i}}const Vs=qe?"altKey":"ctrlKey";function Zs(t,e){let i;return t.someProp("dragCopies",(t=>{i=i||t(e)})),null!=i?!i:!e[Vs]}Ts.dragstart=(t,e)=>{let i=e,s=t.input.mouseDown;if(s&&s.done(),!i.dataTransfer)return;let r,n=t.state.selection,h=n.empty?null:t.posAtCoords(Ns(i));if(h&&h.pos>=n.from&&h.pos<=(n instanceof ue?n.to-1:n.to));else if(s&&s.mightDrag)r=ue.create(t.state.doc,s.mightDrag.pos);else if(i.target&&1==i.target.nodeType){let e=t.docView.nearestDesc(i.target,!0);e&&e.node.type.spec.draggable&&e!=t.docView&&(r=ue.create(t.state.doc,e.posBefore))}let o=(r||t.state.selection).content(),{dom:l,text:u,slice:f}=ps(t,o);(!i.dataTransfer.files.length||!Xe||Ue>120)&&i.dataTransfer.clearData(),i.dataTransfer.setData(Hs?"Text":"text/html",l.innerHTML),i.dataTransfer.effectAllowed="copyMove",Hs||i.dataTransfer.setData("text/plain",u),t.dragging=new Gs(f,Zs(t,i),r)},Ts.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{t.dragging==e&&(t.dragging=null)}),50)},Ds.dragover=Ds.dragenter=(t,e)=>e.preventDefault(),Ds.drop=(t,e)=>{try{!function(t,e,i){if(!e.dataTransfer)return;let s=t.posAtCoords(Ns(e));if(!s)return;let r=t.state.doc.resolve(s.pos),n=i&&i.slice;n?t.someProp("transformPasted",(e=>{n=e(n,t,!1)})):n=ms(t,qs(e.dataTransfer),Hs?null:e.dataTransfer.getData("text/html"),!1,r);let h=!(!i||!Zs(t,e));if(t.someProp("handleDrop",(i=>i(t,e,n||b.empty,h))))return void e.preventDefault();if(!n)return;e.preventDefault();let o=n?function(t,e,i){let s=t.resolve(e);if(!i.content.size)return e;let r=i.content;for(let t=0;t<i.openStart;t++)r=r.firstChild.content;for(let t=1;t<=(0==i.openStart&&i.size?2:1);t++)for(let e=s.depth;e>=0;e--){let i=e==s.depth?0:s.pos<=(s.start(e+1)+s.end(e+1))/2?-1:1,n=s.index(e)+(i>0?1:0),h=s.node(e),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==i?s.pos:i<0?s.before(e+1):s.after(e+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}=i;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&&ue.isSelectable(n.content.firstChild)&&c.nodeAfter&&c.nodeAfter.sameMarkup(n.content.firstChild))l.setSelection(new ue(c));else{let e=l.mapping.map(o);l.mapping.maps[l.mapping.maps.length-1].forEach(((t,i,s,r)=>e=r)),l.setSelection(Zi(t,c,l.doc.resolve(e)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}(t,e,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())&&Xi(t)}),20))},Ts.blur=(t,e)=>{let i=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),i.relatedTarget&&t.dom.contains(i.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)},Ts.beforeinput=(t,e)=>{if(Xe&&Ve&&"deleteContentBackward"==e.inputType){t.domObserver.flushSoon();let{domChangeCount:e}=t.input;setTimeout((()=>{if(t.input.domChangeCount!=e)return;if(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",(e=>e(t,Ne(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())}),50)}};for(let t in Ds)Ts[t]=Ds[t];function Qs(t,e){if(t==e)return!0;for(let i in t)if(t[i]!==e[i])return!1;for(let i in e)if(!(i in t))return!1;return!0}class tr{constructor(t,e){this.toDOM=t,this.spec=e||nr,this.side=this.spec.side||0}map(t,e,i,s){let{pos:r,deleted:n}=t.mapResult(e.from+s,this.side<0?-1:1);return n?null:new sr(r-i,r-i,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 er{constructor(t,e){this.attrs=t,this.spec=e||nr}map(t,e,i,s){let r=t.map(e.from+s,this.spec.inclusiveStart?-1:1)-i,n=t.map(e.to+s,this.spec.inclusiveEnd?1:-1)-i;return r>=n?null:new sr(r,n,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof er&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}static is(t){return t.type instanceof er}destroy(){}}class ir{constructor(t,e){this.attrs=t,this.spec=e||nr}map(t,e,i,s){let r=t.mapResult(e.from+s,1);if(r.deleted)return null;let n=t.mapResult(e.to+s,-1);return n.deleted||n.pos<=r.pos?null:new sr(r.pos-i,n.pos-i,this)}valid(t,e){let i,{index:s,offset:r}=t.content.findIndex(e.from);return r==e.from&&!(i=t.child(s)).isText&&r+i.nodeSize==e.to}eq(t){return this==t||t instanceof ir&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}destroy(){}}class sr{constructor(t,e,i){this.from=t,this.to=e,this.type=i}copy(t,e){return new sr(t,e,this.type)}eq(t,e=0){return this.type.eq(t.type)&&this.from+e==t.from&&this.to+e==t.to}map(t,e,i){return this.type.map(t,this,e,i)}static widget(t,e,i){return new sr(t,t,new tr(e,i))}static inline(t,e,i,s){return new sr(t,e,new er(i,s))}static node(t,e,i,s){return new sr(t,e,new ir(i,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof er}get widget(){return this.type instanceof tr}}const rr=[],nr={};class hr{constructor(t,e){this.local=t.length?t:rr,this.children=e.length?e:rr}static create(t,e){return e.length?cr(e,t,0,nr):or}find(t,e,i){let s=[];return this.findInner(null==t?0:t,null==e?1e9:e,s,0,i),s}findInner(t,e,i,s,r){for(let n=0;n<this.local.length;n++){let h=this.local[n];h.from<=e&&h.to>=t&&(!r||r(h.spec))&&i.push(h.copy(h.from+s,h.to+s))}for(let n=0;n<this.children.length;n+=3)if(this.children[n]<e&&this.children[n+1]>t){let h=this.children[n]+1;this.children[n+2].findInner(t-h,e-h,i,s+h,r)}}map(t,e,i){return this==or||0==t.maps.length?this:this.mapInner(t,e,0,0,i||nr)}mapInner(t,e,i,s,r){let n;for(let h=0;h<this.local.length;h++){let o=this.local[h].map(t,i,s);o&&o.type.valid(e,o)?(n||(n=[])).push(o):r.onRemove&&r.onRemove(this.local[h].spec)}return this.children.length?function(t,e,i,s,r,n,h){let o=t.slice();for(let t=0,e=n;t<i.maps.length;t++){let s=0;i.maps[t].forEach(((t,i,r,n)=>{let h=n-r-(i-t);for(let r=0;r<o.length;r+=3){let n=o[r+1];if(n<0||t>n+e-s)continue;let l=o[r]+e-s;i>=l?o[r+1]=t<=l?-2:-1:t>=e&&h&&(o[r]+=h,o[r+1]+=h)}s+=h})),e=i.maps[t].map(e,-1)}let l=!1;for(let e=0;e<o.length;e+=3)if(o[e+1]<0){if(-2==o[e+1]){l=!0,o[e+1]=-1;continue}let u=i.map(t[e]+n),f=u-r;if(f<0||f>=s.content.size){l=!0;continue}let a=i.map(t[e+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[e+2].mapInner(i,p,u+1,t[e]+n+1,h);s!=or?(o[e]=f,o[e+1]=a,o[e+2]=s):(o[e+1]=-2,l=!0)}else l=!0}if(l){let l=function(t,e,i,s,r,n,h){function o(t,e){for(let n=0;n<t.local.length;n++){let o=t.local[n].map(s,r,e);o?i.push(o):h.onRemove&&h.onRemove(t.local[n].spec)}for(let i=0;i<t.children.length;i+=3)o(t.children[i+2],t.children[i]+e+1)}for(let i=0;i<t.length;i+=3)-1==t[i+1]&&o(t[i+2],e[i]+n+1);return i}(o,t,e,i,r,n,h),u=cr(l,s,0,h);e=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,e=0;t<u.children.length;t+=3){let i=u.children[t];for(;e<o.length&&o[e]<i;)e+=3;o.splice(e,0,u.children[t],u.children[t+1],u.children[t+2])}}return new hr(e.sort(dr),o)}(this.children,n||[],t,e,i,s,r):n?new hr(n.sort(dr),rr):or}add(t,e){return e.length?this==or?hr.create(t,e):this.addInner(t,e,0):this}addInner(t,e,i){let s,r=0;t.forEach(((t,n)=>{let h,o=n+i;if(h=fr(e,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(e):e,-i);for(let e=0;e<n.length;e++)n[e].type.valid(t,n[e])||n.splice(e--,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,e){let i=this.children,s=this.local;for(let s=0;s<i.length;s+=3){let r,n=i[s]+e,h=i[s+1]+e;for(let e,i=0;i<t.length;i++)(e=t[i])&&e.from>n&&e.to<h&&(t[i]=null,(r||(r=[])).push(e));if(!r)continue;i==this.children&&(i=this.children.slice());let o=i[s+2].removeInner(r,n+1);o!=or?i[s+2]=o:(i.splice(s,3),s-=3)}if(s.length)for(let i,r=0;r<t.length;r++)if(i=t[r])for(let t=0;t<s.length;t++)s[t].eq(i,e)&&(s==this.local&&(s=this.local.slice()),s.splice(t--,1));return i==this.children&&s==this.local?this:s.length||i.length?new hr(s,i):or}forChild(t,e){if(this==or)return this;if(e.isLeaf)return hr.empty;let i,s;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(i=this.children[e+2]);break}let r=t+1,n=r+e.content.size;for(let t=0;t<this.local.length;t++){let e=this.local[t];if(e.from<n&&e.to>r&&e.type instanceof er){let t=Math.max(r,e.from)-r,i=Math.min(n,e.to)-r;t<i&&(s||(s=[])).push(e.copy(t,i))}}if(s){let t=new hr(s.sort(dr),rr);return i?new lr([t,i]):t}return i||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 e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(t){return pr(this.localsInner(t))}localsInner(t){if(this==or)return rr;if(t.inlineContent||!this.local.some(er.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++)this.local[t].type instanceof er||e.push(this.local[t]);return e}forEachSet(t){t(this)}}hr.empty=new hr([],[]),hr.removeOverlap=pr;const or=hr.empty;class lr{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,nr)));return lr.from(i)}forChild(t,e){if(e.isLeaf)return hr.empty;let i=[];for(let s=0;s<this.members.length;s++){let r=this.members[s].forChild(t,e);r!=or&&(r instanceof lr?i=i.concat(r.members):i.push(r))}return lr.from(i)}eq(t){if(!(t instanceof lr)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(t){let e,i=!0;for(let s=0;s<this.members.length;s++){let r=this.members[s].localsInner(t);if(r.length)if(e){i&&(e=e.slice(),i=!1);for(let t=0;t<r.length;t++)e.push(r[t])}else e=r}return e?pr(i?e:e.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,e)=>t.concat(e instanceof hr?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function ur(t,e){if(!e||!t.length)return t;let i=[];for(let s=0;s<t.length;s++){let r=t[s];i.push(new sr(r.from+e,r.to+e,r.type))}return i}function fr(t,e,i){if(e.isLeaf)return null;let s=i+e.nodeSize,r=null;for(let e,n=0;n<t.length;n++)(e=t[n])&&e.from>i&&e.to<s&&((r||(r=[])).push(e),t[n]=null);return r}function ar(t){let e=[];for(let i=0;i<t.length;i++)null!=t[i]&&e.push(t[i]);return e}function cr(t,e,i,s){let r=[],n=!1;e.forEach(((e,h)=>{let o=fr(t,e,h+i);if(o){n=!0;let t=cr(o,e,i+h+1,s);t!=or&&r.push(h,h+e.nodeSize,t)}}));let h=ur(n?ar(t):t,-i).sort(dr);for(let t=0;t<h.length;t++)h[t].type.valid(e,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,e){return t.from-e.from||t.to-e.to}function pr(t){let e=t;for(let i=0;i<e.length-1;i++){let s=e[i];if(s.from!=s.to)for(let r=i+1;r<e.length;r++){let n=e[r];if(n.from!=s.from){n.from<s.to&&(e==t&&(e=t.slice()),e[i]=s.copy(s.from,n.from),mr(e,r,s.copy(n.from,s.to)));break}n.to!=s.to&&(e==t&&(e=t.slice()),e[r]=n.copy(n.from,s.to),mr(e,r+1,n.copy(s.to,n.to)))}}return e}function mr(t,e,i){for(;e<t.length&&dr(i,t[e])>0;)e++;t.splice(e,0,i)}function wr(t){let e=[];return t.someProp("decorations",(i=>{let s=i(t.state);s&&s!=or&&e.push(s)})),t.cursorWrapper&&e.push(hr.create(t.state.doc,[t.cursorWrapper.deco])),lr.from(e)}const gr={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},yr=We&&Je<=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,e){this.view=t,this.handleDOMChange=e,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((e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);We&&Je<=11&&e.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():He&&t.composing&&e.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 e=0;e<t.length;e++)this.queue.push(t[e]);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(Qi(this.view)){if(this.suppressingSelectionUpdates)return Xi(this.view);if(We&&Je<=11&&!this.view.state.selection.empty){let t=this.view.domSelectionRange();if(t.focusNode&&Ae(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 e,i=new Set;for(let e=t.focusNode;e;e=Oe(e))i.add(e);for(let s=t.anchorNode;s;s=Oe(s))if(i.has(s)){e=s;break}let s=e&&this.view.docView.nearestDesc(e);return s&&s.ignoreMutation({type:"selection",target:3==e.nodeType?e.parentNode:e})?(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 e=this.pendingRecords();e.length&&(this.queue=[]);let i=t.domSelectionRange(),s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&Qi(t)&&!this.ignoreSelectionChange(i),r=-1,n=-1,h=!1,o=[];if(t.editable)for(let t=0;t<e.length;t++){let i=this.registerMutation(e[t],o);i&&(r=r<0?i.from:Math.min(i.from,r),n=n<0?i.to:Math.max(i.to,n),i.typeOver&&(h=!0))}if(!o.some((t=>"BR"==t.nodeName))||8!=t.input.lastKeyCode&&46!=t.input.lastKeyCode){if(Le&&o.length){let e=o.filter((t=>"BR"==t.nodeName));if(2==e.length){let[t,i]=e;t.parentNode&&t.parentNode.parentNode==i.parentNode?i.remove():t.remove()}else{let{focusNode:i}=this.currentSelection;for(let s of e){let e=s.parentNode;!e||"LI"!=e.nodeName||i&&xr(t,i)==e||s.remove()}}}}else for(let t of o)if("BR"==t.nodeName&&t.parentNode){let e=t.nextSibling;for(;e&&1==e.nodeType;){if("false"==e.contentEditable){t.parentNode.removeChild(t);break}e=e.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&&Ce(i)&&(l=Li(t))&&l.eq(se.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,Xi(t),this.currentSelection.set(i),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=Le,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,e){var i;let{focusNode:s,focusOffset:r}=t.domSelectionRange();for(let n of e)if("TR"==(null===(i=n.parentNode)||void 0===i?void 0:i.nodeName)){let e=n.nextSibling;for(;e&&"TD"!=e.nodeName&&"TH"!=e.nodeName;)e=e.nextSibling;if(e){let i=e;for(;;){let t=i.firstChild;if(!t||1!=t.nodeType||"false"==t.contentEditable||/^(BR|IMG)$/.test(t.nodeName))break;i=t}i.insertBefore(n,i.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(i)||Xi(t),this.currentSelection.set(i))}registerMutation(t,e){if(e.indexOf(t.target)>-1)return null;let i=this.view.docView.nearestDesc(t.target);if("attributes"==t.type&&(i==this.view.docView||"contenteditable"==t.attributeName||"style"==t.attributeName&&!t.oldValue&&!t.target.getAttribute("style")))return null;if(!i||i.ignoreMutation(t))return null;if("childList"==t.type){for(let i=0;i<t.addedNodes.length;i++){let s=t.addedNodes[i];e.push(s),3==s.nodeType&&(this.lastChangedTextNode=s)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let s=t.previousSibling,r=t.nextSibling;if(We&&Je<=11&&t.addedNodes.length)for(let e=0;e<t.addedNodes.length;e++){let{previousSibling:i,nextSibling:n}=t.addedNodes[e];(!i||Array.prototype.indexOf.call(t.addedNodes,i)<0)&&(s=i),(!n||Array.prototype.indexOf.call(t.addedNodes,n)<0)&&(r=n)}let n=s&&s.parentNode==t.target?xe(s)+1:0,h=i.localPosFromDOM(t.target,n,-1),o=r&&r.parentNode==t.target?xe(r):t.target.childNodes.length;return{from:h,to:i.localPosFromDOM(t.target,o,1)}}return"attributes"==t.type?{from:i.posAtStart-i.border,to:i.posAtEnd+i.border}:(this.lastChangedTextNode=t.target,{from:i.posAtStart,to:i.posAtEnd,typeOver:t.target.nodeValue==t.oldValue})}}let vr=new WeakMap,kr=!1;function Sr(t,e){let i=e.startContainer,s=e.startOffset,r=e.endContainer,n=e.endOffset,h=t.domAtPos(t.state.selection.anchor);return Ae(h.node,h.offset,r,n)&&([i,s,r,n]=[r,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}}function xr(t,e){for(let i=e.parentNode;i&&i!=t.dom;i=i.parentNode){let e=t.docView.nearestDesc(i,!0);if(e&&e.node.isBlock)return i}return null}function Or(t){let e=t.pmViewDesc;if(e)return e.parseRule();if("BR"==t.nodeName&&t.parentNode){if(He&&/^(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||He&&/^(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,e,i){return Math.max(i.anchor,i.head)>e.content.size?null:Zi(t,e.resolve(i.anchor),e.resolve(i.head))}function Ar(t,e,i){let s=t.depth,r=e?t.end():t.pos;for(;s>0&&(e||t.indexAfter(s)==t.node(s).childCount);)s--,r++,e=!1;if(i){let e=t.node(s).maybeChild(t.indexAfter(s));for(;e&&!e.isLeaf;)e=e.firstChild,r++}return r}function Rr(t){if(2!=t.length)return!1;let e=t.charCodeAt(0),i=t.charCodeAt(1);return e>=56320&&e<=57343&&i>=55296&&i<=56319}class Er{constructor(t,e){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=e,this.state=e.state,this.directPlugins=e.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=Cr(this),Pr(this),this.nodeViews=Nr(this),this.docView=Di(this.state.doc,$r(this),wr(this),this.dom,this),this.domObserver=new Mr(this,((t,e,i,s)=>function(t,e,i,s,r){let n=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let e=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,i=Li(t,e);if(i&&!t.state.selection.eq(i)){if(Xe&&Ve&&13===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,Ne(13,"Enter")))))return;let s=t.state.tr.setSelection(i);"pointer"==e?s.setMeta("pointer",!0):"key"==e&&s.scrollIntoView(),n&&s.setMeta("composition",n),t.dispatch(s)}return}let h=t.state.doc.resolve(e),o=h.sharedDepth(i);e=h.before(o+1),i=t.state.doc.resolve(i).after(o+1);let l,u,f=t.state.selection,a=function(t,e,i){let s,{node:r,fromOffset:n,toOffset:h,from:o,to:l}=t.docView.parseRange(e,i),u=t.domSelectionRange(),f=u.anchorNode;if(f&&t.dom.contains(1==f.nodeType?f:f.parentNode)&&(s=[{node:f,offset:u.anchorOffset}],Ce(u)||s.push({node:u.focusNode,offset:u.focusOffset})),Xe&&8===t.input.lastKeyCode)for(let t=h;t>n;t--){let e=r.childNodes[t-1],i=e.pmViewDesc;if("BR"==e.nodeName&&!i){h=t;break}if(!i||i.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,e=s[1]&&s[1].pos;null==e&&(e=t),p={anchor:t+o,head:e+o}}return{doc:m,sel:p,from:o,to:l}}(t,e,i),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,e,i,s,r){let n=t.findDiffStart(e,i);if(null==n)return null;let{a:h,b:o}=t.findDiffEnd(e,i+t.size,i+e.size);if("end"==r&&(s-=h+Math.max(0,n-Math.min(h,o))-n),h<n&&t.size<e.size){let t=s<=n&&s>=h?n-s:0;n-=t,n&&n<e.size&&Rr(e.textBetween(n-1,n+1))&&(n+=t?1:-1),o=n+(o-h),h=n}else if(o<n){let e=s<=n&&s>=o?n-s:0;n-=e,n&&n<t.size&&Rr(t.textBetween(n-1,n+1))&&(n+=e?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++,(Ke&&t.input.lastIOSEnter>Date.now()-225||Ve)&&r.some((t=>1==t.nodeType&&!Tr.test(t.nodeName)))&&(!m||m.endA>=m.endB)&&t.someProp("handleKeyDown",(e=>e(t,Ne(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!m){if(!(s&&f instanceof oe&&!f.empty&&f.$head.sameParent(f.$anchor))||t.composing||a.sel&&a.sel.anchor!=a.sel.head){if(a.sel){let e=Dr(t,t.state.doc,a.sel);if(e&&!e.eq(t.state.selection)){let i=t.state.tr.setSelection(e);n&&i.setMeta("composition",n),t.dispatch(i)}}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 oe&&(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)),We&&Je<=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((Ke&&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",(e=>e(t,Ne(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>m.start&&function(t,e,i,s,r){if(i-e<=r.pos-s.pos||Ar(s,!0,!1)<r.pos)return!1;let n=t.resolve(e);if(!s.parent.isTextblock){let t=n.nodeAfter;return null!=t&&i==e+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>i||Ar(h,!0,!1)<i)&&s.parent.content.cut(s.parentOffset).eq(h.parent.content)}(c,m.start,m.endA,w,g)&&t.someProp("handleKeyDown",(e=>e(t,Ne(8,"Backspace")))))return void(Ve&&Xe&&t.domObserver.suppressSelectionUpdates());Xe&&m.endB==m.start&&(t.input.lastChromeDelete=Date.now()),Ve&&!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(e){return e(t,Ne(13,"Enter"))}))}),20));let M,v=m.start,k=m.endA,S=e=>{let i=e||t.state.tr.replace(v,k,a.doc.slice(m.start-a.from,m.endB-a.from));if(a.sel){let e=Dr(t,i.doc,a.sel);e&&!(Xe&&t.composing&&e.empty&&(m.start!=m.endB||t.input.lastChromeDelete<Date.now()-100)&&(e.head==v||e.head==i.mapping.map(k)-1)||We&&e.empty&&e.head==v)&&i.setSelection(e)}return n&&i.setMeta("composition",n),i.scrollIntoView()};if(b)if(w.pos==g.pos){We&&Je<=11&&0==w.parentOffset&&(t.domObserver.suppressSelectionUpdates(),setTimeout((()=>Xi(t)),20));let e=S(t.state.tr.delete(v,k)),i=c.resolve(m.start).marksAcross(c.resolve(m.endA));i&&e.ensureMarks(i),t.dispatch(e)}else if(m.endA==m.endB&&(M=function(t,e){let i,s,r,n=t.firstChild.marks,h=e.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],i="add",r=t=>t.mark(s.addToSet(t.marks));else{if(0!=o.length||1!=l.length)return null;s=l[0],i="remove",r=t=>t.mark(s.removeFromSet(t.marks))}let u=[];for(let t=0;t<e.childCount;t++)u.push(r(e.child(t)));if(d.from(u).eq(t))return{mark:s,type:i}}(w.parent.content.cut(w.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,m.endA-y.start())))){let e=S(t.state.tr);"add"==M.type?e.addMark(v,k,M.mark):e.removeMark(v,k,M.mark),t.dispatch(e)}else if(w.parent.child(w.index()).isText&&w.index()==g.index()-(g.textOffset?0:1)){let e=w.parent.textBetween(w.parentOffset,g.parentOffset),i=()=>S(t.state.tr.insertText(e,v,k));t.someProp("handleTextInput",(s=>s(t,v,k,e,i)))||t.dispatch(i())}else t.dispatch(S());else t.dispatch(S())}(this,t,e,i,s))),this.domObserver.start(),function(t){for(let e in Ts){let i=Ts[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{!Cs(t,e)||Ps(t,e)||!t.editable&&e.type in Ds||i(t,e)},As[e]?{passive:!0}:void 0)}He&&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 e in t)this._props[e]=t[e];this._props.state=this.state}return this._props}update(t){t.handleDOMEvents!=this._props.handleDOMEvents&&$s(this);let e=this._props;this._props=t,t.plugins&&(t.plugins.forEach(Ir),this.directPlugins=t.plugins),this.updateStateInner(t.state,e)}setProps(t){let e={};for(let t in this._props)e[t]=this._props[t];e.state=this.state;for(let i in t)e[i]=t[i];this.update(e)}updateState(t){this.updateStateInner(t,this._props)}updateStateInner(t,e){var i;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!=e.plugins;if(h||this._props.plugins!=e.plugins||this._props.nodeViews!=e.nodeViews){let t=Nr(this);(function(t,e){let i=0,s=0;for(let s in t){if(t[s]!=e[s])return!0;i++}for(let t in e)s++;return i!=s})(t,this.nodeViews)&&(this.nodeViews=t,r=!0)}(h||e.handleDOMEvents!=this._props.handleDOMEvents)&&$s(this),this.editable=Cr(this),Pr(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 e,i,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){e=s,i=o.top;break}}return{refDOM:e,refTop:i,stack:ri(t.dom)}}(this);if(n){this.domObserver.stop();let e=f&&(We||Xe)&&!this.composing&&!s.selection.empty&&!t.selection.empty&&function(t,e){let i=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(i)!=e.$anchor.start(i)}(s.selection,t.selection);if(f){let i=Xe?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let i=function(t,e){for(;;){if(3==t.nodeType&&e)return t;if(1==t.nodeType&&e>0){if("false"==t.contentEditable)return null;e=$e(t=t.childNodes[e-1])}else{if(!t.parentNode||Pe(t))return null;e=xe(t),t=t.parentNode}}}(e.focusNode,e.focusOffset),s=function(t,e){for(;;){if(3==t.nodeType&&e<t.nodeValue.length)return t;if(1==t.nodeType&&e<t.childNodes.length){if("false"==t.contentEditable)return null;t=t.childNodes[e],e=0}else{if(!t.parentNode||Pe(t))return null;e=xe(t)+1,t=t.parentNode}}}(e.focusNode,e.focusOffset);if(i&&s&&i!=s){let e=s.pmViewDesc,r=t.domObserver.lastChangedTextNode;if(i==r||s==r)return r;if(!e||!e.isText(s.nodeValue))return s;if(t.input.compositionNode==s){let t=i.pmViewDesc;if(t&&t.isText(i.nodeValue))return s}}return i||s}(this)),!r&&this.docView.update(t.doc,l,o,this)||(this.docView.updateOuterDeco(l),this.docView.destroy(),this.docView=Di(t.doc,l,o,this.dom,this)),!i||this.trackWrites&&this.dom.contains(this.trackWrites)||(e=!0)}e||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),i=t.domSelectionRange();return Ae(e.node,e.offset,i.anchorNode,i.anchorOffset)}(this))?Xi(this,e):(Gi(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null===(i=this.dragging)||void 0===i?void 0:i.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:e,stack:i}){let s=t?t.getBoundingClientRect().top:0;ni(i,0==s?0:s-e)}(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 ue){let e=this.docView.domAfterPos(this.state.selection.from);1==e.nodeType&&si(this,e.getBoundingClientRect(),t)}else si(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 e=0;e<this.pluginViews.length;e++){let i=this.pluginViews[e];i.update&&i.update(this,t)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let e=this.directPlugins[t];e.spec.view&&this.pluginViews.push(e.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let e=this.state.plugins[t];e.spec.view&&this.pluginViews.push(e.spec.view(this))}}}updateDraggedNode(t,e){let i=t.node,s=-1;if(i.from<this.state.doc.content.size&&this.state.doc.nodeAt(i.from)==i.node)s=i.from;else{let t=i.from+(this.state.doc.content.size-e.doc.content.size);(t>0&&t<this.state.doc.content.size&&this.state.doc.nodeAt(t))==i.node&&(s=t)}this.dragging=new Gs(t.slice,t.move,s<0?void 0:ue.create(this.state.doc,s))}someProp(t,e){let i,s=this._props&&this._props[t];if(null!=s&&(i=e?e(s):s))return i;for(let s=0;s<this.directPlugins.length;s++){let r=this.directPlugins[s].props[t];if(null!=r&&(i=e?e(r):r))return i}let r=this.state.plugins;if(r)for(let s=0;s<r.length;s++){let n=r[s].props[t];if(null!=n&&(i=e?e(n):n))return i}}hasFocus(){if(We){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(hi)return t.focus(hi);let e=ri(t);t.focus(null==hi?{get preventScroll(){return hi={preventScroll:!0},!0}}:void 0),hi||(hi=!1,ni(e,0))}(this.dom),Xi(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 fi(this,t)}coordsAtPos(t,e=1){return pi(this,t,e)}domAtPos(t,e=0){return this.docView.domFromPos(t,e)}nodeDOM(t){let e=this.docView.descAt(t);return e?e.nodeDOM:null}posAtDOM(t,e,i=-1){let s=this.docView.posFromDOM(t,e,i);if(null==s)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(t,e){return function(t,e,i){return bi==e&&Mi==i?vi:(bi=e,Mi=i,vi="up"==i||"down"==i?function(t,e,i){let s=e.selection,r="up"==i?s.$from:s.$to;return gi(t,e,(()=>{let{node:e}=t.docView.domFromPos(r.pos,"up"==i?-1:1);for(;;){let i=t.docView.nearestDesc(e,!0);if(!i)break;if(i.node.isBlock){e=i.contentDOM||i.dom;break}e=i.dom.parentNode}let s=pi(t,r.pos,1);for(let t=e.firstChild;t;t=t.nextSibling){let e;if(1==t.nodeType)e=t.getClientRects();else{if(3!=t.nodeType)continue;e=De(t,0,t.nodeValue.length).getClientRects()}for(let t=0;t<e.length;t++){let r=e[t];if(r.bottom>r.top+1&&("up"==i?s.top-r.top>2*(r.bottom-s.top):r.bottom-s.bottom>2*(s.bottom-r.top)))return!1}}return!0}))}(t,e,i):function(t,e,i){let{$head:s}=e.selection;if(!s.parent.isTextblock)return!1;let r=s.parentOffset,n=!r,h=r==s.parent.content.size,o=t.domSelection();return o?yi.test(s.parent.textContent)&&o.modify?gi(t,e,(()=>{let{focusNode:e,focusOffset:r,anchorNode:n,anchorOffset:h}=t.domSelectionRange(),l=o.caretBidiLevel;o.modify("move",i,"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)||e==f&&r==a;try{o.collapse(n,h),e&&(e!=n||r!=h)&&o.extend&&o.extend(e,r)}catch(t){}return null!=l&&(o.caretBidiLevel=l),c})):"left"==i||"backward"==i?n:h:s.pos==s.start()||s.pos==s.end()}(t,e,i))}(this,e||this.state,t)}pasteHTML(t,e){return Ks(this,"",t,!1,e||new ClipboardEvent("paste"))}pasteText(t,e){return Ks(this,t,null,!0,e||new ClipboardEvent("paste"))}serializeForClipboard(t){return ps(this,t)}destroy(){this.docView&&(function(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);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,Te=null)}get isDestroyed(){return null==this.docView}dispatchEvent(t){return function(t,e){Ps(t,e)||!Ts[e.type]||!t.editable&&e.type in Ds||Ts[e.type](t,e)}(this,t)}domSelectionRange(){let t=this.domSelection();return t?He&&11===this.root.nodeType&&function(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}(this.dom.ownerDocument)==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return Sr(t,i)}let i;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",s,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",s,!0),i?Sr(t,i):null}(this,t)||t:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function $r(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",(i=>{if("function"==typeof i&&(i=i(t.state)),i)for(let t in i)"class"==t?e.class+=" "+i[t]:"style"==t?e.style=(e.style?e.style+";":"")+i[t]:e[t]||"contenteditable"==t||"nodeName"==t||(e[t]=String(i[t]))})),e.translate||(e.translate="no"),[sr.node(0,t.state.doc.content.size,e)]}function Pr(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:sr.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Cr(t){return!t.someProp("editable",(e=>!1===e(t.state)))}function Nr(t){let e=Object.create(null);function i(t){for(let i in t)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=t[i])}return t.someProp("nodeViews",i),t.someProp("markViews",i),e}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 e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};const zr=["p",0],jr=["blockquote",0],_r=["hr"],Fr=["pre",["code",0]],Br=["br"],Wr=["em",0],Jr=["strong",0],Lr=["code",0],Yr=new it({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:()=>jr},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>_r},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:e,alt:i,title:s}=t.attrs;return["img",{src:e,alt:i,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:e,title:i}=t.attrs;return["a",{href:e,title:i},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,e){let i={};for(let e in t)i[e]=t[e];for(let t in e)i[t]=e[t];return i}function Zr(t,e,i){return t.append({ordered_list:Vr(Kr,{content:"list_item+",group:i}),bullet_list:Vr(qr,{content:"list_item+",group:i}),list_item:Vr(Gr,{content:e})})}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 e,i,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))e=!0;else if(/^(c|ctrl|control)$/i.test(h))i=!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:i=!0}}return e&&(h="Alt-"+h),i&&(h="Ctrl-"+h),r&&(h="Meta-"+h),s&&(h="Shift-"+h),h}function un(t,e,i=!0){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),i&&e.shiftKey&&(t="Shift-"+t),t}function fn(t){return new ke({props:{handleKeyDown:an(t)}})}function an(t){let e=function(t){let e=Object.create(null);for(let i in t)e[ln(i)]=t[i];return e}(t);return function(t,i){let s,r=function(t){var e=!(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"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(i),n=e[un(r,i)];if(n&&n(t.state,t.dispatch,t))return!0;if(1==r.length&&" "!=r){if(i.shiftKey){let s=e[un(r,i,!1)];if(s&&s(t.state,t.dispatch,t))return!0}if((i.altKey||i.metaKey||i.ctrlKey)&&!(on&&i.ctrlKey&&i.altKey)&&(s=Qr[i.keyCode])&&s!=r){let r=e[un(s,i)];if(r&&r(t.state,t.dispatch,t))return!0}}return!1}}const cn=(t,e)=>!t.selection.empty&&(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function dn(t,e,i=!1){for(let s=t;s;s="start"==e?s.firstChild:s.lastChild){if(s.isTextblock)return!0;if(i&&1!=s.childCount)return!1}return!1}function pn(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function mn(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let i=t.node(e);if(t.index(e)+1<i.childCount)return t.doc.resolve(t.after(e+1));if(i.type.spec.isolating)break}return null}function wn(t){for(let e=0;e<t.edgeCount;e++){let{type:i}=t.edge(e);if(i.isTextblock&&!i.hasRequiredAttrs())return i}return null}function gn(t,e,i,s){let r,n,h=e.nodeBefore,o=e.nodeAfter,l=h.type.spec.isolating||o.type.spec.isolating;if(!l&&function(t,e,i){let s=e.nodeBefore,r=e.nodeAfter,n=e.index();return!(!(s&&r&&s.type.compatibleContent(r.type))||(!s.content.size&&e.parent.canReplace(n-1,n)?(i&&i(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView()),0):!e.parent.canReplace(n,n+1)||!r.isTextblock&&!Wt(t.doc,e.pos)||(i&&i(t.tr.join(e.pos).scrollIntoView()),0)))}(t,e,i))return!0;let u=!l&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(r=(n=h.contentMatchAt(h.childCount)).findWrapping(o.type))&&n.matchType(r[0]||o.type).validEnd){if(i){let s=e.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 Ct(e.pos-1,s,e.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),i(l.scrollIntoView())}return!0}let f=o.type.spec.isolating||s>0&&l?null:se.findFrom(e,1),a=f&&f.$from.blockRange(f.$to),c=a&&jt(a);if(null!=c&&c>=e.depth)return i&&i(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(i){let s=d.empty;for(let t=r.length-1;t>=0;t--)s=d.from(r[t].copy(s));i(t.tr.step(new Ct(e.pos-r.length,e.pos+o.nodeSize,e.pos+l,e.pos+o.nodeSize-l,new b(s,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function yn(t){return function(e,i){let s=e.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&&(i&&i(e.tr.setSelection(oe.create(e.doc,t<0?r.start(n):r.end(n)))),!0)}}const bn=yn(-1),Mn=yn(1);function vn(...t){return function(e,i,s){for(let r=0;r<t.length;r++)if(t[r](e,i,s))return!0;return!1}}let kn=vn(cn,((t,e,i)=>{let s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("backward",t):i.parentOffset>0)?null:i}(t,i);if(!s)return!1;let r=pn(s);if(!r){let i=s.blockRange(),r=i&&jt(i);return null!=r&&(e&&e(t.tr.lift(i,r).scrollIntoView()),!0)}let n=r.nodeBefore;if(gn(t,r,e,-1))return!0;if(0==s.parent.content.size&&(dn(n,"end")||ue.isSelectable(n)))for(let i=s.depth;;i--){let h=Jt(t.doc,s.before(i),s.after(i),b.empty);if(h&&h.slice.size<h.to-h.from){if(e){let i=t.tr.step(h);i.setSelection(dn(n,"end")?se.findFrom(i.doc.resolve(i.mapping.map(r.pos,-1)),-1):ue.create(i.doc,r.pos-n.nodeSize)),e(i.scrollIntoView())}return!0}if(1==i||s.node(i-1).childCount>1)break}return!(!n.isAtom||r.depth!=s.depth-1||(e&&e(t.tr.delete(r.pos-n.nodeSize,r.pos).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("backward",t):s.parentOffset>0)return!1;n=pn(s)}let h=n&&n.nodeBefore;return!(!h||!ue.isSelectable(h)||(e&&e(t.tr.setSelection(ue.create(t.doc,n.pos-h.nodeSize)).scrollIntoView()),0))})),Sn=vn(cn,((t,e,i)=>{let s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("forward",t):i.parentOffset<i.parent.content.size)?null:i}(t,i);if(!s)return!1;let r=mn(s);if(!r)return!1;let n=r.nodeAfter;if(gn(t,r,e,1))return!0;if(0==s.parent.content.size&&(dn(n,"start")||ue.isSelectable(n))){let i=Jt(t.doc,s.before(),s.after(),b.empty);if(i&&i.slice.size<i.to-i.from){if(e){let s=t.tr.step(i);s.setSelection(dn(n,"start")?se.findFrom(s.doc.resolve(s.mapping.map(r.pos)),1):ue.create(s.doc,s.mapping.map(r.pos))),e(s.scrollIntoView())}return!0}}return!(!n.isAtom||r.depth!=s.depth-1||(e&&e(t.tr.delete(r.pos,r.pos+n.nodeSize).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;n=mn(s)}let h=n&&n.nodeAfter;return!(!h||!ue.isSelectable(h)||(e&&e(t.tr.setSelection(ue.create(t.doc,n.pos)).scrollIntoView()),0))}));const xn={Enter:vn(((t,e)=>{let{$head:i,$anchor:s}=t.selection;return!(!i.parent.type.spec.code||!i.sameParent(s)||(e&&e(t.tr.insertText("\n").scrollIntoView()),0))}),((t,e)=>{let i=t.selection,{$from:s,$to:r}=i;if(i instanceof ae||s.parent.inlineContent||r.parent.inlineContent)return!1;let n=wn(r.parent.contentMatchAt(r.indexAfter()));if(!n||!n.isTextblock)return!1;if(e){let i=(!s.parentOffset&&r.index()<r.parent.childCount?s:r).pos,h=t.tr.insert(i,n.createAndFill());h.setSelection(oe.create(h.doc,i+1)),e(h.scrollIntoView())}return!0}),((t,e)=>{let{$cursor:i}=t.selection;if(!i||i.parent.content.size)return!1;if(i.depth>1&&i.after()!=i.end(-1)){let s=i.before();if(Bt(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let s=i.blockRange(),r=s&&jt(s);return null!=r&&(e&&e(t.tr.lift(s,r).scrollIntoView()),!0)}),((t,e)=>{let{$from:i}=t.selection;if(t.selection instanceof ue&&t.selection.node.isBlock)return!(!i.parentOffset||!Bt(t.doc,i.pos)||(e&&e(t.tr.split(i.pos).scrollIntoView()),0));if(!i.depth)return!1;let s,r,n=[],h=!1,o=!1;for(let t=i.depth;;t--){if(i.node(t).isBlock){h=i.end(t)==i.pos+(i.depth-t),o=i.start(t)==i.pos-(i.depth-t),r=wn(i.node(t-1).contentMatchAt(i.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 oe||t.selection instanceof ae)&&l.deleteSelection();let u=l.mapping.map(i.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&&i.node(s).type!=r){let t=l.mapping.map(i.before(s)),e=l.doc.resolve(t);r&&i.node(s-1).canReplaceWith(e.index(),e.index()+1,r)&&l.setNodeMarkup(l.mapping.map(i.before(s)),r)}return e&&e(l.scrollIntoView()),!0})),"Mod-Enter":(t,e)=>{let{$head:i,$anchor:s}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(s))return!1;let r=i.node(-1),n=i.indexAfter(-1),h=wn(r.contentMatchAt(n));if(!h||!r.canReplaceWith(n,n,h))return!1;if(e){let s=i.after(),r=t.tr.replaceWith(s,s,h.createAndFill());r.setSelection(se.near(r.doc.resolve(s),1)),e(r.scrollIntoView())}return!0},Backspace:kn,"Mod-Backspace":kn,"Shift-Backspace":kn,Delete:Sn,"Mod-Delete":Sn,"Mod-a":(t,e)=>(e&&e(t.tr.setSelection(new ae(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 it({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 e=this._core?.store?.state?.scale,i=null!=e&&e<0?e:1;this.width=this.initialWidth/i,this.height=1.2*this.fontSize/i,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,e,i,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=e||8,r.fontFamily=i||"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:Me.create({doc:t,plugins:[fn(Tn)]}),editable:()=>!1,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e),t.docChanged&&(this.content=e.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 e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const e=this.totalWidth,i=this.totalHeight,s=t.scrollHeight;if(this.width=t.scrollWidth*this.scaleFactor,this.height=s*this.scaleFactor,0!==this.rotation){const t=(this.totalWidth-e)/2/this.scale,s=(this.totalHeight-i)/2/this.scale;if(0!==t||0!==s){const e=Math.cos(this.rotation),i=Math.sin(this.rotation),r=i*t+e*s;this.translateX+=e*t-i*s-t,this.translateY+=r-s}}}}resize(t,e,i,s){if(i<=1||s<=1)return;const r=this.width/this.scaleFactor,n=this.height/this.scaleFactor;this.scaleFactor=Math.min(i/r,s/n),this.width=r*this.scaleFactor,this.height=n*this.scaleFactor,this.translateX=t,this.translateY=e,this._core.store.objects.update(this)}focus(t){if(this.editor){const e=this.editor.state.doc;if(t.x&&t.y&&!this.isEmpty){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(oe.create(e,i.pos))),this.editor.focus(),void(o.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(oe.create(e,i))),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(oe.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:e,_schema:i,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,e){const i=await this.ensureDb(),s=e.id??this.generateUuid(),r={id:s,kind:e.kind??"file",mimeType:e.mimeType,size:t.size,createdAt:Date.now(),width:e.width,height:e.height,durationMs:e.durationMs,originalFilename:e.originalFilename};return await new Promise(((e,n)=>{const h=i.transaction([An,Rn],"readwrite");h.oncomplete=()=>e(),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 e=this._urlCache.get(t);if(e)return e;const i=await this.fetch(t),s=URL.createObjectURL(i);return this._urlCache.set(t,s),s}async fetch(t){const e=await this.ensureDb(),i=await new Promise(((i,s)=>{const r=e.transaction(An,"readonly").objectStore(An).get(t);r.onsuccess=()=>i(r.result),r.onerror=()=>s(r.error)}));if(!i)throw new Error(`[IndexedDBAssetProvider] Asset ${t} not found`);return this._knownIds.add(t),i}async delete(t){const e=await this.ensureDb();await new Promise(((i,s)=>{const r=e.transaction([An,Rn],"readwrite");r.oncomplete=()=>i(),r.onerror=()=>s(r.error),r.objectStore(An).delete(t),r.objectStore(Rn).delete(t)}));const i=this._urlCache.get(t);if(i){try{URL.revokeObjectURL(i)}catch{}this._urlCache.delete(t)}this._knownIds.delete(t)}async getMetadata(t){const e=await this.ensureDb();return new Promise(((i,s)=>{const r=e.transaction(Rn,"readonly").objectStore(Rn).get(t);r.onsuccess=()=>i(r.result),r.onerror=()=>s(r.error)}))}async listAssetsWithPendingRemotes(){const t=await this.ensureDb();return new Promise(((e,i)=>{const s=t.transaction(Rn,"readonly").objectStore(Rn).getAll();s.onsuccess=()=>{e((s.result??[]).filter((t=>Array.isArray(t.pendingRemotes)&&t.pendingRemotes.length>0)))},s.onerror=()=>i(s.error)}))}async setPendingRemotes(t,e){const i=await this.ensureDb();await new Promise(((s,r)=>{const n=i.transaction(Rn,"readwrite");n.oncomplete=()=>s(),n.onerror=()=>r(n.error);const h=n.objectStore(Rn),o=h.get(t);o.onsuccess=()=>{const i=o.result;if(!i)return;const s={...i};e.length>0?s.pendingRemotes=e:delete s.pendingRemotes,h.put(s,t)}}))}async ensureDb(){return this._db||await this.init(),this._db}openDatabase(){return new Promise(((t,e)=>{const i=indexedDB.open(this._dbName,1);i.onupgradeneeded=()=>{const t=i.result;t.objectStoreNames.contains(An)||t.createObjectStore(An),t.objectStoreNames.contains(Rn)||t.createObjectStore(Rn)},i.onsuccess=()=>t(i.result),i.onerror=()=>e(i.error)}))}async loadKnownIds(){const t=this._db;t&&await new Promise(((e,i)=>{const s=t.transaction(Rn,"readonly").objectStore(Rn).getAllKeys();s.onsuccess=()=>{for(const t of s.result)"string"==typeof t&&this._knownIds.add(t);e()},s.onerror=()=>i(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 e=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}}class $n extends Error{assetId;constructor(t,e){super(e??`[KritzelAssetResolver] Asset ${t} not found in any configured provider.`),this.name="AssetNotFoundError",this.assetId=t}}class Pn{_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 e=this.instantiateProviders(t?.providers??[]);e.some((t=>"local"===t.type))||e.unshift(new En),e.sort(((t,e)=>"local"===t.type&&"local"!==e.type?-1:"local"!==t.type&&"local"===e.type?1:0)),this._providers=e,this._local=e.find((t=>"local"===t.type&&"IndexedDBAssetProvider"===t.name))??null,this._remoteProviders=e.filter((t=>"remote"===t.type)),this._local&&await this._local.init();for(const t of this._remoteProviders)try{await t.init()}catch(e){console.warn(`[KritzelAssetResolver] Remote provider "${t.name}" failed to initialize. Assets will be served from the local provider until the remote becomes available.`,e)}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,e){await this.ensureReady();const i=e.id??this.generateUuid(),s={...e,id:i};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(i,t);for(const e of t)this._pending.set(this.pendingKey(i,e),{id:i,providerName:e,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 e=this._resolvePromises.get(t);if(e)return e;const i=(async()=>{if(this._local&&this._local.canResolve(t))return this._local.resolve(t);let e,i=0;for(const s of this._providers)if(s!==this._local){i++;try{const e=await s.fetch(t);if(this._local){try{await this._local.put(e,{id:t,mimeType:e.type||"application/octet-stream",kind:"file"})}catch{}return this._local.resolve(t)}return URL.createObjectURL(e)}catch(t){e=t}}if(0===i)throw new $n(t);throw new Error(`[KritzelAssetResolver] Failed to resolve asset ${t}: ${String(e)}`)})();this._resolvePromises.set(t,i);try{return await i}finally{this._resolvePromises.delete(t)}}async fetchBlob(t){let e;await this.ensureReady();let i=!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?i=!0:r++;try{return await h.fetch(t)}catch(t){h===this._local&&(s=!0),e=t}}if(0===r&&(!i||s))throw new $n(t);throw new Error(`[KritzelAssetResolver] Failed to fetch blob for ${t}: ${String(e)}`)}async putDataUrl(t,e){const i=await this.dataUrlToBlob(t);return this.put(i,{...e,mimeType:e.mimeType??i.type??"application/octet-stream"})}logProviderConfiguration(){const t=[`Asset resolver initialized with ${this._providers.length} provider(s):`];for(const e of this._providers)t.push(` - ${e.name} [${e===this._local?"local (primary write target)":e.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,e){return`${t}::${e}`}async recoverPendingUploads(){if(!this._local||0===this._remoteProviders.length)return;const t=await this._local.listAssetsWithPendingRemotes(),e=new Set(this._remoteProviders.map((t=>t.name))),i=Date.now();let s=0;for(const r of t){const t=(r.pendingRemotes??[]).filter((t=>e.has(t)));if(0!==t.length)for(const e of t)this._pending.set(this.pendingKey(r.id,e),{id:r.id,providerName:e,attempts:0,nextAttemptAt:i}),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 e=Number.POSITIVE_INFINITY;for(const[i,s]of Array.from(this._pending.entries())){if(s.nextAttemptAt>t){e=Math.min(e,s.nextAttemptAt-t);continue}const r=this._remoteProviders.find((t=>t.name===s.providerName));if(!r){this._pending.delete(i);continue}let n,h;try{[n,h]=await Promise.all([this._local.fetch(s.id),this._local.getMetadata(s.id)])}catch{this._pending.delete(i);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(i),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 i=Math.min(3e5,2e3*Math.pow(2,s.attempts-1));s.nextAttemptAt=Date.now()+i,e=Math.min(e,i),console.warn(`[KritzelAssetResolver] Upload to ${r.name} failed for ${s.id} (attempt ${s.attempts}). Retrying in ${Math.round(i/1e3)}s.`,t)}}this._pending.size>0&&Number.isFinite(e)&&this.scheduleFlush(e)}async clearPendingRemote(t,e){if(!this._local)return;const i=await this._local.getMetadata(t);if(!i)return;const s=(i.pendingRemotes??[]).filter((t=>t!==e));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,e)=>{this._resolveReady=t,this._rejectReady=e}))),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 e=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}async dataUrlToBlob(t){return(await fetch(t)).blob()}}class Cn 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 e=new Cn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.x=0,e.y=0,e.translateX=0,e.translateY=0,e.scale=e._core.store.state.scale,e.zIndex=t.store.currentZIndex,e}resize(t,e,i,s){if(i<=1||s<=1)return;const r=s/this.height;this.width=this.width*r,this.height=this.height*r,this.translateX=t,this.translateY=e,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 Cn&&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((e=>{if(e 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}):`,e),t?(this.loadState="error",void this._core?.rerender()):void this.scheduleRetry(this.loadAttempts)}const i=Date.now();null===this.transientRetryStartedAt&&(this.transientRetryStartedAt=i);const s=i-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):`,e),r)return this.loadState="error",void this._core?.rerender();this.scheduleRetry(t+1)}))}scheduleRetry(t){this.loadState="idle";const e=Math.min(2e3,250*Math.pow(2,Math.max(0,t-1)));setTimeout((()=>{"idle"===this.loadState&&this.ensureResolved()}),e)}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,e){return new Promise(((i,s)=>{const r=new Image;r.onload=()=>{const s=new Cn({...e,src:t}),{scaledWidth:n,scaledHeight:h}=s.calculateScaledDimensions(r);s.width=n,s.height=h,i(s)},r.onerror=t=>s(t),r.src=t}))}calculateScaledDimensions(t){let e=t.width,i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);e=t.width*s,i=t.height*s}return{scaledWidth:e,scaledHeight:i}}}class Nn{static isInstanceOf(t,e){return!!t&&t.__class__===e}}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 e=this._core.store.objects.filter((e=>e.id===t));return e.length>0?e[0]:null})).filter((t=>null!==t)):this._pendingChildren}get length(){return this.childIds.length}static create(t){const e=new In;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.scale=t.store.state.scale,e.zIndex=t.store.currentZIndex,e}static createFromObjects(t,e){const i=In.create(t);return e.forEach((t=>{i.childIds.push(t.id)})),i.refreshBoundingBox(),i.captureChildSnapshots(),i}static findParentGroup(t,e){const i=t.store.objects.filter((t=>"KritzelGroup"===t.__class__));for(const t of i)if(t.childIds.includes(e))return t;return null}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 e=this.childIds.indexOf(t);-1!==e&&(this.childIds.splice(e,1),this.refreshBoundingBox(),this.captureChildSnapshots())}ungroup(){return this.children}finalize(){this.refreshBoundingBox(),this.captureChildSnapshots()}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:s,scale:r}=this._core.store.state,{x:n,y:h,width:o,height:l}=this.rotatedBoundingBox,u=(t/2-i)/r-(n+o/2),f=(e/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,e=Math.cos(-t),i=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*e-t.y*i,l=t.x*i+t.y*e;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,e,i,s){const r=(t-i)/this._core.store.state.scale,n=(e-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,e,i,s),this._core.anchorManager.updateAnchorsForObject(r.id)}))})),this.unchangedChildSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}resize(t,e,i,s){const r=i/this.width,n=s/this.height,h=this.translateX+this.totalWidth/2/this.scale,o=this.translateY+this.totalHeight/2/this.scale,l=t+(i+2*this.padding)/2/this.scale,u=e+(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((()=>{this.children.forEach((t=>{const e=t.translateX+t.totalWidth/2/t.scale-h,i=t.translateY+t.totalHeight/2/t.scale-o,s=(e*a-i*c)*r,m=(e*c+i*a)*n,w=l+(s*d-m*p),g=u+(s*p+m*d),y=t.rotation-f,b=Math.cos(y),M=Math.sin(y),v=Math.sqrt(Math.pow(r*b,2)+Math.pow(n*M,2)),k=Math.sqrt(Math.pow(r*M,2)+Math.pow(n*b,2)),S=t.width*v,x=t.height*k;t.resize(w-(S+2*t.padding)/2/t.scale,g-(x+2*t.padding)/2/t.scale,S,x),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshBoundingBox(),this.captureChildSnapshots(),this._core.store.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=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=e+(r*l-n*u)-h.totalWidth/2/h.scale,h.translateY=i+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,e){return this.children.some((i=>i.hitTest(t,e)))}hitTestPolygon(t){return this.children.some((e=>e.hitTestPolygon(t)))}copy(){const t=In.create(this._core),e=[];return this.children.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((i=>{const s=i.copy();e.push(s),t.childIds.push(s.id)})),t._pendingChildren=e,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:e,element:i,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((e=>{e.workspaceId=t,Nn.isInstanceOf(e,"KritzelGroup")&&e.updateWorkspaceId(t)}))}}var zn,jn;!function(t){t.Rectangle="rectangle",t.Ellipse="ellipse",t.Triangle="triangle"}(zn||(zn={}));class _n 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 it({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,e){const i=new _n;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.id,i.x=e?.x??0,i.y=e?.y??0,i.translateX=e?.translateX??0,i.translateY=e?.translateY??0,i.width=e?.width??100,i.height=e?.height??100,i.shapeType=e?.shapeType??zn.Rectangle,i.fillColor=e?.fillColor??{light:"transparent",dark:"transparent"},i.strokeColor=e?.strokeColor??e?.fillColor??{light:"#000000",dark:"#ffffff"},i.strokeWidth=e?.strokeWidth??4,i.opacity=e?.opacity??1,i.fontSize=e?.fontSize??16,i.fontFamily=e?.fontFamily??"Arial",i.fontColor=e?.fontColor??r.determineTextColor(i.fillColor),i.backgroundColor={light:"transparent",dark:"transparent"},i.scaleFactor=1,i.scale=e?.scale??t.store.state.scale,i.zIndex=t.store.currentZIndex,i.editor=i.createEditor(),i.updateDimensions(),i}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:Me.create({doc:t,plugins:[fn(Tn)]}),editable:()=>!1,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e),t.docChanged&&(this.content=e.doc.toJSON(),t.getMeta("fromRemote")||this._core.store.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.objects.update(this))}focus(t){if(!this.editor)return;const e=this.editor.state.doc;if(t?.x&&t?.y){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(oe.create(e,i.pos))),this.editor.focus(),void(o.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(oe.create(e,i))),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(oe.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:e,_schema:i,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,i=this.totalHeight/this.scale,s=this.translateX+t/2,r=this.translateY+i/2,n=this.strokeWidth/this.scale/2;switch(this.shapeType){case zn.Ellipse:return e.getEllipsePolygonApproximation(s,r,t/2+n,i/2+n,32,this.rotation);case zn.Triangle:const h=(t,e)=>{const i=t-s,h=e-r,o=Math.sqrt(i*i+h*h);if(0===o)return{x:t,y:e};const l=(o+n)/o;return{x:s+i*l,y:r+h*l}},o=this.translateX,l=this.translateY+i,u=this.translateX+t,f=this.translateY+i,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),e=Math.sin(this.rotation),i=i=>{const n=i.x-s,h=i.y-r;return{x:s+n*t-h*e,y:r+n*e+h*t}};return[i(a),i(c),i(d)]}return[a,c,d];default:return null}}getSvgPath(){const t=this.width,e=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+e} L ${this.x} ${this.y+e} Z`;case zn.Ellipse:const i=this.x+t/2,s=this.y+e/2,r=t/2,n=e/2;return`M ${i-r} ${s} A ${r} ${n} 0 1 0 ${i+r} ${s} A ${r} ${n} 0 1 0 ${i-r} ${s}`;case zn.Triangle:return`M ${this.x+t/2} ${this.y} L ${this.x+t} ${this.y+e} L ${this.x} ${this.y+e} Z`;default:return`M ${this.x} ${this.y} L ${this.x+t} ${this.y} L ${this.x+t} ${this.y+e} L ${this.x} ${this.y+e} 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,e,i){if("touch"!==t.pointerType)return i?.(),()=>{};const s=t.clientX,r=t.clientY,n=t.target;if(!n)return i?.(),()=>{};const h=setTimeout((()=>{a(),e(t)}),400),o=()=>{clearTimeout(h),a(),i?.()},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 e=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?e:1,n=i.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:e,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 e=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?e: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=i.create(this._core,{points:[[n,h]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?1:e,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 e=this._core.store.objects.findById(this._currentPathId);if(e){const s=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?s:1,h=i.create(this._core,{points:[...e.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=e.id,h.workspaceId=e.workspaceId,h.zIndex=e.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 e=this._core.store.objects.findById(this._currentPathId);if(e){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=i.create(this._core,{points:[...e.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=e.id,l.workspaceId=e.workspaceId,l.zIndex=e.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}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}}}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 e=new Set(this._objectIds),i=this._core.store.objects.filter((t=>e.has(t.id))),s=new Map(i.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 e=new Jn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.clientId=t.store.objects?.localClientId??void 0,e.scale=t.store.state.scale,e.zIndex=99999,e.borderColor={light:"#007AFF",dark:"#0A84FF"},e.borderWidth=2,e.handleColor={light:"#ffffff",dark:"#1a1a1a"},e.handleStrokeColor={light:"#007AFF",dark:"#0A84FF"},e.handleSize=6,e}addObjects(t){let e=!1;for(const i of t)this._objectIds.includes(i.id)||(this._objectIds.push(i.id),e=!0);if(e){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 e=this._objectIds.findIndex((e=>e===t.id));-1===e?this._objectIds.push(t.id):this._objectIds.splice(e,1),this._cachedObjects=null;const i=this.objects;1===i.length?this.rotation=i[0].rotation:i.length>1&&(this.rotation=0),this.captureUnchangedSnapshots(i),this.refreshObjectDimensions(i)}beginTransform(){const t=this.objects;this.refreshObjectDimensions(t),this.captureUnchangedSnapshots(t);for(const e of t)Nn.isInstanceOf(e,"KritzelGroup")&&e.finalize()}deselectAllChildren(){const t=this.objects;for(const e of t)e.isSelected=!1}updateWorkspaceId(t){this.workspaceId=t;const e=this.objects;for(const i of e)i.workspaceId=t}updateZIndices(t){const e=this.objects;for(let i=0;i<e.length;i++)e[i].zIndex=t+i}updatePosition(t,e){const i=this.objects;for(const s of i)s.updatePosition(t+(s.translateX-this.translateX),e+(s.translateY-this.translateY));this.unchangedObjectSnapshots.forEach((i=>{const s=i.translateY-this.translateY;i.translateX=t+(i.translateX-this.translateX),i.translateY=e+s})),this.translateX=t,this.translateY=e,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:e,element:i,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,i&&"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&(p.element=i.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,e,i,s){const r=(t-i)/this._core.store.state.scale,n=(e-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,e,i,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,e,i,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 e of t)this._core.store.objects.update(e)}))}resize(t,e,i,s){const r=i/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+(i+2*this.padding)/2/this.scale,u=e+(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 e=this.unchangedObjectSnapshots.get(t.id);if(!e)return;const i=e.translateX+e.totalWidth/2/e.scale-h,s=e.translateY+e.totalHeight/2/e.scale-o,m=(i*a-s*c)*r,w=(i*c+s*a)*n,g=l+(m*d-w*p),y=u+(m*p+w*d),b=e.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=e.width*k,O=e.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 e=this.translateX+this.totalWidth/2/this.scale,i=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=e+(r*u-n*f)-l.totalWidth/2/l.scale,l.translateY=i+a-l.totalHeight/2/l.scale,l.rotate(1===o?t:h.rotation+s)}}))}copy(){const t=Jn.create(this._core),e=this.objects,i=[...e].sort(((t,e)=>t.zIndex-e.zIndex));for(const e of i){const i=e.copy();t.addOrRemove(i)}return t.captureUnchangedSnapshots(),1===e.length&&(t.rotation=e[0].rotation),t}refreshObjectDimensions(t,e=!1){const i=t??this.objects;if(1===i.length){const t=i[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,e=Math.cos(-t),s=Math.sin(-t);let r=1/0,n=-1/0,h=1/0,o=-1/0;i.forEach((t=>{const i=t.rotatedPolygon;[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft].forEach((t=>{const i=t.x*e-t.y*s,l=t.x*s+t.y*e;i<r&&(r=i),i>n&&(n=i),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}e||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,i){const s=this.objects;if(1===s.length&&"KritzelLine"===s[0].__class__)return s[0].hitTest(t,i);const r=this.rotatedPolygon;if(e.isPointInPolygon({x:t,y:i},[r.topLeft,r.topRight,r.bottomRight,r.bottomLeft]))return!0;for(const e of s)if(e.hitTest(t,i))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 e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?e: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:i?1:e,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 e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?e: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:i?1:e,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 e=this._core.store.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?i: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:i,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});h.id=e.id,h.workspaceId=e.workspaceId,h.zIndex=e.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 e=this._core.store.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?i: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:i,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});l.id=e.id,l.workspaceId=e.workspaceId,l.zIndex=e.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}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}}selectLineAndSwitchTool(t){const e=Jn.create(this._core);e.addOrRemove(t),e.isSelected=!0,e.rotation=t.rotation,this._core.addSelectionGroup(e),this._core.store.setState("activeTool",l.getTool("selection")),this._core.rerender()}}class Yn extends Bn{fontFamily="Arial";fontSize=16;fontColor=n[0];opacity=1;palette=[...n];constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=e?.id?this._core.findObjectById(e.id):null,s=this._core.store.activeText;if(null===s&&i instanceof Dn)return void i.edit(t);if(null!==s&&i instanceof Dn)return s.save(),void i.edit(t);if(null!==s&&i 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 e=Array.from(this._core.store.state.pointers.values()),i=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=i?.id?this._core.findObjectById(i.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(e.length>1)return;const n=Math.round(e[0].clientX-this._core.store.offsetX),h=Math.round(e[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 e=this._core.store.activeText;e&&e.isMounted&&!e.editor?.hasFocus()&&e.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 e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=this._core.findObjectById(e?.id),s=this._core.store.activeShape;if(null===s&&i instanceof _n)return void i.edit(t);if(null!==s&&i instanceof _n)return s.save(),void i.edit(t);if(null!==s&&i instanceof _n==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 e=Array.from(this._core.store.state.pointers.values()),i=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=this._core.findObjectById(i?.id),r=this._core.store.activeShape;if(null===r&&s instanceof _n)return void s.edit(t);if(null!==r&&s instanceof _n)return r.save(),void s.edit(t);if(null!==r&&s instanceof _n==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",l.getTool("selection"));if(e.length>1)return;const n=Math.round(e[0].clientX),h=Math.round(e[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 e=Math.round(t[0].clientX),i=Math.round(t[0].clientY);this.updateShapeSize(e,i)}}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&this.finishDrawing()}startDrawing(t,e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1;this.startX=(t-this._core.store.offsetX)/r,this.startY=(e-this._core.store.offsetY)/r,this.isDrawing=!0,this.currentShape=_n.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:i}),this._core.store.objects.insert(this.currentShape),this._core.store.objects?.setActiveDrawingObject(this.currentShape.id),this._core.rerender()}updateShapeSize(t,e){if(!this.currentShape)return;const i=this._core.store.state.lockDrawingScale?this._core.store.state.scale:1,s=(t-this._core.store.offsetX)/i,r=(e-this._core.store.offsetY)/i,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/i,this.currentShape.translateY=-this._core.store.state.translateY/i,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((e=>e.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.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 e=this._core.store.selectionGroup,i=t.shiftKey||t.ctrlKey;if(!e?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||i)this.trackedPointerId=null;else{const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this._core.store.state.isDragging=!0,this.dragStartX=e,this.dragStartY=i,this.startX=this.dragStartX,this.startY=this.dragStartY,this.initialDragX=e,this.initialDragY=i,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}else this.trackedPointerId=null;if("touch"===t.pointerType||"pen"===t.pointerType){const e=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 i=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(!i?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||s)this.trackedPointerId=null;else{const i=Math.round(e[0].clientX-this._core.store.offsetX),s=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i,this.dragStartY=s,this.startX=i,this.startY=s,this.initialDragX=i,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 e=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&e){const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this.endX=i,this.endY=s;const r=Math.abs(i-this.startX),n=Math.abs(s-this.startY),h=5;(this.hasMoved||r>h||n>h)&&(this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,this.hasMoved=!0)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=this._core.store.selectionGroup;if(1===this._core.store.state.pointers.size&&e&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected&&!this._core.store.state.isScaling){const i=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=i,this.endY=s;const r=Math.abs(i-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(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,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)),"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.reset())}checkAndDisconnectAnchors(t,e){const i=t-this.initialDragX,r=e-this.initialDragY;if(Math.sqrt(i*i+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 e=t;(e.startAnchor||e.endAnchor)&&(e.startAnchor&&this._core.anchorManager.removeAnchor(e.id,"start"),e.endAnchor&&this._core.anchorManager.removeAnchor(e.id,"end"),this.disconnectedLineIds.add(e.id),this._core.store.objects.update(e))}}}!function(t){t.TopLeft="top-left",t.TopRight="top-right",t.BottomLeft="bottom-left",t.BottomRight="bottom-right"}(jn||(jn={}));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 e=this._core.store.selectionGroup;if(e&&this._core.store.state.isResizeHandleSelected){e.beginTransform();const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=e.width,this.initialSize.height=e.height,this.initialSize.x=e.translateX,this.initialSize.y=e.translateY}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=t[0];if(!e)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isResizeHandleSelected){t.beginTransform();const i=Math.round(e.clientX-this._core.store.offsetX),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=i,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 e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=t.clientX-this._core.store.offsetX-this.initialMouseX,s=t.clientY-this._core.store.offsetY-this.initialMouseY,r=Math.abs(i),n=Math.abs(s),h=5;if((r>h||n>h)&&(this.hasResized=!0),!this.hasResized)return;const o=e.rotation,l=Math.sin(o),u=Math.cos(o),f=e.scale||1,a=this._core.store.state.scale,c=(i*u+s*l)/a,d=(-i*l+s*u)/a,p=this.initialSize.x+this.initialSize.width/f/2+i/a/2,m=this.initialSize.y+this.initialSize.height/f/2+s/a/2;switch(this._core.store.state.resizeHandleType){case jn.TopLeft:this.newSize.width=this.initialSize.width-c*f,this.newSize.height=this.initialSize.height-d*f;break;case jn.TopRight:this.newSize.width=this.initialSize.width+c*f,this.newSize.height=this.initialSize.height-d*f;break;case jn.BottomLeft:this.newSize.width=this.initialSize.width-c*f,this.newSize.height=this.initialSize.height+d*f;break;case jn.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,e.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 e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=Math.round(t.clientX-this._core.store.offsetX),s=Math.round(t.clientY-this._core.store.offsetY),r=i-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=e.rotation,f=Math.sin(u),a=Math.cos(u),c=e.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 jn.TopLeft:this.newSize.width=this.initialSize.width-p*c,this.newSize.height=this.initialSize.height-m*c;break;case jn.TopRight:this.newSize.width=this.initialSize.width+p*c,this.newSize.height=this.initialSize.height-m*c;break;case jn.BottomLeft:this.newSize.width=this.initialSize.width-p*c,this.newSize.height=this.initialSize.height+m*c;break;case jn.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,e.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}}constrainToAspectRatio(){const t=this.initialSize.width,e=this.initialSize.height;if(0===t||0===e)return;const i=t/e,s=this.newSize.height/e;Math.abs(this.newSize.width/t-1)>Math.abs(s-1)?this.newSize.height=this.newSize.width/i:this.newSize.width=this.newSize.height*i}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.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.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 e=this._core.store.selectionGroup;if(e&&this._core.store.state.isRotationHandleSelected){e.beginTransform();const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=!0;const r=e.scale||1,n=e.translateX+e.width/2/r,h=e.translateY+e.height/2/r,o=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=e.rotation,this.initialRotation=Math.atan2(h-l,n-o)-e.rotation}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=t[0];if(!e)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isRotationHandleSelected){t.beginTransform();const i=Math.round(e.clientX-this._core.store.offsetX),s=Math.round(e.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=(i-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 e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=e.scale||1,s=Math.atan2(e.translateY+e.height/2/i-(t.clientY-this._core.store.offsetY-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/i-(t.clientX-this._core.store.offsetX-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=s-this.initialRotation,e.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 e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=Math.round(t.clientX-this._core.store.offsetX),s=Math.round(t.clientY-this._core.store.offsetY),r=e.scale||1,n=Math.atan2(e.translateY+e.height/2/r-(s-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/r-(i-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=n-this.initialRotation,e.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.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.reset();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}class Gn extends t{__class__="KritzelSelectionBox";static create(t){const e=new Gn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.scale=t.store.state.scale,e.zIndex=99999,e.backgroundColor={light:"rgba(0, 122, 255, 0.2)",dark:"rgba(0, 122, 255, 0.2)"},e.borderColor={light:"rgba(0, 122, 255, 0.5)",dark:"rgba(0, 122, 255, 0.5)"},e.borderWidth=2,e.height=0,e.width=0,e}}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 e=t.shiftKey||t.ctrlKey;"mouse"===t.pointerType&&(!Fn.isLeftClick(t)||this._core.store.selectionGroup&&!e||this.startMouseSelection(t,e)),"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&&!e||(this.startTouchSelection(t,e),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()),e=Math.round(t[0].clientX-this._core.store.offsetX),i=Math.round(t[0].clientY-this._core.store.offsetY),s=Math.abs(e-this.touchStartX),r=Math.abs(i-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 e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||s||i.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting){if(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag){const e=t.shiftKey||t.ctrlKey;this.updateMouseSelection(t),this.addSelectedObjectsToSelectionGroup(e),this.removeSelectionBox()}this._core.engine.emitObjectsChange()}}if("touch"===t.pointerType||"pen"===t.pointerType){clearTimeout(this.touchStartTimeout);const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||s||i.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting){if(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag){const e=t.shiftKey||t.ctrlKey;this.updateTouchSelection(),this.addSelectedObjectsToSelectionGroup(e),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,e=!1){let i,s;i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;const r=Gn.create(this._core);this.startX=(i-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||!e&&t instanceof Jn&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.objects.insert(r),this._core.store.setSelectionBox(r)}startTouchSelection(t,e=!1){const i=Array.from(this._core.store.state.pointers.values())[0];if(!i)return;let s,r;s=Math.round(i.clientX-this._core.store.offsetX),r=Math.round(i.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||!e&&t instanceof Jn&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.objects.insert(n),this._core.store.setSelectionBox(n)}updateMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,r=(i-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 e,i;e=Math.round(t.clientX-this._core.store.offsetX),i=Math.round(t.clientY-this._core.store.offsetY);const s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,r=(i-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 e=t.rotatedPolygon,i=[e.topLeft.x,e.topRight.x,e.bottomRight.x,e.bottomLeft.x],s=[e.topLeft.y,e.topRight.y,e.bottomRight.y,e.bottomLeft.y],r=Math.min(...i),n=Math.max(...i),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 i=t.hitTestPolygon(e);t.isSelected=i,i&&u.add(t)}for(const t of this._previouslySelectedObjects)u.has(t)||(t.isSelected=!1);this._previouslySelectedObjects=u}handleSelectionClick(t){const e=this.getTopmostHitObject(t),i=t.shiftKey||t.ctrlKey;this.clearSelectionPreview(),e&&this.addObjectToSelectionGroup(e,i),this.removeSelectionBox()}getTopmostHitObject(t){const e=this._core.store.state.pointerX,i=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(e,i))return t;return null}clearSelectionPreview(){for(const t of this._previouslySelectedObjects)t.isSelected=!1;this._previouslySelectedObjects.clear()}addObjectToSelectionGroup(t,e=!1){if(!t)return;const i=In.findParentGroup(this._core,t.id)||t;i.isSelected=!1;const s=this._core.store.selectionGroup;if(e&&s)s.addOrRemove(i),0===s.objects.length?this._core.removeSelectionGroup():this._core.rerender();else{const t=Jn.create(this._core);t.addOrRemove(i),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}addSelectedObjectsToSelectionGroup(t=!1){const e=this._core.store.selectedObjects;if(0===e.length)return;const i=this._core.store.objects.filter((t=>"KritzelGroup"===t.__class__)),s=new Map;for(const t of i)for(const e of t.childIds)s.set(e,t);const r=new Map;for(const t of e){const e=s.get(t.id)||t;r.set(e.id,e),t.isSelected=!1}const n=Array.from(r.values()),h=this._core.store.selectionGroup;if(t&&h)h.addObjects(n),this._core.rerender();else{const t=Jn.create(this._core);t.objectIds=Array.from(r.keys()),1===t.length&&(t.rotation=t.objects[0].rotation),t.captureUnchangedSnapshots(),t.refreshObjectDimensions(),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}}class Zn extends Un{constructor(t){super(t)}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.getObjectFromPointerEvent(t,".object");if(!e)return;e.isHovered=e.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 e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleSelected)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isLineHandleDragging=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialStartX=e.startX,this.initialStartY=e.startY,this.initialEndX=e.endX,this.initialEndY=e.endY,this.initialControlX=e.controlX,this.initialControlY=e.controlY,this.initialTranslateX=e.translateX,this.initialTranslateY=e.translateY;const r=this._core.store.state.lineHandleType;"start"!==r&&"end"!==r||this._core.anchorManager.removeAnchor(e.id,r);const n=this._core.store.state.longTouchTimeout;n&&globalThis.clearTimeout?.(n)}handlePointerMove(t){const e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleDragging)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY,n=i-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=e.scale||1,u=e.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=(i-this._core.store.state.translateX)/o,n=(s-this._core.store.state.translateY)/o,h=e.endAnchor?.objectId,l=this._core.anchorManager.findSnapTarget(t,n,e.id,h);if(this.currentSnapTarget=l,l){const t=this.worldToLineLocal(e,l.centerX,l.centerY);this.updateLineEndpoint(e,t.x,t.y,this.initialEndX,this.initialEndY);const i=this.lineLocalToWorld(e,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(e,"start",s);t&&(n=t.worldX,h=t.worldY,o=t.t)}void 0!==e.controlX&&void 0!==e.controlY&&(u=this.lineLocalToWorld(e,e.controlX,e.controlY)),this._core.anchorManager.setSnapCandidate({objectId:l.objectId,endpoint:"start",centerX:l.centerX,centerY:l.centerY,lineEndpointX:i.x,lineEndpointY:i.y,controlX:u?.x,controlY:u?.y,t:o,edgeX:n,edgeY:h,lineStroke:r.resolveThemeColor(e.stroke),lineStrokeWidth:e.strokeWidth/e.scale,arrowOffset:e.hasStartArrow?e.getArrowSize("start")/e.scale:void 0,arrowStyle:e.hasStartArrow?e.arrows?.start?.style:void 0,arrowFill:e.hasStartArrow?e.getArrowFill("start"):void 0})}else this.updateLineEndpoint(e,this.initialStartX+p,this.initialStartY+m,this.initialEndX,this.initialEndY),this._core.anchorManager.clearSnapCandidate()}else if("end"===w){const t=(i-this._core.store.state.translateX)/o,n=(s-this._core.store.state.translateY)/o,h=e.startAnchor?.objectId,l=this._core.anchorManager.findSnapTarget(t,n,e.id,h);if(this.currentSnapTarget=l,l){const t=this.worldToLineLocal(e,l.centerX,l.centerY);this.updateLineEndpoint(e,this.initialStartX,this.initialStartY,t.x,t.y);const i=this.lineLocalToWorld(e,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(e,"end",s);t&&(n=t.worldX,h=t.worldY,o=t.t)}void 0!==e.controlX&&void 0!==e.controlY&&(u=this.lineLocalToWorld(e,e.controlX,e.controlY)),this._core.anchorManager.setSnapCandidate({objectId:l.objectId,endpoint:"end",centerX:l.centerX,centerY:l.centerY,lineEndpointX:i.x,lineEndpointY:i.y,controlX:u?.x,controlY:u?.y,t:o,edgeX:n,edgeY:h,lineStroke:r.resolveThemeColor(e.stroke),lineStrokeWidth:e.strokeWidth/e.scale,arrowOffset:e.hasEndArrow?e.getArrowSize("end")/e.scale:void 0,arrowStyle:e.hasEndArrow?e.arrows?.end?.style:void 0,arrowFill:e.hasEndArrow?e.getArrowFill("end"):void 0})}else this.updateLineEndpoint(e,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,i=(this.initialControlY??(this.initialStartY+this.initialEndY)/2)+2*m,s=e.startX,r=e.startY,n=e.endX,h=e.endY,o=n-s,l=h-r,u=o*o+l*l;let f,a,c=-1;0!==u&&(c=((t-s)*o+(i-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=i-a;Math.sqrt(d*d+w*w)<15?e.updateControlPoint(void 0,void 0):e.updateControlPoint(t,i)}this._core.rerender()}worldToLineLocal(t,e,i){const s=(e-t.translateX)*t.scale,r=(i-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,e,i){const s=e-t.x,r=i-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,e,i,r,n){const{minX:h,minY:o,maxX:l,maxY:u}=s.calculateBoundingBox(e,i,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=e,t.startY=i,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(),e=this._core.store.state.lineHandleType;if(t&&this.hasMoved){!this.currentSnapTarget||"start"!==e&&"end"!==e||this._core.anchorManager.setAnchor(t.id,e,this.currentSnapTarget.objectId);const i=this._core.store.selectionGroup;i&&(i.refreshObjectDimensions(),i.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0)}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 e=t.objects[0];return e instanceof s?e: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 e=[];for(const i of t)Nn.isInstanceOf(i,"KritzelGroup")?e=e.concat(this.flattenObjects(i.children)):e.push(i);return e}get color(){const t=this.flattenObjects(this.getSelectedObjects());if(0===t.length)return n[0];for(const e of t){if(e instanceof i)return e.fill;if(e instanceof s)return e.stroke;if(e instanceof Dn)return e.fontColor;if(e instanceof _n)return e.strokeColor}return n[0]}set color(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof i&&this._core.updateObject(e,{fill:t}),e instanceof s&&this._core.updateObject(e,{stroke:t}),e instanceof Dn&&this._core.updateObject(e,{fontColor:t}),e instanceof _n&&this._core.updateObject(e,{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((e=>this._core.updateObject(e,{opacity:t}))),this._core.rerender()}get size(){const t=this.flattenObjects(this.getSelectedObjects());if(0===t.length)return 1;for(const e of t){if(e instanceof i)return e.strokeWidth;if(e instanceof s)return e.strokeWidth;if(e instanceof Dn)return e.fontSize;if(e instanceof _n)return e.strokeWidth}return 1}set size(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof i&&this._core.updateObject(e,{strokeWidth:t}),e instanceof s&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Dn&&this._core.updateObject(e,{fontSize:t}),e instanceof _n&&this._core.updateObject(e,{strokeWidth:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}get fillColor(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t)if(e instanceof _n)return e.fillColor;return{light:"transparent",dark:"transparent"}}set fillColor(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{if(e instanceof _n){const i=r.determineTextColor(t);this._core.updateObject(e,{fillColor:t,fontColor:i}),("string"==typeof t?"transparent"===t:"transparent"===t.light&&"transparent"===t.dark)||this._core.updateObject(e,{strokeColor:t})}})),this._core.rerender()}get fontFamily(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t){if(e instanceof Dn)return e.fontFamily;if(e instanceof _n)return e.fontFamily}return"Arial"}set fontFamily(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Dn&&this._core.updateObject(e,{fontFamily:t}),e instanceof _n&&this._core.updateObject(e,{fontFamily:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}get arrows(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t)if(e instanceof s)return e.arrows??{start:{enabled:!1},end:{enabled:!1}};return{start:{enabled:!1},end:{enabled:!1}}}set arrows(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof s&&this._core.updateObject(e,{arrows:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}getToolConfig(){if(!this.hasSelection())return null;const t=this.flattenObjects(this.getSelectedObjects()),e=[],r=t.some((t=>t instanceof _n)),n=t.some((t=>t instanceof Dn)),h=t.some((t=>t instanceof s)),o=t.some((t=>t instanceof Cn)),l=t.some((t=>t instanceof i||t instanceof s||t instanceof _n));return!o||r||n||h||l?(n&&!l?(e.push({type:"font-size",propertyName:"size"}),e.push({type:"font-family",propertyName:"fontFamily"})):l&&!n?e.push({type:"stroke-size",propertyName:"size"}):(l&&e.push({type:"stroke-size",propertyName:"size"}),n&&e.push({type:"font-family",propertyName:"fontFamily"})),h&&e.push({type:"line-endings",propertyName:"arrows"}),r&&e.push({type:"shape-fill",propertyName:"fillColor"}),{type:"selection",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"palette",controls:e}):{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 e=this.getSelectedObject(t),i=this._core.store.selectionGroup;if(null!==e&&!(e&&i&&e.id!==i.id)||!i||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()),e&&!1===e.isSelected&&1===e?.objects.length&&e.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 e=this.getSelectedObject(t),i=this._core.store.selectionGroup,s=e&&i&&e.id!==i.id,r=t.shiftKey||t.ctrlKey;!i&&e&&(this._core.store.state.skipContextMenu=!0),null!==e&&!s||!i||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 e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=e?.id?this._core.findObjectById(e.id):null;if(!i)return null;const{x:s,y:r}=this._core.getCanvasPoint(t);if(!i.hitTest(s,r))return null;if(i instanceof Jn)return i;{const t=Jn.create(this._core);return t.translateX=0,t.translateY=0,t.addOrRemove(i),t}}getHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("resize-handle-overlay")));return i?.classList[1]}isHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("resize-handle-overlay")))}isRotationHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("rotation-handle-overlay")))}isLineHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("selection-line-handle-overlay")))}getLineHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("selection-line-handle-overlay")));return i?.classList[1]}}export{$n as A,En as I,Dn as K,zn as S,Cn as a,In as b,_n as c,Wn as d,Ln as e,Yn as f,Xn as g,th as h,Pn 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}
|
|
1
|
+
import{c as t,b as e,K as i,a as s}from"./p-u-827ZX7.js";import{a as r,D as n}from"./p-BCzbwL4m.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,e,i){const s=new e(i);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 e=t.getAttribute("content");e?.includes("interactive-widget=resizes-content")||(e+=", interactive-widget=resizes-content"),e&&t.setAttribute("content",e)}}static disableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let e=t.getAttribute("content"),i=e?.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");void 0!==i&&(i=i.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim(),t.setAttribute("content",i))}}static onKeyboardVisibleChanged(t){if("visualViewport"in window){const e=.75,i=i=>{const s=i.target,r=o.isMobile(),n=s.height*s.scale/window.screen.height<e;t(r&&n)};return window.visualViewport?.addEventListener("resize",i),()=>window.visualViewport?.removeEventListener("resize",i)}return console.warn("Listening for keyboard visibility changes is not reliably supported in this browser."),()=>{}}}function f(t){this.content=t}function a(t,e,i){for(let s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:i;let r=t.child(s),n=e.child(s);if(r!=n){if(!r.sameMarkup(n))return i;if(r.isText&&r.text!=n.text){for(let t=0;r.text[t]==n.text[t];t++)i++;return i}if(r.content.size||n.content.size){let t=a(r.content,n.content,i+1);if(null!=t)return t}i+=r.nodeSize}else i+=r.nodeSize}}function c(t,e,i,s){for(let r=t.childCount,n=e.childCount;;){if(0==r||0==n)return r==n?null:{a:i,b:s};let h=t.child(--r),o=e.child(--n),l=h.nodeSize;if(h!=o){if(!h.sameMarkup(o))return{a:i,b:s};if(h.isText&&h.text!=o.text){let t=0,e=Math.min(h.text.length,o.text.length);for(;t<e&&h.text[h.text.length-t-1]==o.text[o.text.length-t-1];)t++,i--,s--;return{a:i,b:s}}if(h.content.size||o.content.size){let t=c(h.content,o.content,i-1,s-1);if(t)return t}i-=l,s-=l}else i-=l,s-=l}}f.prototype={constructor:f,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return-1==e?void 0:this.content[e+1]},update:function(t,e,i){var s=i&&i!=t?this.remove(i):this,r=s.find(t),n=s.content.slice();return-1==r?n.push(i||t,e):(n[r+1]=e,i&&(n[r]=i)),new f(n)},remove:function(t){var e=this.find(t);if(-1==e)return this;var i=this.content.slice();return i.splice(e,2),new f(i)},addToStart:function(t,e){return new f([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var i=this.remove(t).content.slice();return i.push(t,e),new f(i)},addBefore:function(t,e,i){var s=this.remove(e),r=s.content.slice(),n=s.find(t);return r.splice(-1==n?r.length:n,0,e,i),new f(r)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+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 e=this;t=f.from(t);for(var i=0;i<t.content.length;i+=2)e=e.remove(t.content[i]);return e},toObject:function(){var t={};return this.forEach((function(e,i){t[e]=i})),t},get size(){return this.content.length>>1}},f.from=function(t){if(t instanceof f)return t;var e=[];if(t)for(var i in t)e.push(i,t[i]);return new f(e)};class d{constructor(t,e){if(this.content=t,this.size=e||0,null==e)for(let e=0;e<t.length;e++)this.size+=t[e].nodeSize}nodesBetween(t,e,i,s=0,r){for(let n=0,h=0;h<e;n++){let o=this.content[n],l=h+o.nodeSize;if(l>t&&!1!==i(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,e-r),i,s+r)}h=l}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,i,s){let r="",n=!0;return this.nodesBetween(t,e,((h,o)=>{let l=h.isText?h.text.slice(Math.max(t,o)-o,e-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)&&i&&(n?n=!1:r+=i),r+=l}),0),r}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,i=t.firstChild,s=this.content.slice(),r=0;for(e.isText&&e.sameMarkup(i)&&(s[s.length-1]=e.withText(e.text+i.text),r=1);r<t.content.length;r++)s.push(t.content[r]);return new d(s,this.size+t.size)}cut(t,e=this.size){if(0==t&&e==this.size)return this;let i=[],s=0;if(e>t)for(let r=0,n=0;n<e;r++){let h=this.content[r],o=n+h.nodeSize;o>t&&((n<t||o>e)&&(h=h.isText?h.cut(Math.max(0,t-n),Math.min(h.text.length,e-n)):h.cut(Math.max(0,t-n-1),Math.min(h.content.size,e-n-1))),i.push(h),s+=h.nodeSize),n=o}return new d(i,s)}cutByIndex(t,e){return t==e?d.empty:0==t&&e==this.content.length?this:new d(this.content.slice(t,e))}replaceChild(t,e){let i=this.content[t];if(i==e)return this;let s=this.content.slice(),r=this.size+e.nodeSize-i.nodeSize;return s[t]=e,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 e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))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 e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,i=0;e<this.content.length;e++){let s=this.content[e];t(s,i,e),i+=s.nodeSize}}findDiffStart(t,e=0){return a(this,t,e)}findDiffEnd(t,e=this.size,i=t.size){return c(this,t,e,i)}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 e=0,i=0;;e++){let s=i+this.child(e).nodeSize;if(s>=t)return s==t?m(e+1,s):m(e,i);i=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,e){if(!e)return d.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new d(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return d.empty;let e,i=0;for(let s=0;s<t.length;s++){let r=t[s];i+=r.nodeSize,s&&r.isText&&t[s-1].sameMarkup(r)?(e||(e=t.slice(0,s)),e[e.length-1]=r.withText(e[e.length-1].text+r.text)):e&&e.push(r)}return new d(e||t,i)}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,e){return p.index=t,p.offset=e,p}function w(t,e){if(t===e)return!0;if(!t||"object"!=typeof t||!e||"object"!=typeof e)return!1;let i=Array.isArray(t);if(Array.isArray(e)!=i)return!1;if(i){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!w(t[i],e[i]))return!1}else{for(let i in t)if(!(i in e)||!w(t[i],e[i]))return!1;for(let i in e)if(!(i in t))return!1}return!0}class g{constructor(t,e){this.type=t,this.attrs=e}addToSet(t){let e,i=!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))e||(e=t.slice(0,s));else{if(r.type.excludes(this.type))return t;!i&&r.type.rank>this.type.rank&&(e||(e=t.slice(0,s)),e.push(this),i=!0),e&&e.push(r)}}return e||(e=t.slice()),i||e.push(this),e}removeFromSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return t.slice(0,e).concat(t.slice(e+1));return t}isInSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))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 e in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Mark.fromJSON");let i=t.marks[e.type];if(!i)throw new RangeError(`There is no mark type ${e.type} in this schema`);let s=i.create(e.attrs);return i.checkAttrs(s.attrs),s}static sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].eq(e[i]))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 e=t.slice();return e.sort(((t,e)=>t.type.rank-e.type.rank)),e}}g.none=[];class y extends Error{}class b{constructor(t,e,i){this.content=t,this.openStart=e,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let i=v(this.content,t+this.openStart,e);return i&&new b(i,this.openStart,this.openEnd)}removeBetween(t,e){return new b(M(this.content,t+this.openStart,e+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,e){if(!e)return b.empty;let i=e.openStart||0,s=e.openEnd||0;if("number"!=typeof i||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new b(d.fromJSON(t,e.content),i,s)}static maxOpen(t,e=!0){let i=0,s=0;for(let s=t.firstChild;s&&!s.isLeaf&&(e||!s.type.spec.isolating);s=s.firstChild)i++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)s++;return new b(t,i,s)}}function M(t,e,i){let{index:s,offset:r}=t.findIndex(e),n=t.maybeChild(s),{index:h,offset:o}=t.findIndex(i);if(r==e||n.isText){if(o!=i&&!t.child(h).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(i))}if(s!=h)throw new RangeError("Removing non-flat range");return t.replaceChild(s,n.copy(M(n.content,e-r-1,i-r-1)))}function v(t,e,i,s){let{index:r,offset:n}=t.findIndex(e),h=t.maybeChild(r);if(n==e||h.isText)return s&&!s.canReplace(r,r,i)?null:t.cut(0,e).append(i).append(t.cut(e));let o=v(h.content,e-n-1,i,h);return o&&t.replaceChild(r,h.copy(o))}function k(t,e,i){if(i.openStart>t.depth)throw new y("Inserted content deeper than insertion position");if(t.depth-i.openStart!=e.depth-i.openEnd)throw new y("Inconsistent open depths");return S(t,e,i,0)}function S(t,e,i,s){let r=t.index(s),n=t.node(s);if(r==e.index(s)&&s<t.depth-i.openStart){let h=S(t,e,i,s+1);return n.copy(n.content.replaceChild(r,h))}if(i.content.size){if(i.openStart||i.openEnd||t.depth!=s||e.depth!=s){let{start:r,end:h}=function(t,e){let i=e.depth-t.openStart,s=e.node(i).copy(t.content);for(let t=i-1;t>=0;t--)s=e.node(t).copy(d.from(s));return{start:s.resolveNoCache(t.openStart+i),end:s.resolveNoCache(s.content.size-t.openEnd-i)}}(i,t);return A(n,R(t,r,h,e,s))}{let s=t.parent,r=s.content;return A(s,r.cut(0,t.parentOffset).append(i.content).append(r.cut(e.parentOffset)))}}return A(n,E(t,e,s))}function x(t,e){if(!e.type.compatibleContent(t.type))throw new y("Cannot join "+e.type.name+" onto "+t.type.name)}function O(t,e,i){let s=t.node(i);return x(s,e.node(i)),s}function T(t,e){let i=e.length-1;i>=0&&t.isText&&t.sameMarkup(e[i])?e[i]=t.withText(e[i].text+t.text):e.push(t)}function D(t,e,i,s){let r=(e||t).node(i),n=0,h=e?e.index(i):r.childCount;t&&(n=t.index(i),t.depth>i?n++:t.textOffset&&(T(t.nodeAfter,s),n++));for(let t=n;t<h;t++)T(r.child(t),s);e&&e.depth==i&&e.textOffset&&T(e.nodeBefore,s)}function A(t,e){return t.type.checkContent(e),t.copy(e)}function R(t,e,i,s,r){let n=t.depth>r&&O(t,e,r+1),h=s.depth>r&&O(i,s,r+1),o=[];return D(null,t,r,o),n&&h&&e.index(r)==i.index(r)?(x(n,h),T(A(n,R(t,e,i,s,r+1)),o)):(n&&T(A(n,E(t,e,r+1)),o),D(e,i,r,o),h&&T(A(h,E(i,s,r+1)),o)),D(s,null,r,o),new d(o)}function E(t,e,i){let s=[];return D(null,t,i,s),t.depth>i&&T(A(O(t,e,i+1),E(t,e,i+1)),s),D(e,null,i,s),new d(s)}b.empty=new b(d.empty,0,0);class ${constructor(t,e,i){this.pos=t,this.path=e,this.parentOffset=i,this.depth=e.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,e=this.index(this.depth);if(e==t.childCount)return null;let i=this.pos-this.path[this.path.length-1],s=t.child(e);return i?t.child(e).cut(i):s}get nodeBefore(){let t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):0==t?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let i=this.path[3*e],s=0==e?0:this.path[3*e-1]+1;for(let e=0;e<t;e++)s+=i.child(e).nodeSize;return s}marks(){let t=this.parent,e=this.index();if(0==t.content.size)return g.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),s=t.maybeChild(e);if(!i){let t=i;i=s,s=t}let r=i.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 e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let i=e.marks,s=t.parent.maybeChild(t.index());for(var r=0;r<i.length;r++)!1!==i[r].type.spec.inclusive||s&&i[r].isInSet(s.marks)||(i=i[r--].removeFromSet(i));return i}sharedDepth(t){for(let e=this.depth;e>0;e--)if(this.start(e)<=t&&this.end(e)>=t)return e;return 0}blockRange(t=this,e){if(t.pos<this.pos)return t.blockRange(this);for(let i=this.depth-(this.parent.inlineContent||this.pos==t.pos?1:0);i>=0;i--)if(t.pos<=this.end(i)&&(!e||e(this.node(i))))return new I(this,t,i);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 e=1;e<=this.depth;e++)t+=(t?"/":"")+this.node(e).type.name+"_"+this.index(e-1);return t+":"+this.parentOffset}static resolve(t,e){if(!(e>=0&&e<=t.content.size))throw new RangeError("Position "+e+" out of range");let i=[],s=0,r=e;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(r),h=r-n;if(i.push(e,t,s+n),!h)break;if(e=e.child(t),e.isText)break;r=h-1,s+=n+1}return new $(e,i,r)}static resolveCached(t,e){let i=N.get(t);if(i)for(let t=0;t<i.elts.length;t++){let s=i.elts[t];if(s.pos==e)return s}else N.set(t,i=new C);let s=i.elts[i.i]=$.resolve(t,e);return i.i=(i.i+1)%P,s}}class C{constructor(){this.elts=[],this.i=0}}const P=12,N=new WeakMap;class I{constructor(t,e,i){this.$from=t,this.$to=e,this.depth=i}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,e,i,s=g.none){this.type=t,this.attrs=e,this.marks=s,this.content=i||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,e,i,s=0){this.content.nodesBetween(t,e,i,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,e,i,s){return this.content.textBetween(t,e,i,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,e,i){return this.type==t&&w(this.attrs,e||t.defaultAttrs||z)&&g.sameSet(this.marks,i||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,e=this.content.size){return 0==t&&e==this.content.size?this:this.copy(this.content.cut(t,e))}slice(t,e=this.content.size,i=!1){if(t==e)return b.empty;let s=this.resolve(t),r=this.resolve(e),n=i?0:s.sharedDepth(e),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,e,i){return k(this.resolve(t),this.resolve(e),i)}nodeAt(t){for(let e=this;;){let{index:i,offset:s}=e.content.findIndex(t);if(e=e.maybeChild(i),!e)return null;if(s==t||e.isText)return e;t-=s+1}}childAfter(t){let{index:e,offset:i}=this.content.findIndex(t);return{node:this.content.maybeChild(e),index:e,offset:i}}childBefore(t){if(0==t)return{node:null,index:0,offset:0};let{index:e,offset:i}=this.content.findIndex(t);if(i<t)return{node:this.content.child(e),index:e,offset:i};let s=this.content.child(e-1);return{node:s,index:e-1,offset:i-s.nodeSize}}resolve(t){return $.resolveCached(this,t)}resolveNoCache(t){return $.resolve(this,t)}rangeHasMark(t,e,i){let s=!1;return e>t&&this.nodesBetween(t,e,(t=>(i.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 e=this.type.contentMatch.matchFragment(this.content,0,t);if(!e)throw new Error("Called contentMatchAt on a node with invalid content");return e}canReplace(t,e,i=d.empty,s=0,r=i.childCount){let n=this.contentMatchAt(t).matchFragment(i,s,r),h=n&&n.matchFragment(this.content,e);if(!h||!h.validEnd)return!1;for(let t=s;t<r;t++)if(!this.type.allowsMarks(i.child(t).marks))return!1;return!0}canReplaceWith(t,e,i,s){if(s&&!this.type.allowsMarks(s))return!1;let r=this.contentMatchAt(t).matchType(i),n=r&&r.matchFragment(this.content,e);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 e=0;e<this.marks.length;e++){let i=this.marks[e];i.type.checkAttrs(i.attrs),t=i.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 e 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,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");let i;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=e.marks.map(t.markFromJSON)}if("text"==e.type){if("string"!=typeof e.text)throw new RangeError("Invalid text node in JSON");return t.text(e.text,i)}let s=d.fromJSON(t,e.content),r=t.nodeType(e.type).create(e.attrs,s,i);return r.type.checkAttrs(r.attrs),r}}_.prototype.text=void 0;class j extends _{constructor(t,e,i,s){if(super(t,e,null,s),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}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,e){return this.text.slice(t,e)}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,e=this.text.length){return 0==t&&e==this.text.length?this:this.withText(this.text.slice(t,e))}eq(t){return this.sameMarkup(t)&&this.text==t.text}toJSON(){let t=super.toJSON();return t.text=this.text,t}}function F(t,e){for(let i=t.length-1;i>=0;i--)e=t[i].type.name+"("+e+")";return e}class B{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,e){let i=new W(t,e);if(null==i.next)return B.empty;let s=J(i);i.next&&i.err("Unexpected trailing text");let r=function(t){let e=Object.create(null);return function i(s){let r=[];s.forEach((e=>{t[e].forEach((({term:e,to:i})=>{if(!e)return;let s;for(let t=0;t<r.length;t++)r[t][0]==e&&(s=r[t][1]);K(t,i).forEach((t=>{s||r.push([e,s=[]]),-1==s.indexOf(t)&&s.push(t)}))}))}));let n=e[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:e[s.join(",")]||i(s)})}return n}(K(t,0))}(function(t){let e=[[]];return r(function t(e,n){if("choice"==e.type)return e.exprs.reduce(((e,i)=>e.concat(t(i,n))),[]);if("seq"!=e.type){if("star"==e.type){let h=i();return s(n,h),r(t(e.expr,h),h),[s(h)]}if("plus"==e.type){let h=i();return r(t(e.expr,n),h),r(t(e.expr,h),h),[s(h)]}if("opt"==e.type)return[s(n)].concat(t(e.expr,n));if("range"==e.type){let h=n;for(let s=0;s<e.min;s++){let s=i();r(t(e.expr,h),s),h=s}if(-1==e.max)r(t(e.expr,h),h);else for(let n=e.min;n<e.max;n++){let n=i();s(h,n),r(t(e.expr,h),n),h=n}return[s(h)]}if("name"==e.type)return[s(n,void 0,e.value)];throw new Error("Unknown expr type")}for(let s=0;;s++){let h=t(e.exprs[s],n);if(s==e.exprs.length-1)return h;r(h,n=i())}}(t,0),i()),e;function i(){return e.push([])-1}function s(t,i,s){let r={term:s,to:i};return e[t].push(r),r}function r(t,e){t.forEach((t=>t.to=e))}}(s));return function(t,e){for(let i=0,s=[t];i<s.length;i++){let t=s[i],r=!t.validEnd,n=[];for(let e=0;e<t.next.length;e++){let{type:i,next:h}=t.next[e];n.push(i.name),!r||i.isText||i.hasRequiredAttrs()||(r=!1),-1==s.indexOf(h)&&s.push(h)}r&&e.err("Only non-generatable nodes ("+n.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,i),r}matchType(t){for(let e=0;e<this.next.length;e++)if(this.next[e].type==t)return this.next[e].next;return null}matchFragment(t,e=0,i=t.childCount){let s=this;for(let r=e;s&&r<i;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:e}=this.next[t];if(!e.isText&&!e.hasRequiredAttrs())return e}return null}compatible(t){for(let e=0;e<this.next.length;e++)for(let i=0;i<t.next.length;i++)if(this.next[e].type==t.next[i].type)return!0;return!1}fillBefore(t,e=!1,i=0){let s=[this];return function r(n,h){let o=n.matchFragment(t,i);if(o&&(!e||o.validEnd))return d.from(h.map((t=>t.createAndFill())));for(let t=0;t<n.next.length;t++){let{type:e,next:i}=n.next[t];if(!e.isText&&!e.hasRequiredAttrs()&&-1==s.indexOf(i)){s.push(i);let t=r(i,h.concat(e));if(t)return t}}return null}(this,[])}findWrapping(t){for(let e=0;e<this.wrapCache.length;e+=2)if(this.wrapCache[e]==t)return this.wrapCache[e+1];let e=this.computeWrapping(t);return this.wrapCache.push(t,e),e}computeWrapping(t){let e=Object.create(null),i=[{match:this,type:null,via:null}];for(;i.length;){let s=i.shift(),r=s.match;if(r.matchType(t)){let t=[];for(let e=s;e.type;e=e.via)t.push(e.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 e||s.type&&!h.validEnd||(i.push({match:n.contentMatch,type:n,via:s}),e[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 e(i){t.push(i);for(let s=0;s<i.next.length;s++)-1==t.indexOf(i.next[s].next)&&e(i.next[s].next)}(this),t.map(((e,i)=>{let s=i+(e.validEnd?"*":" ")+" ";for(let i=0;i<e.next.length;i++)s+=(i?", ":"")+e.next[i].type.name+"->"+t.indexOf(e.next[i].next);return s})).join("\n")}}B.empty=new B(!0);class W{constructor(t,e){this.string=t,this.nodeTypes=e,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 e=[];do{e.push(L(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function L(t){let e=[];do{e.push(X(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==e.length?e[0]:{type:"seq",exprs:e}}function X(t){let e=function(t){if(t.eat("(")){let e=J(t);return t.eat(")")||t.err("Missing closing paren"),e}if(!/\W/.test(t.next)){let e=function(t,e){let i=t.nodeTypes,s=i[e];if(s)return[s];let r=[];for(let t in i){let s=i[t];s.isInGroup(e)&&r.push(s)}return 0==r.length&&t.err("No node type or group '"+e+"' found"),r}(t,t.next).map((e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e})));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}t.err("Unexpected token '"+t.next+"'")}(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else{if(!t.eat("{"))break;e=U(t,e)}return e}function Y(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function U(t,e){let i=Y(t),s=i;return t.eat(",")&&(s="}"!=t.next?Y(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:i,max:s,expr:e}}function H(t,e){return e-t}function K(t,e){let i=[];return function e(s){let r=t[s];if(1==r.length&&!r[0].term)return e(r[0].to);i.push(s);for(let t=0;t<r.length;t++){let{term:s,to:n}=r[t];s||-1!=i.indexOf(n)||e(n)}}(e),i.sort(H)}function q(t){let e=Object.create(null);for(let i in t){let s=t[i];if(!s.hasDefault)return null;e[i]=s.default}return e}function G(t,e){let i=Object.create(null);for(let s in t){let r=e&&e[s];if(void 0===r){let e=t[s];if(!e.hasDefault)throw new RangeError("No value supplied for attribute "+s);r=e.default}i[s]=r}return i}function V(t,e,i){for(let s in e)if(!(s in t))throw new RangeError(`Unsupported attribute ${s} for ${i} of type ${s}`);for(let i in t){let s=t[i];s.validate&&s.validate(e[i])}}function Z(t,e){let i=Object.create(null);if(e)for(let s in e)i[s]=new tt(t,s,e[s]);return i}let Q=class t{constructor(t,e,i){this.name=t,this.schema=e,this.spec=i,this.markSet=null,this.groups=i.group?i.group.split(" "):[],this.attrs=Z(t,i.attrs),this.defaultAttrs=q(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(i.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,e,i){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new _(this,this.computeAttrs(t),d.from(e),g.setFrom(i))}createChecked(t=null,e,i){return e=d.from(e),this.checkContent(e),new _(this,this.computeAttrs(t),e,g.setFrom(i))}createAndFill(t=null,e,i){if(t=this.computeAttrs(t),(e=d.from(e)).size){let t=this.contentMatch.fillBefore(e);if(!t)return null;e=t.append(e)}let s=this.contentMatch.matchFragment(e),r=s&&s.fillBefore(d.empty,!0);return r?new _(this,t,e.append(r),g.setFrom(i)):null}validContent(t){let e=this.contentMatch.matchFragment(t);if(!e||!e.validEnd)return!1;for(let e=0;e<t.childCount;e++)if(!this.allowsMarks(t.child(e).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 e=0;e<t.length;e++)if(!this.allowsMarkType(t[e].type))return!1;return!0}allowedMarks(t){if(null==this.markSet)return t;let e;for(let i=0;i<t.length;i++)this.allowsMarkType(t[i].type)?e&&e.push(t[i]):e||(e=t.slice(0,i));return e?e.length?e:g.none:t}static compile(e,i){let s=Object.create(null);e.forEach(((e,r)=>s[e]=new t(e,i,r)));let r=i.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,e,i){this.hasDefault=Object.prototype.hasOwnProperty.call(i,"default"),this.default=i.default,this.validate="string"==typeof i.validate?function(t,e,i){let s=i.split("|");return i=>{let r=null===i?"null":typeof i;if(s.indexOf(r)<0)throw new RangeError(`Expected value of type ${s} for attribute ${e} on type ${t}, got ${r}`)}}(t,e,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class et{constructor(t,e,i,s){this.name=t,this.rank=e,this.schema=i,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,e){let i=Object.create(null),s=0;return t.forEach(((t,r)=>i[t]=new et(t,s++,e,r))),i}removeFromSet(t){for(var e=0;e<t.length;e++)t[e].type==this&&(t=t.slice(0,e).concat(t.slice(e+1)),e--);return t}isInSet(t){for(let e=0;e<t.length;e++)if(t[e].type==this)return t[e]}checkAttrs(t){V(this.attrs,t,"mark")}excludes(t){return this.excluded.indexOf(t)>-1}}class it{constructor(t){this.linebreakReplacement=null,this.cached=Object.create(null);let e=this.spec={};for(let i in t)e[i]=t[i];e.nodes=f.from(t.nodes),e.marks=f.from(t.marks||{}),this.nodes=Q.compile(this.spec.nodes,this),this.marks=et.compile(this.spec.marks,this);let i=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 e=this.nodes[t],s=e.spec.content||"",r=e.spec.marks;if(e.contentMatch=i[s]||(i[s]=B.parse(s,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet="_"==r?null:r?st(this,r.split(" ")):""!=r&&e.inlineContent?null:[]}for(let t in this.marks){let e=this.marks[t],i=e.spec.excludes;e.excluded=null==i?[e]:""==i?[]:st(this,i.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,e=null,i,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(e,i,s)}text(t,e){let i=this.nodes.text;return new j(i,i.defaultAttrs,t,g.setFrom(e))}mark(t,e){return"string"==typeof t&&(t=this.marks[t]),t.create(e)}nodeType(t){let e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e}}function st(t,e){let i=[];for(let s=0;s<e.length;s++){let r=e[s],n=t.marks[r],h=n;if(n)i.push(n);else for(let e in t.marks){let s=t.marks[e];("_"==r||s.spec.group&&s.spec.group.split(" ").indexOf(r)>-1)&&i.push(h=s)}if(!h)throw new SyntaxError("Unknown mark type: '"+e[s]+"'")}return i}class rt{constructor(t,e){this.schema=t,this.rules=e,this.tags=[],this.styles=[];let i=this.matchedStyles=[];e.forEach((t=>{if(function(t){return null!=t.tag}(t))this.tags.push(t);else if(function(t){return null!=t.style}(t)){let e=/[^=]*/.exec(t.style)[0];i.indexOf(e)<0&&i.push(e),this.styles.push(t)}})),this.normalizeLists=!this.tags.some((e=>{if(!/^(ul|ol)\b/.test(e.tag)||!e.node)return!1;let i=t.nodes[e.node];return i.contentMatch.matchType(i)}))}parse(t,e={}){let i=new ft(this,e,!1);return i.addAll(t,g.none,e.from,e.to),i.finish()}parseSlice(t,e={}){let i=new ft(this,e,!0);return i.addAll(t,g.none,e.from,e.to),b.maxOpen(i.finish())}matchTag(t,e,i){for(let s=i?this.tags.indexOf(i)+1:0;s<this.tags.length;s++){let i=this.tags[s];if(at(t,i.tag)&&(void 0===i.namespace||t.namespaceURI==i.namespace)&&(!i.context||e.matchesContext(i.context))){if(i.getAttrs){let e=i.getAttrs(t);if(!1===e)continue;i.attrs=e||void 0}return i}}}matchStyle(t,e,i,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&&!i.matchesContext(s.context)||n.length>t.length&&(61!=n.charCodeAt(t.length)||n.slice(t.length+1)!=e))){if(s.getAttrs){let t=s.getAttrs(e);if(!1===t)continue;s.attrs=t||void 0}return s}}}static schemaRules(t){let e=[];function i(t){let i=null==t.priority?50:t.priority,s=0;for(;s<e.length;s++){let t=e[s];if((null==t.priority?50:t.priority)<i)break}e.splice(s,0,t)}for(let e in t.marks){let s=t.marks[e].spec.parseDOM;s&&s.forEach((t=>{i(t=ct(t)),t.mark||t.ignore||t.clearMark||(t.mark=e)}))}for(let e in t.nodes){let s=t.nodes[e].spec.parseDOM;s&&s.forEach((t=>{i(t=ct(t)),t.node||t.ignore||t.mark||(t.node=e)}))}return e}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,e,i){return null!=e?(e?1:0)|("full"===e?2:0):t&&"pre"==t.whitespace?3:-5&i}class ut{constructor(t,e,i,s,r,n){this.type=t,this.attrs=e,this.marks=i,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 e=this.type.contentMatch.fillBefore(d.from(t));if(!e){let e,i=this.type.contentMatch;return(e=i.findWrapping(t.type))?(this.match=i,e):null}this.match=this.type.contentMatch.matchFragment(e)}return this.match.findWrapping(t.type)}finish(t){if(!(1&this.options)){let t,e=this.content[this.content.length-1];if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let i=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-t[0].length))}}let e=d.from(this.content);return!t&&this.match&&(e=e.append(this.match.fillBefore(d.empty,!0))),this.type?this.type.create(this.attrs,e,this.marks):e}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,e,i){this.parser=t,this.options=e,this.isOpen=i,this.open=0,this.localPreserveWS=!1;let s,r=e.topNode,n=lt(null,e.preserveWhitespace,0)|(i?4:0);s=r?new ut(r.type,r.attrs,g.none,!0,e.topMatch||r.type.contentMatch,n):new ut(i?null:t.schema.topNodeType,null,g.none,!0,null,n),this.nodes=[s],this.find=e.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t,e){3==t.nodeType?this.addTextNode(t,e):1==t.nodeType&&this.addElement(t,e)}addTextNode(t,e){let i=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(i)){if(r)if("full"===r)i=i.replace(/\r\n?/g,"\n");else if(n.linebreakReplacement&&/[\r\n]/.test(i)&&this.top.findWrapping(n.linebreakReplacement.create())){let t=i.split(/\r?\n|\r/);for(let i=0;i<t.length;i++)i&&this.insertNode(n.linebreakReplacement.create(),e,!0),t[i]&&this.insertNode(n.text(t[i]),e,!/\S/.test(t[i]));i=""}else i=i.replace(/\r?\n|\r/g," ");else if(i=i.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(i)&&this.open==this.nodes.length-1){let e=s.content[s.content.length-1],r=t.previousSibling;(!e||r&&"BR"==r.nodeName||e.isText&&/[ \t\r\n\u000c]$/.test(e.text))&&(i=i.slice(1))}i&&this.insertNode(n.text(i),e,!/\S/.test(i)),this.findInText(t)}else this.findInside(t)}addElement(t,e,i){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 e=t.firstChild,i=null;e;e=e.nextSibling){let t=1==e.nodeType?e.nodeName.toLowerCase():null;t&&ot.hasOwnProperty(t)&&i?(i.appendChild(e),e=i):"li"==t?i=e:t&&(i=null)}}(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(n=this.parser.matchTag(t,this,i));t:if(o?o.ignore:ht.hasOwnProperty(h))this.findInside(t),this.ignoreFallback(t,e);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 i,s=this.needsBlock;if(nt.hasOwnProperty(h))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),i=!0,r.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t,e);break t}let n=o&&o.skip?e:this.readStyles(t,e);n&&this.addAll(t,n),i&&this.sync(r),this.needsBlock=s}else{let i=this.readStyles(t,e);i&&this.addElementByRule(t,o,i,!1===o.consuming?n:void 0)}this.localPreserveWS=s}leafFallback(t,e){"BR"==t.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode("\n"),e)}ignoreFallback(t,e){"BR"!=t.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),e,!0)}readStyles(t,e){let i=t.style;if(i&&i.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let s=this.parser.matchedStyles[t],r=i.getPropertyValue(s);if(r)for(let t;;){let i=this.parser.matchStyle(s,r,this,t);if(!i)break;if(i.ignore)return null;if(e=i.clearMark?e.filter((t=>!i.clearMark(t))):e.concat(this.parser.schema.marks[i.mark].create(i.attrs)),!1!==i.consuming)break;t=i}}return e}addElementByRule(t,e,i,s){let r,n;if(e.node)if(n=this.parser.schema.nodes[e.node],n.isLeaf)this.insertNode(n.create(e.attrs),i,"BR"==t.nodeName)||this.leafFallback(t,i);else{let t=this.enter(n,e.attrs||null,i,e.preserveWhitespace);t&&(r=!0,i=t)}else i=i.concat(this.parser.schema.marks[e.mark].create(e.attrs));let h=this.top;if(n&&n.isLeaf)this.findInside(t);else if(s)this.addElement(t,i,s);else if(e.getContent)this.findInside(t),e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,i,!1)));else{let s=t;"string"==typeof e.contentElement?s=t.querySelector(e.contentElement):"function"==typeof e.contentElement?s=e.contentElement(t):e.contentElement&&(s=e.contentElement),this.findAround(t,s,!0),this.addAll(s,i),this.findAround(t,s,!1)}r&&this.sync(h)&&this.open--}addAll(t,e,i,s){let r=i||0;for(let n=i?t.childNodes[i]:t.firstChild,h=null==s?null:t.childNodes[s];n!=h;n=n.nextSibling,++r)this.findAtPoint(t,r),this.addDOM(n,e);this.findAtPoint(t,r)}findPlace(t,e,i){let s,r;for(let e=this.open,n=0;e>=0;e--){let h=this.nodes[e],o=h.findWrapping(t);if(o&&(!s||s.length>o.length+n)&&(s=o,r=h,!o.length))break;if(h.solid){if(i)break;n+=2}}if(!s)return null;this.sync(r);for(let t=0;t<s.length;t++)e=this.enterInner(s[t],null,e,!1);return e}insertNode(t,e,i){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();t&&(e=this.enterInner(t,null,e))}let s=this.findPlace(t,e,i);if(s){this.closeExtra();let e=this.top;e.match&&(e.match=e.match.matchType(t.type));let i=g.none;for(let r of s.concat(t.marks))(e.type?e.type.allowsMarkType(r.type):dt(r.type,t.type))&&(i=r.addToSet(i));return e.content.push(t.mark(i)),!0}return!1}enter(t,e,i,s){let r=this.findPlace(t.create(e),i,!1);return r&&(r=this.enterInner(t,e,i,!0,s)),r}enterInner(t,e,i,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 i=i.filter((e=>!(n.type?n.type.allowsMarkType(e.type):dt(e.type,t))||(o=e.addToSet(o),!1))),this.nodes.push(new ut(t,e,o,s,null,h)),this.open++,i}closeExtra(t=!1){let e=this.nodes.length-1;if(e>this.open){for(;e>this.open;e--)this.nodes[e-1].content.push(this.nodes[e].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 e=this.open;e>=0;e--){if(this.nodes[e]==t)return this.open=e,!0;this.localPreserveWS&&(this.nodes[e].options|=1)}return!1}get currentPos(){this.closeExtra();let t=0;for(let e=this.open;e>=0;e--){let i=this.nodes[e].content;for(let e=i.length-1;e>=0;e--)t+=i[e].nodeSize;e&&t++}return t}findAtPoint(t,e){if(this.find)for(let i=0;i<this.find.length;i++)this.find[i].node==t&&this.find[i].offset==e&&(this.find[i].pos=this.currentPos)}findInside(t){if(this.find)for(let e=0;e<this.find.length;e++)null==this.find[e].pos&&1==t.nodeType&&t.contains(this.find[e].node)&&(this.find[e].pos=this.currentPos)}findAround(t,e,i){if(t!=e&&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)&&e.compareDocumentPosition(this.find[s].node)&(i?2:4)&&(this.find[s].pos=this.currentPos)}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].node==t&&(this.find[e].pos=this.currentPos-(t.nodeValue.length-this.find[e].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/"),i=this.options.context,s=!(this.isOpen||i&&i.parent.type!=this.nodes[0].type),r=(s?0:1)-(i?i.depth+1:0),n=(t,h)=>{for(;t>=0;t--){let o=e[t];if(""==o){if(t==e.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:i&&h>=r?i.node(h-r).type:null;if(!t||t.name!=o&&!t.isInGroup(o))return!1;h--}}return!0};return n(e.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let e=t.depth;e>=0;e--){let i=t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;if(i&&i.isTextblock&&i.defaultAttrs)return i}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}}function at(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function ct(t){let e={};for(let i in t)e[i]=t[i];return e}function dt(t,e){let i=e.schema.nodes;for(let s in i){let r=i[s];if(!r.allowsMarkType(t))continue;let n=[],h=t=>{n.push(t);for(let i=0;i<t.edgeCount;i++){let{type:s,next:r}=t.edge(i);if(s==e)return!0;if(n.indexOf(r)<0&&h(r))return!0}};if(h(r.contentMatch))return!0}}class pt{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},i){i||(i=wt(e).createDocumentFragment());let s=i,r=[];return t.forEach((t=>{if(r.length||t.marks.length){let i=0,n=0;for(;i<r.length&&n<t.marks.length;){let e=t.marks[n];if(this.marks[e.type.name]){if(!e.eq(r[i][0])||!1===e.type.spec.spanning)break;i++,n++}else n++}for(;i<r.length;)s=r.pop()[1];for(;n<t.marks.length;){let i=t.marks[n++],h=this.serializeMark(i,t.isInline,e);h&&(r.push([i,s]),s.appendChild(h.dom),s=h.contentDOM||h.dom)}}s.appendChild(this.serializeNodeInner(t,e))})),i}serializeNodeInner(t,e){let{dom:i,contentDOM:s}=yt(wt(e),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,e,s)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let s=t.marks.length-1;s>=0;s--){let r=this.serializeMark(t.marks[s],t.isInline,e);r&&((r.contentDOM||r.dom).appendChild(i),i=r.dom)}return i}serializeMark(t,e,i={}){let s=this.marks[t.type.name];return s&&yt(wt(i),s(t,e),null,t.attrs)}static renderSpec(t,e,i=null,s){return yt(t,e,i,s)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new pt(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=mt(t.nodes);return e.text||(e.text=t=>t.text),e}static marksFromSchema(t){return mt(t.marks)}}function mt(t){let e={};for(let i in t){let s=t[i].spec.toDOM;s&&(e[i]=s)}return e}function wt(t){return t.document||window.document}const gt=new WeakMap;function yt(t,e,i,s){if("string"==typeof e)return{dom:t.createTextNode(e)};if(null!=e.nodeType)return{dom:e};if(e.dom&&null!=e.dom.nodeType)return e;let r,n=e[0];if("string"!=typeof n)throw new RangeError("Invalid array passed to renderSpec");if(s&&(r=function(t){let e=gt.get(t);return void 0===e&>.set(t,e=function(t){let e=null;return function t(i){if(i&&"object"==typeof i)if(Array.isArray(i))if("string"==typeof i[0])e||(e=[]),e.push(i);else for(let e=0;e<i.length;e++)t(i[e]);else for(let e in i)t(i[e])}(t),e}(t)),e}(s))&&r.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let h,o=n.indexOf(" ");o>0&&(i=n.slice(0,o),n=n.slice(o+1));let l=i?t.createElementNS(i,n):t.createElement(n),u=e[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 e=t.indexOf(" ");e>0?l.setAttributeNS(t.slice(0,e),t.slice(e+1),u[t]):"style"==t&&l.style?l.style.cssText=u[t]:l.setAttribute(t,u[t])}}for(let r=f;r<e.length;r++){let n=e[r];if(0===n){if(r<e.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:e,contentDOM:r}=yt(t,n,i,s);if(l.appendChild(e),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,e,i){this.pos=t,this.delInfo=e,this.recover=i}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,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&kt.empty)return kt.empty}recover(t){let e=0,i=Mt(t);if(!this.inverted)for(let t=0;t<i;t++)e+=this.ranges[3*t+2]-this.ranges[3*t+1];return this.ranges[3*i]+e+function(t){return(t-(65535&t))/bt}(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,i){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:e:e)<0?0:u);if(i)return r;let n=t==o?2:t==f?1:4;return(e<0?t!=o:t!=f)&&(n|=8),new vt(r,n,t==(e<0?o:f)?null:h/3+(t-o)*bt)}s+=u-l}return i?t+s:new vt(t+s,0,null)}touches(t,e){let i=0,s=Mt(e),r=this.inverted?2:1,n=this.inverted?1:2;for(let e=0;e<this.ranges.length;e+=3){let h=this.ranges[e]-(this.inverted?i:0);if(h>t)break;let o=this.ranges[e+r];if(t<=h+o&&e==3*s)return!0;i+=this.ranges[e+n]-o}return!1}forEach(t){let e=this.inverted?2:1,i=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+e],u=this.ranges[s+i];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,e,i=0,s=(t?t.length:0)){this.mirror=e,this.from=i,this.to=s,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new St(this._maps,this.mirror,t,e)}appendMap(t,e){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(t),null!=e&&this.setMirror(this._maps.length-1,e)}appendMapping(t){for(let e=0,i=this._maps.length;e<t._maps.length;e++){let s=t.getMirror(e);this.appendMap(t._maps[e],null!=s&&s<e?i+s:void 0)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){this.mirror||(this.mirror=[]),this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,i=this._maps.length+t._maps.length;e>=0;e--){let s=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=s&&s>e?i-s-1:void 0)}}invert(){let t=new St;return t.appendMappingInverted(this),t}map(t,e=1){if(this.mirror)return this._map(t,e,!0);for(let i=this.from;i<this.to;i++)t=this._maps[i].map(t,e);return t}mapResult(t,e=1){return this._map(t,e,!1)}_map(t,e,i){let s=0;for(let i=this.from;i<this.to;i++){let r=this._maps[i].mapResult(t,e);if(null!=r.recover){let e=this.getMirror(i);if(null!=e&&e>i&&e<this.to){i=e,t=this._maps[e].recover(r.recover);continue}}s|=r.delInfo,t=r.pos}return i?t:new vt(t,s,null)}}const xt=Object.create(null);class Ot{getMap(){return kt.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=xt[e.stepType];if(!i)throw new RangeError(`No step type ${e.stepType} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in xt)throw new RangeError("Duplicate use of step JSON ID "+t);return xt[t]=e,e.prototype.jsonID=t,e}}class Tt{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new Tt(t,null)}static fail(t){return new Tt(null,t)}static fromReplace(t,e,i,s){try{return Tt.ok(t.replace(e,i,s))}catch(t){if(t instanceof y)return Tt.fail(t.message);throw t}}}function Dt(t,e,i){let s=[];for(let r=0;r<t.childCount;r++){let n=t.child(r);n.content.size&&(n=n.copy(Dt(n.content,e,n))),n.isInline&&(n=e(n,i,r)),s.push(n)}return d.fromArray(s)}class At extends Ot{constructor(t,e,i){super(),this.from=t,this.to=e,this.mark=i}apply(t){let e=t.slice(this.from,this.to),i=t.resolve(this.from),s=i.node(i.sharedDepth(this.to)),r=new b(Dt(e.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),s),e.openStart,e.openEnd);return Tt.fromReplace(t,this.from,this.to,r)}invert(){return new Rt(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);return e.deleted&&i.deleted||e.pos>=i.pos?null:new At(e.pos,i.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,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new At(e.from,e.to,t.markFromJSON(e.mark))}}Ot.jsonID("addMark",At);class Rt extends Ot{constructor(t,e,i){super(),this.from=t,this.to=e,this.mark=i}apply(t){let e=t.slice(this.from,this.to),i=new b(Dt(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return Tt.fromReplace(t,this.from,this.to,i)}invert(){return new At(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);return e.deleted&&i.deleted||e.pos>=i.pos?null:new Rt(e.pos,i.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,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Rt(e.from,e.to,t.markFromJSON(e.mark))}}Ot.jsonID("removeMark",Rt);class Et extends Ot{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Tt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let i=0;i<e.marks.length;i++)if(!e.marks[i].isInSet(t))return new Et(this.pos,e.marks[i]);return new Et(this.pos,this.mark)}}return new $t(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Et(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Et(e.pos,t.markFromJSON(e.mark))}}Ot.jsonID("addNodeMark",Et);class $t extends Ot{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Tt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new Et(this.pos,this.mark):this}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new $t(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new $t(e.pos,t.markFromJSON(e.mark))}}Ot.jsonID("removeNodeMark",$t);class Ct extends Ot{constructor(t,e,i,s=!1){super(),this.from=t,this.to=e,this.slice=i,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 e=t.mapResult(this.to,-1),i=this.from==this.to&&Ct.MAP_BIAS<0?e:t.mapResult(this.from,1);return i.deletedAcross&&e.deletedAcross?null:new Ct(i.pos,Math.max(i.pos,e.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 e=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,e,this.structure)}}{let e=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),e,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,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Ct(e.from,e.to,b.fromJSON(t,e.slice),!!e.structure)}}Ct.MAP_BIAS=1,Ot.jsonID("replace",Ct);class Pt extends Ot{constructor(t,e,i,s,r,n,h=!1){super(),this.from=t,this.to=e,this.gapFrom=i,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 e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return Tt.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,e.content);return i?Tt.fromReplace(t,this.from,this.to,i):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 e=this.gapTo-this.gapFrom;return new Pt(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1),s=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),r=this.to==this.gapTo?i.pos:t.map(this.gapTo,1);return e.deletedAcross&&i.deletedAcross||s<e.pos||r>i.pos?null:new Pt(e.pos,i.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,e){if("number"!=typeof e.from||"number"!=typeof e.to||"number"!=typeof e.gapFrom||"number"!=typeof e.gapTo||"number"!=typeof e.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Pt(e.from,e.to,e.gapFrom,e.gapTo,b.fromJSON(t,e.slice),e.insert,!!e.structure)}}function Nt(t,e,i){let s=t.resolve(e),r=i-e,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,e,i,s=i.contentMatch,r=!0){let n=t.doc.nodeAt(e),h=[],o=e+1;for(let e=0;e<n.childCount;e++){let l=n.child(e),u=o+l.nodeSize,f=s.matchType(l.type);if(f){s=f;for(let e=0;e<l.marks.length;e++)i.allowsMarkType(l.marks[e].type)||t.step(new Rt(o,u,l.marks[e]));if(r&&l.isText&&"pre"!=i.whitespace){let t,e,s=/\r?\n|\r/g;for(;t=s.exec(l.text);)e||(e=new b(d.from(i.schema.text(" ",i.allowedMarks(l.marks))),0,0)),h.push(new Ct(o+t.index,o+t.index+t[0].length,e))}}else h.push(new Ct(o,u,b.empty));o=u}if(!s.validEnd){let e=s.fillBefore(d.empty,!0);t.replace(o,o,new b(e,0,0))}for(let e=h.length-1;e>=0;e--)t.step(h[e])}function zt(t,e,i){return(0==e||t.canReplace(e,t.childCount))&&(i==t.childCount||t.canReplace(0,i))}function _t(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let i=t.depth,s=0,r=0;;--i){let n=t.$from.node(i),h=t.$from.index(i)+s,o=t.$to.indexAfter(i)-r;if(i<t.depth&&n.canReplace(h,o,e))return i;if(0==i||n.type.spec.isolating||!zt(n,h,o))break;h&&(s=1),o<n.childCount&&(r=1)}return null}function jt(t,e,i,s){e.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(i+1+n+h.index);t.replaceWith(r,r+1,e.type.schema.linebreakReplacement.create())}}}))}function Ft(t,e,i,s){e.forEach(((r,n)=>{if(r.type==r.type.schema.linebreakReplacement){let r=t.mapping.slice(s).map(i+1+n);t.replaceWith(r,r+1,e.type.schema.text("\n"))}}))}function Bt(t,e,i=1,s){let r=t.resolve(e),n=r.depth-i,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,e=i-2;t>n;t--,e--){let i=r.node(t),n=r.index(t);if(i.type.spec.isolating)return!1;let h=i.content.cutByIndex(n,i.childCount),o=s&&s[e+1];o&&(h=h.replaceChild(0,o.type.create(o.attrs)));let l=s&&s[e]||i;if(!i.canReplace(n+1,i.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,e){let i=t.resolve(e),s=i.index();return n=i.nodeAfter,!(!(r=i.nodeBefore)||!n||r.isLeaf||!function(t,e){e.content.size||t.type.compatibleContent(e.type);let i=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let r=0;r<e.childCount;r++){let n=e.child(r);if(i=i.matchType(n.type==s?t.type.schema.nodes.text:n.type),!i)return!1;if(!t.type.allowsMarks(n.marks))return!1}return i.validEnd}(r,n))&&i.parent.canReplace(s,s+1);var r,n}function Jt(t,e,i=e,s=b.empty){if(e==i&&!s.size)return null;let r=t.resolve(e),n=t.resolve(i);return Lt(r,n,s)?new Ct(e,i,s):new Xt(r,n,s).fit()}function Lt(t,e,i){return!i.openStart&&!i.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),i.content)}Ot.jsonID("replaceAround",Pt);class Xt{constructor(t,e,i){this.$from=t,this.$to=e,this.unplaced=i,this.frontier=[],this.placed=d.empty;for(let e=0;e<=t.depth;e++){let i=t.node(e);this.frontier.push({type:i.type,match:i.contentMatchAt(t.indexAfter(e))})}for(let e=t.depth;e>0;e--)this.placed=d.from(t.node(e).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(),e=this.placed.size-this.depth-this.$from.depth,i=this.$from,s=this.close(t<0?this.$to:i.doc.resolve(t));if(!s)return null;let r=this.placed,n=i.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(i.pos,t,this.$to.pos,this.$to.end(),o,e):o.size||i.pos!=this.$to.pos?new Ct(i.pos,s.pos,o):null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,i=0,s=this.unplaced.openEnd;i<t;i++){let r=e.firstChild;if(e.childCount>1&&(s=0),r.type.spec.isolating&&s<=i){t=i;break}e=r.content}for(let e=1;e<=2;e++)for(let i=1==e?t:this.unplaced.openStart;i>=0;i--){let t,s=null;i?(s=Ht(this.unplaced.content,i-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==e&&(r?o.matchType(r.type)||(l=o.fillBefore(d.from(r),!1)):s&&h.compatibleContent(s.type)))return{sliceDepth:i,frontierDepth:t,parent:s,inject:l};if(2==e&&r&&(n=o.findWrapping(r.type)))return{sliceDepth:i,frontierDepth:t,parent:s,wrap:n};if(s&&o.matchType(s.type))break}}}openMore(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Ht(t,e);return!(!s.childCount||s.firstChild.isLeaf||(this.unplaced=new b(t,e+1,Math.max(i,s.size+e>=t.size-i?e+1:0)),0))}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Ht(t,e);if(s.childCount<=1&&e>0){let r=t.size-e<=e+s.size;this.unplaced=new b(Yt(t,e-1,1),e-1,r?e-1:i)}else this.unplaced=new b(Yt(t,e,1),e,i)}placeNodes({sliceDepth:t,frontierDepth:e,parent:i,inject:s,wrap:r}){for(;this.depth>e;)this.closeFrontierNode();if(r)for(let t=0;t<r.length;t++)this.openFrontierNode(r[t]);let n=this.unplaced,h=i?i.content:n.content,o=n.openStart-t,l=0,u=[],{match:f,type:a}=this.frontier[e];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),e=f.matchType(t.type);if(!e)break;l++,(l>1||0==o||t.content.size)&&(f=e,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,e,d.from(u)),this.frontier[e].match=f,p&&c<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,e=h;t<c;t++){let t=e.lastChild;this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)}),e=t.content}this.unplaced=p?0==t?b.empty:new b(Yt(n.content,t-1,1),t-1,c<0?n.openEnd:t-1):new b(Yt(n.content,t,l),n.openStart,n.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t,e=this.frontier[this.depth];if(!e.type.isTextblock||!qt(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:i}=this.$to,s=this.$to.after(i);for(;i>1&&s==this.$to.end(--i);)++s;return s}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:i,type:s}=this.frontier[e],r=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),n=qt(t,e,s,i,r);if(n){for(let i=e-1;i>=0;i--){let{match:e,type:s}=this.frontier[i],r=qt(t,i,s,e,!0);if(!r||r.childCount)continue t}return{depth:e,fit:n,move:r?t.doc.resolve(t.after(e+1)):t}}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;for(;this.depth>e.depth;)this.closeFrontierNode();e.fit.childCount&&(this.placed=Ut(this.placed,e.depth,e.fit)),t=e.move;for(let i=e.depth+1;i<=t.depth;i++){let e=t.node(i),s=e.type.contentMatch.fillBefore(e.content,!0,t.index(i));this.openFrontierNode(e.type,e.attrs,s)}return t}openFrontierNode(t,e=null,i){let s=this.frontier[this.depth];s.match=s.match.matchType(t),this.placed=Ut(this.placed,this.depth,d.from(t.create(e,i))),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 Yt(t,e,i){return 0==e?t.cutByIndex(i,t.childCount):t.replaceChild(0,t.firstChild.copy(Yt(t.firstChild.content,e-1,i)))}function Ut(t,e,i){return 0==e?t.append(i):t.replaceChild(t.childCount-1,t.lastChild.copy(Ut(t.lastChild.content,e-1,i)))}function Ht(t,e){for(let i=0;i<e;i++)t=t.firstChild.content;return t}function Kt(t,e,i){if(e<=0)return t;let s=t.content;return e>1&&(s=s.replaceChild(0,Kt(s.firstChild,e-1,1==s.childCount?i-1:0))),e>0&&(s=t.type.contentMatch.fillBefore(s).append(s),i<=0&&(s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(d.empty,!0)))),t.copy(s)}function qt(t,e,i,s,r){let n=t.node(e),h=r?t.indexAfter(e):t.index(e);if(h==n.childCount&&!i.compatibleContent(n.type))return null;let o=s.fillBefore(n.content,!0,h);return o&&!function(t,e,i){for(let s=i;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return!0;return!1}(i,n.content,h)?o:null}function Gt(t,e,i,s,r){if(e<i){let r=t.firstChild;t=t.replaceChild(0,r.copy(Gt(r.content,e+1,i,s,r)))}if(e>s){let e=r.contentMatchAt(0),i=e.fillBefore(t).append(t);t=i.append(e.matchFragment(i).fillBefore(d.empty,!0))}return t}function Vt(t,e){let i=[];for(let s=Math.min(t.depth,e.depth);s>=0;s--){let r=t.start(s);if(r<t.pos-(t.depth-s)||e.end(s)>e.pos+(e.depth-s)||t.node(s).type.spec.isolating||e.node(s).type.spec.isolating)break;(r==e.start(s)||s==t.depth&&s==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==r-1)&&i.push(s)}return i}class Zt extends Ot{constructor(t,e,i){super(),this.pos=t,this.attr=e,this.value=i}apply(t){let e=t.nodeAt(this.pos);if(!e)return Tt.fail("No node at attribute step's position");let i=Object.create(null);for(let t in e.attrs)i[t]=e.attrs[t];i[this.attr]=this.value;let s=e.type.create(i,null,e.marks);return Tt.fromReplace(t,this.pos,this.pos+1,new b(d.from(s),0,e.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 e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Zt(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if("number"!=typeof e.pos||"string"!=typeof e.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new Zt(e.pos,e.attr,e.value)}}Ot.jsonID("attr",Zt);class Qt extends Ot{constructor(t,e){super(),this.attr=t,this.value=e}apply(t){let e=Object.create(null);for(let i in t.attrs)e[i]=t.attrs[i];e[this.attr]=this.value;let i=t.type.create(e,t.content,t.marks);return Tt.ok(i)}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,e){if("string"!=typeof e.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Qt(e.attr,e.value)}}Ot.jsonID("docAttr",Qt);let te=class extends Error{};te=function t(e){let i=Error.call(this,e);return i.__proto__=t.prototype,i},(te.prototype=Object.create(Error.prototype)).constructor=te,te.prototype.name="TransformError";class ee{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 e=this.maybeStep(t);if(e.failed)throw new te(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);return e.failed||this.addStep(t,e.doc),e}get docChanged(){return this.steps.length>0}changedRange(){let t=1e9,e=-1e9;for(let i=0;i<this.mapping.maps.length;i++){let s=this.mapping.maps[i];i&&(t=s.map(t,1),e=s.map(e,-1)),s.forEach(((i,s,r,n)=>{t=Math.min(t,r),e=Math.max(e,n)}))}return 1e9==t?null:{from:t,to:e}}addStep(t,e){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=e}replace(t,e=t,i=b.empty){let s=Jt(this.doc,t,e,i);return s&&this.step(s),this}replaceWith(t,e,i){return this.replace(t,e,new b(d.from(i),0,0))}delete(t,e){return this.replace(t,e,b.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(t,e,i){return function(t,e,i,s){if(!s.size)return t.deleteRange(e,i);let r=t.doc.resolve(e),n=t.doc.resolve(i);if(Lt(r,n,s))return t.step(new Ct(e,i,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,e=r.pos-1;t>0;t--,e--){let i=r.node(t).type.spec;if(i.defining||i.definingAsContext||i.isolating)break;h.indexOf(t)>-1?o=t:r.before(t)==e&&h.splice(1,0,-t)}let l=h.indexOf(o),u=[],f=s.openStart;for(let t=s.content,e=0;;e++){let i=t.firstChild;if(u.push(i),e==s.openStart)break;t=i.content}for(let t=f-1;t>=0;t--){let e=u[t],i=(a=e.type).spec.defining||a.spec.definingForContent;if(i&&!e.sameMarkup(r.node(Math.abs(o)-1)))f=t;else if(i||!e.type.isTextblock)break}var a;for(let e=s.openStart;e>=0;e--){let o=(e+f+1)%(s.openStart+1),a=u[o];if(a)for(let e=0;e<h.length;e++){let u=h[(e+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):i,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(e,i,s),!(t.steps.length>c));o--){let t=h[o];t<0||(e=r.before(t),i=n.after(t))}}(this,t,e,i),this}replaceRangeWith(t,e,i){return function(t,e,i,s){if(!s.isInline&&e==i&&t.doc.resolve(e).parent.content.size){let r=function(t,e,i){let s=t.resolve(e);if(s.parent.canReplaceWith(s.index(),s.index(),i))return e;if(0==s.parentOffset)for(let t=s.depth-1;t>=0;t--){let e=s.index(t);if(s.node(t).canReplaceWith(e,e,i))return s.before(t+1);if(e>0)return null}if(s.parentOffset==s.parent.content.size)for(let t=s.depth-1;t>=0;t--){let e=s.indexAfter(t);if(s.node(t).canReplaceWith(e,e,i))return s.after(t+1);if(e<s.node(t).childCount)return null}return null}(t.doc,e,s.type);null!=r&&(e=i=r)}t.replaceRange(e,i,new b(d.from(s),0,0))}(this,t,e,i),this}deleteRange(t,e){return function(t,e,i){let s=t.doc.resolve(e),r=t.doc.resolve(i);if(s.parent.isTextblock&&r.parent.isTextblock&&s.start()!=r.start()&&0==s.parentOffset&&0==r.parentOffset){let n=s.sharedDepth(i),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&&e==s.start(t);t--)e=s.before(t);for(let t=r.depth;t>0&&i==r.start(t);t--)i=r.before(t);s=t.doc.resolve(e),r=t.doc.resolve(i)}}let n=Vt(s,r);for(let e=0;e<n.length;e++){let i=n[e],h=e==n.length-1;if(h&&0==i||s.node(i).type.contentMatch.validEnd)return t.delete(s.start(i),r.end(i));if(i>0&&(h||s.node(i-1).canReplace(s.index(i-1),r.indexAfter(i-1))))return t.delete(s.before(i),r.after(i))}for(let n=1;n<=s.depth&&n<=r.depth;n++)if(e-s.start(n)==s.depth-n&&i>s.end(n)&&r.end(n)-i!=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),i);t.delete(e,i)}(this,t,e),this}lift(t,e){return function(t,e,i){let{$from:s,$to:r,depth:n}=e,h=s.before(n+1),o=r.after(n+1),l=h,u=o,f=d.empty,a=0;for(let t=n,e=!1;t>i;t--)e||s.index(t)>0?(e=!0,f=d.from(s.node(t).copy(f)),a++):l--;let c=d.empty,p=0;for(let t=n,e=!1;t>i;t--)e||r.after(t+1)<r.end(t)?(e=!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,e),this}join(t,e=1){return function(t,e,i){let s=null,{linebreakReplacement:r}=t.doc.type.schema,n=t.doc.resolve(e-i),h=n.node().type;if(r&&h.inlineContent){let t="pre"==h.whitespace,e=!!h.contentMatch.matchType(r);t&&!e?s=!1:!t&&e&&(s=!0)}let o=t.steps.length;if(!1===s){let s=t.doc.resolve(e+i);Ft(t,s.node(),s.before(),o)}h.inlineContent&&It(t,e+i-1,h,n.node().contentMatchAt(n.index()),null==s);let l=t.mapping.slice(o),u=l.map(e-i);if(t.step(new Ct(u,l.map(e+i,-1),b.empty,!0)),!0===s){let e=t.doc.resolve(u);jt(t,e.node(),e.before(),t.steps.length)}}(this,t,e),this}wrap(t,e){return function(t,e,i){let s=d.empty;for(let t=i.length-1;t>=0;t--){if(s.size){let e=i[t].type.contentMatch.matchFragment(s);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=d.from(i[t].type.create(i[t].attrs,s))}let r=e.start,n=e.end;t.step(new Pt(r,n,r,n,new b(s,0,0),i.length,!0))}(this,t,e),this}setBlockType(t,e=t,i,s=null){return function(t,e,i,s,r){if(!s.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let n=t.steps.length;t.doc.nodesBetween(e,i,((e,i)=>{let h="function"==typeof r?r(e):r;if(e.isTextblock&&!e.hasMarkup(s,h)&&function(t,e,i){let s=t.resolve(e),r=s.index();return s.parent.canReplaceWith(r,r+1,i)}(t.doc,t.mapping.slice(n).map(i),s)){let r=null;if(s.schema.linebreakReplacement){let t="pre"==s.whitespace,e=!!s.contentMatch.matchType(s.schema.linebreakReplacement);t&&!e?r=!1:!t&&e&&(r=!0)}!1===r&&Ft(t,e,i,n),It(t,t.mapping.slice(n).map(i,1),s,void 0,null===r);let o=t.mapping.slice(n),l=o.map(i,1),u=o.map(i+e.nodeSize,1);return t.step(new Pt(l,u,l+1,u-1,new b(d.from(s.create(h,null,e.marks)),0,0),1,!0)),!0===r&&jt(t,e,i,n),!1}}))}(this,t,e,i,s),this}setNodeMarkup(t,e,i=null,s){return function(t,e,i,s,r){let n=t.doc.nodeAt(e);if(!n)throw new RangeError("No node at given position");i||(i=n.type);let h=i.create(s,null,r||n.marks);if(n.isLeaf)return t.replaceWith(e,e+n.nodeSize,h);if(!i.validContent(n.content))throw new RangeError("Invalid content for node type "+i.name);t.step(new Pt(e,e+n.nodeSize,e+1,e+n.nodeSize-1,new b(d.from(h),0,0),1,!0))}(this,t,e,i,s),this}setNodeAttribute(t,e,i){return this.step(new Zt(t,e,i)),this}setDocAttribute(t,e){return this.step(new Qt(t,e)),this}addNodeMark(t,e){return this.step(new Et(t,e)),this}removeNodeMark(t,e){let i=this.doc.nodeAt(t);if(!i)throw new RangeError("No node at position "+t);if(e instanceof g)e.isInSet(i.marks)&&this.step(new $t(t,e));else{let s,r=i.marks,n=[];for(;s=e.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,e=1,i){return function(t,e,i=1,s){let r=t.doc.resolve(e),n=d.empty,h=d.empty;for(let t=r.depth,e=r.depth-i,o=i-1;t>e;t--,o--){n=d.from(r.node(t).copy(n));let e=s&&s[o];h=d.from(e?e.type.create(e.attrs,h):r.node(t).copy(h))}t.step(new Ct(e,e,new b(n.append(h),i,i),!0))}(this,t,e,i),this}addMark(t,e,i){return function(t,e,i,s){let r,n,h=[],o=[];t.doc.nodesBetween(e,i,((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,e),a=Math.min(l+t.nodeSize,i),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((e=>t.step(e))),o.forEach((e=>t.step(e)))}(this,t,e,i),this}removeMark(t,e,i){return function(t,e,i,s){let r=[],n=0;t.doc.nodesBetween(e,i,((t,h)=>{if(!t.isInline)return;n++;let o=null;if(s instanceof et){let e,i=t.marks;for(;e=s.isInSet(i);)(o||(o=[])).push(e),i=e.removeFromSet(i)}else s?s.isInSet(t.marks)&&(o=[s]):o=t.marks;if(o&&o.length){let s=Math.min(h+t.nodeSize,i);for(let t=0;t<o.length;t++){let i,l=o[t];for(let t=0;t<r.length;t++){let e=r[t];e.step==n-1&&l.eq(r[t].style)&&(i=e)}i?(i.to=s,i.step=n):r.push({style:l,from:Math.max(h,e),to:s,step:n})}}})),r.forEach((e=>t.step(new Rt(e.from,e.to,e.style))))}(this,t,e,i),this}clearIncompatible(t,e,i){return It(this,t,e,i),this}}const ie=Object.create(null);class se{constructor(t,e,i){this.$anchor=t,this.$head=e,this.ranges=i||[new re(t.min(e),t.max(e))]}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 e=0;e<t.length;e++)if(t[e].$from.pos!=t[e].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,e=b.empty){let i=e.content.lastChild,s=null;for(let t=0;t<e.openEnd;t++)s=i,i=i.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:e),0==h&&pe(t,r,(i?i.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(t,e){let i=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(i),l=o.map(n.pos),u=o.map(h.pos);r?t.deleteRange(l,u):(t.replaceRangeWith(l,u,e),pe(t,i,e.isInline?-1:1))}}static findFrom(t,e,i=!1){let s=t.parent.inlineContent?new oe(t):de(t.node(0),t.parent,t.pos,t.index(),e,i);if(s)return s;for(let s=t.depth-1;s>=0;s--){let r=e<0?de(t.node(0),t.node(s),t.before(s+1),t.index(s),e,i):de(t.node(0),t.node(s),t.after(s+1),t.index(s)+1,e,i);if(r)return r}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new ae(t.node(0))}static atStart(t){return de(t,t,0,0,1)||new ae(t)}static atEnd(t){return de(t,t,t.content.size,t.childCount,-1)||new ae(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let i=ie[e.type];if(!i)throw new RangeError(`No selection type ${e.type} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in ie)throw new RangeError("Duplicate use of selection JSON ID "+t);return ie[t]=e,e.prototype.jsonID=t,e}getBookmark(){return oe.between(this.$anchor,this.$head).getBookmark()}}se.prototype.visible=!0;class re{constructor(t,e){this.$from=t,this.$to=e}}let ne=!1;function he(t){ne||t.parent.inlineContent||(ne=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class oe extends se{constructor(t,e=t){he(t),he(e),super(t,e)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,e){let i=t.resolve(e.map(this.head));if(!i.parent.inlineContent)return se.near(i);let s=t.resolve(e.map(this.anchor));return new oe(s.parent.inlineContent?s:i,i)}replace(t,e=b.empty){if(super.replace(t,e),e==b.empty){let e=this.$from.marksAcross(this.$to);e&&t.ensureMarks(e)}}eq(t){return t instanceof oe&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new le(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if("number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new oe(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,i=e){let s=t.resolve(e);return new this(s,i==e?s:t.resolve(i))}static between(t,e,i){let s=t.pos-e.pos;if(i&&!s||(i=s>=0?1:-1),!e.parent.inlineContent){let t=se.findFrom(e,i,!0)||se.findFrom(e,-i,!0);if(!t)return se.near(e,i);e=t.$head}return t.parent.inlineContent||(0==s||(t=(se.findFrom(t,-i,!0)||se.findFrom(t,i,!0)).$anchor).pos<e.pos!=s<0)&&(t=e),new oe(t,e)}}se.jsonID("text",oe);class le{constructor(t,e){this.anchor=t,this.head=e}map(t){return new le(t.map(this.anchor),t.map(this.head))}resolve(t){return oe.between(t.resolve(this.anchor),t.resolve(this.head))}}class ue extends se{constructor(t){let e=t.nodeAfter,i=t.node(0).resolve(t.pos+e.nodeSize);super(t,i),this.node=e}map(t,e){let{deleted:i,pos:s}=e.mapResult(this.anchor),r=t.resolve(s);return i?se.near(r):new ue(r)}content(){return new b(d.from(this.node),0,0)}eq(t){return t instanceof ue&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new fe(this.anchor)}static fromJSON(t,e){if("number"!=typeof e.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new ue(t.resolve(e.anchor))}static create(t,e){return new ue(t.resolve(e))}static isSelectable(t){return!t.isText&&!1!==t.type.spec.selectable}}ue.prototype.visible=!1,se.jsonID("node",ue);class fe{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:i}=t.mapResult(this.anchor);return e?new le(i,i):new fe(i)}resolve(t){let e=t.resolve(this.anchor),i=e.nodeAfter;return i&&ue.isSelectable(i)?new ue(e):se.near(e)}}class ae extends se{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,e=b.empty){if(e==b.empty){t.delete(0,t.doc.content.size);let e=se.atStart(t.doc);e.eq(t.selection)||t.setSelection(e)}else super.replace(t,e)}toJSON(){return{type:"all"}}static fromJSON(t){return new ae(t)}map(t){return new ae(t)}eq(t){return t instanceof ae}getBookmark(){return ce}}se.jsonID("all",ae);const ce={map(){return this},resolve:t=>new ae(t)};function de(t,e,i,s,r,n=!1){if(e.inlineContent)return oe.create(t,i);for(let h=s-(r>0?0:1);r>0?h<e.childCount:h>=0;h+=r){let s=e.child(h);if(s.isAtom){if(!n&&ue.isSelectable(s))return ue.create(t,i-(r<0?s.nodeSize:0))}else{let e=de(t,s,i+r,r<0?s.childCount:0,r,n);if(e)return e}i+=s.nodeSize*r}return null}function pe(t,e,i){let s=t.steps.length-1;if(s<e)return;let r,n=t.steps[s];(n instanceof Ct||n instanceof Pt)&&(t.mapping.maps[s].forEach(((t,e,i,s)=>{null==r&&(r=s)})),t.setSelection(se.near(t.doc.resolve(r),i)))}class me extends ee{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,e){super.addStep(t,e),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,e=!0){let i=this.selection;return e&&(t=t.mark(this.storedMarks||(i.empty?i.$from.marks():i.$from.marksAcross(i.$to)||g.none))),i.replaceWith(this,t),this}deleteSelection(){return this.selection.replace(this),this}insertText(t,e,i){let s=this.doc.type.schema;if(null==e)return t?this.replaceSelectionWith(s.text(t),!0):this.deleteSelection();{if(null==i&&(i=e),!t)return this.deleteRange(e,i);let r=this.storedMarks;if(!r){let t=this.doc.resolve(e);r=i==e?t.marks():t.marksAcross(this.doc.resolve(i))}return this.replaceRangeWith(e,i,s.text(t,r)),this.selection.empty||this.selection.to!=e+t.length||this.setSelection(se.near(this.selection.$to)),this}}setMeta(t,e){return this.meta["string"==typeof t?t:t.key]=e,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 we(t,e){return e&&t?t.bind(e):t}class ge{constructor(t,e,i){this.name=t,this.init=we(e.init,i),this.apply=we(e.apply,i)}}const ye=[new ge("doc",{init:t=>t.doc||t.schema.topNodeType.createAndFill(),apply:t=>t.doc}),new ge("selection",{init:(t,e)=>t.selection||se.atStart(e.doc),apply:t=>t.selection}),new ge("storedMarks",{init:t=>t.storedMarks||null,apply:(t,e,i,s)=>s.selection.$cursor?t.storedMarks:null}),new ge("scrollToSelection",{init:()=>0,apply:(t,e)=>t.scrolledIntoView?e+1:e})];class be{constructor(t,e){this.schema=t,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ye.slice(),e&&e.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 ge(t.key,t.spec.state,t))}))}}class Me{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,e=-1){for(let i=0;i<this.config.plugins.length;i++)if(i!=e){let e=this.config.plugins[i];if(e.spec.filterTransaction&&!e.spec.filterTransaction.call(e,t,this))return!1}return!0}applyTransaction(t){if(!this.filterTransaction(t))return{state:this,transactions:[]};let e=[t],i=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<e.length&&h.spec.appendTransaction.call(h,o?e.slice(o):e,l,i);if(u&&i.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:i,n:e.length}:{state:this,n:0})}e.push(u),i=i.applyInner(u),r=!0}s&&(s[n]={state:i,n:e.length})}}if(!r)return{state:i,transactions:e}}}applyInner(t){if(!t.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let e=new Me(this.config),i=this.config.fields;for(let s=0;s<i.length;s++){let r=i[s];e[r.name]=r.apply(t,this[r.name],this,e)}return e}get tr(){return new me(this)}static create(t){let e=new be(t.doc?t.doc.type.schema:t.schema,t.plugins),i=new Me(e);for(let s=0;s<e.fields.length;s++)i[e.fields[s].name]=e.fields[s].init(t,i);return i}reconfigure(t){let e=new be(this.schema,t.plugins),i=e.fields,s=new Me(e);for(let e=0;e<i.length;e++){let r=i[e].name;s[r]=this.hasOwnProperty(r)?this[r]:i[e].init(t,s)}return s}toJSON(t){let e={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(e.storedMarks=this.storedMarks.map((t=>t.toJSON()))),t&&"object"==typeof t)for(let i in t){if("doc"==i||"selection"==i)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let s=t[i],r=s.spec.state;r&&r.toJSON&&(e[i]=r.toJSON.call(s,this[s.key]))}return e}static fromJSON(t,e,i){if(!e)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let s=new be(t.schema,t.plugins),r=new Me(s);return s.fields.forEach((s=>{if("doc"==s.name)r.doc=_.fromJSON(t.schema,e.doc);else if("selection"==s.name)r.selection=se.fromJSON(r.doc,e.selection);else if("storedMarks"==s.name)e.storedMarks&&(r.storedMarks=e.storedMarks.map(t.schema.markFromJSON));else{if(i)for(let n in i){let h=i[n],o=h.spec.state;if(h.key==s.name&&o&&o.fromJSON&&Object.prototype.hasOwnProperty.call(e,n))return void(r[s.name]=o.fromJSON.call(h,t,e[n],r))}r[s.name]=s.init(t,r)}})),r}}function ve(t,e,i){for(let s in t){let r=t[s];r instanceof Function?r=r.bind(e):"handleDOMEvents"==s&&(r=ve(r,e,{})),i[s]=r}return i}class ke{constructor(t){var e;this.spec=t,this.props={},t.props&&ve(t.props,this,this.props),this.key=t.key?t.key.key:(e="plugin")in Se?e+"$"+ ++Se[e]:(Se[e]=0,e+"$")}getState(t){return t[this.key]}}const Se=Object.create(null),xe=function(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e},Oe=function(t){let e=t.assignedSlot||t.parentNode;return e&&11==e.nodeType?e.host:e};let Te=null;const De=function(t,e,i){let s=Te||(Te=document.createRange());return s.setEnd(t,null==i?t.nodeValue.length:i),s.setStart(t,e||0),s},Ae=function(t,e,i,s){return i&&(Ee(t,e,i,s,-1)||Ee(t,e,i,s,1))},Re=/^(img|br|input|textarea|hr)$/i;function Ee(t,e,i,s,r){for(var n;;){if(t==i&&e==s)return!0;if(e==(r<0?0:$e(t))){let i=t.parentNode;if(!i||1!=i.nodeType||Ce(t)||Re.test(t.nodeName)||"false"==t.contentEditable)return!1;e=xe(t)+(r<0?0:1),t=i}else{if(1!=t.nodeType)return!1;{let i=t.childNodes[e+(r<0?-1:0)];if(1==i.nodeType&&"false"==i.contentEditable){if(!(null===(n=i.pmViewDesc)||void 0===n?void 0:n.ignoreForSelection))return!1;e+=r}else t=i,e=r<0?$e(t):0}}}}function $e(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Ce(t){let e;for(let i=t;i&&!(e=i.pmViewDesc);i=i.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Pe=function(t){return t.focusNode&&Ae(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Ne(t,e){let i=document.createEvent("Event");return i.initEvent("keydown",!0,!0),i.keyCode=t,i.key=i.code=e,i}const Ie="undefined"!=typeof navigator?navigator:null,ze="undefined"!=typeof document?document:null,_e=Ie&&Ie.userAgent||"",je=/Edge\/(\d+)/.exec(_e),Fe=/MSIE \d/.exec(_e),Be=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(_e),We=!!(Fe||Be||je),Je=Fe?document.documentMode:Be?+Be[1]:je?+je[1]:0,Le=!We&&/gecko\/(\d+)/i.test(_e),Xe=!We&&/Chrome\/(\d+)/.exec(_e),Ye=!!Xe,Ue=Xe?+Xe[1]:0,He=!We&&!!Ie&&/Apple Computer/.test(Ie.vendor),Ke=He&&(/Mobile\/\w+/.test(_e)||!!Ie&&Ie.maxTouchPoints>2),qe=Ke||!!Ie&&/Mac/.test(Ie.platform),Ge=!!Ie&&/Win/.test(Ie.platform),Ve=/Android \d/.test(_e),Ze=!!ze&&"webkitFontSmoothing"in ze.documentElement.style,Qe=Ze?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ti(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function ei(t,e){return"number"==typeof t?t:t[e]}function ii(t){let e=t.getBoundingClientRect();return{left:e.left,right:e.left+t.clientWidth*(e.width/t.offsetWidth||1),top:e.top,bottom:e.top+t.clientHeight*(e.height/t.offsetHeight||1)}}function si(t,e,i){let s=t.someProp("scrollThreshold")||0,r=t.someProp("scrollMargin")||5,n=t.dom.ownerDocument;for(let h=i||t.dom;h;){if(1!=h.nodeType){h=Oe(h);continue}let t=h,i=t==n.body,o=i?ti(n):ii(t),l=0,u=0;if(e.top<o.top+ei(s,"top")?u=-(o.top-e.top+ei(r,"top")):e.bottom>o.bottom-ei(s,"bottom")&&(u=e.bottom-e.top>o.bottom-o.top?e.top+ei(r,"top")-o.top:e.bottom-o.bottom+ei(r,"bottom")),e.left<o.left+ei(s,"left")?l=-(o.left-e.left+ei(r,"left")):e.right>o.right-ei(s,"right")&&(l=e.right-o.right+ei(r,"right")),l||u)if(i)n.defaultView.scrollBy(l,u);else{let i=t.scrollLeft,s=t.scrollTop;u&&(t.scrollTop+=u),l&&(t.scrollLeft+=l);let r=t.scrollLeft-i,n=t.scrollTop-s;e={left:e.left-r,top:e.top-n,right:e.right-r,bottom:e.bottom-n}}let f=i?"fixed":getComputedStyle(h).position;if(/^(fixed|sticky)$/.test(f))break;h="absolute"==f?h.offsetParent:Oe(h)}}function ri(t){let e=[],i=t.ownerDocument;for(let s=t;s&&(e.push({dom:s,top:s.scrollTop,left:s.scrollLeft}),t!=i);s=Oe(s));return e}function ni(t,e){for(let i=0;i<t.length;i++){let{dom:s,top:r,left:n}=t[i];s.scrollTop!=r+e&&(s.scrollTop=r+e),s.scrollLeft!=n&&(s.scrollLeft=n)}}let hi=null;function oi(t,e){let i,s,r,n,h=2e8,o=0,l=e.top,u=e.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=De(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>e.left?d.left-e.left:d.right<e.left?e.left-d.right:0;if(t<h){i=f,h=t,s=t&&3==i.nodeType?{left:d.right<e.left?d.right:d.left,top:e.top}:e,1==f.nodeType&&t&&(o=a+(e.left>=(d.left+d.right)/2?1:0));continue}}else d.top>e.top&&!r&&d.left<=e.left&&d.right>=e.left&&(r=f,n={left:Math.max(d.left,Math.min(d.right,e.left)),top:d.top});!i&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom)&&(o=a+1)}}return!i&&r&&(i=r,s=n,h=0),i&&3==i.nodeType?function(t,e){let i,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=ci(r,1);if(s.top!=s.bottom&&li(e,s)){i={node:t,offset:n+(e.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}(i,s):!i||h&&1==i.nodeType?{node:t,offset:o}:oi(i,s)}function li(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function ui(t,e,i){let s=t.childNodes.length;if(s&&i.top<i.bottom)for(let r=Math.max(0,Math.min(s-1,Math.floor(s*(e.top-i.top)/(i.bottom-i.top))-2)),n=r;;){let i=t.childNodes[n];if(1==i.nodeType){let t=i.getClientRects();for(let s=0;s<t.length;s++){let r=t[s];if(li(e,r))return ui(i,e,r)}}if((n=(n+1)%s)==r)break}return t}function fi(t,e){let i,s=t.dom.ownerDocument,r=0,n=function(t,e,i){if(t.caretPositionFromPoint)try{let s=t.caretPositionFromPoint(e,i);if(s)return{node:s.offsetNode,offset:Math.min($e(s.offsetNode),s.offset)}}catch(t){}if(t.caretRangeFromPoint){let s=t.caretRangeFromPoint(e,i);if(s)return{node:s.startContainer,offset:Math.min($e(s.startContainer),s.startOffset)}}}(s,e.left,e.top);n&&({node:i,offset:r}=n);let h,o=(t.root.elementFromPoint?t.root:s).elementFromPoint(e.left,e.top);if(!o||!t.dom.contains(1!=o.nodeType?o.parentNode:o)){let i=t.dom.getBoundingClientRect();if(!li(e,i))return null;if(o=ui(t.dom,e,i),!o)return null}if(He)for(let t=o;i&&t;t=Oe(t))t.draggable&&(i=void 0);if(o=function(t,e){let i=t.parentNode;return i&&/^li$/i.test(i.nodeName)&&e.left<t.getBoundingClientRect().left?i:t}(o,e),i){if(Le&&1==i.nodeType&&(r=Math.min(r,i.childNodes.length),r<i.childNodes.length)){let t,s=i.childNodes[r];"IMG"==s.nodeName&&(t=s.getBoundingClientRect()).right<=e.left&&t.bottom>e.top&&r++}let s;Ze&&r&&1==i.nodeType&&1==(s=i.childNodes[r-1]).nodeType&&"false"==s.contentEditable&&s.getBoundingClientRect().top>=e.top&&r--,i==t.dom&&r==i.childNodes.length-1&&1==i.lastChild.nodeType&&e.top>i.lastChild.getBoundingClientRect().bottom?h=t.state.doc.content.size:0!=r&&1==i.nodeType&&"BR"==i.childNodes[r-1].nodeName||(h=function(t,e,i,s){let r=-1;for(let i=e,n=!1;i!=t.dom;){let e,h=t.docView.nearestDesc(i,!0);if(!h)return null;if(1==h.dom.nodeType&&(h.node.isBlock&&h.parent||!h.contentDOM)&&((e=h.dom.getBoundingClientRect()).width||e.height)&&(h.node.isBlock&&h.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(h.dom.nodeName)&&(!n&&e.left>s.left||e.top>s.top?r=h.posBefore:(!n&&e.right<s.left||e.bottom<s.top)&&(r=h.posAfter),n=!0),!h.contentDOM&&r<0&&!h.node.isText))return(h.node.isBlock?s.top<(e.top+e.bottom)/2:s.left<(e.left+e.right)/2)?h.posBefore:h.posAfter;i=h.dom.parentNode}return r>-1?r:t.docView.posFromDOM(e,i,-1)}(t,i,r,e))}null==h&&(h=function(t,e,i){let{node:s,offset:r}=oi(e,i),n=-1;if(1==s.nodeType&&!s.firstChild){let t=s.getBoundingClientRect();n=t.left!=t.right&&i.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(s,r,n)}(t,o,e));let l=t.docView.nearestDesc(o,!0);return{pos:h,inside:l?l.posAtStart-l.border:-1}}function ai(t){return t.top<t.bottom||t.left<t.right}function ci(t,e){let i=t.getClientRects();if(i.length){let t=i[e<0?0:i.length-1];if(ai(t))return t}return Array.prototype.find.call(i,ai)||t.getBoundingClientRect()}const di=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function pi(t,e,i){let{node:s,offset:r,atom:n}=t.docView.domFromPos(e,i<0?-1:1),h=Ze||Le;if(3==s.nodeType){if(!h||!di.test(s.nodeValue)&&(i<0?r:r!=s.nodeValue.length)){let t=r,e=r,n=i<0?1:-1;return i<0&&!r?(e++,n=-1):i>=0&&r==s.nodeValue.length?(t--,n=1):i<0?t--:e++,mi(ci(De(s,t,e),n),n<0)}{let t=ci(De(s,r,r),i);if(Le&&r&&/\s/.test(s.nodeValue[r-1])&&r<s.nodeValue.length){let e=ci(De(s,r-1,r-1),-1);if(e.top==t.top){let i=ci(De(s,r,r+1),-1);if(i.top!=t.top)return mi(i,i.left<e.left)}}return t}}if(!t.state.doc.resolve(e-(n||0)).parent.inlineContent){if(null==n&&r&&(i<0||r==$e(s))){let t=s.childNodes[r-1];if(1==t.nodeType)return wi(t.getBoundingClientRect(),!1)}if(null==n&&r<$e(s)){let t=s.childNodes[r];if(1==t.nodeType)return wi(t.getBoundingClientRect(),!0)}return wi(s.getBoundingClientRect(),i>=0)}if(null==n&&r&&(i<0||r==$e(s))){let t=s.childNodes[r-1],e=3==t.nodeType?De(t,$e(t)-(h?0:1)):1!=t.nodeType||"BR"==t.nodeName&&t.nextSibling?null:t;if(e)return mi(ci(e,1),!1)}if(null==n&&r<$e(s)){let t=s.childNodes[r];for(;t.pmViewDesc&&t.pmViewDesc.ignoreForCoords;)t=t.nextSibling;let e=t?3==t.nodeType?De(t,0,h?0:1):1==t.nodeType?t:null:null;if(e)return mi(ci(e,-1),!0)}return mi(ci(3==s.nodeType?De(s):s,-i),i>=0)}function mi(t,e){if(0==t.width)return t;let i=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:i,right:i}}function wi(t,e){if(0==t.height)return t;let i=e?t.top:t.bottom;return{top:i,bottom:i,left:t.left,right:t.right}}function gi(t,e,i){let s=t.state,r=t.root.activeElement;s!=e&&t.updateState(e),r!=t.dom&&t.focus();try{return i()}finally{s!=e&&t.updateState(s),r!=t.dom&&r&&r.focus()}}const yi=/[\u0590-\u08ac]/;let bi=null,Mi=null,vi=!1;class ki{constructor(t,e,i,s){this.parent=t,this.children=e,this.dom=i,this.contentDOM=s,this.dirty=0,i.pmViewDesc=this}matchesWidget(t){return!1}matchesMark(t){return!1}matchesNode(t,e,i){return!1}matchesHack(t){return!1}parseRule(){return null}stopEvent(t){return!1}get size(){let t=0;for(let e=0;e<this.children.length;e++)t+=this.children[e].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 e=0,i=this.posAtStart;;e++){let s=this.children[e];if(s==t)return i;i+=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,e,i){if(this.contentDOM&&this.contentDOM.contains(1==t.nodeType?t:t.parentNode)){if(i<0){let i,s;if(t==this.contentDOM)i=t.childNodes[e-1];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.previousSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.previousSibling;return i?this.posBeforeChild(s)+s.size:this.posAtStart}{let i,s;if(t==this.contentDOM)i=t.childNodes[e];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.nextSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.nextSibling;return i?this.posBeforeChild(s):this.posAtEnd}}let s;if(t==this.dom&&this.contentDOM)s=e>xe(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==e)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!1;break}if(e.previousSibling)break}if(null==s&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!0;break}if(e.nextSibling)break}}return(null==s?i>0:s)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=!1){for(let i=!0,s=t;s;s=s.parentNode){let r,n=this.getDesc(s);if(n&&(!e||n.node)){if(!i||!(r=n.nodeDOM)||(1==r.nodeType?r.contains(1==t.nodeType?t:t.parentNode):r==t))return n;i=!1}}}getDesc(t){let e=t.pmViewDesc;for(let t=e;t;t=t.parent)if(t==this)return e}posFromDOM(t,e,i){for(let s=t;s;s=s.parentNode){let r=this.getDesc(s);if(r)return r.localPosFromDOM(t,e,i)}return-1}descAt(t){for(let e=0,i=0;e<this.children.length;e++){let s=this.children[e],r=i+s.size;if(i==t&&r!=i){for(;!s.border&&s.children.length;)for(let t=0;t<s.children.length;t++){let e=s.children[t];if(e.size){s=e;break}}return s}if(t<r)return s.descAt(t-i-s.border);i=r}}domFromPos(t,e){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let i=0,s=0;for(let e=0;i<this.children.length;i++){let r=this.children[i],n=e+r.size;if(n>t||r instanceof Ri){s=t-e;break}e=n}if(s)return this.children[i].domFromPos(s-this.children[i].border,e);for(let t;i&&!(t=this.children[i-1]).size&&t instanceof Si&&t.side>=0;i--);if(e<=0){let t,s=!0;for(;t=i?this.children[i-1]:null,t&&t.dom.parentNode!=this.contentDOM;i--,s=!1);return t&&e&&s&&!t.border&&!t.domAtom?t.domFromPos(t.size,e):{node:this.contentDOM,offset:t?xe(t.dom)+1:0}}{let t,s=!0;for(;t=i<this.children.length?this.children[i]:null,t&&t.dom.parentNode!=this.contentDOM;i++,s=!1);return t&&s&&!t.border&&!t.domAtom?t.domFromPos(0,e):{node:this.contentDOM,offset:t?xe(t.dom):this.contentDOM.childNodes.length}}}parseRange(t,e,i=0){if(0==this.children.length)return{node:this.contentDOM,from:t,to:e,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let s=-1,r=-1;for(let n=i,h=0;;h++){let i=this.children[h],o=n+i.size;if(-1==s&&t<=o){let r=n+i.border;if(t>=r&&e<=o-i.border&&i.node&&i.contentDOM&&this.contentDOM.contains(i.contentDOM))return i.parseRange(t,e,r);t=n;for(let e=h;e>0;e--){let i=this.children[e-1];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(1)){s=xe(i.dom)+1;break}t-=i.size}-1==s&&(s=0)}if(s>-1&&(o>e||h==this.children.length-1)){e=o;for(let t=h+1;t<this.children.length;t++){let i=this.children[t];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(-1)){r=xe(i.dom);break}e+=i.size}-1==r&&(r=this.contentDOM.childNodes.length);break}n=o}return{node:this.contentDOM,from:t,to:e,fromOffset:s,toOffset:r}}emptyChildAt(t){if(this.border||!this.contentDOM||!this.children.length)return!1;let e=this.children[t<0?0:this.children.length-1];return 0==e.size||e.emptyChildAt(t)}domAfterPos(t){let{node:e,offset:i}=this.domFromPos(t,0);if(1!=e.nodeType||i==e.childNodes.length)throw new RangeError("No node after pos "+t);return e.childNodes[i]}setSelection(t,e,i,s=!1){let r=Math.min(t,e),n=Math.max(t,e);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,e-o-l.border,i,s);o=u}let h=this.domFromPos(t,t?-1:1),o=e==t?h:this.domFromPos(e,e?-1:1),l=i.root.getSelection(),u=i.domSelectionRange(),f=!1;if((Le||He)&&t==e){let{node:t,offset:e}=h;if(3==t.nodeType){if(f=!(!e||"\n"!=t.nodeValue[e-1]),f&&e==t.nodeValue.length)for(let e,i=t;i;i=i.parentNode){if(e=i.nextSibling){"BR"==e.nodeName&&(h=o={node:e.parentNode,offset:xe(e)+1});break}let t=i.pmViewDesc;if(t&&t.node&&t.node.isBlock)break}}else{let i=t.childNodes[e-1];f=i&&("BR"==i.nodeName||"false"==i.contentEditable)}}if(Le&&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&&He)&&Ae(h.node,h.offset,u.anchorNode,u.anchorOffset)&&Ae(o.node,o.offset,u.focusNode,u.focusOffset))return;let a=!1;if((l.extend||t==e)&&(!f||!Le)){l.collapse(h.node,h.offset);try{t!=e&&l.extend(o.node,o.offset),a=!0}catch(t){}}if(!a){if(t>e){let t=h;h=o,o=t}let i=document.createRange();i.setEnd(o.node,o.offset),i.setStart(h.node,h.offset),l.removeAllRanges(),l.addRange(i)}}ignoreMutation(t){return!this.contentDOM&&"selection"!=t.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(t,e){for(let i=0,s=0;s<this.children.length;s++){let r=this.children[s],n=i+r.size;if(i==n?t<=n&&e>=i:t<n&&e>i){let s=i+r.border,h=n-r.border;if(t>=s&&e<=h)return this.dirty=t==i||e==n?2:1,void(t!=s||e!=h||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(t-s,e-s):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.children.length?3:2}i=n}this.dirty=2}markParentsDirty(){let t=1;for(let e=this.parent;e;e=e.parent,t++){let i=1==t?2:1;e.dirty<i&&(e.dirty=i)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(t){return!1}}class Si extends ki{constructor(t,e,i,s){let r,n=e.type.toDOM;if("function"==typeof n&&(n=n(i,(()=>r?r.parent?r.parent.posBeforeChild(r):void 0:s))),!e.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=e,this.widget=e,r=this}matchesWidget(t){return 0==this.dirty&&t.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(t){let e=this.widget.spec.stopEvent;return!!e&&e(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 xi extends ki{constructor(t,e,i,s){super(t,[],e,null),this.textDOM=i,this.text=s}get size(){return this.text.length}localPosFromDOM(t,e){return t!=this.textDOM?this.posAtStart+(e?this.size:0):this.posAtStart+e}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return"characterData"===t.type&&t.target.nodeValue==t.oldValue}}class Oi extends ki{constructor(t,e,i,s,r){super(t,[],i,s),this.mark=e,this.spec=r}static create(t,e,i,s){let r=s.nodeViews[e.type.name],n=r&&r(e,s,i);return n&&n.dom||(n=pt.renderSpec(document,e.type.spec.toDOM(e,i),null,e.attrs)),new Oi(t,e,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,e){if(super.markDirty(t,e),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,e,i){let s=Oi.create(this.parent,this.mark,!0,i),r=this.children,n=this.size;e<n&&(r=Ji(r,e,n,i)),t>0&&(r=Ji(r,0,t,i));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 Ti extends ki{constructor(t,e,i,s,r,n,h,o,l){super(t,[],r,n),this.node=e,this.outerDeco=i,this.innerDeco=s,this.nodeDOM=h}static create(t,e,i,s,r,n){let h,o=r.nodeViews[e.type.name],l=o&&o(e,r,(()=>h?h.parent?h.parent.posBeforeChild(h):void 0:n),i,s),u=l&&l.dom,f=l&&l.contentDOM;if(e.isText)if(u){if(3!=u.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else u=document.createTextNode(e.text);else if(!u){let t=pt.renderSpec(document,e.type.spec.toDOM(e),null,e.attrs);({dom:u,contentDOM:f}=t)}f||e.isText||"BR"==u.nodeName||(u.hasAttribute("contenteditable")||(u.contentEditable="false"),e.type.spec.draggable&&(u.draggable=!0));let a=u;return u=_i(u,i,e),l?h=new Ei(t,e,i,s,u,f||null,a,l,r,n+1):e.isText?new Ai(t,e,i,s,u,a,r):new Ti(t,e,i,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 e=this.children.length-1;e>=0;e--){let i=this.children[e];if(this.dom.contains(i.dom.parentNode)){t.contentElement=i.dom.parentNode;break}}t.contentElement||(t.getContent=()=>d.empty)}else t.contentElement=this.contentDOM;else t.getContent=()=>this.node.content;return t}matchesNode(t,e,i){return 0==this.dirty&&t.eq(this.node)&&ji(e,this.outerDeco)&&i.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(t,e){let i=this.node.inlineContent,s=e,r=t.composing?this.localCompositionInfo(t,e):null,n=r&&r.pos>-1?r:null,h=r&&r.pos<0,o=new Bi(this,n&&n.node,t);!function(t,e,i,s){let r=e.locals(t),n=0;if(0==r.length){for(let i=0;i<t.childCount;i++){let h=t.child(i);s(h,r,e.forChild(n,h),i),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(Wi);for(let t=0;t<a.length;t++)i(a[t],u,!!l)}else i(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 e=0;e<o.length;e++)o[e].to<t&&(t=o[e].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(),e.forChild(n,c),d),n=p}}(this.node,this.innerDeco,((e,r,n)=>{e.spec.marks?o.syncToMarks(e.spec.marks,i,t,r):e.type.side>=0&&!n&&o.syncToMarks(r==this.node.childCount?g.none:this.node.child(r).marks,i,t,r),o.placeWidget(e,t,s)}),((e,n,l,u)=>{let f;o.syncToMarks(e.marks,i,t,u),o.findNodeMatch(e,n,l,u)||h&&t.state.selection.from>s&&t.state.selection.to<s+e.nodeSize&&(f=o.findIndexWithChild(r.node))>-1&&o.updateNodeAt(e,n,l,f,t)||o.updateNextNode(e,n,l,t,u,s)||o.addNode(e,n,l,t,s),s+=e.nodeSize})),o.syncToMarks([],i,t,0),this.node.isTextblock&&o.addTextblockHacks(),o.destroyRest(),(o.changed||2==this.dirty)&&(n&&this.protectLocalComposition(t,n),$i(this.contentDOM,this.children,t),Ke&&function(t){if("UL"==t.nodeName||"OL"==t.nodeName){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t),t.style.cssText=e}}(this.dom))}localCompositionInfo(t,e){let{from:i,to:s}=t.state.selection;if(!(t.state.selection instanceof oe)||i<e||s>e+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,e,i,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 e=t.child(r++);if(n+=e.nodeSize,!e.isText)break;l+=e.text}if(n>=i){if(n>=s&&l.slice(s-e.length-o,s-o)==e)return s-e.length;let t=o<s?l.lastIndexOf(e,s-o-1):-1;if(t>=0&&t+e.length+o>=i)return o+t;if(i==s&&l.length>=s+e.length-o&&l.slice(s-o,s-o+e.length)==e)return s}}return-1}(this.node.content,t,i-e,s-e);return n<0?null:{node:r,pos:n,text:t}}return{node:r,pos:-1,text:""}}protectLocalComposition(t,{node:e,pos:i,text:s}){if(this.getDesc(e))return;let r=e;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 xi(this,r,e,s);t.input.compositionNodes.push(n),this.children=Ji(this.children,i,i+s.length,t,n)}update(t,e,i,s){return!(3==this.dirty||!t.sameMarkup(this.node)||(this.updateInner(t,e,i,s),0))}updateInner(t,e,i,s){this.updateOuterDeco(e),this.node=t,this.innerDeco=i,this.contentDOM&&this.updateChildren(s,this.posAtStart),this.dirty=0}updateOuterDeco(t){if(ji(t,this.outerDeco))return;let e=1!=this.nodeDOM.nodeType,i=this.dom;this.dom=Ii(this.dom,this.nodeDOM,Ni(this.outerDeco,this.node,e),Ni(t,this.node,e)),this.dom!=i&&(i.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 Di(t,e,i,s,r){_i(s,e,t);let n=new Ti(void 0,t,e,i,s,s,s,r,0);return n.contentDOM&&n.updateChildren(r,0),n}class Ai extends Ti{constructor(t,e,i,s,r,n,h){super(t,e,i,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,e,i,s){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!t.sameMarkup(this.node)||(this.updateOuterDeco(e),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 e=this.nodeDOM;e;e=e.parentNode)if(e==t)return!0;return!1}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,e,i){return t==this.nodeDOM?this.posAtStart+Math.min(e,this.node.text.length):super.localPosFromDOM(t,e,i)}ignoreMutation(t){return"characterData"!=t.type&&"selection"!=t.type}slice(t,e,i){let s=this.node.cut(t,e),r=document.createTextNode(s.text);return new Ai(this.parent,s,this.outerDeco,this.innerDeco,r,r,i)}markDirty(t,e){super.markDirty(t,e),this.dom==this.nodeDOM||0!=t&&e!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}isText(t){return this.node.text==t}}class Ri extends ki{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 Ei extends Ti{constructor(t,e,i,s,r,n,h,o,l,u){super(t,e,i,s,r,n,h,l,u),this.spec=o}update(t,e,i,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,e,i);return r&&this.updateInner(t,e,i,s),r}return!(!this.contentDOM&&!t.isLeaf)&&super.update(t,e,i,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,e,i,s){this.spec.setSelection?this.spec.setSelection(t,e,i.root):super.setSelection(t,e,i,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 $i(t,e,i){let s=t.firstChild,r=!1;for(let n=0;n<e.length;n++){let h=e[n],o=h.dom;if(o.parentNode==t){for(;o!=s;)s=Fi(s),r=!0;s=s.nextSibling}else r=!0,t.insertBefore(o,s);if(h instanceof Oi){let e=s?s.previousSibling:t.lastChild;$i(h.contentDOM,h.children,i),s=e?e.nextSibling:t.firstChild}}for(;s;)s=Fi(s),r=!0;r&&i.trackWrites==t&&(i.trackWrites=null)}const Ci=function(t){t&&(this.nodeName=t)};Ci.prototype=Object.create(null);const Pi=[new Ci];function Ni(t,e,i){if(0==t.length)return Pi;let s=i?Pi[0]:new Ci,r=[s];for(let n=0;n<t.length;n++){let h=t[n].type.attrs;if(h){h.nodeName&&r.push(s=new Ci(h.nodeName));for(let t in h){let n=h[t];null!=n&&(i&&1==r.length&&r.push(s=new Ci(e.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 Ii(t,e,i,s){if(i==Pi&&s==Pi)return e;let r=e;for(let e=0;e<s.length;e++){let n=s[e],h=i[e];if(e){let e;h&&h.nodeName==n.nodeName&&r!=t&&(e=r.parentNode)&&e.nodeName.toLowerCase()==n.nodeName||(e=document.createElement(n.nodeName),e.pmIsDeco=!0,e.appendChild(r),h=Pi[0]),r=e}zi(r,h||Pi[0],n)}return r}function zi(t,e,i){for(let s in e)"class"==s||"style"==s||"nodeName"==s||s in i||t.removeAttribute(s);for(let s in i)"class"!=s&&"style"!=s&&"nodeName"!=s&&i[s]!=e[s]&&t.setAttribute(s,i[s]);if(e.class!=i.class){let s=e.class?e.class.split(" ").filter(Boolean):[],r=i.class?i.class.split(" ").filter(Boolean):[];for(let e=0;e<s.length;e++)-1==r.indexOf(s[e])&&t.classList.remove(s[e]);for(let e=0;e<r.length;e++)-1==s.indexOf(r[e])&&t.classList.add(r[e]);0==t.classList.length&&t.removeAttribute("class")}if(e.style!=i.style){if(e.style){let i,s=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;i=s.exec(e.style);)t.style.removeProperty(i[1])}i.style&&(t.style.cssText+=i.style)}}function _i(t,e,i){return Ii(t,t,Pi,Ni(e,i,1!=t.nodeType))}function ji(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].type.eq(e[i].type))return!1;return!0}function Fi(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class Bi{constructor(t,e,i){this.lock=e,this.view=i,this.index=0,this.stack=[],this.changed=!1,this.top=t,this.preMatch=function(t,e){let i=e,s=i.children.length,r=t.childCount,n=new Map,h=[];t:for(;r>0;){let o;for(;;)if(s){let t=i.children[s-1];if(!(t instanceof Oi)){o=t,s--;break}i=t,s=t.children.length}else{if(i==e)break t;s=i.parent.children.indexOf(i),i=i.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,e){if(t!=e){for(let i=t;i<e;i++)this.top.children[i].destroy();this.top.children.splice(t,e-t),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(t,e,i,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 e=this.index;e<h;e++){let i=this.top.children[e];if(i.matchesMark(t[n])&&!this.isLocked(i.dom)){r=e;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=Oi.create(this.top,t[n],e,i);this.top.children.splice(this.index,0,s),this.top=s,this.changed=!0}this.index=0,n++}}findNodeMatch(t,e,i,s){let r,n=-1;if(s>=this.preMatch.index&&(r=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&r.matchesNode(t,e,i))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,e,i)&&!this.preMatch.matched.has(r)){n=s;break}}return!(n<0||(this.destroyBetween(this.index,n),this.index++,0))}updateNodeAt(t,e,i,s,r){let n=this.top.children[s];return 3==n.dirty&&n.dom==n.contentDOM&&(n.dirty=2),!!n.update(t,e,i,r)&&(this.destroyBetween(this.index,s),this.index++,!0)}findIndexWithChild(t){for(;;){let e=t.parentNode;if(!e)return-1;if(e==this.top.contentDOM){let e=t.pmViewDesc;if(e)for(let t=this.index;t<this.top.children.length;t++)if(this.top.children[t]==e)return t;return-1}t=e}}updateNextNode(t,e,i,s,r,n){for(let h=this.index;h<this.top.children.length;h++){let o=this.top.children[h];if(o instanceof Ti){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&&ji(e,o.outerDeco));if(!a&&o.update(t,e,i,s))return this.destroyBetween(this.index,h),o.dom!=f&&(this.changed=!0),this.index++,!0;if(!a&&(u=this.recreateWrapper(o,t,e,i,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,e,i,s,r,n){if(t.dirty||e.isAtom||!t.children.length||!t.node.content.eq(e.content)||!ji(i,t.outerDeco)||!s.eq(t.innerDeco))return null;let h=Ti.create(this.top,e,i,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,e,i,s,r){let n=Ti.create(this.top,t,e,i,s,r);n.contentDOM&&n.updateChildren(s,r+1),this.top.children.splice(this.index++,0,n),this.changed=!0}placeWidget(t,e,i){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 Si(this.top,t,e,i);this.top.children.splice(this.index++,0,s),this.changed=!0}else this.index++}addTextblockHacks(){let t=this.top.children[this.index-1],e=this.top;for(;t instanceof Oi;)e=t,t=e.children[e.children.length-1];(!t||!(t instanceof Ai)||/\n$/.test(t.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(t.node.text))&&((He||Ye)&&t&&"false"==t.dom.contentEditable&&this.addHackNode("IMG",e),this.addHackNode("BR",this.top))}addHackNode(t,e){if(e==this.top&&this.index<e.children.length&&e.children[this.index].matchesHack(t))this.index++;else{let i=document.createElement(t);"IMG"==t&&(i.className="ProseMirror-separator",i.alt=""),"BR"==t&&(i.className="ProseMirror-trailingBreak");let s=new Ri(this.top,[],i,null);e!=this.top?e.children.push(s):e.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 Wi(t,e){return t.type.side-e.type.side}function Ji(t,e,i,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>=i||f<=e?n.push(l):(u<e&&n.push(l.slice(0,e-u,s)),r&&(n.push(r),r=void 0),f>i&&n.push(l.slice(i-u,l.size,s)))}return n}function Li(t,e=null){let i=t.domSelectionRange(),s=t.state.doc;if(!i.focusNode)return null;let r=t.docView.nearestDesc(i.focusNode),n=r&&0==r.size,h=t.docView.posFromDOM(i.focusNode,i.focusOffset,1);if(h<0)return null;let o,l,u=s.resolve(h);if(Pe(i)){for(o=h;r&&!r.node;)r=r.parent;let t=r.node;if(r&&t.isAtom&&ue.isSelectable(t)&&r.parent&&(!t.isInline||!function(t,e,i){for(let s=0==e,r=e==$e(t);s||r;){if(t==i)return!0;let e=xe(t);if(!(t=t.parentNode))return!1;s=s&&0==e,r=r&&e==$e(t)}}(i.focusNode,i.focusOffset,r.dom))){let t=r.posBefore;l=new ue(h==t?u:s.resolve(t))}}else{if(i instanceof t.dom.ownerDocument.defaultView.Selection&&i.rangeCount>1){let e=h,r=h;for(let s=0;s<i.rangeCount;s++){let n=i.getRangeAt(s);e=Math.min(e,t.docView.posFromDOM(n.startContainer,n.startOffset,1)),r=Math.max(r,t.docView.posFromDOM(n.endContainer,n.endOffset,-1))}if(e<0)return null;[o,h]=r==t.state.selection.anchor?[r,e]:[e,r],u=s.resolve(h)}else o=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1);if(o<0)return null}let f=s.resolve(o);return l||(l=Zi(t,f,u,"pointer"==e||t.state.selection.head<u.pos&&!n?1:-1)),l}function Xi(t){return t.editable?t.hasFocus():ts(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function Yi(t,e=!1){let i=t.state.selection;if(Gi(t,i),Xi(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Ye){let e=t.domSelectionRange(),i=t.domObserver.currentSelection;if(e.anchorNode&&i.anchorNode&&Ae(e.anchorNode,e.anchorOffset,i.anchorNode,i.anchorOffset))return t.input.mouseDown.delayedSelectionSync=!0,void t.domObserver.setCurSelection()}if(t.domObserver.disconnectSelection(),t.cursorWrapper)!function(t){let e=t.domSelection();if(!e)return;let i=t.cursorWrapper.dom,s="IMG"==i.nodeName;s?e.collapse(i.parentNode,xe(i)+1):e.collapse(i,0),!s&&!t.state.selection.visible&&We&&Je<=11&&(i.disabled=!0,i.disabled=!1)}(t);else{let s,r,{anchor:n,head:h}=i;!Ui||i instanceof oe||(i.$from.parent.inlineContent||(s=Hi(t,i.from)),i.empty||i.$from.parent.inlineContent||(r=Hi(t,i.to))),t.docView.setSelection(n,h,t,e),Ui&&(s&&qi(s),r&&qi(r)),i.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let i=t.domSelectionRange(),s=i.anchorNode,r=i.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{i.anchorNode==s&&i.anchorOffset==r||(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout((()=>{Xi(t)&&!t.state.selection.visible||t.dom.classList.remove("ProseMirror-hideselection")}),20))})}(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}const Ui=He||Ye&&Ue<63;function Hi(t,e){let{node:i,offset:s}=t.docView.domFromPos(e,0),r=s<i.childNodes.length?i.childNodes[s]:null,n=s?i.childNodes[s-1]:null;if(He&&r&&"false"==r.contentEditable)return Ki(r);if(!(r&&"false"!=r.contentEditable||n&&"false"!=n.contentEditable)){if(r)return Ki(r);if(n)return Ki(n)}}function Ki(t){return t.contentEditable="true",He&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function qi(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function Gi(t,e){if(e instanceof ue){let i=t.docView.descAt(e.from);i!=t.lastSelectedViewDesc&&(Vi(t),i&&i.selectNode(),t.lastSelectedViewDesc=i)}else Vi(t)}function Vi(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Zi(t,e,i,s){return t.someProp("createSelectionBetween",(s=>s(t,e,i)))||oe.between(e,i,s)}function Qi(t){return!(t.editable&&!t.hasFocus())&&ts(t)}function ts(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(3==e.anchorNode.nodeType?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(3==e.focusNode.nodeType?e.focusNode.parentNode:e.focusNode))}catch(t){return!1}}function es(t,e){let{$anchor:i,$head:s}=t.selection,r=e>0?i.max(s):i.min(s),n=r.parent.inlineContent?r.depth?t.doc.resolve(e>0?r.after():r.before()):null:r;return n&&se.findFrom(n,e)}function is(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function ss(t,e,i){let s=t.state.selection;if(!(s instanceof oe)){if(s instanceof ue&&s.node.isInline)return is(t,new oe(e>0?s.$to:s.$from));{let i=es(t.state,e);return!!i&&is(t,i)}}if(i.indexOf("s")>-1){let{$head:i}=s,r=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let n=t.state.doc.resolve(i.pos+r.nodeSize*(e<0?-1:1));return is(t,new oe(s.$anchor,n))}if(!s.empty)return!1;if(t.endOfTextblock(e>0?"forward":"backward")){let i=es(t.state,e);return!!(i&&i instanceof ue)&&is(t,i)}if(!(qe&&i.indexOf("m")>-1)){let i,r=s.$head,n=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!n||n.isText)return!1;let h=e<0?r.pos-n.nodeSize:r.pos;return!!(n.isAtom||(i=t.docView.descAt(h))&&!i.contentDOM)&&(ue.isSelectable(n)?is(t,new ue(e<0?t.state.doc.resolve(r.pos-n.nodeSize):r)):!!Ze&&is(t,new oe(t.state.doc.resolve(e<0?h:h+n.nodeSize))))}}function rs(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function ns(t,e){let i=t.pmViewDesc;return i&&0==i.size&&(e<0||t.nextSibling||"BR"!=t.nodeName)}function hs(t,e){return e<0?function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,h=!1;for(Le&&1==i.nodeType&&s<rs(i)&&ns(i.childNodes[s],-1)&&(h=!0);;)if(s>0){if(1!=i.nodeType)break;{let t=i.childNodes[s-1];if(ns(t,-1))r=i,n=--s;else{if(3!=t.nodeType)break;i=t,s=i.nodeValue.length}}}else{if(ls(i))break;{let e=i.previousSibling;for(;e&&ns(e,-1);)r=i.parentNode,n=xe(e),e=e.previousSibling;if(e)i=e,s=rs(i);else{if(i=i.parentNode,i==t.dom)break;s=0}}}h?us(t,i,s):r&&us(t,r,n)}(t):function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,h=rs(i);for(;;)if(s<h){if(1!=i.nodeType)break;if(!ns(i.childNodes[s],1))break;r=i,n=++s}else{if(ls(i))break;{let e=i.nextSibling;for(;e&&ns(e,1);)r=e.parentNode,n=xe(e)+1,e=e.nextSibling;if(e)i=e,s=0,h=rs(i);else{if(i=i.parentNode,i==t.dom)break;s=h=0}}}r&&us(t,r,n)}(t)}function ls(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function us(t,e,i){if(3!=e.nodeType){let t,s;(s=function(t,e){for(;t&&e==t.childNodes.length&&!Ce(t);)e=xe(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let i=t.childNodes[e];if(3==i.nodeType)return i;if(1==i.nodeType&&"false"==i.contentEditable)break;t=i,e=0}}(e,i))?(e=s,i=0):(t=function(t,e){for(;t&&!e&&!Ce(t);)e=xe(t),t=t.parentNode;for(;t&&e;){let i=t.childNodes[e-1];if(3==i.nodeType)return i;if(1==i.nodeType&&"false"==i.contentEditable)break;e=(t=i).childNodes.length}}(e,i))&&(e=t,i=t.nodeValue.length)}let s=t.domSelection();if(!s)return;if(Pe(s)){let t=document.createRange();t.setEnd(e,i),t.setStart(e,i),s.removeAllRanges(),s.addRange(t)}else s.extend&&s.extend(e,i);t.domObserver.setCurSelection();let{state:r}=t;setTimeout((()=>{t.state==r&&Yi(t)}),50)}function fs(t,e){let i=t.state.doc.resolve(e);if(!Ye&&!Ge&&i.parent.inlineContent){let s=t.coordsAtPos(e);if(e>i.start()){let i=t.coordsAtPos(e-1),r=(i.top+i.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(i.left-s.left)>1)return i.left<s.left?"ltr":"rtl"}if(e<i.end()){let i=t.coordsAtPos(e+1),r=(i.top+i.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(i.left-s.left)>1)return i.left>s.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(t.dom).direction?"rtl":"ltr"}function as(t,e,i){let s=t.state.selection;if(s instanceof oe&&!s.empty||i.indexOf("s")>-1)return!1;if(qe&&i.indexOf("m")>-1)return!1;let{$from:r,$to:n}=s;if(!r.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=es(t.state,e);if(i&&i instanceof ue)return is(t,i)}if(!r.parent.inlineContent){let i=e<0?r:n,h=s instanceof ae?se.near(i,e):se.findFrom(i,e);return!!h&&is(t,h)}return!1}function cs(t,e){if(!(t.state.selection instanceof oe))return!0;let{$head:i,$anchor:s,empty:r}=t.state.selection;if(!i.sameParent(s))return!0;if(!r)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let n=!i.textOffset&&(e<0?i.nodeBefore:i.nodeAfter);if(n&&!n.isText){let s=t.state.tr;return e<0?s.delete(i.pos-n.nodeSize,i.pos):s.delete(i.pos,i.pos+n.nodeSize),t.dispatch(s),!0}return!1}function ds(t,e,i){t.domObserver.stop(),e.contentEditable=i,t.domObserver.start()}function ps(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:s,openStart:r,openEnd:n}=e;for(;r>1&&n>1&&1==s.childCount&&1==s.firstChild.childCount;){r--,n--;let t=s.firstChild;i.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 e=o.createElement(u[t]);for(;l.firstChild;)e.appendChild(l.firstChild);l.appendChild(e),a++}f=l.firstChild}return f&&1==f.nodeType&&f.setAttribute("data-pm-slice",`${r} ${n}${a?` -${a}`:""} ${JSON.stringify(i)}`),{dom:l,text:t.someProp("clipboardTextSerializer",(i=>i(e,t)))||e.content.textBetween(0,e.content.size,"\n\n"),slice:e}}function ms(t,e,i,s,r){let n,h,o=r.parent.type.spec.code;if(!i&&!e)return null;let l=!!e&&(s||o||!i);if(l){if(t.someProp("transformPastedText",(i=>{e=i(e,o||s,t)})),o)return h=new b(d.from(t.state.schema.text(e.replace(/\r\n?/g,"\n"))),0,0),t.someProp("transformPasted",(e=>{h=e(h,t,!0)})),h;let i=t.someProp("clipboardTextParser",(i=>i(e,r,s,t)));if(i)h=i;else{let i=r.marks(),{schema:s}=t.state,h=pt.fromSchema(s);n=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=n.appendChild(document.createElement("p"));t&&e.appendChild(h.serializeNode(s.text(t,i)))}))}}else t.someProp("transformPastedHTML",(e=>{i=e(i,t)})),n=function(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let i,s=xs().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t);if((i=r&&ks[r[1].toLowerCase()])&&(t=i.map((t=>"<"+t+">")).join("")+t+i.map((t=>"</"+t+">")).reverse().join("")),s.innerHTML=function(t){let e=window.trustedTypes;return e?(Os||(Os=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Os.createHTML(t)):t}(t),i)for(let t=0;t<i.length;t++)s=s.querySelector(i[t])||s;return s}(i),Ze&&function(t){let e=t.querySelectorAll(Ye?"span:not([class]):not([style])":"span.Apple-converted-space");for(let i=0;i<e.length;i++){let s=e[i];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 e=t.someProp("clipboardParser")||t.someProp("domParser")||rt.fromSchema(t.state.schema);h=e.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,e){if(!t.size)return t;let i,s=t.content.firstChild.type.schema;try{i=JSON.parse(e)}catch(e){return t}let{content:r,openStart:n,openEnd:h}=t;for(let t=i.length-2;t>=0;t-=2){let e=s.nodes[i[t]];if(!e||e.hasRequiredAttrs())break;r=d.from(e.create(i[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,e){if(t.childCount<2)return t;for(let i=e.depth;i>=0;i--){let s,r=e.node(i).contentMatchAt(e.index(i)),n=[];if(t.forEach((t=>{if(!n)return;let e,i=r.findWrapping(t.type);if(!i)return n=null;if(e=n.length&&s.length&&ys(i,s,t,n[n.length-1],0))n[n.length-1]=e;else{n.length&&(n[n.length-1]=bs(n[n.length-1],s.length));let e=gs(t,i);n.push(e),r=r.matchType(e.type),s=i}})),n)return d.from(n)}return t}(h.content,r),!0),h.openStart||h.openEnd){let t=0,e=0;for(let e=h.content.firstChild;t<h.openStart&&!e.type.spec.isolating;t++,e=e.firstChild);for(let t=h.content.lastChild;e<h.openEnd&&!t.type.spec.isolating;e++,t=t.lastChild);h=vs(h,t,e)}return t.someProp("transformPasted",(e=>{h=e(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,e,i=0){for(let s=e.length-1;s>=i;s--)t=e[s].create(null,d.from(t));return t}function ys(t,e,i,s,r){if(r<t.length&&r<e.length&&t[r]==e[r]){let n=ys(t,e,i,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?i.type:t[r+1]))return s.copy(s.content.append(d.from(gs(i,t,r+1))))}}function bs(t,e){if(0==e)return t;let i=t.content.replaceChild(t.childCount-1,bs(t.lastChild,e-1)),s=t.contentMatchAt(t.childCount).fillBefore(d.empty,!0);return t.copy(i.append(s))}function Ms(t,e,i,s,r,n){let h=e<0?t.firstChild:t.lastChild,o=h.content;return t.childCount>1&&(n=0),r<s-1&&(o=Ms(o,e,i,s,r+1,n)),r>=i&&(o=e<0?h.contentMatchAt(0).fillBefore(o,n<=r).append(o):o.append(h.contentMatchAt(h.childCount).fillBefore(d.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,h.copy(o))}function vs(t,e,i){return e<t.openStart&&(t=new b(Ms(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),i<t.openEnd&&(t=new b(Ms(t.content,1,i,t.openEnd,0,0),t.openStart,i)),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,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function $s(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)t.input.eventHandlers[i]||t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>Cs(t,e))}))}function Cs(t,e){return t.someProp("handleDOMEvents",(i=>{let s=i[e.type];return!!s&&(s(t,e)||e.defaultPrevented)}))}function Ps(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i=e.target;i!=t.dom;i=i.parentNode)if(!i||11==i.nodeType||i.pmViewDesc&&i.pmViewDesc.stopEvent(e))return!1;return!0}function Ns(t){return{left:t.clientX,top:t.clientY}}function Is(t,e,i,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(e,(e=>s>n.depth?e(t,i,n.nodeAfter,n.before(s),r,!0):e(t,i,n.node(s),n.before(s),r,!1))))return!0;return!1}function zs(t,e){if(t.focused||t.focus(),t.state.selection.eq(e))return;let i=t.state.tr.setSelection(e);i.setMeta("pointer",!0),t.dispatch(i)}function _s(t,e,i,s){return Is(t,"handleDoubleClickOn",e,i,s)||t.someProp("handleDoubleClick",(i=>i(t,e,s)))}function js(t,e,i,s){return Is(t,"handleTripleClickOn",e,i,s)||t.someProp("handleTripleClick",(i=>i(t,e,s)))||function(t,e,i){if(0!=i.button)return!1;let s=t.state.doc;if(-1==e)return!!s.inlineContent&&(zs(t,oe.create(s,0,s.content.size)),!0);let r=s.resolve(e);for(let e=r.depth+1;e>0;e--){let i=e>r.depth?r.nodeAfter:r.node(e),n=r.before(e);if(i.inlineContent)zs(t,oe.create(s,n+1,n+1+i.content.size));else{if(!ue.isSelectable(i))continue;zs(t,ue.create(s,n))}return!0}}(t,i,s)}function Fs(t){return Us(t)}Ds.keydown=(t,e)=>{let i=e;if(t.input.shiftKey=16==i.keyCode||i.shiftKey,!Js(t,i)&&(t.input.lastKeyCode=i.keyCode,t.input.lastKeyCodeTime=Date.now(),!Ve||!Ye||13!=i.keyCode))if(229!=i.keyCode&&t.domObserver.forceFlush(),!Ke||13!=i.keyCode||i.ctrlKey||i.altKey||i.metaKey)t.someProp("handleKeyDown",(e=>e(t,i)))||function(t,e){let i=e.keyCode,s=function(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}(e);if(8==i||qe&&72==i&&"c"==s)return cs(t,-1)||hs(t,-1);if(46==i&&!e.shiftKey||qe&&68==i&&"c"==s)return cs(t,1)||hs(t,1);if(13==i||27==i)return!0;if(37==i||qe&&66==i&&"c"==s){let e=37==i?"ltr"==fs(t,t.state.selection.from)?-1:1:-1;return ss(t,e,s)||hs(t,e)}if(39==i||qe&&70==i&&"c"==s){let e=39==i?"ltr"==fs(t,t.state.selection.from)?1:-1:1;return ss(t,e,s)||hs(t,e)}return 38==i||qe&&80==i&&"c"==s?as(t,-1,s)||hs(t,-1):40==i||qe&&78==i&&"c"==s?function(t){if(!He||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(e&&1==e.nodeType&&0==i&&e.firstChild&&"false"==e.firstChild.contentEditable){let i=e.firstChild;ds(t,i,"true"),setTimeout((()=>ds(t,i,"false")),20)}return!1}(t)||as(t,1,s)||hs(t,1):s==(qe?"m":"c")&&(66==i||73==i||89==i||90==i)}(t,i)?i.preventDefault():Es(t,"key");else{let e=Date.now();t.input.lastIOSEnter=e,t.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{t.input.lastIOSEnter==e&&(t.someProp("handleKeyDown",(e=>e(t,Ne(13,"Enter")))),t.input.lastIOSEnter=0)}),200)}},Ds.keyup=(t,e)=>{16==e.keyCode&&(t.input.shiftKey=!1)},Ds.keypress=(t,e)=>{let i=e;if(Js(t,i)||!i.charCode||i.ctrlKey&&!i.altKey||qe&&i.metaKey)return;if(t.someProp("handleKeyPress",(e=>e(t,i))))return void i.preventDefault();let s=t.state.selection;if(!(s instanceof oe&&s.$from.sameParent(s.$to))){let e=String.fromCharCode(i.charCode),r=()=>t.state.tr.insertText(e).scrollIntoView();/[\r\n]/.test(e)||t.someProp("handleTextInput",(i=>i(t,s.$from.pos,s.$to.pos,e,r)))||t.dispatch(r()),i.preventDefault()}};const Bs=qe?"metaKey":"ctrlKey";Ts.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let s=Fs(t),r=Date.now(),n="singleClick";r-t.input.lastClick.time<500&&function(t,e){let i=e.x-t.clientX,s=e.y-t.clientY;return i*i+s*s<100}(i,t.input.lastClick)&&!i[Bs]&&t.input.lastClick.button==i.button&&("singleClick"==t.input.lastClick.type?n="doubleClick":"doubleClick"==t.input.lastClick.type&&(n="tripleClick")),t.input.lastClick={time:r,x:i.clientX,y:i.clientY,type:n,button:i.button};let h=t.posAtCoords(Ns(i));h&&("singleClick"==n?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Ws(t,h,i,!!s)):("doubleClick"==n?_s:js)(t,h.pos,h.inside,i)?i.preventDefault():Es(t,"pointer"))};class Ws{constructor(t,e,i,s){let r,n;if(this.view=t,this.pos=e,this.event=i,this.flushed=s,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!i[Bs],this.allowDefault=i.shiftKey,e.inside>-1)r=t.state.doc.nodeAt(e.inside),n=e.inside;else{let i=t.state.doc.resolve(e.pos);r=i.parent,n=i.depth?i.before():0}const h=s?null:i.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==i.button&&(r.type.spec.draggable&&!1!==r.type.spec.selectable||l instanceof ue&&l.from<=n&&l.to>n)&&(this.mightDrag={node:r,pos:n,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!Le||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((()=>Yi(this.view))),this.view.input.mouseDown=null}up(t){if(this.done(),!this.view.dom.contains(t.target))return;let e=this.pos;this.view.state.doc!=this.startDoc&&(e=this.view.posAtCoords(Ns(t))),this.updateAllowDefault(t),this.allowDefault||!e?Es(this.view,"pointer"):function(t,e,i,s,r){return Is(t,"handleClickOn",e,i,s)||t.someProp("handleClick",(i=>i(t,e,s)))||(r?function(t,e){if(-1==e)return!1;let i,s,r=t.state.selection;r instanceof ue&&(i=r.node);let n=t.state.doc.resolve(e);for(let t=n.depth+1;t>0;t--){let e=t>n.depth?n.nodeAfter:n.node(t);if(ue.isSelectable(e)){s=i&&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,ue.create(t.state.doc,s)),!0)}(t,i):function(t,e){if(-1==e)return!1;let i=t.state.doc.resolve(e),s=i.nodeAfter;return!!(s&&s.isAtom&&ue.isSelectable(s))&&(zs(t,new ue(i)),!0)}(t,i))}(this.view,e.pos,e.inside,t,this.selectNode)?t.preventDefault():0==t.button&&(this.flushed||He&&this.mightDrag&&!this.mightDrag.node.isAtom||Ye&&!this.view.state.selection.visible&&Math.min(Math.abs(e.pos-this.view.state.selection.from),Math.abs(e.pos-this.view.state.selection.to))<=2)?(zs(this.view,se.near(this.view.state.doc.resolve(e.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,e){return!!t.composing||!!(He&&Math.abs(e.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=Ve?5e3:-1;function Xs(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout((()=>Us(t)),e))}function Ys(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,e=!1){if(!(Ve&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Ys(t),e||t.docView&&t.docView.dirty){let i=Li(t),s=t.state.selection;return i&&!i.eq(s)?t.dispatch(t.state.tr.setSelection(i)):!t.markCursor&&!e||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:e}=t,i=e.selection.$to;if(e.selection instanceof oe&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))||Ye&&Ge&&function(t){let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(!e||1!=e.nodeType||i>=e.childNodes.length)return!1;let s=e.childNodes[i];return 1==s.nodeType&&"false"==s.contentEditable}(t)))t.markCursor=t.state.storedMarks||i.marks(),Us(t,!0),t.markCursor=null;else if(Us(t,!e.selection.empty),Le&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,s=e.focusOffset;i&&1==i.nodeType&&0!=s;){let e=s<0?i.lastChild:i.childNodes[s-1];if(!e)break;if(3==e.nodeType){let i=t.domSelection();i&&i.collapse(e,e.nodeValue.length);break}i=e,s=-1}}t.input.composing=!0}Xs(t,Ls)},Ds.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.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++,Xs(t,20))};const Hs=We&&Je<15||Ke&&Qe<604;function Ks(t,e,i,s,r){let n=ms(t,e,i,s,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(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 e=t.getData("text/plain")||t.getData("Text");if(e)return e;let i=t.getData("text/uri-list");return i?i.replace(/\r?\n/g," "):""}Ts.copy=Ds.cut=(t,e)=>{let i=e,s=t.state.selection,r="cut"==i.type;if(s.empty)return;let n=Hs?null:i.clipboardData,h=s.content(),{dom:o,text:l}=ps(t,h);n?(i.preventDefault(),n.clearData(),n.setData("text/html",o.innerHTML),n.setData("text/plain",l)):function(t,e){if(!t.dom.parentNode)return;let i=t.dom.parentNode.appendChild(document.createElement("div"));i.appendChild(e),i.style.cssText="position: fixed; left: -10000px; top: 10px";let s=getSelection(),r=document.createRange();r.selectNodeContents(e),t.dom.blur(),s.removeAllRanges(),s.addRange(r),setTimeout((()=>{i.parentNode&&i.parentNode.removeChild(i),t.focus()}),50)}(t,o),r&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},Ds.paste=(t,e)=>{let i=e;if(t.composing&&!Ve)return;let s=Hs?null:i.clipboardData,r=t.input.shiftKey&&45!=t.input.lastKeyCode;s&&Ks(t,qs(s),s.getData("text/html"),r,i)?i.preventDefault():function(t,e){if(!t.dom.parentNode)return;let i=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,s=t.dom.parentNode.appendChild(document.createElement(i?"textarea":"div"));i||(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),i?Ks(t,s.value,null,r,e):Ks(t,s.textContent,s.innerHTML,r,e)}),50)}(t,i)};class Gs{constructor(t,e,i){this.slice=t,this.move=e,this.node=i}}const Vs=qe?"altKey":"ctrlKey";function Zs(t,e){let i;return t.someProp("dragCopies",(t=>{i=i||t(e)})),null!=i?!i:!e[Vs]}Ts.dragstart=(t,e)=>{let i=e,s=t.input.mouseDown;if(s&&s.done(),!i.dataTransfer)return;let r,n=t.state.selection,h=n.empty?null:t.posAtCoords(Ns(i));if(h&&h.pos>=n.from&&h.pos<=(n instanceof ue?n.to-1:n.to));else if(s&&s.mightDrag)r=ue.create(t.state.doc,s.mightDrag.pos);else if(i.target&&1==i.target.nodeType){let e=t.docView.nearestDesc(i.target,!0);e&&e.node.type.spec.draggable&&e!=t.docView&&(r=ue.create(t.state.doc,e.posBefore))}let o=(r||t.state.selection).content(),{dom:l,text:u,slice:f}=ps(t,o);(!i.dataTransfer.files.length||!Ye||Ue>120)&&i.dataTransfer.clearData(),i.dataTransfer.setData(Hs?"Text":"text/html",l.innerHTML),i.dataTransfer.effectAllowed="copyMove",Hs||i.dataTransfer.setData("text/plain",u),t.dragging=new Gs(f,Zs(t,i),r)},Ts.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{t.dragging==e&&(t.dragging=null)}),50)},Ds.dragover=Ds.dragenter=(t,e)=>e.preventDefault(),Ds.drop=(t,e)=>{try{!function(t,e,i){if(!e.dataTransfer)return;let s=t.posAtCoords(Ns(e));if(!s)return;let r=t.state.doc.resolve(s.pos),n=i&&i.slice;n?t.someProp("transformPasted",(e=>{n=e(n,t,!1)})):n=ms(t,qs(e.dataTransfer),Hs?null:e.dataTransfer.getData("text/html"),!1,r);let h=!(!i||!Zs(t,e));if(t.someProp("handleDrop",(i=>i(t,e,n||b.empty,h))))return void e.preventDefault();if(!n)return;e.preventDefault();let o=n?function(t,e,i){let s=t.resolve(e);if(!i.content.size)return e;let r=i.content;for(let t=0;t<i.openStart;t++)r=r.firstChild.content;for(let t=1;t<=(0==i.openStart&&i.size?2:1);t++)for(let e=s.depth;e>=0;e--){let i=e==s.depth?0:s.pos<=(s.start(e+1)+s.end(e+1))/2?-1:1,n=s.index(e)+(i>0?1:0),h=s.node(e),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==i?s.pos:i<0?s.before(e+1):s.after(e+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}=i;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&&ue.isSelectable(n.content.firstChild)&&c.nodeAfter&&c.nodeAfter.sameMarkup(n.content.firstChild))l.setSelection(new ue(c));else{let e=l.mapping.map(o);l.mapping.maps[l.mapping.maps.length-1].forEach(((t,i,s,r)=>e=r)),l.setSelection(Zi(t,c,l.doc.resolve(e)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}(t,e,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())&&Yi(t)}),20))},Ts.blur=(t,e)=>{let i=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),i.relatedTarget&&t.dom.contains(i.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)},Ts.beforeinput=(t,e)=>{if(Ye&&Ve&&"deleteContentBackward"==e.inputType){t.domObserver.flushSoon();let{domChangeCount:e}=t.input;setTimeout((()=>{if(t.input.domChangeCount!=e)return;if(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",(e=>e(t,Ne(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())}),50)}};for(let t in Ds)Ts[t]=Ds[t];function Qs(t,e){if(t==e)return!0;for(let i in t)if(t[i]!==e[i])return!1;for(let i in e)if(!(i in t))return!1;return!0}class tr{constructor(t,e){this.toDOM=t,this.spec=e||nr,this.side=this.spec.side||0}map(t,e,i,s){let{pos:r,deleted:n}=t.mapResult(e.from+s,this.side<0?-1:1);return n?null:new sr(r-i,r-i,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 er{constructor(t,e){this.attrs=t,this.spec=e||nr}map(t,e,i,s){let r=t.map(e.from+s,this.spec.inclusiveStart?-1:1)-i,n=t.map(e.to+s,this.spec.inclusiveEnd?1:-1)-i;return r>=n?null:new sr(r,n,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof er&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}static is(t){return t.type instanceof er}destroy(){}}class ir{constructor(t,e){this.attrs=t,this.spec=e||nr}map(t,e,i,s){let r=t.mapResult(e.from+s,1);if(r.deleted)return null;let n=t.mapResult(e.to+s,-1);return n.deleted||n.pos<=r.pos?null:new sr(r.pos-i,n.pos-i,this)}valid(t,e){let i,{index:s,offset:r}=t.content.findIndex(e.from);return r==e.from&&!(i=t.child(s)).isText&&r+i.nodeSize==e.to}eq(t){return this==t||t instanceof ir&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}destroy(){}}class sr{constructor(t,e,i){this.from=t,this.to=e,this.type=i}copy(t,e){return new sr(t,e,this.type)}eq(t,e=0){return this.type.eq(t.type)&&this.from+e==t.from&&this.to+e==t.to}map(t,e,i){return this.type.map(t,this,e,i)}static widget(t,e,i){return new sr(t,t,new tr(e,i))}static inline(t,e,i,s){return new sr(t,e,new er(i,s))}static node(t,e,i,s){return new sr(t,e,new ir(i,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof er}get widget(){return this.type instanceof tr}}const rr=[],nr={};class hr{constructor(t,e){this.local=t.length?t:rr,this.children=e.length?e:rr}static create(t,e){return e.length?cr(e,t,0,nr):or}find(t,e,i){let s=[];return this.findInner(null==t?0:t,null==e?1e9:e,s,0,i),s}findInner(t,e,i,s,r){for(let n=0;n<this.local.length;n++){let h=this.local[n];h.from<=e&&h.to>=t&&(!r||r(h.spec))&&i.push(h.copy(h.from+s,h.to+s))}for(let n=0;n<this.children.length;n+=3)if(this.children[n]<e&&this.children[n+1]>t){let h=this.children[n]+1;this.children[n+2].findInner(t-h,e-h,i,s+h,r)}}map(t,e,i){return this==or||0==t.maps.length?this:this.mapInner(t,e,0,0,i||nr)}mapInner(t,e,i,s,r){let n;for(let h=0;h<this.local.length;h++){let o=this.local[h].map(t,i,s);o&&o.type.valid(e,o)?(n||(n=[])).push(o):r.onRemove&&r.onRemove(this.local[h].spec)}return this.children.length?function(t,e,i,s,r,n,h){let o=t.slice();for(let t=0,e=n;t<i.maps.length;t++){let s=0;i.maps[t].forEach(((t,i,r,n)=>{let h=n-r-(i-t);for(let r=0;r<o.length;r+=3){let n=o[r+1];if(n<0||t>n+e-s)continue;let l=o[r]+e-s;i>=l?o[r+1]=t<=l?-2:-1:t>=e&&h&&(o[r]+=h,o[r+1]+=h)}s+=h})),e=i.maps[t].map(e,-1)}let l=!1;for(let e=0;e<o.length;e+=3)if(o[e+1]<0){if(-2==o[e+1]){l=!0,o[e+1]=-1;continue}let u=i.map(t[e]+n),f=u-r;if(f<0||f>=s.content.size){l=!0;continue}let a=i.map(t[e+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[e+2].mapInner(i,p,u+1,t[e]+n+1,h);s!=or?(o[e]=f,o[e+1]=a,o[e+2]=s):(o[e+1]=-2,l=!0)}else l=!0}if(l){let l=function(t,e,i,s,r,n,h){function o(t,e){for(let n=0;n<t.local.length;n++){let o=t.local[n].map(s,r,e);o?i.push(o):h.onRemove&&h.onRemove(t.local[n].spec)}for(let i=0;i<t.children.length;i+=3)o(t.children[i+2],t.children[i]+e+1)}for(let i=0;i<t.length;i+=3)-1==t[i+1]&&o(t[i+2],e[i]+n+1);return i}(o,t,e,i,r,n,h),u=cr(l,s,0,h);e=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,e=0;t<u.children.length;t+=3){let i=u.children[t];for(;e<o.length&&o[e]<i;)e+=3;o.splice(e,0,u.children[t],u.children[t+1],u.children[t+2])}}return new hr(e.sort(dr),o)}(this.children,n||[],t,e,i,s,r):n?new hr(n.sort(dr),rr):or}add(t,e){return e.length?this==or?hr.create(t,e):this.addInner(t,e,0):this}addInner(t,e,i){let s,r=0;t.forEach(((t,n)=>{let h,o=n+i;if(h=fr(e,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(e):e,-i);for(let e=0;e<n.length;e++)n[e].type.valid(t,n[e])||n.splice(e--,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,e){let i=this.children,s=this.local;for(let s=0;s<i.length;s+=3){let r,n=i[s]+e,h=i[s+1]+e;for(let e,i=0;i<t.length;i++)(e=t[i])&&e.from>n&&e.to<h&&(t[i]=null,(r||(r=[])).push(e));if(!r)continue;i==this.children&&(i=this.children.slice());let o=i[s+2].removeInner(r,n+1);o!=or?i[s+2]=o:(i.splice(s,3),s-=3)}if(s.length)for(let i,r=0;r<t.length;r++)if(i=t[r])for(let t=0;t<s.length;t++)s[t].eq(i,e)&&(s==this.local&&(s=this.local.slice()),s.splice(t--,1));return i==this.children&&s==this.local?this:s.length||i.length?new hr(s,i):or}forChild(t,e){if(this==or)return this;if(e.isLeaf)return hr.empty;let i,s;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(i=this.children[e+2]);break}let r=t+1,n=r+e.content.size;for(let t=0;t<this.local.length;t++){let e=this.local[t];if(e.from<n&&e.to>r&&e.type instanceof er){let t=Math.max(r,e.from)-r,i=Math.min(n,e.to)-r;t<i&&(s||(s=[])).push(e.copy(t,i))}}if(s){let t=new hr(s.sort(dr),rr);return i?new lr([t,i]):t}return i||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 e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(t){return pr(this.localsInner(t))}localsInner(t){if(this==or)return rr;if(t.inlineContent||!this.local.some(er.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++)this.local[t].type instanceof er||e.push(this.local[t]);return e}forEachSet(t){t(this)}}hr.empty=new hr([],[]),hr.removeOverlap=pr;const or=hr.empty;class lr{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,nr)));return lr.from(i)}forChild(t,e){if(e.isLeaf)return hr.empty;let i=[];for(let s=0;s<this.members.length;s++){let r=this.members[s].forChild(t,e);r!=or&&(r instanceof lr?i=i.concat(r.members):i.push(r))}return lr.from(i)}eq(t){if(!(t instanceof lr)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(t){let e,i=!0;for(let s=0;s<this.members.length;s++){let r=this.members[s].localsInner(t);if(r.length)if(e){i&&(e=e.slice(),i=!1);for(let t=0;t<r.length;t++)e.push(r[t])}else e=r}return e?pr(i?e:e.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,e)=>t.concat(e instanceof hr?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function ur(t,e){if(!e||!t.length)return t;let i=[];for(let s=0;s<t.length;s++){let r=t[s];i.push(new sr(r.from+e,r.to+e,r.type))}return i}function fr(t,e,i){if(e.isLeaf)return null;let s=i+e.nodeSize,r=null;for(let e,n=0;n<t.length;n++)(e=t[n])&&e.from>i&&e.to<s&&((r||(r=[])).push(e),t[n]=null);return r}function ar(t){let e=[];for(let i=0;i<t.length;i++)null!=t[i]&&e.push(t[i]);return e}function cr(t,e,i,s){let r=[],n=!1;e.forEach(((e,h)=>{let o=fr(t,e,h+i);if(o){n=!0;let t=cr(o,e,i+h+1,s);t!=or&&r.push(h,h+e.nodeSize,t)}}));let h=ur(n?ar(t):t,-i).sort(dr);for(let t=0;t<h.length;t++)h[t].type.valid(e,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,e){return t.from-e.from||t.to-e.to}function pr(t){let e=t;for(let i=0;i<e.length-1;i++){let s=e[i];if(s.from!=s.to)for(let r=i+1;r<e.length;r++){let n=e[r];if(n.from!=s.from){n.from<s.to&&(e==t&&(e=t.slice()),e[i]=s.copy(s.from,n.from),mr(e,r,s.copy(n.from,s.to)));break}n.to!=s.to&&(e==t&&(e=t.slice()),e[r]=n.copy(n.from,s.to),mr(e,r+1,n.copy(s.to,n.to)))}}return e}function mr(t,e,i){for(;e<t.length&&dr(i,t[e])>0;)e++;t.splice(e,0,i)}function wr(t){let e=[];return t.someProp("decorations",(i=>{let s=i(t.state);s&&s!=or&&e.push(s)})),t.cursorWrapper&&e.push(hr.create(t.state.doc,[t.cursorWrapper.deco])),lr.from(e)}const gr={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},yr=We&&Je<=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,e){this.view=t,this.handleDOMChange=e,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((e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);We&&Je<=11&&e.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():He&&t.composing&&e.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 e=0;e<t.length;e++)this.queue.push(t[e]);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(Qi(this.view)){if(this.suppressingSelectionUpdates)return Yi(this.view);if(We&&Je<=11&&!this.view.state.selection.empty){let t=this.view.domSelectionRange();if(t.focusNode&&Ae(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 e,i=new Set;for(let e=t.focusNode;e;e=Oe(e))i.add(e);for(let s=t.anchorNode;s;s=Oe(s))if(i.has(s)){e=s;break}let s=e&&this.view.docView.nearestDesc(e);return s&&s.ignoreMutation({type:"selection",target:3==e.nodeType?e.parentNode:e})?(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 e=this.pendingRecords();e.length&&(this.queue=[]);let i=t.domSelectionRange(),s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&Qi(t)&&!this.ignoreSelectionChange(i),r=-1,n=-1,h=!1,o=[];if(t.editable)for(let t=0;t<e.length;t++){let i=this.registerMutation(e[t],o);i&&(r=r<0?i.from:Math.min(i.from,r),n=n<0?i.to:Math.max(i.to,n),i.typeOver&&(h=!0))}if(!o.some((t=>"BR"==t.nodeName))||8!=t.input.lastKeyCode&&46!=t.input.lastKeyCode){if(Le&&o.length){let e=o.filter((t=>"BR"==t.nodeName));if(2==e.length){let[t,i]=e;t.parentNode&&t.parentNode.parentNode==i.parentNode?i.remove():t.remove()}else{let{focusNode:i}=this.currentSelection;for(let s of e){let e=s.parentNode;!e||"LI"!=e.nodeName||i&&xr(t,i)==e||s.remove()}}}}else for(let t of o)if("BR"==t.nodeName&&t.parentNode){let e=t.nextSibling;for(;e&&1==e.nodeType;){if("false"==e.contentEditable){t.parentNode.removeChild(t);break}e=e.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&&Pe(i)&&(l=Li(t))&&l.eq(se.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,Yi(t),this.currentSelection.set(i),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=Le,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,e){var i;let{focusNode:s,focusOffset:r}=t.domSelectionRange();for(let n of e)if("TR"==(null===(i=n.parentNode)||void 0===i?void 0:i.nodeName)){let e=n.nextSibling;for(;e&&"TD"!=e.nodeName&&"TH"!=e.nodeName;)e=e.nextSibling;if(e){let i=e;for(;;){let t=i.firstChild;if(!t||1!=t.nodeType||"false"==t.contentEditable||/^(BR|IMG)$/.test(t.nodeName))break;i=t}i.insertBefore(n,i.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(i)||Yi(t),this.currentSelection.set(i))}registerMutation(t,e){if(e.indexOf(t.target)>-1)return null;let i=this.view.docView.nearestDesc(t.target);if("attributes"==t.type&&(i==this.view.docView||"contenteditable"==t.attributeName||"style"==t.attributeName&&!t.oldValue&&!t.target.getAttribute("style")))return null;if(!i||i.ignoreMutation(t))return null;if("childList"==t.type){for(let i=0;i<t.addedNodes.length;i++){let s=t.addedNodes[i];e.push(s),3==s.nodeType&&(this.lastChangedTextNode=s)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let s=t.previousSibling,r=t.nextSibling;if(We&&Je<=11&&t.addedNodes.length)for(let e=0;e<t.addedNodes.length;e++){let{previousSibling:i,nextSibling:n}=t.addedNodes[e];(!i||Array.prototype.indexOf.call(t.addedNodes,i)<0)&&(s=i),(!n||Array.prototype.indexOf.call(t.addedNodes,n)<0)&&(r=n)}let n=s&&s.parentNode==t.target?xe(s)+1:0,h=i.localPosFromDOM(t.target,n,-1),o=r&&r.parentNode==t.target?xe(r):t.target.childNodes.length;return{from:h,to:i.localPosFromDOM(t.target,o,1)}}return"attributes"==t.type?{from:i.posAtStart-i.border,to:i.posAtEnd+i.border}:(this.lastChangedTextNode=t.target,{from:i.posAtStart,to:i.posAtEnd,typeOver:t.target.nodeValue==t.oldValue})}}let vr=new WeakMap,kr=!1;function Sr(t,e){let i=e.startContainer,s=e.startOffset,r=e.endContainer,n=e.endOffset,h=t.domAtPos(t.state.selection.anchor);return Ae(h.node,h.offset,r,n)&&([i,s,r,n]=[r,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}}function xr(t,e){for(let i=e.parentNode;i&&i!=t.dom;i=i.parentNode){let e=t.docView.nearestDesc(i,!0);if(e&&e.node.isBlock)return i}return null}function Or(t){let e=t.pmViewDesc;if(e)return e.parseRule();if("BR"==t.nodeName&&t.parentNode){if(He&&/^(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||He&&/^(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,e,i){return Math.max(i.anchor,i.head)>e.content.size?null:Zi(t,e.resolve(i.anchor),e.resolve(i.head))}function Ar(t,e,i){let s=t.depth,r=e?t.end():t.pos;for(;s>0&&(e||t.indexAfter(s)==t.node(s).childCount);)s--,r++,e=!1;if(i){let e=t.node(s).maybeChild(t.indexAfter(s));for(;e&&!e.isLeaf;)e=e.firstChild,r++}return r}function Rr(t){if(2!=t.length)return!1;let e=t.charCodeAt(0),i=t.charCodeAt(1);return e>=56320&&e<=57343&&i>=55296&&i<=56319}class Er{constructor(t,e){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=e,this.state=e.state,this.directPlugins=e.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=Di(this.state.doc,$r(this),wr(this),this.dom,this),this.domObserver=new Mr(this,((t,e,i,s)=>function(t,e,i,s,r){let n=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let e=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,i=Li(t,e);if(i&&!t.state.selection.eq(i)){if(Ye&&Ve&&13===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,Ne(13,"Enter")))))return;let s=t.state.tr.setSelection(i);"pointer"==e?s.setMeta("pointer",!0):"key"==e&&s.scrollIntoView(),n&&s.setMeta("composition",n),t.dispatch(s)}return}let h=t.state.doc.resolve(e),o=h.sharedDepth(i);e=h.before(o+1),i=t.state.doc.resolve(i).after(o+1);let l,u,f=t.state.selection,a=function(t,e,i){let s,{node:r,fromOffset:n,toOffset:h,from:o,to:l}=t.docView.parseRange(e,i),u=t.domSelectionRange(),f=u.anchorNode;if(f&&t.dom.contains(1==f.nodeType?f:f.parentNode)&&(s=[{node:f,offset:u.anchorOffset}],Pe(u)||s.push({node:u.focusNode,offset:u.focusOffset})),Ye&&8===t.input.lastKeyCode)for(let t=h;t>n;t--){let e=r.childNodes[t-1],i=e.pmViewDesc;if("BR"==e.nodeName&&!i){h=t;break}if(!i||i.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,e=s[1]&&s[1].pos;null==e&&(e=t),p={anchor:t+o,head:e+o}}return{doc:m,sel:p,from:o,to:l}}(t,e,i),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,e,i,s,r){let n=t.findDiffStart(e,i);if(null==n)return null;let{a:h,b:o}=t.findDiffEnd(e,i+t.size,i+e.size);if("end"==r&&(s-=h+Math.max(0,n-Math.min(h,o))-n),h<n&&t.size<e.size){let t=s<=n&&s>=h?n-s:0;n-=t,n&&n<e.size&&Rr(e.textBetween(n-1,n+1))&&(n+=t?1:-1),o=n+(o-h),h=n}else if(o<n){let e=s<=n&&s>=o?n-s:0;n-=e,n&&n<t.size&&Rr(t.textBetween(n-1,n+1))&&(n+=e?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++,(Ke&&t.input.lastIOSEnter>Date.now()-225||Ve)&&r.some((t=>1==t.nodeType&&!Tr.test(t.nodeName)))&&(!m||m.endA>=m.endB)&&t.someProp("handleKeyDown",(e=>e(t,Ne(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!m){if(!(s&&f instanceof oe&&!f.empty&&f.$head.sameParent(f.$anchor))||t.composing||a.sel&&a.sel.anchor!=a.sel.head){if(a.sel){let e=Dr(t,t.state.doc,a.sel);if(e&&!e.eq(t.state.selection)){let i=t.state.tr.setSelection(e);n&&i.setMeta("composition",n),t.dispatch(i)}}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 oe&&(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)),We&&Je<=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((Ke&&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",(e=>e(t,Ne(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>m.start&&function(t,e,i,s,r){if(i-e<=r.pos-s.pos||Ar(s,!0,!1)<r.pos)return!1;let n=t.resolve(e);if(!s.parent.isTextblock){let t=n.nodeAfter;return null!=t&&i==e+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>i||Ar(h,!0,!1)<i)&&s.parent.content.cut(s.parentOffset).eq(h.parent.content)}(c,m.start,m.endA,w,g)&&t.someProp("handleKeyDown",(e=>e(t,Ne(8,"Backspace")))))return void(Ve&&Ye&&t.domObserver.suppressSelectionUpdates());Ye&&m.endB==m.start&&(t.input.lastChromeDelete=Date.now()),Ve&&!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(e){return e(t,Ne(13,"Enter"))}))}),20));let M,v=m.start,k=m.endA,S=e=>{let i=e||t.state.tr.replace(v,k,a.doc.slice(m.start-a.from,m.endB-a.from));if(a.sel){let e=Dr(t,i.doc,a.sel);e&&!(Ye&&t.composing&&e.empty&&(m.start!=m.endB||t.input.lastChromeDelete<Date.now()-100)&&(e.head==v||e.head==i.mapping.map(k)-1)||We&&e.empty&&e.head==v)&&i.setSelection(e)}return n&&i.setMeta("composition",n),i.scrollIntoView()};if(b)if(w.pos==g.pos){We&&Je<=11&&0==w.parentOffset&&(t.domObserver.suppressSelectionUpdates(),setTimeout((()=>Yi(t)),20));let e=S(t.state.tr.delete(v,k)),i=c.resolve(m.start).marksAcross(c.resolve(m.endA));i&&e.ensureMarks(i),t.dispatch(e)}else if(m.endA==m.endB&&(M=function(t,e){let i,s,r,n=t.firstChild.marks,h=e.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],i="add",r=t=>t.mark(s.addToSet(t.marks));else{if(0!=o.length||1!=l.length)return null;s=l[0],i="remove",r=t=>t.mark(s.removeFromSet(t.marks))}let u=[];for(let t=0;t<e.childCount;t++)u.push(r(e.child(t)));if(d.from(u).eq(t))return{mark:s,type:i}}(w.parent.content.cut(w.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,m.endA-y.start())))){let e=S(t.state.tr);"add"==M.type?e.addMark(v,k,M.mark):e.removeMark(v,k,M.mark),t.dispatch(e)}else if(w.parent.child(w.index()).isText&&w.index()==g.index()-(g.textOffset?0:1)){let e=w.parent.textBetween(w.parentOffset,g.parentOffset),i=()=>S(t.state.tr.insertText(e,v,k));t.someProp("handleTextInput",(s=>s(t,v,k,e,i)))||t.dispatch(i())}else t.dispatch(S());else t.dispatch(S())}(this,t,e,i,s))),this.domObserver.start(),function(t){for(let e in Ts){let i=Ts[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{!Ps(t,e)||Cs(t,e)||!t.editable&&e.type in Ds||i(t,e)},As[e]?{passive:!0}:void 0)}He&&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 e in t)this._props[e]=t[e];this._props.state=this.state}return this._props}update(t){t.handleDOMEvents!=this._props.handleDOMEvents&&$s(this);let e=this._props;this._props=t,t.plugins&&(t.plugins.forEach(Ir),this.directPlugins=t.plugins),this.updateStateInner(t.state,e)}setProps(t){let e={};for(let t in this._props)e[t]=this._props[t];e.state=this.state;for(let i in t)e[i]=t[i];this.update(e)}updateState(t){this.updateStateInner(t,this._props)}updateStateInner(t,e){var i;let s=this.state,r=!1,n=!1;t.storedMarks&&this.composing&&(Ys(this),n=!0),this.state=t;let h=s.plugins!=t.plugins||this._props.plugins!=e.plugins;if(h||this._props.plugins!=e.plugins||this._props.nodeViews!=e.nodeViews){let t=Nr(this);(function(t,e){let i=0,s=0;for(let s in t){if(t[s]!=e[s])return!0;i++}for(let t in e)s++;return i!=s})(t,this.nodeViews)&&(this.nodeViews=t,r=!0)}(h||e.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 e,i,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){e=s,i=o.top;break}}return{refDOM:e,refTop:i,stack:ri(t.dom)}}(this);if(n){this.domObserver.stop();let e=f&&(We||Ye)&&!this.composing&&!s.selection.empty&&!t.selection.empty&&function(t,e){let i=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(i)!=e.$anchor.start(i)}(s.selection,t.selection);if(f){let i=Ye?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let i=function(t,e){for(;;){if(3==t.nodeType&&e)return t;if(1==t.nodeType&&e>0){if("false"==t.contentEditable)return null;e=$e(t=t.childNodes[e-1])}else{if(!t.parentNode||Ce(t))return null;e=xe(t),t=t.parentNode}}}(e.focusNode,e.focusOffset),s=function(t,e){for(;;){if(3==t.nodeType&&e<t.nodeValue.length)return t;if(1==t.nodeType&&e<t.childNodes.length){if("false"==t.contentEditable)return null;t=t.childNodes[e],e=0}else{if(!t.parentNode||Ce(t))return null;e=xe(t)+1,t=t.parentNode}}}(e.focusNode,e.focusOffset);if(i&&s&&i!=s){let e=s.pmViewDesc,r=t.domObserver.lastChangedTextNode;if(i==r||s==r)return r;if(!e||!e.isText(s.nodeValue))return s;if(t.input.compositionNode==s){let t=i.pmViewDesc;if(t&&t.isText(i.nodeValue))return s}}return i||s}(this)),!r&&this.docView.update(t.doc,l,o,this)||(this.docView.updateOuterDeco(l),this.docView.destroy(),this.docView=Di(t.doc,l,o,this.dom,this)),!i||this.trackWrites&&this.dom.contains(this.trackWrites)||(e=!0)}e||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),i=t.domSelectionRange();return Ae(e.node,e.offset,i.anchorNode,i.anchorOffset)}(this))?Yi(this,e):(Gi(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null===(i=this.dragging)||void 0===i?void 0:i.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:e,stack:i}){let s=t?t.getBoundingClientRect().top:0;ni(i,0==s?0:s-e)}(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 ue){let e=this.docView.domAfterPos(this.state.selection.from);1==e.nodeType&&si(this,e.getBoundingClientRect(),t)}else si(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 e=0;e<this.pluginViews.length;e++){let i=this.pluginViews[e];i.update&&i.update(this,t)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let e=this.directPlugins[t];e.spec.view&&this.pluginViews.push(e.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let e=this.state.plugins[t];e.spec.view&&this.pluginViews.push(e.spec.view(this))}}}updateDraggedNode(t,e){let i=t.node,s=-1;if(i.from<this.state.doc.content.size&&this.state.doc.nodeAt(i.from)==i.node)s=i.from;else{let t=i.from+(this.state.doc.content.size-e.doc.content.size);(t>0&&t<this.state.doc.content.size&&this.state.doc.nodeAt(t))==i.node&&(s=t)}this.dragging=new Gs(t.slice,t.move,s<0?void 0:ue.create(this.state.doc,s))}someProp(t,e){let i,s=this._props&&this._props[t];if(null!=s&&(i=e?e(s):s))return i;for(let s=0;s<this.directPlugins.length;s++){let r=this.directPlugins[s].props[t];if(null!=r&&(i=e?e(r):r))return i}let r=this.state.plugins;if(r)for(let s=0;s<r.length;s++){let n=r[s].props[t];if(null!=n&&(i=e?e(n):n))return i}}hasFocus(){if(We){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(hi)return t.focus(hi);let e=ri(t);t.focus(null==hi?{get preventScroll(){return hi={preventScroll:!0},!0}}:void 0),hi||(hi=!1,ni(e,0))}(this.dom),Yi(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 fi(this,t)}coordsAtPos(t,e=1){return pi(this,t,e)}domAtPos(t,e=0){return this.docView.domFromPos(t,e)}nodeDOM(t){let e=this.docView.descAt(t);return e?e.nodeDOM:null}posAtDOM(t,e,i=-1){let s=this.docView.posFromDOM(t,e,i);if(null==s)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(t,e){return function(t,e,i){return bi==e&&Mi==i?vi:(bi=e,Mi=i,vi="up"==i||"down"==i?function(t,e,i){let s=e.selection,r="up"==i?s.$from:s.$to;return gi(t,e,(()=>{let{node:e}=t.docView.domFromPos(r.pos,"up"==i?-1:1);for(;;){let i=t.docView.nearestDesc(e,!0);if(!i)break;if(i.node.isBlock){e=i.contentDOM||i.dom;break}e=i.dom.parentNode}let s=pi(t,r.pos,1);for(let t=e.firstChild;t;t=t.nextSibling){let e;if(1==t.nodeType)e=t.getClientRects();else{if(3!=t.nodeType)continue;e=De(t,0,t.nodeValue.length).getClientRects()}for(let t=0;t<e.length;t++){let r=e[t];if(r.bottom>r.top+1&&("up"==i?s.top-r.top>2*(r.bottom-s.top):r.bottom-s.bottom>2*(s.bottom-r.top)))return!1}}return!0}))}(t,e,i):function(t,e,i){let{$head:s}=e.selection;if(!s.parent.isTextblock)return!1;let r=s.parentOffset,n=!r,h=r==s.parent.content.size,o=t.domSelection();return o?yi.test(s.parent.textContent)&&o.modify?gi(t,e,(()=>{let{focusNode:e,focusOffset:r,anchorNode:n,anchorOffset:h}=t.domSelectionRange(),l=o.caretBidiLevel;o.modify("move",i,"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)||e==f&&r==a;try{o.collapse(n,h),e&&(e!=n||r!=h)&&o.extend&&o.extend(e,r)}catch(t){}return null!=l&&(o.caretBidiLevel=l),c})):"left"==i||"backward"==i?n:h:s.pos==s.start()||s.pos==s.end()}(t,e,i))}(this,e||this.state,t)}pasteHTML(t,e){return Ks(this,"",t,!1,e||new ClipboardEvent("paste"))}pasteText(t,e){return Ks(this,t,null,!0,e||new ClipboardEvent("paste"))}serializeForClipboard(t){return ps(this,t)}destroy(){this.docView&&(function(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);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,Te=null)}get isDestroyed(){return null==this.docView}dispatchEvent(t){return function(t,e){Cs(t,e)||!Ts[e.type]||!t.editable&&e.type in Ds||Ts[e.type](t,e)}(this,t)}domSelectionRange(){let t=this.domSelection();return t?He&&11===this.root.nodeType&&function(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}(this.dom.ownerDocument)==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return Sr(t,i)}let i;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",s,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",s,!0),i?Sr(t,i):null}(this,t)||t:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function $r(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",(i=>{if("function"==typeof i&&(i=i(t.state)),i)for(let t in i)"class"==t?e.class+=" "+i[t]:"style"==t?e.style=(e.style?e.style+";":"")+i[t]:e[t]||"contenteditable"==t||"nodeName"==t||(e[t]=String(i[t]))})),e.translate||(e.translate="no"),[sr.node(0,t.state.doc.content.size,e)]}function Cr(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:sr.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Pr(t){return!t.someProp("editable",(e=>!1===e(t.state)))}function Nr(t){let e=Object.create(null);function i(t){for(let i in t)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=t[i])}return t.someProp("nodeViews",i),t.someProp("markViews",i),e}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 e=this._props.dispatchTransaction;e?e.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],Xr=new it({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:e,alt:i,title:s}=t.attrs;return["img",{src:e,alt:i,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:e,title:i}=t.attrs;return["a",{href:e,title:i},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}}}),Yr=["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?Yr:["ol",{start:t.attrs.order},0]},qr={parseDOM:[{tag:"ul"}],toDOM:()=>Ur},Gr={parseDOM:[{tag:"li"}],toDOM:()=>Hr,defining:!0};function Vr(t,e){let i={};for(let e in t)i[e]=t[e];for(let t in e)i[t]=e[t];return i}function Zr(t,e,i){return t.append({ordered_list:Vr(Kr,{content:"list_item+",group:i}),bullet_list:Vr(qr,{content:"list_item+",group:i}),list_item:Vr(Gr,{content:e})})}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 e,i,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))e=!0;else if(/^(c|ctrl|control)$/i.test(h))i=!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:i=!0}}return e&&(h="Alt-"+h),i&&(h="Ctrl-"+h),r&&(h="Meta-"+h),s&&(h="Shift-"+h),h}function un(t,e,i=!0){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),i&&e.shiftKey&&(t="Shift-"+t),t}function fn(t){return new ke({props:{handleKeyDown:an(t)}})}function an(t){let e=function(t){let e=Object.create(null);for(let i in t)e[ln(i)]=t[i];return e}(t);return function(t,i){let s,r=function(t){var e=!(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"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(i),n=e[un(r,i)];if(n&&n(t.state,t.dispatch,t))return!0;if(1==r.length&&" "!=r){if(i.shiftKey){let s=e[un(r,i,!1)];if(s&&s(t.state,t.dispatch,t))return!0}if((i.altKey||i.metaKey||i.ctrlKey)&&!(on&&i.ctrlKey&&i.altKey)&&(s=Qr[i.keyCode])&&s!=r){let r=e[un(s,i)];if(r&&r(t.state,t.dispatch,t))return!0}}return!1}}const cn=(t,e)=>!t.selection.empty&&(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function dn(t,e,i=!1){for(let s=t;s;s="start"==e?s.firstChild:s.lastChild){if(s.isTextblock)return!0;if(i&&1!=s.childCount)return!1}return!1}function pn(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function mn(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let i=t.node(e);if(t.index(e)+1<i.childCount)return t.doc.resolve(t.after(e+1));if(i.type.spec.isolating)break}return null}function wn(t){for(let e=0;e<t.edgeCount;e++){let{type:i}=t.edge(e);if(i.isTextblock&&!i.hasRequiredAttrs())return i}return null}function gn(t,e,i,s){let r,n,h=e.nodeBefore,o=e.nodeAfter,l=h.type.spec.isolating||o.type.spec.isolating;if(!l&&function(t,e,i){let s=e.nodeBefore,r=e.nodeAfter,n=e.index();return!(!(s&&r&&s.type.compatibleContent(r.type))||(!s.content.size&&e.parent.canReplace(n-1,n)?(i&&i(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView()),0):!e.parent.canReplace(n,n+1)||!r.isTextblock&&!Wt(t.doc,e.pos)||(i&&i(t.tr.join(e.pos).scrollIntoView()),0)))}(t,e,i))return!0;let u=!l&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(r=(n=h.contentMatchAt(h.childCount)).findWrapping(o.type))&&n.matchType(r[0]||o.type).validEnd){if(i){let s=e.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(e.pos-1,s,e.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),i(l.scrollIntoView())}return!0}let f=o.type.spec.isolating||s>0&&l?null:se.findFrom(e,1),a=f&&f.$from.blockRange(f.$to),c=a&&_t(a);if(null!=c&&c>=e.depth)return i&&i(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(i){let s=d.empty;for(let t=r.length-1;t>=0;t--)s=d.from(r[t].copy(s));i(t.tr.step(new Pt(e.pos-r.length,e.pos+o.nodeSize,e.pos+l,e.pos+o.nodeSize-l,new b(s,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function yn(t){return function(e,i){let s=e.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&&(i&&i(e.tr.setSelection(oe.create(e.doc,t<0?r.start(n):r.end(n)))),!0)}}const bn=yn(-1),Mn=yn(1);function vn(...t){return function(e,i,s){for(let r=0;r<t.length;r++)if(t[r](e,i,s))return!0;return!1}}let kn=vn(cn,((t,e,i)=>{let s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("backward",t):i.parentOffset>0)?null:i}(t,i);if(!s)return!1;let r=pn(s);if(!r){let i=s.blockRange(),r=i&&_t(i);return null!=r&&(e&&e(t.tr.lift(i,r).scrollIntoView()),!0)}let n=r.nodeBefore;if(gn(t,r,e,-1))return!0;if(0==s.parent.content.size&&(dn(n,"end")||ue.isSelectable(n)))for(let i=s.depth;;i--){let h=Jt(t.doc,s.before(i),s.after(i),b.empty);if(h&&h.slice.size<h.to-h.from){if(e){let i=t.tr.step(h);i.setSelection(dn(n,"end")?se.findFrom(i.doc.resolve(i.mapping.map(r.pos,-1)),-1):ue.create(i.doc,r.pos-n.nodeSize)),e(i.scrollIntoView())}return!0}if(1==i||s.node(i-1).childCount>1)break}return!(!n.isAtom||r.depth!=s.depth-1||(e&&e(t.tr.delete(r.pos-n.nodeSize,r.pos).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("backward",t):s.parentOffset>0)return!1;n=pn(s)}let h=n&&n.nodeBefore;return!(!h||!ue.isSelectable(h)||(e&&e(t.tr.setSelection(ue.create(t.doc,n.pos-h.nodeSize)).scrollIntoView()),0))})),Sn=vn(cn,((t,e,i)=>{let s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("forward",t):i.parentOffset<i.parent.content.size)?null:i}(t,i);if(!s)return!1;let r=mn(s);if(!r)return!1;let n=r.nodeAfter;if(gn(t,r,e,1))return!0;if(0==s.parent.content.size&&(dn(n,"start")||ue.isSelectable(n))){let i=Jt(t.doc,s.before(),s.after(),b.empty);if(i&&i.slice.size<i.to-i.from){if(e){let s=t.tr.step(i);s.setSelection(dn(n,"start")?se.findFrom(s.doc.resolve(s.mapping.map(r.pos)),1):ue.create(s.doc,s.mapping.map(r.pos))),e(s.scrollIntoView())}return!0}}return!(!n.isAtom||r.depth!=s.depth-1||(e&&e(t.tr.delete(r.pos,r.pos+n.nodeSize).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;n=mn(s)}let h=n&&n.nodeAfter;return!(!h||!ue.isSelectable(h)||(e&&e(t.tr.setSelection(ue.create(t.doc,n.pos)).scrollIntoView()),0))}));const xn={Enter:vn(((t,e)=>{let{$head:i,$anchor:s}=t.selection;return!(!i.parent.type.spec.code||!i.sameParent(s)||(e&&e(t.tr.insertText("\n").scrollIntoView()),0))}),((t,e)=>{let i=t.selection,{$from:s,$to:r}=i;if(i instanceof ae||s.parent.inlineContent||r.parent.inlineContent)return!1;let n=wn(r.parent.contentMatchAt(r.indexAfter()));if(!n||!n.isTextblock)return!1;if(e){let i=(!s.parentOffset&&r.index()<r.parent.childCount?s:r).pos,h=t.tr.insert(i,n.createAndFill());h.setSelection(oe.create(h.doc,i+1)),e(h.scrollIntoView())}return!0}),((t,e)=>{let{$cursor:i}=t.selection;if(!i||i.parent.content.size)return!1;if(i.depth>1&&i.after()!=i.end(-1)){let s=i.before();if(Bt(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let s=i.blockRange(),r=s&&_t(s);return null!=r&&(e&&e(t.tr.lift(s,r).scrollIntoView()),!0)}),((t,e)=>{let{$from:i}=t.selection;if(t.selection instanceof ue&&t.selection.node.isBlock)return!(!i.parentOffset||!Bt(t.doc,i.pos)||(e&&e(t.tr.split(i.pos).scrollIntoView()),0));if(!i.depth)return!1;let s,r,n=[],h=!1,o=!1;for(let t=i.depth;;t--){if(i.node(t).isBlock){h=i.end(t)==i.pos+(i.depth-t),o=i.start(t)==i.pos-(i.depth-t),r=wn(i.node(t-1).contentMatchAt(i.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 oe||t.selection instanceof ae)&&l.deleteSelection();let u=l.mapping.map(i.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&&i.node(s).type!=r){let t=l.mapping.map(i.before(s)),e=l.doc.resolve(t);r&&i.node(s-1).canReplaceWith(e.index(),e.index()+1,r)&&l.setNodeMarkup(l.mapping.map(i.before(s)),r)}return e&&e(l.scrollIntoView()),!0})),"Mod-Enter":(t,e)=>{let{$head:i,$anchor:s}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(s))return!1;let r=i.node(-1),n=i.indexAfter(-1),h=wn(r.contentMatchAt(n));if(!h||!r.canReplaceWith(n,n,h))return!1;if(e){let s=i.after(),r=t.tr.replaceWith(s,s,h.createAndFill());r.setSelection(se.near(r.doc.resolve(s),1)),e(r.scrollIntoView())}return!0},Backspace:kn,"Mod-Backspace":kn,"Shift-Backspace":kn,Delete:Sn,"Mod-Delete":Sn,"Mod-a":(t,e)=>(e&&e(t.tr.setSelection(new ae(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 it({nodes:Zr(Xr.spec.nodes,"paragraph block*","block"),marks:Xr.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 e=this._core?.store?.state?.scale,i=null!=e&&e<0?e:1;this.width=this.initialWidth/i,this.height=1.2*this.fontSize/i,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,e,i,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=e||8,r.fontFamily=i||"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:Me.create({doc:t,plugins:[fn(Tn)]}),editable:()=>!1,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e),t.docChanged&&(this.content=e.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 e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const e=this.totalWidth,i=this.totalHeight,s=t.scrollHeight;if(this.width=t.scrollWidth*this.scaleFactor,this.height=s*this.scaleFactor,0!==this.rotation){const t=(this.totalWidth-e)/2/this.scale,s=(this.totalHeight-i)/2/this.scale;if(0!==t||0!==s){const e=Math.cos(this.rotation),i=Math.sin(this.rotation),r=i*t+e*s;this.translateX+=e*t-i*s-t,this.translateY+=r-s}}}}resize(t,e,i,s){if(i<=1||s<=1)return;const r=this.width/this.scaleFactor,n=this.height/this.scaleFactor;this.scaleFactor=Math.min(i/r,s/n),this.width=r*this.scaleFactor,this.height=n*this.scaleFactor,this.translateX=t,this.translateY=e,this._core.store.objects.update(this)}focus(t){if(this.editor){const e=this.editor.state.doc;if(t.x&&t.y&&!this.isEmpty){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(oe.create(e,i.pos))),this.editor.focus(),void(o.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(oe.create(e,i))),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(oe.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:e,_schema:i,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,e){const i=await this.ensureDb(),s=e.id??this.generateUuid(),r={id:s,kind:e.kind??"file",mimeType:e.mimeType,size:t.size,createdAt:Date.now(),width:e.width,height:e.height,durationMs:e.durationMs,originalFilename:e.originalFilename};return await new Promise(((e,n)=>{const h=i.transaction([An,Rn],"readwrite");h.oncomplete=()=>e(),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 e=this._urlCache.get(t);if(e)return e;const i=await this.fetch(t),s=URL.createObjectURL(i);return this._urlCache.set(t,s),s}async fetch(t){const e=await this.ensureDb(),i=await new Promise(((i,s)=>{const r=e.transaction(An,"readonly").objectStore(An).get(t);r.onsuccess=()=>i(r.result),r.onerror=()=>s(r.error)}));if(!i)throw new Error(`[IndexedDBAssetProvider] Asset ${t} not found`);return this._knownIds.add(t),i}async delete(t){const e=await this.ensureDb();await new Promise(((i,s)=>{const r=e.transaction([An,Rn],"readwrite");r.oncomplete=()=>i(),r.onerror=()=>s(r.error),r.objectStore(An).delete(t),r.objectStore(Rn).delete(t)}));const i=this._urlCache.get(t);if(i){try{URL.revokeObjectURL(i)}catch{}this._urlCache.delete(t)}this._knownIds.delete(t)}async getMetadata(t){const e=await this.ensureDb();return new Promise(((i,s)=>{const r=e.transaction(Rn,"readonly").objectStore(Rn).get(t);r.onsuccess=()=>i(r.result),r.onerror=()=>s(r.error)}))}async listAssetsWithPendingRemotes(){const t=await this.ensureDb();return new Promise(((e,i)=>{const s=t.transaction(Rn,"readonly").objectStore(Rn).getAll();s.onsuccess=()=>{e((s.result??[]).filter((t=>Array.isArray(t.pendingRemotes)&&t.pendingRemotes.length>0)))},s.onerror=()=>i(s.error)}))}async setPendingRemotes(t,e){const i=await this.ensureDb();await new Promise(((s,r)=>{const n=i.transaction(Rn,"readwrite");n.oncomplete=()=>s(),n.onerror=()=>r(n.error);const h=n.objectStore(Rn),o=h.get(t);o.onsuccess=()=>{const i=o.result;if(!i)return;const s={...i};e.length>0?s.pendingRemotes=e:delete s.pendingRemotes,h.put(s,t)}}))}async ensureDb(){return this._db||await this.init(),this._db}openDatabase(){return new Promise(((t,e)=>{const i=indexedDB.open(this._dbName,1);i.onupgradeneeded=()=>{const t=i.result;t.objectStoreNames.contains(An)||t.createObjectStore(An),t.objectStoreNames.contains(Rn)||t.createObjectStore(Rn)},i.onsuccess=()=>t(i.result),i.onerror=()=>e(i.error)}))}async loadKnownIds(){const t=this._db;t&&await new Promise(((e,i)=>{const s=t.transaction(Rn,"readonly").objectStore(Rn).getAllKeys();s.onsuccess=()=>{for(const t of s.result)"string"==typeof t&&this._knownIds.add(t);e()},s.onerror=()=>i(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 e=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}}class $n extends Error{assetId;constructor(t,e){super(e??`[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 e=this.instantiateProviders(t?.providers??[]);e.some((t=>"local"===t.type))||e.unshift(new En),e.sort(((t,e)=>"local"===t.type&&"local"!==e.type?-1:"local"!==t.type&&"local"===e.type?1:0)),this._providers=e,this._local=e.find((t=>"local"===t.type&&"IndexedDBAssetProvider"===t.name))??null,this._remoteProviders=e.filter((t=>"remote"===t.type)),this._local&&await this._local.init();for(const t of this._remoteProviders)try{await t.init()}catch(e){console.warn(`[KritzelAssetResolver] Remote provider "${t.name}" failed to initialize. Assets will be served from the local provider until the remote becomes available.`,e)}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,e){await this.ensureReady();const i=e.id??this.generateUuid(),s={...e,id:i};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(i,t);for(const e of t)this._pending.set(this.pendingKey(i,e),{id:i,providerName:e,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 e=this._resolvePromises.get(t);if(e)return e;const i=(async()=>{if(this._local&&this._local.canResolve(t))return this._local.resolve(t);let e,i=0;for(const s of this._providers)if(s!==this._local){i++;try{const e=await s.fetch(t);if(this._local){try{await this._local.put(e,{id:t,mimeType:e.type||"application/octet-stream",kind:"file"})}catch{}return this._local.resolve(t)}return URL.createObjectURL(e)}catch(t){e=t}}if(0===i)throw new $n(t);throw new Error(`[KritzelAssetResolver] Failed to resolve asset ${t}: ${String(e)}`)})();this._resolvePromises.set(t,i);try{return await i}finally{this._resolvePromises.delete(t)}}async fetchBlob(t){let e;await this.ensureReady();let i=!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?i=!0:r++;try{return await h.fetch(t)}catch(t){h===this._local&&(s=!0),e=t}}if(0===r&&(!i||s))throw new $n(t);throw new Error(`[KritzelAssetResolver] Failed to fetch blob for ${t}: ${String(e)}`)}async putDataUrl(t,e){const i=await this.dataUrlToBlob(t);return this.put(i,{...e,mimeType:e.mimeType??i.type??"application/octet-stream"})}logProviderConfiguration(){const t=[`Asset resolver initialized with ${this._providers.length} provider(s):`];for(const e of this._providers)t.push(` - ${e.name} [${e===this._local?"local (primary write target)":e.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,e){return`${t}::${e}`}async recoverPendingUploads(){if(!this._local||0===this._remoteProviders.length)return;const t=await this._local.listAssetsWithPendingRemotes(),e=new Set(this._remoteProviders.map((t=>t.name))),i=Date.now();let s=0;for(const r of t){const t=(r.pendingRemotes??[]).filter((t=>e.has(t)));if(0!==t.length)for(const e of t)this._pending.set(this.pendingKey(r.id,e),{id:r.id,providerName:e,attempts:0,nextAttemptAt:i}),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 e=Number.POSITIVE_INFINITY;for(const[i,s]of Array.from(this._pending.entries())){if(s.nextAttemptAt>t){e=Math.min(e,s.nextAttemptAt-t);continue}const r=this._remoteProviders.find((t=>t.name===s.providerName));if(!r){this._pending.delete(i);continue}let n,h;try{[n,h]=await Promise.all([this._local.fetch(s.id),this._local.getMetadata(s.id)])}catch{this._pending.delete(i);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(i),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 i=Math.min(3e5,2e3*Math.pow(2,s.attempts-1));s.nextAttemptAt=Date.now()+i,e=Math.min(e,i),console.warn(`[KritzelAssetResolver] Upload to ${r.name} failed for ${s.id} (attempt ${s.attempts}). Retrying in ${Math.round(i/1e3)}s.`,t)}}this._pending.size>0&&Number.isFinite(e)&&this.scheduleFlush(e)}async clearPendingRemote(t,e){if(!this._local)return;const i=await this._local.getMetadata(t);if(!i)return;const s=(i.pendingRemotes??[]).filter((t=>t!==e));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,e)=>{this._resolveReady=t,this._rejectReady=e}))),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 e=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.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 e=new Pn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.x=0,e.y=0,e.translateX=0,e.translateY=0,e.scale=e._core.store.state.scale,e.zIndex=t.store.currentZIndex,e}resize(t,e,i,s){if(i<=1||s<=1)return;const r=s/this.height;this.width=this.width*r,this.height=this.height*r,this.translateX=t,this.translateY=e,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((e=>{if(e 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}):`,e),t?(this.loadState="error",void this._core?.rerender()):void this.scheduleRetry(this.loadAttempts)}const i=Date.now();null===this.transientRetryStartedAt&&(this.transientRetryStartedAt=i);const s=i-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):`,e),r)return this.loadState="error",void this._core?.rerender();this.scheduleRetry(t+1)}))}scheduleRetry(t){this.loadState="idle";const e=Math.min(2e3,250*Math.pow(2,Math.max(0,t-1)));setTimeout((()=>{"idle"===this.loadState&&this.ensureResolved()}),e)}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,e){return new Promise(((i,s)=>{const r=new Image;r.onload=()=>{const s=new Pn({...e,src:t}),{scaledWidth:n,scaledHeight:h}=s.calculateScaledDimensions(r);s.width=n,s.height=h,i(s)},r.onerror=t=>s(t),r.src=t}))}calculateScaledDimensions(t){let e=t.width,i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);e=t.width*s,i=t.height*s}return{scaledWidth:e,scaledHeight:i}}}class Nn{static isInstanceOf(t,e){return!!t&&t.__class__===e}}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 e=this._core.store.objects.filter((e=>e.id===t));return e.length>0?e[0]:null})).filter((t=>null!==t)):this._pendingChildren}get length(){return this.childIds.length}static create(t){const e=new In;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.scale=t.store.state.scale,e.zIndex=t.store.currentZIndex,e}static createFromObjects(t,e){const i=In.create(t);return e.forEach((t=>{i.childIds.push(t.id)})),i.refreshBoundingBox(),i.captureChildSnapshots(),i}static findParentGroup(t,e){const i=t.store.objects.filter((t=>"KritzelGroup"===t.__class__));for(const t of i)if(t.childIds.includes(e))return t;return null}static collectDescendantIds(t,e=new Set){for(const i of t.children)e.add(i.id),i instanceof In&&In.collectDescendantIds(i,e);return e}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 e=this.childIds.indexOf(t);-1!==e&&(this.childIds.splice(e,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:e,translateX:i,translateY:s,scale:r}=this._core.store.state,{x:n,y:h,width:o,height:l}=this.rotatedBoundingBox,u=(t/2-i)/r-(n+o/2),f=(e/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,e=Math.cos(-t),i=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*e-t.y*i,l=t.x*i+t.y*e;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,e,i,s){const r=(t-i)/this._core.store.state.scale,n=(e-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,e,i,s),this._core.anchorManager.updateAnchorsForObject(r.id)}))})),this.unchangedChildSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}resize(t,e,i,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?i/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+(i+2*this.padding)/2/this.scale,c=e+(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 e=this.unchangedChildSnapshots.get(t.id),i=e?e.width:t.width,s=e?e.height:t.height,r=(e?e.scale:t.scale)||1,n=(e?e.translateX:t.translateX)+(e?e.totalWidth:t.totalWidth)/2/r-u,h=(e?e.translateY:t.translateY)+(e?e.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=(e?e.rotation:t.rotation)-d,S=Math.cos(k),x=Math.sin(k),O=i*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 e=this.translateX+this.totalWidth/2/this.scale,i=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=e+(r*l-n*u)-h.totalWidth/2/h.scale,h.translateY=i+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,e){return this.children.some((i=>i.hitTest(t,e)))}hitTestPolygon(t){return this.children.some((e=>e.hitTestPolygon(t)))}copy(){const t=In.create(this._core),e=[];return this.children.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((i=>{const s=i.copy();e.push(s),t.childIds.push(s.id)})),t._pendingChildren=e,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:e,element:i,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((e=>{e.workspaceId=t,Nn.isInstanceOf(e,"KritzelGroup")&&e.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 it({nodes:Zr(Xr.spec.nodes,"paragraph block*","block"),marks:Xr.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,e){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.x=e?.x??0,i.y=e?.y??0,i.translateX=e?.translateX??0,i.translateY=e?.translateY??0,i.width=e?.width??100,i.height=e?.height??100,i.shapeType=e?.shapeType??zn.Rectangle,i.fillColor=e?.fillColor??{light:"transparent",dark:"transparent"},i.strokeColor=e?.strokeColor??e?.fillColor??{light:"#000000",dark:"#ffffff"},i.strokeWidth=e?.strokeWidth??4,i.opacity=e?.opacity??1,i.fontSize=e?.fontSize??16,i.fontFamily=e?.fontFamily??"Arial",i.fontColor=e?.fontColor??r.determineTextColor(i.fillColor),i.backgroundColor={light:"transparent",dark:"transparent"},i.scaleFactor=1,i.scale=e?.scale??t.store.state.scale,i.zIndex=t.store.currentZIndex,i.editor=i.createEditor(),i.updateDimensions(),i}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:Me.create({doc:t,plugins:[fn(Tn)]}),editable:()=>!1,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e),t.docChanged&&(this.content=e.doc.toJSON(),t.getMeta("fromRemote")||this._core.store.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.objects.update(this))}focus(t){if(!this.editor)return;const e=this.editor.state.doc;if(t?.x&&t?.y){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(oe.create(e,i.pos))),this.editor.focus(),void(o.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(oe.create(e,i))),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(oe.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:e,_schema:i,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,i=this.totalHeight/this.scale,s=this.translateX+t/2,r=this.translateY+i/2,n=this.strokeWidth/this.scale/2;switch(this.shapeType){case zn.Ellipse:return e.getEllipsePolygonApproximation(s,r,t/2+n,i/2+n,32,this.rotation);case zn.Triangle:const h=(t,e)=>{const i=t-s,h=e-r,o=Math.sqrt(i*i+h*h);if(0===o)return{x:t,y:e};const l=(o+n)/o;return{x:s+i*l,y:r+h*l}},o=this.translateX,l=this.translateY+i,u=this.translateX+t,f=this.translateY+i,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),e=Math.sin(this.rotation),i=i=>{const n=i.x-s,h=i.y-r;return{x:s+n*t-h*e,y:r+n*e+h*t}};return[i(a),i(c),i(d)]}return[a,c,d];default:return null}}getSvgPath(){const t=this.width,e=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+e} L ${this.x} ${this.y+e} Z`;case zn.Ellipse:const i=this.x+t/2,s=this.y+e/2,r=t/2,n=e/2;return`M ${i-r} ${s} A ${r} ${n} 0 1 0 ${i+r} ${s} A ${r} ${n} 0 1 0 ${i-r} ${s}`;case zn.Triangle:return`M ${this.x+t/2} ${this.y} L ${this.x+t} ${this.y+e} L ${this.x} ${this.y+e} Z`;default:return`M ${this.x} ${this.y} L ${this.x+t} ${this.y} L ${this.x+t} ${this.y+e} L ${this.x} ${this.y+e} 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,e,i){if("touch"!==t.pointerType)return i?.(),()=>{};const s=t.clientX,r=t.clientY,n=t.target;if(!n)return i?.(),()=>{};const h=setTimeout((()=>{a(),e(t)}),400),o=()=>{clearTimeout(h),a(),i?.()},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 e=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?e:1,n=i.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:e,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 e=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?e: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=i.create(this._core,{points:[[n,h]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?1:e,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 e=this._core.store.objects.findById(this._currentPathId);if(e){const s=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?s:1,h=i.create(this._core,{points:[...e.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=e.id,h.workspaceId=e.workspaceId,h.zIndex=e.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 e=this._core.store.objects.findById(this._currentPathId);if(e){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=i.create(this._core,{points:[...e.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=e.id,l.workspaceId=e.workspaceId,l.zIndex=e.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}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}}}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 e=new Set(this._objectIds),i=this._core.store.objects.filter((t=>e.has(t.id))),s=new Map(i.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 e=new Jn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.clientId=t.store.objects?.localClientId??void 0,e.scale=t.store.state.scale,e.zIndex=99999,e.borderColor={light:"#007AFF",dark:"#0A84FF"},e.borderWidth=2,e.handleColor={light:"#ffffff",dark:"#1a1a1a"},e.handleStrokeColor={light:"#007AFF",dark:"#0A84FF"},e.handleSize=6,e}addObjects(t){let e=!1;for(const i of t)this._objectIds.includes(i.id)||(this._objectIds.push(i.id),e=!0);if(e){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 e=this._objectIds.findIndex((e=>e===t.id));-1===e?this._objectIds.push(t.id):this._objectIds.splice(e,1),this._cachedObjects=null;const i=this.objects;1===i.length?this.rotation=i[0].rotation:i.length>1&&(this.rotation=0),this.captureUnchangedSnapshots(i),this.refreshObjectDimensions(i)}beginTransform(){const t=this.objects;this.refreshObjectDimensions(t),this.captureUnchangedSnapshots(t);for(const e of t)Nn.isInstanceOf(e,"KritzelGroup")&&e.finalize()}deselectAllChildren(){const t=this.objects;for(const e of t)e.isSelected=!1}updateWorkspaceId(t){this.workspaceId=t;const e=this.objects;for(const i of e)i.workspaceId=t}updateZIndices(t){const e=this.objects;for(let i=0;i<e.length;i++)e[i].zIndex=t+i}updatePosition(t,e){const i=this.objects;for(const s of i)s.updatePosition(t+(s.translateX-this.translateX),e+(s.translateY-this.translateY));this.unchangedObjectSnapshots.forEach((i=>{const s=i.translateY-this.translateY;i.translateX=t+(i.translateX-this.translateX),i.translateY=e+s})),this.translateX=t,this.translateY=e,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:e,element:i,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,i&&"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&(p.element=i.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,e,i,s){const r=(t-i)/this._core.store.state.scale,n=(e-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,e,i,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,e,i,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 e of t)this._core.store.objects.update(e)}))}resize(t,e,i,s){const r=i/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+(i+2*this.padding)/2/this.scale,u=e+(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 e=this.unchangedObjectSnapshots.get(t.id);if(!e)return;const i=e.translateX+e.totalWidth/2/e.scale-h,s=e.translateY+e.totalHeight/2/e.scale-o,m=(i*a-s*c)*r,w=(i*c+s*a)*n,g=l+(m*d-w*p),y=u+(m*p+w*d),b=e.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=e.width*k,O=e.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 e=this.translateX+this.totalWidth/2/this.scale,i=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=e+(r*u-n*f)-l.totalWidth/2/l.scale,l.translateY=i+a-l.totalHeight/2/l.scale,l.rotate(1===o?t:h.rotation+s)}}))}copy(){const t=Jn.create(this._core),e=this.objects,i=[...e].sort(((t,e)=>t.zIndex-e.zIndex));for(const e of i){const i=e.copy();t.addOrRemove(i)}return t.captureUnchangedSnapshots(),1===e.length&&(t.rotation=e[0].rotation),t}refreshObjectDimensions(t,e=!1){const i=t??this.objects;if(1===i.length){const t=i[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,e=Math.cos(-t),s=Math.sin(-t);let r=1/0,n=-1/0,h=1/0,o=-1/0;i.forEach((t=>{const i=t.rotatedPolygon;[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft].forEach((t=>{const i=t.x*e-t.y*s,l=t.x*s+t.y*e;i<r&&(r=i),i>n&&(n=i),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}e||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,i){const s=this.objects;if(1===s.length&&"KritzelLine"===s[0].__class__)return s[0].hitTest(t,i);const r=this.rotatedPolygon;if(e.isPointInPolygon({x:t,y:i},[r.topLeft,r.topRight,r.bottomRight,r.bottomLeft]))return!0;for(const e of s)if(e.hitTest(t,i))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 e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?e: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:i?1:e,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 e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?e: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:i?1:e,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 e=this._core.store.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?i: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:i,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});h.id=e.id,h.workspaceId=e.workspaceId,h.zIndex=e.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 e=this._core.store.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,n=r?i: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:i,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});l.id=e.id,l.workspaceId=e.workspaceId,l.zIndex=e.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}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}}selectLineAndSwitchTool(t){const e=Jn.create(this._core);e.addOrRemove(t),e.isSelected=!0,e.rotation=t.rotation,this._core.addSelectionGroup(e),this._core.store.setState("activeTool",l.getTool("selection")),this._core.rerender()}}class Xn 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 e=this._core?.store?.activeText;e&&(this._core.updateObject(e,t),this._core.rerender())}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=e?.id?this._core.findObjectById(e.id):null,s=this._core.store.activeText;if(null===s&&i instanceof Dn)return void i.edit(t);if(null!==s&&i instanceof Dn)return s.save(),void i.edit(t);if(null!==s&&i 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 e=Array.from(this._core.store.state.pointers.values()),i=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=i?.id?this._core.findObjectById(i.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(e.length>1)return;const n=Math.round(e[0].clientX-this._core.store.offsetX),h=Math.round(e[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 e=this._core.store.activeText;e&&e.isMounted&&!e.editor?.hasFocus()&&e.focus({x:t.clientX,y:t.clientY})}}class Yn 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 e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=this._core.findObjectById(e?.id),s=this._core.store.activeShape;if(null===s&&i instanceof jn)return void i.edit(t);if(null!==s&&i instanceof jn)return s.save(),void i.edit(t);if(null!==s&&i 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 e=Array.from(this._core.store.state.pointers.values()),i=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=this._core.findObjectById(i?.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(e.length>1)return;const n=Math.round(e[0].clientX),h=Math.round(e[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 e=Math.round(t[0].clientX),i=Math.round(t[0].clientY);this.updateShapeSize(e,i)}}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&this.finishDrawing()}startDrawing(t,e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1;this.startX=(t-this._core.store.offsetX)/r,this.startY=(e-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:i}),this._core.store.objects.insert(this.currentShape),this._core.store.objects?.setActiveDrawingObject(this.currentShape.id),this._core.rerender()}updateShapeSize(t,e){if(!this.currentShape)return;const i=this._core.store.state.lockDrawingScale?this._core.store.state.scale:1,s=(t-this._core.store.offsetX)/i,r=(e-this._core.store.offsetY)/i,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/i,this.currentShape.translateY=-this._core.store.state.translateY/i,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((e=>e.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.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 e=this._core.store.selectionGroup,i=t.shiftKey||t.ctrlKey;if(!e?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||i)this.trackedPointerId=null;else{const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this._core.store.state.isDragging=!0,this.dragStartX=e,this.dragStartY=i,this.startX=this.dragStartX,this.startY=this.dragStartY,this.initialDragX=e,this.initialDragY=i,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}else this.trackedPointerId=null;if("touch"===t.pointerType||"pen"===t.pointerType){const e=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 i=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(!i?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||s)this.trackedPointerId=null;else{const i=Math.round(e[0].clientX-this._core.store.offsetX),s=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i,this.dragStartY=s,this.startX=i,this.startY=s,this.initialDragX=i,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 e=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&e){const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this.endX=i,this.endY=s;const r=Math.abs(i-this.startX),n=Math.abs(s-this.startY),h=5;(this.hasMoved||r>h||n>h)&&(this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,this.hasMoved=!0)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=this._core.store.selectionGroup;if(1===this._core.store.state.pointers.size&&e&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected&&!this._core.store.state.isScaling){const i=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=i,this.endY=s;const r=Math.abs(i-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(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,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)),"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.reset())}checkAndDisconnectAnchors(t,e){const i=t-this.initialDragX,r=e-this.initialDragY;if(Math.sqrt(i*i+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 e=t;(e.startAnchor||e.endAnchor)&&(e.startAnchor&&this._core.anchorManager.removeAnchor(e.id,"start"),e.endAnchor&&this._core.anchorManager.removeAnchor(e.id,"end"),this.disconnectedLineIds.add(e.id),this._core.store.objects.update(e))}}}!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 e=this._core.store.selectionGroup;if(e&&this._core.store.state.isResizeHandleSelected){e.beginTransform();const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=e.width,this.initialSize.height=e.height,this.initialSize.x=e.translateX,this.initialSize.y=e.translateY}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=t[0];if(!e)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isResizeHandleSelected){t.beginTransform();const i=Math.round(e.clientX-this._core.store.offsetX),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=i,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 e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=t.clientX-this._core.store.offsetX-this.initialMouseX,s=t.clientY-this._core.store.offsetY-this.initialMouseY,r=Math.abs(i),n=Math.abs(s),h=5;if((r>h||n>h)&&(this.hasResized=!0),!this.hasResized)return;const o=e.rotation,l=Math.sin(o),u=Math.cos(o),f=e.scale||1,a=this._core.store.state.scale,c=(i*u+s*l)/a,d=(-i*l+s*u)/a,p=this.initialSize.x+this.initialSize.width/f/2+i/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,e.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 e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=Math.round(t.clientX-this._core.store.offsetX),s=Math.round(t.clientY-this._core.store.offsetY),r=i-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=e.rotation,f=Math.sin(u),a=Math.cos(u),c=e.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,e.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}}constrainToAspectRatio(){const t=this.initialSize.width,e=this.initialSize.height;if(0===t||0===e)return;const i=t/e,s=this.newSize.height/e;Math.abs(this.newSize.width/t-1)>Math.abs(s-1)?this.newSize.height=this.newSize.width/i:this.newSize.width=this.newSize.height*i}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.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.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 e=this._core.store.selectionGroup;if(e&&this._core.store.state.isRotationHandleSelected){e.beginTransform();const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=!0;const r=e.scale||1,n=e.translateX+e.width/2/r,h=e.translateY+e.height/2/r,o=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=e.rotation,this.initialRotation=Math.atan2(h-l,n-o)-e.rotation}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=t[0];if(!e)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isRotationHandleSelected){t.beginTransform();const i=Math.round(e.clientX-this._core.store.offsetX),s=Math.round(e.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=(i-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 e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=e.scale||1,s=Math.atan2(e.translateY+e.height/2/i-(t.clientY-this._core.store.offsetY-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/i-(t.clientX-this._core.store.offsetX-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=s-this.initialRotation,e.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 e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=Math.round(t.clientX-this._core.store.offsetX),s=Math.round(t.clientY-this._core.store.offsetY),r=e.scale||1,n=Math.atan2(e.translateY+e.height/2/r-(s-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/r-(i-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=n-this.initialRotation,e.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.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.reset();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}class Gn extends t{__class__="KritzelSelectionBox";static create(t){const e=new Gn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.scale=t.store.state.scale,e.zIndex=99999,e.backgroundColor={light:"rgba(0, 122, 255, 0.2)",dark:"rgba(0, 122, 255, 0.2)"},e.borderColor={light:"rgba(0, 122, 255, 0.5)",dark:"rgba(0, 122, 255, 0.5)"},e.borderWidth=2,e.height=0,e.width=0,e}}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 e=t.shiftKey||t.ctrlKey;"mouse"===t.pointerType&&(!Fn.isLeftClick(t)||this._core.store.selectionGroup&&!e||this.startMouseSelection(t,e)),"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&&!e||(this.startTouchSelection(t,e),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()),e=Math.round(t[0].clientX-this._core.store.offsetX),i=Math.round(t[0].clientY-this._core.store.offsetY),s=Math.abs(e-this.touchStartX),r=Math.abs(i-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 e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||s||i.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting){if(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag){const e=t.shiftKey||t.ctrlKey;this.updateMouseSelection(t),this.addSelectedObjectsToSelectionGroup(e),this.removeSelectionBox()}this._core.engine.emitObjectsChange()}}if("touch"===t.pointerType||"pen"===t.pointerType){clearTimeout(this.touchStartTimeout);const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||s||i.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting){if(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag){const e=t.shiftKey||t.ctrlKey;this.updateTouchSelection(),this.addSelectedObjectsToSelectionGroup(e),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,e=!1){let i,s;i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;const r=Gn.create(this._core);this.startX=(i-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||!e&&t instanceof Jn&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.objects.insert(r),this._core.store.setSelectionBox(r)}startTouchSelection(t,e=!1){const i=Array.from(this._core.store.state.pointers.values())[0];if(!i)return;let s,r;s=Math.round(i.clientX-this._core.store.offsetX),r=Math.round(i.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||!e&&t instanceof Jn&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.objects.insert(n),this._core.store.setSelectionBox(n)}updateMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,r=(i-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 e,i;e=Math.round(t.clientX-this._core.store.offsetX),i=Math.round(t.clientY-this._core.store.offsetY);const s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,r=(i-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 e=t.rotatedPolygon,i=[e.topLeft.x,e.topRight.x,e.bottomRight.x,e.bottomLeft.x],s=[e.topLeft.y,e.topRight.y,e.bottomRight.y,e.bottomLeft.y],r=Math.min(...i),n=Math.max(...i),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 i=t.hitTestPolygon(e);t.isSelected=i,i&&u.add(t)}for(const t of this._previouslySelectedObjects)u.has(t)||(t.isSelected=!1);this._previouslySelectedObjects=u}handleSelectionClick(t){const e=this.getTopmostHitObject(t),i=t.shiftKey||t.ctrlKey;this.clearSelectionPreview(),e&&this.addObjectToSelectionGroup(e,i),this.removeSelectionBox()}getTopmostHitObject(t){const e=this._core.store.state.pointerX,i=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(e,i))return t;return null}clearSelectionPreview(){for(const t of this._previouslySelectedObjects)t.isSelected=!1;this._previouslySelectedObjects.clear()}addObjectToSelectionGroup(t,e=!1){if(!t)return;const i=In.findParentGroup(this._core,t.id)||t;i.isSelected=!1;const s=this._core.store.selectionGroup;if(e&&s)s.addOrRemove(i),this.removeDescendantsOfSelectedGroups(s),0===s.objects.length?this._core.removeSelectionGroup():this._core.rerender();else{const t=Jn.create(this._core);t.addOrRemove(i),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}addSelectedObjectsToSelectionGroup(t=!1){const e=this._core.store.selectedObjects;if(0===e.length)return;const i=this._core.store.objects.filter((t=>"KritzelGroup"===t.__class__)),s=new Map;for(const t of i)for(const e of t.childIds)s.set(e,t);const r=new Map;for(const t of e){const e=s.get(t.id)||t;r.set(e.id,e),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 e=new Set;for(const i of t)i instanceof In&&In.collectDescendantIds(i,e);return 0===e.size?t:t.filter((t=>!e.has(t.id)))}removeDescendantsOfSelectedGroups(t){const e=this.filterDescendantsOfSelectedGroups(t.objects);e.length!==t.objects.length&&(t.objectIds=e.map((t=>t.id)))}}class Zn extends Un{constructor(t){super(t)}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.getObjectFromPointerEvent(t,".object");if(!e)return;e.isHovered=e.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 e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleSelected)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isLineHandleDragging=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialStartX=e.startX,this.initialStartY=e.startY,this.initialEndX=e.endX,this.initialEndY=e.endY,this.initialControlX=e.controlX,this.initialControlY=e.controlY,this.initialTranslateX=e.translateX,this.initialTranslateY=e.translateY;const r=this._core.store.state.lineHandleType;"start"!==r&&"end"!==r||this._core.anchorManager.removeAnchor(e.id,r);const n=this._core.store.state.longTouchTimeout;n&&globalThis.clearTimeout?.(n)}handlePointerMove(t){const e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleDragging)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY,n=i-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=e.scale||1,u=e.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=(i-this._core.store.state.translateX)/o,n=(s-this._core.store.state.translateY)/o,h=e.endAnchor?.objectId,l=this._core.anchorManager.findSnapTarget(t,n,e.id,h);if(this.currentSnapTarget=l,l){const t=this.worldToLineLocal(e,l.centerX,l.centerY);this.updateLineEndpoint(e,t.x,t.y,this.initialEndX,this.initialEndY);const i=this.lineLocalToWorld(e,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(e,"start",s);t&&(n=t.worldX,h=t.worldY,o=t.t)}void 0!==e.controlX&&void 0!==e.controlY&&(u=this.lineLocalToWorld(e,e.controlX,e.controlY)),this._core.anchorManager.setSnapCandidate({objectId:l.objectId,endpoint:"start",centerX:l.centerX,centerY:l.centerY,lineEndpointX:i.x,lineEndpointY:i.y,controlX:u?.x,controlY:u?.y,t:o,edgeX:n,edgeY:h,lineStroke:r.resolveThemeColor(e.stroke),lineStrokeWidth:e.strokeWidth/e.scale,arrowOffset:e.hasStartArrow?e.getArrowSize("start")/e.scale:void 0,arrowStyle:e.hasStartArrow?e.arrows?.start?.style:void 0,arrowFill:e.hasStartArrow?e.getArrowFill("start"):void 0})}else this.updateLineEndpoint(e,this.initialStartX+p,this.initialStartY+m,this.initialEndX,this.initialEndY),this._core.anchorManager.clearSnapCandidate()}else if("end"===w){const t=(i-this._core.store.state.translateX)/o,n=(s-this._core.store.state.translateY)/o,h=e.startAnchor?.objectId,l=this._core.anchorManager.findSnapTarget(t,n,e.id,h);if(this.currentSnapTarget=l,l){const t=this.worldToLineLocal(e,l.centerX,l.centerY);this.updateLineEndpoint(e,this.initialStartX,this.initialStartY,t.x,t.y);const i=this.lineLocalToWorld(e,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(e,"end",s);t&&(n=t.worldX,h=t.worldY,o=t.t)}void 0!==e.controlX&&void 0!==e.controlY&&(u=this.lineLocalToWorld(e,e.controlX,e.controlY)),this._core.anchorManager.setSnapCandidate({objectId:l.objectId,endpoint:"end",centerX:l.centerX,centerY:l.centerY,lineEndpointX:i.x,lineEndpointY:i.y,controlX:u?.x,controlY:u?.y,t:o,edgeX:n,edgeY:h,lineStroke:r.resolveThemeColor(e.stroke),lineStrokeWidth:e.strokeWidth/e.scale,arrowOffset:e.hasEndArrow?e.getArrowSize("end")/e.scale:void 0,arrowStyle:e.hasEndArrow?e.arrows?.end?.style:void 0,arrowFill:e.hasEndArrow?e.getArrowFill("end"):void 0})}else this.updateLineEndpoint(e,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,i=(this.initialControlY??(this.initialStartY+this.initialEndY)/2)+2*m,s=e.startX,r=e.startY,n=e.endX,h=e.endY,o=n-s,l=h-r,u=o*o+l*l;let f,a,c=-1;0!==u&&(c=((t-s)*o+(i-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=i-a;Math.sqrt(d*d+w*w)<15?e.updateControlPoint(void 0,void 0):e.updateControlPoint(t,i)}this._core.rerender()}worldToLineLocal(t,e,i){const s=(e-t.translateX)*t.scale,r=(i-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,e,i){const s=e-t.x,r=i-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,e,i,r,n){const{minX:h,minY:o,maxX:l,maxY:u}=s.calculateBoundingBox(e,i,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=e,t.startY=i,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(),e=this._core.store.state.lineHandleType;if(t&&this.hasMoved){!this.currentSnapTarget||"start"!==e&&"end"!==e||this._core.anchorManager.setAnchor(t.id,e,this.currentSnapTarget.objectId);const i=this._core.store.selectionGroup;i&&(i.refreshObjectDimensions(),i.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0)}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 e=t.objects[0];return e instanceof s?e: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 e=[];for(const i of t)Nn.isInstanceOf(i,"KritzelGroup")?e=e.concat(this.flattenObjects(i.children)):e.push(i);return e}get color(){const t=this.flattenObjects(this.getSelectedObjects());if(0===t.length)return n[0];for(const e of t){if(e instanceof i)return e.fill;if(e instanceof s)return e.stroke;if(e instanceof Dn)return e.fontColor;if(e instanceof jn)return e.strokeColor}return n[0]}set color(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof i&&this._core.updateObject(e,{fill:t}),e instanceof s&&this._core.updateObject(e,{stroke:t}),e instanceof Dn&&this._core.updateObject(e,{fontColor:t}),e instanceof jn&&this._core.updateObject(e,{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((e=>this._core.updateObject(e,{opacity:t}))),this._core.rerender()}get size(){const t=this.flattenObjects(this.getSelectedObjects());if(0===t.length)return 1;for(const e of t){if(e instanceof i)return e.strokeWidth;if(e instanceof s)return e.strokeWidth;if(e instanceof Dn)return e.fontSize;if(e instanceof jn)return e.strokeWidth}return 1}set size(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof i&&this._core.updateObject(e,{strokeWidth:t}),e instanceof s&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Dn&&this._core.updateObject(e,{fontSize:t}),e instanceof jn&&this._core.updateObject(e,{strokeWidth:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}get fillColor(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t)if(e instanceof jn)return e.fillColor;return{light:"transparent",dark:"transparent"}}set fillColor(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{if(e instanceof jn){const i=r.determineTextColor(t);this._core.updateObject(e,{fillColor:t,fontColor:i}),("string"==typeof t?"transparent"===t:"transparent"===t.light&&"transparent"===t.dark)||this._core.updateObject(e,{strokeColor:t})}})),this._core.rerender()}get fontFamily(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t){if(e instanceof Dn)return e.fontFamily;if(e instanceof jn)return e.fontFamily}return"Arial"}set fontFamily(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Dn&&this._core.updateObject(e,{fontFamily:t}),e instanceof jn&&this._core.updateObject(e,{fontFamily:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}get arrows(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t)if(e instanceof s)return e.arrows??{start:{enabled:!1},end:{enabled:!1}};return{start:{enabled:!1},end:{enabled:!1}}}set arrows(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof s&&this._core.updateObject(e,{arrows:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}getToolConfig(){if(!this.hasSelection())return null;const t=this.flattenObjects(this.getSelectedObjects()),e=[],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 i||t instanceof s||t instanceof jn));return!o||r||n||h||l?(n&&!l?(e.push({type:"font-size",propertyName:"size"}),e.push({type:"font-family",propertyName:"fontFamily"})):l&&!n?e.push({type:"stroke-size",propertyName:"size"}):(l&&e.push({type:"stroke-size",propertyName:"size"}),n&&e.push({type:"font-family",propertyName:"fontFamily"})),h&&e.push({type:"line-endings",propertyName:"arrows"}),r&&e.push({type:"shape-fill",propertyName:"fillColor"}),{type:"selection",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"palette",controls:e}):{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 e=this.getSelectedObject(t),i=this._core.store.selectionGroup;if(null!==e&&!(e&&i&&e.id!==i.id)||!i||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()),e&&!1===e.isSelected&&1===e?.objects.length&&e.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 e=this.getSelectedObject(t),i=this._core.store.selectionGroup,s=e&&i&&e.id!==i.id,r=t.shiftKey||t.ctrlKey;!i&&e&&(this._core.store.state.skipContextMenu=!0),null!==e&&!s||!i||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 e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=e?.id?this._core.findObjectById(e.id):null;if(!i)return null;const{x:s,y:r}=this._core.getCanvasPoint(t);if(!i.hitTest(s,r))return null;if(i instanceof Jn)return i;{const t=Jn.create(this._core);return t.translateX=0,t.translateY=0,t.addOrRemove(i),t}}getHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("resize-handle-overlay")));return i?.classList[1]}isHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("resize-handle-overlay")))}isRotationHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("rotation-handle-overlay")))}isLineHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("selection-line-handle-overlay")))}getLineHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("selection-line-handle-overlay")));return i?.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,Xn as f,Yn 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}
|