>>8^n[(i^s)&255]}return i=(i^-1)>>>0,i.toString(16).padStart(8,"0")}function KRe(t){const e=[{name:"address",isVoid:!1},{name:"article",isVoid:!1},{name:"aside",isVoid:!1},{name:"blockquote",isVoid:!1},{name:"details",isVoid:!1},{name:"dialog",isVoid:!1},{name:"dd",isVoid:!1},{name:"div",isVoid:!1},{name:"dl",isVoid:!1},{name:"dt",isVoid:!1},{name:"fieldset",isVoid:!1},{name:"figcaption",isVoid:!1},{name:"figure",isVoid:!1},{name:"footer",isVoid:!1},{name:"form",isVoid:!1},{name:"h1",isVoid:!1},{name:"h2",isVoid:!1},{name:"h3",isVoid:!1},{name:"h4",isVoid:!1},{name:"h5",isVoid:!1},{name:"h6",isVoid:!1},{name:"header",isVoid:!1},{name:"hgroup",isVoid:!1},{name:"hr",isVoid:!0},{name:"li",isVoid:!1},{name:"main",isVoid:!1},{name:"nav",isVoid:!1},{name:"ol",isVoid:!1},{name:"p",isVoid:!1},{name:"section",isVoid:!1},{name:"table",isVoid:!1},{name:"tbody",isVoid:!1},{name:"td",isVoid:!1},{name:"th",isVoid:!1},{name:"thead",isVoid:!1},{name:"tr",isVoid:!1},{name:"ul",isVoid:!1}],n=e.map(s=>s.name).join("|"),i=t.replace(new RegExp(`?(${n})( .*?)?>`,"g"),`
+$&
+`).replace(/
]*>/g,`$&
+`).split(`
+`);let r=0,o=!1;return i.map(s=>(o=XRe(s,o),!s.length&&!o?"":GRe(s,e)?ty(s,r++):YRe(s,e)?ty(s,--r):o==="middle"||o==="last"?ty(s,0):ty(s,r))).join("").trimEnd()}function GRe(t,e){return e.some(n=>!(n.isVoid||!new RegExp(`<${n.name}( .*?)?>`).test(t)))}function YRe(t,e){return e.some(n=>new RegExp(`${n.name}>`).test(t))}function ty(t,e,n=" "){return`${n.repeat(Math.max(0,e))}${t}
+`}function XRe(t,e){const n=//.test(t),i=/<\/pre>/.test(t);return n&&i?!1:n?"first":i?"last":e==="first"||e==="middle"?"middle":!1}function JRe(t){return!!t&&t.length==1&&/[\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f]/.test(t)}function ZRe(t){return!!t&&t.length==1&&/[\ud800-\udbff]/.test(t)}function QRe(t){return!!t&&t.length==1&&/[\udc00-\udfff]/.test(t)}function UM(t,e){return ZRe(t.charAt(e-1))&&QRe(t.charAt(e))}function WM(t,e){return JRe(t.charAt(e))}const eMe=tMe();function aG(t,e){const n=String(t).matchAll(eMe);return Array.from(n).some(i=>i.indexr.source).join("|")+")",i=`${e}|${n}(?:${n})*`;return new RegExp(i,"ug")}function g4(t){if(!t)return null;const e=nMe(t);return e?HM(e):null}function nMe(t){const e=t.split(".");return e.length!=3?null:e[1]}function iMe(t,e){return(t.removeFeatures||[]).includes(e)}const Fg=new WeakMap;let p4=!1;function qM({view:t,element:e,text:n,isDirectHost:i=!0,keepOnFocus:r=!1}){const o=t.document;Fg.has(o)||(Fg.set(o,new Map),o.registerPostFixer(a=>xT(Fg.get(o),a)),o.on("change:isComposing",()=>{t.change(a=>xT(Fg.get(o),a))},{priority:"high"})),e.is("editableElement")&&e.on("change:placeholder",(a,l,u)=>s(u)),e.placeholder?s(e.placeholder):n&&s(n),n&&lMe();function s(a){const l={text:a,isDirectHost:i,keepOnFocus:r,hostElement:i?e:null};Fg.get(o).set(e,l),t.change(u=>xT([[e,l]],u))}}function rMe(t,e){return e.hasClass("ck-placeholder")?!1:(t.addClass("ck-placeholder",e),!0)}function lG(t,e){return e.hasClass("ck-placeholder")?(t.removeClass("ck-placeholder",e),!0):!1}function oMe(t,e){if(!t.isAttached()||sMe(t))return!1;const n=t.document,r=n.selection.anchor;return n.isComposing&&r&&r.parent===t?!1:e||!n.isFocused?!0:!!r&&r.parent!==t}function sMe(t){for(const e of t.getChildren())if(!e.is("uiElement"))return!0;return!1}function xT(t,e){const n=[];let i=!1;for(const[r,o]of t)o.isDirectHost&&(n.push(r),v4(e,r,o)&&(i=!0));for(const[r,o]of t){if(o.isDirectHost)continue;const s=aMe(r);s!==o.hostElement&&o.hostElement&&(e.removeAttribute("data-placeholder",o.hostElement),lG(e,o.hostElement),o.hostElement=null,i=!0),s&&(n.includes(s)||(o.hostElement=s,v4(e,r,o)&&(i=!0)))}return i}function v4(t,e,n){const{text:i,isDirectHost:r,hostElement:o}=n;let s=!1;return o.getAttribute("data-placeholder")!==i&&(t.setAttribute("data-placeholder",i,o),s=!0),(r||e.childCount==1)&&oMe(o,n.keepOnFocus)?rMe(t,o)&&(s=!0):lG(t,o)&&(s=!0),s}function aMe(t){if(t.childCount){const e=t.getChild(0);if(e.is("element")&&!e.is("uiElement")&&!e.is("attributeElement"))return e}return null}function lMe(){p4||hn("enableViewPlaceholder-deprecated-text-option"),p4=!0}class $f{is(){throw new Error("is() method is abstract")}}class zf extends Fn($f){document;parent;constructor(e){super(),this.document=e,this.parent=null}get index(){let e;if(!this.parent)return null;if((e=this.parent.getChildIndex(this))==-1)throw new oe("view-node-not-found-in-parent",this);return e}get nextSibling(){const e=this.index;return e!==null&&this.parent.getChild(e+1)||null}get previousSibling(){const e=this.index;return e!==null&&this.parent.getChild(e-1)||null}get root(){let e=this;for(;e.parent;)e=e.parent;return e}isAttached(){return this.root.is("rootElement")}getPath(){const e=[];let n=this;for(;n.parent;)e.unshift(n.index),n=n.parent;return e}getAncestors(e={}){const n=[];let i=e.includeSelf?this:this.parent;for(;i;)n[e.parentFirst?"push":"unshift"](i),i=i.parent;return n}getCommonAncestor(e,n={}){const i=this.getAncestors(n),r=e.getAncestors(n);let o=0;for(;i[o]==r[o]&&i[o];)o++;return o===0?null:i[o-1]}isBefore(e){if(this==e||this.root!==e.root)return!1;const n=this.getPath(),i=e.getPath(),r=ur(n,i);switch(r){case"prefix":return!0;case"extension":return!1;default:return n[r]e.data.length)throw new oe("view-textproxy-wrong-offsetintext",this);if(i<0||n+i>e.data.length)throw new oe("view-textproxy-wrong-length",this);this.data=e.data.substring(n,n+i),this.offsetInText=n}get offsetSize(){return this.data.length}get isPartial(){return this.data.length!==this.textNode.data.length}get parent(){return this.textNode.parent}get root(){return this.textNode.root}get document(){return this.textNode.document}getAncestors(e={}){const n=[];let i=e.includeSelf?this.textNode:this.parent;for(;i!==null;)n[e.parentFirst?"push":"unshift"](i),i=i.parent;return n}}Wl.prototype.is=function(t){return t==="$textProxy"||t==="view:$textProxy"||t==="textProxy"||t==="view:textProxy"};class u1{_consumables=new Map;add(e,n){let i;if(e.is("$text")||e.is("documentFragment")){this._consumables.set(e,!0);return}this._consumables.has(e)?i=this._consumables.get(e):(i=new uMe(e),this._consumables.set(e,i)),i.add(n?wp(n):e._getConsumables())}test(e,n){const i=this._consumables.get(e);return i===void 0?null:e.is("$text")||e.is("documentFragment")?i:i.test(wp(n))}consume(e,n){if(e.is("$text")||e.is("documentFragment"))return this.test(e,n)?(this._consumables.set(e,!1),!0):!1;const i=this._consumables.get(e);return i===void 0?!1:i.consume(wp(n))}revert(e,n){const i=this._consumables.get(e);i!==void 0&&(e.is("$text")||e.is("documentFragment")?this._consumables.set(e,!0):i.revert(wp(n)))}static createFrom(e,n){if(n||(n=new u1),e.is("$text"))n.add(e);else if(e.is("element")||e.is("documentFragment")){n.add(e);for(const i of e.getChildren())u1.createFrom(i,n)}return n}}class uMe{element;_canConsumeName=null;_attributes=new Map;constructor(e){this.element=e}add(e){e.name&&(this._canConsumeName=!0);for(const[n,i]of e.attributes)if(i){let r=this._attributes.get(n);(!r||typeof r=="boolean")&&(r=new Map,this._attributes.set(n,r)),r.set(i,!0)}else{if(n=="style"||n=="class")throw new oe("viewconsumable-invalid-attribute",this);this._attributes.set(n,!0)}}test(e){if(e.name&&!this._canConsumeName)return this._canConsumeName;for(const[n,i]of e.attributes){const r=this._attributes.get(n);if(r===void 0)return null;if(r===!1)return!1;if(r!==!0){if(i){const o=r.get(i);if(o===void 0)return null;if(!o)return!1}else for(const o of r.values())if(!o)return!1}}return!0}consume(e){if(!this.test(e))return!1;e.name&&(this._canConsumeName=!1);for(const[n,i]of e.attributes){const r=this._attributes.get(n);if(typeof r=="boolean")for(const[o]of this.element._getConsumables(n,i).attributes)this._attributes.set(o,!1);else if(i)for(const[,o]of this.element._getConsumables(n,i).attributes)r.set(o,!1);else for(const o of r.keys())r.set(o,!1)}return!0}revert(e){e.name&&(this._canConsumeName=!0);for(const[n,i]of e.attributes){const r=this._attributes.get(n);if(r===!1){this._attributes.set(n,!0);continue}if(!(r===void 0||r===!0))if(i)r.get(i)===!1&&r.set(i,!0);else for(const o of r.keys())r.set(o,!0)}}}function wp(t){const e=[];return"attributes"in t&&t.attributes&&AT(e,t.attributes),"classes"in t&&t.classes&&AT(e,t.classes,"class"),"styles"in t&&t.styles&&AT(e,t.styles,"style"),{name:t.name||!1,attributes:e}}function AT(t,e,n){if(typeof e=="string"){t.push(n?[n,e]:[e]);return}for(const i of e)Array.isArray(i)?t.push(i):t.push(n?[n,i]:[i])}class pl{_patterns=[];constructor(...e){this.add(...e)}add(...e){for(let n of e)(typeof n=="string"||n instanceof RegExp)&&(n={name:n}),this._patterns.push(n)}match(...e){for(const n of e)for(const i of this._patterns){const r=this._isElementMatching(n,i);if(r)return{element:n,pattern:i,match:r}}return null}matchAll(...e){const n=[];for(const i of e)for(const r of this._patterns){const o=this._isElementMatching(i,r);o&&n.push({element:i,pattern:r,match:o})}return n.length>0?n:null}getElementName(){if(this._patterns.length!==1)return null;const e=this._patterns[0],n=e.name;return typeof e!="function"&&n&&!(n instanceof RegExp)?n:null}_isElementMatching(e,n){if(typeof n=="function"){const o=n(e);return!o||typeof o!="object"?o:wp(o)}const i={};if(n.name&&(i.name=cMe(n.name,e.name),!i.name))return null;const r=[];return n.attributes&&!dMe(n.attributes,e,r)||n.classes&&!fMe(n.classes,e,r)||n.styles&&!hMe(n.styles,e,r)?null:(r.length&&(i.attributes=r),i)}}function c1(t,e){return t===!0||t===e||t instanceof RegExp&&!!String(e).match(t)}function cMe(t,e){return t instanceof RegExp?!!e.match(t):t===e}function jM(t,e){if(Array.isArray(t))return t.map(i=>typeof i!="object"||i instanceof RegExp?e?[e,i,!0]:[i,!0]:((i.key===void 0||i.value===void 0)&&hn("matcher-pattern-missing-key-or-value",i),e?[e,i.key,i.value]:[i.key,i.value]));if(typeof t!="object"||t instanceof RegExp)return[e?[e,t,!0]:[t,!0]];const n=[];for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.push(e?[e,i,t[i]]:[i,t[i]]);return n}function dMe(t,e,n){let i;return typeof t=="object"&&!(t instanceof RegExp)&&!Array.isArray(t)?(t.style!==void 0&&hn("matcher-pattern-deprecated-attributes-style-key",t),t.class!==void 0&&hn("matcher-pattern-deprecated-attributes-class-key",t)):i=["class","style"],e._collectAttributesMatch(jM(t),n,i)}function fMe(t,e,n){return e._collectAttributesMatch(jM(t,"class"),n)}function hMe(t,e,n){return e._collectAttributesMatch(jM(t,"style"),n)}class tv{_styles;_cachedStyleNames=null;_cachedExpandedStyleNames=null;_styleProcessor;constructor(e){this._styles={},this._styleProcessor=e}get isEmpty(){return!Object.entries(this._styles).length}get size(){return this.isEmpty?0:this.getStyleNames().length}setTo(e){this.clear();const n=gMe(e);for(const[i,r]of n)this._styleProcessor.toNormalizedForm(i,r,this._styles);return this}has(e){if(this.isEmpty)return!1;const i=this._styleProcessor.getReducedForm(e,this._styles).find(([r])=>r===e);return Array.isArray(i)}set(e,n){if(this._cachedStyleNames=null,this._cachedExpandedStyleNames=null,so(e))for(const[i,r]of Object.entries(e))this._styleProcessor.toNormalizedForm(i,r,this._styles);else this._styleProcessor.toNormalizedForm(e,n,this._styles)}remove(e){const n={};for(const i of li(e)){const r=_A(i),o=Ic(this._styles,r);if(o)Jw(n,r,o);else{const s=this.getAsString(i);s!==void 0&&this._styleProcessor.toNormalizedForm(i,s,n)}}Object.keys(n).length&&(uG(this._styles,n),this._cachedStyleNames=null,this._cachedExpandedStyleNames=null)}getNormalized(e){return this._styleProcessor.getNormalized(e,this._styles)}toString(){return this.isEmpty?"":this.getStylesEntries().map(e=>e.join(":")).sort().join(";")+";"}getAsString(e){if(this.isEmpty)return;if(this._styles[e]&&!so(this._styles[e]))return this._styles[e];const i=this._styleProcessor.getReducedForm(e,this._styles).find(([r])=>r===e);if(Array.isArray(i))return i[1]}getStyleNames(e=!1){return this.isEmpty?[]:e?(this._cachedExpandedStyleNames||=this._styleProcessor.getStyleNames(this._styles),this._cachedExpandedStyleNames):(this._cachedStyleNames||=this.getStylesEntries().map(([n])=>n),this._cachedStyleNames)}keys(){return this.getStyleNames()}clear(){this._styles={},this._cachedStyleNames=null,this._cachedExpandedStyleNames=null}isSimilar(e){if(this.size!==e.size)return!1;for(const n of this.getStyleNames())if(!e.has(n)||e.getAsString(n)!==this.getAsString(n))return!1;return!0}getStylesEntries(){const e=[],n=Object.keys(this._styles);for(const i of n)e.push(...this._styleProcessor.getReducedForm(i,this._styles));return e}_clone(){const e=new this.constructor(this._styleProcessor);return e.set(this.getNormalized()),e}_getTokensMatch(e,n){const i=[];for(const r of this.getStyleNames(!0))if(c1(e,r)){if(n===!0){i.push(r);continue}const o=this.getAsString(r);c1(n,o)&&i.push(r)}return i.length?i:void 0}_getConsumables(e){const n=[];if(e){n.push(e);for(const i of this._styleProcessor.getRelatedStyles(e))n.push(i)}else for(const i of this.getStyleNames()){for(const r of this._styleProcessor.getRelatedStyles(i))n.push(r);n.push(i)}return n}_canMergeFrom(e){for(const n of e.getStyleNames())if(this.has(n)&&this.getAsString(n)!==e.getAsString(n))return!1;return!0}_mergeFrom(e){for(const n of e.getStyleNames())this.has(n)||this.set(n,e.getAsString(n))}_isMatching(e){for(const n of e.getStyleNames())if(!this.has(n)||this.getAsString(n)!==e.getAsString(n))return!1;return!0}}class mMe{_normalizers;_extractors;_reducers;_consumables;constructor(){this._normalizers=new Map,this._extractors=new Map,this._reducers=new Map,this._consumables=new Map}toNormalizedForm(e,n,i){if(so(n)){Jw(i,_A(e),n);return}if(this._normalizers.has(e)){const r=this._normalizers.get(e),{path:o,value:s}=r(n);Jw(i,o,s)}else Jw(i,e,n)}getNormalized(e,n){if(!e)return DM({},n);if(n[e]!==void 0)return n[e];if(this._extractors.has(e)){const i=this._extractors.get(e);if(typeof i=="string")return Ic(n,i);const r=i(e,n);if(r)return r}return Ic(n,_A(e))}getReducedForm(e,n){const i=this.getNormalized(e,n);return i===void 0?[]:this._reducers.has(e)?this._reducers.get(e)(i):[[e,i]]}getStyleNames(e){const n=new Set;for(const i of this._consumables.keys()){const r=this.getNormalized(i,e);r&&(typeof r!="object"||Object.keys(r).length)&&n.add(i)}for(const i of Object.keys(e))n.add(i);return Array.from(n)}getRelatedStyles(e){return this._consumables.get(e)||[]}setNormalizer(e,n){this._normalizers.set(e,n)}setExtractor(e,n){this._extractors.set(e,n)}setReducer(e,n){this._reducers.set(e,n)}setStyleRelation(e,n){this._mapStyleNames(e,n);for(const i of n)this._mapStyleNames(i,[e])}_mapStyleNames(e,n){this._consumables.has(e)||this._consumables.set(e,[]),this._consumables.get(e).push(...n)}}function gMe(t){let e=null,n=0,i=0,r=null;const o=new Map;if(t==="")return o;t.charAt(t.length-1)!=";"&&(t=t+";");for(let s=0;sr!="style"&&r!="class").map(r=>`${r[0]}="${r[1]}"`).sort().join(" ");return this.name+(e==""?"":` class="${e}"`)+(n?` style="${n}"`:"")+(i==""?"":` ${i}`)}shouldRenderUnsafeAttribute(e){return this._unsafeAttributesToRender.includes(e)}toJSON(){const e=super.toJSON();if(e.name=this.name,e.type="Element",this._attrs.size&&(e.attributes=Object.fromEntries(this.getAttributes())),this._children.length>0){e.children=[];for(const n of this._children)e.children.push(n.toJSON())}return e}_clone(e=!1){const n=[];if(e)for(const r of this.getChildren())n.push(r._clone(e));const i=new this.constructor(this.document,this.name,this._attrs,n);return i._customProperties=new Map(this._customProperties),i.getFillerOffset=this.getFillerOffset,i._unsafeAttributesToRender=this._unsafeAttributesToRender,i}_appendChild(e){return this._insertChild(this.childCount,e)}_insertChild(e,n){this._fireChange("children",this,{index:e});let i=0;const r=pMe(this.document,n);for(const o of r)o.parent!==null&&o._remove(),o.parent=this,o.document=this.document,this._children.splice(e,0,o),e++,i++;return i}_removeChildren(e,n=1){this._fireChange("children",this,{index:e});for(let i=e;io&&e.selection.editableElement==this),this.listenTo(e.selection,"change",()=>{this.isFocused=e.isFocused&&e.selection.editableElement==this})}destroy(){this.stopListening()}toJSON(){const e=super.toJSON();return e.type="EditableElement",e.isReadOnly=this.isReadOnly,e.isFocused=this.isFocused,e}}hS.prototype.is=function(t,e){return e?e===this.name&&(t==="editableElement"||t==="view:editableElement"||t==="containerElement"||t==="view:containerElement"||t==="element"||t==="view:element"):t==="editableElement"||t==="view:editableElement"||t==="containerElement"||t==="view:containerElement"||t==="element"||t==="view:element"||t==="node"||t==="view:node"};const b4=Symbol("rootName");class cG extends hS{constructor(e,n){super(e,n),this.rootName="main"}get rootName(){return this.getCustomProperty(b4)}set rootName(e){this._setCustomProperty(b4,e)}toJSON(){return this.rootName}set _name(e){this.name=e}}cG.prototype.is=function(t,e){return e?e===this.name&&(t==="rootElement"||t==="view:rootElement"||t==="editableElement"||t==="view:editableElement"||t==="containerElement"||t==="view:containerElement"||t==="element"||t==="view:element"):t==="rootElement"||t==="view:rootElement"||t==="editableElement"||t==="view:editableElement"||t==="containerElement"||t==="view:containerElement"||t==="element"||t==="view:element"||t==="node"||t==="view:node"};class Xd{direction;boundaries;singleCharacters;shallow;ignoreElementEnd;_position;_boundaryStartParent;_boundaryEndParent;constructor(e={}){if(!e.boundaries&&!e.startPosition)throw new oe("view-tree-walker-no-start-position",null);if(e.direction&&e.direction!="forward"&&e.direction!="backward")throw new oe("view-tree-walker-unknown-direction",e.startPosition,{direction:e.direction});this.boundaries=e.boundaries||null,e.startPosition?this._position=Ge._createAt(e.startPosition):this._position=Ge._createAt(e.boundaries[e.direction=="backward"?"end":"start"]),this.direction=e.direction||"forward",this.singleCharacters=!!e.singleCharacters,this.shallow=!!e.shallow,this.ignoreElementEnd=!!e.ignoreElementEnd,this._boundaryStartParent=this.boundaries?this.boundaries.start.parent:null,this._boundaryEndParent=this.boundaries?this.boundaries.end.parent:null}[Symbol.iterator](){return this}get position(){return this._position}skip(e){let n,i;do i=this.position,n=this.next();while(!n.done&&e(n.value));n.done||(this._position=i)}jumpTo(e){this._boundaryStartParent&&e.isBefore(this.boundaries.start)?e=this.boundaries.start:this._boundaryEndParent&&e.isAfter(this.boundaries.end)&&(e=this.boundaries.end),this._position=e.clone()}next(){return this.direction=="forward"?this._next():this._previous()}_next(){let e=this.position.clone();const n=this.position,i=e.parent;if(i.parent===null&&e.offset===i.childCount)return{done:!0,value:void 0};if(i===this._boundaryEndParent&&e.offset==this.boundaries.end.offset)return{done:!0,value:void 0};let r;if(i&&i.is("view:$text")){if(e.isAtEnd)return this._position=Ge._createAfter(i),this._next();r=i.data[e.offset]}else r=i.getChild(e.offset);if(typeof r=="string"){let o;this.singleCharacters?o=1:o=(i===this._boundaryEndParent?this.boundaries.end.offset:i.data.length)-e.offset;const s=new Wl(i,e.offset,o);return e.offset+=o,this._position=e,this._formatReturnValue("text",s,n,e,o)}if(r&&r.is("view:element")){if(!this.shallow)e=new Ge(r,0);else{if(this.boundaries&&this.boundaries.end.isBefore(e))return{done:!0,value:void 0};e.offset++}return this._position=e,this._formatReturnValue("elementStart",r,n,e,1)}if(r&&r.is("view:$text")){if(this.singleCharacters)return e=new Ge(r,0),this._position=e,this._next();let o=r.data.length,s;return r==this._boundaryEndParent?(o=this.boundaries.end.offset,s=new Wl(r,0,o),e=Ge._createAfter(s)):(s=new Wl(r,0,r.data.length),e.offset++),this._position=e,this._formatReturnValue("text",s,n,e,o)}return e=Ge._createAfter(i),this._position=e,this.ignoreElementEnd?this._next():this._formatReturnValue("elementEnd",i,n,e)}_previous(){let e=this.position.clone();const n=this.position,i=e.parent;if(i.parent===null&&e.offset===0)return{done:!0,value:void 0};if(i==this._boundaryStartParent&&e.offset==this.boundaries.start.offset)return{done:!0,value:void 0};let r;if(i.is("view:$text")){if(e.isAtStart)return this._position=Ge._createBefore(i),this._previous();r=i.data[e.offset-1]}else r=i.getChild(e.offset-1);if(typeof r=="string"){let o;if(this.singleCharacters)o=1;else{const a=i===this._boundaryStartParent?this.boundaries.start.offset:0;o=e.offset-a}e.offset-=o;const s=new Wl(i,e.offset,o);return this._position=e,this._formatReturnValue("text",s,n,e,o)}if(r&&r.is("view:element"))return this.shallow?(e.offset--,this._position=e,this._formatReturnValue("elementStart",r,n,e,1)):(e=new Ge(r,r.childCount),this._position=e,this.ignoreElementEnd?this._previous():this._formatReturnValue("elementEnd",r,n,e));if(r&&r.is("view:$text")){if(this.singleCharacters)return e=new Ge(r,r.data.length),this._position=e,this._previous();let o=r.data.length,s;if(r==this._boundaryStartParent){const a=this.boundaries.start.offset;s=new Wl(r,a,r.data.length-a),o=s.data.length,e=Ge._createBefore(s)}else s=new Wl(r,0,r.data.length),e.offset--;return this._position=e,this._formatReturnValue("text",s,n,e,o)}return e=Ge._createBefore(i),this._position=e,this._formatReturnValue("elementStart",i,n,e,1)}_formatReturnValue(e,n,i,r,o){return n.is("view:$textProxy")&&(n.offsetInText+n.data.length==n.textNode.data.length&&(this.direction=="forward"&&!(this.boundaries&&this.boundaries.end.isEqual(this.position))?(r=Ge._createAfter(n.textNode),this._position=r):i=Ge._createAfter(n.textNode)),n.offsetInText===0&&(this.direction=="backward"&&!(this.boundaries&&this.boundaries.start.isEqual(this.position))?(r=Ge._createBefore(n.textNode),this._position=r):i=Ge._createBefore(n.textNode))),{done:!1,value:{type:e,item:n,previousPosition:i,nextPosition:r,length:o}}}}class Ge extends $f{parent;offset;constructor(e,n){super(),this.parent=e,this.offset=n}get nodeAfter(){return this.parent.is("$text")?null:this.parent.getChild(this.offset)||null}get nodeBefore(){return this.parent.is("$text")?null:this.parent.getChild(this.offset-1)||null}get isAtStart(){return this.offset===0}get isAtEnd(){const e=this.parent.is("$text")?this.parent.data.length:this.parent.childCount;return this.offset===e}get root(){return this.parent.root}get editableElement(){let e=this.parent;for(;!(e instanceof hS);)if(e.parent)e=e.parent;else return null;return e}getShiftedBy(e){const n=Ge._createAt(this),i=n.offset+e;return n.offset=i<0?0:i,n}getLastMatchingPosition(e,n={}){n.startPosition=this;const i=new Xd(n);return i.skip(e),i.position}getAncestors(){return this.parent.is("documentFragment")?[this.parent]:this.parent.getAncestors({includeSelf:!0})}getCommonAncestor(e){const n=this.getAncestors(),i=e.getAncestors();let r=0;for(;n[r]==i[r]&&n[r];)r++;return r===0?null:n[r-1]}isEqual(e){return this.parent==e.parent&&this.offset==e.offset}isBefore(e){return this.compareWith(e)=="before"}isAfter(e){return this.compareWith(e)=="after"}compareWith(e){if(this.root!==e.root)return"different";if(this.isEqual(e))return"same";const n=this.parent.is("node")?this.parent.getPath():[],i=e.parent.is("node")?e.parent.getPath():[];n.push(this.offset),i.push(e.offset);const r=ur(n,i);switch(r){case"prefix":return"before";case"extension":return"after";default:return n[r]0?new this(i,r):new this(r,i)}static _createIn(e){return this._createFromParentsAndOffsets(e,0,e,e.childCount)}static _createOn(e){const n=e.is("$textProxy")?e.offsetSize:1;return this._createFromPositionAndShift(Ge._createBefore(e),n)}}Nt.prototype.is=function(t){return t==="range"||t==="view:range"};function ny(t){return!!(t.item.is("attributeElement")||t.item.is("uiElement"))}class aa extends Fn($f){_ranges;_lastRangeBackward;_isFake;_fakeSelectionLabel;constructor(...e){super(),this._ranges=[],this._lastRangeBackward=!1,this._isFake=!1,this._fakeSelectionLabel="",e.length&&this.setTo(...e)}get isFake(){return this._isFake}get fakeSelectionLabel(){return this._fakeSelectionLabel}get anchor(){if(!this._ranges.length)return null;const e=this._ranges[this._ranges.length-1];return(this._lastRangeBackward?e.end:e.start).clone()}get focus(){if(!this._ranges.length)return null;const e=this._ranges[this._ranges.length-1];return(this._lastRangeBackward?e.start:e.end).clone()}get isCollapsed(){return this.rangeCount===1&&this._ranges[0].isCollapsed}get rangeCount(){return this._ranges.length}get isBackward(){return!this.isCollapsed&&this._lastRangeBackward}get editableElement(){return this.anchor?this.anchor.editableElement:null}*getRanges(){for(const e of this._ranges)yield e.clone()}getFirstRange(){let e=null;for(const n of this._ranges)(!e||n.start.isBefore(e.start))&&(e=n);return e?e.clone():null}getLastRange(){let e=null;for(const n of this._ranges)(!e||n.end.isAfter(e.end))&&(e=n);return e?e.clone():null}getFirstPosition(){const e=this.getFirstRange();return e?e.start.clone():null}getLastPosition(){const e=this.getLastRange();return e?e.end.clone():null}isEqual(e){if(this.isFake!=e.isFake||this.isFake&&this.fakeSelectionLabel!=e.fakeSelectionLabel||this.rangeCount!=e.rangeCount)return!1;if(this.rangeCount===0)return!0;if(!this.anchor.isEqual(e.anchor)||!this.focus.isEqual(e.focus))return!1;for(const n of this._ranges){let i=!1;for(const r of e._ranges)if(n.isEqual(r)){i=!0;break}if(!i)return!1}return!0}isSimilar(e){if(this.isBackward!=e.isBackward)return!1;const n=yA(this.getRanges()),i=yA(e.getRanges());if(n!=i)return!1;if(n==0)return!0;for(let r of this.getRanges()){r=r.getTrimmed();let o=!1;for(let s of e.getRanges())if(s=s.getTrimmed(),r.start.isEqual(s.start)&&r.end.isEqual(s.end)){o=!0;break}if(!o)return!1}return!0}getSelectedElement(){return this.rangeCount!==1?null:this.getFirstRange().getContainedElement()}setTo(...e){let[n,i,r]=e;if(typeof i=="object"&&(r=i,i=void 0),n===null)this._setRanges([]),this._setFakeOptions(r);else if(n instanceof aa||n instanceof KM)this._setRanges(n.getRanges(),n.isBackward),this._setFakeOptions({fake:n.isFake,label:n.fakeSelectionLabel});else if(n instanceof Nt)this._setRanges([n],r&&r.backward),this._setFakeOptions(r);else if(n instanceof Ge)this._setRanges([new Nt(n)]),this._setFakeOptions(r);else if(n instanceof zf){const o=!!r&&!!r.backward;let s;if(i===void 0)throw new oe("view-selection-setto-required-second-parameter",this);i=="in"?s=Nt._createIn(n):i=="on"?s=Nt._createOn(n):s=new Nt(Ge._createAt(n,i)),this._setRanges([s],o),this._setFakeOptions(r)}else if(us(n))this._setRanges(n,r&&r.backward),this._setFakeOptions(r);else throw new oe("view-selection-setto-not-selectable",this);this.fire("change")}setFocus(e,n){if(this.anchor===null)throw new oe("view-selection-setfocus-no-ranges",this);const i=Ge._createAt(e,n);if(i.compareWith(this.focus)=="same")return;const r=this.anchor;this._ranges.pop(),i.compareWith(r)=="before"?this._addRange(new Nt(i,r),!0):this._addRange(new Nt(r,i)),this.fire("change")}toJSON(){const e={ranges:Array.from(this.getRanges()).map(n=>n.toJSON())};return this.isBackward&&(e.isBackward=!0),this.isFake&&(e.isFake=!0),e}_setRanges(e,n=!1){e=Array.from(e),this._ranges=[];for(const i of e)this._addRange(i);this._lastRangeBackward=!!n}_setFakeOptions(e={}){this._isFake=!!e.fake,this._fakeSelectionLabel=e.fake&&e.label||""}_addRange(e,n=!1){if(!(e instanceof Nt))throw new oe("view-selection-add-range-not-range",this);this._pushRange(e),this._lastRangeBackward=!!n}_pushRange(e){for(const n of this._ranges)if(e.isIntersecting(n))throw new oe("view-selection-range-intersects",this,{addedRange:e,intersectingRange:n});this._ranges.push(new Nt(e.start,e.end))}}aa.prototype.is=function(t){return t==="selection"||t==="view:selection"};class KM extends Fn($f){_selection;constructor(...e){super(),this._selection=new aa,this._selection.delegate("change").to(this),e.length&&this._selection.setTo(...e)}get isFake(){return this._selection.isFake}get fakeSelectionLabel(){return this._selection.fakeSelectionLabel}get anchor(){return this._selection.anchor}get focus(){return this._selection.focus}get isCollapsed(){return this._selection.isCollapsed}get rangeCount(){return this._selection.rangeCount}get isBackward(){return this._selection.isBackward}get editableElement(){return this._selection.editableElement}get _ranges(){return this._selection._ranges}*getRanges(){yield*this._selection.getRanges()}getFirstRange(){return this._selection.getFirstRange()}getLastRange(){return this._selection.getLastRange()}getFirstPosition(){return this._selection.getFirstPosition()}getLastPosition(){return this._selection.getLastPosition()}getSelectedElement(){return this._selection.getSelectedElement()}isEqual(e){return this._selection.isEqual(e)}isSimilar(e){return this._selection.isSimilar(e)}toJSON(){return this._selection.toJSON()}_setTo(...e){this._selection.setTo(...e)}_setFocus(e,n){this._selection.setFocus(e,n)}}KM.prototype.is=function(t){return t==="selection"||t=="documentSelection"||t=="view:selection"||t=="view:documentSelection"};class Hf extends pu{startRange;_eventPhase;_currentTarget;constructor(e,n,i){super(e,n),this.startRange=i,this._eventPhase="none",this._currentTarget=null}get eventPhase(){return this._eventPhase}get currentTarget(){return this._currentTarget}}const IT=Symbol("bubblingEmitter"),RT=Symbol("bubblingCallbacks"),MT=Symbol("bubblingContexts");function bMe(t){class e extends t{fire(i,...r){try{const o=i instanceof pu?i:new pu(this,i),s=OT(this),a=w4(this);if(zg(o,"capturing",this),iy(s,"$capture",o,...r))return o.return;const l=o.startRange||this.selection.getFirstRange(),u=l?l.getContainedElement():null,c=u?wMe(a,u):!1;let d=u||_Me(l);if(zg(o,"atTarget",d),!c){if(iy(s,"$text",o,...r))return o.return;zg(o,"bubbling",d)}for(;d;){if(d.is("element")&&iy(s,d,o,...r))return o.return;d=d.parent,zg(o,"bubbling",d)}return zg(o,"bubbling",this),iy(s,"$document",o,...r),o.return}catch(o){oe.rethrowUnexpectedError(o,this)}}_addEventListener(i,r,o){const s=li(o.context||"$document"),a=OT(this),l=y4(this);for(const c of s)typeof c=="function"&&w4(this).add(c);const u=yMe(this,s,r);l.set(r,u),this.listenTo(a,i,u,o)}_removeEventListener(i,r){const o=OT(this),s=y4(this),a=s.get(r);a&&(s.delete(r),this.stopListening(o,i,a))}}return e}function zg(t,e,n){t instanceof Hf&&(t._eventPhase=e,t._currentTarget=n)}function iy(t,e,n,...i){return t.fire(n,{currentTarget:e,eventArgs:i}),!!n.stop.called}function yMe(t,e,n){return function(i,r){const{currentTarget:o,eventArgs:s}=r;if(typeof o=="string"){e.includes(o)&&n.call(t,i,...s);return}if(o.is("rootElement")&&e.includes("$root")){n.call(t,i,...s);return}if(e.includes(o.name)){n.call(t,i,...s);return}for(const a of e)if(typeof a=="function"&&a(o)){n.call(t,i,...s);return}}}function OT(t){return t[IT]||(t[IT]=new(Fn())),t[IT]}function y4(t){return t[RT]||(t[RT]=new Map),t[RT]}function w4(t){return t[MT]||(t[MT]=new Set),t[MT]}function wMe(t,e){for(const n of t)if(n(e))return!0;return!1}function _Me(t){if(!t)return null;const e=t.start.parent,n=t.end.parent,i=e.getPath(),r=n.getPath();return i.length>r.length?e:n}class mS extends bMe(Ln()){selection;roots;stylesProcessor;_postFixers=new Set;constructor(e){super(),this.selection=new KM,this.roots=new Er({idProperty:"rootName"}),this.stylesProcessor=e,this.set("isReadOnly",!1),this.set("isFocused",!1),this.set("isSelecting",!1),this.set("isComposing",!1)}getRoot(e="main"){return this.roots.get(e)}registerPostFixer(e){this._postFixers.add(e)}destroy(){this.roots.forEach(e=>e.destroy()),this.stopListening()}_callPostFixers(e){let n=!1;do for(const i of this._postFixers)if(n=i(e),n)break;while(n)}}const _4=10;class hm extends ga{static DEFAULT_PRIORITY=_4;_priority=_4;_id=null;_clonesGroup=null;constructor(e,n,i,r){super(e,n,i,r),this.getFillerOffset=CMe}get priority(){return this._priority}get id(){return this._id}getElementsWithSameId(){if(this.id===null)throw new oe("attribute-element-get-elements-with-same-id-no-id",this);return new Set(this._clonesGroup)}isSimilar(e){return this.id!==null||e.id!==null?this.id===e.id:super.isSimilar(e)&&this.priority==e.priority}toJSON(){const e=super.toJSON();return e.type="AttributeElement",e}_clone(e=!1){const n=super._clone(e);return n._priority=this._priority,n._id=this._id,n}_canMergeAttributesFrom(e){return this.id!==null||e.id!==null||this.priority!==e.priority?!1:super._canMergeAttributesFrom(e)}_canSubtractAttributesOf(e){return this.id!==null||e.id!==null||this.priority!==e.priority?!1:super._canSubtractAttributesOf(e)}}hm.prototype.is=function(t,e){return e?e===this.name&&(t==="attributeElement"||t==="view:attributeElement"||t==="element"||t==="view:element"):t==="attributeElement"||t==="view:attributeElement"||t==="element"||t==="view:element"||t==="node"||t==="view:node"};function CMe(){if(LT(this))return null;let t=this.parent;for(;t&&t.is("attributeElement");){if(LT(t)>1)return null;t=t.parent}return!t||LT(t)>1?null:this.childCount}function LT(t){return Array.from(t.getChildren()).filter(e=>!e.is("uiElement")).length}class GM extends ga{constructor(e,n,i,r){super(e,n,i,r),this.getFillerOffset=SMe}toJSON(){const e=super.toJSON();return e.type="EmptyElement",e}_insertChild(e,n){if(n&&(n instanceof zf||Array.from(n).length>0))throw new oe("view-emptyelement-cannot-add",[this,n]);return 0}}GM.prototype.is=function(t,e){return e?e===this.name&&(t==="emptyElement"||t==="view:emptyElement"||t==="element"||t==="view:element"):t==="emptyElement"||t==="view:emptyElement"||t==="element"||t==="view:element"||t==="node"||t==="view:node"};function SMe(){return null}class gS extends ga{constructor(e,n,i,r){super(e,n,i,r),this.getFillerOffset=TMe}_insertChild(e,n){if(n&&(n instanceof zf||Array.from(n).length>0))throw new oe("view-uielement-cannot-add",[this,n]);return 0}render(e,n){return this.toDomElement(e)}toDomElement(e){const n=e.createElement(this.name);for(const i of this.getAttributeKeys())n.setAttribute(i,this.getAttribute(i));return n}toJSON(){const e=super.toJSON();return e.type="UIElement",e}}gS.prototype.is=function(t,e){return e?e===this.name&&(t==="uiElement"||t==="view:uiElement"||t==="element"||t==="view:element"):t==="uiElement"||t==="view:uiElement"||t==="element"||t==="view:element"||t==="node"||t==="view:node"};function kMe(t){t.document.on("arrowKey",(e,n)=>EMe(e,n,t.domConverter),{priority:"low"})}function TMe(){return null}function EMe(t,e,n){if(e.keyCode==Yt.arrowright){const i=e.domTarget.ownerDocument.defaultView.getSelection(),r=i.rangeCount==1&&i.getRangeAt(0).collapsed;if(r||e.shiftKey){const o=i.focusNode,s=i.focusOffset,a=n.domPositionToView(o,s);if(a===null)return;let l=!1;const u=a.getLastMatchingPosition(c=>(c.item.is("uiElement")&&(l=!0),!!(c.item.is("uiElement")||c.item.is("attributeElement"))));if(l){const c=n.viewPositionToDom(u);r?i.collapse(c.parent,c.offset):i.extend(c.parent,c.offset)}}}}class YM extends ga{constructor(e,n,i,r){super(e,n,i,r),this.getFillerOffset=xMe}toJSON(){const e=super.toJSON();return e.type="RawElement",e}_insertChild(e,n){if(n&&(n instanceof zf||Array.from(n).length>0))throw new oe("view-rawelement-cannot-add",[this,n]);return 0}render(e,n){}}YM.prototype.is=function(t,e){return e?e===this.name&&(t==="rawElement"||t==="view:rawElement"||t==="element"||t==="view:element"):t==="rawElement"||t==="view:rawElement"||t===this.name||t==="view:"+this.name||t==="element"||t==="view:element"||t==="node"||t==="view:node"};function xMe(){return null}class af extends Fn($f){document;_children=[];_customProperties=new Map;constructor(e,n){super(),this.document=e,n&&this._insertChild(0,n)}[Symbol.iterator](){return this._children[Symbol.iterator]()}get childCount(){return this._children.length}get isEmpty(){return this.childCount===0}get root(){return this}get parent(){return null}get name(){}get getFillerOffset(){}getCustomProperty(e){return this._customProperties.get(e)}*getCustomProperties(){yield*this._customProperties.entries()}toJSON(){const e=[];for(const n of this._children)e.push(n.toJSON());return e}_appendChild(e){return this._insertChild(this.childCount,e)}getChild(e){return this._children[e]}getChildIndex(e){return this._children.indexOf(e)}getChildren(){return this._children[Symbol.iterator]()}_insertChild(e,n){this._fireChange("children",this,{index:e});let i=0;const r=AMe(this.document,n);for(const o of r)o.parent!==null&&o._remove(),o.parent=this,this._children.splice(e,0,o),e++,i++;return i}_removeChildren(e,n=1){this._fireChange("children",this,{index:e});for(let i=e;itypeof n=="string"?new Ji(t,n):n instanceof Wl?new Ji(t,n.data):n))}class dG{document;_cloneGroups=new Map;_slotFactory=null;constructor(e){this.document=e}setSelection(...e){this.document.selection._setTo(...e)}setSelectionFocus(e,n){this.document.selection._setFocus(e,n)}createDocumentFragment(e){return new af(this.document,e)}createText(e){return new Ji(this.document,e)}createAttributeElement(e,n,i={}){const r=new hm(this.document,e,n);return typeof i.priority=="number"&&(r._priority=i.priority),i.id&&(r._id=i.id),i.renderUnsafeAttributes&&r._unsafeAttributesToRender.push(...i.renderUnsafeAttributes),r}createContainerElement(e,n,i={},r={}){let o;MMe(i)?r=i:o=i;const s=new nb(this.document,e,n,o);return r.renderUnsafeAttributes&&s._unsafeAttributesToRender.push(...r.renderUnsafeAttributes),s}createEditableElement(e,n,i={}){const r=new hS(this.document,e,n);return i.renderUnsafeAttributes&&r._unsafeAttributesToRender.push(...i.renderUnsafeAttributes),r}createEmptyElement(e,n,i={}){const r=new GM(this.document,e,n);return i.renderUnsafeAttributes&&r._unsafeAttributesToRender.push(...i.renderUnsafeAttributes),r}createUIElement(e,n,i){const r=new gS(this.document,e,n);return i&&(r.render=i),r}createRawElement(e,n,i,r={}){const o=new YM(this.document,e,n);return i&&(o.render=i),r.renderUnsafeAttributes&&o._unsafeAttributesToRender.push(...r.renderUnsafeAttributes),o}setAttribute(e,n,i,r){r!==void 0?r._setAttribute(e,n,i):i._setAttribute(e,n)}removeAttribute(e,n,i){i!==void 0?i._removeAttribute(e,n):n._removeAttribute(e)}addClass(e,n){n._addClass(e)}removeClass(e,n){n._removeClass(e)}setStyle(e,n,i){Wa(e)&&i===void 0?n._setStyle(e):i._setStyle(e,n)}removeStyle(e,n){n._removeStyle(e)}setCustomProperty(e,n,i){i._setCustomProperty(e,n)}removeCustomProperty(e,n){return n._removeCustomProperty(e)}breakAttributes(e){return e instanceof Ge?this._breakAttributes(e):this._breakAttributesRange(e)}breakContainer(e){const n=e.parent;if(!n.is("containerElement"))throw new oe("view-writer-break-non-container-element",this.document);if(!n.parent)throw new oe("view-writer-break-root",this.document);if(e.isAtStart)return Ge._createBefore(n);if(!e.isAtEnd){const i=n._clone(!1);this.insert(Ge._createAfter(n),i);const r=new Nt(e,Ge._createAt(n,"end")),o=new Ge(i,0);this.move(r,o)}return Ge._createAfter(n)}mergeAttributes(e){const n=e.offset,i=e.parent;if(i.is("$text"))return e;if(i.is("attributeElement")&&i.childCount===0){const s=i.parent,a=i.index;return i._remove(),this._removeFromClonedElementsGroup(i),this.mergeAttributes(new Ge(s,a))}const r=i.getChild(n-1),o=i.getChild(n);if(!r||!o)return e;if(r.is("$text")&&o.is("$text"))return S4(r,o);if(r.is("attributeElement")&&o.is("attributeElement")&&r.isSimilar(o)){const s=r.childCount;return r._appendChild(o.getChildren()),o._remove(),this._removeFromClonedElementsGroup(o),this.mergeAttributes(new Ge(r,s))}return e}mergeContainers(e){const n=e.nodeBefore,i=e.nodeAfter;if(!n||!i||!n.is("containerElement")||!i.is("containerElement"))throw new oe("view-writer-merge-containers-invalid-position",this.document);const r=n.getChild(n.childCount-1),o=r instanceof Ji?Ge._createAt(r,"end"):Ge._createAt(n,"end");return this.move(Nt._createIn(i),Ge._createAt(n,"end")),this.remove(Nt._createOn(i)),o}insert(e,n){n=us(n)?[...n]:[n],fG(n,this.document);const i=n.reduce((s,a)=>{const l=s[s.length-1],u=!a.is("uiElement");return!l||l.breakAttributes!=u?s.push({breakAttributes:u,nodes:[a]}):l.nodes.push(a),s},[]);let r=null,o=e;for(const{nodes:s,breakAttributes:a}of i){const l=this._insertNodes(o,s,a);r||(r=l.start),o=l.end}return r?new Nt(r,o):new Nt(e)}remove(e){const n=e instanceof Nt?e:Nt._createOn(e);if(Hg(n,this.document),n.isCollapsed)return new af(this.document);const{start:i,end:r}=this._breakAttributesRange(n,!0),o=i.parent,s=r.offset-i.offset,a=o._removeChildren(i.offset,s);for(const u of a)this._removeFromClonedElementsGroup(u);const l=this.mergeAttributes(i);return n.start=l,n.end=l.clone(),new af(this.document,a)}clear(e,n){Hg(e,this.document);const i=e.getWalker({direction:"backward",ignoreElementEnd:!0});for(const r of i){const o=r.item;let s;if(o.is("element")&&n.isSimilar(o))s=Nt._createOn(o);else if(!r.nextPosition.isAfter(e.start)&&o.is("$textProxy")){const a=o.getAncestors().find(l=>l.is("element")&&n.isSimilar(l));a&&(s=Nt._createIn(a))}s&&(s.end.isAfter(e.end)&&(s.end=e.end),s.start.isBefore(e.start)&&(s.start=e.start),this.remove(s))}}move(e,n){let i;if(n.isAfter(e.end)){n=this._breakAttributes(n,!0);const r=n.parent,o=r.childCount;e=this._breakAttributesRange(e,!0),i=this.remove(e),n.offset+=r.childCount-o}else i=this.remove(e);return this.insert(n,i)}wrap(e,n){if(!(n instanceof hm))throw new oe("view-writer-wrap-invalid-attribute",this.document);if(Hg(e,this.document),e.isCollapsed){let i=e.start;i.parent.is("element")&&!PMe(i.parent)&&(i=i.getLastMatchingPosition(o=>o.item.is("uiElement"))),i=this._wrapPosition(i,n);const r=this.document.selection;return r.isCollapsed&&r.getFirstPosition().isEqual(e.start)&&this.setSelection(i),new Nt(i)}else return this._wrapRange(e,n)}unwrap(e,n){if(!(n instanceof hm))throw new oe("view-writer-unwrap-invalid-attribute",this.document);if(Hg(e,this.document),e.isCollapsed)return e;const{start:i,end:r}=this._breakAttributesRange(e,!0),o=i.parent,s=this._unwrapChildren(o,i.offset,r.offset,n),a=this.mergeAttributes(s.start);a.isEqual(s.start)||s.end.offset--;const l=this.mergeAttributes(s.end);return new Nt(a,l)}rename(e,n){const i=new nb(this.document,e,n.getAttributes());return this.insert(Ge._createAfter(n),i),this.move(Nt._createIn(n),Ge._createAt(i,0)),this.remove(Nt._createOn(n)),i}clearClonedElementsGroup(e){this._cloneGroups.delete(e)}createPositionAt(e,n){return Ge._createAt(e,n)}createPositionAfter(e){return Ge._createAfter(e)}createPositionBefore(e){return Ge._createBefore(e)}createRange(e,n){return new Nt(e,n)}createRangeOn(e){return Nt._createOn(e)}createRangeIn(e){return Nt._createIn(e)}createSelection(...e){return new aa(...e)}createSlot(e="children"){if(!this._slotFactory)throw new oe("view-writer-invalid-create-slot-context",this.document);return this._slotFactory(this,e)}_registerSlotFactory(e){this._slotFactory=e}_clearSlotFactory(){this._slotFactory=null}_insertNodes(e,n,i){let r;if(i?r=CA(e):r=e.parent.is("$text")?e.parent.parent:e.parent,!r)throw new oe("view-writer-invalid-position-container",this.document);let o;i?o=this._breakAttributes(e,!0):o=e.parent.is("$text")?DT(e):e;const s=r._insertChild(o.offset,n);for(const c of n)this._addToClonedElementsGroup(c);const a=o.getShiftedBy(s),l=this.mergeAttributes(o);l.isEqual(o)||a.offset--;const u=this.mergeAttributes(a);return new Nt(l,u)}_wrapChildren(e,n,i,r){let o=n;const s=[];for(;o!1,e.parent._insertChild(e.offset,i);const r=new Nt(e,e.getShiftedBy(1));this.wrap(r,n);const o=new Ge(i.parent,i.index);i._remove();const s=o.nodeBefore,a=o.nodeAfter;return s&&s.is("view:$text")&&a&&a.is("view:$text")?S4(s,a):C4(o)}_breakAttributesRange(e,n=!1){const i=e.start,r=e.end;if(Hg(e,this.document),e.isCollapsed){const l=this._breakAttributes(e.start,n);return new Nt(l,l)}const o=this._breakAttributes(r,n),s=o.parent.childCount,a=this._breakAttributes(i,n);return o.offset+=o.parent.childCount-s,new Nt(a,o)}_breakAttributes(e,n=!1){const i=e.offset,r=e.parent;if(e.parent.is("emptyElement"))throw new oe("view-writer-cannot-break-empty-element",this.document);if(e.parent.is("uiElement"))throw new oe("view-writer-cannot-break-ui-element",this.document);if(e.parent.is("rawElement"))throw new oe("view-writer-cannot-break-raw-element",this.document);if(!n&&r.is("$text")&&SA(r.parent)||SA(r))return e.clone();if(r.is("$text"))return this._breakAttributes(DT(e),n);const o=r.childCount;if(i==o){const s=new Ge(r.parent,r.index+1);return this._breakAttributes(s,n)}else if(i===0){const s=new Ge(r.parent,r.index);return this._breakAttributes(s,n)}else{const s=r.index+1,a=r._clone();r.parent._insertChild(s,a),this._addToClonedElementsGroup(a);const l=r.childCount-i,u=r._removeChildren(i,l);a._appendChild(u);const c=new Ge(r.parent,s);return this._breakAttributes(c,n)}}_addToClonedElementsGroup(e){if(!e.root.is("rootElement"))return;if(e.is("element"))for(const r of e.getChildren())this._addToClonedElementsGroup(r);const n=e.id;if(!n)return;let i=this._cloneGroups.get(n);i||(i=new Set,this._cloneGroups.set(n,i)),i.add(e),e._clonesGroup=i}_removeFromClonedElementsGroup(e){if(e.is("element"))for(const r of e.getChildren())this._removeFromClonedElementsGroup(r);const n=e.id;if(!n)return;const i=this._cloneGroups.get(n);i&&i.delete(e)}}function PMe(t){return Array.from(t.getChildren()).some(e=>!e.is("uiElement"))}function CA(t){let e=t.parent;for(;!SA(e);){if(!e)return;e=e.parent}return e}function IMe(t,e){return t.prioritye.priority?!1:t.getIdentity()n instanceof i))throw new oe("view-writer-insert-invalid-node-type",e);n.is("$text")||fG(n.getChildren(),e)}}function SA(t){return t&&(t.is("containerElement")||t.is("documentFragment"))}function Hg(t,e){const n=CA(t.start),i=CA(t.end);if(!n||!i||n!==i)throw new oe("view-writer-invalid-range-container",e)}function MMe(t){return Wa(t)}const hG=t=>t.createTextNode(" "),mG=t=>{const e=t.createElement("span");return e.dataset.ckeFiller="true",e.innerText=" ",e},gG=t=>{const e=t.createElement("br");return e.dataset.ckeFiller="true",e},ts=7,ib="".repeat(ts);function Qr(t){return typeof t=="string"?t.substr(0,ts)===ib:fi(t)&&t.data.substr(0,ts)===ib}function Kh(t){return t.data.length==ts&&Qr(t)}function k4(t){const e=typeof t=="string"?t:t.data;return Qr(t)?e.slice(ts):e}function OMe(t){t.document.on("arrowKey",LMe,{priority:"low"})}function LMe(t,e){if(e.keyCode==Yt.arrowleft){const n=e.domTarget.ownerDocument.defaultView.getSelection();if(n.rangeCount==1&&n.getRangeAt(0).collapsed){const i=n.getRangeAt(0).startContainer,r=n.getRangeAt(0).startOffset;Qr(i)&&r<=ts&&n.collapse(i,0)}}}class DMe extends Ln(){domDocuments=new Set;domConverter;markedAttributes=new Set;markedChildren=new Set;markedTexts=new Set;selection;_inlineFiller=null;_fakeSelectionContainer=null;constructor(e,n){super(),this.domConverter=e,this.selection=n,this.set("isFocused",!1),this.set("isSelecting",!1),this.set("isComposing",!1),vt.isBlink&&!vt.isAndroid&&this.on("change:isSelecting",()=>{this.isSelecting||this.render()})}markToSync(e,n){if(e==="text")this.domConverter.mapViewToDom(n.parent)&&this.markedTexts.add(n);else{if(!this.domConverter.mapViewToDom(n))return;if(e==="attributes")this.markedAttributes.add(n);else if(e==="children")this.markedChildren.add(n);else throw new oe("view-renderer-unknown-type",this)}}render(){if(this.isComposing&&!vt.isAndroid)return;let e=null;const n=vt.isBlink&&!vt.isAndroid?!this.isSelecting:!0;for(const i of this.markedChildren)this._updateChildrenMappings(i);n?(this._inlineFiller&&!this._isSelectionInInlineFiller()&&this._removeInlineFiller(),this._inlineFiller?e=this._getInlineFillerPosition():this._needsInlineFillerAtSelection()&&(e=this.selection.getFirstPosition(),this.markedChildren.add(e.parent))):this._inlineFiller&&this._inlineFiller.parentNode&&(e=this.domConverter.domPositionToView(this._inlineFiller),e&&e.parent.is("$text")&&(e=Ge._createBefore(e.parent)));for(const i of this.markedAttributes)this._updateAttrs(i);for(const i of this.markedChildren)this._updateChildren(i,{inlineFillerPosition:e});for(const i of this.markedTexts)!this.markedChildren.has(i.parent)&&this.domConverter.mapViewToDom(i.parent)&&this._updateText(i,{inlineFillerPosition:e});if(n)if(e){const i=this.domConverter.viewPositionToDom(e),r=i.parent.ownerDocument;Qr(i.parent)?this._inlineFiller=i.parent:this._inlineFiller=T4(r,i.parent,i.offset)}else this._inlineFiller=null;this._updateFocus(),this._updateSelection(),this.domConverter._clearTemporaryCustomProperties(),this.markedTexts.clear(),this.markedAttributes.clear(),this.markedChildren.clear()}_updateChildrenMappings(e){const n=this.domConverter.mapViewToDom(e);if(!n)return;const i=Array.from(n.childNodes),r=Array.from(this.domConverter.viewChildrenToDom(e,{withChildren:!1})),o=this._diffNodeLists(i,r),s=this._findUpdateActions(o,i,r,BMe);if(s.indexOf("update")!==-1){const a={equal:0,insert:0,delete:0};for(const l of s)if(l==="update"){const u=a.equal+a.insert,c=a.equal+a.delete,d=e.getChild(u);d&&!d.is("uiElement")&&!d.is("rawElement")&&this._updateElementMappings(d,i[c]),a4(r[u]),a.equal++}else a[l]++}}_updateElementMappings(e,n){this.domConverter.unbindDomElement(n),this.domConverter.bindElements(n,e),this.markedChildren.add(e),this.markedAttributes.add(e)}_getInlineFillerPosition(){const e=this.selection.getFirstPosition();return e.parent.is("$text")?Ge._createBefore(e.parent):e}_isSelectionInInlineFiller(){if(this.selection.rangeCount!=1||!this.selection.isCollapsed)return!1;const e=this.selection.getFirstPosition(),n=this.domConverter.viewPositionToDom(e);return!!(n&&fi(n.parent)&&Qr(n.parent))}_removeInlineFiller(){const e=this._inlineFiller;if(!Qr(e))throw new oe("view-renderer-filler-was-lost",this);Kh(e)?e.remove():e.data=e.data.substr(ts),this._inlineFiller=null}_needsInlineFillerAtSelection(){if(this.selection.rangeCount!=1||!this.selection.isCollapsed)return!1;const e=this.selection.getFirstPosition(),n=e.parent,i=e.offset;if(!this.domConverter.mapViewToDom(n.root)||!n.is("element")||!NMe(n))return!1;const r=e.nodeBefore,o=e.nodeAfter;return!(r instanceof Ji||o instanceof Ji||i===n.getFillerOffset()&&(!r||!r.is("element","br"))||vt.isAndroid&&(r||o))}_updateText(e,n){const i=this.domConverter.findCorrespondingDomText(e);let o=this.domConverter.viewToDom(e).data;const s=n.inlineFillerPosition;s&&s.parent==e.parent&&s.offset==e.index&&(o=ib+o),this._updateTextNode(i,o)}_updateAttrs(e){const n=this.domConverter.mapViewToDom(e);if(n){for(const i of Array.from(n.attributes)){const r=i.name;e.hasAttribute(r)||this.domConverter.removeDomElementAttribute(n,r)}for(const i of e.getAttributeKeys())this.domConverter.setDomElementAttribute(n,i,e.getAttribute(i),e)}}_updateChildren(e,n){const i=this.domConverter.mapViewToDom(e);if(!i)return;if(vt.isAndroid){let d=null;for(const f of Array.from(i.childNodes)){if(d&&fi(d)&&fi(f)){i.normalize();break}d=f}}const r=n.inlineFillerPosition,o=i.childNodes,s=Array.from(this.domConverter.viewChildrenToDom(e,{bind:!0}));r&&r.parent===e&&T4(i.ownerDocument,s,r.offset);const a=this._diffNodeLists(o,s),l=this._findUpdateActions(a,o,s,VMe);let u=0;const c=new Set;for(const d of l)d==="delete"?(c.add(o[u]),a4(o[u])):(d==="equal"||d==="update")&&u++;u=0;for(const d of l)d==="insert"?(eG(i,u,s[u]),u++):d==="update"?(this._updateTextNode(o[u],s[u].data),u++):d==="equal"&&(this._markDescendantTextToSync(this.domConverter.domToView(s[u])),u++);for(const d of c)d.parentNode||this.domConverter.unbindDomElement(d)}_diffNodeLists(e,n){return e=zMe(e,this._fakeSelectionContainer),fm(e,n,FMe.bind(null,this.domConverter))}_findUpdateActions(e,n,i,r){if(e.indexOf("insert")===-1||e.indexOf("delete")===-1)return e;let o=[],s=[],a=[];const l={equal:0,insert:0,delete:0};for(const u of e)u==="insert"?a.push(i[l.equal+l.insert]):u==="delete"?s.push(n[l.equal+l.delete]):(o=o.concat(fm(s,a,r).map(c=>c==="equal"?"update":c)),o.push("equal"),s=[],a=[]),l[u]++;return o.concat(fm(s,a,r).map(u=>u==="equal"?"update":u))}_updateTextNode(e,n){const i=e.data;i!=n&&(vt.isAndroid&&this.isComposing&&i.replace(/\u00A0/g," ")==n.replace(/\u00A0/g," ")||this._updateTextNodeInternal(e,n))}_updateTextNodeInternal(e,n){const i=FK(e.data,n);for(const r of i)r.type==="insert"?e.insertData(r.index,r.values.join("")):e.deleteData(r.index,r.howMany)}_markDescendantTextToSync(e){if(e){if(e.is("$text"))this.markedTexts.add(e);else if(e.is("element"))for(const n of e.getChildren())this._markDescendantTextToSync(n)}}_updateSelection(){if(vt.isBlink&&!vt.isAndroid&&this.isSelecting&&!this.markedChildren.size)return;if(this.selection.rangeCount===0){this._removeDomSelection(),this._removeFakeSelection();return}const e=this.domConverter.mapViewToDom(this.selection.editableElement);if(!this.isFocused||!e){!this.selection.isFake&&this._fakeSelectionContainer&&this._fakeSelectionContainer.isConnected&&this._removeFakeSelection();return}this.selection.isFake?this._updateFakeSelection(e):this._fakeSelectionContainer&&this._fakeSelectionContainer.isConnected?(this._removeFakeSelection(),this._updateDomSelection(e)):this.isComposing&&vt.isAndroid||this._updateDomSelection(e)}_updateFakeSelection(e){const n=e.ownerDocument;this._fakeSelectionContainer||(this._fakeSelectionContainer=HMe(n));const i=this._fakeSelectionContainer;if(this.domConverter.bindFakeSelection(i,this.selection),!this._fakeSelectionNeedsUpdate(e))return;(!i.parentElement||i.parentElement!=e)&&e.appendChild(i),i.textContent=this.selection.fakeSelectionLabel||" ";const r=n.getSelection(),o=n.createRange();r.removeAllRanges(),o.selectNodeContents(i),r.addRange(o)}_updateDomSelection(e){const n=e.ownerDocument.defaultView.getSelection();if(!this._domSelectionNeedsUpdate(n))return;const i=this.domConverter.viewPositionToDom(this.selection.anchor),r=this.domConverter.viewPositionToDom(this.selection.focus);n.setBaseAndExtent(i.parent,i.offset,r.parent,r.offset),vt.isGecko&&$Me(r,n)}_domSelectionNeedsUpdate(e){if(!this.domConverter.isDomSelectionCorrect(e))return!0;const n=e&&this.domConverter.domSelectionToView(e);return!(n&&this.selection.isEqual(n)||!this.selection.isCollapsed&&this.selection.isSimilar(n))}_fakeSelectionNeedsUpdate(e){const n=this._fakeSelectionContainer,i=e.ownerDocument.getSelection();return!n||n.parentElement!==e||i.anchorNode!==n&&!n.contains(i.anchorNode)?!0:n.textContent!==this.selection.fakeSelectionLabel}_removeDomSelection(){for(const e of this.domDocuments){const n=e.getSelection();if(n.rangeCount){const i=e.activeElement,r=this.domConverter.mapDomToView(i);i&&r&&n.removeAllRanges()}}}_removeFakeSelection(){const e=this._fakeSelectionContainer;e&&e.remove()}_updateFocus(){if(this.isFocused){const e=this.selection.editableElement;e&&this.domConverter.focus(e)}}}function NMe(t){if(t.getAttribute("contenteditable")=="false")return!1;const e=t.findAncestor(n=>n.hasAttribute("contenteditable"));return!e||e.getAttribute("contenteditable")=="true"}function T4(t,e,n){const i=e instanceof Array?e:e.childNodes,r=i[n];if(fi(r))return r.data=ib+r.data,r;{const o=t.createTextNode(ib);return Array.isArray(e)?i.splice(n,0,o):eG(e,n,o),o}}function BMe(t,e){return Mc(t)&&Mc(e)&&!fi(t)&&!fi(e)&&!ev(t)&&!ev(e)&&t.tagName.toLowerCase()===e.tagName.toLowerCase()}function VMe(t,e){return Mc(t)&&Mc(e)&&fi(t)&&fi(e)}function FMe(t,e,n){return e===n?!0:fi(e)&&fi(n)?e.data===n.data:!!(t.isBlockFiller(e)&&t.isBlockFiller(n))}function $Me(t,e){let n=t.parent,i=t.offset;if(fi(n)&&Kh(n)&&(i=jh(n)+1,n=n.parentNode),n.nodeType!=Node.ELEMENT_NODE||i!=n.childNodes.length-1)return;const r=n.childNodes[i];r&&r.tagName=="BR"&&e.addRange(e.getRangeAt(0))}function zMe(t,e){const n=Array.from(t);return n.length==0||!e||n[n.length-1]==e&&n.pop(),n}function HMe(t){const e=t.createElement("div");return e.className="ck-fake-selection-container",Object.assign(e.style,{position:"fixed",top:0,left:"-9999px",width:"42px"}),e.textContent=" ",e}const UMe=gG(Qe.document),WMe=hG(Qe.document),qMe=mG(Qe.document),ry="data-ck-unsafe-attribute-",E4="data-ck-unsafe-element";class pS{document;renderingMode;blockFillerMode;preElements;blockElements;inlineObjectElements;unsafeElements;_domDocument;_domToViewMapping=new WeakMap;_viewToDomMapping=new WeakMap;_fakeSelectionMapping=new WeakMap;_rawContentElementMatcher=new pl;_inlineObjectElementMatcher=new pl;_elementsWithTemporaryCustomProperties=new Set;constructor(e,{blockFillerMode:n,renderingMode:i="editing"}={}){this.document=e,this.renderingMode=i,this.blockFillerMode=n||(i==="editing"?"br":"nbsp"),this.preElements=["pre","textarea"],this.blockElements=["address","article","aside","blockquote","caption","center","dd","details","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","legend","li","main","menu","nav","ol","p","pre","section","summary","table","tbody","td","tfoot","th","thead","tr","ul"],this.inlineObjectElements=["object","iframe","input","button","textarea","select","option","video","embed","audio","img","canvas"],this.unsafeElements=["script","style"],this._domDocument=this.renderingMode==="editing"?Qe.document:Qe.document.implementation.createHTMLDocument("")}get domDocument(){return this._domDocument}bindFakeSelection(e,n){this._fakeSelectionMapping.set(e,new aa(n))}fakeSelectionToView(e){return this._fakeSelectionMapping.get(e)}bindElements(e,n){this._domToViewMapping.set(e,n),this._viewToDomMapping.set(n,e)}unbindDomElement(e){const n=this._domToViewMapping.get(e);if(n){this._domToViewMapping.delete(e),this._viewToDomMapping.delete(n);for(const i of e.children)this.unbindDomElement(i)}}bindDocumentFragments(e,n){this._domToViewMapping.set(e,n),this._viewToDomMapping.set(n,e)}shouldRenderAttribute(e,n,i){return this.renderingMode==="data"?!0:(e=e.toLowerCase(),e.startsWith("on")||e==="srcdoc"&&n.match(/\bon\S+\s*=|javascript:|<\s*\/*script/i)?!1:i==="img"&&(e==="src"||e==="srcset")||i==="source"&&e==="srcset"?!0:!n.match(/^\s*(javascript:|data:(image\/svg|text\/x?html))/i))}setContentOf(e,n){if(this.renderingMode==="data"){e.innerHTML=n;return}const i=new DOMParser().parseFromString(n,"text/html"),r=i.createDocumentFragment(),o=i.body.childNodes;for(;o.length>0;)r.appendChild(o[0]);const s=i.createTreeWalker(r,NodeFilter.SHOW_ELEMENT),a=[];let l;for(;l=s.nextNode();)a.push(l);for(const u of a){for(const d of u.getAttributeNames())this.setDomElementAttribute(u,d,u.getAttribute(d));const c=u.tagName.toLowerCase();this._shouldRenameElement(c)&&(I4(c),u.replaceWith(this._createReplacementDomElement(c,u)))}for(;e.firstChild;)e.firstChild.remove();e.append(r)}viewToDom(e,n={}){if(e.is("$text")){const i=this._processDataFromViewText(e);return this._domDocument.createTextNode(i)}else{const i=e;if(this.mapViewToDom(i))if(i.getCustomProperty("editingPipeline:doNotReuseOnce"))this._elementsWithTemporaryCustomProperties.add(i);else return this.mapViewToDom(i);let r;if(i.is("documentFragment"))r=this._domDocument.createDocumentFragment(),n.bind&&this.bindDocumentFragments(r,i);else{if(i.is("uiElement"))return i.name==="$comment"?r=this._domDocument.createComment(i.getCustomProperty("$rawContent")):r=i.render(this._domDocument,this),n.bind&&this.bindElements(r,i),r;this._shouldRenameElement(i.name)?(I4(i.name),r=this._createReplacementDomElement(i.name)):i.hasAttribute("xmlns")?r=this._domDocument.createElementNS(i.getAttribute("xmlns"),i.name):r=this._domDocument.createElement(i.name),i.is("rawElement")&&i.render(r,this),n.bind&&this.bindElements(r,i);for(const o of i.getAttributeKeys())this.setDomElementAttribute(r,o,i.getAttribute(o),i)}if(n.withChildren!==!1)for(const o of this.viewChildrenToDom(i,n))r instanceof HTMLTemplateElement?r.content.appendChild(o):r.appendChild(o);return r}}setDomElementAttribute(e,n,i,r){const o=this.shouldRenderAttribute(n,i,e.tagName.toLowerCase())||r&&r.shouldRenderUnsafeAttribute(n);if(o||hn("domconverter-unsafe-attribute-detected",{domElement:e,key:n,value:i}),!CRe(n)){hn("domconverter-invalid-attribute-detected",{domElement:e,key:n,value:i});return}e.hasAttribute(n)&&!o?e.removeAttribute(n):e.hasAttribute(ry+n)&&o&&e.removeAttribute(ry+n),e.setAttribute(o?n:ry+n,i)}removeDomElementAttribute(e,n){n!=E4&&(e.removeAttribute(n),e.removeAttribute(ry+n))}*viewChildrenToDom(e,n={}){const i=e.getFillerOffset&&e.getFillerOffset();let r=0;for(const o of e.getChildren()){i===r&&(yield this._getBlockFiller());const s=o.is("element")&&!!o.getCustomProperty("dataPipeline:transparentRendering")&&!Mi(o.getAttributes());if(s&&this.renderingMode=="data")if(o.is("rawElement")){const a=this._domDocument.createElement(o.name);o.render(a,this),yield*[...a.childNodes]}else yield*this.viewChildrenToDom(o,n);else s&&hn("domconverter-transparent-rendering-unsupported-in-editing-pipeline",{viewElement:o}),yield this.viewToDom(o,n);r++}i===r&&(yield this._getBlockFiller())}viewRangeToDom(e){const n=this.viewPositionToDom(e.start),i=this.viewPositionToDom(e.end),r=this._domDocument.createRange();return r.setStart(n.parent,n.offset),r.setEnd(i.parent,i.offset),r}viewPositionToDom(e){const n=e.parent;if(n.is("$text")){const i=this.findCorrespondingDomText(n);if(!i)return null;let r=e.offset;return Qr(i)&&(r+=ts),i.data&&r>i.data.length&&(r=i.data.length),{parent:i,offset:r}}else{let i,r,o;if(e.offset===0){if(i=this.mapViewToDom(n),!i)return null;o=i.childNodes[0]}else{const a=e.nodeBefore;if(r=a.is("$text")?this.findCorrespondingDomText(a):this.mapViewToDom(a),!r)return null;i=r.parentNode,o=r.nextSibling}if(fi(o)&&Qr(o))return{parent:o,offset:ts};const s=r?jh(r)+1:0;return{parent:i,offset:s}}}domToView(e,n={}){const i=[],r=this._domToView(e,n,i),o=r.next().value;return!o||(r.next(),this._processDomInlineNodes(null,i,n),this.blockFillerMode=="br"&&A4(o))||o.is("$text")&&o.data.length==0?null:o}*domChildrenToView(e,n={},i=[]){let r=[];e instanceof HTMLTemplateElement?r=[...e.content.childNodes]:r=[...e.childNodes];for(let o=0;o{const{scrollLeft:a,scrollTop:l}=s;o.push([a,l])}),n.focus({preventScroll:!0}),x4(n,s=>{const[a,l]=o.shift();s.scrollLeft=a,s.scrollTop=l}),Qe.window.scrollTo(i,r)}_clearDomSelection(){const e=this.mapViewToDom(this.document.selection.editableElement);if(!e)return;const n=e.ownerDocument.defaultView.getSelection(),i=this.domSelectionToView(n);i&&i.rangeCount>0&&n.removeAllRanges()}isElement(e){return e&&e.nodeType==Node.ELEMENT_NODE}isDocumentFragment(e){return e&&e.nodeType==Node.DOCUMENT_FRAGMENT_NODE}isBlockFiller(e){return this.blockFillerMode=="br"?e.isEqualNode(UMe):P4(e,this.blockElements)?!0:e.isEqualNode(qMe)||KMe(e,this.blockElements)}isDomSelectionBackward(e){if(e.isCollapsed)return!1;const n=this._domDocument.createRange();try{n.setStart(e.anchorNode,e.anchorOffset),n.setEnd(e.focusNode,e.focusOffset)}catch{return!1}const i=n.collapsed;return n.detach(),i}getHostViewElement(e){const n=vRe(e);for(n.pop();n.length;){const i=n.pop(),r=this._domToViewMapping.get(i);if(r&&(r.is("uiElement")||r.is("rawElement")))return r}return null}isDomSelectionCorrect(e){return this._isDomSelectionPositionCorrect(e.anchorNode,e.anchorOffset)&&this._isDomSelectionPositionCorrect(e.focusNode,e.focusOffset)}registerRawContentMatcher(e){this._rawContentElementMatcher.add(e)}registerInlineObjectMatcher(e){this._inlineObjectElementMatcher.add(e)}_clearTemporaryCustomProperties(){for(const e of this._elementsWithTemporaryCustomProperties)e._removeCustomProperty("editingPipeline:doNotReuseOnce");this._elementsWithTemporaryCustomProperties.clear()}_getBlockFiller(){switch(this.blockFillerMode){case"nbsp":return hG(this._domDocument);case"markedNbsp":return mG(this._domDocument);case"br":return gG(this._domDocument)}}_isDomSelectionPositionCorrect(e,n){if(fi(e)&&Qr(e)&&n0?n[o-1]:null,c=o+1n.is("element")&&e.includes(n.name))}function x4(t,e){let n=t;for(;n;)e(n),n=n.parentElement}function KMe(t,e){return t.isEqualNode(WMe)&&pG(t,e)&&t.parentNode.childNodes.length===1}function pG(t,e){const n=t.parentNode;return!!n&&!!n.tagName&&e.includes(n.tagName.toLowerCase())}function GMe(t,e,n){return e==" "&&t&&t.is("element")&&t.childCount==1&&n.includes(t.name)}function YMe(t,e){return e==" "&&t&&t.is("element","span")&&t.childCount==1&&t.hasAttribute("data-cke-filler")}function A4(t){return t.is("element","br")&&t.hasAttribute("data-cke-filler")}function P4(t,e){return t.tagName==="BR"&&pG(t,e)&&t.parentNode.childNodes.length===1}function I4(t){t==="script"&&hn("domconverter-unsafe-script-element-detected"),t==="style"&&hn("domconverter-unsafe-style-element-detected")}function XMe(t){if(!vt.isGecko||!t.rangeCount)return!1;const e=t.getRangeAt(0).startContainer;try{Object.prototype.toString.call(e)}catch{return!0}return!1}class _l extends zo(){view;document;_isEnabled=!1;constructor(e){super(),this.view=e,this.document=e.document}get isEnabled(){return this._isEnabled}enable(){this._isEnabled=!0}disable(){this._isEnabled=!1}destroy(){this.disable(),this.stopListening()}checkShouldIgnoreEventFromTarget(e){return e&&e.nodeType===3&&(e=e.parentNode),!e||e.nodeType!==1?!1:e.matches("[data-cke-ignore-events], [data-cke-ignore-events] *")}}class Sf{view;document;domEvent;domTarget;constructor(e,n,i){this.view=e,this.document=e.document,this.domEvent=n,this.domTarget=n.target,BK(this,i)}get target(){return this.view.domConverter.mapDomToView(this.domTarget)}preventDefault(){this.domEvent.preventDefault()}stopPropagation(){this.domEvent.stopPropagation()}}class Cl extends _l{useCapture=!1;usePassive=!1;observe(e){(typeof this.domEventType=="string"?[this.domEventType]:this.domEventType).forEach(i=>{this.listenTo(e,i,(r,o)=>{this.isEnabled&&!this.checkShouldIgnoreEventFromTarget(o.target)&&this.onDomEvent(o)},{useCapture:this.useCapture,usePassive:this.usePassive})})}stopObserving(e){this.stopListening(e)}fire(e,n,i){this.isEnabled&&this.document.fire(e,new Sf(this.view,n,i))}}class JMe extends Cl{domEventType=["keydown","keyup"];onDomEvent(e){const n={keyCode:e.keyCode,altKey:e.altKey,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,metaKey:e.metaKey,get keystroke(){return Gm(this)}};this.fire(e.type,e,n)}}class ZMe extends _l{_fireSelectionChangeDoneDebounced;constructor(e){super(e),this._fireSelectionChangeDoneDebounced=ml(n=>{this.document.fire("selectionChangeDone",n)},200)}observe(){const e=this.document;e.on("arrowKey",(n,i)=>{e.selection.isFake&&this.isEnabled&&i.preventDefault()},{context:"$capture"}),e.on("arrowKey",(n,i)=>{e.selection.isFake&&this.isEnabled&&this._handleSelectionMove(i.keyCode)},{priority:"lowest"})}stopObserving(){}destroy(){super.destroy(),this._fireSelectionChangeDoneDebounced.cancel()}_handleSelectionMove(e){const n=this.document.selection,i=new aa(n.getRanges(),{backward:n.isBackward,fake:!1});(e==Yt.arrowleft||e==Yt.arrowup)&&i.setTo(i.getFirstPosition()),(e==Yt.arrowright||e==Yt.arrowdown)&&i.setTo(i.getLastPosition());const r={oldSelection:n,newSelection:i,domSelection:null};this.document.fire("selectionChange",r),this._fireSelectionChangeDoneDebounced(r)}}let vG=class extends _l{domConverter;_config;_domElements;_mutationObserver;constructor(e){super(e),this._config={childList:!0,characterData:!0,subtree:!0},this.domConverter=e.domConverter,this._domElements=new Set,this._mutationObserver=new window.MutationObserver(this._onMutations.bind(this))}flush(){this._onMutations(this._mutationObserver.takeRecords())}observe(e){this._domElements.add(e),this.isEnabled&&this._mutationObserver.observe(e,this._config)}stopObserving(e){if(this._domElements.delete(e),this.isEnabled){this._mutationObserver.disconnect();for(const n of this._domElements)this._mutationObserver.observe(n,this._config)}}enable(){super.enable();for(const e of this._domElements)this._mutationObserver.observe(e,this._config)}disable(){super.disable(),this._mutationObserver.disconnect()}destroy(){super.destroy(),this._mutationObserver.disconnect()}_onMutations(e){if(e.length===0)return;const n=this.domConverter,i=new Set,r=new Set;for(const s of e){const a=n.mapDomToView(s.target);a&&(a.is("uiElement")||a.is("rawElement")||s.type==="childList"&&!this._isBogusBrMutation(s)&&r.add(a))}for(const s of e){const a=n.mapDomToView(s.target);if(!(a&&(a.is("uiElement")||a.is("rawElement")))&&s.type==="characterData"){const l=n.findCorrespondingViewText(s.target);l&&!r.has(l.parent)?i.add(l):!l&&Qr(s.target)&&r.add(n.mapDomToView(s.target.parentNode))}}const o=[];for(const s of i)o.push({type:"text",node:s});for(const s of r){const a=n.mapViewToDom(s),l=Array.from(s.getChildren()),u=Array.from(n.domChildrenToView(a,{withChildren:!1}));pA(l,u,QMe)||o.push({type:"children",node:s})}o.length&&this.document.fire("mutations",{mutations:o})}_isBogusBrMutation(e){let n=null;return e.nextSibling===null&&e.removedNodes.length===0&&e.addedNodes.length==1&&(n=this.domConverter.domToView(e.addedNodes[0],{withChildren:!1})),n&&n.is("element","br")}};function QMe(t,e){if(!Array.isArray(t))return t===e?!0:t.is("$text")&&e.is("$text")?t.data===e.data:!1}class d1 extends Cl{_renderTimeoutId=null;_isFocusChanging=!1;domEventType=["focus","blur"];constructor(e){super(e),this.useCapture=!0;const n=this.document;n.on("focus",()=>this._handleFocus()),n.on("blur",(i,r)=>this._handleBlur(r)),n.on("beforeinput",()=>{n.isFocused||this._handleFocus()},{priority:"highest"})}flush(){this._isFocusChanging&&(this._isFocusChanging=!1,this.document.isFocused=!0)}onDomEvent(e){this.fire(e.type,e)}destroy(){this._clearTimeout(),super.destroy()}_handleFocus(){this._clearTimeout(),this._isFocusChanging=!0,this._renderTimeoutId=setTimeout(()=>{this._renderTimeoutId=null,this.flush(),this.view.change(()=>{})},50)}_handleBlur(e){const n=this.document.selection.editableElement;(n===null||n===e.target)&&(this.document.isFocused=!1,this._isFocusChanging=!1,this.view.change(()=>{}))}_clearTimeout(){this._renderTimeoutId&&(clearTimeout(this._renderTimeoutId),this._renderTimeoutId=null)}}class eOe extends _l{mutationObserver;focusObserver;selection;domConverter;_documents=new WeakSet;_fireSelectionChangeDoneDebounced;_clearInfiniteLoopInterval;_documentIsSelectingInactivityTimeoutDebounced;_loopbackCounter=0;_pendingSelectionChange=new Set;constructor(e){super(e),this.mutationObserver=e.getObserver(vG),this.focusObserver=e.getObserver(d1),this.selection=this.document.selection,this.domConverter=e.domConverter,this._fireSelectionChangeDoneDebounced=ml(n=>{this.document.fire("selectionChangeDone",n)},200),this._clearInfiniteLoopInterval=setInterval(()=>this._clearInfiniteLoop(),1e3),this._documentIsSelectingInactivityTimeoutDebounced=ml(()=>this.document.isSelecting=!1,5e3),this.view.document.on("change:isFocused",(n,i,r)=>{if(r&&this._pendingSelectionChange.size){for(const o of Array.from(this._pendingSelectionChange))this._handleSelectionChange(o);this._pendingSelectionChange.clear()}})}observe(e){const n=e.ownerDocument,i=()=>{this.document.isSelecting=!0,this._documentIsSelectingInactivityTimeoutDebounced()},r=()=>{this.document.isSelecting&&(this._handleSelectionChange(n),this.document.isSelecting=!1,this._documentIsSelectingInactivityTimeoutDebounced.cancel())};this.listenTo(e,"selectstart",i,{priority:"highest"}),this.listenTo(e,"keydown",r,{priority:"highest",useCapture:!0}),this.listenTo(e,"keyup",r,{priority:"highest",useCapture:!0}),!this._documents.has(n)&&(this.listenTo(n,"mouseup",r,{priority:"highest",useCapture:!0}),this.listenTo(n,"selectionchange",()=>{this.document.isComposing&&!vt.isAndroid||(this._handleSelectionChange(n),this._documentIsSelectingInactivityTimeoutDebounced())}),this.listenTo(this.view.document,"compositionstart",()=>{this._handleSelectionChange(n)},{priority:"lowest"}),this._documents.add(n))}stopObserving(e){this.stopListening(e)}destroy(){super.destroy(),clearInterval(this._clearInfiniteLoopInterval),this._fireSelectionChangeDoneDebounced.cancel(),this._documentIsSelectingInactivityTimeoutDebounced.cancel()}_reportInfiniteLoop(){}_handleSelectionChange(e){if(!this.isEnabled)return;const n=e.defaultView.getSelection();if(this.checkShouldIgnoreEventFromTarget(n.anchorNode))return;this.mutationObserver.flush();const i=this.domConverter.domSelectionToView(n);if(i.rangeCount==0){this.view.hasDomSelection=!1;return}if(this.view.hasDomSelection=!0,this.focusObserver.flush(),!this.view.document.isFocused&&!this.view.document.isReadOnly){this._pendingSelectionChange.add(e);return}if(this._pendingSelectionChange.delete(e),!(this.selection.isEqual(i)&&this.domConverter.isDomSelectionCorrect(n))){if(++this._loopbackCounter>60){this._reportInfiniteLoop();return}if(!tOe(i))this.view.forceRender();else if(this.selection.isSimilar(i))this.view.forceRender();else{const r={oldSelection:this.selection,newSelection:i,domSelection:n};this.document.fire("selectionChange",r),this._fireSelectionChangeDoneDebounced(r)}}}_clearInfiniteLoop(){this._loopbackCounter=0}}function tOe(t){return Array.from(t.getRanges()).flatMap(e=>[e.start.root,e.end.root]).every(e=>e&&e.is("rootElement"))}class nOe extends Cl{domEventType=["compositionstart","compositionupdate","compositionend"];constructor(e){super(e);const n=this.document;n.on("compositionstart",()=>{n.isComposing=!0}),n.on("compositionend",()=>{n.isComposing=!1})}onDomEvent(e){this.fire(e.type,e,{data:e.data})}}class bG{_files;_native;constructor(e,n={}){this._files=n.cacheFiles?R4(e):null,this._native=e}get files(){return this._files||(this._files=R4(this._native)),this._files}get types(){return this._native.types}getData(e){return this._native.getData(e)}setData(e,n){this._native.setData(e,n)}set effectAllowed(e){this._native.effectAllowed=e}get effectAllowed(){return this._native.effectAllowed}set dropEffect(e){this._native.dropEffect=e}get dropEffect(){return this._native.dropEffect}setDragImage(e,n,i){this._native.setDragImage(e,n,i)}get isCanceled(){return this._native.dropEffect=="none"||!!this._native.mozUserCancelled}}function R4(t){const e=Array.from(t.files||[]),n=Array.from(t.items||[]);return e.length?e:n.filter(i=>i.kind==="file").map(i=>i.getAsFile())}class iOe extends Cl{domEventType="beforeinput";onDomEvent(e){const n=e.getTargetRanges(),i=this.view,r=i.document;let o=null,s=null,a=[];if(e.dataTransfer&&(o=new bG(e.dataTransfer)),e.data!==null?s=e.data:o&&(s=o.getData("text/plain")),r.selection.isFake)a=Array.from(r.selection.getRanges()),e.preventDefault();else if(n.length)a=n.map(l=>{let u=i.domConverter.domPositionToView(l.startContainer,l.startOffset);const c=i.domConverter.domPositionToView(l.endContainer,l.endOffset);if(u&&Qr(l.startContainer)&&l.startOffset!!(f.item.is("attributeElement")||f.item.is("uiElement")||f.item.is("$textProxy")&&d--),{direction:"backward",singleCharacters:!0})}if(rOe(l.endContainer,l.endOffset)&&e.preventDefault(),u)return i.createRange(u,c);if(c)return i.createRange(c)}).filter(l=>!!l);else if(vt.isAndroid){const l=e.target.ownerDocument.defaultView.getSelection();a=Array.from(i.domConverter.domSelectionToView(l).getRanges())}if(vt.isAndroid&&e.inputType=="insertCompositionText"&&s&&s.endsWith(`
+`)){this.fire(e.type,e,{inputType:"insertParagraph",targetRanges:[i.createRange(a[0].end)]});return}if(["insertText","insertReplacementText"].includes(e.inputType)&&s&&s.includes(`
+`)){const l=s.split(/\n{1,2}/g);let u=a;e.preventDefault();for(let c=0;c{if(this.isEnabled&&RRe(i.keyCode)){const r=new Hf(this.document,"arrowKey",this.document.selection.getFirstRange());this.document.fire(r,i),r.stop.called&&n.stop()}})}observe(){}stopObserving(){}}class sOe extends _l{constructor(e){super(e);const n=this.document;n.on("keydown",(i,r)=>{if(!this.isEnabled||r.keyCode!=Yt.tab||r.ctrlKey)return;const o=new Hf(n,"tab",n.selection.getFirstRange());n.fire(o,r),o.stop.called&&i.stop()})}observe(){}stopObserving(){}}class aOe extends Ln(){document;domConverter;domRoots=new Map;_renderer;_initialDomRootAttributes=new WeakMap;_observers=new Map;_writer;_ongoingChange=!1;_postFixersInProgress=!1;_renderingDisabled=!1;_hasChangedSinceTheLastRendering=!1;constructor(e){super(),this.document=new mS(e),this.domConverter=new pS(this.document),this.set("isRenderingInProgress",!1),this.set("hasDomSelection",!1),this._renderer=new DMe(this.domConverter,this.document.selection),this._renderer.bind("isFocused","isSelecting","isComposing").to(this.document,"isFocused","isSelecting","isComposing"),this._writer=new dG(this.document),this.addObserver(vG),this.addObserver(d1),this.addObserver(eOe),this.addObserver(JMe),this.addObserver(ZMe),this.addObserver(nOe),this.addObserver(oOe),this.addObserver(iOe),this.addObserver(sOe),OMe(this),kMe(this),this.on("render",()=>{this._render(),this.document.fire("layoutChanged"),this._hasChangedSinceTheLastRendering=!1}),this.listenTo(this.document.selection,"change",()=>{this._hasChangedSinceTheLastRendering=!0}),this.listenTo(this.document,"change:isFocused",()=>{this._hasChangedSinceTheLastRendering=!0}),vt.isiOS&&this.listenTo(this.document,"blur",(n,i)=>{this.domConverter.mapDomToView(i.domEvent.relatedTarget)||this.domConverter._clearDomSelection()}),this.listenTo(this.document,"mutations",(n,{mutations:i})=>{i.forEach(r=>this._renderer.markToSync(r.type,r.node))},{priority:"low"}),this.listenTo(this.document,"mutations",()=>{this.forceRender()},{priority:"lowest"})}attachDomRoot(e,n="main"){const i=this.document.getRoot(n);i._name=e.tagName.toLowerCase();const r={};for(const{name:s,value:a}of Array.from(e.attributes))r[s]=a,s==="class"?this._writer.addClass(a.split(" "),i):i.hasAttribute(s)||this._writer.setAttribute(s,a,i);this._initialDomRootAttributes.set(e,r);const o=()=>{this._writer.setAttribute("contenteditable",(!i.isReadOnly).toString(),i),i.isReadOnly?this._writer.addClass("ck-read-only",i):this._writer.removeClass("ck-read-only",i)};o(),this.domRoots.set(n,e),this.domConverter.bindElements(e,i),this._renderer.markToSync("children",i),this._renderer.markToSync("attributes",i),this._renderer.domDocuments.add(e.ownerDocument),i.on("change:children",(s,a)=>this._renderer.markToSync("children",a)),i.on("change:attributes",(s,a)=>this._renderer.markToSync("attributes",a)),i.on("change:text",(s,a)=>this._renderer.markToSync("text",a)),i.on("change:isReadOnly",()=>this.change(o)),i.on("change",()=>{this._hasChangedSinceTheLastRendering=!0});for(const s of this._observers.values())s.observe(e,n)}detachDomRoot(e){const n=this.domRoots.get(e);Array.from(n.attributes).forEach(({name:r})=>n.removeAttribute(r));const i=this._initialDomRootAttributes.get(n);for(const r in i)n.setAttribute(r,i[r]);this.domRoots.delete(e),this.domConverter.unbindDomElement(n);for(const r of this._observers.values())r.stopObserving(n)}getDomRoot(e="main"){return this.domRoots.get(e)}addObserver(e){let n=this._observers.get(e);if(n)return n;n=new e(this),this._observers.set(e,n);for(const[i,r]of this.domRoots)n.observe(r,i);return n.enable(),n}getObserver(e){return this._observers.get(e)}disableObservers(){for(const e of this._observers.values())e.disable()}enableObservers(){for(const e of this._observers.values())e.enable()}scrollToTheSelection({alignToTop:e,forceScroll:n,viewportOffset:i=20,ancestorOffset:r=20}={}){const o=this.document.selection.getFirstRange();if(!o)return;const s=Bo({alignToTop:e,forceScroll:n,viewportOffset:i,ancestorOffset:r});typeof i=="number"&&(i={top:i,bottom:i,left:i,right:i});const a={target:this.domConverter.viewRangeToDom(o),viewportOffset:i,ancestorOffset:r,alignToTop:e,forceScroll:n};this.fire("scrollToTheSelection",a,s),kRe(a)}focus(){if(!this.document.isFocused){const e=this.document.selection.editableElement;e&&(this.domConverter.focus(e),this.forceRender())}}change(e){if(this.isRenderingInProgress||this._postFixersInProgress)throw new oe("cannot-change-view-tree",this);try{if(this._ongoingChange)return e(this._writer);this._ongoingChange=!0;const n=e(this._writer);return this._ongoingChange=!1,!this._renderingDisabled&&this._hasChangedSinceTheLastRendering&&(this._postFixersInProgress=!0,this.document._callPostFixers(this._writer),this._postFixersInProgress=!1,this.fire("render")),n}catch(n){oe.rethrowUnexpectedError(n,this)}}forceRender(){this._hasChangedSinceTheLastRendering=!0,this.getObserver(d1).flush(),this.change(()=>{})}destroy(){for(const e of this._observers.values())e.destroy();this.document.destroy(),this.stopListening()}createPositionAt(e,n){return Ge._createAt(e,n)}createPositionAfter(e){return Ge._createAfter(e)}createPositionBefore(e){return Ge._createBefore(e)}createRange(e,n){return new Nt(e,n)}createRangeOn(e){return Nt._createOn(e)}createRangeIn(e){return Nt._createIn(e)}createSelection(...e){return new aa(...e)}_disableRendering(e){this._renderingDisabled=e,e==!1&&this.change(()=>{})}_render(){this.isRenderingInProgress=!0,this.disableObservers(),this._renderer.render(),this.enableObservers(),this.isRenderingInProgress=!1}}class Kc{is(){throw new Error("is() method is abstract")}}class ea extends Kc{textNode;data;offsetInText;constructor(e,n,i){if(super(),this.textNode=e,n<0||n>e.offsetSize)throw new oe("model-textproxy-wrong-offsetintext",this);if(i<0||n+i>e.offsetSize)throw new oe("model-textproxy-wrong-length",this);this.data=e.data.substring(n,n+i),this.offsetInText=n}get startOffset(){return this.textNode.startOffset!==null?this.textNode.startOffset+this.offsetInText:null}get offsetSize(){return this.data.length}get endOffset(){return this.startOffset!==null?this.startOffset+this.offsetSize:null}get isPartial(){return this.offsetSize!==this.textNode.offsetSize}get parent(){return this.textNode.parent}get root(){return this.textNode.root}getPath(){const e=this.textNode.getPath();return e.length>0&&(e[e.length-1]+=this.offsetInText),e}getAncestors(e={}){const n=[];let i=e.includeSelf?this:this.parent;for(;i;)n[e.parentFirst?"push":"unshift"](i),i=i.parent;return n}hasAttribute(e){return this.textNode.hasAttribute(e)}getAttribute(e){return this.textNode.getAttribute(e)}getAttributes(){return this.textNode.getAttributes()}getAttributeKeys(){return this.textNode.getAttributeKeys()}}ea.prototype.is=function(t){return t==="$textProxy"||t==="model:$textProxy"||t==="textProxy"||t==="model:textProxy"};class Ql{direction;boundaries;singleCharacters;shallow;ignoreElementEnd;_position;_boundaryStartParent;_boundaryEndParent;_visitedParent;constructor(e){if(!e||!e.boundaries&&!e.startPosition)throw new oe("model-tree-walker-no-start-position",null);const n=e.direction||"forward";if(n!="forward"&&n!="backward")throw new oe("model-tree-walker-unknown-direction",e,{direction:n});this.direction=n,this.boundaries=e.boundaries||null,e.startPosition?this._position=e.startPosition.clone():this._position=Be._createAt(this.boundaries[this.direction=="backward"?"end":"start"]),this.position.stickiness="toNone",this.singleCharacters=!!e.singleCharacters,this.shallow=!!e.shallow,this.ignoreElementEnd=!!e.ignoreElementEnd,this._boundaryStartParent=this.boundaries?this.boundaries.start.parent:null,this._boundaryEndParent=this.boundaries?this.boundaries.end.parent:null,this._visitedParent=this.position.parent}[Symbol.iterator](){return this}get position(){return this._position}skip(e){let n,i,r,o;do r=this.position,o=this._visitedParent,{done:n,value:i}=this.next();while(!n&&e(i));n||(this._position=r,this._visitedParent=o)}jumpTo(e){this._boundaryStartParent&&e.isBefore(this.boundaries.start)?e=this.boundaries.start:this._boundaryEndParent&&e.isAfter(this.boundaries.end)&&(e=this.boundaries.end),this._position=e.clone(),this._visitedParent=e.parent}next(){return this.direction=="forward"?this._next():this._previous()}_next(){const e=this.position,n=this.position.clone(),i=this._visitedParent;if(i.parent===null&&n.offset===i.maxOffset)return{done:!0,value:void 0};if(i===this._boundaryEndParent&&n.offset==this.boundaries.end.offset)return{done:!0,value:void 0};const r=nv(n,i),o=r||yG(n,i,r);if(o&&o.is("model:element")){if(!this.shallow)n.path.push(0),this._visitedParent=o;else{if(this.boundaries&&this.boundaries.end.isBefore(n))return{done:!0,value:void 0};n.offset++}return this._position=n,ad("elementStart",o,e,n,1)}if(o&&o.is("model:$text")){let s;if(this.singleCharacters)s=1;else{let u=o.endOffset;this._boundaryEndParent==i&&this.boundaries.end.offsetc&&(c=this.boundaries.start.offset),a=n.offset-c}const l=n.offset-s.startOffset,u=new ea(s,l-a,a);return n.offset-=a,this._position=n,ad("text",u,e,n,a)}return n.path.pop(),this._position=n,this._visitedParent=i.parent,ad("elementStart",i,e,n,1)}}function ad(t,e,n,i,r){return{done:!1,value:{type:t,item:e,previousPosition:n,nextPosition:i,length:r}}}class Be extends Kc{root;path;stickiness;constructor(e,n,i="toNone"){if(super(),!e.is("element")&&!e.is("documentFragment"))throw new oe("model-position-root-invalid",e);if(!Array.isArray(n)||n.length===0)throw new oe("model-position-path-incorrect-format",e,{path:n});e.is("rootElement")?n=n.slice():(n=[...e.getPath(),...n],e=e.root),this.root=e,this.path=n,this.stickiness=i}get offset(){return this.path[this.path.length-1]}set offset(e){this.path[this.path.length-1]=e}get parent(){let e=this.root;for(let n=0;n1)return!1;if(r===1)return M4(e,this,i);if(r===-1)return M4(this,e,i)}return this.path.length===e.path.length?!0:this.path.length>e.path.length?kA(this.path,n):kA(e.path,n)}hasSameParentAs(e){if(this.root!==e.root)return!1;const n=this.getParentPath(),i=e.getParentPath();return ur(n,i)=="same"}getTransformedByOperation(e){let n;switch(e.type){case"insert":n=this._getTransformedByInsertOperation(e);break;case"move":case"remove":case"reinsert":n=this._getTransformedByMoveOperation(e);break;case"split":n=this._getTransformedBySplitOperation(e);break;case"merge":n=this._getTransformedByMergeOperation(e);break;default:n=Be._createAt(this);break}return n}_getTransformedByInsertOperation(e){return this._getTransformedByInsertion(e.position,e.howMany)}_getTransformedByMoveOperation(e){return this._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany)}_getTransformedBySplitOperation(e){const n=e.movedRange;return n.containsPosition(this)||n.start.isEqual(this)&&this.stickiness=="toNext"?this._getCombined(e.splitPosition,e.moveTargetPosition):e.graveyardPosition?this._getTransformedByMove(e.graveyardPosition,e.insertionPosition,1):this._getTransformedByInsertion(e.insertionPosition,1)}_getTransformedByMergeOperation(e){const n=e.movedRange,i=n.containsPosition(this)||n.start.isEqual(this);let r;return i?(r=this._getCombined(e.sourcePosition,e.targetPosition),e.sourcePosition.isBefore(e.targetPosition)&&(r=r._getTransformedByDeletion(e.deletionPosition,1))):this.isEqual(e.deletionPosition)?r=Be._createAt(e.deletionPosition):r=this._getTransformedByMove(e.deletionPosition,e.graveyardPosition,1),r}_getTransformedByDeletion(e,n){const i=Be._createAt(this);if(this.root!=e.root)return i;if(ur(e.getParentPath(),this.getParentPath())=="same"){if(e.offsetthis.offset)return null;i.offset-=n}}else if(ur(e.getParentPath(),this.getParentPath())=="prefix"){const r=e.path.length-1;if(e.offset<=this.path[r]){if(e.offset+n>this.path[r])return null;i.path[r]-=n}}return i}_getTransformedByInsertion(e,n){const i=Be._createAt(this);if(this.root!=e.root)return i;if(ur(e.getParentPath(),this.getParentPath())=="same")(e.offset=e;){if(t.path[i]+r!==n.maxOffset)return!1;r=1,i--,n=n.parent}return!0}class Ee extends Kc{start;end;constructor(e,n){super(),this.start=Be._createAt(e),this.end=n?Be._createAt(n):Be._createAt(e),this.start.stickiness=this.isCollapsed?"toNone":"toNext",this.end.stickiness=this.isCollapsed?"toNone":"toPrevious"}*[Symbol.iterator](){yield*new Ql({boundaries:this,ignoreElementEnd:!0})}get isCollapsed(){return this.start.isEqual(this.end)}get isFlat(){const e=this.start.getParentPath(),n=this.end.getParentPath();return ur(e,n)=="same"}get root(){return this.start.root}containsPosition(e){return e.isAfter(this.start)&&e.isBefore(this.end)}containsRange(e,n=!1){e.isCollapsed&&(n=!1);const i=this.containsPosition(e.start)||n&&this.start.isEqual(e.start),r=this.containsPosition(e.end)||n&&this.end.isEqual(e.end);return i&&r}containsItem(e){const n=Be._createBefore(e);return this.containsPosition(n)||this.start.isEqual(n)}isEqual(e){return this.start.isEqual(e.start)&&this.end.isEqual(e.end)}isIntersecting(e){return this.start.isBefore(e.end)&&this.end.isAfter(e.start)}getDifference(e){const n=[];return this.isIntersecting(e)?(this.containsPosition(e.start)&&n.push(new Ee(this.start,e.start)),this.containsPosition(e.end)&&n.push(new Ee(e.end,this.end))):n.push(new Ee(this.start,this.end)),n}getIntersection(e){if(this.isIntersecting(e)){let n=this.start,i=this.end;return this.containsPosition(e.start)&&(n=e.start),this.containsPosition(e.end)&&(i=e.end),new Ee(n,i)}return null}getJoined(e,n=!1){let i=this.isIntersecting(e);if(i||(this.start.isBefore(e.start)?i=n?this.end.isTouching(e.start):this.end.isEqual(e.start):i=n?e.end.isTouching(this.start):e.end.isEqual(this.start)),!i)return null;let r=this.start,o=this.end;return e.start.isBefore(r)&&(r=e.start),e.end.isAfter(o)&&(o=e.end),new Ee(r,o)}getMinimalFlatRanges(){const e=[],n=this.start.getCommonPath(this.end).length,i=Be._createAt(this.start);let r=i.parent;for(;i.path.length>n+1;){const o=r.maxOffset-i.offset;o!==0&&e.push(new Ee(i,i.getShiftedBy(o))),i.path=i.path.slice(0,-1),i.offset++,r=r.parent}for(;i.path.length<=this.end.path.length;){const o=this.end.path[i.path.length-1],s=o-i.offset;s!==0&&e.push(new Ee(i,i.getShiftedBy(s))),i.offset=o,i.path.push(0)}return e}getWalker(e={}){return e.boundaries=this,new Ql(e)}*getItems(e={}){e.boundaries=this,e.ignoreElementEnd=!0;const n=new Ql(e);for(const i of n)yield i.item}*getPositions(e={}){e.boundaries=this;const n=new Ql(e);yield n.position;for(const i of n)yield i.nextPosition}getTransformedByOperation(e){switch(e.type){case"insert":return this._getTransformedByInsertOperation(e);case"move":case"remove":case"reinsert":return this._getTransformedByMoveOperation(e);case"split":return[this._getTransformedBySplitOperation(e)];case"merge":return[this._getTransformedByMergeOperation(e)]}return[new Ee(this.start,this.end)]}getTransformedByOperations(e){const n=[new Ee(this.start,this.end)];for(const i of e)for(let r=0;r0?new this(i,r):new this(r,i)}static _createIn(e){return new this(Be._createAt(e,0),Be._createAt(e,e.maxOffset))}static _createOn(e){return this._createFromPositionAndShift(Be._createBefore(e),e.offsetSize)}static _createFromRanges(e){if(e.length===0)throw new oe("range-create-from-ranges-empty-array",null);if(e.length==1)return e[0].clone();const n=e[0];e.sort((o,s)=>o.start.isAfter(s.start)?1:-1);const i=e.indexOf(n),r=new this(n.start,n.end);for(let o=i-1;o>=0&&e[o].end.isEqual(r.start);o--)r.start=Be._createAt(e[o].start);for(let o=i+1;o{if(n.viewPosition)return;const i=this._modelToViewMapping.get(n.modelPosition.parent);if(!i)throw new oe("mapping-model-position-view-parent-not-found",this,{modelPosition:n.modelPosition});n.viewPosition=this.findPositionIn(i,n.modelPosition.offset)},{priority:"low"}),this.on("viewToModelPosition",(e,n)=>{if(n.modelPosition)return;const i=this.findMappedViewAncestor(n.viewPosition),r=this._viewToModelMapping.get(i),o=this._toModelOffset(n.viewPosition.parent,n.viewPosition.offset,i);n.modelPosition=Be._createAt(r,o)},{priority:"low"})}bindElements(e,n){this._modelToViewMapping.set(e,n),this._viewToModelMapping.set(n,e)}unbindViewElement(e,n={}){const i=this.toModelElement(e);if(this._elementToMarkerNames.has(e))for(const r of this._elementToMarkerNames.get(e))this._unboundMarkerNames.add(r);n.defer?this._deferredBindingRemovals.set(e,e.root):(this._viewToModelMapping.delete(e)&&this._cache.stopTracking(e),this._modelToViewMapping.get(i)==e&&this._modelToViewMapping.delete(i))}unbindModelElement(e){const n=this.toViewElement(e);this._modelToViewMapping.delete(e),this._viewToModelMapping.get(n)==e&&this._viewToModelMapping.delete(n)&&this._cache.stopTracking(n)}bindElementToMarker(e,n){const i=this._markerNameToElements.get(n)||new Set;i.add(e);const r=this._elementToMarkerNames.get(e)||new Set;r.add(n),this._markerNameToElements.set(n,i),this._elementToMarkerNames.set(e,r)}unbindElementFromMarkerName(e,n){const i=this._markerNameToElements.get(n);i&&(i.delete(e),i.size==0&&this._markerNameToElements.delete(n));const r=this._elementToMarkerNames.get(e);r&&(r.delete(n),r.size==0&&this._elementToMarkerNames.delete(e))}flushUnboundMarkerNames(){const e=Array.from(this._unboundMarkerNames);return this._unboundMarkerNames.clear(),e}flushDeferredBindings(){for(const[e,n]of this._deferredBindingRemovals)e.root==n&&this.unbindViewElement(e);this._deferredBindingRemovals=new Map}clearBindings(){this._modelToViewMapping=new WeakMap,this._viewToModelMapping=new WeakMap,this._markerNameToElements=new Map,this._elementToMarkerNames=new Map,this._unboundMarkerNames=new Set,this._deferredBindingRemovals=new Map}toModelElement(e){return this._viewToModelMapping.get(e)}toViewElement(e){return this._modelToViewMapping.get(e)}toModelRange(e){return new Ee(this.toModelPosition(e.start),this.toModelPosition(e.end))}toViewRange(e){return new Nt(this.toViewPosition(e.start),this.toViewPosition(e.end))}toModelPosition(e){const n={viewPosition:e,mapper:this};return this.fire("viewToModelPosition",n),n.modelPosition}toViewPosition(e,n={}){const i={modelPosition:e,mapper:this,isPhantom:n.isPhantom};return this.fire("modelToViewPosition",i),i.viewPosition}markerNameToElements(e){const n=this._markerNameToElements.get(e);if(!n)return null;const i=new Set;for(const r of n)if(r.is("attributeElement"))for(const o of r.getElementsWithSameId())i.add(o);else i.add(r);return i}registerViewToModelLength(e,n){this._viewToModelLengthCallbacks.set(e,n)}findMappedViewAncestor(e){let n=e.parent;for(;!this._viewToModelMapping.has(n);)n=n.parent;return n}_toModelOffset(e,n,i){if(i!=e){const o=this._toModelOffset(e.parent,e.index,i),s=this._toModelOffset(e,n,e);return o+s}if(e.is("$text"))return n;let r=0;for(let o=0;o0;){const r=n.pop(),o=r.name&&this._viewToModelLengthCallbacks.size>0&&this._viewToModelLengthCallbacks.get(r.name);if(o)i+=o(r);else if(this._viewToModelMapping.has(r))i+=1;else if(r.is("$text"))i+=r.data.length;else{if(r.is("uiElement"))continue;for(const s of r.getChildren())n.push(s)}}return i}findPositionIn(e,n){if(n===0)return this._moveViewPositionToTextNode(new Ge(e,0));if(this._viewToModelLengthCallbacks.size==0&&this._viewToModelMapping.has(e)){const r=this._cache.getClosest(e,n);return this._findPositionStartingFrom(r.viewPosition,r.modelOffset,n,e,!0)}else return this._findPositionStartingFrom(new Ge(e,0),0,n,e,!1)}_findPositionStartingFrom(e,n,i,r,o){let s=e.parent,a=e.offset;if(s.is("$text"))return new Ge(s,i-n);let l,u=n,c=0;for(;u{this._clearCacheInsideParent(n,i.index)};_invalidateOnTextChangeCallback=(e,n)=>{this._clearCacheAfter(n)};save(e,n,i,r){const o=this._cachedMapping.get(i),s=o.cacheMap.get(r);if(s){const c=e.getChild(n-1),d=s.viewPosition.nodeBefore?this._nodeToCacheListIndex.get(s.viewPosition.nodeBefore):0;this._nodeToCacheListIndex.set(c,d);return}const l={viewPosition:new Ge(e,n),modelOffset:r};o.maxModelOffset=r>o.maxModelOffset?r:o.maxModelOffset,o.cacheMap.set(r,l);let u=o.cacheList.length-1;for(;u>=0&&o.cacheList[u].modelOffset>r;)u--;if(o.cacheList.splice(u+1,0,l),n>0){const c=e.getChild(n-1);this._nodeToCacheListIndex.set(c,u+1)}}getClosest(e,n){const i=this._cachedMapping.get(e);let r;if(i)if(n>i.maxModelOffset)r=i.cacheList[i.cacheList.length-1];else{const o=i.cacheMap.get(n);o?r=o:r=this._findInCacheList(i.cacheList,n)}else r=this.startTracking(e);return{modelOffset:r.modelOffset,viewPosition:r.viewPosition.clone()}}startTracking(e){const i={viewPosition:new Ge(e,0),modelOffset:0},r={maxModelOffset:0,cacheList:[i],cacheMap:new Map([[0,i]])};return this._cachedMapping.set(e,r),e.on("change:children",this._invalidateOnChildrenChangeCallback),e.on("change:text",this._invalidateOnTextChangeCallback),i}stopTracking(e){e.off("change:children",this._invalidateOnChildrenChangeCallback),e.off("change:text",this._invalidateOnTextChangeCallback),this._cachedMapping.delete(e)}_clearCacheInsideParent(e,n){if(n==0)this._cachedMapping.has(e)?this._clearCacheAll(e):this._clearCacheInsideParent(e.parent,e.index);else{const i=e.getChild(n-1);this._clearCacheAfter(i)}}_clearCacheAll(e){const n=this._cachedMapping.get(e);n.maxModelOffset>0&&(n.maxModelOffset=0,n.cacheList.length=1,n.cacheMap.clear(),n.cacheMap.set(0,n.cacheList[0]))}_clearCacheAfter(e){const n=this._nodeToCacheListIndex.get(e);if(n===void 0){const r=e.parent;this._cachedMapping.has(r)||this._clearCacheInsideParent(r.parent,r.index);return}let i=e.parent;for(;!this._cachedMapping.has(i);)i=i.parent;this._clearCacheFromCacheIndex(i,n)}_clearCacheFromCacheIndex(e,n){n===0&&(n=1);const i=this._cachedMapping.get(e),r=i.cacheList[n-1];if(!r)return;i.maxModelOffset=r.modelOffset;const o=i.cacheList.splice(n);for(const s of o){i.cacheMap.delete(s.modelOffset);const a=s.viewPosition.nodeBefore;this._nodeToCacheListIndex.delete(a)}}_findInCacheList(e,n){let i=0,r=e.length-1,o=r-i>>1,s=e[o];for(;i>1),s=e[o];return s.modelOffset<=n?s:e[o-1]}}class cOe{_consumable=new Map;_textProxyRegistry=new Map;add(e,n){n=oy(n),e instanceof ea&&(e=this._getSymbolForTextProxy(e)),this._consumable.has(e)||this._consumable.set(e,new Map),this._consumable.get(e).set(n,!0)}consume(e,n){return n=oy(n),e instanceof ea&&(e=this._getSymbolForTextProxy(e)),this.test(e,n)?(this._consumable.get(e).set(n,!1),!0):!1}test(e,n){n=oy(n),e instanceof ea&&(e=this._getSymbolForTextProxy(e));const i=this._consumable.get(e);if(i===void 0)return null;const r=i.get(n);return r===void 0?null:r}revert(e,n){n=oy(n),e instanceof ea&&(e=this._getSymbolForTextProxy(e));const i=this.test(e,n);return i===!1?(this._consumable.get(e).set(n,!0),!0):i===!0?!1:null}verifyAllConsumed(e){const n=[];for(const[i,r]of this._consumable)for(const[o,s]of r){const a=o.split(":")[0];s&&e==a&&n.push({event:o,item:i.name||i.description})}if(n.length)throw new oe("conversion-model-consumable-not-consumed",null,{items:n})}_getSymbolForTextProxy(e){let n=null;const i=this._textProxyRegistry.get(e.startOffset);if(i){const r=i.get(e.endOffset);r&&(n=r.get(e.parent))}return n||(n=this._addSymbolForTextProxy(e)),n}_addSymbolForTextProxy(e){const n=e.startOffset,i=e.endOffset,r=e.parent,o=Symbol("$textProxy:"+e.data);let s,a;return s=this._textProxyRegistry.get(n),s||(s=new Map,this._textProxyRegistry.set(n,s)),a=s.get(i),a||(a=new Map,s.set(i,a)),a.set(r,o),o}}function oy(t){const e=t.split(":");return e[0]=="insert"?e[0]:e[0]=="addMarker"||e[0]=="removeMarker"?t:e.length>1?e[0]+":"+e[1]:e[0]}class CG extends Fn(){_conversionApi;_firedEventsMap;constructor(e){super(),this._conversionApi={dispatcher:this,...e},this._firedEventsMap=new WeakMap}convertChanges(e,n,i){const r=e.getRefreshedItems(),o=this._createConversionApi(i,r);for(const a of e.getMarkersToRemove())this._convertMarkerRemove(a.name,a.range,o);const s=this._reduceChanges(e.getChanges(),r);for(const a of s)a.type==="insert"?this._convertInsert(Ee._createFromPositionAndShift(a.position,a.length),o):a.type==="reinsert"?this._convertReinsert(Ee._createFromPositionAndShift(a.position,a.length),o):a.type==="remove"?this._convertRemove(a.position,a.length,a.name,o):this._convertAttribute(a.range,a.attributeKey,a.attributeOldValue,a.attributeNewValue,o);o.mapper.flushDeferredBindings();for(const a of o.mapper.flushUnboundMarkerNames()){const l=n.get(a).getRange();this._convertMarkerRemove(a,l,o),this._convertMarkerAdd(a,l,o)}for(const a of e.getMarkersToAdd())this._convertMarkerAdd(a.name,a.range,o);o.consumable.verifyAllConsumed("insert")}convert(e,n,i,r={}){const o=this._createConversionApi(i,void 0,r);this._convertInsert(e,o);for(const[s,a]of n)this._convertMarkerAdd(s,a,o);o.consumable.verifyAllConsumed("insert")}convertSelection(e,n,i){const r=this._createConversionApi(i);this.fire("cleanSelection",{selection:e},r);const o=e.getFirstPosition().root;if(!r.mapper.toViewElement(o))return;const s=Array.from(n.getMarkersAtPosition(e.getFirstPosition()));if(this._addConsumablesForSelection(r.consumable,e,s),this.fire("selection",{selection:e},r),!!e.isCollapsed){for(const a of s)if(r.consumable.test(e,"addMarker:"+a.name)){const l=a.getRange();if(!dOe(e.getFirstPosition(),a,r.mapper))continue;const u={item:e,markerName:a.name,markerRange:l};this.fire(`addMarker:${a.name}`,u,r)}for(const a of e.getAttributeKeys())if(r.consumable.test(e,"attribute:"+a)){const l={item:e,range:e.getFirstRange(),attributeKey:a,attributeOldValue:null,attributeNewValue:e.getAttribute(a)};this.fire(`attribute:${a}:$text`,l,r)}}}_convertInsert(e,n,i={}){i.doNotAddConsumables||this._addConsumablesForInsert(n.consumable,e);for(const r of e.getWalker({shallow:!0}))this._testAndFire("insert",O4(r),n)}_convertRemove(e,n,i,r){this.fire(`remove:${i}`,{position:e,length:n},r)}_convertAttribute(e,n,i,r,o){this._addConsumablesForRange(o.consumable,e,`attribute:${n}`);for(const s of e){const a={item:s.item,range:Ee._createFromPositionAndShift(s.previousPosition,s.length),attributeKey:n,attributeOldValue:i,attributeNewValue:r};this._testAndFire(`attribute:${n}`,a,o)}}_convertReinsert(e,n){const i=Array.from(e.getWalker({shallow:!0}));this._addConsumablesForInsert(n.consumable,i);for(const r of i.map(O4))this.fire(`remove:${r.item.is("element")?r.item.name:"$text"}`,{position:r.range.start,length:r.item.offsetSize,reconversion:!0},n),this._testAndFire("insert",{...r,reconversion:!0},n)}_convertMarkerAdd(e,n,i){if(n.root.rootName=="$graveyard")return;const r=`addMarker:${e}`;if(i.consumable.add(n,r),this.fire(r,{markerName:e,markerRange:n},i),!!i.consumable.consume(n,r)){this._addConsumablesForRange(i.consumable,n,r);for(const o of n.getItems()){if(!i.consumable.test(o,r))continue;const s={item:o,range:Ee._createOn(o),markerName:e,markerRange:n};this.fire(r,s,i)}}}_convertMarkerRemove(e,n,i){n.root.rootName!="$graveyard"&&this.fire(`removeMarker:${e}`,{markerName:e,markerRange:n},i)}_reduceChanges(e,n){const i={changes:e,refreshedItems:n};return this.fire("reduceChanges",i),i.changes}_addConsumablesForInsert(e,n){for(const i of n){const r=i.item;if(e.test(r,"insert")===null){e.add(r,"insert");for(const o of r.getAttributeKeys())e.add(r,"attribute:"+o)}}return e}_addConsumablesForRange(e,n,i){for(const r of n.getItems())e.add(r,i);return e}_addConsumablesForSelection(e,n,i){e.add(n,"selection");for(const r of i)e.add(n,"addMarker:"+r.name);for(const r of n.getAttributeKeys())e.add(n,"attribute:"+r);return e}_testAndFire(e,n,i){const r=fOe(e,n),o=n.item.is("$textProxy")?i.consumable._getSymbolForTextProxy(n.item):n.item,s=this._firedEventsMap.get(i),a=s.get(o);if(!a)s.set(o,new Set([r]));else if(!a.has(r))a.add(r);else return;this.fire(r,n,i)}_testAndFireAddAttributes(e,n){const i={item:e,range:Ee._createOn(e)};for(const r of i.item.getAttributeKeys())i.attributeKey=r,i.attributeOldValue=null,i.attributeNewValue=i.item.getAttribute(r),this._testAndFire(`attribute:${r}`,i,n)}_createConversionApi(e,n=new Set,i={}){const r={...this._conversionApi,consumable:new cOe,writer:e,options:i,convertItem:o=>this._convertInsert(Ee._createOn(o),r),convertChildren:o=>this._convertInsert(Ee._createIn(o),r,{doNotAddConsumables:!0}),convertAttributes:o=>this._testAndFireAddAttributes(o,r),canReuseView:o=>!n.has(r.mapper.toModelElement(o))};return this._firedEventsMap.set(r,new Map),r}}function dOe(t,e,n){const i=e.getRange(),r=Array.from(t.getAncestors());return r.shift(),r.reverse(),!r.some(s=>{if(i.containsItem(s))return!!n.toViewElement(s).getCustomProperty("addHighlight")})}function fOe(t,e){const n=e.item.is("element")?e.item.name:"$text";return`${t}:${n}`}function O4(t){return{item:t.item,range:Ee._createFromPositionAndShift(t.previousPosition,t.length)}}class Uf extends Kc{parent=null;_attrs;_index=null;_startOffset=null;constructor(e){super(),this._attrs=gl(e)}get document(){return null}get index(){return this._index}get startOffset(){return this._startOffset}get offsetSize(){return 1}get endOffset(){return this.startOffset===null?null:this.startOffset+this.offsetSize}get nextSibling(){const e=this.index;return e!==null&&this.parent.getChild(e+1)||null}get previousSibling(){const e=this.index;return e!==null&&this.parent.getChild(e-1)||null}get root(){let e=this;for(;e.parent;)e=e.parent;return e}isAttached(){return this.parent===null?!1:this.root.isAttached()}getPath(){const e=[];let n=this;for(;n.parent;)e.unshift(n.startOffset),n=n.parent;return e}getAncestors(e={}){const n=[];let i=e.includeSelf?this:this.parent;for(;i;)n[e.parentFirst?"push":"unshift"](i),i=i.parent;return n}getCommonAncestor(e,n={}){const i=this.getAncestors(n),r=e.getAncestors(n);let o=0;for(;i[o]==r[o]&&i[o];)o++;return o===0?null:i[o-1]}isBefore(e){if(this==e||this.root!==e.root)return!1;const n=this.getPath(),i=e.getPath(),r=ur(n,i);switch(r){case"prefix":return!0;case"extension":return!1;default:return n[r](n[i[0]]=i[1],n),{})),e}_clone(e){return new this.constructor(this._attrs)}_remove(){this.parent._removeChildren(this.index)}_setAttribute(e,n){this._attrs.set(e,n)}_setAttributesTo(e){this._attrs=gl(e)}_removeAttribute(e){return this._attrs.delete(e)}_clearAttributes(){this._attrs.clear()}}Uf.prototype.is=function(t){return t==="node"||t==="model:node"};class Xo extends Fn(Kc){_lastRangeBackward=!1;_attrs=new Map;_ranges=[];constructor(...e){super(),e.length&&this.setTo(...e)}get anchor(){if(this._ranges.length>0){const e=this._ranges[this._ranges.length-1];return this._lastRangeBackward?e.end:e.start}return null}get focus(){if(this._ranges.length>0){const e=this._ranges[this._ranges.length-1];return this._lastRangeBackward?e.start:e.end}return null}get isCollapsed(){return this._ranges.length===1?this._ranges[0].isCollapsed:!1}get rangeCount(){return this._ranges.length}get isBackward(){return!this.isCollapsed&&this._lastRangeBackward}isEqual(e){if(this.rangeCount!=e.rangeCount)return!1;if(this.rangeCount===0)return!0;if(!this.anchor.isEqual(e.anchor)||!this.focus.isEqual(e.focus))return!1;for(const n of this._ranges){let i=!1;for(const r of e._ranges)if(n.isEqual(r)){i=!0;break}if(!i)return!1}return!0}*getRanges(){for(const e of this._ranges)yield new Ee(e.start,e.end)}getFirstRange(){let e=null;for(const n of this._ranges)(!e||n.start.isBefore(e.start))&&(e=n);return e?new Ee(e.start,e.end):null}getLastRange(){let e=null;for(const n of this._ranges)(!e||n.end.isAfter(e.end))&&(e=n);return e?new Ee(e.start,e.end):null}getFirstPosition(){const e=this.getFirstRange();return e?e.start.clone():null}getLastPosition(){const e=this.getLastRange();return e?e.end.clone():null}setTo(...e){let[n,i,r]=e;if(typeof i=="object"&&(r=i,i=void 0),n===null)this._setRanges([]);else if(n instanceof Xo)this._setRanges(n.getRanges(),n.isBackward);else if(n&&typeof n.getRanges=="function")this._setRanges(n.getRanges(),n.isBackward);else if(n instanceof Ee)this._setRanges([n],!!r&&!!r.backward);else if(n instanceof Be)this._setRanges([new Ee(n)]);else if(n instanceof Uf){const o=!!r&&!!r.backward;let s;if(i=="in")s=Ee._createIn(n);else if(i=="on")s=Ee._createOn(n);else if(i!==void 0)s=new Ee(Be._createAt(n,i));else throw new oe("model-selection-setto-required-second-parameter",[this,n]);this._setRanges([s],o)}else if(us(n))this._setRanges(n,r&&!!r.backward);else throw new oe("model-selection-setto-not-selectable",[this,n])}_setRanges(e,n=!1){const i=Array.from(e),r=i.some(o=>{if(!(o instanceof Ee))throw new oe("model-selection-set-ranges-not-range",[this,e]);return this._ranges.every(s=>!s.isEqual(o))});i.length===this._ranges.length&&!r||(this._replaceAllRanges(i),this._lastRangeBackward=!!n,this.fire("change:range",{directChange:!0}))}setFocus(e,n){if(this.anchor===null)throw new oe("model-selection-setfocus-no-ranges",[this,e]);const i=Be._createAt(e,n);if(i.compareWith(this.focus)=="same")return;const r=this.anchor;this._ranges.length&&this._popRange(),i.compareWith(r)=="before"?(this._pushRange(new Ee(i,r)),this._lastRangeBackward=!0):(this._pushRange(new Ee(r,i)),this._lastRangeBackward=!1),this.fire("change:range",{directChange:!0})}getAttribute(e){return this._attrs.get(e)}getAttributes(){return this._attrs.entries()}getAttributeKeys(){return this._attrs.keys()}hasAttribute(e){return this._attrs.has(e)}removeAttribute(e){this.hasAttribute(e)&&(this._attrs.delete(e),this.fire("change:attribute",{attributeKeys:[e],directChange:!0}))}setAttribute(e,n){this.getAttribute(e)!==n&&(this._attrs.set(e,n),this.fire("change:attribute",{attributeKeys:[e],directChange:!0}))}getSelectedElement(){return this.rangeCount!==1?null:this.getFirstRange().getContainedElement()}*getSelectedBlocks(){const e=new WeakSet;for(const n of this.getRanges()){const i=L4(n.start,e);mOe(i,n)&&(yield i);const r=n.getWalker();for(const s of r){const a=s.item;s.type=="elementEnd"&&hOe(a,e,n)?yield a:s.type=="elementStart"&&a.is("model:element")&&a.root.document.model.schema.isBlock(a)&&r.jumpTo(Be._createAt(a,"end"))}const o=L4(n.end,e);gOe(o,n)&&(yield o)}}containsEntireContent(e=this.anchor.root){const n=Be._createAt(e,0),i=Be._createAt(e,"end");return n.isTouching(this.getFirstPosition())&&i.isTouching(this.getLastPosition())}toJSON(){const e={ranges:Array.from(this.getRanges()).map(i=>i.toJSON())},n=Object.fromEntries(this.getAttributes());return Object.keys(n).length&&(e.attributes=n),this.isBackward&&(e.isBackward=!0),e}_pushRange(e){this._checkRange(e),this._ranges.push(new Ee(e.start,e.end))}_checkRange(e){for(let n=0;n0;)this._popRange()}_popRange(){this._ranges.pop()}}Xo.prototype.is=function(t){return t==="selection"||t==="model:selection"};function SG(t,e){return e.has(t)?!1:(e.add(t),t.root.document.model.schema.isBlock(t)&&!!t.parent)}function hOe(t,e,n){return SG(t,e)&&XM(t,n)}function L4(t,e){const i=t.parent.root.document.model.schema,r=t.parent.getAncestors({parentFirst:!0,includeSelf:!0});let o=!1;const s=r.find(a=>o?!1:(o=i.isLimit(a),!o&&SG(a,e)));return r.forEach(a=>e.add(a)),s}function XM(t,e){const n=pOe(t);return n?!e.containsRange(Ee._createOn(n),!0):!0}function mOe(t,e){return t?e.isCollapsed||t.isEmpty?!0:e.start.isTouching(Be._createAt(t,t.maxOffset))?!1:XM(t,e):!1}function gOe(t,e){return t?e.isCollapsed||t.isEmpty?!0:e.end.isTouching(Be._createAt(t,0))?!1:XM(t,e):!1}function pOe(t){const e=t.root.document.model.schema;let n=t.parent;for(;n;){if(e.isBlock(n))return n;n=n.parent}}class ko extends Fn(Ee){constructor(e,n){super(e,n),vOe.call(this)}detach(){this.stopListening()}toRange(){return new Ee(this.start,this.end)}static fromRange(e){return new ko(e.start,e.end)}}ko.prototype.is=function(t){return t==="liveRange"||t==="model:liveRange"||t=="range"||t==="model:range"};function vOe(){this.listenTo(this.root.document.model,"applyOperation",(t,e)=>{const n=e[0];n.isDocumentOperation&&bOe.call(this,n)},{priority:"low"})}function bOe(t){const e=this.getTransformedByOperation(t),n=Ee._createFromRanges(e),i=!n.isEqual(this),r=yOe(this,t);let o=null;if(i){n.root.rootName=="$graveyard"&&(t.type=="remove"?o=t.sourcePosition:o=t.deletionPosition);const s=this.toRange();this.start=n.start,this.end=n.end,this.fire("change:range",s,{deletionPosition:o})}else r&&this.fire("change:content",this.toRange(),{deletionPosition:o})}function yOe(t,e){switch(e.type){case"insert":return t.containsPosition(e.position);case"move":case"remove":case"reinsert":case"merge":return t.containsPosition(e.sourcePosition)||t.start.isEqual(e.sourcePosition)||t.containsPosition(e.targetPosition);case"split":return t.containsPosition(e.splitPosition)||t.containsPosition(e.insertionPosition)}return!1}class ni extends Uf{_data;constructor(e,n){super(n),this._data=e||""}get offsetSize(){return this.data.length}get data(){return this._data}toJSON(){const e=super.toJSON();return e.data=this.data,e}_clone(){return new ni(this.data,this.getAttributes())}static fromJSON(e){return new ni(e.data,e.attributes)}}ni.prototype.is=function(t){return t==="$text"||t==="model:$text"||t==="text"||t==="model:text"||t==="node"||t==="model:node"};const rb="selection:";class cs extends Fn(Kc){_selection;constructor(e){super(),this._selection=new wOe(e),this._selection.delegate("change:range").to(this),this._selection.delegate("change:attribute").to(this),this._selection.delegate("change:marker").to(this)}get isCollapsed(){return this._selection.isCollapsed}get anchor(){return this._selection.anchor}get focus(){return this._selection.focus}get rangeCount(){return this._selection.rangeCount}get hasOwnRange(){return this._selection.hasOwnRange}get isBackward(){return this._selection.isBackward}get isGravityOverridden(){return this._selection.isGravityOverridden}get markers(){return this._selection.markers}get _ranges(){return this._selection._ranges}getRanges(){return this._selection.getRanges()}getFirstPosition(){return this._selection.getFirstPosition()}getLastPosition(){return this._selection.getLastPosition()}getFirstRange(){return this._selection.getFirstRange()}getLastRange(){return this._selection.getLastRange()}getSelectedBlocks(){return this._selection.getSelectedBlocks()}getSelectedElement(){return this._selection.getSelectedElement()}containsEntireContent(e){return this._selection.containsEntireContent(e)}destroy(){this._selection.destroy()}getAttributeKeys(){return this._selection.getAttributeKeys()}getAttributes(){return this._selection.getAttributes()}getAttribute(e){return this._selection.getAttribute(e)}hasAttribute(e){return this._selection.hasAttribute(e)}refresh(){this._selection.updateMarkers(),this._selection._updateAttributes(!1)}observeMarkers(e){this._selection.observeMarkers(e)}toJSON(){return this._selection.toJSON()}_setFocus(e,n){this._selection.setFocus(e,n)}_setTo(...e){this._selection.setTo(...e)}_setAttribute(e,n){this._selection.setAttribute(e,n)}_removeAttribute(e){this._selection.removeAttribute(e)}_getStoredAttributes(){return this._selection.getStoredAttributes()}_overrideGravity(){return this._selection.overrideGravity()}_restoreGravity(e){this._selection.restoreGravity(e)}static _getStoreAttributeKey(e){return rb+e}static _isStoreAttributeKey(e){return e.startsWith(rb)}}cs.prototype.is=function(t){return t==="selection"||t=="model:selection"||t=="documentSelection"||t=="model:documentSelection"};class wOe extends Xo{markers=new Er({idProperty:"name"});_model;_document;_attributePriority=new Map;_selectionRestorePosition=null;_hasChangedRange=!1;_overriddenGravityRegister=new Set;_observedMarkers=new Set;constructor(e){super(),this._model=e.model,this._document=e,this.listenTo(this._model,"applyOperation",(n,i)=>{const r=i[0];!r.isDocumentOperation||r.type=="marker"||r.type=="rename"||r.type=="noop"||(this._ranges.length==0&&this._selectionRestorePosition&&this._fixGraveyardSelection(this._selectionRestorePosition),this._selectionRestorePosition=null,this._hasChangedRange&&(this._hasChangedRange=!1,this.fire("change:range",{directChange:!1})))},{priority:"lowest"}),this.on("change:range",()=>{this._validateSelectionRanges(this.getRanges())}),this.listenTo(this._model.markers,"update",(n,i,r,o)=>{this._updateMarker(i,o)}),this.listenTo(this._document,"change",(n,i)=>{_Oe(this._model,i)})}get isCollapsed(){return this._ranges.length===0?this._document._getDefaultRange().isCollapsed:super.isCollapsed}get anchor(){return super.anchor||this._document._getDefaultRange().start}get focus(){return super.focus||this._document._getDefaultRange().end}get rangeCount(){return this._ranges.length?this._ranges.length:1}get hasOwnRange(){return this._ranges.length>0}get isGravityOverridden(){return!!this._overriddenGravityRegister.size}destroy(){for(let e=0;en.toJSON())),e}_validateSelectionRanges(e){for(const n of e)if(!this._document._validateSelectionRange(n))throw new oe("document-selection-wrong-position",this,{range:n})}_prepareRange(e){if(this._checkRange(e),e.root==this._document.graveyard)return;const n=ko.fromRange(e);return n.on("change:range",(i,r,o)=>{if(this._hasChangedRange=!0,n.root==this._document.graveyard){this._selectionRestorePosition=o.deletionPosition;const s=this._ranges.indexOf(n);this._ranges.splice(s,1),n.detach()}}),n}updateMarkers(){if(!this._observedMarkers.size)return;const e=[];let n=!1;for(const r of this._model.markers){const o=r.name.split(":",1)[0];if(!this._observedMarkers.has(o))continue;const s=r.getRange();for(const a of this.getRanges())s.containsRange(a,!a.isCollapsed)&&e.push(r)}const i=Array.from(this.markers);for(const r of e)this.markers.has(r)||(this.markers.add(r),n=!0);for(const r of Array.from(this.markers))e.includes(r)||(this.markers.remove(r),n=!0);n&&this.fire("change:marker",{oldMarkers:i,directChange:!1})}_updateMarker(e,n){const i=e.name.split(":",1)[0];if(!this._observedMarkers.has(i))return;let r=!1;const o=Array.from(this.markers),s=this.markers.has(e);if(!n)s&&(this.markers.remove(e),r=!0);else{let a=!1;for(const l of this.getRanges())if(n.containsRange(l,!l.isCollapsed)){a=!0;break}a&&!s?(this.markers.add(e),r=!0):!a&&s&&(this.markers.remove(e),r=!0)}r&&this.fire("change:marker",{oldMarkers:o,directChange:!1})}_updateAttributes(e){const n=gl(this._getSurroundingAttributes()),i=gl(this.getAttributes());if(e)this._attributePriority=new Map,this._attrs=new Map;else for(const[o,s]of this._attributePriority)s=="low"&&(this._attrs.delete(o),this._attributePriority.delete(o));this._setAttributesTo(n);const r=[];for(const[o,s]of this.getAttributes())(!i.has(o)||i.get(o)!==s)&&r.push(o);for(const[o]of i)this.hasAttribute(o)||r.push(o);r.length>0&&this.fire("change:attribute",{attributeKeys:r,directChange:!1})}_setAttribute(e,n,i=!0){const r=i?"normal":"low";return r=="low"&&this._attributePriority.get(e)=="normal"||super.getAttribute(e)===n?!1:(this._attrs.set(e,n),this._attributePriority.set(e,r),!0)}_removeAttribute(e,n=!0){const i=n?"normal":"low";return i=="low"&&this._attributePriority.get(e)=="normal"||(this._attributePriority.set(e,i),!super.hasAttribute(e))?!1:(this._attrs.delete(e),!0)}_setAttributesTo(e){const n=new Set;for(const[i,r]of this.getAttributes())e.get(i)!==r&&this._removeAttribute(i,!1);for(const[i,r]of e)this._setAttribute(i,r,!1)&&n.add(i);return n}*getStoredAttributes(){const e=this.getFirstPosition().parent;if(this.isCollapsed&&e.isEmpty)for(const n of e.getAttributeKeys())n.startsWith(rb)&&(yield[n.substr(rb.length),e.getAttribute(n)])}_getSurroundingAttributes(){const e=this.getFirstPosition(),n=this._model.schema;if(e.root.rootName=="$graveyard")return null;let i=null;if(this.isCollapsed){const r=e.textNode?e.textNode:e.nodeBefore,o=e.textNode?e.textNode:e.nodeAfter;if(this.isGravityOverridden||(i=Ug(r,n)),i||(i=Ug(o,n)),!this.isGravityOverridden&&!i){let s=r;for(;s&&!i;)s=s.previousSibling,i=Ug(s,n)}if(!i){let s=o;for(;s&&!i;)s=s.nextSibling,i=Ug(s,n)}i||(i=this.getStoredAttributes())}else{const r=this.getFirstRange();for(const o of r){if(o.item.is("element")&&n.isObject(o.item)){i=Ug(o.item,n);break}if(o.type=="text"){i=o.item.getAttributes();break}}}return i}_fixGraveyardSelection(e){const n=this._model.schema.getNearestSelectionRange(e);n&&this._pushRange(n)}}function Ug(t,e){if(!t)return null;if(t instanceof ea||t instanceof ni)return t.getAttributes();if(!e.isInline(t))return null;if(!e.isObject(t))return[];const n=[];for(const[i,r]of t.getAttributes())e.checkAttribute("$text",i)&&e.getAttributeProperties(i).copyFromObject!==!1&&n.push([i,r]);return n}function _Oe(t,e){const n=t.document.differ;for(const i of n.getChanges()){if(i.type!="insert")continue;const r=i.position.parent;i.length===r.maxOffset&&t.enqueueChange(e,s=>{const a=Array.from(r.getAttributeKeys()).filter(l=>l.startsWith(rb));for(const l of a)s.removeAttribute(l,r)})}}class iv{_nodes=[];_offsetToNode=[];constructor(e){e&&this._insertNodes(0,e)}[Symbol.iterator](){return this._nodes[Symbol.iterator]()}get length(){return this._nodes.length}get maxOffset(){return this._offsetToNode.length}getNode(e){return this._nodes[e]||null}getNodeAtOffset(e){return this._offsetToNode[e]||null}getNodeIndex(e){return e.index}getNodeStartOffset(e){return e.startOffset}indexToOffset(e){if(e==this._nodes.length)return this.maxOffset;const n=this._nodes[e];if(!n)throw new oe("model-nodelist-index-out-of-bounds",this);return this.getNodeStartOffset(n)}offsetToIndex(e){if(e==this._offsetToNode.length)return this._nodes.length;const n=this._offsetToNode[e];if(!n)throw new oe("model-nodelist-offset-out-of-bounds",this,{offset:e,nodeList:this});return this.getNodeIndex(n)}_insertNodes(e,n){const i=[];for(const o of n){if(!(o instanceof Uf))throw new oe("model-nodelist-insertnodes-not-node",this);i.push(o)}let r=this.indexToOffset(e);m4(this._nodes,i,e),m4(this._offsetToNode,COe(i),r);for(let o=e;oi.index!==null),this._offsetToNode=this._offsetToNode.filter(i=>i.index!==null);let n=0;for(let i=0;ie.toJSON())}}function COe(t){const e=[];let n=0;for(const i of t)for(let r=0;r0){e.children=[];for(const n of this._children)e.children.push(n.toJSON())}return e}_clone(e=!1){const n=e?kOe(this._children):void 0;return new zn(this.name,this.getAttributes(),n)}_appendChild(e){this._insertChild(this.childCount,e)}_insertChild(e,n){const i=SOe(n);for(const r of i)r.parent!==null&&r._remove(),r.parent=this;this._children._insertNodes(e,i)}_removeChildren(e,n=1){const i=this._children._removeNodes(e,n);for(const r of i)r.parent=null;return i}_removeChildrenArray(e){this._children._removeNodesArray(e);for(const n of e)n.parent=null}static fromJSON(e){let n;if(e.children){n=[];for(const i of e.children)i.name?n.push(zn.fromJSON(i)):n.push(ni.fromJSON(i))}return new zn(e.name,e.attributes,n)}}zn.prototype.is=function(t,e){return e?e===this.name&&(t==="element"||t==="model:element"):t==="element"||t==="model:element"||t==="node"||t==="model:node"};function SOe(t){if(typeof t=="string")return[new ni(t)];us(t)||(t=[t]);const e=[];for(const n of t)typeof n=="string"?e.push(new ni(n)):n instanceof ea?e.push(new ni(n.data,n.getAttributes())):e.push(n);return e}function kOe(t){const e=[];for(const n of t)e.push(n._clone(!0));return e}class kG{_dispatchers;constructor(e){this._dispatchers=e}add(e){for(const n of this._dispatchers)e(n);return this}}class TOe extends kG{elementToElement(e){return this.add(UOe(e))}elementToStructure(e){return this.add(WOe(e))}attributeToElement(e){return this.add(qOe(e))}attributeToAttribute(e){return this.add(jOe(e))}markerToElement(e){return this.add(KOe(e))}markerToHighlight(e){return this.add(YOe(e))}markerToData(e){return this.add(GOe(e))}}function TG(){return(t,e,n)=>{if(!n.consumable.consume(e.item,t.name))return;const i=n.writer,r=n.mapper.toViewPosition(e.range.start),o=i.createText(e.item.data);i.insert(r,o)}}function EG(){return(t,e,n)=>{n.convertAttributes(e.item),!e.reconversion&&e.item.is("element")&&!e.item.isEmpty&&n.convertChildren(e.item)}}function EOe(){return(t,e,n)=>{if(e.reconversion)return;const i=n.mapper.toViewPosition(e.position),r=e.position.getShiftedBy(e.length),o=n.mapper.toViewPosition(r,{isPhantom:!0}),s=n.writer.createRange(i,o);AG(s.getTrimmed(),n)}}function xG(t,e){const n=t.createAttributeElement("span",e.attributes);return e.classes&&n._addClass(e.classes),typeof e.priority=="number"&&(n._priority=e.priority),n._id=e.id,n}function xOe(){return(t,e,n)=>{const i=e.selection;if(i.isCollapsed||!n.consumable.consume(i,"selection"))return;const r=[];for(const o of i.getRanges())r.push(n.mapper.toViewRange(o));n.writer.setSelection(r,{backward:i.isBackward})}}function AOe(){return(t,e,n)=>{const i=e.selection;if(!i.isCollapsed||!n.consumable.consume(i,"selection"))return;const r=n.writer,o=i.getFirstPosition(),s=n.mapper.toViewPosition(o),a=r.breakAttributes(s);r.setSelection(a)}}function POe(){return(t,e,n)=>{const i=n.writer,r=i.document.selection;for(const o of r.getRanges())o.isCollapsed&&o.end.parent.isAttached()&&n.writer.mergeAttributes(o.start);i.setSelection(null)}}function IOe(t){return(e,n,i)=>{if(!i.consumable.test(n.item,e.name))return;const r=t(n.attributeOldValue,i,n),o=t(n.attributeNewValue,i,n);if(!r&&!o)return;i.consumable.consume(n.item,e.name);const s=i.writer,a=s.document.selection;if(n.item instanceof Xo||n.item instanceof cs)s.wrap(a.getFirstRange(),o);else{let l=i.mapper.toViewRange(n.range);n.attributeOldValue!==null&&r&&(l=s.unwrap(l,r)),n.attributeNewValue!==null&&o&&s.wrap(l,o)}}}function ROe(t,e=nLe){return(n,i,r)=>{if(!e(i.item,r.consumable,{preflight:!0}))return;const o=t(i.item,r,i);if(!o)return;e(i.item,r.consumable);const s=i.reconversion&&PG(i.item,r)||r.mapper.toViewPosition(i.range.start);r.mapper.bindElements(i.item,o),r.writer.insert(s,o),r.convertAttributes(i.item),LG(o,i.item.getChildren(),r,{reconversion:i.reconversion})}}function MOe(t,e){return(n,i,r)=>{if(!e(i.item,r.consumable,{preflight:!0}))return;const o=new Map;r.writer._registerSlotFactory(ZOe(i.item,o,r));const s=t(i.item,r,i);if(r.writer._clearSlotFactory(),!s)return;QOe(i.item,o,r),e(i.item,r.consumable);const a=i.reconversion&&PG(i.item,r)||r.mapper.toViewPosition(i.range.start);r.mapper.bindElements(i.item,s),r.writer.insert(a,s),r.convertAttributes(i.item),eLe(s,o,r,{reconversion:i.reconversion})}}function OOe(t){return(e,n,i)=>{n.isOpening=!0;const r=t(n,i);n.isOpening=!1;const o=t(n,i);if(!r||!o)return;const s=n.markerRange;if(s.isCollapsed&&!i.consumable.consume(s,e.name))return;for(const u of s)if(!i.consumable.consume(u.item,e.name))return;const a=i.mapper,l=i.writer;l.insert(a.toViewPosition(s.start),r),i.mapper.bindElementToMarker(r,n.markerName),s.isCollapsed||(l.insert(a.toViewPosition(s.end),o),i.mapper.bindElementToMarker(o,n.markerName)),e.stop()}}function AG(t,e){const n=e.writer.remove(t);for(const i of e.writer.createRangeIn(n).getItems())e.mapper.unbindViewElement(i,{defer:!0});return t.start}function PG(t,e){const n=e.mapper.toViewElement(t);return n&&AG(e.writer.createRangeOn(n),e)}function LOe(){return(t,e,n)=>{const i=n.mapper.markerNameToElements(e.markerName);if(i){for(const r of i)n.mapper.unbindElementFromMarkerName(r,e.markerName),n.writer.clear(n.writer.createRangeOn(r),r);n.writer.clearClonedElementsGroup(e.markerName),t.stop()}}}function DOe(t){return(e,n,i)=>{const r=t(n.markerName,i);if(!r)return;const o=n.markerRange;i.consumable.consume(o,e.name)&&(D4(o,!1,i,n,r),D4(o,!0,i,n,r),e.stop())}}function D4(t,e,n,i,r){const o=e?t.start:t.end,s=o.nodeAfter&&o.nodeAfter.is("element")?o.nodeAfter:null,a=o.nodeBefore&&o.nodeBefore.is("element")?o.nodeBefore:null;if(s||a){let u,c;e&&s||!e&&!a?(u=s,c=!0):(u=a,c=!1);const d=n.mapper.toViewElement(u);if(d){NOe(d,e,c,n,i,r);return}}const l=n.mapper.toViewPosition(o);BOe(l,e,n,i,r)}function NOe(t,e,n,i,r,o){const s=`data-${o.group}-${e?"start":"end"}-${n?"before":"after"}`,a=t.hasAttribute(s)?t.getAttribute(s).split(","):[];a.unshift(o.name),i.writer.setAttribute(s,a.join(","),t),i.mapper.bindElementToMarker(t,r.markerName)}function BOe(t,e,n,i,r){const o=`${r.group}-${e?"start":"end"}`,s=r.name?{name:r.name}:null,a=n.writer.createUIElement(o,s);n.writer.insert(t,a),n.mapper.bindElementToMarker(a,i.markerName)}function VOe(t){return(e,n,i)=>{const r=t(n.markerName,i);if(!r)return;const o=i.mapper.markerNameToElements(n.markerName);if(!o)return;for(const a of o)i.mapper.unbindElementFromMarkerName(a,n.markerName),a.is("containerElement")?(s(`data-${r.group}-start-before`,a),s(`data-${r.group}-start-after`,a),s(`data-${r.group}-end-before`,a),s(`data-${r.group}-end-after`,a)):i.writer.clear(i.writer.createRangeOn(a),a);i.writer.clearClonedElementsGroup(n.markerName),e.stop();function s(a,l){if(l.hasAttribute(a)){const u=new Set(l.getAttribute(a).split(","));u.delete(r.name),u.size==0?i.writer.removeAttribute(a,l):i.writer.setAttribute(a,Array.from(u).join(","),l)}}}}function FOe(t){return(e,n,i)=>{if(!i.consumable.test(n.item,e.name))return;const r=t(n.attributeOldValue,i,n),o=t(n.attributeNewValue,i,n);if(!r&&!o)return;i.consumable.consume(n.item,e.name);const s=i.mapper.toViewElement(n.item),a=i.writer;if(!s)throw new oe("conversion-attribute-to-attribute-on-text",i.dispatcher,n);if(n.attributeOldValue!==null&&r){let l=r.value;r.key=="style"&&(typeof r.value=="string"?l=new tv(a.document.stylesProcessor).setTo(r.value).getStylesEntries().map(([u])=>u):l=Object.keys(r.value)),a.removeAttribute(r.key,l,s)}if(n.attributeNewValue!==null&&o){let l=o.value;o.key=="style"&&typeof o.value=="string"&&(l=Object.fromEntries(new tv(a.document.stylesProcessor).setTo(o.value).getStylesEntries())),a.setAttribute(o.key,l,!1,s)}}}function $Oe(t){return(e,n,i)=>{if(!n.item||!(n.item instanceof Xo||n.item instanceof cs)&&!n.item.is("$textProxy"))return;const r=JM(t,n,i);if(!r||!i.consumable.consume(n.item,e.name))return;const o=i.writer,s=xG(o,r),a=o.document.selection;if(n.item instanceof Xo||n.item instanceof cs)o.wrap(a.getFirstRange(),s);else{const l=i.mapper.toViewRange(n.range),u=o.wrap(l,s);for(const c of u.getItems())if(c.is("attributeElement")&&c.isSimilar(s)){i.mapper.bindElementToMarker(c,n.markerName);break}}}}function zOe(t){return(e,n,i)=>{if(!n.item||!(n.item instanceof zn))return;const r=JM(t,n,i);if(!r||!i.consumable.test(n.item,e.name))return;const o=i.mapper.toViewElement(n.item);if(o&&o.getCustomProperty("addHighlight")){i.consumable.consume(n.item,e.name);for(const a of Ee._createIn(n.item))i.consumable.consume(a.item,e.name);o.getCustomProperty("addHighlight")(o,r,i.writer),i.mapper.bindElementToMarker(o,n.markerName)}}}function HOe(t){return(e,n,i)=>{if(n.markerRange.isCollapsed)return;const r=JM(t,n,i);if(!r)return;const o=xG(i.writer,r),s=i.mapper.markerNameToElements(n.markerName);if(s){for(const a of s)i.mapper.unbindElementFromMarkerName(a,n.markerName),a.is("attributeElement")?i.writer.unwrap(i.writer.createRangeOn(a),o):a.getCustomProperty("removeHighlight")(a,r.id,i.writer);i.writer.clearClonedElementsGroup(n.markerName),e.stop()}}}function UOe(t){const e=IG(t.model),n=ob(t.view,"container");return e.attributes.length&&(e.children=!0),i=>{i.on(`insert:${e.name}`,ROe(n,OG(e)),{priority:t.converterPriority||"normal"}),(e.children||e.attributes.length)&&i.on("reduceChanges",MG(e),{priority:"low"})}}function WOe(t){const e=IG(t.model),n=ob(t.view,"container");return e.children=!0,i=>{if(i._conversionApi.schema.checkChild(e.name,"$text"))throw new oe("conversion-element-to-structure-disallowed-text",i,{elementName:e.name});i.on(`insert:${e.name}`,MOe(n,OG(e)),{priority:t.converterPriority||"normal"}),i.on("reduceChanges",MG(e),{priority:"low"})}}function qOe(t){t=Bo(t);let e=t.model;typeof e=="string"&&(e={key:e});let n=`attribute:${e.key}`;if(e.name&&(n+=":"+e.name),e.values)for(const r of e.values)t.view[r]=ob(t.view[r],"attribute");else t.view=ob(t.view,"attribute");const i=RG(t);return r=>{r.on(n,IOe(i),{priority:t.converterPriority||"normal"})}}function jOe(t){t=Bo(t);let e=t.model;typeof e=="string"&&(e={key:e});let n=`attribute:${e.key}`;if(e.name&&(n+=":"+e.name),e.values)for(const r of e.values)t.view[r]=N4(t.view[r]);else t.view=N4(t.view);const i=RG(t);return r=>{r.on(n,FOe(i),{priority:t.converterPriority||"normal"})}}function KOe(t){const e=ob(t.view,"ui");return n=>{n.on(`addMarker:${t.model}`,OOe(e),{priority:t.converterPriority||"normal"}),n.on(`removeMarker:${t.model}`,LOe(),{priority:t.converterPriority||"normal"})}}function GOe(t){t=Bo(t);const e=t.model;let n=t.view;return n||(n=i=>({group:e,name:i.substr(t.model.length+1)})),i=>{i.on(`addMarker:${e}`,DOe(n),{priority:t.converterPriority||"normal"}),i.on(`removeMarker:${e}`,VOe(n),{priority:t.converterPriority||"normal"})}}function YOe(t){return e=>{e.on(`addMarker:${t.model}`,$Oe(t.view),{priority:t.converterPriority||"normal"}),e.on(`addMarker:${t.model}`,zOe(t.view),{priority:t.converterPriority||"normal"}),e.on(`removeMarker:${t.model}`,HOe(t.view),{priority:t.converterPriority||"normal"})}}function IG(t){return typeof t=="string"&&(t={name:t}),{name:t.name,attributes:t.attributes?li(t.attributes):[],children:!!t.children}}function ob(t,e){return typeof t=="function"?t:(n,i)=>XOe(t,i,e)}function XOe(t,e,n){typeof t=="string"&&(t={name:t});let i;const r=e.writer,o=Object.assign({},t.attributes);if(n=="container")i=r.createContainerElement(t.name,o);else if(n=="attribute"){const s={priority:t.priority||hm.DEFAULT_PRIORITY};i=r.createAttributeElement(t.name,o,s)}else i=r.createUIElement(t.name,o);if(t.styles){const s=Object.keys(t.styles);for(const a of s)r.setStyle(a,t.styles[a],i)}if(t.classes){const s=t.classes;if(typeof s=="string")r.addClass(s,i);else for(const a of s)r.addClass(a,i)}return i}function RG(t){return t.model.values?(e,n,i)=>{const r=t.view[e];return r?r(e,n,i):null}:t.view}function N4(t){return typeof t=="string"?e=>({key:t,value:e}):typeof t=="object"?t.value?()=>t:e=>({key:t.key,value:e}):t}function JM(t,e,n){const i=typeof t=="function"?t(e,n):{...t};return i?(i.priority||(i.priority=10),i.id||(i.id=e.markerName),i):null}function JOe(t){return(e,n)=>{if(!e.is("element",t.name))return!1;if(n.type=="attribute"){if(t.attributes.includes(n.attributeKey))return!0}else{if(t.children)return!0}return!1}}function MG(t){const e=JOe(t);return(n,i)=>{const r=[];i.reconvertedElements||(i.reconvertedElements=new Set);for(const o of i.changes){const s=o.type=="attribute"?o.range.start.nodeAfter:o.position.parent;if(!s||!e(s,o)||o.type=="reinsert"){r.push(o);continue}if(o.type=="insert"&&o.action=="rename"&&i.refreshedItems.add(o.position.nodeAfter),!i.reconvertedElements.has(s)){i.reconvertedElements.add(s);const a=Be._createBefore(s);let l=r.length;for(let u=r.length-1;u>=0;u--){const c=r[u],f=(c.type=="attribute"?c.range.start:c.position).compareWith(a);if(f=="before"||c.type=="remove"&&f=="same")break;l=u}r.splice(l,0,{type:"reinsert",name:s.name,position:a,length:1})}}i.changes=r}}function OG(t){return(e,n,i={})=>{const r=["insert"];for(const o of t.attributes)e.hasAttribute(o)&&r.push(`attribute:${o}`);return r.every(o=>n.test(e,o))?(i.preflight||r.forEach(o=>n.consume(e,o)),!0):!1}}function ZOe(t,e,n){return(i,r)=>{const o=i.createContainerElement("$slot");let s=null;if(r==="children")s=Array.from(t.getChildren());else if(typeof r=="function")s=Array.from(t.getChildren()).filter(a=>r(a));else throw new oe("conversion-slot-mode-unknown",n.dispatcher,{modeOrFilter:r});return e.set(o,s),o}}function QOe(t,e,n){const i=Array.from(e.values()).flat(),r=new Set(i);if(r.size!=i.length)throw new oe("conversion-slot-filter-overlap",n.dispatcher,{element:t});if(r.size!=t.childCount)throw new oe("conversion-slot-filter-incomplete",n.dispatcher,{element:t})}function eLe(t,e,n,i){n.mapper.on("modelToViewPosition",s,{priority:"highest"});let r=null,o=null;for([r,o]of e)LG(t,o,n,i),n.writer.setCustomProperty("$structureSlotParent",!0,r.parent),n.writer.move(n.writer.createRangeIn(r),n.writer.createPositionBefore(r)),n.writer.remove(r);n.mapper.off("modelToViewPosition",s);function s(a,l){const u=l.modelPosition.nodeAfter,c=o.indexOf(u);c<0||(l.viewPosition=l.mapper.findPositionIn(r,c))}}function LG(t,e,n,i){for(const r of e)tLe(t.root,r,n,i)||n.convertItem(r)}function tLe(t,e,n,i){const{writer:r,mapper:o}=n;if(!i.reconversion)return!1;const s=o.toViewElement(e);return!s||s.root==t||!n.canReuseView(s)?!1:(r.move(r.createRangeOn(s),o.toViewPosition(Be._createBefore(e))),!0)}function nLe(t,e,{preflight:n}={}){return n?e.test(t,"insert"):e.consume(t,"insert")}function DG(t){const{schema:e,document:n}=t.model;for(const i of n.getRoots())if(i.isEmpty&&!e.checkChild(i,"$text")&&e.checkChild(i,"paragraph"))return t.insertElement("paragraph",i),!0;return!1}function NG(t,e,n){const i=n.createContext(t);return!(!n.checkChild(i,"paragraph")||!n.checkChild(i.push("paragraph"),e))}function BG(t,e){const n=e.createElement("paragraph");return e.insert(n,t),e.createPositionAt(n,0)}class iLe extends kG{elementToElement(e){return this.add(VG(e))}elementToAttribute(e){return this.add(sLe(e))}attributeToAttribute(e){return this.add(aLe(e))}elementToMarker(e){return this.add(lLe(e))}dataToMarker(e){return this.add(uLe(e))}}function B4(){return(t,e,n)=>{if(!e.modelRange&&n.consumable.consume(e.viewItem,{name:!0})){const{modelRange:i,modelCursor:r}=n.convertChildren(e.viewItem,e.modelCursor);e.modelRange=i,e.modelCursor=r}}}function rLe(){return(t,e,{schema:n,consumable:i,writer:r})=>{let o=e.modelCursor;if(!i.test(e.viewItem))return;if(!n.checkChild(o,"$text")){if(!NG(o,"$text",n)||e.viewItem.data.trim().length==0)return;o=BG(o,r)}i.consume(e.viewItem);const s=r.createText(e.viewItem.data);r.insert(s,o),e.modelRange=r.createRange(o,o.getShiftedBy(s.offsetSize)),e.modelCursor=e.modelRange.end}}function oLe(t,e){return(n,i)=>{const r=i.newSelection,o=[];for(const a of r.getRanges())o.push(e.toModelRange(a));const s=t.createSelection(o,{backward:r.isBackward});s.isEqual(t.document.selection)||t.change(a=>{a.setSelection(s)})}}function VG(t){t=Bo(t);const e=TA(t),n=ZM(t.view),i=n?`element:${n}`:"element";return r=>{r.on(i,e,{priority:t.converterPriority||"normal"})}}function sLe(t){t=Bo(t),FG(t);const e=$G(t,!1),n=ZM(t.view),i=n?`element:${n}`:"element";return r=>{r.on(i,e,{priority:t.converterPriority||"low"})}}function aLe(t){t=Bo(t);let e=null;(typeof t.view=="string"||t.view.key)&&(e=fLe(t)),FG(t,e);const n=$G(t,!0);return i=>{i.on("element",n,{priority:t.converterPriority||"low"})}}function lLe(t){const e=gLe(t.model);return VG({...t,model:e})}function uLe(t){t=Bo(t),t.model||(t.model=r=>r?t.view+":"+r:t.view);const e={view:t.view,model:t.model},n=TA(V4(e,"start")),i=TA(V4(e,"end"));return r=>{r.on(`element:${t.view}-start`,n,{priority:t.converterPriority||"normal"}),r.on(`element:${t.view}-end`,i,{priority:t.converterPriority||"normal"});const o=ou.low,s=ou.highest,a=ou.get(t.converterPriority)/s;r.on("element",cLe(e),{priority:o+a})}}function cLe(t){return(e,n,i)=>{const r=`data-${t.view}`;if(!i.consumable.test(n.viewItem,{attributes:r+"-end-after"})&&!i.consumable.test(n.viewItem,{attributes:r+"-start-after"})&&!i.consumable.test(n.viewItem,{attributes:r+"-end-before"})&&!i.consumable.test(n.viewItem,{attributes:r+"-start-before"}))return;n.modelRange||Object.assign(n,i.convertChildren(n.viewItem,n.modelCursor)),i.consumable.consume(n.viewItem,{attributes:r+"-end-after"})&&o(n.modelRange.end,n.viewItem.getAttribute(r+"-end-after").split(",")),i.consumable.consume(n.viewItem,{attributes:r+"-start-after"})&&o(n.modelRange.end,n.viewItem.getAttribute(r+"-start-after").split(",")),i.consumable.consume(n.viewItem,{attributes:r+"-end-before"})&&o(n.modelRange.start,n.viewItem.getAttribute(r+"-end-before").split(",")),i.consumable.consume(n.viewItem,{attributes:r+"-start-before"})&&o(n.modelRange.start,n.viewItem.getAttribute(r+"-start-before").split(","));function o(s,a){for(const l of a){const u=t.model(l,i),c=i.writer.createElement("$marker",{"data-name":u});i.writer.insert(c,s),n.modelCursor.isEqual(s)?n.modelCursor=n.modelCursor.getShiftedBy(1):n.modelCursor=n.modelCursor._getTransformedByInsertion(s,1),n.modelRange=n.modelRange._getTransformedByInsertion(s,1)[0]}}}}function ZM(t){return typeof t=="string"?t:typeof t=="object"&&typeof t.name=="string"?t.name:null}function TA(t){const e=new pl(t.view);return(n,i,r)=>{const o=e.match(i.viewItem);if(!o)return;const s=o.match;if(s.name=!0,!r.consumable.test(i.viewItem,s))return;const a=dLe(t.model,i.viewItem,r);a&&r.safeInsert(a,i.modelCursor)&&(r.consumable.consume(i.viewItem,s),r.convertChildren(i.viewItem,a),r.updateConversionResult(a,i))}}function dLe(t,e,n){return t instanceof Function?t(e,n):n.writer.createElement(t)}function fLe(t){typeof t.view=="string"&&(t.view={key:t.view});const e=t.view.key,n=typeof t.view.value>"u"?/[\s\S]*/:t.view.value;let i;return e=="class"||e=="style"?i={[e=="class"?"classes":"styles"]:n}:i={attributes:{[e]:n}},t.view.name&&(i.name=t.view.name),t.view=i,e}function FG(t,e=null){const n=e===null?!0:o=>o.getAttribute(e),i=typeof t.model!="object"?t.model:t.model.key,r=typeof t.model!="object"||typeof t.model.value>"u"?n:t.model.value;t.model={key:i,value:r}}function $G(t,e){const n=new pl(t.view);return(i,r,o)=>{if(!r.modelRange&&e)return;const s=n.match(r.viewItem);if(!s||(hLe(t.view,r.viewItem)?s.match.name=!0:delete s.match.name,!o.consumable.test(r.viewItem,s.match)))return;const a=t.model.key,l=typeof t.model.value=="function"?t.model.value(r.viewItem,o,r):t.model.value;if(l==null)return;r.modelRange||Object.assign(r,o.convertChildren(r.viewItem,r.modelCursor)),mLe(r.modelRange,{key:a,value:l},e,o)&&(o.consumable.test(r.viewItem,{name:!0})&&(s.match.name=!0),o.consumable.consume(r.viewItem,s.match))}}function hLe(t,e){const n=typeof t=="function"?t(e):t;return typeof n=="object"&&!ZM(n)?!1:!n.classes&&!n.attributes&&!n.styles}function mLe(t,e,n,i){let r=!1;for(const o of Array.from(t.getItems({shallow:n})))i.schema.checkAttribute(o,e.key)&&(r=!0,!o.hasAttribute(e.key)&&i.writer.setAttribute(e.key,e.value,o));return r}function gLe(t){return(e,n)=>{const i=typeof t=="string"?t:t(e,n);return n.writer.createElement("$marker",{"data-name":i})}}function V4(t,e){const n=(i,r)=>{const o=i.getAttribute("name"),s=t.model(o,r);return r.writer.createElement("$marker",{"data-name":s})};return{view:`${t.view}-${e}`,model:n}}class pLe extends Ln(){model;view;mapper;downcastDispatcher;constructor(e,n){super(),this.model=e,this.view=new aOe(n),this.mapper=new _G,this.downcastDispatcher=new CG({mapper:this.mapper,schema:e.schema});const i=this.model.document,r=i.selection,o=this.model.markers;this.listenTo(this.model,"_beforeChanges",()=>{this.view._disableRendering(!0)},{priority:"highest"}),this.listenTo(this.model,"_afterChanges",()=>{this.view._disableRendering(!1)},{priority:"lowest"}),this.listenTo(i,"change",()=>{this.view.change(s=>{this.downcastDispatcher.convertChanges(i.differ,o,s),this.downcastDispatcher.convertSelection(r,o,s)})},{priority:"low"}),this.listenTo(this.view.document,"selectionChange",oLe(this.model,this.mapper)),this.downcastDispatcher.on("insert:$text",TG(),{priority:"lowest"}),this.downcastDispatcher.on("insert",EG(),{priority:"lowest"}),this.downcastDispatcher.on("remove",EOe(),{priority:"low"}),this.downcastDispatcher.on("cleanSelection",POe()),this.downcastDispatcher.on("selection",xOe(),{priority:"low"}),this.downcastDispatcher.on("selection",AOe(),{priority:"low"}),this.view.document.roots.bindTo(this.model.document.roots).using(s=>{if(s.rootName=="$graveyard")return null;const a=new cG(this.view.document,s.name);return a.rootName=s.rootName,this.mapper.bindElements(s,a),a})}destroy(){this.view.destroy(),this.stopListening()}reconvertMarker(e){const n=typeof e=="string"?e:e.name,i=this.model.markers.get(n);if(!i)throw new oe("editingcontroller-reconvertmarker-marker-not-exist",this,{markerName:n});this.model.change(()=>{this.model.markers._refresh(i)})}reconvertItem(e){this.model.change(()=>{this.model.document.differ._refreshItem(e)})}}class vLe extends Ln(){_sourceDefinitions={};_attributeProperties=Object.create(null);_customChildChecks=new Map;_customAttributeChecks=new Map;_genericCheckSymbol=Symbol("$generic");_compiledDefinitions;constructor(){super(),this.decorate("checkChild"),this.decorate("checkAttribute"),this.on("checkAttribute",(e,n)=>{n[0]=new su(n[0])},{priority:"highest"}),this.on("checkChild",(e,n)=>{n[0]=new su(n[0]),n[1]=this.getDefinition(n[1])},{priority:"highest"})}register(e,n){if(this._sourceDefinitions[e])throw new oe("schema-cannot-register-item-twice",this,{itemName:e});this._sourceDefinitions[e]=[Object.assign({},n)],this._clearCache()}extend(e,n){if(!this._sourceDefinitions[e])throw new oe("schema-cannot-extend-missing-item",this,{itemName:e});this._sourceDefinitions[e].push(Object.assign({},n)),this._clearCache()}getDefinitions(){return this._compiledDefinitions||this._compile(),this._compiledDefinitions}getDefinition(e){let n;return typeof e=="string"?n=e:"is"in e&&(e.is("$text")||e.is("$textProxy"))?n="$text":n=e.name,this.getDefinitions()[n]}isRegistered(e){return!!this.getDefinition(e)}isBlock(e){const n=this.getDefinition(e);return!!(n&&n.isBlock)}isLimit(e){const n=this.getDefinition(e);return n?!!(n.isLimit||n.isObject):!1}isObject(e){const n=this.getDefinition(e);return n?!!(n.isObject||n.isLimit&&n.isSelectable&&n.isContent):!1}isInline(e){const n=this.getDefinition(e);return!!(n&&n.isInline)}isSelectable(e){const n=this.getDefinition(e);return n?!!(n.isSelectable||n.isObject):!1}isContent(e){const n=this.getDefinition(e);return n?!!(n.isContent||n.isObject):!1}checkChild(e,n){return n?this._checkContextMatch(e,n):!1}checkAttribute(e,n){const i=this.getDefinition(e.last);if(!i)return!1;const r=this._evaluateAttributeChecks(e,n);return r!==void 0?r:i.allowAttributes.includes(n)}checkMerge(e,n){if(e instanceof Be){const i=e.nodeBefore,r=e.nodeAfter;if(!(i instanceof zn))throw new oe("schema-check-merge-no-element-before",this);if(!(r instanceof zn))throw new oe("schema-check-merge-no-element-after",this);return this.checkMerge(i,r)}if(this.isLimit(e)||this.isLimit(n))return!1;for(const i of n.getChildren())if(!this.checkChild(e,i))return!1;return!0}addChildCheck(e,n){const i=n!==void 0?n:this._genericCheckSymbol,r=this._customChildChecks.get(i)||[];r.push(e),this._customChildChecks.set(i,r)}addAttributeCheck(e,n){const i=n!==void 0?n:this._genericCheckSymbol,r=this._customAttributeChecks.get(i)||[];r.push(e),this._customAttributeChecks.set(i,r)}setAttributeProperties(e,n){this._attributeProperties[e]=Object.assign(this.getAttributeProperties(e),n)}getAttributeProperties(e){return this._attributeProperties[e]||Object.create(null)}getLimitElement(e){let n;for(e instanceof Be?n=e.parent:n=(e instanceof Ee?[e]:Array.from(e.getRanges())).reduce((r,o)=>{const s=o.getCommonAncestor();return r?r.getCommonAncestor(s,{includeSelf:!0}):s},null);!this.isLimit(n)&&n.parent;)n=n.parent;return n}checkAttributeInSelection(e,n){if(e.isCollapsed){const r=[...e.getFirstPosition().getAncestors(),new ni("",e.getAttributes())];return this.checkAttribute(r,n)}else{const i=e.getRanges();for(const r of i)for(const o of r)if(this.checkAttribute(o.item,n))return!0}return!1}*getValidRanges(e,n,i={}){e=OLe(e);for(const r of e)yield*this._getValidRangesForRange(r,n,i)}getNearestSelectionRange(e,n="both"){if(e.root.rootName=="$graveyard")return null;if(this.checkChild(e,"$text"))return new Ee(e);let i,r;const o=e.getAncestors().reverse().find(s=>this.isLimit(s))||e.root;(n=="both"||n=="backward")&&(i=new Ql({boundaries:Ee._createIn(o),startPosition:e,direction:"backward"})),(n=="both"||n=="forward")&&(r=new Ql({boundaries:Ee._createIn(o),startPosition:e}));for(const s of MLe(i,r)){const a=s.walker==i?"elementEnd":"elementStart",l=s.value;if(l.type==a&&this.isObject(l.item))return Ee._createOn(l.item);if(this.checkChild(l.nextPosition,"$text"))return new Ee(l.nextPosition)}return null}findAllowedParent(e,n){let i=e.parent;for(;i;){if(this.checkChild(i,n))return i;if(this.isLimit(i))return null;i=i.parent}return null}setAllowedAttributes(e,n,i){const r=i.model;for(const[o,s]of Object.entries(n))r.schema.checkAttribute(e,o)&&i.setAttribute(o,s,e)}removeDisallowedAttributes(e,n){for(const i of e)if(i.is("$text"))F4(this,i,n);else{const o=Ee._createIn(i).getPositions();for(const s of o){const a=s.nodeBefore||s.parent;F4(this,a,n)}}}getAttributesWithProperty(e,n,i){const r={};for(const[o,s]of e.getAttributes()){const a=this.getAttributeProperties(o);a[n]!==void 0&&(i===void 0||i===a[n])&&(r[o]=s)}return r}createContext(e){return new su(e)}_clearCache(){this._compiledDefinitions=null}_compile(){const e={},n=this._sourceDefinitions,i=Object.keys(n);for(const o of i)e[o]=bLe(n[o],o);const r=Object.values(e);for(const o of r)yLe(e,o),wLe(e,o),_Le(e,o),CLe(e,o);for(const o of r)SLe(e,o);for(const o of r)kLe(e,o);for(const o of r)TLe(e,o);for(const o of r)xLe(e,o);for(const o of r)ALe(e,o);this._compiledDefinitions=ELe(e)}_checkContextMatch(e,n){const i=e.last;let r=this._evaluateChildChecks(e,n);if(r=r!==void 0?r:n.allowIn.includes(i.name),!r)return!1;const o=this.getDefinition(i),s=e.trimLast();return o?s.length==0?!0:this._checkContextMatch(s,o):!1}_evaluateChildChecks(e,n){const i=this._customChildChecks.get(this._genericCheckSymbol)||[],r=this._customChildChecks.get(n.name)||[];for(const o of[...i,...r]){const s=o(e,n);if(s!==void 0)return s}}_evaluateAttributeChecks(e,n){const i=this._customAttributeChecks.get(this._genericCheckSymbol)||[],r=this._customAttributeChecks.get(n)||[];for(const o of[...i,...r]){const s=o(e,n);if(s!==void 0)return s}}*_getValidRangesForRange(e,n,i){let r=e.start,o=e.start;for(const s of e.getItems({shallow:!0})){if(s.is("element"))if(i.includeEmptyRanges&&s.isEmpty){const a=this.createContext(s);this.checkChild(a,"$text")&&this.checkAttribute(a.push("$text"),n)&&(yield Ee._createIn(s))}else yield*this._getValidRangesForRange(Ee._createIn(s),n,i);this.checkAttribute(s,n)||(r.isEqual(o)||(yield new Ee(r,o)),r=Be._createAfter(s)),o=Be._createAfter(s)}r.isEqual(o)||(yield new Ee(r,o))}findOptimalInsertionRange(e,n){const i=e.getSelectedElement();if(i&&this.isObject(i)&&!this.isInline(i))return n=="before"||n=="after"?new Ee(Be._createAt(i,n)):Ee._createOn(i);const r=Mi(e.getSelectedBlocks());if(!r)return new Ee(e.focus);if(r.isEmpty)return new Ee(Be._createAt(r,0));const o=Be._createAfter(r);return e.focus.isTouching(o)?new Ee(o):new Ee(Be._createBefore(r))}}class su{_items;constructor(e){if(e instanceof su)return e;let n;typeof e=="string"?n=[e]:Array.isArray(e)?n=e:n=e.getAncestors({includeSelf:!0}),this._items=n.map(RLe)}get length(){return this._items.length}get last(){return this._items[this._items.length-1]}[Symbol.iterator](){return this._items[Symbol.iterator]()}push(e){const n=new su([e]);return n._items=[...this._items,...n._items],n}trimLast(){const e=new su([]);return e._items=this._items.slice(0,-1),e}getItem(e){return this._items[e]}*getNames(){yield*this._items.map(e=>e.name)}endsWith(e){return Array.from(this.getNames()).join(" ").endsWith(e)}startsWith(e){return Array.from(this.getNames()).join(" ").startsWith(e)}}function bLe(t,e){const n={name:e,allowIn:new Set,allowChildren:new Set,disallowIn:new Set,disallowChildren:new Set,allowContentOf:new Set,allowWhere:new Set,allowAttributes:new Set,disallowAttributes:new Set,allowAttributesOf:new Set,inheritTypesFrom:new Set};return PLe(t,n),Ra(t,n,"allowIn"),Ra(t,n,"allowChildren"),Ra(t,n,"disallowIn"),Ra(t,n,"disallowChildren"),Ra(t,n,"allowContentOf"),Ra(t,n,"allowWhere"),Ra(t,n,"allowAttributes"),Ra(t,n,"disallowAttributes"),Ra(t,n,"allowAttributesOf"),Ra(t,n,"inheritTypesFrom"),ILe(t,n),n}function yLe(t,e){for(const n of e.allowIn){const i=t[n];i?i.allowChildren.add(e.name):e.allowIn.delete(n)}}function wLe(t,e){for(const n of e.allowChildren){const i=t[n];i?i.allowIn.add(e.name):e.allowChildren.delete(n)}}function _Le(t,e){for(const n of e.disallowIn){const i=t[n];i?i.disallowChildren.add(e.name):e.disallowIn.delete(n)}}function CLe(t,e){for(const n of e.disallowChildren){const i=t[n];i?i.disallowIn.add(e.name):e.disallowChildren.delete(n)}}function SLe(t,e){for(const n of e.disallowChildren)e.allowChildren.delete(n);for(const n of e.disallowIn)e.allowIn.delete(n);for(const n of e.disallowAttributes)e.allowAttributes.delete(n)}function kLe(t,e){for(const n of e.allowContentOf){const i=t[n];i&&(i.disallowChildren.forEach(r=>{e.allowChildren.has(r)||(e.disallowChildren.add(r),t[r].disallowIn.add(e.name))}),i.allowChildren.forEach(r=>{e.disallowChildren.has(r)||(e.allowChildren.add(r),t[r].allowIn.add(e.name))}))}}function TLe(t,e){for(const n of e.allowWhere){const i=t[n];i&&(i.disallowIn.forEach(r=>{e.allowIn.has(r)||(e.disallowIn.add(r),t[r].disallowChildren.add(e.name))}),i.allowIn.forEach(r=>{e.disallowIn.has(r)||(e.allowIn.add(r),t[r].allowChildren.add(e.name))}))}}function ELe(t){const e={};for(const n of Object.values(t))e[n.name]={name:n.name,isBlock:!!n.isBlock,isContent:!!n.isContent,isInline:!!n.isInline,isLimit:!!n.isLimit,isObject:!!n.isObject,isSelectable:!!n.isSelectable,allowIn:Array.from(n.allowIn).filter(i=>!!t[i]),allowChildren:Array.from(n.allowChildren).filter(i=>!!t[i]),allowAttributes:Array.from(n.allowAttributes)};return e}function xLe(t,e){for(const n of e.allowAttributesOf){const i=t[n];if(!i)return;i.allowAttributes.forEach(r=>{e.disallowAttributes.has(r)||e.allowAttributes.add(r)})}}function ALe(t,e){for(const n of e.inheritTypesFrom){const i=t[n];if(i){const r=Object.keys(i).filter(o=>o.startsWith("is"));for(const o of r)o in e||(e[o]=i[o])}}}function PLe(t,e){for(const n of t){const i=Object.keys(n).filter(r=>r.startsWith("is"));for(const r of i)e[r]=!!n[r]}}function Ra(t,e,n){for(const i of t){let r=i[n];typeof r=="string"&&(r=[r]),Array.isArray(r)&&r.forEach(o=>e[n].add(o))}}function ILe(t,e){for(const n of t){const i=n.inheritAllFrom;i&&(e.allowContentOf.add(i),e.allowWhere.add(i),e.allowAttributesOf.add(i),e.inheritTypesFrom.add(i))}}function RLe(t){return typeof t=="string"||t.is("documentFragment")?{name:typeof t=="string"?t:"$documentFragment",*getAttributeKeys(){},getAttribute(){}}:{name:t.is("element")?t.name:"$text",*getAttributeKeys(){yield*t.getAttributeKeys()},getAttribute(e){return t.getAttribute(e)}}}function*MLe(t,e){let n=!1;for(;!n;){if(n=!0,t){const i=t.next();i.done||(n=!1,yield{walker:t,value:i.value})}if(e){const i=e.next();i.done||(n=!1,yield{walker:e,value:i.value})}}}function*OLe(t){for(const e of t)yield*e.getMinimalFlatRanges()}function F4(t,e,n){for(const i of e.getAttributeKeys())t.checkAttribute(e,i)||n.removeAttribute(i,e)}class LLe extends Fn(){conversionApi;_splitParts=new Map;_cursorParents=new Map;_modelCursor=null;_emptyElementsToKeep=new Set;constructor(e){super(),this.conversionApi={...e,consumable:null,writer:null,store:null,convertItem:(n,i)=>this._convertItem(n,i),convertChildren:(n,i)=>this._convertChildren(n,i),safeInsert:(n,i)=>this._safeInsert(n,i),updateConversionResult:(n,i)=>this._updateConversionResult(n,i),splitToAllowedParent:(n,i)=>this._splitToAllowedParent(n,i),getSplitParts:n=>this._getSplitParts(n),keepEmptyElement:n=>this._keepEmptyElement(n)}}convert(e,n,i=["$root"]){this.fire("viewCleanup",e),this._modelCursor=NLe(i,n),this.conversionApi.writer=n,this.conversionApi.consumable=u1.createFrom(e),this.conversionApi.store={};const{modelRange:r}=this._convertItem(e,this._modelCursor),o=n.createDocumentFragment();if(r){this._removeEmptyElements();const s=this._modelCursor.parent,a=s._removeChildren(0,s.childCount);o._insertChild(0,a),o.markers=DLe(o,n)}return this._modelCursor=null,this._splitParts.clear(),this._cursorParents.clear(),this._emptyElementsToKeep.clear(),this.conversionApi.writer=null,this.conversionApi.store=null,o}_convertItem(e,n){const i={viewItem:e,modelCursor:n,modelRange:null};if(e.is("element")?this.fire(`element:${e.name}`,i,this.conversionApi):e.is("$text")?this.fire("text",i,this.conversionApi):this.fire("documentFragment",i,this.conversionApi),i.modelRange&&!(i.modelRange instanceof Ee))throw new oe("view-conversion-dispatcher-incorrect-result",this);return{modelRange:i.modelRange,modelCursor:i.modelCursor}}_convertChildren(e,n){let i=n.is("position")?n:Be._createAt(n,0);const r=new Ee(i);for(const o of Array.from(e.getChildren())){const s=this._convertItem(o,i);s.modelRange instanceof Ee&&(r.end=s.modelRange.end,i=s.modelCursor)}return{modelRange:r,modelCursor:i}}_safeInsert(e,n){const i=this._splitToAllowedParent(e,n);return i?(this.conversionApi.writer.insert(e,i.position),!0):!1}_updateConversionResult(e,n){const i=this._getSplitParts(e),r=this.conversionApi.writer;n.modelRange||(n.modelRange=r.createRange(r.createPositionBefore(e),r.createPositionAfter(i[i.length-1])));const o=this._cursorParents.get(e);o?n.modelCursor=r.createPositionAt(o,0):n.modelCursor=n.modelRange.end}_splitToAllowedParent(e,n){const{schema:i,writer:r}=this.conversionApi;let o=i.findAllowedParent(n,e);if(o){if(o===n.parent)return{position:n};this._modelCursor.parent.getAncestors().includes(o)&&(o=null)}if(!o)return NG(n,e,i)?{position:BG(n,r)}:null;const s=this.conversionApi.writer.split(n,o),a=[];for(const u of s.range.getWalker())if(u.type=="elementEnd")a.push(u.item);else{const c=a.pop(),d=u.item;this._registerSplitPair(c,d)}const l=s.range.end.parent;return this._cursorParents.set(e,l),{position:s.position,cursorParent:l}}_registerSplitPair(e,n){this._splitParts.has(e)||this._splitParts.set(e,[e]);const i=this._splitParts.get(e);this._splitParts.set(n,i),i.push(n)}_getSplitParts(e){let n;return this._splitParts.has(e)?n=this._splitParts.get(e):n=[e],n}_keepEmptyElement(e){this._emptyElementsToKeep.add(e)}_removeEmptyElements(){const e=new Map;for(const n of this._splitParts.keys())if(n.isEmpty&&!this._emptyElementsToKeep.has(n)){const i=e.get(n.parent)||[];i.push(n),this._splitParts.delete(n),e.set(n.parent,i)}for(const[n,i]of e)n._removeChildrenArray(i);e.size&&this._removeEmptyElements()}}function DLe(t,e){const n=new Set,i=new Map,r=Ee._createIn(t).getItems();for(const o of r)o.is("element","$marker")&&n.add(o);for(const o of n){const s=o.getAttribute("data-name"),a=e.createPositionBefore(o);i.has(s)?i.get(s).end=a.clone():i.set(s,new Ee(a.clone())),e.remove(o)}return i}function NLe(t,e){let n;for(const i of new su(t)){const r={};for(const s of i.getAttributeKeys())r[s]=i.getAttribute(s);const o=e.createElement(i.name,r);n&&e.insert(o,n),n=Be._createAt(o,0)}return n}class BLe{getHtml(e){const i=Qe.document.implementation.createHTMLDocument("").createElement("div");return i.appendChild(e),i.innerHTML}}class VLe{domParser;domConverter;htmlWriter;skipComments=!0;constructor(e){this.domParser=new DOMParser,this.domConverter=new pS(e,{renderingMode:"data"}),this.htmlWriter=new BLe}toData(e){const n=this.domConverter.viewToDom(e);return this.htmlWriter.getHtml(n)}toView(e){const n=this._toDom(e);return this.domConverter.domToView(n,{skipComments:this.skipComments})}registerRawContentMatcher(e){this.domConverter.registerRawContentMatcher(e)}useFillerType(e){this.domConverter.blockFillerMode=e=="marked"?"markedNbsp":"nbsp"}_toDom(e){/<(?:html|body|head|meta)(?:\s[^>]*)?>/i.test(e.trim().slice(0,1e4))||(e=`${e}`);const n=this.domParser.parseFromString(e,"text/html"),i=n.createDocumentFragment(),r=n.body.childNodes;for(;r.length>0;)i.appendChild(r[0]);return i}}class FLe extends Fn(){model;mapper;downcastDispatcher;upcastDispatcher;viewDocument;stylesProcessor;htmlProcessor;processor;_viewWriter;constructor(e,n){super(),this.model=e,this.mapper=new _G,this.downcastDispatcher=new CG({mapper:this.mapper,schema:e.schema}),this.downcastDispatcher.on("insert:$text",TG(),{priority:"lowest"}),this.downcastDispatcher.on("insert",EG(),{priority:"lowest"}),this.upcastDispatcher=new LLe({schema:e.schema}),this.viewDocument=new mS(n),this.stylesProcessor=n,this.htmlProcessor=new VLe(this.viewDocument),this.processor=this.htmlProcessor,this._viewWriter=new dG(this.viewDocument),this.upcastDispatcher.on("text",rLe(),{priority:"lowest"}),this.upcastDispatcher.on("element",B4(),{priority:"lowest"}),this.upcastDispatcher.on("documentFragment",B4(),{priority:"lowest"}),Ln().prototype.decorate.call(this,"init"),Ln().prototype.decorate.call(this,"set"),Ln().prototype.decorate.call(this,"get"),Ln().prototype.decorate.call(this,"toView"),Ln().prototype.decorate.call(this,"toModel"),this.on("init",()=>{this.fire("ready")},{priority:"lowest"}),this.on("ready",()=>{this.model.enqueueChange({isUndoable:!1},DG)},{priority:"lowest"})}get(e={}){const{rootName:n="main",trim:i="empty"}=e;if(!this._checkIfRootsExists([n]))throw new oe("datacontroller-get-non-existent-root",this);const r=this.model.document.getRoot(n);return r.isAttached()||hn("datacontroller-get-detached-root",this),i==="empty"&&!this.model.hasContent(r,{ignoreWhitespaces:!0})?"":this.stringify(r,e)}stringify(e,n={}){const i=this.toView(e,n);return this.processor.toData(i)}toView(e,n={}){const i=this.viewDocument,r=this._viewWriter;this.mapper.clearBindings();const o=Ee._createIn(e),s=new af(i);this.mapper.bindElements(e,s);const a=e.is("documentFragment")?e.markers:$Le(e);return this.downcastDispatcher.convert(o,a,r,n),s}init(e){if(this.model.document.version)throw new oe("datacontroller-init-document-not-empty",this);let n={};if(typeof e=="string"?n.main=e:n=e,!this._checkIfRootsExists(Object.keys(n)))throw new oe("datacontroller-init-non-existent-root",this);return this.model.enqueueChange({isUndoable:!1},i=>{for(const r of Object.keys(n)){const o=this.model.document.getRoot(r);i.insert(this.parse(n[r],o),o,0)}}),Promise.resolve()}set(e,n={}){let i={};if(typeof e=="string"?i.main=e:i=e,!this._checkIfRootsExists(Object.keys(i)))throw new oe("datacontroller-set-non-existent-root",this);this.model.enqueueChange(n.batchType||{},r=>{r.setSelection(null),r.removeSelectionAttribute(this.model.document.selection.getAttributeKeys());for(const o of Object.keys(i)){const s=this.model.document.getRoot(o);r.remove(r.createRangeIn(s)),r.insert(this.parse(i[o],s),s,0)}})}parse(e,n="$root"){const i=this.processor.toView(e);return this.toModel(i,n)}toModel(e,n="$root"){return this.model.change(i=>this.upcastDispatcher.convert(e,i,n))}addStyleProcessorRules(e){e(this.stylesProcessor)}registerRawContentMatcher(e){this.processor&&this.processor!==this.htmlProcessor&&this.processor.registerRawContentMatcher(e),this.htmlProcessor.registerRawContentMatcher(e)}destroy(){this.stopListening()}_checkIfRootsExists(e){for(const n of e)if(!this.model.document.getRoot(n))return!1;return!0}}function $Le(t){const e=[],n=t.root.document;if(!n)return new Map;const i=Ee._createIn(t);for(const r of n.model.markers){const o=r.getRange(),s=o.isCollapsed,a=o.start.isEqual(i.start)||o.end.isEqual(i.end);if(s&&a)e.push([r.name,o]);else{const l=i.getIntersection(o);l&&e.push([r.name,l])}}return e.sort(([r,o],[s,a])=>{if(o.end.compareWith(a.start)!=="after")return 1;if(o.start.compareWith(a.end)!=="before")return-1;switch(o.start.compareWith(a.start)){case"before":return 1;case"after":return-1;default:switch(o.end.compareWith(a.end)){case"before":return 1;case"after":return-1;default:return s.localeCompare(r)}}}),new Map(e)}class zLe{_helpers=new Map;_downcast;_upcast;constructor(e,n){this._downcast=li(e),this._createConversionHelpers({name:"downcast",dispatchers:this._downcast,isDowncast:!0}),this._upcast=li(n),this._createConversionHelpers({name:"upcast",dispatchers:this._upcast,isDowncast:!1})}addAlias(e,n){const i=this._downcast.includes(n);if(!this._upcast.includes(n)&&!i)throw new oe("conversion-add-alias-dispatcher-not-registered",this);this._createConversionHelpers({name:e,dispatchers:[n],isDowncast:i})}for(e){if(!this._helpers.has(e))throw new oe("conversion-for-unknown-group",this);return this._helpers.get(e)}elementToElement(e){this.for("downcast").elementToElement(e);for(const{model:n,view:i}of NT(e))this.for("upcast").elementToElement({model:n,view:i,converterPriority:e.converterPriority})}attributeToElement(e){this.for("downcast").attributeToElement(e);for(const{model:n,view:i}of NT(e))this.for("upcast").elementToAttribute({view:i,model:n,converterPriority:e.converterPriority})}attributeToAttribute(e){this.for("downcast").attributeToAttribute(e);for(const{model:n,view:i}of NT(e))this.for("upcast").attributeToAttribute({view:i,model:n})}_createConversionHelpers({name:e,dispatchers:n,isDowncast:i}){if(this._helpers.has(e))throw new oe("conversion-group-exists",this);const r=i?new TOe(n):new iLe(n);this._helpers.set(e,r)}}function*NT(t){if(t.model.values)for(const e of t.model.values){const n={key:t.model.key,value:e},i=t.view[e],r=t.upcastAlso?t.upcastAlso[e]:void 0;yield*$4(n,i,r)}else yield*$4(t.model,t.view,t.upcastAlso)}function*$4(t,e,n){if(yield{model:t,view:e},n)for(const i of li(n))yield{model:t,view:i}}class ds{baseVersion;isDocumentOperation;batch;constructor(e){this.baseVersion=e,this.isDocumentOperation=this.baseVersion!==null,this.batch=null}_validate(){}toJSON(){const e=Object.assign({},this);return e.__className=this.constructor.className,delete e.batch,delete e.isDocumentOperation,e}static get className(){return"Operation"}static fromJSON(e,n){return new this(e.baseVersion)}}function QM(t,e){const n=HG(e),i=n.reduce((s,a)=>s+a.offsetSize,0),r=t.parent;lb(t);const o=t.index;return r._insertChild(o,n),ab(r,o+n.length),ab(r,o),new Ee(t,t.getShiftedBy(i))}function zG(t){if(!t.isFlat)throw new oe("operation-utils-remove-range-not-flat",this);const e=t.start.parent;lb(t.start),lb(t.end);const n=e._removeChildren(t.start.index,t.end.index-t.start.index);return ab(e,t.start.index),n}function sb(t,e){if(!t.isFlat)throw new oe("operation-utils-move-range-not-flat",this);const n=zG(t);return e=e._getTransformedByDeletion(t.start,t.end.offset-t.start.offset),QM(e,n)}function HLe(t,e,n){lb(t.start),lb(t.end);for(const i of t.getItems({shallow:!0})){const r=i.is("$textProxy")?i.textNode:i;n!==null?r._setAttribute(e,n):r._removeAttribute(e),ab(r.parent,r.index)}ab(t.end.parent,t.end.index)}function HG(t){const e=[];function n(i){if(typeof i=="string")e.push(new ni(i));else if(i instanceof ea)e.push(new ni(i.data,i.getAttributes()));else if(i instanceof Uf)e.push(i);else if(us(i))for(const r of i)n(r)}n(t);for(let i=1;ie.maxOffset)throw new oe("move-operation-nodes-do-not-exist",this);if(e===n&&i=i&&this.targetPosition.path[o]i._clone(!0))),n=new hr(this.position,e,this.baseVersion);return n.shouldReceiveAttributes=this.shouldReceiveAttributes,n}getReversed(){const e=this.position.root.document.graveyard,n=new Be(e,[0]);return new Tn(this.position,this.nodes.maxOffset,n,this.baseVersion+1)}_validate(){const e=this.position.parent;if(!e||e.maxOffsetn._clone(!0))),QM(this.position,e)}toJSON(){const e=super.toJSON();return e.position=this.position.toJSON(),e.nodes=this.nodes.toJSON(),e}static get className(){return"InsertOperation"}static fromJSON(e,n){const i=[];for(const o of e.nodes)o.name?i.push(zn.fromJSON(o)):i.push(ni.fromJSON(o));const r=new hr(Be.fromJSON(e.position,n),i,e.baseVersion);return r.shouldReceiveAttributes=e.shouldReceiveAttributes,r}}class Hn extends ds{splitPosition;howMany;insertionPosition;graveyardPosition;constructor(e,n,i,r,o){super(o),this.splitPosition=e.clone(),this.splitPosition.stickiness="toNext",this.howMany=n,this.insertionPosition=i,this.graveyardPosition=r?r.clone():null,this.graveyardPosition&&(this.graveyardPosition.stickiness="toNext")}get type(){return"split"}get moveTargetPosition(){const e=this.insertionPosition.path.slice();return e.push(0),new Be(this.insertionPosition.root,e)}get movedRange(){const e=this.splitPosition.getShiftedBy(Number.POSITIVE_INFINITY);return new Ee(this.splitPosition,e)}get affectedSelectable(){const e=[Ee._createFromPositionAndShift(this.splitPosition,0),Ee._createFromPositionAndShift(this.insertionPosition,0)];return this.graveyardPosition&&e.push(Ee._createFromPositionAndShift(this.graveyardPosition,0)),e}clone(){return new Hn(this.splitPosition,this.howMany,this.insertionPosition,this.graveyardPosition,this.baseVersion)}getReversed(){const e=this.splitPosition.root.document.graveyard,n=new Be(e,[0]);return new Ai(this.moveTargetPosition,this.howMany,this.splitPosition,n,this.baseVersion+1)}_validate(){const e=this.splitPosition.parent,n=this.splitPosition.offset;if(!e||e.maxOffset1&&e.sourcePosition.isEqual(n.deletionPosition)?this._setRelation(e,n,"firstToMoveMerged"):e.howMany>1&&e.sourcePosition.getShiftedBy(e.howMany-1).isEqual(n.deletionPosition)&&this._setRelation(e,n,"lastToMoveMerged"):n instanceof Tn&&(e.targetPosition.isEqual(n.sourcePosition)||e.targetPosition.isBefore(n.sourcePosition)?this._setRelation(e,n,"insertBefore"):this._setRelation(e,n,"insertAfter"));else if(e instanceof Hn){if(n instanceof Ai)e.splitPosition.isBefore(n.sourcePosition)&&this._setRelation(e,n,"splitBefore");else if(n instanceof Tn)if(e.splitPosition.isEqual(n.sourcePosition)||e.splitPosition.isBefore(n.sourcePosition))this._setRelation(e,n,"splitBefore");else{const i=Ee._createFromPositionAndShift(n.sourcePosition,n.howMany);if(e.splitPosition.hasSameParentAs(n.sourcePosition)&&i.containsPosition(e.splitPosition)){const r=i.end.offset-e.splitPosition.offset,o=e.splitPosition.offset-i.start.offset;this._setRelation(e,n,{howMany:r,offset:o})}}}else if(e instanceof Ai)n instanceof Ai?(e.targetPosition.isEqual(n.sourcePosition)||this._setRelation(e,n,"mergeTargetNotMoved"),e.sourcePosition.isEqual(n.targetPosition)&&this._setRelation(e,n,"mergeSourceNotMoved"),e.sourcePosition.isEqual(n.sourcePosition)&&this._setRelation(e,n,"mergeSameElement")):n instanceof Hn?e.sourcePosition.isEqual(n.splitPosition)&&this._setRelation(e,n,"splitAtSource"):n instanceof Tn&&n.howMany>0&&(e.sourcePosition.isEqual(n.sourcePosition.getShiftedBy(n.howMany))&&this._setRelation(e,n,"mergeSourceAffected"),e.targetPosition.isEqual(n.sourcePosition)&&this._setRelation(e,n,"mergeTargetWasBefore"));else if(e instanceof no){const i=e.newRange;if(!i)return;if(n instanceof Ai){const r=i.start.isEqual(n.targetPosition),o=i.start.isEqual(n.deletionPosition),s=i.end.isEqual(n.deletionPosition),a=i.end.isEqual(n.sourcePosition);(r||o||s||a)&&this._setRelation(e,n,{wasInLeftElement:r,wasStartBeforeMergedElement:o,wasEndBeforeMergedElement:s,wasInRightElement:a})}}}getContext(e,n,i){return{aIsStrong:i,aWasUndone:this._wasUndone(e),bWasUndone:this._wasUndone(n),abRelation:this._useRelations?this._getRelation(e,n):null,baRelation:this._useRelations?this._getRelation(n,e):null,forceWeakRemove:this._forceWeakRemove}}_wasUndone(e){const n=this.originalOperations.get(e);return n.wasUndone||this._history.isUndoneOperation(n)}_getRelation(e,n){const i=this.originalOperations.get(n),r=this._history.getUndoneOperation(i);if(!r)return null;const o=this.originalOperations.get(e),s=this._relations.get(o);return s&&s.get(r)||null}_setRelation(e,n,i){const r=this.originalOperations.get(e),o=this.originalOperations.get(n);let s=this._relations.get(r);s||(s=new Map,this._relations.set(r,s)),s.set(o,i)}}function H4(t,e){for(const n of t)n.baseVersion=e++}function U4(t){const e=new Map;for(let n=0;n{if(t.key===e.key&&t.range.start.hasSameParentAs(e.range.start)){const i=t.range.getDifference(e.range).map(o=>new zi(o,t.key,t.oldValue,t.newValue,0)),r=t.range.getIntersection(e.range);return r&&n.aIsStrong&&i.push(new zi(r,e.key,e.newValue,t.newValue,0)),i.length==0?[new or(0)]:i}else return[t]});_n(zi,hr,(t,e)=>{if(t.range.start.hasSameParentAs(e.position)&&t.range.containsPosition(e.position)){const i=t.range._getTransformedByInsertion(e.position,e.howMany,!e.shouldReceiveAttributes).map(r=>new zi(r,t.key,t.oldValue,t.newValue,t.baseVersion));if(e.shouldReceiveAttributes){const r=WG(e,t.key,t.oldValue);r&&i.unshift(r)}return i}return t.range=t.range._getTransformedByInsertion(e.position,e.howMany,!1)[0],[t]});function WG(t,e,n){const r=t.nodes.getNode(0).getAttribute(e);if(r==n)return null;const o=new Ee(t.position,t.position.getShiftedBy(t.howMany));return new zi(o,e,r,n,0)}_n(zi,Ai,(t,e)=>{const n=[];t.range.start.hasSameParentAs(e.deletionPosition)&&(t.range.containsPosition(e.deletionPosition)||t.range.start.isEqual(e.deletionPosition))&&n.push(Ee._createFromPositionAndShift(e.graveyardPosition,1));const i=t.range._getTransformedByMergeOperation(e);return i.isCollapsed||n.push(i),n.map(r=>new zi(r,t.key,t.oldValue,t.newValue,t.baseVersion))});_n(zi,Tn,(t,e)=>GLe(t.range,e).map(i=>new zi(i,t.key,t.oldValue,t.newValue,t.baseVersion)));function GLe(t,e){const n=Ee._createFromPositionAndShift(e.sourcePosition,e.howMany);let i=null,r=[];n.containsRange(t,!0)?i=t:t.start.hasSameParentAs(n.start)?(r=t.getDifference(n),i=t.getIntersection(n)):r=[t];const o=[];for(let s of r){s=s._getTransformedByDeletion(e.sourcePosition,e.howMany);const a=e.getMovedRangeStart(),l=s.start.hasSameParentAs(a),u=s._getTransformedByInsertion(a,e.howMany,l);o.push(...u)}return i&&o.push(i._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany,!1)[0]),o}_n(zi,Hn,(t,e)=>{if(t.range.end.isEqual(e.insertionPosition))return e.graveyardPosition||t.range.end.offset++,[t];if(t.range.start.hasSameParentAs(e.splitPosition)&&t.range.containsPosition(e.splitPosition)){const n=t.clone();return n.range=new Ee(e.moveTargetPosition.clone(),t.range.end._getCombined(e.splitPosition,e.moveTargetPosition)),t.range.end=e.splitPosition.clone(),t.range.end.stickiness="toPrevious",[t,n]}return t.range=t.range._getTransformedBySplitOperation(e),[t]});_n(hr,zi,(t,e)=>{const n=[t];if(t.shouldReceiveAttributes&&t.position.hasSameParentAs(e.range.start)&&e.range.containsPosition(t.position)){const i=WG(t,e.key,e.newValue);i&&n.push(i)}return n});_n(hr,hr,(t,e,n)=>t.position.isEqual(e.position)&&n.aIsStrong?[t]:(t.position=t.position._getTransformedByInsertOperation(e),[t]));_n(hr,Tn,(t,e)=>(t.position=t.position._getTransformedByMoveOperation(e),[t]));_n(hr,Hn,(t,e)=>(t.position=t.position._getTransformedBySplitOperation(e),[t]));_n(hr,Ai,(t,e)=>(t.position=t.position._getTransformedByMergeOperation(e),[t]));_n(no,hr,(t,e)=>(t.oldRange&&(t.oldRange=t.oldRange._getTransformedByInsertOperation(e)[0]),t.newRange&&(t.newRange=t.newRange._getTransformedByInsertOperation(e)[0]),[t]));_n(no,no,(t,e,n)=>{if(t.name==e.name)if(n.aIsStrong)t.oldRange=e.newRange?e.newRange.clone():null;else return[new or(0)];return[t]});_n(no,Ai,(t,e)=>(t.oldRange&&(t.oldRange=t.oldRange._getTransformedByMergeOperation(e)),t.newRange&&(t.newRange=t.newRange._getTransformedByMergeOperation(e)),[t]));_n(no,Tn,(t,e)=>{const n=[t];if(t.oldRange&&(t.oldRange=Ee._createFromRanges(t.oldRange._getTransformedByMoveOperation(e))),t.newRange){const i=t.newRange._getTransformedByMoveOperation(e);t.newRange=i[0];for(let r=1;r{if(t.oldRange&&(t.oldRange=t.oldRange._getTransformedBySplitOperation(e)),t.newRange){if(n.abRelation){const i=t.newRange._getTransformedBySplitOperation(e);return t.newRange.start.isEqual(e.splitPosition)?n.abRelation.wasStartBeforeMergedElement?t.newRange.start=Be._createAt(e.insertionPosition):n.abRelation.wasInLeftElement?t.newRange.start=Be._createAt(t.newRange.start):t.newRange.start=Be._createAt(e.moveTargetPosition):t.newRange.start=i.start,t.newRange.end.isEqual(e.splitPosition)?t.newRange.end.isEqual(e.splitPosition)&&n.abRelation.wasEndBeforeMergedElement?t.newRange.end=Be._createAt(e.insertionPosition):n.abRelation.wasInRightElement?t.newRange.end=Be._createAt(e.moveTargetPosition):t.newRange.end=Be._createAt(t.newRange.end):t.newRange.end=i.end,[t]}t.newRange=t.newRange._getTransformedBySplitOperation(e)}return[t]});_n(Ai,hr,(t,e)=>(t.sourcePosition.hasSameParentAs(e.position)&&(t.howMany+=e.howMany),t.sourcePosition=t.sourcePosition._getTransformedByInsertOperation(e),t.targetPosition=t.targetPosition._getTransformedByInsertOperation(e),[t]));_n(Ai,Ai,(t,e,n)=>{if(t.sourcePosition.isEqual(e.sourcePosition)&&t.targetPosition.isEqual(e.targetPosition))if(n.bWasUndone){const i=e.graveyardPosition.path.slice();return i.push(0),t.sourcePosition=new Be(e.graveyardPosition.root,i),t.howMany=0,[t]}else return[new or(0)];if(t.sourcePosition.isEqual(e.sourcePosition)&&!t.targetPosition.isEqual(e.targetPosition)&&!n.bWasUndone&&n.abRelation!="splitAtSource"){const i=t.targetPosition.root.rootName=="$graveyard",r=e.targetPosition.root.rootName=="$graveyard";if(r&&!i||!(i&&!r)&&n.aIsStrong){const l=e.targetPosition._getTransformedByMergeOperation(e),u=t.targetPosition._getTransformedByMergeOperation(e);return[new Tn(l,t.howMany,u,0)]}else return[new or(0)]}return t.sourcePosition.hasSameParentAs(e.targetPosition)&&(t.howMany+=e.howMany),t.sourcePosition=t.sourcePosition._getTransformedByMergeOperation(e),t.targetPosition=t.targetPosition._getTransformedByMergeOperation(e),(!t.graveyardPosition.isEqual(e.graveyardPosition)||!n.aIsStrong)&&(t.graveyardPosition=t.graveyardPosition._getTransformedByMergeOperation(e)),[t]});_n(Ai,Tn,(t,e,n)=>{const i=Ee._createFromPositionAndShift(e.sourcePosition,e.howMany);return e.type=="remove"&&!n.bWasUndone&&t.deletionPosition.hasSameParentAs(e.sourcePosition)&&i.containsPosition(t.sourcePosition)?[new or(0)]:(e.sourcePosition.getShiftedBy(e.howMany).isEqual(t.sourcePosition)?t.sourcePosition.stickiness="toNone":e.targetPosition.isEqual(t.sourcePosition)&&n.abRelation=="mergeSourceAffected"?t.sourcePosition.stickiness="toNext":e.sourcePosition.isEqual(t.targetPosition)?(t.targetPosition.stickiness="toNone",t.howMany-=e.howMany):e.targetPosition.isEqual(t.targetPosition)&&n.abRelation=="mergeTargetWasBefore"?(t.targetPosition.stickiness="toPrevious",t.howMany+=e.howMany):(t.sourcePosition.hasSameParentAs(e.targetPosition)&&(t.howMany+=e.howMany),t.sourcePosition.hasSameParentAs(e.sourcePosition)&&(t.howMany-=e.howMany)),t.sourcePosition=t.sourcePosition._getTransformedByMoveOperation(e),t.targetPosition=t.targetPosition._getTransformedByMoveOperation(e),t.sourcePosition.stickiness="toPrevious",t.targetPosition.stickiness="toNext",t.graveyardPosition.isEqual(e.targetPosition)||(t.graveyardPosition=t.graveyardPosition._getTransformedByMoveOperation(e)),[t])});_n(Ai,Hn,(t,e,n)=>{if(e.graveyardPosition&&(t.graveyardPosition=t.graveyardPosition._getTransformedByDeletion(e.graveyardPosition,1),t.deletionPosition.isEqual(e.graveyardPosition)&&(t.howMany=e.howMany)),t.targetPosition.isEqual(e.splitPosition)&&(e.graveyardPosition&&t.deletionPosition.isEqual(e.graveyardPosition)||n.abRelation=="mergeTargetNotMoved"))return t.sourcePosition=t.sourcePosition._getTransformedBySplitOperation(e),[t];if(t.sourcePosition.isEqual(e.splitPosition)){if(n.abRelation=="mergeSourceNotMoved")return t.howMany=0,t.targetPosition=t.targetPosition._getTransformedBySplitOperation(e),[t];if(n.abRelation=="mergeSameElement"||t.sourcePosition.offset>0)return t.sourcePosition=e.moveTargetPosition.clone(),t.targetPosition=t.targetPosition._getTransformedBySplitOperation(e),[t]}return t.sourcePosition.hasSameParentAs(e.splitPosition)&&(t.howMany=e.splitPosition.offset),t.sourcePosition=t.sourcePosition._getTransformedBySplitOperation(e),t.targetPosition=t.targetPosition._getTransformedBySplitOperation(e),[t]});_n(Tn,hr,(t,e)=>{const i=Ee._createFromPositionAndShift(t.sourcePosition,t.howMany)._getTransformedByInsertOperation(e,!1)[0];return t.sourcePosition=i.start,t.howMany=i.end.offset-i.start.offset,t.targetPosition.isEqual(e.position)||(t.targetPosition=t.targetPosition._getTransformedByInsertOperation(e)),[t]});_n(Tn,Tn,(t,e,n)=>{const i=Ee._createFromPositionAndShift(t.sourcePosition,t.howMany),r=Ee._createFromPositionAndShift(e.sourcePosition,e.howMany);let o=n.aIsStrong,s=!n.aIsStrong;n.abRelation=="insertBefore"||n.baRelation=="insertAfter"?s=!0:(n.abRelation=="insertAfter"||n.baRelation=="insertBefore")&&(s=!1);let a;if(t.targetPosition.isEqual(e.targetPosition)&&s?a=t.targetPosition._getTransformedByDeletion(e.sourcePosition,e.howMany):a=t.targetPosition._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),W4(t,e)&&W4(e,t))return[e.getReversed()];if(i.containsPosition(e.targetPosition)&&i.containsRange(r,!0))return i.start=i.start._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),i.end=i.end._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),Gh([i],a);if(r.containsPosition(t.targetPosition)&&r.containsRange(i,!0))return i.start=i.start._getCombined(e.sourcePosition,e.getMovedRangeStart()),i.end=i.end._getCombined(e.sourcePosition,e.getMovedRangeStart()),Gh([i],a);const c=ur(t.sourcePosition.getParentPath(),e.sourcePosition.getParentPath());if(c=="prefix"||c=="extension")return i.start=i.start._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),i.end=i.end._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany),Gh([i],a);t.type=="remove"&&e.type!="remove"&&!n.aWasUndone&&!n.forceWeakRemove?o=!0:t.type!="remove"&&e.type=="remove"&&!n.bWasUndone&&!n.forceWeakRemove&&(o=!1);const d=[],f=i.getDifference(r);for(const m of f){m.start=m.start._getTransformedByDeletion(e.sourcePosition,e.howMany),m.end=m.end._getTransformedByDeletion(e.sourcePosition,e.howMany);const g=ur(m.start.getParentPath(),e.getMovedRangeStart().getParentPath())=="same",v=m._getTransformedByInsertion(e.getMovedRangeStart(),e.howMany,g);d.push(...v)}const h=i.getIntersection(r);return h!==null&&o&&(h.start=h.start._getCombined(e.sourcePosition,e.getMovedRangeStart()),h.end=h.end._getCombined(e.sourcePosition,e.getMovedRangeStart()),d.length===0?d.push(h):d.length==1?r.start.isBefore(i.start)||r.start.isEqual(i.start)?d.unshift(h):d.push(h):d.splice(1,0,h)),d.length===0?[new or(t.baseVersion)]:Gh(d,a)});_n(Tn,Hn,(t,e,n)=>{let i=t.targetPosition.clone();if((!t.targetPosition.isEqual(e.insertionPosition)||!e.graveyardPosition||n.abRelation=="moveTargetAfter")&&(i=t.targetPosition._getTransformedBySplitOperation(e)),t.sourcePosition.isEqual(e.insertionPosition)&&n.abRelation=="firstToMoveMerged")return t.howMany++,t.targetPosition=i,[t];const r=Ee._createFromPositionAndShift(t.sourcePosition,t.howMany);if(r.end.isEqual(e.insertionPosition))return(!e.graveyardPosition||n.abRelation=="lastToMoveMerged")&&t.howMany++,t.targetPosition=i,[t];if(r.start.hasSameParentAs(e.splitPosition)&&r.containsPosition(e.splitPosition)){let a=new Ee(e.splitPosition,r.end);a=a._getTransformedBySplitOperation(e);const l=[new Ee(r.start,e.splitPosition),a];return Gh(l,i)}t.targetPosition.isEqual(e.splitPosition)&&n.abRelation=="insertAtSource"&&(i=e.moveTargetPosition),t.targetPosition.isEqual(e.insertionPosition)&&n.abRelation=="insertBetween"&&(i=t.targetPosition);const s=[r._getTransformedBySplitOperation(e)];if(e.graveyardPosition){const a=r.start.isEqual(e.graveyardPosition)||r.containsPosition(e.graveyardPosition);t.howMany>1&&a&&!n.aWasUndone&&s.push(Ee._createFromPositionAndShift(e.insertionPosition,1))}return Gh(s,i)});_n(Tn,Ai,(t,e,n)=>{const i=Ee._createFromPositionAndShift(t.sourcePosition,t.howMany);if(e.deletionPosition.hasSameParentAs(t.sourcePosition)&&i.containsPosition(e.sourcePosition)){if(t.type=="remove"&&!n.forceWeakRemove){if(!n.aWasUndone){const s=[];let a=e.graveyardPosition.clone(),l=e.targetPosition._getTransformedByMergeOperation(e);const u=t.targetPosition.getTransformedByOperation(e);t.howMany>1&&(s.push(new Tn(t.sourcePosition,t.howMany-1,u,0)),a=a._getTransformedByMove(t.sourcePosition,u,t.howMany-1),l=l._getTransformedByMove(t.sourcePosition,u,t.howMany-1));const c=e.deletionPosition._getCombined(t.sourcePosition,u),d=new Tn(a,1,c,0),f=d.getMovedRangeStart().path.slice();f.push(0);const h=new Be(d.targetPosition.root,f);l=l._getTransformedByMove(a,c,1);const m=new Tn(l,e.howMany,h,0);return s.push(d),s.push(m),s}}else if(t.howMany==1)return n.bWasUndone?(t.sourcePosition=e.graveyardPosition.clone(),t.targetPosition=t.targetPosition._getTransformedByMergeOperation(e),[t]):[new or(0)]}const o=Ee._createFromPositionAndShift(t.sourcePosition,t.howMany)._getTransformedByMergeOperation(e);return t.sourcePosition=o.start,t.howMany=o.end.offset-o.start.offset,t.targetPosition=t.targetPosition._getTransformedByMergeOperation(e),[t]});_n(Po,hr,(t,e)=>(t.position=t.position._getTransformedByInsertOperation(e),[t]));_n(Po,Ai,(t,e)=>t.position.isEqual(e.deletionPosition)?(t.position=e.graveyardPosition.clone(),t.position.stickiness="toNext",[t]):(t.position=t.position._getTransformedByMergeOperation(e),[t]));_n(Po,Tn,(t,e)=>(t.position=t.position._getTransformedByMoveOperation(e),[t]));_n(Po,Po,(t,e,n)=>{if(t.position.isEqual(e.position))if(n.aIsStrong)t.oldName=e.newName;else return[new or(0)];return[t]});_n(Po,Hn,(t,e)=>{const n=t.position.path,i=e.splitPosition.getParentPath();if(ur(n,i)=="same"&&!e.graveyardPosition){const r=new Po(t.position.getShiftedBy(1),t.oldName,t.newName,0);return[t,r]}return t.position=t.position._getTransformedBySplitOperation(e),[t]});_n(au,au,(t,e,n)=>{if(t.root===e.root&&t.key===e.key)if(n.aIsStrong)t.oldValue=e.newValue;else return[new or(0)];return[t]});_n(Qa,Qa,(t,e)=>t.rootName===e.rootName&&t.isAdd===e.isAdd?[new or(0)]:[t]);_n(Hn,hr,(t,e)=>(t.splitPosition.hasSameParentAs(e.position)&&t.splitPosition.offset{if(!t.graveyardPosition&&!n.bWasUndone&&t.splitPosition.hasSameParentAs(e.sourcePosition)){const i=e.graveyardPosition.path.slice();i.push(0);const r=new Be(e.graveyardPosition.root,i),o=Hn.getInsertionPosition(new Be(e.graveyardPosition.root,i)),s=new Hn(r,0,o,null,0);return t.splitPosition=t.splitPosition._getTransformedByMergeOperation(e),t.insertionPosition=Hn.getInsertionPosition(t.splitPosition),t.graveyardPosition=s.insertionPosition.clone(),t.graveyardPosition.stickiness="toNext",[s,t]}return t.splitPosition.hasSameParentAs(e.deletionPosition)&&!t.splitPosition.isAfter(e.deletionPosition)&&t.howMany--,t.splitPosition.hasSameParentAs(e.targetPosition)&&(t.howMany+=e.howMany),t.splitPosition=t.splitPosition._getTransformedByMergeOperation(e),t.insertionPosition=Hn.getInsertionPosition(t.splitPosition),t.graveyardPosition&&(t.graveyardPosition=t.graveyardPosition._getTransformedByMergeOperation(e)),[t]});_n(Hn,Tn,(t,e,n)=>{const i=Ee._createFromPositionAndShift(e.sourcePosition,e.howMany);if(t.graveyardPosition){const o=i.start.isEqual(t.graveyardPosition)||i.containsPosition(t.graveyardPosition);if(!n.bWasUndone&&o){const s=t.splitPosition._getTransformedByMoveOperation(e),a=t.graveyardPosition._getTransformedByMoveOperation(e),l=a.path.slice();l.push(0);const u=new Be(a.root,l);return[new Tn(s,t.howMany,u,0)]}t.graveyardPosition=t.graveyardPosition._getTransformedByMoveOperation(e)}const r=t.splitPosition.isEqual(e.targetPosition);if(r&&(n.baRelation=="insertAtSource"||n.abRelation=="splitBefore"))return t.howMany+=e.howMany,t.splitPosition=t.splitPosition._getTransformedByDeletion(e.sourcePosition,e.howMany),t.insertionPosition=Hn.getInsertionPosition(t.splitPosition),[t];if(r&&n.abRelation&&n.abRelation.howMany){const{howMany:o,offset:s}=n.abRelation;return t.howMany+=o,t.splitPosition=t.splitPosition.getShiftedBy(s),[t]}if(t.splitPosition.hasSameParentAs(e.sourcePosition)&&i.containsPosition(t.splitPosition)){const o=e.howMany-(t.splitPosition.offset-e.sourcePosition.offset);return t.howMany-=o,t.splitPosition.hasSameParentAs(e.targetPosition)&&t.splitPosition.offset{if(t.splitPosition.isEqual(e.splitPosition)){if(!t.graveyardPosition&&!e.graveyardPosition)return[new or(0)];if(t.graveyardPosition&&e.graveyardPosition&&t.graveyardPosition.isEqual(e.graveyardPosition))return[new or(0)];if(n.abRelation=="splitBefore")return t.howMany=0,t.graveyardPosition=t.graveyardPosition._getTransformedBySplitOperation(e),[t]}if(t.graveyardPosition&&e.graveyardPosition&&t.graveyardPosition.isEqual(e.graveyardPosition)){const i=t.splitPosition.root.rootName=="$graveyard",r=e.splitPosition.root.rootName=="$graveyard";if(r&&!i||!(i&&!r)&&n.aIsStrong){const l=[];return e.howMany&&l.push(new Tn(e.moveTargetPosition,e.howMany,e.splitPosition,0)),t.howMany&&l.push(new Tn(t.splitPosition,t.howMany,t.moveTargetPosition,0)),l}else return[new or(0)]}if(t.graveyardPosition&&(t.graveyardPosition=t.graveyardPosition._getTransformedBySplitOperation(e)),t.splitPosition.isEqual(e.insertionPosition)&&n.abRelation=="splitBefore")return t.howMany++,[t];if(e.splitPosition.isEqual(t.insertionPosition)&&n.baRelation=="splitBefore"){const i=e.insertionPosition.path.slice();i.push(0);const r=new Be(e.insertionPosition.root,i),o=new Tn(t.insertionPosition,1,r,0);return[t,o]}return t.splitPosition.hasSameParentAs(e.splitPosition)&&t.splitPosition.offset{const n=e[0];n.isDocumentOperation&&XLe.call(this,n)},{priority:"low"})}function XLe(t){const e=this.getTransformedByOperation(t);if(!this.isEqual(e)){const n=this.toPosition();this.path=e.path,this.root=e.root,this.fire("change",n)}}class lh{operations;isUndoable;isLocal;isUndo;isTyping;constructor(e={}){typeof e=="string"&&(e=e==="transparent"?{isUndoable:!1}:{},hn("batch-constructor-deprecated-string-type"));const{isUndoable:n=!0,isLocal:i=!0,isUndo:r=!1,isTyping:o=!1}=e;this.operations=[],this.isUndoable=n,this.isLocal=i,this.isUndo=r,this.isTyping=o}get baseVersion(){for(const e of this.operations)if(e.baseVersion!==null)return e.baseVersion;return null}addOperation(e){return e.isDocumentOperation&&(e.batch=this,this.operations.push(e)),e}}class f1{static _statesPriority=[void 0,"refresh","rename","move"];_markerCollection;_changesInElement=new Map;_elementsSnapshots=new Map;_elementChildrenSnapshots=new Map;_elementState=new Map;_changedMarkers=new Map;_changedRoots=new Map;_changeCount=0;_cachedChanges=null;_cachedChangesWithGraveyard=null;_refreshedItems=new Set;constructor(e){this._markerCollection=e}get isEmpty(){return this._changesInElement.size==0&&this._changedMarkers.size==0&&this._changedRoots.size==0}bufferOperation(e){const n=e;switch(n.type){case"insert":{if(this._isInInsertedElement(n.position.parent))return;this._markInsert(n.position.parent,n.position.offset,n.nodes.maxOffset);break}case"addAttribute":case"removeAttribute":case"changeAttribute":{for(const i of n.range.getItems({shallow:!0}))this._isInInsertedElement(i.parent)||this._markAttribute(i);break}case"remove":case"move":case"reinsert":{if(n.sourcePosition.isEqual(n.targetPosition)||n.sourcePosition.getShiftedBy(n.howMany).isEqual(n.targetPosition))return;const i=this._isInInsertedElement(n.sourcePosition.parent),r=this._isInInsertedElement(n.targetPosition.parent);i||this._markRemove(n.sourcePosition.parent,n.sourcePosition.offset,n.howMany),r||this._markInsert(n.targetPosition.parent,n.getMovedRangeStart().offset,n.howMany);const o=Ee._createFromPositionAndShift(n.sourcePosition,n.howMany);for(const s of o.getItems({shallow:!0}))this._setElementState(s,"move");break}case"rename":{if(this._isInInsertedElement(n.position.parent))return;this._markRemove(n.position.parent,n.position.offset,1),this._markInsert(n.position.parent,n.position.offset,1);const i=Ee._createFromPositionAndShift(n.position,1);for(const r of this._markerCollection.getMarkersIntersectingRange(i)){const o=r.getData();this.bufferMarkerChange(r.name,o,o)}this._setElementState(n.position.nodeAfter,"rename");break}case"split":{const i=n.splitPosition.parent;if(!this._isInInsertedElement(i)){this._markRemove(i,n.splitPosition.offset,n.howMany);const r=Ee._createFromPositionAndShift(n.splitPosition,n.howMany);for(const o of r.getItems({shallow:!0}))this._setElementState(o,"move")}this._isInInsertedElement(n.insertionPosition.parent)||this._markInsert(n.insertionPosition.parent,n.insertionPosition.offset,1),n.graveyardPosition&&(this._markRemove(n.graveyardPosition.parent,n.graveyardPosition.offset,1),this._setElementState(n.graveyardPosition.nodeAfter,"move"));break}case"merge":{const i=n.sourcePosition.parent;this._isInInsertedElement(i.parent)||this._markRemove(i.parent,i.startOffset,1);const r=n.graveyardPosition.parent;this._markInsert(r,n.graveyardPosition.offset,1),this._setElementState(i,"move");const o=n.targetPosition.parent;if(!this._isInInsertedElement(o)){this._markInsert(o,n.targetPosition.offset,i.maxOffset);const s=Ee._createFromPositionAndShift(n.sourcePosition,n.howMany);for(const a of s.getItems({shallow:!0}))this._setElementState(a,"move")}break}case"detachRoot":case"addRoot":{const i=n.affectedSelectable;if(!i._isLoaded||i.isAttached()==n.isAdd)return;this._bufferRootStateChange(n.rootName,n.isAdd);break}case"addRootAttribute":case"removeRootAttribute":case"changeRootAttribute":{if(!n.root._isLoaded)return;const i=n.root.rootName;this._bufferRootAttributeChange(i,n.key,n.oldValue,n.newValue);break}}this._cachedChanges=null}bufferMarkerChange(e,n,i){n.range&&n.range.root.is("rootElement")&&!n.range.root._isLoaded&&(n.range=null),i.range&&i.range.root.is("rootElement")&&!i.range.root._isLoaded&&(i.range=null);let r=this._changedMarkers.get(e);r?r.newMarkerData=i:(r={newMarkerData:i,oldMarkerData:n},this._changedMarkers.set(e,r)),r.oldMarkerData.range==null&&i.range==null&&this._changedMarkers.delete(e)}getMarkersToRemove(){const e=[];for(const[n,i]of this._changedMarkers)i.oldMarkerData.range!=null&&e.push({name:n,range:i.oldMarkerData.range});return e}getMarkersToAdd(){const e=[];for(const[n,i]of this._changedMarkers)i.newMarkerData.range!=null&&e.push({name:n,range:i.newMarkerData.range});return e}getChangedMarkers(){return Array.from(this._changedMarkers).map(([e,n])=>({name:e,data:{oldRange:n.oldMarkerData.range,newRange:n.newMarkerData.range}}))}hasDataChanges(){if(this.getChanges().length||this._changedRoots.size>0)return!0;for(const{newMarkerData:e,oldMarkerData:n}of this._changedMarkers.values()){if(e.affectsData!==n.affectsData)return!0;if(e.affectsData){const i=e.range&&!n.range,r=!e.range&&n.range,o=e.range&&n.range&&!e.range.isEqual(n.range);if(i||r||o)return!0}}return!1}getChanges(e={}){if(this._cachedChanges)return e.includeChangesInGraveyard?this._cachedChangesWithGraveyard.slice():this._cachedChanges.slice();let n=[];for(const i of this._changesInElement.keys()){const r=this._changesInElement.get(i).sort((c,d)=>c.offset===d.offset?c.type!=d.type?c.type=="remove"?-1:1:0:c.offseti.position.root!=r.position.root?i.position.root.rootNamei);for(const i of n)delete i.changeCount,i.type=="attribute"&&(delete i.position,delete i.length);return this._changeCount=0,this._cachedChangesWithGraveyard=n,this._cachedChanges=n.filter(ZLe),e.includeChangesInGraveyard?this._cachedChangesWithGraveyard.slice():this._cachedChanges.slice()}getChangedRoots(){return Array.from(this._changedRoots.values()).map(e=>{const n={...e};return n.state!==void 0&&delete n.attributes,n})}getRefreshedItems(){return new Set(this._refreshedItems)}reset(){this._changesInElement.clear(),this._elementChildrenSnapshots.clear(),this._elementsSnapshots.clear(),this._elementState.clear(),this._changedMarkers.clear(),this._changedRoots.clear(),this._refreshedItems.clear(),this._cachedChanges=null}_refreshItem(e){if(this._isInInsertedElement(e.parent))return;this._markRemove(e.parent,e.startOffset,e.offsetSize),this._markInsert(e.parent,e.startOffset,e.offsetSize),this._refreshedItems.add(e),this._setElementState(e,"refresh");const n=Ee._createOn(e);for(const i of this._markerCollection.getMarkersIntersectingRange(n)){const r=i.getData();this.bufferMarkerChange(i.name,r,r)}this._cachedChanges=null}_bufferRootLoad(e){if(e.isAttached()){this._bufferRootStateChange(e.rootName,!0),this._markInsert(e,0,e.maxOffset);for(const n of e.getAttributeKeys())this._bufferRootAttributeChange(e.rootName,n,null,e.getAttribute(n));for(const n of this._markerCollection)if(n.getRange().root==e){const i=n.getData();this.bufferMarkerChange(n.name,{...i,range:null},i)}}}_bufferRootStateChange(e,n){if(!this._changedRoots.has(e)){this._changedRoots.set(e,{name:e,state:n?"attached":"detached"});return}const i=this._changedRoots.get(e);i.state!==void 0?(delete i.state,i.attributes===void 0&&this._changedRoots.delete(e)):i.state=n?"attached":"detached"}_bufferRootAttributeChange(e,n,i,r){const o=this._changedRoots.get(e)||{name:e},s=o.attributes||{};if(s[n]){const a=s[n];r===a.oldValue?delete s[n]:a.newValue=r}else s[n]={oldValue:i,newValue:r};Object.entries(s).length===0?(delete o.attributes,o.state===void 0&&this._changedRoots.delete(e)):(o.attributes=s,this._changedRoots.set(e,o))}_markInsert(e,n,i){if(e.root.is("rootElement")&&!e.root._isLoaded)return;const r={type:"insert",offset:n,howMany:i,count:this._changeCount++};this._markChange(e,r)}_markRemove(e,n,i){if(e.root.is("rootElement")&&!e.root._isLoaded)return;const r={type:"remove",offset:n,howMany:i,count:this._changeCount++};this._markChange(e,r),this._removeAllNestedChanges(e,n,i)}_markAttribute(e){if(e.root.is("rootElement")&&!e.root._isLoaded)return;const n={type:"attribute",offset:e.startOffset,howMany:e.offsetSize,count:this._changeCount++};this._markChange(e.parent,n)}_markChange(e,n){this._makeSnapshots(e);const i=this._getChangesForElement(e);this._handleChange(n,i),i.push(n);for(let r=0;ri&&this._elementState.set(e,n)}_getDiffActionForNode(e,n){if(!e.is("element")||!this._elementsSnapshots.has(e))return n;const i=this._elementState.get(e);return!i||i=="move"?n:i}_getChangesForElement(e){let n;return this._changesInElement.has(e)?n=this._changesInElement.get(e):(n=[],this._changesInElement.set(e,n)),n}_makeSnapshots(e){if(this._elementChildrenSnapshots.has(e))return;const n=j4(e.getChildren());this._elementChildrenSnapshots.set(e,n);for(const i of n)this._elementsSnapshots.set(i.node,i)}_handleChange(e,n){e.nodesToHandle=e.howMany;for(const i of n){const r=e.offset+e.howMany,o=i.offset+i.howMany;if(e.type=="insert"&&(i.type=="insert"&&(e.offset<=i.offset?i.offset+=e.howMany:e.offseti.offset){if(r>o){const s={type:"attribute",offset:o,howMany:r-o,count:this._changeCount++};this._handleChange(s,n),n.push(s)}e.nodesToHandle=i.offset-e.offset,e.howMany=e.nodesToHandle}else e.offset>=i.offset&&e.offseto?(e.nodesToHandle=r-o,e.offset=o):e.nodesToHandle=0);if(i.type=="remove"&&e.offseti.offset){const s={type:"attribute",offset:i.offset,howMany:r-i.offset,count:this._changeCount++};this._handleChange(s,n),n.push(s),e.nodesToHandle=i.offset-e.offset,e.howMany=e.nodesToHandle}i.type=="attribute"&&(e.offset>=i.offset&&r<=o?(e.nodesToHandle=0,e.howMany=0,e.offset=0):e.offset<=i.offset&&r>=o&&(i.howMany=0))}}e.howMany=e.nodesToHandle,delete e.nodesToHandle}_getInsertDiff(e,n,i,r,o){const s={type:"insert",position:Be._createAt(e,n),name:r.name,attributes:new Map(r.attributes),length:1,changeCount:this._changeCount++,action:i};return i!="insert"&&o&&(s.before={name:o.name,attributes:new Map(o.attributes)}),s}_getRemoveDiff(e,n,i,r){return{type:"remove",action:i,position:Be._createAt(e,n),name:r.name,attributes:new Map(r.attributes),length:1,changeCount:this._changeCount++}}_getAttributesDiff(e,n,i){const r=[];i=new Map(i);for(const[o,s]of n){const a=i.has(o)?i.get(o):null;a!==s&&r.push({type:"attribute",position:e.start,range:e.clone(),length:1,attributeKey:o,attributeOldValue:s,attributeNewValue:a,changeCount:this._changeCount++}),i.delete(o)}for(const[o,s]of i)r.push({type:"attribute",position:e.start,range:e.clone(),length:1,attributeKey:o,attributeOldValue:null,attributeNewValue:s,changeCount:this._changeCount++});return r}_isInInsertedElement(e){const n=e.parent;if(!n)return!1;const i=this._changesInElement.get(n),r=e.startOffset;if(i){for(const o of i)if(o.type=="insert"&&r>=o.offset&&ri){for(let s=0;s1500)for(let s=0;sthis._version+1&&this._gaps.set(this._version,e),this._version=e}get lastOperation(){return this._operations[this._operations.length-1]}addOperation(e){if(e.baseVersion!==this.version)throw new oe("model-document-history-addoperation-incorrect-version",this,{operation:e,historyVersion:this.version});this._operations.push(e),this._version++,this._baseVersionToOperationIndex.set(e.baseVersion,this._operations.length-1)}getOperations(e,n=this.version){if(!this._operations.length)return[];const i=this._operations[0];e===void 0&&(e=i.baseVersion);let r=n-1;for(const[a,l]of this._gaps)e>a&&ea&&rthis.lastOperation.baseVersion)return[];let o=this._baseVersionToOperationIndex.get(e);o===void 0&&(o=0);let s=this._baseVersionToOperationIndex.get(r);return s===void 0&&(s=this._operations.length-1),this._operations.slice(o,s+1)}getOperation(e){const n=this._baseVersionToOperationIndex.get(e);if(n!==void 0)return this._operations[n]}setOperationAsUndone(e,n){this._undoPairs.set(n,e),this._undoneOperations.add(e)}isUndoingOperation(e){return this._undoPairs.has(e)}isUndoneOperation(e){return this._undoneOperations.has(e)}getUndoneOperation(e){return this._undoPairs.get(e)}reset(){this._version=0,this._undoPairs=new Map,this._operations=[],this._undoneOperations=new Set,this._gaps=new Map,this._baseVersionToOperationIndex=new Map}}class h1 extends zn{rootName;_document;_isAttached=!0;_isLoaded=!0;constructor(e,n,i="main"){super(n),this._document=e,this.rootName=i}get document(){return this._document}isAttached(){return this._isAttached}toJSON(){return this.rootName}}h1.prototype.is=function(t,e){return e?e===this.name&&(t==="rootElement"||t==="model:rootElement"||t==="element"||t==="model:element"):t==="rootElement"||t==="model:rootElement"||t==="element"||t==="model:element"||t==="node"||t==="model:node"};const K4="$graveyard";class e5e extends Fn(){model;history;selection;roots;differ;isReadOnly;_postFixers;_hasSelectionChangedFromTheLastChangeBlock;constructor(e){super(),this.model=e,this.history=new QLe,this.selection=new cs(this),this.roots=new Er({idProperty:"rootName"}),this.differ=new f1(e.markers),this.isReadOnly=!1,this._postFixers=new Set,this._hasSelectionChangedFromTheLastChangeBlock=!1,this.createRoot("$root",K4),this.listenTo(e,"applyOperation",(n,i)=>{const r=i[0];r.isDocumentOperation&&this.differ.bufferOperation(r)},{priority:"high"}),this.listenTo(e,"applyOperation",(n,i)=>{const r=i[0];r.isDocumentOperation&&this.history.addOperation(r)},{priority:"low"}),this.listenTo(this.selection,"change",()=>{this._hasSelectionChangedFromTheLastChangeBlock=!0}),this.listenTo(e.markers,"update",(n,i,r,o,s)=>{const a={...i.getData(),range:o};this.differ.bufferMarkerChange(i.name,s,a),r===null&&i.on("change",(l,u)=>{const c=i.getData();this.differ.bufferMarkerChange(i.name,{...c,range:u},c)})}),this.registerPostFixer(n=>{let i=!1;for(const r of this.roots)!r.isAttached()&&!r.isEmpty&&(n.remove(n.createRangeIn(r)),i=!0);for(const r of this.model.markers)r.getRange().root.isAttached()||(n.removeMarker(r),i=!0);return i})}get version(){return this.history.version}set version(e){this.history.version=e}get graveyard(){return this.getRoot(K4)}createRoot(e="$root",n="main"){if(this.roots.get(n))throw new oe("model-document-createroot-name-exists",this,{name:n});const i=new h1(this,e,n);return this.roots.add(i),i}destroy(){this.selection.destroy(),this.stopListening()}getRoot(e="main"){return this.roots.get(e)}getRootNames(e=!1){return this.getRoots(e).map(n=>n.rootName)}getRoots(e=!1){return this.roots.filter(n=>n!=this.graveyard&&(e||n.isAttached())&&n._isLoaded)}registerPostFixer(e){this._postFixers.add(e)}toJSON(){const e=SIe(this);return e.selection="[engine.model.DocumentSelection]",e.model="[engine.model.Model]",e}_handleChangeBlock(e){this._hasDocumentChangedFromTheLastChangeBlock()&&(this._callPostFixers(e),this.selection.refresh(),this.differ.hasDataChanges()?this.fire("change:data",e.batch):this.fire("change",e.batch),this.selection.refresh(),this.differ.reset()),this._hasSelectionChangedFromTheLastChangeBlock=!1}_hasDocumentChangedFromTheLastChangeBlock(){return!this.differ.isEmpty||this._hasSelectionChangedFromTheLastChangeBlock}_getDefaultRoot(){const e=this.getRoots();return e.length?e[0]:this.graveyard}_getDefaultRange(){const e=this._getDefaultRoot(),n=this.model,i=n.schema,r=n.createPositionFromPath(e,[0]);return i.getNearestSelectionRange(r)||n.createRange(r)}_validateSelectionRange(e){return e.start.isValid()&&e.end.isValid()&&G4(e.start)&&G4(e.end)}_callPostFixers(e){let n=!1;do for(const i of this._postFixers)if(this.selection.refresh(),n=i(e),n)break;while(n)}}function G4(t){const e=t.textNode;if(e){const n=e.data,i=t.offset-e.startOffset;return!UM(n,i)&&!WM(n,i)}return!0}class t5e extends Fn(){_markers=new Map;[Symbol.iterator](){return this._markers.values()}has(e){const n=e instanceof Bh?e.name:e;return this._markers.has(n)}get(e){return this._markers.get(e)||null}_set(e,n,i=!1,r=!1){const o=e instanceof Bh?e.name:e;if(o.includes(","))throw new oe("markercollection-incorrect-marker-name",this);const s=this._markers.get(o);if(s){const u=s.getData(),c=s.getRange();let d=!1;return c.isEqual(n)||(s._attachLiveRange(ko.fromRange(n)),d=!0),i!=s.managedUsingOperations&&(s._managedUsingOperations=i,d=!0),typeof r=="boolean"&&r!=s.affectsData&&(s._affectsData=r,d=!0),d&&this.fire(`update:${o}`,s,c,n,u),s}const a=ko.fromRange(n),l=new Bh(o,a,i,r);return this._markers.set(o,l),this.fire(`update:${o}`,l,null,n,{...l.getData(),range:null}),l}_remove(e){const n=e instanceof Bh?e.name:e,i=this._markers.get(n);return i?(this._markers.delete(n),this.fire(`update:${n}`,i,i.getRange(),null,i.getData()),this._destroyMarker(i),!0):!1}_refresh(e){const n=e instanceof Bh?e.name:e,i=this._markers.get(n);if(!i)throw new oe("markercollection-refresh-marker-not-exists",this);const r=i.getRange();this.fire(`update:${n}`,i,r,r,i.getData())}*getMarkersAtPosition(e){for(const n of this)n.getRange().containsPosition(e)&&(yield n)}*getMarkersIntersectingRange(e){for(const n of this)n.getRange().getIntersection(e)!==null&&(yield n)}destroy(){for(const e of this._markers.values())this._destroyMarker(e);this._markers=null,this.stopListening()}*getMarkersGroup(e){for(const n of this._markers.values())n.name.startsWith(e+":")&&(yield n)}_destroyMarker(e){e.stopListening(),e._detachLiveRange()}}class Bh extends Fn(Kc){name;_managedUsingOperations;_affectsData;_liveRange;constructor(e,n,i,r){super(),this.name=e,this._liveRange=this._attachLiveRange(n),this._managedUsingOperations=i,this._affectsData=r}get managedUsingOperations(){if(!this._liveRange)throw new oe("marker-destroyed",this);return this._managedUsingOperations}get affectsData(){if(!this._liveRange)throw new oe("marker-destroyed",this);return this._affectsData}getData(){return{range:this.getRange(),affectsData:this.affectsData,managedUsingOperations:this.managedUsingOperations}}getStart(){if(!this._liveRange)throw new oe("marker-destroyed",this);return this._liveRange.start.clone()}getEnd(){if(!this._liveRange)throw new oe("marker-destroyed",this);return this._liveRange.end.clone()}getRange(){if(!this._liveRange)throw new oe("marker-destroyed",this);return this._liveRange.toRange()}toJSON(){return{name:this.name,range:this._liveRange?.toJSON(),usingOperations:this._managedUsingOperations,affectsData:this._affectsData}}_attachLiveRange(e){return this._liveRange&&this._detachLiveRange(),e.delegate("change:range").to(this),e.delegate("change:content").to(this),this._liveRange=e,e}_detachLiveRange(){this._liveRange.stopDelegating("change:range",this),this._liveRange.stopDelegating("change:content",this),this._liveRange.detach(),this._liveRange=null}}Bh.prototype.is=function(t){return t==="marker"||t==="model:marker"};class n5e extends ds{sourcePosition;howMany;constructor(e,n){super(null),this.sourcePosition=e.clone(),this.howMany=n}get type(){return"detach"}get affectedSelectable(){return null}toJSON(){const e=super.toJSON();return e.sourcePosition=this.sourcePosition.toJSON(),e}_validate(){if(this.sourcePosition.root.document)throw new oe("detach-operation-on-document-node",this)}_execute(){zG(Ee._createFromPositionAndShift(this.sourcePosition,this.howMany))}static get className(){return"DetachOperation"}}class za extends Kc{markers=new Map;_children=new iv;constructor(e){super(),e&&this._insertChild(0,e)}[Symbol.iterator](){return this.getChildren()}get childCount(){return this._children.length}get maxOffset(){return this._children.maxOffset}get isEmpty(){return this.childCount===0}get nextSibling(){return null}get previousSibling(){return null}get root(){return this}get parent(){return null}get document(){return null}isAttached(){return!1}getAncestors(){return[]}getChild(e){return this._children.getNode(e)}getChildAtOffset(e){return this._children.getNodeAtOffset(e)}getChildren(){return this._children[Symbol.iterator]()}getChildIndex(e){return this._children.getNodeIndex(e)}getChildStartOffset(e){return this._children.getNodeStartOffset(e)}getPath(){return[]}getNodeByPath(e){let n=this;for(const i of e)n=n.getChildAtOffset(i);return n}offsetToIndex(e){return this._children.offsetToIndex(e)}toJSON(){const e=[];for(const n of this._children)e.push(n.toJSON());return e}static fromJSON(e){const n=[];for(const i of e)i.name?n.push(zn.fromJSON(i)):n.push(ni.fromJSON(i));return new za(n)}_appendChild(e){this._insertChild(this.childCount,e)}_insertChild(e,n){const i=i5e(n);for(const r of i)r.parent!==null&&r._remove(),r.parent=this;this._children._insertNodes(e,i)}_removeChildren(e,n=1){const i=this._children._removeNodes(e,n);for(const r of i)r.parent=null;return i}_removeChildrenArray(e){this._children._removeNodesArray(e);for(const n of e)n.parent=null}}za.prototype.is=function(t){return t==="documentFragment"||t==="model:documentFragment"};function i5e(t){return typeof t=="string"?[new ni(t)]:(us(t)||(t=[t]),Array.from(t).map(e=>typeof e=="string"?new ni(e):e instanceof ea?new ni(e.data,e.getAttributes()):e))}class r5e{model;batch;constructor(e,n){this.model=e,this.batch=n}createText(e,n){return new ni(e,n)}createElement(e,n){return new zn(e,n)}createDocumentFragment(){return new za}cloneElement(e,n=!0){return e._clone(n)}insert(e,n,i=0){if(this._assertWriterUsedCorrectly(),e instanceof ni&&e.data=="")return;const r=Be._createAt(n,i);if(e.parent)if(J4(e.root,r.root)){this.move(Ee._createOn(e),r);return}else{if(e.root.document)throw new oe("model-writer-insert-forbidden-move",this);this.remove(e)}const o=r.root.document?r.root.document.version:null,s=e instanceof za?e._removeChildren(0,e.childCount):e,a=new hr(r,s,o);if(e instanceof ni&&(a.shouldReceiveAttributes=!0),this.batch.addOperation(a),this.model.applyOperation(a),e instanceof za)for(const[l,u]of e.markers){const c=Be._createAt(u.root,0),f={range:new Ee(u.start._getCombined(c,r),u.end._getCombined(c,r)),usingOperation:!0,affectsData:!0};this.model.markers.has(l)?this.updateMarker(l,f):this.addMarker(l,f)}}insertText(e,n,i,r){n instanceof za||n instanceof zn||n instanceof Be?this.insert(this.createText(e),n,i):this.insert(this.createText(e,n),i,r)}insertElement(e,n,i,r){n instanceof za||n instanceof zn||n instanceof Be?this.insert(this.createElement(e),n,i):this.insert(this.createElement(e,n),i,r)}append(e,n){this.insert(e,n,"end")}appendText(e,n,i){n instanceof za||n instanceof zn?this.insert(this.createText(e),n,"end"):this.insert(this.createText(e,n),i,"end")}appendElement(e,n,i){n instanceof za||n instanceof zn?this.insert(this.createElement(e),n,"end"):this.insert(this.createElement(e,n),i,"end")}setAttribute(e,n,i){if(this._assertWriterUsedCorrectly(),i instanceof Ee){const r=i.getMinimalFlatRanges();for(const o of r)Y4(this,e,n,o)}else X4(this,e,n,i)}setAttributes(e,n){for(const[i,r]of gl(e))this.setAttribute(i,r,n)}removeAttribute(e,n){if(this._assertWriterUsedCorrectly(),n instanceof Ee){const i=n.getMinimalFlatRanges();for(const r of i)Y4(this,e,null,r)}else X4(this,e,null,n)}clearAttributes(e){this._assertWriterUsedCorrectly();const n=i=>{for(const r of i.getAttributeKeys())this.removeAttribute(r,i)};if(!(e instanceof Ee))n(e);else for(const i of e.getItems())n(i)}move(e,n,i){if(this._assertWriterUsedCorrectly(),!(e instanceof Ee))throw new oe("writer-move-invalid-range",this);if(!e.isFlat)throw new oe("writer-move-range-not-flat",this);const r=Be._createAt(n,i);if(r.isEqual(e.start))return;if(this._addOperationForAffectedMarkers("move",e),!J4(e.root,r.root))throw new oe("writer-move-different-document",this);const o=e.root.document?e.root.document.version:null,s=new Tn(e.start,e.end.offset-e.start.offset,r,o);this.batch.addOperation(s),this.model.applyOperation(s)}remove(e){this._assertWriterUsedCorrectly();const i=(e instanceof Ee?e:Ee._createOn(e)).getMinimalFlatRanges().reverse();for(const r of i)this._addOperationForAffectedMarkers("move",r),o5e(r.start,r.end.offset-r.start.offset,this.batch,this.model)}merge(e){this._assertWriterUsedCorrectly();const n=e.nodeBefore,i=e.nodeAfter;if(this._addOperationForAffectedMarkers("merge",e),!(n instanceof zn))throw new oe("writer-merge-no-element-before",this);if(!(i instanceof zn))throw new oe("writer-merge-no-element-after",this);e.root.document?this._merge(e):this._mergeDetached(e)}createPositionFromPath(e,n,i){return this.model.createPositionFromPath(e,n,i)}createPositionAt(e,n){return this.model.createPositionAt(e,n)}createPositionAfter(e){return this.model.createPositionAfter(e)}createPositionBefore(e){return this.model.createPositionBefore(e)}createRange(e,n){return this.model.createRange(e,n)}createRangeIn(e){return this.model.createRangeIn(e)}createRangeOn(e){return this.model.createRangeOn(e)}createSelection(...e){return this.model.createSelection(...e)}_mergeDetached(e){const n=e.nodeBefore,i=e.nodeAfter;this.move(Ee._createIn(i),Be._createAt(n,"end")),this.remove(i)}_merge(e){const n=Be._createAt(e.nodeBefore,"end"),i=Be._createAt(e.nodeAfter,0),r=e.root.document.graveyard,o=new Be(r,[0]),s=e.root.document.version,a=new Ai(i,e.nodeAfter.maxOffset,n,o,s);this.batch.addOperation(a),this.model.applyOperation(a)}rename(e,n){if(this._assertWriterUsedCorrectly(),!(e instanceof zn))throw new oe("writer-rename-not-element-instance",this);const i=e.root.document?e.root.document.version:null,r=new Po(Be._createBefore(e),e.name,n,i);this.batch.addOperation(r),this.model.applyOperation(r)}split(e,n){this._assertWriterUsedCorrectly();let i=e.parent;if(!i.parent)throw new oe("writer-split-element-no-parent",this);if(n||(n=i.parent),!e.parent.getAncestors({includeSelf:!0}).includes(n))throw new oe("writer-split-invalid-limit-element",this);let r,o;do{const s=i.root.document?i.root.document.version:null,a=i.maxOffset-e.offset,l=Hn.getInsertionPosition(e),u=new Hn(e,a,l,null,s);this.batch.addOperation(u),this.model.applyOperation(u),!r&&!o&&(r=i,o=e.parent.nextSibling),e=this.createPositionAfter(e.parent),i=e.parent}while(i!==n);return{position:e,range:new Ee(Be._createAt(r,"end"),Be._createAt(o,0))}}wrap(e,n){if(this._assertWriterUsedCorrectly(),!e.isFlat)throw new oe("writer-wrap-range-not-flat",this);const i=n instanceof zn?n:new zn(n);if(i.childCount>0)throw new oe("writer-wrap-element-not-empty",this);if(i.parent!==null)throw new oe("writer-wrap-element-attached",this);this.insert(i,e.start);const r=new Ee(e.start.getShiftedBy(1),e.end.getShiftedBy(1));this.move(r,Be._createAt(i,0))}unwrap(e){if(this._assertWriterUsedCorrectly(),e.parent===null)throw new oe("writer-unwrap-element-no-parent",this);this.move(Ee._createIn(e),this.createPositionAfter(e)),this.remove(e)}addMarker(e,n){if(this._assertWriterUsedCorrectly(),!n||typeof n.usingOperation!="boolean")throw new oe("writer-addmarker-no-usingoperation",this);const i=n.usingOperation,r=n.range,o=n.affectsData===void 0?!1:n.affectsData;if(this.model.markers.has(e))throw new oe("writer-addmarker-marker-exists",this);if(!r)throw new oe("writer-addmarker-no-range",this);return i?(Wg(this,e,null,r,o),this.model.markers.get(e)):this.model.markers._set(e,r,i,o)}updateMarker(e,n){this._assertWriterUsedCorrectly();const i=typeof e=="string"?e:e.name,r=this.model.markers.get(i);if(!r)throw new oe("writer-updatemarker-marker-not-exists",this);if(!n){hn("writer-updatemarker-reconvert-using-editingcontroller",{markerName:i}),this.model.markers._refresh(r);return}const o=typeof n.usingOperation=="boolean",s=typeof n.affectsData=="boolean",a=s?n.affectsData:r.affectsData;if(!o&&!n.range&&!s)throw new oe("writer-updatemarker-wrong-options",this);const l=r.getRange(),u=n.range?n.range:l;if(o&&n.usingOperation!==r.managedUsingOperations){n.usingOperation?Wg(this,i,null,u,a):(Wg(this,i,l,null,a),this.model.markers._set(i,u,void 0,a));return}r.managedUsingOperations?Wg(this,i,l,u,a):this.model.markers._set(i,u,void 0,a)}removeMarker(e){this._assertWriterUsedCorrectly();const n=typeof e=="string"?e:e.name;if(!this.model.markers.has(n))throw new oe("writer-removemarker-no-marker",this);const i=this.model.markers.get(n);if(!i.managedUsingOperations){this.model.markers._remove(n);return}const r=i.getRange();Wg(this,n,r,null,i.affectsData)}addRoot(e,n="$root"){this._assertWriterUsedCorrectly();const i=this.model.document.getRoot(e);if(i&&i.isAttached())throw new oe("writer-addroot-root-exists",this);const r=this.model.document,o=new Qa(e,n,!0,r,r.version);return this.batch.addOperation(o),this.model.applyOperation(o),this.model.document.getRoot(e)}detachRoot(e){this._assertWriterUsedCorrectly();const n=typeof e=="string"?this.model.document.getRoot(e):e;if(!n||!n.isAttached())throw new oe("writer-detachroot-no-root",this);for(const o of this.model.markers)o.getRange().root===n&&this.removeMarker(o);for(const o of n.getAttributeKeys())this.removeAttribute(o,n);this.remove(this.createRangeIn(n));const i=this.model.document,r=new Qa(n.rootName,n.name,!1,i,i.version);this.batch.addOperation(r),this.model.applyOperation(r)}setSelection(...e){this._assertWriterUsedCorrectly(),this.model.document.selection._setTo(...e)}setSelectionFocus(e,n){this._assertWriterUsedCorrectly(),this.model.document.selection._setFocus(e,n)}setSelectionAttribute(e,n){if(this._assertWriterUsedCorrectly(),typeof e=="string")this._setSelectionAttribute(e,n);else for(const[i,r]of gl(e))this._setSelectionAttribute(i,r)}removeSelectionAttribute(e){if(this._assertWriterUsedCorrectly(),typeof e=="string")this._removeSelectionAttribute(e);else for(const n of e)this._removeSelectionAttribute(n)}overrideSelectionGravity(){return this.model.document.selection._overrideGravity()}restoreSelectionGravity(e){this.model.document.selection._restoreGravity(e)}_setSelectionAttribute(e,n){const i=this.model.document.selection;if(i.isCollapsed&&i.anchor.parent.isEmpty){const r=cs._getStoreAttributeKey(e);this.setAttribute(r,n,i.anchor.parent)}i._setAttribute(e,n)}_removeSelectionAttribute(e){const n=this.model.document.selection;if(n.isCollapsed&&n.anchor.parent.isEmpty){const i=cs._getStoreAttributeKey(e);this.removeAttribute(i,n.anchor.parent)}n._removeAttribute(e)}_assertWriterUsedCorrectly(){if(this.model._currentWriter!==this)throw new oe("writer-incorrect-use",this)}_addOperationForAffectedMarkers(e,n){for(const i of this.model.markers){if(!i.managedUsingOperations)continue;const r=i.getRange();let o=!1;if(e==="move"){const s=n;o=s.containsPosition(r.start)||s.start.isEqual(r.start)||s.containsPosition(r.end)||s.end.isEqual(r.end)}else{const s=n,a=s.nodeBefore,l=s.nodeAfter,u=r.start.parent==a&&r.start.isAtEnd,c=r.end.parent==l&&r.end.offset==0,d=r.end.nodeAfter==l,f=r.start.nodeAfter==l;o=u||c||d||f}o&&this.updateMarker(i.name,{range:r})}}}function Y4(t,e,n,i){const r=t.model,o=r.document;let s=i.start,a,l,u;for(const d of i.getWalker({shallow:!0}))u=d.item.getAttribute(e),a&&l!=u&&(l!=n&&c(),s=a),a=d.nextPosition,l=u;a instanceof Be&&a!=s&&l!=n&&c();function c(){const d=new Ee(s,a),f=d.root.document?o.version:null,h=new zi(d,e,l,n,f);t.batch.addOperation(h),r.applyOperation(h)}}function X4(t,e,n,i){const r=t.model,o=r.document,s=i.getAttribute(e);let a,l;if(s!=n){if(i.root===i){const c=i.document?o.version:null;l=new au(i,e,s,n,c)}else{a=new Ee(Be._createBefore(i),t.createPositionAfter(i));const c=a.root.document?o.version:null;l=new zi(a,e,s,n,c)}t.batch.addOperation(l),r.applyOperation(l)}}function Wg(t,e,n,i,r){const o=t.model,s=o.document,a=new no(e,n,i,o.markers,!!r,s.version);t.batch.addOperation(a),o.applyOperation(a)}function o5e(t,e,n,i){let r;if(t.root.document){const o=i.document,s=new Be(o.graveyard,[0]);r=new Tn(t,e,s,o.version)}else r=new n5e(t,e);n.addOperation(r),i.applyOperation(r)}function J4(t,e){return t===e||t instanceof h1&&e instanceof h1}function s5e(t){t.document.registerPostFixer(e=>a5e(e,t))}function a5e(t,e){const n=e.document.selection,i=e.schema,r=[];let o=!1;for(const s of n.getRanges()){const a=eO(s,i);a&&!a.isEqual(s)?(r.push(a),o=!0):r.push(s)}return o&&t.setSelection(d5e(r),{backward:n.isBackward}),!1}function eO(t,e){return t.isCollapsed?l5e(t,e):u5e(t,e)}function l5e(t,e){const n=t.start,i=e.getNearestSelectionRange(n);if(!i){const o=n.getAncestors().reverse().find(s=>e.isObject(s));return o?Ee._createOn(o):null}if(!i.isCollapsed)return i;const r=i.start;return n.isEqual(r)?null:new Ee(r)}function u5e(t,e){const{start:n,end:i}=t,r=e.checkChild(n,"$text"),o=e.checkChild(i,"$text"),s=e.getLimitElement(n),a=e.getLimitElement(i);if(s===a){if(r&&o)return null;if(c5e(n,i,e)){const d=n.nodeAfter&&e.isSelectable(n.nodeAfter)?null:e.getNearestSelectionRange(n,"forward"),h=i.nodeBefore&&e.isSelectable(i.nodeBefore)?null:e.getNearestSelectionRange(i,"backward"),m=d?d.start:n,g=h?h.end:i;return new Ee(m,g)}}const l=s&&!s.is("rootElement"),u=a&&!a.is("rootElement");if(l||u){const c=n.nodeAfter&&i.nodeBefore&&n.nodeAfter.parent===i.nodeBefore.parent,d=l&&(!c||!Q4(n.nodeAfter,e)),f=u&&(!c||!Q4(i.nodeBefore,e));let h=n,m=i;return d&&(h=Be._createBefore(Z4(s,e))),f&&(m=Be._createAfter(Z4(a,e))),new Ee(h,m)}return null}function Z4(t,e){let n=t,i=n;for(;e.isLimit(i)&&i.parent;)n=i,i=i.parent;return n}function c5e(t,e,n){const i=t.nodeAfter&&!n.isLimit(t.nodeAfter)||n.checkChild(t,"$text"),r=e.nodeBefore&&!n.isLimit(e.nodeBefore)||n.checkChild(e,"$text");return i||r}function d5e(t){const e=[...t],n=new Set;let i=1;for(;i!n.has(s))}function Q4(t,e){return t&&e.isSelectable(t)}function f5e(t,e,n={}){if(e.isCollapsed)return;const i=e.getFirstRange();if(i.root.rootName=="$graveyard")return;const r=t.schema;t.change(o=>{if(!n.doNotResetEntireContent&&_5e(r,e)){w5e(o,e);return}const s={};if(!n.doNotAutoparagraph){const u=e.getSelectedElement();u&&Object.assign(s,r.getAttributesWithProperty(u,"copyOnReplace",!0))}let a,l;n.doNotFixSelection?(a=Bi.fromPosition(i.start,"toPrevious"),l=Bi.fromPosition(i.end,"toNext")):[a,l]=h5e(i),a.isTouching(l)||o.remove(o.createRange(a,l)),n.leaveUnmerged||(g5e(o,a,l),r.removeDisallowedAttributes(a.parent.getChildren(),o)),GG(o,e,a),!n.doNotAutoparagraph&&b5e(r,a)&&KG(o,a,e,s),a.detach(),l.detach()})}function h5e(t){const e=t.root.document.model,n=t.start;let i=t.end;if(e.hasContent(t,{ignoreMarkers:!0})){const r=m5e(i);if(r&&i.isTouching(e.createPositionAt(r,0))){const o=e.createSelection(t);e.modifySelection(o,{direction:"backward"});const s=o.getLastPosition(),a=e.createRange(s,i);e.hasContent(a,{ignoreMarkers:!0})||(i=s)}}return[Bi.fromPosition(n,"toPrevious"),Bi.fromPosition(i,"toNext")]}function m5e(t){const e=t.parent,n=e.root.document.model.schema,i=e.getAncestors({parentFirst:!0,includeSelf:!0});for(const r of i){if(n.isLimit(r))return null;if(n.isBlock(r))return r}}function g5e(t,e,n){const i=t.model;if(!tO(t.model.schema,e,n))return;const[r,o]=v5e(e,n);!r||!o||(!i.hasContent(r,{ignoreMarkers:!0})&&i.hasContent(o,{ignoreMarkers:!0})?jG(t,e,n,r.parent):qG(t,e,n,r.parent))}function qG(t,e,n,i){const r=e.parent,o=n.parent;if(!(r==i||o==i)){for(e=t.createPositionAfter(r),n=t.createPositionBefore(o),n.isEqual(e)||t.insert(o,e),t.merge(e);n.parent.isEmpty;){const s=n.parent;n=t.createPositionBefore(s),t.remove(s)}tO(t.model.schema,e,n)&&qG(t,e,n,i)}}function jG(t,e,n,i){const r=e.parent,o=n.parent;if(!(r==i||o==i)){for(e=t.createPositionAfter(r),n=t.createPositionBefore(o),n.isEqual(e)||t.insert(r,n);e.parent.isEmpty;){const s=e.parent;e=t.createPositionBefore(s),t.remove(s)}n=t.createPositionBefore(o),p5e(t,n),tO(t.model.schema,e,n)&&jG(t,e,n,i)}}function p5e(t,e){const n=e.nodeBefore,i=e.nodeAfter;n.name!=i.name&&t.rename(n,i.name),t.clearAttributes(n),t.setAttributes(Object.fromEntries(i.getAttributes()),n),t.merge(e)}function tO(t,e,n){const i=e.parent,r=n.parent;return i==r||t.isLimit(i)||t.isLimit(r)?!1:y5e(e,n,t)}function v5e(t,e){const n=t.getAncestors(),i=e.getAncestors();let r=0;for(;n[r]&&n[r]==i[r];)r++;return[n[r],i[r]]}function b5e(t,e){const n=t.checkChild(e,"$text"),i=t.checkChild(e,"paragraph");return!n&&i}function y5e(t,e,n){const i=new Ee(t,e);for(const r of i.getWalker())if(n.isLimit(r.item))return!1;return!0}function KG(t,e,n,i={}){const r=t.createElement("paragraph");t.model.schema.setAllowedAttributes(r,i,t),t.insert(r,e),GG(t,n,t.createPositionAt(r,0))}function w5e(t,e){const n=t.model.schema.getLimitElement(e);t.remove(t.createRangeIn(n)),KG(t,t.createPositionAt(n,0),e)}function _5e(t,e){const n=t.getLimitElement(e);if(!e.containsEntireContent(n))return!1;const i=e.getFirstRange();return i.start.parent==i.end.parent?!1:t.checkChild(n,"paragraph")}function GG(t,e,n){e instanceof cs?t.setSelection(n):e.setTo(n)}function C5e(t,e){return t.change(n=>{const i=n.createDocumentFragment(),r=e.getFirstRange();if(!r||r.isCollapsed)return i;const o=r.start.root,s=r.start.getCommonPath(r.end),a=o.getNodeByPath(s);let l;r.start.parent==r.end.parent?l=r:l=n.createRange(n.createPositionAt(a,r.start.path[s.length]),n.createPositionAt(a,r.end.path[s.length]+1));const u=l.end.offset-l.start.offset;for(const c of l.getItems({shallow:!0}))c.is("$textProxy")?n.appendText(c.data,c.getAttributes(),i):n.append(n.cloneElement(c,!0),i);if(l!=r){const c=r._getTransformedByMove(l.start,n.createPositionAt(i,0),u)[0],d=n.createRange(n.createPositionAt(i,0),c.start),f=n.createRange(c.end,n.createPositionAt(i,"end"));eV(f,n),eV(d,n)}return i})}function eV(t,e){const n=[];Array.from(t.getItems({direction:"backward"})).map(i=>e.createRangeOn(i)).filter(i=>(i.start.isAfter(t.start)||i.start.isEqual(t.start))&&(i.end.isBefore(t.end)||i.end.isEqual(t.end))).forEach(i=>{n.push(i.start.parent),e.remove(i)}),n.forEach(i=>{let r=i;for(;r.parent&&r.isEmpty;){const o=e.createRangeOn(r);r=r.parent,e.remove(o)}})}function S5e(t,e,n){return t.change(i=>{const r=n||t.document.selection;r.isCollapsed||t.deleteContent(r,{doNotAutoparagraph:!0});const o=new k5e(t,i,r.anchor),s=[];let a;if(e.is("documentFragment")){if(e.markers.size){const c=[];for(const[d,f]of e.markers){const{start:h,end:m}=f,g=h.isEqual(m);c.push({position:h,name:d,isCollapsed:g},{position:m,name:d,isCollapsed:g})}c.sort(({position:d},{position:f})=>d.isBefore(f)?1:-1);for(const{position:d,name:f,isCollapsed:h}of c){let m=null,g=null;const v=d.parent===e&&d.isAtStart,p=d.parent===e&&d.isAtEnd;!v&&!p?(m=i.createElement("$marker"),i.insert(m,d)):h&&(g=v?"start":"end"),s.push({name:f,element:m,collapsed:g})}}a=e.getChildren()}else a=[e];o.handleNodes(a);let l=o.getSelectionRange();if(e.is("documentFragment")&&s.length){const c=l?ko.fromRange(l):null,d={};for(let f=s.length-1;f>=0;f--){const{name:h,element:m,collapsed:g}=s[f],v=!d[h];if(v&&(d[h]=[]),m){const p=i.createPositionAt(m,"before");d[h].push(p),i.remove(m)}else{const p=o.getAffectedRange();if(!p){g&&d[h].push(o.position);continue}g?d[h].push(p[g]):d[h].push(v?p.start:p.end)}}for(const[f,[h,m]]of Object.entries(d))h&&m&&h.root===m.root&&h.root.document&&!i.model.markers.has(f)&&i.addMarker(f,{usingOperation:!0,affectsData:!0,range:new Ee(h,m)});c&&(l=c.toRange(),c.detach())}l&&(r instanceof cs?i.setSelection(l):r.setTo(l));const u=o.getAffectedRange()||t.createRange(r.anchor);return o.destroy(),u})}class k5e{model;writer;position;canMergeWith;schema;_documentFragment;_documentFragmentPosition;_firstNode=null;_lastNode=null;_lastAutoParagraph=null;_filterAttributesAndChildrenOf=[];_affectedStart=null;_affectedEnd=null;_nodeToSelect=null;constructor(e,n,i){this.model=e,this.writer=n,this.position=i,this.canMergeWith=new Set([this.position.parent]),this.schema=e.schema,this._documentFragment=n.createDocumentFragment(),this._documentFragmentPosition=n.createPositionAt(this._documentFragment,0)}handleNodes(e){for(const n of Array.from(e))n.offsetSize>0&&this._handleNode(n);this._insertPartialFragment(),this._lastAutoParagraph&&this._updateLastNodeFromAutoParagraph(this._lastAutoParagraph),this._mergeOnRight(),this.schema.removeDisallowedAttributes(this._filterAttributesAndChildrenOf,this.writer),this.model._config?.get("experimentalFlags.modelInsertContentDeepSchemaVerification")&&this._removeDisallowedChildren(this._filterAttributesAndChildrenOf),this._filterAttributesAndChildrenOf=[]}_removeDisallowedChildren(e){const n=Array.from(e);for(const i of n){if(!i.is("element"))continue;const r=[],o=[],s=this.writer.createRangeIn(i).getWalker({ignoreElementEnd:!0});for(const{item:a}of s){const l=a.parent;this.schema.checkChild(l,a)||(a.is("element")&&!this.schema.isObject(a)?(o.push(a),n.push(l)):r.push(a),s.jumpTo(this.writer.createPositionAfter(a)))}for(const a of o)this.writer.unwrap(a);for(const a of r)this.writer.remove(a)}}_updateLastNodeFromAutoParagraph(e){const n=this.writer.createPositionAfter(this._lastNode),i=this.writer.createPositionAfter(e);if(i.isAfter(n)){this._lastNode=e;if(this.position.parent!=e||!this.position.isAtEnd)throw new oe("insertcontent-invalid-insertion-position",this);this.position=i,this._setAffectedBoundaries(this.position)}}getSelectionRange(){return this._nodeToSelect?Ee._createOn(this._nodeToSelect):this.model.schema.getNearestSelectionRange(this.position)}getAffectedRange(){return this._affectedStart?new Ee(this._affectedStart,this._affectedEnd):null}destroy(){this._affectedStart&&this._affectedStart.detach(),this._affectedEnd&&this._affectedEnd.detach()}_handleNode(e){if(!this._checkAndSplitToAllowedPosition(e)){this.schema.isObject(e)||this._handleDisallowedNode(e);return}e=this._appendToFragment(e),this._firstNode||(this._firstNode=e),this._lastNode=e}_insertPartialFragment(){if(this._documentFragment.isEmpty)return;const e=Bi.fromPosition(this.position,"toNext");this._setAffectedBoundaries(this.position),this._documentFragment.getChild(0)==this._firstNode&&(this.writer.insert(this._firstNode,this.position),this._mergeOnLeft(),this.position=e.toPosition()),this._documentFragment.isEmpty||this.writer.insert(this._documentFragment,this.position),this._documentFragmentPosition=this.writer.createPositionAt(this._documentFragment,0),this.position=e.toPosition(),e.detach()}_handleDisallowedNode(e){e.is("element")&&this.handleNodes(e.getChildren())}_appendToFragment(e){if(!this.schema.checkChild(this.position,e))throw new oe("insertcontent-wrong-position",this,{node:e,position:this.position});return this.writer.insert(e,this._documentFragmentPosition),this._documentFragmentPosition=this._documentFragmentPosition.getShiftedBy(e.offsetSize),e.parent||(e=this._documentFragmentPosition.nodeBefore),this.schema.isObject(e)&&!this.schema.checkChild(this.position,"$text")?this._nodeToSelect=e:this._nodeToSelect=null,this._filterAttributesAndChildrenOf.push(e),e}_setAffectedBoundaries(e){this._affectedStart||(this._affectedStart=Bi.fromPosition(e,"toPrevious")),(!this._affectedEnd||this._affectedEnd.isBefore(e))&&(this._affectedEnd&&this._affectedEnd.detach(),this._affectedEnd=Bi.fromPosition(e,"toNext"))}_mergeOnLeft(){const e=this._firstNode;if(!(e instanceof zn)||!this._canMergeLeft(e))return;const n=Bi._createBefore(e);n.stickiness="toNext";const i=Bi.fromPosition(this.position,"toNext");this._affectedStart.isEqual(n)&&(this._affectedStart.detach(),this._affectedStart=Bi._createAt(n.nodeBefore,"end","toPrevious")),this._firstNode===this._lastNode&&(this._firstNode=n.nodeBefore,this._lastNode=n.nodeBefore),this.writer.merge(n),n.isEqual(this._affectedEnd)&&this._firstNode===this._lastNode&&(this._affectedEnd.detach(),this._affectedEnd=Bi._createAt(n.nodeBefore,"end","toNext")),this.position=i.toPosition(),i.detach(),this._filterAttributesAndChildrenOf.push(this.position.parent),n.detach()}_mergeOnRight(){const e=this._lastNode;if(!(e instanceof zn)||!this._canMergeRight(e))return;const n=Bi._createAfter(e);n.stickiness="toNext";if(!this.position.isEqual(n))throw new oe("insertcontent-invalid-insertion-position",this);this.position=Be._createAt(n.nodeBefore,"end");const i=Bi.fromPosition(this.position,"toPrevious");this._affectedEnd.isEqual(n)&&(this._affectedEnd.detach(),this._affectedEnd=Bi._createAt(n.nodeBefore,"end","toNext")),this._firstNode===this._lastNode&&(this._firstNode=n.nodeBefore,this._lastNode=n.nodeBefore),this.writer.merge(n),n.getShiftedBy(-1).isEqual(this._affectedStart)&&this._firstNode===this._lastNode&&(this._affectedStart.detach(),this._affectedStart=Bi._createAt(n.nodeBefore,0,"toPrevious")),this.position=i.toPosition(),i.detach(),this._filterAttributesAndChildrenOf.push(this.position.parent),n.detach()}_canMergeLeft(e){const n=e.previousSibling;return n instanceof zn&&this.canMergeWith.has(n)&&this.model.schema.checkMerge(n,e)}_canMergeRight(e){const n=e.nextSibling;return n instanceof zn&&this.canMergeWith.has(n)&&this.model.schema.checkMerge(e,n)}_insertAutoParagraph(){this._insertPartialFragment();const e=this.writer.createElement("paragraph");this.writer.insert(e,this.position),this._setAffectedBoundaries(this.position),this._lastAutoParagraph=e,this.position=this.writer.createPositionAt(e,0)}_checkAndSplitToAllowedPosition(e){const n=this._getAllowedIn(this.position.parent,e);if(!n)return!1;for(n!=this.position.parent&&this._insertPartialFragment();n!=this.position.parent;)if(this.position.isAtStart){const i=this.position.parent;this.position=this.writer.createPositionBefore(i),i.isEmpty&&i.parent===n&&this.writer.remove(i)}else if(this.position.isAtEnd)this.position=this.writer.createPositionAfter(this.position.parent);else{const i=this.writer.createPositionAfter(this.position.parent);this._setAffectedBoundaries(this.position),this.writer.split(this.position),this.position=i,this.canMergeWith.add(this.position.nodeAfter)}return this.schema.checkChild(this.position.parent,e)||this._insertAutoParagraph(),!0}_getAllowedIn(e,n){const i=this.schema.createContext(e);return this.schema.checkChild(i,n)||this.schema.checkChild(i,"paragraph")&&this.schema.checkChild(i.push("paragraph"),n)?e:this.schema.isLimit(e)?null:this._getAllowedIn(e.parent,n)}}function T5e(t,e,n,i={}){if(!t.schema.isObject(e))throw new oe("insertobject-element-not-an-object",t,{object:e});const r=n||t.document.selection;let o=r;i.findOptimalPosition&&t.schema.isBlock(e)&&(o=t.createSelection(t.schema.findOptimalInsertionRange(r,i.findOptimalPosition)));const s=Mi(r.getSelectedBlocks()),a={};return s&&Object.assign(a,t.schema.getAttributesWithProperty(s,"copyOnReplace",!0)),t.change(l=>{o.isCollapsed||t.deleteContent(o,{doNotAutoparagraph:!0});let u=e;const c=o.anchor.parent,d=t.schema.createContext(c);!t.schema.checkChild(d,e)&&t.schema.checkChild(d,"paragraph")&&t.schema.checkChild(d.push("paragraph"),e)&&(u=l.createElement("paragraph"),l.insert(e,u)),t.schema.setAllowedAttributes(u,a,l);const f=t.insertContent(u,o);return f.isCollapsed||i.setSelection&&E5e(l,e,i.setSelection,a),f})}function E5e(t,e,n,i){const r=t.model;if(n=="on"){t.setSelection(e,"on");return}if(n!="after")throw new oe("insertobject-invalid-place-parameter-value",r);let o=e.nextSibling;if(r.schema.isInline(e)){t.setSelection(e,"after");return}!(o&&r.schema.checkChild(o,"$text"))&&r.schema.checkChild(e.parent,"paragraph")&&(o=t.createElement("paragraph"),r.schema.setAllowedAttributes(o,i,t),r.insertContent(o,t.createPositionAfter(e))),o&&t.setSelection(o,0)}const x5e=' ,.?!:;"-()';function A5e(t,e,n={}){const i=t.schema,r=n.direction!="backward",o=n.unit?n.unit:"character",s=!!n.treatEmojiAsSingleUnit,a=e.focus,l=new Ql({boundaries:M5e(a,r),singleCharacters:!0,direction:r?"forward":"backward"}),u={walker:l,schema:i,isForward:r,unit:o,treatEmojiAsSingleUnit:s};let c;for(;c=l.next();){if(c.done)return;const d=P5e(u,c.value);if(d){e instanceof cs?t.change(f=>{f.setSelectionFocus(d)}):e.setFocus(d);return}}}function P5e(t,e){const{isForward:n,walker:i,unit:r,schema:o,treatEmojiAsSingleUnit:s}=t,{type:a,item:l,nextPosition:u}=e;if(a=="text")return t.unit==="word"?R5e(i,n):I5e(i,r,s);if(a==(n?"elementStart":"elementEnd")){if(o.isSelectable(l))return Be._createAt(l,n?"after":"before");if(o.checkChild(u,"$text"))return u}else{if(o.isLimit(l)){i.skip(()=>!0);return}if(o.checkChild(u,"$text"))return u}}function I5e(t,e,n){const i=t.position.textNode;if(i){const r=i.data;let o=t.position.offset-i.startOffset;for(;UM(r,o)||e=="character"&&WM(r,o)||n&&aG(r,o);)t.next(),o=t.position.offset-i.startOffset}return t.position}function R5e(t,e){let n=t.position.textNode;for(n||(n=e?t.position.nodeAfter:t.position.nodeBefore);n&&n.is("$text");){const i=t.position.offset-n.startOffset;if(L5e(n,i,e))n=e?t.position.nodeAfter:t.position.nodeBefore;else{if(O5e(n.data,i,e))break;t.next()}}return t.position}function M5e(t,e){const n=t.root,i=Be._createAt(n,e?"end":0);return e?new Ee(t,i):new Ee(i,t)}function O5e(t,e,n){const i=e+(n?0:-1);return x5e.includes(t.charAt(i))}function L5e(t,e,n){return e===(n?t.offsetSize:0)}let D5e=class extends Ln(){markers;document;schema;_config;_pendingChanges;_currentWriter;constructor(e){super(),this.markers=new t5e,this.document=new e5e(this),this.schema=new vLe,this._config=e,this._pendingChanges=[],this._currentWriter=null,["deleteContent","modifySelection","getSelectedContent","applyOperation"].forEach(n=>this.decorate(n)),this.on("applyOperation",(n,i)=>{i[0]._validate()},{priority:"highest"}),this.schema.register("$root",{isLimit:!0}),this.schema.register("$container",{allowIn:["$root","$container"]}),this.schema.register("$block",{allowIn:["$root","$container"],isBlock:!0}),this.schema.register("$blockObject",{allowWhere:"$block",isBlock:!0,isObject:!0}),this.schema.register("$inlineObject",{allowWhere:"$text",allowAttributesOf:"$text",isInline:!0,isObject:!0}),this.schema.register("$text",{allowIn:"$block",isInline:!0,isContent:!0}),this.schema.register("$clipboardHolder",{allowContentOf:"$root",allowChildren:"$text",isLimit:!0}),this.schema.register("$documentFragment",{allowContentOf:"$root",allowChildren:"$text",isLimit:!0}),this.schema.register("$marker"),this.schema.addChildCheck(()=>!0,"$marker"),s5e(this),this.document.registerPostFixer(DG),this.on("insertContent",(n,[i,r])=>{n.return=S5e(this,i,r)}),this.on("insertObject",(n,[i,r,o])=>{n.return=T5e(this,i,r,o)}),this.on("canEditAt",n=>{const i=!this.document.isReadOnly;n.return=i,i||n.stop()})}change(e){try{return this._pendingChanges.length===0?(this._pendingChanges.push({batch:new lh,callback:e}),this._runPendingChanges()[0]):e(this._currentWriter)}catch(n){oe.rethrowUnexpectedError(n,this)}}enqueueChange(e,n){try{e?typeof e=="function"?(n=e,e=new lh):e instanceof lh||(e=new lh(e)):e=new lh,this._pendingChanges.push({batch:e,callback:n}),this._pendingChanges.length==1&&this._runPendingChanges()}catch(i){oe.rethrowUnexpectedError(i,this)}}applyOperation(e){e._execute()}insertContent(e,n,i,...r){const o=BT(n,i);return this.fire("insertContent",[e,o,i,...r])}insertObject(e,n,i,r,...o){const s=BT(n,i);return this.fire("insertObject",[e,s,r,r,...o])}deleteContent(e,n){f5e(this,e,n)}modifySelection(e,n){A5e(this,e,n)}getSelectedContent(e){return C5e(this,e)}hasContent(e,n={}){const i=e instanceof Ee?e:Ee._createIn(e);if(i.isCollapsed)return!1;const{ignoreWhitespaces:r=!1,ignoreMarkers:o=!1}=n;if(!o){for(const s of this.markers.getMarkersIntersectingRange(i))if(s.affectsData)return!0}for(const s of i.getItems())if(this.schema.isContent(s))if(s.is("$textProxy"))if(r){if(s.data.search(/\S/)!==-1)return!0}else return!0;else return!0;return!1}canEditAt(e){const n=BT(e);return this.fire("canEditAt",[n])}createPositionFromPath(e,n,i){return new Be(e,n,i)}createPositionAt(e,n){return Be._createAt(e,n)}createPositionAfter(e){return Be._createAfter(e)}createPositionBefore(e){return Be._createBefore(e)}createRange(e,n){return new Ee(e,n)}createRangeIn(e){return Ee._createIn(e)}createRangeOn(e){return Ee._createOn(e)}createSelection(...e){return new Xo(...e)}createBatch(e){return new lh(e)}createOperationFromJSON(e){return ULe.fromJSON(e,this.document)}destroy(){this.document.destroy(),this.stopListening()}_runPendingChanges(){const e=[];this.fire("_beforeChanges");try{for(;this._pendingChanges.length;){const n=this._pendingChanges[0].batch;this._currentWriter=new r5e(this,n);const i=this._pendingChanges[0].callback(this._currentWriter);e.push(i),this.document._handleChangeBlock(this._currentWriter),this._pendingChanges.shift(),this._currentWriter=null}}finally{this._pendingChanges.length=0,this._currentWriter=null,this.fire("_afterChanges")}return e}};function BT(t,e){if(t)return t instanceof Xo||t instanceof cs?t:t instanceof Uf?e||e===0?new Xo(t,e):t.is("rootElement")?new Xo(t,"in"):new Xo(t,"on"):new Xo(t)}class N5e extends Cl{domEventType="click";onDomEvent(e){this.fire(e.type,e)}}class nO extends Cl{domEventType=["mousedown","mouseup","mouseover","mouseout"];onDomEvent(e){this.fire(e.type,e)}}class B5e extends Cl{domEventType=["touchstart","touchend","touchmove"];onDomEvent(e){this.fire(e.type,e)}}class YG extends Cl{domEventType=["pointerdown","pointerup","pointermove"];onDomEvent(e){this.fire(e.type,e)}}class Pu{document;constructor(e){this.document=e}createDocumentFragment(e){return new af(this.document,e)}createElement(e,n,i){return new ga(this.document,e,n,i)}createText(e){return new Ji(this.document,e)}clone(e,n=!1){return e._clone(n)}appendChild(e,n){return n._appendChild(e)}insertChild(e,n,i){return i._insertChild(e,n)}removeChildren(e,n,i){return i._removeChildren(e,n)}remove(e){const n=e.parent;return n?this.removeChildren(n.getChildIndex(e),1,n):[]}replace(e,n){const i=e.parent;if(i){const r=i.getChildIndex(e);return this.removeChildren(r,1,i),this.insertChild(r,n,i),!0}return!1}unwrapElement(e){const n=e.parent;if(n){const i=n.getChildIndex(e);this.remove(e),this.insertChild(i,e.getChildren(),n)}}rename(e,n){const i=new ga(this.document,e,n.getAttributes(),n.getChildren());return this.replace(n,i)?i:null}setAttribute(e,n,i){i._setAttribute(e,n)}removeAttribute(e,n){n._removeAttribute(e)}addClass(e,n){n._addClass(e)}removeClass(e,n){n._removeClass(e)}setStyle(e,n,i){Wa(e)&&i===void 0?n._setStyle(e):i._setStyle(e,n)}removeStyle(e,n){n._removeStyle(e)}setCustomProperty(e,n,i){i._setCustomProperty(e,n)}removeCustomProperty(e,n){return n._removeCustomProperty(e)}createPositionAt(e,n){return Ge._createAt(e,n)}createPositionAfter(e){return Ge._createAfter(e)}createPositionBefore(e){return Ge._createBefore(e)}createRange(e,n){return new Nt(e,n)}createRangeOn(e){return Nt._createOn(e)}createRangeIn(e){return Nt._createIn(e)}createSelection(...e){return new aa(...e)}}const V5e=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,F5e=/^rgb\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}[0-9]{1,3}[ %]?\)$/i,$5e=/^rgba\([ ]?([0-9]{1,3}[ %]?,[ ]?){3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i,z5e=/^hsl\([ ]?([0-9]{1,3}[ %]?[,]?[ ]*){3}(1|[0-9]+%|[0]?\.?[0-9]+)?\)$/i,H5e=/^hsla\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i,U5e=/\w+\((?:[^()]|\([^()]*\))*\)|\S+/gi,W5e=new Set(["black","silver","gray","white","maroon","red","purple","fuchsia","green","lime","olive","yellow","navy","blue","teal","aqua","orange","aliceblue","antiquewhite","aquamarine","azure","beige","bisque","blanchedalmond","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","gainsboro","ghostwhite","gold","goldenrod","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","limegreen","linen","magenta","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","oldlace","olivedrab","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","thistle","tomato","turquoise","violet","wheat","whitesmoke","yellowgreen","activeborder","activecaption","appworkspace","background","buttonface","buttonhighlight","buttonshadow","buttontext","captiontext","graytext","highlight","highlighttext","inactiveborder","inactivecaption","inactivecaptiontext","infobackground","infotext","menu","menutext","scrollbar","threeddarkshadow","threedface","threedhighlight","threedlightshadow","threedshadow","window","windowframe","windowtext","rebeccapurple","currentcolor","transparent"]);function XG(t){return t.startsWith("#")?V5e.test(t):t.startsWith("rgb")?F5e.test(t)||$5e.test(t):t.startsWith("hsl")?z5e.test(t)||H5e.test(t):W5e.has(t.toLowerCase())}const q5e=["none","hidden","dotted","dashed","solid","double","groove","ridge","inset","outset"];function j5e(t){return q5e.includes(t)}const K5e=/^([+-]?[0-9]*([.][0-9]+)?(px|cm|mm|in|pc|pt|ch|em|ex|rem|vh|vw|vmin|vmax)|0)$/;function vS(t){return K5e.test(t)}const G5e=/^[+-]?[0-9]*([.][0-9]+)?%$/;function JG(t){return G5e.test(t)}const Y5e=["repeat-x","repeat-y","repeat","space","round","no-repeat"];function X5e(t){return Y5e.includes(t)}const J5e=["center","top","bottom","left","right"];function Z5e(t){return J5e.includes(t)}const Q5e=["fixed","scroll","local"];function eDe(t){return Q5e.includes(t)}const tDe=/^url\(/;function nDe(t){return tDe.test(t)}function rv(t=""){if(t==="")return{top:void 0,right:void 0,bottom:void 0,left:void 0};const e=iO(t),n=e[0],i=e[2]||n,r=e[1]||n,o=e[3]||r;return{top:n,bottom:i,right:r,left:o}}function ov(t){return e=>{const{top:n,right:i,bottom:r,left:o}=e,s=[];return[n,i,o,r].every(a=>!!a)?s.push([t,iDe(e)]):(n&&s.push([t+"-top",n]),i&&s.push([t+"-right",i]),r&&s.push([t+"-bottom",r]),o&&s.push([t+"-left",o])),s}}function iDe({top:t,right:e,bottom:n,left:i}){const r=[];return i!==e?r.push(t,e,n,i):n!==t?r.push(t,e,n):e!==t?r.push(t,e):r.push(t),r.join(" ")}function ZG(t){return e=>({path:t,value:rv(e)})}function iO(t){const e=t.trim().slice(0,1500).matchAll(U5e);return Array.from(e).map(n=>n[0])}function QG(t){t.setNormalizer("background",rDe()),t.setNormalizer("background-color",oDe()),t.setReducer("background",sDe()),t.setStyleRelation("background",["background-color"])}function rDe(){return t=>{const e={},n=iO(t);for(const i of n)X5e(i)?(e.repeat=e.repeat||[],e.repeat.push(i)):Z5e(i)?(e.position=e.position||[],e.position.push(i)):eDe(i)?e.attachment=i:XG(i)?e.color=i:nDe(i)&&(e.image=i);return{path:"background",value:e}}}function oDe(){return t=>({path:"background.color",value:t})}function sDe(){return t=>{const e=[];return e.push(["background-color",t.color]),e}}function aDe(t){t.setNormalizer("border",lDe()),t.setNormalizer("border-top",sy("top")),t.setNormalizer("border-right",sy("right")),t.setNormalizer("border-bottom",sy("bottom")),t.setNormalizer("border-left",sy("left")),t.setNormalizer("border-color",VT("color")),t.setNormalizer("border-width",VT("width")),t.setNormalizer("border-style",VT("style")),t.setNormalizer("border-top-color",vs("color","top")),t.setNormalizer("border-top-style",vs("style","top")),t.setNormalizer("border-top-width",vs("width","top")),t.setNormalizer("border-right-color",vs("color","right")),t.setNormalizer("border-right-style",vs("style","right")),t.setNormalizer("border-right-width",vs("width","right")),t.setNormalizer("border-bottom-color",vs("color","bottom")),t.setNormalizer("border-bottom-style",vs("style","bottom")),t.setNormalizer("border-bottom-width",vs("width","bottom")),t.setNormalizer("border-left-color",vs("color","left")),t.setNormalizer("border-left-style",vs("style","left")),t.setNormalizer("border-left-width",vs("width","left")),t.setExtractor("border-top",ay("top")),t.setExtractor("border-right",ay("right")),t.setExtractor("border-bottom",ay("bottom")),t.setExtractor("border-left",ay("left")),t.setExtractor("border-top-color","border.color.top"),t.setExtractor("border-right-color","border.color.right"),t.setExtractor("border-bottom-color","border.color.bottom"),t.setExtractor("border-left-color","border.color.left"),t.setExtractor("border-top-width","border.width.top"),t.setExtractor("border-right-width","border.width.right"),t.setExtractor("border-bottom-width","border.width.bottom"),t.setExtractor("border-left-width","border.width.left"),t.setExtractor("border-top-style","border.style.top"),t.setExtractor("border-right-style","border.style.right"),t.setExtractor("border-bottom-style","border.style.bottom"),t.setExtractor("border-left-style","border.style.left"),t.setReducer("border-color",ov("border-color")),t.setReducer("border-style",ov("border-style")),t.setReducer("border-width",ov("border-width")),t.setReducer("border-top",ly("top")),t.setReducer("border-right",ly("right")),t.setReducer("border-bottom",ly("bottom")),t.setReducer("border-left",ly("left")),t.setReducer("border",cDe()),t.setStyleRelation("border",["border-color","border-style","border-width","border-top","border-right","border-bottom","border-left","border-top-color","border-right-color","border-bottom-color","border-left-color","border-top-style","border-right-style","border-bottom-style","border-left-style","border-top-width","border-right-width","border-bottom-width","border-left-width"]),t.setStyleRelation("border-color",["border-top-color","border-right-color","border-bottom-color","border-left-color"]),t.setStyleRelation("border-style",["border-top-style","border-right-style","border-bottom-style","border-left-style"]),t.setStyleRelation("border-width",["border-top-width","border-right-width","border-bottom-width","border-left-width"]),t.setStyleRelation("border-top",["border-top-color","border-top-style","border-top-width"]),t.setStyleRelation("border-right",["border-right-color","border-right-style","border-right-width"]),t.setStyleRelation("border-bottom",["border-bottom-color","border-bottom-style","border-bottom-width"]),t.setStyleRelation("border-left",["border-left-color","border-left-style","border-left-width"])}function lDe(){return t=>{const{color:e,style:n,width:i}=eY(t);return{path:"border",value:{color:rv(e),style:rv(n),width:rv(i)}}}}function sy(t){return e=>{const{color:n,style:i,width:r}=eY(e),o={};return n!==void 0&&(o.color={[t]:n}),i!==void 0&&(o.style={[t]:i}),r!==void 0&&(o.width={[t]:r}),{path:"border",value:o}}}function VT(t){return e=>({path:"border",value:uDe(e,t)})}function uDe(t,e){return{[e]:rv(t)}}function vs(t,e){return n=>({path:"border",value:{[t]:{[e]:n}}})}function ay(t){return(e,n)=>{if(n.border)return _p(n.border,t)}}function _p(t,e){const n={};return t.width&&t.width[e]&&(n.width=t.width[e]),t.style&&t.style[e]&&(n.style=t.style[e]),t.color&&t.color[e]&&(n.color=t.color[e]),n}function eY(t){const e={},n=iO(t);for(const i of n)vS(i)||/thin|medium|thick/.test(i)?e.width=i:j5e(i)?e.style=i:e.color=i;return e}function cDe(){return e=>{const n=_p(e,"top"),i=_p(e,"right"),r=_p(e,"bottom"),o=_p(e,"left"),s=[n,i,r,o],a={width:t(s,"width"),style:t(s,"style"),color:t(s,"color")},l=Vh(a,"all");return l.length?l:[...Object.entries(a).reduce((c,[d,f])=>(f&&(c.push([`border-${d}`,f]),s.forEach(h=>delete h[d])),c),[]),...Vh(n,"top"),...Vh(i,"right"),...Vh(r,"bottom"),...Vh(o,"left")]};function t(e,n){return e.map(i=>i[n]).reduce((i,r)=>i==r?i:null)}}function ly(t){return e=>Vh(e,t)}function Vh(t,e){const n=[];if(t&&t.width&&n.push("width"),t&&t.style&&n.push("style"),t&&t.color&&n.push("color"),n.length==3){const i=n.map(r=>t[r]).join(" ");return[e=="all"?["border",i]:[`border-${e}`,i]]}return e=="all"?[]:n.map(i=>[`border-${e}-${i}`,t[i]])}function dDe(t){t.setNormalizer("margin",ZG("margin")),t.setNormalizer("margin-top",e=>({path:"margin.top",value:e})),t.setNormalizer("margin-right",e=>({path:"margin.right",value:e})),t.setNormalizer("margin-bottom",e=>({path:"margin.bottom",value:e})),t.setNormalizer("margin-left",e=>({path:"margin.left",value:e})),t.setReducer("margin",ov("margin")),t.setStyleRelation("margin",["margin-top","margin-right","margin-bottom","margin-left"])}function fDe(t){t.setNormalizer("padding",ZG("padding")),t.setNormalizer("padding-top",e=>({path:"padding.top",value:e})),t.setNormalizer("padding-right",e=>({path:"padding.right",value:e})),t.setNormalizer("padding-bottom",e=>({path:"padding.bottom",value:e})),t.setNormalizer("padding-left",e=>({path:"padding.left",value:e})),t.setReducer("padding",ov("padding")),t.setStyleRelation("padding",["padding-top","padding-right","padding-bottom","padding-left"])}class tY{crashes=[];state="initializing";_crashNumberLimit;_now=Date.now;_minimumNonErrorTimePeriod;_boundErrorHandler;_listeners;constructor(e){if(this.crashes=[],this._crashNumberLimit=typeof e.crashNumberLimit=="number"?e.crashNumberLimit:3,this._minimumNonErrorTimePeriod=typeof e.minimumNonErrorTimePeriod=="number"?e.minimumNonErrorTimePeriod:5e3,this._boundErrorHandler=n=>{const i="error"in n?n.error:n.reason;i instanceof Error&&this._handleError(i,n)},this._listeners={},!this._restart)throw new Error("The Watchdog class was split into the abstract `Watchdog` class and the `EditorWatchdog` class. Please, use `EditorWatchdog` if you have used the `Watchdog` class previously.")}destroy(){this._stopErrorHandling(),this._listeners={}}on(e,n){this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(n)}off(e,n){this._listeners[e]=this._listeners[e].filter(i=>i!==n)}_fire(e,...n){const i=this._listeners[e]||[];for(const r of i)r.apply(this,[null,...n])}_startErrorHandling(){window.addEventListener("error",this._boundErrorHandler),window.addEventListener("unhandledrejection",this._boundErrorHandler)}_stopErrorHandling(){window.removeEventListener("error",this._boundErrorHandler),window.removeEventListener("unhandledrejection",this._boundErrorHandler)}_handleError(e,n){if(this._shouldReactToError(e)){this.crashes.push({message:e.message,stack:e.stack,filename:n instanceof ErrorEvent?n.filename:void 0,lineno:n instanceof ErrorEvent?n.lineno:void 0,colno:n instanceof ErrorEvent?n.colno:void 0,date:this._now()});const i=this._shouldRestart();this.state="crashed",this._fire("stateChange"),this._fire("error",{error:e,causesRestart:i}),i?this._restart():(this.state="crashedPermanently",this._fire("stateChange"))}}_shouldReactToError(e){return e.is&&e.is("CKEditorError")&&e.context!==void 0&&e.context!==null&&this.state==="ready"&&this._isErrorComingFromThisItem(e)}_shouldRestart(){if(this.crashes.length<=this._crashNumberLimit)return!0;const e=this.crashes[this.crashes.length-1].date,n=this.crashes[this.crashes.length-1-this._crashNumberLimit].date;return(e-n)/this._crashNumberLimit>this._minimumNonErrorTimePeriod}}function xA(t,e=new Set){const n=[t],i=new Set;let r=0;for(;n.length>r;){const o=n[r++];if(!(i.has(o)||!hDe(o)||e.has(o)))if(i.add(o),Symbol.iterator in o)try{for(const s of o)n.push(s)}catch{}else for(const s in o)s!=="defaultValue"&&n.push(o[s])}return i}function hDe(t){const e=Object.prototype.toString.call(t),n=typeof t;return!(n==="number"||n==="boolean"||n==="string"||n==="symbol"||n==="function"||e==="[object Date]"||e==="[object RegExp]"||e==="[object Module]"||t===void 0||t===null||t._watchdogExcluded||t instanceof EventTarget||t instanceof Event)}function nY(t,e,n=new Set){if(t===e&&mDe(t))return!0;const i=xA(t,n),r=xA(e,n);for(const o of i)if(r.has(o))return!0;return!1}function mDe(t){return typeof t=="object"&&t!==null}class iY extends tY{_editor=null;_lifecyclePromise=null;_throttledSave;_data;_lastDocumentVersion;_elementOrData;_initUsingData=!0;_editables={};_config;_excludedProps;constructor(e,n={}){super(n),this._throttledSave=Km(this._save.bind(this),typeof n.saveInterval=="number"?n.saveInterval:5e3),e&&(this._creator=(i,r)=>e.create(i,r)),this._destructor=i=>i.destroy()}get editor(){return this._editor}get _item(){return this._editor}setCreator(e){this._creator=e}setDestructor(e){this._destructor=e}_restart(){return Promise.resolve().then(()=>(this.state="initializing",this._fire("stateChange"),this._destroy())).catch(e=>{console.error("An error happened during the editor destroying.",e)}).then(()=>{const e={},n=[],i=this._config.rootsAttributes||{},r={};for(const[s,a]of Object.entries(this._data.roots))a.isLoaded?(e[s]="",r[s]=i[s]||{}):n.push(s);const o={...this._config,extraPlugins:this._config.extraPlugins||[],lazyRoots:n,rootsAttributes:r,_watchdogInitialData:this._data};return delete o.initialData,o.extraPlugins.push(gDe),this._initUsingData?this.create(e,o,o.context):Rc(this._elementOrData)?this.create(this._elementOrData,o,o.context):this.create(this._editables,o,o.context)}).then(()=>{this._fire("restart")})}create(e=this._elementOrData,n=this._config,i){return this._lifecyclePromise=Promise.resolve(this._lifecyclePromise).then(()=>(super._startErrorHandling(),this._elementOrData=e,this._initUsingData=typeof e=="string"||Object.keys(e).length>0&&typeof Object.values(e)[0]=="string",this._config=this._cloneEditorConfiguration(n)||{},this._config.context=i,this._creator(e,this._config))).then(r=>{this._editor=r,r.model.document.on("change:data",this._throttledSave),this._lastDocumentVersion=r.model.document.version,this._data=this._getData(),this._initUsingData||(this._editables=this._getEditables()),this.state="ready",this._fire("stateChange")}).finally(()=>{this._lifecyclePromise=null}),this._lifecyclePromise}destroy(){return this._lifecyclePromise=Promise.resolve(this._lifecyclePromise).then(()=>(this.state="destroyed",this._fire("stateChange"),super.destroy(),this._destroy())).finally(()=>{this._lifecyclePromise=null}),this._lifecyclePromise}_destroy(){return Promise.resolve().then(()=>{this._stopErrorHandling(),this._throttledSave.cancel();const e=this._editor;return this._editor=null,e.model.document.off("change:data",this._throttledSave),this._destructor(e)})}_save(){const e=this._editor.model.document.version;try{this._data=this._getData(),this._initUsingData||(this._editables=this._getEditables()),this._lastDocumentVersion=e}catch(n){console.error(n,"An error happened during restoring editor data. Editor will be restored from the previously saved data.")}}_setExcludedProperties(e){this._excludedProps=e}_getData(){const e=this._editor,n=e.model.document.roots.filter(a=>a.isAttached()&&a.rootName!="$graveyard"),{plugins:i}=e,r=i.has("CommentsRepository")&&i.get("CommentsRepository"),o=i.has("TrackChanges")&&i.get("TrackChanges"),s={roots:{},markers:{},commentThreads:JSON.stringify([]),suggestions:JSON.stringify([])};n.forEach(a=>{s.roots[a.rootName]={content:JSON.stringify(Array.from(a.getChildren())),attributes:JSON.stringify(Array.from(a.getAttributes())),isLoaded:a._isLoaded}});for(const a of e.model.markers)a._affectsData&&(s.markers[a.name]={rangeJSON:a.getRange().toJSON(),usingOperation:a._managedUsingOperations,affectsData:a._affectsData});return r&&(s.commentThreads=JSON.stringify(r.getCommentThreads({toJSON:!0,skipNotAttached:!0}))),o&&(s.suggestions=JSON.stringify(o.getSuggestions({toJSON:!0,skipNotAttached:!0}))),s}_getEditables(){const e={};for(const n of this.editor.model.document.getRootNames()){const i=this.editor.ui.getEditableElement(n);i&&(e[n]=i)}return e}_isErrorComingFromThisItem(e){return nY(this._editor,e.context,this._excludedProps)}_cloneEditorConfiguration(e){return dS(e,(n,i)=>{if(Rc(n)||i==="context")return n})}}class gDe{editor;_data;constructor(e){this.editor=e,this._data=e.config.get("_watchdogInitialData")}init(){this.editor.data.on("init",e=>{e.stop(),this.editor.model.enqueueChange({isUndoable:!1},n=>{this._restoreCollaborationData(),this._restoreEditorData(n)}),this.editor.data.fire("ready")},{priority:999})}_createNode(e,n){if("name"in n){const i=e.createElement(n.name,n.attributes);if(n.children)for(const r of n.children)i._appendChild(this._createNode(e,r));return i}else return e.createText(n.data,n.attributes)}_restoreEditorData(e){const n=this.editor;Object.entries(this._data.roots).forEach(([i,{content:r,attributes:o}])=>{const s=JSON.parse(r),a=JSON.parse(o),l=n.model.document.getRoot(i);for(const[u,c]of a)e.setAttribute(u,c,l);for(const u of s){const c=this._createNode(e,u);e.insert(c,l,"end")}}),Object.entries(this._data.markers).forEach(([i,r])=>{const{document:o}=n.model,{rangeJSON:{start:s,end:a},...l}=r,u=o.getRoot(s.root),c=e.createPositionFromPath(u,s.path,s.stickiness),d=e.createPositionFromPath(u,a.path,a.stickiness),f=e.createRange(c,d);e.addMarker(i,{range:f,...l})})}_restoreCollaborationData(){const e=JSON.parse(this._data.commentThreads),n=JSON.parse(this._data.suggestions);if(this.editor.plugins.has("CommentsRepository")){const i=this.editor.plugins.get("CommentsRepository");for(const r of i.getCommentThreads())i._removeCommentThread({threadId:r.id});e.forEach(r=>{const o=this.editor.config.get("collaboration.channelId");this.editor.plugins.get("CommentsRepository").addCommentThread({channelId:o,...r})})}if(this.editor.plugins.has("TrackChangesEditing")){const i=this.editor.plugins.get("TrackChangesEditing");for(const r of i.getSuggestions())i._removeSuggestion(r);n.forEach(r=>{i.addSuggestionData(r)})}}}const sv=Symbol("MainQueueId");class pDe extends tY{_watchdogs=new Map;_watchdogConfig;_context=null;_contextProps=new Set;_actionQueues=new vDe;_contextConfig;_item;constructor(e,n={}){super(n),this._watchdogConfig=n,this._creator=i=>e.create(i),this._destructor=i=>i.destroy(),this._actionQueues.onEmpty(()=>{this.state==="initializing"&&(this.state="ready",this._fire("stateChange"))})}setCreator(e){this._creator=e}setDestructor(e){this._destructor=e}get context(){return this._context}create(e={}){return this._actionQueues.enqueue(sv,()=>(this._contextConfig=e,this._create()))}getItem(e){return this._getWatchdog(e)._item}getItemState(e){return this._getWatchdog(e).state}add(e){const n=tV(e);return Promise.all(n.map(i=>this._actionQueues.enqueue(i.id,()=>{if(this.state==="destroyed")throw new Error("Cannot add items to destroyed watchdog.");if(!this._context)throw new Error("Context was not created yet. You should call the `ContextWatchdog#create()` method first.");let r;if(this._watchdogs.has(i.id))throw new Error(`Item with the given id is already added: '${i.id}'.`);if(i.type==="editor")return r=new iY(null,this._watchdogConfig),r.setCreator(i.creator),r._setExcludedProperties(this._contextProps),i.destructor&&r.setDestructor(i.destructor),this._watchdogs.set(i.id,r),r.on("error",(o,{error:s,causesRestart:a})=>{this._fire("itemError",{itemId:i.id,error:s}),a&&this._actionQueues.enqueue(i.id,()=>new Promise(l=>{const u=()=>{r.off("restart",u),this._fire("itemRestart",{itemId:i.id}),l()};r.on("restart",u)}))}),r.create(i.sourceElementOrData,i.config,this._context);throw new Error(`Not supported item type: '${i.type}'.`)})))}remove(e){const n=tV(e);return Promise.all(n.map(i=>this._actionQueues.enqueue(i,()=>{const r=this._getWatchdog(i);return this._watchdogs.delete(i),r.destroy()})))}destroy(){return this._actionQueues.enqueue(sv,()=>(this.state="destroyed",this._fire("stateChange"),super.destroy(),this._destroy()))}_restart(){return this._actionQueues.enqueue(sv,()=>(this.state="initializing",this._fire("stateChange"),this._destroy().catch(e=>{console.error("An error happened during destroying the context or items.",e)}).then(()=>this._create()).then(()=>this._fire("restart"))))}_create(){return Promise.resolve().then(()=>(this._startErrorHandling(),this._creator(this._contextConfig))).then(e=>(this._context=e,this._contextProps=xA(this._context),Promise.all(Array.from(this._watchdogs.values()).map(n=>(n._setExcludedProperties(this._contextProps),n.create(void 0,void 0,this._context))))))}_destroy(){return Promise.resolve().then(()=>{this._stopErrorHandling();const e=this._context;return this._context=null,this._contextProps=new Set,Promise.all(Array.from(this._watchdogs.values()).map(n=>n.destroy())).then(()=>this._destructor(e))})}_getWatchdog(e){const n=this._watchdogs.get(e);if(!n)throw new Error(`Item with the given id was not registered: ${e}.`);return n}_isErrorComingFromThisItem(e){for(const n of this._watchdogs.values())if(n._isErrorComingFromThisItem(e))return!1;return nY(this._context,e.context)}}class vDe{_onEmptyCallbacks=[];_queues=new Map;_activeActions=0;onEmpty(e){this._onEmptyCallbacks.push(e)}enqueue(e,n){const i=e===sv;this._activeActions++,this._queues.get(e)||this._queues.set(e,Promise.resolve());const o=(i?Promise.all(this._queues.values()):Promise.all([this._queues.get(sv),this._queues.get(e)])).then(n),s=o.catch(()=>{});return this._queues.set(e,s),o.finally(()=>{this._activeActions--,this._queues.get(e)===s&&this._activeActions===0&&this._onEmptyCallbacks.forEach(a=>a())})}}function tV(t){return Array.isArray(t)?t:[t]}class xe extends Ln(){editor;_disableStack=new Set;constructor(e){super(),this.editor=e,this.set("isEnabled",!0)}forceDisabled(e){this._disableStack.add(e),this._disableStack.size==1&&(this.on("set:isEnabled",nV,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(e){this._disableStack.delete(e),this._disableStack.size==0&&(this.off("set:isEnabled",nV),this.isEnabled=!0)}destroy(){this.stopListening()}static get isContextPlugin(){return!1}static get isOfficialPlugin(){return!1}static get isPremiumPlugin(){return!1}}function nV(t){t.return=!1,t.stop()}class Ht extends Ln(){editor;_isEnabledBasedOnSelection;_affectsData;_disableStack;static get _throwErrorWhenUsedAsAPlugin(){return!0}constructor(e){super(),this.editor=e,this.set("value",void 0),this.set("isEnabled",!1),this._affectsData=!0,this._isEnabledBasedOnSelection=!0,this._disableStack=new Set,this.decorate("execute"),this.listenTo(this.editor.model.document,"change",()=>{this.refresh()}),this.listenTo(e,"change:isReadOnly",()=>{this.refresh()}),this.on("set:isEnabled",n=>{if(!this.affectsData)return;const i=e.model.document.selection,o=!(i.getFirstPosition().root.rootName=="$graveyard")&&e.model.canEditAt(i);(e.isReadOnly||this._isEnabledBasedOnSelection&&!o)&&(n.return=!1,n.stop())},{priority:"highest"}),this.on("execute",n=>{this.isEnabled||n.stop()},{priority:"high"})}get affectsData(){return this._affectsData}set affectsData(e){this._affectsData=e}refresh(){this.isEnabled=!0}forceDisabled(e){this._disableStack.add(e),this._disableStack.size==1&&(this.on("set:isEnabled",iV,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(e){this._disableStack.delete(e),this._disableStack.size==0&&(this.off("set:isEnabled",iV),this.refresh())}execute(...e){}destroy(){this.stopListening()}}function iV(t){t.return=!1,t.stop()}class rV extends Ht{_childCommandsDefinitions=[];refresh(){}execute(...e){const n=this._getFirstEnabledCommand();return!!n&&n.execute(e)}registerChildCommand(e,n={}){$K(this._childCommandsDefinitions,{command:e,priority:n.priority||"normal"}),e.on("change:isEnabled",()=>this._checkEnabled()),this._checkEnabled()}_checkEnabled(){this.isEnabled=!!this._getFirstEnabledCommand()}_getFirstEnabledCommand(){const e=this._childCommandsDefinitions.find(({command:n})=>n.isEnabled);return e&&e.command}}class bDe{_commands;constructor(){this._commands=new Map}add(e,n){this._commands.set(e,n)}get(e){return this._commands.get(e)}execute(e,...n){const i=this.get(e);if(!i)throw new oe("commandcollection-command-not-found",this,{commandName:e});return i.execute(...n)}*names(){yield*this._commands.keys()}*commands(){yield*this._commands.values()}[Symbol.iterator](){return this._commands[Symbol.iterator]()}destroy(){for(const e of this.commands())e.destroy()}}class rY extends Fn(){_context;_plugins=new Map;_availablePlugins;_contextPlugins;constructor(e,n=[],i=[]){super(),this._context=e,this._availablePlugins=new Map;for(const r of n)r.pluginName&&this._availablePlugins.set(r.pluginName,r);this._contextPlugins=new Map;for(const[r,o]of i)this._contextPlugins.set(r,o),this._contextPlugins.set(o,r),r.pluginName&&this._availablePlugins.set(r.pluginName,r)}*[Symbol.iterator](){for(const e of this._plugins)typeof e[0]=="function"&&(yield e)}get(e){const n=this._plugins.get(e);if(!n){let i=e;throw typeof e=="function"&&(i=e.pluginName||e.name),new oe("plugincollection-plugin-not-loaded",this._context,{plugin:i})}return n}has(e){return this._plugins.has(e)}async init(e,n=[],i=[]){const r=this,o=this._context;h(e),g(e);const s=e.filter(k=>!d(k,n)),a=[...m(s)];S(a,i);const l=_(a);return await C(l,"init"),await C(l,"afterInit"),l;function u(k){return typeof k=="function"}function c(k){return u(k)&&!!k.isContextPlugin}function d(k,T){return T.some(E=>E===k||f(k)===E||f(E)===k)}function f(k){return u(k)?k.pluginName||k.name:k}function h(k,T=new Set){k.forEach(E=>{u(E)&&(T.has(E)||(T.add(E),E.pluginName&&!r._availablePlugins.has(E.pluginName)&&r._availablePlugins.set(E.pluginName,E),E.requires&&h(E.requires,T)))})}function m(k,T=new Set){return k.map(E=>u(E)?E:r._availablePlugins.get(E)).reduce((E,x)=>T.has(x)?E:(T.add(x),x.requires&&(g(x.requires,x),m(x.requires,T).forEach(P=>E.add(P))),E.add(x)),new Set)}function g(k,T=null){k.map(E=>u(E)?E:r._availablePlugins.get(E)||E).forEach(E=>{v(E),p(E,T),b(E,T),y(E,T)})}function v(k){if(typeof k=="function"&&k._throwErrorWhenUsedAsAPlugin)throw new oe("plugincollection-plugin-invalid-constructor",o,{name:k.name})}function p(k,T){if(!u(k))throw T?new oe("plugincollection-soft-required",o,{missingPlugin:k,requiredBy:f(T)}):new oe("plugincollection-plugin-not-found",o,{plugin:k})}function b(k,T){if(c(T)&&!c(k))throw new oe("plugincollection-context-required",o,{plugin:f(k),requiredBy:f(T)})}function y(k,T){if(T&&d(k,n))throw new oe("plugincollection-required",o,{plugin:f(k),requiredBy:f(T)})}function _(k){return k.map(T=>{let E=r._contextPlugins.get(T);return E=E||new T(o),r._add(T,E),E})}function C(k,T){return k.reduce((E,x)=>!x[T]||r._contextPlugins.has(x)?E:E.then(x[T].bind(x)),Promise.resolve())}function S(k,T){for(const E of T){if(typeof E!="function")throw new oe("plugincollection-replace-plugin-invalid-type",null,{pluginItem:E});const x=E.pluginName;if(!x)throw new oe("plugincollection-replace-plugin-missing-name",null,{pluginItem:E});if(E.requires&&E.requires.length)throw new oe("plugincollection-plugin-for-replacing-cannot-have-dependencies",null,{pluginName:x});const P=r._availablePlugins.get(x);if(!P)throw new oe("plugincollection-plugin-for-replacing-not-exist",null,{pluginName:x});const A=k.indexOf(P);if(A===-1){if(r._contextPlugins.has(P))return;throw new oe("plugincollection-plugin-for-replacing-not-loaded",null,{pluginName:x})}if(P.requires&&P.requires.length)throw new oe("plugincollection-replaced-plugin-cannot-have-dependencies",null,{pluginName:x});k.splice(A,1,E),r._availablePlugins.set(x,E)}}}destroy(){const e=[];for(const[,n]of this)typeof n.destroy=="function"&&!this._contextPlugins.has(n)&&e.push(n.destroy());return Promise.all(e)}_add(e,n){this._plugins.set(e,n);const i=e.pluginName;if(i){if(this._plugins.has(i))throw new oe("plugincollection-plugin-name-conflict",null,{pluginName:i,plugin1:this._plugins.get(i).constructor,plugin2:e});this._plugins.set(i,n)}}}class oV{config;plugins;locale;t;editors;static defaultConfig;static builtinPlugins;_contextOwner=null;constructor(e){const{translations:n,...i}=e||{};this.config=new KK(i,this.constructor.defaultConfig);const r=this.constructor.builtinPlugins;this.config.define("plugins",r),this.plugins=new rY(this,r);const o=this.config.get("language")||{};this.locale=new zRe({uiLanguage:typeof o=="string"?o:o.ui,contentLanguage:this.config.get("language.content"),translations:n}),this.t=this.locale.t,this.editors=new Er}initPlugins(){const e=this.config.get("plugins")||[],n=this.config.get("substitutePlugins")||[];for(const i of e.concat(n)){if(typeof i!="function")throw new oe("context-initplugins-constructor-only",null,{Plugin:i});if(i.isContextPlugin!==!0)throw new oe("context-initplugins-invalid-plugin",null,{Plugin:i})}return this.plugins.init(e,[],n)}destroy(){return Promise.all(Array.from(this.editors,e=>e.destroy())).then(()=>this.plugins.destroy())}_addEditor(e,n){if(this._contextOwner)throw new oe("context-addeditor-private-context");this.editors.add(e),n&&(this._contextOwner=e)}_removeEditor(e){return this.editors.has(e)&&this.editors.remove(e),this._contextOwner===e?this.destroy():Promise.resolve()}_getEditorConfig(){const e={};for(const n of this.config.names())["plugins","removePlugins","extraPlugins"].includes(n)||(e[n]=this.config.get(n));return e}static create(e){return new Promise(n=>{const i=new this(e);n(i.initPlugins().then(()=>i))})}static get _throwErrorWhenUsedAsAPlugin(){return!0}}class bS extends Ln(){context;constructor(e){super(),this.context=e}destroy(){this.stopListening()}static get isContextPlugin(){return!0}static get isOfficialPlugin(){return!1}static get isPremiumPlugin(){return!1}}class yDe extends Qi{editor;constructor(e){super(),this.editor=e}set(e,n,i={}){if(typeof n=="string"){const r=n;n=(o,s)=>{this.editor.execute(r),s()}}super.set(e,n,i)}}const FT="contentEditing",sV="common";class wDe{keystrokeInfos=new Map;_editor;constructor(e){this._editor=e;const n=e.config.get("menuBar.isVisible"),i=e.locale.t;this.addKeystrokeInfoCategory({id:FT,label:i("Content editing keystrokes"),description:i("These keyboard shortcuts allow for quick access to content editing features.")});const r=[{label:i("Close contextual balloons, dropdowns, and dialogs"),keystroke:"Esc"},{label:i("Open the accessibility help dialog"),keystroke:"Alt+0"},{label:i("Move focus between form fields (inputs, buttons, etc.)"),keystroke:[["Tab"],["Shift+Tab"]]},{label:i("Move focus to the toolbar, navigate between toolbars"),keystroke:"Alt+F10",mayRequireFn:!0},{label:i("Navigate through the toolbar or menu bar"),keystroke:[["arrowup"],["arrowright"],["arrowdown"],["arrowleft"]]},{label:i("Execute the currently focused button. Executing buttons that interact with the editor content moves the focus back to the content."),keystroke:[["Enter"],["Space"]]}];n&&r.push({label:i("Move focus to the menu bar, navigate between menu bars"),keystroke:"Alt+F9",mayRequireFn:!0}),this.addKeystrokeInfoCategory({id:"navigation",label:i("User interface and content navigation keystrokes"),description:i("Use the following keystrokes for more efficient navigation in the CKEditor 5 user interface."),groups:[{id:"common",keystrokes:r}]})}addKeystrokeInfoCategory({id:e,label:n,description:i,groups:r}){this.keystrokeInfos.set(e,{id:e,label:n,description:i,groups:new Map}),this.addKeystrokeInfoGroup({categoryId:e,id:sV}),r&&r.forEach(o=>{this.addKeystrokeInfoGroup({categoryId:e,...o})})}addKeystrokeInfoGroup({categoryId:e=FT,id:n,label:i,keystrokes:r}){const o=this.keystrokeInfos.get(e);if(!o)throw new oe("accessibility-unknown-keystroke-info-category",this._editor,{groupId:n,categoryId:e});o.groups.set(n,{id:n,label:i,keystrokes:r||[]})}addKeystrokeInfos({categoryId:e=FT,groupId:n=sV,keystrokes:i}){if(!this.keystrokeInfos.has(e))throw new oe("accessibility-unknown-keystroke-info-category",this._editor,{categoryId:e,keystrokes:i});const r=this.keystrokeInfos.get(e);if(!r.groups.has(n))throw new oe("accessibility-unknown-keystroke-info-group",this._editor,{groupId:n,categoryId:e,keystrokes:i});r.groups.get(n).keystrokes.push(...i)}}function _De(t){return{sessionId:EDe(),pageSessionId:xDe(),hostname:window.location.hostname,version:globalThis.CKEDITOR_VERSION,type:CDe(t),plugins:SDe(t.plugins),distribution:kDe(),env:TDe(),integration:Object.create(null),menuBar:{isVisible:!!t.config.get("menuBar.isVisible")},language:{ui:t.locale.uiLanguage,content:t.locale.contentLanguage},toolbar:{main:$T(t.config.get("toolbar")),block:$T(t.config.get("blockToolbar")),balloon:$T(t.config.get("balloonToolbar"))}}}function CDe(t){return Object.getPrototypeOf(t).constructor.editorName}function SDe(t){return Array.from(t).filter(([e])=>!!e.pluginName).map(([e])=>{const{pluginName:n,isContextPlugin:i,isOfficialPlugin:r,isPremiumPlugin:o}=e;return{isContext:!!i,isOfficial:!!r,isPremium:!!o,name:n}})}function $T(t){if(!t)return;const e=Array.isArray(t)?{items:t}:t,n=o(e.items||[]);return{isMultiline:n.includes("-"),shouldNotGroupWhenFull:!!e.shouldNotGroupWhenFull,items:r(n)};function r(s){return s.filter(a=>a!=="|"&&a!=="-")}function o(s){return s.flatMap(a=>typeof a=="string"?[a]:o(a.items))}}function kDe(){return{channel:window[Symbol.for("cke distribution")]||"sh"}}function TDe(){let t="unknown",e="unknown";return vt.isMac?t="mac":vt.isWindows?t="windows":vt.isiOS?t="ios":vt.isAndroid&&(t="android"),vt.isGecko?e="gecko":vt.isBlink?e="blink":vt.isSafari&&(e="safari"),{os:t,browser:e}}function EDe(){return localStorage.getItem("__ckeditor-session-id")||localStorage.setItem("__ckeditor-session-id",Ur()),localStorage.getItem("__ckeditor-session-id")}function xDe(){return Qe.window.CKEDITOR_PAGE_SESSION_ID=Qe.window.CKEDITOR_PAGE_SESSION_ID||Ur(),Qe.window.CKEDITOR_PAGE_SESSION_ID}class ADe extends Ln(){static get editorName(){return"Editor"}accessibility;commands;config;conversion;data;editing;locale;model;plugins;keystrokes;t;static defaultConfig;static builtinPlugins;_context;_readOnlyLocks;static get _throwErrorWhenUsedAsAPlugin(){return!0}constructor(e={}){if(super(),typeof e!="object"||Array.isArray(e))throw new oe("editor-config-invalid-type");if("sanitizeHtml"in e)throw new oe("editor-config-sanitizehtml-not-supported");const n=this.constructor,{translations:i,...r}=n.defaultConfig||{},{translations:o=i,...s}=e,a=e.language||r.language;this._context=e.context||new oV({language:a,translations:o}),this._context._addEditor(this,!e.context);const l=Array.from(n.builtinPlugins||[]);this.config=new KK(s,r),this.config.define("plugins",l),this.config.define(this._context._getEditorConfig()),c(this.config),this.plugins=new rY(this,l,this._context.plugins),this.locale=this._context.locale,this.t=this.locale.t,this._readOnlyLocks=new Set,this.commands=new bDe,this.set("state","initializing"),this.once("ready",()=>this.state="ready",{priority:"high"}),this.once("destroy",()=>this.state="destroyed",{priority:"high"}),this.model=new D5e(this.config),this.on("change:isReadOnly",()=>{this.model.document.isReadOnly=this.isReadOnly});const u=new mMe;this.data=new FLe(this.model,u),this.editing=new pLe(this.model,u),this.editing.view.document.bind("isReadOnly").to(this),this.conversion=new zLe([this.editing.downcastDispatcher,this.data.downcastDispatcher],this.data.upcastDispatcher),this.conversion.addAlias("dataDowncast",this.data.downcastDispatcher),this.conversion.addAlias("editingDowncast",this.editing.downcastDispatcher),this.keystrokes=new yDe(this),this.keystrokes.listenTo(this.editing.view.document),this.accessibility=new wDe(this),d(this);function c(f){let h=f.get("licenseKey");if(!h&&window.CKEDITOR_GLOBAL_LICENSE_KEY&&(h=window.CKEDITOR_GLOBAL_LICENSE_KEY,f.set("licenseKey",h)),!h)throw new oe("license-key-missing")}function d(f){const h=f.config.get("licenseKey"),m=window[Symbol.for("cke distribution")]||"sh";function g(k,T){f.enableReadOnlyMode(Symbol("invalidLicense")),f._showLicenseError(k,T)}function v(k){return["exp","jti","vc"].every(E=>E in k)}function p(k){return Object.getOwnPropertyNames(k).sort().filter(x=>x!="vc"&&k[x]!=null).map(x=>k[x])}function b(k){const{hostname:T}=new URL(window.location.href);if(k.includes(T))return!0;const E=T.split(".");return k.filter(x=>x.includes("*")).map(x=>x.split(".")).filter(x=>x.length<=E.length).map(x=>Array(E.length-x.length).fill(x[0]==="*"?"*":"").concat(x)).some(x=>E.every((P,A)=>x[A]===P||x[A]==="*"))}function y(k){const T=k[0].toUpperCase()+k.slice(1),E=k==="evaluation"?"an":"a";console.info(`%cCKEditor 5 ${T} License`,"color: #ffffff; background: #743CCD; font-size: 14px; padding: 4px 8px; border-radius: 4px;"),console.warn(`⚠️ You are using ${E} ${k} license of CKEditor 5${k==="trial"?" which is for evaluation purposes only":""}. For production usage, please obtain a production license at https://portal.ckeditor.com/`)}if(h=="GPL"){m=="cloud"&&g("distributionChannel");return}const _=g4(h);if(!_){g("invalid");return}if(!v(_)){g("invalid");return}if(_.distributionChannel&&!li(_.distributionChannel).includes(m)){g("distributionChannel");return}if(jRe(p(_))!=_.vc.toLowerCase()){g("invalid");return}if(new Date(_.exp*1e3)0&&!b(S)){g("domainLimit");return}if(["evaluation","trial"].includes(_.licenseType)&&_.exp*1e3{g(`${k}Limit`)},6e5);f.on("destroy",()=>{clearTimeout(T)})}_.usageEndpoint&&f.once("ready",()=>{const k={requestId:Ur(),requestTime:Math.round(Date.now()/1e3),license:h,editor:PDe(f)};f._sendUsageRequest(_.usageEndpoint,k).then(T=>{const{status:E,message:x}=T;x&&console.warn(x),E!="ok"&&g("usageLimit")},()=>{YIe("license-key-validation-endpoint-not-reachable",{url:_.usageEndpoint})})},{priority:"high"})}}get isReadOnly(){return this._readOnlyLocks.size>0}set isReadOnly(e){throw new oe("editor-isreadonly-has-no-setter")}enableReadOnlyMode(e){if(typeof e!="string"&&typeof e!="symbol")throw new oe("editor-read-only-lock-id-invalid",null,{lockId:e});this._readOnlyLocks.has(e)||(this._readOnlyLocks.add(e),this._readOnlyLocks.size===1&&this.fire("change:isReadOnly","isReadOnly",!0,!1))}disableReadOnlyMode(e){if(typeof e!="string"&&typeof e!="symbol")throw new oe("editor-read-only-lock-id-invalid",null,{lockId:e});this._readOnlyLocks.has(e)&&(this._readOnlyLocks.delete(e),this._readOnlyLocks.size===0&&this.fire("change:isReadOnly","isReadOnly",!1,!0))}setData(e){this.data.set(e)}getData(e){return this.data.get(e)}initPlugins(){const e=this.config,n=e.get("plugins"),i=e.get("removePlugins")||[],r=e.get("extraPlugins")||[],o=e.get("substitutePlugins")||[];return this.plugins.init(n.concat(r),i,o).then(a=>(s(this),a));function s(a){const l=a.config.get("licenseKey");if(l==="GPL")return;const u=g4(l);if(!u)return;const c=[...a.plugins].map(([d])=>d).find(d=>!d.pluginName||!d.licenseFeatureCode?!1:iMe(u,d.licenseFeatureCode));c&&(a.enableReadOnlyMode(Symbol("invalidLicense")),a._showLicenseError("pluginNotAllowed",c.pluginName))}}destroy(){let e=Promise.resolve();return this.state=="initializing"&&(e=new Promise(n=>this.once("ready",n))),e.then(()=>{this.fire("destroy"),this.stopListening(),this.commands.destroy()}).then(()=>this.plugins.destroy()).then(()=>{this.model.destroy(),this.data.destroy(),this.editing.destroy(),this.keystrokes.destroy()}).then(()=>this._context._removeEditor(this))}execute(e,...n){try{return this.commands.execute(e,...n)}catch(i){oe.rethrowUnexpectedError(i,this)}}focus(){this.editing.view.focus()}static create(...e){throw new Error("This is an abstract method.")}static Context=oV;static EditorWatchdog=iY;static ContextWatchdog=pDe;_showLicenseError(e,n){setTimeout(()=>{if(e=="invalid")throw new oe("invalid-license-key");if(e=="expired")throw new oe("license-key-expired");if(e=="domainLimit")throw new oe("license-key-domain-limit");if(e=="pluginNotAllowed"){const i=n.replace(/(Editing|UI)$/,""),r=this.plugins.has(i);throw new oe("license-key-plugin-not-allowed",null,{pluginName:r?i:n})}if(e=="featureNotAllowed")throw new oe("license-key-feature-not-allowed",null,{featureName:n});if(e=="evaluationLimit")throw new oe("license-key-evaluation-limit");if(e=="trialLimit")throw new oe("license-key-trial-limit");if(e=="developmentLimit")throw new oe("license-key-development-limit");if(e=="usageLimit")throw new oe("license-key-usage-limit");if(e=="distributionChannel")throw new oe("license-key-invalid-distribution-channel")},0),this._showLicenseError=()=>{}}async _sendUsageRequest(e,n){const i=new Headers({"Content-Type":"application/json"}),r=await fetch(new URL(e),{method:"POST",headers:i,body:JSON.stringify(n)});if(!r.ok)throw new Error(`HTTP Response: ${r.status}`);return r.json()}}function PDe(t){const e=_De(t);function n(i,r){if(Ic(e,i)!==void 0)throw new oe("editor-usage-data-path-already-set",{path:i});LK(e,i,r)}return t.fire("collectUsageData",{setUsageData:n}),e}function IDe(t){if(!s1(t.updateSourceElement))throw new oe("attachtoform-missing-elementapi-interface",t);const e=t.sourceElement;if(RDe(e)&&e.form){let n;const i=e.form,r=()=>t.updateSourceElement();s1(i.submit)&&(n=i.submit,i.submit=()=>{r(),n.apply(i)}),i.addEventListener("submit",r),t.on("destroy",()=>{i.removeEventListener("submit",r),n&&(i.submit=n)})}}function RDe(t){return!!t&&t.tagName.toLowerCase()==="textarea"}function MDe(t){class e extends t{sourceElement;updateSourceElement(i){if(!this.sourceElement)throw new oe("editor-missing-sourceelement",this);const r=this.config.get("updateSourceElementOnDestroy"),o=this.sourceElement instanceof HTMLTextAreaElement;if(!r&&!o){o4(this.sourceElement,"");return}const s=typeof i=="string"?i:this.data.get();o4(this.sourceElement,s)}}return e}class m1 extends bS{_actions;static get pluginName(){return"PendingActions"}static get isOfficialPlugin(){return!0}init(){this.set("hasAny",!1),this._actions=new Er({idProperty:"_id"}),this._actions.delegate("add","remove").to(this)}add(e){if(typeof e!="string")throw new oe("pendingactions-add-invalid-message",this);const n=new(Ln());return n.set("message",e),this._actions.add(n),this.hasAny=!0,n}remove(e){this._actions.remove(e),this.hasAny=!!this._actions.length}get first(){return this._actions.get(0)}[Symbol.iterator](){return this._actions[Symbol.iterator]()}}class ODe extends Ln(){total;_reader;_data;constructor(){super();const e=new window.FileReader;this._reader=e,this._data=void 0,this.set("loaded",0),e.onprogress=n=>{this.loaded=n.loaded}}get error(){return this._reader.error}get data(){return this._data}read(e){const n=this._reader;return this.total=e.size,new Promise((i,r)=>{n.onload=()=>{const o=n.result;this._data=o,i(o)},n.onerror=()=>{r("error")},n.onabort=()=>{r("aborted")},this._reader.readAsDataURL(e)})}abort(){this._reader.abort()}}class eu extends xe{loaders=new Er;_loadersMap=new Map;_pendingAction=null;static get pluginName(){return"FileRepository"}static get isOfficialPlugin(){return!0}static get requires(){return[m1]}init(){this.loaders.on("change",()=>this._updatePendingAction()),this.set("uploaded",0),this.set("uploadTotal",null),this.bind("uploadedPercent").to(this,"uploaded",this,"uploadTotal",(e,n)=>n?e/n*100:0)}getLoader(e){return this._loadersMap.get(e)||null}createLoader(e){if(!this.createUploadAdapter)return hn("filerepository-no-upload-adapter"),null;const n=new aV(Promise.resolve(e),this.createUploadAdapter);return this.loaders.add(n),this._loadersMap.set(e,n),e instanceof Promise&&n.file.then(i=>{this._loadersMap.set(i,n)}).catch(()=>{}),n.on("change:uploaded",()=>{let i=0;for(const r of this.loaders)i+=r.uploaded;this.uploaded=i}),n.on("change:uploadTotal",()=>{let i=0;for(const r of this.loaders)r.uploadTotal&&(i+=r.uploadTotal);this.uploadTotal=i}),n}destroyLoader(e){const n=e instanceof aV?e:this.getLoader(e);n._destroy(),this.loaders.remove(n),this._loadersMap.forEach((i,r)=>{i===n&&this._loadersMap.delete(r)})}_updatePendingAction(){const e=this.editor.plugins.get(m1);if(this.loaders.length){if(!this._pendingAction){const n=this.editor.t,i=r=>`${n("Upload in progress")} ${parseInt(r)}%.`;this._pendingAction=e.add(i(this.uploadedPercent)),this._pendingAction.bind("message").to(this,"uploadedPercent",i)}}else e.remove(this._pendingAction),this._pendingAction=null}}class aV extends Ln(){id;_filePromiseWrapper;_adapter;_reader;constructor(e,n){super(),this.id=Ur(),this._filePromiseWrapper=this._createFilePromiseWrapper(e),this._adapter=n(this),this._reader=new ODe,this.set("status","idle"),this.set("uploaded",0),this.set("uploadTotal",null),this.bind("uploadedPercent").to(this,"uploaded",this,"uploadTotal",(i,r)=>r?i/r*100:0),this.set("uploadResponse",null)}get file(){return this._filePromiseWrapper?this._filePromiseWrapper.promise.then(e=>this._filePromiseWrapper?e:null):Promise.resolve(null)}get data(){return this._reader.data}read(){if(this.status!="idle")throw new oe("filerepository-read-wrong-status",this);return this.status="reading",this.file.then(e=>this._reader.read(e)).then(e=>{if(this.status!=="reading")throw this.status;return this.status="idle",e}).catch(e=>{throw e==="aborted"?(this.status="aborted","aborted"):(this.status="error",this._reader.error?this._reader.error:e)})}upload(){if(this.status!="idle")throw new oe("filerepository-upload-wrong-status",this);return this.status="uploading",this.file.then(()=>this._adapter.upload()).then(e=>(this.uploadResponse=e,this.status="idle",e)).catch(e=>{throw this.status==="aborted"?"aborted":(this.status="error",e)})}abort(){const e=this.status;this.status="aborted",this._filePromiseWrapper.isFulfilled?e=="reading"?this._reader.abort():e=="uploading"&&this._adapter.abort&&this._adapter.abort():(this._filePromiseWrapper.promise.catch(()=>{}),this._filePromiseWrapper.rejecter("aborted")),this._destroy()}_destroy(){this._filePromiseWrapper=void 0,this._reader=void 0,this._adapter=void 0,this.uploadResponse=void 0}_createFilePromiseWrapper(e){const n={};return n.promise=new Promise((i,r)=>{n.rejecter=r,n.isFulfilled=!1,e.then(o=>{n.isFulfilled=!0,i(o)}).catch(o=>{n.isFulfilled=!0,r(o)})}),n}}class LDe extends xe{static get requires(){return[eu]}static get pluginName(){return"Base64UploadAdapter"}static get licenseFeatureCode(){return"B64A"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}init(){this.editor.plugins.get(eu).createUploadAdapter=e=>new DDe(e)}}let DDe=class{loader;reader;constructor(e){this.loader=e}upload(){return new Promise((e,n)=>{const i=this.reader=new window.FileReader;i.addEventListener("load",()=>{e({default:i.result})}),i.addEventListener("error",r=>{n(r)}),i.addEventListener("abort",()=>{n()}),this.loader.file.then(r=>{i.readAsDataURL(r)})})}abort(){this.reader.abort()}};var lV='