e(...s),t)}return n.cancel=()=>{clearTimeout(i)},n}function bi(e){try{if(!e.startsWith("ey"))return null;const t=atob(e.replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(t)}catch{return null}}function wi(e){const t=[{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:"tfoot",isVoid:!1},{name:"tr",isVoid:!1},{name:"ul",isVoid:!1}],i=t.map(e=>e.name).join("|"),n=e.replace(new RegExp(`?(${i})( .*?)?>`,"g"),"\n$&\n").replace(/ ]*>/g,"$&\n").split("\n");let s=0,o=!1;return n.map(e=>(o=function(e,t){const i=//.test(e),n=/<\/pre>/.test(e);return(!i||!n)&&(i?"first":n?"last":("first"===t||"middle"===t)&&"middle")}(e,o),e.length||o?function(e,t){return t.some(t=>!t.isVoid&&!!new RegExp(`<${t.name}( .*?)?>`).test(e))}(e,t)?_i(e,s++):function(e,t){return t.some(t=>new RegExp(`${t.name}>`).test(e))}(e,t)?_i(e,--s):_i(e,"middle"===o||"last"===o?0:s):"")).join("").trimEnd()}function _i(e,t,i=" "){return`${i.repeat(Math.max(0,t))}${e}\n`}function vi(e,t){return!!(i=e.charAt(t-1))&&1==i.length&&/[\ud800-\udbff]/.test(i)&&function(e){return!!e&&1==e.length&&/[\udc00-\udfff]/.test(e)}(e.charAt(t));var i}function yi(e,t){return!!(i=e.charAt(t))&&1==i.length&&/[\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f]/.test(i);var i}const ki=Ai();function Ci(e,t){const i=String(e).matchAll(ki);return Array.from(i).some(e=>e.indexe.source).join("|")+")";return new RegExp(`${e}|${t}(?:${t})*`,"ug")}function Ti(e){if(!e)return null;const t=function(e){const t=e.split(".");return 3!=t.length?null:t[1]}(e);return t?bi(t):null}function Ei(e,t){return(e.removeFeatures||[]).includes(t)}function xi(e){if(!e)return null;const[,t,i]=e.trim().match(/([.,\d]+)(%|px)$/)||[],n=Number.parseFloat(t);return Number.isNaN(n)?null:{value:n,unit:i}}function Pi(e,t,i){return"px"===i?{value:t.value,unit:"px"}:{value:t.value/e*100,unit:"%"}}function Si(e,t,{signal:i,edges:n}={}){let s,o=null;const r=null!=n&&n.includes("leading"),a=null==n||n.includes("trailing"),l=()=>{null!==o&&(e.apply(s,o),s=void 0,o=null)};let c=null;const d=()=>{null!=c&&clearTimeout(c),c=setTimeout(()=>{c=null,a&&l(),u()},t)},u=()=>{null!==c&&(clearTimeout(c),c=null),s=void 0,o=null},h=function(...e){if(i?.aborted)return;s=this,o=e;const t=null==c;d(),r&&t&&l()};return h.schedule=d,h.cancel=u,h.flush=()=>{l()},i?.addEventListener("abort",u,{once:!0}),h}function Ii(e,t=0,i={}){"object"!=typeof i&&(i={});const{leading:n=!1,trailing:s=!0,maxWait:o}=i,r=Array(2);let a;n&&(r[0]="leading"),s&&(r[1]="trailing");let l=null;const c=Si(function(...t){a=e.apply(this,t),l=null},t,{edges:r}),d=function(...t){return null!=o&&(null===l&&(l=Date.now()),Date.now()-l>=o)?(a=e.apply(this,t),l=Date.now(),c.cancel(),c.schedule(),a):(c.apply(this,t),a)};return d.cancel=c.cancel,d.flush=()=>(c.flush(),a),d}function Vi(e,t=0,i={}){const{leading:n=!0,trailing:s=!0}=i;return Ii(e,t,{leading:n,maxWait:t,trailing:s})}function Oi(e){const t=e?.constructor;return e===("function"==typeof t?t.prototype:Object.prototype)}function Ri(e){return"symbol"==typeof e||e instanceof Symbol}function Bi(e){if(!e)return 0===e?e:0;if((e=function(e){return Ri(e)?NaN:Number(e)}(e))===1/0||e===-1/0){return(e<0?-1:1)*Number.MAX_VALUE}return e==e?e:0}function Mi(e,t){if((e=function(e){const t=Bi(e),i=t%1;return i?t-i:t}(e))<1||!Number.isSafeInteger(e))return[];const i=new Array(e);for(let n=0;n`${e}`),i=new Set(t);(function(e){return"undefined"!=typeof Buffer&&Buffer.isBuffer(e)})(e)&&(i.add("offset"),i.add("parent"));W(e)&&(i.add("buffer"),i.add("byteLength"),i.add("byteOffset"));const n=Ni(e).filter(e=>!i.has(e));if(Array.isArray(e))return[...t,...n];return[...t.filter(t=>Object.hasOwn(e,t)),...n]}(e):Oi(e)?function(e){const t=Ni(e);return t.filter(e=>"constructor"!==e)}(e):Ni(e);default:return Ni(Object(e))}}function Ni(e){const t=[];for(const i in e)t.push(i);return t}function Li(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function Di(e,...t){for(let i=0;i{const n=e[t];Object.hasOwn(e,t)&&Li(n,i)&&(void 0!==i||t in e)||(e[t]=i)},Gi=/^(?:0|[1-9]\d*)$/;function Ji(e,t=Number.MAX_SAFE_INTEGER){switch(typeof e){case"number":return Number.isInteger(e)&&e>=0&&ei,()=>{})}function en(e,t){if(!Number.isInteger(e)||e<0)throw new Error("n must be a non-negative integer.");let i=0;return(...n)=>{if(++i>=e)return t(...n)}}function tn(e){if(!e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t))&&"[object Object]"===Object.prototype.toString.call(e)}function nn(e,t,i){return sn(e,t,void 0,void 0,void 0,void 0,i)}function sn(e,t,i,n,s,o,r){const a=r(e,t,i,n,s,o);if(void 0!==a)return a;if(typeof e==typeof t)switch(typeof e){case"bigint":case"string":case"boolean":case"symbol":case"undefined":case"function":return e===t;case"number":return e===t||Object.is(e,t);case"object":return on(e,t,o,r)}return on(e,t,o,r)}function on(e,t,i,n){if(Object.is(e,t))return!0;let s=a(e),o=a(t);if(s===h&&(s=_),o===h&&(o=_),s!==o)return!1;switch(s){case c:return e.toString()===t.toString();case d:return Li(e.valueOf(),t.valueOf());case u:case g:case m:return Object.is(e.valueOf(),t.valueOf());case l:return e.source===t.source&&e.flags===t.flags;case"[object Function]":return e===t}const I=(i=i??new Map).get(e),V=i.get(t);if(null!=I&&null!=V)return I===t;i.set(e,t),i.set(t,e);try{switch(s){case f:if(e.size!==t.size)return!1;for(const[s,o]of e.entries())if(!t.has(s)||!sn(o,t.get(s),s,e,t,i,n))return!1;return!0;case p:{if(e.size!==t.size)return!1;const s=Array.from(e.values()),o=Array.from(t.values());for(let r=0;rsn(a,s,void 0,e,t,i,n));if(-1===l)return!1;o.splice(l,1)}return!0}case b:case y:case k:case C:case A:case"[object BigUint64Array]":case T:case E:case x:case"[object BigInt64Array]":case P:case S:if("undefined"!=typeof Buffer&&Buffer.isBuffer(e)!==Buffer.isBuffer(t))return!1;if(e.length!==t.length)return!1;for(let s=0;s{}),nn(e,t,(...n)=>{const s=i(...n);return void 0!==s?Boolean(s):e instanceof Map&&t instanceof Map||e instanceof Set&&t instanceof Set?rn(Array.from(e),Array.from(t),en(2,i)):void 0})}function an(e,t){return nn(e,t,j)}function ln(e){if(I(e))return e;const t=a(e);if(!function(e){switch(a(e)){case h:case b:case w:case v:case u:case g:case P:case S:case T:case E:case x:case f:case d:case _:case l:case p:case c:case m:case y:case k:case C:case A:return!0;default:return!1}}(e))return{};if(i=e,Array.isArray(i)){const t=Array.from(e);return e.length>0&&"string"==typeof e[0]&&Object.hasOwn(e,"index")&&(t.index=e.index,t.input=e.input),t}var i;if(W(e)){const t=e;return new(0,t.constructor)(t.buffer,t.byteOffset,t.length)}if(t===w)return new ArrayBuffer(e.byteLength);if(t===v){const t=e,i=t.buffer,n=t.byteOffset,s=t.byteLength,o=new ArrayBuffer(s),r=new Uint8Array(i,n,s);return new Uint8Array(o).set(r),new DataView(o)}if(t===u||t===d||t===c){const i=new(0,e.constructor)(e.valueOf());return t===c?function(e,t){const i=t.valueOf().length;for(const n in t)Object.hasOwn(t,n)&&(Number.isNaN(Number(n))||Number(n)>=i)&&(e[n]=t[n])}(i,e):cn(i,e),i}if(t===g)return new Date(Number(e));if(t===l){const t=e,i=new RegExp(t.source,t.flags);return i.lastIndex=t.lastIndex,i}if(t===m)return Object(Symbol.prototype.valueOf.call(e));if(t===f){const t=e,i=new Map;return t.forEach((e,t)=>{i.set(t,e)}),i}if(t===p){const t=e,i=new Set;return t.forEach(e=>{i.add(e)}),i}if(t===h){const t=e,i={};return cn(i,t),i.length=t.length,i[Symbol.iterator]=t[Symbol.iterator],i}const n={};return function(e,t){const i=Object.getPrototypeOf(t);if(null!==i){"function"==typeof t.constructor&&Object.setPrototypeOf(e,i)}}(n,e),cn(n,e),function(e,t){const i=Object.getOwnPropertySymbols(t);for(let n=0;ngn([[t,r]],e))}dn.has(o)||(dn.set(o,new Map),o.registerPostFixer(e=>gn(dn.get(o),e)),o.on("change:isComposing",()=>{e.change(e=>gn(dn.get(o),e))},{priority:"high"})),t.is("editableElement")&&t.on("change:placeholder",(e,t,i)=>r(i)),t.placeholder?r(t.placeholder):i&&r(i),i&&function(){un||pe("enableViewPlaceholder-deprecated-text-option");un=!0}()}function mn(e,t){return!!t.hasClass("ck-placeholder")&&(e.removeClass("ck-placeholder",t),!0)}function gn(e,t){const i=[];let n=!1;for(const[s,o]of e)o.isDirectHost&&(i.push(s),fn(t,s,o)&&(n=!0));for(const[s,o]of e){if(o.isDirectHost)continue;const e=pn(s);e!==o.hostElement&&o.hostElement&&(t.removeAttribute("data-placeholder",o.hostElement),mn(t,o.hostElement),o.hostElement=null,n=!0),e&&(i.includes(e)||(o.hostElement=e,fn(t,s,o)&&(n=!0)))}return n}function fn(e,t,i){const{text:n,isDirectHost:s,hostElement:o}=i;let r=!1;return o.getAttribute("data-placeholder")!==n&&(e.setAttribute("data-placeholder",n,o),r=!0),(s||1==t.childCount)&&function(e,t){if(!e.isAttached())return!1;if(function(e){for(const t of e.getChildren())if(!t.is("uiElement"))return!0;return!1}(e))return!1;const i=e.document,n=i.selection.anchor;return!(i.isComposing&&n&&n.parent===e||!t&&i.isFocused&&(!n||n.parent===e))}(o,i.keepOnFocus)?function(e,t){return!t.hasClass("ck-placeholder")&&(e.addClass("ck-placeholder",t),!0)}(e,o)&&(r=!0):mn(e,o)&&(r=!0),r}function pn(e){if(e.childCount){const t=e.getChild(0);if(t.is("element")&&!t.is("uiElement")&&!t.is("attributeElement"))return t}return null}var bn=class{is(){throw new Error("is() method is abstract")}};const wn=Te(bn);var _n=class extends wn{document;parent;constructor(e){super(),this.document=e,this.parent=null}get index(){let e;if(!this.parent)return null;if(-1==(e=this.parent.getChildIndex(this)))throw new fe("view-node-not-found-in-parent",this);return e}get nextSibling(){const e=this.index;return null!==e&&this.parent.getChild(e+1)||null}get previousSibling(){const e=this.index;return null!==e&&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 t=this;for(;t.parent;)e.unshift(t.index),t=t.parent;return e}getAncestors(e={}){const t=[];let i=e.includeSelf?this:this.parent;for(;i;)t[e.parentFirst?"push":"unshift"](i),i=i.parent;return t}getCommonAncestor(e,t={}){const i=this.getAncestors(t),n=e.getAncestors(t);let s=0;for(;i[s]==n[s]&&i[s];)s++;return 0===s?null:i[s-1]}isBefore(e){if(this==e)return!1;if(this.root!==e.root)return!1;const t=this.getPath(),i=e.getPath(),n=Ke(t,i);switch(n){case"prefix":return!0;case"extension":return!1;default:return t[n]e.data.length)throw new fe("view-textproxy-wrong-offsetintext",this);if(i<0||t+i>e.data.length)throw new fe("view-textproxy-wrong-length",this);this.data=e.data.substring(t,t+i),this.offsetInText=t}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 t=[];let i=e.includeSelf?this.textNode:this.parent;for(;null!==i;)t[e.parentFirst?"push":"unshift"](i),i=i.parent;return t}};yn.prototype.is=function(e){return"$textProxy"===e||"view:$textProxy"===e||"textProxy"===e||"view:textProxy"===e};var kn=class e{_consumables=new Map;add(e,t){let i;e.is("$text")||e.is("documentFragment")?this._consumables.set(e,!0):(this._consumables.has(e)?i=this._consumables.get(e):(i=new Cn(e),this._consumables.set(e,i)),i.add(t?An(t):e._getConsumables()))}test(e,t){const i=this._consumables.get(e);return void 0===i?null:e.is("$text")||e.is("documentFragment")?i:i.test(An(t))}consume(e,t){if(e.is("$text")||e.is("documentFragment"))return!!this.test(e,t)&&(this._consumables.set(e,!1),!0);const i=this._consumables.get(e);return void 0!==i&&i.consume(An(t))}revert(e,t){const i=this._consumables.get(e);void 0!==i&&(e.is("$text")||e.is("documentFragment")?this._consumables.set(e,!0):i.revert(An(t)))}static createFrom(t,i){if(i||(i=new e),t.is("$text"))i.add(t);else if(t.is("element")||t.is("documentFragment")){i.add(t);for(const n of t.getChildren())e.createFrom(n,i)}return i}},Cn=class{element;_canConsumeName=null;_attributes=new Map;constructor(e){this.element=e}add(e){e.name&&(this._canConsumeName=!0);for(const[t,i]of e.attributes)if(i){let e=this._attributes.get(t);e&&"boolean"!=typeof e||(e=new Map,this._attributes.set(t,e)),e.set(i,!0)}else{if("style"==t||"class"==t)throw new fe("viewconsumable-invalid-attribute",this);this._attributes.set(t,!0)}}test(e){if(e.name&&!this._canConsumeName)return this._canConsumeName;for(const[t,i]of e.attributes){const e=this._attributes.get(t);if(void 0===e)return null;if(!1===e)return!1;if(!0!==e)if(i){const t=e.get(i);if(void 0===t)return null;if(!t)return!1}else for(const t of e.values())if(!t)return!1}return!0}consume(e){if(!this.test(e))return!1;e.name&&(this._canConsumeName=!1);for(const[t,i]of e.attributes){const e=this._attributes.get(t);if("boolean"==typeof e)for(const[e]of this.element._getConsumables(t,i).attributes)this._attributes.set(e,!1);else if(i)for(const[,n]of this.element._getConsumables(t,i).attributes)e.set(n,!1);else for(const t of e.keys())e.set(t,!1)}return!0}revert(e){e.name&&(this._canConsumeName=!0);for(const[t,i]of e.attributes){const e=this._attributes.get(t);if(!1!==e){if(void 0!==e&&!0!==e)if(i)!1===e.get(i)&&e.set(i,!0);else for(const t of e.keys())e.set(t,!0)}else this._attributes.set(t,!0)}}};function An(e){const t=[];return"attributes"in e&&e.attributes&&Tn(t,e.attributes),"classes"in e&&e.classes&&Tn(t,e.classes,"class"),"styles"in e&&e.styles&&Tn(t,e.styles,"style"),{name:e.name||!1,attributes:t}}function Tn(e,t,i){if("string"!=typeof t)for(const n of t)Array.isArray(n)?e.push(n):e.push(i?[i,n]:[n]);else e.push(i?[i,t]:[t])}var En=class{_patterns=[];constructor(...e){this.add(...e)}add(...e){for(let t of e)("string"==typeof t||t instanceof RegExp)&&(t={name:t}),this._patterns.push(t)}match(...e){for(const t of e)for(const e of this._patterns){const i=this._isElementMatching(t,e);if(i)return{element:t,pattern:e,match:i}}return null}matchAll(...e){const t=[];for(const i of e)for(const e of this._patterns){const n=this._isElementMatching(i,e);n&&t.push({element:i,pattern:e,match:n})}return t.length>0?t:null}getElementName(){if(1!==this._patterns.length)return null;const e=this._patterns[0],t=e.name;return"function"==typeof e||!t||t instanceof RegExp?null:t}_isElementMatching(e,t){if("function"==typeof t){const i=t(e);return i&&"object"==typeof i?An(i):i}const i={};if(t.name&&(i.name=function(e,t){return e instanceof RegExp?!!t.match(e):e===t}(t.name,e.name),!i.name))return null;const n=[];return t.attributes&&!function(e,t,i){let n;"object"!=typeof e||e instanceof RegExp||Array.isArray(e)?n=["class","style"]:(void 0!==e.style&&pe("matcher-pattern-deprecated-attributes-style-key",e),void 0!==e.class&&pe("matcher-pattern-deprecated-attributes-class-key",e));return t._collectAttributesMatch(Pn(e),i,n)}(t.attributes,e,n)||t.classes&&!function(e,t,i){return t._collectAttributesMatch(Pn(e,"class"),i)}(t.classes,e,n)||t.styles&&!function(e,t,i){return t._collectAttributesMatch(Pn(e,"style"),i)}(t.styles,e,n)?null:(n.length&&(i.attributes=n),i)}};function xn(e,t){return!0===e||e===t||e instanceof RegExp&&!!String(t).match(e)}function Pn(e,t){if(Array.isArray(e))return e.map(e=>"object"!=typeof e||e instanceof RegExp?t?[t,e,!0]:[e,!0]:(void 0!==e.key&&void 0!==e.value||pe("matcher-pattern-missing-key-or-value",e),t?[t,e.key,e.value]:[e.key,e.value]));if("object"!=typeof e||e instanceof RegExp)return[t?[t,e,!0]:[e,!0]];const i=[];for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&i.push(t?[t,n,e[n]]:[n,e[n]]);return i}var Sn=class{_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 t=function(e){let t=null,i=0,n=0,s=null;const o=new Map;if(""===e)return o;";"!=e.charAt(e.length-1)&&(e+=";");for(let r=0;rt===e);return Array.isArray(t)}set(e,t){if(this._cachedStyleNames=null,this._cachedExpandedStyleNames=null,n(e))for(const[t,i]of Object.entries(e))this._styleProcessor.toNormalizedForm(t,i,this._styles);else this._styleProcessor.toNormalizedForm(e,t,this._styles)}remove(e){const t={};for(const i of ii(e)){const e=Vn(i),n=ji(this._styles,e);if(n)On(t,e,n);else{const e=this.getAsString(i);void 0!==e&&this._styleProcessor.toNormalizedForm(i,e,t)}}Object.keys(t).length&&(Rn(this._styles,t),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]&&!n(this._styles[e]))return this._styles[e];const t=this._styleProcessor.getReducedForm(e,this._styles).find(([t])=>t===e);return Array.isArray(t)?t[1]:void 0}getStyleNames(e=!1){return this.isEmpty?[]:e?(this._cachedExpandedStyleNames||=this._styleProcessor.getStyleNames(this._styles),this._cachedExpandedStyleNames):(this._cachedStyleNames||=this.getStylesEntries().map(([e])=>e),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 t of this.getStyleNames())if(!e.has(t)||e.getAsString(t)!==this.getAsString(t))return!1;return!0}getStylesEntries(){const e=[],t=Object.keys(this._styles);for(const i of t)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,t){const i=[];for(const n of this.getStyleNames(!0))if(xn(e,n)){if(!0===t){i.push(n);continue}xn(t,this.getAsString(n))&&i.push(n)}return i.length?i:void 0}_getConsumables(e){const t=[];if(e){t.push(e);for(const i of this._styleProcessor.getRelatedStyles(e))t.push(i)}else for(const e of this.getStyleNames()){for(const i of this._styleProcessor.getRelatedStyles(e))t.push(i);t.push(e)}return t}_canMergeFrom(e){for(const t of e.getStyleNames())if(this.has(t)&&this.getAsString(t)!==e.getAsString(t))return!1;return!0}_mergeFrom(e){for(const t of e.getStyleNames())this.has(t)||this.set(t,e.getAsString(t))}_isMatching(e){for(const t of e.getStyleNames())if(!this.has(t)||this.getAsString(t)!==e.getAsString(t))return!1;return!0}},In=class{_normalizers;_extractors;_reducers;_consumables;constructor(){this._normalizers=new Map,this._extractors=new Map,this._reducers=new Map,this._consumables=new Map}toNormalizedForm(e,t,i){if(n(t))On(i,Vn(e),t);else if(this._normalizers.has(e)){const{path:n,value:s}=this._normalizers.get(e)(t);On(i,n,s)}else On(i,e,t)}getNormalized(e,t){if(!e)return K({},t);if(void 0!==t[e])return t[e];if(this._extractors.has(e)){const i=this._extractors.get(e);if("string"==typeof i)return ji(t,i);const n=i(e,t);if(n)return n}return ji(t,Vn(e))}getReducedForm(e,t){const i=this.getNormalized(e,t);return void 0===i?[]:this._reducers.has(e)?this._reducers.get(e)(i):[[e,i]]}getStyleNames(e){const t=new Set;for(const i of this._consumables.keys()){const n=this.getNormalized(i,e);n&&("object"!=typeof n||Object.keys(n).length)&&t.add(i)}for(const i of Object.keys(e))t.add(i);return Array.from(t)}getRelatedStyles(e){return this._consumables.get(e)||[]}setNormalizer(e,t){this._normalizers.set(e,t)}setExtractor(e,t){this._extractors.set(e,t)}setReducer(e,t){this._reducers.set(e,t)}setStyleRelation(e,t){this._mapStyleNames(e,t);for(const i of t)this._mapStyleNames(i,[e])}_mapStyleNames(e,t){this._consumables.has(e)||this._consumables.set(e,[]),this._consumables.get(e).push(...t)}};function Vn(e){return e.replace("-",".")}function On(e,t,i){let s=i;n(i)&&!Array.isArray(i)&&(s=K({},ji(e,t),i)),Zi(e,t,s)}function Rn(e,t){for(const i of Object.keys(t))null===e[i]||Array.isArray(e[i])||"object"!=typeof e[i]||"object"!=typeof t[i]?delete e[i]:(Rn(e[i],t[i]),Object.keys(e[i]).length||delete e[i])}var Bn=class{_set=new Set;get isEmpty(){return 0==this._set.size}get size(){return this._set.size}has(e){return this._set.has(e)}keys(){return Array.from(this._set.keys())}setTo(e){this.clear();for(const t of e.split(/\s+/))t&&this._set.add(t);return this}set(e){for(const t of ii(e))t&&this._set.add(t)}remove(e){for(const t of ii(e))this._set.delete(t)}clear(){this._set.clear()}toString(){return Array.from(this._set).join(" ")}isSimilar(e){if(this.size!==e.size)return!1;for(const t of this.keys())if(!e.has(t))return!1;return!0}_clone(){const e=new this.constructor;return e._set=new Set(this._set),e}_getTokensMatch(e){const t=[];if(!0===e){for(const e of this._set.keys())t.push(e);return t}if("string"==typeof e){for(const i of e.split(/\s+/)){if(!this._set.has(i))return;t.push(i)}return t}for(const i of this._set.keys())i.match(e)&&t.push(i);return t.length?t:void 0}_getConsumables(e){return e?[e]:this.keys()}_canMergeFrom(){return!0}_mergeFrom(e){for(const t of e._set.keys())this._set.has(t)||this._set.add(t)}_isMatching(e){for(const t of e._set.keys())if(!this._set.has(t))return!1;return!0}},Mn=class e extends _n{name;_unsafeAttributesToRender=[];_attrs;_children;_customProperties=new Map;get _classes(){return this._attrs.get("class")}get _styles(){return this._attrs.get("style")}constructor(e,t,i,n){super(e),this.name=t,this._attrs=this._parseAttributes(i),this._children=[],n&&this._insertChild(0,n)}get childCount(){return this._children.length}get isEmpty(){return 0===this._children.length}getChild(e){return this._children[e]}getChildIndex(e){return this._children.indexOf(e)}getChildren(){return this._children[Symbol.iterator]()}*getAttributeKeys(){this._classes&&(yield"class"),this._styles&&(yield"style");for(const e of this._attrs.keys())"class"!=e&&"style"!=e&&(yield e)}*getAttributes(){for(const[e,t]of this._attrs.entries())yield[e,String(t)]}getAttribute(e){return this._attrs.has(e)?String(this._attrs.get(e)):void 0}hasAttribute(e,t){return!!this._attrs.has(e)&&(void 0===t||(Nn(this.name,e)||Fn(this.name,e)?this._attrs.get(e).has(t):this._attrs.get(e)===t))}isSimilar(t){if(!(t instanceof e))return!1;if(this===t)return!0;if(this.name!=t.name)return!1;if(this._attrs.size!==t._attrs.size)return!1;for(const[e,i]of this._attrs){const n=t._attrs.get(e);if(void 0===n)return!1;if("string"==typeof i||"string"==typeof n){if(n!==i)return!1}else if(!i.isSimilar(n))return!1}return!0}hasClass(...e){for(const t of e)if(!this._classes||!this._classes.has(t))return!1;return!0}getClassNames(){const e=this._classes?this._classes.keys():[],t=e[Symbol.iterator]();return Object.assign(e,{next:t.next.bind(t)})}getStyle(e){return this._styles&&this._styles.getAsString(e)}getNormalizedStyle(e){return this._styles&&this._styles.getNormalized(e)}getStyleNames(e){return this._styles?this._styles.getStyleNames(e):[]}hasStyle(...e){for(const t of e)if(!this._styles||!this._styles.has(t))return!1;return!0}findAncestor(...e){const t=new En(...e);let i=this.parent;for(;i&&!i.is("documentFragment");){if(t.match(i))return i;i=i.parent}return null}getCustomProperty(e){return this._customProperties.get(e)}*getCustomProperties(){yield*this._customProperties.entries()}getIdentity(){const e=this._classes?this._classes.keys().sort().join(","):"",t=this._styles&&String(this._styles),i=Array.from(this._attrs).filter(([e])=>"style"!=e&&"class"!=e).map(e=>`${e[0]}="${e[1]}"`).sort().join(" ");return this.name+(""==e?"":` class="${e}"`)+(t?` style="${t}"`:"")+(""==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 t of this._children)e.children.push(t.toJSON())}return e}_clone(e=!1){const t=[];if(e)for(const i of this.getChildren())t.push(i._clone(e));const i=new this.constructor(this.document,this.name,this._attrs,t);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,t){this._fireChange("children",this,{index:e});let i=0;const n=function(e,t){if("string"==typeof t)return[new vn(e,t)];Ge(t)||(t=[t]);const i=[];for(const n of t)"string"==typeof n?i.push(new vn(e,n)):n instanceof yn?i.push(new vn(e,n.data)):i.push(n);return i}(this.document,t);for(const t of n)null!==t.parent&&t._remove(),t.parent=this,t.document=this.document,this._children.splice(e,0,t),e++,i++;return i}_removeChildren(e,t=1){this._fireChange("children",this,{index:e});for(let i=e;it&&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}};Hn.prototype.is=function(e,t){return t?t===this.name&&("editableElement"===e||"view:editableElement"===e||"containerElement"===e||"view:containerElement"===e||"element"===e||"view:element"===e):"editableElement"===e||"view:editableElement"===e||"containerElement"===e||"view:containerElement"===e||"element"===e||"view:element"===e||"node"===e||"view:node"===e};const $n=Symbol("rootName");var Wn=class extends Hn{constructor(e,t){super(e,t),this.rootName="main"}get rootName(){return this.getCustomProperty($n)}set rootName(e){this._setCustomProperty($n,e)}toJSON(){return this.rootName}set _name(e){this.name=e}};Wn.prototype.is=function(e,t){return t?t===this.name&&("rootElement"===e||"view:rootElement"===e||"editableElement"===e||"view:editableElement"===e||"containerElement"===e||"view:containerElement"===e||"element"===e||"view:element"===e):"rootElement"===e||"view:rootElement"===e||"editableElement"===e||"view:editableElement"===e||"containerElement"===e||"view:containerElement"===e||"element"===e||"view:element"===e||"node"===e||"view:node"===e};var Un=class{direction;boundaries;singleCharacters;shallow;ignoreElementEnd;_position;_boundaryStartParent;_boundaryEndParent;constructor(e={}){if(!e.boundaries&&!e.startPosition)throw new fe("view-tree-walker-no-start-position",null);if(e.direction&&"forward"!=e.direction&&"backward"!=e.direction)throw new fe("view-tree-walker-unknown-direction",e.startPosition,{direction:e.direction});this.boundaries=e.boundaries||null,e.startPosition?this._position=qn._createAt(e.startPosition):this._position=qn._createAt(e.boundaries["backward"==e.direction?"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 t,i;do{i=this.position,t=this.next()}while(!t.done&&e(t.value));t.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"forward"==this.direction?this._next():this._previous()}_next(){let e=this.position.clone();const t=this.position,i=e.parent;if(null===i.parent&&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 n;if(i&&i.is("view:$text")){if(e.isAtEnd)return this._position=qn._createAfter(i),this._next();n=i.data[e.offset]}else n=i.getChild(e.offset);if("string"==typeof n){let n;n=this.singleCharacters?1:(i===this._boundaryEndParent?this.boundaries.end.offset:i.data.length)-e.offset;const s=new yn(i,e.offset,n);return e.offset+=n,this._position=e,this._formatReturnValue("text",s,t,e,n)}if(n&&n.is("view:element")){if(this.shallow){if(this.boundaries&&this.boundaries.end.isBefore(e))return{done:!0,value:void 0};e.offset++}else e=new qn(n,0);return this._position=e,this._formatReturnValue("elementStart",n,t,e,1)}if(n&&n.is("view:$text")){if(this.singleCharacters)return e=new qn(n,0),this._position=e,this._next();let i,s=n.data.length;return n==this._boundaryEndParent?(s=this.boundaries.end.offset,i=new yn(n,0,s),e=qn._createAfter(i)):(i=new yn(n,0,n.data.length),e.offset++),this._position=e,this._formatReturnValue("text",i,t,e,s)}return e=qn._createAfter(i),this._position=e,this.ignoreElementEnd?this._next():this._formatReturnValue("elementEnd",i,t,e)}_previous(){let e=this.position.clone();const t=this.position,i=e.parent;if(null===i.parent&&0===e.offset)return{done:!0,value:void 0};if(i==this._boundaryStartParent&&e.offset==this.boundaries.start.offset)return{done:!0,value:void 0};let n;if(i.is("view:$text")){if(e.isAtStart)return this._position=qn._createBefore(i),this._previous();n=i.data[e.offset-1]}else n=i.getChild(e.offset-1);if("string"==typeof n){let n;if(this.singleCharacters)n=1;else{const t=i===this._boundaryStartParent?this.boundaries.start.offset:0;n=e.offset-t}e.offset-=n;const s=new yn(i,e.offset,n);return this._position=e,this._formatReturnValue("text",s,t,e,n)}if(n&&n.is("view:element"))return this.shallow?(e.offset--,this._position=e,this._formatReturnValue("elementStart",n,t,e,1)):(e=new qn(n,n.childCount),this._position=e,this.ignoreElementEnd?this._previous():this._formatReturnValue("elementEnd",n,t,e));if(n&&n.is("view:$text")){if(this.singleCharacters)return e=new qn(n,n.data.length),this._position=e,this._previous();let i,s=n.data.length;if(n==this._boundaryStartParent){const t=this.boundaries.start.offset;i=new yn(n,t,n.data.length-t),s=i.data.length,e=qn._createBefore(i)}else i=new yn(n,0,n.data.length),e.offset--;return this._position=e,this._formatReturnValue("text",i,t,e,s)}return e=qn._createBefore(i),this._position=e,this._formatReturnValue("elementStart",i,t,e,1)}_formatReturnValue(e,t,i,n,s){return t.is("view:$textProxy")&&(t.offsetInText+t.data.length==t.textNode.data.length&&("forward"!=this.direction||this.boundaries&&this.boundaries.end.isEqual(this.position)?i=qn._createAfter(t.textNode):(n=qn._createAfter(t.textNode),this._position=n)),0===t.offsetInText&&("backward"!=this.direction||this.boundaries&&this.boundaries.start.isEqual(this.position)?i=qn._createBefore(t.textNode):(n=qn._createBefore(t.textNode),this._position=n))),{done:!1,value:{type:e,item:t,previousPosition:i,nextPosition:n,length:s}}}},qn=class e extends bn{parent;offset;constructor(e,t){super(),this.parent=e,this.offset=t}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 0===this.offset}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 Hn);){if(!e.parent)return null;e=e.parent}return e}getShiftedBy(t){const i=e._createAt(this),n=i.offset+t;return i.offset=n<0?0:n,i}getLastMatchingPosition(e,t={}){t.startPosition=this;const i=new Un(t);return i.skip(e),i.position}getAncestors(){return this.parent.is("documentFragment")?[this.parent]:this.parent.getAncestors({includeSelf:!0})}getCommonAncestor(e){const t=this.getAncestors(),i=e.getAncestors();let n=0;for(;t[n]==i[n]&&t[n];)n++;return 0===n?null:t[n-1]}isEqual(e){return this.parent==e.parent&&this.offset==e.offset}isBefore(e){return"before"==this.compareWith(e)}isAfter(e){return"after"==this.compareWith(e)}compareWith(e){if(this.root!==e.root)return"different";if(this.isEqual(e))return"same";const t=this.parent.is("node")?this.parent.getPath():[],i=e.parent.is("node")?e.parent.getPath():[];t.push(this.offset),i.push(e.offset);const n=Ke(t,i);switch(n){case"prefix":return"before";case"extension":return"after";default:return t[n]0?new this(i,n):new this(n,i)}static _createIn(e){return this._createFromParentsAndOffsets(e,0,e,e.childCount)}static _createOn(e){const t=e.is("$textProxy")?e.offsetSize:1;return this._createFromPositionAndShift(qn._createBefore(e),t)}};function Kn(e){return!(!e.item.is("attributeElement")&&!e.item.is("uiElement"))}jn.prototype.is=function(e){return"range"===e||"view:range"===e};const Gn=Te(bn);var Jn=class e extends Gn{_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 1===this.rangeCount&&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 t of this._ranges)e&&!t.start.isBefore(e.start)||(e=t);return e?e.clone():null}getLastRange(){let e=null;for(const t of this._ranges)e&&!t.end.isAfter(e.end)||(e=t);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)return!1;if(this.isFake&&this.fakeSelectionLabel!=e.fakeSelectionLabel)return!1;if(this.rangeCount!=e.rangeCount)return!1;if(0===this.rangeCount)return!0;if(!this.anchor.isEqual(e.anchor)||!this.focus.isEqual(e.focus))return!1;for(const t of this._ranges){let i=!1;for(const n of e._ranges)if(t.isEqual(n)){i=!0;break}if(!i)return!1}return!0}isSimilar(e){if(this.isBackward!=e.isBackward)return!1;const t=je(this.getRanges());if(t!=je(e.getRanges()))return!1;if(0==t)return!0;for(let t of this.getRanges()){t=t.getTrimmed();let i=!1;for(let n of e.getRanges())if(n=n.getTrimmed(),t.start.isEqual(n.start)&&t.end.isEqual(n.end)){i=!0;break}if(!i)return!1}return!0}getSelectedElement(){return 1!==this.rangeCount?null:this.getFirstRange().getContainedElement()}setTo(...t){let[i,n,s]=t;if("object"==typeof n&&(s=n,n=void 0),null===i)this._setRanges([]),this._setFakeOptions(s);else if(i instanceof e||i instanceof Yn)this._setRanges(i.getRanges(),i.isBackward),this._setFakeOptions({fake:i.isFake,label:i.fakeSelectionLabel});else if(i instanceof jn)this._setRanges([i],s&&s.backward),this._setFakeOptions(s);else if(i instanceof qn)this._setRanges([new jn(i)]),this._setFakeOptions(s);else if(i instanceof _n){const e=!!s&&!!s.backward;let t;if(void 0===n)throw new fe("view-selection-setto-required-second-parameter",this);t="in"==n?jn._createIn(i):"on"==n?jn._createOn(i):new jn(qn._createAt(i,n)),this._setRanges([t],e),this._setFakeOptions(s)}else{if(!Ge(i))throw new fe("view-selection-setto-not-selectable",this);this._setRanges(i,s&&s.backward),this._setFakeOptions(s)}this.fire("change")}setFocus(e,t){if(null===this.anchor)throw new fe("view-selection-setfocus-no-ranges",this);const i=qn._createAt(e,t);if("same"==i.compareWith(this.focus))return;const n=this.anchor;this._ranges.pop(),"before"==i.compareWith(n)?this._addRange(new jn(i,n),!0):this._addRange(new jn(n,i)),this.fire("change")}toJSON(){const e={ranges:Array.from(this.getRanges()).map(e=>e.toJSON())};return this.isBackward&&(e.isBackward=!0),this.isFake&&(e.isFake=!0),e}_setRanges(e,t=!1){e=Array.from(e),this._ranges=[];for(const t of e)this._addRange(t);this._lastRangeBackward=!!t}_setFakeOptions(e={}){this._isFake=!!e.fake,this._fakeSelectionLabel=e.fake&&e.label||""}_addRange(e,t=!1){if(!(e instanceof jn))throw new fe("view-selection-add-range-not-range",this);this._pushRange(e),this._lastRangeBackward=!!t}_pushRange(e){for(const t of this._ranges)if(e.isIntersecting(t))throw new fe("view-selection-range-intersects",this,{addedRange:e,intersectingRange:t});this._ranges.push(new jn(e.start,e.end))}};Jn.prototype.is=function(e){return"selection"===e||"view:selection"===e};const Qn=Te(bn);var Yn=class extends Qn{_selection;constructor(...e){super(),this._selection=new Jn,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,t){this._selection.setFocus(e,t)}};Yn.prototype.is=function(e){return"selection"===e||"documentSelection"==e||"view:selection"==e||"view:documentSelection"==e};var Xn=class extends de{startRange;_eventPhase;_currentTarget;constructor(e,t,i){super(e,t),this.startRange=i,this._eventPhase="none",this._currentTarget=null}get eventPhase(){return this._eventPhase}get currentTarget(){return this._currentTarget}};const Zn=Symbol("bubblingEmitter"),es=Symbol("bubblingCallbacks"),ts=Symbol("bubblingContexts");function is(e){return class extends e{fire(e,...t){try{const i=e instanceof de?e:new de(this,e),n=os(this),s=as(this);if(ns(i,"capturing",this),ss(n,"$capture",i,...t))return i.return;const o=i.startRange||this.selection.getFirstRange(),r=o?o.getContainedElement():null,a=!!r&&function(e,t){for(const i of e)if(i(t))return!0;return!1}(s,r);let l=r||function(e){if(!e)return null;const t=e.start.parent,i=e.end.parent,n=t.getPath(),s=i.getPath();return n.length>s.length?t:i}(o);if(ns(i,"atTarget",l),!a){if(ss(n,"$text",i,...t))return i.return;ns(i,"bubbling",l)}for(;l;){if(l.is("element")&&ss(n,l,i,...t))return i.return;l=l.parent,ns(i,"bubbling",l)}return ns(i,"bubbling",this),ss(n,"$document",i,...t),i.return}catch(e){fe.rethrowUnexpectedError(e,this)}}_addEventListener(e,t,i){const n=ii(i.context||"$document"),s=os(this),o=rs(this);for(const e of n)"function"==typeof e&&as(this).add(e);const r=function(e,t,i){return function(n,s){const{currentTarget:o,eventArgs:r}=s;if("string"!=typeof o){if(o.is("rootElement")&&t.includes("$root"))i.call(e,n,...r);else if(t.includes(o.name))i.call(e,n,...r);else for(const s of t)if("function"==typeof s&&s(o))return void i.call(e,n,...r)}else t.includes(o)&&i.call(e,n,...r)}}(this,n,t);o.set(t,r),this.listenTo(s,e,r,i)}_removeEventListener(e,t){const i=os(this),n=rs(this),s=n.get(t);s&&(n.delete(t),this.stopListening(i,e,s))}}}function ns(e,t,i){e instanceof Xn&&(e._eventPhase=t,e._currentTarget=i)}function ss(e,t,i,...n){return e.fire(i,{currentTarget:t,eventArgs:n}),!!i.stop.called}function os(e){return e[Zn]||(e[Zn]=new(Te())),e[Zn]}function rs(e){return e[es]||(e[es]=new Map),e[es]}function as(e){return e[ts]||(e[ts]=new Set),e[ts]}const ls=is(De());var cs=class extends ls{selection;roots;stylesProcessor;_postFixers=new Set;constructor(e){super(),this.selection=new Yn,this.roots=new ri({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)}getRoots(){return Array.from(this.roots)}registerPostFixer(e){this._postFixers.add(e)}destroy(){this.roots.forEach(e=>e.destroy()),this.stopListening()}_callPostFixers(e){let t=!1;do{for(const i of this._postFixers)if(t=i(e),t)break}while(t)}};var ds=class extends Mn{static DEFAULT_PRIORITY=10;_priority=10;_id=null;_clonesGroup=null;constructor(e,t,i,n){super(e,t,i,n),this.getFillerOffset=us}get priority(){return this._priority}get id(){return this._id}getElementsWithSameId(){if(null===this.id)throw new fe("attribute-element-get-elements-with-same-id-no-id",this);return new Set(this._clonesGroup)}isSimilar(e){return null!==this.id||null!==e.id?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 t=super._clone(e);return t._priority=this._priority,t._id=this._id,t}_canMergeAttributesFrom(e){return null===this.id&&null===e.id&&this.priority===e.priority&&super._canMergeAttributesFrom(e)}_canSubtractAttributesOf(e){return null===this.id&&null===e.id&&this.priority===e.priority&&super._canSubtractAttributesOf(e)}};function us(){if(hs(this))return null;let e=this.parent;for(;e&&e.is("attributeElement");){if(hs(e)>1)return null;e=e.parent}return!e||hs(e)>1?null:this.childCount}function hs(e){return Array.from(e.getChildren()).filter(e=>!e.is("uiElement")).length}ds.prototype.is=function(e,t){return t?t===this.name&&("attributeElement"===e||"view:attributeElement"===e||"element"===e||"view:element"===e):"attributeElement"===e||"view:attributeElement"===e||"element"===e||"view:element"===e||"node"===e||"view:node"===e};var ms=class extends Mn{constructor(e,t,i,n){super(e,t,i,n),this.getFillerOffset=gs}toJSON(){const e=super.toJSON();return e.type="EmptyElement",e}_insertChild(e,t){if(t&&(t instanceof _n||Array.from(t).length>0))throw new fe("view-emptyelement-cannot-add",[this,t]);return 0}};function gs(){return null}ms.prototype.is=function(e,t){return t?t===this.name&&("emptyElement"===e||"view:emptyElement"===e||"element"===e||"view:element"===e):"emptyElement"===e||"view:emptyElement"===e||"element"===e||"view:element"===e||"node"===e||"view:node"===e};var fs=class extends Mn{constructor(e,t,i,n){super(e,t,i,n),this.getFillerOffset=bs}_insertChild(e,t){if(t&&(t instanceof _n||Array.from(t).length>0))throw new fe("view-uielement-cannot-add",[this,t]);return 0}render(e,t){return this.toDomElement(e)}toDomElement(e){const t=e.createElement(this.name);for(const e of this.getAttributeKeys())t.setAttribute(e,this.getAttribute(e));return t}toJSON(){const e=super.toJSON();return e.type="UIElement",e}};function ps(e){e.document.on("arrowKey",(t,i)=>function(e,t,i){if(t.keyCode==Kt.arrowright){const e=t.domTarget.ownerDocument.defaultView.getSelection(),n=1==e.rangeCount&&e.getRangeAt(0).collapsed;if(n||t.shiftKey){const t=e.focusNode,s=e.focusOffset,o=i.domPositionToView(t,s);if(null===o)return;let r=!1;const a=o.getLastMatchingPosition(e=>(e.item.is("uiElement")&&(r=!0),!(!e.item.is("uiElement")&&!e.item.is("attributeElement"))));if(r){const t=i.viewPositionToDom(a);n?e.collapse(t.parent,t.offset):e.extend(t.parent,t.offset)}}}}(0,i,e.domConverter),{priority:"low"})}function bs(){return null}fs.prototype.is=function(e,t){return t?t===this.name&&("uiElement"===e||"view:uiElement"===e||"element"===e||"view:element"===e):"uiElement"===e||"view:uiElement"===e||"element"===e||"view:element"===e||"node"===e||"view:node"===e};var ws=class extends Mn{constructor(e,t,i,n){super(e,t,i,n),this.getFillerOffset=_s}toJSON(){const e=super.toJSON();return e.type="RawElement",e}_insertChild(e,t){if(t&&(t instanceof _n||Array.from(t).length>0))throw new fe("view-rawelement-cannot-add",[this,t]);return 0}render(e,t){}};function _s(){return null}ws.prototype.is=function(e,t){return t?t===this.name&&("rawElement"===e||"view:rawElement"===e||"element"===e||"view:element"===e):"rawElement"===e||"view:rawElement"===e||e===this.name||e==="view:"+this.name||"element"===e||"view:element"===e||"node"===e||"view:node"===e};const vs=Te(bn);var ys=class extends vs{document;_children=[];_customProperties=new Map;constructor(e,t){super(),this.document=e,t&&this._insertChild(0,t)}[Symbol.iterator](){return this._children[Symbol.iterator]()}get childCount(){return this._children.length}get isEmpty(){return 0===this.childCount}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 t of this._children)e.push(t.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,t){this._fireChange("children",this,{index:e});let i=0;const n=function(e,t){if("string"==typeof t)return[new vn(e,t)];Ge(t)||(t=[t]);return Array.from(t).map(t=>"string"==typeof t?new vn(e,t):t instanceof yn?new vn(e,t.data):t)}(this.document,t);for(const t of n)null!==t.parent&&t._remove(),t.parent=this,this._children.splice(e,0,t),e++,i++;return i}_removeChildren(e,t=1){this._fireChange("children",this,{index:e});for(let i=e;i{const i=e[e.length-1],n=!t.is("uiElement");return i&&i.breakAttributes==n?i.nodes.push(t):e.push({breakAttributes:n,nodes:[t]}),e},[]);let n=null,s=e;for(const{nodes:e,breakAttributes:t}of i){const i=this._insertNodes(s,e,t);n||(n=i.start),s=i.end}return n?new jn(n,s):new jn(e)}remove(e){const t=e instanceof jn?e:jn._createOn(e);if(Vs(t,this.document),t.isCollapsed)return new ys(this.document);const{start:i,end:n}=this._breakAttributesRange(t,!0),s=i.parent,o=n.offset-i.offset,r=s._removeChildren(i.offset,o);for(const e of r)this._removeFromClonedElementsGroup(e);const a=this.mergeAttributes(i);return t.start=a,t.end=a.clone(),new ys(this.document,r)}clear(e,t){Vs(e,this.document);const i=e.getWalker({direction:"backward",ignoreElementEnd:!0});for(const n of i){const i=n.item;let s;if(i.is("element")&&t.isSimilar(i))s=jn._createOn(i);else if(!n.nextPosition.isAfter(e.start)&&i.is("$textProxy")){const e=i.getAncestors().find(e=>e.is("element")&&t.isSimilar(e));e&&(s=jn._createIn(e))}s&&(s.end.isAfter(e.end)&&(s.end=e.end),s.start.isBefore(e.start)&&(s.start=e.start),this.remove(s))}}move(e,t){let i;if(t.isAfter(e.end)){const n=(t=this._breakAttributes(t,!0)).parent,s=n.childCount;e=this._breakAttributesRange(e,!0),i=this.remove(e),t.offset+=n.childCount-s}else i=this.remove(e);return this.insert(t,i)}wrap(e,t){if(!(t instanceof ds))throw new fe("view-writer-wrap-invalid-attribute",this.document);if(Vs(e,this.document),e.isCollapsed){let n=e.start;n.parent.is("element")&&(i=n.parent,!Array.from(i.getChildren()).some(e=>!e.is("uiElement")))&&(n=n.getLastMatchingPosition(e=>e.item.is("uiElement"))),n=this._wrapPosition(n,t);const s=this.document.selection;return s.isCollapsed&&s.getFirstPosition().isEqual(e.start)&&this.setSelection(n),new jn(n)}return this._wrapRange(e,t);var i}unwrap(e,t){if(!(t instanceof ds))throw new fe("view-writer-unwrap-invalid-attribute",this.document);if(Vs(e,this.document),e.isCollapsed)return e;const{start:i,end:n}=this._breakAttributesRange(e,!0),s=i.parent,o=this._unwrapChildren(s,i.offset,n.offset,t),r=this.mergeAttributes(o.start);return r.isEqual(o.start)||o.end.offset--,new jn(r,this.mergeAttributes(o.end))}rename(e,t){const i=new Ln(this.document,e,t.getAttributes());return this.insert(qn._createAfter(t),i),this.move(jn._createIn(t),qn._createAt(i,0)),this.remove(jn._createOn(t)),i}clearClonedElementsGroup(e){this._cloneGroups.delete(e)}createPositionAt(e,t){return qn._createAt(e,t)}createPositionAfter(e){return qn._createAfter(e)}createPositionBefore(e){return qn._createBefore(e)}createRange(e,t){return new jn(e,t)}createRangeOn(e){return jn._createOn(e)}createRangeIn(e){return jn._createIn(e)}createSelection(...e){return new Jn(...e)}createSlot(e="children"){if(!this._slotFactory)throw new fe("view-writer-invalid-create-slot-context",this.document);return this._slotFactory(this,e)}_registerSlotFactory(e){this._slotFactory=e}_clearSlotFactory(){this._slotFactory=null}_insertNodes(e,t,i){let n,s;if(n=i?Cs(e):e.parent.is("$text")?e.parent.parent:e.parent,!n)throw new fe("view-writer-invalid-position-container",this.document);s=i?this._breakAttributes(e,!0):e.parent.is("$text")?Es(e):e;const o=n._insertChild(s.offset,t);for(const e of t)this._addToClonedElementsGroup(e);const r=s.getShiftedBy(o),a=this.mergeAttributes(s);return a.isEqual(s)||r.offset--,new jn(a,this.mergeAttributes(r))}_wrapChildren(e,t,i,n){let s=t;const o=[];for(;s!1,e.parent._insertChild(e.offset,i);const n=new jn(e,e.getShiftedBy(1));this.wrap(n,t);const s=new qn(i.parent,i.index);i._remove();const o=s.nodeBefore,r=s.nodeAfter;return o&&o.is("view:$text")&&r&&r.is("view:$text")?xs(o,r):Ts(s)}_breakAttributesRange(e,t=!1){const i=e.start,n=e.end;if(Vs(e,this.document),e.isCollapsed){const i=this._breakAttributes(e.start,t);return new jn(i,i)}const s=this._breakAttributes(n,t),o=s.parent.childCount,r=this._breakAttributes(i,t);return s.offset+=s.parent.childCount-o,new jn(r,s)}_breakAttributes(e,t=!1){const i=e.offset,n=e.parent;if(e.parent.is("emptyElement"))throw new fe("view-writer-cannot-break-empty-element",this.document);if(e.parent.is("uiElement"))throw new fe("view-writer-cannot-break-ui-element",this.document);if(e.parent.is("rawElement"))throw new fe("view-writer-cannot-break-raw-element",this.document);if(!t&&n.is("$text")&&Is(n.parent))return e.clone();if(Is(n))return e.clone();if(n.is("$text"))return this._breakAttributes(Es(e),t);if(i==n.childCount){const e=new qn(n.parent,n.index+1);return this._breakAttributes(e,t)}if(0===i){const e=new qn(n.parent,n.index);return this._breakAttributes(e,t)}{const e=n.index+1,s=n._clone();n.parent._insertChild(e,s),this._addToClonedElementsGroup(s);const o=n.childCount-i,r=n._removeChildren(i,o);s._appendChild(r);const a=new qn(n.parent,e);return this._breakAttributes(a,t)}}_addToClonedElementsGroup(e){if(!e.root.is("rootElement"))return;if(e.is("element"))for(const t of e.getChildren())this._addToClonedElementsGroup(t);const t=e.id;if(!t)return;let i=this._cloneGroups.get(t);i||(i=new Set,this._cloneGroups.set(t,i)),i.add(e),e._clonesGroup=i}_removeFromClonedElementsGroup(e){if(e.is("element"))for(const t of e.getChildren())this._removeFromClonedElementsGroup(t);const t=e.id;if(!t)return;const i=this._cloneGroups.get(t);i&&i.delete(e)}};function Cs(e){let t=e.parent;for(;!Is(t);){if(!t)return;t=t.parent}return t}function As(e,t){return e.priorityt.priority)&&e.getIdentity()i instanceof e))throw new fe("view-writer-insert-invalid-node-type",t);i.is("$text")||Ss(i.getChildren(),t)}}function Is(e){return e&&(e.is("containerElement")||e.is("documentFragment"))}function Vs(e,t){const i=Cs(e.start),n=Cs(e.end);if(!i||!n||i!==n)throw new fe("view-writer-invalid-range-container",t)}const Os=e=>e.createTextNode(" "),Rs=e=>{const t=e.createElement("span");return t.dataset.ckeFiller="true",t.innerText=" ",t},Bs=e=>{const t=e.createElement("br");return t.dataset.ckeFiller="true",t},Ms="".repeat(7);function Fs(e){return"string"==typeof e?e.substr(0,7)===Ms:dt(e)&&e.data.substr(0,7)===Ms}function Ns(e){return 7==e.data.length&&Fs(e)}function Ls(e){const t="string"==typeof e?e:e.data;return Fs(e)?t.slice(7):t}function Ds(e,t){if(t.keyCode==Kt.arrowleft){const e=t.domTarget.ownerDocument.defaultView.getSelection();if(1==e.rangeCount&&e.getRangeAt(0).collapsed){const t=e.getRangeAt(0).startContainer,i=e.getRangeAt(0).startOffset;Fs(t)&&i<=7&&e.collapse(t,0)}}}const zs=De();var Hs=class extends zs{domDocuments=new Set;domConverter;markedAttributes=new Set;markedChildren=new Set;markedTexts=new Set;selection;_inlineFiller=null;_fakeSelectionContainer=null;constructor(e,t){super(),this.domConverter=e,this.selection=t,this.set("isFocused",!1),this.set("isSelecting",!1),this.set("isComposing",!1),Y.isBlink&&!Y.isAndroid&&this.on("change:isSelecting",()=>{this.isSelecting||this.render()})}markToSync(e,t){if("text"===e)this.domConverter.mapViewToDom(t.parent)&&this.markedTexts.add(t);else{if(!this.domConverter.mapViewToDom(t))return;if("attributes"===e)this.markedAttributes.add(t);else{if("children"!==e)throw new fe("view-renderer-unknown-type",this);this.markedChildren.add(t)}}}render(){if(this.isComposing&&!Y.isAndroid)return;let e=null;const t=!(Y.isBlink&&!Y.isAndroid)||!this.isSelecting;for(const e of this.markedChildren)this._updateChildrenMappings(e);t?(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=qn._createBefore(e.parent)));for(const e of this.markedAttributes)this._updateAttrs(e);for(const t of this.markedChildren)this._updateChildren(t,{inlineFillerPosition:e});for(const t of this.markedTexts)!this.markedChildren.has(t.parent)&&this.domConverter.mapViewToDom(t.parent)&&this._updateText(t,{inlineFillerPosition:e});if(t)if(e){const t=this.domConverter.viewPositionToDom(e),i=t.parent.ownerDocument;Fs(t.parent)?this._inlineFiller=t.parent:this._inlineFiller=$s(i,t.parent,t.offset)}else this._inlineFiller=null;this._updateFocus(),this._updateSelection(),this.domConverter._clearTemporaryCustomProperties(),this.markedTexts.clear(),this.markedAttributes.clear(),this.markedChildren.clear()}_updateChildrenMappings(e){const t=this.domConverter.mapViewToDom(e);if(!t)return;const i=Array.from(t.childNodes),n=Array.from(this.domConverter.viewChildrenToDom(e,{withChildren:!1})),s=this._diffNodeLists(i,n),o=this._findUpdateActions(s,i,n,Ws);if(-1!==o.indexOf("update")){const t={equal:0,insert:0,delete:0};for(const s of o)if("update"===s){const s=t.equal+t.insert,o=t.equal+t.delete,r=e.getChild(s);!r||r.is("uiElement")||r.is("rawElement")||this._updateElementMappings(r,i[o]),Rt(n[s]),t.equal++}else t[s]++}}_updateElementMappings(e,t){this.domConverter.unbindDomElement(t),this.domConverter.bindElements(t,e),this.markedChildren.add(e),this.markedAttributes.add(e)}_getInlineFillerPosition(){const e=this.selection.getFirstPosition();return e.parent.is("$text")?qn._createBefore(e.parent):e}_isSelectionInInlineFiller(){if(1!=this.selection.rangeCount||!this.selection.isCollapsed)return!1;const e=this.selection.getFirstPosition(),t=this.domConverter.viewPositionToDom(e);return!!(t&&dt(t.parent)&&Fs(t.parent))}_removeInlineFiller(){const e=this._inlineFiller;if(!Fs(e))throw new fe("view-renderer-filler-was-lost",this);Ns(e)?e.remove():e.data=e.data.substr(7),this._inlineFiller=null}_needsInlineFillerAtSelection(){if(1!=this.selection.rangeCount||!this.selection.isCollapsed)return!1;const e=this.selection.getFirstPosition(),t=e.parent,i=e.offset;if(!this.domConverter.mapViewToDom(t.root))return!1;if(!t.is("element"))return!1;if(!function(e){if("false"==e.getAttribute("contenteditable"))return!1;const t=e.findAncestor(e=>e.hasAttribute("contenteditable"));return!t||"true"==t.getAttribute("contenteditable")}(t))return!1;const n=e.nodeBefore,s=e.nodeAfter;return!(n instanceof vn||s instanceof vn)&&(!!(i!==t.getFillerOffset()||n&&n.is("element","br"))&&(!Y.isAndroid||!n&&!s))}_updateText(e,t){const i=this.domConverter.findCorrespondingDomText(e);let n=this.domConverter.viewToDom(e).data;const s=t.inlineFillerPosition;s&&s.parent==e.parent&&s.offset==e.index&&(n=Ms+n),this._updateTextNode(i,n)}_updateAttrs(e){const t=this.domConverter.mapViewToDom(e);if(t){for(const i of Array.from(t.attributes)){const n=i.name;e.hasAttribute(n)||this.domConverter.removeDomElementAttribute(t,n)}for(const i of e.getAttributeKeys())this.domConverter.setDomElementAttribute(t,i,e.getAttribute(i),e)}}_updateChildren(e,t){const i=this.domConverter.mapViewToDom(e);if(!i)return;if(Y.isAndroid){let e=null;for(const t of Array.from(i.childNodes)){if(e&&dt(e)&&dt(t)){i.normalize();break}e=t}}const n=t.inlineFillerPosition,s=i.childNodes,o=Array.from(this.domConverter.viewChildrenToDom(e,{bind:!0}));n&&n.parent===e&&$s(i.ownerDocument,o,n.offset);const r=this._diffNodeLists(s,o),a=this._findUpdateActions(r,s,o,Us);let l=0;const c=new Set;for(const e of a)"delete"===e?(c.add(s[l]),Rt(s[l])):"equal"!==e&&"update"!==e||l++;l=0;for(const e of a)"insert"===e?(Tt(i,l,o[l]),l++):"update"===e?(this._updateTextNode(s[l],o[l].data),l++):"equal"===e&&(this._markDescendantTextToSync(this.domConverter.domToView(o[l])),l++);for(const e of c)e.parentNode||this.domConverter.unbindDomElement(e)}_diffNodeLists(e,t){return e=function(e,t){const i=Array.from(e);if(0==i.length||!t)return i;i[i.length-1]==t&&i.pop();return i}(e,this._fakeSelectionContainer),ce(e,t,qs.bind(null,this.domConverter))}_findUpdateActions(e,t,i,n){if(-1===e.indexOf("insert")||-1===e.indexOf("delete"))return e;let s=[],o=[],r=[];const a={equal:0,insert:0,delete:0};for(const l of e)"insert"===l?r.push(i[a.equal+a.insert]):"delete"===l?o.push(t[a.equal+a.delete]):(s=s.concat(ce(o,r,n).map(e=>"equal"===e?"update":e)),s.push("equal"),o=[],r=[]),a[l]++;return s.concat(ce(o,r,n).map(e=>"equal"===e?"update":e))}_updateTextNode(e,t){const i=e.data;i!=t&&(Y.isAndroid&&this.isComposing&&i.replace(/\u00A0/g," ")==t.replace(/\u00A0/g," ")||this._updateTextNodeInternal(e,t))}_updateTextNodeInternal(e,t){const i=re(e.data,t);for(const t of i)"insert"===t.type?e.insertData(t.index,t.values.join("")):e.deleteData(t.index,t.howMany)}_markDescendantTextToSync(e){if(e)if(e.is("$text"))this.markedTexts.add(e);else if(e.is("element"))for(const t of e.getChildren())this._markDescendantTextToSync(t)}_updateSelection(){if(Y.isBlink&&!Y.isAndroid&&this.isSelecting&&!this.markedChildren.size)return;if(0===this.selection.rangeCount)return this._removeDomSelection(),void this._removeFakeSelection();const e=this.domConverter.mapViewToDom(this.selection.editableElement);this.isFocused&&e?this.selection.isFake?this._updateFakeSelection(e):this._fakeSelectionContainer&&this._fakeSelectionContainer.isConnected?(this._removeFakeSelection(),this._updateDomSelection(e)):this.isComposing&&Y.isAndroid||this._updateDomSelection(e):!this.selection.isFake&&this._fakeSelectionContainer&&this._fakeSelectionContainer.isConnected&&this._removeFakeSelection()}_updateFakeSelection(e){const t=e.ownerDocument;this._fakeSelectionContainer||(this._fakeSelectionContainer=function(e){const t=e.createElement("div");return t.className="ck-fake-selection-container",Object.assign(t.style,{position:"fixed",top:0,left:"-9999px",width:"42px"}),t.textContent=" ",t}(t));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 n=t.getSelection(),s=t.createRange();n.removeAllRanges(),s.selectNodeContents(i),n.addRange(s)}_updateDomSelection(e){const t=e.ownerDocument.defaultView.getSelection();if(!this._domSelectionNeedsUpdate(t))return;const i=this.domConverter.viewPositionToDom(this.selection.anchor),n=this.domConverter.viewPositionToDom(this.selection.focus);t.setBaseAndExtent(i.parent,i.offset,n.parent,n.offset),Y.isGecko&&function(e,t){let i=e.parent,n=e.offset;dt(i)&&Ns(i)&&(n=At(i)+1,i=i.parentNode);if(i.nodeType!=Node.ELEMENT_NODE||n!=i.childNodes.length-1)return;const s=i.childNodes[n];s&&"BR"==s.tagName&&t.addRange(t.getRangeAt(0))}(n,t)}_domSelectionNeedsUpdate(e){if(!this.domConverter.isDomSelectionCorrect(e))return!0;const t=e&&this.domConverter.domSelectionToView(e);return(!t||!this.selection.isEqual(t))&&!(!this.selection.isCollapsed&&this.selection.isSimilar(t))}_fakeSelectionNeedsUpdate(e){const t=this._fakeSelectionContainer,i=e.ownerDocument.getSelection();return!t||t.parentElement!==e||(i.anchorNode!==t&&!t.contains(i.anchorNode)||t.textContent!==this.selection.fakeSelectionLabel)}_removeDomSelection(){for(const e of this.domDocuments){const t=e.getSelection();if(t.rangeCount){const i=e.activeElement,n=this.domConverter.mapDomToView(i);i&&n&&t.removeAllRanges()}}}_removeFakeSelection(){const e=this._fakeSelectionContainer;e&&e.remove()}_updateFocus(){if(this.isFocused){const e=this.selection.editableElement;e&&this.domConverter.focus(e)}}};function $s(e,t,i){const n=t instanceof Array?t:t.childNodes,s=n[i];if(dt(s))return s.data=Ms+s.data,s;{const s=e.createTextNode(Ms);return Array.isArray(t)?n.splice(i,0,s):Tt(t,i,s),s}}function Ws(e,t){return Ze(e)&&Ze(t)&&!dt(e)&&!dt(t)&&!Et(e)&&!Et(t)&&e.tagName.toLowerCase()===t.tagName.toLowerCase()}function Us(e,t){return Ze(e)&&Ze(t)&&dt(e)&&dt(t)}function qs(e,t,i){return t===i||(dt(t)&&dt(i)?t.data===i.data:!(!e.isBlockFiller(t)||!e.isBlockFiller(i)))}const js=Bs(G.document),Ks=Os(G.document),Gs=Rs(G.document),Js="data-ck-unsafe-attribute-",Qs="data-ck-unsafe-element";var Ys=class{document;renderingMode;blockFillerMode;preElements;blockElements;inlineObjectElements;unsafeElements;_domDocument;_domToViewMapping=new WeakMap;_viewToDomMapping=new WeakMap;_fakeSelectionMapping=new WeakMap;_rawContentElementMatcher=new En;_inlineObjectElementMatcher=new En;_elementsWithTemporaryCustomProperties=new Set;constructor(e,{blockFillerMode:t,renderingMode:i="editing"}={}){this.document=e,this.renderingMode=i,this.blockFillerMode=t||("editing"===i?"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="editing"===this.renderingMode?G.document:G.document.implementation.createHTMLDocument("")}get domDocument(){return this._domDocument}bindFakeSelection(e,t){this._fakeSelectionMapping.set(e,new Jn(t))}fakeSelectionToView(e){return this._fakeSelectionMapping.get(e)}bindElements(e,t){this._domToViewMapping.set(e,t),this._viewToDomMapping.set(t,e)}unbindDomElement(e){const t=this._domToViewMapping.get(e);if(t){this._domToViewMapping.delete(e),this._viewToDomMapping.delete(t);for(const t of e.children)this.unbindDomElement(t)}}bindDocumentFragments(e,t){this._domToViewMapping.set(e,t),this._viewToDomMapping.set(t,e)}shouldRenderAttribute(e,t,i){return"data"===this.renderingMode||!(e=e.toLowerCase()).startsWith("on")&&("srcdoc"!==e&&("img"===i&&("src"===e||"srcset"===e)||("source"===i&&"srcset"===e||!t.replace(/\s+/g,"").match(/^(javascript:|data:(image\/svg|text\/x?html))/i))))}setContentOf(e,t){if("data"===this.renderingMode)return void(e.innerHTML=t);const i=(new DOMParser).parseFromString(t,"text/html"),n=i.createDocumentFragment(),s=i.body.childNodes;for(;s.length>0;)n.appendChild(s[0]);const o=i.createTreeWalker(n,NodeFilter.SHOW_ELEMENT),r=[];let a;for(;a=o.nextNode();)r.push(a);for(const e of r){for(const t of e.getAttributeNames())this.setDomElementAttribute(e,t,e.getAttribute(t));const t=e.tagName.toLowerCase();this._shouldRenameElement(t)&&(so(t),e.replaceWith(this._createReplacementDomElement(t,e)))}for(;e.firstChild;)e.firstChild.remove();e.append(n)}viewToDom(e,t={}){if(e.is("$text")){const t=this._processDataFromViewText(e);return this._domDocument.createTextNode(t)}{const i=e;if(this.mapViewToDom(i)){if(!i.getCustomProperty("editingPipeline:doNotReuseOnce"))return this.mapViewToDom(i);this._elementsWithTemporaryCustomProperties.add(i)}let n;if(i.is("documentFragment"))n=this._domDocument.createDocumentFragment(),t.bind&&this.bindDocumentFragments(n,i);else{if(i.is("uiElement"))return n="$comment"===i.name?this._domDocument.createComment(i.getCustomProperty("$rawContent")):i.render(this._domDocument,this),t.bind&&this.bindElements(n,i),n;this._shouldRenameElement(i.name)?(so(i.name),n=this._createReplacementDomElement(i.name)):n=i.hasAttribute("xmlns")?this._domDocument.createElementNS(i.getAttribute("xmlns"),i.name):this._domDocument.createElement(i.name),i.is("rawElement")&&i.render(n,this),t.bind&&this.bindElements(n,i);for(const e of i.getAttributeKeys())this.setDomElementAttribute(n,e,i.getAttribute(e),i)}if(!1!==t.withChildren)for(const e of this.viewChildrenToDom(i,t))n instanceof HTMLTemplateElement?n.content.appendChild(e):n.appendChild(e);return n}}setDomElementAttribute(e,t,i,n){const s=this.shouldRenderAttribute(t,i,e.tagName.toLowerCase())||n&&n.shouldRenderUnsafeAttribute(t);s||pe("domconverter-unsafe-attribute-detected",{domElement:e,key:t,value:i}),xt(t)?(e.hasAttribute(t)&&!s?e.removeAttribute(t):e.hasAttribute(Js+t)&&s&&e.removeAttribute(Js+t),e.setAttribute(s?t:Js+t,i)):pe("domconverter-invalid-attribute-detected",{domElement:e,key:t,value:i})}removeDomElementAttribute(e,t){t!=Qs&&(e.removeAttribute(t),e.removeAttribute(Js+t))}*viewChildrenToDom(e,t={}){const i=e.getFillerOffset&&e.getFillerOffset();let n=0;for(const s of e.getChildren()){i===n&&(yield this._getBlockFiller());const e=s.is("element")&&!!s.getCustomProperty("dataPipeline:transparentRendering")&&!ai(s.getAttributes());if(e&&"data"==this.renderingMode)if(s.is("rawElement")){const e=this._domDocument.createElement(s.name);s.render(e,this),yield*[...e.childNodes]}else yield*this.viewChildrenToDom(s,t);else e&&pe("domconverter-transparent-rendering-unsupported-in-editing-pipeline",{viewElement:s}),yield this.viewToDom(s,t);n++}i===n&&(yield this._getBlockFiller())}viewRangeToDom(e){const t=this.viewPositionToDom(e.start),i=this.viewPositionToDom(e.end),n=this._domDocument.createRange();return n.setStart(t.parent,t.offset),n.setEnd(i.parent,i.offset),n}viewPositionToDom(e){const t=e.parent;if(t.is("$text")){const i=this.findCorrespondingDomText(t);if(!i)return null;let n=e.offset;return Fs(i)&&(n+=7),i.data&&n>i.data.length&&(n=i.data.length),{parent:i,offset:n}}{let i,n,s;if(0===e.offset){if(i=this.mapViewToDom(t),!i)return null;s=i.childNodes[0]}else{const t=e.nodeBefore;if(n=t.is("$text")?this.findCorrespondingDomText(t):this.mapViewToDom(t),!n)return null;i=n.parentNode,s=n.nextSibling}if(dt(s)&&Fs(s))return{parent:s,offset:7};return{parent:i,offset:n?At(n)+1:0}}}domToView(e,t={}){const i=[],n=this._domToView(e,t,i),s=n.next().value;return s?(n.next(),this._processDomInlineNodes(null,i,t),"br"==this.blockFillerMode&&io(s)||s.is("$text")&&0==s.data.length?null:s):null}*domChildrenToView(e,t={},i=[]){let n;n=e instanceof HTMLTemplateElement?[...e.content.childNodes]:[...e.childNodes];for(let s=0;s{const{scrollLeft:t,scrollTop:i}=e;s.push([t,i])}),t.focus({preventScroll:!0}),Xs(t,e=>{const[t,i]=s.shift();e.scrollLeft=t,e.scrollTop=i}),G.window.scrollTo(i,n)}_clearDomSelection(){const e=this.mapViewToDom(this.document.selection.editableElement);if(!e)return;const t=e.ownerDocument.defaultView.getSelection(),i=this.domSelectionToView(t);i&&i.rangeCount>0&&t.removeAllRanges()}isElement(e){return e&&e.nodeType==Node.ELEMENT_NODE}isDocumentFragment(e){return e&&e.nodeType==Node.DOCUMENT_FRAGMENT_NODE}isBlockFiller(e){return"br"==this.blockFillerMode?e.isEqualNode(js):!!no(e,this.blockElements)||(e.isEqualNode(Gs)||function(e,t){return e.isEqualNode(Ks)&&Zs(e,t)&&1===e.parentNode.childNodes.length}(e,this.blockElements))}isDomSelectionBackward(e){if(e.isCollapsed)return!1;const t=this._domDocument.createRange();try{t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset)}catch{return!1}const i=t.collapsed;return t.detach(),i}getHostViewElement(e){const t=rt(e);for(t.pop();t.length;){const e=t.pop(),i=this._domToViewMapping.get(e);if(i&&(i.is("uiElement")||i.is("rawElement")))return i}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 Os(this._domDocument);case"markedNbsp":return Rs(this._domDocument);case"br":return Bs(this._domDocument)}}_isDomSelectionPositionCorrect(e,t){if(dt(e)&&Fs(e)&&t<7)return!1;if(this.isElement(e)&&Fs(e.childNodes[t]))return!1;const i=this.mapDomToView(e);return!i||!i.is("uiElement")&&!i.is("rawElement")}*_domToView(e,t,i){if("br"!=this.blockFillerMode&&no(e,this.blockElements))return null;const n=this.getHostViewElement(e);if(n)return n;if(Et(e)&&t.skipComments)return null;if(dt(e)){if(Ns(e))return null;{const t=e.data;if(""===t)return null;const n=new vn(this.document,t);return i.push(n),n}}{let n=this.mapDomToView(e);if(n)return this._isInlineObjectElement(n)&&i.push(n),n;if(this.isDocumentFragment(e))n=new ys(this.document),t.bind&&this.bindDocumentFragments(e,n);else{n=this._createViewElement(e,t),t.bind&&this.bindElements(e,n);const s=e.attributes;if(s)for(let e=s.length,t=0;t0?t[e-1]:null,l=e+1e.is("element")&&t.includes(e.name))}(e,this.preElements))return!0;for(const t of e.getAncestors({parentFirst:!0}))if(t.is("element")&&t.hasStyle("white-space")&&"inherit"!==t.getStyle("white-space"))return["pre","pre-wrap","break-spaces"].includes(t.getStyle("white-space"));return!1}_getTouchingInlineViewNode(e,t){const i=new Un({startPosition:t?qn._createAfter(e):qn._createBefore(e),direction:t?"forward":"backward"});for(const{item:e}of i){if(e.is("$textProxy"))return e;if(e.is("element")&&e.getCustomProperty("dataPipeline:transparentRendering"))continue;if(e.is("element","br"))return null;if(this._isInlineObjectElement(e))return e;if(e.is("containerElement")||this._isBlockViewElement(e))return null}return null}_isBlockDomElement(e){return this.isElement(e)&&this.blockElements.includes(e.tagName.toLowerCase())}_isBlockViewElement(e){return e.is("element")&&this.blockElements.includes(e.name)}_isInlineObjectElement(e){return!!e.is("element")&&("br"==e.name||this.inlineObjectElements.includes(e.name)||!!this._inlineObjectElementMatcher.match(e))}_createViewElement(e,t){if(Et(e))return new fs(this.document,"$comment");const i=t.keepOriginalCase?e.tagName:e.tagName.toLowerCase();return new Mn(this.document,i)}_isViewElementWithRawContent(e,t){return!1!==t.withChildren&&e.is("element")&&!!this._rawContentElementMatcher.match(e)}_shouldRenameElement(e){const t=e.toLowerCase();return"editing"===this.renderingMode&&this.unsafeElements.includes(t)}_createReplacementDomElement(e,t){const i=this._domDocument.createElement("span");if(i.setAttribute(Qs,e),t){for(;t.firstChild;)i.appendChild(t.firstChild);for(const e of t.getAttributeNames())i.setAttribute(e,t.getAttribute(e))}return i}};function Xs(e,t){let i=e;for(;i;)t(i),i=i.parentElement}function Zs(e,t){const i=e.parentNode;return!!i&&!!i.tagName&&t.includes(i.tagName.toLowerCase())}function eo(e,t,i){return" "==t&&e&&e.is("element")&&1==e.childCount&&i.includes(e.name)}function to(e,t){return" "==t&&e&&e.is("element","span")&&1==e.childCount&&e.hasAttribute("data-cke-filler")}function io(e){return e.is("element","br")&&e.hasAttribute("data-cke-filler")}function no(e,t){return"BR"===e.tagName&&Zs(e,t)&&1===e.parentNode.childNodes.length}function so(e){"script"===e&&pe("domconverter-unsafe-script-element-detected"),"style"===e&&pe("domconverter-unsafe-style-element-detected")}const oo=nt();var ro=class extends oo{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&&3===e.nodeType&&(e=e.parentNode),!(!e||1!==e.nodeType)&&e.matches("[data-cke-ignore-events], [data-cke-ignore-events] *")}},ao=class{view;document;domEvent;domTarget;constructor(e,t,i){this.view=e,this.document=e.document,this.domEvent=t,this.domTarget=t.target,Di(this,i)}get target(){return this.view.domConverter.mapDomToView(this.domTarget)}preventDefault(){this.domEvent.preventDefault()}stopPropagation(){this.domEvent.stopPropagation()}},lo=class extends ro{useCapture=!1;usePassive=!1;observe(e){("string"==typeof this.domEventType?[this.domEventType]:this.domEventType).forEach(t=>{this.listenTo(e,t,(e,t)=>{this.isEnabled&&!this.checkShouldIgnoreEventFromTarget(t.target)&&this.onDomEvent(t)},{useCapture:this.useCapture,usePassive:this.usePassive})})}stopObserving(e){this.stopListening(e)}fire(e,t,i){this.isEnabled&&this.document.fire(e,new ao(this.view,t,i))}},co=class extends lo{domEventType=["keydown","keyup"];onDomEvent(e){const t={keyCode:e.keyCode,altKey:e.altKey,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,metaKey:e.metaKey,get keystroke(){return Jt(this)}};this.fire(e.type,e,t)}},uo=class extends ro{_fireSelectionChangeDoneDebounced;constructor(e){super(e),this._fireSelectionChangeDoneDebounced=Ii(e=>{this.document.fire("selectionChangeDone",e)},200)}observe(){const e=this.document;e.on("arrowKey",(t,i)=>{e.selection.isFake&&this.isEnabled&&i.preventDefault()},{context:"$capture"}),e.on("arrowKey",(t,i)=>{e.selection.isFake&&this.isEnabled&&this._handleSelectionMove(i.keyCode)},{priority:"lowest"})}stopObserving(){}destroy(){super.destroy(),this._fireSelectionChangeDoneDebounced.cancel()}_handleSelectionMove(e){const t=this.document.selection,i=new Jn(t.getRanges(),{backward:t.isBackward,fake:!1});e!=Kt.arrowleft&&e!=Kt.arrowup||i.setTo(i.getFirstPosition()),e!=Kt.arrowright&&e!=Kt.arrowdown||i.setTo(i.getLastPosition());const n={oldSelection:t,newSelection:i,domSelection:null};this.document.fire("selectionChange",n),this._fireSelectionChangeDoneDebounced(n)}},ho=class extends ro{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 e of this._domElements)this._mutationObserver.observe(e,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(0===e.length)return;const t=this.domConverter,i=new Set,n=new Set;for(const i of e){const e=t.mapDomToView(i.target);e&&(e.is("uiElement")||e.is("rawElement")||"childList"!==i.type||this._isBogusBrMutation(i)||n.add(e))}for(const s of e){const e=t.mapDomToView(s.target);if((!e||!e.is("uiElement")&&!e.is("rawElement"))&&"characterData"===s.type){const e=t.findCorrespondingViewText(s.target);e&&!n.has(e.parent)?i.add(e):!e&&Fs(s.target)&&n.add(t.mapDomToView(s.target.parentNode))}}const s=[];for(const e of i)s.push({type:"text",node:e});for(const e of n){const i=t.mapViewToDom(e);rn(Array.from(e.getChildren()),Array.from(t.domChildrenToView(i,{withChildren:!1})),mo)||s.push({type:"children",node:e})}s.length&&this.document.fire("mutations",{mutations:s})}_isBogusBrMutation(e){let t=null;return null===e.nextSibling&&0===e.removedNodes.length&&1==e.addedNodes.length&&(t=this.domConverter.domToView(e.addedNodes[0],{withChildren:!1})),t&&t.is("element","br")}};function mo(e,t){if(!Array.isArray(e))return e===t||!(!e.is("$text")||!t.is("$text"))&&e.data===t.data}var go=class extends lo{_renderTimeoutId=null;_isFocusChanging=!1;domEventType=["focus","blur"];constructor(e){super(e),this.useCapture=!0;const t=this.document;t.on("focus",()=>this._handleFocus()),t.on("blur",(e,t)=>this._handleBlur(t)),t.on("beforeinput",()=>{t.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 t=this.document.selection.editableElement;null!==t&&t!==e.target||(this.document.isFocused=!1,this._isFocusChanging=!1,this.view.change(()=>{}))}_clearTimeout(){this._renderTimeoutId&&(clearTimeout(this._renderTimeoutId),this._renderTimeoutId=null)}},fo=class extends ro{mutationObserver;focusObserver;selection;domConverter;_documents=new WeakSet;_fireSelectionChangeDoneDebounced;_clearInfiniteLoopInterval;_documentIsSelectingInactivityTimeoutDebounced;_loopbackCounter=0;_pendingSelectionChange=new Set;constructor(e){super(e),this.mutationObserver=e.getObserver(ho),this.focusObserver=e.getObserver(go),this.selection=this.document.selection,this.domConverter=e.domConverter,this._fireSelectionChangeDoneDebounced=Ii(e=>{this.document.fire("selectionChangeDone",e)},200),this._clearInfiniteLoopInterval=setInterval(()=>this._clearInfiniteLoop(),1e3),this._documentIsSelectingInactivityTimeoutDebounced=Ii(()=>this.document.isSelecting=!1,5e3),this.view.document.on("change:isFocused",(e,t,i)=>{if(i&&this._pendingSelectionChange.size){for(const e of Array.from(this._pendingSelectionChange))this._handleSelectionChange(e);this._pendingSelectionChange.clear()}})}observe(e){const t=e.ownerDocument,i=()=>{this.document.isSelecting&&(this._handleSelectionChange(t),this.document.isSelecting=!1,this._documentIsSelectingInactivityTimeoutDebounced.cancel())};this.listenTo(e,"selectstart",()=>{this.document.isSelecting=!0,this._documentIsSelectingInactivityTimeoutDebounced()},{priority:"highest"}),this.listenTo(e,"keydown",i,{priority:"highest",useCapture:!0}),this.listenTo(e,"keyup",i,{priority:"highest",useCapture:!0}),this._documents.has(t)||(this.listenTo(t,"mouseup",i,{priority:"highest",useCapture:!0}),this.listenTo(t,"selectionchange",()=>{this.document.isComposing&&!Y.isAndroid||(this._handleSelectionChange(t),this._documentIsSelectingInactivityTimeoutDebounced())}),this.listenTo(this.view.document,"compositionstart",()=>{this._handleSelectionChange(t)},{priority:"lowest"}),this._documents.add(t))}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 t=e.defaultView.getSelection();if(this.checkShouldIgnoreEventFromTarget(t.anchorNode))return;this.mutationObserver.flush();const i=this.domConverter.domSelectionToView(t);var n;if(0!=i.rangeCount)if(this.view.hasDomSelection=!0,this.focusObserver.flush(),this.view.document.isFocused||this.view.document.isReadOnly){if(this._pendingSelectionChange.delete(e),!this.selection.isEqual(i)||!this.domConverter.isDomSelectionCorrect(t))if(++this._loopbackCounter>60)this._reportInfiniteLoop();else if(n=i,Array.from(n.getRanges()).flatMap(e=>[e.start.root,e.end.root]).every(e=>e&&e.is("rootElement")))if(this.selection.isSimilar(i))this.view.forceRender();else{const e={oldSelection:this.selection,newSelection:i,domSelection:t};this.document.fire("selectionChange",e),this._fireSelectionChangeDoneDebounced(e)}else this.view.forceRender()}else this._pendingSelectionChange.add(e);else this.view.hasDomSelection=!1}_clearInfiniteLoop(){this._loopbackCounter=0}};var po=class extends lo{domEventType=["compositionstart","compositionupdate","compositionend"];constructor(e){super(e);const t=this.document;t.on("compositionstart",()=>{t.isComposing=!0}),t.on("compositionend",()=>{t.isComposing=!1})}onDomEvent(e){this.fire(e.type,e,{data:e.data})}},bo=class{_files;_native;constructor(e,t={}){this._files=t.cacheFiles?wo(e):null,this._native=e}get files(){return this._files||(this._files=wo(this._native)),this._files}get types(){return this._native.types}getData(e){return this._native.getData(e)}setData(e,t){this._native.setData(e,t)}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,t,i){this._native.setDragImage(e,t,i)}get isCanceled(){return"none"==this._native.dropEffect||!!this._native.mozUserCancelled}};function wo(e){const t=Array.from(e.files||[]),i=Array.from(e.items||[]);return t.length?t:i.filter(e=>"file"===e.kind).map(e=>e.getAsFile())}var _o=class extends lo{domEventType="beforeinput";onDomEvent(e){const t=e.getTargetRanges(),i=this.view,n=i.document;let s=null,o=null,r=[];if(e.dataTransfer&&(s=new bo(e.dataTransfer)),null!==e.data?o=e.data:s&&(o=s.getData("text/plain")),n.selection.isFake)r=Array.from(n.selection.getRanges()),e.preventDefault();else if(t.length)r=t.map(t=>{let n=i.domConverter.domPositionToView(t.startContainer,t.startOffset);const s=i.domConverter.domPositionToView(t.endContainer,t.endOffset);if(n&&Fs(t.startContainer)&&t.startOffset<7){e.preventDefault();let i=7-t.startOffset;n=n.getLastMatchingPosition(e=>!(!e.item.is("attributeElement")&&!e.item.is("uiElement"))||!(!e.item.is("$textProxy")||!i--),{direction:"backward",singleCharacters:!0})}return function(e,t){for(;e.parentNode;){if(dt(e)){if(t!=e.data.length)return!1}else if(t!=e.childNodes.length)return!1;if((t=At(e)+1)<(e=e.parentNode).childNodes.length&&Fs(e.childNodes[t]))return!0}return!1}(t.endContainer,t.endOffset)&&e.preventDefault(),n?i.createRange(n,s):s?i.createRange(s):void 0}).filter(e=>!!e);else if(Y.isAndroid){const t=e.target.ownerDocument.defaultView.getSelection();r=Array.from(i.domConverter.domSelectionToView(t).getRanges())}if(Y.isAndroid&&"insertCompositionText"==e.inputType&&o&&o.endsWith("\n"))this.fire(e.type,e,{inputType:"insertParagraph",targetRanges:[i.createRange(r[0].end)]});else{if(["insertText","insertReplacementText"].includes(e.inputType)&&o&&o.includes("\n")){const t=o.split(/\n{1,2}/g);let i=r;e.preventDefault();for(let o=0;o{if(this.isEnabled&&((i=t.keyCode)==Kt.arrowright||i==Kt.arrowleft||i==Kt.arrowup||i==Kt.arrowdown)){const i=new Xn(this.document,"arrowKey",this.document.selection.getFirstRange());this.document.fire(i,t),i.stop.called&&e.stop()}var i})}observe(){}stopObserving(){}},yo=class extends ro{constructor(e){super(e);const t=this.document;t.on("keydown",(e,i)=>{if(!this.isEnabled||i.keyCode!=Kt.tab||i.ctrlKey)return;const n=new Xn(t,"tab",t.selection.getFirstRange());t.fire(n,i),n.stop.called&&e.stop()})}observe(){}stopObserving(){}};const ko=De();var Co=class extends ko{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 cs(e),this.domConverter=new Ys(this.document),this.set("isRenderingInProgress",!1),this.set("hasDomSelection",!1),this._renderer=new Hs(this.domConverter,this.document.selection),this._renderer.bind("isFocused","isSelecting","isComposing").to(this.document,"isFocused","isSelecting","isComposing"),this._writer=new ks(this.document),this.addObserver(ho),this.addObserver(go),this.addObserver(fo),this.addObserver(co),this.addObserver(uo),this.addObserver(po),this.addObserver(vo),this.addObserver(_o),this.addObserver(yo),this.document.on("arrowKey",Ds,{priority:"low"}),ps(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}),Y.isiOS&&this.listenTo(this.document,"blur",(e,t)=>{this.domConverter.mapDomToView(t.domEvent.relatedTarget)||this.domConverter._clearDomSelection()}),this.listenTo(this.document,"mutations",(e,{mutations:t})=>{t.forEach(e=>this._renderer.markToSync(e.type,e.node))},{priority:"low"}),this.listenTo(this.document,"mutations",()=>{this.forceRender()},{priority:"lowest"})}attachDomRoot(e,t="main"){const i=this.document.getRoot(t);i._name=e.tagName.toLowerCase();const n={};for(const{name:t,value:s}of Array.from(e.attributes))n[t]=s,"class"===t?this._writer.addClass(s.split(" "),i):i.hasAttribute(t)||this._writer.setAttribute(t,s,i);this._initialDomRootAttributes.set(e,n);const s=()=>{this._writer.setAttribute("contenteditable",(!i.isReadOnly).toString(),i),i.isReadOnly?this._writer.addClass("ck-read-only",i):this._writer.removeClass("ck-read-only",i)};s(),this.domRoots.set(t,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",(e,t)=>this._renderer.markToSync("children",t)),i.on("change:attributes",(e,t)=>this._renderer.markToSync("attributes",t)),i.on("change:text",(e,t)=>this._renderer.markToSync("text",t)),i.on("change:isReadOnly",()=>this.change(s)),i.on("change",()=>{this._hasChangedSinceTheLastRendering=!0});for(const i of this._observers.values())i.observe(e,t)}detachDomRoot(e){const t=this.domRoots.get(e);Array.from(t.attributes).forEach(({name:e})=>t.removeAttribute(e));const i=this._initialDomRootAttributes.get(t);for(const e in i)t.setAttribute(e,i[e]);this.domRoots.delete(e),this.domConverter.unbindDomElement(t);for(const e of this._observers.values())e.stopObserving(t)}getDomRoot(e="main"){return this.domRoots.get(e)}addObserver(e){let t=this._observers.get(e);if(t)return t;t=new e(this),this._observers.set(e,t);for(const[e,i]of this.domRoots)t.observe(i,e);return t.enable(),t}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:t,viewportOffset:i=20,ancestorOffset:n=20}={}){const s=this.document.selection.getFirstRange();if(!s)return;const o=L({alignToTop:e,forceScroll:t,viewportOffset:i,ancestorOffset:n});"number"==typeof i&&(i={top:i,bottom:i,left:i,right:i});const r={target:this.domConverter.viewRangeToDom(s),viewportOffset:i,ancestorOffset:n,alignToTop:e,forceScroll:t};this.fire("scrollToTheSelection",r,o),function({target:e,viewportOffset:t=0,ancestorOffset:i=0,alignToTop:n,forceScroll:s}){const o=Ht(e);let r=o,a=null;for(t=function(e){return"number"==typeof e?{top:e,bottom:e,left:e,right:e}:e}(t);r;){let l;l=$t(r==o?e:a),Ft({parent:l,getRect:()=>Wt(e,r),alignToTop:n,ancestorOffset:i,forceScroll:s});let c=Wt(e,r);const d=Wt(l,r);if(c.height>d.height){const e=c.getIntersection(d);e&&(c=e)}if(Mt({window:r,rect:c,viewportOffset:t,alignToTop:n,forceScroll:s}),r.parent!=r){if(a=r.frameElement,r=r.parent,!a)return}else r=null}}(r)}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 fe("cannot-change-view-tree",this);try{if(this._ongoingChange)return e(this._writer);this._ongoingChange=!0;const t=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")),t}catch(e){fe.rethrowUnexpectedError(e,this)}}forceRender(){this._hasChangedSinceTheLastRendering=!0,this.getObserver(go).flush(),this.change(()=>{})}destroy(){for(const e of this._observers.values())e.destroy();this.document.destroy(),this.stopListening()}createPositionAt(e,t){return qn._createAt(e,t)}createPositionAfter(e){return qn._createAfter(e)}createPositionBefore(e){return qn._createBefore(e)}createRange(e,t){return new jn(e,t)}createRangeOn(e){return jn._createOn(e)}createRangeIn(e){return jn._createIn(e)}createSelection(...e){return new Jn(...e)}_disableRendering(e){this._renderingDisabled=e,0==e&&this.change(()=>{})}_render(){this.isRenderingInProgress=!0,this.disableObservers(),this._renderer.render(),this.enableObservers(),this.isRenderingInProgress=!1}},Ao=class{is(){throw new Error("is() method is abstract")}},To=class extends Ao{textNode;data;offsetInText;constructor(e,t,i){if(super(),this.textNode=e,t<0||t>e.offsetSize)throw new fe("model-textproxy-wrong-offsetintext",this);if(i<0||t+i>e.offsetSize)throw new fe("model-textproxy-wrong-length",this);this.data=e.data.substring(t,t+i),this.offsetInText=t}get startOffset(){return null!==this.textNode.startOffset?this.textNode.startOffset+this.offsetInText:null}get offsetSize(){return this.data.length}get endOffset(){return null!==this.startOffset?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 t=[];let i=e.includeSelf?this:this.parent;for(;i;)t[e.parentFirst?"push":"unshift"](i),i=i.parent;return t}hasAttribute(e){return this.textNode.hasAttribute(e)}getAttribute(e){return this.textNode.getAttribute(e)}getAttributes(){return this.textNode.getAttributes()}getAttributeKeys(){return this.textNode.getAttributeKeys()}};To.prototype.is=function(e){return"$textProxy"===e||"model:$textProxy"===e||"textProxy"===e||"model:textProxy"===e};var Eo=class{direction;boundaries;singleCharacters;shallow;ignoreElementEnd;_position;_boundaryStartParent;_boundaryEndParent;_visitedParent;constructor(e){if(!e||!e.boundaries&&!e.startPosition)throw new fe("model-tree-walker-no-start-position",null);const t=e.direction||"forward";if("forward"!=t&&"backward"!=t)throw new fe("model-tree-walker-unknown-direction",e,{direction:t});this.direction=t,this.boundaries=e.boundaries||null,e.startPosition?this._position=e.startPosition.clone():this._position=Po._createAt(this.boundaries["backward"==this.direction?"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 t,i,n,s;do{n=this.position,s=this._visitedParent,({done:t,value:i}=this.next())}while(!t&&e(i));t||(this._position=n,this._visitedParent=s)}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"forward"==this.direction?this._next():this._previous()}_next(){const e=this.position,t=this.position.clone(),i=this._visitedParent;if(null===i.parent&&t.offset===i.maxOffset)return{done:!0,value:void 0};if(i===this._boundaryEndParent&&t.offset==this.boundaries.end.offset)return{done:!0,value:void 0};const n=So(t,i),s=n||Io(t,i,n);if(s&&s.is("model:element")){if(this.shallow){if(this.boundaries&&this.boundaries.end.isBefore(t))return{done:!0,value:void 0};t.offset++}else t.path.push(0),this._visitedParent=s;return this._position=t,xo("elementStart",s,e,t,1)}if(s&&s.is("model:$text")){let n;if(this.singleCharacters)n=1;else{let e=s.endOffset;this._boundaryEndParent==i&&this.boundaries.end.offsete&&(e=this.boundaries.start.offset),n=t.offset-e}const s=new To(o,t.offset-o.startOffset-n,n);return t.offset-=n,this._position=t,xo("text",s,e,t,n)}return t.path.pop(),this._position=t,this._visitedParent=i.parent,xo("elementStart",i,e,t,1)}};function xo(e,t,i,n,s){return{done:!1,value:{type:e,item:t,previousPosition:i,nextPosition:n,length:s}}}var Po=class e extends Ao{root;path;stickiness;constructor(e,t,i="toNone"){if(super(),!e.is("element")&&!e.is("documentFragment"))throw new fe("model-position-root-invalid",e);if(!Array.isArray(t)||0===t.length)throw new fe("model-position-path-incorrect-format",e,{path:t});e.is("rootElement")?t=t.slice():(t=[...e.getPath(),...t],e=e.root),this.root=e,this.path=t,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 t=0;t1)return!1;if(1===t)return Oo(e,this,i);if(-1===t)return Oo(this,e,i)}return this.path.length===e.path.length||(this.path.length>e.path.length?Ro(this.path,t):Ro(e.path,t))}hasSameParentAs(e){return this.root===e.root&&"same"==Ke(this.getParentPath(),e.getParentPath())}getTransformedByOperation(t){let i;switch(t.type){case"insert":i=this._getTransformedByInsertOperation(t);break;case"move":case"remove":case"reinsert":i=this._getTransformedByMoveOperation(t);break;case"split":i=this._getTransformedBySplitOperation(t);break;case"merge":i=this._getTransformedByMergeOperation(t);break;case"detach":i=this._getTransformedByDetachOperation(t);break;default:i=e._createAt(this)}return i}_getTransformedByDetachOperation(t){return this._getTransformedByDeletion(t.sourcePosition,t.howMany)||e._createAt(t.sourcePosition)}_getTransformedByInsertOperation(e){return this._getTransformedByInsertion(e.position,e.howMany)}_getTransformedByMoveOperation(e){return this._getTransformedByMove(e.sourcePosition,e.targetPosition,e.howMany)}_getTransformedBySplitOperation(e){const t=e.movedRange;return t.containsPosition(this)||t.start.isEqual(this)&&"toNext"==this.stickiness?this._getCombined(e.splitPosition,e.moveTargetPosition):e.graveyardPosition?this._getTransformedByMove(e.graveyardPosition,e.insertionPosition,1):this._getTransformedByInsertion(e.insertionPosition,1)}_getTransformedByMergeOperation(t){const i=t.movedRange;let n;return i.containsPosition(this)||i.start.isEqual(this)?(n=this._getCombined(t.sourcePosition,t.targetPosition),t.sourcePosition.isBefore(t.targetPosition)&&(n=n._getTransformedByDeletion(t.deletionPosition,1))):n=this.isEqual(t.deletionPosition)?e._createAt(t.deletionPosition):this._getTransformedByMove(t.deletionPosition,t.graveyardPosition,1),n}_getTransformedByDeletion(t,i){const n=e._createAt(this);if(this.root!=t.root)return n;if("same"==Ke(t.getParentPath(),this.getParentPath())){if(t.offsetthis.offset)return null;n.offset-=i}}else if("prefix"==Ke(t.getParentPath(),this.getParentPath())){const e=t.path.length-1;if(t.offset<=this.path[e]){if(t.offset+i>this.path[e])return null;n.path[e]-=i}}return n}_getTransformedByInsertion(t,i){const n=e._createAt(this);if(this.root!=t.root)return n;if("same"==Ke(t.getParentPath(),this.getParentPath()))(t.offset=t;){if(e.path[n]+s!==i.maxOffset)return!1;s=1,n--,i=i.parent}return!0}(e,i+1))}function Ro(e,t){for(;ti+1;){const i=s.maxOffset-n.offset;0!==i&&t.push(new e(n,n.getShiftedBy(i))),n.path=n.path.slice(0,-1),n.offset++,s=s.parent}for(;n.path.length<=this.end.path.length;){const i=this.end.path[n.path.length-1],s=i-n.offset;0!==s&&t.push(new e(n,n.getShiftedBy(s))),n.offset=i,n.path.push(0)}return t}getWalker(e={}){return e.boundaries=this,new Eo(e)}*getItems(e={}){e.boundaries=this,e.ignoreElementEnd=!0;const t=new Eo(e);for(const e of t)yield e.item}*getPositions(e={}){e.boundaries=this;const t=new Eo(e);yield t.position;for(const e of t)yield e.nextPosition}getTransformedByOperation(t){switch(t.type){case"insert":return this._getTransformedByInsertOperation(t);case"move":case"remove":case"reinsert":return this._getTransformedByMoveOperation(t);case"split":return[this._getTransformedBySplitOperation(t)];case"merge":return[this._getTransformedByMergeOperation(t)];case"detach":return this._getTransformedByDetachOperation(t)}return[new e(this.start,this.end)]}getTransformedByOperations(t){const i=[new e(this.start,this.end)];for(const e of t)for(let t=0;t0?new this(i,n):new this(n,i)}static _createIn(e){return new this(Po._createAt(e,0),Po._createAt(e,e.maxOffset))}static _createOn(e){return this._createFromPositionAndShift(Po._createBefore(e),e.offsetSize)}static _createFromRanges(e){if(0===e.length)throw new fe("range-create-from-ranges-empty-array",null);if(1==e.length)return e[0].clone();const t=e[0];e.sort((e,t)=>e.start.isAfter(t.start)?1:-1);const i=e.indexOf(t),n=new this(t.start,t.end);for(let t=i-1;t>=0&&e[t].end.isEqual(n.start);t--)n.start=Po._createAt(e[t].start);for(let t=i+1;t{if(t.viewPosition)return;const i=this._modelToViewMapping.get(t.modelPosition.parent);if(!i)throw new fe("mapping-model-position-view-parent-not-found",this,{modelPosition:t.modelPosition});t.viewPosition=this.findPositionIn(i,t.modelPosition.offset)},{priority:"low"}),this.on("viewToModelPosition",(e,t)=>{if(t.modelPosition)return;const i=this.findMappedViewAncestor(t.viewPosition),n=this._viewToModelMapping.get(i),s=this._toModelOffset(t.viewPosition.parent,t.viewPosition.offset,i);t.modelPosition=Po._createAt(n,s)},{priority:"low"})}bindElements(e,t){this._modelToViewMapping.set(e,t),this._viewToModelMapping.set(t,e)}unbindViewElement(e,t={}){const i=this.toModelElement(e);if(this._elementToMarkerNames.has(e))for(const t of this._elementToMarkerNames.get(e))this._unboundMarkerNames.add(t);t.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 t=this.toViewElement(e);this._modelToViewMapping.delete(e),this._viewToModelMapping.get(t)==e&&this._viewToModelMapping.delete(t)&&this._cache.stopTracking(t)}bindElementToMarker(e,t){const i=this._markerNameToElements.get(t)||new Set;i.add(e);const n=this._elementToMarkerNames.get(e)||new Set;n.add(t),this._markerNameToElements.set(t,i),this._elementToMarkerNames.set(e,n)}unbindElementFromMarkerName(e,t){const i=this._markerNameToElements.get(t);i&&(i.delete(e),0==i.size&&this._markerNameToElements.delete(t));const n=this._elementToMarkerNames.get(e);n&&(n.delete(t),0==n.size&&this._elementToMarkerNames.delete(e))}flushUnboundMarkerNames(){const e=Array.from(this._unboundMarkerNames);return this._unboundMarkerNames.clear(),e}flushDeferredBindings(){for(const[e,t]of this._deferredBindingRemovals)e.root==t&&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 Bo(this.toModelPosition(e.start),this.toModelPosition(e.end))}toViewRange(e){return new jn(this.toViewPosition(e.start),this.toViewPosition(e.end))}toModelPosition(e){const t={viewPosition:e,mapper:this};return this.fire("viewToModelPosition",t),t.modelPosition}toViewPosition(e,t={}){const i={modelPosition:e,mapper:this,isPhantom:t.isPhantom};return this.fire("modelToViewPosition",i),i.viewPosition}markerNameToElements(e){const t=this._markerNameToElements.get(e);if(!t)return null;const i=new Set;for(const e of t)if(e.is("attributeElement"))for(const t of e.getElementsWithSameId())i.add(t);else i.add(e);return i}registerViewToModelLength(e,t){this._viewToModelLengthCallbacks.set(e,t)}findMappedViewAncestor(e){let t=e.parent;for(;!this._viewToModelMapping.has(t);)t=t.parent;return t}_toModelOffset(e,t,i){if(i!=e)return this._toModelOffset(e.parent,e.index,i)+this._toModelOffset(e,t,e);if(e.is("$text"))return t;let n=0;for(let i=0;i0;){const e=t.pop(),n=e.name&&this._viewToModelLengthCallbacks.size>0&&this._viewToModelLengthCallbacks.get(e.name);if(n)i+=n(e);else if(this._viewToModelMapping.has(e))i+=1;else if(e.is("$text"))i+=e.data.length;else{if(e.is("uiElement"))continue;for(const i of e.getChildren())t.push(i)}}return i}findPositionIn(e,t){if(0===t)return this._moveViewPositionToTextNode(new qn(e,0));if(0==this._viewToModelLengthCallbacks.size&&this._viewToModelMapping.has(e)){const i=this._cache.getClosest(e,t);return this._findPositionStartingFrom(i.viewPosition,i.modelOffset,t,e,!0)}return this._findPositionStartingFrom(new qn(e,0),0,t,e,!1)}_findPositionStartingFrom(e,t,i,n,s){let o,r=e.parent,a=e.offset;if(r.is("$text"))return new qn(r,i-t);let l=t,c=0;for(;l{this._clearCacheInsideParent(t,i.index)};_invalidateOnTextChangeCallback=(e,t)=>{this._clearCacheAfter(t)};save(e,t,i,n){const s=this._cachedMapping.get(i),o=s.cacheMap.get(n);if(o){const i=e.getChild(t-1),n=o.viewPosition.nodeBefore?this._nodeToCacheListIndex.get(o.viewPosition.nodeBefore):0;return void this._nodeToCacheListIndex.set(i,n)}const r={viewPosition:new qn(e,t),modelOffset:n};s.maxModelOffset=n>s.maxModelOffset?n:s.maxModelOffset,s.cacheMap.set(n,r);let a=s.cacheList.length-1;for(;a>=0&&s.cacheList[a].modelOffset>n;)a--;if(s.cacheList.splice(a+1,0,r),t>0){const i=e.getChild(t-1);this._nodeToCacheListIndex.set(i,a+1)}}getClosest(e,t){const i=this._cachedMapping.get(e);let n;if(i)if(t>i.maxModelOffset)n=i.cacheList[i.cacheList.length-1];else{const e=i.cacheMap.get(t);n=e||this._findInCacheList(i.cacheList,t)}else n=this.startTracking(e);return{modelOffset:n.modelOffset,viewPosition:n.viewPosition.clone()}}startTracking(e){const t={viewPosition:new qn(e,0),modelOffset:0},i={maxModelOffset:0,cacheList:[t],cacheMap:new Map([[0,t]])};return this._cachedMapping.set(e,i),e.on("change:children",this._invalidateOnChildrenChangeCallback),e.on("change:text",this._invalidateOnTextChangeCallback),t}stopTracking(e){e.off("change:children",this._invalidateOnChildrenChangeCallback),e.off("change:text",this._invalidateOnTextChangeCallback),this._cachedMapping.delete(e)}_clearCacheInsideParent(e,t){if(0==t)this._cachedMapping.has(e)?this._clearCacheAll(e):this._clearCacheInsideParent(e.parent,e.index);else{const i=e.getChild(t-1);this._clearCacheAfter(i)}}_clearCacheAll(e){const t=this._cachedMapping.get(e);t.maxModelOffset>0&&(t.maxModelOffset=0,t.cacheList.length=1,t.cacheMap.clear(),t.cacheMap.set(0,t.cacheList[0]))}_clearCacheAfter(e){const t=this._nodeToCacheListIndex.get(e);if(void 0===t){const t=e.parent;return void(this._cachedMapping.has(t)||this._clearCacheInsideParent(t.parent,t.index))}let i=e.parent;for(;!this._cachedMapping.has(i);)i=i.parent;this._clearCacheFromCacheIndex(i,t)}_clearCacheFromCacheIndex(e,t){0===t&&(t=1);const i=this._cachedMapping.get(e),n=i.cacheList[t-1];if(!n)return;i.maxModelOffset=n.modelOffset;const s=i.cacheList.splice(t);for(const e of s){i.cacheMap.delete(e.modelOffset);const t=e.viewPosition.nodeBefore;this._nodeToCacheListIndex.delete(t)}}_findInCacheList(e,t){let i=0,n=e.length-1,s=n-i>>1,o=e[s];for(;i>1),o=e[s];return o.modelOffset<=t?o:e[s-1]}},Do=class{_consumable=new Map;_textProxyRegistry=new Map;add(e,t){t=zo(t),e instanceof To&&(e=this._getSymbolForTextProxy(e)),this._consumable.has(e)||this._consumable.set(e,new Map),this._consumable.get(e).set(t,!0)}consume(e,t){return t=zo(t),e instanceof To&&(e=this._getSymbolForTextProxy(e)),!!this.test(e,t)&&(this._consumable.get(e).set(t,!1),!0)}test(e,t){t=zo(t),e instanceof To&&(e=this._getSymbolForTextProxy(e));const i=this._consumable.get(e);if(void 0===i)return null;const n=i.get(t);return void 0===n?null:n}revert(e,t){t=zo(t),e instanceof To&&(e=this._getSymbolForTextProxy(e));const i=this.test(e,t);return!1===i?(this._consumable.get(e).set(t,!0),!0):!0!==i&&null}verifyAllConsumed(e){const t=[];for(const[i,n]of this._consumable)for(const[s,o]of n){const n=s.split(":")[0];o&&e==n&&t.push({event:s,item:i.name||i.description})}if(t.length)throw new fe("conversion-model-consumable-not-consumed",null,{items:t})}_getSymbolForTextProxy(e){let t=null;const i=this._textProxyRegistry.get(e.startOffset);if(i){const n=i.get(e.endOffset);n&&(t=n.get(e.parent))}return t||(t=this._addSymbolForTextProxy(e)),t}_addSymbolForTextProxy(e){const t=e.startOffset,i=e.endOffset,n=e.parent,s=Symbol("$textProxy:"+e.data);let o,r;return o=this._textProxyRegistry.get(t),o||(o=new Map,this._textProxyRegistry.set(t,o)),r=o.get(i),r||(r=new Map,o.set(i,r)),r.set(n,s),s}};function zo(e){const t=e.split(":");return"insert"==t[0]?t[0]:"addMarker"==t[0]||"removeMarker"==t[0]?e:t.length>1?t[0]+":"+t[1]:t[0]}function Ho([e,t],[i,n]){if("after"!==t.end.compareWith(n.start))return 1;if("before"!==t.start.compareWith(n.end))return-1;switch(t.start.compareWith(n.start)){case"before":return 1;case"after":return-1;default:switch(t.end.compareWith(n.end)){case"before":return-1;case"after":return 1;default:return i.localeCompare(e)}}}const $o=Te();var Wo=class extends $o{_conversionApi;_firedEventsMap;constructor(e){super(),this._conversionApi={dispatcher:this,...e},this._firedEventsMap=new WeakMap}convertChanges(e,t,i){const n=e.getRefreshedItems(),s=this._createConversionApi(i,n);for(const t of e.getMarkersToRemove())this._convertMarkerRemove(t.name,t.range,s);const o=this._reduceChanges(e.getChanges(),n);for(const e of o)"insert"===e.type?this._convertInsert(Bo._createFromPositionAndShift(e.position,e.length),s):"reinsert"===e.type?this._convertReinsert(Bo._createFromPositionAndShift(e.position,e.length),s):"remove"===e.type?this._convertRemove(e.position,e.length,e.name,s):this._convertAttribute(e.range,e.attributeKey,e.attributeOldValue,e.attributeNewValue,s);s.mapper.flushDeferredBindings();for(const e of s.mapper.flushUnboundMarkerNames()){const i=t.get(e).getRange();this._convertMarkerRemove(e,i,s),this._convertMarkerAdd(e,i,s)}const r=e.getMarkersToAdd().sort((e,t)=>Ho([e.name,e.range],[t.name,t.range]));for(const e of r)this._convertMarkerAdd(e.name,e.range,s);s.consumable.verifyAllConsumed("insert")}convert(e,t,i,n={}){const s=this._createConversionApi(i,void 0,n);this._convertInsert(e,s);for(const[e,i]of Array.from(t).sort(Ho))this._convertMarkerAdd(e,i,s);s.consumable.verifyAllConsumed("insert")}convertSelection(e,t,i){const n=this._createConversionApi(i);this.fire("cleanSelection",{selection:e},n);const s=e.getFirstPosition().root;if(!n.mapper.toViewElement(s))return;const o=Array.from(t.getMarkersAtPosition(e.getFirstPosition()));if(this._addConsumablesForSelection(n.consumable,e,o),this.fire("selection",{selection:e},n),e.isCollapsed){for(const t of o)if(n.consumable.test(e,"addMarker:"+t.name)){const i=t.getRange();if(!Uo(e.getFirstPosition(),t,n.mapper))continue;const s={item:e,markerName:t.name,markerRange:i};this.fire(`addMarker:${t.name}`,s,n)}for(const t of e.getAttributeKeys())if(n.consumable.test(e,"attribute:"+t)){const i={item:e,range:e.getFirstRange(),attributeKey:t,attributeOldValue:null,attributeNewValue:e.getAttribute(t)};this.fire(`attribute:${t}:$text`,i,n)}}}_convertInsert(e,t,i={}){i.doNotAddConsumables||this._addConsumablesForInsert(t.consumable,e);for(const i of e.getWalker({shallow:!0}))this._testAndFire("insert",qo(i),t)}_convertRemove(e,t,i,n){this.fire(`remove:${i}`,{position:e,length:t},n)}_convertAttribute(e,t,i,n,s){this._addConsumablesForRange(s.consumable,e,`attribute:${t}`);for(const o of e){const e={item:o.item,range:Bo._createFromPositionAndShift(o.previousPosition,o.length),attributeKey:t,attributeOldValue:i,attributeNewValue:n};this._testAndFire(`attribute:${t}`,e,s)}}_convertReinsert(e,t){const i=Array.from(e.getWalker({shallow:!0}));this._addConsumablesForInsert(t.consumable,i);for(const e of i.map(qo))this.fire(`remove:${e.item.is("element")?e.item.name:"$text"}`,{position:e.range.start,length:e.item.offsetSize,reconversion:!0},t),this._testAndFire("insert",{...e,reconversion:!0},t)}_convertMarkerAdd(e,t,i){if("$graveyard"==t.root.rootName)return;const n=`addMarker:${e}`;if(i.consumable.add(t,n),this.fire(n,{markerName:e,markerRange:t},i),i.consumable.consume(t,n)){this._addConsumablesForRange(i.consumable,t,n);for(const s of t.getItems()){if(!i.consumable.test(s,n))continue;const o={item:s,range:Bo._createOn(s),markerName:e,markerRange:t};this.fire(n,o,i)}}}_convertMarkerRemove(e,t,i){"$graveyard"!=t.root.rootName&&this.fire(`removeMarker:${e}`,{markerName:e,markerRange:t},i)}_reduceChanges(e,t){const i={changes:e,refreshedItems:t};return this.fire("reduceChanges",i),i.changes}_addConsumablesForInsert(e,t){for(const i of t){const t=i.item;if(null===e.test(t,"insert")){e.add(t,"insert");for(const i of t.getAttributeKeys())e.add(t,"attribute:"+i)}}return e}_addConsumablesForRange(e,t,i){for(const n of t.getItems())e.add(n,i);return e}_addConsumablesForSelection(e,t,i){e.add(t,"selection");for(const n of i)e.add(t,"addMarker:"+n.name);for(const i of t.getAttributeKeys())e.add(t,"attribute:"+i);return e}_testAndFire(e,t,i){const n=function(e,t){return`${e}:${t.item.is("element")?t.item.name:"$text"}`}(e,t),s=t.item.is("$textProxy")?i.consumable._getSymbolForTextProxy(t.item):t.item,o=this._firedEventsMap.get(i),r=o.get(s);if(r){if(r.has(n))return;r.add(n)}else o.set(s,new Set([n]));this.fire(n,t,i)}_testAndFireAddAttributes(e,t){const i={item:e,range:Bo._createOn(e)};for(const e of i.item.getAttributeKeys())i.attributeKey=e,i.attributeOldValue=null,i.attributeNewValue=i.item.getAttribute(e),this._testAndFire(`attribute:${e}`,i,t)}_createConversionApi(e,t=new Set,i={}){const n={...this._conversionApi,consumable:new Do,writer:e,options:i,convertItem:e=>this._convertInsert(Bo._createOn(e),n),convertChildren:e=>this._convertInsert(Bo._createIn(e),n,{doNotAddConsumables:!0}),convertAttributes:e=>this._testAndFireAddAttributes(e,n),canReuseView:e=>!t.has(n.mapper.toModelElement(e))};return this._firedEventsMap.set(n,new Map),n}};function Uo(e,t,i){const n=t.getRange(),s=Array.from(e.getAncestors());return s.shift(),s.reverse(),!s.some(e=>{if(n.containsItem(e))return!!i.toViewElement(e).getCustomProperty("addHighlight")})}function qo(e){return{item:e.item,range:Bo._createFromPositionAndShift(e.previousPosition,e.length)}}var jo=class extends Ao{parent=null;_attrs;_index=null;_startOffset=null;constructor(e){super(),this._attrs=gi(e)}get document(){return null}get index(){return this._index}get startOffset(){return this._startOffset}get offsetSize(){return 1}get endOffset(){return null===this.startOffset?null:this.startOffset+this.offsetSize}get nextSibling(){const e=this.index;return null!==e&&this.parent.getChild(e+1)||null}get previousSibling(){const e=this.index;return null!==e&&this.parent.getChild(e-1)||null}get root(){let e=this;for(;e.parent;)e=e.parent;return e}isAttached(){return null!==this.parent&&this.root.isAttached()}getPath(){const e=[];let t=this;for(;t.parent;)e.unshift(t.startOffset),t=t.parent;return e}getAncestors(e={}){const t=[];let i=e.includeSelf?this:this.parent;for(;i;)t[e.parentFirst?"push":"unshift"](i),i=i.parent;return t}getCommonAncestor(e,t={}){const i=this.getAncestors(t),n=e.getAncestors(t);let s=0;for(;i[s]==n[s]&&i[s];)s++;return 0===s?null:i[s-1]}isBefore(e){if(this==e)return!1;if(this.root!==e.root)return!1;const t=this.getPath(),i=e.getPath(),n=Ke(t,i);switch(n){case"prefix":return!0;case"extension":return!1;default:return t[n](e[t[0]]=t[1],e),{})),e}_clone(e){return new this.constructor(this._attrs)}_remove(){this.parent._removeChildren(this.index)}_setAttribute(e,t){this._attrs.set(e,t)}_setAttributesTo(e){this._attrs=gi(e)}_removeAttribute(e){return this._attrs.delete(e)}_clearAttributes(){this._attrs.clear()}};jo.prototype.is=function(e){return"node"===e||"model:node"===e};const Ko=Te(Ao);var Go=class e extends Ko{_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 1===this._ranges.length&&this._ranges[0].isCollapsed}get rangeCount(){return this._ranges.length}get isBackward(){return!this.isCollapsed&&this._lastRangeBackward}isEqual(e){if(this.rangeCount!=e.rangeCount)return!1;if(0===this.rangeCount)return!0;if(!this.anchor.isEqual(e.anchor)||!this.focus.isEqual(e.focus))return!1;for(const t of this._ranges){let i=!1;for(const n of e._ranges)if(t.isEqual(n)){i=!0;break}if(!i)return!1}return!0}*getRanges(){for(const e of this._ranges)yield new Bo(e.start,e.end)}getFirstRange(){let e=null;for(const t of this._ranges)e&&!t.start.isBefore(e.start)||(e=t);return e?new Bo(e.start,e.end):null}getLastRange(){let e=null;for(const t of this._ranges)e&&!t.end.isAfter(e.end)||(e=t);return e?new Bo(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(...t){let[i,n,s]=t;if("object"==typeof n&&(s=n,n=void 0),null===i)this._setRanges([]);else if(i instanceof e)this._setRanges(i.getRanges(),i.isBackward);else if(i&&"function"==typeof i.getRanges)this._setRanges(i.getRanges(),i.isBackward);else if(i instanceof Bo)this._setRanges([i],!!s&&!!s.backward);else if(i instanceof Po)this._setRanges([new Bo(i)]);else if(i instanceof jo){const e=!!s&&!!s.backward;let t;if("in"==n)t=Bo._createIn(i);else if("on"==n)t=Bo._createOn(i);else{if(void 0===n)throw new fe("model-selection-setto-required-second-parameter",[this,i]);t=new Bo(Po._createAt(i,n))}this._setRanges([t],e)}else{if(!Ge(i))throw new fe("model-selection-setto-not-selectable",[this,i]);this._setRanges(i,s&&!!s.backward)}}_setRanges(e,t=!1){const i=Array.from(e),n=i.some(t=>{if(!(t instanceof Bo))throw new fe("model-selection-set-ranges-not-range",[this,e]);return this._ranges.every(e=>!e.isEqual(t))});(i.length!==this._ranges.length||n)&&(this._replaceAllRanges(i),this._lastRangeBackward=!!t,this.fire("change:range",{directChange:!0}))}setFocus(e,t){if(null===this.anchor)throw new fe("model-selection-setfocus-no-ranges",[this,e]);const i=Po._createAt(e,t);if("same"==i.compareWith(this.focus))return;const n=this.anchor;this._ranges.length&&this._popRange(),"before"==i.compareWith(n)?(this._pushRange(new Bo(i,n)),this._lastRangeBackward=!0):(this._pushRange(new Bo(n,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,t){this.getAttribute(e)!==t&&(this._attrs.set(e,t),this.fire("change:attribute",{attributeKeys:[e],directChange:!0}))}getSelectedElement(){return 1!==this.rangeCount?null:this.getFirstRange().getContainedElement()}*getSelectedBlocks(){const e=new WeakSet;for(const t of this.getRanges()){const i=Yo(t.start,e);Zo(i,t)&&(yield i);const n=t.getWalker();for(const i of n){const s=i.item;"elementEnd"==i.type&&Qo(s,e,t)?yield s:"elementStart"==i.type&&s.is("model:element")&&s.root.document.model.schema.isBlock(s)&&n.jumpTo(Po._createAt(s,"end"))}const s=Yo(t.end,e);er(s,t)&&(yield s)}}containsEntireContent(e=this.anchor.root){const t=Po._createAt(e,0),i=Po._createAt(e,"end");return t.isTouching(this.getFirstPosition())&&i.isTouching(this.getLastPosition())}toJSON(){const e={ranges:Array.from(this.getRanges()).map(e=>e.toJSON())},t=Object.fromEntries(this.getAttributes());return Object.keys(t).length&&(e.attributes=t),this.isBackward&&(e.isBackward=!0),e}_pushRange(e){this._checkRange(e),this._ranges.push(new Bo(e.start,e.end))}_checkRange(e){for(let t=0;t0;)this._popRange()}_popRange(){this._ranges.pop()}};function Jo(e,t){return!t.has(e)&&(t.add(e),e.root.document.model.schema.isBlock(e)&&!!e.parent)}function Qo(e,t,i){return Jo(e,t)&&Xo(e,i)}function Yo(e,t){const i=e.parent.root.document.model.schema,n=e.parent.getAncestors({parentFirst:!0,includeSelf:!0});let s=!1;const o=n.find(e=>!s&&(s=i.isLimit(e),!s&&Jo(e,t)));return n.forEach(e=>t.add(e)),o}function Xo(e,t){const i=function(e){const t=e.root.document.model.schema;let i=e.parent;for(;i;){if(t.isBlock(i))return i;i=i.parent}}(e);return!i||!t.containsRange(Bo._createOn(i),!0)}function Zo(e,t){return!!e&&(!(!t.isCollapsed&&!e.isEmpty)||!t.start.isTouching(Po._createAt(e,e.maxOffset))&&Xo(e,t))}function er(e,t){return!!e&&(!(!t.isCollapsed&&!e.isEmpty)||!t.end.isTouching(Po._createAt(e,0))&&Xo(e,t))}Go.prototype.is=function(e){return"selection"===e||"model:selection"===e};const tr=Te(Bo);var ir=class e extends tr{constructor(e,t,i){super(e,t);const n=this.root,s=i||(n.is("rootElement")?n.document.model:null);if(!s)throw new fe("model-liverange-no-model-reference",n);nr.call(this,s)}detach(){this.stopListening()}toRange(){return new Bo(this.start,this.end)}static fromRange(t){return new e(t.start,t.end)}static _fromRangeInDocumentFragment(e,t){return new this(e.start,e.end,t)}};function nr(e){const t=!this.root.is("rootElement");this.listenTo(e,"applyOperation",(e,i)=>{const n=i[0];(t||n.isDocumentOperation)&&sr.call(this,n)},{priority:"low"})}function sr(e){const t=this.getTransformedByOperation(e);if(0===t.length){const t=e.sourcePosition;return this.start=t,this.end=t,void this.fire("change:drop",this.toRange(),{deletionPosition:t})}const i=Bo._createFromRanges(t),n=!i.isEqual(this),s=function(e,t){switch(t.type){case"insert":return e.containsPosition(t.position);case"move":case"remove":case"reinsert":case"merge":return e.containsPosition(t.sourcePosition)||e.start.isEqual(t.sourcePosition)||e.containsPosition(t.targetPosition);case"split":return e.containsPosition(t.splitPosition)||e.containsPosition(t.insertionPosition)}return!1}(this,e);let o=null;if(n){"$graveyard"==i.root.rootName&&(o="remove"==e.type?e.sourcePosition:e.deletionPosition);const t=this.toRange();this.start=i.start,this.end=i.end,this.fire("change:range",t,{deletionPosition:o})}else s&&this.fire("change:content",this.toRange(),{deletionPosition:o})}ir.prototype.is=function(e){return"liveRange"===e||"model:liveRange"===e||"range"==e||"model:range"===e};var or=class e extends jo{_data;constructor(e,t){super(t),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 e(this.data,this.getAttributes())}static fromJSON(t){return new e(t.data,t.attributes)}};or.prototype.is=function(e){return"$text"===e||"model:$text"===e||"text"===e||"model:text"===e||"node"===e||"model:node"===e};const rr="selection:",ar=Te(Ao);var lr=class extends ar{_selection;constructor(e){super(),this._selection=new cr(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,t){this._selection.setFocus(e,t)}_setTo(...e){this._selection.setTo(...e)}_setAttribute(e,t){this._selection.setAttribute(e,t)}_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 rr+e}static _isStoreAttributeKey(e){return e.startsWith(rr)}static _dropStoreAttributeKeyPrefix(e){return e.startsWith(rr)?e.substring(10):e}};lr.prototype.is=function(e){return"selection"===e||"model:selection"==e||"documentSelection"==e||"model:documentSelection"==e};var cr=class extends Go{markers=new ri({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",(e,t)=>{const i=t[0];i.isDocumentOperation&&"marker"!=i.type&&"rename"!=i.type&&"noop"!=i.type&&(0==this._ranges.length&&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",(e,t,i,n)=>{this._updateMarker(t,n)}),this.listenTo(this._document,"change",(e,t)=>{!function(e,t){const i=e.document.differ;for(const n of i.getChanges()){if("insert"!=n.type)continue;const i=n.position.parent;n.length===i.maxOffset&&e.enqueueChange(t,e=>{const t=Array.from(i.getAttributeKeys()).filter(e=>e.startsWith(rr));for(const n of t)e.removeAttribute(n,i)})}}(this._model,t)})}get isCollapsed(){return 0===this._ranges.length?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;ee.toJSON())),e}_validateSelectionRanges(e){for(const t of e)if(!this._document._validateSelectionRange(t))throw new fe("document-selection-wrong-position",this,{range:t})}_prepareRange(e){if(this._checkRange(e),e.root==this._document.graveyard)return;const t=ir.fromRange(e);return t.on("change:range",(e,i,n)=>{if(this._hasChangedRange=!0,t.root==this._document.graveyard){this._selectionRestorePosition=n.deletionPosition;const e=this._ranges.indexOf(t);this._ranges.splice(e,1),t.detach()}}),t}updateMarkers(){if(!this._observedMarkers.size)return;const e=[];let t=!1;for(const t of this._model.markers){const i=t.name.split(":",1)[0];if(!this._observedMarkers.has(i))continue;const n=t.getRange();for(const i of this.getRanges())n.containsRange(i,!i.isCollapsed)&&e.push(t)}const i=Array.from(this.markers);for(const i of e)this.markers.has(i)||(this.markers.add(i),t=!0);for(const i of Array.from(this.markers))e.includes(i)||(this.markers.remove(i),t=!0);t&&this.fire("change:marker",{oldMarkers:i,directChange:!1})}_updateMarker(e,t){const i=e.name.split(":",1)[0];if(!this._observedMarkers.has(i))return;let n=!1;const s=Array.from(this.markers),o=this.markers.has(e);if(t){let i=!1;for(const e of this.getRanges())if(t.containsRange(e,!e.isCollapsed)){i=!0;break}i&&!o?(this.markers.add(e),n=!0):!i&&o&&(this.markers.remove(e),n=!0)}else o&&(this.markers.remove(e),n=!0);n&&this.fire("change:marker",{oldMarkers:s,directChange:!1})}_updateAttributes(e){const t=gi(this._getSurroundingAttributes()),i=gi(this.getAttributes());if(e)this._attributePriority=new Map,this._attrs=new Map;else for(const[e,t]of this._attributePriority)"low"==t&&(this._attrs.delete(e),this._attributePriority.delete(e));this._setAttributesTo(t);const n=[];for(const[e,t]of this.getAttributes())i.has(e)&&i.get(e)===t||n.push(e);for(const[e]of i)this.hasAttribute(e)||n.push(e);n.length>0&&this.fire("change:attribute",{attributeKeys:n,directChange:!1})}_setAttribute(e,t,i=!0){const n=i?"normal":"low";return("low"!=n||"normal"!=this._attributePriority.get(e))&&(super.getAttribute(e)!==t&&(this._attrs.set(e,t),this._attributePriority.set(e,n),!0))}_removeAttribute(e,t=!0){const i=t?"normal":"low";return("low"!=i||"normal"!=this._attributePriority.get(e))&&(this._attributePriority.set(e,i),!!super.hasAttribute(e)&&(this._attrs.delete(e),!0))}_setAttributesTo(e){const t=new Set;for(const[t,i]of this.getAttributes())e.get(t)!==i&&this._removeAttribute(t,!1);for(const[i,n]of e)this._setAttribute(i,n,!1)&&t.add(i);return t}*getStoredAttributes(){const e=this.getFirstPosition().parent;if(this.isCollapsed&&e.isEmpty)for(const t of e.getAttributeKeys())t.startsWith(rr)&&(yield[t.substr(10),e.getAttribute(t)])}_getSurroundingAttributes(){const e=this.getFirstPosition(),t=this._model.schema;if("$graveyard"==e.root.rootName)return null;let i=null;if(this.isCollapsed){const n=e.textNode?e.textNode:e.nodeBefore,s=e.textNode?e.textNode:e.nodeAfter;this.isGravityOverridden||(i=dr(n,t)),i||(i=dr(s,t)),this.isGravityOverridden||i||(i=dr(n,t,"backward")),i||(i=dr(s,t,"forward")),i||(i=this.getStoredAttributes())}else{const e=this.getFirstRange();for(const n of e){if(n.item.is("element")&&t.isObject(n.item)){i=dr(n.item,t);break}if("text"==n.type){i=n.item.getAttributes();break}}}return i}_fixGraveyardSelection(e){const t=this._model.schema.getNearestSelectionRange(e);t&&this._pushRange(t)}};function dr(e,t,i="self"){if(!e)return null;for(const n of function*(e,t){if("self"==t)yield e;else{let i=e;for(;i;)i="backward"==t?i.previousSibling:i.nextSibling,yield i}return null}(e,i)){if(!n)return null;if(n instanceof or)return n.getAttributes();if(!t.isInline(n))continue;const e=t.isObject(n),i=[];for(const[s,o]of n.getAttributes())!t.checkAttribute("$text",s)||e&&!1===t.getAttributeProperties(s).copyFromObject||i.push([s,o]);return i}return null}var ur=class{_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 t=this._nodes[e];if(!t)throw new fe("model-nodelist-index-out-of-bounds",this);return this.getNodeStartOffset(t)}offsetToIndex(e){if(e==this._offsetToNode.length)return this._nodes.length;const t=this._offsetToNode[e];if(!t)throw new fe("model-nodelist-offset-out-of-bounds",this,{offset:e,nodeList:this});return this.getNodeIndex(t)}_insertNodes(e,t){const i=[];for(const e of t){if(!(e instanceof jo))throw new fe("model-nodelist-insertnodes-not-node",this);i.push(e)}let n=this.indexToOffset(e);fi(this._nodes,i,e),fi(this._offsetToNode,function(e){const t=[];let i=0;for(const n of e)for(let e=0;enull!==e.index),this._offsetToNode=this._offsetToNode.filter(e=>null!==e.index);let t=0;for(let e=0;ee.toJSON())}};var hr=class e extends jo{name;_children=new ur;constructor(e,t,i){super(t),this.name=e,i&&this._insertChild(0,i)}get childCount(){return this._children.length}get maxOffset(){return this._children.maxOffset}get isEmpty(){return 0===this.childCount}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)}offsetToIndex(e){return this._children.offsetToIndex(e)}getNodeByPath(e){let t=this;for(const i of e)t=t.getChildAtOffset(i);return t}findAncestor(e,t={}){let i=t.includeSelf?this:this.parent;for(;i;){if(i.name===e)return i;i=i.parent}return null}toJSON(){const e=super.toJSON();if(e.name=this.name,this._children.length>0){e.children=[];for(const t of this._children)e.children.push(t.toJSON())}return e}_clone(t=!1){const i=t?function(e){const t=[];for(const i of e)t.push(i._clone(!0));return t}(this._children):void 0;return new e(this.name,this.getAttributes(),i)}_appendChild(e){this._insertChild(this.childCount,e)}_insertChild(e,t){const i=function(e){if("string"==typeof e)return[new or(e)];Ge(e)||(e=[e]);const t=[];for(const i of e)"string"==typeof i?t.push(new or(i)):i instanceof To?t.push(new or(i.data,i.getAttributes())):t.push(i);return t}(t);for(const e of i)null!==e.parent&&e._remove(),e.parent=this;this._children._insertNodes(e,i)}_removeChildren(e,t=1){const i=this._children._removeNodes(e,t);for(const e of i)e.parent=null;return i}_removeChildrenArray(e){this._children._removeNodesArray(e);for(const t of e)t.parent=null}static fromJSON(t){let i;if(t.children){i=[];for(const n of t.children)n.name?i.push(e.fromJSON(n)):i.push(or.fromJSON(n))}return new e(t.name,t.attributes,i)}};hr.prototype.is=function(e,t){return t?t===this.name&&("element"===e||"model:element"===e):"element"===e||"model:element"===e||"node"===e||"model:node"===e};var mr=class{_dispatchers;constructor(e){this._dispatchers=e}add(e){for(const t of this._dispatchers)e(t);return this}},gr=class extends mr{elementToElement(e){return this.add(function(e){const t=kr(e.model),i=Cr(e.view,"container");t.attributes.length&&(t.children=!0);return n=>{n.on(`insert:${t.name}`,br(i,Pr(t)),{priority:e.converterPriority||"normal"}),(t.children||t.attributes.length)&&n.on("reduceChanges",xr(t),{priority:"low"})}}(e))}elementToStructure(e){return this.add(function(e){const t=kr(e.model),i=Cr(e.view,"container");return t.children=!0,n=>{if(n._conversionApi.schema.checkChild(t.name,"$text"))throw new fe("conversion-element-to-structure-disallowed-text",n,{elementName:t.name});var s,o;n.on(`insert:${t.name}`,(s=i,o=Pr(t),(e,t,i)=>{if(!o(t.item,i.consumable,{preflight:!0}))return;const n=new Map;i.writer._registerSlotFactory(function(e,t,i){return(n,s)=>{const o=n.createContainerElement("$slot");let r;if("children"===s)r=Array.from(e.getChildren());else{if("function"!=typeof s)throw new fe("conversion-slot-mode-unknown",i.dispatcher,{modeOrFilter:s});r=Array.from(e.getChildren()).filter(e=>s(e))}return t.set(o,r),o}}(t.item,n,i));const r=s(t.item,i,t);if(i.writer._clearSlotFactory(),!r)return;!function(e,t,i){const n=Array.from(t.values()).flat(),s=new Set(n);if(s.size!=n.length)throw new fe("conversion-slot-filter-overlap",i.dispatcher,{element:e});if(s.size!=e.childCount)throw new fe("conversion-slot-filter-incomplete",i.dispatcher,{element:e})}(t.item,n,i),o(t.item,i.consumable);const a=t.reconversion&&vr(t.item,i)||i.mapper.toViewPosition(t.range.start);i.mapper.bindElements(t.item,r),i.writer.insert(a,r),i.convertAttributes(t.item),function(e,t,i,n){i.mapper.on("modelToViewPosition",r,{priority:"highest"});let s=null,o=null;for([s,o]of t)Sr(e,o,i,n),i.writer.setCustomProperty("$structureSlotParent",!0,s.parent),i.writer.move(i.writer.createRangeIn(s),i.writer.createPositionBefore(s)),i.writer.remove(s);function r(e,t){const i=t.modelPosition.nodeAfter,n=o.indexOf(i);n<0||(t.viewPosition=t.mapper.findPositionIn(s,n))}i.mapper.off("modelToViewPosition",r)}(r,n,i,{reconversion:t.reconversion})}),{priority:e.converterPriority||"normal"}),n.on("reduceChanges",xr(t),{priority:"low"})}}(e))}attributeToElement(e){return this.add(function(e){e=L(e);let t=e.model;"string"==typeof t&&(t={key:t});let i=`attribute:${t.key}`;t.name&&(i+=":"+t.name);if(t.values)for(const i of t.values)e.view[i]=Cr(e.view[i],"attribute");else e.view=Cr(e.view,"attribute");const n=Ar(e);return t=>{t.on(i,pr(n),{priority:e.converterPriority||"normal"})}}(e))}attributeToAttribute(e){return this.add(function(e){e=L(e);let t=e.model;"string"==typeof t&&(t={key:t});let i=`attribute:${t.key}`;t.name&&(i+=":"+t.name);if(t.values)for(const i of t.values)e.view[i]=Tr(e.view[i]);else e.view=Tr(e.view);const n=Ar(e);return t=>{var s;t.on(i,(s=n,(e,t,i)=>{if(!i.consumable.test(t.item,e.name))return;const n=s(t.attributeOldValue,i,t),o=s(t.attributeNewValue,i,t);if(!n&&!o)return;i.consumable.consume(t.item,e.name);const r=i.mapper.toViewElement(t.item),a=i.writer;if(!r)throw new fe("conversion-attribute-to-attribute-on-text",i.dispatcher,t);if(null!==t.attributeOldValue&&n){let e=n.value;"style"==n.key&&(e="string"==typeof n.value?new Sn(a.document.stylesProcessor).setTo(n.value).getStylesEntries().map(([e])=>e):Object.keys(n.value)),a.removeAttribute(n.key,e,r)}if(null!==t.attributeNewValue&&o){let e=o.value;"style"==o.key&&"string"==typeof o.value&&(e=Object.fromEntries(new Sn(a.document.stylesProcessor).setTo(o.value).getStylesEntries())),a.setAttribute(o.key,e,!1,r)}}),{priority:e.converterPriority||"normal"})}}(e))}markerToElement(e){return this.add(function(e){const t=Cr(e.view,"ui");return i=>{i.on(`addMarker:${e.model}`,wr(t),{priority:e.converterPriority||"normal"}),i.on(`removeMarker:${e.model}`,(e,t,i)=>{const n=i.mapper.markerNameToElements(t.markerName);if(n){for(const e of n)i.mapper.unbindElementFromMarkerName(e,t.markerName),i.writer.clear(i.writer.createRangeOn(e),e);i.writer.clearClonedElementsGroup(t.markerName),e.stop()}},{priority:e.converterPriority||"normal"})}}(e))}markerToHighlight(e){return this.add(function(e){return t=>{var i;t.on(`addMarker:${e.model}`,(i=e.view,(e,t,n)=>{if(!t.item)return;if(!(t.item instanceof Go||t.item instanceof lr||t.item.is("$textProxy")))return;const s=Er(i,t,n);if(!s)return;if(!n.consumable.consume(t.item,e.name))return;const o=n.writer,r=fr(o,s),a=o.document.selection;if(t.item instanceof Go||t.item instanceof lr)o.wrap(a.getFirstRange(),r);else{const e=n.mapper.toViewRange(t.range),i=o.wrap(e,r);for(const e of i.getItems())if(e.is("attributeElement")&&e.isSimilar(r)){n.mapper.bindElementToMarker(e,t.markerName);break}}}),{priority:e.converterPriority||"normal"}),t.on(`addMarker:${e.model}`,function(e){return(t,i,n)=>{if(!i.item)return;if(!(i.item instanceof hr))return;const s=Er(e,i,n);if(!s)return;if(!n.consumable.test(i.item,t.name))return;const o=n.mapper.toViewElement(i.item);if(o&&o.getCustomProperty("addHighlight")){n.consumable.consume(i.item,t.name);for(const e of Bo._createIn(i.item))n.consumable.consume(e.item,t.name);o.getCustomProperty("addHighlight")(o,s,n.writer),n.mapper.bindElementToMarker(o,i.markerName)}}}(e.view),{priority:e.converterPriority||"normal"}),t.on(`removeMarker:${e.model}`,function(e){return(t,i,n)=>{if(i.markerRange.isCollapsed)return;const s=Er(e,i,n);if(!s)return;const o=fr(n.writer,s),r=n.mapper.markerNameToElements(i.markerName);if(r){for(const e of r)n.mapper.unbindElementFromMarkerName(e,i.markerName),e.is("attributeElement")?n.writer.unwrap(n.writer.createRangeOn(e),o):e.getCustomProperty("removeHighlight")(e,s.id,n.writer);n.writer.clearClonedElementsGroup(i.markerName),t.stop()}}}(e.view),{priority:e.converterPriority||"normal"})}}(e))}markerToData(e){return this.add(function(e){e=L(e);const t=e.model;let i=e.view;i||(i=i=>({group:t,name:i.substr(e.model.length+1)}));return n=>{var s;n.on(`addMarker:${t}`,(s=i,(e,t,i)=>{const n=s(t.markerName,i);if(!n)return;const o=t.markerRange;i.consumable.consume(o,e.name)&&(yr(o,!1,i,t,n),yr(o,!0,i,t,n),e.stop())}),{priority:e.converterPriority||"normal"}),n.on(`removeMarker:${t}`,function(e){return(t,i,n)=>{const s=e(i.markerName,n);if(!s)return;const o=n.mapper.markerNameToElements(i.markerName);if(o){for(const e of o)n.mapper.unbindElementFromMarkerName(e,i.markerName),e.is("containerElement")?(r(`data-${s.group}-start-before`,e),r(`data-${s.group}-start-after`,e),r(`data-${s.group}-end-before`,e),r(`data-${s.group}-end-after`,e)):n.writer.clear(n.writer.createRangeOn(e),e);n.writer.clearClonedElementsGroup(i.markerName),t.stop()}function r(e,t){if(t.hasAttribute(e)){const i=new Set(t.getAttribute(e).split(","));i.delete(s.name),0==i.size?n.writer.removeAttribute(e,t):n.writer.setAttribute(e,Array.from(i).join(","),t)}}}}(i),{priority:e.converterPriority||"normal"})}}(e))}};function fr(e,t){const i=e.createAttributeElement("span",t.attributes);return t.classes&&i._addClass(t.classes),"number"==typeof t.priority&&(i._priority=t.priority),i._id=t.id,i}function pr(e){return(t,i,n)=>{if(!n.consumable.test(i.item,t.name))return;const s=e(i.attributeOldValue,n,i),o=e(i.attributeNewValue,n,i);if(!s&&!o)return;n.consumable.consume(i.item,t.name);const r=n.writer,a=r.document.selection;if(i.item instanceof Go||i.item instanceof lr)r.wrap(a.getFirstRange(),o);else{let e=n.mapper.toViewRange(i.range);null!==i.attributeOldValue&&s&&(e=r.unwrap(e,s)),null!==i.attributeNewValue&&o&&r.wrap(e,o)}}}function br(e,t=Vr){return(i,n,s)=>{if(!t(n.item,s.consumable,{preflight:!0}))return;const o=e(n.item,s,n);if(!o)return;t(n.item,s.consumable);const r=n.reconversion&&vr(n.item,s)||s.mapper.toViewPosition(n.range.start);s.mapper.bindElements(n.item,o),s.writer.insert(r,o),s.convertAttributes(n.item),Sr(o,n.item.getChildren(),s,{reconversion:n.reconversion})}}function wr(e){return(t,i,n)=>{i.isOpening=!0;const s=e(i,n);i.isOpening=!1;const o=e(i,n);if(!s||!o)return;const{markerRange:r,markerName:a}=i;if(r.isCollapsed&&!n.consumable.consume(r,t.name))return;for(const e of r)if(!n.consumable.consume(e.item,t.name))return;const l=n.mapper,c=n.writer;c.setCustomProperty("markerBoundaryType","start",s),c.setCustomProperty("markerBoundaryName",a,s),c.setCustomProperty("markerBoundaryType","end",o),c.setCustomProperty("markerBoundaryName",a,o);const d=(e,t)=>{const i=l.markerNameToElements(e);if(i)for(const e of i)if(e.getCustomProperty("markerBoundaryType")===t)return l.toModelPosition(c.createPositionBefore(e));return null};if(!r.isCollapsed){const e=l.toViewPosition(r.end).getLastMatchingPosition(({item:e})=>{if(!e.is("uiElement")||"end"!==e.getCustomProperty("markerBoundaryType"))return!1;const t=e.getCustomProperty("markerBoundaryName"),i=d(t,"start");if(!i)return!1;const n=i.compareWith(r.start);return"same"===n?t.localeCompare(a)>0:"after"===n});c.insert(e,o),l.bindElementToMarker(o,a)}const u=l.toViewPosition(r.start).getLastMatchingPosition(({item:e})=>{if(!e.is("uiElement"))return!1;const t=e.getCustomProperty("markerBoundaryType");if(!t)return!1;if("end"===t)return!0;const i=e.getCustomProperty("markerBoundaryName"),n=d(i,"end");if(!n)return r.isCollapsed;if(r.isCollapsed)return!0;const s=n.compareWith(r.end);return"same"===s?i.localeCompare(a)<0:"after"===s});c.insert(u,s),l.bindElementToMarker(s,a),t.stop()}}function _r(e,t){const i=t.writer.remove(e);for(const e of t.writer.createRangeIn(i).getItems())t.mapper.unbindViewElement(e,{defer:!0});return e.start}function vr(e,t){const i=t.mapper.toViewElement(e);return i&&_r(t.writer.createRangeOn(i),t)}function yr(e,t,i,n,s){const o=t?e.start:e.end,r=o.nodeAfter&&o.nodeAfter.is("element")?o.nodeAfter:null,a=o.nodeBefore&&o.nodeBefore.is("element")?o.nodeBefore:null;if(r||a){let e,o;t&&r||!t&&!a?(e=r,o=!0):(e=a,o=!1);const l=i.mapper.toViewElement(e);if(l)return void function(e,t,i,n,s,o){const r=`data-${o.group}-${t?"start":"end"}-${i?"before":"after"}`,a=e.hasAttribute(r)?e.getAttribute(r).split(","):[];a.unshift(o.name),n.writer.setAttribute(r,a.join(","),e),n.mapper.bindElementToMarker(e,s.markerName)}(l,t,o,i,n,s)}!function(e,t,i,n,s){const o=`${s.group}-${t?"start":"end"}`,r=s.name?{name:s.name}:null,a=i.writer.createUIElement(o,r);i.writer.insert(e,a),i.mapper.bindElementToMarker(a,n.markerName)}(i.mapper.toViewPosition(o),t,i,n,s)}function kr(e){return"string"==typeof e&&(e={name:e}),{name:e.name,attributes:e.attributes?ii(e.attributes):[],children:!!e.children}}function Cr(e,t){return"function"==typeof e?e:(i,n)=>function(e,t,i){"string"==typeof e&&(e={name:e});let n;const s=t.writer,o=Object.assign({},e.attributes);if("container"==i)n=s.createContainerElement(e.name,o);else if("attribute"==i){const t={priority:e.priority||ds.DEFAULT_PRIORITY};n=s.createAttributeElement(e.name,o,t)}else n=s.createUIElement(e.name,o);if(e.styles){const t=Object.keys(e.styles);for(const i of t)s.setStyle(i,e.styles[i],n)}if(e.classes){const t=e.classes;if("string"==typeof t)s.addClass(t,n);else for(const e of t)s.addClass(e,n)}return n}(e,n,t)}function Ar(e){return e.model.values?(t,i,n)=>{const s=e.view[t];return s?s(t,i,n):null}:e.view}function Tr(e){return"string"==typeof e?t=>({key:e,value:t}):"object"==typeof e?e.value?()=>e:t=>({key:e.key,value:t}):e}function Er(e,t,i){const n="function"==typeof e?e(t,i):{...e};return n?(n.priority||(n.priority=10),n.id||(n.id=t.markerName),n):null}function xr(e){const t=function(e){return(t,i)=>{if(!t.is("element",e.name))return!1;if("attribute"==i.type){if(e.attributes.includes(i.attributeKey))return!0}else if(e.children)return!0;return!1}}(e);return(e,i)=>{const n=[];i.reconvertedElements||(i.reconvertedElements=new Set);for(const e of i.changes){const s="attribute"==e.type?e.range.start.nodeAfter:e.position.parent;if(s&&t(s,e)&&"reinsert"!=e.type){if("insert"==e.type&&"rename"==e.action&&i.refreshedItems.add(e.position.nodeAfter),!i.reconvertedElements.has(s)){i.reconvertedElements.add(s);const e=Po._createBefore(s);let t=n.length;for(let i=n.length-1;i>=0;i--){const s=n[i],o=("attribute"==s.type?s.range.start:s.position).compareWith(e);if("before"==o||"remove"==s.type&&"same"==o)break;t=i}n.splice(t,0,{type:"reinsert",name:s.name,position:e,length:1})}}else n.push(e)}i.changes=n}}function Pr(e){return(t,i,n={})=>{const s=["insert"];for(const i of e.attributes)t.hasAttribute(i)&&s.push(`attribute:${i}`);return!!s.every(e=>i.test(t,e))&&(n.preflight||s.forEach(e=>i.consume(t,e)),!0)}}function Sr(e,t,i,n){for(const s of t)Ir(e.root,s,i,n)||i.convertItem(s)}function Ir(e,t,i,n){const{writer:s,mapper:o}=i;if(!n.reconversion)return!1;const r=o.toViewElement(t);return!(!r||r.root==e)&&(!!i.canReuseView(r)&&(s.move(s.createRangeOn(r),o.toViewPosition(Po._createBefore(t))),!0))}function Vr(e,t,{preflight:i}={}){return i?t.test(e,"insert"):t.consume(e,"insert")}function Or(e){const{schema:t,document:i}=e.model;for(const n of i.getRoots())if(n.isEmpty&&!t.checkChild(n,"$text")&&t.checkChild(n,"paragraph"))return e.insertElement("paragraph",n),!0;return!1}function Rr(e,t,i){const n=i.createContext(e);return!!i.checkChild(n,"paragraph")&&!!i.checkChild(n.push("paragraph"),t)}function Br(e,t){const i=t.createElement("paragraph");return t.insert(i,e),t.createPositionAt(i,0)}var Mr=class extends mr{elementToElement(e){return this.add(Fr(e))}elementToAttribute(e){return this.add(function(e){e=L(e),Dr(e);const t=zr(e,!1),i=Nr(e.view),n=i?`element:${i}`:"element";return i=>{i.on(n,t,{priority:e.converterPriority||"low"})}}(e))}attributeToAttribute(e){return this.add(function(e){e=L(e);let t=null;("string"==typeof e.view||e.view.key)&&(t=function(e){"string"==typeof e.view&&(e.view={key:e.view});const t=e.view.key,i=void 0===e.view.value?/[\s\S]*/:e.view.value;let n;n="class"==t||"style"==t?{["class"==t?"classes":"styles"]:i}:{attributes:{[t]:i}};e.view.name&&(n.name=e.view.name);return e.view=n,t}(e));Dr(e,t);const i=zr(e,!0);return t=>{t.on("element",i,{priority:e.converterPriority||"low"})}}(e))}elementToMarker(e){return this.add(function(e){const t=function(e){return(t,i)=>{const n="string"==typeof e?e:e(t,i);return i.writer.createElement("$marker",{"data-name":n})}}(e.model);return Fr({...e,model:t})}(e))}dataToMarker(e){return this.add(function(e){e=L(e),e.model||(e.model=t=>t?e.view+":"+t:e.view);const t={view:e.view,model:e.model},i=Lr(Hr(t,"start")),n=Lr(Hr(t,"end"));return s=>{s.on(`element:${e.view}-start`,i,{priority:e.converterPriority||"normal"}),s.on(`element:${e.view}-end`,n,{priority:e.converterPriority||"normal"});const o=me.low,r=me.highest,a=me.get(e.converterPriority)/r;s.on("element",function(e){return(t,i,n)=>{const s=`data-${e.view}`;function o(t,s){for(const o of s){const s=e.model(o,n),r=n.writer.createElement("$marker",{"data-name":s});n.writer.insert(r,t),i.modelCursor.isEqual(t)?i.modelCursor=i.modelCursor.getShiftedBy(1):i.modelCursor=i.modelCursor._getTransformedByInsertion(t,1),i.modelRange=i.modelRange._getTransformedByInsertion(t,1)[0]}}(n.consumable.test(i.viewItem,{attributes:s+"-end-after"})||n.consumable.test(i.viewItem,{attributes:s+"-start-after"})||n.consumable.test(i.viewItem,{attributes:s+"-end-before"})||n.consumable.test(i.viewItem,{attributes:s+"-start-before"}))&&(i.modelRange||Object.assign(i,n.convertChildren(i.viewItem,i.modelCursor)),n.consumable.consume(i.viewItem,{attributes:s+"-end-after"})&&o(i.modelRange.end,i.viewItem.getAttribute(s+"-end-after").split(",")),n.consumable.consume(i.viewItem,{attributes:s+"-start-after"})&&o(i.modelRange.end,i.viewItem.getAttribute(s+"-start-after").split(",")),n.consumable.consume(i.viewItem,{attributes:s+"-end-before"})&&o(i.modelRange.start,i.viewItem.getAttribute(s+"-end-before").split(",")),n.consumable.consume(i.viewItem,{attributes:s+"-start-before"})&&o(i.modelRange.start,i.viewItem.getAttribute(s+"-start-before").split(",")))}}(t),{priority:o+a})}}(e))}};function Fr(e){const t=Lr(e=L(e)),i=Nr(e.view),n=i?`element:${i}`:"element";return i=>{i.on(n,t,{priority:e.converterPriority||"normal"})}}function Nr(e){return"string"==typeof e?e:"object"==typeof e&&"string"==typeof e.name?e.name:null}function Lr(e){const t=new En(e.view);return(i,n,s)=>{const o=t.match(n.viewItem);if(!o)return;const r=o.match;if(r.name=!0,!s.consumable.test(n.viewItem,r))return;const a=function(e,t,i){return e instanceof Function?e(t,i):i.writer.createElement(e)}(e.model,n.viewItem,s);a&&s.safeInsert(a,n.modelCursor)&&(s.consumable.consume(n.viewItem,r),s.convertChildren(n.viewItem,a),s.updateConversionResult(a,n))}}function Dr(e,t=null){const i=null===t||(e=>e.getAttribute(t));e.model={key:"object"!=typeof e.model?e.model:e.model.key,value:"object"!=typeof e.model||void 0===e.model.value?i:e.model.value}}function zr(e,t){const i=new En(e.view);return(n,s,o)=>{if(!s.modelRange&&t)return;const r=i.match(s.viewItem);if(!r)return;if(!function(e,t){const i="function"==typeof e?e(t):e;return!("object"==typeof i&&!Nr(i))&&(!i.classes&&!i.attributes&&!i.styles)}(e.view,s.viewItem)?delete r.match.name:r.match.name=!0,!o.consumable.test(s.viewItem,r.match))return;const a=e.model.key,l="function"==typeof e.model.value?e.model.value(s.viewItem,o,s):e.model.value;null!=l&&(s.modelRange||Object.assign(s,o.convertChildren(s.viewItem,s.modelCursor)),function(e,t,i,n){let s=!1;for(const o of Array.from(e.getItems({shallow:i})))n.schema.checkAttribute(o,t.key)&&(s=!0,o.hasAttribute(t.key)||n.writer.setAttribute(t.key,t.value,o));return s}(s.modelRange,{key:a,value:l},t,o)&&(o.consumable.test(s.viewItem,{name:!0})&&(r.match.name=!0),o.consumable.consume(s.viewItem,r.match)))}}function Hr(e,t){return{view:`${e.view}-${t}`,model:(t,i)=>{const n=t.getAttribute("name"),s=e.model(n,i);return i.writer.createElement("$marker",{"data-name":s})}}}const $r=De();var Wr=class extends $r{model;view;mapper;downcastDispatcher;constructor(e,t){super(),this.model=e,this.view=new Co(t),this.mapper=new No,this.downcastDispatcher=new Wo({mapper:this.mapper,schema:e.schema});const i=this.model.document,n=i.selection,s=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(e=>{this.downcastDispatcher.convertChanges(i.differ,s,e),this.downcastDispatcher.convertSelection(n,s,e)})},{priority:"low"}),this.listenTo(this.view.document,"selectionChange",function(e,t){return(i,n)=>{const s=n.newSelection,o=[];for(const e of s.getRanges())o.push(t.toModelRange(e));const r=e.createSelection(o,{backward:s.isBackward});r.isEqual(e.document.selection)||e.change(e=>{e.setSelection(r)})}}(this.model,this.mapper)),this.downcastDispatcher.on("insert:$text",(e,t,i)=>{if(!i.consumable.consume(t.item,e.name))return;const n=i.writer,s=i.mapper.toViewPosition(t.range.start),o=n.createText(t.item.data);n.insert(s,o)},{priority:"lowest"}),this.downcastDispatcher.on("insert",(e,t,i)=>{i.convertAttributes(t.item),t.reconversion||!t.item.is("element")||t.item.isEmpty||i.convertChildren(t.item)},{priority:"lowest"}),this.downcastDispatcher.on("remove",(e,t,i)=>{if(t.reconversion)return;const n=i.mapper.toViewPosition(t.position),s=t.position.getShiftedBy(t.length),o=i.mapper.toViewPosition(s,{isPhantom:!0});_r(i.writer.createRange(n,o).getTrimmed(),i)},{priority:"low"}),this.downcastDispatcher.on("cleanSelection",(e,t,i)=>{const n=i.writer,s=n.document.selection;for(const e of s.getRanges())e.isCollapsed&&e.end.parent.isAttached()&&i.writer.mergeAttributes(e.start);n.setSelection(null)}),this.downcastDispatcher.on("selection",(e,t,i)=>{const n=t.selection;if(n.isCollapsed)return;if(!i.consumable.consume(n,"selection"))return;const s=[];for(const e of n.getRanges())s.push(i.mapper.toViewRange(e));i.writer.setSelection(s,{backward:n.isBackward})},{priority:"low"}),this.downcastDispatcher.on("selection",(e,t,i)=>{const n=t.selection;if(!n.isCollapsed)return;if(!i.consumable.consume(n,"selection"))return;const s=i.writer,o=n.getFirstPosition(),r=i.mapper.toViewPosition(o),a=s.breakAttributes(r);s.setSelection(a)},{priority:"low"}),this.view.document.roots.bindTo(this.model.document.roots).using(e=>{if("$graveyard"==e.rootName)return null;const t=new Wn(this.view.document,e.name);return t.rootName=e.rootName,this.mapper.bindElements(e,t),t})}destroy(){this.view.destroy(),this.stopListening()}reconvertMarker(e){const t="string"==typeof e?e:e.name,i=this.model.markers.get(t);if(!i)throw new fe("editingcontroller-reconvertmarker-marker-not-exist",this,{markerName:t});this.model.change(()=>{this.model.markers._refresh(i)})}reconvertItem(e){this.model.change(()=>{this.model.document.differ._refreshItem(e)})}};const Ur=De();var qr=class extends Ur{_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,t)=>{t[0]=new jr(t[0])},{priority:"highest"}),this.on("checkChild",(e,t)=>{t[0]=new jr(t[0]),t[1]=this.getDefinition(t[1])},{priority:"highest"})}register(e,t){if(this._sourceDefinitions[e])throw new fe("schema-cannot-register-item-twice",this,{itemName:e});this._sourceDefinitions[e]=[Object.assign({},t)],this._clearCache()}extend(e,t){if(!this._sourceDefinitions[e])throw new fe("schema-cannot-extend-missing-item",this,{itemName:e});this._sourceDefinitions[e].push(Object.assign({},t)),this._clearCache()}getDefinitions(){return this._compiledDefinitions||this._compile(),this._compiledDefinitions}getDefinition(e){let t;return t="string"==typeof e?e:"is"in e&&(e.is("$text")||e.is("$textProxy"))?"$text":e.name,this.getDefinitions()[t]}isRegistered(e){return!!this.getDefinition(e)}isBlock(e){const t=this.getDefinition(e);return!(!t||!t.isBlock)}isLimit(e){const t=this.getDefinition(e);return!!t&&!(!t.isLimit&&!t.isObject)}isObject(e){const t=this.getDefinition(e);return!!t&&!!(t.isObject||t.isLimit&&t.isSelectable&&t.isContent)}isInline(e){const t=this.getDefinition(e);return!(!t||!t.isInline)}isSelectable(e){const t=this.getDefinition(e);return!!t&&!(!t.isSelectable&&!t.isObject)}isContent(e){const t=this.getDefinition(e);return!!t&&!(!t.isContent&&!t.isObject)}checkChild(e,t){return!!t&&this._checkContextMatch(e,t)}checkAttribute(e,t){const i=this.getDefinition(e.last);if(!i)return!1;const n=this._evaluateAttributeChecks(e,t);return void 0!==n?n:i.allowAttributes.includes(t)}checkMerge(e,t){if(e instanceof Po){const t=e.nodeBefore,i=e.nodeAfter;if(!(t instanceof hr))throw new fe("schema-check-merge-no-element-before",this);if(!(i instanceof hr))throw new fe("schema-check-merge-no-element-after",this);return this.checkMerge(t,i)}if(this.isLimit(e)||this.isLimit(t))return!1;for(const i of t.getChildren())if(!this.checkChild(e,i))return!1;return!0}addChildCheck(e,t){const i=void 0!==t?t:this._genericCheckSymbol,n=this._customChildChecks.get(i)||[];n.push(e),this._customChildChecks.set(i,n)}addAttributeCheck(e,t){const i=void 0!==t?t:this._genericCheckSymbol,n=this._customAttributeChecks.get(i)||[];n.push(e),this._customAttributeChecks.set(i,n)}setAttributeProperties(e,t){this._attributeProperties[e]=Object.assign(this.getAttributeProperties(e),t)}getAttributeProperties(e){return this._attributeProperties[e]||Object.create(null)}getLimitElement(e){let t;for(t=e instanceof Po?e.parent:(e instanceof Bo?[e]:Array.from(e.getRanges())).reduce((e,t)=>{const i=t.getCommonAncestor();return e?e.getCommonAncestor(i,{includeSelf:!0}):i},null);!this.isLimit(t)&&t.parent;)t=t.parent;return t}checkAttributeInSelection(e,t){if(e.isCollapsed){const i=[...e.getFirstPosition().getAncestors(),new or("",e.getAttributes())];return this.checkAttribute(i,t)}{const i=e.getRanges();for(const e of i)for(const i of e)if(this.checkAttribute(i.item,t))return!0}return!1}*getValidRanges(e,t,i={}){e=function*(e){for(const t of e)yield*t.getMinimalFlatRanges()}(e);for(const n of e)yield*this._getValidRangesForRange(n,t,i)}getNearestSelectionRange(e,t="both"){if("$graveyard"==e.root.rootName)return null;if(this.checkChild(e,"$text"))return new Bo(e);let i,n;const s=e.getAncestors().reverse().find(e=>this.isLimit(e))||e.root;"both"!=t&&"backward"!=t||(i=new Eo({boundaries:Bo._createIn(s),startPosition:e,direction:"backward"})),"both"!=t&&"forward"!=t||(n=new Eo({boundaries:Bo._createIn(s),startPosition:e}));for(const e of function*(e,t){let i=!1;for(;!i;){if(i=!0,e){const t=e.next();t.done||(i=!1,yield{walker:e,value:t.value})}if(t){const e=t.next();e.done||(i=!1,yield{walker:t,value:e.value})}}}(i,n)){const t=e.walker==i?"elementEnd":"elementStart",n=e.value;if(n.type==t&&this.isObject(n.item))return Bo._createOn(n.item);if(this.checkChild(n.nextPosition,"$text"))return new Bo(n.nextPosition)}return null}findAllowedParent(e,t){let i=e.parent;for(;i;){if(this.checkChild(i,t))return i;if(this.isLimit(i))return null;i=i.parent}return null}setAllowedAttributes(e,t,i){const n=i.model;for(const[s,o]of Object.entries(t))n.schema.checkAttribute(e,s)&&i.setAttribute(s,o,e)}removeDisallowedAttributes(e,t){for(const i of e)if(i.is("$text"))oa(this,i,t);else{const e=Bo._createIn(i).getPositions();for(const i of e){oa(this,i.nodeBefore||i.parent,t)}}}getAttributesWithProperty(e,t,i){const n={};for(const[s,o]of e.getAttributes()){const e=this.getAttributeProperties(s);void 0!==e[t]&&(void 0!==i&&i!==e[t]||(n[s]=o))}return n}createContext(e){return new jr(e)}_clearCache(){this._compiledDefinitions=null}_compile(){const e={},t=this._sourceDefinitions,i=Object.keys(t);for(const n of i)e[n]=Kr(t[n],n);const n=Object.values(e);for(const t of n)Gr(e,t),Jr(e,t),Qr(e,t),Yr(e,t);for(const t of n)Xr(e,t);for(const t of n)Zr(e,t);for(const t of n)ea(e,t);for(const t of n)ta(e,t);for(const t of n)ia(e,t);this._compiledDefinitions=function(e){const t={};for(const i of Object.values(e))t[i.name]={name:i.name,isBlock:!!i.isBlock,isContent:!!i.isContent,isInline:!!i.isInline,isLimit:!!i.isLimit,isObject:!!i.isObject,isSelectable:!!i.isSelectable,allowIn:Array.from(i.allowIn).filter(t=>!!e[t]),allowChildren:Array.from(i.allowChildren).filter(t=>!!e[t]),allowAttributes:Array.from(i.allowAttributes)};return t}(e)}_checkContextMatch(e,t){const i=e.last;let n=this._evaluateChildChecks(e,t);if(n=void 0!==n?n:t.allowIn.includes(i.name),!n)return!1;const s=this.getDefinition(i),o=e.trimLast();return!!s&&(0==o.length||this._checkContextMatch(o,s))}_evaluateChildChecks(e,t){const i=this._customChildChecks.get(this._genericCheckSymbol)||[],n=this._customChildChecks.get(t.name)||[];for(const s of[...i,...n]){const i=s(e,t);if(void 0!==i)return i}}_evaluateAttributeChecks(e,t){const i=this._customAttributeChecks.get(this._genericCheckSymbol)||[],n=this._customAttributeChecks.get(t)||[];for(const s of[...i,...n]){const i=s(e,t);if(void 0!==i)return i}}*_getValidRangesForRange(e,t,i){let n=e.start,s=e.start;for(const o of e.getItems({shallow:!0})){if(o.is("element"))if(i.includeEmptyRanges&&o.isEmpty){const e=this.createContext(o);this.checkChild(e,"$text")&&this.checkAttribute(e.push("$text"),t)&&(yield Bo._createIn(o))}else yield*this._getValidRangesForRange(Bo._createIn(o),t,i);this.checkAttribute(o,t)||(n.isEqual(s)||(yield new Bo(n,s)),n=Po._createAfter(o)),s=Po._createAfter(o)}n.isEqual(s)||(yield new Bo(n,s))}findOptimalInsertionRange(e,t){const i=e.getSelectedElement();if(i&&this.isObject(i)&&!this.isInline(i))return"before"==t||"after"==t?new Bo(Po._createAt(i,t)):Bo._createOn(i);const n=ai(e.getSelectedBlocks());if(!n)return new Bo(e.focus);if(n.isEmpty)return new Bo(Po._createAt(n,0));const s=Po._createAfter(n);return e.focus.isTouching(s)?new Bo(s):new Bo(Po._createBefore(n))}},jr=class e{_items;constructor(t){if(t instanceof e)return t;let i;i="string"==typeof t?[t]:Array.isArray(t)?t:t.getAncestors({includeSelf:!0}),this._items=i.map(sa)}get length(){return this._items.length}get last(){return this._items[this._items.length-1]}[Symbol.iterator](){return this._items[Symbol.iterator]()}push(t){const i=new e([t]);return i._items=[...this._items,...i._items],i}trimLast(){const t=new e([]);return t._items=this._items.slice(0,-1),t}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 Kr(e,t){const i={name:t,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 function(e,t){for(const i of e){const e=Object.keys(i).filter(e=>e.startsWith("is"));for(const n of e)t[n]=!!i[n]}}(e,i),na(e,i,"allowIn"),na(e,i,"allowChildren"),na(e,i,"disallowIn"),na(e,i,"disallowChildren"),na(e,i,"allowContentOf"),na(e,i,"allowWhere"),na(e,i,"allowAttributes"),na(e,i,"disallowAttributes"),na(e,i,"allowAttributesOf"),na(e,i,"inheritTypesFrom"),function(e,t){for(const i of e){const e=i.inheritAllFrom;e&&(t.allowContentOf.add(e),t.allowWhere.add(e),t.allowAttributesOf.add(e),t.inheritTypesFrom.add(e))}}(e,i),i}function Gr(e,t){for(const i of t.allowIn){const n=e[i];n?n.allowChildren.add(t.name):t.allowIn.delete(i)}}function Jr(e,t){for(const i of t.allowChildren){const n=e[i];n?n.allowIn.add(t.name):t.allowChildren.delete(i)}}function Qr(e,t){for(const i of t.disallowIn){const n=e[i];n?n.disallowChildren.add(t.name):t.disallowIn.delete(i)}}function Yr(e,t){for(const i of t.disallowChildren){const n=e[i];n?n.disallowIn.add(t.name):t.disallowChildren.delete(i)}}function Xr(e,t){for(const e of t.disallowChildren)t.allowChildren.delete(e);for(const e of t.disallowIn)t.allowIn.delete(e);for(const e of t.disallowAttributes)t.allowAttributes.delete(e)}function Zr(e,t){for(const i of t.allowContentOf){const n=e[i];n&&(n.disallowChildren.forEach(i=>{t.allowChildren.has(i)||(t.disallowChildren.add(i),e[i].disallowIn.add(t.name))}),n.allowChildren.forEach(i=>{t.disallowChildren.has(i)||(t.allowChildren.add(i),e[i].allowIn.add(t.name))}))}}function ea(e,t){for(const i of t.allowWhere){const n=e[i];n&&(n.disallowIn.forEach(i=>{t.allowIn.has(i)||(t.disallowIn.add(i),e[i].disallowChildren.add(t.name))}),n.allowIn.forEach(i=>{t.disallowIn.has(i)||(t.allowIn.add(i),e[i].allowChildren.add(t.name))}))}}function ta(e,t){for(const i of t.allowAttributesOf){const n=e[i];if(!n)return;n.allowAttributes.forEach(e=>{t.disallowAttributes.has(e)||t.allowAttributes.add(e)})}}function ia(e,t){for(const i of t.inheritTypesFrom){const n=e[i];if(n){const e=Object.keys(n).filter(e=>e.startsWith("is"));for(const i of e)i in t||(t[i]=n[i])}}}function na(e,t,i){for(const n of e){let e=n[i];"string"==typeof e&&(e=[e]),Array.isArray(e)&&e.forEach(e=>t[i].add(e))}}function sa(e){return"string"==typeof e||e.is("documentFragment")?{name:"string"==typeof e?e:"$documentFragment",*getAttributeKeys(){},getAttribute(){}}:{name:e.is("element")?e.name:"$text",*getAttributeKeys(){yield*e.getAttributeKeys()},getAttribute:t=>e.getAttribute(t)}}function oa(e,t,i){for(const n of t.getAttributeKeys())e.checkAttribute(t,n)||i.removeAttribute(n,t)}const ra=Te();var aa=class extends ra{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:(e,t)=>this._convertItem(e,t),convertChildren:(e,t)=>this._convertChildren(e,t),safeInsert:(e,t)=>this._safeInsert(e,t),updateConversionResult:(e,t)=>this._updateConversionResult(e,t),splitToAllowedParent:(e,t)=>this._splitToAllowedParent(e,t),getSplitParts:e=>this._getSplitParts(e),keepEmptyElement:e=>this._keepEmptyElement(e)}}convert(e,t,i=["$root"]){this.fire("viewCleanup",e),this._modelCursor=function(e,t){let i;for(const n of new jr(e)){const e={};for(const t of n.getAttributeKeys())e[t]=n.getAttribute(t);const s=t.createElement(n.name,e);i&&t.insert(s,i),i=Po._createAt(s,0)}return i}(i,t),this.conversionApi.writer=t,this.conversionApi.consumable=kn.createFrom(e),this.conversionApi.store={};const{modelRange:n}=this._convertItem(e,this._modelCursor),s=t.createDocumentFragment();if(n){this._removeEmptyElements();const e=this._modelCursor.parent,i=e._removeChildren(0,e.childCount);s._insertChild(0,i),s.markers=function(e,t){const i=new Set,n=new Map,s=Bo._createIn(e).getItems();for(const e of s)e.is("element","$marker")&&i.add(e);for(const e of i){const i=e.getAttribute("data-name"),s=t.createPositionBefore(e);n.has(i)?n.get(i).end=s.clone():n.set(i,new Bo(s.clone())),t.remove(e)}return n}(s,t)}return this._modelCursor=null,this._splitParts.clear(),this._cursorParents.clear(),this._emptyElementsToKeep.clear(),this.conversionApi.writer=null,this.conversionApi.store=null,s}_convertItem(e,t){const i={viewItem:e,modelCursor:t,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 Bo))throw new fe("view-conversion-dispatcher-incorrect-result",this);return{modelRange:i.modelRange,modelCursor:i.modelCursor}}_convertChildren(e,t){let i=t.is("position")?t:Po._createAt(t,0);const n=new Bo(i);for(const t of Array.from(e.getChildren())){const e=this._convertItem(t,i);e.modelRange instanceof Bo&&(n.end=e.modelRange.end,i=e.modelCursor)}return{modelRange:n,modelCursor:i}}_safeInsert(e,t){const i=this._splitToAllowedParent(e,t);return!!i&&(this.conversionApi.writer.insert(e,i.position),!0)}_updateConversionResult(e,t){const i=this._getSplitParts(e),n=this.conversionApi.writer;t.modelRange||(t.modelRange=n.createRange(n.createPositionBefore(e),n.createPositionAfter(i[i.length-1])));const s=this._cursorParents.get(e);t.modelCursor=s?n.createPositionAt(s,0):t.modelRange.end}_splitToAllowedParent(e,t){const{schema:i,writer:n}=this.conversionApi;let s=i.findAllowedParent(t,e);if(s){if(s===t.parent)return{position:t};this._modelCursor.parent.getAncestors().includes(s)&&(s=null)}if(!s)return Rr(t,e,i)?{position:Br(t,n)}:null;const o=this.conversionApi.writer.split(t,s),r=[];for(const e of o.range.getWalker())if("elementEnd"==e.type)r.push(e.item);else{const t=r.pop(),i=e.item;this._registerSplitPair(t,i)}const a=o.range.end.parent;return this._cursorParents.set(e,a),{position:o.position,cursorParent:a}}_registerSplitPair(e,t){this._splitParts.has(e)||this._splitParts.set(e,[e]);const i=this._splitParts.get(e);this._splitParts.set(t,i),i.push(t)}_getSplitParts(e){let t;return t=this._splitParts.has(e)?this._splitParts.get(e):[e],t}_keepEmptyElement(e){this._emptyElementsToKeep.add(e)}_removeEmptyElements(){const e=new Map;for(const t of this._splitParts.keys())if(t.isEmpty&&!this._emptyElementsToKeep.has(t)){const i=e.get(t.parent)||[];i.push(t),this._splitParts.delete(t),e.set(t.parent,i)}for(const[t,i]of e)t._removeChildrenArray(i);e.size&&this._removeEmptyElements()}};var la=class{getHtml(e){const t=G.document.implementation.createHTMLDocument("").createElement("div");return t.appendChild(e),t.innerHTML}},ca=class{domParser;domConverter;htmlWriter;skipComments=!0;constructor(e){this.domParser=new DOMParser,this.domConverter=new Ys(e,{renderingMode:"data"}),this.htmlWriter=new la}toData(e){const t=this.domConverter.viewToDom(e);return this.htmlWriter.getHtml(t)}toView(e){const t=this._toDom(e);return this.domConverter.domToView(t,{skipComments:this.skipComments})}registerRawContentMatcher(e){this.domConverter.registerRawContentMatcher(e)}useFillerType(e){this.domConverter.blockFillerMode="marked"==e?"markedNbsp":"nbsp"}_toDom(e){/<(?:html|body|head|meta)(?:\s[^>]*)?>/i.test(e.trim().slice(0,1e4))||(e=`${e}`);const t=this.domParser.parseFromString(e,"text/html"),i=t.createDocumentFragment(),n=t.body.childNodes;for(;n.length>0;)i.appendChild(n[0]);return i}};const da=Te();var ua=class extends da{model;mapper;downcastDispatcher;upcastDispatcher;viewDocument;stylesProcessor;htmlProcessor;processor;_viewWriter;constructor(e,t){super(),this.model=e,this.mapper=new No,this.downcastDispatcher=new Wo({mapper:this.mapper,schema:e.schema}),this.downcastDispatcher.on("insert:$text",(e,t,i)=>{if(!i.consumable.consume(t.item,e.name))return;const n=i.writer,s=i.mapper.toViewPosition(t.range.start),o=n.createText(t.item.data);n.insert(s,o)},{priority:"lowest"}),this.downcastDispatcher.on("insert",(e,t,i)=>{i.convertAttributes(t.item),t.reconversion||!t.item.is("element")||t.item.isEmpty||i.convertChildren(t.item)},{priority:"lowest"}),this.upcastDispatcher=new aa({schema:e.schema}),this.viewDocument=new cs(t),this.stylesProcessor=t,this.htmlProcessor=new ca(this.viewDocument),this.processor=this.htmlProcessor,this._viewWriter=new ks(this.viewDocument),this.upcastDispatcher.on("text",(e,t,{schema:i,consumable:n,writer:s})=>{let o=t.modelCursor;if(!n.test(t.viewItem))return;if(!i.checkChild(o,"$text")){if(!Rr(o,"$text",i))return;if(0==t.viewItem.data.trim().length)return;o=Br(o,s)}n.consume(t.viewItem);const r=s.createText(t.viewItem.data);s.insert(r,o),t.modelRange=s.createRange(o,o.getShiftedBy(r.offsetSize)),t.modelCursor=t.modelRange.end},{priority:"lowest"}),this.upcastDispatcher.on("element",(e,t,i)=>{if(!t.modelRange&&i.consumable.consume(t.viewItem,{name:!0})){const{modelRange:e,modelCursor:n}=i.convertChildren(t.viewItem,t.modelCursor);t.modelRange=e,t.modelCursor=n}},{priority:"lowest"}),this.upcastDispatcher.on("documentFragment",(e,t,i)=>{if(!t.modelRange&&i.consumable.consume(t.viewItem,{name:!0})){const{modelRange:e,modelCursor:n}=i.convertChildren(t.viewItem,t.modelCursor);t.modelRange=e,t.modelCursor=n}},{priority:"lowest"}),De().prototype.decorate.call(this,"init"),De().prototype.decorate.call(this,"set"),De().prototype.decorate.call(this,"get"),De().prototype.decorate.call(this,"toView"),De().prototype.decorate.call(this,"toModel"),this.on("init",()=>{this.fire("ready")},{priority:"lowest"}),this.on("ready",()=>{this.model.enqueueChange({isUndoable:!1},Or)},{priority:"lowest"})}get(e={}){const{rootName:t="main",trim:i="empty"}=e;if(!this._checkIfRootsExists([t]))throw new fe("datacontroller-get-non-existent-root",this);const n=this.model.document.getRoot(t);return n.isAttached()||pe("datacontroller-get-detached-root",this),"empty"!==i||this.model.hasContent(n,{ignoreWhitespaces:!0})?this.stringify(n,e):""}stringify(e,t={}){const i=this.toView(e,t);return this.processor.toData(i)}toView(e,t={}){const i=this.viewDocument,n=this._viewWriter;this.mapper.clearBindings();const s=Bo._createIn(e),o=new ys(i);this.mapper.bindElements(e,o);const r=e.is("documentFragment")?e.markers:function(e){const t=[],i=e.root.document;if(!i)return new Map;const n=Bo._createIn(e);for(const e of i.model.markers){const i=e.getRange(),s=i.isCollapsed,o=i.start.isEqual(n.start)||i.end.isEqual(n.end);if(s&&o)t.push([e.name,i]);else{const s=n.getIntersection(i);s&&t.push([e.name,s])}}return new Map(t)}(e);return this.downcastDispatcher.convert(s,r,n,t),o}init(e){if(this.model.document.version)throw new fe("datacontroller-init-document-not-empty",this);let t={};if("string"==typeof e?t.main=e:t=e,!this._checkIfRootsExists(Object.keys(t)))throw new fe("datacontroller-init-non-existent-root",this);return this.model.enqueueChange({isUndoable:!1},e=>{for(const i of Object.keys(t)){const n=this.model.document.getRoot(i);e.insert(this.parse(t[i],n),n,0)}}),Promise.resolve()}set(e,t={}){let i={};if("string"==typeof e?i.main=e:i=e,!this._checkIfRootsExists(Object.keys(i)))throw new fe("datacontroller-set-non-existent-root",this);this.model.enqueueChange(t.batchType||{},e=>{e.setSelection(null),e.removeSelectionAttribute(this.model.document.selection.getAttributeKeys());for(const t of Object.keys(i)){const n=this.model.document.getRoot(t);e.remove(e.createRangeIn(n)),e.insert(this.parse(i[t],n),n,0)}})}parse(e,t="$root"){const i=this.processor.toView(e);return this.toModel(i,t)}toModel(e,t="$root"){return this.model.change(i=>this.upcastDispatcher.convert(e,i,t))}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 t of e)if(!this.model.document.getRoot(t))return!1;return!0}};var ha=class{_helpers=new Map;_downcast;_upcast;constructor(e,t){this._downcast=ii(e),this._createConversionHelpers({name:"downcast",dispatchers:this._downcast,isDowncast:!0}),this._upcast=ii(t),this._createConversionHelpers({name:"upcast",dispatchers:this._upcast,isDowncast:!1})}addAlias(e,t){const i=this._downcast.includes(t);if(!this._upcast.includes(t)&&!i)throw new fe("conversion-add-alias-dispatcher-not-registered",this);this._createConversionHelpers({name:e,dispatchers:[t],isDowncast:i})}for(e){if(!this._helpers.has(e))throw new fe("conversion-for-unknown-group",this);return this._helpers.get(e)}elementToElement(e){this.for("downcast").elementToElement(e);for(const{model:t,view:i}of ma(e))this.for("upcast").elementToElement({model:t,view:i,converterPriority:e.converterPriority})}attributeToElement(e){this.for("downcast").attributeToElement(e);for(const{model:t,view:i}of ma(e))this.for("upcast").elementToAttribute({view:i,model:t,converterPriority:e.converterPriority})}attributeToAttribute(e){this.for("downcast").attributeToAttribute(e);for(const{model:t,view:i}of ma(e))this.for("upcast").attributeToAttribute({view:i,model:t})}_createConversionHelpers({name:e,dispatchers:t,isDowncast:i}){if(this._helpers.has(e))throw new fe("conversion-group-exists",this);const n=i?new gr(t):new Mr(t);this._helpers.set(e,n)}};function*ma(e){if(e.model.values)for(const t of e.model.values){const i={key:e.model.key,value:t},n=e.view[t];yield*ga(i,n,e.upcastAlso?e.upcastAlso[t]:void 0)}else yield*ga(e.model,e.view,e.upcastAlso)}function*ga(e,t,i){if(yield{model:e,view:t},i)for(const t of ii(i))yield{model:e,view:t}}var fa=class{baseVersion;isDocumentOperation;batch;constructor(e){this.baseVersion=e,this.isDocumentOperation=null!==this.baseVersion,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,t){return new this(e.baseVersion)}};function pa(e,t){const i=_a(t),n=i.reduce((e,t)=>e+t.offsetSize,0),s=e.parent;ya(e);const o=e.index;return s._insertChild(o,i),va(s,o+i.length),va(s,o),new Bo(e,e.getShiftedBy(n))}function ba(e){if(!e.isFlat)throw new fe("operation-utils-remove-range-not-flat",this);const t=e.start.parent;ya(e.start),ya(e.end);const i=t._removeChildren(e.start.index,e.end.index-e.start.index);return va(t,e.start.index),i}function wa(e,t){if(!e.isFlat)throw new fe("operation-utils-move-range-not-flat",this);const i=ba(e);return pa(t=t._getTransformedByDeletion(e.start,e.end.offset-e.start.offset),i)}function _a(e){const t=[];!function e(i){if("string"==typeof i)t.push(new or(i));else if(i instanceof To)t.push(new or(i.data,i.getAttributes()));else if(i instanceof jo)t.push(i);else if(Ge(i))for(const t of i)e(t)}(e);for(let e=1;ee.maxOffset)throw new fe("move-operation-nodes-do-not-exist",this);if(e===t&&i=i&&this.targetPosition.path[e]e._clone(!0))),i=new e(this.position,t,this.baseVersion);return i.shouldReceiveAttributes=this.shouldReceiveAttributes,i}getReversed(){const e=this.position.root.document.graveyard,t=new Po(e,[0]);return new Ca(this.position,this.nodes.maxOffset,t,this.baseVersion+1)}_validate(){const e=this.position.parent;if(!e||e.maxOffsete._clone(!0))),pa(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(t,i){const n=[];for(const e of t.nodes)e.name?n.push(hr.fromJSON(e)):n.push(or.fromJSON(e));const s=new e(Po.fromJSON(t.position,i),n,t.baseVersion);return s.shouldReceiveAttributes=t.shouldReceiveAttributes,s}},Ta=class e extends fa{splitPosition;howMany;insertionPosition;graveyardPosition;constructor(e,t,i,n,s){super(s),this.splitPosition=e.clone(),this.splitPosition.stickiness="toNext",this.howMany=t,this.insertionPosition=i,this.graveyardPosition=n?n.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 Po(this.insertionPosition.root,e)}get movedRange(){const e=this.splitPosition.getShiftedBy(Number.POSITIVE_INFINITY);return new Bo(this.splitPosition,e)}get affectedSelectable(){const e=[Bo._createFromPositionAndShift(this.splitPosition,0),Bo._createFromPositionAndShift(this.insertionPosition,0)];return this.graveyardPosition&&e.push(Bo._createFromPositionAndShift(this.graveyardPosition,0)),e}clone(){return new e(this.splitPosition,this.howMany,this.insertionPosition,this.graveyardPosition,this.baseVersion)}getReversed(){const e=this.splitPosition.root.document.graveyard,t=new Po(e,[0]);return new Ea(this.moveTargetPosition,this.howMany,this.splitPosition,t,this.baseVersion+1)}_validate(){const e=this.splitPosition.parent,t=this.splitPosition.offset;if(!e||e.maxOffset1&&e.sourcePosition.isEqual(t.deletionPosition)?this._setRelation(e,t,"firstToMoveMerged"):e.howMany>1&&e.sourcePosition.getShiftedBy(e.howMany-1).isEqual(t.deletionPosition)&&this._setRelation(e,t,"lastToMoveMerged"):t instanceof Ca&&(e.targetPosition.isEqual(t.sourcePosition)||e.targetPosition.isBefore(t.sourcePosition)?this._setRelation(e,t,"insertBefore"):this._setRelation(e,t,"insertAfter"));else if(e instanceof Ta){if(t instanceof Ea)e.splitPosition.isBefore(t.sourcePosition)&&this._setRelation(e,t,"splitBefore");else if(t instanceof Ca)if(e.splitPosition.isEqual(t.sourcePosition)||e.splitPosition.isBefore(t.sourcePosition))this._setRelation(e,t,"splitBefore");else{const i=Bo._createFromPositionAndShift(t.sourcePosition,t.howMany);if(e.splitPosition.hasSameParentAs(t.sourcePosition)&&i.containsPosition(e.splitPosition)){const n=i.end.offset-e.splitPosition.offset,s=e.splitPosition.offset-i.start.offset;this._setRelation(e,t,{howMany:n,offset:s})}}}else if(e instanceof Ea)t instanceof Ea?(e.targetPosition.isEqual(t.sourcePosition)||this._setRelation(e,t,"mergeTargetNotMoved"),e.sourcePosition.isEqual(t.targetPosition)&&this._setRelation(e,t,"mergeSourceNotMoved"),e.sourcePosition.isEqual(t.sourcePosition)&&this._setRelation(e,t,"mergeSameElement")):t instanceof Ta?e.sourcePosition.isEqual(t.splitPosition)&&this._setRelation(e,t,"splitAtSource"):t instanceof Ca&&t.howMany>0&&(e.sourcePosition.isEqual(t.sourcePosition.getShiftedBy(t.howMany))&&this._setRelation(e,t,"mergeSourceAffected"),e.targetPosition.isEqual(t.sourcePosition)&&this._setRelation(e,t,"mergeTargetWasBefore"));else if(e instanceof xa){const i=e.newRange;if(!i)return;if(t instanceof Ea){const n=i.start.isEqual(t.targetPosition),s=i.start.isEqual(t.deletionPosition),o=i.end.isEqual(t.deletionPosition),r=i.end.isEqual(t.sourcePosition);(n||s||o||r)&&this._setRelation(e,t,{wasInLeftElement:n,wasStartBeforeMergedElement:s,wasEndBeforeMergedElement:o,wasInRightElement:r})}}}getContext(e,t,i){return{aIsStrong:i,aWasUndone:this._wasUndone(e),bWasUndone:this._wasUndone(t),abRelation:this._useRelations?this._getRelation(e,t):null,baRelation:this._useRelations?this._getRelation(t,e):null,forceWeakRemove:this._forceWeakRemove}}_wasUndone(e){const t=this.originalOperations.get(e);return t.wasUndone||this._history.isUndoneOperation(t)}_getRelation(e,t){const i=this.originalOperations.get(t),n=this._history.getUndoneOperation(i);if(!n)return null;const s=this.originalOperations.get(e),o=this._relations.get(s);return o&&o.get(n)||null}_setRelation(e,t,i){const n=this.originalOperations.get(e),s=this.originalOperations.get(t);let o=this._relations.get(n);o||(o=new Map,this._relations.set(n,o)),o.set(s,i)}};function Ha(e,t){for(const i of e)i.baseVersion=t++}function $a(e,t){for(let i=0;i{if(e.key===t.key&&e.range.start.hasSameParentAs(t.range.start)){const n=e.range.getDifference(t.range).map(t=>new Pa(t,e.key,e.oldValue,e.newValue,0)),s=e.range.getIntersection(t.range);return s&&i.aIsStrong&&n.push(new Pa(s,t.key,t.newValue,e.newValue,0)),0==n.length?[new Sa(0)]:n}return[e]}),Fa(Pa,Aa,(e,t)=>{if(e.range.start.hasSameParentAs(t.position)&&e.range.containsPosition(t.position)){const i=e.range._getTransformedByInsertion(t.position,t.howMany,!t.shouldReceiveAttributes).map(t=>new Pa(t,e.key,e.oldValue,e.newValue,e.baseVersion));if(t.shouldReceiveAttributes){const n=Ua(t,e.key,e.oldValue);n&&i.unshift(n)}return i}return e.range=e.range._getTransformedByInsertion(t.position,t.howMany,!1)[0],[e]}),Fa(Pa,Ea,(e,t)=>{const i=[];e.range.start.hasSameParentAs(t.deletionPosition)&&(e.range.containsPosition(t.deletionPosition)||e.range.start.isEqual(t.deletionPosition))&&i.push(Bo._createFromPositionAndShift(t.graveyardPosition,1));const n=e.range._getTransformedByMergeOperation(t);return n.isCollapsed||i.push(n),i.map(t=>new Pa(t,e.key,e.oldValue,e.newValue,e.baseVersion))}),Fa(Pa,Ca,(e,t)=>function(e,t){const i=Bo._createFromPositionAndShift(t.sourcePosition,t.howMany);let n=null,s=[];i.containsRange(e,!0)?n=e:e.start.hasSameParentAs(i.start)?(s=e.getDifference(i),n=e.getIntersection(i)):s=[e];const o=[];for(let e of s){e=e._getTransformedByDeletion(t.sourcePosition,t.howMany);const i=t.getMovedRangeStart(),n=e.start.hasSameParentAs(i),s=e._getTransformedByInsertion(i,t.howMany,n);o.push(...s)}n&&o.push(n._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany,!1)[0]);return o}(e.range,t).map(t=>new Pa(t,e.key,e.oldValue,e.newValue,e.baseVersion))),Fa(Pa,Ta,(e,t)=>{if(e.range.end.isEqual(t.insertionPosition))return t.graveyardPosition||e.range.end.offset++,[e];if(e.range.start.hasSameParentAs(t.splitPosition)&&e.range.containsPosition(t.splitPosition)){const i=e.clone();return i.range=new Bo(t.moveTargetPosition.clone(),e.range.end._getCombined(t.splitPosition,t.moveTargetPosition)),e.range.end=t.splitPosition.clone(),e.range.end.stickiness="toPrevious",[e,i]}return e.range=e.range._getTransformedBySplitOperation(t),[e]}),Fa(Aa,Pa,(e,t)=>{const i=[e];if(e.shouldReceiveAttributes&&e.position.hasSameParentAs(t.range.start)&&t.range.containsPosition(e.position)){const n=Ua(e,t.key,t.newValue);n&&i.push(n)}return i}),Fa(Aa,Aa,(e,t,i)=>(e.position.isEqual(t.position)&&i.aIsStrong||(e.position=e.position._getTransformedByInsertOperation(t)),[e])),Fa(Aa,Ca,(e,t)=>(e.position=e.position._getTransformedByMoveOperation(t),[e])),Fa(Aa,Ta,(e,t)=>(e.position=e.position._getTransformedBySplitOperation(t),[e])),Fa(Aa,Ea,(e,t)=>(e.position=e.position._getTransformedByMergeOperation(t),[e])),Fa(xa,Aa,(e,t)=>(e.oldRange&&(e.oldRange=e.oldRange._getTransformedByInsertOperation(t)[0]),e.newRange&&(e.newRange=e.newRange._getTransformedByInsertOperation(t)[0]),[e])),Fa(xa,xa,(e,t,i)=>{if(e.name==t.name){if(!i.aIsStrong)return[new Sa(0)];e.oldRange=t.newRange?t.newRange.clone():null}return[e]}),Fa(xa,Ea,(e,t)=>(e.oldRange&&(e.oldRange=e.oldRange._getTransformedByMergeOperation(t)),e.newRange&&(e.newRange=e.newRange._getTransformedByMergeOperation(t)),[e])),Fa(xa,Ca,(e,t)=>{const i=[e];if(e.oldRange&&(e.oldRange=Bo._createFromRanges(e.oldRange._getTransformedByMoveOperation(t))),e.newRange){const n=e.newRange._getTransformedByMoveOperation(t);e.newRange=n[0];for(let t=1;t{if(e.oldRange&&(e.oldRange=e.oldRange._getTransformedBySplitOperation(t)),e.newRange){if(i.abRelation){const n=e.newRange._getTransformedBySplitOperation(t);return e.newRange.start.isEqual(t.splitPosition)?i.abRelation.wasStartBeforeMergedElement?e.newRange.start=Po._createAt(t.insertionPosition):i.abRelation.wasInLeftElement?e.newRange.start=Po._createAt(e.newRange.start):e.newRange.start=Po._createAt(t.moveTargetPosition):e.newRange.start=n.start,e.newRange.end.isEqual(t.splitPosition)?e.newRange.end.isEqual(t.splitPosition)&&i.abRelation.wasEndBeforeMergedElement?e.newRange.end=Po._createAt(t.insertionPosition):i.abRelation.wasInRightElement?e.newRange.end=Po._createAt(t.moveTargetPosition):e.newRange.end=Po._createAt(e.newRange.end):e.newRange.end=n.end,[e]}e.newRange=e.newRange._getTransformedBySplitOperation(t)}return[e]}),Fa(Ea,Aa,(e,t)=>(e.sourcePosition.hasSameParentAs(t.position)&&(e.howMany+=t.howMany),e.sourcePosition=e.sourcePosition._getTransformedByInsertOperation(t),e.targetPosition=e.targetPosition._getTransformedByInsertOperation(t),[e])),Fa(Ea,Ea,(e,t,i)=>{if(e.sourcePosition.isEqual(t.sourcePosition)&&e.targetPosition.isEqual(t.targetPosition)){if(i.bWasUndone){const i=t.graveyardPosition.path.slice();return i.push(0),e.sourcePosition=new Po(t.graveyardPosition.root,i),e.howMany=0,[e]}return[new Sa(0)]}if(e.sourcePosition.isEqual(t.sourcePosition)&&!e.targetPosition.isEqual(t.targetPosition)&&!i.bWasUndone&&"splitAtSource"!=i.abRelation){const n="$graveyard"==e.targetPosition.root.rootName,s="$graveyard"==t.targetPosition.root.rootName;if(s&&!n||(!n||s)&&i.aIsStrong){const i=t.targetPosition._getTransformedByMergeOperation(t),n=e.targetPosition._getTransformedByMergeOperation(t);return[new Ca(i,e.howMany,n,0)]}return[new Sa(0)]}return e.sourcePosition.hasSameParentAs(t.targetPosition)&&(e.howMany+=t.howMany),e.sourcePosition=e.sourcePosition._getTransformedByMergeOperation(t),e.targetPosition=e.targetPosition._getTransformedByMergeOperation(t),e.graveyardPosition.isEqual(t.graveyardPosition)&&i.aIsStrong||(e.graveyardPosition=e.graveyardPosition._getTransformedByMergeOperation(t)),[e]}),Fa(Ea,Ca,(e,t,i)=>{const n=Bo._createFromPositionAndShift(t.sourcePosition,t.howMany);return"remove"==t.type&&!i.bWasUndone&&e.deletionPosition.hasSameParentAs(t.sourcePosition)&&n.containsPosition(e.sourcePosition)?[new Sa(0)]:(t.sourcePosition.getShiftedBy(t.howMany).isEqual(e.sourcePosition)?e.sourcePosition.stickiness="toNone":t.targetPosition.isEqual(e.sourcePosition)&&"mergeSourceAffected"==i.abRelation?e.sourcePosition.stickiness="toNext":t.sourcePosition.isEqual(e.targetPosition)?(e.targetPosition.stickiness="toNone",e.howMany-=t.howMany):t.targetPosition.isEqual(e.targetPosition)&&"mergeTargetWasBefore"==i.abRelation?(e.targetPosition.stickiness="toPrevious",e.howMany+=t.howMany):(e.sourcePosition.hasSameParentAs(t.targetPosition)&&(e.howMany+=t.howMany),e.sourcePosition.hasSameParentAs(t.sourcePosition)&&(e.howMany-=t.howMany)),e.sourcePosition=e.sourcePosition._getTransformedByMoveOperation(t),e.targetPosition=e.targetPosition._getTransformedByMoveOperation(t),e.sourcePosition.stickiness="toPrevious",e.targetPosition.stickiness="toNext",e.graveyardPosition.isEqual(t.targetPosition)||(e.graveyardPosition=e.graveyardPosition._getTransformedByMoveOperation(t)),[e])}),Fa(Ea,Ta,(e,t,i)=>{if(t.graveyardPosition&&(e.graveyardPosition=e.graveyardPosition._getTransformedByDeletion(t.graveyardPosition,1),e.deletionPosition.isEqual(t.graveyardPosition)&&(e.howMany=t.howMany)),e.targetPosition.isEqual(t.splitPosition)&&(t.graveyardPosition&&e.deletionPosition.isEqual(t.graveyardPosition)||"mergeTargetNotMoved"==i.abRelation))return e.sourcePosition=e.sourcePosition._getTransformedBySplitOperation(t),[e];if(e.sourcePosition.isEqual(t.splitPosition)){if("mergeSourceNotMoved"==i.abRelation)return e.howMany=0,e.targetPosition=e.targetPosition._getTransformedBySplitOperation(t),[e];if("mergeSameElement"==i.abRelation||e.sourcePosition.offset>0)return e.sourcePosition=t.moveTargetPosition.clone(),e.targetPosition=e.targetPosition._getTransformedBySplitOperation(t),[e]}return e.sourcePosition.hasSameParentAs(t.splitPosition)&&(e.howMany=t.splitPosition.offset),e.sourcePosition=e.sourcePosition._getTransformedBySplitOperation(t),e.targetPosition=e.targetPosition._getTransformedBySplitOperation(t),[e]}),Fa(Ca,Aa,(e,t)=>{const i=Bo._createFromPositionAndShift(e.sourcePosition,e.howMany)._getTransformedByInsertOperation(t,!1)[0];return e.sourcePosition=i.start,e.howMany=i.end.offset-i.start.offset,e.targetPosition.isEqual(t.position)||(e.targetPosition=e.targetPosition._getTransformedByInsertOperation(t)),[e]}),Fa(Ca,Ca,(e,t,i)=>{const n=Bo._createFromPositionAndShift(e.sourcePosition,e.howMany),s=Bo._createFromPositionAndShift(t.sourcePosition,t.howMany);let o,r=i.aIsStrong,a=!i.aIsStrong;if("insertBefore"==i.abRelation||"insertAfter"==i.baRelation?a=!0:"insertAfter"!=i.abRelation&&"insertBefore"!=i.baRelation||(a=!1),o=e.targetPosition.isEqual(t.targetPosition)&&a?e.targetPosition._getTransformedByDeletion(t.sourcePosition,t.howMany):e.targetPosition._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),qa(e,t)&&qa(t,e))return[t.getReversed()];if(n.containsPosition(t.targetPosition)&&n.containsRange(s,!0))return n.start=n.start._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),n.end=n.end._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),ja([n],o);if(s.containsPosition(e.targetPosition)&&s.containsRange(n,!0))return n.start=n.start._getCombined(t.sourcePosition,t.getMovedRangeStart()),n.end=n.end._getCombined(t.sourcePosition,t.getMovedRangeStart()),ja([n],o);const l=Ke(e.sourcePosition.getParentPath(),t.sourcePosition.getParentPath());if("prefix"==l||"extension"==l)return n.start=n.start._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),n.end=n.end._getTransformedByMove(t.sourcePosition,t.targetPosition,t.howMany),ja([n],o);"remove"!=e.type||"remove"==t.type||i.aWasUndone||i.forceWeakRemove?"remove"==e.type||"remove"!=t.type||i.bWasUndone||i.forceWeakRemove||(r=!1):r=!0;const c=[],d=n.getDifference(s);for(const e of d){e.start=e.start._getTransformedByDeletion(t.sourcePosition,t.howMany),e.end=e.end._getTransformedByDeletion(t.sourcePosition,t.howMany);const i="same"==Ke(e.start.getParentPath(),t.getMovedRangeStart().getParentPath()),n=e._getTransformedByInsertion(t.getMovedRangeStart(),t.howMany,i);c.push(...n)}const u=n.getIntersection(s);return null!==u&&r&&(u.start=u.start._getCombined(t.sourcePosition,t.getMovedRangeStart()),u.end=u.end._getCombined(t.sourcePosition,t.getMovedRangeStart()),0===c.length?c.push(u):1==c.length?s.start.isBefore(n.start)||s.start.isEqual(n.start)?c.unshift(u):c.push(u):c.splice(1,0,u)),0===c.length?[new Sa(e.baseVersion)]:ja(c,o)}),Fa(Ca,Ta,(e,t,i)=>{let n=e.targetPosition.clone();if(e.targetPosition.isEqual(t.insertionPosition)&&t.graveyardPosition&&"moveTargetAfter"!=i.abRelation||(n=e.targetPosition._getTransformedBySplitOperation(t)),e.sourcePosition.isEqual(t.insertionPosition)&&"firstToMoveMerged"==i.abRelation)return e.howMany++,e.targetPosition=n,[e];const s=Bo._createFromPositionAndShift(e.sourcePosition,e.howMany);if(s.end.isEqual(t.insertionPosition))return t.graveyardPosition&&"lastToMoveMerged"!=i.abRelation||e.howMany++,e.targetPosition=n,[e];if(s.start.hasSameParentAs(t.splitPosition)&&s.containsPosition(t.splitPosition)){let e=new Bo(t.splitPosition,s.end);return e=e._getTransformedBySplitOperation(t),ja([new Bo(s.start,t.splitPosition),e],n)}e.targetPosition.isEqual(t.splitPosition)&&"insertAtSource"==i.abRelation&&(n=t.moveTargetPosition),e.targetPosition.isEqual(t.insertionPosition)&&"insertBetween"==i.abRelation&&(n=e.targetPosition);const o=[s._getTransformedBySplitOperation(t)];if(t.graveyardPosition){const n=s.start.isEqual(t.graveyardPosition)||s.containsPosition(t.graveyardPosition);e.howMany>1&&n&&!i.aWasUndone&&o.push(Bo._createFromPositionAndShift(t.insertionPosition,1))}return ja(o,n)}),Fa(Ca,Ea,(e,t,i)=>{const n=Bo._createFromPositionAndShift(e.sourcePosition,e.howMany);if(t.deletionPosition.hasSameParentAs(e.sourcePosition)&&n.containsPosition(t.sourcePosition))if("remove"!=e.type||i.forceWeakRemove){if(1==e.howMany)return i.bWasUndone?(e.sourcePosition=t.graveyardPosition.clone(),e.targetPosition=e.targetPosition._getTransformedByMergeOperation(t),[e]):[new Sa(0)]}else if(!i.aWasUndone){const i=[];let n=t.graveyardPosition.clone(),s=t.targetPosition._getTransformedByMergeOperation(t);const o=e.targetPosition.getTransformedByOperation(t);e.howMany>1&&(i.push(new Ca(e.sourcePosition,e.howMany-1,o,0)),n=n._getTransformedByMove(e.sourcePosition,o,e.howMany-1),s=s._getTransformedByMove(e.sourcePosition,o,e.howMany-1));const r=t.deletionPosition._getCombined(e.sourcePosition,o),a=new Ca(n,1,r,0),l=a.getMovedRangeStart().path.slice();l.push(0);const c=new Po(a.targetPosition.root,l);s=s._getTransformedByMove(n,r,1);const d=new Ca(s,t.howMany,c,0);return i.push(a),i.push(d),i}const s=Bo._createFromPositionAndShift(e.sourcePosition,e.howMany)._getTransformedByMergeOperation(t);return e.sourcePosition=s.start,e.howMany=s.end.offset-s.start.offset,e.targetPosition=e.targetPosition._getTransformedByMergeOperation(t),[e]}),Fa(Ia,Aa,(e,t)=>(e.position=e.position._getTransformedByInsertOperation(t),[e])),Fa(Ia,Ea,(e,t)=>e.position.isEqual(t.deletionPosition)?(e.position=t.graveyardPosition.clone(),e.position.stickiness="toNext",[e]):(e.position=e.position._getTransformedByMergeOperation(t),[e])),Fa(Ia,Ca,(e,t)=>(e.position=e.position._getTransformedByMoveOperation(t),[e])),Fa(Ia,Ia,(e,t,i)=>{if(e.position.isEqual(t.position)){if(!i.aIsStrong)return[new Sa(0)];e.oldName=t.newName}return[e]}),Fa(Ia,Ta,(e,t)=>"same"!=Ke(e.position.path,t.splitPosition.getParentPath())||t.graveyardPosition?(e.position=e.position._getTransformedBySplitOperation(t),[e]):[e,new Ia(e.position.getShiftedBy(1),e.oldName,e.newName,0)]),Fa(Va,Va,(e,t,i)=>{if(e.root===t.root&&e.key===t.key){if(!i.aIsStrong)return[new Sa(0)];e.oldValue=t.newValue}return[e]}),Fa(Oa,Oa,(e,t)=>e.rootName===t.rootName&&e.isAdd===t.isAdd?[new Sa(0)]:[e]),Fa(Ta,Aa,(e,t)=>(e.splitPosition.hasSameParentAs(t.position)&&e.splitPosition.offset{if(!e.graveyardPosition&&!i.bWasUndone&&e.splitPosition.hasSameParentAs(t.sourcePosition)){const i=t.graveyardPosition.path.slice();i.push(0);const n=new Ta(new Po(t.graveyardPosition.root,i),0,Ta.getInsertionPosition(new Po(t.graveyardPosition.root,i)),null,0);return e.splitPosition=e.splitPosition._getTransformedByMergeOperation(t),e.insertionPosition=Ta.getInsertionPosition(e.splitPosition),e.graveyardPosition=n.insertionPosition.clone(),e.graveyardPosition.stickiness="toNext",[n,e]}return e.splitPosition.hasSameParentAs(t.deletionPosition)&&!e.splitPosition.isAfter(t.deletionPosition)&&e.howMany--,e.splitPosition.hasSameParentAs(t.targetPosition)&&(e.howMany+=t.howMany),e.splitPosition=e.splitPosition._getTransformedByMergeOperation(t),e.insertionPosition=Ta.getInsertionPosition(e.splitPosition),e.graveyardPosition&&(e.graveyardPosition=e.graveyardPosition._getTransformedByMergeOperation(t)),[e]}),Fa(Ta,Ca,(e,t,i)=>{const n=Bo._createFromPositionAndShift(t.sourcePosition,t.howMany);if(e.graveyardPosition){const s=n.start.isEqual(e.graveyardPosition)||n.containsPosition(e.graveyardPosition);if(!i.bWasUndone&&s){const i=e.splitPosition._getTransformedByMoveOperation(t),n=e.graveyardPosition._getTransformedByMoveOperation(t),s=n.path.slice();s.push(0);const o=new Po(n.root,s);return[new Ca(i,e.howMany,o,0)]}e.graveyardPosition=e.graveyardPosition._getTransformedByMoveOperation(t)}const s=e.splitPosition.isEqual(t.targetPosition);if(s&&("insertAtSource"==i.baRelation||"splitBefore"==i.abRelation))return e.howMany+=t.howMany,e.splitPosition=e.splitPosition._getTransformedByDeletion(t.sourcePosition,t.howMany),e.insertionPosition=Ta.getInsertionPosition(e.splitPosition),[e];if(s&&i.abRelation&&i.abRelation.howMany){const{howMany:t,offset:n}=i.abRelation;return e.howMany+=t,e.splitPosition=e.splitPosition.getShiftedBy(n),[e]}if(e.splitPosition.hasSameParentAs(t.sourcePosition)&&n.containsPosition(e.splitPosition)){const i=t.howMany-(e.splitPosition.offset-t.sourcePosition.offset);return e.howMany-=i,e.splitPosition.hasSameParentAs(t.targetPosition)&&e.splitPosition.offset{if(e.splitPosition.isEqual(t.splitPosition)){if(!e.graveyardPosition&&!t.graveyardPosition)return[new Sa(0)];if(e.graveyardPosition&&t.graveyardPosition&&e.graveyardPosition.isEqual(t.graveyardPosition))return[new Sa(0)];if("splitBefore"==i.abRelation)return e.howMany=0,e.graveyardPosition=e.graveyardPosition._getTransformedBySplitOperation(t),[e]}if(e.graveyardPosition&&t.graveyardPosition&&e.graveyardPosition.isEqual(t.graveyardPosition)){const n="$graveyard"==e.splitPosition.root.rootName,s="$graveyard"==t.splitPosition.root.rootName;if(s&&!n||(!n||s)&&i.aIsStrong){const i=[];return t.howMany&&i.push(new Ca(t.moveTargetPosition,t.howMany,t.splitPosition,0)),e.howMany&&i.push(new Ca(e.splitPosition,e.howMany,e.moveTargetPosition,0)),i}return[new Sa(0)]}if(e.graveyardPosition&&(e.graveyardPosition=e.graveyardPosition._getTransformedBySplitOperation(t)),e.splitPosition.isEqual(t.insertionPosition)&&"splitBefore"==i.abRelation)return e.howMany++,[e];if(t.splitPosition.isEqual(e.insertionPosition)&&"splitBefore"==i.baRelation){const i=t.insertionPosition.path.slice();i.push(0);const n=new Po(t.insertionPosition.root,i);return[e,new Ca(e.insertionPosition,1,n,0)]}return e.splitPosition.hasSameParentAs(t.splitPosition)&&e.splitPosition.offset{const n=i[0];(t||n.isDocumentOperation)&&Qa.call(this,n)},{priority:"low"})}function Qa(e){const t=this.getTransformedByOperation(e);if(!this.isEqual(t)){const e=this.toPosition();this.path=t.path,this.root=t.root,this.fire("change",e)}}Ga.prototype.is=function(e){return"livePosition"===e||"model:livePosition"===e||"position"==e||"model:position"===e};var Ya=class{operations;isUndoable;isLocal;isUndo;isTyping;constructor(e={}){"string"==typeof e&&(e="transparent"===e?{isUndoable:!1}:{},pe("batch-constructor-deprecated-string-type"));const{isUndoable:t=!0,isLocal:i=!0,isUndo:n=!1,isTyping:s=!1}=e;this.operations=[],this.isUndoable=t,this.isLocal=i,this.isUndo=n,this.isTyping=s}get baseVersion(){for(const e of this.operations)if(null!==e.baseVersion)return e.baseVersion;return null}addOperation(e){return e.isDocumentOperation&&(e.batch=this,this.operations.push(e)),e}},Xa=class e{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 0==this._changesInElement.size&&0==this._changedMarkers.size&&0==this._changedRoots.size}bufferOperation(e){const t=e;switch(t.type){case"insert":if(this._isInInsertedElement(t.position.parent))return;this._markInsert(t.position.parent,t.position.offset,t.nodes.maxOffset);break;case"addAttribute":case"removeAttribute":case"changeAttribute":for(const e of t.range.getItems({shallow:!0}))this._isInInsertedElement(e.parent)||this._markAttribute(e);break;case"remove":case"move":case"reinsert":{if(t.sourcePosition.isEqual(t.targetPosition)||t.sourcePosition.getShiftedBy(t.howMany).isEqual(t.targetPosition))return;const e=this._isInInsertedElement(t.sourcePosition.parent),i=this._isInInsertedElement(t.targetPosition.parent);e||this._markRemove(t.sourcePosition.parent,t.sourcePosition.offset,t.howMany),i||this._markInsert(t.targetPosition.parent,t.getMovedRangeStart().offset,t.howMany);const n=Bo._createFromPositionAndShift(t.sourcePosition,t.howMany);for(const e of n.getItems({shallow:!0}))this._setElementState(e,"move");break}case"rename":{if(this._isInInsertedElement(t.position.parent))return;this._markRemove(t.position.parent,t.position.offset,1),this._markInsert(t.position.parent,t.position.offset,1);const e=Bo._createFromPositionAndShift(t.position,1);for(const t of this._markerCollection.getMarkersIntersectingRange(e)){const e=t.getData();this.bufferMarkerChange(t.name,e,e)}this._setElementState(t.position.nodeAfter,"rename");break}case"split":{const e=t.splitPosition.parent;if(!this._isInInsertedElement(e)){this._markRemove(e,t.splitPosition.offset,t.howMany);const i=Bo._createFromPositionAndShift(t.splitPosition,t.howMany);for(const e of i.getItems({shallow:!0}))this._setElementState(e,"move")}this._isInInsertedElement(t.insertionPosition.parent)||this._markInsert(t.insertionPosition.parent,t.insertionPosition.offset,1),t.graveyardPosition&&(this._markRemove(t.graveyardPosition.parent,t.graveyardPosition.offset,1),this._setElementState(t.graveyardPosition.nodeAfter,"move"));break}case"merge":{const e=t.sourcePosition.parent;this._isInInsertedElement(e.parent)||this._markRemove(e.parent,e.startOffset,1);const i=t.graveyardPosition.parent;this._markInsert(i,t.graveyardPosition.offset,1),this._setElementState(e,"move");const n=t.targetPosition.parent;if(!this._isInInsertedElement(n)){this._markInsert(n,t.targetPosition.offset,e.maxOffset);const i=Bo._createFromPositionAndShift(t.sourcePosition,t.howMany);for(const e of i.getItems({shallow:!0}))this._setElementState(e,"move")}break}case"detachRoot":case"addRoot":{const e=t.affectedSelectable;if(!e._isLoaded)return;if(e.isAttached()==t.isAdd)return;this._bufferRootStateChange(t.rootName,t.isAdd);break}case"addRootAttribute":case"removeRootAttribute":case"changeRootAttribute":{if(!t.root._isLoaded)return;const e=t.root.rootName;this._bufferRootAttributeChange(e,t.key,t.oldValue,t.newValue);break}}this._cachedChanges=null}bufferMarkerChange(e,t,i){t.range&&t.range.root.is("rootElement")&&!t.range.root._isLoaded&&(t.range=null),i.range&&i.range.root.is("rootElement")&&!i.range.root._isLoaded&&(i.range=null);let n=this._changedMarkers.get(e);n?n.newMarkerData=i:(n={newMarkerData:i,oldMarkerData:t},this._changedMarkers.set(e,n)),null==n.oldMarkerData.range&&null==i.range&&this._changedMarkers.delete(e)}getMarkersToRemove(){const e=[];for(const[t,i]of this._changedMarkers)null!=i.oldMarkerData.range&&e.push({name:t,range:i.oldMarkerData.range});return e}getMarkersToAdd(){const e=[];for(const[t,i]of this._changedMarkers)null!=i.newMarkerData.range&&e.push({name:t,range:i.newMarkerData.range});return e}getChangedMarkers(){return Array.from(this._changedMarkers).map(([e,t])=>({name:e,data:{oldRange:t.oldMarkerData.range,newRange:t.newMarkerData.range}}))}hasDataChanges(){if(this.getChanges().length)return!0;if(this._changedRoots.size>0)return!0;for(const{newMarkerData:e,oldMarkerData:t}of this._changedMarkers.values()){if(e.affectsData!==t.affectsData)return!0;if(e.affectsData){const i=e.range&&!t.range,n=!e.range&&t.range,s=e.range&&t.range&&!e.range.isEqual(t.range);if(i||n||s)return!0}}return!1}getChanges(e={}){if(this._cachedChanges)return e.includeChangesInGraveyard?this._cachedChangesWithGraveyard.slice():this._cachedChanges.slice();let t=[];for(const e of this._changesInElement.keys()){const i=this._changesInElement.get(e).sort((e,t)=>e.offset===t.offset?e.type!=t.type?"remove"==e.type?-1:1:0:e.offsete.position.root!=t.position.root?e.position.root.rootNamee);for(const e of t)delete e.changeCount,"attribute"==e.type&&(delete e.position,delete e.length);return this._changeCount=0,this._cachedChangesWithGraveyard=t,this._cachedChanges=t.filter(il),e.includeChangesInGraveyard?this._cachedChangesWithGraveyard.slice():this._cachedChanges.slice()}getChangedRoots(){return Array.from(this._changedRoots.values()).map(e=>{const t={...e};return void 0!==t.state&&delete t.attributes,t})}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 t=Bo._createOn(e);for(const e of this._markerCollection.getMarkersIntersectingRange(t)){const t=e.getData();this.bufferMarkerChange(e.name,t,t)}this._cachedChanges=null}_bufferRootLoad(e){if(e.isAttached()){this._bufferRootStateChange(e.rootName,!0),this._markInsert(e,0,e.maxOffset);for(const t of e.getAttributeKeys())this._bufferRootAttributeChange(e.rootName,t,null,e.getAttribute(t));for(const t of this._markerCollection)if(t.getRange().root==e){const e=t.getData();this.bufferMarkerChange(t.name,{...e,range:null},e)}}}_bufferRootStateChange(e,t){if(!this._changedRoots.has(e))return void this._changedRoots.set(e,{name:e,state:t?"attached":"detached"});const i=this._changedRoots.get(e);void 0!==i.state?(delete i.state,void 0===i.attributes&&this._changedRoots.delete(e)):i.state=t?"attached":"detached"}_bufferRootAttributeChange(e,t,i,n){const s=this._changedRoots.get(e)||{name:e},o=s.attributes||{};if(o[t]){const e=o[t];n===e.oldValue?delete o[t]:e.newValue=n}else o[t]={oldValue:i,newValue:n};0===Object.entries(o).length?(delete s.attributes,void 0===s.state&&this._changedRoots.delete(e)):(s.attributes=o,this._changedRoots.set(e,s))}_markInsert(e,t,i){if(e.root.is("rootElement")&&!e.root._isLoaded)return;const n={type:"insert",offset:t,howMany:i,count:this._changeCount++};this._markChange(e,n)}_markRemove(e,t,i){if(e.root.is("rootElement")&&!e.root._isLoaded)return;const n={type:"remove",offset:t,howMany:i,count:this._changeCount++};this._markChange(e,n),this._removeAllNestedChanges(e,t,i)}_markAttribute(e){if(e.root.is("rootElement")&&!e.root._isLoaded)return;const t={type:"attribute",offset:e.startOffset,howMany:e.offsetSize,count:this._changeCount++};this._markChange(e.parent,t)}_markChange(e,t){this._makeSnapshots(e);const i=this._getChangesForElement(e);this._handleChange(t,i),i.push(t);for(let e=0;en&&this._elementState.set(t,i)}_getDiffActionForNode(e,t){if(!e.is("element"))return t;if(!this._elementsSnapshots.has(e))return t;const i=this._elementState.get(e);return i&&"move"!=i?i:t}_getChangesForElement(e){let t;return this._changesInElement.has(e)?t=this._changesInElement.get(e):(t=[],this._changesInElement.set(e,t)),t}_makeSnapshots(e){if(this._elementChildrenSnapshots.has(e))return;const t=el(e.getChildren());this._elementChildrenSnapshots.set(e,t);for(const e of t)this._elementsSnapshots.set(e.node,e)}_handleChange(e,t){e.nodesToHandle=e.howMany;for(const i of t){const n=e.offset+e.howMany,s=i.offset+i.howMany;if("insert"==e.type&&("insert"==i.type&&(e.offset<=i.offset?i.offset+=e.howMany:e.offseti.offset){if(n>s){const e={type:"attribute",offset:s,howMany:n-s,count:this._changeCount++};this._handleChange(e,t),t.push(e)}e.nodesToHandle=i.offset-e.offset,e.howMany=e.nodesToHandle}else e.offset>=i.offset&&e.offsets?(e.nodesToHandle=n-s,e.offset=s):e.nodesToHandle=0);if("remove"==i.type&&e.offseti.offset){const s={type:"attribute",offset:i.offset,howMany:n-i.offset,count:this._changeCount++};this._handleChange(s,t),t.push(s),e.nodesToHandle=i.offset-e.offset,e.howMany=e.nodesToHandle}"attribute"==i.type&&(e.offset>=i.offset&&n<=s?(e.nodesToHandle=0,e.howMany=0,e.offset=0):e.offset<=i.offset&&n>=s&&(i.howMany=0))}}e.howMany=e.nodesToHandle,delete e.nodesToHandle}_getInsertDiff(e,t,i,n,s){const o={type:"insert",position:Po._createAt(e,t),name:n.name,attributes:new Map(n.attributes),length:1,changeCount:this._changeCount++,action:i};return"insert"!=i&&s&&(o.before={name:s.name,attributes:new Map(s.attributes)}),o}_getRemoveDiff(e,t,i,n){return{type:"remove",action:i,position:Po._createAt(e,t),name:n.name,attributes:new Map(n.attributes),length:1,changeCount:this._changeCount++}}_getAttributesDiff(e,t,i){const n=[];i=new Map(i);for(const[s,o]of t){const t=i.has(s)?i.get(s):null;t!==o&&n.push({type:"attribute",position:e.start,range:e.clone(),length:1,attributeKey:s,attributeOldValue:o,attributeNewValue:t,changeCount:this._changeCount++}),i.delete(s)}for(const[t,s]of i)n.push({type:"attribute",position:e.start,range:e.clone(),length:1,attributeKey:t,attributeOldValue:null,attributeNewValue:s,changeCount:this._changeCount++});return n}_isInInsertedElement(e){const t=e.parent;if(!t)return!1;const i=this._changesInElement.get(t),n=e.startOffset;if(i)for(const e of i)if("insert"==e.type&&n>=e.offset&&nn){for(let t=0;t1500)for(let t=0;tthis._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 fe("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,t=this.version){if(!this._operations.length)return[];const i=this._operations[0];void 0===e&&(e=i.baseVersion);let n=t-1;for(const[t,i]of this._gaps)e>t&&et&&nthis.lastOperation.baseVersion)return[];let s=this._baseVersionToOperationIndex.get(e);void 0===s&&(s=0);let o=this._baseVersionToOperationIndex.get(n);return void 0===o&&(o=this._operations.length-1),this._operations.slice(s,o+1)}getOperation(e){const t=this._baseVersionToOperationIndex.get(e);if(void 0!==t)return this._operations[t]}setOperationAsUndone(e,t){this._undoPairs.set(t,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}},sl=class extends hr{rootName;_document;_isAttached=!0;_isLoaded=!0;constructor(e,t,i="main"){super(t),this._document=e,this.rootName=i}get document(){return this._document}isAttached(){return this._isAttached}toJSON(){return this.rootName}};sl.prototype.is=function(e,t){return t?t===this.name&&("rootElement"===e||"model:rootElement"===e||"element"===e||"model:element"===e):"rootElement"===e||"model:rootElement"===e||"element"===e||"model:element"===e||"node"===e||"model:node"===e};const ol="$graveyard",rl=Te();var al=class extends rl{model;history;selection;roots;differ;isReadOnly;_postFixers;_hasSelectionChangedFromTheLastChangeBlock;constructor(e){super(),this.model=e,this.history=new nl,this.selection=new lr(this),this.roots=new ri({idProperty:"rootName"}),this.differ=new Xa(e.markers),this.isReadOnly=!1,this._postFixers=new Set,this._hasSelectionChangedFromTheLastChangeBlock=!1,this.createRoot("$root",ol),this.listenTo(e,"applyOperation",(e,t)=>{const i=t[0];i.isDocumentOperation&&this.differ.bufferOperation(i)},{priority:"high"}),this.listenTo(e,"applyOperation",(e,t)=>{const i=t[0];i.isDocumentOperation&&this.history.addOperation(i)},{priority:"low"}),this.listenTo(this.selection,"change",()=>{this._hasSelectionChangedFromTheLastChangeBlock=!0}),this.listenTo(e.markers,"update",(e,t,i,n,s)=>{const o={...t.getData(),range:n};this.differ.bufferMarkerChange(t.name,s,o),null===i&&t.on("change",(e,i)=>{const n=t.getData();this.differ.bufferMarkerChange(t.name,{...n,range:i},n)})}),this.registerPostFixer(e=>{let t=!1;for(const i of this.roots)i.isAttached()||i.isEmpty||(e.remove(e.createRangeIn(i)),t=!0);for(const i of this.model.markers)i.getRange().root.isAttached()||(e.removeMarker(i),t=!0);return t})}get version(){return this.history.version}set version(e){this.history.version=e}get graveyard(){return this.getRoot(ol)}createRoot(e="$root",t="main"){if(this.roots.get(t))throw new fe("model-document-createroot-name-exists",this,{name:t});const i=new sl(this,e,t);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(e=>e.rootName)}getRoots(e=!1){return this.roots.filter(t=>t!=this.graveyard&&(e||t.isAttached())&&t._isLoaded)}registerPostFixer(e){this._postFixers.add(e)}toJSON(){const e=ln(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(),t=this.model,i=t.schema,n=t.createPositionFromPath(e,[0]);return i.getNearestSelectionRange(n)||t.createRange(n)}_validateSelectionRange(e){return e.start.isValid()&&e.end.isValid()&&ll(e.start)&&ll(e.end)}_callPostFixers(e){let t=!1;do{for(const i of this._postFixers)if(this.selection.refresh(),t=i(e),t)break}while(t)}};function ll(e){const t=e.textNode;if(t){const i=t.data,n=e.offset-t.startOffset;return!vi(i,n)&&!yi(i,n)}return!0}const cl=Te(),dl=Te(Ao);var ul=class extends cl{_markers=new Map;[Symbol.iterator](){return this._markers.values()}has(e){const t=e instanceof hl?e.name:e;return this._markers.has(t)}get(e){return this._markers.get(e)||null}_set(e,t,i=!1,n=!1){const s=e instanceof hl?e.name:e;if(s.includes(","))throw new fe("markercollection-incorrect-marker-name",this);const o=this._markers.get(s);if(o){const e=o.getData(),r=o.getRange();let a=!1;return r.isEqual(t)||(o._attachLiveRange(ir.fromRange(t)),a=!0),i!=o.managedUsingOperations&&(o._managedUsingOperations=i,a=!0),"boolean"==typeof n&&n!=o.affectsData&&(o._affectsData=n,a=!0),a&&this.fire(`update:${s}`,o,r,t,e),o}const r=ir.fromRange(t),a=new hl(s,r,i,n);return this._markers.set(s,a),this.fire(`update:${s}`,a,null,t,{...a.getData(),range:null}),a}_remove(e){const t=e instanceof hl?e.name:e,i=this._markers.get(t);return!!i&&(this._markers.delete(t),this.fire(`update:${t}`,i,i.getRange(),null,i.getData()),this._destroyMarker(i),!0)}_refresh(e){const t=e instanceof hl?e.name:e,i=this._markers.get(t);if(!i)throw new fe("markercollection-refresh-marker-not-exists",this);const n=i.getRange();this.fire(`update:${t}`,i,n,n,i.getData())}*getMarkersAtPosition(e){for(const t of this)t.getRange().containsPosition(e)&&(yield t)}*getMarkersIntersectingRange(e){for(const t of this)null!==t.getRange().getIntersection(e)&&(yield t)}destroy(){for(const e of this._markers.values())this._destroyMarker(e);this._markers.clear(),this.stopListening()}*getMarkersGroup(e){for(const t of this._markers.values())t.name.startsWith(e+":")&&(yield t)}_destroyMarker(e){e.stopListening(),e._detachLiveRange()}},hl=class extends dl{name;_managedUsingOperations;_affectsData;_liveRange;constructor(e,t,i,n){super(),this.name=e,this._liveRange=this._attachLiveRange(t),this._managedUsingOperations=i,this._affectsData=n}get managedUsingOperations(){if(!this._liveRange)throw new fe("marker-destroyed",this);return this._managedUsingOperations}get affectsData(){if(!this._liveRange)throw new fe("marker-destroyed",this);return this._affectsData}getData(){return{range:this.getRange(),affectsData:this.affectsData,managedUsingOperations:this.managedUsingOperations}}getStart(){if(!this._liveRange)throw new fe("marker-destroyed",this);return this._liveRange.start.clone()}getEnd(){if(!this._liveRange)throw new fe("marker-destroyed",this);return this._liveRange.end.clone()}getRange(){if(!this._liveRange)throw new fe("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}};hl.prototype.is=function(e){return"marker"===e||"model:marker"===e};var ml=class extends fa{sourcePosition;howMany;constructor(e,t){super(null),this.sourcePosition=e.clone(),this.howMany=t}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 fe("detach-operation-on-document-node",this)}_execute(){ba(Bo._createFromPositionAndShift(this.sourcePosition,this.howMany))}static get className(){return"DetachOperation"}},gl=class e extends Ao{markers=new Map;_children=new ur;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 0===this.childCount}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 t=this;for(const i of e)t=t.getChildAtOffset(i);return t}offsetToIndex(e){return this._children.offsetToIndex(e)}toJSON(){const e=[];for(const t of this._children)e.push(t.toJSON());return e}static fromJSON(t){const i=[];for(const e of t)e.name?i.push(hr.fromJSON(e)):i.push(or.fromJSON(e));return new e(i)}_appendChild(e){this._insertChild(this.childCount,e)}_insertChild(e,t){const i=function(e){if("string"==typeof e)return[new or(e)];Ge(e)||(e=[e]);return Array.from(e).map(e=>"string"==typeof e?new or(e):e instanceof To?new or(e.data,e.getAttributes()):e)}(t);for(const e of i)null!==e.parent&&e._remove(),e.parent=this;this._children._insertNodes(e,i)}_removeChildren(e,t=1){const i=this._children._removeNodes(e,t);for(const e of i)e.parent=null;return i}_removeChildrenArray(e){this._children._removeNodesArray(e);for(const t of e)t.parent=null}};gl.prototype.is=function(e){return"documentFragment"===e||"model:documentFragment"===e};var fl=class{model;batch;constructor(e,t){this.model=e,this.batch=t}createText(e,t){return new or(e,t)}createElement(e,t){return new hr(e,t)}createDocumentFragment(){return new gl}cloneElement(e,t=!0){return e._clone(t)}insert(e,t,i=0){if(this._assertWriterUsedCorrectly(),e instanceof or&&""==e.data)return;const n=Po._createAt(t,i);if(e.parent){if(vl(e.root,n.root))return void this.move(Bo._createOn(e),n);if(e.root.document)throw new fe("model-writer-insert-forbidden-move",this);this.remove(e)}const s=n.root.document?n.root.document.version:null,o=new Aa(n,e instanceof gl?e._removeChildren(0,e.childCount):e,s);if(e instanceof or&&(o.shouldReceiveAttributes=!0),this.batch.addOperation(o),this.model.applyOperation(o),e instanceof gl)for(const[t,i]of e.markers){const e=Po._createAt(i.root,0),s={range:new Bo(i.start._getCombined(e,n),i.end._getCombined(e,n)),usingOperation:!0,affectsData:!0};this.model.markers.has(t)?this.updateMarker(t,s):this.addMarker(t,s)}}insertText(e,t,i,n){t instanceof gl||t instanceof hr||t instanceof Po?this.insert(this.createText(e),t,i):this.insert(this.createText(e,t),i,n)}insertElement(e,t,i,n){t instanceof gl||t instanceof hr||t instanceof Po?this.insert(this.createElement(e),t,i):this.insert(this.createElement(e,t),i,n)}append(e,t){this.insert(e,t,"end")}appendText(e,t,i){t instanceof gl||t instanceof hr?this.insert(this.createText(e),t,"end"):this.insert(this.createText(e,t),i,"end")}appendElement(e,t,i){t instanceof gl||t instanceof hr?this.insert(this.createElement(e),t,"end"):this.insert(this.createElement(e,t),i,"end")}setAttribute(e,t,i){if(this._assertWriterUsedCorrectly(),i instanceof Bo){const n=i.getMinimalFlatRanges();for(const i of n)pl(this,e,t,i)}else bl(this,e,t,i)}setAttributes(e,t){for(const[i,n]of gi(e))this.setAttribute(i,n,t)}removeAttribute(e,t){if(this._assertWriterUsedCorrectly(),t instanceof Bo){const i=t.getMinimalFlatRanges();for(const t of i)pl(this,e,null,t)}else bl(this,e,null,t)}clearAttributes(e){this._assertWriterUsedCorrectly();const t=e=>{for(const t of e.getAttributeKeys())this.removeAttribute(t,e)};if(e instanceof Bo)for(const i of e.getItems())t(i);else t(e)}move(e,t,i){if(this._assertWriterUsedCorrectly(),!(e instanceof Bo))throw new fe("writer-move-invalid-range",this);if(!e.isFlat)throw new fe("writer-move-range-not-flat",this);const n=Po._createAt(t,i);if(n.isEqual(e.start))return;if(this._addOperationForAffectedMarkers("move",e),!vl(e.root,n.root))throw new fe("writer-move-different-document",this);const s=e.root.document?e.root.document.version:null,o=new Ca(e.start,e.end.offset-e.start.offset,n,s);this.batch.addOperation(o),this.model.applyOperation(o)}remove(e){this._assertWriterUsedCorrectly();const t=(e instanceof Bo?e:Bo._createOn(e)).getMinimalFlatRanges().reverse();for(const e of t)this._addOperationForAffectedMarkers("move",e),_l(e.start,e.end.offset-e.start.offset,this.batch,this.model)}merge(e){this._assertWriterUsedCorrectly();const t=e.nodeBefore,i=e.nodeAfter;if(this._addOperationForAffectedMarkers("merge",e),!(t instanceof hr))throw new fe("writer-merge-no-element-before",this);if(!(i instanceof hr))throw new fe("writer-merge-no-element-after",this);e.root.document?this._merge(e):this._mergeDetached(e)}createPositionFromPath(e,t,i){return this.model.createPositionFromPath(e,t,i)}createPositionAt(e,t){return this.model.createPositionAt(e,t)}createPositionAfter(e){return this.model.createPositionAfter(e)}createPositionBefore(e){return this.model.createPositionBefore(e)}createRange(e,t){return this.model.createRange(e,t)}createRangeIn(e){return this.model.createRangeIn(e)}createRangeOn(e){return this.model.createRangeOn(e)}createSelection(...e){return this.model.createSelection(...e)}_mergeDetached(e){const t=e.nodeBefore,i=e.nodeAfter;this.move(Bo._createIn(i),Po._createAt(t,"end")),this.remove(i)}_merge(e){const t=Po._createAt(e.nodeBefore,"end"),i=Po._createAt(e.nodeAfter,0),n=e.root.document.graveyard,s=new Po(n,[0]),o=e.root.document.version,r=new Ea(i,e.nodeAfter.maxOffset,t,s,o);this.batch.addOperation(r),this.model.applyOperation(r)}rename(e,t){if(this._assertWriterUsedCorrectly(),!(e instanceof hr))throw new fe("writer-rename-not-element-instance",this);const i=e.root.document?e.root.document.version:null,n=new Ia(Po._createBefore(e),e.name,t,i);this.batch.addOperation(n),this.model.applyOperation(n)}split(e,t){this._assertWriterUsedCorrectly();let i,n,s=e.parent;if(!s.parent)throw new fe("writer-split-element-no-parent",this);if(t||(t=s.parent),!e.parent.getAncestors({includeSelf:!0}).includes(t))throw new fe("writer-split-invalid-limit-element",this);do{const t=s.root.document?s.root.document.version:null,o=s.maxOffset-e.offset,r=Ta.getInsertionPosition(e),a=new Ta(e,o,r,null,t);this.batch.addOperation(a),this.model.applyOperation(a),i||n||(i=s,n=e.parent.nextSibling),s=(e=this.createPositionAfter(e.parent)).parent}while(s!==t);return{position:e,range:new Bo(Po._createAt(i,"end"),Po._createAt(n,0))}}wrap(e,t){if(this._assertWriterUsedCorrectly(),!e.isFlat)throw new fe("writer-wrap-range-not-flat",this);const i=t instanceof hr?t:new hr(t);if(i.childCount>0)throw new fe("writer-wrap-element-not-empty",this);if(null!==i.parent)throw new fe("writer-wrap-element-attached",this);this.insert(i,e.start);const n=new Bo(e.start.getShiftedBy(1),e.end.getShiftedBy(1));this.move(n,Po._createAt(i,0))}unwrap(e){if(this._assertWriterUsedCorrectly(),null===e.parent)throw new fe("writer-unwrap-element-no-parent",this);this.move(Bo._createIn(e),this.createPositionAfter(e)),this.remove(e)}addMarker(e,t){if(this._assertWriterUsedCorrectly(),!t||"boolean"!=typeof t.usingOperation)throw new fe("writer-addmarker-no-usingoperation",this);const i=t.usingOperation,n=t.range,s=void 0!==t.affectsData&&t.affectsData;if(this.model.markers.has(e))throw new fe("writer-addmarker-marker-exists",this);if(!n)throw new fe("writer-addmarker-no-range",this);return i?(wl(this,e,null,n,s),this.model.markers.get(e)):this.model.markers._set(e,n,i,s)}updateMarker(e,t){this._assertWriterUsedCorrectly();const i="string"==typeof e?e:e.name,n=this.model.markers.get(i);if(!n)throw new fe("writer-updatemarker-marker-not-exists",this);if(!t)return pe("writer-updatemarker-reconvert-using-editingcontroller",{markerName:i}),void this.model.markers._refresh(n);const s="boolean"==typeof t.usingOperation,o="boolean"==typeof t.affectsData,r=o?t.affectsData:n.affectsData;if(!s&&!t.range&&!o)throw new fe("writer-updatemarker-wrong-options",this);const a=n.getRange(),l=t.range?t.range:a;s&&t.usingOperation!==n.managedUsingOperations?t.usingOperation?wl(this,i,null,l,r):(wl(this,i,a,null,r),this.model.markers._set(i,l,void 0,r)):n.managedUsingOperations?wl(this,i,a,l,r):this.model.markers._set(i,l,void 0,r)}removeMarker(e){this._assertWriterUsedCorrectly();const t="string"==typeof e?e:e.name;if(!this.model.markers.has(t))throw new fe("writer-removemarker-no-marker",this);const i=this.model.markers.get(t);if(!i.managedUsingOperations)return void this.model.markers._remove(t);wl(this,t,i.getRange(),null,i.affectsData)}addRoot(e,t="$root"){this._assertWriterUsedCorrectly();const i=this.model.document.getRoot(e);if(i&&i.isAttached())throw new fe("writer-addroot-root-exists",this);const n=this.model.document,s=new Oa(e,t,!0,n,n.version);return this.batch.addOperation(s),this.model.applyOperation(s),this.model.document.getRoot(e)}detachRoot(e){this._assertWriterUsedCorrectly();const t="string"==typeof e?this.model.document.getRoot(e):e;if(!t||!t.isAttached())throw new fe("writer-detachroot-no-root",this);for(const e of this.model.markers)e.getRange().root===t&&this.removeMarker(e);for(const e of t.getAttributeKeys())this.removeAttribute(e,t);this.remove(this.createRangeIn(t));const i=this.model.document,n=new Oa(t.rootName,t.name,!1,i,i.version);this.batch.addOperation(n),this.model.applyOperation(n)}setSelection(...e){this._assertWriterUsedCorrectly(),this.model.document.selection._setTo(...e)}setSelectionFocus(e,t){this._assertWriterUsedCorrectly(),this.model.document.selection._setFocus(e,t)}setSelectionAttribute(e,t){if(this._assertWriterUsedCorrectly(),"string"==typeof e)this._setSelectionAttribute(e,t);else for(const[t,i]of gi(e))this._setSelectionAttribute(t,i)}removeSelectionAttribute(e){if(this._assertWriterUsedCorrectly(),"string"==typeof e)this._removeSelectionAttribute(e);else for(const t of e)this._removeSelectionAttribute(t)}overrideSelectionGravity(){return this.model.document.selection._overrideGravity()}restoreSelectionGravity(e){this.model.document.selection._restoreGravity(e)}_setSelectionAttribute(e,t){const i=this.model.document.selection;if(i.isCollapsed&&i.anchor.parent.isEmpty){const n=lr._getStoreAttributeKey(e);this.setAttribute(n,t,i.anchor.parent)}i._setAttribute(e,t)}_removeSelectionAttribute(e){const t=this.model.document.selection;if(t.isCollapsed&&t.anchor.parent.isEmpty){const i=lr._getStoreAttributeKey(e);this.removeAttribute(i,t.anchor.parent)}t._removeAttribute(e)}_assertWriterUsedCorrectly(){if(this.model._currentWriter!==this)throw new fe("writer-incorrect-use",this)}_addOperationForAffectedMarkers(e,t){for(const i of this.model.markers){if(!i.managedUsingOperations)continue;const n=i.getRange();let s;if("move"===e){const e=t;s=e.containsPosition(n.start)||e.start.isEqual(n.start)||e.containsPosition(n.end)||e.end.isEqual(n.end)}else{const e=t,i=e.nodeBefore,o=e.nodeAfter,r=n.start.parent==i&&n.start.isAtEnd,a=n.end.parent==o&&0==n.end.offset,l=n.end.nodeAfter==o,c=n.start.nodeAfter==o;s=r||a||l||c}s&&this.updateMarker(i.name,{range:n})}}};function pl(e,t,i,n){const s=e.model,o=s.document;let r,a,l,c=n.start;for(const e of n.getWalker({shallow:!0}))l=e.item.getAttribute(t),r&&a!=l&&(a!=i&&d(),c=r),r=e.nextPosition,a=l;function d(){const n=new Bo(c,r),l=n.root.document?o.version:null,d=new Pa(n,t,a,i,l);e.batch.addOperation(d),s.applyOperation(d)}r instanceof Po&&r!=c&&a!=i&&d()}function bl(e,t,i,n){const s=e.model,o=s.document,r=n.getAttribute(t);let a,l;if(r!=i){if(n.root===n)l=new Va(n,t,r,i,n.document?o.version:null);else{a=new Bo(Po._createBefore(n),e.createPositionAfter(n));const s=a.root.document?o.version:null;l=new Pa(a,t,r,i,s)}e.batch.addOperation(l),s.applyOperation(l)}}function wl(e,t,i,n,s){const o=e.model,r=o.document,a=new xa(t,i,n,o.markers,!!s,r.version);e.batch.addOperation(a),o.applyOperation(a)}function _l(e,t,i,n){let s;if(e.root.document){const i=n.document;s=new Ca(e,t,new Po(i.graveyard,[0]),i.version)}else s=new ml(e,t);i.addOperation(s),n.applyOperation(s)}function vl(e,t){return e===t||e instanceof sl&&t instanceof sl}function yl(e){e.document.registerPostFixer(t=>function(e,t){const i=t.document.selection,n=t.schema,s=[];let o=!1;for(const e of i.getRanges()){const t=kl(e,n);t&&!t.isEqual(e)?(s.push(t),o=!0):s.push(e)}o&&e.setSelection(function(e){const t=[...e],i=new Set;let n=1;for(;n!i.has(t))}(s),{backward:i.isBackward});return!1}(t,e))}function kl(e,t){return e.isCollapsed?function(e,t){const i=e.start,n=t.getNearestSelectionRange(i);if(!n){const e=i.getAncestors().reverse().find(e=>t.isObject(e));return e?Bo._createOn(e):null}if(!n.isCollapsed)return n;const s=n.start;return i.isEqual(s)?null:new Bo(s)}(e,t):function(e,t){const{start:i,end:n}=e,s=t.checkChild(i,"$text"),o=t.checkChild(n,"$text"),r=t.getLimitElement(i),a=t.getLimitElement(n);if(r===a){if(s&&o)return null;if(function(e,t,i){const n=e.nodeAfter&&!i.isLimit(e.nodeAfter)||i.checkChild(e,"$text"),s=t.nodeBefore&&!i.isLimit(t.nodeBefore)||i.checkChild(t,"$text");return n||s}(i,n,t)){const e=i.nodeAfter&&t.isSelectable(i.nodeAfter)?null:t.getNearestSelectionRange(i,"forward"),s=n.nodeBefore&&t.isSelectable(n.nodeBefore)?null:t.getNearestSelectionRange(n,"backward");return new Bo(e?e.start:i,s?s.end:n)}}const l=r&&!r.is("rootElement"),c=a&&!a.is("rootElement");if(l||c){const e=i.nodeAfter&&n.nodeBefore&&i.nodeAfter.parent===n.nodeBefore.parent,s=l&&(!e||!Al(i.nodeAfter,t)),o=c&&(!e||!Al(n.nodeBefore,t));let d=i,u=n;return s&&(d=Po._createBefore(Cl(r,t))),o&&(u=Po._createAfter(Cl(a,t))),new Bo(d,u)}return null}(e,t)}function Cl(e,t){let i=e,n=i;for(;t.isLimit(n)&&n.parent;)i=n,n=n.parent;return i}function Al(e,t){return e&&t.isSelectable(e)}function Tl(e,t,i={}){if(t.isCollapsed)return;const n=t.getFirstRange();if("$graveyard"==n.root.rootName)return;const s=e.schema,o=e.document.selection,r=function(e,t,i){if(e instanceof lr)return!0;if(t.isCollapsed){const e=t.getFirstPosition();return e.isEqual(i.start)||e.isEqual(i.end)}return!!t.getFirstRange()?.isIntersecting(i)}(t,o,n),a=Array.from(o.getAttributes()),l=!!o.getFirstRange()?.start.parent.isEmpty;e.change(o=>{if(!i.doNotResetEntireContent&&function(e,t){const i=e.getLimitElement(t);if(!t.containsEntireContent(i))return!1;const n=t.getFirstRange();return n.start.parent!=n.end.parent&&e.checkChild(i,"paragraph")}(s,t))return void function(e,t){const i=e.model.schema.getLimitElement(t);e.remove(e.createRangeIn(i)),Sl(e,e.createPositionAt(i,0),t)}(o,t);const c={};if(!i.doNotAutoparagraph){const e=t.getSelectedElement();e&&Object.assign(c,s.getAttributesWithProperty(e,"copyOnReplace",!0))}let d,u;n.root instanceof gl?(d=Ga._fromPositionInDocumentFragment(n.start,e,"toPrevious"),u=Ga._fromPositionInDocumentFragment(n.end,e,"toNext")):i.doNotFixSelection?(d=Ga.fromPosition(n.start,"toPrevious"),u=Ga.fromPosition(n.end,"toNext")):[d,u]=function(e){const t=e.root.document.model,i=e.start;let n=e.end;if(t.hasContent(e,{ignoreMarkers:!0})){const i=function(e){const t=e.parent,i=t.root.document.model.schema,n=t.getAncestors({parentFirst:!0,includeSelf:!0});for(const e of n){if(i.isLimit(e))return null;if(i.isBlock(e))return e}}(n);if(i&&n.isTouching(t.createPositionAt(i,0))){const i=t.createSelection(e);t.modifySelection(i,{direction:"backward"});const s=i.getLastPosition(),o=t.createRange(s,n);t.hasContent(o,{ignoreMarkers:!0})||(n=s)}}return[Ga.fromPosition(i,"toPrevious"),Ga.fromPosition(n,"toNext")]}(n),d.isTouching(u)||o.remove(o.createRange(d,u)),i.leaveUnmerged||(!function(e,t,i){const n=e.model;if(!Pl(e.model.schema,t,i))return;const[s,o]=function(e,t){const i=e.getAncestors(),n=t.getAncestors();let s=0;for(;i[s]&&i[s]==n[s];)s++;return[i[s],n[s]]}(t,i);if(!s||!o)return;!n.hasContent(s,{ignoreMarkers:!0})&&n.hasContent(o,{ignoreMarkers:!0})?xl(e,t,i,s.parent):El(e,t,i,s.parent)}(o,d,u),s.removeDisallowedAttributes(d.parent.getChildren(),o)),Il(o,t,d),!i.doNotAutoparagraph&&function(e,t){const i=e.checkChild(t,"$text"),n=e.checkChild(t,"paragraph");return!i&&n}(s,d)&&Sl(o,d,t,c),r&&function(e,t,i){if(!t.length)return;const n=e.model.document.selection;if(!n.anchor.parent.isEmpty)return;if(i)return;for(const[i,s]of t)e.model.schema.getAttributeProperties(i).isFormatting&&e.model.schema.checkAttributeInSelection(n,i)&&e.setSelectionAttribute(i,s)}(o,a,l),d.detach(),u.detach()})}function El(e,t,i,n){const s=t.parent,o=i.parent;if(s!=n&&o!=n){for(t=e.createPositionAfter(s),(i=e.createPositionBefore(o)).isEqual(t)||e.insert(o,t),e.merge(t);i.parent.isEmpty;){const t=i.parent;i=e.createPositionBefore(t),e.remove(t)}Pl(e.model.schema,t,i)&&El(e,t,i,n)}}function xl(e,t,i,n){const s=t.parent,o=i.parent;if(s!=n&&o!=n){for(t=e.createPositionAfter(s),(i=e.createPositionBefore(o)).isEqual(t)||e.insert(s,i);t.parent.isEmpty;){const i=t.parent;t=e.createPositionBefore(i),e.remove(i)}i=e.createPositionBefore(o),function(e,t){const i=t.nodeBefore,n=t.nodeAfter;i.name!=n.name&&e.rename(i,n.name);e.clearAttributes(i),e.setAttributes(Object.fromEntries(n.getAttributes()),i),e.merge(t)}(e,i),Pl(e.model.schema,t,i)&&xl(e,t,i,n)}}function Pl(e,t,i){const n=t.parent,s=i.parent;return n!=s&&(!e.isLimit(n)&&!e.isLimit(s)&&function(e,t,i){const n=new Bo(e,t);for(const e of n.getWalker())if(i.isLimit(e.item))return!1;return!0}(t,i,e))}function Sl(e,t,i,n={}){const s=e.createElement("paragraph");e.model.schema.setAllowedAttributes(s,n,e),e.insert(s,t),Il(e,i,e.createPositionAt(s,0))}function Il(e,t,i){t instanceof lr?e.setSelection(i):t.setTo(i)}function Vl(e,t){const i=[];Array.from(e.getItems({direction:"backward"})).map(e=>t.createRangeOn(e)).filter(t=>(t.start.isAfter(e.start)||t.start.isEqual(e.start))&&(t.end.isBefore(e.end)||t.end.isEqual(e.end))).forEach(e=>{i.push(e.start.parent),t.remove(e)}),i.forEach(e=>{let i=e;for(;i.parent&&i.isEmpty;){const e=t.createRangeOn(i);i=i.parent,t.remove(e)}})}var Ol=class{model;writer;position;canMergeWith;schema;_documentFragment;_documentFragmentPosition;_firstNode=null;_lastNode=null;_lastAutoParagraph=null;_filterAttributesAndChildrenOf=[];_affectedStart=null;_affectedEnd=null;_nodeToSelect=null;constructor(e,t,i){this.model=e,this.writer=t,this.position=i,this.canMergeWith=new Set([this.position.parent]),this.schema=e.schema,this._documentFragment=t.createDocumentFragment(),this._documentFragmentPosition=t.createPositionAt(this._documentFragment,0)}handleNodes(e){for(const t of Array.from(e))t.offsetSize>0&&this._handleNode(t);this._insertPartialFragment(),this._lastAutoParagraph&&this._updateLastNodeFromAutoParagraph(this._lastAutoParagraph),this._mergeOnRight(),this.schema.removeDisallowedAttributes(this._filterAttributesAndChildrenOf,this.writer),!1!==this.model._config?.get("experimentalFlags.modelInsertContentDeepSchemaVerification")&&this._removeDisallowedChildren(this._filterAttributesAndChildrenOf),this._filterAttributesAndChildrenOf=[]}_removeDisallowedChildren(e){const t=Array.from(e);for(const e of t){if(!e.is("element"))continue;const i=[],n=[],s=this.writer.createRangeIn(e).getWalker({ignoreElementEnd:!0});for(const{item:e}of s){const o=e.parent;this.schema.checkChild(o,e)||(e.is("element")&&!this.schema.isObject(e)?(n.push(e),t.push(o)):i.push(e),s.jumpTo(this.writer.createPositionAfter(e)))}for(const e of n)this.writer.unwrap(e);for(const e of i)this.writer.remove(e)}}_updateLastNodeFromAutoParagraph(e){const t=this.writer.createPositionAfter(this._lastNode),i=this.writer.createPositionAfter(e);if(i.isAfter(t)){if(this._lastNode=e,this.position.parent!=e||!this.position.isAtEnd)throw new fe("insertcontent-invalid-insertion-position",this);this.position=i,this._setAffectedBoundaries(this.position)}}getSelectionRange(){return this._nodeToSelect?Bo._createOn(this._nodeToSelect):this.model.schema.getNearestSelectionRange(this.position)}getAffectedRange(){return this._affectedStart?new Bo(this._affectedStart,this._affectedEnd):null}destroy(){this._affectedStart&&this._affectedStart.detach(),this._affectedEnd&&this._affectedEnd.detach()}_handleNode(e){this._checkAndSplitToAllowedPosition(e)?(e=this._appendToFragment(e),this._firstNode||(this._firstNode=e),this._lastNode=e):this.schema.isObject(e)||this._handleDisallowedNode(e)}_insertPartialFragment(){if(this._documentFragment.isEmpty)return;const e=Ga.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 fe("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=Ga.fromPosition(e,"toPrevious")),this._affectedEnd&&!this._affectedEnd.isBefore(e)||(this._affectedEnd&&this._affectedEnd.detach(),this._affectedEnd=Ga.fromPosition(e,"toNext"))}_mergeOnLeft(){const e=this._firstNode;if(!(e instanceof hr))return;if(!this._canMergeLeft(e))return;const t=Ga._createBefore(e);t.stickiness="toNext";const i=Ga.fromPosition(this.position,"toNext");this._affectedStart.isEqual(t)&&(this._affectedStart.detach(),this._affectedStart=Ga._createAt(t.nodeBefore,"end","toPrevious")),this._firstNode===this._lastNode&&(this._firstNode=t.nodeBefore,this._lastNode=t.nodeBefore),this.writer.merge(t),t.isEqual(this._affectedEnd)&&this._firstNode===this._lastNode&&(this._affectedEnd.detach(),this._affectedEnd=Ga._createAt(t.nodeBefore,"end","toNext")),this.position=i.toPosition(),i.detach(),this._filterAttributesAndChildrenOf.push(this.position.parent),t.detach()}_mergeOnRight(){const e=this._lastNode;if(!(e instanceof hr))return;if(!this._canMergeRight(e))return;const t=Ga._createAfter(e);if(t.stickiness="toNext",!this.position.isEqual(t))throw new fe("insertcontent-invalid-insertion-position",this);this.position=Po._createAt(t.nodeBefore,"end");const i=Ga.fromPosition(this.position,"toPrevious");this._affectedEnd.isEqual(t)&&(this._affectedEnd.detach(),this._affectedEnd=Ga._createAt(t.nodeBefore,"end","toNext")),this._firstNode===this._lastNode&&(this._firstNode=t.nodeBefore,this._lastNode=t.nodeBefore),this.writer.merge(t),t.getShiftedBy(-1).isEqual(this._affectedStart)&&this._firstNode===this._lastNode&&(this._affectedStart.detach(),this._affectedStart=Ga._createAt(t.nodeBefore,0,"toPrevious")),this.position=i.toPosition(),i.detach(),this._filterAttributesAndChildrenOf.push(this.position.parent),t.detach()}_canMergeLeft(e){const t=e.previousSibling;return t instanceof hr&&this.canMergeWith.has(t)&&this.model.schema.checkMerge(t,e)}_canMergeRight(e){const t=e.nextSibling;return t instanceof hr&&this.canMergeWith.has(t)&&this.model.schema.checkMerge(e,t)}_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 t=this._getAllowedIn(this.position.parent,e);if(!t)return!1;for(t!=this.position.parent&&this._insertPartialFragment();t!=this.position.parent;)if(this.position.isAtStart){const e=this.position.parent;this.position=this.writer.createPositionBefore(e),e.isEmpty&&e.parent===t&&this.writer.remove(e)}else if(this.position.isAtEnd)this.position=this.writer.createPositionAfter(this.position.parent);else{const e=this.writer.createPositionAfter(this.position.parent);this._setAffectedBoundaries(this.position),this.writer.split(this.position),this.position=e,this.canMergeWith.add(this.position.nodeAfter)}return this.schema.checkChild(this.position.parent,e)||this._insertAutoParagraph(),!0}_getAllowedIn(e,t){const i=this.schema.createContext(e);return this.schema.checkChild(i,t)||this.schema.checkChild(i,"paragraph")&&this.schema.checkChild(i.push("paragraph"),t)?e:this.schema.isLimit(e)?null:this._getAllowedIn(e.parent,t)}};function Rl(e,t,i,n={}){if(!e.schema.isObject(t))throw new fe("insertobject-element-not-an-object",e,{object:t});const s=i||e.document.selection;let o=s;n.findOptimalPosition&&e.schema.isBlock(t)&&(o=e.createSelection(e.schema.findOptimalInsertionRange(s,n.findOptimalPosition)));const r=ai(s.getSelectedBlocks()),a={};return r&&Object.assign(a,e.schema.getAttributesWithProperty(r,"copyOnReplace",!0)),e.change(i=>{o.isCollapsed||e.deleteContent(o,{doNotAutoparagraph:!0});let s=t;const r=o.anchor.parent,l=e.schema.createContext(r);!e.schema.checkChild(l,t)&&e.schema.checkChild(l,"paragraph")&&e.schema.checkChild(l.push("paragraph"),t)&&(s=i.createElement("paragraph"),i.insert(t,s)),e.schema.setAllowedAttributes(s,a,i);const c=e.insertContent(s,o);return c.isCollapsed||n.setSelection&&function(e,t,i,n){const s=e.model;if("on"==i)return void e.setSelection(t,"on");if("after"!=i)throw new fe("insertobject-invalid-place-parameter-value",s);let o=t.nextSibling;if(s.schema.isInline(t))return void e.setSelection(t,"after");o&&s.schema.checkChild(o,"$text")||!s.schema.checkChild(t.parent,"paragraph")||(o=e.createElement("paragraph"),s.schema.setAllowedAttributes(o,n,e),s.insertContent(o,e.createPositionAfter(t)));o&&e.setSelection(o,0)}(i,t,n.setSelection,a),c})}function Bl(e,t){const{isForward:i,walker:n,unit:s,schema:o,treatEmojiAsSingleUnit:r}=e,{type:a,item:l,nextPosition:c}=t;if("text"==a)return"word"===e.unit?function(e,t){let i=e.position.textNode;i||(i=t?e.position.nodeAfter:e.position.nodeBefore);for(;i&&i.is("$text");){const n=e.position.offset-i.startOffset;if(Nl(i,n,t))i=t?e.position.nodeAfter:e.position.nodeBefore;else{if(Fl(i.data,n,t))break;e.next()}}return e.position}(n,i):function(e,t,i){const n=e.position.textNode;if(n){const s=n.data;let o=e.position.offset-n.startOffset;for(;vi(s,o)||"character"==t&&yi(s,o)||i&&Ci(s,o);)e.next(),o=e.position.offset-n.startOffset}return e.position}(n,s,r);if(a==(i?"elementStart":"elementEnd")){if(o.isSelectable(l))return Po._createAt(l,i?"after":"before");if(o.checkChild(c,"$text"))return c}else{if(o.isLimit(l))return void n.skip(()=>!0);if(o.checkChild(c,"$text"))return c}}function Ml(e,t){const i=e.root,n=Po._createAt(i,t?"end":0);return t?new Bo(e,n):new Bo(n,e)}function Fl(e,t,i){const n=t+(i?0:-1);return' ,.?!:;"-()'.includes(e.charAt(n))}function Nl(e,t,i){return t===(i?e.offsetSize:0)}const Ll=De();var Dl=class extends Ll{markers;document;schema;_config;_pendingChanges;_currentWriter;constructor(e){super(),this.markers=new ul,this.document=new al(this),this.schema=new qr,this._config=e,this._pendingChanges=[],this._currentWriter=null,["deleteContent","modifySelection","getSelectedContent","applyOperation"].forEach(e=>this.decorate(e)),this.on("applyOperation",(e,t)=>{t[0]._validate()},{priority:"highest"}),this.schema.register("$root",{isLimit:!0}),this.schema.register("$inlineRoot",{allowContentOf:"$block",allowAttributesOf:"$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","$inlineRoot"],allowChildren:"$text",isLimit:!0}),this.schema.register("$documentFragment",{allowContentOf:["$root","$inlineRoot"],allowChildren:"$text",isLimit:!0}),this.schema.register("$marker"),this.schema.addChildCheck(()=>!0,"$marker"),yl(this),this.document.registerPostFixer(Or),this.on("insertContent",(e,[t,i])=>{e.return=function(e,t,i){return e.change(n=>{const s=i||e.document.selection;s.isCollapsed||e.deleteContent(s,{doNotAutoparagraph:!0});const o=new Ol(e,n,s.anchor),r=[];let a;if(t.is("documentFragment")){if(t.markers.size){const e=[];for(const[i,n]of t.markers){const{start:t,end:s}=n,o=t.isEqual(s);e.push({position:t,name:i,isCollapsed:o},{position:s,name:i,isCollapsed:o})}e.sort(({position:e},{position:t})=>e.isBefore(t)?1:-1);for(const{position:i,name:s,isCollapsed:o}of e){let e=null,a=null;const l=i.parent===t&&i.isAtStart,c=i.parent===t&&i.isAtEnd;l||c?o&&(a=l?"start":"end"):(e=n.createElement("$marker"),n.insert(e,i)),r.push({name:s,element:e,collapsed:a})}}a=t.getChildren()}else a=[t];o.handleNodes(a);let l=o.getSelectionRange();if(t.is("documentFragment")&&r.length){const e=l?ir.fromRange(l):null,t={};for(let e=r.length-1;e>=0;e--){const{name:i,element:s,collapsed:a}=r[e],l=!t[i];if(l&&(t[i]=[]),s){const e=n.createPositionAt(s,"before");t[i].push(e),n.remove(s)}else{const e=o.getAffectedRange();if(!e){a&&t[i].push(o.position);continue}a?t[i].push(e[a]):t[i].push(l?e.start:e.end)}}for(const[e,[i,s]]of Object.entries(t))i&&s&&i.root===s.root&&i.root.document&&!n.model.markers.has(e)&&n.addMarker(e,{usingOperation:!0,affectsData:!0,range:new Bo(i,s)});e&&(l=e.toRange(),e.detach())}l&&(s instanceof lr?n.setSelection(l):s.setTo(l));const c=o.getAffectedRange()||e.createRange(s.anchor);return o.destroy(),c})}(this,t,i)}),this.on("insertObject",(e,[t,i,n])=>{e.return=Rl(this,t,i,n)}),this.on("canEditAt",e=>{const t=!this.document.isReadOnly;e.return=t,t||e.stop()})}change(e){try{return 0===this._pendingChanges.length?(this._pendingChanges.push({batch:new Ya,callback:e}),this._runPendingChanges()[0]):e(this._currentWriter)}catch(e){fe.rethrowUnexpectedError(e,this)}}enqueueChange(e,t){try{e?"function"==typeof e?(t=e,e=new Ya):e instanceof Ya||(e=new Ya(e)):e=new Ya,this._pendingChanges.push({batch:e,callback:t}),1==this._pendingChanges.length&&this._runPendingChanges()}catch(e){fe.rethrowUnexpectedError(e,this)}}applyOperation(e){e._execute()}insertContent(e,t,i,...n){const s=zl(t,i);return this.fire("insertContent",[e,s,i,...n])}insertObject(e,t,i,n,...s){const o=zl(t,i);return this.fire("insertObject",[e,o,n,n,...s])}deleteContent(e,t){Tl(this,e,t)}modifySelection(e,t){!function(e,t,i={}){const n=e.schema,s="backward"!=i.direction,o=i.unit?i.unit:"character",r=!!i.treatEmojiAsSingleUnit,a=t.focus,l=new Eo({boundaries:Ml(a,s),singleCharacters:!0,direction:s?"forward":"backward"}),c={walker:l,schema:n,isForward:s,unit:o,treatEmojiAsSingleUnit:r};let d;for(;d=l.next();){if(d.done)return;const i=Bl(c,d.value);if(i)return void(t instanceof lr?e.change(e=>{e.setSelectionFocus(i)}):t.setFocus(i))}}(this,e,t)}getSelectedContent(e){return function(e,t){return e.change(e=>{const i=e.createDocumentFragment(),n=t.getFirstRange();if(!n||n.isCollapsed)return i;const s=n.start.root,o=n.start.getCommonPath(n.end),r=s.getNodeByPath(o);let a;a=n.start.parent==n.end.parent?n:e.createRange(e.createPositionAt(r,n.start.path[o.length]),e.createPositionAt(r,n.end.path[o.length]+1));const l=a.end.offset-a.start.offset;for(const t of a.getItems({shallow:!0}))t.is("$textProxy")?e.appendText(t.data,t.getAttributes(),i):e.append(e.cloneElement(t,!0),i);if(a!=n){const t=n._getTransformedByMove(a.start,e.createPositionAt(i,0),l)[0],s=e.createRange(e.createPositionAt(i,0),t.start);Vl(e.createRange(t.end,e.createPositionAt(i,"end")),e),Vl(s,e)}return i})}(this,e)}hasContent(e,t={}){let i;i=e.is("selection")?Array.from(e.getRanges()):e.is("range")?[e]:[Bo._createIn(e)];for(const e of i)if(this._rangeHasContent(e,t))return!0;return!1}_rangeHasContent(e,t){if(e.isCollapsed)return!1;const{ignoreWhitespaces:i=!1,ignoreMarkers:n=!1}=t;if(!n)for(const t of this.markers.getMarkersIntersectingRange(e))if(t.affectsData)return!0;for(const t of e.getItems())if(this.schema.isContent(t)){if(!t.is("$textProxy"))return!0;if(!i)return!0;if(-1!==t.data.search(/\S/))return!0}return!1}canEditAt(e){const t=zl(e);return this.fire("canEditAt",[t])}createPositionFromPath(e,t,i){return new Po(e,t,i)}createPositionAt(e,t){return Po._createAt(e,t)}createPositionAfter(e){return Po._createAfter(e)}createPositionBefore(e){return Po._createBefore(e)}createRange(e,t){return new Bo(e,t)}createRangeIn(e){return Bo._createIn(e)}createRangeOn(e){return Bo._createOn(e)}createSelection(...e){return new Go(...e)}createBatch(e){return new Ya(e)}createOperationFromJSON(e){return Ba.fromJSON(e,this.document)}destroy(){this.document.destroy(),this.markers.destroy(),this.stopListening()}_runPendingChanges(){const e=[];this.fire("_beforeChanges");try{for(;this._pendingChanges.length;){const t=this._pendingChanges[0].batch;this._currentWriter=new fl(this,t);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 zl(e,t){if(e)return e instanceof Go||e instanceof lr?e:e instanceof jo?t||0===t?new Go(e,t):e.is("rootElement")?new Go(e,"in"):new Go(e,"on"):new Go(e)}var Hl=class extends lo{domEventType="click";onDomEvent(e){this.fire(e.type,e)}},$l=class extends lo{domEventType=["mousedown","mouseup","mouseover","mouseout"];onDomEvent(e){this.fire(e.type,e)}},Wl=class extends lo{domEventType=["touchstart","touchend","touchmove"];onDomEvent(e){this.fire(e.type,e)}},Ul=class extends lo{domEventType=["pointerdown","pointerup","pointermove"];onDomEvent(e){this.fire(e.type,e)}},ql=class{document;constructor(e){this.document=e}createDocumentFragment(e){return new ys(this.document,e)}createElement(e,t,i){return new Mn(this.document,e,t,i)}createText(e){return new vn(this.document,e)}clone(e,t=!1){return e._clone(t)}appendChild(e,t){return t._appendChild(e)}insertChild(e,t,i){return i._insertChild(e,t)}removeChildren(e,t,i){return i._removeChildren(e,t)}remove(e){const t=e.parent;return t?this.removeChildren(t.getChildIndex(e),1,t):[]}replace(e,t){const i=e.parent;if(i){const n=i.getChildIndex(e);return this.removeChildren(n,1,i),this.insertChild(n,t,i),!0}return!1}unwrapElement(e){const t=e.parent;if(t){const i=t.getChildIndex(e);this.remove(e),this.insertChild(i,e.getChildren(),t)}}rename(e,t){const i=new Mn(this.document,e,t.getAttributes(),t.getChildren());return this.replace(t,i)?i:null}setAttribute(e,t,i){i._setAttribute(e,t)}removeAttribute(e,t){t._removeAttribute(e)}addClass(e,t){t._addClass(e)}removeClass(e,t){t._removeClass(e)}setStyle(e,t,i){o(e)&&void 0===i?t._setStyle(e):i._setStyle(e,t)}removeStyle(e,t){t._removeStyle(e)}setCustomProperty(e,t,i){i._setCustomProperty(e,t)}removeCustomProperty(e,t){return t._removeCustomProperty(e)}createPositionAt(e,t){return qn._createAt(e,t)}createPositionAfter(e){return qn._createAfter(e)}createPositionBefore(e){return qn._createBefore(e)}createRange(e,t){return new jn(e,t)}createRangeOn(e){return jn._createOn(e)}createRangeIn(e){return jn._createIn(e)}createSelection(...e){return new Jn(...e)}};const jl=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,Kl=/^rgb\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}[0-9]{1,3}[ %]?\)$/i,Gl=/^rgba\([ ]?([0-9]{1,3}[ %]?,[ ]?){3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i,Jl=/^hsl\([ ]?([0-9]{1,3}[ %]?[,]?[ ]*){3}(1|[0-9]+%|[0]?\.?[0-9]+)?\)$/i,Ql=/^hsla\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i,Yl=/\w+\((?:[^()]|\([^()]*\))*\)|\S+/gi,Xl=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 Zl(e){return e.startsWith("#")?jl.test(e):e.startsWith("rgb")?Kl.test(e)||Gl.test(e):e.startsWith("hsl")?Jl.test(e)||Ql.test(e):Xl.has(e.toLowerCase())}const ec=["none","hidden","dotted","dashed","solid","double","groove","ridge","inset","outset"];function tc(e){return ec.includes(e)}const ic=/^([+-]?[0-9]*([.][0-9]+)?(px|cm|mm|in|pc|pt|ch|em|ex|rem|vh|vw|vmin|vmax)|0)$/;function nc(e){return ic.test(e)}const sc=/^[+-]?[0-9]*([.][0-9]+)?%$/;function oc(e){return sc.test(e)}const rc=["auto","cover","contain"];function ac(e){return rc.includes(e)||nc(e)||oc(e)}const lc=["repeat-x","repeat-y","repeat","space","round","no-repeat"];function cc(e){return lc.includes(e)}const dc=["center","top","bottom","left","right"];function uc(e){return dc.includes(e)}const hc=["fixed","scroll","local"];function mc(e){return hc.includes(e)}const gc=["border-box","padding-box","content-box"];function fc(e){return gc.includes(e)}const pc=["border-box","padding-box","content-box","text"];function bc(e){return pc.includes(e)}function wc(e=""){if(""===e)return{top:void 0,right:void 0,bottom:void 0,left:void 0};const t=kc(e),i=t[0],n=t[2]||i,s=t[1]||i;return{top:i,bottom:n,right:s,left:t[3]||s}}function _c(e){return t=>{const{top:i,right:n,bottom:s,left:o}=t,r=[];return[i,n,o,s].every(e=>!!e)?r.push([e,vc(t)]):(i&&r.push([e+"-top",i]),n&&r.push([e+"-right",n]),s&&r.push([e+"-bottom",s]),o&&r.push([e+"-left",o])),r}}function vc({top:e,right:t,bottom:i,left:n}){const s=[];return n!==t?s.push(e,t,i,n):i!==e?s.push(e,t,i):t!==e?s.push(e,t):s.push(e),s.join(" ")}function yc(e){return t=>({path:e,value:wc(t)})}function kc(e){const t=e.trim().slice(0,1500).matchAll(Yl);return Array.from(t).map(e=>e[0])}const Cc={image:"none",repeat:"repeat",position:"0% 0%",size:"auto",origin:"padding-box",clip:"border-box",attachment:"scroll"},Ac=["linear-gradient","repeating-linear-gradient","radial-gradient","repeating-radial-gradient","conic-gradient","repeating-conic-gradient","url"];function Tc(e){e.setNormalizer("background-color",e=>({path:"background.color",value:e}));for(const t in Cc)e.setNormalizer(`background-${t}`,Ec(`background.${t}`)),e.setReducer(`background-${t}`,xc(`background-${t}`));e.setNormalizer("background",e=>{const t=function(e){return Vc(e).map(Sc).filter(e=>null!==e)}(e);return t.length||t.push({...Ic(),color:e}),{path:"background",value:Pc(t)}}),e.setReducer("background",e=>{const t=e;return Object.keys(Cc).every(e=>{const i=t[e];return void 0!==i&&(!Array.isArray(i)||i.length>0)})?function(e){const t=[],i=function(e){const t=function(e){let t=0;for(const i of Object.values(e))Array.isArray(i)&&i.length>t&&(t=i.length);return t}(e),i=Array.from({length:t},(t,i)=>{const n=Ic();return e.image?.[i]&&(n.image=e.image[i]),e.position?.[i]&&(n.position=e.position[i].split(" ")),e.size?.[i]&&(n.size=e.size[i].split(" ")),e.repeat?.[i]&&(n.repeat=e.repeat[i].split(" ")),e.attachment?.[i]&&(n.attachment=e.attachment[i]),e.origin?.[i]&&(n.origin=e.origin[i]),e.clip?.[i]&&(n.clip=e.clip[i]),n});return e.color&&(i.at(-1).color=e.color),i}(e).map(e=>function(e){const t=[];e.image&&e.image!==Cc.image&&t.push(e.image);const i=e.position.join(" "),n=!i||i===Cc.position;n||t.push(i);const s=e.size.join(" ");s&&s!==Cc.size&&(n&&t.push("0% 0%"),t.push("/",s));const o=e.repeat.join(" ");o&&o!==Cc.repeat&&t.push(o),e.attachment&&e.attachment!==Cc.attachment&&t.push(e.attachment);const r=e.origin===Cc.origin,a=e.clip===Cc.clip;return r&&a||(t.push(e.origin),e.clip!==e.origin&&t.push(e.clip)),e.color&&t.push(e.color),t.join(" ")}(e).trim()).filter(Boolean).join(", ");return i&&t.push(["background",i]),t}(t):function(e){const t=[];for(const i in Cc){const n=e[i];Array.isArray(n)&&t.push([`background-${i}`,n.join(", ")])}return void 0!==e.color&&t.push(["background-color",e.color]),t}(t)}),e.setStyleRelation("background",["background-color","background-image","background-repeat","background-position","background-size","background-attachment","background-origin","background-clip"])}function Ec(e){return t=>({path:e,value:Vc(t)})}function xc(e){return t=>[[e,t.join(", ")]]}function Pc(e){const t={image:[],position:[],size:[],repeat:[],attachment:[],origin:[],clip:[]};for(const i of e)t.position.push(i.position.join(" ")),t.size.push(i.size.join(" ")),t.repeat.push(i.repeat.join(" ")),t.image.push(i.image),t.attachment.push(i.attachment),t.origin.push(i.origin),t.clip.push(i.clip);return e.at(-1)?.color&&(t.color=e.at(-1).color),t}function Sc(e){const t={},{value:i,image:n}=function(e){for(const t of Ac){const i=t+"(",n=e.indexOf(i);if(n<0)continue;let s=t,o=0;for(let i=n+t.length;i"constructor"!==e).length:0===t.length}return!0}(t)?null:{...Ic(),...t}}function Ic(){return{attachment:Cc.attachment,image:Cc.image,origin:Cc.origin,clip:Cc.clip,position:Cc.position.split(" "),repeat:Cc.repeat.split(" "),size:Cc.size.split(" ")}}function Vc(e){const t=[];let i="",n=0;for(const s of e){if("("===s)n++;else if(")"===s)n--;else if(","===s&&0===n){t.push(i.trim()),i="";continue}i+=s}return i.trim()&&t.push(i.trim()),t}function Oc(e){e.setNormalizer("border",e=>{const{color:t,style:i,width:n}=Dc(e);return{path:"border",value:{color:wc(t),style:wc(i),width:wc(n)}}}),e.setNormalizer("border-top",Rc("top")),e.setNormalizer("border-right",Rc("right")),e.setNormalizer("border-bottom",Rc("bottom")),e.setNormalizer("border-left",Rc("left")),e.setNormalizer("border-color",Bc("color")),e.setNormalizer("border-width",Bc("width")),e.setNormalizer("border-style",Bc("style")),e.setNormalizer("border-top-color",Fc("color","top")),e.setNormalizer("border-top-style",Fc("style","top")),e.setNormalizer("border-top-width",Fc("width","top")),e.setNormalizer("border-right-color",Fc("color","right")),e.setNormalizer("border-right-style",Fc("style","right")),e.setNormalizer("border-right-width",Fc("width","right")),e.setNormalizer("border-bottom-color",Fc("color","bottom")),e.setNormalizer("border-bottom-style",Fc("style","bottom")),e.setNormalizer("border-bottom-width",Fc("width","bottom")),e.setNormalizer("border-left-color",Fc("color","left")),e.setNormalizer("border-left-style",Fc("style","left")),e.setNormalizer("border-left-width",Fc("width","left")),e.setExtractor("border-top",Nc("top")),e.setExtractor("border-right",Nc("right")),e.setExtractor("border-bottom",Nc("bottom")),e.setExtractor("border-left",Nc("left")),e.setExtractor("border-top-color","border.color.top"),e.setExtractor("border-right-color","border.color.right"),e.setExtractor("border-bottom-color","border.color.bottom"),e.setExtractor("border-left-color","border.color.left"),e.setExtractor("border-top-width","border.width.top"),e.setExtractor("border-right-width","border.width.right"),e.setExtractor("border-bottom-width","border.width.bottom"),e.setExtractor("border-left-width","border.width.left"),e.setExtractor("border-top-style","border.style.top"),e.setExtractor("border-right-style","border.style.right"),e.setExtractor("border-bottom-style","border.style.bottom"),e.setExtractor("border-left-style","border.style.left"),e.setReducer("border-color",_c("border-color")),e.setReducer("border-style",_c("border-style")),e.setReducer("border-width",_c("border-width")),e.setReducer("border-top",zc("top")),e.setReducer("border-right",zc("right")),e.setReducer("border-bottom",zc("bottom")),e.setReducer("border-left",zc("left")),e.setReducer("border",function(){return t=>{const i=Lc(t,"top"),n=Lc(t,"right"),s=Lc(t,"bottom"),o=Lc(t,"left"),r=[i,n,s,o],a={width:e(r,"width"),style:e(r,"style"),color:e(r,"color")},l=Hc(a,"all");return l.length?l:[...Object.entries(a).reduce((e,[t,i])=>(i&&(e.push([`border-${t}`,i]),r.forEach(e=>delete e[t])),e),[]),...Hc(i,"top"),...Hc(n,"right"),...Hc(s,"bottom"),...Hc(o,"left")]};function e(e,t){return e.map(e=>e[t]).reduce((e,t)=>e==t?e:null)}}()),e.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"]),e.setStyleRelation("border-color",["border-top-color","border-right-color","border-bottom-color","border-left-color"]),e.setStyleRelation("border-style",["border-top-style","border-right-style","border-bottom-style","border-left-style"]),e.setStyleRelation("border-width",["border-top-width","border-right-width","border-bottom-width","border-left-width"]),e.setStyleRelation("border-top",["border-top-color","border-top-style","border-top-width"]),e.setStyleRelation("border-right",["border-right-color","border-right-style","border-right-width"]),e.setStyleRelation("border-bottom",["border-bottom-color","border-bottom-style","border-bottom-width"]),e.setStyleRelation("border-left",["border-left-color","border-left-style","border-left-width"])}function Rc(e){return t=>{const{color:i,style:n,width:s}=Dc(t),o={};return void 0!==i&&(o.color={[e]:i}),void 0!==n&&(o.style={[e]:n}),void 0!==s&&(o.width={[e]:s}),{path:"border",value:o}}}function Bc(e){return t=>({path:"border",value:Mc(t,e)})}function Mc(e,t){return{[t]:wc(e)}}function Fc(e,t){return i=>({path:"border",value:{[e]:{[t]:i}}})}function Nc(e){return(t,i)=>{if(i.border)return Lc(i.border,e)}}function Lc(e,t){const i={};return e.width&&e.width[t]&&(i.width=e.width[t]),e.style&&e.style[t]&&(i.style=e.style[t]),e.color&&e.color[t]&&(i.color=e.color[t]),i}function Dc(e){const t={},i=kc(e);for(const e of i)nc(e)||/thin|medium|thick/.test(e)?t.width=e:tc(e)?t.style=e:t.color=e;return t}function zc(e){return t=>Hc(t,e)}function Hc(e,t){const i=[];if(e&&e.width&&i.push("width"),e&&e.style&&i.push("style"),e&&e.color&&i.push("color"),3==i.length){const n=i.map(t=>e[t]).join(" ");return["all"==t?["border",n]:[`border-${t}`,n]]}return"all"==t?[]:i.map(i=>[`border-${t}-${i}`,e[i]])}function $c(e){e.setNormalizer("margin",yc("margin")),e.setNormalizer("margin-top",e=>({path:"margin.top",value:e})),e.setNormalizer("margin-right",e=>({path:"margin.right",value:e})),e.setNormalizer("margin-bottom",e=>({path:"margin.bottom",value:e})),e.setNormalizer("margin-left",e=>({path:"margin.left",value:e})),e.setReducer("margin",_c("margin")),e.setStyleRelation("margin",["margin-top","margin-right","margin-bottom","margin-left"])}function Wc(e){e.setNormalizer("padding",yc("padding")),e.setNormalizer("padding-top",e=>({path:"padding.top",value:e})),e.setNormalizer("padding-right",e=>({path:"padding.right",value:e})),e.setNormalizer("padding-bottom",e=>({path:"padding.bottom",value:e})),e.setNormalizer("padding-left",e=>({path:"padding.left",value:e})),e.setReducer("padding",_c("padding")),e.setStyleRelation("padding",["padding-top","padding-right","padding-bottom","padding-left"])}Symbol("_treeDump");var Uc=class{crashes=[];state="initializing";_crashNumberLimit;_now=Date.now;_minimumNonErrorTimePeriod;_boundErrorHandler;_listeners;constructor(e){if(this.crashes=[],this._crashNumberLimit="number"==typeof e.crashNumberLimit?e.crashNumberLimit:3,this._minimumNonErrorTimePeriod="number"==typeof e.minimumNonErrorTimePeriod?e.minimumNonErrorTimePeriod:5e3,this._boundErrorHandler=e=>{const t="error"in e?e.error:e.reason;t instanceof Error&&this._handleError(t,e)},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,t){this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t)}off(e,t){this._listeners[e]=this._listeners[e].filter(e=>e!==t)}_fire(e,...t){const i=this._listeners[e]||[];for(const e of i)e.apply(this,[null,...t])}_startErrorHandling(){window.addEventListener("error",this._boundErrorHandler),window.addEventListener("unhandledrejection",this._boundErrorHandler)}_stopErrorHandling(){window.removeEventListener("error",this._boundErrorHandler),window.removeEventListener("unhandledrejection",this._boundErrorHandler)}_handleError(e,t){if(this._shouldReactToError(e)){this.crashes.push({message:e.message,stack:e.stack,filename:t instanceof ErrorEvent?t.filename:void 0,lineno:t instanceof ErrorEvent?t.lineno:void 0,colno:t instanceof ErrorEvent?t.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")&&void 0!==e.context&&null!==e.context&&"ready"===this.state&&this._isErrorComingFromThisItem(e)}_shouldRestart(){return this.crashes.length<=this._crashNumberLimit||(this.crashes[this.crashes.length-1].date-this.crashes[this.crashes.length-1-this._crashNumberLimit].date)/this._crashNumberLimit>this._minimumNonErrorTimePeriod}};function qc(e,t=new Set){const i=[e],n=new Set;let s=0;for(;i.length>s;){const e=i[s++];if(!n.has(e)&&jc(e)&&!t.has(e))if(n.add(e),Symbol.iterator in e)try{for(const t of e)i.push(t)}catch{}else for(const t in e)"defaultValue"!==t&&i.push(e[t])}return n}function jc(e){const t=Object.prototype.toString.call(e),i=typeof e;return!("number"===i||"boolean"===i||"string"===i||"symbol"===i||"function"===i||"[object Date]"===t||"[object RegExp]"===t||"[object Module]"===t||null==e||e._watchdogExcluded||e instanceof EventTarget||e instanceof Event)}function Kc(e,t,i=new Set){if(e===t&&("object"==typeof(n=e)&&null!==n))return!0;var n;const s=qc(e,i),o=qc(t,i);for(const e of s)if(o.has(e))return!0;return!1}function Gc(e,t,i){const n=t.root,s=t.roots||Object.create(null);i&&!s[i]&&(s[i]=n||Object.create(null));const o=function(e){return!!e&&"object"==typeof e&&!Array.isArray(e)&&(t=e,!F(t));var t}(e),r=function(e,t,i){return t||!i?e.initialData||Object.create(null):{[i]:e.initialData}}(t,o,i),a=Array.from(new Set([...o?Object.keys(e):[],...Object.keys(s),...Object.keys(r)]));for(const e of a){const i=s[e]||Object.create(null);i.initialData="",i.placeholder??=Jc(t,"placeholder",e),i.label??=Jc(t,"label",e),s[e]=i}t.roots=s}function Jc(e,t,i){const n=e[t];if(n)return"string"==typeof n?n:n[i]}var Qc=class extends Uc{_editor=null;_lifecyclePromise=null;_throttledSave;_data;_lastDocumentVersion;_elementOrData;_editorAttachTo=null;_isSingleRootEditor=!0;_isUsingConfigBasedCreator=!1;_editables={};_config;_excludedProps;constructor(e,t={}){super(t),this._throttledSave=Vi(this._save.bind(this),"number"==typeof t.saveInterval?t.saveInterval:5e3),e&&(this._creator=(t,i)=>void 0===i?e.create(t):e.create(t,i)),this._destructor=e=>e.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(()=>{this._isUsingConfigBasedCreator?Gc(this._isSingleRootEditor?"":{},this._config,!!this._isSingleRootEditor&&"main"):Gc(this._isSingleRootEditor?this._editorAttachTo||"":this._editables,this._config,!!this._isSingleRootEditor&&"main");const e={...this._config,extraPlugins:this._config.extraPlugins||[],_watchdogInitialData:this._data};e.extraPlugins.push(Yc);const t={};for(const[i,n]of Object.entries(this._data.roots)){const s=e.roots[i]||Object.create(null);s.initialData="",s.modelElement=n.modelElement,this._isUsingConfigBasedCreator&&(this._editables[i]?.isConnected?s.element=this._editables[i]:n.isLoaded&&!s.element&&Object.assign(s,Zc(n.attributes))),n.isLoaded?s.lazyLoad=!1:delete s.modelAttributes,t[i]=s}if(e.roots=t,delete e.initialData,delete e.root,this._isUsingConfigBasedCreator)return this.create(e,e.context);const i=this._isSingleRootEditor?this._editorAttachTo||"":this._editables;return this.create(i,e,e.context)}).then(()=>{this._fire("restart")})}create(e=(this._isUsingConfigBasedCreator?this._config:this._elementOrData),t=(this._isUsingConfigBasedCreator?void 0:this._config),i){const n=this._detectConfigBasedCreator(e,t),s=n?void 0:e,o=n?e:t,r=n?t:i;return this._lifecyclePromise=Promise.resolve(this._lifecyclePromise).then(()=>{if(super._startErrorHandling(),this._isUsingConfigBasedCreator=n,this._elementOrData=s,this._config=this._cloneEditorConfiguration(o||{}),this._config.context=r,n){this._editorAttachTo=null;const e=this._config.roots?Object.keys(this._config.roots).length:0,t=this._config.initialData,i=t&&"object"==typeof t;this._isSingleRootEditor=!i&&e<=1}else this._editorAttachTo=Xc(s)?s:null,this._isSingleRootEditor=Xc(s)||"string"==typeof s;return n?this._creator(this._config):this._creator(s,this._config)}).then(e=>{this._editor=e,e.model.document.on("change:data",this._throttledSave),this._lastDocumentVersion=e.model.document.version,this._data=this._getData(),this._editorAttachTo||(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._editorAttachTo||(this._editables=this._getEditables()),this._lastDocumentVersion=e}catch(e){console.error(e,"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,t=e.model.document.roots.filter(e=>e.isAttached()&&"$graveyard"!=e.rootName),{plugins:i}=e,n=i.has("CommentsRepository")&&i.get("CommentsRepository"),s=i.has("TrackChanges")&&i.get("TrackChanges"),o={roots:{},markers:{},commentThreads:JSON.stringify([]),suggestions:JSON.stringify([])};t.forEach(e=>{o.roots[e.rootName]={content:JSON.stringify(Array.from(e.getChildren())),attributes:JSON.stringify(Array.from(e.getAttributes())),modelElement:e.name,isLoaded:e._isLoaded}});for(const t of e.model.markers)t._affectsData&&(o.markers[t.name]={rangeJSON:t.getRange().toJSON(),usingOperation:t._managedUsingOperations,affectsData:t._affectsData});return n&&(o.commentThreads=JSON.stringify(n.getCommentThreads({toJSON:!0,skipNotAttached:!0}))),s&&(o.suggestions=JSON.stringify(s.getSuggestions({toJSON:!0,skipNotAttached:!0}))),o}_getEditables(){const e={};for(const t of this.editor.model.document.getRootNames()){const i=this.editor.ui.getEditableElement(t);i&&(e[t]=i)}return e}_isErrorComingFromThisItem(e){return Kc(this._editor,e.context,this._excludedProps)}_detectConfigBasedCreator(e,t){if("string"==typeof e||Xc(e))return!1;if(t&&"object"==typeof t&&!("destroy"in t)&&Object.keys(t).length>0)return!1;if(e&&"object"==typeof e){const t=Object.values(e);if(t.length>0&&t.every(e=>"string"==typeof e||Xc(e)))return!1}return!0}_cloneEditorConfiguration(e){return B(e,(e,t)=>Xc(e)||"context"===t?e:void 0)}},Yc=class{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},e=>{this._restoreCollaborationData(),this._restoreEditorData(e)}),this.editor.data.fire("ready")},{priority:999})}_createNode(e,t){if("name"in t){const i=e.createElement(t.name,t.attributes);if(t.children)for(const n of t.children)i._appendChild(this._createNode(e,n));return i}return e.createText(t.data,t.attributes)}_restoreEditorData(e){const t=this.editor;Object.entries(this._data.roots).forEach(([i,{content:n,attributes:s}])=>{const o=JSON.parse(n),r=JSON.parse(s),a=t.model.document.getRoot(i);for(const[t,i]of r)e.setAttribute(t,i,a);for(const t of o){const i=this._createNode(e,t);e.insert(i,a,"end")}}),Object.entries(this._data.markers).forEach(([i,n])=>{const{document:s}=t.model,{rangeJSON:{start:o,end:r},...a}=n,l=s.getRoot(o.root),c=e.createPositionFromPath(l,o.path,o.stickiness),d=e.createPositionFromPath(l,r.path,r.stickiness),u=e.createRange(c,d);e.addMarker(i,{range:u,...a})})}_restoreCollaborationData(){const e=JSON.parse(this._data.commentThreads),t=JSON.parse(this._data.suggestions);if(this.editor.plugins.has("CommentsRepository")){const t=this.editor.plugins.get("CommentsRepository");for(const e of t.getCommentThreads())t._removeCommentThread({threadId:e.id});e.forEach(e=>{const t=this.editor.config.get("collaboration.channelId");this.editor.plugins.get("CommentsRepository").addCommentThread({channelId:t,...e})})}if(this.editor.plugins.has("TrackChangesEditing")){const e=this.editor.plugins.get("TrackChangesEditing");for(const t of e.getSuggestions())e._removeSuggestion(t);t.forEach(t=>{e.addSuggestionData(t)})}}};function Xc(e){return F(e)}function Zc(e){const{$rootEditableOptions:t}=Object.fromEntries(JSON.parse(e));return t&&"object"==typeof t?{...t.placeholder&&{placeholder:t.placeholder},...t.label&&{label:t.label},...t.element&&{element:t.element}}:{}}const ed=Symbol("MainQueueId");var td=class extends Uc{_watchdogs=new Map;_watchdogConfig;_context=null;_contextProps=new Set;_actionQueues=new id;_contextConfig;_item;constructor(e,t={}){super(t),this._watchdogConfig=t,this._creator=t=>e.create(t),this._destructor=e=>e.destroy(),this._actionQueues.onEmpty(()=>{"initializing"===this.state&&(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(ed,()=>(this._contextConfig=e,this._create()))}getItem(e){return this._getWatchdog(e)._item}getItemState(e){return this._getWatchdog(e).state}add(e){const t=nd(e);return Promise.all(t.map(e=>this._actionQueues.enqueue(e.id,()=>{if("destroyed"===this.state)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 t;if(this._watchdogs.has(e.id))throw new Error(`Item with the given id is already added: '${e.id}'.`);if("editor"===e.type)return t=new Qc(null,this._watchdogConfig),t.setCreator(e.creator),t._setExcludedProperties(this._contextProps),e.destructor&&t.setDestructor(e.destructor),this._watchdogs.set(e.id,t),t.on("error",(i,{error:n,causesRestart:s})=>{this._fire("itemError",{itemId:e.id,error:n}),s&&this._actionQueues.enqueue(e.id,()=>new Promise(i=>{const n=()=>{t.off("restart",n),this._fire("itemRestart",{itemId:e.id}),i()};t.on("restart",n)}))}),void 0!==e.sourceElementOrData?t.create(e.sourceElementOrData,e.config,this._context):t.create(e.config,this._context);throw new Error(`Not supported item type: '${e.type}'.`)})))}remove(e){const t=nd(e);return Promise.all(t.map(e=>this._actionQueues.enqueue(e,()=>{const t=this._getWatchdog(e);return this._watchdogs.delete(e),t.destroy()})))}destroy(){return this._actionQueues.enqueue(ed,()=>(this.state="destroyed",this._fire("stateChange"),super.destroy(),this._destroy()))}_restart(){return this._actionQueues.enqueue(ed,()=>(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=qc(this._context),Promise.all(Array.from(this._watchdogs.values()).map(e=>(e._setExcludedProperties(this._contextProps),e._isUsingConfigBasedCreator?e.create(void 0,this._context):e.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(e=>e.destroy())).then(()=>this._destructor(e))})}_getWatchdog(e){const t=this._watchdogs.get(e);if(!t)throw new Error(`Item with the given id was not registered: ${e}.`);return t}_isErrorComingFromThisItem(e){for(const t of this._watchdogs.values())if(t._isErrorComingFromThisItem(e))return!1;return Kc(this._context,e.context)}},id=class{_onEmptyCallbacks=[];_queues=new Map;_activeActions=0;onEmpty(e){this._onEmptyCallbacks.push(e)}enqueue(e,t){const i=e===ed;this._activeActions++,this._queues.get(e)||this._queues.set(e,Promise.resolve());const n=(i?Promise.all(this._queues.values()):Promise.all([this._queues.get(ed),this._queues.get(e)])).then(t),s=n.catch(()=>{});return this._queues.set(e,s),n.finally(()=>{this._activeActions--,this._queues.get(e)===s&&0===this._activeActions&&this._onEmptyCallbacks.forEach(e=>e())})}};function nd(e){return Array.isArray(e)?e:[e]}const sd=De();var od=class extends sd{editor;_disableStack=new Set;constructor(e){super(),this.editor=e,this.set("isEnabled",!0)}forceDisabled(e){this._disableStack.add(e),1==this._disableStack.size&&(this.on("set:isEnabled",rd,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(e){this._disableStack.delete(e),0==this._disableStack.size&&(this.off("set:isEnabled",rd),this.isEnabled=!0)}destroy(){this.stopListening()}static get isContextPlugin(){return!1}static get isOfficialPlugin(){return!1}static get isPremiumPlugin(){return!1}};function rd(e){e.return=!1,e.stop()}const ad=De();var ld=class extends ad{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",t=>{if(!this.affectsData)return;const i=e.model.document.selection,n=!("$graveyard"==i.getFirstPosition().root.rootName)&&e.model.canEditAt(i);(e.isReadOnly||this._isEnabledBasedOnSelection&&!n)&&(t.return=!1,t.stop())},{priority:"highest"}),this.on("execute",e=>{this.isEnabled||e.stop()},{priority:"high"})}get affectsData(){return this._affectsData}set affectsData(e){this._affectsData=e}refresh(){this.isEnabled=!0}forceDisabled(e){this._disableStack.add(e),1==this._disableStack.size&&(this.on("set:isEnabled",cd,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(e){this._disableStack.delete(e),0==this._disableStack.size&&(this.off("set:isEnabled",cd),this.refresh())}execute(...e){}destroy(){this.stopListening()}};function cd(e){e.return=!1,e.stop()}var dd=class extends ld{_childCommandsDefinitions=[];refresh(){}execute(...e){const t=this._getFirstEnabledCommand();return!!t&&t.execute(e)}registerChildCommand(e,t={}){ge(this._childCommandsDefinitions,{command:e,priority:t.priority||"normal"}),e.on("change:isEnabled",()=>this._checkEnabled()),this._checkEnabled()}_checkEnabled(){this.isEnabled=!!this._getFirstEnabledCommand()}_getFirstEnabledCommand(){const e=this._childCommandsDefinitions.find(({command:e})=>e.isEnabled);return e&&e.command}},ud=class{_commands;constructor(){this._commands=new Map}add(e,t){this._commands.set(e,t)}get(e){return this._commands.get(e)}execute(e,...t){const i=this.get(e);if(!i)throw new fe("commandcollection-command-not-found",this,{commandName:e});return i.execute(...t)}*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()}};const hd=Te();var md=class extends hd{_context;_plugins=new Map;_availablePlugins;_contextPlugins;constructor(e,t=[],i=[]){super(),this._context=e,this._availablePlugins=new Map;for(const e of t)e.pluginName&&this._availablePlugins.set(e.pluginName,e);this._contextPlugins=new Map;for(const[e,t]of i)this._contextPlugins.set(e,t),this._contextPlugins.set(t,e),e.pluginName&&this._availablePlugins.set(e.pluginName,e)}*[Symbol.iterator](){for(const e of this._plugins)"function"==typeof e[0]&&(yield e)}get(e){const t=this._plugins.get(e);if(!t){let t=e;throw"function"==typeof e&&(t=e.pluginName||e.name),new fe("plugincollection-plugin-not-loaded",this._context,{plugin:t})}return t}has(e){return this._plugins.has(e)}async init(e,t=[],i=[]){const n=this,s=this._context;!function e(t,i=new Set){t.forEach(t=>{a(t)&&(i.has(t)||(i.add(t),t.pluginName&&!n._availablePlugins.has(t.pluginName)&&n._availablePlugins.set(t.pluginName,t),t.requires&&e(t.requires,i)))})}(e),u(e);const o=[...function e(t,i=new Set){return t.map(e=>a(e)?e:n._availablePlugins.get(e)).reduce((t,n)=>i.has(n)?t:(i.add(n),n.requires&&(u(n.requires,n),e(n.requires,i).forEach(e=>t.add(e))),t.add(n)),new Set)}(e.filter(e=>!c(e,t)))];!function(e,t){for(const i of t){if("function"!=typeof i)throw new fe("plugincollection-replace-plugin-invalid-type",null,{pluginItem:i});const t=i.pluginName;if(!t)throw new fe("plugincollection-replace-plugin-missing-name",null,{pluginItem:i});if(i.requires&&i.requires.length)throw new fe("plugincollection-plugin-for-replacing-cannot-have-dependencies",null,{pluginName:t});const s=n._availablePlugins.get(t);if(!s)throw new fe("plugincollection-plugin-for-replacing-not-exist",null,{pluginName:t});const o=e.indexOf(s);if(-1===o){if(n._contextPlugins.has(s))return;throw new fe("plugincollection-plugin-for-replacing-not-loaded",null,{pluginName:t})}if(s.requires&&s.requires.length)throw new fe("plugincollection-replaced-plugin-cannot-have-dependencies",null,{pluginName:t});e.splice(o,1,i),n._availablePlugins.set(t,i)}}(o,i);const r=function(e){return e.map(e=>{let t=n._contextPlugins.get(e);return t=t||new e(s),n._add(e,t),t})}(o);return await h(r,"init"),await h(r,"afterInit"),r;function a(e){return"function"==typeof e}function l(e){return a(e)&&!!e.isContextPlugin}function c(e,t){return t.some(t=>t===e||(d(e)===t||d(t)===e))}function d(e){return a(e)?e.pluginName||e.name:e}function u(e,i=null){e.map(e=>a(e)?e:n._availablePlugins.get(e)||e).forEach(e=>{!function(e){if("function"!=typeof e)return;if(e._throwErrorWhenUsedAsAPlugin)throw new fe("plugincollection-plugin-invalid-constructor",s,{name:e.name})}(e),function(e,t){if(a(e))return;if(t)throw new fe("plugincollection-soft-required",s,{missingPlugin:e,requiredBy:d(t)});throw new fe("plugincollection-plugin-not-found",s,{plugin:e})}(e,i),function(e,t){if(!l(t))return;if(l(e))return;throw new fe("plugincollection-context-required",s,{plugin:d(e),requiredBy:d(t)})}(e,i),function(e,i){if(!i)return;if(!c(e,t))return;throw new fe("plugincollection-required",s,{plugin:d(e),requiredBy:d(i)})}(e,i)})}function h(e,t){return e.reduce((e,i)=>i[t]?n._contextPlugins.has(i)?e:e.then(i[t].bind(i)):e,Promise.resolve())}}destroy(){const e=[];for(const[,t]of this)"function"!=typeof t.destroy||this._contextPlugins.has(t)||e.push(t.destroy());return Promise.all(e)}_add(e,t){this._plugins.set(e,t);const i=e.pluginName;if(i){if(this._plugins.has(i))throw new fe("plugincollection-plugin-name-conflict",null,{pluginName:i,plugin1:this._plugins.get(i).constructor,plugin2:e});this._plugins.set(i,t)}}},gd=class{config;plugins;locale;t;editors;static defaultConfig;static builtinPlugins;_contextOwner=null;constructor(e){const{translations:t,...i}=e||{};this.config=new Qe(i,this.constructor.defaultConfig);const n=this.constructor.builtinPlugins;this.config.define("plugins",n),this.plugins=new md(this,n);const s=this.config.get("language")||{};this.locale=new si({uiLanguage:"string"==typeof s?s:s.ui,contentLanguage:this.config.get("language.content"),translations:t}),this.t=this.locale.t,this.editors=new ri}initPlugins(){const e=this.config.get("plugins")||[],t=this.config.get("substitutePlugins")||[];for(const i of e.concat(t)){if("function"!=typeof i)throw new fe("context-initplugins-constructor-only",null,{Plugin:i});if(!0!==i.isContextPlugin)throw new fe("context-initplugins-invalid-plugin",null,{Plugin:i})}return this.plugins.init(e,[],t)}destroy(){return Promise.all(Array.from(this.editors,e=>e.destroy())).then(()=>this.plugins.destroy())}_addEditor(e,t){if(this._contextOwner)throw new fe("context-addeditor-private-context");this.editors.add(e),t&&(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 t of this.config.names())["plugins","removePlugins","extraPlugins"].includes(t)||(e[t]=this.config.get(t));return e}static create(e){return new Promise(t=>{const i=new this(e);t(i.initPlugins().then(()=>i))})}static get _throwErrorWhenUsedAsAPlugin(){return!0}};const fd=De();var pd=class extends fd{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}},bd=class extends mi{editor;constructor(e){super(),this.editor=e}set(e,t,i={}){if("string"==typeof t){const e=t;t=(t,i)=>{this.editor.execute(e),i()}}super.set(e,t,i)}};const wd="contentEditing",_d="common";var vd=class{keystrokeInfos=new Map;_editor;constructor(e){this._editor=e;const t=e.config.get("menuBar.isVisible"),i=e.locale.t;this.addKeystrokeInfoCategory({id:wd,label:i("Content editing keystrokes"),description:i("These keyboard shortcuts allow for quick access to content editing features.")});const n=[{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"]]}];t&&n.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:n}]})}addKeystrokeInfoCategory({id:e,label:t,description:i,groups:n}){this.keystrokeInfos.set(e,{id:e,label:t,description:i,groups:new Map}),this.addKeystrokeInfoGroup({categoryId:e,id:_d}),n&&n.forEach(t=>{this.addKeystrokeInfoGroup({categoryId:e,...t})})}addKeystrokeInfoGroup({categoryId:e=wd,id:t,label:i,keystrokes:n}){const s=this.keystrokeInfos.get(e);if(!s)throw new fe("accessibility-unknown-keystroke-info-category",this._editor,{groupId:t,categoryId:e});s.groups.set(t,{id:t,label:i,keystrokes:n||[]})}addKeystrokeInfos({categoryId:e=wd,groupId:t=_d,keystrokes:i}){if(!this.keystrokeInfos.has(e))throw new fe("accessibility-unknown-keystroke-info-category",this._editor,{categoryId:e,keystrokes:i});const n=this.keystrokeInfos.get(e);if(!n.groups.has(t))throw new fe("accessibility-unknown-keystroke-info-group",this._editor,{groupId:t,categoryId:e,keystrokes:i});n.groups.get(t).keystrokes.push(...i)}};function yd(e){return Object.getPrototypeOf(e).constructor.editorName}function kd(e){if(!e)return;const t=Array.isArray(e)?{items:e}:e,i=function e(t){return t.flatMap(t=>"string"==typeof t?[t]:e(t.items))}(t.items||[]);return{isMultiline:i.includes("-"),shouldNotGroupWhenFull:!!t.shouldNotGroupWhenFull,items:(n=i,n.filter(e=>"|"!==e&&"-"!==e))};var n}function Cd(){let e="unknown",t="unknown";return Y.isMac?e="mac":Y.isWindows?e="windows":Y.isiOS?e="ios":Y.isAndroid&&(e="android"),Y.isGecko?t="gecko":Y.isBlink?t="blink":Y.isSafari&&(t="safari"),{os:e,browser:t}}function Ad(){return localStorage.getItem("__ckeditor-session-id")||localStorage.setItem("__ckeditor-session-id",he()),localStorage.getItem("__ckeditor-session-id")}function Td(){return G.window.CKEDITOR_PAGE_SESSION_ID=G.window.CKEDITOR_PAGE_SESSION_ID||he(),G.window.CKEDITOR_PAGE_SESSION_ID}const Ed=De();var xd=class extends Ed{static get editorName(){return"Editor"}accessibility;commands;config;conversion;data;editing;locale;model;plugins;keystrokes;t;static defaultConfig;static builtinPlugins;_context;_readOnlyLocks;_registeredRootsAttributesKeys=new Set;static get _throwErrorWhenUsedAsAPlugin(){return!0}constructor(e={}){if(super(),"object"!=typeof e||Array.isArray(e))throw new fe("editor-config-invalid-type");if("sanitizeHtml"in e)throw new fe("editor-config-sanitizehtml-not-supported");const t=this.constructor,{translations:i,...n}=t.defaultConfig||{},{translations:s=i,...o}=e,r=e.language||n.language;this._context=e.context||new gd({language:r,translations:s}),this._context._addEditor(this,!e.context);const a=Array.from(t.builtinPlugins||[]);this.config=new Qe(o,n),this.config.define("plugins",a),this.config.define(this._context._getEditorConfig()),function(e){let t=e.get("licenseKey");!t&&window.CKEDITOR_GLOBAL_LICENSE_KEY&&(t=window.CKEDITOR_GLOBAL_LICENSE_KEY,e.set("licenseKey",t));if(!t)throw new fe("license-key-missing")}(this.config),this.plugins=new md(this,a,this._context.plugins),this.locale=this._context.locale,this.t=this.locale.t,this._readOnlyLocks=new Set,this.commands=new ud,this.set("state","initializing"),this.once("ready",()=>this.state="ready",{priority:"high"}),this.once("destroy",()=>this.state="destroyed",{priority:"high"}),this.model=new Dl(this.config),this.on("change:isReadOnly",()=>{this.model.document.isReadOnly=this.isReadOnly});const l=new In;this.data=new ua(this.model,l),this.editing=new Wr(this.model,l),this.editing.view.document.bind("isReadOnly").to(this),this.conversion=new ha([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 bd(this),this.keystrokes.listenTo(this.editing.view.document),this.accessibility=new vd(this),function(e){const t=e.config.get("licenseKey"),i=window[Symbol.for("cke distribution")]||"sh";function n(t,i){e.enableReadOnlyMode(Symbol("invalidLicense")),e._showLicenseError(t,i)}if("GPL"==t)return void("cloud"==i&&n("distributionChannel"));const s=Ti(t);if(!s)return void n("invalid");if(!function(e){return["exp","jti","vc"].every(t=>t in e)}(s))return void n("invalid");if(s.distributionChannel&&!ii(s.distributionChannel).includes(i))return void n("distributionChannel");if(function(e){const t=Array.isArray(e)?e:[e],i=function(){const e=[];for(let t=0;t<256;t++){let i=t;for(let e=0;e<8;e++)1&i?i=3988292384^i>>>1:i>>>=1;e[t]=i}return e}();let n=-1;const s=t.map(e=>Array.isArray(e)?e.join(""):String(e)).join("");for(let e=0;e>>8^i[255&(n^s.charCodeAt(e))];return n=(-1^n)>>>0,n.toString(16).padStart(8,"0")}(function(e){return Object.getOwnPropertyNames(e).sort().filter(t=>"vc"!=t&&null!=e[t]).map(t=>e[t])}(s))!=s.vc.toLowerCase())return void n("invalid");if(new Date(1e3*s.exp)0&&!function(e){const{hostname:t}=new URL(window.location.href);if(e.includes(t))return!0;const i=t.split(".");return e.filter(e=>e.includes("*")).map(e=>e.split(".")).filter(e=>e.length<=i.length).map(e=>Array(i.length-e.length).fill("*"===e[0]?"*":"").concat(e)).some(e=>i.every((t,i)=>e[i]===t||"*"===e[i]))}(o))return void n("domainLimit");if(["evaluation","trial"].includes(s.licenseType)&&1e3*s.exp{n("evaluationLimit")},6e5);e.on("destroy",()=>{clearTimeout(t)})}s.usageEndpoint&&e.once("ready",()=>{const i={requestId:he(),requestTime:Math.round(Date.now()/1e3),license:t,editor:Pd(e)};e._sendUsageRequest(s.usageEndpoint,i).then(e=>{const{status:t,message:i}=e;i&&console.warn(i),"ok"!=t&&n("usageLimit")},()=>{be("license-key-validation-endpoint-not-reachable",{url:s.usageEndpoint})})},{priority:"high"})}(this)}get isReadOnly(){return this._readOnlyLocks.size>0}set isReadOnly(e){throw new fe("editor-isreadonly-has-no-setter")}enableReadOnlyMode(e){if("string"!=typeof e&&"symbol"!=typeof e)throw new fe("editor-read-only-lock-id-invalid",null,{lockId:e});this._readOnlyLocks.has(e)||(this._readOnlyLocks.add(e),1===this._readOnlyLocks.size&&this.fire("change:isReadOnly","isReadOnly",!0,!1))}disableReadOnlyMode(e){if("string"!=typeof e&&"symbol"!=typeof e)throw new fe("editor-read-only-lock-id-invalid",null,{lockId:e});this._readOnlyLocks.has(e)&&(this._readOnlyLocks.delete(e),0===this._readOnlyLocks.size&&this.fire("change:isReadOnly","isReadOnly",!1,!0))}setData(e){this.data.set(e)}getData(e){return this.data.get(e)}async initPlugins(){const e=this.config,t=e.get("plugins"),i=e.get("removePlugins")||[],n=e.get("extraPlugins")||[],s=e.get("substitutePlugins")||[],o=await this.plugins.init(t.concat(n),i,s);return function(e){const t=e.config.get("licenseKey");if("GPL"===t)return;const i=Ti(t);if(!i)return;const n=[...e.plugins].map(([e])=>e).find(e=>!!e.pluginName&&(!!e.licenseFeatureCode&&Ei(i,e.licenseFeatureCode)));n&&(e.enableReadOnlyMode(Symbol("invalidLicense")),e._showLicenseError("pluginNotAllowed",n.pluginName))}(this),o}async destroy(){"initializing"==this.state&&await new Promise(e=>this.once("ready",e)),this.fire("destroy"),this.stopListening(),this.commands.destroy(),await this.plugins.destroy(),this.model.destroy(),this.data.destroy(),this.editing.destroy(),this.keystrokes.destroy(),await this._context._removeEditor(this)}execute(e,...t){try{return this.commands.execute(e,...t)}catch(e){fe.rethrowUnexpectedError(e,this)}}focus(){this.editing.view.focus()}registerRootAttribute(e){this._registeredRootsAttributesKeys.has(e)||(this._registeredRootsAttributesKeys.add(e),this.editing.model.schema.extend("$root",{allowAttributes:e}))}getRootAttributes(e="main"){const t=this.model.document.getRoot(e);if(!t)throw new fe("get-root-attributes-missing-root",this,{rootName:e});const i={};for(const e of this._registeredRootsAttributesKeys)i[e]=t.hasAttribute(e)?t.getAttribute(e):null;return i}static create(...e){throw new Error("This is an abstract method.")}static Context=gd;static EditorWatchdog=Qc;static ContextWatchdog=td;_showLicenseError(e,t){setTimeout(()=>{if("invalid"==e)throw new fe("invalid-license-key");if("expired"==e)throw new fe("license-key-expired");if("domainLimit"==e)throw new fe("license-key-domain-limit");if("pluginNotAllowed"==e){const e=t.replace(/(Editing|UI)$/,"");throw new fe("license-key-plugin-not-allowed",null,{pluginName:this.plugins.has(e)?e:t})}if("featureNotAllowed"==e)throw new fe("license-key-feature-not-allowed",null,{featureName:t});if("evaluationLimit"==e)throw new fe("license-key-evaluation-limit");if("trialLimit"==e)throw new fe("license-key-trial-limit");if("developmentLimit"==e)throw new fe("license-key-development-limit");if("usageLimit"==e)throw new fe("license-key-usage-limit");if("distributionChannel"==e)throw new fe("license-key-invalid-distribution-channel")},0),this._showLicenseError=()=>{}}async _sendUsageRequest(e,t){const i=new Headers({"Content-Type":"application/json"}),n=await fetch(new URL(e),{method:"POST",headers:i,body:JSON.stringify(t)});if(!n.ok)throw new Error(`HTTP Response: ${n.status}`);return n.json()}};function Pd(e){const t=function(e){return{sessionId:Ad(),pageSessionId:Td(),hostname:window.location.hostname,version:globalThis.CKEDITOR_VERSION,type:yd(e),plugins:(t=e.plugins,Array.from(t).filter(([e])=>!!e.pluginName).map(([e])=>{const{pluginName:t,isContextPlugin:i,isOfficialPlugin:n,isPremiumPlugin:s}=e;return{isContext:!!i,isOfficial:!!n,isPremium:!!s,name:t}})),distribution:{channel:window[Symbol.for("cke distribution")]||"sh"},env:Cd(),integration:Object.create(null),menuBar:{isVisible:!!e.config.get("menuBar.isVisible")},language:{ui:e.locale.uiLanguage,content:e.locale.contentLanguage},toolbar:{main:kd(e.config.get("toolbar")),block:kd(e.config.get("blockToolbar")),balloon:kd(e.config.get("balloonToolbar"))}};var t}(e);return e.fire("collectUsageData",{setUsageData:function(e,i){if(void 0!==ji(t,e))throw new fe("editor-usage-data-path-already-set",{path:e});Zi(t,e,i)}}),t}function Sd(e){if(!N(e.updateSourceElement))throw new fe("attachtoform-missing-elementapi-interface",e);const t=e.sourceElement;if(function(e){return!!e&&"textarea"===e.tagName.toLowerCase()}(t)&&t.form){let i;const n=t.form,s=()=>e.updateSourceElement();N(n.submit)&&(i=n.submit,n.submit=()=>{s(),i.apply(n)}),n.addEventListener("submit",s),e.on("destroy",()=>{n.removeEventListener("submit",s),i&&(n.submit=i)})}}function Id(e){return class extends e{sourceElement;updateSourceElement(e){if(!this.sourceElement)throw new fe("editor-missing-sourceelement",this);const t=this.config.get("updateSourceElementOnDestroy"),i=this.sourceElement instanceof HTMLTextAreaElement;if(!t&&!i)return void kt(this.sourceElement,"");const n="string"==typeof e?e:this.data.get();kt(this.sourceElement,n)}}}const Vd=[["description","$description"],["title","$title"]];function Od(e){const t=e.config.get("roots");for(const[i,n]of Object.entries(t)){let t=null;for(const[e,i]of Vd)null==n[e]||n.modelAttributes&&i in n.modelAttributes||(t=t||{...n.modelAttributes},t[i]=n[e]);t&&e.config.set(`roots.${i}.modelAttributes`,t)}const i=e.config.get("roots");let n=!1;for(const t of Object.values(i))for(const i of Object.keys(t.modelAttributes||{}))e.registerRootAttribute(i),n=!0;n&&e.data.once("init",()=>{e.model.enqueueChange({isUndoable:!1},t=>{for(const[n,s]of Object.entries(i)){const i=e.model.document.getRoot(n);if(i)for(const[e,n]of Object.entries(s.modelAttributes||{}))null!==n&&t.setAttribute(e,n,i)}})})}function Rd(e,t,i="main",n=!1){const s=t.get("root"),r=t.get("roots")||Object.create(null);if(!o(r))throw new fe("editor-create-roots-not-plain-object",null);if(s){if(!i)throw new fe("editor-create-multi-root-with-main",null);if(i in r)throw new fe("editor-create-roots-with-main",null)}i&&!r[i]&&(r[i]=s||Object.create(null));const a=function(e){return!!e&&"object"==typeof e&&!Array.isArray(e)&&!zd(e)}(e),l=function(e,t,i){return t||!i?e.get("initialData")||Object.create(null):{[i]:e.get("initialData")}}(t,a,i),c=Array.from(new Set([...a?Object.keys(e):[],...Object.keys(r),...Object.keys(l)]));for(const i of c){const s=r[i]||Object.create(null),o=a?e[i]:e;if(!n&&zd(o)){if(s.element)throw new fe("editor-create-root-element-overspecified",null);s.element=o}if(n&&zd(s.element)&&(pe("editor-create-root-element-not-supported"),s.element=void 0),void 0===s.initialData)if(void 0===l[i]){const e=zd(s.element)?s.element:void 0;s.initialData=Md(o||e||n&&t.get("attachTo")||"")}else{if(o&&!zd(o))throw new fe("editor-create-initial-data-overspecified",null);s.initialData=l[i]}else{if(o&&!zd(o))throw new fe("editor-create-root-initial-data-overspecified",null);if(void 0!==l[i])throw new fe("editor-create-legacy-initial-data-overspecified",null)}s.placeholder??=Fd(t,"placeholder",i),s.label??=Fd(t,"label",i),s.modelElement||="$root",s.element=Nd(s.element),r[i]=s}if(n&&zd(e)){if(t.get("attachTo"))throw new fe("editor-create-attachto-overspecified",null);t.set("attachTo",e)}if(!n&&t.get("attachTo"))throw new fe("editor-create-attachto-ignored",null);t.set("roots",r)}function Bd(e,t){return"string"==typeof e||zd(e)||t&&Object.keys(t).length?{sourceElementOrData:e,editorConfig:t}:{sourceElementOrData:"",editorConfig:e}}function Md(e){return zd(e)?(t=e)instanceof HTMLTextAreaElement?t.value:t.innerHTML:e;var t}function Fd(e,t,i){const n=e.get(t);if(n)return"string"==typeof n?n:n[i]}function Nd(e){if(null==e)return;if(zd(e))return Dd(e.tagName),e;if("string"==typeof e)return Dd(e),{name:e};const{name:t,classes:i,styles:n,attributes:s}=e;void 0!==t&&Dd(t);const{class:o,style:r,...a}=s||{},l=!!s&&"class"in s,c=!!n&&Object.keys(n).length>0,d=c&&!!r;d&&pe("editor-root-element-styles-overspecified");const u=[...Ld(i),...Ld(o)],h={...a};return l&&(h.class=""),d?h.style="":r&&(h.style=r),{...void 0!==t&&{name:t},...u.length&&{classes:u},...c&&{styles:n},...Object.keys(h).length&&{attributes:h}}}function Ld(e){return e?ii(e).flatMap(e=>e.split(/\s+/)).filter(Boolean):[]}function Dd(e){if("string"!=typeof e||!/^[A-Za-z][A-Za-z0-9_-]*$/.test(e))throw new fe("editor-wrong-element-name",null,{name:e});if(["textarea","input"].includes(e.toLowerCase()))throw new fe("editor-wrong-element",null)}function zd(e){return F(e)}function Hd(e){const t=e.model.schema,i=e.model.document;for(const e of i.roots)if(e!==i.graveyard&&e.isAttached()&&!t.isLimit(e))throw new fe("editor-root-element-is-not-limit",null,{rootName:e.rootName,elementName:e.name})}function $d(e,t){const i=e.model.document.getRoot(t);return e.model.schema.checkChild(i,"$block")}var Wd=class extends pd{_actions;static get pluginName(){return"PendingActions"}static get isOfficialPlugin(){return!0}init(){this.set("hasAny",!1),this._actions=new ri({idProperty:"_id"}),this._actions.delegate("add","remove").to(this)}add(e){if("string"!=typeof e)throw new fe("pendingactions-add-invalid-message",this);const t=new(De());return t.set("message",e),this._actions.add(t),this.hasAny=!0,t}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]()}},Ud=' ',qd=' ',jd=' ',Kd=' ',Gd=' ',Jd=' ',Qd=' ',Yd=' ',Xd=' ',Zd=' ',eu=' ',tu=' ',iu=' ',nu=' ',su=' ',ou=' ',ru=' ',au=' ',lu=' ',cu=' ',du=' ',uu=' ',hu=' ',mu=' ',gu=' ',fu=' ',pu=' ',bu=' ',wu=' ',_u=' ',vu=' ',yu=' ',ku=' ',Cu=' ',Au=' \n',Tu=' ',Eu=' ',xu=' ',Pu=' ',Su=' ';const Iu={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};for(const e in Iu)Object.freeze(Iu[e]);const Vu=Object.freeze(Iu),Ou=function(e){var t,i,n=[],s=1;if("number"==typeof e)return{space:"rgb",values:[e>>>16,(65280&e)>>>8,255&e],alpha:1};if("number"==typeof e)return{space:"rgb",values:[e>>>16,(65280&e)>>>8,255&e],alpha:1};if(e=String(e).toLowerCase(),Vu[e])n=Vu[e].slice(),i="rgb";else if("transparent"===e)s=0,i="rgb",n=[0,0,0];else if("#"===e[0]){var o=e.slice(1),r=o.length;s=1,r<=4?(n=[parseInt(o[0]+o[0],16),parseInt(o[1]+o[1],16),parseInt(o[2]+o[2],16)],4===r&&(s=parseInt(o[3]+o[3],16)/255)):(n=[parseInt(o[0]+o[1],16),parseInt(o[2]+o[3],16),parseInt(o[4]+o[5],16)],8===r&&(s=parseInt(o[6]+o[7],16)/255)),n[0]||(n[0]=0),n[1]||(n[1]=0),n[2]||(n[2]=0),i="rgb"}else if(t=/^((?:rgba?|hs[lvb]a?|hwba?|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms|oklch|oklab|color))\s*\(([^\)]*)\)/.exec(e)){var a=t[1],l="cmyk"===(i=a.replace(/a$/,""))?4:"gray"===i?1:3;n=t[2].trim().split(/\s*[,\/]\s*|\s+/),"color"===i&&(i=n.shift()),n=n.map(function(e,t){if("%"===e[e.length-1])return e=parseFloat(e)/100,3===t?e:"rgb"===i?255*e:"h"===i[0]?100*e:"l"!==i[0]||t?"lab"===i?125*e:"lch"===i?t<2?150*e:360*e:"o"!==i[0]||t?"oklab"===i?.4*e:"oklch"===i?t<2?.4*e:360*e:e:e:100*e;if("h"===i[t]||2===t&&"h"===i[i.length-1]){if(void 0!==Ru[e])return Ru[e];if(e.endsWith("deg"))return parseFloat(e);if(e.endsWith("turn"))return 360*parseFloat(e);if(e.endsWith("grad"))return 360*parseFloat(e)/400;if(e.endsWith("rad"))return 180*parseFloat(e)/Math.PI}return"none"===e?0:parseFloat(e)}),s=n.length>l?n.pop():1}else/[0-9](?:\s|\/|,)/.test(e)&&(n=e.match(/([0-9]+)/g).map(function(e){return parseFloat(e)}),i=e.match(/([a-z])/gi)?.join("")?.toLowerCase()||"rgb");return{space:i,values:n,alpha:s}};var Ru={red:0,orange:60,yellow:120,green:180,blue:240,purple:300};const Bu={};for(const e of Object.keys(Vu))Bu[Vu[e]]=e;const Mu={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},oklab:{channels:3,labels:["okl","oka","okb"]},lch:{channels:3,labels:"lch"},oklch:{channels:3,labels:["okl","okc","okh"]},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}},Fu=Mu,Nu=(6/29)**3;function Lu(e){const t=e>.0031308?1.055*e**(1/2.4)-.055:12.92*e;return Math.min(Math.max(0,t),1)}function Du(e){return e>.04045?((e+.055)/1.055)**2.4:e/12.92}for(const e of Object.keys(Mu)){if(!("channels"in Mu[e]))throw new Error("missing channels property: "+e);if(!("labels"in Mu[e]))throw new Error("missing channel labels property: "+e);if(Mu[e].labels.length!==Mu[e].channels)throw new Error("channel and label counts mismatch: "+e);const{channels:t,labels:i}=Mu[e];delete Mu[e].channels,delete Mu[e].labels,Object.defineProperty(Mu[e],"channels",{value:t}),Object.defineProperty(Mu[e],"labels",{value:i})}function zu(e,t){return(e[0]-t[0])**2+(e[1]-t[1])**2+(e[2]-t[2])**2}function Hu(e){const t=function(){const e={},t=Object.keys(Fu);for(let{length:i}=t,n=0;n0;){const e=i.pop(),n=Object.keys(Fu[e]);for(let{length:s}=n,o=0;o1&&(s-=1)}return[360*s,100*o,100*c]},Mu.rgb.hwb=function(e){const t=e[0],i=e[1];let n=e[2];const s=Mu.rgb.hsl(e)[0],o=1/255*Math.min(t,Math.min(i,n));return n=1-1/255*Math.max(t,Math.max(i,n)),[s,100*o,100*n]},Mu.rgb.oklab=function(e){const t=Du(e[0]/255),i=Du(e[1]/255),n=Du(e[2]/255),s=Math.cbrt(.4122214708*t+.5363325363*i+.0514459929*n),o=Math.cbrt(.2119034982*t+.6806995451*i+.1073969566*n),r=Math.cbrt(.0883024619*t+.2817188376*i+.6299787005*n);return[100*(.2104542553*s+.793617785*o-.0040720468*r),100*(1.9779984951*s-2.428592205*o+.4505937099*r),100*(.0259040371*s+.7827717662*o-.808675766*r)]},Mu.rgb.cmyk=function(e){const t=e[0]/255,i=e[1]/255,n=e[2]/255,s=Math.min(1-t,1-i,1-n);return[100*((1-t-s)/(1-s)||0),100*((1-i-s)/(1-s)||0),100*((1-n-s)/(1-s)||0),100*s]},Mu.rgb.keyword=function(e){const t=Bu[e];if(t)return t;let i,n=Number.POSITIVE_INFINITY;for(const t of Object.keys(Vu)){const s=zu(e,Vu[t]);sNu?i**(1/3):7.787*i+16/116,n=n>Nu?n**(1/3):7.787*n+16/116,s=s>Nu?s**(1/3):7.787*s+16/116;return[116*n-16,500*(i-n),200*(n-s)]},Mu.hsl.rgb=function(e){const t=e[0]/360,i=e[1]/100,n=e[2]/100;let s,o;if(0===i)return o=255*n,[o,o,o];const r=n<.5?n*(1+i):n+i-n*i,a=2*n-r,l=[0,0,0];for(let e=0;e<3;e++)s=t+1/3*-(e-1),s<0&&s++,s>1&&s--,o=6*s<1?a+6*(r-a)*s:2*s<1?r:3*s<2?a+(r-a)*(2/3-s)*6:a,l[e]=255*o;return l},Mu.hsl.hsv=function(e){const t=e[0];let i=e[1]/100,n=e[2]/100,s=i;const o=Math.max(n,.01);n*=2,i*=n<=1?n:2-n,s*=o<=1?o:2-o;return[t,100*(0===n?2*s/(o+s):2*i/(n+i)),100*((n+i)/2)]},Mu.hsv.rgb=function(e){const t=e[0]/60,i=e[1]/100;let n=e[2]/100;const s=Math.floor(t)%6,o=t-Math.floor(t),r=255*n*(1-i),a=255*n*(1-i*o),l=255*n*(1-i*(1-o));switch(n*=255,s){case 0:return[n,l,r];case 1:return[a,n,r];case 2:return[r,n,l];case 3:return[r,a,n];case 4:return[l,r,n];case 5:return[n,r,a]}},Mu.hsv.hsl=function(e){const t=e[0],i=e[1]/100,n=e[2]/100,s=Math.max(n,.01);let o,r;r=(2-i)*n;const a=(2-i)*s;return o=i*s,o/=a<=1?a:2-a,o=o||0,r/=2,[t,100*o,100*r]},Mu.hwb.rgb=function(e){const t=e[0]/360;let i=e[1]/100,n=e[2]/100;const s=i+n;let o;s>1&&(i/=s,n/=s);const r=Math.floor(6*t),a=1-n;o=6*t-r,1&r&&(o=1-o);const l=i+o*(a-i);let c,d,u;switch(r){default:case 6:case 0:c=a,d=l,u=i;break;case 1:c=l,d=a,u=i;break;case 2:c=i,d=a,u=l;break;case 3:c=i,d=l,u=a;break;case 4:c=l,d=i,u=a;break;case 5:c=a,d=i,u=l}return[255*c,255*d,255*u]},Mu.cmyk.rgb=function(e){const t=e[0]/100,i=e[1]/100,n=e[2]/100,s=e[3]/100;return[255*(1-Math.min(1,t*(1-s)+s)),255*(1-Math.min(1,i*(1-s)+s)),255*(1-Math.min(1,n*(1-s)+s))]},Mu.xyz.rgb=function(e){const t=e[0]/100,i=e[1]/100,n=e[2]/100;let s,o,r;return s=3.2404542*t+-1.5371385*i+-.4985314*n,o=-.969266*t+1.8760108*i+.041556*n,r=.0556434*t+-.2040259*i+1.0572252*n,s=Lu(s),o=Lu(o),r=Lu(r),[255*s,255*o,255*r]},Mu.xyz.lab=function(e){let t=e[0],i=e[1],n=e[2];t/=95.047,i/=100,n/=108.883,t=t>Nu?t**(1/3):7.787*t+16/116,i=i>Nu?i**(1/3):7.787*i+16/116,n=n>Nu?n**(1/3):7.787*n+16/116;return[116*i-16,500*(t-i),200*(i-n)]},Mu.xyz.oklab=function(e){const t=e[0]/100,i=e[1]/100,n=e[2]/100,s=Math.cbrt(.8189330101*t+.3618667424*i-.1288597137*n),o=Math.cbrt(.0329845436*t+.9293118715*i+.0361456387*n),r=Math.cbrt(.0482003018*t+.2643662691*i+.633851707*n);return[100*(.2104542553*s+.793617785*o-.0040720468*r),100*(1.9779984951*s-2.428592205*o+.4505937099*r),100*(.0259040371*s+.7827717662*o-.808675766*r)]},Mu.oklab.oklch=function(e){return Mu.lab.lch(e)},Mu.oklab.xyz=function(e){const t=e[0]/100,i=e[1]/100,n=e[2]/100,s=(.999999998*t+.396337792*i+.215803758*n)**3,o=(1.000000008*t-.105561342*i-.063854175*n)**3,r=(1.000000055*t-.089484182*i-1.291485538*n)**3;return[100*(1.227013851*s-.55779998*o+.281256149*r),100*(-.040580178*s+1.11225687*o-.071676679*r),100*(-.076381285*s-.421481978*o+1.58616322*r)]},Mu.oklab.rgb=function(e){const t=e[0]/100,i=e[1]/100,n=e[2]/100,s=(t+.3963377774*i+.2158037573*n)**3,o=(t-.1055613458*i-.0638541728*n)**3,r=(t-.0894841775*i-1.291485548*n)**3;return[255*Lu(4.0767416621*s-3.3077115913*o+.2309699292*r),255*Lu(-1.2684380046*s+2.6097574011*o-.3413193965*r),255*Lu(-.0041960863*s-.7034186147*o+1.707614701*r)]},Mu.oklch.oklab=function(e){return Mu.lch.lab(e)},Mu.lab.xyz=function(e){let t,i,n;i=(e[0]+16)/116,t=e[1]/500+i,n=i-e[2]/200;const s=i**3,o=t**3,r=n**3;return i=s>Nu?s:(i-16/116)/7.787,t=o>Nu?o:(t-16/116)/7.787,n=r>Nu?r:(n-16/116)/7.787,t*=95.047,i*=100,n*=108.883,[t,i,n]},Mu.lab.lch=function(e){const t=e[0],i=e[1],n=e[2];let s;s=360*Math.atan2(n,i)/2/Math.PI,s<0&&(s+=360);return[t,Math.sqrt(i*i+n*n),s]},Mu.lch.lab=function(e){const t=e[0],i=e[1],n=e[2]/360*2*Math.PI;return[t,i*Math.cos(n),i*Math.sin(n)]},Mu.rgb.ansi16=function(e,t=null){const[i,n,s]=e;let o=null===t?Mu.rgb.hsv(e)[2]:t;if(o=Math.round(o/50),0===o)return 30;let r=30+(Math.round(s/255)<<2|Math.round(n/255)<<1|Math.round(i/255));return 2===o&&(r+=60),r},Mu.hsv.ansi16=function(e){return Mu.rgb.ansi16(Mu.hsv.rgb(e),e[2])},Mu.rgb.ansi256=function(e){const t=e[0],i=e[1],n=e[2];if(t>>4==i>>4&&i>>4==n>>4)return t<8?16:t>248?231:Math.round((t-8)/247*24)+232;return 16+36*Math.round(t/255*5)+6*Math.round(i/255*5)+Math.round(n/255*5)},Mu.ansi16.rgb=function(e){let t=(e=e[0])%10;if(0===t||7===t)return e>50&&(t+=3.5),t=t/10.5*255,[t,t,t];const i=.5*(Math.trunc(e>50)+1);return[(1&t)*i*255,(t>>1&1)*i*255,(t>>2&1)*i*255]},Mu.ansi256.rgb=function(e){if((e=e[0])>=232){const t=10*(e-232)+8;return[t,t,t]}let t;e-=16;return[Math.floor(e/36)/5*255,Math.floor((t=e%36)/6)/5*255,t%6/5*255]},Mu.rgb.hex=function(e){const t=(((255&Math.round(e[0]))<<16)+((255&Math.round(e[1]))<<8)+(255&Math.round(e[2]))).toString(16).toUpperCase();return"000000".slice(t.length)+t},Mu.hex.rgb=function(e){const t=e.toString(16).match(/[a-f\d]{6}|[a-f\d]{3}/i);if(!t)return[0,0,0];let i=t[0];3===t[0].length&&(i=[...i].map(e=>e+e).join(""));const n=Number.parseInt(i,16);return[n>>16&255,n>>8&255,255&n]},Mu.rgb.hcg=function(e){const t=e[0]/255,i=e[1]/255,n=e[2]/255,s=Math.max(Math.max(t,i),n),o=Math.min(Math.min(t,i),n),r=s-o;let a;return a=r<=0?0:s===t?(i-n)/r%6:s===i?2+(n-t)/r:4+(t-i)/r,a/=6,a%=1,[360*a,100*r,100*(r<1?o/(1-r):0)]},Mu.hsl.hcg=function(e){const t=e[1]/100,i=e[2]/100,n=i<.5?2*t*i:2*t*(1-i);let s=0;return n<1&&(s=(i-.5*n)/(1-n)),[e[0],100*n,100*s]},Mu.hsv.hcg=function(e){const t=e[1]/100,i=e[2]/100,n=t*i;let s=0;return n<1&&(s=(i-n)/(1-n)),[e[0],100*n,100*s]},Mu.hcg.rgb=function(e){const t=e[0]/360,i=e[1]/100,n=e[2]/100;if(0===i)return[255*n,255*n,255*n];const s=[0,0,0],o=t%1*6,r=o%1,a=1-r;let l=0;switch(Math.floor(o)){case 0:s[0]=1,s[1]=r,s[2]=0;break;case 1:s[0]=a,s[1]=1,s[2]=0;break;case 2:s[0]=0,s[1]=1,s[2]=r;break;case 3:s[0]=0,s[1]=a,s[2]=1;break;case 4:s[0]=r,s[1]=0,s[2]=1;break;default:s[0]=1,s[1]=0,s[2]=a}return l=(1-i)*n,[255*(i*s[0]+l),255*(i*s[1]+l),255*(i*s[2]+l)]},Mu.hcg.hsv=function(e){const t=e[1]/100,i=t+e[2]/100*(1-t);let n=0;return i>0&&(n=t/i),[e[0],100*n,100*i]},Mu.hcg.hsl=function(e){const t=e[1]/100,i=e[2]/100*(1-t)+.5*t;let n=0;return i>0&&i<.5?n=t/(2*i):i>=.5&&i<1&&(n=t/(2*(1-i))),[e[0],100*n,100*i]},Mu.hcg.hwb=function(e){const t=e[1]/100,i=t+e[2]/100*(1-t);return[e[0],100*(i-t),100*(1-i)]},Mu.hwb.hcg=function(e){const t=e[1]/100,i=1-e[2]/100,n=i-t;let s=0;return n<1&&(s=(i-n)/(1-n)),[e[0],100*n,100*s]},Mu.apple.rgb=function(e){return[e[0]/65535*255,e[1]/65535*255,e[2]/65535*255]},Mu.rgb.apple=function(e){return[e[0]/255*65535,e[1]/255*65535,e[2]/255*65535]},Mu.gray.rgb=function(e){return[e[0]/100*255,e[0]/100*255,e[0]/100*255]},Mu.gray.hsl=function(e){return[0,0,e[0]]},Mu.gray.hsv=Mu.gray.hsl,Mu.gray.hwb=function(e){return[0,100,e[0]]},Mu.gray.cmyk=function(e){return[0,0,0,e[0]]},Mu.gray.lab=function(e){return[e[0],0,0]},Mu.gray.hex=function(e){const t=255&Math.round(e[0]/100*255),i=((t<<16)+(t<<8)+t).toString(16).toUpperCase();return"000000".slice(i.length)+i},Mu.rgb.gray=function(e){return[(e[0]+e[1]+e[2])/3/255*100]};const Uu=function(e){const t=Hu(e),i={},n=Object.keys(t);for(let{length:e}=n,s=0;s1&&(t=i),e(t))};return"conversion"in e&&(t.conversion=e.conversion),t}function Gu(e){const t=function(...t){const i=t[0];if(null==i)return i;i.length>1&&(t=i);const n=e(t);if("object"==typeof n)for(let{length:e}=n,t=0;te>i?i:eMath.round(i*e)/i,Xu=(Math.PI,e=>("#"===e[0]&&(e=e.substring(1)),e.length<6?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:4===e.length?Yu(parseInt(e[3]+e[3],16)/255,2):1}:{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16),a:8===e.length?Yu(parseInt(e.substring(6,8),16)/255,2):1})),Zu=({h:e,s:t,v:i,a:n})=>{const s=(200-t)*i/100;return{h:Yu(e),s:Yu(s>0&&s<200?t*i/100/(s<=100?s:200-s)*100:0),l:Yu(s/2),a:Yu(n,2)}},eh=e=>{const{h:t,s:i,l:n}=Zu(e);return`hsl(${t}, ${i}%, ${n}%)`},th=({h:e,s:t,v:i,a:n})=>{e=e/360*6,t/=100,i/=100;const s=Math.floor(e),o=i*(1-t),r=i*(1-(e-s)*t),a=i*(1-(1-e+s)*t),l=s%6;return{r:Yu(255*[i,r,o,o,a,i][l]),g:Yu(255*[a,i,i,r,o,o][l]),b:Yu(255*[o,o,a,i,i,r][l]),a:Yu(n,2)}},ih=e=>{const t=e.toString(16);return t.length<2?"0"+t:t},nh=({r:e,g:t,b:i,a:n})=>{const s=n<1?ih(Yu(255*n)):"";return"#"+ih(e)+ih(t)+ih(i)+s},sh=({r:e,g:t,b:i,a:n})=>{const s=Math.max(e,t,i),o=s-Math.min(e,t,i),r=o?s===e?(t-i)/o:s===t?2+(i-e)/o:4+(e-t)/o:0;return{h:Yu(60*(r<0?r+6:r)),s:Yu(s?o/s*100:0),v:Yu(s/255*100),a:n}},oh=(e,t)=>{if(e===t)return!0;for(const i in e)if(e[i]!==t[i])return!1;return!0},rh={},ah=e=>{let t=rh[e];return t||(t=document.createElement("template"),t.innerHTML=e,rh[e]=t),t},lh=(e,t,i)=>{e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:i}))};let ch=!1;const dh=e=>"touches"in e,uh=(e,t)=>{const i=dh(t)?t.touches[0]:t,n=e.el.getBoundingClientRect();lh(e.el,"move",e.getMove({x:Qu((i.pageX-(n.left+window.pageXOffset))/n.width),y:Qu((i.pageY-(n.top+window.pageYOffset))/n.height)}))};class hh{constructor(e,t,i,n){const s=ah(``);e.appendChild(s.content.cloneNode(!0));const o=e.querySelector(`[part=${t}]`);o.addEventListener("mousedown",this),o.addEventListener("touchstart",this),o.addEventListener("keydown",this),this.el=o,this.xy=n,this.nodes=[o.firstChild,o]}set dragging(e){const t=e?document.addEventListener:document.removeEventListener;t(ch?"touchmove":"mousemove",this),t(ch?"touchend":"mouseup",this)}handleEvent(e){switch(e.type){case"mousedown":case"touchstart":if(e.preventDefault(),!(e=>!(ch&&!dh(e)||(ch||(ch=dh(e)),0)))(e)||!ch&&0!=e.button)return;this.el.focus(),uh(this,e),this.dragging=!0;break;case"mousemove":case"touchmove":e.preventDefault(),uh(this,e);break;case"mouseup":case"touchend":this.dragging=!1;break;case"keydown":((e,t)=>{const i=t.keyCode;i>40||e.xy&&i<37||i<33||(t.preventDefault(),lh(e.el,"move",e.getMove({x:39===i?.01:37===i?-.01:34===i?.05:33===i?-.05:35===i?1:36===i?-1:0,y:40===i?.01:38===i?-.01:0},!0)))})(this,e)}}style(e){e.forEach((e,t)=>{for(const i in e)this.nodes[t].style.setProperty(i,e[i])})}}class mh extends hh{constructor(e){super(e,"hue",'aria-label="Hue" aria-valuemin="0" aria-valuemax="360"',!1)}update({h:e}){this.h=e,this.style([{left:e/360*100+"%",color:eh({h:e,s:100,v:100,a:1})}]),this.el.setAttribute("aria-valuenow",`${Yu(e)}`)}getMove(e,t){return{h:t?Qu(this.h+360*e.x,0,360):360*e.x}}}class gh extends hh{constructor(e){super(e,"saturation",'aria-label="Color"',!0)}update(e){this.hsva=e,this.style([{top:100-e.v+"%",left:`${e.s}%`,color:eh(e)},{"background-color":eh({h:e.h,s:100,v:100,a:1})}]),this.el.setAttribute("aria-valuetext",`Saturation ${Yu(e.s)}%, Brightness ${Yu(e.v)}%`)}getMove(e,t){return{s:t?Qu(this.hsva.s+100*e.x,0,100):100*e.x,v:t?Qu(this.hsva.v-100*e.y,0,100):Math.round(100-100*e.y)}}}const fh=Symbol("same"),ph=Symbol("color"),bh=Symbol("hsva"),wh=Symbol("update"),_h=Symbol("parts"),vh=Symbol("css"),yh=Symbol("sliders");class kh extends HTMLElement{static get observedAttributes(){return["color"]}get[vh](){return[':host{display:flex;flex-direction:column;position:relative;width:200px;height:200px;user-select:none;-webkit-user-select:none;cursor:default}:host([hidden]){display:none!important}[role=slider]{position:relative;touch-action:none;user-select:none;-webkit-user-select:none;outline:0}[role=slider]:last-child{border-radius:0 0 8px 8px}[part$=pointer]{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;display:flex;place-content:center center;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}[part$=pointer]::after{content:"";width:100%;height:100%;border-radius:inherit;background-color:currentColor}[role=slider]:focus [part$=pointer]{transform:translate(-50%,-50%) scale(1.1)}',"[part=hue]{flex:0 0 24px;background:linear-gradient(to right,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red 100%)}[part=hue-pointer]{top:50%;z-index:2}","[part=saturation]{flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(to top,#000,transparent),linear-gradient(to right,#fff,rgba(255,255,255,0));box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}[part=saturation-pointer]{z-index:3}"]}get[yh](){return[gh,mh]}get color(){return this[ph]}set color(e){if(!this[fh](e)){const t=this.colorModel.toHsva(e);this[wh](t),this[ph]=e}}constructor(){super();const e=ah(``),t=this.attachShadow({mode:"open"});t.appendChild(e.content.cloneNode(!0)),t.addEventListener("move",this),this[_h]=this[yh].map(e=>new e(t))}connectedCallback(){if(this.hasOwnProperty("color")){const e=this.color;delete this.color,this.color=e}else this.color||(this.color=this.colorModel.defaultColor)}attributeChangedCallback(e,t,i){const n=this.colorModel.fromAttr(i);this[fh](n)||(this.color=n)}handleEvent(e){const t=this[bh],i={...t,...e.detail};let n;this[wh](i),oh(i,t)||this[fh](n=this.colorModel.fromHsva(i))||(this[ph]=n,lh(this,"color-changed",{value:n}))}[fh](e){return this.color&&this.colorModel.equal(e,this.color)}[wh](e){this[bh]=e,this[_h].forEach(t=>t.update(e))}}const Ch={defaultColor:"#000",toHsva:e=>sh(Xu(e)),fromHsva:({h:e,s:t,v:i})=>nh(th({h:e,s:t,v:i,a:1})),equal:(e,t)=>e.toLowerCase()===t.toLowerCase()||oh(Xu(e),Xu(t)),fromAttr:e=>e};class Ah extends kh{get colorModel(){return Ch}}var Th=class extends ri{_parentElement;constructor(e=[]){super(e,{idProperty:"viewUid"}),this.on("add",(e,t,i)=>{this._renderViewIntoCollectionParent(t,i)}),this.on("remove",(e,t)=>{t.element&&this._parentElement&&t.element.remove()}),this._parentElement=null}destroy(){this.map(e=>e.destroy())}setParent(e){this._parentElement=e;for(const e of this)this._renderViewIntoCollectionParent(e)}delegate(...e){if(!e.length||!e.every(e=>"string"==typeof e))throw new fe("ui-viewcollection-delegate-wrong-events",this);return{to:t=>{for(const i of this)for(const n of e)i.delegate(n).to(t);this.on("add",(i,n)=>{for(const i of e)n.delegate(i).to(t)}),this.on("remove",(i,n)=>{for(const i of e)n.stopDelegating(i,t)})}}}_renderViewIntoCollectionParent(e,t){e.isRendered||e.render(),e.element&&this._parentElement&&this._parentElement.insertBefore(e.element,this._parentElement.children[t])}remove(e){return super.remove(e)}};const Eh=Te();var xh=class extends Eh{ns;tag;text;attributes;children;eventListeners;_isRendered;_revertData;constructor(e){super(),Object.assign(this,Lh(Nh(e))),this._isRendered=!1,this._revertData=null}render(){const e=this._renderNode({intoFragment:!0});return this._isRendered=!0,e}apply(e){return this._revertData={children:[],bindings:[],attributes:{}},this._renderNode({node:e,intoFragment:!1,isApplying:!0,revertData:this._revertData}),e}revert(e){if(!this._revertData)throw new fe("ui-template-revert-not-applied",[this,e]);this._revertTemplateFromNode(e,this._revertData)}*getViews(){yield*function*e(t){if(t.children)for(const i of t.children)Uh(i)?yield i:qh(i)&&(yield*e(i))}(this)}static bind(e,t){return{to:(i,n)=>new Sh({eventNameOrFunction:i,attribute:i,observable:e,emitter:t,callback:n}),if:(i,n,s)=>new Ih({observable:e,emitter:t,attribute:i,valueIfTrue:n,callback:s})}}static extend(e,t){if(e._isRendered)throw new fe("template-extend-render",[this,e]);$h(e,Lh(Nh(t)))}_renderNode(e){let t;if(t=e.node?this.tag&&this.text:this.tag?this.text:!this.text,t)throw new fe("ui-template-wrong-syntax",this);return this.text?this._renderText(e):this._renderElement(e)}_renderElement(e){let t=e.node;return t||(t=e.node=document.createElementNS(this.ns||"http://www.w3.org/1999/xhtml",this.tag)),this._renderAttributes(e),this._renderElementChildren(e),this._setUpListeners(e),t}_renderText(e){let t=e.node;return t?e.revertData.text=t.textContent:t=e.node=document.createTextNode(""),Vh(this.text)?this._bindToObservable({schema:this.text,updater:Bh(t),data:e}):t.textContent=this.text.join(""),t}_renderAttributes(e){if(!this.attributes)return;const t=e.node,i=e.revertData;for(const n in this.attributes){const s=t.getAttribute(n),o=this.attributes[n];i&&(i.attributes[n]=s);const r=Kh(o)?o[0].ns:null;if(Vh(o)){const a=Kh(o)?o[0].value:o;i&&Jh(n)&&a.unshift(s),this._bindToObservable({schema:a,updater:Mh(t,n,r),data:e})}else if("style"==n&&"string"!=typeof o[0])this._renderStyleAttribute(o[0],e);else{i&&s&&Jh(n)&&o.unshift(s);const e=o.map(e=>e&&e.value||e).reduce((e,t)=>e.concat(t),[]).reduce(zh,"");Wh(e)||t.setAttributeNS(r,n,e)}}}_renderStyleAttribute(e,t){const i=t.node;for(const n in e){const s=e[n];Vh(s)?this._bindToObservable({schema:[s],updater:Fh(i,n),data:t}):Oh(n)?i.style.setProperty(n,s):i.style[n]=s}}_renderElementChildren(e){const t=e.node,i=e.intoFragment?document.createDocumentFragment():t,n=e.isApplying;let s=0;for(const o of this.children)if(jh(o)){if(!n){o.setParent(t);for(const e of o)i.appendChild(e.element)}}else if(Uh(o))n||(o.isRendered||o.render(),i.appendChild(o.element));else if(Ze(o))i.appendChild(o);else if(n){const t=e.revertData,n=Gh();t.children.push(n),o._renderNode({intoFragment:!1,node:i.childNodes[s++],isApplying:!0,revertData:n})}else i.appendChild(o.render());e.intoFragment&&t.appendChild(i)}_setUpListeners(e){if(this.eventListeners)for(const t in this.eventListeners){const i=this.eventListeners[t].map(i=>{const[n,s]=t.split("@");return i.activateDomEventListener(n,s,e)});e.revertData&&e.revertData.bindings.push(i)}}_bindToObservable({schema:e,updater:t,data:i}){const n=i.revertData;Rh(e,t,i);const s=e.filter(e=>!Wh(e)).filter(e=>e.observable).map(n=>n.activateAttributeListener(e,t,i));n&&n.bindings.push(s)}_revertTemplateFromNode(e,t){for(const e of t.bindings)for(const t of e)t();if(t.text)return void(e.textContent=t.text);const i=e;for(const e in t.attributes){const n=t.attributes[e];null===n?i.removeAttribute(e):i.setAttribute(e,n)}for(let e=0;eRh(e,t,i);return this.emitter.listenTo(this.observable,`change:${this.attribute}`,n),()=>{this.emitter.stopListening(this.observable,`change:${this.attribute}`,n)}}},Sh=class extends Ph{eventNameOrFunction;constructor(e){super(e),this.eventNameOrFunction=e.eventNameOrFunction}activateDomEventListener(e,t,i){const n=(e,i)=>{t&&!i.target.matches(t)||("function"==typeof this.eventNameOrFunction?this.eventNameOrFunction(i):this.observable.fire(this.eventNameOrFunction,i))};return this.emitter.listenTo(i.node,e,n),()=>{this.emitter.stopListening(i.node,e,n)}}},Ih=class extends Ph{valueIfTrue;constructor(e){super(e),this.valueIfTrue=e.valueIfTrue}getValue(e){return!Wh(super.getValue(e))&&(this.valueIfTrue||!0)}};function Vh(e){return!!e&&(e.value&&(e=e.value),Array.isArray(e)?e.some(Vh):e instanceof Ph)}function Oh(e){return/^--[a-zA-Z_-][\w-]*$/.test(e)}function Rh(e,t,{node:i}){const n=function(e,t){return e.map(e=>e instanceof Ph?e.getValue(t):e)}(e,i);let s;s=1==e.length&&e[0]instanceof Ih?n[0]:n.reduce(zh,""),Wh(s)?t.remove():t.set(s)}function Bh(e){return{set(t){e.textContent=t},remove(){e.textContent=""}}}function Mh(e,t,i){return{set(n){e.setAttributeNS(i,t,n)},remove(){e.removeAttributeNS(i,t)}}}function Fh(e,t){return{set(i){Oh(t)?e.style.setProperty(t,i):e.style[t]=i},remove(){Oh(t)?e.style.removeProperty(t):e.style[t]=null}}}function Nh(e){return B(e,e=>{if(e&&(e instanceof Ph||qh(e)||Uh(e)||jh(e)))return e})}function Lh(e){if("string"==typeof e?e=function(e){return{text:[e]}}(e):e.text&&function(e){e.text=ii(e.text)}(e),e.on&&(e.eventListeners=function(e){for(const t in e)Dh(e,t);return e}(e.on),delete e.on),!e.text){e.attributes&&function(e){for(const t in e)e[t].value&&(e[t].value=ii(e[t].value)),Dh(e,t)}(e.attributes);const t=[];if(e.children)if(jh(e.children))t.push(e.children);else for(const i of e.children)qh(i)||Uh(i)||Ze(i)?t.push(i):t.push(new xh(i));e.children=t}return e}function Dh(e,t){e[t]=ii(e[t])}function zh(e,t){return Wh(t)?e:Wh(e)?t:`${e} ${t}`}function Hh(e,t){for(const i in t)e[i]?e[i].push(...t[i]):e[i]=t[i]}function $h(e,t){if(t.attributes&&(e.attributes||(e.attributes={}),Hh(e.attributes,t.attributes)),t.eventListeners&&(e.eventListeners||(e.eventListeners={}),Hh(e.eventListeners,t.eventListeners)),t.text&&e.text.push(...t.text),t.children&&t.children.length){if(e.children.length!=t.children.length)throw new fe("ui-template-extend-children-mismatch",e);let i=0;for(const n of t.children)$h(e.children[i++],n)}}function Wh(e){return!e&&0!==e}function Uh(e){return e instanceof Yh}function qh(e){return e instanceof xh}function jh(e){return e instanceof Th}function Kh(e){return n(e[0])&&e[0].ns}function Gh(){return{children:[],bindings:[],attributes:{}}}function Jh(e){return"class"==e||"style"==e}const Qh=nt(De());var Yh=class extends Qh{element;isRendered;locale;t;template;_viewCollections;_unboundChildren;_bindTemplate;constructor(e){super(),this.element=null,this.isRendered=!1,this.locale=e,this.t=e&&e.t,this._viewCollections=new ri,this._unboundChildren=this.createCollection(),this._viewCollections.on("add",(t,i)=>{i.locale=e,i.t=e&&e.t}),this.decorate("render")}get bindTemplate(){return this._bindTemplate?this._bindTemplate:this._bindTemplate=xh.bind(this,this)}createCollection(e){const t=new Th(e);return this._viewCollections.add(t),t}registerChild(e){Ge(e)||(e=[e]);for(const t of e)this._unboundChildren.add(t)}deregisterChild(e){Ge(e)||(e=[e]);for(const t of e)this._unboundChildren.remove(t)}setTemplate(e){this.template=new xh(e)}extendTemplate(e){xh.extend(this.template,e)}render(){if(this.isRendered)throw new fe("ui-view-render-already-rendered",this);this.template&&(this.element=this.template.render(),this.registerChild(this.template.getViews())),this.isRendered=!0}destroy(){this.stopListening(),this._viewCollections.map(e=>e.destroy()),this.template&&this.template._revertData&&this.template.revert(this.element)}};const Xh={POLITE:"polite",ASSERTIVE:"assertive"};var Zh=class{editor;view;constructor(e){this.editor=e,e.once("ready",()=>{for(const e of Object.values(Xh))this.announce("",e)})}announce(e,t=Xh.POLITE){const i=this.editor;if(!i.ui.view)return;this.view||(this.view=new em(i.locale),i.ui.view.body.add(this.view));const{politeness:n,isUnsafeHTML:s}="string"==typeof t?{politeness:t}:t;let o=this.view.regionViews.find(e=>e.politeness===n);o||(o=new tm(i,n),this.view.regionViews.add(o)),o.announce({announcement:e,isUnsafeHTML:s})}},em=class extends Yh{regionViews;constructor(e){super(e),this.regionViews=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-aria-live-announcer"]},children:this.regionViews})}},tm=class extends Yh{politeness;_domConverter;_pruneAnnouncementsInterval;constructor(e,t){super(e.locale),this.setTemplate({tag:"div",attributes:{"aria-live":t,"aria-relevant":"additions"},children:[{tag:"ul",attributes:{class:["ck","ck-aria-live-region-list"]}}]}),e.on("destroy",()=>{null!==this._pruneAnnouncementsInterval&&(clearInterval(this._pruneAnnouncementsInterval),this._pruneAnnouncementsInterval=null)}),this.politeness=t,this._domConverter=e.data.htmlProcessor.domConverter,this._pruneAnnouncementsInterval=setInterval(()=>{this.element&&this._listElement.firstChild&&this._listElement.firstChild.remove()},5e3)}announce({announcement:e,isUnsafeHTML:t}){if(!e.trim().length)return;const i=document.createElement("li");t?this._domConverter.setContentOf(i,e):i.innerText=e,this._listElement.appendChild(i)}get _listElement(){return this.element.querySelector("ul")}};function im({emitter:e,activator:t,callback:i,contextElements:n,listenerOptions:s}){e.listenTo(document,"mousedown",(e,s)=>{if(!t())return;const o="function"==typeof s.composedPath?s.composedPath():[],r="function"==typeof n?n():n;for(const e of r)if(e.contains(s.target)||o.includes(e))return;i()},s)}function nm(e){return class extends e{disableCssTransitions(){this._isCssTransitionsDisabled=!0}enableCssTransitions(){this._isCssTransitionsDisabled=!1}constructor(...e){super(...e),this.set("_isCssTransitionsDisabled",!1),this.initializeCssTransitionDisablerMixin()}initializeCssTransitionDisablerMixin(){this.template&&this.extendTemplate({attributes:{class:[this.bindTemplate.if("_isCssTransitionsDisabled","ck-transitions-disabled")]}})}}}function sm(e){return class extends e{_onDragBound=this._onDrag.bind(this);_onDragEndBound=this._onDragEnd.bind(this);_lastDraggingCoordinates={x:0,y:0};constructor(...e){super(...e),this.on("render",()=>{this._attachListeners()}),this.set("isDragging",!1)}_attachListeners(){this.listenTo(this.element,"mousedown",this._onDragStart.bind(this)),this.listenTo(this.element,"touchstart",this._onDragStart.bind(this))}_attachDragListeners(){this.listenTo(G.document,"mouseup",this._onDragEndBound),this.listenTo(G.document,"touchend",this._onDragEndBound),this.listenTo(G.document,"mousemove",this._onDragBound),this.listenTo(G.document,"touchmove",this._onDragBound)}_detachDragListeners(){this.stopListening(G.document,"mouseup",this._onDragEndBound),this.stopListening(G.document,"touchend",this._onDragEndBound),this.stopListening(G.document,"mousemove",this._onDragBound),this.stopListening(G.document,"touchmove",this._onDragBound)}_onDragStart(e,t){if(!this._isHandleElementPressed(t))return;let i,n;this._attachDragListeners(),t instanceof MouseEvent?(i=t.clientX,n=t.clientY):(i=t.touches[0].clientX,n=t.touches[0].clientY),this._lastDraggingCoordinates={x:i,y:n},this.isDragging=!0}_onDrag(e,t){if(!this.isDragging)return void this._detachDragListeners();let i,n;t instanceof MouseEvent?(i=t.clientX,n=t.clientY):(i=t.touches[0].clientX,n=t.touches[0].clientY),t.preventDefault(),this.fire("drag",{deltaX:Math.round(i-this._lastDraggingCoordinates.x),deltaY:Math.round(n-this._lastDraggingCoordinates.y)}),this._lastDraggingCoordinates={x:i,y:n}}_onDragEnd(){this._detachDragListeners(),this.isDragging=!1}_isHandleElementPressed(e){return!!this.dragHandleElement&&(this.dragHandleElement===e.target||e.target instanceof HTMLElement&&this.dragHandleElement.contains(e.target))}}}function om({view:e}){e.listenTo(e.element,"submit",(t,i)=>{i.preventDefault(),e.fire("submit")},{useCapture:!0})}function rm({keystrokeHandler:e,focusTracker:t,gridItems:i,numberOfColumns:n,uiLanguageDirection:s}){const o="number"==typeof n?()=>n:n;function r(e){return n=>{const s=i.find(e=>e.element===t.focusedElement),o=e(i.getIndex(s),i);i.get(o).focus(),n.stopPropagation(),n.preventDefault()}}function a(e,t){return e===t-1?0:e+1}function l(e,t){return 0===e?t-1:e-1}e.set("arrowright",r((e,t)=>"rtl"===s?l(e,t.length):a(e,t.length))),e.set("arrowleft",r((e,t)=>"rtl"===s?a(e,t.length):l(e,t.length))),e.set("arrowup",r((e,t)=>{let i=e-o();return i<0&&(i=e+o()*Math.floor(t.length/o()),i>t.length-1&&(i-=o())),i})),e.set("arrowdown",r((e,t)=>{let i=e+o();return i>t.length-1&&(i=e%o()),i}))}var am=class extends Yh{id;constructor(e){super(e),this.set("text",void 0),this.set("for",void 0),this.id=`ck-editor__label_${he()}`;const t=this.bindTemplate;this.setTemplate({tag:"label",attributes:{class:["ck","ck-label"],id:this.id,for:t.to("for")},children:[{text:t.to("text")}]})}},lm=class extends Yh{constructor(e,t){super(e);const i=e.t,n=new am;n.text=i("Help Contents. To close this dialog press ESC."),this.setTemplate({tag:"div",attributes:{class:["ck","ck-accessibility-help-dialog__content"],"aria-labelledby":n.id,role:"document",tabindex:-1},children:[Je(document,"p",{},i("Below, you can find a list of keyboard shortcuts that can be used in the editor.")),...this._createCategories(Array.from(t.values())),n]})}focus(){this.element.focus()}_createCategories(e){return e.map(e=>{const t=[Je(document,"h3",{},e.label),...Array.from(e.groups.values()).map(e=>this._createGroup(e)).flat()];return e.description&&t.splice(1,0,Je(document,"p",{},e.description)),Je(document,"section",{},t)})}_createGroup(e){const t=e.keystrokes.sort((e,t)=>e.label.localeCompare(t.label)).map(e=>this._createGroupRow(e)).flat(),i=[Je(document,"dl",{},t)];return e.label&&i.unshift(Je(document,"h4",{},e.label)),i}_createGroupRow(e){const t=this.locale.t,i=Je(document,"dt"),n=Je(document,"dd"),s="string"==typeof(o=e.keystroke)?[[o]]:"string"==typeof o[0]?[o]:o;var o;const r=[];for(const e of s)r.push(e.map(cm).join(""));return i.innerHTML=e.label,n.innerHTML=r.join(", ")+(e.mayRequireFn&&Y.isMac?` ${t("(may require Fn )")}`:""),[i,n]}};function cm(e){return Yt(e).split("+").map(e=>`${e} `).join("+")}var dm=class e extends Yh{static presentationalAttributeNames=["alignment-baseline","baseline-shift","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-rendering","cursor","direction","display","dominant-baseline","fill","fill-opacity","fill-rule","filter","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","image-rendering","letter-spacing","lighting-color","marker-end","marker-mid","marker-start","mask","opacity","overflow","paint-order","pointer-events","shape-rendering","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","text-anchor","text-decoration","text-overflow","text-rendering","transform","unicode-bidi","vector-effect","visibility","white-space","word-spacing","writing-mode"];constructor(){super();const e=this.bindTemplate;this.set("content",""),this.set("viewBox","0 0 20 20"),this.set("fillColor",""),this.set("isColorInherited",!0),this.set("isVisible",!0),this.setTemplate({tag:"svg",ns:"http://www.w3.org/2000/svg",attributes:{class:["ck","ck-icon",e.if("isVisible","ck-hidden",e=>!e),"ck-reset_all-excluded",e.if("isColorInherited","ck-icon_inherit-color")],viewBox:e.to("viewBox"),"aria-hidden":!0}})}render(){super.render(),this._updateXMLContent(),this._colorFillPaths(),this.on("change:content",()=>{this._updateXMLContent(),this._colorFillPaths()}),this.on("change:fillColor",()=>{this._colorFillPaths()})}_updateXMLContent(){if(this.content){const t=(new DOMParser).parseFromString(this.content.trim(),"image/svg+xml").querySelector("svg");if(!t)throw new fe("ui-iconview-invalid-svg",this);const i=t.getAttribute("viewBox");i&&(this.viewBox=i);for(const{name:i,value:n}of Array.from(t.attributes))e.presentationalAttributeNames.includes(i)&&this.element.setAttribute(i,n);for(;this.element.firstChild;)this.element.removeChild(this.element.firstChild);for(;t.childNodes.length>0;)this.element.appendChild(t.childNodes[0])}}_colorFillPaths(){this.fillColor&&this.element.querySelectorAll(".ck-icon__fill").forEach(e=>{e.style.fill=this.fillColor})}},um=class extends Yh{constructor(){super(),this.set({style:void 0,text:void 0,id:void 0});const e=this.bindTemplate;this.setTemplate({tag:"span",attributes:{class:["ck","ck-button__label"],style:e.to("style"),id:e.to("id")},children:[{text:e.to("text")}]})}},hm=class extends Yh{children;labelView;iconView;keystrokeView;_focusDelayed=null;constructor(e,t=new um){super(e);const i=this.bindTemplate,n=he();this.set("_ariaPressed",!1),this.set("_ariaChecked",!1),this.set("ariaLabel",void 0),this.set("ariaLabelledBy",`ck-editor__aria-label_${n}`),this.set("class",void 0),this.set("labelStyle",void 0),this.set("icon",void 0),this.set("isEnabled",!0),this.set("isOn",!1),this.set("isVisible",!0),this.set("isToggleable",!1),this.set("keystroke",void 0),this.set("label",void 0),this.set("role",void 0),this.set("tabindex",-1),this.set("tooltip",!1),this.set("tooltipPosition","s"),this.set("type","button"),this.set("withText",!1),this.set("withKeystroke",!1),this.children=this.createCollection(),this.labelView=this._setupLabelView(t),this.iconView=new dm,this.iconView.extendTemplate({attributes:{class:"ck-button__icon"}}),this.iconView.bind("content").to(this,"icon"),this.keystrokeView=this._createKeystrokeView(),this.bind("_tooltipString").to(this,"tooltip",this,"label",this,"keystroke",this._getTooltipString.bind(this));const s={tag:"button",attributes:{class:["ck","ck-button",i.to("class"),i.if("isEnabled","ck-disabled",e=>!e),i.if("isVisible","ck-hidden",e=>!e),i.to("isOn",e=>e?"ck-on":"ck-off"),i.if("withText","ck-button_with-text"),i.if("withKeystroke","ck-button_with-keystroke")],role:i.to("role"),type:i.to("type",e=>e||"button"),tabindex:i.to("tabindex"),"aria-checked":i.to("_ariaChecked"),"aria-pressed":i.to("_ariaPressed"),"aria-label":i.to("ariaLabel"),"aria-labelledby":i.to("ariaLabelledBy"),"aria-disabled":i.if("isEnabled",!0,e=>!e),"data-cke-tooltip-text":i.to("_tooltipString"),"data-cke-tooltip-position":i.to("tooltipPosition")},children:this.children,on:{click:i.to(e=>{this.isEnabled?this.fire("execute"):e.preventDefault()})}};this.bind("_ariaPressed").to(this,"isOn",this,"isToggleable",this,"role",(e,t,i)=>!(!t||mm(i))&&String(!!e)),this.bind("_ariaChecked").to(this,"isOn",this,"isToggleable",this,"role",(e,t,i)=>!(!t||!mm(i))&&String(!!e)),Y.isSafari&&(this._focusDelayed||(this._focusDelayed=pi(()=>this.focus(),0)),s.on.mousedown=i.to(()=>{this._focusDelayed()}),s.on.mouseup=i.to(()=>{this._focusDelayed.cancel()})),this.setTemplate(s)}render(){super.render(),this.icon&&this.children.add(this.iconView),this.on("change:icon",(e,t,i,n)=>{i&&!n?this.children.add(this.iconView,0):!i&&n&&this.children.remove(this.iconView)}),this.children.add(this.labelView),this.withKeystroke&&this.keystroke&&this.children.add(this.keystrokeView)}focus(){this.element.focus()}destroy(){this._focusDelayed&&this._focusDelayed.cancel(),super.destroy()}_setupLabelView(e){return e.bind("text","style","id").to(this,"label","labelStyle","ariaLabelledBy"),e}_createKeystrokeView(){const e=new Yh;return e.setTemplate({tag:"span",attributes:{class:["ck","ck-button__keystroke"]},children:[{text:this.bindTemplate.to("keystroke",e=>Yt(e))}]}),e}_getTooltipString(e,t,i){return e?"string"==typeof e?e:(i&&(i=Yt(i)),e instanceof Function?e(t,i):`${t}${i?` (${i})`:""}`):""}};function mm(e){switch(e){case"radio":case"checkbox":case"option":case"switch":case"menuitemcheckbox":case"menuitemradio":return!0;default:return!1}}var gm=class extends Yh{children;iconView;constructor(e,t={}){super(e);const i=this.bindTemplate;this.set("label",t.label||""),this.set("class",t.class||null),this.children=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-form__header",i.to("class")]},children:this.children}),t.icon&&(this.iconView=new dm,this.iconView.content=t.icon,this.children.add(this.iconView));const n=new Yh(e);n.setTemplate({tag:"h2",attributes:{class:["ck","ck-form__header__label"],role:"presentation"},children:[{text:i.to("label")}]}),this.children.add(n)}};const fm=Te();var pm=class extends fm{focusables;focusTracker;keystrokeHandler;actions;constructor(e){if(super(),this.focusables=e.focusables,this.focusTracker=e.focusTracker,this.keystrokeHandler=e.keystrokeHandler,this.actions=e.actions,e.actions&&e.keystrokeHandler)for(const t in e.actions){let i=e.actions[t];"string"==typeof i&&(i=[i]);for(const n of i)e.keystrokeHandler.set(n,(e,i)=>{this[t](),i()},e.keystrokeHandlerOptions)}this.on("forwardCycle",()=>this.focusFirst(),{priority:"low"}),this.on("backwardCycle",()=>this.focusLast(),{priority:"low"})}get first(){return this.focusables.find(bm)||null}get last(){return this.focusables.filter(bm).slice(-1)[0]||null}get next(){return this._getDomFocusableItem(1)}get previous(){return this._getDomFocusableItem(-1)}get current(){let e=null;return null===this.focusTracker.focusedElement?null:(this.focusables.find((t,i)=>{const n=t.element===this.focusTracker.focusedElement;return n&&(e=i),n}),e)}focusFirst(){this._focus(this.first,1)}focusLast(){this._focus(this.last,-1)}focusNext(){const e=this.next;e&&this.focusables.getIndex(e)===this.current||e===this.first?this.fire("forwardCycle"):this._focus(e,1)}focusPrevious(){const e=this.previous;e&&this.focusables.getIndex(e)===this.current||e===this.last?this.fire("backwardCycle"):this._focus(e,-1)}chain(e){const t=()=>null===this.current?null:this.focusables.get(this.current);this.listenTo(e,"forwardCycle",e=>{const i=t();this.focusNext(),i!==t()&&e.stop()},{priority:"low"}),this.listenTo(e,"backwardCycle",e=>{const i=t();this.focusPrevious(),i!==t()&&e.stop()},{priority:"low"})}unchain(e){this.stopListening(e)}_focus(e,t){e&&this.focusTracker.focusedElement!==e.element&&e.focus(t)}_getDomFocusableItem(e){const t=this.focusables.length;if(!t)return null;const i=this.current;if(null===i)return this[1===e?"first":"last"];let n=this.focusables.get(i),s=(i+t+e)%t;do{const i=this.focusables.get(s);if(bm(i)){n=i;break}s=(s+t+e)%t}while(s!==i);return n}};function bm(e){return wm(e)&&Pt(e.element)}function wm(e){return!(!("focus"in e)||"function"!=typeof e.focus)}var _m=class extends Yh{children;keystrokes;focusCycler;_focusTracker;_focusables;constructor(e){super(e),this.children=this.createCollection(),this.keystrokes=new mi,this._focusTracker=new ci,this._focusables=new Th,this.focusCycler=new pm({focusables:this._focusables,focusTracker:this._focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-dialog__actions"]},children:this.children})}render(){super.render(),this.keystrokes.listenTo(this.element)}setButtons(e){for(const t of e){const e=new hm(this.locale);let i;for(i in e.on("execute",()=>t.onExecute()),t.onCreate&&t.onCreate(e),t)"onExecute"!=i&&"onCreate"!=i&&e.set(i,t[i]);this.children.add(e)}this._updateFocusCyclableItems()}focus(e){-1===e?this.focusCycler.focusLast():this.focusCycler.focusFirst()}_updateFocusCyclableItems(){Array.from(this.children).forEach(e=>{this._focusables.add(e),this._focusTracker.add(e.element)})}},vm=class extends Yh{children;constructor(e){super(e),this.children=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-dialog__content"]},children:this.children})}reset(){for(;this.children.length;)this.children.remove(0)}};const ym="screen-center",km="editor-center",Cm="editor-top-side",Am="editor-top-center",Tm="editor-bottom-center",Em="editor-above-center",xm="editor-below-center",Pm=Ct("px"),Sm=sm(Yh);var Im=class e extends Sm{parts;headerView;closeButtonView;actionsView;static defaultOffset=15;contentView;keystrokes;focusTracker;wasMoved=!1;_getDomRootElement;_getViewportOffset;_focusables;_focusCycler;constructor(e,{getDomRootElement:t,getViewportOffset:i,keystrokeHandlerOptions:n}){super(e);const s=this.bindTemplate,o=e.t;this.set("className",""),this.set("ariaLabel",o("Editor dialog")),this.set("isModal",!1),this.set("position",ym),this.set("_isVisible",!1),this.set("_isTransparent",!1),this.set("_top",0),this.set("_left",0),this._getDomRootElement=t,this._getViewportOffset=i,this.decorate("moveTo"),this.parts=this.createCollection(),this.keystrokes=new mi,this.focusTracker=new ci,this._focusables=new Th,this._focusCycler=new pm({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"},keystrokeHandlerOptions:n}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-dialog-overlay",s.if("isModal","ck-dialog-overlay__transparent",e=>!e),s.if("_isVisible","ck-hidden",e=>!e)],tabindex:"-1"},children:[{tag:"div",attributes:{tabindex:"-1",class:["ck","ck-dialog",s.if("isModal","ck-dialog_modal"),s.to("className")],role:"dialog","aria-label":s.to("ariaLabel"),style:{top:s.to("_top",e=>Pm(e)),left:s.to("_left",e=>Pm(e)),visibility:s.if("_isTransparent","hidden")}},children:this.parts}]})}render(){super.render(),this.keystrokes.set("Esc",(e,t)=>{e.defaultPrevented||(this.fire("close",{source:"escKeyPress"}),t())}),this.on("drag",(e,{deltaX:t,deltaY:i})=>{this.wasMoved=!0,this.moveBy(t,i)}),this.listenTo(G.window,"resize",()=>{this._isVisible&&!this.wasMoved&&this.updatePosition()}),this.listenTo(G.document,"scroll",()=>{this._isVisible&&!this.wasMoved&&this.updatePosition()}),this.on("change:_isVisible",(e,t,i)=>{i&&(this._isTransparent=!0,setTimeout(()=>{this.updatePosition(),this._isTransparent=!1,this.focus()},10))}),this.keystrokes.listenTo(this.element)}get dragHandleElement(){return this.headerView&&!this.isModal?this.headerView.element:null}setupParts({icon:e,title:t,hasCloseButton:i=!0,content:n,actionButtons:s}){t&&(this.headerView=new gm(this.locale,{icon:e}),i&&(this.closeButtonView=this._createCloseButton(),this.headerView.children.add(this.closeButtonView)),this.headerView.label=t,this.ariaLabel=t,this.parts.add(this.headerView,0)),n&&(n instanceof Yh&&(n=[n]),this.contentView=new vm(this.locale),this.contentView.children.addMany(n),this.parts.add(this.contentView)),s&&(this.actionsView=new _m(this.locale),this.actionsView.setButtons(s),this.parts.add(this.actionsView)),this._updateFocusCyclableItems()}focus(){this._focusCycler.focusFirst()}moveTo(e,t){const i=this._getViewportRect(),n=this._getDialogRect();e+n.width>i.right&&(e=i.right-n.width),e{var t;this._focusables.add(e),this.focusTracker.add(e.element),wm(t=e)&&"focusCycler"in t&&t.focusCycler instanceof pm&&this._focusCycler.chain(e.focusCycler)})}_createCloseButton(){const e=new hm(this.locale),t=this.locale.t;return e.set({label:t("Close"),tooltip:!0,icon:Yd}),e.on("execute",()=>this.fire("close",{source:"closeButton"})),e}},Vm=class e extends od{view;static _visibleDialogPlugin;_onHide;static get pluginName(){return"Dialog"}static get isOfficialPlugin(){return!0}constructor(e){super(e);const t=e.t;this._initShowHideListeners(),this._initFocusToggler(),this._initMultiRootIntegration(),this.set({id:null,isOpen:!1}),e.accessibility.addKeystrokeInfos({categoryId:"navigation",keystrokes:[{label:t("Move focus in and out of an active dialog window"),keystroke:"Ctrl+F6",mayRequireFn:!0}]})}destroy(){super.destroy(),e._visibleDialogPlugin===this&&this._unlockBodyScroll()}_initShowHideListeners(){this.on("show",(e,t)=>{this._show(t)}),this.on("show",(e,t)=>{t.onShow&&t.onShow(this)},{priority:"low"}),this.on("hide",()=>{e._visibleDialogPlugin&&e._visibleDialogPlugin._hide()}),this.on("hide",()=>{this._onHide&&(this._onHide(this),this._onHide=void 0)},{priority:"low"})}_initFocusToggler(){const e=this.editor;e.keystrokes.set("Ctrl+F6",(t,i)=>{this.isOpen&&!this.view.isModal&&(this.view.focusTracker.isFocused?e.editing.view.focus():this.view.focus(),i())})}_initMultiRootIntegration(){const e=this.editor.model;e.document.on("change:data",()=>{if(!this.view)return;const t=e.document.differ.getChangedRoots();for(const e of t)e.state&&this.view.updatePosition()})}show(e){this.hide(),this.fire(`show:${e.id}`,e)}_show({id:t,icon:i,title:n,hasCloseButton:s=!0,content:o,actionButtons:r,className:a,isModal:l,position:c,onHide:d,getRootName:u,keystrokeHandlerOptions:h}){const m=this.editor;this.view=new Im(m.locale,{getDomRootElement:()=>{const e=u?.()??this.editor.model.document.selection.anchor.root.rootName;return e&&m.editing.view.domRoots.has(e)?m.editing.view.getDomRoot(e)??null:null},getViewportOffset:()=>m.ui.viewportOffset,keystrokeHandlerOptions:h});const g=this.view;g.on("close",()=>{this.hide()}),m.ui.view.body.add(g),m.keystrokes.listenTo(g.element),c||(c=l?ym:km),l&&this._lockBodyScroll(),g.set({position:c,_isVisible:!0,className:a,isModal:l}),g.setupParts({icon:i,title:n,hasCloseButton:s,content:o,actionButtons:r}),this.id=t,d&&(this._onHide=d),this.isOpen=!0,e._visibleDialogPlugin=this}hide(){e._visibleDialogPlugin&&e._visibleDialogPlugin.fire(`hide:${e._visibleDialogPlugin.id}`)}_hide(){if(!this.view)return;const t=this.editor,i=this.view;i.isModal&&this._unlockBodyScroll(),i.contentView&&i.contentView.reset(),t.ui.view.body.remove(i),t.ui.focusTracker.remove(i.element),t.keystrokes.stopListening(i.element),i.destroy(),t.editing.view.focus(),this.id=null,this.isOpen=!1,e._visibleDialogPlugin=null}_lockBodyScroll(){document.documentElement.classList.add("ck-dialog-scroll-locked")}_unlockBodyScroll(){document.documentElement.classList.remove("ck-dialog-scroll-locked")}},Om=class extends hm{_checkIconHolderView=new Rm;constructor(e,t=new um){super(e,t),this.set({hasCheckSpace:!1,_hasCheck:this.isToggleable});const i=this.bindTemplate;this.extendTemplate({attributes:{class:["ck-list-item-button",i.if("isToggleable","ck-list-item-button_toggleable")]}}),this.bind("_hasCheck").to(this,"hasCheckSpace",this,"isToggleable",(e,t)=>e||t)}render(){super.render(),this._hasCheck&&this.children.add(this._checkIconHolderView,0),this._watchCheckIconHolderMount()}_watchCheckIconHolderMount(){this._checkIconHolderView.bind("isOn").to(this,"isOn",e=>this.isToggleable&&e),this.on("change:_hasCheck",(e,t,i)=>{const{children:n,_checkIconHolderView:s}=this;i?n.add(s,0):n.remove(s)})}},Rm=class extends Yh{children;_checkIconView=this._createCheckIconView();constructor(){super();const e=this.bindTemplate;this.children=this.createCollection(),this.set("isOn",!1),this.setTemplate({tag:"span",children:this.children,attributes:{class:["ck","ck-list-item-button__check-holder",e.to("isOn",e=>e?"ck-on":"ck-off")]}})}render(){super.render(),this.isOn&&this.children.add(this._checkIconView,0),this._watchCheckIconMount()}_watchCheckIconMount(){this.on("change:isOn",(e,t,i)=>{const{children:n,_checkIconView:s}=this;i&&!n.has(s)?n.add(s):!i&&n.has(s)&&n.remove(s)})}_createCheckIconView(){const e=new dm;return e.content=Zd,e.extendTemplate({attributes:{class:"ck-list-item-button__check-icon"}}),e}},Bm=class extends Om{constructor(e){super(e),this.set({withText:!0,withKeystroke:!0,tooltip:!1,role:"menuitem"}),this.extendTemplate({attributes:{class:["ck-menu-bar__menu__item__button"]}})}},Mm=class extends od{contentView=null;static get requires(){return[Vm]}static get pluginName(){return"AccessibilityHelp"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.locale.t;e.ui.componentFactory.add("accessibilityHelp",()=>{const e=this._createButton(hm);return e.set({tooltip:!0,withText:!1,label:t("Accessibility help")}),e}),e.ui.componentFactory.add("menuBar:accessibilityHelp",()=>{const e=this._createButton(Bm);return e.label=t("Accessibility"),e}),e.keystrokes.set("Alt+0",(e,t)=>{this._toggleDialog(),t()}),this._setupRootLabels()}_createButton(e){const t=this.editor,i=t.plugins.get("Dialog"),n=new e(t.locale);return n.set({keystroke:"Alt+0",icon:Ud,isToggleable:!0}),n.on("execute",()=>this._toggleDialog()),n.bind("isOn").to(i,"id",e=>"accessibilityHelp"===e),n}_setupRootLabels(){const e=this.editor,t=e.editing.view,i=e.t;function n(e,t){const n=[t.getAttribute("aria-label"),i("Press %0 for help.",[Yt("Alt+0")])].filter(e=>e).join(". ");e.setAttribute("aria-label",n,t)}e.ui.on("ready",()=>{t.change(e=>{for(const i of t.document.roots)n(e,i)}),e.on("addRoot",(i,s)=>{const o=e.editing.view.document.getRoot(s.rootName);t.change(e=>n(e,o))},{priority:"low"})})}_toggleDialog(){const e=this.editor,t=e.plugins.get("Dialog"),i=e.locale.t;this.contentView||(this.contentView=new lm(e.locale,e.accessibility.keystrokeInfos)),"accessibilityHelp"===t.id?t.hide():t.show({id:"accessibilityHelp",className:"ck-accessibility-help-dialog",title:i("Accessibility help"),icon:Ud,hasCloseButton:!0,content:this.contentView})}},Fm=class e extends Th{locale;_bodyCollectionContainer;static _bodyWrapper;constructor(e,t=[]){super(t),this.locale=e}get bodyCollectionContainer(){return this._bodyCollectionContainer}attachToDom(){this._bodyCollectionContainer=new xh({tag:"div",attributes:{class:["ck","ck-reset_all","ck-body","ck-rounded-corners"],dir:this.locale.uiLanguageDirection,role:"application"},children:this}).render(),e._bodyWrapper&&e._bodyWrapper.isConnected||(e._bodyWrapper=Je(document,"div",{class:"ck-body-wrapper"}),document.body.appendChild(e._bodyWrapper)),e._bodyWrapper.appendChild(this._bodyCollectionContainer)}detachFromDom(){super.destroy(),this._bodyCollectionContainer&&this._bodyCollectionContainer.remove(),e._bodyWrapper&&!e._bodyWrapper.childElementCount&&(e._bodyWrapper.remove(),delete e._bodyWrapper)}};const Nm=Ct("px"),Lm={top:-99999,left:-99999,name:"arrowless",config:{withArrow:!1}};var Dm=class e extends Yh{content;_pinWhenIsVisibleCallback;_resizeObserver;constructor(e){super(e);const t=this.bindTemplate;this.set("top",0),this.set("left",0),this.set("position","arrow_nw"),this.set("isVisible",!1),this.set("withArrow",!0),this.set("class",void 0),this._pinWhenIsVisibleCallback=null,this._resizeObserver=null,this.content=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-balloon-panel",t.to("position",e=>`ck-balloon-panel_${e}`),t.if("isVisible","ck-balloon-panel_visible"),t.if("withArrow","ck-balloon-panel_with-arrow"),t.to("class")],style:{top:t.to("top",Nm),left:t.to("left",Nm)}},children:this.content})}destroy(){this.hide(),super.destroy()}show(){this.isVisible=!0}hide(){this.isVisible=!1}attachTo(t){const i=zm(t.target);if(i&&!Pt(i))return!1;this.show();const n=e.defaultPositions,s=Object.assign({},{element:this.element,positions:[n.southArrowNorth,n.southArrowNorthMiddleWest,n.southArrowNorthMiddleEast,n.southArrowNorthWest,n.southArrowNorthEast,n.northArrowSouth,n.northArrowSouthMiddleWest,n.northArrowSouthMiddleEast,n.northArrowSouthWest,n.northArrowSouthEast,n.viewportStickyNorth],limiter:G.document.body,fitInViewport:!0},t),o=e._getOptimalPosition(s)||Lm,r=parseInt(o.left),a=parseInt(o.top),l=o.name,{withArrow:c=!0}=o.config||{};return this.top=a,this.left=r,this.position=l,this.withArrow=c,!0}pin(e){this.unpin(),this._startPinning(e)&&(this._pinWhenIsVisibleCallback=()=>{this.isVisible?this._startPinning(e):this._stopPinning()},this.listenTo(this,"change:isVisible",this._pinWhenIsVisibleCallback))}unpin(){this._pinWhenIsVisibleCallback&&(this._stopPinning(),this.stopListening(this,"change:isVisible",this._pinWhenIsVisibleCallback),this._pinWhenIsVisibleCallback=null,this.hide())}_startPinning(e){if(!this.attachTo(e))return!1;let t=zm(e.target);const i=e.limiter?zm(e.limiter):G.document.body;if(this.listenTo(G.document,"scroll",(n,s)=>{const o=s.target,r=t&&o.contains(t),a=i&&o.contains(i);!r&&!a&&t&&i||this.attachTo(e)},{useCapture:!0}),this.listenTo(G.window,"resize",()=>{this.attachTo(e)}),!this._resizeObserver&&(t&&dt(t)&&(t=t.parentElement),t)){const e=()=>{Pt(t)||this.unpin()};this._resizeObserver=new yt(t,e)}return!0}_stopPinning(){this.stopListening(G.document,"scroll"),this.stopListening(G.window,"resize"),this._resizeObserver&&(this._resizeObserver.destroy(),this._resizeObserver=null)}static generatePositions(t={}){const{sideOffset:i=e.arrowSideOffset,heightOffset:n=e.arrowHeightOffset,stickyVerticalOffset:s=e.stickyVerticalOffset,config:o}=t;return{northWestArrowSouthWest:(e,t)=>({top:r(e,t),left:e.left-i,name:"arrow_sw",...o&&{config:o}}),northWestArrowSouthMiddleWest:(e,t)=>({top:r(e,t),left:e.left-.25*t.width-i,name:"arrow_smw",...o&&{config:o}}),northWestArrowSouth:(e,t)=>({top:r(e,t),left:e.left-t.width/2,name:"arrow_s",...o&&{config:o}}),northWestArrowSouthMiddleEast:(e,t)=>({top:r(e,t),left:e.left-.75*t.width+i,name:"arrow_sme",...o&&{config:o}}),northWestArrowSouthEast:(e,t)=>({top:r(e,t),left:e.left-t.width+i,name:"arrow_se",...o&&{config:o}}),northArrowSouthWest:(e,t)=>({top:r(e,t),left:e.left+e.width/2-i,name:"arrow_sw",...o&&{config:o}}),northArrowSouthMiddleWest:(e,t)=>({top:r(e,t),left:e.left+e.width/2-.25*t.width-i,name:"arrow_smw",...o&&{config:o}}),northArrowSouth:(e,t)=>({top:r(e,t),left:e.left+e.width/2-t.width/2,name:"arrow_s",...o&&{config:o}}),northArrowSouthMiddleEast:(e,t)=>({top:r(e,t),left:e.left+e.width/2-.75*t.width+i,name:"arrow_sme",...o&&{config:o}}),northArrowSouthEast:(e,t)=>({top:r(e,t),left:e.left+e.width/2-t.width+i,name:"arrow_se",...o&&{config:o}}),northEastArrowSouthWest:(e,t)=>({top:r(e,t),left:e.right-i,name:"arrow_sw",...o&&{config:o}}),northEastArrowSouthMiddleWest:(e,t)=>({top:r(e,t),left:e.right-.25*t.width-i,name:"arrow_smw",...o&&{config:o}}),northEastArrowSouth:(e,t)=>({top:r(e,t),left:e.right-t.width/2,name:"arrow_s",...o&&{config:o}}),northEastArrowSouthMiddleEast:(e,t)=>({top:r(e,t),left:e.right-.75*t.width+i,name:"arrow_sme",...o&&{config:o}}),northEastArrowSouthEast:(e,t)=>({top:r(e,t),left:e.right-t.width+i,name:"arrow_se",...o&&{config:o}}),southWestArrowNorthWest:e=>({top:a(e),left:e.left-i,name:"arrow_nw",...o&&{config:o}}),southWestArrowNorthMiddleWest:(e,t)=>({top:a(e),left:e.left-.25*t.width-i,name:"arrow_nmw",...o&&{config:o}}),southWestArrowNorth:(e,t)=>({top:a(e),left:e.left-t.width/2,name:"arrow_n",...o&&{config:o}}),southWestArrowNorthMiddleEast:(e,t)=>({top:a(e),left:e.left-.75*t.width+i,name:"arrow_nme",...o&&{config:o}}),southWestArrowNorthEast:(e,t)=>({top:a(e),left:e.left-t.width+i,name:"arrow_ne",...o&&{config:o}}),southArrowNorthWest:e=>({top:a(e),left:e.left+e.width/2-i,name:"arrow_nw",...o&&{config:o}}),southArrowNorthMiddleWest:(e,t)=>({top:a(e),left:e.left+e.width/2-.25*t.width-i,name:"arrow_nmw",...o&&{config:o}}),southArrowNorth:(e,t)=>({top:a(e),left:e.left+e.width/2-t.width/2,name:"arrow_n",...o&&{config:o}}),southArrowNorthMiddleEast:(e,t)=>({top:a(e),left:e.left+e.width/2-.75*t.width+i,name:"arrow_nme",...o&&{config:o}}),southArrowNorthEast:(e,t)=>({top:a(e),left:e.left+e.width/2-t.width+i,name:"arrow_ne",...o&&{config:o}}),southEastArrowNorthWest:e=>({top:a(e),left:e.right-i,name:"arrow_nw",...o&&{config:o}}),southEastArrowNorthMiddleWest:(e,t)=>({top:a(e),left:e.right-.25*t.width-i,name:"arrow_nmw",...o&&{config:o}}),southEastArrowNorth:(e,t)=>({top:a(e),left:e.right-t.width/2,name:"arrow_n",...o&&{config:o}}),southEastArrowNorthMiddleEast:(e,t)=>({top:a(e),left:e.right-.75*t.width+i,name:"arrow_nme",...o&&{config:o}}),southEastArrowNorthEast:(e,t)=>({top:a(e),left:e.right-t.width+i,name:"arrow_ne",...o&&{config:o}}),westArrowEast:(e,t)=>({top:e.top+e.height/2-t.height/2,left:e.left-t.width-n,name:"arrow_e",...o&&{config:o}}),eastArrowWest:(e,t)=>({top:e.top+e.height/2-t.height/2,left:e.right+n,name:"arrow_w",...o&&{config:o}}),viewportStickyNorth:(e,t,i)=>{const n=new gt(G.document.body).getIntersection(i.getVisible());if(!n)return null;const r=n.getVisible();return e.getIntersection(r)&&r.top-e.top-sthis._showBalloon(),50,{leading:!0});_lastFocusedEditableElement=null;_balloonClass;constructor(e,t={}){super(),this.editor=e,this._balloonClass=t.balloonClass,e.on("ready",()=>this._handleEditorReady())}destroy(){const e=this._balloonView;e&&(e.unpin(),this._balloonView=null),this._showBalloonThrottled.cancel(),this.stopListening()}_handleEditorReady(){const e=this.editor;this._isEnabled()&&e.ui.view&&(e.ui.focusTracker.on("change:isFocused",(e,t,i)=>{this._updateLastFocusedEditableElement(),i?this._showBalloon():this._hideBalloon()}),e.ui.focusTracker.on("change:focusedElement",(e,t,i)=>{this._updateLastFocusedEditableElement(),i&&this._showBalloon()}),e.ui.on("update",()=>{this._showBalloonThrottled()}))}_getNormalizedConfig(){return{side:"ltr"===this.editor.locale.contentLanguageDirection?"right":"left",position:"border",verticalOffset:0,horizontalOffset:5}}_showBalloon(){const e=this._getBalloonAttachOptions();e&&(this._balloonView||(this._balloonView=this._createBalloonView()),this._balloonView.pin(e))}_hideBalloon(){this._balloonView&&this._balloonView.unpin()}_createBalloonView(){const e=this.editor,t=new Dm,i=this._createBadgeContent();return t.content.add(i),this._balloonClass&&(t.class=this._balloonClass),e.ui.view.body.add(t),t}_getBalloonAttachOptions(){if(!this._lastFocusedEditableElement)return null;const e=this._getNormalizedConfig(),t="right"===e.side?Wm(this._lastFocusedEditableElement,i=e,(e,t)=>e.left+e.width-t.width-i.horizontalOffset):function(e,t){return Wm(e,t,e=>e.left+t.horizontalOffset)}(this._lastFocusedEditableElement,e);var i;return{target:this._lastFocusedEditableElement,positions:[t]}}_updateLastFocusedEditableElement(){const e=this.editor,t=e.ui.focusTracker.isFocused,i=e.ui.focusTracker.focusedElement;if(!t||!i)return void(this._lastFocusedEditableElement=null);const n=Array.from(e.ui.getEditableElementsNames()).map(t=>e.ui.getEditableElement(t));n.includes(i)?this._lastFocusedEditableElement=i:this._lastFocusedEditableElement=n[0]}};function Wm(e,t,i){return(n,s)=>{const o=new gt(e);if(o.width<350||o.height<50)return null;let r;r="inside"===t.position?o.bottom-s.height:o.bottom-s.height/2,r-=t.verticalOffset;const a=i(o,s),l=n.clone().moveTo(a,r).getIntersection(s.clone().moveTo(a,r)).getVisible();return!l||l.getArea() \n',isColorInherited:!1}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-powered-by"],"aria-hidden":!0},children:[{tag:"a",attributes:{href:"https://ckeditor.com/powered-by-ckeditor/?utm_source=ckeditor&utm_medium=referral&utm_campaign=701Dn000000hVgmIAE_powered_by_ckeditor_logo",target:"_blank",tabindex:"-1"},children:[...t?[{tag:"span",attributes:{class:["ck","ck-powered-by__label"]},children:[t]}]:[],i],on:{dragstart:n.to(e=>e.preventDefault())}}]})}},jm=class extends hm{toggleSwitchView;constructor(e){super(e),this.isToggleable=!0,this.toggleSwitchView=this._createToggleView(),this.extendTemplate({attributes:{class:"ck-switchbutton"}})}render(){super.render(),this.children.add(this.toggleSwitchView)}_createToggleView(){const e=new Yh;return e.setTemplate({tag:"span",attributes:{class:["ck","ck-button__toggle"]},children:[{tag:"span",attributes:{class:["ck","ck-button__toggle__inner"]}}]}),e}};const Km=Ym(hm),Gm=Ym(Om);var Jm=class extends Km{},Qm=class extends Gm{};function Ym(e){return class extends e{_fileInputView;constructor(...e){super(...e),this._fileInputView=new Xm(this.locale),this._fileInputView.bind("acceptedType").to(this),this._fileInputView.bind("allowMultipleFiles").to(this),this._fileInputView.delegate("done").to(this),this.on("execute",()=>{this._fileInputView.open()}),this.extendTemplate({attributes:{class:"ck-file-dialog-button"}})}render(){super.render(),this.children.add(this._fileInputView)}}}var Xm=class extends Yh{constructor(e){super(e),this.set("acceptedType",void 0),this.set("allowMultipleFiles",!1);const t=this.bindTemplate;this.setTemplate({tag:"input",attributes:{class:["ck-hidden"],type:"file",tabindex:"-1",accept:t.to("acceptedType"),multiple:t.to("allowMultipleFiles")},on:{change:t.to(()=>{this.element?.files?.length&&this.fire("done",this.element.files),this.element.value=""})}})}open(){this.element.click()}},Zm=class extends Yh{buttonView;children;constructor(e,t){super(e);const i=this.bindTemplate;this.set("isCollapsed",!1),this.set("label",""),this.buttonView=this._createButtonView(),this.children=this.createCollection(),this.set("_collapsibleAriaLabelUid",void 0),t&&this.children.addMany(t),this.setTemplate({tag:"div",attributes:{class:["ck","ck-collapsible",i.if("isCollapsed","ck-collapsible_collapsed")]},children:[this.buttonView,{tag:"div",attributes:{class:["ck","ck-collapsible__children"],role:"region",hidden:i.if("isCollapsed","hidden"),"aria-labelledby":i.to("_collapsibleAriaLabelUid")},children:this.children}]})}render(){super.render(),this._collapsibleAriaLabelUid=this.buttonView.labelView.element.id}focus(){this.buttonView.focus()}_createButtonView(){const e=new hm(this.locale),t=e.bindTemplate;return e.set({withText:!0,icon:tu}),e.extendTemplate({attributes:{"aria-expanded":t.to("isOn",e=>String(e))}}),e.bind("label").to(this),e.bind("isOn").to(this,"isCollapsed",e=>!e),e.on("execute",()=>{this.isCollapsed=!this.isCollapsed}),e}};function eg(e,t){const i=e.t,n={Black:i("Black"),"Dim grey":i("Dim grey"),Grey:i("Grey"),"Light grey":i("Light grey"),White:i("White"),Red:i("Red"),Orange:i("Orange"),Yellow:i("Yellow"),"Light green":i("Light green"),Green:i("Green"),Aquamarine:i("Aquamarine"),Turquoise:i("Turquoise"),"Light blue":i("Light blue"),Blue:i("Blue"),Purple:i("Purple")};return t.map(e=>{const t=n[e.label];return t&&t!=e.label&&(e.label=t),e})}function tg(e){return e.map(ig).filter(e=>!!e)}function ig(e){return"string"==typeof e?{model:e,label:e,hasBorder:!1,view:{name:"span",styles:{color:e}}}:{model:e.color,label:e.label||e.color,hasBorder:void 0!==e.hasBorder&&e.hasBorder,view:{name:"span",styles:{color:`${e.color}`}}}}var ng=class extends hm{constructor(e){super(e);const t=this.bindTemplate;this.set("color",void 0),this.set("hasBorder",!1),this.icon=' ',this.extendTemplate({attributes:{style:{backgroundColor:t.to("color",e=>Y.isMediaForcedColors?null:e)},class:["ck","ck-color-grid__tile",t.if("hasBorder","ck-color-selector__color-tile_bordered")]}})}render(){super.render(),this.iconView.fillColor="hsl(0, 0%, 100%)"}},sg=class extends Yh{columns;items;focusTracker;keystrokes;constructor(e,t){super(e);const i=t&&t.colorDefinitions?t.colorDefinitions:[];this.columns=t?.columns||5;const n={gridTemplateColumns:`repeat( ${this.columns}, 1fr)`};this.set("selectedColor",void 0),this.items=this.createCollection(),this.focusTracker=new ci,this.keystrokes=new mi,this.items.on("add",(e,t)=>{t.isOn=t.color===this.selectedColor}),i.forEach(e=>{const t=new ng;t.set({color:e.color,label:e.label,tooltip:!0,hasBorder:e.options.hasBorder}),t.on("execute",()=>{this.fire("execute",{value:e.color,hasBorder:e.options.hasBorder,label:e.label})}),this.items.add(t)}),this.setTemplate({tag:"div",children:this.items,attributes:{class:["ck","ck-color-grid"],style:n}}),this.on("change:selectedColor",(e,t,i)=>{for(const e of this.items)e.isOn=e.color===i})}focus(){this.items.length&&this.items.first.focus()}focusLast(){this.items.length&&this.items.last.focus()}render(){super.render();for(const e of this.items)this.focusTracker.add(e.element);this.items.on("add",(e,t)=>{this.focusTracker.add(t.element)}),this.items.on("remove",(e,t)=>{this.focusTracker.remove(t.element)}),this.keystrokes.listenTo(this.element),rm({keystrokeHandler:this.keystrokes,focusTracker:this.focusTracker,gridItems:this.items,numberOfColumns:this.columns,uiLanguageDirection:this.locale?.uiLanguageDirection})}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}};function og(e,t){if(!e)return"";const i=rg(e);if(!i)return"";if(i.space===t)return e;if(n=i,!Object.keys(Ju).includes(n.space))return"";var n;const s=Ju[i.space][t];return s?function(e,t){switch(t){case"hex":return`#${e}`;case"rgb":return`rgb(${e[0]}, ${e[1]}, ${e[2]})`;case"hsl":return`hsl(${e[0]}, ${e[1]}%, ${e[2]}%)`;case"hwb":return`hwb(${e[0]}, ${e[1]}, ${e[2]})`;case"lab":return`lab(${e[0]}% ${e[1]} ${e[2]})`;case"lch":return`lch(${e[0]}% ${e[1]} ${e[2]})`;default:return""}}(s("hex"===i.space?i.hexValue:i.values),t):""}function rg(e){if(e.startsWith("#")){const t=Ou(e);return{space:"hex",values:t.values,hexValue:e,alpha:t.alpha}}const t=Ou(e);return t.space?t:null}var ag=class extends Yh{fieldView;labelView;statusView;fieldWrapperChildren;constructor(e,t){super(e);const i=`ck-labeled-field-view-${he()}`,n=`ck-labeled-field-view-status-${he()}`;this.fieldView=t(this,i,n),this.set("label",void 0),this.set("isEnabled",!0),this.set("isEmpty",!0),this.set("isFocused",!1),this.set("errorText",null),this.set("infoText",null),this.set("class",void 0),this.set("placeholder",void 0),this.labelView=this._createLabelView(i),this.statusView=this._createStatusView(n),this.fieldWrapperChildren=this.createCollection([this.fieldView,this.labelView]),this.bind("_statusText").to(this,"errorText",this,"infoText",(e,t)=>e||t);const s=this.bindTemplate;this.setTemplate({tag:"div",attributes:{class:["ck","ck-labeled-field-view",s.to("class"),s.if("isEnabled","ck-disabled",e=>!e),s.if("isEmpty","ck-labeled-field-view_empty"),s.if("isFocused","ck-labeled-field-view_focused"),s.if("placeholder","ck-labeled-field-view_placeholder"),s.if("errorText","ck-error")]},children:[{tag:"div",attributes:{class:["ck","ck-labeled-field-view__input-wrapper"]},children:this.fieldWrapperChildren},this.statusView]})}_createLabelView(e){const t=new am(this.locale);return t.for=e,t.bind("text").to(this,"label"),t}_createStatusView(e){const t=new Yh(this.locale),i=this.bindTemplate;return t.setTemplate({tag:"div",attributes:{class:["ck","ck-labeled-field-view__status",i.if("errorText","ck-labeled-field-view__status_error"),i.if("_statusText","ck-hidden",e=>!e)],id:e,role:i.if("errorText","alert")},children:[{text:i.to("_statusText")}]}),t}focus(e){this.fieldView.focus(e)}},lg=class extends Yh{focusTracker;constructor(e){super(e),this.set("value",void 0),this.set("id",void 0),this.set("placeholder",void 0),this.set("tabIndex",void 0),this.set("isReadOnly",!1),this.set("hasError",!1),this.set("ariaDescribedById",void 0),this.set("ariaLabel",void 0),this.focusTracker=new ci,this.bind("isFocused").to(this.focusTracker),this.set("isEmpty",!0);const t=this.bindTemplate;this.setTemplate({tag:"input",attributes:{class:["ck","ck-input",t.if("isFocused","ck-input_focused"),t.if("isEmpty","ck-input-text_empty"),t.if("hasError","ck-error")],id:t.to("id"),placeholder:t.to("placeholder"),tabindex:t.to("tabIndex"),readonly:t.to("isReadOnly"),"aria-invalid":t.if("hasError",!0),"aria-describedby":t.to("ariaDescribedById"),"aria-label":t.to("ariaLabel")},on:{input:t.to((...e)=>{this.fire("input",...e),this._updateIsEmpty()}),change:t.to(this._updateIsEmpty.bind(this))}})}render(){super.render(),this.focusTracker.add(this.element),this._setDomElementValue(this.value),this._updateIsEmpty(),this.on("change:value",(e,t,i)=>{this._setDomElementValue(i),this._updateIsEmpty()})}destroy(){super.destroy(),this.focusTracker.destroy()}select(){this.element.select()}focus(){this.element.focus()}reset(){this.value=this.element.value="",this._updateIsEmpty()}_updateIsEmpty(){this.isEmpty=!this.element.value}_setDomElementValue(e){this.element.value=e||0===e?e:""}};var cg=class extends lg{constructor(e){super(e),this.set("inputMode","text");const t=this.bindTemplate;this.extendTemplate({attributes:{inputmode:t.to("inputMode")}})}},dg=class extends cg{constructor(e){super(e),this.extendTemplate({attributes:{type:"text",class:["ck-input-text"]}})}},ug=class extends cg{constructor(e,{min:t,max:i,step:n}={}){super(e);const s=this.bindTemplate;this.set("min",t),this.set("max",i),this.set("step",n),this.extendTemplate({attributes:{type:"number",class:["ck-input-number"],min:s.to("min"),max:s.to("max"),step:s.to("step")}})}};var hg=class extends Yh{children;constructor(e){super(e);const t=this.bindTemplate;this.set("isVisible",!1),this.set("position","se"),this.children=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-reset","ck-dropdown__panel",t.to("position",e=>`ck-dropdown__panel_${e}`),t.if("isVisible","ck-dropdown__panel-visible")],tabindex:"-1"},children:this.children,on:{selectstart:t.to(e=>{const t=e.target;t instanceof Element&&"input"===t.tagName.toLocaleLowerCase()||e.preventDefault()})}})}focus(){if(this.children.length){const e=this.children.first;"function"==typeof e.focus?e.focus():pe("ui-dropdown-panel-focus-child-missing-focus",{childView:this.children.first,dropdownPanel:this})}}focusLast(){if(this.children.length){const e=this.children.last;"function"==typeof e.focusLast?e.focusLast():e.focus()}}},mg=class e extends Yh{buttonView;panelView;focusTracker;keystrokes;listView;toolbarView;menuView;constructor(e,t,i){super(e);const n=this.bindTemplate;this.buttonView=t,this.panelView=i,this.set("isOpen",!1),this.set("isEnabled",!0),this.set("class",void 0),this.set("id",void 0),this.set("panelPosition","auto"),this.panelView.bind("isVisible").to(this,"isOpen"),this.keystrokes=new mi,this.focusTracker=new ci,this.setTemplate({tag:"div",attributes:{class:["ck","ck-dropdown",n.to("class"),n.if("isEnabled","ck-disabled",e=>!e)],id:n.to("id"),"aria-describedby":n.to("ariaDescribedById")},children:[t,i]}),t.extendTemplate({attributes:{class:["ck-dropdown__button"],"data-cke-tooltip-disabled":n.to("isOpen")}})}render(){super.render(),this.focusTracker.add(this.buttonView.element),this.focusTracker.add(this.panelView.element),this.listenTo(this.buttonView,"open",()=>{this.isOpen=!this.isOpen}),this.on("change:isOpen",(t,i,n)=>{if(n)if("auto"===this.panelPosition){const t=e._getOptimalPosition({element:this.panelView.element,target:this.buttonView.element,fitInViewport:!0,positions:this._panelPositions});this.panelView.position=t?t.name:this._defaultPanelPositionName}else this.panelView.position=this.panelPosition}),this.keystrokes.listenTo(this.element);const t=(e,t)=>{this.isOpen&&(this.isOpen=!1,t())};this.keystrokes.set("arrowdown",(e,t)=>{this.buttonView.isEnabled&&!this.isOpen&&(this.isOpen=!0,t())}),this.keystrokes.set("arrowright",(e,t)=>{this.isOpen&&t()}),this.keystrokes.set("arrowleft",t),this.keystrokes.set("esc",t)}focus(){this.buttonView.focus()}get _panelPositions(){const{south:t,north:i,southEast:n,southWest:s,northEast:o,northWest:r,southMiddleEast:a,southMiddleWest:l,northMiddleEast:c,northMiddleWest:d}=e.defaultPanelPositions;return"rtl"!==this.locale.uiLanguageDirection?[n,s,a,l,t,o,r,c,d,i]:[s,n,l,a,t,r,o,d,c,i]}get _defaultPanelPositionName(){return"rtl"===this.locale.uiLanguageDirection?"sw":"se"}static defaultPanelPositions={south:(e,t)=>({top:e.bottom,left:e.left-(t.width-e.width)/2,name:"s"}),southEast:e=>({top:e.bottom,left:e.left,name:"se"}),southWest:(e,t)=>({top:e.bottom,left:e.left-t.width+e.width,name:"sw"}),southMiddleEast:(e,t)=>({top:e.bottom,left:e.left-(t.width-e.width)/4,name:"sme"}),southMiddleWest:(e,t)=>({top:e.bottom,left:e.left-3*(t.width-e.width)/4,name:"smw"}),north:(e,t)=>({top:e.top-t.height,left:e.left-(t.width-e.width)/2,name:"n"}),northEast:(e,t)=>({top:e.top-t.height,left:e.left,name:"ne"}),northWest:(e,t)=>({top:e.top-t.height,left:e.left-t.width+e.width,name:"nw"}),northMiddleEast:(e,t)=>({top:e.top-t.height,left:e.left-(t.width-e.width)/4,name:"nme"}),northMiddleWest:(e,t)=>({top:e.top-t.height,left:e.left-3*(t.width-e.width)/4,name:"nmw"})};static _getOptimalPosition=St},gg=class extends hm{arrowView;constructor(e){super(e),this.arrowView=this._createArrowView(),this.extendTemplate({attributes:{"aria-haspopup":!0,"aria-expanded":this.bindTemplate.to("isOn",e=>String(e))}}),this.delegate("execute").to(this,"open")}render(){super.render(),this.children.add(this.arrowView)}_createArrowView(){const e=new dm;return e.content=tu,e.extendTemplate({attributes:{class:"ck-dropdown__arrow"}}),e}},fg=class extends Yh{children;constructor(e){super(e);const t=this.bindTemplate;this.set("isVisible",!0),this.children=this.createCollection(),this.setTemplate({tag:"li",attributes:{class:["ck","ck-list__item",t.if("isVisible","ck-hidden",e=>!e)],role:"presentation"},children:this.children})}focus(){this.children.first&&this.children.first.focus()}},pg=class extends Yh{constructor(e){super(e),this.setTemplate({tag:"li",attributes:{class:["ck","ck-list__separator"]}})}},bg=class extends Yh{labelView;items;children;constructor(e,t=new am){super(e);const i=this.bindTemplate,n=new wg(e);this.set({label:"",isVisible:!0}),this.labelView=t,this.labelView.bind("text").to(this,"label"),this.children=this.createCollection(),this.children.addMany([this.labelView,n]),n.set({role:"group",ariaLabelledBy:t.id}),n.focusTracker.destroy(),n.keystrokes.destroy(),this.items=n.items,this.setTemplate({tag:"li",attributes:{role:"presentation",class:["ck","ck-list__group",i.if("isVisible","ck-hidden",e=>!e)]},children:this.children})}focus(){if(this.items){const e=this.items.find(e=>!(e instanceof pg));e&&e.focus()}}},wg=class extends Yh{focusables;items;focusTracker;keystrokes;_focusCycler;_listItemGroupToChangeListeners=new WeakMap;constructor(e){super(e);const t=this.bindTemplate;this.focusables=new Th,this.items=this.createCollection(),this.focusTracker=new ci,this.keystrokes=new mi,this._focusCycler=new pm({focusables:this.focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"arrowup",focusNext:"arrowdown"}}),this.set("ariaLabel",void 0),this.set("ariaLabelledBy",void 0),this.set("role",void 0),this.setTemplate({tag:"ul",attributes:{class:["ck","ck-reset","ck-list"],role:t.to("role"),"aria-label":t.to("ariaLabel"),"aria-labelledby":t.to("ariaLabelledBy")},children:this.items})}render(){super.render();for(const e of this.items)e instanceof bg?this._registerFocusableItemsGroup(e):e instanceof fg&&this._registerFocusableListItem(e);this.items.on("change",(e,t)=>{for(const e of t.removed)e instanceof bg?this._deregisterFocusableItemsGroup(e):e instanceof fg&&this._deregisterFocusableListItem(e);for(const e of Array.from(t.added).reverse())e instanceof bg?this._registerFocusableItemsGroup(e,t.index):this._registerFocusableListItem(e,t.index)}),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}focus(){this._focusCycler.focusFirst()}focusFirst(){this._focusCycler.focusFirst()}focusLast(){this._focusCycler.focusLast()}_registerFocusableListItem(e,t){this.focusTracker.add(e.element),this.focusables.add(e,t)}_deregisterFocusableListItem(e){this.focusTracker.remove(e.element),this.focusables.remove(e)}_getOnGroupItemsChangeCallback(e){return(t,i)=>{for(const e of i.removed)this._deregisterFocusableListItem(e);for(const t of Array.from(i.added).reverse())this._registerFocusableListItem(t,this.items.getIndex(e)+i.index)}}_registerFocusableItemsGroup(e,t){Array.from(e.items).forEach((e,i)=>{const n=void 0!==t?t+i:void 0;this._registerFocusableListItem(e,n)});const i=this._getOnGroupItemsChangeCallback(e);this._listItemGroupToChangeListeners.set(e,i),e.items.on("change",i)}_deregisterFocusableItemsGroup(e){for(const t of e.items)this._deregisterFocusableListItem(t);e.items.off("change",this._listItemGroupToChangeListeners.get(e)),this._listItemGroupToChangeListeners.delete(e)}};var _g=class extends Yh{constructor(e){super(e),this.setTemplate({tag:"span",attributes:{class:["ck","ck-toolbar__separator"]}})}},vg=class extends Yh{constructor(e){super(e),this.setTemplate({tag:"span",attributes:{class:["ck","ck-toolbar__line-break"]}})}};function yg(e){if(Array.isArray(e))return{items:e,removeItems:[]};const t={items:[],removeItems:[]};return e?{...t,...e}:t}const kg=(()=>({alignLeft:Kd,bold:Jd,importExport:' ',paragraph:' ',plus:' ',text:' ',threeVerticalDots:Pu,pilcrow:' ',dragIndicator:' '}))();var Cg=class extends Yh{options;items;focusTracker;keystrokes;itemsView;children;focusables;_focusCycler;_behavior;constructor(e,t){super(e);const i=this.bindTemplate,n=this.t;this.options=t||{},this.set("ariaLabel",n("Editor toolbar")),this.set("maxWidth","auto"),this.set("role","toolbar"),this.set("isGrouping",!!this.options.shouldGroupWhenFull),this.items=this.createCollection(),this.focusTracker=new ci,this.keystrokes=new mi,this.set("class",void 0),this.set("isCompact",!1),this.set("isVertical",!1),this.itemsView=new Ag(e),this.children=this.createCollection(),this.children.add(this.itemsView),this.focusables=this.createCollection();const s="rtl"===e.uiLanguageDirection;this._focusCycler=new pm({focusables:this.focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:[s?"arrowright":"arrowleft","arrowup"],focusNext:[s?"arrowleft":"arrowright","arrowdown"]}});const o=["ck","ck-toolbar",i.to("class"),i.if("isCompact","ck-toolbar_compact"),i.if("isGrouping","ck-toolbar_grouping"),i.if("isVertical","ck-toolbar_vertical")];var r;this.options.shouldGroupWhenFull&&this.options.isFloating&&o.push("ck-toolbar_floating"),this.setTemplate({tag:"div",attributes:{class:o,role:i.to("role"),"aria-label":i.to("ariaLabel"),style:{maxWidth:i.to("maxWidth")},tabindex:-1},children:this.children,on:{mousedown:(r=this,r.bindTemplate.to(e=>{e.target===r.element&&e.preventDefault()}))}}),this._behavior=this.options.shouldGroupWhenFull?new Eg(this):new Tg(this)}render(){super.render(),this.focusTracker.add(this.element);for(const e of this.items)this.focusTracker.add(e);this.items.on("add",(e,t)=>{this.focusTracker.add(t)}),this.items.on("remove",(e,t)=>{this.focusTracker.remove(t)}),this.keystrokes.listenTo(this.element),this._behavior.render(this)}destroy(){return this._behavior.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy(),super.destroy()}focus(){this._focusCycler.focusFirst()}focusLast(){this._focusCycler.focusLast()}fillFromConfig(e,t,i){this.items.addMany(this._buildItemsFromConfig(e,t,i))}switchBehavior(e){this._behavior.type!==e&&(this._behavior.destroy(),this.itemsView.children.clear(),this.focusables.clear(),"dynamic"===e?(this._behavior=new Eg(this),this._behavior.render(this),this._behavior.refreshItems()):(this._behavior=new Tg(this),this._behavior.render(this)))}_buildItemsFromConfig(e,t,i){const s=yg(e),o=i||s.removeItems;return this._cleanItemsConfiguration(s.items,t,o).map(e=>n(e)?this._createNestedToolbarDropdown(e,t,o):"|"===e?new _g:"-"===e?new vg:t.create(e)).filter(e=>!!e)}_cleanItemsConfiguration(e,t,i){const s=e.filter((e,s,o)=>"|"===e||-1===i.indexOf(e)&&("-"===e?!this.options.shouldGroupWhenFull||(pe("toolbarview-line-break-ignored-when-grouping-items",o),!1):!(!n(e)&&!t.has(e))||(pe("toolbarview-item-unavailable",{item:e}),!1)));return this._cleanSeparatorsAndLineBreaks(s)}_cleanSeparatorsAndLineBreaks(e){const t=e=>"-"!==e&&"|"!==e,i=e.length,n=e.findIndex(t);if(-1===n)return[];const s=i-e.slice().reverse().findIndex(t);return e.slice(n,s).filter((e,i,n)=>!!t(e)||!(i>0&&n[i-1]===e))}_createNestedToolbarDropdown(e,t,i){let{label:n,icon:s,items:o,tooltip:r=!0,withText:a=!1}=e;if(o=this._cleanItemsConfiguration(o,t,i),!o.length)return null;const l=Pg(this.locale);return n||pe("toolbarview-nested-toolbar-dropdown-missing-label",e),l.class="ck-toolbar__nested-toolbar-dropdown",l.buttonView.set({label:n,tooltip:r,withText:!!a}),!1!==s?l.buttonView.icon=kg[s]||s||Pu:l.buttonView.withText=!0,Sg(l,()=>l.toolbarView._buildItemsFromConfig(o,t,i)),l}},Ag=class extends Yh{children;constructor(e){super(e),this.children=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-toolbar__items"]},children:this.children})}},Tg=class{type="static";constructor(e){e.isGrouping=!1,e.itemsView.children.bindTo(e.items).using(e=>e),e.focusables.bindTo(e.items).using(e=>wm(e)?e:null)}render(){}destroy(){}},Eg=class{type="dynamic";view;viewChildren;viewFocusables;viewItemsView;viewFocusTracker;viewLocale;ungroupedItems;groupedItems;groupedItemsDropdown;resizeObserver=null;cachedPadding=null;shouldUpdateGroupingOnNextResize=!1;viewElement;constructor(e){this.view=e,this.viewChildren=e.children,this.viewFocusables=e.focusables,this.viewItemsView=e.itemsView,this.viewFocusTracker=e.focusTracker,this.viewLocale=e.locale,this.view.isGrouping=!0,this.ungroupedItems=e.createCollection(),this.groupedItems=e.createCollection(),this.groupedItemsDropdown=this._createGroupedItemsDropdown(),e.itemsView.children.bindTo(this.ungroupedItems).using(e=>e),this.ungroupedItems.on("change",this._updateFocusCyclableItems.bind(this)),e.children.on("change",this._updateFocusCyclableItems.bind(this)),e.items.on("change",(e,t)=>{const i=t.index,n=Array.from(t.added);for(const e of t.removed)i>=this.ungroupedItems.length?this.groupedItems.remove(e):this.ungroupedItems.remove(e);for(let e=i;ethis.ungroupedItems.length?this.groupedItems.add(t,e-this.ungroupedItems.length):this.ungroupedItems.add(t,e)}this._updateGrouping()})}render(e){this.viewElement=e.element,this._enableGroupingOnResize(),this._enableGroupingOnMaxWidthChange(e)}destroy(){this.groupedItemsDropdown.destroy(),this.viewChildren.length>1&&(this.viewChildren.remove(this.groupedItemsDropdown),this.viewChildren.remove(this.viewChildren.last)),this.resizeObserver.destroy()}refreshItems(){const e=this.view;if(e.items.length){for(let t=0;tn.right-this.cachedPadding:i.left{e&&e===t.contentRect.width&&!this.shouldUpdateGroupingOnNextResize||(this.shouldUpdateGroupingOnNextResize=!1,this._updateGrouping(),e=t.contentRect.width)}),this._updateGrouping()}_enableGroupingOnMaxWidthChange(e){e.on("change:maxWidth",()=>{this._updateGrouping()})}_groupLastItem(){this.groupedItems.length||(this.viewChildren.add(new _g),this.viewChildren.add(this.groupedItemsDropdown),this.viewFocusTracker.add(this.groupedItemsDropdown.element)),this.groupedItems.add(this.ungroupedItems.remove(this.ungroupedItems.last),0)}_ungroupFirstItem(){this.ungroupedItems.add(this.groupedItems.remove(this.groupedItems.first)),this.groupedItems.length||(this.viewChildren.remove(this.groupedItemsDropdown),this.viewChildren.remove(this.viewChildren.last),this.viewFocusTracker.remove(this.groupedItemsDropdown.element))}_createGroupedItemsDropdown(){const e=this.viewLocale,t=e.t,i=Pg(e);return i.class="ck-toolbar__grouped-dropdown",i.panelPosition="ltr"===e.uiLanguageDirection?"sw":"se",Sg(i,this.groupedItems),i.buttonView.set({label:t("Show more items"),tooltip:!0,tooltipPosition:"rtl"===e.uiLanguageDirection?"se":"sw",icon:Pu}),i}_updateFocusCyclableItems(){this.viewFocusables.clear(),this.ungroupedItems.map(e=>{wm(e)&&this.viewFocusables.add(e)}),this.groupedItems.length&&this.viewFocusables.add(this.groupedItemsDropdown)}},xg=class extends Yh{children;actionView;arrowView;keystrokes;focusTracker;constructor(e,t){super(e);const i=this.bindTemplate;this.set("class",void 0),this.set("labelStyle",void 0),this.set("icon",void 0),this.set("isEnabled",!0),this.set("isOn",!1),this.set("isToggleable",!1),this.set("isVisible",!0),this.set("keystroke",void 0),this.set("withKeystroke",!1),this.set("label",void 0),this.set("tabindex",-1),this.set("tooltip",!1),this.set("tooltipPosition","s"),this.set("type","button"),this.set("withText",!1),this.children=this.createCollection(),this.actionView=this._createActionView(t),this.arrowView=this._createArrowView(),this.keystrokes=new mi,this.focusTracker=new ci,this.setTemplate({tag:"div",attributes:{class:["ck","ck-splitbutton",i.to("class"),i.if("isVisible","ck-hidden",e=>!e),this.arrowView.bindTemplate.if("isOn","ck-splitbutton_open")]},children:this.children})}render(){super.render(),this.children.add(this.actionView),this.children.add(this.arrowView),this.focusTracker.add(this.actionView.element),this.focusTracker.add(this.arrowView.element),this.keystrokes.listenTo(this.element),this.keystrokes.set("arrowright",(e,t)=>{this.focusTracker.focusedElement===this.actionView.element&&(this.arrowView.focus(),t())}),this.keystrokes.set("arrowleft",(e,t)=>{this.focusTracker.focusedElement===this.arrowView.element&&(this.actionView.focus(),t())})}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}focus(){this.actionView.focus()}_createActionView(e){const t=e||new hm;return e||t.bind("icon","isEnabled","isOn","isToggleable","keystroke","label","tabindex","tooltip","tooltipPosition","type","withText").to(this),t.extendTemplate({attributes:{class:"ck-splitbutton__action"}}),t.delegate("execute").to(this),t}_createArrowView(){const e=new hm,t=e.bindTemplate;return e.icon=tu,e.extendTemplate({attributes:{class:["ck-splitbutton__arrow"],"data-cke-tooltip-disabled":t.to("isOn"),"aria-haspopup":!0,"aria-expanded":t.to("isOn",e=>String(e))}}),e.bind("isEnabled").to(this),e.bind("label").to(this),e.bind("tooltip").to(this),e.delegate("execute").to(this,"open"),e}};function Pg(e,t=gg){const i="function"==typeof t?new t(e):t,n=new mg(e,i,new hg(e));return i.bind("isEnabled").to(n),i instanceof xg?i.arrowView.bind("isOn").to(n,"isOpen"):i.bind("isOn").to(n,"isOpen"),function(e){(function(e){im({emitter:e,activator:()=>e.isRendered&&e.isOpen,callback:()=>{e.isOpen=!1},contextElements:()=>[e.element,...Bg(e.focusTracker).filter(t=>!e.element.contains(t))]})})(e),function(e){e.on("execute",t=>{t.source instanceof jm||(e.isOpen=!1)})}(e),function(e){e.focusTracker.on("change:isFocused",(t,i,n)=>{!n&&e.isOpen&&(e.isOpen=!1)})}(e),function(e){e.keystrokes.set("arrowdown",(t,i)=>{e.isOpen&&(e.panelView.focus(),i())}),e.keystrokes.set("arrowup",(t,i)=>{e.isOpen&&(e.panelView.focusLast(),i())})}(e),function(e){e.on("change:isOpen",(t,i,n)=>{n||e.focusTracker.elements.some(e=>e.contains(G.document.activeElement))&&e.buttonView.focus()})}(e),function(e){e.on("change:isOpen",(t,i,n)=>{n&&e.panelView.focus()},{priority:"low"})}(e)}(n),n}function Sg(e,t,i={}){e.extendTemplate({attributes:{class:["ck-toolbar-dropdown"]}}),e.isOpen?Ig(e,t,i):e.once("change:isOpen",()=>Ig(e,t,i),{priority:"highest"}),i.enableActiveItemFocusOnDropdownOpen&&Rg(e,()=>e.toolbarView.items.find(e=>e.isOn))}function Ig(e,t,i){const n=e.locale,s=n.t,o=e.toolbarView=new Cg(n),r="function"==typeof t?t():t;o.ariaLabel=i.ariaLabel||s("Dropdown toolbar"),i.maxWidth&&(o.maxWidth=i.maxWidth),i.class&&(o.class=i.class),i.isCompact&&(o.isCompact=i.isCompact),i.isVertical&&(o.isVertical=!0),r instanceof Th?o.items.bindTo(r).using(e=>e):o.items.addMany(r),e.panelView.children.add(o),e.focusTracker.add(o),o.items.delegate("execute").to(e)}function Vg(e,t,i={}){e.isOpen?Og(e,t,i):e.once("change:isOpen",()=>Og(e,t,i),{priority:"highest"}),Rg(e,()=>e.listView.items.find(e=>e instanceof fg&&e.children.first.isOn))}function Og(e,t,i){const n=e.locale,s=e.listView=new wg(n),o="function"==typeof t?t():t;s.ariaLabel=i.ariaLabel,s.role=i.role,Mg(e,s.items,o,n),e.panelView.children.add(s),s.items.delegate("execute").to(e)}function Rg(e,t){e.on("change:isOpen",()=>{if(!e.isOpen)return;const i=t();i&&("function"==typeof i.focus?i.focus():pe("ui-dropdown-focus-child-on-open-child-missing-focus",{view:i}))},{priority:me.low-10})}function Bg(e){return[...e.elements,...e.externalViews.flatMap(e=>Bg(e.focusTracker))]}function Mg(e,t,i,n){!function(e){let t=0;const i=e=>e instanceof fg&&e.children.first instanceof Om?e.children.first:null,n=e=>{const t=i(e);return t&&t.isToggleable?t:null},s=t=>{for(const n of e){const e=i(n);e&&(e.hasCheckSpace=t)}};e.on("change",(e,o)=>{const r=t>0;for(const e of o.removed)n(e)&&t--;for(const e of o.added){const n=i(e);n&&(n.isToggleable&&t++,n.hasCheckSpace=t>0)}const a=t>0;r!==a&&s(a)})}(t),t.bindTo(i).using(t=>{if("separator"===t.type)return new pg(n);if("group"===t.type){const i=new bg(n);return i.set({label:t.label}),Mg(e,i.items,t.items,n),i.items.delegate("execute").to(e),i}if("button"===t.type||"switchbutton"===t.type){const e="menuitemcheckbox"===t.model.role||"menuitemradio"===t.model.role,i=new fg(n);let s;return"button"===t.type?(s=new Om(n,t.labelView),s.set({isToggleable:e})):s=new jm(n),s.bind(...Object.keys(t.model)).to(t.model),s.delegate("execute").to(i),i.children.add(s),i}return null})}const Fg=(e,t,i)=>{const n=new dg(e.locale);return n.set({id:t,ariaDescribedById:i}),n.bind("isReadOnly").to(e,"isEnabled",e=>!e),n.bind("hasError").to(e,"errorText",e=>!!e),n.on("input",()=>{e.errorText=null}),e.bind("isEmpty","isFocused","placeholder").to(n),n},Ng=(e,t,i)=>{const n=new ug(e.locale);return n.set({id:t,ariaDescribedById:i,inputMode:"numeric"}),n.bind("isReadOnly").to(e,"isEnabled",e=>!e),n.bind("hasError").to(e,"errorText",e=>!!e),n.on("input",()=>{e.errorText=null}),e.bind("isEmpty","isFocused","placeholder").to(n),n},Lg=(e,t,i)=>{const n=Pg(e.locale);return n.set({id:t,ariaDescribedById:i}),n.bind("isEnabled").to(e),n};var Dg=class extends Yh{hexInputRow;_debounceColorPickerEvent;_config;constructor(e,t={}){super(e),this.set({color:"",_hexColor:""}),this.hexInputRow=this._createInputRow();const i=this.createCollection();t.hideInput||i.add(this.hexInputRow),this.setTemplate({tag:"div",attributes:{class:["ck","ck-color-picker"],tabindex:-1},children:i}),this._config=t,this._debounceColorPickerEvent=Ii(e=>{this.set("color",e),this.fire("colorSelected",{color:this.color})},150,{leading:!0}),this.on("set:color",(e,t,i)=>{e.return=og(i,this._config.format||"hsl")}),this.on("change:color",()=>{this._hexColor=zg(this.color)}),this.on("change:_hexColor",()=>{document.activeElement!==this.picker&&this.picker.setAttribute("color",this._hexColor),zg(this.color)!=zg(this._hexColor)&&(this.color=this._hexColor)})}render(){var e,t;if(super.render(),e="hex-color-picker",t=Ah,void 0===customElements.get(e)&&customElements.define(e,t),this.picker=G.document.createElement("hex-color-picker"),this.picker.setAttribute("class","hex-color-picker"),this.picker.setAttribute("tabindex","-1"),this._createSlidersView(),this.element){this.hexInputRow.element?this.element.insertBefore(this.picker,this.hexInputRow.element):this.element.appendChild(this.picker);const e=document.createElement("style");e.textContent='[role="slider"]:focus [part$="pointer"] {border: 1px solid #fff;outline: 1px solid var(--ck-color-focus-border);box-shadow: 0 0 0 2px #fff;}',this.picker.shadowRoot.appendChild(e)}this.picker.addEventListener("color-changed",e=>{const t=e.detail.value;this._debounceColorPickerEvent(t)})}focus(){!this._config.hideInput&&(Y.isGecko||Y.isiOS||Y.isSafari||Y.isBlink)&&this.hexInputRow.children.get(1).focus(),this.slidersView.first.focus()}_createSlidersView(){const e=[...this.picker.shadowRoot.children].filter(e=>"slider"===e.getAttribute("role")).map(e=>new Hg(e));this.slidersView=this.createCollection(),e.forEach(e=>{this.slidersView.add(e)})}_createInputRow(){const e=this._createColorInput();return new Wg(this.locale,e)}_createColorInput(){const e=new ag(this.locale,Fg),{t}=this.locale;return e.set({label:t("HEX"),class:"color-picker-hex-input"}),e.fieldView.bind("value").to(this,"_hexColor",t=>e.isFocused?e.fieldView.value:t.startsWith("#")?t.substring(1):t),e.fieldView.on("input",()=>{const t=e.fieldView.element.value;if(t){const e=Ug(t);e&&this._debounceColorPickerEvent(e)}}),e}isValid(){const{t:e}=this.locale;return!!this._config.hideInput||(this.resetValidationStatus(),!!this.hexInputRow.getParsedColor()||(this.hexInputRow.inputView.errorText=e('Please enter a valid color (e.g. "ff0000").'),!1))}resetValidationStatus(){this.hexInputRow.inputView.errorText=null}};function zg(e){let t=function(e){if(!e)return"";const t=rg(e);return t?"hex"===t.space?t.hexValue:og(e,"hex"):"#000"}(e);return t||(t="#000"),4===t.length&&(t="#"+[t[1],t[1],t[2],t[2],t[3],t[3]].join("")),t.toLowerCase()}var Hg=class extends Yh{constructor(e){super(),this.element=e}focus(){this.element.focus()}},$g=class extends Yh{constructor(e){super(e),this.setTemplate({tag:"div",attributes:{class:["ck","ck-color-picker__hash-view"]},children:"#"})}},Wg=class extends Yh{children;inputView;constructor(e,t){super(e),this.inputView=t,this.children=this.createCollection([new $g,this.inputView]),this.setTemplate({tag:"div",attributes:{class:["ck","ck-color-picker__row"]},children:this.children})}getParsedColor(){return Ug(this.inputView.fieldView.element.value)}};function Ug(e){if(!e)return null;const t=e.trim().replace(/^#/,"");return[3,4,6,8].includes(t.length)&&/^(([0-9a-fA-F]{2}){3,4}|([0-9a-fA-F]){3,4})$/.test(t)?`#${t}`:null}const qg=De(ri);var jg=class extends qg{constructor(e){super(e),this.set("isEmpty",!0),this.on("change",()=>{this.set("isEmpty",0===this.length)})}add(e,t){return this.find(t=>t.color===e.color)?this:super.add(e,t)}hasColor(e){return!!this.find(t=>t.color===e)}},Kg=class extends Yh{items;colorDefinitions;focusTracker;columns;documentColors;documentColorsCount;staticColorsGrid;documentColorsGrid;colorPickerButtonView;removeColorButtonView;_focusables;_documentColorsLabel;_removeButtonLabel;_colorPickerLabel;constructor(e,{colors:t,columns:i,removeButtonLabel:n,documentColorsLabel:s,documentColorsCount:o,colorPickerLabel:r,focusTracker:a,focusables:l}){super(e);const c=this.bindTemplate;this.set("isVisible",!0),this.focusTracker=a,this.items=this.createCollection(),this.colorDefinitions=t,this.columns=i,this.documentColors=new jg,this.documentColorsCount=o,this._focusables=l,this._removeButtonLabel=n,this._colorPickerLabel=r,this._documentColorsLabel=s,this.setTemplate({tag:"div",attributes:{class:["ck-color-grids-fragment",c.if("isVisible","ck-hidden",e=>!e)]},children:this.items}),this.removeColorButtonView=this._createRemoveColorButton(),this.items.add(this.removeColorButtonView)}updateDocumentColors(e,t){const i=e.document,n=this.documentColorsCount;this.documentColors.clear();for(const s of i.getRoots()){const i=e.createRangeIn(s);for(const e of i.getItems())if(e.is("$textProxy")&&e.hasAttribute(t)&&(this._addColorToDocumentColors(e.getAttribute(t)),this.documentColors.length>=n))return}}updateSelectedColors(){const e=this.documentColorsGrid,t=this.staticColorsGrid,i=this.selectedColor;t.selectedColor=i,e&&(e.selectedColor=i)}render(){if(super.render(),this.staticColorsGrid=this._createStaticColorsGrid(),this.items.add(this.staticColorsGrid),this.documentColorsCount){const e=xh.bind(this.documentColors,this.documentColors),t=new Yh(this.locale);t.setTemplate({tag:"span",attributes:{class:["ck","ck-color-grid__label",e.if("isEmpty","ck-hidden")]},children:[{text:this._documentColorsLabel}]}),this.items.add(t),this.documentColorsGrid=this._createDocumentColorsGrid(),this.items.add(this.documentColorsGrid)}this._createColorPickerButton(),this._addColorSelectorElementsToFocusTracker()}focus(){this.removeColorButtonView.focus()}destroy(){super.destroy()}addColorPickerButton(){this.colorPickerButtonView&&(this.items.add(this.colorPickerButtonView),this.focusTracker.add(this.colorPickerButtonView.element),this._focusables.add(this.colorPickerButtonView))}_addColorSelectorElementsToFocusTracker(){this.focusTracker.add(this.removeColorButtonView.element),this._focusables.add(this.removeColorButtonView),this.staticColorsGrid&&(this.focusTracker.add(this.staticColorsGrid.element),this._focusables.add(this.staticColorsGrid)),this.documentColorsGrid&&(this.focusTracker.add(this.documentColorsGrid.element),this._focusables.add(this.documentColorsGrid))}_createColorPickerButton(){this.colorPickerButtonView=new hm,this.colorPickerButtonView.set({label:this._colorPickerLabel,withText:!0,icon:' ',class:"ck-color-selector__color-picker"}),this.colorPickerButtonView.on("execute",()=>{this.fire("colorPicker:show")})}_createRemoveColorButton(){const e=new hm;return e.set({withText:!0,icon:iu,label:this._removeButtonLabel}),e.class="ck-color-selector__remove-color",e.on("execute",()=>{this.fire("execute",{value:null,source:"removeColorButton"})}),e.render(),e}_createStaticColorsGrid(){const e=new sg(this.locale,{colorDefinitions:this.colorDefinitions,columns:this.columns});return e.on("execute",(e,t)=>{this.fire("execute",{value:t.value,source:"staticColorsGrid"})}),e}_createDocumentColorsGrid(){const e=xh.bind(this.documentColors,this.documentColors),t=new sg(this.locale,{columns:this.columns});return t.extendTemplate({attributes:{class:e.if("isEmpty","ck-hidden")}}),t.items.bindTo(this.documentColors).using(e=>{const t=new ng;return t.set({color:e.color,hasBorder:e.options?.hasBorder}),e.label&&t.set({label:e.label,tooltip:!0}),t.on("execute",()=>{this.fire("execute",{value:e.color,source:"documentColorsGrid"})}),t}),this.documentColors.on("change:isEmpty",(e,i,n)=>{n&&(t.selectedColor=null)}),t}_addColorToDocumentColors(e){const t=this.colorDefinitions.find(t=>t.color===e);t?this.documentColors.add(Object.assign({},t)):this.documentColors.add({color:e,label:e,options:{hasBorder:!1}})}},Gg=class extends Yh{items;colorPickerView;saveButtonView;cancelButtonView;actionBarView;focusTracker;keystrokes;_focusables;_colorPickerViewConfig;constructor(e,{focusTracker:t,focusables:i,keystrokes:n,colorPickerViewConfig:s}){super(e),this.items=this.createCollection(),this.focusTracker=t,this.keystrokes=n,this.set("isVisible",!1),this.set("selectedColor",void 0),this._focusables=i,this._colorPickerViewConfig=s;const o=this.bindTemplate,{saveButtonView:r,cancelButtonView:a}=this._createActionButtons();this.saveButtonView=r,this.cancelButtonView=a,this.actionBarView=this._createActionBarView({saveButtonView:r,cancelButtonView:a}),this.setTemplate({tag:"div",attributes:{class:["ck-color-picker-fragment",o.if("isVisible","ck-hidden",e=>!e)]},children:this.items})}render(){super.render();const e=new Dg(this.locale,{...this._colorPickerViewConfig});this.colorPickerView=e,this.colorPickerView.render(),this.selectedColor&&(e.color=this.selectedColor),this.listenTo(this,"change:selectedColor",(t,i,n)=>{e.color=n}),this.items.add(this.colorPickerView),this.items.add(this.actionBarView),this._addColorPickersElementsToFocusTracker(),this._stopPropagationOnArrowsKeys(),this._executeOnEnterPress(),this._executeUponColorChange()}destroy(){super.destroy()}focus(){this.colorPickerView.focus()}resetValidationStatus(){this.colorPickerView.resetValidationStatus()}_executeOnEnterPress(){this.keystrokes.set("enter",e=>{this.isVisible&&this.focusTracker.focusedElement!==this.cancelButtonView.element&&this.colorPickerView.isValid()&&(this.fire("execute",{value:this.selectedColor}),e.stopPropagation(),e.preventDefault())})}_stopPropagationOnArrowsKeys(){const e=e=>e.stopPropagation();this.keystrokes.set("arrowright",e),this.keystrokes.set("arrowleft",e),this.keystrokes.set("arrowup",e),this.keystrokes.set("arrowdown",e)}_addColorPickersElementsToFocusTracker(){for(const e of this.colorPickerView.slidersView)this.focusTracker.add(e.element),this._focusables.add(e);const e=this.colorPickerView.hexInputRow.children.get(1);e.element&&(this.focusTracker.add(e.element),this._focusables.add(e)),this.focusTracker.add(this.saveButtonView.element),this._focusables.add(this.saveButtonView),this.focusTracker.add(this.cancelButtonView.element),this._focusables.add(this.cancelButtonView)}_createActionBarView({saveButtonView:e,cancelButtonView:t}){const i=new Yh,n=this.createCollection();return n.add(e),n.add(t),i.setTemplate({tag:"div",attributes:{class:["ck","ck-color-selector_action-bar"]},children:n}),i}_createActionButtons(){const e=this.locale,t=e.t,i=new hm(e),n=new hm(e);return i.set({icon:Zd,class:"ck-button-save",type:"button",withText:!1,label:t("Accept")}),n.set({icon:Yd,class:"ck-button-cancel",type:"button",withText:!1,label:t("Cancel")}),i.on("execute",()=>{this.colorPickerView.isValid()&&this.fire("execute",{source:"colorPickerSaveButton",value:this.selectedColor})}),n.on("execute",()=>{this.fire("colorPicker:cancel")}),{saveButtonView:i,cancelButtonView:n}}_executeUponColorChange(){this.colorPickerView.on("colorSelected",(e,t)=>{this.fire("execute",{value:t.color,source:"colorPicker"}),this.set("selectedColor",t.color)})}},Jg=class extends Yh{focusTracker;keystrokes;items;colorGridsFragmentView;colorPickerFragmentView;_focusCycler;_focusables;_colorPickerViewConfig;constructor(e,{colors:t,columns:i,removeButtonLabel:n,documentColorsLabel:s,documentColorsCount:o,colorPickerLabel:r,colorPickerViewConfig:a}){super(e),this.items=this.createCollection(),this.focusTracker=new ci,this.keystrokes=new mi,this._focusables=new Th,this._colorPickerViewConfig=a,this._focusCycler=new pm({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.colorGridsFragmentView=new Kg(e,{colors:t,columns:i,removeButtonLabel:n,documentColorsLabel:s,documentColorsCount:o,colorPickerLabel:r,focusTracker:this.focusTracker,focusables:this._focusables}),this.colorPickerFragmentView=new Gg(e,{focusables:this._focusables,focusTracker:this.focusTracker,keystrokes:this.keystrokes,colorPickerViewConfig:a}),this.set("_isColorGridsFragmentVisible",!0),this.set("_isColorPickerFragmentVisible",!1),this.set("selectedColor",void 0),this.colorGridsFragmentView.bind("isVisible").to(this,"_isColorGridsFragmentVisible"),this.colorPickerFragmentView.bind("isVisible").to(this,"_isColorPickerFragmentVisible"),this.on("change:selectedColor",(e,t,i)=>{this.colorGridsFragmentView.set("selectedColor",i),this.colorPickerFragmentView.set("selectedColor",i)}),this.colorGridsFragmentView.on("change:selectedColor",(e,t,i)=>{this.set("selectedColor",i)}),this.colorPickerFragmentView.on("change:selectedColor",(e,t,i)=>{this.set("selectedColor",i)}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-color-selector"]},children:this.items})}render(){super.render(),this.keystrokes.listenTo(this.element)}destroy(){super.destroy(),this.focusTracker.destroy(),this.keystrokes.destroy()}appendUI(){this._appendColorGridsFragment(),this._colorPickerViewConfig&&this._appendColorPickerFragment()}showColorPickerFragment(){this.colorPickerFragmentView.colorPickerView&&!this._isColorPickerFragmentVisible&&(this._isColorPickerFragmentVisible=!0,this.colorPickerFragmentView.focus(),this.colorPickerFragmentView.resetValidationStatus(),this._isColorGridsFragmentVisible=!1)}showColorGridsFragment(){this._isColorGridsFragmentVisible||(this._isColorGridsFragmentVisible=!0,this.colorGridsFragmentView.focus(),this._isColorPickerFragmentVisible=!1)}focus(){this._focusCycler.focusFirst()}focusLast(){this._focusCycler.focusLast()}updateDocumentColors(e,t){this.colorGridsFragmentView.updateDocumentColors(e,t)}updateSelectedColors(){this.colorGridsFragmentView.updateSelectedColors()}_appendColorGridsFragment(){this.items.length||(this.items.add(this.colorGridsFragmentView),this.colorGridsFragmentView.delegate("execute").to(this),this.colorGridsFragmentView.delegate("colorPicker:show").to(this))}_appendColorPickerFragment(){2!==this.items.length&&(this.items.add(this.colorPickerFragmentView),this.colorGridsFragmentView.colorPickerButtonView&&this.colorGridsFragmentView.colorPickerButtonView.on("execute",()=>{this.showColorPickerFragment()}),this.colorGridsFragmentView.addColorPickerButton(),this.colorPickerFragmentView.delegate("execute").to(this),this.colorPickerFragmentView.delegate("colorPicker:cancel").to(this))}},Qg=class{editor;_components=new Map;constructor(e){this.editor=e}*names(){for(const e of this._components.values())yield e.originalName}add(e,t){this._components.set(Yg(e),{callback:t,originalName:e})}create(e){if(!this.has(e))throw new fe("componentfactory-item-missing",this,{name:e});return this._components.get(Yg(e)).callback(this.editor.locale)}has(e){return this._components.has(Yg(e))}};function Yg(e){return String(e).toLowerCase()}const Xg="ck-tooltip",Zg=nt();var ef=class e extends Zg{tooltipTextView;balloonPanelView;static defaultBalloonPositions=Dm.generatePositions({heightOffset:5,sideOffset:13});_currentElementWithTooltip=null;_currentTooltipPosition=null;_mutationObserver=null;_pinTooltipDebounced;_unpinTooltipDebounced;_watchdogExcluded;static _editors=new Set;static _instance=null;constructor(t){if(super(),e._editors.add(t),e._instance)return e._instance;e._instance=this,this.tooltipTextView=new Yh(t.locale),this.tooltipTextView.set("text",""),this.tooltipTextView.setTemplate({tag:"span",attributes:{class:["ck","ck-tooltip__text"]},children:[{text:this.tooltipTextView.bindTemplate.to("text")}]}),this.balloonPanelView=new Dm(t.locale),this.balloonPanelView.class=Xg,this.balloonPanelView.content.add(this.tooltipTextView),this._mutationObserver=function(e){const t=new MutationObserver(()=>{e()});return{attach(e){t.observe(e,{attributes:!0,attributeFilter:["data-cke-tooltip-text","data-cke-tooltip-position"]})},detach(){t.disconnect()}}}(()=>{this._updateTooltipPosition()}),this._pinTooltipDebounced=Ii(this._pinTooltip,600),this._unpinTooltipDebounced=Ii(this._unpinTooltip,400),this.listenTo(G.document,"keydown",this._onKeyDown.bind(this),{useCapture:!0}),this.listenTo(G.document,"mouseenter",this._onEnterOrFocus.bind(this),{useCapture:!0}),this.listenTo(G.document,"mouseleave",this._onLeaveOrBlur.bind(this),{useCapture:!0}),this.listenTo(G.document,"focus",this._onEnterOrFocus.bind(this),{useCapture:!0}),this.listenTo(G.document,"blur",this._onLeaveOrBlur.bind(this),{useCapture:!0}),this.listenTo(G.document,"scroll",this._onScroll.bind(this),{useCapture:!0}),this._watchdogExcluded=!0}destroy(t){const i=t.ui.view&&t.ui.view.body;e._editors.delete(t),this.stopListening(t.ui),i&&i.has(this.balloonPanelView)&&i.remove(this.balloonPanelView),e._editors.size||(this._unpinTooltip(),this.balloonPanelView.destroy(),this.stopListening(),e._instance=null)}static getPositioningFunctions(t){const i=e.defaultBalloonPositions;return{s:[i.southArrowNorth,i.southArrowNorthEast,i.southArrowNorthWest],n:[i.northArrowSouth],e:[i.eastArrowWest],w:[i.westArrowEast],sw:[i.southArrowNorthEast],se:[i.southArrowNorthWest]}[t]}_onKeyDown(e,t){"Escape"===t.key&&this._currentElementWithTooltip&&(this._unpinTooltip(),t.stopPropagation())}_onEnterOrFocus(e,{target:t}){const i=tf(t);i?i!==this._currentElementWithTooltip?(this._unpinTooltip(),"focus"===e.name&&!i.matches(":hover")||i.matches("[data-cke-tooltip-instant]")?this._pinTooltip(i,nf(i)):this._pinTooltipDebounced(i,nf(i))):this._unpinTooltipDebounced.cancel():"focus"===e.name&&this._unpinTooltip()}_onLeaveOrBlur(e,{target:t,relatedTarget:i}){if("mouseleave"===e.name){if(!F(t))return;const e=this.balloonPanelView.element,n=e&&(e===i||e.contains(i)),s=!n&&t===e;if(n)return void this._unpinTooltipDebounced.cancel();if(!s&&this._currentElementWithTooltip&&t!==this._currentElementWithTooltip)return;const o=tf(t),r=tf(i);(s||o&&o!==r)&&(this._pinTooltipDebounced.cancel(),this._currentElementWithTooltip&&this._currentElementWithTooltip.matches("[data-cke-tooltip-instant]")||o&&o.matches("[data-cke-tooltip-instant]")?this._unpinTooltip():this._unpinTooltipDebounced())}else{if(this._currentElementWithTooltip&&t!==this._currentElementWithTooltip)return;this._pinTooltipDebounced.cancel(),this._unpinTooltipDebounced()}}_onScroll(e,{target:t}){this._currentElementWithTooltip&&(t.contains(this.balloonPanelView.element)&&t.contains(this._currentElementWithTooltip)||this._unpinTooltip())}_pinTooltip(t,{text:i,position:n,cssClass:s}){this._unpinTooltip();const o=ai(e._editors.values()).ui.view.body;o.has(this.balloonPanelView)||o.add(this.balloonPanelView),this.tooltipTextView.text=i,this.balloonPanelView.class=[Xg,s].filter(e=>e).join(" "),this.balloonPanelView.pin({target:t,positions:e.getPositioningFunctions(n)}),this._mutationObserver.attach(t);for(const t of e._editors)this.listenTo(t.ui,"update",this._updateTooltipPosition.bind(this),{priority:"low"});this._currentElementWithTooltip=t,this._currentTooltipPosition=n}_unpinTooltip(){this._unpinTooltipDebounced.cancel(),this._pinTooltipDebounced.cancel(),this.balloonPanelView.unpin();for(const t of e._editors)this.stopListening(t.ui,"update");this._currentElementWithTooltip=null,this._currentTooltipPosition=null,this.tooltipTextView.text="",this._mutationObserver.detach()}_updateTooltipPosition(){if(!this._currentElementWithTooltip)return;const t=nf(this._currentElementWithTooltip);Pt(this._currentElementWithTooltip)&&t.text?this.balloonPanelView.pin({target:this._currentElementWithTooltip,positions:e.getPositioningFunctions(t.position)}):this._unpinTooltip()}};function tf(e){return F(e)?e.closest("[data-cke-tooltip-text]:not([data-cke-tooltip-disabled])"):null}function nf(e){return{text:e.dataset.ckeTooltipText,position:e.dataset.ckeTooltipPosition||"s",cssClass:e.dataset.ckeTooltipClass||""}}var sf=class extends $m{licenseTypeMessage={evaluation:"For evaluation purposes only",trial:"For evaluation purposes only",development:"For development purposes only"};constructor(e){super(e,{balloonClass:"ck-evaluation-badge-balloon"})}_isEnabled(){const e=rf(this.editor.config.get("licenseKey"));return Boolean(e&&this.licenseTypeMessage[e])}_createBadgeContent(){const e=rf(this.editor.config.get("licenseKey"));return new of(this.editor.locale,this.licenseTypeMessage[e])}_getNormalizedConfig(){const e=super._getNormalizedConfig(),t=this.editor.config.get("ui.poweredBy")||{};return{position:t.position||e.position,side:"left"===(t.side||e.side)?"right":"left",verticalOffset:e.verticalOffset,horizontalOffset:e.horizontalOffset}}},of=class extends Yh{constructor(e,t){super(e),this.setTemplate({tag:"div",attributes:{class:["ck","ck-evaluation-badge"],"aria-hidden":!0},children:[{tag:"span",attributes:{class:["ck","ck-evaluation-badge__label"]},children:[t]}]})}};function rf(e){if("GPL"==e)return"GPL";const t=bi(e.split(".")[1]);return t?t.licenseType||"production":null}var af=class extends fg{constructor(e,t){super(e);const i=this.bindTemplate;this.extendTemplate({attributes:{class:["ck-menu-bar__menu__item"]},on:{mouseenter:i.to("mouseenter")}}),this.delegate("mouseenter").to(t)}};const lf={toggleMenusAndFocusItemsOnHover(e){e.on("menu:mouseenter",t=>{if(e.isFocusBorderEnabled||e.isOpen){if(e.isOpen)for(const i of e.menus){const e=t.path[0],n=e instanceof af&&e.children.first===i;i.isOpen=(t.path.includes(i)||n)&&i.isEnabled}t.source.focus()}})},focusCycleMenusOnArrows(e){const t="rtl"===e.locale.uiLanguageDirection;function i(t,i){const n=e.children.getIndex(t),s=t.isOpen,o=e.children.length,r=e.children.get((n+o+i)%o);t.isOpen=!1,s&&(r.isOpen=!0),r.buttonView.focus()}e.on("menu:arrowright",e=>{i(e.source,t?-1:1)}),e.on("menu:arrowleft",e=>{i(e.source,t?1:-1)})},closeMenusWhenTheBarCloses(e){e.on("change:isOpen",()=>{e.isOpen||e.menus.forEach(e=>{e.isOpen=!1})})},closeMenuWhenAnotherOnTheSameLevelOpens(e){e.on("menu:change:isOpen",(t,i,n)=>{n&&e.menus.filter(e=>t.source.parentMenuView===e.parentMenuView&&t.source!==e&&e.isOpen).forEach(e=>{e.isOpen=!1})})},closeOnClickOutside(e){im({emitter:e,activator:()=>e.isOpen,callback:()=>e.close(),contextElements:()=>e.children.map(e=>e.element)})},enableFocusHighlightOnInteraction(e){let t=!1;e.on("change:isOpen",(i,n,s)=>{s||(t||(e.isFocusBorderEnabled=!1),t=!1)}),e.listenTo(e.element,"keydown",()=>{t=!0},{useCapture:!0}),e.listenTo(e.element,"keyup",()=>{t=!1},{useCapture:!0}),e.listenTo(e.element,"focus",()=>{t&&(e.isFocusBorderEnabled=!0)},{useCapture:!0})}},cf={openAndFocusPanelOnArrowDownKey(e){e.keystrokes.set("arrowdown",(t,i)=>{e.isEnabled&&e.focusTracker.focusedElement===e.buttonView.element&&(e.isOpen||(e.isOpen=!0),e.panelView.focus(),i())})},openOnArrowRightKey(e){const t="rtl"===e.locale.uiLanguageDirection?"arrowleft":"arrowright";e.keystrokes.set(t,(t,i)=>{e.focusTracker.focusedElement===e.buttonView.element&&e.isEnabled&&(e.isOpen||(e.isOpen=!0),e.panelView.focus(),i())})},openOnButtonClick(e){e.buttonView.on("execute",()=>{e.isOpen=!0})},toggleOnButtonClick(e){e.buttonView.on("execute",()=>{e.isOpen=!e.isOpen})},openAndFocusOnEnterKeyPress(e){e.keystrokes.set("enter",(t,i)=>{e.focusTracker.focusedElement===e.buttonView.element&&(e.isOpen=!0,e.panelView.focus(),i())})},closeOnArrowLeftKey(e){const t="rtl"===e.locale.uiLanguageDirection?"arrowright":"arrowleft";e.keystrokes.set(t,(t,i)=>{e.isOpen&&(e.isOpen=!1,e.focus(),i())})},closeOnEscKey(e){e.keystrokes.set("esc",(t,i)=>{e.isOpen&&(e.isOpen=!1,e.focus(),i())})},closeOnParentClose(e){e.parentMenuView.on("change:isOpen",(t,i,n)=>{n||t.source!==e.parentMenuView||(e.isOpen=!1)})}},df={southEast:e=>({top:e.bottom,left:e.left,name:"se"}),southWest:(e,t)=>({top:e.bottom,left:e.left-t.width+e.width,name:"sw"}),northEast:(e,t)=>({top:e.top-t.height,left:e.left,name:"ne"}),northWest:(e,t)=>({top:e.top-t.height,left:e.left-t.width+e.width,name:"nw"}),eastSouth:e=>({top:e.top,left:e.right-5,name:"es"}),eastNorth:(e,t)=>({top:e.top-t.height,left:e.right-5,name:"en"}),westSouth:(e,t)=>({top:e.top,left:e.left-t.width+5,name:"ws"}),westNorth:(e,t)=>({top:e.top-t.height,left:e.left-t.width+5,name:"wn"})},uf=[{menuId:"file",label:"File",groups:[{groupId:"export",items:["menuBar:exportPdf","menuBar:exportWord"]},{groupId:"import",items:["menuBar:importWord"]},{groupId:"revisionHistory",items:["menuBar:revisionHistory"]}]},{menuId:"edit",label:"Edit",groups:[{groupId:"undo",items:["menuBar:undo","menuBar:redo"]},{groupId:"selectAll",items:["menuBar:selectAll"]},{groupId:"findAndReplace",items:["menuBar:findAndReplace"]}]},{menuId:"view",label:"View",groups:[{groupId:"sourceEditingEnhanced",items:["menuBar:sourceEditingEnhanced"]},{groupId:"sourceEditing",items:["menuBar:sourceEditing"]},{groupId:"showBlocks",items:["menuBar:showBlocks"]},{groupId:"previewMergeFields",items:["menuBar:previewMergeFields"]},{groupId:"fullscreen",items:["menuBar:fullscreen"]},{groupId:"restrictedEditing",items:["menuBar:restrictedEditing"]}]},{menuId:"insert",label:"Insert",groups:[{groupId:"insertMainWidgets",items:["menuBar:insertImage","menuBar:ckbox","menuBar:ckfinder","menuBar:insertTable","menuBar:insertTableLayout"]},{groupId:"insertInline",items:["menuBar:link","menuBar:insertFootnote","menuBar:bookmark","menuBar:comment","menuBar:insertMergeField","menuBar:emoji"]},{groupId:"insertMinorWidgets",items:["menuBar:mediaEmbed","menuBar:insertTemplate","menuBar:specialCharacters","menuBar:blockQuote","menuBar:codeBlock","menuBar:htmlEmbed"]},{groupId:"insertStructureWidgets",items:["menuBar:horizontalLine","menuBar:pageBreak","menuBar:tableOfContents"]},{groupId:"restrictedEditingException",items:["menuBar:restrictedEditingException:inline","menuBar:restrictedEditingException:block"]}]},{menuId:"format",label:"Format",groups:[{groupId:"textAndFont",items:[{menuId:"text",label:"Text",groups:[{groupId:"basicStyles",items:["menuBar:bold","menuBar:italic","menuBar:underline","menuBar:strikethrough","menuBar:superscript","menuBar:subscript","menuBar:code"]},{groupId:"textPartLanguage",items:["menuBar:textPartLanguage"]}]},{menuId:"font",label:"Font",groups:[{groupId:"fontProperties",items:["menuBar:fontSize","menuBar:fontFamily"]},{groupId:"fontColors",items:["menuBar:fontColor","menuBar:fontBackgroundColor"]},{groupId:"highlight",items:["menuBar:highlight"]}]},"menuBar:heading"]},{groupId:"list",items:["menuBar:bulletedList","menuBar:numberedList","menuBar:multiLevelList","menuBar:todoList"]},{groupId:"indent",items:["menuBar:alignment","menuBar:lineHeight","menuBar:indent","menuBar:outdent"]},{groupId:"caseChange",items:["menuBar:caseChange"]},{groupId:"removeFormat",items:["menuBar:removeFormat"]}]},{menuId:"tools",label:"Tools",groups:[{groupId:"aiTools",items:["menuBar:aiAssistant","menuBar:aiCommands","menuBar:toggleAi","menuBar:aiQuickActions"]},{groupId:"tools",items:["menuBar:trackChanges","menuBar:commentsArchive"]}]},{menuId:"help",label:"Help",groups:[{groupId:"help",items:["menuBar:accessibilityHelp"]}]}];function hf({normalizedConfig:e,locale:t,componentFactory:i,extraItems:n}){const s=L(e);return mf(e,s,n),function(e,t){const i=t.removeItems,n=[];t.items=t.items.filter(({menuId:e})=>!i.includes(e)||(n.push(e),!1)),bf(t.items,e=>{e.groups=e.groups.filter(({groupId:e})=>!i.includes(e)||(n.push(e),!1));for(const t of e.groups)t.items=t.items.filter(e=>{const t=kf(e);return!i.includes(t)||(n.push(t),!1)})});for(const t of i)n.includes(t)||pe("menu-bar-item-could-not-be-removed",{menuBarConfig:e,itemName:t})}(e,s),mf(e,s,s.addItems),function(e,t,i){bf(t.items,n=>{for(const s of n.groups)s.items=s.items.filter(s=>{const o="string"==typeof s&&!i.has(s);return o&&!t.isUsingDefaultConfig&&pe("menu-bar-item-unavailable",{menuBarConfig:e,parentMenuConfig:L(n),componentName:s}),!o})})}(e,s,i),ff(e,s),function(e,t){const i=t.t,n={File:i({string:"File",id:"MENU_BAR_MENU_FILE"}),Edit:i({string:"Edit",id:"MENU_BAR_MENU_EDIT"}),View:i({string:"View",id:"MENU_BAR_MENU_VIEW"}),Insert:i({string:"Insert",id:"MENU_BAR_MENU_INSERT"}),Format:i({string:"Format",id:"MENU_BAR_MENU_FORMAT"}),Tools:i({string:"Tools",id:"MENU_BAR_MENU_TOOLS"}),Help:i({string:"Help",id:"MENU_BAR_MENU_HELP"}),Text:i({string:"Text",id:"MENU_BAR_MENU_TEXT"}),Font:i({string:"Font",id:"MENU_BAR_MENU_FONT"})};bf(e.items,e=>{e.label in n&&(e.label=n[e.label])})}(s,t),s}function mf(e,t,i){const n=[];if(0!=i.length){for(const e of i){const i=vf(e.position),s=yf(e.position);if(wf(e))if(s){const o=t.items.findIndex(e=>e.menuId===s);-1!=o?"before"===i?(t.items.splice(o,0,e.menu),n.push(e)):"after"===i&&(t.items.splice(o+1,0,e.menu),n.push(e)):gf(t,e.menu,s,i)&&n.push(e)}else"start"===i?(t.items.unshift(e.menu),n.push(e)):"end"===i&&(t.items.push(e.menu),n.push(e));else _f(e)?bf(t.items,t=>{if(t.menuId===s)"start"===i?(t.groups.unshift(e.group),n.push(e)):"end"===i&&(t.groups.push(e.group),n.push(e));else{const o=t.groups.findIndex(e=>e.groupId===s);-1!==o&&("before"===i?(t.groups.splice(o,0,e.group),n.push(e)):"after"===i&&(t.groups.splice(o+1,0,e.group),n.push(e)))}}):gf(t,e.item,s,i)&&n.push(e)}for(const t of i)n.includes(t)||pe("menu-bar-item-could-not-be-added",{menuBarConfig:e,addedItemConfig:t})}}function gf(e,t,i,n){let s=!1;return bf(e.items,e=>{for(const{groupId:o,items:r}of e.groups){if(s)return;if(o===i)"start"===n?(r.unshift(t),s=!0):"end"===n&&(r.push(t),s=!0);else{const e=r.findIndex(e=>kf(e)===i);-1!==e&&("before"===n?(r.splice(e,0,t),s=!0):"after"===n&&(r.splice(e+1,0,t),s=!0))}}}),s}function ff(e,t){const i=t.isUsingDefaultConfig;let n=!1;t.items=t.items.filter(t=>!!t.groups.length||(pf(e,t,i),!1)),t.items.length?(bf(t.items,t=>{t.groups=t.groups.filter(e=>!!e.items.length||(n=!0,!1));for(const s of t.groups)s.items=s.items.filter(t=>!(Cf(t)&&!t.groups.length)||(pf(e,t,i),n=!0,!1))}),n&&ff(e,t)):pf(e,e,i)}function pf(e,t,i){i||pe("menu-bar-menu-empty",{menuBarConfig:e,emptyMenuConfig:t})}function bf(e,t){if(Array.isArray(e))for(const t of e)i(t);function i(e){t(e);for(const t of e.groups)for(const e of t.items)Cf(e)&&i(e)}}function wf(e){return"object"==typeof e&&"menu"in e}function _f(e){return"object"==typeof e&&"group"in e}function vf(e){return e.startsWith("start")?"start":e.startsWith("end")?"end":e.startsWith("after")?"after":"before"}function yf(e){const t=e.match(/^[^:]+:(.+)/);return t?t[1]:null}function kf(e){return"string"==typeof e?e:e.menuId}function Cf(e){return"object"==typeof e&&"menuId"in e}const Af=De();var Tf=class extends Af{editor;componentFactory;focusTracker;tooltipManager;poweredBy;evaluationBadge;ariaLiveAnnouncer;isReady=!1;_editableElementsMap=new Map;_focusableToolbarDefinitions=[];_extraMenuBarElements=[];_lastFocusedForeignElement=null;_domEmitter;constructor(e){super();const t=e.editing.view;this.editor=e,this.componentFactory=new Qg(e),this.focusTracker=new ci,this.tooltipManager=new ef(e),this.poweredBy=new Um(e),this.evaluationBadge=new sf(e),this.ariaLiveAnnouncer=new Zh(e),this._initViewportOffset(this._readViewportOffsetFromConfig()),this.once("ready",()=>{this._bindBodyCollectionWithFocusTracker(),this.isReady=!0}),this.listenTo(t.document,"layoutChanged",this.update.bind(this)),this.listenTo(t,"scrollToTheSelection",this._handleScrollToTheSelection.bind(this)),this._initFocusTracking(),this._initVisualViewportSupport()}get element(){return null}update(){this.fire("update")}destroy(){this.stopListening(),this.focusTracker.destroy(),this.tooltipManager.destroy(this.editor),this.poweredBy.destroy(),this.evaluationBadge.destroy();for(const e of this._editableElementsMap.values())e.ckeditorInstance=null,this.editor.keystrokes.stopListening(e);this._editableElementsMap=new Map,this._focusableToolbarDefinitions=[],this._domEmitter&&this._domEmitter.stopListening()}setEditableElement(e,t){this._editableElementsMap.set(e,t),t.ckeditorInstance||(t.ckeditorInstance=this.editor),this.focusTracker.add(t);const i=()=>{this.editor.editing.view.getDomRoot(e)||this.editor.keystrokes.listenTo(t)};this.isReady?i():this.once("ready",i)}removeEditableElement(e){const t=this._editableElementsMap.get(e);t&&(this._editableElementsMap.delete(e),this.editor.keystrokes.stopListening(t),this.focusTracker.remove(t),t.ckeditorInstance=null)}getEditableElement(e="main"){return this._editableElementsMap.get(e)}getEditableElementsNames(){return this._editableElementsMap.keys()}addToolbar(e,t={}){e.isRendered?(this.focusTracker.add(e),this.editor.keystrokes.listenTo(e.element)):e.once("render",()=>{this.focusTracker.add(e),this.editor.keystrokes.listenTo(e.element)}),this._focusableToolbarDefinitions.push({toolbarView:e,options:t})}extendMenuBar(e){this._extraMenuBarElements.push(e)}initMenuBar(e){const t=e.element;this.focusTracker.add(t),this.editor.keystrokes.listenTo(t);const i=function(e){let t;return t="items"in e&&e.items?{items:e.items,removeItems:[],addItems:[],isVisible:!0,isUsingDefaultConfig:!1,...e}:{items:L(uf),addItems:[],removeItems:[],isVisible:!0,isUsingDefaultConfig:!0,...e},t}(this.editor.config.get("menuBar")||{});e.fillFromConfig(i,this.componentFactory,this._extraMenuBarElements),this.editor.keystrokes.set("Esc",(e,i)=>{t.contains(this.editor.ui.focusTracker.focusedElement)&&(this._lastFocusedForeignElement?(this._lastFocusedForeignElement.focus(),this._lastFocusedForeignElement=null):this.editor.editing.view.focus(),i())}),this.editor.keystrokes.set("Alt+F9",(i,n)=>{t.contains(this.editor.ui.focusTracker.focusedElement)||(this._saveLastFocusedForeignElement(),e.isFocusBorderEnabled=!0,e.focus(),n())})}_readViewportOffsetFromConfig(){const e=this.editor,t=e.config.get("ui.viewportOffset");if(t)return t;const i=e.config.get("toolbar.viewportTopOffset");return i?(console.warn("editor-ui-deprecated-viewport-offset-config: The `toolbar.vieportTopOffset` configuration option is deprecated. It will be removed from future CKEditor versions. Use `ui.viewportOffset.top` instead."),{top:i}):{top:0}}_initFocusTracking(){const e=this.editor;let t;e.keystrokes.set("Alt+F10",(e,i)=>{this._saveLastFocusedForeignElement();const n=this._getCurrentFocusedToolbarDefinition();n&&t||(t=this._getFocusableCandidateToolbarDefinitions());for(let e=0;e{const n=this._getCurrentFocusedToolbarDefinition();n&&(this._lastFocusedForeignElement?(this._lastFocusedForeignElement.focus(),this._lastFocusedForeignElement=null):e.editing.view.focus(),n.options.afterBlur&&n.options.afterBlur(),i())})}_saveLastFocusedForeignElement(){const e=this.focusTracker.focusedElement;Array.from(this._editableElementsMap.values()).includes(e)&&!Array.from(this.editor.editing.view.domRoots.values()).includes(e)&&(this._lastFocusedForeignElement=e)}_getFocusableCandidateToolbarDefinitions(){const e=[];for(const t of this._focusableToolbarDefinitions){const{toolbarView:i,options:n}=t;(Pt(i.element)||n.beforeFocus)&&e.push(t)}return e.sort((e,t)=>Ef(e)-Ef(t)),e}_getCurrentFocusedToolbarDefinition(){for(const e of this._focusableToolbarDefinitions)if(e.toolbarView.element&&e.toolbarView.element.contains(this.focusTracker.focusedElement))return e;return null}_focusFocusableCandidateToolbar(e){const{toolbarView:t,options:{beforeFocus:i}}=e;return i&&i(),!!Pt(t.element)&&(t.focus(),!0)}_handleScrollToTheSelection(e,t){const i={top:0,bottom:0,left:0,right:0,...this.viewportOffset};t.viewportOffset.top+=i.top,t.viewportOffset.bottom+=i.bottom,t.viewportOffset.left+=i.left,t.viewportOffset.right+=i.right}_bindBodyCollectionWithFocusTracker(){const e=this.view.body;for(const t of e)this.focusTracker.add(t.element);e.on("add",(e,t)=>{this.focusTracker.add(t.element)}),e.on("remove",(e,t)=>{this.focusTracker.remove(t.element)})}_initViewportOffset(e){this.on("set:viewportOffset",(e,t,i)=>{const n=this._getVisualViewportTopOffset(i);i.visualTop!==n&&(e.return={...i,visualTop:n})}),this.set("viewportOffset",e)}_initVisualViewportSupport(){if(!G.window.visualViewport)return;const e=()=>{const e=this._getVisualViewportTopOffset(this.viewportOffset);this.viewportOffset.visualTop!==e&&(this.viewportOffset={...this.viewportOffset,visualTop:e})};this._domEmitter=new(nt()),this._domEmitter.listenTo(G.window.visualViewport,"scroll",e),this._domEmitter.listenTo(G.window.visualViewport,"resize",e)}_getVisualViewportTopOffset(e){const t=Bt().top,i=e.top||0;return t>i?0:i-t}};function Ef(e){const{toolbarView:t,options:i}=e;let n=10;return Pt(t.element)&&n--,i.isContextual&&(n-=2),n}var xf=class extends Yh{body;menuBarView;toolbar;constructor(e){super(e),this.body=new Fm(e)}render(){super.render(),this.body.attachToDom()}destroy(){return this.body.detachFromDom(),super.destroy()}},Pf=class extends xf{top;main;_voiceLabelView;constructor(e){super(e),this.top=this.createCollection(),this.main=this.createCollection(),this._voiceLabelView=this._createVoiceLabel(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-reset","ck-editor","ck-rounded-corners"],role:"application",dir:e.uiLanguageDirection,lang:e.uiLanguage,"aria-labelledby":this._voiceLabelView.id},children:[this._voiceLabelView,{tag:"div",attributes:{class:["ck","ck-editor__top","ck-reset_all"],role:"presentation"},children:this.top},{tag:"div",attributes:{class:["ck","ck-editor__main"],role:"presentation"},children:this.main}]})}_createVoiceLabel(){const e=this.t,t=new am;return t.text=e("Rich Text Editor"),t.extendTemplate({attributes:{class:"ck-voice-label"}}),t}},Sf=class extends Yh{name=null;_editingView;_editableElement;_hasExternalElement;constructor(e,t,i){super(e);const{name:n,classes:s,styles:o,attributes:r}=(If(i)?void 0:i)||{};this.set("isFocused",!1),this.set("isInlineRoot",!1),this.setTemplate({tag:n||"div",attributes:{...r,class:["ck","ck-content","ck-editor__editable","ck-rounded-corners",this.bindTemplate.if("isInlineRoot","ck-editor__editable_inline-root"),...s?ii(s):[]],...o&&{style:o},lang:e.contentLanguage,dir:e.contentLanguageDirection}}),this._editableElement=If(i)?i:void 0,this._hasExternalElement=!!this._editableElement,this._editingView=t}render(){super.render(),this._hasExternalElement?this.template.apply(this.element=this._editableElement):this._editableElement=this.element,this.on("change:isFocused",()=>this._updateIsFocusedClasses()),this._updateIsFocusedClasses()}destroy(){this._hasExternalElement&&this.template.revert(this._editableElement),super.destroy()}get hasExternalElement(){return this._hasExternalElement}_updateIsFocusedClasses(){const e=this._editingView;function t(t){e.change(i=>{const n=e.document.getRoot(t.name);i.addClass(t.isFocused?"ck-focused":"ck-blurred",n),i.removeClass(t.isFocused?"ck-blurred":"ck-focused",n)})}e.isRenderingInProgress?function i(n){e.once("change:isRenderingInProgress",(e,s,o)=>{o?i(n):t(n)})}(this):t(this)}};function If(e){return F(e)}var Vf=class extends Sf{_options;constructor(e,t,i,n={}){super(e,t,i),this._options=n,this.extendTemplate({attributes:{role:"textbox",class:"ck-editor__editable_inline"}})}render(){super.render();const e=this._editingView;e.change(t=>{const i=e.document.getRoot(this.name);t.setAttribute("aria-label",this.getEditableAriaLabel(),i)})}getEditableAriaLabel(){const e=this.locale.t,t=this._options.label,i=this._editableElement,n=this.name;if("string"==typeof t)return t;if("object"==typeof t)return t[n];if("function"==typeof t)return t(this);if(i){const e=i.getAttribute("aria-label");if(e)return e}return e("Rich Text Editor. Editing area: %0",n)}},Of=class extends Yh{children;constructor(e,t={}){super(e);const i=this.bindTemplate;this.set("class",["ck","ck-form__row",...ii(t.class||[])]),this.children=this.createCollection(),t.children&&t.children.forEach(e=>this.children.add(e)),this.set("_role",null),this.set("_ariaLabelledBy",null),t.labelView&&this.set({_role:"group",_ariaLabelledBy:t.labelView.id}),this.setTemplate({tag:"div",attributes:{class:i.to("class",e=>e.join(" ")),role:i.to("_role"),"aria-labelledby":i.to("_ariaLabelledBy")},children:this.children})}};var Rf=class extends pd{static get pluginName(){return"Notification"}static get isOfficialPlugin(){return!0}init(){this.on("show:warning",(e,t)=>{window.alert(t.message)},{priority:"lowest"})}showSuccess(e,t={}){this._showNotification({message:e,type:"success",namespace:t.namespace,title:t.title})}showInfo(e,t={}){this._showNotification({message:e,type:"info",namespace:t.namespace,title:t.title})}showWarning(e,t={}){this._showNotification({message:e,type:"warning",namespace:t.namespace,title:t.title})}_showNotification(e){const t=e.namespace?`show:${e.type}:${e.namespace}`:`show:${e.type}`;this.fire(t,{message:e.message,type:e.type,title:e.title||""})}};const Bf=De();var Mf=class extends Bf{constructor(e,t){super(),t&&Di(this,t),e&&this.set(e)}};const Ff=Ct("px");var Nf=class extends od{positionLimiter;visibleStack;_viewToStack=new Map;_idToStack=new Map;_view=null;_rotatorView=null;_fakePanelsView=null;static get pluginName(){return"ContextualBalloon"}static get isOfficialPlugin(){return!0}constructor(e){super(e),this.positionLimiter=()=>{const e=this.editor.editing.view,t=e.document.selection.editableElement;return t?e.domConverter.mapViewToDom(t.root):null},this.decorate("getPositionOptions"),this.set("visibleView",null),this.set("_numberOfStacks",0),this.set("_singleViewMode",!1)}destroy(){super.destroy(),this._view&&this._view.destroy(),this._rotatorView&&this._rotatorView.destroy(),this._fakePanelsView&&this._fakePanelsView.destroy()}get view(){return this._view||this._createPanelView(),this._view}hasView(e){return Array.from(this._viewToStack.keys()).includes(e)}add(e){if(this._view||this._createPanelView(),this.hasView(e.view))throw new fe("contextualballoon-add-view-exist",[this,e]);const t=e.stackId||"main";if(!this._idToStack.has(t))return this._idToStack.set(t,new Map([[e.view,e]])),this._viewToStack.set(e.view,this._idToStack.get(t)),this._numberOfStacks=this._idToStack.size,void(this._visibleStack&&!e.singleViewMode||this.showStack(t));const i=this._idToStack.get(t);e.singleViewMode&&this.showStack(t),i.set(e.view,e),this._viewToStack.set(e.view,i),i===this._visibleStack&&this._showView(e)}remove(e){if(!this.hasView(e))throw new fe("contextualballoon-remove-view-not-exist",[this,e]);const t=this._viewToStack.get(e);this._singleViewMode&&this.visibleView===e&&(this._singleViewMode=!1),this.visibleView===e&&(1===t.size?this._idToStack.size>1?this._showNextStack():(this.view.hide(),this.visibleView=null,this._rotatorView.hideView()):this._showView(Array.from(t.values())[t.size-2])),1===t.size?(this._idToStack.delete(this._getStackId(t)),this._numberOfStacks=this._idToStack.size):t.delete(e),this._viewToStack.delete(e)}updatePosition(e){e&&(this._visibleStack.get(this.visibleView).position=e),this.view.pin(this.getPositionOptions()),this._fakePanelsView.updatePosition()}getPositionOptions(){let e=Array.from(this._visibleStack.values()).pop().position;return e&&(e.limiter||(e=Object.assign({},e,{limiter:this.positionLimiter})),e=Object.assign({},e,{viewportOffsetConfig:{...this.editor.ui.viewportOffset,top:this.editor.ui.viewportOffset.visualTop}})),e}showStack(e){this.visibleStack=e;const t=this._idToStack.get(e);if(!t)throw new fe("contextualballoon-showstack-stack-not-exist",this);this._visibleStack!==t&&this._showView(Array.from(t.values()).pop())}_createPanelView(){this._view=new Dm(this.editor.locale),this.editor.ui.view.body.add(this._view),this._rotatorView=this._createRotatorView(),this._fakePanelsView=this._createFakePanelsView()}get _visibleStack(){return this._viewToStack.get(this.visibleView)}_getStackId(e){return Array.from(this._idToStack.entries()).find(t=>t[1]===e)[0]}_showNextStack(){const e=Array.from(this._idToStack.values());let t=e.indexOf(this._visibleStack)+1;e[t]||(t=0),this.showStack(this._getStackId(e[t]))}_showPrevStack(){const e=Array.from(this._idToStack.values());let t=e.indexOf(this._visibleStack)-1;e[t]||(t=e.length-1),this.showStack(this._getStackId(e[t]))}_createRotatorView(){const e=new Lf(this.editor.locale),t=this.editor.locale.t;return this.view.content.add(e),e.bind("isNavigationVisible").to(this,"_numberOfStacks",this,"_singleViewMode",(e,t)=>!t&&e>1),e.on("change:isNavigationVisible",()=>this.updatePosition(),{priority:"low"}),e.bind("counter").to(this,"visibleView",this,"_numberOfStacks",(e,i)=>{if(i<2)return"";const n=Array.from(this._idToStack.values()).indexOf(this._visibleStack)+1;return t("%0 of %1",[n,i])}),e.buttonNextView.on("execute",()=>{e.focusTracker.isFocused&&this.editor.editing.view.focus(),this._showNextStack()}),e.buttonPrevView.on("execute",()=>{e.focusTracker.isFocused&&this.editor.editing.view.focus(),this._showPrevStack()}),e}_createFakePanelsView(){const e=new Df(this.editor.locale,this.view);return e.bind("numberOfPanels").to(this,"_numberOfStacks",this,"_singleViewMode",(e,t)=>!t&&e>=2?Math.min(e-1,2):0),e.listenTo(this.view,"change:top",()=>e.updatePosition()),e.listenTo(this.view,"change:left",()=>e.updatePosition()),this.editor.ui.view.body.add(e),e}_showView({view:e,balloonClassName:t="",withArrow:i=!0,singleViewMode:n=!1}){this.view.class=t,this.view.withArrow=i,this._rotatorView.showView(e),this.visibleView=e,this.view.pin(this.getPositionOptions()),this._fakePanelsView.updatePosition(),n&&(this._singleViewMode=!0)}},Lf=class extends Yh{focusTracker;buttonPrevView;buttonNextView;content;constructor(e){super(e);const t=e.t,i=this.bindTemplate;this.set("isNavigationVisible",!0),this.focusTracker=new ci,this.buttonPrevView=this._createButtonView(t("Previous"),ku),this.buttonNextView=this._createButtonView(t("Next"),au),this.content=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-balloon-rotator"],"z-index":"-1"},children:[{tag:"div",attributes:{class:["ck-balloon-rotator__navigation",i.to("isNavigationVisible",e=>e?"":"ck-hidden")]},children:[this.buttonPrevView,{tag:"span",attributes:{class:["ck-balloon-rotator__counter"]},children:[{text:i.to("counter")}]},this.buttonNextView]},{tag:"div",attributes:{class:"ck-balloon-rotator__content"},children:this.content}]})}render(){super.render(),this.focusTracker.add(this.element)}destroy(){super.destroy(),this.focusTracker.destroy()}showView(e){this.hideView(),this.content.add(e)}hideView(){this.content.clear()}_createButtonView(e,t){const i=new hm(this.locale);return i.set({label:e,icon:t,tooltip:!0}),i.extendTemplate({on:{mousedown:i.bindTemplate.to(e=>e.preventDefault())}}),i}},Df=class extends Yh{content;_balloonPanelView;constructor(e,t){super(e);const i=this.bindTemplate;this.set("top",0),this.set("left",0),this.set("height",0),this.set("width",0),this.set("numberOfPanels",0),this.content=this.createCollection(),this._balloonPanelView=t,this.setTemplate({tag:"div",attributes:{class:["ck-fake-panel",i.to("numberOfPanels",e=>e?"":"ck-hidden")],style:{top:i.to("top",Ff),left:i.to("left",Ff),width:i.to("width",Ff),height:i.to("height",Ff)}},children:this.content}),this.on("change:numberOfPanels",(e,t,i,n)=>{i>n?this._addPanels(i-n):this._removePanels(n-i),this.updatePosition()})}_addPanels(e){for(;e--;){const e=new Yh;e.setTemplate({tag:"div"}),this.content.add(e),this.registerChild(e)}}_removePanels(e){for(;e--;){const e=this.content.last;this.content.remove(e),this.deregisterChild(e),e.destroy()}}updatePosition(){if(this.numberOfPanels){const{top:e,left:t}=this._balloonPanelView,{width:i,height:n}=new gt(this._balloonPanelView.element);Object.assign(this,{top:e,left:t,width:i,height:n})}}};const zf=Ct("px");var Hf=class extends Yh{content;contentPanelElement;_contentPanelPlaceholder;constructor(e){super(e);const t=this.bindTemplate;this.set("isActive",!1),this.set("isSticky",!1),this.set("limiterElement",null),this.set("limiterBottomOffset",50),this.set("viewportTopOffset",0),this.set("_marginLeft",null),this.set("_isStickyToTheBottomOfLimiter",!1),this.set("_stickyTopOffset",null),this.set("_stickyBottomOffset",null),this.content=this.createCollection(),this._contentPanelPlaceholder=new xh({tag:"div",attributes:{class:["ck","ck-sticky-panel__placeholder"],style:{display:t.to("isSticky",e=>e?"block":"none"),height:t.to("isSticky",e=>e?zf(this._contentPanelRect.height):null)}}}).render(),this.contentPanelElement=new xh({tag:"div",attributes:{class:["ck","ck-sticky-panel__content",t.if("isSticky","ck-sticky-panel__content_sticky"),t.if("_isStickyToTheBottomOfLimiter","ck-sticky-panel__content_sticky_bottom-limit")],style:{width:t.to("isSticky",e=>e?zf(this._contentPanelPlaceholder.getBoundingClientRect().width):null),top:t.to("_stickyTopOffset",e=>e?zf(e):e),bottom:t.to("_stickyBottomOffset",e=>e?zf(e):e),marginLeft:t.to("_marginLeft")}},children:this.content}).render(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-sticky-panel"]},children:[this._contentPanelPlaceholder,this.contentPanelElement]})}render(){super.render(),this.checkIfShouldBeSticky(),this.listenTo(G.document,"scroll",()=>{this.checkIfShouldBeSticky()},{useCapture:!0}),this.listenTo(this,"change:isActive",()=>{this.checkIfShouldBeSticky()}),G.window.visualViewport&&(this.listenTo(G.window.visualViewport,"scroll",()=>{this.checkIfShouldBeSticky()}),this.listenTo(G.window.visualViewport,"resize",()=>{this.checkIfShouldBeSticky()}))}checkIfShouldBeSticky(){if(!this.limiterElement||!this.isActive)return void this._unstick();const e=new gt(this.limiterElement);let t=e.getVisible();if(t){const e=new gt(G.window);e.top+=this.viewportTopOffset,e.height-=this.viewportTopOffset,t=t.getIntersection(e)}const{left:i,top:n}=Bt();if(e.moveBy(i,n),t&&t.moveBy(i,n),t&&e.topt.height){const i=Math.max(e.bottom-t.bottom,0)+this.limiterBottomOffset;this._contentPanelRect.height+i+1String(e)),"data-cke-tooltip-disabled":t.to("isOn")},on:{mouseenter:t.to("mouseenter")}})}render(){super.render(),this.children.add(this.arrowView)}_createArrowView(){const e=new dm;return e.content=tu,e.extendTemplate({attributes:{class:"ck-menu-bar__menu__button__arrow"}}),e}},Wf=class extends Yh{children;constructor(e){super(e);const t=this.bindTemplate;this.set("isVisible",!1),this.set("position","se"),this.children=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-reset","ck-menu-bar__menu__panel",t.to("position",e=>`ck-menu-bar__menu__panel_position_${e}`),t.if("isVisible","ck-hidden",e=>!e)],tabindex:"-1"},children:this.children,on:{selectstart:t.to(e=>{"input"!==e.target.tagName.toLocaleLowerCase()&&e.preventDefault()})}})}focus(e=1){this.children.length&&(1===e?this.children.first.focus():this.children.last.focus())}},Uf=class e extends Yh{buttonView;panelView;focusTracker;keystrokes;constructor(e){super(e);const t=this.bindTemplate;this.buttonView=new $f(e),this.buttonView.delegate("mouseenter").to(this),this.buttonView.bind("isOn","isEnabled").to(this,"isOpen","isEnabled"),this.panelView=new Wf(e),this.panelView.bind("isVisible").to(this,"isOpen"),this.keystrokes=new mi,this.focusTracker=new ci,this.set("isOpen",!1),this.set("isEnabled",!0),this.set("panelPosition","w"),this.set("class",void 0),this.set("parentMenuView",null),this.setTemplate({tag:"div",attributes:{class:["ck","ck-menu-bar__menu",t.to("class"),t.if("isEnabled","ck-disabled",e=>!e),t.if("parentMenuView","ck-menu-bar__menu_top-level",e=>!e)]},children:[this.buttonView,this.panelView]})}render(){super.render(),this.focusTracker.add(this.buttonView.element),this.focusTracker.add(this.panelView.element),this.keystrokes.listenTo(this.element),cf.closeOnEscKey(this),this._closeOnDisabled(),this._repositionPanelOnOpen()}_attachBehaviors(){this.parentMenuView?(cf.openOnButtonClick(this),cf.openOnArrowRightKey(this),cf.closeOnArrowLeftKey(this),cf.openAndFocusOnEnterKeyPress(this),cf.closeOnParentClose(this)):(this._propagateArrowKeystrokeEvents(),cf.openAndFocusPanelOnArrowDownKey(this),cf.toggleOnButtonClick(this))}_propagateArrowKeystrokeEvents(){this.keystrokes.set("arrowright",(e,t)=>{this.fire("arrowright"),t()}),this.keystrokes.set("arrowleft",(e,t)=>{this.fire("arrowleft"),t()})}_closeOnDisabled(){this.on("change:isEnabled",(e,t,i)=>{i||(this.isOpen=!1)})}_repositionPanelOnOpen(){this.on("change:isOpen",(t,i,n)=>{if(!n)return;const s=e._getOptimalPosition({element:this.panelView.element,target:this.buttonView.element,fitInViewport:!0,positions:this._panelPositions});this.panelView.position=s?s.name:this._defaultMenuPositionName})}focus(){this.buttonView.focus()}get _panelPositions(){const{southEast:e,southWest:t,northEast:i,northWest:n,westSouth:s,eastSouth:o,westNorth:r,eastNorth:a}=df;return"ltr"===this.locale.uiLanguageDirection?this.parentMenuView?[o,a,s,r]:[e,t,i,n]:this.parentMenuView?[s,r,o,a]:[t,e,n,i]}get _defaultMenuPositionName(){return"ltr"===this.locale.uiLanguageDirection?this.parentMenuView?"es":"se":this.parentMenuView?"ws":"sw"}static _getOptimalPosition=St},qf=class extends wg{constructor(e){super(e),this.role="menu",this.items.on("change",this._setItemsCheckSpace.bind(this))}_setItemsCheckSpace(){const e=Array.from(this.items).some(e=>{const t=jf(e);return t&&t.isToggleable});this.items.forEach(t=>{const i=jf(t);i&&(i.hasCheckSpace=e)})}};function jf(e){return e instanceof fg?e.children.map(e=>function(e){return"object"==typeof e&&"buttonView"in e&&e.buttonView instanceof hm}(e)?e.buttonView:e).find(e=>e instanceof Om):null}var Kf=class extends Qm{constructor(e){super(e),this.set({withText:!0,withKeystroke:!0,tooltip:!1,role:"menuitem"}),this.extendTemplate({attributes:{class:["ck-menu-bar__menu__item__button"]}})}};const Gf=["mouseenter","arrowleft","arrowright","change:isOpen"];var Jf=class extends Yh{children;menus=[];constructor(e){super(e);const t=e.t,i=this.bindTemplate;this.set({isOpen:!1,isFocusBorderEnabled:!1}),this._setupIsOpenUpdater(),this.children=this.createCollection(),this.setTemplate({tag:"div",attributes:{class:["ck","ck-menu-bar",i.if("isFocusBorderEnabled","ck-menu-bar_focus-border-enabled")],"aria-label":t("Editor menu bar"),role:"menubar"},children:this.children})}fillFromConfig(e,t,i=[]){const n=hf({normalizedConfig:e,locale:this.locale,componentFactory:t,extraItems:i}).items.map(e=>this._createMenu({componentFactory:t,menuDefinition:e}));this.children.addMany(n)}render(){super.render(),lf.toggleMenusAndFocusItemsOnHover(this),lf.closeMenusWhenTheBarCloses(this),lf.closeMenuWhenAnotherOnTheSameLevelOpens(this),lf.focusCycleMenusOnArrows(this),lf.closeOnClickOutside(this),lf.enableFocusHighlightOnInteraction(this)}focus(){this.children.first&&this.children.first.focus()}close(){for(const e of this.children)e.isOpen=!1;this.isOpen=!1}disable(){for(const e of this.children)e.isEnabled=!1}enable(){for(const e of this.children)e.isEnabled=!0}registerMenu(e,t=null){t?(e.delegate(...Gf).to(t),e.parentMenuView=t):e.delegate(...Gf).to(this,e=>"menu:"+e),e._attachBehaviors(),this.menus.push(e)}_createMenu({componentFactory:e,menuDefinition:t,parentMenuView:i}){const n=this.locale,s=new Uf(n);return this.registerMenu(s,i),s.buttonView.set({label:t.label}),s.once("change:isOpen",()=>{const i=new qf(n);i.ariaLabel=t.label,s.panelView.children.add(i),i.items.addMany(this._createMenuItems({menuDefinition:t,parentMenuView:s,componentFactory:e}))}),s}_createMenuItems({menuDefinition:e,parentMenuView:t,componentFactory:i}){const s=this.locale,o=[];for(const r of e.groups){for(const e of r.items){const r=new af(s,t);if(n(e))r.children.add(this._createMenu({componentFactory:i,menuDefinition:e,parentMenuView:t}));else{const n=this._createMenuItemContentFromFactory({componentName:e,componentFactory:i,parentMenuView:t});if(!n)continue;r.children.add(n)}o.push(r)}r!==e.groups[e.groups.length-1]&&o.push(new pg(s))}return o}_createMenuItemContentFromFactory({componentName:e,parentMenuView:t,componentFactory:i}){const n=i.create(e);return n instanceof Uf||n instanceof Bm||n instanceof Kf?(this._registerMenuTree(n,t),n.on("execute",()=>{this.close()}),n):(pe("menu-bar-component-unsupported",{componentName:e,componentView:n}),null)}_registerMenuTree(e,t){if(!(e instanceof Uf))return void e.delegate("mouseenter").to(t);this.registerMenu(e,t);const i=e.panelView.children.filter(e=>e instanceof qf)[0];if(!i)return void e.delegate("mouseenter").to(t);const n=i.items.filter(e=>e instanceof fg);for(const t of n)this._registerMenuTree(t.children.get(0),e)}_setupIsOpenUpdater(){let e;this.on("menu:change:isOpen",(t,i,n)=>{clearTimeout(e),n?this.isOpen=!0:e=setTimeout(()=>{this.isOpen=Array.from(this.children).some(e=>e.isOpen)},0)})}};const Qf=De();var Yf=class extends Qf{total;_reader;_data;constructor(){super();const e=new window.FileReader;this._reader=e,this._data=void 0,this.set("loaded",0),e.onprogress=e=>{this.loaded=e.loaded}}get error(){return this._reader.error}get data(){return this._data}read(e){const t=this._reader;return this.total=e.size,new Promise((i,n)=>{t.onload=()=>{const e=t.result;this._data=e,i(e)},t.onerror=()=>{n("error")},t.onabort=()=>{n("aborted")},this._reader.readAsDataURL(e)})}abort(){this._reader.abort()}};const Xf=De();var Zf=class extends od{loaders=new ri;_loadersMap=new Map;_pendingAction=null;static get pluginName(){return"FileRepository"}static get isOfficialPlugin(){return!0}static get requires(){return[Wd]}init(){this.loaders.on("change",()=>this._updatePendingAction()),this.set("uploaded",0),this.set("uploadTotal",null),this.bind("uploadedPercent").to(this,"uploaded",this,"uploadTotal",(e,t)=>t?e/t*100:0)}getLoader(e){return this._loadersMap.get(e)||null}createLoader(e){if(!this.createUploadAdapter)return pe("filerepository-no-upload-adapter"),null;const t=new ep(Promise.resolve(e),this.createUploadAdapter);return this.loaders.add(t),this._loadersMap.set(e,t),e instanceof Promise&&t.file.then(e=>{this._loadersMap.set(e,t)}).catch(()=>{}),t.on("change:uploaded",()=>{let e=0;for(const t of this.loaders)e+=t.uploaded;this.uploaded=e}),t.on("change:uploadTotal",()=>{let e=0;for(const t of this.loaders)t.uploadTotal&&(e+=t.uploadTotal);this.uploadTotal=e}),t}destroyLoader(e){const t=e instanceof ep?e:this.getLoader(e);t._destroy(),this.loaders.remove(t),this._loadersMap.forEach((e,i)=>{e===t&&this._loadersMap.delete(i)})}_updatePendingAction(){const e=this.editor.plugins.get(Wd);if(this.loaders.length){if(!this._pendingAction){const t=this.editor.t,i=e=>`${t("Upload in progress")} ${parseInt(e)}%.`;this._pendingAction=e.add(i(this.uploadedPercent)),this._pendingAction.bind("message").to(this,"uploadedPercent",i)}}else e.remove(this._pendingAction),this._pendingAction=null}},ep=class extends Xf{id;_filePromiseWrapper;_adapter;_reader;constructor(e,t){super(),this.id=he(),this._filePromiseWrapper=this._createFilePromiseWrapper(e),this._adapter=t(this),this._reader=new Yf,this.set("status","idle"),this.set("uploaded",0),this.set("uploadTotal",null),this.bind("uploadedPercent").to(this,"uploaded",this,"uploadTotal",(e,t)=>t?e/t*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("idle"!=this.status)throw new fe("filerepository-read-wrong-status",this);return this.status="reading",this.file.then(e=>this._reader.read(e)).then(e=>{if("reading"!==this.status)throw this.status;return this.status="idle",e}).catch(e=>{if("aborted"===e)throw this.status="aborted","aborted";throw this.status="error",this._reader.error?this._reader.error:e})}upload(){if("idle"!=this.status)throw new fe("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=>{if("aborted"===this.status)throw"aborted";throw this.status="error",e})}abort(){const e=this.status;this.status="aborted",this._filePromiseWrapper.isFulfilled?"reading"==e?this._reader.abort():"uploading"==e&&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 t={};return t.promise=new Promise((i,n)=>{t.rejecter=n,t.isFulfilled=!1,e.then(e=>{t.isFulfilled=!0,i(e)}).catch(e=>{t.isFulfilled=!0,n(e)})}),t}};const tp=["left","right","center","justify"];function ip(e){return tp.includes(e)}function np(e,t){return"rtl"==t.contentLanguageDirection?"right"===e:"left"===e}function sp(e){const t=e.map(e=>{let t;return t="string"==typeof e?{name:e}:e,t}).filter(e=>{const t=tp.includes(e.name);return t||pe("alignment-config-name-not-recognized",{option:e}),t}),i=t.filter(e=>Boolean(e.className)).length;if(i&&i{const s=n.slice(i+1);if(s.some(e=>e.name==t.name))throw new fe("alignment-config-name-already-defined",{option:t,configuredOptions:e});if(t.className&&s.some(e=>e.className==t.className))throw new fe("alignment-config-classname-already-defined",{option:t,configuredOptions:e})}),t}const op="alignment";var rp=class extends ld{refresh(){const e=this.editor.locale,t=ai(this.editor.model.document.selection.getSelectedBlocks());this.isEnabled=Boolean(t)&&this._canBeAligned(t),this.isEnabled&&t.hasAttribute("alignment")?this.value=t.getAttribute("alignment"):this.value="rtl"===e.contentLanguageDirection?"right":"left"}execute(e={}){const t=this.editor,i=t.locale,n=t.model,s=n.document,o=e.value;n.change(e=>{const t=Array.from(s.selection.getSelectedBlocks()).filter(e=>this._canBeAligned(e)),n=t[0].getAttribute("alignment");np(o,i)||n===o||!o?function(e,t){for(const i of e)t.removeAttribute(op,i)}(t,e):function(e,t,i){for(const n of e)t.setAttribute(op,i,n)}(t,e,o)})}_canBeAligned(e){return this.editor.model.schema.checkAttribute(e,op)}};var ap=class extends od{static get pluginName(){return"AlignmentEditing"}static get isOfficialPlugin(){return!0}constructor(e){super(e),e.config.define("alignment",{options:tp.map(e=>({name:e}))})}init(){const e=this.editor,t=e.locale,i=e.model.schema,n=sp(e.config.get("alignment.options")).filter(e=>ip(e.name)&&!np(e.name,t)),s=n.some(e=>!!e.className);i.extend("$block",{allowAttributes:"alignment"}),e.model.schema.setAttributeProperties("alignment",{isFormatting:!0,blockAlignment:lp(t)}),s?e.conversion.attributeToAttribute(function(e){const t={};for(const i of e)t[i.name]={key:"class",value:i.className};return{model:{key:"alignment",values:e.map(e=>e.name)},view:t}}(n)):e.conversion.for("downcast").attributeToAttribute(function(e){const t={};for(const{name:i}of e)t[i]={key:"style",value:{"text-align":i}};return{model:{key:"alignment",values:e.map(e=>e.name)},view:t}}(n));const o=function(e){const t=[];for(const{name:i}of e)t.push({view:{key:"style",value:{"text-align":i}},model:{key:"alignment",value:i}});return t}(n);for(const t of o)e.conversion.for("upcast").attributeToAttribute(t);const r=function(e){const t=[];for(const{name:i}of e)t.push({view:{key:"align",value:i},model:{key:"alignment",value:i}});return t}(n);for(const t of r)e.conversion.for("upcast").attributeToAttribute(t);e.commands.add("alignment",new rp(e))}};function lp(e){const t={left:{value:"left"},right:{value:"right"},center:{value:"center"},justify:{value:"justify"}};return t["rtl"==e.contentLanguageDirection?"right":"left"].isDefault=!0,t}const cp=(()=>new Map([["left",Kd],["right",Gd],["center",qd],["justify",jd]]))();var dp=class extends od{get localizedOptionTitles(){const e=this.editor.t;return{left:e("Align left"),right:e("Align right"),center:e("Align center"),justify:e("Justify")}}static get pluginName(){return"AlignmentUI"}static get isOfficialPlugin(){return!0}init(){const e=sp(this.editor.config.get("alignment.options"));e.map(e=>e.name).filter(ip).forEach(e=>this._addButton(e)),this._addToolbarDropdown(e),this._addMenuBarMenu(e)}_addButton(e){this.editor.ui.componentFactory.add(`alignment:${e}`,t=>this._createButton(t,e))}_createButton(e,t,i={}){const n=this.editor,s=n.commands.get("alignment"),o=new hm(e);return o.set({label:this.localizedOptionTitles[t],icon:cp.get(t),tooltip:!0,isToggleable:!0,...i}),o.bind("isEnabled").to(s),o.bind("isOn").to(s,"value",e=>e===t),this.listenTo(o,"execute",()=>{n.execute("alignment",{value:t}),n.editing.view.focus()}),o}_addToolbarDropdown(e){const t=this.editor;t.ui.componentFactory.add("alignment",i=>{const n=Pg(i),s="rtl"===i.uiLanguageDirection?"w":"e",o=i.t;Sg(n,()=>e.map(e=>this._createButton(i,e.name,{tooltipPosition:s})),{enableActiveItemFocusOnDropdownOpen:!0,isVertical:!0,ariaLabel:o("Text alignment toolbar")}),n.buttonView.set({label:o("Text alignment"),tooltip:!0}),n.extendTemplate({attributes:{class:"ck-alignment-dropdown"}});const r="rtl"===i.contentLanguageDirection?cp.get("right"):cp.get("left"),a=t.commands.get("alignment");return n.buttonView.bind("icon").to(a,"value",e=>cp.get(e)||r),n.bind("isEnabled").to(a,"isEnabled"),this.listenTo(n,"execute",()=>{t.editing.view.focus()}),n})}_addMenuBarMenu(e){const t=this.editor;t.ui.componentFactory.add("menuBar:alignment",i=>{const n=t.commands.get("alignment"),s=i.t,o=new Uf(i),r=new qf(i);o.bind("isEnabled").to(n),r.set({ariaLabel:s("Text alignment"),role:"menu"}),o.buttonView.set({label:s("Text alignment")});for(const s of e){const e=new af(i,o),a=new Bm(i);a.delegate("execute").to(o),a.set({label:this.localizedOptionTitles[s.name],icon:cp.get(s.name),role:"menuitemcheckbox",isToggleable:!0}),a.on("execute",()=>{t.execute("alignment",{value:s.name}),t.editing.view.focus()}),a.bind("isOn").to(n,"value",e=>e===s.name),a.bind("isEnabled").to(n,"isEnabled"),e.children.add(a),r.items.add(e)}return o.panelView.children.add(r),o})}},up=class extends od{static get requires(){return[ap,dp]}static get pluginName(){return"Alignment"}static get isOfficialPlugin(){return!0}},hp=class{model;limit;_isLocked;_size;_batch=null;_changeCallback;_selectionChangeCallback;constructor(e,t=20){this.model=e,this._size=0,this.limit=t,this._isLocked=!1,this._changeCallback=(e,t)=>{t.isLocal&&t.isUndoable&&t!==this._batch&&this._reset(!0)},this._selectionChangeCallback=()=>{this._reset()},this.model.document.on("change",this._changeCallback),this.model.document.selection.on("change:range",this._selectionChangeCallback),this.model.document.selection.on("change:attribute",this._selectionChangeCallback)}get batch(){return this._batch||(this._batch=this.model.createBatch({isTyping:!0})),this._batch}get size(){return this._size}input(e){this._size+=e,this._size>=this.limit&&this._reset(!0)}get isLocked(){return this._isLocked}lock(){this._isLocked=!0}unlock(){this._isLocked=!1}destroy(){this.model.document.off("change",this._changeCallback),this.model.document.selection.off("change:range",this._selectionChangeCallback),this.model.document.selection.off("change:attribute",this._selectionChangeCallback)}_reset(e=!1){this.isLocked&&!e||(this._batch=null,this._size=0)}},mp=class extends ld{_buffer;constructor(e,t){super(e),this._buffer=new hp(e.model,t),this._isEnabledBasedOnSelection=!1}get buffer(){return this._buffer}destroy(){super.destroy(),this._buffer.destroy()}execute(e={}){const t=this.editor.model,i=t.document,n=e.text||"",s=n.length;let o=i.selection;if(e.selection?o=e.selection:e.range&&(o=t.createSelection(e.range)),!t.canEditAt(o))return;const r=e.resultRange;t.enqueueChange(this._buffer.batch,e=>{this._buffer.lock();const a=Array.from(i.selection.getAttributes());t.deleteContent(o),n&&t.insertContent(e.createText(n,a),o),r?e.setSelection(r):o.is("documentSelection")||e.setSelection(o),this._buffer.unlock(),this._buffer.input(s)})}};const gp=["insertText","insertReplacementText"],fp=[...gp,"insertCompositionText"];var pp=class extends ro{focusObserver;constructor(e){super(e),this.focusObserver=e.getObserver(go);const t=Y.isAndroid?fp:gp,i=e.document;i.on("beforeinput",(n,s)=>{if(!this.isEnabled)return;const{data:o,targetRanges:r,inputType:a,domEvent:l,isComposing:c}=s;if(!t.includes(a))return;this.focusObserver.flush();const d=new de(i,"insertText");i.fire(d,new ao(e,l,{text:o,selection:e.createSelection(r),isComposing:c})),d.stop.called&&n.stop()}),Y.isAndroid||i.on("compositionend",(t,{data:n,domEvent:s})=>{this.isEnabled&&n&&i.fire("insertText",new ao(e,s,{text:n,isComposing:!0}))},{priority:"low"})}observe(){}stopObserving(){}},bp=class extends od{_typingQueue;static get pluginName(){return"Input"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.model,i=e.editing.view,n=e.editing.mapper,s=t.document.selection;this._typingQueue=new wp(e),i.addObserver(pp);const o=new mp(e,e.config.get("typing.undoStep")||20);e.commands.add("insertText",o),e.commands.add("input",o),this.listenTo(i.document,"beforeinput",()=>{this._typingQueue.flush("next beforeinput")},{priority:"high"}),this.listenTo(i.document,"insertText",(e,r)=>{const{text:a,selection:l}=r;if(i.document.selection.isFake&&l&&i.document.selection.isSimilar(l)&&r.preventDefault(),l&&Array.from(l.getRanges()).some(e=>!e.isCollapsed)&&r.preventDefault(),!o.isEnabled)return void r.preventDefault();let c;l&&(c=Array.from(l.getRanges()).filter(e=>e.root.is("rootElement")).map(e=>n.toModelRange(e)).map(e=>kl(e,t.schema)||e)),c&&c.length||(c=Array.from(s.getRanges()));let d=a;if(Y.isAndroid){const e=Array.from(c[0].getItems()).reduce((e,t)=>e+(t.is("$textProxy")?t.data:""),"");if(e&&(e.length<=d.length?d.startsWith(e)&&(d=d.substring(e.length),c[0].start=c[0].start.getShiftedBy(e.length)):e.startsWith(d)&&(c[0].start=c[0].start.getShiftedBy(d.length),d="")),0==d.length&&c[0].isCollapsed)return}const u={text:d,selection:t.createSelection(c)};this._typingQueue.push(u,Boolean(r.isComposing)),r.domEvent.defaultPrevented&&this._typingQueue.flush("beforeinput default prevented")}),Y.isAndroid?this.listenTo(i.document,"keydown",(e,n)=>{!s.isCollapsed&&229==n.keyCode&&i.document.isComposing&&_p(t,o)}):this.listenTo(i.document,"compositionstart",()=>{s.isCollapsed||_p(t,o)},{priority:"high"}),this.listenTo(i.document,"mutations",(e,{mutations:t})=>{if(this._typingQueue.hasAffectedElements())for(const{node:e}of t){const t=vp(e,n),i=n.toModelElement(t);if(this._typingQueue.isElementAffected(i))return void this._typingQueue.flush("mutations")}}),this.listenTo(i.document,"compositionend",()=>{this._typingQueue.flush("before composition end")},{priority:"high"}),this.listenTo(i.document,"compositionend",()=>{this._typingQueue.flush("after composition end");const e=[];if(this._typingQueue.hasAffectedElements())for(const t of this._typingQueue.flushAffectedElements()){const i=n.toViewElement(t);i&&e.push({type:"children",node:i})}!e.length&&Y.isAndroid||i.document.fire("mutations",{mutations:e})},{priority:"lowest"})}destroy(){super.destroy(),this._typingQueue.destroy()}},wp=class{editor;flushDebounced=Ii(()=>this.flush("timeout"),50);_queue=[];_isComposing=!1;_affectedElements=new Set;constructor(e){this.editor=e}destroy(){for(this.flushDebounced.cancel(),this._affectedElements.clear();this._queue.length;)this.shift()}get length(){return this._queue.length}push(e,t){const i={text:e.text};if(e.selection){i.selectionRanges=[];for(const t of e.selection.getRanges())i.selectionRanges.push(ir.fromRange(t)),this._affectedElements.add(t.start.parent)}this._queue.push(i),this._isComposing||=t,this.flushDebounced()}shift(){const e=this._queue.shift(),t={text:e.text};if(e.selectionRanges){const i=e.selectionRanges.map(e=>function(e){const t=e.toRange();return e.detach(),"$graveyard"==t.root.rootName?null:t}(e)).filter(e=>!!e);i.length&&(t.selection=this.editor.model.createSelection(i))}return t}flush(e){const t=this.editor,i=t.model,n=t.editing.view;if(this.flushDebounced.cancel(),!this._queue.length)return;const s=t.commands.get("insertText").buffer;i.enqueueChange(s.batch,()=>{for(s.lock();this._queue.length;){const e=this.shift();t.execute("insertText",e)}s.unlock(),this._isComposing||this._affectedElements.clear(),this._isComposing=!1}),n.scrollToTheSelection()}isElementAffected(e){return this._affectedElements.has(e)}hasAffectedElements(){return this._affectedElements.size>0}flushAffectedElements(){const e=Array.from(this._affectedElements);return this._affectedElements.clear(),e}};function _p(e,t){if(!t.isEnabled)return;const i=t.buffer;i.lock(),e.enqueueChange(i.batch,()=>{e.deleteContent(e.document.selection)}),i.unlock()}function vp(e,t){let i=e.is("$text")?e.parent:e;for(;!t.toModelElement(i);)i=i.parent;return i}var yp=class extends ld{direction;_buffer;constructor(e,t){super(e),this.direction=t,this._buffer=new hp(e.model,e.config.get("typing.undoStep")),this._isEnabledBasedOnSelection=!1}get buffer(){return this._buffer}execute(e={}){const t=this.editor.model,i=t.document;t.enqueueChange(this._buffer.batch,n=>{this._buffer.lock();const s=n.createSelection(e.selection||i.selection);if(!t.canEditAt(s))return;const o=e.sequence||1,r=s.isCollapsed;if(s.isCollapsed&&t.modifySelection(s,{direction:this.direction,unit:e.unit,treatEmojiAsSingleUnit:!0}),this._shouldEntireContentBeReplacedWithParagraph(o))return void this._replaceEntireContentWithParagraph(n);if(this._shouldReplaceFirstBlockWithParagraph(s,o))return void this.editor.execute("paragraph",{selection:s});if(s.isCollapsed)return;let a=0;s.getFirstRange().getMinimalFlatRanges().forEach(e=>{a+=je(e.getWalker({singleCharacters:!0,ignoreElementEnd:!0,shallow:!0}))}),t.deleteContent(s,{doNotResetEntireContent:r,direction:this.direction}),this._buffer.input(a),n.setSelection(s),this._buffer.unlock()})}_shouldEntireContentBeReplacedWithParagraph(e){if(e>1)return!1;const t=this.editor.model,i=t.document.selection,n=t.schema.getLimitElement(i);if(!i.isCollapsed||!i.containsEntireContent(n))return!1;if(!t.schema.checkChild(n,"paragraph"))return!1;const s=n.getChild(0);return!s||!s.is("element","paragraph")}_replaceEntireContentWithParagraph(e){const t=this.editor.model,i=t.document.selection,n=t.schema.getLimitElement(i),s=e.createElement("paragraph");e.remove(e.createRangeIn(n)),e.insert(s,n),e.setSelection(s,0)}_shouldReplaceFirstBlockWithParagraph(e,t){const i=this.editor.model;if(t>1||"backward"!=this.direction)return!1;if(!e.isCollapsed)return!1;const n=e.getFirstPosition(),s=i.schema.getLimitElement(n),o=s.getChild(0);return n.parent==o&&(!!e.containsEntireContent(o)&&(!!i.schema.checkChild(s,"paragraph")&&"paragraph"!=o.name))}};const kp="word",Cp="selection",Ap="backward",Tp="forward",Ep={deleteContent:{unit:Cp,direction:Ap},deleteContentBackward:{unit:"codePoint",direction:Ap},deleteWordBackward:{unit:kp,direction:Ap},deleteHardLineBackward:{unit:Cp,direction:Ap},deleteSoftLineBackward:{unit:Cp,direction:Ap},deleteContentForward:{unit:"character",direction:Tp},deleteWordForward:{unit:kp,direction:Tp},deleteHardLineForward:{unit:Cp,direction:Tp},deleteSoftLineForward:{unit:Cp,direction:Tp}};var xp=class extends ro{constructor(e){super(e);const t=e.document;let i=0;t.on("keydown",()=>{i++}),t.on("keyup",()=>{i=0}),t.on("beforeinput",(n,s)=>{if(!this.isEnabled)return;const{targetRanges:o,domEvent:r,inputType:a}=s,l=Ep[a];if(!l)return;const c={direction:l.direction,unit:l.unit,sequence:i};c.unit==Cp&&(c.selectionToRemove=e.createSelection(o[0])),"deleteContentBackward"===a&&(Y.isAndroid&&(c.sequence=1),function(e){if(1!=e.length||e[0].isCollapsed)return!1;const t=e[0].getWalker({direction:"backward",singleCharacters:!0,ignoreElementEnd:!0});let i=0;for(const{nextPosition:e,item:n}of t){if(e.parent.is("$text")){const t=e.parent.data,n=e.offset;if(vi(t,n)||yi(t,n)||Ci(t,n))continue;i++}else(n.is("containerElement")||n.is("emptyElement"))&&i++;if(i>1)return!0}return!1}(o)&&(c.unit=Cp,c.selectionToRemove=e.createSelection(o)));const d=new Xn(t,"delete",o[0]);t.fire(d,new ao(e,r,c)),d.stop.called&&n.stop()}),Y.isBlink&&function(e){const t=e.view,i=t.document;let n=null,s=!1;function o(e){return e==Kt.backspace||e==Kt.delete}function r(e){return e==Kt.backspace?Ap:Tp}i.on("keydown",(e,{keyCode:t})=>{n=t,s=!1}),i.on("keyup",(a,{keyCode:l,domEvent:c})=>{const d=i.selection,u=e.isEnabled&&l==n&&o(l)&&!d.isCollapsed&&!s;if(n=null,u){const e=d.getFirstRange(),n=new Xn(i,"delete",e),s={unit:Cp,direction:r(l),selectionToRemove:d};i.fire(n,new ao(t,c,s))}}),i.on("beforeinput",(e,{inputType:t})=>{const i=Ep[t];o(n)&&i&&i.direction==r(n)&&(s=!0)},{priority:"high"}),i.on("beforeinput",(e,{inputType:t,data:i})=>{n==Kt.delete&&"insertText"==t&&""==i&&e.stop()},{priority:"high"})}(this)}observe(){}stopObserving(){}};var Pp=class extends od{_undoOnBackspace;static get pluginName(){return"Delete"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.editing.view,i=t.document,n=e.model.document;t.addObserver(xp),this._undoOnBackspace=!1;const s=new yp(e,"forward");e.commands.add("deleteForward",s),e.commands.add("forwardDelete",s),e.commands.add("delete",new yp(e,"backward")),this.listenTo(i,"delete",(n,s)=>{i.isComposing||s.preventDefault();const{direction:o,sequence:r,selectionToRemove:a,unit:l}=s,c="forward"===o?"deleteForward":"delete",d={sequence:r};if("selection"==l){const t=Array.from(a.getRanges()).map(t=>e.editing.mapper.toModelRange(t)).map(t=>kl(t,e.model.schema)||t);d.selection=e.model.createSelection(t)}else d.unit=l;e.execute(c,d),t.scrollToTheSelection()},{priority:"low"}),this.listenTo(i,"keydown",(s,o)=>{if(i.isComposing||o.keyCode!=Kt.backspace||!n.selection.isCollapsed)return;const r=e.model.schema.getLimitElement(n.selection),a=e.model.createPositionAt(r,0);if(a.isTouching(n.selection.getFirstPosition())){o.preventDefault();const n=e.model.schema.getNearestSelectionRange(a,"forward");if(!n)return;const s=t.createSelection(e.editing.mapper.toViewRange(n)),r=s.getFirstRange(),l=new Xn(document,"delete",r),c={unit:"selection",direction:"backward",selectionToRemove:s};i.fire(l,new ao(t,o.domEvent,c))}}),this.editor.plugins.has("UndoEditing")&&(this.listenTo(i,"delete",(t,i)=>{this._undoOnBackspace&&"backward"==i.direction&&1==i.sequence&&"codePoint"==i.unit&&(this._undoOnBackspace=!1,e.execute("undo"),i.preventDefault(),t.stop())},{context:"$capture"}),this.listenTo(n,"change",()=>{this._undoOnBackspace=!1}))}requestUndoOnBackspace(){this.editor.plugins.has("UndoEditing")&&(this._undoOnBackspace=!0)}},Sp=class extends od{static get requires(){return[bp,Pp]}static get pluginName(){return"Typing"}static get isOfficialPlugin(){return!0}};function Ip(e,t){let i=e.start;return{text:Array.from(e.getWalker({ignoreElementEnd:!1})).reduce((e,{item:n})=>n.is("$text")||n.is("$textProxy")?e+n.data:(i=t.createPositionAfter(n),""),""),range:t.createRange(i,e.end)}}const Vp=De();var Op=class extends Vp{model;testCallback;_hasMatch;constructor(e,t){super(),this.model=e,this.testCallback=t,this._hasMatch=!1,this.set("isEnabled",!0),this.on("change:isEnabled",()=>{this.isEnabled?this._startListening():(this.stopListening(e.document.selection),this.stopListening(e.document))}),this._startListening()}get hasMatch(){return this._hasMatch}_startListening(){const e=this.model.document;this.listenTo(e.selection,"change:range",(t,{directChange:i})=>{i&&(e.selection.isCollapsed?this._evaluateTextBeforeSelection("selection"):this.hasMatch&&(this.fire("unmatched"),this._hasMatch=!1))}),this.listenTo(e,"change:data",(e,t)=>{!t.isUndo&&t.isLocal&&this._evaluateTextBeforeSelection("data",{batch:t})})}_evaluateTextBeforeSelection(e,t={}){const i=this.model,n=i.document.selection,{text:s,range:o}=Ip(i.createRange(i.createPositionAt(n.focus.parent,0),n.focus),i),r=this.testCallback(s);if(!r&&this.hasMatch&&this.fire("unmatched"),this._hasMatch=!!r,r){const i=Object.assign(t,{text:s,range:o});"object"==typeof r&&Object.assign(i,r),this.fire(`matched:${e}`,i)}}},Rp=class extends od{attributes;_overrideUid;_isNextGravityRestorationSkipped=!1;static get pluginName(){return"TwoStepCaretMovement"}static get isOfficialPlugin(){return!0}constructor(e){super(e),this.attributes=new Set,this._overrideUid=null}init(){const e=this.editor,t=e.model,i=e.editing.view,n=e.locale,s=t.document.selection;this.listenTo(i.document,"arrowKey",(e,t)=>{if(!s.isCollapsed)return;if(t.shiftKey||t.altKey||t.ctrlKey)return;const i=t.keyCode==Kt.arrowright,o=t.keyCode==Kt.arrowleft;if(!i&&!o)return;const r=n.contentLanguageDirection;let a;a="ltr"===r&&i||"rtl"===r&&o?this._handleForwardMovement(t):this._handleBackwardMovement(t),!0===a&&e.stop()},{context:"$text",priority:"highest"}),this.listenTo(s,"change:range",(e,t)=>{this._isNextGravityRestorationSkipped?this._isNextGravityRestorationSkipped=!1:this._isGravityOverridden&&(!t.directChange&&Dp(s.getFirstPosition(),this.attributes)||this._restoreGravity())}),this._enableClickingAfterNode(),this._enableInsertContentSelectionAttributesFixer(),this._handleDeleteContentAfterNode()}registerAttribute(e){this.attributes.add(e)}_handleForwardMovement(e){const t=this.attributes,i=this.editor.model,n=i.document.selection,s=n.getFirstPosition();return!this._isGravityOverridden&&((!s.isAtStart||!Bp(n,t))&&(!!Dp(s,t)&&(e&&Np(e),Bp(n,t)&&Dp(s,t,!0)?Fp(i,t):this._overrideGravity(),!0)))}_handleBackwardMovement(e){const t=this.attributes,i=this.editor.model,n=i.document.selection,s=n.getFirstPosition();return this._isGravityOverridden?(e&&Np(e),this._restoreGravity(),Dp(s,t,!0)?Fp(i,t):Mp(i,t,s),!0):s.isAtStart?!!Bp(n,t)&&(e&&Np(e),Mp(i,t,s),!0):!Bp(n,t)&&Dp(s,t,!0)?(e&&Np(e),Mp(i,t,s),!0):!!Lp(s,t)&&(s.isAtEnd&&!Bp(n,t)&&Dp(s,t)?(e&&Np(e),Mp(i,t,s),!0):(this._isNextGravityRestorationSkipped=!0,this._overrideGravity(),!1))}_enableClickingAfterNode(){const e=this.editor,t=e.model,i=t.document.selection,n=e.editing.view.document;e.editing.view.addObserver($l),e.editing.view.addObserver(Wl);let s=!1,o=!1;this.listenTo(n,"touchstart",()=>{o=!1,s=!0}),this.listenTo(n,"mousedown",()=>{o=!0}),this.listenTo(n,"selectionChange",()=>{const e=this.attributes;if(!o&&!s)return;if(o=!1,s=!1,!i.isCollapsed)return;if(!Bp(i,e))return;const n=i.getFirstPosition();Dp(n,e)&&(n.isAtStart||Dp(n,e,!0)?Fp(t,e):this._isGravityOverridden||this._overrideGravity())})}_enableInsertContentSelectionAttributesFixer(){const e=this.editor.model,t=e.document.selection,i=this.attributes;this.listenTo(e,"insertContent",()=>{const n=t.getFirstPosition();Bp(t,i)&&Dp(n,i)&&Fp(e,i)},{priority:"low"})}_handleDeleteContentAfterNode(){const e=this.editor,t=e.model,i=t.document.selection,n=e.editing.view;let s=!1,o=!1;this.listenTo(n.document,"delete",(e,t)=>{s="backward"===t.direction},{priority:"high"}),this.listenTo(t,"deleteContent",()=>{if(!s)return;const e=i.getFirstPosition();o=Bp(i,this.attributes)&&!Lp(e,this.attributes)},{priority:"high"}),this.listenTo(t,"deleteContent",()=>{s&&(s=!1,o||e.model.enqueueChange(()=>{const e=i.getFirstPosition();Bp(i,this.attributes)&&Dp(e,this.attributes)&&(e.isAtStart||Dp(e,this.attributes,!0)?Fp(t,this.attributes):this._isGravityOverridden||this._overrideGravity())}))},{priority:"low"})}get _isGravityOverridden(){return!!this._overrideUid}_overrideGravity(){this._overrideUid=this.editor.model.change(e=>e.overrideSelectionGravity())}_restoreGravity(){this.editor.model.change(e=>{e.restoreSelectionGravity(this._overrideUid),this._overrideUid=null})}};function Bp(e,t){for(const i of t)if(e.hasAttribute(i))return!0;return!1}function Mp(e,t,i){const n=i.nodeBefore;e.change(i=>{if(n){const t=[],s=e.schema.isObject(n)&&e.schema.isInline(n);for(const[i,o]of n.getAttributes())!e.schema.checkAttribute("$text",i)||s&&!1===e.schema.getAttributeProperties(i).copyFromObject||t.push([i,o]);i.setSelectionAttribute(t)}else i.removeSelectionAttribute(t)})}function Fp(e,t){e.change(e=>{e.removeSelectionAttribute(t)})}function Np(e){e.preventDefault()}function Lp(e,t){return Dp(e.getShiftedBy(-1),t)}function Dp(e,t,i=!1){const{nodeBefore:n,nodeAfter:s}=e;for(const e of t){const t=n?n.getAttribute(e):void 0,o=s?s.getAttribute(e):void 0;if((!i||void 0!==t&&void 0!==o)&&o!==t)return!0}return!1}const zp={copyright:{from:"(c)",to:"©"},registeredTrademark:{from:"(r)",to:"®"},trademark:{from:"(tm)",to:"™"},oneHalf:{from:/(^|[^/a-z0-9])(1\/2)([^/a-z0-9])$/i,to:[null,"½",null]},oneThird:{from:/(^|[^/a-z0-9])(1\/3)([^/a-z0-9])$/i,to:[null,"⅓",null]},twoThirds:{from:/(^|[^/a-z0-9])(2\/3)([^/a-z0-9])$/i,to:[null,"⅔",null]},oneForth:{from:/(^|[^/a-z0-9])(1\/4)([^/a-z0-9])$/i,to:[null,"¼",null]},threeQuarters:{from:/(^|[^/a-z0-9])(3\/4)([^/a-z0-9])$/i,to:[null,"¾",null]},lessThanOrEqual:{from:"<=",to:"≤"},greaterThanOrEqual:{from:">=",to:"≥"},notEqual:{from:"!=",to:"≠"},arrowLeft:{from:"<-",to:"←"},arrowRight:{from:"->",to:"→"},horizontalEllipsis:{from:"...",to:"…"},enDash:{from:/(^| )(--)( )$/,to:[null,"–",null]},emDash:{from:/(^| )(---)( )$/,to:[null,"—",null]},quotesPrimary:{from:Kp('"'),to:[null,"“",null,"”"]},quotesSecondary:{from:Kp("'"),to:[null,"‘",null,"’"]},quotesPrimaryEnGb:{from:Kp("'"),to:[null,"‘",null,"’"]},quotesSecondaryEnGb:{from:Kp('"'),to:[null,"“",null,"”"]},quotesPrimaryPl:{from:Kp('"'),to:[null,"„",null,"”"]},quotesSecondaryPl:{from:Kp("'"),to:[null,"‚",null,"’"]}},Hp={symbols:["copyright","registeredTrademark","trademark"],mathematical:["oneHalf","oneThird","twoThirds","oneForth","threeQuarters","lessThanOrEqual","greaterThanOrEqual","notEqual","arrowLeft","arrowRight"],typography:["horizontalEllipsis","enDash","emDash"],quotes:["quotesPrimary","quotesSecondary"]},$p=["symbols","mathematical","typography","quotes"];var Wp=class extends od{static get requires(){return[Pp,bp]}static get pluginName(){return"TextTransformation"}static get isOfficialPlugin(){return!0}constructor(e){super(e),e.config.define("typing",{transformations:{include:$p}})}init(){const e=this.editor.model.document.selection;e.on("change:range",()=>{const t=e.anchor,i=!!t&&t.parent.is("element","codeBlock"),n=e.hasAttribute("code");this.isEnabled=!(i||n)}),this._enableTransformationWatchers()}_enableTransformationWatchers(){const e=this.editor,t=e.model,i=e.plugins.get("Delete"),n=function(e){const t=e.extra||[],i=e.remove||[],n=e=>!i.includes(e);return function(e){const t=new Set;for(const i of e)if("string"==typeof i&&Hp[i])for(const e of Hp[i])t.add(e);else t.add(i);return Array.from(t)}(e.include.concat(t).filter(n)).filter(n).map(e=>"string"==typeof e&&zp[e]?zp[e]:e).filter(e=>"object"==typeof e).map(e=>({from:Up(e.from),to:qp(e.to)}))}(e.config.get("typing.transformations")),s=new Op(e.model,e=>{for(const t of n)if(t.from.test(e))return{normalizedTransformation:t}});s.on("matched:data",(e,n)=>{if(!n.batch.isTyping)return;const{from:s,to:o}=n.normalizedTransformation,r=s.exec(n.text),a=o(r.slice(1)),l=n.range;let c=r.index;t.enqueueChange(e=>{for(let i=1;i